cdvdgigaherz: Remove ISO file reader (#1569)

It doesn't support dual layer ISO images, and the ini has to be edited
manually so it loads an ISO image ("$" has to be prepended to the ISO
path as well). The PCSX2 internal ISO file reader is probably better in
most/all aspects and I don't think it's worth copying the logic from
PCSX2 into the plugin.
This commit is contained in:
Jonathan Li 2016-09-18 17:38:21 +01:00 committed by Gregory Hainaut
parent 310f13a2f7
commit 15fbd6fbf4
11 changed files with 5 additions and 653 deletions

View File

@ -241,22 +241,12 @@ s32 CALLBACK CDVDopen(const char* pTitleFilename)
return 0;
}
if(source_drive=='$')
{
printf(" * CDVD: Opening image '%s'...\n",source_file);
//open device file
src= TryLoaders(source_file);
}
else
{
sprintf(csrc, "\\\\.\\%c:", source_drive);
printf(" * CDVD: Opening drive '%s'...\n", csrc);
// open device file
src = new IOCtlSrc(csrc);
}
if(!src->IsOK())
{

View File

@ -139,14 +139,11 @@ public:
extern Source *src;
Source* TryLoaders(const char* fileName);
int FindDiskType();
void configure();
extern char source_drive;
extern char source_file[];
extern HINSTANCE hinst;

View File

@ -1,142 +0,0 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2014 David Quintana [gigaherz]
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 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 PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/stat.h>
#include "CDVD.h"
#include "FileStream.h"
using namespace std;
FileStream::FileStream(const char* fileName)
{
struct __stat64 stat_info;
_stat64(fileName, &stat_info);
fileSize = stat_info.st_size;
handle = fopen(fileName, "rb");
}
void FileStream::seek(s64 offset)
{
seek(offset,SEEK_SET);
}
void FileStream::seek(s64 offset, int ref_position)
{
int ret = _fseeki64(handle, offset, ref_position);
#ifdef __linux__
if (ret) throw "Seek offset out of bounds.";
#else
if (ret)
throw new exception("Seek offset out of bounds.");
#endif
}
void FileStream::reset()
{
seek(0);
}
s64 FileStream::skip(s64 n)
{
s64 before = getFilePointer();
seek(n,SEEK_CUR);
return getFilePointer() - before;
}
s64 FileStream::getFilePointer()
{
return _ftelli64(handle);
}
bool FileStream::eof()
{
return feof(handle)!=0;
}
int FileStream::read()
{
return fgetc(handle);
}
int FileStream::read(byte* b, int len)
{
if (b == NULL)
{
#ifdef __linux__
throw "NULL buffer passed.";
#else
throw new exception("NULL buffer passed.");
#endif
}
if (len < 0)
{
#ifdef __linux__
throw "off<0 or len<0.";
#else
throw new exception("off<0 or len<0.");
#endif
}
return fread(b,1,len,handle);
}
string FileStream::readLine()
{
string s;
s.clear();
while (!eof())
{
char c = read();
if ((c == '\n') || (c == '\r') || (c == '\0'))
break;
s.append(1, c);
}
return s;
}
wstring FileStream::readLineW()
{
wstring s;
s.clear();
while (!eof())
{
wchar_t c = read<wchar_t>();
if ((c == L'\n') || (c == L'\r') || (c == L'\0'))
break;
s.append(1, c);
}
return s;
}
s64 FileStream::getLength()
{
return fileSize;
}
FileStream::~FileStream(void)
{
fclose(handle);
}

View File

@ -1,66 +0,0 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2014 David Quintana [gigaherz]
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 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 PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdio.h>
#include <string>
typedef unsigned char byte;
class FileStream
{
int internalRead(byte* b, int off, int len);
FILE* handle;
s64 fileSize;
FileStream(FileStream&);
public:
FileStream(const char* fileName);
virtual void seek(s64 offset);
virtual void seek(s64 offset, int ref_position);
virtual void reset();
virtual s64 skip(s64 n);
virtual s64 getFilePointer();
virtual bool eof();
virtual int read();
virtual int read(byte* b, int len);
// Tool to read a specific value type, including structs.
template<class T>
T read()
{
if(sizeof(T)==1)
return (T)read();
else
{
T t;
read((byte*)&t,sizeof(t));
return t;
}
}
virtual std::string readLine(); // Assume null-termination
virtual std::wstring readLineW(); // (this one too)
virtual s64 getLength();
virtual ~FileStream(void);
};

View File

@ -1,216 +0,0 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2014 David Quintana [gigaherz]
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 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 PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "CDVD.h"
#include <ntddcdrm.h>
#include <cstddef>
#include "ReaderModules.h"
#include "SectorConverters.h"
#include <string>
#define RETURN(v) {OpenOK=v; return;}
s32 PlainIso::Reopen()
{
if(fileSource)
{
delete fileSource;
fileSource = NULL;
}
OpenOK = false;
fileSource = new FileStream(fName);
tocCached = false;
mediaTypeCached = false;
discSizeCached = false;
layerBreakCached = false;
OpenOK=true;
return 0;
}
PlainIso::PlainIso(const char* fileName)
{
fileSource=NULL;
strcpy_s(fName,256,fileName);
Reopen();
}
PlainIso::~PlainIso()
{
if(fileSource && OpenOK)
{
delete fileSource;
}
}
s32 PlainIso::GetSectorCount()
{
if(discSizeCached)
return discSize;
s64 length = fileSource->getLength();
discSizeCached = true;
discSize = (s32)(length / 2048);
return discSize;
}
s32 PlainIso::GetLayerBreakAddress()
{
return 0;
}
s32 PlainIso::GetMediaType()
{
if(mediaTypeCached)
return mediaType;
// assume single layer DVD, for now
mediaTypeCached = true;
mediaType = 0;
return mediaType;
}
#define MKDESCRIPTOR(n,ses,ctr,adr,pt,me,se,fe,tm,ts,tf) \
ftd->Descriptors[n].SessionNumber = ses; \
ftd->Descriptors[n].Control = ctr; \
ftd->Descriptors[n].Adr = adr; \
ftd->Descriptors[n].Reserved1 = 0; \
ftd->Descriptors[n].Point = pt; \
ftd->Descriptors[n].MsfExtra[0] = me; \
ftd->Descriptors[n].MsfExtra[1] = se; \
ftd->Descriptors[n].MsfExtra[2] = fe; \
ftd->Descriptors[n].Zero = 0; \
ftd->Descriptors[n].Msf[0] = tm; \
ftd->Descriptors[n].Msf[1] = ts; \
ftd->Descriptors[n].Msf[2] = tf;
#define MSF_TO_LBA(m,s,f) ((m*60+s)*75+f-150)
#define LBA_TO_MSF(m,s,f,l) \
m = (l)/(75*60); \
s = (((l)/75)%60); \
f = ((l)%75);
s32 PlainIso::ReadTOC(char *toc,int msize)
{
if(GetMediaType()>=0)
return -1;
if(!tocCached)
{
CDROM_TOC_FULL_TOC_DATA *ftd=(CDROM_TOC_FULL_TOC_DATA*)tocCacheData;
// Build basic TOC
int length = 6 * sizeof(ftd->Descriptors[0]) + 2;
ftd->Length[0] = length>>8;
ftd->Length[1] = length;
ftd->FirstCompleteSession=1;
ftd->LastCompleteSession=2;
int dm,ds,df;
LBA_TO_MSF(dm,ds,df,sector_count);
MKDESCRIPTOR(0,1,0x00,1,0xA0,0,0,0,1,0,0);
MKDESCRIPTOR(1,1,0x00,1,0xA1,0,0,0,1,0,0);
MKDESCRIPTOR(2,1,0x00,1,0xA2,0,0,0,dm,ds,df);
MKDESCRIPTOR(3,1,0x00,5,0xB0,0,0,0,0,0,0);
MKDESCRIPTOR(4,1,0x00,5,0xC0,0,0,0,0,0,0);
MKDESCRIPTOR(5,1,0x04,1,0x01,0,0,0,0,2,0);
tocCached = true;
}
memcpy(toc,tocCacheData,min(2048,msize));
return 0;
}
s32 PlainIso::ReadSectors2048(u32 sector, u32 count, char *buffer)
{
if(!OpenOK) return -1;
fileSource->seek(sector*(u64)2048);
s32 bytes = count * 2048;
s32 size = fileSource->read((byte*)buffer,bytes);
if(size!=bytes)
{
return -1;
}
return 0;
}
s32 PlainIso::ReadSectors2352(u32 sector, u32 count, char *buffer)
{
if(!OpenOK) return -1;
fileSource->seek(sector*(u64)2352);
for(uint i=0;i<count;i++)
{
s32 size = fileSource->read((byte*)sectorbuffer,2352);
if(size!=2352)
{
return -1;
}
Convert<2048,2352>(buffer+2048*i,sectorbuffer,sector+i);
}
return 0;
}
s32 PlainIso::DiscChanged()
{
if(!OpenOK) return -1;
return 0;
}
s32 PlainIso::IsOK()
{
return OpenOK;
}
Reader* PlainIso::TryLoad(const char* fName)
{
std::string fileName = fName;
std::string::size_type pos = fileName.find_last_of('.');
if(pos == std::string::npos) // no "." found, error.
return NULL;
std::string extension = fileName.substr(pos);
if((extension.compare(".iso")!=0)&&
(extension.compare(".ISO")!=0)) // assume valid
return NULL;
return new PlainIso(fName);
}

View File

@ -1,27 +0,0 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2014 David Quintana [gigaherz]
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 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 PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "CDVD.h"
#include "ReaderModules.h"
Source* TryLoaders(const char* fileName)
{
Source *src=NULL;
if((src=PlainIso::TryLoad(fileName))!=NULL) return src;
//if((src=CueSheet::TryLoad(fileName))!=NULL) return src;
//if((src=CloneCD::TryLoad(fileName))!=NULL) return src;
//error
return NULL;
}

View File

@ -1,94 +0,0 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2014 David Quintana [gigaherz]
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 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 PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "FileStream.h"
class Reader: public Source //abstract class as base for Reader modules
{
Reader(Reader&);
public:
Reader(){};
//virtual destructor
virtual ~Reader() {}
//virtual members
virtual s32 GetSectorCount()=0;
virtual s32 ReadTOC(char *toc,int size)=0;
virtual s32 ReadSectors2048(u32 sector, u32 count, char *buffer)=0;
virtual s32 ReadSectors2352(u32 sector, u32 count, char *buffer)=0;
virtual s32 GetLayerBreakAddress()=0;
virtual s32 GetMediaType()=0;
virtual s32 IsOK()=0;
virtual s32 Reopen()=0;
virtual s32 DiscChanged()=0;
//added members
static Reader* TryLoad(const char* fileName);
};
class PlainIso: public Reader
{
FileStream* fileSource;
bool OpenOK;
s32 sector_count;
char sectorbuffer[32*2048];
char fName[256];
DWORD sessID;
bool tocCached;
char tocCacheData[2048];
bool mediaTypeCached;
int mediaType;
bool discSizeCached;
s32 discSize;
bool layerBreakCached;
s32 layerBreak;
PlainIso(PlainIso&);
public:
PlainIso(const char* fileName);
virtual ~PlainIso();
//virtual members
virtual s32 GetSectorCount();
virtual s32 ReadTOC(char *toc,int size);
virtual s32 ReadSectors2048(u32 sector, u32 count, char *buffer);
virtual s32 ReadSectors2352(u32 sector, u32 count, char *buffer);
virtual s32 GetLayerBreakAddress();
virtual s32 GetMediaType();
virtual s32 IsOK();
virtual s32 Reopen();
virtual s32 DiscChanged();
static Reader* TryLoad(const char* fileName);
};

View File

@ -1,55 +0,0 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2014 David Quintana [gigaherz]
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 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 PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
template<int from, int to>
int Convert(char *dest, const char* psrc, int lsn);
template<>
int Convert<2048,2048>(char *dest, const char* psrc, int lsn)
{
memcpy(dest,psrc,2048);
return 0;
}
template<>
int Convert<2352,2352>(char *dest, const char* psrc, int lsn)
{
memcpy(dest,psrc,2352);
return 0;
}
template<>
int Convert<2352,2048>(char *dest, const char* psrc, int lsn)
{
memcpy(dest,psrc+16,2048);
return 0;
}
template<>
int Convert<2048,2352>(char *dest, const char* psrc, int lsn)
{
u8 m = lsn / (75*60);
u8 s = (lsn/75) % 60;
u8 f = lsn%75;
u8 header[16] = {
0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,m,s,f,0x02
};
memcpy(dest,header,16);
memcpy(dest+16,psrc,2048);
return 0;
}

View File

@ -54,19 +54,13 @@
<ItemGroup>
<ClCompile Include="..\CDVD.cpp" />
<ClCompile Include="config.cpp" />
<ClCompile Include="..\FileStream.cpp" />
<ClCompile Include="IOCtlSrc.cpp" />
<ClCompile Include="..\ReaderModules.cpp" />
<ClCompile Include="..\ReadThread.cpp" />
<ClCompile Include="..\TocStuff.cpp" />
<ClCompile Include="..\PlainIso.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\CDVD.h" />
<ClInclude Include="..\FileStream.h" />
<ClInclude Include="..\ReaderModules.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="..\SectorConverters.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="cdvdGigaherz.rc" />

View File

@ -5,9 +5,6 @@
<UniqueIdentifier>{c03fe088-95f7-4235-a796-5fe044914fb5}</UniqueIdentifier>
<Extensions>cpp;c;cxx;rc;def;r;odl;idl;hpj;bat</Extensions>
</Filter>
<Filter Include="Source Files\Reader Modules">
<UniqueIdentifier>{1dc55077-7d7a-4951-8841-26d21ff1513b}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{6c12b075-7b05-42ce-8628-c668f325f4ce}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl</Extensions>
@ -24,41 +21,23 @@
<ClCompile Include="config.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\FileStream.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="IOCtlSrc.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\ReaderModules.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\ReadThread.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\TocStuff.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\PlainIso.cpp">
<Filter>Source Files\Reader Modules</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\CDVD.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\FileStream.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\ReaderModules.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\SectorConverters.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="cdvdGigaherz.rc">

View File

@ -26,7 +26,6 @@
// DEBUG
char source_drive;
char source_file[MAX_PATH];
char CfgFile[MAX_PATH+10] = "inis/cdvdGigaherz.ini";
@ -123,24 +122,17 @@ void ReadSettings()
CfgReadStr("Config","Source",temp,511,"-");
source_drive=temp[0];
if(source_drive=='$')
strcpy_s(source_file,sizeof(source_file),temp+1);
else
source_file[0]=0;
}
/*****************************************************************************/
void WriteSettings()
{
char temp[511];
char temp[2];
temp[0]=source_drive;
temp[1]=0;
strcat(temp,source_file);
CfgWriteStr("Config","Source",temp);
}