32#define CD_SERVER_NCMD 0x80000595
36 CDVD_ST_CMD_START = 1,
69int _CdCheckNCmd(
int cmd);
78#ifdef F__ncmd_internals
103u32 cdda_st_buf[64 /
sizeof(u32)] ALIGNED(64);
108extern int nCmdSemaId;
110extern u32 readStreamData[5];
111extern u32 readData[6];
113extern u32 getTocSendBuff[3];
114extern u32 _rd_intr_data[64];
115extern u32 curReadPos;
116extern u8 tocBuff[2064];
117extern u8 nCmdRecvBuff[48];
119extern int streamStatus;
121extern u32 seekSector;
122extern u32 cdda_st_buf[64 /
sizeof(u32)];
150void _CdAlignReadBuffer(
void *data);
154#ifdef F__CdAlignReadBuffer
155void _CdAlignReadBuffer(
void *data)
159 if (uncached->size1 && uncached->dest1) {
160 memcpy(uncached->dest1, &uncached->src1, uncached->size1);
163 if (uncached->size2 && uncached->dest2) {
164 memcpy(uncached->dest2, &uncached->src2, uncached->size2);
167 _CdGenericCallbackFunction((
void *)&CdCallbackNum);
178 if (_CdCheckNCmd(CD_NCMD_READ) == 0)
182 readData[1] = sectors;
183 readData[2] = (u32)buf;
184 readData[3] = (mode->trycount) | (mode->spindlctrl << 8) | (mode->datapattern << 16);
185 readData[4] = (u32)_rd_intr_data;
186 readData[5] = (u32)&curReadPos;
189 if (mode->datapattern == SCECdSecS2328)
190 bufSize = sectors * 2328;
191 else if (mode->datapattern == SCECdSecS2340)
192 bufSize = sectors * 2340;
194 bufSize = sectors * 2048;
197 SifWriteBackDCache(buf, bufSize);
198 SifWriteBackDCache(&curReadPos,
sizeof(curReadPos));
201 printf(
"call sceCdread cmd\n");
203 CdCallbackNum = CD_NCMD_READ;
206 if (SifCallRpc(&clientNCmd, CD_NCMD_READ,
SIF_RPC_M_NOWAIT, readData, 24, NULL, 0, &_CdAlignReadBuffer, _rd_intr_data) < 0) {
209 SignalSema(nCmdSemaId);
214 printf(
"sceCdread end\n");
222#ifdef F_sceCdReadDVDV
223int sceCdReadDVDV(u32 lbn, u32 nsectors,
void *buf,
sceCdRMode *rm)
227 if (_CdCheckNCmd(CD_NCMD_DVDREAD) == 0)
231 readData[1] = nsectors;
232 readData[2] = (u32)buf;
234 readData[4] = (u32)_rd_intr_data;
236 SifWriteBackDCache(buf, nsectors * 2064);
238 CdCallbackNum = CD_NCMD_DVDREAD;
241 if (SifCallRpc(&clientNCmd, CD_NCMD_DVDREAD,
SIF_RPC_M_NOWAIT, readData, 24, NULL, 0, &_CdAlignReadBuffer, _rd_intr_data) < 0) {
244 SignalSema(nCmdSemaId);
254#ifdef F_sceCdReadCDDA
255int sceCdReadCDDA(u32 lbn, u32 nsectors,
void *buf,
sceCdRMode *rm)
257 unsigned int sector_size;
261 if (_CdCheckNCmd(CD_NCMD_CDDAREAD) == 0)
265 readData[1] = nsectors;
266 readData[2] = (u32)buf;
268 readData[4] = (u32)_rd_intr_data;
282 SifWriteBackDCache(buf, nsectors * sector_size);
284 CdCallbackNum = CD_NCMD_CDDAREAD;
287 if (SifCallRpc(&clientNCmd, CD_NCMD_CDDAREAD,
SIF_RPC_M_NOWAIT, readData, 24, NULL, 0, &_CdAlignReadBuffer, _rd_intr_data) < 0) {
290 SignalSema(nCmdSemaId);
305 if (_CdCheckNCmd(CD_NCMD_GETTOC) == 0)
308 getTocSendBuff[0] = (u32)tocBuff;
309 SifWriteBackDCache(tocBuff, 2064);
311 if (SifCallRpc(&clientNCmd, CD_NCMD_GETTOC, 0, getTocSendBuff, 12, nCmdRecvBuff, 8, NULL, NULL) < 0) {
312 SignalSema(nCmdSemaId);
316 tocPtr = UNCACHED_SEG(tocBuff);
317 tocEnd = tocPtr + 1024;
318 if (*(u32 *)(nCmdRecvBuff + 4)) {
320 memcpy(
toc, tocPtr, 32);
323 }
while (tocPtr < tocEnd);
325 tocEnd = tocPtr + 2048;
328 memcpy(
toc, tocPtr, 32);
331 }
while (tocPtr < tocEnd);
333 memcpy(
toc, tocPtr, 16);
336 SignalSema(nCmdSemaId);
337 return *(
int *)UNCACHED_SEG(nCmdRecvBuff);
346 if (_CdCheckNCmd(CD_NCMD_SEEK) == 0)
351 CdCallbackNum = CD_NCMD_SEEK;
353 if (SifCallRpc(&clientNCmd, CD_NCMD_SEEK,
SIF_RPC_M_NOWAIT, &seekSector, 4, NULL, 0, &_CdGenericCallbackFunction, (
void *)&CdCallbackNum) < 0) {
356 SignalSema(nCmdSemaId);
371 if (_CdCheckNCmd(CD_NCMD_STANDBY) == 0)
374 CdCallbackNum = CD_NCMD_STANDBY;
376 if (SifCallRpc(&clientNCmd, CD_NCMD_STANDBY,
SIF_RPC_M_NOWAIT, NULL, 0, NULL, 0, &_CdGenericCallbackFunction, (
void *)&CdCallbackNum) < 0) {
379 SignalSema(nCmdSemaId);
394 if (_CdCheckNCmd(CD_NCMD_STOP) == 0)
397 CdCallbackNum = CD_NCMD_STOP;
399 if (SifCallRpc(&clientNCmd, CD_NCMD_STOP,
SIF_RPC_M_NOWAIT, NULL, 0, NULL, 0, &_CdGenericCallbackFunction, (
void *)&CdCallbackNum) < 0) {
402 SignalSema(nCmdSemaId);
417 if (_CdCheckNCmd(CD_NCMD_PAUSE) == 0)
420 CdCallbackNum = CD_NCMD_PAUSE;
422 if (SifCallRpc(&clientNCmd, CD_NCMD_PAUSE,
SIF_RPC_M_NOWAIT, NULL, 0, NULL, 0, &_CdGenericCallbackFunction, (
void *)&CdCallbackNum) < 0) {
425 SignalSema(nCmdSemaId);
435#ifdef F_sceCdApplyNCmd
440 if (_CdCheckNCmd(CD_NCMD_NCMD) == 0)
443 nCmdSendBuff.ncmd.cmdNum = cmdNum;
444 nCmdSendBuff.ncmd.inBuffSize = inBuffSize;
445 memset(nCmdSendBuff.ncmd.inBuff, 0, 16);
447 memcpy(nCmdSendBuff.ncmd.inBuff, inBuff, inBuffSize);
449 if (SifCallRpc(&clientNCmd, CD_NCMD_NCMD, 0, &nCmdSendBuff, 20, nCmdRecvBuff, 16, NULL, NULL) < 0) {
450 SignalSema(nCmdSemaId);
454 SignalSema(nCmdSemaId);
455 return *(
int *)UNCACHED_SEG(nCmdRecvBuff);
459#ifdef F_sceCdReadIOPMem
464 if (_CdCheckNCmd(CD_NCMD_READIOPMEM) == 0)
468 readData[1] = sectors;
469 readData[2] = (u32)buf;
470 readData[3] = (mode->trycount) | (mode->spindlctrl << 8) | (mode->datapattern << 16);
471 readData[4] = (u32)_rd_intr_data;
472 readData[5] = (u32)&curReadPos;
474 CdCallbackNum = CD_NCMD_READIOPMEM;
476 if (SifCallRpc(&clientNCmd, CD_NCMD_READIOPMEM,
SIF_RPC_M_NOWAIT, readData, 24, NULL, 0, &_CdGenericCallbackFunction, (
void *)&CdCallbackNum) < 0) {
479 SignalSema(nCmdSemaId);
484 printf(
"sceCdread end\n");
492#ifdef F_sceCdNCmdDiskReady
495 if (_CdCheckNCmd(CD_NCMD_DISKREADY) == 0)
498 if (SifCallRpc(&clientNCmd, CD_NCMD_DISKREADY, 0, NULL, 0, &nCmdRecvBuff, 4, NULL, NULL) < 0) {
499 SignalSema(nCmdSemaId);
503 SignalSema(nCmdSemaId);
504 return *(
int *)UNCACHED_SEG(nCmdRecvBuff);
508#ifdef F_sceCdReadChain
511 int chainNum, i, sectorType;
519 printf(
"call sceCdReadChain cmd 0\n");
521 for (chainNum = 0; chainNum < 64; chainNum++) {
522 if (readChain[chainNum].lbn == 0xFFFFFFFF ||
523 readChain[chainNum].sectors == 0xFFFFFFFF || readChain[chainNum].buffer == 0xFFFFFFFF)
525 readChainData[chainNum].
lbn = readChain[chainNum].
lbn;
527 readChainData[chainNum].
buffer = readChain[chainNum].
buffer;
530 readChainData[chainNum].
lbn = 0xFFFFFFFF;
531 readChainData[chainNum].
sectors = 0xFFFFFFFF;
532 readChainData[chainNum].
buffer = 0xFFFFFFFF;
535 readChainData[65].
lbn = (mode->trycount) | (mode->spindlctrl << 8) | (mode->datapattern << 16);
536 readChainData[65].
sectors = (u32)&curReadPos;
538 if (mode->datapattern == SCECdSecS2328)
540 else if (mode->datapattern == SCECdSecS2340)
547 printf(
"call sceCdReadChain cmd 1\n");
549 for (i = 0; i < chainNum; i++) {
551 if ((readChainData[i].buffer & 1) == 0) {
553 printf(
"SifWriteBackDCache addr= 0x%08x size= %d, sector= %d\n",
554 readChainData[i].buffer, readChainData[i].sectors * sectorType,
555 readChainData[i].lbn);
556 SifWriteBackDCache((
void *)(readChainData[i].buffer),
557 readChainData[i].sectors * sectorType);
561 SifWriteBackDCache(&curReadPos, 4);
564 printf(
"call sceCdReadChain cmd 2\n");
570 SignalSema(nCmdSemaId);
575 printf(
"sceCdread end\n");
583#ifdef F_sceCdGetReadPos
586 if (CdCallbackNum == CD_NCMD_READ) {
587 return *(u32 *)UNCACHED_SEG(curReadPos);
599 return sceCdStream(lbn, 0, NULL, CDVD_ST_CMD_START, mode);
604int sceCdStRead(u32 sectorType, u32 *buffer, u32 mode, u32 *error)
610 printf(
"sceCdStRead call read size=%d mode=%d\n", sectorType, mode);
611 if (streamStatus == 0)
613 SifWriteBackDCache(buffer, sectorType * 2048);
617 ret = sceCdStream(0, sectorType, buffer, CDVD_ST_CMD_READ, &dummyMode);
622 for (i = 0; (u32)i < sectorType;) {
623 int err, sectorReadSize;
625 ret = sceCdStream(0, sectorType - i, (buffer + (i * 2048)), CDVD_ST_CMD_READ, &dummyMode);
626 sectorReadSize = ret & 0xFFFF;
633 printf(
"sceCdStRead BLK Read cur_size= %d read_size= %d req_size= %d err 0x%x\n", i,
634 sectorReadSize, sectorType, err);
636 if (sectorReadSize == 0)
642 printf(
"sceCdStRead BLK Read Ended\n");
651 return sceCdStream(0, 0, NULL, CDVD_ST_CMD_STOP, &dummyMode);
658 return sceCdStream(lbn, 0, NULL, CDVD_ST_CMD_SEEK, &dummyMode);
663int sceCdStInit(u32 buffSize, u32 numBuffers,
void *buf)
666 return sceCdStream(buffSize, numBuffers, buf, CDVD_ST_CMD_INIT, &dummyMode);
674 return sceCdStream(0, 0, NULL, CDVD_ST_CMD_STAT, &dummyMode);
682 return sceCdStream(0, 0, NULL, CDVD_ST_CMD_PAUSE, &dummyMode);
686#ifdef F_sceCdStResume
690 return sceCdStream(0, 0, NULL, CDVD_ST_CMD_RESUME, &dummyMode);
698 if (_CdCheckNCmd(15) == 0)
702 printf(
"call sceCdreadstm call\n");
704 readStreamData[0] = lbn;
705 readStreamData[1] = nsectors;
706 readStreamData[2] = (u32)buf;
707 readStreamData[3] = cmd;
712 printf(
"call sceCdreadstm cmd\n");
714 if (SifCallRpc(&clientNCmd, CD_NCMD_STREAM, 0, readStreamData, 20, nCmdRecvBuff, 4, NULL, NULL) < 0) {
715 SignalSema(nCmdSemaId);
720 printf(
"sceCdread end\n");
721 SignalSema(nCmdSemaId);
722 return *(
int *)UNCACHED_SEG(nCmdRecvBuff);
726#ifdef F_sceCdCddaStream
729 unsigned int sector_size;
731 if (_CdCheckNCmd(17) == 0)
732 return cmd < CDVD_ST_CMD_INIT ? -1 : 0;
739 readStreamData[0] = lbn;
740 readStreamData[1] = nsectors * sector_size;
741 readStreamData[2] = (u32)buf;
742 readStreamData[3] = cmd;
745 if (cmd == CDVD_ST_CMD_INIT)
746 readStreamData[2] = (u32)cdda_st_buf;
750 if (SifCallRpc(&clientNCmd, CD_NCMD_CDDASTREAM, 0, readStreamData, 20, nCmdRecvBuff, 4, NULL, NULL) < 0) {
751 SignalSema(nCmdSemaId);
752 return cmd < CDVD_ST_CMD_INIT ? -1 : 0;
755 SignalSema(nCmdSemaId);
756 return *(
int *)UNCACHED_SEG(nCmdRecvBuff);
766 printf(
"N cmd wait\n");
769 while (cbSema || SifCheckStatRpc(&clientNCmd))
774 if (cbSema || SifCheckStatRpc(&clientNCmd))
787int _CdCheckNCmd(
int cmd)
790 if (PollSema(nCmdSemaId) != nCmdSemaId) {
792 printf(
"Ncmd fail sema cmd:%d keep_cmd:%d\n", cmd, nCmdNum);
797 ReferThreadStatus(CdThreadId, &CdThreadParam);
799 SignalSema(nCmdSemaId);
811 printf(
"Libcdvd bind err N CMD\n");
813 if (clientNCmd.server != 0)
825int sceCdReadKey(
unsigned char arg1,
unsigned char arg2,
unsigned int command,
unsigned char *key)
829 if (_CdCheckNCmd(CD_NCMD_READ_KEY) == 0)
832 nCmdSendBuff.readKey.arg1 = arg1;
833 nCmdSendBuff.readKey.arg2 = arg2;
834 nCmdSendBuff.readKey.command = command;
836 if (SifCallRpc(&clientNCmd, CD_NCMD_READ_KEY, 0, &nCmdSendBuff, 0xC, nCmdRecvBuff, 0x18, NULL, NULL) >= 0) {
837 memcpy(key, UNCACHED_SEG(&nCmdRecvBuff[4]), 16);
840 SignalSema(nCmdSemaId);
int sceCdStRead(u32 sectors, u32 *buffer, u32 mode, u32 *error)
int sceCdReadKey(unsigned char arg1, unsigned char arg2, unsigned int command, unsigned char *key)
int sceCdStInit(u32 bufmax, u32 bankmax, void *buffer)
u32 sceCdGetReadPos(void)
int sceCdStStart(u32 lbn, sceCdRMode *mode)
int sceCdRead(u32 lbn, u32 sectors, void *buffer, sceCdRMode *mode)
int sceCdApplyNCmd(u8 cmdNum, const void *inBuff, u16 inBuffSize)
int sceCdReadChain(sceCdRChain *tag, sceCdRMode *mode)
int sceCdReadIOPMem(u32 lbn, u32 sectors, void *buf, sceCdRMode *mode)
int sceCdNCmdDiskReady(void)