From 086d8e43953ac264638abcac88865ac22b2df59a Mon Sep 17 00:00:00 2001 From: Nathaniel Walizer Date: Tue, 22 Apr 2025 00:05:57 -0700 Subject: [PATCH] Add full set of alternate button mappings --- src/linux/port.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/linux/port.c b/src/linux/port.c index 1cfd7af..665839c 100644 --- a/src/linux/port.c +++ b/src/linux/port.c @@ -140,7 +140,7 @@ static const int sdl_action_keycodes[Action_Max] = { [Action_Turbo] = SDLK_t, }; -static const int sdl_button_keycodes[nes_controller_num_buttons] = { +static const int sdl_button_keycodes[2 * nes_controller_num_buttons] = { SDLK_a, SDLK_s, SDLK_q, @@ -149,9 +149,16 @@ static const int sdl_button_keycodes[nes_controller_num_buttons] = { SDLK_DOWN, SDLK_LEFT, SDLK_RIGHT, -}; -#define sdl_alt_start_key (SDLK_RETURN) + SDLK_LCTRL, + SDLK_LALT, + SDLK_TAB, + SDLK_RETURN, + SDLK_KP_8, + SDLK_KP_2, + SDLK_KP_4, + SDLK_KP_6, +}; static int keycode_index(int keycode, const int* codes, int n_codes) { int index = n_codes - 1; @@ -173,14 +180,13 @@ static nese_Action process_events(nes* sys) { SDL_KEYUP == event.type) && 0 == event.key.repeat ) { - int index = ( sdl_alt_start_key == - event.key.keysym.sym) ? - Button_Start : keycode_index( - event.key.keysym.sym, - sdl_button_keycodes, - nes_controller_num_buttons - ); + int index = keycode_index( + event.key.keysym.sym, + sdl_button_keycodes, + 2 * nes_controller_num_buttons + ); if (index >= 0) { + index %= nes_controller_num_buttons; uint8_t mask = (1 << index); if (SDL_KEYDOWN == event.type) { input->gamepads[0].buttons |= mask;