# Start here: the Sega 32X as a board A primer for the session that builds the board. It says what the machine is, where each fact comes from, and which facts are soft. Numbers with no source are not to be trusted; the sources are pinned in [validation.md](validation.md) and fetched into `reference/` by `scripts/fetch_references.py`. Short names used below: - **Manual**: Sega's *32X Hardware Manual*, Doc. #MAR-32-R4-072294 (Sega of America, 1994; "Provisional Version 3", June 1 1994, 84 pages), the scan `reference/manuals/32X_Hardware_Manual_1994_Sega.pdf` (no text layer; PDF page numbers). `reference/src/32XDK/docs/32x-hardware-manual.md` is a markdown transcription of the same document (its history block matches page 2): grep that, cite the scan. Specification tier, and **provisional**: written before the hardware shipped. - **Supplement 1 / 2**: the manual's two supplements (1994), also scans. Supplement 2 carries the unified interrupt handler (Technical Bulletin #27). - **Bulletins**: Sega's 32X Technical Bulletins #9, #10, #14, #27, as PDFs in `reference/src/32XDK/bulletins/`. - **Service manual**: *Sega Service Manual Genesis 32X / Mega Drive 32X* No. 012 (June 1995), page scans in `reference/manuals/Sega_Service_Manual_...cbr` (a RAR of JPEGs: `unrar e`). Its block diagram (pp. 7-8, scan `A406a`) and main schematic (pp. 13-14, `A408a`) are the only primary source for **which signals cross the cartridge slot**. - **SDK**: Sega DTS's 32X SDK, `reference/sdk/32xSDK.zip`: `32X/DIAGNSTC/` is Sega's 32X hardware diagnostic (source and S-records), `32X/SAMPLES/` the samples. - **testpico**: notaz's self-checking test program (`reference/src/megadrive-notaz/testpico`), 14 32X tests run on his hardware ([validation.md](validation.md)). - **32XDK wiki**: `reference/src/32XDK.wiki/`, developer notes (Chilly Willy, viciious and others); research tier. - **ares** (ISC) and **MAME**'s `mega32x.cpp` (BSD-3): emulators whose source may be read, with notice; emulator-derived. - **PicoDrive** (non-commercial), **jgenesis**, **BlastEm** (GPL-3.0), the **MiSTer** core (GPL): closed boxes only (the family's `sources.md`). They may be built and run as detectors; their source is never opened. Results from running them are marked OBSERVED. (Scrub of 2026-11-19: statements that came from reading their source were struck from this page.) ## The machine in one paragraph The 32X plugs into the Mega Drive's cartridge slot; the game cartridge plugs into the top of the 32X (Manual 1.1). Inside: two SH-2s (SH7095, an SH7604 core; Sega part numbers 315-0922, 315-0922A, 315-0998 = Hitachi HD6417095F23/F28, service manual parts table, `A408a`), 256 KB of SDRAM (2 Mbit) shared by both, two 128 KB frame buffers (1 Mbit DRAM each, one displayed while the other is drawn), a 256-entry palette, a VDP with no sprites or tiles (three bitmap formats), and a 2-channel PWM. Two Sega gate arrays do the work: **315-5818** (IC4, 176 pins: the Mega Drive interface, the system registers, the FIFO, the communication ports, PWM, the SH-2 bus) and **315-5781** (IC6, 144 pins: the VDP, its registers, the palette and RAMDAC) (service manual `A406a`, `A408a`). The 68000 controls everything except the SH-2s and the SDRAM; the SH-2s cannot see the Mega Drive at all (Manual 2.2: "MEGA Drive hardware cannot map in SH2 address space") and talk to the 68000 only through the communication ports, the CMD interrupt and the DREQ FIFO. Nothing in the 32X interrupts the 68000 (Manual 3.3: "There are no interrupts from SH2 to 68000"). ## Clocks | Clock | Value | Source | | --- | --- | --- | | MCLK | NTSC 53.693175 MHz, PAL 53.203424 MHz | Manual 3.3, "Clock Used by the 32X" | | 68000 (VCLK) | MCLK / 7 | same | | SH-2 (Sclk) | VCLK x 3 = MCLK x 3/7 (NTSC 23.0114 MHz) | same; service manual block diagram: a PLL takes VCLK from the slot and makes 23 and 46 MHz; "CPU clock runs only when the software selectable MARS bit is set" | | 32X pixel | the Mega Drive's EDCLK (MCLK/8 in H40) | the VDP (IC6) takes EDCLK, HSYNC, VSYNC and YS from the slot (`A408a`, pins 64-69) | The SH-2 clock is phase-locked to the 68000's, so the whole 32X lives in the Mega Drive's MCLK domain: 7 MCLK = 3 SH-2 clocks exactly. A scheduler can count MCLK and step each SH-2 by `mclk * 3 // 7` with a remainder, as `expansion-sockets.md` socket 4 says. The PWM's "Scyc" is the SH-2 clock (Manual 3.2.1, Cycle Register). ## 68000 memory map Two states (Manual 3.1, table "When Power is On (ADEN = 0)" / "When Using Super 32X (ADEN = 1)"; 3.5): **ADEN = 0** (power on): "address space of 68000 is mapped the same as the MEGA Drive unit" (Manual 3.5): the cartridge at `$000000`, so a plain Mega Drive game runs through a 32X untouched. `$A130EC` reads `"MARS"` (the 32X ID; testpico reads it to detect a 32X, `main.c` line 2583) and `$A15100` is there so the initial program can set ADEN. ares (`bus-external.cpp`) agrees. The transcription's ADEN = 0 table, which lists the vector ROM at `$000000`, is garbled; check the scan. **ADEN = 1** (after the cartridge's Sega-supplied initial program, `ICD_MARS.PRG` at `$3F0`, sets it): | 68000 address | Contents | Notes | | --- | --- | --- | | `$000000-$0000FF` | the 32X's vector ROM | the level-4 (HINT) vector at `$70` is a writable register (ares `bus-external.cpp`; testpico `t_32x_md_rom` writes and reads it back); testpico: it reads 0 after reset (`main.c` line 2099) | | `$000100-$3FFFFF` | the cartridge **only when RV = 1** | Manual 3.1 "ROM Access When Using the 32X"; with RV = 0 the cartridge is not there (what reads instead: open item) | | `$400000-$7FFFFF` | Mega Drive (expansion) | unchanged | | `$840000-$85FFFF` | frame buffer (the one not displayed) | FM = 0 required; byte writes of `$00` ignored | | `$860000-$87FFFF` | overwrite image of the same DRAM | `$00` bytes ignored for byte and word writes | | `$880000-$8FFFFF` | cartridge `$000000-$07FFFF`, fixed | RV = 0 only | | `$900000-$9FFFFF` | cartridge, one of four 1 MB banks | bank register `$A15104` (BK1:BK0) | | `$A130EC` | `"MARS"` | in the `/TIME` range | | `$A15100-$A1513F` | system registers, communication ports, PWM | below | | `$A15180-$A1518B` | 32X VDP registers | FM = 0 required | | `$A15200-$A153FF` | palette, 256 words | FM = 0; word access only | The 68000 reaches the 32X through ranges where the Mega Drive itself never asserts DTACK (`$84xxxx-$9FFFFF`, `$A15xxx`), so the 32X can hold the 68000 off with its own DTACK when the SH-2s have the bus (32XDK wiki, Bank-switching). Cartridge writes (mapper, save RAM) do not get that protection: games set RV = 1 around them, and the SH-2s stall on cartridge access while RV = 1 (Manual 3.1, 3.2.1 DREQ Control). The Z80's bank window can reach the 32X registers marked "V" in the Manual's access table (3.4), but Sega forbids banking it onto `$000000-$3FFFFF` or `$840000-$9FFFFF` (32X Technical Note 22, quoted in the 32XDK wiki), and an older note says Z80 writes to `$840000-$9FFFFF` and `$A15100-$A153FF` lock the 68000 ("supposedly fixed"). ## SH-2 memory map The same for both SH-2s (Manual 3.1 "SH2 Memory Map"). Cache-through addresses are the cached ones plus `$20000000`. | Cached | Through | Contents | | --- | --- | --- | | `$00000000` | `$20000000` | boot ROM (master 2 KB, slave 1 KB: one per CPU) | | `$00004000` | `$20004000` | system registers | | `$00004100` | `$20004100` | VDP registers | | `$00004200` | `$20004200` | palette | | `$02000000-$023FFFFF` | `$22000000` | cartridge (4 MB), only while RV = 0 | | `$04000000-$0401FFFF` | `$24000000` | frame buffer (FM = 1) | | `$04020000-$0403FFFF` | `$24020000` | overwrite image | | `$06000000-$0603FFFF` | `$26000000` | SDRAM | The 32XDK wiki records an undocumented mirror of the frame buffer at `$24040000` (used by the prototype Soulstar X; ares issue 744). The on-die region (`$FFFFFE00-$FFFFFFFF`, the SH7604 peripherals) and the cache address array belong to sh2-python. ## System registers 68000 side at `$A151xx`, SH-2 side at `$200040xx`; most are shared, some exist per CPU (Manual 3.2.1, 3.2.2): | 68000 | SH-2 | Register | Notes | | --- | --- | --- | --- | | `$A15100` | `$20004000` | adapter control / interrupt mask | 68000: FM, REN, RES, ADEN. SH-2: FM, ADEN, CART (cartridge absent), HEN, and V, H, CMD, PWM masks **per SH-2** at one address | | `$A15102` | `$20004002` | interrupt control (INTS, INTM) / standby changer | the 68000 raises CMD on either SH-2 | | `$A15104` | `$20004004` | bank set (BK1:0) / H count | | | `$A15106` | `$20004006` | DREQ control: FULL, 68S, RV | RV is read-only from the SH-2s; the SH-2 view adds frame-buffer FIFO FULL/EMPTY | | `$A15108-$A1510E` | `$20004008-E` | DREQ source / destination | unused by the circuit (Manual) | | `$A15110` | `$20004010` | DREQ length (words, multiple of 4) | | | `$A15112` | `$20004012` | FIFO | 68000 writes, SH-2 DMA channel 0 reads (DREQ0) | | `$A1511A` | `$2000401A` | SEGA TV (CM) / CMD interrupt clear | testpico: only bits 0 and 8 writable (`t_32x_init` writes `$FFFF`, expects `$0101`, `main.c` line 1999) | | - | `$20004014-1C` | VRES, V, H, CMD, PWM interrupt clears | | | `$A15120-$A1512F` | `$20004020-2F` | communication ports, 8 words | simultaneous writes undefined | | `$A15130-$A15138` | `$20004030-38` | PWM control, cycle, L, R, mono | | SH-2 interrupt levels (Manual 3.2.2): VRES 14, VINT 12, HINT 10, CMD 8, PWM 6, on the SH-2's /IRL lines as auto-vectors. On the board the SH-2s' FRT output A is wired to /IRL0's least significant bit, which is why Sega's handlers toggle the FRT (32XDK wiki "FRT Bumping", from the schematic; Bulletin #27; Supplement 2). That wire is a **board** fact that the core must let the board express: the board ORs FTOA into the IRL level it presents. ## The 32X VDP (315-5781) From the Manual (3.2.3, 3.3) unless noted: - **Display**: 320 x 224, or 320 x 240 on PAL; non-interlaced only. The Mega Drive must be in H40 and the matching V28/V30 whenever the 32X is not in blank mode (Manual "Display Mode Possible Combinations"). Games break that rule (NFL Quarterback Club turns on H32 in its menus, seen on the board and both detectors run here, [validation.md](validation.md), "Milestone 4"). - **Modes** (`$A15180` / `$20004100` bits M1:M0): blank, packed pixel (8-bit palette index, two per word), direct colour (16-bit: priority bit 15, BGR555), run length (one word = an 8-bit run length and an 8-bit palette index, 1-256 pixels; the Manual does not say which byte is which; ares (`m32x/vdp.cpp`, `scanlineMode3`) puts the length in the high byte, and the Mars Check Program's and Sega's run-length sample's pictures agree with it on the board). PRI swaps the priority sense, 240 selects 240 lines (PAL only), PAL is read-only (0 = PAL). The Manual's scan (PDF page 36) puts PRI at bit 7 and 240 at bit 6; the 32XDK transcription's bit table is the garbled one. - **Line table**: the first 256 words of the displayed frame buffer are word offsets of each line's pixels. A line starts wherever its entry points; the VDP reads 320 pixels' worth from there, running into the overwrite image if it must. - **Screen shift** (`$A15182`): one-pixel left shift for packed mode; ignored on a line whose table entry's low byte is `$FF` (Bulletin #14). - **Frame buffer control** (`$A1518A`): VBLK, HBLK, PEN (palette access allowed), FEN (frame buffer busy: fill or refresh), FS (which buffer is displayed). Writing FS during display swaps at the next VBlank; reads return the displayed buffer until then. - **Auto fill** (`$A15184-$A15188`): length-1 (0-255), start address (A16-A9 fixed, A8-A1 incrementing, so a fill wraps within a 256-word page), data; writing the data starts it; it takes 7 + 3 x length cycles. - **Palette**: 256 words, BGR555 + through bit; access only in blanking or in direct colour mode (PEN), otherwise the CPU waits up to a line. - **Priority** (Manual 3.3 "Priority"): the 32X pixel is in front of or behind the Mega Drive's planes and sprites, by PRI and each pixel's through bit; "when the MD color code is 0, and when the 32X designates blank ... each becomes transparent". The hardware does it with the Mega Drive VDP's **YS** signal (the "no plane or sprite pixel here" output), which crosses the cartridge slot to the 32X VDP (`-MYS`, `A408a`); the 32X produces its own `YSO` and an analog video mixer (IC12) "switches between input via YS signal to produce one output" (`A406a`). The composite is an **analog switch** between the Mega Drive's finished RGB and the 32X's RAMDAC output, pixel by pixel, not a blend. ## PWM Two 12-bit pulse-width channels, each with a 3-entry FIFO, a cycle register setting the period in SH-2 clocks, a timer interrupt every TM periods (TM = 0 means 16) that also paces DREQ1 for SH-2 DMA channel 1 (Manual 3.2.1, 3.4; "DMA Controller Settings"). The routing bits per channel select off, L, or R. ares (`pwm.cpp`) uses a period of `cycle - 1` clocks; run here, PicoDrive's tones fit `cycle - 1` and BlastEm's `cycle - 2` (OBSERVED, [validation.md](validation.md), "Milestone 5"); the Manual says `cycle x Scyc` (contested, [undocumented-behavior.md](undocumented-behavior.md)). The PWM reaches the speaker through the 32X's sound mixer IC11 and the slot's audio lines (`SL1`/`SR1` in the block diagram); the Mega Drive's own sound reaches the 32X by the A/V cable (CN6) and leaves through the 32X's output (CN7). The board's PWM is `src/sega32x_python/pwm.py` (milestone 5), socket 8's source at the period's own rate. ## Boot ROMs Three: 68000 (256 bytes: the vector table at `$000000`), master SH-2 (2 KB) and slave SH-2 (1 KB). **Bring-your-own; never fetched or committed.** SHA-1s, for checking what a user supplies (No-Intro "[BIOS] 32X ... (USA)", identical to MAME's `32x_g_bios.bin`, `32x_m_bios.bin`, `32x_s_bios.bin`): | ROM | Size | SHA-1 | | --- | --- | --- | | 68000 | 256 | `dbebd76a448447cb6e524ac3cb0fd19fc065d944` | | master SH-2 | 2,048 | `1e5b0b2441a4979b6966d942b20cc76c413b8c5e` | | slave SH-2 | 1,024 | `4103668c1bbd66c5e24558e73d4f3f92061a109a` | MAME also lists an SDK master ROM, `32x_m_bios_sdk.bin`, as a bad dump. What they do (Manual 5.1, 5.2): the master initialises registers, the bus state controller and SDRAM, sleeps until the 68000's initial program wakes the 32X, tests and clears SDRAM ("SDER" on failure), checks for a cartridge, checks the security code (the initial program at `$3F0` must be Sega's, byte for byte: "SQER" on failure), writes the checksum to comm8, loads the initial data named by the user header at `$3C0-$3EF` (source, destination, size, start addresses, vector bases) from cartridge to SDRAM, writes `"M_OK"` to comm0 and jumps. The slave waits for `"M_OK"` (or `"CD_*"` for a CD boot) and writes `"S_OK"` to comm4. With no cartridge the master boots from the CD path. **A free replacement** is practical, because the boot ROMs' job is small and fully described by the Manual. Three precedents, none to be copied: 1. **PicoDrive's built-in start**: run with no BIOS, PicoDrive starts 32X programs by itself (OBSERVED; how it does so is not read here). testpico ran on it here: 54/57 ([validation.md](validation.md)). 2. **Devster's "Poorman's 32X BIOS"** (Joseph Norman, 2005; `reference/free-bios/poormans_sega_32x_bios.zip`, SNASM source included): three replacement ROMs; the master omits the SDRAM and security checks (its `about.txt`; the source is non-commercial and not read). Freeware, non-commercial, no bundling without consent, so it cannot ship with this repository. fedex81 published a one-word fix for CD 32X boots (VBR from `$24000028`). 3. **Write our own** from the Manual's flow charts, in SH-2 and 68000 assembly built with the pinned marsdev toolchain, MIT, in this repository. The board would then run with no user files at all; the user's Sega ROMs, when given, replace it. This is an open decision; the boot ROMs' timing (how long the master takes before `M_OK`) is visible to games that poll, so the replacement is a convenience and the real ROMs stay the judge. ## The Sega CD 32X (later) Six FMV titles use both add-ons; all six are in a local copy of Redump's Sega CD set with "(Sega CD 32X)" / "(Mega-CD 32X)" / "(32X CD)" in their names: Corpse Killer, Fahrenheit (disc 2), Night Trap, Slam City with Scottie Pippen, Supreme Warrior, Surgical Strike (Brazil). With no cartridge in the 32X, the master boot ROM takes the `"CD_*"` path and the Sega CD supplies the program (Manual 5.1 flow chart; fedex81's README: Devster's master gets the VBR wrong on that path). Sega warns that Word-RAM-to-VRAM DMA has a fetch-timing problem when the CD is used (32XDK wiki). On the board this is one device in each socket of `expansion-sockets.md`: the 32X in the slot, the CD in the expansion port. It is the last milestone ([handoff-brief.md](handoff-brief.md)). ## Where the cores fit - **megadrive-python** (pinned by revision once its sockets PR lands): the 68000, the Z80, the Mega Drive VDP, FM, PSG, I/O, and the sockets. - **sh2-python** (pinned by revision): two instances, master and slave; on-die peripherals inside the core. What this board needs from it is in [handoff-brief.md](handoff-brief.md), "What the board needs from sh2-python". - This repository: everything in the 315-5818 and 315-5781, the SDRAM, the frame buffers, the boot ROM mapping, the composite, PWM, and the board's wiring (FTOA into /IRL, the two SH-2s' serial lines, DREQ0/DREQ1).