cpu = manager.machine.devices[":maincpu"] space = cpu.spaces["program"] dbg = manager.machine.debugger regions = {} tap = space:install_write_tap(0x0, 0xffffff, "w", function(offset, data, mask) local r = offset >> 16 regions[r] = (regions[r] or 0) + 1 end) traces = {"maincpu", "audiocpu"} frames = 0 sub = emu.add_machine_frame_notifier(function() frames = frames + 1 if frames == 590 then for _, tag in ipairs(traces) do dbg:command("trace " .. tag:gsub(":", "_") .. ".tr," .. tag .. ",noloop") end end if frames == 592 then for _, tag in ipairs(traces) do dbg:command("trace off," .. tag) end end if frames == 600 then local out = io.open("writes.txt", "w") for r, n in pairs(regions) do out:write(string.format("%06X %d\n", r << 16, n)) end out:close() manager.machine.video:snapshot() print("FRAMES " .. frames) manager.machine:exit() end end)