-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdock-asm.js
190 lines (174 loc) · 4.79 KB
/
dock-asm.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
"use strict";
let aDisasm = [];
/**
* create a new dock
*/
function new_dock_disam()
{
const html='<div class="disam-menu"><div id="jump"><input type="text" id="goto" name="goto" required minlength="4" maxlength="4" size="10" onkeypress="clickPress(event)"/></div></div><div id="disam"></div>'
dock_new("Disassembler", "dock-disam")
let node = $('#dock-disam')
node.html(html)
dock_disam_display()
}
/**
* download and disassemble a memory block
* @param {*} bank
* @param {*} address
* @returns
*/
function dock_disasm(bank, address)
{
let remote = "http://localhost:9009/dump/" + bank + "/" + address;
let p = fetch (remote, {
method: 'GET',
mode: "cors"
})
.then ( response => response.arrayBuffer())
.then ( buffer => {
let bytes = new Uint8Array( buffer );
let pc = 0
let asm = {
pc: 0,
start: address,
txt: "",
symbol: undefined,
next: 0
}
let brk=false;
let i = 0;
let newMap = aDisasm.length == 0;
while (asm.next < 253) {
// ignore the last 3 bytes, as the instruction my go over buffer
disam_line(bytes, asm, 0);
brk=false;
if (Breakpoints[asm.pc + asm.start] != undefined) {
brk = true;
}
if (i >= aDisasm.length) {
aDisasm.push({
'addr':asm.pc + asm.start,
'instr':asm.txt,
'symbol': asm.symbol
})
}
else {
aDisasm[i].addr = asm.pc + asm.start;
aDisasm[i].instr = asm.txt;
aDisasm[i].symbol = asm.symbol;
}
asm.pc = asm.next;
i++;
}
dock_disam_display();
return "ok"
})
.catch (error => {
console.log(error);
})
return p
}
/**
* disassemble the memory block
*/
function dock_disam_display()
{
let table=$('<table>');
for (let i=0; i<32; i++) {
let tr=$('<tr>');
let clss = "nobrk";
let addr = aDisasm[i].addr;
let symbol = aDisasm[i].symbol; if (symbol == undefined) symbol = "";
if (addr == cpu.pc) {
if (Breakpoints[addr] != undefined) {
clss = "exec-breakpoint"
}
else {
clss = "exec"
}
cpu.update = aDisasm[i].addr
}
else if (Breakpoints[addr] != undefined) {
clss = "breakpoint"
}
let onclick = "onClick='toggleBreapoint(" + addr + ",0);'"
tr.append("<td class=\""+ clss + "\" " + onclick + "> </td><td class=\"addr\">"+snprintf(aDisasm[i].addr,"%04X")+"</td><td class=\"source-instr\">"+symbol+"</td><td>"+aDisasm[i].instr)+"</td>";
tr.attr("id", "brk" + addr)
table.append(tr);
}
table.attr("class", "code")
$('#disam')[0].innerHTML = table[0].outerHTML;
if (cpu.update) {
cpu.previous_pc = $("#brk" + cpu.update)
cpu.update = false
}
}
/**
* update PC during debugging
* @returns
*/
function dock_disam_update()
{
let id = '#brk'+cpu.pc;
let found = $(id); // PC is on screen ?
if (found.length == 0) {
// jumped page
dock_disasm(0, cpu.pc);
return
}
// clean previous pointer
if (cpu.previous_pc != undefined) {
cpu.previous_pc.removeClass("pc")
let td = cpu.previous_pc.find("td:first-child")
let clss = td.attr("class")
switch (clss) {
case "exec":
td.removeClass(clss);
td.addClass("nobrk");
break;
case "exec-breakpoint":
td.removeClass(clss);
td.addClass("breakpoint");
break;
}
}
// activate new pointer
let td = found.find("td:first-child")
let clss = td.attr("class")
switch (clss) {
case "breakpoint":
td.removeClass(clss);
td.addClass("exec-breakpoint");
break;
case "nobrk":
td.removeClass(clss);
td.addClass("exec");
break;
}
found.addClass("pc")
cpu.previous_pc = found;
}
/**
* Toggle the breakpoint
* @param {*} brk
*/
function disasm_toggleBreakpoint(addr)
{
let id = '#brk' + addr;
let found = $(id); // PC is on screen ?
if (found.length == 0) {
return
}
let td = found.find("td:first-child")
let clss = td.attr("class")
switch (clss) {
case "breakpoint":
td.removeClass(clss);
td.addClass("nobrk");
break;
case "nobrk":
td.removeClass(clss);
td.addClass("breakpoint");
break;
}
}