1
0
Fork 0
mirror of https://github.com/notwa/mm synced 2025-02-05 13:23:23 -08:00

Monitor class; class inheritance

This commit is contained in:
Connor Olding 2015-05-01 08:40:32 -07:00
parent 2c75c55dc3
commit fee7a6f2e2
4 changed files with 50 additions and 54 deletions

View file

@ -54,12 +54,15 @@ function A(addr, atype)
}, mt) }, mt)
end end
Class = function() Class = function(inherit)
return setmetatable({}, {__call = function(self, ...) return setmetatable({}, {
local obj = setmetatable({}, {__index = self}) __call = function(self, ...)
obj:init(...) local obj = setmetatable({}, {__index = self})
return obj obj:init(...)
end}) return obj
end,
__index = inherit,
})
end end
function printf(fmt, ...) function printf(fmt, ...)

26
Lua/classes.lua Normal file
View file

@ -0,0 +1,26 @@
Monitor = Class()
function Monitor:init(name, a)
self.name = name
self.begin = a.addr
self.len = a.type
self.once = false
self.old_bytes = {}
end
function Monitor:diff()
local bytes = mainmemory.readbyterange(self.begin, self.len)
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

View file

@ -1,5 +1,6 @@
require "boilerplate" require "boilerplate"
require "addrs.init" require "addrs.init"
require "classes"
local ignore = { local ignore = {
-- every time a scene (un)loads -- every time a scene (un)loads
@ -21,23 +22,7 @@ local ignore = {
['28,2=1 (weg)'] = true, ['28,2=1 (weg)'] = true,
} }
function poop(x, x1, i, name) FlagMonitor = Class(Monitor)
local now = emu.framecount()
local diff = bit.bxor(x, x1)
for which = 0, 7 do
if bit.band(diff, 2^which) ~= 0 then
local state = bit.band(x, 2^which) ~= 0 and 1 or 0
local str = ('%02i,%i=%i (%s)'):format(i, which, state, name)
if not ignore[str] then
printf('%s @%i', str, now)
gui.addmessage(str)
end
end
end
end
FlagMonitor = Class()
function FlagMonitor:init(name, a) function FlagMonitor:init(name, a)
self.name = name self.name = name
self.begin = a.addr self.begin = a.addr
@ -46,21 +31,19 @@ function FlagMonitor:init(name, a)
self.old_bytes = {} self.old_bytes = {}
end end
function FlagMonitor:diff() function FlagMonitor:mark(i, x, x1)
local bytes = mainmemory.readbyterange(self.begin, self.len) local now = emu.framecount()
local old_bytes = self.old_bytes local diff = bit.bxor(x, x1)
if self.once then for which = 0, 7 do
for k, v in pairs(bytes) do if bit.band(diff, 2^which) ~= 0 then
local i = tonumber(k) - self.begin local state = bit.band(x, 2^which) ~= 0 and 1 or 0
local x = tonumber(v) local str = ('%02i,%i=%i (%s)'):format(i, which, state, self.name)
local x1 = tonumber(old_bytes[k]) if not ignore[str] then
if x ~= x1 then printf('%s @%i', str, now)
poop(x, x1, i, self.name) gui.addmessage(str)
end end
end end
end end
self.old_bytes = bytes
self.once = true
end end
local weg = FlagMonitor('weg', addrs.week_event_reg) local weg = FlagMonitor('weg', addrs.week_event_reg)

View file

@ -1,5 +1,6 @@
require "boilerplate" require "boilerplate"
require "addrs.init" require "addrs.init"
require "classes"
require "serialize" require "serialize"
local blocknames = { local blocknames = {
@ -21,7 +22,7 @@ function butts(ih)
return block, page, row return block, page, row
end end
ShortMonitor = Class() ShortMonitor = Class(Monitor)
function ShortMonitor:init(name, a) function ShortMonitor:init(name, a)
self.name = name self.name = name
self.begin = a.addr self.begin = a.addr
@ -33,23 +34,6 @@ function ShortMonitor:init(name, a)
self.dirty = false self.dirty = false
end end
function ShortMonitor:diff()
local bytes = mainmemory.readbyterange(self.begin, self.len)
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
function ShortMonitor:mark(i, x, x1) function ShortMonitor:mark(i, x, x1)
local ih = math.floor(i/2) local ih = math.floor(i/2)
if not self.modified[ih] then if not self.modified[ih] then
@ -67,7 +51,7 @@ function ShortMonitor:dump()
local block, page, row = butts(ih) local block, page, row = butts(ih)
local mod = self.modified[ih] local mod = self.modified[ih]
local value = R2(self.begin + ih) local value = R2(self.begin + ih)
local vs = mod and '[variable]' or ('%04X'):format(value) local vs = mod and 'n/a' or ('%04X'):format(value)
local s = ('%02X\t%i\t%i\t%s\n'):format(block, page+1, row+1, vs) local s = ('%02X\t%i\t%i\t%s\n'):format(block, page+1, row+1, vs)
buff = buff..s buff = buff..s
end end