DIP Switches in MAME

From MAMEDEV Wiki
Revision as of 17:46, 7 March 2007 by Mellery (talk | contribs) (→‎Example: adding table)

DIP switches were used by arcade games to allow settings like difficulty, cost per play, number of lives, etc. For more info and pictures of DIP switches see the Wikipedia article. DIP Switches can be viewed and set in game by pressing TAB and going to the menu marked DIP Switches.

A large number of DIP switch settings are not documented, and thus marked as Unknown. Some games will not run or will display wrong colors if DIP switches are not set correctly, so figuring out what these unknown switches do is helpful. What these switches do can be determined by looking at the games code, reading the game's operator manual, or by just adjusting the DIP switches and observing how the game runs differently (this method is usually not enough to figure out what most switches do). Also, some games manuals do not cover different regions or versions or the same game, so what the settings should be checked in game to verify the manual is correct.

How DIP Switches work

(a picture a of dipswitch would help here) http://en.wikipedia.org/wiki/Image:Dipswitch.JPG

Dip switches usually come in packages of 8, and from left to right are numbered 1 to 8. DIP Switch 8 would be the least significant bit (LSB0 and DIP Switch 1 would be the most significant bit (MSB). DIP Switches are binary (they can be ON or OFF, 1 or 0). So using binary, from MSB to LSB the switches have the values 128 64 32 16 8 4 2 1 equaling 256 different possible combinations!

How DIP Switches are Coded in MAME

The following macros are the most common ones for DIPs.

PORT_START is to declare the start of a new input port (dipswitch)

PORT_DIPNAME is used as the name of what the setting does and follows the format

PORT_DIPNAME( dip_value, default_position, name )

Where dip_value and default_position are in hex, and name is a string. Some settings need more than one switch, so dip_value and default_position could be the sum of a few switches.

PORT_DIPSETTING is used to define each setting and follows the format

PORT_DIPSETTING( position, name )

Where position is in hex, and name is a string.

PORT_DIPLOCATION defines which switches are used and are shown in the DIP Switch menu

PORT_DIPLOCATION( "switch:x" )

Where switch is the name of the DIP Switch on the PCB, and x are the numbers of the dip switches used separated by comma. When covering more than one bit, the dip switch numbers are listed from LSB to MSB order.

PORT_DIPLOCATION was recently added to MAME and most drivers still need someone to add the dip locations

PORT_DIPUNUSED_DIPLOC is a shorthand way of adding dips when they are unused. If a board has multiple unused DIPs they should each have there own PORT_DIPUNUSED_DIPLOC so they can still each be individually toggled.

PORT_DIPUNUSED_DIPLOC( dip_value, default_position, "switch:x" )

These are the most commonly uses macros, for more advanced ones see /src/emu/inptport.h in the MAME source code.

Example

Here is the code used to define DIP Switch 0 for the game Zero Hour from the driver redclash.c. Zero Hour uses an addition DIP Switch DSW1 which is not shown here. Look in the MAME source for many more examples. First the dip settings as defined in the operator's manual, and then the actual code.

Setting the number of lives uses SW1 and SW2

SW1 SW2
2 Lives ON ON
3 Lives OFF OFF
4 Lives OFF ON
5 Lives ON OFF

Setting the required score for additional spaceship uses SW3 and SW 4

SW3 SW4
Over 5000 OFF OFF
Over 8000 OFF ON
Over 10000 ON OFF
No Extra ON ON

Setting the mode of the game uses SW5

SW5
Table OFF
Upright ON


SW6 SW7 and SW8 are not used


The above looks like the following in code,

PORT_START	/* DSW0 */
PORT_DIPUNUSED_DIPLOC( 0x01, 0x01, "SW1:8" ) 	/* Switches 6-8 are not used */
PORT_DIPUNUSED_DIPLOC( 0x02, 0x02, "SW1:7" )
PORT_DIPUNUSED_DIPLOC( 0x04, 0x04, "SW1:6" )
PORT_DIPNAME( 0x08, 0x00, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("SW1:5")
PORT_DIPSETTING(    0x00, DEF_STR( Upright ) )
PORT_DIPSETTING(    0x08, DEF_STR( Cocktail ) )
PORT_DIPNAME( 0x30, 0x00, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("SW1:4,3")
PORT_DIPSETTING(    0x00, "5000" )
PORT_DIPSETTING(    0x10, "8000" )
PORT_DIPSETTING(    0x20, "10000" )
PORT_DIPSETTING(    0x30, "No Bonus" )
PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Lives ) ) PORT_DIPLOCATION("SW1:2,1")
PORT_DIPSETTING(    0x00, "2" )
PORT_DIPSETTING(    0xc0, "3" )
PORT_DIPSETTING(    0x80, "4" )
PORT_DIPSETTING(    0x40, "5" )

More Information

To generate a list of games which have dips marked as unknown do the following GREP,

grep PORT_DIPNAME src/mame/drivers/*.c | grep Unknown

or on Windows

findstr PORT_DIPNAME src\mame\drivers\*.c | findstr Unknown

A list of games with unknown dips, but is not always up to date can be found at Guru's Unknown DIPs page.

The inptport.h file where the DIP related macros are declared can be viewed at MAWS - MAME souce