Monday, 30 November 2020

Lunchtime Coder #4-2 - 8080 Emulator for Space Invaders Arcade - Memory Buffer / Memory Map

Before I can start emulating, I need to make a buffer to store the roms and provide video ram.

And before I can do that, I need to know the Space Invaders memory map.

Space Invaders has four 2 kB roms:

invaders.e
invaders.f
invaders.g
invaders.h

This rom set is widely available on the internet. I googled for websites supplying MAME 0.36 romsets. If you end up with a romset that has 4 x 2 kB roms of a different naming convention, you may be able to work out which rom corresponds to the naming convention above, or just find an older set.

Space invaders then has 8 kB of RAM; 1 kB of general purpose RAM and 7 kB of video RAM.

The processor addresses these ROMs and RAM as a single 16 kB entity so the memory map in Hex goes:

invaders.h 2 kB 0000 to 07ff
invaders.g 2 kB 0800 to 0fff
invaders.f 2 kB 1000 to 17ff
invaders.e 2 kB 1800 to 1fff
RAM 1 kB 2000 to 23ff
Video RAM 7 kB 2400 to 3fff

Note that already we can start to gather info for the processor emulator. 16 kB cannot be addressed in 8 bits / 1 byte. The 8080 processor is an 8 bit processor, but must use 16 bit memory addressing, or memory addressing spread across two bytes.

Also note that Space Invaders screen resolution is 256 x 224 in black and white, so one bit per pixel. 256 x 224 is 57344 bits or 7168 bytes or 7 kB. This makes for a nice easy bit streaming screen interpreter hopefully.

Now that I have the memory map details, I can start making the memory buffer.

I basically have two choices; Array or Databank. Both should be pretty straight forward. Set up an array or databank with 16384 slots and allow one byte in each slot. The only real question is, which would be faster?

DEV 1 - Program to test the speed of writing to and reading from an array vs writing to and reading from a databank.

This was a nice easy dev program that checks the time in ms, writes a fixed value to each of the 16384 slots in the array, and then reads each of them back out. On completion check the time is ms again and see how long its taken.

Repeat the process for the databank and then compare which one was faster.

I let this run for several thousand cycles capturing the average time taken for each one, and was slightly disappointed to find that both methods take pretty much exactly the same amount of time.. (rolls eyes) and so after literally three seconds of consideration, I went with the array option as the coding to read and write from array slots is shorter.

I have a feeling that this will by far be the easiest part of this emulator.

I have made a single dimension array with 16384 spaces. I have loaded up the Space Invaders roms into first half of the array in the correct order... And that's about it!

One last important thing to know. What memory location do you start running the Space Invaders game from?

While this isn't always the case with 8080 code, conveniently Space Invaders starts running from memory location 0000.

No comments:

Post a comment