RetroArch/input/drivers/gx_input.c

199 lines
5.1 KiB
C
Raw Normal View History

2012-04-21 23:13:50 +02:00
/* RetroArch - A frontend for libretro.
2014-01-01 01:50:59 +01:00
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2017-01-22 13:40:32 +01:00
* Copyright (C) 2011-2017 - Daniel De Matteis
2015-01-07 17:46:50 +01:00
* Copyright (C) 2012-2015 - Michael Lelli
*
2012-04-21 23:13:50 +02:00
* RetroArch is free software: you can redistribute it and/or modify it under the terms
2011-12-14 13:20:22 +01:00
* 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.
*
2012-04-21 23:13:50 +02:00
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
2011-12-14 13:20:22 +01:00
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
2012-04-21 23:31:57 +02:00
* You should have received a copy of the GNU General Public License along with RetroArch.
2011-12-14 13:20:22 +01:00
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <stdlib.h>
2012-01-03 12:11:02 +01:00
#include <string.h>
#include <math.h>
2011-12-14 13:20:22 +01:00
#include <boolean.h>
2015-11-24 00:05:37 +01:00
#include <retro_miscellaneous.h>
#include <libretro.h>
#include "../../config.def.h"
2011-12-14 13:20:22 +01:00
#include "../input_driver.h"
2019-02-03 15:49:35 -08:00
/* TODO/FIXME -
* fix game focus toggle */
typedef struct gx_input
{
bool blocked;
const input_device_driver_t *joypad;
} gx_input_t;
2012-04-11 04:22:41 +02:00
static int16_t gx_input_state(void *data,
rarch_joypad_info_t joypad_info,
const struct retro_keybind **binds,
unsigned port, unsigned device,
2014-10-20 20:31:00 +02:00
unsigned idx, unsigned id)
2011-12-14 13:20:22 +01:00
{
2017-01-10 03:44:53 +01:00
gx_input_t *gx = (gx_input_t*)data;
int16_t ret = 0;
2017-01-10 03:44:53 +01:00
if (port >= DEFAULT_MAX_PADS || !gx)
return 0;
2011-12-14 13:20:22 +01:00
2013-07-04 14:52:53 -04:00
switch (device)
{
case RETRO_DEVICE_JOYPAD:
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
{
unsigned i;
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
{
/* Auto-binds are per joypad, not per user. */
const uint64_t joykey = (binds[port][i].joykey != NO_BTN)
? binds[port][i].joykey : joypad_info.auto_binds[i].joykey;
const uint32_t joyaxis = (binds[port][i].joyaxis != AXIS_NONE)
? binds[port][i].joyaxis : joypad_info.auto_binds[i].joyaxis;
bool res = false;
if ((uint16_t)joykey != NO_BTN && gx->joypad->button(joypad_info.joy_idx, (uint16_t)joykey))
res = true;
else if (((float)abs(gx->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold)
res = true;
if (res)
ret |= (1 << i);
}
}
else
{
/* Auto-binds are per joypad, not per user. */
const uint64_t joykey = (binds[port][id].joykey != NO_BTN)
? binds[port][id].joykey : joypad_info.auto_binds[id].joykey;
const uint32_t joyaxis = (binds[port][id].joyaxis != AXIS_NONE)
? binds[port][id].joyaxis : joypad_info.auto_binds[id].joyaxis;
if ((uint16_t)joykey != NO_BTN && gx->joypad->button(joypad_info.joy_idx, (uint16_t)joykey))
ret = 1;
else if (((float)abs(gx->joypad->axis(joypad_info.joy_idx, joyaxis)) / 0x8000) > joypad_info.axis_threshold)
ret = 1;
}
return ret;
2013-07-04 14:52:53 -04:00
case RETRO_DEVICE_ANALOG:
if (binds[port])
2017-09-27 23:16:37 +02:00
return input_joypad_analog(gx->joypad,
joypad_info, port, idx, id, binds[port]);
break;
2013-07-04 14:52:53 -04:00
}
return 0;
2011-12-14 13:20:22 +01:00
}
static void gx_input_free_input(void *data)
2011-12-14 13:20:22 +01:00
{
2014-06-09 21:17:43 +02:00
gx_input_t *gx = (gx_input_t*)data;
2011-12-14 13:20:22 +01:00
if (!gx)
return;
2014-06-09 21:17:43 +02:00
if (gx->joypad)
gx->joypad->destroy();
free(gx);
}
static void *gx_input_init(const char *joypad_driver)
2014-06-09 21:17:43 +02:00
{
gx_input_t *gx = (gx_input_t*)calloc(1, sizeof(*gx));
if (!gx)
return NULL;
gx->joypad = input_joypad_init_driver(joypad_driver, gx);
return gx;
}
static void gx_input_poll(void *data)
{
gx_input_t *gx = (gx_input_t*)data;
2012-12-15 05:46:49 +01:00
if (gx && gx->joypad)
gx->joypad->poll();
2011-12-14 13:20:22 +01:00
}
static uint64_t gx_input_get_capabilities(void *data)
{
(void)data;
return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG);
}
static const input_device_driver_t *gx_input_get_joypad_driver(void *data)
{
gx_input_t *gx = (gx_input_t*)data;
if (!gx)
return NULL;
return gx->joypad;
}
static void gx_input_grab_mouse(void *data, bool state)
{
(void)data;
(void)state;
}
static bool gx_input_set_rumble(void *data, unsigned port,
enum retro_rumble_effect effect, uint16_t strength)
{
(void)data;
(void)port;
(void)effect;
(void)strength;
return false;
}
static bool gx_input_keyboard_mapping_is_blocked(void *data)
{
gx_input_t *gx = (gx_input_t*)data;
if (!gx)
return false;
return gx->blocked;
}
2015-06-22 08:01:13 +02:00
static void gx_input_keyboard_mapping_set_block(void *data, bool value)
{
gx_input_t *gx = (gx_input_t*)data;
if (!gx)
return;
gx->blocked = value;
}
2014-09-11 07:06:20 +02:00
input_driver_t input_gx = {
gx_input_init,
gx_input_poll,
gx_input_state,
gx_input_free_input,
NULL,
NULL,
gx_input_get_capabilities,
"gx",
gx_input_grab_mouse,
NULL,
gx_input_set_rumble,
gx_input_get_joypad_driver,
2015-11-16 02:39:38 +01:00
NULL,
gx_input_keyboard_mapping_is_blocked,
gx_input_keyboard_mapping_set_block,
};