-- SPDX-License-Identifier: MIT -- Written for pico-python's mame_trace.py: log the Pico I/O block, then snapshot. local out = io.open("io.log", "w") local space = manager.machine.devices[":maincpu"].spaces["program"] local cpu = manager.machine.devices[":maincpu"] local screen = manager.machine.screens[":megadriv"] local frames = 0 local function log(kind, offset, data, mask) out:write(string.format("%d %s pc=%06X %06X data=%04X mask=%04X\n", frames, kind, cpu.state["PC"].value, offset, data, mask)) end -- held in globals so they are not collected io_read_tap = space:install_read_tap(0x800000, 0x80001f, "pico_io_r", function(offset, data, mask) log("R", offset, data, mask) end) io_write_tap = space:install_write_tap(0x800000, 0x80001f, "pico_io_w", function(offset, data, mask) log("W", offset, data, mask) end) frame_sub = emu.add_machine_frame_notifier(function() frames = frames + 1 if frames == 480 then out:close() screen:snapshot() manager.machine:exit() end end)