10 static struct interrupt_handler keyboard;
12 static unsigned char keymap[128] = {
13 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b',
14 '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n',
15 0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`',
16 0, '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 0,
18 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
19 0, 0, 0, 0, 0, '-', 0, 0, 0, '+',
20 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
23 static unsigned char keymap_shift[128] = {
24 0, 27, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '\b',
25 '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n',
26 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~',
27 0, '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0,
29 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
30 0, 0, 0, 0, 0, '-', 0, 0, 0, '+',
31 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
34 static unsigned int kbd_state = 0;
36 static unsigned char keyboard_decode(unsigned char scancode) {
37 if (scancode & 0x80) {
39 scancode = scancode & 0x7F;
40 if (scancode == 0x2A || scancode == 0x36) {
41 /* left or right shift */
46 if (scancode == 0x2A || scancode == 0x36) {
52 return keymap_shift[scancode];
54 return keymap[scancode];
59 static void keyboard_handler(struct interrupt_context *c, void *unused) {
61 unsigned char scancode;
63 scancode = inport8(0x60);
65 code = keyboard_decode(scancode);
67 /* TODO deliver to process with console open */
68 /* will need a notion of 'foreground' and 'background' processes */
69 /* might make sense to just hand it off to whatever terminal it is
78 void init_keyboard() {
79 keyboard.handler = keyboard_handler;
82 interrupt_add_handler(IRQ1, &keyboard);