forked from compilersoftware/pasmo
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
81 lines (72 loc) · 2.05 KB
/
index.js
File metadata and controls
81 lines (72 loc) · 2.05 KB
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
const Module = require('./dist/pasmo.js');
/**
* Compiles a .TAP file given assembly source input.
* @param asmInput
* @returns {Promise<function>}
*/
export default function compile(asmInput) {
// Prepare args for the pasmo command.
const args = [];
// args.push('-v');
args.push('--tapbas');
args.push('input.asm');
args.push('output.tap');
// Collect output.
const out = [];
// Call the pasmo module with data for command.
return new Promise((resolve, reject) => {
Module({
arguments: args,
asmInput,
out,
resolve,
reject,
print: (text) => {
// console.log(`[stdout] ${text}`);
out.push({type: 'out', text});
},
printErr: (text) => {
// console.log(`[stderr] ${text}`);
out.push({type: 'err', text});
}
});
});
}
/**
* Compiles a .TAP file by adding a loader (in assembly) given a binary input.
* @param binInput
* @returns {Promise<function>}
*/
export function bin2tap(binInput) {
// Prepare args for the pasmo command.
const args = [];
// args.push('-v');
args.push('--tapbas');
args.push('input.asm');
args.push('output.tap');
// Collect output.
const out = [];
// Assembler code to prepare the program.
const asmInput = `ORG 0x8000
INCBIN input.bin
END 0x8000`;
// Call the pasmo module with data for command.
return new Promise((resolve, reject) => {
Module({
arguments: args,
asmInput,
binInput,
out,
resolve,
reject,
print: (text) => {
// console.log(`[stdout] ${text}`);
out.push({type: 'out', text});
},
printErr: (text) => {
// console.log(`[stderr] ${text}`);
out.push({type: 'err', text});
}
});
});
}