# sega32x-rust-fast > **Lineage:** sega32x-python → sega32x-rust → **sega32x-rust-fast** · > fixes start in sega32x-python and flow down by merges · > [family charter](https://github.com/alewman/emulator-lineage/blob/main/docs/charter.md) The ladder-gated speed fork of [sega32x-rust](../sega32x-rust), as megadrive-rust-fast is of megadrive-rust. Tier `x-rust-fast` of the charter: **every bus cycle the same board as upstream.** A change is kept only when the ladder (`scripts/ladder.sh`) passes and it wins on every code layout (`scripts/ab.sh`); what did not pay is in [docs/not-kept.md](docs/not-kept.md). "Matches sega32x-rust" is the only claim here; sega32x-rust's is "matches the Python", and how the Python stands against a 32X is sega32x-python's docs/claims.md. No 32X hardware is at hand. Forked 2026-11-26 from sega32x-rust `5b1bd11` (remote `upstream`, the local checkout; local only, no remote of its own). Status, every rung's count and every step's ratios: [docs/status.md](docs/status.md). | Part | What | Pin | | --- | --- | --- | | The board's reference | sega32x-python | `0553957` (src tree `d532709`), through sega32x-rust's cached traces | | Upstream | sega32x-rust | `5b1bd11`, built in `external/base` against its own pins (below) | | Mega Drive board | megadrive-rust-fast, branch `sockets-32x` | `8f5cf5f`: its `sockets` `9995ffb` (= megadrive-rust `d39b9bf`) + megadrive-rust's `sockets-32x` `ef621e6` (the five hooks) | | SH-2 | sh2-rust-fast, branch `board-context` | `43ab381`: its main `49a009d` + sh2-rust's `board-context` `c5634ef` (`BusContext`'s waits) | | Their cores | megadrive-rust-fast's own | m68000-rust-fast, z80-rust-fast (git), ym2612-rust `a3ae306`, sn76489-rust `ac95bea`, ssp1601-rust `7249814` (paths, upstream's pins) | The dependencies are in `external/` (git-ignored), made by [`scripts/external.sh`](scripts/external.sh): the two -fast branches as worktrees of the clones beside this repository (their checkouts are never switched: play-md builds from `../megadrive-rust-fast`), upstream's trees as private clones, and `external/base`, this repository at the fork point. None of the branches is merged or pushed (Aubrey's call). ## Running ```sh scripts/external.sh # the dependency trees, at their revisions cargo build --release target/release/s32x-bench GAME.32x --bios-dir "$SEGA32X_BIOS_DIR" --frames 900 [--no-fm] [--press start@500:504] target/release/s32x-run GAME.32x --bios-dir "$SEGA32X_BIOS_DIR" --frames 900 [--no-fm] target/release/s32x-trace GAME.32x --bios-dir "$SEGA32X_BIOS_DIR" --frames 600 [upstream's options] scripts/bench.sh # the four benchmark cartridges scripts/ab.sh BASE # BASE against the working tree, CPU 28, both layouts ``` The 32X boot ROMs are the user's own (`$SEGA32X_BIOS_DIR`, checked by SHA-1); games come from `$NO_INTRO_DIR`. Neither is ever copied into the repository. ## The gate `scripts/ladder.sh` (`FULL=1` runs rung 1 at full length, `PY=1` lets rung 3 run the reference for a case it has no cached trace of, `FAULTS=1` adds rung 5). It runs on CPUS (default 24-27), JOBS (default 4) at a time. | Rung | What | Command | | --- | --- | --- | | 0 | the dependencies at their revisions; the builds; `cargo test` (rung 2, upstream's 6,000 unit calls replayed) | `scripts/external.sh --check`, `cargo test --release` | | 1 | **ADEN = 0**: megadrive-rust's 87 cases, three traces each byte-identical: upstream's board (megadrive-rust `ef621e6`), megadrive-rust-fast `sockets-32x` with nothing attached, and this board's passive 32X. **Cut to 300 frames a case** by default; `FULL=1` for the whole table | `scripts/passive.py [--full]` | | 3 | **whole machine**: upstream's 21 cases against sega32x-python's traces, cached by sega32x-rust's rung 3 and copied with the fork (the reference is not run unless `PY=1`) | `scripts/lockstep.py` | | 3b | **the benchmark's workloads** (900 frames each, the FM on, SH-2 bus CRCs for 60 frames) against sega32x-rust at the fork point | `scripts/lockstep.py --against-base --cases scripts/speed-cases.tsv` | | 4 | **save states**: each rung-3 case through three save states, against the reference's trace | `scripts/state_rung.py` | | 5 | upstream's seeded faults (heavy; not rerun in the fork) | `scripts/seeded_faults.py` | ## Speed On one E-core (CPU 28), load 12-19, 900 frames, best of 3 alternating (docs/status.md): | Cartridge | sega32x-rust | this fork | | | --- | ---: | ---: | ---: | | Knuckles' Chaotix (FM on) | 38.5 fps | 43.6 fps (0.73x real time) | x1.133 | | Knuckles' Chaotix (`--no-fm`) | 38.0 fps | 43.7 fps (0.73x real time) | x1.152 | | Virtua Racing Deluxe (USA) | 39.6 fps | 46.7 fps (0.78x real time) | x1.179 | | Star Wars Arcade (USA) | 33.8 fps | 39.9 fps (0.66x real time) | x1.179 | | Doom (Japan, USA) | 35.7 fps | 42.4 fps (0.71x real time) | x1.186 | The kept steps: the -fast dependencies (x1.08-1.12), the release profile with fat LTO (x1.056), megadrive-rust-fast's pin-2-od2 (x1.006-1.017). Not kept: docs/not-kept.md. ## 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.