Hacker's Delight:
EOS Game Controller Input
by Dr. Solomon Swift

Editor's Note: This article originally appeared in the September issue of Nibbles & Bits, page 11.

The game controllers are read through any of the double port pairs starting at number 224. These same ports are used by the sound chip for output. Thus, it is not possible to send a value OUT to a PDL. The values are read in conjunction with the strobe port. When the strobe port is reset (OUT $C0 or OUT 128), the right trigger, keypad, and the two lower super action triggers can be read. The returned keypad values need to be converted from the pin codes to binary values. In addition to all of this, you need to compliment the read value and then mask out certain bits to get the correct input values.

To avoid these complexities, you may utilize the EOS "read game controllers" routine. It is the 91st vector in the EOS jump table. The jump table address is 64830 (64, 253). And, the actual routine is at address 57939 (83, 226).

Before using either CALL option, the accumulator and IX must be set up. The index register should contain a pointer to your 10 byte decoded input buffer. Load the accumulator with one of the following values:

1 = Read REAR Only
2 = Read FRONT Only
3 = Read Both Controllers

There is also an option to read the spinner with this routine, but it doesn't work correctly. In fact, this routine actually resets the spinner's EOS buffer values. We'll discuss this in a later issue and how to correct the bug.

The user input buffer is formatted as follows:

Byte 0: REAR Joystick
Byte 1: REAR Left Trigger
Byte 2: REAR Right Trigger
Byte 3: REAR Keypad
Byte 4: REAR Spinner (Has Bug)
Byte 5: FRONT Joystick
Byte 6: FRONT Left Trigger
Byte 7: FRONT Right Trigger
Byte 8: FRONT Keypad
Byte 9: FRONT Spinner (Has Bug)

After CALLing the EOS routine, you can check the appropriate address in the buffer for a particular input.

Next month we'll continue our study of this routine and correct another minor bug with it (in decoding the keypad inputs). For further study, you might want to examine last month's MoreKeys program and the disassembled routines for it.

Back to Top