-
Notifications
You must be signed in to change notification settings - Fork 1
/
memxtend.lua
79 lines (72 loc) · 1.57 KB
/
memxtend.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
-- initialize an empty memory bank
function bank_init()
local result = {};
for i = 0, 0xFFFF do
result[i] = 0x0
end
return result
end
-- memory storage locations
local bank = {};
bank[0] = bank_init();
bank[1] = bank_init();
bank[2] = bank_init();
bank[3] = bank_init();
bank[4] = bank_init();
bank[5] = bank_init();
bank[6] = bank_init();
bank[7] = bank_init();
bank[8] = bank_init();
bank[9] = bank_init();
-- interrupt values
local INT_MEM_SWAP = 0;
local INT_MEM_CLONE = 1;
-- swap the current CPU ram with then
-- memory bank.
function bank_swap(cpu, target)
local temp = {};
for i = 0, 0xFFFF do
temp[i] = cpu.ram[i]
end
for i = 0, 0xFFFF do
cpu.ram[i] = target[i]
end
for i = 0, 0xFFFF do
target[i] = temp[i]
end
end
-- clone the current CPU ram into the
-- memory bank.
function bank_clone(cpu, target)
for i = 0, 0xFFFF do
target[i] = cpu.ram[i]
end
end
-- handle interrupt
function interrupt(cpu)
if (cpu.registers.A == INT_MEM_SWAP) then
if (cpu.registers.B < 0x0) or (cpu.registers.B > 0x9) then
bank_corrupt(cpu)
else
bank_swap(cpu, bank[cpu.registers.B]);
end
elseif (cpu.registers.A == INT_MEM_CLONE) then
if (cpu.registers.B < 0x0) or (cpu.registers.B > 0x9) then
bank_corrupt(cpu)
else
bank_clone(cpu, bank[cpu.registers.B]);
end
end
end
MODULE = {
Type = "Hardware",
Name = "MEMXTEND - Physical Memory Extensions",
Version = "0.1",
SDescription = "Physical memory swapping device",
URL = "http://dcputoolcha.in/docs/modules/list/memxtend.html"
};
HARDWARE = {
ID = 0x38f6ab35,
Version = 0x0001,
Manufacturer = 0x00000000
};