PEEK(197) or PEEK(203) Keyboard Scan Codes
I have recently been typing some basic games from the Melbourne House Games Book 2, and in these games they heavily use the Peek(197) or Peek(203) comment for scanning the keyboard, but they do not show which characaters the results of these peeks are.
So I did my investigation of my own, and here are the results.
The keyscan interrupt routine uses this location to indicate which key is currently being pressed. The value here is then used as an index into the appropriate keyboard table to determine which character to print when a key is struck.
The correspondence between the key pressed and the number stored here is as follows:
+------------------------+------------------------+
| 0 = INSERT/DELETE | 4 = F1 |
+------------------------+------------------------+
| 1 = RETURN | 5 = F3 |
+------------------------+------------------------+
| 2 = CURSOR RIGHT | 6 = F5 |
+------------------------+------------------------+
| 3 = F7 | 7 = CURSOR DOWN |
+------------------------+------------------------+
| 8 = 3 | 9 = W |
+------------------------+------------------------+
| 10 = A | 11 = 4 |
+------------------------+------------------------+
| 12 = Z | 13 = S |
+------------------------+------------------------+
| 14 = E | 15 = NOT USED |
+------------------------+------------------------+
| 16 = 5 | 17 = R |
+------------------------+------------------------+
| 18 = D | 19 = 6 |
+------------------------+------------------------+
| 20 = C | 21 = F |
+------------------------+------------------------+
| 22 = T | 23 = X |
+------------------------+------------------------+
| 24 = 7 | 25 = Y |
+------------------------+------------------------+
| 26 = G | 27 = 8 |
+------------------------+------------------------+
| 28 = B | 29 = H |
+------------------------+------------------------+
| 30 = U | 31 = V |
+------------------------+------------------------+
| 32 = 9 | 33 = I |
+------------------------+------------------------+
| 34 = J | 35 = 0 |
+------------------------+------------------------+
| 36 = M | 37 = K |
+------------------------+------------------------+
| 38 = O | 39 = N |
+------------------------+------------------------+
| 40 = + | 41 = P |
+------------------------+------------------------+
| 42 = L | 43 = - |
+------------------------+------------------------+
| 44 = . | 45 = : |
+------------------------+------------------------+
| 46 = @ | 47 = , |
+------------------------+------------------------+
| 48 = £ | 49 = * |
+------------------------+------------------------+
| 50 = ; | 51 = CLEAR/HOME |
+------------------------+------------------------+
| 52 = NOT USED | 53 = = |
+------------------------+------------------------+
| 54 = Exponent Arrow Up | 55 = / |
+------------------------+------------------------+
| 56 = 1 | 57 = LEFT ARROW |
+------------------------+------------------------+
| 58 = NOT USED | 59 = 2 |
+------------------------+------------------------+
| 60 = SPACE BAR | 61 = NOT USED |
+------------------------+------------------------+
| 62 = Q | 63 = RUN/STOP |
+------------------------+------------------------+
| 64 = NO KEY PRESSED (default) |
+------------------------+------------------------+
The RESTORE key is not accounted for, because it is not part of the normal keyboard matrix. Instead, it is connected directly to the microprocessor NMI line, and causes an NMI interrupt whenever it is pressed.
For those who are using the Peek Codes, here is a list of Constants for CBM PRG Studio:
scanCode_INS_DEL$ = 0
scanCode_RET$ = 1
scanCode_CUR_RI$ = 2
scanCode_F7$ = 3
scanCode_F1$ = 4
scanCode_F3$ = 5
scanCode_F5$ = 6
scanCode_CUR_DN$ = 7
scanCode_3$ = 8
scanCode_W$ = 9
scanCode_A$ = 10
scanCode_4$ = 11
scanCode_Z$ = 12
scanCode_S$ = 13
scanCode_E$ = 14
scanCode_5$ = 16
scanCode_R$ = 17
scanCode_D$ = 18
scanCode_6$ = 19
scanCode_C$ = 20
scanCode_F$ = 21
scanCode_T$ = 22
scanCode_X$ = 23
scanCode_7$ = 24
scanCode_Y$ = 25
scanCode_G$ = 26
scanCode_8$ = 27
scanCode_B$ = 28
scanCode_H$ = 29
scanCode_U$ = 30
scanCode_V$ = 31
scanCode_9$ = 32
scanCode_I$ = 33
scanCode_J$ = 34
scanCode_0$ = 35
scanCode_M$ = 36
scanCode_K$ = 37
scanCode_O$ = 38
scanCode_N$ = 39
scanCode_PLUS$ = 40
scanCode_P$ = 41
scanCode_L$ = 42
scanCode_MINUS$ = 43
scanCode_FULSTP$ = 44
scanCode_COLON$ = 45
scanCode_AT$ = 46
scanCode_COMMA$ = 47
scanCode_POUND$ = 48
scanCode_ASTRIK$ = 49
scanCode_SEMICOLON$ = 50
scanCode_CLEAR_HOME$ = 51
scanCode_EQUALS$ = 53
scanCode_EXPONENT_ARROW$ = 54
scanCode_FWD_SLASH$ = 55
scanCode_1$ = 56
scanCode_LEFT_ARROW$ = 57
scanCode_2$ = 59
scanCode_SPACEBAR$ = 60
scanCode_Q$ = 62
scanCode_RUNSTOP$ = 63
scanCode_NO_KEY$ = 64
***UPDATE***, and now the constants for Kick Assembler 🙂
.namespace kbScanCode
{
.label key_INS_DEL = 0
.label key_RET = 1
.label key_CUR_RI = 2
.label key_F7 = 3
.label key_F1 = 4
.label key_F3 = 5
.label key_F5 = 6
.label key_CUR_DN = 7
.label key_3 = 8
.label key_W = 9
.label key_A = 10
.label key_4 = 11
.label key_Z = 12
.label key_S = 13
.label key_E = 14
.label key_5 = 16
.label key_R = 17
.label key_D = 18
.label key_6 = 19
.label key_C = 20
.label key_F = 21
.label key_T = 22
.label key_X = 23
.label key_7 = 24
.label key_Y = 25
.label key_G = 26
.label key_8 = 27
.label key_B = 28
.label key_H = 29
.label key_U = 30
.label key_V = 31
.label key_9 = 32
.label key_I = 33
.label key_J = 34
.label key_0 = 35
.label key_M = 36
.label key_K = 37
.label key_O = 38
.label key_N = 39
.label key_PLUS = 40
.label key_P = 41
.label key_L = 42
.label key_MINUS = 43
.label key_FULSTP = 44
.label key_COLON = 45
.label key_AT = 46
.label key_COMMA = 47
.label key_POUND = 48
.label key_ASTRIK = 49
.label key_SEMICOLON = 50
.label key_CLEAR_HOME = 51
.label key_EQUALS = 53
.label key_EXPONENT_ARROW = 54
.label key_FWD_SLASH = 55
.label key_1 = 56
.label key_LEFT_ARROW = 57
.label key_2 = 59
.label key_SPACEBAR = 60
.label key_Q = 62
.label key_RUNSTOP = 63
.label key_NO_KEY = 64
}