From 4f0b889b74b71b8667b17022c389bf4f313868be Mon Sep 17 00:00:00 2001 From: Guy Perfect Date: Tue, 18 Feb 2025 15:10:46 -0600 Subject: [PATCH] Adjustments for use in the web frontend --- web/Audio.js | 2 -- web/Constants.js | 5 ++--- web/Core.js | 37 ++++++++++++++++++++++++++++++++++++- web/VB.js | 26 ++++++++++++++++++++++++-- 4 files changed, 62 insertions(+), 8 deletions(-) diff --git a/web/Audio.js b/web/Audio.js index 093560f..8178ccf 100644 --- a/web/Audio.js +++ b/web/Audio.js @@ -1,7 +1,5 @@ "use strict"; -//////////////////////////////////// Audio //////////////////////////////////// - // Dedicated audio output processor class Audio extends AudioWorkletProcessor { diff --git a/web/Constants.js b/web/Constants.js index a8f318f..37d7206 100644 --- a/web/Constants.js +++ b/web/Constants.js @@ -1,4 +1,5 @@ -let Constants = { +"use strict"; +export default { // Core VB: { @@ -85,5 +86,3 @@ let Constants = { } }; - -export { Constants }; diff --git a/web/Core.js b/web/Core.js index 92b75b9..cb261bc 100644 --- a/web/Core.js +++ b/web/Core.js @@ -1,5 +1,5 @@ "use strict"; -import { Constants } from "./Constants.js"; +import Constants from /***/"./Constants.js"; @@ -258,6 +258,41 @@ new class Core { }); } + // Attempt to produce a ROM from an ISX debugger file + fromISX(message) { + + // Transfer the input data into WebAssembly memory + let input = new Uint8Array(message.data); + let inPtr = this.Realloc(0, input.length); + let inMem = new Uint8Array(this.memory.buffer, inPtr, input.length); + for (let x = 0; x < input.length; x++) + inMem[x] = input[x]; + + // Attempt to decode the ISX file as a ROM + let outPtr = this.FromISX(inPtr, input.length); + this.Realloc(inPtr, 0); + + // The data is not an ISX file + if (outPtr == 0) { + this.dom.postMessage({ promised: true, data: null }); + return; + } + + // Transfer the decoded ROM from WebAssembly memory + let output = new Uint8Array(this.GetISXLength(outPtr)); + let outMem = new Uint8Array(this.memory.buffer, + this.GetISXROM(outPtr), output.length); + for (let x = 0; x < output.length; x++) + output[x] = outMem[x]; + this.Realloc(outPtr, 0); + + // Notify DOM thread + this.dom.postMessage({ + promised: true, + data : output.buffer + }, [ output.buffer ]); + } + // Specify anaglyph colors setAnaglyph(message) { this.SetAnaglyph(message.sim, message.left, message.right); diff --git a/web/VB.js b/web/VB.js index 1b2150f..e1dc088 100644 --- a/web/VB.js +++ b/web/VB.js @@ -1,5 +1,5 @@ "use strict"; -import { Constants } from "./Constants.js"; +import Constants from /**/"./Constants.js"; // Instantiation guard const GUARD = Symbol(); @@ -864,6 +864,28 @@ class VB { return true; } + // Decode an ISX debugger file to a Virtual Boy ROM + async fromISX(data) { + + // Validation + if (data instanceof ArrayBuffer) + data = new Uint8Array(data); + if ( + !(data instanceof Uint8Array) && + !(data instanceof Uint8ClampedArray) + ) data = Uint8Array.from(data); + + // Send the memory to the core + data = data.slice(); + let response = await this.#toCore({ + command : "fromISX", + promised : true, + data : data.buffer, + transfers: [ data.buffer ] + }); + return response.data == null ? null : new Uint8Array(response.data); + } + // Suspend automatic emulation async suspend() { @@ -932,4 +954,4 @@ class VB { } -export { VB }; +export default VB;