Overview

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:

Physical port configuration

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 numberFunction
1Up
2Down
3Left
4Right
5VCC
6TL
7TH (Gnd on Mark III)
8Gnd
9TR

The use of these pins depends on the peripheral being used.

Accessing from software

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:

Port $3F: I/O port control

BitFunction
7Port B TH pin output level (1=high, 0=low)
6Port B TR pin output level (1=high, 0=low)
5Port A TH pin output level (1=high, 0=low)
4Port A TR pin output level (1=high, 0=low)
3Port B TH pin direction (1=input, 0=output)
2Port B TR pin direction (1=input, 0=output)
1Port A TH pin direction (1=input, 0=output)
0Port 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.

Port $DC: I/O port A and B

BitFunction
7Port B Down pin input
6Port B Up pin input
5Port A TR pin input
4Port A TL pin input
3Port A Right pin input
2Port A Left pin input
1Port A Down pin input
0Port A Up pin input

(1= not pressed, 0= pressed)

Port $DD: I/O port B and miscellaneous

BitFunction
7Port B TH pin input
6Port A TH pin input
5Cartridge slot CONT pin *
4Reset button *
3Port B TR pin input
2Port B TL pin input
1Port B Right pin input
0Port 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.

I/O port mirrors

Master System, Master System II:

PortMirrors
$3FAll odd addresses from $01 to $3F
$DCAll even addresses from $C0 to $FE
$DDAll odd addresses from $C1 to $FF

Game Gear (GG mode):

PortMirrors
$3FAll odd addresses from $07 to $3F
$DC$C0 only
$DD$C1 only

Game Gear (SMS mode), Mega Drive (MD and SMS modes):

PortMirrors
$3FAll 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.

References




Return to top
0.065s