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.
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
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.