Giter Site home page Giter Site logo

switch-gba's Introduction

Switch GBA Emulator

Docker Cloud Build Status

Motivation

Homebrewing / Hacking a switch is too much of a dangerous affair for me personally and after learning there is a browser I tried to get it running in there. Turns out it is (sort of) possible.

Preview (Old UI but still relevant)

This project is meant as an experiment of what is possible and not to be used commercially. This is a hobby project and therefore I won't commit to offering help / maintaining / updating this project unless I choose to do so.

Information / How it's done This project makes use of the Switch browser that comes up when trying to verify / sign in with certain DNS providers. I won't explain how to do this here but if are capable of setting this up you certainly will also be able to find that information yourself.

The way the Switch handles B is a bit different if there is an iFrame present on the page. In this case B will actually navigate the iFrame back first before navigating back the actual page (or reloading it). This is crucial for my workaround. With the use of postMessage I always immediately return to a "navigated" state of the iFrame.

This is a modified and heavily towards switch tailored version of [crowdsourced-gba](https://github.com/vinnyoodles/crowdsourced-gba) by vinnynoodles.

Planned features

  • [Done] Save states
  • [Done] Gamepad API

Button Layout

Thanks to the Gamepad API I was able to remove most of the onscreen buttons and enable hardware button support.

Since v1.0.2 custom layouts are also supported. Just click the cogs at the top of the screen during rom selection to open the options menu. The left side shows the GBA key and the right side shows the currently assigned Switch key.

Developer info The current layout file is found at `src/backend/layout.json`. A default configuration is always saved at `src/backend/layout.backup.json`, which is also used for the reset.


Usage

The emulator in it's entirety is ready to be pulled as a docker image. It runs on and exposes port 8888 by default.

Docker Images

Latest release
bfriedrichs/switch-gba:release-latest

Latest master (possibly unstable)
bfriedrichs/switch-gba:latest

Latest dev (most likely unstable)
bfriedrichs/switch-gba:dev

Older release
bfriedrichs/switch-gba:release-{version}

I'm not distributing any roms, so you will have to make a folder roms with your .gba files directly in it.

Example

docker run -d -v $(pwd)/roms:/home/roms/ --name switch-gba -p 8888:8888 bfriedrichs/switch-gba:release-latest

Versions

1.0.2

  • Added custom button layouts
  • Code restructuring

1.0.1

  • Add fix for content size warning after alerts are open for too long
  • Minor changes

1.0.0

  • Initial release
  • ROM selection
  • Gamepad support
  • Turbo mode (2-20x speed)

Misc issues / features

Some other stuff that I build / had to deal with.

  • Page size too large, refresh the page This popped up every now and then and then made the window lag out continously even when Cancel is pressed. I changed from png to uncompressed webp images and added logic that disconnects the WebSocket if there's no input for more than 10 seconds. The WebSocket automatically reconnects if there's new input.

  • Turbo mode When enabled turbo mode makes the emulator tick at times the speed of its usual execution (e.g. 600 vs 60 fps for x10). The output rate of frames remains 60 so the switch doesn't choke up.

  • Audio Sadly the switch doesn't seem to have an exposed audio API for the web browser. I'm still looking for a solution since various feature checkers actually report a prefixed AudioContext to be present but I didn't have luck with that yet.


Resources

Switch supported HTML features http://html5test.com/s/a77ccd45f1540617.html

switch-gba's People

Contributors

bfriedrichs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

switch-gba's Issues

Alerts can stop execution

By choking up the system, any alert can cause a content size warning which stops some functionality if it’s displayed for too long.

Related:
#1

Emulator does not load

When choosing an rom, the screen stays black, only showing slot, turbo, go back, reset and reload page buttons.

EDIT: Issue occurs only when using NGINX as a reverse proxy.

The B button isn't working properly

The behavior of the B button is awkward. Maybe you should try a different approach than the iframe.
The following snippets was tested on switch browser and worked very well.

Using window.location.hash:

<html>
<script>
var cnt = 0;

window.location.hash = "#1";
function beginHistory() {
  window.location.hash = "#2";
  setInterval(function(){
    if (window.location.hash != "#2") {
      window.location.hash = "#2";
      ++cnt;
      document.getElementById('content').innerHTML = 'PRESS #' + cnt;
    }
  }, 1);
}

setTimeout(function(){beginHistory();}, 1);
</script>

<div id='content'></div>
</html>

Using HTML5 pushState: (dont know why, but this doesn't work on my Chorme)

<html>

<script>
var cnt = 0;

history.pushState("#1", null, "");
function beginHistory() {
  history.pushState("#2", null, "");
  window.onpopstate = function(event) {
    history.pushState("#2", null, "");
    ++cnt;
    document.getElementById('content').innerHTML = 'PRESS #' + cnt;
  };
}
setTimeout(function(){beginHistory();}, 1);

</script>

<div id='content'></div>

</html>

the second one is better, because it does not rely on a interval polling the hash value.

"You are now leaving this screen" on "B" button press

After playing for a while, I'll often get this message:

"Due to the size of the page, not all content could be displayed. try reloading the page?"

After doing the reload, the "B" button workaround sorta stops working. Every press of B works, but I get a pop up saying:

"You are now leaving this screen. Any information you have entered will not be saved"

I've found that doing a reload using the "Reload page" in the bottom right fixes this though.

Certainly not a huge issue, I more wanted to log an issue in case anyone else is having the issue and hasn't found the workaround.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.