Skip to content

Commit

Permalink
Vita: - added two player support on Vita TV, second paired Dualshock …
Browse files Browse the repository at this point in the history
…controller controls the 'other' joystick, only works if ports is not set to 'both' - fixed a crash bug when changing audio parameters while sound was playing
  • Loading branch information
rsn8887 committed Jan 9, 2017
1 parent cab6a62 commit 883fe4a
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 41 deletions.
43 changes: 41 additions & 2 deletions src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ int rAnalogXCenter=0;
int rAnalogYCenter=0;
int haveJoysticksBeenCentered=0;
extern int mainMenu_leftStickMouse;
//Rudimentary second Player support for Vita TV
int lAnalogXPly2=0;
int lAnalogYPly2=0;
int dpadUpPly2=0;
int dpadDownPly2=0;
int dpadLeftPly2=0;
int dpadRightPly2=0;
int buttonAPly2=0;
int buttonBPly2=0;
int buttonXPly2=0;
int buttonYPly2=0;
int triggerLPly2=0;
int triggerRPly2=0;
int buttonSelectPly2=0;
int buttonStartPly2=0;
#endif // __PSP2__

#ifdef USE_UAE4ALL_VKBD
Expand Down Expand Up @@ -532,7 +547,7 @@ void gui_handle_events (void)
Uint8 *keystate = SDL_GetKeyState(NULL);
#ifdef __PSP2__
SDL_JoystickUpdate();

// Main Controller
//On Vita, always use either the left of right analog for mouse pointer movement
//the other stick replicates the dpad inputs
lAnalogX=SDL_JoystickGetAxis(uae4all_joy0, 0);
Expand Down Expand Up @@ -578,7 +593,7 @@ void gui_handle_events (void)
dpadDown = SDL_JoystickGetButton(uae4all_joy0, 6)
|| (lAnalogY > 1024*10) ? 1 : 0;
}

buttonA = SDL_JoystickGetButton(uae4all_joy0, PAD_SQUARE);
buttonB = SDL_JoystickGetButton(uae4all_joy0, PAD_CIRCLE);
buttonX = SDL_JoystickGetButton(uae4all_joy0, PAD_CROSS);
Expand All @@ -598,6 +613,30 @@ void gui_handle_events (void)
rAnalogYCenter=SDL_JoystickGetAxis(uae4all_joy0, 3);
goMenu();
}

// Second paired Controller for two players,
// only rudimentary mapping for now for two player games
// with Vita TV.
lAnalogXPly2=SDL_JoystickGetAxis(uae4all_joy1, 0);
lAnalogYPly2=SDL_JoystickGetAxis(uae4all_joy1, 1);

dpadRightPly2 = SDL_JoystickGetButton(uae4all_joy1, 9)
|| (lAnalogXPly2 > 1024*10) ? 1 : 0;
dpadLeftPly2 = SDL_JoystickGetButton(uae4all_joy1, 7)
|| (lAnalogXPly2 < -1024*10) ? 1 : 0;
dpadUpPly2 = SDL_JoystickGetButton(uae4all_joy1, 8)
|| (lAnalogYPly2 < -1024*10) ? 1 : 0;
dpadDownPly2 = SDL_JoystickGetButton(uae4all_joy1, 6)
|| (lAnalogYPly2 > 1024*10) ? 1 : 0;

buttonAPly2 = SDL_JoystickGetButton(uae4all_joy1, PAD_SQUARE);
buttonBPly2 = SDL_JoystickGetButton(uae4all_joy1, PAD_CIRCLE);
buttonXPly2 = SDL_JoystickGetButton(uae4all_joy1, PAD_CROSS);
buttonYPly2 = SDL_JoystickGetButton(uae4all_joy1, PAD_TRIANGLE);
triggerLPly2 = SDL_JoystickGetButton(uae4all_joy1, PAD_L);
triggerRPly2 = SDL_JoystickGetButton(uae4all_joy1, PAD_R);
buttonSelectPly2 = SDL_JoystickGetButton(uae4all_joy1, PAD_SELECT);
buttonStartPly2 = SDL_JoystickGetButton(uae4all_joy1, PAD_START);
#else
dpadUp = keystate[SDLK_UP];
dpadDown = keystate[SDLK_DOWN];
Expand Down
142 changes: 110 additions & 32 deletions src/od-joy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ extern int lAnalogX;
extern int lAnalogY;
extern int mainMenu_leftStickMouse;
extern int mainMenu_deadZone;
extern int lAnalogXPly2;
extern int lAnalogYPly2;
extern int dpadUpPly2;
extern int dpadDownPly2;
extern int dpadLeftPly2;
extern int dpadRightPly2;
extern int buttonAPly2;
extern int buttonBPly2;
extern int buttonXPly2;
extern int buttonYPly2;
extern int triggerLPly2;
extern int triggerRPly2;
extern int buttonSelectPly2;
extern int buttonStartPly2;
#endif

