diff --git a/src/assembler.js b/src/assembler.js index ae2d503..1ec4981 100755 --- a/src/assembler.js +++ b/src/assembler.js @@ -2,7 +2,8 @@ const fs = require('fs'); -const { logMemory, num2hex } = require('./logging.js'); +const { logMemory } = require('./logging.js'); +const { num2hex } = require('./conversions.js'); const DBG = require('./dbg.js'); const CFG = require('./machine.config.js'); diff --git a/src/cardiograph.js b/src/cardiograph.js index 49cf372..e25c921 100755 --- a/src/cardiograph.js +++ b/src/cardiograph.js @@ -1,7 +1,7 @@ #!/usr/bin/env node const DBG = require('./dbg.js'); -const { num2hex, bool2bit } = require('./logging.js'); +const { num2hex, bool2bit } = require('./conversions.js'); const CFG = require('./machine.config.js'); const CPU = require('./cpu.js'); @@ -16,7 +16,6 @@ main(); async function main() { const input = await readPipedStdin(); - dbg.nit('input: \n', input); const debuggable = true; // FIXME - Get this as a command line flag instead // if debuggable === true, the input is JSON {sourceInfo, machineCode} diff --git a/src/cpu.js b/src/cpu.js index c66fa69..9e40913 100644 --- a/src/cpu.js +++ b/src/cpu.js @@ -1,4 +1,4 @@ -const { num2hex } = require('./logging.js'); +const { num2hex } = require('./conversions.js'); module.exports = class CPU { diff --git a/src/logging.js b/src/logging.js index a8ca701..7b5fbf5 100644 --- a/src/logging.js +++ b/src/logging.js @@ -1,3 +1,5 @@ +let { num2hex } = require('./conversions.js'); + /** * Display a table of memory locations. * Call with [start] and [end] indices to display a range. @@ -38,54 +40,7 @@ const logRunningHeader = () => { console.log( `└─────────────────────┘`); } -/** - * @param {number} num - * @returns {string} - */ -const num2hex = (num) => num.toString(16).toUpperCase().padStart(2, "0"); - -/** - * @param {string} hex - * @returns {number} - */ -const hex2num = (hex) => parseInt(hex, 16); - -/** - * Convert a number to binary, padded to 8 bits - * See here for an explanation: https://stackoverflow.com/questions/9939760/how-do-i-convert-an-integer-to-binary-in-javascript - * @param {number} num - * @returns {string} binary representation of the input - **/ -const num2bin = (num) => (num >>> 0).toString(2).padStart(8, "0"); - -/** - * Convert a number to binary, padded to 4 bits - * See here for an explanation: https://stackoverflow.com/questions/9939760/how-do-i-convert-an-integer-to-binary-in-javascript - * @param {number} num - * @returns {string} binary representation of the input - **/ -const num2bin_4bit = (num) => (num >>> 0).toString(2).padStart(4, "0"); - -/** - * @param {string} bin - * @returns {number} - */ -const bin2num = (bin) => parseInt(bin, 2) - -/** - * @param {Boolean} bool - * @returns {0|1} - **/ -const bool2bit = (bool) => bool ? 1 : 0; - - module.exports = { "logMemory": logMemory, "logRunningHeader": logRunningHeader, - "num2hex": num2hex, - "hex2num": hex2num, - "num2bin": num2bin, - "num2bin_4bit": num2bin_4bit, - "bin2num": bin2num, - "bool2bit": bool2bit, } \ No newline at end of file