From 30dff10c7e8e5725d8f890839317ae9b116956e9 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sat, 25 Apr 2015 23:54:04 -0700 Subject: [PATCH] abstract to FlagMonitor class --- Lua/boilerplate.lua | 8 ++++++++ Lua/event flag monitor.lua | 29 +++++++++++++++++------------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Lua/boilerplate.lua b/Lua/boilerplate.lua index c1cbf87..daa72a1 100755 --- a/Lua/boilerplate.lua +++ b/Lua/boilerplate.lua @@ -54,6 +54,14 @@ function A(addr, atype) }, mt) end +Class = function() + return setmetatable({}, {__call = function(self, ...) + local obj = setmetatable({}, {__index = self}) + obj:init(...) + return obj + end}) +end + function printf(fmt, ...) print(fmt:format(...)) end diff --git a/Lua/event flag monitor.lua b/Lua/event flag monitor.lua index b3db28e..1333534 100644 --- a/Lua/event flag monitor.lua +++ b/Lua/event flag monitor.lua @@ -1,9 +1,5 @@ require "boilerplate" -function Butts(name, begin, len) - return {name=name, begin=begin, len=len, once = false, old_bytes = {}} -end - local ignore = { -- every time a scene (un)loads ['92,7=0 (weg)'] = true, @@ -39,8 +35,17 @@ function poop(x, x1, i, name) end end --- obvious todo: use actual classes/objects -function diff(self) +FlagMonitor = Class() + +function FlagMonitor:init(name, begin, len) + self.name = name + self.begin = begin + self.len = len + self.once = false + 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 @@ -58,12 +63,12 @@ function diff(self) end -- US 1.0 addresses for the time being -local region1 = Butts('weg', 0x1F0568, 100) -- week_event_reg -local region2 = Butts('inf', 0x1F067C, 8) -- event_inf -local region3 = Butts('mmb', 0x1F3F3A, 8) -- mask_mask_bit (bad address?) +local weg = FlagMonitor('weg', 0x1F0568, 100) -- week_event_reg +local inf = FlagMonitor('inf', 0x1F067C, 8) -- event_inf +local mmb = FlagMonitor('mmb', 0x1F3F3A, 8) -- mask_mask_bit (bad address?) while true do - diff(region1) - diff(region2) - diff(region3) + weg:diff() + inf:diff() + mmb:diff() emu.frameadvance() end