Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
RishiRecon
GitHub Repository: RishiRecon/exploits
Path: blob/main/misc/emulator/xnes/snes9x/controls.h
28547 views
1
/***********************************************************************************
2
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3
4
(c) Copyright 1996 - 2002 Gary Henderson ([email protected]),
5
Jerremy Koot ([email protected])
6
7
(c) Copyright 2002 - 2004 Matthew Kendora
8
9
(c) Copyright 2002 - 2005 Peter Bortas ([email protected])
10
11
(c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/)
12
13
(c) Copyright 2001 - 2006 John Weidman ([email protected])
14
15
(c) Copyright 2002 - 2006 funkyass ([email protected]),
16
Kris Bleakley ([email protected])
17
18
(c) Copyright 2002 - 2010 Brad Jorsch ([email protected]),
19
Nach ([email protected]),
20
21
(c) Copyright 2002 - 2011 zones ([email protected])
22
23
(c) Copyright 2006 - 2007 nitsuja
24
25
(c) Copyright 2009 - 2011 BearOso,
26
OV2
27
28
29
BS-X C emulator code
30
(c) Copyright 2005 - 2006 Dreamer Nom,
31
zones
32
33
C4 x86 assembler and some C emulation code
34
(c) Copyright 2000 - 2003 _Demo_ ([email protected]),
35
Nach,
36
zsKnight ([email protected])
37
38
C4 C++ code
39
(c) Copyright 2003 - 2006 Brad Jorsch,
40
Nach
41
42
DSP-1 emulator code
43
(c) Copyright 1998 - 2006 _Demo_,
44
Andreas Naive ([email protected]),
45
Gary Henderson,
46
Ivar ([email protected]),
47
John Weidman,
48
Kris Bleakley,
49
Matthew Kendora,
50
Nach,
51
neviksti ([email protected])
52
53
DSP-2 emulator code
54
(c) Copyright 2003 John Weidman,
55
Kris Bleakley,
56
Lord Nightmare ([email protected]),
57
Matthew Kendora,
58
neviksti
59
60
DSP-3 emulator code
61
(c) Copyright 2003 - 2006 John Weidman,
62
Kris Bleakley,
63
Lancer,
64
z80 gaiden
65
66
DSP-4 emulator code
67
(c) Copyright 2004 - 2006 Dreamer Nom,
68
John Weidman,
69
Kris Bleakley,
70
Nach,
71
z80 gaiden
72
73
OBC1 emulator code
74
(c) Copyright 2001 - 2004 zsKnight,
75
pagefault ([email protected]),
76
Kris Bleakley
77
Ported from x86 assembler to C by sanmaiwashi
78
79
SPC7110 and RTC C++ emulator code used in 1.39-1.51
80
(c) Copyright 2002 Matthew Kendora with research by
81
zsKnight,
82
John Weidman,
83
Dark Force
84
85
SPC7110 and RTC C++ emulator code used in 1.52+
86
(c) Copyright 2009 byuu,
87
neviksti
88
89
S-DD1 C emulator code
90
(c) Copyright 2003 Brad Jorsch with research by
91
Andreas Naive,
92
John Weidman
93
94
S-RTC C emulator code
95
(c) Copyright 2001 - 2006 byuu,
96
John Weidman
97
98
ST010 C++ emulator code
99
(c) Copyright 2003 Feather,
100
John Weidman,
101
Kris Bleakley,
102
Matthew Kendora
103
104
Super FX x86 assembler emulator code
105
(c) Copyright 1998 - 2003 _Demo_,
106
pagefault,
107
zsKnight
108
109
Super FX C emulator code
110
(c) Copyright 1997 - 1999 Ivar,
111
Gary Henderson,
112
John Weidman
113
114
Sound emulator code used in 1.5-1.51
115
(c) Copyright 1998 - 2003 Brad Martin
116
(c) Copyright 1998 - 2006 Charles Bilyue'
117
118
Sound emulator code used in 1.52+
119
(c) Copyright 2004 - 2007 Shay Green ([email protected])
120
121
SH assembler code partly based on x86 assembler code
122
(c) Copyright 2002 - 2004 Marcus Comstedt ([email protected])
123
124
2xSaI filter
125
(c) Copyright 1999 - 2001 Derek Liauw Kie Fa
126
127
HQ2x, HQ3x, HQ4x filters
128
(c) Copyright 2003 Maxim Stepin ([email protected])
129
130
NTSC filter
131
(c) Copyright 2006 - 2007 Shay Green
132
133
GTK+ GUI code
134
(c) Copyright 2004 - 2011 BearOso
135
136
Win32 GUI code
137
(c) Copyright 2003 - 2006 blip,
138
funkyass,
139
Matthew Kendora,
140
Nach,
141
nitsuja
142
(c) Copyright 2009 - 2011 OV2
143
144
Mac OS GUI code
145
(c) Copyright 1998 - 2001 John Stiles
146
(c) Copyright 2001 - 2011 zones
147
148
149
Specific ports contains the works of other authors. See headers in
150
individual files.
151
152
153
Snes9x homepage: http://www.snes9x.com/
154
155
Permission to use, copy, modify and/or distribute Snes9x in both binary
156
and source form, for non-commercial purposes, is hereby granted without
157
fee, providing that this license information and copyright notice appear
158
with all copies and any derived work.
159
160
This software is provided 'as-is', without any express or implied
161
warranty. In no event shall the authors be held liable for any damages
162
arising from the use of this software or it's derivatives.
163
164
Snes9x is freeware for PERSONAL USE only. Commercial users should
165
seek permission of the copyright holders first. Commercial use includes,
166
but is not limited to, charging money for Snes9x or software derived from
167
Snes9x, including Snes9x or derivatives in commercial game bundles, and/or
168
using Snes9x as a promotion for your commercial product.
169
170
The copyright holders request that bug fixes and improvements to the code
171
should be forwarded to them so everyone can benefit from the modifications
172
in future versions.
173
174
Super NES and Super Nintendo Entertainment System are trademarks of
175
Nintendo Co., Limited and its subsidiary companies.
176
***********************************************************************************/
177
178
179
#ifndef _CONTROLS_H_
180
#define _CONTROLS_H_
181
182
#define S9xNoMapping 0
183
#define S9xButtonJoypad 1
184
#define S9xButtonMouse 2
185
#define S9xButtonSuperscope 3
186
#define S9xButtonJustifier 4
187
#define S9xButtonCommand 5
188
#define S9xButtonMulti 6
189
#define S9xAxisJoypad 7
190
#define S9xPointer 8
191
192
#define S9xButtonPseudopointer 254
193
#define S9xAxisPseudopointer 253
194
#define S9xAxisPseudobuttons 252
195
196
// These are automatically kicked out to the S9xHandlePortCommand function.
197
// If your port wants to define port-specific commands or whatever, use these values for the s9xcommand_t type field.
198
199
#define S9xButtonPort 251
200
#define S9xAxisPort 250
201
#define S9xPointerPort 249
202
203
#define S9xBadMapping 255
204
#define InvalidControlID ((uint32) -1)
205
206
// S9xButtonPseudopointer and S9xAxisPseudopointer will report pointer motion using IDs PseudoPointerBase through PseudoPointerBase+7.
207
// S9xAxisPseudopointer command types. S9xAxisPseudobuttons will report buttons with IDs PseudoButtonBase to PseudoButtonBase+255.
208
209
#define PseudoPointerBase (InvalidControlID - 8)
210
#define PseudoButtonBase (PseudoPointerBase - 256)
211
212
typedef struct
213
{
214
uint8 type;
215
uint8 multi_press:2;
216
uint8 button_norpt:1;
217
218
union
219
{
220
union
221
{
222
struct
223
{
224
uint8 idx:3; // Pad number 0-7
225
uint8 toggle:1; // If set, toggle turbo/sticky for the button
226
uint8 turbo:1; // If set, be a 'turbo' button
227
uint8 sticky:1; // If set, toggle button state (on/turbo or off) when pressed and do nothing on release
228
uint16 buttons; // Which buttons to actuate. Use SNES_*_MASK constants from snes9x.h
229
} joypad;
230
231
struct
232
{
233
uint8 idx:1; // Mouse number 0-1
234
uint8 left:1; // buttons
235
uint8 right:1;
236
} mouse;
237
238
struct
239
{
240
uint8 fire:1;
241
uint8 cursor:1;
242
uint8 turbo:1;
243
uint8 pause:1;
244
uint8 aim_offscreen:1; // Pretend we're pointing the gun offscreen (ignore the pointer)
245
} scope;
246
247
struct
248
{
249
uint8 idx:3; // Pseudo-pointer number 0-7
250
uint8 speed_type:2; // 0=variable, 1=slow, 2=med, 3=fast
251
int8 UD:2; // -1=up, 1=down, 0=no vertical motion
252
int8 LR:2; // -1=left, 1=right, 0=no horizontal motion
253
} pointer;
254
255
struct
256
{
257
uint8 idx:1; // Justifier number 0-1
258
uint8 trigger:1; // buttons
259
uint8 start:1;
260
uint8 aim_offscreen:1; // Pretend we're pointing the gun offscreen (ignore the pointer)
261
} justifier;
262
263
int32 multi_idx;
264
uint16 command;
265
} button;
266
267
union
268
{
269
struct
270
{
271
uint8 idx:3; // Pad number 0-7
272
uint8 invert:1; // 1 = positive is Left/Up/Y/X/L
273
uint8 axis:3; // 0=Left/Right, 1=Up/Down, 2=Y/A, 3=X/B, 4=L/R
274
uint8 threshold; // (threshold+1)/256% deflection is a button press
275
} joypad;
276
277
struct
278
{
279
uint8 idx:3; // Pseudo-pointer number 0-7
280
uint8 speed_type:2; // 0=variable, 1=slow, 2=med, 3=fast
281
uint8 invert:1; // 1 = invert axis, so positive is up/left
282
uint8 HV:1; // 0=horizontal, 1=vertical
283
} pointer;
284
285
struct
286
{
287
uint8 threshold; // (threshold+1)/256% deflection is a button press
288
uint8 negbutton; // Button ID for negative deflection
289
uint8 posbutton; // Button ID for positive deflection
290
} button;
291
} axis;
292
293
struct // Which SNES-pointers to control with this pointer
294
{
295
uint16 aim_mouse0:1;
296
uint16 aim_mouse1:1;
297
uint16 aim_scope:1;
298
uint16 aim_justifier0:1;
299
uint16 aim_justifier1:1;
300
} pointer;
301
302
uint8 port[4];
303
} input;
304
} s9xcommand_t;
305
306
// Starting out...
307
308
void S9xUnmapAllControls (void);
309
310
// Setting which controllers are plugged in.
311
312
enum controllers
313
{
314
CTL_NONE, // all ids ignored
315
CTL_JOYPAD, // use id1 to specify 0-7
316
CTL_MOUSE, // use id1 to specify 0-1
317
CTL_SUPERSCOPE,
318
CTL_JUSTIFIER, // use id1: 0=one justifier, 1=two justifiers
319
CTL_MP5 // use id1-id4 to specify pad 0-7 (or -1)
320
};
321
322
void S9xSetController (int port, enum controllers controller, int8 id1, int8 id2, int8 id3, int8 id4); // port=0-1
323
void S9xGetController (int port, enum controllers *controller, int8 *id1, int8 *id2, int8 *id3, int8 *id4);
324
void S9xReportControllers (void);
325
326
// Call this when you're done with S9xSetController, or if you change any of the controller Settings.*Master flags.
327
// Returns true if something was disabled.
328
329
bool S9xVerifyControllers (void);
330
331
// Functions for translation s9xcommand_t's into strings, and vice versa.
332
// free() the returned string after you're done with it.
333
334
char * S9xGetCommandName (s9xcommand_t command);
335
s9xcommand_t S9xGetCommandT (const char *name);
336
337
// Returns an array of strings naming all the snes9x commands.
338
// Note that this is only the strings for S9xButtonCommand!
339
// The idea is that this would be used for a pull-down list in a config GUI. DO NOT free() the returned value.
340
341
const char ** S9xGetAllSnes9xCommands (void);
342
343
// Generic mapping functions
344
345
s9xcommand_t S9xGetMapping (uint32 id);
346
void S9xUnmapID (uint32 id);
347
348
// Button mapping functions.
349
// If a button is mapped with poll=TRUE, then S9xPollButton will be called whenever snes9x feels a need for that mapping.
350
// Otherwise, snes9x will assume you will call S9xReportButton() whenever the button state changes.
351
// S9xMapButton() will fail and return FALSE if mapping.type isn't an S9xButton* type.
352
353
bool S9xMapButton (uint32 id, s9xcommand_t mapping, bool poll);
354
void S9xReportButton (uint32 id, bool pressed);
355
356
// Pointer mapping functions.
357
// If a pointer is mapped with poll=TRUE, then S9xPollPointer will be called whenever snes9x feels a need for that mapping.
358
// Otherwise, snes9x will assume you will call S9xReportPointer() whenever the pointer position changes.
359
// S9xMapPointer() will fail and return FALSE if mapping.type isn't an S9xPointer* type.
360
361
// Note that position [0,0] is considered the upper-left corner of the 'screen',
362
// and either [255,223] or [255,239] is the lower-right.
363
// Note that the SNES mouse doesn't aim at a particular point,
364
// so the SNES's idea of where the mouse pointer is will probably differ from your OS's idea.
365
366
bool S9xMapPointer (uint32 id, s9xcommand_t mapping, bool poll);
367
void S9xReportPointer (uint32 id, int16 x, int16 y);
368
369
// Axis mapping functions.
370
// If an axis is mapped with poll=TRUE, then S9xPollAxis will be called whenever snes9x feels a need for that mapping.
371
// Otherwise, snes9x will assume you will call S9xReportAxis() whenever the axis deflection changes.
372
// S9xMapAxis() will fail and return FALSE if mapping.type isn't an S9xAxis* type.
373
374
// Note that value is linear -32767 through 32767 with 0 being no deflection.
375
// If your axis reports differently you should transform the value before passing it to S9xReportAxis().
376
377
bool S9xMapAxis (uint32 id, s9xcommand_t mapping, bool poll);
378
void S9xReportAxis (uint32 id, int16 value);
379
380
// Do whatever the s9xcommand_t says to do.
381
// If cmd.type is a button type, data1 should be TRUE (non-0) or FALSE (0) to indicate whether the 'button' is pressed or released.
382
// If cmd.type is an axis, data1 holds the deflection value.
383
// If cmd.type is a pointer, data1 and data2 are the positions of the pointer.
384
385
void S9xApplyCommand (s9xcommand_t cmd, int16 data1, int16 data2);
386
387
//////////
388
// These functions are called by snes9x into your port, so each port should implement them.
389
390
// If something was mapped with poll=TRUE, these functions will be called when snes9x needs the button/axis/pointer state.
391
// Fill in the reference options as appropriate.
392
393
bool S9xPollButton (uint32 id, bool *pressed);
394
bool S9xPollPointer (uint32 id, int16 *x, int16 *y);
395
bool S9xPollAxis (uint32 id, int16 *value);
396
397
// These are called when snes9x tries to apply a command with a S9x*Port type.
398
// data1 and data2 are filled in like S9xApplyCommand.
399
400
void S9xHandlePortCommand (s9xcommand_t cmd, int16 data1, int16 data2);
401
402
// Called before already-read SNES joypad data is being used by the game if your port defines SNES_JOY_READ_CALLBACKS.
403
404
#ifdef SNES_JOY_READ_CALLBACKS
405
void S9xOnSNESPadRead (void);
406
#endif
407
408
// These are for your use.
409
410
s9xcommand_t S9xGetPortCommandT (const char *name);
411
char * S9xGetPortCommandName (s9xcommand_t command);
412
void S9xSetupDefaultKeymap (void);
413
bool8 S9xMapInput (const char *name, s9xcommand_t *cmd);
414
415
//////////
416
// These functions are called from snes9x into this subsystem. No need to use them from a port.
417
418
// Use when resetting snes9x.
419
420
void S9xControlsReset (void);
421
void S9xControlsSoftReset (void);
422
423
// Use when writing to $4016.
424
425
void S9xSetJoypadLatch (bool latch);
426
427
// Use when reading $4016/7 (JOYSER0 and JOYSER1).
428
429
uint8 S9xReadJOYSERn (int n);
430
431
// End-Of-Frame processing. Sets gun latch variables and tries to draw crosshairs
432
433
void S9xControlEOF (void);
434
435
// Functions and a structure for snapshot.
436
437
struct SControlSnapshot
438
{
439
uint8 ver;
440
uint8 port1_read_idx[2];
441
uint8 dummy1[4]; // for future expansion
442
uint8 port2_read_idx[2];
443
uint8 dummy2[4];
444
uint8 mouse_speed[2];
445
uint8 justifier_select;
446
uint8 dummy3[8];
447
bool8 pad_read, pad_read_last;
448
uint8 internal[60]; // yes, we need to save this!
449
};
450
451
void S9xControlPreSaveState (struct SControlSnapshot *s);
452
void S9xControlPostLoadState (struct SControlSnapshot *s);
453
454
#endif
455
456