Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for up to 16bit stick axis values, and signed values (aroma) #44

Open
wants to merge 2 commits into
base: aroma
Choose a base branch
from

Conversation

patters-match
Copy link

@patters-match patters-match commented Oct 26, 2024

Purpose

I set out to add support for the Adaptoid N64-controller-to-USB-HID adapter made by Wish Technologies in around 1999, which was popular during the heyday of the UltraHLE N64 emulator on PC.

Changes

In order to add Adaptoid support I needed to extend controller_patcher to support the following:

  • Stick axis values up to 16bit (Adaptoid uses 12bit, controller_patcher had used 8bits only)
  • Signed axis values (Adaptoid uses a range of -1200 to 1200)
  • Non byte-aligned HID axis reports (Adaptoid packs two 12bit reports into 3 bytes, so the second one starts one nibble into a byte).

Rationale

My aim was to introduce this support without making breaking changes to the schema for existing INI files, and with minimal impact to the existing code. I initially tried changing all the config value types from uint8_t to uint16_t but this seemed too disruptive.

Instead, where I needed additional bytes of precision for existing variables, I added new parameters to capture their most significant bytes (MSB). I wrote additional logic to read in this additional data and to properly sign-extend and cast signed values. I then extended the inputs of the convertAnalogValue function from uint8_t to int32_t type so that they could accommodate the full range of both signed and unsigned 16bit values. I also amended the deadzone and scaling logic to cope with negative values.

Status

  • Working Adaptoid device support when mapped to a Gamepad using hid_to_vpad.
  • When Adaptoid is mapped to a Pro Controller input buffering isn't correct however. If I hold a stick direction it resets to zero input. Inputs are only registered while HID stick data is changing, e.g. running Mario in S-like patterns rather than directly forward. I've spent a long time debugging but I cannot figure this out. There must be some edge case in functionsetProControllerDataFromHID that doesn't apply in setControllerDataFromHID. This behaviour only occurs after I exit hid_to_vpad and apply patches. While I remain in hid_to_vpad the debug logging confirms that all stick movement is polled correctly. I spent a long time reading the Gbatemp forum thread for hid_to_vpad and I did see some other mention of a device not working properly with one type of binding being ok using the other type, so I am inclined to think this is more of a long standing issue which I am unlikely to be able to solve.

Build

I originally made these changes for the Tiramisu build of this library for hid_to_vpad here. I was able to build hid_to_vpad 0.1.1-alpha for aroma with these changes to the aroma branch of controller_patcher, using WUPS 0.7.1. Pacman package versions were as follows:

devkitPPC r45.2-1
wut 1.7.0-1
wut-tools 1.3.5-1

I needed to amend logger.h in hid_to_vpad to remove the extern "C" { parts since that seems to be adequately handled in the current whb logger headers.

Download

  • Download the compiled hid_to_vpad binary and Adaptoid device profile here at Gbatemp.

Testing

  • I have used UDP debug logging to confirm the deadzone logic and sanity of the config and HID data values.
  • These changes work perfectly using an Adaptoid with N64 controller playing the Wii U native port of Super Mario 64.
  • Ship of Harkinian also works fine.
  • I can also confirm that I did not break the existing processing logic for the official Nintendo GameCube controller adapter (unsigned 8 bit axis data).
  • Unfortunately the Adaptoid stick input exhibits issues in the Virtual Console versions of Super Mario 64 and Starfox 64. It seems that if I push fully in a direction on the stick Mario will turn back in the opposite direction. Likewise for flying the craft in Starfox. If I tilt the stick to say 90% range then it's fine - I don't see this behaviour. I do see that this exact issue was already reported long before I made these changes. There was a recommendation to use the N64 emulator INI to limit the stick values to 90 and use a newer emulator binary, which had also been an issue with gc_to_vpad. GameCube controllers are unaffected.
  • Strangely, when considering the above point, the Adaptoid behaves fine in the Virtual Console versions of Mario Kart 64 and F-Zero X. Upon further reading, it seems these use a later version of Nintendo's Virtual Console N64 emulator.
  • For native Wii U software, the Adaptoid works perfectly for Breath of The Wild and for Mario Kart 8.

Misc

I have included my controller INI definition for the Adaptoid in the root folder, demonstrating the new configuration parameters. I realise it should go in the controller_patcher_configs repo but I figured that can wait while this PR is pending.

@patters-match patters-match changed the title Support for up to 16bit stick axis values, and signed values Support for up to 16bit stick axis values, and signed values (aroma) Oct 27, 2024
@patters-match patters-match force-pushed the aroma-improved-axis-support branch from 404eff2 to 63dbd65 Compare October 28, 2024 11:24
@patters-match patters-match force-pushed the aroma-improved-axis-support branch 2 times, most recently from ea5653f to 58d21c2 Compare November 2, 2024 22:34
@patters-match patters-match force-pushed the aroma-improved-axis-support branch from 58d21c2 to 68b1a75 Compare November 4, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant