aboutsummaryrefslogtreecommitdiff
path: root/src/timer.c
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-06-15 22:58:30 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-06-15 22:58:30 +0100
commita1de326ac5d89cbf9555c9a0a9a662af35c6dcf7 (patch)
treeffe56e86be4acefcee8b89753cf31f7a8c1db20d /src/timer.c
parent07e829e591394fa182e75ecab86051f1fb850ce7 (diff)
downloadgold-mine-run-a1de326ac5d89cbf9555c9a0a9a662af35c6dcf7.tar.gz
gold-mine-run-a1de326ac5d89cbf9555c9a0a9a662af35c6dcf7.zip
Implement a countdown clock in the timer
Updated the HUD to show the time.
Diffstat (limited to 'src/timer.c')
-rw-r--r--src/timer.c45
1 files changed, 40 insertions, 5 deletions
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 <dpmi.h>
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;
}