From 956a66dc311c80063a8a11c8c09b966b48287e17 Mon Sep 17 00:00:00 2001 From: Erick Date: Sat, 5 Feb 2022 01:27:53 +0100 Subject: [PATCH] fix include errors, include correct libraries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit include 🐛 are finally gone yay it was just a matter of using the right libraries --- tyvm.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/tyvm.c b/tyvm.c index 2144b96..23126fd 100644 --- a/tyvm.c +++ b/tyvm.c @@ -7,14 +7,11 @@ //#define __UNIX /* universal libraries */ -#include -#include -#include -#include -#include + #include + #include + #include /* unix only libraries */ -// FIXME: solve include errors #ifdef __UNIX #include #include @@ -24,11 +21,16 @@ #include #include #include +/* windows only */ +#else + #include + #include #endif #define TRUE 1 #define FALSE 0 +HANDLE hStdin = INVALID_HANDLE_VALUE; /* memory mapped register tables */ enum mmr { @@ -168,7 +170,6 @@ void mem_write(uint16_t address, uint16_t val) { memory[address] = val; } - void mem_read(uint16_t address) { if(address == MMR_KSR) { if(check_key()) { @@ -196,9 +197,36 @@ void mem_read(uint16_t address) { tcsetattr(STDIN_FILENO, TCSANOW, &original_tio); } #else + DWORD fdwMode, fdwOldMode; + void disable_input_buffering() + { + hStdin = GetStdHandle(STD_INPUT_HANDLE); + GetConsoleMode(hStdin, &fdwOldMode); // save old mode + fdwMode = fdwOldMode + ^ ENABLE_ECHO_INPUT // no input echo + ^ ENABLE_LINE_INPUT; // return when one or more characters are available + SetConsoleMode(hStdin, fdwMode); // set new mode + FlushConsoleInputBuffer(hStdin); // clear buffer + } + + void restore_input_buffering() + { + SetConsoleMode(hStdin, fdwOldMode); + } #endif +#ifdef __UNIX + void handle_interrupt(int signal) { + restore_input_buffering(); + printf("\n"); + exit(-2); + } +#endif + + + + int main(int argc, const char* argv[]) { if(argc < 2) {