data = open(r"C:/Users/vikto/Documents/Claude/rt-4d/radio-spi-dump.bin","rb").read()

# BLOB1 decode as GB2312
seg=data[0x198000:0x19b800]
try:
    txt=seg.decode('gb2312', errors='replace')
    print("BLOB1 as GB2312 (first 120 chars):")
    print(repr(txt[:120]))
    print("...middle:", repr(txt[3000:3060]))
except Exception as e:
    print("err",e)

# Count of hanzi in BLOB1 (each 2 bytes)
n1 = len(seg)//2
print("BLOB1 char count:", n1)

# BLOB3: sorted UTF-16BE codepoints. Count them (until 00 00 fill)
seg3=data[0x3f0000:0x400000]
cps=[]
for i in range(0,len(seg3)-1,2):
    v=(seg3[i]<<8)|seg3[i+1]
    if v==0:
        # zeros are padding within blocks; keep scanning but record
        cps.append(0)
    else:
        cps.append(v)
nonzero=[v for v in cps if v!=0]
print("BLOB3 total 2-byte slots:",len(cps),"nonzero:",len(nonzero))
print("BLOB3 first cps:", [hex(v) for v in nonzero[:16]])
print("BLOB3 last  cps:", [hex(v) for v in nonzero[-16:]])
print("BLOB3 min/max:", hex(min(nonzero)), hex(max(nonzero)))
# is it strictly ascending overall? check monotonic ignoring zeros
asc=all(nonzero[i]<=nonzero[i+1] for i in range(len(nonzero)-1))
print("BLOB3 nonzero ascending?", asc)
# decode a few as unicode chars
print("BLOB3 sample chars:", ''.join(chr(v) for v in nonzero[:20]))

# BLOB2 audio - measure total extent: from 0x352000 until sustained FF
i=0x352000
run=0; endaud=None
while i<0x3e0000:
    if data[i]==0xff:
        run+=1
        if run>=2048:
            endaud=i-run+1; break
    else:
        run=0
    i+=1
print("BLOB2 audio ends ~", hex(endaud) if endaud else "not found within 0x3e0000")
