From eae7442610215e55ea350c65aab4ab3869111014 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Fri, 19 Feb 2021 22:24:08 -0500 Subject: kernel settings file --- src/kernel/kbd.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/kernel/kbd.c') diff --git a/src/kernel/kbd.c b/src/kernel/kbd.c index c09684d..96d2069 100644 --- a/src/kernel/kbd.c +++ b/src/kernel/kbd.c @@ -1,14 +1,16 @@ #include +#include "settings.h" #include "window.h" #include "drive.h" #include "panic.h" #include "pmap.h" #include "util.h" #include "kbd.h" +#include "log.h" -#define SCANTAB_DIR "sys/scantabs" -#define LAYOUT_HARDCODE_TMP "qwerty" +#define SCANTAB_DIR "sys/scantabs/" +#define SCANTAB_DIR_LEN 13 enum { PS2_CMD = 0x64, @@ -45,14 +47,29 @@ enum { ST_SKIP }; +#define LAYOUT_NAME_MAX_LEN 31 +static char scantab_path[SCANTAB_DIR_LEN + LAYOUT_NAME_MAX_LEN + 5] = SCANTAB_DIR; + void init_kbd() { outb(PS2_CMD, PS2C_READ_CONFIG); uint8_t config = inb(PS2_DATA); outb(PS2_CMD, PS2C_WRITE_CONFIG); outb(PS2_DATA, config | PS2G_XT_COMPAT); - //TODO: get layout from some config file - file_id_t stf = drives->get_file(drives, SCANTAB_DIR "/" LAYOUT_HARDCODE_TMP ".sct"); + uint32_t layout_len; + if (!try_get_sz_setting("kbd-layout", scantab_path + SCANTAB_DIR_LEN, LAYOUT_NAME_MAX_LEN, &layout_len)) + PANIC("keyboard layout not found in settings file."); + if (layout_len == LAYOUT_NAME_MAX_LEN) + logf(LOG_WARN, "keyboard layout name potentially cropped."); + scantab_path[SCANTAB_DIR_LEN + layout_len] = '.'; + scantab_path[SCANTAB_DIR_LEN + layout_len + 1] = 's'; + scantab_path[SCANTAB_DIR_LEN + layout_len + 2] = 'c'; + scantab_path[SCANTAB_DIR_LEN + layout_len + 3] = 't'; + scantab_path[SCANTAB_DIR_LEN + layout_len + 4] = '\0'; + logf(LOG_INFO, "Using scantab file at \"%s\".", scantab_path); + file_id_t stf = drives->get_file(drives, scantab_path); + if (!stf) + PANIC("could not load scantab file."); fmcpy(&n_scantabs, drives, stf, 0, 4); scantabs = allocate_kernel_pages((sizeof(struct scantab_info) * n_scantabs - 1) / 4096 + 1); -- cgit v1.2.3