# supergrafx-rust A Rust NEC SuperGrafx transcribed from [supergrafx-python](https://github.com/alewman/supergrafx-python) at `v0.1.0` and proven equivalent to it: every CPU bus cycle (physical address, value, kind, master clock), every frame's mixed picture at the 9-bit palette value, every mixed audio sample and the CPU's state, frame by frame, on the five library cards, on Daimakaimura into its first stage and on a probe card that drives every VPC register through the frame. supergrafx-python is the specification (readable, cited, judged against Mesen2 and Beetle PCE); this crate adds nothing to the machine and tunes nothing. It is an **add-on to [pcengine-rust](../pcengine-rust)**, as the reference is an add-on to pcengine-python: the base board runs the HuC6280, the VCE, the PSG and the VDCs; this crate adds what the SuperGrafx has beyond a PC Engine through the base board's socket traits, and copies nothing from it: - `machine::SUPERGRAFX`, the machine row: two VDCs, 32 KiB of work RAM; - `vpc::Vpc`, the HuC6202 video priority controller: its registers, the two windows, the four priority groups and the mix, with every named switch of the reference as a field with the reference's default; - `vpc::VideoPage`, the decode of `$FF:0000-03FF` with the back-panel compatibility switch and the steering of `ST0`-`ST2` by the CPU's opcode; it is the board's `PixelPath`; - `board::SuperGrafx`, the builder. ```text cargo build --release scripts/fetch_reference.sh # the reference at its pins into external/ scripts/rung1.sh # the unit tests scripts/rung2.sh # Covell's CPU test and the probe card in lockstep ``` **`Cargo.toml` depends on pcengine-rust by path (`../pcengine-rust`, which depends on `../huc6280-rust`) while they are local only**: clone the three side by side; the dependencies are repinned to GitHub revisions once pushed. ROMs are bring-your-own, read in place and never committed (`.gitignore` refuses their extensions). Nothing GPL or LGPL was read or transcribed for this crate: the only source transcribed is supergrafx-python, which is ours and MIT. No emulator's source was opened, and no `reference/` directory. ## Certification | What | Version | | --- | --- | | supergrafx-python (the reference) | tag `v0.1.0`, `eee789a63f806723ea936c70293e8a413bee9cab` | | pcengine-python, huc6280-python, 6502-python (what it runs on) | `v0.1.0` (`bc9b976`), `v0.3.0` (`bf20330`), `2146eba` | | pcengine-rust (the base board) | `49e3d48`, by path; it brings huc6280-rust `7f49bf8` | | The SuperGrafx cards | the five `.7z` images of the user's library (SHA-1 of each image in `src/cards.rs`) | | Covell's CPU test | `CPU_Test_10.pce` of pcengine-python's pinned `CPU_Test.zip` | Ladder status at this commit, each rung reproduced with the script named, on Linux x86_64, rustc 1.93.1, the reference on PyPy 7.3.20 (Python 3.11, `PYPY_GC_NURSERY=1M`): | Rung | What | Result | Script | | --- | --- | --- | --- | | 1 | Unit tests: the reference's `tests/test_vpc.py`, `test_board.py`, `test_core_st.py` transcribed (with `test_state.py` and `test_gate.py`, which rungs 5 and 4 run by name) | passed: 52 tests (23 of the VPC, 20 of the board, 2 through the real core, 5 of save states, the gate, the doc example) | `rung1.sh` | | 2 | The gate itself, on Covell's CPU test (60 frames) and the probe card (120 frames) | identical, both | `rung2.sh` | | 3 | The five library cards, 600 frames each with a RUN press; Daimakaimura into its first stage (1,800 frames), the same under `PRIORITY_LABELS = sgxtech`, and in PC Engine position (300 frames); every other named switch away from its default; and which case each switch changes | 17 of 17 identical, 9,660 frames; 8 of 8 switches and switch positions change at least one of their cases | `rung3.sh` | | 4 | The reference's `tests/test_gate.py`: with VDC 2 idle the add-on draws what the one-VDC board draws on Covell's CPU test; and the fallback and PC Engine position in lockstep | the test passes (4 frames, every row, the same master clock); 4 of 4 cases identical (480 frames) | `rung4.sh` | | 5 | Save states: the base board's `save_state`/`load_state` and the snapshot pair over this machine | 8 of 8 cases equal, twice each, and run-ahead equal on all 8; 5 unit tests (a state made here is refused by a plain board) | `rung5.sh` | | 6 | Seeded faults | 30 caught, 0 missed (below) | `rung6.sh` | **The gate** (`scripts/sgx_lockstep.py`) runs each case of `scripts/cases.tsv` on both sides: `scripts/sgx_trace.py` on PyPy builds the reference's `SuperGrafx` and `target/release/sgx-trace` this crate's, and each writes one line a frame, the base gate's line: the frame counter, the master clock, the count and SHA-1 of the CPU bus log (`address << 8 | value`, `mclk << 2 | kind` for every cycle), the SHA-1 of the picture (`capture.last_frame`: the rows the VPC mixed, at the 9-bit value, then the dividers), the count and SHA-1 of the mixed audio and every field of the CPU's state. A case passes when the two files are identical. Otherwise the first differing frame is named and both sides are run again with `--detail` on it, which narrows the difference to the first differing bus cycle. The line, the bus tap, the comparison and the archive handling are the base board's, imported by path from `../pcengine-rust/scripts` (`pce_trace.py`, `lockstep.py`), as the reference's scripts import pcengine-python's; only the building of the machine is this repository's. The reference's traces are kept (`--reference-cache external/refcache`), so a rerun costs the Rust side only. Archives are extracted one at a time into `scratch/` and removed; the library is only read. **In all, 10,260 frames in 22 cases, and no case has ever differed**: the transcription was identical to the reference on the first run of each. (The per-cycle narrowing has therefore only been exercised by the seeded faults.) **Rung 3.** The five cards are 1941 Counter Attack, Aldynes, Battle Ace, Daimakaimura and Madou King Granzort, each 600 frames from power-on with RUN at frame 250. Daimakaimura with `run@400+10 run@700+10` is in its first stage at frame 1,800, where the VPC holds `$75 $56` and the windows `$000` and `$3FF` (`sgx-bench` prints them): identical, and identical again under `PRIORITY_LABELS = sgxtech`, whose picture leaves the default's at frame 155. In PC Engine position (`--mode compat`) it runs 300 frames, identical. **A switch that changes nothing proves nothing** (the base Rust board's rule): `scripts/sgx_switch_effect.py` compares each switch case's reference trace with the same card's trace without the switch and fails if a switch has no case it changes. The library's first seconds do not reach most of the VPC (the reference's docs/m6-record.md: no card moves a window edge into the picture or writes a register mid-line near its checkpoints), so `scripts/sgx_probe.py` builds a synthetic 8 KiB card, this repository's own code, that does: both VDCs with background, sprites and holes, VDC 2's display narrower than VDC 1's; every turn of a free-running loop writes both priority registers from a table of all 256 values and both window widths (window 1 sweeps its 10 bits), so that writes land on every dot of a line; `$08-$0F`, the gap and two mirrors are read back; `ST0`-`ST2` go to VDC 2 with `$0E` set and to VDC 1 with it clear, with plain stores to both in between; VDC 2's VRAM is read back; the dot clock changes every 256 turns. | Switch | Away from its default on | First frame it changes, and what | | --- | --- | --- | | `PRIORITY_LABELS = sgxtech` | Daimakaimura's first stage; the probe | frame 155, the picture; frame 0, the picture | | `WINDOW_ORIGIN = 48, 48, 48` (Mesen2's) | the probe | frame 0, the picture | | `WINDOW_OFF_AT_OR_BELOW` | Daimakaimura's first stage (1023: no window at all); the probe (256) | frame 1,506, the picture; frame 0, the picture | | `ST_STEERS_IN_COMPAT = true` | the probe with the back-panel switch moved after frame 60, `$0E` left set | frame 60, the picture | | the back-panel switch | Daimakaimura and the probe from power-on; the probe, moved after frame 60 | frame 0, the bus log; frame 60, the bus log | | `power_on_seed` (a base board switch, here over two VDCs and 32 KiB) | the probe | frame 4, the bus log | | the fallback (`--mode base`: one VDC, no VPC, 32 KiB) | Daimakaimura, the probe, Covell's test | frame 0, the bus log | `WINDOW_ORIGIN` has no case on a game: Daimakaimura's first stage holds its windows at `$000` and `$3FF` (off, and the whole row), where an origin cannot show; the case was tried, had no effect, and was dropped. **Rung 4.** `tests/gate.rs` is the reference's test: Covell's CPU test on the add-on and on the fallback row (`trace::BASE_MODE`), four frames, every row equal and the same master clock. The lockstep cases add the reference's side: Covell's test on the add-on, on the fallback and in PC Engine position, and Daimakaimura on the fallback (the measured picture of the reference's docs/m6-record.md), each identical to the reference. **Rung 5.** As the reference's `scripts/sgx_state.py`: the five cards saved 148 to 696 instructions into frame 300 with a RUN press before, Daimakaimura in stage 1 (saved inside frame 1,650, pad input after the save) and in PC Engine position, and the probe card with the switch moved before the save. Each state is loaded into a fresh machine and into one that had run, the 60 frames after compared by the gate's own lines, and the loaded machine saved at once gives the same bytes. States are 4 to 71 KiB. Then the snapshot pair (which the reference does not have): after each frame a snapshot, two frames run ahead with other buttons held, the snapshot put back; every frame's line and the end state equal the plain run's. A snapshot is 338 to 394 KiB. `tests/state.rs` has the reference's two tests (the VPC, the page, the switch and the second VDC come back; a plain board refuses the state, with the reference's message, and is left untouched) and the round trip on a synthetic card. ### Seeded faults `scripts/sgx_seeded_faults.py` plants one single-line fault at a time in a copy of `src/`, builds it, and puts it to both cheap checks, so the table says which of them see it: rung 1 (`cargo test`) and the gate on its short cases (Covell's test and the probe card of rung 2, the probe's switch cases of rung 3, the Covell cases of rung 4). Only a fault neither catches goes on to the cards of rung 3 and the round trips of rung 5. | Fault | Module | What it changes | Rung 1 (the test) | The gate (the first case) | | --- | --- | --- | --- | --- | | `window-msb-three-bits` | `vpc.rs` | window 1's MSB register keeps three bits (it reads back $04-$07) | `every_vpc_register_reads_back_through_the_bus` | `probe` | | `steer-register-reads-back` | `vpc.rs` | $0E and $0F read the steering bit, not $00 | `every_vpc_register_reads_back_through_the_bus` | `probe` | | `steer-on-any-bit` | `vpc.rs` | any bit of $0E steers ST0-ST2, not bit 0 alone | `register_0e_steers_st_but_reads_zero_and_0f_is_unused` | not caught | | `window-two-alone-takes-the-overlap-nibble` | `vpc.rs` | the area inside window 2 alone is mixed by the overlap's group | `the_four_areas_take_their_own_nibbles` | `probe` | | `no-window-takes-window-ones-nibble` | `vpc.rs` | the area outside both windows is mixed by window 1's group | `a_register_written_mid_line_takes_effect_at_that_dot` | `probe` | | `window-of-0x40-is-on` | `vpc.rs` | a window of exactly $40 is not disabled (U-SGX2) | `a_window_of_0x40_or_less_is_disabled` | `probe` | | `window-origin-ignores-the-dot-clock` | `vpc.rs` | the window edge at 7.16 MHz uses the 5.37 MHz origin (U-SGX1) | `the_edge_origin_follows_the_dot_clock` | `probe` | | `second-window-msb-not-replayed` | `vpc.rs` | the mix sees one bit of window 2's MSB register | not caught | `probe` | | `rows-swapped` | `vpc.rs` | the two VDCs' pixel buses are swapped | `a_register_written_mid_line_takes_effect_at_that_dot` | `covell` | | `mid-line-write-a-dot-early` | `vpc.rs` | a register written inside a dot takes effect from that dot, not the next (U-SGX3) | `a_write_inside_a_dot_takes_effect_at_the_next` | `probe` | | `both-off-shows-vdc1` | `vpc.rs` | an area with both layers disabled shows VDC 1, not colour 0 | `both_off_shows_colour_zero_in_the_overscan_too` | `probe` | | `transparent-pair-shows-vdc1` | `vpc.rs` | where both pixels are transparent the default order shows VDC 1's, not VDC 2's (U-SGX5) | `two_transparent_pixels_show_vdc2s` | `probe` | | `vdc2-sprites-over-vdc1-sprites` | `vpc.rs` | priority code 01b puts VDC 2's sprites in front of VDC 1's sprites too | `vdc2_sprites_in_front_of_vdc1_background_behind_vdc1_sprites` | not caught | | `code-10-is-the-default-order` | `vpc.rs` | priority code 10b mixes in the default order | `vdc1_sprites_behind_vdc2_background_but_in_front_of_vdc2_sprites` | `probe` | | `priority-labels-not-read` | `vpc.rs` | the PRIORITY_LABELS switch is not wired (C-SGX1) | `sgxtech_labels_swap_the_two_codes_and_nothing_else` | `sw-labels-probe` | | `plain-stores-steered` | `vpc.rs` | with $0E set every write of the area goes to VDC 2, not only ST0-ST2 | `st_goes_to_vdc2_only_while_0e_bit_0_is_set_and_only_for_st_instructions` | `probe` | | `st2-not-steered` | `vpc.rs` | ST2 is not taken for a store-immediate | `st_goes_to_vdc2_only_while_0e_bit_0_is_set_and_only_for_st_instructions` | `probe` | | `compat-still-steers` | `vpc.rs` | ST0-ST2 follow a left-over $0E bit in PC Engine position whatever the switch (U-SGX4) | `st_steering_is_off_with_the_switch_in_compat_position` | `sw-compat-at-probe` | | `steers-in-compat-not-read` | `vpc.rs` | the ST_STEERS_IN_COMPAT switch is not wired (U-SGX4) | `st_steering_is_off_with_the_switch_in_compat_position` | `sw-steers-probe` | | `vdc2-write-mirror-missing` | `vpc.rs` | writes to $14-$17 do not reach VDC 2 | `native_decode_maps_two_vdcs_and_the_vpc_in_a_32_byte_block` | `probe` | | `block-not-repeated-for-writes` | `vpc.rs` | the 32-byte block takes writes only in its first copy | `the_block_repeats_every_32_bytes_through_the_1k_area` | `probe` | | `gap-reads-zero` | `vpc.rs` | $18-$1F read $00 | `the_gap_18_to_1f_reads_ff_and_ignores_writes` | `probe` | | `compat-reads-keep-the-native-decode` | `vpc.rs` | in PC Engine position only $00-$07 of the block read VDC 1 | `compat_reads_are_vdc1s_everywhere` | `sw-compat-at-probe` | | `button-reset-resets-the-vpc` | `vpc.rs` | the VPC is reset by the button and not by power-on | `a_power_on_reset_resets_the_vpc_and_a_button_reset_does_not` | not caught | | `state-forgets-the-switch-position` | `vpc.rs` | a state is saved with the back-panel switch in SuperGrafx position | `the_vpc_the_page_and_the_second_vdc_come_back` | not caught | | `state-forgets-the-pending-writes` | `vpc.rs` | a loaded state keeps the VPC writes the system it is loaded into had not drawn yet | `a_loaded_run_continues_bus_cycle_for_bus_cycle` | not caught | | `state-loses-the-line-shadow` | `vpc.rs` | a loaded state mixes the line in progress with the windows as last written | `a_loaded_run_continues_bus_cycle_for_bus_cycle` | not caught | | `work-ram-8k` | `machine.rs` | the SuperGrafx row has the PC Engine's 8 KiB, mirrored | `work_ram_is_32k_in_banks_f8_to_fb_without_the_8k_mirror` | not caught | | `builder-ignores-the-switch` | `board.rs` | a SuperGrafx built in PC Engine position is in SuperGrafx position | `compat_reads_are_vdc1s_everywhere` | `sw-compat-probe` | | `builder-ignores-the-vpc-given` | `board.rs` | the builder puts a VPC with default switches on the board | `the_builder_takes_a_vpc_with_other_switches_and_refuses_another_pixel_path` | `sw-labels-probe` | **30 caught, 0 missed**: 22 by both the unit tests and the gate, 7 by the unit tests alone, 1 by the gate alone. The gate does not see those seven on its short cases (a `$0E` value other than 0 or 1, VDC 2 sprites over VDC 1 sprites under code 01b, a reset, the three save-state faults, the size of the RAM); whether the cards of rung 3 or the round trips of rung 5 would was not run, since a fault goes on to them only when neither cheap check catches it, and none did. ### Speed Speed is a fast fork's job; this is the figure to measure it against. Frames per second from power-on, nothing logged (`sgx-bench`, `scripts/sgx_bench.py`), one core: | Card (600 frames with a RUN press) | supergrafx-rust | supergrafx-python on PyPy 7.3.20 (whole run; second half) | | --- | --- | --- | | Daimakaimura | 161-183 | 9.7; 10.2 | | 1941 Counter Attack | 169-213 | 11.1; 10.5 | About 3 times real time (59.8 frames a second) against the reference's 0.17, some 17 to 19 times the reference, on a machine at load 13-15 (the Rust runs three times each, one after another). Two VDCs and a per-line mix cost about a third of the base board's speed (pcengine-rust's README: 296-337 frames a second on its three titles). ## Where Rust forced a difference Each module's header says so; together: - **One trait object where the reference has two objects.** The reference's `Vpc` is the pixel path and its `VideoPage` claims the pages; they share state by reference, and the page holds both VDCs. Here `VideoPage` is the board's `PixelPath` (which in pcengine-rust may also claim pages), owns the `Vpc` (`page.vpc`) and reaches the VDCs through `pins.vdcs`, handed in with every access. - **`store_immediate` is `pins.opcode`.** The reference's page calls back into the `SuperGrafx` object, which reads the core's `opcode` (with a fallback to a private attribute for an older core). The base Rust board hands the opcode of the instruction being run to the device with each access; with no CPU it is 0, where the reference answers `False`. - **The board owns the VPC and the CPU owns the board**, so `SuperGrafx` cannot keep `vpc`, `page`, `vdc1` and `vdc2` beside the board. They are `board.vdcs[0]`, `board.vdcs[1]` and `video_page(&mut board)` (the page, and `page.vpc`); `build` consumes the `SuperGrafx` and gives the `System`, after which they are reached through `system.board_mut()`. `set_compat(&mut system, bool)` moves the switch of a running machine. - **Reset** is one call: `Board::reset` calls the pixel path's `reset`, which resets the VPC on power-on. The reference's `SuperGrafx.reset` does the two itself, and its `board.reset` alone leaves the VPC as it was. - **Switches** are fields: `Vpc::priority_labels` (the enum `PriorityLabels::{Detectors, Sgxtech}` for the two strings), `Vpc::window_origin` (`WindowOrigin { divider4, divider3, divider2 }` for the dict by dot divider), `Vpc::window_off_at_or_below`, `VideoPage::st_steers_in_compat`. The constructor's keyword arguments are `SuperGrafxOptions { compat, vpc, st_steers_in_compat, board }`, `board` being the base's `BoardOptions` (the reference's `**board_kwargs`). - **Save states**: the page saves itself through the base board's `DeviceState` (bincode of the registers, the line's shadows, the pending write log and the switch's position), where the reference's state walks the object graph. As there, the position of the back-panel switch is in a state and comes back with it. The named switches are not: a loaded state keeps the system's own (the base Rust board's rule; in the reference a switch set on the instance travels with the state and one set on the class does not). - **Python's arithmetic**: the mid-line dot is `-((first - when) // div)`, a ceiling by floor division of a negative, spelled with the base's `py_floordiv`; window edges are `i64` so that a switch that makes one negative behaves as in Python. - **The unit tests of ST steering.** The reference's test double sets the opcode with each write. The base Rust board takes the opcode from the core's `Pins`, which nothing outside the core can set, so those tests drive the page with `sockets::DetachedPins` (two VDCs and an opcode, no board) and, through the board, the real core (`tests/core_st.rs`). - **Not carried over**: the fallback from `cpu.opcode` to `cpu._opcode` (one core here) and its test; `register_package` (a state's parts are named by the trait). - **Added**: `cards.rs` (which images are SuperGrafx cards: a host needs to know), `trace.rs` and the three binaries (the gate), `SuperGrafx::with_card`, `video_page`, `set_compat`. ## Using it (the fast fork, the browser page) ```rust use supergrafx_rust::pcengine_rust::pads; use supergrafx_rust::pcengine_rust::state::{load_state, save_state}; use supergrafx_rust::{is_supergrafx_card, set_compat, SuperGrafx}; fn run(image: &[u8], file_name: &str) -> Result<(), String> { // Which machine? One of the five known images, or a file named .sgx. if !is_supergrafx_card(image, Some(file_name)) { return Err("a PC Engine card: build pcengine-rust's board".to_string()); } // A SuperGrafx from card bytes, the switch in SuperGrafx position, a 2-button pad. let mut system = SuperGrafx::with_card(image, false)?.build(); // One frame: hold buttons, run, take the sound and the picture (the base board's API). system.board_mut().set_pressed(0, pads::RUN | pads::I); system.run_frame(); let _samples: Vec<(i16, i16)> = system.board_mut().take_audio(); // 44,100 Hz stereo if let Some(frame) = system.board().capture.last_frame.as_ref() { let table = &system.board().vce.rgb_table; for row in &frame.rows { // 242 rows of 9-bit colours, already mixed by the VPC let _rgb: Vec<(u8, u8, u8)> = row.iter().map(|&value| table[value as usize]).collect(); } } set_compat(&mut system, true); // the back-panel switch, moved while it runs let state: Vec = save_state(&system); // the base board's; the VPC is in it load_state(&mut system, &state) } ``` - **Building**: `SuperGrafx::with_card(&bytes, compat) -> Result` (`make_card` strips a 512-byte copier header; a 2-button pad), then `.build() -> pcengine_rust::system::System`. For anything else (another pad, a port device, a power-on seed, a VPC with other switches) `SuperGrafx::new(SuperGrafxOptions { compat, vpc, st_steers_in_compat, board: BoardOptions { card, pad, .. } })`; `board.machine` is replaced by the `SUPERGRAFX` row and `board.pixel_path` must be `None`. - **Everything after `build` is the base board's**: `run_frame`, `step`, `board_mut().set_pressed`, `take_audio`, `capture.last_frame`, `vce.rgb_table`, `save_state`/`load_state`, `save_snapshot`/`load_snapshot` (pcengine-rust's README, "Using the board"). The crate re-exports the base as `supergrafx_rust::pcengine_rust`. - **Compat mode**: `compat = true` is the switch on the back in PC Engine position: VDC 1 alone is decoded, mirrored every 4 bytes, and `ST0`-`ST2` are not steered. The mix still runs (with the VPC at its power-up values it shows VDC 1 only) and the machine keeps its 32 KiB. `set_compat(&mut system, bool)` moves it later; `video_page(system.board_mut())` gives the page (`compat`, `st_steers_in_compat`, `vpc` and its registers). - **Which machine for a card**: a HuCard has no header that says. Use `is_supergrafx_card(&bytes, Some(file_name))`: true for the five cards sold for the SuperGrafx alone (1941 Counter Attack, Aldynes, Battle Ace, Daimakaimura, Madou King Granzort; by the SHA-1 of the image without a copier header: the dumps of the user's library, so another dump or a translation is not recognised by content) and for any file named `.sgx`. `supergrafx_title(&bytes)` gives the title of a known one. Everything else is a PC Engine card and belongs on pcengine-rust's board; a page may still offer "run as SuperGrafx" (the two Darius cards draw more on one), which nothing here measured. The five cards do not run correctly on the plain board: four of five are visibly wrong without VDC 2 (the reference's docs/m6-record.md, "The base-mode fallback, measured"). - **Save states** made here are refused by a plain board and the other way round (the machine row's name and the pixel path's identity are in the header), with the system untouched. - **wasm**: the library builds for `wasm32-unknown-unknown` (`cargo build --release --lib --target wasm32-unknown-unknown`); nothing in it touches a file, a clock or a thread outside `trace::SgxSetup::parse` (through the base's `Setup::parse`) and the binaries. ## Layout `src/machine.rs`, `src/vpc.rs` and `src/board.rs` are the transcriptions of the `supergrafx_python` modules of the same names. Not from the reference's package: `src/cards.rs` (the five cards), `src/trace.rs` (how a traced machine is built from a command line, `roundtrip` and `runahead`) and the binaries `sgx-trace`, `sgx-state-roundtrip`, `sgx-bench`. Tests: `tests/vpc.rs` (the reference's `tests/test_vpc.py`), `board.rs` (`test_board.py`), `core_st.rs` (`test_core_st.py`), `gate.rs` (`test_gate.py`), `state.rs` (`test_state.py`). Not transcribed: the reference's scripts that drive Mesen2, Beetle PCE and MAME and the picture comparisons against them (the reference has been judged against those; this crate is judged against the reference). ## Notes on the reference Nothing found is a divergence: this crate does what supergrafx-python `v0.1.0` does in each case. They are places where the reference looked unintended or stale while it was being transcribed, left for its maintainers: 1. **`board.reset` alone leaves the VPC.** `SuperGrafx.reset(POWER_ON)` resets the board and then the VPC, but the base board's own `Board.reset` (which a host holding `sg.board`, or `System`, would call) knows nothing of the wrapper, so a power-on through it keeps the VPC's registers. Here there is one path (`PixelPath::reset`, called by `Board::reset`), so `board.reset(PowerOn)` does what the reference's `SuperGrafx.reset` does: the one place a call on the Rust board does more than the same call on the reference's. No rung's case resets a machine. 2. **A switch set on the instance travels in a save state; one set on the class does not.** `scripts/sgx_ours.py --vpc-option` uses `setattr` on the `Vpc` instance, and `sg.page.ST_STEERS_IN_COMPAT = True` (the test) sets an instance attribute: both are then walked into a state and overwrite the loading machine's, while a subclass's or the class's value is not saved. Here a state never carries a switch. 3. **`WINDOW_OFF_AT_OR_BELOW` moves the threshold but not the zero of the width**: `window_edge` still subtracts `0x40`, so with the switch below `0x40` a width between the two gives an edge left of the origin (or a negative one, which then means no window). Probably intended, since the two are separate entries (U-SGX1, U-SGX2); noted because the names read as one quantity. 4. **`_replay`'s last branch** takes any register that is not one of the other five as window 2's MSB. Only six registers are ever logged, so it is not reachable with another; it reads as if `$0E` could arrive there. 5. Stale text: `SuperGrafx._store_immediate`'s docstring says the pinned core only keeps the private `_opcode` (the pinned huc6280-python `v0.3.0` has the public `opcode`, as docs/start-here.md says); `tests/test_board.py` calls register 8 "BXR" in one comment (it is BYR; register 7 is BXR). 6. The reference has no test of U-SGX5 (two transparent pixels show VDC 2's), and no card or case of its own tells it apart: the two VDCs' transparent values differ only where one is in its border and the other is not. The seeded fault for it was missed here until the probe gave VDC 2 a narrower display and a unit test was added (`tests/vpc.rs`, `two_transparent_pixels_show_vdc2s`). ## Reproducing ```text scripts/fetch_reference.sh [SOURCE] # the four checkouts at their pins, into external/ scripts/rung1.sh scripts/rung2.sh scripts/rung3.sh --short # the probe's switch cases first scripts/rung3.sh # the cards (about ten minutes of 6 PyPy processes, once) scripts/rung4.sh scripts/rung5.sh scripts/rung6.sh # after a full gate run (it uses the reference cache) ``` `$LIB` (the SuperGrafx cards, default `/data/emu/roms-retrobat/supergrafx`) and `$COVELL` name the user's files; `$PCENGINE_RUST` the base board's checkout (default `../pcengine-rust`), whose `scripts/` the gate imports; `$PYPY` the interpreter. `scripts/sgx_probe.py` builds the synthetic probe card (this repository's own code, not a ROM of anything) into `scratch/`. `JOBS` sets the parallel cases (at most 8). `docs/handoff-brief.md` is the brief this was built from, with what was built appended. ## Licence MIT (see `LICENSE`). Nothing third-party is committed: the reference, the cards and Covell's test are fetched or read in place.