fixing the keyboard and bootloader so that its 2 stage again

This commit is contained in:
2025-08-02 20:06:15 -07:00
parent e1e30b511a
commit 267130281a
7 changed files with 411 additions and 53 deletions

View File

@@ -20,34 +20,40 @@ static const char scancode_map[128] = {
};
// Interrupt handler for IRQ1
void keyboard_callback() {
uint8_t scancode = inb(KEYBOARD_DATA_PORT);
void keyboard_callback(void) {
uint8_t scancode = inb(0x60);
// Ignore key releases (scancodes with high bit set)
if (scancode & 0x80)
return;
char c = scancode_map[scancode];
if (c && buffer_index < sizeof(key_buffer) - 1) {
key_buffer[buffer_index++] = c;
terminal_putchar(c); // Echo to terminal (optional)
// Only handle key press (ignore key release)
if (!(scancode & 0x80)) {
char c = scancode_map[scancode];
if (c && buffer_index < sizeof(key_buffer) - 1) {
key_buffer[buffer_index++] = c;
terminal_putchar(c);
}
}
// Send End of Interrupt (EOI) to the PIC
outb(0x20, 0x20);
}
void keyboard_init() {
register_interrupt_handler(33, keyboard_callback); // IRQ1 = int 33 (0x21)
}
// Blocking read (returns one char)
char keyboard_get_char() {
while (buffer_index == 0);
char c = key_buffer[0];
while (buffer_index == 0); // Busy wait
// Shift buffer left
char c;
__asm__ __volatile__("cli");
c = key_buffer[0];
for (uint8_t i = 1; i < buffer_index; i++) {
key_buffer[i - 1] = key_buffer[i];
}
buffer_index--;
__asm__ __volatile__("sti");
return c;
}