It takes just $10 and a few hours, writes James C. Righter
WHILE the low cost of the T/S1000,ZX81 is a strong selling point, not having a joystick input is one of the drawbacks of a no-frills machine. Fortunately, a joystick input can be added for a low cost (less than $10) and a few hours’ time. Some decent games are on the market for the T/S,ZX, or you can write some, that make good use of a joystick control. In particular, two games sold commercially, Mazogs and Flight Simulation, seem to be naturals for a joystick control. After playing these two using the keyboard controls, I decided that a joystick control would be a great improvement.
First we will look at the interface circuit, then some example programs.
Circuit Details
Only three integrated circuits and a handful of parts are needed to construct the interface circuit. All materials are readily available at Radio Shack stores with the exception of an Atari* joystick or one of its clones.
The Atari* joystick was chosen because of its simplicity of having switches instead of variable resistors. The joystick has five normally open switches that are closed whenever the stick is moved or the “fire” button is pressed. Moving the stick to the top or forward position closes one switch, while moving the stick back to the bottom position allows the top switch to open and closes the bottom switch. The same goes for left and right movement of the stick and when the button is pushed. All switches are open when the stick is in the neutral position and the button is not pressed.
*Atari is a registered trademark of Atari Inc.
A block diagram of the interface circuit is in Figure 1, and consists of a one-of-eight decoder (74LS138), an or gate (74LS32) and an octal non-inverting buffer (74LS244). The first integrated circuit (IC1) functions as an address decoder for lines A13 through A15 of the T/S,ZX. IC1 is enabled when the memory request line (MREQ) from the computer goes low. When this happens one of the eight output lines of the decoder chip goes low (15 through 9 and 7). Which of the decoders output lines goes low depends on which addresses within an 8K segment are chosen. Each segment or 8K block of addresses and the status of the decoders output lines are shown in Figure 2. In this circuit line 10 was used so the addresses were well above the 16K RAM addresses. Line 10 from IC1 along with the read-enable line (RD) from the computer are combined in an or gate of IC2 to form the enable line (IN) that turns on the three-state buffer (IC3). Normally the input buffer is in a high impedance state until the correct address, a memory request signal and a read-enable signal are output from the computer. Only when all of these signals are present on the computer’s buss will the data lines from the computer “read” the input from the buffer. Information read in from the buffer can then be stored in memory for later use or discarded as the program dictates.

