-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemulator.js
63 lines (59 loc) · 1.8 KB
/
emulator.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
/**
* monitor the emulator
*/
let Emulator = {
'monitor': undefined,
'pid': -1,
'status': undefined,
'inBasic': true
}
function emulator_run()
{
if (Emulator.timer == undefined) {
Emulator.timer = setInterval(emulator_check, 100)
}
}
function emulator_check()
{
let remote = "http://localhost:9009/emulator";
fetch (remote, {
method: 'GET',
mode: "cors"
})
.then ( response => response.json())
.then ( json => {
switch (Emulator.status) {
case undefined:
case "disconnected":
Emulator.status = "connected"
Emulator.inBasic = json.inBasic
cpu_run()
debug_activate()
break
}
if (Emulator.pid < 0) {
// we are just starting, download breakpoints from the emulator
Emulator.pid = json.pid
breakpoints_load()
dock_disasm(0, 0) // reload the asm code
}
else if (json.pid != Emulator.pid) {
// we are speaking to a new emulator, prabably the user closed the emulator
Emulator.pid = json.pid
dock_disasm(cpu.currentBank, cpu.pc) // reload the asm code
breakpoints_upload() // upload breakpoints to a new emulator
if (Emulator.inBasic) {
debug_run() // and restart the prg
}
}
})
.catch (error => {
console.log(error)
// suspend all components when the emulator is unavailable
if (Emulator.status != "disconnected") {
Emulator.status = "disconnected"
cpu_pause() // suspend cpu monitoring
debug_deactivate() // deactivate all features on the debugbar
}
})
}