Did a bit of cleanup on the new iso code, mainly so we're using the Console functions for messages.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1548 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2009-07-21 21:29:27 +00:00
parent 98c1855916
commit 6aeda9884a
5 changed files with 153 additions and 123 deletions

View File

@ -15,11 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/*
* Original code from libcdvd by Hiryu & Sjeep (C) 2002
* Modified by Florin for PCSX2 emu
* Fixed CdRead by linuzappz
*/
#include "PrecompiledHeader.h"
#include <stdio.h>
#include <stdlib.h>

View File

@ -15,6 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/*
* Original code from libcdvd by Hiryu & Sjeep (C) 2002
* Modified by Florin for PCSX2 emu

View File

@ -15,11 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/*
* Original code from libcdvd by Hiryu & Sjeep (C) 2002
* Modified by Florin for PCSX2 emu
* Fixed CdRead by linuzappz
*/
#include "PrecompiledHeader.h"
#include <ctype.h>

View File

@ -1,10 +1,22 @@
/* Pcsx2 - Pc Ps2 Emulator
* Copyright (C) 2002-2009 Pcsx2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "PrecompiledHeader.h"
#define __USE_LARGEFILE64
#define __USE_FILE_OFFSET64
#define _FILE_OFFSET_BITS 64
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#include "IopCommon.h"
#include "IsoFStools.h"
#include "IsoFSdrv.h"
@ -12,6 +24,7 @@
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#ifdef _WIN32
#include <windows.h>
@ -20,7 +33,7 @@ void *_openfile(const char *filename, int flags)
{
HANDLE handle;
// printf("_openfile %s, %d\n", filename, flags & O_RDONLY);
// Console::WriteLn("_openfile %s, %d", params filename, flags & O_RDONLY);
if (flags & O_WRONLY)
{
int _flags = CREATE_NEW;
@ -48,7 +61,7 @@ int _seekfile(void *handle, u64 offset, int whence)
{
u64 ofs = (u64)offset;
PLONG _ofs = (LONG*) & ofs;
// printf("_seekfile %p, %d_%d\n", handle, _ofs[1], _ofs[0]);
// Console::WriteLn("_seekfile %p, %d_%d", params handle, _ofs[1], _ofs[0]);
if (whence == SEEK_SET)
{
SetFilePointer(handle, _ofs[0], &_ofs[1], FILE_BEGIN);
@ -64,9 +77,9 @@ int _readfile(void *handle, void *dst, int size)
{
DWORD ret;
// printf("_readfile %p %d\n", handle, size);
// Console::WriteLn("_readfile %p %d", params handle, size);
ReadFile(handle, dst, size, &ret, NULL);
// printf("_readfile ret %d; %d\n", ret, GetLastError());
// Console::WriteLn("_readfile ret %d; %d", params ret, GetLastError());
return ret;
}
@ -74,10 +87,10 @@ int _writefile(void *handle, void *src, int size)
{
DWORD ret;
// printf("_writefile %p, %d\n", handle, size);
// Console::WriteLn("_writefile %p, %d", params handle, size);
// _seekfile(handle, _tellfile(handle));
WriteFile(handle, src, size, &ret, NULL);
// printf("_writefile ret %d\n", ret);
// Console::WriteLn("_writefile ret %d", params ret);
return ret;
}
@ -90,7 +103,7 @@ void _closefile(void *handle)
void *_openfile(const char *filename, int flags)
{
printf("_openfile %s %x\n", filename, flags);
// Console::WriteLn("_openfile %s %x", params filename, flags);
if (flags & O_WRONLY)
return fopen64(filename, "wb");
@ -98,11 +111,10 @@ void *_openfile(const char *filename, int flags)
return fopen64(filename, "rb");
}
#include <errno.h>
u64 _tellfile(void *handle)
{
s64 cursize = ftell(handle);
if (cursize == -1)
{
// try 64bit
@ -120,7 +132,7 @@ int _seekfile(void *handle, u64 offset, int whence)
{
int seekerr = fseeko64(handle, offset, whence);
if (seekerr == -1) printf("failed to seek\n");
if (seekerr == -1) Console::Error("Failed to seek.");
return seekerr;
}
@ -164,13 +176,12 @@ int detect(isoFile *iso)
int _isoReadDtable(isoFile *iso)
{
int ret;
int i;
_seekfile(iso->handle, 0, SEEK_END);
iso->dtablesize = (_tellfile(iso->handle) - 16) / (iso->blocksize + 4);
iso->dtable = (u32*)malloc(iso->dtablesize * 4);
for (i = 0; i < iso->dtablesize; i++)
for (int i = 0; i < iso->dtablesize; i++)
{
_seekfile(iso->handle, 16 + (iso->blocksize + 4)*i, SEEK_SET);
ret = _readfile(iso->handle, &iso->dtable[i], 4);
@ -180,6 +191,16 @@ int _isoReadDtable(isoFile *iso)
return 0;
}
bool tryIsoType(isoFile *iso, u32 size, u32 offset, u32 blockofs)
{
iso->blocksize = size;
iso->offset = offset;
iso->blockofs = blockofs;
if (detect(iso) == 1) return true;
return false;
}
int isoDetect(isoFile *iso) // based on florin's CDVDbin detection code :)
{
char buf[32];
@ -206,78 +227,27 @@ int isoDetect(isoFile *iso) // based on florin's CDVDbin detection code :)
iso->blocks = 16;
}
// ISO 2048
iso->blocksize = 2048;
iso->offset = 0;
iso->blockofs = 24;
if (detect(iso) == 1) return 0;
// RAW 2336
iso->blocksize = 2336;
iso->offset = 0;
iso->blockofs = 16;
if (detect(iso) == 1) return 0;
// RAW 2352
iso->blocksize = 2352;
iso->offset = 0;
iso->blockofs = 0;
if (detect(iso) == 1) return 0;
// RAWQ 2448
iso->blocksize = 2448;
iso->offset = 0;
iso->blockofs = 0;
if (detect(iso) == 1) return 0;
// NERO ISO 2048
iso->blocksize = 2048;
iso->offset = 150 * 2048;
iso->blockofs = 24;
if (detect(iso) == 1) return 0;
// NERO RAW 2352
iso->blocksize = 2352;
iso->offset = 150 * 2048;
iso->blockofs = 0;
if (detect(iso) == 1) return 0;
// NERO RAWQ 2448
iso->blocksize = 2448;
iso->offset = 150 * 2048;
iso->blockofs = 0;
if (detect(iso) == 1) return 0;
// ISO 2048
iso->blocksize = 2048;
iso->offset = -8;
iso->blockofs = 24;
if (detect(iso) == 1) return 0;
// RAW 2352
iso->blocksize = 2352;
iso->offset = -8;
iso->blockofs = 0;
if (detect(iso) == 1) return 0;
// RAWQ 2448
iso->blocksize = 2448;
iso->offset = -8;
iso->blockofs = 0;
if (detect(iso) == 1) return 0;
if (tryIsoType(iso, 2048, 0, 24)) return 0; // ISO 2048
if (tryIsoType(iso, 2336, 0, 16)) return 0; // RAW 2336
if (tryIsoType(iso, 2352, 0, 0)) return 0; // RAW 2352
if (tryIsoType(iso, 2448, 0, 0)) return 0; // RAWQ 2448
if (tryIsoType(iso, 2048, 150 * 2048, 24)) return 0; // NERO ISO 2048
if (tryIsoType(iso, 2352, 150 * 2048, 0)) return 0; // NERO RAW 2352
if (tryIsoType(iso, 2448, 150 * 2048, 0)) return 0; // NERO RAWQ 2448
if (tryIsoType(iso, 2048, -8, 24)) return 0; // ISO 2048
if (tryIsoType(iso, 2352, -8, 0)) return 0; // RAW 2352
if (tryIsoType(iso, 2448, -8, 0)) return 0; // RAWQ 2448
iso->offset = 0;
iso->blocksize = 2352;
iso->blockofs = 0;
iso->type = ISOTYPE_AUDIO;
return 0;
return -1;
}
isoFile *isoOpen(const char *filename)
{
isoFile *iso;
int i;
iso = (isoFile*)malloc(sizeof(isoFile));
if (iso == NULL) return NULL;
@ -288,31 +258,35 @@ isoFile *isoOpen(const char *filename)
iso->handle = _openfile(iso->filename, O_RDONLY);
if (iso->handle == NULL)
{
printf("Error loading %s\n", iso->filename);
Console::Error("error loading %s", params iso->filename);
return NULL;
}
if (isoDetect(iso) == -1) return NULL;
printf("detected blocksize = %d\n", iso->blocksize);
Console::WriteLn("detected blocksize = %d", params iso->blocksize);
if (strlen(iso->filename) > 3 && strncmp(iso->filename + (strlen(iso->filename) - 3), "I00", 3) == 0)
{
int i;
_closefile(iso->handle);
iso->flags |= ISOFLAGS_MULTI;
iso->blocks = 0;
for (i = 0; i < 8; i++)
{
iso->filename[strlen(iso->filename) - 1] = '0' + i;
iso->multih[i].handle = _openfile(iso->filename, O_RDONLY);
if (iso->multih[i].handle == NULL)
{
break;
}
iso->multih[i].slsn = iso->blocks;
_seekfile(iso->multih[i].handle, 0, SEEK_END);
iso->blocks += (u32)((_tellfile(iso->multih[i].handle) - iso->offset) /
(iso->blocksize));
iso->blocks += (u32)((_tellfile(iso->multih[i].handle) - iso->offset) / (iso->blocksize));
iso->multih[i].elsn = iso->blocks - 1;
}
@ -329,13 +303,12 @@ isoFile *isoOpen(const char *filename)
(iso->blocksize));
}
printf("isoOpen: %s ok\n", iso->filename);
printf("offset = %d\n", iso->offset);
printf("blockofs = %d\n", iso->blockofs);
printf("blocksize = %d\n", iso->blocksize);
printf("blocks = %d\n", iso->blocks);
printf("type = %d\n", iso->type);
Console::WriteLn("isoOpen: %s ok", params iso->filename);
Console::WriteLn("offset = %d", params iso->offset);
Console::WriteLn("blockofs = %d", params iso->blockofs);
Console::WriteLn("blocksize = %d", params iso->blocksize);
Console::WriteLn("blocks = %d", params iso->blocks);
Console::WriteLn("type = %d", params iso->type);
return iso;
}
@ -350,6 +323,7 @@ isoFile *isoCreate(const char *filename, int flags)
memset(iso, 0, sizeof(isoFile));
strcpy(iso->filename, filename);
iso->flags = flags;
iso->offset = 0;
iso->blockofs = 24;
@ -360,6 +334,7 @@ isoFile *isoCreate(const char *filename, int flags)
{
sprintf(Zfile, "%s.table", iso->filename);
iso->htable = _openfile(Zfile, O_WRONLY);
if (iso->htable == NULL)
{
return NULL;
@ -367,13 +342,15 @@ isoFile *isoCreate(const char *filename, int flags)
}
iso->handle = _openfile(iso->filename, O_WRONLY | O_CREAT);
if (iso->handle == NULL)
{
printf("Error loading %s\n", iso->filename);
Console::Error("Error loading %s", params iso->filename);
return NULL;
}
printf("isoCreate: %s ok\n", iso->filename);
printf("offset = %d\n", iso->offset);
Console::WriteLn("isoCreate: %s ok", params iso->filename);
Console::WriteLn("offset = %d", params iso->offset);
return iso;
}
@ -383,9 +360,11 @@ int isoSetFormat(isoFile *iso, int blockofs, int blocksize, int blocks)
iso->blocksize = blocksize;
iso->blocks = blocks;
iso->blockofs = blockofs;
printf("blockofs = %d\n", iso->blockofs);
printf("blocksize = %d\n", iso->blocksize);
printf("blocks = %d\n", iso->blocks);
Console::WriteLn("blockofs = %d", params iso->blockofs);
Console::WriteLn("blocksize = %d", params iso->blocksize);
Console::WriteLn("blocks = %d", params iso->blocks);
if (iso->flags & ISOFLAGS_BLOCKDUMP)
{
if (_writefile(iso->handle, "BDV2", 4) < 4) return -1;
@ -428,10 +407,12 @@ int _isoReadBlock(isoFile *iso, u8 *dst, int lsn)
memset(dst, 0, iso->blockofs);
_seekfile(iso->handle, ofs, SEEK_SET);
ret = _readfile(iso->handle, dst, iso->blocksize);
if (ret < iso->blocksize)
{
printf("read error %d\n", ret);
Console::Error("read error %d in _isoReadBlock", params ret);
return -1;
}
@ -441,21 +422,22 @@ int _isoReadBlock(isoFile *iso, u8 *dst, int lsn)
int _isoReadBlockD(isoFile *iso, u8 *dst, int lsn)
{
int ret;
int i;
// printf("_isoReadBlockD %d, blocksize=%d, blockofs=%d\n", lsn, iso->blocksize, iso->blockofs);
// Console::WriteLn("_isoReadBlockD %d, blocksize=%d, blockofs=%d\n", params lsn, iso->blocksize, iso->blockofs);
memset(dst, 0, iso->blockofs);
for (i = 0; i < iso->dtablesize;i++)
for (int i = 0; i < iso->dtablesize;i++)
{
if (iso->dtable[i] != lsn) continue;
_seekfile(iso->handle, 16 + i*(iso->blocksize + 4) + 4, SEEK_SET);
ret = _readfile(iso->handle, dst, iso->blocksize);
if (ret < iso->blocksize) return -1;
return 0;
}
printf("block %d not found in dump\n", lsn);
Console::WriteLn("Block %d not found in dump", params lsn);
return -1;
}
@ -463,28 +445,29 @@ int _isoReadBlockD(isoFile *iso, u8 *dst, int lsn)
int _isoReadBlockM(isoFile *iso, u8 *dst, int lsn)
{
u64 ofs;
int ret;
int i;
int ret, i;
for (i = 0; i < 8; i++)
{
if (lsn >= iso->multih[i].slsn &&
lsn <= iso->multih[i].elsn)
if (lsn >= iso->multih[i].slsn && lsn <= iso->multih[i].elsn)
{
break;
}
}
if (i == 8) return -1;
ofs = (u64)(lsn - iso->multih[i].slsn) * iso->blocksize + iso->offset;
// printf("_isoReadBlock %d, blocksize=%d, blockofs=%d\n", lsn, iso->blocksize, iso->blockofs);
// Console::WriteLn("_isoReadBlock %d, blocksize=%d, blockofs=%d\n", params lsn, iso->blocksize, iso->blockofs);
memset(dst, 0, iso->blockofs);
_seekfile(iso->multih[i].handle, ofs, SEEK_SET);
ret = _readfile(iso->multih[i].handle, dst, iso->blocksize);
if (ret < iso->blocksize)
{
printf("read error %d\n", ret);
Console::WriteLn("read error %d in _isoReadBlockM", params ret);
return -1;
}
@ -497,7 +480,7 @@ int isoReadBlock(isoFile *iso, u8 *dst, int lsn)
if (lsn > iso->blocks)
{
printf("isoReadBlock: %d > %d\n", lsn, iso->blocks);
Console::WriteLn("isoReadBlock: %d > %d", params lsn, iso->blocks);
return -1;
}
@ -522,8 +505,8 @@ int isoReadBlock(isoFile *iso, u8 *dst, int lsn)
int _isoWriteBlock(isoFile *iso, u8 *src, int lsn)
{
u64 ofs = (u64)lsn * iso->blocksize + iso->offset;
int ret;
u64 ofs = (u64)lsn * iso->blocksize + iso->offset;
_seekfile(iso->handle, ofs, SEEK_SET);
ret = _writefile(iso->handle, src, iso->blocksize);
@ -536,11 +519,14 @@ int _isoWriteBlockD(isoFile *iso, u8 *src, int lsn)
{
int ret;
// printf("_isoWriteBlock %d (ofs=%d)\n", iso->blocksize, ofs);
// Console::WriteLn("_isoWriteBlock %d (ofs=%d)", params iso->blocksize, ofs);
ret = _writefile(iso->handle, &lsn, 4);
if (ret < 4) return -1;
ret = _writefile(iso->handle, src, iso->blocksize);
// printf("_isoWriteBlock %d\n", ret);
// Console::WriteLn("_isoWriteBlock %d", params ret);
if (ret < iso->blocksize) return -1;
return 0;

View File

@ -1,21 +1,60 @@
#ifndef __LIBISO_H__
/* Pcsx2 - Pc Ps2 Emulator
* Copyright (C) 2002-2009 Pcsx2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __LIBISO_H__
#define __LIBISO_H__
#ifndef __USE_LARGEFILE64
#define __USE_LARGEFILE64
#endif
#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE_SOURCE
#endif
#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE64_SOURCE
#endif
#define __USE_FILE_OFFSET64
#define _FILE_OFFSET_BITS 64
#ifdef _MSC_VER
#pragma warning(disable:4018)
#endif
#define ISOTYPE_ILLEGAL 0
#define ISOTYPE_CD 1
#define ISOTYPE_DVD 2
#define ISOTYPE_AUDIO 3
#define ISOTYPE_DVDDL 4
enum isoType
{
ISOTYPE_ILLEGAL = 0,
ISOTYPE_CD,
ISOTYPE_DVD,
ISOTYPE_AUDIO,
ISOTYPE_DVDDL
};
#define ISOFLAGS_Z 0x0001
#define ISOFLAGS_Z2 0x0002
#define ISOFLAGS_BLOCKDUMP 0x0004
#define ISOFLAGS_MULTI 0x0008
#define ISOFLAGS_BZ2 0x0010
enum isoFlags
{
ISOFLAGS_Z = 0x0001,
ISOFLAGS_Z2 = 0x0002,
ISOFLAGS_BLOCKDUMP = 0x0004,
ISOFLAGS_MULTI = 0x0008,
ISOFLAGS_BZ2 = 0x0010
};
#define CD_FRAMESIZE_RAW 2352
#define DATA_SIZE (CD_FRAMESIZE_RAW-12)