diff options
author | Marvin Borner | 2021-07-10 18:36:50 +0200 |
---|---|---|
committer | Marvin Borner | 2021-07-10 18:36:50 +0200 |
commit | 4f1ae4fa4250369919a975f5568425f6791b2489 (patch) | |
tree | aec903e642561edbf6a6cccf513abccff882426f /src/loader/sel.c | |
parent | ad56eb28f0614db4b7656ade390f1c79b446cbc9 (diff) |
Fixed interrupts and added keyboard handler
Diffstat (limited to 'src/loader/sel.c')
-rw-r--r-- | src/loader/sel.c | 46 |
1 files changed, 37 insertions, 9 deletions
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 <cfg.h> +#include <cpu.h> #include <def.h> +#include <int.h> #include <log.h> #include <pnc.h> #include <sel.h> @@ -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); } |