Code-to-key conversion table |
Code | Key |
Dec. | Hex. |
0 | $00 | Inst/Del |
1 | $01 | Return |
2 | $02 | Crsr ←→ |
3 | $03 | F7/F8 |
4 | $04 | F1/F2 |
5 | $05 | F3/F4 |
6 | $06 | F5/F6 |
7 | $07 | Crsr ↑↓ |
8 | $08 | 3 |
9 | $09 | W |
10 | $0A | A |
11 | $0B | 4 |
12 | $0C | Z |
13 | $0D | S |
14 | $0E | E |
15 | $0F | (Unused) |
|
Code | Key |
Dec. | Hex. |
16 | $10 | 5 |
17 | $11 | R |
18 | $12 | D |
19 | $13 | 6 |
20 | $14 | C |
21 | $15 | F |
22 | $16 | T |
23 | $17 | X |
24 | $18 | 7 |
25 | $19 | Y |
26 | $1A | G |
27 | $1B | 8 |
28 | $1C | B |
29 | $1D | H |
30 | $1E | U |
31 | $1F | V |
|
Code | Key |
Dec. | Hex. |
32 | $20 | 9 |
33 | $21 | I |
34 | $22 | J |
35 | $23 | 0 |
36 | $24 | M |
37 | $25 | K |
38 | $26 | O |
39 | $27 | N |
40 | $28 | + |
41 | $29 | P |
42 | $2A | L |
43 | $2B | − |
44 | $2C | > |
45 | $2D | [ |
46 | $2E | @ |
47 | $2F | < |
|
Code | Key |
Dec. | Hex. |
48 | $30 | £ |
49 | $31 | * |
50 | $32 | ] |
51 | $33 | Clr/Home |
52 | $34 | (Unused) |
53 | $35 | = |
54 | $36 | ↑ |
55 | $37 | ? |
56 | $38 | 1 |
57 | $39 | ← |
58 | $3A | (Unused) |
59 | $3B | 2 |
60 | $3C | Space |
61 | $3D | (Unused) |
62 | $3E | Q |
63 | $3F | Run/Stop |
|
Keyboard codes are numbers in the range 0–63/$00–$3F, assigned to most of the keys on the 64's keyboard (the exceptions are Shift and Shift Lock keys, the Commodore logo key, the Ctrl key, and the Restore key): When scanning the keyboard, the 64 will place the keyboard code of whatever key was pressed down, in addresses 203 and later 197. If no key was pressed, the scan routine will report a "key code" of 64/$40, and if more than one of the keys which have a key code is pressed, the one with the highest key code will take precedence.
Note the four unused codes; 15/$0F, 52/$34, 58/$3A, and 61/$3D: Internally in the ROM routines handling the keyboard, these codes represent the Shift, Commodore and Ctrl keys. Since they are only used internally, it's not possible to detect the depression of these keys — to do this, use addresses 653 and 654.
- 15/$0F is the leftmost of the two Shift keys, or the Shift Lock key
- 52/$34 is the rightmost of the two Shift keys
- 58/$3A is the Ctrl key
- 61/$3D is the Commodore logo key
The RESTORE key does not leave software-readable "signs" in the system; rather, it raises a Non-Maskable interrupt. "Reading" the RESTORE key thus implies writing a custom interrupt handling routine for the purpose.
The KERNAL ROM contains four tables used by the system to convert keyboard codes into PETSCII character codes: Each table contains 65 bytes; one PETSCII code for each of the 64 keys assigned a keyboard code, plus a 255/$FF which will be returned for the keyboard code of 64/$40 (indicating no key pressed).
- 60289–60353/$EB81–$EBC1: PETSCII codes for keys pressed without simultaneously using Shift, Commodore or Ctrl keys. In this table, the entries for those three keys are 1, 2 and 4; values which get "sorted out" by the keyboard scan routines in ROM and thus never "show up" in the addresses 203 and 197.
- 60354–60418/$EBC2–$EC02: PETSCII codes for keys pressed simultaneously with a Shift or the Shift Lock keys.
- 60419–60483/$EC03–$EC43: PETSCII codes for keys pressed simultaneously with the Commodore logo key.
- 60536–60600/$EC78–$ECB8: PETSCII codes for keys pressed simultaneously with the Ctrl key. This table has several bytes with 255/$FF, indicating no character; if you press Ctrl along with e.g. Inst/Del, the 64 behaves as if nothing was typed at all.