mirror of
https://github.com/gbowne1/ClassicOS.git
synced 2025-10-13 13:15:07 -07:00
fixing the keyboard and bootloader so that its 2 stage again
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -11,6 +11,7 @@
|
||||
#include "kmalloc.h"
|
||||
#include "timer.h"
|
||||
#include "utils.h"
|
||||
#include "keyboard.h"
|
||||
|
||||
#define LPT1 0x378
|
||||
|
||||
@@ -54,6 +55,10 @@ void kmain(void) {
|
||||
timer_init(100); // 100 Hz (10 ms interval)
|
||||
serial_write("Timer initialized.\n");
|
||||
|
||||
terminal_write("Initializing keyboard...\n");
|
||||
keyboard_init();
|
||||
serial_write("Keyboard initialized.\n");
|
||||
|
||||
terminal_write("Getting memory map...\n");
|
||||
memory_map_entry_t mmap[32];
|
||||
uint32_t mmap_size = get_memory_map(mmap, 32);
|
||||
|
@@ -4,17 +4,20 @@
|
||||
#include "terminal.h"
|
||||
#include "stdio.h"
|
||||
|
||||
static uint32_t tick = 0;
|
||||
static volatile uint32_t tick = 0;
|
||||
|
||||
void timer_callback(void) {
|
||||
tick++;
|
||||
|
||||
// Print every 100 ticks for debugging purposes
|
||||
|
||||
if (tick % 100 == 0) {
|
||||
char tick_msg[50];
|
||||
snprintf(tick_msg, sizeof(tick_msg), "Tick count: %u\n", tick);
|
||||
terminal_write(tick_msg);
|
||||
char buf[16];
|
||||
itoa(tick, buf, 10);
|
||||
terminal_write("Tick count: ");
|
||||
terminal_write(buf);
|
||||
terminal_write("\n");
|
||||
}
|
||||
|
||||
outb(0x20, 0x20); // EOI to PIC
|
||||
}
|
||||
|
||||
void timer_init(uint32_t frequency) {
|
||||
@@ -29,4 +32,4 @@ void timer_init(uint32_t frequency) {
|
||||
|
||||
uint32_t timer_get_ticks(void) {
|
||||
return tick;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user