From 162d024a53e1e31e00ff0b6f47dd4590edebc551 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 9 Aug 2020 16:51:01 +0200 Subject: Heavy restructuring of libc, kernel and apps --- kernel/drivers/keyboard.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 kernel/drivers/keyboard.c (limited to 'kernel/drivers/keyboard.c') diff --git a/kernel/drivers/keyboard.c b/kernel/drivers/keyboard.c new file mode 100644 index 0000000..38ff1f7 --- /dev/null +++ b/kernel/drivers/keyboard.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include + +char keymap[128]; + +// TODO: Use keyboard as event and move logic to other file +void keyboard_handler() +{ + u8 scan_code = inb(0x60); + + if (scan_code > 128) + return; + + if ((scan_code & 0x80) == 0) { // PRESS + gui_term_write_char(keymap[scan_code]); + } +} + +void keyboard_acknowledge() +{ + while (inb(0x60) != 0xfa) + ; +} + +void keyboard_rate() +{ + outb(0x60, 0xF3); + keyboard_acknowledge(); + outb(0x60, 0x0); // Rate{00000} Delay{00} 0 +} + +void keyboard_install() +{ + //keyboard_rate(); TODO: Fix keyboard rate? + irq_install_handler(1, keyboard_handler); +} + +char keymap[128] = { + 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', + '\b', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', + '\n', 17, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', + 14, '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 14, '*', + 0, // Alt key + ' ', // Space bar + 15, // Caps lock + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // F keys + 0, // Num lock + 0, // Scroll lock + 0, // Home key + 0, // Up arrow + 0, // Page up + '-', + 0, // Left arrow + 0, + 0, // Right arrow + '+', + 0, // End key + 0, // Down arrow + 0, // Page down + 0, // Insert key + 0, // Delete key + 0, 0, 0, + 0, // F11 + 0, // F12 + 0, // Other keys +}; -- cgit v1.2.3