2022-02-24 21:16:28 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "std/kstd.h"
|
|
|
|
#include "ps2/keyboard.h"
|
|
|
|
#include "cpu/pic.h"
|
|
|
|
#include "cpu/idt.h"
|
|
|
|
#include "cpu/io.h"
|
2022-02-24 22:01:02 +02:00
|
|
|
#include "gfx/terminal.h"
|
2022-02-24 21:16:28 +02:00
|
|
|
|
|
|
|
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_descriptor_32 *frame) {
|
2022-02-24 22:01:02 +02:00
|
|
|
uint8_t scancode = inb(0x60);
|
2022-02-24 21:16:28 +02:00
|
|
|
|
|
|
|
if (scancode & 128) {
|
|
|
|
goto end; // ignore release scancode
|
|
|
|
}
|
|
|
|
|
|
|
|
terminal_putchar(us_map[scancode]);
|
|
|
|
end:
|
|
|
|
pic_send_eoi(1);
|
|
|
|
}
|
|
|
|
|
2022-02-24 21:57:59 +02:00
|
|
|
void keyboard_init(void) {
|
2022-02-24 21:16:28 +02:00
|
|
|
pic_irq_clear_mask(1);
|
|
|
|
idt_register_handler(33, (size_t)irq);
|
|
|
|
inb(0x60);
|
|
|
|
}
|