From e60c3c684f87f32ba0500892ff85215faaaad0d5 Mon Sep 17 00:00:00 2001 From: Manuel Palenzuela Date: Mon, 19 Jul 2021 17:30:55 +0100 Subject: Feature: Added timers thread --- emulator.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'emulator.c') 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"); -- cgit 1.4.1