diff options
author | Ben Bridle <ben@derelict.engineering> | 2025-09-13 07:19:05 +1200 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2025-09-13 07:50:11 +1200 |
commit | 39af042fbcc7cf900493df33f69281a39dee4a51 (patch) | |
tree | 48512d4bc93a2ffa82bab6e9317bb08766ddc216 /bedrock.js | |
parent | b452cc1a0afdfe863b5dd92b8bd9d05fd9e347a8 (diff) | |
download | bedrock-js-39af042fbcc7cf900493df33f69281a39dee4a51.zip |
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.
Diffstat (limited to 'bedrock.js')
-rw-r--r-- | bedrock.js | 45 |
1 files changed, 25 insertions, 20 deletions
@@ -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. |