local frames = 0 local snaplog = io.open("snaps.txt", "w") local script = {[500] = {"reset"}, [506] = {"switches-off"}, [650] = {"left"}, [656] = {"none"}, [750] = {"left"}, [756] = {"none"}, [850] = {"left"}, [856] = {"none"}, [950] = {"right"}, [956] = {"none"}, [1050] = {"right"}, [1056] = {"none"}} local fields = { up = {":joysticks", "P1 Up"}, down = {":joysticks", "P1 Down"}, left = {":joysticks", "P1 Left"}, right = {":joysticks", "P1 Right"}, b1 = {":buttons", "P1 Button 1"}, b2 = {":buttons", "P1 Button 2"}, reset = {":console_buttons", "Reset"}, select = {":console_buttons", "Select"}, pause = {":console_buttons", "Pause"}, } local function set(name, on) local f = fields[name] manager.machine.ioport.ports[f[1]].fields[f[2]]:set_value(on and 1 or 0) end emu.register_frame_done(function() frames = frames + 1 local actions = script[frames + 1] -- applied as frame frames + 1 starts if actions then for _, a in ipairs(actions) do if a == "none" or a == "b1" or a == "b2" or a == "b12" or a == "up" or a == "down" or a == "left" or a == "right" then for _, n in ipairs({"up", "down", "left", "right", "b1", "b2"}) do set(n, false) end if a == "b1" or a == "b12" then set("b1", true) end if a == "b2" or a == "b12" then set("b2", true) end if fields[a] and a ~= "b1" and a ~= "b2" then set(a, true) end elseif a == "switches-off" then set("reset", false); set("select", false); set("pause", false) else set(a, true) end end end if frames % 50 == 0 or ({})[frames] then manager.machine.video:snapshot() snaplog:write(frames .. "\n"); snaplog:flush() end if frames >= 1300 then manager.machine:exit() end end)