编写不在操作系统上跑的贪吃蛇程序

X86实模式下运行的贪吃蛇程序

前段时间看了《操作系统真象还原》,于是闲暇之余做了一个运行在x86实地址模式下运行的贪吃蛇小游戏练手。目前只是完成了基本功能,程序本身还存在一些问题,待后期有时间慢慢完善。
github地址:https://github.com/SunZhp/GredySnake_X86RealMode
如果喜欢的话点个start吧!

运行环境

bochs,centos8
bochs是一个x86环境的虚拟机,具体就不细说了,网上有很多安装和使用的教程,需要的请执行搜索

运行截图

bochs 贪吃蛇
界面有点丑,个人审美问题,请见谅!

项目文件结构

mbr.S : 主引导区代码,使用汇编编写,主要用于加在贪吃蛇程序
gredysnake_no_os.c:贪吃蛇主逻辑代码,使用C和内联汇编

编译环境搭建

编译环境安装参考自:https://github.com/cfenollosa/os-tutorial.git

binutils

Remember: always be careful before pasting walls of text from the internet. I recommend copying line by line.

mkdir /tmp/src
cd /tmp/src
curl -O http://ftp.gnu.org/gnu/binutils/binutils-2.24.tar.gz # If the link 404’s, look for a more recent version
tar xf binutils-2.24.tar.gz
mkdir binutils-build
cd binutils-build
../binutils-2.24/configure --target=$TARGET --enable-interwork --enable-multilib --disable-nls --disable-werror --prefix=$PREFIX 2>&1 | tee configure.log
make all install 2>&1 | tee make.log

gcc

cd /tmp/src
curl -O https://ftp.gnu.org/gnu/gcc/gcc-4.9.1/gcc-4.9.1.tar.bz2
tar xf gcc-4.9.1.tar.bz2
mkdir gcc-build
cd gcc-build
../gcc-4.9.1/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --disable-libssp --enable-languages=c --without-headers
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc

bochs

yum install bochs

编译

mbr

编译:nasm -f bin -o mbr.bin mbr.S
安装:dd if=mbr.bin of=hd60.img bs=512 conv=notrunk

GredySnake_X86RealMode

编译:
/usr/local/i386elfgcc/bin/i386-elf-gcc -m16 -ffreestanding -c -o gredysnake_no_os.o gredysnake_no_os.c
/usr/local/i386elfgcc/bin/i386-elf-ld -o gredysnake_no_os.bin -Ttext 0x900 --oformat binary gredysnake_no_os.o

安装:dd if=gredysnake_no_os.bin of=hd60.img bs=512 conv=notrunc seek=2

运行

bochs -f bochsrc.disk

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值