Segment Address Line #
(n)
1 0 to 8191 15
2 8192 to 16383 14
3 16384 to 24575 13
4 24576 to 32767 12
5 32768 to 40959 11
6 40960 to 49151 10
7 49152 to 57343 9
8 57344 to 65535 7
Figure 2. Any address within these 8K segments makes line (n) low. Decoder I.C. 74LS138.
There are probably as many ways to decode the address lines from the computer as there are hardware designs to do so, but this is a simple, inexpensive scheme that works well for this purpose. This particular scheme is generally referred to as being memory mapped as opposed to input/output mapped. Machine language must be used with the T/S1000,ZX81 when input/output decoding is used because there are no specialized instructions contained in the T/S,ZX BASIC language for that purpose. In contrast, memory mapped decoding will work with PEEKs and POKEs (in BASIC) as well as machine language. The circuit that has been discussed here will also work with the 16K RAM unattached.
Any convenient way of constructing the circuit is fine, as there is nothing at all critical about the layout. One of the universal printed circuit boards from Radio Shack works well, or you may find perfboard more to your liking. Whichever way you choose to wire the circuit, be it point-to-point, wire-wrap, or a custom made printed circuit board, it is best to use sockets for the integrated circuits. This eliminates the danger of ruining an integrated circuit while soldering.
Sixteen conductor ribbon cable can be used to attach the completed circuit to the computer. Each conductor or wire should be soldered very carefully to the appropriate buss line of the computer. The T/S,ZX circuit board should be removed from the case for this operation, so the wires can be attached at least a one-half inch from the edge of the board. This will allow the RAM connector room to slide onto the edge of the computer’s edge connector. A slot can then be cut in the side of the case (a heated knife works well) for the cable or wires to exit. Keeping the ribbon cable as short as possible will alleviate the interference problem of the television display.
Keep in mind that any soldering or cutting on the T/S,ZX will void the warranty. If the appropriate connectors can be located or made for a feed-through buss, the case need not be opened or any soldering done on the computer circuit board.
Attaching the joystick to the interface circuit can be accomplished with a detachable plug, a header, or hard-wiring directly to the circuit. The diagram in Figure 1 illustrates how the Atari* joystick should be wired to the interface circuit. The color-coded wires are exposed by cutting off the female connector at the end of the joystick cable and stripping back the outer cover. Each colored wire can then be used as a guide for connecting the joystick to the interface circuit. After the circuit has been assembled and all soldering has been completed, check the circuit for solder bridges and shorts before applying power.
Example Programs
If you are satisfied that your interface circuit is in good working order, turn the computer power on and check if the cursor is on the left-bottom part of the display screen. If after a moment or two the cursor does not appear on the screen, immediately disconnect the power and check the circuit for wiring errors, shorts, and so on. When the interface circuit is working correctly, enter and run the test program in Listing 1. For the programs in this article to work, the joystick must be wired as shown in Figure 1. If a problem still exists with running the test program, again power down and check the circuit for wiring errors and shorts.
Listing 1.
10 LET A=PEEK 46000 Address of input port
20 IF A=31 THEN GOTO 10 If in neutral, try again
30 SCROLL
40 IF A=30 THEN PRINT "UP" 30=up pos. of stick
50 IF A=29 THEN PRINT "LEFT" 29=left pos. of stick
60 IF A=27 THEN PRINT "RIGHT" 27=right pos. of stick
70 IF A=23 THEN PRINT "DOWN" 23=down pos. of stick
80 IF A=15 THEN PRINT "BANG" 15=button pressed
90 GOTO 10
Of course you may choose to wire the joystick differently, but the programs used here must be changed to reflect those differences.
Programs in Listings 3, 4 and 5 are written in machine code and make use of the joystick interface. A short program in Listing 2 may be used to enter the code from the programs. To use the code-entering program, enter a starting address and then begin entering the code: for example type 58 and hit enter, type 0 and hit enter, and so on. When you wish to terminate the program, enter any letter and the program will stop with an error code. Remember to enter the line 2 REM statement with 50 Xs before entering the machine code.
Listing 2.
2 REM XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3 PRINT "ENTER STARTING ADDRESS"
4 INPUT A
5 PRINT "ENTER CODE IN DECIMAL"
6 INPUT B
7 POKE A,B
8 SCROLL
9 PRINT A, PEEK A
10 LET A=A+1
11 GOTO 6
Programs in Listings 3 and 4 are for use with the games mentioned at the beginning of this article. Mazogs is distributed by Bug-Byte, Flight Simulator by Timex-Sinclair. It can only be assumed that each cassette sold is identical to the ones I used. If you have either or both of these games, load one into the computer. After loading is complete, hit the break key to stop the program. Enter LIST 2 and note what is in lines 2 through 11 of the program. If any lines contain something other than REM statements, write it down so it can be re-entered later. Now enter the line 2 REM statement with 50 Xs and the program in Listing 2. After entering the code from Listing 3 or 4 to the addresses indicated, delete the code-entering program; do not delete the line 2 REM statement, though. Re-enter any lines that you may have deleted earlier from the original game program. The procedure outlined above is used for both games. The keyboard of the computer should function normally for both.
Listing 3. Code to Mazogs program.
Address Dec. Code Mnemonic
16606 205, 221, 81 CALL 20957
16609 201 RET
Write code to #2 REM statement with 50 Xs.
Address Dec. Code Mnemonic
20957 58, 0, 176 LD A, (46000)
254, 31 CP 31
40, 28 JR Z, EXIT
254, 30 CP 30
32, 3 JR NZ, LEFT
62, 8 LD A, 8
201 RET
254, 29 LEFT CP 29
32, 3 JR NZ, RIGHT
62, 96 LD A, 96
201 RET
254, 27 RIGHT CP 27
32, 3 JR NZ, DOWN
62, 80 LD A, 80
201 RET
254, 23 DOWN CP 23
32, 3 JR NZ, EXIT
62, 6 LD A, 6
201 RET
167 EXIT AND A
33, 255, 255 LD HL, 255,255
237, 75, 37, 64 LD BC, (16421)
237, 66 SBC HL, BC
124 LD A, H
133 ADD A, L
21004 201 RET
Listing 4. Code to Flight Simulation program.
Address Dec. Code Mnemonic
17316 205, 247, 75 CALL 19447
Write code to #2 REM statement with 50 Xs.
Address Dec. Code Mnemonic
19447 58, 0, 176 LD A, (46000)
254, 31 CP 31
40, 32 JR Z, EXIT
254, 30 CP 30
32, 4 JR NZ, DOWN
33, 239, 239 LD HL, 239, 239
201 RET
254, 23 DOWN CP 23
32, 4 JR NZ, LEFT
33, 239, 223 LD HL, 223, 239
201 RET
254, 29 LEFT CP 29
32, 4 JR NZ, RIGHT
33, 247, 223 LD HL, 223, 247
201 RET
254, 27 RIGHT CP 27
32, 4 JR NZ, EXIT
33, 239, 247 LD HL, 247,239
201 RET
205, 187, 2 EXIT CALL KSCAN
19489 201 RET
Listing 5 contains a program for drawing lines horizontally and vertically using the joystick to control the direction of the plotted or unplotted line. This program makes use of the plot routine in the ROM and can be run in the slow mode. The program is not tied to any address, so it can be entered and used at any location in RAM that you desire. Possibly the best place would be a REM statement (with 150 Xs) entered as the first statement in program memory. Code entered into a REM statement has the advantage of being saved easily for later use.
Listing 5. Linedraw with joystick (150 bytes).
ADDRESS DEC. CODE MNEMONIC COMMENT
16514 42, 123, 64 START: LD HL, (16507) Coords plot pos.
(Addresses 58, 176, 179 LD A, (46000) Load A port status.
used for 254, 15 CP 15 Check button status.
locating 40,112 JR Z PLOT/UNPLOT If button pressed.
code in 254, 27 RIGHT: CP 27 Check stick status
REM state. 32, 9 JR NZ, LEFT Check left.
Can be 44 INC L Add one to horizontal
located 125 LD A,L plot position.
any- 254, 64 CP 64 Check if off screen.
where.) 32, 40 JR NZ,PLOT If not got to plot.
45 DEC L Subtract 1 from plot
24, 37 JR,PLOT position
254, 29 LEFT: CP 29 Check stick status.
32, 9 JR NZ,UP Go to up.
45 DEC L Subtract 1 from plot
125 LD A,L position.
254, 255 CP 255 Check if off screen,
32, 27 JR NZ,PLOT If not go to plot.
44 INC L Add 1 to plot pos.
24, 24 JR,PLOT
254, 30 UP: CP 30 Check stick status.
32,9 JR NZ,DOWN Check down.
36 INC H Add 1 to vertical
124 LD A,H plot position.
254, 44 CP 44 Check if off screen.
32, 14 JR NZ,PLOT If not go to plot
position.
37 DEC H Subtract 1 from plot
24, 11 JR,PLOT position.
254, 23 DOWN: CP 23 Check stick status
32, 7 JR NZ, PLOT Go to plot.
37 DEC H Subtract 1 from plot
124 LD A,H position.
254, 255 CP 255 Check if off screen,
32, 1 JR NZ,PLOT If not go to plot.
36 INC H Add 1 to plot pos.
68 PLOT: LD B,H Load coords from
77 LD C,L HL into BC.
34, 123 ,64 LD (16507),HL Store plot coords.
237, 67, 54, 64 LD(16438),BC Last point plotted.
62, 75 LD A,75 Plot/unplot status.
50, 48, 64 LD(16432),A T-ADDR
205, 178, 11 CALL ROM Plot routine in ROM
17, 0, 9 LOOP: LD DE,900 Determines delay.
27 DELAY: DEC DE Delay loop.
122 LD A,D
179 OR E
32, 251 JR NZ,DELAY
58, 33, 64 LD A,(16417) Plot/unplot status.
254, 0 CP O If p/u not changed,
32, 12 JR NZ,EXIT GOTO to exit routine.
237, 75, 123, 64 LD BC,(16507) Retrieve plot coords.
62,0 LD, A,0 Change plot to unplot.
50, 48, 64 LD (16432),A T-ADDR
16615 205, 178, 11 CALL ROM Plot routine in ROM .
16618 167 EXIT: AND A Reset carry.
33, 255, 255 LD HL,255,255
237,75,37,64 LD BC,(16421) Keyboard scan.
237, 66 SBC HL,BC Check what key
124 LD A,H pressed.
133 ADD L
254, 3 CP 8 Check if "W" is pressed,
200 RET Z If so exit program.
24, 134 FAR: JR,START Go to beginning.
17, 0, 80 PLOT/UNPLOT: LD DE 5000 Determines delay time
27 DELAY: DEC DE for button status.
122 LD A, D Delay loop
179 OR E
32,251 JR NZ,DELAY
58, 33, 64 LD A,(16417) Plot/unplot status.
254,0 CP O If unplot,
40,7 JR Z,SETPLOT Goto setplot.
62,0 SET UNPLOT: LD A,O Change plot to unplot.
50,33,64 LD(6417), A Store p/u status.
24,232 JR, FAR Go to start
62,75 SETPLOT: LD A,75 Change unplot to plot.
50, 33, 64 LD (16417), A Store p/u status
16662 24,225 JR, FAR Go to start
16664 End of Program.
After the code has been entered for the line-draw routine, run the program by entering a program line in BASIC: 10 LET L=USR (your address). To stop the program hit the “W” key on the keyboard. To plot a line press the “fire” button on the joystick once; to unplot press the button again. The first delay in the program may be changed to a larger or smaller value. For instance, LD DE,900 could be changed to LD DE,200 for faster plotting or a larger value entered for slower plotting.
Hopefully, this article has aroused your imagination. If you have any ideas for the joystick interface, I would like to hear about them: write to me care of this magazine. (Please include a self-addressed, stamped envelope if a reply is expected.) The Timex Sinclair computer can be used for solving serious problems, but why not have a little fun, too? We deserve it!
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.