From 4f1ae4fa4250369919a975f5568425f6791b2489 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 10 Jul 2021 18:36:50 +0200 Subject: Fixed interrupts and added keyboard handler --- src/loader/sel.c | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'src/loader/sel.c') diff --git a/src/loader/sel.c b/src/loader/sel.c index acdc783..9052712 100644 --- a/src/loader/sel.c +++ b/src/loader/sel.c @@ -2,7 +2,9 @@ // Selection interface #include +#include #include +#include #include #include #include @@ -22,29 +24,55 @@ static u8 sel_entry_add(struct cfg_entry *entry) return 0; } -// TODO: Keyboard listener +static u8 sel_entry_exists(u8 entry) +{ + return !!sel_entries[entry].cfg; +} + static void sel_entry_select(u8 entry) { - cfg_exec(sel_entries[entry].cfg); + if (sel_entry_exists(entry)) + cfg_exec(sel_entries[entry].cfg); + else + log("Invalid selection\n"); } static void sel_entries_draw(void) { - for (u8 i = 0; i < COUNT(sel_entries); i++) { - if (!sel_entries[i].cfg) - break; - + for (u8 i = 0; sel_entry_exists(i); i++) vga_log("> '%s' (%s)\n", sel_entries[i].cfg->name, sel_entries[i].cfg->path); - } +} + +// Using PS2 magic +static void sel_keyboard_handler(void) +{ + static u8 row = 0; + + while (!(inb(0x64) & 1)) // Wait for data (bit 0 gets set) + ; + u8 data = inb(0x60); + + // Reset previous selection + vga_put_at('>', 0, row + 2, 0x07); + + if (data == 0x24 && sel_entry_exists(row + 1)) // j/down key + row++; + else if (data == 0x25 && row > 0) // k/up key + row--; + else if (data == (0x1c | 0x80)) // enter key release (| 0x80) + sel_entry_select(row); + + // Draw selection + vga_put_at('#', 0, row + 2, 0x03); } void sel_draw(void) { vga_clear(); + vga_log("SegelBoot by Marvin Borner\n\n"); cfg_foreach(&sel_entry_add); sel_entries_draw(); - // Just for testing - sel_entry_select(0); + int_event_handler_add(1, &sel_keyboard_handler); } -- cgit v1.2.3