Files

30 lines
1.3 KiB
Lua

-- Log CPU regs when given PCs execute (first N hits each). Env: TBG_LIB, TBG_LOAD, TBG_END, TBG_OUT, TBG_PCS="81CFC4,..", TBG_MAXHITS, TBG_PLAN
local L = dofile(os.getenv("TBG_LIB"))
local last = tonumber(os.getenv("TBG_END") or "600")
local maxh = tonumber(os.getenv("TBG_MAXHITS") or "20")
local plan = L.inputPlan(os.getenv("TBG_PLAN"))
local frame = 0
local h = io.open(os.getenv("TBG_OUT"), "w")
if os.getenv("TBG_LOAD") then L.load(os.getenv("TBG_LOAD")) end
for pc in (os.getenv("TBG_PCS") or ""):gmatch("%x+") do
local a, n = tonumber(pc, 16), 0
emu.addMemoryCallback(function()
n = n + 1
if n > maxh then return end
local s = emu.getState()
h:write(string.format("f%05d %06X A=%04X X=%04X Y=%04X D=%04X DB=%02X P=%02X S=%04X\n", frame, a,
s["cpu.a"], s["cpu.x"], s["cpu.y"], s["cpu.d"], s["cpu.dbr"], s["cpu.ps"], s["cpu.sp"]))
end, emu.callbackType.exec, a, a, emu.cpuType.snes)
end
emu.addEventCallback(function()
local pressed = {[0] = {}, [1] = {}}
for _, e in ipairs(plan) do
if frame >= e.f and frame < e.f + e.hold then for b in e.b:gmatch("[^+]+") do pressed[e.port][b] = true end end
end
emu.setInput(pressed[0], 0); emu.setInput(pressed[1], 1)
end, emu.eventType.inputPolled)
emu.addEventCallback(function()
frame = frame + 1
if frame >= last then h:close(); emu.stop(0) end
end, emu.eventType.endFrame)