# Drive Nuked-MD's own F5/F7 flags from Python. Usage: drive.py save|load|both SECONDS import ctypes, os, sys, threading, time mode, secs = sys.argv[1], float(sys.argv[2]) lib = ctypes.CDLL(os.path.abspath("libnukedmd.so"), mode=ctypes.RTLD_GLOBAL) for f in ("probe_ym_addr", "probe_expected", "probe_actual"): getattr(lib, f).restype = ctypes.c_uint64 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") names = ["arb.ext_data_out", "arb.ext_vaddress_out", "ioc.ext_vdata_out", "ioc.ext_zdata_out", "ioc.ext_vaddress_out", "tmss.ext_data_out"] def report(tag): bad = sum(lib.probe_actual(i) != lib.probe_expected(i) for i in range(6)) print(f"{tag}: &ym={lib.probe_ym_addr():#x} mcycles={mcycles.value} pointers off-target: {bad}/6", flush=True) for i in range(6): if lib.probe_actual(i) != lib.probe_expected(i): print(f" {names[i]} = {lib.probe_actual(i):#x}, should be {lib.probe_expected(i):#x}", flush=True) if mode == "load": load.value = 1 # as F7, pressed before the first frame 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 == "load": while load.value: time.sleep(0.01) report("B after load"); t0 = mcycles.value time.sleep(secs) print(f"B ran {mcycles.value - t0} half-MCLK after loading, no crash", flush=True) else: time.sleep(secs); report("A before save") save.value = 1 # as F5 while save.value: time.sleep(0.01) print(f"A saved at mcycles={mcycles.value}", flush=True) os._exit(0)