From 06fe0ee3f4efc30c17bdf6c8ff9970bb02430203 Mon Sep 17 00:00:00 2001 From: Jon Feldman Date: Mon, 20 Feb 2017 21:53:43 -0500 Subject: [PATCH] Reimplement (shitty) ps/2 keyboard input module --- Makefile | 1 + common/kernel_main.c | 3 +- include/module_console.h | 17 +++++++++-- module/biosvga/module.c | 5 +++- module/console.c | 8 ++++++ module/ps2input/module.c | 62 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 module/ps2input/module.c diff --git a/Makefile b/Makefile index 246db95..f02c60e 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ TGT=i686 SOURCES= \ $(TGT)/entry.o $(TGT)/utils.o $(TGT)/gdt.o $(TGT)/idt.o $(TGT)/timer.o \ module/biosvga/module.o \ + module/ps2input/module.o \ module/console.o \ common/stdc/putc.o common/stdc/puts.o common/stdc/vsprintf.o common/stdc/printf.o common/stdc/strcatlen.o common/stdc/dumphex.o \ common/stdc/memmove.o common/stdc/strlen.o common/stdc/memcmp.o common/stdc/memset.o common/stdc/memcpy.o \ diff --git a/common/kernel_main.c b/common/kernel_main.c index f8214ec..98fa21d 100644 --- a/common/kernel_main.c +++ b/common/kernel_main.c @@ -11,8 +11,7 @@ int kernel_main(struct multiboot *mboot_ptr) printf("1%c%% %s %X\n", 'c', "whoop", 0xDEADBEEF); while(1) { - uint64_t ticks = clock(); - printf("%X%X\r", ((uint32_t*)&ticks)[1], ((uint32_t*)&ticks)[0]); + console_refresh(); asm("hlt"); } diff --git a/include/module_console.h b/include/module_console.h index 4e0b137..c274c8e 100644 --- a/include/module_console.h +++ b/include/module_console.h @@ -1,12 +1,23 @@ #include typedef void (*module_out_f) (char); +typedef char (*module_in_f) (void); +typedef int (*module_avail_f) (void); struct output { - module_out_f out; + module_out_f out; }; -void console_reg(struct output*); -void console_unreg(struct output*); +struct input { + module_in_f in; + module_avail_f avail; +}; + +void console_reg_write(struct output*); +void console_unreg_write(struct output*); + +void console_reg_read(struct input*); +void console_unreg_read(struct input*); + void console_init(); void console_deinit(); diff --git a/module/biosvga/module.c b/module/biosvga/module.c index a9f4866..04f1fca 100644 --- a/module/biosvga/module.c +++ b/module/biosvga/module.c @@ -31,7 +31,10 @@ void biosvga_wb(char c) { x = 0; break; case '\b': - if (x) --x; + if (x) { + --x; + video_mem[y * 80 + x] = (attr << 8) | ' '; + } break; case '\t': x += 4 - (x % 4); diff --git a/module/console.c b/module/console.c index 9faf2c4..e836b88 100644 --- a/module/console.c +++ b/module/console.c @@ -32,12 +32,20 @@ void console_unreg_read(struct input* out) { in_active = NULL; } +void console_refresh() { + while (in_active->avail()) { + out_active->out(in_active->in()); + } +} + void console_init() { // Temporary biosvga_init(); + ps2input_init(); } void console_deinit() { // Temporary biosvga_deinit(); + ps2input_deinit(); } diff --git a/module/ps2input/module.c b/module/ps2input/module.c new file mode 100644 index 0000000..27a1e6d --- /dev/null +++ b/module/ps2input/module.c @@ -0,0 +1,62 @@ +#include +#include +#include +#include + +#include + +char avail_buf[256]; +int avail_cnt = 0; + +void ps2input_int(struct interrupt_frame* esp) { + do { + if (inb(0x60) != 0) { + avail_buf[avail_cnt] = inb(0x60); + if (avail_buf[avail_cnt]) { + ++avail_cnt; + return; + } + } + } while(1); +} + +char charmap[256] = { + 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', + '-', '=', '\b', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', + 'o', 'p', '[', ']', '\n', 0, 'a', 's', 'd', 'f', 'g', 'h', + 'j', 'k', 'l', ';', '\'', '`', 0, '\\', 'z', 'x', 'c', 'v', + 'b', 'n', 'm', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', 0, 0, 0, '+', ' ', +}; + +char ps2input_rb() { + if (!avail_cnt) + return 0; + + --avail_cnt; + + char r = charmap[avail_buf[0]]; + + memcpy(&avail_buf[0], &avail_buf[1], 255); + + return r; +} + +int ps2input_avail() { + return avail_cnt; +} + +struct input ps2input_module = { + .in = ps2input_rb, + .avail = ps2input_avail +}; + +void ps2input_init() { + register_int_handler(33, ps2input_int); + console_reg_read(&ps2input_module); +} + +void ps2input_deinit() { + console_unreg_read(&ps2input_module); + // Stub. +} -- 2.39.5