N64 Controller Interface

Authored by Francisco Martin and Andrew Smith

The Nintendo 64 Controller Interface is an mbed library that allows one or more Nintendo 64 controllers to be used as input devices for the mbed. With this library, one will be able to control games created for an mbed using a Nintendo 64 controller. In addition, the library can easily be used to forward N64 inputs to a computer. Using the N64 Controller executable, one can communicate with multiple controllers.

The N64 Controller executable is it's own stand alone program. It is highly configurable including modifying keybindings to be used with an emulator or changing background colors for streaming and recording. The N64 also allows passive listening. During this setting, one can connect the N64 Controller Interface adapter to an Nintendo 64 and play normally. Connecting the computer simply displays button presses in the GUI . For more information on the N64 Controller program, check its section below.

Hookup Guide

The N64 Controller Interface requires the following additional devices:

Wire Stripping and Soldering

1. Cut and strip the extension cable closer to the female end. Strip each internal cable on both ends. /media/uploads/fomartin/20160412_173614.jpg

2. Solder stripped ends to pin wires. /media/uploads/fomartin/20160412_174030.jpg

3. Hide exposed wires with electrical tape and/or shrink tube. /media/uploads/fomartin/20160412_172938.jpg

Suggested Hookup

The following image is our suggested wiring schematic. Refer to this image when reading the following hookup tables. /media/uploads/fomartin/hookup-clipart.png /media/uploads/fomartin/20160427_124021.jpg

Male End Extension Cable

Only necessary if you plan to have controller plugged into genuine N64 as well, and passively read inputs from controller instead of actively polling for them (not yet supported by the mbed library).

Cablembed
+ (red)Vout
- (white)GND
SignalParallel to Female End

Female End Extension Cable

Cablembed
+ (red)Vout
- (white)GND
Signalp25 (pull-up with 2.2K Ohm Resistor)

2.2K Ohm Resistor

Set to High parallel to the female end of the extension cable. The data pin (p25) should be pulled high, and must be set to OpenDrain mode in order transmit low values as well.

Test Video

N64 Controller Interface Library

To understand how to interface with an N64 controller, one must first understand the protocol that a genuine N64 uses to interface with the controller. All data is transmitted on a single, half-duplex wire (the signal wire plugged into pin 25 above). When this wire is idle, it is high (hence the pull-up resistor). If a falling edge is detected, it means that bits are being transmitted. Bits are transmitted in 4μs intervals. For a 0, the wire is low for 3μs and high for 1μs. For a 1, the wire is low for 1μs and high for 3μs. In order to read a bit, you must simply wait for a falling edge, and then read the wire 2μs after the falling edge. If the wire is high, the value is a 1, if it is low, the value is a 0. All transmissions end with a 1 bit that is not followed by a falling edge, called the signal bit.

/media/uploads/fomartin/protocol.png

The mbed has a built-in wait_us(int) function that waits a set number of microseconds. However, a microsecond is the smallest resolution that the built-in clock has, so relying on it to wait exactly 1, 2, or 3 microseconds (as our code requires) is not reliable. Instead, a custom assembly function was written to wait an arbitrary number of microseconds. Because the mbed has a clock frequency of 96 MHz, it was calculated that 96 clock cycles should equal 1 microsecond. Assuming a throughput of 1 instruction per clock cycle, this corresponds to 96 instructions. The assembly code does bogus add instructions to consume time equal to 1 microsecond. It does this in a loop, with the number of iterations equaling the parameter that was passed in. NOPs are not used, since according to the ARM assembly reference NOP instructions are liable to be optimized away from the processor.

To request data from the controller, the mbed must write the byte 0x01 onto the wire. The controller then responds with 4 bytes, indicating the inputs on the controller.

Bit0123456789101112131415
DataABZSD↑D↓D←D→**LRD↑D↓D←D→

S = Start, D = D-Pad, C = C-Buttons, * = Unused

Bit16 - 2324 - 31
DataAnalog XAnalog Y

Each button is indicated by a specific bit of the response. A 0 in that bit means the button is not pressed, a 1 means it is pressed. The analog values are signed 8-bit integers. For X, negative is left, and positive is right. For Y, negative is down, and positive is up.

The mbed library polls for this data 100 times a second (using a Ticker), and stores the result. It has methods that allow client code to check the stored result to see which buttons are currently being pressed, and what the values of the joystick are.

Source Code

Import libraryn64

The Nintendo 64 Controller Interface is an mbed library that allows one or more Nintendo 64 controllers to be used as input devices for the mbed. With this library, one will be able to control games created for an mbed using a Nintendo 64 controller. In addition, the library can easily be used to forward N64 inputs to a computer. Using the N64 Controller executable, one can communicate with multiple controllers.

N64 Controller GUI Program

The source code for the GUI program is available at the link below. It is divided into three main sections:

  • N64GUI: Takes care of the UI of the program and loading important components.
  • ControllerListener: Runs on its own thread and listens the serial port for signals.
  • ControllerEventHandler: Takes care of mbed commands and simulates button presses.

One can choose which COM port to connect in the Conneciton tool strip. One can choose the Quit command to close the application. Test Connection is used during debugging and will write to the Output window in Visual Studio if the connection is successful. Layout currently allows to hide/show the controller outline. Future updates will allow new layouts. Finally, Settings Allows to set key bindings and background color. Under Key Bindings, you turn off or on Emulator Mode. When on, Emulator Mode simulates the key pressed with the corresponding button.

Source Code

The source code and installer can be found at its GitHub page here or the following website: https://github.com/fomartin/N64_Controller


Please log in to post comments.