-- SPDX-License-Identifier: MIT -- Log the main CPU's accesses to the board's DMA blitter registers, the protection -- read port (Y-unit) and the sound command port, per frame, from MAME 0.285 run as a -- closed box. Addresses are TMS34010 bit addresses, as MAME's map reports them. -- Environment: TAP_DMA=lo-hi TAP_PROT=lo-hi TAP_SND=lo-hi (hex), TAP_FROM, TAP_TO -- (frames), TAP_OUT (file), TAP_SNAP=1 (save a snapshot into snap/ at the end). local function range(name) local v = os.getenv(name) if not v then return nil end local lo, hi = v:match("(%x+)-(%x+)") return tonumber(lo, 16), tonumber(hi, 16) end local from = tonumber(os.getenv("TAP_FROM") or "600") local to = tonumber(os.getenv("TAP_TO") or "606") local out = io.open(os.getenv("TAP_OUT") or "tap.txt", "w") local cpu = manager.machine.devices[":maincpu"] local space = cpu.spaces["program"] local frame = 0 local function pc() return cpu.state["PC"].value end local function log(kind) return function(offset, data, mask) if frame >= from and frame < to then out:write(string.format("%d %s %08x %04x %08x\n", frame, kind, offset, data, pc())) end return data end end -- Taps are installed one frame before the window opens: taps installed at start-up were -- lost after boot in five of seven runs (2026-11-26), so they are not relied on. local function install() _G.taps = {} local lo, hi = range("TAP_DMA") if lo then _G.taps[#_G.taps + 1] = space:install_write_tap(lo, hi, "dmaw", log("DW")) end if lo then _G.taps[#_G.taps + 1] = space:install_read_tap(lo, hi, "dmar", log("DR")) end lo, hi = range("TAP_PROT") if lo then _G.taps[#_G.taps + 1] = space:install_read_tap(lo, hi, "protr", log("PR")) end if lo then _G.taps[#_G.taps + 1] = space:install_write_tap(lo, hi, "protw", log("PW")) end lo, hi = range("TAP_SND") if lo then _G.taps[#_G.taps + 1] = space:install_write_tap(lo, hi, "sndw", log("SW")) end end _G.tap_frames = emu.add_machine_frame_notifier(function() frame = frame + 1 if frame == from - 1 then install() end if frame >= to then if os.getenv("TAP_SNAP") then manager.machine.video:snapshot() end out:close() manager.machine:exit() end end)