-- Boot the ROM and drive a real 2-player VS battle (both pads), saving a savestate in it. -- Env: TBG_LIB TBG_OUT TBG_PLAN (battle_lib inputPlan: "f:btn[/hold]" port 1, "p2@f:btn" port 2) -- TBG_SHOTS "f,f,..." TBG_SAVE_AT frame (writes OUT/state.mss) TBG_END last frame local L = dofile(os.getenv("TBG_LIB")) local out = os.getenv("TBG_OUT") local W = emu.memType.snesWorkRam local plan = L.inputPlan(os.getenv("TBG_PLAN")) local shots = {} for f in (os.getenv("TBG_SHOTS") or ""):gmatch("%d+") do shots[tonumber(f)] = true end local saveAt = tonumber(os.getenv("TBG_SAVE_AT") or "-1") local last = tonumber(os.getenv("TBG_END") or "3000") local frame = 0 local log = io.open(out .. "/log.txt", "w") emu.addEventCallback(function() local t = {[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 t[e.port][b] = true end end end emu.setInput(t[0], 0) emu.setInput(t[1], 1, 1) -- Mesen 2.1.1: port 2 needs the third argument (with (t, 1) it goes to port 1) end, emu.eventType.inputPolled) emu.addEventCallback(function() frame = frame + 1 if frame % 50 == 0 then log:write(string.format("%d DE=%02X P1st=%02X P2st=%02X E0=%02X E1=%02X\n", frame, emu.read(0xDE, W), emu.read(0x20D, W), emu.read(0x46D, W), emu.read(0xE0, W), emu.read(0xE1, W))) end if shots[frame] then L.shot(string.format("%s/f%05d.png", out, frame)) end if frame == saveAt then L.save(out .. "/state.mss") end if frame >= last then log:close(); emu.stop(0) end end, emu.eventType.endFrame)