40 lines
1.9 KiB
Lua
40 lines
1.9 KiB
Lua
-- Per-frame WRAM recorder ($0000-$07FF, 2 KiB/frame, end of frame) with random P1 input; COM plays P2.
|
|
-- Also logs, per frame, every value written to the COM virtual pad ($1F1 at 81:B2E0) into pad.txt.
|
|
-- Env: TBG_LIB, TBG_LOAD, TBG_OUT (dir), TBG_FRAMES, TBG_P1RAND (seed, 0 = idle), TBG_POKES "a=v,.." (frame 2)
|
|
local L = dofile(os.getenv("TBG_LIB"))
|
|
local out = os.getenv("TBG_OUT")
|
|
local frames = tonumber(os.getenv("TBG_FRAMES") or "3000")
|
|
local seed = tonumber(os.getenv("TBG_P1RAND") or "0")
|
|
local pokes = os.getenv("TBG_POKES") or ""
|
|
local rec = io.open(out .. "/rec.bin", "wb")
|
|
local pad = io.open(out .. "/pad.txt", "w")
|
|
local frame = 0
|
|
local function w(a) return emu.read(a, emu.memType.snesWorkRam) end
|
|
L.load(os.getenv("TBG_LOAD"))
|
|
emu.addMemoryCallback(function()
|
|
pad:write(string.format("%d %02X%02X\n", frame, w(0x1F2), w(0x1F1)))
|
|
end, emu.callbackType.exec, 0x81B2E0, 0x81B2E0, emu.cpuType.snes)
|
|
emu.addMemoryCallback(function()
|
|
pad:write(string.format("%d PLAN\n", frame))
|
|
end, emu.callbackType.exec, 0x81D9BA, 0x81D9BA, emu.cpuType.snes)
|
|
local rs = seed
|
|
local function rnd() rs = (rs * 1103515245 + 12345) % 2147483648 return rs end
|
|
local held = {}
|
|
emu.addEventCallback(function() if seed ~= 0 then emu.setInput(held, 0) end end, emu.eventType.inputPolled)
|
|
emu.addEventCallback(function()
|
|
frame = frame + 1
|
|
if frame == 2 then
|
|
for a, v in pokes:gmatch("(%x+)=(%x+)") do emu.write(tonumber(a, 16), tonumber(v, 16), emu.memType.snesWorkRam) end
|
|
end
|
|
if seed ~= 0 and frame % 6 == 0 then
|
|
local r = rnd() % 10
|
|
held = {}
|
|
if r == 0 then held.left = true elseif r == 1 then held.right = true elseif r == 2 then held.a = true
|
|
elseif r == 3 then held.b = true elseif r <= 6 then held.down = true end
|
|
end
|
|
local t = {}
|
|
for i = 0, 0x7FF do t[#t + 1] = string.char(w(i)) end
|
|
rec:write(table.concat(t))
|
|
if frame >= frames then rec:close(); pad:close(); emu.stop(0) end
|
|
end, emu.eventType.endFrame)
|