Skip to content

Commit

Permalink
VITA: -added analog joystick deadzone setting
Browse files Browse the repository at this point in the history
- implemented autocentering to fix mouse pointer drift on some Vitas
- START+DPAD left/right for quick switching between different zoomed screenmodes, useful for games like Chaos Engine.
(Use START+DPAD up/down to center screen after quick switching)
  • Loading branch information
rsn8887 committed Dec 22, 2016
1 parent a2dac27 commit 515c939
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 40 deletions.
13 changes: 6 additions & 7 deletions Readme.txt
Expand Up @@ -32,15 +32,14 @@ Files must be named as kick13.rom kick20.rom kick31.rom

Vita Controls:

A=square
B=circle
X=cross
Y=triangle

Vita controls:
square=A
circle=B
cross=X
triangle=Y

Select = toggle menu
Start+dpad = move screen
Start+dpad up/down = move screen up down
Start+dpad left/right = change screenmode (to zoom in on games with borders)
right analog stick = analog mouse (can switch this to left in menu)
left analog stick = acts as amiga joystick

Expand Down
12 changes: 7 additions & 5 deletions src/gp2x/menu/menu_config.cpp
Expand Up @@ -93,7 +93,9 @@ int visibleAreaWidth = 320;
int saveMenu_n_savestate = 0;

#ifdef __PSP2__
int mainMenu_shader = 5;
int mainMenu_leftStickMouse = 0;
int mainMenu_deadZone = 100;
#endif

// The following params in use, but can't be changed with gui
Expand All @@ -103,10 +105,6 @@ int mainMenu_button2 = GP2X_BUTTON_A;
int mainMenu_autofireButton1 = GP2X_BUTTON_B;
int mainMenu_jump = -1;

#ifdef __PSP2__
int mainMenu_shader = 5;
#endif

// The following params not in use, but stored to write them back to the config file
int gp2xClockSpeed = -1;
int mainMenu_scanlines = 0;
Expand Down Expand Up @@ -222,6 +220,7 @@ void SetDefaultMenuSettings(int general)
#ifdef __PSP2__
mainMenu_shader = 5;
mainMenu_leftStickMouse = 0;
mainMenu_deadZone = 100;
#endif

// The following params can't be changed in gui
Expand Down Expand Up @@ -810,6 +809,8 @@ int saveconfig(int general)
fputs(buffer,f);
snprintf((char*)buffer, 255, "leftstickmouse=%d\n",mainMenu_leftStickMouse);
fputs(buffer,f);
snprintf((char*)buffer, 255, "deadzone=%d\n",mainMenu_deadZone);
fputs(buffer,f);
#endif
snprintf((char*)buffer, 255, "showstatus=%d\n",mainMenu_showStatus);
fputs(buffer,f);
Expand Down Expand Up @@ -1110,7 +1111,8 @@ void loadconfig(int general)
#endif
#ifdef __PSP2__
fscanf(f,"shader=%d\n",&mainMenu_shader);
fscanf(f,"leftstickmouse=%d\n",&mainMenu_leftStickMouse);
fscanf(f,"leftstickmouse=%d\n",&mainMenu_leftStickMouse);
fscanf(f,"deadzone=%d\n",&mainMenu_deadZone);
#endif
fscanf(f,"showstatus=%d\n",&mainMenu_showStatus);
fscanf(f,"mousemultiplier=%d\n",&mainMenu_mouseMultiplier );
Expand Down
1 change: 1 addition & 0 deletions src/gp2x/menu/menu_config.h
Expand Up @@ -106,4 +106,5 @@ extern char custom_kickrom[256];
#ifdef __PSP2__
extern int mainMenu_leftStickMouse;
extern int mainMenu_shader;
extern int mainMenu_deadZone;
#endif
50 changes: 48 additions & 2 deletions src/gp2x/menu/menu_misc.cpp
Expand Up @@ -73,7 +73,11 @@ enum {
MENUMISC_STATUSLINE,
MENUMISC_MOUSEMULTIPLIER,
MENUMISC_STYLUSOFFSET,
#ifdef __PSP2__
MENUMISC_DEADZONE,
#else
MENUMISC_TAPDELAY,
#endif
MENUMISC_END
};

