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
|
|
|
|
|
2012-11-23 02:29:30 +00:00
|
|
|
#include "sdk_defines.h"
|
2012-11-23 01:40:03 +00:00
|
|
|
#include "psp_input.h"
|
|
|
|
|
|
|
|
#include "../driver.h"
|
|
|
|
#include "../libretro.h"
|
|
|
|
#include "../general.h"
|
|
|
|
|
|
|
|
#define ANALOGSTICK_DEADZONE_LOW (0x40)
|
|
|
|
#define ANALOGSTICK_DEADZONE_HIGH (0xc0)
|
|
|
|
|
2013-03-16 16:51:45 +00:00
|
|
|
#define MAX_PADS 1
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2012-11-23 01:40:03 +00:00
|
|
|
static uint64_t state;
|
|
|
|
|
|
|
|
static void psp_input_poll(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
|
|
|
|
SceCtrlData state_tmp;
|
2012-11-23 06:19:21 +00:00
|
|
|
int ret = CtrlReadBufferPositive(0, &state_tmp, 1);
|
2014-02-11 13:10:47 +00:00
|
|
|
state = 0;
|
|
|
|
|
|
|
|
if (ret != SCE_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_LEFT) ? PSP_GAMEPAD_DPAD_LEFT : 0;
|
|
|
|
state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_DOWN) ? PSP_GAMEPAD_DPAD_DOWN : 0;
|
|
|
|
state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_RIGHT) ? PSP_GAMEPAD_DPAD_RIGHT : 0;
|
|
|
|
state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_UP) ? PSP_GAMEPAD_DPAD_UP : 0;
|
|
|
|
state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_START) ? PSP_GAMEPAD_START : 0;
|
|
|
|
state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_SELECT) ? PSP_GAMEPAD_SELECT : 0;
|
|
|
|
state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_TRIANGLE) ? PSP_GAMEPAD_TRIANGLE : 0;
|
|
|
|
state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_SQUARE) ? PSP_GAMEPAD_SQUARE : 0;
|
|
|
|
state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_CROSS) ? PSP_GAMEPAD_CROSS : 0;
|
|
|
|
state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_CIRCLE) ? PSP_GAMEPAD_CIRCLE : 0;
|
|
|
|
state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_R) ? PSP_GAMEPAD_R : 0;
|
|
|
|
state |= (STATE_BUTTON(state_tmp) & PSP_CTRL_L) ? PSP_GAMEPAD_L : 0;
|
|
|
|
state |= (STATE_ANALOGLX(state_tmp) < ANALOGSTICK_DEADZONE_LOW) ? PSP_GAMEPAD_LSTICK_LEFT_MASK : 0;
|
|
|
|
state |= (STATE_ANALOGLX(state_tmp) > ANALOGSTICK_DEADZONE_HIGH) ? PSP_GAMEPAD_LSTICK_RIGHT_MASK : 0;
|
|
|
|
state |= (STATE_ANALOGLY(state_tmp) < ANALOGSTICK_DEADZONE_LOW) ? PSP_GAMEPAD_LSTICK_UP_MASK : 0;
|
|
|
|
state |= (STATE_ANALOGLY(state_tmp) > ANALOGSTICK_DEADZONE_HIGH) ? PSP_GAMEPAD_LSTICK_DOWN_MASK : 0;
|
2012-11-23 01:40:03 +00:00
|
|
|
#ifdef SN_TARGET_PSP2
|
2014-02-11 13:10:47 +00:00
|
|
|
state |= (STATE_ANALOGRX(state_tmp) < ANALOGSTICK_DEADZONE_LOW) ? PSP_GAMEPAD_RSTICK_LEFT_MASK : 0;
|
|
|
|
state |= (STATE_ANALOGRX(state_tmp) > ANALOGSTICK_DEADZONE_HIGH) ? PSP_GAMEPAD_RSTICK_RIGHT_MASK : 0;
|
|
|
|
state |= (STATE_ANALOGRY(state_tmp) < ANALOGSTICK_DEADZONE_LOW) ? PSP_GAMEPAD_RSTICK_UP_MASK : 0;
|
|
|
|
state |= (STATE_ANALOGRY(state_tmp) > ANALOGSTICK_DEADZONE_HIGH) ? PSP_GAMEPAD_RSTICK_DOWN_MASK : 0;
|
2012-11-23 01:40:03 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int16_t psp_input_state(void *data, const struct retro_keybind **binds,
|
|
|
|
unsigned port, unsigned device,
|
|
|
|
unsigned index, unsigned id)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
|
|
|
|
uint64_t button = binds[0][id].joykey;
|
|
|
|
int16_t retval = 0;
|
|
|
|
|
|
|
|
switch (device)
|
|
|
|
{
|
|
|
|
case RETRO_DEVICE_JOYPAD:
|
|
|
|
retval = (state & button) ? 1 : 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2013-03-14 01:24:57 +00:00
|
|
|
static void psp_input_free_input(void *data)
|
2012-11-23 01:40:03 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
}
|
|
|
|
|
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;
|
2013-03-13 22:17:33 +00:00
|
|
|
(void)id;
|
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
|
|
|
{
|
2013-03-14 01:24:57 +00:00
|
|
|
for (unsigned i = 0; i < RARCH_CUSTOM_BIND_LIST_END; i++)
|
|
|
|
{
|
|
|
|
g_settings.input.binds[port][i].id = i;
|
|
|
|
g_settings.input.binds[port][i].def_joykey = platform_keys[i].joykey;
|
|
|
|
g_settings.input.binds[port][i].joykey = g_settings.input.binds[port][i].def_joykey;
|
|
|
|
}
|
2013-03-13 15:06:13 +00:00
|
|
|
}
|
2013-03-12 23:34:46 +00:00
|
|
|
}
|
|
|
|
|
2012-11-23 01:40:03 +00:00
|
|
|
static void* psp_input_initialize(void)
|
|
|
|
{
|
|
|
|
#ifdef PSP
|
|
|
|
sceCtrlSetSamplingCycle(0);
|
|
|
|
#endif
|
|
|
|
sceCtrlSetSamplingMode(DEFAULT_SAMPLING_MODE);
|
|
|
|
|
2013-03-12 23:34:46 +00:00
|
|
|
return (void*)-1;
|
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
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
|
|
|
|
switch (key)
|
|
|
|
{
|
2014-02-12 18:27:44 +00:00
|
|
|
#if 0
|
2012-11-26 06:03:31 +00:00
|
|
|
case RARCH_QUIT_KEY:
|
2012-11-28 14:11:27 +00:00
|
|
|
RARCH_LOG("Got to here once.\n");
|
2012-11-26 06:03:31 +00:00
|
|
|
return true;
|
2014-02-12 18:27:44 +00:00
|
|
|
#endif
|
2012-11-23 01:40:03 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
"psp",
|
2012-11-23 01:40:03 +00:00
|
|
|
};
|