aboutsummaryrefslogtreecommitdiff
path: root/src/timer.c
blob: d7810b6d1a6ec9f49c4297ed9bbf0a1797bc9866 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
#include <stdint.h>
#include <go32.h>
#include <dpmi.h>

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()
{
    _go32_dpmi_get_protected_mode_interrupt_vector(0x1c, &old_handler);
    new_handler.pm_offset = (unsigned long)timer_handler;
    new_handler.pm_selector = _go32_my_cs();
    _go32_dpmi_chain_protected_mode_interrupt_vector(0x1c, &new_handler);
}

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;
}