-- Record WRAM [TBG_LO, TBG_HI) every frame to TBG_OUT (raw, concatenated), plus input bytes. Env: -- TBG_LIB, TBG_LOAD, TBG_END, TBG_OUT, TBG_PLAN, TBG_LO, TBG_HI (hex) local L = dofile(os.getenv("TBG_LIB")) local last = tonumber(os.getenv("TBG_END") or "600") local lo, hi = tonumber(os.getenv("TBG_LO") or "0", 16), tonumber(os.getenv("TBG_HI") or "1000", 16) local plan = L.inputPlan(os.getenv("TBG_PLAN")) local frame = 0 local h = io.open(os.getenv("TBG_OUT"), "wb") if os.getenv("TBG_LOAD") then L.load(os.getenv("TBG_LOAD")) 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 local t = {} for i = lo, hi - 1 do t[#t + 1] = string.char(emu.read(i, emu.memType.snesWorkRam)) end h:write(table.concat(t)) if frame >= last then h:close(); emu.stop(0) end end, emu.eventType.endFrame)