mirror of
https://github.com/RetroPortingToolKit/psxrecomp
synced 2026-10-27 10:38:46 -04:00
4f80d22096
The Ape Escape "Checking MEMORY CARD" thread-switch smear: a genuine in-exception ChangeThread detected deep in nested host dispatch commits a poisoned TCB context (stale resume-PC latch ahead of the live GPRs) -> the resumed consumer faults on a smeared jumptable index (DISPATCH FATAL). Fix #2 (user-agreed architecture): don't honor the switch at the poisoned nested point. Resume the outgoing thread transparently at its OWN EPC, record the switch as pending, and honor it at the next block leader where that thread is running with a materialized resume PC -- re-saving it cleanly there. Do NOT require the outermost STATIC dispatch boundary: the memcard consumer lives permanently inside the nested dirty-RAM interpreter and never reaches it; the scheduler landing already resets the nested dispatch/call-unit counters on the longjmp, same as the immediate-switch path. - interrupts.c: the kind-30 escape splits into immediate (outermost / toggle-off / no clean resume PC) vs deferred; new honor hook at the top of psx_check_interrupts; always-on thread_trace kinds 31 (defer) / 32 (honor) / 33 (stale-drop). The deferred branch restores the outgoing thread's clean GPRs/HI/LO/SR AND cpu->pc (the in-exception RFE had left cpu->pc at the target). - traps.c: psx_sched_save_context / set_current_tcb / current_tcb exports over the scheduler's private TCB accessors. - A/B toggle PSX_DEFER_SWITCH (default ON); =0 forces baseline immediate switch. Validated (LLE + HLE, ring-verified): converts the smear DISPATCH-FATAL into forward progress -- the card driver now reads 108 blocks. A/B (PSX_DEFER_SWITCH=0) proves the fix is SOUND: the remaining stall (SIO IRQ bit 7 masked in I_MASK, card read never completing) reproduces IDENTICALLY with the fix off, so it is a SEPARATE, pre-existing SIO-mask bug -- the next blocker, not this fix's residual. Goal (file-select showing File 1-4) NOT yet reached. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>