Update `logMemory` to add an option to log just a specific range

This commit is contained in:
n loewen 2023-08-03 16:24:18 +01:00
parent 5fa20c3963
commit ea26f5d77b
2 changed files with 15 additions and 4 deletions

View File

@ -1,11 +1,22 @@
const logMemory = (x) => {
const logMemory = (mem, start=0, end=mem.length) => {
// This function can only handle
// an even number of array entries
if ((start % 2) === 1) { start -= 1; }
if ((end % 2) === 1) { end += 1; }
mem = mem.slice(start, end);
console.log(`┌────────┬────────┬────────┐`);
console.log(`│ addr │ op │ arg │`);
console.log(`├────────┼────────┼────────┤`);
for (let i = 0; i < x.length; i += 2) {
console.log(`${num2hex(i)}${num2hex(x[i])}${num2hex(x[i+1])}`);
//for (let i = 0; i < mem.length; i += 2) {
for (let i = start; i < mem.length; i +=2) {
console.log(`${num2hex(i)}${num2hex(mem[i])}${num2hex(mem[i+1])}`);
// Add a blank row every 4 lines:
if (((i + 2) % 8) === 0) {
if ((i < (mem.length - 2))) {
console.log(`│ │ │ │`);
}
}
}
console.log(`└────────┴────────┴────────┘`);

View File

@ -19,7 +19,7 @@
- [x] Make $0F a NOP
- [ ] In assembler.js: validateLabel()
- [ ] In assemble.js: print better output to stdout
- [ ] Add a function for logging just a specific range of memory
- [x] Add a function for logging just a specific range of memory
### Under-the-hood improvements