mirror of
https://github.com/RetroPortingToolKit/psxrecomp
synced 2026-10-26 02:11:36 -04:00
980274a405
Segment-aware code, rollout PR B (docs/SEGMENT_AWARE_CODE.md §5.2). Game/overlay emitter: CodeGenerator gains a code segment and runtime_pc(addr) = code_seg | phys. Links (including a jalr in a branch delay slot), fetch tags and the uncached-fetch test in emit_pre_icache, interrupt resume PCs, CPS exit PCs and continuation keys, store-PC stamps, the reserved-instruction EPC, the slice resume PC, call_by_address and stale-guard targets, the call contract's return PC, cosim PCs, the VSync-query hook's base PC, the data stubs' unknown-dispatch PC and the dispatch rows' addr/resume_pc all go through it. func_/block_ names, .ranges and entry-hook ids keep the compile address. The VSync-query hook is not emitted for an uncached code segment: its hand-timed body charges cached fetches only. The segment defaults to the image's own, so runtime_pc(addr) == addr for every existing input and KSEG0 titles regenerate byte for byte. BIOS emitter: StrictTranslator::translate(d, runtime_pc) stamps stores, the syscall EPC and the break and unaligned-access PCs with the PC the code runs at; the psx_ldd_ temporaries keep the ROM address. The full-function emitter passes relocate_ra() to every translate() call and publishes the runtime PC on a fallthrough. Relocated kernel and shell code therefore stamps its RAM address, as the interpreter does. memory.c re-keys, in the same change, the seven SCPH-1001 store-PC keys that named ROM addresses of relocated code: RAM-0 filters 0x00000F00 (ROM 0xBFC10A00), 0x80056EB4, 0x800585E4, 0x80058788, 0x80059C50 (ROM 0xBFC3EEB4/405E4/40788/41C50), the opt-in Tomba EvCB key 0x00001CE4 (ROM 0xBFC117E4) and the GP0 source key 0x80050B1C (ROM 0xBFC38B1C). Without the re-key the new stamps would silently disable all seven. A RAM PC is ambiguous where the ROM key was not, so each key goes through scph1001_relocated_store(pc, rom): it matches only while the active image is SCPH-1001 and the word at pc is still the ROM word copied there. Other BIOSes and game code at those addresses never match, as before. Tests: emitter_runtime_pc_test (new, CTest, run with PSX_CPS unset and set to 0) compiles a small program through generate_all_functions with the code segment left default, KSEG0, KUSEG and KSEG1, in CPS, CPS-overlay and legacy mode. It requires every emission path to be reached and checks every guest-visible PC class, the identity keys, physical-only differences and KSEG1 per-instruction fetch charging, and the translator's runtime PCs in every PC-bearing form. The ledger gains two regression guards: bios-runtime-pc (OpenBIOS output, plus every translate() call site) and store-pc-keys-runtime (memory.c keys against SCPH1001.toml's windows). KNOWN_GAPS is unchanged: B closes no ledger id on its own (§5.2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>