Create a memory-mapped-display visualizer that is separate from the CPU debugging printout
This commit is contained in:
parent
3748e7af24
commit
f7c2203450
|
|
@ -10,9 +10,9 @@ const filename = process.argv[2];
|
||||||
const inputFile_str = fs.readFileSync(filename, 'utf8');
|
const inputFile_str = fs.readFileSync(filename, 'utf8');
|
||||||
let machineCode = assembler.assemble(inputFile_str);
|
let machineCode = assembler.assemble(inputFile_str);
|
||||||
|
|
||||||
console.log();
|
// console.group("Machine code output");
|
||||||
console.group("Machine code output");
|
// printMemory.printTable(machineCode);
|
||||||
printMemory.printTable(machineCode);
|
// console.groupEnd('Machine code output');
|
||||||
console.groupEnd('Machine code output');
|
|
||||||
|
|
||||||
computer.runProgram(machineCode);
|
//computer.debugProgram(machineCode);
|
||||||
|
computer.displayProgram(machineCode);
|
||||||
|
|
@ -175,7 +175,7 @@ function stepCPU() {
|
||||||
// console.groupEnd("Step CPU");
|
// console.groupEnd("Step CPU");
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.runProgram = (code) => {
|
exports.debugProgram = (code) => {
|
||||||
CPU.loadMemory(code);
|
CPU.loadMemory(code);
|
||||||
const initialMemory = JSON.parse(JSON.stringify(CPU.memory)); // Hack to make a copy-by-value -- https://stackoverflow.com/questions/18829099/copy-a-variables-value-into-another
|
const initialMemory = JSON.parse(JSON.stringify(CPU.memory)); // Hack to make a copy-by-value -- https://stackoverflow.com/questions/18829099/copy-a-variables-value-into-another
|
||||||
console.log();
|
console.log();
|
||||||
|
|
@ -197,6 +197,19 @@ exports.runProgram = (code) => {
|
||||||
console.groupEnd('Display');
|
console.groupEnd('Display');
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.displayProgram = async (code) => {
|
||||||
|
CPU.loadMemory(code);
|
||||||
|
const initialMemory = JSON.parse(JSON.stringify(CPU.memory)); // Hack to make a copy-by-value -- https://stackoverflow.com/questions/18829099/copy-a-variables-value-into-another
|
||||||
|
CPU.running = true;
|
||||||
|
for (let i = 0; i < CYCLE_LIMIT; i++) { // FIXME: temporary limit as a lazy way to halt infinite loops
|
||||||
|
if (!CPU.running) break;
|
||||||
|
if (CPU.IP >= CPU.memory.length) break;
|
||||||
|
stepCPU();
|
||||||
|
console.clear();
|
||||||
|
display.printDisplay(CPU.memory);
|
||||||
|
logCPUState();
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 75));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue