From 39af042fbcc7cf900493df33f69281a39dee4a51 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Sat, 13 Sep 2025 07:19:05 +1200 Subject: Implement the FORK and RESET device signals These were implemented before version 1.1.0, but I hadn't gotten around to implementing them again during the big restructure in commit 19c5679. The main change here is that the existing `reset` method was renamed to `end`, and a new `reset` method was created that only affects the core and devices. --- bedrock.js | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/bedrock.js b/bedrock.js index b5c7e19..d9811c1 100644 --- a/bedrock.js +++ b/bedrock.js @@ -880,6 +880,12 @@ function Bedrock(emulatorElement, wasm=defaultToWasm) { await core.init(this.dev.read, this.dev.write); } + // Reset the emulator, keep running. + this.reset = () => { + core.reset(); + this.dev.reset(); + } + // Fully reset the emulator, and load in a new program. this.load = (bytecode) => { this.reset(); @@ -887,10 +893,9 @@ function Bedrock(emulatorElement, wasm=defaultToWasm) { this.blank = false; } - // Fully reset the emulator. - this.reset = () => { - core.reset(); - this.dev.reset(); + // Fully stop and reset the emulator. + this.end = () => { + this.reset(); this.blank = true; // emulator has been fully reset, screen is blank. this.paused = true; // program is not currently executing. this.asleep = false; // program is waiting for input. @@ -936,7 +941,7 @@ function Bedrock(emulatorElement, wasm=defaultToWasm) { // End and reset the program, allow it to run from the beginning. this.stop = () => { - this.reset(); + this.end(); this.update(); this.render(); } @@ -964,13 +969,13 @@ function Bedrock(emulatorElement, wasm=defaultToWasm) { return; } switch (core.eval(1)) { - case Signal.HALT: this.halt(); return; - case Signal.DB4: this.assert(); break; - // case Signal.RESET: this.reset(); break; - // case Signal.FORK: this.reset(); break; - case Signal.SLEEP: this.sleep(); return; - case Signal.DB1: this.pause(); break; - default: // NORMAL + case Signal.HALT: this.halt(); return; + case Signal.DB4: this.assert(); break; + case Signal.RESET: this.reset(); break; + case Signal.FORK: this.reset(); break; + case Signal.SLEEP: this.sleep(); return; + case Signal.DB1: this.pause(); break; + default: break; } this.update(); this.render(); @@ -986,13 +991,13 @@ function Bedrock(emulatorElement, wasm=defaultToWasm) { } // Tail-recursive with timeout to allow other code to run. switch (core.eval(cyclesPerBatch)) { - case Signal.HALT: this.halt(); return; - case Signal.DB4: this.assert(); break; - // case Signal.RESET: this.reset(); break; - // case Signal.FORK: this.reset(); break; - case Signal.SLEEP: this.sleep(); return; - case Signal.DB1: this.pause(); break; - default: // NORMAL + case Signal.HALT: this.halt(); return; + case Signal.DB4: this.assert(); break; + case Signal.RESET: this.reset(); break; + case Signal.FORK: this.reset(); break; + case Signal.SLEEP: this.sleep(); return; + case Signal.DB1: this.pause(); break; + default: break; } this.update(); // Force a render if the frame has been running for too long. @@ -2436,7 +2441,7 @@ function EmulatorElement(options) { // Initialise emulator and emulator element. this.init = async () => { await this.br.init(); - this.br.reset(); + this.br.end(); this.br.onUpdate = () => this.updateDOM(); // Apply options. -- cgit v1.2.3-70-g09d2