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

Joypad subsystem #430

Merged
merged 49 commits into from
Sep 15, 2023
Merged

Joypad subsystem #430

merged 49 commits into from
Sep 15, 2023

Conversation

meeq
Copy link
Contributor

@meeq meeq commented Sep 2, 2023

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.

Copy link
Collaborator

@rasky rasky left a comment

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.

include/joypad.h Outdated Show resolved Hide resolved
include/joypad.h Outdated Show resolved Hide resolved
include/joypad.h Show resolved Hide resolved
include/joypad.h Show resolved Hide resolved
include/joypad.h Show resolved Hide resolved
src/joypad.c Outdated Show resolved Hide resolved
src/joypad.c Outdated Show resolved Hide resolved
include/joypad.h Outdated Show resolved Hide resolved
src/joypad.c Outdated Show resolved Hide resolved
src/joypad.c Outdated Show resolved Hide resolved
Copy link
Collaborator

@rasky rasky left a comment

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...

include/joybus_accessory.h Outdated Show resolved Hide resolved
include/joypad.h Outdated Show resolved Hide resolved
include/joypad.h Outdated Show resolved Hide resolved
include/libdragon.h Show resolved Hide resolved
include/joypad.h Outdated Show resolved Hide resolved
include/joybus.h Outdated Show resolved Hide resolved
src/joybus_accessory.c Show resolved Hide 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
4 checks passed
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.

3 participants