Star Tip

Author(s): Pete Cooke
Publication: The Data Expansion
Pub Details: The D/FW Data Expansion v4 n11 (Volume 4, Issue 11)
Date: November 1987
Pages: 8-11

From YS OCT-87

Pete has spent a lot of time programming computer games, his first products coming out on the Richard Shepard Software label between 1983-85. First “Invincible Island”, the “Urban Upstart”, “Inferno” and finally “Ski Star 2000”. Moving over to CRP in 1985, he produced “Juggernaut”, and the “Tau Ceti” range of games. Pete now works for Nexus and, having recently wowed us all with the excellent “Micronaut One”, is currently working on a top secret project.

The routine Pete has contributed is the keyboard scanning routine from both the “Tau Ceti” games and “Micronaut One”. It is an assembly routine printed as such because it’s easier to make out what’s happening that way. Now you will be able to inncorporate Pete’s routines into your games, as the first step to implementing the sort of Windows, Icons, Mouse, and Pointer type controls. This is just the first step, the rest is up to you.

To substitute different key combinations in the routine, simply copy new values into the 5 byte table KEYTAB. The assembly listing is pretty self-explanatory, having piles of comment lines with details of how to use the program.

ASSEMBLY LISTING

  10             ORG   60000
20 ENT 60000
30 ;
40 ;
50 ; YS_KEYS
60 ;
70 ;prog fro your sinclair
80 ;
90 ;file for Hisoft GENS
100 ;assembler but should
110 ;be suitable for most
120 ;assemblers on the market
130 ;
140 ;Reads the keyboard
150 ;Returns with C
160 ;holding L/R/U/D/F
170 ;
180 ;bit 4,C left
190 ;bit 3,C right
200 ;bit 2,C up
210 ;bit 1,C down
220 ;bit 0,C fire
230 ;
240 ;bit set to 1 if pressed
250 ;
260 ;keys are chosen by
270 ;values in KEYTAB
280 ;
290 READKE LD HL,KEYTAB
300 LD BC,#0500
310 ;
320 ;5 keys to read
330 ;
340 READ_1 LD A,(HL)
350 RRA
360 RRA
370 AND #1E
380 LD E,A
390 LD D,0
400 ;
410 ;2*the row no
420 ;
430 LD A,(HL)
440 INC HL
450 PUSH HL
460 ;
470 ;save place in KEYTAB
480 ;
490 LD HL,KEYTAB
500 ADD HL,DE
510 LD D,A
520 ;
530 ;index port addresses
540 ;
550 PUSH BC
560 LD C,(HL)
570 INC HL
580 LD B,(HL)
590 IN A,(C)
600 INC B
610 DEC B
620 JR Z,READ_2
630 CPL
640 READ_2 LD E,A
650 ;
660 ;read the port
670 ;and flip bits if not
680 ;kempston
690 ;
700 POP BC
710 POP HL
720 ;
730 ;and get BC+HL back
740 ;
750 LD A,D
760 AND #07
770 JR Z,READ_4
780 ;
790 READ_3 RR E
800 DEC A
810 JR NZ,READ_3
820 ;
830 ;rotate L so bit needed
840 ;is in bit 0
850 ;
860 READ_4 RR E
870 RL C
880 ;
890 ;rotate the bit into C
900 ;
910 DJNZ READ_1
920 RET
930 ;
940 ;exit B=0
950 ; C=keys
960 ;
970 ;A,HL,DE corrupt
980 ;
990 ;
1000 ;port addresses of 1010 ;the keyboard rows
1020 ;
1030 KEYADD DEFW 63486,64510,
65022,65278,61438,57342,
49150,32766
1040 DEFW 31 ;*kempstom*
1050 ;
1060 ;
1070 ;KEYTAB holds the position
1080 ;of each key as
1090 ;1/2 row no*8 plus
1100 ;distance from edge
1110 ;e.g. P = 5*8+0
1120 ; O = 5*8+1
1130 ; Q = 1*8+0
1140 ; 4 = 0*8+3
1150 ;
1160 KEYTAB DEFB 5*8+1,5*8+0,2*8+1,3*8+2,7*8+0
1170 ;
1180 ;set for O,P,S,X,space
1190 ;
1200 ;for a Kempston Joystick
1210 ;substitute
1220 ;
1230 DEFB 8*8+1,8*8+0,8*8+3,8*8+2,8*8+4
1240 ;

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