diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2020-08-10 19:21:59 -0400 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2020-08-10 19:21:59 -0400 |
commit | a4931b7202c60749df8aeb01c1acb7d538520041 (patch) | |
tree | c4d32af75fb091583a96ced8db44e925445c9f76 /sux.c | |
parent | 2b03202a30e9da09bfc5c0d382b1f5d2287287a4 (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 'sux.c')
-rw-r--r-- | sux.c | 43 |
1 files changed, 22 insertions, 21 deletions
@@ -1,7 +1,5 @@ #include "sux.h" #include <assert.h> -#include <ctype.h> -#include <string.h> #if getclk uint64_t clk[THREADS]; /* Per Thread Clock cycles. */ @@ -512,7 +510,7 @@ void *run(void *args) { #if getclk wprintw(scr, ", Clock cycles: %"PRIu64, iclk); #endif - if (!step && !subdbg) { + if (step && !subdbg) { wrefresh(scr); } #if keypoll @@ -540,7 +538,8 @@ void init_scr() { if (!scr) { scr = initscr(); } - nodelay(stdscr, 0); + nodelay(scr, 0); + wtimeout(scr, 8); crmode(); noecho(); nl(); @@ -556,6 +555,7 @@ int main(int argc, char **argv) { struct suxthr thr[THREADS]; char *tmp = malloc(2048); addr = malloc(mem_size); + memset(key, 0, sizeof(key)); #if bench inss = 0; #endif @@ -637,14 +637,24 @@ int main(int argc, char **argv) { #if keypoll pthread_mutex_lock(&mutex); #endif + c = get_key(scr); + if (c == 19) { + if (kbd_rdy) { + + c = get_key(scr); + } + step = 1; + } else if (c == 0x11) { + end = 1; + continue; + } if (step) { - keypad(scr, 1); - c = wgetch(scr); if (c != 19 && c != 18 && c != 0x11 && !isalnum(c)) { /*WINDOW *w; int maxcol = getmaxx(scr)/2; int maxrow = getmaxy(scr)/2;*/ - switch (c) { + int keycode = get_keycode(key); + switch (keycode) { case KEY_F(1): /*w = newwin(maxrow, maxcol, maxrow, maxcol); emumon(w); @@ -663,20 +673,7 @@ int main(int argc, char **argv) { wprintw(scr, "c: %i", c); wmove(scr, y, x); #endif - c = 0; } - keypad(scr, 0); - } else { - c = wgetch(scr); - } - if (c == 19) { - if (kbd_rdy) { - c = wgetch(scr); - } - step = 1; - } else if (c == 0x11) { - end = 1; - continue; } if (kbd_rdy) { switch (c) { @@ -691,7 +688,11 @@ int main(int argc, char **argv) { #if debug && !bench wmove(scr, getmaxy(scr)-1, 0); wclrtoeol(scr); - wprintw(scr, "c: %i", c); + wprintw(scr, "c: %i ", c); + wprintw(scr, "key: "); + for (int i = 0; key[i] != '\0'; i++) { + wprintw(scr, "$%02X%s", key[i], (key[i+1] != '\0') ? ", " : ""); + } wmove(scr, y, x); #endif } |