-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathlr_input.c
278 lines (237 loc) · 7.44 KB
/
lr_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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#include "lr_input.h"
#include "lr_input_crosshair.h"
#include "opera_lr_callbacks.h"
#include <libopera/opera_pbus.h>
#include <libretro.h>
static uint32_t ACTIVE_DEVICES = 0;
static unsigned PBUS_DEVICES[LR_INPUT_MAX_DEVICES] = {0};
static
uint8_t
poll_joypad(const int port_,
const int id_)
{
return retro_input_state_cb(port_,RETRO_DEVICE_JOYPAD,0,id_);
}
static
int16_t
poll_analog_lx(const int port_)
{
return retro_input_state_cb(port_,
RETRO_DEVICE_ANALOG,
RETRO_DEVICE_INDEX_ANALOG_LEFT,
RETRO_DEVICE_ID_ANALOG_X);
}
static
int16_t
poll_analog_ly(const int port_)
{
return retro_input_state_cb(port_,
RETRO_DEVICE_ANALOG,
RETRO_DEVICE_INDEX_ANALOG_LEFT,
RETRO_DEVICE_ID_ANALOG_Y);
}
static
int16_t
poll_analog_rx(const int port_)
{
return retro_input_state_cb(port_,
RETRO_DEVICE_ANALOG,
RETRO_DEVICE_INDEX_ANALOG_RIGHT,
RETRO_DEVICE_ID_ANALOG_X);
}
static
int16_t
poll_analog_ry(const int port_)
{
return retro_input_state_cb(port_,
RETRO_DEVICE_ANALOG,
RETRO_DEVICE_INDEX_ANALOG_RIGHT,
RETRO_DEVICE_ID_ANALOG_Y);
}
static
uint32_t
poll_mouse(const int port_,
const int id_)
{
return retro_input_state_cb(port_,RETRO_DEVICE_MOUSE,0,id_);
}
static
uint32_t
poll_lightgun(const int port_,
const int id_)
{
return retro_input_state_cb(port_,RETRO_DEVICE_LIGHTGUN,0,id_);
}
static
void
lr_input_poll_joypad(const int port_)
{
opera_pbus_joypad_t jp;
jp.u = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_UP);
jp.d = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_DOWN);
jp.l = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_LEFT);
jp.r = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_RIGHT);
jp.lt = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_L);
jp.rt = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_R);
jp.x = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_SELECT);
jp.p = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_START) |
poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_X);
jp.a = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_Y);
jp.b = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_B);
jp.c = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_A);
opera_pbus_add_joypad(&jp);
}
static
void
lr_input_poll_flightstick(const int port_)
{
opera_pbus_flightstick_t fs;
fs.h_pos = poll_analog_lx(port_);
fs.v_pos = poll_analog_ly(port_);
fs.z_pos = poll_analog_ry(port_);
fs.fire = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_R2);
fs.a = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_Y);
fs.b = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_B);
fs.c = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_A);
fs.u = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_UP);
fs.d = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_DOWN);
fs.l = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_LEFT);
fs.r = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_RIGHT);
fs.p = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_START);
fs.x = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_SELECT);
fs.lt = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_L);
fs.rt = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_R);
opera_pbus_add_flightstick(&fs);
}
static
void
lr_input_poll_mouse(const int port_)
{
opera_pbus_mouse_t m;
m.x = poll_mouse(port_,RETRO_DEVICE_ID_MOUSE_X);
m.y = poll_mouse(port_,RETRO_DEVICE_ID_MOUSE_Y);
m.left = poll_mouse(port_,RETRO_DEVICE_ID_MOUSE_LEFT);
m.middle = poll_mouse(port_,RETRO_DEVICE_ID_MOUSE_MIDDLE);
m.right = poll_mouse(port_,RETRO_DEVICE_ID_MOUSE_RIGHT);
m.shift = poll_mouse(port_,RETRO_DEVICE_ID_MOUSE_BUTTON_4);
opera_pbus_add_mouse(&m);
}
static
void
lr_input_poll_lightgun(const int port_)
{
opera_pbus_lightgun_t lg;
lg.x = poll_lightgun(port_,RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X);
lg.y = poll_lightgun(port_,RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y);
lg.trigger = poll_lightgun(port_,RETRO_DEVICE_ID_LIGHTGUN_TRIGGER);
lg.option = poll_lightgun(port_,RETRO_DEVICE_ID_LIGHTGUN_SELECT);
lg.reload = poll_lightgun(port_,RETRO_DEVICE_ID_LIGHTGUN_RELOAD);
if(poll_lightgun(port_,RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN))
{
lg.trigger = 0;
lg.reload = poll_lightgun(port_,RETRO_DEVICE_ID_LIGHTGUN_TRIGGER) || poll_lightgun(port_,RETRO_DEVICE_ID_LIGHTGUN_RELOAD);
}
lr_input_crosshair_set(port_,lg.x,lg.y);
opera_pbus_add_lightgun(&lg);
}
static
void
lr_input_poll_arcade_lightgun(const int port_)
{
opera_pbus_arcade_lightgun_t lg;
lg.x = poll_lightgun(port_,RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X);
lg.y = poll_lightgun(port_,RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y);
lg.trigger = poll_lightgun(port_,RETRO_DEVICE_ID_LIGHTGUN_TRIGGER);
lg.service = poll_lightgun(port_,RETRO_DEVICE_ID_LIGHTGUN_AUX_A);
lg.coins = poll_lightgun(port_,RETRO_DEVICE_ID_LIGHTGUN_SELECT);
lg.start = poll_lightgun(port_,RETRO_DEVICE_ID_LIGHTGUN_START);
lg.holster = poll_lightgun(port_,RETRO_DEVICE_ID_LIGHTGUN_RELOAD);
if(poll_lightgun(port_,RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN))
{
lg.trigger = 0;
lg.holster = poll_lightgun(port_,RETRO_DEVICE_ID_LIGHTGUN_TRIGGER) || poll_lightgun(port_,RETRO_DEVICE_ID_LIGHTGUN_RELOAD);
}
lr_input_crosshair_set(port_,lg.x,lg.y);
opera_pbus_add_arcade_lightgun(&lg);
}
static
void
lr_input_poll_orbatak_trackball(const int port_)
{
opera_pbus_orbatak_trackball_t tb;
tb.x = (poll_analog_lx(port_) / (32768 / 24));
tb.y = (poll_analog_ly(port_) / (32768 / 24));
if(tb.x == 0)
{
if(poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_LEFT))
tb.x = -24;
else if(poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_RIGHT))
tb.x = 24;
}
if(tb.y == 0)
{
if(poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_UP))
tb.y = -24;
else if(poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_DOWN))
tb.y = 24;
}
tb.start_p1 = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_SELECT);
tb.start_p2 = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_START);
tb.coin_p1 = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_L);
tb.coin_p2 = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_R);
tb.service = poll_joypad(port_,RETRO_DEVICE_ID_JOYPAD_R2);
opera_pbus_add_orbatak_trackball(&tb);
}
static
void
lr_input_poll(const int port_)
{
switch(PBUS_DEVICES[port_])
{
case RETRO_DEVICE_NONE:
break;
default:
case RETRO_DEVICE_JOYPAD:
lr_input_poll_joypad(port_);
return;
case RETRO_DEVICE_FLIGHTSTICK:
lr_input_poll_flightstick(port_);
break;
case RETRO_DEVICE_MOUSE:
lr_input_poll_mouse(port_);
break;
case RETRO_DEVICE_LIGHTGUN:
lr_input_poll_lightgun(port_);
break;
case RETRO_DEVICE_ARCADE_LIGHTGUN:
lr_input_poll_arcade_lightgun(port_);
break;
case RETRO_DEVICE_ORBATAK_TRACKBALL:
lr_input_poll_orbatak_trackball(port_);
break;
}
}
void
lr_input_device_set(const uint32_t port_,
const uint32_t device_)
{
PBUS_DEVICES[port_] = device_;
}
uint32_t
lr_input_device_get(const uint32_t port_)
{
return PBUS_DEVICES[port_];
}
void
lr_input_update(const uint32_t active_devices_)
{
int i;
opera_pbus_reset();
retro_input_poll_cb();
for(i = 0; i < active_devices_; i++)
{
if(PBUS_DEVICES[i] == RETRO_DEVICE_NONE)
continue;
lr_input_poll(i);
}
}