-- Run (optionally from savestate) with input plan, then dump Mesen CDL for PRG ROM. Env: -- TBG_LIB, TBG_LOAD, TBG_END, TBG_OUT (file), TBG_PLAN local L = dofile(os.getenv("TBG_LIB")) local last = tonumber(os.getenv("TBG_END") or "600") local plan = L.inputPlan(os.getenv("TBG_PLAN")) local frame = 0 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 if frame >= last then local d = emu.getCdlData(emu.memType.snesPrgRom) local t = {} for i = 0, #d do t[#t + 1] = string.char(d[i] or 0) end local h = io.open(os.getenv("TBG_OUT"), "wb"); h:write(table.concat(t)); h:close() emu.stop(0) end end, emu.eventType.endFrame)