34#define CD_SERVER_INIT 0x80000592
35#define CD_SERVER_SEARCHFILE 0x80000597
36#define CD_SERVER_DISKREADY 0x8000059A
38#define CD_SERVER_POFF 0x80000596
44void _CdSemaExit(
void);
54#ifdef F__libcdvd_internals
57int bindDiskReady = -1;
58int bindSearchFile = -1;
72int callbackSemaId = -1;
74volatile int cbSema = 0;
77volatile int CdCallbackNum;
83int callbackThreadId = 0;
99extern int bindDiskReady;
100extern int bindSearchFile;
105extern int callbackSemaId;
106extern volatile int cbSema;
107extern volatile int CdCallbackNum;
109extern int CdThreadId;
111extern int callbackThreadId;
113extern s32 diskReadyMode;
114extern s32 trayReqData;
117extern u32 searchFileRecvBuff;
127 CdThreadId = GetThreadId();
135 if (SifBindRpc(&clientInit, CD_SERVER_INIT, 0) < 0) {
137 printf(
"Libcdvd bind err CD_Init\n");
138 }
else if (clientInit.server != 0)
146 if (SifCallRpc(&clientInit, 0, 0, &initMode, 4, 0, 0, 0, 0) < 0)
150 printf(
"Libcdvd Exit\n");
163#ifdef F_sceCdIntToPos
166 p->minute = (((((i + 150) / 75) / 60) / 10) * 16) + ((((i + 150) / 75) / 60) % 10);
167 p->second = (((((i + 150) / 75) % 60) / 10) * 16) + ((((i + 150) / 75) % 60) % 10);
168 p->sector = ((((i + 150) % 75) / 10) * 16) + (((i + 150) % 75) % 10);
173#ifdef F_sceCdPosToInt
176 return ((((p->minute / 16) * 10) + (p->minute & 0xF)) * 60 + ((p->second / 16) * 10) + (p->second & 0xF)) * 75 + (p->sector / 16) * 10 + (p->sector & 0xF) - 150;
180#ifdef F_sceCdSearchFile
184 if (PollSema(nCmdSemaId) != nCmdSemaId)
186 nCmdNum = CD_SERVER_SEARCHFILE;
187 ReferThreadStatus(CdThreadId, &CdThreadParam);
189 SignalSema(nCmdSemaId);
193 if (bindSearchFile < 0) {
195 if (SifBindRpc(&clientSearchFile, CD_SERVER_SEARCHFILE, 0) < 0) {
197 printf(
"libsceCdvd bind err sceCdSearchFile\n");
199 if (clientSearchFile.server != 0)
207 strncpy(searchFileSendBuff.name, name, 255);
208 searchFileSendBuff.name[255] =
'\0';
209 searchFileSendBuff.dest = &searchFileSendBuff;
212 printf(
"ee call cmd search %s\n", searchFileSendBuff.name);
213 if (SifCallRpc(&clientSearchFile, 0, 0, &searchFileSendBuff,
sizeof(
SearchFilePkt), nCmdRecvBuff, 4, NULL, NULL) < 0) {
214 SignalSema(nCmdSemaId);
218 memcpy(file, UNCACHED_SEG(&searchFileSendBuff), 32);
221 printf(
"search name %s\n", file->
name);
222 printf(
"search size %d\n", file->
size);
223 printf(
"search loc lnn %d\n", file->
lsn);
224 printf(
"search loc date %02X %02X %02X %02X %02X %02X %02X %02X\n",
227 printf(
"search loc date %02d %02d %02d %02d %02d %02d %02d %02d\n",
232 SignalSema(nCmdSemaId);
233 return *(s32 *)UNCACHED_SEG(nCmdRecvBuff);
237#ifdef F_sceCdDiskReady
241 printf(
"DiskReady 0\n");
244 if (PollSema(sCmdSemaId) != sCmdSemaId)
247 SignalSema(sCmdSemaId);
252 if (bindDiskReady < 0) {
254 if (SifBindRpc(&clientDiskReady, CD_SERVER_DISKREADY, 0) < 0) {
256 printf(
"Libcdvd bind err CdDiskReady\n");
258 if (clientDiskReady.server != 0)
265 diskReadyMode = mode;
267 if (SifCallRpc(&clientDiskReady, 0, 0, &diskReadyMode, 4, sCmdRecvBuff, 4, NULL, NULL) < 0) {
268 SignalSema(sCmdSemaId);
272 printf(
"DiskReady ended\n");
274 SignalSema(sCmdSemaId);
275 return *(s32 *)UNCACHED_SEG(sCmdRecvBuff);
280void _CdSemaInit(
void)
285 if (nCmdSemaId != -1 && sCmdSemaId != -1)
288 semaParam.init_count = 1;
289 semaParam.max_count = 1;
290 semaParam.option = 0;
291 nCmdSemaId = CreateSema(&semaParam);
292 sCmdSemaId = CreateSema(&semaParam);
294 semaParam.init_count = 0;
295 callbackSemaId = CreateSema(&semaParam);
302void _CdSemaExit(
void)
304 if (callbackThreadId) {
306 SignalSema(callbackSemaId);
308 DeleteSema(nCmdSemaId);
309 DeleteSema(sCmdSemaId);
310 DeleteSema(callbackSemaId);
314#ifdef F_sceCdInitEeCB
315static void _CdCallbackLoop(
void);
316s32
sceCdInitEeCB(s32 priority,
void *stackAddr, s32 stackSize)
319 if (callbackThreadId != 0) {
320 ChangeThreadPriority(callbackThreadId, priority);
324 CdThreadId = GetThreadId();
325 ReferThreadStatus(CdThreadId, &CdThreadParam);
326 callbackThreadParam.stack_size = stackSize;
327 callbackThreadParam.gp_reg = &
_gp;
328 callbackThreadParam.func = &_CdCallbackLoop;
329 callbackThreadParam.stack = stackAddr;
330 callbackThreadParam.initial_priority = priority;
331 callbackThreadId = CreateThread(&callbackThreadParam);
332 StartThread(callbackThreadId, NULL);
338#ifdef F_sceCdCallback
346 sceCdCallbackFunc = newFunc;
359#ifdef F_sceCdInitEeCB
360static void _CdCallbackLoop(
void)
363 WaitSema(callbackSemaId);
366 if (CdCallbackNum == -1)
370 printf(
"sceCdCallbackFunc = %08X CdCallbackNum = %d\n", (u32)sceCdCallbackFunc, CdCallbackNum);
373 if (sceCdCallbackFunc && CdCallbackNum)
374 sceCdCallbackFunc(CdCallbackNum);
382#ifdef F__CdGenericCallbackFunction
383void _CdGenericCallbackFunction(
void *funcNum)
386 CdCallbackNum = *(s32 *)funcNum;
387 iSignalSema(nCmdSemaId);
390 if (callbackThreadId) {
391 if (sceCdCallbackFunc) {
392 iSignalSema(callbackSemaId);
int sceCdSearchFile(sceCdlFILE *file, const char *name)
int sceCdInitEeCB(int priority, void *stackAddr, int stackSize)
sceCdCBFunc sceCdCallback(sceCdCBFunc function)
int sceCdDiskReady(int mode)
u32 sceCdPosToInt(sceCdlLOCCD *p)
sceCdlLOCCD * sceCdIntToPos(u32 i, sceCdlLOCCD *p)
void(* sceCdCBFunc)(int reason)