From b8b7e8d14db416c40799c00e7b3aedcb220c67e9 Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Mon, 13 Jul 2009 13:09:27 +0000 Subject: [PATCH] Minor code conformity cleanups and svn properties settings for new cdvd code. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1504 96395faa-99c1-11dd-bbfe-3dabce05a288 --- pcsx2/CDVD/CDVDaccess.cpp | 1066 +++++++++++++++++----------------- pcsx2/CDVD/CDVDaccess.h | 37 +- pcsx2/CDVD/CDVDisoReader.cpp | 852 +++++++++++++-------------- pcsx2/CDVD/CDVDisoReader.h | 130 ++--- pcsx2/CDVD/IsoFileFormats.h | 136 ++--- 5 files changed, 1110 insertions(+), 1111 deletions(-) diff --git a/pcsx2/CDVD/CDVDaccess.cpp b/pcsx2/CDVD/CDVDaccess.cpp index 0975fb9d0c..e183f64db5 100644 --- a/pcsx2/CDVD/CDVDaccess.cpp +++ b/pcsx2/CDVD/CDVDaccess.cpp @@ -1,531 +1,535 @@ -/* Pcsx2 - Pc Ps2 Emulator - * Copyright (C) 2002-2009 Pcsx2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include "PrecompiledHeader.h" - -// TODO: fix this for linux! (hardcoded as _WIN32 only) -#define ENABLE_TIMESTAMPS - -#include -#include - -#include "IopCommon.h" -#include "IsoFStools.h" -#include "IsoFSdrv.h" -#include "CDVDisoReader.h" - -static int diskTypeCached=-1; - -static int psize; -static int plsn=0; - -static isoFile *blockDumpFile; - -///////////////////////////////////////////////// -// -// Disk Type detection stuff (from cdvdGigaherz) -// - -int CheckDiskTypeFS(int baseType) -{ - int f; - char buffer[256];//if a file is longer...it should be shorter :D - char *pos; - static struct TocEntry tocEntry; - - IsoFS_init(); - - // check if the file exists - if (IsoFS_findFile("SYSTEM.CNF;1", &tocEntry) == TRUE) - { - f=IsoFS_open("SYSTEM.CNF;1", 1); - IsoFS_read(f, buffer, 256); - IsoFS_close(f); - - buffer[tocEntry.fileSize]='\0'; - - pos=strstr(buffer, "BOOT2"); - if (pos==NULL){ - pos=strstr(buffer, "BOOT"); - if (pos==NULL) { - return CDVD_TYPE_ILLEGAL; - } - return CDVD_TYPE_PSCD; - } - return (baseType==CDVD_TYPE_DETCTCD)?CDVD_TYPE_PS2CD:CDVD_TYPE_PS2DVD; - } - - if (IsoFS_findFile("PSX.EXE;1", &tocEntry) == TRUE) - { - return CDVD_TYPE_PSCD; - } - - if (IsoFS_findFile("VIDEO_TS/VIDEO_TS.IFO;1", &tocEntry) == TRUE) - { - return CDVD_TYPE_DVDV; - } - - return CDVD_TYPE_ILLEGAL; // << Only for discs which aren't ps2 at all. -} - -static char bleh[2352]; - -int FindDiskType(int mType) -{ - int dataTracks=0; - int audioTracks=0; - - int iCDType = CDVD_TYPE_DETCTDVDS; - - s32 mt=mType; - - cdvdTN tn; - - DoCDVDgetTN(&tn); - - if((mt<0) || ((mt == CDVD_TYPE_DETCTDVDS) && (tn.strack != tn.etrack))) - { - cdvdTD td; - DoCDVDgetTD(0,&td); - if(td.lsn>452849) - { - iCDType = CDVD_TYPE_DETCTDVDS; - } - else if(DoCDVDreadSector((u8*)bleh,16,CDVD_MODE_2048)==0) - { - struct cdVolDesc* volDesc=(struct cdVolDesc *)bleh; - if(volDesc) - { - if(volDesc->rootToc.tocSize==2048) iCDType = CDVD_TYPE_DETCTCD; - else iCDType = CDVD_TYPE_DETCTDVDS; - } - } - } - - fprintf(stderr," * CDVD Disk Open: %d tracks (%d to %d):\n",tn.etrack-tn.strack+1,tn.strack,tn.etrack); - - audioTracks=dataTracks=0; - for(int i=tn.strack;i<=tn.etrack;i++) - { - cdvdTD td,td2; - DoCDVDgetTD(i,&td); - - if(tn.etrack>i) - DoCDVDgetTD(i+1,&td2); - else - DoCDVDgetTD(0,&td2); - - int tlength = td2.lsn - td.lsn; - - if(td.type==CDVD_AUDIO_TRACK) - { - audioTracks++; - fprintf(stderr," * * Track %d: Audio (%d sectors)\n",i,tlength); - } - else - { - dataTracks++; - fprintf(stderr," * * Track %d: Data (Mode %d) (%d sectors)\n",i,((td.type==CDVD_MODE1_TRACK)?1:2),tlength); - } - } - - if(dataTracks>0) - { - iCDType=CheckDiskTypeFS(iCDType); - } - - if(audioTracks>0) - { - if(iCDType==CDVD_TYPE_PS2CD) - { - iCDType=CDVD_TYPE_PS2CDDA; - } - else if(iCDType==CDVD_TYPE_PSCD) - { - iCDType=CDVD_TYPE_PSCDDA; - } - else - { - iCDType=CDVD_TYPE_CDDA; - } - } - - return iCDType; -} - -void DetectDiskType() -{ - if (DoCDVDgetTrayStatus() == CDVD_TRAY_OPEN) - { - diskTypeCached = CDVD_TYPE_NODISC; - return; - } - - int baseMediaType = DoCDVDgetDiskType(); - int mType = -1; - - switch(baseMediaType) // Paranoid mode: do not trust the plugin's detection system to work correctly. - { - case CDVD_TYPE_CDDA: - case CDVD_TYPE_PSCD: - case CDVD_TYPE_PS2CD: - case CDVD_TYPE_PSCDDA: - case CDVD_TYPE_PS2CDDA: - mType=CDVD_TYPE_DETCTCD; - break; - case CDVD_TYPE_DVDV: - case CDVD_TYPE_PS2DVD: - mType=CDVD_TYPE_DETCTDVDS; - break; - case CDVD_TYPE_DETCTDVDS: - case CDVD_TYPE_DETCTDVDD: - case CDVD_TYPE_DETCTCD: - mType=baseMediaType; - break; - case CDVD_TYPE_NODISC: - diskTypeCached = CDVD_TYPE_NODISC; - return; - } - - diskTypeCached = FindDiskType(mType); -} - -// -///////////////////////////////////////////////// - -int cdvdInitCount=0; - -s32 DoCDVDinit() -{ - // called even when not used - ISOinit(); - - if(!loadFromISO) - { - cdvdInitCount++; // used to handle the case where the plugin was inited at boot, but then iso takes over - return CDVDinit(); - } - - diskTypeCached=-1; - - return 0; -} - -s32 DoCDVDopen(const char* pTitleFilename) -{ - int ret=0; - if(loadFromISO) - ret = ISOopen(pTitleFilename); - else - ret = CDVDopen(pTitleFilename); - - int cdtype = DoCDVDdetectDiskType(); - - if((Config.Blockdump)&&(cdtype != CDVD_TYPE_NODISC)) - { - char fname_only[MAX_PATH]; - - if(loadFromISO) - { -#ifdef _WIN32 - char fname[MAX_PATH], ext[MAX_PATH]; - _splitpath(isoFileName, NULL, NULL, fname, ext); - _makepath(fname_only, NULL, NULL, fname, NULL); -#else - char* p, *plast; - - plast = p = strchr(isoFileName, '/'); - while (p != NULL) - { - plast = p; - p = strchr(p + 1, '/'); - } - - // Lets not create dumps in the plugin directory. - strcpy(fname_only, "../"); - if (plast != NULL) - strcat(fname_only, plast + 1); - else - strcat(fname_only, isoFileName); - - plast = p = strchr(fname_only, '.'); - - while (p != NULL) - { - plast = p; - p = strchr(p + 1, '.'); - } - - if (plast != NULL) *plast = 0; -#endif - } - else - { - strcpy(fname_only, "Untitled"); - } - -#if defined(_WIN32) && defined(ENABLE_TIMESTAMPS) - SYSTEMTIME time; - GetLocalTime(&time); - - sprintf( - fname_only+strlen(fname_only), - " (%04d-%02d-%02d %02d-%02d-%02d).dump", - time.wYear, time.wMonth, time.wDay, - time.wHour, time.wMinute, time.wSecond); - - // TODO: implement this for linux -#else - strcat(fname_only, ".dump"); -#endif - cdvdTD td; - DoCDVDgetTD(0, &td); - - int blockofs=0; - int blocksize=0; - int blocks = td.lsn; - - switch(cdtype) - { - case CDVD_TYPE_PS2DVD: - case CDVD_TYPE_DVDV: - case CDVD_TYPE_DETCTDVDS: - case CDVD_TYPE_DETCTDVDD: - blockofs = 24; - blocksize = 2048; - break; - default: - blockofs = 0; - blocksize= 2352; - break; - } - - blockDumpFile = isoCreate(fname_only, ISOFLAGS_BLOCKDUMP); - if (blockDumpFile) isoSetFormat(blockDumpFile, blockofs, blocksize, blocks); - } - else - { - blockDumpFile = NULL; - } - - return ret; -} - -void DoCDVDclose() -{ - if(loadFromISO) - ISOclose(); - else - CDVDclose(); - - if (blockDumpFile != NULL) isoClose(blockDumpFile); -} - -void DoCDVDshutdown() -{ - if((!loadFromISO)||(cdvdInitCount>0)) // handle the case where the plugin was inited at boot, but then iso takes over - { - cdvdInitCount--; - if (CDVDshutdown != NULL) CDVDshutdown(); - } - - ISOshutdown(); -} - -s32 DoCDVDreadSector(u8* buffer, u32 lsn, int mode) -{ - int ret; - - if(loadFromISO) - ret = ISOreadSector(buffer,lsn,mode); - else - { - CDVDreadTrack(lsn,mode); - void* pbuffer = CDVDgetBuffer(); - if(pbuffer!=NULL) - { - switch(mode) - { - case CDVD_MODE_2048: - memcpy(buffer,pbuffer,2048); - break; - case CDVD_MODE_2328: - memcpy(buffer,pbuffer,2328); - break; - case CDVD_MODE_2340: - memcpy(buffer,pbuffer,2340); - break; - case CDVD_MODE_2352: - memcpy(buffer,pbuffer,2352); - break; - } - ret = 0; - } - else ret = -1; - } - - if(ret==0) - { - if (blockDumpFile != NULL) - { - isoWriteBlock(blockDumpFile, buffer, plsn); - } - } - return ret; -} - -s32 DoCDVDreadTrack(u32 lsn, int mode) -{ - if(loadFromISO) - return ISOreadTrack(lsn, mode); - else - { - // TEMP: until I fix all the plugins to use the new CDVDgetBuffer style - switch (mode) - { - case CDVD_MODE_2352: - psize = 2352; - break; - case CDVD_MODE_2340: - psize = 2340; - break; - case CDVD_MODE_2328: - psize = 2328; - break; - case CDVD_MODE_2048: - psize = 2048; - break; - } - return CDVDreadTrack(lsn, mode); - } -} - -// return can be NULL (for async modes) -s32 DoCDVDgetBuffer(u8* buffer) -{ - int ret; - - if(loadFromISO) - ret = ISOgetBuffer(buffer); - else - { - // TEMP: until I fix all the plugins to use this function style - u8* pb = CDVDgetBuffer(); - if(pb!=NULL) - { - memcpy(buffer,pb,psize); - ret=0; - } - else ret= -1; - } - - if(ret==0) - { - if (blockDumpFile != NULL) - { - isoWriteBlock(blockDumpFile, buffer, plsn); - } - } - return ret; -} - -s32 DoCDVDreadSubQ(u32 lsn, cdvdSubQ* subq) -{ - if(loadFromISO) - return ISOreadSubQ(lsn,subq); - else - return CDVDreadSubQ(lsn,subq); -} - -s32 DoCDVDgetTN(cdvdTN *Buffer) -{ - if(loadFromISO) - return ISOgetTN(Buffer); - else - return CDVDgetTN(Buffer); -} - -s32 DoCDVDgetTD(u8 Track, cdvdTD *Buffer) -{ - if(loadFromISO) - return ISOgetTD(Track,Buffer); - else - return CDVDgetTD(Track,Buffer); -} - -s32 DoCDVDgetTOC(void* toc) -{ - if(loadFromISO) - return ISOgetTOC(toc); - else - return CDVDgetTOC(toc); -} - -s32 DoCDVDgetDiskType() -{ - if(loadFromISO) - return ISOgetDiskType(); - else - return CDVDgetDiskType(); -} - -s32 DoCDVDdetectDiskType() -{ - if(diskTypeCached<0) - DetectDiskType(); - - return diskTypeCached; -} - -void DoCDVDresetDiskTypeCache() -{ - diskTypeCached=-1; -} - -s32 DoCDVDgetTrayStatus() -{ - if(loadFromISO) - return ISOgetTrayStatus(); - else - return CDVDgetTrayStatus(); - -} - -s32 DoCDVDctrlTrayOpen() -{ - if(loadFromISO) - return ISOctrlTrayOpen(); - else - return CDVDctrlTrayOpen(); -} - -s32 DoCDVDctrlTrayClose() -{ - if(loadFromISO) - return ISOctrlTrayClose(); - else - return CDVDctrlTrayClose(); -} - -void DoCDVDnewDiskCB(void (*callback)()) -{ - if(!loadFromISO) - { - if (CDVDnewDiskCB) CDVDnewDiskCB(callback); - } -} +/* Pcsx2 - Pc Ps2 Emulator + * Copyright (C) 2002-2009 Pcsx2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "PrecompiledHeader.h" + +// TODO: fix this for linux! (hardcoded as _WIN32 only) +#define ENABLE_TIMESTAMPS + +#ifdef _WIN32 +#include +#endif + +#include +#include + +#include "IopCommon.h" +#include "IsoFStools.h" +#include "IsoFSdrv.h" +#include "CDVDisoReader.h" + +static int diskTypeCached=-1; + +static int psize; +static int plsn=0; + +static isoFile *blockDumpFile; + +///////////////////////////////////////////////// +// +// Disk Type detection stuff (from cdvdGigaherz) +// + +int CheckDiskTypeFS(int baseType) +{ + int f; + char buffer[256];//if a file is longer...it should be shorter :D + char *pos; + static struct TocEntry tocEntry; + + IsoFS_init(); + + // check if the file exists + if (IsoFS_findFile("SYSTEM.CNF;1", &tocEntry) == TRUE) + { + f=IsoFS_open("SYSTEM.CNF;1", 1); + IsoFS_read(f, buffer, 256); + IsoFS_close(f); + + buffer[tocEntry.fileSize]='\0'; + + pos=strstr(buffer, "BOOT2"); + if (pos==NULL){ + pos=strstr(buffer, "BOOT"); + if (pos==NULL) { + return CDVD_TYPE_ILLEGAL; + } + return CDVD_TYPE_PSCD; + } + return (baseType==CDVD_TYPE_DETCTCD)?CDVD_TYPE_PS2CD:CDVD_TYPE_PS2DVD; + } + + if (IsoFS_findFile("PSX.EXE;1", &tocEntry) == TRUE) + { + return CDVD_TYPE_PSCD; + } + + if (IsoFS_findFile("VIDEO_TS/VIDEO_TS.IFO;1", &tocEntry) == TRUE) + { + return CDVD_TYPE_DVDV; + } + + return CDVD_TYPE_ILLEGAL; // << Only for discs which aren't ps2 at all. +} + +static char bleh[2352]; + +int FindDiskType(int mType) +{ + int dataTracks=0; + int audioTracks=0; + + int iCDType = CDVD_TYPE_DETCTDVDS; + + s32 mt=mType; + + cdvdTN tn; + + DoCDVDgetTN(&tn); + + if((mt<0) || ((mt == CDVD_TYPE_DETCTDVDS) && (tn.strack != tn.etrack))) + { + cdvdTD td; + DoCDVDgetTD(0,&td); + if(td.lsn>452849) + { + iCDType = CDVD_TYPE_DETCTDVDS; + } + else if(DoCDVDreadSector((u8*)bleh,16,CDVD_MODE_2048)==0) + { + struct cdVolDesc* volDesc=(struct cdVolDesc *)bleh; + if(volDesc) + { + if(volDesc->rootToc.tocSize==2048) iCDType = CDVD_TYPE_DETCTCD; + else iCDType = CDVD_TYPE_DETCTDVDS; + } + } + } + + fprintf(stderr," * CDVD Disk Open: %d tracks (%d to %d):\n",tn.etrack-tn.strack+1,tn.strack,tn.etrack); + + audioTracks=dataTracks=0; + for(int i=tn.strack;i<=tn.etrack;i++) + { + cdvdTD td,td2; + DoCDVDgetTD(i,&td); + + if(tn.etrack>i) + DoCDVDgetTD(i+1,&td2); + else + DoCDVDgetTD(0,&td2); + + int tlength = td2.lsn - td.lsn; + + if(td.type==CDVD_AUDIO_TRACK) + { + audioTracks++; + fprintf(stderr," * * Track %d: Audio (%d sectors)\n",i,tlength); + } + else + { + dataTracks++; + fprintf(stderr," * * Track %d: Data (Mode %d) (%d sectors)\n",i,((td.type==CDVD_MODE1_TRACK)?1:2),tlength); + } + } + + if(dataTracks>0) + { + iCDType=CheckDiskTypeFS(iCDType); + } + + if(audioTracks>0) + { + if(iCDType==CDVD_TYPE_PS2CD) + { + iCDType=CDVD_TYPE_PS2CDDA; + } + else if(iCDType==CDVD_TYPE_PSCD) + { + iCDType=CDVD_TYPE_PSCDDA; + } + else + { + iCDType=CDVD_TYPE_CDDA; + } + } + + return iCDType; +} + +void DetectDiskType() +{ + if (DoCDVDgetTrayStatus() == CDVD_TRAY_OPEN) + { + diskTypeCached = CDVD_TYPE_NODISC; + return; + } + + int baseMediaType = DoCDVDgetDiskType(); + int mType = -1; + + switch(baseMediaType) // Paranoid mode: do not trust the plugin's detection system to work correctly. + { + case CDVD_TYPE_CDDA: + case CDVD_TYPE_PSCD: + case CDVD_TYPE_PS2CD: + case CDVD_TYPE_PSCDDA: + case CDVD_TYPE_PS2CDDA: + mType=CDVD_TYPE_DETCTCD; + break; + case CDVD_TYPE_DVDV: + case CDVD_TYPE_PS2DVD: + mType=CDVD_TYPE_DETCTDVDS; + break; + case CDVD_TYPE_DETCTDVDS: + case CDVD_TYPE_DETCTDVDD: + case CDVD_TYPE_DETCTCD: + mType=baseMediaType; + break; + case CDVD_TYPE_NODISC: + diskTypeCached = CDVD_TYPE_NODISC; + return; + } + + diskTypeCached = FindDiskType(mType); +} + +// +///////////////////////////////////////////////// + +int cdvdInitCount=0; + +s32 DoCDVDinit() +{ + // called even when not used + ISOinit(); + + if(!loadFromISO) + { + cdvdInitCount++; // used to handle the case where the plugin was inited at boot, but then iso takes over + return CDVDinit(); + } + + diskTypeCached=-1; + + return 0; +} + +s32 DoCDVDopen(const char* pTitleFilename) +{ + int ret=0; + if(loadFromISO) + ret = ISOopen(pTitleFilename); + else + ret = CDVDopen(pTitleFilename); + + int cdtype = DoCDVDdetectDiskType(); + + if((Config.Blockdump)&&(cdtype != CDVD_TYPE_NODISC)) + { + char fname_only[MAX_PATH]; + + if(loadFromISO) + { +#ifdef _WIN32 + char fname[MAX_PATH], ext[MAX_PATH]; + _splitpath(isoFileName, NULL, NULL, fname, ext); + _makepath(fname_only, NULL, NULL, fname, NULL); +#else + char* p, *plast; + + plast = p = strchr(isoFileName, '/'); + while (p != NULL) + { + plast = p; + p = strchr(p + 1, '/'); + } + + // Lets not create dumps in the plugin directory. + strcpy(fname_only, "../"); + if (plast != NULL) + strcat(fname_only, plast + 1); + else + strcat(fname_only, isoFileName); + + plast = p = strchr(fname_only, '.'); + + while (p != NULL) + { + plast = p; + p = strchr(p + 1, '.'); + } + + if (plast != NULL) *plast = 0; +#endif + } + else + { + strcpy(fname_only, "Untitled"); + } + +#if defined(_WIN32) && defined(ENABLE_TIMESTAMPS) + SYSTEMTIME time; + GetLocalTime(&time); + + sprintf( + fname_only+strlen(fname_only), + " (%04d-%02d-%02d %02d-%02d-%02d).dump", + time.wYear, time.wMonth, time.wDay, + time.wHour, time.wMinute, time.wSecond); + + // TODO: implement this for linux +#else + strcat(fname_only, ".dump"); +#endif + cdvdTD td; + DoCDVDgetTD(0, &td); + + int blockofs=0; + int blocksize=0; + int blocks = td.lsn; + + switch(cdtype) + { + case CDVD_TYPE_PS2DVD: + case CDVD_TYPE_DVDV: + case CDVD_TYPE_DETCTDVDS: + case CDVD_TYPE_DETCTDVDD: + blockofs = 24; + blocksize = 2048; + break; + default: + blockofs = 0; + blocksize= 2352; + break; + } + + blockDumpFile = isoCreate(fname_only, ISOFLAGS_BLOCKDUMP); + if (blockDumpFile) isoSetFormat(blockDumpFile, blockofs, blocksize, blocks); + } + else + { + blockDumpFile = NULL; + } + + return ret; +} + +void DoCDVDclose() +{ + if(loadFromISO) + ISOclose(); + else + CDVDclose(); + + if (blockDumpFile != NULL) isoClose(blockDumpFile); +} + +void DoCDVDshutdown() +{ + if((!loadFromISO)||(cdvdInitCount>0)) // handle the case where the plugin was inited at boot, but then iso takes over + { + cdvdInitCount--; + if (CDVDshutdown != NULL) CDVDshutdown(); + } + + ISOshutdown(); +} + +s32 DoCDVDreadSector(u8* buffer, u32 lsn, int mode) +{ + int ret; + + if(loadFromISO) + ret = ISOreadSector(buffer,lsn,mode); + else + { + CDVDreadTrack(lsn,mode); + void* pbuffer = CDVDgetBuffer(); + if(pbuffer!=NULL) + { + switch(mode) + { + case CDVD_MODE_2048: + memcpy(buffer,pbuffer,2048); + break; + case CDVD_MODE_2328: + memcpy(buffer,pbuffer,2328); + break; + case CDVD_MODE_2340: + memcpy(buffer,pbuffer,2340); + break; + case CDVD_MODE_2352: + memcpy(buffer,pbuffer,2352); + break; + } + ret = 0; + } + else ret = -1; + } + + if(ret==0) + { + if (blockDumpFile != NULL) + { + isoWriteBlock(blockDumpFile, buffer, plsn); + } + } + return ret; +} + +s32 DoCDVDreadTrack(u32 lsn, int mode) +{ + if(loadFromISO) + return ISOreadTrack(lsn, mode); + else + { + // TEMP: until I fix all the plugins to use the new CDVDgetBuffer style + switch (mode) + { + case CDVD_MODE_2352: + psize = 2352; + break; + case CDVD_MODE_2340: + psize = 2340; + break; + case CDVD_MODE_2328: + psize = 2328; + break; + case CDVD_MODE_2048: + psize = 2048; + break; + } + return CDVDreadTrack(lsn, mode); + } +} + +// return can be NULL (for async modes) +s32 DoCDVDgetBuffer(u8* buffer) +{ + int ret; + + if(loadFromISO) + ret = ISOgetBuffer(buffer); + else + { + // TEMP: until I fix all the plugins to use this function style + u8* pb = CDVDgetBuffer(); + if(pb!=NULL) + { + memcpy(buffer,pb,psize); + ret=0; + } + else ret= -1; + } + + if(ret==0) + { + if (blockDumpFile != NULL) + { + isoWriteBlock(blockDumpFile, buffer, plsn); + } + } + return ret; +} + +s32 DoCDVDreadSubQ(u32 lsn, cdvdSubQ* subq) +{ + if(loadFromISO) + return ISOreadSubQ(lsn,subq); + else + return CDVDreadSubQ(lsn,subq); +} + +s32 DoCDVDgetTN(cdvdTN *Buffer) +{ + if(loadFromISO) + return ISOgetTN(Buffer); + else + return CDVDgetTN(Buffer); +} + +s32 DoCDVDgetTD(u8 Track, cdvdTD *Buffer) +{ + if(loadFromISO) + return ISOgetTD(Track,Buffer); + else + return CDVDgetTD(Track,Buffer); +} + +s32 DoCDVDgetTOC(void* toc) +{ + if(loadFromISO) + return ISOgetTOC(toc); + else + return CDVDgetTOC(toc); +} + +s32 DoCDVDgetDiskType() +{ + if(loadFromISO) + return ISOgetDiskType(); + else + return CDVDgetDiskType(); +} + +s32 DoCDVDdetectDiskType() +{ + if(diskTypeCached<0) + DetectDiskType(); + + return diskTypeCached; +} + +void DoCDVDresetDiskTypeCache() +{ + diskTypeCached=-1; +} + +s32 DoCDVDgetTrayStatus() +{ + if(loadFromISO) + return ISOgetTrayStatus(); + else + return CDVDgetTrayStatus(); + +} + +s32 DoCDVDctrlTrayOpen() +{ + if(loadFromISO) + return ISOctrlTrayOpen(); + else + return CDVDctrlTrayOpen(); +} + +s32 DoCDVDctrlTrayClose() +{ + if(loadFromISO) + return ISOctrlTrayClose(); + else + return CDVDctrlTrayClose(); +} + +void DoCDVDnewDiskCB(void (*callback)()) +{ + if(!loadFromISO) + { + if (CDVDnewDiskCB) CDVDnewDiskCB(callback); + } +} diff --git a/pcsx2/CDVD/CDVDaccess.h b/pcsx2/CDVD/CDVDaccess.h index 6dbafaad47..de9abb692b 100644 --- a/pcsx2/CDVD/CDVDaccess.h +++ b/pcsx2/CDVD/CDVDaccess.h @@ -19,22 +19,23 @@ #ifndef __CDVD_ACCESS_H__ #define __CDVD_ACCESS_H__ -s32 DoCDVDinit(); -s32 DoCDVDopen(const char* pTitleFilename); -void DoCDVDclose(); -void DoCDVDshutdown(); -s32 DoCDVDreadSector(u8* buffer, u32 lsn, int mode); -s32 DoCDVDreadTrack(u32 lsn, int mode); -s32 DoCDVDgetBuffer(u8* buffer); -s32 DoCDVDreadSubQ(u32 lsn, cdvdSubQ* subq); -s32 DoCDVDgetTN(cdvdTN *Buffer); -s32 DoCDVDgetTD(u8 Track, cdvdTD *Buffer); -s32 DoCDVDgetTOC(void* toc); -s32 DoCDVDgetDiskType(); -s32 DoCDVDgetTrayStatus(); -s32 DoCDVDctrlTrayOpen(); -s32 DoCDVDctrlTrayClose(); -void DoCDVDnewDiskCB(void (*callback)()); -s32 DoCDVDdetectDiskType(); -void DoCDVDresetDiskTypeCache(); +extern s32 DoCDVDinit(); +extern s32 DoCDVDopen(const char* pTitleFilename); +extern void DoCDVDclose(); +extern void DoCDVDshutdown(); +extern s32 DoCDVDreadSector(u8* buffer, u32 lsn, int mode); +extern s32 DoCDVDreadTrack(u32 lsn, int mode); +extern s32 DoCDVDgetBuffer(u8* buffer); +extern s32 DoCDVDreadSubQ(u32 lsn, cdvdSubQ* subq); +extern s32 DoCDVDgetTN(cdvdTN *Buffer); +extern s32 DoCDVDgetTD(u8 Track, cdvdTD *Buffer); +extern s32 DoCDVDgetTOC(void* toc); +extern s32 DoCDVDgetDiskType(); +extern s32 DoCDVDgetTrayStatus(); +extern s32 DoCDVDctrlTrayOpen(); +extern s32 DoCDVDctrlTrayClose(); +extern void DoCDVDnewDiskCB(void (*callback)()); +extern s32 DoCDVDdetectDiskType(); +extern void DoCDVDresetDiskTypeCache(); + #endif /* __CDVD_H__ */ diff --git a/pcsx2/CDVD/CDVDisoReader.cpp b/pcsx2/CDVD/CDVDisoReader.cpp index 7399b07928..f9869cdcda 100644 --- a/pcsx2/CDVD/CDVDisoReader.cpp +++ b/pcsx2/CDVD/CDVDisoReader.cpp @@ -1,426 +1,426 @@ -/* Pcsx2 - Pc Ps2 Emulator - * Copyright (C) 2002-2009 Pcsx2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ -/* - * Original code from libcdvd by Hiryu & Sjeep (C) 2002 - * Modified by Florin for PCSX2 emu - * Fixed CdRead by linuzappz - */ -#include "PrecompiledHeader.h" -#include -#include -#include - -#include "CDVDisoReader.h" - -bool loadFromISO=false; - -char isoFileName[256]; - -u8 *pbuffer; -int cdtype; - -int psize; - -isoFile *iso; - -FILE *cdvdLog = NULL; - -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 - - -s32 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 - - return 0; -} - -void ISOshutdown() -{ -#ifdef CDVD_LOG - if (cdvdLog != NULL) fclose(cdvdLog); -#endif -} - -s32 ISOopen(const char* pTitle) -{ - //if (pTitle != NULL) strcpy(isoFileName, pTitle); - - iso = isoOpen(isoFileName); - if (iso == NULL) - { - Console::Error("Error loading %s\n", params isoFileName); - return -1; - } - - if (iso->type == ISOTYPE_DVD) - cdtype = CDVD_TYPE_PS2DVD; - else if (iso->type == ISOTYPE_AUDIO) - cdtype = CDVD_TYPE_CDDA; - else - cdtype = CDVD_TYPE_PS2CD; - - return 0; -} - -void ISOclose() -{ - isoClose(iso); -} - -s32 ISOreadSubQ(u32 lsn, cdvdSubQ* subq) -{ - // fake it - u8 min, sec, frm; - subq->ctrl = 4; - subq->mode = 1; - subq->trackNum = itob(1); - subq->trackIndex = itob(1); - - lba_to_msf(lsn, &min, &sec, &frm); - subq->trackM = itob(min); - subq->trackS = itob(sec); - subq->trackF = itob(frm); - - subq->pad = 0; - - lba_to_msf(lsn + (2*75), &min, &sec, &frm); - subq->discM = itob(min); - subq->discS = itob(sec); - subq->discF = itob(frm); - return 0; -} - -s32 ISOgetTN(cdvdTN *Buffer) -{ - Buffer->strack = 1; - Buffer->etrack = 1; - - return 0; -} - -s32 ISOgetTD(u8 Track, cdvdTD *Buffer) -{ - if (Track == 0) - { - Buffer->lsn = iso->blocks; - } - else - { - Buffer->type = CDVD_MODE1_TRACK; - Buffer->lsn = 0; - } - - return 0; -} - -static s32 layer1start = -1; -s32 ISOgetTOC(void* toc) -{ - u8 type = CDVDgetDiskType(); - u8* tocBuff = (u8*)toc; - - //__Log("CDVDgetTOC\n"); - - if (type == CDVD_TYPE_DVDV || type == CDVD_TYPE_PS2DVD) - { - // get dvd structure format - // scsi command 0x43 - memset(tocBuff, 0, 2048); - - if (layer1start != -2 && iso->blocks >= 0x300000) - { - int off = iso->blockofs; - u8* tempbuffer; - - // dual sided - tocBuff[ 0] = 0x24; - tocBuff[ 1] = 0x02; - tocBuff[ 2] = 0xF2; - tocBuff[ 3] = 0x00; - tocBuff[ 4] = 0x41; - tocBuff[ 5] = 0x95; - - tocBuff[14] = 0x60; // dual sided, ptp - - tocBuff[16] = 0x00; - tocBuff[17] = 0x03; - tocBuff[18] = 0x00; - tocBuff[19] = 0x00; - - // search for it - if (layer1start == -1) - { - printf("CDVD: searching for layer1..."); - tempbuffer = (u8*)malloc(CD_FRAMESIZE_RAW); - for (layer1start = (iso->blocks / 2 - 0x10) & ~0xf; layer1start < 0x200010; layer1start += 16) - { - isoReadBlock(iso, tempbuffer, layer1start); - // CD001 - if (tempbuffer[off+1] == 0x43 && tempbuffer[off+2] == 0x44 && tempbuffer[off+3] == 0x30 && tempbuffer[off+4] == 0x30 && tempbuffer[off+5] == 0x31) - break; - } - free(tempbuffer); - - if (layer1start == 0x200010) - { - printf("Couldn't find second layer on dual layer... ignoring\n"); - // fake it - tocBuff[ 0] = 0x04; - tocBuff[ 1] = 0x02; - tocBuff[ 2] = 0xF2; - tocBuff[ 3] = 0x00; - tocBuff[ 4] = 0x86; - tocBuff[ 5] = 0x72; - - tocBuff[16] = 0x00; - tocBuff[17] = 0x03; - tocBuff[18] = 0x00; - tocBuff[19] = 0x00; - layer1start = -2; - return 0; - } - - printf("found at 0x%8.8x\n", layer1start); - layer1start = layer1start + 0x30000 - 1; - } - - tocBuff[20] = layer1start >> 24; - tocBuff[21] = (layer1start >> 16) & 0xff; - tocBuff[22] = (layer1start >> 8) & 0xff; - tocBuff[23] = (layer1start >> 0) & 0xff; - } - else - { - // fake it - tocBuff[ 0] = 0x04; - tocBuff[ 1] = 0x02; - tocBuff[ 2] = 0xF2; - tocBuff[ 3] = 0x00; - tocBuff[ 4] = 0x86; - tocBuff[ 5] = 0x72; - - tocBuff[16] = 0x00; - tocBuff[17] = 0x03; - tocBuff[18] = 0x00; - tocBuff[19] = 0x00; - } - } - else if ((type == CDVD_TYPE_CDDA) || (type == CDVD_TYPE_PS2CDDA) || - (type == CDVD_TYPE_PS2CD) || (type == CDVD_TYPE_PSCDDA) || (type == CDVD_TYPE_PSCD)) - { - // cd toc - // (could be replaced by 1 command that reads the full toc) - u8 min, sec, frm; - s32 i, 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; - - //Number of FirstTrack - tocBuff[2] = 0xA0; - tocBuff[7] = itob(diskInfo.strack); - - //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); - - 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); - } - } - else - return -1; - - return 0; -} - -s32 ISOreadSector(u8* tempbuffer, u32 lsn, int mode) -{ - int _lsn = lsn; - - if (_lsn < 0) - lsn = iso->blocks + _lsn; - - if(lsn > iso->blocks) - return -1; - - if(mode == CDVD_MODE_2352) - { - isoReadBlock(iso, tempbuffer, lsn); - return 0; - } - - isoReadBlock(iso, cdbuffer + iso->blockofs, lsn); - - pbuffer = cdbuffer; - switch (mode) - { - case CDVD_MODE_2352: - psize = 2352; - break; - case CDVD_MODE_2340: - pbuffer += 12; - psize = 2340; - break; - case CDVD_MODE_2328: - pbuffer += 24; - psize = 2328; - break; - case CDVD_MODE_2048: - pbuffer += 24; - psize = 2048; - break; - } - - memcpy_fast(tempbuffer,pbuffer,psize); - - return 0; -} - -s32 ISOreadTrack(u32 lsn, int mode) -{ - int _lsn = lsn; - - if (_lsn < 0) - lsn = iso->blocks + _lsn; - - if(lsn > iso->blocks) - return -1; - - isoReadBlock(iso, cdbuffer + iso->blockofs, lsn); - - pbuffer = cdbuffer; - switch (mode) - { - case CDVD_MODE_2352: - psize = 2352; - break; - case CDVD_MODE_2340: - pbuffer += 12; - psize = 2340; - break; - case CDVD_MODE_2328: - pbuffer += 24; - psize = 2328; - break; - case CDVD_MODE_2048: - pbuffer += 24; - psize = 2048; - break; - } - - return 0; -} - -s32 ISOgetBuffer(u8* buffer) -{ - memcpy_fast(buffer,pbuffer,psize); - return 0; -} - -s32 ISOgetDiskType() -{ - return cdtype; -} - -s32 ISOgetTrayStatus() -{ - return CDVD_TRAY_CLOSE; -} - -s32 ISOctrlTrayOpen() -{ - return 0; -} -s32 ISOctrlTrayClose() -{ - return 0; -} - +/* Pcsx2 - Pc Ps2 Emulator + * Copyright (C) 2002-2009 Pcsx2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ +/* + * Original code from libcdvd by Hiryu & Sjeep (C) 2002 + * Modified by Florin for PCSX2 emu + * Fixed CdRead by linuzappz + */ +#include "PrecompiledHeader.h" +#include +#include +#include + +#include "CDVDisoReader.h" + +bool loadFromISO=false; + +char isoFileName[256]; + +u8 *pbuffer; +int cdtype; + +int psize; + +isoFile *iso; + +FILE *cdvdLog = NULL; + +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 + + +s32 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 + + return 0; +} + +void ISOshutdown() +{ +#ifdef CDVD_LOG + if (cdvdLog != NULL) fclose(cdvdLog); +#endif +} + +s32 ISOopen(const char* pTitle) +{ + //if (pTitle != NULL) strcpy(isoFileName, pTitle); + + iso = isoOpen(isoFileName); + if (iso == NULL) + { + Console::Error("Error loading %s\n", params isoFileName); + return -1; + } + + if (iso->type == ISOTYPE_DVD) + cdtype = CDVD_TYPE_PS2DVD; + else if (iso->type == ISOTYPE_AUDIO) + cdtype = CDVD_TYPE_CDDA; + else + cdtype = CDVD_TYPE_PS2CD; + + return 0; +} + +void ISOclose() +{ + isoClose(iso); +} + +s32 ISOreadSubQ(u32 lsn, cdvdSubQ* subq) +{ + // fake it + u8 min, sec, frm; + subq->ctrl = 4; + subq->mode = 1; + subq->trackNum = itob(1); + subq->trackIndex = itob(1); + + lba_to_msf(lsn, &min, &sec, &frm); + subq->trackM = itob(min); + subq->trackS = itob(sec); + subq->trackF = itob(frm); + + subq->pad = 0; + + lba_to_msf(lsn + (2*75), &min, &sec, &frm); + subq->discM = itob(min); + subq->discS = itob(sec); + subq->discF = itob(frm); + return 0; +} + +s32 ISOgetTN(cdvdTN *Buffer) +{ + Buffer->strack = 1; + Buffer->etrack = 1; + + return 0; +} + +s32 ISOgetTD(u8 Track, cdvdTD *Buffer) +{ + if (Track == 0) + { + Buffer->lsn = iso->blocks; + } + else + { + Buffer->type = CDVD_MODE1_TRACK; + Buffer->lsn = 0; + } + + return 0; +} + +static s32 layer1start = -1; +s32 ISOgetTOC(void* toc) +{ + u8 type = CDVDgetDiskType(); + u8* tocBuff = (u8*)toc; + + //__Log("CDVDgetTOC\n"); + + if (type == CDVD_TYPE_DVDV || type == CDVD_TYPE_PS2DVD) + { + // get dvd structure format + // scsi command 0x43 + memset(tocBuff, 0, 2048); + + if (layer1start != -2 && iso->blocks >= 0x300000) + { + int off = iso->blockofs; + u8* tempbuffer; + + // dual sided + tocBuff[ 0] = 0x24; + tocBuff[ 1] = 0x02; + tocBuff[ 2] = 0xF2; + tocBuff[ 3] = 0x00; + tocBuff[ 4] = 0x41; + tocBuff[ 5] = 0x95; + + tocBuff[14] = 0x60; // dual sided, ptp + + tocBuff[16] = 0x00; + tocBuff[17] = 0x03; + tocBuff[18] = 0x00; + tocBuff[19] = 0x00; + + // search for it + if (layer1start == -1) + { + printf("CDVD: searching for layer1..."); + tempbuffer = (u8*)malloc(CD_FRAMESIZE_RAW); + for (layer1start = (iso->blocks / 2 - 0x10) & ~0xf; layer1start < 0x200010; layer1start += 16) + { + isoReadBlock(iso, tempbuffer, layer1start); + // CD001 + if (tempbuffer[off+1] == 0x43 && tempbuffer[off+2] == 0x44 && tempbuffer[off+3] == 0x30 && tempbuffer[off+4] == 0x30 && tempbuffer[off+5] == 0x31) + break; + } + free(tempbuffer); + + if (layer1start == 0x200010) + { + printf("Couldn't find second layer on dual layer... ignoring\n"); + // fake it + tocBuff[ 0] = 0x04; + tocBuff[ 1] = 0x02; + tocBuff[ 2] = 0xF2; + tocBuff[ 3] = 0x00; + tocBuff[ 4] = 0x86; + tocBuff[ 5] = 0x72; + + tocBuff[16] = 0x00; + tocBuff[17] = 0x03; + tocBuff[18] = 0x00; + tocBuff[19] = 0x00; + layer1start = -2; + return 0; + } + + printf("found at 0x%8.8x\n", layer1start); + layer1start = layer1start + 0x30000 - 1; + } + + tocBuff[20] = layer1start >> 24; + tocBuff[21] = (layer1start >> 16) & 0xff; + tocBuff[22] = (layer1start >> 8) & 0xff; + tocBuff[23] = (layer1start >> 0) & 0xff; + } + else + { + // fake it + tocBuff[ 0] = 0x04; + tocBuff[ 1] = 0x02; + tocBuff[ 2] = 0xF2; + tocBuff[ 3] = 0x00; + tocBuff[ 4] = 0x86; + tocBuff[ 5] = 0x72; + + tocBuff[16] = 0x00; + tocBuff[17] = 0x03; + tocBuff[18] = 0x00; + tocBuff[19] = 0x00; + } + } + else if ((type == CDVD_TYPE_CDDA) || (type == CDVD_TYPE_PS2CDDA) || + (type == CDVD_TYPE_PS2CD) || (type == CDVD_TYPE_PSCDDA) || (type == CDVD_TYPE_PSCD)) + { + // cd toc + // (could be replaced by 1 command that reads the full toc) + u8 min, sec, frm; + s32 i, 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; + + //Number of FirstTrack + tocBuff[2] = 0xA0; + tocBuff[7] = itob(diskInfo.strack); + + //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); + + 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); + } + } + else + return -1; + + return 0; +} + +s32 ISOreadSector(u8* tempbuffer, u32 lsn, int mode) +{ + int _lsn = lsn; + + if (_lsn < 0) + lsn = iso->blocks + _lsn; + + if(lsn > iso->blocks) + return -1; + + if(mode == CDVD_MODE_2352) + { + isoReadBlock(iso, tempbuffer, lsn); + return 0; + } + + isoReadBlock(iso, cdbuffer + iso->blockofs, lsn); + + pbuffer = cdbuffer; + switch (mode) + { + case CDVD_MODE_2352: + psize = 2352; + break; + case CDVD_MODE_2340: + pbuffer += 12; + psize = 2340; + break; + case CDVD_MODE_2328: + pbuffer += 24; + psize = 2328; + break; + case CDVD_MODE_2048: + pbuffer += 24; + psize = 2048; + break; + } + + memcpy_fast(tempbuffer,pbuffer,psize); + + return 0; +} + +s32 ISOreadTrack(u32 lsn, int mode) +{ + int _lsn = lsn; + + if (_lsn < 0) + lsn = iso->blocks + _lsn; + + if(lsn > iso->blocks) + return -1; + + isoReadBlock(iso, cdbuffer + iso->blockofs, lsn); + + pbuffer = cdbuffer; + switch (mode) + { + case CDVD_MODE_2352: + psize = 2352; + break; + case CDVD_MODE_2340: + pbuffer += 12; + psize = 2340; + break; + case CDVD_MODE_2328: + pbuffer += 24; + psize = 2328; + break; + case CDVD_MODE_2048: + pbuffer += 24; + psize = 2048; + break; + } + + return 0; +} + +s32 ISOgetBuffer(u8* buffer) +{ + memcpy_fast(buffer,pbuffer,psize); + return 0; +} + +s32 ISOgetDiskType() +{ + return cdtype; +} + +s32 ISOgetTrayStatus() +{ + return CDVD_TRAY_CLOSE; +} + +s32 ISOctrlTrayOpen() +{ + return 0; +} +s32 ISOctrlTrayClose() +{ + return 0; +} + diff --git a/pcsx2/CDVD/CDVDisoReader.h b/pcsx2/CDVD/CDVDisoReader.h index e3776a0018..509aebc8c8 100644 --- a/pcsx2/CDVD/CDVDisoReader.h +++ b/pcsx2/CDVD/CDVDisoReader.h @@ -1,70 +1,64 @@ -/* Pcsx2 - Pc Ps2 Emulator -* Copyright (C) 2002-2009 Pcsx2 Team -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -*/ - -#ifndef __CDVD_ISO_READER_H__ -#define __CDVD_ISO_READER_H__ - -#ifdef _MSC_VER -#pragma warning(disable:4018) -#endif - -#include - -#ifdef _WIN32 -#include -#endif - -#include "IopCommon.h" -#include "IsoFStools.h" +/* Pcsx2 - Pc Ps2 Emulator +* Copyright (C) 2002-2009 Pcsx2 Team +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +*/ + +#ifndef __CDVD_ISO_READER_H__ +#define __CDVD_ISO_READER_H__ + +#ifdef _MSC_VER +#pragma warning(disable:4018) +#endif + +#include + +#include "IopCommon.h" +#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[256]; - -//extern isoFile *blockDumpFile; -extern isoFile *iso; - -s32 ISOinit(); -void ISOshutdown(); -s32 ISOopen(const char* pTitle); -void ISOclose(); -s32 ISOreadSubQ(u32 lsn, cdvdSubQ* subq); -s32 ISOgetTN(cdvdTN *Buffer); -s32 ISOgetTD(u8 tn, cdvdTD *Buffer); -s32 ISOgetDiskType(); -s32 ISOgetTrayStatus(); -s32 ISOctrlTrayOpen(); -s32 ISOctrlTrayClose(); -s32 ISOreadSector(u8* tempbuffer, u32 lsn, int mode); -s32 ISOgetTOC(void* toc); -s32 ISOreadTrack(u32 lsn, int mode); -s32 ISOgetBuffer(u8* buffer); - + +#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[256]; +extern isoFile *iso; + +extern s32 ISOinit(); +extern void ISOshutdown(); +extern s32 ISOopen(const char* pTitle); +extern void ISOclose(); +extern s32 ISOreadSubQ(u32 lsn, cdvdSubQ* subq); +extern s32 ISOgetTN(cdvdTN *Buffer); +extern s32 ISOgetTD(u8 tn, cdvdTD *Buffer); +extern s32 ISOgetDiskType(); +extern s32 ISOgetTrayStatus(); +extern s32 ISOctrlTrayOpen(); +extern s32 ISOctrlTrayClose(); +extern s32 ISOreadSector(u8* tempbuffer, u32 lsn, int mode); +extern s32 ISOgetTOC(void* toc); +extern s32 ISOreadTrack(u32 lsn, int mode); +extern s32 ISOgetBuffer(u8* buffer); + #endif \ No newline at end of file diff --git a/pcsx2/CDVD/IsoFileFormats.h b/pcsx2/CDVD/IsoFileFormats.h index 3187b2ded0..074663aa45 100644 --- a/pcsx2/CDVD/IsoFileFormats.h +++ b/pcsx2/CDVD/IsoFileFormats.h @@ -1,68 +1,68 @@ -#ifndef __LIBISO_H__ -#define __LIBISO_H__ - -#ifdef _MSC_VER -#pragma warning(disable:4018) -#endif - -#define ISOTYPE_ILLEGAL 0 -#define ISOTYPE_CD 1 -#define ISOTYPE_DVD 2 -#define ISOTYPE_AUDIO 3 -#define ISOTYPE_DVDDL 4 - -#define ISOFLAGS_Z 0x0001 -#define ISOFLAGS_Z2 0x0002 -#define ISOFLAGS_BLOCKDUMP 0x0004 -#define ISOFLAGS_MULTI 0x0008 -#define ISOFLAGS_BZ2 0x0010 - -#define CD_FRAMESIZE_RAW 2352 -#define DATA_SIZE (CD_FRAMESIZE_RAW-12) - -#define itob(i) ((i)/10*16 + (i)%10) /* u_char to BCD */ -#define btoi(b) ((b)/16*10 + (b)%16) /* BCD to u_char */ - -typedef struct -{ - u32 slsn; - u32 elsn; - void *handle; -} _multih; - -typedef struct -{ - char filename[256]; - u32 type; - u32 flags; - u32 offset; - u32 blockofs; - u32 blocksize; - u32 blocks; - void *handle; - void *htable; - char *Ztable; - u32 *dtable; - int dtablesize; - _multih multih[8]; - int buflsn; - u8 *buffer; -} isoFile; - - -isoFile *isoOpen(const char *filename); -isoFile *isoCreate(const char *filename, int mode); -int isoSetFormat(isoFile *iso, int blockofs, int blocksize, int blocks); -int isoDetect(isoFile *iso); -int isoReadBlock(isoFile *iso, u8 *dst, int lsn); -int isoWriteBlock(isoFile *iso, u8 *src, int lsn); -void isoClose(isoFile *iso); - -void *_openfile(const char *filename, int flags); -u64 _tellfile(void *handle); -int _seekfile(void *handle, u64 offset, int whence); -int _readfile(void *handle, void *dst, int size); -int _writefile(void *handle, void *src, int size); -void _closefile(void *handle); - -#endif /* __LIBISO_H__ */ +#ifndef __LIBISO_H__ +#define __LIBISO_H__ + +#ifdef _MSC_VER +#pragma warning(disable:4018) +#endif + +#define ISOTYPE_ILLEGAL 0 +#define ISOTYPE_CD 1 +#define ISOTYPE_DVD 2 +#define ISOTYPE_AUDIO 3 +#define ISOTYPE_DVDDL 4 + +#define ISOFLAGS_Z 0x0001 +#define ISOFLAGS_Z2 0x0002 +#define ISOFLAGS_BLOCKDUMP 0x0004 +#define ISOFLAGS_MULTI 0x0008 +#define ISOFLAGS_BZ2 0x0010 + +#define CD_FRAMESIZE_RAW 2352 +#define DATA_SIZE (CD_FRAMESIZE_RAW-12) + +#define itob(i) ((i)/10*16 + (i)%10) /* u_char to BCD */ +#define btoi(b) ((b)/16*10 + (b)%16) /* BCD to u_char */ + +typedef struct +{ + u32 slsn; + u32 elsn; + void *handle; +} _multih; + +typedef struct +{ + char filename[256]; + u32 type; + u32 flags; + u32 offset; + u32 blockofs; + u32 blocksize; + u32 blocks; + void *handle; + void *htable; + char *Ztable; + u32 *dtable; + int dtablesize; + _multih multih[8]; + int buflsn; + u8 *buffer; +} isoFile; + + +isoFile *isoOpen(const char *filename); +isoFile *isoCreate(const char *filename, int mode); +int isoSetFormat(isoFile *iso, int blockofs, int blocksize, int blocks); +int isoDetect(isoFile *iso); +int isoReadBlock(isoFile *iso, u8 *dst, int lsn); +int isoWriteBlock(isoFile *iso, u8 *src, int lsn); +void isoClose(isoFile *iso); + +void *_openfile(const char *filename, int flags); +u64 _tellfile(void *handle); +int _seekfile(void *handle, u64 offset, int whence); +int _readfile(void *handle, void *dst, int size); +int _writefile(void *handle, void *src, int size); +void _closefile(void *handle); + +#endif /* __LIBISO_H__ */