JSNES JavaScript NES emulator may be working on switch

Discussion in 'Switch - Emulation, Homebrew & Software Projects' started by Suso_, Apr 23, 2017.

  1. Suso_

    Suso_ Newbie

    Apr 23, 2017
    Hey! I've been lurking in the forums for a while, but I decided to make an account now that I need to ask about this.

    So I was messing round with the unlocked switch web browser by using the fiddler method to browse anywhere and tried to use JSNES... Surprisingly, it started working (even though it seems necessary to disable sound or else it just drops to 0 fps).

    The problem is that controls are obviously prepared to play on PC, so I cant even press the start button to check if it's working. I opened the code to try and change the controls or something... but then I realized I don't know the codes for switch input...

    This is the switch for the input (it starts on line 2027 of the code):
    switch (key) {
    //Player 1 controls
                case 88: this.state1[this.keys.KEY_A] = value; break;      // X
                case 89: this.state1[this.keys.KEY_B] = value; break;      // Y (Central European keyboard)
                case 90: this.state1[this.keys.KEY_B] = value; break;      // Z
                case 17: this.state1[this.keys.KEY_SELECT] = value; break; // Right Ctrl
                case 13: this.state1[this.keys.KEY_START] = value; break;  // Enter
                case 38: this.state1[this.keys.KEY_UP] = value; break;     // Up
                case 40: this.state1[this.keys.KEY_DOWN] = value; break;   // Down
                case 37: this.state1[this.keys.KEY_LEFT] = value; break;   // Left
                case 39: this.state1[this.keys.KEY_RIGHT] = value; break;  // Right
    //Player 2 controls
                case 103: this.state2[this.keys.KEY_A] = value; break;     // Num-7
                case 105: this.state2[this.keys.KEY_B] = value; break;     // Num-9
                case 99: this.state2[this.keys.KEY_SELECT] = value; break; // Num-3
                case 97: this.state2[this.keys.KEY_START] = value; break;  // Num-1
                case 104: this.state2[this.keys.KEY_UP] = value; break;    // Num-8
                case 98: this.state2[this.keys.KEY_DOWN] = value; break;   // Num-2
                case 100: this.state2[this.keys.KEY_LEFT] = value; break;  // Num-4
                case 102: this.state2[this.keys.KEY_RIGHT] = value; break; // Num-6
                default: return true;
    Anyone knows what would be the codes for the switch's joycons?
    Alternis, vinipeix and ElijahZAwesome like this.
  2. MashedPotatos

    MashedPotatos Advanced Member

    Apr 10, 2017
    I'm not entirely sure this will work, but try to find the button values of the controls of the joycon and then change KEY_A, KEY_B, etc to what the joycons buttons are for example if you where to port the Xbox one controller to this you would change KEY_UP, KEY_DOWN, KEY_LEFT and KEY_RIGHT to DPAD_UP, DPAD_DOWN, DPAD_LEFT and DPAD_RIGHT
  3. Suso_

    Suso_ Newbie

    Apr 23, 2017
    I think what we actually need to change are the key variable values that the switch looks for (88, 89, 90, 17, 13, 38, 40, 37 and 39). They seem to represent the keys that match the emulator's controls.
  4. the_randomizer

    the_randomizer The Temp's official fox whisperer

    Apr 29, 2011
    United States
    Dr. Wahwee's castle
    Whoa, didn't expect this to be feasible o.O
  5. fedehda

    fedehda GBAtemp Fan

    GBAtemp Patron
    fedehda is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    Mar 7, 2017
    At your current screen. And in heaven
    Awesome. I'll keep an eye on the thread
    NutymcNuty likes this.
  6. g00s3y

    g00s3y Asshole

    Aug 6, 2008
    United States
    Big if true
  7. NSStack

    NSStack Newbie

    Apr 24, 2017
    United States
    I'll look more into it on Friday (when I finally get the Switch) if someone doesn't before me. Seems like a fun little side project.
    Last edited by NSStack, Apr 24, 2017
  8. Suso_

    Suso_ Newbie

    Apr 23, 2017
    I figured out a way to find the keycodes we need:

    I made this simple test html:
    <!DOCTYPE html>
    <title>Test KeyCodes</title>
    <p id="output">Key-Keycode</p>
    document.onkeydown = function (e) {
        e = e || window.event;
        var code = e.keyCode;
        document.getElementById("output").innerHTML = document.getElementById("output").innerHTML  + "; " + String.fromCharCode(code) + "-" + code;
    It gives you the code of every key you press, so I run it on the switch and got these:

    A button: 13 = ENTER
    B button: Exits the web.
    Y button: Doesn't give output.
    X button: Exits the web.

    D-PAD Left: 37 = %
    D-PAD Up: 38 = &
    D-PAD Right: 39 = '
    D-PAD Down: 40 = (

    Sticks: Don't give output, even by pressing them.

    L/R/ZL/ZR/SL(L)/SR(L)/SL(R)/SR(R): Don't give output.

    +/- buttons: Show information about the page.

    Capture button: Doesn't give output.
    Home button: Exits to the home menu.

    Volume buttons: Don't give output.
    ON/OFF button: Starts sleep mode.

    I'm going to try and get the emulator's start button working.
    Last edited by Suso_, Apr 24, 2017
    dragonslayer817 likes this.
  9. anonymoose

    anonymoose Lannister

    Nov 15, 2015
    If it's about joycons, you should ask @shinyquagsire23
    Last edited by anonymoose, Apr 24, 2017
  10. NSStack

    NSStack Newbie

    Apr 24, 2017
    United States
    Definitely. @shinyquagsire23 has been working on an evdev input driver recently. I'm not sure if he'll have any knowledge for capturing the input in the Switch browser, but it's worth a shot.
  11. Suso_

    Suso_ Newbie

    Apr 23, 2017
    I managed to get it working :D It's still unplayable (because it can only get to about 7 fps) but it's definitely something.

    I already got some keyCodes, but I think i should ask @shinyquagsire23 anyways. Maybe he knows how to get the other buttons working...
    Gungerino likes this.
  12. the_randomizer

    the_randomizer The Temp's official fox whisperer

    Apr 29, 2011
    United States
    Dr. Wahwee's castle
    Still a better effort than Nintendo's lack of VC on the Switch.
  13. BL4Z3D247

    BL4Z3D247 GBAtemp Stoner

    Oct 22, 2008
    United States
    I'm so high, I don't even know!
    Why not just optimized JSNES to run better on the Switch's browser and then make a designated webpage to host it on?

    The source is here...

    Nice find regardless. I hope to see this go somewhere. :)
  14. Sasori

    Sasori GBAtemp Advanced Maniac

    Jan 28, 2015
    United States
    All javascript emulators work on the switch. Albeit very poorly. I've used and recorded them when I released DNSwitch when the switch first came out
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice