-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdock-cpu.js
189 lines (169 loc) · 5.28 KB
/
dock-cpu.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
"use strict";
let currentStatus = undefined;
let currentBank = undefined;
let cpu = {
'status': 1,
'previous_pc': undefined,
'pc': undefined,
'a': undefined,
'x': undefined,
'y': undefined,
'timer': undefined,
'registers': Array(5)
}
/**
* Emulator is running, so monitor
*/
function cpu_run()
{
if (cpu.timer == undefined) {
$("#emu").html("Running")
cpu.timer = setInterval(cpu_check, 100)
}
}
/**
* Emulator is paused, stop monitoring
*/
function cpu_pause()
{
$("#emu").html("Paused")
clearInterval(cpu.timer)
cpu.timer = undefined
}
/**
* create a new dock
*/
function new_dock_cpu()
{
const cpuHTML='<table><tr><td>Emu</td><td id="emu">Disconnected</td></tr><tr><td>PC</td><td id="pc"></td></tr><tr><td>SP</td><td id="sp"></td></tr><tr><td>A</td><td id="a"></td></tr><tr><td>X</td><td id="x"></td></tr><tr><td>Y</td><td id="y"></td></tr><tr><td>Flags</td><td id="status"></td></tr></table><div id="registers"></div><div id="vera"></div>'
dock_new("Cpu", "dock-cpu")
let div = $("#dock-cpu")
div.html(cpuHTML)
}
/**
* check the status of the emulator
*/
function cpu_check()
{
let remote = "http://localhost:9009/cpu";
fetch (remote, {
method: 'GET',
mode: "cors"
})
.then ( response => response.json())
.then ( json => {
// reactive run & restart after a network disconnection
if (cpu.status < 0) {
$("#run").removeClass("disabled-link")
$("#restart").removeClass("disabled-link")
}
$('#pc').html(snprintf(json.pc,"%04X"));
$('#sp').html(snprintf(json.sp,"%02X"));
if (json.a != cpu.a) {
$('#a').html(snprintf(json.a,"%02X"));
$('#a').addClass("updated")
cpu.a = json.a
}
else {
$('#a').removeClass("updated")
}
if (json.x != cpu.x) {
$('#x').html(snprintf(json.x,"%02X"));
$('#x').addClass("updated")
cpu.x = json.x
}
else {
$('#x').removeClass("updated")
}
if (json.y != cpu.y) {
$('#y').html(snprintf(json.y,"%02X"));
$('#y').addClass("updated")
cpu.y = json.y
}
else {
$('#y').removeClass("updated")
}
let n = (json.flags & 0x80) ? "N" : "-";
let v = (json.flags & 0x40) ? "V" : "-";
let b = (json.flags & 0x10) ? "B" : "-";
let d = (json.flags & 0x08) ? "D" : "-";
let i = (json.flags & 0x04) ? "I" : "-";
let c = (json.flags & 0x02) ? "Z" : "-";
let z = (json.flags & 0x01) ? "C" : "-";
$('#status').html(n+v+"-"+b+d+i+c+z);
if (json.myStatus == 0) {
// the emulator entered suspended mode
cpu_pause()
}
if (json.myStatus != cpu.status) {
if (json.myStatus == 0) {
// debug buttons are visible
$("#continue").removeClass("disabled-link")
$("#stepinto").removeClass("disabled-link")
$("#stepover").removeClass("disabled-link")
$("#stepout").removeClass("disabled-link")
// intercept debug keys
document.onkeydown = function(evt) {
switch (evt.key) {
case 'F5':
debug_continue()
return false;
case 'F10':
debug_stepover()
return false;
case 'F11':
debug_stepinto()
return false;
}
};
}
else {
// debug buttons are hidden
$("#continue").addClass("disabled-link")
$("#stepinto").addClass("disabled-link")
$("#stepover").addClass("disabled-link")
$("#stepout").addClass("disabled-link")
// release debug keys
document.onkeydown = undefined
}
cpu.status = json.mystatus
}
if (json.myStatus == 0) {
currentBank = json.bank;
cpu.pc = json.pc;
let found = $('#brk' + cpu.pc); // PC is on screen ?
if (found.length == 0) {
// jumped page
dock_disasm(currentBank, cpu.pc);
}
else {
// move PC on screen
dock_disam_update();
}
source_update_pc()
memory_update()
dock_registers()
dock_vera()
watches_update()
tiles_update()
}
})
.catch (error => {
$("#run").addClass("disabled-link")
$("#restart").addClass("disabled-link")
$("#continue").addClass("disabled-link")
$("#stepinto").addClass("disabled-link")
$("#stepover").addClass("disabled-link")
$("#stepout").addClass("disabled-link")
$("#emu").html("Disconnected")
cpu.status = -1
})
}
function clickPress(event)
{
if (event.key == "Enter") {
let goto = $('#goto').val();
goto = parseInt(goto, 16);
dock_disasm(0, goto);
}
}