-
Notifications
You must be signed in to change notification settings - Fork 0
/
Debugger.js
39 lines (31 loc) · 1.32 KB
/
Debugger.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
(() => {
const trace = ({ opName, pcAddr, stack, v }) => {
const currentOpSelector = document.getElementById('currentOp')
const currentOpChild = currentOpSelector.childNodes[0]
if (currentOpChild) {
currentOpSelector.removeChild(currentOpChild)
}
currentOpSelector.append(opName)
const currentPcSelector = document.getElementById('currentPc')
const currentPcChild = currentPcSelector.childNodes[0]
if (currentPcChild) {
currentPcSelector.removeChild(currentPcChild)
}
currentPcSelector.append(pcAddr)
stackRootSelector = document.getElementById('stackRoot')
stackRootSelector.childNodes.forEach((node) => node.innerHTML = '')
stack.slice(0, 3).forEach((addr, i) => {
const stackElem = document.querySelector(`#stackRoot > div:nth-child(${i + 1})`)
stackElem.innerHTML = chip8.lib.dec2hex(addr)
})
vregRootSelector = document.getElementById('vregRoot')
vregRootSelector.childNodes.forEach((node) => node.innerHTML = '')
v.forEach((reg, i) => {
const regElem = document.querySelector(`#vregRoot > div:nth-child(${i + 1})`)
regElem.innerHTML = chip8.lib.dec2hex(reg)
})
}
window.chip8.Debugger = {
trace,
}
})()