Thursday, 25 March 2021

Lunchtime Coder #5 - Space Invaders Colour Emulator in Blitz3D / Blitz Basic

Having written a Space Invaders emulator based around an early and late version of the various romsets available, I decided to up the game and try some other similar romsets in my emulator to see how they ran.

The first different romset I tried was Super Earth Invasion, a UK bootleg/clone of Space Invaders with different graphics for the Invaders, houses instead of shields, and also some code changes that enabled motherships to drop super bombs on you, and for shot invaders to split and multiply. It was designed to run on the Space Invaders Deluxe hardware, and in some ways has more in common with this game than with the original Space Invaders.

There was some minor differences in the DIP switch settings and how they related to the processor input ports, but with a few tweaks and adjustments it ran perfectly.

I added some colour to simulate the coloured gel treated mirror
effect seen in Space Invaders upright cabinets.

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 that the romset contained 4 x 2 kB roms (similar to the original Space Invaders romset), and when I ran them I got monochrome Space Invaders out of them.

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 screen. Essentially the 1-bit bitmap is generated in ram, and then the colour is added during the video processing stage of the hardware.

To be more accurate, the player 1 colour map is really everything but player 2 playing colour 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, Magenta, Yellow and White).

Each byte corresponds to an 8 x 8 pixel square in the game remembering that the Space Invaders screen is rotated 90 degrees anticlockwise so the screen drawing starts from bottom left to top left and continues moving right across the screen.

A quick update of my emulator code to read the eprom map as it was drawing the bits gave me glorious colour-o-vision.

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

Making the colour change to red when a base gets hit was pretty easy. I used Intel 8080 Output Port 3 bit 0x04. This is the trigger for the 'Base Hit' sound sample to play, but this bit is set for a specific duration, so it seems that when its set to 1, all of the on screen graphics are red.

To flip between player colour maps, I used the Intel 8080 Output Port 5, Bit 0x20 which is for tabletop cabinet screen flipping. By default it is set to 0, but when Player 2 is playing, it flips to 1. This means that it must be the trigger for both cocktail mode screen flipping, and for changing between player 1 and Player 2 colour maps.

Player 1 Colour Map
Player 2 Colour Map

Near perfect.. Well you cant have 100 % perfection without having the original arcade machine running in front of you...

Tuesday, 23 March 2021

Lunchtime Coder #4 - Space Invaders Emulator in Blitz3D / Blitz Basic

Have you ever wanted to take a trip down gaming nostalgia lane and relive the “good old days” of late 70s/early 80s arcade gaming?


Me neither... but apparently there are some odd types around who miss the retroness of old skool arcade gaming in smoke filled germ ridden festering pits of arcadiness, and this led to the miracle of EMULATION !

But... Playing retro games using emulators is one thing... Writing an emulator? Now thats a tough old well done rump!

(BTW I kid... I bloody love emulators!)

I wrote this emulator as a two headed "Technical Demonstration":

1. I wanted to demonstrate that Blitz3D, despite being an older language, still has good capability and can still be used for some kuul coding projects.

2. I wanted to prove to myself that I could write an emulator...

I have provided a link above for the Blitz3D source code of my basic Space Invaders emulator.

The basic emulator includes support for the following:

1. Two romsets of the original Space Invaders monochrome game - an older and newer version with noticeable differences.

2. Adjustable dip switch settings and access to the diagnostic mode and the coin mechanism tilt switch function.

3. A cocktail flip screen mode.

4. A simulated colour overlay (the old skool red, green and white overlay).

5. Any other settings that existed in the original arcade Space Invaders.

There is also a lot of rambling comments / remarks to explain what each part of the emulator code does.

The emulator should run other 8080 based Taito Arcade games and bootlegs with a bit of adjustment on the memory array size, rom placing within the array and dipswitch / Input Port settings and assignments.

I have tried Lunar Rescue, Galaxy Wars and other Space Invaders variants / bootlegs and these seemed to run fine.

The full compiled release has additional support for Space Invaders Colour, Space Invaders Part II, Space Invaders Deluxe and Super Earth Invasion (Bootleg of Space Invaders).

I included Super Earth Invasion for one reason only. Its the version I remember playing as a kid back in the very early 80's.

It also includes a lot of "fluff" such as Bezels, Backgrounds and simulated colour cellophane overlays, and the whole thing runs from a select menu system making jumping between games a bit easier.

So what does the emulator contain?

1. Full Intel 8080 processor emulator including all opcodes and conditional flags.
2. Rom and ram area up to a maximum of 64 kB, the maximum that the 8080 with its 16-bit memory bus could address.
3. Emulated 16 bit Shift Register.
4. Video Display emulator including Interrupt generator.
5. Master and Secondary dip switch Input.
6. Inputs from Coin mechanism including Tilt Switch.
7. Inputs from Player Controls.
8. Sound Output simulator using sound samples.

I will follow this post up with some posts on the trickier aspects of the emulator, and how to overcome them.