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

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

static _go32_dpmi_seginfo old_handler, new_handler;

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

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

    outportb(0x20, 0x20);
}

void ubox_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_allocate_iret_wrapper(&new_handler);
    _go32_dpmi_set_protected_mode_interrupt_vector(9, &new_handler);
}

void ubox_keyb_free()
{
    if (_go32_dpmi_set_protected_mode_interrupt_vector(9, &old_handler) != -1)
        _go32_dpmi_free_iret_wrapper(&new_handler);
}