-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.c
168 lines (70 loc) · 1.67 KB
/
controller.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "controller.h"
void wait_button(void) {
ctrl_data_t ctl;
int btn;
btn=1;
while(btn!=0){
sceCtrlRead(&ctl,1);
btn = ((ctl.buttons & 0xF000) != 0);
}
btn=0;
while(btn==0){
sceCtrlRead(&ctl,1);
btn = ((ctl.buttons & 0xF000) != 0);
}
}
#define REPEAT_TIME 0x40000
static unsigned long control_bef_ctl = 0;
static unsigned long control_bef_tick = 0;
unsigned long Read_Key(void) {
ctrl_data_t ctl;
sceCtrlRead(&ctl,1);
if (ctl.buttons == control_bef_ctl) {
if ((ctl.frame - control_bef_tick) > REPEAT_TIME) {
return control_bef_ctl;
}
return 0;
}
control_bef_ctl = ctl.buttons;
control_bef_tick = ctl.frame;
return control_bef_ctl;
}
int Confirm_Control(void) {
unsigned long key;
while(1) {
while(1) {
key = Read_Key();
if (key != 0) break;
pgWaitV();
}
if (key & CTRL_CIRCLE) {
return 1;
}
if (key & CTRL_CROSS) {
return 0;
}
}
}
int Control(void) {
unsigned long key;
int i;
// wait key
while(1) {
key = Read_Key();
if (key != 0) break;
pgWaitV();
}
if (key & CTRL_SQUARE) {return 1;}
if (key & CTRL_TRIANGLE) {return 2;}
if (key & CTRL_CIRCLE) {return 3;}
if (key & CTRL_CROSS) {return 4;}
if (key & CTRL_UP) {return 5;}
if (key & CTRL_DOWN) {return 6;}
if (key & CTRL_LEFT) {return 7;}
if (key & CTRL_RIGHT) {return 8;}
if (key & CTRL_START) {return 9;}
if (key & CTRL_SELECT) {return 10;}
if (key & CTRL_LTRIGGER) {return 11;}
if (key & CTRL_RTRIGGER) {return 12;}
return 0;
}