rest of the machine

The code we’ve written to emulate the 8080 processor has been pretty generic and can easily be adapted to run on anything with a C compiler. To actually see and play this game, we’re going to have to do more than that. We're going to have to emulate the hardware of the arcade machine, and write code to glue the specifics of our computer environment to the emulator.

(It might be interesting for you to take a look at the schematic for the machine.)

Timing

The game ran on a 2MHz 8080. Your computer is much faster than that. We’ll have to invent a mechanism to reconcile that.

Interrupts

Interrupts are designed to let processors handle time-sensitive tasks like I/O. The processor can be running a program, and when the interrupt pin on the CPU gets triggered, the CPU will stop executing the current program and do something else.

We'll have to mimic how the arcade machine generates interrupts.

Graphics

Space Invaders draws its graphics into its memory at 0x2400. The real hardware’s video controller would read that RAM and drive the CRT display. Our program will have to emulate that by drawing the game image into a window.

Buttons

The game had physical buttons which the program read through the 8080’s IN instruction. Our emulator will have to map input from the keyboard onto those IN instructions.

ROM vs RAM

Another confession: We've taken a shortcut. We've made a 16k buffer of memory that encompasses the bottom 16K of the processor's memory map. In reality, the first 2K of the memory map is real ROM (read-only memory). We should consider putting our memory writes into a function so we can prevent ROM from being written.

Sound

We haven't mentioned sound yet. Space Invaders has neat analog sound circuitry that plays one of 8 sounds triggered by an OUT instruction to one of the ports. We’ll have to convert those OUT instructions to play sound samples on the platform.

This might sound like a lot of stuff, but it isn’t too bad and we can add it on a little at a time. The first thing we want to do is see the screen which will require us to implement interrupts, graphics, and some of the IN and OUT handling.

← Prev: displays-and-refresh   Next: buttons-and-ports →


Post questions or comments on Twitter @realemulator101, or if you find issues in the code, file them on the github repository.