Browse Source

Add full set of alternate button mappings

v2
Nathaniel Walizer 7 months ago
parent
commit
086d8e4395
1 changed files with 16 additions and 10 deletions
  1. +16
    -10
      src/linux/port.c

+ 16
- 10
src/linux/port.c View File

@@ -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;


Loading…
Cancel
Save