/* [<][>][^][v][top][bottom][index][help] */
1 // PC keyboard interface constants
2
3 #define KBSTATP 0x64 // kbd controller status port(I)
4 #define KBS_DIB 0x01 // kbd data in buffer
5 #define KBDATAP 0x60 // kbd data port(I)
6
7 #define NO 0
8
9 #define SHIFT (1<<0)
10 #define CTL (1<<1)
11 #define ALT (1<<2)
12
13 #define CAPSLOCK (1<<3)
14 #define NUMLOCK (1<<4)
15 #define SCROLLLOCK (1<<5)
16
17 #define E0ESC (1<<6)
18
19 // Special keycodes
20 #define KEY_HOME 0xE0
21 #define KEY_END 0xE1
22 #define KEY_UP 0xE2
23 #define KEY_DN 0xE3
24 #define KEY_LF 0xE4
25 #define KEY_RT 0xE5
26 #define KEY_PGUP 0xE6
27 #define KEY_PGDN 0xE7
28 #define KEY_INS 0xE8
29 #define KEY_DEL 0xE9
30
31 // C('A') == Control-A
32 #define C(x) (x - '@')
33
34 static uchar shiftcode[256] =
35 {
36 [0x1D] CTL,
37 [0x2A] SHIFT,
38 [0x36] SHIFT,
39 [0x38] ALT,
40 [0x9D] CTL,
41 [0xB8] ALT
42 };
43
44 static uchar togglecode[256] =
45 {
46 [0x3A] CAPSLOCK,
47 [0x45] NUMLOCK,
48 [0x46] SCROLLLOCK
49 };
50
51 static uchar normalmap[256] =
52 {
53 NO, 0x1B, '1', '2', '3', '4', '5', '6', // 0x00
54 '7', '8', '9', '0', '-', '=', '\b', '\t',
55 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', // 0x10
56 'o', 'p', '[', ']', '\n', NO, 'a', 's',
57 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', // 0x20
58 '\'', '`', NO, '\\', 'z', 'x', 'c', 'v',
59 'b', 'n', 'm', ',', '.', '/', NO, '*', // 0x30
60 NO, ' ', NO, NO, NO, NO, NO, NO,
61 NO, NO, NO, NO, NO, NO, NO, '7', // 0x40
62 '8', '9', '-', '4', '5', '6', '+', '1',
63 '2', '3', '0', '.', NO, NO, NO, NO, // 0x50
64 [0x9C] '\n', // KP_Enter
65 [0xB5] '/', // KP_Div
66 [0xC8] KEY_UP, [0xD0] KEY_DN,
67 [0xC9] KEY_PGUP, [0xD1] KEY_PGDN,
68 [0xCB] KEY_LF, [0xCD] KEY_RT,
69 [0x97] KEY_HOME, [0xCF] KEY_END,
70 [0xD2] KEY_INS, [0xD3] KEY_DEL
71 };
72
73 static uchar shiftmap[256] =
74 {
75 NO, 033, '!', '@', '#', '$', '%', '^', // 0x00
76 '&', '*', '(', ')', '_', '+', '\b', '\t',
77 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', // 0x10
78 'O', 'P', '{', '}', '\n', NO, 'A', 'S',
79 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', // 0x20
80 '"', '~', NO, '|', 'Z', 'X', 'C', 'V',
81 'B', 'N', 'M', '<', '>', '?', NO, '*', // 0x30
82 NO, ' ', NO, NO, NO, NO, NO, NO,
83 NO, NO, NO, NO, NO, NO, NO, '7', // 0x40
84 '8', '9', '-', '4', '5', '6', '+', '1',
85 '2', '3', '0', '.', NO, NO, NO, NO, // 0x50
86 [0x9C] '\n', // KP_Enter
87 [0xB5] '/', // KP_Div
88 [0xC8] KEY_UP, [0xD0] KEY_DN,
89 [0xC9] KEY_PGUP, [0xD1] KEY_PGDN,
90 [0xCB] KEY_LF, [0xCD] KEY_RT,
91 [0x97] KEY_HOME, [0xCF] KEY_END,
92 [0xD2] KEY_INS, [0xD3] KEY_DEL
93 };
94
95 static uchar ctlmap[256] =
96 {
97 NO, NO, NO, NO, NO, NO, NO, NO,
98 NO, NO, NO, NO, NO, NO, NO, NO,
99 C('Q'), C('W'), C('E'), C('R'), C('T'), C('Y'), C('U'), C('I'),
100 C('O'), C('P'), NO, NO, '\r', NO, C('A'), C('S'),
101 C('D'), C('F'), C('G'), C('H'), C('J'), C('K'), C('L'), NO,
102 NO, NO, NO, C('\\'), C('Z'), C('X'), C('C'), C('V'),
103 C('B'), C('N'), C('M'), NO, NO, C('/'), NO, NO,
104 [0x9C] '\r', // KP_Enter
105 [0xB5] C('/'), // KP_Div
106 [0xC8] KEY_UP, [0xD0] KEY_DN,
107 [0xC9] KEY_PGUP, [0xD1] KEY_PGDN,
108 [0xCB] KEY_LF, [0xCD] KEY_RT,
109 [0x97] KEY_HOME, [0xCF] KEY_END,
110 [0xD2] KEY_INS, [0xD3] KEY_DEL
111 };
112