PS2GL
OpenGL*-like API for the PS2
Loading...
Searching...
No Matches
pads.h
1/* Copyright (C) 2000,2001,2002 Sony Computer Entertainment America
2
3 This file is subject to the terms and conditions of the GNU Lesser
4 General Public License Version 2.1. See the file "COPYING" in the
5 main directory of this archive for more details. */
6
7#ifndef pads_h
8#define pads_h
9
10#include "libpad.h"
11
12#include "ps2s/types.h"
13
14#define scePadDmaBufferMax (256 / 16)
15
16/********************************************
17 * types
18 */
19
20/********************************************
21 * class def
22 */
23
24namespace Pads {
25void Init(void);
26void Read(void);
27
28static const unsigned int kSelect = 0,
29 kLeftStickButton = 1,
30 kRightStickButton = 2,
31 kStart = 3,
32 kLeftUp = 4,
33 kLeftRight = 5,
34 kLeftDown = 6,
35 kLeftLeft = 7,
36 kL2 = 8,
37 kR2 = 9,
38 kL1 = 10,
39 kR1 = 11,
40 kRightUp = 12,
41 kRightRight = 13,
42 kRightDown = 14,
43 kRightLeft = 15;
44}
45
46class CPad {
47public:
48 CPad(unsigned int port);
49
50 bool Open(void);
51 void Read(void);
52
53 bool IsDown(unsigned int button);
54 bool IsUp(unsigned int button);
55 bool WasPushed(unsigned int button);
56 bool WasReleased(unsigned int button);
57
58 float RightStickX(void) { return CurStatus.rightStick.xPos; }
59 float RightStickY(void) { return CurStatus.rightStick.yPos; }
60
61 float LeftStickX(void) { return CurStatus.leftStick.xPos; }
62 float LeftStickY(void) { return CurStatus.leftStick.yPos; }
63
64private:
65 typedef struct {
66 uint16_t select : 1;
67 uint16_t i : 1;
68 uint16_t j : 1;
69 uint16_t start : 1;
70
71 uint16_t leftUp : 1;
72 uint16_t leftRight : 1;
73 uint16_t leftDown : 1;
74 uint16_t leftLeft : 1;
75
76 uint16_t l2 : 1;
77 uint16_t r2 : 1;
78 uint16_t l1 : 1;
79 uint16_t r1 : 1;
80
81 uint16_t rightUp : 1;
82 uint16_t rightRight : 1;
83 uint16_t rightDown : 1;
84 uint16_t rightLeft : 1;
86
87 typedef struct {
88 uint8_t xVal, yVal;
89 uint8_t xCenter, yCenter;
90 float xPos, yPos;
91 bool isCentered;
92 } tStickData;
93
94 typedef struct {
95 uint8_t success;
96 uint8_t statLen;
97 uint16_t buttons; /* 16 buttons */
98 uint8_t r3h;
99 uint8_t r3v;
100 uint8_t l3h;
101 uint8_t l3v;
102 uint8_t kanAtsu[12]; // deal with this crap later
103 uint8_t whoKnows[12]; // make the structure 32 bytes long
104 tStickData rightStick, leftStick;
105 } tPadStatus;
106
107 bool IsDown(tPadStatus status, unsigned int button);
108 bool IsUp(tPadStatus status, unsigned int button);
109 bool UpdateStick(tStickData* stickCur, tStickData* stickLast);
110
111 uint128_t DmaBuffer[scePadDmaBufferMax] __attribute__((aligned(64)));
112 tPadStatus CurStatus __attribute__((aligned(16)));
113 tPadStatus LastStatus __attribute__((aligned(16)));
114 unsigned int uiPort;
115 bool bPadModeSet;
116};
117
118extern CPad Pad0;
119extern CPad Pad1;
120
121#endif // pads_h
Definition pads.h:46