mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-21 12:29:43 -10:00
Every input driver's state call took a flag, keyboard_mapping_blocked: whether the keys are kept from the binds. It mattered when drivers answered the binds themselves. The frontend answers them now, from the keys it asks a driver for once a poll, and applies the flag itself; a driver's state call answers the keyboard, the mouse and the pointer, and none of the twenty-three read the flag. (udev passed it to its touch code, which did not read it either.) The parameter goes: from the interface, the twenty-three drivers, the frontend's own stand-in driver and its nine calls. The frontend's own functions keep theirs - that is where it is used. Measured against this same master built without it, the frame's input work over 300 frames (X11): 3,690,770 instructions to 3,690,476 with no controller, 4,354,940 to 4,354,646 with one. An argument a call. Checked: the frontend harness passes every lane; the X11 keyboard session logs the same as before, and the hotkey and quit-combination sessions what master's binary logged; the raw input keyboards test and the plain Win32 input test, which call a driver's state function themselves, pass under Wine. Built: Linux in full; DirectInput, raw input and the plain Win32 driver with a mingw compiler; the Android unity build with the NDK; Wayland; the Visual C++ 6 project and the QNX driver on their stand-ins; a build with the optional features off. Not compiled, there being no compiler for them here: Cocoa, UWP, the web driver, SDL 1 and the console drivers (DOS, Wii, PS3, PS4, PSP and Vita, Switch, Wii U); theirs is the same one line, taken out by script. The second of three pieces before steps 3 and 4 of the mapping compiler (plan, section 21). The joypad, its info and the binds are handed to the same call, and two drivers use any of it: the Wii's reads one field of the info, the Wii U's asks the joypad for its touch screen. With those two reworked the call would take the port and what is asked, and nothing else.
245 lines
6.5 KiB
C
245 lines
6.5 KiB
C
/* RetroArch - A frontend for libretro.
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
|
* Copyright (C) 2016-2019 - Brad Parker
|
|
*
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
*
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <pc.h>
|
|
#include <dos.h>
|
|
#include <go32.h>
|
|
#include <dpmi.h>
|
|
#include <sys/segments.h>
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
|
|
#include <retro_miscellaneous.h>
|
|
|
|
#include "../input_driver.h"
|
|
#include "../input_keymaps.h"
|
|
#include "../drivers_keyboard/keyboard_event_dos.h"
|
|
|
|
#define MAX_KEYS LAST_KEYCODE + 1
|
|
|
|
#define END_FUNC(x) static void x##_End() { }
|
|
|
|
#define LOCK_VAR(x) LockData((void*)&x, sizeof(x))
|
|
#define LOCK_FUNC(x) LockCode(x, (int)x##_End - (int)x)
|
|
|
|
/* static globals for interrupt handler */
|
|
static uint16_t normal_keys[MAX_KEYS];
|
|
static _go32_dpmi_seginfo old_kbd_int;
|
|
static _go32_dpmi_seginfo kbd_int;
|
|
|
|
static int LockData(void *a, int size)
|
|
{
|
|
uint32_t baseaddr;
|
|
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(®ion) != -1)
|
|
return 0;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
static int LockCode(void *a, int size)
|
|
{
|
|
uint32_t baseaddr;
|
|
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(®ion) != -1)
|
|
return 0;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
static void keyb_int(void)
|
|
{
|
|
unsigned char buffer = normal_keys[LAST_KEYCODE];
|
|
unsigned char rawcode = inp(0x60);
|
|
/* read scancode from keyboard controller */
|
|
unsigned char make_break = !(rawcode & 0x80);
|
|
/* bit 7: 0 = make, 1 = break */
|
|
int scancode = rawcode & 0x7F;
|
|
|
|
if (buffer == 0xE0)
|
|
{
|
|
/* second byte of an extended key */
|
|
if (scancode < 0x60)
|
|
normal_keys[scancode | (1 << 8)] = make_break;
|
|
|
|
buffer = 0;
|
|
}
|
|
else if (buffer >= 0xE1 && buffer <= 0xE2)
|
|
buffer = 0; /* ignore these extended keys */
|
|
else if (rawcode >= 0xE0 && rawcode <= 0xE2)
|
|
buffer = rawcode; /* first byte of an extended key */
|
|
else if (scancode < 0x60)
|
|
{
|
|
normal_keys[scancode] = make_break;
|
|
buffer = 0;
|
|
}
|
|
normal_keys[LAST_KEYCODE] = buffer;
|
|
outp(0x20, 0x20); /* must send EOI to finish interrupt */
|
|
}
|
|
END_FUNC(keyb_int)
|
|
|
|
/* TODO/FIXME - static globals */
|
|
static uint16_t dos_key_state[MAX_KEYS];
|
|
|
|
uint16_t *dos_keyboard_state_get(void)
|
|
{
|
|
return dos_key_state;
|
|
}
|
|
|
|
static void dos_keyboard_free(void)
|
|
{
|
|
unsigned j;
|
|
|
|
for (j = 0; j < MAX_KEYS; j++)
|
|
dos_key_state[j] = 0;
|
|
}
|
|
|
|
/* The keys the frontend asks about, for a port's binds: which are
|
|
* down. The driver evaluated the binds itself, for the RetroPad mask
|
|
* and for each button; the frontend does that for every driver that
|
|
* hands it the keys, and applies the same rules to all of them. */
|
|
static void dos_input_keys_down(void *data, unsigned port,
|
|
const uint16_t *keys, const uint8_t *bind, unsigned count,
|
|
uint32_t *down)
|
|
{
|
|
unsigned i;
|
|
(void)data;
|
|
(void)bind;
|
|
if (port >= MAX_USERS)
|
|
return;
|
|
for (i = 0; i < count; i++)
|
|
{
|
|
/* as a key is looked up for the keyboard device below */
|
|
unsigned sym = rarch_keysym_lut[keys[i]] & LAST_KEYCODE;
|
|
if (keys[i] < RETROK_LAST && dos_key_state[sym])
|
|
down[i >> 5] |= (1u << (i & 31));
|
|
}
|
|
}
|
|
|
|
static int16_t dos_input_state(
|
|
void *data,
|
|
const input_device_driver_t *joypad,
|
|
rarch_joypad_info_t *joypad_info,
|
|
const retro_keybind_set *binds,
|
|
unsigned port,
|
|
unsigned device,
|
|
unsigned idx,
|
|
unsigned id)
|
|
{
|
|
if (port < MAX_USERS)
|
|
{
|
|
switch (device)
|
|
{
|
|
/* The RetroPad's buttons, where they are bound to keys, are the
|
|
* frontend's to answer: it asks dos_input_keys_down() for the
|
|
* keys once a poll. */
|
|
case RETRO_DEVICE_KEYBOARD:
|
|
|
|
if (id && id < RETROK_LAST)
|
|
{
|
|
unsigned sym = rarch_keysym_lut[(enum retro_key)id] & LAST_KEYCODE;
|
|
return dos_key_state[sym];
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void dos_input_poll(void *data)
|
|
{
|
|
uint32_t key;
|
|
uint16_t *cur_state = dos_keyboard_state_get();
|
|
|
|
for (key = 0; key < LAST_KEYCODE; key++)
|
|
{
|
|
if (cur_state[key] != normal_keys[key])
|
|
{
|
|
unsigned code = input_keymaps_translate_keysym_to_rk(key);
|
|
input_keyboard_event(normal_keys[key], code, code, 0, RETRO_DEVICE_KEYBOARD);
|
|
}
|
|
}
|
|
memcpy(cur_state, normal_keys, sizeof(normal_keys));
|
|
}
|
|
|
|
static void dos_input_free_input(void *data)
|
|
{
|
|
dos_keyboard_free();
|
|
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 void* dos_input_init(const char *joypad_driver)
|
|
{
|
|
_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);
|
|
|
|
input_keymaps_init_keyboard_lut(rarch_key_map_dos);
|
|
return (void*)-1;
|
|
}
|
|
|
|
static uint64_t dos_input_get_capabilities(void *data)
|
|
{
|
|
return (1 << RETRO_DEVICE_JOYPAD)
|
|
| (1 << RETRO_DEVICE_KEYBOARD);
|
|
}
|
|
|
|
input_driver_t input_dos = {
|
|
dos_input_init,
|
|
dos_input_poll,
|
|
dos_input_state,
|
|
dos_input_free_input,
|
|
NULL,
|
|
NULL,
|
|
dos_input_get_capabilities,
|
|
"dos",
|
|
NULL, /* grab_mouse */
|
|
NULL,
|
|
NULL,
|
|
NULL, /* survives_video */
|
|
dos_input_keys_down
|
|
};
|