forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 2
/
xenon360_input.c
135 lines (114 loc) · 3.37 KB
/
xenon360_input.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - 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>
#include <string.h>
#include <input/input.h>
#include <usb/usbmain.h>
#include <libretro.h>
#include "../input_driver.h"
#define MAX_PADS 4
static uint64_t state[MAX_PADS];
static void xenon360_input_poll(void *data)
{
(void)data;
for (unsigned i = 0; i < MAX_PADS; i++)
{
struct controller_data_s pad;
usb_do_poll();
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;
}
}
static int16_t xenon360_input_state(void *data,
rarch_joypad_info_t joypad_info,
const struct retro_keybind **binds,
bool port, unsigned device,
unsigned idx, unsigned id)
{
unsigned user = port;
uint64_t button = binds[user][id].joykey;
int16_t retval = 0;
if(user < MAX_PADS)
{
switch (device)
{
case RETRO_DEVICE_JOYPAD:
retval = (state[user] & button) ? 1 : 0;
break;
default:
break;
}
}
return retval;
}
static void xenon360_input_free_input(void *data)
{
(void)data;
}
static void* xenon360_input_init(const char *joypad_driver)
{
return (void*)-1;
}
static uint64_t xenon360_input_get_capabilities(void *data)
{
uint64_t caps = 0;
caps |= (1 << RETRO_DEVICE_JOYPAD);
return caps;
}
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;
}
input_driver_t input_xenon360 = {
xenon360_input_init,
xenon360_input_poll,
xenon360_input_state,
xenon360_input_free_input,
NULL,
NULL,
NULL,
xenon360_input_get_capabilities,
"xenon360",
xenon360_input_grab_mouse,
NULL,
xenon360_input_set_rumble,
NULL,
NULL,
NULL,
};