mirror of https://github.com/LIJI32/SameBoy.git
Add joypad hotkeys to SDL
This commit is contained in:
parent
08549c1395
commit
349114097b
|
@ -30,6 +30,9 @@ configuration_t configuration =
|
|||
4,
|
||||
-1,
|
||||
5,
|
||||
// The rest are unmapped by default
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
},
|
||||
.joypad_axises = {
|
||||
0,
|
||||
|
|
|
@ -25,6 +25,8 @@ typedef enum {
|
|||
JOYPAD_BUTTON_TURBO,
|
||||
JOYPAD_BUTTON_REWIND,
|
||||
JOYPAD_BUTTON_SLOW_MOTION,
|
||||
JOYPAD_BUTTON_HOTKEY_1,
|
||||
JOYPAD_BUTTON_HOTKEY_2,
|
||||
JOYPAD_BUTTONS_MAX
|
||||
} joypad_button_t;
|
||||
|
||||
|
@ -34,6 +36,35 @@ typedef enum {
|
|||
JOYPAD_AXISES_MAX
|
||||
} joypad_axis_t;
|
||||
|
||||
typedef enum {
|
||||
HOTKEY_NONE,
|
||||
HOTKEY_PAUSE,
|
||||
HOTKEY_MUTE,
|
||||
HOTKEY_RESET,
|
||||
HOTKEY_QUIT,
|
||||
HOTKEY_SAVE_STATE_1,
|
||||
HOTKEY_LOAD_STATE_1,
|
||||
HOTKEY_SAVE_STATE_2,
|
||||
HOTKEY_LOAD_STATE_2,
|
||||
HOTKEY_SAVE_STATE_3,
|
||||
HOTKEY_LOAD_STATE_3,
|
||||
HOTKEY_SAVE_STATE_4,
|
||||
HOTKEY_LOAD_STATE_4,
|
||||
HOTKEY_SAVE_STATE_5,
|
||||
HOTKEY_LOAD_STATE_5,
|
||||
HOTKEY_SAVE_STATE_6,
|
||||
HOTKEY_LOAD_STATE_6,
|
||||
HOTKEY_SAVE_STATE_7,
|
||||
HOTKEY_LOAD_STATE_7,
|
||||
HOTKEY_SAVE_STATE_8,
|
||||
HOTKEY_LOAD_STATE_8,
|
||||
HOTKEY_SAVE_STATE_9,
|
||||
HOTKEY_LOAD_STATE_9,
|
||||
HOTKEY_SAVE_STATE_10,
|
||||
HOTKEY_LOAD_STATE_10,
|
||||
HOTKEY_MAX = HOTKEY_LOAD_STATE_10,
|
||||
} hotkey_action_t;
|
||||
|
||||
typedef struct {
|
||||
SDL_Scancode keys[9];
|
||||
GB_color_correction_mode_t color_correction_mode;
|
||||
|
@ -59,7 +90,7 @@ typedef struct {
|
|||
/* v0.11 */
|
||||
uint32_t rewind_length;
|
||||
SDL_Scancode keys_2[32]; /* Rewind and underclock, + padding for the future */
|
||||
uint8_t joypad_configuration[32]; /* 12 Keys + padding for the future*/;
|
||||
uint8_t joypad_configuration[32]; /* 14 Keys + padding for the future*/;
|
||||
uint8_t joypad_axises[JOYPAD_AXISES_MAX];
|
||||
|
||||
/* v0.12 */
|
||||
|
@ -99,6 +130,7 @@ typedef struct {
|
|||
bool allow_background_controllers;
|
||||
bool gui_pallete_enabled; // Change the GUI palette only once the user changed the DMG palette
|
||||
char dmg_palette_name[25];
|
||||
hotkey_action_t hotkey_actions[2];
|
||||
};
|
||||
} configuration_t;
|
||||
|
||||
|
|
55
SDL/gui.c
55
SDL/gui.c
|
@ -1283,10 +1283,63 @@ static const char *current_background_control_mode(unsigned index)
|
|||
return configuration.allow_background_controllers? "Always" : "During Window Focus Only";
|
||||
}
|
||||
|
||||
static void cycle_hotkey(unsigned index)
|
||||
{
|
||||
if (configuration.hotkey_actions[index - 2] == HOTKEY_MAX) {
|
||||
configuration.hotkey_actions[index - 2] = 0;
|
||||
}
|
||||
else {
|
||||
configuration.hotkey_actions[index - 2]++;
|
||||
}
|
||||
}
|
||||
|
||||
static void cycle_hotkey_backwards(unsigned index)
|
||||
{
|
||||
if (configuration.hotkey_actions[index - 2] == 0) {
|
||||
configuration.hotkey_actions[index - 2] = HOTKEY_MAX;
|
||||
}
|
||||
else {
|
||||
configuration.hotkey_actions[index - 2]--;
|
||||
}
|
||||
}
|
||||
|
||||
static const char *current_hotkey(unsigned index)
|
||||
{
|
||||
return (const char *[]){
|
||||
"None",
|
||||
"Toggle Pause",
|
||||
"Toggle Mute",
|
||||
"Reset",
|
||||
"Quit SameBoy",
|
||||
"Save State Slot 1",
|
||||
"Load State Slot 1",
|
||||
"Save State Slot 2",
|
||||
"Load State Slot 2",
|
||||
"Save State Slot 3",
|
||||
"Load State Slot 3",
|
||||
"Save State Slot 4",
|
||||
"Load State Slot 4",
|
||||
"Save State Slot 5",
|
||||
"Load State Slot 5",
|
||||
"Save State Slot 6",
|
||||
"Load State Slot 6",
|
||||
"Save State Slot 7",
|
||||
"Load State Slot 7",
|
||||
"Save State Slot 8",
|
||||
"Load State Slot 8",
|
||||
"Save State Slot 9",
|
||||
"Load State Slot 9",
|
||||
"Save State Slot 10",
|
||||
"Load State Slot 10",
|
||||
}
|
||||
[configuration.hotkey_actions[index - 2]];
|
||||
}
|
||||
|
||||
static const struct menu_item joypad_menu[] = {
|
||||
{"Joypad:", cycle_joypads, current_joypad_name, cycle_joypads_backwards},
|
||||
{"Configure layout", detect_joypad_layout},
|
||||
{"Hotkey 1 Action:", cycle_hotkey, current_hotkey, cycle_hotkey_backwards},
|
||||
{"Hotkey 2 Action:", cycle_hotkey, current_hotkey, cycle_hotkey_backwards},
|
||||
{"Rumble Mode:", cycle_rumble_mode, current_rumble_mode, cycle_rumble_mode_backwards},
|
||||
{"Enable Control:", toggle_allow_background_controllers, current_background_control_mode, toggle_allow_background_controllers},
|
||||
{"Back", enter_controls_menu},
|
||||
|
@ -2015,6 +2068,8 @@ void run_gui(bool is_running)
|
|||
"Turbo",
|
||||
"Rewind",
|
||||
"Slow-Motion",
|
||||
"Hotkey 1",
|
||||
"Hotkey 2",
|
||||
"",
|
||||
} [joypad_configuration_progress],
|
||||
gui_palette_native[3], gui_palette_native[0], DECORATION_NONE);
|
||||
|
|
35
SDL/main.c
35
SDL/main.c
|
@ -271,6 +271,37 @@ static void handle_events(GB_gameboy_t *gb)
|
|||
else if (button == JOYPAD_BUTTON_MENU && event.type == SDL_JOYBUTTONDOWN) {
|
||||
open_menu();
|
||||
}
|
||||
else if ((button == JOYPAD_BUTTON_HOTKEY_1 || button == JOYPAD_BUTTON_HOTKEY_2) && event.type == SDL_JOYBUTTONDOWN) {
|
||||
hotkey_action_t action = configuration.hotkey_actions[button - JOYPAD_BUTTON_HOTKEY_1];
|
||||
switch (action) {
|
||||
case HOTKEY_NONE:
|
||||
break;
|
||||
case HOTKEY_PAUSE:
|
||||
paused = !paused;
|
||||
break;
|
||||
case HOTKEY_MUTE:
|
||||
GB_audio_set_paused(GB_audio_is_playing());
|
||||
break;
|
||||
case HOTKEY_RESET:
|
||||
pending_command = GB_SDL_RESET_COMMAND;
|
||||
break;
|
||||
case HOTKEY_QUIT:
|
||||
pending_command = GB_SDL_QUIT_COMMAND;
|
||||
break;
|
||||
default:
|
||||
command_parameter = (action - HOTKEY_SAVE_STATE_1) / 2 + 1;
|
||||
pending_command = ((action - HOTKEY_SAVE_STATE_1) % 2)? GB_SDL_LOAD_STATE_COMMAND:GB_SDL_SAVE_STATE_COMMAND;
|
||||
break;
|
||||
case HOTKEY_SAVE_STATE_10:
|
||||
command_parameter = 0;
|
||||
pending_command = GB_SDL_SAVE_STATE_COMMAND;
|
||||
break;
|
||||
case HOTKEY_LOAD_STATE_10:
|
||||
command_parameter = 0;
|
||||
pending_command = GB_SDL_LOAD_STATE_COMMAND;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -862,6 +893,10 @@ int main(int argc, char **argv)
|
|||
configuration.cgb_revision %= GB_MODEL_CGB_E - GB_MODEL_CGB_0 + 1;
|
||||
configuration.audio_driver[15] = 0;
|
||||
configuration.dmg_palette_name[24] = 0;
|
||||
// Fix broken defaults, should keys 12-31 should be unmapped by default
|
||||
if (configuration.joypad_configuration[31] == 0) {
|
||||
memset(configuration.joypad_configuration + 12 , -1, 32 - 12);
|
||||
}
|
||||
}
|
||||
|
||||
if (configuration.model >= MODEL_MAX) {
|
||||
|
|
Loading…
Reference in New Issue