2012-04-21 23:13:50 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 01:50:59 +01:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2014 - Daniel De Matteis
|
2011-11-30 17:24:18 +01:00
|
|
|
*
|
2012-04-21 23:13:50 +02:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
2011-11-30 17:24:18 +01:00
|
|
|
* 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.
|
|
|
|
*
|
2012-04-21 23:13:50 +02:00
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
2011-11-30 17:24:18 +01:00
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
2012-04-21 23:31:57 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
2011-11-30 17:24:18 +01:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2012-03-05 16:57:43 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
2012-03-19 02:55:13 +01:00
|
|
|
|
2012-07-01 20:45:13 +02:00
|
|
|
#include <sdk_version.h>
|
2014-02-11 07:48:53 +01:00
|
|
|
#include "../boolean.h"
|
2012-07-01 14:10:13 +02:00
|
|
|
|
2014-05-13 17:01:27 +02:00
|
|
|
#include "../ps3/sdk_defines.h"
|
2012-07-01 16:13:25 +02:00
|
|
|
|
2012-03-05 16:57:43 +01:00
|
|
|
#include "../driver.h"
|
2012-04-10 00:22:02 +02:00
|
|
|
#include "../libretro.h"
|
2012-01-21 00:30:01 +01:00
|
|
|
#include "../general.h"
|
2011-11-30 17:24:18 +01:00
|
|
|
|
2012-06-19 05:10:42 +02:00
|
|
|
#ifdef HAVE_MOUSE
|
2012-07-01 16:32:15 +02:00
|
|
|
#ifndef __PSL1GHT__
|
2012-06-19 05:10:42 +02:00
|
|
|
#define MAX_MICE 7
|
2012-07-01 16:32:15 +02:00
|
|
|
#endif
|
2012-06-19 05:10:42 +02:00
|
|
|
#endif
|
|
|
|
|
2013-11-13 00:41:03 +01:00
|
|
|
#ifndef __PSL1GHT__
|
|
|
|
#define MAX_PADS 7
|
|
|
|
#endif
|
|
|
|
|
2013-11-03 20:25:15 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
float z;
|
|
|
|
} sensor_t;
|
|
|
|
|
2013-11-01 16:33:32 +01:00
|
|
|
typedef struct ps3_input
|
|
|
|
{
|
2012-07-01 15:18:26 +02:00
|
|
|
#ifdef HAVE_MOUSE
|
2013-11-01 16:33:32 +01:00
|
|
|
unsigned mice_connected;
|
2012-07-01 15:18:26 +02:00
|
|
|
#endif
|
2014-06-09 16:03:26 +02:00
|
|
|
const rarch_joypad_driver_t *joypad;
|
2013-11-01 16:33:32 +01:00
|
|
|
} ps3_input_t;
|
2012-03-26 00:36:40 +02:00
|
|
|
|
2011-11-30 17:24:18 +01:00
|
|
|
static void ps3_input_poll(void *data)
|
|
|
|
{
|
2013-11-01 16:33:32 +01:00
|
|
|
ps3_input_t *ps3 = (ps3_input_t*)data;
|
2012-12-14 18:37:18 +01:00
|
|
|
|
2014-10-05 17:19:25 +02:00
|
|
|
if (ps3 && ps3->joypad)
|
|
|
|
ps3->joypad->poll();
|
2013-11-03 20:25:15 +01:00
|
|
|
|
2012-06-19 05:10:42 +02:00
|
|
|
#ifdef HAVE_MOUSE
|
2013-10-06 20:28:39 +00:00
|
|
|
CellMouseInfo mouse_info;
|
|
|
|
cellMouseGetInfo(&mouse_info);
|
2013-11-01 16:33:32 +01:00
|
|
|
ps3->mice_connected = mouse_info.now_connect;
|
2012-06-19 05:10:42 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_MOUSE
|
2014-10-05 17:19:25 +02:00
|
|
|
static int16_t ps3_mouse_device_state(ps3_input_t *ps3,
|
|
|
|
unsigned player, unsigned id)
|
2012-06-19 05:10:42 +02:00
|
|
|
{
|
2013-10-06 20:28:39 +00:00
|
|
|
CellMouseData mouse_state;
|
|
|
|
cellMouseGetData(id, &mouse_state);
|
2014-10-05 18:14:40 +02:00
|
|
|
|
|
|
|
if (!ps3->mice_connected)
|
|
|
|
return 0;
|
2012-06-19 05:10:42 +02:00
|
|
|
|
|
|
|
switch (id)
|
|
|
|
{
|
2014-04-25 21:35:13 +02:00
|
|
|
/* TODO: mouse wheel up/down */
|
2012-06-19 05:10:42 +02:00
|
|
|
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
2014-10-05 18:14:40 +02:00
|
|
|
return (mouse_state.buttons & CELL_MOUSE_BUTTON_1);
|
2012-06-19 05:10:42 +02:00
|
|
|
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
2014-10-05 18:14:40 +02:00
|
|
|
return (mouse_state.buttons & CELL_MOUSE_BUTTON_2);
|
2012-06-19 05:10:42 +02:00
|
|
|
case RETRO_DEVICE_ID_MOUSE_X:
|
2014-10-05 18:14:40 +02:00
|
|
|
return (mouse_state.x_axis);
|
2012-06-19 05:10:42 +02:00
|
|
|
case RETRO_DEVICE_ID_MOUSE_Y:
|
2014-10-05 18:14:40 +02:00
|
|
|
return (mouse_state.y_axis);
|
2012-06-19 05:10:42 +02:00
|
|
|
}
|
2014-10-05 17:19:25 +02:00
|
|
|
|
|
|
|
return 0;
|
2011-11-30 17:24:18 +01:00
|
|
|
}
|
|
|
|
|
2012-06-19 05:10:42 +02:00
|
|
|
#endif
|
|
|
|
|
2014-10-05 18:14:40 +02:00
|
|
|
static int16_t ps3_input_state(void *data,
|
|
|
|
const struct retro_keybind **binds,
|
2012-04-10 01:00:25 +02:00
|
|
|
unsigned port, unsigned device,
|
2011-12-02 02:34:06 +01:00
|
|
|
unsigned index, unsigned id)
|
2011-11-30 17:24:18 +01:00
|
|
|
{
|
2013-11-01 16:33:32 +01:00
|
|
|
ps3_input_t *ps3 = (ps3_input_t*)data;
|
2012-04-10 18:07:21 +02:00
|
|
|
|
2014-05-28 23:32:14 +02:00
|
|
|
if (!ps3)
|
|
|
|
return 0;
|
|
|
|
|
2014-10-05 17:19:25 +02:00
|
|
|
switch (device)
|
2012-06-19 05:10:42 +02:00
|
|
|
{
|
2014-10-05 17:19:25 +02:00
|
|
|
case RETRO_DEVICE_JOYPAD:
|
|
|
|
return input_joypad_pressed(ps3->joypad, port, binds[port], id);
|
|
|
|
case RETRO_DEVICE_ANALOG:
|
|
|
|
return input_joypad_analog(ps3->joypad, port, index, id, binds[port]);
|
2014-01-20 17:09:31 +01:00
|
|
|
#if 0
|
2014-10-05 17:19:25 +02:00
|
|
|
case RETRO_DEVICE_SENSOR_ACCELEROMETER:
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
// fixed range of 0x000 - 0x3ff
|
|
|
|
case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_X:
|
|
|
|
retval = ps3->accelerometer_state[port].x;
|
|
|
|
break;
|
|
|
|
case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_Y:
|
|
|
|
retval = ps3->accelerometer_state[port].y;
|
|
|
|
break;
|
|
|
|
case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_Z:
|
|
|
|
retval = ps3->accelerometer_state[port].z;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
retval = 0;
|
|
|
|
}
|
|
|
|
break;
|
2014-01-20 17:09:31 +01:00
|
|
|
#endif
|
2012-06-19 05:10:42 +02:00
|
|
|
#ifdef HAVE_MOUSE
|
2014-10-05 17:19:25 +02:00
|
|
|
case RETRO_DEVICE_MOUSE:
|
|
|
|
return ps3_mouse_device_state(data, port, id);
|
2012-06-19 05:10:42 +02:00
|
|
|
#endif
|
2012-11-03 00:30:41 +01:00
|
|
|
}
|
2011-11-30 17:24:18 +01:00
|
|
|
|
2014-10-05 17:19:25 +02:00
|
|
|
return 0;
|
2011-11-30 17:24:18 +01:00
|
|
|
}
|
|
|
|
|
2012-11-27 00:50:29 +01:00
|
|
|
static void ps3_input_free_input(void *data)
|
2012-07-27 15:46:15 +02:00
|
|
|
{
|
2014-05-28 23:32:14 +02:00
|
|
|
ps3_input_t *ps3 = (ps3_input_t*)data;
|
2014-10-05 17:19:25 +02:00
|
|
|
|
2014-05-28 23:32:14 +02:00
|
|
|
if (!ps3)
|
2013-11-01 16:33:32 +01:00
|
|
|
return;
|
|
|
|
|
2014-06-09 16:03:26 +02:00
|
|
|
if (ps3->joypad)
|
|
|
|
ps3->joypad->destroy();
|
|
|
|
|
2013-11-01 16:33:32 +01:00
|
|
|
#ifdef HAVE_MOUSE
|
2014-05-28 23:32:14 +02:00
|
|
|
cellMouseEnd();
|
2013-11-01 16:33:32 +01:00
|
|
|
#endif
|
2014-05-30 00:02:06 +02:00
|
|
|
free(data);
|
2012-07-27 15:46:15 +02:00
|
|
|
}
|
|
|
|
|
2012-07-28 01:37:15 +02:00
|
|
|
|
2013-03-13 00:34:46 +01:00
|
|
|
static void* ps3_input_init(void)
|
2012-07-27 15:46:15 +02:00
|
|
|
{
|
2013-11-01 16:33:32 +01:00
|
|
|
ps3_input_t *ps3 = (ps3_input_t*)calloc(1, sizeof(*ps3));
|
|
|
|
if (!ps3)
|
|
|
|
return NULL;
|
|
|
|
|
2014-10-05 17:19:25 +02:00
|
|
|
ps3->joypad = input_joypad_init_driver(g_settings.input.joypad_driver);
|
|
|
|
|
|
|
|
if (ps3->joypad)
|
|
|
|
ps3->joypad->init();
|
|
|
|
|
2013-03-13 00:34:46 +01:00
|
|
|
#ifdef HAVE_MOUSE
|
|
|
|
cellMouseInit(MAX_MICE);
|
|
|
|
#endif
|
2013-11-01 16:33:32 +01:00
|
|
|
return ps3;
|
2012-07-27 15:46:15 +02:00
|
|
|
}
|
|
|
|
|
2012-11-27 00:50:29 +01:00
|
|
|
static bool ps3_input_key_pressed(void *data, int key)
|
2011-12-02 02:34:06 +01:00
|
|
|
{
|
2014-06-09 16:09:51 +02:00
|
|
|
ps3_input_t *ps3 = (ps3_input_t*)data;
|
2014-10-05 17:19:25 +02:00
|
|
|
if (ps3)
|
|
|
|
return (g_extern.lifecycle_state & (1ULL << key)) ||
|
|
|
|
input_joypad_pressed(ps3->joypad, 0, g_settings.input.binds[0], key);
|
|
|
|
return false;
|
2011-11-30 17:24:18 +01:00
|
|
|
}
|
|
|
|
|
2013-11-02 21:16:57 +01:00
|
|
|
static uint64_t ps3_input_get_capabilities(void *data)
|
|
|
|
{
|
2014-10-05 17:19:25 +02:00
|
|
|
(void)data;
|
|
|
|
return
|
2013-11-02 21:16:57 +01:00
|
|
|
#ifdef HAVE_MOUSE
|
2014-10-05 17:19:25 +02:00
|
|
|
(1 << RETRO_DEVICE_MOUSE) |
|
2013-11-02 21:16:57 +01:00
|
|
|
#endif
|
2014-10-05 17:19:25 +02:00
|
|
|
(1 << RETRO_DEVICE_JOYPAD) |
|
|
|
|
(1 << RETRO_DEVICE_ANALOG);
|
2013-11-02 21:16:57 +01:00
|
|
|
}
|
|
|
|
|
2014-10-05 17:19:25 +02:00
|
|
|
static bool ps3_input_set_sensor_state(void *data, unsigned port,
|
|
|
|
enum retro_sensor_action action, unsigned event_rate)
|
2013-11-03 20:25:15 +01:00
|
|
|
{
|
|
|
|
CellPadInfo2 pad_info;
|
|
|
|
(void)event_rate;
|
|
|
|
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case RETRO_SENSOR_ACCELEROMETER_ENABLE:
|
|
|
|
cellPadGetInfo2(&pad_info);
|
2014-10-05 17:19:25 +02:00
|
|
|
if ((pad_info.device_capability[port]
|
|
|
|
& CELL_PAD_CAPABILITY_SENSOR_MODE)
|
|
|
|
!= CELL_PAD_CAPABILITY_SENSOR_MODE)
|
2013-11-03 20:25:15 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
cellPadSetPortSetting(port, CELL_PAD_SETTING_SENSOR_ON);
|
|
|
|
return true;
|
|
|
|
case RETRO_SENSOR_ACCELEROMETER_DISABLE:
|
|
|
|
cellPadSetPortSetting(port, 0);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-05 17:19:25 +02:00
|
|
|
static bool ps3_input_set_rumble(void *data, unsigned port,
|
|
|
|
enum retro_rumble_effect effect, uint16_t strength)
|
2013-11-03 20:55:07 +01:00
|
|
|
{
|
2014-10-05 18:29:22 +02:00
|
|
|
ps3_input_t *ps3 = (ps3_input_t*)data;
|
2013-11-03 20:55:07 +01:00
|
|
|
|
2014-10-05 18:29:22 +02:00
|
|
|
if (ps3 && ps3->joypad)
|
|
|
|
return input_joypad_set_rumble(ps3->joypad,
|
|
|
|
port, effect, strength);
|
|
|
|
return false;
|
2013-11-03 20:55:07 +01:00
|
|
|
}
|
|
|
|
|
2013-12-26 18:07:09 +01:00
|
|
|
static const rarch_joypad_driver_t *ps3_input_get_joypad_driver(void *data)
|
|
|
|
{
|
2014-06-09 16:03:26 +02:00
|
|
|
ps3_input_t *ps3 = (ps3_input_t*)data;
|
2014-10-05 18:30:23 +02:00
|
|
|
if (ps3)
|
|
|
|
return ps3->joypad;
|
|
|
|
return NULL;
|
2013-12-26 18:07:09 +01:00
|
|
|
}
|
|
|
|
|
2014-09-11 07:06:20 +02:00
|
|
|
input_driver_t input_ps3 = {
|
2013-11-02 21:16:57 +01:00
|
|
|
ps3_input_init,
|
|
|
|
ps3_input_poll,
|
|
|
|
ps3_input_state,
|
|
|
|
ps3_input_key_pressed,
|
|
|
|
ps3_input_free_input,
|
2013-11-03 20:25:15 +01:00
|
|
|
ps3_input_set_sensor_state,
|
2014-01-20 14:52:53 +01:00
|
|
|
NULL,
|
2013-11-02 21:16:57 +01:00
|
|
|
ps3_input_get_capabilities,
|
|
|
|
"ps3",
|
2011-12-11 13:14:44 +01:00
|
|
|
|
2013-11-03 20:55:07 +01:00
|
|
|
NULL,
|
|
|
|
ps3_input_set_rumble,
|
2013-12-26 18:07:09 +01:00
|
|
|
ps3_input_get_joypad_driver,
|
|
|
|
};
|