aboutsummaryrefslogtreecommitdiff
path: root/src/keyb.c
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-06-05 22:38:57 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-06-05 22:38:57 +0100
commit830082c1b0219b95ad4f38d1f0270fd210d9b511 (patch)
tree2a920d1ae02ff68ac608284344edd983f531425a /src/keyb.c
parent6c93950f95fe77d3877557c8eca08c13f5eb2594 (diff)
downloadgold-mine-run-830082c1b0219b95ad4f38d1f0270fd210d9b511.tar.gz
gold-mine-run-830082c1b0219b95ad4f38d1f0270fd210d9b511.zip
Add a keyboard driver
Defines for some of the keys.
Diffstat (limited to 'src/keyb.c')
-rw-r--r--src/keyb.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/keyb.c b/src/keyb.c
new file mode 100644
index 0000000..3862871
--- /dev/null
+++ b/src/keyb.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <go32.h>
+#include <dpmi.h>
+#include <pc.h>
+
+volatile uint8_t keys[0xff] = { 0 };
+
+static _go32_dpmi_seginfo old_handler, new_handler;
+
+static void keyb_handler()
+{
+ uint8_t k = inportb(0x60);
+
+ if (k & 128)
+ keys[k & 127] = 0;
+ else
+ keys[k] = 1;
+}
+
+void keyb_init()
+{
+ _go32_dpmi_get_protected_mode_interrupt_vector(9, &old_handler);
+ new_handler.pm_offset = (unsigned long)keyb_handler;
+ new_handler.pm_selector = _go32_my_cs();
+ _go32_dpmi_chain_protected_mode_interrupt_vector(9, &new_handler);
+}
+
+void keyb_free()
+{
+ if (_go32_dpmi_set_protected_mode_interrupt_vector(9, &old_handler) == -1)
+ fprintf(stderr, "Failed to free the keyb :(\n");
+}