Major Fixes!

* Fixed like a gazillion bugs in the new CDVD system; memory corruption, memory leaks, failed resets, and who knows what else.
 * New commandline parameters!!  Added -skipbios/-nodisc/-usecdvd/-elf [file] options, intended replacements for the now obsolete -bootmode (bootmode should still work as it used to).
 * fixed a bug that kept -help from working, and updated -help to display all the new command lines.
 * -nogui command line now causes PCSX2 to close on escape, instead of escaping back to the GUI.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1684 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
Jake.Stine 2009-08-27 02:00:25 +00:00
parent b5264ca7c9
commit d77ac4786d
23 changed files with 709 additions and 618 deletions

View File

@ -819,35 +819,12 @@ extern _SPU2test SPU2test;
extern _SPU2about SPU2about;
// CDVD
struct CDVDplugin {
_CDVDinit init;
_CDVDopen open;
_CDVDclose close;
_CDVDshutdown shutdown;
_CDVDreadTrack readTrack;
_CDVDgetBuffer getBuffer;
_CDVDreadSubQ readSubQ;
_CDVDgetTN getTN;
_CDVDgetTD getTD;
_CDVDgetTOC getTOC;
_CDVDgetDiskType getDiskType;
_CDVDgetTrayStatus getTrayStatus;
_CDVDctrlTrayOpen ctrlTrayOpen;
_CDVDctrlTrayClose ctrlTrayClose;
_CDVDconfigure configure;
_CDVDtest test;
_CDVDabout about;
_CDVDnewDiskCB newDiskCB;
// special functions, not in external interface yet
_CDVDreadSector readSector;
_CDVDgetBuffer2 getBuffer2;
_CDVDgetDualInfo getDualInfo;
int* initCount;
};
extern CDVDplugin CDVD_plugin; // _plugin because of
extern _CDVDclose CDVDclose;
extern _CDVDinit CDVDinit;
extern _CDVDshutdown CDVDshutdown;
extern _CDVDconfigure CDVDconfigure;
extern _CDVDabout CDVDabout;
extern _CDVDtest CDVDtest;
// DEV9
extern _DEV9init DEV9init;

View File

