local conditions = {} -- Util local function tohex(n, size) size = size or 2 return string.format("$%0" .. tostring(size) .. "X", n) end local function call_for_each_bank(address, fn, ...) for i = 0x00, 0xFF do fn(bit.lshift(i, 16) + address, unpack(arg)) end end -- Execute/writes local function ai_changed(addr, size) assert(size == 2) local val = memory.readwordunsigned(addr) local deathlunges = memory.readwordunsigned(0x7E800A) local condstr = '' if conditions[4] then condstr = 'higher' elseif conditions[3] then condstr = 'behind' elseif conditions[2] then condstr = 'wall' elseif conditions[1] then condstr = 'spin' end conditions = {} if condstr ~= '' then condstr = ' (' .. condstr .. ')' end local line = "[" .. tohex(memory.getregister("pb"), 2) .. ":" .. tohex(memory.getregister("pc"), 4) .. "] " .. tohex(addr, 6) .. "[" .. tostring(size) .. "] = " .. tohex(val, size == 1 and 2 or 4) .. (size == 1 and " | " or " | ") .. " F=" .. emu.framecount() .. " L=" .. tohex(deathlunges, 2) .. condstr print(line) end local function plm_changed(addr, size) assert(size == 2) local val = memory.readwordunsigned(addr) print('PLM', tohex(val), val == 0xE73A and 'FIREBALL' or '') end local function speed_changed(addr, size) assert(size == 2) local val = memory.readwordunsigned(addr) if val > 0x600 then print("OMG: ", tohex(memory.getregister("pb"), 2) .. ":" .. tohex(memory.getregister("pc"), 4)) end end call_for_each_bank(0x0000, function (bank_only) memory.registerwrite(bank_only + 0x0FA8, 0x2, ai_changed) -- memory.registerwrite(bank_only + 0x0F92, 0x2, plm_changed) -- memory.registerwrite(bank_only + 0x0FAC, 0x2, speed_changed) end) -- BAB7 conditions memory.registerexecute(0xA6BABA, function() conditions[1] = true end) memory.registerexecute(0xA6BAC0, function() conditions[2] = true end) memory.registerexecute(0xA6BAE5, function() conditions[3] = true end) memory.registerexecute(0xA6BAF2, function() conditions[4] = true end) memory.registerexecute(0xA6BAF4, function() conditions = {} end) -- Main print('init', tohex(memory.readwordunsigned(0x7E0FA8))) while true do snes9x.frameadvance() end