-- Probe: log DMA/HDMA channel setups for a few battle frames (find the OAM shadow buffer and HDMA usage). local L = dofile(os.getenv("TBG_LIB")) local out = os.getenv("TBG_OUT") local M = emu.memType.snesMemory local log = io.open(out .. "/probe.txt", "w") local frame = 0 local function onWrite(reg, fn) for _, base in ipairs({0x00, 0x80}) do for bank = base, base + 0x3F do local a = (bank << 16) | reg emu.addMemoryCallback(fn, emu.callbackType.write, a, a) end end end for _, r in ipairs({0x420B, 0x420C}) do onWrite(r, function(a, v) for ch = 0, 7 do if (v >> ch) & 1 == 1 then local b = 0x4300 + ch * 16 log:write(string.format("f%04d %04X ch%d ctl=%02X bb=%02X src=%02X%02X%02X n=%02X%02X pc=%06X\n", frame, a & 0xFFFF, ch, emu.read(b, M), emu.read(b + 1, M), emu.read(b + 4, M), emu.read(b + 3, M), emu.read(b + 2, M), emu.read(b + 6, M), emu.read(b + 5, M), L.pc())) end end end) end L.load(os.getenv("TBG_LOAD")) emu.addEventCallback(function() frame = frame + 1 if frame >= 4 then log:close(); emu.stop(0) end end, emu.eventType.endFrame)