Skip to content

The keyboard matrix

The ACE's 67 keys are wired as an 8 × 8 grid. A microcontroller on the board — an ATmega1284P running the AB Controller firmware — drives one row at a time on PA0PA7, reads the columns back on PB0PB7, and hands the CPU the ASCII code for whatever it found.

You never need this to use the machine. You need it if you are building a keyboard for an enclosed ACE, chasing a key that has stopped working, or writing code that reads the ports directly.

Row down the left, column across the top. The small code under each key is what the controller sends when you press it.

PB0PB1PB2PB3PB4PB5PB6PB7
PA0`
$60
1
$31
2
$32
3
$33
4
$34
5
$35
6
$36
7
$37
PA18
$38
9
$39
0
$30
-
$2D
=
$3D
Bksp
$08
Esc
$1B
Tab
$09
PA2Q
$51
W
$57
E
$45
R
$52
T
$54
Y
$59
U
$55
I
$49
PA3O
$4F
P
$50
[
$5B
]
$5D
Backslash
$5C
Ins
$1A
Caps
none
A
$41
PA4S
$53
D
$44
F
$46
G
$47
H
$48
J
$4A
K
$4B
L
$4C
PA5;
$3B
'
$27
Enter
$0D
Del
$7F
Shift
modifier
Z
$5A
X
$58
C
$43
PA6V
$56
B
$42
N
$4E
M
$4D
,
$2C
.
$2E
/
$2F
Up
$1E
PA7Ctrl
modifier
Menu
none
Alt
none
Space
$20
Fn
none
Left
$1C
Down
$1F
Right
$1D

What the controller does with a press

Letters are always capitals. Shift changes the symbols and the number row and nothing else. There is no lower case at the machine — it exists over the serial line, and only there.

Four keys are dead. Caps Lock, Menu, Alt and Fn are read and dropped: no character, no state. Caps Lock in particular is not a lock, because there is nothing for it to switch.

Ctrl sends a control code. Ctrl+A through Ctrl+Z send 1 to 26, so Ctrl+C is $03 — the break — and Ctrl+H is $08, the same as backspace. Ctrl+[ sends $1B, which is Esc.

The arrow keys send $1C to $1F. Nothing in BASIC listens for them. They are there for programs you write.

The header

The grid comes out of the board on a 1 × 16 pin header at 2 mm pitch: pins 1–8 are PA0PA7, pins 9–16 are PB0PB7. On a stock ACE the board's own 67 switches are soldered across it.

Anyone putting the board in a case leaves those switches unfitted and wires their own 8 × 8 grid here instead. Same rows, same columns, same codes — the firmware does not know the difference.

Why reading a joystick is fiddly

Those two ports are the same sixteen VIA lines the joysticks use. The controller is scanning them ten times a second, so a program that reads the port directly will catch the scan mid-sweep and get nonsense.

That is why the Kernal's joystick routines disable the encoder, wait for it to let go of the lines, read, and enable it again — and why doing it by hand needs the same KBDisable → read → KBEnable dance, with about 200 µs of settling in the middle. The keyboard and the sticks has the code.

Written for BIOS v1.5. Released under the MIT License.