Homebrew JSNES JavaScript NES emulator may be working on switch

Suso_

Member
OP
Newcomer
Joined
Apr 23, 2017
Messages
6
Trophies
0
XP
58
Country
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):
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?
 

MashedPotatos

Well-Known Member
Newcomer
Joined
Apr 10, 2017
Messages
77
Trophies
0
Age
28
Location
pp
XP
265
Country
Canada
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
 

Suso_

Member
OP
Newcomer
Joined
Apr 23, 2017
Messages
6
Trophies
0
XP
58
Country
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

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.
 

NSStack

Member
Newcomer
Joined
Apr 24, 2017
Messages
12
Trophies
0
XP
81
Country
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,

Suso_

Member
OP
Newcomer
Joined
Apr 23, 2017
Messages
6
Trophies
0
XP
58
Country
I figured out a way to find the keycodes we need:

I made this simple test html:
HTML:
<!DOCTYPE html>
<html>

<title>Test KeyCodes</title>

<body>

<p id="output">Key-Keycode</p>

<script>
document.onkeydown = function (e) {
    e = e || window.event;
    var code = e.keyCode;
    document.getElementById("output").innerHTML = document.getElementById("output").innerHTML  + "; " + String.fromCharCode(code) + "-" + code;
};
</script>

</body>

</html>

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_,
  • Like
Reactions: dragonslayer817

Suso_

Member
OP
Newcomer
Joined
Apr 23, 2017
Messages
6
Trophies
0
XP
58
Country
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.

If it's about joycons, you should ask @shinyquagsire23
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.
I already got some keyCodes, but I think i should ask @shinyquagsire23 anyways. Maybe he knows how to get the other buttons working...
 
  • Like
Reactions: Gungerino
D

Deleted User

Guest
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):
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?
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
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    K3Nv2 @ K3Nv2: https://youtu.be/IihvJBjUpNE?si=CsvoEbwzNKFf0GAm cool