extern char launchDir[300];
Expand All @@ -82,6 +96,9 @@ void read_joystick(int nr, unsigned int *dir, int *button)

nr = (~nr)&0x1;

// are we trying to figure out the regular GP2X controls for the primary (or both) joysticks?
int usingRegularControls = (!mainMenu_customControls) && ((mainMenu_joyPort == 0) || (nr == 1 && mainMenu_joyPort == 2) || (nr == 0 && mainMenu_joyPort == 1));

SDL_JoystickUpdate ();
/* Temporary disabled
#ifdef ANDROIDSDL
Expand All @@ -104,6 +121,7 @@ void read_joystick(int nr, unsigned int *dir, int *button)
if (mouseScale > (99*16))
mouseScale /= 100;

//Digital mouseemu hotkeys: Triangle changes mouse speed etc.
#if !defined(__PSP2__) && defined(USE_UAE4ALL_VKBD)
if (!vkbd_mode && ((mainMenu_customControls && mainMenu_custom_dpad==2) || gp2xMouseEmuOn || (triggerL && !triggerR && !gp2xButtonRemappingOn)))
#else
Expand Down Expand Up @@ -161,8 +179,9 @@ void read_joystick(int nr, unsigned int *dir, int *button)
newmousecounters=1;
}
}
else if (!triggerR /*R+dpad = arrow keys*/ && !(mainMenu_customControls && !mainMenu_custom_dpad))
else if (!triggerR /*R+dpad = arrow keys*/ && !(mainMenu_customControls && mainMenu_custom_dpad==0) && usingRegularControls)
{
//regular direction controls for main Joystick (or both if "both" is set.)
#if !defined(AROS) && !defined(__PSP2__)
if (dpadRight || SDL_JoystickGetAxis(joy, 0) > 0) right=1;
if (dpadLeft || SDL_JoystickGetAxis(joy, 0) < 0) left=1;
Expand All @@ -185,7 +204,60 @@ void read_joystick(int nr, unsigned int *dir, int *button)
top = 1;
}
}

// regular button controls without custom remapping
#ifdef USE_UAE4ALL_VKBD
if (usingRegularControls && !(gp2xMouseEmuOn) && !(gp2xButtonRemappingOn) && !vkbd_mode)
#else
if (usingRegularControls && !(gp2xMouseEmuOn) && !(gp2xButtonRemappingOn))
#endif
{
if (
(mainMenu_autofire & switch_autofire & delay>mainMenu_autofireRate)
||
(
(
(mainMenu_autofireButton1==GP2X_BUTTON_B && buttonA)
||
(mainMenu_autofireButton1==GP2X_BUTTON_X && buttonX)
||
(mainMenu_autofireButton1==GP2X_BUTTON_Y && buttonY)
)
& delay>mainMenu_autofireRate
)
)
{
if(!buttonB)
*button=1;
delay=0;
*button |= (buttonB & 1) << 1;
}
else
{
#ifdef __PSP2__
*button = ((mainMenu_button1==GP2X_BUTTON_B && buttonA) || (mainMenu_button1==GP2X_BUTTON_X && buttonX) || (mainMenu_button1==GP2X_BUTTON_Y && buttonY)) & 1;
#else
#if !(defined(ANDROIDSDL) || defined(AROS))
*button = ((mainMenu_button1==GP2X_BUTTON_B && buttonA) || (mainMenu_button1==GP2X_BUTTON_X && buttonX) || (mainMenu_button1==GP2X_BUTTON_Y && buttonY) || SDL_JoystickGetButton(joy, mainMenu_button1)) & 1;
#else
*button = ((mainMenu_button1==GP2X_BUTTON_B && buttonA) || (mainMenu_button1==GP2X_BUTTON_X && buttonX) || (mainMenu_button1==GP2X_BUTTON_Y && buttonY)) & 1;
#endif
#endif //__PSP2__
delay++;
#ifdef __PSP2__
*button |= ((buttonB) & 1) << 1;
#else
#if defined(PANDORA) && !defined(AROS)
*button |= ((buttonB || SDL_JoystickGetButton(joy, mainMenu_button2)) & 1) << 1;
#else
*button |= ((buttonB) & 1) << 1;
#endif
#endif //__PSP2__
}
}


