Friday, 23 April 2021

Lunchtime Coder #6 - Space Invaders Part II /Deluxe Emulator in Blitz3D / Blitz Basic

So once you have a few games running on your emulator successfully, the process of adding more games gets easier right? Wrong!

Every game added comes with its own individual issues to resolve, but then that's the fun of writing emulators.

The Space Invaders Part 2 romset comes as five 2 kB roms and two 1 kB eproms.

The first four 2 kB roms go into the bottom 8 kB of the memory area 0x0000 to 0x1FFF (as per Space Invaders and Space Invaders CV). The fifth 2 kB rom goes in above the screen ram area at 0x4000 to 0x47ff.

The two 1 kB eproms are colour maps for "Everything but player two playing" and "Player two playing".

I took a quick peek at the colour map eproms expecting similar / the same as for Space Invaders CV.

This time, the values are offset by 8 so instead of the eight different colours ranging from 0 to 7, they now range from 8 to 15.

The colour maps themselves also differ from Space Invaders CV slightly.

The screen turns red on the fly when a base is hit, so again I used the Intel 8080 Output Port 3 Bit 0x04, the trigger for sound sample for base being hit to control the trigger and duration of screen going red. Basically the same method that I used in Space Invaders CV.

I also used the same method to detect when Player two is on screen as I did with Space Invaders CV. This is the cocktail screen flip bit in Intel 8080 Output Port 5, Bit 0x20. When set to 1, player 2 is playing.

All good so far. So with the roms in place, the eproms integrated into the drawing routine and a few tweaks to the dip switch settings, I ran up the game.

I should point out that my Intel 8080 emulator now has all 256 opcodes and all 5 conditional bits / flags implemented, so no additional opcodes to throw into the code this time.

Issue 1: There was an erroneous manufacturers logo on the opening screen. This shouldn't be there.

Issue 2: When that logo is meant to be there on completion of the opening screen drawing, it should flash between the manufacturers name and the word "HI-SCORE". This wasn't happening either. Just a fixed manufacturers name.

Issue 3: All sorts of bizarre effects when you get in game / attract mode game, from graphic artefacts to resetting back to the opening screen.

It seemed to me that the interrupts were occurring too quickly, as in before the code had reached the point that it was waiting for an interrupt.

My first attempted resolution was to speed up the processor clock by allowing more processor clock pulses between each interrupt. This actually resolved issue 3, and the game became playable without any artefacts. The speed of the processor was now at 3.125 MHz which by chance is the same speed that an Intel 8080b runs at.

However MAME insists that this game should run on a 2 MHz Intel 8080, and I still had the issues with the manufacturers logo on the opening screen. Something was definitely not right.

I decided to go back to basics, and activate the debug log, and this was what saved the day.

I noticed an IN 0 opcode being run which means that the processor is reading Input Port 0. The romset versions of Space Invaders / Space Invaders CV / Super Earth Invasion didn't read Input Port 0, so for emulation purposes, Input 0 can be set to 0, or just ignored.

But...If its being read by the code, then there must be something to read in Input 0.

By a process of elimination, I set each bit in turn on Input 0 to 1, and ran the game... and Bingo! 0x40 set to 1 cleared all 3 issues.

There was some paranoia about people typing in rude names when they achieved the high score, so Taito supplied a "Reset High Score" button which is tied to 0x40 of Input Port 0.

The reason that the emulator hadn't been working correctly was that I was running it with this button permanently pushed down. This meant that additional code was running between interrupts and the program wasn't ready for the interrupts to happen, and this is why running it with more time between interrupts solved some of the issues.

Setting this bit to 1 resolved all of the issues.

Taito also provided a "Preset Mode" which I found by accident by setting what I thought was the bonus score dip switch.

The Preset mode enables you to set a score before you start the game, so in effect, cheat! This was so that arcade operators could set high scores higher and put in their own custom names as the high scorers.

Interestingly, The manuals for Space Invaders part 2 and Space Invaders Deluxe do not mention the High Score reset button. The preset mode is mentioned in the Space Invaders Deluxe manual.

Another game successfully emulated.