summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2020-08-10 19:21:59 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2020-08-10 19:21:59 -0400
commita4931b7202c60749df8aeb01c1acb7d538520041 (patch)
treec4d32af75fb091583a96ced8db44e925445c9f76 /io.c
parent2b03202a30e9da09bfc5c0d382b1f5d2287287a4 (diff)
Refactored the keyboard I/O emulation.
It now saves the characters of the typed key into a buffer, and returns each character in the buffer one at a time, until it reaches a null terminator, at which point it starts getting the next key. The reason for doing this was to make getting multi character keys faster, by not calling getch() for each character. The only downside to this is that I have to set a timeout() for getch(), making it somewhat non blocking, although the delay is 8 milliseconds. The next thing I'll probably be doing, is working more on the SuB suite.
Diffstat (limited to 'io.c')
-rw-r--r--io.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/io.c b/io.c
index dc07d52..352d8ab 100644
--- a/io.c
+++ b/io.c
@@ -1,9 +1,103 @@
#include "sux.h"
+uint8_t key_idx = 0;
+
uint8_t iscol;
uint8_t idx = 3;
uint8_t bcd[4];
+int get_keycode(char *str) {
+ size_t size = strlen(str);
+ int keycode = 0;
+ if (size == 1) {
+ keycode = str[0];
+ } else if (size > 1) {
+ int isesc = 0;
+ for (int i = 0; str[i] != '\0'; i++) {
+ switch (str[i]) {
+ case '\x1B': isesc = 1; break;
+ case '[':
+ if (isesc) {
+ i++;
+ char tmp[3];
+ switch (str[i]) {
+ case 'A': keycode = KEY_UP ; break;
+ case 'B': keycode = KEY_DOWN ; break;
+ case 'C': keycode = KEY_LEFT ; break;
+ case 'D': keycode = KEY_RIGHT; break;
+ default :
+ if (isdigit(str[i])) {
+ memcpy(tmp, str+i, 2);
+ i += 2;
+ tmp[2] = '\0';
+ int num = strtol(tmp, NULL, 10);
+ if (str[i] == '~') {
+ switch (num) {
+ case 15: keycode = KEY_F( 5); break;
+ case 17: keycode = KEY_F( 6); break;
+ case 18: keycode = KEY_F( 7); break;
+ case 19: keycode = KEY_F( 8); break;
+ case 20: keycode = KEY_F( 9); break;
+ case 21: keycode = KEY_F(10); break;
+ case 23: keycode = KEY_F(11); break;
+ case 24: keycode = KEY_F(12); break;
+ }
+ }
+ }
+
+ }
+ } else {
+ keycode = '[';
+ }
+ break;
+ case 'O':
+ if (isesc) {
+ i++;
+ switch (str[i]) {
+ case 'P': keycode = KEY_F(1); break;
+ case 'Q': keycode = KEY_F(2); break;
+ case 'R': keycode = KEY_F(3); break;
+ case 'S': keycode = KEY_F(4); break;
+ }
+ } else {
+ keycode = 'O';
+ }
+ break;
+ }
+ }
+ }
+ return keycode;
+}
+
+int get_key(WINDOW *scr) {
+ int c = 0;
+ uint8_t i = 0;
+ uint8_t isesc = 0;
+
+ size_t size = strlen(key);
+ if (key[key_idx] == '\0' && size) {
+ memset(key, 0, size+1);
+ key_idx = 0;
+ }
+ if (!size || !key_idx) {
+ for (;;) {
+ c = wgetch(scr);
+ if (c != ERR) {
+ key[i++] = c;
+ isesc = (c == '\x1B');
+ } else if (i && !isesc) {
+ key[i] = 0;
+ key_idx = 0;
+ size = strlen(key);
+ break;
+ }
+ }
+ }
+ if (key[key_idx] != '\0') {
+ return key[key_idx++];
+ }
+}
+
void io(uint64_t address, uint8_t rw) {
int x, y;
uint16_t scr_col = 0;