38 lines
1000 B
C
Raw Normal View History

2022-11-21 00:16:28 +03:00
#include "keyboard.h"
2025-01-17 21:46:47 +04:00
#include "cpu/isr.h"
#include "cpu/memlayout.h"
#include "console.h"
2022-11-21 00:16:28 +03:00
#include "port.h"
2025-01-17 23:29:01 +04:00
#include "kernel/mem.h"
2022-11-21 00:16:28 +03:00
static const char sc_ascii[] = {
'?', '?', '1', '2', '3', '4', '5', '6',
2022-12-13 01:18:30 +03:00
'7', '8', '9', '0', '-', '=', '?', '?', 'q', 'w', 'e', 'r', 't', 'y',
'u', 'i', 'o', 'p', '[', ']', '\n', '?', 'a', 's', 'd', 'f', 'g',
'h', 'j', 'k', 'l', ';', '\'', '`', '?', '\\', 'z', 'x', 'c', 'v',
'b', 'n', 'm', ',', '.', '/', '?', '?', '?', ' ',
2022-11-21 00:16:28 +03:00
};
2025-01-17 21:46:47 +04:00
enum { kbd_buf_capacity = PGSIZE };
2022-12-13 19:12:31 +03:00
2022-11-21 00:16:28 +03:00
static void interrupt_handler(registers_t *r) {
uint8_t scancode = port_byte_in(0x60);
if (scancode < sizeof(sc_ascii)) {
2022-12-13 01:18:30 +03:00
char c = sc_ascii[scancode];
2022-12-13 19:12:31 +03:00
if (kbd_buf_size < kbd_buf_capacity) {
2022-12-13 01:18:30 +03:00
kbd_buf[kbd_buf_size++] = c;
}
char string[] = {c, '\0'};
2022-11-21 00:16:28 +03:00
printk(string);
}
}
2022-12-13 01:18:30 +03:00
char* kbd_buf;
unsigned kbd_buf_size;
2022-11-21 00:16:28 +03:00
void init_keyboard() {
2025-01-17 21:46:47 +04:00
kbd_buf = kalloc();
2022-12-13 01:18:30 +03:00
2022-11-21 00:16:28 +03:00
register_interrupt_handler(IRQ1, interrupt_handler);
}