cdvdgigaherz: Reformat with clang-format

This commit is contained in:
Clang Format 2016-09-19 18:24:54 +01:00 committed by Jonathan Li
parent 60da39712c
commit 2967d5d3f1
6 changed files with 1197 additions and 1268 deletions

View File

@ -21,7 +21,7 @@ void (*newDiscCB)();
HANDLE hThread_keepAlive = nullptr; HANDLE hThread_keepAlive = nullptr;
HANDLE hNotify_keepAlive = nullptr; HANDLE hNotify_keepAlive = nullptr;
DWORD pidThreadKeepAlive = 0; DWORD pidThreadKeepAlive = 0;
#define STRFY(x) #x #define STRFY(x) #x
#define TOSTR(x) STRFY(x) #define TOSTR(x) STRFY(x)
@ -44,15 +44,15 @@ int cmode;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Plugin Interface // // Plugin Interface //
char *LibName = "cdvdGigaherz " char *LibName = "cdvdGigaherz "
#ifdef PCSX2_DEBUG #ifdef PCSX2_DEBUG
" Debug " " Debug "
#endif #endif
"(" TOSTR(SVN_REV) "(" TOSTR(SVN_REV)
#if SVN_MODS #if SVN_MODS
"/modded" "/modded"
#endif #endif
")"; ")";
const unsigned char version = PS2E_CDVD_VERSION; const unsigned char version = PS2E_CDVD_VERSION;
const unsigned char revision = 0; const unsigned char revision = 0;
@ -61,62 +61,67 @@ const unsigned char build = 10;
HINSTANCE hinst; HINSTANCE hinst;
BOOL WINAPI DllMain( BOOL WINAPI DllMain(
HINSTANCE hinstDLL, // handle to DLL module HINSTANCE hinstDLL, // handle to DLL module
DWORD fdwReason, // reason for calling function DWORD fdwReason, // reason for calling function
LPVOID lpvReserved // reserved LPVOID lpvReserved // reserved
) )
{ {
if(fdwReason==DLL_PROCESS_ATTACH) { if (fdwReason == DLL_PROCESS_ATTACH) {
hinst=hinstDLL; hinst = hinstDLL;
} }
return TRUE; return TRUE;
} }
char* CALLBACK PS2EgetLibName() { char *CALLBACK PS2EgetLibName()
return LibName; {
return LibName;
} }
u32 CALLBACK PS2EgetLibType() { u32 CALLBACK PS2EgetLibType()
return PS2E_LT_CDVD; {
return PS2E_LT_CDVD;
} }
u32 CALLBACK PS2EgetLibVersion2(u32 type) { u32 CALLBACK PS2EgetLibVersion2(u32 type)
return (version << 16) | (revision << 8) | build; {
return (version << 16) | (revision << 8) | build;
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Utility Functions // // Utility Functions //
void SysMessage(char *fmt, ...) { void SysMessage(char *fmt, ...)
va_list list; {
char tmp[512]; va_list list;
char tmp[512];
va_start(list,fmt); va_start(list, fmt);
vsprintf(tmp,fmt,list); vsprintf(tmp, fmt, list);
va_end(list); va_end(list);
MessageBox(0, tmp, "cdvdGigaherz Msg", 0); MessageBox(0, tmp, "cdvdGigaherz Msg", 0);
} }
u8 __inline dec_to_bcd(u8 dec) 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); *frame = dec_to_bcd(lsn % 75);
lsn/=75; lsn /= 75;
*second= dec_to_bcd(lsn%60); *second = dec_to_bcd(lsn % 60);
lsn/=60; lsn /= 60;
*minute= dec_to_bcd(lsn%100); *minute = dec_to_bcd(lsn % 100);
} }
void __inline lba_to_msf(s32 lba, u8* m, u8* s, u8* f) { void __inline lba_to_msf(s32 lba, u8 *m, u8 *s, u8 *f)
lba += 150; {
*m = (u8)(lba / (60*75)); lba += 150;
*s = (u8)((lba / 75) % 60); *m = (u8)(lba / (60 * 75));
*f = (u8)(lba % 75); *s = (u8)((lba / 75) % 60);
*f = (u8)(lba % 75);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -142,446 +147,437 @@ extern s32 prefetch_last_mode;
DWORD CALLBACK keepAliveThread(PVOID param) DWORD CALLBACK keepAliveThread(PVOID param)
{ {
printf(" * CDVD: KeepAlive thread started...\n"); printf(" * CDVD: KeepAlive thread started...\n");
while (cdvdKeepAlive_is_open) while (cdvdKeepAlive_is_open) {
{ // Sleep 30 seconds with thread abort check
// Sleep 30 seconds with thread abort check if (WaitForSingleObject(hNotify_keepAlive, 30000) != WAIT_TIMEOUT)
if (WaitForSingleObject(hNotify_keepAlive, 30000) != WAIT_TIMEOUT) break; break;
if (!cdvdKeepAlive_is_open) { if (!cdvdKeepAlive_is_open) {
break; break;
} }
//printf(" * keepAliveThread: polling drive.\n"); //printf(" * keepAliveThread: polling drive.\n");
//if (prefetch_last_mode == CDVD_MODE_2048) //if (prefetch_last_mode == CDVD_MODE_2048)
src->ReadSectors2048(prefetch_last_lba, 1, throwaway); src->ReadSectors2048(prefetch_last_lba, 1, throwaway);
//else //else
// src->ReadSectors2352(prefetch_last_lba, 1, throwaway); // src->ReadSectors2352(prefetch_last_lba, 1, throwaway);
} }
printf(" * CDVD: KeepAlive thread finished.\n"); printf(" * CDVD: KeepAlive thread finished.\n");
return 0; return 0;
} }
s32 StartKeepAliveThread() s32 StartKeepAliveThread()
{ {
hNotify_keepAlive = CreateEvent(NULL, FALSE, FALSE, NULL); hNotify_keepAlive = CreateEvent(NULL, FALSE, FALSE, NULL);
if (hNotify_keepAlive == nullptr) if (hNotify_keepAlive == nullptr)
return -1; return -1;
cdvdKeepAlive_is_open = true; cdvdKeepAlive_is_open = true;
hThread_keepAlive = CreateThread(NULL, 0, keepAliveThread, NULL, 0, &pidThreadKeepAlive); hThread_keepAlive = CreateThread(NULL, 0, keepAliveThread, NULL, 0, &pidThreadKeepAlive);
if (hThread_keepAlive == nullptr) { if (hThread_keepAlive == nullptr) {
cdvdKeepAlive_is_open = false; cdvdKeepAlive_is_open = false;
return -1; return -1;
} }
SetThreadPriority(hThread_keepAlive, THREAD_PRIORITY_NORMAL); SetThreadPriority(hThread_keepAlive, THREAD_PRIORITY_NORMAL);
return 0; return 0;
} }
void StopKeepAliveThread() void StopKeepAliveThread()
{ {
cdvdKeepAlive_is_open = false; cdvdKeepAlive_is_open = false;
PulseEvent(hNotify_keepAlive); PulseEvent(hNotify_keepAlive);
if (WaitForSingleObject(hThread_keepAlive, 5000) == WAIT_TIMEOUT) if (WaitForSingleObject(hThread_keepAlive, 5000) == WAIT_TIMEOUT) {
{ TerminateThread(hThread_keepAlive, 0);
TerminateThread(hThread_keepAlive, 0); }
} CloseHandle(hThread_keepAlive);
CloseHandle(hThread_keepAlive); CloseHandle(hNotify_keepAlive);
CloseHandle(hNotify_keepAlive);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// CDVD Pluin Interface // // CDVD Pluin Interface //
void CALLBACK CDVDsetSettingsDir(const char* dir) void CALLBACK CDVDsetSettingsDir(const char *dir)
{ {
CfgSetSettingsDir(dir); CfgSetSettingsDir(dir);
} }
s32 CALLBACK CDVDinit() s32 CALLBACK CDVDinit()
{ {
return 0; return 0;
} }
s32 CALLBACK CDVDopen(const char* pTitleFilename) s32 CALLBACK CDVDopen(const char *pTitleFilename)
{ {
ReadSettings(); ReadSettings();
if(source_drive=='-') if (source_drive == '-') {
{ // MSDN : Trailing backslash is required to ensure consistent behavior across
// MSDN : Trailing backslash is required to ensure consistent behavior across // various versions of Windows and storage types.
// various versions of Windows and storage types. char temp[] = "A:\\";
char temp[]="A:\\";
for(char d='A';d<='Z';d++) for (char d = 'A'; d <= 'Z'; d++) {
{ temp[0] = d;
temp[0]=d; if (GetDriveType(temp) == DRIVE_CDROM) {
if(GetDriveType(temp)==DRIVE_CDROM) source_drive = d;
{ break;
source_drive=d; }
break; }
} }
}
}
if(source_drive=='@') if (source_drive == '@') {
{ curDiskType = CDVD_TYPE_NODISC;
curDiskType=CDVD_TYPE_NODISC; return 0;
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 // open device file
src = new IOCtlSrc(csrc); src = new IOCtlSrc(csrc);
if(!src->IsOK()) if (!src->IsOK()) {
{ printf(" * CDVD: Error opening source.\n");
printf(" * CDVD: Error opening source.\n"); return -1;
return -1; }
}
//setup threading manager //setup threading manager
cdvdStartThread(); cdvdStartThread();
StartKeepAliveThread(); StartKeepAliveThread();
return cdvdRefreshData(); return cdvdRefreshData();
} }
void CALLBACK CDVDclose() void CALLBACK CDVDclose()
{ {
StopKeepAliveThread(); StopKeepAliveThread();
cdvdStopThread(); cdvdStopThread();
//close device //close device
delete src; delete src;
src=NULL; src = NULL;
} }
void CALLBACK CDVDshutdown() 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()) switch (src->GetMediaType()) {
{ case 1:
case 1: *dualType = 1;
*dualType = 1; *_layer1start = src->GetLayerBreakAddress() + 1;
*_layer1start = src->GetLayerBreakAddress() + 1; return 0;
return 0; case 2:
case 2: *dualType = 2;
*dualType = 2; *_layer1start = src->GetLayerBreakAddress() + 1;
*_layer1start = src->GetLayerBreakAddress() + 1; return 0;
return 0; case 0:
case 0: *dualType = 0;
*dualType = 0; *_layer1start = 0;
*_layer1start = 0; return 0;
return 0; }
} return -1;
return -1;
} }
int lastReadInNewDiskCB=0; int lastReadInNewDiskCB = 0;
char directReadSectorBuffer[2448]; 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) s32 CALLBACK CDVDreadTrack(u32 lsn, int mode)
{ {
csector=lsn; csector = lsn;
cmode=mode; cmode = mode;
if(weAreInNewDiskCB) if (weAreInNewDiskCB) {
{ int ret = cdvdDirectReadSector(lsn, mode, directReadSectorBuffer);
int ret = cdvdDirectReadSector(lsn,mode,directReadSectorBuffer); if (ret == 0)
if(ret==0) lastReadInNewDiskCB=1; lastReadInNewDiskCB = 1;
return ret; return ret;
} }
if(lsn>tracks[0].length) // track 0 is total disc. if (lsn > tracks[0].length) { // track 0 is total disc.
{ return -1;
return -1; }
}
return cdvdRequestSector(lsn,mode); return cdvdRequestSector(lsn, mode);
} }
// return can be NULL (for async modes) // return can be NULL (for async modes)
u8* CALLBACK CDVDgetBuffer() u8 *CALLBACK CDVDgetBuffer()
{ {
if(lastReadInNewDiskCB) if (lastReadInNewDiskCB) {
{ lastReadInNewDiskCB = 0;
lastReadInNewDiskCB=0; return (u8 *)directReadSectorBuffer;
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) // return can be NULL (for async modes)
int CALLBACK CDVDgetBuffer2(u8* dest) int CALLBACK CDVDgetBuffer2(u8 *dest)
{ {
int csize = 2352; int csize = 2352;
switch(cmode) switch (cmode) {
{ case CDVD_MODE_2048:
case CDVD_MODE_2048: csize = 2048; break; csize = 2048;
case CDVD_MODE_2328: csize = 2328; break; break;
case CDVD_MODE_2340: csize = 2340; break; case CDVD_MODE_2328:
} csize = 2328;
break;
case CDVD_MODE_2340:
csize = 2340;
break;
}
if(lastReadInNewDiskCB) if (lastReadInNewDiskCB) {
{ lastReadInNewDiskCB = 0;
lastReadInNewDiskCB=0;
memcpy(dest, directReadSectorBuffer, csize); memcpy(dest, directReadSectorBuffer, csize);
return 0; 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; int i;
// the formatted subq command returns: control/adr, track, index, trk min, trk sec, trk frm, 0x00, abs min, abs sec, abs frm // 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. if (lsn > tracks[0].length) // track 0 is total disc.
return -1; 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; i = strack;
while(i<=etrack) while (i <= etrack) {
{ if (lsn <= tracks[i].length)
if(lsn<=tracks[i].length) break;
break; lsn -= tracks[i].length;
lsn-=tracks[i].length; i++;
i++; }
}
if(i>etrack) if (i > etrack)
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->mode = 1;
subq->ctrl=tracks[i].type; subq->ctrl = tracks[i].type;
subq->trackNum=i; subq->trackNum = i;
subq->trackIndex=1; subq->trackIndex = 1;
return 0; return 0;
} }
s32 CALLBACK CDVDgetTN(cdvdTN *Buffer) s32 CALLBACK CDVDgetTN(cdvdTN *Buffer)
{ {
Buffer->strack=strack; Buffer->strack = strack;
Buffer->etrack=etrack; Buffer->etrack = etrack;
return 0; return 0;
} }
s32 CALLBACK CDVDgetTD(u8 Track, cdvdTD *Buffer) s32 CALLBACK CDVDgetTD(u8 Track, cdvdTD *Buffer)
{ {
if(Track==0) if (Track == 0) {
{ Buffer->lsn = tracks[0].length;
Buffer->lsn = tracks[0].length; Buffer->type = 0;
Buffer->type= 0; return 0;
return 0; }
}
if(Track<strack) return -1; if (Track < strack)
if(Track>etrack) return -1; return -1;
if (Track > etrack)
return -1;
Buffer->lsn = tracks[Track].start_lba; Buffer->lsn = tracks[Track].start_lba;
Buffer->type= tracks[Track].type; Buffer->type = tracks[Track].type;
return 0; return 0;
} }
s32 CALLBACK CDVDgetTOC(u8* tocBuff) s32 CALLBACK CDVDgetTOC(u8 *tocBuff)
{ {
//return src->ReadTOC((char*)toc,2048); //return src->ReadTOC((char*)toc,2048);
//that didn't work too well... //that didn't work too well...
if (curDiskType == CDVD_TYPE_NODISC) if (curDiskType == CDVD_TYPE_NODISC)
return -1; return -1;
if (curDiskType == CDVD_TYPE_DETCTDVDS || curDiskType == CDVD_TYPE_DETCTDVDD) if (curDiskType == CDVD_TYPE_DETCTDVDS || curDiskType == CDVD_TYPE_DETCTDVDD) {
{ memset(tocBuff, 0, 2048);
memset(tocBuff, 0, 2048);
s32 mt=src->GetMediaType(); s32 mt = src->GetMediaType();
if(mt<0) if (mt < 0)
return -1; return -1;
if(mt==0) //single layer if (mt == 0) { //single layer
{ // fake it
// fake it tocBuff[0] = 0x04;
tocBuff[ 0] = 0x04; tocBuff[1] = 0x02;
tocBuff[ 1] = 0x02; tocBuff[2] = 0xF2;
tocBuff[ 2] = 0xF2; tocBuff[3] = 0x00;
tocBuff[ 3] = 0x00; tocBuff[4] = 0x86;
tocBuff[ 4] = 0x86; tocBuff[5] = 0x72;
tocBuff[ 5] = 0x72;
tocBuff[16] = 0x00; // first sector for layer 0 tocBuff[16] = 0x00; // first sector for layer 0
tocBuff[17] = 0x03; tocBuff[17] = 0x03;
tocBuff[18] = 0x00; tocBuff[18] = 0x00;
tocBuff[19] = 0x00; tocBuff[19] = 0x00;
} } else if (mt == 1) { //PTP
else if(mt==1) //PTP u32 layer1start = src->GetLayerBreakAddress() + 0x30000;
{
u32 layer1start = src->GetLayerBreakAddress() + 0x30000;
// dual sided // dual sided
tocBuff[ 0] = 0x24; tocBuff[0] = 0x24;
tocBuff[ 1] = 0x02; tocBuff[1] = 0x02;
tocBuff[ 2] = 0xF2; tocBuff[2] = 0xF2;
tocBuff[ 3] = 0x00; tocBuff[3] = 0x00;
tocBuff[ 4] = 0x41; tocBuff[4] = 0x41;
tocBuff[ 5] = 0x95; tocBuff[5] = 0x95;
tocBuff[14] = 0x61; // PTP tocBuff[14] = 0x61; // PTP
tocBuff[16] = 0x00; tocBuff[16] = 0x00;
tocBuff[17] = 0x03; tocBuff[17] = 0x03;
tocBuff[18] = 0x00; tocBuff[18] = 0x00;
tocBuff[19] = 0x00; tocBuff[19] = 0x00;
tocBuff[20] = (layer1start>>24); tocBuff[20] = (layer1start >> 24);
tocBuff[21] = (layer1start>>16)&0xff; tocBuff[21] = (layer1start >> 16) & 0xff;
tocBuff[22] = (layer1start>> 8)&0xff; tocBuff[22] = (layer1start >> 8) & 0xff;
tocBuff[23] = (layer1start>> 0)&0xff; tocBuff[23] = (layer1start >> 0) & 0xff;
} } else { //OTP
else //OTP u32 layer1start = src->GetLayerBreakAddress() + 0x30000;
{
u32 layer1start = src->GetLayerBreakAddress() + 0x30000;
// dual sided // dual sided
tocBuff[ 0] = 0x24; tocBuff[0] = 0x24;
tocBuff[ 1] = 0x02; tocBuff[1] = 0x02;
tocBuff[ 2] = 0xF2; tocBuff[2] = 0xF2;
tocBuff[ 3] = 0x00; tocBuff[3] = 0x00;
tocBuff[ 4] = 0x41; tocBuff[4] = 0x41;
tocBuff[ 5] = 0x95; tocBuff[5] = 0x95;
tocBuff[14] = 0x71; // OTP tocBuff[14] = 0x71; // OTP
tocBuff[16] = 0x00; tocBuff[16] = 0x00;
tocBuff[17] = 0x03; tocBuff[17] = 0x03;
tocBuff[18] = 0x00; tocBuff[18] = 0x00;
tocBuff[19] = 0x00; tocBuff[19] = 0x00;
tocBuff[24] = (layer1start>>24); tocBuff[24] = (layer1start >> 24);
tocBuff[25] = (layer1start>>16)&0xff; tocBuff[25] = (layer1start >> 16) & 0xff;
tocBuff[26] = (layer1start>> 8)&0xff; tocBuff[26] = (layer1start >> 8) & 0xff;
tocBuff[27] = (layer1start>> 0)&0xff; tocBuff[27] = (layer1start >> 0) & 0xff;
} }
} } else if (curDiskType == CDVD_TYPE_DETCTCD) {
else if (curDiskType == CDVD_TYPE_DETCTCD) // cd toc
{ // (could be replaced by 1 command that reads the full toc)
// cd toc u8 min, sec, frm, i;
// (could be replaced by 1 command that reads the full toc) s32 err;
u8 min, sec, frm,i; cdvdTN diskInfo;
s32 err; cdvdTD trackInfo;
cdvdTN diskInfo; memset(tocBuff, 0, 1024);
cdvdTD trackInfo; if (CDVDgetTN(&diskInfo) == -1) {
memset(tocBuff, 0, 1024); diskInfo.etrack = 0;
if (CDVDgetTN(&diskInfo) == -1) { diskInfo.etrack = 0;diskInfo.strack = 1; } diskInfo.strack = 1;
if (CDVDgetTD(0, &trackInfo) == -1) trackInfo.lsn = 0; }
if (CDVDgetTD(0, &trackInfo) == -1)
trackInfo.lsn = 0;
tocBuff[0] = 0x41; tocBuff[0] = 0x41;
tocBuff[1] = 0x00; tocBuff[1] = 0x00;
#define itob(n) ((((n)/10)<<4)+((n)%10)) #define itob(n) ((((n) / 10) << 4) + ((n) % 10))
//Number of FirstTrack //Number of FirstTrack
tocBuff[2] = 0xA0; tocBuff[2] = 0xA0;
tocBuff[7] = itob(diskInfo.strack); tocBuff[7] = itob(diskInfo.strack);
//Number of LastTrack //Number of LastTrack
tocBuff[12] = 0xA1; tocBuff[12] = 0xA1;
tocBuff[17] = itob(diskInfo.etrack); tocBuff[17] = itob(diskInfo.etrack);
//DiskLength //DiskLength
lba_to_msf(trackInfo.lsn, &min, &sec, &frm); lba_to_msf(trackInfo.lsn, &min, &sec, &frm);
tocBuff[22] = 0xA2; tocBuff[22] = 0xA2;
tocBuff[27] = itob(min); tocBuff[27] = itob(min);
tocBuff[28] = itob(sec); tocBuff[28] = itob(sec);
tocBuff[29] = itob(frm); 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++) for (i = diskInfo.strack; i <= diskInfo.etrack; i++) {
{ err = CDVDgetTD(i, &trackInfo);
err = CDVDgetTD(i, &trackInfo); lba_to_msf(trackInfo.lsn, &min, &sec, &frm);
lba_to_msf(trackInfo.lsn, &min, &sec, &frm); tocBuff[i * 10 + 30] = trackInfo.type;
tocBuff[i*10+30] = trackInfo.type; tocBuff[i * 10 + 32] = err == -1 ? 0 : itob(i); //number
tocBuff[i*10+32] = err == -1 ? 0 : itob(i); //number tocBuff[i * 10 + 37] = itob(min);
tocBuff[i*10+37] = itob(min); tocBuff[i * 10 + 38] = itob(sec);
tocBuff[i*10+38] = itob(sec); tocBuff[i * 10 + 39] = itob(frm);
tocBuff[i*10+39] = itob(frm); fprintf(stderr, "Track %d: %d mins %d secs %d frames\n", i, min, sec, frm);
fprintf(stderr,"Track %d: %d mins %d secs %d frames\n",i,min,sec,frm); }
} } else
} return -1;
else
return -1;
return 0; return 0;
} }
s32 CALLBACK CDVDgetDiskType() s32 CALLBACK CDVDgetDiskType()
{ {
return curDiskType; return curDiskType;
} }
s32 CALLBACK CDVDgetTrayStatus() s32 CALLBACK CDVDgetTrayStatus()
{ {
return curTrayStatus; return curTrayStatus;
} }
s32 CALLBACK CDVDctrlTrayOpen() s32 CALLBACK CDVDctrlTrayOpen()
{ {
curTrayStatus=CDVD_TRAY_OPEN; curTrayStatus = CDVD_TRAY_OPEN;
return 0; return 0;
} }
s32 CALLBACK CDVDctrlTrayClose() s32 CALLBACK CDVDctrlTrayClose()
{ {
curTrayStatus=CDVD_TRAY_CLOSE; curTrayStatus = CDVD_TRAY_CLOSE;
return 0; return 0;
} }
void CALLBACK CDVDnewDiskCB(void (*callback)()) void CALLBACK CDVDnewDiskCB(void (*callback)())
{ {
newDiscCB=callback; newDiscCB = callback;
} }
void CALLBACK CDVDconfigure() void CALLBACK CDVDconfigure()
{ {
configure(); configure();
} }
void CALLBACK CDVDabout() { void CALLBACK CDVDabout()
SysMessage("%s %d.%d", LibName, revision, build); {
SysMessage("%s %d.%d", LibName, revision, build);
} }
s32 CALLBACK CDVDtest() { s32 CALLBACK CDVDtest()
return 0; {
return 0;
} }

View File

@ -25,9 +25,9 @@
typedef struct _track typedef struct _track
{ {
u32 start_lba; u32 start_lba;
u32 length; u32 length;
u32 type; u32 type;
} track; } track;
extern int strack; extern int strack;
@ -37,10 +37,11 @@ extern track tracks[100];
extern int curDiskType; extern int curDiskType;
extern int curTrayStatus; extern int curTrayStatus;
typedef struct _toc_entry { typedef struct _toc_entry
{
UCHAR SessionNumber; UCHAR SessionNumber;
UCHAR Control : 4; UCHAR Control : 4;
UCHAR Adr : 4; UCHAR Adr : 4;
UCHAR Reserved1; UCHAR Reserved1;
UCHAR Point; UCHAR Point;
UCHAR MsfExtra[3]; UCHAR MsfExtra[3];
@ -59,82 +60,83 @@ typedef struct _toc_data
extern toc_data cdtoc; 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: public:
Source(){}; Source(){};
//virtual destructor //virtual destructor
virtual ~Source() virtual ~Source()
{ {
} }
//virtual members //virtual members
virtual s32 GetSectorCount()=0; virtual s32 GetSectorCount() = 0;
virtual s32 ReadTOC(char *toc,int size)=0; virtual s32 ReadTOC(char *toc, int size) = 0;
virtual s32 ReadSectors2048(u32 sector, u32 count, char *buffer)=0; virtual s32 ReadSectors2048(u32 sector, u32 count, char *buffer) = 0;
virtual s32 ReadSectors2352(u32 sector, u32 count, char *buffer)=0; virtual s32 ReadSectors2352(u32 sector, u32 count, char *buffer) = 0;
virtual s32 GetLayerBreakAddress()=0; virtual s32 GetLayerBreakAddress() = 0;
virtual s32 GetMediaType()=0; virtual s32 GetMediaType() = 0;
virtual s32 IsOK()=0; virtual s32 IsOK() = 0;
virtual s32 Reopen()=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; HANDLE device;
bool m_can_use_spti; bool m_can_use_spti;
bool OpenOK; 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; bool tocCached;
char tocCacheData[2048]; char tocCacheData[2048];
bool mediaTypeCached; bool mediaTypeCached;
int mediaType; int mediaType;
bool discSizeCached; bool discSizeCached;
s32 discSize; s32 discSize;
bool layerBreakCached; bool layerBreakCached;
s32 layerBreak; s32 layerBreak;
public: public:
IOCtlSrc(const char* fileName); IOCtlSrc(const char *fileName);
//virtual destructor //virtual destructor
virtual ~IOCtlSrc(); virtual ~IOCtlSrc();
//virtual members //virtual members
virtual s32 GetSectorCount(); virtual s32 GetSectorCount();
virtual s32 ReadTOC(char *toc,int size); virtual s32 ReadTOC(char *toc, int size);
virtual s32 ReadSectors2048(u32 sector, u32 count, char *buffer); virtual s32 ReadSectors2048(u32 sector, u32 count, char *buffer);
virtual s32 ReadSectors2352(u32 sector, u32 count, char *buffer); virtual s32 ReadSectors2352(u32 sector, u32 count, char *buffer);
virtual s32 GetLayerBreakAddress(); virtual s32 GetLayerBreakAddress();
virtual s32 GetMediaType(); virtual s32 GetMediaType();
virtual void SetSpindleSpeed(bool restore_defaults); virtual void SetSpindleSpeed(bool restore_defaults);
virtual s32 IsOK(); virtual s32 IsOK();
virtual s32 Reopen(); virtual s32 Reopen();
virtual s32 DiscChanged(); virtual s32 DiscChanged();
}; };
extern Source *src; extern Source *src;
@ -145,7 +147,7 @@ extern char source_drive;
extern HINSTANCE hinst; 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); s32 cdvdDirectReadSector(s32 first, s32 mode, char *buffer);
@ -153,7 +155,7 @@ s32 cdvdGetMediaType();
void ReadSettings(); void ReadSettings();
void WriteSettings(); void WriteSettings();
void CfgSetSettingsDir( const char* dir ); void CfgSetSettingsDir(const char *dir);
extern char csrc[]; extern char csrc[];
extern bool cdvd_is_open; extern bool cdvd_is_open;
@ -167,7 +169,7 @@ s32 cdvdStartThread();
void cdvdStopThread(); void cdvdStopThread();
s32 cdvdRequestSector(u32 sector, s32 mode); s32 cdvdRequestSector(u32 sector, s32 mode);
s32 cdvdRequestComplete(); s32 cdvdRequestComplete();
char* cdvdGetSector(s32 sector, s32 mode); char *cdvdGetSector(s32 sector, s32 mode);
s32 cdvdDirectReadSector(s32 first, s32 mode, char *buffer); s32 cdvdDirectReadSector(s32 first, s32 mode, char *buffer);
s32 cdvdGetMediaType(); s32 cdvdGetMediaType();
s32 cdvdRefreshData(); s32 cdvdRefreshData();

View File

@ -15,11 +15,11 @@
#include "CDVD.h" #include "CDVD.h"
const s32 prefetch_max_blocks=16; const s32 prefetch_max_blocks = 16;
s32 prefetch_mode=0; s32 prefetch_mode = 0;
s32 prefetch_last_lba=0; s32 prefetch_last_lba = 0;
s32 prefetch_last_mode=0; s32 prefetch_last_mode = 0;
s32 prefetch_left=0; s32 prefetch_left = 0;
HANDLE hNotify = nullptr; HANDLE hNotify = nullptr;
HANDLE hThread = nullptr; HANDLE hThread = nullptr;
@ -27,431 +27,412 @@ HANDLE hRequestComplete = nullptr;
CRITICAL_SECTION CacheMutex; CRITICAL_SECTION CacheMutex;
DWORD pidThread= 0; DWORD pidThread = 0;
enum loadStatus enum loadStatus {
{ LoadIdle,
LoadIdle, LoadPending,
LoadPending, LoadSuccess,
LoadSuccess,
}; };
typedef struct typedef struct
{ {
int lsn; int lsn;
int mode; int mode;
char data[2352*16]; //we will read in blocks of 16 sectors char data[2352 * 16]; //we will read in blocks of 16 sectors
} SectorInfo; } SectorInfo;
//bits: 12 would use 1<<12 entries, or 4096*16 sectors ~ 128MB //bits: 12 would use 1<<12 entries, or 4096*16 sectors ~ 128MB
#define CACHE_SIZE 12 #define CACHE_SIZE 12
const s32 CacheSize=(1<<CACHE_SIZE); const s32 CacheSize = (1 << CACHE_SIZE);
SectorInfo Cache[CacheSize]; SectorInfo Cache[CacheSize];
bool threadRequestPending; bool threadRequestPending;
SectorInfo threadRequestInfo; SectorInfo threadRequestInfo;
u32 cdvdSectorHash(int lsn, int mode) u32 cdvdSectorHash(int lsn, int mode)
{ {
u32 t = 0; u32 t = 0;
int i=32; int i = 32;
int m=CacheSize-1; int m = CacheSize - 1;
while(i>=0) while (i >= 0) {
{ t ^= lsn & m;
t^=lsn&m; lsn >>= CACHE_SIZE;
lsn>>=CACHE_SIZE; i -= 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 ); EnterCriticalSection(&CacheMutex);
u32 entry = cdvdSectorHash(lsn,mode); u32 entry = cdvdSectorHash(lsn, mode);
memcpy(Cache[entry].data,data,2352*16); memcpy(Cache[entry].data, data, 2352 * 16);
Cache[entry].lsn = lsn; Cache[entry].lsn = lsn;
Cache[entry].mode = mode; Cache[entry].mode = mode;
LeaveCriticalSection( &CacheMutex ); LeaveCriticalSection(&CacheMutex);
} }
bool cdvdCacheFetch(int lsn, int mode, char* data) bool cdvdCacheFetch(int lsn, int mode, char *data)
{ {
EnterCriticalSection( &CacheMutex ); EnterCriticalSection(&CacheMutex);
u32 entry = cdvdSectorHash(lsn,mode); u32 entry = cdvdSectorHash(lsn, mode);
if((Cache[entry].lsn==lsn) && if ((Cache[entry].lsn == lsn) &&
(Cache[entry].mode==mode)) (Cache[entry].mode == mode)) {
{ memcpy(data, Cache[entry].data, 2352 * 16);
memcpy(data,Cache[entry].data,2352*16); LeaveCriticalSection(&CacheMutex);
LeaveCriticalSection( &CacheMutex ); return true;
return true; }
} //printf("NOT IN CACHE\n");
//printf("NOT IN CACHE\n"); LeaveCriticalSection(&CacheMutex);
LeaveCriticalSection( &CacheMutex ); return false;
return false;
} }
void cdvdCacheReset() void cdvdCacheReset()
{ {
EnterCriticalSection( &CacheMutex ); EnterCriticalSection(&CacheMutex);
for(int i=0;i<CacheSize;i++) for (int i = 0; i < CacheSize; i++) {
{ Cache[i].lsn = -1;
Cache[i].lsn=-1; Cache[i].mode = -1;
Cache[i].mode=-1; }
} LeaveCriticalSection(&CacheMutex);
LeaveCriticalSection( &CacheMutex );
} }
void cdvdCallNewDiscCB() void cdvdCallNewDiscCB()
{ {
weAreInNewDiskCB = true; weAreInNewDiskCB = true;
newDiscCB(); newDiscCB();
weAreInNewDiskCB = false; weAreInNewDiskCB = false;
} }
bool cdvdUpdateDiscStatus() bool cdvdUpdateDiscStatus()
{ {
int change = src->DiscChanged(); int change = src->DiscChanged();
if(change==-1) //error getting status (no disc in drive?) if (change == -1) { //error getting status (no disc in drive?)
{ //try to recreate the device
//try to recreate the device src->Reopen();
src->Reopen();
if(src->IsOK()) if (src->IsOK()) {
{ change = 1;
change = 1; } else {
} curDiskType = CDVD_TYPE_NODISC;
else curTrayStatus = CDVD_TRAY_OPEN;
{ return true;
curDiskType=CDVD_TYPE_NODISC; }
curTrayStatus=CDVD_TRAY_OPEN; }
return true;
}
}
if(change==1) if (change == 1) {
{ if (!disc_has_changed) {
if(!disc_has_changed) disc_has_changed = true;
{ curDiskType = CDVD_TYPE_NODISC;
disc_has_changed = true; curTrayStatus = CDVD_TRAY_OPEN;
curDiskType = CDVD_TYPE_NODISC; cdvdCallNewDiscCB();
curTrayStatus = CDVD_TRAY_OPEN; }
cdvdCallNewDiscCB(); } else {
} if (disc_has_changed) {
} curDiskType = CDVD_TYPE_NODISC;
else curTrayStatus = CDVD_TRAY_CLOSE;
{
if(disc_has_changed)
{
curDiskType = CDVD_TYPE_NODISC;
curTrayStatus = CDVD_TRAY_CLOSE;
// just a test // just a test
src->Reopen(); src->Reopen();
disc_has_changed = false; disc_has_changed = false;
cdvdRefreshData(); cdvdRefreshData();
cdvdCallNewDiscCB(); cdvdCallNewDiscCB();
} }
} }
return (change!=0); return (change != 0);
} }
DWORD CALLBACK cdvdThread(PVOID param) DWORD CALLBACK cdvdThread(PVOID param)
{ {
printf(" * CDVD: IO thread started...\n"); printf(" * CDVD: IO thread started...\n");
while(cdvd_is_open) while (cdvd_is_open) {
{ if (!src)
if(!src) break; break;
if(cdvdUpdateDiscStatus()) if (cdvdUpdateDiscStatus()) {
{ // Need to sleep some to avoid an aggressive spin that sucks the cpu dry.
// Need to sleep some to avoid an aggressive spin that sucks the cpu dry. Sleep(10);
Sleep( 10 ); continue;
continue; }
}
if(prefetch_left) if (prefetch_left)
WaitForSingleObject(hNotify,1); WaitForSingleObject(hNotify, 1);
else else
WaitForSingleObject(hNotify,250); WaitForSingleObject(hNotify, 250);
// check again to make sure we're not done here... // check again to make sure we're not done here...
if(!cdvd_is_open) break; if (!cdvd_is_open)
break;
static SectorInfo info; static SectorInfo info;
bool handlingRequest = false; bool handlingRequest = false;
if(threadRequestPending) if (threadRequestPending) {
{ info = threadRequestInfo;
info=threadRequestInfo; handlingRequest = true;
handlingRequest = true; } else {
} info.lsn = prefetch_last_lba;
else info.mode = prefetch_last_mode;
{ }
info.lsn = prefetch_last_lba;
info.mode = prefetch_last_mode;
}
if(threadRequestPending || prefetch_left) if (threadRequestPending || prefetch_left) {
{ s32 ret = -1;
s32 ret = -1; s32 tries = 5;
s32 tries=5;
s32 count = 16; s32 count = 16;
s32 left = tracks[0].length-info.lsn; s32 left = tracks[0].length - info.lsn;
if(left<count) count=left; if (left < count)
count = left;
do { do {
if(info.mode==CDVD_MODE_2048) if (info.mode == CDVD_MODE_2048)
ret = src->ReadSectors2048(info.lsn,count,info.data); ret = src->ReadSectors2048(info.lsn, count, info.data);
else else
ret = src->ReadSectors2352(info.lsn,count,info.data); ret = src->ReadSectors2352(info.lsn, count, info.data);
if(ret==0) if (ret == 0)
break; 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) if (handlingRequest) {
{ threadRequestInfo = info;
threadRequestInfo = info;
handlingRequest = false; handlingRequest = false;
threadRequestPending = false; threadRequestPending = false;
PulseEvent(hRequestComplete); PulseEvent(hRequestComplete);
prefetch_last_lba=info.lsn; prefetch_last_lba = info.lsn;
prefetch_last_mode=info.mode; prefetch_last_mode = info.mode;
prefetch_left = prefetch_max_blocks; prefetch_left = prefetch_max_blocks;
} } else {
else prefetch_last_lba += 16;
{ prefetch_left--;
prefetch_last_lba+=16; }
prefetch_left--; }
} }
} printf(" * CDVD: IO thread finished.\n");
} return 0;
printf(" * CDVD: IO thread finished.\n");
return 0;
} }
s32 cdvdStartThread() s32 cdvdStartThread()
{ {
InitializeCriticalSection( &CacheMutex ); InitializeCriticalSection(&CacheMutex);
hNotify = CreateEvent(NULL,FALSE,FALSE,NULL); hNotify = CreateEvent(NULL, FALSE, FALSE, NULL);
if(hNotify == nullptr) if (hNotify == nullptr)
return -1; return -1;
hRequestComplete = CreateEvent(NULL,FALSE,FALSE,NULL); hRequestComplete = CreateEvent(NULL, FALSE, FALSE, NULL);
if(hRequestComplete == nullptr) if (hRequestComplete == nullptr)
return -1; return -1;
cdvd_is_open=true; cdvd_is_open = true;
hThread = CreateThread(NULL,0,cdvdThread,NULL,0,&pidThread); hThread = CreateThread(NULL, 0, cdvdThread, NULL, 0, &pidThread);
if(hThread == nullptr) if (hThread == nullptr)
return -1; return -1;
SetThreadPriority(hThread,THREAD_PRIORITY_NORMAL); SetThreadPriority(hThread, THREAD_PRIORITY_NORMAL);
cdvdCacheReset(); cdvdCacheReset();
return 0; return 0;
} }
void cdvdStopThread() void cdvdStopThread()
{ {
cdvd_is_open=false; cdvd_is_open = false;
PulseEvent(hNotify); PulseEvent(hNotify);
if(WaitForSingleObject(hThread,4000)==WAIT_TIMEOUT) if (WaitForSingleObject(hThread, 4000) == WAIT_TIMEOUT) {
{ TerminateThread(hThread, 0);
TerminateThread(hThread,0); }
} CloseHandle(hThread);
CloseHandle(hThread); CloseHandle(hNotify);
CloseHandle(hNotify); CloseHandle(hRequestComplete);
CloseHandle(hRequestComplete);
DeleteCriticalSection( &CacheMutex ); DeleteCriticalSection(&CacheMutex);
} }
s32 cdvdRequestSector(u32 sector, s32 mode) s32 cdvdRequestSector(u32 sector, s32 mode)
{ {
if(sector>=tracks[0].length) if (sector >= tracks[0].length)
return -1; return -1;
sector&=~15; //align to 16-sector block sector &= ~15; //align to 16-sector block
threadRequestInfo.lsn = sector; threadRequestInfo.lsn = sector;
threadRequestInfo.mode = mode; threadRequestInfo.mode = mode;
threadRequestPending = false; threadRequestPending = false;
if(cdvdCacheFetch(sector,mode,threadRequestInfo.data)) if (cdvdCacheFetch(sector, mode, threadRequestInfo.data)) {
{ return 0;
return 0; }
}
threadRequestPending = true; threadRequestPending = true;
ResetEvent(hRequestComplete); ResetEvent(hRequestComplete);
PulseEvent(hNotify); PulseEvent(hNotify);
return 0; return 0;
} }
s32 cdvdRequestComplete() s32 cdvdRequestComplete()
{ {
return !threadRequestPending; return !threadRequestPending;
} }
s8* cdvdGetSector(s32 sector, s32 mode) s8 *cdvdGetSector(s32 sector, s32 mode)
{ {
while(threadRequestPending) while (threadRequestPending) {
{ WaitForSingleObject(hRequestComplete, 10);
WaitForSingleObject( hRequestComplete, 10 ); }
}
s32 offset; s32 offset;
if(mode==CDVD_MODE_2048) if (mode == CDVD_MODE_2048) {
{ offset = 2048 * (sector - threadRequestInfo.lsn);
offset = 2048*(sector-threadRequestInfo.lsn); return threadRequestInfo.data + offset;
return threadRequestInfo.data + offset; }
}
offset = 2352*(sector-threadRequestInfo.lsn); offset = 2352 * (sector - threadRequestInfo.lsn);
s8* data = threadRequestInfo.data + offset; s8 *data = threadRequestInfo.data + offset;
switch(mode) switch (mode) {
{ case CDVD_MODE_2328:
case CDVD_MODE_2328: return data + 24;
return data + 24; case CDVD_MODE_2340:
case CDVD_MODE_2340: return data + 12;
return data + 12; }
} return data;
return data;
} }
s32 cdvdDirectReadSector(s32 first, s32 mode, char *buffer) s32 cdvdDirectReadSector(s32 first, s32 mode, char *buffer)
{ {
static char data[16*2352]; static char data[16 * 2352];
if((u32)first>=tracks[0].length) if ((u32)first >= tracks[0].length)
return -1; return -1;
s32 sector = first&(~15); //align to 16-sector block s32 sector = first & (~15); //align to 16-sector block
EnterCriticalSection( &CacheMutex ); EnterCriticalSection(&CacheMutex);
if(!cdvdCacheFetch(sector,mode,data)) if (!cdvdCacheFetch(sector, mode, data)) {
{ s32 ret = -1;
s32 ret = -1; s32 tries = 5;
s32 tries=5;
s32 count = 16; s32 count = 16;
s32 left = tracks[0].length-sector; s32 left = tracks[0].length - sector;
if(left<count) count=left; if (left < count)
count = left;
do { do {
if(mode==CDVD_MODE_2048) if (mode == CDVD_MODE_2048)
ret = src->ReadSectors2048(sector,count,data); ret = src->ReadSectors2048(sector, count, data);
else else
ret = src->ReadSectors2352(sector,count,data); ret = src->ReadSectors2352(sector, count, data);
if(ret==0) if (ret == 0)
break; break;
tries--; tries--;
} while((ret<0)&&(tries>0)); } while ((ret < 0) && (tries > 0));
cdvdCacheUpdate(sector,mode,data); cdvdCacheUpdate(sector, mode, data);
} }
LeaveCriticalSection( &CacheMutex ); LeaveCriticalSection(&CacheMutex);
s32 offset; s32 offset;
if(mode==CDVD_MODE_2048) if (mode == CDVD_MODE_2048) {
{ offset = 2048 * (first - sector);
offset = 2048*(first-sector); memcpy(buffer, data + offset, 2048);
memcpy(buffer,data + offset,2048); return 0;
return 0; }
}
offset = 2352*(first-sector); offset = 2352 * (first - sector);
s8* bfr = data + offset; s8 *bfr = data + offset;
switch(mode) switch (mode) {
{ case CDVD_MODE_2328:
case CDVD_MODE_2328: memcpy(buffer, bfr + 24, 2328);
memcpy(buffer,bfr+24,2328); return 0;
return 0; case CDVD_MODE_2340:
case CDVD_MODE_2340: memcpy(buffer, bfr + 12, 2340);
memcpy(buffer,bfr+12,2340); return 0;
return 0; default:
default: memcpy(buffer, bfr + 12, 2352);
memcpy(buffer,bfr+12,2352); return 0;
return 0; }
} return 0;
return 0;
} }
s32 cdvdGetMediaType() s32 cdvdGetMediaType()
{ {
return src->GetMediaType(); return src->GetMediaType();
} }
s32 refreshes=0; s32 refreshes = 0;
s32 cdvdRefreshData() s32 cdvdRefreshData()
{ {
char *diskTypeName="Unknown"; char *diskTypeName = "Unknown";
//read TOC from device //read TOC from device
cdvdParseTOC(); cdvdParseTOC();
if((etrack==0)||(strack>etrack)) if ((etrack == 0) || (strack > etrack)) {
{ curDiskType = CDVD_TYPE_NODISC;
curDiskType=CDVD_TYPE_NODISC; } else {
} s32 mt = cdvdGetMediaType();
else
{
s32 mt=cdvdGetMediaType();
if(mt<0) curDiskType = CDVD_TYPE_DETCTCD; if (mt < 0)
else if(mt == 0) curDiskType = CDVD_TYPE_DETCTDVDS; curDiskType = CDVD_TYPE_DETCTCD;
else curDiskType = CDVD_TYPE_DETCTDVDD; else if (mt == 0)
} curDiskType = CDVD_TYPE_DETCTDVDS;
else
curDiskType = CDVD_TYPE_DETCTDVDD;
}
curTrayStatus = CDVD_TRAY_CLOSE; curTrayStatus = CDVD_TRAY_CLOSE;
switch(curDiskType) switch (curDiskType) {
{ case CDVD_TYPE_DETCTDVDD:
case CDVD_TYPE_DETCTDVDD: diskTypeName="Double-Layer DVD"; break; diskTypeName = "Double-Layer DVD";
case CDVD_TYPE_DETCTDVDS: diskTypeName="Single-Layer DVD"; break; break;
case CDVD_TYPE_DETCTCD: diskTypeName="CD-ROM"; break; case CDVD_TYPE_DETCTDVDS:
case CDVD_TYPE_NODISC: diskTypeName="No Disc"; break; 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;
} }

View File

@ -19,128 +19,110 @@ toc_data cdtoc;
s32 cdvdParseTOC() 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].length = len;
tracks[0].start_lba = 0; tracks[0].start_lba = 0;
tracks[0].type = 0; tracks[0].type = 0;
tracks[1].start_lba = 0; tracks[1].start_lba = 0;
if (len <= 0) if (len <= 0) {
{ curDiskType = CDVD_TYPE_NODISC;
curDiskType = CDVD_TYPE_NODISC; tracks[0].length = 0;
tracks[0].length = 0; strack = 1;
strack = 1; etrack = 0;
etrack = 0; return 0;
return 0; }
}
s32 mt = src->GetMediaType(); s32 mt = src->GetMediaType();
if (mt >= 0) if (mt >= 0) {
{ tracks[1].length = tracks[0].length;
tracks[1].length = tracks[0].length; tracks[1].type = 0;
tracks[1].type = 0;
strack = 1; strack = 1;
etrack = 1; etrack = 1;
} } else {
else u8 min, sec, frm;
{
u8 min, sec, frm;
if(src->ReadTOC((char*)&cdtoc,sizeof(cdtoc))<0) if (src->ReadTOC((char *)&cdtoc, sizeof(cdtoc)) < 0) {
{ /*
/* printf(" * CDVD: WARNING ReadTOC() failed, trying to use MCI instead...\n");
printf(" * CDVD: WARNING ReadTOC() failed, trying to use MCI instead...\n"); delete src;
delete src; int status = MCI_CDGetTOC(source_drive);
int status = MCI_CDGetTOC(source_drive);
src=new SOURCECLASS(csrc); src=new SOURCECLASS(csrc);
if(status<0)*/ if(status<0)*/
return -1; return -1;
//return 0; //return 0;
} }
int length = (cdtoc.Length[0]<<8) | cdtoc.Length[1]; int length = (cdtoc.Length[0] << 8) | cdtoc.Length[1];
int descriptors = length/sizeof(cdtoc.Descriptors[0]); int descriptors = length / sizeof(cdtoc.Descriptors[0]);
for(int i=0;i<descriptors;i++) for (int i = 0; i < descriptors; i++) {
{ switch (cdtoc.Descriptors[i].Point) {
switch(cdtoc.Descriptors[i].Point) case 0xa0:
{ if (cdtoc.Descriptors[i].SessionNumber == cdtoc.FirstCompleteSession) {
case 0xa0: strack = cdtoc.Descriptors[i].Msf[0];
if(cdtoc.Descriptors[i].SessionNumber==cdtoc.FirstCompleteSession) }
{ break;
strack = cdtoc.Descriptors[i].Msf[0]; case 0xa1:
} if (cdtoc.Descriptors[i].SessionNumber == cdtoc.LastCompleteSession) {
break; etrack = cdtoc.Descriptors[i].Msf[0];
case 0xa1: }
if(cdtoc.Descriptors[i].SessionNumber==cdtoc.LastCompleteSession) break;
{ case 0xa2: // session size
etrack = cdtoc.Descriptors[i].Msf[0]; if (cdtoc.Descriptors[i].SessionNumber == cdtoc.LastCompleteSession) {
} min = cdtoc.Descriptors[i].Msf[0];
break; sec = cdtoc.Descriptors[i].Msf[1];
case 0xa2: // session size frm = cdtoc.Descriptors[i].Msf[2];
if(cdtoc.Descriptors[i].SessionNumber==cdtoc.LastCompleteSession)
{
min=cdtoc.Descriptors[i].Msf[0];
sec=cdtoc.Descriptors[i].Msf[1];
frm=cdtoc.Descriptors[i].Msf[2];
tracks[0].length = MSF_TO_LBA(min,sec,frm); tracks[0].length = MSF_TO_LBA(min, sec, frm);
tracks[0].type = 0; tracks[0].type = 0;
} }
break; break;
case 0xb0: case 0xb0:
break; break;
case 0xb1: case 0xb1:
break; break;
case 0xb2: case 0xb2:
break; break;
case 0xc0: case 0xc0:
break; break;
default: default:
if((cdtoc.Descriptors[i].Point<100)&&(cdtoc.Descriptors[i].Point>0)) if ((cdtoc.Descriptors[i].Point < 100) && (cdtoc.Descriptors[i].Point > 0)) {
{ int tn = cdtoc.Descriptors[i].Point;
int tn=cdtoc.Descriptors[i].Point;
min=cdtoc.Descriptors[i].Msf[0]; min = cdtoc.Descriptors[i].Msf[0];
sec=cdtoc.Descriptors[i].Msf[1]; sec = cdtoc.Descriptors[i].Msf[1];
frm=cdtoc.Descriptors[i].Msf[2]; frm = cdtoc.Descriptors[i].Msf[2];
tracks[tn].start_lba = MSF_TO_LBA(min,sec,frm); tracks[tn].start_lba = MSF_TO_LBA(min, sec, frm);
if(tn>1) if (tn > 1)
tracks[tn-1].length = tracks[tn].start_lba - tracks[tn-1].start_lba; tracks[tn - 1].length = tracks[tn].start_lba - tracks[tn - 1].start_lba;
if((cdtoc.Descriptors[i].Control&4)==0) if ((cdtoc.Descriptors[i].Control & 4) == 0) {
{ tracks[tn].type = CDVD_AUDIO_TRACK;
tracks[tn].type = CDVD_AUDIO_TRACK; } else if ((cdtoc.Descriptors[i].Control & 0xE) == 4) {
} tracks[tn].type = CDVD_MODE1_TRACK;
else if((cdtoc.Descriptors[i].Control&0xE)==4) } else {
{ tracks[tn].type = CDVD_MODE1_TRACK;
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); fprintf(stderr, "Track %d: %d mins %d secs %d frames\n", tn, min, sec, frm);
} } else if (cdtoc.Descriptors[i].Point > 0) {
else if(cdtoc.Descriptors[i].Point>0) printf("Found code 0x%02x\n", cdtoc.Descriptors[i].Point);
{ }
printf("Found code 0x%02x\n",cdtoc.Descriptors[i].Point); break;
} }
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;
} }

View File

@ -19,366 +19,336 @@
#include <ntddcdvd.h> #include <ntddcdvd.h>
#include <ntddcdrm.h> #include <ntddcdrm.h>
// "typedef ignored" warning will disappear once we move to the Windows 10 SDK. // "typedef ignored" warning will disappear once we move to the Windows 10 SDK.
#pragma warning (push) #pragma warning(push)
#pragma warning (disable: 4091) #pragma warning(disable : 4091)
#include <ntddscsi.h> #include <ntddscsi.h>
#pragma warning (pop) #pragma warning(pop)
#include <cstddef> #include <cstddef>
#include <cstdlib> #include <cstdlib>
s32 IOCtlSrc::Reopen() s32 IOCtlSrc::Reopen()
{ {
if(device!=INVALID_HANDLE_VALUE) if (device != INVALID_HANDLE_VALUE) {
{ DWORD size;
DWORD size; DeviceIoControl(device, IOCTL_DVD_END_SESSION, &sessID, sizeof(DVD_SESSION_ID), NULL, 0, &size, NULL);
DeviceIoControl(device,IOCTL_DVD_END_SESSION,&sessID,sizeof(DVD_SESSION_ID),NULL,0,&size, NULL); CloseHandle(device);
CloseHandle(device); }
}
DWORD share = FILE_SHARE_READ; DWORD share = FILE_SHARE_READ;
DWORD flags = FILE_ATTRIBUTE_READONLY | FILE_FLAG_SEQUENTIAL_SCAN; DWORD flags = FILE_ATTRIBUTE_READONLY | FILE_FLAG_SEQUENTIAL_SCAN;
DWORD size; DWORD size;
OpenOK = false; OpenOK = false;
// SPTI only works if the device is opened with GENERIC_WRITE access. // SPTI only works if the device is opened with GENERIC_WRITE access.
m_can_use_spti = true; m_can_use_spti = true;
device = CreateFile(fName, GENERIC_READ|GENERIC_WRITE|FILE_READ_ATTRIBUTES, share, NULL, OPEN_EXISTING, flags, 0); device = CreateFile(fName, GENERIC_READ | GENERIC_WRITE | FILE_READ_ATTRIBUTES, share, NULL, OPEN_EXISTING, flags, 0);
if(device==INVALID_HANDLE_VALUE) if (device == INVALID_HANDLE_VALUE) {
{ device = CreateFile(fName, GENERIC_READ | FILE_READ_ATTRIBUTES, share, NULL, OPEN_EXISTING, flags, 0);
device = CreateFile(fName, GENERIC_READ|FILE_READ_ATTRIBUTES, share, NULL, OPEN_EXISTING, flags, 0); if (device == INVALID_HANDLE_VALUE)
if(device==INVALID_HANDLE_VALUE) return -1;
return -1; m_can_use_spti = false;
m_can_use_spti = false; }
} // Dual layer DVDs cannot read from layer 1 without this ioctl
// Dual layer DVDs cannot read from layer 1 without this ioctl DeviceIoControl(device, FSCTL_ALLOW_EXTENDED_DASD_IO, nullptr, 0, nullptr, 0, &size, nullptr);
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. // FIXME: 0 is a valid session id, but the code assumes that it isn't.
sessID=0; sessID = 0;
DeviceIoControl(device,IOCTL_DVD_START_SESSION,NULL,0,&sessID,sizeof(DVD_SESSION_ID), &size, NULL); DeviceIoControl(device, IOCTL_DVD_START_SESSION, NULL, 0, &sessID, sizeof(DVD_SESSION_ID), &size, NULL);
tocCached = false; tocCached = false;
mediaTypeCached = false; mediaTypeCached = false;
discSizeCached = false; discSizeCached = false;
layerBreakCached = false; layerBreakCached = false;
OpenOK=true; OpenOK = true;
return 0; 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(); Reopen();
SetSpindleSpeed(false); SetSpindleSpeed(false);
} }
IOCtlSrc::~IOCtlSrc() IOCtlSrc::~IOCtlSrc()
{ {
if(OpenOK) if (OpenOK) {
{ SetSpindleSpeed(true);
SetSpindleSpeed( true ); DWORD size;
DWORD size; DeviceIoControl(device, IOCTL_DVD_END_SESSION, &sessID, sizeof(DVD_SESSION_ID), NULL, 0, &size, NULL);
DeviceIoControl(device,IOCTL_DVD_END_SESSION,&sessID,sizeof(DVD_SESSION_ID),NULL,0,&size, NULL);
CloseHandle(device); CloseHandle(device);
} }
} }
struct mycrap struct mycrap
{ {
DWORD shit; DWORD shit;
DVD_LAYER_DESCRIPTOR ld; DVD_LAYER_DESCRIPTOR ld;
// The IOCTL_DVD_READ_STRUCTURE expects a size of at least 22 bytes when // The IOCTL_DVD_READ_STRUCTURE expects a size of at least 22 bytes when
// reading the dvd physical layer descriptor // reading the dvd physical layer descriptor
// 4 bytes header // 4 bytes header
// 17 bytes for the layer descriptor // 17 bytes for the layer descriptor
// 1 byte of the media specific data for no reason whatsoever... // 1 byte of the media specific data for no reason whatsoever...
UCHAR fixup; UCHAR fixup;
}; };
DVD_READ_STRUCTURE dvdrs; DVD_READ_STRUCTURE dvdrs;
mycrap dld; mycrap dld;
CDROM_READ_TOC_EX tocrq={0}; CDROM_READ_TOC_EX tocrq = {0};
s32 IOCtlSrc::GetSectorCount() s32 IOCtlSrc::GetSectorCount()
{ {
DWORD size; DWORD size;
LARGE_INTEGER li; LARGE_INTEGER li;
if(discSizeCached) if (discSizeCached)
return discSize; return discSize;
if(GetFileSizeEx(device,&li)) if (GetFileSizeEx(device, &li)) {
{ discSizeCached = true;
discSizeCached = true; discSize = (s32)(li.QuadPart / 2048);
discSize = (s32)(li.QuadPart / 2048); return discSize;
return discSize; }
}
GET_LENGTH_INFORMATION info; GET_LENGTH_INFORMATION info;
if(DeviceIoControl(device, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &info, sizeof(info), &size, NULL)) if (DeviceIoControl(device, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &info, sizeof(info), &size, NULL)) {
{ discSizeCached = true;
discSizeCached = true; discSize = (s32)(info.Length.QuadPart / 2048);
discSize = (s32)(info.Length.QuadPart / 2048); return discSize;
return discSize; }
}
memset(&tocrq,0,sizeof(CDROM_READ_TOC_EX)); memset(&tocrq, 0, sizeof(CDROM_READ_TOC_EX));
tocrq.Format = CDROM_READ_TOC_EX_FORMAT_FULL_TOC; tocrq.Format = CDROM_READ_TOC_EX_FORMAT_FULL_TOC;
tocrq.Msf=1; tocrq.Msf = 1;
tocrq.SessionTrack=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)) if (DeviceIoControl(device, IOCTL_CDROM_READ_TOC_EX, &tocrq, sizeof(tocrq), ftd, 2048, &size, NULL)) {
{ for (int i = 0; i < 101; i++) {
for(int i=0;i<101;i++) if (ftd->Descriptors[i].Point == 0xa2) {
{ if (ftd->Descriptors[i].SessionNumber == ftd->LastCompleteSession) {
if(ftd->Descriptors[i].Point==0xa2) int min = ftd->Descriptors[i].Msf[0];
{ int sec = ftd->Descriptors[i].Msf[1];
if(ftd->Descriptors[i].SessionNumber==ftd->LastCompleteSession) int frm = ftd->Descriptors[i].Msf[2];
{
int min=ftd->Descriptors[i].Msf[0];
int sec=ftd->Descriptors[i].Msf[1];
int frm=ftd->Descriptors[i].Msf[2];
discSizeCached = true; discSizeCached = true;
discSize = (s32)MSF_TO_LBA(min,sec,frm); discSize = (s32)MSF_TO_LBA(min, sec, frm);
return discSize; return discSize;
} }
} }
} }
} }
dvdrs.BlockByteOffset.QuadPart=0; dvdrs.BlockByteOffset.QuadPart = 0;
dvdrs.Format=DvdPhysicalDescriptor; dvdrs.Format = DvdPhysicalDescriptor;
dvdrs.SessionId=sessID; dvdrs.SessionId = sessID;
dvdrs.LayerNumber=0; dvdrs.LayerNumber = 0;
if(DeviceIoControl(device,IOCTL_DVD_READ_STRUCTURE,&dvdrs,sizeof(dvdrs),&dld, sizeof(dld), &size, NULL)!=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;
s32 sectors1 = _byteswap_ulong(dld.ld.EndDataSector) - _byteswap_ulong(dld.ld.StartingDataSector) + 1; if (dld.ld.NumberOfLayers == 1) { // PTP, OTP
if (dld.ld.NumberOfLayers == 1) // PTP, OTP if (dld.ld.TrackPath == 0) { // PTP
{ dvdrs.LayerNumber = 1;
if (dld.ld.TrackPath == 0) // PTP 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;
dvdrs.LayerNumber = 1; }
if (DeviceIoControl(device, IOCTL_DVD_READ_STRUCTURE, &dvdrs, sizeof(dvdrs), &dld, sizeof(dld), &size, nullptr) != 0) } else { // OTP
{ // sectors = end_sector - (~end_sector_l0 & 0xFFFFFF) + end_sector_l0 - start_sector
sectors1 += _byteswap_ulong(dld.ld.EndDataSector) - _byteswap_ulong(dld.ld.StartingDataSector) + 1; dld.ld.EndLayerZeroSector = _byteswap_ulong(dld.ld.EndLayerZeroSector);
} sectors1 += dld.ld.EndLayerZeroSector - (~dld.ld.EndLayerZeroSector & 0x00FFFFFF) + 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; discSizeCached = true;
discSize = sectors1; discSize = sectors1;
return discSize; return discSize;
} }
return -1; return -1;
} }
s32 IOCtlSrc::GetLayerBreakAddress() s32 IOCtlSrc::GetLayerBreakAddress()
{ {
DWORD size; DWORD size;
if(GetMediaType()<0) if (GetMediaType() < 0)
return -1; return -1;
if(layerBreakCached) if (layerBreakCached)
return layerBreak; return layerBreak;
dvdrs.BlockByteOffset.QuadPart=0; dvdrs.BlockByteOffset.QuadPart = 0;
dvdrs.Format=DvdPhysicalDescriptor; dvdrs.Format = DvdPhysicalDescriptor;
dvdrs.SessionId=sessID; dvdrs.SessionId = sessID;
dvdrs.LayerNumber=0; dvdrs.LayerNumber = 0;
if (DeviceIoControl(device, IOCTL_DVD_READ_STRUCTURE, &dvdrs, sizeof(dvdrs), &dld, sizeof(dld), &size, nullptr)) if (DeviceIoControl(device, IOCTL_DVD_READ_STRUCTURE, &dvdrs, sizeof(dvdrs), &dld, sizeof(dld), &size, nullptr)) {
{ if (dld.ld.NumberOfLayers == 0) { // Single layer
if (dld.ld.NumberOfLayers == 0) // Single layer layerBreak = 0;
{ } else if (dld.ld.TrackPath == 0) { // PTP
layerBreak = 0; layerBreak = _byteswap_ulong(dld.ld.EndDataSector) - _byteswap_ulong(dld.ld.StartingDataSector);
} } else { // OTP
else if (dld.ld.TrackPath == 0) // PTP layerBreak = _byteswap_ulong(dld.ld.EndLayerZeroSector) - _byteswap_ulong(dld.ld.StartingDataSector);
{ }
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; layerBreakCached = true;
return layerBreak; return layerBreak;
} }
//if not a cd, and fails, assume single layer //if not a cd, and fails, assume single layer
return 0; return 0;
} }
void IOCtlSrc::SetSpindleSpeed(bool restore_defaults) { 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;
if (DeviceIoControl(device, DWORD dontcare;
IOCTL_CDROM_SET_SPEED, //operation to perform int speed = 0;
&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, if (GetMediaType() < 0)
IOCTL_CDROM_SET_SPEED, //operation to perform speed = 4800; // CD-ROM to ~32x (PS2 has 24x (3600 KB/s))
&s, sizeof(s), //no input buffer else
NULL, 0, //output buffer speed = 11080; // DVD-ROM to ~8x (PS2 has 4x (5540 KB/s))
&dontcare, //#bytes returned
(LPOVERLAPPED)NULL); //synchronous I/O == 0) 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() s32 IOCtlSrc::GetMediaType()
{ {
DWORD size; DWORD size;
if(mediaTypeCached) if (mediaTypeCached)
return mediaType; return mediaType;
memset(&tocrq,0,sizeof(CDROM_READ_TOC_EX)); memset(&tocrq, 0, sizeof(CDROM_READ_TOC_EX));
tocrq.Format = CDROM_READ_TOC_EX_FORMAT_FULL_TOC; tocrq.Format = CDROM_READ_TOC_EX_FORMAT_FULL_TOC;
tocrq.Msf=1; tocrq.Msf = 1;
tocrq.SessionTrack=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)) if (DeviceIoControl(device, IOCTL_CDROM_READ_TOC_EX, &tocrq, sizeof(tocrq), ftd, 2048, &size, NULL)) {
{ mediaTypeCached = true;
mediaTypeCached = true; mediaType = -1;
mediaType = -1; return mediaType;
return mediaType; }
}
dvdrs.BlockByteOffset.QuadPart=0; dvdrs.BlockByteOffset.QuadPart = 0;
dvdrs.Format=DvdPhysicalDescriptor; dvdrs.Format = DvdPhysicalDescriptor;
dvdrs.SessionId=sessID; dvdrs.SessionId = sessID;
dvdrs.LayerNumber=0; dvdrs.LayerNumber = 0;
if (DeviceIoControl(device, IOCTL_DVD_READ_STRUCTURE, &dvdrs, sizeof(dvdrs), &dld, sizeof(dld), &size, nullptr)) if (DeviceIoControl(device, IOCTL_DVD_READ_STRUCTURE, &dvdrs, sizeof(dvdrs), &dld, sizeof(dld), &size, nullptr)) {
{ if (dld.ld.NumberOfLayers == 0) { // Single layer
if (dld.ld.NumberOfLayers == 0) // Single layer mediaType = 0;
{ } else if (dld.ld.TrackPath == 0) { // PTP
mediaType = 0; mediaType = 1;
} } else { // OTP
else if (dld.ld.TrackPath == 0) // PTP mediaType = 2;
{ }
mediaType = 1;
}
else // OTP
{
mediaType = 2;
}
mediaTypeCached = true; mediaTypeCached = true;
return mediaType; return mediaType;
} }
//if not a cd, and fails, assume single layer //if not a cd, and fails, assume single layer
mediaTypeCached = true; mediaTypeCached = true;
mediaType = 0; mediaType = 0;
return mediaType; 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) if (GetMediaType() >= 0)
return -1; return -1;
if(!tocCached) if (!tocCached) {
{ memset(&tocrq, 0, sizeof(CDROM_READ_TOC_EX));
memset(&tocrq,0,sizeof(CDROM_READ_TOC_EX)); tocrq.Format = CDROM_READ_TOC_EX_FORMAT_FULL_TOC;
tocrq.Format = CDROM_READ_TOC_EX_FORMAT_FULL_TOC; tocrq.Msf = 1;
tocrq.Msf=1; tocrq.SessionTrack = 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) if (code == 0)
return -1; 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) 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.DiskOffset.QuadPart = sector * (u64)2048;
rri.SectorCount=count; rri.SectorCount = count;
//fall back to standard reading //fall back to standard reading
if(SetFilePointer(device,rri.DiskOffset.LowPart,&rri.DiskOffset.HighPart,FILE_BEGIN)==-1) if (SetFilePointer(device, rri.DiskOffset.LowPart, &rri.DiskOffset.HighPart, FILE_BEGIN) == -1) {
{ if (GetLastError() != 0)
if(GetLastError()!=0) return -1;
return -1; }
}
if(ReadFile(device,buffer,2048*count,&size,NULL)==0) if (ReadFile(device, buffer, 2048 * count, &size, NULL) == 0) {
{ return -1;
return -1; }
}
if(size!=(2048*count)) if (size != (2048 * count)) {
{ return -1;
return -1; }
}
return 0; return 0;
} }
@ -386,122 +356,114 @@ s32 IOCtlSrc::ReadSectors2048(u32 sector, u32 count, char *buffer)
// of different types. // of different types.
s32 IOCtlSrc::ReadSectors2352(u32 sector, u32 count, char *buffer) 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) if (m_can_use_spti) {
{ struct sptdinfo
struct sptdinfo {
{ SCSI_PASS_THROUGH_DIRECT info;
SCSI_PASS_THROUGH_DIRECT info; char sense_buffer[20];
char sense_buffer[20]; } sptd = {};
} sptd = {};
// READ CD command // READ CD command
sptd.info.Cdb[0] = 0xBE; sptd.info.Cdb[0] = 0xBE;
// Don't care about sector type. // Don't care about sector type.
sptd.info.Cdb[1] = 0; sptd.info.Cdb[1] = 0;
sptd.info.Cdb[2] = (sector >> 24) & 0xFF; sptd.info.Cdb[2] = (sector >> 24) & 0xFF;
sptd.info.Cdb[3] = (sector >> 16) & 0xFF; sptd.info.Cdb[3] = (sector >> 16) & 0xFF;
sptd.info.Cdb[4] = (sector >> 8) & 0xFF; sptd.info.Cdb[4] = (sector >> 8) & 0xFF;
sptd.info.Cdb[5] = sector & 0xFF; sptd.info.Cdb[5] = sector & 0xFF;
sptd.info.Cdb[6] = (count >> 16) & 0xFF; sptd.info.Cdb[6] = (count >> 16) & 0xFF;
sptd.info.Cdb[7] = (count >> 8) & 0xFF; sptd.info.Cdb[7] = (count >> 8) & 0xFF;
sptd.info.Cdb[8] = count & 0xFF; sptd.info.Cdb[8] = count & 0xFF;
// Sync + all headers + user data + EDC/ECC. Excludes C2 + subchannel // Sync + all headers + user data + EDC/ECC. Excludes C2 + subchannel
sptd.info.Cdb[9] = 0xF8; sptd.info.Cdb[9] = 0xF8;
sptd.info.Cdb[10] = 0; sptd.info.Cdb[10] = 0;
sptd.info.Cdb[11] = 0; sptd.info.Cdb[11] = 0;
sptd.info.CdbLength = 12; sptd.info.CdbLength = 12;
sptd.info.Length = sizeof(SCSI_PASS_THROUGH_DIRECT); sptd.info.Length = sizeof(SCSI_PASS_THROUGH_DIRECT);
sptd.info.DataIn = SCSI_IOCTL_DATA_IN; sptd.info.DataIn = SCSI_IOCTL_DATA_IN;
sptd.info.DataTransferLength = 2352 * count; sptd.info.DataTransferLength = 2352 * count;
sptd.info.DataBuffer = buffer; sptd.info.DataBuffer = buffer;
sptd.info.SenseInfoLength = sizeof(sptd.sense_buffer); sptd.info.SenseInfoLength = sizeof(sptd.sense_buffer);
sptd.info.SenseInfoOffset = offsetof(sptdinfo, sense_buffer); sptd.info.SenseInfoOffset = offsetof(sptdinfo, sense_buffer);
sptd.info.TimeOutValue = 5; sptd.info.TimeOutValue = 5;
if (DeviceIoControl(device, IOCTL_SCSI_PASS_THROUGH_DIRECT, &sptd, if (DeviceIoControl(device, IOCTL_SCSI_PASS_THROUGH_DIRECT, &sptd,
sizeof(sptd), &sptd, sizeof(sptd), &size, nullptr)) sizeof(sptd), &sptd, sizeof(sptd), &size, nullptr)) {
{ if (sptd.info.DataTransferLength == 2352 * count)
if (sptd.info.DataTransferLength == 2352 * count) return 0;
return 0; }
} printf(" * CDVD: SPTI failed reading sectors %u-%u\n", sector, sector + count - 1);
printf(" * CDVD: SPTI failed reading sectors %u-%u\n", sector, sector + count - 1); }
}
rri.DiskOffset.QuadPart=sector*(u64)2048; rri.DiskOffset.QuadPart = sector * (u64)2048;
rri.SectorCount=count; rri.SectorCount = count;
rri.TrackMode=(TRACK_MODE_TYPE)last_read_mode; rri.TrackMode = (TRACK_MODE_TYPE)last_read_mode;
if(DeviceIoControl(device,IOCTL_CDROM_RAW_READ,&rri,sizeof(rri),buffer, 2352*count, &size, NULL)==0) if (DeviceIoControl(device, IOCTL_CDROM_RAW_READ, &rri, sizeof(rri), buffer, 2352 * count, &size, NULL) == 0) {
{ rri.TrackMode = XAForm2;
rri.TrackMode = XAForm2; printf(" * CDVD: CD-ROM read mode change\n");
printf(" * CDVD: CD-ROM read mode change\n"); printf(" * CDVD: Trying XAForm2\n");
printf(" * CDVD: Trying XAForm2\n"); if (DeviceIoControl(device, IOCTL_CDROM_RAW_READ, &rri, sizeof(rri), buffer, 2352 * count, &size, NULL) == 0) {
if(DeviceIoControl(device,IOCTL_CDROM_RAW_READ,&rri,sizeof(rri),buffer, 2352*count, &size, NULL)==0) rri.TrackMode = YellowMode2;
{ printf(" * CDVD: Trying YellowMode2\n");
rri.TrackMode = YellowMode2; if (DeviceIoControl(device, IOCTL_CDROM_RAW_READ, &rri, sizeof(rri), buffer, 2352 * count, &size, NULL) == 0) {
printf(" * CDVD: Trying YellowMode2\n"); rri.TrackMode = CDDA;
if(DeviceIoControl(device,IOCTL_CDROM_RAW_READ,&rri,sizeof(rri),buffer, 2352*count, &size, NULL)==0) printf(" * CDVD: Trying CDDA\n");
{ if (DeviceIoControl(device, IOCTL_CDROM_RAW_READ, &rri, sizeof(rri), buffer, 2352 * count, &size, NULL) == 0) {
rri.TrackMode = CDDA; printf(" * CDVD: Failed to read this CD-ROM with error code: %d\n", GetLastError());
printf(" * CDVD: Trying CDDA\n"); return -1;
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)) if (size != (2352 * count)) {
{ return -1;
return -1; }
}
return 0; return 0;
} }
s32 IOCtlSrc::DiscChanged() 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) if (ret == 0) {
{ tocCached = false;
tocCached = false; mediaTypeCached = false;
mediaTypeCached = false; discSizeCached = false;
discSizeCached = false; layerBreakCached = false;
layerBreakCached = false;
if(sessID!=0) if (sessID != 0) {
{ DeviceIoControl(device, IOCTL_DVD_END_SESSION, &sessID, sizeof(DVD_SESSION_ID), NULL, 0, &size, NULL);
DeviceIoControl(device,IOCTL_DVD_END_SESSION,&sessID,sizeof(DVD_SESSION_ID),NULL,0,&size, NULL); sessID = 0;
sessID=0; }
} return 1;
return 1; }
}
if(sessID==0) if (sessID == 0) {
{ DeviceIoControl(device, IOCTL_DVD_START_SESSION, NULL, 0, &sessID, sizeof(DVD_SESSION_ID), &size, NULL);
DeviceIoControl(device,IOCTL_DVD_START_SESSION,NULL,0,&sessID,sizeof(DVD_SESSION_ID), &size, NULL); }
}
return 0; return 0;
} }
s32 IOCtlSrc::IsOK() s32 IOCtlSrc::IsOK()
{ {
return OpenOK; return OpenOK;
} }

View File

@ -27,19 +27,19 @@
char source_drive; 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. // a better std::string version, but it's inconvenient for other reasons.
//CfgFile = std::string(( dir == NULL ) ? "inis/" : dir) + "cdvdGigaherz.ini"; //CfgFile = std::string(( dir == NULL ) ? "inis/" : dir) + "cdvdGigaherz.ini";
strcpy_s(CfgFile, (dir==NULL) ? "inis" : dir); strcpy_s(CfgFile, (dir == NULL) ? "inis" : dir);
strcat_s(CfgFile, "/cdvdGigaherz.ini"); strcat_s(CfgFile, "/cdvdGigaherz.ini");
} }
/*| Config File Format: |¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯*\ /*| Config File Format: |¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯*\
+--+---------------------+------------------------+ +--+---------------------+------------------------+
| | | |
| Option=Value | | Option=Value |
@ -54,166 +54,172 @@ void CfgSetSettingsDir( const char* dir )
\*_____________________________________________*/ \*_____________________________________________*/
void CfgWriteBool(char *Section, char*Name, char Value) { void CfgWriteBool(char *Section, char *Name, char Value)
char *Data=Value?"TRUE":"FALSE"; {
char *Data = Value ? "TRUE" : "FALSE";
WritePrivateProfileString(Section,Name,Data,CfgFile); WritePrivateProfileString(Section, Name, Data, CfgFile);
} }
void CfgWriteInt(char *Section, char*Name, int Value) { void CfgWriteInt(char *Section, char *Name, int Value)
char Data[255]; {
_itoa(Value,Data,10); 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) { void CfgWriteStr(char *Section, char *Name, char *Data)
WritePrivateProfileString(Section,Name,Data,CfgFile); {
WritePrivateProfileString(Section, Name, Data, CfgFile);
} }
/*****************************************************************************/ /*****************************************************************************/
char CfgReadBool(char *Section,char *Name,char Default) { char CfgReadBool(char *Section, char *Name, char Default)
char Data[255]=""; {
GetPrivateProfileString(Section,Name,"",Data,255,CfgFile); char Data[255] = "";
Data[254]=0; GetPrivateProfileString(Section, Name, "", Data, 255, CfgFile);
if(strlen(Data)==0) { Data[254] = 0;
CfgWriteBool(Section,Name,Default); if (strlen(Data) == 0) {
return Default; CfgWriteBool(Section, Name, Default);
} return Default;
}
if(strcmp(Data,"1")==0) return -1; if (strcmp(Data, "1") == 0)
if(strcmp(Data,"Y")==0) return -1; return -1;
if(strcmp(Data,"T")==0) return -1; if (strcmp(Data, "Y") == 0)
if(strcmp(Data,"YES")==0) return -1; return -1;
if(strcmp(Data,"TRUE")==0) return -1; if (strcmp(Data, "T") == 0)
return 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) { int CfgReadInt(char *Section, char *Name, int Default)
char Data[255]=""; {
GetPrivateProfileString(Section,Name,"",Data,255,CfgFile); char Data[255] = "";
Data[254]=0; GetPrivateProfileString(Section, Name, "", Data, 255, CfgFile);
Data[254] = 0;
if(strlen(Data)==0) { if (strlen(Data) == 0) {
CfgWriteInt(Section,Name,Default); CfgWriteInt(Section, Name, Default);
return Default; return Default;
} }
return atoi(Data); return atoi(Data);
} }
void CfgReadStr(char *Section, char*Name,char *Data,int DataSize,char *Default) { void CfgReadStr(char *Section, char *Name, char *Data, int DataSize, char *Default)
int sl; {
GetPrivateProfileString(Section,Name,"",Data,DataSize,CfgFile); int sl;
GetPrivateProfileString(Section, Name, "", Data, DataSize, CfgFile);
if(strlen(Data)==0) { if (strlen(Data) == 0) {
sl=(int)strlen(Default); sl = (int)strlen(Default);
strncpy(Data,Default,sl>255?255:sl); strncpy(Data, Default, sl > 255 ? 255 : sl);
CfgWriteStr(Section,Name,Data); CfgWriteStr(Section, Name, Data);
} }
} }
/*****************************************************************************/ /*****************************************************************************/
void ReadSettings() void ReadSettings()
{ {
char temp[512]; char temp[512];
CfgReadStr("Config","Source",temp,511,"-"); CfgReadStr("Config", "Source", temp, 511, "-");
source_drive=temp[0]; source_drive = temp[0];
} }
/*****************************************************************************/ /*****************************************************************************/
void WriteSettings() void WriteSettings()
{ {
char temp[2]; char temp[2];
temp[0]=source_drive; temp[0] = source_drive;
temp[1]=0; temp[1] = 0;
CfgWriteStr("Config","Source",temp); CfgWriteStr("Config", "Source", temp);
} }
char* path[] = { char *path[] = {
"A:","B:","C:","D:","E:","F:","G:","H:","I:","J:","K:","L:","M:", "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:", "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; 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}; 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: case WM_PAINT:
return FALSE; return FALSE;
case WM_INITDIALOG: 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_RESETCONTENT, 0, 0);
SendMessage(GetDlgItem(hWnd,IDC_DRIVE),CB_ADDSTRING,0,(LPARAM)"@ (No disc)"); SendMessage(GetDlgItem(hWnd, IDC_DRIVE), CB_ADDSTRING, 0, (LPARAM) "@ (No disc)");
for(char d='A';d<='Z';d++) for (char d = 'A'; d <= 'Z'; d++) {
{ if (GetDriveType(path[d - 'A']) == DRIVE_CDROM) {
if(GetDriveType(path[d-'A'])==DRIVE_CDROM) n++;
{
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) if (source_drive == d) {
{ s = n;
s=n; }
} }
} }
}
SendMessage(GetDlgItem(hWnd,IDC_DRIVE),CB_SETCURSEL,s,0); SendMessage(GetDlgItem(hWnd, IDC_DRIVE), CB_SETCURSEL, s, 0);
break; break;
case WM_COMMAND: case WM_COMMAND:
wmId = LOWORD(wParam); wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam); wmEvent = HIWORD(wParam);
// Parse the menu selections: // Parse the menu selections:
switch (wmId) switch (wmId) {
{ case IDOK:
case IDOK: GetDlgItemText(hWnd, IDC_DRIVE, temp, 20);
GetDlgItemText(hWnd,IDC_DRIVE,temp,20); temp[19] = 0;
temp[19]=0; source_drive = temp[0];
source_drive=temp[0];
WriteSettings(); WriteSettings();
EndDialog(hWnd,0); EndDialog(hWnd, 0);
break; break;
case IDCANCEL: case IDCANCEL:
EndDialog(hWnd,0); EndDialog(hWnd, 0);
break; break;
default: default:
return FALSE; return FALSE;
} }
break; break;
default: default:
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
void configure() void configure()
{ {
INT_PTR ret; INT_PTR ret;
ReadSettings(); ReadSettings();
ret=DialogBoxParam(hinst,MAKEINTRESOURCE(IDD_CONFIG),GetActiveWindow(),(DLGPROC)ConfigProc,1); ret = DialogBoxParam(hinst, MAKEINTRESOURCE(IDD_CONFIG), GetActiveWindow(), (DLGPROC)ConfigProc, 1);
if(ret==-1) if (ret == -1) {
{ MessageBoxEx(GetActiveWindow(), "Error Opening the config dialog.", "OMG ERROR!", MB_OK, 0);
MessageBoxEx(GetActiveWindow(),"Error Opening the config dialog.","OMG ERROR!",MB_OK,0); return;
return; }
} ReadSettings();
ReadSettings();
} }