libretro / flycast

Flycast is a multiplatform Sega Dreamcast emulator. NOTE: No longer actively developed, use upstream repo for libretro from now on - https://github.com/flyinghead/flycast
http://reicast.com
GNU General Public License v2.0
155 stars 78 forks source link

L2 button always mapped to L Trigger #835

Closed jstolarek closed 2 years ago

jstolarek commented 4 years ago

I recently upgraded from RetroArch 1.7.3 and flycast 4565fe0 to a RetroArch 1.8.5 (unstable compiled from sources, https://github.com/libretro/RetroArch/commit/e2378680ef282c8fd935f7ee52ec9800d4568f36) and flycast 11c4008. I kept my old retroarch.cfg but deleted retroarch-core-options.cfg and everything from the config directory. After the upgrade the L2 pad button is not handled correctly in Dreamcast games (I have not tested Naomi).

I have a HORI Fighting Commander pad with the following entries in the autoconfig file:

input_b_btn = "0"
input_y_btn = "2"
input_select_btn = "6"
input_start_btn = "7"
input_up_btn = "h0up"
input_down_btn = "h0down"
input_left_btn = "h0left"
input_right_btn = "h0right"
input_a_btn = "1"
input_x_btn = "3"
input_l_btn = "4"
input_r_btn = "5"
input_l2_axis = "+2"
input_r2_axis = "+5"
input_l3_btn = "9"
input_r3_btn = "10"
input_menu_toggle_btn = "8"

I would like to configure input in such a way that R1 corresponds to L trigger and and R2 corresponds to R trigger - in Capcom fighting games this will be an equivalent of R1 standing for strong punch and R2 for strong kick. I want L1 and L2 buttons on the pad to do nothing. Let's say I load Capcom vs SNK 2, go into the training mode, then go into the Quick Menu -> Controls -> Port 1 Controls, and set the buttons as described above. Here's a screenshot:

1

I save the remap; config/remaps/Flycast.rmp now contains:

input_libretro_device_p1 = "1"
input_libretro_device_p2 = "1"
input_player1_analog_dpad_mode = "0"
input_player1_btn_l2 = "-1"
input_player1_btn_r = "12"
input_player2_analog_dpad_mode = "0"

However, while the R1 and R2 buttons work as intended, the L2 button also maps to a strong punch (the same as R1), despite menu displaying it maps to nothing. If I set L2 to map to A - which should be a weak kick - the game still maps it to a strong punch. If I set L2 to map to Analog Y- then pressing the button results in a strong punch but holding it results in character jumping, so it's like the button is mapping two to different inputs.

Now, if I delete the following line from a remap file:

input_player1_btn_l2 = "-1"

and go to controls configuration, the entry for L2 shows that it maps to L Trigger (previously it would show ---, although in practice it mapped to an L Trigger). Setting it back to --- restores the deleted line from the remap file, but does not remove the actual mapping, i.e. L2 still results in a strong punch.

Another interesting behaviour concerns the L1 button settings. If I highlight the L1 entry in the button configuration menu and press right it switches from --- to L Trigger. But when I now press left it does not switch back to ---, instead it switches to Y. If I press left until L1 is set to --- again and save the remap, the remap file will have an extra line:

input_player1_btn_l = "-1"

which it didn't have previously, although technically the setting is the same as it was, i.e. ---.

For the sake of completeness here's a screenshot from general RA input settings for player 1:

2

jstolarek commented 4 years ago

I did some more testing and realised that this bug was actually present before the upgrade, i.e. on RA 1.7.3 and flycast 4565fe0. I think I never realised because I had old button rempas that I never messed with.

jstolarek commented 4 years ago

I tried debugging this a little bit but only ended more confused. Assume settings as on the first screenshot, i.e. R1 -> L Trigger, R2 -> R Trigger. Recall that in this setting L2 also maps to L trigger. Now if I flip the "Digital triggers" option then R1, R2 and L2 buttons on the pad don't do anything, whereas L1 button suddenly acts as L trigger.

Anyway, here's what the code says:

// -- analog triggers
lt[port] = get_analog_trigger(ret, input_cb, port, RETRO_DEVICE_ID_JOYPAD_L2 ) / 128;
rt[port] = get_analog_trigger(ret, input_cb, port, RETRO_DEVICE_ID_JOYPAD_R2 ) / 128;

It looks like the core always reads L2 and R2 regardless of how the mapping is set. If I unset mapping for R2 in the controls menu the R2 button on the pad still maps to R trigger, i.e. the game responds to the button being pressed.

flyinghead commented 4 years ago

I'm as confused as you are. But I think this may be due to RetroArch limitations. First the dual nature (analog or digital depending on the controller) of triggers confuses RA. On linux I have to manually edit retroarch.cfg for the analog triggers to work, otherwise digital triggers take precedence.

Flycast always uses RETRO_DEVICE_ID_JOYPAD_L2/R2 for dreamcast triggers because they are the only analog triggers (L1/R1 and L3/R3 being digital iirc). Ideally, if you map a digital input input to L2 or R2, RA should simuiate an analog response on L2/R2 but it's probably just mapping it to the digital L2/R2 instead.

However digital triggers should work in this configuration.

barbudreadmon commented 4 years ago

Same here, i think it might be a retroarch issue due to the mix of input bitmask + analog + digital

flyinghead commented 4 years ago

I think I got it to work (on my machine at least). I didn't change my input binding (Settings -> Input) but I used the remap menu (Quick Menu -> Controls). I mapped R1 to R Trigger and R2 to L Trigger and it seems to work fine. And you can have a per-game setting.

image

I also enabled Digital Triggers. Not sure it makes a difference.

jstolarek commented 4 years ago

Flycast always uses RETRO_DEVICE_ID_JOYPAD_L2/R2 for dreamcast triggers because they are the only analog triggers (L1/R1 and L3/R3 being digital iirc).

As a user I would expect that if I map L/R triggers to digital buttons then pressing these buttons will be an equivalent of maximally pushing the trigger. My understanding is that this is what the "digital triggers" option is intended to do - but it does not seem to work as intended.

I mapped R1 to R Trigger and R2 to L Trigger and it seems to work fine.

Indeed, that works as intended, except that in this setup L2 also maps to L trigger. This isn't game-breaking, but it's definitely not the way things are supposed to be.

I also enabled Digital Triggers. Not sure it makes a difference.

As mentioned, if I enable digital triggers all trigger mappings don't work. Sorry, that's imprecise. L1 maps to L trigger, whereas R1, R2 and L2 don't map to anything. EDIT: which is the exact opposite to the situation when this option is disabled.

flyinghead commented 4 years ago

Actually I spoke a tad bit too fast. There's also a problem with the digital triggers option since it uses L1/R1 for 100% press and R2/L2 for 50%. That's why it's not currently working.

Since this is making more harm than good I'm going to push a fix to only use R2/L2 so whatever is mapped to L Trigger and R Trigger will work.

jstolarek commented 4 years ago

Just tested your fix. "Digital triggers" now work as expected when enabled. No change when "Digital triggers" are disabled.

Shoegzer commented 4 years ago

@jstolarek In case it helps, just wanted to mention that a while ago I documented some of the outstanding input-related issues remaining to be worked out wrt analog triggers, as I discovered them to occur at the RA level.

flyinghead commented 4 years ago

Yes, I believe the remaining issue(s) with analog triggers is probably at the RA level. The cores have no knowledge of the current input bindings or remappings. This is all handled by the frontend.

However, for this kind of application, the digital trigger option is probably the way to go.

jstolarek commented 4 years ago

@Shoegzer thanks for the link - it would be surprising if i was the first person to run into the problem. One interesting thing to note is that the pad that I'm using - Hori Fighting Commander - does not have analog triggers. Both L2 and R2 are actually (physically) buttons on this pad. However, they map to logical axes with autoconfig saying:

input_l2_axis = "+2"
input_r2_axis = "+5"

That is how the system sees them - they are registered as axes and pressing any of these buttons is treated as fully pushing a trigger. Thus I don't understand your comment (https://github.com/libretro/RetroArch/issues/6920#issuecomment-452411556) about UI mapping these axes to digital buttons instead. How would that be possible if the system does not see them as digital buttons?

Shoegzer commented 4 years ago

@jstolarek I'm using linux with ds4 pads, which as you may know use analog L2 and R2 triggers. When I configure them via the RA UI, they do not map to the analog values of +2 and +5 as they should, but rather the values corresponding to digital buttons - so at least on my setup, they are indeed seen that way. Hand-editing retroarch.cfg to the correct values (as @flyinghead did from his note above) does work, but is of course suboptimal.

barbudreadmon commented 4 years ago

@jstolarek actually i was surprised when i saw the l2/r2 axis in your autoconfig file, i own 2 Hori Fighting Commander (using this autoconfig : https://github.com/libretro/retroarch-joypad-autoconfig/blob/master/udev/HORI_Fighting_Commander_4.cfg) and they don't have analog triggers either. The fact not many people did run into this problem might be explained by the fact the autoconfig db covers most controllers, it could be nice to add yours to avoid this problem in the future since it seems to be a different model from mine ?

jstolarek commented 4 years ago

@Shoegzer:

When I configure them via the RA UI, they do not map to the analog values of +2 and +5 as they should, but rather the values corresponding to digital buttons

That's the part that I find confusing. It sounds as if a trigger is seen in the system as both an axis and a digital button at the same time. Is that really the case with DS4? It isn't like that with my pad.

@barbudreadmon, your autoconfig is for Fighting Commander 4:

4

I have Fighting Commander 5:

5

I don't use the official autoconfig repo, rather I create my own autoconfig files using the method described in the documentation. It seems that at least in my case RA has done the right thing and identified L2 and R2 as axes and not as buttons. I definitely did not edit my autoconfig as I wasn't aware of the problem at all until yesterday :-)

Shoegzer commented 4 years ago

@jstolarek: That is indeed really the case, as I suspect it would be with any analog triggers under linux/udev and the RA UI.

The only controllers I'm aware of that combine both an analog axis and button into one trigger are original gamecube controllers (where pressing in the analog trigger completely until it "clicks" will register as a button). That said, I don't think this RA issue is due to an attempt to accommodate such pads; rather I suspect something was simply missed in the udev mapping code. Just a guess.

flyinghead commented 4 years ago

With udev on linux, the DS3 analog triggers do react both as an analog axis (ABS_RZ) and as a digital button (BTN_TR2)..

jstolarek commented 4 years ago

I suspect it would be with any analog triggers under linux/udev and the RA UI.

Does not happen with Logitech F310, which has proper analog triggers. These are seen as axes only, there are no buttons associated with them.

Shoegzer commented 4 years ago

Well are you using linux with udev joypad driver?

jstolarek commented 4 years ago

Yes.

input_driver = "udev"
input_device = "HORI Fighting Commander"
input_device_display_name = "HORI Fighting Commander"
input_vendor_id = "3853"
input_product_id = "134"
input_device = "Logitech Gamepad F310"
input_driver = "udev"
input_vendor_id = 1133
input_product_id = 49693
Shoegzer commented 4 years ago

Not sure then. I just re-tested with a build of RA I compiled last week. Attempting to set the ds4's L2 trigger results in RA setting it to "6" rather than "+2" as it should. Only hand-editing the cfg fixes this.

jstolarek commented 4 years ago

I believe you that this is what RA does. But do you have a tool that would allow you to read button outputs outside of RA? I am using Trinity Desktop Environment and it has a joystick testing tool as part of its configuration panel:

joy

This is for the Fighting Commander. I was holding L1 and L2 when making this screenshot. L1 is registered as button 5, L2 as axis 3 (reported as maximal value on that axis). Compare with depressed R2 on axis 6, reported as maximal negative value. Logitech F310 behaves the same, with the obvious difference that L2 and R2 are proper analog triggers that take any values between the minimal and maximal values.

Shoegzer commented 4 years ago

I use jstest with gtk interface. Pressing L2 for example registers as both a button press with value "6" as well as axis 2 between minimal and maximal values, as shown:

pic

jstolarek commented 4 years ago

Wow. This is the first time I am actually seeing something like this. My assumption would be that this is an exception rather than a rule (which of course doesn't mean it shouldn't be fixed).

jstolarek commented 4 years ago

@flyinghead would it be possible to make "Digital triggers" per-controller setting?

clebercasali commented 4 years ago

Looks like the MAME bug that maps L2 and R2 to TAB and F11. Argh!

After struggling with this for more than one hour, I have figured out a workaround.

In Flycast.rmp :

input_libretro_device_p1 = "1025"
input_libretro_device_p2 = "1025"
input_libretro_device_p3 = "1025"
input_libretro_device_p4 = "1025"

This changes the device from 'Controller' to 'Arcade Stick' and the bug is gone. For some reason if I try to change this using the GUI I can't remap anything.

crocket commented 3 years ago

I just hit this issue after submitting https://github.com/libretro/retroarch-joypad-autoconfig/blob/dadf40810bb64a96dd176b3435d1993a07c057ef/udev/HORI_Fighting_Commander_for_Nintendo_Switch.cfg However, turning on digital trigger option in flycast libretro core works around the issue wonderfully. In my case, the problem was that if I re-map ZL (axis) (left trigger) to right trigger in Quick Menu > Controls > Port 1 Controls, ZL is actually mapped to right trigger and left trigger simultaneously. This broke chu chu rocket which has to distinguish left trigger and right trigger.

My controller is Hori Fighting Commander for Nintendo Switch. Hori Fighting Commander for Nintendo Switch - 01 Hori Fighting Commander for Nintendo Switch - 02

What should have been right trigger is actually ZL which is equivalent to left trigger. ZR is right trigger and exists as a button on the pad.

On evtest, ZL is ABS_Z, and ZR is ABS_RZ.

Event: time 1633854831.690311, type 3 (EV_ABS), code 2 (ABS_Z), value 255
Event: time 1633854831.690311, -------------- SYN_REPORT ------------
Event: time 1633854831.830301, type 3 (EV_ABS), code 2 (ABS_Z), value 0
Event: time 1633854831.830301, -------------- SYN_REPORT ------------
Event: time 1633854833.126318, type 3 (EV_ABS), code 5 (ABS_RZ), value 255
Event: time 1633854833.126318, -------------- SYN_REPORT ------------
Event: time 1633854833.258320, type 3 (EV_ABS), code 5 (ABS_RZ), value 0
Event: time 1633854833.258320, -------------- SYN_REPORT ------------
barbudreadmon commented 2 years ago

This is a retroarch issue, closing in favor of https://github.com/libretro/RetroArch/issues/12596