diff --git a/Makefile b/Makefile index 91d6c330..2ac32b1a 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/vita/vita_input.c b/vita/vita_input.c index dd0143c3..7707a9a9 100644 --- a/vita/vita_input.c +++ b/vita/vita_input.c @@ -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; @@ -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; } } } @@ -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; } @@ -138,9 +149,9 @@ 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; } @@ -148,21 +159,21 @@ bool S9xReadMousePosition(int player, int* x, int* y, uint32_t* buttons) // 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; } diff --git a/vita/vita_input.h b/vita/vita_input.h index d99e3c7b..509e60e7 100644 --- a/vita/vita_input.h +++ b/vita/vita_input.h @@ -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();