Offthread gfx #22

Merged
merged 16 commits into from Jan 24, 2016

Move blitter responsibility to renderer core

Will allow shimming and is cleaner in api terms.
  • Loading branch information...
taisel committed Jan 23, 2016
commit faf611f198b657310b010098b0c16d4610556d41
View
@@ -21,20 +21,12 @@ function GameBoyAdvanceEmulator() {
};
this.audioFound = 0; //Do we have audio output sink found yet?
this.emulatorStatus = 0x10; //{paused, saves loaded, fault found, loaded}
- this.offscreenWidth = 240; //Width of the GBA screen.
- this.offscreenHeight = 160; //Height of the GBA screen.
this.BIOS = []; //Initialize BIOS as not existing.
this.ROM = []; //Initialize BIOS as not existing.
- //Cache some frame buffer lengths:
- this.offscreenRGBCount = ((this.offscreenWidth | 0) * (this.offscreenHeight | 0) * 3) | 0;
- //Graphics buffers to generate in advance:
- this.frameBuffer = getInt32Array(this.offscreenRGBCount | 0); //The internal buffer to composite to.
- this.swizzledFrame = getUint8Array(this.offscreenRGBCount | 0); //The swizzled output buffer that syncs to the internal framebuffer on v-blank.
this.audioUpdateState = 1; //Do we need to update the sound core with new info?
this.saveExportHandler = null; //Save export handler attached by GUI.
this.saveImportHandler = null; //Save import handler attached by GUI.
this.speedCallback = null; //Speed report handler attached by GUI.
- this.graphicsHandle = null; //Graphics blitter handler attached by GUI.
this.timerIntervalRate = 4; //How often the emulator core is called into (in milliseconds).
this.lastTimestamp = 0; //Track the last time given in milliseconds.
this.dynamicSpeedRefresh = false; //Whether speed is allowed to be changed dynamically in the current cycle.
@@ -47,10 +39,7 @@ GameBoyAdvanceEmulator.prototype.generateCoreExposed = function () {
"outputAudio":function (l, r) {
parentObj.outputAudio(l, r);
},
- "frameBuffer":parentObj.frameBuffer,
- "prepareFrame":function () {
- parentObj.prepareFrame();
- }
+ graphicsHandle:null
}
}
GameBoyAdvanceEmulator.prototype.play = function () {
@@ -270,37 +259,14 @@ GameBoyAdvanceEmulator.prototype.keyUp = function (keyReleased) {
}
GameBoyAdvanceEmulator.prototype.attachGraphicsFrameHandler = function (handler) {
if (typeof handler == "object") {
- this.graphicsHandle = handler;
+ this.coreExposed.graphicsHandle = handler;
}
}
GameBoyAdvanceEmulator.prototype.attachAudioHandler = function (mixerInputHandler) {
if (mixerInputHandler) {
this.audio = mixerInputHandler;
}
}
-GameBoyAdvanceEmulator.prototype.swizzleFrameBuffer = function () {
- //Convert our dirty 15-bit (15-bit, with internal render flags above it) framebuffer to an 8-bit buffer with separate indices for the RGB channels:
- var bufferIndex = 0;
- for (var canvasIndex = 0; (canvasIndex | 0) < (this.offscreenRGBCount | 0); bufferIndex = ((bufferIndex | 0) + 1) | 0) {
- this.swizzledFrame[canvasIndex | 0] = (this.frameBuffer[bufferIndex | 0] & 0x1F) << 3; //Red
- canvasIndex = ((canvasIndex | 0) + 1) | 0;
- this.swizzledFrame[canvasIndex | 0] = (this.frameBuffer[bufferIndex | 0] & 0x3E0) >> 2; //Green
- canvasIndex = ((canvasIndex | 0) + 1) | 0;
- this.swizzledFrame[canvasIndex | 0] = (this.frameBuffer[bufferIndex | 0] & 0x7C00) >> 7; //Blue
- canvasIndex = ((canvasIndex | 0) + 1) | 0;
- }
-}
-GameBoyAdvanceEmulator.prototype.prepareFrame = function () {
- //Copy the internal frame buffer to the output buffer:
- this.swizzleFrameBuffer();
- this.requestDraw();
-}
-GameBoyAdvanceEmulator.prototype.requestDraw = function () {
- if (this.graphicsHandle) {
- //We actually updated the graphics internally, so copy out:
- this.graphicsHandle.copyBuffer(this.swizzledFrame);
- }
-}
GameBoyAdvanceEmulator.prototype.enableAudio = function () {
if ((this.audioFound | 0) == 0 && this.audio) {
this.audioFound = 1; //Set audio to 'found' by default.
@@ -1,11 +1,11 @@
"use strict";
/*
Copyright (C) 2012-2015 Grant Galitz
-
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
function GameBoyAdvanceGraphicsRenderer(coreExposed, skippingBIOS) {
@@ -30,7 +30,8 @@ if (__VIEWS_SUPPORTED__) {
this.paletteRAM32 = getInt32View(this.paletteRAM);
this.buffer = getInt32Array(0x680);
this.lineBuffer = getInt32ViewCustom(this.buffer, 0, 240);
- this.frameBuffer = this.coreExposed.frameBuffer;
+ this.frameBuffer = getInt32Array(38400); //The internal buffer to composite to.
+ this.swizzledFrame = getUint8Array(115200); //The swizzled output buffer that syncs to the internal framebuffer on v-blank.
this.totalLinesPassed = 0;
this.queuedScanLines = 0;
this.lastUnrenderedLine = 0;
@@ -55,7 +56,8 @@ else {
this.paletteRAM16 = getUint16View(this.paletteRAM);
this.paletteRAM32 = getInt32View(this.paletteRAM);
this.buffer = getInt32Array(0x680);
- this.frameBuffer = this.coreExposed.frameBuffer;
+ this.frameBuffer = getInt32Array(38400); //The internal buffer to composite to.
+ this.swizzledFrame = getUint8Array(115200); //The swizzled output buffer that syncs to the internal framebuffer on v-blank.
this.totalLinesPassed = 0;
this.queuedScanLines = 0;
this.lastUnrenderedLine = 0;
@@ -120,7 +122,30 @@ GameBoyAdvanceGraphicsRenderer.prototype.ensureFraming = function () {
//Make sure our gfx are up-to-date:
this.graphicsJITVBlank();
//Draw the frame:
- this.coreExposed.prepareFrame();
+ this.prepareFrame();
+ }
+}
+GameBoyAdvanceGraphicsRenderer.prototype.swizzleFrameBuffer = function () {
+ //Convert our dirty 15-bit (15-bit, with internal render flags above it) framebuffer to an 8-bit buffer with separate indices for the RGB channels:
+ var bufferIndex = 0;
+ for (var canvasIndex = 0; (canvasIndex | 0) < 115200; bufferIndex = ((bufferIndex | 0) + 1) | 0) {
+ this.swizzledFrame[canvasIndex | 0] = (this.frameBuffer[bufferIndex | 0] & 0x1F) << 3; //Red
+ canvasIndex = ((canvasIndex | 0) + 1) | 0;
+ this.swizzledFrame[canvasIndex | 0] = (this.frameBuffer[bufferIndex | 0] & 0x3E0) >> 2; //Green
+ canvasIndex = ((canvasIndex | 0) + 1) | 0;
+ this.swizzledFrame[canvasIndex | 0] = (this.frameBuffer[bufferIndex | 0] & 0x7C00) >> 7; //Blue
+ canvasIndex = ((canvasIndex | 0) + 1) | 0;
+ }
+}
+GameBoyAdvanceGraphicsRenderer.prototype.prepareFrame = function () {
+ //Copy the internal frame buffer to the output buffer:
+ this.swizzleFrameBuffer();
+ this.requestDraw();
+}
+GameBoyAdvanceGraphicsRenderer.prototype.requestDraw = function () {
+ if (this.coreExposed.graphicsHandle) {
+ //We actually updated the graphics internally, so copy out:
+ this.coreExposed.graphicsHandle.copyBuffer(this.swizzledFrame);
}
}
GameBoyAdvanceGraphicsRenderer.prototype.graphicsJIT = function () {
@@ -1385,4 +1410,4 @@ GameBoyAdvanceGraphicsRenderer.prototype.writePalette16Color = function (address
}
GameBoyAdvanceGraphicsRenderer.prototype.readPalette8 = function (address) {
return this.paletteRAM[address & 0x3FF] | 0;
-}
+}
View
@@ -1,7 +1,7 @@
JavaScript GameBoy Advance Emulator
=================================
-**Copyright (C) 2010 - 2015 Grant Galitz**
+**Copyright (C) 2010 - 2016 Grant Galitz**
A GameBoy Advance emulator that utilizes HTML5 canvas and JavaScript audio APIs to provide a full emulation of the console.
@@ -20,39 +20,39 @@ Screenshots
* **Pokemon Ruby:**
![Pokemon Ruby](http://i.imgur.com/OO9XCRk.png "Pokemon Ruby")
-
+
* **Super Mario Advance:**
-
+
![Super Mario Advance](http://i.imgur.com/ewhtAJg.png "Super Mario Advance")
* **Mario & Luigi Superstar Saga:**
-
+
![Mario & Luigi Superstar Saga](http://i.imgur.com/Do8TbsMh.png "Mario & Luigi Superstar Saga")
-
+
* **Mario Kart Advance:**
-
+
![Mario Kart Advance](http://i.imgur.com/37xx3yPh.png “Super Circuit”)
-
+
* **Earthworm Jim:**
-
+
![Earthworm Jim](http://i.imgur.com/Ip3MHzmh.png “Earthworm Jim”)
-
+
* **Advance Wars:**
-
+
![Advance Wars](http://i.imgur.com/akKzA97h.png “Advance Wars”)
-
+
* **Wario Land 4:**
-
+
![Wario Land 4](http://i.imgur.com/eaDqCxuh.png “Wario Land 4”)
-
+
* **Golden Sun:**
-
+
![Golden Sun](http://i.imgur.com/EctuZxo.png “Golden Sun”)
* **Game & Watch Gallery 4:**
-
+
![Game & Watch Gallery 4](http://i.imgur.com/awLMWsIh.png “Game & Watch Gallery 4”)
-
+
* **GBA BIOS:**
- ![GBA BIOS](http://i.imgur.com/kzxGoAHh.png “GBA BIOS”)
+ ![GBA BIOS](http://i.imgur.com/kzxGoAHh.png “GBA BIOS”)