Files
TeslaRel410/emulator/firmware-decomp/capemit.py
T
CydandClaude Opus 4.8 a7a59af9b4 Emit-stream capture + first span read-out from a live scene (trek)
capemit.py records every emitter-range write plus the DMA stream during trek
draws; analyze_emit.py decodes it. Findings: TILE ids = a 13x4 grid (row<<5|col,
832/64 x 512/128); the famous SENDE block at 0x8015020 is byte-identical across
captures = the fixed BACKGROUND-CLEAR program (not scene coeffs); trek's scene
content lives in further payload blocks (0x8015800..0x80168c8+, many primitives)
with a readable per-scanline span structure: row ids (0x39f,0x3a0,... = rows
415..422 observed), place-value indices, and edge constants in x2 chains. A
first-guess parser already extracts 8 consecutive spans forming a leaning
polygon edge -- rasterized geometry read directly from the compiled micro-code.
Full multi-block decode + scene assembly = next session (see memory).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-16 20:50:43 -05:00

63 lines
2.7 KiB
Python

"""THE capture: during 2 trek draws record (a) every w32 issued from the EMITTER range
(0xf041d000-0xf041e000): (pc, addr, word) -- the compiled micro-code with tile-local
coords packed in 8-bit fields; (b) every DMA-list pair from the coeff-copy
(0xf0411cd4): the TILE(id)/GOTO(link) entries that map queue pages -> tile ids.
Save both streams to trek_emit.pkl for offline decode + scene reconstruction."""
import sys, time, struct, pickle
sys.path.insert(0, r'C:\VWE\TeslaRel410\emulator\firmware-decomp')
sys.path.insert(0, r'C:\VWE\TeslaRel410\dpl3-revive\patha')
import emu860, dis860, emu_main
emu860.Mem.log = lambda self, *a, **k: None
S = r'C:\Users\cyd\AppData\Local\Temp\claude\c--VWE-TeslaRel410\4e848c76-6e89-4034-8047-d8d491cb32d8\scratchpad'
snap = pickle.load(open(S + r'\snap_trek0.pkl', 'rb'))
r = emu_main.MainRunner(r'C:\VWE\TeslaRel410\dpl3-revive\patha\trek.raw.bin',
fw='capfw7', max_cmds=30000)
cpu = r.cpu
cpu.mem.pages = {k: bytearray(v) for k, v in snap['pages'].items()}
cpu.ctrl.clear(); cpu.ctrl.update(snap['ctrl'])
cpu.r = list(snap['r']); cpu.f = list(snap['f']); cpu.cr = dict(snap['cr']); cpu.pc = snap['pc']
cpu._apipe = list(snap['apipe']); cpu._mpipe = list(snap['mpipe']); cpu._fp_pipes()
cpu._lpipe = list(snap['lpipe']); cpu._gpipe = list(snap['gpipe'])
cpu._kr, cpu._ki, cpu._t = snap['kr'], snap['ki'], snap['t']
cpu.lcc = snap['lcc']; r.qi = snap['qi']; r.heap = list(snap['heap'])
ELO, EHI = 0xf041d000, 0xf041e000
COPY = 0xf0411cd4
emits = [] # (qi, pc, addr, word)
dma = [] # copy words in order (pairs)
orig = emu860.Mem.w32
def w32(self, addr, val):
pc = cpu.pc
if ELO <= pc < EHI:
emits.append((r.qi, pc, addr & 0xffffffff, val & 0xffffffff))
elif pc == COPY:
dma.append(val & 0xffffffff)
return orig(self, addr, val)
emu860.Mem.w32 = w32
t0 = time.time(); startq = r.qi
while time.time() - t0 < 300:
if r.qi >= startq + 4: break
h = r.hooks.get(cpu.pc)
if h:
if h(cpu) == 'done': break
continue
if not cpu.step(): break
emu860.Mem.w32 = orig
print("emitter writes: %d dma words: %d (cmds %d..%d)" %
(len(emits), len(dma), startq, r.qi))
pickle.dump({'emits': emits, 'dma': dma}, open(S + r'\trek_emit.pkl', 'wb'))
print("saved trek_emit.pkl")
# quick preview: field spectrum of the packed words
import collections
b0 = collections.Counter(); b1 = collections.Counter()
pages = collections.Counter()
for qi, pc, a, w in emits:
b0[w & 0xff] += 1
b1[(w >> 8) & 0xff] += 1
pages[a >> 12] += 1
print("distinct target pages:", len(pages))
print("byte0 spectrum (top 12):", dict(b0.most_common(12)))
print("byte1 spectrum (top 12):", dict(b1.most_common(12)))