6502

minimal 6502 emulator written in C
Index Commits Files Refs README LICENSE
commit 8515a45ff17102a93bf77c123798a1aa3f636b46
parent a2a21b54011e12761f6b51f6343f9491a05b1cc5
Author: mjkloeckner <martin.cachari@gmail.com>
Date:   Sun, 30 Apr 2023 17:38:54 -0300

wait for user input if invalid instruction reached

Diffstat:
Mmain.c | 13++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/main.c b/main.c
@@ -8,6 +8,8 @@
 #include <stdbool.h>
 #include <signal.h>
 
+#include <unistd.h>
+
 #include <time.h>
 #define usleep(t) nanosleep((const struct timespec[]){{0, t * 1000L}}, NULL)
 
@@ -60,9 +62,14 @@ int main (void) {
         CPU_fetch(&ins);
         CPU_dump();
 
-        /* Execute instruction */
-        if(CPU_exec(ins) != 0) brk = true;
-        usleep(100);
+        if(CPU_exec(ins) != 0) {
+            /* exit if invalid instruction */
+            char c;
+            read(STDIN_FILENO, &c, 1);
+            brk = true;
+        }
+
+        nsleep(1000);
     } while(!brk);
 
     reset_input_mode();