From ba9fabf3367047a4e5db841ce8e73ef01d3f557c Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Tue, 6 Jun 2023 21:44:15 +0100 Subject: Add timer wait --- src/timer.c | 9 ++++++++- src/timer.h | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/timer.c b/src/timer.c index 73675dc..d7810b6 100644 --- a/src/timer.c +++ b/src/timer.c @@ -3,14 +3,15 @@ #include #include -/* updates 18.2 times per second by default */ volatile uint32_t ticks = 0; +volatile static uint32_t ticks_to = 0; static _go32_dpmi_seginfo old_handler, new_handler; static void timer_handler() { ticks++; + ticks_to++; } void timer_init() @@ -26,3 +27,9 @@ void timer_free() if (_go32_dpmi_set_protected_mode_interrupt_vector(0x1c, &old_handler) == -1) fprintf(stderr, "Failed to free the timer :(\n"); } + +void timer_wait(uint8_t t) +{ + while (ticks_to < t); + ticks_to = 0; +} diff --git a/src/timer.h b/src/timer.h index 22ef6d2..8ae7e60 100644 --- a/src/timer.h +++ b/src/timer.h @@ -1,9 +1,13 @@ #ifndef _TIMER_H #define _TIMER_H +/* updates 18.2 times per second */ extern volatile uint32_t ticks; void timer_init(); void timer_free(); +/* each t is 54.9254 ms */ +void timer_wait(uint8_t t); + #endif /* _TIMER_H */ -- cgit v1.2.3