this is my first real project with rust. it is an intel 8080 emulator core that i eventually turned into a full space invaders cabinet emulator.
i wrote this on an absolute potato laptop (pentium processor + windows 11... dont ask) so i had to do most of the work in rust playground and verify the kernel stuff with an online wasm2wat tool because my machine was struggling.
- 8080 core: a
#![no_std]implementation of the 8080 cpu. i wanted it to be as tiny as possible for web usage. - space invaders: i ended up putting the game-specific hardware logic (the shift register and interrupts) into a wasm variant so i can play it in a browser.
- cpu: passes the standard test roms. i used a massive match statement for the opcodes which is probably not the "correct" rust way but it works.
- no_std math: since i couldn't use the standard library, i had to implement a 9th-degree taylor series approximation for sine waves to get the audio working. it synthesizes the ufo and fleet sounds manually.
- the shift register: i implemented the 8255 i/o ports. turns out space invaders uses dedicated hardware for bit-shifting sprites because the 8080 was too slow to do it in software.
- timing: handles mid-frame and vblank interrupts (rst 1 and rst 2) to keep the game running at the original hardware speed.
the core is in src/. for the space invaders version, check the space-invaders folder.
- build the wasm:
cargo build --target wasm32-unknown-unknown --release - open the
index.htmlin that folder. - you'll need the original rom files (
invaders.h,invaders.g, etc.). i can't provide those for legal reasons but you can find them easily.
it hits 60fps even on my pentium laptop. the code is probably messy and i'm still confused by UnsafeCell and raw pointers, but the game is playable and the sounds are okay.
if you want to roast my code go ahead i guess.
peace.