-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdock-vram.js
164 lines (148 loc) · 4.03 KB
/
dock-vram.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
"use strict";
let Vram = {
'addr' : 0,
'prev' : {
'addr': 0,
'bytes': undefined
},
'start': 0
}
$(function() {
$.contextMenu({
selector: '.brk_vram',
callback: function(key, options) {
let id = $(this).attr('id').substring(5)
let addr = parseInt(id)
switch (key) {
case 'ubyte':
case 'byte':
vram_toggleWatch(addr, 1)
break;
case 'uword':
case 'word':
vram_toggleWatch(addr, 2)
break;
case 'ulong':
case 'long':
vram_toggleWatch(addr, 4)
break;
}
},
items: {
"ubyte": {name: "Monitor as byte"},
"uword": {name: "Monitor as word"},
"ulong": {name: "Monitor as long"},
}
});
});
/**
* create a new dock
*/
function new_dock_vram()
{
const html='<div class="vram-menu"><input type="text" id="vdump" name="dmp" required minlength="4" maxlength="4" size="10" onkeypress="vram_dump(event)"/></div><div id="vram" style="overflow:scroll;"></div>'
dock_new("VRAM", "dock-vram")
let node = $('#dock-vram')
node.html(html)
vram_update()
}
/**
* Display a new vram location
* @param {*} event
*/
function vram_dump(event)
{
if (event.key == "Enter") {
let goto = $('#vdump').val();
goto = parseInt(goto, 16);
dock_vram(goto);
}
}
/**
*
*/
function vram_update()
{
dock_vram(Vram.addr);
}
/**
*
* @param {*} address
* @param {*} bank
* @param {*} len
* @param {*} upload
*/
function vram_toggleWatch(address, len, upload)
{
let bank = (address & 0x10000) >> 16
let addr = (address & 0x0ffff)
let remote = "http://localhost:9009/vwatch/" + bank + "/" + addr
if (len != undefined) {
remote += ("/" + len)
}
fetch (remote, {
method: 'GET',
mode: "cors"
})
.then ( response => response.json())
.then ( json => {
if (json.status == "ok" && upload == undefined) {
// only download the breakpointIF we are not uploading the current breakpoint
breakpoints_load()
vram_update()
}
})
.catch (error => {
console.log(error);
})
}
/**
* Download 256 bytes from vram
* @param {*} bank
* @param {*} address
*/
function dock_vram(address)
{
let remote = "http://localhost:9009/vera/dump/" + address;
fetch (remote, {
method: 'GET',
mode: "cors"
})
.then ( response => response.arrayBuffer())
.then ( buffer => {
let bytes = new Uint8Array( buffer )
let table=$('<table>');
let i = 0;
let prev = (address == Vram.addr && Vram.prev.bytes != undefined)
let clss = undefined
let counter = 0
let current = address
for (let y=0; y<16; y++) {
let tr=$('<tr>');
tr.append("<td class=\"addr\">" + snprintf(current,"%05X") + "</td>");
for (let x=0; x<16; x++) {
let type = bytes[i]
let byte = bytes[i + 1]
clss = "brk_vram"
if (prev && Vram.prev.bytes[i+1] != bytes[i+1]) {
clss += " updated"
}
if (Breakpoints[current] != undefined && Breakpoints[current].type == "vwatch") {
counter = Breakpoints[current].len
}
if (counter > 0) {
clss += " memory-monitor"
counter--
}
tr.append( "<td id=\"vmem_" + current + "\" class=\"" + clss + "\">" + snprintf(byte,"%02X") + "</td>");
i += 2
current++
}
table.append(tr);
}
$('#vram')[0].innerHTML = table[0].outerHTML;
Vram.prev.addr = Vram.addr
Vram.prev.bytes = bytes
Vram.addr = address
})
}