-- Per-frame hex log of WRAM ranges. env: TBG_LOAD, TBG_OUT(file), TBG_END, TBG_PLAN, TBG_RANGES="lo-hi,lo-hi" (hex WRAM offsets) package.path = "/home/siege/Projects/tbg/re/lua/?.lua;" .. package.path local L = require("mech_lib") local last = tonumber(os.getenv("TBG_END") or "600") local plan = L.plan(os.getenv("TBG_PLAN")) local ranges = {} for a, b in os.getenv("TBG_RANGES"):gmatch("(%x+)-(%x+)") do ranges[#ranges + 1] = {tonumber(a, 16), tonumber(b, 16)} end local frame, held, holdLeft, running = 0, nil, 0, false local h = io.open(os.getenv("TBG_OUT"), "w") L.load(os.getenv("TBG_LOAD"), function() running = true end) emu.addEventCallback(L.guard(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(L.guard(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 local parts = {string.format("%05d", frame), (held and holdLeft > 0) and held or "-"} for _, r in ipairs(ranges) do local s = {} for i = r[1], r[2] do s[#s + 1] = string.format("%02X", emu.read(i, emu.memType.snesWorkRam)) end parts[#parts + 1] = table.concat(s) end h:write(table.concat(parts, " "), "\n") if frame >= last then h:close(); emu.stop(0) end end), emu.eventType.endFrame)