加入星计划,您可以享受以下权益:

  • 创作内容快速变现
  • 行业影响力扩散
  • 作品版权保护
  • 300W+ 专业用户
  • 1.5W+ 优质创作者
  • 5000+ 长期合作伙伴
立即加入
  • 正文
  • 推荐器件
  • 相关推荐
  • 电子产业图谱
申请入驻 产业图谱

上班摸鱼?C语言玩魂斗罗!

08/27 10:40
668
阅读需 12 分钟
加入交流群
扫码加入
获取工程师必备礼包
参与热点资讯讨论

来源:公众号【鱼鹰谈单片机】,作者:鱼鹰Osprey

最近玩了docker,发现真的很方便,和Java 、Python这种类似,一次写好,到处运行。

虽然是一项技术,也是工作技能,但只是工作怎么行,闲暇之余,还是可以用来摸摸鱼的。

比如用来玩玩魂斗罗、超级玛丽,只要是nes游戏,应该都支持。

双人模式下,目前数字键使用的是小键盘。

nes-dockerfile 文件

FROM ubuntu:18.04 as builder
MAINTAINER Osprey
#docker build -f nes-dockerfile -t nes.osprey.io/nes-build-run .
# docker start nes-build # docker attach nes-build # docker exec -it  nes-build  /bin/bash

# 创建用户 cmd:idARG USERNAME=ospreyARG USER_UID=1000ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME     && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME         && apt-get update     && apt-get install -y sudo     && echo $USERNAME ALL=(root) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME     && chmod 0440 /etc/sudoers.d/$USERNAME
RUN apt-get update# for cmd: add-apt-repositoryRUN apt -y install software-properties-common dirmngr apt-transport-https lsb-release ca-certificatesRUN add-apt-repository ppa:xmake-io/xmake -y && apt-get update && apt-get install -y xmakeRUN apt-get install -y libsdl2-dev
RUN apt-get install -y git make gcc # optionRUN  apt-get install -y nano iputils-ping# setting the password of root to 123456RUN echo 'root:123456' | chpasswd
USER $USERNAMEENV HOME=/home/$USERNAME
RUN mkdir /home/$USERNAME/work
WORKDIR /home/$USERNAME/work
RUN git clone https://gitee.com/Dozingfiretruck/nes && cd nes && xmake

###########################################FROM ubuntu:18.04 as prod
#设置时区ENV TZ=Asia/ShanghaiRUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 创建用户 cmd:idARG USERNAME=ospreyARG USER_UID=1000ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME     && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME         && apt-get update     && apt-get install -y sudo     && echo $USERNAME ALL=(root) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME     && chmod 0440 /etc/sudoers.d/$USERNAME
RUN apt-get updateRUN apt-get install -y p7zip-full libsdl2-dev
USER $USERNAMEENV HOME=/home/$USERNAME
RUN mkdir /home/$USERNAME/workWORKDIR /home/$USERNAME/workRUN echo "PS1='[e[0;33m]u@h[e[0m]:[e[0;34m]w[e[0m]$ '" >> /home/$USERNAME/.bashrc
COPY --from=0 /home/$USERNAME/work/nes/build/linux/x86_64/release/nes .COPY contra.nes .COPY SuperMarioBrosWorld.nes .#CMD ["~/work/nes contra.nes"]
# run cmd:# docker run --name=nes-test --rm -it -v /tmp/.X11-unix:/tmp/.X11-unix -v /dev/snd:/dev/snd --privileged -e DISPLAY=unix$DISPLAY nes.osprey.io/nes-build-run /bin/bash -c "./nes contra.nes"

编译命令(前提是安装好docker,参考:docker通用安装使用指南-Ubuntu-树莓派5):

docker build -f nes-dockerfile -t nes.osprey.io/nes-build-run .

摸鱼指令(nes-build-run 由前面的命令生成)

docker run --name=nes-test --rm -it -v /tmp/.X11-unix:/tmp/.X11-unix -v /dev/snd:/dev/snd --privileged -e DISPLAY=unix$DISPLAY nes.osprey.io/nes-build-run /bin/bash -c "./nes contra.nes"

如果有新的 nes 游戏,可以拷贝到容器中后,再进入容器中运行该文件

docker cp xx.nes nes-test:/home/osprey/nes

最后为了更好的摸鱼,可以配合vscode使用,随时随地打开模拟器摸鱼,爽歪歪。

ubuntu18 以下版本只能下载v1.85的deb 文件,最新版本安装不了(其他版本安装最新的vscode就行):

https://update.code.visualstudio.com/1.85.2/linux-deb-x64/stable

安装deb文件

sudo dpkg -i code_1.85.2-1705561292_amd64.deb

vscode打开 nes,

# forkr from https://gitee.com/Dozingfiretruckgit clone https://gitee.com/embeddedosprey/nes -b docker# docker 分支目前含有编译好的镜像 nes-build-run 565M,直接使用 load 命令导入即可code nes# 如果是自己导入的镜像,可能需要需要修改一下镜像名称

安装插件 Dev Containers

右下角点击重新打开 Reopen in Container(如果没有,可以通过 ctrl + shift+p,输入 rebuild)

容器内执行命令

导出镜像:

docker save nes.osprey.io/nes-build-run > nes-build-run.tar

在虚拟机的代码仓库.devcontainer里面导入镜像:

docker load < nes-build-run.tar

nes C语言模拟器开源仓库地址:

https://github.com/Dozingfiretruck/nes

https://gitee.com/Dozingfiretruck/nes

魂斗罗 nes 下载参考链接  https://www.fcnes.com/fc/act/38.html#downadress

推荐器件

更多器件
器件型号 数量 器件厂商 器件描述 数据手册 ECAD模型 风险等级 参考价格 更多信息
DP83822IRHBR 1 Texas Instruments Low-power, robust 10/100-Mbps Ethernet PHY transceiver with 16-kV ESD 32-VQFN -40 to 85

ECAD模型

下载ECAD模型
$5.64 查看
6N137 1 Avago Technologies 1 CHANNEL LOGIC OUTPUT OPTOCOUPLER, 10Mbps, 0.300 INCH, DIP-8
$0.99 查看
SN74LVC1G125DCKT 1 Texas Instruments Single 1.65-V to 5.5-V buffer with 3-state outputs 5-SC70 -40 to 125

ECAD模型

下载ECAD模型
$0.9 查看

相关推荐

电子产业图谱