diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2022-02-02 15:02:20 -0400 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2022-02-02 15:02:20 -0400 |
commit | 9e5faf854dad240e8eb089ce799c6912054aabf6 (patch) | |
tree | 157a1751b8e63fff94a339337b5bf9acefdeff3c | |
parent | 5aa885bb00a76a6be066a164187c8c2a065d6fab (diff) |
sux.h, io.c: Added support for setting key timeout.
-rw-r--r-- | io.c | 13 | ||||
-rw-r--r-- | sux.h | 8 |
2 files changed, 11 insertions, 10 deletions
@@ -44,13 +44,14 @@ static inline char *get_keyseq(int keycode) { } } -int get_key(WINDOW *scr) { +int get_key(WINDOW *scr, int delay, uint64_t cycles) { int x, y; int c; int keycode = 0; int tmp_flag = dbg_print_per_inst; - curs_set(1); - if ((key == NULL) || (key && key[key_idx] == '\0') || !kbd_rdy) { + wtimeout(scr, delay); + curs_set((delay < 0)); + if ((key == NULL) || (key && key[key_idx] == '\0') || !kbd_rdy || delay >= 0) { c = wgetch(scr); if (c == 19) { if (kbd_rdy) { @@ -60,13 +61,13 @@ int get_key(WINDOW *scr) { } else if (c == 0x11) { end = 1; } - if (kbd_rdy) { + if (kbd_rdy && delay < 0) { key_idx = 0; key = get_keyseq(c); } keycode = c; } - if (kbd_rdy) { + if (kbd_rdy && delay < 0) { c = (key != NULL) ? key[key_idx++] : c; } @@ -106,7 +107,7 @@ int get_key(WINDOW *scr) { } } - if (kbd_rdy) { + if (kbd_rdy && delay < 0) { switch (c) { case ERR: addr[CTRL_ADDR] = 0; @@ -64,8 +64,8 @@ extern void disasm(struct sux *cpu, WINDOW *w, uint8_t lines, uint8_t opcode, ui /*#define KEYBUF_SIZE 0x40 char key[KEYBUF_SIZE];*/ -extern int get_key(WINDOW *scr); -extern void io(uint64_t address, uint8_t rw); +extern int get_key(WINDOW *scr, int delay, uint64_t cycles); +extern void io(uint64_t address, uint8_t rw, uint64_t cycles); extern void init_scr(); @@ -384,7 +384,7 @@ static /*inline*/ uint64_t read_value(struct sux *cpu, uint64_t reg, uint64_t ad pthread_mutex_lock(&mutex); #endif if (check_io) { - io(address, 1); + io(address, 1, cpu->clk); } #if keypoll pthread_mutex_unlock(&mutex); @@ -422,7 +422,7 @@ static /*inline*/ void write_value(struct sux *cpu, uint64_t value, uint64_t add pthread_mutex_lock(&mutex); #endif if (check_io) { - io(address, 0); + io(address, 0, cpu->clk); } #if keypoll pthread_mutex_unlock(&mutex); |