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.
On the Mark III only the main ports (0x3E, 0x3F, 0x7E, 0x7F, 0xBE, 0xBF) are decoded, according to SMS Power’s table.
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 |
0x01 | GG_SERIAL | Serial port |
0x02 | GG_SERIAL_DIR | Serial direction |
0x03 | GG_SERIAL_TX | Serial transmit |
0x04 | GG_SERIAL_RX | Serial receive |
0x05 | GG_SERIAL_STATUS | Serial status |
0x06 | GG_STEREO | Stereo control for the PSG: bits 7–4 switch channels 4 to 1 off for the left speaker, bits 3–0 for the right; of each speaker. 0xFF turns every channel on for both speakers and 0x00 mutes them all. The polarity of a single bit is not stated here: the text read for this page said both “1 disables” and “0xFF enables all”, which cannot both be true. |
The bits of ports 0x00–0x05 are not in the sources read here, so they are named but not described. 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.
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
- 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,
the Game Gear’s ports 0x00–0x05 bit by bit, the SC-3000 ports and the light phaser and 3-D glasses.