2012-11-23 02:40:03 +01:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 01:50:59 +01:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2017-01-22 13:40:32 +01:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2015-08-31 15:26:37 +02:00
|
|
|
*
|
2012-11-23 02:40:03 +01: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>
|
|
|
|
|
2016-09-11 13:21:56 +02:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../../config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-11-23 02:40:03 +01:00
|
|
|
#if defined(SN_TARGET_PSP2)
|
|
|
|
#include <sceerror.h>
|
|
|
|
#include <kernel.h>
|
|
|
|
#include <ctrl.h>
|
2015-08-10 23:04:09 +02:00
|
|
|
#elif defined(VITA)
|
|
|
|
#include <psp2/ctrl.h>
|
2012-11-23 02:40:03 +01:00
|
|
|
#elif defined(PSP)
|
|
|
|
#include <pspctrl.h>
|
|
|
|
#endif
|
|
|
|
|
2016-05-10 19:03:53 +02:00
|
|
|
#include <boolean.h>
|
|
|
|
#include <libretro.h>
|
2017-01-17 18:12:23 +01:00
|
|
|
#include <retro_miscellaneous.h>
|
2016-05-10 19:03:53 +02:00
|
|
|
|
2016-09-11 13:21:56 +02:00
|
|
|
#ifdef HAVE_KERNEL_PRX
|
|
|
|
#include "../../bootstrap/psp1/kernel_functions.h"
|
|
|
|
#endif
|
|
|
|
|
2015-08-10 23:11:40 +02:00
|
|
|
#include "../../defines/psp_defines.h"
|
2012-11-23 02:40:03 +01:00
|
|
|
|
2017-01-10 17:59:48 +01:00
|
|
|
#include "../input_driver.h"
|
2012-11-23 02:40:03 +01:00
|
|
|
|
2018-07-15 14:34:02 +02:00
|
|
|
/* TODO/FIXME -
|
|
|
|
* fix game focus toggle */
|
|
|
|
|
2014-02-12 21:03:19 +01:00
|
|
|
typedef struct psp_input
|
2012-11-23 02:40:03 +01:00
|
|
|
{
|
2015-06-19 03:45:23 +02:00
|
|
|
bool blocked;
|
2015-04-14 16:37:59 +02:00
|
|
|
const input_device_driver_t *joypad;
|
2014-02-12 21:03:19 +01:00
|
|
|
} psp_input_t;
|
2012-11-23 02:40:03 +01:00
|
|
|
|
2014-02-12 21:03:19 +01:00
|
|
|
static void psp_input_poll(void *data)
|
|
|
|
{
|
|
|
|
psp_input_t *psp = (psp_input_t*)data;
|
2014-02-13 13:20:47 +01:00
|
|
|
|
2017-04-26 22:26:41 +02:00
|
|
|
if (psp && psp->joypad)
|
2014-10-05 17:28:57 +02:00
|
|
|
psp->joypad->poll();
|
2012-11-23 02:40:03 +01:00
|
|
|
}
|
|
|
|
|
2017-01-10 17:40:21 +01:00
|
|
|
static int16_t psp_input_state(void *data,
|
|
|
|
rarch_joypad_info_t joypad_info,
|
|
|
|
const struct retro_keybind **binds,
|
2012-11-23 02:40:03 +01:00
|
|
|
unsigned port, unsigned device,
|
2014-10-20 20:31:00 +02:00
|
|
|
unsigned idx, unsigned id)
|
2012-11-23 02:40:03 +01:00
|
|
|
{
|
2017-01-10 03:44:53 +01:00
|
|
|
psp_input_t *psp = (psp_input_t*)data;
|
2012-11-23 02:40:03 +01:00
|
|
|
|
2016-08-07 16:29:58 +02:00
|
|
|
#if !defined(SN_TARGET_PSP2) && !defined(VITA)
|
2014-02-12 21:03:19 +01:00
|
|
|
if (port > 0)
|
|
|
|
return 0;
|
2016-08-07 16:29:58 +02:00
|
|
|
#endif
|
2012-11-23 02:40:03 +01:00
|
|
|
|
|
|
|
switch (device)
|
|
|
|
{
|
|
|
|
case RETRO_DEVICE_JOYPAD:
|
2017-01-10 17:05:04 +01:00
|
|
|
return input_joypad_pressed(psp->joypad, joypad_info, port, binds[port], id);
|
2014-02-12 21:03:19 +01:00
|
|
|
case RETRO_DEVICE_ANALOG:
|
2016-10-26 10:29:26 +02:00
|
|
|
if (binds[port])
|
2017-01-10 03:53:57 +01:00
|
|
|
return input_joypad_analog(psp->joypad, joypad_info, port, idx, id, binds[port]);
|
2016-10-26 10:29:26 +02:00
|
|
|
break;
|
2012-11-23 02:40:03 +01:00
|
|
|
}
|
|
|
|
|
2014-02-12 21:03:19 +01:00
|
|
|
return 0;
|
2012-11-23 02:40:03 +01:00
|
|
|
}
|
|
|
|
|
2013-03-14 02:24:57 +01:00
|
|
|
static void psp_input_free_input(void *data)
|
2012-11-23 02:40:03 +01:00
|
|
|
{
|
2014-06-09 18:57:17 +02:00
|
|
|
psp_input_t *psp = (psp_input_t*)data;
|
2014-02-12 21:03:19 +01:00
|
|
|
|
2014-10-05 17:28:57 +02:00
|
|
|
if (psp && psp->joypad)
|
2014-06-09 18:57:17 +02:00
|
|
|
psp->joypad->destroy();
|
2013-03-13 16:06:13 +01:00
|
|
|
|
2014-06-09 18:57:17 +02:00
|
|
|
free(data);
|
2013-03-13 00:34:46 +01:00
|
|
|
}
|
|
|
|
|
2017-01-10 17:59:48 +01:00
|
|
|
static void* psp_input_initialize(const char *joypad_driver)
|
2012-11-23 02:40:03 +01:00
|
|
|
{
|
2014-02-12 21:09:11 +01:00
|
|
|
psp_input_t *psp = (psp_input_t*)calloc(1, sizeof(*psp));
|
|
|
|
if (!psp)
|
|
|
|
return NULL;
|
2015-08-31 15:26:37 +02:00
|
|
|
|
2017-01-10 17:59:48 +01:00
|
|
|
psp->joypad = input_joypad_init_driver(joypad_driver, psp);
|
2014-02-12 21:09:11 +01:00
|
|
|
|
|
|
|
return psp;
|
2012-11-23 02:40:03 +01:00
|
|
|
}
|
|
|
|
|
2013-11-03 00:27:58 +01:00
|
|
|
static uint64_t psp_input_get_capabilities(void *data)
|
|
|
|
{
|
2014-10-05 17:28:57 +02:00
|
|
|
(void)data;
|
2013-11-03 00:27:58 +01:00
|
|
|
|
2014-10-05 17:28:57 +02:00
|
|
|
return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG);
|
2013-11-03 00:27:58 +01:00
|
|
|
}
|
|
|
|
|
2015-04-14 16:37:59 +02:00
|
|
|
static const input_device_driver_t *psp_input_get_joypad_driver(void *data)
|
2014-02-12 21:03:19 +01:00
|
|
|
{
|
2014-06-09 18:57:17 +02:00
|
|
|
psp_input_t *psp = (psp_input_t*)data;
|
2014-10-05 17:28:57 +02:00
|
|
|
if (psp)
|
|
|
|
return psp->joypad;
|
|
|
|
return NULL;
|
2014-02-12 21:03:19 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 07:51:50 +01:00
|
|
|
static void psp_input_grab_mouse(void *data, bool state)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool psp_input_set_rumble(void *data, unsigned port,
|
|
|
|
enum retro_rumble_effect effect, uint16_t strength)
|
|
|
|
{
|
2016-08-30 14:29:19 +02:00
|
|
|
psp_input_t *psp = (psp_input_t*)data;
|
2015-03-24 07:51:50 +01:00
|
|
|
|
2016-08-30 14:29:19 +02:00
|
|
|
if (psp && psp->joypad)
|
|
|
|
return input_joypad_set_rumble(psp->joypad,
|
|
|
|
port, effect, strength);
|
2015-03-24 07:51:50 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-19 03:45:23 +02:00
|
|
|
static bool psp_input_keyboard_mapping_is_blocked(void *data)
|
|
|
|
{
|
|
|
|
psp_input_t *psp = (psp_input_t*)data;
|
|
|
|
if (!psp)
|
|
|
|
return false;
|
|
|
|
return psp->blocked;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void psp_input_keyboard_mapping_set_block(void *data, bool value)
|
|
|
|
{
|
|
|
|
psp_input_t *psp = (psp_input_t*)data;
|
|
|
|
if (!psp)
|
|
|
|
return;
|
|
|
|
psp->blocked = value;
|
|
|
|
}
|
|
|
|
|
2014-09-11 07:06:20 +02:00
|
|
|
input_driver_t input_psp = {
|
2013-11-03 00:27:58 +01:00
|
|
|
psp_input_initialize,
|
|
|
|
psp_input_poll,
|
|
|
|
psp_input_state,
|
|
|
|
psp_input_free_input,
|
2014-06-09 18:57:17 +02:00
|
|
|
NULL,
|
2013-11-03 00:27:58 +01:00
|
|
|
NULL,
|
|
|
|
psp_input_get_capabilities,
|
2015-08-31 15:26:37 +02:00
|
|
|
#ifdef VITA
|
|
|
|
"vita",
|
|
|
|
#else
|
2013-11-03 00:27:58 +01:00
|
|
|
"psp",
|
2015-08-31 15:26:37 +02:00
|
|
|
#endif
|
2014-02-13 13:20:47 +01:00
|
|
|
|
2015-03-24 07:51:50 +01:00
|
|
|
psp_input_grab_mouse,
|
2015-05-19 19:33:58 +02:00
|
|
|
NULL,
|
2015-03-24 10:30:05 +01:00
|
|
|
psp_input_set_rumble,
|
2014-02-12 21:03:19 +01:00
|
|
|
psp_input_get_joypad_driver,
|
2015-11-16 02:39:38 +01:00
|
|
|
NULL,
|
2015-06-19 03:45:23 +02:00
|
|
|
psp_input_keyboard_mapping_is_blocked,
|
|
|
|
psp_input_keyboard_mapping_set_block,
|
2014-02-12 21:03:19 +01:00
|
|
|
};
|