]> Chaos Git - misc/eidos.git/commitdiff
Reimplement (shitty) ps/2 keyboard input module
authorJon Feldman <chaos.kagami@gmail.com>
Tue, 21 Feb 2017 02:53:43 +0000 (21:53 -0500)
committerJon Feldman <chaos.kagami@gmail.com>
Tue, 21 Feb 2017 02:53:43 +0000 (21:53 -0500)
Makefile
common/kernel_main.c
include/module_console.h
module/biosvga/module.c
module/console.c
module/ps2input/module.c [new file with mode: 0644]

index 246db951e4c0c52827eaca369f4ee3c8109f10a2..f02c60e8ae2a3c808dfd5425ab104c20b2cae192 100644 (file)
--- 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 \
index f8214ec9d408905e1cb71ec78d62bbde082d551d..98fa21d23a0e0bc51c7d8f3970d520bd853e8e43 100644 (file)
@@ -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");
     }
 
index 4e0b137dabfd377602aaf68d02e4c28c5174db59..c274c8e7610640004ee5477eab734cd6f418fbba 100644 (file)
@@ -1,12 +1,23 @@
 #include <stdarg.h>
 
 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();
index a9f48664b5731eef79e90b50bccbde15d135a7c6..04f1fcac5b1ee5999e101643257a9e10abb2e816 100644 (file)
@@ -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);
index 9faf2c40d18b6b9de325f08ea2f9395c1ea8b230..e836b88f479e2a85f921e80ee5289bfba9e117b1 100644 (file)
@@ -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 (file)
index 0000000..27a1e6d
--- /dev/null
@@ -0,0 +1,62 @@
+#include <stdint.h>
+#include <string.h>
+#include <module.h>
+#include <module_console.h>
+
+#include <idt.h>
+
+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.
+}