Skip to content

Commit

Permalink
Merge pull request #1 from thenick775/mgba-wasm
Browse files Browse the repository at this point in the history
Mgba wasm support
  • Loading branch information
thenick775 committed Feb 20, 2023
2 parents 17e40f4 + 56e62c9 commit bfeb18e
Show file tree
Hide file tree
Showing 35 changed files with 1,279 additions and 409 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
/**/docker-compose.yml
/**/nginx.conf
/**/auth/**/*
/**/mgba.js
/**/mgba.wasm
62 changes: 32 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
gbajs3 -- My Personal Fork
======

This project is a re-skin of the gbajs2 fork by andychase, with some additions.
This project is a Game Boy Advance emulator that is freely licensed and works in any modern browser without plugins.

This project was driven specifically by my want to play older gba rom hacks outside of desktop applications without side loading or building through xcode.
It began as a re-skin of the [gbajs2](https://github.com/andychase/gbajs2) fork by andychase, but now supports both the [mGBA wasm](https://github.com/thenick775/mgba/tree/feature/wasm) core as well as gbajs (a pure javascript GBA core).

A server side rendering approach is planned in the near future.
This project was driven specifically by my need to play modern GBA rom hacks outside of desktop applications, without side loading or building through xcode.

Use it online! <https://gba.nicholas-vancise.dev>

Do not attempt to log into the server unless you are the server owner, your IP may be banned.
Do not attempt to log into the server unless you are the server owner or an approved user, your IP may be banned.

## New Feature List
* Golang server for logged-in user support
* Nginx server for gbajs3 content
* Fast Forward
* Remappable Keyboard Bindings
* Virtual Controls (Desktop/Mobile)
* Movable desktop canvas and controls
* Mobile UI support
* Offline PWA Support
* Functional Surface-level ASM debugger
* Functional Surface-level ASM debugger (gbajs only)
* Interchangeable cores
* mGBA support (wasm based)
* gbajs support (pure javascript)

## Existing Feature List
- Both cores support realtime clock
- For additional gbajs2 features:
- [Compatibility](https://github.com/andychase/gbajs2/wiki/Compatibility-List)
- [Emulator features](https://github.com/andychase/gbajs2)
- For additional mGBA features:
- [mGBA wasm fork Readme](https://github.com/thenick775/mgba/tree/feature/wasm)
- [official mGBA Readme](https://github.com/mgba-emu/mgba)

## To Do
* mGBA wasm support (enhanced compatibility and performance)
* Debugger enhancements
* Cheat entry/injection implementation
* mGBA Save State Support

## Sample Screenshots/Gifs
## Sample Screenshots

* Example Desktop

Expand Down Expand Up @@ -67,33 +82,20 @@ go run users_db_helper.go
* Simply run `docker-compose up --build` and your services will build and start
* Golang api swagger UI can be found at `/api/documentation/`

# -- (Original README below) --

gbajs2 is a Game Boy Advance emulator written in Javascript from scratch using HTML5 technologies like Canvas and Web Audio.
It is freely licensed and works in any modern browser without plugins.

Use it online!

See the issues page for feature suggestions and ways you can help contribute!

Mailing list for general discussion or if you want to just be kept in the loop: ...

## Feature List

* Playable compatibility, see [compatibility](https://github.com/andychase/gbajs2/wiki/Compatibility-List)
* Acceptable performance on modern browsers
* Pure javascript, allowing easy API access
* Realtime clock gamepad support (Pokemon Ruby)
* Save games

## License
Original work by Endrift. Repo: (Archived / No longer maintained) https://github.com/endrift/gbajs

Original work by Endrift. Repo: (Archived / No longer maintained)
https://github.com/endrift/gbajs
Copyright © 2012 – 2013, Jeffrey Pfau

Copyright © 2020, Andrew Chase
Original work by Endrift. Repo: (mGBA wasm base)
https://github.com/endrift/mgba
mGBA is Copyright © 2013 – 2018 Jeffrey Pfau. It is distributed under the [Mozilla Public License version 2.0](https://www.mozilla.org/MPL/2.0/). A full copy of the license is available at my [fork](https://github.com/thenick775/mgba).

Original work by andychase. Repo: (gbajs2 base)
https://github.com/andychase/gbajs2
Copyright © 2020, Andrew Chase

Copyright © 2022, Nicholas VanCise
Copyright © 2022 - 2023, Nicholas VanCise

All rights reserved.

Expand All @@ -117,4 +119,4 @@ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
POSSIBILITY OF SUCH DAMAGE.
1 change: 0 additions & 1 deletion docker/server/auth/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# first stage - builder
FROM golang:alpine as builder
WORKDIR /app/
RUN apk add --update gcc g++
COPY ./server/auth /app/
ENV GO111MODULE=on
RUN go mod download
Expand Down
3 changes: 2 additions & 1 deletion docker/server/nginx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ COPY ./gbajs3 /var/www/
ARG CLIENT_HOST
RUN sed -i "s;<CLIENT_HOST>;${CLIENT_HOST};" /var/www/resources/gba-api.js

RUN cd /var/www/ && minify -r --match="(\.js|\.css)" -o . .
# minify all js/css files except emscripten generated mgba.js
RUN cd /var/www/ && find . | egrep '(.*\.js|.*\.css)' | egrep -v 'mgba.js' | xargs -n 1 -I {} minify -o {} {}

# second stage, server
FROM nginx:stable-alpine
Expand Down
36 changes: 19 additions & 17 deletions gbajs3/console.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
<html>
<head>
<script src="js/util.js"></script>
<script src="js/core.js"></script>
<script src="js/arm.js"></script>
<script src="js/thumb.js"></script>
<script src="js/mmu.js"></script>
<script src="js/io.js"></script>
<script src="js/audio.js"></script>
<script src="js/video.js"></script>
<script src="js/video/proxy.js"></script>
<script src="js/video/software.js"></script>
<script src="js/irq.js"></script>
<script src="js/keypad.js"></script>
<script src="js/sio.js"></script>
<script src="js/savedata.js"></script>
<script src="js/gpio.js"></script>
<script src="js/gba.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>gbajs3 Console</title>
<script src="emulator/gbajs/js/util.js"></script>
<script src="emulator/gbajs/js/core.js"></script>
<script src="emulator/gbajs/js/arm.js"></script>
<script src="emulator/gbajs/js/thumb.js"></script>
<script src="emulator/gbajs/js/mmu.js"></script>
<script src="emulator/gbajs/js/io.js"></script>
<script src="emulator/gbajs/js/audio.js"></script>
<script src="emulator/gbajs/js/video.js"></script>
<script src="emulator/gbajs/js/video/proxy.js"></script>
<script src="emulator/gbajs/js/video/software.js"></script>
<script src="emulator/gbajs/js/irq.js"></script>
<script src="emulator/gbajs/js/keypad.js"></script>
<script src="emulator/gbajs/js/sio.js"></script>
<script src="emulator/gbajs/js/savedata.js"></script>
<script src="emulator/gbajs/js/gpio.js"></script>
<script src="emulator/gbajs/js/gba.js"></script>
<script src="emulator/gbajs/js/console.js"></script>

<script src="resources/xhr.js"></script>
<script src="resources/console.js"></script>
<link href="resources/console.css" rel="stylesheet" />
<script>
function runTest(r) {
Expand Down
4 changes: 2 additions & 2 deletions gbajs3/debugger.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>gbajs3 Debugger</title>
<script src="js/util.js"></script>
<script src="resources/console.js"></script>
<script src="emulator/gbajs/js/util.js"></script>
<script src="emulator/gbajs/js/console.js"></script>
<link href="resources/console.css" rel="stylesheet" />
<script>
window.onmessage = function (message) {
Expand Down
165 changes: 165 additions & 0 deletions gbajs3/emulator/emulator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
class GameBoyAdvanceEmulator {
constructor(emulator = 'mGBA', canvas_id = 'screen') {
this.emulator = null;
switch (emulator) {
case 'mGBA':
this.emulator = new mGBAEmulator(canvas_id);
break;
case 'gbajs':
this.emulator = new GBAJsEmulator(canvas_id);
break;
default:
return { invalid: true, errors: ['Unknown emulator'] };
}

if (!this.emulator || this.emulator.invalid) {
return {
invalid: true,
errors: [
'Error instanciating emulator fo type: ' + emulator
].concat(this.emulator.errors)
};
}
}

// interface for emulators:
// required methods
Run(file, callback) {
this.emulator.run(file, callback);
}

LoadSave(file) {
this.emulator.loadSave(file);
}

IsRunning() {
return this.emulator.getIsRunning();
}

Pause() {
this.emulator.pause();
}

Resume() {
this.emulator.resume();
}

GetPaused() {
return this.emulator.getPaused();
}

SetVolume(percent_value) {
this.emulator.setVolume(percent_value);
}

GetVolume() {
return this.emulator.getVolume();
}

SetPixelated(pixelated) {
this.emulator.setPixelated(pixelated);
}

Reset() {
return this.emulator.reset();
}

QuickReload() {
return this.emulator.quickReload();
}

DownloadSave(filename) {
this.emulator.downloadSave(filename);
}

GetCurrentSave() {
return this.emulator.getCurrentSave();
}

EnableKeyboardInput() {
this.emulator.enableKeyboardInput();
}

DisableKeyboardInput() {
this.emulator.disableKeyboardInput();
}

SimulateKeyDown(keycode) {
this.emulator.simulateKeyDown(keycode);
}

SimulateKeyUp(keycode) {
this.emulator.simulateKeyUp(keycode);
}

RemapKeyBinding(name, keyBindingCode, keybindingName) {
this.emulator.remapKeyBinding(name, keyBindingCode, keybindingName);
}

SetFastForward(mode, value) {
this.emulator.setFastForward(mode, value);
}

ScreenShot() {
this.emulator.screenShot();
}

// optional methods
QuitGame() {
if (this.emulatorCan('quitGame')) {
this.emulator.quitGame();
}
}

QuitEmulator() {
if (this.emulatorCan('quitEmulator')) {
this.emulator.quitEmulator();
}
}

EnterCheat(cheat_code) {
if (this.emulatorCan('enterCheat')) {
this.emulator.enterCheat(cheat_code);
}
}

ToggleCheat(cheat_name) {
//desired params? id or string??
if (this.emulatorCan('toggleCheat')) {
this.emulator.toggleCheat(cheat_name);
}
}

EnableDebug() {
if (this.emulatorCan('enableDebug')) {
this.emulator.enableDebug();
}
}

IsDebugActive() {
if (this.emulatorCan('isDebugActive')) {
return this.emulator.isDebugActive();
}
return false;
}

AudioPolyfill(callback) {
if (this.emulatorCan('audioPolyfill')) {
this.emulator.audioPolyfill(callback);
}
}

LCDFade() {
if (this.emulatorCan('lcdFade')) {
this.emulator.lcdFade();
}
}

// helpers
emulatorCan(methodname) {
if (this.emulator) {
return typeof this.emulator[methodname] === 'function';
}
return false;
}
}
Loading

0 comments on commit bfeb18e

Please sign in to comment.