5

GitHub - trusch/snakeos: bootable x86 snake game in rust

 3 years ago
source link: https://github.com/trusch/snakeos
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

SnakeOS

This is the game snake, bootable on a x86_64 CPU, written completely in rust. It's foundation is following the very interesting Writing an OS in Rust blog which I would recommend everybody who is interested in this kind of stuff.

Features

  • Play snake on any x86_64 CPU
    • Let's have fun!
  • Dynamic memory management
    • The snake can grow!
  • Interrupt handling
    • We can read the keyboard!
  • Async/Await support
    • We can update the world and read user input at the same time!
  • Only 212kB kernel size
    • You can even put this on a 8-inch floppy disk!

Build it

Use the Makefile to build the game. The only dependencies are podman and buildah which are used to setup the build enviroment.

make snakeos.img

This will first setup a build container with the necessary dependencies and then build the game.

Alternativly you can use the rust compiler directly with some tricks applied:

rustup override set nightly
rustup toolchain install nightly
rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu
rustup component add llvm-tools-preview
cargo run \
    --release \
    --target x86_64-custom.json \
    -Zbuild-std=core,alloc \
    -Zbuild-std-features=compiler-builtins-mem -- \
        --no-run
ln -sf target/x86_64-custom/release/boot-bios-snakeos.img snakeos.img

To now run the game, you can use the following command:

make run

which will actually run qemu-system-x86_64 --enable-kvm -drive format=raw,file=snakeos.img for you. From here you can use either w, a, s and d or the arrow keys to control the snake.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK