cpu / display - Fix/Refactor: Fix CPU status display so that it doesn't crash when JMPing to an address that isn't in the assembly source. Refactor CPU status display to streamline.
This commit is contained in:
parent
edad9ecbb8
commit
ddab8f42c4
15
cpu.js
15
cpu.js
|
|
@ -404,17 +404,16 @@ exports.singleStepProgram = (code, debugInfo, debug = false, prettyPrintDisplay
|
||||||
* @param {Boolean} [debug] - Enable/disable debugging printouts
|
* @param {Boolean} [debug] - Enable/disable debugging printouts
|
||||||
**/
|
**/
|
||||||
function logCPUState(debugInfo, debug = false, prettyPrintDisplay = false) {
|
function logCPUState(debugInfo, debug = false, prettyPrintDisplay = false) {
|
||||||
console.group(`Line ${debugInfo[CPU.previousIP].lineNumber} - Step ${CPU.cycleCounter}`);
|
debugInfo = debugInfo[CPU.previousIP] !== 'undefined' ? debugInfo[CPU.previousIP] : false;
|
||||||
|
console.group(`Step ${CPU.cycleCounter}`);
|
||||||
console.log();
|
console.log();
|
||||||
if (!debug) console.clear();
|
if (!debug) console.clear();
|
||||||
if (debug && !prettyPrintDisplay) {
|
display.show(CPU.memory, prettyPrintDisplay);
|
||||||
display.printDisplay(CPU.memory);
|
console.log();
|
||||||
} else {
|
if (debugInfo) {
|
||||||
display.prettyPrintDisplay(CPU.memory);
|
console.log(`Line ${debugInfo.lineNumber}: ${debugInfo.source}`);
|
||||||
|
console.log();
|
||||||
}
|
}
|
||||||
console.log();
|
|
||||||
console.log(`Line ${debugInfo[CPU.previousIP].lineNumber}: ${debugInfo[CPU.previousIP].source}`);
|
|
||||||
console.log();
|
|
||||||
console.log('Mnemonic:', CPU.currentInstruction.mnemonic);
|
console.log('Mnemonic:', CPU.currentInstruction.mnemonic);
|
||||||
console.log(`Machine: $${num2hex(CPU.currentInstruction.opcode)} $${num2hex(CPU.currentInstruction.operand)}`);
|
console.log(`Machine: $${num2hex(CPU.currentInstruction.opcode)} $${num2hex(CPU.currentInstruction.operand)}`);
|
||||||
console.log();
|
console.log();
|
||||||
|
|
|
||||||
24
display.js
24
display.js
|
|
@ -2,29 +2,21 @@ const { POINTER_TO_DISPLAY } = require('./machine.config');
|
||||||
const { num2hex } = require('./logging.js');
|
const { num2hex } = require('./logging.js');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print the contents of display memory as hex number
|
* Print the contents of display memory
|
||||||
|
* by default, each pixel is shown as a hex number
|
||||||
* @param {Uint8Array} mem - CPU memory
|
* @param {Uint8Array} mem - CPU memory
|
||||||
|
* @param {Boolean} pretty - Display pixels using black and white emoji circles
|
||||||
**/
|
**/
|
||||||
const printDisplay = (mem) => {
|
const printDisplay = (mem, pretty=false) => {
|
||||||
const disp = mem[POINTER_TO_DISPLAY];
|
|
||||||
for (let i = disp; i < disp + 25; i += 5) {
|
|
||||||
console.log(`${num2hex(mem[i])} ${num2hex(mem[i+1])} ${num2hex(mem[i+2])} ${num2hex(mem[i+3])} ${num2hex(mem[i+4])}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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_DISPLAY];
|
const disp = mem[POINTER_TO_DISPLAY];
|
||||||
const num2pic = (n) => n > 0 ? '⚫' : '⚪';
|
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) {
|
for (let i = disp; i < disp + 25; i += 5) {
|
||||||
console.log(`${num2pic(mem[i])} ${num2pic(mem[i+1])} ${num2pic(mem[i+2])} ${num2pic(mem[i+3])} ${num2pic(mem[i+4])}`);
|
console.log(`${fmt(mem[i])} ${fmt(mem[i+1])} ${fmt(mem[i+2])} ${fmt(mem[i+3])} ${fmt(mem[i+4])}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"printDisplay": printDisplay,
|
"show": printDisplay,
|
||||||
"prettyPrintDisplay": prettyPrintDisplay,
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue