1 /***********************************************************************************
2   Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3 
4   (c) Copyright 1996 - 2002  Gary Henderson (gary.henderson@ntlworld.com),
5                              Jerremy Koot (jkoot@snes9x.com)
6 
7   (c) Copyright 2002 - 2004  Matthew Kendora
8 
9   (c) Copyright 2002 - 2005  Peter Bortas (peter@bortas.org)
10 
11   (c) Copyright 2004 - 2005  Joel Yliluoma (http://iki.fi/bisqwit/)
12 
13   (c) Copyright 2001 - 2006  John Weidman (jweidman@slip.net)
14 
15   (c) Copyright 2002 - 2006  funkyass (funkyass@spam.shaw.ca),
16                              Kris Bleakley (codeviolation@hotmail.com)
17 
18   (c) Copyright 2002 - 2010  Brad Jorsch (anomie@users.sourceforge.net),
19                              Nach (n-a-c-h@users.sourceforge.net),
20                              zones (kasumitokoduck@yahoo.com)
21 
22   (c) Copyright 2006 - 2007  nitsuja
23 
24   (c) Copyright 2009 - 2010  BearOso,
25                              OV2
26 
27 
28   BS-X C emulator code
29   (c) Copyright 2005 - 2006  Dreamer Nom,
30                              zones
31 
32   C4 x86 assembler and some C emulation code
33   (c) Copyright 2000 - 2003  _Demo_ (_demo_@zsnes.com),
34                              Nach,
35                              zsKnight (zsknight@zsnes.com)
36 
37   C4 C++ code
38   (c) Copyright 2003 - 2006  Brad Jorsch,
39                              Nach
40 
41   DSP-1 emulator code
42   (c) Copyright 1998 - 2006  _Demo_,
43                              Andreas Naive (andreasnaive@gmail.com),
44                              Gary Henderson,
45                              Ivar (ivar@snes9x.com),
46                              John Weidman,
47                              Kris Bleakley,
48                              Matthew Kendora,
49                              Nach,
50                              neviksti (neviksti@hotmail.com)
51 
52   DSP-2 emulator code
53   (c) Copyright 2003         John Weidman,
54                              Kris Bleakley,
55                              Lord Nightmare (lord_nightmare@users.sourceforge.net),
56                              Matthew Kendora,
57                              neviksti
58 
59   DSP-3 emulator code
60   (c) Copyright 2003 - 2006  John Weidman,
61                              Kris Bleakley,
62                              Lancer,
63                              z80 gaiden
64 
65   DSP-4 emulator code
66   (c) Copyright 2004 - 2006  Dreamer Nom,
67                              John Weidman,
68                              Kris Bleakley,
69                              Nach,
70                              z80 gaiden
71 
72   OBC1 emulator code
73   (c) Copyright 2001 - 2004  zsKnight,
74                              pagefault (pagefault@zsnes.com),
75                              Kris Bleakley
76                              Ported from x86 assembler to C by sanmaiwashi
77 
78   SPC7110 and RTC C++ emulator code used in 1.39-1.51
79   (c) Copyright 2002         Matthew Kendora with research by
80                              zsKnight,
81                              John Weidman,
82                              Dark Force
83 
84   SPC7110 and RTC C++ emulator code used in 1.52+
85   (c) Copyright 2009         byuu,
86                              neviksti
87 
88   S-DD1 C emulator code
89   (c) Copyright 2003         Brad Jorsch with research by
90                              Andreas Naive,
91                              John Weidman
92 
93   S-RTC C emulator code
94   (c) Copyright 2001 - 2006  byuu,
95                              John Weidman
96 
97   ST010 C++ emulator code
98   (c) Copyright 2003         Feather,
99                              John Weidman,
100                              Kris Bleakley,
101                              Matthew Kendora
102 
103   Super FX x86 assembler emulator code
104   (c) Copyright 1998 - 2003  _Demo_,
105                              pagefault,
106                              zsKnight
107 
108   Super FX C emulator code
109   (c) Copyright 1997 - 1999  Ivar,
110                              Gary Henderson,
111                              John Weidman
112 
113   Sound emulator code used in 1.5-1.51
114   (c) Copyright 1998 - 2003  Brad Martin
115   (c) Copyright 1998 - 2006  Charles Bilyue'
116 
117   Sound emulator code used in 1.52+
118   (c) Copyright 2004 - 2007  Shay Green (gblargg@gmail.com)
119 
120   SH assembler code partly based on x86 assembler code
121   (c) Copyright 2002 - 2004  Marcus Comstedt (marcus@mc.pp.se)
122 
123   2xSaI filter
124   (c) Copyright 1999 - 2001  Derek Liauw Kie Fa
125 
126   HQ2x, HQ3x, HQ4x filters
127   (c) Copyright 2003         Maxim Stepin (maxim@hiend3d.com)
128 
129   NTSC filter
130   (c) Copyright 2006 - 2007  Shay Green
131 
132   GTK+ GUI code
133   (c) Copyright 2004 - 2010  BearOso
134 
135   Win32 GUI code
136   (c) Copyright 2003 - 2006  blip,
137                              funkyass,
138                              Matthew Kendora,
139                              Nach,
140                              nitsuja
141   (c) Copyright 2009 - 2010  OV2
142 
143   Mac OS GUI code
144   (c) Copyright 1998 - 2001  John Stiles
145   (c) Copyright 2001 - 2010  zones
146 
147   (c) Copyright 2010 - 2016 Daniel De Matteis. (UNDER NO CIRCUMSTANCE
148   WILL COMMERCIAL RIGHTS EVER BE APPROPRIATED TO ANY PARTY)
149 
150   Specific ports contains the works of other authors. See headers in
151   individual files.
152 
153 
154   Snes9x homepage: http://www.snes9x.com/
155 
156   Permission to use, copy, modify and/or distribute Snes9x in both binary
157   and source form, for non-commercial purposes, is hereby granted without
158   fee, providing that this license information and copyright notice appear
159   with all copies and any derived work.
160 
161   This software is provided 'as-is', without any express or implied
162   warranty. In no event shall the authors be held liable for any damages
163   arising from the use of this software or it's derivatives.
164 
165   Snes9x is freeware for PERSONAL USE only. Commercial users should
166   seek permission of the copyright holders first. Commercial use includes,
167   but is not limited to, charging money for Snes9x or software derived from
168   Snes9x, including Snes9x or derivatives in commercial game bundles, and/or
169   using Snes9x as a promotion for your commercial product.
170 
171   The copyright holders request that bug fixes and improvements to the code
172   should be forwarded to them so everyone can benefit from the modifications
173   in future versions.
174 
175   Super NES and Super Nintendo Entertainment System are trademarks of
176   Nintendo Co., Limited and its subsidiary companies.
177  ***********************************************************************************/
178 
179 
180 #ifndef _CONTROLS_H_
181 #define _CONTROLS_H_
182 
183 #define S9xNoMapping			0
184 #define S9xButtonJoypad			1
185 #define S9xButtonMouse			2
186 #define S9xButtonSuperscope		3
187 #define S9xButtonJustifier		4
188 #define S9xPointer			8
189 
190 #define S9xBadMapping			255
191 #define InvalidControlID		((uint32) -1)
192 
193 #define CONTROLS_NONE			(-2)
194 #define MP5				(-1)
195 #define JOYPAD0				0
196 #define JOYPAD1				1
197 #define JOYPAD2				2
198 #define JOYPAD3				3
199 #define JOYPAD4				4
200 #define JOYPAD5				5
201 #define JOYPAD6				6
202 #define JOYPAD7				7
203 #define MOUSE0				8
204 #define MOUSE1				9
205 #define SUPERSCOPE			10
206 #define ONE_JUSTIFIER			11
207 #define TWO_JUSTIFIERS			12
208 #define NUMCTLS				13 /* This must be LAST */
209 
210 typedef struct
211 {
212 	uint8	type;
213 
214 	union
215 	{
216 		union
217 		{
218 			uint16 joypad;	/* Which buttons to actuate. Use SNES_*_MASK constants from snes9x.h */
219 
220 			struct
221 			{
222 				uint8	idx:1;			/* Mouse number 0-1 */
223 				uint8	left:1;			/* buttons */
224 				uint8	right:1;
225 			}	mouse;
226 
227 			struct
228 			{
229 				uint8	fire:1;
230 				uint8	cursor:1;
231 				uint8	turbo:1;
232 				uint8	pause:1;
233 				/* Pretend we're pointing the gun offscreen (ignore the pointer)*/
234 				uint8	aim_offscreen:1;
235 			}	scope;
236 
237 			struct
238 			{
239 				uint8	idx:3;			/* Pseudo-pointer number 0-7 */
240 				uint8	speed_type:2;		/* 0=variable, 1=slow, 2=med, 3=fast */
241 				int8	UD:2;			/* -1=up, 1=down, 0=no vertical motion */
242 				int8	LR:2;			/* -1=left, 1=right, 0=no horizontal motion */
243 			}	pointer;
244 
245 			struct
246 			{
247 				uint8	idx:1;			/* Justifier number 0-1 */
248 				uint8	trigger:1;		/* buttons */
249 				uint8	start:1;
250 				/* Pretend we're pointing the gun offscreen (ignore the pointer) */
251 				uint8	aim_offscreen:1;
252 			}	justifier;
253 
254 			uint16	command;
255 		} button;
256 
257 		struct	/* Which SNES-pointers to control with this pointer */
258 		{
259 			uint16	aim_mouse0:1;
260 			uint16	aim_mouse1:1;
261 			uint16	aim_scope:1;
262 			uint16	aim_justifier0:1;
263 			uint16	aim_justifier1:1;
264 		}	pointer;
265 
266 		uint8	port[4];
267 	} commandunion;
268 }	s9xcommand_t;
269 
270 /* Starting out... */
271 
272 void S9xUnmapAllControls (void);
273 
274 /* Setting which controllers are plugged in. */
275 
276 #define CTL_NONE 0		/* all ids ignored */
277 #define CTL_JOYPAD 1		/* use id1 to specify 0-7 */
278 #define CTL_MOUSE 2		/* use id1 to specify 0-1 */
279 #define CTL_SUPERSCOPE 3
280 #define CTL_JUSTIFIER 4		/* use id1: 0=one justifier, 1=two justifiers */
281 #define CTL_MP5 5		/* use id1-id4 to specify pad 0-7 (or -1) */
282 
283 void S9xSetController (int port, unsigned controller, int8 id1, int8 id2, int8 id3, int8 id4); /* port=0-1 */
284 
285 /* Call this when you're done with S9xSetController, or if you change any of
286    the controller Settings.*Master flags.
287 
288    Returns true if something was disabled. */
289 
290 bool8 S9xVerifyControllers (void);
291 
292 /* Functions for translating s9xcommand_t's into strings, and vice versa.
293    free() the returned string after you're done with it. */
294 
295 s9xcommand_t S9xGetCommandT (const char *name);
296 
297 /* Generic mapping functions */
298 
299 /* Button mapping functions.
300 
301    snes9x will assume you will call S9xReportButton() whenever the
302    button state changes.
303    S9xMapButton() will fail and return FALSE if mapping.type isn't an S9xButton* type. */
304 
305 bool8 S9xMapButton (uint32 id, s9xcommand_t mapping);
306 void S9xReportButton (uint32 id, bool8 pressed);
307 
308 /* Pointer mapping functions.
309 
310    snes9x will assume you will call S9xReportPointer() whenever the
311    pointer position changes.
312 
313    S9xMapPointer() will fail and return FALSE if mapping.type isn't an
314    S9xPointer* type.
315 
316    Note that position [0,0] is considered the upper-left corner of the 'screen',
317    and either [255,223] or [255,239] is the lower-right.
318 
319    Note that the SNES mouse doesn't aim at a particular point,
320    so the SNES's idea of where the mouse pointer is will probably differ
321    from your OS's idea. */
322 
323 bool8 S9xMapPointer (uint32 id, s9xcommand_t mapping);
324 void S9xReportPointer (uint32 id, int16 x, int16 y);
325 
326 /* Do whatever the s9xcommand_t says to do.
327    If cmd.type is a button type, data1 should be TRUE (non-0) or FALSE (0)
328    to indicate whether the 'button' is pressed or released.
329 
330    If cmd.type is an axis, data1 holds the deflection value.
331 
332    If cmd.type is a pointer, data1 and data2 are the positions of the pointer. */
333 
334 void S9xApplyCommand (s9xcommand_t cmd, int16 data1, int16 data2);
335 
336 /* These functions are called from snes9x into this subsystem. No need to use them from a port. */
337 
338 /* Use when resetting snes9x. */
339 
340 void S9xControlsReset (void);
341 void S9xControlsSoftReset (void);
342 
343 /* End-Of-Frame processing. Sets gun latch variables and tries to draw crosshairs */
344 
345 void S9xControlEOF (void);
346 
347 /* Functions and a structure for snapshot. */
348 
349 struct SControlSnapshot
350 {
351 	uint8	ver;
352 	uint8	port1_read_idx[2];
353 	uint8	dummy1[4];		/* for future expansion */
354 	uint8	port2_read_idx[2];
355 	uint8	dummy2[4];
356 	uint8	mouse_speed[2];
357 	uint8	justifier_select;
358 	uint8	dummy3[8];
359 	bool8	pad_read;
360 	uint8	internal[60];		/* yes, we need to save this! */
361 };
362 
363 void S9xControlPreSaveState (struct SControlSnapshot *s);
364 void S9xControlPostLoadState (struct SControlSnapshot *s);
365 
366 #endif
367