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)
end
Class = function()
return setmetatable({}, {__call = function(self, ...)
Class = function(inherit)
return setmetatable({}, {
__call = function(self, ...)
local obj = setmetatable({}, {__index = self})
obj:init(...)
return obj
end})
end,
__index = inherit,
})
end
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 "addrs.init"
require "classes"
local ignore = {
-- every time a scene (un)loads
@ -21,23 +22,7 @@ local ignore = {
['28,2=1 (weg)'] = true,
}
function poop(x, x1, i, name)
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()
FlagMonitor = Class(Monitor)
function FlagMonitor:init(name, a)
self.name = name
self.begin = a.addr
@ -46,21 +31,19 @@ function FlagMonitor:init(name, a)
self.old_bytes = {}
end
function FlagMonitor: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
poop(x, x1, i, self.name)
function FlagMonitor:mark(i, x, x1)
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, self.name)
if not ignore[str] then
printf('%s @%i', str, now)
gui.addmessage(str)
end
end
end
self.old_bytes = bytes
self.once = true
end
local weg = FlagMonitor('weg', addrs.week_event_reg)

View file

@ -1,5 +1,6 @@
require "boilerplate"
require "addrs.init"
require "classes"
require "serialize"
local blocknames = {
@ -21,7 +22,7 @@ function butts(ih)
return block, page, row
end
ShortMonitor = Class()
ShortMonitor = Class(Monitor)
function ShortMonitor:init(name, a)
self.name = name
self.begin = a.addr
@ -33,23 +34,6 @@ function ShortMonitor:init(name, a)
self.dirty = false
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)
local ih = math.floor(i/2)
if not self.modified[ih] then
@ -67,7 +51,7 @@ function ShortMonitor:dump()
local block, page, row = butts(ih)
local mod = self.modified[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)
buff = buff..s
end