import struct, sys, io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
DUMP = r"C:/Users/vikto/Documents/Claude/rt-4d/radio-spi-dump.bin"
data = open(DUMP, "rb").read()
ZN_BASE=0x01C000
def hx(b): return " ".join(f"{x:02X}" for x in b)
# Full 256 zone records across 0x20000
named=0
for i in range(256):
    off=ZN_BASE+i*512
    d=data[off:off+512]
    if all(b==0xFF for b in d): continue
    name=bytes(b for b in d[0x04:0x14] if b!=0xFF).decode('gbk','ignore')
    # skip the channel-copy records (rec0/rec8 look like packed 48B channels: byte0 in 0x0E/0x40 etc)
    count=d[0]|(d[1]<<8)
    hasname = any(32<=b<127 for b in d[0x04:0x14])
    print(f"rec{i} @0x{off:06X} count={count} b0={d[0]:02X} b1={d[1]:02X} b2={d[2]} b3={d[3]} name={name!r} hasname={hasname}")
    if hasname:
        named+=1
        chans=[d[0x14+k*2]|(d[0x15+k*2]<<8) for k in range(20)]
        print("    head0-13:", hx(d[0:0x14]))
        print("    chans:", chans)
        print("    scan@0x1A4:", hx(d[0x1A4:0x1A4+25]))
print("named zones:", named)
