Adding a Joystick to Your ZX81

Author(s): Dave Straub
Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v3 n6 (Volume 3, Issue 6)
Date: June 1982
Pages: 10-11

The principle behind joysticks is that the computer constantly scans the keyboard. When you press a key, you complete a circuit over the matrix-wired keyboard. Take the bottom off your computer and you’ll see two sets of connectors where the keyboard plugs into the computer. Connecting the proper combination of keyboard leads simulates a key depression. For this project you must use a momentary contact matrix wired joystick, not one using potentiometers. I used an Atari joystick. It is inexpensive and easy to get (ask any dealer who sells Atari game consoles). Unless you have the proper complement connector for your joystick, cut off the end of the cable. The Atari stick gives you 4 directions and a fire button. This results in 6 wires, 1 common and 1 each for each position and the button. Most matrix wired joysticks have only 1 common and fewer than 8 wires. First, find the common. This is the contact that, when coupled with another contact and the proper direction pushed on the stick, completes a circuit. Use an ohmmeter to check random pairs of wires for their resistance while moving the stick to all locations. When the resistance drops near 0, one of the wires is the common. Locate the common by elimination, then mark it with tape. Now take the bottom off your computer. With the metallic inside of the bottom panel facing you and the hole for memory expansion at the upper right corner, look at the right edge. At the location marked in Fig. 1 drill a 1/4″ hole. Put some wood directly under where you’ll drill. From the outside, stick the stripped wires from the joystick through the hole. With the heat sink in the bottom right corner, look to the left and find the pins shown in Fig. 2. Solder the common to any pin of KBD0-3. Solder the rest of the wires to pins 1-8 (diodes 1-8 on schematic). Avoid solder drips that cause short circuits. With the bottom still off, plug the computer in and hook it to the TV. You should be able to print characters to the screen by moving the stick around. If you get no response, carefully lift the computer and press some keys. If something appears on the screen, the problem lies in a poor solder joints or a faulty joystick. No keyboard response means the system is locked up from trying to read more than 1 input. You have either a short circuit where you soldered or a faulty joystick. If you don’t have a joystick and want an external control button, you can wire any switch to your computer. One wire must go to KBD0-3 and the other to pins 1-8. You can use INKEY$ to read these inputs, but this is too slow for some programs. I use PEEK 16421. This doesn’t give the character code; translate it to fit your needs. This program demonstrates the usefulness of your new stick. First, determine the code for each direction:

  10 SLOW
20 LET A=PEEK 16421
30 IF A=255 THEN GOTO 20
40 PRINT AT 19,20;A
50 SCROLL
60 GOTO 20

Try each position on the stick and button and write down the number produced. Now run this program:

  10 CLS
20 LET X=30
30 LET Y=20
40 SLOW
50 LET A=PEEK 16421
60 IF A=(CODE FOR UP) THEN LET Y=Y+1
70 IF A=(CODE FOR DOWN) THEN LET Y=Y-1
80 IF A=(CODE FOR LEFT) THEN LET X=X-1
90 IF A=(CODE FOR RIGHT) THEN LET X=X+1
100 IF A=(CODE FOR BUTTON) THEN RUN
110 PLOT X,Y
120 GOTO 50
Base of ZX81 - hole for RAM expansion connector (Figure 1)
Base of ZX81 – hole for RAM expansion connector (Figure 1)
ZX81 board wiring side - diode numbers 1-8 and KBD line numbers 0-4; do not solder above dotted line (Figure 2)
ZX81 board wiring side – diode numbers 1-8 and KBD line numbers 0-4; do not solder above dotted line (Figure 2)