Skip to content

Commit

Permalink
Fixes so that SNES mouse works both on PSTV and VITA
Browse files Browse the repository at this point in the history
  • Loading branch information
skogaby committed Aug 7, 2016
1 parent c6bd325 commit b2dc715
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
TARGET = CATSFC-libretro-vita

PSP_APP_NAME=CATSFC-libretro-vita
PSP_APP_VER=1.1.1
PSP_APP_VER=1.3.0

CORE_DIR := source
VITA_DIR := vita
Expand Down
65 changes: 38 additions & 27 deletions vita/vita_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,20 @@ void retro_input_poll_callback()

for (player = 0; player <= 1; player++)
{
sceCtrlPeekBufferPositive(player + 1, pad, 1);
// dumb hack, but here's the explanation: sceCtrlPeekBufferPositive's
// port parameter can be 0 or 1 to read the first controller on a PSTV,
// but HAS to be 0 for a real VITA and 2 for the 2nd controller on a PSTV
unsigned int p = (player == 1 ? 2 : player);
int result = sceCtrlPeekBufferPositive(p, pad, 1);
stick_in_use = false;

if (result < 1)
{
keys_down[player] = 0;
return;
}

keys_down[player] = pad->buttons;
stick_in_use[player] = false;

// first, handle (single) physical button presses
unsigned int i;
Expand All @@ -55,50 +66,50 @@ void retro_input_poll_callback()
// handle the left analog stick
if (pad->ly < 128 - JOY_THRESHOLD) // analog up
{
if (player == 0) mouse_current_y += ((pad->ly - 128) / 90) * Settings.MouseSpeed;
handle_button_press(player, ActiveConfig.ButtonMap[MAP_ANALOG_UP], true);
mouse_current_y[player] += ((pad->ly - 128) / 90) * Settings.MouseSpeed;
stick_in_use[player] = true;
stick_in_use = true;
}
else if (pad->ly > 128 + JOY_THRESHOLD) // analog down
{
if (player == 0) mouse_current_y += ((pad->ly - 128) / 90) * Settings.MouseSpeed;
handle_button_press(player, ActiveConfig.ButtonMap[MAP_ANALOG_DOWN], true);
mouse_current_y[player] += ((pad->ly - 128) / 90) * Settings.MouseSpeed;
stick_in_use[player] = true;
stick_in_use = true;
}

if (pad->lx < 128 - JOY_THRESHOLD) // analog left
{
if (player == 0) mouse_current_x += ((pad->lx - 128) / 90) * Settings.MouseSpeed;
handle_button_press(player, ActiveConfig.ButtonMap[MAP_ANALOG_LEFT], true);
mouse_current_x[player] += ((pad->lx - 128) / 90) * Settings.MouseSpeed;
stick_in_use[player] = true;
stick_in_use = true;
}
else if (pad->lx > 128 + JOY_THRESHOLD) // analog right
{
if (player == 0) mouse_current_x += ((pad->lx - 128) / 90) * Settings.MouseSpeed;
handle_button_press(player, ActiveConfig.ButtonMap[MAP_ANALOG_RIGHT], true);
mouse_current_x[player] += ((pad->lx - 128) / 90) * Settings.MouseSpeed;
stick_in_use[player] = true;
stick_in_use = true;
}

// only handle the right analog stick if the left stick wasn't in use,
// so they don't double each other or cancel each other out
if (!stick_in_use[player])
if (!stick_in_use && (player == 0))
{
if (pad->ry < 128 - JOY_THRESHOLD) // analog up
{
mouse_current_y[player] += ((pad->ry - 128) / 90) * Settings.MouseSpeed;
mouse_current_y += ((pad->ry - 128) / 90) * Settings.MouseSpeed;
}
else if (pad->ry > 128 + JOY_THRESHOLD) // analog down
{
mouse_current_y[player] += ((pad->ry - 128) / 90) * Settings.MouseSpeed;
mouse_current_y += ((pad->ry - 128) / 90) * Settings.MouseSpeed;
}

if (pad->rx < 128 - JOY_THRESHOLD) // analog left
{
mouse_current_x[player] += ((pad->rx - 128) / 90) * Settings.MouseSpeed;
mouse_current_x += ((pad->rx - 128) / 90) * Settings.MouseSpeed;
}
else if (pad->rx > 128 + JOY_THRESHOLD) // analog right
{
mouse_current_x[player] += ((pad->rx - 128) / 90) * Settings.MouseSpeed;
mouse_current_x += ((pad->rx - 128) / 90) * Settings.MouseSpeed;
}
}
}
Expand Down Expand Up @@ -127,8 +138,8 @@ void handle_button_press(unsigned int player, unsigned int mapping, unsigned int
{
keymap[player][mapping] = pressed;
}
// user wants to go back to the menu
else if (pressed && (mapping == SPC_MENU))
// player 1 wants to go back to the menu
else if (pressed && (mapping == SPC_MENU) && (player == 0))
{
ResumeEmulation = 0;
}
Expand All @@ -138,31 +149,31 @@ void handle_button_press(unsigned int player, unsigned int mapping, unsigned int
* Emulate the SNES mouse. I think this is only used in Mario Paint, but goddamnit,
* I love Mario Paint.
*/
bool S9xReadMousePosition(int player, int* x, int* y, uint32_t* buttons)
bool S9xReadMousePosition(int which1, int* x, int* y, uint32_t* buttons)
{
if (player > 1)
if (which1 != 0)
{
return false;
}

// right now, mouse controls are hard-coded to the analog sticks,
// and a few buttons acting as L/R-click. maybe later I'll make it
// configurable
*x = mouse_current_x[player];
*y = mouse_current_y[player];
*x = mouse_current_x;
*y = mouse_current_y;

// left-click is cross, square, or L-trigger
if ((keys_down[player] & SCE_CTRL_LTRIGGER) ||
(keys_down[player] & SCE_CTRL_SQUARE) ||
(keys_down[player] & SCE_CTRL_CROSS))
if ((keys_down[which1] & SCE_CTRL_LTRIGGER) ||
(keys_down[which1] & SCE_CTRL_SQUARE) ||
(keys_down[which1] & SCE_CTRL_CROSS))
{
*buttons |= 0x1;
}

// right-click is circle, triangle, or R-trigger
if ((keys_down[player] & SCE_CTRL_RTRIGGER) ||
(keys_down[player] & SCE_CTRL_TRIANGLE) ||
(keys_down[player] & SCE_CTRL_CIRCLE))
if ((keys_down[which1] & SCE_CTRL_RTRIGGER) ||
(keys_down[which1] & SCE_CTRL_TRIANGLE) ||
(keys_down[which1] & SCE_CTRL_CIRCLE))
{
*buttons |= 0x2;
}
Expand Down
6 changes: 3 additions & 3 deletions vita/vita_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
SceCtrlData *pad;
uint32_t keymap[2][12];
uint32_t keys_down[2];
int mouse_current_x[2];
int mouse_current_y[2];
bool stick_in_use[2];
int mouse_current_x;
int mouse_current_y;
bool stick_in_use;
extern int ResumeEmulation;

void setup_input();
Expand Down

0 comments on commit b2dc715

Please sign in to comment.