forked from LonelehKitten/AssemblerSimulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
100 lines (87 loc) · 2.3 KB
/
test.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
const { app } = require('electron');
app.commandLine.appendSwitch('js-flags', '--max-old-space-size=4096');
const bindings = require('bindings')
const EventEmitter = require('events');
let asmr;
try {
asmr = bindings('ASMR') ?? null; // Pega o ASMR se ele estiver compilado
} catch (e) {
asmr = null;
console.log(e);
}
console.log("Module C++: ", asmr != null);
const isAsmr = asmr != null;
if (isAsmr) asmr.init();
const emitter = new EventEmitter();
let playing = false;
let MacroExpandedEventObserver = null;
let CycleEventObserver = null;
let LogEventObserver = null;
let ProgramToMemoryEventObserver = null;
// Eventos
emitter.on('macroExpanded', (data) => {
console.log("macro Expand");
clearInterval(MacroExpandedEventObserver)
playing = false;
});
emitter.on("programToMemory", (data) => {
const text = [];
for (let i = 0; i < data.length; i += 2) {
text.push((data[i].toString(16).padStart(2, 0) + data[i + 1].toString(16).padStart(2, 0)));
}
console.log("init memory");
clearInterval(ProgramToMemoryEventObserver)
CycleEventObserver = setInterval(() => asmr.observeCycleFiring(getEmitter()), 10);
});
emitter.on('cycle', (data) => {
if (data === "halt") {
playing = false;
clearInterval(CycleEventObserver);
console.log("end");
return;
}
console.log('on cycle:', data);
const response = JSON.parse(data);
console.log(response);
});
emitter.on('log', (data) => {
console.log(data);
});
const getEmitter = () => emitter.emit.bind(emitter);
LogEventObserver = setInterval(() => asmr?.observeLogFiring(getEmitter()), 10);
const memoryChanges = [];
for (let b = 0; b < 128; b++) {
for (let i = 0; i < 32; i++) {
for (let j = 0; j < 16; j++) {
memoryChanges.push(parseInt(0).toString('16').padStart(4, 0));
}
}
}
const run = () => {
/*
asmr.requestAssembleAndRun(`
ADD AX, 1022
ADD AX, AX
SUB AX, 511
SUB AX, 511
JZ 9
SUB AX, 511
JMP -14
INT 2
`, memoryChanges);*/
asmr.requestAssembleAndRun(`
Dados SEGMENT
Mem1 DW ?
Mem2 DW ?
Dados ENDS
Codigo SEGMENT
ASSUME CS:Codigo
ASSUME DS:Dados
Inicio:
mov Mem1, AX
Codigo ENDS
END Inicio
`, memoryChanges);
ProgramToMemoryEventObserver = setInterval(() => asmr.observeProgramToMemoryFiring(getEmitter()), 10);
}
run();