22 lines
730 B
JavaScript
22 lines
730 B
JavaScript
const { POINTER_TO_DISPLAY } = require('./machine.config');
|
|
const { num2hex } = require('./logging.js');
|
|
|
|
/**
|
|
* Print the contents of display memory
|
|
* by default, each pixel is shown as a hex number
|
|
* @param {Uint8Array} mem - CPU memory
|
|
* @param {Boolean} pretty - Display pixels using black and white emoji circles
|
|
**/
|
|
const printDisplay = (mem, pretty=false) => {
|
|
const disp = mem[POINTER_TO_DISPLAY];
|
|
const num2pic = (n) => n > 0 ? '⚫' : '⚪';
|
|
let fmt = (n) => num2hex(n);
|
|
if (pretty) fmt = (n) => num2pic(n);
|
|
for (let i = disp; i < disp + 25; i += 5) {
|
|
console.log(`${fmt(mem[i])} ${fmt(mem[i+1])} ${fmt(mem[i+2])} ${fmt(mem[i+3])} ${fmt(mem[i+4])}`);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
"show": printDisplay,
|
|
} |