//Analog Mouse
#ifdef USE_UAE4ALL_VKBD
if (!vkbd_mode) {
#endif
Expand Down Expand Up @@ -230,6 +302,7 @@ void read_joystick(int nr, unsigned int *dir, int *button)
if(mainMenu_customControls)
#endif
{
// The main Joystick mapping directions
if ((mainMenu_joyPort == 0) || (nr == 1 && mainMenu_joyPort == 2) || (nr == 0 && mainMenu_joyPort == 1))
{
if((mainMenu_custom_A==-5 && buttonA) || (mainMenu_custom_B==-5 && buttonB) || (mainMenu_custom_X==-5 && buttonX) || (mainMenu_custom_Y==-5 && buttonY) || (mainMenu_custom_L==-5 && triggerL) || (mainMenu_custom_R==-5 && triggerR))
Expand Down Expand Up @@ -264,6 +337,7 @@ void read_joystick(int nr, unsigned int *dir, int *button)
right = 1;
}
}
// The "other" (second) Joystick mapping directions
else if ((nr == 0 && mainMenu_joyPort == 2) || (nr == 1 && mainMenu_joyPort == 1))
{
if((mainMenu_custom_A==-9 && buttonA) || (mainMenu_custom_B==-9 && buttonB) || (mainMenu_custom_X==-9 && buttonX) || (mainMenu_custom_Y==-9 && buttonY) || (mainMenu_custom_L==-9 && triggerL) || (mainMenu_custom_R==-9 && triggerR))
Expand Down Expand Up @@ -302,19 +376,13 @@ void read_joystick(int nr, unsigned int *dir, int *button)

if(!gp2xMouseEmuOn && !gp2xButtonRemappingOn)
{
if(!mainMenu_customControls && ((mainMenu_autofire & switch_autofire & delay>mainMenu_autofireRate) || (((mainMenu_autofireButton1==GP2X_BUTTON_B && buttonA) || (mainMenu_autofireButton1==GP2X_BUTTON_X && buttonX) || (mainMenu_autofireButton1==GP2X_BUTTON_Y && buttonY)) & delay>mainMenu_autofireRate)))
{
if(!buttonB)
*button=1;
delay=0;
*button |= (buttonB & 1) << 1;
}
#ifdef USE_UAE4ALL_VKBD
else if(mainMenu_customControls && !vkbd_mode)
if(mainMenu_customControls && !vkbd_mode)
#else
else if(mainMenu_customControls)
if(mainMenu_customControls)
#endif
{
//The main joystick mapping buttons
if ((mainMenu_joyPort == 0) || (nr == 1 && mainMenu_joyPort == 2) || (nr == 0 && mainMenu_joyPort == 1))
{
if((mainMenu_custom_A==-3 && buttonA) || (mainMenu_custom_B==-3 && buttonB) || (mainMenu_custom_X==-3 && buttonX) || (mainMenu_custom_Y==-3 && buttonY) || (mainMenu_custom_L==-3 && triggerL) || (mainMenu_custom_R==-3 && triggerR))
Expand All @@ -324,7 +392,6 @@ void read_joystick(int nr, unsigned int *dir, int *button)
if((mainMenu_custom_up==-3 && dpadUp) || (mainMenu_custom_down==-3 && dpadDown) || (mainMenu_custom_left==-3 && dpadLeft) || (mainMenu_custom_right==-3 && dpadRight))
*button = 1;
}

if((mainMenu_custom_A==-4 && buttonA) || (mainMenu_custom_B==-4 && buttonB) || (mainMenu_custom_X==-4 && buttonX) || (mainMenu_custom_Y==-4 && buttonY) || (mainMenu_custom_L==-4 && triggerL) || (mainMenu_custom_R==-4 && triggerR))
*button |= 1 << 1;
else if(mainMenu_custom_dpad == 0)
Expand All @@ -333,6 +400,7 @@ void read_joystick(int nr, unsigned int *dir, int *button)
*button |= 1 << 1;
}
}
//The "other" (second) joystick buttons
else if ((nr == 0 && mainMenu_joyPort == 2) || (nr == 1 && mainMenu_joyPort == 1))
{
if((mainMenu_custom_A==-1 && buttonA) || (mainMenu_custom_B==-1 && buttonB) || (mainMenu_custom_X==-1 && buttonX) || (mainMenu_custom_Y==-1 && buttonY) || (mainMenu_custom_L==-1 && triggerL) || (mainMenu_custom_R==-1 && triggerR))
Expand All @@ -353,22 +421,8 @@ void read_joystick(int nr, unsigned int *dir, int *button)
}
delay++;
}
else
{
#if !(defined(ANDROIDSDL) || defined(AROS))
*button = ((mainMenu_button1==GP2X_BUTTON_B && buttonA) || (mainMenu_button1==GP2X_BUTTON_X && buttonX) || (mainMenu_button1==GP2X_BUTTON_Y && buttonY) || SDL_JoystickGetButton(joy, mainMenu_button1)) & 1;
#else
*button = ((mainMenu_button1==GP2X_BUTTON_B && buttonA) || (mainMenu_button1==GP2X_BUTTON_X && buttonX) || (mainMenu_button1==GP2X_BUTTON_Y && buttonY)) & 1;
#endif
delay++;
#if defined(PANDORA) && !defined(AROS)
*button |= ((buttonB || SDL_JoystickGetButton(joy, mainMenu_button2)) & 1) << 1;
#else
*button |= ((buttonB) & 1) << 1;
#endif
}
}

