aboutsummaryrefslogtreecommitdiff
path: root/src/keyb.c
blob: 386287162a1aef31f2b6db1e2d97e29d81f34f5b (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
#include <stdio.h>
#include <stdint.h>
#include <go32.h>
#include <dpmi.h>
#include <pc.h>

volatile uint8_t keys[0xff] = { 0 };

static _go32_dpmi_seginfo old_handler, new_handler;

static void keyb_handler()
{
    uint8_t k = inportb(0x60);

    if (k & 128)
        keys[k & 127] = 0;
    else
        keys[k] = 1;
}

void keyb_init()
{
    _go32_dpmi_get_protected_mode_interrupt_vector(9, &old_handler);
    new_handler.pm_offset = (unsigned long)keyb_handler;
    new_handler.pm_selector = _go32_my_cs();
    _go32_dpmi_chain_protected_mode_interrupt_vector(9, &new_handler);
}

void keyb_free()
{
    if (_go32_dpmi_set_protected_mode_interrupt_vector(9, &old_handler) == -1)
        fprintf(stderr, "Failed to free the keyb :(\n");
}