| @@ -140,7 +140,7 @@ static const int sdl_action_keycodes[Action_Max] = { | |||||
| [Action_Turbo] = SDLK_t, | [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_a, | ||||
| SDLK_s, | SDLK_s, | ||||
| SDLK_q, | SDLK_q, | ||||
| @@ -149,9 +149,16 @@ static const int sdl_button_keycodes[nes_controller_num_buttons] = { | |||||
| SDLK_DOWN, | SDLK_DOWN, | ||||
| SDLK_LEFT, | SDLK_LEFT, | ||||
| SDLK_RIGHT, | 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) { | static int keycode_index(int keycode, const int* codes, int n_codes) { | ||||
| int index = n_codes - 1; | int index = n_codes - 1; | ||||
| @@ -173,14 +180,13 @@ static nese_Action process_events(nes* sys) { | |||||
| SDL_KEYUP == event.type) && | SDL_KEYUP == event.type) && | ||||
| 0 == event.key.repeat | 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) { | if (index >= 0) { | ||||
| index %= nes_controller_num_buttons; | |||||
| uint8_t mask = (1 << index); | uint8_t mask = (1 << index); | ||||
| if (SDL_KEYDOWN == event.type) { | if (SDL_KEYDOWN == event.type) { | ||||
| input->gamepads[0].buttons |= mask; | input->gamepads[0].buttons |= mask; | ||||