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
|
|
|
|
|
2015-05-14 00:50:47 -07:00
|
|
|
function Monitor:read()
|
2015-05-01 09:37:56 -07:00
|
|
|
-- bizhawk has an off-by-one bug where this returns length + 1 bytes
|
2015-05-14 00:50:47 -07:00
|
|
|
local raw = mainmemory.readbyterange(self.begin, self.len-1)
|
|
|
|
local bytes = {}
|
|
|
|
local begin = self.begin
|
|
|
|
for k, v in pairs(raw) do
|
|
|
|
bytes[k - begin] = v
|
|
|
|
end
|
|
|
|
return bytes
|
|
|
|
end
|
|
|
|
|
|
|
|
function Monitor:diff()
|
|
|
|
local bytes = self:read()
|
2015-05-01 08:40:32 -07:00
|
|
|
local old_bytes = self.old_bytes
|
|
|
|
if self.once then
|
2015-05-14 00:50:47 -07:00
|
|
|
for i, v in pairs(bytes) do
|
2015-05-03 12:25:18 -07:00
|
|
|
local x = v
|
2015-05-14 00:50:47 -07:00
|
|
|
local x1 = old_bytes[i]
|
2015-05-01 08:40:32 -07:00
|
|
|
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
|
2015-05-03 16:46:09 -07:00
|
|
|
|
|
|
|
InputHandler = Class()
|
|
|
|
function InputHandler:init(binds)
|
|
|
|
self.binds = binds
|
|
|
|
self.old_ctrl = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
function InputHandler:update()
|
|
|
|
local ctrl = {}
|
|
|
|
local pressed = {}
|
|
|
|
local j = joypad.getimmediate()
|
|
|
|
for k, v in pairs(self.binds) do
|
|
|
|
ctrl[k] = j[v]
|
|
|
|
end
|
|
|
|
for k, v in pairs(ctrl) do
|
|
|
|
pressed[k] = ctrl[k] and not self.old_ctrl[k]
|
|
|
|
end
|
|
|
|
self.old_ctrl = ctrl
|
|
|
|
return ctrl, pressed
|
|
|
|
end
|