local h = io.open("/home/siege/Projects/tbg/re/runs/mech_1/dbg3.txt", "w") local function log(...) local t={} for i,v in ipairs({...}) do t[i]=tostring(v) end h:write(table.concat(t, " "), "\n"); h:flush() end local n, didExec = 0, false emu.addEventCallback(function() if n == 3 then local ok, s = pcall(emu.createSavestate); log("startFrame", ok, type(s), s and #s) end end, emu.eventType.startFrame) emu.addEventCallback(function() if n == 3 then local ok, s = pcall(emu.createSavestate); log("endFrame", ok, type(s), s and #s) end n = n + 1 if n == 6 then emu.stop(0) end end, emu.eventType.endFrame) emu.addMemoryCallback(function() if n == 4 and not didExec then didExec = true; local ok, s = pcall(emu.createSavestate); log("exec", ok, type(s), s and #s) end end, emu.callbackType.exec, 0x0000, 0xFFFFFF)