-
Notifications
You must be signed in to change notification settings - Fork 1
/
makeautoload.js
37 lines (26 loc) · 927 Bytes
/
makeautoload.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
const fs = require('fs');
const fileName = "autoload.bin";
const outName = "autoload.js";
function makeAutoLoad() {
let s = "// file generated automatically by 'makeutoload.js'. Do not edit\r\n\r\n";
if(!fs.existsSync(fileName)) {
console.log(`${fileName} not found, disabling autoload`);
s += "const autoload = undefined;\r\n";
fs.writeFileSync(outName,s);
process.exit(-1);
}
const bytes = fs.readFileSync(fileName);
s += "const autoload = new Uint8Array([\n ";
bytes.forEach((value, i)=> {
const comma = (i != bytes.length-1) ? ',':'';
const cr = (i % 32 == 31) ? '\n ' : '';
s += `${hex(value)}${comma}${cr}`;
});
s+="]);\r\n";
fs.writeFileSync(outName,s);
console.log(`'${outName}' generated from '${fileName}'`);
}
function hex(value) {
return "0x" + (value<=0xF ? "0":"") + value.toString(16);
}
makeAutoLoad();