mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-23 03:10:14 +00:00
123 lines
2.8 KiB
C
123 lines
2.8 KiB
C
/* RetroArch - A frontend for libretro.
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
* Copyright (C) 2011-2014 - Daniel De Matteis
|
|
* Copyright (C) 2012-2014 - Michael Lelli
|
|
*
|
|
* 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/>.
|
|
*/
|
|
|
|
static bool gx_joypad_init(void)
|
|
{
|
|
PAD_Init();
|
|
#ifdef HW_RVL
|
|
WPADInit();
|
|
#endif
|
|
#ifdef HAVE_LIBSICKSAXIS
|
|
int i;
|
|
USB_Initialize();
|
|
ss_init();
|
|
for (i = 0; i < MAX_PADS; i++)
|
|
ss_initialize(&dev[i]);
|
|
#endif
|
|
|
|
|
|
return true;
|
|
}
|
|
|
|
static bool gx_joypad_button(unsigned port_num, uint16_t joykey)
|
|
{
|
|
gx_input_t *gx = (gx_input_t*)driver.input_data;
|
|
|
|
if (port_num >= MAX_PADS)
|
|
return false;
|
|
|
|
return gx->pad_state[port_num] & (1ULL << joykey);
|
|
}
|
|
|
|
static int16_t gx_joypad_axis(unsigned port_num, uint32_t joyaxis)
|
|
{
|
|
gx_input_t *gx = (gx_input_t*)driver.input_data;
|
|
if (joyaxis == AXIS_NONE || port_num >= MAX_PADS)
|
|
return 0;
|
|
|
|
int val = 0;
|
|
|
|
int axis = -1;
|
|
bool is_neg = false;
|
|
bool is_pos = false;
|
|
|
|
if (AXIS_NEG_GET(joyaxis) < 4)
|
|
{
|
|
axis = AXIS_NEG_GET(joyaxis);
|
|
is_neg = true;
|
|
}
|
|
else if (AXIS_POS_GET(joyaxis) < 4)
|
|
{
|
|
axis = AXIS_POS_GET(joyaxis);
|
|
is_pos = true;
|
|
}
|
|
|
|
switch (axis)
|
|
{
|
|
case 0: val = gx->analog_state[port_num][0][0]; break;
|
|
case 1: val = gx->analog_state[port_num][0][1]; break;
|
|
case 2: val = gx->analog_state[port_num][1][0]; break;
|
|
case 3: val = gx->analog_state[port_num][1][1]; break;
|
|
}
|
|
|
|
if (is_neg && val > 0)
|
|
val = 0;
|
|
else if (is_pos && val < 0)
|
|
val = 0;
|
|
|
|
return val;
|
|
}
|
|
|
|
static void gx_joypad_poll(void)
|
|
{
|
|
}
|
|
|
|
static bool gx_joypad_query_pad(unsigned pad)
|
|
{
|
|
gx_input_t *gx = (gx_input_t*)driver.input_data;
|
|
return pad < MAX_PLAYERS && gx->pad_state[pad];
|
|
}
|
|
|
|
static void gx_joypad_destroy(void)
|
|
{
|
|
int i;
|
|
for (i = 0; i < MAX_PADS; i++)
|
|
{
|
|
#ifdef HAVE_LIBSICKSAXIS
|
|
ss_close(&dev[i]);
|
|
USB_Deinitialize();
|
|
#endif
|
|
|
|
#ifdef HW_RVL
|
|
WPAD_Flush(i);
|
|
WPADDisconnect(i);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
const rarch_joypad_driver_t gx_joypad = {
|
|
gx_joypad_init,
|
|
gx_joypad_query_pad,
|
|
gx_joypad_destroy,
|
|
gx_joypad_button,
|
|
gx_joypad_axis,
|
|
gx_joypad_poll,
|
|
NULL,
|
|
gx_joypad_name,
|
|
"gx",
|
|
};
|