-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
74 lines (56 loc) · 1.74 KB
/
index.js
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
let valueRange = new ThrowingRange(
-Math.pow(2, 31), Math.pow(2, 31) - 1, 'Data value out of range'
);
let uiManager = new UIManager();
let clock = new Clock(uiManager);
let mainMemory = new DelegatingMemory([ArrayMemory.forBits(5, valueRange)]);
let screen = new Screen(2, 4, 3, 32, ArrayMemory.forBits(4 + 3, valueRange));
let deviceBus = new ArrayDeviceBus([
screen,
new Drive(ArrayMemory.forBits(8, valueRange))
]);
let screenRenderer = new TableScreenRenderer(document.getElementById('screen-table'));
screenRenderer.link(screen);
uiManager.add(screenRenderer);
let registers = ArrayMemory.forBits(4, valueRange);
let programCounter = new SingleWordMemory(mainMemory.addressRange);
let operations = Operations.TC_06(mainMemory, registers, programCounter, deviceBus);
let controlUnit = new TC_06_ControlUnit(operations, programCounter);
let cpuCore = new TC_06_InstructionUnit(controlUnit, mainMemory, programCounter);
clock.on('tick', () => {
try {
cpuCore.runCycle()
} catch (e) {
console.error('CPU cycle failed', e);
clock.running = false;
}
});
new SystemControls(document.getElementById('system-controls')).link(clock);
let mainMemoryRenderer = new MemoryRenderer(
document.getElementById('main-memory'), uiManager
);
mainMemoryRenderer.link(mainMemory);
uiManager.add(mainMemoryRenderer);
let registersRenderer = new MemoryRenderer(
document.getElementById('registers'), uiManager
);
registersRenderer.link(registers);
uiManager.add(registersRenderer);
[
0x50100000,
0x50210000,
0x50320000,
0x50122000,
0x50212000,
0x50302000,
0x501EC000,
0x501FE000,
0x70200000,
0x10000004,
0x501F0000,
0x10000004,
0x502F0000,
0x48000010,
0x10000000
].forEach((item, index) => mainMemory.write(index, item));
uiManager.triggerRefresh();