diff --git a/Makefile.common b/Makefile.common index 0cb5d1522f..edac155950 100644 --- a/Makefile.common +++ b/Makefile.common @@ -103,6 +103,7 @@ OBJ += frontend/frontend.o \ rewind.o \ gfx/gfx_common.o \ gfx/fonts/bitmapfont.o \ + input/input_autodetect.o \ input/input_common.o \ input/keyboard_line.o \ input/overlay.o \ diff --git a/griffin/griffin.c b/griffin/griffin.c index 14c88ba6b9..4acddb9bf7 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -284,6 +284,7 @@ FONTS /*============================================================ INPUT ============================================================ */ +#include "../input/input_autodetect.c" #include "../input/input_common.c" #include "../input/keyboard_line.c" diff --git a/input/input_autodetect.c b/input/input_autodetect.c new file mode 100644 index 0000000000..20a60a400e --- /dev/null +++ b/input/input_autodetect.c @@ -0,0 +1,153 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2014 - 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 . + */ + +#include "input_common.h" +#include "input_autodetect.h" +#include +#include +#include + +#include "../general.h" + +static void input_autoconfigure_joypad_conf(config_file_t *conf, + struct retro_keybind *binds) +{ + unsigned i; + for (i = 0; i < RARCH_BIND_LIST_END; i++) + { + input_config_parse_joy_button(conf, "input", + input_config_bind_map[i].base, &binds[i]); + input_config_parse_joy_axis(conf, "input", + input_config_bind_map[i].base, &binds[i]); + } +} + +static bool input_try_autoconfigure_joypad_from_conf(config_file_t *conf, + unsigned index, const char *name, const char *driver, + bool block_osd_spam) +{ + if (!conf) + return false; + + char ident[1024], ident_idx[1024]; + char input_driver[1024]; + bool cond_found_idx, cond_found_general; + + *ident = *input_driver = '\0'; + + config_get_array(conf, "input_device", ident, sizeof(ident)); + config_get_array(conf, "input_driver", input_driver, sizeof(input_driver)); + + snprintf(ident_idx, sizeof(ident_idx), "%s_p%u", ident, index); + + //RARCH_LOG("ident_idx: %s\n", ident_idx); + + cond_found_idx = !strcmp(ident_idx, name); + cond_found_general = !strcmp(ident, name) && !strcmp(driver, input_driver); + + if (cond_found_idx) + goto found; + else if (cond_found_general) + goto found; + + return false; + +found: + g_settings.input.autoconfigured[index] = true; + input_autoconfigure_joypad_conf(conf, g_settings.input.autoconf_binds[index]); + + char msg[512]; + snprintf(msg, sizeof(msg), "Joypad port #%u (%s) configured.", + index, name); + + if (!block_osd_spam) + msg_queue_push(g_extern.msg_queue, msg, 0, 60); + RARCH_LOG("%s\n", msg); + + return true; +} + +void input_config_autoconfigure_joypad(unsigned index, + const char *name, const char *driver) +{ + size_t i; + + if (!g_settings.input.autodetect_enable) + return; + + /* This will be the case if input driver is reinit. + * No reason to spam autoconfigure messages + * every time (fine in log). */ + bool block_osd_spam = g_settings.input.autoconfigured[index] && name; + + for (i = 0; i < RARCH_BIND_LIST_END; i++) + { + g_settings.input.autoconf_binds[index][i].joykey = NO_BTN; + g_settings.input.autoconf_binds[index][i].joyaxis = AXIS_NONE; + } + g_settings.input.autoconfigured[index] = false; + + if (!name) + return; + + /* false = load from both cfg files and internal */ + bool internal_only = !*g_settings.input.autoconfig_dir; + +#if defined(HAVE_BUILTIN_AUTOCONFIG) && (!defined(_WIN32) || defined(HAVE_WINXINPUT)) + /* First internal */ + for (i = 0; input_builtin_autoconfs[i]; i++) + { + config_file_t *conf = (config_file_t*) + config_file_new_from_string(input_builtin_autoconfs[i]); + bool success = input_try_autoconfigure_joypad_from_conf(conf, + index, name, driver, block_osd_spam); + config_file_free(conf); + if (success) + break; + } +#endif + + /* Now try files */ + if (!internal_only) + { + struct string_list *list = dir_list_new( + g_settings.input.autoconfig_dir, "cfg", false); + if (!list) + return; + + for (i = 0; i < list->size; i++) + { + config_file_t *conf = config_file_new(list->elems[i].data); + if (!conf) + continue; + bool success = input_try_autoconfigure_joypad_from_conf(conf, + index, name, driver, block_osd_spam); + config_file_free(conf); + if (success) + break; + } + + string_list_free(list); + } +} + +const struct retro_keybind *input_get_auto_bind(unsigned port, unsigned id) +{ + int joy_index = g_settings.input.joypad_map[port]; + if (joy_index < 0) + return NULL; + return &g_settings.input.autoconf_binds[joy_index][id]; +} diff --git a/input/input_autodetect.h b/input/input_autodetect.h new file mode 100644 index 0000000000..b890b041d9 --- /dev/null +++ b/input/input_autodetect.h @@ -0,0 +1,28 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2014 - 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 . + */ + +#ifndef _INPUT_AUTODETECT_H +#define _INPUT_AUTODETECT_H + +const struct retro_keybind *input_get_auto_bind(unsigned port, + unsigned id); + +void input_config_autoconfigure_joypad(unsigned index, + const char *name, const char *driver); + +extern const char* const input_builtin_autoconfs[]; + +#endif diff --git a/input/input_common.c b/input/input_common.c index ebfe5c1097..9f72980d12 100644 --- a/input/input_common.c +++ b/input/input_common.c @@ -1,5 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2014 - 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- @@ -1362,136 +1363,6 @@ void input_config_parse_joy_axis(config_file_t *conf, const char *prefix, } #if !defined(IS_JOYCONFIG) && !defined(IS_RETROLAUNCH) -static void input_autoconfigure_joypad_conf(config_file_t *conf, - struct retro_keybind *binds) -{ - unsigned i; - for (i = 0; i < RARCH_BIND_LIST_END; i++) - { - input_config_parse_joy_button(conf, "input", - input_config_bind_map[i].base, &binds[i]); - input_config_parse_joy_axis(conf, "input", - input_config_bind_map[i].base, &binds[i]); - } -} - -static bool input_try_autoconfigure_joypad_from_conf(config_file_t *conf, - unsigned index, const char *name, const char *driver, - bool block_osd_spam) -{ - if (!conf) - return false; - - char ident[1024], ident_idx[1024]; - char input_driver[1024]; - bool cond_found_idx, cond_found_general; - - *ident = *input_driver = '\0'; - - config_get_array(conf, "input_device", ident, sizeof(ident)); - config_get_array(conf, "input_driver", input_driver, sizeof(input_driver)); - - snprintf(ident_idx, sizeof(ident_idx), "%s_p%u", ident, index); - - //RARCH_LOG("ident_idx: %s\n", ident_idx); - - cond_found_idx = !strcmp(ident_idx, name); - cond_found_general = !strcmp(ident, name) && !strcmp(driver, input_driver); - - if (cond_found_idx) - goto found; - else if (cond_found_general) - goto found; - - return false; - -found: - g_settings.input.autoconfigured[index] = true; - input_autoconfigure_joypad_conf(conf, g_settings.input.autoconf_binds[index]); - - char msg[512]; - snprintf(msg, sizeof(msg), "Joypad port #%u (%s) configured.", - index, name); - - if (!block_osd_spam) - msg_queue_push(g_extern.msg_queue, msg, 0, 60); - RARCH_LOG("%s\n", msg); - - return true; -} - -void input_config_autoconfigure_joypad(unsigned index, - const char *name, const char *driver) -{ - size_t i; - - if (!g_settings.input.autodetect_enable) - return; - - /* This will be the case if input driver is reinit. - * No reason to spam autoconfigure messages - * every time (fine in log). */ - bool block_osd_spam = g_settings.input.autoconfigured[index] && name; - - for (i = 0; i < RARCH_BIND_LIST_END; i++) - { - g_settings.input.autoconf_binds[index][i].joykey = NO_BTN; - g_settings.input.autoconf_binds[index][i].joyaxis = AXIS_NONE; - } - g_settings.input.autoconfigured[index] = false; - - if (!name) - return; - - /* false = load from both cfg files and internal */ - bool internal_only = !*g_settings.input.autoconfig_dir; - -#if defined(HAVE_BUILTIN_AUTOCONFIG) && (!defined(_WIN32) || defined(HAVE_WINXINPUT)) - /* First internal */ - for (i = 0; input_builtin_autoconfs[i]; i++) - { - config_file_t *conf = (config_file_t*) - config_file_new_from_string(input_builtin_autoconfs[i]); - bool success = input_try_autoconfigure_joypad_from_conf(conf, - index, name, driver, block_osd_spam); - config_file_free(conf); - if (success) - break; - } -#endif - - /* Now try files */ - if (!internal_only) - { - struct string_list *list = dir_list_new( - g_settings.input.autoconfig_dir, "cfg", false); - if (!list) - return; - - for (i = 0; i < list->size; i++) - { - config_file_t *conf = config_file_new(list->elems[i].data); - if (!conf) - continue; - bool success = input_try_autoconfigure_joypad_from_conf(conf, - index, name, driver, block_osd_spam); - config_file_free(conf); - if (success) - break; - } - - string_list_free(list); - } -} - -const struct retro_keybind *input_get_auto_bind(unsigned port, unsigned id) -{ - int joy_index = g_settings.input.joypad_map[port]; - if (joy_index < 0) - return NULL; - return &g_settings.input.autoconf_binds[joy_index][id]; -} - static void input_get_bind_string_joykey(char *buf, const char *prefix, const struct retro_keybind *bind, size_t size) { @@ -1555,14 +1426,6 @@ void input_get_bind_string(char *buf, const struct retro_keybind *bind, strlcat(buf, keybuf, size); #endif } -#else -void input_config_autoconfigure_joypad(unsigned index, const char *name, - const char *driver) -{ - (void)index; - (void)name; - (void)driver; -} #endif void input_push_analog_dpad(struct retro_keybind *binds, unsigned mode) diff --git a/input/input_common.h b/input/input_common.h index d3e7b84511..6f2f637f05 100644 --- a/input/input_common.h +++ b/input/input_common.h @@ -16,6 +16,7 @@ #ifndef INPUT_COMMON_H__ #define INPUT_COMMON_H__ +#include "input_autodetect.h" #include "../driver.h" #include "../conf/config_file.h" #include "../general.h" @@ -173,8 +174,6 @@ struct input_bind_map extern const struct input_bind_map input_config_bind_map[]; -const struct retro_keybind *input_get_auto_bind(unsigned port, unsigned id); - /* auto_bind can be NULL. */ void input_get_bind_string(char *buf, const struct retro_keybind *bind, const struct retro_keybind *auto_bind, size_t size); @@ -188,8 +187,6 @@ extern const struct input_key_map input_config_key_map[]; void input_translate_rk_to_str(enum retro_key key, char *buf, size_t size); enum retro_key input_translate_str_to_rk(const char *str); -extern const char* const input_builtin_autoconfs[]; - const char *input_config_get_prefix(unsigned player, bool meta); /* Returns RARCH_BIND_LIST_END on not found. */ @@ -205,9 +202,6 @@ void input_config_parse_joy_button(config_file_t *conf, const char *prefix, void input_config_parse_joy_axis(config_file_t *conf, const char *prefix, const char *axis, struct retro_keybind *bind); -void input_config_autoconfigure_joypad(unsigned index, - const char *name, const char *driver); - void input_push_analog_dpad(struct retro_keybind *binds, unsigned mode); void input_pop_analog_dpad(struct retro_keybind *binds); diff --git a/tools/retroarch-joyconfig.c b/tools/retroarch-joyconfig.c index 3adc698cf2..bbcefb5b60 100644 --- a/tools/retroarch-joyconfig.c +++ b/tools/retroarch-joyconfig.c @@ -430,6 +430,11 @@ static void parse_input(int argc, char *argv[]) } +void input_config_autoconfigure_joypad(unsigned index, + const char *name, const char *driver) +{ +} + // Need SDL_main on OSX. #ifndef __APPLE__ #undef main