@ -25,6 +25,7 @@
#include "IsoFStools.h"
#include "CDVD_internal.h"
#include "CDVDisoReader.h"
#include "GS.h" // for gsRegionMode
static cdvdStruct cdvd;
@ -60,13 +61,13 @@ static void cdvdSetIrq( uint id = (1<<Irq_CommandComplete) )
static int mg_BIToffset(u8 *buffer)
{
int i, ofs = 0x20;
int i, ofs = 0x20;
for (i=0; i<*(u16*)&buffer[0x1A]; i++)
ofs+=0x10;
if (*(u16*)&buffer[0x18] & 1) ofs += buffer[ofs];
if ((*(u16*)&buffer[0x18] & 0xF000) == 0) ofs += 8;
return ofs + 0x20;
}
@ -196,7 +197,7 @@ s32 getNvmData(u8* buffer, s32 offset, s32 size, s32 fmtOffset)
// find the correct bios version
NVMLayout* nvmLayout = getNvmLayout();
if (nvmLayout == NULL) return 1;
// get data from eeprom
return cdvdReadNVM(buffer, *(s32*)(((u8*)nvmLayout)+fmtOffset) + offset, size);
}
@ -205,7 +206,7 @@ s32 setNvmData(const u8* buffer, s32 offset, s32 size, s32 fmtOffset)
// find the correct bios version
NVMLayout* nvmLayout = getNvmLayout();
if (nvmLayout == NULL) return 1;
// set data in eeprom
return cdvdWriteNVM(buffer, *(s32*)(((u8*)nvmLayout)+fmtOffset) + offset, size);
}
@ -278,7 +279,7 @@ s32 cdvdReadConfig(u8* config)
memzero_ptr<16>(config);
return 0;
}
// get config data
switch (cdvd.COffset)
{
@ -303,7 +304,7 @@ s32 cdvdWriteConfig(const u8* config)
((cdvd.COffset == 2) && (cdvd.CBlockIndex >= 7))
)
return 0;
// get config data
switch (cdvd.COffset)
{
@ -325,41 +326,41 @@ void cdvdReadKey(u8 arg0, u16 arg1, u32 arg2, u8* key) {
s32 numbers, letters;
u32 key_0_3;
u8 key_4, key_14;
// get main elf name
GetPS2ElfName(str);
bool IsPs2 = (GetPS2ElfName(str) == 2);
sprintf(exeName, "%c%c%c%c%c%c%c%c%c%c%c",str[8],str[9],str[10],str[11],str[12],str[13],str[14],str[15],str[16],str[17],str[18]);
DevCon::Notice("exeName = %s", params &str[8]);
// convert the number characters to a real 32bit number
numbers = ((((exeName[5] - '0'))*10000) +
(((exeName[ 6] - '0'))*1000) +
(((exeName[ 7] - '0'))*100) +
(((exeName[ 9] - '0'))*10) +
(((exeName[10] - '0'))*1) );
// combine the lower 7 bits of each char
// to make the 4 letters fit into a single u32
letters = (s32)((exeName[3]&0x7F)<< 0) |
(s32)((exeName[2]&0x7F)<< 7) |
(s32)((exeName[1]&0x7F)<<14) |
(s32)((exeName[0]&0x7F)<<21);
// calculate magic numbers
key_0_3 = ((numbers & 0x1FC00) >> 10) | ((0x01FFFFFF & letters) << 7); // numbers = 7F letters = FFFFFF80
key_4 = ((numbers & 0x0001F) << 3) | ((0x0E000000 & letters) >> 25); // numbers = F8 letters = 07
key_14 = ((numbers & 0x003E0) >> 2) | 0x04; // numbers = F8 extra = 04 unused = 03
// clear key values
memzero_ptr<16>(key);
// store key values
key[ 0] = (key_0_3&0x000000FF)>> 0;
key[ 1] = (key_0_3&0x0000FF00)>> 8;
key[ 2] = (key_0_3&0x00FF0000)>>16;
key[ 3] = (key_0_3&0xFF000000)>>24;
key[ 4] = key_4;
if(arg2 == 75)
{
key[14] = key_14;
@ -383,43 +384,44 @@ void cdvdReadKey(u8 arg0, u16 arg1, u32 arg2, u8* key) {
{
key[15] = 0x01;
}
Console::WriteLn( "CDVD.KEY = %02X,%02X,%02X,%02X,%02X,%02X,%02X", params
cdvd.Key[0],cdvd.Key[1],cdvd.Key[2],cdvd.Key[3],cdvd.Key[4],cdvd.Key[14],cdvd.Key[15] );
// Now's a good time to reload the ELF info...
if( ElfCRC == 0 )
if( IsPs2 && (ElfCRC == 0) )
{
ElfCRC = loadElfCRC( str );
ElfApplyPatches();
GSsetGameCRC( ElfCRC, 0 );
if( GSsetGameCRC != NULL )
GSsetGameCRC( ElfCRC, 0 );
}
}
s32 cdvdGetToc(void* toc)
{
s32 ret = CDVD.getTOC(toc);
if (ret == -1) ret = 0x80;
s32 ret = CDVD->getTOC(toc);
if (ret == -1) ret = 0x80;
return ret;
}
s32 cdvdReadSubQ(s32 lsn, cdvdSubQ* subq)
{
s32 ret = CDVD.readSubQ(lsn, subq);
s32 ret = CDVD->readSubQ(lsn, subq);
if (ret == -1) ret = 0x80;
return ret;
}
s32 cdvdCtrlTrayOpen()
{
s32 ret = CDVD.ctrlTrayOpen();
s32 ret = CDVD->ctrlTrayOpen();
if (ret == -1) ret = 0x80;
return ret;
}
s32 cdvdCtrlTrayClose()
{
s32 ret = CDVD.ctrlTrayClose();
s32 ret = CDVD->ctrlTrayClose();
if (ret == -1) ret = 0x80;
return ret;
}
@ -428,9 +430,9 @@ s32 cdvdCtrlTrayClose()
// checks if tray was opened since last call to this func
s32 cdvdGetTrayStatus()
{
s32 ret = CDVD.getTrayStatus();
if (ret == -1)
s32 ret = CDVD->getTrayStatus();
if (ret == -1)
return(CDVD_TRAY_CLOSE);
else
return(ret);
@ -448,7 +450,7 @@ static __forceinline void cdvdGetDiskType()
// check whether disc is single or dual layer
// if its dual layer, check what the disctype is and what sector number
// layer1 starts at
//
//
// args: gets value for dvd type (0=single layer, 1=ptp, 2=otp)
// gets value for start lsn of layer1
// returns: 1 if on dual layer disc
@ -458,7 +460,7 @@ static s32 cdvdReadDvdDualInfo(s32* dualType, u32* layer1Start)
*dualType = 0;
*layer1Start = 0;
return CDVD.getDualInfo(dualType,layer1Start);
return CDVD->getDualInfo(dualType,layer1Start);
}
static uint cdvdBlockReadTime( CDVD_MODE_TYPE mode )
@ -513,21 +515,20 @@ void SaveState::cdvdFreeze()
}
}
// Modified by (efp) - 16/01/2006
void cdvdDetectDisk()
{
cdvd.Type = DoCDVDdetectDiskType();
char str[g_MaxPath];
int result = GetPS2ElfName(str);
bool IsPs2 = (GetPS2ElfName(str) == 2);
// Now's a good time to reload the ELF info...
if( ElfCRC == 0 )
if( IsPs2 && (ElfCRC == 0) )
{
ElfCRC = loadElfCRC( str );
ElfApplyPatches();
GSsetGameCRC( ElfCRC, 0 );
if( GSsetGameCRC != NULL )
GSsetGameCRC( ElfCRC, 0 );
}
}
@ -543,7 +544,7 @@ void mechaDecryptBytes( u32 madr, int size )
int shiftAmount = (cdvd.decSet>>4) & 7;
int doXor = (cdvd.decSet) & 1;
int doShift = (cdvd.decSet) & 2;
u8* curval = iopPhysMem( madr );
for( int i=0; i<size; ++i, ++curval )
{
@ -580,7 +581,7 @@ int cdvdReadSector() {
u32 lsn = cdvd.Sector;
cdvdReadDvdDualInfo(&dualType, &layer1Start);
if((dualType == 1) && (lsn >= layer1Start))
{
// dual layer ptp disc
@ -594,13 +595,13 @@ int cdvdReadSector() {
lsn = ~(layer1Start+0x30000 - 1);
}
else
{
{
// Assuming the other dualType is 0,
// single layer disc, or on first layer of dual layer disc.
layerNum = 0;
lsn += 0x30000;
}
mdest[0] = 0x20 | layerNum;
mdest[1] = (u8)(lsn >> 16);
mdest[2] = (u8)(lsn >> 8);
@ -619,36 +620,19 @@ int cdvdReadSector() {
mdest[11] = 0;
// normal 2048 bytes of sector data
if (cdr.pTransfer == NULL)
{
// Unlike CDVDiso, the internal IsoReadTrack function will pass an error if lsn is more
// then the number of blocks in the iso. If this happens, cdr.pTransfer will be NULL.
//
// Passing null to memcpy is a bad thing, and will result in, for example, the start of
// Final Fantasy X-2 crashing. So we won't.
DevCon::WriteLn("Bad Transfer!");
for (int i = 12; i <= 2060; i++)
{
mdest[i] = 0;
}
}
else
{
memcpy_fast( &mdest[12], cdr.pTransfer, 2048);
}
memcpy_fast( &mdest[12], cdr.Transfer, 2048);
// 4 bytes of edc (not calculated at present)
mdest[2060] = 0;
mdest[2061] = 0;
mdest[2062] = 0;
mdest[2063] = 0;
mdest[2063] = 0;
}
else
{
memcpy_fast( mdest, cdr.pTransfer, cdvd.BlockSize);
memcpy_fast( mdest, cdr.Transfer, cdvd.BlockSize);
}
// decrypt sector's bytes
if( cdvd.decSet ) mechaDecryptBytes( HW_DMA3_MADR, cdvd.BlockSize );
@ -730,24 +714,16 @@ __forceinline void cdvdReadInterrupt()
}
else
{
if (cdvd.RErr == 0)
if (cdvd.RErr == 0)
{
cdr.RErr = DoCDVDgetBuffer(cdr.Transfer);
cdr.pTransfer = cdr.Transfer;
}
else
{
DevCon::WriteLn("Error reading track.");
cdr.pTransfer = NULL;
}
if (cdr.RErr == -1)
else if (cdr.RErr == -1)
{
cdvd.RetryCntP++;
Console::Error("CDVD READ ERROR, sector=%d", params cdvd.Sector);
if (cdvd.RetryCntP <= cdvd.RetryCnt)
if (cdvd.RetryCntP <= cdvd.RetryCnt)
{
cdvd.RErr = DoCDVDreadTrack(cdvd.Sector, cdvd.ReadMode);
CDVDREAD_INT(cdvd.ReadTime);
@ -816,7 +792,7 @@ static uint cdvdStartSeek( uint newsector, CDVD_MODE_TYPE mode )
else if( (tbl_ContigiousSeekDelta[mode] == 0) || (delta >= tbl_ContigiousSeekDelta[mode]) )
{
// Select either Full or Fast seek depending on delta:
if( delta >= tbl_FastSeekDelta[mode] )
{
// Full Seek
@ -832,7 +808,7 @@ static uint cdvdStartSeek( uint newsector, CDVD_MODE_TYPE mode )
else
{
CDR_LOG( "CdSeek Begin > Contiguous block without seek - delta=%d sectors", delta );
// seektime is the time it takes to read to the destination block:
seektime = delta * cdvd.ReadTime;
@ -845,7 +821,7 @@ static uint cdvdStartSeek( uint newsector, CDVD_MODE_TYPE mode )
// setting Readed to 0 skips the seek logic, which means the next call to
// cdvdReadInterrupt will load a block. So make sure it's properly scheduled
// based on sector read speeds:
seektime = cdvd.ReadTime;
}
}
@ -896,7 +872,7 @@ static __forceinline u8 cdvdRead18(void) // SDATAOUT
ret = cdvd.Result[cdvd.ResultP-1];
}
CDR_LOG("cdvdRead18(SDataOut) %x (ResultC=%d, ResultP=%d)", ret, cdvd.ResultC, cdvd.ResultP);
return ret;
}
@ -908,32 +884,32 @@ u8 cdvdRead(u8 key)
CDR_LOG("cdvdRead04(NCMD) %x", cdvd.nCommand);
return cdvd.nCommand;
break;
case 0x05: // N-READY
CDR_LOG("cdvdRead05(NReady) %x", cdvd.Ready);
return cdvd.Ready;
break;
case 0x06: // ERROR
CDR_LOG("cdvdRead06(Error) %x", cdvd.Error);
return cdvd.Error;
break;
case 0x07: // BREAK
CDR_LOG("cdvdRead07(Break) %x", 0);
return 0;
break;
case 0x08: // STATUS
CDR_LOG("cdvdRead08(Status) %x", cdvd.Status);
return cdvd.Status;
break;
case 0x0A: // STATUS
CDR_LOG("cdvdRead0A(Status) %x", cdvd.Status);
return cdvd.Status;
break;
case 0x0B: // TRAY-STATE (if tray has been opened)
{
u8 tray = cdvdGetTrayStatus();
@ -945,104 +921,104 @@ u8 cdvdRead(u8 key)
CDR_LOG("cdvdRead0C(Min) %x", itob((u8)(cdvd.Sector/(60*75))));
return itob((u8)(cdvd.Sector/(60*75)));
break;
case 0x0D: // CRT SECOND
CDR_LOG("cdvdRead0D(Sec) %x", itob((u8)((cdvd.Sector/75)%60)+2));
return itob((u8)((cdvd.Sector/75)%60)+2);
break;
case 0x0E: // CRT FRAME
CDR_LOG("cdvdRead0E(Frame) %x", itob((u8)(cdvd.Sector%75)));
return itob((u8)(cdvd.Sector%75));
break;
case 0x0F: // TYPE
CDR_LOG("cdvdRead0F(Disc Type) %x", cdvd.Type);
cdvdGetDiskType();
return cdvd.Type;
break;
case 0x13: // UNKNOWN
CDR_LOG("cdvdRead13(Unknown) %x", 4);
return 4;
break;
case 0x15: // RSV
CDR_LOG("cdvdRead15(RSV)");
return 0x01; // | 0x80 for ATAPI mode
break;
case 0x16: // SCOMMAND
CDR_LOG("cdvdRead16(SCMD) %x", cdvd.sCommand);
return cdvd.sCommand;
break;
case 0x17: // SREADY
CDR_LOG("cdvdRead17(SReady) %x", cdvd.sDataIn);
return cdvd.sDataIn;
break;
case 0x18:
case 0x18:
return cdvdRead18();
break;
case 0x20:
case 0x21:
case 0x22:
case 0x23:
case 0x24:
{
case 0x20:
case 0x21:
case 0x22:
case 0x23:
case 0x24:
{
int temp = key - 0x20;
CDR_LOG("cdvdRead%d(Key%d) %x", key, temp, cdvd.Key[temp]);
return cdvd.Key[temp];
break;
}
case 0x28:
case 0x29:
case 0x2A:
case 0x2B:
case 0x2C:
{
case 0x28:
case 0x29:
case 0x2A:
case 0x2B:
case 0x2C:
{
int temp = key - 0x23;
CDR_LOG("cdvdRead%d(Key%d) %x", key, temp, cdvd.Key[temp]);
return cdvd.Key[temp];
break;
}
case 0x30:
case 0x31:
case 0x32:
case 0x33:
case 0x34:
{
case 0x30:
case 0x31:
case 0x32:
case 0x33:
case 0x34:
{
int temp = key - 0x26;
CDR_LOG("cdvdRead%d(Key%d) %x", key, temp, cdvd.Key[temp]);
return cdvd.Key[temp];
break;
}
case 0x38: // valid parts of key data (first and last are valid)
CDR_LOG("cdvdRead38(KeysValid) %x", cdvd.Key[15]);
return cdvd.Key[15];
break;
case 0x39: // KEY-XOR
CDR_LOG("cdvdRead39(KeyXor) %x", cdvd.KeyXor);
return cdvd.KeyXor;
break;
case 0x3A: // DEC_SET
CDR_LOG("cdvdRead3A(DecSet) %x", cdvd.decSet);
Console::WriteLn("DecSet Read: %02X", params cdvd.decSet);
return cdvd.decSet;
break;
default:
// note: notify the console since this is a potentially serious emulation problem:
PSXHW_LOG("*Unknown 8bit read at address 0x1f4020%x", key);
@ -1064,7 +1040,7 @@ static void cdvdWrite04(u8 rt) { // NCOMMAND
case N_CD_NOP: // CdNop_
cdvdSetIrq();
break;
case N_CD_STANDBY: // CdStandby
// Seek to sector zero. The cdvdStartSeek function will simulate
@ -1092,10 +1068,10 @@ static void cdvdWrite04(u8 rt) { // NCOMMAND
cdvd.ReadTime = cdvdBlockReadTime( MODE_DVDROM );
CDVD_INT( cdvdStartSeek( *(uint*)(cdvd.Param+0), MODE_DVDROM ) );
break;
case N_CD_READ: // CdRead
// Assign the seek to sector based on cdvd.Param[0]-[3], and the number of sectors based on cdvd.Param[4]-[7].
cdvd.SeekToSector = *(u32*) (cdvd.Param+0);
cdvd.SeekToSector = *(u32*) (cdvd.Param+0);
cdvd.nSectors = *(u32*)(cdvd.Param+4);
cdvd.RetryCnt = (cdvd.Param[8] == 0) ? 0x100 : cdvd.Param[8];
cdvd.SpindlCtrl = cdvd.Param[9];
@ -1103,7 +1079,7 @@ static void cdvdWrite04(u8 rt) { // NCOMMAND
switch (cdvd.Param[10]) {
case 2: cdvd.ReadMode = CDVD_MODE_2340; cdvd.BlockSize = 2340; break;
case 1: cdvd.ReadMode = CDVD_MODE_2328; cdvd.BlockSize = 2328; break;
case 0:
case 0:
default: cdvd.ReadMode = CDVD_MODE_2048; cdvd.BlockSize = 2048; break;
}
@ -1131,16 +1107,16 @@ static void cdvdWrite04(u8 rt) { // NCOMMAND
case N_CD_READ_CDDA: // CdReadCDDA
case N_CD_READ_XCDDA: // CdReadXCDDA
// Assign the seek to sector based on cdvd.Param[0]-[3], and the number of sectors based on cdvd.Param[4]-[7].
cdvd.SeekToSector = *(u32*) (cdvd.Param+0);
cdvd.SeekToSector = *(u32*) (cdvd.Param+0);
cdvd.nSectors = *(u32*)(cdvd.Param+4);
if (cdvd.Param[8] == 0)
if (cdvd.Param[8] == 0)
cdvd.RetryCnt = 0x100;
else
else
cdvd.RetryCnt = cdvd.Param[8];
cdvd.SpindlCtrl = cdvd.Param[9];
switch (cdvd.Param[9]) {
case 0x01: cdvd.Speed = 1; break;
case 0x02: cdvd.Speed = 2; break;
@ -1148,7 +1124,7 @@ static void cdvdWrite04(u8 rt) { // NCOMMAND
case 0x04: cdvd.Speed = 12; break;
default: cdvd.Speed = 24; break;
}
switch (cdvd.Param[10]) {
case 1: cdvd.ReadMode = CDVD_MODE_2368; cdvd.BlockSize = 2368; break;
case 2:
@ -1161,7 +1137,7 @@ static void cdvdWrite04(u8 rt) { // NCOMMAND
if( Config.cdvdPrint )
Console::WriteLn("CdAudioRead: Reading Sector %d(%d Blocks of Size %d) at Speed=%dx",
params cdvd.Sector, cdvd.nSectors,cdvd.BlockSize,cdvd.Speed);
cdvd.ReadTime = cdvdBlockReadTime( MODE_CDROM );
CDVDREAD_INT( cdvdStartSeek( cdvd.SeekToSector, MODE_CDROM ) );
@ -1178,29 +1154,29 @@ static void cdvdWrite04(u8 rt) { // NCOMMAND
case N_DVD_READ: // DvdRead
// Assign the seek to sector based on cdvd.Param[0]-[3], and the number of sectors based on cdvd.Param[4]-[7].
cdvd.SeekToSector = *(u32*) (cdvd.Param+0);
cdvd.SeekToSector = *(u32*) (cdvd.Param+0);
cdvd.nSectors = *(u32*)(cdvd.Param+4);
if (cdvd.Param[8] == 0)
if (cdvd.Param[8] == 0)
cdvd.RetryCnt = 0x100;
else
else
cdvd.RetryCnt = cdvd.Param[8];
cdvd.SpindlCtrl = cdvd.Param[9];
cdvd.Speed = 4;
cdvd.ReadMode = CDVD_MODE_2048;
cdvd.BlockSize = 2064; // Why oh why was it 2064
CDR_LOG( "DvdRead > startSector=%d, nSectors=%d, RetryCnt=%x, Speed=%x(%x), ReadMode=%x(%x) (1074=%x)",
cdvd.Sector, cdvd.nSectors, cdvd.RetryCnt, cdvd.Speed, cdvd.Param[9], cdvd.ReadMode, cdvd.Param[10], psxHu32(0x1074));
if( Config.cdvdPrint )
Console::WriteLn("DvdRead: Reading Sector %d(%d Blocks of Size %d) at Speed=%dx",
params cdvd.Sector, cdvd.nSectors,cdvd.BlockSize,cdvd.Speed);
cdvd.ReadTime = cdvdBlockReadTime( MODE_DVDROM );
CDVDREAD_INT( cdvdStartSeek( cdvd.SeekToSector, MODE_DVDROM ) );
// Read-ahead by telling the plugin about the track now.
// This helps improve performance on actual from-cd emulation
// (ie, not using the hard drive)
@ -1224,7 +1200,7 @@ static void cdvdWrite04(u8 rt) { // NCOMMAND
HW_DMA3_CHCR &= ~0x01000000;
psxDmaInterrupt(3);
break;
case N_CD_READ_KEY: // CdReadKey
{
u8 arg0 = cdvd.Param[0];
@ -1306,9 +1282,9 @@ static __forceinline void cdvdWrite0F(u8 rt) { // TYPE
static __forceinline void cdvdWrite14(u8 rt) { // PS1 MODE??
u32 cycle = psxRegs.cycle;
if (rt == 0xFE)
if (rt == 0xFE)
Console::Notice("*PCSX2*: go PS1 mode DISC SPEED = FAST");
else
else
Console::Notice("*PCSX2*: go PS1 mode DISC SPEED = %dX", params rt);
psxReset();
@ -1330,7 +1306,7 @@ static void cdvdWrite16(u8 rt) // SCOMMAND
// int i, lbn, type, min, sec, frm, address;
int address;
u8 tmp;
CDR_LOG("cdvdWrite16: SCMD %s (%x) (ParamP = %x)", sCmdName[rt], rt, cdvd.ParamP);
cdvd.sCommand = rt;
@ -1352,17 +1328,17 @@ static void cdvdWrite16(u8 rt) // SCOMMAND
SetResultSize(4);
cdvdGetMechaVer(&cdvd.Result[0]);
break;
case 0x44: // write console ID (9:1)
SetResultSize(1);
cdvd.Result[0] = cdvdWriteConsoleID(&cdvd.Param[1]);
break;
case 0x45: // read console ID (1:9)
SetResultSize(9);
cdvd.Result[0] = cdvdReadConsoleID(&cdvd.Result[1]);
break;
case 0xFD: // _sceCdReadRenewalDate (1:6) BCD
SetResultSize(6);
cdvd.Result[0] = 0;
@ -1380,7 +1356,7 @@ static void cdvdWrite16(u8 rt) // SCOMMAND
break;
}
break;
case 0x05: // CdTrayReqState (0:1) - resets the tray open detection
SetResultSize(1);
cdvd.Result[0] = 0;
@ -1401,7 +1377,7 @@ static void cdvdWrite16(u8 rt) // SCOMMAND
cdvd.Result[2] = itob(cdvd.RTC.minute); //Minutes
cdvd.Result[3] = itob((cdvd.RTC.hour+8) %24); //Hours
cdvd.Result[4] = 0; //Nothing
cdvd.Result[5] = itob(cdvd.RTC.day); //Day
cdvd.Result[5] = itob(cdvd.RTC.day); //Day
if(cdvd.Result[3] <= 7) cdvd.Result[5] += 1;
cdvd.Result[6] = itob(cdvd.RTC.month)+0x80; //Month
cdvd.Result[7] = itob(cdvd.RTC.year); //Year
@ -1432,8 +1408,8 @@ static void cdvdWrite16(u8 rt) // SCOMMAND
case 0x0A: // sceCdReadNVM (2:3)
address = (cdvd.Param[0]<<8) | cdvd.Param[1];
if (address < 512)
if (address < 512)
{
SetResultSize(3);
cdvd.Result[0] = cdvdReadNVM(&cdvd.Result[1], address*2, 2);
@ -1441,8 +1417,8 @@ static void cdvdWrite16(u8 rt) // SCOMMAND
tmp = cdvd.Result[1];
cdvd.Result[1] = cdvd.Result[2];
cdvd.Result[2] = tmp;
}
else
}
else
{
SetResultSize(1);
cdvd.Result[0] = 0xff;
@ -1452,26 +1428,26 @@ static void cdvdWrite16(u8 rt) // SCOMMAND
case 0x0B: // sceCdWriteNVM (4:1)
SetResultSize(1);
address = (cdvd.Param[0]<<8) | cdvd.Param[1];
if (address < 512)
if (address < 512)
{
// swap bytes around
tmp = cdvd.Param[2];
cdvd.Param[2] = cdvd.Param[3];
cdvd.Param[3] = tmp;
cdvd.Result[0] = cdvdWriteNVM(&cdvd.Param[2], address*2, 2);
}
else
}
else
{
cdvd.Result[0] = 0xff;
}
break;
// case 0x0C: // sceCdSetHDMode (1:1)
// case 0x0C: // sceCdSetHDMode (1:1)
// break;
case 0x0F: // sceCdPowerOff (0:1)- Call74 from Xcdvdman
case 0x0F: // sceCdPowerOff (0:1)- Call74 from Xcdvdman
SetResultSize(1);
cdvd.Result[0] = 0;
break;
@ -1492,7 +1468,7 @@ static void cdvdWrite16(u8 rt) // SCOMMAND
cdvd.Result[0] = 0; //8 is a flag; not used
break;
case 0x15: // sceCdForbidDVDP (0:1)
case 0x15: // sceCdForbidDVDP (0:1)
//Console::WriteLn("sceCdForbidDVDP");
SetResultSize(1);
cdvd.Result[0] = 5;
@ -1531,7 +1507,7 @@ static void cdvdWrite16(u8 rt) // SCOMMAND
cdvd.Result[0] = 0;
break;
// case 0x1D: // cdvdman_call116 (0:5) - In V10 Bios
// case 0x1D: // cdvdman_call116 (0:5) - In V10 Bios
// break;
case 0x1E: // sceRemote2Read (0:5) - // 00 14 AA BB CC -> remote key code
@ -1553,10 +1529,10 @@ static void cdvdWrite16(u8 rt) // SCOMMAND
cdvd.Result[2] = 0x00;
break;
// case 0x21: // sceCdWriteWakeUpTime (8:1)
// case 0x21: // sceCdWriteWakeUpTime (8:1)
// break;
case 0x22: // sceCdReadWakeUpTime (0:10)
case 0x22: // sceCdReadWakeUpTime (0:10)
SetResultSize(10);
cdvd.Result[0] = 0;
cdvd.Result[1] = 0;
@ -1570,22 +1546,22 @@ static void cdvdWrite16(u8 rt) // SCOMMAND
cdvd.Result[9] = 0;
break;
case 0x24: // sceCdRCBypassCtrl (1:1) - In V10 Bios
case 0x24: // sceCdRCBypassCtrl (1:1) - In V10 Bios
// FIXME: because PRId<0x23, the bit 0 of sio2 don't get updated 0xBF808284
SetResultSize(1);
cdvd.Result[0] = 0;
break;
// case 0x25: // cdvdman_call120 (1:1) - In V10 Bios
// case 0x25: // cdvdman_call120 (1:1) - In V10 Bios
// break;
// case 0x26: // cdvdman_call128 (0,3) - In V10 Bios
// case 0x26: // cdvdman_call128 (0,3) - In V10 Bios
// break;
// case 0x27: // cdvdman_call148 (0:13) - In V10 Bios
// case 0x27: // cdvdman_call148 (0:13) - In V10 Bios
// break;
// case 0x28: // cdvdman_call150 (1:1) - In V10 Bios
// case 0x28: // cdvdman_call150 (1:1) - In V10 Bios
// break;
case 0x29: //sceCdNoticeGameStart (1:1)
@ -1624,7 +1600,7 @@ static void cdvdWrite16(u8 rt) // SCOMMAND
case 0x36: //cdvdman_call189 [__sceCdReadRegionParams - made up name] (0:15) i think it is 16, not 15
SetResultSize(15);
cdvdGetMechaVer(&cdvd.Result[1]);
cdvd.Result[0] = cdvdReadRegionParams(&cdvd.Result[3]);//size==8
Console::WriteLn("REGION PARAMS = %s %s", params mg_zones[cdvd.Result[1]], &cdvd.Result[3]);
@ -1714,7 +1690,7 @@ static void cdvdWrite16(u8 rt) // SCOMMAND
case 0x84: // secrman: __mechacon_auth_0x84
SetResultSize(1+8+4);//in:0
cdvd.Result[0] = 0;
cdvd.Result[1] = 0x21;
cdvd.Result[2] = 0xdc;
cdvd.Result[3] = 0x31;
@ -1733,7 +1709,7 @@ static void cdvdWrite16(u8 rt) // SCOMMAND
case 0x85: // secrman: __mechacon_auth_0x85
SetResultSize(1+4+8);//in:0
cdvd.Result[0] = 0;
cdvd.Result[1] = 0xeb;
cdvd.Result[2] = 0x01;
cdvd.Result[3] = 0xc7;
@ -1793,7 +1769,7 @@ static void cdvdWrite16(u8 rt) // SCOMMAND
fail_pol_cal();
break;
}
Console::Write("[MG] ELF_size=0x%X Hdr_size=0x%X unk=0x%X flags=0x%X count=%d zones=",
params *(u32*)&cdvd.mg_buffer[0x10], *(u16*)&cdvd.mg_buffer[0x14], *(u16*)&cdvd.mg_buffer[0x16],
*(u16*)&cdvd.mg_buffer[0x18], *(u16*)&cdvd.mg_buffer[0x1A]);
@ -1802,18 +1778,18 @@ static void cdvdWrite16(u8 rt) // SCOMMAND
if (cdvd.mg_buffer[0x1C] & (1<<i)) Console::Write("%s ", params mg_zones[i]);
}
Console::Newline();
bit_ofs = mg_BIToffset(cdvd.mg_buffer);
psrc = (u64*)&cdvd.mg_buffer[bit_ofs-0x20];
pdst = (u64*)cdvd.mg_kbit;
pdst[0] = psrc[0];
pdst[0] = psrc[0];
pdst[1] = psrc[1];
//memcpy(cdvd.mg_kbit, &cdvd.mg_buffer[bit_ofs-0x20], 0x10);
pdst = (u64*)cdvd.mg_kcon;
pdst[0] = psrc[2];
pdst[0] = psrc[2];
pdst[1] = psrc[3];
//memcpy(cdvd.mg_kcon, &cdvd.mg_buffer[bit_ofs-0x10], 0x10);
@ -1833,7 +1809,7 @@ static void cdvdWrite16(u8 rt) // SCOMMAND
cdvd.mg_datatype = 1;//header data
Console::WriteLn("[MG] hcode=%d cnum=%d a2=%d length=0x%X", params
cdvd.Param[0], cdvd.Param[3], cdvd.Param[4], cdvd.mg_maxsize = cdvd.Param[1] | (((int)cdvd.Param[2])<<8));
cdvd.Result[0] = 0; // 0 complete ; 1 busy ; 0x80 error
break;
@ -1842,7 +1818,7 @@ static void cdvdWrite16(u8 rt) // SCOMMAND
SetResultSize(3);//in:0
int bit_ofs = mg_BIToffset(cdvd.mg_buffer);
memcpy_fast(cdvd.mg_buffer, &cdvd.mg_buffer[bit_ofs], 8+16*cdvd.mg_buffer[bit_ofs+4]);
cdvd.mg_maxsize = 0; // don't allow any write
cdvd.mg_size = 8+16*cdvd.mg_buffer[4];//new offset, i just moved the data
Console::WriteLn("[MG] BIT count=%d", params cdvd.mg_buffer[4]);
@ -1913,15 +1889,15 @@ static void cdvdWrite16(u8 rt) // SCOMMAND
Console::WriteLn("SCMD Unknown %x", params rt);
break;
} // end switch
//Console::WriteLn("SCMD - 0x%x\n", params rt);
cdvd.ParamP = 0;
cdvd.ParamP = 0;
cdvd.ParamC = 0;
}
static __forceinline void cdvdWrite17(u8 rt) { // SDATAIN
CDR_LOG("cdvdWrite17(SDataIn) %x", rt);
if (cdvd.ParamP < 32) {
cdvd.Param[cdvd.ParamP++] = rt;
cdvd.ParamC++;
@ -1959,4 +1935,4 @@ void cdvdWrite(u8 key, u8 rt)
Console::Notice("IOP Unknown 8bit write to addr 0x1f4020%x = 0x%x", params key, rt);
break;
}
}
}

View File

@ -16,8 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __CDVD_H__
#define __CDVD_H__
#pragma once
#include "IopCommon.h"
#include "CDVD/CDVDaccess.h"
@ -132,6 +131,38 @@ struct cdvdStruct {
bool Spinning; // indicates if the Cdvd is spinning or needs a spinup delay
};
struct CDVD_API
{
void (CALLBACK *close)();
// Don't need init or shutdown. iso/nodisc have no init/shutdown and plugin's
// is handled by the PluginManager.
// Don't need plugin specific things like freeze, test, or other stuff here.
// Those are handled by the plugin manager specifically.
_CDVDopen open;
_CDVDreadTrack readTrack;
_CDVDgetBuffer getBuffer;
_CDVDreadSubQ readSubQ;
_CDVDgetTN getTN;
_CDVDgetTD getTD;
_CDVDgetTOC getTOC;
_CDVDgetDiskType getDiskType;
_CDVDgetTrayStatus getTrayStatus;
_CDVDctrlTrayOpen ctrlTrayOpen;
_CDVDctrlTrayClose ctrlTrayClose;
_CDVDnewDiskCB newDiskCB;
// special functions, not in external interface yet
_CDVDreadSector readSector;
_CDVDgetBuffer2 getBuffer2;
_CDVDgetDualInfo getDualInfo;
string (*getUniqueFilename)();
};
extern void cdvdReset();
extern void cdvdVsync();
extern void cdvdActionInterrupt();
@ -146,8 +177,21 @@ extern void cdvdWrite(u8 key, u8 rt);
// Platform dependent system time assignment (see WinMisc / LnxMisc)
extern void cdvdSetSystemTime(cdvdStruct& setme);
extern CDVDplugin CDVD;
extern CDVDplugin ISO;
extern CDVDplugin NODISC;
// ----------------------------------------------------------------------------
// Multiple interface system for CDVD
// used to provide internal CDVDiso and NoDisc, and external plugin interfaces.
// ---------------------------------------------------------------------------
#endif /* __CDVD_H__ */
enum CDVD_SourceType
{
CDVDsrc_Iso = 0, // use built in ISO api
CDVDsrc_Plugin, // use external plugin
CDVDsrc_NoDisc, // use built in CDVDnull
};
extern void CDVDsys_ChangeSource( CDVD_SourceType type );
extern CDVD_API* CDVD; // currently active CDVD access mode api (either Iso, NoDisc, or Plugin)
extern CDVD_API CDVDapi_Plugin;
extern CDVD_API CDVDapi_Iso;
extern CDVD_API CDVDapi_NoDisc;

View File

@ -32,13 +32,30 @@
#include "IsoFSdrv.h"
#include "CDVDisoReader.h"
static int diskTypeCached=-1;
// ----------------------------------------------------------------------------
// diskTypeCached
// Internal disc type cache, to reduce the overhead of disc type checks, which are
// performed quite liberally by many games (perhaps intended to keep the PS2 DVD
// from spinning down due to idle activity?).
// Cache is set to -1 for init and when the disc is removed/changed, which invokes
// a new DiskTypeCheck. Al subsequent checks use the non-negative value here.
//
static int diskTypeCached = -1;
// used to bridge the gap between the old getBuffer api and the new getBuffer2 api.
int lastReadSize;
static int plsn=0; // This never gets set, so it's always 0.
// Records last read block length for block dumping
static int plsn = 0;
static isoFile *blockDumpFile;
// Assertion check for CDVD != NULL (in devel and debgu builds), because its handier than
// relying on DEP exceptions -- and a little more reliable too.
static void CheckNullCDVD()
{
DevAssert( CDVD != NULL, "Invalid CDVD object state (null pointer exception)" );
}
/////////////////////////////////////////////////
//
// Disk Type detection stuff (from cdvdGigaherz)
@ -88,14 +105,14 @@ int CheckDiskTypeFS(int baseType)
static char bleh[2352];
int FindDiskType(int mType)
static int FindDiskType(int mType)
{
int dataTracks = 0;
int audioTracks = 0;
int iCDType = mType;
cdvdTN tn;
CDVD.getTN(&tn);
CDVD->getTN(&tn);
if (tn.strack != tn.etrack) // multitrack == CD.
{
@ -104,8 +121,8 @@ int FindDiskType(int mType)
else if (mType < 0)
{
cdvdTD td;
CDVD.getTD(0,&td);
CDVD->getTD(0,&td);
if (td.lsn > 452849)
{
iCDType = CDVD_TYPE_DETCTDVDS;
@ -128,7 +145,7 @@ int FindDiskType(int mType)
s32 dlt = 0;
u32 l1s = 0;
if(CDVD.getDualInfo(&dlt,&l1s)==0)
if(CDVD->getDualInfo(&dlt,&l1s)==0)
{
if (dlt > 0) iCDType = CDVD_TYPE_DETCTDVDD;
}
@ -154,12 +171,12 @@ int FindDiskType(int mType)
{
cdvdTD td,td2;
CDVD.getTD(i,&td);
CDVD->getTD(i,&td);
if (tn.etrack > i)
CDVD.getTD(i+1,&td2);
CDVD->getTD(i+1,&td2);
else
CDVD.getTD(0,&td2);
CDVD->getTD(0,&td2);
int tlength = td2.lsn - td.lsn;
@ -199,18 +216,21 @@ int FindDiskType(int mType)
return iCDType;
}
void DetectDiskType()
static void DetectDiskType()
{
if (CDVD.getTrayStatus() == CDVD_TRAY_OPEN)
if (CDVD->getTrayStatus() == CDVD_TRAY_OPEN)
{
diskTypeCached = CDVD_TYPE_NODISC;
return;
}
int baseMediaType = CDVD.getDiskType();
int baseMediaType = CDVD->getDiskType();
int mType = -1;
switch(baseMediaType) // Paranoid mode: do not trust the plugin's detection system to work correctly.
// Paranoid mode: do not trust the plugin's detection system to work correctly.
// (.. and there's no reason plugins should be doing their own detection anyway).
switch(baseMediaType)
{
case CDVD_TYPE_CDDA:
case CDVD_TYPE_PSCD:
@ -239,53 +259,52 @@ void DetectDiskType()
diskTypeCached = FindDiskType(mType);
}
// ----------------------------------------------------------------------------
// CDVDsys_ChangeSource
//
/////////////////////////////////////////////////
s32 DoCDVDinit()
void CDVDsys_ChangeSource( CDVD_SourceType type )
{
diskTypeCached = -1;
CloseCDVD();
switch( type )
{
case CDVDsrc_Iso:
CDVD = &CDVDapi_Iso;
break;
case CDVDsrc_NoDisc:
CDVD = &CDVDapi_NoDisc;
break;
if(CDVD.initCount) *CDVD.initCount++; // used to handle the case where the plugin was inited at boot, but then iso takes over
return CDVD.init();
}
case CDVDsrc_Plugin:
CDVD = &CDVDapi_Plugin;
break;
void DoCDVDshutdown()
{
if(CDVD.initCount) *CDVD.initCount--;
CDVD.shutdown();
jNO_DEFAULT;
}
}
s32 DoCDVDopen(const char* pTitleFilename)
{
int ret = CDVD.open(pTitleFilename);
CheckNullCDVD();
int ret = CDVD->open(pTitleFilename);
int cdtype = DoCDVDdetectDiskType();
if ((Config.Blockdump) && (cdtype != CDVD_TYPE_NODISC))
{
char fname_only[g_MaxPath];
if (CDVD.init == ISO.init)
{
// Base it out of the current directory for now.
string temp = Path::GetWorkingDirectory() + Path::GetFilenameWithoutExt(isoFileName);
strcpy(fname_only, temp.c_str());
}
else
{
strcpy(fname_only, "Untitled");
}
string fname_only( CDVD->getUniqueFilename() );
string fname;
#ifdef ENABLE_TIMESTAMPS
#ifdef _WIN32
SYSTEMTIME time;
GetLocalTime(&time);
sprintf(
fname_only+strlen(fname_only),
" (%04d-%02d-%02d %02d-%02d-%02d).dump",
ssprintf( fname, (fname_only+" (%04d-%02d-%02d %02d-%02d-%02d).dump").c_str(),
time.wYear, time.wMonth, time.wDay,
time.wHour, time.wMinute, time.wSecond);
time.wHour, time.wMinute, time.wSecond
);
#else
time_t rawtime;
struct tm * timeinfo;
@ -293,17 +312,16 @@ s32 DoCDVDopen(const char* pTitleFilename)
time(&rawtime);
timeinfo = localtime(&rawtime);
sprintf(
fname_only+strlen(fname_only),
" (%04d-%02d-%02d %02d-%02d-%02d).dump",
ssprintf( fname, fname_only+" (%04d-%02d-%02d %02d-%02d-%02d).dump",
timeinfo->tm_year + 1900, timeinfo->tm_mon, timeinfo->tm_mday,
timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec
);
#endif
#else
strcat(fname_only, ".dump");
fname = fname_only + ".dump";
#endif
cdvdTD td;
CDVD.getTD(0, &td);
CDVD->getTD(0, &td);
int blockofs = 0, blocksize = 0, blocks = td.lsn;
@ -323,7 +341,7 @@ s32 DoCDVDopen(const char* pTitleFilename)
break;
}
blockDumpFile = isoCreate(fname_only, ISOFLAGS_BLOCKDUMP);
blockDumpFile = isoCreate(fname.c_str(), ISOFLAGS_BLOCKDUMP);
if (blockDumpFile) isoSetFormat(blockDumpFile, blockofs, blocksize, blocks);
}
else
@ -336,26 +354,31 @@ s32 DoCDVDopen(const char* pTitleFilename)
void DoCDVDclose()
{
CheckNullCDVD();
if(blockDumpFile) isoClose(blockDumpFile);
CDVD.close();
if( CDVD->close != NULL )
CDVD->close();
DoCDVDresetDiskTypeCache();
}
s32 DoCDVDreadSector(u8* buffer, u32 lsn, int mode)
{
int ret = CDVD.readSector(buffer,lsn,mode);
CheckNullCDVD();
int ret = CDVD->readSector(buffer,lsn,mode);
if(ret==0)
if(ret == 0 && blockDumpFile != NULL )
{
if (blockDumpFile != NULL)
{
isoWriteBlock(blockDumpFile, buffer, plsn);
}
isoWriteBlock(blockDumpFile, buffer, lsn);
}
return ret;
}
s32 DoCDVDreadTrack(u32 lsn, int mode)
{
CheckNullCDVD();
// TEMP: until all the plugins use the new CDVDgetBuffer style
switch (mode)
{
@ -375,21 +398,17 @@ s32 DoCDVDreadTrack(u32 lsn, int mode)
//DevCon::Notice("CDVD readTrack(lsn=%d,mode=%d)",params lsn, lastReadSize);
return CDVD.readTrack(lsn,mode);
return CDVD->readTrack(lsn,mode);
}
// return can be NULL (for async modes)
s32 DoCDVDgetBuffer(u8* buffer)
{
int ret = CDVD.getBuffer2(buffer);
CheckNullCDVD();
int ret = CDVD->getBuffer2(buffer);
if (ret == 0)
if (ret == 0 && blockDumpFile != NULL)
{
if (blockDumpFile != NULL)
{
isoWriteBlock(blockDumpFile, buffer, plsn);
}
isoWriteBlock(blockDumpFile, buffer, lastReadSize);
}
return ret;
@ -397,8 +416,8 @@ s32 DoCDVDgetBuffer(u8* buffer)
s32 DoCDVDdetectDiskType()
{
if(diskTypeCached<0) DetectDiskType();
CheckNullCDVD();
if(diskTypeCached < 0) DetectDiskType();
return diskTypeCached;
}
@ -412,10 +431,6 @@ void DoCDVDresetDiskTypeCache()
// CDVD null interface for Run BIOS menu
s32 CALLBACK NODISCinit()
{
return 0;
}
s32 CALLBACK NODISCopen(const char* pTitle)
{
@ -426,10 +441,6 @@ void CALLBACK NODISCclose()
{
}
void CALLBACK NODISCshutdown()
{
}
s32 CALLBACK NODISCreadTrack(u32 lsn, int mode)
{
return -1;
@ -476,10 +487,6 @@ s32 CALLBACK NODISCdummyS32()
return 0;
}
void CALLBACK NODISCdummyVOID()
{
}
void CALLBACK NODISCnewDiskCB(__unused void (*callback)())
{
}
@ -499,11 +506,16 @@ s32 CALLBACK NODISCgetDualInfo(s32* dualType, u32* _layer1start)
return -1;
}
CDVDplugin NODISC = {
NODISCinit,
NODISCopen,
const char* NODISCgetUniqueFilename()
{
DevAssert( false, "NODISC is an invalid CDVD object for block dumping.. >_<" );
return "epicfail";
}
CDVD_API CDVDapi_NoDisc =
{
NODISCclose,
NODISCshutdown,
NODISCopen,
NODISCreadTrack,
NODISCgetBuffer,
NODISCreadSubQ,
@ -515,9 +527,6 @@ CDVDplugin NODISC = {
NODISCdummyS32,
NODISCdummyS32,
NODISCdummyVOID,
NODISCdummyS32,
NODISCdummyVOID,
NODISCnewDiskCB,
NODISCreadSector,

View File

@ -16,13 +16,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __CDVD_ACCESS_H__
#define __CDVD_ACCESS_H__
#pragma once
extern s32 DoCDVDinit();
extern s32 DoCDVDopen(const char* pTitleFilename);
extern void DoCDVDclose();
extern void DoCDVDshutdown();
extern s32 DoCDVDreadSector(u8* buffer, u32 lsn, int mode);
extern s32 DoCDVDreadTrack(u32 lsn, int mode);
extern s32 DoCDVDgetBuffer(u8* buffer);
@ -31,4 +28,3 @@ extern void DoCDVDnewDiskCB(void (*callback)());
extern s32 DoCDVDdetectDiskType();
extern void DoCDVDresetDiskTypeCache();
#endif /* __CDVD_H__ */

View File

@ -29,26 +29,23 @@
#include "CDVDisoReader.h"
char isoFileName[g_MaxPath];
u8 *pbuffer;
static char isoFileName[g_MaxPath];
static u8 *pbuffer;
static u8 cdbuffer[2352] = {0};
static isoFile *iso = NULL;
static int psize, cdtype;
u8 cdbuffer[2352] = {0};
isoFile *iso;
s32 CALLBACK ISOinit()
void CALLBACK ISOclose()
{
CDVD_LOG("ISOinit\n");
return 0;
}
void CALLBACK ISOshutdown()
{
CDVD_LOG("ISOshutdown\n");
isoClose(iso);
iso = NULL;
}
s32 CALLBACK ISOopen(const char* pTitle)
{
ISOclose(); // just in case
if ((pTitle != NULL) && (strlen(pTitle) > 0))
strcpy(isoFileName, pTitle);
@ -75,11 +72,6 @@ s32 CALLBACK ISOopen(const char* pTitle)
return 0;
}
void CALLBACK ISOclose()
{
isoClose(iso);
}
s32 CALLBACK ISOreadSubQ(u32 lsn, cdvdSubQ* subq)
{
// fake it
@ -392,19 +384,20 @@ s32 CALLBACK ISOdummyS32()
return 0;
}
void CALLBACK ISOdummyVOID()
void CALLBACK ISOnewDiskCB(void(CALLBACK*)())
{
}
void CALLBACK ISOnewDiskCB(__unused void (*callback)())
string ISOgetUniqueFilename()
{
return Path::GetFilenameWithoutExt( isoFileName );
}
CDVDplugin ISO = {
ISOinit,
ISOopen,
CDVD_API CDVDapi_Iso =
{
ISOclose,
ISOshutdown,
ISOopen,
ISOreadTrack,
ISOgetBuffer, // emu shouldn't use this one.
ISOreadSubQ,
@ -412,13 +405,10 @@ CDVDplugin ISO = {
ISOgetTD,
ISOgetTOC,
ISOgetDiskType,
ISOdummyS32,
ISOdummyS32,
ISOdummyS32,
ISOdummyS32, // trayStatus
ISOdummyS32, // trayOpen
ISOdummyS32, // trayClose
ISOdummyVOID,
ISOdummyS32,
ISOdummyVOID,
ISOnewDiskCB,
ISOreadSector,

View File

@ -29,7 +29,4 @@
#include "IsoFStools.h"
#include "IsoFileFormats.h"
extern char isoFileName[g_MaxPath];
extern isoFile *iso;
#endif

View File

@ -315,7 +315,7 @@ void cdrInterrupt() {
SetResultSize(3);
cdr.StatP|= 0x2;
cdr.Result[0] = cdr.StatP;
if (CDVD.getTN(&cdr.ResultTN) == -1) {
if (CDVD->getTN(&cdr.ResultTN) == -1) {
cdr.Stat = DiskError;
cdr.Result[0]|= 0x01;
} else {
@ -330,7 +330,7 @@ void cdrInterrupt() {
cdr.Track = btoi(cdr.Param[0]);
SetResultSize(4);
cdr.StatP|= 0x2;
if (CDVD.getTD(cdr.Track, &trackInfo) == -1) {
if (CDVD->getTD(cdr.Track, &trackInfo) == -1) {
cdr.Stat = DiskError;
cdr.Result[0]|= 0x01;
} else {
@ -497,9 +497,9 @@ void cdrReadInterrupt() {
cdr.StatP|= 0x22;
cdr.Result[0] = cdr.StatP;
SysPrintf("Reading From CDR");
Console::Status("Reading From CDR");
cdr.RErr = DoCDVDgetBuffer(cdr.Transfer);
if (cdr.RErr == -1)
if (cdr.RErr == -1)
{
CDR_LOG(" err\n");
memzero_ptr<2340>(cdr.Transfer);
@ -509,6 +509,13 @@ void cdrReadInterrupt() {
CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime);
return;
}
else if(cdr.RErr == -2)
{
// async mode is not finished yet ... give it a bit more time
CDREAD_INT(cdReadTime / 4);
return;
}
cdr.Stat = DataReady;
CDR_LOG(" %x:%x:%x", cdr.Transfer[0], cdr.Transfer[1], cdr.Transfer[2]);

View File

@ -414,10 +414,10 @@ int isoWriteBlock(isoFile *iso, u8 *src, int lsn)
void isoClose(isoFile *iso)
{
if (iso == NULL ) return;
if (iso->handle) _closefile(iso->handle);
if (iso->htable) _closefile(iso->htable);
if (iso->buffer) free(iso->buffer);
free(iso);
safe_free( iso->buffer );
safe_free( iso );
}

View File

@ -5,21 +5,21 @@
* 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"
#include "IsoFileTools.h"
#ifdef _WIN32
#ifdef _WIN32
#include <windows.h>
void *_openfile(const char *filename, int flags)
@ -54,11 +54,11 @@ int _seekfile(void *handle, u64 offset, int whence)
{
u64 ofs = (u64)offset;
PLONG _ofs = (LONG*) & ofs;
// Console::WriteLn("_seekfile %p, %d_%d", params handle, _ofs[1], _ofs[0]);
SetFilePointer(handle, _ofs[0], &_ofs[1], (whence == SEEK_SET) ? FILE_BEGIN : FILE_END);
return 0;
}
@ -71,7 +71,7 @@ int _readfile(void *handle, void *dst, int size)
return ret;
}
int _writefile(void *handle, void *src, int size)
int _writefile(void *handle, const void *src, int size)
{
DWORD ret;
@ -94,18 +94,19 @@ void *_openfile(const char *filename, int flags)
if (flags & O_WRONLY)
return fopen64(filename, "wb");
else
else
return fopen64(filename, "rb");
}
u64 _tellfile(void *handle)
{
s64 cursize = ftell(handle);
FILE* fp = (FILE*)handle;
s64 cursize = ftell(fp);
if (cursize == -1)
{
// try 64bit
cursize = ftello64(handle);
cursize = ftello64(fp);
if (cursize < -1)
{
// zero top 32 bits
@ -117,26 +118,26 @@ u64 _tellfile(void *handle)
int _seekfile(void *handle, u64 offset, int whence)
{
int seekerr = fseeko64(handle, offset, whence);
int seekerr = fseeko64((FILE*)handle, offset, whence);
if (seekerr == -1) Console::Error("Failed to seek.");
return seekerr;
}
int _readfile(void *handle, void *dst, int size)
{
return fread(dst, 1, size, handle);
return fread(dst, 1, size, (FILE*)handle);
}
int _writefile(void *handle, void *src, int size)
int _writefile(void *handle, const void *src, int size)
{
return fwrite(src, 1, size, handle);
return fwrite(src, 1, size, (FILE*)handle);
}
void _closefile(void *handle)
{
fclose(handle);
fclose((FILE*)handle);
}
#endif

View File

@ -5,33 +5,35 @@
* 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 __ISO_FILE_TOOLS_H__
#define __ISO_FILE_TOOLS_H__
#pragma once
#ifndef _LARGEFILE_SOURCE
#define _LARGEFILE_SOURCE
#define _LARGEFILE_SOURCE
#endif
#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE64_SOURCE
#endif
#ifndef __USE_FILE_OFFSET64
#define __USE_FILE_OFFSET64
#endif
#define _FILE_OFFSET_BITS 64
#ifdef _MSC_VER
#pragma warning(disable:4018)
# pragma warning(disable:4018) // disable signed/unsigned mismatch error
#endif
#include "IopCommon.h"
@ -40,11 +42,10 @@
#include <fcntl.h>
#include <errno.h>
void *_openfile(const char *filename, int flags);
u64 _tellfile(void *handle);
int _seekfile(void *handle, u64 offset, int whence);
int _readfile(void *handle, void *dst, int size);
int _writefile(void *handle, void *src, int size);
void _closefile(void *handle);
extern void *_openfile(const char *filename, int flags);
extern u64 _tellfile(void *handle);
extern int _seekfile(void *handle, u64 offset, int whence);
extern int _readfile(void *handle, void *dst, int size);
extern int _writefile(void *handle, const void *src, int size);
extern void _closefile(void *handle);
#endif

View File

@ -27,7 +27,7 @@
//#define PSXCLK 186864000 /* 36.864 Mhz */
#define PS2CLK 294912000 //hz /* 294.912 mhz */
#define PCSX2_VERSION "(beta)"
#define PCSX2_VERSION "beta"
#include "System.h"

View File

@ -21,29 +21,31 @@
//////////////////////////////////////////////////////////////////////////////////////////
// Startup Parameters.
enum StartupMode
enum StartupModeType
{
BootMode_Normal = 0,
BootMode_Elf = 1, // not compatible with bios flag, probably
BootMode_Iso = 2,
BootMode_NoDisc = 3, // nodisc implies bios.
BootMode_Quick = 0,
BootMode_Bios = 0x10000,
BootMode_ModeMask = 0xFFFF,
Startup_FromCDVD = 0,
Startup_FromELF = 1, // not compatible with bios flag, probably
};
enum CDVD_SourceType;
class StartupParams
{
public:
// Name of the CDVD or ELF image to load.
// if NULL, the CDVD configured settings are used.
// Name of the CDVD image to load.
// if NULL, the CDVD plugin configured settings are used.
const char* ImageName;
// Name of the ELF file to load. If null, the CDVD is booted instead.
const char* ElfFile;
bool NoGui;
bool Enabled;
StartupMode BootMode;
bool NoGui;
bool Enabled;
StartupModeType StartupMode;
CDVD_SourceType CdvdSource;
// Ignored when booting ELFs.
bool SkipBios;
// Plugin overrides
const char* gsdll, *cdvddll, *spudll;

View File

@ -299,6 +299,10 @@ int IsBIOS(const char *filename, char *description)
return FALSE; //fail quietly
}
// return value:
// 0 - Invalid or unknown disc.
// 1 - PS1 CD
// 2 - PS2 CD
int GetPS2ElfName(char *name){
int f;
char buffer[g_MaxPath];//if a file is longer...it should be shorter :D
@ -309,7 +313,7 @@ int GetPS2ElfName(char *name){
// check if the file exists
if (IsoFS_findFile("SYSTEM.CNF;1", &tocEntry) != TRUE){
Console::Error("Boot Error > SYSTEM.CNF not found");
Console::Status("GetElfName: SYSTEM.CNF not found; invalid cd image or no disc present.");
return 0;//could not find; not a PS/PS2 cdvd
}
@ -323,7 +327,7 @@ int GetPS2ElfName(char *name){
if (pos==NULL){
pos=strstr(buffer, "BOOT");
if (pos==NULL) {
Console::Error("Boot Error > This is not a PS2 game!");
Console::Error("PCSX2 Boot Error: This is not a PS2 game!");
return 0;
}
return 1;
@ -434,8 +438,8 @@ void LoadGSState(const string& file)
delete( f );
GSclose();
PAD1close();
GSclose();
}
#endif

View File

@ -139,8 +139,12 @@ _SPU2test SPU2test;
_SPU2about SPU2about;
// CDVD
CDVDplugin CDVD_plugin = {0};
CDVDplugin CDVD = {0};
_CDVDclose CDVDclose;
_CDVDinit CDVDinit;
_CDVDshutdown CDVDshutdown;
_CDVDconfigure CDVDconfigure;
_CDVDabout CDVDabout;
_CDVDtest CDVDtest;
// DEV9
_DEV9init DEV9init;
@ -248,18 +252,18 @@ PS2E_FW_VERSION};
return -1; \
}
#define MapSymbol(name) MapSymbolVar(name,name)
#define MapSymbol_Fallback(name,fallback) MapSymbolVar_Fallback(name,name,fallback)
#define MapSymbol_Error(name) MapSymbolVar_Error(name,name)
#define MapSymbol(name) MapSymbolVar(name,name)
#define MapSymbol_Fallback(name,fallback) MapSymbolVar_Fallback(name,name,fallback)
#define MapSymbol_Error(name) MapSymbolVar_Error(name,name)
#define MapSymbol2(base,name) MapSymbolVar(base##_plugin.name,base##name)
#define MapSymbol2_Fallback(base,name,fallback) MapSymbolVar_Fallback(base##_plugin.name,base##name,fallback)
#define MapSymbol2_Error(base,name) MapSymbolVar_Error(base##_plugin.name,base##name)
#define MapSymbolCDVD(name) MapSymbolVar(CDVDapi_Plugin.name,CDVD##name)
#define MapSymbolCDVD_Fallback(name,fallback) MapSymbolVar_Fallback(CDVDapi_Plugin.name,CDVD##name,fallback)
#define MapSymbolCDVD_Error(name) MapSymbolVar_Error(CDVDapi_Plugin.name,CDVD##name)
// for pad1/2
#define MapSymbolPAD(var,name) MapSymbolVar(var##name,PAD##name)
#define MapSymbolPAD_Fallback(var,name) if((MapSymbolVarType(var##name,_PAD##name,PAD##name))==NULL) var##name = var##_##name
#define MapSymbolPAD_Error(var,name) MapSymbolVar_Error(var##name,PAD##name)
#define MapSymbolPAD(var,name) MapSymbolVar(var##name,PAD##name)
#define MapSymbolPAD_Fallback(var,name) if((MapSymbolVarType(var##name,_PAD##name,PAD##name))==NULL) var##name = var##_##name
#define MapSymbolPAD_Error(var,name) MapSymbolVar_Error(var##name,PAD##name)
void *GSplugin;
@ -300,13 +304,13 @@ void CALLBACK GS_printf(int timeout, char *fmt, ...) {
Console::WriteLn(msg);
}
s32 CALLBACK GS_freeze(int mode, freezeData *data) { data->size = 0; return 0; }
void CALLBACK GS_keyEvent(keyEvent *ev) {}
void CALLBACK GS_makeSnapshot(const char *path) {}
void CALLBACK GS_irqCallback(void (*callback)()) {}
void CALLBACK GS_configure() {}
void CALLBACK GS_about() {}
s32 CALLBACK GS_test() { return 0; }
static s32 CALLBACK GS_freeze(int mode, freezeData *data) { data->size = 0; return 0; }
static void CALLBACK GS_keyEvent(keyEvent *ev) {}
static void CALLBACK GS_makeSnapshot(const char *path) {}
static void CALLBACK GS_irqCallback(void (*callback)()) {}
static void CALLBACK GS_configure() {}
static void CALLBACK GS_about() {}
static s32 CALLBACK GS_test() { return 0; }
int LoadGSplugin(const string& filename)
{
@ -356,14 +360,14 @@ int LoadGSplugin(const string& filename)
return 0;
}
void *PAD1plugin;
static void *PAD1plugin;
void CALLBACK PAD1_configure() {}
void CALLBACK PAD1_about() {}
s32 CALLBACK PAD1_test() { return 0; }
s32 CALLBACK PAD1_freeze(int mode, freezeData *data) { if (mode == FREEZE_SIZE) data->size = 0; return 0; }
s32 CALLBACK PAD1_setSlot(u8 port, u8 slot) { return slot == 1; }
s32 CALLBACK PAD1_queryMtap(u8 port) { return 0; }
static void CALLBACK PAD1_configure() {}
static void CALLBACK PAD1_about() {}
static s32 CALLBACK PAD1_test() { return 0; }
static s32 CALLBACK PAD1_freeze(int mode, freezeData *data) { if (mode == FREEZE_SIZE) data->size = 0; return 0; }
static s32 CALLBACK PAD1_setSlot(u8 port, u8 slot) { return slot == 1; }
static s32 CALLBACK PAD1_queryMtap(u8 port) { return 0; }
int LoadPAD1plugin(const string& filename) {
void *drv;
@ -393,14 +397,14 @@ int LoadPAD1plugin(const string& filename) {
return 0;
}
void *PAD2plugin;
static void *PAD2plugin;
void CALLBACK PAD2_configure() {}
void CALLBACK PAD2_about() {}
s32 CALLBACK PAD2_test() { return 0; }
s32 CALLBACK PAD2_freeze(int mode, freezeData *data) { if (mode == FREEZE_SIZE) data->size = 0; return 0; }
s32 CALLBACK PAD2_setSlot(u8 port, u8 slot) { return slot == 1; }
s32 CALLBACK PAD2_queryMtap(u8 port) { return 0; }
static void CALLBACK PAD2_configure() {}
static void CALLBACK PAD2_about() {}
static s32 CALLBACK PAD2_test() { return 0; }
static s32 CALLBACK PAD2_freeze(int mode, freezeData *data) { if (mode == FREEZE_SIZE) data->size = 0; return 0; }
static s32 CALLBACK PAD2_setSlot(u8 port, u8 slot) { return slot == 1; }
static s32 CALLBACK PAD2_queryMtap(u8 port) { return 0; }
int LoadPAD2plugin(const string& filename) {
void *drv;
@ -430,12 +434,12 @@ int LoadPAD2plugin(const string& filename) {
return 0;
}
void *SPU2plugin;
static void *SPU2plugin;
s32 CALLBACK SPU2_freeze(int mode, freezeData *data) { data->size = 0; return 0; }
void CALLBACK SPU2_configure() {}
void CALLBACK SPU2_about() {}
s32 CALLBACK SPU2_test() { return 0; }
static s32 CALLBACK SPU2_freeze(int mode, freezeData *data) { data->size = 0; return 0; }
static void CALLBACK SPU2_configure() {}
static void CALLBACK SPU2_about() {}
static s32 CALLBACK SPU2_test() { return 0; }
int LoadSPU2plugin(const string& filename) {
void *drv;
@ -474,37 +478,35 @@ int LoadSPU2plugin(const string& filename) {
return 0;
}
void *CDVDplugin;
static void *CDVDplugin;
void CALLBACK CDVD_configure() {}
void CALLBACK CDVD_about() {}
s32 CALLBACK CDVD_test() { return 0; }
void CALLBACK CDVD_newDiskCB(void (*callback)()) {}
static void CALLBACK CDVD_configure() {}
static void CALLBACK CDVD_about() {}
static s32 CALLBACK CDVD_test() { return 0; }
static void CALLBACK CDVD_newDiskCB(void (*callback)()) {}
extern int lastReadSize;
s32 CALLBACK CDVD_getBuffer2(u8* buffer)
static s32 CALLBACK CDVD_getBuffer2(u8* buffer)
{
int ret;
// TEMP: until I fix all the plugins to use this function style
u8* pb = CDVD.getBuffer();
if(pb!=NULL)
u8* pb = CDVD->getBuffer();
if(pb != NULL)
{
memcpy(buffer,pb,lastReadSize);
ret=0;
ret = 0;
}
else ret= -1;
else ret = -2;
return ret;
}
s32 CALLBACK CDVD_readSector(u8* buffer, u32 lsn, int mode)
static s32 CALLBACK CDVD_readSector(u8* buffer, u32 lsn, int mode)
{
if(CDVD.readTrack(lsn,mode)<0)
if(CDVD->readTrack(lsn,mode) < 0)
return -1;
// TEMP: until all the plugins use the new CDVDgetBuffer style
switch (mode)
{
@ -521,16 +523,17 @@ s32 CALLBACK CDVD_readSector(u8* buffer, u32 lsn, int mode)
lastReadSize = 2048;
break;
}
return CDVD.getBuffer2(buffer);
return CDVD->getBuffer2(buffer);
}
s32 CALLBACK CDVD_getDualInfo(s32* dualType, u32* layer1Start)
static s32 CALLBACK CDVD_getDualInfo(s32* dualType, u32* layer1Start)
{
u8 toc[2064];
// if error getting toc, settle for single layer disc ;)
if(CDVD.getTOC(toc))
if(CDVD->getTOC(toc))
return 0;
if(toc[14] & 0x60)
{
if(toc[14] & 0x10)
@ -556,7 +559,22 @@ s32 CALLBACK CDVD_getDualInfo(s32* dualType, u32* layer1Start)
return 1;
}
int cdvdInitCount;
static void CALLBACK CDVDplugin_Close()
{
if( CDVDclose != NULL )
CDVDclose();
}
CDVD_API CDVDapi_Plugin =
{
CDVDplugin_Close,
// The rest are filled in by the plugin manager below when the plugin is loaded.
NULL
};
CDVD_API* CDVD = NULL;
int LoadCDVDplugin(const string& filename) {
void *drv;
@ -564,32 +582,29 @@ int LoadCDVDplugin(const string& filename) {
if (CDVDplugin == NULL) { Msgbox::Alert("Could Not Load CDVD Plugin '%hs': %s", params &filename, SysLibError()); return -1; }
drv = CDVDplugin;
if (!TestPS2Esyms(drv, PluginTypes::CDVD, filename)) return -1;
MapSymbol2_Error(CDVD,init);
MapSymbol2_Error(CDVD,shutdown);
MapSymbol2_Error(CDVD,open);
MapSymbol2_Error(CDVD,close);
MapSymbol2_Error(CDVD,readTrack);
MapSymbol2_Error(CDVD,getBuffer);
MapSymbol2_Error(CDVD,readSubQ);
MapSymbol2_Error(CDVD,getTN);
MapSymbol2_Error(CDVD,getTD);
MapSymbol2_Error(CDVD,getTOC);
MapSymbol2_Error(CDVD,getDiskType);
MapSymbol2_Error(CDVD,getTrayStatus);
MapSymbol2_Error(CDVD,ctrlTrayOpen);
MapSymbol2_Error(CDVD,ctrlTrayClose);
MapSymbol_Error(CDVDinit);
MapSymbol_Error(CDVDshutdown);
MapSymbolCDVD_Error(open);
MapSymbolCDVD_Error(close);
MapSymbolCDVD_Error(readTrack);
MapSymbolCDVD_Error(getBuffer);
MapSymbolCDVD_Error(readSubQ);
MapSymbolCDVD_Error(getTN);
MapSymbolCDVD_Error(getTD);
MapSymbolCDVD_Error(getTOC);
MapSymbolCDVD_Error(getDiskType);
MapSymbolCDVD_Error(getTrayStatus);
MapSymbolCDVD_Error(ctrlTrayOpen);
MapSymbolCDVD_Error(ctrlTrayClose);
MapSymbol2_Fallback(CDVD,configure,CDVD_configure);
MapSymbol2_Fallback(CDVD,about,CDVD_about);
MapSymbol2_Fallback(CDVD,test,CDVD_test);
MapSymbol2_Fallback(CDVD,newDiskCB,CDVD_newDiskCB);
MapSymbol_Fallback(CDVDconfigure,CDVD_configure);
MapSymbol_Fallback(CDVDabout,CDVD_about);
MapSymbol_Fallback(CDVDtest,CDVD_test);
MapSymbolCDVD_Fallback(newDiskCB,CDVD_newDiskCB);
MapSymbol2_Fallback(CDVD,readSector,CDVD_readSector);
MapSymbol2_Fallback(CDVD,getBuffer2,CDVD_getBuffer2);
MapSymbol2_Fallback(CDVD,getDualInfo,CDVD_getDualInfo);
CDVD.initCount = &cdvdInitCount;
cdvdInitCount=0;
MapSymbolCDVD_Fallback(readSector,CDVD_readSector);
MapSymbolCDVD_Fallback(getBuffer2,CDVD_getBuffer2);
MapSymbolCDVD_Fallback(getDualInfo,CDVD_getDualInfo);
return 0;
}
@ -715,7 +730,6 @@ static PluginOpenStatusFlags OpenStatus = {0};
static bool plugins_loaded = false;
static bool plugins_initialized = false;
static bool only_loading_elf = false;
int LoadPlugins()
{
@ -769,13 +783,12 @@ int InitPlugins()
if (ReportError(PAD2init(2), "PAD2init")) return -1;
if (ReportError(SPU2init(), "SPU2init")) return -1;
if (ReportError(DoCDVDinit(), "CDVDinit")) return -1;
if (ReportError(CDVDinit(), "CDVDinit")) return -1;
if (ReportError(DEV9init(), "DEV9init")) return -1;
if (ReportError(USBinit(), "USBinit")) return -1;
if (ReportError(FWinit(), "FWinit")) return -1;
only_loading_elf = false;
plugins_initialized = true;
return 0;
}
@ -794,13 +807,8 @@ void ShutdownPlugins()
if (SPU2shutdown != NULL) SPU2shutdown();
//if (CDVDshutdown != NULL) CDVDshutdown();
DoCDVDshutdown();
if (CDVDshutdown != NULL) CDVDshutdown();
// safety measures, in case ISO is currently loaded.
if(cdvdInitCount>0)
CDVD_plugin.shutdown();
if (DEV9shutdown != NULL) DEV9shutdown();
if (USBshutdown != NULL) USBshutdown();
if (FWshutdown != NULL) FWshutdown();
@ -839,25 +847,20 @@ bool OpenGS()
bool OpenCDVD(const char* pTitleFilename)
{
// if this assertion fails it means you didn't call CDVDsys_ChangeSource. You should.
// You really should. Really.
jASSUME( CDVD != NULL );
// Don't repetitively open the CDVD plugin if directly loading an elf file and open failed once already.
if (!OpenStatus.CDVD && !only_loading_elf)
if (!OpenStatus.CDVD)
{
//First, we need the data.
CDVD.newDiskCB(cdvdNewDiskCB);
CDVD->newDiskCB( cdvdNewDiskCB );
if (DoCDVDopen(pTitleFilename) != 0)
{
if (g_Startup.BootMode != BootMode_Elf)
{
Msgbox::Alert("Error Opening CDVD Plugin");
ClosePlugins(true);
return false;
}
else
{
Console::Notice("Running ELF File Without CDVD Plugin Support!");
only_loading_elf = true;
}
Msgbox::Alert("Error Opening CDVD Plugin");
ClosePlugins(true);
return false;
}
OpenStatus.CDVD = true;
}
@ -961,22 +964,19 @@ bool OpenFW()
return true;
}
int OpenPlugins(const char* pTitleFilename)
// Note: If the CDVD has not already been manually opened, then it will be opened here
// using NULL as the source file (defaults to whatever's been previously configured into
// the CDVD plugin, which is typically a drive letter)
int OpenPlugins()
{
if (!plugins_initialized)
{
// prevent a crash
if(CDVD.init == NULL)
CDVD = ISO; // CDVD_plugin;
if( InitPlugins() == -1 ) return -1;
if( InitPlugins() == -1 ) return -1;
}
if ((!OpenCDVD(pTitleFilename)) || (!OpenGS()) || (!OpenPAD1()) || (!OpenPAD2()) ||
(!OpenSPU2()) || (!OpenDEV9()) || (!OpenUSB()) || (!OpenFW()))
if( !OpenGS() || !OpenPAD1() || !OpenPAD2() || !OpenCDVD(NULL) ||
!OpenSPU2() || !OpenDEV9() || !OpenUSB() || !OpenFW()
)
return -1;
if (!only_loading_elf) cdvdDetectDisk();
cdvdDetectDisk();
return 0;
}
@ -1018,10 +1018,12 @@ void ClosePlugins( bool closegs )
}
}
CloseCDVD();
if( OpenStatus.CDVD )
{
DoCDVDclose();
OpenStatus.CDVD=false;
OpenStatus.CDVD = false;
}
CLOSE_PLUGIN( DEV9 );
@ -1045,24 +1047,31 @@ void CloseGS()
}
}
void CloseCDVD()
{
if( OpenStatus.CDVD )
{
DoCDVDclose();
OpenStatus.CDVD = false;
}
}
#define SafeSysCloseLib( lib ) ((void)(SysCloseLibrary(GSplugin), GSplugin = NULL))
void ReleasePlugins()
{
if (!plugins_loaded) return;
if ((GSplugin == NULL) || (PAD1plugin == NULL) || (PAD2plugin == NULL) ||
(SPU2plugin == NULL) || (CDVDplugin == NULL) || (DEV9plugin == NULL) ||
(USBplugin == NULL) || (FWplugin == NULL)) return;
ShutdownPlugins();
SysCloseLibrary(GSplugin); GSplugin = NULL;
SysCloseLibrary(PAD1plugin); PAD1plugin = NULL;
SysCloseLibrary(PAD2plugin); PAD2plugin = NULL;
SysCloseLibrary(SPU2plugin); SPU2plugin = NULL;
SysCloseLibrary(CDVDplugin); CDVDplugin = NULL;
SysCloseLibrary(DEV9plugin); DEV9plugin = NULL;
SysCloseLibrary(USBplugin); USBplugin = NULL;
SysCloseLibrary(FWplugin); FWplugin = NULL;
SafeSysCloseLib(GSplugin);
SafeSysCloseLib(PAD1plugin);
SafeSysCloseLib(PAD2plugin);
SafeSysCloseLib(SPU2plugin);
SafeSysCloseLib(CDVDplugin);
SafeSysCloseLib(DEV9plugin);
SafeSysCloseLib(USBplugin);
SafeSysCloseLib(FWplugin);
plugins_loaded = false;
}

View File

@ -24,19 +24,22 @@
#include "PS2Edefs.h"
// Loads plugins as specified in the Config global.
int LoadPlugins();
extern int LoadPlugins();
// Unloads all plugin DLLs. To change plugins, call ReleasePlugins followed by
// changes to Config.Plugins filenames, and then call LoadPlugins.
void ReleasePlugins();
extern void ReleasePlugins();
int OpenPlugins(const char* pTitleFilename);
void ClosePlugins( bool closegs );
void CloseGS();
extern int OpenPlugins();
extern bool OpenCDVD(const char* pTitleFilename);
int InitPlugins();
void ShutdownPlugins();
extern void ClosePlugins( bool closegs );
extern void CloseGS();
extern void CloseCDVD();
void PluginsResetGS();
extern int InitPlugins();
extern void ShutdownPlugins();
extern void PluginsResetGS();
#endif /* __PLUGINS_H__ */

View File

@ -81,7 +81,7 @@ namespace StateRecovery {
void Recover()
{
// Just in case they weren't initialized earlier (no harm in calling this multiple times)
if( OpenPlugins(NULL) == -1 ) return;
if( OpenPlugins() == -1 ) return;
if( g_RecoveryState != NULL )
{

View File

@ -48,7 +48,7 @@ static void _loadStateOrExcept( const string& file )
// Make sure the cpu and plugins are ready to be state-ified!
cpuReset();
OpenPlugins( NULL );
OpenPlugins();
joe.FreezeAll();

View File

@ -390,10 +390,6 @@ void SysEndExecution()
// use_bios - forces the game to boot through the PS2 bios, instead of bypassing it.
void SysPrepareExecution( const char* elf_file, bool use_bios )
{
// solve a little crash
if(CDVD.init == NULL)
CDVD = CDVD_plugin;
if( !g_EmulationInProgress )
{
try
@ -406,11 +402,8 @@ void SysPrepareExecution( const char* elf_file, bool use_bios )
return;
}
g_Startup.BootMode = (elf_file) ? BootMode_Elf : BootMode_Normal;
if (OpenPlugins(NULL) == -1) {
return;
}
if (OpenPlugins() == -1)
return;
if( elf_file == NULL )
{

View File

@ -367,7 +367,7 @@ void EnterRunningState(HWND hDlg)
EnableWindow(GetDlgItem(hDlg, IDC_DEBUG_STEP_EE), FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_DEBUG_STEP), FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_DEBUG_SKIP), FALSE);
OpenPlugins(NULL);
OpenPlugins();
}
static

View File

@ -41,6 +41,8 @@
#include "CDVD/CDVDisoReader.h"
#include "CDVD/CDVD.h"
#include "svnrev.h"
unsigned int langsMax;
static bool m_RestartGui = false; // used to signal a GUI restart after DestroyWindow()
static HBITMAP hbitmap_background = NULL;
@ -64,23 +66,26 @@ BOOL APIENTRY CmdlineProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
//-------------------
static const char* phelpmsg =
"pcsx2 [options] [cdimage/elf file]\n\n"
"\t-cfg [file] {configuration file}\n"
"\t-bootmode [mode] {0 - quick (default), 1 - bios, 2 - load elf}\n"
"\t-nogui {disables display of the gui - skips right to opening the GS window}"
"\t-help {display this help file}\n"
"\t-loadgs [file] {Loads a gsstate}\n\n"
"Run without GUI Options:\n"
"\n"
"Command line : pcsx2 [options] [cdimage]\n\n"
"\t-cfg [file] {specify a custom configuration file}\n"
"\t-help {display this help file}\n\n"
"Auto-Run Options :\n\n"
"\t-nogui {disables display of the gui on exit (program auto-exits)}\n"
"\t-skipbios {emulator will skip standard BIOS splash screens; does not apply to ELF}\n"
"\t-elf [file] {executes an ELF image}\n"
"\t-nodisc {use this to boot into the PS2 system menu}\n"
"\t-usecdvd {auto-boots from the configured CDVD plugin (ignores cdimage parameter)}\n"
"Plugin Overrides (specified dlls will be used in place of configured dlls):\n"
"\t-cdvd [dllpath] {specifies an override for the CDVD plugin}\n"
"\t-gs [dllpath] {specifies an override for the GS plugin}\n"
"\t-spu [dllpath] {specifies an override for the SPU2 plugin}\n"
"\t-pad [dllpath] {specifies an override for *both* pad plugins}\n"
"\t-pad1 [dllpath] {specifies an override for the PAD1 plugin only}\n"
"\t-pad2 [dllpath] {specifies an override for the PAD2 plugin only}\n"
"\t-dev9 [dllpath] {specifies an override for the DEV9 plugin}\n"
"\n\n"
"Plugin Overrides (specified dlls will be used in place of configured dlls):\n\n"
"\t-cdvd [dllpath] {override for the CDVD plugin}\n"
"\t-gs [dllpath] {override for the GS plugin}\n"
"\t-spu [dllpath] {override for the SPU2 plugin}\n"
"\t-pad [dllpath] {override for *both* pad plugins}\n"
"\t-pad1 [dllpath] {override for the PAD1 plugin only}\n"
"\t-pad2 [dllpath] {override for the PAD2 plugin only}\n"
"\t-dev9 [dllpath] {override for the DEV9 plugin}\n"
"\n";
/// This code is courtesy of http://alter.org.ua/en/docs/win/args/
@ -369,33 +374,22 @@ void RunGui()
LoadPatch( str_Default );
if( g_Startup.NoGui || g_Startup.Enabled )
if( g_Startup.Enabled )
{
// Initially bypass GUI and start PCSX2 directly.
// Manually load plugins using the user's configured image (if non-elf).
int mode = g_Startup.BootMode & BootMode_ModeMask;
if( g_Startup.Enabled && (mode != BootMode_Elf) )
{
CDVDsys_ChangeSource( g_Startup.CdvdSource );
DoCDVDopen( g_Startup.ImageName );
if(mode == BootMode_Iso)
CDVD=ISO;
else if(mode == BootMode_NoDisc)
CDVD=NODISC;
else
CDVD=CDVD_plugin;
if (OpenPlugins() == -1)
return;
if (OpenPlugins(g_Startup.ImageName) == -1)
return;
}
SysPrepareExecution(
(g_Startup.BootMode == BootMode_Elf) ? g_Startup.ImageName : NULL,
((g_Startup.BootMode & BootMode_Bios) != 0)
);
SysPrepareExecution( (g_Startup.StartupMode == Startup_FromELF) ? g_Startup.ImageName : NULL, !g_Startup.SkipBios );
}
// Just exit immediately if the user disabled the GUI
if( g_Startup.NoGui ) return;
do
{
CreateMainWindow();
@ -672,12 +666,38 @@ LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
// WM_DESTROY will do the shutdown work for us.
break;
case ID_FILEOPEN:
case ID_FILE_RUNELF_NODISC:
{
string outstr;
if( Open_File_Proc( outstr ) )
{
SysReset();
CDVDsys_ChangeSource( CDVDsrc_NoDisc );
SysPrepareExecution( outstr.c_str() );
}
}
break;
case ID_FILE_RUNELF_ISO:
{
string outstr, isostr;
if( Open_File_Proc( outstr ) && Open_Iso_File_Proc( isostr ) )
{
SysReset();
CDVDsys_ChangeSource( CDVDsrc_Iso );
OpenCDVD( isostr.c_str() );
SysPrepareExecution( outstr.c_str() );
}
}
break;
case ID_FILE_RUNELF_CD:
{
string outstr;
if( Open_File_Proc( outstr ) )
{
SysReset();
CDVDsys_ChangeSource( CDVDsrc_Plugin );
SysPrepareExecution( outstr.c_str() );
}
}
@ -688,23 +708,19 @@ LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
string outstr;
if( Open_Iso_File_Proc( outstr ) )
{
strcpy(isoFileName,outstr.c_str());
//SysReset();
// SysReset shuts down plugins so it's best in here
CDVD = ISO;
SysReset();
CDVDsys_ChangeSource( CDVDsrc_Iso );
OpenCDVD( outstr.c_str() );
SysPrepareExecution( NULL );
}
}
break;
case ID_FILE_RUNBIOS:
//SysReset();
// SysReset shuts down plugins so it's best in here
CDVD = NODISC;
SysPrepareExecution( NULL, true );
break;
SysReset();
CDVDsys_ChangeSource( CDVDsrc_NoDisc );
SysPrepareExecution( NULL, true );
break;
case ID_RUN_EXECUTE:
// Execute without reset -- resumes existing states or runs the BIOS if
@ -713,14 +729,11 @@ LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
break;
case ID_FILE_RUNCD:
//SysReset();
// SysReset shuts down plugins so it's best in here
CDVD = CDVD_plugin;
SysReset();
CDVDsys_ChangeSource( CDVDsrc_Plugin );
SysPrepareExecution( NULL );
break;
case ID_RUN_RESET:
SysReset();
break;
@ -759,7 +772,7 @@ LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
break;
case ID_CONFIG_CDVDROM:
if (CDVD_plugin.configure) CDVD_plugin.configure();
if( CDVDconfigure != NULL ) CDVDconfigure();
break;
case ID_CONFIG_DEV9:
@ -1011,7 +1024,12 @@ void CreateMainMenu() {
ADDSEPARATOR(0);
ADDSUBMENUS(0, 1, _("&States"));
ADDSEPARATOR(0);
ADDMENUITEM(0, _("&Open ELF File..."), ID_FILEOPEN);
ADDSUBMENUS(0, 4, _("Run &ELF File...") );
ADDMENUITEM(4, _("ISO Image..."), ID_FILE_RUNELF_ISO);
ADDMENUITEM(4, _("CDVD Plugin"), ID_FILE_RUNELF_CD);
ADDMENUITEM(4, _("No Disc"), ID_FILE_RUNELF_NODISC);
ADDMENUITEM(0, _("Run &BIOS (No Disc)"), ID_FILE_RUNBIOS);
ADDMENUITEM(0, _("Run &ISO Image..."), ID_FILE_RUNISO);
ADDMENUITEM(0, _("&Run CD/DVD"), ID_FILE_RUNCD);
@ -1106,11 +1124,13 @@ void CreateMainWindow()
int w, h;
#ifdef _MSC_VER
sprintf(COMPILER, "(VC%d)", (_MSC_VER+100)/200);//hacky:) works for VC6 & VC.NET
#elif __BORLANDC__
sprintf(COMPILER, "(BC)");
// 1200 is VC 6.0, and all subsequent compilers are +100, ie:
// 1300 - VC 2003
// 1400 - VC 2005 ... etc!
sprintf( COMPILER, "%s (VC%d)", COMPILEDATE, (_MSC_VER/100)-6 );
#endif
/* Load Background Bitmap from the ressource */
/* Load Background Bitmap from the resource */
if( hbitmap_background == NULL )
hbitmap_background = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(SPLASH_LOGO));
@ -1128,11 +1148,11 @@ void CreateMainWindow()
RegisterClass(&wc);
GetObject(hbitmap_background, sizeof(bm), &bm);
#ifdef PCSX2_DEVBUILD
sprintf(buf, _("PCSX2 %s - Compile Date - %s %s"), PCSX2_VERSION, COMPILEDATE, COMPILER);
#else
sprintf(buf, _("PCSX2 %s"), PCSX2_VERSION);
#endif
// use this for beta/svn builds.
sprintf(buf, "PCSX2 %s.r%d - %s", PCSX2_VERSION, SVN_REV, COMPILER);
// use this for official releases (ie, public release branches/tags only)
//sprintf(buf, "PCSX2 %s", PCSX2_VERSION);
hWnd = CreateWindow(
"PCSX2 Main",

View File

@ -23,6 +23,7 @@
#include "VUmicro.h"
#include "iR5900.h"
#include "cdvd/CDVD.h"
static bool sinit = false;
bool nDisableSC = false; // screensaver
@ -66,7 +67,16 @@ int SysPageFaultExceptionFilter( EXCEPTION_POINTERS* eps )
int ParseCommandLine( int tokenCount, TCHAR *const *const tokens )
{
int tidx = 0;
g_Startup.BootMode = BootMode_Normal;
g_Startup.Enabled = false;
g_Startup.NoGui = false;
g_Startup.ImageName = NULL;
g_Startup.ElfFile = NULL;
g_Startup.StartupMode = Startup_FromCDVD;
g_Startup.SkipBios = true;
g_Startup.CdvdSource = CDVDsrc_Plugin;
bool _legacy_ForceElfLoad = false;
while( tidx < tokenCount )
{
@ -76,6 +86,15 @@ int ParseCommandLine( int tokenCount, TCHAR *const *const tokens )
{
g_Startup.ImageName = command;
g_Startup.Enabled = true;
g_Startup.CdvdSource = CDVDsrc_Iso;
if( _legacy_ForceElfLoad )
{
// This retains compatibility with the older Bootmode command.
g_Startup.ElfFile = command;
g_Startup.StartupMode = Startup_FromELF;
g_Startup.CdvdSource = CDVDsrc_Plugin;
}
continue;
}
@ -85,10 +104,22 @@ int ParseCommandLine( int tokenCount, TCHAR *const *const tokens )
if( CmdSwitchIs( "help" ) )
{
return -1;
return 1;
}
else if( CmdSwitchIs( "nogui" ) ) {
g_Startup.NoGui = true;
g_Startup.Enabled = true;
}
else if( CmdSwitchIs( "skipbios" ) ) {
g_Startup.SkipBios = true;
}
else if( CmdSwitchIs( "nodisc" ) ) {
g_Startup.CdvdSource = CDVDsrc_NoDisc;
g_Startup.Enabled = true;
}
else if( CmdSwitchIs( "usecd" ) ) {
g_Startup.CdvdSource = CDVDsrc_Plugin;
g_Startup.Enabled = true;
}
else if( CmdSwitchIs( "highpriority" ) ) {
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
@ -106,13 +137,41 @@ int ParseCommandLine( int tokenCount, TCHAR *const *const tokens )
if( CmdSwitchIs( "cfg" ) ) {
g_CustomConfigFile = param;
}
else if( CmdSwitchIs( "bootmode" ) ) {
g_Startup.BootMode = (StartupMode)atoi( param );
g_Startup.Enabled = true;
else if( CmdSwitchIs( "elf" ) ) {
g_Startup.StartupMode = Startup_FromELF;
g_Startup.ElfFile = param;
}
else if( CmdSwitchIs( "loadgs" ) ) {
g_pRunGSState = param;
}
// legacy support for the old bootmode option >_<
else if( CmdSwitchIs( "bootmode" ) )
{
int mode = atoi( param );
g_Startup.Enabled = true;
g_Startup.SkipBios = !( mode & 0x10000 );
switch( mode & 0xf )
{
case 0:
g_Startup.CdvdSource = CDVDsrc_Plugin;
break;
case 1:
_legacy_ForceElfLoad = true;
break;
case 2:
g_Startup.CdvdSource = CDVDsrc_Iso;
break;
case 3:
g_Startup.CdvdSource = CDVDsrc_NoDisc;
break;
}
}
// Options to configure plugins:

View File

@ -413,6 +413,9 @@
#define ID_FILE_RUNISO 40105
#define ID_BLOCKDUMP 40106
#define ID_FILE_RUNBIOS 40107
#define ID_FILE_RUNELF_NODISC 40108
#define ID_FILE_RUNELF_ISO 40109
#define ID_FILE_RUNELF_CD 40110
#define ID_LANGS 50000
// Next default values for new objects