"""P2 immutable capture layout and experiment contracts. The diagnostic takes over permanently AFTER the game trace. Synthetic tests may then use the declared RAM/CRAM workspaces; they never resume a contaminated game. Addresses are SH-2 bus addresses, integers are big endian on the wire. """ from pathlib import Path HERE = Path(__file__).resolve().parent AF = HERE.parents[1] OUT = AF / 'board_probe_p2_20261013' ROM = AF / 'sfiii3nr1.bin' ROM_SHA = '35ac2d569893926599b0f68d772e98f412573fb76b305ba3ed910f6136dd2de0' BUILD = 0x50320002 BASE, ROM_LO, ROM_HI = 0x06000000, 0x06700000, 0x06710000 HDR, CONTROL, LAB, LIVE, EVENTS, SCR, END = ( 0x0207A800, 0x0207AB00, 0x0207AC00, 0x0207CC00, 0x0207E600, 0x0207E800, 0x0207F000) LIVE_SIZE, LIVE_COUNT = 80, 80 EVENT_SIZE, EVENT_COUNT = 16, 32 WINDOWS = ((0,16), (120,136), (240,256), (480,496), (640,656)) LIVE_STOP, BOOT_TIMEOUT = 700, 6000 RAM_WORK = (0x02020000, 0x02068000) RAM_A, RAM_B = 0x0202AA00, 0x0203AC00 CRAM_DEST, CRAM_LIST = 0x007F0000, 0x007FF000 WIRE_RANGES = ((HDR, CONTROL), (LAB, SCR)) WIRE_BYTES = sum(b-a for a,b in WIRE_RANGES) SHARD_BYTES, DATA_SHARDS, PARITY_SHARDS = 16, 16, 2 PAGE_BYTES = SHARD_BYTES * DATA_SHARDS PAGES = (WIRE_BYTES + PAGE_BYTES - 1) // PAGE_BYTES # Header 0..0x1ff retains P1's measured-register and summary field addresses. # 0x200..0x2ff is the immutable P2 identity/collection summary. H2 = dict(build=0x200, phase=0x204, error=0x208, lab_done=0x20c, live_count=0x210, event_count=0x214, event_overflow=0x218, trace_first_frame=0x21c, trace_last_frame=0x220, pre_lab_status=0x224, crc32=0x228, lab_bytes=0x22c, trace_policy=0x230, controller_seen=0x234, board_vbr=0x238, terminal_sr=0x23c, init_hash_a=0x240, init_hash_b=0x244, settings=0x248, settings_end=0x288, dma_table=0x288, dma_source=0x28c, dma_format=0x290, dma_source_frame=0x294) # Mutable control is excluded from wire and cannot invalidate the frozen CRC. C = dict(current=0x00, logical_live=0x04, store_live=0x08, timer_saved=0x0c, bench_id=0x10, rep=0x14, flags=0x18, irq_time=0x1c, irq_count=0x20, irq_status=0x24, frame_count=0x28, frame_dest=0x2c, frame_last=0x30, phase=0x34, page=0x38, repeat=0x3c, auto=0x40, page_elapsed=0x44, frc_last=0x48, hold=0x4c, saved_pr=0x50, active_slot=0x54, active_frame=0x58, temp=0x60, render_row=0x64, saved_ccr=0x68, saved_sr=0x6c, last_ftcsr=0x70, vblank_total=0x74, dma_vblank_start=0x78, dma_seed_hash=0x7c) assert LIVE + LIVE_COUNT * LIVE_SIZE <= EVENTS assert EVENTS + EVENT_COUNT * EVENT_SIZE == SCR assert END - HDR == 0x4800 assert PAGES * PAGE_BYTES == WIRE_BYTES def h(name): return HDR + H2[name] def c(name): return CONTROL + C[name] LIMITS = [ 'Phone video supplies digital readout and frame ordering, not calibrated input-to-photon latency.', 'Nominal 25 MHz converts clock/8 timer ticks to time; the independent VBlank experiment measures the CPU-clock/refresh ratio.', 'Repeated values are observations, not proof that one wait-state or arbitration mechanism is uniquely identified.', 'Game fingerprints certify sampled equality only; a mismatch forbids pairing the associated board/emulator timing samples.', 'Synthetic DMA changes video memory only after the game capture; the diagnostic never resumes the game.', 'Busy polling gives completion bounds with measured polling interference, not an unobserved exact completion edge.', 'A missing/corrupt sample remains missing unless recovered from transmitted parity and validated checksums.', ]