kbd.c (2310B)
1 #include <libc.h> 2 #include "libk.h" 3 #include "kbd.h" 4 #include "idt.h" 5 #include "io.h" 6 #include "vga.h" 7 8 #define KBD_CMD 0x60 9 #define KBD_PRESSED 0x80 10 #define KBD_LSHIFT 0x2a 11 #define KBD_RSHIFT 0x36 12 #define KBD_LSHIFT_REL 0xaa 13 #define KBD_RSHIFT_REL 0xb6 14 15 static void kbd_callback(struct regs *); 16 17 static u_char kbdus_upper[128] = { 18 0, /* Error */ 19 27, /* Escape */ 20 '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', 21 '_', '+', '\b', '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 22 '{', '}', '\n', 23 0, /* Control */ 24 'A', 'S', 'D', 'F', 'G', 25 'H', 'J', 'K', 'L', ':', '"', '~', 26 0, /* Left Shift */ 27 '|', 'Z', 'X', 28 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 29 0, /* Right Shift */ 30 '*', 31 0, /* Alt */ 32 ' ', 33 0, /* Caps Lock */ 34 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F1-F10 */ 35 0, /* Num Lock */ 36 0, /* Scroll Lock */ 37 0, /* Home Key */ 38 0, /* Up Arrow */ 39 0, /* Page Up */ 40 '-', 41 0, /* Left Arrow */ 42 0, 43 0, /* Right Arrow */ 44 '+', 45 0, /* End Key */ 46 0, /* Down Arrow */ 47 0, /* Page Down */ 48 0, /* Insert Key */ 49 0, /* Delete Key */ 50 0, 0, 0, 51 0, 0, /* F11, F12 */ 52 0, /* The rest are undefined */ 53 }; 54 55 static u_char kbdus_lower[128] = { 56 0, /* Error */ 57 27, /* Escape */ 58 '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 59 '-', '=', '\b', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 60 '[', ']', '\n', 61 0, /* Control */ 62 'a', 's', 'd', 'f', 'g', 63 'h', 'j', 'k', 'l', ';', '\'', '`', 64 0, /* Left Shift */ 65 '\\', 'z', 'x', 66 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 67 0, /* Right Shift */ 68 '*', 69 0, /* Alt */ 70 ' ', 71 0, /* Caps Lock */ 72 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F1-F10 */ 73 0, /* Num Lock */ 74 0, /* Scroll Lock */ 75 0, /* Home Key */ 76 0, /* Up Arrow */ 77 0, /* Page Up */ 78 '-', 79 0, /* Left Arrow */ 80 0, 81 0, /* Right Arrow */ 82 '+', 83 0, /* End Key */ 84 0, /* Down Arrow */ 85 0, /* Page Down */ 86 0, /* Insert Key */ 87 0, /* Delete Key */ 88 0, 0, 0, 89 0, 0, /* F11, F12 */ 90 0, /* The rest are undefined */ 91 }; 92 93 static void 94 kbd_callback(struct regs *r) 95 { 96 u_int8_t sc; 97 int shift = 0; 98 99 if ((sc = inb(KBD_CMD)) & KBD_PRESSED) { 100 } else { 101 /* TODO: shift */ 102 if (kbdus_lower[sc] == 'r') { 103 dump_regs(r); 104 return; 105 } 106 vga_putc(shift ? kbdus_upper[sc] : kbdus_lower[sc]); 107 } 108 UNUSED(r); 109 } 110 111 void 112 kbd_init(void) 113 { 114 intr_register_handler(IRQ1, kbd_callback); 115 printf("kbd on irq 1\n"); 116 }