"""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(' {out} ({len(cpu.board_log)} entries)")