diff --git a/src/inputdevice.cpp b/src/inputdevice.cpp index 5dac72ab..d1770150 100644 --- a/src/inputdevice.cpp +++ b/src/inputdevice.cpp @@ -278,10 +278,10 @@ uae_u16 JOY0DAT (void) { update_mouse_xy(); #ifdef RASPBERRY - if (currprefs.pandora_custom_dpad == 0) - return joy0dir; if (currprefs.pandora_custom_dpad == 1) return ((uae_u8)mouse_x) | ((uae_u16)mouse_y << 8); + else + return joy0dir; #else return ((uae_u8)mouse_x) + ((uae_u16)mouse_y << 8) + joy0dir; #endif diff --git a/src/od-pandora/joystick.cpp b/src/od-pandora/joystick.cpp index 74095ef7..8557692d 100644 --- a/src/od-pandora/joystick.cpp +++ b/src/od-pandora/joystick.cpp @@ -74,32 +74,63 @@ void read_joystick(int nr, unsigned int *dir, int *button) } else *button = 0; - + +#ifndef RASPBERRY if(currprefs.pandora_joyPort != 0) { // Only one joystick active if((nr == 0 && currprefs.pandora_joyPort == 2) || (nr == 1 && currprefs.pandora_joyPort == 1)) return; } +#endif *dir = 0; SDL_JoystickUpdate (); - #ifdef RASPBERRY - // Always check joystick state on Raspberry pi. - #else + + if (nr != 1) + { + // get joystick direction via joystick or Hat + int hat = SDL_JoystickGetHat(joy,0); + int val = SDL_JoystickGetAxis(joy, 0); + if ((hat & SDL_HAT_RIGHT) || (val > 6000)) right=1; + if ((hat & SDL_HAT_LEFT) || (val < -6000)) left=1; + val = SDL_JoystickGetAxis(joy, 1); + if ((hat & SDL_HAT_UP) || (val < -6000)) top=1; + if ((hat & SDL_HAT_DOWN) || (val > 6000)) bot=1; + + *button |= (SDL_JoystickGetButton(joy, 0)) & 1; + *button |= ((SDL_JoystickGetButton(joy, 1)) & 1) << 1; + + #ifdef SIX_AXIS_WORKAROUND + *button |= (SDL_JoystickGetButton(joy, 13)) & 1; + *button |= ((SDL_JoystickGetButton(joy, 14)) & 1) << 1; + + if ( SDL_JoystickGetButton(joy, 4)) top =1; + if ( SDL_JoystickGetButton(joy, 5)) right=1; + if ( SDL_JoystickGetButton(joy, 6)) bot =1; + if ( SDL_JoystickGetButton(joy, 7)) left =1; + #endif + + // Go over custom management which is only available for first joystick. + goto no_custom; + } + + +#ifdef PANDORA_SPECIFIC if (!triggerR /*R+dpad = arrow keys*/ && currprefs.pandora_custom_dpad==0) - #endif +#endif { - // get joystick direction via dPad or joystick - int hat=SDL_JoystickGetHat(joy,0); + // get joystick direction via dPad or joystick or Hat + int hat = SDL_JoystickGetHat(joy,0); int val = SDL_JoystickGetAxis(joy, 0); if (((hat & SDL_HAT_RIGHT) && currprefs.pandora_custom_dpad < 2) || (dpadRight && currprefs.pandora_custom_dpad < 2) || val > 6000) right=1; if (((hat & SDL_HAT_LEFT) && currprefs.pandora_custom_dpad < 2) || (dpadLeft && currprefs.pandora_custom_dpad < 2) || val < -6000) left=1; val = SDL_JoystickGetAxis(joy, 1); if (((hat & SDL_HAT_UP) && currprefs.pandora_custom_dpad < 2) || (dpadUp && currprefs.pandora_custom_dpad < 2) || val < -6000) top=1; if (((hat & SDL_HAT_DOWN) && currprefs.pandora_custom_dpad < 2) || (dpadDown && currprefs.pandora_custom_dpad < 2) || val > 6000) bot=1; + if (currprefs.pandora_joyConf) { if ((buttonX && currprefs.pandora_jump > -1) || SDL_JoystickGetButton(joy, currprefs.pandora_jump)) @@ -107,6 +138,8 @@ void read_joystick(int nr, unsigned int *dir, int *button) } } + + if(currprefs.pandora_customControls) { // get joystick direction via custom keys @@ -143,6 +176,7 @@ void read_joystick(int nr, unsigned int *dir, int *button) } } + if(currprefs.pandora_custom_dpad == 0) // dPad as joystick { // Handle autofire (only available if no custom controls active) @@ -200,6 +234,7 @@ void read_joystick(int nr, unsigned int *dir, int *button) } + #ifdef RASPBERRY if(!currprefs.pandora_customControls || currprefs.pandora_custom_A == 0) *button |= (SDL_JoystickGetButton(joy, 0)) & 1; @@ -216,6 +251,8 @@ void read_joystick(int nr, unsigned int *dir, int *button) if (!currprefs.pandora_customControls && SDL_JoystickGetButton(joy, 7)) left=1; #endif +no_custom: + // normal joystick movement if (left) top = !top; diff --git a/src/od-pandora/pandora.cpp b/src/od-pandora/pandora.cpp index dd596eb5..14e23022 100644 --- a/src/od-pandora/pandora.cpp +++ b/src/od-pandora/pandora.cpp @@ -1091,6 +1091,9 @@ void handle_events (void) break; case SDL_JOYBUTTONDOWN: /* Handle Joystick Button Presses */ + // Handle custom only for first joystick + if (rEvent.jbutton.which != 0) + break; if (rEvent.jbutton.button == 8) JoystickQuit[0] = 1; //Next if statements are for buttons 8 & 9 together to quit emulator if (rEvent.jbutton.button == 9) JoystickQuit[1] = 1; if (JoystickQuit[0] && JoystickQuit[1]) @@ -1106,6 +1109,9 @@ void handle_events (void) break; case SDL_JOYBUTTONUP: /* Handle Joystick Button Releases */ + // Handle custom only for first joystick + if (rEvent.jbutton.which != 0) + break; if (rEvent.jbutton.button == 8) JoystickQuit[0] = 0; if (rEvent.jbutton.button == 9) JoystickQuit[1] = 0; if (rEvent.jbutton.button > 5 && currprefs.pandora_custom_dpad < 3) break; //Ignore buttons num above 5 if Custom DPad is not on special @@ -1116,6 +1122,9 @@ void handle_events (void) if (currprefs.pandora_custom_dpad == 2 ) { case SDL_JOYHATMOTION: + // Handle custom only for first joystick + if (rEvent.jbutton.which != 0) + break; if (rEvent.jhat.value & SDL_HAT_UP) JoystickButton[6] = 1; else JoystickButton[6] = 0; if (rEvent.jhat.value & SDL_HAT_DOWN) JoystickButton[7] = 1; else JoystickButton[7] = 0; if (rEvent.jhat.value & SDL_HAT_LEFT) JoystickButton[8] = 1; else JoystickButton[8] = 0;