2012-09-28 20:38:42 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2016-01-10 03:33:01 +00:00
|
|
|
* Copyright (C) 2011-2016 - Daniel De Matteis
|
2016-10-27 15:47:10 +00:00
|
|
|
* Copyright (C) 2016 - Brad Parker
|
2014-01-08 17:14:50 +00:00
|
|
|
*
|
2012-09-28 20:38:42 +00: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 <string.h>
|
|
|
|
#include <stdlib.h>
|
2013-07-18 00:26:01 +00:00
|
|
|
#include <ctype.h>
|
2012-09-28 20:38:42 +00:00
|
|
|
|
2016-09-05 22:56:00 +00:00
|
|
|
#include <compat/strl.h>
|
2015-06-22 18:40:11 +00:00
|
|
|
#include <file/file_path.h>
|
2016-12-15 10:17:48 +00:00
|
|
|
#include <file/config_file.h>
|
2015-12-26 06:54:17 +00:00
|
|
|
#include <string/stdstring.h>
|
2015-06-22 18:40:11 +00:00
|
|
|
|
2016-09-06 21:59:43 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../config.h"
|
|
|
|
#endif
|
|
|
|
|
2015-11-28 01:22:46 +00:00
|
|
|
#include "input_config.h"
|
2015-09-04 19:13:12 +00:00
|
|
|
#include "input_keymaps.h"
|
2015-11-24 00:19:48 +00:00
|
|
|
#include "input_remapping.h"
|
2015-09-04 19:13:12 +00:00
|
|
|
|
2016-06-29 00:40:05 +00:00
|
|
|
#include "../msg_hash.h"
|
2016-09-01 03:40:57 +00:00
|
|
|
#include "../configuration.h"
|
2016-06-28 09:10:30 +00:00
|
|
|
#include "../file_path_special.h"
|
2015-11-23 11:03:38 +00:00
|
|
|
#include "../verbosity.h"
|
2012-09-28 20:38:42 +00:00
|
|
|
|
2015-11-27 23:59:47 +00:00
|
|
|
/* Input config. */
|
|
|
|
struct input_bind_map
|
|
|
|
{
|
|
|
|
bool valid;
|
|
|
|
|
|
|
|
/* Meta binds get input as prefix, not input_playerN".
|
|
|
|
* 0 = libretro related.
|
|
|
|
* 1 = Common hotkey.
|
|
|
|
* 2 = Uncommon/obscure hotkey.
|
|
|
|
*/
|
|
|
|
unsigned meta;
|
|
|
|
|
|
|
|
const char *base;
|
2016-10-24 22:22:46 +00:00
|
|
|
enum msg_hash_enums desc;
|
2015-11-27 23:59:47 +00:00
|
|
|
unsigned retro_key;
|
|
|
|
};
|
|
|
|
|
2015-01-05 00:58:00 +00:00
|
|
|
static const char *bind_user_prefix[MAX_USERS] = {
|
2013-04-26 09:44:54 +00:00
|
|
|
"input_player1",
|
|
|
|
"input_player2",
|
|
|
|
"input_player3",
|
|
|
|
"input_player4",
|
|
|
|
"input_player5",
|
|
|
|
"input_player6",
|
|
|
|
"input_player7",
|
|
|
|
"input_player8",
|
2014-09-04 14:15:34 +00:00
|
|
|
"input_player9",
|
|
|
|
"input_player10",
|
|
|
|
"input_player11",
|
|
|
|
"input_player12",
|
|
|
|
"input_player13",
|
|
|
|
"input_player14",
|
|
|
|
"input_player15",
|
|
|
|
"input_player16",
|
2013-04-26 09:44:54 +00:00
|
|
|
};
|
|
|
|
|
2013-04-29 19:11:29 +00:00
|
|
|
#define DECLARE_BIND(x, bind, desc) { true, 0, #x, desc, bind }
|
|
|
|
#define DECLARE_META_BIND(level, x, bind, desc) { true, level, #x, desc, bind }
|
2013-04-26 09:44:54 +00:00
|
|
|
|
|
|
|
const struct input_bind_map input_config_bind_map[RARCH_BIND_LIST_END_NULL] = {
|
2016-10-24 22:22:46 +00:00
|
|
|
DECLARE_BIND(b, RETRO_DEVICE_ID_JOYPAD_B, MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_B),
|
|
|
|
DECLARE_BIND(y, RETRO_DEVICE_ID_JOYPAD_Y, MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_Y),
|
|
|
|
DECLARE_BIND(select, RETRO_DEVICE_ID_JOYPAD_SELECT, MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_SELECT),
|
|
|
|
DECLARE_BIND(start, RETRO_DEVICE_ID_JOYPAD_START, MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_START),
|
2016-12-11 18:00:03 +00:00
|
|
|
DECLARE_BIND(up, RETRO_DEVICE_ID_JOYPAD_UP, MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_UP),
|
|
|
|
DECLARE_BIND(down, RETRO_DEVICE_ID_JOYPAD_DOWN, MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_DOWN),
|
|
|
|
DECLARE_BIND(left, RETRO_DEVICE_ID_JOYPAD_LEFT, MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_LEFT),
|
|
|
|
DECLARE_BIND(right, RETRO_DEVICE_ID_JOYPAD_RIGHT, MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_RIGHT),
|
|
|
|
DECLARE_BIND(a, RETRO_DEVICE_ID_JOYPAD_A, MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_A),
|
|
|
|
DECLARE_BIND(x, RETRO_DEVICE_ID_JOYPAD_X, MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_X),
|
|
|
|
DECLARE_BIND(l, RETRO_DEVICE_ID_JOYPAD_L, MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_L),
|
2016-10-24 22:22:46 +00:00
|
|
|
DECLARE_BIND(r, RETRO_DEVICE_ID_JOYPAD_R, MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_R),
|
|
|
|
DECLARE_BIND(l2, RETRO_DEVICE_ID_JOYPAD_L2, MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_L2),
|
|
|
|
DECLARE_BIND(r2, RETRO_DEVICE_ID_JOYPAD_R2, MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_R2),
|
|
|
|
DECLARE_BIND(l3, RETRO_DEVICE_ID_JOYPAD_L3, MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_L3),
|
|
|
|
DECLARE_BIND(r3, RETRO_DEVICE_ID_JOYPAD_R3, MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_R3),
|
2016-12-11 12:03:02 +00:00
|
|
|
DECLARE_BIND(l_x_plus, RARCH_ANALOG_LEFT_X_PLUS, MENU_ENUM_LABEL_VALUE_INPUT_ANALOG_LEFT_X_PLUS),
|
2016-12-11 18:00:03 +00:00
|
|
|
DECLARE_BIND(l_x_minus, RARCH_ANALOG_LEFT_X_MINUS, MENU_ENUM_LABEL_VALUE_INPUT_ANALOG_LEFT_X_MINUS),
|
|
|
|
DECLARE_BIND(l_y_plus, RARCH_ANALOG_LEFT_Y_PLUS, MENU_ENUM_LABEL_VALUE_INPUT_ANALOG_LEFT_Y_PLUS),
|
|
|
|
DECLARE_BIND(l_y_minus, RARCH_ANALOG_LEFT_Y_MINUS, MENU_ENUM_LABEL_VALUE_INPUT_ANALOG_LEFT_Y_MINUS),
|
2016-12-11 12:03:02 +00:00
|
|
|
DECLARE_BIND(r_x_plus, RARCH_ANALOG_RIGHT_X_PLUS, MENU_ENUM_LABEL_VALUE_INPUT_ANALOG_RIGHT_X_PLUS),
|
2016-12-11 18:00:03 +00:00
|
|
|
DECLARE_BIND(r_x_minus, RARCH_ANALOG_RIGHT_X_MINUS, MENU_ENUM_LABEL_VALUE_INPUT_ANALOG_RIGHT_X_MINUS),
|
|
|
|
DECLARE_BIND(r_y_plus, RARCH_ANALOG_RIGHT_Y_PLUS, MENU_ENUM_LABEL_VALUE_INPUT_ANALOG_RIGHT_Y_PLUS),
|
|
|
|
DECLARE_BIND(r_y_minus, RARCH_ANALOG_RIGHT_Y_MINUS, MENU_ENUM_LABEL_VALUE_INPUT_ANALOG_RIGHT_Y_MINUS),
|
2016-10-24 22:22:46 +00:00
|
|
|
|
|
|
|
DECLARE_BIND(turbo, RARCH_TURBO_ENABLE, MENU_ENUM_LABEL_VALUE_INPUT_TURBO_ENABLE),
|
|
|
|
|
|
|
|
DECLARE_META_BIND(1, toggle_fast_forward, RARCH_FAST_FORWARD_KEY, MENU_ENUM_LABEL_VALUE_INPUT_META_FAST_FORWARD_KEY),
|
|
|
|
DECLARE_META_BIND(2, hold_fast_forward, RARCH_FAST_FORWARD_HOLD_KEY, MENU_ENUM_LABEL_VALUE_INPUT_META_FAST_FORWARD_HOLD_KEY),
|
|
|
|
DECLARE_META_BIND(1, load_state, RARCH_LOAD_STATE_KEY, MENU_ENUM_LABEL_VALUE_INPUT_META_LOAD_STATE_KEY),
|
|
|
|
DECLARE_META_BIND(1, save_state, RARCH_SAVE_STATE_KEY, MENU_ENUM_LABEL_VALUE_INPUT_META_SAVE_STATE_KEY),
|
|
|
|
DECLARE_META_BIND(2, toggle_fullscreen, RARCH_FULLSCREEN_TOGGLE_KEY, MENU_ENUM_LABEL_VALUE_INPUT_META_FULLSCREEN_TOGGLE_KEY),
|
|
|
|
DECLARE_META_BIND(2, exit_emulator, RARCH_QUIT_KEY, MENU_ENUM_LABEL_VALUE_INPUT_META_QUIT_KEY),
|
|
|
|
DECLARE_META_BIND(2, state_slot_increase, RARCH_STATE_SLOT_PLUS, MENU_ENUM_LABEL_VALUE_INPUT_META_STATE_SLOT_PLUS),
|
|
|
|
DECLARE_META_BIND(2, state_slot_decrease, RARCH_STATE_SLOT_MINUS, MENU_ENUM_LABEL_VALUE_INPUT_META_STATE_SLOT_MINUS),
|
|
|
|
DECLARE_META_BIND(1, rewind, RARCH_REWIND, MENU_ENUM_LABEL_VALUE_INPUT_META_REWIND),
|
|
|
|
DECLARE_META_BIND(2, movie_record_toggle, RARCH_MOVIE_RECORD_TOGGLE, MENU_ENUM_LABEL_VALUE_INPUT_META_MOVIE_RECORD_TOGGLE),
|
|
|
|
DECLARE_META_BIND(2, pause_toggle, RARCH_PAUSE_TOGGLE, MENU_ENUM_LABEL_VALUE_INPUT_META_PAUSE_TOGGLE),
|
|
|
|
DECLARE_META_BIND(2, frame_advance, RARCH_FRAMEADVANCE, MENU_ENUM_LABEL_VALUE_INPUT_META_FRAMEADVANCE),
|
|
|
|
DECLARE_META_BIND(2, reset, RARCH_RESET, MENU_ENUM_LABEL_VALUE_INPUT_META_RESET),
|
|
|
|
DECLARE_META_BIND(2, shader_next, RARCH_SHADER_NEXT, MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_NEXT),
|
|
|
|
DECLARE_META_BIND(2, shader_prev, RARCH_SHADER_PREV, MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_PREV),
|
|
|
|
DECLARE_META_BIND(2, cheat_index_plus, RARCH_CHEAT_INDEX_PLUS, MENU_ENUM_LABEL_VALUE_INPUT_META_CHEAT_INDEX_PLUS),
|
|
|
|
DECLARE_META_BIND(2, cheat_index_minus, RARCH_CHEAT_INDEX_MINUS, MENU_ENUM_LABEL_VALUE_INPUT_META_CHEAT_INDEX_MINUS),
|
|
|
|
DECLARE_META_BIND(2, cheat_toggle, RARCH_CHEAT_TOGGLE, MENU_ENUM_LABEL_VALUE_INPUT_META_CHEAT_TOGGLE),
|
|
|
|
DECLARE_META_BIND(2, screenshot, RARCH_SCREENSHOT, MENU_ENUM_LABEL_VALUE_INPUT_META_SCREENSHOT),
|
|
|
|
DECLARE_META_BIND(2, audio_mute, RARCH_MUTE, MENU_ENUM_LABEL_VALUE_INPUT_META_MUTE),
|
|
|
|
DECLARE_META_BIND(2, osk_toggle, RARCH_OSK, MENU_ENUM_LABEL_VALUE_INPUT_META_OSK),
|
2016-12-12 22:22:35 +00:00
|
|
|
DECLARE_META_BIND(2, netplay_flip_players_1_2, RARCH_NETPLAY_FLIP, MENU_ENUM_LABEL_VALUE_INPUT_META_NETPLAY_FLIP),
|
|
|
|
DECLARE_META_BIND(2, netplay_game_watch, RARCH_NETPLAY_GAME_WATCH, MENU_ENUM_LABEL_VALUE_INPUT_META_NETPLAY_GAME_WATCH),
|
2016-10-24 22:22:46 +00:00
|
|
|
DECLARE_META_BIND(2, slowmotion, RARCH_SLOWMOTION, MENU_ENUM_LABEL_VALUE_INPUT_META_SLOWMOTION),
|
|
|
|
DECLARE_META_BIND(2, enable_hotkey, RARCH_ENABLE_HOTKEY, MENU_ENUM_LABEL_VALUE_INPUT_META_ENABLE_HOTKEY),
|
|
|
|
DECLARE_META_BIND(2, volume_up, RARCH_VOLUME_UP, MENU_ENUM_LABEL_VALUE_INPUT_META_VOLUME_UP),
|
|
|
|
DECLARE_META_BIND(2, volume_down, RARCH_VOLUME_DOWN, MENU_ENUM_LABEL_VALUE_INPUT_META_VOLUME_DOWN),
|
|
|
|
DECLARE_META_BIND(2, overlay_next, RARCH_OVERLAY_NEXT, MENU_ENUM_LABEL_VALUE_INPUT_META_OVERLAY_NEXT),
|
|
|
|
DECLARE_META_BIND(2, disk_eject_toggle, RARCH_DISK_EJECT_TOGGLE, MENU_ENUM_LABEL_VALUE_INPUT_META_DISK_EJECT_TOGGLE),
|
|
|
|
DECLARE_META_BIND(2, disk_next, RARCH_DISK_NEXT, MENU_ENUM_LABEL_VALUE_INPUT_META_DISK_NEXT),
|
|
|
|
DECLARE_META_BIND(2, disk_prev, RARCH_DISK_PREV, MENU_ENUM_LABEL_VALUE_INPUT_META_DISK_PREV),
|
|
|
|
DECLARE_META_BIND(2, grab_mouse_toggle, RARCH_GRAB_MOUSE_TOGGLE, MENU_ENUM_LABEL_VALUE_INPUT_META_GRAB_MOUSE_TOGGLE),
|
2016-12-06 05:32:28 +00:00
|
|
|
DECLARE_META_BIND(2, game_focus_toggle, RARCH_GAME_FOCUS_TOGGLE, MENU_ENUM_LABEL_VALUE_INPUT_META_GAME_FOCUS_TOGGLE),
|
2013-11-08 03:36:16 +00:00
|
|
|
#ifdef HAVE_MENU
|
2016-10-24 22:22:46 +00:00
|
|
|
DECLARE_META_BIND(1, menu_toggle, RARCH_MENU_TOGGLE, MENU_ENUM_LABEL_VALUE_INPUT_META_MENU_TOGGLE),
|
2013-04-26 09:44:54 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2015-11-28 01:13:27 +00:00
|
|
|
static const void *input_config_bind_map_get(unsigned i)
|
2015-11-27 23:44:34 +00:00
|
|
|
{
|
2016-05-23 20:04:00 +00:00
|
|
|
return (const struct input_bind_map*)&input_config_bind_map[i];
|
2015-11-27 23:51:33 +00:00
|
|
|
}
|
|
|
|
|
2015-11-28 01:13:27 +00:00
|
|
|
bool input_config_bind_map_get_valid(unsigned i)
|
2015-11-27 23:57:57 +00:00
|
|
|
{
|
2016-02-05 13:09:46 +00:00
|
|
|
const struct input_bind_map *keybind =
|
|
|
|
(const struct input_bind_map*)input_config_bind_map_get(i);
|
2015-11-27 23:57:57 +00:00
|
|
|
if (!keybind)
|
|
|
|
return false;
|
|
|
|
return keybind->valid;
|
|
|
|
}
|
|
|
|
|
2015-11-28 01:13:27 +00:00
|
|
|
unsigned input_config_bind_map_get_meta(unsigned i)
|
2015-11-27 23:51:33 +00:00
|
|
|
{
|
2016-02-05 13:09:46 +00:00
|
|
|
const struct input_bind_map *keybind =
|
|
|
|
(const struct input_bind_map*)input_config_bind_map_get(i);
|
2015-11-27 23:51:33 +00:00
|
|
|
if (!keybind)
|
|
|
|
return 0;
|
|
|
|
return keybind->meta;
|
|
|
|
}
|
|
|
|
|
2015-11-28 01:13:27 +00:00
|
|
|
const char *input_config_bind_map_get_base(unsigned i)
|
2015-11-27 23:51:33 +00:00
|
|
|
{
|
2016-02-05 13:09:46 +00:00
|
|
|
const struct input_bind_map *keybind =
|
|
|
|
(const struct input_bind_map*)input_config_bind_map_get(i);
|
2015-11-27 23:44:34 +00:00
|
|
|
if (!keybind)
|
|
|
|
return NULL;
|
|
|
|
return keybind->base;
|
|
|
|
}
|
|
|
|
|
2015-11-28 01:13:27 +00:00
|
|
|
const char *input_config_bind_map_get_desc(unsigned i)
|
2015-11-27 23:51:33 +00:00
|
|
|
{
|
2016-02-05 13:09:46 +00:00
|
|
|
const struct input_bind_map *keybind =
|
|
|
|
(const struct input_bind_map*)input_config_bind_map_get(i);
|
2015-11-27 23:51:33 +00:00
|
|
|
if (!keybind)
|
|
|
|
return NULL;
|
2016-10-24 22:22:46 +00:00
|
|
|
return msg_hash_to_str(keybind->desc);
|
2015-11-27 23:51:33 +00:00
|
|
|
}
|
|
|
|
|
2016-12-15 10:17:48 +00:00
|
|
|
void input_config_parse_key(void *data,
|
2014-09-02 14:50:28 +00:00
|
|
|
const char *prefix, const char *btn,
|
2013-04-26 09:44:54 +00:00
|
|
|
struct retro_keybind *bind)
|
|
|
|
{
|
2015-11-17 05:23:14 +00:00
|
|
|
char tmp[64];
|
|
|
|
char key[64];
|
2016-12-15 10:17:48 +00:00
|
|
|
config_file_t *conf = (config_file_t*)data;
|
2016-10-09 06:58:44 +00:00
|
|
|
|
|
|
|
tmp[0] = key[0] = '\0';
|
|
|
|
|
2015-06-22 18:40:11 +00:00
|
|
|
fill_pathname_join_delim(key, prefix, btn, '_', sizeof(key));
|
2013-04-26 09:44:54 +00:00
|
|
|
|
|
|
|
if (config_get_array(conf, key, tmp, sizeof(tmp)))
|
2015-11-28 01:26:57 +00:00
|
|
|
bind->key = input_config_translate_str_to_rk(tmp);
|
2013-04-26 09:44:54 +00:00
|
|
|
}
|
|
|
|
|
2014-12-05 12:53:49 +00:00
|
|
|
const char *input_config_get_prefix(unsigned user, bool meta)
|
2013-04-26 09:44:54 +00:00
|
|
|
{
|
2014-12-05 12:53:49 +00:00
|
|
|
if (user == 0)
|
|
|
|
return meta ? "input" : bind_user_prefix[user];
|
2015-11-17 05:23:14 +00:00
|
|
|
|
|
|
|
if (user != 0 && !meta)
|
2014-12-05 12:53:49 +00:00
|
|
|
return bind_user_prefix[user];
|
2015-11-17 05:23:14 +00:00
|
|
|
|
2014-12-05 12:53:49 +00:00
|
|
|
/* Don't bother with meta bind for anyone else than first user. */
|
2014-09-02 14:50:28 +00:00
|
|
|
return NULL;
|
2013-04-26 09:44:54 +00:00
|
|
|
}
|
|
|
|
|
2015-01-10 23:07:59 +00:00
|
|
|
static enum retro_key find_rk_bind(const char *str)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; input_config_key_map[i].str; i++)
|
|
|
|
{
|
2016-01-20 16:34:19 +00:00
|
|
|
if (string_is_equal_noncase(input_config_key_map[i].str, str))
|
2015-01-10 23:07:59 +00:00
|
|
|
return input_config_key_map[i].key;
|
|
|
|
}
|
|
|
|
|
|
|
|
RARCH_WARN("Key name %s not found.\n", str);
|
|
|
|
return RETROK_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2015-01-12 03:19:57 +00:00
|
|
|
/**
|
2015-11-28 01:26:57 +00:00
|
|
|
* input_config_translate_str_to_rk:
|
2015-01-12 03:19:57 +00:00
|
|
|
* @str : String to translate to key ID.
|
|
|
|
*
|
|
|
|
* Translates tring representation to key identifier.
|
|
|
|
*
|
|
|
|
* Returns: key identifier.
|
|
|
|
**/
|
2015-11-28 01:26:57 +00:00
|
|
|
enum retro_key input_config_translate_str_to_rk(const char *str)
|
2015-01-10 23:07:59 +00:00
|
|
|
{
|
2015-09-05 12:31:07 +00:00
|
|
|
if (strlen(str) == 1 && isalpha((int)*str))
|
|
|
|
return (enum retro_key)(RETROK_a + (tolower((int)*str) - (int)'a'));
|
2015-01-10 23:07:59 +00:00
|
|
|
return find_rk_bind(str);
|
|
|
|
}
|
|
|
|
|
2015-01-10 20:17:34 +00:00
|
|
|
/**
|
2015-11-28 01:26:57 +00:00
|
|
|
* input_config_translate_str_to_bind_id:
|
2015-01-10 20:17:34 +00:00
|
|
|
* @str : String to translate to bind ID.
|
|
|
|
*
|
|
|
|
* Translate string representation to bind ID.
|
|
|
|
*
|
2016-02-05 13:09:46 +00:00
|
|
|
* Returns: Bind ID value on success, otherwise
|
|
|
|
* RARCH_BIND_LIST_END on not found.
|
2015-01-10 20:17:34 +00:00
|
|
|
**/
|
2015-11-28 01:26:57 +00:00
|
|
|
unsigned input_config_translate_str_to_bind_id(const char *str)
|
2014-01-07 16:14:09 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
2015-01-12 03:19:57 +00:00
|
|
|
|
2014-01-07 16:14:09 +00:00
|
|
|
for (i = 0; input_config_bind_map[i].valid; i++)
|
2016-01-20 03:07:24 +00:00
|
|
|
if (string_is_equal(str, input_config_bind_map[i].base))
|
2014-01-07 16:14:09 +00:00
|
|
|
return i;
|
2016-01-20 03:07:24 +00:00
|
|
|
|
2014-01-07 16:14:09 +00:00
|
|
|
return RARCH_BIND_LIST_END;
|
|
|
|
}
|
|
|
|
|
2013-04-26 09:44:54 +00:00
|
|
|
static void parse_hat(struct retro_keybind *bind, const char *str)
|
|
|
|
{
|
2015-06-12 21:52:52 +00:00
|
|
|
uint16_t hat;
|
|
|
|
uint16_t hat_dir = 0;
|
|
|
|
char *dir = NULL;
|
2015-01-10 20:17:34 +00:00
|
|
|
|
2014-09-12 02:59:52 +00:00
|
|
|
if (!bind || !str)
|
|
|
|
return;
|
|
|
|
|
2015-09-05 12:31:07 +00:00
|
|
|
if (!isdigit((int)*str))
|
2013-04-26 09:44:54 +00:00
|
|
|
return;
|
|
|
|
|
2015-01-09 00:08:54 +00:00
|
|
|
hat = strtoul(str, &dir, 0);
|
2013-04-26 09:44:54 +00:00
|
|
|
|
|
|
|
if (!dir)
|
|
|
|
{
|
|
|
|
RARCH_WARN("Found invalid hat in config!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-20 16:34:19 +00:00
|
|
|
if (string_is_equal_noncase(dir, "up"))
|
2013-04-26 09:44:54 +00:00
|
|
|
hat_dir = HAT_UP_MASK;
|
2016-01-20 16:34:19 +00:00
|
|
|
else if (string_is_equal_noncase(dir, "down"))
|
2013-04-26 09:44:54 +00:00
|
|
|
hat_dir = HAT_DOWN_MASK;
|
2016-01-20 16:34:19 +00:00
|
|
|
else if (string_is_equal_noncase(dir, "left"))
|
2013-04-26 09:44:54 +00:00
|
|
|
hat_dir = HAT_LEFT_MASK;
|
2016-01-20 16:34:19 +00:00
|
|
|
else if (string_is_equal_noncase(dir, "right"))
|
2013-04-26 09:44:54 +00:00
|
|
|
hat_dir = HAT_RIGHT_MASK;
|
|
|
|
|
|
|
|
if (hat_dir)
|
|
|
|
bind->joykey = HAT_MAP(hat, hat_dir);
|
|
|
|
}
|
|
|
|
|
2016-12-15 10:17:48 +00:00
|
|
|
void input_config_parse_joy_button(void *data, const char *prefix,
|
2013-04-26 09:44:54 +00:00
|
|
|
const char *btn, struct retro_keybind *bind)
|
|
|
|
{
|
2016-10-09 06:58:44 +00:00
|
|
|
char str[256];
|
|
|
|
char tmp[64];
|
|
|
|
char key[64];
|
2016-12-19 17:55:02 +00:00
|
|
|
char key_label[64];
|
2016-10-09 06:58:44 +00:00
|
|
|
char *tmp_a = NULL;
|
2016-12-15 10:17:48 +00:00
|
|
|
config_file_t *conf = (config_file_t*)data;
|
2016-10-09 06:58:44 +00:00
|
|
|
|
2016-12-19 17:55:02 +00:00
|
|
|
str[0] = tmp[0] = key[0] = key_label[0] = '\0';
|
2015-01-09 00:08:54 +00:00
|
|
|
|
2016-02-05 13:09:46 +00:00
|
|
|
fill_pathname_join_delim(str, prefix, btn,
|
|
|
|
'_', sizeof(str));
|
|
|
|
fill_pathname_join_delim(key, str,
|
|
|
|
"btn", '_', sizeof(key));
|
|
|
|
fill_pathname_join_delim(key_label, str,
|
|
|
|
"btn_label", '_', sizeof(key_label));
|
2013-04-26 09:44:54 +00:00
|
|
|
|
|
|
|
if (config_get_array(conf, key, tmp, sizeof(tmp)))
|
|
|
|
{
|
2014-10-14 16:35:38 +00:00
|
|
|
btn = tmp;
|
2016-06-28 09:10:30 +00:00
|
|
|
if (string_is_equal(btn, file_path_str(FILE_PATH_NUL)))
|
2013-04-26 09:44:54 +00:00
|
|
|
bind->joykey = NO_BTN;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (*btn == 'h')
|
|
|
|
parse_hat(bind, btn + 1);
|
|
|
|
else
|
|
|
|
bind->joykey = strtoull(tmp, NULL, 0);
|
|
|
|
}
|
|
|
|
}
|
2014-12-16 05:21:18 +00:00
|
|
|
|
|
|
|
if (config_get_string(conf, key_label, &tmp_a))
|
2015-07-09 17:54:46 +00:00
|
|
|
{
|
2014-12-16 05:21:18 +00:00
|
|
|
strlcpy(bind->joykey_label, tmp_a, sizeof(bind->joykey_label));
|
2015-07-09 17:54:46 +00:00
|
|
|
free(tmp_a);
|
|
|
|
}
|
2013-04-26 09:44:54 +00:00
|
|
|
}
|
|
|
|
|
2016-12-15 10:17:48 +00:00
|
|
|
void input_config_parse_joy_axis(void *data, const char *prefix,
|
2013-04-26 09:44:54 +00:00
|
|
|
const char *axis, struct retro_keybind *bind)
|
|
|
|
{
|
2016-10-09 06:58:44 +00:00
|
|
|
char str[256];
|
|
|
|
char tmp[64];
|
|
|
|
char key[64];
|
|
|
|
char key_label[64];
|
2016-12-15 10:17:48 +00:00
|
|
|
char *tmp_a = NULL;
|
|
|
|
config_file_t *conf = (config_file_t*)data;
|
2015-01-09 00:08:54 +00:00
|
|
|
|
2016-10-09 06:58:44 +00:00
|
|
|
str[0] = tmp[0] = key[0] = key_label[0] = '\0';
|
|
|
|
|
2016-02-05 13:09:46 +00:00
|
|
|
fill_pathname_join_delim(str, prefix, axis,
|
|
|
|
'_', sizeof(str));
|
|
|
|
fill_pathname_join_delim(key, str,
|
|
|
|
"axis", '_', sizeof(key));
|
|
|
|
fill_pathname_join_delim(key_label, str,
|
|
|
|
"axis_label", '_', sizeof(key_label));
|
2013-04-26 09:44:54 +00:00
|
|
|
|
|
|
|
if (config_get_array(conf, key, tmp, sizeof(tmp)))
|
|
|
|
{
|
2016-06-28 09:10:30 +00:00
|
|
|
if (string_is_equal(tmp, file_path_str(FILE_PATH_NUL)))
|
2013-04-26 09:44:54 +00:00
|
|
|
bind->joyaxis = AXIS_NONE;
|
|
|
|
else if (strlen(tmp) >= 2 && (*tmp == '+' || *tmp == '-'))
|
|
|
|
{
|
2014-10-14 16:35:38 +00:00
|
|
|
int i_axis = strtol(tmp + 1, NULL, 0);
|
2013-04-26 09:44:54 +00:00
|
|
|
if (*tmp == '+')
|
2014-10-14 16:35:38 +00:00
|
|
|
bind->joyaxis = AXIS_POS(i_axis);
|
2013-04-26 09:44:54 +00:00
|
|
|
else
|
2014-10-14 16:35:38 +00:00
|
|
|
bind->joyaxis = AXIS_NEG(i_axis);
|
2013-04-26 09:44:54 +00:00
|
|
|
}
|
2014-06-11 13:47:20 +00:00
|
|
|
|
2015-01-10 20:17:34 +00:00
|
|
|
/* Ensure that D-pad emulation doesn't screw this over. */
|
2014-06-11 13:47:20 +00:00
|
|
|
bind->orig_joyaxis = bind->joyaxis;
|
2013-04-26 09:44:54 +00:00
|
|
|
}
|
2014-12-16 05:21:18 +00:00
|
|
|
|
|
|
|
if (config_get_string(conf, key_label, &tmp_a))
|
2015-07-09 17:54:46 +00:00
|
|
|
{
|
2014-12-16 05:21:18 +00:00
|
|
|
strlcpy(bind->joyaxis_label, tmp_a, sizeof(bind->joyaxis_label));
|
2015-07-09 17:54:46 +00:00
|
|
|
free(tmp_a);
|
|
|
|
}
|
2013-04-26 09:44:54 +00:00
|
|
|
}
|
|
|
|
|
2015-11-28 15:06:14 +00:00
|
|
|
static void input_config_get_bind_string_joykey(char *buf, const char *prefix,
|
2014-09-02 14:50:28 +00:00
|
|
|
const struct retro_keybind *bind, size_t size)
|
2014-06-09 17:23:06 +00:00
|
|
|
{
|
2015-03-20 20:22:38 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2017-01-03 03:55:37 +00:00
|
|
|
bool label_show = settings->input.input_descriptor_label_show;
|
2015-03-20 20:22:38 +00:00
|
|
|
|
2014-08-13 22:49:28 +00:00
|
|
|
if (GET_HAT_DIR(bind->joykey))
|
2013-12-24 10:11:25 +00:00
|
|
|
{
|
2016-06-28 09:10:30 +00:00
|
|
|
const char *dir = "?";
|
2015-01-12 03:19:57 +00:00
|
|
|
|
2014-06-09 17:23:06 +00:00
|
|
|
switch (GET_HAT_DIR(bind->joykey))
|
2013-12-24 10:11:25 +00:00
|
|
|
{
|
2014-10-25 08:07:04 +00:00
|
|
|
case HAT_UP_MASK:
|
|
|
|
dir = "up";
|
|
|
|
break;
|
|
|
|
case HAT_DOWN_MASK:
|
|
|
|
dir = "down";
|
|
|
|
break;
|
|
|
|
case HAT_LEFT_MASK:
|
|
|
|
dir = "left";
|
|
|
|
break;
|
|
|
|
case HAT_RIGHT_MASK:
|
|
|
|
dir = "right";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2013-12-24 10:11:25 +00:00
|
|
|
}
|
2014-12-16 05:21:18 +00:00
|
|
|
|
2017-01-03 03:55:37 +00:00
|
|
|
if (!string_is_empty(bind->joykey_label) && label_show)
|
2014-12-16 05:21:18 +00:00
|
|
|
snprintf(buf, size, "%s %s ", prefix, bind->joykey_label);
|
|
|
|
else
|
2016-06-29 00:40:05 +00:00
|
|
|
snprintf(buf, size, "%sHat #%u %s (%s)", prefix,
|
|
|
|
(unsigned)GET_HAT(bind->joykey), dir,
|
|
|
|
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE));
|
2014-06-09 17:23:06 +00:00
|
|
|
}
|
|
|
|
else
|
2014-12-16 05:21:18 +00:00
|
|
|
{
|
2017-01-03 03:55:37 +00:00
|
|
|
if (!string_is_empty(bind->joykey_label) && label_show)
|
2014-12-16 05:21:18 +00:00
|
|
|
snprintf(buf, size, "%s%s (btn) ", prefix, bind->joykey_label);
|
|
|
|
else
|
2016-06-29 00:40:05 +00:00
|
|
|
snprintf(buf, size, "%s%u (%s) ", prefix, (unsigned)bind->joykey,
|
|
|
|
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE));
|
2014-12-16 05:21:18 +00:00
|
|
|
}
|
2014-06-09 17:23:06 +00:00
|
|
|
}
|
|
|
|
|
2015-11-28 15:06:14 +00:00
|
|
|
static void input_config_get_bind_string_joyaxis(char *buf, const char *prefix,
|
2014-09-02 14:50:28 +00:00
|
|
|
const struct retro_keybind *bind, size_t size)
|
2014-06-09 17:23:06 +00:00
|
|
|
{
|
2015-06-12 21:52:52 +00:00
|
|
|
unsigned axis = 0;
|
|
|
|
char dir = '\0';
|
2015-03-20 20:22:38 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2015-01-09 00:08:54 +00:00
|
|
|
|
2014-06-09 17:23:06 +00:00
|
|
|
if (AXIS_NEG_GET(bind->joyaxis) != AXIS_DIR_NONE)
|
|
|
|
{
|
|
|
|
dir = '-';
|
|
|
|
axis = AXIS_NEG_GET(bind->joyaxis);
|
2013-12-24 10:11:25 +00:00
|
|
|
}
|
2014-06-09 17:23:06 +00:00
|
|
|
else if (AXIS_POS_GET(bind->joyaxis) != AXIS_DIR_NONE)
|
|
|
|
{
|
|
|
|
dir = '+';
|
|
|
|
axis = AXIS_POS_GET(bind->joyaxis);
|
|
|
|
}
|
2016-02-05 13:09:46 +00:00
|
|
|
if (!string_is_empty(bind->joyaxis_label)
|
|
|
|
&& settings->input.input_descriptor_label_show)
|
2014-12-16 05:21:18 +00:00
|
|
|
snprintf(buf, size, "%s%s (axis) ", prefix, bind->joyaxis_label);
|
|
|
|
else
|
2016-06-29 00:40:05 +00:00
|
|
|
snprintf(buf, size, "%s%c%u (%s) ", prefix, dir, axis,
|
|
|
|
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE));
|
2014-06-09 17:23:06 +00:00
|
|
|
}
|
|
|
|
|
2015-11-28 15:06:14 +00:00
|
|
|
void input_config_get_bind_string(char *buf, const struct retro_keybind *bind,
|
2014-06-09 17:23:06 +00:00
|
|
|
const struct retro_keybind *auto_bind, size_t size)
|
|
|
|
{
|
2016-02-05 13:09:46 +00:00
|
|
|
#ifndef RARCH_CONSOLE
|
|
|
|
char key[64];
|
|
|
|
char keybuf[64];
|
2016-10-09 06:58:44 +00:00
|
|
|
|
|
|
|
key[0] = keybuf[0] = '\0';
|
2016-02-05 13:09:46 +00:00
|
|
|
#endif
|
2015-01-09 16:48:20 +00:00
|
|
|
|
2014-06-09 17:23:06 +00:00
|
|
|
*buf = '\0';
|
|
|
|
if (bind->joykey != NO_BTN)
|
2015-11-28 15:06:14 +00:00
|
|
|
input_config_get_bind_string_joykey(buf, "", bind, size);
|
2014-06-09 17:23:06 +00:00
|
|
|
else if (bind->joyaxis != AXIS_NONE)
|
2015-11-28 15:06:14 +00:00
|
|
|
input_config_get_bind_string_joyaxis(buf, "", bind, size);
|
2014-06-09 17:23:06 +00:00
|
|
|
else if (auto_bind && auto_bind->joykey != NO_BTN)
|
2015-11-28 15:06:14 +00:00
|
|
|
input_config_get_bind_string_joykey(buf, "Auto: ", auto_bind, size);
|
2014-06-09 17:23:06 +00:00
|
|
|
else if (auto_bind && auto_bind->joyaxis != AXIS_NONE)
|
2015-11-28 15:06:14 +00:00
|
|
|
input_config_get_bind_string_joyaxis(buf, "Auto: ", auto_bind, size);
|
2013-12-24 10:11:25 +00:00
|
|
|
|
|
|
|
#ifndef RARCH_CONSOLE
|
2015-01-12 01:52:52 +00:00
|
|
|
input_keymaps_translate_rk_to_str(bind->key, key, sizeof(key));
|
2016-06-28 09:10:30 +00:00
|
|
|
if (string_is_equal(key, file_path_str(FILE_PATH_NUL)))
|
2013-12-24 10:11:25 +00:00
|
|
|
*key = '\0';
|
|
|
|
|
2016-11-07 22:28:26 +00:00
|
|
|
snprintf(keybuf, sizeof(keybuf), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_KEY), key);
|
2013-12-24 10:11:25 +00:00
|
|
|
strlcat(buf, keybuf, size);
|
|
|
|
#endif
|
|
|
|
}
|
2016-12-01 02:43:51 +00:00
|
|
|
|
|
|
|
const struct retro_keybind *input_config_get_bind_auto(unsigned port, unsigned id)
|
|
|
|
{
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
unsigned joy_idx = 0;
|
|
|
|
|
|
|
|
if (settings)
|
|
|
|
joy_idx = settings->input.joypad_map[port];
|
|
|
|
|
|
|
|
if (joy_idx < MAX_USERS)
|
|
|
|
return &settings->input.autoconf_binds[joy_idx][id];
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-01-05 03:52:04 +00:00
|
|
|
|
|
|
|
unsigned input_config_label_to_key(const char *label)
|
|
|
|
{
|
|
|
|
unsigned key = 0;
|
|
|
|
|
|
|
|
if (string_is_equal(label, "toggle_fast_forward"))
|
|
|
|
key = RARCH_FAST_FORWARD_KEY;
|
|
|
|
else if (string_is_equal(label, "hold_fast_forward"))
|
|
|
|
key = RARCH_FAST_FORWARD_HOLD_KEY;
|
|
|
|
else if (string_is_equal(label, "load_state"))
|
|
|
|
key = RARCH_LOAD_STATE_KEY;
|
|
|
|
else if (string_is_equal(label, "save_state"))
|
|
|
|
key = RARCH_SAVE_STATE_KEY;
|
|
|
|
else if (string_is_equal(label, "toggle_fullscreen"))
|
|
|
|
key = RARCH_FULLSCREEN_TOGGLE_KEY;
|
|
|
|
else if (string_is_equal(label, "exit_emulator"))
|
|
|
|
key = RARCH_QUIT_KEY;
|
|
|
|
else if (string_is_equal(label, "state_slot_increase"))
|
|
|
|
key = RARCH_STATE_SLOT_PLUS;
|
|
|
|
else if (string_is_equal(label, "state_slot_decrease"))
|
|
|
|
key = RARCH_STATE_SLOT_MINUS;
|
|
|
|
else if (string_is_equal(label, "rewind"))
|
|
|
|
key = RARCH_REWIND;
|
|
|
|
else if (string_is_equal(label, "movie_record_toggle"))
|
|
|
|
key = RARCH_MOVIE_RECORD_TOGGLE;
|
|
|
|
else if (string_is_equal(label, "pause_toggle"))
|
|
|
|
key = RARCH_PAUSE_TOGGLE;
|
|
|
|
else if (string_is_equal(label, "frame_advance"))
|
|
|
|
key = RARCH_FRAMEADVANCE;
|
|
|
|
else if (string_is_equal(label, "reset"))
|
|
|
|
key = RARCH_RESET;
|
|
|
|
else if (string_is_equal(label, "shader_next"))
|
|
|
|
key = RARCH_SHADER_NEXT;
|
|
|
|
else if (string_is_equal(label, "shader_prev"))
|
|
|
|
key = RARCH_SHADER_PREV;
|
|
|
|
else if (string_is_equal(label, "cheat_index_plus"))
|
|
|
|
key = RARCH_CHEAT_INDEX_PLUS;
|
|
|
|
else if (string_is_equal(label, "cheat_index_minus"))
|
|
|
|
key = RARCH_CHEAT_INDEX_MINUS;
|
|
|
|
else if (string_is_equal(label, "cheat_toggle"))
|
|
|
|
key = RARCH_CHEAT_TOGGLE;
|
|
|
|
else if (string_is_equal(label, "screenshot"))
|
|
|
|
key = RARCH_SCREENSHOT;
|
|
|
|
else if (string_is_equal(label, "audio_mute"))
|
|
|
|
key = RARCH_MUTE;
|
|
|
|
else if (string_is_equal(label, "osk_toggle"))
|
|
|
|
key = RARCH_OSK;
|
|
|
|
else if (string_is_equal(label, "netplay_flip_players_1_2"))
|
|
|
|
key = RARCH_NETPLAY_FLIP;
|
|
|
|
else if (string_is_equal(label, "netplay_game_watch"))
|
|
|
|
key = RARCH_NETPLAY_GAME_WATCH;
|
|
|
|
else if (string_is_equal(label, "slowmotion"))
|
|
|
|
key = RARCH_SLOWMOTION;
|
|
|
|
else if (string_is_equal(label, "enable_hotkey"))
|
|
|
|
key = RARCH_ENABLE_HOTKEY;
|
|
|
|
else if (string_is_equal(label, "volume_up"))
|
|
|
|
key = RARCH_VOLUME_UP;
|
|
|
|
else if (string_is_equal(label, "volume_down"))
|
|
|
|
key = RARCH_VOLUME_DOWN;
|
|
|
|
else if (string_is_equal(label, "overlay_next"))
|
|
|
|
key = RARCH_OVERLAY_NEXT;
|
|
|
|
else if (string_is_equal(label, "disk_eject_toggle"))
|
|
|
|
key = RARCH_DISK_EJECT_TOGGLE;
|
|
|
|
else if (string_is_equal(label, "disk_next"))
|
|
|
|
key = RARCH_DISK_NEXT;
|
|
|
|
else if (string_is_equal(label, "disk_prev"))
|
|
|
|
key = RARCH_DISK_PREV;
|
|
|
|
else if (string_is_equal(label, "grab_mouse_toggle"))
|
|
|
|
key = RARCH_GRAB_MOUSE_TOGGLE;
|
|
|
|
else if (string_is_equal(label, "game_focus_toggle"))
|
|
|
|
key = RARCH_GAME_FOCUS_TOGGLE;
|
|
|
|
else if (string_is_equal(label, "menu_toggle"))
|
|
|
|
key = RARCH_MENU_TOGGLE;
|
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|