All Master System hardware includes two 9-pin DE-9 ports into which peripherals may be plugged. In most cases, the peripheral is a joypad but other hardware was produced.
The Game Gear uses the same method to access its controller hardware, although its Start button was an addition that could not be added into the existing scheme.
Note that this page does not apply to the SG-1000/Mark III controller hardware which is mapped to the keyboard interface.
Known peripherals include:
The port is a standard DE-9 (commonly mis-titled "DB9") male connector, accepting a female controller plug. Viewed from the front of the port:
1 5 o o o o o o o o o 6 9
Pin functions:
Pin number | Function |
---|---|
1 | Up |
2 | Down |
3 | Left |
4 | Right |
5 | VCC |
6 | TL |
7 | TH (Gnd on Mark III) |
8 | Gnd |
9 | TR |
The use of these pins depends on the peripheral being used.
There are three 8-bit control registers for reading and writing to the controller ports. They have standard officially-documented locations but also many mirrors within the Z80 port space. The control registers are:
Bit | Function |
---|---|
7 | Port B TH pin output level (1=high, 0=low) |
6 | Port B TR pin output level (1=high, 0=low) |
5 | Port A TH pin output level (1=high, 0=low) |
4 | Port A TR pin output level (1=high, 0=low) |
3 | Port B TH pin direction (1=input, 0=output) |
2 | Port B TR pin direction (1=input, 0=output) |
1 | Port A TH pin direction (1=input, 0=output) |
0 | Port A TR pin direction (1=input, 0=output) |
This port is used to control the two input/output lines available on each controller port (referred to as ports A and B). Some control hardware needs to recieve input from the CPU to perform its task, and uses one or more of these lines. Passive hardware uses all of them as inputs.
This functionality is not present on the Mark III (there's no TH at all) and Japanese Master System (when the TH pins are configured as outputs via port $3F, bits 7,6 of port $DD are always zero regardless of the TH pins being pulled high or low). As a result, it is commonly used for region detection. It also means that for compatibility, it defaults to an input-only state (ie. with all the low bits set) on startup.
Bit | Function |
---|---|
7 | Port B Down pin input |
6 | Port B Up pin input |
5 | Port A TR pin input |
4 | Port A TL pin input |
3 | Port A Right pin input |
2 | Port A Left pin input |
1 | Port A Down pin input |
0 | Port A Up pin input |
(1= not pressed, 0= pressed)
Bit | Function |
---|---|
7 | Port B TH pin input |
6 | Port A TH pin input |
5 | Cartridge slot CONT pin * |
4 | Reset button * |
3 | Port B TR pin input |
2 | Port B TL pin input |
1 | Port B Right pin input |
0 | Port B Left pin input |
(1= not pressed, 0= pressed)
* These map to hardware which does not exist on some systems (eg. SMS2 has neither). Reset always returns 1
when hardware is not present; CONT generally returns 1
on 8-bit hardware and 0
on a Mega Drive.
The hardware attached to the input lines is such that they return 1
when unconnected, and a "button press" is registered by pulling the pin
to Gnd. Of course, for more exotic peripheral hardware, the zero or one
state can signify more than just a simple button press.
Master System, Master System II:
Port | Mirrors |
---|---|
$3F | All odd addresses from $01 to $3F |
$DC | All even addresses from $C0 to $FE |
$DD | All odd addresses from $C1 to $FF |
Game Gear (GG mode):
Port | Mirrors |
---|---|
$3F | All odd addresses from $07 to $3F |
$DC | $C0 only |
$DD | $C1 only |
Game Gear (SMS mode), Mega Drive (MD and SMS modes):
Port | Mirrors |
---|---|
$3F | All odd addresses from $01 to $3F |
$DC | $C0 only |
$DD | $C1 only |
An emulator should handle all mirrors but it is highly unrecommended to use non-standard ports in homebrew software.