#!/usr/bin/env python3 """retroDE_ps2 — Ch348 authentic SH3 PSMT8+CLUT through the PERSPECTIVE feeder path. Composes Ch342 (perspective ST/Q triangles via the feeder S1-path) + Ch347 (authentic SH3 PSMT8 texture + real CLUT). The feeder staging carries a perspective QUAD (2 TME tris, word0[32]=1) AND the TEX0 (PSM=PSMT8, CLD=1, CSM2-linear) — so the feeder's TEX0 commit fires the VRAM->CLUT load; a setup bootlet uploads the SH3 PSMT8 texture (as a PSMCT32 transfer — word writes, no byte-RMW) + the SH3 CLUT (256x1 contiguous, the Ch347 lesson). DECAL/opaque; real CLUT RGB authentic, alpha not blended. Label (Codex): authentic SH3 PSMT8 texture + real CLUT rendered through the proven perspective-triangle path on silicon, chosen perspective geometry (NOT authentic SH3 draw geometry). Outputs (LOCAL, gitignored) into sim/data/top_psmct32_raster_demo/: bios_sh3_persp.mem / payload_sh3_persp.mem setup bootlet: BITBLT CLUT + PSMT8 texture (no tris) feeder_sh3_persp.mem feeder staging: perspective quad + TEX0(PSMT8,CLD=1) """ import sys, os HERE=os.path.dirname(os.path.abspath(__file__)); ROOT=os.path.normpath(os.path.join(HERE,"..")) DATA=os.path.join(ROOT,"sim","data","top_psmct32_raster_demo") sys.path.insert(0, DATA); import bake W=H=64 # SH3 64x64 crop TBP0=64 # PSMT8 texture base byte 0x4000 (past the 64x64 PSMCT32 FB = 16 KiB) CBP=80 # CLUT base byte 0x5000 (past the 4 KiB texture) FBW=1 RAM_QWORDS=512 # 8 KiB EE RAM (256-CLUT + 64x64 texture upload ~ 340 qw) # perspective quad in the 64x64 FB: x 8..56, y 8..56; top FAR (w=8), bottom NEAR (w=1); UV over 0..64. PX0,PX1,PY0,PY1 = 8,56,8,56 WF,WN = 8,1 def read_mem(name,n): v=[int(l,16) for l in open(os.path.join(DATA,name)) if l.strip() and not l.strip().startswith("//")] if len(v)RAM_QWORDS: sys.exit(f"payload {qwc}>{RAM_QWORDS-16}") disp_hi=(63<<12)|63 with open(os.path.join(DATA,"payload_sh3_persp.mem"),"w") as f: f.write(f"// Ch348 LOCAL SH3 PSMT8+CLUT perspective setup payload (CLUT@{CBP}, tex@{TBP0}). gitignored. QWC={qwc}.\n") for _ in range(16): f.write(f"{0:032x}\n") for x in payload: f.write(f"{x&((1<<128)-1):032x}\n") for _ in range(RAM_QWORDS-16-qwc): f.write(f"{0:032x}\n") bake.write_bios_mem("bios_sh3_persp.mem", bake.build_textured_demo_bootlet_disp(qwc, disp_hi, FBW), f"Ch348 LOCAL SH3 perspective setup bootlet (QWC={qwc}, DISPLAY1={W}x{H}). gitignored.") stg=build_feeder_staging() bake.write_feeder_stg_mem("feeder_sh3_persp.mem", stg, "Ch348 LOCAL SH3 PSMT8+CLUT perspective quad through the feeder (word0[32]=1, TEX0 PSMT8 CLD=1). gitignored.") print(f"[Ch348] payload_sh3_persp.mem: {qwc} qw (BITBLT 256-CLUT + {W}x{H} PSMT8 tex). feeder_sh3_persp.mem: {len(stg)} words (persp quad).") print(f"[Ch348] perspective quad x[{PX0}..{PX1}] y[{PY0}..{PY1}], top FAR w={WF}, bottom NEAR w={WN}, UV 0..{W}; TEX0 PSMT8 CLD=1 CBP={CBP}.")