about summary refs log tree commit diff
path: root/emulator.c
diff options
context:
space:
mode:
authorManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2021-07-24 20:58:06 +0100
committerManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2021-07-24 20:58:06 +0100
commit5d8e1534937fefdf557dbde091a4bbfb34d603f1 (patch)
tree85b5cf473bd0209ad15762760ec5de6594d4d6ac /emulator.c
parentFeature: Implemented various instructions and added a few roms (diff)
downloadCHIP8-Emulator-5d8e1534937fefdf557dbde091a4bbfb34d603f1.tar.gz
CHIP8-Emulator-5d8e1534937fefdf557dbde091a4bbfb34d603f1.tar.bz2
CHIP8-Emulator-5d8e1534937fefdf557dbde091a4bbfb34d603f1.zip
Misc: Added the timer thread variable to the emulator struct
This way we can keep track of the thread to join it on
emulator_deinitialise()
Diffstat (limited to 'emulator.c')
-rw-r--r--emulator.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/emulator.c b/emulator.c
index 615c4fe..8fed056 100644
--- a/emulator.c
+++ b/emulator.c
@@ -48,8 +48,17 @@ int emulator_initialise(Emulator* emulator)
     emulator->keys[14].value = 'f'; //E
     emulator->keys[15].value = 'v'; //F
 
-    pthread_t emulator_timers_thread_id;
-    pthread_create(&emulator_timers_thread_id, NULL, &emulator_timers_thread, emulator);
+    pthread_create(&emulator->timers_thread, NULL, &emulator_timers_thread, emulator);
+
+    return 0;
+}
+
+int emulator_deinitialise(Emulator* emulator)
+{
+    //join timers thread
+    emulator->is_on = 0;
+
+    pthread_join(emulator->timers_thread, NULL);
 
     return 0;
 }
@@ -155,14 +164,16 @@ int emulator_tick(Emulator* emulator)
             dbgprintf("JUMP! (0x%x)\n", NNN);
             emulator->pc = NNN;
 
+#ifdef STOP_ON_INFINITE_LOOP
             if(NNN == instr_pc) //infinite loop
             {
                 printf("INFINITE LOOP DETECTED! EXITING...\n");
                 emulator_dump_registers(emulator);
-                getchar(); //block
+                sleep(2);
+                //getchar(); //block
                 emulator->is_on = 0;
             }
-
+#endif
             break;
         case 0x2:
             dbgprintf("CALL SUBROUTINE! (0x%x)\n", NNN);