diff options
author | Manuel Palenzuela <manuelpalenzuelamerino@gmail.com> | 2021-07-19 17:30:55 +0100 |
---|---|---|
committer | Manuel Palenzuela <manuelpalenzuelamerino@gmail.com> | 2021-07-19 17:30:55 +0100 |
commit | e60c3c684f87f32ba0500892ff85215faaaad0d5 (patch) | |
tree | 7707021822ebdf348d0dc6468d216ed33d207bff /emulator.c | |
parent | Misc: Added the dbgprintf() macro (diff) | |
download | CHIP8-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.c | 21 |
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"); |