aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/keyb.c33
-rw-r--r--src/keyb.h38
2 files changed, 71 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");
+}
diff --git a/src/keyb.h b/src/keyb.h
new file mode 100644
index 0000000..5e47502
--- /dev/null
+++ b/src/keyb.h
@@ -0,0 +1,38 @@
+#ifndef _KEYB_H
+#define _KEYB_H
+
+extern volatile uint8_t keys[0xff];
+
+void keyb_init();
+void keyb_free();
+
+#define KEY_ESC 1
+#define KEY_TAB 15
+#define KEY_ENTER 28
+#define KEY_SPACEBAR 57
+
+#define KEY_A 30
+#define KEY_S 31
+#define KEY_Z 44
+#define KEY_X 45
+#define KEY_P 25
+
+#define KEY_UP 72
+#define KEY_LEFT 75
+#define KEY_RIGHT 77
+#define KEY_DOWN 80
+
+#define KEY_F1 59
+#define KEY_F2 60
+#define KEY_F3 61
+#define KEY_F4 62
+#define KEY_F5 63
+#define KEY_F6 64
+#define KEY_F7 65
+#define KEY_F8 66
+#define KEY_F9 67
+#define KEY_F10 68
+#define KEY_F11 87
+#define KEY_F12 88
+
+#endif /* _KEYB_H */