mirror of https://github.com/PCSX2/pcsx2.git
Since pcsx2 itself can now identify the specific disk type based on the base media type, cdvdGigaherz does not need to replicate the same work anymore.
This means cdvdGigaherz builds will no longer work on older versions of pcsx2 from before I integrated the detection code into the emu. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2155 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
parent
8bed2e5ff3
commit
909714d08e
|
@ -1,119 +0,0 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "CDVD.h"
|
||||
#include "isofs/CDVDlib.h"
|
||||
#include "isofs/CDVDiso.h"
|
||||
#include "isofs/CDVDisodrv.h"
|
||||
|
||||
char buffer[2048]; //if the file is longer...it should be shorter :D
|
||||
|
||||
int CheckDiskType(int baseType)
|
||||
{
|
||||
int f;
|
||||
char *pos;
|
||||
static struct TocEntry tocEntry;
|
||||
|
||||
CDVDFS_init();
|
||||
|
||||
// check if the file exists
|
||||
if (CDVD_findfile("SYSTEM.CNF;1", &tocEntry) == TRUE)
|
||||
{
|
||||
f=CDVDFS_open("SYSTEM.CNF;1", 1);
|
||||
CDVDFS_read(f, buffer, 2047);
|
||||
CDVDFS_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 (CDVD_findfile("PSX.EXE;1", &tocEntry) == TRUE)
|
||||
{
|
||||
return CDVD_TYPE_PSCD;
|
||||
}
|
||||
|
||||
if (CDVD_findfile("VIDEO_TS/VIDEO_TS.IFO;1", &tocEntry) == TRUE)
|
||||
{
|
||||
return CDVD_TYPE_DVDV;
|
||||
}
|
||||
|
||||
return CDVD_TYPE_ILLEGAL;
|
||||
}
|
||||
|
||||
char bleh[2352];
|
||||
|
||||
int FindDiskType()
|
||||
{
|
||||
int dataTracks=0;
|
||||
int audioTracks=0;
|
||||
|
||||
int iCDType = CDVD_TYPE_DETCTDVDS;
|
||||
|
||||
s32 mt=cdvdGetMediaType();
|
||||
|
||||
if(mt<0)
|
||||
{
|
||||
if(tracks[0].length>452849)
|
||||
{
|
||||
iCDType = CDVD_TYPE_DETCTDVDS;
|
||||
}
|
||||
else if(cdvdDirectReadSector(16,CDVD_MODE_2048,bleh)==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",etrack-strack+1,strack,etrack);
|
||||
|
||||
audioTracks=dataTracks=0;
|
||||
for(int i=strack;i<=etrack;i++)
|
||||
{
|
||||
if(tracks[i].type==CDVD_AUDIO_TRACK)
|
||||
{
|
||||
audioTracks++;
|
||||
fprintf(stderr," * * Track %d: Audio (%d sectors)\n",i,tracks[i].length);
|
||||
}
|
||||
else
|
||||
{
|
||||
dataTracks++;
|
||||
fprintf(stderr," * * Track %d: Data (Mode %d) (%d sectors)\n",i,((tracks[i].type==CDVD_MODE1_TRACK)?1:2),tracks[i].length);
|
||||
}
|
||||
}
|
||||
|
||||
if(dataTracks>0)
|
||||
{
|
||||
iCDType=CheckDiskType(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;
|
||||
}
|
|
@ -419,26 +419,20 @@ s32 cdvdRefreshData()
|
|||
}
|
||||
else
|
||||
{
|
||||
curDiskType = FindDiskType();
|
||||
s32 mt=cdvdGetMediaType();
|
||||
|
||||
if(mt<0) curDiskType = CDVD_TYPE_DETCTCD;
|
||||
else if(mt == 0) curDiskType = CDVD_TYPE_DETCTDVDS;
|
||||
else curDiskType = CDVD_TYPE_DETCTDVDD;
|
||||
}
|
||||
|
||||
curTrayStatus = CDVD_TRAY_CLOSE;
|
||||
|
||||
switch(curDiskType)
|
||||
{
|
||||
case CDVD_TYPE_ILLEGAL: diskTypeName="Illegal Disc"; break;
|
||||
case CDVD_TYPE_DVDV: diskTypeName="DVD-Video"; break;
|
||||
case CDVD_TYPE_CDDA: diskTypeName="CD-Audio"; break;
|
||||
case CDVD_TYPE_PS2DVD: diskTypeName="PS2 DVD"; break;
|
||||
case CDVD_TYPE_PS2CDDA: diskTypeName="PS2 CD+Audio"; break;
|
||||
case CDVD_TYPE_PS2CD: diskTypeName="PS2 CD"; break;
|
||||
case CDVD_TYPE_PSCDDA: diskTypeName="PS1 CD+Audio"; break;
|
||||
case CDVD_TYPE_PSCD: diskTypeName="PS1 CD"; break;
|
||||
case CDVD_TYPE_UNKNOWN: diskTypeName="Unknown"; break;
|
||||
case CDVD_TYPE_DETCTDVDD: diskTypeName="Detecting (Single-Layer DVD)"; break;
|
||||
case CDVD_TYPE_DETCTDVDS: diskTypeName="Detecting (Double-Layer DVD)"; break;
|
||||
case CDVD_TYPE_DETCTCD: diskTypeName="Detecting (CD)"; break;
|
||||
case CDVD_TYPE_DETCT: diskTypeName="Detecting"; break;
|
||||
case CDVD_TYPE_DETCTDVDD: diskTypeName="Single-Layer DVD"; break;
|
||||
case CDVD_TYPE_DETCTDVDS: diskTypeName="Double-Layer DVD"; break;
|
||||
case CDVD_TYPE_DETCTCD: diskTypeName="CD-ROM"; break;
|
||||
case CDVD_TYPE_NODISC: diskTypeName="No Disc"; break;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Version="9,00"
|
||||
Name="cdvdGigaherz"
|
||||
ProjectGUID="{5CF88D5F-64DD-4EDC-9F1A-436BD502940A}"
|
||||
RootNamespace="cdvdGigaherz"
|
||||
|
@ -170,10 +170,6 @@
|
|||
RelativePath="..\CDVD.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\CheckDiskType.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\config.cpp"
|
||||
>
|
||||
|
@ -194,18 +190,6 @@
|
|||
RelativePath="..\TocStuff.cpp"
|
||||
>
|
||||
</File>
|
||||
<Filter
|
||||
Name="isofs"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\isofs\CDVDiso.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\isofs\CDVDisodrv.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
|
|
|
@ -1,825 +0,0 @@
|
|||
/*
|
||||
* Original code from libcdvd by Hiryu & Sjeep (C) 2002
|
||||
* Modified by Florin for PCSX2 emu
|
||||
* Fixed CdRead by linuzappz
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#ifdef __LINUX__
|
||||
#define strnicmp strncasecmp
|
||||
#endif
|
||||
|
||||
#include "CDVDiso.h"
|
||||
#include "CDVDisodrv.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
|
||||
struct dir_toc_data{
|
||||
unsigned int start_LBA;
|
||||
unsigned int num_sectors;
|
||||
unsigned int num_entries;
|
||||
unsigned int current_entry;
|
||||
unsigned int current_sector;
|
||||
unsigned int current_sector_offset;
|
||||
unsigned int inc_dirs;
|
||||
unsigned char extension_list[128+1];
|
||||
};
|
||||
|
||||
//static u8 cdVolDescriptor[2048];
|
||||
static struct dir_toc_data getDirTocData;
|
||||
static struct cdVolDesc CDVolDesc;
|
||||
|
||||
extern s32 cdvdDirectReadSector(s32 first, s32 mode, char *buffer);
|
||||
|
||||
void _splitpath2(const char *constpath, char *dir, char *fname){
|
||||
// 255 char max path-length is an ISO9660 restriction
|
||||
// we must change this for Joliet or relaxed iso restriction support
|
||||
static char pathcopy[1024+1];
|
||||
|
||||
char* slash;
|
||||
|
||||
strncpy(pathcopy, constpath, 1024);
|
||||
pathcopy[1024]=0;
|
||||
|
||||
slash = strrchr (pathcopy, '/');
|
||||
|
||||
// if the path doesn't contain a '/' then look for a '\'
|
||||
if (!slash)
|
||||
slash = strrchr (pathcopy, (int)'\\');
|
||||
|
||||
// if a slash was found
|
||||
if (slash != NULL)
|
||||
{
|
||||
// null terminate the path
|
||||
slash[0] = 0;
|
||||
// and copy the path into 'dir'
|
||||
strncpy(dir, pathcopy, 1024);
|
||||
dir[255]=0;
|
||||
|
||||
// copy the filename into 'fname'
|
||||
strncpy(fname, slash+1, 128);
|
||||
fname[128]=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
dir[0] = 0;
|
||||
|
||||
strncpy(fname, pathcopy, 128);
|
||||
fname[128]=0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Used in findfile
|
||||
int strcasecmp(const char *s1, const char *s2){
|
||||
while (*s1 != '\0' && tolower(*s1) == tolower(*s2))
|
||||
{
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
return tolower(*(unsigned char *) s1) - tolower(*(unsigned char *) s2);
|
||||
}
|
||||
|
||||
// Copy a TOC Entry from the CD native format to our tidier format
|
||||
void TocEntryCopy(struct TocEntry* tocEntry, struct dirTocEntry* internalTocEntry){
|
||||
int i;
|
||||
int filenamelen;
|
||||
|
||||
tocEntry->fileSize = internalTocEntry->fileSize;
|
||||
tocEntry->fileLBA = internalTocEntry->fileLBA;
|
||||
tocEntry->fileProperties = internalTocEntry->fileProperties;
|
||||
memcpy(tocEntry->date, internalTocEntry->dateStamp, 6);
|
||||
tocEntry->date[6]=0;
|
||||
|
||||
if (CDVolDesc.filesystemType == 2){
|
||||
// This is a Joliet Filesystem, so use Unicode to ISO string copy
|
||||
|
||||
filenamelen = internalTocEntry->filenameLength/2;
|
||||
|
||||
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];
|
||||
|
||||
tocEntry->filename[filenamelen] = 0;
|
||||
}
|
||||
else{
|
||||
filenamelen = internalTocEntry->filenameLength;
|
||||
|
||||
if (!(tocEntry->fileProperties & 0x02)){
|
||||
// strip the ;1 from the filename
|
||||
// filenamelen -= 2;//(Florin) nah, do not strip ;1
|
||||
}
|
||||
|
||||
// use normal string copy
|
||||
strncpy((char*)tocEntry->filename,(char*)internalTocEntry->filename,128);
|
||||
tocEntry->filename[filenamelen] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
strncpy(ext_list,extensions,128);
|
||||
ext_list[128]=0;
|
||||
|
||||
token = strtok( ext_list, " ," );
|
||||
while( token != NULL )
|
||||
{
|
||||
// if 'token' matches extension of 'filename'
|
||||
// then return a match
|
||||
ext_point = strrchr(filename,'.');
|
||||
|
||||
if (_strnicmp(ext_point, token, strlen(token)) == 0)
|
||||
return (TRUE);
|
||||
|
||||
/* Get next token: */
|
||||
token = strtok( NULL, " ," );
|
||||
}
|
||||
|
||||
// If not match found then return FALSE
|
||||
return (FALSE);
|
||||
|
||||
}
|
||||
|
||||
#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 CdRead(u32 lsn, u32 sectors, void *buf, CdRMode *mode){
|
||||
u32 i;
|
||||
int rmode;
|
||||
|
||||
switch (mode->datapattern) {
|
||||
case CdSecS2048:
|
||||
rmode = CDVD_MODE_2048; break;
|
||||
case CdSecS2328:
|
||||
rmode = CDVD_MODE_2328; break;
|
||||
case CdSecS2340:
|
||||
rmode = CDVD_MODE_2340; break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i=0; i<sectors; i++)
|
||||
{
|
||||
switch (mode->datapattern)
|
||||
{
|
||||
case CdSecS2048:
|
||||
if(cdvdDirectReadSector(lsn+i, rmode, (char*)buf+2048*i))
|
||||
return 0;
|
||||
case CdSecS2328:
|
||||
if(cdvdDirectReadSector(lsn+i, rmode, (char*)buf+2328*i))
|
||||
return 0;
|
||||
case CdSecS2340:
|
||||
if(cdvdDirectReadSector(lsn+i, rmode, (char*)buf+2340*i))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int DvdRead(u32 lsn, u32 sectors, void *buf, CdRMode *mode){
|
||||
u32 i;
|
||||
|
||||
for (i=lsn; i<(lsn+sectors); i++)
|
||||
{
|
||||
((u32*)buf)[0] = i + 0x30000;
|
||||
|
||||
if(cdvdDirectReadSector(lsn+i, CDVD_MODE_2048,(char*)buf+12))
|
||||
return 0;
|
||||
|
||||
buf=((u8*)buf)+2064; break;
|
||||
// default:
|
||||
// return 0;
|
||||
// }
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**************************************************************
|
||||
* The functions below are not exported for normal file-system *
|
||||
* operations, but are used by the file-system operations, and *
|
||||
* may also be exported for use via RPC *
|
||||
**************************************************************/
|
||||
|
||||
int CDVD_GetVolumeDescriptor(void){
|
||||
// Read until we find the last valid Volume Descriptor
|
||||
int volDescSector;
|
||||
|
||||
static struct cdVolDesc localVolDesc;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("CDVD_GetVolumeDescriptor called\n");
|
||||
#endif
|
||||
|
||||
for (volDescSector = 16; volDescSector<20; volDescSector++)
|
||||
{
|
||||
CdRead(volDescSector,1,&localVolDesc,&cdReadMode);
|
||||
// CdSync(0x00);
|
||||
|
||||
// If this is still a volume Descriptor
|
||||
if (strncmp((char*)localVolDesc.volID, "CD001", 5) == 0)
|
||||
{
|
||||
if ((localVolDesc.filesystemType == 1) ||
|
||||
(localVolDesc.filesystemType == 2))
|
||||
{
|
||||
memcpy(&CDVolDesc, &localVolDesc, sizeof(struct cdVolDesc));
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (CDVolDesc.filesystemType == 1)
|
||||
printf("CD FileSystem is ISO9660\n");
|
||||
else if (CDVolDesc.filesystemType == 2)
|
||||
printf("CD FileSystem is Joliet\n");
|
||||
else printf("Could not detect CD FileSystem type\n");
|
||||
#endif
|
||||
// CdStop();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int CDVD_findfile(char* fname, struct TocEntry* tocEntry){
|
||||
static char filename[128+1];
|
||||
static char pathname[1024+1];
|
||||
static char toc[2048];
|
||||
char* dirname;
|
||||
|
||||
|
||||
static struct TocEntry localTocEntry; // used for internal checking only
|
||||
|
||||
int found_dir;
|
||||
|
||||
int num_dir_sectors;
|
||||
int current_sector;
|
||||
|
||||
int dir_lba;
|
||||
|
||||
struct dirTocEntry* tocEntryPointer;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("CDVD_findfile called\n");
|
||||
#endif
|
||||
|
||||
//make sure we have good cdReadMode
|
||||
cdReadMode.trycount = 0;
|
||||
cdReadMode.spindlctrl = CdSpinStm;
|
||||
cdReadMode.datapattern = CdSecS2048;
|
||||
|
||||
_splitpath2(fname, pathname, filename);
|
||||
|
||||
// Find the TOC for a specific directory
|
||||
if (CDVD_GetVolumeDescriptor() != TRUE){
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("Could not get CD Volume Descriptor\n");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Read the TOC of the root directory
|
||||
if (CdRead(CDVolDesc.rootToc.tocLBA,1,toc,&cdReadMode) != TRUE){
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("Couldn't Read from CD !\n");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
//CdSync(0x00);
|
||||
|
||||
// point the tocEntryPointer at the first real toc entry
|
||||
tocEntryPointer = (dirTocEntry*)toc;
|
||||
|
||||
num_dir_sectors = (tocEntryPointer->fileSize+2047) >> 11; //round up fix
|
||||
current_sector = tocEntryPointer->fileLBA;
|
||||
|
||||
tocEntryPointer = (dirTocEntry*)(((char*)tocEntryPointer)+tocEntryPointer->length);
|
||||
tocEntryPointer = (dirTocEntry*)(((char*)tocEntryPointer)+tocEntryPointer->length);
|
||||
|
||||
|
||||
localTocEntry.fileLBA = CDVolDesc.rootToc.tocLBA;
|
||||
// while (there are more dir names in the path)
|
||||
dirname = strtok( pathname, "\\/" );
|
||||
|
||||
while( dirname != NULL )
|
||||
{
|
||||
found_dir = FALSE;
|
||||
/*
|
||||
while(tocEntryPointer->length > 0)
|
||||
{
|
||||
// while there are still more directory entries then search through
|
||||
// for the one we want
|
||||
|
||||
if (tocEntryPointer->fileProperties & 0x02)
|
||||
{
|
||||
// Copy the CD format TOC Entry to our format
|
||||
TocEntryCopy(&localTocEntry, tocEntryPointer);
|
||||
|
||||
// If this TOC Entry is a directory,
|
||||
// then see if it has the right name
|
||||
if (strcasecmp(dirname,localTocEntry.filename) == 0)
|
||||
{
|
||||
// if the name matches then we've found the directory
|
||||
found_dir = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// point to the next entry
|
||||
(char*)tocEntryPointer += tocEntryPointer->length;
|
||||
}
|
||||
*/
|
||||
while(1)
|
||||
{
|
||||
if ((tocEntryPointer->length == 0) || (((char*)tocEntryPointer-toc)>=2048))
|
||||
{
|
||||
num_dir_sectors--;
|
||||
|
||||
if (num_dir_sectors > 0)
|
||||
{
|
||||
// If we've run out of entries, but arent on the last sector
|
||||
// then load another sector
|
||||
|
||||
current_sector++;
|
||||
if (CdRead(current_sector,1,toc,&cdReadMode) != TRUE)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
// CdSync(0x00);
|
||||
|
||||
tocEntryPointer = (dirTocEntry*)toc;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Couldnt find the directory, and got to end of directory
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (tocEntryPointer->fileProperties & 0x02)
|
||||
{
|
||||
TocEntryCopy(&localTocEntry, tocEntryPointer);
|
||||
|
||||
// If this TOC Entry is a directory,
|
||||
// then see if it has the right name
|
||||
if (strcmp(dirname,(char*)localTocEntry.filename) == 0)
|
||||
{
|
||||
// if the name matches then we've found the directory
|
||||
found_dir = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// point to the next entry
|
||||
tocEntryPointer = (dirTocEntry*)(((char*)tocEntryPointer)+tocEntryPointer->length);
|
||||
}
|
||||
|
||||
// If we havent found the directory name we wanted then fail
|
||||
if (found_dir != TRUE)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get next directory name
|
||||
dirname = strtok( NULL, "\\/" );
|
||||
|
||||
// Read the TOC of the found subdirectory
|
||||
if (CdRead(localTocEntry.fileLBA,1,toc,&cdReadMode) != TRUE)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
// CdSync(0x00);
|
||||
|
||||
num_dir_sectors = (localTocEntry.fileSize+2047) >> 11; //round up fix
|
||||
current_sector = localTocEntry.fileLBA;
|
||||
|
||||
// and point the tocEntryPointer at the first real toc entry
|
||||
tocEntryPointer = (dirTocEntry*)toc;
|
||||
tocEntryPointer = (dirTocEntry*)(((char*)tocEntryPointer)+tocEntryPointer->length);
|
||||
tocEntryPointer = (dirTocEntry*)(((char*)tocEntryPointer)+tocEntryPointer->length);
|
||||
}
|
||||
|
||||
tocEntryPointer = (dirTocEntry*)toc;
|
||||
|
||||
num_dir_sectors = (tocEntryPointer->fileSize+2047) >> 11; //round up fix
|
||||
dir_lba = tocEntryPointer->fileLBA;
|
||||
|
||||
tocEntryPointer = (dirTocEntry*)toc;
|
||||
tocEntryPointer = (dirTocEntry*)(((char*)tocEntryPointer)+tocEntryPointer->length);
|
||||
tocEntryPointer = (dirTocEntry*)(((char*)tocEntryPointer)+tocEntryPointer->length);
|
||||
|
||||
while (num_dir_sectors > 0)
|
||||
{
|
||||
while(tocEntryPointer->length != 0)
|
||||
{
|
||||
// Copy the CD format TOC Entry to our format
|
||||
TocEntryCopy(&localTocEntry, tocEntryPointer);
|
||||
|
||||
if ((_strnicmp((char*)localTocEntry.filename, filename, strlen(filename)) == 0) ||
|
||||
((filename[strlen(filename)-2] == ';') &&
|
||||
(localTocEntry.filename[strlen((char*)localTocEntry.filename)-2] == ';') &&
|
||||
(_strnicmp((char*)localTocEntry.filename, filename, strlen(filename)-2) == 0)))
|
||||
{
|
||||
// if the filename matches then copy the toc Entry
|
||||
tocEntry->fileLBA = localTocEntry.fileLBA;
|
||||
tocEntry->fileProperties = localTocEntry.fileProperties;
|
||||
tocEntry->fileSize = localTocEntry.fileSize;
|
||||
|
||||
strcpy((char*)tocEntry->filename, (char*)localTocEntry.filename);
|
||||
memcpy((char*)tocEntry->date, (char*)localTocEntry.date, 7);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("CDVD_findfile: found file\n");
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
tocEntryPointer = (dirTocEntry*)(((char*)tocEntryPointer)+tocEntryPointer->length);
|
||||
}
|
||||
|
||||
num_dir_sectors--;
|
||||
|
||||
if (num_dir_sectors > 0)
|
||||
{
|
||||
dir_lba++;
|
||||
|
||||
if (CdRead(dir_lba,1,toc,&cdReadMode) != TRUE){
|
||||
return -1;
|
||||
}
|
||||
// CdSync(0x00);
|
||||
|
||||
tocEntryPointer = (dirTocEntry*)toc;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// This is the RPC-ready function which takes the request to start the tocEntry retrieval
|
||||
int CDVD_GetDir_RPC_request(char* pathname, char* extensions, unsigned int inc_dirs){
|
||||
// int dir_depth = 1;
|
||||
static char toc[2048];
|
||||
char* dirname;
|
||||
int found_dir;
|
||||
int num_dir_sectors;
|
||||
unsigned int toc_entry_num;
|
||||
struct dirTocEntry* tocEntryPointer;
|
||||
static struct TocEntry localTocEntry;
|
||||
int current_sector;
|
||||
|
||||
// store the extension list statically for the retrieve function
|
||||
strncpy((char*)getDirTocData.extension_list, extensions, 128);
|
||||
getDirTocData.extension_list[128]=0;
|
||||
|
||||
getDirTocData.inc_dirs = inc_dirs;
|
||||
|
||||
// Find the TOC for a specific directory
|
||||
if (CDVD_GetVolumeDescriptor() != TRUE){
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[RPC:cdvd] Could not get CD Volume Descriptor\n");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[RPC:cdvd] Getting Directory Listing for: \"%s\"\n", pathname);
|
||||
#endif
|
||||
|
||||
// Read the TOC of the root directory
|
||||
if (CdRead(CDVolDesc.rootToc.tocLBA,1,toc,&cdReadMode) != TRUE){
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[RPC: ] Couldn't Read from CD !\n");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
//CdSync(0x00);
|
||||
|
||||
// point the tocEntryPointer at the first real toc entry
|
||||
tocEntryPointer = (dirTocEntry*)toc;
|
||||
|
||||
num_dir_sectors = (tocEntryPointer->fileSize+2047) >> 11;
|
||||
current_sector = tocEntryPointer->fileLBA;
|
||||
|
||||
tocEntryPointer = (dirTocEntry*)(((char*)tocEntryPointer)+tocEntryPointer->length);
|
||||
tocEntryPointer = (dirTocEntry*)(((char*)tocEntryPointer)+tocEntryPointer->length);
|
||||
|
||||
// use strtok to get the next dir name
|
||||
|
||||
// if there isnt one, then assume we want the LBA
|
||||
// for the current one, and exit the while loop
|
||||
|
||||
// if there is another dir name then increment dir_depth
|
||||
// and look through dir table entries until we find the right name
|
||||
// if we dont find the right name
|
||||
// before finding an entry at a higher level (lower num), then return nothing
|
||||
|
||||
localTocEntry.fileLBA = CDVolDesc.rootToc.tocLBA;
|
||||
|
||||
// while (there are more dir names in the path)
|
||||
dirname = strtok( pathname, "\\/" );
|
||||
while( dirname != NULL ){
|
||||
found_dir = FALSE;
|
||||
|
||||
while(1){
|
||||
if ((tocEntryPointer->length == 0) || (((char*)tocEntryPointer-toc)>=2048)) {
|
||||
num_dir_sectors--;
|
||||
|
||||
if (num_dir_sectors > 0){
|
||||
// If we've run out of entries, but arent on the last sector
|
||||
// then load another sector
|
||||
|
||||
current_sector++;
|
||||
if (CdRead(current_sector,1,toc,&cdReadMode) != TRUE){
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[RPC: ] Couldn't Read from CD !\n");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
//CdSync(0x00);
|
||||
|
||||
tocEntryPointer = (dirTocEntry*)toc;
|
||||
}
|
||||
else{
|
||||
// Couldnt find the directory, and got to end of directory
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (tocEntryPointer->fileProperties & 0x02){
|
||||
TocEntryCopy(&localTocEntry, tocEntryPointer);
|
||||
|
||||
// If this TOC Entry is a directory,
|
||||
// then see if it has the right name
|
||||
if (strcmp(dirname,(char*)localTocEntry.filename) == 0){
|
||||
// if the name matches then we've found the directory
|
||||
found_dir = TRUE;
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[RPC: ] Found directory %s in subdir at sector %d\n",dirname,current_sector);
|
||||
RPC_LOG("[RPC: ] LBA of found subdirectory = %d\n",localTocEntry.fileLBA);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// point to the next entry
|
||||
tocEntryPointer = (dirTocEntry*)(((char*)tocEntryPointer)+tocEntryPointer->length);
|
||||
}
|
||||
|
||||
// If we havent found the directory name we wanted then fail
|
||||
if (found_dir != TRUE)
|
||||
return -1;
|
||||
|
||||
// Get next directory name
|
||||
dirname = strtok( NULL, "\\/" );
|
||||
|
||||
// Read the TOC of the found subdirectory
|
||||
if (CdRead(localTocEntry.fileLBA,1,toc,&cdReadMode) != TRUE){
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[RPC: ] Couldn't Read from CD !\n");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
//CdSync(0x00);
|
||||
|
||||
num_dir_sectors = (localTocEntry.fileSize+2047) >> 11;
|
||||
current_sector = localTocEntry.fileLBA;
|
||||
|
||||
// and point the tocEntryPointer at the first real toc entry
|
||||
tocEntryPointer = (dirTocEntry*)toc;
|
||||
tocEntryPointer = (dirTocEntry*)(((char*)tocEntryPointer)+tocEntryPointer->length);
|
||||
tocEntryPointer = (dirTocEntry*)(((char*)tocEntryPointer)+tocEntryPointer->length);
|
||||
}
|
||||
|
||||
// We know how much data we need to read in from the DirTocHeader
|
||||
// but we need to read in at least 1 sector before we can get this value
|
||||
|
||||
// Now we need to COUNT the number of entries (dont do anything with info at this point)
|
||||
// so set the tocEntryPointer to point to the first actual file entry
|
||||
|
||||
// This is a bit of a waste of reads since we're not actually copying the data out yet,
|
||||
// but we dont know how big this TOC might be, so we cant allocate a specific size
|
||||
|
||||
tocEntryPointer = (dirTocEntry*)toc;
|
||||
|
||||
// Need to STORE the start LBA and number of Sectors, for use by the retrieve func.
|
||||
getDirTocData.start_LBA = localTocEntry.fileLBA;
|
||||
getDirTocData.num_sectors = (tocEntryPointer->fileSize+2047) >> 11;
|
||||
getDirTocData.num_entries = 0;
|
||||
getDirTocData.current_entry = 0;
|
||||
getDirTocData.current_sector = getDirTocData.start_LBA;
|
||||
getDirTocData.current_sector_offset = 0;
|
||||
|
||||
num_dir_sectors = getDirTocData.num_sectors;
|
||||
|
||||
tocEntryPointer = (dirTocEntry*)toc;
|
||||
tocEntryPointer = (dirTocEntry*)(((char*)tocEntryPointer)+tocEntryPointer->length);
|
||||
tocEntryPointer = (dirTocEntry*)(((char*)tocEntryPointer)+tocEntryPointer->length);
|
||||
|
||||
toc_entry_num=0;
|
||||
|
||||
while(1){
|
||||
if ((tocEntryPointer->length == 0) || (((char*)tocEntryPointer-toc)>=2048)){
|
||||
// decrease the number of dirs remaining
|
||||
num_dir_sectors--;
|
||||
|
||||
if (num_dir_sectors > 0){
|
||||
// If we've run out of entries, but arent on the last sector
|
||||
// then load another sector
|
||||
getDirTocData.current_sector++;
|
||||
|
||||
if (CdRead(getDirTocData.current_sector,1,toc,&cdReadMode) != TRUE){
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[RPC: ] Couldn't Read from CD !\n");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
//CdSync(0x00);
|
||||
|
||||
tocEntryPointer = (dirTocEntry*)toc;
|
||||
|
||||
// continue;
|
||||
}
|
||||
else{
|
||||
getDirTocData.num_entries = toc_entry_num;
|
||||
getDirTocData.current_sector = getDirTocData.start_LBA;
|
||||
return (toc_entry_num);
|
||||
}
|
||||
}
|
||||
|
||||
// We've found a file/dir in this directory
|
||||
// now check if it matches our extension list (if there is one)
|
||||
TocEntryCopy(&localTocEntry, tocEntryPointer);
|
||||
|
||||
if (localTocEntry.fileProperties & 0x02){
|
||||
// If this is a subdir, then check if we want to include subdirs
|
||||
if (getDirTocData.inc_dirs){
|
||||
toc_entry_num++;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (strlen((char*)getDirTocData.extension_list) > 0){
|
||||
if (TocEntryCompare((char*)localTocEntry.filename, (char*)getDirTocData.extension_list) == TRUE){
|
||||
// increment the number of matching entries counter
|
||||
toc_entry_num++;
|
||||
}
|
||||
}
|
||||
else{
|
||||
toc_entry_num++;
|
||||
}
|
||||
}
|
||||
|
||||
tocEntryPointer = (dirTocEntry*)(((char*)tocEntryPointer)+tocEntryPointer->length);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// THIS SHOULD BE UNREACHABLE -
|
||||
// since we are trying to count ALL matching entries, rather than upto a limit
|
||||
|
||||
|
||||
// STORE total number of TOC entries
|
||||
getDirTocData.num_entries = toc_entry_num;
|
||||
getDirTocData.current_sector = getDirTocData.start_LBA;
|
||||
|
||||
|
||||
// we've reached the toc entry limit, so return how many we've done
|
||||
return (toc_entry_num);
|
||||
|
||||
}
|
||||
|
||||
// This function can be called repeatedly after CDVD_GetDir_RPC_request to get the actual entries
|
||||
// buffer (tocEntry) must be 18KB in size, and this will be filled with a maximum of 128 entries in one go
|
||||
int CDVD_GetDir_RPC_get_entries(struct TocEntry tocEntry[], int req_entries){
|
||||
static char toc[2048];
|
||||
int toc_entry_num;
|
||||
|
||||
struct dirTocEntry* tocEntryPointer;
|
||||
|
||||
if (CdRead(getDirTocData.current_sector,1,toc,&cdReadMode) != TRUE){
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[RPC:cdvd] Couldn't Read from CD !\n");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
//CdSync(0x00);
|
||||
|
||||
if (getDirTocData.current_entry == 0){
|
||||
// if this is the first read then make sure we point to the first real entry
|
||||
tocEntryPointer = (dirTocEntry*)toc;
|
||||
tocEntryPointer = (dirTocEntry*)(((char*)tocEntryPointer)+tocEntryPointer->length);
|
||||
tocEntryPointer = (dirTocEntry*)(((char*)tocEntryPointer)+tocEntryPointer->length);
|
||||
|
||||
getDirTocData.current_sector_offset = (char*)tocEntryPointer - toc;
|
||||
}
|
||||
else{
|
||||
tocEntryPointer = (dirTocEntry*)(toc + getDirTocData.current_sector_offset);
|
||||
}
|
||||
|
||||
if (req_entries > 128)
|
||||
req_entries = 128;
|
||||
|
||||
for (toc_entry_num=0; toc_entry_num < req_entries;){
|
||||
if ((tocEntryPointer->length == 0) || (getDirTocData.current_sector_offset >= 2048)){
|
||||
// decrease the number of dirs remaining
|
||||
getDirTocData.num_sectors--;
|
||||
|
||||
if (getDirTocData.num_sectors > 0){
|
||||
// If we've run out of entries, but arent on the last sector
|
||||
// then load another sector
|
||||
getDirTocData.current_sector++;
|
||||
|
||||
if (CdRead(getDirTocData.current_sector,1,toc,&cdReadMode) != TRUE){
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[RPC:cdvd] Couldn't Read from CD !\n");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
//CdSync(0x00);
|
||||
|
||||
getDirTocData.current_sector_offset = 0;
|
||||
tocEntryPointer = (dirTocEntry*)(toc + getDirTocData.current_sector_offset);
|
||||
|
||||
// continue;
|
||||
}
|
||||
else{
|
||||
return (toc_entry_num);
|
||||
}
|
||||
}
|
||||
|
||||
// This must be incremented even if the filename doesnt match extension list
|
||||
getDirTocData.current_entry++;
|
||||
|
||||
// We've found a file in this directory
|
||||
// now check if it matches our extension list (if there is one)
|
||||
|
||||
// Copy the entry regardless, as it makes the comparison easier
|
||||
// if it doesn't match then it will just be overwritten
|
||||
TocEntryCopy(&tocEntry[toc_entry_num], tocEntryPointer);
|
||||
|
||||
if (tocEntry[toc_entry_num].fileProperties & 0x02){
|
||||
// If this is a subdir, then check if we want to include subdirs
|
||||
if (getDirTocData.inc_dirs) {
|
||||
toc_entry_num++;
|
||||
}
|
||||
|
||||
getDirTocData.current_sector_offset += tocEntryPointer->length;
|
||||
tocEntryPointer = (dirTocEntry*)(toc + getDirTocData.current_sector_offset);
|
||||
}
|
||||
else{
|
||||
if (strlen((char*)getDirTocData.extension_list) > 0){
|
||||
if (TocEntryCompare((char*)tocEntry[toc_entry_num].filename, (char*)getDirTocData.extension_list) == TRUE){
|
||||
// increment the number of matching entries counter
|
||||
toc_entry_num++;
|
||||
}
|
||||
|
||||
getDirTocData.current_sector_offset += tocEntryPointer->length;
|
||||
tocEntryPointer = (dirTocEntry*)(toc + getDirTocData.current_sector_offset);
|
||||
|
||||
}
|
||||
else{
|
||||
toc_entry_num++;
|
||||
getDirTocData.current_sector_offset += tocEntryPointer->length;
|
||||
tocEntryPointer = (dirTocEntry*)(toc + getDirTocData.current_sector_offset);
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (strlen(getDirTocData.extension_list) > 0)
|
||||
{
|
||||
if (TocEntryCompare(tocEntry[toc_entry_num].filename, getDirTocData.extension_list) == TRUE)
|
||||
{
|
||||
|
||||
// increment this here, rather than in the main for loop
|
||||
// since this should count the number of matching entries
|
||||
toc_entry_num++;
|
||||
}
|
||||
|
||||
getDirTocData.current_sector_offset += tocEntryPointer->length;
|
||||
(char*)tocEntryPointer = toc + getDirTocData.current_sector_offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
toc_entry_num++;
|
||||
getDirTocData.current_sector_offset += tocEntryPointer->length;
|
||||
(char*)tocEntryPointer = toc + getDirTocData.current_sector_offset;
|
||||
}
|
||||
*/
|
||||
}
|
||||
return (toc_entry_num);
|
||||
}
|
|
@ -1,131 +0,0 @@
|
|||
/*
|
||||
* Original code from libcdvd by Hiryu & Sjeep (C) 2002
|
||||
* Modified by Florin for PCSX2 emu
|
||||
*/
|
||||
|
||||
#ifndef __CDVDISO_H__
|
||||
#define __CDVDISO_H__
|
||||
|
||||
#include "CDVDlib.h"
|
||||
|
||||
int CDVD_findfile(char* fname, struct TocEntry* tocEntry);
|
||||
int CDVD_GetDir_RPC_request(char* pathname, char* extensions, unsigned int inc_dirs);
|
||||
int CDVD_GetDir_RPC_get_entries(struct TocEntry tocEntry[], int req_entries);
|
||||
|
||||
#if defined(__WIN32__)
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
||||
struct rootDirTocHeader
|
||||
{
|
||||
u16 length; //+00
|
||||
u32 tocLBA; //+02
|
||||
u32 tocLBA_bigend; //+06
|
||||
u32 tocSize; //+0A
|
||||
u32 tocSize_bigend; //+0E
|
||||
u8 dateStamp[8]; //+12
|
||||
u8 reserved[6]; //+1A
|
||||
u8 reserved2; //+20
|
||||
u8 reserved3; //+21
|
||||
#if defined(__WIN32__)
|
||||
}; //+22
|
||||
#else
|
||||
} __attribute__((packed));
|
||||
#endif
|
||||
|
||||
struct asciiDate
|
||||
{
|
||||
char year[4];
|
||||
char month[2];
|
||||
char day[2];
|
||||
char hours[2];
|
||||
char minutes[2];
|
||||
char seconds[2];
|
||||
char hundreths[2];
|
||||
char terminator[1];
|
||||
#if defined(__WIN32__)
|
||||
};
|
||||
#else
|
||||
} __attribute__((packed));
|
||||
#endif
|
||||
|
||||
struct cdVolDesc
|
||||
{
|
||||
u8 filesystemType; // 0x01 = ISO9660, 0x02 = Joliet, 0xFF = NULL
|
||||
u8 volID[5]; // "CD001"
|
||||
u8 reserved2;
|
||||
u8 reserved3;
|
||||
u8 sysIdName[32];
|
||||
u8 volName[32]; // The ISO9660 Volume Name
|
||||
u8 reserved5[8];
|
||||
u32 volSize; // Volume Size
|
||||
u32 volSizeBig; // Volume Size Big-Endian
|
||||
u8 reserved6[32];
|
||||
u32 unknown1;
|
||||
u32 unknown1_bigend;
|
||||
u16 volDescSize; //+80
|
||||
u16 volDescSize_bigend; //+82
|
||||
u32 unknown3; //+84
|
||||
u32 unknown3_bigend; //+88
|
||||
u32 priDirTableLBA; // LBA of Primary Dir Table //+8C
|
||||
u32 reserved7; //+90
|
||||
u32 secDirTableLBA; // LBA of Secondary Dir Table //+94
|
||||
u32 reserved8; //+98
|
||||
struct rootDirTocHeader rootToc;
|
||||
u8 volSetName[128];
|
||||
u8 publisherName[128];
|
||||
u8 preparerName[128];
|
||||
u8 applicationName[128];
|
||||
u8 copyrightFileName[37];
|
||||
u8 abstractFileName[37];
|
||||
u8 bibliographyFileName[37];
|
||||
struct asciiDate creationDate;
|
||||
struct asciiDate modificationDate;
|
||||
struct asciiDate effectiveDate;
|
||||
struct asciiDate expirationDate;
|
||||
u8 reserved10;
|
||||
u8 reserved11[1166];
|
||||
#if defined(__WIN32__)
|
||||
};
|
||||
#else
|
||||
} __attribute__((packed));
|
||||
#endif
|
||||
|
||||
struct dirTableEntry
|
||||
{
|
||||
u8 dirNameLength;
|
||||
u8 reserved;
|
||||
u32 dirTOCLBA;
|
||||
u16 dirDepth;
|
||||
u8 dirName[32];
|
||||
#if defined(__WIN32__)
|
||||
};
|
||||
#else
|
||||
} __attribute__((packed));
|
||||
#endif
|
||||
|
||||
struct dirTocEntry
|
||||
{
|
||||
short length;
|
||||
unsigned int fileLBA;
|
||||
unsigned int fileLBA_bigend;
|
||||
unsigned int fileSize;
|
||||
unsigned int fileSize_bigend;
|
||||
unsigned char dateStamp[6];
|
||||
unsigned char reserved1;
|
||||
unsigned char fileProperties;
|
||||
unsigned char reserved2[6];
|
||||
unsigned char filenameLength;
|
||||
unsigned char filename[128];
|
||||
#if defined(__WIN32__)
|
||||
};
|
||||
#else
|
||||
} __attribute__((packed));
|
||||
#endif // This is the internal format on the CD
|
||||
// TocEntry structure contains only the important stuff needed for export
|
||||
|
||||
#if defined(__WIN32__)
|
||||
#pragma pack()
|
||||
#endif
|
||||
|
||||
#endif//__CDVDISO_H__
|
|
@ -1,269 +0,0 @@
|
|||
/*
|
||||
* Original code from libcdvd by Hiryu & Sjeep (C) 2002
|
||||
* Modified by Florin for PCSX2 emu
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "CDVDlib.h"
|
||||
#include "CDVDiso.h"
|
||||
#include "CDVDisodrv.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
|
||||
#define min(x,y) (((y)<(x))?(x):(y))
|
||||
|
||||
CdRMode cdReadMode;
|
||||
|
||||
struct fdtable{
|
||||
//int fd;
|
||||
int fileSize;
|
||||
int LBA;
|
||||
int filePos;
|
||||
};
|
||||
|
||||
static struct fdtable fd_table[16];
|
||||
static int fd_used[16];
|
||||
static int files_open=0;
|
||||
static int inited=FALSE;
|
||||
|
||||
/*************************************************************
|
||||
* The functions below are the normal file-system operations, *
|
||||
* used to provide a standard filesystem interface *
|
||||
*************************************************************/
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// CDVDFS_init
|
||||
// called by 80000592 sceCdInit()
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
void CDVDFS_init(){
|
||||
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[CDVDisodrv:init] CDVD Filesystem v1.00\n");
|
||||
RPC_LOG("[CDVDisodrv ] \tby A.Lee (aka Hiryu) & Nicholas Van Veen (aka Sjeep)\n");
|
||||
RPC_LOG("[CDVDisodrv ] Initializing '%s' file driver.\n", "cdfs");
|
||||
#endif
|
||||
|
||||
//CdInit(0); already called by plugin loading system ;)
|
||||
|
||||
cdReadMode.trycount = 0;
|
||||
cdReadMode.spindlctrl = CdSpinStm;
|
||||
cdReadMode.datapattern = CdSecS2048; //isofs driver only needs
|
||||
//2KB sectors
|
||||
|
||||
memset(fd_table, 0, sizeof(fd_table));
|
||||
memset(fd_used, 0, 16*sizeof(int));
|
||||
|
||||
inited = TRUE;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// CDVDFS_open
|
||||
// called by 80000001 fileio_open for devices: "cdrom:", "cdrom0:"
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
int CDVDFS_open(char *name, int mode){
|
||||
register int j;
|
||||
static struct TocEntry tocEntry;
|
||||
|
||||
// check if the file exists
|
||||
if (CDVD_findfile(name, &tocEntry) != TRUE)
|
||||
return -1;
|
||||
|
||||
if(mode != 1) return -2; //SCE_RDONLY
|
||||
|
||||
// set up a new file descriptor
|
||||
for(j=0; j < 16; j++) if(fd_used[j] == 0) break;
|
||||
if(j >= 16) return -3;
|
||||
|
||||
fd_used[j] = 1;
|
||||
files_open++;
|
||||
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[CDVDisodrv:open] internal fd=%d\n", j);
|
||||
#endif
|
||||
|
||||
fd_table[j].fileSize = tocEntry.fileSize;
|
||||
fd_table[j].LBA = tocEntry.fileLBA;
|
||||
fd_table[j].filePos = 0;
|
||||
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[CDVDisodrv ] tocEntry.fileSize = %d\n",tocEntry.fileSize);
|
||||
#endif
|
||||
|
||||
return j;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// CDVDFS_lseek
|
||||
// called by 80000001 fileio_lseek for devices: "cdrom:", "cdrom0:"
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
int CDVDFS_lseek(int fd, int offset, int whence){
|
||||
|
||||
if ((fd >= 16) || (fd_used[fd]==0)){
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[CDVDisodrv:lseek] ERROR: File does not appear to be open!\n");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch(whence){
|
||||
case SEEK_SET:
|
||||
fd_table[fd].filePos = offset;
|
||||
break;
|
||||
|
||||
case SEEK_CUR:
|
||||
fd_table[fd].filePos += offset;
|
||||
break;
|
||||
|
||||
case SEEK_END:
|
||||
fd_table[fd].filePos = fd_table[fd].fileSize + offset;
|
||||
break;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fd_table[fd].filePos < 0)
|
||||
fd_table[fd].filePos = 0;
|
||||
|
||||
if (fd_table[fd].filePos > fd_table[fd].fileSize)
|
||||
fd_table[fd].filePos = fd_table[fd].fileSize;
|
||||
|
||||
return fd_table[fd].filePos;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// CDVDFS_read
|
||||
// called by 80000001 fileio_read for devices: "cdrom:", "cdrom0:", "cdfs:"
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
int CDVDFS_read( int fd, char *buffer, int size ){
|
||||
// int start_sector;
|
||||
int off_sector;
|
||||
// int num_sectors;
|
||||
|
||||
//static char local_buffer[2024*2048]; //4MB
|
||||
static char lb[2048]; //2KB
|
||||
//Start, Aligned, End
|
||||
int ssector, asector, esector;
|
||||
int ssize=0, asize, esize;
|
||||
|
||||
if ((fd >= 16) || (fd_used[fd]==0)){
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[CDVDisodrv:read] ERROR: File does not appear to be open!\n");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
// A few sanity checks
|
||||
if (fd_table[fd].filePos > fd_table[fd].fileSize){
|
||||
// We cant start reading from past the beginning of the file
|
||||
return 0; // File exists but we couldnt read anything from it
|
||||
}
|
||||
|
||||
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);
|
||||
if (off_sector){
|
||||
ssize = min(2048 - off_sector, size);
|
||||
size -= ssize;
|
||||
asector++;
|
||||
}
|
||||
asize = size & 0xFFFFF800;
|
||||
esize = size & 0x000007FF;
|
||||
esector=asector + (asize >> 11);
|
||||
size += ssize;
|
||||
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[CDVDisodrv:read] read sectors 0x%08X to 0x%08X\n", ssector, esector-(esize==0));
|
||||
#endif
|
||||
|
||||
if (ssize){ if (CdRead(ssector, 1, lb, &cdReadMode) != TRUE){
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[CDVDisodrv: ] Couldn't Read from file for some reason\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
memcpy(buffer, lb + off_sector, ssize);
|
||||
}
|
||||
if (asize) if (CdRead(asector, asize >> 11, buffer+ssize, &cdReadMode) != TRUE){
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[CDVDisodrv: ] Couldn't Read from file for some reason\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
if (esize){ if (CdRead(esector, 1, lb, &cdReadMode) != TRUE){
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[CDVDisodrv: ] Couldn't Read from file for some reason\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
memcpy(buffer+ssize+asize, lb, esize);
|
||||
}
|
||||
/***********************
|
||||
// Now work out where we want to start reading from
|
||||
start_sector = fd_table[fd].LBA + (fd_table[fd].filePos >> 11);
|
||||
off_sector = (fd_table[fd].filePos & 0x7FF);
|
||||
num_sectors = ((off_sector + size) >> 11) + 1;
|
||||
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[CDVDisodrv:read] read sectors 0x%08X to 0x%08X\n",start_sector,start_sector+num_sectors);
|
||||
#endif
|
||||
|
||||
// Read the data (we only ever get 16KB max request at once)
|
||||
if (CdRead(start_sector, num_sectors, local_buffer, &cdReadMode) != TRUE){
|
||||
#ifdef RPC_LOG
|
||||
//RPC_LOG("sector = %d, start sector = %d\n",sector,start_sector);
|
||||
RPC_LOG("[CDVDisodrv: ] Couldn't Read from file for some reason\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
//CdSync(0); hm, a wait function maybe...
|
||||
|
||||
memcpy(buffer,local_buffer+off_sector,size);
|
||||
**************************/
|
||||
fd_table[fd].filePos += size;
|
||||
|
||||
return (size);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// CDVDFS_write
|
||||
// called by 80000001 fileio_write for devices: "cdrom:", "cdrom0:"
|
||||
// hehe, this ain't a CD writing option :D
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
int CDVDFS_write( int fd, char * buffer, int size ){
|
||||
if(size == 0) return 0;
|
||||
else return -1;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// CDVDFS_close
|
||||
// called by 80000001 fileio_close for devices: "cdrom:", "cdrom0:"
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
int CDVDFS_close( int fd){
|
||||
|
||||
if ((fd >= 16) || (fd_used[fd]==0)){
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[CDVDisodrv:close] ERROR: File does not appear to be open!\n");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef RPC_LOG
|
||||
RPC_LOG("[CDVDisodrv:close] internal fd %d\n", fd);
|
||||
#endif
|
||||
|
||||
fd_used[fd] = 0;
|
||||
files_open--;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
/*
|
||||
* Original code from libcdvd by Hiryu & Sjeep (C) 2002
|
||||
* Modified by Florin for PCSX2 emu
|
||||
*/
|
||||
|
||||
#ifndef __CDVDISODRV_H__
|
||||
#define __CDVDISODRV_H__
|
||||
|
||||
//#include "Common.h"
|
||||
#include "CDVDlib.h"
|
||||
|
||||
extern CdRMode cdReadMode;
|
||||
|
||||
/* Filing-system exported functions */
|
||||
void CDVDFS_init();
|
||||
int CDVDFS_open(char *name, int mode);
|
||||
int CDVDFS_lseek(int fd, int offset, int whence);
|
||||
int CDVDFS_read( int fd, char * buffer, int size );
|
||||
int CDVDFS_write( int fd, char * buffer, int size );
|
||||
int CDVDFS_close( int fd);
|
||||
|
||||
#endif//__CDVDISODRV_H__
|
|
@ -1,186 +0,0 @@
|
|||
/*
|
||||
* Original code from libcdvd by Hiryu & Sjeep (C) 2002
|
||||
* Linux kernel headers
|
||||
* Modified by Florin for PCSX2 emu
|
||||
*/
|
||||
|
||||
#ifndef _CDVDLIB_H
|
||||
#define _CDVDLIB_H
|
||||
|
||||
#define CDVDdefs
|
||||
#include <PS2Edefs.h>
|
||||
|
||||
// Macros for READ Data pattan
|
||||
#define CdSecS2048 0 // sector size 2048
|
||||
#define CdSecS2328 1 // sector size 2328
|
||||
#define CdSecS2340 2 // sector size 2340
|
||||
|
||||
//#define CD_FRAMESIZE_RAW1 (CD_FRAMESIZE_RAW-CD_SYNC_SIZE) /*2340*/
|
||||
//#define CD_FRAMESIZE_RAW0 (CD_FRAMESIZE_RAW-CD_SYNC_SIZE-CD_HEAD_SIZE) /*2336*/
|
||||
//#define CD_HEAD_SIZE 4 /* header (address) bytes per raw data frame */
|
||||
//#define CD_SUBHEAD_SIZE 8 /* subheader bytes per raw XA data frame */
|
||||
//#define CD_XA_HEAD (CD_HEAD_SIZE+CD_SUBHEAD_SIZE) /* "before data" part of raw XA frame */
|
||||
|
||||
/*
|
||||
* A CD-ROM physical sector size is 2048, 2052, 2056, 2324, 2332, 2336,
|
||||
* 2340, or 2352 bytes long.
|
||||
* Sector types of the standard CD-ROM data formats:
|
||||
*
|
||||
* format sector type user data size (bytes)
|
||||
* -----------------------------------------------------------------------------
|
||||
* 1 (Red Book) CD-DA 2352 (CD_FRAMESIZE_RAW)
|
||||
* 2 (Yellow Book) Mode1 Form1 2048 (CD_FRAMESIZE)
|
||||
* 3 (Yellow Book) Mode1 Form2 2336 (CD_FRAMESIZE_RAW0)
|
||||
* 4 (Green Book) Mode2 Form1 2048 (CD_FRAMESIZE)
|
||||
* 5 (Green Book) Mode2 Form2 2328 (2324+4 spare bytes)
|
||||
*
|
||||
*
|
||||
* The layout of the standard CD-ROM data formats:
|
||||
* -----------------------------------------------------------------------------
|
||||
* - audio (red): | audio_sample_bytes |
|
||||
* | 2352 |
|
||||
*
|
||||
* - data (yellow, mode1): | sync - head - data - EDC - zero - ECC |
|
||||
* | 12 - 4 - 2048 - 4 - 8 - 276 |
|
||||
*
|
||||
* - data (yellow, mode2): | sync - head - data |
|
||||
* | 12 - 4 - 2336 |
|
||||
*
|
||||
* - XA data (green, mode2 form1): | sync - head - sub - data - EDC - ECC |
|
||||
* | 12 - 4 - 8 - 2048 - 4 - 276 |
|
||||
*
|
||||
* - XA data (green, mode2 form2): | sync - head - sub - data - Spare |
|
||||
* | 12 - 4 - 8 - 2324 - 4 |
|
||||
*
|
||||
*/
|
||||
|
||||
// Macros for Spindle control
|
||||
#define CdSpinMax 0
|
||||
#define CdSpinNom 1 // Starts reading data at maximum rotational velocity and if a read error occurs, the rotational velocity is reduced.
|
||||
#define CdSpinStm 0 // Recommended stream rotation speed.
|
||||
|
||||
// Macros for TrayReq
|
||||
#define CdTrayOpen 0
|
||||
#define CdTrayClose 1
|
||||
#define CdTrayCheck 2
|
||||
|
||||
/*
|
||||
* Macros for sceCdGetDiskType() //comments translated from japanese;)
|
||||
*/
|
||||
#define SCECdIllgalMedia 0xff
|
||||
/* ILIMEDIA (Illegal Media)
|
||||
A non-PS / non-PS2 Disc. */
|
||||
#define SCECdDVDV 0xfe
|
||||
/* DVDV (DVD Video)
|
||||
A non-PS / non-PS2 Disc, but a DVD Video Disc */
|
||||
#define SCECdCDDA 0xfd
|
||||
/* CDDA (CD DA)
|
||||
A non-PS / non-PS2 Disc that include a DA track */
|
||||
#define SCECdPS2DVD 0x14
|
||||
/* PS2DVD PS2 consumer DVD. */
|
||||
#define SCECdPS2CDDA 0x13
|
||||
/* PS2CDDA PS2 consumer CD that includes a DA track */
|
||||
#define SCECdPS2CD 0x12
|
||||
/* PS2CD PS2 consumer CD that does not include a DA track */
|
||||
#define SCECdPSCDDA 0x11
|
||||
/* PSCDDA PS CD that includes a DA track */
|
||||
#define SCECdPSCD 0x10
|
||||
/* PSCD PS CD that does not include a DA track */
|
||||
#define SCECdDETCT 0x01
|
||||
/* DETCT (Detecting) Disc distinction action */
|
||||
#define SCECdNODISC 0x00
|
||||
/* NODISC (No disc) No disc entered */
|
||||
|
||||
/*
|
||||
* Media mode
|
||||
*/
|
||||
#define SCECdCD 1
|
||||
#define SCECdDVD 2
|
||||
|
||||
typedef struct {
|
||||
u8 stat; // 0: normal. Any other: error
|
||||
u8 second; // second (BCD value)
|
||||
u8 minute; // minute (BCD value)
|
||||
u8 hour; // hour (BCD value)
|
||||
u8 week; // week (BCD value)
|
||||
u8 day; // day (BCD value)
|
||||
u8 month; // month (BCD value)
|
||||
u8 year; // year (BCD value)
|
||||
} CdCLOCK;
|
||||
|
||||
typedef struct {
|
||||
u32 lsn; // Logical sector number of file
|
||||
u32 size; // File size (in bytes)
|
||||
char name[16]; // Filename
|
||||
u8 date[8]; // 1th: Seconds
|
||||
// 2th: Minutes
|
||||
// 3th: Hours
|
||||
// 4th: Date
|
||||
// 5th: Month
|
||||
// 6th 7th: Year (4 digits)
|
||||
} CdlFILE;
|
||||
|
||||
typedef struct {
|
||||
u8 minute; // Minutes
|
||||
u8 second; // Seconds
|
||||
u8 sector; // Sector
|
||||
u8 track; // Track number
|
||||
} CdlLOCCD;
|
||||
|
||||
typedef struct {
|
||||
u8 trycount; // Read try count (No. of error retries + 1) (0 - 255)
|
||||
u8 spindlctrl; // SCECdSpinStm: Recommended stream rotation speed.
|
||||
// SCECdSpinNom: Starts reading data at maximum rotational velocity and if a read error occurs, the rotational velocity is reduced.
|
||||
u8 datapattern; // SCECdSecS2048: Data size 2048 bytes
|
||||
// SCECdSecS2328: 2328 bytes
|
||||
// SCECdSecS2340: 2340 bytes
|
||||
u8 pad; // Padding data produced by alignment.
|
||||
} CdRMode;
|
||||
|
||||
#if defined(__WIN32__)
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
||||
struct TocEntry
|
||||
{
|
||||
u32 fileLBA;
|
||||
u32 fileSize;
|
||||
u8 fileProperties;
|
||||
u8 padding1[3];
|
||||
u8 filename[128+1];
|
||||
u8 date[7];
|
||||
#if defined(__WIN32__)
|
||||
};
|
||||
#else
|
||||
} __attribute__((packed));
|
||||
#endif
|
||||
|
||||
#if defined(__WIN32__)
|
||||
#pragma pack()
|
||||
#endif
|
||||
|
||||
int CDVD_findfile(char* fname, struct TocEntry* tocEntry);
|
||||
/*
|
||||
int CdBreak(void);
|
||||
int CdCallback( void (*func)() );
|
||||
int CdDiskReady(int mode);
|
||||
int CdGetDiskType(void);
|
||||
int CdGetError(void);
|
||||
u32 CdGetReadPos(void);
|
||||
int CdGetToc(u8 *toc);
|
||||
int CdInit(int init_mode);
|
||||
CdlLOCCD *CdIntToPos(int i, CdlLOCCD *p);
|
||||
int CdPause(void);
|
||||
int CdPosToInt(CdlLOCCD *p);*/
|
||||
int CdRead(u32 lsn, u32 sectors, void *buf, CdRMode *mode);
|
||||
int DvdRead(u32 lsn, u32 sectors, void *buf, CdRMode *mode);
|
||||
/*int CdReadClock(CdCLOCK *rtc);
|
||||
int CdSearchFile (CdlFILE *fp, const char *name);
|
||||
int CdSeek(u32 lsn);
|
||||
int CdStandby(void);
|
||||
int CdStatus(void);
|
||||
int CdStop(void);
|
||||
int CdSync(int mode);
|
||||
int CdTrayReq(int mode, u32 *traycnt);
|
||||
*/
|
||||
#endif // _CDVDLIB_H
|
Loading…
Reference in New Issue