Files
psxrecomp/tools/check_card.py
T
Matthew Stanley 711d22cff3 fix: per-slot card SIO state + card-specific IRQ delay
The SIO model had a single global mc_state shared between both card slots,
which caused 100% probe abort rate when the BIOS alternates between slot 0
and slot 1: each new 0x81 probe on the other slot would abort the in-flight
state from the previous slot.

Changes:
- Per-slot McSlotState saved/restored on slot switch via mc_save_slot/mc_load_slot
- 0x01 (pad select) preserves card state instead of aborting it
- SIO_IRQ_DELAY split into PAD (4) and CARD (8) — card delay tuned so the
  SIO chain walker can dispatch func_00004D6C before next idle path tick
  clears the protocol counter

Diagnostic tooling:
- I_MASK[7] trace ring buffer with bit-7 set/clear counts and caller info
- Counter (0x7514) field added to SIO trace so card protocol state machine
  progress is visible
- check_card.py inspects card directory contents

Runtime evidence: mc_aborts went from 100% → 0% (when slots don't overlap).
mc_max_state advanced from 1 (only MC_CMD) to 8 (MC_READ_DATA). dispatch_check
confirms _new_card AND its body 0x5688 are dispatched. Detection callback
(func_00005D94 at BFC15894) verified to clear v0=0 before return — continue
path of func_00004D6C IS being taken (133 I_MASK[7] sets observed).

Remaining: 0x7550 stays NULL despite _new_card being dispatched. Either
shell passes NULL buffer or early-return path of _new_card triggers.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 00:36:15 -07:00

27 lines
792 B
Python

#!/usr/bin/env python3
"""Check memory card file contents."""
import sys
def main():
for fname in ['card1.mcd', 'card2.mcd']:
try:
data = open(fname, 'rb').read()
except FileNotFoundError:
print('%s: NOT FOUND' % fname)
continue
print('%s: %d bytes, header=%s' % (fname, len(data), data[0:2]))
for i in range(1, 16):
off = i * 128
status = data[off]
name_bytes = data[off+10:off+10+20]
name = name_bytes.split(b'\x00')[0].decode('ascii', 'replace')
if status != 0xA0:
print(' Slot %2d: status=0x%02X name=%s (USED)' % (i, status, name))
else:
print(' Slot %2d: FREE' % i)
if __name__ == '__main__':
main()