Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/waterbox/gpgx/core/input_hw/input.c
2 views
1
/***************************************************************************************
2
* Genesis Plus
3
* Input peripherals support
4
*
5
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code)
6
* Copyright (C) 2007-2013 Eke-Eke (Genesis Plus GX)
7
*
8
* Redistribution and use of this code or any derivative works are permitted
9
* provided that the following conditions are met:
10
*
11
* - Redistributions may not be sold, nor may they be used in a commercial
12
* product or activity.
13
*
14
* - Redistributions that are modified from the original source must include the
15
* complete source code, including the source code for all components used by a
16
* binary built from the modified sources. However, as a special exception, the
17
* source code distributed need not include anything that is normally distributed
18
* (in either source or binary form) with the major components (compiler, kernel,
19
* and so on) of the operating system on which the executable runs, unless that
20
* component itself accompanies the executable.
21
*
22
* - Redistributions must reproduce the above copyright notice, this list of
23
* conditions and the following disclaimer in the documentation and/or other
24
* materials provided with the distribution.
25
*
26
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
* POSSIBILITY OF SUCH DAMAGE.
37
*
38
****************************************************************************************/
39
40
#include "shared.h"
41
#include "gamepad.h"
42
#include "lightgun.h"
43
#include "mouse.h"
44
#include "activator.h"
45
#include "xe_a1p.h"
46
#include "teamplayer.h"
47
#include "paddle.h"
48
#include "sportspad.h"
49
#include "terebi_oekaki.h"
50
51
t_input input;
52
int old_system[2] = {-1,-1};
53
54
55
void input_init(void)
56
{
57
int i;
58
int player = 0;
59
60
for (i=0; i<MAX_DEVICES; i++)
61
{
62
input.dev[i] = NO_DEVICE;
63
input.pad[i] = 0;
64
}
65
66
/* PICO tablet */
67
if (system_hw == SYSTEM_PICO)
68
{
69
input.dev[0] = DEVICE_PICO;
70
return;
71
}
72
73
/* Terebi Oekaki tablet */
74
if (cart.special & HW_TEREBI_OEKAKI)
75
{
76
input.dev[0] = DEVICE_TEREBI;
77
return;
78
}
79
80
switch (input.system[0])
81
{
82
case SYSTEM_MS_GAMEPAD:
83
{
84
input.dev[0] = DEVICE_PAD2B;
85
player++;
86
break;
87
}
88
89
case SYSTEM_MD_GAMEPAD:
90
{
91
input.dev[0] = config.input[player].padtype;
92
player++;
93
break;
94
}
95
96
case SYSTEM_MOUSE:
97
{
98
input.dev[0] = DEVICE_MOUSE;
99
player++;
100
break;
101
}
102
103
case SYSTEM_ACTIVATOR:
104
{
105
input.dev[0] = DEVICE_ACTIVATOR;
106
player++;
107
break;
108
}
109
110
case SYSTEM_XE_A1P:
111
{
112
input.dev[0] = DEVICE_XE_A1P;
113
player++;
114
break;
115
}
116
117
case SYSTEM_WAYPLAY:
118
{
119
for (i=0; i< 4; i++)
120
{
121
if (player < MAX_INPUTS)
122
{
123
input.dev[i] = config.input[player].padtype;
124
player++;
125
}
126
}
127
break;
128
}
129
130
case SYSTEM_TEAMPLAYER:
131
{
132
for (i=0; i<4; i++)
133
{
134
if (player < MAX_INPUTS)
135
{
136
input.dev[i] = config.input[player].padtype;
137
player++;
138
}
139
}
140
teamplayer_init(0);
141
break;
142
}
143
144
case SYSTEM_LIGHTPHASER:
145
{
146
input.dev[0] = DEVICE_LIGHTGUN;
147
player++;
148
break;
149
}
150
151
case SYSTEM_PADDLE:
152
{
153
input.dev[0] = DEVICE_PADDLE;
154
player++;
155
break;
156
}
157
158
case SYSTEM_SPORTSPAD:
159
{
160
input.dev[0] = DEVICE_SPORTSPAD;
161
player++;
162
break;
163
}
164
}
165
166
if (player == MAX_INPUTS)
167
{
168
return;
169
}
170
171
switch (input.system[1])
172
{
173
case SYSTEM_MS_GAMEPAD:
174
{
175
input.dev[4] = DEVICE_PAD2B;
176
player++;
177
break;
178
}
179
180
case SYSTEM_MD_GAMEPAD:
181
{
182
input.dev[4] = config.input[player].padtype;
183
player++;
184
break;
185
}
186
187
case SYSTEM_MOUSE:
188
{
189
input.dev[4] = DEVICE_MOUSE;
190
player++;
191
break;
192
}
193
194
case SYSTEM_ACTIVATOR:
195
{
196
input.dev[4] = DEVICE_ACTIVATOR;
197
player++;
198
break;
199
}
200
201
case SYSTEM_XE_A1P:
202
{
203
input.dev[4] = DEVICE_XE_A1P;
204
player++;
205
break;
206
}
207
208
case SYSTEM_MENACER:
209
{
210
input.dev[4] = DEVICE_LIGHTGUN;
211
player++;
212
break;
213
}
214
215
case SYSTEM_JUSTIFIER:
216
{
217
for (i=4; i<6; i++)
218
{
219
if (player < MAX_INPUTS)
220
{
221
input.dev[i] = DEVICE_LIGHTGUN;
222
player++;
223
}
224
}
225
break;
226
}
227
228
case SYSTEM_TEAMPLAYER:
229
{
230
for (i=4; i<8; i++)
231
{
232
if (player < MAX_INPUTS)
233
{
234
input.dev[i] = config.input[player].padtype;
235
player++;
236
}
237
}
238
teamplayer_init(1);
239
break;
240
}
241
242
case SYSTEM_LIGHTPHASER:
243
{
244
input.dev[4] = DEVICE_LIGHTGUN;
245
player++;
246
break;
247
}
248
249
case SYSTEM_PADDLE:
250
{
251
input.dev[4] = DEVICE_PADDLE;
252
player++;
253
break;
254
}
255
256
case SYSTEM_SPORTSPAD:
257
{
258
input.dev[4] = DEVICE_SPORTSPAD;
259
player++;
260
break;
261
}
262
}
263
264
/* J-CART */
265
if (cart.special & HW_J_CART)
266
{
267
/* two additional gamepads */
268
for (i=5; i<7; i++)
269
{
270
if (player < MAX_INPUTS)
271
{
272
input.dev[i] = config.input[player].padtype;
273
player ++;
274
}
275
}
276
}
277
}
278
279
void input_reset(void)
280
{
281
/* Reset input devices */
282
int i;
283
for (i=0; i<MAX_DEVICES; i++)
284
{
285
switch (input.dev[i])
286
{
287
case DEVICE_PAD2B:
288
case DEVICE_PAD3B:
289
case DEVICE_PAD6B:
290
{
291
gamepad_reset(i);
292
break;
293
}
294
295
case DEVICE_LIGHTGUN:
296
{
297
lightgun_reset(i);
298
break;
299
}
300
301
case DEVICE_MOUSE:
302
{
303
mouse_reset(i);
304
break;
305
}
306
307
case DEVICE_ACTIVATOR:
308
{
309
activator_reset(i >> 2);
310
break;
311
}
312
313
case DEVICE_XE_A1P:
314
{
315
xe_a1p_reset(i);
316
break;
317
}
318
319
case DEVICE_PADDLE:
320
{
321
paddle_reset(i);
322
break;
323
}
324
325
case DEVICE_SPORTSPAD:
326
{
327
sportspad_reset(i);
328
break;
329
}
330
331
case DEVICE_TEREBI:
332
{
333
terebi_oekaki_reset();
334
break;
335
}
336
337
default:
338
{
339
break;
340
}
341
}
342
}
343
344
/* Team Player */
345
for (i=0; i<2; i++)
346
{
347
if (input.system[i] == SYSTEM_TEAMPLAYER)
348
{
349
teamplayer_reset(i);
350
}
351
}
352
}
353
354
void input_refresh(void)
355
{
356
int i;
357
for (i=0; i<MAX_DEVICES; i++)
358
{
359
switch (input.dev[i])
360
{
361
case DEVICE_PAD6B:
362
{
363
gamepad_refresh(i);
364
break;
365
}
366
367
case DEVICE_LIGHTGUN:
368
{
369
lightgun_refresh(i);
370
break;
371
}
372
}
373
}
374
}
375
376