about summary refs log tree commit diff
path: root/emulator.c
diff options
context:
space:
mode:
authorManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2021-07-19 17:30:55 +0100
committerManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2021-07-19 17:30:55 +0100
commite60c3c684f87f32ba0500892ff85215faaaad0d5 (patch)
tree7707021822ebdf348d0dc6468d216ed33d207bff /emulator.c
parentMisc: Added the dbgprintf() macro (diff)
downloadCHIP8-Emulator-e60c3c684f87f32ba0500892ff85215faaaad0d5.tar.gz
CHIP8-Emulator-e60c3c684f87f32ba0500892ff85215faaaad0d5.tar.bz2
CHIP8-Emulator-e60c3c684f87f32ba0500892ff85215faaaad0d5.zip
Feature: Added timers thread
Diffstat (limited to 'emulator.c')
-rw-r--r--emulator.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/emulator.c b/emulator.c
index 94cd3d8..ce607fe 100644
--- a/emulator.c
+++ b/emulator.c
@@ -28,6 +28,9 @@ int emulator_initialise(Emulator* emulator)
     memcpy(emulator->memory + FONT_LOAD_LOCATION, font, sizeof(font));
     emulator->is_on = 1;
 
+    pthread_t emulator_timers_thread_id;
+    pthread_create(&emulator_timers_thread_id, NULL, &emulator_timers_thread, emulator);
+
     return 0;
 }
 
@@ -133,6 +136,24 @@ int emulator_tick(Emulator* emulator)
     return 0;
 }
 
+void* emulator_timers_thread(Emulator* emulator)
+{
+    printf("STARTED TIMERS THREAD\n");
+
+    while(emulator->is_on)
+    {
+        if(emulator->delay_timer > 0)
+            --emulator->delay_timer;
+
+        if(emulator->sound_timer > 0)
+            --emulator->sound_timer;
+
+        usleep(1000000 / 60);
+    }
+
+    return NULL;
+}
+
 void emulator_dump_registers(Emulator* emulator)
 {
     printf("REGISTERS: \n");