From fac9ee8a1fd1306e97f264b2ef5d00326c01b98f Mon Sep 17 00:00:00 2001 From: Erick Date: Sat, 5 Feb 2022 01:18:10 +0100 Subject: [PATCH] add check_key() for windows and unix-based os' --- tyvm.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tyvm.c b/tyvm.c index c37d357..701b226 100644 --- a/tyvm.c +++ b/tyvm.c @@ -144,9 +144,29 @@ int read_image(const char* image_path) { return 1; } + +#ifdef __UNIX + uint16_t check_key() +{ + fd_set readfds; + FD_ZERO(&readfds); + FD_SET(STDIN_FILENO, &readfds); + + struct timeval timeout; + timeout.tv_sec = 0; + timeout.tv_usec = 0; + return select(1, &readfds, NULL, NULL, &timeout) != 0; +} +#else +uint16_t check_key() +{ + return WaitForSingleObject(hStdin, 1000) == WAIT_OBJECT_0 && _kbhit(); +} + void mem_write(uint16_t address, uint16_t val) { memory[address] = val; } +#endif void mem_read(uint16_t address) { if(address == MMR_KSR) {