1 #ifndef INPTPORT_H
2 #define INPTPORT_H
3 
4 #include "memory.h"
5 #include "input.h"
6 
7 /* input ports handling */
8 
9 /* Don't confuse this with the I/O ports in memory.h. This is used to handle game */
10 /* inputs (joystick, coin slots, etc). Typically, you will read them using */
11 /* input_port_[n]_r(), which you will associate to the appropriate memory */
12 /* address or I/O port. */
13 
14 /***************************************************************************/
15 
16 struct InputPortTiny
17 {
18 	UINT16 mask;			/* bits affected */
19 	UINT16 default_value;	/* default value for the bits affected */
20 							/* you can also use one of the IP_ACTIVE defines below */
21 	UINT32 type;			/* see defines below */
22 	const char *name;		/* name to display */
23 };
24 
25 struct InputPort
26 {
27 	UINT16 mask;			/* bits affected */
28 	UINT16 default_value;	/* default value for the bits affected */
29 							/* you can also use one of the IP_ACTIVE defines below */
30 	UINT32 type;			/* see defines below */
31 	const char *name;		/* name to display */
32 	InputSeq seq;                  	/* input sequence affecting the input bits */
33 #ifdef MESS
34 	UINT32 arg;				/* extra argument needed in some cases */
35 	UINT16 min, max;		/* for analog controls */
36 #endif
37 };
38 
39 
40 #define IP_ACTIVE_HIGH 0x0000
41 #define IP_ACTIVE_LOW 0xffff
42 
43 enum { IPT_END=1,IPT_PORT,
44 	/* use IPT_JOYSTICK for panels where the player has one single joystick */
45 	IPT_JOYSTICK_UP, IPT_JOYSTICK_DOWN, IPT_JOYSTICK_LEFT, IPT_JOYSTICK_RIGHT,
46 	/* use IPT_JOYSTICKLEFT and IPT_JOYSTICKRIGHT for dual joystick panels */
47 	IPT_JOYSTICKRIGHT_UP, IPT_JOYSTICKRIGHT_DOWN, IPT_JOYSTICKRIGHT_LEFT, IPT_JOYSTICKRIGHT_RIGHT,
48 	IPT_JOYSTICKLEFT_UP, IPT_JOYSTICKLEFT_DOWN, IPT_JOYSTICKLEFT_LEFT, IPT_JOYSTICKLEFT_RIGHT,
49 	IPT_BUTTON1, IPT_BUTTON2, IPT_BUTTON3, IPT_BUTTON4,	/* action buttons */
50 	IPT_BUTTON5, IPT_BUTTON6, IPT_BUTTON7, IPT_BUTTON8, IPT_BUTTON9, IPT_BUTTON10,
51 
52 	/* analog inputs */
53 	/* the "arg" field contains the default sensitivity expressed as a percentage */
54 	/* (100 = default, 50 = half, 200 = twice) */
55 	IPT_ANALOG_START,
56 	IPT_PADDLE, IPT_PADDLE_V,
57 	IPT_DIAL, IPT_DIAL_V,
58 	IPT_TRACKBALL_X, IPT_TRACKBALL_Y,
59 	IPT_AD_STICK_X, IPT_AD_STICK_Y,
60 	IPT_PEDAL,
61 	IPT_ANALOG_END,
62 
63 	IPT_START1, IPT_START2, IPT_START3, IPT_START4,	/* start buttons */
64 	IPT_COIN1, IPT_COIN2, IPT_COIN3, IPT_COIN4,	/* coin slots */
65 	IPT_SERVICE1, IPT_SERVICE2, IPT_SERVICE3, IPT_SERVICE4,	/* service coin */
66 	IPT_SERVICE, IPT_TILT,
67 	IPT_DIPSWITCH_NAME, IPT_DIPSWITCH_SETTING,
68 /* Many games poll an input bit to check for vertical blanks instead of using */
69 /* interrupts. This special value allows you to handle that. If you set one of the */
70 /* input bits to this, the bit will be inverted while a vertical blank is happening. */
71 	IPT_VBLANK,
72 	IPT_UNKNOWN,
73 	IPT_EXTENSION,	/* this is an extension on the previous InputPort, not a real inputport. */
74 					/* It is used to store additional parameters for analog inputs */
75 
76 	/* the following are special codes for user interface handling - not to be used by drivers! */
77 	IPT_UI_CONFIGURE,
78 	IPT_UI_ON_SCREEN_DISPLAY,
79 	IPT_UI_PAUSE,
80 	IPT_UI_RESET_MACHINE,
81 	IPT_UI_SHOW_GFX,
82 	IPT_UI_FRAMESKIP_DEC,
83 	IPT_UI_FRAMESKIP_INC,
84 	IPT_UI_THROTTLE,
85 	IPT_UI_SHOW_FPS,
86 	IPT_UI_SNAPSHOT,
87 	IPT_UI_TOGGLE_CHEAT,
88 	IPT_UI_UP,
89 	IPT_UI_DOWN,
90 	IPT_UI_LEFT,
91 	IPT_UI_RIGHT,
92 	IPT_UI_SELECT,
93 	IPT_UI_CANCEL,
94 	IPT_UI_PAN_UP, IPT_UI_PAN_DOWN, IPT_UI_PAN_LEFT, IPT_UI_PAN_RIGHT,
95 	IPT_UI_SHOW_PROFILER,
96 	IPT_UI_SHOW_COLORS,
97 	IPT_UI_TOGGLE_UI,
98 	__ipt_max
99 };
100 
101 #define IPT_UNUSED     IPF_UNUSED
102 #define IPT_SPECIAL    IPT_UNUSED	/* special meaning handled by custom functions */
103 
104 #define IPF_MASK       0xffffff00
105 #define IPF_UNUSED     0x80000000	/* The bit is not used by this game, but is used */
106 									/* by other games running on the same hardware. */
107 									/* This is different from IPT_UNUSED, which marks */
108 									/* bits not connected to anything. */
109 #define IPF_COCKTAIL   IPF_PLAYER2	/* the bit is used in cocktail mode only */
110 
111 #define IPF_CHEAT      0x40000000	/* Indicates that the input bit is a "cheat" key */
112 									/* (providing invulnerabilty, level advance, and */
113 									/* so on). MAME will not recognize it when the */
114 									/* -nocheat command line option is specified. */
115 
116 #define IPF_PLAYERMASK 0x00030000	/* use IPF_PLAYERn if more than one person can */
117 #define IPF_PLAYER1    0         	/* play at the same time. The IPT_ should be the same */
118 #define IPF_PLAYER2    0x00010000	/* for all players (e.g. IPT_BUTTON1 | IPF_PLAYER2) */
119 #define IPF_PLAYER3    0x00020000	/* IPF_PLAYER1 is the default and can be left out to */
120 #define IPF_PLAYER4    0x00030000	/* increase readability. */
121 
122 #define IPF_8WAY       0         	/* Joystick modes of operation. 8WAY is the default, */
123 #define IPF_4WAY       0x00080000	/* it prevents left/right or up/down to be pressed at */
124 #define IPF_2WAY       0         	/* the same time. 4WAY prevents diagonal directions. */
125 									/* 2WAY should be used for joysticks wich move only */
126                                  	/* on one axis (e.g. Battle Zone) */
127 
128 #define IPF_IMPULSE    0x00100000	/* When this is set, when the key corrisponding to */
129 									/* the input bit is pressed it will be reported as */
130 									/* pressed for a certain number of video frames and */
131 									/* then released, regardless of the real status of */
132 									/* the key. This is useful e.g. for some coin inputs. */
133 									/* The number of frames the signal should stay active */
134 									/* is specified in the "arg" field. */
135 #define IPF_TOGGLE     0x00200000	/* When this is set, the key acts as a toggle - press */
136 									/* it once and it goes on, press it again and it goes off. */
137 									/* useful e.g. for sone Test Mode dip switches. */
138 #define IPF_REVERSE    0x00400000	/* By default, analog inputs like IPT_TRACKBALL increase */
139 									/* when going right/up. This flag inverts them. */
140 
141 #define IPF_CENTER     0x00800000	/* always preload in->default, autocentering the STICK/TRACKBALL */
142 
143 #define IPF_CUSTOM_UPDATE 0x01000000 /* normally, analog ports are updated when they are accessed. */
144 									/* When this flag is set, they are never updated automatically, */
145 									/* it is the responsibility of the driver to call */
146 									/* update_analog_port(int port). */
147 
148 #define IPF_RESETCPU   0x02000000	/* when the key is pressed, reset the first CPU */
149 
150 
151 /* The "arg" field contains 4 bytes fields */
152 #define IPF_SENSITIVITY(percent)	((percent & 0xff) << 8)
153 #define IPF_DELTA(val)				((val & 0xff) << 16)
154 
155 #define IP_GET_IMPULSE(port) (((port)->type >> 8) & 0xff)
156 #define IP_GET_SENSITIVITY(port) ((((port)+1)->type >> 8) & 0xff)
157 #define IP_SET_SENSITIVITY(port,val) ((port)+1)->type = ((port+1)->type & 0xffff00ff)|((val&0xff)<<8)
158 #define IP_GET_DELTA(port) ((((port)+1)->type >> 16) & 0xff)
159 #define IP_SET_DELTA(port,val) ((port)+1)->type = ((port+1)->type & 0xff00ffff)|((val&0xff)<<16)
160 #define IP_GET_MIN(port) (((port)+1)->mask)
161 #define IP_GET_MAX(port) (((port)+1)->default_value)
162 #define IP_GET_CODE_OR1(port) ((port)->mask)
163 #define IP_GET_CODE_OR2(port) ((port)->default_value)
164 
165 #define IP_NAME_DEFAULT ((const char *)-1)
166 
167 /* Wrapper for compatibility */
168 #define IP_KEY_DEFAULT CODE_DEFAULT
169 #define IP_JOY_DEFAULT CODE_DEFAULT
170 #define IP_KEY_PREVIOUS CODE_PREVIOUS
171 #define IP_JOY_PREVIOUS CODE_PREVIOUS
172 #define IP_KEY_NONE CODE_NONE
173 #define IP_JOY_NONE CODE_NONE
174 
175 /* start of table */
176 #define INPUT_PORTS_START(name) \
177 	static struct InputPortTiny input_ports_##name[] = {
178 
179 /* end of table */
180 #define INPUT_PORTS_END \
181 	{ 0, 0, IPT_END, 0  } \
182 	};
183 /* start of a new input port */
184 #define PORT_START \
185 	{ 0, 0, IPT_PORT, 0 },
186 
187 /* input bit definition */
188 #define PORT_BIT(mask,default,type) \
189 	{ mask, default, type, IP_NAME_DEFAULT },
190 
191 /* impulse input bit definition */
192 #define PORT_BIT_IMPULSE(mask,default,type,duration) \
193 	{ mask, default, type | IPF_IMPULSE | ((duration & 0xff) << 8), IP_NAME_DEFAULT },
194 
195 /* key/joy code specification */
196 #define PORT_CODE(key,joy) \
197 	{ key, joy, IPT_EXTENSION, 0 },
198 
199 /* input bit definition with extended fields */
200 #define PORT_BITX(mask,default,type,name,key,joy) \
201 	{ mask, default, type, name }, \
202 	PORT_CODE(key,joy)
203 
204 /* analog input */
205 #define PORT_ANALOG(mask,default,type,sensitivity,delta,min,max) \
206 	{ mask, default, type, IP_NAME_DEFAULT }, \
207 	{ min, max, IPT_EXTENSION | IPF_SENSITIVITY(sensitivity) | IPF_DELTA(delta), IP_NAME_DEFAULT },
208 
209 #define PORT_ANALOGX(mask,default,type,sensitivity,delta,min,max,keydec,keyinc,joydec,joyinc) \
210 	{ mask, default, type, IP_NAME_DEFAULT  }, \
211 	{ min, max, IPT_EXTENSION | IPF_SENSITIVITY(sensitivity) | IPF_DELTA(delta), IP_NAME_DEFAULT }, \
212 	PORT_CODE(keydec,joydec) \
213 	PORT_CODE(keyinc,joyinc)
214 
215 /* dip switch definition */
216 #define PORT_DIPNAME(mask,default,name) \
217 	{ mask, default, IPT_DIPSWITCH_NAME, name },
218 
219 #define PORT_DIPSETTING(default,name) \
220 	{ 0, default, IPT_DIPSWITCH_SETTING, name },
221 
222 
223 #define PORT_SERVICE(mask,default)	\
224 	PORT_BITX(    mask, mask & default, IPT_DIPSWITCH_NAME | IPF_TOGGLE, DEF_STR( Service_Mode ), KEYCODE_F2, IP_JOY_NONE )	\
225 	PORT_DIPSETTING(    mask & default, DEF_STR( Off ) )	\
226 	PORT_DIPSETTING(    mask &~default, DEF_STR( On ) )
227 
228 #define MAX_DEFSTR_LEN 20
229 extern char ipdn_defaultstrings[][MAX_DEFSTR_LEN];
230 
231 /* this must match the ipdn_defaultstrings list in inptport.c */
232 enum {
233 	STR_Off,
234 	STR_On,
235 	STR_No,
236 	STR_Yes,
237 	STR_Lives,
238 	STR_Bonus_Life,
239 	STR_Difficulty,
240 	STR_Demo_Sounds,
241 	STR_Coinage,
242 	STR_Coin_A,
243 	STR_Coin_B,
244 	STR_9C_1C,
245 	STR_8C_1C,
246 	STR_7C_1C,
247 	STR_6C_1C,
248 	STR_5C_1C,
249 	STR_4C_1C,
250 	STR_3C_1C,
251 	STR_8C_3C,
252 	STR_4C_2C,
253 	STR_2C_1C,
254 	STR_5C_3C,
255 	STR_3C_2C,
256 	STR_4C_3C,
257 	STR_4C_4C,
258 	STR_3C_3C,
259 	STR_2C_2C,
260 	STR_1C_1C,
261 	STR_4C_5C,
262 	STR_3C_4C,
263 	STR_2C_3C,
264 	STR_4C_7C,
265 	STR_2C_4C,
266 	STR_1C_2C,
267 	STR_2C_5C,
268 	STR_2C_6C,
269 	STR_1C_3C,
270 	STR_2C_7C,
271 	STR_2C_8C,
272 	STR_1C_4C,
273 	STR_1C_5C,
274 	STR_1C_6C,
275 	STR_1C_7C,
276 	STR_1C_8C,
277 	STR_1C_9C,
278 	STR_Free_Play,
279 	STR_Cabinet,
280 	STR_Upright,
281 	STR_Cocktail,
282 	STR_Flip_Screen,
283 	STR_Service_Mode,
284 	STR_Unused,
285 	STR_Unknown,
286 	STR_TOTAL
287 };
288 
289 #define DEF_STR(str_num) (ipdn_defaultstrings[STR_##str_num])
290 
291 #define MAX_INPUT_PORTS 20
292 
293 
294 int load_input_port_settings(void);
295 void save_input_port_settings(void);
296 
297 const char *input_port_name(const struct InputPort *in);
298 InputSeq* input_port_type_seq(int type);
299 InputSeq* input_port_seq(const struct InputPort *in);
300 
301 struct InputPort* input_port_allocate(const struct InputPortTiny *src);
302 void input_port_free(struct InputPort* dst);
303 
304 #ifdef MAME_NET
305 void set_default_player_controls(int player);
306 #endif /* MAME_NET */
307 
308 void update_analog_port(int port);
309 void update_input_ports(void);	/* called by cpuintrf.c - not for external use */
310 void inputport_vblank_end(void);	/* called by cpuintrf.c - not for external use */
311 
312 int readinputport(int port);
313 READ_HANDLER( input_port_0_r );
314 READ_HANDLER( input_port_1_r );
315 READ_HANDLER( input_port_2_r );
316 READ_HANDLER( input_port_3_r );
317 READ_HANDLER( input_port_4_r );
318 READ_HANDLER( input_port_5_r );
319 READ_HANDLER( input_port_6_r );
320 READ_HANDLER( input_port_7_r );
321 READ_HANDLER( input_port_8_r );
322 READ_HANDLER( input_port_9_r );
323 READ_HANDLER( input_port_10_r );
324 READ_HANDLER( input_port_11_r );
325 READ_HANDLER( input_port_12_r );
326 READ_HANDLER( input_port_13_r );
327 READ_HANDLER( input_port_14_r );
328 READ_HANDLER( input_port_15_r );
329 READ_HANDLER( input_port_16_r );
330 READ_HANDLER( input_port_17_r );
331 READ_HANDLER( input_port_18_r );
332 READ_HANDLER( input_port_19_r );
333 
334 struct ipd
335 {
336 	UINT32 type;
337 	const char *name;
338 	InputSeq seq;
339 };
340 
341 #endif
342