@@ -42,6 +42,7 @@ static bool running = true;
4242static bool paused_when_focus_lost = false ;
4343static Uint64 frame_time_start = 0 ;
4444static Uint64 frame_time_end = 0 ;
45+ static bool input_gamepad_shortcut_prev[config_HotkeyIndex_COUNT] = { };
4546static Uint32 mouse_last_motion_time = 0 ;
4647static const Uint32 mouse_hide_timeout_ms = 1500 ;
4748
@@ -54,6 +55,8 @@ static void sdl_events_emu(const SDL_Event* event);
5455static void sdl_shortcuts_gui (const SDL_Event* event);
5556static void sdl_add_gamepads (void );
5657static void sdl_remove_gamepad (SDL_JoystickID instance_id);
58+ static void input_check_gamepad_shortcuts (void );
59+ static bool input_get_button (SDL_GameController* controller, int mapping);
5760static void handle_mouse_cursor (void );
5861static void handle_menu (void );
5962static void run_emulator (void );
@@ -631,6 +634,8 @@ static void sdl_events_emu(const SDL_Event* event)
631634 emu_key_released (Left_Key);
632635 else if (event->cbutton .button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT )
633636 emu_key_released (Right_Key);
637+
638+ input_check_gamepad_shortcuts ();
634639 }
635640 break ;
636641
@@ -901,6 +906,60 @@ static void sdl_remove_gamepad(SDL_JoystickID instance_id)
901906 }
902907}
903908
909+ static void input_check_gamepad_shortcuts (void )
910+ {
911+ SDL_GameController* sdl_controller = application_gamepad;
912+ if (!IsValidPointer (sdl_controller))
913+ return ;
914+
915+ for (int i = 0 ; i < config_HotkeyIndex_COUNT; i++)
916+ {
917+ int button_mapping = config_input_gamepad_shortcuts.gamepad_shortcuts [i];
918+ if (button_mapping == SDL_CONTROLLER_BUTTON_INVALID )
919+ continue ;
920+
921+ bool button_pressed = input_get_button (sdl_controller, button_mapping);
922+
923+ if (button_pressed && !input_gamepad_shortcut_prev[i])
924+ {
925+ if (i >= config_HotkeyIndex_SelectSlot1 && i <= config_HotkeyIndex_SelectSlot5)
926+ {
927+ config_emulator.save_slot = i - config_HotkeyIndex_SelectSlot1;
928+ }
929+ else
930+ {
931+ for (int j = 0 ; j < GUI_HOTKEY_MAP_COUNT ; j++)
932+ {
933+ if (gui_hotkey_map[j].config_index == i)
934+ {
935+ gui_shortcut ((gui_ShortCutEvent)gui_hotkey_map[j].shortcut );
936+ break ;
937+ }
938+ }
939+ }
940+ }
941+
942+ input_gamepad_shortcut_prev[i] = button_pressed;
943+ }
944+ }
945+
946+ static bool input_get_button (SDL_GameController* controller, int mapping)
947+ {
948+ if (!IsValidPointer (controller))
949+ return false ;
950+
951+ if (mapping >= GAMEPAD_VBTN_AXIS_BASE )
952+ {
953+ int axis = mapping - GAMEPAD_VBTN_AXIS_BASE ;
954+ Sint16 value = SDL_GameControllerGetAxis (controller, (SDL_GameControllerAxis)axis);
955+ return value > GAMEPAD_VBTN_AXIS_THRESHOLD ;
956+ }
957+ else
958+ {
959+ return SDL_GameControllerGetButton (controller, (SDL_GameControllerButton)mapping) != 0 ;
960+ }
961+ }
962+
904963static void run_emulator (void )
905964{
906965 config_emulator.paused = emu_is_paused ();
0 commit comments