forked from jscinoz/optimus-vfio-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit-rom.js
More file actions
executable file
·36 lines (23 loc) · 736 Bytes
/
split-rom.js
File metadata and controls
executable file
·36 lines (23 loc) · 736 Bytes
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
#!/usr/bin/env node
const fs = require("fs");
const buf = fs.readFileSync("960m.bin");
const slices = [];
slices[0] = buf.slice(0, 2**15);
slices[1] = buf.slice(2**15, 2**16);
slices[2] = buf.slice(2**16, 2**15 + 2**16);
slices[3] = buf.slice(2**15 + 2**16, buf.length);
const ITEMS_PER_LINE = 10;
slices.forEach((slice, sliceIdx) => {
const lines = slice.reduce((acc, x, i) => {
const lineIdx = Math.floor(i / ITEMS_PER_LINE);
let line = acc[lineIdx];
if (!line) {
line = [];
acc[lineIdx] = line;
}
line.push(`0x${x.toString(16).padStart(2, "0")}`);
return acc;
}, []);
const str = lines.map(line => line.join(", ")).join(",\n");
fs.writeFileSync(`slice-${sliceIdx}`, str);
});