31 lines
1.8 KiB
Lua
31 lines
1.8 KiB
Lua
-- Log unique PCs (with counts) that read/write a range. env: TBG_LOAD, TBG_OUT(file), TBG_LO, TBG_HI (hex),
|
|
-- TBG_MEM (memType name; default CPU address space), TBG_END, TBG_PLAN
|
|
package.path = "/home/siege/Projects/tbg/re/lua/?.lua;" .. package.path
|
|
local L = require("mech_lib")
|
|
local lo, hi = tonumber(os.getenv("TBG_LO"), 16), tonumber(os.getenv("TBG_HI"), 16)
|
|
local mt = os.getenv("TBG_MEM") and emu.memType[os.getenv("TBG_MEM")] or nil
|
|
local last = tonumber(os.getenv("TBG_END") or "600")
|
|
local plan = L.plan(os.getenv("TBG_PLAN"))
|
|
local frame, held, holdLeft, running = 0, nil, 0, false
|
|
local W, R = {}, {}
|
|
local function rec(T, a) local k = string.format("%06X", L.pc()); local e = T[k]; if not e then e = {0, a, a}; T[k] = e end; e[1] = e[1] + 1; if a < e[2] then e[2] = a end; if a > e[3] then e[3] = a end end
|
|
L.load(os.getenv("TBG_LOAD"), function()
|
|
running = true
|
|
emu.addMemoryCallback(function(a) rec(W, a) end, emu.callbackType.write, lo, hi, emu.cpuType.snes, mt)
|
|
emu.addMemoryCallback(function(a) rec(R, a) end, emu.callbackType.read, lo, hi, emu.cpuType.snes, mt)
|
|
end)
|
|
emu.addEventCallback(function()
|
|
if held and holdLeft > 0 then local t = {} for b in held:gmatch("[^+]+") do t[b] = true end emu.setInput(t, 0) end
|
|
end, emu.eventType.inputPolled)
|
|
emu.addEventCallback(function()
|
|
if not running then return end
|
|
frame = frame + 1; holdLeft = holdLeft - 1
|
|
if plan[frame] then held, holdLeft = plan[frame][1], plan[frame][2] end
|
|
if frame >= last then
|
|
local h = io.open(os.getenv("TBG_OUT"), "w")
|
|
for k, e in pairs(W) do h:write(string.format("W %s %d %06X %06X\n", k, e[1], e[2], e[3])) end
|
|
for k, e in pairs(R) do h:write(string.format("R %s %d %06X %06X\n", k, e[1], e[2], e[3])) end
|
|
h:close(); emu.stop(0)
|
|
end
|
|
end, emu.eventType.endFrame)
|