Tuesday, 27 April 2021

Lunchtime Coder #8 - Space Invaders / INTEL 8080 Emulator with Dip Switches and IN Opcode

If you are writing an Intel 8080 based emulator then sooner or later you will come across the IN Opcode.

The IN Opcode enables the Intel 8080 processor to read inputs from external sources such as the coin mechanism, player start buttons and player controls, however there is other hardware within most arcade machines that interface with the IN Opcode inputs, and its not always straight forward to identify what they are, and what purpose they serve.

Unfortunately, as some of them need to be set for the game to run correctly, its important to know the external hardware that interfaces and how they relate to the inputs that will be read by the IN Opcode.

Its not always easy to find the information required. Getting the IN Opcode inputs correct relies on research and some experimentation. Whilst there is a lot of information on line, its not always accurate, and even the original arcade machine manuals can be misleading.

The Intel 8080 processor has 8 Input ports, IN 0 through to IN 7. Opcode 0xd8 is the IN Opcode, and then the first operand denotes which input port is to be read (0 to 7).

For me, the first step is finding out what IN Opcodes the game actually reads. This can be done with a simple debug routine that writes a text output to a file every time the IN Opcode is called and states which Input channel the Opcode is reading. Alternatively you could use a disassembler to take a look at the code and determine which Inputs are read, but remember that disassembled code can contain bitmaps that can mislead you as to what's actually stored in the rom.

So lets take Taito Space Invaders as an example:

Computerarcheology.com's Input Port Settings
Space Invaders Taito "Trimline" Manual

I started off researching on line, and there is a wealth of information to be found.

computerarcheology.com's excellent Space Invaders hardware page details the Input channels for the Space Invaders arcade cabinet.

Everything is there, however after running a debug log of my emulator, I found that the Space Invaders code doesn't read Input Port 0, so there is no requirement to consider this in an emulator. Original Space Invaders cabinets had a Test Mode as part of the romset. To access this test mode, dip switch 4 was set to On which set bit 0x01 on Input0. This test mode was removed from later romsets, along with the opcode to read Input0. I have checked the MAME romset for "Space Invaders / Space Invaders M" and it doesn't have the test mode code, and hence why the romset I'm using doesn't read IN0.

Input Port 1 for the most part is made up of user controls and coin mechanism input, so inserting a coin, 1P or 2P start and P1 left, right and fire should all be tied to bits in Input 1. The two undefined bits (0x08 and 0x80) can be set or unset. Having experimented with these, it makes no difference to the actual game whether they are on or off. The information above states that 0x08 is always set to 1, however this is in the actual arcade cabinet, and seems to have no affect on how the Space Invaders code runs.

Input Port 2 takes into account Dip Switch settings and P2 left, right and fire. Its also tied to the coin mechanism "Tilt" switch.

The Dip Switches are a row of 8 small switches (pictured at the top of this post) that switch between off and on. Adjusting these switches will adjust various parameters of the game. A thing to remember is that depending on the hardware "ON" can be a 1 or a 0. All "ON" means is the opposite state in 1 and 0 terms to "OFF". When the Space Invaders Trimline manual states "ON", it means set to 0.

In Space Invaders, Dip Switch 1 and 2 refer to Input 2 0x01 and 0x02 and define the number of lives that a player starts with (3 to 6), Dip Switch 4 refers to Input 2 0x08 which is the score at which a bonus life will be earned and Dip Switch 8 refers to 0x80 and determines whether the attract screen displays coin info or not.

Then there is Input 2 0x10, 0x20 and 0x40 which are player 2's control input and finally Input 2 0x04 which is input from coin mechanisms tilt switch.


A Generous Arcade Operator Giving 6 Lives Per Credit.
Yeah Like That Ever Happened...

The Tilt Switch Has Been Triggered !!!

Now You See The Coin Info....

Now You Don't...

Setting up the Input ports correctly means setting the initial value depending on the Dip Switch settings, and then allowing the value to be modified if a button / joystick / switch / coin is used. This value is then read into the Accumulator using the IN Opcode.

In our case above, Input 1 can start of at 0x00, 0x08, 0x80 or 0x88 and any of these values is fine for the emulator to run. According to the original hardware, it should have an initial fixed value of 0x08.

Then this value can be modified if the Insert Coin button is pressed, 1p or 2p button is pressed, P1 left, right or fire is pressed.

