-
Notifications
You must be signed in to change notification settings - Fork 38
/
lr_input_descs.c
256 lines (221 loc) · 8.66 KB
/
lr_input_descs.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
#include "lr_input.h"
#include "opera_lr_callbacks.h"
#include "lr_input_crosshair.h"
#include <libretro.h>
#include <string.h>
static
uint32_t
setup_joypad_desc(struct retro_input_descriptor *desc_,
const unsigned port_,
const unsigned id_,
const char *str_)
{
desc_->port = port_;
desc_->device = RETRO_DEVICE_JOYPAD;
desc_->index = 0;
desc_->id = id_;
desc_->description = str_;
return 1;
}
static
uint32_t
setup_analog_left_desc(struct retro_input_descriptor *desc_,
const unsigned port_,
const unsigned id_,
const char *str_)
{
desc_->port = port_;
desc_->device = RETRO_DEVICE_ANALOG;
desc_->index = RETRO_DEVICE_INDEX_ANALOG_LEFT;
desc_->id = id_;
desc_->description = str_;
return 1;
}
static
uint32_t
setup_analog_right_desc(struct retro_input_descriptor *desc_,
const unsigned port_,
const unsigned id_,
const char *str_)
{
desc_->port = port_;
desc_->device = RETRO_DEVICE_ANALOG;
desc_->index = RETRO_DEVICE_INDEX_ANALOG_RIGHT;
desc_->id = id_;
desc_->description = str_;
return 1;
}
static
uint32_t
setup_mouse_desc(struct retro_input_descriptor *desc_,
const unsigned port_,
const unsigned id_,
const char *str_)
{
desc_->port = port_;
desc_->device = RETRO_DEVICE_MOUSE;
desc_->index = 0;
desc_->id = id_;
desc_->description = str_;
return 1;
}
static
uint32_t
setup_lightgun_desc(struct retro_input_descriptor *desc_,
const unsigned port_,
const unsigned id_,
const char *str_)
{
desc_->port = port_;
desc_->device = RETRO_DEVICE_LIGHTGUN;
desc_->index = 0;
desc_->id = id_;
desc_->description = str_;
return 1;
}
static
uint32_t
setup_joypad_descs(struct retro_input_descriptor *desc_,
const unsigned port_)
{
uint32_t rv;
rv = 0;
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_LEFT,"D-Pad Left");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_UP,"D-Pad Up");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_DOWN,"D-Pad Down");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_RIGHT,"D-Pad Right");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_Y,"A");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_B,"B");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_A,"C");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_L,"L");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_R,"R");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_SELECT,"X (Stop)");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_START,"P (Play/Pause)");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_X,"P (Play/Pause)");
return rv;
}
static
uint32_t
setup_flightstick_descs(struct retro_input_descriptor *desc_,
const unsigned port_)
{
int rv;
rv = 0;
rv += setup_analog_left_desc(desc_++,port_,RETRO_DEVICE_ID_ANALOG_X,"Horizontal (X)");
rv += setup_analog_left_desc(desc_++,port_,RETRO_DEVICE_ID_ANALOG_Y,"Vertical (Y)");
rv += setup_analog_right_desc(desc_++,port_,RETRO_DEVICE_ID_ANALOG_Y,"Depth (Z)");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_LEFT,"D-Pad Left");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_UP,"D-Pad Up");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_DOWN,"D-Pad Down");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_RIGHT,"D-Pad Right");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_Y,"A");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_B,"B");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_A,"C");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_L,"L");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_R,"R");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_R2,"Fire");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_SELECT,"X (Stop)");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_START,"P (Play/Pause)");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_X,"P (Play/Pause)");
return rv;
}
static
uint32_t
setup_mouse_descs(struct retro_input_descriptor *desc_,
const unsigned port_)
{
uint32_t rv;
rv = 0;
rv += setup_mouse_desc(desc_++,port_,RETRO_DEVICE_ID_MOUSE_X,"Horizontal Axis");
rv += setup_mouse_desc(desc_++,port_,RETRO_DEVICE_ID_MOUSE_Y,"Vertical Axis");
rv += setup_mouse_desc(desc_++,port_,RETRO_DEVICE_ID_MOUSE_LEFT,"Left Button");
rv += setup_mouse_desc(desc_++,port_,RETRO_DEVICE_ID_MOUSE_MIDDLE,"Middle Button");
rv += setup_mouse_desc(desc_++,port_,RETRO_DEVICE_ID_MOUSE_RIGHT,"Right Button");
return rv;
}
static
uint32_t
setup_lightgun_descs(struct retro_input_descriptor *desc_,
const unsigned port_)
{
uint32_t rv;
rv = 0;
rv += setup_lightgun_desc(desc_++,port_,RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X,"X Coord");
rv += setup_lightgun_desc(desc_++,port_,RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y,"Y Coord");
rv += setup_lightgun_desc(desc_++,port_,RETRO_DEVICE_ID_LIGHTGUN_TRIGGER,"Trigger");
rv += setup_lightgun_desc(desc_++,port_,RETRO_DEVICE_ID_LIGHTGUN_SELECT,"Option");
rv += setup_lightgun_desc(desc_++,port_,RETRO_DEVICE_ID_LIGHTGUN_RELOAD,"Reload");
return rv;
}
static
uint32_t
setup_lightgun_arcade_descs(struct retro_input_descriptor *desc_,
const unsigned port_)
{
uint32_t rv;
rv = 0;
rv += setup_lightgun_desc(desc_++,port_,RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X,"X Coord");
rv += setup_lightgun_desc(desc_++,port_,RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y,"Y Coord");
rv += setup_lightgun_desc(desc_++,port_,RETRO_DEVICE_ID_LIGHTGUN_TRIGGER,"Trigger");
rv += setup_lightgun_desc(desc_++,port_,RETRO_DEVICE_ID_LIGHTGUN_AUX_A,"Service");
rv += setup_lightgun_desc(desc_++,port_,RETRO_DEVICE_ID_LIGHTGUN_SELECT,"Coins");
rv += setup_lightgun_desc(desc_++,port_,RETRO_DEVICE_ID_LIGHTGUN_START,"Start");
rv += setup_lightgun_desc(desc_++,port_,RETRO_DEVICE_ID_LIGHTGUN_RELOAD,"Holster");
return rv;
}
static
uint32_t
setup_orbatak_descs(struct retro_input_descriptor *desc_,
const unsigned port_)
{
uint32_t rv;
rv = 0;
rv += setup_analog_left_desc(desc_++,port_,RETRO_DEVICE_ID_ANALOG_X,"Trackball (Horizontal)");
rv += setup_analog_left_desc(desc_++,port_,RETRO_DEVICE_ID_ANALOG_Y,"Trackball (Vertical)");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_SELECT,"Start (P1)");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_START,"Start (P2)");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_L,"Coin (P1)");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_R,"Coin (P2)");
rv += setup_joypad_desc(desc_++,port_,RETRO_DEVICE_ID_JOYPAD_R2,"Service");
return rv;
}
void
lr_input_device_set_with_descs(const uint32_t port_,
const uint32_t device_)
{
uint32_t i;
uint32_t rv;
struct retro_input_descriptor desc[256];
lr_input_device_set(port_,device_);
rv = 0;
lr_input_crosshair_reset(port_);
for(i = 0; i < LR_INPUT_MAX_DEVICES; i++)
{
switch(lr_input_device_get(i))
{
case RETRO_DEVICE_NONE:
break;
default:
case RETRO_DEVICE_JOYPAD:
rv += setup_joypad_descs(&desc[rv],i);
break;
case RETRO_DEVICE_FLIGHTSTICK:
rv += setup_flightstick_descs(&desc[rv],i);
break;
case RETRO_DEVICE_MOUSE:
rv += setup_mouse_descs(&desc[rv],i);
break;
case RETRO_DEVICE_LIGHTGUN:
rv += setup_lightgun_descs(&desc[rv],i);
break;
case RETRO_DEVICE_ARCADE_LIGHTGUN:
rv += setup_lightgun_arcade_descs(&desc[rv],i);
break;
case RETRO_DEVICE_ORBATAK_TRACKBALL:
rv += setup_orbatak_descs(&desc[rv],i);
break;
}
}
memset(&desc[rv],0,sizeof(struct retro_input_descriptor));
retro_environment_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS,desc);
}