Skip to content
This repository was archived by the owner on Oct 1, 2026. It is now read-only.

Joypad subsystem - #430

Merged
rasky merged 49 commits into
DragonMinded:unstablefrom
meeq:joypad-subsystem
Sep 15, 2023
Merged

rasky merged 49 commits into
DragonMinded:unstablefrom
meeq:joypad-subsystem

Conversation

@meeq

@meeq meeq commented Sep 2, 2023 •

Copy link
Copy Markdown
Contributor

Stacked on top of #429 which incorporates #426, #427, #428
Finally resolves #218

Highlights

  • Introduces a new Joypad subsystem that is intended to replace the Controller subsystem.
    • Based on my working draft repository: https://github.com/meeq/JoypadTest-N64/
    • Adopts a new abstraction to unify N64 and GameCube joypad input styles into a more-common interface.
    • Intends to replace the usage of synchronous Joybus commands with an asynchronous model so that games aren't burning CPU cycles waiting on a slow serial interface.
  • Deprecates the Controller subsystem and replaces it with a compatibility shim
  • Refactors the inspector to use joypad_read_n64_inputs_sync instead of controller_read
  • Includes a new joypadtest example ROM to demonstrate usage
  • Intentionally does not update existing examples in an attempt to ensure compatibility
    • I intend on updating the examples once the Joypad subsystem is merged and stable

Abstraction details

Supported Controllers

Nintendo 64

The standard Nintendo 64 controller has fewer (and different) inputs than a GameCube controller:

  • Missing X & Y buttons
  • Missing a C analog stick; instead there are 4 digital C directional buttons
  • Does not have any pressure sensitive buttons or triggers

GameCube

GameCube controllers must be connected using a "passive adapter" that can be created by splicing the Joybus data pin on a GameCube controller plug into the Joybus data pin on the N64 console.

The GameCube controller has more (and different) inputs than a Nintendo 64 controller:

  • Has X & Y buttons
  • Has pressure-sensitive L & R triggers
  • Missing C directional buttons; instead there is a C analog stick
  • Some have pressure-sensitive A & B buttons
    • Analog A & B is non-functional on most GameCube controllers (official and third party)

Compatibility compromises

  • Nintendo 64 controllers cannot press X or Y buttons
  • Nintendo 64 controllers (attempt to) emulate analog L & R triggers using digital inputs
  • Nintendo 64 controllers (attempt to) emulate analog C stick using digital inputs
  • GameCube controllers (attempt to) emulate C buttons based on analog C stick position
    • Players will not be able to press C-Left & C-Right or C-Up & C-Down simultaneously
  • GameCube controllers always use analog mode 3 and will not read analog A & B inputs

Rumble

Rumble motor control is supported for both N64 and GameCube controllers with a common API.

For Nintendo 64 controllers, this requires a Rumble Pak accessory.

For GameCube controllers, the 5-volt VCC pin on the controller plug must be connected to an external power source.

Still to do

  • Resolve deprecation warnings in mempak.c
  • Resolve deprecation warnings in tpak.c
  • Improve async APIs for Joypad accessories
    • Currently only the sync APIs are exposed
  • Improve documentation
  • Lots more testing

Under consideration

  • Deadzone handling for analog sticks
  • Deprecate the mempak subsystem in favor of an async version
  • Deprecate the tpak subsystem in favor of an async version
  • Refactor the eeprom and eepromfs subsystems to be async
  • Refactor the rtc subsystem to be async
  • Port over the Bio Sensor subsystem from my working draft repository
  • Implement a pointer subsystem to properly handle mouse input
  • Figure out what's going on with VRU/VRS support
    • There is still one lingering function in controller.c that is only used by the vrutest example.
    • I would strongly prefer to deprecate execute_raw_command and offer a proper VRU/VRS API.
    • The code that exists today is completely opaque and appears to be incomplete.

@rasky rasky left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @meeq, this is FANTASTIC work. I'm in awe at the amount of work you poured into this, and the new library is going to be so great to work with.

I've started a review from joypad.h and joypad.c, mostly around the public API. I'll do the review in parts over several days.

Comment thread include/joypad.h Resolved
Comment thread include/joypad.h Resolved
Comment thread include/joypad.h Resolved
Comment thread include/joypad.h Resolved
Comment thread include/joypad.h Resolved
Comment thread src/joypad.c Resolved
Comment thread src/joypad.c Resolved
Comment thread include/joypad.h Resolved
Comment thread src/joypad.c Resolved
Comment thread src/joypad.c Resolved

@rasky rasky left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for all your work. This is round two, still not fully done. Takes a while...

Comment thread include/joybus_accessory.h Resolved
Comment thread include/joypad.h Resolved
Comment thread include/joypad.h Resolved
Comment thread include/libdragon.h Resolved
Comment thread include/joypad.h Resolved
Comment thread include/joybus.h Resolved
Comment thread src/joybus_accessory.c Resolved
@meeq
meeq marked this pull request as ready for review September 15, 2023 23:22
@rasky
rasky merged commit 9f6f60e into DragonMinded:unstable Sep 15, 2023
@meeq
meeq deleted the joypad-subsystem branch February 1, 2025 02:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants