Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
pad.h
Go to the documentation of this file.
1#ifndef DW3_PAD_H
2#define DW3_PAD_H
3
4/* Controllers and the demo recorder (pad/) */
5
6#include "common.h"
7#include <sys/types.h>
8#include <libgte.h>
9#include <libgpu.h>
10
11/*
12 * Logical buttons: bits of PadSlot.held/pressed/repeated, which readPadButtons
13 * builds from the raw pad data (circle, cross and triangle are rotated, and
14 * the left analog stick also sets the d-pad bits). A button map
15 * (getButtonBit) translates them again; by default it is the identity.
16 * The menus confirm with PAD_CROSS and cancel with PAD_TRIANGLE.
17 */
18#define PAD_SELECT 0
19#define PAD_L3 1
20#define PAD_R3 2
21#define PAD_START 3
22#define PAD_UP 4
23#define PAD_RIGHT 5
24#define PAD_DOWN 6
25#define PAD_LEFT 7
26#define PAD_L2 8
27#define PAD_R2 9
28#define PAD_L1 10
29#define PAD_R1 11
30#define PAD_CIRCLE 12
31#define PAD_CROSS 13
32#define PAD_TRIANGLE 14
33#define PAD_SQUARE 15
34
35/* PadInfoMode(InfoModeCurExID) of a DualShock in digital and analog mode */
36#define PAD_ID_DIGITAL 4
37#define PAD_ID_ANALOG 7
38
39/* The second byte of the raw buffer when a multitap answers */
40#define PAD_MULTITAP_ID 0x80
41
42/* PadSetMainMode's lock: the analog button may change the mode, or not */
43#define PAD_MODE_UNLOCKED 2
44#define PAD_MODE_LOCKED 3
45
46/* Raw bits of circle, cross and triangle, which readPadButtons rotates */
47#define RAW_TRIANGLE 12
48#define RAW_CIRCLE 13
49#define RAW_CROSS 14
50#define FACE_BUTTONS (1 << PAD_CIRCLE | 1 << PAD_CROSS | 1 << PAD_TRIANGLE)
51
52/* A stick at or below LOW, or at or above HIGH, also presses the d-pad */
53#define STICK_LOW 0x40
54#define STICK_HIGH 0xC0
55
56/* What a pad sends (libpad's receive buffer) */
57typedef struct PadData {
58 /* 0x0 */ u8 status; /* 0: it answered */
59 /* 0x1 */ u8 id;
60 /* 0x2 */ u16 buttons; /* raw: a bit is clear while its button is pressed */
61 /* 0x4 */ u8 analog[4];
62} PadData;
63
64/* A port's receive buffer, and a frame of a demo: a pad, or a multitap and
65 the four pads behind it */
66typedef union PadBuffer {
67 u8 bytes[0x22];
69 struct {
71 u8 id; /* PAD_MULTITAP_ID */
73 } tap;
74} PadBuffer;
75
76/* One controller: a port, or one of the four multitap slots behind it */
77typedef struct PadSlot {
78 /* 0x00 */ u16 pressed; /* this frame */
79 /* 0x02 */ u16 repeated; /* pressed, or held long enough to repeat */
80 /* 0x04 */ u16 prevHeld;
81 /* 0x06 */ u16 held;
82 /* 0x08 */ u8 analog[4];
83 /* 0x0C */ s32 repeatTime[16];
84 /* 0x4C */ u8 repeatCount[16];
85 /* 0x5C */ u8 buttonMap[16];
86 /* 0x6C */ s16 vibrationTimers[2];
87} PadSlot;
88
89/*
90 * PadState.flags: bits 0-7 hold the mode lock of each port/slot (lockPadMode),
91 * the rest are these.
92 */
93#define PAD_FLAG_DEMO_PLAYBACK 0x00400000
94#define PAD_FLAG_DEMO_RECORDING 0x00800000
95#define PAD_FLAG_ALIGNING 0x04000000 /* PadSetActAlign sent, not yet stable */
96#define PAD_FLAG_VIBRATION 0x08000000 /* the actuators are aligned */
97#define PAD_FLAG_STARTED 0x20000000 /* PadStartCom done */
98#define PAD_FLAG_INITIALIZED 0x40000000
99#define PAD_FLAG_MULTITAP 0x80000000
100
101/* The bytes PadState keeps before its methods, which initPad clears */
102#define PAD_DATA_SIZE 0x3E0
103
104/*
105 * A demo replays recorded pad data (one raw buffer a frame, up to
106 * DEMO_FRAME_COUNT frames) instead of the pad, except for Start.
107 */
108#define DEMO_FRAME_COUNT 0x707
109
110/* Controller input (PAD) */
111typedef struct PadState {
112 /* 0x000 */ s32 flags;
113 /* 0x004 */ PadBuffer buf[2];
114 /* 0x048 */ PadSlot slots[2][4];
115 /* 0x3C8 */ u8 act[2][6];
116 /* 0x3D4 */ s16 repeatRate; /* vsyncs */
117 /* 0x3D6 */ s16 demoPad;
118 /* 0x3D8 */ PadBuffer *demoData; /* a buffer a frame */
119 /* 0x3DC */ s16 demoFrame;
120 /* 0x3E0 */ void (*init)(); /* PAD_INIT */
121 /* 0x3E4 */ void (*shutdown)();
122 /* 0x3E8 */ void (*update)(); /* PAD_UPDATE */
123 /* 0x3EC */ s32 (*setVibration)(u16 port, s32 motor, s16 time, u8 value);
124 /* 0x3F0 */ s32 (*lockMode)(s32 port, s32 lock);
125 /* 0x3F4 */ s32 (*getPressed)(s32 pad);
126 /* 0x3F8 */ s32 (*getHeld)(s32 pad);
127 /* 0x3FC */ s32 (*getRepeated)(s32 pad);
128 /* 0x400 */ void (*resetButtonMap)(u16 port);
129 /* 0x404 */ void (*swapButtons)(u16 port, s32 a, s32 b);
130 /* 0x408 */ s32 (*getButtonBit)(s32 pad, s32 button);
131 /* 0x40C */ s32 (*startDemoRecording)();
132 /* 0x410 */ void (*stopDemoRecording)();
133 /* 0x414 */ s32 (*isDemoRecording)();
134 /* 0x418 */ s32 (*startDemoPlayback)(s16 pad, PadBuffer *data);
135 /* 0x41C */ void (*stopDemoPlayback)();
136 /* 0x420 */ s32 (*isDemoPlaying)();
137} PadState;
138
139/* One button of pad 1: newly pressed, auto-repeated while held, or held */
140#define PAD_PRESSED(button) ((PAD.getPressed(0) >> PAD.getButtonBit(0, button)) & 1)
141#define PAD_REPEATED(button) ((PAD.getRepeated(0) >> PAD.getButtonBit(0, button)) & 1)
142#define PAD_HELD(button) ((PAD.getHeld(0) >> PAD.getButtonBit(0, button)) & 1)
143
144void readPadButtons(s32 port, PadData *data, PadData *record);
145void updateVibration(u16 port);
146void resetButtonMap(u16 port);
147void swapButtons(u16 port, s32 a, s32 b);
148s32 getButtonBit(s32 pad, s32 index);
149void startPad(void);
150s32 pollPadState(u32 port);
151void stopPad(void);
152void updatePad(void);
153void initPad(s32 multitap, s32 repeatRate);
154void shutdownPad(void);
155s32 setVibration(u16 port, s32 motor, s16 time, u8 value);
157s32 getPadHeld(s32 pad);
159s32 readPad(u16 port, PadData *data);
161void stopDemoRecording(void);
165void stopDemoPlayback(void);
167s32 lockPadMode(s32 port, s32 lock);
168
169extern u8 DEFAULT_BUTTON_MAP[16];
170extern PadState PAD;
171
172#endif /* DW3_PAD_H */
signed int s32
Definition common.h:11
unsigned int u32
Definition common.h:12
signed short s16
Definition common.h:9
unsigned short u16
Definition common.h:10
unsigned char u8
Definition common.h:8
s32 startDemoRecording(void)
Demo recording was left out of the release: it never starts.
Definition demo.c:5
s32 getButtonBit(s32 pad, s32 index)
The bit that logical button index sets on pad 1 or 2.
Definition pad.c:163
s32 setVibration(u16 port, s32 motor, s16 time, u8 value)
Starts a motor for time vsyncs (0 stops it)
Definition pad.c:98
s32 pollPadState(u32 port)
The libpad state of a port while it can be read (0 otherwise); a stable pad gets its actuators aligne...
Definition port.c:8
void updatePad(void)
Reads every pad, or the demo data while a demo plays.
Definition pad.c:62
void shutdownPad(void)
Stops reading the pads and forgets every flag, so the next startPad opens them again.
Definition pad.c:37
s32 getPadHeld(s32 pad)
The logical buttons held on pad 1 or 2.
Definition pad.c:136
s32 readPad(u16 port, PadData *data)
Reads one pad (vibration included), or clears its buttons when it is missing.
Definition port.c:144
void initPad(s32 multitap, s32 repeatRate)
Opens the pads (PadInitMtap or PadInitDirect); repeatRate 0 means DEFAULT_REPEAT_RATE.
Definition pad.c:8
s32 getPadPressed(s32 pad)
The logical buttons newly pressed on pad 1 or 2 this frame.
Definition pad.c:131
void updateVibration(u16 port)
Counts down a pad's vibration timers and stops each motor whose time is up.
Definition port.c:203
PadState PAD
Controller input: cleared by initPad, then the methods.
Definition pad.c:168
void readPadButtons(s32 port, PadData *data, PadData *record)
Builds held/pressed/repeated from the raw data (the demo record replaces all but Start)
Definition port.c:40
void stopPad(void)
Stops reading the pads every vsync.
Definition pad.c:54
s32 isDemoRecording(s32 pad)
1 while pad pad records a demo, -1 while another pad does, 0 otherwise (never set)
Definition demo.c:14
void stopDemoRecording(void)
Does nothing: demo recording was left out.
Definition demo.c:10
u8 DEFAULT_BUTTON_MAP[16]
The identity: logical button i is bit i.
Definition pad.c:178
void stopDemoPlayback(void)
Gives the pads back to the players.
Definition demo.c:40
s32 isDemoPlaying(s32 pad)
1 while pad pad replays a demo, -1 while another pad does, 0 otherwise
Definition demo.c:50
s32 startDemoPlayback(s16 pad, PadBuffer *data)
Replays data (one raw buffer a frame) as the input of pad.
Definition demo.c:25
s32 lockPadMode(s32 port, s32 lock)
Locks or unlocks the analog button of a DualShock, keeping its current mode.
Definition port.c:163
s32 getPadRepeated(s32 pad)
The logical buttons pressed on pad 1 or 2, repeating while held.
Definition pad.c:141
s32 alignActuators(u16 port)
Sends a DualShock its actuator alignment, so setVibration can drive the motors.
Definition port.c:187
void swapButtons(u16 port, s32 a, s32 b)
Swaps two logical buttons in a pad slot's button map.
Definition pad.c:155
void startPad(void)
Opens the pads with the defaults if needed, then starts reading them every vsync.
Definition pad.c:43
void resetButtonMap(u16 port)
Gives a pad slot the default button map, where button i is bit i.
Definition pad.c:146
What a pad sends (libpad's receive buffer)
Definition pad.h:57
u16 buttons
raw: a bit is clear while its button is pressed
Definition pad.h:60
u8 analog[4]
Definition pad.h:61
u8 status
0: it answered
Definition pad.h:58
u8 id
Definition pad.h:59
One controller: a port, or one of the four multitap slots behind it.
Definition pad.h:77
u8 repeatCount[16]
Definition pad.h:84
u16 repeated
pressed, or held long enough to repeat
Definition pad.h:79
u16 prevHeld
Definition pad.h:80
u16 held
Definition pad.h:81
u16 pressed
this frame
Definition pad.h:78
s16 vibrationTimers[2]
Definition pad.h:86
u8 analog[4]
Definition pad.h:82
s32 repeatTime[16]
Definition pad.h:83
u8 buttonMap[16]
Definition pad.h:85
Controller input (PAD)
Definition pad.h:111
s32(* isDemoPlaying)()
Definition pad.h:136
s32(* getRepeated)(s32 pad)
Definition pad.h:127
s32(* getButtonBit)(s32 pad, s32 button)
Definition pad.h:130
PadBuffer buf[2]
Definition pad.h:113
s32 flags
Definition pad.h:112
void(* resetButtonMap)(u16 port)
Definition pad.h:128
u8 act[2][6]
Definition pad.h:115
s32(* startDemoPlayback)(s16 pad, PadBuffer *data)
Definition pad.h:134
s16 repeatRate
vsyncs
Definition pad.h:116
s32(* getHeld)(s32 pad)
Definition pad.h:126
s32(* isDemoRecording)()
Definition pad.h:133
s32(* lockMode)(s32 port, s32 lock)
Definition pad.h:124
void(* shutdown)()
Definition pad.h:121
void(* stopDemoRecording)()
Definition pad.h:132
void(* swapButtons)(u16 port, s32 a, s32 b)
Definition pad.h:129
void(* stopDemoPlayback)()
Definition pad.h:135
PadSlot slots[2][4]
Definition pad.h:114
s32(* getPressed)(s32 pad)
Definition pad.h:125
void(* update)()
PAD_UPDATE.
Definition pad.h:122
s32(* setVibration)(u16 port, s32 motor, s16 time, u8 value)
Definition pad.h:123
s32(* startDemoRecording)()
Definition pad.h:131
PadBuffer * demoData
a buffer a frame
Definition pad.h:118
void(* init)()
PAD_INIT.
Definition pad.h:120
s16 demoPad
Definition pad.h:117
s16 demoFrame
Definition pad.h:119
A port's receive buffer, and a frame of a demo: a pad, or a multitap and the four pads behind it.
Definition pad.h:66
u8 bytes[0x22]
Definition pad.h:67
PadData pad
Definition pad.h:68
u8 id
PAD_MULTITAP_ID.
Definition pad.h:71
u8 status
Definition pad.h:70
struct PadBuffer::@11 tap
PadData pads[4]
Definition pad.h:72