sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
ps2cam_rpc.c
Go to the documentation of this file.
1/*
2 _____ ___ ____
3 ____| | ____| PSX2 OpenSource Project
4 | ___| |____ (c) 2004-2005 Lion | (psxdever@hotmail.com)
5*/
6
11
12#include <tamtypes.h>
13#include <kernel.h>
14#include <sifrpc.h>
15#include <stdio.h>
16#include <string.h>
17#include <iopcontrol.h>
19
20
21
22#define PS2_CAM_RPC_ID 0x00FD000 +2
23
24
25
26static SifRpcClientData_t cdata __attribute__((aligned(64)));
27static char data[1024] __attribute__((aligned(64)));
28static char campacket[896] __attribute__((aligned(64)));
29
30ee_sema_t compSema;
31
32int sem;
33
34
35
36
37int PS2CamInit(int mode)
38{
39 int ret=0;
40 int *buf;
41 // unsigned int i;
42 // int timeout = 100000;
43
44 if (HasIopRebootedSinceLastCall())
45 memset(&cdata, 0, sizeof(cdata));
46 if (cdata.server)
47 return 0;
48
49 sceSifInitRpc(0);
50
51 while (((ret = sceSifBindRpc(&cdata, PS2_CAM_RPC_ID, 0)) >= 0) && (cdata.server == NULL))
52 nopdelay();
53
54 nopdelay();
55
56
57
58 if (ret < 0)return ret;
59
60
61
62 buf = (int *)&data[0];
63 buf[0] = mode;
64
65 printf("bind done\n");
66
67 sceSifCallRpc(&cdata, PS2CAM_RPC_INITIALIZE, 0, (void*)(&data[0]),4,(void*)(&data[0]),4,0,0);
68 nopdelay();
69
70printf("init done\n");
71
72
73 compSema.init_count = 1;
74 compSema.max_count = 1;
75 compSema.option = 0;
76 sem = CreateSema(&compSema);
77
78printf("sema done\n");
79
80 return buf[0];
81}
82
83
84
85
86
88{
89 int *ret;
90
91 ret = (int *)&data[0];
92
93 sceSifCallRpc(&cdata, PS2CAM_RPC_GETIRXVERSION, 0, (void*)(&data[0]),4,(void*)(&data[0]),4,0,0);
94 nopdelay();
95
96 return ret[0];
97}
98
99
100
101
102
104{
105 int *ret;
106
107 ret = (int *)&data[0];
108
109 sceSifCallRpc(&cdata, PS2CAM_RPC_GETDEVCOUNT, 0, (void*)(&data[0]),4,(void*)(&data[0]),4,0,0);
110 nopdelay();
111
112 return ret[0];
113}
114
115
116
117
118
119int PS2CamOpenDevice(int device_index)
120{
121 int *ret;
122
123 ret = (int *)&data[0];
124
125 ret[0] = device_index;
126
127 sceSifCallRpc(&cdata, PS2CAM_RPC_OPENDEVICE, 0, (void*)(&data[0]),4,(void*)(&data[0]),4,0,0);
128
129 return ret[0];
130}
131
132
133
134
135int PS2CamCloseDevice(int handle)
136{
137 int *ret;
138
139 ret = (int *)&data[0];
140
141 ret[0] = handle;
142
143 sceSifCallRpc(&cdata, PS2CAM_RPC_CLOSEDEVICE, 0, (void*)(&data[0]),4,(void*)(&data[0]),4,0,0);
144
145 return ret[0];
146}
147
148
149
150
151
153{
154 int *ret;
155
156
157 ret = (int *)&data[0];
158
159 ret[0] = handle;
160
161
162 sceSifCallRpc(&cdata, PS2CAM_RPC_GETDEVSTATUS, 0, (void*)(&data[0]),4,(void*)(&data[0]),4,0,0);
163 nopdelay();
164
165 return ret[0];
166}
167
168
169
170
171int PS2CamGetDeviceInfo(int handle, PS2CAM_DEVICE_INFO *info)
172{
173 int *ret;
174 PS2CAM_DEVICE_INFO *iop_info;
175
176 ret = (int *)&data[0];
177 iop_info = (PS2CAM_DEVICE_INFO *)&ret[1];
178
179 ret[0] = handle;
180
181 memcpy(iop_info, info, info->ssize);
182
183 sceSifCallRpc(&cdata, PS2CAM_RPC_GETDEVINFO, 0, (void*)(&data[0]),info->ssize+4,(void*)(&data[0]),info->ssize+4,0,0);
184 nopdelay();
185
186 memcpy(info, iop_info, iop_info->ssize);
187
188 return ret[0];
189}
190
191
192
193
194
195int PS2CamSetDeviceBandwidth(int handle, char bandwidth)
196{
197 int *ret;
198
199 ret = (int *)&data[0];
200
201 ret[0] = handle;
202 ret[1] = bandwidth;
203
204
205
206 sceSifCallRpc(&cdata, PS2CAM_RPC_SETDEVBANDWIDTH, 0, (void*)(&data[0]),4,(void*)(&data[0]),4,0,0);
207 nopdelay();
208
209 return ret[0];
210}
211
212
213
214
215
216
217int PS2CamReadPacket(int handle)
218{
219 int *ret;
220 SifRpcReceiveData_t rdata;
221
222 WaitSema(sem);
223
224 ret = (int *)&data[0];
225
226 ret[0] = handle;
227
228 sceSifCallRpc(&cdata, PS2CAM_RPC_READPACKET, 0, (void*)(&data[0]),4,(void*)(&data[0]),4*2,0,0);
229
230
231 if(ret[0] < 0) return ret[0];
232
233 SyncDCache(campacket, (u8 *)(&campacket[0]) + sizeof(campacket));
234 if (sceSifGetOtherData(&rdata, (void *)ret[1], &campacket[0], sizeof(campacket), 0) < 0)
235 return -1;
236
237 //if i add a printf here, the ps2 will exit to sony's explorer
238 SignalSema(sem);
239 return ret[0];
240}
241
242
243
244
245int PS2CamSetLEDMode(int handle, int mode)
246{
247 int *ret;
248
249 ret = (int *)&data[0];
250
251 ret[0] = handle;
252 ret[1] = mode;
253
254 sceSifCallRpc(&cdata, PS2CAM_RPC_SETLEDMODE, 0, (void*)(&data[0]),4,(void*)(&data[0]),4,0,0);
255
256 return ret[0];
257}
258
259
260
262{
263 int *ret;
264
265 ret = (int *)&data[0];
266
267 ret[0] = handle;
268
269 memcpy(&ret[1], cfg, cfg->ssize);
270
271 sceSifCallRpc(&cdata, PS2CAM_RPC_SETDEVCONFIG, 0, (void*)(&data[0]), 4+cfg->ssize,(void*)(&data[0]),4+cfg->ssize,0,0);
272
273 return ret[0];
274}
275
276
277
278int PS2CamExtractFrame(int handle, char *buffer, int bufsize)
279{
280 static int capturing;
281 static int pos;
282 static int pic_size;
283
284 (void)bufsize;
285
286 pos = 0;
287 capturing = 0;
288
289
290
291 while(1)
292 {
293 static EYETOY_FRAME_HEAD *head;
294 static int ret;
295
296 ret = PS2CamReadPacket(handle);
297
298 // printf("packet =%d\n",ret);
299 //if read has a error return it
300 if(ret < 0) return ret;
301
302 head = (EYETOY_FRAME_HEAD *)UNCACHED_SEG(&campacket[0]);
303
304 if(head->magic2==0xff && head->magic3==0xff && ret!=0)
305 {
306 if(head->type==0x50 && head->frame==0x00)
307 {
308 // start of frame
309 // printf("SOF(%d)\n",ret);
310 if(capturing == 1)
311 {
312 return 0;
313 }
314
315 memcpy(&buffer[pos], UNCACHED_SEG(&campacket[16]), ret-16 );
316 pos += (ret-16);
317 capturing = 1;
318
319 }
320 else if(head->type==0x50 && head->frame==0x01)
321 {
322 // frame head with no data
323 // so do nothing
324
325 }
326 else if(head->type==0x51 && capturing==1)
327 {
328 //end of frame
329 // printf("EOF(%d)\n",ret);
330 pic_size = (int)(((head->Lo) + ((int)(head->Hi)<<8))<<3);
331
332
333 if(pos != pic_size)
334 {
335 return 0;
336 }
337 else
338 {
339 return pic_size;
340 }
341 }
342 else
343 {
344 //if it doesnt fit in those pos then it must be data
345 if(capturing==1)
346 {
347 memcpy(&buffer[pos], UNCACHED_SEG(&campacket[0]), ret );
348 pos += (ret);
349 }
350 }
351 }
352 else
353 {
354 // it must be data
355 if(capturing==1 && ret !=0)
356 {
357 memcpy(&buffer[pos], UNCACHED_SEG(&campacket[0]), ret );
358 pos += (ret);
359 }
360 }
361 }
362
363}
364
365
366
367
#define PS2CAM_RPC_GETDEVSTATUS
Definition ps2cam.h:28
#define PS2CAM_RPC_SETDEVBANDWIDTH
Definition ps2cam.h:32
int PS2CamGetDeviceStatus(int device_id)
Definition ps2cam.c:1090
int PS2CamGetDeviceCount(void)
Definition ps2cam.c:967
int PS2CamSetLEDMode(int device_id, int mode)
Definition ps2cam.c:1309
int PS2CamGetDeviceInfo(int handle, int *info)
Definition ps2cam.c:1114
int PS2CamInit(int mode)
Definition ps2cam.c:955
#define PS2CAM_RPC_GETIRXVERSION
Definition ps2cam.h:20
int PS2CamCloseDevice(int handle)
Definition ps2cam.c:1060
int PS2CamSetDeviceBandwidth(int device_id, char bandwidth)
Definition ps2cam.c:1179
#define PS2CAM_RPC_GETDEVCOUNT
Definition ps2cam.h:24
#define PS2CAM_RPC_SETLEDMODE
Definition ps2cam.h:36
#define PS2CAM_RPC_GETDEVINFO
Definition ps2cam.h:30
#define PS2CAM_RPC_INITIALIZE
Definition ps2cam.h:22
int PS2CamGetIRXVersion(void)
Definition ps2cam.c:940
int PS2CamSetDeviceConfig(int handle, void *config)
Definition ps2cam.c:1354
int PS2CamOpenDevice(int device_index)
Definition ps2cam.c:991
int PS2CamReadPacket(int device_id)
Definition ps2cam.c:1255
#define PS2CAM_RPC_READPACKET
Definition ps2cam.h:34
unsigned char magic3
Definition ps2cam.h:211
unsigned char Hi
Definition ps2cam.h:228
unsigned char type
Definition ps2cam.h:213
unsigned char Lo
Definition ps2cam.h:226
unsigned char frame
Definition ps2cam.h:220
unsigned char magic2
Definition ps2cam.h:209
unsigned int ssize
Definition ps2cam.h:185
unsigned int ssize
Definition ps2cam.h:148