const { POINTER_TO_START_OF_DISPLAY_MEM } = require('./machine.config'); const { num2hex } = require('./logging.js'); /** * Print the contents of display memory as hex number * @param {Uint8Array} mem - CPU memory **/ const printDisplay = (mem) => { const disp = mem[POINTER_TO_START_OF_DISPLAY_MEM]; for (let i = disp; i < disp + 16; i += 4) { console.log(`${num2hex(mem[i])} ${num2hex(mem[i+1])} ${num2hex(mem[i+2])} ${num2hex(mem[i+3])}`); } } /** * Print the contents of display memory using black and white emoji circles * @param {Uint8Array} mem - CPU memory **/ const prettyPrintDisplay = (mem) => { const disp = mem[POINTER_TO_START_OF_DISPLAY_MEM]; const num2pic = (n) => n > 0 ? '⚫' : '⚪'; for (let i = disp; i < disp + 16; i += 4) { console.log(`${num2pic(mem[i])}${num2pic(mem[i+1])}${num2pic(mem[i+2])}${num2pic(mem[i+3])}`); } } module.exports = { "printDisplay": printDisplay, "prettyPrintDisplay": prettyPrintDisplay, }