mirror of
https://github.com/RetroPortingToolKit/psxrecomp
synced 2026-10-26 02:11:36 -04:00
94be8f6386
SCPH-1001's reset code enters its relocated kernel through the uncached alias (lui $a0,0xA000; addiu $a0,$a0,0x500; jr $a0 at ROM 0xBFC0044C). Beetle charges those four instructions as uncached fetches, 20 cycles; the BIOS dispatch normalized 0xA0000500 to the kernel body compiled for runtime 0x00000500, which charges cached fetches, 11. That is the -9 cycles left at SCPH-1001's kernel entry since #429 (docs/SEGMENT_AWARE_CODE.md §3.3). A BIOS seed that is a runtime PC inside a relocated copy window, in another segment than the window runs in, now asks for a segment variant (§5.4): the function at those ROM bytes and its direct-edge closure (branch and J/JAL targets that leave it, the call return and fall-through past its end) are emitted again with the seed's segment. Every PC a variant computes from its own PCs is in that segment (links, fetch tags and the uncached test, IRQ resume, branch, J and fallthrough targets, store and exception PCs), a KSEG1 variant charges a fetch per instruction, and a jump-table case in another segment is dispatched instead of continuing locally. Variants and their continuations get exact-PC rows in a segment_variant_table. A variant seed that names no emitted function entry stops the build, and so does one in a segment that does not map physical memory (0x20000000-0x7FFFFFFF, KSEG2). The dispatch still finds the word by its normalized key (and applies the kernel-bless guard); a new psx_bios_hit_body() then picks the body for the exact PC. A variant compiled for that PC runs. Any other PC in another segment than the one the word's home body was compiled for still runs the home body, as before, but is now recorded as a BIOS segment miss in the segment-miss ring (kind "bios", with the home PC), so a new alias entry is loud instead of silent (§5.5). psx_bios_key_home_pc(), emitted from the address model, gives each key's home runtime PC: its copy window's runtime address, or the ROM run in place. The ring, TCP segment_misses and the exit report carry each entry's kind; tools/collect_game_misses.py lists a BIOS segment miss for the BIOS seeds instead of writing it into the game's. SCPH-1001's seeds gain 0xA0000500 (kernel_entry_kseg1): a 4-instruction KSEG1 variant of kernel_trampoline_0. Every BIOS's dispatch C gains the two helpers and calls psx_bios_hit_body() where it called the home body. A BIOS without variant seeds (OpenBIOS, SCPH-101, SCPH-5552) keeps its full C; SCPH-1001's full C gains the variant body and its dispatch C the one-row segment_variant_table. New bios_segment_variants test: OpenBIOS with KSEG1 variants of kernel 0x12BC (closure 0x6F8 by jal and 0x70C by fall-through) and 0x13F4 (0x1424 by a conditional branch only) and a KSEG0 variant of kernel memset 0x540 (a KUSEG jump table), plus a static check of SCPH-1001's seed. It compiles the emitted lookup, with and without variants, and queries every variant row, every home key's home PC (checked against the PC each function body was compiled for) and every other segment's alias of it. Seeds in a segment that does not map physical memory stop the build, and a runtime PC in its window's own segment stays a discovery seed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>