1
0
Fork 0
mirror of https://github.com/notwa/mm synced 2024-06-28 21:07:12 -07:00
mm/Lua/oot memory editor monitor.lua

76 lines
1.8 KiB
Lua
Raw Normal View History

2015-05-01 06:16:44 -07:00
require "boilerplate"
require "addrs.init"
2015-05-01 08:40:32 -07:00
require "classes"
require "serialize"
2015-05-01 06:16:44 -07:00
local blocknames = {
'R ', 'RS', 'RO', 'RP',
'RQ', 'RM', 'RY', 'RD',
'RU', 'RI', 'RZ', 'RC',
'RN', 'RK', 'RX', 'Rc',
'Rs', 'Ri', 'RW', 'RA',
'RV', 'RH', 'RG', 'Rm',
'Rn', 'RB', 'Rd', 'Rk',
'Rb',
}
function butts(ih)
local block = math.floor(ih/16/6)
local ir = ih - block*16*6
local page = math.floor(ir/16)
local row = ir - page*16
return block, page, row
end
2015-05-01 08:40:32 -07:00
ShortMonitor = Class(Monitor)
2015-05-01 06:16:44 -07:00
function ShortMonitor:init(name, a)
self.name = name
self.begin = a.addr
self.len = a.type
self.once = false
self.old_bytes = {}
self.modified = {}
self.dirty = false
2015-05-01 06:16:44 -07:00
end
function ShortMonitor:mark(i, x, x1)
local ih = math.floor(i/2)
if not self.modified[ih] then
2015-05-01 06:16:44 -07:00
self.modified[ih] = true
self.dirty = true
2015-05-01 06:16:44 -07:00
local block, page, row = butts(ih)
printf('%2s Page %1i Row %3i', blocknames[block+1], page+1, row+1)
end
end
function ShortMonitor:dump()
local buff = ''
for i=0, self.len/2 - 1 do
local ih = i
local block, page, row = butts(ih)
local mod = self.modified[ih]
local value = R2(self.begin + ih)
2015-05-01 08:40:32 -07:00
local vs = mod and 'n/a' or ('%04X'):format(value)
2015-05-01 09:37:56 -07:00
local name = ('%s%02i'):format(blocknames[block+1], page*16 + row)
local s = ('%s\t%i\t%i\t%s\n'):format(name, page+1, row+1, vs)
2015-05-01 06:16:44 -07:00
buff = buff..s
end
print(buff)
end
-- 2 bytes each, 16 values per page, 6 pages per block, 29 blocks
-- = 5568 bytes (0x15C0)
me = ShortMonitor('me', A(0x210A24, 0x15C0))
me.modified = deserialize('_ootmemod.lua') or {}
2015-05-01 09:37:56 -07:00
while version == "O EUDB MQ" do
2015-05-01 06:16:44 -07:00
me:diff()
if me.dirty then
serialize(me.modified, ('_ootmemod.lua'))
me.dirty = false
end
2015-05-01 06:16:44 -07:00
emu.frameadvance()
end