-- wall_hist.lua -- where does the run END UP, and does it keep changing?
--
-- Samples the PC once per emulated frame but only counts the window
-- [W_START, W_END], so the early boot/test phases do not pollute the histogram
-- of the final state. Prints a few timestamped PC snapshots so "stuck" is
-- supported by an across-time comparison, not one sample.
--
-- W_START= default 5000
-- W_END= default 20000
-- W_SNAP= snapshot stride (default 2000)
-- W_OUT= printable summary copy
--
-- vt1200 ... -debug -debugger none -debuglog \
-- VT1200_LOG_UNMAPPED=... VT1200_BOARD_LOG=... VT1200_DUARTLOG=... \
-- -autoboot_script harness/mame/wall_hist.lua -autoboot_delay 0
local machine = manager.machine
local dbg = machine.debugger
local cpu = machine.devices[':maincpu']
if not dbg then
print("ERROR: debugger not enabled; pass -debug")
machine:exit()
return
end
local wstart = tonumber(os.getenv("W_START") or "5000")
local wend = tonumber(os.getenv("W_END") or "20000")
local snap = tonumber(os.getenv("W_SNAP") or "2000")
local frames = 0
local hist, first, last = {}, {}, {}
emu.register_frame_done(function()
frames = frames + 1
local v = cpu.state['PC'].value
if frames >= wstart then
hist[v] = (hist[v] or 0) + 1
if not first[v] then first[v] = frames end
last[v] = frames
end
if frames % snap == 0 then
print(string.format("frame %6d PC=%08X", frames, v))
end
if frames >= wend then
local n = 0
for _ in pairs(hist) do n = n + 1 end
print(string.format("--- window [%d,%d]: distinct PCs=%d", wstart, wend, n))
print("--- hottest PCs ---")
local list = {}
for k, c in pairs(hist) do list[#list + 1] = {k, c} end
table.sort(list, function(a, b) return a[2] > b[2] end)
for i = 1, math.min(25, #list) do
print(string.format(" PC=%08X samples=%d first=%d last=%d",
list[i][1], list[i][2], first[list[i][1]], last[list[i][1]]))
end
machine:exit()
end
end, "vt1200-wall")
dbg.visible_cpu = cpu
dbg.execution_state = 'run'