The ZX Breadboarder: A Proportional Joystick Interface

Author(s): Fred Nachbaur
Publication: ZX-Appeal
Date: March - April 1989
Pages: 12-15

Project #1

For the ZX81, TS1000, TS1500 and PC8300-T

Here is a little project for kitters, tinkerers, and other hardware hackers. No exotic parts, yet gives you a wonderful pointing and control tool. Immediately position a cursor anywhere on the screen (32×24), play “Flight Simulator” like it was supposed to be, and stay tuned for other wonderful modified programs that are waiting in the wings!

The hardware is designed around the software, which was designed around the hardware. I think that Wilf Rigter will get a chuckle out of it. The simple hardware (3 cheap chips) is read by an equally simple software routine (3 Z80 commands). The software routine is nestled into a copy of the keyboard routine (02BB) which is called instead by the vertical sync interrupt routine (SLOW mode processor), so the joystick is in a sense “interrupt driven,” even though such shenanigans are supposedly not possible on the ZX.

FREEBIE DEPT: Anyone who wishes may do anything he/she wishes with this hardware design and artwork. The software in this article are equally in the public domain. If some enterprising fellow wants to put these together for sale to others, he has my full permission (and condolances).

MORE FREEBIES: I wrote up a fairly thorough article on this beast, which is recommended reading for PJI experimenters. Plus, you just might pick up a couple other things on the side. It is being made available to the Vancouver ZX User Group, who may make copies available to others at nominal cost.

Also available are two PJI-compatible games. “JOY-FLIGHT” is the Psion/Timex Flight Simulator adapted for the PJI. The program’s realism takes a quantum leap with the use of a proportional joystick. “JOY-BUST” is the excellent “Breakout” program, with a twist. (Stand by for Merchant of Venus, PJI style.)

Schematic: Proportional Joystick Interface for ZX81 V2.0 by Fred Nachbaur, S.M.C.
Schematic: Proportional Joystick Interface for ZX81 V2.0 by Fred Nachbaur, S.M.C.
C1 -     .002 uFd. disc or mylar capacitor
C2 -     .0015 uFd. disc or mylar capacitor
C3,C4 -  .01 uFd. disc capacitors
D1,D2 -  1N4148 or 1N914A glass diodes
IC1 -    74LS32 quad 2-input OR gate
IC2 -    NE556 dual timer
IC3 -    74LS125 quad tri-state buffer
J1 -     100K Proportional Joystick,
         Radio Shack 26-3008 or equivalent
P1 -     46-pin edge connector, .100" spacing,
         key at position 3
P2 -     46-trace expansion connector,
         slot at position 3
R1 -     100K, 1/4W 5% film resistor
R2 -     160K, 1/4W 5% film resistor
R3 -     2.2K, 1/4W 5% film resistor
R4,R5 -  1K, 1/4/W 5% film resistors
VR1,2 -  100K linear trimpots

THE HARDWARE

PC board artwork, P.J.I. #2, FN 1989
PC board artwork, P.J.I. #2, FN 1989

PC BOARD ARTWORK

Copy this actual-size artwork to a sheet of photo-copy mylar. Your local copy shop should be able to help you out for under $2. Expose, develop, etch and drill the board. Tin-plate if desired. Fix any breaks.

Install the eight wire jumpers on the component side. (These are non-intersecting, so you can use a 2-sided board if you’re a perfectionist. Harry, I’d love to see your board when it’s done.)

Install the 3 14-pin DIP sockets. Before installing the socket for IC2, run a 30 AWG bare jumper through pins 4 and 10 before inserting the socket to solder it. Alternately, jumper these two pins with a piece of resistor wire-end on the wiring side. Install the 5 resistors, 2 diodes and 4 capacitors. See the component layout diagram.

Use a DIP header, 1/2 of a DIP socket, or whatever (spacing is .200″) to connect to the joystick, which has been modified as per the schematic.

Install the edge-connector and finger board, or make other arrangements for connecting to your computer. Install the trimpots. If you can’t find the little cermet jobs with .100″ lead spacing, use silicone, wire, and bubble-gum as required.

Alternately, wire it up on a piece of plated perf-board. It’ll probably be done a lot faster that way anyhow.

To make the component layout diagram work as an “overlay” for your board, reduce it to 97%.

Component layout, Proportional Joystick Interface
Component layout, Proportional Joystick Interface

PJI SOFTWARE

LISTING 1: MACHINE-CODE LOADER

   1 REM XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
9000 REM M/C LOADER
9020 CLS
9030 PRINT "ADDRESS? ";
9040 INPUT AD
9050 PRINT AD,"BYTES? ";
9060 INPUT BY
9070 PRINT BY
9080 FOR N=AD TO AD+BY-1
9090 INPUT V
9100 POKE N,V
9110 PRINT (STR$ (V+1000))(2 TO );":";
9120 NEXT N
9130 STOP

TABLE 1: PROP. JOYSTICK MACHINE CODE, DECIMAL VALUES

ADDRESS? 16624  BYTES? 90

001:031:031:033:130:064:237:178:
211:255:042:012:064:203:252:205:
146:002:237:095:001:001:025:062:
245:205:181:002:043:205:146:002:
195:162:064:000:000:000:000:000:
221:033:162:064:201:253:070:052:
058:052:064:184:040:250:033:130:
064:001:000:000:030:031:203:102:
040:001:012:203:110:040:001:004:
035:029:032:242:062:023:184:048:
001:071:043:126:230:192:050:022:
065:201:

