wavelength 1.0.0
Loading...
Searching...
No Matches
joypad.h File Reference
#include "app/msgsink.h"
Include dependency graph for joypad.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  JoypadStick
 Position of one analogue stick. More...
class  JoypadState
 State of one controller port as the last poll read it. More...

Enumerations

enum  JoypadButton {
  kPadL2 = 0 , kPadR2 = 1 , kPadL1 = 2 , kPadR1 = 3 ,
  kPadTriangle = 4 , kPadCircle = 5 , kPadCross = 6 , kPadSquare = 7 ,
  kPadSelect = 8 , kPadL3 = 9 , kPadR3 = 10 , kPadStart = 11 ,
  kPadDUp = 12 , kPadDRight = 13 , kPadDDown = 14 , kPadDLeft = 15 ,
  kPadLeftStickUp = 16 , kPadLeftStickRight = 17 , kPadLeftStickDown = 18 , kPadLeftStickLeft = 19 ,
  kPadRightStickUp = 20 , kPadRightStickRight = 21 , kPadRightStickDown = 22 , kPadRightStickLeft = 23 ,
  kPadNone = 24
}
 Buttons of a controller, the values JoypadInputMsg::mButton takes. More...

Functions

void JoypadInit ()
 Open every controller port and give the first port to pad 0.
void JoypadTerminate ()
 Shut the controller layer down.
void JoypadPoll ()
 Read every controller port that serves a pad, and send messages for what changed.
int JoypadWait ()
 Wait for pad 0 to release every button and then press one.
JoypadState * JoypadGetState (int nPad)
 Report the state of a controller.
void JoypadAddSink (MsgSink *pSink)
 Add a sink to the receivers of the controller messages.
void JoypadRemoveSink (MsgSink *pSink)
 Remove a sink from the receivers of the controller messages.
void JoypadSetStickMessages (bool bEnable)
 Turn the analog stick messages of the controller poll on or off.
void JoypadSetMenuControl (int nPad, bool bMenu)
 Give the input of a controller to the menus or to the running world.
void JoypadSetVibration (int nPad, int nSmallMotor, int nBigMotor)
 Drive the vibration motors of the controller on a port.
void JoypadMapDefault (bool bPort0Multitap, bool bPort1Multitap)
 Give the controller ports to the pads.
int JoypadMultitapConnected ()
 Report whether a multitap is connected, as the controller poll last found.

Variables

constexpr int kJoypadNumSticks = 2
 The number of analogue sticks of a controller.
constexpr int kJoypadNumButtons = 24
 The number of buttons of a controller, counting the stick directions.
constexpr int kJoypadNumPorts = 8
 The number of controllers the poll reads, four multitap slots on each of two ports.
constexpr int kJoypadNumPads = 4
 The number of players the controllers can be given to.
constexpr int kJoypadNoPad = -1
 The pad a port stores while no player uses it.

Enumeration Type Documentation

◆ JoypadButton

Buttons of a controller, the values JoypadInputMsg::mButton takes.

The name is inferred.

Enumerator
kPadL2 

The L2 button.

kPadR2 

The R2 button.

kPadL1 

The L1 button.

kPadR1 

The R1 button.

kPadTriangle 

The triangle button.

kPadCircle 

The circle button.

kPadCross 

The cross button, which chooses in the menus.

kPadSquare 

The square button.

kPadSelect 

The SELECT button.

kPadL3 

The left stick pressed in.

kPadR3 

The right stick pressed in.

kPadStart 

The START button.

kPadDUp 

Up on the directional buttons.

kPadDRight 

Right on the directional buttons.

kPadDDown 

Down on the directional buttons.

kPadDLeft 

Left on the directional buttons.

kPadLeftStickUp 

The left stick pushed up past the threshold.

kPadLeftStickRight 

The left stick pushed right past the threshold.

kPadLeftStickDown 

The left stick pushed down past the threshold.

kPadLeftStickLeft 

The left stick pushed left past the threshold.

kPadRightStickUp 

The right stick pushed up past the threshold.

kPadRightStickRight 

The right stick pushed right past the threshold.

kPadRightStickDown 

The right stick pushed down past the threshold.

kPadRightStickLeft 

The right stick pushed left past the threshold.

kPadNone 

No button.

Function Documentation

◆ JoypadInit()

void JoypadInit ( )

Open every controller port and give the first port to pad 0.

Reads the deadzone and threshold settings of the joypad block of the system configuration, 24 and 0.75 by default.

Ghidra address:
NTSC-U/C: 0x0028aea0
Ghidra address:
PAL: 0x00294698

◆ JoypadTerminate()

void JoypadTerminate ( )

Shut the controller layer down.

The body does nothing.

Ghidra address:
NTSC-U/C: 0x0028af50
Ghidra address:
PAL: 0x00294748

