DIP Switches in MAME: Difference between revisions

From MAMEDEV Wiki
m (→‎Example: adding table)
mNo edit summary
 
(10 intermediate revisions by 4 users not shown)
Line 1: Line 1:
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 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.


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.
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==
==How DIP Switches work==


(a picture a of dipswitch would help here) http://en.wikipedia.org/wiki/Image:Dipswitch.JPG
Here's a picture of a DIP switch package.... http://en.wikipedia.org/wiki/File: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!
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==
==How DIP Switches are Coded in MAME==
Line 13: Line 17:
The following macros are the most common ones for DIPs.
The following macros are the most common ones for DIPs.


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


'''PORT_DIPNAME''' is used as the name of what the setting does and follows the format
'''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'' )
  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.
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 each setting and follows the format
'''PORT_DIPSETTING''' is used to define possible values for a setting setting and follows the format


  PORT_DIPSETTING( ''position'', ''name'' )
  PORT_DIPSETTING( ''position'', ''name'' )


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


'''PORT_DIPLOCATION''' defines which switches are used and are shown in the DIP Switch menu
'''PORT_DIPLOCATION''' is used to declare which physical switches correspond to the setting:


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


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.
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.
These are the most commonly uses macros, for more advanced ones see /src/emu/inptport.h in the MAME source code.
Line 43: Line 49:
===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


{| border="1" cellpadding="4" cellspacing="0"
{| border="1" cellpadding="4" cellspacing="0"
|-
|-
!align="right" |
!align="right" |
|SW1
|SW1 1
|SW2
|SW1 2
|-
|-
!align="right" |2 Lives
!align="right" |2 Lives
Line 71: Line 77:
|}
|}


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


{| border="1" cellpadding="4" cellspacing="0"
{| border="1" cellpadding="4" cellspacing="0"
|-
|-
!align="right" |
!align="right" |
|SW3
|SW1 3
|SW4
|SW1 4
|-
|-
!align="right" |Over 5000
!align="right" |Over 5000
Line 97: Line 103:
|}
|}


Setting the mode of the game uses SW5
Setting the mode of the game uses SW1 5


{| border="1" cellpadding="4" cellspacing="0"
{| border="1" cellpadding="4" cellspacing="0"
|-
|-
!align="right" |
!align="right" |
|SW5
|SW1 5
|-
|-
!align="right" |Table
!align="right" |Table
Line 113: Line 119:




SW6 SW7 and SW8 are not used
SW1 6, 7 and 8 are not used




Line 139: 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
or on Windows
Line 145: Line 151:
  findstr PORT_DIPNAME src\mame\drivers\*.c | findstr Unknown
  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 [http://www.mameworld.net/gurudumps/DumpingProject/diplist.html Guru's Unknown DIPs page].
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).


The inptport.h file where the DIP related macros are declared can be viewed at
The inptport.h file where the DIP related macros are declared can be viewed at
[http://www.mameworld.net/maws/mamesrc/src/emu/inptport.h MAWS - MAME souce]
[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)