Diagonal Movement

See all articles from SINCUS v1 n9

If you have always wanted a joystick for your Sinclair, but were a little intimidated about making hardware modifications, the article -“Adding a Joystick to the Timex-Sinclair 1000” by James Stephens, SYNC, Vol 3, No 4 Jul/Aug 1983, page 52 is for you. It shows a simple inexpensive way to add an atari type joystick.The only catch is that the program listed in the article provides only for up-down and left – right movement – it will not do the diagonals. The following program uses the system variable LAST K instead of the function INKEY$. LAST-K (PEEK 16421 + 256 * PEEK 16422), provides a useful value even with two or more keys simultaneously depressed, exactly what we need for diagonals. The program is a little slow as it stands, but it maybe compiled (using Bob Beach’s compiler), without changes. The resulting machine code is surprisingly fast.

The program listing:

001  SLOW
005 LET X = 20
007 LET Y = 20
010 LET A = PEEK 16422
015 LET B = PEEK 16421
020 IF A = 255 THEN GOTO 10
040 IF A <> 223 THEN GOTO 80
050 IF B <> 239 THEN GOTO 60
052 LET Y = Y - 1
056 GOTO 500
060 IF B <> 247 THEN GOTO 70
062 LET X = X - 1
066 GOTO 500
070 LET X = X - 1
072 LET Y = Y - 1
076 GOTO 500
080 IF A <> 239 THEN GOTO 100
085 LET Y = Y + 1
090 GOTO 500
100 IF A <> 247 THEN GOTO 130
110 LET X = X + 1
120 GOTO 500
130 IF A <> 207 THEN GOTO 170
140 LET X = X - 1
150 LET Y = Y + 1
160 GOTO 500
170 IF A <> 215 THEN GOTO 210
180 LET X = X + 1
190 LET Y = Y - 1
200 GOTO 500
210 IF A <> 231 THEN GOTO 290
220 LET X = X - 1
230 LET Y = Y + 1
240 GOTO 500
290 IF A <> 253 THEN GOTO 10
300 RETURN
500 IF X > 63 THEN LET X = 63
510 IF X < 0 THEN LET X = 0
520 IF Y > 43 THEN LET Y = 43
530 IF Y < 0 THEN LET Y = 0
570 PLOT X,Y
600 GOTO 10

enter the program and RUN – use the ” magic arrow ” keys, 5, 6, 7, 8 to move the dot around- try pressing two keys in combination.

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