X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=input.c;h=f01c53d189cc5e07a67708c57d1d8c4a4015b1ed;hb=refs%2Fheads%2Fmaster;hp=4b908bb2e320efdabbfb2645f81a8336d0763920;hpb=43c24b301dc8c0c5952e1d22bad865f4304d01f8;p=gpsp.git diff --git a/input.c b/input.c index 4b908bb..f01c53d 100644 --- a/input.c +++ b/input.c @@ -24,7 +24,6 @@ void trigger_key(u32 key) { u32 p1_cnt = io_registers[REG_P1CNT]; - u32 p1; if((p1_cnt >> 14) & 0x01) { @@ -454,7 +453,7 @@ u32 update_input() handled_buttons = (last_buttons ^ buttons) & buttons; last_buttons = buttons; - for(i = 0; i < 16; i++) + for(i = 0; i < PLAT_BUTTON_COUNT; i++) { if(handled_buttons & button_plat_mask_to_config[i]) button_id = gamepad_config_map[i]; @@ -474,7 +473,7 @@ u32 update_input() case BUTTON_ID_LOADSTATE: { - u8 current_savestate_filename[512]; + char current_savestate_filename[512]; get_savestate_filename_noshot(savestate_slot, current_savestate_filename); load_state(current_savestate_filename); @@ -483,7 +482,7 @@ u32 update_input() case BUTTON_ID_SAVESTATE: { - u8 current_savestate_filename[512]; + char current_savestate_filename[512]; u16 *current_screen = copy_screen(); get_savestate_filename_noshot(savestate_slot, current_savestate_filename); @@ -556,8 +555,49 @@ void init_input() #endif +#if defined(RPI_BUILD) -#ifdef PC_BUILD +u32 key_map(SDLKey key_sym) +{ + switch(key_sym) + { + case SDLK_a: + return BUTTON_L; + + case SDLK_s: + return BUTTON_R; + + case SDLK_DOWN: + return BUTTON_DOWN; + + case SDLK_UP: + return BUTTON_UP; + + case SDLK_LEFT: + return BUTTON_LEFT; + + case SDLK_RIGHT: + return BUTTON_RIGHT; + + case SDLK_RETURN: + return BUTTON_START; + + case SDLK_BACKSPACE: + return BUTTON_SELECT; + + case SDLK_x: + return BUTTON_B; + + case SDLK_z: + return BUTTON_A; + + default: + return BUTTON_NONE; + } +} +#endif + +#if defined(PC_BUILD) u32 key_map(SDLKey key_sym) { @@ -597,6 +637,8 @@ u32 key_map(SDLKey key_sym) return BUTTON_NONE; } } +#endif +#if defined(PC_BUILD) || defined(RPI_BUILD) u32 joy_map(u32 button) { @@ -608,16 +650,16 @@ u32 joy_map(u32 button) case 5: return BUTTON_R; - case 9: + case 2: return BUTTON_START; - case 8: + case 3: return BUTTON_SELECT; - case 0: + case 1: return BUTTON_B; - case 1: + case 0: return BUTTON_A; default: @@ -633,7 +675,7 @@ gui_action_type get_gui_input() delay_us(30000); while(SDL_PollEvent(&event)) - { + { switch(event.type) { case SDL_QUIT: @@ -670,12 +712,49 @@ gui_action_type get_gui_input() case SDLK_BACKSPACE: gui_action = CURSOR_BACK; break; - } - break; + default: + break; } } - } + break; +#ifdef RPI_BUILD + case SDL_JOYBUTTONDOWN: + { + switch (event.jbutton.button) + { + case 2: + gui_action = CURSOR_BACK; + break; + + case 1: + gui_action = CURSOR_EXIT; + break; + + case 0: + gui_action = CURSOR_SELECT; + break; + } + } + break; + + case SDL_JOYAXISMOTION: + { + if (event.jaxis.axis==0) { //Left-Right + if (event.jaxis.value < -3200) gui_action = CURSOR_LEFT; + else if (event.jaxis.value > 3200) gui_action = CURSOR_RIGHT; + } + if (event.jaxis.axis==1) { //Up-Down + if (event.jaxis.value < -3200) gui_action = CURSOR_UP; + else if (event.jaxis.value > 3200) gui_action = CURSOR_DOWN; + } + } + break; +#endif + default: + break; + } + } return gui_action; } @@ -696,8 +775,11 @@ u32 update_input() { quit(); } - +#ifdef PC_BUILD if(event.key.keysym.sym == SDLK_BACKSPACE) +#else + if(event.key.keysym.sym == SDLK_F10) +#endif { u16 *screen_copy = copy_screen(); u32 ret_val = menu(screen_copy); @@ -706,7 +788,7 @@ u32 update_input() return ret_val; } else - +#ifdef PC_BUILD if(event.key.keysym.sym == SDLK_F1) { debug_on(); @@ -739,10 +821,10 @@ u32 update_input() dump_translation_cache(); } else - +#endif if(event.key.keysym.sym == SDLK_F5) { - u8 current_savestate_filename[512]; + char current_savestate_filename[512]; u16 *current_screen = copy_screen(); get_savestate_filename_noshot(savestate_slot, current_savestate_filename); @@ -753,7 +835,7 @@ u32 update_input() if(event.key.keysym.sym == SDLK_F7) { - u8 current_savestate_filename[512]; + char current_savestate_filename[512]; get_savestate_filename_noshot(savestate_slot, current_savestate_filename); load_state(current_savestate_filename); @@ -793,6 +875,22 @@ u32 update_input() key &= ~(joy_map(event.jbutton.button)); break; } +#ifdef RPI_BUILD + case SDL_JOYAXISMOTION: + { + if (event.jaxis.axis==0) { //Left-Right + key &= ~(BUTTON_LEFT|BUTTON_RIGHT); + if (event.jaxis.value < -3200) key |= BUTTON_LEFT; + else if (event.jaxis.value > 3200) key |= BUTTON_RIGHT; + } + if (event.jaxis.axis==1) { //Up-Down + key &= ~(BUTTON_UP|BUTTON_DOWN); + if (event.jaxis.value < -3200) key |= BUTTON_UP; + else if (event.jaxis.value > 3200) key |= BUTTON_DOWN; + } + break; +#endif + } } }