mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-28 02:30:35 +00:00
Merged input_joypad.c and input_joypad_driver.c
This commit is contained in:
parent
1df5d44bdb
commit
c23846c5dc
@ -161,7 +161,6 @@ OBJ += frontend/frontend.o \
|
||||
gfx/drivers_font_renderer/bitmapfont.o \
|
||||
input/input_autodetect.o \
|
||||
input/input_joypad_driver.o \
|
||||
input/input_joypad.o \
|
||||
input/input_config.o \
|
||||
input/input_keymaps.o \
|
||||
input/input_remapping.o \
|
||||
|
@ -309,7 +309,6 @@ INPUT
|
||||
============================================================ */
|
||||
#include "../input/input_autodetect.c"
|
||||
#include "../input/input_joypad_driver.c"
|
||||
#include "../input/input_joypad.c"
|
||||
#include "../input/input_hid_driver.c"
|
||||
#include "../input/input_config.c"
|
||||
#include "../input/input_keymaps.c"
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include "../../frontend/drivers/platform_linux.h"
|
||||
#include "../input_autodetect.h"
|
||||
#include "../input_config.h"
|
||||
#include "../input_joypad.h"
|
||||
#include "../input_joypad_driver.h"
|
||||
#include "../../performance.h"
|
||||
#include "../../general.h"
|
||||
#include "../../driver.h"
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../input_config.h"
|
||||
#include "../input_joypad.h"
|
||||
#include "../input_joypad_driver.h"
|
||||
#include "../input_keymaps.h"
|
||||
#include "cocoa_input.h"
|
||||
#include "../../general.h"
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "../../libretro.h"
|
||||
#include "../../general.h"
|
||||
#include "../input_config.h"
|
||||
#include "../input_joypad.h"
|
||||
#include "../input_joypad_driver.h"
|
||||
|
||||
#define MAX_PADS 1
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
||||
#include "../../verbosity.h"
|
||||
#include "../input_autodetect.h"
|
||||
#include "../input_config.h"
|
||||
#include "../input_joypad.h"
|
||||
#include "../input_joypad_driver.h"
|
||||
#include "../input_keymaps.h"
|
||||
|
||||
/* Keep track of which pad indexes are 360 controllers.
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
#include "../common/linux_common.h"
|
||||
#include "../input_keymaps.h"
|
||||
#include "../input_joypad.h"
|
||||
#include "../input_joypad_driver.h"
|
||||
|
||||
typedef struct linuxraw_input
|
||||
{
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <boolean.h>
|
||||
|
||||
#include "../input_joypad.h"
|
||||
#include "../input_joypad_driver.h"
|
||||
#include "../input_autodetect.h"
|
||||
#include "../input_keyboard.h"
|
||||
#include "../input_config.h"
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "../../libretro.h"
|
||||
#include "../input_autodetect.h"
|
||||
#include "../input_config.h"
|
||||
#include "../input_joypad.h"
|
||||
#include "../input_joypad_driver.h"
|
||||
#include "../input_keymaps.h"
|
||||
#include "../input_keyboard.h"
|
||||
|
||||
|
@ -37,7 +37,7 @@
|
||||
#include "../common/linux_common.h"
|
||||
|
||||
#include "../input_config.h"
|
||||
#include "../input_joypad.h"
|
||||
#include "../input_joypad_driver.h"
|
||||
#include "../input_keymaps.h"
|
||||
#include "../../general.h"
|
||||
#include "../../verbosity.h"
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <boolean.h>
|
||||
|
||||
#include "../input_config.h"
|
||||
#include "../input_joypad.h"
|
||||
#include "../input_joypad_driver.h"
|
||||
#include "../input_keymaps.h"
|
||||
|
||||
#include "../../driver.h"
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include "../../verbosity.h"
|
||||
#include "../input_autodetect.h"
|
||||
#include "../input_config.h"
|
||||
#include "../input_joypad.h"
|
||||
#include "../input_joypad_driver.h"
|
||||
#include "../input_keymaps.h"
|
||||
|
||||
struct dinput_joypad
|
||||
|
@ -1,247 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2015 - Daniel De Matteis
|
||||
*
|
||||
* 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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "input_joypad.h"
|
||||
|
||||
#include "../general.h"
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "../config.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* input_joypad_name:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : Joystick number.
|
||||
*
|
||||
* Gets name of the joystick (@port).
|
||||
*
|
||||
* Returns: name of joystick #port.
|
||||
**/
|
||||
const char *input_joypad_name(const input_device_driver_t *drv,
|
||||
unsigned port)
|
||||
{
|
||||
if (!drv)
|
||||
return NULL;
|
||||
return drv->name(port);
|
||||
}
|
||||
|
||||
/**
|
||||
* input_joypad_set_rumble:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : User number.
|
||||
* @effect : Rumble effect to set.
|
||||
* @strength : Strength of rumble effect.
|
||||
*
|
||||
* Sets rumble effect @effect with strength @strength.
|
||||
*
|
||||
* Returns: true (1) if successful, otherwise false (0).
|
||||
**/
|
||||
bool input_joypad_set_rumble(const input_device_driver_t *drv,
|
||||
unsigned port, enum retro_rumble_effect effect, uint16_t strength)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
unsigned joy_idx = settings->input.joypad_map[port];
|
||||
|
||||
if (!drv || !drv->set_rumble)
|
||||
return false;
|
||||
|
||||
if (joy_idx >= MAX_USERS)
|
||||
return false;
|
||||
|
||||
return drv->set_rumble(joy_idx, effect, strength);
|
||||
}
|
||||
|
||||
/**
|
||||
* input_joypad_is_pressed:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : User number.
|
||||
* @binds : Binds of user.
|
||||
* @key : Identifier of key.
|
||||
*
|
||||
* Checks if key (@key) was being pressed by user
|
||||
* with number @port with provided keybinds (@binds).
|
||||
*
|
||||
* Returns: true (1) if key was pressed, otherwise
|
||||
* false (0).
|
||||
**/
|
||||
bool input_joypad_pressed(
|
||||
const input_device_driver_t *drv,
|
||||
unsigned port,
|
||||
const struct retro_keybind *binds,
|
||||
unsigned key)
|
||||
{
|
||||
float scaled_axis;
|
||||
int16_t axis;
|
||||
uint32_t joyaxis;
|
||||
uint64_t joykey;
|
||||
const struct retro_keybind *auto_binds = NULL;
|
||||
settings_t *settings = config_get_ptr();
|
||||
unsigned joy_idx = settings->input.joypad_map[port];
|
||||
|
||||
if (joy_idx >= MAX_USERS)
|
||||
return false;
|
||||
if (!drv || !binds[key].valid)
|
||||
return false;
|
||||
|
||||
/* Auto-binds are per joypad, not per user. */
|
||||
auto_binds = settings->input.autoconf_binds[joy_idx];
|
||||
|
||||
joykey = binds[key].joykey;
|
||||
if (joykey == NO_BTN)
|
||||
joykey = auto_binds[key].joykey;
|
||||
|
||||
if (drv->button(joy_idx, (uint16_t)joykey))
|
||||
return true;
|
||||
|
||||
joyaxis = binds[key].joyaxis;
|
||||
if (joyaxis == AXIS_NONE)
|
||||
joyaxis = auto_binds[key].joyaxis;
|
||||
|
||||
axis = drv->axis(joy_idx, joyaxis);
|
||||
scaled_axis = (float)abs(axis) / 0x8000;
|
||||
return scaled_axis > settings->input.axis_threshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* input_joypad_analog:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : User number.
|
||||
* @idx : Analog key index.
|
||||
* E.g.:
|
||||
* - RETRO_DEVICE_INDEX_ANALOG_LEFT
|
||||
* - RETRO_DEVICE_INDEX_ANALOG_RIGHT
|
||||
* @ident : Analog key identifier.
|
||||
* E.g.:
|
||||
* - RETRO_DEVICE_ID_ANALOG_X
|
||||
* - RETRO_DEVICE_ID_ANALOG_Y
|
||||
* @binds : Binds of user.
|
||||
*
|
||||
* Gets analog value of analog key identifiers @idx and @ident
|
||||
* from user with number @port with provided keybinds (@binds).
|
||||
*
|
||||
* Returns: analog value on success, otherwise 0.
|
||||
**/
|
||||
int16_t input_joypad_analog(const input_device_driver_t *drv,
|
||||
unsigned port, unsigned idx, unsigned ident,
|
||||
const struct retro_keybind *binds)
|
||||
{
|
||||
uint32_t axis_minus, axis_plus;
|
||||
uint64_t key_minus, key_plus;
|
||||
int16_t pressed_minus, pressed_plus, res;
|
||||
unsigned ident_minus = 0, ident_plus = 0;
|
||||
int16_t digital_left = 0, digital_right = 0;
|
||||
const struct retro_keybind *auto_binds = NULL;
|
||||
const struct retro_keybind *bind_minus = NULL;
|
||||
const struct retro_keybind *bind_plus = NULL;
|
||||
settings_t *settings = config_get_ptr();
|
||||
unsigned joy_idx = settings->input.joypad_map[port];
|
||||
|
||||
if (!drv)
|
||||
return 0;
|
||||
|
||||
if (joy_idx >= MAX_USERS)
|
||||
return 0;
|
||||
|
||||
/* Auto-binds are per joypad, not per user. */
|
||||
auto_binds = settings->input.autoconf_binds[joy_idx];
|
||||
|
||||
input_conv_analog_id_to_bind_id(idx, ident, &ident_minus, &ident_plus);
|
||||
|
||||
bind_minus = &binds[ident_minus];
|
||||
bind_plus = &binds[ident_plus];
|
||||
if (!bind_minus->valid || !bind_plus->valid)
|
||||
return 0;
|
||||
|
||||
axis_minus = bind_minus->joyaxis;
|
||||
axis_plus = bind_plus->joyaxis;
|
||||
if (axis_minus == AXIS_NONE)
|
||||
axis_minus = auto_binds[ident_minus].joyaxis;
|
||||
if (axis_plus == AXIS_NONE)
|
||||
axis_plus = auto_binds[ident_plus].joyaxis;
|
||||
|
||||
pressed_minus = abs(drv->axis(joy_idx, axis_minus));
|
||||
pressed_plus = abs(drv->axis(joy_idx, axis_plus));
|
||||
res = pressed_plus - pressed_minus;
|
||||
|
||||
if (res != 0)
|
||||
return res;
|
||||
|
||||
key_minus = bind_minus->joykey;
|
||||
key_plus = bind_plus->joykey;
|
||||
if (key_minus == NO_BTN)
|
||||
key_minus = auto_binds[ident_minus].joykey;
|
||||
if (key_plus == NO_BTN)
|
||||
key_plus = auto_binds[ident_plus].joykey;
|
||||
|
||||
if (drv->button(joy_idx, (uint16_t)key_minus))
|
||||
digital_left = -0x7fff;
|
||||
if (drv->button(joy_idx, (uint16_t)key_plus))
|
||||
digital_right = 0x7fff;
|
||||
return digital_right + digital_left;
|
||||
}
|
||||
|
||||
/**
|
||||
* input_joypad_axis_raw:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : Joystick number.
|
||||
* @axis : Identifier of axis.
|
||||
*
|
||||
* Checks if axis (@axis) was being pressed by user
|
||||
* with joystick number @port.
|
||||
*
|
||||
* Returns: true (1) if axis was pressed, otherwise
|
||||
* false (0).
|
||||
**/
|
||||
int16_t input_joypad_axis_raw(const input_device_driver_t *drv,
|
||||
unsigned port, unsigned axis)
|
||||
{
|
||||
if (!drv)
|
||||
return 0;
|
||||
return drv->axis(port, AXIS_POS(axis)) +
|
||||
drv->axis(port, AXIS_NEG(axis));
|
||||
}
|
||||
|
||||
/**
|
||||
* input_joypad_button_raw:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : Joystick number.
|
||||
* @button : Identifier of key.
|
||||
*
|
||||
* Checks if key (@button) was being pressed by user
|
||||
* with joystick number @port.
|
||||
*
|
||||
* Returns: true (1) if key was pressed, otherwise
|
||||
* false (0).
|
||||
**/
|
||||
bool input_joypad_button_raw(const input_device_driver_t *drv,
|
||||
unsigned port, unsigned button)
|
||||
{
|
||||
if (!drv)
|
||||
return false;
|
||||
return drv->button(port, button);
|
||||
}
|
||||
|
||||
bool input_joypad_hat_raw(const input_device_driver_t *drv,
|
||||
unsigned port, unsigned hat_dir, unsigned hat)
|
||||
{
|
||||
if (!drv)
|
||||
return false;
|
||||
return drv->button(port, HAT_MAP(hat, hat_dir));
|
||||
}
|
@ -1,174 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2015 - Daniel De Matteis
|
||||
*
|
||||
* 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_JOYPAD_H__
|
||||
#define INPUT_JOYPAD_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "../driver.h"
|
||||
#include <retro_inline.h>
|
||||
|
||||
/**
|
||||
* input_conv_analog_id_to_bind_id:
|
||||
* @idx : Analog key index.
|
||||
* E.g.:
|
||||
* - RETRO_DEVICE_INDEX_ANALOG_LEFT
|
||||
* - RETRO_DEVICE_INDEX_ANALOG_RIGHT
|
||||
* @ident : Analog key identifier.
|
||||
* E.g.:
|
||||
* - RETRO_DEVICE_ID_ANALOG_X
|
||||
* - RETRO_DEVICE_ID_ANALOG_Y
|
||||
* @ident_minus : Bind ID minus, will be set by function.
|
||||
* @ident_plus : Bind ID plus, will be set by function.
|
||||
*
|
||||
* Takes as input analog key identifiers and converts
|
||||
* them to corresponding bind IDs @ident_minus and @ident_plus.
|
||||
**/
|
||||
static INLINE void input_conv_analog_id_to_bind_id(unsigned idx, unsigned ident,
|
||||
unsigned *ident_minus, unsigned *ident_plus)
|
||||
{
|
||||
switch ((idx << 1) | ident)
|
||||
{
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_LEFT << 1) | RETRO_DEVICE_ID_ANALOG_X:
|
||||
*ident_minus = RARCH_ANALOG_LEFT_X_MINUS;
|
||||
*ident_plus = RARCH_ANALOG_LEFT_X_PLUS;
|
||||
break;
|
||||
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_LEFT << 1) | RETRO_DEVICE_ID_ANALOG_Y:
|
||||
*ident_minus = RARCH_ANALOG_LEFT_Y_MINUS;
|
||||
*ident_plus = RARCH_ANALOG_LEFT_Y_PLUS;
|
||||
break;
|
||||
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_RIGHT << 1) | RETRO_DEVICE_ID_ANALOG_X:
|
||||
*ident_minus = RARCH_ANALOG_RIGHT_X_MINUS;
|
||||
*ident_plus = RARCH_ANALOG_RIGHT_X_PLUS;
|
||||
break;
|
||||
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_RIGHT << 1) | RETRO_DEVICE_ID_ANALOG_Y:
|
||||
*ident_minus = RARCH_ANALOG_RIGHT_Y_MINUS;
|
||||
*ident_plus = RARCH_ANALOG_RIGHT_Y_PLUS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* input_joypad_pressed:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : User number.
|
||||
* @binds : Binds of user.
|
||||
* @key : Identifier of key.
|
||||
*
|
||||
* Checks if key (@key) was being pressed by user
|
||||
* with number @port with provided keybinds (@binds).
|
||||
*
|
||||
* Returns: true (1) if key was pressed, otherwise
|
||||
* false (0).
|
||||
**/
|
||||
bool input_joypad_pressed(const input_device_driver_t *driver,
|
||||
unsigned port, const struct retro_keybind *binds, unsigned key);
|
||||
|
||||
/**
|
||||
* input_joypad_analog:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : User number.
|
||||
* @idx : Analog key index.
|
||||
* E.g.:
|
||||
* - RETRO_DEVICE_INDEX_ANALOG_LEFT
|
||||
* - RETRO_DEVICE_INDEX_ANALOG_RIGHT
|
||||
* @ident : Analog key identifier.
|
||||
* E.g.:
|
||||
* - RETRO_DEVICE_ID_ANALOG_X
|
||||
* - RETRO_DEVICE_ID_ANALOG_Y
|
||||
* @binds : Binds of user.
|
||||
*
|
||||
* Gets analog value of analog key identifiers @idx and @ident
|
||||
* from user with number @port with provided keybinds (@binds).
|
||||
*
|
||||
* Returns: analog value on success, otherwise 0.
|
||||
**/
|
||||
int16_t input_joypad_analog(const input_device_driver_t *driver,
|
||||
unsigned port, unsigned idx, unsigned ident,
|
||||
const struct retro_keybind *binds);
|
||||
|
||||
/**
|
||||
* input_joypad_set_rumble:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : User number.
|
||||
* @effect : Rumble effect to set.
|
||||
* @strength : Strength of rumble effect.
|
||||
*
|
||||
* Sets rumble effect @effect with strength @strength.
|
||||
*
|
||||
* Returns: true (1) if successful, otherwise false (0).
|
||||
**/
|
||||
bool input_joypad_set_rumble(const input_device_driver_t *driver,
|
||||
unsigned port, enum retro_rumble_effect effect, uint16_t strength);
|
||||
|
||||
/**
|
||||
* input_joypad_axis_raw:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : Joystick number.
|
||||
* @axis : Identifier of axis.
|
||||
*
|
||||
* Checks if axis (@axis) was being pressed by user
|
||||
* with joystick number @port.
|
||||
*
|
||||
* Returns: true (1) if axis was pressed, otherwise
|
||||
* false (0).
|
||||
**/
|
||||
int16_t input_joypad_axis_raw(const input_device_driver_t *driver,
|
||||
unsigned port, unsigned axis);
|
||||
|
||||
/**
|
||||
* input_joypad_button_raw:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : Joystick number.
|
||||
* @button : Identifier of key.
|
||||
*
|
||||
* Checks if key (@button) was being pressed by user
|
||||
* with joystick number @port.
|
||||
*
|
||||
* Returns: true (1) if key was pressed, otherwise
|
||||
* false (0).
|
||||
**/
|
||||
bool input_joypad_button_raw(const input_device_driver_t *driver,
|
||||
unsigned port, unsigned button);
|
||||
|
||||
bool input_joypad_hat_raw(const input_device_driver_t *driver,
|
||||
unsigned joypad, unsigned hat_dir, unsigned hat);
|
||||
|
||||
/**
|
||||
* input_joypad_name:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : Joystick number.
|
||||
*
|
||||
* Gets name of the joystick (@port).
|
||||
*
|
||||
* Returns: name of joystick #port.
|
||||
**/
|
||||
const char *input_joypad_name(const input_device_driver_t *driver,
|
||||
unsigned port);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -167,3 +167,271 @@ const input_device_driver_t *input_joypad_init_first(void *data)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* input_joypad_name:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : Joystick number.
|
||||
*
|
||||
* Gets name of the joystick (@port).
|
||||
*
|
||||
* Returns: name of joystick #port.
|
||||
**/
|
||||
const char *input_joypad_name(const input_device_driver_t *drv,
|
||||
unsigned port)
|
||||
{
|
||||
if (!drv)
|
||||
return NULL;
|
||||
return drv->name(port);
|
||||
}
|
||||
|
||||
/**
|
||||
* input_joypad_set_rumble:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : User number.
|
||||
* @effect : Rumble effect to set.
|
||||
* @strength : Strength of rumble effect.
|
||||
*
|
||||
* Sets rumble effect @effect with strength @strength.
|
||||
*
|
||||
* Returns: true (1) if successful, otherwise false (0).
|
||||
**/
|
||||
bool input_joypad_set_rumble(const input_device_driver_t *drv,
|
||||
unsigned port, enum retro_rumble_effect effect, uint16_t strength)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
unsigned joy_idx = settings->input.joypad_map[port];
|
||||
|
||||
if (!drv || !drv->set_rumble)
|
||||
return false;
|
||||
|
||||
if (joy_idx >= MAX_USERS)
|
||||
return false;
|
||||
|
||||
return drv->set_rumble(joy_idx, effect, strength);
|
||||
}
|
||||
|
||||
/**
|
||||
* input_joypad_is_pressed:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : User number.
|
||||
* @binds : Binds of user.
|
||||
* @key : Identifier of key.
|
||||
*
|
||||
* Checks if key (@key) was being pressed by user
|
||||
* with number @port with provided keybinds (@binds).
|
||||
*
|
||||
* Returns: true (1) if key was pressed, otherwise
|
||||
* false (0).
|
||||
**/
|
||||
bool input_joypad_pressed(
|
||||
const input_device_driver_t *drv,
|
||||
unsigned port,
|
||||
const void *binds_data,
|
||||
unsigned key)
|
||||
{
|
||||
float scaled_axis;
|
||||
int16_t axis;
|
||||
uint32_t joyaxis;
|
||||
uint64_t joykey;
|
||||
const struct retro_keybind *auto_binds = NULL;
|
||||
const struct retro_keybind *binds = (const struct retro_keybind*)
|
||||
binds_data;
|
||||
settings_t *settings = config_get_ptr();
|
||||
unsigned joy_idx = settings->input.joypad_map[port];
|
||||
|
||||
if (joy_idx >= MAX_USERS)
|
||||
return false;
|
||||
if (!drv || !binds[key].valid)
|
||||
return false;
|
||||
|
||||
/* Auto-binds are per joypad, not per user. */
|
||||
auto_binds = settings->input.autoconf_binds[joy_idx];
|
||||
|
||||
joykey = binds[key].joykey;
|
||||
if (joykey == NO_BTN)
|
||||
joykey = auto_binds[key].joykey;
|
||||
|
||||
if (drv->button(joy_idx, (uint16_t)joykey))
|
||||
return true;
|
||||
|
||||
joyaxis = binds[key].joyaxis;
|
||||
if (joyaxis == AXIS_NONE)
|
||||
joyaxis = auto_binds[key].joyaxis;
|
||||
|
||||
axis = drv->axis(joy_idx, joyaxis);
|
||||
scaled_axis = (float)abs(axis) / 0x8000;
|
||||
return scaled_axis > settings->input.axis_threshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* input_joypad_analog:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : User number.
|
||||
* @idx : Analog key index.
|
||||
* E.g.:
|
||||
* - RETRO_DEVICE_INDEX_ANALOG_LEFT
|
||||
* - RETRO_DEVICE_INDEX_ANALOG_RIGHT
|
||||
* @ident : Analog key identifier.
|
||||
* E.g.:
|
||||
* - RETRO_DEVICE_ID_ANALOG_X
|
||||
* - RETRO_DEVICE_ID_ANALOG_Y
|
||||
* @binds : Binds of user.
|
||||
*
|
||||
* Gets analog value of analog key identifiers @idx and @ident
|
||||
* from user with number @port with provided keybinds (@binds).
|
||||
*
|
||||
* Returns: analog value on success, otherwise 0.
|
||||
**/
|
||||
int16_t input_joypad_analog(const input_device_driver_t *drv,
|
||||
unsigned port, unsigned idx, unsigned ident,
|
||||
const void *binds_data)
|
||||
{
|
||||
uint32_t axis_minus, axis_plus;
|
||||
uint64_t key_minus, key_plus;
|
||||
int16_t pressed_minus, pressed_plus, res;
|
||||
unsigned ident_minus = 0, ident_plus = 0;
|
||||
int16_t digital_left = 0, digital_right = 0;
|
||||
const struct retro_keybind *auto_binds = NULL;
|
||||
const struct retro_keybind *bind_minus = NULL;
|
||||
const struct retro_keybind *bind_plus = NULL;
|
||||
const struct retro_keybind *binds = (const struct retro_keybind*)
|
||||
binds_data;
|
||||
settings_t *settings = config_get_ptr();
|
||||
unsigned joy_idx = settings->input.joypad_map[port];
|
||||
|
||||
if (!drv)
|
||||
return 0;
|
||||
|
||||
if (joy_idx >= MAX_USERS)
|
||||
return 0;
|
||||
|
||||
/* Auto-binds are per joypad, not per user. */
|
||||
auto_binds = settings->input.autoconf_binds[joy_idx];
|
||||
|
||||
input_conv_analog_id_to_bind_id(idx, ident, &ident_minus, &ident_plus);
|
||||
|
||||
bind_minus = &binds[ident_minus];
|
||||
bind_plus = &binds[ident_plus];
|
||||
if (!bind_minus->valid || !bind_plus->valid)
|
||||
return 0;
|
||||
|
||||
axis_minus = bind_minus->joyaxis;
|
||||
axis_plus = bind_plus->joyaxis;
|
||||
if (axis_minus == AXIS_NONE)
|
||||
axis_minus = auto_binds[ident_minus].joyaxis;
|
||||
if (axis_plus == AXIS_NONE)
|
||||
axis_plus = auto_binds[ident_plus].joyaxis;
|
||||
|
||||
pressed_minus = abs(drv->axis(joy_idx, axis_minus));
|
||||
pressed_plus = abs(drv->axis(joy_idx, axis_plus));
|
||||
res = pressed_plus - pressed_minus;
|
||||
|
||||
if (res != 0)
|
||||
return res;
|
||||
|
||||
key_minus = bind_minus->joykey;
|
||||
key_plus = bind_plus->joykey;
|
||||
if (key_minus == NO_BTN)
|
||||
key_minus = auto_binds[ident_minus].joykey;
|
||||
if (key_plus == NO_BTN)
|
||||
key_plus = auto_binds[ident_plus].joykey;
|
||||
|
||||
if (drv->button(joy_idx, (uint16_t)key_minus))
|
||||
digital_left = -0x7fff;
|
||||
if (drv->button(joy_idx, (uint16_t)key_plus))
|
||||
digital_right = 0x7fff;
|
||||
return digital_right + digital_left;
|
||||
}
|
||||
|
||||
/**
|
||||
* input_joypad_axis_raw:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : Joystick number.
|
||||
* @axis : Identifier of axis.
|
||||
*
|
||||
* Checks if axis (@axis) was being pressed by user
|
||||
* with joystick number @port.
|
||||
*
|
||||
* Returns: true (1) if axis was pressed, otherwise
|
||||
* false (0).
|
||||
**/
|
||||
int16_t input_joypad_axis_raw(const input_device_driver_t *drv,
|
||||
unsigned port, unsigned axis)
|
||||
{
|
||||
if (!drv)
|
||||
return 0;
|
||||
return drv->axis(port, AXIS_POS(axis)) +
|
||||
drv->axis(port, AXIS_NEG(axis));
|
||||
}
|
||||
|
||||
/**
|
||||
* input_joypad_button_raw:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : Joystick number.
|
||||
* @button : Identifier of key.
|
||||
*
|
||||
* Checks if key (@button) was being pressed by user
|
||||
* with joystick number @port.
|
||||
*
|
||||
* Returns: true (1) if key was pressed, otherwise
|
||||
* false (0).
|
||||
**/
|
||||
bool input_joypad_button_raw(const input_device_driver_t *drv,
|
||||
unsigned port, unsigned button)
|
||||
{
|
||||
if (!drv)
|
||||
return false;
|
||||
return drv->button(port, button);
|
||||
}
|
||||
|
||||
bool input_joypad_hat_raw(const input_device_driver_t *drv,
|
||||
unsigned port, unsigned hat_dir, unsigned hat)
|
||||
{
|
||||
if (!drv)
|
||||
return false;
|
||||
return drv->button(port, HAT_MAP(hat, hat_dir));
|
||||
}
|
||||
|
||||
/**
|
||||
* input_conv_analog_id_to_bind_id:
|
||||
* @idx : Analog key index.
|
||||
* E.g.:
|
||||
* - RETRO_DEVICE_INDEX_ANALOG_LEFT
|
||||
* - RETRO_DEVICE_INDEX_ANALOG_RIGHT
|
||||
* @ident : Analog key identifier.
|
||||
* E.g.:
|
||||
* - RETRO_DEVICE_ID_ANALOG_X
|
||||
* - RETRO_DEVICE_ID_ANALOG_Y
|
||||
* @ident_minus : Bind ID minus, will be set by function.
|
||||
* @ident_plus : Bind ID plus, will be set by function.
|
||||
*
|
||||
* Takes as input analog key identifiers and converts
|
||||
* them to corresponding bind IDs @ident_minus and @ident_plus.
|
||||
**/
|
||||
void input_conv_analog_id_to_bind_id(unsigned idx, unsigned ident,
|
||||
unsigned *ident_minus, unsigned *ident_plus)
|
||||
{
|
||||
switch ((idx << 1) | ident)
|
||||
{
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_LEFT << 1) | RETRO_DEVICE_ID_ANALOG_X:
|
||||
*ident_minus = RARCH_ANALOG_LEFT_X_MINUS;
|
||||
*ident_plus = RARCH_ANALOG_LEFT_X_PLUS;
|
||||
break;
|
||||
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_LEFT << 1) | RETRO_DEVICE_ID_ANALOG_Y:
|
||||
*ident_minus = RARCH_ANALOG_LEFT_Y_MINUS;
|
||||
*ident_plus = RARCH_ANALOG_LEFT_Y_PLUS;
|
||||
break;
|
||||
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_RIGHT << 1) | RETRO_DEVICE_ID_ANALOG_X:
|
||||
*ident_minus = RARCH_ANALOG_RIGHT_X_MINUS;
|
||||
*ident_plus = RARCH_ANALOG_RIGHT_X_PLUS;
|
||||
break;
|
||||
|
||||
case (RETRO_DEVICE_INDEX_ANALOG_RIGHT << 1) | RETRO_DEVICE_ID_ANALOG_Y:
|
||||
*ident_minus = RARCH_ANALOG_RIGHT_Y_MINUS;
|
||||
*ident_plus = RARCH_ANALOG_RIGHT_Y_PLUS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ extern "C" {
|
||||
|
||||
#include <stdint.h>
|
||||
#include <boolean.h>
|
||||
|
||||
#include "../libretro.h"
|
||||
|
||||
typedef struct rarch_joypad_driver input_device_driver_t;
|
||||
@ -108,6 +109,123 @@ const input_device_driver_t *input_joypad_init_driver(const char *ident, void *d
|
||||
**/
|
||||
const input_device_driver_t *input_joypad_init_first(void *data);
|
||||
|
||||
/**
|
||||
* input_conv_analog_id_to_bind_id:
|
||||
* @idx : Analog key index.
|
||||
* E.g.:
|
||||
* - RETRO_DEVICE_INDEX_ANALOG_LEFT
|
||||
* - RETRO_DEVICE_INDEX_ANALOG_RIGHT
|
||||
* @ident : Analog key identifier.
|
||||
* E.g.:
|
||||
* - RETRO_DEVICE_ID_ANALOG_X
|
||||
* - RETRO_DEVICE_ID_ANALOG_Y
|
||||
* @ident_minus : Bind ID minus, will be set by function.
|
||||
* @ident_plus : Bind ID plus, will be set by function.
|
||||
*
|
||||
* Takes as input analog key identifiers and converts
|
||||
* them to corresponding bind IDs @ident_minus and @ident_plus.
|
||||
**/
|
||||
void input_conv_analog_id_to_bind_id(unsigned idx, unsigned ident,
|
||||
unsigned *ident_minus, unsigned *ident_plus);
|
||||
|
||||
/**
|
||||
* input_joypad_pressed:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : User number.
|
||||
* @binds : Binds of user.
|
||||
* @key : Identifier of key.
|
||||
*
|
||||
* Checks if key (@key) was being pressed by user
|
||||
* with number @port with provided keybinds (@binds).
|
||||
*
|
||||
* Returns: true (1) if key was pressed, otherwise
|
||||
* false (0).
|
||||
**/
|
||||
bool input_joypad_pressed(const input_device_driver_t *driver,
|
||||
unsigned port, const void *binds, unsigned key);
|
||||
|
||||
/**
|
||||
* input_joypad_analog:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : User number.
|
||||
* @idx : Analog key index.
|
||||
* E.g.:
|
||||
* - RETRO_DEVICE_INDEX_ANALOG_LEFT
|
||||
* - RETRO_DEVICE_INDEX_ANALOG_RIGHT
|
||||
* @ident : Analog key identifier.
|
||||
* E.g.:
|
||||
* - RETRO_DEVICE_ID_ANALOG_X
|
||||
* - RETRO_DEVICE_ID_ANALOG_Y
|
||||
* @binds : Binds of user.
|
||||
*
|
||||
* Gets analog value of analog key identifiers @idx and @ident
|
||||
* from user with number @port with provided keybinds (@binds).
|
||||
*
|
||||
* Returns: analog value on success, otherwise 0.
|
||||
**/
|
||||
int16_t input_joypad_analog(const input_device_driver_t *driver,
|
||||
unsigned port, unsigned idx, unsigned ident,
|
||||
const void *binds);
|
||||
|
||||
/**
|
||||
* input_joypad_set_rumble:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : User number.
|
||||
* @effect : Rumble effect to set.
|
||||
* @strength : Strength of rumble effect.
|
||||
*
|
||||
* Sets rumble effect @effect with strength @strength.
|
||||
*
|
||||
* Returns: true (1) if successful, otherwise false (0).
|
||||
**/
|
||||
bool input_joypad_set_rumble(const input_device_driver_t *driver,
|
||||
unsigned port, enum retro_rumble_effect effect, uint16_t strength);
|
||||
|
||||
/**
|
||||
* input_joypad_axis_raw:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : Joystick number.
|
||||
* @axis : Identifier of axis.
|
||||
*
|
||||
* Checks if axis (@axis) was being pressed by user
|
||||
* with joystick number @port.
|
||||
*
|
||||
* Returns: true (1) if axis was pressed, otherwise
|
||||
* false (0).
|
||||
**/
|
||||
int16_t input_joypad_axis_raw(const input_device_driver_t *driver,
|
||||
unsigned port, unsigned axis);
|
||||
|
||||
/**
|
||||
* input_joypad_button_raw:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : Joystick number.
|
||||
* @button : Identifier of key.
|
||||
*
|
||||
* Checks if key (@button) was being pressed by user
|
||||
* with joystick number @port.
|
||||
*
|
||||
* Returns: true (1) if key was pressed, otherwise
|
||||
* false (0).
|
||||
**/
|
||||
bool input_joypad_button_raw(const input_device_driver_t *driver,
|
||||
unsigned port, unsigned button);
|
||||
|
||||
bool input_joypad_hat_raw(const input_device_driver_t *driver,
|
||||
unsigned joypad, unsigned hat_dir, unsigned hat);
|
||||
|
||||
/**
|
||||
* input_joypad_name:
|
||||
* @drv : Input device driver handle.
|
||||
* @port : Joystick number.
|
||||
*
|
||||
* Gets name of the joystick (@port).
|
||||
*
|
||||
* Returns: name of joystick #port.
|
||||
**/
|
||||
const char *input_joypad_name(const input_device_driver_t *driver,
|
||||
unsigned port);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -36,7 +36,7 @@
|
||||
#include "../general.h"
|
||||
#include "../cheats.h"
|
||||
#include "../performance.h"
|
||||
#include "../input/input_joypad.h"
|
||||
#include "../input/input_joypad_driver.h"
|
||||
#include "../input/input_remapping.h"
|
||||
#include "../input/input_config.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user