from pathlib import Path p = Path("README.md"); t = p.read_text() LADDER = """| 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` |""" RESULTS = """**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.""" SPEED = """| 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).""" NOTES = """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`), so the two calls cannot differ; which is a behaviour the reference does not have through `board.reset`. 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); docs/m6-record.md's "Reproducing" says 40 tests where the tree has 41 test functions (45 cases with the parameters). 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`).""" for key, value in (("LADDER", LADDER), ("RESULTS", RESULTS), ("SPEED", SPEED), ("NOTES", NOTES)): assert f"@@{key}@@" in t t = t.replace(f"@@{key}@@", value) p.write_text(t)