summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2022-02-02 15:02:20 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2022-02-02 15:02:20 -0400
commit9e5faf854dad240e8eb089ce799c6912054aabf6 (patch)
tree157a1751b8e63fff94a339337b5bf9acefdeff3c
parent5aa885bb00a76a6be066a164187c8c2a065d6fab (diff)
sux.h, io.c: Added support for setting key timeout.
-rw-r--r--io.c13
-rw-r--r--sux.h8
2 files changed, 11 insertions, 10 deletions
diff --git a/io.c b/io.c
index 9848e8d..0c3a327 100644
--- a/io.c
+++ b/io.c
@@ -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;
diff --git a/sux.h b/sux.h
index 18087a0..d80afc1 100644
--- a/sux.h
+++ b/sux.h
@@ -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);