LISTING 2: ROM-CODE UPLOADER

8000 LET AD=16546
8005 FOR N=553 TO 630
8010 POKE AD,PEEK N
8015 LET AD=AD+1
8018 NEXT N
8020 STOP

LISTING 3: JOYSTICK MACHINE-CODE

addr HEXCODE   NAME MNEMONIC
=========================
40A2 2A3440 DP-1 LD HL,(FRMS)
40A5 2B DEC HL
40A6 3E7F DP-P LD A,7F
40A8 A4 AND H
40A9 B5 OR L
40AA 7C LD A,H
40AB 2003 JR NZ ANTH
40AD 17 RLA
40AE 1802 JR OVNC
40B0 46 ANTH LD B,(HL)
40B1 37 SCF
40B2 67 OVNC LD H,A
40B3 223440 LD (FRMS),HL
40B6 D0 RET NC
40B7 CD6B02 DP-2 CALL KBSC
40BA ED4B2540 LD BC,(LASK)
40BE 222540 LD (LASK),HL
40C1 78 LD A,B
40C2 C602 ADD A,02
40C4 ED42 SBC HL,BC
40C6 3A2740 LD A,(DBNC)
40C9 B4 OR H
40CA B5 OR L
40CB 58 LD E,B
40CC 060B LD B,0B
40CE 213B40 LD HL,CDFG
40D1 CB86 RES 0,(HL)
40D3 2008 JR NZ NKEY
40D5 CB7E BIT 7,(HL)
40D7 CBC6 SET 0,(HL)
40D9 C8 RET Z
40DA 05 DEC B
40DB 00 NOP
40DC 37 SCF
40DD 212740 NKEY LD HL,DBNC
40E0 3F CCF
40E1 CB10 RL B
40E3 10FE LP-B DJNZ LP-B
40E5 46 LD B,(HL)
40E6 7B LD A,E
40E7 FEFE CP FE
40E9 9F SBC A,A
40EA 061F LD B,1F
40EC B6 OR (HL)
40ED A0 AND B
40EE 1F RRA
40EF 77 LD (HL),A
40F0 011F1F LD BC,1F1F
40F3 218240 JOYS LD HL,BUFR
40F6 EDB2 INIR
40F8 D3FF D-ON OUT (FF),A
40FA 2A0C40 LD HL,(DFIL)
40FD CBFC SET 7,H
40FF CD9202 CALL MRGN
4102 ED5F LD A,R
4104 010119 LD BC,1901
4107 3EF5 LD A,F5
4109 CDB502 CALL SCRN
410C 2B DEC HL
410D CD9202 CALL MRGN
4110 C3A240 JP DP-1
4113 00 NOP
4114 00 NOP
4115 00 NOP
4116 00 BUTN NOP
4117 00 NOP
4118 DD21A240 ENGA LD IX,DP-1
411C C9 RET
411D FD4634 DCOD LD B,(FRMS)
4120 3A3440 WAIT LD A,(FRMS)
4123 B8 CP B
4124 28FA JR Z WAIT
4126 218240 LD HL,BUFR
4129 010000 LD BC,0000
412C 1E1F LD E,1F
412E CB66 LOOP BIT 4,(HL)
4130 2801 JR Z NO-X
4132 0C INCX INC C
4133 CB6E NO-X BIT 5,(HL)
4135 2801 JR Z NO-Y
4137 04 INCY INC B
4138 23 NO-Y INC HL
4139 1D DEC E
413A 20F2 JR NZ LOOP
413C 3E17 OVR? LD A,17
413E B8 CP B
413F 3001 JR NC BUT?
4141 47 LD B,A
4142 2B BUT? DEC HL
4143 7E LD A,(HL)
4144 E6C0 AND C0
4146 321641 LD (BUTN),A
4149 C9 RET

LISTING 4: BASIC DEMO AND JOYSTICK CALIBRATION

   2 REM  USR 16664 TO ENGAGE
3 REM USR 16669 TO DECODE
4 REM PEEK 16662 => BUTTONS
9 REM basic demo+calibration
10 REM BY F.NACHBAUR, S.M.C.
15 RAND USR 16664
20 LET D=16669
30 LET B=16662
40 POKE 16418,0
42 LET X=0
44 LET Y=0
46 POKE 16418,0
50 PRINT AT Y,X;" ";AT 0,0;"O";AT 0,31;"O";AT 23,0;"O";AT 23,31;"O"
55 LET L=USR D
60 LET Y=INT (L/256)
70 LET X=L-256*Y
75 LET A$=(CHR$ 23 AND NOT PEEK B)+(CHR$ 128 AND PEEK B)
80 PRINT AT Y,X;A$
90 GOTO 50

ENTERING THE SOFTWARE

Use Listing 1 to enter the decimal values of Table 1 into a 1 REM line. Then use Listing 2 to steal the required code from the ROM. Finally use Listing 4 to calibrate and demonstrate the use of the joystick. Listing 3 is the source-code of the machine-code in the 1 REM.

FUN AND GAMES DEPARTMENT: Change the LD HL,nnnn at JOYS (40F3) to point instead to the first byte of the display file. Now engage the joystick with RAND USR 16664. You get a graphic demonstration of what “interrupt driven” means, as you move the joystick around. Just don’t press the button! (However, “button 2” would be allowable.) Incidentally, this was my best debugging tool during development.

Improvements have been and will continue to be made to the DCOD decoding routine. Join in the fun!

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.