From 36e768d8f0f9d86d3462141715f6b023a27b3311 Mon Sep 17 00:00:00 2001 From: dorianignee <83406502+dorianignee@users.noreply.github.com> Date: Thu, 5 Dec 2024 17:24:52 +0100 Subject: [PATCH] Fix #523: Cpu emulator test runner doesn't recognize asm from assembler 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 --- 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", );