summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--io.c94
-rw-r--r--sux.c43
-rw-r--r--sux.h7
3 files changed, 123 insertions, 21 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;
diff --git a/sux.c b/sux.c
index 4a08d59..cf66bfd 100644
--- a/sux.c
+++ b/sux.c
@@ -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
}
diff --git a/sux.h b/sux.h
index abc6b7f..681e08e 100644
--- a/sux.h
+++ b/sux.h
@@ -1,5 +1,7 @@
#include "opcode.h"
#include <pthread.h>
+#include <ctype.h>
+#include <string.h>
#if bench
#include <sys/time.h>
@@ -39,6 +41,11 @@ extern pthread_cond_t main_cond;
extern void disasm(struct sux *cpu, uint64_t *operands, uint8_t lines, uint8_t opcode, uint8_t prefix, uint8_t thread);
#endif
+#define KEYBUF_SIZE 0x40
+char key[KEYBUF_SIZE];
+
+extern int get_keycode(char *str);
+extern int get_key(WINDOW *scr);
extern void io(uint64_t address, uint8_t rw);
static inline uint64_t get_addr(struct sux *cpu, uint64_t *tmpaddr, uint8_t opcode, uint8_t prefix, uint8_t thread) {