45 lines
2.0 KiB
Lua
45 lines
2.0 KiB
Lua
-- Force P1 to cast power TBG_POWER at level 1, then record. Env:
|
|
-- TBG_LIB, TBG_LOAD, TBG_OUT (dir), TBG_POWER (hex id), TBG_SLOT (0-3, default 0), TBG_SHOTREL (frames after cast), TBG_SPAN
|
|
local L = dofile(os.getenv("TBG_LIB"))
|
|
local out = os.getenv("TBG_OUT")
|
|
local pid = tonumber(os.getenv("TBG_POWER"), 16)
|
|
local slot = tonumber(os.getenv("TBG_SLOT") or "0")
|
|
local span = tonumber(os.getenv("TBG_SPAN") or "700")
|
|
local rel = {}
|
|
for f in (os.getenv("TBG_SHOTREL") or "5,40,90,150,250,400,700"):gmatch("%d+") do rel[tonumber(f)] = true end
|
|
local W = emu.memType.snesWorkRam
|
|
local frame, castAt, pressUntil = 0, nil, -1
|
|
local log = io.open(out .. "/log.txt", "w")
|
|
local bf = io.open(out .. "/boards.bin", "wb")
|
|
L.load(os.getenv("TBG_LOAD"))
|
|
emu.addEventCallback(function()
|
|
emu.setInput(frame < pressUntil and {up = true} or {}, 0)
|
|
emu.setInput({}, 1)
|
|
end, emu.eventType.inputPolled)
|
|
emu.addEventCallback(function()
|
|
frame = frame + 1
|
|
if not castAt and frame > 3 and emu.read(0x20D, W) == 5 and emu.read(0x46D, W) ~= 0x0B and emu.read(0x46D, W) ~= 0x0C then
|
|
emu.write(0x231 + slot, pid, W)
|
|
emu.write(0x221, slot + 1, W)
|
|
L.dumpWram(out .. "/before.wram")
|
|
L.shot(out .. "/before.png")
|
|
pressUntil = frame + 4
|
|
castAt = frame
|
|
end
|
|
if castAt then
|
|
local r = frame - castAt
|
|
local t = {}
|
|
for _, a in ipairs({0x20D, 0x229, 0x221, 0x46D, 0x489, 0x481, 0x16F, 0x16B, 0x16C, 0x16D, 0x170, 0x171, 0xD8}) do
|
|
t[#t + 1] = string.format("%02X", emu.read(a, W))
|
|
end
|
|
log:write(r .. " " .. table.concat(t, " ") .. "\n")
|
|
local b = {}
|
|
for i = 0, 219 do b[#b + 1] = string.char(emu.read(0x296 + i, W)) end
|
|
for i = 0, 219 do b[#b + 1] = string.char(emu.read(0x4F6 + i, W)) end
|
|
bf:write(table.concat(b))
|
|
if rel[r] then L.shot(string.format("%s/r%04d.png", out, r)); L.dumpWram(string.format("%s/r%04d.wram", out, r)) end
|
|
if r >= span then log:close(); bf:close(); emu.stop(0) end
|
|
end
|
|
if frame > 2000 then log:close(); emu.stop(1) end
|
|
end, emu.eventType.endFrame)
|