-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui-draw.js
179 lines (155 loc) · 4.35 KB
/
ui-draw.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
let lastSP = -1;
let byteElements = undefined;
function hideInput() {
$("#input-div").hide();
$("#input-hidden-div").show();
}
function showInput() {
$("#input-div").show();
$("#input-hidden-div").hide();
}
function drawHexOutput(view, len) {
let hexString = "";
for (let i = 0; i < len; i++) {
hexString += ("0" + Number(view[i]).toString(16)).slice(-2).toUpperCase();
}
romTextarea.text(hexString);
}
function drawRAMOutput(view, len, all) {
let i = 0;
if(!byteElements) {
byteElements = $("#RAM-output-div > span");
}
if (all) {
for (let i = 0; i < len; i++) {
let hexByte = ("0" + Number(view[i]).toString(16))
.slice(-2)
.toUpperCase();
$(byteElements[i]).text(hexByte);
}
$(byteElements).removeClass("hilight");
$(byteElements).removeClass("hilight-read");
$(byteElements).removeClass("stack-pointer");
} else {
while ((i = lastClockWrite.pop())) {
let hexByte = ("0" + Number(view[i]).toString(16))
.slice(-2)
.toUpperCase();
$(byteElements[i]).text(hexByte);
}
if(lastRAMWrite.length > 0) {
$("#RAM-output-div > span.hilight").removeClass("hilight");
}
while ((i = lastRAMWrite.pop())) {
let hexByte = ("0" + Number(view[i]).toString(16))
.slice(-2)
.toUpperCase();
$(byteElements[i]).text(hexByte);
$(byteElements[i]).addClass("hilight");
if ($("#followRamWrite-input").is(":checked")) {
$("#RAM-output-div").scrollTop(
$(byteElements[i]).offset().top -
$(byteElements[i])
.parent()
.offset().top
);
}
}
while ((i = lastClockRead.pop())) {
let hexByte = ("0" + Number(view[i]).toString(16))
.slice(-2)
.toUpperCase();
$(byteElements[i]).text(hexByte);
}
if(lastRAMRead.length > 0) {
$("#RAM-output-div > span.hilight-read").removeClass("hilight-read");
}
while ((i = lastRAMRead.pop())) {
let hexByte = ("0" + Number(view[i]).toString(16))
.slice(-2)
.toUpperCase();
$(byteElements[i]).text(hexByte);
$(byteElements[i]).addClass("hilight-read");
if ($("#followRamRead-input").is(":checked")) {
$("#RAM-output-div").scrollTop(
$(byteElements[i]).offset().top -
$(byteElements[i])
.parent()
.offset().top
);
}
}
if(cpu.SP != lastSP) {
lastSP = cpu.SP;
$(byteElements).removeClass("stack-pointer");
$(byteElements[cpu.SP]).addClass("stack-pointer");
}
}
}
function updateRegisters(i) {
let bin = ("00000000" + cpu.memory.view[i].toString(2)).slice(-8);
$("#data-registers-table > tbody > tr:eq(" + i + ") table td").each(function(
index,
elem
) {
$(elem).text(bin[index]);
});
// Special cases
switch (i) {
case 0:
$("#data-registers-table > tbody > tr:eq(2) table th").each(function(
index,
elem
) {
$(elem)
.text("1" === bin[index] ? "O" : "I")
.attr("title", "1" === bin[index] ? "Output" : "Input");
});
break;
case 1:
$("#data-registers-table > tbody > tr:eq(3) table th").each(function(
index,
elem
) {
$(elem)
.text("1" === bin[index] ? "O" : "I")
.attr("title", "1" === bin[index] ? "Output" : "Input");
});
break;
case 4:
$("#data-registers-table > tbody > tr:eq(6) table th").each(function(
index,
elem
) {
$(elem)
.text("1" === bin[index] ? "O" : "I")
.attr("title", "1" === bin[index] ? "Output" : "Input");
});
break;
case 5:
$("#data-registers-table > tbody > tr:eq(7) table th").each(function(
index,
elem
) {
$(elem)
.text("1" === bin[index] ? "O" : "I")
.attr("title", "1" === bin[index] ? "Output" : "Input");
});
break;
case 0x15:
$("#data-registers-table > tbody > tr:eq(0x16) table th").each(function(
index,
elem
) {
$(elem)
.text("1" === bin[index] ? "O" : "I")
.attr("title", "1" === bin[index] ? "Output" : "Input");
});
break;
}
}
function updatePCOutput() {
elementCache.pcRegisterOutput.val(
("0" + Number(cpu.PC).toString(16)).slice(-4).toUpperCase()
);
}