diff --git a/issues/todo.md b/issues/todo.md index 6dd1dbc..a410f26 100644 --- a/issues/todo.md +++ b/issues/todo.md @@ -41,6 +41,7 @@ For extended commentary, see [issues](issues.md). ## Closed +- 2023-08-26 - [fix] (logging) - 'undefined operand' situation is caused by assembling to an initial IP of $1C, which is an odd number - (assembler) Pass asm line thru to cpu to print when debugging diff --git a/logging.js b/logging.js index 2e1d581..a662a71 100644 --- a/logging.js +++ b/logging.js @@ -6,26 +6,28 @@ * @param {number} [end] - An end-index, in decimal **/ const logMemory = (mem, start=0, end=mem.length) => { - mem = mem.slice(start, end); - console.log(`┌────────┬────────┬─────────┐`); - console.log(`│ addr │ opcode │ operand │`); - console.log(`├────────┼────────┼─────────┤`); + let top1 = `┌─────────┬────────┬─────────┐`; + let top2 = `│ addrs │ opcode │ operand │`; + let top3 = `├─────────┼────────┼─────────┤`; + let blnk = `│ │ │ │`; + let bot1 = `└─────────┴────────┴─────────┘`; + console.log(`${top1}\n${top2}\n${top3}`); for (let i = start; i < mem.length; i +=2) { let operand = mem[i+1]; if (typeof operand === 'undefined') { - console.warn(' operand undefined'); - operand = -1; + console.log(` ${num2hex(i)} ${num2hex(i+1)} │ ${num2hex(mem[i])} │ │`); + } else { + console.log(`│ ${num2hex(i)} ${num2hex(i+1)} │ ${num2hex(mem[i])} │ ${num2hex(operand)} │`); } - console.log(`│ ${num2hex(i)} │ ${num2hex(mem[i])} │ ${num2hex(operand)} │`); // Add a blank row every 4 lines: - if (((i + 2) % 8) === 0) { - if ((i < (mem.length - 2))) { - console.log(`│ │ │ │`); - } + let rowNum = i - start + 2; // Not actually the row number... + if ((rowNum % 8 === 0) + && (i < (mem.length - 2))) { + console.log(blnk); } } - console.log(`└────────┴────────┴─────────┘`); + console.log(bot1); } const logRunningHeader = () => { diff --git a/run-assembler.js b/run-assembler.js index 12a22f4..57dfb88 100755 --- a/run-assembler.js +++ b/run-assembler.js @@ -8,6 +8,7 @@ const fs = require('fs'); const assembler = require('./assembler.js'); const { logMemory, num2hex, num2bin } = require('./logging.js'); const { machine } = require('os'); +const machineConfig = require('./machine.config.js'); const mode = process.argv[2]; const filename = process.argv[3]; @@ -19,7 +20,7 @@ if (mode === "debug") { assembler_output = assembler.assemble(inputFile_str, true); console.log(''); console.group("Machine code output"); - logMemory(assembler_output.machineCode); + logMemory(assembler_output.machineCode, machineConfig.INITIAL_IP_ADDRESS); console.groupEnd(); } else { assembler_output = assembler.assemble(inputFile_str);