mirror of
https://github.com/libretro/RetroArch
synced 2025-02-11 06:40:48 +00:00
Refactor out input_conv_analog*
This commit is contained in:
parent
bd9f8dbd3a
commit
192ca096c9
49
input/input_common.h
Normal file
49
input/input_common.h
Normal file
@ -0,0 +1,49 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef INPUT_COMMON_H__
|
||||
#define INPUT_COMMON_H__
|
||||
|
||||
#include "../driver.h"
|
||||
|
||||
static inline void input_conv_analog_id_to_bind_id(unsigned index, unsigned id,
|
||||
unsigned *id_minus, unsigned *id_plus)
|
||||
{
|
||||
switch ((index << 1) | id)
|
||||
{
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_LEFT << 1) | RETRO_DEVICE_ID_ANALOG_X:
|
||||
*id_minus = RARCH_ANALOG_LEFT_X_MINUS;
|
||||
*id_plus = RARCH_ANALOG_LEFT_X_PLUS;
|
||||
break;
|
||||
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_LEFT << 1) | RETRO_DEVICE_ID_ANALOG_Y:
|
||||
*id_minus = RARCH_ANALOG_LEFT_Y_MINUS;
|
||||
*id_plus = RARCH_ANALOG_LEFT_Y_PLUS;
|
||||
break;
|
||||
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_RIGHT << 1) | RETRO_DEVICE_ID_ANALOG_X:
|
||||
*id_minus = RARCH_ANALOG_RIGHT_X_MINUS;
|
||||
*id_plus = RARCH_ANALOG_RIGHT_X_PLUS;
|
||||
break;
|
||||
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_RIGHT << 1) | RETRO_DEVICE_ID_ANALOG_Y:
|
||||
*id_minus = RARCH_ANALOG_RIGHT_Y_MINUS;
|
||||
*id_plus = RARCH_ANALOG_RIGHT_Y_PLUS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "../general.h"
|
||||
#include "linuxraw_input.h"
|
||||
#include "rarch_sdl_input.h"
|
||||
#include "input_common.h"
|
||||
|
||||
static long oldKbmd = 0xffff;
|
||||
static struct termios oldTerm, newTerm;
|
||||
@ -256,33 +257,6 @@ static bool linuxraw_bind_button_pressed(void *data, int key)
|
||||
input_sdl.key_pressed(linuxraw->sdl, key);
|
||||
}
|
||||
|
||||
static void conv_analog_id_to_bind_id(unsigned index, unsigned id,
|
||||
unsigned *id_minus, unsigned *id_plus)
|
||||
{
|
||||
switch ((index << 1) | id)
|
||||
{
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_LEFT << 1) | RETRO_DEVICE_ID_ANALOG_X:
|
||||
*id_minus = RARCH_ANALOG_LEFT_X_MINUS;
|
||||
*id_plus = RARCH_ANALOG_LEFT_X_PLUS;
|
||||
break;
|
||||
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_LEFT << 1) | RETRO_DEVICE_ID_ANALOG_Y:
|
||||
*id_minus = RARCH_ANALOG_LEFT_Y_MINUS;
|
||||
*id_plus = RARCH_ANALOG_LEFT_Y_PLUS;
|
||||
break;
|
||||
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_RIGHT << 1) | RETRO_DEVICE_ID_ANALOG_X:
|
||||
*id_minus = RARCH_ANALOG_RIGHT_X_MINUS;
|
||||
*id_plus = RARCH_ANALOG_RIGHT_X_PLUS;
|
||||
break;
|
||||
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_RIGHT << 1) | RETRO_DEVICE_ID_ANALOG_Y:
|
||||
*id_minus = RARCH_ANALOG_RIGHT_Y_MINUS;
|
||||
*id_plus = RARCH_ANALOG_RIGHT_Y_PLUS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int16_t raw_analog_state(linuxraw_input_t *linuxraw, const struct retro_keybind **binds_,
|
||||
unsigned port, unsigned index, unsigned id)
|
||||
{
|
||||
@ -293,7 +267,7 @@ static int16_t raw_analog_state(linuxraw_input_t *linuxraw, const struct retro_k
|
||||
unsigned id_minus = 0;
|
||||
unsigned id_plus = 0;
|
||||
|
||||
conv_analog_id_to_bind_id(index, id, &id_minus, &id_plus);
|
||||
input_conv_analog_id_to_bind_id(index, id, &id_minus, &id_plus);
|
||||
|
||||
const struct retro_keybind *bind_minus = &binds[id_minus];
|
||||
const struct retro_keybind *bind_plus = &binds[id_plus];
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "../libretro.h"
|
||||
#include "rarch_sdl_input.h"
|
||||
#include "input_common.h"
|
||||
|
||||
struct key_bind
|
||||
{
|
||||
@ -309,33 +310,6 @@ static int16_t sdl_joypad_device_state(sdl_input_t *sdl, const struct retro_keyb
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void conv_analog_id_to_bind_id(unsigned index, unsigned id,
|
||||
unsigned *id_minus, unsigned *id_plus)
|
||||
{
|
||||
switch ((index << 1) | id)
|
||||
{
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_LEFT << 1) | RETRO_DEVICE_ID_ANALOG_X:
|
||||
*id_minus = RARCH_ANALOG_LEFT_X_MINUS;
|
||||
*id_plus = RARCH_ANALOG_LEFT_X_PLUS;
|
||||
break;
|
||||
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_LEFT << 1) | RETRO_DEVICE_ID_ANALOG_Y:
|
||||
*id_minus = RARCH_ANALOG_LEFT_Y_MINUS;
|
||||
*id_plus = RARCH_ANALOG_LEFT_Y_PLUS;
|
||||
break;
|
||||
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_RIGHT << 1) | RETRO_DEVICE_ID_ANALOG_X:
|
||||
*id_minus = RARCH_ANALOG_RIGHT_X_MINUS;
|
||||
*id_plus = RARCH_ANALOG_RIGHT_X_PLUS;
|
||||
break;
|
||||
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_RIGHT << 1) | RETRO_DEVICE_ID_ANALOG_Y:
|
||||
*id_minus = RARCH_ANALOG_RIGHT_Y_MINUS;
|
||||
*id_plus = RARCH_ANALOG_RIGHT_Y_PLUS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int16_t sdl_analog_device_state(sdl_input_t *sdl, const struct retro_keybind **binds_,
|
||||
unsigned port_num, unsigned index, unsigned id)
|
||||
{
|
||||
@ -345,7 +319,7 @@ static int16_t sdl_analog_device_state(sdl_input_t *sdl, const struct retro_keyb
|
||||
|
||||
unsigned id_minus = 0;
|
||||
unsigned id_plus = 0;
|
||||
conv_analog_id_to_bind_id(index, id, &id_minus, &id_plus);
|
||||
input_conv_analog_id_to_bind_id(index, id, &id_minus, &id_plus);
|
||||
|
||||
const struct retro_keybind *bind_minus = &binds[id_minus];
|
||||
const struct retro_keybind *bind_plus = &binds[id_plus];
|
||||
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "x11_input.h"
|
||||
#include "input_common.h"
|
||||
|
||||
struct key_bind
|
||||
{
|
||||
@ -182,33 +183,6 @@ static bool x_bind_button_pressed(void *data, int key)
|
||||
input_sdl.key_pressed(x11->sdl, key);
|
||||
}
|
||||
|
||||
static void conv_analog_id_to_bind_id(unsigned index, unsigned id,
|
||||
unsigned *id_minus, unsigned *id_plus)
|
||||
{
|
||||
switch ((index << 1) | id)
|
||||
{
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_LEFT << 1) | RETRO_DEVICE_ID_ANALOG_X:
|
||||
*id_minus = RARCH_ANALOG_LEFT_X_MINUS;
|
||||
*id_plus = RARCH_ANALOG_LEFT_X_PLUS;
|
||||
break;
|
||||
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_LEFT << 1) | RETRO_DEVICE_ID_ANALOG_Y:
|
||||
*id_minus = RARCH_ANALOG_LEFT_Y_MINUS;
|
||||
*id_plus = RARCH_ANALOG_LEFT_Y_PLUS;
|
||||
break;
|
||||
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_RIGHT << 1) | RETRO_DEVICE_ID_ANALOG_X:
|
||||
*id_minus = RARCH_ANALOG_RIGHT_X_MINUS;
|
||||
*id_plus = RARCH_ANALOG_RIGHT_X_PLUS;
|
||||
break;
|
||||
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_RIGHT << 1) | RETRO_DEVICE_ID_ANALOG_Y:
|
||||
*id_minus = RARCH_ANALOG_RIGHT_Y_MINUS;
|
||||
*id_plus = RARCH_ANALOG_RIGHT_Y_PLUS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int16_t x_analog_state(x11_input_t *x11, const struct retro_keybind **binds_,
|
||||
unsigned port, unsigned index, unsigned id)
|
||||
{
|
||||
@ -219,7 +193,7 @@ static int16_t x_analog_state(x11_input_t *x11, const struct retro_keybind **bin
|
||||
unsigned id_minus = 0;
|
||||
unsigned id_plus = 0;
|
||||
|
||||
conv_analog_id_to_bind_id(index, id, &id_minus, &id_plus);
|
||||
input_conv_analog_id_to_bind_id(index, id, &id_minus, &id_plus);
|
||||
|
||||
const struct retro_keybind *bind_minus = &binds[id_minus];
|
||||
const struct retro_keybind *bind_plus = &binds[id_plus];
|
||||
|
Loading…
x
Reference in New Issue
Block a user