2012-04-21 21:13:50 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2016-01-10 03:33:01 +00:00
|
|
|
* Copyright (C) 2011-2016 - Daniel De Matteis
|
2011-12-14 00:35:17 +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-12-14 00:35:17 +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-12-14 00:35:17 +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-12-14 00:35:17 +00:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2011-12-14 07:36:04 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2011-12-14 00:35:17 +00:00
|
|
|
#include <input/input.h>
|
|
|
|
#include <usb/usbmain.h>
|
|
|
|
|
2016-05-10 17:03:53 +00:00
|
|
|
#include <libretro.h>
|
|
|
|
|
|
|
|
#include "../../driver.h"
|
|
|
|
|
2013-03-16 16:51:45 +00:00
|
|
|
#define MAX_PADS 4
|
|
|
|
|
|
|
|
static uint64_t state[MAX_PADS];
|
2015-07-10 16:45:22 +00:00
|
|
|
static uint64_t lifecycle_state;
|
2013-01-10 02:34:43 +00:00
|
|
|
|
2011-12-14 00:35:17 +00:00
|
|
|
static void xenon360_input_poll(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
2013-03-16 16:51:45 +00:00
|
|
|
for (unsigned i = 0; i < MAX_PADS; i++)
|
2011-12-14 00:35:17 +00:00
|
|
|
{
|
2013-01-13 19:58:52 +00:00
|
|
|
struct controller_data_s pad;
|
2011-12-14 07:36:04 +00:00
|
|
|
usb_do_poll();
|
2013-01-13 19:58:52 +00:00
|
|
|
get_controller_data(&pad, i);
|
|
|
|
|
|
|
|
uint64_t *cur_state = &state[i];
|
|
|
|
|
|
|
|
*cur_state |= pad.b ? RETRO_DEVICE_ID_JOYPAD_A : 0;
|
|
|
|
*cur_state |= pad.a ? RETRO_DEVICE_ID_JOYPAD_B : 0;
|
|
|
|
*cur_state |= pad.y ? RETRO_DEVICE_ID_JOYPAD_X : 0;
|
|
|
|
*cur_state |= pad.x ? RETRO_DEVICE_ID_JOYPAD_Y : 0;
|
|
|
|
*cur_state |= pad.left ? RETRO_DEVICE_ID_JOYPAD_LEFT : 0;
|
|
|
|
*cur_state |= pad.right ? RETRO_DEVICE_ID_JOYPAD_RIGHT : 0;
|
|
|
|
*cur_state |= pad.up ? RETRO_DEVICE_ID_JOYPAD_UP : 0;
|
|
|
|
*cur_state |= pad.down ? RETRO_DEVICE_ID_JOYPAD_DOWN : 0;
|
|
|
|
*cur_state |= pad.start ? RETRO_DEVICE_ID_JOYPAD_START : 0;
|
|
|
|
*cur_state |= pad.back ? RETRO_DEVICE_ID_JOYPAD_SELECT : 0;
|
|
|
|
*cur_state |= pad.lt ? RETRO_DEVICE_ID_JOYPAD_L : 0;
|
|
|
|
*cur_state |= pad.rt ? RETRO_DEVICE_ID_JOYPAD_R : 0;
|
2011-12-14 00:35:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-07 15:19:32 +00:00
|
|
|
static int16_t xenon360_input_state(void *data, const struct retro_keybind **binds,
|
2011-12-14 00:35:17 +00:00
|
|
|
bool port, unsigned device,
|
2014-10-20 18:31:00 +00:00
|
|
|
unsigned idx, unsigned id)
|
2011-12-14 00:35:17 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
2014-10-20 18:31:00 +00:00
|
|
|
(void)idx;
|
2014-12-05 12:53:49 +00:00
|
|
|
unsigned user = port;
|
|
|
|
uint64_t button = binds[user][id].joykey;
|
2013-01-13 19:58:52 +00:00
|
|
|
int16_t retval = 0;
|
2011-12-14 00:35:17 +00:00
|
|
|
|
2014-12-05 12:53:49 +00:00
|
|
|
if(user < MAX_PADS)
|
2011-12-14 00:35:17 +00:00
|
|
|
{
|
2013-01-13 19:58:52 +00:00
|
|
|
switch (device)
|
|
|
|
{
|
|
|
|
case RETRO_DEVICE_JOYPAD:
|
2014-12-05 12:53:49 +00:00
|
|
|
retval = (state[user] & button) ? 1 : 0;
|
2013-01-13 19:58:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-12-14 00:35:17 +00:00
|
|
|
}
|
|
|
|
|
2013-01-13 19:58:52 +00:00
|
|
|
return retval;
|
2011-12-14 00:35:17 +00:00
|
|
|
}
|
|
|
|
|
2013-01-13 19:58:52 +00:00
|
|
|
static void xenon360_input_free_input(void *data)
|
2011-12-14 00:35:17 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
}
|
|
|
|
|
2013-03-12 23:34:46 +00:00
|
|
|
static void* xenon360_input_init(void)
|
2013-01-13 20:20:43 +00:00
|
|
|
{
|
2013-03-12 23:34:46 +00:00
|
|
|
return (void*)-1;
|
2013-01-13 20:20:43 +00:00
|
|
|
}
|
|
|
|
|
2015-11-07 19:59:12 +00:00
|
|
|
static bool xenon360_input_key_pressed(void *data, int key)
|
2013-03-12 23:34:46 +00:00
|
|
|
{
|
2015-10-23 06:34:15 +00:00
|
|
|
if (lifecycle_state & (UINT64_C(1) << key))
|
|
|
|
return true;
|
2015-10-22 17:17:47 +00:00
|
|
|
|
2015-10-23 06:34:15 +00:00
|
|
|
return false;
|
2013-03-12 23:34:46 +00:00
|
|
|
}
|
|
|
|
|
2015-11-07 19:59:12 +00:00
|
|
|
static bool xenon360_input_meta_key_pressed(void *data, int key)
|
2015-07-17 01:31:51 +00:00
|
|
|
{
|
2015-11-07 19:59:12 +00:00
|
|
|
return (lifecycle_state & (UINT64_C(1) << key));
|
2015-07-17 01:31:51 +00:00
|
|
|
}
|
|
|
|
|
2015-09-28 20:03:05 +00:00
|
|
|
static uint64_t xenon360_input_get_capabilities(void *data)
|
2013-11-02 20:16:57 +00:00
|
|
|
{
|
|
|
|
uint64_t caps = 0;
|
|
|
|
|
|
|
|
caps |= (1 << RETRO_DEVICE_JOYPAD);
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
2013-03-12 23:34:46 +00:00
|
|
|
|
2015-03-24 06:51:50 +00:00
|
|
|
static void xenon360_input_grab_mouse(void *data, bool state)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool xenon360_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_xenon360 = {
|
2013-11-02 20:16:57 +00:00
|
|
|
xenon360_input_init,
|
|
|
|
xenon360_input_poll,
|
|
|
|
xenon360_input_state,
|
|
|
|
xenon360_input_key_pressed,
|
2015-07-17 01:31:51 +00:00
|
|
|
xenon360_input_meta_key_pressed,
|
2013-11-02 20:16:57 +00:00
|
|
|
xenon360_input_free_input,
|
2014-06-09 23:30:25 +00:00
|
|
|
NULL,
|
2013-11-02 23:27:58 +00:00
|
|
|
NULL,
|
2014-01-20 13:52:53 +00:00
|
|
|
NULL,
|
2013-11-02 20:16:57 +00:00
|
|
|
xenon360_input_get_capabilities,
|
|
|
|
"xenon360",
|
2015-03-24 06:51:50 +00:00
|
|
|
xenon360_input_grab_mouse,
|
2015-05-19 17:33:58 +00:00
|
|
|
NULL,
|
2015-03-24 06:51:50 +00:00
|
|
|
xenon360_input_set_rumble,
|
2015-06-19 01:45:23 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2015-11-16 01:39:38 +00:00
|
|
|
NULL,
|
2011-12-14 00:35:17 +00:00
|
|
|
};
|