Files
TeslaRel410/emulator/firmware-decomp/run_to_draw.py
T
CydandClaude Opus 4.8 d9cfd74070 i860 emu: pipelined FP unit + dual-ops, adds CC sign rule, flush op;
version-matched capfw7 replay BUILDS THE SCENE

- Pipelined FP model: 3-stage adder / 2-stage(double) multiplier pipes with
  KR/KI/T registers; pfadd/pfsub/pfmul honor the P-bit; PFAM(0x00-0x0f)/
  PFSM(0x10-0x1f) dual-operations implemented from the validated mnemonic
  grammar (r2pt, ra1p2, m12apm, ...: M-unit/A-unit routing + K/T loading).
  Survives the capture build's Newton-Raphson boot math.
- adds CC = result-negative (sign rule); addu stays carry. Fixes printf's
  pad-to-width loops and the exit-walk's empty-table branch.
- op 0x0d = flush (cache-line flush, store-format split offset, bit0
  auto-increment): boot cache-flush loops.
- fix/ftrunc: NaN/inf/out-of-range -> IEEE indefinite instead of raising.
- emu_main: per-build address maps (sda4 + capfw7); capfw7 map fully derived
  (main 0xf0403f80, remote_velocirender 0xf040cee0, dN_receive 0xf04024c0,
  velocirender_init 0xf040c5d8, do_init 0xf0409440, reply 0xf0409320,
  alloc core 0xf042c628, v2p 0xf042c300, locks 0xf0423360/0xf04233b8).
  The 860-boot preamble is skipped for capfw7 (the monitor's job -- the app
  build rejects those actions); the capture build dispatches 42 actions,
  explaining the unknown actions 29/42 in cap7.
- run_to_draw: version-matched marathon from the TRUE ENTRY 0xf0400000 with
  the boot handshake ([0xfffff728]) satisfied -- crt0/pools/main are all the
  firmware's own startup, eliminating the seed-slot guesswork.

STATE: authentic boot + init (reply=4) + scene build running: 152 commands
(31 create, 59 flush, dcs_link, list_add, texmaps) processed and replied
before the time cap. First draw_scene sits ~1400 commands ahead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-15 13:20:35 -05:00

63 lines
2.3 KiB
Python

"""Marathon runner: version-matched (capfw7) authentic boot + cap7 replay.
Runs the capture's own firmware build from its TRUE ENTRY (0xf0400000) with the
boot handshake satisfied, so the full startup (crt0, pools, main) is the
firmware's own code; then feeds the capture's scene commands via dN_receive.
Writes the board/IGC stream to igc_stream.bin and prints progress.
Usage: python run_to_draw.py [capture] [max_cmds] [time_budget_s]
"""
import sys, os, time, struct
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import emu860, dis860, emu_main
CAP = sys.argv[1] if len(sys.argv) > 1 else r'C:\VWE\TeslaRel410\dpl3-revive\patha\cap7.raw.bin'
MAXC = int(sys.argv[2]) if len(sys.argv) > 2 else 800
TIME_BUDGET = float(sys.argv[3]) if len(sys.argv) > 3 else 540.0
emu860.Mem.log = lambda self, *a, **k: None
r = emu_main.MainRunner(CAP, fw='capfw7', max_cmds=MAXC)
cpu = r.cpu
cpu.ctrl[0xfffff728] = 1 # boot handshake: transputer says go
cpu.wr(2, 0x000c0000)
cpu.pc = 0xf0400000 # true entry: authentic full startup
t0 = time.time(); last = t0
result = 'time-budget'
while True:
pc = cpu.pc
if pc == cpu.RET_SENTINEL:
result = 'main-returned'; break
if pc < 0x100000:
result = f'derail->{pc:#x}'; break
h = r.hooks.get(pc)
if h:
if h(cpu) == 'done':
result = 'queue-done'; break
continue
if not cpu.step():
result = f'STOP {cpu.stopmsg}'; break
now = time.time()
if now - last > 60:
last = now
print(f" .. t={now-t0:6.0f}s steps={cpu.steps:,} cmds={r.qi} "
f"igc={len(cpu.igc)} board={len(cpu.board_log)}", flush=True)
if now - t0 > TIME_BUDGET:
break
print(f"\nRESULT: {result}")
print(f"steps={cpu.steps:,} cmds={r.qi}/{len(r.queue)}")
print(f"done={dict(r.done)}")
print(f"replies (last 12): {r.replies[-12:]}")
print(f"IGC={len(cpu.igc)} board-log={len(cpu.board_log)}")
if cpu.stopmsg or result.startswith('derail'):
for tpc, tw in cpu.tail[-16:]:
m, ops = dis860.decode(tw, tpc)
print(f" {tpc:#010x}: {tw:08x} {m} {ops}")
out = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'igc_stream.bin')
with open(out, 'wb') as f:
for k, a, v in cpu.board_log:
f.write(struct.pack('<BII', 1 if k == 'w' else 0, a, v))
print(f"board stream -> {out} ({len(cpu.board_log)} entries)")