#ifdef USE_UAE4ALL_VKBD
if (vkbd_mode && nr)
{
Expand Down Expand Up @@ -476,12 +530,32 @@ void read_joystick(int nr, unsigned int *dir, int *button)
else
#endif
{
// normal joystick movement
if (left) top = !top;
if (right) bot = !bot;
*dir = bot | (right << 1) | (top << 8) | (left << 9);
}
#ifdef __PSP2__
// On Vita, map the second player to always using the GP2X mapping, in addition to everything else
if((nr == 0 && mainMenu_joyPort == 2) || (nr == 1 && mainMenu_joyPort == 1))
{
if (dpadRightPly2)
right = 1;
else if (dpadLeftPly2)
left = 1;
if (dpadUpPly2)
top = 1;
else if (dpadDownPly2)
bot = 1;
if ((mainMenu_button1==GP2X_BUTTON_B && buttonAPly2) || (mainMenu_button1==GP2X_BUTTON_X && buttonXPly2) || (mainMenu_button1==GP2X_BUTTON_Y && buttonYPly2))
*button |= 0x01;
if (buttonBPly2)
*button |= (0x01 << 1);
}
#endif //__PSP2__
// normal joystick movement
if (left) top = !top;
if (right) bot = !bot;
*dir = bot | (right << 1) | (top << 8) | (left << 9);
}

#ifndef __PSP2__
//If not on Vita, zero the "other" joystick
if (!mainMenu_customControls)
{
if(mainMenu_joyPort != 0)
Expand All @@ -494,9 +568,13 @@ void read_joystick(int nr, unsigned int *dir, int *button)
}
}
}
#endif


#endif //__PSP2__
#endif // MAXAUTOEVENTS
}


void init_joystick(void)
{
int i;
Expand Down
14 changes: 10 additions & 4 deletions src/psp2/psp2_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,19 @@ int PSP2_PollEvent(SDL_Event *event) {
break;

case SDL_JOYBUTTONDOWN:
event->type = SDL_KEYDOWN;
event->key.keysym.sym = getKey(event->jbutton.button);
if (event->jbutton.which==0) // Only Joystick 0 controls the menu
{
event->type = SDL_KEYDOWN;
event->key.keysym.sym = getKey(event->jbutton.button);
}
break;

case SDL_JOYBUTTONUP:
event->type = SDL_KEYUP;
event->key.keysym.sym = getKey(event->jbutton.button);
if (event->jbutton.which==0)
{
event->type = SDL_KEYUP;
event->key.keysym.sym = getKey(event->jbutton.button);
}
break;

default:
Expand Down
14 changes: 11 additions & 3 deletions src/sound_sdl_new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ unsigned n_callback_sndbuff, n_render_sndbuff;
uae_u16 *sndbufpt = sndbuffer[0];
uae_u16 *render_sndbuff = sndbuffer[0];

extern void gp2x_stop_sound();

#ifdef NO_SOUND


Expand Down Expand Up @@ -144,9 +146,15 @@ static int gp2x_start_sound(int rate, int bits, int stereo)
if( audioOpened ) {
// __android_log_print(ANDROID_LOG_INFO, "UAE4ALL2", "UAE tries to open SDL sound device 2 times, ignoring that.");
#ifdef __PSP2__
//this allows the user to change sound settings on the fly
//without having to save config and restart
SDL_CloseAudio();
//this allows the user to change sound settings on the fly
//without having to save config and restart
//safely stop sound
SDL_PauseAudio(1);
sound_thread_exit = 1;
uae_sem_post(&sound_sem);
SDL_Delay(333);
SDL_CloseAudio();
sound_thread_exit=0;
#else
return 0;
#endif
Expand Down

0 comments on commit 883fe4a

Please sign in to comment.