From ed14016e2c13538251450e1d0ebb94b06a02f8d1 Mon Sep 17 00:00:00 2001 From: nino-porcino Date: Thu, 13 Jan 2022 13:04:55 +0100 Subject: [PATCH] improve prg2bin, use node_modules --- package.json | 26 ++++++++++++++++++++++++++ tools/parseOptions.js | 12 ++++++++++++ tools/prg2bin.js | 18 +++++++++++++++--- 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 package.json create mode 100644 tools/parseOptions.js diff --git a/package.json b/package.json new file mode 100644 index 0000000..c7fd0cb --- /dev/null +++ b/package.json @@ -0,0 +1,26 @@ +{ + "name": "apple1-videocard-lib", + "version": "1.0.0", + "description": "Library and demos for the \"Apple-1 Graphic Card\" by P-LAB, \r featuring the TMS9918 Video Display Processor by Texas Instruments.", + "main": "index.js", + "directories": { + "doc": "docs", + "lib": "lib" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/nippur72/apple1-videocard-lib.git" + }, + "author": "Antonino Porcino ", + "license": "MIT", + "bugs": { + "url": "https://github.com/nippur72/apple1-videocard-lib/issues" + }, + "homepage": "https://github.com/nippur72/apple1-videocard-lib#readme", + "dependencies": { + "command-line-args": "^5.2.0" + } +} diff --git a/tools/parseOptions.js b/tools/parseOptions.js new file mode 100644 index 0000000..2380d12 --- /dev/null +++ b/tools/parseOptions.js @@ -0,0 +1,12 @@ +const commandLineArgs = require('command-line-args'); + +function parseOptions(optionDefinitions) { + try { + return commandLineArgs(optionDefinitions); + } catch(ex) { + console.log(ex.message); + process.exit(-1); + } + } + + module.exports = parseOptions; diff --git a/tools/prg2bin.js b/tools/prg2bin.js index 417fb6d..5e5ff87 100644 --- a/tools/prg2bin.js +++ b/tools/prg2bin.js @@ -1,9 +1,21 @@ const fs = require('fs'); +const parseOptions = require("./parseOptions"); -let prg = fs.readFileSync("test_apple1.prg"); +const options = parseOptions([ + { name: 'input', alias: 'i', type: String }, + { name: 'output', alias: 'o', type: String } +]); + +if(options.input === undefined || options.output === undefined) { + console.log("usage: prg2bin -i inputfile.prg -o outputfile.bin"); + process.exit(-1); +} + +let prg = fs.readFileSync(options.input); prg = prg.slice(2); -fs.writeFileSync("test_apple1.bin",prg); +fs.writeFileSync(options.output,prg); + +console.log(`${options.output} written`); -console.log("bin written");