Refactored the IsoFS crap to use better function names, and removed some stupid remains from when this code was part of a PS2 driver.

Added a WIP Iso reader to pcsx2. Right now it doesn't do anything (meant to be a backup in case I mess things up too much later), but the idea is to integrate iso reading, blockdump creation and loading into pcsx2, obsoleting CDVDiso and cdvdBlockDumper, and giving support for potential future features.



git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1489 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gigaherz 2009-07-11 23:24:23 +00:00
parent 18dfadfa79
commit bef8f8b07f
11 changed files with 663 additions and 311 deletions

View File

@ -0,0 +1,474 @@
#include "PrecompiledHeader.h"
#include "CDVDisoReader.h"
#ifndef MAX_PATH
#define MAX_PATH 255
#endif
char IsoFile[256];
u8 *pbuffer;
int BlockDump;
FILE* fdump;
FILE* isoFile;
FILE *cdvdLog = NULL;
int isoType;
int isoNumAudioTracks = 0;
int isoNumSectors = 0;
int isoSectorSize = 0;
int isoSectorOffset = 0;
#ifndef _WIN32
// if this doesn't work in linux, sorry
#define _ftelli64 ftell64
#define _fseeki64 fseek64
#endif
// This var is used to detect resume-style behavior of the Pcsx2 emulator,
// and skip prompting the user for a new CD when it's likely they want to run the existing one.
static char cdvdCurrentIso[MAX_PATH];
u8 cdbuffer[CD_FRAMESIZE_RAW * 10] = {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);
}
#define CDVD_LOG __Log
#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("ISOinit\n");
#endif
cdvdCurrentIso[0] = 0;
return 0;
}
void ISOshutdown()
{
cdvdCurrentIso[0] = 0;
#ifdef CDVD_LOG
if (cdvdLog != NULL) fclose(cdvdLog);
#endif
}
s32 ISOopen(const char* pTitle)
{
if (pTitle != NULL) strcpy(IsoFile, pTitle);
if (*IsoFile == 0) strcpy(IsoFile, cdvdCurrentIso);
if (*IsoFile == 0)
{
char temp[256];
//CfgOpenFile();
strcpy(temp, IsoFile);
*IsoFile = 0;
strcpy(IsoFile, temp);
}
isoFile = fopen(IsoFile,"rb");
if (isoFile == NULL)
{
Console::Error("Error loading %s\n", params IsoFile);
return -1;
}
// pretend it's a ps2 dvd... for now
isoType=CDVD_TYPE_PS2DVD;
isoSectorSize = 2048;
isoSectorOffset = 0;
// probably vc++ only, CBA to find the unix equivalent
isoNumSectors = (int)(_ftelli64(isoFile)/isoSectorSize);
if (BlockDump)
{
char fname_only[MAX_PATH];
#ifdef _WIN32
char fname[MAX_PATH], ext[MAX_PATH];
_splitpath(IsoFile, NULL, NULL, fname, ext);
_makepath(fname_only, NULL, NULL, fname, NULL);
#else
char* p, *plast;
plast = p = strchr(IsoFile, '/');
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, IsoFile);
plast = p = strchr(fname_only, '.');
while (p != NULL)
{
plast = p;
p = strchr(p + 1, '.');
}
if (plast != NULL) *plast = 0;
#endif
strcat(fname_only, ".dump");
fdump = fopen(fname_only, "wb");
if(fdump)
{
if(isoNumAudioTracks)
{
int k;
fwrite("BDV2",4,1,fdump);
k=2352;
fwrite(&k,4,1,fdump);
k=isoNumSectors;
fwrite(&k,4,1,fdump);
k=0;
fwrite(&k,4,1,fdump);
}
else
{
int k;
fwrite("BDV2",4,1,fdump);
k=2048;
fwrite(&k,4,1,fdump);
k=isoNumSectors;
fwrite(&k,4,1,fdump);
k=0x18;
fwrite(&k,4,1,fdump);
}
}
}
else
{
fdump = NULL;
}
return 0;
}
void ISOclose()
{
strcpy(cdvdCurrentIso, IsoFile);
fclose(isoFile);
if (fdump != NULL) fclose(fdump);
}
s32 ISOreadSubQ(u32 lsn, cdvdSubQ* subq)
{
// fake it, until some kind of support for clonecd .sub files is implemented
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(int tn, cdvdTD *Buffer)
{
if(tn==1)
{
Buffer->lsn = 0;
Buffer->type = CDVD_MODE1_TRACK;
}
else
{
Buffer->lsn = isoNumSectors;
Buffer->type = 0;
}
return 0;
}
s32 ISOgetDiskType()
{
return isoType;
}
s32 ISOgetTrayStatus()
{
return CDVD_TRAY_CLOSE;
}
s32 ISOctrlTrayOpen()
{
return 0;
}
s32 ISOctrlTrayClose()
{
return 0;
}
s32 ISOreadSector(u8* tempbuffer, u32 lsn)
{
// dummy function, doesn't create valid info for the data surrounding the userdata bytes!
// probably vc++ only, CBA to figure out the unix equivalent of fseek with support for >2gb seeking
_fseeki64(isoFile, lsn * (s64)isoSectorSize, SEEK_SET);
return fread(tempbuffer+24, isoSectorSize, 1, isoFile)-1;
}
static s32 layer1start = -1;
s32 ISOgetTOC(void* toc)
{
u8 type = ISOgetDiskType();
u8* tocBuff = (u8*)toc;
//__Log("ISOgetTOC\n");
if (type == CDVD_TYPE_DVDV || type == CDVD_TYPE_PS2DVD)
{
// get dvd structure format
// scsi command 0x43
memset(tocBuff, 0, 2048);
if (layer1start != -2 && isoNumSectors >= 0x300000)
{
int off = isoSectorOffset;
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 * 10);
for (layer1start = (isoNumSectors / 2 - 0x10) & ~0xf; layer1start < 0x200010; layer1start += 16)
{
ISOreadSector(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 (ISOgetTN(&diskInfo) == -1)
{
diskInfo.etrack = 0;
diskInfo.strack = 1;
}
if (ISOgetTD(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 = ISOgetTD(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 ISOreadTrack(u32 lsn, int mode)
{
int _lsn = lsn;
//__Log("ISOreadTrack: %x %x\n", lsn, mode);
if (_lsn < 0)
{
// lsn = 2097152 + (-_lsn);
lsn = isoNumSectors - (-_lsn);
}
// printf ("CDRreadTrack %d\n", lsn);
ISOreadSector(cdbuffer, lsn);
if (fdump != NULL)
{
fwrite(&lsn,4,1,fdump);
fwrite(cdbuffer,isoSectorSize,1,fdump);
}
pbuffer = cdbuffer;
switch (mode)
{
case CDVD_MODE_2352:
break;
case CDVD_MODE_2340:
pbuffer += 12;
break;
case CDVD_MODE_2328:
pbuffer += 24;
break;
case CDVD_MODE_2048:
pbuffer += 24;
break;
}
return 0;
}
u8* ISOgetBuffer()
{
return pbuffer;
}

View File

@ -0,0 +1,50 @@
/* CDVDiso
* Copyright (C) 2002-2004 CDVDiso 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __CDVD_ISO_H__
#define __CDVD_ISO_H__
#ifdef _MSC_VER
#pragma warning(disable:4018)
#endif
#include <stdio.h>
#include "IopCommon.h"
#include "IsoFStools.h"
#include "CDVD_internal.h"
#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 */
#define MSF2SECT(m,s,f) (((m)*60+(s)-2)*75+(f))
extern char IsoFile[256];
extern int BlockDump;
extern FILE* fdump;
extern FILE* isoFile;
extern int isoType;
extern u8 cdbuffer[];
extern u8 *pbuffer;
#endif

View File

@ -26,122 +26,6 @@
#include "Common.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;)
*/
// These are already declared with different names in PS2Edefs.h. And aren't used.
#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(_MSC_VER)
#pragma pack(1)
#endif
@ -164,8 +48,7 @@ struct TocEntry
#pragma pack()
#endif
int CDVD_findfile(const char* fname, struct TocEntry* tocEntry);
int CdRead(u32 lsn, u32 sectors, void *buf, CdRMode *mode);
int DvdRead(u32 lsn, u32 sectors, void *buf, CdRMode *mode);
int IsoFS_findFile(const char* fname, struct TocEntry* tocEntry);
int IsoFS_readSectors(u32 lsn, u32 sectors, void *buf);
#endif // _ISOFSCDVD_H

View File

@ -25,8 +25,6 @@
#include "IsoFStools.h"
#include "IsoFSdrv.h"
CdRMode cdReadMode;
struct fdtable{
//int fd;
int fileSize;
@ -46,22 +44,12 @@ static int inited=FALSE;
//////////////////////////////////////////////////////////////////////
// CDVDFS_init
// called by 80000592 sceCdInit()
//////////////////////////////////////////////////////////////////////
void CDVDFS_init(){
void IsoFS_init()
{
if (inited) return; //might change in the future as a param; forceInit/Reset
if (inited) return;//might change in the future as a param; forceInit/Reset
RPC_LOG("[CDVDisodrv:init] CDVD Filesystem v1.00");
RPC_LOG("[CDVDisodrv ] \tby A.Lee (aka Hiryu) & Nicholas Van Veen (aka Sjeep)");
RPC_LOG("[CDVDisodrv ] Initializing '%s' file driver.", "cdfs");
//CdInit(0); already called by plugin loading system ;)
cdReadMode.trycount = 0;
cdReadMode.spindlctrl = CdSpinStm;
cdReadMode.datapattern = CdSecS2048; //isofs driver only needs
//2KB sectors
ISOFS_LOG("[IsoFSdrv:init] Initializing '%s' file driver.", "IsoFS");
memzero_obj( fd_table );
memzero_obj( fd_used );
@ -73,14 +61,13 @@ void CDVDFS_init(){
//////////////////////////////////////////////////////////////////////
// CDVDFS_open
// called by 80000001 fileio_open for devices: "cdrom:", "cdrom0:"
//////////////////////////////////////////////////////////////////////
int CDVDFS_open(const char *name, int mode){
int IsoFS_open(const char *name, int mode){
int j;
static struct TocEntry tocEntry;
// check if the file exists
if (CDVD_findfile(name, &tocEntry) != TRUE)
if (IsoFS_findFile(name, &tocEntry) != TRUE)
return -1;
if(mode != 1) return -2; //SCE_RDONLY
@ -92,24 +79,23 @@ int CDVDFS_open(const char *name, int mode){
fd_used[j] = 1;
files_open++;
RPC_LOG("[CDVDisodrv:open] internal fd=%d", j);
ISOFS_LOG("[IsoFSdrv:open] internal fd=%d", j);
fd_table[j].fileSize = tocEntry.fileSize;
fd_table[j].LBA = tocEntry.fileLBA;
fd_table[j].filePos = 0;
RPC_LOG("[CDVDisodrv ] tocEntry.fileSize = %d",tocEntry.fileSize);
ISOFS_LOG("[IsoFSdrv:open] tocEntry.fileSize = %d",tocEntry.fileSize);
return j;
}
//////////////////////////////////////////////////////////////////////
// CDVDFS_lseek
// called by 80000001 fileio_lseek for devices: "cdrom:", "cdrom0:"
//////////////////////////////////////////////////////////////////////
int CDVDFS_lseek(int fd, int offset, int whence){
int IsoFS_lseek(int fd, int offset, int whence){
if ((fd >= 16) || (fd_used[fd]==0)){
RPC_LOG("[CDVDisodrv:lseek] ERROR: File does not appear to be open!");
ISOFS_LOG("[IsoFSdrv:lseek] ERROR: File does not appear to be open!");
return -1;
}
@ -141,28 +127,27 @@ int CDVDFS_lseek(int fd, int offset, int whence){
//////////////////////////////////////////////////////////////////////
// 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 IsoFS_read( int fd, char *buffer, int size )
{
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)){
RPC_LOG("[CDVDisodrv:read] ERROR: File does not appear to be open!");
if ((fd >= 16) || (fd_used[fd]==0))
{
ISOFS_LOG("[IsoFSdrv:read] ERROR: File does not appear to be open!");
return -1;
}
// A few sanity checks
if (fd_table[fd].filePos > fd_table[fd].fileSize){
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
return 0; // File exists but we couldn't read anything from it
}
if ((fd_table[fd].filePos + size) > fd_table[fd].fileSize)
@ -171,7 +156,8 @@ int CDVDFS_read( int fd, char *buffer, int size ){
// 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){
if (off_sector)
{
ssize = std::min(2048 - off_sector, size);
size -= ssize;
asector++;
@ -181,22 +167,27 @@ int CDVDFS_read( int fd, char *buffer, int size ){
esector=asector + (asize >> 11);
size += ssize;
RPC_LOG("[CDVDisodrv:read] read sectors 0x%08X to 0x%08X", ssector, esector-(esize==0));
ISOFS_LOG("[IsoFSdrv:read] read sectors 0x%08X to 0x%08X", ssector, esector-(esize==0));
if (ssize){
if (CdRead(ssector, 1, lb, &cdReadMode) != TRUE){
RPC_LOG("[CDVDisodrv: ] Couldn't Read from file for some reason");
if (ssize)
{
if (IsoFS_readSectors(ssector, 1, lb) != TRUE)
{
ISOFS_LOG("[IsoFSdrv:read] Couldn't Read from file for some reason");
return 0;
}
memcpy_fast(buffer, lb + off_sector, ssize);
}
if (asize) if (CdRead(asector, asize >> 11, buffer+ssize, &cdReadMode) != TRUE){
RPC_LOG("[CDVDisodrv: ] Couldn't Read from file for some reason");
if (asize) if (IsoFS_readSectors(asector, asize >> 11, buffer+ssize) != TRUE)
{
ISOFS_LOG("[IsoFSdrv:read] Couldn't Read from file for some reason");
return 0;
}
if (esize){
if (CdRead(esector, 1, lb, &cdReadMode) != TRUE){
RPC_LOG("[CDVDisodrv: ] Couldn't Read from file for some reason");
if (esize)
{
if (IsoFS_readSectors(esector, 1, lb) != TRUE)
{
ISOFS_LOG("[IsoFSdrv:read] Couldn't Read from file for some reason");
return 0;
}
memcpy_fast(buffer+ssize+asize, lb, esize);
@ -207,13 +198,13 @@ int CDVDFS_read( int fd, char *buffer, int size ){
off_sector = (fd_table[fd].filePos & 0x7FF);
num_sectors = ((off_sector + size) >> 11) + 1;
RPC_LOG("[CDVDisodrv:read] read sectors 0x%08X to 0x%08X",start_sector,start_sector+num_sectors);
RPC_LOG("[IsoFSdrv:read] read sectors 0x%08X to 0x%08X",start_sector,start_sector+num_sectors);
// Read the data (we only ever get 16KB max request at once)
if (CdRead(start_sector, num_sectors, local_buffer, &cdReadMode) != TRUE){
//RPC_LOG("sector = %d, start sector = %d",sector,start_sector);
RPC_LOG("[CDVDisodrv: ] Couldn't Read from file for some reason");
RPC_LOG("[IsoFSdrv: ] Couldn't Read from file for some reason");
return 0;
}
//CdSync(0); hm, a wait function maybe...
@ -225,27 +216,18 @@ int CDVDFS_read( int fd, char *buffer, int 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){
int IsoFS_close( int fd)
{
if ((fd >= 16) || (fd_used[fd]==0)){
RPC_LOG("[CDVDisodrv:close] ERROR: File does not appear to be open!");
if ((fd >= 16) || (fd_used[fd]==0))
{
ISOFS_LOG("[IsoFSdrv:close] ERROR: File does not appear to be open!");
return -1;
}
RPC_LOG("[CDVDisodrv:close] internal fd %d", fd);
ISOFS_LOG("[IsoFSdrv:close] internal fd %d", fd);
fd_used[fd] = 0;
files_open--;

View File

@ -25,14 +25,11 @@
#include "IsoFScdvd.h"
extern CdRMode cdReadMode;
/* Filing-system exported functions */
void CDVDFS_init();
int CDVDFS_open(const 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);
void IsoFS_init();
int IsoFS_open(const char *name, int mode);
int IsoFS_lseek(int fd, int offset, int whence);
int IsoFS_read( int fd, char * buffer, int size );
int IsoFS_close( int fd);
#endif//__ISOFSDRV_H__

View File

@ -168,59 +168,24 @@ int TocEntryCompare(char* filename, char* extensions){
#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){
int IsoFS_readSectors(u32 lsn, u32 sectors, void *buf)
{
u32 i;
u8* buff;
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++){
if (CDVDreadTrack(lsn+i, rmode)==-1)
for (i=0; i<sectors; i++)
{
if (CDVDreadTrack(lsn+i, CDVD_MODE_2048)==-1)
return 0;
buff = CDVDgetBuffer();
if (buff==NULL) return 0;
switch (mode->datapattern){
case CdSecS2048:
memcpy_fast((void*)((uptr)buf+2048*i), buff, 2048);break;//only data
case CdSecS2328:
memcpy_fast((void*)((uptr)buf+2328*i), buff, 2328);break;//without sync & head & sub
case CdSecS2340:
memcpy_fast((void*)((uptr)buf+2340*i), buff, 2340);break;//without sync
}
}
return 1;
}
int DvdRead(u32 lsn, u32 sectors, void *buf, CdRMode *mode){
u32 i;
u8* buff;
for (i=lsn; i<(lsn+sectors); i++){
if (CDVDreadTrack(i, CDVD_MODE_2048)==-1)
if (buff==NULL)
return 0;
buff = CDVDgetBuffer();
if (buff==NULL) return 0;
// switch (mode->datapattern){
// case CdSecS2064:
((u32*)buf)[0] = i + 0x30000;
memcpy_fast((u8*)buf+12, buff, 2048);
buf = (char*)buf + 2064; break;
// default:
// return 0;
// }
memcpy_fast((void*)((uptr)buf+2048*i), buff, 2048);break;//only data
}
return 1;
}
@ -230,7 +195,8 @@ int DvdRead(u32 lsn, u32 sectors, void *buf, CdRMode *mode){
* may also be exported for use via RPC *
**************************************************************/
int CDVD_GetVolumeDescriptor(void){
int IsoFS_getVolumeDescriptor(void)
{
// Read until we find the last valid Volume Descriptor
int volDescSector;
@ -240,7 +206,7 @@ int CDVD_GetVolumeDescriptor(void){
for (volDescSector = 16; volDescSector<20; volDescSector++)
{
CdRead(volDescSector,1,&localVolDesc,&cdReadMode);
IsoFS_readSectors(volDescSector,1,&localVolDesc);
// CdSync(0x00);
// If this is still a volume Descriptor
@ -267,7 +233,7 @@ int CDVD_GetVolumeDescriptor(void){
return TRUE;
}
int CDVD_findfile(const char* fname, TocEntry* tocEntry){
int IsoFS_findFile(const char* fname, TocEntry* tocEntry){
char filename[g_MaxPath+1];
char pathname[JolietMaxPath+1];
char toc[2048];
@ -286,22 +252,18 @@ int CDVD_findfile(const char* fname, TocEntry* tocEntry){
DbgCon::WriteLn("CDVD_findfile called");
//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){
RPC_LOG("Could not get CD Volume Descriptor");
if (IsoFS_getVolumeDescriptor() != TRUE)
{
ISOFS_LOG("Could not get CD Volume Descriptor");
return -1;
}
// Read the TOC of the root directory
if (CdRead(CDVolDesc.rootToc.tocLBA,1,toc,&cdReadMode) != TRUE){
RPC_LOG("Couldn't Read from CD !");
if (IsoFS_readSectors(CDVolDesc.rootToc.tocLBA,1,toc) != TRUE){
ISOFS_LOG("Couldn't Read from CD !");
return -1;
}
//CdSync(0x00);
@ -360,7 +322,7 @@ int CDVD_findfile(const char* fname, TocEntry* tocEntry){
// then load another sector
current_sector++;
if (CdRead(current_sector,1,toc,&cdReadMode) != TRUE)
if (IsoFS_readSectors(current_sector,1,toc) != TRUE)
{
Console::Error("Couldn't Read from CD !");
return -1;
@ -406,7 +368,7 @@ int CDVD_findfile(const char* fname, TocEntry* tocEntry){
dirname = strtok( NULL, "\\/" );
// Read the TOC of the found subdirectory
if (CdRead(localTocEntry.fileLBA,1,toc,&cdReadMode) != TRUE)
if (IsoFS_readSectors(localTocEntry.fileLBA,1,toc) != TRUE)
{
Console::Error("Couldn't Read from CD !");
return -1;
@ -422,7 +384,7 @@ int CDVD_findfile(const char* fname, TocEntry* tocEntry){
tocEntryPointer = (dirTocEntry*)((char*)tocEntryPointer + tocEntryPointer->length);
}
RPC_LOG("[RPC:cdvd] findfile: found dir, now looking for file");
ISOFS_LOG("[IsoFStools] findfile: found dir, now looking for file");
tocEntryPointer = (dirTocEntry*)toc;
@ -467,7 +429,7 @@ int CDVD_findfile(const char* fname, TocEntry* tocEntry){
{
dir_lba++;
if (CdRead(dir_lba,1,toc,&cdReadMode) != TRUE){
if (IsoFS_readSectors(dir_lba,1,toc) != TRUE){
Console::Error("Couldn't Read from CD !");
return -1;
}
@ -483,7 +445,7 @@ int CDVD_findfile(const char* fname, TocEntry* tocEntry){
}
// 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 IsoFS_initDirectoryList(char* pathname, char* extensions, unsigned int inc_dirs){
// int dir_depth = 1;
char toc[2048];
char* dirname;
@ -501,16 +463,16 @@ int CDVD_GetDir_RPC_request(char* pathname, char* extensions, unsigned int inc_d
getDirTocData.inc_dirs = inc_dirs;
// Find the TOC for a specific directory
if (CDVD_GetVolumeDescriptor() != TRUE){
RPC_LOG("[RPC:cdvd] Could not get CD Volume Descriptor");
if (IsoFS_getVolumeDescriptor() != TRUE){
ISOFS_LOG("[IsoFStools] Could not get CD Volume Descriptor");
return -1;
}
RPC_LOG("[RPC:cdvd] Getting Directory Listing for: \"%s\"", pathname);
ISOFS_LOG("[IsoFStools] Getting Directory Listing for: \"%s\"", pathname);
// Read the TOC of the root directory
if (CdRead(CDVolDesc.rootToc.tocLBA,1,toc,&cdReadMode) != TRUE){
RPC_LOG("[RPC: ] Couldn't Read from CD !");
if (IsoFS_readSectors(CDVolDesc.rootToc.tocLBA,1,toc) != TRUE){
ISOFS_LOG("[IsoFStools] Couldn't Read from CD !");
return -1;
}
//CdSync(0x00);
@ -526,12 +488,12 @@ int CDVD_GetDir_RPC_request(char* pathname, char* extensions, unsigned int inc_d
// use strtok to get the next dir name
// if there isnt one, then assume we want the LBA
// if there isn't 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
// if we don't find the right name
// before finding an entry at a higher level (lower num), then return nothing
localTocEntry.fileLBA = CDVolDesc.rootToc.tocLBA;
@ -550,8 +512,8 @@ int CDVD_GetDir_RPC_request(char* pathname, char* extensions, unsigned int inc_d
// then load another sector
current_sector++;
if (CdRead(current_sector,1,toc,&cdReadMode) != TRUE){
RPC_LOG("[RPC: ] Couldn't Read from CD !");
if (IsoFS_readSectors(current_sector,1,toc) != TRUE){
ISOFS_LOG("[IsoFStools] Couldn't Read from CD !");
return -1;
}
@ -573,8 +535,8 @@ int CDVD_GetDir_RPC_request(char* pathname, char* extensions, unsigned int inc_d
if (strcmp(dirname,localTocEntry.filename) == 0){
// if the name matches then we've found the directory
found_dir = TRUE;
RPC_LOG("[RPC: ] Found directory %s in subdir at sector %d",dirname,current_sector);
RPC_LOG("[RPC: ] LBA of found subdirectory = %d",localTocEntry.fileLBA);
ISOFS_LOG("[IsoFStools] Found directory %s in subdir at sector %d",dirname,current_sector);
ISOFS_LOG("[IsoFStools] LBA of found subdirectory = %d",localTocEntry.fileLBA);
break;
}
@ -592,8 +554,8 @@ int CDVD_GetDir_RPC_request(char* pathname, char* extensions, unsigned int inc_d
dirname = strtok( NULL, "\\/" );
// Read the TOC of the found subdirectory
if (CdRead(localTocEntry.fileLBA,1,toc,&cdReadMode) != TRUE){
RPC_LOG("[RPC: ] Couldn't Read from CD !");
if (IsoFS_readSectors(localTocEntry.fileLBA,1,toc) != TRUE){
ISOFS_LOG("[IsoFStools] Couldn't Read from CD !");
return -1;
}
//CdSync(0x00);
@ -644,8 +606,8 @@ int CDVD_GetDir_RPC_request(char* pathname, char* extensions, unsigned int inc_d
// then load another sector
getDirTocData.current_sector++;
if (CdRead(getDirTocData.current_sector,1,toc,&cdReadMode) != TRUE){
RPC_LOG("[RPC: ] Couldn't Read from CD !");
if (IsoFS_readSectors(getDirTocData.current_sector,1,toc) != TRUE){
ISOFS_LOG("[IsoFStools] Couldn't Read from CD !");
return -1;
}
//CdSync(0x00);
@ -703,14 +665,14 @@ int CDVD_GetDir_RPC_request(char* pathname, char* extensions, unsigned int inc_d
// 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(TocEntry tocEntry[], int req_entries){
int IsoFS_getDirectories(TocEntry tocEntry[], int req_entries){
char toc[2048];
int toc_entry_num;
dirTocEntry* tocEntryPointer;
if (CdRead(getDirTocData.current_sector,1,toc,&cdReadMode) != TRUE){
RPC_LOG("[RPC:cdvd] Couldn't Read from CD !");
if (IsoFS_readSectors(getDirTocData.current_sector,1,toc) != TRUE){
ISOFS_LOG("[IsoFStools] Couldn't Read from CD !");
return -1;
}
//CdSync(0x00);
@ -730,18 +692,21 @@ int CDVD_GetDir_RPC_get_entries(TocEntry tocEntry[], int req_entries){
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)){
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 (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){
RPC_LOG("[RPC:cdvd] Couldn't Read from CD !");
if (IsoFS_readSectors(getDirTocData.current_sector,1,toc) != TRUE){
ISOFS_LOG("[IsoFStools] Couldn't Read from CD !");
return -1;
}
//CdSync(0x00);
@ -751,7 +716,8 @@ int CDVD_GetDir_RPC_get_entries(TocEntry tocEntry[], int req_entries){
// continue;
}
else{
else
{
return (toc_entry_num);
}
}
@ -792,27 +758,6 @@ int CDVD_GetDir_RPC_get_entries(TocEntry tocEntry[], int req_entries){
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);
}

View File

@ -25,9 +25,8 @@
#include "IsoFScdvd.h"
int CDVD_findfile(const char* fname, TocEntry* tocEntry);
int CDVD_GetDir_RPC_request(char* pathname, char* extensions, unsigned int inc_dirs);
int CDVD_GetDir_RPC_get_entries(TocEntry tocEntry[], int req_entries);
int IsoFS_initDirectoryList(char* pathname, char* extensions, unsigned int inc_dirs);
int IsoFS_getDirectories(TocEntry tocEntry[], int req_entries);
#if defined(_MSC_VER)
#pragma pack(1)

View File

@ -130,7 +130,7 @@ extern bool SrcLog_GPU( const char* fmt, ... );
#define SIF_LOG (varLog & 0x00002000) && SrcLog_SIF
#define IPU_LOG (varLog & 0x00004000) && SrcLog_IPU
#define VUM_LOG (varLog & 0x00008000) && SrcLog_VUM
#define RPC_LOG (varLog & 0x00010000) && SrcLog_RPC
#define ISOFS_LOG (varLog & 0x00010000) && SrcLog_RPC
#define EECNT_LOG (varLog & 0x40000000) && SrcLog_EECNT
#define PSXCPU_LOG (varLog & 0x00100000) && SrcLog_PSXCPU
@ -170,7 +170,7 @@ extern bool SrcLog_GPU( const char* fmt, ... );
#define SIF_LOG 0&&
#define IPU_LOG 0&&
#define VUM_LOG 0&&
#define RPC_LOG 0&&
#define ISOFS_LOG 0&&
#define PSXCPU_LOG 0&&
#define PSXMEM_LOG 0&&

View File

@ -299,13 +299,13 @@ struct ElfObject
if ((strnicmp( filename.c_str(), "cdrom0:", strlen("cdromN:")) == 0) ||
(strnicmp( filename.c_str(), "cdrom1:", strlen("cdromN:")) == 0))
{
int fi = CDVDFS_open(filename.c_str() + strlen("cdromN:"), 1);//RDONLY
int fi = IsoFS_open(filename.c_str() + strlen("cdromN:"), 1);//RDONLY
if (fi < 0) throw Exception::FileNotFound( filename );
CDVDFS_lseek( fi, 0, SEEK_SET );
rsize = CDVDFS_read( fi, (char*)data.GetPtr(), data.GetSizeInBytes() );
CDVDFS_close( fi );
IsoFS_lseek( fi, 0, SEEK_SET );
rsize = IsoFS_read( fi, (char*)data.GetPtr(), data.GetSizeInBytes() );
IsoFS_close( fi );
}
else
{
@ -486,8 +486,8 @@ u32 loadElfCRC( const char* filename )
{
TocEntry toc;
CDVDFS_init( );
if ( CDVD_findfile( filename + strlen( "cdromN:" ), &toc ) == -1 )
IsoFS_init( );
if ( IsoFS_findFile( filename + strlen( "cdromN:" ), &toc ) == -1 )
return 0;
DevCon::Status( "loadElfFile: %d bytes", params toc.fileSize );
@ -529,8 +529,8 @@ int loadElfFile(const char *filename)
{
// Loading from a CD rom or CD image.
TocEntry toc;
CDVDFS_init( );
if ( CDVD_findfile( filename + strlen( "cdromN:" ), &toc ) == -1 )
IsoFS_init( );
if ( IsoFS_findFile( filename + strlen( "cdromN:" ), &toc ) == -1 )
return -1;
elfsize = toc.fileSize;
}

View File

@ -305,17 +305,17 @@ int GetPS2ElfName(char *name){
char *pos;
TocEntry tocEntry;
CDVDFS_init();
IsoFS_init();
// check if the file exists
if (CDVD_findfile("SYSTEM.CNF;1", &tocEntry) != TRUE){
if (IsoFS_findFile("SYSTEM.CNF;1", &tocEntry) != TRUE){
Console::Error("Boot Error > SYSTEM.CNF not found");
return 0;//could not find; not a PS/PS2 cdvd
}
f=CDVDFS_open("SYSTEM.CNF;1", 1);
CDVDFS_read(f, buffer, g_MaxPath);
CDVDFS_close(f);
f=IsoFS_open("SYSTEM.CNF;1", 1);
IsoFS_read(f, buffer, g_MaxPath);
IsoFS_close(f);
buffer[tocEntry.fileSize]='\0';

View File

@ -1529,6 +1529,28 @@
RelativePath="..\..\CDVD\CDVD_internal.h"
>
</File>
<File
RelativePath="..\..\CDVD\CDVDisoReader.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\CDVD\CDVDisoReader.h"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCustomBuildTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\IopBios.cpp"
>