RetroArch/ps3/pad_input.c

123 lines
4.1 KiB
C
Raw Normal View History

2011-12-01 20:23:49 +00:00
/*******************************************************************************
* -- Cellframework Mk.II - Open framework to abstract the common tasks related to
* PS3 application development.
*
* Copyright (C) 2010-2011
*
* This program 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 Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
********************************************************************************/
/*******************************************************************************
* pad_input.c - Cellframework Mk. II
*
* Created on: Jan 30, 2011
*
* NOTES AS OF NOW:
********************************************************************************/
#include <cell/pad.h>
#include <sdk_version.h>
#include "pad_input.h"
#define LOWER_BUTTONS 2
#define HIGHER_BUTTONS 3
#define RSTICK_X 4
#define RSTICK_Y 5
#define LSTICK_X 6
#define LSTICK_Y 7
#define DEADZONE_LOW 55
#define DEADZONE_HIGH 210
#define PRESSED_LEFT_LSTICK(state) (CTRL_AXIS_LSTICK_X(state) <= DEADZONE_LOW)
#define PRESSED_RIGHT_LSTICK(state) (CTRL_AXIS_LSTICK_X(state) >= DEADZONE_HIGH)
#define PRESSED_UP_LSTICK(state) (CTRL_AXIS_LSTICK_Y(state) <= DEADZONE_LOW)
#define PRESSED_DOWN_LSTICK(state) (CTRL_AXIS_LSTICK_Y(state) >= DEADZONE_HIGH)
#define PRESSED_LEFT_RSTICK(state) (CTRL_AXIS_RSTICK_X(state) <= DEADZONE_LOW)
#define PRESSED_RIGHT_RSTICK(state) (CTRL_AXIS_RSTICK_X(state) >= DEADZONE_HIGH)
#define PRESSED_UP_RSTICK(state) (CTRL_AXIS_RSTICK_Y(state) <= DEADZONE_LOW)
#define PRESSED_DOWN_RSTICK(state) (CTRL_AXIS_RSTICK_Y(state) >= DEADZONE_HIGH)
#define LSTICK_LEFT_SHIFT 48
#define LSTICK_RIGHT_SHIFT 49
#define LSTICK_UP_SHIFT 50
#define LSTICK_DOWN_SHIFT 51
#define RSTICK_LEFT_SHIFT 52
#define RSTICK_RIGHT_SHIFT 53
#define RSTICK_UP_SHIFT 54
#define RSTICK_DOWN_SHIFT 55
int cell_pad_input_init(void)
{
return cellPadInit(MAX_PADS);
}
void cell_pad_input_deinit(void)
{
cellPadEnd();
}
uint32_t cell_pad_input_pads_connected(void)
{
#if(CELL_SDK_VERSION > 0x340000)
CellPadInfo2 pad_info;
cellPadGetInfo2(&pad_info);
#else
CellPadInfo pad_info;
cellPadGetInfo(&pad_info);
#endif
return pad_info.now_connect;
}
#define M(x) (x & 0xFF)
uint64_t cell_pad_input_poll_device(uint32_t id)
{
CellPadData pad_data;
static uint64_t ret[MAX_PADS];
// Get new pad data
cellPadGetData(id, &pad_data);
if (pad_data.len == 0)
return ret[id];
else
{
ret[id] = 0;
// Build the return value.
ret[id] |= (uint64_t)M(pad_data.button[LOWER_BUTTONS]);
ret[id] |= (uint64_t)M(pad_data.button[HIGHER_BUTTONS]) << 8;
ret[id] |= (uint64_t)M(pad_data.button[RSTICK_X]) << 32;
ret[id] |= (uint64_t)M(pad_data.button[RSTICK_Y]) << 40;
ret[id] |= (uint64_t)M(pad_data.button[LSTICK_X]) << 16;
ret[id] |= (uint64_t)M(pad_data.button[LSTICK_Y]) << 24;
ret[id] |= (uint64_t)(PRESSED_LEFT_LSTICK(ret[id]) ? 1 : 0) << LSTICK_LEFT_SHIFT;
ret[id] |= (uint64_t)(PRESSED_RIGHT_LSTICK(ret[id]) ? 1 : 0) << LSTICK_RIGHT_SHIFT;
ret[id] |= (uint64_t)(PRESSED_UP_LSTICK(ret[id]) ? 1 : 0) << LSTICK_UP_SHIFT;
ret[id] |= (uint64_t)(PRESSED_DOWN_LSTICK(ret[id]) ? 1 : 0) << LSTICK_DOWN_SHIFT;
ret[id] |= (uint64_t)(PRESSED_LEFT_RSTICK(ret[id]) ? 1 : 0) << RSTICK_LEFT_SHIFT;
ret[id] |= (uint64_t)(PRESSED_RIGHT_RSTICK(ret[id]) ? 1 : 0) << RSTICK_RIGHT_SHIFT;
ret[id] |= (uint64_t)(PRESSED_UP_RSTICK(ret[id]) ? 1 : 0) << RSTICK_UP_SHIFT;
ret[id] |= (uint64_t)(PRESSED_DOWN_RSTICK(ret[id]) ? 1 : 0) << RSTICK_DOWN_SHIFT;
return ret[id];
}
}
#undef M