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>
81 lines
3.4 KiB
Python
81 lines
3.4 KiB
Python
"""Confirm the bit-serial coefficient encoding: group payload floats into x2 doubling
|
|
chains (bit-plane place values C*2^k) and recover each base coefficient C. Then check
|
|
the bases against the object's geometry-derived edge/plane slopes."""
|
|
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'
|
|
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]
|
|
|
|
# collect payload floats WITH which SEND + offset they came from
|
|
allf = []
|
|
for base, n, tag in [(0x08015000, 4, 'EDGE'), (0x08015020, 0x45, 'ZCOL'),
|
|
(0x08015260, 0x21, 'S21'), (0x08015380, 0x29, 'S29')]:
|
|
for i in range(n):
|
|
f = asf(rw(base + i * 4))
|
|
if 1e-5 < abs(f) < 1e7:
|
|
allf.append(f)
|
|
|
|
# group into doubling chains: reduce each |f| by dividing by 2 until in [base_lo,base_hi)
|
|
def fundamental(f):
|
|
a = abs(f)
|
|
while a >= 0.02: # bring into a common decade
|
|
a /= 2.0
|
|
return a
|
|
bases = {}
|
|
for f in allf:
|
|
fu = round(fundamental(f), 6)
|
|
# merge near-equal fundamentals
|
|
key = None
|
|
for k in bases:
|
|
if abs(k - fu) < 0.0006:
|
|
key = k; break
|
|
if key is None:
|
|
bases[fu] = []
|
|
key = fu
|
|
bases[key].append(round(f, 6))
|
|
print("recovered BASE coefficients (each = a bit-serial x2 chain):")
|
|
for k in sorted(bases):
|
|
ch = sorted(set(bases[k]), key=abs)
|
|
print(" base ~%.6f <- chain %s" % (k, ch))
|
|
|
|
# geometry: object's screen-space edge slopes (dy/dx normal) + z-plane A/B
|
|
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
|
|
return A,B
|
|
zAB=set()
|
|
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])]
|
|
p=plane(a['sx'],a['sy'],a['mz'],b['sx'],b['sy'],b['mz'],c['sx'],c['sy'],c['mz'])
|
|
if p: zAB.add(round(abs(p[0]),5)); zAB.add(round(abs(p[1]),5))
|
|
print("\nobject z-plane |A|,|B| slopes (screen space), smallest 15:")
|
|
print(" ", sorted(x for x in zAB if x>1e-4)[:15])
|