2018-04-24 13:37:02 +00:00
|
|
|
/* 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"
|
|
|
|
|
2019-05-27 12:32:40 +00:00
|
|
|
enum gamepad_pad_axes
|
|
|
|
{
|
2020-07-07 01:49:54 +00:00
|
|
|
AXIS_LEFT_ANALOG_X = 0,
|
2018-04-24 13:37:02 +00:00
|
|
|
AXIS_LEFT_ANALOG_Y,
|
|
|
|
AXIS_RIGHT_ANALOG_X,
|
|
|
|
AXIS_RIGHT_ANALOG_Y,
|
2020-08-14 06:31:17 +00:00
|
|
|
AXIS_TOUCH_X,
|
|
|
|
AXIS_TOUCH_Y,
|
2018-04-24 13:37:02 +00:00
|
|
|
AXIS_INVALID
|
|
|
|
};
|
|
|
|
|
|
|
|
void gamepad_read_axis_data(uint32_t axis, axis_data *data)
|
|
|
|
{
|
2020-07-24 20:12:33 +00:00
|
|
|
if (!data)
|
2018-04-24 13:37:02 +00:00
|
|
|
return;
|
|
|
|
|
2020-07-24 20:12:33 +00:00
|
|
|
data->axis = AXIS_POS_GET(axis);
|
|
|
|
data->is_negative = false;
|
2018-04-24 13:37:02 +00:00
|
|
|
|
2020-07-24 20:12:33 +00:00
|
|
|
if (data->axis >= AXIS_INVALID)
|
2018-04-24 13:37:02 +00:00
|
|
|
{
|
2020-07-24 20:12:33 +00:00
|
|
|
data->axis = AXIS_NEG_GET(axis);
|
2018-04-24 13:37:02 +00:00
|
|
|
data->is_negative = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int16_t gamepad_get_axis_value(int16_t state[3][2], axis_data *data)
|
2021-10-15 23:02:34 +00:00
|
|
|
{
|
|
|
|
return gamepad_get_axis_value_raw(state, data, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
int16_t gamepad_get_axis_value_raw(int16_t state[3][2], axis_data *data, bool do_clamp)
|
2018-04-24 13:37:02 +00:00
|
|
|
{
|
|
|
|
int16_t value = 0;
|
|
|
|
|
2020-07-24 20:12:33 +00:00
|
|
|
if (!data)
|
2018-04-24 13:37:02 +00:00
|
|
|
return 0;
|
|
|
|
|
2020-08-28 18:40:06 +00:00
|
|
|
switch (data->axis)
|
2018-04-24 13:37:02 +00:00
|
|
|
{
|
|
|
|
case AXIS_LEFT_ANALOG_X:
|
2021-09-15 01:30:05 +00:00
|
|
|
value = state[RETRO_DEVICE_INDEX_ANALOG_LEFT][1];
|
|
|
|
break;
|
2018-04-24 13:37:02 +00:00
|
|
|
case AXIS_LEFT_ANALOG_Y:
|
2021-09-15 01:30:05 +00:00
|
|
|
value = state[RETRO_DEVICE_INDEX_ANALOG_LEFT][0];
|
2018-04-24 13:37:02 +00:00
|
|
|
break;
|
|
|
|
case AXIS_RIGHT_ANALOG_X:
|
2021-09-15 01:30:05 +00:00
|
|
|
value = state[RETRO_DEVICE_INDEX_ANALOG_RIGHT][1];
|
|
|
|
break;
|
2018-04-24 13:37:02 +00:00
|
|
|
case AXIS_RIGHT_ANALOG_Y:
|
2021-09-15 01:30:05 +00:00
|
|
|
value = state[RETRO_DEVICE_INDEX_ANALOG_RIGHT][0];
|
2018-04-24 13:37:02 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-10-15 23:02:34 +00:00
|
|
|
if(do_clamp) {
|
|
|
|
if (data->is_negative && value > 0)
|
|
|
|
return 0;
|
|
|
|
if (!data->is_negative && value < 0)
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-24 20:12:33 +00:00
|
|
|
|
|
|
|
return value;
|
2018-04-24 13:37:02 +00:00
|
|
|
}
|