Files
TeslaRel410/dpl3-revive/patha/bsl_pair.py
T
CydandClaude Fable 5 afc3fd839e Vendor dpl3-revive: the Division/DPL3 renderer, now ours
Bring the graphics-dev collaborator's dpl3-revive into the repo as first-class
project code (they've handed it off; it's ours now). This is the proven
Division renderer that our in-process rt_draw has been trying to be.

What's here:
- parser/  B2Z/V2Z/SVT/SCN/SPL/BGF/BMF/BSL decoders (pure Python).
- spec/    reverse-engineered format + the definitive VelociRender wire
           protocol (from the original DIVISION source, matches our live
           VPX node/action tables exactly).
- source-ref/  read-only copies of the original DIVISION C (BIZREAD.C,
           DPLTYPES.H, DPL.H) that define the formats.
- patha/   the "virtual VelociRender board": vrboard.py (24-action protocol
           server), vrview.py (numpy software rasterizer, the reference),
           vrview_gl.py (moderngl GPU backend, 832x512@60Hz), plus the
           run/replay/regress tooling and evidence renders. Drives FLYK/BLADE/
           Star Trek demos AND our btl4opt/rpl4opt game binaries.
- viewer/  WebGL archive generators (.py); prebuilt HTML/data regeneratable.
- samples/ small test models/textures.
- bt*.raw.bin  real BTL4OPT arena wire captures (kept for offline renderer
           testing/regression against OUR game).

.gitignore keeps the multi-hundred-MB demo capture dumps + debug logs +
regeneratable viewer bundles out of history (they stay on disk).

Phase 0 of the integration is validated: their board decodes our bt8 capture
with zero errors (3748 nodes, 507 instances, 4 mechs) and renders our arena
(terrain/dome/sky, correct Division DAC gamma). Plan + status in memory;
integration continues in emulator/RENDERER-COLLAB.md.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-05 22:06:25 -05:00

77 lines
2.8 KiB
Python

#!/usr/bin/env python3
"""
bsl_pair.py -- decode the wire BSL slice-selector encoding by pairing:
wire side: mode-0 texmap pages + the texture nodes' selector words
file side: which .BSL file each page is (byte compare) + the bitslice values
(b2z tag 0x018) of every texture entry that references that .BSL
in the scene's .BGF/.BMF models.
python bsl_pair.py sdemo2.raw.bin c:\\temp\\flykc\\HPDAVE\\VIDEO
"""
import os, sys, struct, glob
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'parser'))
from vrboard import VirtualBoard, Assembler
from decode_anim import find_framed_start
import b2z
cap = sys.argv[1] if len(sys.argv) > 1 else 'sdemo2.raw.bin'
vid = sys.argv[2] if len(sys.argv) > 2 else r'c:\temp\flykc\HPDAVE\VIDEO'
data = open(cap, 'rb').read()
board = VirtualBoard(); asm = Assembler(); asm.feed(data[find_framed_start(data):])
for m in asm:
try: board.handle(m)
except Exception: pass
if board.frames >= 50: break
types = {h: nd.get('type') for h, nd in board.nodes.items()}
# wire: selectors per texmap
sel_by_texmap = {}
for h, nd in board.nodes.items():
if types.get(h) != 0xc:
continue
b = nd.get('body') or b''
if len(b) < 56:
continue
texm = struct.unpack_from('<I', b, 4)[0]
sel = struct.unpack_from('<I', b, 52)[0]
sel_by_texmap.setdefault(texm, []).append((h, sel))
# file: read every .BSL in the search dir
bsls = {}
for f in glob.glob(os.path.join(vid, '*.BSL')):
bsls[os.path.basename(f)] = open(f, 'rb').read()
# file: texture entries (name, mapfile, bitslice) from every .BGF/.BMF
filetex = {}
for f in glob.glob(os.path.join(vid, '*.BGF')) + glob.glob(os.path.join(vid, '*.BMF')):
try:
mdl = b2z.load(f)
except Exception:
continue
for name, t in mdl.textures.items():
if t.mapfile:
filetex.setdefault(t.mapfile.upper(), []).append(
(name, t.bitslice, os.path.basename(f)))
for texm, sels in sorted(sel_by_texmap.items()):
entry = board.tex.get(texm)
if entry is None or entry['mode'] != 0:
continue
page = bytes(entry['data'])
match = None
for bn, bd in bsls.items():
if bd[:len(page)] == page or page[:min(len(page), len(bd))] == bd[:min(len(page), len(bd))]:
match = bn
break
print(f"texmap {texm:#5x} {entry['u']}x{entry['v']} mode0 -> file {match}")
print(f" wire selectors: {sorted(set(s for _, s in sels))} "
f"({[hex(s) for _, s in sorted(sels)]})")
if match:
keys = [k for k in filetex if match.split('.')[0] in k]
for k in keys:
for name, bs, src in sorted(set(filetex[k])):
print(f" file: {name:24} bitslice={bs:3} (in {src}, map {k})")