# Usage: drive2.py LIB A|B STOP_AT # A: run, press F5 (pending_save_state) after ~10 s, keep running, dump at STOP_AT. # B: fresh launch, press F7 (pending_load_state) before the first pass, run, dump at STOP_AT. import ctypes, os, sys, threading, time lib_path, mode, stop = sys.argv[1], sys.argv[2], int(sys.argv[3]) 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") if mode == "B": load.value = 1 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: while load.value: time.sleep(0.001) print(f"B: &ym={lib.probe_ym_addr():#x}, loaded, off target now {lib.probe_off_target()}/6, mcycles={mcycles.value}", flush=True) time.sleep(600) print("timed out", flush=True)