diff --git a/input/input_driver.c b/input/input_driver.c index 090083855b..d111d52e8a 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -25,6 +25,9 @@ #include "../verbosity.h" #include "../configuration.h" #include "../list_special.h" +#include "../performance_counters.h" + +#define HOLD_BTN_DELAY_SEC 2 /**************************************/ @@ -421,3 +424,140 @@ static const input_device_driver_t *input_joypad_init_first(void *data) return NULL; } + +bool input_driver_toggle_button_combo( + unsigned mode, + retro_time_t current_time, + input_bits_t* p_input) +{ + switch (mode) + { + case INPUT_TOGGLE_DOWN_Y_L_R: + if (BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_DOWN) && + BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_Y) && + BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_L) && + BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_R)) + return true; + break; + case INPUT_TOGGLE_L3_R3: + if (BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_L3) && + BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_R3)) + return true; + break; + case INPUT_TOGGLE_L1_R1_START_SELECT: + if (BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_L) && + BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_R) && + BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_START) && + BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_SELECT)) + return true; + break; + case INPUT_TOGGLE_START_SELECT: + if (BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_START) && + BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_SELECT)) + return true; + break; + case INPUT_TOGGLE_L3_R: + if (BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_L3) && + BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_R)) + return true; + break; + case INPUT_TOGGLE_L_R: + if (BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_L) && + BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_R)) + return true; + break; + case INPUT_TOGGLE_DOWN_SELECT: + if (BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_DOWN) && + BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_SELECT)) + return true; + break; + case INPUT_TOGGLE_L2_R2: + if (BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_L2) && + BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_R2)) + return true; + break; + case INPUT_TOGGLE_HOLD_START: + { + static rarch_timer_t timer = {0}; + + if (!BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_START)) + { + /* timer only runs while start is held down */ + timer.timer_end = true; + timer.timer_begin = false; + timer.timeout_end = 0; + return false; + } + + /* User started holding down the start button, start the timer */ + if (!timer.timer_begin) + { + uint64_t current_usec = cpu_features_get_time_usec(); + timer.timeout_us = HOLD_BTN_DELAY_SEC * 1000000; + timer.current = current_usec; + timer.timeout_end = timer.current + timer.timeout_us; + timer.timer_begin = true; + timer.timer_end = false; + } + + timer.current = current_time; + timer.timeout_us = (timer.timeout_end - timer.current); + + if (!timer.timer_end && (timer.timeout_us <= 0)) + { + /* start has been held down long enough, + * stop timer and enter menu */ + timer.timer_end = true; + timer.timer_begin = false; + timer.timeout_end = 0; + return true; + } + + return false; + } + case INPUT_TOGGLE_HOLD_SELECT: + { + static rarch_timer_t timer = {0}; + + if (!BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_SELECT)) + { + /* timer only runs while select is held down */ + timer.timer_end = true; + timer.timer_begin = false; + timer.timeout_end = 0; + return false; + } + + /* user started holding down the select button, start the timer */ + if (!timer.timer_begin) + { + uint64_t current_usec = cpu_features_get_time_usec(); + timer.timeout_us = HOLD_BTN_DELAY_SEC * 1000000; + timer.current = current_usec; + timer.timeout_end = timer.current + timer.timeout_us; + timer.timer_begin = true; + timer.timer_end = false; + } + + timer.current = current_time; + timer.timeout_us = (timer.timeout_end - timer.current); + + if (!timer.timer_end && (timer.timeout_us <= 0)) + { + /* select has been held down long enough, + * stop timer and enter menu */ + timer.timer_end = true; + timer.timer_begin = false; + timer.timeout_end = 0; + return true; + } + + return false; + } + default: + case INPUT_TOGGLE_NONE: + break; + } + + return false; +} diff --git a/input/input_driver.h b/input/input_driver.h index f401a733a3..390dfb3601 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -648,6 +648,11 @@ char *input_config_get_device_name_ptr(unsigned port); */ size_t input_config_get_device_name_size(unsigned port); +bool input_driver_toggle_button_combo( + unsigned mode, + retro_time_t current_time, + input_bits_t* p_input); + /*****************************************************************************/ const struct retro_keybind *input_config_get_bind_auto(unsigned port, unsigned id); diff --git a/retroarch.c b/retroarch.c index b3040f3299..17f0cc69bc 100644 --- a/retroarch.c +++ b/retroarch.c @@ -34408,133 +34408,6 @@ void runloop_get_status(bool *is_paused, bool *is_idle, } #ifdef HAVE_MENU -static bool input_driver_toggle_button_combo( - unsigned mode, - retro_time_t current_time, - input_bits_t* p_input) -{ - switch (mode) - { - case INPUT_TOGGLE_DOWN_Y_L_R: - if (BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_DOWN) && - BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_Y) && - BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_L) && - BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_R)) - return true; - break; - case INPUT_TOGGLE_L3_R3: - if (BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_L3) && - BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_R3)) - return true; - break; - case INPUT_TOGGLE_L1_R1_START_SELECT: - if (BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_L) && - BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_R) && - BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_START) && - BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_SELECT)) - return true; - break; - case INPUT_TOGGLE_START_SELECT: - if (BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_START) && - BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_SELECT)) - return true; - break; - case INPUT_TOGGLE_L3_R: - if (BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_L3) && - BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_R)) - return true; - break; - case INPUT_TOGGLE_L_R: - if (BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_L) && - BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_R)) - return true; - break; - case INPUT_TOGGLE_DOWN_SELECT: - if (BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_DOWN) && - BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_SELECT)) - return true; - break; - case INPUT_TOGGLE_L2_R2: - if (BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_L2) && - BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_R2)) - return true; - break; - case INPUT_TOGGLE_HOLD_START: - { - static rarch_timer_t timer = {0}; - - if (!BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_START)) - { - /* timer only runs while start is held down */ - RARCH_TIMER_END(timer); - return false; - } - - /* User started holding down the start button, start the timer */ - if (!timer.timer_begin) - { - uint64_t current_usec = cpu_features_get_time_usec(); - RARCH_TIMER_BEGIN_NEW_TIME_USEC(timer, - current_usec, - HOLD_BTN_DELAY_SEC * 1000000); - timer.timer_begin = true; - timer.timer_end = false; - } - - RARCH_TIMER_TICK(timer, current_time); - - if (!timer.timer_end && RARCH_TIMER_HAS_EXPIRED(timer)) - { - /* start has been held down long enough, - * stop timer and enter menu */ - RARCH_TIMER_END(timer); - return true; - } - - return false; - } - case INPUT_TOGGLE_HOLD_SELECT: - { - static rarch_timer_t timer = {0}; - - if (!BIT256_GET_PTR(p_input, RETRO_DEVICE_ID_JOYPAD_SELECT)) - { - /* timer only runs while select is held down */ - RARCH_TIMER_END(timer); - return false; - } - - /* user started holding down the select button, start the timer */ - if (!timer.timer_begin) - { - uint64_t current_usec = cpu_features_get_time_usec(); - RARCH_TIMER_BEGIN_NEW_TIME_USEC(timer, - current_usec, - HOLD_BTN_DELAY_SEC * 1000000); - timer.timer_begin = true; - timer.timer_end = false; - } - - RARCH_TIMER_TICK(timer, current_time); - - if (!timer.timer_end && RARCH_TIMER_HAS_EXPIRED(timer)) - { - /* select has been held down long enough, - * stop timer and enter menu */ - RARCH_TIMER_END(timer); - return true; - } - - return false; - } - default: - case INPUT_TOGGLE_NONE: - break; - } - - return false; -} - /* Display the libretro core's framebuffer onscreen. */ static bool menu_display_libretro( struct rarch_state *p_rarch, diff --git a/retroarch_data.h b/retroarch_data.h index 40c804b9e3..ebd6f4daef 100644 --- a/retroarch_data.h +++ b/retroarch_data.h @@ -56,7 +56,6 @@ #endif #define SHADER_FILE_WATCH_DELAY_MSEC 500 -#define HOLD_BTN_DELAY_SEC 2 #define QUIT_DELAY_USEC 3 * 1000000 /* 3 seconds */