The Z80 has a separate address space for devices, reached with IN and OUT. The console decodes only a few
address lines of the port number, so every device answers at many ports: the Master System uses bits 7, 6 and 0 (the
decoding shown by SMS Power’s port map and used in JSSMS’s ports.js, which picks the device by port & 0xC1).
The explorer puts the name in the note of every IN A,(n) and OUT (n),A; ports in register C
(IN r,(C), OUTI, OTIR…) cannot be named without running the program.
Sources are SMS Power’s three port maps and Charles MacDonald’s Sega Master System / Game Gear Technical Information for the bit meanings.
Master System
| Port | Viewer name | Direction | What it is |
|---|---|---|---|
0x00–0x3F, even (0x3E) | MEM_CONTROL | write | Memory control |
0x01–0x3F, odd (0x3F) | IO_CONTROL | write | I/O control |
0x40–0x7F, even (0x7E) | VCOUNT | read | VDP vertical counter |
0x41–0x7F, odd (0x7F) | HCOUNT | read | VDP horizontal counter |
0x40–0x7F, any (0x7F) | PSG | write | SN76489 sound chip |
0x80–0xBE, even (0xBE) | VDP_DATA | read, write | VDP data port |
0x81–0xBF, odd (0xBF) | VDP_CONTROL, VDP_STATUS | write, read | VDP control port and status |
0xC0–0xFF, even (0xDC) | IO_PORT_A | read | Joypad port A and part of port B |
0xC1–0xFF, odd (0xDD) | IO_PORT_B | read | Port B and miscellaneous |
0xF0 | FM_REG | write | YM2413 register select (the FM sound unit of the Japanese Master System and Mark III) |
0xF1 | FM_DATA | write | YM2413 register data |
0xF2 | AUDIO_CTRL | write, read | Audio control port; bit 0 can be written and read back to detect the FM unit, after setting bit 2 of port 0x3E to disable the I/O chip |
On the original VDP (SMS1) SMS Power shows reads of the memory and I/O control ports as the open bus, on the later one as
0xFF. The writes to 0xC0–0xFF other than the FM ports do nothing. Ports 0xDE and
0xDF belonged to the SC-3000’s keyboard chip and some software writes to them; they are not Master System ports.
SMS Power’s Mark III column lists only the ports 0x3E, 0x3F, 0x7E, 0x7F, 0xBE, 0xBF, 0xC0, 0xC1, 0xDC, 0xDD and 0xF0–0xF2 (not the mirrors), and says that most Mark III port information is still missing.
Memory control (0x3E) and I/O control (0x3F)
| Port | Bit | Meaning |
|---|---|---|
0x3E (write) | 7 | Expansion slot disabled |
| 6 | Cartridge slot disabled | |
| 5 | Card slot disabled | |
| 4 | Work RAM disabled | |
| 3 | BIOS ROM disabled | |
| 2 | I/O chip disabled (needed to read 0xF2 for the FM unit) | |
0x3F (write) | 7, 5 | Output level of the TH pin of port B, port A |
| 6, 4 | Output level of the TR pin of port B, port A | |
| 3, 1 | Direction of the TH pin of port B, port A | |
| 2, 0 | Direction of the TR pin of port B, port A |
Bits 1 and 0 of 0x3E are unknown.
Joypads (0xDC and 0xDD)
A button that is pressed reads 0.
| Bit | 0xDC | 0xDD |
|---|---|---|
| 7 | Port B down | Port B TH |
| 6 | Port B up | Port A TH |
| 5 | Port A TR | unused (1 on the SMS, SMS 2 and Game Gear) |
| 4 | Port A TL | Reset button (0 = pressed; always 1 on the Game Gear) |
| 3 | Port A right | Port B TR |
| 2 | Port A left | Port B TL |
| 1 | Port A down | Port B right |
| 0 | Port A up | Port B left |
Game Gear
In Game Gear mode ports 0x00–0x06 are the Game Gear’s own; 0x07–0x3F decode as on the
Master System, and so do the rest, with the Game Gear reading 0xFF from 0xF0–0xFF and joypad 1 and 2 from
0xC0/0xDC and 0xC1/0xDD. When the cartridge runs the console in Master System mode, SMS Power’s
table shows ports 0x00–0x06 as the memory and I/O control ports again.
| Port | Viewer name | What it is |
|---|---|---|
0x00 | GG_START | Start button, read: bit 7 is 1 when not pressed and 0 when pressed (SMS Power, Start Button). The other bits are not described by that page. In Master System mode the Start button acts like the Pause button. |
0x01 | GG_SERIAL | Serial port (the name in SMS Power’s port map). Its bits are not described in any source read. |
0x02 | GG_SERIAL_DIR | Direction of the seven parallel bits of the Gear-to-Gear port: 0 is output, 1 is input (SMS Power, Gear to Gear Cable). |
0x03 | GG_SERIAL_TX | In parallel mode, read or written to receive or transmit the seven bits (they arrive in a different order: sent bit 0, 1, 2, 3, 4, 5, 6 is received as bit 2, 3, 0, 1, 5, 4, 6). In serial mode, writing sends a byte; check bit 0 of port 0x05 first. |
0x04 | GG_SERIAL_RX | Serial mode: reading receives a byte; read it only when bit 1 of port 0x05 says there is one. |
0x05 | GG_SERIAL_STATUS | Bit 0: 1 if the send buffer is occupied. Bit 1: 1 if the receive buffer is occupied. Bit 2: 1 if the connected console is not powered on or there was an error. Bit 3: 1 enables the NMI when new data arrives. Bits 4–5: must be 1 to enable Gear-to-Gear operation. Bits 6–7: speed, 00 = 4800 bps, 01 = 2400, 10 = 1200, 11 = 300 (SMS Power, Gear to Gear Cable). |
0x06 | GG_STEREO | Stereo control for the PSG, write only. Bits 0–3 send channels 1 to 4 to the right side and bits 4–7 channels 1 to 4 to the left side; a bit set means the channel is sent to that side, so 0xFF sends all channels to both sides and 0xF0 to the left side only (SMS Power, Game Gear Stereo). It affects only the headphones, not the built-in speaker, so it cannot be used to mute the sound. Charles MacDonald’s text labels the same bits “1 = disabled” but also says 0xFF enables everything; the two cannot both hold, and this page follows SMS Power. |
The Gear-to-Gear cable has two modes, parallel and serial, both only in Game Gear mode. In serial mode the NMI is raised when a byte arrives or the
other console is switched off; the line is a 5 V UART with 8 data bits, least significant bit first, no parity and one stop bit
(SMS Power, Gear to Gear Cable). MacDonald’s text gives the power-on state of ports 0x00–0x06 as
C0 7F FF 00 FF 00 FF. In JSSMS reads of port 0x00 give the Start button and a region bit, ports
0x01–0x05 read 0 and writes to ports below 7 do nothing; that is an emulator’s shortcut, not documentation. Port 0x00’s
lower bits and port 0x01 are not described in any source read.
SG-1000
SMS Power’s SG-1000 table: 0x40–0x7F the sound chip (write); 0x80–0xBF the VDP data port
(even) and control or status (odd); 0xC0–0xDF joypad 1 (even) and joypad 2 (odd), read; 0xF0 onwards also
joypad 1 and 2. Nothing is connected below 0x40. SMS Power says it is still missing most port information for the SC-3000, which
is not described here.
VDP registers
The video chip is written through the control port (0xBF) in two bytes: first the value, then a byte whose top two bits say what to
do and whose low bits are the register number: 0x80 + register writes a register (JSSMS’s vdp.js decodes the second byte’s top two
bits as 0 read address, 1 write address, 2 register, 3 colour address). The registers below are those of mode 4, the mode the Master System and Game
Gear use; registers 0x0B and up have no effect.
| Register | Name | Bits |
|---|---|---|
| 0 | Mode control 1 | Bit 7 lock the rightmost eight columns at vertical scroll 0; 6 lock the top two rows (16 pixels) at horizontal scroll 0; 5 hide the leftmost 8 pixels; 4 line interrupts; 3 shift sprites left 8 pixels; 2 mode 4; 1 extra height / mode select; 0 sync disable (always 0). |
| 1 | Mode control 2 | Bit 7 always 1; 6 display enable; 5 frame interrupts; 4 and 3 the 224-line and 240-line modes; 2 always 0; 1 tall (8×16) sprites; 0 doubled sprites. |
| 2 | Name table base | Bits 1–3 set the base of the background tile map (all set: 0x3800 in 192-line mode, 0x3700 in the 224- and 240-line modes). Bit 0 is a mask bit on the original VDP. |
| 3 | Colour table base | Supplies high address bits for tile pattern fetches. Mode 4 software sets all bits on the original VDP, where they act as masks for bitplanes 0 and 1. |
| 4 | Pattern generator base | As register 3; the low three bits should be set and act as masks for bitplanes 2 and 3. |
| 5 | Sprite attribute table base | Sets the table base; all bits set gives 0x3F00. Bit 0 is a mask bit that should be 1. |
| 6 | Sprite pattern generator base | Bit 2 chooses 0x0000 (0) or 0x2000 (1) for sprite patterns. Bits 1–0 are mask bits. Bits 7–3 unused. |
| 7 | Overscan / backdrop colour | A colour 0–15 from the sprite palette; the top four bits do nothing. |
| 8 | Background X scroll | All 8 bits. |
| 9 | Background Y scroll | All 8 bits. |
| 10 | Line counter | The value for the line interrupt. |
Sources
- I/O Port Map – SMS, Game Gear and SG-1000 and SC-3000 – SMS Power
- Start Button, Gear to Gear Cable and Game Gear Stereo – SMS Power: Game Gear ports
0x00–0x06 - VDP Registers – SMS Power
- Sega Master System / Game Gear Technical Information – Charles MacDonald (a copy on nakardo.github.io): the bits of ports
0x3E,0x3F,0xDC,0xDDand0x06, and the FM ports
Not described
The VDP’s other modes (the original TMS9918 modes), the VDP’s memory, the colour and sprite formats, the status register, the PSG’s registers,
bits 0–6 of Game Gear port 0x00 and the bits of port 0x01, the SC-3000 ports and the light phaser and 3-D glasses.