Simplify DOS keyboard code

This commit is contained in:
twinaphex 2019-06-23 02:22:54 +02:00
parent e51a98a295
commit ceecf4751a
4 changed files with 31 additions and 66 deletions

View File

@ -1888,8 +1888,7 @@ ifneq ($(findstring DOS,$(OS)),)
gfx/drivers_font/vga_font.o \
input/drivers/dos_input.o \
input/drivers_joypad/dos_joypad.o \
frontend/drivers/platform_dos.o \
input/drivers_keyboard/keyboard_event_dos.o
frontend/drivers/platform_dos.o
ifeq ($(HAVE_MENU_COMMON), 1)
OBJ += menu/drivers_display/menu_display_vga.o

View File

@ -1,6 +1,7 @@
/* 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-
@ -17,6 +18,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <retro_miscellaneous.h>
#include "../input_driver.h"
#include "../input_keymaps.h"
#include "../drivers_keyboard/keyboard_event_dos.h"
@ -29,6 +32,33 @@ typedef struct dos_input
const input_device_driver_t *joypad;
} dos_input_t;
#define MAX_KEYS LAST_KEYCODE + 1
/* First ports are used to keeping track of gamepad states. Last port is used for keyboard state */
static uint16_t dos_key_state[MAX_PADS+1][MAX_KEYS];
static bool dos_keyboard_port_input_pressed(
const struct retro_keybind *binds, unsigned id)
{
if (id < RARCH_BIND_LIST_END)
return dos_key_state[DOS_KEYBOARD_PORT][rarch_keysym_lut[&binds[id].key]];
return false;
}
uint16_t *dos_keyboard_state_get(unsigned port)
{
return dos_key_state[port];
}
static void dos_keyboard_free(void)
{
unsigned i, j;
for (i = 0; i < MAX_PADS; i++)
for (j = 0; j < MAX_KEYS; j++)
dos_key_state[i][j] = 0;
}
static void dos_input_poll(void *data)
{
dos_input_t *dos = (dos_input_t*)data;

View File

@ -1,56 +0,0 @@
/* RetroArch - A frontend for libretro.
* 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 <retro_miscellaneous.h>
#include "keyboard_event_dos.h"
#include "../input_keymaps.h"
#define MAX_KEYS LAST_KEYCODE + 1
// First ports are used to keeping track of gamepad states. Last port is used for keyboard state
static uint16_t dos_key_state[MAX_PADS+1][MAX_KEYS];
bool dos_keyboard_port_input_pressed(const struct retro_keybind *binds, unsigned id)
{
if (id < RARCH_BIND_LIST_END)
{
const struct retro_keybind *bind = &binds[id];
unsigned key = rarch_keysym_lut[bind->key];
return dos_key_state[DOS_KEYBOARD_PORT][key];
}
return false;
}
bool dos_keyboard_input_pressed(unsigned key)
{
unsigned keysym = rarch_keysym_lut[key];
return dos_key_state[DOS_KEYBOARD_PORT][keysym];
}
uint16_t *dos_keyboard_state_get(unsigned port)
{
return dos_key_state[port];
}
void dos_keyboard_free(void)
{
unsigned i, j;
for (i = 0; i < MAX_PADS; i++)
for (j = 0; j < MAX_KEYS; j++)
dos_key_state[i][j] = 0;
}

View File

@ -124,14 +124,6 @@ enum {
#define DOS_KEYBOARD_PORT MAX_PADS
bool dos_keyboard_port_input_pressed(const struct retro_keybind *binds, unsigned id);
bool dos_keyboard_input_pressed(unsigned key);
uint16_t *dos_keyboard_state_get(unsigned port);
void dos_keyboard_init(void);
void dos_keyboard_free(void);
#endif