diff --git a/common/include/PS2Edefs.h b/common/include/PS2Edefs.h index 70cc460169..aa42ef0c32 100644 --- a/common/include/PS2Edefs.h +++ b/common/include/PS2Edefs.h @@ -617,8 +617,22 @@ typedef s32 (CALLBACK* _CDVDinit)(); typedef s32 (CALLBACK* _CDVDopen)(const char* pTitleFilename); typedef void (CALLBACK* _CDVDclose)(); typedef void (CALLBACK* _CDVDshutdown)(); + +// Initiates an asynchronous track read operation. +// Returns -1 on error (invalid track) +// Returns 0 on success. typedef s32 (CALLBACK* _CDVDreadTrack)(u32 lsn, int mode); + +// *OBSOLETE* returns a pointer to the buffer, or NULL if data hasn't finished +// loading yet. typedef u8* (CALLBACK* _CDVDgetBuffer)(); + +// Copies loaded data to the target buffer. +// Returns -2 if the asynchronous read is still pending. +// Returns 0 on success. +// This function is not allowed to return -1 (reserved for use by readTrack) +typedef s32 (CALLBACK* _CDVDgetBuffer2)(u8* buffer); + typedef s32 (CALLBACK* _CDVDreadSubQ)(u32 lsn, cdvdSubQ* subq); typedef s32 (CALLBACK* _CDVDgetTN)(cdvdTN *Buffer); typedef s32 (CALLBACK* _CDVDgetTD)(u8 Track, cdvdTD *Buffer); @@ -628,7 +642,6 @@ typedef s32 (CALLBACK* _CDVDgetTrayStatus)(); typedef s32 (CALLBACK* _CDVDctrlTrayOpen)(); typedef s32 (CALLBACK* _CDVDctrlTrayClose)(); typedef s32 (CALLBACK* _CDVDreadSector)(u8* buffer, u32 lsn, int mode); -typedef s32 (CALLBACK* _CDVDgetBuffer2)(u8* buffer); typedef s32 (CALLBACK* _CDVDgetDualInfo)(s32* dualType, u32* _layer1start); typedef void (CALLBACK* _CDVDconfigure)(); diff --git a/pcsx2/CDVD/CDVD.cpp b/pcsx2/CDVD/CDVD.cpp index 419f0a84ce..dff2701f3e 100644 --- a/pcsx2/CDVD/CDVD.cpp +++ b/pcsx2/CDVD/CDVD.cpp @@ -714,11 +714,9 @@ __forceinline void cdvdReadInterrupt() } else { - if (cdvd.RErr == 0) - { - cdr.RErr = DoCDVDgetBuffer(cdr.Transfer); - } - else if (cdr.RErr == -1) + // Read Error -1 is only returned by readTrack, so handle it first here. + // If readTrack failed it means we don't have any valid data to fetch. + if (cdvd.RErr == -1) { cdvd.RetryCntP++; Console::Error("CDVD READ ERROR, sector=%d", params cdvd.Sector); @@ -730,10 +728,13 @@ __forceinline void cdvdReadInterrupt() return; } } - else if(cdr.RErr == -2) + + cdvd.RErr = DoCDVDgetBuffer(cdr.Transfer); + + if(cdvd.RErr == -2) { // not finished yet ... give it a bit more time - CDVDREAD_INT(cdvd.ReadTime); + CDVDREAD_INT(cdvd.ReadTime/4); return; } cdvd.Reading = false; @@ -764,7 +765,7 @@ __forceinline void cdvdReadInterrupt() cdvd.RetryCntP = 0; cdvd.Reading = 1; - cdr.RErr = DoCDVDreadTrack(cdvd.Sector, cdvd.ReadMode); + cdvd.RErr = DoCDVDreadTrack(cdvd.Sector, cdvd.ReadMode); CDVDREAD_INT(cdvd.ReadTime); return; diff --git a/pcsx2/CDVD/CdRom.cpp b/pcsx2/CDVD/CdRom.cpp index d5c742b3ae..7cecf04277 100644 --- a/pcsx2/CDVD/CdRom.cpp +++ b/pcsx2/CDVD/CdRom.cpp @@ -497,19 +497,22 @@ void cdrReadInterrupt() { cdr.StatP|= 0x22; cdr.Result[0] = cdr.StatP; - Console::Status("Reading From CDR"); - cdr.RErr = DoCDVDgetBuffer(cdr.Transfer); + // Read Error -1 is only returned by readTrack, so handle it first here. + // If readTrack failed it means we don't have any valid data to fetch. if (cdr.RErr == -1) { CDR_LOG(" err\n"); - memzero_ptr<2340>(cdr.Transfer); + memzero_obj(cdr.Transfer); cdr.Stat = DiskError; cdr.Result[0]|= 0x01; ReadTrack(); CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime); return; } - else if(cdr.RErr == -2) + + cdr.RErr = DoCDVDgetBuffer(cdr.Transfer); + + if(cdr.RErr == -2) { // async mode is not finished yet ... give it a bit more time CDREAD_INT(cdReadTime / 4); diff --git a/pcsx2/CDVD/IsoFileFormats.cpp b/pcsx2/CDVD/IsoFileFormats.cpp index abfb9277e1..fb0f8a4d67 100644 --- a/pcsx2/CDVD/IsoFileFormats.cpp +++ b/pcsx2/CDVD/IsoFileFormats.cpp @@ -362,8 +362,13 @@ int isoReadBlock(isoFile *iso, u8 *dst, int lsn) if (iso->type == ISOTYPE_CD) { - LSNtoMSF(dst + 12, lsn); - dst[15] = 2; + // This is weird voodoo mess that does some kind of time adjustment on the + // block headers of CD-Rom images. hackfixed it to work with 24 byte block + // offsets... no idea if it'll work with others. + DevAssert( iso->blockofs == 24, "Undocumented CD-Rom checkpoint." ); + + LSNtoMSF(dst - iso->blockofs + 12, lsn); + dst[15-iso->blockofs] = 2; } return 0; diff --git a/pcsx2/CDVD/IsoFileFormats.h b/pcsx2/CDVD/IsoFileFormats.h index f7e6f95af2..0645e7d36f 100644 --- a/pcsx2/CDVD/IsoFileFormats.h +++ b/pcsx2/CDVD/IsoFileFormats.h @@ -33,10 +33,10 @@ enum isoType enum isoFlags { - ISOFLAGS_Z = 0x0001, + ISOFLAGS_Z = 0x0001, ISOFLAGS_Z2 = 0x0002, ISOFLAGS_BLOCKDUMP = 0x0004, - ISOFLAGS_MULTI = 0x0008, + ISOFLAGS_MULTI = 0x0008, ISOFLAGS_BZ2 = 0x0010 }; @@ -46,17 +46,17 @@ enum isoFlags //#define itob(i) ((i)/10*16 + (i)%10) /* u_char to BCD */ //#define btoi(b) ((b)/16*10 + (b)%16) /* BCD to u_char */ -typedef struct +struct _multih { u32 slsn; u32 elsn; void *handle; -} _multih; +}; -typedef struct +struct isoFile { char filename[256]; - u32 type; + isoType type; u32 flags; u32 offset; u32 blockofs; @@ -70,7 +70,7 @@ typedef struct _multih multih[8]; int buflsn; u8 *buffer; -} isoFile; +}; isoFile *isoOpen(const char *filename); diff --git a/pcsx2/Plugins.cpp b/pcsx2/Plugins.cpp index 534a3e8f28..a523321f07 100644 --- a/pcsx2/Plugins.cpp +++ b/pcsx2/Plugins.cpp @@ -488,18 +488,12 @@ static void CALLBACK CDVD_newDiskCB(void (*callback)()) {} extern int lastReadSize; static s32 CALLBACK CDVD_getBuffer2(u8* buffer) { - int ret; - // TEMP: until I fix all the plugins to use this function style u8* pb = CDVD->getBuffer(); - if(pb != NULL) - { - memcpy(buffer,pb,lastReadSize); - ret = 0; - } - else ret = -2; + if(pb == NULL) return -2; - return ret; + memcpy_fast( buffer, pb, lastReadSize ); + return 0; } static s32 CALLBACK CDVD_readSector(u8* buffer, u32 lsn, int mode)