diff options
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 94 |
1 files changed, 94 insertions, 0 deletions
@@ -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; |