2012-11-23 01:40:03 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2014 - Daniel De Matteis
|
2012-11-23 01:40:03 +00:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#if defined(SN_TARGET_PSP2)
|
|
|
|
#include <sceerror.h>
|
|
|
|
#include <kernel.h>
|
|
|
|
#include <ctrl.h>
|
|
|
|
#elif defined(PSP)
|
|
|
|
#include <pspctrl.h>
|
|
|
|
#endif
|
|
|
|
|
2014-05-13 15:01:27 +00:00
|
|
|
#include "../psp/sdk_defines.h"
|
2012-11-23 01:40:03 +00:00
|
|
|
|
|
|
|
#include "../driver.h"
|
|
|
|
#include "../libretro.h"
|
|
|
|
#include "../general.h"
|
2014-06-04 00:52:29 +00:00
|
|
|
#ifdef HAVE_KERNEL_PRX
|
2014-06-04 00:35:26 +00:00
|
|
|
#include "../psp1/kernelFunctions.h"
|
2014-06-04 00:52:29 +00:00
|
|
|
#endif
|
2012-11-23 01:40:03 +00:00
|
|
|
|
2014-05-13 15:01:27 +00:00
|
|
|
enum {
|
|
|
|
PSP_GAMEPAD_CROSS = 1ULL << 0,
|
|
|
|
PSP_GAMEPAD_SQUARE = 1ULL << 1,
|
|
|
|
PSP_GAMEPAD_SELECT = 1ULL << 2,
|
|
|
|
PSP_GAMEPAD_START = 1ULL << 3,
|
|
|
|
PSP_GAMEPAD_DPAD_UP = 1ULL << 4,
|
|
|
|
PSP_GAMEPAD_DPAD_DOWN = 1ULL << 5,
|
|
|
|
PSP_GAMEPAD_DPAD_LEFT = 1ULL << 6,
|
|
|
|
PSP_GAMEPAD_DPAD_RIGHT = 1ULL << 7,
|
|
|
|
PSP_GAMEPAD_CIRCLE = 1ULL << 8,
|
|
|
|
PSP_GAMEPAD_TRIANGLE = 1ULL << 9,
|
|
|
|
PSP_GAMEPAD_L = 1ULL << 10,
|
|
|
|
PSP_GAMEPAD_R = 1ULL << 11,
|
|
|
|
PSP_GAMEPAD_LSTICK_LEFT_MASK = 1ULL << 16,
|
|
|
|
PSP_GAMEPAD_LSTICK_RIGHT_MASK = 1ULL << 17,
|
|
|
|
PSP_GAMEPAD_LSTICK_UP_MASK = 1ULL << 18,
|
|
|
|
PSP_GAMEPAD_LSTICK_DOWN_MASK = 1ULL << 19,
|
|
|
|
#ifdef SN_TARGET_PSP2
|
|
|
|
PSP_GAMEPAD_RSTICK_LEFT_MASK = 1ULL << 20,
|
|
|
|
PSP_GAMEPAD_RSTICK_RIGHT_MASK = 1ULL << 21,
|
|
|
|
PSP_GAMEPAD_RSTICK_UP_MASK = 1ULL << 22,
|
|
|
|
PSP_GAMEPAD_RSTICK_DOWN_MASK = 1ULL << 23,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2012-11-23 01:40:03 +00:00
|
|
|
#define ANALOGSTICK_DEADZONE_LOW (0x40)
|
|
|
|
#define ANALOGSTICK_DEADZONE_HIGH (0xc0)
|
|
|
|
|
2013-03-16 16:51:45 +00:00
|
|
|
#define MAX_PADS 1
|
|
|
|
|
2014-04-17 18:47:11 +00:00
|
|
|
enum input_devices
|
|
|
|
{
|
|
|
|
DEVICE_PSP = 0,
|
|
|
|
DEVICE_LAST
|
|
|
|
};
|
|
|
|
|
2012-11-24 00:42:00 +00:00
|
|
|
const struct platform_bind platform_keys[] = {
|
|
|
|
{ PSP_GAMEPAD_CIRCLE, "Circle button" },
|
|
|
|
{ PSP_GAMEPAD_CROSS, "Cross button" },
|
|
|
|
{ PSP_GAMEPAD_TRIANGLE, "Triangle button" },
|
|
|
|
{ PSP_GAMEPAD_SQUARE, "Square button" },
|
|
|
|
{ PSP_GAMEPAD_DPAD_UP, "D-Pad Up" },
|
|
|
|
{ PSP_GAMEPAD_DPAD_DOWN, "D-Pad Down" },
|
|
|
|
{ PSP_GAMEPAD_DPAD_LEFT, "D-Pad Left" },
|
|
|
|
{ PSP_GAMEPAD_DPAD_RIGHT, "D-Pad Right" },
|
|
|
|
{ PSP_GAMEPAD_SELECT, "Select button" },
|
|
|
|
{ PSP_GAMEPAD_START, "Start button" },
|
|
|
|
{ PSP_GAMEPAD_L, "L button" },
|
|
|
|
{ 0, "Unused" },
|
|
|
|
{ 0, "Unused" },
|
|
|
|
{ PSP_GAMEPAD_R, "R button" },
|
|
|
|
{ 0, "Unused" },
|
|
|
|
{ 0, "Unused" },
|
|
|
|
{ PSP_GAMEPAD_LSTICK_LEFT_MASK, "LStick Left" },
|
|
|
|
{ PSP_GAMEPAD_LSTICK_RIGHT_MASK, "LStick Right" },
|
|
|
|
{ PSP_GAMEPAD_LSTICK_UP_MASK, "LStick Up" },
|
|
|
|
{ PSP_GAMEPAD_LSTICK_DOWN_MASK, "LStick Down" },
|
|
|
|
#ifdef SN_TARGET_PSP2
|
|
|
|
{ PSP_GAMEPAD_RSTICK_LEFT_MASK, "RStick Left" },
|
|
|
|
{ PSP_GAMEPAD_RSTICK_RIGHT_MASK, "RStick Right" },
|
|
|
|
{ PSP_GAMEPAD_RSTICK_UP_MASK, "RStick Up" },
|
|
|
|
{ PSP_GAMEPAD_RSTICK_DOWN_MASK, "RStick Down" },
|
|
|
|
#else
|
|
|
|
{ 0, "Unused" },
|
|
|
|
{ 0, "Unused" },
|
|
|
|
{ 0, "Unused" },
|
|
|
|
{ 0, "Unused" },
|
|
|
|
{ 0, "Unused" },
|
|
|
|
{ 0, "Unused" },
|
|
|
|
{ 0, "Unused" },
|
|
|
|
{ 0, "Unused" },
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2014-02-12 20:03:19 +00:00
|
|
|
extern const rarch_joypad_driver_t psp_joypad;
|
2012-11-23 01:40:03 +00:00
|
|
|
|
2014-02-12 20:03:19 +00:00
|
|
|
typedef struct psp_input
|
2012-11-23 01:40:03 +00:00
|
|
|
{
|
2014-02-13 12:20:47 +00:00
|
|
|
uint64_t pad_state;
|
2014-02-12 20:03:19 +00:00
|
|
|
int16_t analog_state[1][2][2];
|
|
|
|
} psp_input_t;
|
2012-11-23 01:40:03 +00:00
|
|
|
|
2014-02-16 14:42:02 +00:00
|
|
|
static void psp_input_set_keybinds(void *data, unsigned device, unsigned port,
|
|
|
|
unsigned id, unsigned keybind_action);
|
|
|
|
|
2014-02-12 20:03:19 +00:00
|
|
|
static void psp_input_poll(void *data)
|
|
|
|
{
|
2014-02-19 16:47:59 +00:00
|
|
|
int32_t ret;
|
2014-02-16 16:06:53 +00:00
|
|
|
uint64_t *lifecycle_state = (uint64_t*)&g_extern.lifecycle_state;
|
2012-11-23 01:40:03 +00:00
|
|
|
SceCtrlData state_tmp;
|
2014-02-12 20:03:19 +00:00
|
|
|
psp_input_t *psp = (psp_input_t*)data;
|
2014-02-13 12:20:47 +00:00
|
|
|
|
|
|
|
#ifdef PSP
|
|
|
|
sceCtrlSetSamplingCycle(0);
|
|
|
|
#endif
|
|
|
|
sceCtrlSetSamplingMode(DEFAULT_SAMPLING_MODE);
|
2014-02-22 14:23:58 +00:00
|
|
|
ret = CtrlPeekBufferPositive(0, &state_tmp, 1);
|
2014-06-04 00:52:29 +00:00
|
|
|
#ifdef HAVE_KERNEL_PRX
|
2014-06-04 00:35:26 +00:00
|
|
|
state_tmp.Buttons = (state_tmp.Buttons&0x0000FFFF)|(readSystemButtons()&0xFFFF0000);
|
2014-06-04 00:52:29 +00:00
|
|
|
#endif
|
2014-02-19 16:47:59 +00:00
|
|
|
(void)ret;
|
2014-02-12 20:03:19 +00:00
|
|
|
|
2014-02-12 20:40:57 +00:00
|
|
|
psp->analog_state[0][0][0] = psp->analog_state[0][0][1] = psp->analog_state[0][1][0] = psp->analog_state[0][1][1] = 0;
|
2014-02-13 12:20:47 +00:00
|
|
|
psp->pad_state = 0;
|
|
|
|
psp->pad_state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_LEFT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
|
|
|
|
psp->pad_state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_DOWN) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
|
|
|
|
psp->pad_state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_RIGHT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
|
|
|
|
psp->pad_state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_UP) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
|
|
|
|
psp->pad_state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_START) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_START) : 0;
|
|
|
|
psp->pad_state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_SELECT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0;
|
|
|
|
psp->pad_state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_TRIANGLE) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_X) : 0;
|
|
|
|
psp->pad_state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_SQUARE) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_Y) : 0;
|
|
|
|
psp->pad_state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_CROSS) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_B) : 0;
|
|
|
|
psp->pad_state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_CIRCLE) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_A) : 0;
|
|
|
|
psp->pad_state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_R) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R) : 0;
|
|
|
|
psp->pad_state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_L) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L) : 0;
|
2014-02-16 21:35:08 +00:00
|
|
|
|
2014-02-16 23:49:25 +00:00
|
|
|
psp->analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_X] = (int16_t)(STATE_ANALOGLX(state_tmp)-128) * 256;
|
|
|
|
psp->analog_state[0][RETRO_DEVICE_INDEX_ANALOG_LEFT] [RETRO_DEVICE_ID_ANALOG_Y] = (int16_t)(STATE_ANALOGLY(state_tmp)-128) * 256;
|
2014-02-16 22:46:01 +00:00
|
|
|
#ifdef SN_TARGET_PSP2
|
2014-02-16 23:49:25 +00:00
|
|
|
psp->analog_state[0][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = (int16_t)(STATE_ANALOGRX(state_tmp)-128) * 256;
|
|
|
|
psp->analog_state[0][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = (int16_t)(STATE_ANALOGRY(state_tmp)-128) * 256;
|
2014-02-16 22:46:01 +00:00
|
|
|
#endif
|
|
|
|
|
2014-02-16 23:27:49 +00:00
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
for (int j = 0; j < 2; j++)
|
|
|
|
if (psp->analog_state[0][i][j] == -0x8000)
|
|
|
|
psp->analog_state[0][i][j] = -0x7fff;
|
|
|
|
|
2014-02-16 21:35:08 +00:00
|
|
|
*lifecycle_state &= ~((1ULL << RARCH_MENU_TOGGLE));
|
|
|
|
|
2014-06-04 00:52:29 +00:00
|
|
|
#ifdef HAVE_KERNEL_PRX
|
2014-06-04 00:35:26 +00:00
|
|
|
if (STATE_BUTTON(state_tmp) & PSP_CTRL_NOTE)
|
2014-06-04 00:52:29 +00:00
|
|
|
#else
|
|
|
|
if (
|
|
|
|
(psp->pad_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_L))
|
|
|
|
&& (psp->pad_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_R))
|
|
|
|
&& (psp->pad_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_SELECT))
|
|
|
|
&& (psp->pad_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_START))
|
|
|
|
)
|
|
|
|
#endif
|
2014-02-16 21:35:08 +00:00
|
|
|
*lifecycle_state |= (1ULL << RARCH_MENU_TOGGLE);
|
2014-02-16 22:46:01 +00:00
|
|
|
|
2014-02-16 14:36:01 +00:00
|
|
|
if (g_settings.input.autodetect_enable)
|
|
|
|
{
|
2014-02-16 14:42:02 +00:00
|
|
|
if (strcmp(g_settings.input.device_names[0], "PSP") != 0)
|
|
|
|
psp_input_set_keybinds(NULL, DEVICE_PSP, 0, 0, (1ULL << KEYBINDS_ACTION_SET_DEFAULT_BINDS));
|
2014-02-16 14:36:01 +00:00
|
|
|
}
|
2012-11-23 01:40:03 +00:00
|
|
|
}
|
|
|
|
|
2014-02-12 20:03:19 +00:00
|
|
|
static bool psp_menu_input_state(uint64_t joykey, uint64_t state)
|
|
|
|
{
|
|
|
|
switch (joykey)
|
|
|
|
{
|
|
|
|
case CONSOLE_MENU_A:
|
|
|
|
return state & (1ULL << RETRO_DEVICE_ID_JOYPAD_A);
|
|
|
|
case CONSOLE_MENU_B:
|
|
|
|
return state & (1ULL << RETRO_DEVICE_ID_JOYPAD_B);
|
|
|
|
case CONSOLE_MENU_X:
|
|
|
|
return state & (1ULL << RETRO_DEVICE_ID_JOYPAD_X);
|
|
|
|
case CONSOLE_MENU_Y:
|
|
|
|
return state & (1ULL << RETRO_DEVICE_ID_JOYPAD_Y);
|
|
|
|
case CONSOLE_MENU_START:
|
|
|
|
return state & (1ULL << RETRO_DEVICE_ID_JOYPAD_START);
|
|
|
|
case CONSOLE_MENU_SELECT:
|
|
|
|
return state & (1ULL << RETRO_DEVICE_ID_JOYPAD_SELECT);
|
|
|
|
case CONSOLE_MENU_UP:
|
|
|
|
return state & (1ULL << RETRO_DEVICE_ID_JOYPAD_UP);
|
|
|
|
case CONSOLE_MENU_DOWN:
|
|
|
|
return state & (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN);
|
|
|
|
case CONSOLE_MENU_LEFT:
|
|
|
|
return state & (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT);
|
|
|
|
case CONSOLE_MENU_RIGHT:
|
|
|
|
return state & (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT);
|
|
|
|
case CONSOLE_MENU_L:
|
|
|
|
return state & (1ULL << RETRO_DEVICE_ID_JOYPAD_L);
|
|
|
|
case CONSOLE_MENU_R:
|
|
|
|
return state & (1ULL << RETRO_DEVICE_ID_JOYPAD_R);
|
|
|
|
case CONSOLE_MENU_HOME:
|
|
|
|
return (state & (1ULL << RETRO_DEVICE_ID_JOYPAD_L3)) && (state & (1ULL << RETRO_DEVICE_ID_JOYPAD_R3));
|
|
|
|
case CONSOLE_MENU_L2:
|
|
|
|
return state & (1ULL << RETRO_DEVICE_ID_JOYPAD_L2);
|
|
|
|
case CONSOLE_MENU_R2:
|
|
|
|
return state & (1ULL << RETRO_DEVICE_ID_JOYPAD_R2);
|
|
|
|
case CONSOLE_MENU_L3:
|
|
|
|
return state & (1ULL << RETRO_DEVICE_ID_JOYPAD_L3);
|
|
|
|
case CONSOLE_MENU_R3:
|
|
|
|
return state & (1ULL << RETRO_DEVICE_ID_JOYPAD_R3);
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-23 01:40:03 +00:00
|
|
|
static int16_t psp_input_state(void *data, const struct retro_keybind **binds,
|
|
|
|
unsigned port, unsigned device,
|
|
|
|
unsigned index, unsigned id)
|
|
|
|
{
|
2014-02-12 20:03:19 +00:00
|
|
|
psp_input_t *psp = (psp_input_t*)data;
|
2012-11-23 01:40:03 +00:00
|
|
|
|
2014-02-12 20:03:19 +00:00
|
|
|
if (port > 0)
|
|
|
|
return 0;
|
2012-11-23 01:40:03 +00:00
|
|
|
|
|
|
|
switch (device)
|
|
|
|
{
|
|
|
|
case RETRO_DEVICE_JOYPAD:
|
2014-02-12 20:03:19 +00:00
|
|
|
if (binds[port][id].joykey >= CONSOLE_MENU_FIRST && binds[port][id].joykey <= CONSOLE_MENU_LAST)
|
2014-02-13 12:20:47 +00:00
|
|
|
return psp_menu_input_state(binds[port][id].joykey, psp->pad_state) ? 1 : 0;
|
2014-02-12 20:03:19 +00:00
|
|
|
else
|
|
|
|
return input_joypad_pressed(&psp_joypad, port, binds[port], id);
|
|
|
|
case RETRO_DEVICE_ANALOG:
|
|
|
|
return input_joypad_analog(&psp_joypad, port, index, id, binds[port]);
|
2012-11-23 01:40:03 +00:00
|
|
|
}
|
|
|
|
|
2014-02-12 20:03:19 +00:00
|
|
|
return 0;
|
2012-11-23 01:40:03 +00:00
|
|
|
}
|
|
|
|
|
2013-03-14 01:24:57 +00:00
|
|
|
static void psp_input_free_input(void *data)
|
2012-11-23 01:40:03 +00:00
|
|
|
{
|
2014-05-29 20:33:44 +00:00
|
|
|
free(data);
|
2012-11-23 01:40:03 +00:00
|
|
|
}
|
|
|
|
|
2013-03-14 01:24:57 +00:00
|
|
|
static void psp_input_set_keybinds(void *data, unsigned device, unsigned port,
|
|
|
|
unsigned id, unsigned keybind_action)
|
2013-03-12 23:34:46 +00:00
|
|
|
{
|
|
|
|
(void)device;
|
2014-02-12 20:03:19 +00:00
|
|
|
uint64_t *key = &g_settings.input.binds[port][id].joykey;
|
2014-02-16 14:20:46 +00:00
|
|
|
size_t arr_size = sizeof(platform_keys) / sizeof(platform_keys[0]);
|
|
|
|
(void)device;
|
2014-02-12 20:03:19 +00:00
|
|
|
|
|
|
|
if (keybind_action & (1ULL << KEYBINDS_ACTION_SET_DEFAULT_BIND))
|
|
|
|
*key = g_settings.input.binds[port][id].def_joykey;
|
2013-03-13 15:06:13 +00:00
|
|
|
|
2013-03-14 01:24:57 +00:00
|
|
|
if (keybind_action & (1ULL << KEYBINDS_ACTION_SET_DEFAULT_BINDS))
|
2013-03-13 15:06:13 +00:00
|
|
|
{
|
2014-02-12 20:03:19 +00:00
|
|
|
strlcpy(g_settings.input.device_names[port], "PSP", sizeof(g_settings.input.device_names[port]));
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_B].def_joykey = (RETRO_DEVICE_ID_JOYPAD_B);
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_Y].def_joykey = (RETRO_DEVICE_ID_JOYPAD_Y);
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_SELECT].def_joykey = (RETRO_DEVICE_ID_JOYPAD_SELECT);
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_START].def_joykey = (RETRO_DEVICE_ID_JOYPAD_START);
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_UP].def_joykey = (RETRO_DEVICE_ID_JOYPAD_UP);
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_DOWN].def_joykey = (RETRO_DEVICE_ID_JOYPAD_DOWN);
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_LEFT].def_joykey = (RETRO_DEVICE_ID_JOYPAD_LEFT);
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_RIGHT].def_joykey = (RETRO_DEVICE_ID_JOYPAD_RIGHT);
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_A].def_joykey = (RETRO_DEVICE_ID_JOYPAD_A);
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_X].def_joykey = (RETRO_DEVICE_ID_JOYPAD_X);
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L].def_joykey = (RETRO_DEVICE_ID_JOYPAD_L);
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R].def_joykey = (RETRO_DEVICE_ID_JOYPAD_R);
|
2014-02-16 14:20:46 +00:00
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L2].def_joykey = NO_BTN;
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R2].def_joykey = NO_BTN;
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L3].def_joykey = NO_BTN;
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R3].def_joykey = NO_BTN;
|
2014-02-12 20:03:19 +00:00
|
|
|
g_settings.input.binds[port][RARCH_ANALOG_LEFT_X_PLUS].def_joykey = NO_BTN;
|
|
|
|
g_settings.input.binds[port][RARCH_ANALOG_LEFT_X_MINUS].def_joykey = NO_BTN;
|
|
|
|
g_settings.input.binds[port][RARCH_ANALOG_LEFT_Y_PLUS].def_joykey = NO_BTN;
|
|
|
|
g_settings.input.binds[port][RARCH_ANALOG_LEFT_Y_MINUS].def_joykey = NO_BTN;
|
|
|
|
g_settings.input.binds[port][RARCH_ANALOG_RIGHT_X_PLUS].def_joykey = NO_BTN;
|
|
|
|
g_settings.input.binds[port][RARCH_ANALOG_RIGHT_X_MINUS].def_joykey = NO_BTN;
|
|
|
|
g_settings.input.binds[port][RARCH_ANALOG_RIGHT_Y_PLUS].def_joykey = NO_BTN;
|
|
|
|
g_settings.input.binds[port][RARCH_ANALOG_RIGHT_Y_MINUS].def_joykey = NO_BTN;
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_B].def_joyaxis = AXIS_NONE;
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_Y].def_joyaxis = AXIS_NONE;
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_SELECT].def_joyaxis = AXIS_NONE;
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_START].def_joyaxis = AXIS_NONE;
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_UP].def_joyaxis = AXIS_NONE;
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_DOWN].def_joyaxis = AXIS_NONE;
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_LEFT].def_joyaxis = AXIS_NONE;
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_RIGHT].def_joyaxis = AXIS_NONE;
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_A].def_joyaxis = AXIS_NONE;
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_X].def_joyaxis = AXIS_NONE;
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L].def_joyaxis = AXIS_NONE;
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R].def_joyaxis = AXIS_NONE;
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L2].def_joyaxis = AXIS_NONE;
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R2].def_joyaxis = AXIS_NONE;
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_L3].def_joyaxis = AXIS_NONE;
|
|
|
|
g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_R3].def_joyaxis = AXIS_NONE;
|
|
|
|
g_settings.input.binds[port][RARCH_ANALOG_LEFT_X_PLUS].def_joyaxis = AXIS_POS(0);
|
|
|
|
g_settings.input.binds[port][RARCH_ANALOG_LEFT_X_MINUS].def_joyaxis = AXIS_NEG(0);
|
|
|
|
g_settings.input.binds[port][RARCH_ANALOG_LEFT_Y_PLUS].def_joyaxis = AXIS_POS(1);
|
|
|
|
g_settings.input.binds[port][RARCH_ANALOG_LEFT_Y_MINUS].def_joyaxis = AXIS_NEG(1);
|
|
|
|
g_settings.input.binds[port][RARCH_ANALOG_RIGHT_X_PLUS].def_joyaxis = AXIS_POS(2);
|
|
|
|
g_settings.input.binds[port][RARCH_ANALOG_RIGHT_X_MINUS].def_joyaxis = AXIS_NEG(2);
|
|
|
|
g_settings.input.binds[port][RARCH_ANALOG_RIGHT_Y_PLUS].def_joyaxis = AXIS_POS(3);
|
|
|
|
g_settings.input.binds[port][RARCH_ANALOG_RIGHT_Y_MINUS].def_joyaxis = AXIS_NEG(3);
|
2014-02-12 20:55:33 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < RARCH_CUSTOM_BIND_LIST_END; i++)
|
|
|
|
{
|
|
|
|
g_settings.input.binds[port][i].id = i;
|
|
|
|
g_settings.input.binds[port][i].joykey = g_settings.input.binds[port][i].def_joykey;
|
|
|
|
g_settings.input.binds[port][i].joyaxis = g_settings.input.binds[port][i].def_joyaxis;
|
|
|
|
}
|
2013-03-13 15:06:13 +00:00
|
|
|
}
|
2014-02-16 14:20:46 +00:00
|
|
|
|
|
|
|
if (keybind_action & (1ULL << KEYBINDS_ACTION_GET_BIND_LABEL))
|
|
|
|
{
|
|
|
|
struct platform_bind *ret = (struct platform_bind*)data;
|
|
|
|
|
|
|
|
if (ret->joykey == NO_BTN)
|
|
|
|
strlcpy(ret->desc, "No button", sizeof(ret->desc));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < arr_size; i++)
|
|
|
|
{
|
|
|
|
if (platform_keys[i].joykey == ret->joykey)
|
|
|
|
{
|
|
|
|
strlcpy(ret->desc, platform_keys[i].desc, sizeof(ret->desc));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
strlcpy(ret->desc, "Unknown", sizeof(ret->desc));
|
|
|
|
}
|
|
|
|
}
|
2013-03-12 23:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-11-23 01:40:03 +00:00
|
|
|
static void* psp_input_initialize(void)
|
|
|
|
{
|
2014-02-12 20:09:11 +00:00
|
|
|
psp_input_t *psp = (psp_input_t*)calloc(1, sizeof(*psp));
|
|
|
|
if (!psp)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return psp;
|
2012-11-23 01:40:03 +00:00
|
|
|
}
|
|
|
|
|
2013-03-14 01:24:57 +00:00
|
|
|
static bool psp_input_key_pressed(void *data, int key)
|
2012-11-23 01:40:03 +00:00
|
|
|
{
|
2014-02-28 04:23:19 +00:00
|
|
|
return (g_extern.lifecycle_state & (1ULL << key)) || input_joypad_pressed(&psp_joypad, 0, g_settings.input.binds[0], key);
|
2012-11-23 01:40:03 +00:00
|
|
|
}
|
|
|
|
|
2013-11-02 23:27:58 +00:00
|
|
|
static uint64_t psp_input_get_capabilities(void *data)
|
|
|
|
{
|
|
|
|
uint64_t caps = 0;
|
|
|
|
|
|
|
|
caps |= (1 << RETRO_DEVICE_JOYPAD);
|
2014-02-13 12:20:47 +00:00
|
|
|
caps |= (1 << RETRO_DEVICE_ANALOG);
|
2013-11-02 23:27:58 +00:00
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2014-02-12 20:03:19 +00:00
|
|
|
static const rarch_joypad_driver_t *psp_input_get_joypad_driver(void *data)
|
|
|
|
{
|
|
|
|
return &psp_joypad;
|
|
|
|
}
|
|
|
|
|
2014-04-17 18:47:11 +00:00
|
|
|
static unsigned psp_input_devices_size(void *data)
|
|
|
|
{
|
|
|
|
return DEVICE_LAST;
|
|
|
|
}
|
|
|
|
|
2012-11-23 01:40:03 +00:00
|
|
|
const input_driver_t input_psp = {
|
2013-11-02 23:27:58 +00:00
|
|
|
psp_input_initialize,
|
|
|
|
psp_input_poll,
|
|
|
|
psp_input_state,
|
|
|
|
psp_input_key_pressed,
|
|
|
|
psp_input_free_input,
|
|
|
|
psp_input_set_keybinds,
|
|
|
|
NULL,
|
2014-01-20 13:52:53 +00:00
|
|
|
NULL,
|
2013-11-02 23:27:58 +00:00
|
|
|
psp_input_get_capabilities,
|
2014-04-17 18:47:11 +00:00
|
|
|
psp_input_devices_size,
|
2013-11-02 23:27:58 +00:00
|
|
|
"psp",
|
2014-02-13 12:20:47 +00:00
|
|
|
|
2014-02-12 20:03:19 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
psp_input_get_joypad_driver,
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool psp_joypad_init(void)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool psp_joypad_button(unsigned port_num, uint16_t joykey)
|
|
|
|
{
|
|
|
|
psp_input_t *psp = (psp_input_t*)driver.input_data;
|
|
|
|
|
|
|
|
if (port_num >= MAX_PADS)
|
|
|
|
return false;
|
|
|
|
|
2014-02-13 12:20:47 +00:00
|
|
|
return (psp->pad_state & (1ULL << joykey));
|
2014-02-12 20:03:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int16_t psp_joypad_axis(unsigned port_num, uint32_t joyaxis)
|
|
|
|
{
|
|
|
|
psp_input_t *psp = (psp_input_t*)driver.input_data;
|
|
|
|
if (joyaxis == AXIS_NONE || port_num >= MAX_PADS)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
int val = 0;
|
|
|
|
|
|
|
|
int axis = -1;
|
|
|
|
bool is_neg = false;
|
|
|
|
bool is_pos = false;
|
|
|
|
|
|
|
|
if (AXIS_NEG_GET(joyaxis) < 4)
|
|
|
|
{
|
|
|
|
axis = AXIS_NEG_GET(joyaxis);
|
|
|
|
is_neg = true;
|
|
|
|
}
|
|
|
|
else if (AXIS_POS_GET(joyaxis) < 4)
|
|
|
|
{
|
|
|
|
axis = AXIS_POS_GET(joyaxis);
|
|
|
|
is_pos = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (axis)
|
|
|
|
{
|
|
|
|
case 0: val = psp->analog_state[port_num][0][0]; break;
|
|
|
|
case 1: val = psp->analog_state[port_num][0][1]; break;
|
|
|
|
case 2: val = psp->analog_state[port_num][1][0]; break;
|
|
|
|
case 3: val = psp->analog_state[port_num][1][1]; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_neg && val > 0)
|
|
|
|
val = 0;
|
|
|
|
else if (is_pos && val < 0)
|
|
|
|
val = 0;
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void psp_joypad_poll(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool psp_joypad_query_pad(unsigned pad)
|
|
|
|
{
|
|
|
|
psp_input_t *psp = (psp_input_t*)driver.input_data;
|
2014-02-13 12:20:47 +00:00
|
|
|
return pad < MAX_PLAYERS && psp->pad_state;
|
2014-02-12 20:03:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *psp_joypad_name(unsigned pad)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void psp_joypad_destroy(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const rarch_joypad_driver_t psp_joypad = {
|
|
|
|
psp_joypad_init,
|
|
|
|
psp_joypad_query_pad,
|
|
|
|
psp_joypad_destroy,
|
|
|
|
psp_joypad_button,
|
|
|
|
psp_joypad_axis,
|
|
|
|
psp_joypad_poll,
|
|
|
|
NULL,
|
|
|
|
psp_joypad_name,
|
|
|
|
"psp",
|
2012-11-23 01:40:03 +00:00
|
|
|
};
|