1
0
Fork 0
mirror of https://github.com/notwa/mm synced 2024-11-04 20:09:03 -08:00
mm/Lua/classes.lua

45 lines
1,023 B
Lua
Raw Normal View History

2015-05-03 10:37:45 -07:00
require "serialize"
2015-05-01 08:40:32 -07:00
Monitor = Class()
function Monitor:init(name, a)
self.name = name
self.begin = a.addr
self.len = a.type
self.once = false
self.old_bytes = {}
2015-05-03 10:37:45 -07:00
self.modified = {}
self.dirty = false
2015-05-01 08:40:32 -07:00
end
function Monitor:diff()
2015-05-01 09:37:56 -07:00
-- bizhawk has an off-by-one bug where this returns length + 1 bytes
local bytes = mainmemory.readbyterange(self.begin, self.len-1)
2015-05-01 08:40:32 -07:00
local old_bytes = self.old_bytes
if self.once then
for k, v in pairs(bytes) do
local i = tonumber(k) - self.begin
local x = tonumber(v)
local x1 = tonumber(old_bytes[k])
if x ~= x1 then
self:mark(i, x, x1)
end
end
end
self.old_bytes = bytes
self.once = true
end
2015-05-03 10:37:45 -07:00
function Monitor:load(fn)
self.modified = deserialize(fn) or {}
self.dirty = false
self.fn = fn
end
function Monitor:save(fn)
if self.dirty then
serialize(fn or self.fn, self.modified)
self.dirty = false
end
end