Files
psxrecomp/tools/inspect_card.py
T
Matthew Stanley e88e9a0233 phase 4: fix mc_flag persistence so multi-sector card reads work
Before: only sector 0 read succeeded; sector ≥1 reads aborted at 2 bytes
because mc_flag was loaded from mc_slots[].flag on every 0x81 select but
never saved back. The clear in MC_CMD lived only in the working static, so
every reselect re-loaded the stale 0x08 ("new card / changed battery") init
value, and the BIOS bailed every multi-sector op as "card was just inserted,
re-init."

After: BIOS shell memcard menu reads the full 15-sector directory area for
both slots. Real save filenames decode (e.g. "BISLPS-01234SAVE00") and per
card icons render in the bottom panes — the Phase 4 success criterion.

Also bundled this session:
- debug_server: B9D0..B9F0 added to always-on wtrace ranges; fn_dump_parse
  default window scoped to 1M most-recent entries (filter scans against the
  full 128M ring used to freeze the debug server thread for many seconds).
- ISSUES.md + diagnostic tools/*.py written during the audit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 16:43:07 -07:00

31 lines
1.1 KiB
Python

"""Inspect a PSX memcard image — show sector 0, sector 1 (first dir entry),
and check whether sectors 1..15 are formatted-empty (proper) vs zero-padded
(invalid)."""
import sys
def show_sector(name, data, n=16):
print(f" {name}: " + ' '.join(f'{b:02X}' for b in data[:n]))
for path in ('dummy.0.mcr', 'dummy.1.mcr', 'card1.mcd', 'card2.mcd'):
try:
d = open(path, 'rb').read()
except FileNotFoundError:
continue
print(f"=== {path} ({len(d)} bytes) ===")
if len(d) != 131072:
print(" WRONG SIZE — expected 131072")
continue
# Sector 0 (header)
show_sector("sec 0 (header)", d[0:128])
# Directory frames: sectors 1..15
for s in range(1, 16):
off = s * 128
sec = d[off:off+128]
# PSX free directory entry: byte0=0xA0, byte8..11=0xFFFFFFFF, byte127=checksum
print(f" sec {s:>2}: " + ' '.join(f'{b:02X}' for b in sec[:16])
+ f" ck=0x{sec[127]:02X}")
# Count non-zero bytes in directory frames (sectors 1..15)
nz = sum(1 for b in d[128:128*16] if b != 0)
print(f" non-zero bytes in dir frames 1..15: {nz}/{128*15}")
print()