-- From the char-select savestate, force 1P progression flags on entry to the map scene (84:8000): -- $E2 = FF (all 8 beaten), $E3 = TBG_E3 (0 → char 8 next, 1 → char 9 next). Screenshots via TBG_SHOTS. local out, last = os.getenv("TBG_OUT"), tonumber(os.getenv("TBG_END") or "1500") local e3 = tonumber(os.getenv("TBG_E3") or "0") local plan, shots = {}, {} for f, b in (os.getenv("TBG_PLAN") or ""):gmatch("(%d+):([%w+]+)") do plan[tonumber(f)] = b end for f in (os.getenv("TBG_SHOTS") or ""):gmatch("%d+") do shots[tonumber(f)] = true end local frame, held, holdLeft, loaded = 0, nil, 0, false emu.addMemoryCallback(function() if not loaded then local h = io.open(os.getenv("TBG_LOAD"), "rb"); emu.loadSavestate(h:read("a")); h:close(); loaded = true end end, emu.callbackType.exec, 0x0081B6) emu.addMemoryCallback(function() emu.write(0xE2, 0xFF, emu.memType.snesWorkRam) emu.write(0xE3, e3, emu.memType.snesWorkRam) print(string.format("f%05d map scene entered, E0=%02X E1=%02X", frame, emu.read(0xE0, emu.memType.snesWorkRam), emu.read(0xE1, emu.memType.snesWorkRam))) end, emu.callbackType.exec, 0x848000) emu.addEventCallback(function() if held and holdLeft > 0 then local t = {} for b in held:gmatch("[^+]+") do t[b] = true end emu.setInput(t, 0) end end, emu.eventType.inputPolled) emu.addEventCallback(function() if not loaded then return end frame = frame + 1 holdLeft = holdLeft - 1 if plan[frame] then held, holdLeft = plan[frame], 4 end if shots[frame] then local h = io.open(string.format("%s/f%05d.png", out, frame), "wb"); h:write(emu.takeScreenshot()); h:close() end if frame == last then print(string.format("end E1=%02X", emu.read(0xE1, emu.memType.snesWorkRam))) emu.stop(0) end end, emu.eventType.endFrame)