Skip to content

Intel 8080 Space Invaders Emulator in Rust

License

Notifications You must be signed in to change notification settings

krueger71/inv8080rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust

Intel 8080 Space Invaders Emulator in Rust

Original version that ran on the Taito 8080 hardware.

screenshot

Running the emulator

Clone the repo and build the emulator with cargo build --release.

The game rom cannot be distributed here for copyright reasons. Sound samples are available in the assets-folder. Sounds were created at jsfxr with the same copyright as the source code. Sounds could be customized with other samples if filenames and format are kept as-is (8-bit mono 11025Hz).

Sounds and the game rom should be located in a common folder called assets as a sub-directory in the current working directory. The game rom should be in one single file called invaders.rom, with the whole program in correct order. Then execute the binary ./target/release/inv8080rs directly or do cargo run --release to start the emulator.

Design notes

  • cpu.rs Intel 8080 CPU model. Only the instructions used by the game are implemented.

    Instructions are modeled as enums, carrying any immediate data. Execution is one big match-statement. Common cpu-operations have their own functions ("micro-code") to avoid duplication.

  • emu.rs SDL2-based I/O (keyboard, graphics, sound).

    Runs the cpu-model in a loop at approximately the original speed (2 MHz) with the original 60 Hz display update. Two interrupts are generated during each frame (one in the middle of execution and one at the end). The execution is single-threaded.

    The framebuffer is a piece of RAM-memory that needs to be rotated 90 degrees ccw before display. This transformation is done on-the-fly in the cpu:s display-function. The colored overlay is handled by drawing the display in several passes in different colors. The band at the bottom with remaining ships and score is not exactly as in the arcade game. The remaining ships are white here, not green. A slight retro pixelated effect is applied via alpha-blending of a grid on top of the game scene.

    Sound is handled with queues for each individual sample. Each sample is played only once while the corresponding bit is set. The looping feature for the UFO-sound has not been implemented.

    Mapping keys to input-bus bits straightforwardly using scan-codes.

    • 5 add credits
    • 1 start 1-player mode
    • 2 start 2-player mode
    • Left arrow player 1 left
    • Right arrow player 1 right
    • Left ctrl player 1 fire
    • D player 1 left
    • G player 1 right
    • A player 1 fire
    • T tilt and game over!
    • Esc quit
  • utils.rs A couple of useful functions.

  • main.rs Creates a CPU model, sets some options, connects it to the emulator, then runs the emulator.

Useful resources