let { num2hex } = require('./conversions.js'); /** * Display a table of memory locations. * Call with [start] and [end] indices to display a range. * @param {Uint8Array} mem - Memory to display * @param {number} [start] - A start-index, in decimal * @param {number} [end] - An end-index, in decimal **/ const logMemory = (mem, start=0, end=mem.length) => { 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.log(`│ ${num2hex(i)} ${num2hex(i+1)} │ ${num2hex(mem[i])} │ │`); } else { console.log(`│ ${num2hex(i)} ${num2hex(i+1)} │ ${num2hex(mem[i])} │ ${num2hex(operand)} │`); } // Add a blank row every 4 lines: let rowNum = i - start + 2; // Not actually the row number... if ((rowNum % 8 === 0) && (i < (mem.length - 2))) { console.log(blnk); } } console.log(bot1); } const logRunningHeader = () => { console.log(); let time = new Date(); console.log( `┌─────────────────────┐`); console.log( `│ Running at ${time.toLocaleTimeString('en-GB')} │` ); console.log( `└─────────────────────┘`); } module.exports = { "logMemory": logMemory, "logRunningHeader": logRunningHeader, }