From 91da5c3b33e7d98ea95b34093c7215e4b5147009 Mon Sep 17 00:00:00 2001 From: Julian Uy Date: Thu, 14 May 2026 00:11:31 -0500 Subject: [PATCH] cleanup: merge cdvd and xcdvd libraries --- ee/rpc/Makefile | 1 - ee/rpc/cdvd/Makefile | 8 ++++- ee/rpc/cdvd/src/libcdvd.c | 22 +++++++++++- ee/rpc/cdvd/src/ncmd.c | 72 +++++++++++++++++++++++++++++++++------ ee/rpc/cdvd/src/scmd.c | 7 ++-- ee/rpc/xcdvd/Makefile | 20 ----------- 6 files changed, 91 insertions(+), 39 deletions(-) delete mode 100755 ee/rpc/xcdvd/Makefile diff --git a/ee/rpc/Makefile b/ee/rpc/Makefile index 031a8fbe8b3c..50e37d284364 100644 --- a/ee/rpc/Makefile +++ b/ee/rpc/Makefile @@ -23,7 +23,6 @@ SUBDIRS += remote SUBDIRS += secr SUBDIRS += sior SUBDIRS += tcpips -SUBDIRS += xcdvd include $(PS2SDKSRC)/Defs.make include $(PS2SDKSRC)/Rules.make diff --git a/ee/rpc/cdvd/Makefile b/ee/rpc/cdvd/Makefile index 476a6e9bd821..a5c76496451b 100755 --- a/ee/rpc/cdvd/Makefile +++ b/ee/rpc/cdvd/Makefile @@ -15,7 +15,8 @@ NCMD_OBJS += _ncmd_internals.o _CdAlignReadBuffer.o sceCdRead.o sceCdReadDVDV.o sceCdApplyNCmd.o sceCdReadIOPMem.o sceCdNCmdDiskReady.o \ sceCdGetReadPos.o sceCdStStart.o sceCdStRead.o sceCdStStop.o sceCdStSeek.o sceCdStInit.o \ sceCdStStat.o sceCdStPause.o sceCdStResume.o sceCdStream.o sceCdCddaStream.o sceCdSync.o \ - _CdCheckNCmd.o sceCdReadKey.o + _CdCheckNCmd.o sceCdReadKey.o \ + sceCdReadChain.o SCMD_OBJS += _scmd_internals.o sceCdReadClock.o ps2time.o sceCdWriteClock.o sceCdGetDiskType.o \ sceCdGetError.o sceCdTrayReq.o sceCdApplySCmd.o sceCdStatus.o sceCdBreak.o \ @@ -24,8 +25,13 @@ SCMD_OBJS += _scmd_internals.o sceCdReadClock.o ps2time.o sceCdWriteClock.o sceC sceCdReadConfig.o sceCdWriteConfig.o \ sceCdReadNVM.o sceCdWriteNVM.o sceCdRI.o sceCdWI.o sceCdReadConsoleID.o sceCdWriteConsoleID.o \ sceCdNoticeGameStart.o \ + sceCdCancelPOffRdy.o sceCdBlueLedCtrl.o sceCdPowerOff.o sceCdMmode.o \ + sceCdForbidRead.o sceCdSpinCtrlEE.o sceCdBootCertify.o sceCdRM.o sceCdWM.o \ + sceCdChangeThreadPriority.o \ _CdSyncS.o +EE_LIB_ALTNAMES ?= libxcdvd.a + EE_OBJS = $(LIBCDVD_OBJS) $(NCMD_OBJS) $(SCMD_OBJS) erl-support.o include $(PS2SDKSRC)/Defs.make diff --git a/ee/rpc/cdvd/src/libcdvd.c b/ee/rpc/cdvd/src/libcdvd.c index e42752306f22..2affbbda4312 100644 --- a/ee/rpc/cdvd/src/libcdvd.c +++ b/ee/rpc/cdvd/src/libcdvd.c @@ -43,6 +43,16 @@ extern void *_gp; // prototypes void _CdSemaExit(void); +typedef struct +{ + int m_init_result; + /* The rest of the values in this struct are only set in SDK >= 2.0.0. */ + /* Otherwise they are zero. */ + int m_cdvdfsv_version; + int m_cdvdman_version; + int m_cdvdfsv_isverbose; +} CdInitPkt; + /** searchfile structure */ typedef struct { @@ -56,6 +66,9 @@ typedef struct int bindInit = -1; int bindDiskReady = -1; int bindSearchFile = -1; +// version variables +int initVersionCdvdfsv; +int initVersionCdvdman; // rpc binded client data /** for sceCdInit() */ SifRpcClientData_t clientInit __attribute__((aligned(64))); @@ -89,6 +102,8 @@ s32 diskReadyMode __attribute__((aligned(64))); s32 trayReqData __attribute__((aligned(64))); u32 initMode __attribute__((aligned(64))); +// init stuff +CdInitPkt cdInitRecvBuff __attribute__((aligned(64))); // searchfile stuff SearchFilePkt searchFileSendBuff __attribute__((aligned(64))); u32 searchFileRecvBuff __attribute__((aligned(64))); @@ -98,6 +113,8 @@ u32 searchFileRecvBuff __attribute__((aligned(64))); extern int bindInit; extern int bindDiskReady; extern int bindSearchFile; +extern int initVersionCdvdfsv; +extern int initVersionCdvdman; extern SifRpcClientData_t clientInit; extern SifRpcClientData_t clientDiskReady; extern SifRpcClientData_t clientSearchFile; @@ -113,6 +130,7 @@ extern ee_thread_t callbackThreadParam; extern s32 diskReadyMode; extern s32 trayReqData; extern u32 initMode; +extern CdInitPkt cdInitRecvBuff; extern SearchFilePkt searchFileSendBuff; extern u32 searchFileRecvBuff; @@ -143,8 +161,10 @@ s32 sceCdInit(s32 mode) bindInit = 0; initMode = mode; - if (sceSifCallRpc(&clientInit, 0, 0, &initMode, 4, 0, 0, 0, 0) < 0) + if (sceSifCallRpc(&clientInit, 0, 0, &initMode, sizeof(initMode), &cdInitRecvBuff, sizeof(cdInitRecvBuff), 0, 0) < 0) return 0; + initVersionCdvdfsv = cdInitRecvBuff.m_cdvdfsv_version; + initVersionCdvdman = cdInitRecvBuff.m_cdvdman_version; if (mode == SCECdEXIT) { if (CdDebug > 0) printf("Libcdvd Exit\n"); diff --git a/ee/rpc/cdvd/src/ncmd.c b/ee/rpc/cdvd/src/ncmd.c index 213efaf0384d..d67201569e2e 100644 --- a/ee/rpc/cdvd/src/ncmd.c +++ b/ee/rpc/cdvd/src/ncmd.c @@ -103,6 +103,7 @@ u32 seekSector __attribute__((aligned(64))); u32 cdda_st_buf[64 / sizeof(u32)] ALIGNED(64); #endif +extern int initVersionCdvdfsv; extern int bindNcmd; extern SifRpcClientData_t clientNCmd; extern int nCmdSemaId; @@ -125,8 +126,7 @@ int sceCdNCmdDiskReady(void); /* N-Command Functions */ -#ifdef _XCDVD -struct _cdvd_read_data +struct _cdvd_read_data_1400 { u32 size1; u32 size2; @@ -135,8 +135,7 @@ struct _cdvd_read_data u8 src1[64]; u8 src2[64]; }; -#else -struct _cdvd_read_data +struct _cdvd_read_data_1300 { u32 size1; u32 size2; @@ -145,27 +144,42 @@ struct _cdvd_read_data u8 src1[16]; u8 src2[16]; }; -#endif -void _CdAlignReadBuffer(void *data); +extern void _CdAlignReadBuffer(void *data); /** this gets called when the sceCdRead function finishes * to copy the data read in to unaligned buffers */ #ifdef F__CdAlignReadBuffer void _CdAlignReadBuffer(void *data) { - struct _cdvd_read_data *uncached = UNCACHED_SEG(data); + if (initVersionCdvdfsv > 0x104) + { + struct _cdvd_read_data_1400 *uncached = UNCACHED_SEG(data); + + if (uncached->size1 && uncached->dest1) { + memcpy(uncached->dest1, &uncached->src1, uncached->size1); + } - if (uncached->size1 && uncached->dest1) { - memcpy(uncached->dest1, &uncached->src1, uncached->size1); + if (uncached->size2 && uncached->dest2) { + memcpy(uncached->dest2, &uncached->src2, uncached->size2); + } } + else + { + struct _cdvd_read_data_1300 *uncached = UNCACHED_SEG(data); - if (uncached->size2 && uncached->dest2) { - memcpy(uncached->dest2, &uncached->src2, uncached->size2); + if (uncached->size1 && uncached->dest1) { + memcpy(uncached->dest1, &uncached->src1, uncached->size1); + } + + if (uncached->size2 && uncached->dest2) { + memcpy(uncached->dest2, &uncached->src2, uncached->size2); + } } _CdGenericCallbackFunction((void *)&CdCallbackNum); } + #endif #ifdef F_sceCdRead @@ -815,6 +829,42 @@ int _CdCheckNCmd(int cmd) nopdelay(); } + if (!initVersionCdvdfsv) + { + struct _cdvd_read_data_1400 tmpbuf; + int i; + int eq_count; + struct _cdvd_read_data_1400 *uncached; + + uncached = UNCACHED_SEG(_rd_intr_data); + // Attempt to determine the size of the CDVD read unaligned buffer + readData[0] = 0; + readData[1] = 0; + readData[2] = (u32)NULL; + readData[3] = 0; + readData[4] = (u32)_rd_intr_data; + + if (sceSifCallRpc(&clientNCmd, CD_NCMD_CDDAREAD, 0, readData, sizeof(readData), NULL, 0, 0, 0) < 0) + return 0; + + // Nothing is read, so ensure that is the case + if (uncached->size1 || uncached->dest1 || uncached->size2 || uncached->dest2) + return 0; + tmpbuf = *uncached; + for (i = 0; i < sizeof(*uncached); i += 1) + ((u8 *)uncached)[i] ^= 0xFF; + + if (sceSifCallRpc(&clientNCmd, CD_NCMD_CDDAREAD, 0, readData, sizeof(readData), NULL, 0, 0, 0) < 0) + return 0; + // Nothing is read, so ensure that is the case + if (uncached->size1 || uncached->dest1 || uncached->size2 || uncached->dest2) + return 0; + + eq_count = 0; + for (i = 0; i < sizeof(*uncached); i += 1) + eq_count += (((u8 *)uncached)[i] == ((u8 *)&tmpbuf)[i]) ? 1 : 0; + initVersionCdvdfsv = (eq_count > sizeof(struct _cdvd_read_data_1300)) ? 0x200 : 0x104; + } bindNCmd = 0; return 1; diff --git a/ee/rpc/cdvd/src/scmd.c b/ee/rpc/cdvd/src/scmd.c index fa0487a96448..e85280d03a37 100644 --- a/ee/rpc/cdvd/src/scmd.c +++ b/ee/rpc/cdvd/src/scmd.c @@ -101,6 +101,7 @@ int sCmdNum = 0; int CdConfigRdWrNumBlocks; #endif +extern int initVersionCdvdman; extern int bindSCmd; extern SifRpcClientData_t clientSCmd; extern int sCmdSemaId; @@ -875,11 +876,7 @@ int sceCdMV(unsigned char *buffer, u32 *result) if (sceSifCallRpc(&clientSCmd, CD_SCMD_READ_MECHACON_VERSION, 0, NULL, 0, sCmdRecvBuff, 16, NULL, NULL) >= 0) { -#ifdef _XCDVD - memcpy(buffer, UNCACHED_SEG(&sCmdRecvBuff[8]), 4); -#else - memcpy(buffer, UNCACHED_SEG(&sCmdRecvBuff[8]), 3); -#endif + memcpy(buffer, UNCACHED_SEG(&sCmdRecvBuff[8]), (initVersionCdvdman >= 0x200) ? 4 : 3); *result = *(u32 *)UNCACHED_SEG(&sCmdRecvBuff[4]); status = *(int *)UNCACHED_SEG(sCmdRecvBuff); } else { diff --git a/ee/rpc/xcdvd/Makefile b/ee/rpc/xcdvd/Makefile deleted file mode 100755 index 7a19dc4576c2..000000000000 --- a/ee/rpc/xcdvd/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# _____ ___ ____ ___ ____ -# ____| | ____| | | |____| -# | ___| |____ ___| ____| | \ PS2DEV Open Source Project. -#----------------------------------------------------------------------- -# Copyright 2001-2004, ps2dev - http://www.ps2dev.org -# Licenced under Academic Free License version 2.0 -# Review ps2sdk README & LICENSE files for further details. - -EE_SRC_DIR = $(PS2SDKSRC)/ee/rpc/cdvd/src/ -EE_INC_DIR = $(PS2SDKSRC)/ee/rpc/cdvd/include/ - -EE_CFLAGS += -D_XCDVD - -NCMD_OBJS += sceCdReadChain.o - -SCMD_OBJS += sceCdCancelPOffRdy.o sceCdBlueLedCtrl.o sceCdPowerOff.o sceCdMmode.o \ - sceCdForbidRead.o sceCdSpinCtrlEE.o sceCdBootCertify.o sceCdRM.o sceCdWM.o \ - sceCdChangeThreadPriority.o - -include $(PS2SDKSRC)/ee/rpc/cdvd/Makefile