1: /******************************************************************************
2:
3: SystemButtons.prx
4:
5: ******************************************************************************/
6:
7: #include <pspsdk.h>
8: #include <pspctrl.h>
9: #include <pspimpose_driver.h>
10:
11:
12: PSP_MODULE_INFO("SystemButtons", PSP_MODULE_KERNEL, 0, 0);
13: PSP_MAIN_THREAD_ATTR(0);
14:
15:
16: /******************************************************************************
17: prototypes
18: ******************************************************************************/
19:
20: int sceCtrl_driver_C4AAD55F(SceCtrlData *pad_data, int count);
21:
22: #define sceCtrlPeekBufferPositive371 sceCtrl_driver_C4AAD55F
23:
24:
25: /******************************************************************************
26: local variables
27: ******************************************************************************/
28:
29: static volatile int thread_active;
30: static unsigned int system_buttons;
31: static int main_volume;
32: static SceUID sysbutton_thread;
33:
34: static int (*__sceCtrlPeekBufferPositive)(SceCtrlData *pad_data, int count);
35: static int (*__sceImposeGetParam)(SceImposeParam param);
36:
37:
38: /******************************************************************************
39: functions
40: ******************************************************************************/
41:
42: static int SystemButtonsThread(SceSize args, void *argp)
43: {
44: SceCtrlData paddata;
45:
46: thread_active = 1;
47:
48: while (thread_active)
49: {
50: if (__sceCtrlPeekBufferPositive)
51: {
52: (*__sceCtrlPeekBufferPositive)(&paddata, 1);
53: system_buttons = paddata.Buttons & 0xf70000;
54:
55: if (__sceImposeGetParam)
56: main_volume = (*__sceImposeGetParam)(PSP_IMPOSE_MAIN_VOLUME);
57: }
58: sceKernelDelayThread(1000000/60);
59: }
60:
61: sceKernelExitThread(0);
62:
63: return 0;
64: }
65:
66:
67: void initSystemButtons(int devkit_version)
68: {
69: if (devkit_version < 0x03070110)
70: __sceCtrlPeekBufferPositive = sceCtrlPeekBufferPositive;
71: else
72: __sceCtrlPeekBufferPositive = sceCtrlPeekBufferPositive371;
73:
74: if (devkit_version >= 0x03050210)
75: __sceImposeGetParam = sceImposeGetParam;
76: }
77:
78:
79: unsigned int readSystemButtons(void)
80: {
81: return system_buttons;
82: }
83:
84:
85: unsigned int readHomeButton(void)
86: {
87: return system_buttons & PSP_CTRL_HOME;
88: }
89:
90:
91: unsigned int readVolumeButtons(void)
92: {
93: return system_buttons & (PSP_CTRL_VOLUP | PSP_CTRL_VOLDOWN);
94: }
95:
96:
97: unsigned int readVolUpButton(void)
98: {
99: return system_buttons & PSP_CTRL_VOLUP;
100: }
101:
102:
103: unsigned int readVolDownButton(void)
104: {
105: return system_buttons & PSP_CTRL_VOLDOWN;
106: }
107:
108:
109: unsigned int readNoteButton(void)
110: {
111: return system_buttons & PSP_CTRL_NOTE;
112: }
113:
114:
115: unsigned int readScreenButton(void)
116: {
117: return system_buttons & PSP_CTRL_SCREEN;
118: }
119:
120:
121: unsigned int readHoldSwitch(void)
122: {
123: return system_buttons & PSP_CTRL_HOLD;
124: }
125:
126:
127: unsigned int readWLANSwitch(void)
128: {
129: return system_buttons & PSP_CTRL_WLAN_UP;
130: }
131:
132:
133: int readMainVolume(void)
134: {
135: return main_volume;
136: }
137:
138:
139: int module_start(SceSize args, void *argp)
140: {
141: __sceCtrlPeekBufferPositive = NULL;
142: __sceImposeGetParam = NULL;
143:
144: system_buttons = 0;
145: main_volume = -1;
146: thread_active = 0;
147: sysbutton_thread = sceKernelCreateThread(
148: "System Button Thread",
149: SystemButtonsThread,
150: 0x11,
151: 0x200,
152: 0,
153: NULL
154: );
155:
156: if (sysbutton_thread >= 0)
157: sceKernelStartThread(sysbutton_thread, 0, 0);
158:
159: return 0;
160: }
161:
162:
163: int module_stop(void)
164: {
165: if (sysbutton_thread >= 0)
166: {
167: thread_active = 0;
168: sceKernelWaitThreadEnd(sysbutton_thread, NULL);
169: }
170: return 0;
171: }
172: