# sega32x-rust > **Lineage:** sega32x-python → **sega32x-rust** · > fixes start in sega32x-python and flow down by merges · > [family charter](https://github.com/alewman/emulator-lineage/blob/main/docs/charter.md) A Rust **Sega 32X** board, transcribed module for module from [sega32x-python](../sega32x-python) and held in lockstep with it: a cartridge-slot device for [megadrive-rust](../megadrive-rust)'s expansion sockets, with two SH-2s from [sh2-rust](../sh2-rust). Tier `x-rust` of the charter: **"matches the Python" is the only claim here.** How well the Python matches a 32X (testpico, the Mars Check Program, the detectors, the documents) is the reference's [docs/claims.md](../sega32x-python/docs/claims.md); no 32X hardware is at hand and nothing here is measured on one. Status (2026-11-25, every rung with its command, count and commit in [docs/status.md](docs/status.md)): the transcription is whole -- the 68000's side, the SH-2 side and its bus, the 32X VDP, PWM, the composite, the models and quirks, save states -- and every rung of [`scripts/ladder.sh`](scripts/ladder.sh) passes on what exists: rung 1 87 of 87 (81 through a passive 32X), rung 2 6,000 of 6,000 unit calls, rung 3 21 of 21 whole-machine cases (16,360 frames), rung 4 21 of 21 through save states, rung 5 31 of 34 counted faults caught (2 equivalent, 3 blind spots named in docs/status.md). | Part | Reference | Pin | | --- | --- | --- | | The board's reference | sega32x-python | `0553957` (its main, local, unpushed: the sh2-python 8824075 repin, the /TIME fix, decision B6; src tree `d532709`) | | Mega Drive board | megadrive-rust, branch `sockets-32x` | `ef621e6`: `sockets` `0959147` (= megadrive-python `efd80fc`, the reference's pin) + this board's five hooks (below) | | SH-2 | sh2-rust, branch `board-context` | `c5634ef`: `fcb9dae` (= sh2-python `8824075`, the reference's pin) + `BusContext`'s BSC waits (below) | The dependencies are worktrees in `external/` (git-ignored), made by [`scripts/external.sh`](scripts/external.sh) from the clones beside this repository; none of the branches above is merged or pushed (Aubrey's call). ## Running ```sh scripts/external.sh # the dependency worktrees, at their revisions cargo build --release # frames per second (no trace) target/release/s32x-run GAME.32x --bios-dir "$SEGA32X_BIOS_DIR" --frames 900 [--no-fm] # the lockstep trace (scripts/s32x_trace.py writes the reference's) target/release/s32x-trace GAME.32x --bios-dir "$SEGA32X_BIOS_DIR" --frames 600 \ [--press start@300:304] [--reset-at N] [--no-fm] [--bus-frames N] [--save-at F[+STEPS]] [--out FILE] ``` The 32X boot ROMs are the user's own, found through `$SEGA32X_BIOS_DIR` and checked by SHA-1 (`src/bootrom.rs`); games come from `$NO_INTRO_DIR`. Neither is ever copied into the repository. ## The gate `scripts/ladder.sh` (`FAULTS=1` adds the seeded faults): | Rung | What | Command | | --- | --- | --- | | 0 | the dependencies at their revisions; build; `cargo test` | `scripts/external.sh --check`, `cargo test --release` | | 1 | **ADEN = 0**: every case of megadrive-rust's own lockstep table, three traces each byte-identical: `md-trace` at `0959147`, `md-trace` on `sockets-32x` with nothing attached, and `s32x-mdtrace`, the same case with a passive 32X holding the cartridge | `scripts/passive.py` | | 2 | **unit level**: 6,000 seeded calls straight into the device on the reference, replayed here -- the 68000's and Z80's accesses to every 32X range, the SH-2 side's bus cycles on every region (arbitration, WAIT, the frame-buffer FIFO, the cartridge against the 68000, SDRAM, the registers), line records, socket 7's lines, socket 8's samples, catch-ups that step both SH-2s through our own boot programs; each answer and a CRC of the device's whole state after it | `tests/units.rs`, vectors from `scripts/make_unit_vectors.py` | | 3 | **whole machine**: per frame the Mega Drive's whole trace (megadrive-rust's: both CPUs, every memory, the VDP, the picture, the sound), the final mix with the PWM, the 32X's registers, VDP (line records, events, palette, the picture), PWM, composite, SH-2 side, both chips' complete state, and for the first frames a CRC of every SH-2 bus cycle (address, width, value, kind, direction, start state) per chip | `scripts/lockstep.py` (`scripts/cases.tsv`) | | 4 | **save states**: every rung-3 case saved three times (a frame's start, 1,777 and 3 steps into a frame), loaded into a fresh machine, and its trace identical to the reference's uninterrupted run | `scripts/state_rung.py` | | 5 | **seeded one-line faults**, each caught by rungs 1-4 | `scripts/seeded_faults.py` | The reference runs at about 2.4 frames a second, so its traces are cached under `external/reference-cache/`, keyed by its source tree (`git rev-parse HEAD:src`), the pins its interpreter has installed and the trace scripts' digest; a Rust change reruns only the Rust side. Python runs at most `--jobs` at a time under `nice` with `PYPY_GC_NURSERY=1M`. ## Speed A first number only: this tier is not optimised (that is a `-fast` fork's job). `s32x-run --frames 900`, one core of the shared i9-13900K at load 15-20, 2026-11-25: | Cartridge | FM on | `--no-fm` | | --- | ---: | ---: | | Knuckles' Chaotix | 49.6 fps (0.83x real time) | 33.7 fps | | Virtua Racing Deluxe | 48.8 fps (0.81x) | 47.7 fps | | Star Wars Arcade | 45.1 fps (0.75x) | 40.4 fps | | Doom | 30.7 fps (0.51x) | 31.6 fps | The reference runs these at about 2.4 frames a second on PyPy: about 13-20 times faster, and still short of real time. ## What Rust forced Everything else is the reference's names, order, comments and evidence tags. - **The device is shared.** The reference hands one `Sega32X` to four sockets (slot, video timing, picture, sound); here four small socket objects share it (`Arc>`, `src/console.rs`), each locking it for its call. - **The board is lent, not kept.** megadrive-rust lends a device the board for each call (`&mut Devices`); every method that needs it takes it. The board owns the held cartridge (`Devices::cartridge`, the reference's `game_cartridge`). - **The Mega Drive's VDP is brought up by the board.** The reference's `video_lines_to` runs `board.vdp.sync(mclk)` from inside the device's own access or catch-up. A device here cannot reach the VDP, so megadrive-rust asks first (`Clocked::video_first`, added on `sockets-32x`): the device does what precedes the sync in the reference's call (the clock taken, ADEN looked at) and says whether to sync; the board syncs; the call finishes the catch-up. Not asked on a DMA read, where the reference's sync does nothing (the VDP is the caller, already at the clock). - **The SH-2s' callbacks.** The reference's bus callbacks are closures over the side and the device. Here each chip owns a `Port` (sh2-rust's `Bus`) that reaches the device and the board through pointers set for the length of a call into the chip, and the chip is taken out of the side while it runs, so its clock, wait, BSC lists and pins are the callback's `BusContext` (`sh2side::Own`) and the other chip is in place. The side's methods that go through the device are device methods (`sh2_*`), in `sh2side.rs`. sh2-rust's `BusContext` gained the BSC's `waits` and `wait_pin` (read only; branch `board-context`), which the reference reads inside its callbacks to decide the WAIT it drives. - **The VDP's and the PWM's device.** What they reach of the device (HEN, the H count, the SH-2 side, the composite, the frame buffers; ADEN) is lent to each call as a `Links`. - **Exceptions** (`Lockup`, `ResetLanding`, `BootROMError`) are a `Result`'s `Stop`; at the socket a lock-up is the board's (`Devices::lock_up`). - **Claims** changed inside a call (ADEN, RV) are read again as the call returns (the board defers a device's own update to then in any case). - **The Acclaim EEPROM cartridge** (a `Cartridge` subclass in the reference) is megadrive-rust's `Cartridge::sda_line` flag (added on `sockets-32x`); `peek_byte` is lent the board too (the 32X peeks the cartridge's windows). - **The quirk records** (`src/machine.rs`) are generated from the reference's `machine.py` by `scripts/gen_machine.py`, every field word for word; a dict value is a struct with the same keys. - **Save states** are written field by field (the reference pickles the graph), with megadrive-rust's own state for the Mega Drive and the renderer's rows the composite fills (`Renderer::picture_side`, added on `sockets-32x`), shared rows kept shared. The formats are not shared with the reference's; rung 4 is the cross-tier proof. - **Not transcribed:** the debugger hook `on_step`; `runner.py`, `__main__.py`, `harness.py` (tools: `s32x-run`, `s32x-trace` and `s32x-mdtrace` stand in for them). ## Licence MIT (see `LICENSE` and `NOTICE`). PicoDrive's and BlastEm's source were never opened; nothing by furrtek is used.