RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    Howto: fix broken 360 Controller mapping in Moonlight

    Scheduled Pinned Locked Moved Help and Support
    moonlightxbox360mappingsld2controllermap
    4 Posts 2 Posters 1.8k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      tuxophil
      last edited by tuxophil

      tl;dr: My Xbox 360 Controller (wireless, connected via original USB receiver bundled with the controller) had a wrong config for Moonlight. Here's how to fix it. This post has been updated (marked with UPD).

      Setup: Official retropie image installed on a Raspberry Pi 4. (Currently 4.8/Buster).
      Controller: Xbox 360 Controller connected wirelessly and showing up in lsusb as follows:
      Bus 001 Device 005: ID 045e:0719 Microsoft Corp. Xbox 360 Wireless Adapter
      Driver (UPD): Retropie's default out-of-the-box patched(!) xpaddriver is in use.
      Issue: The controller works fine in various libretro emulators (after initial config in EmluationStation, not sure if needed), but it is messed up in Moonlight. Among others the dpad axes are interchanged....

      (UPD) The reason is that retropie uses a patched xpad driver instead of the kernel's default xpad. The proper solution to my problem is to simply remove the patched xpad via the retropie-setup menu.

      Below you'll find my first "solution". I leave it here because it may still be useful for other controllers.

      The reason is that Moonlight has its own controller database in /opt/retropie/supplementary/moonlight/share/moonlight/gamecontrollerdb.txt. There are mappings for various revisions of the controller:

      # Game Controller DB for SDL in 2.0.16 format
      # Source: https://github.com/gabomdq/SDL_GameControllerDB
      (...)
      030000005e0400009102000007010000,Xbox 360 Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux,
      030000005e040000a102000000010000,Xbox 360 Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux,
      (...)
      

      The first field is an SDL-generated (supposedly) unique identifier (guid).

      In order to find out my controller's guid and actually remap it in a userfriendly GUI I compiled SDL's controllermap utility. I can't thank @isrnick enough for his tutorial for PPSSPP controller mapping. I just had to adapt it to the SDL version currently installed on my system. (The 2.0.16 mentioned in the config threw me of here at first. It wouldn't compile.) There is also this thread, but I'm not sure if this ever got solved and I'm wondering about the location of the controller database which differs from the one here.

      Step-by-step:

      1. Either quit EmulationStation or connect via SSH as pi.
      2. Check your currently installed libsdl version:
        apt search libsdl2-dev | grep installed
        (2.0.10 in my case.)
      3. wget http://libsdl.org/release/SDL2-2.0.10.tar.gz
      4. tar -zxvf SDL2-2.0.10.tar.gz
      5. cd SDL2-2.0.10/test
      6. ./configure
      7. make controllermap

      I was pleasantly surprised that I didn't have to do any dependency hunting for the compilation process, it's just a teeny tiny compilation that won't take long either.

      1. If you did the steps above via ssh, now is the time to actually quit EmulationStation... (Still no physical keyboard needed if you're using ssh.)
      2. Still in /home/pi/SDL2-2.0.10/test launch the GUI app to map the buttons and store the config string in /home/pi/my360.txt.
        ./controllermap >> ~/my360.txt
      3. Show the generated config: cat ~/my360.txt. Here's my output:
      030000005e040000a102000000010000,Xbox 360 Wireless Receiver,platform:Linux,a:b0,b:b1,x:b2,y:b3,back:b8,guide:b10,start:b9,leftstick:b11,rightstick:b12,leftshoulder:b4,rightshoulder:b5,dpup:b15,dpdown:b16,dpleft:b13,dpright:b14,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,
      
      1. It's probably best to check if an entry for this guid already exists in the database. I'm not sure what happens if there are duplicate entries...
        grep 030000005e040000a102000000010000 /opt/retropie/supplementary/moonlight/share/moonlight/gamecontrollerdb.txt
      2. In my case there was already an existing entry for this guid, so I commented it out (adding an # at the beginning of that line) and added my new config line. You may use nano or some other text editor of your liking to do this: nano /opt/retropie/supplementary/moonlight/share/moonlight/gamecontrollerdb.txt. Here's the result:
      # wrong config 030000005e040000a102000000010000,Xbox 360 Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux,
      030000005e040000a102000000010000,Xbox 360 Wireless Receiver,platform:Linux,a:b0,b:b1,x:b2,y:b3,back:b8,guide:b10,start:b9,leftstick:b11,rightstick:b12,leftshoulder:b4,rightshoulder:b5,dpup:b15,dpdown:b16,dpleft:b13,dpright:b14,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,
      

      That should be all. Just restart emulationstation and have fun. :-)

      1. (optional) Clean up: rm -rf /home/pi/SDL2-2.0.10*
      1 Reply Last reply Reply Quote 1
      • T
        tuxophil
        last edited by

        Oh well, I did some more reading on controller support in linux. Lots of reading. Until I found this bug report:
        https://github.com/RetroPie/RetroPie-Setup/issues/3379

        It seems that my issues are well known and due to an incorrectly patched xpad (for historic reasons). Removing retropie's xpad driver via retropie's package management menu should be all that's needed to fix it! It would then revert to the kernel's default xpad driver. It must be remapped though in EmulationStation.
        I'll try that later and update the initial post if this indeed solves the issue in a cleaner way.

        T 1 Reply Last reply Reply Quote 0
        • T
          tuxophil @tuxophil
          last edited by

          And just now I've found that a note has even been added to the FAQ:
          https://retropie.org.uk/docs/FAQ/?h=faq#my-xbox-controller-is-not-working-properly-with-moonlight-embeddedppsspp
          But there is no word on this issue in the actual documentation for the 360 controller: https://retropie.org.uk/docs/Xbox-360-Controller/

          The wording in the FAQ is also suboptimal:

          RetroPie's xpad Xbox controller driver is configured to map the controller's LT/RT as buttons - insteads of axis - and this option makes the controller not working properly in applications that use SDL gamepad mappings.

          This sounds as if only the triggers were concerned. But it's the whole controller that is messed up!

          I'd kindly like to suggest to:

          1. Move the warning from the FAQ to the 360 Controller page and link to it from the FAQ or the Moonlight and ppsspp docs.
          2. Change the warning text to insist that it completely messes up the controller in sdl games.
          3. Add a link to the github bug.
          4. Suggest to remove the 'xpad' driver. (I'll test to confirm)
          5. In the next major release or so fix this once and for all by dropping the patch that breaks xpad.

          Let me just say that I learned a lot over the last hours...

          L 1 Reply Last reply Reply Quote 0
          • L
            Larkas @tuxophil
            last edited by

            Just a heads-up: removing xpad might break the controller in emulationstation and elsewhere. In my case, the triggers weren't being properly parsed, and as such they couldn't be properly mapped. Hence, I wasn't able to simply remove said driver. That being said, the original solution by @tuxophil DOES work properly, and as such I would still recommend it. Keep in mind, though, that the command at step "8" requires a declaration about which controller you want to map. As such, a correct command might be ./controllermap 0 >> ~/my360.txt, if your X360 gamepad is in slot 0. Running just ./controllermap will show which controllers are connected, so use your gamepad's slot from that list.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post

            Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

            Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.