Mattel Aquarius

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.

switchData bus
Decimal code
k1D6 BF191
k4D5 DF223
P1 D1 FD253
P2 D1,4 ED237
P3 D1,0,4EC236
P4 D1,0 FC252
P5 D0 FE254
P6 D0,4 EE238
P7 D3,0,4E6230
P8 D3,0 F6246
P9 D3 F7247
P10D3,4 E7231
P12D3,2 F3243
P13D2 FB251
P14D2,4 EB235
P16D1,2 F9249

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
(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
40 X=USR(0)
50 ?PEEK(i)

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.