local frames = 0 local snaplog = io.open("snaps.txt", "w") local script = {[600] = {"reset"}, [606] = {"switches-off"}} 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() if true then local space = manager.machine.devices[":maincpu"].spaces["program"] local parts = {} for a = 0x1800, 0x27ff do parts[#parts + 1] = string.format("%02X", space:read_u8(a)) end local ramlog = io.open("ram.txt", "a") ramlog:write(frames .. " " .. table.concat(parts) .. "\n"); ramlog:close() end end if frames >= 1200 then manager.machine:exit() end end)