# Review variant of study/harness/drive2.py. Usage: drive3.py LIB A|B STOP_AT [B_DELAY_SECONDS] # A: run, set pending_save_state after ~10 s, keep running, dump at STOP_AT (probe2.c). # B: fresh launch, run for B_DELAY_SECONDS first (closer to a real F7 press), then set pending_load_state, # run on, dump at STOP_AT. import ctypes, os, sys, threading, time lib_path, mode, stop = sys.argv[1], sys.argv[2], int(sys.argv[3]) delay = float(sys.argv[4]) if len(sys.argv) > 4 else 0.0 lib = ctypes.CDLL(os.path.abspath(lib_path), mode=ctypes.RTLD_GLOBAL) lib.probe_ym_addr.restype = ctypes.c_uint64 ctypes.c_uint64.in_dll(lib, "stop_at").value = stop save = ctypes.c_int.in_dll(lib, "pending_save_state") load = ctypes.c_int.in_dll(lib, "pending_load_state") mcycles = ctypes.c_uint64.in_dll(lib, "mcycles") argv = (ctypes.c_char_p * 6)(b"nmd", b"-a", b"audio.bin", b"-v", b"video.bin", b"rom.bin") threading.Thread(target=lib.nuked_main, args=(6, argv), daemon=True).start() if mode == "A": time.sleep(10); save.value = 1 while save.value: time.sleep(0.001) print(f"A: &ym={lib.probe_ym_addr():#x}, saved near mcycles={mcycles.value}", flush=True) else: time.sleep(delay) before = mcycles.value load.value = 1 while load.value: time.sleep(0.001) print(f"B: &ym={lib.probe_ym_addr():#x}, ran to mcycles={before} before loading, loaded, " f"off target now {lib.probe_off_target()}/6, mcycles={mcycles.value}", flush=True) time.sleep(900) print("timed out", flush=True)