Pretty-print display when not in debug mode
This commit is contained in:
parent
edad8c17e1
commit
01be57f772
16
display.js
16
display.js
|
|
@ -1,9 +1,23 @@
|
||||||
const { POINTER_TO_START_OF_DISPLAY_MEM } = require('./machine.config');
|
const { POINTER_TO_START_OF_DISPLAY_MEM } = require('./machine.config');
|
||||||
const { num2hex } = require('./logging.js');
|
const { num2hex } = require('./logging.js');
|
||||||
|
|
||||||
exports.printDisplay = (mem) => {
|
const printDisplay = (mem) => {
|
||||||
const disp = mem[POINTER_TO_START_OF_DISPLAY_MEM];
|
const disp = mem[POINTER_TO_START_OF_DISPLAY_MEM];
|
||||||
|
console.log("DISP", disp);
|
||||||
for (let i = disp; i < disp + 16; i += 4) {
|
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])}`);
|
console.log(`${num2hex(mem[i])} ${num2hex(mem[i+1])} ${num2hex(mem[i+2])} ${num2hex(mem[i+3])}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
|
@ -198,7 +198,11 @@ exports.runProgram = async (code, debug = false) => {
|
||||||
async function logCPUState(debug = false) {
|
async function logCPUState(debug = false) {
|
||||||
console.group(`Step`);
|
console.group(`Step`);
|
||||||
if (!debug) console.clear();
|
if (!debug) console.clear();
|
||||||
|
if (debug) {
|
||||||
display.printDisplay(CPU.memory);
|
display.printDisplay(CPU.memory);
|
||||||
|
} else {
|
||||||
|
display.prettyPrintDisplay(CPU.memory);
|
||||||
|
}
|
||||||
console.log();
|
console.log();
|
||||||
console.log('Mnemonic:', CPU.currentInstruction.mnemonic);
|
console.log('Mnemonic:', CPU.currentInstruction.mnemonic);
|
||||||
console.log(`Machine: $${num2hex(CPU.currentInstruction.opcode)} $${num2hex(CPU.currentInstruction.argument)}`);
|
console.log(`Machine: $${num2hex(CPU.currentInstruction.opcode)} $${num2hex(CPU.currentInstruction.argument)}`);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue