Skip to content

Commit

Permalink
Fix #523: Cpu emulator test runner doesn't recognize asm from assembl…
Browse files Browse the repository at this point in the history
…er page (#525)

fix #523: Test runner of cpu emulator page doesn't execute code that was passed from assembler page

add isEmpty() to Memory class
check for ROM.isEmpty() in cputst.step()

Co-authored-by: Dorian Ignee <[email protected]>
  • Loading branch information
dorianignee and Dorian Ignee authored Dec 5, 2024
1 parent 20f9059 commit 36e768d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions simulator/src/cpu/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ export class Memory implements MemoryAdapter {
[Symbol.iterator](): Iterable<number> {
return this.map((_, v) => v);
}

isEmpty(): boolean {
return this.memory.every((word) => word === 0);
}
}

export class SubMemory implements MemoryAdapter {
Expand Down
2 changes: 1 addition & 1 deletion simulator/src/test/cputst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class CPUTest extends Test<CPUTestInstruction> {
}

override async step() {
if (!(this.hasLoad || this.fileLoaded)) {
if (!this.hasLoad && this.cpu.ROM.isEmpty()) {
throw new Error(
"Cannot execute the test without first loading an .asm or .hack file",
);
Expand Down

0 comments on commit 36e768d

Please sign in to comment.