-- msg_snap.lua -- read-only frame side channel + on-demand screen snapshots. -- -- No breakpoints and no firmware memory writes: this only reads the frame -- counter and takes MAME screenshots when the host creates the trigger file. -- -- MSG_TRIGGER= file the host writes; content: " " -- MSG_DIR= where PNGs go -- -- The host writes " 1 0" for one immediate frame, or e.g. -- " 8 5" for eight snapshots five frames apart. The file is removed -- when consumed. Snapshots render through the emulated palette. local machine = manager.machine local dir = os.getenv("MSG_DIR") or "." local trigger = os.getenv("MSG_TRIGGER") or (dir .. "/trigger") local screen = nil for _, s in pairs(machine.screens) do screen = s; break end local frame = 0 local job = nil local function consume_trigger() local fh = io.open(trigger, "r") if not fh then return end local text = fh:read("*a") or "" fh:close() os.remove(trigger) local prefix, count, stride = text:match("(%S+)%s+(%d+)%s+(%d+)") if not prefix then print("msg_snap: bad trigger " .. text) return end job = { prefix = prefix, left = tonumber(count), stride = tonumber(stride), next = frame } print(string.format("msg_snap: frame %d job %s x%d every %d", frame, prefix, job.left, job.stride)) end emu.register_frame_done(function() frame = frame + 1 consume_trigger() if job and frame >= job.next and screen then local out = string.format("%s/%s_frame%05d.png", dir, job.prefix, frame) local ok, err = pcall(function() return screen:snapshot(out) end) print(string.format("msg_snap: frame %d %s ok=%s err=%s", frame, out, tostring(ok), tostring(err))) job.left = job.left - 1 job.next = frame + job.stride if job.left <= 0 then job = nil end end if frame % 500 == 0 then local cpu = machine.devices[':maincpu'] print(string.format("msg_snap: frame %d PC=%08X", frame, cpu.state['PC'].value)) end end, "vt1200-msg-snap") if machine.debugger then machine.debugger.execution_state = 'run' end