diff --git a/logging.js b/logging.js index c97f140..9695d4d 100644 --- a/logging.js +++ b/logging.js @@ -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(`└────────┴────────┴────────┘`); diff --git a/readme.md b/readme.md index eb9ee32..bd85afe 100644 --- a/readme.md +++ b/readme.md @@ -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