22 lines
1.2 KiB
Lua
22 lines
1.2 KiB
Lua
-- Battle savestate, force $D2 = TBG_D2, count COM planner calls (81:D9BA with $12A=1) and P2 soft-drop presses over TBG_END frames.
|
|
local last, d2 = tonumber(os.getenv("TBG_END") or "1200"), tonumber(os.getenv("TBG_D2") or "0")
|
|
local frame, loaded, plans, downs, ups = 0, false, 0, 0, 0
|
|
emu.addMemoryCallback(function()
|
|
if not loaded then local h = io.open(os.getenv("TBG_LOAD"), "rb"); emu.loadSavestate(h:read("a")); h:close(); loaded = true end
|
|
emu.write(0xD2, d2, emu.memType.snesWorkRam)
|
|
end, emu.callbackType.exec, 0x0081B6)
|
|
emu.addMemoryCallback(function()
|
|
if loaded and emu.read(0x12A, emu.memType.snesWorkRam) == 1 then plans = plans + 1 end
|
|
end, emu.callbackType.exec, 0x81D9BA)
|
|
emu.addEventCallback(function()
|
|
if not loaded then return end
|
|
frame = frame + 1
|
|
local pad = emu.read(0x1F1, emu.memType.snesWorkRam) | (emu.read(0x1F2, emu.memType.snesWorkRam) << 8)
|
|
if pad & 0x0400 ~= 0 then downs = downs + 1 end
|
|
if pad & 0x0800 ~= 0 then ups = ups + 1 end
|
|
if frame >= last then
|
|
print(string.format("D2=%d frames=%d com_pieces=%d frames_softdrop=%d frames_up=%d p2_meter=%02X", d2, frame, plans, downs, ups, emu.read(0x481, emu.memType.snesWorkRam)))
|
|
emu.stop(0)
|
|
end
|
|
end, emu.eventType.endFrame)
|