1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 179
6#include "sce/libgraph.h"
13unsigned char pad_dma_buf[1024] __attribute__((aligned(64)));
14unsigned char pad_dma_buf2[1024] __attribute__((aligned(64)));
21 while (sceGsSyncV(0) == 0) {
31 for (i = 0; i < 2; i++) {
39 for (
int j = 0; j < 6; j++) {
48 for (
int j = 0; j < 32; j++) {
55 if (!scePadPortOpen(0, 0, pad_dma_buf)) {
56 printf(
"ERROR: scePadPortOpen\n");
65 if (!scePadPortOpen(1, 0, pad_dma_buf2)) {
66 printf(
"ERROR: scePadPortOpen\n");
76#define PAD_STATIC_COUNTER_1(name) static const int name = 0;
77#define PAD_STATIC_COUNTER_2(name) PAD_STATIC_COUNTER_1(name##0) PAD_STATIC_COUNTER_1(name##1)
78#define PAD_STATIC_COUNTER_4(name) PAD_STATIC_COUNTER_2(name##0) PAD_STATIC_COUNTER_2(name##1)
79#define PAD_STATIC_COUNTER_8(name) PAD_STATIC_COUNTER_4(name##0) PAD_STATIC_COUNTER_4(name##1)
80#define PAD_STATIC_COUNTER_16(name) PAD_STATIC_COUNTER_8(name##0) PAD_STATIC_COUNTER_8(name##1)
81#define PAD_STATIC_COUNTER_32(name) PAD_STATIC_COUNTER_16(name##0) PAD_STATIC_COUNTER_16(name##1)
82#define PAD_STATIC_COUNTER_64(name) PAD_STATIC_COUNTER_32(name##0) PAD_STATIC_COUNTER_32(name##1)
83#define PAD_STATIC_COUNTER_128(name) PAD_STATIC_COUNTER_64(name##0) PAD_STATIC_COUNTER_64(name##1)
85int pad_button_read(
PAD_STATUS *status,
int port,
int slot) {
86 PAD_STATIC_COUNTER_128(pad_static_128_)
87 PAD_STATIC_COUNTER_16(pad_static_16_)
88 PAD_STATIC_COUNTER_4(pad_static_4_)
89 PAD_STATIC_COUNTER_1(pad_static_1_)
93 unsigned char data[32];
102 if (!scePadRead(port, slot, data)) {
107 int button = ((data[2] << 8) | data[3]) ^ 0xffff;
108 status->
button = button & 0xffff;
120int read_pad(
PAD_STATUS *status,
int port,
int slot) {
121 volatile int *phase = &status->
phase;
122 int *state = &status->
state;
124 int *read_result = &status->
pad_mode;
127 *state = scePadGetState(port, slot);
129 if (*state == scePadStateDiscon) {
130 *phase = PAD_PHASE_QUERY;
136 case PAD_PHASE_QUERY:
137 if (*state == scePadStateStable || *state == scePadStateFindCTP1) {
138 int terminal_id = scePadInfoMode(port, slot, InfoModeCurID, 0);
140 if (terminal_id != 0) {
141 *mode_count = scePadInfoMode(port, slot, InfoModeCurExID, 0);
143 if (*mode_count > 0) {
144 terminal_id = *mode_count;
147 switch (terminal_id) {
148 case PAD_TERMINAL_NEGCON:
149 *phase = PAD_PHASE_READY;
151 case PAD_TERMINAL_KONAMI_GUN:
152 *phase = PAD_PHASE_READY;
154 case PAD_TERMINAL_DIGITAL:
155 *phase = PAD_PHASE_ANALOG_CHECK;
157 case PAD_TERMINAL_ANALOG_JOYSTICK:
158 *phase = PAD_PHASE_READY;
160 case PAD_TERMINAL_NAMCO_GUN:
161 *phase = PAD_PHASE_READY;
163 case PAD_TERMINAL_DUALSHOCK:
164 *phase = PAD_PHASE_ACTUATOR_CHECK;
166 case PAD_TERMINAL_EX_TSURICON:
167 *phase = PAD_PHASE_READY;
169 case PAD_TERMINAL_EX_JOGCON:
170 *phase = PAD_PHASE_READY;
173 *phase = PAD_PHASE_READY;
180 case PAD_PHASE_ANALOG_CHECK:
181 if (scePadInfoMode(port, slot, InfoModeCurExID, 0) == 0) {
182 *phase = PAD_PHASE_READY;
188 case PAD_PHASE_ANALOG_SET:
189 if (scePadSetMainMode(port, slot, 1, 3) == 1) {
194 case PAD_PHASE_ANALOG_WAIT:
195 if (scePadGetState(port, slot) != scePadStateExecCmd) {
196 *phase = PAD_PHASE_QUERY;
200 case PAD_PHASE_ACTUATOR_CHECK:
201 if (scePadInfoAct(port, slot, -1, 0) == 0) {
202 *phase = PAD_PHASE_READY;
208 for (
int i = 2; i < 6; i++) {
212 if (scePadSetActAlign(port, slot, status->
actuator)) {
217 case PAD_PHASE_ACTUATOR_WAIT:
218 if (scePadGetState(port, slot) != scePadStateExecCmd) {
219 *phase = PAD_PHASE_READY;
224 if (*state == scePadStateStable || *state == scePadStateFindCTP1) {
225 int result = pad_button_read(status, port, slot);
226 *read_result = result;
229 if (*previous_read_result != 0 && *read_result != *previous_read_result) {
230 *previous_read_result = 0;
231 *phase = PAD_PHASE_QUERY;
236 *previous_read_result = *read_result;
251 if (*read_result == 4) {
282 *destination = value;
284 }
while (copy_count > 0);
296 *destination = value;
298 }
while (copy_count > 0);
304 for (i = 0; i < 2; i++) {
312 if (threshold <
GetLX()) {
316 if (
GetLX() < -threshold) {
320 if (threshold <
GetLY()) {
324 if (
GetLY() < -threshold) {
333 for (i = 0; i < 32; i++, bit <<= 1) {
334 if (repeat_state->
enabled & bit) {
339 repeat_state->
active |= bit;
343 repeat_state->
active &= ~bit;
353 for (i = 0; i < 2; i++) {
383#undef PAD_STATIC_COUNTER_128
384#undef PAD_STATIC_COUNTER_64
385#undef PAD_STATIC_COUNTER_32
386#undef PAD_STATIC_COUNTER_16
387#undef PAD_STATIC_COUNTER_8
388#undef PAD_STATIC_COUNTER_4
389#undef PAD_STATIC_COUNTER_2
390#undef PAD_STATIC_COUNTER_1
393 for (
int i = 0; i < 2; i++) {
417int AxisCalibration(
int axis) {
419 int calibrated = axis - 128;
422 if (calibrated < 50 && calibrated > -50) {
424 }
else if (calibrated > zero) {
425 calibrated = ((calibrated - 49) << 7) / 78;
427 calibrated = ((calibrated + 50) << 7) / 78;
474 for (i = 0; i < 32; i++, bit <<= 1) {
477 auto_repeat->
active &= ~bit;
490 for (i = 0; i < 32; i++, bit <<= 1) {
491 if (!(auto_repeat->
enabled & bit) && (mask & bit)) {
493 auto_repeat->
active &= ~bit;
534 return (
float)
GetRX() / 128.0f;
538 return (
float)
GetRY() / 128.0f;
542 return (
float)
GetLX() / 128.0f;
546 return (
float)
GetLY() / 128.0f;
550 return (
float)
GetLX2() / 128.0f;
554 return (
float)
GetLY2() / 128.0f;
563 if (mask == PAD_START &&
On2(PAD_START)) {
567 if (mask != PAD_START &&
On2(PAD_SELECT)) {
589 if (mask == PAD_START &&
On2(PAD_START)) {
593 if (mask != PAD_START &&
On2(PAD_SELECT)) {
626 if (motor < 0 || motor >= 2 || duration < 0 || duration > 1200) {
633 intensity = intensity != 0;
void VibrationEnable(int enable)
void CancelAutoRepeat(int mask)
void MenuModeOn(int threshold)
void SetVibration(int motor, int intensity, int duration)
void SetAutoRepeat(int mask, int initial_delay, int repeat_delay)
unsigned char actuator[6]
unsigned char vibration[6]
struct PAD_DATA::@16 input
unsigned char vibration[6]
struct PAD_DATA::@17 actuator