Input 2 should have an initial value depending on the settings of Dip Switches 1, 2, 4 and 8 according to the manual, or 3, 5, 6 and 7 according to the information above. Given that 1, 2, 4 and 8 correspond to bits 0x01, 0x02, 0x04 and 0x80 on Input 2 port, I'm inclined to go with the manual. It should also be understood that there is a large number of Hardware domestic and licensed versions for Space Invaders, and Dip Switch settings probably varied from version to version. As you can define what Dip Switches you use in your emulator, it doesn't really matter how you number them, as long as the correct one is tied to the correct bit in Input 2.

Input 2 can then be modified when P2 left, right or fire is pressed or when the Tilt switch button is pressed. The Tilt switch needs to be implemented as a button/trigger as setting it to 1 permanently will stop the emulator from running the game. Its the software equivalent of having the tilt switch jammed on permanently in the arcade cabinet.

Checking the MAME Driver Can Be Very Helpful

What if you have conflicting information? Well, its not difficult to go through each Input port setting bits and seeing what the effect is on the game, so trialling out the settings can always be a help.

If you are really stuck, or just want to confirm that your settings are correct, the MAME drivers in MAME source code can be a big help. In the case of Space Invaders, look at the mw8080.cpp / 8080bw.cpp drivers, and it will list the Input port settings for each 8080 game that MAME supports.

Space Invaders (CV) Colour:

Despite some slight code changes between Space Invaders and Space Invaders CV, the Input ports are mapped in exactly the same way.

Again the game doesn't read Input 0. Input 1 and Input 2 have the exact same Dip Switch mapping and the same Tilt, coin mech and player control mapping.

Easy!

Super Earth Invasion (Space Invaders Bootleg/Clone):

Again Super Earth Invasion doesn't read Input 0.

Input 1 is mapped as per Space Invaders with 0x08 and 0x80 not mapped to anything.

Input 2 differs to Space Invaders. The number of lives (2 or 3) is set using Dip Switch 1 only which is mapped to Input 2 0x01.

Dip Switch 2 switches the "Pence" mode on or off. Enabling the "Pence" mode means that the attract mode will mention UK 50p coins. This is mapped to Input 2 0x02.

Input 2 0x04 is mapped to Coin Slot 2. Coin Slot 2 is the UK 50p coin slot which will give you 3 or 5 credits per coin inserted depending on the coins per credit setting.

Input 2 0x08 is not mapped to anything. I have tried the game with this bit both set and unset, and it doesn't appear to have any bearing on the game.

Input 2 0x10, 0x20 and 0x40 are mapped to Player 2 controls.

Input 2 0x80 is set by Dip Switch 8 and is the coins per credit switch, either 1 coin=1 credit or 2 coins=1 credits. The 2 coins per credit gives the player 2 bonus lives.

There is no bonus score dip switch or tilt switch input.

Space Invaders Part 2 / Deluxe:

Space Invaders Part 2 / Deluxe DOES read Input 0, and if it isn't set correctly, the game will not play correctly.

Space Invaders Part 2 / Deluxe allows the highest scorer to input their name, and this name is then displayed above the high score value.

To reset this name back to default ("Taito" or "Midway"), there is a high score reset button, and this is mapped to Input 0 0x40.

The default setting for this is 1 or On, and to activate the reset high score button, its set to 0.

There is all sorts of issues with the gameplay if you leave this set to 0 all the time so ensure that this bit is set to 1 as default, and if you wish to implement a High Score Reset button in your emulator, the button press should set it to 0.

Again Input 1 is mapped as per Space Invaders with 0x08 and 0x80 not mapped to anything.

Input 2 differs to Space Invaders. The number of lives (3 or 4) is set using Dip Switch 1 only which is mapped to Input 2 0x01.

Dip Switch 2 is mapped to Input 2 0x02 and should rotate the screen, but it doesn't seem to work for me or for the MAME dev team.

Input 2 0x04 is mapped to the Tilt Switch.

Input 2 0x08 is mapped to Dip Switch 4 and switches the Preset mode On or Off. The Preset mode allows you to cheat basically to set the high score and the high score name. With the preset mode enabled, you can pump up the score before you start playing and hence guarantee that you achieve a high score and get your name in.

Input 2 0x10, 0x20 and 0x40 are mapped to Player 2 controls.

Input 2 0x80 is mapped to Dip Switch 8 and is the coin info switch as per the original Space Invaders.

There is no bonus score dip switch.

No comments:

Post a comment