Files
psxrecomp/tools/decode_ctrl_window.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

36 lines
1.4 KiB
Python

"""Decode CTRL/TX_DATA writes around a byte_seq window. Args: bs_min bs_max."""
import sys, json, re
if len(sys.argv) != 3:
print('usage: decode_ctrl_window.py BS_MIN BS_MAX', file=sys.stderr); sys.exit(1)
bs_min, bs_max = int(sys.argv[1]), int(sys.argv[2])
txt = sys.stdin.read()
m = re.search(r'\{.*\}', txt, re.S)
if not m:
print('parse fail'); sys.exit(1)
j = json.loads(m.group(0))
ents = j.get('entries', [])
hits = [e for e in ents if bs_min <= e.get('byte_seq', 0) <= bs_max]
print(f'(found {len(hits)} of {len(ents)} entries with byte_seq in [{bs_min},{bs_max}])')
print(' seq pc func reg value byte_seq')
for e in hits:
val = int(e['value'], 16)
a = e['addr']
if a.endswith('1040'):
kind, meaning = 'TX_DATA', f'tx={val:#04x}'
elif a.endswith('104A'):
kind = 'CTRL'
bits = []
if val & 0x1: bits.append('TX_EN')
if val & 0x2: bits.append('SELECT')
if val & 0x4: bits.append('RX_EN')
if val & 0x10: bits.append('ACK')
if val & 0x40: bits.append('RESET')
if val & 0x1000: bits.append('ACK_IRQ_EN')
if val & 0x2000: bits.append('SLOT')
meaning = f'{val:#06x} = {"|".join(bits) if bits else "NONE"}'
else:
kind, meaning = a[-4:], e['value']
print(f" {e['seq']:>5} {e['pc']} {e['func']} {kind:>7} {meaning:30s} bs={e['byte_seq']}")