mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 12:32:52 +00:00
78858a9474
== DETAILS File this one under "I'm not sure how this ever worked." I mean, it did (in 1.8.8). I'm not sure what changed, but ultimately what I did was a bunch of comparative testing against 1.8.8: - I confirmed the packet data was still being read successfully - I confirmed that the axis value being passed into pad->get_axis() had not changed - I confirmed the work done in `gamepad_read_axis_data()` was working the same between 1.8.8 and master With the only difference between 1.8.8 and current being the return value from `gamepad_read_axis_data()`, I just rewrote the method to work properly, and also fixed up the default axis mapping. I tested this with a sixaxis controller and GCA, configuring the analog-to-digital control override to use the right stick.
75 lines
2.0 KiB
C
75 lines
2.0 KiB
C
/* RetroArch - A frontend for libretro.
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
* Copyright (C) 2011-2017 - 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 "../include/gamepad.h"
|
|
|
|
enum gamepad_pad_axes
|
|
{
|
|
AXIS_LEFT_ANALOG_X = 0,
|
|
AXIS_LEFT_ANALOG_Y,
|
|
AXIS_RIGHT_ANALOG_X,
|
|
AXIS_RIGHT_ANALOG_Y,
|
|
AXIS_TOUCH_X,
|
|
AXIS_TOUCH_Y,
|
|
AXIS_INVALID
|
|
};
|
|
|
|
void gamepad_read_axis_data(uint32_t axis, axis_data *data)
|
|
{
|
|
if (!data)
|
|
return;
|
|
|
|
data->axis = AXIS_POS_GET(axis);
|
|
data->is_negative = false;
|
|
|
|
if (data->axis >= AXIS_INVALID)
|
|
{
|
|
data->axis = AXIS_NEG_GET(axis);
|
|
data->is_negative = true;
|
|
}
|
|
}
|
|
|
|
int16_t gamepad_get_axis_value(int16_t state[3][2], axis_data *data)
|
|
{
|
|
int16_t value = 0;
|
|
|
|
if (!data)
|
|
return 0;
|
|
|
|
switch (data->axis)
|
|
{
|
|
case AXIS_LEFT_ANALOG_X:
|
|
value = state[RETRO_DEVICE_INDEX_ANALOG_LEFT][1];
|
|
break;
|
|
case AXIS_LEFT_ANALOG_Y:
|
|
value = state[RETRO_DEVICE_INDEX_ANALOG_LEFT][0];
|
|
break;
|
|
case AXIS_RIGHT_ANALOG_X:
|
|
value = state[RETRO_DEVICE_INDEX_ANALOG_RIGHT][1];
|
|
break;
|
|
case AXIS_RIGHT_ANALOG_Y:
|
|
value = state[RETRO_DEVICE_INDEX_ANALOG_RIGHT][0];
|
|
break;
|
|
}
|
|
|
|
if (data->is_negative && value > 0)
|
|
return 0;
|
|
if (!data->is_negative && value < 0)
|
|
return 0;
|
|
|
|
return value;
|
|
}
|