Monday, June 17, 2013

Booting Minecraft (or maybe Assembling Minecraft) - MineAssemble is a bootable Minecraft clone, written in mostly x86 assembly

OS News - Bootable Minecraft clone written party in x86 assembly

"MineAssemble is a tiny bootable Minecraft clone written partly in x86 assembly. I made it first and foremost because a university assignment required me to implement a game in assembly for a computer systems course. Because I had never implemented anything more complex than a 'Hello World' bootloader before, I decided I wanted to learn about writing my own kernel code at the same time...."

Overv / MineAssemble 

image

MineAssemble is a tiny bootable Minecraft clone written partly in x86 assembly. I made it first and foremost because a university assignment required me to implement a game in assembly for a computer systems course. Because I had never implemented anything more complex than a "Hello World" bootloader before, I decided I wanted to learn about writing my own kernel code at the same time.

Note that the goal of this project was not to write highly efficient hand-optimized assembly code, but rather to have fun and write code that balances readability and speed. This is primarily accomplished by proper commenting and consistent code structuring.

Starting in assembly right away would be a bit too insane, so I first wrote a reference implementation in C using the SDL library, which can be found in the reference directory. I started writing it with the idea that if it was longer than 150 statements excluding boilerplate, it wouldn't be worth doing it in assembly. Like all estimates in the world of programming, this limit turned out to be a gross underestimate, reaching about 134 lines before adding the texture or even the input code.

After completing the reference code, I wrote the kernel boilerplate code (setting up VGA, interrupts, etc.) and changed the reference C code to work with this. Then I began slowly porting everything to handwritten assembly.

Unfortunately this turned out to be a lot more work than I expected, so currently a large fraction of the codebase is still in C. Slowly porting everything to assembly is an ongoing process. The code also isn't fully compatible with all systems yet. It seems to cause floating point exceptions on some setups.

How to play

QEMU

To run the game with QEMU, simply run make test This is a quick and easy way to play around with it.

Virtual machine

If you want to use virtualization software like VirtualBox, you can produce an .iso image with make iso and mount it. The virtual machine doesn't need a hard drive and requires no more than 4 MB of RAM.

You can also burn this image to a CD or DVD, but that is rather wasteful. Use the USB stick method to try it on real hardware unless it really isn't an option for some reason.

USB stick

Booting from an USB stick is an excellent way to try it on real hardware, but does involve a little bit more work. Note that this process will remove all data currently on the USB stick. Also, make sure to get the drive name right or you might accidentally wipe your hard drive!

  1. Format your USB stick to FAT32 with 1 MB free space preceding.
  2. Mount it using mount /dev/sdx1 /mnt where sdx is the drive name.
  3. Turn it into a GRUB rescue disk with grub-install --no-floppy --root-directory=/mnt /dev/sdx.
  4. Run make iso and copy the contents of the iso directory to the USB stick.
  5. Unmount with umount -l /dev/sdx1.

Now reboot your PC and boot from USB.

...

image

..."

That's officially cool. Got to love he released the source too...

No comments: