Building an 8080 Emulator: Planning

My Capstone project this term is Build an Emulator and Run Space Invaders ROM. I will be working with a team of three other students. I am excited about working on this project because I am interested in low-level programming and old-school video games. Most of the code will be written in C (my favorite programming language!), but 8080 assembly code will also be used.

The program will take a ROM file as input. Currently, we are planning to target the Space Invaders ROM, but we may test with other ROM files if time allows. Since my group includes both Linux and Windows users, the program will be compatible with Linux and Windows. As an extension, we may develop for compatibility with other platforms, such as mobile.

Building the Disassembler

The first step will be to build a disassembler that will read hexadecimal data from the ROM file and print out the corresponding 8080 assembly instruction. There are 256 instructions, corresponding to opcodes 0x00 through 0xff. Thus, the implementation will likely involve a really long switch statement. For example, this snippet from emulator 101:

	switch (*code) {    
	case 0x00: 
		printf("NOP"); break;    
	case 0x01: 
		printf("LXI    B,#$%02x%02x", code[2], code[1]);
		opbytes=3; break;    

Memory Map

The Intel 8080 CPU has 16 address pins, so it uses 16 bit addresses (0000 through ffff). The memory map for Space Invaders tells us what each address is used for.

0000-1FFF 8K ROM
2000-23FF 1K RAM
2400-3FFF 7K Video RAM
4000- RAM mirror

Implementing Opcodes

The next step will be to implement the instructions. We will create data structures to store info about the current state of the registers and the values of the FLAGS. The Intel 8080 CPU has seven 8-bit registers (A, B, C, D, E, H, and L) as well as the 16-bit registers for the stack pointer (SP), program counter (PC), and status register (FLAGS).

The program will modify the state (stored in the data structures) according to what effect that instruction would actually have on the registers in the 8080.

Emulating the Rest of the Hardware

We will need to emulate the rest of the hardware in the Space Invaders machine to actually see and play the game. This includes interrupts, graphics, buttons, and sounds. We will also need to emulate the speed of the 8080 processor, which has a CPU clock rate of 2 Mhz.

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *