* Should fix iso hot-swapping.

* Fixed a startup crash by moving the game database initialization to cpuReset().  This is a temporary measure until we sort out a better system for it.  This is needed because initializing complex classes in C++ as globals is VERY dangerous and unpredictable.  The databse was being loaded before any wxWidgets/UI objects were being created themselves, so any errors, exceptions, or console logs generated by the database were likely to cause unpredictable behavior.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2989 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
Jake.Stine 2010-05-12 18:27:01 +00:00
parent 30cf31b7bc
commit 069d1d59b8
9 changed files with 54 additions and 20 deletions

View File

@ -29,7 +29,8 @@
#include "ps2/BiosTools.h"
#include "DataBase_Loader.h"
DataBase_Loader GameDB("DataBase.dbf", "Serial");
ScopedPtr<DataBase_Loader> GameDB;
wxString DiscID;
static cdvdStruct cdvd;
@ -348,8 +349,11 @@ static __forceinline void _reloadElfInfo(wxString elfpath)
elfptr.Delete();
// Set the Game DataBase to the correct game based on Game Serial Code...
GameDB.setGame(DiscID.ToUTF8().data());
Console.WriteLn("Game = %s (%s)", GameDB.getString("Name").c_str(), GameDB.getString("Region").c_str());
if( GameDB )
{
GameDB->setGame(DiscID.ToUTF8().data());
Console.WriteLn("Game = %s (%s)", GameDB->getString("Name").c_str(), GameDB->getString("Region").c_str());
}
}
void cdvdReloadElfInfo()
@ -536,6 +540,8 @@ void cdvdReset()
cdvd.RTC.day = (u8)curtime.GetDay(wxDateTime::GMT9);
cdvd.RTC.month = (u8)curtime.GetMonth(wxDateTime::GMT9) + 1; // WX returns Jan as "0"
cdvd.RTC.year = (u8)(curtime.GetYear(wxDateTime::GMT9) - 2000);
GameDB = new DataBase_Loader("DataBase.dbf", "Serial");
}
struct Freeze_v10Compat

View File

@ -143,6 +143,6 @@ extern void cdvdNewDiskCB();
extern u8 cdvdRead(u8 key);
extern void cdvdWrite(u8 key, u8 rt);
void cdvdReloadElfInfo();
extern void cdvdReloadElfInfo();
extern wxString DiscID;

View File

@ -281,6 +281,11 @@ void CDVDsys_SetFile( CDVD_SourceType srctype, const wxString& newfile )
m_SourceFilename[srctype] = newfile;
}
const wxString& CDVDsys_GetFile( CDVD_SourceType srctype )
{
return m_SourceFilename[srctype];
}
CDVD_SourceType CDVDsys_GetSourceType()
{
return m_CurrentSourceType;

View File

@ -69,6 +69,7 @@ extern const wxChar* CDVD_SourceLabels[];
extern void CDVDsys_ChangeSource( CDVD_SourceType type );
extern void CDVDsys_SetFile( CDVD_SourceType srctype, const wxString& newfile );
extern const wxString& CDVDsys_GetFile( CDVD_SourceType srctype );
extern CDVD_SourceType CDVDsys_GetSourceType();
extern bool DoCDVDopen();

View File

@ -202,4 +202,4 @@ public:
}
};
extern DataBase_Loader GameDB;
extern ScopedPtr<DataBase_Loader> GameDB;

View File

@ -578,8 +578,12 @@ void __fastcall eeGameStarting()
{
if (!g_GameStarted && ElfCRC) {
wxString gameCRC( wxsFormat( L"%8.8x", ElfCRC ) );
wxString gameName = GameDB.getStringWX("Name");
gameName += L" (" + GameDB.getStringWX("Region") + L")";
wxString gameName;
if( GameDB )
{
gameName = GameDB->getStringWX("Name");
gameName += L" (" + GameDB->getStringWX("Region") + L")";
}
gameName += L" [" + DiscID + L"]";
gameName += L" [" + gameCRC + L"]";

View File

@ -70,6 +70,7 @@ static void PostCoreStatus( CoreThreadStatus pevt )
// --------------------------------------------------------------------------------------
AppCoreThread::AppCoreThread() : SysCoreThread()
{
m_resetCdvd = false;
}
AppCoreThread::~AppCoreThread() throw()
@ -146,6 +147,13 @@ void AppCoreThread::ChangeCdvdSource()
void AppCoreThread::OnResumeReady()
{
ApplySettings( g_Conf->EmuOptions );
CDVD_SourceType cdvdsrc( g_Conf->CdvdSource );
if( cdvdsrc != CDVDsys_GetSourceType() || (cdvdsrc==CDVDsrc_Iso && (CDVDsys_GetFile(cdvdsrc) != g_Conf->CurrentIso)) )
{
m_resetCdvd = true;
}
CDVDsys_SetFile( CDVDsrc_Iso, g_Conf->CurrentIso );
AppSaveSettings();
@ -195,6 +203,13 @@ void AppCoreThread::DoCpuReset()
void AppCoreThread::OnResumeInThread( bool isSuspended )
{
if( m_resetCdvd )
{
GetCorePlugins().Close( PluginId_CDVD );
CDVDsys_ChangeSource( g_Conf->CdvdSource );
m_resetCdvd = false;
}
_parent::OnResumeInThread( isSuspended );
PostCoreStatus( CoreThread_Resumed );
}

View File

@ -120,6 +120,9 @@ class AppCoreThread : public SysCoreThread
{
typedef SysCoreThread _parent;
protected:
volatile bool m_resetCdvd;
public:
AppCoreThread();
virtual ~AppCoreThread() throw();

View File

@ -140,18 +140,18 @@ wxWindowID SwapOrReset_Iso( wxWindow* owner, IScopedCoreThread& core_control, co
}
SysUpdateIsoSrcFile( isoFilename );
if( result != wxID_RESET )
{
Console.Indent().WriteLn( "HotSwapping to new ISO src image!" );
g_Conf->CdvdSource = CDVDsrc_Iso;
CoreThread.ChangeCdvdSource();
core_control.AllowResume();
}
else
if( result == wxID_RESET )
{
core_control.DisallowResume();
sApp.SysExecute( CDVDsrc_Iso );
}
else
{
Console.Indent().WriteLn( "HotSwapping to new ISO src image!" );
g_Conf->CdvdSource = CDVDsrc_Iso;
//CoreThread.ChangeCdvdSource();
core_control.AllowResume();
}
return result;
}
@ -190,7 +190,7 @@ wxWindowID SwapOrReset_CdvdSrc( wxWindow* owner, CDVD_SourceType newsrc )
if( result != wxID_RESET )
{
Console.Indent().WriteLn( L"(CdvdSource) HotSwapping CDVD source types from %s to %s.", CDVD_SourceLabels[oldsrc], CDVD_SourceLabels[newsrc] );
CoreThread.ChangeCdvdSource();
//CoreThread.ChangeCdvdSource();
sMainFrame.UpdateIsoSrcSelection();
core.AllowResume();
}