/[pcsx2_0.9.7]/trunk/pcsx2/System.cpp
ViewVC logotype

Diff of /trunk/pcsx2/System.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/pcsx2/System.cpp	2010/09/07 03:24:11	31
+++ trunk/pcsx2/System.cpp	2010/09/07 11:08:22	62
@@ -15,7 +15,7 @@
 
 #include "PrecompiledHeader.h"
 #include "Common.h"
-#include "HostGui.h"
+#include "IopCommon.h"
 
 #include "System/PageFaultSource.h"
 #include "Utilities/EventSource.inl"
@@ -23,7 +23,8 @@
 // Includes needed for cleanup, since we don't have a good system (yet) for
 // cleaning up these things.
 #include "sVU_zerorec.h"
-#include "DataBase_Loader.h"
+#include "GameDatabase.h"
+#include "Elfheader.h"
 
 extern void closeNewVif(int idx);
 extern void resetNewVif(int idx);
@@ -89,13 +90,6 @@
 	return const_cast<Pcsx2Config::GamefixOptions&>(EmuConfig.Gamefixes);
 }
 
-ConsoleLogFilters& SetConsoleConfig()
-{
-	//DbgCon.WriteLn( "Direct modification of EmuConfig.Log detected" );
-	AffinityAssert_AllowFrom_MainUI();
-	return const_cast<ConsoleLogFilters&>(EmuConfig.Log);
-}
-
 TraceLogFilters& SetTraceConfig()
 {
 	//DbgCon.WriteLn( "Direct modification of EmuConfig.TraceLog detected" );
@@ -107,7 +101,7 @@
 // This function should be called once during program execution.
 void SysLogMachineCaps()
 {
-	Console.WriteLn( Color_StrongGreen, "PCSX2 %d.%d.%d.r%d %s - compiled on " __DATE__, PCSX2_VersionHi, PCSX2_VersionMid, PCSX2_VersionLo,
+	Console.WriteLn( Color_StrongGreen, "PCSX2 %u.%u.%u.r%d %s - compiled on " __DATE__, PCSX2_VersionHi, PCSX2_VersionMid, PCSX2_VersionLo,
 		SVN_REV, SVN_MODS ? "(modded)" : ""
 	);
 
@@ -116,6 +110,8 @@
 
 	Console.WriteLn( Color_StrongBlack, "x86-32 Init:" );
 
+	u32 speed = x86caps.CalculateMHz();
+
 	Console.Indent().WriteLn(
 		L"CPU vendor name  =  %s\n"
 		L"FamilyID         =  %x\n"
@@ -127,9 +123,9 @@
 		L"x86EFlags        =  %8.8x",
 			fromUTF8( x86caps.VendorName ).c_str(), x86caps.StepID,
 			fromUTF8( x86caps.FamilyName ).Trim().Trim(false).c_str(),
-			x86caps.Speed / 1000, x86caps.Speed % 1000,
+			speed / 1000, speed % 1000,
 			x86caps.PhysicalCores, x86caps.LogicalCores,
-			fromUTF8( x86caps.TypeName ).c_str(),
+			x86caps.GetTypeName().c_str(),
 			x86caps.Flags, x86caps.Flags2,
 			x86caps.EFlags
 	);
@@ -151,9 +147,11 @@
 	if( x86caps.has3DNOWInstructionExtensionsExt )	features[1].Add( L"3DNOW2" );
 	if( x86caps.hasStreamingSIMD4ExtensionsA )		features[1].Add( L"SSE4a " );
 
-	wxString result[2];
-	JoinString( result[0], features[0], L".. " );
-	JoinString( result[1], features[1], L".. " );
+	const wxString result[2] =
+	{
+		JoinString( features[0], L".. " ),
+		JoinString( features[1], L".. " )
+	};
 
 	Console.WriteLn( Color_StrongBlack,	L"x86 Features Detected:" );
 	Console.Indent().WriteLn( result[0] + (result[1].IsEmpty() ? L"" : (L"\n" + result[1])) );
@@ -164,8 +162,9 @@
 class CpuInitializer
 {
 public:
-	ScopedPtr<CpuType>	MyCpu;
-
+	ScopedPtr<CpuType>			MyCpu;
+	ScopedPtr<BaseException>	ExThrown;
+	
 	CpuInitializer();
 	virtual ~CpuInitializer() throw();
 
@@ -196,14 +195,14 @@
 	catch( Exception::RuntimeError& ex )
 	{
 		Console.Error( L"CPU provider error:\n\t" + ex.FormatDiagnosticMessage() );
-		if( MyCpu )
-			MyCpu = NULL;
+		MyCpu = NULL;
+		ExThrown = ex.Clone();
 	}
 	catch( std::runtime_error& ex )
 	{
 		Console.Error( L"CPU provider error (STL Exception)\n\tDetails:" + fromUTF8( ex.what() ) );
-		if( MyCpu )
-			MyCpu = NULL;
+		MyCpu = NULL;
+		ExThrown = new Exception::RuntimeError(ex);
 	}
 }
 
@@ -238,20 +237,20 @@
 // returns the translated error message for the Virtual Machine failing to allocate!
 static wxString GetMemoryErrorVM()
 {
-	return pxE( ".Popup Error:EmuCore::MemoryForVM",
+	return pxE( ".Error:EmuCore::MemoryForVM",
 		L"PCSX2 is unable to allocate memory needed for the PS2 virtual machine. "
 		L"Close out some memory hogging background tasks and try again."
 	);
 }
 
-SysCoreAllocations::SysCoreAllocations()
+// --------------------------------------------------------------------------------------
+//  SysAllocVM  (implementations)
+// --------------------------------------------------------------------------------------
+SysAllocVM::SysAllocVM()
 {
 	InstallSignalHandler();
 
-	Console.WriteLn( "Initializing PS2 virtual machine..." );
-
-	m_RecSuccessEE		= false;
-	m_RecSuccessIOP		= false;
+	Console.WriteLn( "Allocating memory for the PS2 virtual machine..." );
 
 	try
 	{
@@ -263,8 +262,7 @@
 	// ----------------------------------------------------------------------------
 	catch( Exception::OutOfMemory& ex )
 	{
-		wxString newmsg( ex.UserMsg() + L"\n\n" + GetMemoryErrorVM() );
-		ex.UserMsg() = newmsg;
+		ex.UserMsg() += L"\n\n" + GetMemoryErrorVM();
 		CleanupMess();
 		throw;
 	}
@@ -275,34 +273,57 @@
 		// re-throw std::bad_alloc as something more friendly.  This is needed since
 		// much of the code uses new/delete internally, which throw std::bad_alloc on fail.
 
-		throw Exception::OutOfMemory(
-			L"std::bad_alloc caught while trying to allocate memory for the PS2 Virtual Machine.\n"
-			L"Error Details: " + fromUTF8( ex.what() ),
+		throw Exception::OutOfMemory()
+			.SetDiagMsg(
+				L"std::bad_alloc caught while trying to allocate memory for the PS2 Virtual Machine.\n"
+				L"Error Details: " + fromUTF8( ex.what() )
+			)
+			.SetUserMsg(GetMemoryErrorVM()); 	// translated
+	}
+}
 
-			GetMemoryErrorVM()	// translated
-		);
+void SysAllocVM::CleanupMess() throw()
+{
+	try
+	{
+		vuMicroMemShutdown();
+		psxMemShutdown();
+		memShutdown();
+		vtlb_Core_Shutdown();
 	}
+	DESTRUCTOR_CATCHALL
+}
 
+SysAllocVM::~SysAllocVM() throw()
+{
+	CleanupMess();
+}
+
+// --------------------------------------------------------------------------------------
+//  SysCpuProviderPack  (implementations)
+// --------------------------------------------------------------------------------------
+SysCpuProviderPack::SysCpuProviderPack()
+{
 	Console.WriteLn( "Allocating memory for recompilers..." );
 
 	CpuProviders = new CpuInitializerSet();
 
 	try {
 		recCpu.Allocate();
-		m_RecSuccessEE = true;
 	}
 	catch( Exception::RuntimeError& ex )
 	{
+		m_RecExceptionEE = ex.Clone();
 		Console.Error( L"EE Recompiler Allocation Failed:\n" + ex.FormatDiagnosticMessage() );
 		recCpu.Shutdown();
 	}
 
 	try {
 		psxRec.Allocate();
-		m_RecSuccessIOP = true;
 	}
 	catch( Exception::RuntimeError& ex )
 	{
+		m_RecExceptionIOP = ex.Clone();
 		Console.Error( L"IOP Recompiler Allocation Failed:\n" + ex.FormatDiagnosticMessage() );
 		psxRec.Shutdown();
 	}
@@ -315,18 +336,21 @@
 		SuperVUDestroy( -1 );
 }
 
-bool SysCoreAllocations::IsRecAvailable_MicroVU0() const { return CpuProviders->microVU0.IsAvailable(); }
-bool SysCoreAllocations::IsRecAvailable_MicroVU1() const { return CpuProviders->microVU1.IsAvailable(); }
-
-bool SysCoreAllocations::IsRecAvailable_SuperVU0() const { return CpuProviders->superVU0.IsAvailable(); }
-bool SysCoreAllocations::IsRecAvailable_SuperVU1() const { return CpuProviders->superVU1.IsAvailable(); }
+bool SysCpuProviderPack::IsRecAvailable_MicroVU0() const { return CpuProviders->microVU0.IsAvailable(); }
+bool SysCpuProviderPack::IsRecAvailable_MicroVU1() const { return CpuProviders->microVU1.IsAvailable(); }
+BaseException* SysCpuProviderPack::GetException_MicroVU0() const { return CpuProviders->microVU0.ExThrown; }
+BaseException* SysCpuProviderPack::GetException_MicroVU1() const { return CpuProviders->microVU1.ExThrown; }
+
+bool SysCpuProviderPack::IsRecAvailable_SuperVU0() const { return CpuProviders->superVU0.IsAvailable(); }
+bool SysCpuProviderPack::IsRecAvailable_SuperVU1() const { return CpuProviders->superVU1.IsAvailable(); }
+BaseException* SysCpuProviderPack::GetException_SuperVU0() const { return CpuProviders->superVU0.ExThrown; }
+BaseException* SysCpuProviderPack::GetException_SuperVU1() const { return CpuProviders->superVU1.ExThrown; }
 
 
-void SysCoreAllocations::CleanupMess() throw()
+void SysCpuProviderPack::CleanupMess() throw()
 {
 	try
 	{
-		GameDB.Delete();
 		closeNewVif(0);
 		closeNewVif(1);
 
@@ -335,21 +359,16 @@
 
 		psxRec.Shutdown();
 		recCpu.Shutdown();
-
-		vuMicroMemShutdown();
-		psxMemShutdown();
-		memShutdown();
-		vtlb_Core_Shutdown();
 	}
 	DESTRUCTOR_CATCHALL
 }
 
-SysCoreAllocations::~SysCoreAllocations() throw()
+SysCpuProviderPack::~SysCpuProviderPack() throw()
 {
 	CleanupMess();
 }
 
-bool SysCoreAllocations::HadSomeFailures( const Pcsx2Config::RecompilerOptions& recOpts ) const
+bool SysCpuProviderPack::HadSomeFailures( const Pcsx2Config::RecompilerOptions& recOpts ) const
 {
 	return	(recOpts.EnableEE && !IsRecAvailable_EE()) ||
 			(recOpts.EnableIOP && !IsRecAvailable_IOP()) ||
@@ -363,7 +382,7 @@
 BaseVUmicroCPU* CpuVU0 = NULL;
 BaseVUmicroCPU* CpuVU1 = NULL;
 
-void SysCoreAllocations::SelectCpuProviders() const
+void SysCpuProviderPack::ApplyConfig() const
 {
 	Cpu		= CHECK_EEREC	? &recCpu : &intCpu;
 	psxCpu	= CHECK_IOPREC	? &psxRec : &psxInt;
@@ -378,6 +397,15 @@
 		CpuVU1 = EmuConfig.Cpu.Recompiler.UseMicroVU1 ? (BaseVUmicroCPU*)CpuProviders->microVU1 : (BaseVUmicroCPU*)CpuProviders->superVU1;
 }
 
+// This is a semi-hacky function for convenience
+BaseVUmicroCPU* SysCpuProviderPack::getVUprovider(int whichProvider, int vuIndex) const {
+	switch (whichProvider) {
+		case 0: return vuIndex ? (BaseVUmicroCPU*)CpuProviders->interpVU1 : (BaseVUmicroCPU*)CpuProviders->interpVU0;
+		case 1: return vuIndex ? (BaseVUmicroCPU*)CpuProviders->superVU1  : (BaseVUmicroCPU*)CpuProviders->superVU0;
+		case 2: return vuIndex ? (BaseVUmicroCPU*)CpuProviders->microVU1  : (BaseVUmicroCPU*)CpuProviders->microVU0;
+	}
+	return NULL;
+}
 
 // Resets all PS2 cpu execution caches, which does not affect that actual PS2 state/condition.
 // This can be called at any time outside the context of a Cpu->Execute() block without
@@ -386,7 +414,7 @@
 // Use this method to reset the recs when important global pointers like the MTGS are re-assigned.
 void SysClearExecutionCache()
 {
-	GetSysCoreAlloc().SelectCpuProviders();
+	GetCpuProviders().ApplyConfig();
 
 	// SuperVUreset will do nothing is none of the recs are initialized.
 	// But it's needed if one or the other is initialized.
@@ -394,6 +422,9 @@
 
 	Cpu->Reset();
 	psxCpu->Reset();
+	// mVU's VU0 needs to be properly initialised for macro mode even if it's not used for micro mode!
+	if (CHECK_EEREC)
+		((BaseVUmicroCPU*)GetCpuProviders().CpuProviders->microVU0)->Reset();
 	CpuVU0->Reset();
 	CpuVU1->Reset();
 
@@ -405,9 +436,9 @@
 // allocation is below a certain memory address (specified in "bounds" parameter).
 // The allocated block has code execution privileges.
 // Returns NULL on allocation failure.
-u8 *SysMmapEx(uptr base, u32 size, uptr bounds, const char *caller)
+u8* SysMmapEx(uptr base, u32 size, uptr bounds, const char *caller)
 {
-	u8 *Mem = (u8*)HostSys::Mmap( base, size );
+	u8* Mem = (u8*)HostSys::Mmap( base, size );
 
 	if( (Mem == NULL) || (bounds != 0 && (((uptr)Mem + size) > bounds)) )
 	{
@@ -433,3 +464,20 @@
 	}
 	return Mem;
 }
+
+// This function always returns a valid DiscID -- using the Sony serial when possible, and
+// falling back on the CRC checksum of the ELF binary if the PS2 software being run is
+// homebrew or some other serial-less item.
+wxString SysGetDiscID()
+{
+	if( !DiscSerial.IsEmpty() ) return DiscSerial;
+	
+	if( !ElfCRC )
+	{
+		// FIXME: If the system is currently running the BIOS, it should return a serial based on
+		// the BIOS being run (either a checksum of the BIOS roms, and/or a string based on BIOS
+		// region and revision).
+	}
+
+	return wxsFormat( L"%8.8x", ElfCRC );
+}

 

  ViewVC Help
Powered by ViewVC 1.1.22