RetroArch/input/drivers/psp_input.c

152 lines
3.5 KiB
C
Raw Normal View History

/* RetroArch - A frontend for libretro.
2014-01-01 00:50:59 +00:00
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2015-01-07 16:46:50 +00:00
* Copyright (C) 2011-2015 - Daniel De Matteis
*
* 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
2015-01-12 05:55:31 +00:00
#include "../../gfx/drivers/psp_sdk_defines.h"
2015-01-12 05:16:52 +00:00
#include "../../driver.h"
#include "../../libretro.h"
#include "../../general.h"
#include "../input_common.h"
2014-06-04 00:52:29 +00:00
#ifdef HAVE_KERNEL_PRX
2015-01-12 05:16:52 +00:00
#include "../../psp1/kernel_functions.h"
2014-06-04 00:52:29 +00:00
#endif
#define MAX_PADS 1
typedef struct psp_input
{
const input_device_driver_t *joypad;
} psp_input_t;
static void psp_input_poll(void *data)
{
psp_input_t *psp = (psp_input_t*)data;
2014-02-13 12:20:47 +00:00
if (psp->joypad)
psp->joypad->poll();
}
static int16_t psp_input_state(void *data, const struct retro_keybind **binds,
unsigned port, unsigned device,
2014-10-20 18:31:00 +00:00
unsigned idx, unsigned id)
{
psp_input_t *psp = (psp_input_t*)data;
if (port > 0)
return 0;
switch (device)
{
case RETRO_DEVICE_JOYPAD:
2014-06-09 16:57:17 +00:00
return input_joypad_pressed(psp->joypad, port, binds[port], id);
case RETRO_DEVICE_ANALOG:
2014-10-20 18:31:00 +00:00
return input_joypad_analog(psp->joypad, port, idx, id, binds[port]);
}
return 0;
}
static void psp_input_free_input(void *data)
{
2014-06-09 16:57:17 +00:00
psp_input_t *psp = (psp_input_t*)data;
if (psp && psp->joypad)
2014-06-09 16:57:17 +00:00
psp->joypad->destroy();
2014-06-09 16:57:17 +00:00
free(data);
}
static void* psp_input_initialize(void)
{
2015-03-20 21:32:09 +00:00
settings_t *settings = config_get_ptr();
psp_input_t *psp = (psp_input_t*)calloc(1, sizeof(*psp));
if (!psp)
return NULL;
2014-06-09 16:57:17 +00:00
2015-03-20 21:32:09 +00:00
psp->joypad = input_joypad_init_driver(settings->input.joypad_driver);
return psp;
}
static bool psp_input_key_pressed(void *data, int key)
{
2015-03-20 21:32:09 +00:00
settings_t *settings = config_get_ptr();
2015-03-21 04:42:49 +00:00
global_t *global = global_get_ptr();
psp_input_t *psp = (psp_input_t*)data;
return (global->lifecycle_state & (1ULL << key)) ||
2015-03-20 21:32:09 +00:00
input_joypad_pressed(psp->joypad, 0, settings->input.binds[0], key);
}
static uint64_t psp_input_get_capabilities(void *data)
{
(void)data;
return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG);
}
static const input_device_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;
if (psp)
return psp->joypad;
return NULL;
}
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)
{
(void)data;
(void)port;
(void)effect;
(void)strength;
return false;
}
2014-09-11 05:06:20 +00:00
input_driver_t input_psp = {
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,
NULL,
psp_input_get_capabilities,
"psp",
2014-02-13 12:20:47 +00:00
psp_input_grab_mouse,
2015-03-24 09:30:05 +00:00
psp_input_set_rumble,
psp_input_get_joypad_driver,
};