diff options
author | Marvin Borner | 2021-07-12 12:20:24 +0200 |
---|---|---|
committer | Marvin Borner | 2021-07-12 12:20:24 +0200 |
commit | d414d2f6f46bd425d727af5baae3e2658d6e1384 (patch) | |
tree | 375edc8f05dc2bd15cb7514bda4885d49e963a27 | |
parent | 91f534979f4790d5cfc0514eb110f3b1f4fb219b (diff) |
Renamed sel to gui
-rw-r--r-- | src/loader/gui.c | 78 | ||||
-rw-r--r-- | src/loader/inc/gui.h (renamed from src/loader/inc/sel.h) | 6 | ||||
-rw-r--r-- | src/loader/main.c | 4 | ||||
-rw-r--r-- | src/loader/sel.c | 78 |
4 files changed, 83 insertions, 83 deletions
diff --git a/src/loader/gui.c b/src/loader/gui.c new file mode 100644 index 0000000..6ae35e6 --- /dev/null +++ b/src/loader/gui.c @@ -0,0 +1,78 @@ +// MIT License, Copyright (c) 2021 Marvin Borner +// GUI - selection interface + +#include <cfg.h> +#include <cpu.h> +#include <def.h> +#include <gui.h> +#include <int.h> +#include <log.h> +#include <pnc.h> + +struct { + struct cfg_entry *cfg; +} gui_entries[16] = { 0 }; + +static u8 gui_entry_add(struct cfg_entry *entry) +{ + static u8 index = 0; + assert(index + 1 < (u8)sizeof(gui_entries)); + + gui_entries[index].cfg = entry; + + index++; + return 0; +} + +static u8 gui_entry_exists(u8 entry) +{ + return !!gui_entries[entry].cfg; +} + +static void gui_entry_select(u8 entry) +{ + if (gui_entry_exists(entry)) + cfg_exec(gui_entries[entry].cfg); + else + log("Invalid selection\n"); +} + +static void gui_entries_draw(void) +{ + for (u8 i = 0; gui_entry_exists(i); i++) + vga_log("> '%s' (%s)\n", gui_entries[i].cfg->name, gui_entries[i].cfg->path); +} + +// Using PS2 magic +static void gui_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 && gui_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) + gui_entry_select(row); + + // Draw selection + vga_put_at('#', 0, row + 2, 0x03); +} + +void gui_draw(void) +{ + vga_clear(); + vga_log("SegelBoot by Marvin Borner\n\n"); + + cfg_foreach(&gui_entry_add); + gui_entries_draw(); + + int_event_handler_add(1, &gui_keyboard_handler); +} diff --git a/src/loader/inc/sel.h b/src/loader/inc/gui.h index 3885d34..cb67c88 100644 --- a/src/loader/inc/sel.h +++ b/src/loader/inc/gui.h @@ -1,8 +1,8 @@ // MIT License, Copyright (c) 2021 Marvin Borner -#ifndef SEL_H -#define SEL_H +#ifndef GUI_H +#define GUI_H -void sel_draw(void); +void gui_draw(void); #endif diff --git a/src/loader/main.c b/src/loader/main.c index 97fc8ef..a16149e 100644 --- a/src/loader/main.c +++ b/src/loader/main.c @@ -5,13 +5,13 @@ #include <cfg.h> #include <def.h> #include <dev.h> +#include <gui.h> #include <ide.h> #include <int.h> #include <log.h> #include <mem.h> #include <pci.h> #include <pic.h> -#include <sel.h> /** * Entry @@ -37,7 +37,7 @@ int start(u8 disk) dev_print(); cfg_read(); - sel_draw(); + gui_draw(); // Sleep and wait for interrupts __asm__ volatile("sti"); diff --git a/src/loader/sel.c b/src/loader/sel.c deleted file mode 100644 index 9052712..0000000 --- a/src/loader/sel.c +++ /dev/null @@ -1,78 +0,0 @@ -// MIT License, Copyright (c) 2021 Marvin Borner -// Selection interface - -#include <cfg.h> -#include <cpu.h> -#include <def.h> -#include <int.h> -#include <log.h> -#include <pnc.h> -#include <sel.h> - -struct { - struct cfg_entry *cfg; -} sel_entries[16] = { 0 }; - -static u8 sel_entry_add(struct cfg_entry *entry) -{ - static u8 index = 0; - assert(index + 1 < (u8)sizeof(sel_entries)); - - sel_entries[index].cfg = entry; - - index++; - return 0; -} - -static u8 sel_entry_exists(u8 entry) -{ - return !!sel_entries[entry].cfg; -} - -static void sel_entry_select(u8 entry) -{ - 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; 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(); - - int_event_handler_add(1, &sel_keyboard_handler); -} |