(Joypad drivers) Cleanup dos_joypad.c

This commit is contained in:
libretroadmin 2023-02-20 10:18:48 +01:00
parent 6f26f37cec
commit 93de4f3c4f

View File

@ -43,40 +43,34 @@ static uint16_t normal_keys[LAST_KEYCODE + 1];
static _go32_dpmi_seginfo old_kbd_int;
static _go32_dpmi_seginfo kbd_int;
int LockData(void *a, int size)
static int LockData(void *a, int size)
{
uint32_t baseaddr;
__dpmi_meminfo region;
if (__dpmi_get_segment_base_address(_my_ds(), &baseaddr) == -1)
return -1;
region.handle = 0;
region.size = size;
region.address = baseaddr + (uint32_t)a;
if (__dpmi_lock_linear_region(&region) == -1)
return -1;
return 0;
if (__dpmi_get_segment_base_address(_my_ds(), &baseaddr) != -1)
{
__dpmi_meminfo region;
region.handle = 0;
region.size = size;
region.address = baseaddr + (uint32_t)a;
if (__dpmi_lock_linear_region(&region) != -1)
return 0;
}
return -1;
}
int LockCode(void *a, int size)
static int LockCode(void *a, int size)
{
uint32_t baseaddr;
__dpmi_meminfo region;
if (__dpmi_get_segment_base_address(_my_cs(), &baseaddr) == -1)
return (-1);
region.handle = 0;
region.size = size;
region.address = baseaddr + (uint32_t)a;
if (__dpmi_lock_linear_region(&region) == -1)
return (-1);
return 0;
if (__dpmi_get_segment_base_address(_my_cs(), &baseaddr) != -1)
{
__dpmi_meminfo region;
region.handle = 0;
region.size = size;
region.address = baseaddr + (uint32_t)a;
if (__dpmi_lock_linear_region(&region) != -1)
return 0;
}
return -1;
}
static void keyb_int(void)
@ -107,35 +101,6 @@ static void keyb_int(void)
}
END_FUNC(keyb_int)
static void hook_keyb_int(void)
{
_go32_dpmi_get_protected_mode_interrupt_vector(9, &old_kbd_int);
memset(&kbd_int, 0, sizeof(kbd_int));
memset(normal_keys, 0, sizeof(normal_keys));
LOCK_FUNC(keyb_int);
LOCK_VAR(normal_keys);
kbd_int.pm_selector = _go32_my_cs();
kbd_int.pm_offset = (uint32_t)&keyb_int;
_go32_dpmi_allocate_iret_wrapper(&kbd_int);
_go32_dpmi_set_protected_mode_interrupt_vector(9, &kbd_int);
}
static void unhook_keyb_int(void)
{
if (old_kbd_int.pm_offset)
{
_go32_dpmi_set_protected_mode_interrupt_vector(9, &old_kbd_int);
_go32_dpmi_free_iret_wrapper(&kbd_int);
memset(&old_kbd_int, 0, sizeof(old_kbd_int));
}
}
static const char *dos_joypad_name(unsigned pad)
{
return "DOS Controller";
@ -155,7 +120,20 @@ static void dos_joypad_autodetect_add(unsigned autoconf_pad)
static void *dos_joypad_init(void *data)
{
hook_keyb_int();
_go32_dpmi_get_protected_mode_interrupt_vector(9, &old_kbd_int);
memset(&kbd_int, 0, sizeof(kbd_int));
memset(normal_keys, 0, sizeof(normal_keys));
LOCK_FUNC(keyb_int);
LOCK_VAR(normal_keys);
kbd_int.pm_selector = _go32_my_cs();
kbd_int.pm_offset = (uint32_t)&keyb_int;
_go32_dpmi_allocate_iret_wrapper(&kbd_int);
_go32_dpmi_set_protected_mode_interrupt_vector(9, &kbd_int);
dos_joypad_autodetect_add(0);
return (void*)-1;
}
@ -258,7 +236,13 @@ static bool dos_joypad_query_pad(unsigned pad)
static void dos_joypad_destroy(void)
{
unhook_keyb_int();
if (old_kbd_int.pm_offset)
{
_go32_dpmi_set_protected_mode_interrupt_vector(9, &old_kbd_int);
_go32_dpmi_free_iret_wrapper(&kbd_int);
memset(&old_kbd_int, 0, sizeof(old_kbd_int));
}
}
input_device_driver_t dos_joypad = {