Expand Down Expand Up @@ -371,7 +375,18 @@ static void draw_miscMenu(int c)
if ((mainMenu_stylusOffset==16)&&((menuMisc!=MENUMISC_STYLUSOFFSET)||(bb)))
write_text_inv(tabstop9,menuLine,text_str_8px);
else
write_text(tabstop9,menuLine,text_str_8px);
write_text(tabstop9,menuLine,text_str_8px);
#ifdef __PSP2__
//Analog Stick Deadzone settings on Vita
//MENUMISC_DEADZONE
menuLine+=2;
write_text(leftMargin,menuLine,"Mouse Deadzone");
snprintf((char*)cpuSpeed, 8, "%d", mainMenu_deadZone);
if ((menuMisc!=MENUMISC_DEADZONE)||(bb))
write_text_inv(tabstop3-2,menuLine,cpuSpeed);
else
write_text(tabstop3-2,menuLine,cpuSpeed);
#else
// MENUMISC_TAPDELAY
menuLine+=2;
write_text(leftMargin,menuLine,text_str_tap_delay);
Expand All @@ -390,7 +405,7 @@ static void draw_miscMenu(int c)
write_text_inv(tabstop9,menuLine,text_str_none);
else
write_text(tabstop9,menuLine,text_str_none);

#endif
menuLine++;
write_text(leftMargin,menuLine,text_str_misc_separator);
menuLine++;
Expand Down Expand Up @@ -645,6 +660,36 @@ static int key_miscMenu(int *c)
mainMenu_stylusOffset = 0;
}
break;
#ifdef __PSP2__
case MENUMISC_DEADZONE:
if (left)
{
if (mainMenu_deadZone <= 0)
mainMenu_deadZone=0;
else if (mainMenu_deadZone >= 2000)
mainMenu_deadZone-=1000;
else if (mainMenu_deadZone >= 200)
mainMenu_deadZone-=100;
else if (mainMenu_deadZone >= 20)
mainMenu_deadZone-=10;
else if (mainMenu_deadZone >= 1)
mainMenu_deadZone-=1;
}
else if (right)
{
if (mainMenu_deadZone >= 10000)
mainMenu_deadZone=10000;
else if (mainMenu_deadZone>=1000)
mainMenu_deadZone+=1000;
else if (mainMenu_deadZone>=100)
mainMenu_deadZone+=100;
else if (mainMenu_deadZone>=10)
mainMenu_deadZone+=10;
else if (mainMenu_deadZone>=0)
mainMenu_deadZone+=1;
}
break;
#else
case MENUMISC_TAPDELAY:
if (left)
{
Expand All @@ -665,6 +710,7 @@ static int key_miscMenu(int *c)
mainMenu_tapDelay = 10;
}
break;
#endif
}
}

Expand Down
111 changes: 102 additions & 9 deletions src/gui.cpp
Expand Up @@ -74,6 +74,45 @@ extern SDL_Surface *prSDLScreen;

extern SDL_Joystick *uae4all_joy0, *uae4all_joy1;

#ifdef __PSP2__
//Predefined quick switch resolutions to select via START+DPAD LEFT/RIGHT
int quickSwitchModeID=8;
struct myRes
{
int num_lines;
int top_pos;
};
myRes quickSwitchModes[] = {
{192, 0},
{200, 0},
{216, 0},
{224, 0},
{240, 0},
{256, 0},
{270, 0},
{192, 14},
{200, 14},
{216, 14},
{224, 14},
{240, 14},
{256, 14},
{270, 14},
};
extern int moveY;

//analog stick values for mouse emulation on Vita
int lAnalogX=0;
int lAnalogY=0;
int rAnalogX=0;
int rAnalogY=0;
int lAnalogXCenter=0;
int lAnalogYCenter=0;
int rAnalogXCenter=0;
int rAnalogYCenter=0;
int haveJoysticksBeenCentered=0;
extern int mainMenu_leftStickMouse;
#endif // __PSP2__

#ifdef USE_UAE4ALL_VKBD
extern int keycode2amiga(SDL_keysym *prKeySym);
#endif
Expand Down Expand Up @@ -105,14 +144,6 @@ int triggerL=0;
int triggerR=0;
int buttonSelect=0;
int buttonStart=0;
#ifdef __PSP2__
//right analog stick values for mouse emulation on Vita
int lAnalogX=0;
int lAnalogY=0;
int rAnalogX=0;
int rAnalogY=0;
extern int mainMenu_leftStickMouse;
#endif

