import io
data = open(r"C:/Users/vikto/Documents/Claude/rt-4d/radio-spi-dump.bin","rb").read()
out=io.open(r"C:/Users/vikto/Documents/Claude/rt-4d/analyze/out11.txt","w",encoding="utf-8")

# The font bitmap likely starts on a clean boundary. Find where the pinyin/CJK code
# table ends and bitmap begins. The 0x19c000 area had a leading block of zeros then bitmaps.
# Let's find a good glyph base by scanning for a 32-byte-aligned region where rendering
# 16 rows x 2 bytes gives connected shapes. Test several bases and stride 32.

def render(off, w_bytes, rows):
    lines=[]
    for r in range(rows):
        line=""
        for cb in range(w_bytes):
            b=data[off+r*w_bytes+cb]
            for bit in range(8):
                line += "#" if (b>>bit)&1 else "."
        lines.append(line)
    return lines

# Render 4 consecutive 16x16 glyphs side by side starting at a base, for several bases
for base in (0x19c400, 0x1a0000, 0x1b0000, 0x200000):
    out.write("=== base %#x, four 16x16 glyphs (32B each) ===\n"%base)
    gs=[render(base+g*32,2,16) for g in range(4)]
    for r in range(16):
        out.write("  ".join(gs[g][r] for g in range(4))+"\n")
    out.write("\n")
out.close()
print("done")
