Overview
TheN64Backend class implements the Joybus protocol for communicating with Nintendo 64 consoles. It handles bidirectional communication over a single data line, responding to console polls and sending controller state.
The N64 backend uses the same Joybus protocol family as GameCube but with a different report format and timing characteristics.
Platform Support
- Raspberry Pi Pico: ✅ Supported (PIO-based)
- Arduino (AVR): ✅ Supported (Nintendo library)
Constructor
Raspberry Pi Pico
Reference to the global input state structure.
Array of pointers to input source objects.
Number of elements in the
input_sources array.GPIO pin number for the Joybus data line (bidirectional communication).
PIO block to use for Joybus communication (pio0 or pio1).
State machine index to use. -1 for automatic allocation.
Program offset in PIO instruction memory. -1 for automatic allocation.
Arduino (AVR)
Expected polling rate from the console in Hz (typically 60-240). Set to 0 to disable delay compensation.
Arduino pin number for the Joybus data line.
The AVR version uses the polling rate to calculate optimal timing delays, ensuring reports are ready just before the next poll.
Configuration Example
Backend ID
SendReport Method
SendReport() method implements the N64 polling response protocol:
Pico Implementation
- Scans slow and medium-speed inputs
- Waits for console poll signal
- Scans fast inputs immediately after poll
- Updates output state based on game mode
- Maps outputs to N64 report format
- Sends report to console
Arduino Implementation
- Scans all inputs at once
- Updates output state based on game mode
- Maps outputs to N64 report format
- Sends report to console
- Delays until just before next expected poll
Report Structure
N64 controllers report the following:Digital Buttons
- A, B
- Z (mapped from buttonR)
- L, R (trigger digital)
- Start
- D-pad: Up, Down, Left, Right
- C-buttons: C-Up, C-Down, C-Left, C-Right
Analog Input
- Control stick: X/Y (signed 8-bit, -128 to +127)
Unlike GameCube, the N64 uses signed 8-bit integers for analog stick values, with 0 representing center position.
C-Button Mapping
The right analog stick is mapped to the C-buttons:This allows modern analog sticks to control games expecting C-button digital input.
Analog Stick Conversion
The firmware converts unsigned 8-bit stick values to signed:Polling Rate and Timing
Pico (PIO-based)
- Uses hardware state machines for precise timing
- Automatically synchronizes with console polls
- Immediate response to poll signal
Arduino (Software-based)
- Requires manual polling rate configuration
- Calculates delay:
(1000000 / polling_rate) - 850 - Leaves 850μs for processing before next poll
- Typical N64 polling rates: 60-240 Hz
GetOffset Method (Pico Only)
Hardware Requirements
Signal Line
- Voltage: 3.3V logic (N64 uses 3.3V natively)
- Pull-up: 1kΩ resistor to 3.3V
- Cable: Connect to controller port data line
Pin Configuration
- Bidirectional data line (input/output)
- Must support fast GPIO operations
- Pico: Any GPIO pin
- Arduino: Pin 2 recommended (interrupt capable)
Usage Example
Console Detection
The N64 backend can be automatically selected based on console detection:Performance Notes
- Pico: Uses hardware PIO for precise timing, minimal CPU overhead
- Arduino: Software-based, requires careful timing calibration
- Polling rates: N64 supports variable rates (60-240 Hz)
- Input lag: Typically under 1ms with proper configuration
Differences from GameCube Backend
| Feature | N64 | GameCube |
|---|---|---|
| Analog range | Signed 8-bit (-128 to +127) | Unsigned 8-bit (0-255) |
| C-buttons | Digital (4 buttons) | Analog C-stick |
| Triggers | Digital only | Digital + Analog |
| Polling timing | Single wait | Start + End detection |
| Default polling | 60-240 Hz | 125-200 Hz |
Troubleshooting
If the console doesn’t detect the controller:
- Check data pin connection and pull-up resistor
- Verify voltage levels (3.3V)
- Ensure polling rate matches console expectations
- Check for proper grounding between controller and console
- Try cleaning the controller port contacts
Advanced: Polling Rate Optimization
For Arduino, optimize the polling rate based on your use case:See Also
- GamecubeBackend - Similar Joybus protocol for GameCube
- Communication Backends - Backend selection guide
- Pinouts - Hardware pin mapping
