From 18ea4cc95fced337946c93d17ac1d41ceb9c829d Mon Sep 17 00:00:00 2001 From: Dorian Ignee Date: Wed, 4 Dec 2024 11:11:39 +0100 Subject: [PATCH] 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() --- simulator/src/cpu/memory.ts | 4 ++++ simulator/src/test/cputst.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/simulator/src/cpu/memory.ts b/simulator/src/cpu/memory.ts index dacd1fd4b..8979ddc88 100644 --- a/simulator/src/cpu/memory.ts +++ b/simulator/src/cpu/memory.ts @@ -127,6 +127,10 @@ export class Memory implements MemoryAdapter { [Symbol.iterator](): Iterable { return this.map((_, v) => v); } + + isEmpty(): boolean { + return this.memory.every((word) => word === 0); + } } export class SubMemory implements MemoryAdapter { diff --git a/simulator/src/test/cputst.ts b/simulator/src/test/cputst.ts index bc28f414c..8b041871a 100644 --- a/simulator/src/test/cputst.ts +++ b/simulator/src/test/cputst.ts @@ -55,7 +55,7 @@ export class CPUTest extends Test { } 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", );