-- Log sound-dispatcher calls (88:8000) while battle_power.lua forces a P1 cast. Same env as battle_power.lua. local out = os.getenv("TBG_OUT") local log = io.open(out .. "/snd_calls.txt", "w") local frame = 0 emu.addEventCallback(function() frame = frame + 1 end, emu.eventType.endFrame) emu.addMemoryCallback(function() local s = emu.getState() local sp = s["cpu.sp"] local ret = emu.read((sp + 1) & 0xFFFF, emu.memType.snesMemory) | (emu.read((sp + 2) & 0xFFFF, emu.memType.snesMemory) << 8) | (emu.read((sp + 3) & 0xFFFF, emu.memType.snesMemory) << 16) log:write(string.format("%d CALL A=%04X X=%04X Y=%04X from=%06X\n", frame, s["cpu.a"], s["cpu.x"], s["cpu.y"], ret)) log:flush() end, emu.callbackType.exec, 0x888000, 0x888000, emu.cpuType.snes) local plog = io.open(out .. "/ports.txt", "w") for _, bank in ipairs({0x00, 0x80, 0x81, 0x82, 0x83, 0x84, 0x86, 0x88}) do emu.addMemoryCallback(function(addr, value) local s = emu.getState() plog:write(string.format("%d W %04X=%02X pc=%02X%04X\n", frame, addr & 0xFFFF, value, s["cpu.k"], s["cpu.pc"])) end, emu.callbackType.write, (bank << 16) + 0x2140, (bank << 16) + 0x2143, emu.cpuType.snes) end local dumps = {} for f in (os.getenv("SND_DUMPS") or ""):gmatch("%d+") do dumps[tonumber(f)] = true end emu.addEventCallback(function() if dumps[frame] then local t = {} for i = 0, 0xFFFF do t[#t + 1] = string.char(emu.read(i, emu.memType.spcRam)) end local h = io.open(string.format("%s/spc_%d.ram", out, frame), "wb"); h:write(table.concat(t)); h:close() t = {} for i = 0, 0x7F do t[#t + 1] = string.char(emu.read(i, emu.memType.spcDspRegisters)) end h = io.open(string.format("%s/spc_%d.dsp", out, frame), "wb"); h:write(table.concat(t)); h:close() end end, emu.eventType.endFrame) dofile(os.getenv("SND_BATTLE_POWER"))