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-08-15 19:14:26 +00:00
|
|
|
#include "../gfx/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 23:17:37 +00:00
|
|
|
#include "../psp1/kernel_functions.h"
|
2014-06-04 00:52:29 +00:00
|
|
|
#endif
|
2012-11-23 01:40:03 +00:00
|
|
|
|
2013-03-16 16:51:45 +00:00
|
|
|
#define MAX_PADS 1
|
|
|
|
|
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];
|
2014-06-09 16:57:17 +00:00
|
|
|
const rarch_joypad_driver_t *joypad;
|
2014-02-12 20:03:19 +00:00
|
|
|
} psp_input_t;
|
2012-11-23 01:40:03 +00:00
|
|
|
|
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 23:17:37 +00:00
|
|
|
state_tmp.Buttons = (state_tmp.Buttons&0x0000FFFF)|(read_system_buttons()&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-09-09 16:15:17 +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);
|
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-06-09 16:57:17 +00:00
|
|
|
return input_joypad_pressed(psp->joypad, port, binds[port], id);
|
2014-02-12 20:03:19 +00:00
|
|
|
case RETRO_DEVICE_ANALOG:
|
2014-06-09 16:57:17 +00:00
|
|
|
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-06-09 16:57:17 +00:00
|
|
|
psp_input_t *psp = (psp_input_t*)data;
|
2014-02-12 20:03:19 +00:00
|
|
|
|
2014-06-09 16:57:17 +00:00
|
|
|
if (psp->joypad)
|
|
|
|
psp->joypad->destroy();
|
2013-03-13 15:06:13 +00:00
|
|
|
|
2014-06-09 16:57:17 +00:00
|
|
|
free(data);
|
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;
|
2014-06-09 16:57:17 +00:00
|
|
|
|
|
|
|
psp->joypad = input_joypad_init_driver(g_settings.input.joypad_driver);
|
2014-02-12 20:09:11 +00:00
|
|
|
|
|
|
|
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-06-09 16:57:17 +00:00
|
|
|
psp_input_t *psp = (psp_input_t*)data;
|
2014-09-09 16:15:17 +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)
|
|
|
|
{
|
2014-06-09 16:57:17 +00:00
|
|
|
psp_input_t *psp = (psp_input_t*)data;
|
|
|
|
return psp->joypad;
|
2014-02-12 20:03:19 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 05:06:20 +00:00
|
|
|
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,
|
2014-06-09 16:57:17 +00:00
|
|
|
NULL,
|
2013-11-02 23:27:58 +00:00
|
|
|
NULL,
|
|
|
|
psp_input_get_capabilities,
|
|
|
|
"psp",
|
2014-02-13 12:20:47 +00:00
|
|
|
|
2014-02-12 20:03:19 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
psp_input_get_joypad_driver,
|
|
|
|
};
|