Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
pad.h File Reference

Controllers and the demo recorder (pad/) More...

#include "common.h"
#include <sys/types.h>
#include <libgte.h>
#include <libgpu.h>
Include dependency graph for pad.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PadData
 What a pad sends (libpad's receive buffer) More...
 
union  PadBuffer
 A port's receive buffer, and a frame of a demo: a pad, or a multitap and the four pads behind it. More...
 
struct  PadSlot
 One controller: a port, or one of the four multitap slots behind it. More...
 
struct  PadState
 Controller input (PAD) More...
 

Macros

#define PAD_SELECT   0
 Logical buttons: bits of PadSlot.held/pressed/repeated, which readPadButtons builds from the raw pad data (circle, cross and triangle are rotated, and the left analog stick also sets the d-pad bits).
 
#define PAD_L3   1
 
#define PAD_R3   2
 
#define PAD_START   3
 
#define PAD_UP   4
 
#define PAD_RIGHT   5
 
#define PAD_DOWN   6
 
#define PAD_LEFT   7
 
#define PAD_L2   8
 
#define PAD_R2   9
 
#define PAD_L1   10
 
#define PAD_R1   11
 
#define PAD_CIRCLE   12
 
#define PAD_CROSS   13
 
#define PAD_TRIANGLE   14
 
#define PAD_SQUARE   15
 
#define PAD_ID_DIGITAL   4
 PadInfoMode(InfoModeCurExID) of a DualShock in digital and analog mode.
 
#define PAD_ID_ANALOG   7
 
#define PAD_MULTITAP_ID   0x80
 The second byte of the raw buffer when a multitap answers.
 
#define PAD_MODE_UNLOCKED   2
 PadSetMainMode's lock: the analog button may change the mode, or not.
 
#define PAD_MODE_LOCKED   3
 
#define RAW_TRIANGLE   12
 Raw bits of circle, cross and triangle, which readPadButtons rotates.
 
#define RAW_CIRCLE   13
 
#define RAW_CROSS   14
 
#define FACE_BUTTONS   (1 << PAD_CIRCLE | 1 << PAD_CROSS | 1 << PAD_TRIANGLE)
 
#define STICK_LOW   0x40
 A stick at or below LOW, or at or above HIGH, also presses the d-pad.
 
#define STICK_HIGH   0xC0
 
#define PAD_FLAG_DEMO_PLAYBACK   0x00400000
 PadState.flags: bits 0-7 hold the mode lock of each port/slot (lockPadMode), the rest are these.
 
#define PAD_FLAG_DEMO_RECORDING   0x00800000
 
#define PAD_FLAG_ALIGNING   0x04000000
 PadSetActAlign sent, not yet stable.
 
#define PAD_FLAG_VIBRATION   0x08000000
 the actuators are aligned
 
#define PAD_FLAG_STARTED   0x20000000
 PadStartCom done.
 
#define PAD_FLAG_INITIALIZED   0x40000000
 
#define PAD_FLAG_MULTITAP   0x80000000
 
#define PAD_DATA_SIZE   0x3E0
 The bytes PadState keeps before its methods, which initPad clears.
 
#define DEMO_FRAME_COUNT   0x707
 A demo replays recorded pad data (one raw buffer a frame, up to DEMO_FRAME_COUNT frames) instead of the pad, except for Start.
 
#define PAD_PRESSED(button)   ((PAD.getPressed(0) >> PAD.getButtonBit(0, button)) & 1)
 One button of pad 1: newly pressed, auto-repeated while held, or held.
 
#define PAD_REPEATED(button)   ((PAD.getRepeated(0) >> PAD.getButtonBit(0, button)) & 1)
 
#define PAD_HELD(button)   ((PAD.getHeld(0) >> PAD.getButtonBit(0, button)) & 1)
 

Functions

void readPadButtons (s32 port, PadData *data, PadData *record)
 Builds held/pressed/repeated from the raw data (the demo record replaces all but Start)
 
void updateVibration (u16 port)
 Counts down a pad's vibration timers and stops each motor whose time is up.
 
void resetButtonMap (u16 port)
 Gives a pad slot the default button map, where button i is bit i.
 
void swapButtons (u16 port, s32 a, s32 b)
 Swaps two logical buttons in a pad slot's button map.
 
s32 getButtonBit (s32 pad, s32 index)
 The bit that logical button index sets on pad 1 or 2.
 
void startPad (void)
 Opens the pads with the defaults if needed, then starts reading them every vsync.
 
s32 pollPadState (u32 port)
 The libpad state of a port while it can be read (0 otherwise); a stable pad gets its actuators aligned.
 
void stopPad (void)
 Stops reading the pads every vsync.
 
void updatePad (void)
 Reads every pad, or the demo data while a demo plays.
 
void initPad (s32 multitap, s32 repeatRate)
 Opens the pads (PadInitMtap or PadInitDirect); repeatRate 0 means DEFAULT_REPEAT_RATE.
 
void shutdownPad (void)
 Stops reading the pads and forgets every flag, so the next startPad opens them again.
 
s32 setVibration (u16 port, s32 motor, s16 time, u8 value)
 Starts a motor for time vsyncs (0 stops it)
 
s32 getPadPressed (s32 pad)
 The logical buttons newly pressed on pad 1 or 2 this frame.
 
s32 getPadHeld (s32 pad)
 The logical buttons held on pad 1 or 2.
 
s32 getPadRepeated (s32 pad)
 The logical buttons pressed on pad 1 or 2, repeating while held.
 
s32 readPad (u16 port, PadData *data)
 Reads one pad (vibration included), or clears its buttons when it is missing.
 
s32 startDemoRecording (void)
 Demo recording was left out of the release: it never starts.
 
void stopDemoRecording (void)
 Does nothing: demo recording was left out.
 
s32 isDemoRecording (s32 pad)
 1 while pad pad records a demo, -1 while another pad does, 0 otherwise (never set)
 
s32 alignActuators (u16 port)
 Sends a DualShock its actuator alignment, so setVibration can drive the motors.
 
s32 startDemoPlayback (s16 pad, PadBuffer *data)
 Replays data (one raw buffer a frame) as the input of pad.
 
void stopDemoPlayback (void)
 Gives the pads back to the players.
 
s32 isDemoPlaying (s32 pad)
 1 while pad pad replays a demo, -1 while another pad does, 0 otherwise
 
s32 lockPadMode (s32 port, s32 lock)
 Locks or unlocks the analog button of a DualShock, keeping its current mode.
 

Variables

u8 DEFAULT_BUTTON_MAP [16]
 The identity: logical button i is bit i.
 
PadState PAD
 Controller input: cleared by initPad, then the methods.
 

Detailed Description

Controllers and the demo recorder (pad/)

Definition in file pad.h.

Macro Definition Documentation

◆ PAD_SELECT

#define PAD_SELECT   0

Logical buttons: bits of PadSlot.held/pressed/repeated, which readPadButtons builds from the raw pad data (circle, cross and triangle are rotated, and the left analog stick also sets the d-pad bits).

A button map (getButtonBit) translates them again; by default it is the identity. The menus confirm with PAD_CROSS and cancel with PAD_TRIANGLE.

Definition at line 18 of file pad.h.

◆ PAD_L3

#define PAD_L3   1

Definition at line 19 of file pad.h.

◆ PAD_R3

#define PAD_R3   2

Definition at line 20 of file pad.h.

◆ PAD_START

#define PAD_START   3

Definition at line 21 of file pad.h.

◆ PAD_UP

#define PAD_UP   4

Definition at line 22 of file pad.h.

◆ PAD_RIGHT

#define PAD_RIGHT   5

Definition at line 23 of file pad.h.

◆ PAD_DOWN

#define PAD_DOWN   6

Definition at line 24 of file pad.h.

◆ PAD_LEFT

#define PAD_LEFT   7

Definition at line 25 of file pad.h.

◆ PAD_L2

#define PAD_L2   8

Definition at line 26 of file pad.h.

◆ PAD_R2

#define PAD_R2   9

Definition at line 27 of file pad.h.

◆ PAD_L1

#define PAD_L1   10

Definition at line 28 of file pad.h.

◆ PAD_R1

#define PAD_R1   11

Definition at line 29 of file pad.h.

◆ PAD_CIRCLE

#define PAD_CIRCLE   12

Definition at line 30 of file pad.h.

◆ PAD_CROSS

#define PAD_CROSS   13

Definition at line 31 of file pad.h.

◆ PAD_TRIANGLE

#define PAD_TRIANGLE   14

Definition at line 32 of file pad.h.

◆ PAD_SQUARE

#define PAD_SQUARE   15

Definition at line 33 of file pad.h.

◆ PAD_ID_DIGITAL

#define PAD_ID_DIGITAL   4

PadInfoMode(InfoModeCurExID) of a DualShock in digital and analog mode.

Definition at line 36 of file pad.h.

◆ PAD_ID_ANALOG

#define PAD_ID_ANALOG   7

Definition at line 37 of file pad.h.

◆ PAD_MULTITAP_ID

#define PAD_MULTITAP_ID   0x80

The second byte of the raw buffer when a multitap answers.

Definition at line 40 of file pad.h.

◆ PAD_MODE_UNLOCKED

#define PAD_MODE_UNLOCKED   2

PadSetMainMode's lock: the analog button may change the mode, or not.

Definition at line 43 of file pad.h.

◆ PAD_MODE_LOCKED

#define PAD_MODE_LOCKED   3

Definition at line 44 of file pad.h.

◆ RAW_TRIANGLE

#define RAW_TRIANGLE   12

Raw bits of circle, cross and triangle, which readPadButtons rotates.

Definition at line 47 of file pad.h.

◆ RAW_CIRCLE

#define RAW_CIRCLE   13

Definition at line 48 of file pad.h.

◆ RAW_CROSS

#define RAW_CROSS   14

Definition at line 49 of file pad.h.

◆ FACE_BUTTONS

#define FACE_BUTTONS   (1 << PAD_CIRCLE | 1 << PAD_CROSS | 1 << PAD_TRIANGLE)

Definition at line 50 of file pad.h.

◆ STICK_LOW

#define STICK_LOW   0x40

A stick at or below LOW, or at or above HIGH, also presses the d-pad.

Definition at line 53 of file pad.h.

◆ STICK_HIGH

#define STICK_HIGH   0xC0

Definition at line 54 of file pad.h.

◆ PAD_FLAG_DEMO_PLAYBACK

#define PAD_FLAG_DEMO_PLAYBACK   0x00400000

PadState.flags: bits 0-7 hold the mode lock of each port/slot (lockPadMode), the rest are these.

Definition at line 93 of file pad.h.

◆ PAD_FLAG_DEMO_RECORDING

#define PAD_FLAG_DEMO_RECORDING   0x00800000

Definition at line 94 of file pad.h.

◆ PAD_FLAG_ALIGNING

#define PAD_FLAG_ALIGNING   0x04000000

PadSetActAlign sent, not yet stable.

Definition at line 95 of file pad.h.

◆ PAD_FLAG_VIBRATION

#define PAD_FLAG_VIBRATION   0x08000000

the actuators are aligned

Definition at line 96 of file pad.h.

◆ PAD_FLAG_STARTED

#define PAD_FLAG_STARTED   0x20000000

PadStartCom done.

Definition at line 97 of file pad.h.

◆ PAD_FLAG_INITIALIZED

#define PAD_FLAG_INITIALIZED   0x40000000

Definition at line 98 of file pad.h.

◆ PAD_FLAG_MULTITAP

#define PAD_FLAG_MULTITAP   0x80000000

Definition at line 99 of file pad.h.

◆ PAD_DATA_SIZE

#define PAD_DATA_SIZE   0x3E0

The bytes PadState keeps before its methods, which initPad clears.

Definition at line 102 of file pad.h.

◆ DEMO_FRAME_COUNT

#define DEMO_FRAME_COUNT   0x707

A demo replays recorded pad data (one raw buffer a frame, up to DEMO_FRAME_COUNT frames) instead of the pad, except for Start.

Definition at line 108 of file pad.h.

◆ PAD_PRESSED

#define PAD_PRESSED (   button)    ((PAD.getPressed(0) >> PAD.getButtonBit(0, button)) & 1)

One button of pad 1: newly pressed, auto-repeated while held, or held.

Definition at line 140 of file pad.h.

◆ PAD_REPEATED

#define PAD_REPEATED (   button)    ((PAD.getRepeated(0) >> PAD.getButtonBit(0, button)) & 1)

Definition at line 141 of file pad.h.

◆ PAD_HELD

#define PAD_HELD (   button)    ((PAD.getHeld(0) >> PAD.getButtonBit(0, button)) & 1)

Definition at line 142 of file pad.h.

Function Documentation

◆ readPadButtons()

void readPadButtons ( s32  port,
PadData *  data,
PadData *  record 
)

Builds held/pressed/repeated from the raw data (the demo record replaces all but Start)

Definition at line 40 of file port.c.

Referenced by readPad(), and updatePad().

Here is the caller graph for this function:

◆ updateVibration()

void updateVibration ( u16  port)

Counts down a pad's vibration timers and stops each motor whose time is up.

Definition at line 203 of file port.c.

Referenced by readPad().

Here is the caller graph for this function:

◆ resetButtonMap()

void resetButtonMap ( u16  port)

Gives a pad slot the default button map, where button i is bit i.

Definition at line 146 of file pad.c.

Referenced by initPad().

Here is the caller graph for this function:

◆ swapButtons()

void swapButtons ( u16  port,
s32  a,
s32  b 
)

Swaps two logical buttons in a pad slot's button map.

Definition at line 155 of file pad.c.

◆ getButtonBit()

s32 getButtonBit ( s32  pad,
s32  index 
)

The bit that logical button index sets on pad 1 or 2.

Definition at line 163 of file pad.c.

◆ startPad()

void startPad ( void  )

Opens the pads with the defaults if needed, then starts reading them every vsync.

< PadStartCom done

< PadStartCom done

Definition at line 43 of file pad.c.

Referenced by initPad().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pollPadState()

s32 pollPadState ( u32  port)

The libpad state of a port while it can be read (0 otherwise); a stable pad gets its actuators aligned.

< PadSetActAlign sent, not yet stable

< the actuators are aligned

< the actuators are aligned

< PadSetActAlign sent, not yet stable

< the actuators are aligned

< PadSetActAlign sent, not yet stable

Definition at line 8 of file port.c.

Referenced by lockPadMode(), readPad(), and setVibration().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stopPad()

void stopPad ( void  )

Stops reading the pads every vsync.

< PadStartCom done

< PadStartCom done

Definition at line 54 of file pad.c.

Referenced by shutdownPad().

Here is the caller graph for this function:

◆ updatePad()

void updatePad ( void  )

Reads every pad, or the demo data while a demo plays.

Definition at line 62 of file pad.c.

Here is the call graph for this function:

◆ initPad()

void initPad ( s32  multitap,
s32  repeatRate 
)

Opens the pads (PadInitMtap or PadInitDirect); repeatRate 0 means DEFAULT_REPEAT_RATE.

Definition at line 8 of file pad.c.

Referenced by startPad().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shutdownPad()

void shutdownPad ( void  )

Stops reading the pads and forgets every flag, so the next startPad opens them again.

Definition at line 37 of file pad.c.

Here is the call graph for this function:

◆ setVibration()

s32 setVibration ( u16  port,
s32  motor,
s16  time,
u8  value 
)

Starts a motor for time vsyncs (0 stops it)

< the actuators are aligned

Definition at line 98 of file pad.c.

Referenced by startDemoPlayback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPadPressed()

s32 getPadPressed ( s32  pad)

The logical buttons newly pressed on pad 1 or 2 this frame.

Definition at line 131 of file pad.c.

◆ getPadHeld()

s32 getPadHeld ( s32  pad)

The logical buttons held on pad 1 or 2.

Definition at line 136 of file pad.c.

◆ getPadRepeated()

s32 getPadRepeated ( s32  pad)

The logical buttons pressed on pad 1 or 2, repeating while held.

Definition at line 141 of file pad.c.

◆ readPad()

s32 readPad ( u16  port,
PadData *  data 
)

Reads one pad (vibration included), or clears its buttons when it is missing.

Definition at line 144 of file port.c.

Referenced by updatePad().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ startDemoRecording()

s32 startDemoRecording ( void  )

Demo recording was left out of the release: it never starts.

Definition at line 5 of file demo.c.

◆ stopDemoRecording()

void stopDemoRecording ( void  )

Does nothing: demo recording was left out.

Definition at line 10 of file demo.c.

Referenced by updatePad().

Here is the caller graph for this function:

◆ isDemoRecording()

s32 isDemoRecording ( s32  pad)

1 while pad pad records a demo, -1 while another pad does, 0 otherwise (never set)

Definition at line 14 of file demo.c.

Referenced by updatePad().

Here is the caller graph for this function:

◆ alignActuators()

s32 alignActuators ( u16  port)

Sends a DualShock its actuator alignment, so setVibration can drive the motors.

Definition at line 187 of file port.c.

Referenced by pollPadState().

Here is the caller graph for this function:

◆ startDemoPlayback()

s32 startDemoPlayback ( s16  pad,
PadBuffer *  data 
)

Replays data (one raw buffer a frame) as the input of pad.

Definition at line 25 of file demo.c.

Here is the call graph for this function:

◆ stopDemoPlayback()

void stopDemoPlayback ( void  )

Gives the pads back to the players.

Definition at line 40 of file demo.c.

◆ isDemoPlaying()

s32 isDemoPlaying ( s32  pad)

1 while pad pad replays a demo, -1 while another pad does, 0 otherwise

Definition at line 50 of file demo.c.

◆ lockPadMode()

s32 lockPadMode ( s32  port,
s32  lock 
)

Locks or unlocks the analog button of a DualShock, keeping its current mode.

< PadSetActAlign sent, not yet stable

< the actuators are aligned

Definition at line 163 of file port.c.

Here is the call graph for this function:

Variable Documentation

◆ DEFAULT_BUTTON_MAP

u8 DEFAULT_BUTTON_MAP[16]
extern

The identity: logical button i is bit i.

Definition at line 178 of file pad.c.

Referenced by resetButtonMap().

◆ PAD

PadState PAD
extern

Controller input: cleared by initPad, then the methods.

Definition at line 168 of file pad.c.

Referenced by alignActuators(), answerQuitQuestion(), browseOpponentRow(), browseOwnRow(), browsePlayedRow(), CARDGAME_browseHand(), CARDGAME_drawFirstPlayer(), CARDGAME_readChooseInput(), CARDGAME_readCountInput(), CARDGAME_readPickInput(), editBattleDebug(), editProgress(), FIELDSTG_controlClimb(), FIELDSTG_controlFlight(), FIELDSTG_controlPlayer(), FIELDSTG_runGauge(), FIELDSTG_updateTriggers(), FIGHTSTG_stepConfusedMessage(), FIGHTSTG_stepMessage(), FIGHTSTG_updateCommandMenu(), FIGHTSTG_updateConfusedMenu(), FIGHTSTG_updateCursor(), FIGHTSTG_updateDigivolveMenu(), FIGHTSTG_updateItemMenu(), FIGHTSTG_updateSwitchInMenu(), FIGHTSTG_updateSwitchMenu(), FIGHTSTG_updateTechMenu(), getButtonBit(), getPadHeld(), getPadPressed(), getPadRepeated(), initPad(), isDemoPlaying(), isDemoRecording(), lockPadMode(), main(), moveDeckMarker(), moveMenuCursor(), openFieldMenu(), pickEffect(), pickInOpponentRow(), pickInOwnRow(), pollPadState(), readPad(), readPadButtons(), resetButtonMap(), runCameraList(), runFighterList(), runMotionList(), runPlayPage(), runStageList(), setVibration(), SHOCKTST_playPattern(), SHOCKTST_updateEditor(), shutdownPad(), SOUNDTST_playSounds(), SOUNDTST_selectBank(), SOUNDTST_updateScene(), STAGSLCT_updateStageSelect(), STAGSLCT_zoomTitle(), startDemoPlayback(), startPad(), STDWTITL_tickMoviePlayer(), stopDemoPlayback(), stopPad(), swapButtons(), updatePad(), updateTextWindow(), updateVibration(), WFIGHTTS_battleTest(), WFIGHTTS_cameraList(), WFIGHTTS_effectList(), WFIGHTTS_fighterList(), WFIGHTTS_motionList(), and WFIGHTTS_stageList().