extern int mainMenu_case;
#ifdef WITH_TESTMODE
Expand All @@ -133,7 +164,7 @@ static void getChanges(void)
changed_produce_sound=0;
changed_gfx_framerate=mainMenu_frameskip;
}

int gui_init (void)
{
SDL_ShowCursor(SDL_DISABLE);
Expand Down Expand Up @@ -520,6 +551,18 @@ void gui_handle_events (void)
rAnalogX=SDL_JoystickGetAxis(uae4all_joy0, 2);
rAnalogY=SDL_JoystickGetAxis(uae4all_joy0, 3);

//Is this the first time this routine is called when the program has just been launched?
//If yes, center the joysticks now
//After that, center the joysticks everytime we open the menu with "select"
if (!haveJoysticksBeenCentered) {
lAnalogXCenter=lAnalogX;
lAnalogYCenter=lAnalogY;
rAnalogXCenter=rAnalogX;
rAnalogYCenter=rAnalogY;
//From now on only center when entering menu
haveJoysticksBeenCentered=1;
}

if (mainMenu_leftStickMouse) {
dpadRight = SDL_JoystickGetButton(uae4all_joy0, 9)
|| (rAnalogX > 1024*10) ? 1 : 0;
Expand All @@ -529,6 +572,8 @@ void gui_handle_events (void)
|| (rAnalogY < -1024*10) ? 1 : 0;
dpadDown = SDL_JoystickGetButton(uae4all_joy0, 6)
|| (rAnalogY > 1024*10) ? 1 : 0;
lAnalogX=lAnalogX-lAnalogXCenter;
lAnalogY=lAnalogY-lAnalogYCenter;
}
else
{
Expand All @@ -540,6 +585,8 @@ void gui_handle_events (void)
|| (lAnalogY < -1024*10) ? 1 : 0;
dpadDown = SDL_JoystickGetButton(uae4all_joy0, 6)
|| (lAnalogY > 1024*10) ? 1 : 0;
rAnalogX=rAnalogX-rAnalogXCenter;
rAnalogY=rAnalogY-rAnalogYCenter;
}

buttonA = SDL_JoystickGetButton(uae4all_joy0, PAD_SQUARE);
Expand All @@ -552,7 +599,15 @@ void gui_handle_events (void)
buttonStart = SDL_JoystickGetButton(uae4all_joy0, PAD_START);

if(buttonSelect)
{
//re-center the Joysticks when the user opens the menu
SDL_JoystickUpdate();
lAnalogXCenter=SDL_JoystickGetAxis(uae4all_joy0, 0);
lAnalogYCenter=SDL_JoystickGetAxis(uae4all_joy0, 1);
rAnalogXCenter=SDL_JoystickGetAxis(uae4all_joy0, 2);
rAnalogYCenter=SDL_JoystickGetAxis(uae4all_joy0, 3);
goMenu();
}
#else
dpadUp = keystate[SDLK_UP];
dpadDown = keystate[SDLK_DOWN];
Expand Down Expand Up @@ -695,18 +750,56 @@ if(!vkbd_mode)
//left
else if(dpadLeft)
{
#ifdef __PSP2__
// Change zoom:
// quickSwitch resolution presets
if (quickSwitchModeID==0)
{
quickSwitchModeID=sizeof(quickSwitchModes)/sizeof(quickSwitchModes[0])-1;
}
else
{
quickSwitchModeID--;
}
mainMenu_displayedLines =
quickSwitchModes[quickSwitchModeID].num_lines;
moveY =
quickSwitchModes[quickSwitchModeID].top_pos;
getChanges();
check_all_prefs();
update_display();
#else
screenWidth -=10;
if(screenWidth<200)
screenWidth = 200;
update_display();
#endif
}
//right
else if(dpadRight)
{
#ifdef __PSP2__
if (quickSwitchModeID==sizeof(quickSwitchModes)/sizeof(quickSwitchModes[0])-1)
{
quickSwitchModeID=0;
}
else
{
quickSwitchModeID++;
}
mainMenu_displayedLines =
quickSwitchModes[quickSwitchModeID].num_lines;
moveY =
quickSwitchModes[quickSwitchModeID].top_pos;
getChanges();
check_all_prefs();
update_display();
#else
screenWidth +=10;
if(screenWidth>800)
screenWidth = 800;
update_display();
#endif
}
//1
else if(keystate[SDLK_1])
Expand Down

0 comments on commit 515c939

Please sign in to comment.