diff --git a/pcsx2/CDVD/CDVD.cpp b/pcsx2/CDVD/CDVD.cpp index b6708bdc19..3273973c4b 100644 --- a/pcsx2/CDVD/CDVD.cpp +++ b/pcsx2/CDVD/CDVD.cpp @@ -294,11 +294,8 @@ s32 cdvdReadConfig(u8* config) } s32 cdvdWriteConfig(const u8* config) { - // make sure its in write mode - if(cdvd.CReadWrite != 1) - return 1; - // check if block index is in bounds - else if(cdvd.CBlockIndex >= cdvd.CNumBlocks) + // make sure its in write mode && the block index is in bounds + if ((cdvd.CReadWrite != 1) || (cdvd.CBlockIndex >= cdvd.CNumBlocks)) return 1; else if( ((cdvd.COffset == 0) && (cdvd.CBlockIndex >= 4))|| @@ -543,14 +540,12 @@ void cdvdNewDiskCB() void mechaDecryptBytes( u32 madr, int size ) { - int i; - int shiftAmount = (cdvd.decSet>>4) & 7; int doXor = (cdvd.decSet) & 1; int doShift = (cdvd.decSet) & 2; u8* curval = iopPhysMem( madr ); - for( i=0; i> shiftAmount) | (*curval << (8-shiftAmount) ); @@ -600,9 +595,8 @@ int cdvdReadSector() { } else { - // Assumed the other dualType is 0. - // single layer disc - // or on first layer of dual layer disc + // Assuming the other dualType is 0, + // single layer disc, or on first layer of dual layer disc. layerNum = 0; lsn += 0x30000; } @@ -634,7 +628,7 @@ int cdvdReadSector() { // Final Fantasy X-2 crashing. So we won't. DevCon::WriteLn("Bad Transfer!"); - for (int i = 12; i > 2060; i++) + for (int i = 12; i <= 2060; i++) { mdest[i] = 0; } @@ -789,7 +783,6 @@ __forceinline void cdvdReadInterrupt() cdvd.Ready = CDVD_READY2; // All done! :D - return; } diff --git a/pcsx2/CDVD/CDVD.h b/pcsx2/CDVD/CDVD.h index 81e9a50774..1649bcab5d 100644 --- a/pcsx2/CDVD/CDVD.h +++ b/pcsx2/CDVD/CDVD.h @@ -27,6 +27,43 @@ extern char isoFileName[]; #define btoi(b) ((b)/16*10 + (b)%16) /* BCD to u_char */ #define itob(i) ((i)/10*16 + (i)%10) /* u_char to BCD */ +static __forceinline s32 msf_to_lsn(u8 *Time) +{ + u32 lsn; + + lsn = Time[2]; + lsn +=(Time[1] - 2) * 75; + lsn += Time[0] * 75 * 60; + return lsn; +} + +static __forceinline s32 msf_to_lba(u8 m, u8 s, u8 f) +{ + u32 lsn; + lsn = f; + lsn += (s - 2) * 75; + lsn += m * 75 * 60; + return lsn; +} + +static __forceinline void lsn_to_msf(u8 *Time, s32 lsn) +{ + lsn += 150; + Time[2] = lsn / 4500; // minuten + lsn = lsn - Time[2] * 4500; // minuten rest + Time[1] = lsn / 75; // sekunden + Time[0] = lsn - Time[1] * 75; // sekunden rest +} + + +static __forceinline void lba_to_msf(s32 lba, u8* m, u8* s, u8* f) +{ + lba += 150; + *m = lba / (60 * 75); + *s = (lba / 75) % 60; + *f = lba % 75; +} + struct cdvdRTC { u8 status; u8 second; diff --git a/pcsx2/CDVD/CDVDaccess.cpp b/pcsx2/CDVD/CDVDaccess.cpp index 5054c8dae2..c966628f2b 100644 --- a/pcsx2/CDVD/CDVDaccess.cpp +++ b/pcsx2/CDVD/CDVDaccess.cpp @@ -305,9 +305,7 @@ s32 DoCDVDopen(const char* pTitleFilename) cdvdTD td; CDVD.getTD(0, &td); - int blockofs = 0; - int blocksize = 0; - int blocks = td.lsn; + int blockofs = 0, blocksize = 0, blocks = td.lsn; switch(cdtype) { diff --git a/pcsx2/CDVD/CDVDisoReader.cpp b/pcsx2/CDVD/CDVDisoReader.cpp index 4b8f9b21b2..c7f70c4e53 100644 --- a/pcsx2/CDVD/CDVDisoReader.cpp +++ b/pcsx2/CDVD/CDVDisoReader.cpp @@ -30,79 +30,21 @@ #include "CDVDisoReader.h" char isoFileName[g_MaxPath]; - u8 *pbuffer; -int cdtype; - -static int psize; - -isoFile *iso; - -FILE *cdvdLog = NULL; - +static int psize, cdtype; u8 cdbuffer[2352] = {0}; - -s32 msf_to_lba(u8 m, u8 s, u8 f) -{ - u32 lsn; - lsn = f; - lsn += (s - 2) * 75; - lsn += m * 75 * 60; - return lsn; -} - -void lba_to_msf(s32 lba, u8* m, u8* s, u8* f) -{ - lba += 150; - *m = lba / (60 * 75); - *s = (lba / 75) % 60; - *f = lba % 75; -} - -//#define btoi(b) ((b)/16*10 + (b)%16) /* BCD to u_char */ -//#define itob(i) ((i)/10*16 + (i)%10) /* u_char to BCD */ - - -/*#ifdef PCSX2_DEBUG -void __Log(char *fmt, ...) -{ - va_list list; - - if (cdvdLog == NULL) return; - - va_start(list, fmt); - vfprintf(cdvdLog, fmt, list); - va_end(list); -} -#else -#define __Log 0&& -#endif*/ +isoFile *iso; s32 CALLBACK ISOinit() { -/*#ifdef PCSX2_DEBUG - cdvdLog = fopen("logs/cdvdLog.txt", "w"); - if (cdvdLog == NULL) - { - cdvdLog = fopen("cdvdLog.txt", "w"); - if (cdvdLog == NULL) - { - Console::Error("Can't create cdvdLog.txt"); - return -1; - } - } - setvbuf(cdvdLog, NULL, _IONBF, 0);*/ - CDVD_LOG("CDVDinit\n"); -/*#endif*/ + CDVD_LOG("ISOinit\n"); return 0; } void CALLBACK ISOshutdown() { -/*#ifdef CDVD_LOG - if (cdvdLog != NULL) fclose(cdvdLog); -#endif*/ + CDVD_LOG("ISOshutdown\n"); } s32 CALLBACK ISOopen(const char* pTitle) @@ -246,7 +188,7 @@ s32 CALLBACK ISOgetTOC(void* toc) u8 type = ISOgetDiskType(); u8* tocBuff = (u8*)toc; - //__Log("CDVDgetTOC\n"); + //CDVD_LOG("CDVDgetTOC\n"); if (type == CDVD_TYPE_DVDV || type == CDVD_TYPE_PS2DVD) { diff --git a/pcsx2/CDVD/CDVDisoReader.h b/pcsx2/CDVD/CDVDisoReader.h index cb0448d72a..8e988acee9 100644 --- a/pcsx2/CDVD/CDVDisoReader.h +++ b/pcsx2/CDVD/CDVDisoReader.h @@ -29,19 +29,6 @@ #include "IsoFStools.h" #include "IsoFileFormats.h" -//#define CDVD_LOG __Log - -//#ifndef MAX_PATH -//#define MAX_PATH 255 -//#endif - -//extern FILE *cdvdLog; - -//void __Log(char *fmt, ...); - -//#define itob(i) ((i)/10*16 + (i)%10) /* u_char to BCD */ -//#define btoi(b) ((b)/16*10 + (b)%16) /* BCD to u_char */ - extern char isoFileName[g_MaxPath]; extern isoFile *iso; diff --git a/pcsx2/CDVD/CdRom.cpp b/pcsx2/CDVD/CdRom.cpp index 726d4ae97b..ed9aa41f7f 100644 --- a/pcsx2/CDVD/CdRom.cpp +++ b/pcsx2/CDVD/CdRom.cpp @@ -118,30 +118,13 @@ static __forceinline void SetResultSize(u8 size) { cdr.ResultReady = 1; } -static __forceinline s32 MSFtoLSN(u8 *Time) { - u32 lsn; - - lsn = Time[2]; - lsn+=(Time[1] - 2) * 75; - lsn+= Time[0] * 75 * 60; - return lsn; -} - -static __forceinline void LSNtoMSF(u8 *Time, s32 lsn) { - lsn += 150; - Time[2] = lsn / 4500; // minuten - lsn = lsn - Time[2] * 4500; // minuten rest - Time[1] = lsn / 75; // sekunden - Time[0] = lsn - Time[1] * 75; // sekunden rest -} - static void ReadTrack() { cdr.Prev[0] = itob(cdr.SetSector[0]); cdr.Prev[1] = itob(cdr.SetSector[1]); cdr.Prev[2] = itob(cdr.SetSector[2]); CDR_LOG("KEY *** %x:%x:%x", cdr.Prev[0], cdr.Prev[1], cdr.Prev[2]); - cdr.RErr = DoCDVDreadTrack(MSFtoLSN(cdr.SetSector), CDVD_MODE_2340); + cdr.RErr = DoCDVDreadTrack(msf_to_lsn(cdr.SetSector), CDVD_MODE_2340); } // cdr.Stat: @@ -351,7 +334,7 @@ void cdrInterrupt() { cdr.Stat = DiskError; cdr.Result[0]|= 0x01; } else { - LSNtoMSF(cdr.ResultTD, trackInfo.lsn); + lsn_to_msf(cdr.ResultTD, trackInfo.lsn); cdr.Stat = Acknowledge; cdr.Result[0] = cdr.StatP; cdr.Result[1] = itob(cdr.ResultTD[0]); @@ -397,11 +380,14 @@ void cdrInterrupt() { SetResultSize(4); *(int*)cdr.Result = *(int*)Test20; break; + case 0x22: SetResultSize(8); *(int*)cdr.Result = *(int*)Test22; break; - case 0x23: case 0x24: + + case 0x23: + case 0x24: SetResultSize(8); *(int*)cdr.Result = *(int*)Test23; break; @@ -456,8 +442,7 @@ void cdrInterrupt() { break; case READ_ACK: - if (!cdr.Reading) - return; + if (!cdr.Reading) return; SetResultSize(1); cdr.StatP|= 0x2; diff --git a/pcsx2/CDVD/IsoFSdrv.cpp b/pcsx2/CDVD/IsoFSdrv.cpp index ce014f892b..19d8bc9dec 100644 --- a/pcsx2/CDVD/IsoFSdrv.cpp +++ b/pcsx2/CDVD/IsoFSdrv.cpp @@ -27,7 +27,7 @@ #include "IsoFSdrv.h" struct fdtable{ -//int fd; +// int fd; int fileSize; int LBA; int filePos; @@ -68,8 +68,7 @@ int IsoFS_open(const char *name, int mode){ static struct TocEntry tocEntry; // check if the file exists - if (IsoFS_findFile(name, &tocEntry) != TRUE) - return -1; + if (IsoFS_findFile(name, &tocEntry) != TRUE) return -1; if(mode != 1) return -2; //SCE_RDONLY @@ -117,11 +116,12 @@ int IsoFS_lseek(int fd, int offset, int whence){ return -1; } - if (fd_table[fd].filePos < 0) - fd_table[fd].filePos = 0; + if (fd_table[fd].filePos < 0) fd_table[fd].filePos = 0; - if (fd_table[fd].filePos > fd_table[fd].fileSize) + if (fd_table[fd].filePos > fd_table[fd].fileSize) + { fd_table[fd].filePos = fd_table[fd].fileSize; + } return fd_table[fd].filePos; } @@ -152,8 +152,10 @@ int IsoFS_read( int fd, char *buffer, int size ) } if ((fd_table[fd].filePos + size) > fd_table[fd].fileSize) + { size = fd_table[fd].fileSize - fd_table[fd].filePos; - + } + // Now work out where we want to start reading from asector = ssector = fd_table[fd].LBA + (fd_table[fd].filePos >> 11); off_sector = (fd_table[fd].filePos & 0x7FF); @@ -179,7 +181,7 @@ int IsoFS_read( int fd, char *buffer, int size ) } memcpy_fast(buffer, lb + off_sector, ssize); } - if (asize) if (IsoFS_readSectors(asector, asize >> 11, buffer+ssize) != TRUE) + if (asize && (IsoFS_readSectors(asector, asize >> 11, buffer+ssize) != TRUE)) { ISOFS_LOG("[IsoFSdrv:read] Couldn't Read from file for some reason"); return 0; @@ -228,6 +230,7 @@ int IsoFS_close( int fd) ISOFS_LOG("[IsoFSdrv:close] ERROR: File does not appear to be open!"); return -1; } + ISOFS_LOG("[IsoFSdrv:close] internal fd %d", fd); fd_used[fd] = 0; files_open--; diff --git a/pcsx2/CDVD/IsoFStools.cpp b/pcsx2/CDVD/IsoFStools.cpp index 4ef2d6cac8..8282379782 100644 --- a/pcsx2/CDVD/IsoFStools.cpp +++ b/pcsx2/CDVD/IsoFStools.cpp @@ -113,10 +113,10 @@ void TocEntryCopy(TocEntry* tocEntry, const dirTocEntry* internalTocEntry){ filenamelen = internalTocEntry->filenameLength/2; - if (!(tocEntry->fileProperties & 0x02)){ +// if (!(tocEntry->fileProperties & 0x02)){ // strip the ;1 from the filename // filenamelen -= 2;//(Florin) nah, do not strip ;1 - } +// } for (i=0; i < filenamelen; i++) tocEntry->filename[i] = internalTocEntry->filename[(i<<1)+1]; @@ -126,10 +126,10 @@ void TocEntryCopy(TocEntry* tocEntry, const dirTocEntry* internalTocEntry){ else{ filenamelen = internalTocEntry->filenameLength; - if (!(tocEntry->fileProperties & 0x02)){ +// if (!(tocEntry->fileProperties & 0x02)){ // strip the ;1 from the filename // filenamelen -= 2;//(Florin) nah, do not strip ;1 - } +// } // use normal string copy strncpy(tocEntry->filename,internalTocEntry->filename,128); @@ -140,10 +140,7 @@ void TocEntryCopy(TocEntry* tocEntry, const dirTocEntry* internalTocEntry){ // Check if a TOC Entry matches our extension list int TocEntryCompare(char* filename, char* extensions){ static char ext_list[129]; - - char* token; - - char* ext_point; + char* token, ext_point; strncpy(ext_list,extensions,128); ext_list[128]=0; @@ -167,15 +164,9 @@ int TocEntryCompare(char* filename, char* extensions){ } -#define CD_SECS 60 /* seconds per minute */ -#define CD_FRAMES 75 /* frames per second */ -#define CD_MSF_OFFSET 150 /* MSF numbering offset of first frame */ - int IsoFS_readSectors(u32 lsn, u32 sectors, void *buf) { - u32 i; - - for (i=0; i 128) - req_entries = 128; + if (req_entries > 128) req_entries = 128; for (toc_entry_num=0; toc_entry_num < req_entries;) { diff --git a/pcsx2/CDVD/IsoFStools.h b/pcsx2/CDVD/IsoFStools.h index 6c146e4abc..93e38000bc 100644 --- a/pcsx2/CDVD/IsoFStools.h +++ b/pcsx2/CDVD/IsoFStools.h @@ -28,6 +28,10 @@ int IsoFS_initDirectoryList(char* pathname, char* extensions, unsigned int inc_dirs); int IsoFS_getDirectories(TocEntry tocEntry[], int req_entries); +#define CD_SECS 60 /* seconds per minute */ +#define CD_FRAMES 75 /* frames per second */ +#define CD_MSF_OFFSET 150 /* MSF numbering offset of first frame */ + #if defined(_MSC_VER) #pragma pack(1) #pragma warning(disable:4996) //ignore the stricmp deprecated warning diff --git a/pcsx2/CDVD/IsoFileFormats.cpp b/pcsx2/CDVD/IsoFileFormats.cpp index 25b9f3f248..22d4fdbeb1 100644 --- a/pcsx2/CDVD/IsoFileFormats.cpp +++ b/pcsx2/CDVD/IsoFileFormats.cpp @@ -205,10 +205,7 @@ isoFile *isoCreate(const char *filename, int flags) sprintf(Zfile, "%s.table", iso->filename); iso->htable = _openfile(Zfile, O_WRONLY); - if (iso->htable == NULL) - { - return NULL; - } + if (iso->htable == NULL) return NULL; } iso->handle = _openfile(iso->filename, O_WRONLY | O_CREAT); @@ -361,7 +358,7 @@ int isoReadBlock(isoFile *iso, u8 *dst, int lsn) else ret = _isoReadBlock(iso, dst, lsn); - if (ret == -1) return ret; + if (ret == -1) return -1; if (iso->type == ISOTYPE_CD) { @@ -411,7 +408,7 @@ int isoWriteBlock(isoFile *iso, u8 *src, int lsn) else ret = _isoWriteBlock(iso, src, lsn); - if (ret == -1) return ret; + if (ret == -1) return -1; return 0; } diff --git a/pcsx2/CDVD/IsoFileTools.cpp b/pcsx2/CDVD/IsoFileTools.cpp index 0fb7ea10e6..455eac513f 100644 --- a/pcsx2/CDVD/IsoFileTools.cpp +++ b/pcsx2/CDVD/IsoFileTools.cpp @@ -54,15 +54,11 @@ int _seekfile(void *handle, u64 offset, int whence) { u64 ofs = (u64)offset; PLONG _ofs = (LONG*) & ofs; + // Console::WriteLn("_seekfile %p, %d_%d", params handle, _ofs[1], _ofs[0]); - if (whence == SEEK_SET) - { - SetFilePointer(handle, _ofs[0], &_ofs[1], FILE_BEGIN); - } - else - { - SetFilePointer(handle, _ofs[0], &_ofs[1], FILE_END); - } + + SetFilePointer(handle, _ofs[0], &_ofs[1], (whence == SEEK_SET) ? FILE_BEGIN : FILE_END); + return 0; } @@ -70,9 +66,8 @@ int _readfile(void *handle, void *dst, int size) { DWORD ret; -// Console::WriteLn("_readfile %p %d", params handle, size); ReadFile(handle, dst, size, &ret, NULL); -// Console::WriteLn("_readfile ret %d; %d", params ret, GetLastError()); +// Console::WriteLn("_readfile(%p, %d) = %d; %d", params handle, size, ret, GetLastError()); return ret; } @@ -80,10 +75,9 @@ int _writefile(void *handle, void *src, int size) { DWORD ret; -// Console::WriteLn("_writefile %p, %d", params handle, size); // _seekfile(handle, _tellfile(handle)); WriteFile(handle, src, size, &ret, NULL); -// Console::WriteLn("_writefile ret %d", params ret); +// Console::WriteLn("_readfile(%p, %d) = %d", params handle, size, ret); return ret; } diff --git a/pcsx2/Console.cpp b/pcsx2/Console.cpp index abed30a619..a4eaa64c47 100644 --- a/pcsx2/Console.cpp +++ b/pcsx2/Console.cpp @@ -60,11 +60,13 @@ namespace Console bool Write( Colors color, const char* fmt, VARG_PARAM dummy, ... ) { varg_assert(); + SetColor( color ); va_list list; va_start(list,dummy); Write( vfmt_string( fmt, list ).c_str() ); va_end(list); + ClearColor(); return false; }