The handcontrollers
The handcontrollers are controlled by the IO-Ports A and B of the AY-3-8910 Programmable Sound Generator (PSG). In order to read the handcontrollers you should have some knowledge about how the PSG works. Please make sure you have read the pages about programming the AY-3-8910.
switch | Data bus grounded | Hex code | Decimal code | |
---|---|---|---|---|
k1 | D6 | BF | 191 | |
k2 | D7,2 | 7B | 123 | |
k3 | D7,5 | 5F | 95 | |
k4 | D5 | DF | 223 | |
k5 | D7,1 | 7D | 125 | |
k6 | D7,0 | 7E | 126 | |
P1 | D1 | FD | 253 | |
P2 | D1,4 | ED | 237 | |
P3 | D1,0,4 | EC | 236 | |
P4 | D1,0 | FC | 252 | |
P5 | D0 | FE | 254 | |
P6 | D0,4 | EE | 238 | |
P7 | D3,0,4 | E6 | 230 | |
P8 | D3,0 | F6 | 246 | |
P9 | D3 | F7 | 247 | |
P10 | D3,4 | E7 | 231 | |
P11 | D3,2,4 | E3 | 227 | |
P12 | D3,2 | F3 | 243 | |
P13 | D2 | FB | 251 | |
P14 | D2,4 | EB | 235 | |
P15 | D1,2,4 | E9 | 233 | |
P16 | D1,2 | F9 | 249 |
Note on double keying
If any two switches (keypad and disc) of the hand controller are pressed at the same time, a unique code will be generated exept the following switch combinations:
Switch combinations generating the same code |
Code | Data Bus Grounded |
|
---|---|---|---|
(I) | P5 K5 | 124 | D0,1,7 |
P4 K5 | |||
K6 K5 | |||
K6 P1 | |||
K6 P4 | |||
(II) | P5 K2 | 122 | D0,2,7 |
K6 K2 | |||
K6 P13 | |||
(III) | K5 P16 | 121 | D1,2,7 |
K5 P13 | |||
K5 K2 | |||
P1 K2 | |||
P16 K2 | |||
(IV) | K6 P16 | 120 | D0,1,2,7 |
K2 P4 | |||
(V) | K3 | 95 | D7,5 |
K3 K4 |
Do not use the above codes whenever possible.
In order to read the hand controller you first have to set bits 6 and 7 of R7 to 0. After you have set the two bits to zero, all you have to do to read the hand controllers is to output the correct value (register) to port 247, and then read the input from port 246.
OUT 247, 14 ; for the right-hand controller OUT 247, 15 ; for the left-hand controller
A small machine code routine to read the right-hand controller for the Aquarius looks like:
data label opcode operand comment 62, 7 start: LD A, 7 ; Select register 7 211,247 OUT (247),A ; Send to the register pointer 62, 63 LD A, 63 ; Value for register 211,246 OUT (246),A ; Send to data transfer 62, 14 LD A, 14 ; Select register 14 211,247 OUT (247),A ; Send to the register pointer 219,246 IN A, (246) ; Read the value for R 14 50,216,57 LD (14808),A ; Store value at mem location 14808 201 RET ; Return to basic
Which results in the following BASIC prog:
5 ?CHR$(11) 10 DATA 62,7,211,247,62,63,211,246,62,14,211,247,219,246,50,216,57,201 20 I=14790:POKE14340,198:POKE14341,57 30 READX:POKEI,X:I=I+1:IFX<>201THEN30 40 X=USR(0) 50 ?PEEK(i) 60 IFINKEY$=""THEN40
You should change the number 14 in the DATA line into 15 to read the left-hand controller.
After the machine code we use the PEEK command to read the value at memory location 14808 and use the print command to show it on screen. The program loops until a key is pressed on the keyboard.
I've choosen memory address 14790 as the start address for the machine code. This is -almost- directly after the BASIC program. The value returned by the hand-controller is stored at memory address 14808 which in turn is directly after the machine code.
If you want to use this routine in your own BASIC program then you'll have to modify the start address of the machine code at a higher memory address and also the value returned by the hand-controller must be stored at a higher location.
The tight numbers have been choosen so the program still works on a standard Mattel Aquarius computer without memory upgrade.