libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.88k stars 1.83k forks source link

Are the Famicom NSO controllers supported? #7787

Closed Bitwolfies closed 1 year ago

Bitwolfies commented 1 year ago

Support for the NES variant was added a long time ago, but it's unclear if the Famicom variant is supported. One of the two controllers in the pack has a microphone which is a fairly large difference. Just wondering if its supported since I have a set on the way and once arrived can contribute any info needed to get them in if they're not already. Thanks!

slouken commented 1 year ago

If they don't work out of the box, I can help you get them set up.

Bitwolfies commented 1 year ago

If they don't work out of the box, I can help you get them set up.

Thanks, once they arrive ill let you know, any chance the mic will work out of the box or is that gonna require some extra legwork?

slouken commented 1 year ago

Usually controller microphones show up as audio devices to the OS.

Bitwolfies commented 1 year ago

Hey @slouken, controllers are here! My results:

They show up as "HVC Controller (1) and (2)" respectively.

Deck does recognize them as sideways Switch Controllers, and A and B work as expected, though Steam shows option to "combine them" like joycons, dunno if the NES ones do that.

Mic is not working.

If there's any dumps you need, say to give them a more friendly name. let me know!

slouken commented 1 year ago

Take a look at SDL_hidapi_switch.c, and look for code dealing with k_eSwitchDeviceInfoControllerType_NESLeft and k_eSwitchDeviceInfoControllerType_NESRight. These controllers need to be handled the same way.

Can you tell me what ctx->m_eControllerType is inside of BReadDeviceInfo(), for each of them? Can you also link to a picture of the exact model you have?

Bitwolfies commented 1 year ago

Take a look at SDL_hidapi_switch.c, and look for code dealing with k_eSwitchDeviceInfoControllerType_NESLeft and k_eSwitchDeviceInfoControllerType_NESRight. These controllers need to be handled the same way.

Can you tell me what ctx->m_eControllerType is inside of BReadDeviceInfo(), for each of them? Can you also link to a picture of the exact model you have?

No problems doing either, but I do need a bit of guidance, if you tell me which command to gather the BReadDeviceInfo, Ive got no problems sending it over.

Bitwolfies commented 1 year ago

"Right" controller, faded text is M9WF200 "Left" is M9WF100. Left also goes by HAC-035 PXL_20230628_052327495.jpg

slouken commented 1 year ago

Can you apply this patch to SDL, and then build and run the testgamepad test program? If you're having trouble with that, go ahead and send me e-mail at slouken@libsdl.org and we can schedule a Zoom call to walk through the process.

diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c
index 438c9c62c..9a184f492 100644
--- a/src/joystick/hidapi/SDL_hidapi_switch.c
+++ b/src/joystick/hidapi/SDL_hidapi_switch.c
@@ -591,6 +591,7 @@ static SDL_bool BReadDeviceInfo(SDL_DriverSwitch_Context *ctx)
         if (WriteSubcommand(ctx, k_eSwitchSubcommandIDs_RequestDeviceInfo, NULL, 0, &reply)) {
             // Byte 2: Controller ID (1=LJC, 2=RJC, 3=Pro)
             ctx->m_eControllerType = CalculateControllerType(ctx, (ESwitchDeviceInfoControllerType)reply->deviceInfo.ucDeviceType);
+SDL_Log("CONTROLLER TYPE: %d\n", ctx->m_eControllerType);

             // Bytes 4-9: MAC address (big-endian)
             SDL_memcpy(ctx->m_rgucMACAddress, reply->deviceInfo.rgucMACAddress, sizeof(ctx->m_rgucMACAddress));
Bitwolfies commented 1 year ago

Unless I did something wrong, its not happy with the patch. Screenshot_20230628_121125 Screenshot_20230628_121144

slouken commented 1 year ago

Remove the + at the beginning of the line

Bitwolfies commented 1 year ago

Woof, that was embarrassing. Regardless its built now, though I have no idea where the testgamepad program is. For building I just followed the first set of instructions found here. https://wiki.libsdl.org/SDL2/Installation

slouken commented 1 year ago

It's in the test directory. It's easier to build with Visual Studio or if you're using CMake you can pass -DSDL_TESTS=ON to build the tests as well.

Bitwolfies commented 1 year ago

Alright, built with cmake with the test flag passed. how should I run it and what data do you need?

slouken commented 1 year ago

If you're not running in Visual Studio you may need to get DebugView to see the debug output, but just run testgamepad, then connect the left controller, disconnect it, then connect the right controller, and copy the debug output here.

Thanks!

Bitwolfies commented 1 year ago

Right, though I'm on Linux so I'll just have to find where the program got stashed, thanks!

slouken commented 1 year ago

Oh, if you're on Linux it's easier, just cd $(dirname $(find . -name testgamepad)) && ./testgamepad

Bitwolfies commented 1 year ago

INFO: Nintendo Switch Joy-Con 0: HVC Controller (2), /dev/hidraw4 (guid 030096757e0500000720000000006808, VID 0x057e, PID 0x2007, player index = 0)

Bitwolfies commented 1 year ago

INFO: Nintendo Switch Joy-Con 0: HVC Controller (1), /dev/hidraw4 (guid 030096857e0500000720000000006807, VID 0x057e, PID 0x2007, player index = 0)

Bitwolfies commented 1 year ago

Inputs are:

Controller 1: Dpad, Start/select, A, B, ZL, ZR Controller 2: Dpad, A, B, Zl, ZR, Mic, Volume slider.

slouken commented 1 year ago

Can you update code and see if they're recognized properly? This change should have what you need: https://github.com/libsdl-org/SDL/commit/baa9c57581490bd9cdefabb213e7cb6d0c30b296

slouken commented 1 year ago

(Side note, could you also tell me the uninstall command for this build of sdl? Thanks!)

If you haven't done make install, it isn't installed, you can just delete the SDL directory. If you have done make install, then make uninstall should take care of uninstalling it.

slouken commented 1 year ago

Can you please let me know if this change works properly for you? If so, I'll merge it into the SDL used by Steam.

Bitwolfies commented 1 year ago

Sorry for leaving you hanging, got hit with a nasty fever, I'll compile as soon as I can. Thanks for all your patience.

Bitwolfies commented 1 year ago

Seems to be fine, let me know when it hits steam beta so I can test it out on my deck as well.

slouken commented 1 year ago

Thanks! I hope you feel better soon!