2017-09-07 22:30:42 -05:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2019-06-16 13:32:27 -05:00
|
|
|
* Copyright (C) 2016-2019 - Andrés Suárez
|
2017-09-07 22:30:42 -05:00
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <direct.h>
|
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <compat/strl.h>
|
|
|
|
#include <compat/posix_string.h>
|
|
|
|
#include <libretro.h>
|
2017-12-26 22:02:11 -05:00
|
|
|
|
2017-09-07 22:30:42 -05:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../config.h"
|
|
|
|
#endif
|
|
|
|
|
2019-07-10 05:39:50 +02:00
|
|
|
#include "input_driver.h"
|
2017-09-07 22:30:42 -05:00
|
|
|
#include "input_mapper.h"
|
|
|
|
|
2018-05-02 13:52:27 +02:00
|
|
|
#ifdef HAVE_OVERLAY
|
|
|
|
#include "input_overlay.h"
|
|
|
|
#endif
|
|
|
|
|
2017-09-07 22:30:42 -05:00
|
|
|
#include "../configuration.h"
|
2020-03-24 20:00:13 -07:00
|
|
|
#include "../retroarch.h"
|
2017-09-07 22:30:42 -05:00
|
|
|
|
2019-07-10 04:43:19 +02:00
|
|
|
void input_mapper_poll(input_mapper_t *handle,
|
2019-07-10 05:39:50 +02:00
|
|
|
void *ol_pointer,
|
2019-07-10 04:43:19 +02:00
|
|
|
void *settings_data,
|
2019-08-09 16:17:30 +02:00
|
|
|
void *input_data,
|
2019-07-10 04:43:19 +02:00
|
|
|
unsigned max_users,
|
|
|
|
bool poll_overlay)
|
2017-09-07 22:30:42 -05:00
|
|
|
{
|
2018-04-08 23:13:20 +02:00
|
|
|
unsigned i, j;
|
2019-07-10 05:39:50 +02:00
|
|
|
#ifdef HAVE_OVERLAY
|
|
|
|
input_overlay_t *overlay_pointer = (input_overlay_t*)ol_pointer;
|
|
|
|
#endif
|
2019-07-10 04:43:19 +02:00
|
|
|
settings_t *settings = (settings_t*)settings_data;
|
2019-08-09 16:17:30 +02:00
|
|
|
input_bits_t *current_inputs = (input_bits_t*)input_data;
|
2017-11-24 02:37:53 +01:00
|
|
|
|
|
|
|
memset(handle->keys, 0, sizeof(handle->keys));
|
2018-04-03 20:16:15 -05:00
|
|
|
|
2018-04-04 12:22:07 -05:00
|
|
|
for (i = 0; i < max_users; i++)
|
2017-11-24 02:37:53 +01:00
|
|
|
{
|
2019-08-07 04:05:12 +02:00
|
|
|
unsigned device = settings->uints.input_libretro_device[i]
|
|
|
|
& RETRO_DEVICE_MASK;
|
2019-08-09 16:17:30 +02:00
|
|
|
input_bits_t current_input = *current_inputs++;
|
2019-08-07 04:05:12 +02:00
|
|
|
|
|
|
|
switch (device)
|
|
|
|
{
|
|
|
|
/* keyboard to gamepad remapping */
|
|
|
|
case RETRO_DEVICE_KEYBOARD:
|
2018-04-08 22:36:48 +02:00
|
|
|
for (j = 0; j < RARCH_CUSTOM_BIND_LIST_END; j++)
|
2018-04-08 21:38:57 +02:00
|
|
|
{
|
2018-09-15 01:21:03 -04:00
|
|
|
unsigned remap_button =
|
2018-04-08 22:36:48 +02:00
|
|
|
settings->uints.input_keymapper_ids[i][j];
|
2018-04-08 23:08:21 +02:00
|
|
|
bool remap_valid = remap_button != RETROK_UNKNOWN;
|
2018-04-08 22:36:48 +02:00
|
|
|
|
2018-04-08 23:08:21 +02:00
|
|
|
if (remap_valid)
|
2018-04-08 22:36:48 +02:00
|
|
|
{
|
2018-04-08 23:08:21 +02:00
|
|
|
unsigned current_button_value = BIT256_GET(current_input, j);
|
2018-07-22 11:32:52 -10:00
|
|
|
#ifdef HAVE_OVERLAY
|
2019-08-07 04:05:12 +02:00
|
|
|
if (poll_overlay && i == 0)
|
|
|
|
current_button_value |= input_overlay_key_pressed(overlay_pointer, j);
|
2018-07-22 11:32:52 -10:00
|
|
|
#endif
|
2018-04-08 23:08:21 +02:00
|
|
|
if ((current_button_value == 1) && (j != remap_button))
|
|
|
|
{
|
|
|
|
MAPPER_SET_KEY (handle,
|
|
|
|
remap_button);
|
|
|
|
input_keyboard_event(true,
|
|
|
|
remap_button,
|
|
|
|
0, 0, RETRO_DEVICE_KEYBOARD);
|
2019-08-07 04:05:12 +02:00
|
|
|
continue;
|
2018-04-08 23:08:21 +02:00
|
|
|
}
|
2019-08-07 04:05:12 +02:00
|
|
|
|
|
|
|
/* Release keyboard event*/
|
|
|
|
input_keyboard_event(false,
|
|
|
|
remap_button,
|
|
|
|
0, 0, RETRO_DEVICE_KEYBOARD);
|
2018-03-28 17:45:05 -05:00
|
|
|
}
|
|
|
|
}
|
2018-04-08 22:36:48 +02:00
|
|
|
break;
|
2018-04-04 21:33:03 -05:00
|
|
|
|
2018-04-08 22:36:48 +02:00
|
|
|
/* gamepad remapping */
|
|
|
|
case RETRO_DEVICE_JOYPAD:
|
|
|
|
case RETRO_DEVICE_ANALOG:
|
2018-09-15 01:21:03 -04:00
|
|
|
/* this loop iterates on all users and all buttons,
|
|
|
|
* and checks if a pressed button is assigned to any
|
|
|
|
* other button than the default one, then it sets
|
|
|
|
* the bit on the mapper input bitmap, later on the
|
2018-04-08 22:36:48 +02:00
|
|
|
* original input is cleared in input_state */
|
|
|
|
BIT256_CLEAR_ALL(handle->buttons[i]);
|
2018-04-08 01:45:40 -05:00
|
|
|
|
2018-04-08 22:36:48 +02:00
|
|
|
for (j = 0; j < 8; j++)
|
|
|
|
handle->analog_value[i][j] = 0;
|
2018-04-03 00:21:33 -05:00
|
|
|
|
2018-04-08 22:36:48 +02:00
|
|
|
for (j = 0; j < RARCH_FIRST_CUSTOM_BIND; j++)
|
2018-04-08 12:12:45 -05:00
|
|
|
{
|
2018-05-02 13:52:27 +02:00
|
|
|
bool remap_valid;
|
2019-07-10 04:43:19 +02:00
|
|
|
unsigned remap_button =
|
|
|
|
settings->uints.input_remap_ids[i][j];
|
2018-04-08 22:36:48 +02:00
|
|
|
unsigned current_button_value = BIT256_GET(current_input, j);
|
2018-05-02 13:52:27 +02:00
|
|
|
#ifdef HAVE_OVERLAY
|
2018-05-01 18:07:24 -05:00
|
|
|
if (poll_overlay && i == 0)
|
2019-07-10 04:43:19 +02:00
|
|
|
current_button_value |= input_overlay_key_pressed(overlay_pointer, j);
|
2018-05-02 13:52:27 +02:00
|
|
|
#endif
|
|
|
|
remap_valid = (current_button_value == 1) &&
|
2018-04-08 23:08:21 +02:00
|
|
|
(j != remap_button) && (remap_button != RARCH_UNMAPPED);
|
2018-04-08 22:36:48 +02:00
|
|
|
|
2020-04-17 16:29:23 +02:00
|
|
|
#ifdef HAVE_ACCESSIBILITY
|
2020-03-24 20:00:13 -07:00
|
|
|
/* gamepad override */
|
|
|
|
if (i==0 && get_gamepad_input_override() & (1<<j))
|
|
|
|
{
|
|
|
|
BIT256_SET(handle->buttons[i], j);
|
|
|
|
}
|
2020-04-17 16:29:23 +02:00
|
|
|
#endif
|
2020-03-24 20:00:13 -07:00
|
|
|
|
2018-04-08 23:08:21 +02:00
|
|
|
if (remap_valid)
|
2018-04-08 22:36:48 +02:00
|
|
|
{
|
2018-04-08 23:08:21 +02:00
|
|
|
if (remap_button < RARCH_FIRST_CUSTOM_BIND)
|
|
|
|
{
|
|
|
|
BIT256_SET(handle->buttons[i], remap_button);
|
|
|
|
}
|
|
|
|
else if (remap_button >= RARCH_FIRST_CUSTOM_BIND)
|
|
|
|
{
|
|
|
|
int invert = 1;
|
2018-04-08 12:12:45 -05:00
|
|
|
|
2018-04-08 23:08:21 +02:00
|
|
|
if (remap_button % 2 != 0)
|
|
|
|
invert = -1;
|
2018-04-08 12:12:45 -05:00
|
|
|
|
2018-04-08 23:08:21 +02:00
|
|
|
handle->analog_value[i][
|
2018-09-15 01:21:03 -04:00
|
|
|
remap_button - RARCH_FIRST_CUSTOM_BIND] =
|
2018-11-10 17:27:14 +01:00
|
|
|
(current_input.analog_buttons[j] ? current_input.analog_buttons[j] : 32767) * invert;
|
2018-04-08 23:08:21 +02:00
|
|
|
}
|
2018-04-08 22:36:48 +02:00
|
|
|
}
|
2018-04-08 12:12:45 -05:00
|
|
|
}
|
2018-04-03 00:21:33 -05:00
|
|
|
|
2018-04-08 22:36:48 +02:00
|
|
|
for (j = 0; j < 8; j++)
|
2018-04-08 00:44:05 -05:00
|
|
|
{
|
2018-04-08 22:36:48 +02:00
|
|
|
unsigned k = j + RARCH_FIRST_CUSTOM_BIND;
|
|
|
|
int16_t current_axis_value = current_input.analogs[j];
|
2018-09-15 01:21:03 -04:00
|
|
|
unsigned remap_axis =
|
2018-04-08 22:36:48 +02:00
|
|
|
settings->uints.input_remap_ids[i][k];
|
|
|
|
|
|
|
|
if (
|
2018-05-27 11:58:52 -05:00
|
|
|
(abs(current_axis_value) > 0 &&
|
2019-08-07 04:05:12 +02:00
|
|
|
(k != remap_axis) &&
|
|
|
|
(remap_axis != RARCH_UNMAPPED)
|
|
|
|
))
|
2018-04-08 01:45:40 -05:00
|
|
|
{
|
2018-09-15 01:21:03 -04:00
|
|
|
if (remap_axis < RARCH_FIRST_CUSTOM_BIND &&
|
2019-08-07 04:05:12 +02:00
|
|
|
abs(current_axis_value) > *input_driver_get_float(INPUT_ACTION_AXIS_THRESHOLD) * 32767)
|
2018-04-08 22:36:48 +02:00
|
|
|
{
|
|
|
|
BIT256_SET(handle->buttons[i], remap_axis);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-15 01:21:03 -04:00
|
|
|
unsigned remap_axis_bind = remap_axis - RARCH_FIRST_CUSTOM_BIND;
|
2018-04-08 22:36:48 +02:00
|
|
|
|
2018-09-15 01:21:03 -04:00
|
|
|
if (remap_axis_bind < sizeof(handle->analog_value[i]))
|
|
|
|
{
|
2019-07-10 04:43:19 +02:00
|
|
|
int invert = 1;
|
|
|
|
if ( (k % 2 == 0 && remap_axis % 2 != 0) ||
|
|
|
|
(k % 2 != 0 && remap_axis % 2 == 0)
|
|
|
|
)
|
|
|
|
invert = -1;
|
|
|
|
|
2018-09-15 01:21:03 -04:00
|
|
|
handle->analog_value[i][
|
|
|
|
remap_axis_bind] =
|
|
|
|
current_axis_value * invert;
|
|
|
|
}
|
2018-04-08 22:36:48 +02:00
|
|
|
}
|
2018-04-08 01:45:40 -05:00
|
|
|
}
|
2018-04-08 12:12:45 -05:00
|
|
|
|
2018-04-08 00:44:05 -05:00
|
|
|
}
|
2018-04-08 22:36:48 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2018-04-03 00:21:33 -05:00
|
|
|
}
|
|
|
|
}
|
2017-09-07 22:30:42 -05:00
|
|
|
}
|