DIP Switches in MAME: Difference between revisions

From MAMEDEV Wiki
mNo edit summary
 
(15 intermediate revisions by 5 users not shown)
Line 1: Line 1:
=DIP Switches in MAME=
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 [http://en.wikipedia.org/wiki/DIP_switch Wikipedia article].  DIP Switches can be viewed and set in game by pressing TAB and going to the menu marked DIP Switches.


DIP switches were used by arcade games to allow certain settings like difficulty, cost per play, number of lives, etcFor more info and pictures of DIP switches see the [http://en.wikipedia.org/wiki/Dip_switch 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 helpfulWhat these switches do can be determined by looking at the game 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 game manuals do not cover different regions or versions of the same game, so the settings should be checked in game to verify the manual is correct.    On top of this, there are cases where the game is buggy, or the manual is wrong.


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 can be 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==


==How DIP Switches work==
Here's a picture of a DIP switch package.... http://en.wikipedia.org/wiki/File:Dipswitch.JPG
 
DIP switches (Dual Inline Package switches) are small banks of switches, with the same pin spacing as integrated circuits.  This makes them convenient for use with automated PCB assembly system.  They generally come in packages of four to twelve switches.  When you're looking at the DIP switches "right-way up", the switches will be numbered from left to right, starting at number 1.  In almost all cases, pushing a switch up switches it on (i.e. closes the contacts).


(a picture a of dipswitch would help here) http://en.wikipedia.org/wiki/Image:Dipswitch.JPG
Most arcade PCBs use packages of eight DIP switches, as they can be conveniently connected to an 8-bit input port (this isn't always the case - Bally Midway MCR uses 10-switch packages).  The switches in a single package will generally be connected to consecutive bits in an input port.  Depending on how the switches are wired, and how the logic works, turning a switch on may produce a logic 0 or 1, and the port may be wired so that switch 1 is the most significant bit (MSB) and switch 8 is the least significant bit (LSB), or it could be wired the other way around so that switch 1 is the LSB and switch 8 is the MSB.


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!
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 (0x80 0x40 0x20 0x10 0x08 0x04 0x02 0x01) equalling 256 different possible combinations!


==How DIP Switches are Coded in MAME==
==How DIP Switches are Coded in MAME==


'''PORT_DIPNAME''' is used as the name of what the setting does and follows the format
The following macros are the most common ones for DIPs.


PORT_DIPNAME( dip value, default position, name)
'''PORT_START''' is to declare the start of a new input port (DIP switch)


Where dip value and default position are in hex, and name is a string.
'''PORT_DIPNAME''' is used to declare the name of the setting (what it does), which port bits it uses and what the default setting is. It follows the format


Some settings need more than one switch, so dip value and position could be the sum of a few switches.
PORT_DIPNAME( ''dip_value'', ''default_position'', ''name'' )


'''PORT_DIPSETTING''' is used to define each setting and follows the format
Where ''dip_value'' is the sum of the values of the switches used for this setting, ''default_position'' is the default value for the setting (best to get this from the manual) and ''name'' is a string.  ''dip_value'' and ''default_position'' are usually specified in hex, as it's easier to calculate bit masks this way. 


PORT_DIPSETTING( position, name )
'''PORT_DIPSETTING''' is used to define possible values for a setting setting and follows the format


Where position is in hex, and name is a string.
PORT_DIPSETTING( ''position'', ''name'' )


'''PORT_DIPLOCATION''' defines which switches are used and are shown in the DIP Switch menu
Where ''position'' is in the value (usually in hex), and ''name'' is a descriptive string.


PORT_DIPLOCATION("switch:x")
'''PORT_DIPLOCATION''' is used to declare which physical switches correspond to the setting:


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.
PORT_DIPLOCATION( "''switch'':''[''!'']x['',''[switch'':''][''!'']y['',''...]]''" )
 
Where ''switch'' is the name of the DIP switch bank on the PCB, and ''x'', ''y'', etc. are the numbers of the switches used.  The switches are listed from least significant to most significant bit.  If turning the switch on produces a logic 1 (as in early Nintendo games), prefix the number with a '''!''' (you don't need a prefix if turning the switch on produces a logic 0).  If all the switches are in a single bank, you only need to specify the bank name once at the beginning.


PORT_DIPLOCATION was recently added to MAME and most drivers still need someone to add the dip locations  
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''' is a shorthand way of adding DIPs when they are unused, '''PORT_DIPUNKNOWN_DIPLOC''' is a shorthand way of adding DIPs when their function is unknown and '''PORT_SERVICE_DIPLOC''' is a shorthand way of adding a service mode DIP switch.  If a board has multiple unused/unknown DIPs, each switch should have its own declaration so they can still each be individually toggled.


PORT_DIPUNUSED_DIPLOC( dip value, default position, "switch:x" )
PORT_DIPUNUSED_DIPLOC( ''dip_value'', ''default_position'', "''switch'':''[''!'']x''" )
PORT_DIPUNKNOWN_DIPLOC( ''dip_value'', ''default_position'', "''switch'':''[''!'']x''" )
PORT_SERVICE_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===
===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.
Here is the code used to define DIP switch bank SW0 for the game Zero Hour from the driver redclash.c.  Zero Hour uses an addition DIP switch bank 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.  In this case, the switches are wired so that turning a switch on produces a logic 0, and switch 8 is the LSB and switch 1 is the MSB.


Setting the number of lives uses SW1 and SW2
Setting the number of lives uses SW1 1 and 2
<br>          SW1 SW2
<br>2 lives = on  on
<br>3 lives = off off
<br>4 lives = off on
<br>5 lives = on  off


Setting the required score for additional spaceship uses SW3 and SW 4
{| border="1" cellpadding="4" cellspacing="0"
<br>            SW3 SW4
|-
<br>over 5000  = off off
!align="right" |
<br>over 8000  = off on
|SW1 1
<br>over 10000 = on  off
|SW1 2
<br>no extra  = on  on
|-
!align="right" |2 Lives
|ON
|ON
|-
!align="right" |3 Lives
|OFF
|OFF
|-
!align="right" |4 Lives
|OFF
|ON
|-
!align="right" |5 Lives
|ON
|OFF
|-
|}


Setting the mode of the game uses SW5
Setting the required score for additional spaceship uses SW1 3 and 4
<br>Table  = off
<br>Upright = on


SW6 SW7 and SW8 are not used
{| border="1" cellpadding="4" cellspacing="0"
|-
!align="right" |
|SW1 3
|SW1 4
|-
!align="right" |Over 5000
|OFF
|OFF
|-
!align="right" |Over 8000
|OFF
|ON
|-
!align="right" |Over 10000
|ON
|OFF
|-
!align="right" |No Extra
|ON
|ON
|-
|}


Setting the mode of the game uses SW1 5


----
{| border="1" cellpadding="4" cellspacing="0"
|-
!align="right" |
|SW1 5
|-
!align="right" |Table
|OFF
|-
!align="right" |Upright
|ON
|-
|}


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


==More Information==
==More Information==
Line 91: Line 145:
To generate a list of games which have dips marked as unknown do the following GREP,
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
egrep 'PORT_DIPNAME|PORT_DIPUNKNOWN' src/mame/drivers/*.c | grep -i Unknown
 
or on Windows
 
findstr PORT_DIPNAME src\mame\drivers\*.c | findstr Unknown


or a list of games with unknown dips, but is a few releases out of date can be found here
A list of games with unknown dips, but is not always up to date can be found at [http://web.archive.org/web/20081220000907/http://www.mameworld.net/gurudumps/DumpingProject/diplist.html Guru's Unknown DIPs page] (archived).


http://www.mameworld.net/gurudumps/DumpingProject/diplist.html
The inptport.h file where the DIP related macros are declared can be viewed at
[https://github.com/mamedev/mame/blob/master/src/emu/inptport.h MAME source]. (broken link)

Latest revision as of 18:18, 31 March 2015

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 game 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 game manuals do not cover different regions or versions of the same game, so the settings should be checked in game to verify the manual is correct. On top of this, there are cases where the game is buggy, or the manual is wrong.

How DIP Switches work

Here's a picture of a DIP switch package.... http://en.wikipedia.org/wiki/File:Dipswitch.JPG

DIP switches (Dual Inline Package switches) are small banks of switches, with the same pin spacing as integrated circuits. This makes them convenient for use with automated PCB assembly system. They generally come in packages of four to twelve switches. When you're looking at the DIP switches "right-way up", the switches will be numbered from left to right, starting at number 1. In almost all cases, pushing a switch up switches it on (i.e. closes the contacts).

Most arcade PCBs use packages of eight DIP switches, as they can be conveniently connected to an 8-bit input port (this isn't always the case - Bally Midway MCR uses 10-switch packages). The switches in a single package will generally be connected to consecutive bits in an input port. Depending on how the switches are wired, and how the logic works, turning a switch on may produce a logic 0 or 1, and the port may be wired so that switch 1 is the most significant bit (MSB) and switch 8 is the least significant bit (LSB), or it could be wired the other way around so that switch 1 is the LSB and switch 8 is the MSB.

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 (0x80 0x40 0x20 0x10 0x08 0x04 0x02 0x01) equalling 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 (DIP switch)

PORT_DIPNAME is used to declare the name of the setting (what it does), which port bits it uses and what the default setting is. It follows the format

PORT_DIPNAME( dip_value, default_position, name )

Where dip_value is the sum of the values of the switches used for this setting, default_position is the default value for the setting (best to get this from the manual) and name is a string. dip_value and default_position are usually specified in hex, as it's easier to calculate bit masks this way.

PORT_DIPSETTING is used to define possible values for a setting setting and follows the format

PORT_DIPSETTING( position, name )

Where position is in the value (usually in hex), and name is a descriptive string.

PORT_DIPLOCATION is used to declare which physical switches correspond to the setting:

PORT_DIPLOCATION( "switch:[!]x[,[switch:][!]y[,...]]" )

Where switch is the name of the DIP switch bank on the PCB, and x, y, etc. are the numbers of the switches used. The switches are listed from least significant to most significant bit. If turning the switch on produces a logic 1 (as in early Nintendo games), prefix the number with a ! (you don't need a prefix if turning the switch on produces a logic 0). If all the switches are in a single bank, you only need to specify the bank name once at the beginning.

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, PORT_DIPUNKNOWN_DIPLOC is a shorthand way of adding DIPs when their function is unknown and PORT_SERVICE_DIPLOC is a shorthand way of adding a service mode DIP switch. If a board has multiple unused/unknown DIPs, each switch should have its own declaration so they can still each be individually toggled.

PORT_DIPUNUSED_DIPLOC( dip_value, default_position, "switch:[!]x" )
PORT_DIPUNKNOWN_DIPLOC( dip_value, default_position, "switch:[!]x" )
PORT_SERVICE_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 bank SW0 for the game Zero Hour from the driver redclash.c. Zero Hour uses an addition DIP switch bank 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. In this case, the switches are wired so that turning a switch on produces a logic 0, and switch 8 is the LSB and switch 1 is the MSB.

Setting the number of lives uses SW1 1 and 2

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

Setting the required score for additional spaceship uses SW1 3 and 4

SW1 3 SW1 4
Over 5000 OFF OFF
Over 8000 OFF ON
Over 10000 ON OFF
No Extra ON ON

Setting the mode of the game uses SW1 5

SW1 5
Table OFF
Upright ON


SW1 6, 7 and 8 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,

egrep 'PORT_DIPNAME|PORT_DIPUNKNOWN' src/mame/drivers/*.c | grep -i 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 (archived).

The inptport.h file where the DIP related macros are declared can be viewed at MAME source. (broken link)