◆ JoypadPoll()

void JoypadPoll ( )

Read every controller port that serves a pad, and send messages for what changed.

Sends a JoypadConnectionMsg when a pad connects or disconnects, a JoypadAnalogStickMsg when a stick moves while JoypadSetStickMessages() is on, and a JoypadInputMsg for each button pressed or released. A digital-only pad is ignored. Before JoypadInit() the call only reports an error.

Ghidra address:
NTSC-U/C: 0x0028a780
Ghidra address:
PAL: 0x00293f78

◆ JoypadWait()

int JoypadWait ( )

Wait for pad 0 to release every button and then press one.

Before JoypadInit() the call waits five seconds instead.

Returns
The buttons pad 0 holds, or 0 before JoypadInit().
Ghidra address:
NTSC-U/C: 0x0028a6e8
Ghidra address:
PAL: 0x00293ee0

◆ JoypadGetState()

JoypadState * JoypadGetState ( int nPad)

Report the state of a controller.

Parameters
nPadThe controller.
Returns
The state.
Ghidra address:
NTSC-U/C: 0x0028aca0
Ghidra address:
PAL: 0x00294498

◆ JoypadAddSink()

void JoypadAddSink ( MsgSink * pSink)

Add a sink to the receivers of the controller messages.

Parameters
pSinkThe sink.
Ghidra address:
NTSC-U/C: 0x0028acf0
Ghidra address:
PAL: 0x002944e8

◆ JoypadRemoveSink()

void JoypadRemoveSink ( MsgSink * pSink)

Remove a sink from the receivers of the controller messages.

Parameters
pSinkThe sink.
Ghidra address:
NTSC-U/C: 0x0028ad18
Ghidra address:
PAL: 0x00294510

◆ JoypadSetStickMessages()

void JoypadSetStickMessages ( bool bEnable)

Turn the analog stick messages of the controller poll on or off.

While the setting is off, the poll does not compare stick positions and sends no message for a moved stick. The setting starts off. The name is inferred from the behaviour.

Parameters
bEnableWhether moved sticks send messages.
Ghidra address:
NTSC-U/C: 0x0028ace0
Ghidra address:
PAL: 0x002944d8

◆ JoypadSetMenuControl()

void JoypadSetMenuControl ( int nPad,
bool bMenu )

Give the input of a controller to the menus or to the running world.

WorldLogic gives every controller to the world while it exists, and a paused game gives them back to the menus. While the menus receive a pad's input, its left stick also presses the directional buttons. The name is inferred.

Parameters
nPadThe controller.
bMenuWhether the menus receive the input.
Ghidra address:
NTSC-U/C: 0x0028acc8
Ghidra address:
PAL: 0x002944c0

◆ JoypadSetVibration()

void JoypadSetVibration ( int nPad,
int nSmallMotor,
int nBigMotor )

Drive the vibration motors of the controller on a port.

The name is inferred.

Parameters
nPadThe controller port.
nSmallMotorThe small motor's state, 0 or 1.
nBigMotorThe big motor's level.
Ghidra address:
NTSC-U/C: 0x0028aff8
Ghidra address:
PAL: 0x002947f0

◆ JoypadMapDefault()

void JoypadMapDefault ( bool bPort0Multitap,
bool bPort1Multitap )

Give the controller ports to the pads.

With bPort0Multitap set, the four slots of port 0 serve pads 0 to 3. Otherwise slot 0 of port 0 serves pad 0, slot 0 of port 1 serves pad 1 unless bPort1Multitap is set, and the other slots serve no pad.

Parameters
bPort0MultitapWhether a multitap is connected to port 0.
bPort1MultitapWhether a multitap is connected to port 1.
Ghidra address:
NTSC-U/C: 0x0028b048
Ghidra address:
PAL: 0x00294840

◆ JoypadMultitapConnected()

int JoypadMultitapConnected ( )

Report whether a multitap is connected, as the controller poll last found.

The name is inferred from the player count screen. That screen offers three and four players only while the flag is set.

Returns
Non-zero while a multitap is connected.
Ghidra address:
NTSC-U/C: 0x0028c4d0
Ghidra address:
PAL: 0x00295e20

Variable Documentation

◆ kJoypadNumSticks

int kJoypadNumSticks = 2
constexpr

The number of analogue sticks of a controller.

◆ kJoypadNumButtons

int kJoypadNumButtons = 24
constexpr

The number of buttons of a controller, counting the stick directions.

◆ kJoypadNumPorts

int kJoypadNumPorts = 8
constexpr

The number of controllers the poll reads, four multitap slots on each of two ports.

◆ kJoypadNumPads

int kJoypadNumPads = 4
constexpr

The number of players the controllers can be given to.

◆ kJoypadNoPad

int kJoypadNoPad = -1
constexpr

The pad a port stores while no player uses it.