
The schematic above is a Kempston-compatible joystick interface: the simplest and most widely supported way to use an Atari-style joystick on a 16K, 48K or Spectrum+ machine. It needs only two logic chips, a handful of resistors and a 9-pin D connector, which is why it is still one of the most popular first builds for Spectrum hardware hobbyists.
This guide walks through the circuit block by block, explains what the Spectrum sees when it reads the joystick, and finishes with a simple BASIC program to test a finished interface.
Why the Kempston standard won
The original Spectrum had no joystick port at all. Several standards appeared in the early 1980s: the Sinclair Interface 2, which made the joystick look like the number keys 6 to 0 (and 1 to 5 for a second stick); “Cursor” or Protek interfaces, which mapped the stick to keys 5, 6, 7, 8 and 0; and the Kempston interface, which gave the joystick its own input port.
Because a Kempston interface is read with a single instruction and does not clash with the keyboard, it became the de facto standard. Most games from the mid-1980s onwards offer it, and the Kempston port is still emulated by modern hardware such as the ZX Spectrum Next.
What the Spectrum reads: port 31
Software reads a Kempston interface with an IN instruction on port 31 (1F in hex). The bits are active high, so a value of 0 means nothing is pressed:
| Bit | Value | Meaning |
|---|---|---|
| 0 | 1 | Right |
| 1 | 2 | Left |
| 2 | 4 | Down |
| 3 | 8 | Up |
| 4 | 16 | Fire |
Diagonals simply add together, so up and right gives 9, and up plus fire gives 24. Bits 5 to 7 are normally 0, although a few later clones use bit 5 for a second fire button.
The schematic, block by block
1. The joystick connector and pull-up resistors
The DE9 connector on the right of the schematic follows the Atari wiring used by Atari, Commodore and most third-party joysticks: up, down, left and right on pins 1 to 4, fire on pin 6, +5V on pin 7 and ground on pin 8. This design also brings out extra buttons on pins 9 and 5.
A standard joystick is just a set of switches to ground. Each input therefore has a 10k resistor to +5V (the RN resistor network in the drawing), so the line sits at 5V when a switch is open and drops to 0V when it closes.
2. The inverting buffer (74LS540)
Because the switches pull lines low but the Kempston standard is active high, the signals have to be inverted. The 74LS540 is an octal inverting buffer with tri-state outputs: its eight inputs come from the joystick lines and its outputs connect to the data bus D0 to D7. Its two enable pins (G1 and G2) keep the outputs switched off, so the chip only drives the data bus when the computer actually reads the joystick.
Many original-era interfaces used a 74LS366 hex inverting buffer or a 74LS240 instead. They do the same job; the 540 simply has eight lines in a convenient flow-through pinout.
3. Address decoding (74LS138)
The 74LS138 is a 3-to-8 line decoder. In a typical Kempston design it watches the Z80’s I/O request, read and M1 signals, plus a few address lines, and pulls one output low only during an I/O read from the joystick’s port. That output enables the buffer.
Most commercial Kempston interfaces used partial decoding to save cost: many only check that A5 is low while IORQ and RD are active. That means the interface also answers on many other port numbers, which is harmless on its own but can clash with other add-ons. A full decode checks A5, A6 and A7 low, IORQ and RD low, and M1 high, so the interface never responds during an interrupt acknowledge cycle.
4. Power and decoupling
The two capacitors at the top left are decoupling capacitors across the supply pins of the chips. Keep them close to the ICs on your board; they stop switching noise upsetting the logic.
Building one safely
- Check your connector pinout twice. The 48K edge connector also carries +9V, +12V and -5V lines, so a short or an off-by-one connection can damage the computer.
- Never plug or unplug an interface while the Spectrum is switched on.
- Use sockets for the two chips so you can swap them while testing.
- If you put a through-connector on the back, other add-ons can be stacked behind the interface; just watch for port clashes caused by partial decoding.
Parts are cheap and easy to find: a 74LS138, a 74LS540, a 10k resistor network, a DE9 male connector, and a classic Atari-style joystick to test with. If you would rather not build one, ready-made Kempston-compatible interfaces are still made by small retro suppliers.
Testing the interface in BASIC
With the interface fitted and the Spectrum switched on, type this two-line program and RUN it:
10 PRINT AT 0,0;IN 31;" "20 GO TO 10
You should see 0 with the stick centred, and the values from the table above as you move it or press fire. If the number never changes, check the enable logic first. If it shows a random-looking value or 255 when idle, the buffer is probably not being enabled at the right time, or a pull-up is missing.
What about the Spectrum +2 and +3?
The Amstrad-made +2, +2A and +3 have built-in joystick ports, but they follow the Sinclair Interface 2 key mapping and use a non-standard pinout, so a normal Atari-style joystick will not work fully in them without an adaptor. A Kempston interface on the expansion port is the usual answer if you want Kempston support on those models.
Related guides
For more on the hardware side, see our guides to ZX Spectrum hardware mods, replacing the Spectrum voltage regulator and identifying your Spectrum model.
FAQ
What port does a Kempston joystick use?
Port 31 (1F hex). Bits 0 to 4 are right, left, down, up and fire, and are active high, so 0 means nothing is pressed.
Can I use a Mega Drive pad on a Kempston interface?
Atari-style digital joysticks and pads work. Sega Mega Drive pads use a select line to multiplex their buttons, so on a plain Atari-style port usually only the directions and one or two buttons work. Full button support needs an interface designed for Mega Drive pads.
Why does my Kempston interface conflict with another add-on?
Most Kempston designs only decode address line A5, so they respond on many port addresses. If another device uses one of those addresses, both drive the data bus at once. A fully decoded interface avoids this.
Do I need a Kempston interface for a Spectrum +2?
The +2 has built-in joystick ports, but they use the Sinclair key mapping and a non-standard pinout. For games that only support Kempston, or for an Atari-style stick, you still need a Kempston interface.
