-
Notifications
You must be signed in to change notification settings - Fork 3
/
addon.js
133 lines (115 loc) · 2.83 KB
/
addon.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
const asmr = require('./build/Release/ASMR.node')
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);
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(JSON.parse(data));
});
const getEmitter = () => emitter.emit.bind(emitter);
LogEventObserver = setInterval(() => asmr?.observeLogFiring(getEmitter()), 10);
const run = () => {
const params = [`
Dados SEGMENT
Var1 DW 5
Var2 DW 8
Var3 DW 3
Dados ENDS
Codigo SEGMENT
ASSUME CS: Codigo
ASSUME DS: Dados
SomaMem MACRO Mem1, Mem2 ;; Soma duas variáveis
mov AX,Mem1
push AX
mov AX,Mem2
mov DX,AX
pop AX
add AX,DX
mov Mem1,AX
ENDM
Inicio:
mov AX, Dados
mov DS, AX
mov AX,2
mov AX, DX
mul DX
SomaMem Var1,V
mov AX, Var1
add AX, DX
mov Var2, AX
SomaMem Var1, 3
SomaMem Var1, Var3
CODIGO ENDS
END Inicio
`,[]];
const type = "requestAssembleAndRun";
asmr[type].apply(asmr,params)
ProgramToMemoryEventObserver = setInterval(() => asmr.observeProgramToMemoryFiring(getEmitter()), 10);
}
run();
/*
'use strict';
const EventEmitter = require('events').EventEmitter;
const addon = require('bindings')('ASMR.node');
//const addon = require('./build/Release/ASMR.node');
const emitter = new EventEmitter();
/*
let myPromise = new Promise(function(myResolve, myReject) {
addon.requestTest();
myResolve(); // when successful
myReject(); // when error
});
myPromise.then(
function(value) { },
function(error) { }
);
addon.requestEndTest();
*
emitter.on("log", (data) => {
console.log(JSON.parse(data).message);
})
addon.init(emitter.emit.bind(emitter));
console.log("-- post init")
addon.requestEndTest();
console.log("-- referencial")*/