From cd525078a74c1585cb020cee9b933c1f2c01dae3 Mon Sep 17 00:00:00 2001 From: nino-porcino Date: Sat, 15 Jan 2022 14:31:00 +0100 Subject: [PATCH] add bin2prg tool --- tools/bin2prg.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tools/bin2prg.js diff --git a/tools/bin2prg.js b/tools/bin2prg.js new file mode 100644 index 0000000..a06135a --- /dev/null +++ b/tools/bin2prg.js @@ -0,0 +1,26 @@ +const fs = require('fs'); +const parseOptions = require("./parseOptions"); + +const options = parseOptions([ + { name: 'input', alias: 'i', type: String }, + { name: 'output', alias: 'o', type: String }, + { name: 'start', alias: 's', type: String } +]); + +if(options.input === undefined || options.output === undefined || options.start === undefined) { + console.log("usage: bin2prg -i inputfile.prg -o outputfile.bin -s hexaddress"); + process.exit(-1); +} + +let bin = fs.readFileSync(options.input); + +let start_address = parseInt(options.start, 16); +let lo = (start_address >> 0) & 0xFF; +let hi = (start_address >> 8) & 0xFF; + +let prg = new Uint8Array([ lo, hi, ...bin ]); + +fs.writeFileSync(options.output, prg); + +console.log(`${options.output} written`); +