(:toc:) !!Overview All [[Hardware/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 [[Hardware/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 [[Hardware/SG-1000]]/[[Hardware/Mark III]] controller hardware which is mapped to the [[keyboard]] interface. Known peripherals include: *[[Joypad]] *[[Paddle]] *[[Sports Pad]] *[[Light Phaser]] *[[Reset Button]] !!Physical port configuration (:include ControllerPort:) !! 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: !!![[#port3f]]Port $3F: I/O port control ||border=1 ||! 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 [[Hardware/Mark III]]''' (there's no TH at all) '''and Japanese [[Hardware/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. [[#portdc]] !!!Port $DC: I/O port A and B ||border=1 ||! 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) [[#portdd]] !!!Port $DD: I/O port B and miscellaneous ||border=1 ||! 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. !! I/O port mirrors '''Master System, Master System II:''' ||border=1 ||! 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):''' ||border=1 ||! 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):''' ||border=1 ||! 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. !!References *[[http://www.techno-junk.org/txt/smstech.txt|SMS/GG hardware notes]] by Charles `MacDonald *[[http://www.techno-junk.org/txt/gen-hw.txt|Sega Genesis hardware notes]] by Charles `MacDonald