From a1de326ac5d89cbf9555c9a0a9a662af35c6dcf7 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Thu, 15 Jun 2023 22:58:30 +0100 Subject: Implement a countdown clock in the timer Updated the HUD to show the time. --- src/timer.c | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) (limited to 'src/timer.c') diff --git a/src/timer.c b/src/timer.c index d7810b6..ae76037 100644 --- a/src/timer.c +++ b/src/timer.c @@ -4,14 +4,31 @@ #include volatile uint32_t ticks = 0; -volatile static uint32_t ticks_to = 0; +volatile uint32_t clock = 0; +volatile uint8_t clock_secs = 0; +volatile uint8_t clock_enabled = 0; +volatile uint8_t *clock_updated = NULL; static _go32_dpmi_seginfo old_handler, new_handler; static void timer_handler() { ticks++; - ticks_to++; + + if (clock_enabled) + { + clock += 5494; + if (clock > 100000) + { + clock -= 100000; + if (clock_secs) + { + clock_secs--; + if (clock_updated) + *clock_updated = 1; + } + } + } } void timer_init() @@ -28,8 +45,26 @@ void timer_free() fprintf(stderr, "Failed to free the timer :(\n"); } -void timer_wait(uint8_t t) +void timer_start(uint8_t secs, uint8_t *updated) +{ + *updated = 0; + clock_updated = updated; + clock_secs = secs; + clock_enabled = 1; +} + +uint8_t timer_value() +{ + *clock_updated = 0; + return clock_secs; +} + +void timer_stop() +{ + clock_enabled = 0; +} + +void timer_resume() { - while (ticks_to < t); - ticks_to = 0; + clock_enabled = 1; } -- cgit v1.2.3