31 lines
1.3 KiB
Lua
31 lines
1.3 KiB
Lua
-- Execution coverage: unique (PC, M/X/E flags) executed after loading a savestate.
|
|
-- env: TBG_LOAD, TBG_OUT(file), TBG_END, TBG_PLAN
|
|
package.path = "/home/siege/Projects/tbg/re/lua/?.lua;" .. package.path
|
|
local L = require("mech_lib")
|
|
local last = tonumber(os.getenv("TBG_END") or "600")
|
|
local plan = L.plan(os.getenv("TBG_PLAN"))
|
|
local frame, held, holdLeft, running = 0, nil, 0, false
|
|
local seen = {}
|
|
L.load(os.getenv("TBG_LOAD"), function()
|
|
running = true
|
|
emu.addMemoryCallback(L.guard(function(a)
|
|
if not seen[a] then
|
|
local st = emu.getState()
|
|
seen[a] = (st["cpu.ps"] & 0x30) | (st["cpu.emulationMode"] and 1 or 0)
|
|
end
|
|
end), emu.callbackType.exec, 0x008000, 0xFFFFFF)
|
|
end)
|
|
emu.addEventCallback(function()
|
|
if held and holdLeft > 0 then local t = {} for b in held:gmatch("[^+]+") do t[b] = true end emu.setInput(t, 0) end
|
|
end, emu.eventType.inputPolled)
|
|
emu.addEventCallback(L.guard(function()
|
|
if not running then return end
|
|
frame = frame + 1; holdLeft = holdLeft - 1
|
|
if plan[frame] then held, holdLeft = plan[frame][1], plan[frame][2] end
|
|
if frame >= last then
|
|
local h = io.open(os.getenv("TBG_OUT"), "w")
|
|
for a, f in pairs(seen) do h:write(string.format("%06X %02X\n", a, f)) end
|
|
h:close(); emu.stop(0)
|
|
end
|
|
end), emu.eventType.endFrame)
|