2012-04-21 21:13:50 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2013-01-01 00:37:37 +00:00
|
|
|
* Copyright (C) 2010-2013 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2013 - Daniel De Matteis
|
2011-11-30 16:24:18 +00:00
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
2011-11-30 16:24:18 +00: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 21:13:50 +00:00
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
2011-11-30 16:24:18 +00: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 21:31:57 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
2011-11-30 16:24:18 +00:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2012-03-05 15:57:43 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
2012-03-19 01:55:13 +00:00
|
|
|
|
2012-07-01 18:45:13 +00:00
|
|
|
#ifndef __PSL1GHT__
|
|
|
|
#include <sdk_version.h>
|
|
|
|
#endif
|
|
|
|
|
2012-03-25 22:36:40 +00:00
|
|
|
#include <sys/memory.h>
|
2012-07-01 12:10:13 +00:00
|
|
|
|
2012-07-01 14:13:25 +00:00
|
|
|
#include "sdk_defines.h"
|
|
|
|
|
2012-01-11 21:27:07 +00:00
|
|
|
#include "ps3_input.h"
|
2012-03-05 15:57:43 +00:00
|
|
|
#include "../driver.h"
|
2012-04-09 22:22:02 +00:00
|
|
|
#include "../libretro.h"
|
2012-01-20 23:30:01 +00:00
|
|
|
#include "../general.h"
|
2011-11-30 16:24:18 +00:00
|
|
|
|
2012-06-19 03:10:42 +00:00
|
|
|
#ifdef HAVE_MOUSE
|
2012-07-01 14:32:15 +00:00
|
|
|
#ifndef __PSL1GHT__
|
2012-06-19 03:10:42 +00:00
|
|
|
#define MAX_MICE 7
|
2012-07-01 14:32:15 +00:00
|
|
|
#endif
|
2012-06-19 03:10:42 +00:00
|
|
|
#endif
|
|
|
|
|
2012-03-25 22:36:40 +00:00
|
|
|
/*============================================================
|
2012-11-02 23:30:41 +00:00
|
|
|
PS3 PAD
|
|
|
|
============================================================ */
|
2012-03-19 01:55:13 +00:00
|
|
|
|
2013-11-03 19:25:15 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
float z;
|
|
|
|
} sensor_t;
|
|
|
|
|
2012-07-25 17:35:21 +00:00
|
|
|
const struct platform_bind platform_keys[] = {
|
2012-12-14 16:42:01 +00:00
|
|
|
{ (1ULL << RETRO_DEVICE_ID_JOYPAD_B), "Cross button" },
|
|
|
|
{ (1ULL << RETRO_DEVICE_ID_JOYPAD_Y), "Square button" },
|
|
|
|
{ (1ULL << RETRO_DEVICE_ID_JOYPAD_SELECT), "Select button" },
|
|
|
|
{ (1ULL << RETRO_DEVICE_ID_JOYPAD_START), "Start button" },
|
|
|
|
{ (1ULL << RETRO_DEVICE_ID_JOYPAD_UP), "D-Pad Up" },
|
|
|
|
{ (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN), "D-Pad Down" },
|
|
|
|
{ (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT), "D-Pad Left" },
|
|
|
|
{ (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT), "D-Pad Right" },
|
|
|
|
{ (1ULL << RETRO_DEVICE_ID_JOYPAD_A), "Circle button" },
|
|
|
|
{ (1ULL << RETRO_DEVICE_ID_JOYPAD_X), "Triangle button" },
|
|
|
|
{ (1ULL << RETRO_DEVICE_ID_JOYPAD_L), "L1 button" },
|
|
|
|
{ (1ULL << RETRO_DEVICE_ID_JOYPAD_R), "R1 button" },
|
|
|
|
{ (1ULL << RETRO_DEVICE_ID_JOYPAD_L2), "L2 button" },
|
|
|
|
{ (1ULL << RETRO_DEVICE_ID_JOYPAD_R2), "R2 button" },
|
|
|
|
{ (1ULL << RETRO_DEVICE_ID_JOYPAD_L3), "L3 button" },
|
|
|
|
{ (1ULL << RETRO_DEVICE_ID_JOYPAD_R3), "R3 button" },
|
2013-11-02 00:25:25 +00:00
|
|
|
{ (1ULL << RARCH_TURBO_ENABLE), "Turbo button (unmapped)" },
|
2012-07-25 17:35:21 +00:00
|
|
|
};
|
|
|
|
|
2013-11-01 15:33:32 +00:00
|
|
|
typedef struct ps3_input
|
|
|
|
{
|
|
|
|
uint64_t state[MAX_PADS];
|
|
|
|
unsigned pads_connected;
|
2012-07-01 13:18:26 +00:00
|
|
|
#ifdef HAVE_MOUSE
|
2013-11-01 15:33:32 +00:00
|
|
|
unsigned mice_connected;
|
2012-07-01 13:18:26 +00:00
|
|
|
#endif
|
2013-11-03 19:25:15 +00:00
|
|
|
sensor_t accelerometer_state[MAX_PADS];
|
2013-11-01 15:33:32 +00:00
|
|
|
} ps3_input_t;
|
2012-03-25 22:36:40 +00:00
|
|
|
|
2013-11-06 22:10:12 +00:00
|
|
|
uint8_t analog_state[MAX_PADS][2][2];
|
2013-11-03 18:39:43 +00:00
|
|
|
|
2011-11-30 16:24:18 +00:00
|
|
|
static void ps3_input_poll(void *data)
|
|
|
|
{
|
2012-07-16 19:49:51 +00:00
|
|
|
CellPadInfo2 pad_info;
|
2013-11-01 15:33:32 +00:00
|
|
|
ps3_input_t *ps3 = (ps3_input_t*)data;
|
2012-07-01 20:14:09 +00:00
|
|
|
|
2013-11-03 18:39:43 +00:00
|
|
|
for (unsigned port = 0; port < MAX_PADS; port++)
|
2012-07-31 22:00:44 +00:00
|
|
|
{
|
|
|
|
static CellPadData state_tmp;
|
2013-11-03 18:39:43 +00:00
|
|
|
cellPadGetData(port, &state_tmp);
|
2012-07-31 22:00:44 +00:00
|
|
|
|
|
|
|
if (state_tmp.len != 0)
|
|
|
|
{
|
2013-11-03 18:39:43 +00:00
|
|
|
uint64_t *state_cur = &ps3->state[port];
|
2013-01-05 20:56:19 +00:00
|
|
|
*state_cur = 0;
|
2013-11-03 18:39:43 +00:00
|
|
|
analog_state[0][0][0] = analog_state[0][0][1] = analog_state[0][1][0] = analog_state[0][1][1] = 0;
|
|
|
|
analog_state[1][0][0] = analog_state[1][0][1] = analog_state[1][1][0] = analog_state[1][1][1] = 0;
|
|
|
|
analog_state[2][0][0] = analog_state[2][0][1] = analog_state[2][1][0] = analog_state[2][1][1] = 0;
|
|
|
|
analog_state[3][0][0] = analog_state[3][0][1] = analog_state[3][1][0] = analog_state[3][1][1] = 0;
|
2012-08-09 05:29:56 +00:00
|
|
|
#ifdef __PSL1GHT__
|
2013-01-05 20:56:19 +00:00
|
|
|
*state_cur |= (state_tmp.BTN_LEFT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
|
|
|
|
*state_cur |= (state_tmp.BTN_DOWN) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
|
|
|
|
*state_cur |= (state_tmp.BTN_RIGHT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
|
|
|
|
*state_cur |= (state_tmp.BTN_UP) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
|
|
|
|
*state_cur |= (state_tmp.BTN_START) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_START) : 0;
|
|
|
|
*state_cur |= (state_tmp.BTN_R3) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R3) : 0;
|
|
|
|
*state_cur |= (state_tmp.BTN_L3) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L3) : 0;
|
|
|
|
*state_cur |= (state_tmp.BTN_SELECT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0;
|
|
|
|
*state_cur |= (state_tmp.BTN_TRIANGLE) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_X) : 0;
|
|
|
|
*state_cur |= (state_tmp.BTN_SQUARE) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_Y) : 0;
|
|
|
|
*state_cur |= (state_tmp.BTN_CROSS) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_B) : 0;
|
|
|
|
*state_cur |= (state_tmp.BTN_CIRCLE) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_A) : 0;
|
|
|
|
*state_cur |= (state_tmp.BTN_R1) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R) : 0;
|
|
|
|
*state_cur |= (state_tmp.BTN_L1) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L) : 0;
|
|
|
|
*state_cur |= (state_tmp.BTN_R2) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R2) : 0;
|
|
|
|
*state_cur |= (state_tmp.BTN_L2) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L2) : 0;
|
2012-08-09 05:29:56 +00:00
|
|
|
#else
|
2013-01-05 20:56:19 +00:00
|
|
|
*state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL1] & CELL_PAD_CTRL_LEFT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
|
|
|
|
*state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL1] & CELL_PAD_CTRL_DOWN) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
|
|
|
|
*state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL1] & CELL_PAD_CTRL_RIGHT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
|
|
|
|
*state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL1] & CELL_PAD_CTRL_UP) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
|
|
|
|
*state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL1] & CELL_PAD_CTRL_START) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_START) : 0;
|
|
|
|
*state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL1] & CELL_PAD_CTRL_R3) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R3) : 0;
|
|
|
|
*state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL1] & CELL_PAD_CTRL_L3) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L3) : 0;
|
|
|
|
*state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL1] & CELL_PAD_CTRL_SELECT) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0;
|
|
|
|
*state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_PAD_CTRL_TRIANGLE) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_X) : 0;
|
|
|
|
*state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_PAD_CTRL_SQUARE) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_Y) : 0;
|
|
|
|
*state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_PAD_CTRL_CROSS) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_B) : 0;
|
|
|
|
*state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_PAD_CTRL_CIRCLE) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_A) : 0;
|
|
|
|
*state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_PAD_CTRL_R1) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R) : 0;
|
|
|
|
*state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_PAD_CTRL_L1) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L) : 0;
|
|
|
|
*state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_PAD_CTRL_R2) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R2) : 0;
|
|
|
|
*state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_PAD_CTRL_L2) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L2) : 0;
|
2013-11-03 18:39:43 +00:00
|
|
|
*state_cur |= (state_tmp.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_PAD_CTRL_L2) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L2) : 0;
|
2013-11-06 22:10:12 +00:00
|
|
|
analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT ][RETRO_DEVICE_ID_ANALOG_X] = state_tmp.button[CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X];
|
|
|
|
analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT ][RETRO_DEVICE_ID_ANALOG_Y] = state_tmp.button[CELL_PAD_BTN_OFFSET_ANALOG_LEFT_Y];
|
|
|
|
analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = state_tmp.button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X];
|
|
|
|
analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = state_tmp.button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_Y];
|
2013-11-03 19:25:15 +00:00
|
|
|
ps3->accelerometer_state[port].x = state_tmp.button[CELL_PAD_BTN_OFFSET_SENSOR_X];
|
|
|
|
ps3->accelerometer_state[port].y = state_tmp.button[CELL_PAD_BTN_OFFSET_SENSOR_Y];
|
|
|
|
ps3->accelerometer_state[port].z = state_tmp.button[CELL_PAD_BTN_OFFSET_SENSOR_Z];
|
2012-08-09 05:29:56 +00:00
|
|
|
#endif
|
2012-07-31 22:00:44 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-10 16:07:21 +00:00
|
|
|
|
2013-11-01 15:33:32 +00:00
|
|
|
uint64_t *state_p1 = &ps3->state[0];
|
2013-01-06 23:31:38 +00:00
|
|
|
uint64_t *lifecycle_state = &g_extern.lifecycle_state;
|
|
|
|
|
2013-11-07 20:44:44 +00:00
|
|
|
*lifecycle_state &= ~((1ULL << RARCH_MENU_TOGGLE));
|
2013-01-06 23:31:38 +00:00
|
|
|
|
2013-04-18 21:54:15 +00:00
|
|
|
if ((*state_p1 & (1ULL << RETRO_DEVICE_ID_JOYPAD_L3)) && (*state_p1 & (1ULL << RETRO_DEVICE_ID_JOYPAD_R3)))
|
|
|
|
*lifecycle_state |= (1ULL << RARCH_MENU_TOGGLE);
|
2012-12-14 17:37:18 +00:00
|
|
|
|
2012-07-16 19:49:51 +00:00
|
|
|
cellPadGetInfo2(&pad_info);
|
2013-11-01 15:33:32 +00:00
|
|
|
ps3->pads_connected = pad_info.now_connect;
|
2013-11-03 19:25:15 +00:00
|
|
|
|
2012-06-19 03:10:42 +00:00
|
|
|
#ifdef HAVE_MOUSE
|
2013-10-06 20:28:39 +00:00
|
|
|
CellMouseInfo mouse_info;
|
|
|
|
cellMouseGetInfo(&mouse_info);
|
2013-11-01 15:33:32 +00:00
|
|
|
ps3->mice_connected = mouse_info.now_connect;
|
2012-06-19 03:10:42 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_MOUSE
|
|
|
|
|
|
|
|
static int16_t ps3_mouse_device_state(void *data, unsigned player, unsigned id)
|
|
|
|
{
|
2013-11-01 15:33:32 +00:00
|
|
|
ps3_input_t *ps3 = (ps3_input_t*)data;
|
2013-10-06 20:28:39 +00:00
|
|
|
CellMouseData mouse_state;
|
|
|
|
cellMouseGetData(id, &mouse_state);
|
2012-06-19 03:10:42 +00:00
|
|
|
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
2013-11-01 15:33:32 +00:00
|
|
|
return (!ps3->mice_connected ? 0 : mouse_state.buttons & CELL_MOUSE_BUTTON_1);
|
2012-06-19 03:10:42 +00:00
|
|
|
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
2013-11-01 15:33:32 +00:00
|
|
|
return (!ps3->mice_connected ? 0 : mouse_state.buttons & CELL_MOUSE_BUTTON_2);
|
2012-06-19 03:10:42 +00:00
|
|
|
case RETRO_DEVICE_ID_MOUSE_X:
|
2013-11-01 15:33:32 +00:00
|
|
|
return (!ps3->mice_connected ? 0 : mouse_state.x_axis);
|
2012-06-19 03:10:42 +00:00
|
|
|
case RETRO_DEVICE_ID_MOUSE_Y:
|
2013-11-01 15:33:32 +00:00
|
|
|
return (!ps3->mice_connected ? 0 : mouse_state.y_axis);
|
2012-06-19 03:10:42 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2011-11-30 16:24:18 +00:00
|
|
|
}
|
|
|
|
|
2012-06-19 03:10:42 +00:00
|
|
|
#endif
|
|
|
|
|
2012-07-07 15:19:32 +00:00
|
|
|
static int16_t ps3_input_state(void *data, const struct retro_keybind **binds,
|
2012-04-09 23:00:25 +00:00
|
|
|
unsigned port, unsigned device,
|
2011-12-02 01:34:06 +00:00
|
|
|
unsigned index, unsigned id)
|
2011-11-30 16:24:18 +00:00
|
|
|
{
|
2013-11-01 15:33:32 +00:00
|
|
|
ps3_input_t *ps3 = (ps3_input_t*)data;
|
2013-11-07 04:21:09 +00:00
|
|
|
uint64_t button;
|
2012-06-19 03:10:42 +00:00
|
|
|
int16_t retval = 0;
|
2012-04-10 16:07:21 +00:00
|
|
|
|
2013-11-03 18:39:43 +00:00
|
|
|
if (port < ps3->pads_connected)
|
2012-06-19 03:10:42 +00:00
|
|
|
{
|
|
|
|
switch (device)
|
|
|
|
{
|
|
|
|
case RETRO_DEVICE_JOYPAD:
|
2013-11-07 04:21:09 +00:00
|
|
|
button = binds[port][id].joykey;
|
2013-11-03 18:39:43 +00:00
|
|
|
retval = (ps3->state[port] & button) ? 1 : 0;
|
|
|
|
break;
|
|
|
|
case RETRO_DEVICE_ANALOG:
|
2013-11-06 22:10:12 +00:00
|
|
|
{
|
|
|
|
int analog = (analog_state[port][index][id] - 128) * 0x0101;
|
|
|
|
if (analog < -0x7fff)
|
|
|
|
analog = -0x7fff;
|
|
|
|
retval = analog;
|
|
|
|
}
|
2012-06-19 03:10:42 +00:00
|
|
|
break;
|
2013-11-03 19:25:15 +00: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;
|
2013-11-11 11:36:34 +00:00
|
|
|
break;
|
2013-11-03 19:25:15 +00:00
|
|
|
case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_Y:
|
|
|
|
retval = ps3->accelerometer_state[port].y;
|
2013-11-11 11:36:34 +00:00
|
|
|
break;
|
2013-11-03 19:25:15 +00:00
|
|
|
case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_Z:
|
|
|
|
retval = ps3->accelerometer_state[port].z;
|
2013-11-11 11:36:34 +00:00
|
|
|
break;
|
2013-11-03 19:25:15 +00:00
|
|
|
default:
|
|
|
|
retval = 0;
|
|
|
|
}
|
|
|
|
break;
|
2012-06-19 03:10:42 +00:00
|
|
|
#ifdef HAVE_MOUSE
|
|
|
|
case RETRO_DEVICE_MOUSE:
|
2013-11-03 18:39:43 +00:00
|
|
|
retval = ps3_mouse_device_state(data, port, id);
|
2012-06-19 03:10:42 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2013-11-07 04:21:09 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
2012-06-19 03:10:42 +00:00
|
|
|
}
|
2012-11-02 23:30:41 +00:00
|
|
|
}
|
2011-11-30 16:24:18 +00:00
|
|
|
|
2012-04-10 16:07:21 +00:00
|
|
|
return retval;
|
2011-11-30 16:24:18 +00:00
|
|
|
}
|
|
|
|
|
2012-03-25 22:36:40 +00:00
|
|
|
/*============================================================
|
2012-11-02 23:30:41 +00:00
|
|
|
ON-SCREEN KEYBOARD UTILITY
|
|
|
|
============================================================ */
|
2012-03-25 22:36:40 +00:00
|
|
|
|
2013-11-11 15:58:12 +00:00
|
|
|
#ifdef HAVE_OSK
|
2012-06-19 03:10:42 +00:00
|
|
|
|
2012-04-10 19:23:42 +00:00
|
|
|
#define OSK_IN_USE 1
|
2012-03-25 22:36:40 +00:00
|
|
|
|
2013-11-12 16:16:11 +00:00
|
|
|
void *oskutil_init(size_t size)
|
2012-03-25 22:36:40 +00:00
|
|
|
{
|
2013-11-11 15:58:12 +00:00
|
|
|
ps3_osk_t *params = (ps3_osk_t*)calloc(1, sizeof(*params));
|
|
|
|
|
|
|
|
if (!params)
|
|
|
|
return NULL;
|
|
|
|
|
2012-03-25 22:36:40 +00:00
|
|
|
params->flags = 0;
|
2013-11-12 16:16:11 +00:00
|
|
|
if (size)
|
|
|
|
params->osk_memorycontainer = size;
|
2012-03-25 22:36:40 +00:00
|
|
|
else
|
2013-01-17 09:40:35 +00:00
|
|
|
params->osk_memorycontainer = 1024*1024*2;
|
2013-11-11 15:58:12 +00:00
|
|
|
|
|
|
|
return params;
|
2012-03-25 22:36:40 +00:00
|
|
|
}
|
|
|
|
|
2013-11-11 15:58:12 +00:00
|
|
|
void oskutil_free(void *data)
|
2012-03-25 22:36:40 +00:00
|
|
|
{
|
2013-11-11 15:58:12 +00:00
|
|
|
ps3_osk_t *params = (ps3_osk_t*)data;
|
|
|
|
|
|
|
|
if (params)
|
|
|
|
free(params);
|
|
|
|
}
|
|
|
|
|
2013-11-12 16:16:11 +00:00
|
|
|
static bool oskutil_enable_key_layout(void *data)
|
2013-11-11 15:58:12 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
|
|
|
|
if (pOskSetKeyLayoutOption(CELL_OSKDIALOG_10KEY_PANEL | CELL_OSKDIALOG_FULLKEY_PANEL) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2012-03-25 22:36:40 +00:00
|
|
|
}
|
|
|
|
|
2013-11-11 15:58:12 +00:00
|
|
|
static void oskutil_create_activation_parameters(void *data)
|
2012-03-25 22:36:40 +00:00
|
|
|
{
|
2013-11-11 15:58:12 +00:00
|
|
|
ps3_osk_t *params = (ps3_osk_t*)data;
|
2012-03-25 22:36:40 +00:00
|
|
|
params->dialogParam.controlPoint.x = 0.0;
|
|
|
|
params->dialogParam.controlPoint.y = 0.0;
|
|
|
|
|
|
|
|
int32_t LayoutMode = CELL_OSKDIALOG_LAYOUTMODE_X_ALIGN_CENTER | CELL_OSKDIALOG_LAYOUTMODE_Y_ALIGN_TOP;
|
2012-07-01 18:45:13 +00:00
|
|
|
pOskSetLayoutMode(LayoutMode);
|
2012-03-25 22:36:40 +00:00
|
|
|
|
2012-07-01 18:45:13 +00:00
|
|
|
params->dialogParam.osk_allowed_panels =
|
2012-11-02 23:30:41 +00:00
|
|
|
CELL_OSKDIALOG_PANELMODE_ALPHABET |
|
|
|
|
CELL_OSKDIALOG_PANELMODE_NUMERAL |
|
|
|
|
CELL_OSKDIALOG_PANELMODE_NUMERAL_FULL_WIDTH |
|
|
|
|
CELL_OSKDIALOG_PANELMODE_ENGLISH;
|
2012-03-25 22:36:40 +00:00
|
|
|
|
|
|
|
params->dialogParam.firstViewPanel = CELL_OSKDIALOG_PANELMODE_ENGLISH;
|
2012-07-01 18:45:13 +00:00
|
|
|
params->dialogParam.osk_prohibit_flags = 0;
|
2012-03-25 22:36:40 +00:00
|
|
|
}
|
|
|
|
|
2013-11-11 15:58:12 +00:00
|
|
|
void oskutil_write_message(void *data, const void *data_msg)
|
2012-03-25 22:36:40 +00:00
|
|
|
{
|
2013-11-11 15:58:12 +00:00
|
|
|
ps3_osk_t *params = (ps3_osk_t*)data;
|
|
|
|
const wchar_t *msg = (const wchar_t*)data_msg;
|
2012-07-01 18:45:13 +00:00
|
|
|
params->inputFieldInfo.osk_inputfield_message = (uint16_t*)msg;
|
2012-03-25 22:36:40 +00:00
|
|
|
}
|
|
|
|
|
2013-11-11 15:58:12 +00:00
|
|
|
void oskutil_write_initial_message(void *data, const void *data_msg)
|
2012-03-25 22:36:40 +00:00
|
|
|
{
|
2013-11-11 15:58:12 +00:00
|
|
|
ps3_osk_t *params = (ps3_osk_t*)data;
|
|
|
|
const wchar_t *msg = (const wchar_t*)data_msg;
|
2012-07-01 18:45:13 +00:00
|
|
|
params->inputFieldInfo.osk_inputfield_starttext = (uint16_t*)msg;
|
2012-03-25 22:36:40 +00:00
|
|
|
}
|
|
|
|
|
2013-11-11 15:58:12 +00:00
|
|
|
bool oskutil_start(void *data)
|
2012-03-25 22:36:40 +00:00
|
|
|
{
|
2013-11-11 15:58:12 +00:00
|
|
|
ps3_osk_t *params = (ps3_osk_t*)data;
|
|
|
|
|
2012-03-25 22:36:40 +00:00
|
|
|
if (params->flags & OSK_IN_USE)
|
2013-01-17 09:40:35 +00:00
|
|
|
{
|
|
|
|
RARCH_WARN("OSK util already initialized and in use\n");
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-25 22:36:40 +00:00
|
|
|
|
2013-11-11 15:58:12 +00:00
|
|
|
if (sys_memory_container_create(¶ms->containerid, params->osk_memorycontainer) < 0)
|
2013-01-17 09:40:35 +00:00
|
|
|
goto do_deinit;
|
|
|
|
|
|
|
|
params->outputInfo.osk_callback_return_param = CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK;
|
|
|
|
params->outputInfo.osk_callback_num_chars = 256;
|
|
|
|
params->outputInfo.osk_callback_return_string = (uint16_t *)params->text_buf;
|
|
|
|
|
|
|
|
memset(params->text_buf, 0, sizeof(*params->text_buf));
|
2012-03-25 22:36:40 +00:00
|
|
|
|
2012-07-01 18:45:13 +00:00
|
|
|
params->inputFieldInfo.osk_inputfield_max_length = CELL_OSKDIALOG_STRING_SIZE;
|
2012-03-25 22:36:40 +00:00
|
|
|
|
|
|
|
oskutil_create_activation_parameters(params);
|
|
|
|
|
2013-11-11 15:58:12 +00:00
|
|
|
if (!oskutil_enable_key_layout(params))
|
2012-03-25 22:36:40 +00:00
|
|
|
return (false);
|
|
|
|
|
2013-11-11 15:58:12 +00:00
|
|
|
if (pOskLoadAsync(params->containerid, ¶ms->dialogParam, ¶ms->inputFieldInfo) < 0)
|
2013-01-17 09:40:35 +00:00
|
|
|
goto do_deinit;
|
2012-03-25 22:36:40 +00:00
|
|
|
|
2013-01-17 09:40:35 +00:00
|
|
|
params->flags |= OSK_IN_USE;
|
2012-03-25 22:36:40 +00:00
|
|
|
|
2013-01-17 09:40:35 +00:00
|
|
|
return true;
|
2012-03-25 22:36:40 +00:00
|
|
|
|
2013-01-17 09:40:35 +00:00
|
|
|
do_deinit:
|
|
|
|
RARCH_ERR("Could not properly initialize OSK util.\n");
|
|
|
|
return false;
|
2012-03-25 22:36:40 +00:00
|
|
|
}
|
2013-11-11 15:58:12 +00:00
|
|
|
|
|
|
|
void oskutil_lifecycle(void *data, uint64_t status)
|
|
|
|
{
|
|
|
|
ps3_osk_t *osk = (ps3_osk_t*)data;
|
|
|
|
|
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
case CELL_SYSUTIL_OSKDIALOG_LOADED:
|
|
|
|
break;
|
|
|
|
case CELL_SYSUTIL_OSKDIALOG_INPUT_CANCELED:
|
|
|
|
RARCH_LOG("CELL_SYSUTIL_OSKDIALOG_INPUT_CANCELED.\n");
|
|
|
|
pOskAbort(); //fall-through
|
|
|
|
case CELL_SYSUTIL_OSKDIALOG_FINISHED:
|
|
|
|
if (status == CELL_SYSUTIL_OSKDIALOG_FINISHED)
|
|
|
|
RARCH_LOG("CELL_SYSUTIL_OSKDIALOG_FINISHED.\n");
|
|
|
|
|
|
|
|
pOskUnloadAsync(&osk->outputInfo);
|
|
|
|
|
|
|
|
if (osk->outputInfo.result == CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK)
|
|
|
|
{
|
|
|
|
RARCH_LOG("Setting MODE_OSK_ENTRY_SUCCESS.\n");
|
|
|
|
g_extern.lifecycle_state |= (1ULL << MODE_OSK_ENTRY_SUCCESS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RARCH_LOG("Setting MODE_OSK_ENTRY_FAIL.\n");
|
|
|
|
g_extern.lifecycle_state |= (1ULL << MODE_OSK_ENTRY_FAIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
osk->flags &= ~OSK_IN_USE;
|
|
|
|
break;
|
|
|
|
case CELL_SYSUTIL_OSKDIALOG_UNLOADED:
|
|
|
|
RARCH_LOG("CELL_SYSUTIL_OSKDIALOG_UNLOADED.\n");
|
|
|
|
sys_memory_container_destroy(osk->containerid);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-11-12 16:16:11 +00:00
|
|
|
|
|
|
|
const input_osk_driver_t input_ps3_osk = {
|
|
|
|
oskutil_init,
|
|
|
|
oskutil_free,
|
|
|
|
oskutil_enable_key_layout,
|
|
|
|
oskutil_create_activation_parameters,
|
|
|
|
oskutil_write_message,
|
|
|
|
oskutil_write_initial_message,
|
|
|
|
oskutil_start,
|
|
|
|
oskutil_lifecycle,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
"ps3osk"
|
|
|
|
};
|
2012-06-19 03:10:42 +00:00
|
|
|
#endif
|
|
|
|
|
2012-03-25 22:36:40 +00:00
|
|
|
/*============================================================
|
2012-11-02 23:30:41 +00:00
|
|
|
RetroArch PS3 INPUT DRIVER
|
|
|
|
============================================================ */
|
2012-03-25 22:36:40 +00:00
|
|
|
|
2012-11-26 23:50:29 +00:00
|
|
|
static void ps3_input_free_input(void *data)
|
2012-07-27 13:46:15 +00:00
|
|
|
{
|
2013-11-01 15:33:32 +00:00
|
|
|
if (!data)
|
|
|
|
return;
|
|
|
|
|
2013-11-03 18:39:43 +00:00
|
|
|
#ifndef __CELLOS_LV2__
|
|
|
|
cellPadEnd();
|
|
|
|
#endif
|
2013-11-01 15:33:32 +00:00
|
|
|
#ifdef HAVE_MOUSE
|
2013-10-06 20:28:39 +00:00
|
|
|
//cellMouseEnd();
|
2013-11-01 15:33:32 +00:00
|
|
|
#endif
|
2012-07-27 13:46:15 +00:00
|
|
|
}
|
|
|
|
|
2013-03-14 01:24:57 +00:00
|
|
|
static void ps3_input_set_keybinds(void *data, unsigned device,
|
|
|
|
unsigned port, unsigned id, unsigned keybind_action)
|
2013-03-12 23:12:29 +00:00
|
|
|
{
|
2013-03-14 14:01:36 +00:00
|
|
|
uint64_t *key = &g_settings.input.binds[port][id].joykey;
|
2013-11-01 15:33:32 +00:00
|
|
|
//uint64_t joykey = *key;
|
2013-03-14 20:55:10 +00:00
|
|
|
size_t arr_size = sizeof(platform_keys) / sizeof(platform_keys[0]);
|
2013-03-14 14:01:36 +00:00
|
|
|
|
2013-03-12 23:12:29 +00:00
|
|
|
(void)device;
|
2013-03-14 14:01:36 +00:00
|
|
|
|
|
|
|
if (keybind_action & (1ULL << KEYBINDS_ACTION_SET_DEFAULT_BIND))
|
|
|
|
*key = g_settings.input.binds[port][id].def_joykey;
|
2013-03-12 23:12:29 +00:00
|
|
|
|
2013-03-14 01:24:57 +00:00
|
|
|
if (keybind_action & (1ULL << KEYBINDS_ACTION_SET_DEFAULT_BINDS))
|
|
|
|
{
|
|
|
|
for (int 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-14 17:02:19 +00:00
|
|
|
if (keybind_action & (1ULL << KEYBINDS_ACTION_GET_BIND_LABEL))
|
|
|
|
{
|
|
|
|
struct platform_bind *ret = (struct platform_bind*)data;
|
|
|
|
|
|
|
|
if (ret->joykey == NO_BTN)
|
|
|
|
strlcpy(ret->desc, "No button", sizeof(ret->desc));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < arr_size; i++)
|
|
|
|
{
|
2013-03-14 17:04:16 +00:00
|
|
|
if (platform_keys[i].joykey == ret->joykey)
|
2013-03-14 17:02:19 +00:00
|
|
|
{
|
|
|
|
strlcpy(ret->desc, platform_keys[i].desc, sizeof(ret->desc));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
strlcpy(ret->desc, "Unknown", sizeof(ret->desc));
|
|
|
|
}
|
|
|
|
}
|
2013-03-12 23:12:29 +00:00
|
|
|
}
|
2012-07-27 23:37:15 +00:00
|
|
|
|
2013-03-12 23:34:46 +00:00
|
|
|
static void* ps3_input_init(void)
|
2012-07-27 13:46:15 +00:00
|
|
|
{
|
2013-11-01 15:33:32 +00:00
|
|
|
ps3_input_t *ps3 = (ps3_input_t*)calloc(1, sizeof(*ps3));
|
|
|
|
if (!ps3)
|
|
|
|
return NULL;
|
|
|
|
|
2013-03-16 16:51:45 +00:00
|
|
|
cellPadInit(MAX_PADS);
|
2013-03-12 23:34:46 +00:00
|
|
|
#ifdef HAVE_MOUSE
|
|
|
|
cellMouseInit(MAX_MICE);
|
|
|
|
#endif
|
|
|
|
|
2013-11-01 15:33:32 +00:00
|
|
|
return ps3;
|
2012-07-27 13:46:15 +00:00
|
|
|
}
|
|
|
|
|
2012-11-26 23:50:29 +00:00
|
|
|
static bool ps3_input_key_pressed(void *data, int key)
|
2011-12-02 01:34:06 +00:00
|
|
|
{
|
2012-12-23 13:44:46 +00:00
|
|
|
return (g_extern.lifecycle_state & (1ULL << key));
|
2011-11-30 16:24:18 +00:00
|
|
|
}
|
|
|
|
|
2013-11-02 20:16:57 +00:00
|
|
|
static uint64_t ps3_input_get_capabilities(void *data)
|
|
|
|
{
|
|
|
|
uint64_t caps = 0;
|
|
|
|
|
|
|
|
caps |= (1 << RETRO_DEVICE_JOYPAD);
|
|
|
|
#ifdef HAVE_MOUSE
|
|
|
|
caps |= (1 << RETRO_DEVICE_MOUSE);
|
|
|
|
#endif
|
2013-11-03 18:39:43 +00:00
|
|
|
caps |= (1 << RETRO_DEVICE_ANALOG);
|
2013-11-03 19:25:15 +00:00
|
|
|
caps |= (1 << RETRO_DEVICE_SENSOR_ACCELEROMETER);
|
2013-11-02 20:16:57 +00:00
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2013-11-03 19:25:15 +00:00
|
|
|
static bool ps3_input_set_sensor_state(void *data, unsigned port, enum retro_sensor_action action, unsigned event_rate)
|
|
|
|
{
|
|
|
|
CellPadInfo2 pad_info;
|
|
|
|
(void)event_rate;
|
|
|
|
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case RETRO_SENSOR_ACCELEROMETER_ENABLE:
|
|
|
|
cellPadGetInfo2(&pad_info);
|
|
|
|
if ((pad_info.device_capability[port] & CELL_PAD_CAPABILITY_SENSOR_MODE) != CELL_PAD_CAPABILITY_SENSOR_MODE)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
cellPadSetPortSetting(port, CELL_PAD_SETTING_SENSOR_ON);
|
|
|
|
return true;
|
|
|
|
case RETRO_SENSOR_ACCELEROMETER_DISABLE:
|
|
|
|
cellPadSetPortSetting(port, 0);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-03 19:55:07 +00:00
|
|
|
static bool ps3_input_set_rumble(void *data, unsigned port, enum retro_rumble_effect effect, uint16_t strength)
|
|
|
|
{
|
|
|
|
CellPadActParam params;
|
|
|
|
|
|
|
|
switch (effect)
|
|
|
|
{
|
|
|
|
case RETRO_RUMBLE_WEAK:
|
|
|
|
if (strength > 1)
|
|
|
|
strength = 1;
|
|
|
|
params.motor[0] = strength;
|
|
|
|
break;
|
|
|
|
case RETRO_RUMBLE_STRONG:
|
|
|
|
if (strength > 255)
|
|
|
|
strength = 255;
|
|
|
|
params.motor[1] = strength;
|
|
|
|
}
|
|
|
|
|
|
|
|
cellPadSetActDirect(port, ¶ms);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-30 16:24:18 +00:00
|
|
|
const input_driver_t input_ps3 = {
|
2013-11-02 20:16:57 +00:00
|
|
|
ps3_input_init,
|
|
|
|
ps3_input_poll,
|
|
|
|
ps3_input_state,
|
|
|
|
ps3_input_key_pressed,
|
|
|
|
ps3_input_free_input,
|
|
|
|
ps3_input_set_keybinds,
|
2013-11-03 19:25:15 +00:00
|
|
|
ps3_input_set_sensor_state,
|
2013-11-02 20:16:57 +00:00
|
|
|
ps3_input_get_capabilities,
|
|
|
|
"ps3",
|
2011-12-11 12:14:44 +00:00
|
|
|
|
2013-11-03 19:55:07 +00:00
|
|
|
NULL,
|
|
|
|
ps3_input_set_rumble,
|
|
|
|
NULL,
|
|
|
|
};
|