Files

14 lines
909 B
Lua

local h = io.open("/home/siege/Projects/tbg/re/runs/mech_1/dbg2.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 done, n = false, 0
local function try(where)
if done then return end
local f = io.open("/home/siege/Projects/tbg/re/runs/battle1/state.mss", "rb"); local d = f:read("a"); f:close()
local ok, r = pcall(emu.loadSavestate, d)
log(where, "len", #d, "ok", ok, "ret", r, "pc", emu.getState()["cpu.pc"])
done = ok and r ~= false
end
emu.addEventCallback(function() try("startFrame") end, emu.eventType.startFrame)
local id; id = emu.addMemoryCallback(function() try("exec"); end, emu.callbackType.exec, 0x8000, 0xFFFFFF)
emu.addEventCallback(function() n = n + 1; if n == 5 then log("end pc", emu.getState()["cpu.k"], emu.getState()["cpu.pc"]); emu.stop(0) end end, emu.eventType.endFrame)