MAME4iOS icon indicating copy to clipboard operation
MAME4iOS copied to clipboard

iCade and joystick direction problem

Open GeorgeMcMullen opened this issue 2 years ago • 4 comments

Hello,

I'm currently running an iPad 9th Generation on iPadOS 15.5. I have an Ion iCade which is configured and verified to be working. If I open up Notes and use the joystick and buttons, it outputs the correct keys for key-down and key-up sequences as per the documentation and code comments (https://github.com/yoshisuga/MAME4iOS/blob/0a3641e5ceca555d6928147c956788a74bb98e53/iOS/KeyboardView.m#L123). I'm compiling and installing myself via XCode.

The problem arises when I try to use the joystick. The direction I press the joystick does not correlate to the graphical joystick's direction on the screen or what gets sent to MAME. If I switch the view to D-Pad, the directions do match, but the incorrect joystick direction is still being sent. Trying to reconfigure MAME does not work because the joystick events are still being sent. Here is what my MAME Player 1 Controls configuration looks like:

  • P1 Up: Joy 1 Right Joy 1 D-Pad Up
  • P1 Down: Joy 1 Left Joy 1 D-Pad Down
  • P1 Left: Joy 1 Down Joy 1 D-Pad Left
  • P1 Right: Joy 1 Up Joy 1 D-Pad Right

Some of my configuration is as follows:

Input Options:

  • Touch Type: I've tried Digital DPAD and Digital Stick
  • Ways: I've tried Auto, 4 Way, and 8 Way
  • External Controller: iCade or compatible

I've not found anything in the code that would cause this. I'd appreciate the help if possible. Let me know if you need any further detail. Thank you!

GeorgeMcMullen avatar Sep 01 '23 09:09 GeorgeMcMullen

After a little more investigation, I found the following lines (in the same file and function as previously mentioned: KeyboardView.m:iCadeKey:

https://github.com/yoshisuga/MAME4iOS/blob/0a3641e5ceca555d6928147c956788a74bb98e53/iOS/KeyboardView.m#L587C2-L588C106

It seems as though the x and y coordinates for the analog joystick are switched, where MYOSD_UP/MYOSD_DOWN is being used for myosd_pad_x and MYOSD_RIGHT/MYOSD_LEFT are being used for myosd_pad_y. Switching x and y seems to resolve the issue, though I don't yet know how this affects other things.

    myosd_pad_y = (myosd_pad_status & MYOSD_UP)    ? +1.0 : (myosd_pad_status & MYOSD_DOWN) ? -1.0 : 0.0;
    myosd_pad_x = (myosd_pad_status & MYOSD_RIGHT) ? +1.0 : (myosd_pad_status & MYOSD_LEFT) ? -1.0 : 0.0;

GeorgeMcMullen avatar Sep 05 '23 11:09 GeorgeMcMullen

Wow this might be totaly busted? If so it has been backward for a while.....

ToddLa avatar Sep 05 '23 18:09 ToddLa

Yeah. The iCade is pretty old though, so testing new functionality against it is probably getting hard and harder. The prior git blame shows that the x and y were correct, so it was probably just a simple mistake.

Also I found similar code in AnalogStick.m but the directions are correct. So it's probably safe to get X and Y in the proper place.

https://github.com/yoshisuga/MAME4iOS/blob/master/iOS/AnalogStick.m#L187C1-L188C114

I created a pull request to fix the code: https://github.com/yoshisuga/MAME4iOS/pull/449

GeorgeMcMullen avatar Sep 06 '23 20:09 GeorgeMcMullen

I hit the same problem, found this issue, and was very grateful for @GeorgeMcMullen's PR which fixed the issue for me. Thanks! It'd be great to merge the PR.

simonwatson avatar Sep 25 '23 07:09 simonwatson