hippOS/ps2/keyboard.c
2022-02-25 21:29:18 +02:00

66 lines
1.4 KiB
C

#include <stdint.h>
#include "std/kstd.h"
#include "ps2/keyboard.h"
#include "cpu/pic.h"
#include "cpu/idt.h"
#include "cpu/io.h"
#include "gfx/terminal.h"
const char us_map[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',
0, // 29 ctrl
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
'\'', '`', 0, // 42 left shift
'\\', 'z', 'x', 'c', 'v', 'b', 'n',
'm', ',', '.', '/', 0, // 54 right shift
'*',
0, // 56 alt
' ',
0, // 58 caps lock
0, // 59 F1 key
0, 0, 0, 0, 0, 0, 0, 0,
0, // 68 F10 key
0, // 69 num lock
0, // 70 scroll lock
0, // 71 home key
0, // 72 up arrow
0, // 73 page up
'-',
0, // 75 left arrow
0,
0, // 77 right arrow
'+',
0, // 79 end key
0, // 80 down arrow
0, // 81 page down
0, // 82 insert key
0, // 83 delete key
0, 0, 0,
0, // 87 F11 key
0, // 88 F12 key
0
};
__attribute__((interrupt))
static void irq(struct interrupt_frame_32 *frame) {
uint8_t scancode = inb(0x60);
if (scancode & 128) {
goto end; // ignore release scancode
}
terminal_putchar(us_map[scancode]);
end:
pic_send_eoi(1);
}
void keyboard_init(void) {
pic_irq_clear_mask(1);
idt_register_handler(33, (size_t)irq);
inb(0x60);
}