-
Notifications
You must be signed in to change notification settings - Fork 0
/
bus.lua
executable file
·42 lines (40 loc) · 1.33 KB
/
bus.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
local bit = bit or require('bit32')
local bus = setmetatable({
memory_map = {},
--breakpoint = {
-- address = nil,
-- read = false,
-- write = false
--},
connect = function(self, startAddress, module)
local tbl = { startAddress = startAddress, module = module }
for i = startAddress, startAddress + module.size do
self.memory_map[i] = tbl
end
end
}, {
__index = function(self, address)
address = bit.band(address, 0xFFFF)
--if address == self.breakpoint.address and self.breakpoint.read then
-- self.cpu.pause = true
--end
local tbl = self.memory_map[address]
if tbl then
return tbl.module[address - tbl.startAddress]
end
print("Attempted read at unmapped address " .. string.format("%04X", address))
return 0
end,
__newindex = function(self, address, newValue)
--if address == self.breakpoint.address and self.breakpoint.write then
-- self.cpu.pause = true
--end
local tbl = self.memory_map[address]
if tbl then
tbl.module[address - tbl.startAddress] = newValue
return
end
print("Attempted write at unmapped address " .. string.format("%04X", address) .. " with value " .. newValue)
end
})
return bus