Thursday, 25 March 2021

Lunchtime Coder #5 - Space Invaders Colour Emulator

Having sucessfully written a Space Invaders emulator based around the original Taito 8 kB (4 x 2 kB) Romset, I decided to up the game and try some other similar romsets in my emulator to see how they ran.

The first romset I tried was Super Earth Invasion, a UK bootleg/clone of Space Invaders with different graphics for the invaders and houses instead of shields.
I had implemented some Intel 8080 opcodes that the original Space Invaders hadn't needed and the Parity flag into my emulator. Not a straight clone then...
There was also some minor differences in the DIP switch settings/input but with a few tweaks and adjustments, it ran perfectly.

On the back of this success, I went for the Space Invaders Colour (CV) romset fully expecting some heavy additional coding to be required, at least in the screen drawing routine. I was surprised to find 4 x 2 kB roms, and when I ran them I got monochrome Space Invaders out of them.

To be fair, its a slightly updated romset. The 'Taito Corporation' logo now appears on the front screen, and all of the scores now have five digits, rather than the four on the older romset version. I was also required to implement another half a dozen or so Intel 8080 opcodes so there had been a few code changes and improvements when compared to the original romset.

Also included in this romset are 2 x 1 kB eprom images. A bit of on line investigation showed that these two eproms hold the colour maps for a Player 1 and Player 2 game. Essentially the 1-bit bitmap is generated in ram, and then the colour is added during the video processing stage later on in the hardware.

To be more accurate, the player 1 colour map is really everything but player 2 playing map. The player 2 colour map changes the colour of the bases and highlights the player two score in white. The rest of the colour map is the same as the 'Everything else' colour map.

I Wrote a small program that read the bytes from these eprom images and arranged them in a 32 by 32 square that showed that each square had a value of between 0 and 7 representing one of 8 different colours (Black, Red, Green, Blue, Cyan, Megenta, Yellow and White).
Each byte corresponded to an 8 x 8 pixel square in the game remembering that the Space Invaders screen is rotated 90 degrees anticlockwise. Nice and easy!

A quick update of my emulator code to read the eprom map as it was drawing the bits gave me glorious colour-o-vision, however how to trigger between the two colour maps for player 1 and player 2?

After playing Space Invaders Colour on MAME a few times, I noticed that the whole screen turns red when a base is hit by a bomb. This must mean that the colour video processing can turn the whole screen a single colour 'on the fly'. I also noticed that the colour maps change pretty much spot on the player change.

Making the colour change to red when a base gets hit was pretty easy as I used the 'Base Hit' sound sample as the trigger and duration of red screen drawing.

I then scoured the trusty 'Computer Archeology' Space Invaders Hardware Code webpage for some way of telling whether player 1 or player 2 is on within the Invaders code.

I eventually found that the Invaders code has an offset that points to player 1 or player 2s game details at 0x2067. This value is either 0x21 or 0x22 and is the MSB of the 16 bit address for the players details/attributes.
Monitoring this value would tell me if player 2 was playing or not and I have used this as a trigger to switch between the two colour map eproms.

Player 1 Colour Map
Player 2 Colour Map

Its not perfect though... It switches slightly early after the screen returns from all red, but before the 'Player 2' banner comes up so I am still looking for a better trigger, however as they say... Close enough for government work!

No comments:

Post a comment