Files
TeslaRel410/emulator/firmware-decomp/decode_corr.py
T
CydandClaude Opus 4.8 34e2155672 Decode the IGC coefficient value encoding: bit-serial x2 place values
The payload floats group into clean x2 doubling chains (0.0079 0.016 0.032 ...
1.009) = a coefficient stored as its binary place values C*2^k across the
bit-planes, exactly how a bit-serial adder holds a number. Recovered base
coefficients correlate with the object's own screen-space edge/z slopes
(decode_corr.py, chain_decode.py), so igc_array.py's inputs are cross-validated
against the compiled stream. Fixed-point scales from FOOTER.SS (Czscale=2^20,
Ctexscale=2^16). Readout §02 + decode notes updated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-16 15:33:45 -05:00

86 lines
3.9 KiB
Python

"""Correlate the object's KNOWN geometry coefficients against the floats embedded in
the IGC SEND payloads. If the payload floats match the edge/z/color planes we compute
from the captured screen vertices, we've cracked the encoding mapping."""
import sys, time, struct, pickle, math
sys.path.insert(0, r'C:\VWE\TeslaRel410\emulator\firmware-decomp')
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'
# ---- (A) payload floats from the emulator ----
snap = pickle.load(open(S + r'\snapv2.pkl', 'rb'))
r = emu_main.MainRunner(r'C:\VWE\TeslaRel410\dpl3-revive\patha\cap7.raw.bin', fw='capfw7', max_cmds=6000)
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'])
t0 = time.time(); startq = r.qi
while time.time() - t0 < 60:
if r.qi >= startq + 2: break
h = r.hooks.get(cpu.pc)
if h:
if h(cpu) == 'done': break
continue
if not cpu.step(): break
def rw(a): return cpu.mem.r32(a & 0xffffffff)
def asf(w): return struct.unpack('<f', struct.pack('<I', w))[0]
payload_floats = []
for base, n in [(0x08015000, 4), (0x08015020, 0x45), (0x08015260, 0x21), (0x08015380, 0x29)]:
for i in range(n):
w = rw(base + i * 4); f = asf(w)
if 1e-4 < abs(f) < 1e6: # plausible coefficient range
payload_floats.append(round(f, 5))
uniq = sorted(set(payload_floats), key=abs)
print("PAYLOAD floats (%d, %d unique): " % (len(payload_floats), len(uniq)))
print(" ", uniq)
# ---- (B) geometry-derived coefficients from the captured object ----
objs = pickle.load(open(S + r'\vfull.pkl', 'rb'))['objs']
allv = [v for o in objs for v in o]
xs = sorted(set(round(v['mx'], 2) for v in allv)); zs = sorted(set(round(v['mz'], 2) for v in allv))
grid = {(round(v['mx'], 2), round(v['mz'], 2)): v for v in allv}
def plane(x0, y0, v0, x1, y1, v1, x2, y2, v2):
det = (x1-x0)*(y2-y0) - (x2-x0)*(y1-y0)
if abs(det) < 1e-9: return None
A = ((v1-v0)*(y2-y0) - (v2-v0)*(y1-y0))/det
B = ((v2-v0)*(x1-x0) - (v1-v0)*(x2-x0))/det
C = v0 - A*x0 - B*y0
return A, B, C
# for each grid quad, compute edge slopes + z-plane (screen space) coefficients
edgeAB = []; zplanes = []
for i in range(len(xs)-1):
for j in range(len(zs)-1):
a = grid[(xs[i], zs[j])]; b = grid[(xs[i+1], zs[j])]; c = grid[(xs[i], zs[j+1])]
tri = [a, b, c]
for k in range(3):
p, q = tri[k], tri[(k+1) % 3]
dx = q['sx'] - p['sx']; dy = q['sy'] - p['sy']
L = math.hypot(dx, dy) or 1
edgeAB.append((round(-dy/L, 5), round(dx/L, 5))) # normalised edge normal
zc = plane(a['sx'], a['sy'], a['mz'], b['sx'], b['sy'], b['mz'], c['sx'], c['sy'], c['mz'])
if zc: zplanes.append(tuple(round(v, 5) for v in zc))
edge_vals = sorted(set(v for e in edgeAB for v in e), key=abs)
zA = sorted(set(z[0] for z in zplanes), key=abs)
print("\nGEOMETRY edge normal components (%d unique):" % len(edge_vals))
print(" ", edge_vals[:40])
print("\nGEOMETRY z-plane A (dz/dx) values (%d):" % len(zA))
print(" ", zA[:20])
# ---- (C) look for matches ----
print("\nMATCHES (payload float ~= a geometry coefficient, tol 5%):")
geo_all = set(edge_vals) | set(zA) | set(z[1] for z in zplanes)
hits = 0
for pf in uniq:
for gv in geo_all:
if gv != 0 and abs(pf - gv) < 0.05 * max(abs(pf), abs(gv)) + 1e-4:
print(" payload %.5f ~ geometry %.5f" % (pf, gv)); hits += 1; break
print("total matches:", hits, "/", len(uniq))