From 2967d5d3f1f08b228214fc9f72ae5f50e34d5be3 Mon Sep 17 00:00:00 2001 From: Clang Format Date: Mon, 19 Sep 2016 18:24:54 +0100 Subject: [PATCH] cdvdgigaherz: Reformat with clang-format --- plugins/cdvdGigaherz/src/CDVD.cpp | 656 +++++++++-------- plugins/cdvdGigaherz/src/CDVD.h | 118 +-- plugins/cdvdGigaherz/src/ReadThread.cpp | 571 +++++++-------- plugins/cdvdGigaherz/src/TocStuff.cpp | 194 +++-- plugins/cdvdGigaherz/src/Windows/IOCtlSrc.cpp | 688 +++++++++--------- plugins/cdvdGigaherz/src/Windows/config.cpp | 238 +++--- 6 files changed, 1197 insertions(+), 1268 deletions(-) diff --git a/plugins/cdvdGigaherz/src/CDVD.cpp b/plugins/cdvdGigaherz/src/CDVD.cpp index 13e4ba206f..997318a46d 100644 --- a/plugins/cdvdGigaherz/src/CDVD.cpp +++ b/plugins/cdvdGigaherz/src/CDVD.cpp @@ -21,7 +21,7 @@ void (*newDiscCB)(); HANDLE hThread_keepAlive = nullptr; HANDLE hNotify_keepAlive = nullptr; -DWORD pidThreadKeepAlive = 0; +DWORD pidThreadKeepAlive = 0; #define STRFY(x) #x #define TOSTR(x) STRFY(x) @@ -44,15 +44,15 @@ int cmode; /////////////////////////////////////////////////////////////////////////////// // Plugin Interface // -char *LibName = "cdvdGigaherz " +char *LibName = "cdvdGigaherz " #ifdef PCSX2_DEBUG - " Debug " + " Debug " #endif - "(" TOSTR(SVN_REV) + "(" TOSTR(SVN_REV) #if SVN_MODS - "/modded" + "/modded" #endif - ")"; + ")"; const unsigned char version = PS2E_CDVD_VERSION; const unsigned char revision = 0; @@ -61,62 +61,67 @@ const unsigned char build = 10; HINSTANCE hinst; BOOL WINAPI DllMain( - HINSTANCE hinstDLL, // handle to DLL module - DWORD fdwReason, // reason for calling function - LPVOID lpvReserved // reserved -) + HINSTANCE hinstDLL, // handle to DLL module + DWORD fdwReason, // reason for calling function + LPVOID lpvReserved // reserved + ) { - if(fdwReason==DLL_PROCESS_ATTACH) { - hinst=hinstDLL; - } - return TRUE; + if (fdwReason == DLL_PROCESS_ATTACH) { + hinst = hinstDLL; + } + return TRUE; } -char* CALLBACK PS2EgetLibName() { - return LibName; +char *CALLBACK PS2EgetLibName() +{ + return LibName; } -u32 CALLBACK PS2EgetLibType() { - return PS2E_LT_CDVD; +u32 CALLBACK PS2EgetLibType() +{ + return PS2E_LT_CDVD; } -u32 CALLBACK PS2EgetLibVersion2(u32 type) { - return (version << 16) | (revision << 8) | build; +u32 CALLBACK PS2EgetLibVersion2(u32 type) +{ + return (version << 16) | (revision << 8) | build; } /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// // Utility Functions // -void SysMessage(char *fmt, ...) { - va_list list; - char tmp[512]; +void SysMessage(char *fmt, ...) +{ + va_list list; + char tmp[512]; - va_start(list,fmt); - vsprintf(tmp,fmt,list); - va_end(list); - MessageBox(0, tmp, "cdvdGigaherz Msg", 0); + va_start(list, fmt); + vsprintf(tmp, fmt, list); + va_end(list); + MessageBox(0, tmp, "cdvdGigaherz Msg", 0); } u8 __inline dec_to_bcd(u8 dec) { - return ((dec/10)<<4)|(dec%10); + return ((dec / 10) << 4) | (dec % 10); } -void __inline lsn_to_msf(u8* minute, u8* second, u8* frame, u32 lsn) +void __inline lsn_to_msf(u8 *minute, u8 *second, u8 *frame, u32 lsn) { - *frame = dec_to_bcd(lsn%75); - lsn/=75; - *second= dec_to_bcd(lsn%60); - lsn/=60; - *minute= dec_to_bcd(lsn%100); + *frame = dec_to_bcd(lsn % 75); + lsn /= 75; + *second = dec_to_bcd(lsn % 60); + lsn /= 60; + *minute = dec_to_bcd(lsn % 100); } -void __inline lba_to_msf(s32 lba, u8* m, u8* s, u8* f) { - lba += 150; - *m = (u8)(lba / (60*75)); - *s = (u8)((lba / 75) % 60); - *f = (u8)(lba % 75); +void __inline lba_to_msf(s32 lba, u8 *m, u8 *s, u8 *f) +{ + lba += 150; + *m = (u8)(lba / (60 * 75)); + *s = (u8)((lba / 75) % 60); + *f = (u8)(lba % 75); } /////////////////////////////////////////////////////////////////////////////// @@ -142,446 +147,437 @@ extern s32 prefetch_last_mode; DWORD CALLBACK keepAliveThread(PVOID param) { - printf(" * CDVD: KeepAlive thread started...\n"); + printf(" * CDVD: KeepAlive thread started...\n"); - while (cdvdKeepAlive_is_open) - { - // Sleep 30 seconds with thread abort check - if (WaitForSingleObject(hNotify_keepAlive, 30000) != WAIT_TIMEOUT) break; + while (cdvdKeepAlive_is_open) { + // Sleep 30 seconds with thread abort check + if (WaitForSingleObject(hNotify_keepAlive, 30000) != WAIT_TIMEOUT) + break; if (!cdvdKeepAlive_is_open) { break; } - //printf(" * keepAliveThread: polling drive.\n"); - //if (prefetch_last_mode == CDVD_MODE_2048) - src->ReadSectors2048(prefetch_last_lba, 1, throwaway); - //else - // src->ReadSectors2352(prefetch_last_lba, 1, throwaway); - } + //printf(" * keepAliveThread: polling drive.\n"); + //if (prefetch_last_mode == CDVD_MODE_2048) + src->ReadSectors2048(prefetch_last_lba, 1, throwaway); + //else + // src->ReadSectors2352(prefetch_last_lba, 1, throwaway); + } - printf(" * CDVD: KeepAlive thread finished.\n"); - - return 0; + printf(" * CDVD: KeepAlive thread finished.\n"); + + return 0; } s32 StartKeepAliveThread() { - hNotify_keepAlive = CreateEvent(NULL, FALSE, FALSE, NULL); - if (hNotify_keepAlive == nullptr) - return -1; + hNotify_keepAlive = CreateEvent(NULL, FALSE, FALSE, NULL); + if (hNotify_keepAlive == nullptr) + return -1; - cdvdKeepAlive_is_open = true; - hThread_keepAlive = CreateThread(NULL, 0, keepAliveThread, NULL, 0, &pidThreadKeepAlive); - if (hThread_keepAlive == nullptr) { - cdvdKeepAlive_is_open = false; - return -1; - } + cdvdKeepAlive_is_open = true; + hThread_keepAlive = CreateThread(NULL, 0, keepAliveThread, NULL, 0, &pidThreadKeepAlive); + if (hThread_keepAlive == nullptr) { + cdvdKeepAlive_is_open = false; + return -1; + } - SetThreadPriority(hThread_keepAlive, THREAD_PRIORITY_NORMAL); + SetThreadPriority(hThread_keepAlive, THREAD_PRIORITY_NORMAL); - return 0; + return 0; } void StopKeepAliveThread() { - cdvdKeepAlive_is_open = false; - PulseEvent(hNotify_keepAlive); - if (WaitForSingleObject(hThread_keepAlive, 5000) == WAIT_TIMEOUT) - { - TerminateThread(hThread_keepAlive, 0); - } - CloseHandle(hThread_keepAlive); - CloseHandle(hNotify_keepAlive); + cdvdKeepAlive_is_open = false; + PulseEvent(hNotify_keepAlive); + if (WaitForSingleObject(hThread_keepAlive, 5000) == WAIT_TIMEOUT) { + TerminateThread(hThread_keepAlive, 0); + } + CloseHandle(hThread_keepAlive); + CloseHandle(hNotify_keepAlive); } /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// // CDVD Pluin Interface // -void CALLBACK CDVDsetSettingsDir(const char* dir) +void CALLBACK CDVDsetSettingsDir(const char *dir) { - CfgSetSettingsDir(dir); + CfgSetSettingsDir(dir); } s32 CALLBACK CDVDinit() { - return 0; + return 0; } -s32 CALLBACK CDVDopen(const char* pTitleFilename) +s32 CALLBACK CDVDopen(const char *pTitleFilename) { - ReadSettings(); + ReadSettings(); - if(source_drive=='-') - { - // MSDN : Trailing backslash is required to ensure consistent behavior across - // various versions of Windows and storage types. - char temp[]="A:\\"; + if (source_drive == '-') { + // MSDN : Trailing backslash is required to ensure consistent behavior across + // various versions of Windows and storage types. + char temp[] = "A:\\"; - for(char d='A';d<='Z';d++) - { - temp[0]=d; - if(GetDriveType(temp)==DRIVE_CDROM) - { - source_drive=d; - break; - } - } - } + for (char d = 'A'; d <= 'Z'; d++) { + temp[0] = d; + if (GetDriveType(temp) == DRIVE_CDROM) { + source_drive = d; + break; + } + } + } - if(source_drive=='@') - { - curDiskType=CDVD_TYPE_NODISC; - return 0; - } + if (source_drive == '@') { + curDiskType = CDVD_TYPE_NODISC; + return 0; + } - sprintf(csrc, "\\\\.\\%c:", source_drive); + sprintf(csrc, "\\\\.\\%c:", source_drive); - printf(" * CDVD: Opening drive '%s'...\n", csrc); + printf(" * CDVD: Opening drive '%s'...\n", csrc); - // open device file - src = new IOCtlSrc(csrc); + // open device file + src = new IOCtlSrc(csrc); - if(!src->IsOK()) - { - printf(" * CDVD: Error opening source.\n"); - return -1; - } + if (!src->IsOK()) { + printf(" * CDVD: Error opening source.\n"); + return -1; + } - //setup threading manager - cdvdStartThread(); - StartKeepAliveThread(); + //setup threading manager + cdvdStartThread(); + StartKeepAliveThread(); - return cdvdRefreshData(); + return cdvdRefreshData(); } void CALLBACK CDVDclose() { - StopKeepAliveThread(); - cdvdStopThread(); - //close device - delete src; - src=NULL; + StopKeepAliveThread(); + cdvdStopThread(); + //close device + delete src; + src = NULL; } void CALLBACK CDVDshutdown() { - //nothing to do here + //nothing to do here } -s32 CALLBACK CDVDgetDualInfo(s32* dualType, u32* _layer1start) +s32 CALLBACK CDVDgetDualInfo(s32 *dualType, u32 *_layer1start) { - switch(src->GetMediaType()) - { - case 1: - *dualType = 1; - *_layer1start = src->GetLayerBreakAddress() + 1; - return 0; - case 2: - *dualType = 2; - *_layer1start = src->GetLayerBreakAddress() + 1; - return 0; - case 0: - *dualType = 0; - *_layer1start = 0; - return 0; - } - return -1; + switch (src->GetMediaType()) { + case 1: + *dualType = 1; + *_layer1start = src->GetLayerBreakAddress() + 1; + return 0; + case 2: + *dualType = 2; + *_layer1start = src->GetLayerBreakAddress() + 1; + return 0; + case 0: + *dualType = 0; + *_layer1start = 0; + return 0; + } + return -1; } -int lastReadInNewDiskCB=0; +int lastReadInNewDiskCB = 0; char directReadSectorBuffer[2448]; -s32 CALLBACK CDVDreadSector(u8* buffer, s32 lsn, int mode) +s32 CALLBACK CDVDreadSector(u8 *buffer, s32 lsn, int mode) { - return cdvdDirectReadSector(lsn,mode,(char*)buffer); + return cdvdDirectReadSector(lsn, mode, (char *)buffer); } s32 CALLBACK CDVDreadTrack(u32 lsn, int mode) { - csector=lsn; - cmode=mode; + csector = lsn; + cmode = mode; - if(weAreInNewDiskCB) - { - int ret = cdvdDirectReadSector(lsn,mode,directReadSectorBuffer); - if(ret==0) lastReadInNewDiskCB=1; - return ret; - } + if (weAreInNewDiskCB) { + int ret = cdvdDirectReadSector(lsn, mode, directReadSectorBuffer); + if (ret == 0) + lastReadInNewDiskCB = 1; + return ret; + } - if(lsn>tracks[0].length) // track 0 is total disc. - { - return -1; - } + if (lsn > tracks[0].length) { // track 0 is total disc. + return -1; + } - return cdvdRequestSector(lsn,mode); + return cdvdRequestSector(lsn, mode); } // return can be NULL (for async modes) -u8* CALLBACK CDVDgetBuffer() +u8 *CALLBACK CDVDgetBuffer() { - if(lastReadInNewDiskCB) - { - lastReadInNewDiskCB=0; - return (u8*)directReadSectorBuffer; - } + if (lastReadInNewDiskCB) { + lastReadInNewDiskCB = 0; + return (u8 *)directReadSectorBuffer; + } - u8 *s = (u8*)cdvdGetSector(csector,cmode); + u8 *s = (u8 *)cdvdGetSector(csector, cmode); - return s; + return s; } // return can be NULL (for async modes) -int CALLBACK CDVDgetBuffer2(u8* dest) +int CALLBACK CDVDgetBuffer2(u8 *dest) { - int csize = 2352; - switch(cmode) - { - case CDVD_MODE_2048: csize = 2048; break; - case CDVD_MODE_2328: csize = 2328; break; - case CDVD_MODE_2340: csize = 2340; break; - } + int csize = 2352; + switch (cmode) { + case CDVD_MODE_2048: + csize = 2048; + break; + case CDVD_MODE_2328: + csize = 2328; + break; + case CDVD_MODE_2340: + csize = 2340; + break; + } - if(lastReadInNewDiskCB) - { - lastReadInNewDiskCB=0; + if (lastReadInNewDiskCB) { + lastReadInNewDiskCB = 0; - memcpy(dest, directReadSectorBuffer, csize); - return 0; - } + memcpy(dest, directReadSectorBuffer, csize); + return 0; + } - memcpy(dest, cdvdGetSector(csector,cmode), csize); + memcpy(dest, cdvdGetSector(csector, cmode), csize); - return 0; + return 0; } -s32 CALLBACK CDVDreadSubQ(u32 lsn, cdvdSubQ* subq) +s32 CALLBACK CDVDreadSubQ(u32 lsn, cdvdSubQ *subq) { - int i; - // the formatted subq command returns: control/adr, track, index, trk min, trk sec, trk frm, 0x00, abs min, abs sec, abs frm + int i; + // the formatted subq command returns: control/adr, track, index, trk min, trk sec, trk frm, 0x00, abs min, abs sec, abs frm - if(lsn>tracks[0].length) // track 0 is total disc. - return -1; + if (lsn > tracks[0].length) // track 0 is total disc. + return -1; - memset(subq,0,sizeof(cdvdSubQ)); + memset(subq, 0, sizeof(cdvdSubQ)); - lsn_to_msf(&subq->discM,&subq->discS,&subq->discF,lsn+150); + lsn_to_msf(&subq->discM, &subq->discS, &subq->discF, lsn + 150); - i=strack; - while(i<=etrack) - { - if(lsn<=tracks[i].length) - break; - lsn-=tracks[i].length; - i++; - } + i = strack; + while (i <= etrack) { + if (lsn <= tracks[i].length) + break; + lsn -= tracks[i].length; + i++; + } - if(i>etrack) - i=etrack; + if (i > etrack) + i = etrack; - lsn_to_msf(&subq->trackM,&subq->trackS,&subq->trackF,lsn); + lsn_to_msf(&subq->trackM, &subq->trackS, &subq->trackF, lsn); - subq->mode=1; - subq->ctrl=tracks[i].type; - subq->trackNum=i; - subq->trackIndex=1; + subq->mode = 1; + subq->ctrl = tracks[i].type; + subq->trackNum = i; + subq->trackIndex = 1; - return 0; + return 0; } s32 CALLBACK CDVDgetTN(cdvdTN *Buffer) { - Buffer->strack=strack; - Buffer->etrack=etrack; - return 0; + Buffer->strack = strack; + Buffer->etrack = etrack; + return 0; } s32 CALLBACK CDVDgetTD(u8 Track, cdvdTD *Buffer) { - if(Track==0) - { - Buffer->lsn = tracks[0].length; - Buffer->type= 0; - return 0; - } + if (Track == 0) { + Buffer->lsn = tracks[0].length; + Buffer->type = 0; + return 0; + } - if(Tracketrack) return -1; + if (Track < strack) + return -1; + if (Track > etrack) + return -1; - Buffer->lsn = tracks[Track].start_lba; - Buffer->type= tracks[Track].type; - return 0; + Buffer->lsn = tracks[Track].start_lba; + Buffer->type = tracks[Track].type; + return 0; } -s32 CALLBACK CDVDgetTOC(u8* tocBuff) +s32 CALLBACK CDVDgetTOC(u8 *tocBuff) { - //return src->ReadTOC((char*)toc,2048); - //that didn't work too well... + //return src->ReadTOC((char*)toc,2048); + //that didn't work too well... - if (curDiskType == CDVD_TYPE_NODISC) - return -1; + if (curDiskType == CDVD_TYPE_NODISC) + return -1; - if (curDiskType == CDVD_TYPE_DETCTDVDS || curDiskType == CDVD_TYPE_DETCTDVDD) - { - memset(tocBuff, 0, 2048); + if (curDiskType == CDVD_TYPE_DETCTDVDS || curDiskType == CDVD_TYPE_DETCTDVDD) { + memset(tocBuff, 0, 2048); - s32 mt=src->GetMediaType(); + s32 mt = src->GetMediaType(); - if(mt<0) - return -1; + if (mt < 0) + return -1; - if(mt==0) //single layer - { - // fake it - tocBuff[ 0] = 0x04; - tocBuff[ 1] = 0x02; - tocBuff[ 2] = 0xF2; - tocBuff[ 3] = 0x00; - tocBuff[ 4] = 0x86; - tocBuff[ 5] = 0x72; + if (mt == 0) { //single layer + // fake it + tocBuff[0] = 0x04; + tocBuff[1] = 0x02; + tocBuff[2] = 0xF2; + tocBuff[3] = 0x00; + tocBuff[4] = 0x86; + tocBuff[5] = 0x72; - tocBuff[16] = 0x00; // first sector for layer 0 - tocBuff[17] = 0x03; - tocBuff[18] = 0x00; - tocBuff[19] = 0x00; - } - else if(mt==1) //PTP - { - u32 layer1start = src->GetLayerBreakAddress() + 0x30000; + tocBuff[16] = 0x00; // first sector for layer 0 + tocBuff[17] = 0x03; + tocBuff[18] = 0x00; + tocBuff[19] = 0x00; + } else if (mt == 1) { //PTP + u32 layer1start = src->GetLayerBreakAddress() + 0x30000; - // dual sided - tocBuff[ 0] = 0x24; - tocBuff[ 1] = 0x02; - tocBuff[ 2] = 0xF2; - tocBuff[ 3] = 0x00; - tocBuff[ 4] = 0x41; - tocBuff[ 5] = 0x95; + // dual sided + tocBuff[0] = 0x24; + tocBuff[1] = 0x02; + tocBuff[2] = 0xF2; + tocBuff[3] = 0x00; + tocBuff[4] = 0x41; + tocBuff[5] = 0x95; - tocBuff[14] = 0x61; // PTP + tocBuff[14] = 0x61; // PTP - tocBuff[16] = 0x00; - tocBuff[17] = 0x03; - tocBuff[18] = 0x00; - tocBuff[19] = 0x00; + tocBuff[16] = 0x00; + tocBuff[17] = 0x03; + tocBuff[18] = 0x00; + tocBuff[19] = 0x00; - tocBuff[20] = (layer1start>>24); - tocBuff[21] = (layer1start>>16)&0xff; - tocBuff[22] = (layer1start>> 8)&0xff; - tocBuff[23] = (layer1start>> 0)&0xff; - } - else //OTP - { - u32 layer1start = src->GetLayerBreakAddress() + 0x30000; + tocBuff[20] = (layer1start >> 24); + tocBuff[21] = (layer1start >> 16) & 0xff; + tocBuff[22] = (layer1start >> 8) & 0xff; + tocBuff[23] = (layer1start >> 0) & 0xff; + } else { //OTP + u32 layer1start = src->GetLayerBreakAddress() + 0x30000; - // dual sided - tocBuff[ 0] = 0x24; - tocBuff[ 1] = 0x02; - tocBuff[ 2] = 0xF2; - tocBuff[ 3] = 0x00; - tocBuff[ 4] = 0x41; - tocBuff[ 5] = 0x95; + // dual sided + tocBuff[0] = 0x24; + tocBuff[1] = 0x02; + tocBuff[2] = 0xF2; + tocBuff[3] = 0x00; + tocBuff[4] = 0x41; + tocBuff[5] = 0x95; - tocBuff[14] = 0x71; // OTP + tocBuff[14] = 0x71; // OTP - tocBuff[16] = 0x00; - tocBuff[17] = 0x03; - tocBuff[18] = 0x00; - tocBuff[19] = 0x00; + tocBuff[16] = 0x00; + tocBuff[17] = 0x03; + tocBuff[18] = 0x00; + tocBuff[19] = 0x00; - tocBuff[24] = (layer1start>>24); - tocBuff[25] = (layer1start>>16)&0xff; - tocBuff[26] = (layer1start>> 8)&0xff; - tocBuff[27] = (layer1start>> 0)&0xff; - } - } - else if (curDiskType == CDVD_TYPE_DETCTCD) - { - // cd toc - // (could be replaced by 1 command that reads the full toc) - u8 min, sec, frm,i; - s32 err; - cdvdTN diskInfo; - cdvdTD trackInfo; - memset(tocBuff, 0, 1024); - if (CDVDgetTN(&diskInfo) == -1) { diskInfo.etrack = 0;diskInfo.strack = 1; } - if (CDVDgetTD(0, &trackInfo) == -1) trackInfo.lsn = 0; + tocBuff[24] = (layer1start >> 24); + tocBuff[25] = (layer1start >> 16) & 0xff; + tocBuff[26] = (layer1start >> 8) & 0xff; + tocBuff[27] = (layer1start >> 0) & 0xff; + } + } else if (curDiskType == CDVD_TYPE_DETCTCD) { + // cd toc + // (could be replaced by 1 command that reads the full toc) + u8 min, sec, frm, i; + s32 err; + cdvdTN diskInfo; + cdvdTD trackInfo; + memset(tocBuff, 0, 1024); + if (CDVDgetTN(&diskInfo) == -1) { + diskInfo.etrack = 0; + diskInfo.strack = 1; + } + if (CDVDgetTD(0, &trackInfo) == -1) + trackInfo.lsn = 0; - tocBuff[0] = 0x41; - tocBuff[1] = 0x00; + tocBuff[0] = 0x41; + tocBuff[1] = 0x00; -#define itob(n) ((((n)/10)<<4)+((n)%10)) +#define itob(n) ((((n) / 10) << 4) + ((n) % 10)) - //Number of FirstTrack - tocBuff[2] = 0xA0; - tocBuff[7] = itob(diskInfo.strack); + //Number of FirstTrack + tocBuff[2] = 0xA0; + tocBuff[7] = itob(diskInfo.strack); - //Number of LastTrack - tocBuff[12] = 0xA1; - tocBuff[17] = itob(diskInfo.etrack); + //Number of LastTrack + tocBuff[12] = 0xA1; + tocBuff[17] = itob(diskInfo.etrack); - //DiskLength - lba_to_msf(trackInfo.lsn, &min, &sec, &frm); - tocBuff[22] = 0xA2; - tocBuff[27] = itob(min); - tocBuff[28] = itob(sec); - tocBuff[29] = itob(frm); + //DiskLength + lba_to_msf(trackInfo.lsn, &min, &sec, &frm); + tocBuff[22] = 0xA2; + tocBuff[27] = itob(min); + tocBuff[28] = itob(sec); + tocBuff[29] = itob(frm); - fprintf(stderr,"Track 0: %d mins %d secs %d frames\n",min,sec,frm); + fprintf(stderr, "Track 0: %d mins %d secs %d frames\n", min, sec, frm); - for (i=diskInfo.strack; i<=diskInfo.etrack; i++) - { - err = CDVDgetTD(i, &trackInfo); - lba_to_msf(trackInfo.lsn, &min, &sec, &frm); - tocBuff[i*10+30] = trackInfo.type; - tocBuff[i*10+32] = err == -1 ? 0 : itob(i); //number - tocBuff[i*10+37] = itob(min); - tocBuff[i*10+38] = itob(sec); - tocBuff[i*10+39] = itob(frm); - fprintf(stderr,"Track %d: %d mins %d secs %d frames\n",i,min,sec,frm); - } - } - else - return -1; + for (i = diskInfo.strack; i <= diskInfo.etrack; i++) { + err = CDVDgetTD(i, &trackInfo); + lba_to_msf(trackInfo.lsn, &min, &sec, &frm); + tocBuff[i * 10 + 30] = trackInfo.type; + tocBuff[i * 10 + 32] = err == -1 ? 0 : itob(i); //number + tocBuff[i * 10 + 37] = itob(min); + tocBuff[i * 10 + 38] = itob(sec); + tocBuff[i * 10 + 39] = itob(frm); + fprintf(stderr, "Track %d: %d mins %d secs %d frames\n", i, min, sec, frm); + } + } else + return -1; - return 0; + return 0; } s32 CALLBACK CDVDgetDiskType() { - return curDiskType; + return curDiskType; } s32 CALLBACK CDVDgetTrayStatus() { - return curTrayStatus; + return curTrayStatus; } s32 CALLBACK CDVDctrlTrayOpen() { - curTrayStatus=CDVD_TRAY_OPEN; - return 0; + curTrayStatus = CDVD_TRAY_OPEN; + return 0; } s32 CALLBACK CDVDctrlTrayClose() { - curTrayStatus=CDVD_TRAY_CLOSE; - return 0; + curTrayStatus = CDVD_TRAY_CLOSE; + return 0; } void CALLBACK CDVDnewDiskCB(void (*callback)()) { - newDiscCB=callback; + newDiscCB = callback; } void CALLBACK CDVDconfigure() { - configure(); + configure(); } -void CALLBACK CDVDabout() { - SysMessage("%s %d.%d", LibName, revision, build); +void CALLBACK CDVDabout() +{ + SysMessage("%s %d.%d", LibName, revision, build); } -s32 CALLBACK CDVDtest() { - return 0; +s32 CALLBACK CDVDtest() +{ + return 0; } diff --git a/plugins/cdvdGigaherz/src/CDVD.h b/plugins/cdvdGigaherz/src/CDVD.h index 5e6a8bd5d8..8829d67e4c 100644 --- a/plugins/cdvdGigaherz/src/CDVD.h +++ b/plugins/cdvdGigaherz/src/CDVD.h @@ -25,9 +25,9 @@ typedef struct _track { - u32 start_lba; - u32 length; - u32 type; + u32 start_lba; + u32 length; + u32 type; } track; extern int strack; @@ -37,10 +37,11 @@ extern track tracks[100]; extern int curDiskType; extern int curTrayStatus; -typedef struct _toc_entry { +typedef struct _toc_entry +{ UCHAR SessionNumber; - UCHAR Control : 4; - UCHAR Adr : 4; + UCHAR Control : 4; + UCHAR Adr : 4; UCHAR Reserved1; UCHAR Point; UCHAR MsfExtra[3]; @@ -59,82 +60,83 @@ typedef struct _toc_data extern toc_data cdtoc; -class Source //abstract class as base for source modules +class Source //abstract class as base for source modules { - Source(Source&); + Source(Source &); + public: - Source(){}; + Source(){}; - //virtual destructor - virtual ~Source() - { - } + //virtual destructor + virtual ~Source() + { + } - //virtual members - virtual s32 GetSectorCount()=0; - virtual s32 ReadTOC(char *toc,int size)=0; - virtual s32 ReadSectors2048(u32 sector, u32 count, char *buffer)=0; - virtual s32 ReadSectors2352(u32 sector, u32 count, char *buffer)=0; - virtual s32 GetLayerBreakAddress()=0; + //virtual members + virtual s32 GetSectorCount() = 0; + virtual s32 ReadTOC(char *toc, int size) = 0; + virtual s32 ReadSectors2048(u32 sector, u32 count, char *buffer) = 0; + virtual s32 ReadSectors2352(u32 sector, u32 count, char *buffer) = 0; + virtual s32 GetLayerBreakAddress() = 0; - virtual s32 GetMediaType()=0; + virtual s32 GetMediaType() = 0; - virtual s32 IsOK()=0; - virtual s32 Reopen()=0; + virtual s32 IsOK() = 0; + virtual s32 Reopen() = 0; - virtual s32 DiscChanged()=0; + virtual s32 DiscChanged() = 0; }; -class IOCtlSrc: public Source +class IOCtlSrc : public Source { - IOCtlSrc(IOCtlSrc&); + IOCtlSrc(IOCtlSrc &); - HANDLE device; - bool m_can_use_spti; - bool OpenOK; + HANDLE device; + bool m_can_use_spti; + bool OpenOK; - s32 last_read_mode; + s32 last_read_mode; - s32 last_sector_count; + s32 last_sector_count; - char sectorbuffer[32*2048]; + char sectorbuffer[32 * 2048]; - char fName[256]; + char fName[256]; - DWORD sessID; + DWORD sessID; - bool tocCached; - char tocCacheData[2048]; + bool tocCached; + char tocCacheData[2048]; - bool mediaTypeCached; - int mediaType; + bool mediaTypeCached; + int mediaType; - bool discSizeCached; - s32 discSize; + bool discSizeCached; + s32 discSize; - bool layerBreakCached; - s32 layerBreak; + bool layerBreakCached; + s32 layerBreak; public: - IOCtlSrc(const char* fileName); + IOCtlSrc(const char *fileName); - //virtual destructor - virtual ~IOCtlSrc(); + //virtual destructor + virtual ~IOCtlSrc(); - //virtual members - virtual s32 GetSectorCount(); - virtual s32 ReadTOC(char *toc,int size); - virtual s32 ReadSectors2048(u32 sector, u32 count, char *buffer); - virtual s32 ReadSectors2352(u32 sector, u32 count, char *buffer); - virtual s32 GetLayerBreakAddress(); + //virtual members + virtual s32 GetSectorCount(); + virtual s32 ReadTOC(char *toc, int size); + virtual s32 ReadSectors2048(u32 sector, u32 count, char *buffer); + virtual s32 ReadSectors2352(u32 sector, u32 count, char *buffer); + virtual s32 GetLayerBreakAddress(); - virtual s32 GetMediaType(); - virtual void SetSpindleSpeed(bool restore_defaults); + virtual s32 GetMediaType(); + virtual void SetSpindleSpeed(bool restore_defaults); - virtual s32 IsOK(); - virtual s32 Reopen(); + virtual s32 IsOK(); + virtual s32 Reopen(); - virtual s32 DiscChanged(); + virtual s32 DiscChanged(); }; extern Source *src; @@ -145,7 +147,7 @@ extern char source_drive; extern HINSTANCE hinst; -#define MSF_TO_LBA(m,s,f) ((m*60+s)*75+f-150) +#define MSF_TO_LBA(m, s, f) ((m * 60 + s) * 75 + f - 150) s32 cdvdDirectReadSector(s32 first, s32 mode, char *buffer); @@ -153,7 +155,7 @@ s32 cdvdGetMediaType(); void ReadSettings(); void WriteSettings(); -void CfgSetSettingsDir( const char* dir ); +void CfgSetSettingsDir(const char *dir); extern char csrc[]; extern bool cdvd_is_open; @@ -167,7 +169,7 @@ s32 cdvdStartThread(); void cdvdStopThread(); s32 cdvdRequestSector(u32 sector, s32 mode); s32 cdvdRequestComplete(); -char* cdvdGetSector(s32 sector, s32 mode); +char *cdvdGetSector(s32 sector, s32 mode); s32 cdvdDirectReadSector(s32 first, s32 mode, char *buffer); s32 cdvdGetMediaType(); s32 cdvdRefreshData(); diff --git a/plugins/cdvdGigaherz/src/ReadThread.cpp b/plugins/cdvdGigaherz/src/ReadThread.cpp index cf6bacf03a..78c497fdb8 100644 --- a/plugins/cdvdGigaherz/src/ReadThread.cpp +++ b/plugins/cdvdGigaherz/src/ReadThread.cpp @@ -15,11 +15,11 @@ #include "CDVD.h" -const s32 prefetch_max_blocks=16; -s32 prefetch_mode=0; -s32 prefetch_last_lba=0; -s32 prefetch_last_mode=0; -s32 prefetch_left=0; +const s32 prefetch_max_blocks = 16; +s32 prefetch_mode = 0; +s32 prefetch_last_lba = 0; +s32 prefetch_last_mode = 0; +s32 prefetch_left = 0; HANDLE hNotify = nullptr; HANDLE hThread = nullptr; @@ -27,431 +27,412 @@ HANDLE hRequestComplete = nullptr; CRITICAL_SECTION CacheMutex; -DWORD pidThread= 0; +DWORD pidThread = 0; -enum loadStatus -{ - LoadIdle, - LoadPending, - LoadSuccess, +enum loadStatus { + LoadIdle, + LoadPending, + LoadSuccess, }; typedef struct { - int lsn; - int mode; - char data[2352*16]; //we will read in blocks of 16 sectors + int lsn; + int mode; + char data[2352 * 16]; //we will read in blocks of 16 sectors } SectorInfo; //bits: 12 would use 1<<12 entries, or 4096*16 sectors ~ 128MB #define CACHE_SIZE 12 -const s32 CacheSize=(1<=0) - { - t^=lsn&m; - lsn>>=CACHE_SIZE; - i-=CACHE_SIZE; - } + while (i >= 0) { + t ^= lsn & m; + lsn >>= CACHE_SIZE; + i -= CACHE_SIZE; + } - return (t^mode)&m; + return (t ^ mode) & m; } -void cdvdCacheUpdate(int lsn, int mode, char* data) +void cdvdCacheUpdate(int lsn, int mode, char *data) { - EnterCriticalSection( &CacheMutex ); - u32 entry = cdvdSectorHash(lsn,mode); + EnterCriticalSection(&CacheMutex); + u32 entry = cdvdSectorHash(lsn, mode); - memcpy(Cache[entry].data,data,2352*16); - Cache[entry].lsn = lsn; - Cache[entry].mode = mode; - LeaveCriticalSection( &CacheMutex ); + memcpy(Cache[entry].data, data, 2352 * 16); + Cache[entry].lsn = lsn; + Cache[entry].mode = mode; + LeaveCriticalSection(&CacheMutex); } -bool cdvdCacheFetch(int lsn, int mode, char* data) +bool cdvdCacheFetch(int lsn, int mode, char *data) { - EnterCriticalSection( &CacheMutex ); - u32 entry = cdvdSectorHash(lsn,mode); + EnterCriticalSection(&CacheMutex); + u32 entry = cdvdSectorHash(lsn, mode); - if((Cache[entry].lsn==lsn) && - (Cache[entry].mode==mode)) - { - memcpy(data,Cache[entry].data,2352*16); - LeaveCriticalSection( &CacheMutex ); - return true; - } - //printf("NOT IN CACHE\n"); - LeaveCriticalSection( &CacheMutex ); - return false; + if ((Cache[entry].lsn == lsn) && + (Cache[entry].mode == mode)) { + memcpy(data, Cache[entry].data, 2352 * 16); + LeaveCriticalSection(&CacheMutex); + return true; + } + //printf("NOT IN CACHE\n"); + LeaveCriticalSection(&CacheMutex); + return false; } void cdvdCacheReset() { - EnterCriticalSection( &CacheMutex ); - for(int i=0;iDiscChanged(); + int change = src->DiscChanged(); - if(change==-1) //error getting status (no disc in drive?) - { - //try to recreate the device - src->Reopen(); + if (change == -1) { //error getting status (no disc in drive?) + //try to recreate the device + src->Reopen(); - if(src->IsOK()) - { - change = 1; - } - else - { - curDiskType=CDVD_TYPE_NODISC; - curTrayStatus=CDVD_TRAY_OPEN; - return true; - } - } + if (src->IsOK()) { + change = 1; + } else { + curDiskType = CDVD_TYPE_NODISC; + curTrayStatus = CDVD_TRAY_OPEN; + return true; + } + } - if(change==1) - { - if(!disc_has_changed) - { - disc_has_changed = true; - curDiskType = CDVD_TYPE_NODISC; - curTrayStatus = CDVD_TRAY_OPEN; - cdvdCallNewDiscCB(); - } - } - else - { - if(disc_has_changed) - { - curDiskType = CDVD_TYPE_NODISC; - curTrayStatus = CDVD_TRAY_CLOSE; + if (change == 1) { + if (!disc_has_changed) { + disc_has_changed = true; + curDiskType = CDVD_TYPE_NODISC; + curTrayStatus = CDVD_TRAY_OPEN; + cdvdCallNewDiscCB(); + } + } else { + if (disc_has_changed) { + curDiskType = CDVD_TYPE_NODISC; + curTrayStatus = CDVD_TRAY_CLOSE; - // just a test - src->Reopen(); + // just a test + src->Reopen(); - disc_has_changed = false; - cdvdRefreshData(); - cdvdCallNewDiscCB(); - } - } - return (change!=0); + disc_has_changed = false; + cdvdRefreshData(); + cdvdCallNewDiscCB(); + } + } + return (change != 0); } DWORD CALLBACK cdvdThread(PVOID param) { - printf(" * CDVD: IO thread started...\n"); + printf(" * CDVD: IO thread started...\n"); - while(cdvd_is_open) - { - if(!src) break; + while (cdvd_is_open) { + if (!src) + break; - if(cdvdUpdateDiscStatus()) - { - // Need to sleep some to avoid an aggressive spin that sucks the cpu dry. - Sleep( 10 ); - continue; - } + if (cdvdUpdateDiscStatus()) { + // Need to sleep some to avoid an aggressive spin that sucks the cpu dry. + Sleep(10); + continue; + } - if(prefetch_left) - WaitForSingleObject(hNotify,1); - else - WaitForSingleObject(hNotify,250); + if (prefetch_left) + WaitForSingleObject(hNotify, 1); + else + WaitForSingleObject(hNotify, 250); - // check again to make sure we're not done here... - if(!cdvd_is_open) break; + // check again to make sure we're not done here... + if (!cdvd_is_open) + break; - static SectorInfo info; + static SectorInfo info; - bool handlingRequest = false; + bool handlingRequest = false; - if(threadRequestPending) - { - info=threadRequestInfo; - handlingRequest = true; - } - else - { - info.lsn = prefetch_last_lba; - info.mode = prefetch_last_mode; - } + if (threadRequestPending) { + info = threadRequestInfo; + handlingRequest = true; + } else { + info.lsn = prefetch_last_lba; + info.mode = prefetch_last_mode; + } - if(threadRequestPending || prefetch_left) - { - s32 ret = -1; - s32 tries=5; + if (threadRequestPending || prefetch_left) { + s32 ret = -1; + s32 tries = 5; - s32 count = 16; + s32 count = 16; - s32 left = tracks[0].length-info.lsn; + s32 left = tracks[0].length - info.lsn; - if(leftReadSectors2048(info.lsn,count,info.data); - else - ret = src->ReadSectors2352(info.lsn,count,info.data); + do { + if (info.mode == CDVD_MODE_2048) + ret = src->ReadSectors2048(info.lsn, count, info.data); + else + ret = src->ReadSectors2352(info.lsn, count, info.data); - if(ret==0) - break; + if (ret == 0) + break; - tries--; + tries--; - } while((ret<0)&&(tries>0)); + } while ((ret < 0) && (tries > 0)); - cdvdCacheUpdate(info.lsn,info.mode,info.data); + cdvdCacheUpdate(info.lsn, info.mode, info.data); - if(handlingRequest) - { - threadRequestInfo = info; + if (handlingRequest) { + threadRequestInfo = info; - handlingRequest = false; - threadRequestPending = false; - PulseEvent(hRequestComplete); + handlingRequest = false; + threadRequestPending = false; + PulseEvent(hRequestComplete); - prefetch_last_lba=info.lsn; - prefetch_last_mode=info.mode; + prefetch_last_lba = info.lsn; + prefetch_last_mode = info.mode; - prefetch_left = prefetch_max_blocks; - } - else - { - prefetch_last_lba+=16; - prefetch_left--; - } - } - } - printf(" * CDVD: IO thread finished.\n"); - return 0; + prefetch_left = prefetch_max_blocks; + } else { + prefetch_last_lba += 16; + prefetch_left--; + } + } + } + printf(" * CDVD: IO thread finished.\n"); + return 0; } s32 cdvdStartThread() { - InitializeCriticalSection( &CacheMutex ); + InitializeCriticalSection(&CacheMutex); - hNotify = CreateEvent(NULL,FALSE,FALSE,NULL); - if(hNotify == nullptr) - return -1; + hNotify = CreateEvent(NULL, FALSE, FALSE, NULL); + if (hNotify == nullptr) + return -1; - hRequestComplete = CreateEvent(NULL,FALSE,FALSE,NULL); - if(hRequestComplete == nullptr) - return -1; + hRequestComplete = CreateEvent(NULL, FALSE, FALSE, NULL); + if (hRequestComplete == nullptr) + return -1; - cdvd_is_open=true; - hThread = CreateThread(NULL,0,cdvdThread,NULL,0,&pidThread); + cdvd_is_open = true; + hThread = CreateThread(NULL, 0, cdvdThread, NULL, 0, &pidThread); - if(hThread == nullptr) - return -1; + if (hThread == nullptr) + return -1; - SetThreadPriority(hThread,THREAD_PRIORITY_NORMAL); + SetThreadPriority(hThread, THREAD_PRIORITY_NORMAL); - cdvdCacheReset(); + cdvdCacheReset(); - return 0; + return 0; } void cdvdStopThread() { - cdvd_is_open=false; - PulseEvent(hNotify); - if(WaitForSingleObject(hThread,4000)==WAIT_TIMEOUT) - { - TerminateThread(hThread,0); - } - CloseHandle(hThread); - CloseHandle(hNotify); - CloseHandle(hRequestComplete); + cdvd_is_open = false; + PulseEvent(hNotify); + if (WaitForSingleObject(hThread, 4000) == WAIT_TIMEOUT) { + TerminateThread(hThread, 0); + } + CloseHandle(hThread); + CloseHandle(hNotify); + CloseHandle(hRequestComplete); - DeleteCriticalSection( &CacheMutex ); + DeleteCriticalSection(&CacheMutex); } s32 cdvdRequestSector(u32 sector, s32 mode) { - if(sector>=tracks[0].length) - return -1; + if (sector >= tracks[0].length) + return -1; - sector&=~15; //align to 16-sector block + sector &= ~15; //align to 16-sector block - threadRequestInfo.lsn = sector; - threadRequestInfo.mode = mode; - threadRequestPending = false; - if(cdvdCacheFetch(sector,mode,threadRequestInfo.data)) - { - return 0; - } + threadRequestInfo.lsn = sector; + threadRequestInfo.mode = mode; + threadRequestPending = false; + if (cdvdCacheFetch(sector, mode, threadRequestInfo.data)) { + return 0; + } - threadRequestPending = true; - ResetEvent(hRequestComplete); - PulseEvent(hNotify); + threadRequestPending = true; + ResetEvent(hRequestComplete); + PulseEvent(hNotify); - return 0; + return 0; } s32 cdvdRequestComplete() { - return !threadRequestPending; + return !threadRequestPending; } -s8* cdvdGetSector(s32 sector, s32 mode) +s8 *cdvdGetSector(s32 sector, s32 mode) { - while(threadRequestPending) - { - WaitForSingleObject( hRequestComplete, 10 ); - } + while (threadRequestPending) { + WaitForSingleObject(hRequestComplete, 10); + } - s32 offset; + s32 offset; - if(mode==CDVD_MODE_2048) - { - offset = 2048*(sector-threadRequestInfo.lsn); - return threadRequestInfo.data + offset; - } + if (mode == CDVD_MODE_2048) { + offset = 2048 * (sector - threadRequestInfo.lsn); + return threadRequestInfo.data + offset; + } - offset = 2352*(sector-threadRequestInfo.lsn); - s8* data = threadRequestInfo.data + offset; + offset = 2352 * (sector - threadRequestInfo.lsn); + s8 *data = threadRequestInfo.data + offset; - switch(mode) - { - case CDVD_MODE_2328: - return data + 24; - case CDVD_MODE_2340: - return data + 12; - } - return data; + switch (mode) { + case CDVD_MODE_2328: + return data + 24; + case CDVD_MODE_2340: + return data + 12; + } + return data; } s32 cdvdDirectReadSector(s32 first, s32 mode, char *buffer) { - static char data[16*2352]; + static char data[16 * 2352]; - if((u32)first>=tracks[0].length) - return -1; + if ((u32)first >= tracks[0].length) + return -1; - s32 sector = first&(~15); //align to 16-sector block + s32 sector = first & (~15); //align to 16-sector block - EnterCriticalSection( &CacheMutex ); - if(!cdvdCacheFetch(sector,mode,data)) - { - s32 ret = -1; - s32 tries=5; + EnterCriticalSection(&CacheMutex); + if (!cdvdCacheFetch(sector, mode, data)) { + s32 ret = -1; + s32 tries = 5; - s32 count = 16; + s32 count = 16; - s32 left = tracks[0].length-sector; + s32 left = tracks[0].length - sector; - if(leftReadSectors2048(sector,count,data); - else - ret = src->ReadSectors2352(sector,count,data); + do { + if (mode == CDVD_MODE_2048) + ret = src->ReadSectors2048(sector, count, data); + else + ret = src->ReadSectors2352(sector, count, data); - if(ret==0) - break; + if (ret == 0) + break; - tries--; + tries--; - } while((ret<0)&&(tries>0)); + } while ((ret < 0) && (tries > 0)); - cdvdCacheUpdate(sector,mode,data); - } - LeaveCriticalSection( &CacheMutex ); + cdvdCacheUpdate(sector, mode, data); + } + LeaveCriticalSection(&CacheMutex); - s32 offset; + s32 offset; - if(mode==CDVD_MODE_2048) - { - offset = 2048*(first-sector); - memcpy(buffer,data + offset,2048); - return 0; - } + if (mode == CDVD_MODE_2048) { + offset = 2048 * (first - sector); + memcpy(buffer, data + offset, 2048); + return 0; + } - offset = 2352*(first-sector); - s8* bfr = data + offset; + offset = 2352 * (first - sector); + s8 *bfr = data + offset; - switch(mode) - { - case CDVD_MODE_2328: - memcpy(buffer,bfr+24,2328); - return 0; - case CDVD_MODE_2340: - memcpy(buffer,bfr+12,2340); - return 0; - default: - memcpy(buffer,bfr+12,2352); - return 0; - } - return 0; + switch (mode) { + case CDVD_MODE_2328: + memcpy(buffer, bfr + 24, 2328); + return 0; + case CDVD_MODE_2340: + memcpy(buffer, bfr + 12, 2340); + return 0; + default: + memcpy(buffer, bfr + 12, 2352); + return 0; + } + return 0; } s32 cdvdGetMediaType() { - return src->GetMediaType(); + return src->GetMediaType(); } -s32 refreshes=0; +s32 refreshes = 0; s32 cdvdRefreshData() { - char *diskTypeName="Unknown"; + char *diskTypeName = "Unknown"; - //read TOC from device - cdvdParseTOC(); + //read TOC from device + cdvdParseTOC(); - if((etrack==0)||(strack>etrack)) - { - curDiskType=CDVD_TYPE_NODISC; - } - else - { - s32 mt=cdvdGetMediaType(); + if ((etrack == 0) || (strack > etrack)) { + curDiskType = CDVD_TYPE_NODISC; + } else { + s32 mt = cdvdGetMediaType(); - if(mt<0) curDiskType = CDVD_TYPE_DETCTCD; - else if(mt == 0) curDiskType = CDVD_TYPE_DETCTDVDS; - else curDiskType = CDVD_TYPE_DETCTDVDD; - } + if (mt < 0) + curDiskType = CDVD_TYPE_DETCTCD; + else if (mt == 0) + curDiskType = CDVD_TYPE_DETCTDVDS; + else + curDiskType = CDVD_TYPE_DETCTDVDD; + } - curTrayStatus = CDVD_TRAY_CLOSE; + curTrayStatus = CDVD_TRAY_CLOSE; - switch(curDiskType) - { - case CDVD_TYPE_DETCTDVDD: diskTypeName="Double-Layer DVD"; break; - case CDVD_TYPE_DETCTDVDS: diskTypeName="Single-Layer DVD"; break; - case CDVD_TYPE_DETCTCD: diskTypeName="CD-ROM"; break; - case CDVD_TYPE_NODISC: diskTypeName="No Disc"; break; - } + switch (curDiskType) { + case CDVD_TYPE_DETCTDVDD: + diskTypeName = "Double-Layer DVD"; + break; + case CDVD_TYPE_DETCTDVDS: + diskTypeName = "Single-Layer DVD"; + break; + case CDVD_TYPE_DETCTCD: + diskTypeName = "CD-ROM"; + break; + case CDVD_TYPE_NODISC: + diskTypeName = "No Disc"; + break; + } - printf(" * CDVD: Disk Type: %s\n",diskTypeName); + printf(" * CDVD: Disk Type: %s\n", diskTypeName); - cdvdCacheReset(); + cdvdCacheReset(); - return 0; + return 0; } diff --git a/plugins/cdvdGigaherz/src/TocStuff.cpp b/plugins/cdvdGigaherz/src/TocStuff.cpp index cd8244da4c..23ae3d68ca 100644 --- a/plugins/cdvdGigaherz/src/TocStuff.cpp +++ b/plugins/cdvdGigaherz/src/TocStuff.cpp @@ -19,128 +19,110 @@ toc_data cdtoc; s32 cdvdParseTOC() { - memset(&cdtoc, 0, sizeof(cdtoc)); + memset(&cdtoc, 0, sizeof(cdtoc)); - s32 len = src->GetSectorCount(); + s32 len = src->GetSectorCount(); - tracks[0].length = len; - tracks[0].start_lba = 0; - tracks[0].type = 0; - tracks[1].start_lba = 0; + tracks[0].length = len; + tracks[0].start_lba = 0; + tracks[0].type = 0; + tracks[1].start_lba = 0; - if (len <= 0) - { - curDiskType = CDVD_TYPE_NODISC; - tracks[0].length = 0; - strack = 1; - etrack = 0; - return 0; - } + if (len <= 0) { + curDiskType = CDVD_TYPE_NODISC; + tracks[0].length = 0; + strack = 1; + etrack = 0; + return 0; + } - s32 mt = src->GetMediaType(); + s32 mt = src->GetMediaType(); - if (mt >= 0) - { - tracks[1].length = tracks[0].length; - tracks[1].type = 0; + if (mt >= 0) { + tracks[1].length = tracks[0].length; + tracks[1].type = 0; - strack = 1; - etrack = 1; - } - else - { - u8 min, sec, frm; + strack = 1; + etrack = 1; + } else { + u8 min, sec, frm; - if(src->ReadTOC((char*)&cdtoc,sizeof(cdtoc))<0) - { - /* - printf(" * CDVD: WARNING ReadTOC() failed, trying to use MCI instead...\n"); - delete src; - int status = MCI_CDGetTOC(source_drive); + if (src->ReadTOC((char *)&cdtoc, sizeof(cdtoc)) < 0) { + /* + printf(" * CDVD: WARNING ReadTOC() failed, trying to use MCI instead...\n"); + delete src; + int status = MCI_CDGetTOC(source_drive); - src=new SOURCECLASS(csrc); + src=new SOURCECLASS(csrc); - if(status<0)*/ - return -1; + if(status<0)*/ + return -1; - //return 0; - } + //return 0; + } - int length = (cdtoc.Length[0]<<8) | cdtoc.Length[1]; - int descriptors = length/sizeof(cdtoc.Descriptors[0]); - for(int i=0;i0)) - { - int tn=cdtoc.Descriptors[i].Point; + tracks[0].length = MSF_TO_LBA(min, sec, frm); + tracks[0].type = 0; + } + break; + case 0xb0: + break; + case 0xb1: + break; + case 0xb2: + break; + case 0xc0: + break; + default: + if ((cdtoc.Descriptors[i].Point < 100) && (cdtoc.Descriptors[i].Point > 0)) { + int tn = cdtoc.Descriptors[i].Point; - min=cdtoc.Descriptors[i].Msf[0]; - sec=cdtoc.Descriptors[i].Msf[1]; - frm=cdtoc.Descriptors[i].Msf[2]; + min = cdtoc.Descriptors[i].Msf[0]; + sec = cdtoc.Descriptors[i].Msf[1]; + frm = cdtoc.Descriptors[i].Msf[2]; - tracks[tn].start_lba = MSF_TO_LBA(min,sec,frm); - if(tn>1) - tracks[tn-1].length = tracks[tn].start_lba - tracks[tn-1].start_lba; + tracks[tn].start_lba = MSF_TO_LBA(min, sec, frm); + if (tn > 1) + tracks[tn - 1].length = tracks[tn].start_lba - tracks[tn - 1].start_lba; - if((cdtoc.Descriptors[i].Control&4)==0) - { - tracks[tn].type = CDVD_AUDIO_TRACK; - } - else if((cdtoc.Descriptors[i].Control&0xE)==4) - { - tracks[tn].type = CDVD_MODE1_TRACK; - } - else - { - tracks[tn].type = CDVD_MODE1_TRACK; - } + if ((cdtoc.Descriptors[i].Control & 4) == 0) { + tracks[tn].type = CDVD_AUDIO_TRACK; + } else if ((cdtoc.Descriptors[i].Control & 0xE) == 4) { + tracks[tn].type = CDVD_MODE1_TRACK; + } else { + tracks[tn].type = CDVD_MODE1_TRACK; + } - fprintf(stderr,"Track %d: %d mins %d secs %d frames\n",tn,min,sec,frm); - } - else if(cdtoc.Descriptors[i].Point>0) - { - printf("Found code 0x%02x\n",cdtoc.Descriptors[i].Point); - } - break; - } - } + fprintf(stderr, "Track %d: %d mins %d secs %d frames\n", tn, min, sec, frm); + } else if (cdtoc.Descriptors[i].Point > 0) { + printf("Found code 0x%02x\n", cdtoc.Descriptors[i].Point); + } + break; + } + } - tracks[etrack].length = tracks[0].length - tracks[etrack].start_lba; - } + tracks[etrack].length = tracks[0].length - tracks[etrack].start_lba; + } - return 0; + return 0; } diff --git a/plugins/cdvdGigaherz/src/Windows/IOCtlSrc.cpp b/plugins/cdvdGigaherz/src/Windows/IOCtlSrc.cpp index 69a98c4169..40f4143d93 100644 --- a/plugins/cdvdGigaherz/src/Windows/IOCtlSrc.cpp +++ b/plugins/cdvdGigaherz/src/Windows/IOCtlSrc.cpp @@ -19,366 +19,336 @@ #include #include // "typedef ignored" warning will disappear once we move to the Windows 10 SDK. -#pragma warning (push) -#pragma warning (disable: 4091) +#pragma warning(push) +#pragma warning(disable : 4091) #include -#pragma warning (pop) +#pragma warning(pop) #include #include s32 IOCtlSrc::Reopen() { - if(device!=INVALID_HANDLE_VALUE) - { - DWORD size; - DeviceIoControl(device,IOCTL_DVD_END_SESSION,&sessID,sizeof(DVD_SESSION_ID),NULL,0,&size, NULL); - CloseHandle(device); - } + if (device != INVALID_HANDLE_VALUE) { + DWORD size; + DeviceIoControl(device, IOCTL_DVD_END_SESSION, &sessID, sizeof(DVD_SESSION_ID), NULL, 0, &size, NULL); + CloseHandle(device); + } - DWORD share = FILE_SHARE_READ; - DWORD flags = FILE_ATTRIBUTE_READONLY | FILE_FLAG_SEQUENTIAL_SCAN; - DWORD size; + DWORD share = FILE_SHARE_READ; + DWORD flags = FILE_ATTRIBUTE_READONLY | FILE_FLAG_SEQUENTIAL_SCAN; + DWORD size; - OpenOK = false; - // SPTI only works if the device is opened with GENERIC_WRITE access. - m_can_use_spti = true; - device = CreateFile(fName, GENERIC_READ|GENERIC_WRITE|FILE_READ_ATTRIBUTES, share, NULL, OPEN_EXISTING, flags, 0); - if(device==INVALID_HANDLE_VALUE) - { - device = CreateFile(fName, GENERIC_READ|FILE_READ_ATTRIBUTES, share, NULL, OPEN_EXISTING, flags, 0); - if(device==INVALID_HANDLE_VALUE) - return -1; - m_can_use_spti = false; - } - // Dual layer DVDs cannot read from layer 1 without this ioctl - DeviceIoControl(device, FSCTL_ALLOW_EXTENDED_DASD_IO, nullptr, 0, nullptr, 0, &size, nullptr); + OpenOK = false; + // SPTI only works if the device is opened with GENERIC_WRITE access. + m_can_use_spti = true; + device = CreateFile(fName, GENERIC_READ | GENERIC_WRITE | FILE_READ_ATTRIBUTES, share, NULL, OPEN_EXISTING, flags, 0); + if (device == INVALID_HANDLE_VALUE) { + device = CreateFile(fName, GENERIC_READ | FILE_READ_ATTRIBUTES, share, NULL, OPEN_EXISTING, flags, 0); + if (device == INVALID_HANDLE_VALUE) + return -1; + m_can_use_spti = false; + } + // Dual layer DVDs cannot read from layer 1 without this ioctl + DeviceIoControl(device, FSCTL_ALLOW_EXTENDED_DASD_IO, nullptr, 0, nullptr, 0, &size, nullptr); - // FIXME: 0 is a valid session id, but the code assumes that it isn't. - sessID=0; - DeviceIoControl(device,IOCTL_DVD_START_SESSION,NULL,0,&sessID,sizeof(DVD_SESSION_ID), &size, NULL); + // FIXME: 0 is a valid session id, but the code assumes that it isn't. + sessID = 0; + DeviceIoControl(device, IOCTL_DVD_START_SESSION, NULL, 0, &sessID, sizeof(DVD_SESSION_ID), &size, NULL); - tocCached = false; - mediaTypeCached = false; - discSizeCached = false; - layerBreakCached = false; + tocCached = false; + mediaTypeCached = false; + discSizeCached = false; + layerBreakCached = false; - OpenOK=true; - return 0; + OpenOK = true; + return 0; } -IOCtlSrc::IOCtlSrc(const char* fileName) +IOCtlSrc::IOCtlSrc(const char *fileName) { - device=INVALID_HANDLE_VALUE; + device = INVALID_HANDLE_VALUE; - strcpy_s(fName,256,fileName); + strcpy_s(fName, 256, fileName); - Reopen(); - SetSpindleSpeed(false); + Reopen(); + SetSpindleSpeed(false); } IOCtlSrc::~IOCtlSrc() { - if(OpenOK) - { - SetSpindleSpeed( true ); - DWORD size; - DeviceIoControl(device,IOCTL_DVD_END_SESSION,&sessID,sizeof(DVD_SESSION_ID),NULL,0,&size, NULL); + if (OpenOK) { + SetSpindleSpeed(true); + DWORD size; + DeviceIoControl(device, IOCTL_DVD_END_SESSION, &sessID, sizeof(DVD_SESSION_ID), NULL, 0, &size, NULL); - CloseHandle(device); - } + CloseHandle(device); + } } struct mycrap { - DWORD shit; - DVD_LAYER_DESCRIPTOR ld; - // The IOCTL_DVD_READ_STRUCTURE expects a size of at least 22 bytes when - // reading the dvd physical layer descriptor - // 4 bytes header - // 17 bytes for the layer descriptor - // 1 byte of the media specific data for no reason whatsoever... - UCHAR fixup; + DWORD shit; + DVD_LAYER_DESCRIPTOR ld; + // The IOCTL_DVD_READ_STRUCTURE expects a size of at least 22 bytes when + // reading the dvd physical layer descriptor + // 4 bytes header + // 17 bytes for the layer descriptor + // 1 byte of the media specific data for no reason whatsoever... + UCHAR fixup; }; DVD_READ_STRUCTURE dvdrs; mycrap dld; -CDROM_READ_TOC_EX tocrq={0}; +CDROM_READ_TOC_EX tocrq = {0}; s32 IOCtlSrc::GetSectorCount() { - DWORD size; + DWORD size; - LARGE_INTEGER li; + LARGE_INTEGER li; - if(discSizeCached) - return discSize; + if (discSizeCached) + return discSize; - if(GetFileSizeEx(device,&li)) - { - discSizeCached = true; - discSize = (s32)(li.QuadPart / 2048); - return discSize; - } + if (GetFileSizeEx(device, &li)) { + discSizeCached = true; + discSize = (s32)(li.QuadPart / 2048); + return discSize; + } - GET_LENGTH_INFORMATION info; - if(DeviceIoControl(device, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &info, sizeof(info), &size, NULL)) - { - discSizeCached = true; - discSize = (s32)(info.Length.QuadPart / 2048); - return discSize; - } + GET_LENGTH_INFORMATION info; + if (DeviceIoControl(device, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &info, sizeof(info), &size, NULL)) { + discSizeCached = true; + discSize = (s32)(info.Length.QuadPart / 2048); + return discSize; + } - memset(&tocrq,0,sizeof(CDROM_READ_TOC_EX)); - tocrq.Format = CDROM_READ_TOC_EX_FORMAT_FULL_TOC; - tocrq.Msf=1; - tocrq.SessionTrack=1; + memset(&tocrq, 0, sizeof(CDROM_READ_TOC_EX)); + tocrq.Format = CDROM_READ_TOC_EX_FORMAT_FULL_TOC; + tocrq.Msf = 1; + tocrq.SessionTrack = 1; - CDROM_TOC_FULL_TOC_DATA *ftd=(CDROM_TOC_FULL_TOC_DATA*)sectorbuffer; + CDROM_TOC_FULL_TOC_DATA *ftd = (CDROM_TOC_FULL_TOC_DATA *)sectorbuffer; - if(DeviceIoControl(device,IOCTL_CDROM_READ_TOC_EX,&tocrq,sizeof(tocrq),ftd, 2048, &size, NULL)) - { - for(int i=0;i<101;i++) - { - if(ftd->Descriptors[i].Point==0xa2) - { - if(ftd->Descriptors[i].SessionNumber==ftd->LastCompleteSession) - { - int min=ftd->Descriptors[i].Msf[0]; - int sec=ftd->Descriptors[i].Msf[1]; - int frm=ftd->Descriptors[i].Msf[2]; + if (DeviceIoControl(device, IOCTL_CDROM_READ_TOC_EX, &tocrq, sizeof(tocrq), ftd, 2048, &size, NULL)) { + for (int i = 0; i < 101; i++) { + if (ftd->Descriptors[i].Point == 0xa2) { + if (ftd->Descriptors[i].SessionNumber == ftd->LastCompleteSession) { + int min = ftd->Descriptors[i].Msf[0]; + int sec = ftd->Descriptors[i].Msf[1]; + int frm = ftd->Descriptors[i].Msf[2]; - discSizeCached = true; - discSize = (s32)MSF_TO_LBA(min,sec,frm); - return discSize; - } - } - } - } + discSizeCached = true; + discSize = (s32)MSF_TO_LBA(min, sec, frm); + return discSize; + } + } + } + } - dvdrs.BlockByteOffset.QuadPart=0; - dvdrs.Format=DvdPhysicalDescriptor; - dvdrs.SessionId=sessID; - dvdrs.LayerNumber=0; - if(DeviceIoControl(device,IOCTL_DVD_READ_STRUCTURE,&dvdrs,sizeof(dvdrs),&dld, sizeof(dld), &size, NULL)!=0) - { - s32 sectors1 = _byteswap_ulong(dld.ld.EndDataSector) - _byteswap_ulong(dld.ld.StartingDataSector) + 1; - if (dld.ld.NumberOfLayers == 1) // PTP, OTP - { - if (dld.ld.TrackPath == 0) // PTP - { - dvdrs.LayerNumber = 1; - if (DeviceIoControl(device, IOCTL_DVD_READ_STRUCTURE, &dvdrs, sizeof(dvdrs), &dld, sizeof(dld), &size, nullptr) != 0) - { - sectors1 += _byteswap_ulong(dld.ld.EndDataSector) - _byteswap_ulong(dld.ld.StartingDataSector) + 1; - } - } - else // OTP - { - // sectors = end_sector - (~end_sector_l0 & 0xFFFFFF) + end_sector_l0 - start_sector - dld.ld.EndLayerZeroSector = _byteswap_ulong(dld.ld.EndLayerZeroSector); - sectors1 += dld.ld.EndLayerZeroSector - (~dld.ld.EndLayerZeroSector & 0x00FFFFFF) + 1; - } - } + dvdrs.BlockByteOffset.QuadPart = 0; + dvdrs.Format = DvdPhysicalDescriptor; + dvdrs.SessionId = sessID; + dvdrs.LayerNumber = 0; + if (DeviceIoControl(device, IOCTL_DVD_READ_STRUCTURE, &dvdrs, sizeof(dvdrs), &dld, sizeof(dld), &size, NULL) != 0) { + s32 sectors1 = _byteswap_ulong(dld.ld.EndDataSector) - _byteswap_ulong(dld.ld.StartingDataSector) + 1; + if (dld.ld.NumberOfLayers == 1) { // PTP, OTP + if (dld.ld.TrackPath == 0) { // PTP + dvdrs.LayerNumber = 1; + if (DeviceIoControl(device, IOCTL_DVD_READ_STRUCTURE, &dvdrs, sizeof(dvdrs), &dld, sizeof(dld), &size, nullptr) != 0) { + sectors1 += _byteswap_ulong(dld.ld.EndDataSector) - _byteswap_ulong(dld.ld.StartingDataSector) + 1; + } + } else { // OTP + // sectors = end_sector - (~end_sector_l0 & 0xFFFFFF) + end_sector_l0 - start_sector + dld.ld.EndLayerZeroSector = _byteswap_ulong(dld.ld.EndLayerZeroSector); + sectors1 += dld.ld.EndLayerZeroSector - (~dld.ld.EndLayerZeroSector & 0x00FFFFFF) + 1; + } + } - discSizeCached = true; - discSize = sectors1; - return discSize; - } + discSizeCached = true; + discSize = sectors1; + return discSize; + } - return -1; + return -1; } s32 IOCtlSrc::GetLayerBreakAddress() { - DWORD size; + DWORD size; - if(GetMediaType()<0) - return -1; + if (GetMediaType() < 0) + return -1; - if(layerBreakCached) - return layerBreak; + if (layerBreakCached) + return layerBreak; - dvdrs.BlockByteOffset.QuadPart=0; - dvdrs.Format=DvdPhysicalDescriptor; - dvdrs.SessionId=sessID; - dvdrs.LayerNumber=0; - if (DeviceIoControl(device, IOCTL_DVD_READ_STRUCTURE, &dvdrs, sizeof(dvdrs), &dld, sizeof(dld), &size, nullptr)) - { - if (dld.ld.NumberOfLayers == 0) // Single layer - { - layerBreak = 0; - } - else if (dld.ld.TrackPath == 0) // PTP - { - layerBreak = _byteswap_ulong(dld.ld.EndDataSector) - _byteswap_ulong(dld.ld.StartingDataSector); - } - else // OTP - { - layerBreak = _byteswap_ulong(dld.ld.EndLayerZeroSector) - _byteswap_ulong(dld.ld.StartingDataSector); - } + dvdrs.BlockByteOffset.QuadPart = 0; + dvdrs.Format = DvdPhysicalDescriptor; + dvdrs.SessionId = sessID; + dvdrs.LayerNumber = 0; + if (DeviceIoControl(device, IOCTL_DVD_READ_STRUCTURE, &dvdrs, sizeof(dvdrs), &dld, sizeof(dld), &size, nullptr)) { + if (dld.ld.NumberOfLayers == 0) { // Single layer + layerBreak = 0; + } else if (dld.ld.TrackPath == 0) { // PTP + layerBreak = _byteswap_ulong(dld.ld.EndDataSector) - _byteswap_ulong(dld.ld.StartingDataSector); + } else { // OTP + layerBreak = _byteswap_ulong(dld.ld.EndLayerZeroSector) - _byteswap_ulong(dld.ld.StartingDataSector); + } - layerBreakCached = true; - return layerBreak; - } + layerBreakCached = true; + return layerBreak; + } - //if not a cd, and fails, assume single layer - return 0; + //if not a cd, and fails, assume single layer + return 0; } -void IOCtlSrc::SetSpindleSpeed(bool restore_defaults) { - - DWORD dontcare; - int speed = 0; - - if (GetMediaType() < 0 ) speed = 4800; // CD-ROM to ~32x (PS2 has 24x (3600 KB/s)) - else speed = 11080; // DVD-ROM to ~8x (PS2 has 4x (5540 KB/s)) - - if (!restore_defaults) { - CDROM_SET_SPEED s; - s.RequestType = CdromSetSpeed; - s.RotationControl = CdromDefaultRotation; - s.ReadSpeed = speed; - s.WriteSpeed = speed; +void IOCtlSrc::SetSpindleSpeed(bool restore_defaults) +{ - if (DeviceIoControl(device, - IOCTL_CDROM_SET_SPEED, //operation to perform - &s, sizeof(s), //no input buffer - NULL, 0, //output buffer - &dontcare, //#bytes returned - (LPOVERLAPPED)NULL)) //synchronous I/O == 0) - { - printf(" * CDVD: setSpindleSpeed success (%dKB/s)\n", speed); - } - else - { - printf(" * CDVD: setSpindleSpeed failed! \n"); - } - } - else { - CDROM_SET_SPEED s; - s.RequestType = CdromSetSpeed; - s.RotationControl = CdromDefaultRotation; - s.ReadSpeed = 0xffff; // maximum ? - s.WriteSpeed = 0xffff; + DWORD dontcare; + int speed = 0; - DeviceIoControl(device, - IOCTL_CDROM_SET_SPEED, //operation to perform - &s, sizeof(s), //no input buffer - NULL, 0, //output buffer - &dontcare, //#bytes returned - (LPOVERLAPPED)NULL); //synchronous I/O == 0) - } + if (GetMediaType() < 0) + speed = 4800; // CD-ROM to ~32x (PS2 has 24x (3600 KB/s)) + else + speed = 11080; // DVD-ROM to ~8x (PS2 has 4x (5540 KB/s)) + + if (!restore_defaults) { + CDROM_SET_SPEED s; + s.RequestType = CdromSetSpeed; + s.RotationControl = CdromDefaultRotation; + s.ReadSpeed = speed; + s.WriteSpeed = speed; + + if (DeviceIoControl(device, + IOCTL_CDROM_SET_SPEED, //operation to perform + &s, sizeof(s), //no input buffer + NULL, 0, //output buffer + &dontcare, //#bytes returned + (LPOVERLAPPED)NULL)) //synchronous I/O == 0) + { + printf(" * CDVD: setSpindleSpeed success (%dKB/s)\n", speed); + } else { + printf(" * CDVD: setSpindleSpeed failed! \n"); + } + } else { + CDROM_SET_SPEED s; + s.RequestType = CdromSetSpeed; + s.RotationControl = CdromDefaultRotation; + s.ReadSpeed = 0xffff; // maximum ? + s.WriteSpeed = 0xffff; + + DeviceIoControl(device, + IOCTL_CDROM_SET_SPEED, //operation to perform + &s, sizeof(s), //no input buffer + NULL, 0, //output buffer + &dontcare, //#bytes returned + (LPOVERLAPPED)NULL); //synchronous I/O == 0) + } } s32 IOCtlSrc::GetMediaType() { - DWORD size; + DWORD size; - if(mediaTypeCached) - return mediaType; + if (mediaTypeCached) + return mediaType; - memset(&tocrq,0,sizeof(CDROM_READ_TOC_EX)); - tocrq.Format = CDROM_READ_TOC_EX_FORMAT_FULL_TOC; - tocrq.Msf=1; - tocrq.SessionTrack=1; + memset(&tocrq, 0, sizeof(CDROM_READ_TOC_EX)); + tocrq.Format = CDROM_READ_TOC_EX_FORMAT_FULL_TOC; + tocrq.Msf = 1; + tocrq.SessionTrack = 1; - CDROM_TOC_FULL_TOC_DATA *ftd=(CDROM_TOC_FULL_TOC_DATA*)sectorbuffer; + CDROM_TOC_FULL_TOC_DATA *ftd = (CDROM_TOC_FULL_TOC_DATA *)sectorbuffer; - if(DeviceIoControl(device,IOCTL_CDROM_READ_TOC_EX,&tocrq,sizeof(tocrq),ftd, 2048, &size, NULL)) - { - mediaTypeCached = true; - mediaType = -1; - return mediaType; - } + if (DeviceIoControl(device, IOCTL_CDROM_READ_TOC_EX, &tocrq, sizeof(tocrq), ftd, 2048, &size, NULL)) { + mediaTypeCached = true; + mediaType = -1; + return mediaType; + } - dvdrs.BlockByteOffset.QuadPart=0; - dvdrs.Format=DvdPhysicalDescriptor; - dvdrs.SessionId=sessID; - dvdrs.LayerNumber=0; - if (DeviceIoControl(device, IOCTL_DVD_READ_STRUCTURE, &dvdrs, sizeof(dvdrs), &dld, sizeof(dld), &size, nullptr)) - { - if (dld.ld.NumberOfLayers == 0) // Single layer - { - mediaType = 0; - } - else if (dld.ld.TrackPath == 0) // PTP - { - mediaType = 1; - } - else // OTP - { - mediaType = 2; - } + dvdrs.BlockByteOffset.QuadPart = 0; + dvdrs.Format = DvdPhysicalDescriptor; + dvdrs.SessionId = sessID; + dvdrs.LayerNumber = 0; + if (DeviceIoControl(device, IOCTL_DVD_READ_STRUCTURE, &dvdrs, sizeof(dvdrs), &dld, sizeof(dld), &size, nullptr)) { + if (dld.ld.NumberOfLayers == 0) { // Single layer + mediaType = 0; + } else if (dld.ld.TrackPath == 0) { // PTP + mediaType = 1; + } else { // OTP + mediaType = 2; + } - mediaTypeCached = true; - return mediaType; - } + mediaTypeCached = true; + return mediaType; + } - //if not a cd, and fails, assume single layer - mediaTypeCached = true; - mediaType = 0; - return mediaType; + //if not a cd, and fails, assume single layer + mediaTypeCached = true; + mediaType = 0; + return mediaType; } -s32 IOCtlSrc::ReadTOC(char *toc,int msize) +s32 IOCtlSrc::ReadTOC(char *toc, int msize) { - DWORD size=0; + DWORD size = 0; - if(GetMediaType()>=0) - return -1; + if (GetMediaType() >= 0) + return -1; - if(!tocCached) - { - memset(&tocrq,0,sizeof(CDROM_READ_TOC_EX)); - tocrq.Format = CDROM_READ_TOC_EX_FORMAT_FULL_TOC; - tocrq.Msf=1; - tocrq.SessionTrack=1; + if (!tocCached) { + memset(&tocrq, 0, sizeof(CDROM_READ_TOC_EX)); + tocrq.Format = CDROM_READ_TOC_EX_FORMAT_FULL_TOC; + tocrq.Msf = 1; + tocrq.SessionTrack = 1; - if(!OpenOK) return -1; + if (!OpenOK) + return -1; - int code = DeviceIoControl(device,IOCTL_CDROM_READ_TOC_EX,&tocrq,sizeof(tocrq),tocCacheData, 2048, &size, NULL); + int code = DeviceIoControl(device, IOCTL_CDROM_READ_TOC_EX, &tocrq, sizeof(tocrq), tocCacheData, 2048, &size, NULL); - if(code==0) - return -1; + if (code == 0) + return -1; - tocCached = true; - } + tocCached = true; + } - memcpy(toc,tocCacheData,min(2048,msize)); + memcpy(toc, tocCacheData, min(2048, msize)); - return 0; + return 0; } s32 IOCtlSrc::ReadSectors2048(u32 sector, u32 count, char *buffer) { - RAW_READ_INFO rri; + RAW_READ_INFO rri; - DWORD size=0; + DWORD size = 0; - if(!OpenOK) return -1; + if (!OpenOK) + return -1; - rri.DiskOffset.QuadPart=sector*(u64)2048; - rri.SectorCount=count; + rri.DiskOffset.QuadPart = sector * (u64)2048; + rri.SectorCount = count; - //fall back to standard reading - if(SetFilePointer(device,rri.DiskOffset.LowPart,&rri.DiskOffset.HighPart,FILE_BEGIN)==-1) - { - if(GetLastError()!=0) - return -1; - } + //fall back to standard reading + if (SetFilePointer(device, rri.DiskOffset.LowPart, &rri.DiskOffset.HighPart, FILE_BEGIN) == -1) { + if (GetLastError() != 0) + return -1; + } - if(ReadFile(device,buffer,2048*count,&size,NULL)==0) - { - return -1; - } + if (ReadFile(device, buffer, 2048 * count, &size, NULL) == 0) { + return -1; + } - if(size!=(2048*count)) - { - return -1; - } + if (size != (2048 * count)) { + return -1; + } - return 0; + return 0; } @@ -386,122 +356,114 @@ s32 IOCtlSrc::ReadSectors2048(u32 sector, u32 count, char *buffer) // of different types. s32 IOCtlSrc::ReadSectors2352(u32 sector, u32 count, char *buffer) { - RAW_READ_INFO rri; + RAW_READ_INFO rri; - DWORD size=0; + DWORD size = 0; - if(!OpenOK) return -1; + if (!OpenOK) + return -1; - if (m_can_use_spti) - { - struct sptdinfo - { - SCSI_PASS_THROUGH_DIRECT info; - char sense_buffer[20]; - } sptd = {}; + if (m_can_use_spti) { + struct sptdinfo + { + SCSI_PASS_THROUGH_DIRECT info; + char sense_buffer[20]; + } sptd = {}; - // READ CD command - sptd.info.Cdb[0] = 0xBE; - // Don't care about sector type. - sptd.info.Cdb[1] = 0; - sptd.info.Cdb[2] = (sector >> 24) & 0xFF; - sptd.info.Cdb[3] = (sector >> 16) & 0xFF; - sptd.info.Cdb[4] = (sector >> 8) & 0xFF; - sptd.info.Cdb[5] = sector & 0xFF; - sptd.info.Cdb[6] = (count >> 16) & 0xFF; - sptd.info.Cdb[7] = (count >> 8) & 0xFF; - sptd.info.Cdb[8] = count & 0xFF; - // Sync + all headers + user data + EDC/ECC. Excludes C2 + subchannel - sptd.info.Cdb[9] = 0xF8; - sptd.info.Cdb[10] = 0; - sptd.info.Cdb[11] = 0; + // READ CD command + sptd.info.Cdb[0] = 0xBE; + // Don't care about sector type. + sptd.info.Cdb[1] = 0; + sptd.info.Cdb[2] = (sector >> 24) & 0xFF; + sptd.info.Cdb[3] = (sector >> 16) & 0xFF; + sptd.info.Cdb[4] = (sector >> 8) & 0xFF; + sptd.info.Cdb[5] = sector & 0xFF; + sptd.info.Cdb[6] = (count >> 16) & 0xFF; + sptd.info.Cdb[7] = (count >> 8) & 0xFF; + sptd.info.Cdb[8] = count & 0xFF; + // Sync + all headers + user data + EDC/ECC. Excludes C2 + subchannel + sptd.info.Cdb[9] = 0xF8; + sptd.info.Cdb[10] = 0; + sptd.info.Cdb[11] = 0; - sptd.info.CdbLength = 12; - sptd.info.Length = sizeof(SCSI_PASS_THROUGH_DIRECT); - sptd.info.DataIn = SCSI_IOCTL_DATA_IN; - sptd.info.DataTransferLength = 2352 * count; - sptd.info.DataBuffer = buffer; - sptd.info.SenseInfoLength = sizeof(sptd.sense_buffer); - sptd.info.SenseInfoOffset = offsetof(sptdinfo, sense_buffer); - sptd.info.TimeOutValue = 5; + sptd.info.CdbLength = 12; + sptd.info.Length = sizeof(SCSI_PASS_THROUGH_DIRECT); + sptd.info.DataIn = SCSI_IOCTL_DATA_IN; + sptd.info.DataTransferLength = 2352 * count; + sptd.info.DataBuffer = buffer; + sptd.info.SenseInfoLength = sizeof(sptd.sense_buffer); + sptd.info.SenseInfoOffset = offsetof(sptdinfo, sense_buffer); + sptd.info.TimeOutValue = 5; - if (DeviceIoControl(device, IOCTL_SCSI_PASS_THROUGH_DIRECT, &sptd, - sizeof(sptd), &sptd, sizeof(sptd), &size, nullptr)) - { - if (sptd.info.DataTransferLength == 2352 * count) - return 0; - } - printf(" * CDVD: SPTI failed reading sectors %u-%u\n", sector, sector + count - 1); - } + if (DeviceIoControl(device, IOCTL_SCSI_PASS_THROUGH_DIRECT, &sptd, + sizeof(sptd), &sptd, sizeof(sptd), &size, nullptr)) { + if (sptd.info.DataTransferLength == 2352 * count) + return 0; + } + printf(" * CDVD: SPTI failed reading sectors %u-%u\n", sector, sector + count - 1); + } - rri.DiskOffset.QuadPart=sector*(u64)2048; - rri.SectorCount=count; + rri.DiskOffset.QuadPart = sector * (u64)2048; + rri.SectorCount = count; - rri.TrackMode=(TRACK_MODE_TYPE)last_read_mode; - if(DeviceIoControl(device,IOCTL_CDROM_RAW_READ,&rri,sizeof(rri),buffer, 2352*count, &size, NULL)==0) - { - rri.TrackMode = XAForm2; - printf(" * CDVD: CD-ROM read mode change\n"); - printf(" * CDVD: Trying XAForm2\n"); - if(DeviceIoControl(device,IOCTL_CDROM_RAW_READ,&rri,sizeof(rri),buffer, 2352*count, &size, NULL)==0) - { - rri.TrackMode = YellowMode2; - printf(" * CDVD: Trying YellowMode2\n"); - if(DeviceIoControl(device,IOCTL_CDROM_RAW_READ,&rri,sizeof(rri),buffer, 2352*count, &size, NULL)==0) - { - rri.TrackMode = CDDA; - printf(" * CDVD: Trying CDDA\n"); - if(DeviceIoControl(device,IOCTL_CDROM_RAW_READ,&rri,sizeof(rri),buffer, 2352*count, &size, NULL)==0) - { - printf(" * CDVD: Failed to read this CD-ROM with error code: %d\n", GetLastError()); - return -1; - } - } - } - } + rri.TrackMode = (TRACK_MODE_TYPE)last_read_mode; + if (DeviceIoControl(device, IOCTL_CDROM_RAW_READ, &rri, sizeof(rri), buffer, 2352 * count, &size, NULL) == 0) { + rri.TrackMode = XAForm2; + printf(" * CDVD: CD-ROM read mode change\n"); + printf(" * CDVD: Trying XAForm2\n"); + if (DeviceIoControl(device, IOCTL_CDROM_RAW_READ, &rri, sizeof(rri), buffer, 2352 * count, &size, NULL) == 0) { + rri.TrackMode = YellowMode2; + printf(" * CDVD: Trying YellowMode2\n"); + if (DeviceIoControl(device, IOCTL_CDROM_RAW_READ, &rri, sizeof(rri), buffer, 2352 * count, &size, NULL) == 0) { + rri.TrackMode = CDDA; + printf(" * CDVD: Trying CDDA\n"); + if (DeviceIoControl(device, IOCTL_CDROM_RAW_READ, &rri, sizeof(rri), buffer, 2352 * count, &size, NULL) == 0) { + printf(" * CDVD: Failed to read this CD-ROM with error code: %d\n", GetLastError()); + return -1; + } + } + } + } - last_read_mode=rri.TrackMode; + last_read_mode = rri.TrackMode; - if(size!=(2352*count)) - { - return -1; - } + if (size != (2352 * count)) { + return -1; + } - return 0; + return 0; } s32 IOCtlSrc::DiscChanged() { - DWORD size=0; + DWORD size = 0; - if(!OpenOK) return -1; + if (!OpenOK) + return -1; - int ret = DeviceIoControl(device,IOCTL_STORAGE_CHECK_VERIFY,NULL,0,NULL,0, &size, NULL); + int ret = DeviceIoControl(device, IOCTL_STORAGE_CHECK_VERIFY, NULL, 0, NULL, 0, &size, NULL); - if(ret==0) - { - tocCached = false; - mediaTypeCached = false; - discSizeCached = false; - layerBreakCached = false; + if (ret == 0) { + tocCached = false; + mediaTypeCached = false; + discSizeCached = false; + layerBreakCached = false; - if(sessID!=0) - { - DeviceIoControl(device,IOCTL_DVD_END_SESSION,&sessID,sizeof(DVD_SESSION_ID),NULL,0,&size, NULL); - sessID=0; - } - return 1; - } + if (sessID != 0) { + DeviceIoControl(device, IOCTL_DVD_END_SESSION, &sessID, sizeof(DVD_SESSION_ID), NULL, 0, &size, NULL); + sessID = 0; + } + return 1; + } - if(sessID==0) - { - DeviceIoControl(device,IOCTL_DVD_START_SESSION,NULL,0,&sessID,sizeof(DVD_SESSION_ID), &size, NULL); - } + if (sessID == 0) { + DeviceIoControl(device, IOCTL_DVD_START_SESSION, NULL, 0, &sessID, sizeof(DVD_SESSION_ID), &size, NULL); + } - return 0; + return 0; } s32 IOCtlSrc::IsOK() { - return OpenOK; + return OpenOK; } diff --git a/plugins/cdvdGigaherz/src/Windows/config.cpp b/plugins/cdvdGigaherz/src/Windows/config.cpp index e9a0d7e719..ee044ba329 100644 --- a/plugins/cdvdGigaherz/src/Windows/config.cpp +++ b/plugins/cdvdGigaherz/src/Windows/config.cpp @@ -27,19 +27,19 @@ char source_drive; -char CfgFile[MAX_PATH+10] = "inis/cdvdGigaherz.ini"; +char CfgFile[MAX_PATH + 10] = "inis/cdvdGigaherz.ini"; -void CfgSetSettingsDir( const char* dir ) +void CfgSetSettingsDir(const char *dir) { - // a better std::string version, but it's inconvenient for other reasons. - //CfgFile = std::string(( dir == NULL ) ? "inis/" : dir) + "cdvdGigaherz.ini"; + // a better std::string version, but it's inconvenient for other reasons. + //CfgFile = std::string(( dir == NULL ) ? "inis/" : dir) + "cdvdGigaherz.ini"; - strcpy_s(CfgFile, (dir==NULL) ? "inis" : dir); - strcat_s(CfgFile, "/cdvdGigaherz.ini"); + strcpy_s(CfgFile, (dir == NULL) ? "inis" : dir); + strcat_s(CfgFile, "/cdvdGigaherz.ini"); } - /*| Config File Format: |ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ*\ +/*| Config File Format: |ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ*\ +--+---------------------+------------------------+ | | | Option=Value | @@ -54,166 +54,172 @@ void CfgSetSettingsDir( const char* dir ) \*_____________________________________________*/ -void CfgWriteBool(char *Section, char*Name, char Value) { - char *Data=Value?"TRUE":"FALSE"; +void CfgWriteBool(char *Section, char *Name, char Value) +{ + char *Data = Value ? "TRUE" : "FALSE"; - WritePrivateProfileString(Section,Name,Data,CfgFile); + WritePrivateProfileString(Section, Name, Data, CfgFile); } -void CfgWriteInt(char *Section, char*Name, int Value) { - char Data[255]; - _itoa(Value,Data,10); +void CfgWriteInt(char *Section, char *Name, int Value) +{ + char Data[255]; + _itoa(Value, Data, 10); - WritePrivateProfileString(Section,Name,Data,CfgFile); + WritePrivateProfileString(Section, Name, Data, CfgFile); } -void CfgWriteStr(char *Section, char*Name,char *Data) { - WritePrivateProfileString(Section,Name,Data,CfgFile); +void CfgWriteStr(char *Section, char *Name, char *Data) +{ + WritePrivateProfileString(Section, Name, Data, CfgFile); } /*****************************************************************************/ -char CfgReadBool(char *Section,char *Name,char Default) { - char Data[255]=""; - GetPrivateProfileString(Section,Name,"",Data,255,CfgFile); - Data[254]=0; - if(strlen(Data)==0) { - CfgWriteBool(Section,Name,Default); - return Default; - } +char CfgReadBool(char *Section, char *Name, char Default) +{ + char Data[255] = ""; + GetPrivateProfileString(Section, Name, "", Data, 255, CfgFile); + Data[254] = 0; + if (strlen(Data) == 0) { + CfgWriteBool(Section, Name, Default); + return Default; + } - if(strcmp(Data,"1")==0) return -1; - if(strcmp(Data,"Y")==0) return -1; - if(strcmp(Data,"T")==0) return -1; - if(strcmp(Data,"YES")==0) return -1; - if(strcmp(Data,"TRUE")==0) return -1; - return 0; + if (strcmp(Data, "1") == 0) + return -1; + if (strcmp(Data, "Y") == 0) + return -1; + if (strcmp(Data, "T") == 0) + return -1; + if (strcmp(Data, "YES") == 0) + return -1; + if (strcmp(Data, "TRUE") == 0) + return -1; + return 0; } -int CfgReadInt(char *Section, char*Name,int Default) { - char Data[255]=""; - GetPrivateProfileString(Section,Name,"",Data,255,CfgFile); - Data[254]=0; +int CfgReadInt(char *Section, char *Name, int Default) +{ + char Data[255] = ""; + GetPrivateProfileString(Section, Name, "", Data, 255, CfgFile); + Data[254] = 0; - if(strlen(Data)==0) { - CfgWriteInt(Section,Name,Default); - return Default; - } + if (strlen(Data) == 0) { + CfgWriteInt(Section, Name, Default); + return Default; + } - return atoi(Data); + return atoi(Data); } -void CfgReadStr(char *Section, char*Name,char *Data,int DataSize,char *Default) { - int sl; - GetPrivateProfileString(Section,Name,"",Data,DataSize,CfgFile); +void CfgReadStr(char *Section, char *Name, char *Data, int DataSize, char *Default) +{ + int sl; + GetPrivateProfileString(Section, Name, "", Data, DataSize, CfgFile); - if(strlen(Data)==0) { - sl=(int)strlen(Default); - strncpy(Data,Default,sl>255?255:sl); - CfgWriteStr(Section,Name,Data); - } + if (strlen(Data) == 0) { + sl = (int)strlen(Default); + strncpy(Data, Default, sl > 255 ? 255 : sl); + CfgWriteStr(Section, Name, Data); + } } /*****************************************************************************/ void ReadSettings() { - char temp[512]; + char temp[512]; - CfgReadStr("Config","Source",temp,511,"-"); - source_drive=temp[0]; + CfgReadStr("Config", "Source", temp, 511, "-"); + source_drive = temp[0]; } /*****************************************************************************/ void WriteSettings() { - char temp[2]; + char temp[2]; - temp[0]=source_drive; - temp[1]=0; + temp[0] = source_drive; + temp[1] = 0; - CfgWriteStr("Config","Source",temp); + CfgWriteStr("Config", "Source", temp); } -char* path[] = { - "A:","B:","C:","D:","E:","F:","G:","H:","I:","J:","K:","L:","M:", - "N:","O:","P:","Q:","R:","S:","T:","U:","V:","W:","X:","Y:","Z:", +char *path[] = { + "A:", "B:", "C:", "D:", "E:", "F:", "G:", "H:", "I:", "J:", "K:", "L:", "M:", + "N:", "O:", "P:", "Q:", "R:", "S:", "T:", "U:", "V:", "W:", "X:", "Y:", "Z:", }; -int n,s; +int n, s; -BOOL CALLBACK ConfigProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam) +BOOL CALLBACK ConfigProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { - int wmId,wmEvent; - char temp[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + int wmId, wmEvent; + char temp[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - switch(uMsg) - { + switch (uMsg) { - case WM_PAINT: - return FALSE; - case WM_INITDIALOG: + case WM_PAINT: + return FALSE; + case WM_INITDIALOG: - n=0;s=0; + n = 0; + s = 0; - SendMessage(GetDlgItem(hWnd,IDC_DRIVE),CB_RESETCONTENT,0,0); - SendMessage(GetDlgItem(hWnd,IDC_DRIVE),CB_ADDSTRING,0,(LPARAM)"@ (No disc)"); - for(char d='A';d<='Z';d++) - { - if(GetDriveType(path[d-'A'])==DRIVE_CDROM) - { - n++; + SendMessage(GetDlgItem(hWnd, IDC_DRIVE), CB_RESETCONTENT, 0, 0); + SendMessage(GetDlgItem(hWnd, IDC_DRIVE), CB_ADDSTRING, 0, (LPARAM) "@ (No disc)"); + for (char d = 'A'; d <= 'Z'; d++) { + if (GetDriveType(path[d - 'A']) == DRIVE_CDROM) { + n++; - SendMessage(GetDlgItem(hWnd,IDC_DRIVE),CB_ADDSTRING,0,(LPARAM)path[d-'A']); + SendMessage(GetDlgItem(hWnd, IDC_DRIVE), CB_ADDSTRING, 0, (LPARAM)path[d - 'A']); - if(source_drive==d) - { - s=n; - } - } - } + if (source_drive == d) { + s = n; + } + } + } - SendMessage(GetDlgItem(hWnd,IDC_DRIVE),CB_SETCURSEL,s,0); + SendMessage(GetDlgItem(hWnd, IDC_DRIVE), CB_SETCURSEL, s, 0); - break; - case WM_COMMAND: - wmId = LOWORD(wParam); - wmEvent = HIWORD(wParam); - // Parse the menu selections: - switch (wmId) - { - case IDOK: - GetDlgItemText(hWnd,IDC_DRIVE,temp,20); - temp[19]=0; - source_drive=temp[0]; + break; + case WM_COMMAND: + wmId = LOWORD(wParam); + wmEvent = HIWORD(wParam); + // Parse the menu selections: + switch (wmId) { + case IDOK: + GetDlgItemText(hWnd, IDC_DRIVE, temp, 20); + temp[19] = 0; + source_drive = temp[0]; - WriteSettings(); - EndDialog(hWnd,0); - break; - case IDCANCEL: - EndDialog(hWnd,0); - break; + WriteSettings(); + EndDialog(hWnd, 0); + break; + case IDCANCEL: + EndDialog(hWnd, 0); + break; - default: - return FALSE; - } - break; - default: - return FALSE; - } - return TRUE; + default: + return FALSE; + } + break; + default: + return FALSE; + } + return TRUE; } void configure() { - INT_PTR ret; - ReadSettings(); - ret=DialogBoxParam(hinst,MAKEINTRESOURCE(IDD_CONFIG),GetActiveWindow(),(DLGPROC)ConfigProc,1); - if(ret==-1) - { - MessageBoxEx(GetActiveWindow(),"Error Opening the config dialog.","OMG ERROR!",MB_OK,0); - return; - } - ReadSettings(); + INT_PTR ret; + ReadSettings(); + ret = DialogBoxParam(hinst, MAKEINTRESOURCE(IDD_CONFIG), GetActiveWindow(), (DLGPROC)ConfigProc, 1); + if (ret == -1) { + MessageBoxEx(GetActiveWindow(), "Error Opening the config dialog.", "OMG ERROR!", MB_OK, 0); + return; + } + ReadSettings(); }