Use the Spectrum 128 style menu below to navigate to the various sections detailing the keypad.

Keypad Main Menu Title
View History Of The Keypad
View Appearance Of The Keypad
View Editing Functions Available Via The Keypad
View Method Of Operation
View Communication Details
View Timing Details
View Hardware Details
View Software Details
View Details About Building A Compatible Keypad

Software Details

The 48K BASIC ROM in the Spectrum 128 contains all of the routines used to communicate with the keypad and these occupy locations 386Eh to 3B3Bh. The flow diagrams below describe the logical process of reading the keypad but do not make reference to the timing details involved. For information on the timing aspects refer to the previous section entitled Timing Details.

Note that in the following flow diagrams Register 14 refers to the AY-3-8912 sound generator, and NZ, Z, C and NC representing zero flag reset, zero flag set, carry flag set and carry flag reset respectively.

Reading The Keypad (39A0h)

Reading the keypad involves polling it to establish communications. The five rows are then read in. Prior to reading each row's nibble of data a key press status bit is read. Only if this indicates that at least one key is being pressed in the row will the row's nibble of data be read. The IX register is used to point to the location where the read in nibbles are to be stored. Once all five row nibble have been obtained they are decoded to form a unique key code in the E register.

Read Keypad Flow Chart

Polling The Keypad (3938h)

Polling the keypad involves setting the output line to the keypad and verifying that the input line reflects these soon after. If the keypad responds when the output line is set and responds again when the output line is then reset, the Spectrum 128 attempts to read in a nibble of data from the keypad. This nibble must have its second most significant bit set; the states of the other bits are unimportant.

Poll Keypad Flow Chart

Reading A Nibble / Bit (38D8h / 38DFh)

This routine is used to obtain a nibble of data or a single bit of data from the keypad. This is achieved using a loop counter which is set it to a value of 4 or 1 respectively.

Read Nibble / Bit Flow Chart

A commented disassembly of the keypad communication routines contained within the 48K BASIC ROM of the Spectrum 128 is available here for viewing or downloading. It also documents a fifteen entry vector table contained within the EDITOR ROM that points to useful routines within both ROMs, including one for scanning the keypad. The table is designed to allow machine code programs to reliably access these routines even if subsequent versions of the ROMs stored them at different locations. However, due to a programming error the keypad scanning entry does not work. The disassembly file is stored in PDF format and hence Adobe Acrobat Reader is required.

Click here to view the ROM disassembly of the Spectrum 128's keypad communication routines.

Full disassemblies of the Spectrum 128 ROMs, along with disassemblies of the Spectrum +2 ROMs, and Spanish Spectrum 128 ROMs are also available.