repos/6502

minimal 6502 cpu emulator
Commits Files Refs README LICENSE
commit 87b9a3eb0c956a70efaff38862222f5b088285f7
parent 4e9422fc672e8de182977c34b3492a54633820ad
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date:   Sun, 12 Oct 2025 19:06:32 -0300

fix `usleep` not working properly

Diffstat:
Mmain.c | 11++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/main.c b/main.c
@@ -11,14 +11,19 @@
 #include <unistd.h>
 
 #include <time.h>
-#define nsleep(t) nanosleep((const struct timespec[]){{0, t * 1000L}}, NULL)
 
-#define INPUT_FILE_PATH    "6502_functional_test.bin"
+#define usleep(t) do {                                     \
+    nanosleep((const struct timespec[])                    \
+            {{t / 1000000, (t % 1000000) * 1000L}}, NULL); \
+    } while(0)
+
+#define INPUT_FILE_PATH "6502_functional_test.bin"
 
 /* TODO: Add support for command line arguments */
 /* TODO: Add proper system monitor (memory dump, cpu registers) */
 
 static bool brk = false;
+uint32_t t_us_delay = 50000;
 
 void CPU_brk(uint16_t pc) {
     if (CPU_get_pc () == pc) {
@@ -70,7 +75,7 @@ int main(void) {
             brk = true;
         }
 
-        nsleep(1000);
+        usleep(t_us_delay);
     } while(!brk);
 
     reset_input_mode();