diff --git a/common/build/Utilities/utilities.vcproj b/common/build/Utilities/utilities.vcproj index bd7c29127a..5aba44fe50 100644 --- a/common/build/Utilities/utilities.vcproj +++ b/common/build/Utilities/utilities.vcproj @@ -41,6 +41,8 @@ Name="VCCLCompilerTool" PreprocessorDefinitions="_LIB" ExceptionHandling="2" + UsePrecompiledHeader="2" + PrecompiledHeaderThrough="PrecompiledHeader.h" /> + + + + + + + + + + + @@ -367,6 +401,10 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > + + diff --git a/common/include/Pcsx2Defs.h b/common/include/Pcsx2Defs.h index 98d4d801d6..1a4a7ac054 100644 --- a/common/include/Pcsx2Defs.h +++ b/common/include/Pcsx2Defs.h @@ -59,7 +59,10 @@ // jASSUME - give hints to the optimizer // This is primarily useful for the default case switch optimizer, which enables VC to // generate more compact switches. - +// +// Note: When using the PCSX2 Utilities library, this is deprecated. Use pxAssert instead, +// which itself optimizes to an __assume() hint in release mode builds. +// #ifndef jASSUME # ifdef NDEBUG # define jBREAKPOINT() ((void) 0) @@ -224,8 +227,9 @@ This theoretically unoptimizes. Not having much luck so far. # define PCSX2_ALIGNED_EXTERN(alig,x) extern x __attribute((aligned(alig))) # define PCSX2_ALIGNED16_EXTERN(x) extern x __attribute((aligned(16))) -# define __naked // GCC lacks the naked specifier -# define CALLBACK // CALLBACK is a win32-specific mess +# define __naked // GCC lacks the naked specifier +# define __assume(cond) // GCC has no equivalent for __assume +# define CALLBACK __stdcall // Inlining note: GCC needs ((unused)) attributes defined on inlined functions to suppress // warnings when a static inlined function isn't used in the scope of a single file (which diff --git a/common/include/Utilities/Assertions.h b/common/include/Utilities/Assertions.h new file mode 100644 index 0000000000..086092b6f0 --- /dev/null +++ b/common/include/Utilities/Assertions.h @@ -0,0 +1,84 @@ +/* PCSX2 - PS2 Emulator for PCs + * Copyright (C) 2002-2009 PCSX2 Dev Team + * + * PCSX2 is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * PCSX2 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 PCSX2. + * If not, see . + */ + +#pragma once + +// ---------------------------------------------------------------------------------------- +// pxAssert / pxAssertDev / pxFail / pxFailDev +// ---------------------------------------------------------------------------------------- +// Standard debug-ony "nothrow" (pxAssert) and devel-style "throw" (pxAssertDev) style +// assertions. All assertions act as valid conditional statements that return the result +// of the specified conditional; useful for handling failed assertions in a "graceful" fashion +// when utilizing the "ignore" feature of assertion debugging. (Release builds *always* return +// true for assertion success, but no actual assertion check is performed). +// +// Performance: All assertion types optimize into __assume() directives in Release builds. +// +// pxAssertDev is an assertion tool for Devel builds, intended for sanity checking and/or +// bounds checking variables in areas which are not performance critical. +// +// How it works: pxAssertDev throws an exception of type Exception::LogicError if the assertion +// conditional is false. Typically for the end-user, this exception is handled by the general +// exception handler defined by the application, which (should eventually) create some state +// dumps and other information for troubleshooting purposes. +// +// From a debugging environment, you can trap your pxAssertDev by either breakpointing the +// exception throw code in pxOnAssert, or by adding Exception::LogicError to your First-Chance +// Exception catch list (Visual Studio, under the Debug->Exceptions menu/dialog). You should +// have LogicErrors enabled as First-Chance exceptions regardless, so do it now. :) +// +// Credits Notes: These macros are based on a combination of wxASSERT, MSVCRT's assert +// and the ATL's Assertion/Assumption macros. the best of all worlds! + +#if defined(PCSX2_DEBUG) + +# define pxAssertMsg(cond, msg) ( ((!!(cond)) || \ + (pxOnAssert(__TFILE__, __LINE__, __WXFUNCTION__, _T(#cond), msg), 0)), !!(cond) ) + +# define pxAssertDev(cond,msg) pxAssertMsg(cond, msg) + +# define pxFail(msg) pxAssertMsg(false, msg) +# define pxFailDev(msg) pxAssertDev(false, msg) + +#elif defined(PCSX2_DEVBUILD) + + // Devel builds use __assume for standard assertions and call pxOnAssertDevel + // for AssertDev brand assertions (which typically throws a LogicError exception). + +# define pxAssertMsg(cond, msg) (!!(cond)) + +# define pxAssertDev(cond, msg) ( ((!!(cond)) || \ + (pxOnAssert(__TFILE__, __LINE__, __WXFUNCTION__, _T(#cond), msg), 0)), !!(cond) ) + +# define pxFail(msg) __assume(false) +# define pxFailDev(msg ) pxAssertDev(false, msg) + +#else + + // Release Builds just use __assume as an optimization, and always return 'true' + // indicating the assertion check succeeded (no actual check is performed). + +# define pxAssertMsg(cond, msg) (__assume(cond), true) +# define pxAssertDev(cond, msg) (__assume(cond), true) +# define pxFail(msg) (__assume(false), true) +# define pxFailDev(msg) (__assume(false), true) + +#endif + +#define pxAssert(cond) pxAssertMsg(cond, (wxChar*)NULL) + +extern void pxOnAssert( const wxChar* file, int line, const char* func, const wxChar* cond, const wxChar* msg); +extern void pxOnAssert( const wxChar* file, int line, const char* func, const wxChar* cond, const char* msg); + diff --git a/common/include/Utilities/Console.h b/common/include/Utilities/Console.h index 1f05141246..36c7e96e36 100644 --- a/common/include/Utilities/Console.h +++ b/common/include/Utilities/Console.h @@ -17,103 +17,99 @@ #include "StringHelpers.h" -////////////////////////////////////////////////////////////////////////////////////////// -// Console Namespace -- For printing messages to the console. -// + +enum ConsoleColors +{ + Color_Black = 0, + Color_Red, + Color_Green, + Color_Yellow, + Color_Blue, + Color_Magenta, + Color_Cyan, + Color_White +}; + +// Use fastcall for the console; should be helpful in most cases +#define __concall __fastcall + +// ---------------------------------------------------------------------------------------- +// IConsole -- For printing messages to the console. +// ---------------------------------------------------------------------------------------- // SysPrintf is depreciated; We should phase these in over time. // -namespace Console +struct IConsoleWriter { - enum Colors - { - Color_Black = 0, - Color_Red, - Color_Green, - Color_Yellow, - Color_Blue, - Color_Magenta, - Color_Cyan, - Color_White - }; + // Write implementation for internal use only. + void (__concall *DoWrite)( const wxString& fmt ); - // va_args version of WriteLn, mostly for internal use only. - extern void __fastcall _WriteLn( Colors color, const char* fmt, va_list args ); + // WriteLn implementation for internal use only. + void (__concall *DoWriteLn)( const wxString& fmt ); - extern void __fastcall SetTitle( const wxString& title ); + void (__concall *Newline)(); + + void (__concall *SetTitle)( const wxString& title ); // Changes the active console color. // This color will be unset by calls to colored text methods // such as ErrorMsg and Notice. - extern void __fastcall SetColor( Colors color ); + void (__concall *SetColor)( ConsoleColors color ); // Restores the console color to default (usually low-intensity white on Win32) - extern void ClearColor(); + void (__concall *ClearColor)(); - // The following Write functions return bool so that we can use macros to exclude - // them from different build types. The return values are always zero. + // ---------------------------------------------------------------------------- + // Public members; call these to print stuff to console! - // Writes a newline to the console. - extern bool Newline(); + void Write( ConsoleColors color, const char* fmt, ... ) const; + void Write( const char* fmt, ... ) const; + void Write( ConsoleColors color, const wxString& fmt ) const; + void Write( const wxString& fmt ) const; - // Writes a line of colored text to the console, with automatic newline appendage. - // The console color is reset to default when the operation is complete. - extern bool WriteLn( Colors color, const char* fmt, ... ); + void WriteLn( ConsoleColors color, const char* fmt, ... ) const; + void WriteLn( const char* fmt, ... ) const; + void WriteLn( ConsoleColors color, const wxString& fmt ) const; + void WriteLn( const wxString& fmt ) const; - // Writes a formatted message to the console, with appended newline. - extern bool WriteLn( const char* fmt, ... ); + void Error( const char* fmt, ... ) const; + void Notice( const char* fmt, ... ) const; + void Status( const char* fmt, ... ) const; - // Writes a line of colored text to the console (no newline). - // The console color is reset to default when the operation is complete. - extern bool Write( Colors color, const char* fmt, ... ); + void Error( const wxString& src ) const; + void Notice( const wxString& src ) const; + void Status( const wxString& src ) const; - // Writes a formatted message to the console (no newline) - extern bool Write( const char* fmt, ... ); + // ---------------------------------------------------------------------------- + // Private Members; for internal use only. - // Displays a message in the console with red emphasis. - // Newline is automatically appended. - extern bool Error( const char* fmt, ... ); + void _Write( const char* fmt, va_list args ) const; + void _WriteLn( const char* fmt, va_list args ) const; + void _WriteLn( ConsoleColors color, const char* fmt, va_list args ) const; +}; - // Displays a message in the console with yellow emphasis. - // Newline is automatically appended. - extern bool Notice( const char* fmt, ... ); +extern void Console_SetActiveHandler( const IConsoleWriter& writer, FILE* flushfp=NULL ); +extern const wxString& ConsoleBuffer_Get(); +extern void ConsoleBuffer_Clear(); +extern void ConsoleBuffer_FlushToFile( FILE *fp ); - // Displays a message in the console with yellow emphasis. - // Newline is automatically appended. - extern bool Status( const char* fmt, ... ); +extern const IConsoleWriter ConsoleWriter_Null; +extern const IConsoleWriter ConsoleWriter_Assert; +extern const IConsoleWriter ConsoleWriter_Buffered; +extern const IConsoleWriter ConsoleWriter_wxError; - - extern bool __fastcall Write( const wxString& text ); - extern bool __fastcall Write( Colors color, const wxString& text ); - extern bool __fastcall WriteLn( const wxString& text ); - extern bool __fastcall WriteLn( Colors color, const wxString& text ); - - extern bool __fastcall Error( const wxString& text ); - extern bool __fastcall Notice( const wxString& text ); - extern bool __fastcall Status( const wxString& text ); -} - -using Console::Color_Black; -using Console::Color_Red; -using Console::Color_Green; -using Console::Color_Blue; -using Console::Color_Magenta; -using Console::Color_Cyan; -using Console::Color_Yellow; -using Console::Color_White; - -////////////////////////////////////////////////////////////////////////////////////////// -// DevCon / DbgCon +extern IConsoleWriter Console; #ifdef PCSX2_DEVBUILD -# define DevCon Console -# define DevMsg MsgBox + extern IConsoleWriter DevConWriter; +# define DevCon DevConWriter #else -# define DevCon 0&&Console -# define DevMsg +# define DevCon ConsoleWriter_Null #endif #ifdef PCSX2_DEBUG -# define DbgCon Console + extern IConsoleWriter DbgConWriter; +# define DbgCon DbgConWriter #else -# define DbgCon 0&&Console +# define DbgCon ConsoleWriter_Null #endif + diff --git a/common/include/Utilities/Dependencies.h b/common/include/Utilities/Dependencies.h index 7305a55763..0f40db2b0c 100644 --- a/common/include/Utilities/Dependencies.h +++ b/common/include/Utilities/Dependencies.h @@ -15,6 +15,8 @@ #pragma once +// Dependencies.h : Contains classes required by all Utilities headers. + ////////////////////////////////////////////////////////////////////////////////////////// // DeclareNoncopyableObject // This macro provides an easy and clean method for ensuring objects are not copyable. @@ -73,17 +75,15 @@ protected: // #define wxLt(a) (a) -#ifndef wxASSERT_MSG_A -# define wxASSERT_MSG_A( cond, msg ) wxASSERT_MSG( cond, wxString::FromAscii( msg ).c_str() ) -#endif - // must include wx/setup.h first, otherwise we get warnings/errors regarding __LINUX__ #include +class wxString; + #include "Pcsx2Defs.h" #include -#include +//#include #include // for wxPoint/wxRect stuff #include #include @@ -94,3 +94,5 @@ protected: #include // string.h under c++ #include // stdio.h under c++ #include + +#include "Utilities/Assertions.h" diff --git a/common/include/Utilities/Exceptions.h b/common/include/Utilities/Exceptions.h index c6eb8796bb..1762e1fe93 100644 --- a/common/include/Utilities/Exceptions.h +++ b/common/include/Utilities/Exceptions.h @@ -17,8 +17,6 @@ #include "Dependencies.h" -extern bool DevAssert( bool condition, const char* msg ); - // -------------------------------------------------------------------------------------- // DESTRUCTOR_CATCHALL - safe destructor helper // -------------------------------------------------------------------------------------- @@ -30,13 +28,13 @@ extern bool DevAssert( bool condition, const char* msg ); #define __DESTRUCTOR_CATCHALL( funcname ) \ catch( Exception::BaseException& ex ) \ { \ - Console::Error( "Unhandled BaseException in %s (ignored!):", funcname ); \ - Console::Error( ex.FormatDiagnosticMessage() ); \ + Console.Error( "Unhandled BaseException in %s (ignored!):", funcname ); \ + Console.Error( ex.FormatDiagnosticMessage() ); \ } \ catch( std::exception& ex ) \ { \ - Console::Error( "Unhandled std::exception in %s (ignored!):", funcname ); \ - Console::Error( ex.what() ); \ + Console.Error( "Unhandled std::exception in %s (ignored!):", funcname ); \ + Console.Error( ex.what() ); \ } #ifdef __GNUC__ diff --git a/common/include/Utilities/General.h b/common/include/Utilities/General.h index 0efc4f2a4b..66892892a7 100644 --- a/common/include/Utilities/General.h +++ b/common/include/Utilities/General.h @@ -15,6 +15,31 @@ #pragma once +// ---------------------------------------------------------------------------------------- +// RecursionGuard - Basic protection against function recursion +// ---------------------------------------------------------------------------------------- +// Thread safety note: If used in a threaded environment, you shoud use a handle to a __threadlocal +// storage variable (protects aaginst race conditions and, in *most* cases, is more desirable +// behavior as well. +// +// Rationale: wxWidgets has its own wxRecursionGuard, but it has a sloppy implementation with +// entirely unnecessary assertion checks. +// +class RecursionGuard +{ +public: + int& Counter; + + RecursionGuard( int& counter ) : Counter( counter ) + { ++Counter; } + + virtual ~RecursionGuard() throw() + { --Counter; } + + bool IsReentrant() const { return Counter > 1; } +}; + + enum PageProtectionMode { Protect_NoAccess = 0, diff --git a/common/include/Utilities/StringHelpers.h b/common/include/Utilities/StringHelpers.h index 0e60e8f79e..0f43f1e89a 100644 --- a/common/include/Utilities/StringHelpers.h +++ b/common/include/Utilities/StringHelpers.h @@ -15,13 +15,48 @@ #pragma once +#include "Dependencies.h" + #include #include #include // for wxPoint/wxRect stuff -////////////////////////////////////////////////////////////////////////////////////////// -// Helpers for wxWidgets stuff! -// +extern void px_fputs( FILE* fp, const char* src ); + +// -------------------------------------------------------------------------------------- +// toUTF8 - shortcut for str.ToUTF8().data() +// -------------------------------------------------------------------------------------- +class toUTF8 +{ + DeclareNoncopyableObject( toUTF8 ); + +protected: + wxCharBuffer m_charbuffer; + +public: + toUTF8( const wxString& str ) : m_charbuffer( str.ToUTF8().data() ) { } + virtual ~toUTF8() throw() {} + + operator const char*() { return m_charbuffer.data(); } +}; + +// This class provided for completeness sake. You probably should use toUTF8 instead. +class toAscii +{ + DeclareNoncopyableObject( toAscii ); + +protected: + wxCharBuffer m_charbuffer; + +public: + toAscii( const wxString& str ) : m_charbuffer( str.ToAscii().data() ) { } + virtual ~toAscii() throw() {} + + operator const char*() { return m_charbuffer.data(); } +}; + +extern wxString fromUTF8( const char* src ); +extern wxString fromAscii( const char* src ); // wxWidgets lacks one of its own... extern const wxRect wxDefaultRect; diff --git a/common/include/Utilities/Threading.h b/common/include/Utilities/Threading.h index befa17d964..08e3473cdc 100644 --- a/common/include/Utilities/Threading.h +++ b/common/include/Utilities/Threading.h @@ -120,25 +120,33 @@ namespace Threading virtual bool IsSelf() const { return false; } virtual bool IsRunning() { return false; } - virtual int GetReturnCode() const - { - DevAssert( false, "Cannot obtain a return code from a placebo thread." ); - return 0; - } virtual void Start() {} virtual void Cancel( bool isBlocking = true ) {} - virtual sptr Block() { return NULL; } + virtual void Block() {} virtual bool Detach() { return false; } }; // -------------------------------------------------------------------------------------- // PersistentThread - Helper class for the basics of starting/managing persistent threads. // -------------------------------------------------------------------------------------- -// Use this as a base class for your threaded procedure, and implement the 'int ExecuteTask()' -// method. Use Start() and Cancel() to start and shutdown the thread, and use m_sem_event -// internally to post/receive events for the thread (make a public accessor for it in your -// derived class if your thread utilizes the post). +// This class is meant to be a helper for the typical threading model of "start once and +// reuse many times." This class incorporates a lot of extra overhead in stopping and +// starting threads, but in turn provides most of the basic thread-safety and event-handling +// functionality needed for a threaded operation. In practice this model is usually an +// ideal one for efficiency since Operating Systems themselves typically subscribe to a +// design where sleeping, suspending, and resuming threads is very efficient, but starting +// new threads has quite a bit of overhead. +// +// To use this as a base class for your threaded procedure, overload the following virtual +// methods: +// void OnStart(); +// void ExecuteTask(); +// void OnThreadCleanup(); +// +// Use the public methods Start() and Cancel() to start and shutdown the thread, and use +// m_sem_event internally to post/receive events for the thread (make a public accessor for +// it in your derived class if your thread utilizes the post). // // Notes: // * Constructing threads as static global vars isn't recommended since it can potentially @@ -159,7 +167,6 @@ namespace Threading Semaphore m_sem_event; // general wait event that's needed by most threads. Semaphore m_sem_finished; // used for canceling and closing threads in a deadlock-safe manner MutexLock m_lock_start; // used to lock the Start() code from starting simutaneous threads accidentally. - sptr m_returncode; // value returned from the thread on close. volatile long m_detached; // a boolean value which indicates if the m_thread handle is valid volatile long m_running; // set true by Start(), and set false by Cancel(), Block(), etc. @@ -176,18 +183,23 @@ namespace Threading virtual void Start(); virtual void Cancel( bool isBlocking = true ); virtual bool Detach(); - virtual sptr Block(); - - virtual int GetReturnCode() const; + virtual void Block(); virtual void RethrowException() const; bool IsRunning() const; bool IsSelf() const; wxString GetName() const; - virtual void DoThreadCleanup(); + void _ThreadCleanup(); protected: + + // Extending classes should always implement your own OnStart(), which is called by + // Start() once necessary locks have been obtained. Do not override Start() directly + // unless you're really sure that's what you need to do. ;) + virtual void OnStart()=0; + virtual void OnThreadCleanup()=0; + void DoSetThreadName( const wxString& name ); void DoSetThreadName( __unused const char* name ); void _internal_execute(); @@ -198,7 +210,7 @@ namespace Threading static void* _internal_callback( void* func ); // Implemented by derived class to handle threading actions! - virtual sptr ExecuteTask()=0; + virtual void ExecuteTask()=0; }; ////////////////////////////////////////////////////////////////////////////////////////// @@ -295,7 +307,7 @@ namespace Threading { } - sptr Block(); + void Block(); void PostTask(); void WaitForResult(); @@ -304,7 +316,7 @@ namespace Threading // all your necessary processing work here. virtual void Task()=0; - sptr ExecuteTask(); + virtual void ExecuteTask(); }; ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/common/include/Utilities/wxBaseTools.h b/common/include/Utilities/wxBaseTools.h index 3cd62cbed4..49289e79e2 100644 --- a/common/include/Utilities/wxBaseTools.h +++ b/common/include/Utilities/wxBaseTools.h @@ -55,36 +55,3 @@ public: wxLog::EnableLogging( m_prev ); } }; - -// -------------------------------------------------------------------------------------- -// wxToUTF8 - shortcut for str.ToUTF8().data() -// -------------------------------------------------------------------------------------- -class wxToUTF8 -{ - DeclareNoncopyableObject( wxToUTF8 ); - -protected: - wxCharBuffer m_charbuffer; - -public: - wxToUTF8( const wxString& str ) : m_charbuffer( str.ToUTF8().data() ) { } - virtual ~wxToUTF8() throw() {} - - operator const char*() { return m_charbuffer.data(); } -}; - -// This class provided for completeness sake. You probably should use ToUTF8 instead. -class wxToAscii -{ - DeclareNoncopyableObject( wxToAscii ); - -protected: - wxCharBuffer m_charbuffer; - -public: - wxToAscii( const wxString& str ) : m_charbuffer( str.ToAscii().data() ) { } - virtual ~wxToAscii() throw() {} - - operator const char*() { return m_charbuffer.data(); } -}; - diff --git a/common/include/wx/folderdesc.txt b/common/include/wx/folderdesc.txt index 445d474d78..2c9133cbc8 100644 --- a/common/include/wx/folderdesc.txt +++ b/common/include/wx/folderdesc.txt @@ -11,3 +11,7 @@ folder prefix, these files can be included the same way as other wxWidgets inclu If/when PCSX2 upgrades to wx2.9/3.0 these files will be removed and the wxWidgets distribution files will automatically be used instead. + + +NOTE: Removed wxScopedPtr in favor of our own implementation, which uses a more +sensible API naming convention and also features better operator assignment. \ No newline at end of file diff --git a/common/include/x86emitter/inlines.inl b/common/include/x86emitter/inlines.inl index f1eec1b442..59cadea384 100644 --- a/common/include/x86emitter/inlines.inl +++ b/common/include/x86emitter/inlines.inl @@ -203,7 +203,7 @@ namespace x86Emitter Factor++; else { - DevAssert( Index.IsEmpty(), "x86Emitter: Only one scaled index register is allowed in an address modifier." ); + pxAssertDev( Index.IsEmpty(), "x86Emitter: Only one scaled index register is allowed in an address modifier." ); Index = src; Factor = 2; } @@ -287,7 +287,7 @@ namespace x86Emitter // Don't ask. --arcum42 #if !defined(__LINUX__) || !defined(DEBUG) - Console::Error( "Emitter Error: Invalid short jump displacement = 0x%x", (int)displacement ); + Console.Error( "Emitter Error: Invalid short jump displacement = 0x%x", (int)displacement ); #endif } BasePtr[-1] = (s8)displacement; diff --git a/common/src/Utilities/Console.cpp b/common/src/Utilities/Console.cpp index b1afd1ca14..6c2c7eed47 100644 --- a/common/src/Utilities/Console.cpp +++ b/common/src/Utilities/Console.cpp @@ -19,138 +19,301 @@ using namespace Threading; using namespace std; -namespace Console +// Important! Only Assert and Null console loggers are allowed for initial console targeting. +// Other log targets rely on the static buffer and a threaded mutex lock, which are only valid +// after C++ initialization has finished. +void Console_SetActiveHandler( const IConsoleWriter& writer, FILE* flushfp ) { - MutexLock m_writelock; + pxAssertDev( + (writer.DoWrite != NULL) && (writer.DoWriteLn != NULL) && + (writer.Newline != NULL) && (writer.SetTitle != NULL) && + (writer.SetColor != NULL) && (writer.ClearColor != NULL), + "Invalid IConsoleWriter object! All function pointer interfaces must be implemented." + ); + + if( !ConsoleBuffer_Get().IsEmpty() ) + writer.DoWriteLn( ConsoleBuffer_Get() ); - bool __fastcall Write( Colors color, const wxString& fmt ) - { - SetColor( color ); - Write( fmt ); - ClearColor(); + Console = writer; - return false; - } - - bool __fastcall WriteLn( Colors color, const wxString& fmt ) - { - SetColor( color ); - WriteLn( fmt ); - ClearColor(); - return false; - } - - // ------------------------------------------------------------------------ - __forceinline void __fastcall _Write( const char* fmt, va_list args ) - { - std::string m_format_buffer; - vssprintf( m_format_buffer, fmt, args ); - Write( wxString::FromUTF8( m_format_buffer.c_str() ) ); - } - - __forceinline void __fastcall _WriteLn( const char* fmt, va_list args ) - { - std::string m_format_buffer; - vssprintf( m_format_buffer, fmt, args ); - WriteLn( wxString::FromUTF8( m_format_buffer.c_str() ) ); - } - - __forceinline void __fastcall _WriteLn( Colors color, const char* fmt, va_list args ) - { - SetColor( color ); - _WriteLn( fmt, args ); - ClearColor(); - } - - // ------------------------------------------------------------------------ - bool Write( const char* fmt, ... ) - { - va_list args; - va_start(args,fmt); - _Write( fmt, args ); - va_end(args); - - return false; - } - - bool Write( Colors color, const char* fmt, ... ) - { - va_list args; - va_start(args,fmt); - SetColor( color ); - _Write( fmt, args ); - ClearColor(); - va_end(args); - - return false; - } - - // ------------------------------------------------------------------------ - bool WriteLn( const char* fmt, ... ) - { - va_list args; - va_start(args,fmt); - _WriteLn( fmt, args ); - va_end(args); - - return false; - } - - bool WriteLn( Colors color, const char* fmt, ... ) - { - va_list args; - va_start(args,fmt); - _WriteLn( color, fmt, args ); - va_end(args); - return false; - } - - // ------------------------------------------------------------------------ - bool Error( const char* fmt, ... ) - { - va_list args; - va_start(args,fmt); - _WriteLn( Color_Red, fmt, args ); - va_end(args); - return false; - } - - bool Notice( const char* fmt, ... ) - { - va_list list; - va_start(list,fmt); - _WriteLn( Color_Yellow, fmt, list ); - va_end(list); - return false; - } - - bool Status( const char* fmt, ... ) - { - va_list list; - va_start(list,fmt); - _WriteLn( Color_Green, fmt, list ); - va_end(list); - return false; - } - - // ------------------------------------------------------------------------ - bool __fastcall Error( const wxString& src ) - { - WriteLn( Color_Red, src ); - return false; - } - - bool __fastcall Notice( const wxString& src ) - { - WriteLn( Color_Yellow, src ); - return false; - } - - bool __fastcall Status( const wxString& src ) - { - WriteLn( Color_Green, src ); - return false; - } +#ifdef PCSX2_DEVBUILD + DevCon = writer; +#endif +#ifdef PCSX2_DEBUG + DbgCon = writer; +#endif } +// -------------------------------------------------------------------------------------- +// ConsoleImpl_Null +// -------------------------------------------------------------------------------------- + +static void __concall ConsoleNull_SetTitle( const wxString& title ) {} +static void __concall ConsoleNull_SetColor( ConsoleColors color ) {} +static void __concall ConsoleNull_ClearColor() {} +static void __concall ConsoleNull_Newline() {} +static void __concall ConsoleNull_DoWrite( const wxString& fmt ) {} +static void __concall ConsoleNull_DoWriteLn( const wxString& fmt ) {} + +// -------------------------------------------------------------------------------------- +// ConsoleImpl_Assert +// -------------------------------------------------------------------------------------- + +static void __concall ConsoleAssert_DoWrite( const wxString& fmt ) +{ + pxFail( L"Console class has not been initialized; Message written:\n\t" + fmt ); +} + +static void __concall ConsoleAssert_DoWriteLn( const wxString& fmt ) +{ + pxFail( L"Console class has not been initialized; Message written:\n\t" + fmt ); +} + +// -------------------------------------------------------------------------------------- +// ConsoleImpl_Buffered Implementations +// -------------------------------------------------------------------------------------- + +static wxString m_buffer; + +const wxString& ConsoleBuffer_Get() +{ + return m_buffer; +} + +void ConsoleBuffer_Clear() +{ + m_buffer.Clear(); +} + +void ConsoleBuffer_FlushToFile( FILE *fp ) +{ + if( fp == NULL || m_buffer.IsEmpty() ) return; + px_fputs( fp, toUTF8(m_buffer) ); + m_buffer.Clear(); +} + +static void __concall ConsoleBuffer_DoWrite( const wxString& fmt ) +{ + m_buffer += fmt; +} + +static void __concall ConsoleBuffer_DoWriteLn( const wxString& fmt ) +{ + m_buffer += fmt + L"\n"; +} + +// -------------------------------------------------------------------------------------- +// ConsoleImpl_wxLogError Implementations +// -------------------------------------------------------------------------------------- + +static void __concall Console_wxLogError_DoWriteLn( const wxString& fmt ) +{ + if( !m_buffer.IsEmpty() ) + { + wxLogError( m_buffer ); + m_buffer.Clear(); + } + wxLogError( fmt ); +} + +// -------------------------------------------------------------------------------------- +// IConsole Implementations +// -------------------------------------------------------------------------------------- + +// Default write action at startup and shutdown is to use the stdout. +void IConsole_DoWrite( const wxString& fmt ) +{ + wxPrintf( fmt ); +} + +// Default write action at startup and shutdown is to use the stdout. +void IConsole_DoWriteLn( const wxString& fmt ) +{ + wxPrintf( fmt ); +} + +// Writes a line of colored text to the console (no newline). +// The console color is reset to default when the operation is complete. +void IConsoleWriter::Write( ConsoleColors color, const wxString& fmt ) const +{ + SetColor( color ); + Write( fmt ); + ClearColor(); +} + +// Writes a line of colored text to the console, with automatic newline appendage. +// The console color is reset to default when the operation is complete. +void IConsoleWriter::WriteLn( ConsoleColors color, const wxString& fmt ) const +{ + SetColor( color ); + WriteLn( fmt ); + ClearColor(); +} + +void IConsoleWriter::_Write( const char* fmt, va_list args ) const +{ + std::string m_format_buffer; + vssprintf( m_format_buffer, fmt, args ); + Write( wxString::FromUTF8( m_format_buffer.c_str() ) ); +} + +void IConsoleWriter::_WriteLn( const char* fmt, va_list args ) const +{ + std::string m_format_buffer; + vssprintf( m_format_buffer, fmt, args ); + WriteLn( wxString::FromUTF8( m_format_buffer.c_str() ) ); +} + +void IConsoleWriter::_WriteLn( ConsoleColors color, const char* fmt, va_list args ) const +{ + SetColor( color ); + _WriteLn( fmt, args ); + ClearColor(); +} + +void IConsoleWriter::Write( const char* fmt, ... ) const +{ + va_list args; + va_start(args,fmt); + _Write( fmt, args ); + va_end(args); +} + +void IConsoleWriter::Write( ConsoleColors color, const char* fmt, ... ) const +{ + va_list args; + va_start(args,fmt); + SetColor( color ); + _Write( fmt, args ); + ClearColor(); + va_end(args); +} + +void IConsoleWriter::WriteLn( const char* fmt, ... ) const +{ + va_list args; + va_start(args,fmt); + _WriteLn( fmt, args ); + va_end(args); +} + +void IConsoleWriter::WriteLn( ConsoleColors color, const char* fmt, ... ) const +{ + va_list args; + va_start(args,fmt); + _WriteLn( color, fmt, args ); + va_end(args); +} + +void IConsoleWriter::Write( const wxString& src ) const +{ + DoWrite( src ); +} + +void IConsoleWriter::WriteLn( const wxString& src ) const +{ + DoWriteLn( src ); +} + +void IConsoleWriter::Error( const char* fmt, ... ) const +{ + va_list args; + va_start(args,fmt); + _WriteLn( Color_Red, fmt, args ); + va_end(args); +} + +void IConsoleWriter::Notice( const char* fmt, ... ) const +{ + va_list list; + va_start(list,fmt); + _WriteLn( Color_Yellow, fmt, list ); + va_end(list); +} + +void IConsoleWriter::Status( const char* fmt, ... ) const +{ + va_list list; + va_start(list,fmt); + _WriteLn( Color_Green, fmt, list ); + va_end(list); +} + +void IConsoleWriter::Error( const wxString& src ) const +{ + WriteLn( Color_Red, src ); +} + +void IConsoleWriter::Notice( const wxString& src ) const +{ + WriteLn( Color_Yellow, src ); +} + +void IConsoleWriter::Status( const wxString& src ) const +{ + WriteLn( Color_Green, src ); +} + +const IConsoleWriter ConsoleWriter_Null = +{ + ConsoleNull_DoWrite, + ConsoleNull_DoWriteLn, + + ConsoleNull_Newline, + + ConsoleNull_SetTitle, + ConsoleNull_SetColor, + ConsoleNull_ClearColor, +}; + +const IConsoleWriter ConsoleWriter_Assert = +{ + ConsoleAssert_DoWrite, + ConsoleAssert_DoWriteLn, + + ConsoleNull_Newline, + + ConsoleNull_SetTitle, + ConsoleNull_SetColor, + ConsoleNull_ClearColor, +}; + +const IConsoleWriter ConsoleWriter_wxError = +{ + ConsoleBuffer_DoWrite, // Writes without newlines go to buffer to avoid error log spam. + Console_wxLogError_DoWriteLn, + + ConsoleNull_Newline, + + ConsoleNull_SetTitle, + ConsoleNull_SetColor, + ConsoleNull_ClearColor, +}; + +const IConsoleWriter ConsoleWriter_Buffered = +{ + ConsoleBuffer_DoWrite, // Writes without newlines go to buffer to avoid assertion spam. + ConsoleBuffer_DoWriteLn, + + ConsoleNull_Newline, + + ConsoleNull_SetTitle, + ConsoleNull_SetColor, + ConsoleNull_ClearColor, +}; + + +// Important! Only Assert and Null console loggers are allowed for initial console targeting. +// Other log targets rely on the static buffer and a threaded mutex lock, which are only valid +// after C++ initialization has finished. + +IConsoleWriter Console = ConsoleWriter_Assert; + +#ifdef PCSX2_DEVBUILD + IConsoleWriter DevConWriter= ConsoleWriter_Assert; +#endif + +#ifdef PCSX2_DEBUG + IConsoleWriter DbgConWriter= ConsoleWriter_Assert; +#endif \ No newline at end of file diff --git a/common/src/Utilities/Exceptions.cpp b/common/src/Utilities/Exceptions.cpp index b8881eb146..8186259dea 100644 --- a/common/src/Utilities/Exceptions.cpp +++ b/common/src/Utilities/Exceptions.cpp @@ -15,6 +15,8 @@ #include "PrecompiledHeader.h" +#include + wxString GetEnglish( const char* msg ) { return wxString::FromAscii(msg); @@ -26,11 +28,9 @@ wxString GetTranslation( const char* msg ) } // ------------------------------------------------------------------------ -// Force DevAssert to *not* inline for devel/debug builds (allows using breakpoints to trap -// assertions), and force it to inline for release builds (optimizes it out completely since -// IsDevBuild is false). Since Devel builds typically aren't enabled with Global Optimization/ -// LTCG, this currently isn't even necessary. But might as well, in case we decide at a later -// date to re-enable LTCG for devel. +// Force DevAssert to *not* inline for devel builds (allows using breakpoints to trap assertions, +// and force it to inline for release builds (optimizes it out completely since IsDevBuild is a +// const false). // #ifdef PCSX2_DEVBUILD # define DEVASSERT_INLINE __noinline @@ -38,37 +38,44 @@ wxString GetTranslation( const char* msg ) # define DEVASSERT_INLINE __forceinline #endif -////////////////////////////////////////////////////////////////////////////////////////// -// Assertion tool for Devel builds, intended for sanity checking and/or bounds checking -// variables in areas which are not performance critical. -// -// How it works: This function throws an exception of type Exception::AssertionFailure if -// the assertion conditional is false. Typically for the end-user, this exception is handled -// by the general handler, which (should eventually) create some state dumps and other -// information for troubleshooting purposes. -// -// From a debugging environment, you can trap your DevAssert by either breakpointing the -// exception throw below, or by adding Exception::LogicError to your First-Chance Exception -// catch list (Visual Studio, under the Debug->Exceptions menu/dialog). You should have -// LogicErrors enabled as First-Chance exceptions regardless, so do it now. :) -// -// Returns: -// TRUE if the assertion succeeded (condition is valid), or FALSE if the assertion -// failed. The true clause is only reachable in release builds, and can be used by code -// to provide a "stable" escape clause for unexpected behavior. -// -DEVASSERT_INLINE bool DevAssert( bool condition, const char* msg ) +// Using a threadlocal assertion guard. Separate threads can assert at the same time. +// That's ok. What we don't want is the *same* thread recurse-asserting. +static __threadlocal int s_assert_guard = 0; + +DEVASSERT_INLINE void pxOnAssert( const wxChar* file, int line, const char* func, const wxChar* cond, const wxChar* msg) { - if( condition ) return true; +#ifdef PCSX2_DEVBUILD + RecursionGuard guard( s_assert_guard ); + if( guard.IsReentrant() ) return; + + if( wxTheApp == NULL ) + { + // Note: Format uses MSVC's syntax for output window hotlinking. + wxsFormat( L"%s(%d): Assertion failed in %s: %s\n", + file, line, fromUTF8(func), msg ); - wxASSERT_MSG_A( false, msg ); - - if( IsDevBuild && !IsDebugBuild ) - throw Exception::LogicError( msg ); - - return false; + wxLogError( msg ); + } + else + { + #ifdef __WXDEBUG__ + wxTheApp->OnAssertFailure( file, line, fromUTF8(func), cond, msg ); + #elif wxUSE_GUI + // FIXME: this should create a popup dialog for devel builds. + wxLogError( msg ); + #else + wxLogError( msg ); + #endif + } +#endif } +__forceinline void pxOnAssert( const wxChar* file, int line, const char* func, const wxChar* cond, const char* msg) +{ + pxOnAssert( file, line, func, cond, fromUTF8(msg) ); +} + + // -------------------------------------------------------------------------------------- // Exception Namespace Implementations (Format message handlers for general exceptions) // -------------------------------------------------------------------------------------- @@ -87,7 +94,7 @@ void Exception::BaseException::InitBaseEx( const wxString& msg_eng, const wxStri #ifdef __LINUX__ //wxLogError( msg_eng.c_str() ); - Console::Error( msg_eng ); + Console.Error( msg_eng ); #endif } @@ -100,7 +107,7 @@ void Exception::BaseException::InitBaseEx( const char* msg_eng ) #ifdef __LINUX__ //wxLogError( m_message_diag.c_str() ); - Console::Error( msg_eng ); + Console.Error( msg_eng ); #endif } diff --git a/common/src/Utilities/Linux/LnxHostSys.cpp b/common/src/Utilities/Linux/LnxHostSys.cpp index 66b7932b05..eb99a3192d 100644 --- a/common/src/Utilities/Linux/LnxHostSys.cpp +++ b/common/src/Utilities/Linux/LnxHostSys.cpp @@ -27,7 +27,7 @@ namespace HostSys { u8 *Mem; Mem = (u8*)mmap((uptr*)base, size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); - if (Mem == MAP_FAILED) Console::Notice("Mmap Failed!"); + if (Mem == MAP_FAILED) Console.Notice("Mmap Failed!"); return Mem; } diff --git a/common/src/Utilities/PrecompiledHeader.h b/common/src/Utilities/PrecompiledHeader.h index 05f0f62af8..81362ff7f8 100644 --- a/common/src/Utilities/PrecompiledHeader.h +++ b/common/src/Utilities/PrecompiledHeader.h @@ -7,6 +7,7 @@ using std::string; using std::min; using std::max; +#include "Assertions.h" #include "MemcpyFast.h" #include "Console.h" #include "Exceptions.h" diff --git a/common/src/Utilities/StringHelpers.cpp b/common/src/Utilities/StringHelpers.cpp index a6eb8b01c2..99f20f02ef 100644 --- a/common/src/Utilities/StringHelpers.cpp +++ b/common/src/Utilities/StringHelpers.cpp @@ -17,6 +17,17 @@ const wxRect wxDefaultRect( wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord ); + +__forceinline wxString fromUTF8( const char* src ) +{ + return wxString::FromUTF8( src ); +} + +__forceinline wxString fromAscii( const char* src ) +{ + return wxString::FromAscii( src ); +} + // Splits a string into parts and adds the parts into the given SafeList. // This list is not cleared, so concatenating many splits into a single large list is // the 'default' behavior, unless you manually clear the SafeList prior to subsequent calls. @@ -160,3 +171,49 @@ bool TryParse( wxRect& dest, const wxString& src, const wxRect& defval, const wx dest = wxRect( point, size ); return true; } + +// Performs a cross-platform puts operation, which adds CRs to naked LFs on Win32 platforms, +// so that Notepad won't throw a fit and Rama can read the logs again! On Unix and Mac platforms, +// the input string is written unmodified. +// +// PCSX2 generally uses Unix-style newlines -- LF (\n) only -- hence there's no need to strip CRs +// from incoming data. Mac platforms may need an implementation of their own that converts +// newlines to CRs...? +// +void px_fputs( FILE* fp, const char* src ) +{ + if( fp == NULL ) return; + +#ifdef _WIN32 + // Windows needs CR's partnered with all newlines, or else notepad.exe can't view + // the stupid logfile. Best way is to write one char at a time.. >_< + + const char* curchar = src; + bool prevcr = false; + while( *curchar != 0 ) + { + if( *curchar == '\r' ) + { + prevcr = true; + } + else + { + // Only write a CR/LF pair if the current LF is not prefixed nor + // post-fixed by a CR. + if( *curchar == '\n' && !prevcr && (*(curchar+1) != '\r') ) + fputs( "\r\n", fp ); + else + fputc( *curchar, fp ); + + prevcr = false; + } + ++curchar; + } + +#else + // Linux is happy with plain old LFs. Not sure about Macs... does OSX still + // go by the old school Mac style of using Crs only? + + fputs( src, emuLog ); // fputs does not do automatic newlines, so it's ok! +#endif +} \ No newline at end of file diff --git a/common/src/Utilities/ThreadTools.cpp b/common/src/Utilities/ThreadTools.cpp index bc8ffefc50..a9009acdce 100644 --- a/common/src/Utilities/ThreadTools.cpp +++ b/common/src/Utilities/ThreadTools.cpp @@ -34,7 +34,7 @@ namespace Threading static void _pt_callback_cleanup( void* handle ) { - ((PersistentThread*)handle)->DoThreadCleanup(); + ((PersistentThread*)handle)->_ThreadCleanup(); } PersistentThread::PersistentThread() : @@ -43,39 +43,60 @@ namespace Threading , m_sem_event() , m_sem_finished() , m_lock_start( true ) // recursive mutexing! - , m_returncode( 0 ) , m_detached( true ) // start out with m_thread in detached/invalid state , m_running( false ) { } - // This destructor performs basic "last chance" cleanup, which is a blocking - // join against non-detached threads. Detached threads are unhandled. - // Extending classes should always implement their own thread closure process. - // This class must not be deleted from its own thread. That would be like marrying - // your sister, and then cheating on her with your daughter. + // This destructor performs basic "last chance" cleanup, which is a blocking join + // against the thread. Extending classes should almost always implement their own + // thread closure process, since any PersistentThread will, by design, not terminate + // unless it has been properly canceled. + // + // Thread safetly: This class must not be deleted from its own thread. That would be + // like marrying your sister, and then cheating on her with your daughter. PersistentThread::~PersistentThread() throw() { - if( m_running ) + try { -#if wxUSE_GUI - m_sem_finished.WaitGui(); -#else - m_sem_finished.Wait(); -#endif - } + wxString logfix = L"Thread Destructor for " + m_name; - Detach(); + if( m_running ) + { + Console.WriteLn( logfix + L": Waiting for running thread to end."); + #if wxUSE_GUI + m_sem_finished.WaitGui(); + #else + m_sem_finished.Wait(); + #endif + // Need to lock here so that the thread can finish shutting down before + // it gets destroyed, otherwise th mutex handle would become invalid. + ScopedLock locker( m_lock_start ); + } + else + Console.WriteLn( logfix + L": thread not running."); + Sleep( 1 ); + Detach(); + } + DESTRUCTOR_CATCHALL } + // Main entry point for starting or e-starting a persistent thread. This function performs necessary + // locks and checks for avoiding race conditions, and then calls OnStart() immeediately before + // the actual thread creation. Extending classes should generally not override Start(), and should + // instead override DoPrepStart instead. + // // This function should not be called from the owner thread. void PersistentThread::Start() { ScopedLock startlock( m_lock_start ); // Prevents sudden parallel startup if( m_running ) return; - Detach(); // clean up previous thread, if one exists. + Detach(); // clean up previous thread handle, if one exists. m_sem_finished.Reset(); + + OnStart(); + if( pthread_create( &m_thread, NULL, _internal_callback, this ) != 0 ) throw Exception::ThreadCreationError(); @@ -108,11 +129,12 @@ namespace Threading void PersistentThread::Cancel( bool isBlocking ) { wxASSERT( !IsSelf() ); - if( !m_running ) return; + + if( !m_running ) return; if( m_detached ) { - Console::Notice( "Threading Warning: Attempted to cancel detached thread; Ignoring..." ); + Console.Notice( "Threading Warning: Attempted to cancel detached thread; Ignoring..." ); return; } @@ -136,9 +158,9 @@ namespace Threading // Returns the return code of the thread. // This method is roughly the equivalent of pthread_join(). // - sptr PersistentThread::Block() + void PersistentThread::Block() { - DevAssert( !IsSelf(), "Thread deadlock detected; Block() should never be called by the owner thread." ); + pxAssertDev( !IsSelf(), "Thread deadlock detected; Block() should never be called by the owner thread." ); if( m_running ) #if wxUSE_GUI @@ -146,7 +168,6 @@ namespace Threading #else m_sem_finished.Wait(); #endif - return m_returncode; } bool PersistentThread::IsSelf() const @@ -159,18 +180,6 @@ namespace Threading return !!m_running; } - // Gets the return code of the thread. - // Exceptions: - // InvalidOperation - thrown if the thread is still running or has never been started. - // - sptr PersistentThread::GetReturnCode() const - { - if( IsRunning() ) - throw Exception::InvalidOperation( "Thread.GetReturnCode : thread is still running." ); - - return m_returncode; - } - // Throws an exception if the thread encountered one. Uses the BaseException's Rethrow() method, // which ensures the exception type remains consistent. Debuggable stacktraces will be lost, since // the thread will have allowed itself to terminate properly. @@ -180,10 +189,19 @@ namespace Threading m_except->Rethrow(); } - // invoked when canceling or exiting the thread. - void PersistentThread::DoThreadCleanup() + // invoked internally when canceling or exiting the thread. Extending classes should implement + // OnThreadCleanup() to extend clenup functionality. + void PersistentThread::_ThreadCleanup() { wxASSERT( IsSelf() ); // only allowed from our own thread, thanks. + + // Typically thread cleanup needs to lock against thread startup, since both + // will perform some measure of variable inits or resets, depending on how the + // derrived class is implemented. + ScopedLock startlock( m_lock_start ); + + OnThreadCleanup(); + m_running = false; m_sem_finished.Post(); } @@ -199,7 +217,7 @@ namespace Threading DoSetThreadName( m_name ); try { - m_returncode = ExecuteTask(); + ExecuteTask(); } catch( std::logic_error& ex ) { @@ -233,6 +251,9 @@ namespace Threading } } + void PersistentThread::OnStart() {} + void PersistentThread::OnThreadCleanup() {} + void* PersistentThread::_internal_callback( void* itsme ) { jASSUME( itsme != NULL ); @@ -241,12 +262,12 @@ namespace Threading pthread_cleanup_push( _pt_callback_cleanup, itsme ); owner._internal_execute(); pthread_cleanup_pop( true ); - return (void*)owner.m_returncode; + return NULL; } void PersistentThread::DoSetThreadName( const wxString& name ) { - DoSetThreadName( wxToUTF8(name) ); + DoSetThreadName( toUTF8(name) ); } void PersistentThread::DoSetThreadName( __unused const char* name ) @@ -292,12 +313,12 @@ namespace Threading // -------------------------------------------------------------------------------------- // Tells the thread to exit and then waits for thread termination. - sptr BaseTaskThread::Block() + void BaseTaskThread::Block() { - if( !IsRunning() ) return m_returncode; + if( !IsRunning() ) return; m_Done = true; m_sem_event.Post(); - return PersistentThread::Block(); + PersistentThread::Block(); } // Initiates the new task. This should be called after your own StartTask has @@ -326,7 +347,7 @@ namespace Threading m_post_TaskComplete.Reset(); } - sptr BaseTaskThread::ExecuteTask() + void BaseTaskThread::ExecuteTask() { while( !m_Done ) { @@ -340,7 +361,7 @@ namespace Threading m_lock_TaskComplete.Unlock(); }; - return 0; + return; } // -------------------------------------------------------------------------------------- diff --git a/common/src/Utilities/Windows/WinHostSys.cpp b/common/src/Utilities/Windows/WinHostSys.cpp index 33eacb643f..8edeb26651 100644 --- a/common/src/Utilities/Windows/WinHostSys.cpp +++ b/common/src/Utilities/Windows/WinHostSys.cpp @@ -13,7 +13,7 @@ * If not, see . */ -#include "../PrecompiledHeader.h" +#include "PrecompiledHeader.h" #include "Utilities/RedtapeWindows.h" #include diff --git a/common/src/Utilities/Windows/WinMisc.cpp b/common/src/Utilities/Windows/WinMisc.cpp index 1d5835859b..cabdd0bfe2 100644 --- a/common/src/Utilities/Windows/WinMisc.cpp +++ b/common/src/Utilities/Windows/WinMisc.cpp @@ -13,7 +13,7 @@ * If not, see . */ -#include "../PrecompiledHeader.h" +#include "PrecompiledHeader.h" #include "RedtapeWindows.h" #include "WinVersion.h" diff --git a/common/src/Utilities/Windows/WinThreads.cpp b/common/src/Utilities/Windows/WinThreads.cpp index 038e263dbb..7bccb2de49 100644 --- a/common/src/Utilities/Windows/WinThreads.cpp +++ b/common/src/Utilities/Windows/WinThreads.cpp @@ -13,7 +13,7 @@ * If not, see . */ -#include "../PrecompiledHeader.h" +#include "PrecompiledHeader.h" #include "RedtapeWindows.h" #include "x86emitter/tools.h" #include "Threading.h" diff --git a/common/src/Utilities/x86/MemcpyFast.cpp b/common/src/Utilities/x86/MemcpyFast.cpp index d66a26a3d5..078bab8ab7 100644 --- a/common/src/Utilities/x86/MemcpyFast.cpp +++ b/common/src/Utilities/x86/MemcpyFast.cpp @@ -31,7 +31,7 @@ 3dsdk.support@amd.com ******************************************************************************/ -#include "../PrecompiledHeader.h" +#include "PrecompiledHeader.h" #ifdef _MSC_VER #pragma warning(disable:4414) diff --git a/common/src/x86emitter/cpudetect.cpp b/common/src/x86emitter/cpudetect.cpp index 9218054bd8..cb2e528c6b 100644 --- a/common/src/x86emitter/cpudetect.cpp +++ b/common/src/x86emitter/cpudetect.cpp @@ -98,7 +98,7 @@ static void SetSingleAffinity() if( s_oldmask == ERROR_INVALID_PARAMETER ) { - Console::Notice( + Console.Notice( "CpuDetect: SetThreadAffinityMask failed...\n" "\tSystem Affinity : 0x%08x" "\tProcess Affinity: 0x%08x" @@ -354,7 +354,7 @@ void cpudetectInit() if( sse3_result != !!x86caps.hasStreamingSIMD3Extensions ) { - Console::Notice( "SSE3 Detection Inconsistency: cpuid=%s, test_result=%s", + Console.Notice( "SSE3 Detection Inconsistency: cpuid=%s, test_result=%s", bool_to_char( !!x86caps.hasStreamingSIMD3Extensions ), bool_to_char( sse3_result ) ); x86caps.hasStreamingSIMD3Extensions = sse3_result; @@ -362,7 +362,7 @@ void cpudetectInit() if( ssse3_result != !!x86caps.hasSupplementalStreamingSIMD3Extensions ) { - Console::Notice( "SSSE3 Detection Inconsistency: cpuid=%s, test_result=%s", + Console.Notice( "SSSE3 Detection Inconsistency: cpuid=%s, test_result=%s", bool_to_char( !!x86caps.hasSupplementalStreamingSIMD3Extensions ), bool_to_char( ssse3_result ) ); x86caps.hasSupplementalStreamingSIMD3Extensions = ssse3_result; @@ -370,7 +370,7 @@ void cpudetectInit() if( sse41_result != !!x86caps.hasStreamingSIMD4Extensions ) { - Console::Notice( "SSE4 Detection Inconsistency: cpuid=%s, test_result=%s", + Console.Notice( "SSE4 Detection Inconsistency: cpuid=%s, test_result=%s", bool_to_char( !!x86caps.hasStreamingSIMD4Extensions ), bool_to_char( sse41_result ) ); x86caps.hasStreamingSIMD4Extensions = sse41_result; @@ -379,7 +379,7 @@ void cpudetectInit() } else { - Console::Notice( + Console.Notice( "Notice: Could not allocate memory for SSE3/4 detection.\n" "\tRelying on CPUID results. [this is not an error]" ); diff --git a/common/src/x86emitter/legacy.cpp b/common/src/x86emitter/legacy.cpp index abf8a31a83..dedb8a2c4a 100644 --- a/common/src/x86emitter/legacy.cpp +++ b/common/src/x86emitter/legacy.cpp @@ -370,7 +370,7 @@ void x86SetJ8( u8* j8 ) u32 jump = ( x86Ptr - j8 ) - 1; if ( jump > 0x7f ) { - Console::Error( "j8 greater than 0x7f!!" ); + Console.Error( "j8 greater than 0x7f!!" ); assert(0); } *j8 = (u8)jump; @@ -381,7 +381,7 @@ void x86SetJ8A( u8* j8 ) u32 jump = ( x86Ptr - j8 ) - 1; if ( jump > 0x7f ) { - Console::Error( "j8 greater than 0x7f!!" ); + Console.Error( "j8 greater than 0x7f!!" ); assert(0); } diff --git a/common/src/x86emitter/tools.cpp b/common/src/x86emitter/tools.cpp index 46162c93e1..b7d119ebb5 100644 --- a/common/src/x86emitter/tools.cpp +++ b/common/src/x86emitter/tools.cpp @@ -40,14 +40,14 @@ __forceinline void FreezeMMXRegs(int save) { if( !g_EEFreezeRegs ) return; - //DevCon::Notice("FreezeMMXRegs_(%d); [%d]\n", save, g_globalMMXSaved); + //DevCon.Notice("FreezeMMXRegs_(%d); [%d]\n", save, g_globalMMXSaved); if( save ) { g_globalMMXSaved++; if( g_globalMMXSaved > 1 ) { - //DevCon::Notice("MMX Already Saved!\n"); + //DevCon.Notice("MMX Already Saved!\n"); return; } @@ -84,7 +84,7 @@ __forceinline void FreezeMMXRegs(int save) else { if( g_globalMMXSaved==0 ) { - //DevCon::Notice("MMX Not Saved!\n"); + //DevCon.Notice("MMX Not Saved!\n"); return; } g_globalMMXSaved--; @@ -129,13 +129,13 @@ __forceinline void FreezeXMMRegs(int save) { if( !g_EEFreezeRegs ) return; - //DevCon::Notice("FreezeXMMRegs_(%d); [%d]\n", save, g_globalXMMSaved); + //DevCon.Notice("FreezeXMMRegs_(%d); [%d]\n", save, g_globalXMMSaved); if( save ) { g_globalXMMSaved++; if( g_globalXMMSaved > 1 ){ - //DevCon::Notice("XMM Already saved\n"); + //DevCon.Notice("XMM Already saved\n"); return; } @@ -173,7 +173,7 @@ __forceinline void FreezeXMMRegs(int save) { if( g_globalXMMSaved==0 ) { - //DevCon::Notice("XMM Regs not saved!\n"); + //DevCon.Notice("XMM Regs not saved!\n"); return; } diff --git a/pcsx2/CDVD/CDVD.cpp b/pcsx2/CDVD/CDVD.cpp index dcb3255f4d..50fae6ab0a 100644 --- a/pcsx2/CDVD/CDVD.cpp +++ b/pcsx2/CDVD/CDVD.cpp @@ -84,11 +84,11 @@ FILE *_cdvdOpenMechaVer() fd = fopen(file.data(), "r+b"); if (fd == NULL) { - Console::Notice("MEC File Not Found , Creating Blank File"); + Console.Notice("MEC File Not Found , Creating Blank File"); fd = fopen(file.data(), "wb"); if (fd == NULL) { - Console::Error( "\tMEC File Creation failed!" ); + Console.Error( "\tMEC File Creation failed!" ); throw Exception::CreateStream( file ); //Msgbox::Alert( "_cdvdOpenMechaVer: Error creating %s", file); //exit(1); @@ -124,11 +124,11 @@ FILE *_cdvdOpenNVM() fd = fopen(file.data(), "r+b"); if (fd == NULL) { - Console::Notice("NVM File Not Found , Creating Blank File"); + Console.Notice("NVM File Not Found , Creating Blank File"); fd = fopen(file.data(), "wb"); if (fd == NULL) { - Console::Error( "\tMEC File Creation failed!" ); + Console.Error( "\tMEC File Creation failed!" ); throw Exception::CreateStream( file ); } for (int i=0; i<1024; i++) fputc(0, fd); @@ -314,7 +314,7 @@ void cdvdReadKey(u8 arg0, u16 arg1, u32 arg2, u8* key) { const wxCharBuffer crap( fname.ToAscii() ); const char* str = crap.data(); 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", &str[8]); + DevCon.Notice("exeName = %s", &str[8]); // convert the number characters to a real 32bit number numbers = ((((exeName[5] - '0'))*10000) + @@ -369,7 +369,7 @@ void cdvdReadKey(u8 arg0, u16 arg1, u32 arg2, u8* key) { key[15] = 0x01; } - Console::WriteLn( "CDVD.KEY = %02X,%02X,%02X,%02X,%02X,%02X,%02X", + Console.WriteLn( "CDVD.KEY = %02X,%02X,%02X,%02X,%02X,%02X,%02X", 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... @@ -622,7 +622,7 @@ int cdvdReadSector() { // be more correct. (air) psxCpu->Clear( HW_DMA3_MADR, cdvd.BlockSize/4 ); -// Console::WriteLn("sector %x;%x;%x", PSXMu8(madr+0), PSXMu8(madr+1), PSXMu8(madr+2)); +// Console.WriteLn("sector %x;%x;%x", PSXMu8(madr+0), PSXMu8(madr+1), PSXMu8(madr+2)); HW_DMA3_BCR_H16 -= (cdvd.BlockSize / (HW_DMA3_BCR_L16*4)); HW_DMA3_MADR += cdvd.BlockSize; @@ -670,7 +670,7 @@ __forceinline void cdvdActionInterrupt() // inlined due to being referenced in only one place. __forceinline void cdvdReadInterrupt() { - //Console::WriteLn("cdvdReadInterrupt %x %x %x %x %x", cpuRegs.interrupt, cdvd.Readed, cdvd.Reading, cdvd.nSectors, (HW_DMA3_BCR_H16 * HW_DMA3_BCR_L16) *4); + //Console.WriteLn("cdvdReadInterrupt %x %x %x %x %x", cpuRegs.interrupt, cdvd.Readed, cdvd.Reading, cdvd.nSectors, (HW_DMA3_BCR_H16 * HW_DMA3_BCR_L16) *4); cdvd.Ready = CDVD_NOTREADY; if (!cdvd.Readed) @@ -717,7 +717,7 @@ __forceinline void cdvdReadInterrupt() CDVDREAD_INT(cdvd.ReadTime); } else - Console::Error("CDVD READ ERROR, sector = 0x%08x", cdvd.Sector); + Console.Error("CDVD READ ERROR, sector = 0x%08x", cdvd.Sector); return; } @@ -1011,14 +1011,14 @@ u8 cdvdRead(u8 key) case 0x3A: // DEC_SET CDR_LOG("cdvdRead3A(DecSet) %x", cdvd.decSet); - Console::WriteLn("DecSet Read: %02X", cdvd.decSet); + Console.WriteLn("DecSet Read: %02X", 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); - Console::Error( "IOP Unknown 8bit read from addr 0x1f4020%x", key ); + Console.Error( "IOP Unknown 8bit read from addr 0x1f4020%x", key ); return 0; break; } @@ -1042,14 +1042,14 @@ static void cdvdWrite04(u8 rt) { // NCOMMAND // Seek to sector zero. The cdvdStartSeek function will simulate // spinup times if needed. - DevCon::Notice( "CdStandby : %d", rt ); + DevCon.Notice( "CdStandby : %d", rt ); cdvd.Action = cdvdAction_Standby; cdvd.ReadTime = cdvdBlockReadTime( MODE_DVDROM ); CDVD_INT( cdvdStartSeek( 0, MODE_DVDROM ) ); break; case N_CD_STOP: // CdStop - DevCon::Notice( "CdStop : %d", rt ); + DevCon.Notice( "CdStop : %d", rt ); cdvd.Action = cdvdAction_Stop; CDVD_INT( PSXCLK / 6 ); // 166ms delay? break; @@ -1083,7 +1083,7 @@ static void cdvdWrite04(u8 rt) { // NCOMMAND cdvd.Sector, cdvd.nSectors, cdvd.RetryCnt, cdvd.Speed, cdvd.Param[9], cdvd.ReadMode, cdvd.Param[10], psxHu32(0x1074)); if( EmuConfig.CdvdVerboseReads ) - Console::WriteLn("CdRead: Reading Sector %d(%d Blocks of Size %d) at Speed=%dx", + Console.WriteLn("CdRead: Reading Sector %d(%d Blocks of Size %d) at Speed=%dx", cdvd.Sector, cdvd.nSectors,cdvd.BlockSize,cdvd.Speed); cdvd.ReadTime = cdvdBlockReadTime( MODE_CDROM ); @@ -1131,7 +1131,7 @@ static void cdvdWrite04(u8 rt) { // NCOMMAND cdvd.Sector, cdvd.nSectors, cdvd.RetryCnt, cdvd.Speed, cdvd.Param[9], cdvd.ReadMode, cdvd.Param[10], psxHu32(0x1074)); if( EmuConfig.CdvdVerboseReads ) - Console::WriteLn("CdAudioRead: Reading Sector %d(%d Blocks of Size %d) at Speed=%dx", + Console.WriteLn("CdAudioRead: Reading Sector %d(%d Blocks of Size %d) at Speed=%dx", cdvd.Sector, cdvd.nSectors,cdvd.BlockSize,cdvd.Speed); cdvd.ReadTime = cdvdBlockReadTime( MODE_CDROM ); @@ -1167,7 +1167,7 @@ static void cdvdWrite04(u8 rt) { // NCOMMAND cdvd.Sector, cdvd.nSectors, cdvd.RetryCnt, cdvd.Speed, cdvd.Param[9], cdvd.ReadMode, cdvd.Param[10], psxHu32(0x1074)); if( EmuConfig.CdvdVerboseReads ) - Console::WriteLn("DvdRead: Reading Sector %d(%d Blocks of Size %d) at Speed=%dx", + Console.WriteLn("DvdRead: Reading Sector %d(%d Blocks of Size %d) at Speed=%dx", cdvd.Sector, cdvd.nSectors,cdvd.BlockSize,cdvd.Speed); cdvd.ReadTime = cdvdBlockReadTime( MODE_DVDROM ); @@ -1189,7 +1189,7 @@ static void cdvdWrite04(u8 rt) { // NCOMMAND //the code below handles only CdGetToc! //if(cdvd.Param[0]==0x01) //{ - DevCon::WriteLn("CDGetToc Param[0]=%d, Param[1]=%d", cdvd.Param[0],cdvd.Param[1]); + DevCon.WriteLn("CDGetToc Param[0]=%d, Param[1]=%d", cdvd.Param[0],cdvd.Param[1]); //} cdvdGetToc( iopPhysMem( HW_DMA3_MADR ) ); cdvdSetIrq( (1<> 0) & 0xFF; @@ -1882,11 +1882,11 @@ static void cdvdWrite16(u8 rt) // SCOMMAND // fake a 'correct' command SetResultSize(1); //in:0 cdvd.Result[0] = 0; // 0 complete ; 1 busy ; 0x80 error - Console::WriteLn("SCMD Unknown %x", rt); + Console.WriteLn("SCMD Unknown %x", rt); break; } // end switch - //Console::WriteLn("SCMD - 0x%x\n", rt); + //Console.WriteLn("SCMD - 0x%x\n", rt); cdvd.ParamP = 0; cdvd.ParamC = 0; } @@ -1902,13 +1902,13 @@ static __forceinline void cdvdWrite17(u8 rt) { // SDATAIN static __forceinline void cdvdWrite18(u8 rt) { // SDATAOUT CDR_LOG("cdvdWrite18(SDataOut) %x", rt); - Console::WriteLn("*PCSX2* SDATAOUT"); + Console.WriteLn("*PCSX2* SDATAOUT"); } static __forceinline void cdvdWrite3A(u8 rt) { // DEC-SET CDR_LOG("cdvdWrite3A(DecSet) %x", rt); cdvd.decSet = rt; - Console::WriteLn("DecSet Write: %02X", cdvd.decSet); + Console.WriteLn("DecSet Write: %02X", cdvd.decSet); } void cdvdWrite(u8 key, u8 rt) @@ -1928,7 +1928,7 @@ void cdvdWrite(u8 key, u8 rt) case 0x18: cdvdWrite18(rt); break; case 0x3A: cdvdWrite3A(rt); break; default: - Console::Notice("IOP Unknown 8bit write to addr 0x1f4020%x = 0x%x", key, rt); + Console.Notice("IOP Unknown 8bit write to addr 0x1f4020%x = 0x%x", key, rt); break; } } diff --git a/pcsx2/CDVD/CDVDaccess.cpp b/pcsx2/CDVD/CDVDaccess.cpp index a808f2924d..c731279692 100644 --- a/pcsx2/CDVD/CDVDaccess.cpp +++ b/pcsx2/CDVD/CDVDaccess.cpp @@ -61,7 +61,7 @@ static isoFile *blockDumpFile = NULL; // relying on DEP exceptions -- and a little more reliable too. static void CheckNullCDVD() { - DevAssert( CDVD != NULL, "Invalid CDVD object state (null pointer exception)" ); + pxAssertDev( CDVD != NULL, "Invalid CDVD object state (null pointer exception)" ); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -159,15 +159,15 @@ static int FindDiskType(int mType) switch(iCDType) { case CDVD_TYPE_DETCTCD: - Console::Status(" * CDVD Disk Open: CD, %d tracks (%d to %d):", tn.etrack-tn.strack+1,tn.strack,tn.etrack); + Console.Status(" * CDVD Disk Open: CD, %d tracks (%d to %d):", tn.etrack-tn.strack+1,tn.strack,tn.etrack); break; case CDVD_TYPE_DETCTDVDS: - Console::Status(" * CDVD Disk Open: DVD, Single layer or unknown:"); + Console.Status(" * CDVD Disk Open: DVD, Single layer or unknown:"); break; case CDVD_TYPE_DETCTDVDD: - Console::Status(" * CDVD Disk Open: DVD, Double layer:"); + Console.Status(" * CDVD Disk Open: DVD, Double layer:"); break; } @@ -188,12 +188,12 @@ static int FindDiskType(int mType) if (td.type == CDVD_AUDIO_TRACK) { audioTracks++; - Console::Status(" * * Track %d: Audio (%d sectors)", i,tlength); + Console.Status(" * * Track %d: Audio (%d sectors)", i,tlength); } else { dataTracks++; - Console::Status(" * * Track %d: Data (Mode %d) (%d sectors)", i,((td.type==CDVD_MODE1_TRACK)?1:2),tlength); + Console.Status(" * * Track %d: Data (Mode %d) (%d sectors)", i,((td.type==CDVD_MODE1_TRACK)?1:2),tlength); } } @@ -402,7 +402,7 @@ s32 DoCDVDreadTrack(u32 lsn, int mode) break; } - //DevCon::Notice("CDVD readTrack(lsn=%d,mode=%d)",params lsn, lastReadSize); + //DevCon.Notice("CDVD readTrack(lsn=%d,mode=%d)",params lsn, lastReadSize); lastLSN = lsn; return CDVD->readTrack(lsn,mode); } diff --git a/pcsx2/CDVD/CDVDisoReader.cpp b/pcsx2/CDVD/CDVDisoReader.cpp index 4220f4ed96..6510015f9d 100644 --- a/pcsx2/CDVD/CDVDisoReader.cpp +++ b/pcsx2/CDVD/CDVDisoReader.cpp @@ -45,14 +45,14 @@ s32 CALLBACK ISOopen(const char* pTitle) if( (pTitle == NULL) || (pTitle[0] == 0) ) { - Console::Error( "CDVDiso Error: No filename specified." ); + Console.Error( "CDVDiso Error: No filename specified." ); return -1; } iso = isoOpen(pTitle); if (iso == NULL) { - Console::Error( "CDVDiso Error: Failed loading %s", pTitle ); + Console.Error( "CDVDiso Error: Failed loading %s", pTitle ); return -1; } @@ -128,7 +128,7 @@ static void FindLayer1Start() int off = iso->blockofs; u8 tempbuffer[CD_FRAMESIZE_RAW]; - Console::Status("CDVDiso: searching for layer1..."); + Console.Status("CDVDiso: searching for layer1..."); //tempbuffer = (u8*)malloc(CD_FRAMESIZE_RAW); for (layer1start = (iso->blocks / 2 - 0x10) & ~0xf; layer1start < 0x200010; layer1start += 16) { @@ -146,12 +146,12 @@ static void FindLayer1Start() if(layer1start == 0x200010) { - Console::Status("\tCouldn't find second layer on dual layer... ignoring"); + Console.Status("\tCouldn't find second layer on dual layer... ignoring"); layer1start=-2; } if(layer1start>=0) - Console::Status("\tfound at 0x%8.8x", layer1start); + Console.Status("\tfound at 0x%8.8x", layer1start); } } diff --git a/pcsx2/CDVD/CdRom.cpp b/pcsx2/CDVD/CdRom.cpp index de495259eb..5fffdb7e01 100644 --- a/pcsx2/CDVD/CdRom.cpp +++ b/pcsx2/CDVD/CdRom.cpp @@ -943,7 +943,7 @@ s32 cdvdDmaRead(s32 channel, u32* data, u32 wordsLeft, u32* wordsProcessed) cdr.pTransfer+=wordsLeft; *wordsProcessed = wordsLeft; - Console::Status("New IOP DMA handled CDVD DMA: channel %d, data %p, remaining %08x, processed %08x.", channel,data,wordsLeft, *wordsProcessed); + Console.Status("New IOP DMA handled CDVD DMA: channel %d, data %p, remaining %08x, processed %08x.", channel,data,wordsLeft, *wordsProcessed); return 0; } diff --git a/pcsx2/CDVD/IsoFStools.cpp b/pcsx2/CDVD/IsoFStools.cpp index a0998ba950..af0c32aa2d 100644 --- a/pcsx2/CDVD/IsoFStools.cpp +++ b/pcsx2/CDVD/IsoFStools.cpp @@ -184,7 +184,7 @@ int IsoFS_getVolumeDescriptor(void) s32 volDescSector; cdVolDesc localVolDesc; - DbgCon::WriteLn("IsoFS_GetVolumeDescriptor called"); + DbgCon.WriteLn("IsoFS_GetVolumeDescriptor called"); for (volDescSector = 16; volDescSector<20; volDescSector++) { @@ -205,11 +205,11 @@ int IsoFS_getVolumeDescriptor(void) } if (CDVolDesc.filesystemType == 1) - DbgCon::WriteLn( Color_Green, "CD FileSystem is ISO9660" ); + DbgCon.WriteLn( Color_Green, "CD FileSystem is ISO9660" ); else if (CDVolDesc.filesystemType == 2) - DbgCon::WriteLn( Color_Green, "CD FileSystem is Joliet"); + DbgCon.WriteLn( Color_Green, "CD FileSystem is Joliet"); else - DbgCon::Notice("Could not detect CD FileSystem type"); + DbgCon.Notice("Could not detect CD FileSystem type"); // CdStop(); @@ -223,7 +223,7 @@ int IsoFS_findFile(const char* fname, TocEntry* tocEntry){ dirTocEntry* tocEntryPointer; TocEntry localTocEntry; // used for internal checking only - DbgCon::WriteLn("IsoFS_findfile(\"%s\") called", fname); + DbgCon.WriteLn("IsoFS_findfile(\"%s\") called", fname); _splitpath2(fname, pathname, filename); @@ -297,7 +297,7 @@ int IsoFS_findFile(const char* fname, TocEntry* tocEntry){ current_sector++; if (IsoFS_readSectors(current_sector,1,toc) != TRUE) { - Console::Error("Couldn't Read from CD !"); + Console.Error("Couldn't Read from CD !"); return -1; } // CdSync(0x00); @@ -333,7 +333,7 @@ int IsoFS_findFile(const char* fname, TocEntry* tocEntry){ // If we havent found the directory name we wanted then fail if (found_dir != TRUE) { - Console::Notice( "IsoFS_findfile: could not find dir" ); + Console.Notice( "IsoFS_findfile: could not find dir" ); return -1; } @@ -343,7 +343,7 @@ int IsoFS_findFile(const char* fname, TocEntry* tocEntry){ // Read the TOC of the found subdirectory if (IsoFS_readSectors(localTocEntry.fileLBA,1,toc) != TRUE) { - Console::Error("Couldn't Read from CD !"); + Console.Error("Couldn't Read from CD !"); return -1; } // CdSync(0x00); @@ -388,7 +388,7 @@ int IsoFS_findFile(const char* fname, TocEntry* tocEntry){ strcpy(tocEntry->filename, localTocEntry.filename); memcpy(tocEntry->date, localTocEntry.date, 7); - DbgCon::WriteLn("IsoFS_findfile: found file"); + DbgCon.WriteLn("IsoFS_findfile: found file"); return TRUE; } @@ -403,7 +403,7 @@ int IsoFS_findFile(const char* fname, TocEntry* tocEntry){ dir_lba++; if (IsoFS_readSectors(dir_lba,1,toc) != TRUE){ - Console::Error("Couldn't Read from CD !"); + Console.Error("Couldn't Read from CD !"); return -1; } // CdSync(0x00); @@ -412,7 +412,7 @@ int IsoFS_findFile(const char* fname, TocEntry* tocEntry){ } } - DbgCon::Notice("IsoFS_findfile: could not find file"); + DbgCon.Notice("IsoFS_findfile: could not find file"); return FALSE; } diff --git a/pcsx2/CDVD/IsoFileFormats.cpp b/pcsx2/CDVD/IsoFileFormats.cpp index 098d45cf25..8bf9c560b8 100644 --- a/pcsx2/CDVD/IsoFileFormats.cpp +++ b/pcsx2/CDVD/IsoFileFormats.cpp @@ -137,13 +137,13 @@ isoFile *isoOpen(const char *filename) iso->handle = _openfile( iso->filename, O_RDONLY); if (iso->handle == NULL) { - Console::Error("error loading %s", iso->filename); + Console.Error("error loading %s", iso->filename); return NULL; } if (isoDetect(iso) == -1) return NULL; - Console::WriteLn("detected blocksize = %d", iso->blocksize); + Console.WriteLn("detected blocksize = %d", iso->blocksize); if ((strlen(iso->filename) > 3) && strncmp(iso->filename + (strlen(iso->filename) - 3), "I00", 3) == 0) { @@ -181,12 +181,12 @@ isoFile *isoOpen(const char *filename) iso->blocks = (u32)((_tellfile(iso->handle) - iso->offset) / (iso->blocksize)); } - Console::WriteLn("isoOpen: %s ok", iso->filename); - Console::WriteLn("offset = %d", iso->offset); - Console::WriteLn("blockofs = %d", iso->blockofs); - Console::WriteLn("blocksize = %d", iso->blocksize); - Console::WriteLn("blocks = %d", iso->blocks); - Console::WriteLn("type = %d", iso->type); + Console.WriteLn("isoOpen: %s ok", iso->filename); + Console.WriteLn("offset = %d", iso->offset); + Console.WriteLn("blockofs = %d", iso->blockofs); + Console.WriteLn("blocksize = %d", iso->blocksize); + Console.WriteLn("blocks = %d", iso->blocks); + Console.WriteLn("type = %d", iso->type); return iso; } @@ -219,12 +219,12 @@ isoFile *isoCreate(const char *filename, int flags) if (iso->handle == NULL) { - Console::Error("Error loading %s", iso->filename); + Console.Error("Error loading %s", iso->filename); return NULL; } - Console::WriteLn("isoCreate: %s ok", iso->filename); - Console::WriteLn("offset = %d", iso->offset); + Console.WriteLn("isoCreate: %s ok", iso->filename); + Console.WriteLn("offset = %d", iso->offset); return iso; } @@ -235,9 +235,9 @@ int isoSetFormat(isoFile *iso, int blockofs, int blocksize, int blocks) iso->blocks = blocks; iso->blockofs = blockofs; - Console::WriteLn("blockofs = %d", iso->blockofs); - Console::WriteLn("blocksize = %d", iso->blocksize); - Console::WriteLn("blocks = %d", iso->blocks); + Console.WriteLn("blockofs = %d", iso->blockofs); + Console.WriteLn("blocksize = %d", iso->blocksize); + Console.WriteLn("blocks = %d", iso->blocks); if (iso->flags & ISOFLAGS_BLOCKDUMP_V2) { @@ -292,7 +292,7 @@ int _isoReadBlock(isoFile *iso, u8 *dst, int lsn) if (ret < iso->blocksize) { - Console::Error("read error %d in _isoReadBlock", ret); + Console.Error("read error %d in _isoReadBlock", ret); return -1; } @@ -303,7 +303,7 @@ int _isoReadBlockD(isoFile *iso, u8 *dst, int lsn) { int ret; -// Console::WriteLn("_isoReadBlockD %d, blocksize=%d, blockofs=%d\n", lsn, iso->blocksize, iso->blockofs); +// Console.WriteLn("_isoReadBlockD %d, blocksize=%d, blockofs=%d\n", lsn, iso->blocksize, iso->blockofs); memset(dst, 0, iso->blockofs); for (int i = 0; i < iso->dtablesize; i++) @@ -317,7 +317,7 @@ int _isoReadBlockD(isoFile *iso, u8 *dst, int lsn) return 0; } - Console::WriteLn("Block %d not found in dump", lsn); + Console.WriteLn("Block %d not found in dump", lsn); return -1; } @@ -339,7 +339,7 @@ int _isoReadBlockM(isoFile *iso, u8 *dst, int lsn) ofs = (u64)(lsn - iso->multih[i].slsn) * iso->blocksize + iso->offset; -// Console::WriteLn("_isoReadBlock %d, blocksize=%d, blockofs=%d\n", lsn, iso->blocksize, iso->blockofs); +// Console.WriteLn("_isoReadBlock %d, blocksize=%d, blockofs=%d\n", lsn, iso->blocksize, iso->blockofs); memset(dst, 0, iso->blockofs); _seekfile(iso->multih[i].handle, ofs, SEEK_SET); @@ -347,7 +347,7 @@ int _isoReadBlockM(isoFile *iso, u8 *dst, int lsn) if (ret < iso->blocksize) { - Console::WriteLn("read error %d in _isoReadBlockM", ret); + Console.WriteLn("read error %d in _isoReadBlockM", ret); return -1; } @@ -360,7 +360,7 @@ int isoReadBlock(isoFile *iso, u8 *dst, int lsn) if (lsn > iso->blocks) { - Console::WriteLn("isoReadBlock: %d > %d", lsn, iso->blocks); + Console.WriteLn("isoReadBlock: %d > %d", lsn, iso->blocks); return -1; } @@ -401,13 +401,13 @@ int _isoWriteBlockD(isoFile *iso, u8 *src, int lsn) { int ret; -// Console::WriteLn("_isoWriteBlock %d (ofs=%d)", iso->blocksize, ofs); +// Console.WriteLn("_isoWriteBlock %d (ofs=%d)", iso->blocksize, ofs); ret = _writefile(iso->handle, &lsn, 4); if (ret < 4) return -1; ret = _writefile(iso->handle, src + iso->blockofs, iso->blocksize); -// Console::WriteLn("_isoWriteBlock %d", ret); +// Console.WriteLn("_isoWriteBlock %d", ret); if (ret < iso->blocksize) return -1; diff --git a/pcsx2/CDVD/IsoFileTools.cpp b/pcsx2/CDVD/IsoFileTools.cpp index 538b180d33..c58af81717 100644 --- a/pcsx2/CDVD/IsoFileTools.cpp +++ b/pcsx2/CDVD/IsoFileTools.cpp @@ -23,7 +23,7 @@ void *_openfile(const char *filename, int flags) { HANDLE handle; -// Console::WriteLn("_openfile %s, %d", filename, flags & O_RDONLY); +// Console.WriteLn("_openfile %s, %d", filename, flags & O_RDONLY); if (flags & O_WRONLY) { int _flags = CREATE_NEW; @@ -52,7 +52,7 @@ int _seekfile(void *handle, u64 offset, int whence) u64 ofs = (u64)offset; PLONG _ofs = (LONG*) & ofs; -// Console::WriteLn("_seekfile %p, %d_%d", handle, _ofs[1], _ofs[0]); +// Console.WriteLn("_seekfile %p, %d_%d", handle, _ofs[1], _ofs[0]); SetFilePointer(handle, _ofs[0], &_ofs[1], (whence == SEEK_SET) ? FILE_BEGIN : FILE_END); @@ -64,7 +64,7 @@ int _readfile(void *handle, void *dst, int size) DWORD ret; ReadFile(handle, dst, size, &ret, NULL); -// Console::WriteLn("_readfile(%p, %d) = %d; %d", handle, size, ret, GetLastError()); +// Console.WriteLn("_readfile(%p, %d) = %d; %d", handle, size, ret, GetLastError()); return ret; } @@ -74,7 +74,7 @@ int _writefile(void *handle, const void *src, int size) // _seekfile(handle, _tellfile(handle)); WriteFile(handle, src, size, &ret, NULL); -// Console::WriteLn("_readfile(%p, %d) = %d", handle, size, ret); +// Console.WriteLn("_readfile(%p, %d) = %d", handle, size, ret); return ret; } @@ -87,7 +87,7 @@ void _closefile(void *handle) void *_openfile(const char *filename, int flags) { -// Console::WriteLn("_openfile %s %x", filename, flags); +// Console.WriteLn("_openfile %s %x", filename, flags); if (flags & O_WRONLY) return fopen64(filename, "wb"); @@ -117,7 +117,7 @@ int _seekfile(void *handle, u64 offset, int whence) { int seekerr = fseeko64((FILE*)handle, offset, whence); - if (seekerr == -1) Console::Error("Failed to seek."); + if (seekerr == -1) Console.Error("Failed to seek."); return seekerr; } diff --git a/pcsx2/COP0.cpp b/pcsx2/COP0.cpp index 696cadb12d..d061a0f193 100644 --- a/pcsx2/COP0.cpp +++ b/pcsx2/COP0.cpp @@ -48,12 +48,12 @@ void MapTLB(int i) u32 mask, addr; u32 saddr, eaddr; - DevCon::WriteLn("MAP TLB %d: %08x-> [%08x %08x] S=%d G=%d ASID=%d Mask= %03X", + DevCon.WriteLn("MAP TLB %d: %08x-> [%08x %08x] S=%d G=%d ASID=%d Mask= %03X", i,tlb[i].VPN2,tlb[i].PFN0,tlb[i].PFN1,tlb[i].S,tlb[i].G,tlb[i].ASID,tlb[i].Mask); if (tlb[i].S) { - DevCon::WriteLn("OMG SPRAM MAPPING %08X %08X\n", tlb[i].VPN2,tlb[i].Mask); + DevCon.WriteLn("OMG SPRAM MAPPING %08X %08X\n", tlb[i].VPN2,tlb[i].Mask); vtlb_VMapBuffer(tlb[i].VPN2, psS, 0x4000); } @@ -88,7 +88,7 @@ void MapTLB(int i) void UnmapTLB(int i) { - //Console::WriteLn("Clear TLB %d: %08x-> [%08x %08x] S=%d G=%d ASID=%d Mask= %03X", i,tlb[i].VPN2,tlb[i].PFN0,tlb[i].PFN1,tlb[i].S,tlb[i].G,tlb[i].ASID,tlb[i].Mask); + //Console.WriteLn("Clear TLB %d: %08x-> [%08x %08x] S=%d G=%d ASID=%d Mask= %03X", i,tlb[i].VPN2,tlb[i].PFN0,tlb[i].PFN1,tlb[i].S,tlb[i].G,tlb[i].ASID,tlb[i].Mask); u32 mask, addr; u32 saddr, eaddr; @@ -103,7 +103,7 @@ void UnmapTLB(int i) mask = ((~tlb[i].Mask) << 1) & 0xfffff; saddr = tlb[i].VPN2 >> 12; eaddr = saddr + tlb[i].Mask + 1; - // Console::WriteLn("Clear TLB: %08x ~ %08x",saddr,eaddr-1); + // Console.WriteLn("Clear TLB: %08x ~ %08x",saddr,eaddr-1); for (addr=saddr; addr> 12) & mask)) { //match memClearPageAddr(addr << 12); @@ -116,7 +116,7 @@ void UnmapTLB(int i) mask = ((~tlb[i].Mask) << 1) & 0xfffff; saddr = (tlb[i].VPN2 >> 12) + tlb[i].Mask + 1; eaddr = saddr + tlb[i].Mask + 1; - // Console::WriteLn("Clear TLB: %08x ~ %08x",saddr,eaddr-1); + // Console.WriteLn("Clear TLB: %08x ~ %08x",saddr,eaddr-1); for (addr=saddr; addr> 12) & mask)) { //match memClearPageAddr(addr << 12); @@ -210,10 +210,10 @@ static __forceinline bool PERF_ShouldCountEvent( uint evt ) void COP0_DiagnosticPCCR() { if( cpuRegs.PERF.n.pccr.b.Event0 >= 7 && cpuRegs.PERF.n.pccr.b.Event0 <= 10 ) - Console::Notice( "PERF/PCR0 Unsupported Update Event Mode = 0x%x", cpuRegs.PERF.n.pccr.b.Event0 ); + Console.Notice( "PERF/PCR0 Unsupported Update Event Mode = 0x%x", cpuRegs.PERF.n.pccr.b.Event0 ); if( cpuRegs.PERF.n.pccr.b.Event1 >= 7 && cpuRegs.PERF.n.pccr.b.Event1 <= 10 ) - Console::Notice( "PERF/PCR1 Unsupported Update Event Mode = 0x%x", cpuRegs.PERF.n.pccr.b.Event1 ); + Console.Notice( "PERF/PCR1 Unsupported Update Event Mode = 0x%x", cpuRegs.PERF.n.pccr.b.Event1 ); } extern int branch; __forceinline void COP0_UpdatePCCR() @@ -337,7 +337,7 @@ void MFC0() if ((_Rd_ != 9) && !_Rt_ ) return; if (_Rd_ != 9) { COP0_LOG("%s", disR5900Current.getCString() ); } - //if(bExecBIOS == FALSE && _Rd_ == 25) Console::WriteLn("MFC0 _Rd_ %x = %x", _Rd_, cpuRegs.CP0.r[_Rd_]); + //if(bExecBIOS == FALSE && _Rd_ == 25) Console.WriteLn("MFC0 _Rd_ %x = %x", _Rd_, cpuRegs.CP0.r[_Rd_]); switch (_Rd_) { case 12: @@ -361,12 +361,12 @@ void MFC0() cpuRegs.GPR.r[_Rt_].SD[0] = (s32)cpuRegs.PERF.n.pcr1; break; } - /*Console::WriteLn("MFC0 PCCR = %x PCR0 = %x PCR1 = %x IMM= %x", params + /*Console.WriteLn("MFC0 PCCR = %x PCR0 = %x PCR1 = %x IMM= %x", params cpuRegs.PERF.n.pccr, cpuRegs.PERF.n.pcr0, cpuRegs.PERF.n.pcr1, _Imm_ & 0x3F);*/ break; case 24: - Console::WriteLn("MFC0 Breakpoint debug Registers code = %x", cpuRegs.code & 0x3FF); + Console.WriteLn("MFC0 Breakpoint debug Registers code = %x", cpuRegs.code & 0x3FF); break; case 9: @@ -386,7 +386,7 @@ void MFC0() void MTC0() { COP0_LOG("%s\n", disR5900Current.getCString()); - //if(bExecBIOS == FALSE && _Rd_ == 25) Console::WriteLn("MTC0 _Rd_ %x = %x", _Rd_, cpuRegs.CP0.r[_Rd_]); + //if(bExecBIOS == FALSE && _Rd_ == 25) Console.WriteLn("MTC0 _Rd_ %x = %x", _Rd_, cpuRegs.CP0.r[_Rd_]); switch (_Rd_) { case 9: @@ -399,11 +399,11 @@ void MTC0() break; case 24: - Console::WriteLn("MTC0 Breakpoint debug Registers code = %x", cpuRegs.code & 0x3FF); + Console.WriteLn("MTC0 Breakpoint debug Registers code = %x", cpuRegs.code & 0x3FF); break; case 25: - /*if(bExecBIOS == FALSE && _Rd_ == 25) Console::WriteLn("MTC0 PCCR = %x PCR0 = %x PCR1 = %x IMM= %x", params + /*if(bExecBIOS == FALSE && _Rd_ == 25) Console.WriteLn("MTC0 PCCR = %x PCR0 = %x PCR1 = %x IMM= %x", params cpuRegs.PERF.n.pccr, cpuRegs.PERF.n.pcr0, cpuRegs.PERF.n.pcr1, _Imm_ & 0x3F);*/ switch(_Imm_ & 0x3F) { diff --git a/pcsx2/COP2.cpp b/pcsx2/COP2.cpp index 560e468fd8..99faa3714b 100644 --- a/pcsx2/COP2.cpp +++ b/pcsx2/COP2.cpp @@ -42,7 +42,7 @@ void BC2F() { if (CP2COND == 0) { - Console::WriteLn("VU0 Macro Branch"); + Console.WriteLn("VU0 Macro Branch"); intDoBranch(_BranchTarget_); } } @@ -50,7 +50,7 @@ void BC2T() { if (CP2COND == 1) { - Console::WriteLn("VU0 Macro Branch"); + Console.WriteLn("VU0 Macro Branch"); intDoBranch(_BranchTarget_); } } @@ -59,7 +59,7 @@ void BC2FL() { if (CP2COND == 0) { - Console::WriteLn("VU0 Macro Branch"); + Console.WriteLn("VU0 Macro Branch"); intDoBranch(_BranchTarget_); } else @@ -71,7 +71,7 @@ void BC2TL() { if (CP2COND == 1) { - Console::WriteLn("VU0 Macro Branch"); + Console.WriteLn("VU0 Macro Branch"); intDoBranch(_BranchTarget_); } else diff --git a/pcsx2/Config.h b/pcsx2/Config.h index 5fa9963a92..39704bf8ac 100644 --- a/pcsx2/Config.h +++ b/pcsx2/Config.h @@ -295,11 +295,7 @@ public: void Save( const wxString& dstfile ); void Save( const wxOutputStream& deststream ); - bool MultitapEnabled( uint port ) const - { - wxASSERT( port < 2 ); - return (port==0) ? MultitapPort0_Enabled : MultitapPort1_Enabled; - } + bool MultitapEnabled( uint port ) const; bool operator ==( const Pcsx2Config& right ) const { diff --git a/pcsx2/Counters.cpp b/pcsx2/Counters.cpp index f5e5be2633..0438153506 100644 --- a/pcsx2/Counters.cpp +++ b/pcsx2/Counters.cpp @@ -256,7 +256,7 @@ u32 UpdateVSyncRate() { m_iTicks = ticks; gsOnModeChanged( vSyncInfo.Framerate, m_iTicks ); - Console::Status( limiterMsg, EmuConfig.Video.FpsLimit, 0 ); + Console.Status( limiterMsg, EmuConfig.Video.FpsLimit, 0 ); } } else @@ -266,7 +266,7 @@ u32 UpdateVSyncRate() { m_iTicks = ticks; gsOnModeChanged( vSyncInfo.Framerate, m_iTicks ); - Console::Status( limiterMsg, vSyncInfo.Framerate/50, (vSyncInfo.Framerate*2)%100 ); + Console.Status( limiterMsg, vSyncInfo.Framerate/50, (vSyncInfo.Framerate*2)%100 ); } } @@ -476,7 +476,7 @@ __forceinline void rcntUpdate_vSync() if( vblankinc > 1 ) { if( hsc != vSyncInfo.hScanlinesPerFrame ) - Console::WriteLn( " ** vSync > Abnormal Scanline Count: %d", hsc ); + Console.WriteLn( " ** vSync > Abnormal Scanline Count: %d", hsc ); hsc = 0; vblankinc = 0; } diff --git a/pcsx2/Dump.cpp b/pcsx2/Dump.cpp index f6c4393265..fa7a483441 100644 --- a/pcsx2/Dump.cpp +++ b/pcsx2/Dump.cpp @@ -207,7 +207,7 @@ void iDumpBlock( int startpc, u8 * ptr ) u8 fpuused[33]; int numused, fpunumused; - Console::Status( "dump1 %x:%x, %x", startpc, pc, cpuRegs.cycle ); + Console.Status( "dump1 %x:%x, %x", startpc, pc, cpuRegs.cycle ); g_Conf->Folders.Logs.Mkdir(); AsciiFile eff( diff --git a/pcsx2/Elfheader.cpp b/pcsx2/Elfheader.cpp index 9f1b327dc5..c77525c554 100644 --- a/pcsx2/Elfheader.cpp +++ b/pcsx2/Elfheader.cpp @@ -263,10 +263,10 @@ struct ElfObject secthead = (ELF_SHR*)&data[header.e_shoff]; if ( ( header.e_shnum > 0 ) && ( header.e_shentsize != sizeof(ELF_SHR) ) ) - Console::Error( "ElfLoader Warning > Size of section headers is not standard" ); + Console.Error( "ElfLoader Warning > Size of section headers is not standard" ); if ( ( header.e_phnum > 0 ) && ( header.e_phentsize != sizeof(ELF_PHR) ) ) - Console::Error( "ElfLoader Warning > Size of program headers is not standard" ); + Console.Error( "ElfLoader Warning > Size of program headers is not standard" ); ELF_LOG( "type: " ); switch( header.e_type ) @@ -388,7 +388,7 @@ struct ElfObject size = proghead[ i ].p_filesz; if( proghead[ i ].p_vaddr != proghead[ i ].p_paddr ) - Console::Notice( "ElfProgram different load addrs: paddr=0x%8.8x, vaddr=0x%8.8x", + Console.Notice( "ElfProgram different load addrs: paddr=0x%8.8x, vaddr=0x%8.8x", proghead[ i ].p_paddr, proghead[ i ].p_vaddr); // used to be paddr @@ -475,7 +475,7 @@ struct ElfObject SymNames = (char*)data.GetPtr( secthead[ i_dt ].sh_offset ); eS = (Elf32_Sym*)data.GetPtr( secthead[ i_st ].sh_offset ); - Console::WriteLn("found %d symbols", secthead[ i_st ].sh_size / sizeof( Elf32_Sym )); + Console.WriteLn("found %d symbols", secthead[ i_st ].sh_size / sizeof( Elf32_Sym )); for( uint i = 1; i < ( secthead[ i_st ].sh_size / sizeof( Elf32_Sym ) ); i++ ) { if ( ( eS[ i ].st_value != 0 ) && ( ELF32_ST_TYPE( eS[ i ].st_info ) == 2 ) ) { @@ -491,17 +491,17 @@ void ElfApplyPatches() wxString filename( wxsFormat( L"%8.8x", ElfCRC ) ); // if patches found the following status msg will be overwritten - Console::SetTitle( wxsFormat( _("Game running [CRC=%s]"), filename.c_str() ) ); + Console.SetTitle( wxsFormat( _("Game running [CRC=%s]"), filename.c_str() ) ); if( !EmuConfig.EnablePatches ) return; if(LoadPatch( filename ) != 0) { - Console::WriteLn( "XML Loader returned an error. Trying to load a pnach..." ); + Console.WriteLn( "XML Loader returned an error. Trying to load a pnach..." ); inifile_read( filename.ToAscii().data() ); } else - Console::WriteLn( "XML Loading success. Will not load from pnach..." ); + Console.WriteLn( "XML Loading success. Will not load from pnach..." ); applypatch( 0 ); } @@ -513,14 +513,14 @@ u32 loadElfCRC( const char* filename ) IsoFS_init( ); - Console::Status("loadElfCRC: %s", filename); + Console.Status("loadElfCRC: %s", filename); int mylen = strlen( "cdromN:" ); if ( IsoFS_findFile( filename + mylen, &toc ) == -1 ) return 0; - DevCon::Status( "loadElfFile: %d bytes", toc.fileSize ); + DevCon.Status( "loadElfFile: %d bytes", toc.fileSize ); u32 crcval = ElfObject( wxString::FromAscii( filename ), toc.fileSize ).GetCRC(); - Console::Status( "loadElfFile: %s; CRC = %8.8X", filename, crcval ); + Console.Status( "loadElfFile: %s; CRC = %8.8X", filename, crcval ); return crcval; } @@ -540,7 +540,7 @@ void loadElfFile(const wxString& filename) if( filename.IsEmpty() ) return; s64 elfsize; - Console::Status( wxsFormat( L"loadElfFile: %s", filename.c_str() ) ); + Console.Status( wxsFormat( L"loadElfFile: %s", filename.c_str() ) ); const wxCharBuffer buffer( filename.ToAscii() ); const char* fnptr = buffer.data(); @@ -548,12 +548,12 @@ void loadElfFile(const wxString& filename) if( !filename.StartsWith( L"cdrom0:" ) && !filename.StartsWith( L"cdrom1:" ) ) { - DevCon::WriteLn("Loading from a file (or non-cd image)"); + DevCon.WriteLn("Loading from a file (or non-cd image)"); elfsize = Path::GetFileSize( filename ); } else { - DevCon::WriteLn("Loading from a CD rom or CD image"); + DevCon.WriteLn("Loading from a CD rom or CD image"); useCdvdSource = true; TocEntry toc; IsoFS_init( ); @@ -565,7 +565,7 @@ void loadElfFile(const wxString& filename) if( elfsize > 0xfffffff ) throw Exception::BadStream( filename, wxLt("Illegal ELF file size, over 2GB!") ); - Console::Status( wxsFormat(L"loadElfFile: %d", wxULongLong(elfsize).GetLo() ) ); + Console.Status( wxsFormat(L"loadElfFile: %d", wxULongLong(elfsize).GetLo() ) ); if( elfsize == 0 ) throw Exception::BadStream( filename, wxLt("Unexpected end of ELF file: ") ); @@ -597,12 +597,12 @@ void loadElfFile(const wxString& filename) if( memcmp( "rom0:OSDSYS", (char*)PSM( i ), 11 ) == 0 ) { strcpy( (char*)PSM( i ), fnptr ); - DevCon::Status( "loadElfFile: addr %x \"%s\" -> \"%s\"", i, "rom0:OSDSYS", fnptr ); + DevCon.Status( "loadElfFile: addr %x \"%s\" -> \"%s\"", i, "rom0:OSDSYS", fnptr ); } } ElfCRC = elfobj.GetCRC(); - Console::Status( wxsFormat( L"loadElfFile: %s; CRC = %8.8X", filename.c_str(), ElfCRC ) ); + Console.Status( wxsFormat( L"loadElfFile: %s; CRC = %8.8X", filename.c_str(), ElfCRC ) ); ElfApplyPatches(); @@ -624,7 +624,7 @@ int GetPS2ElfName( wxString& name ) // check if the file exists if (IsoFS_findFile("SYSTEM.CNF;1", &tocEntry) != TRUE){ - Console::Status("GetElfName: SYSTEM.CNF not found; invalid cd image or no disc present."); + Console.Status("GetElfName: SYSTEM.CNF not found; invalid cd image or no disc present."); return 0;//could not find; not a PS/PS2 cdvd } @@ -638,7 +638,7 @@ int GetPS2ElfName( wxString& name ) if (pos==NULL){ pos=strstr(buffer, "BOOT"); if (pos==NULL) { - Console::Error("PCSX2 Boot Error: This is not a Playstation or PS2 game!"); + Console.Error("PCSX2 Boot Error: This is not a Playstation or PS2 game!"); return 0; } return 1; @@ -664,7 +664,7 @@ int GetPS2ElfName( wxString& name ) u32 addr; - Console::WriteLn("Loading System.map..."); + Console.WriteLn("Loading System.map..."); while (!feof(fp)) { fseek(fp, 8, SEEK_CUR); buffer[0] = '0'; buffer[1] = 'x'; diff --git a/pcsx2/FPU.cpp b/pcsx2/FPU.cpp index 158103a69c..3eea7b0d2d 100644 --- a/pcsx2/FPU.cpp +++ b/pcsx2/FPU.cpp @@ -80,7 +80,7 @@ using namespace std; // for min / max // If we have an infinity value, then Overflow has occured. #define checkOverflow(xReg, cFlagsToSet, shouldReturn) { \ if ( ( xReg & ~0x80000000 ) == PosInfinity ) { \ - /*Console::Notice( "FPU OVERFLOW!: Changing to +/-Fmax!!!!!!!!!!!!\n" );*/ \ + /*Console.Notice( "FPU OVERFLOW!: Changing to +/-Fmax!!!!!!!!!!!!\n" );*/ \ xReg = ( xReg & 0x80000000 ) | posFmax; \ _ContVal_ |= cFlagsToSet; \ if ( shouldReturn ) { return; } \ @@ -90,7 +90,7 @@ using namespace std; // for min / max // If we have a denormal value, then Underflow has occured. #define checkUnderflow(xReg, cFlagsToSet, shouldReturn) { \ if ( ( ( xReg & 0x7F800000 ) == 0 ) && ( ( xReg & 0x007FFFFF ) != 0 ) ) { \ - /*Console::Notice( "FPU UNDERFLOW!: Changing to +/-0!!!!!!!!!!!!\n" );*/ \ + /*Console.Notice( "FPU UNDERFLOW!: Changing to +/-0!!!!!!!!!!!!\n" );*/ \ xReg &= 0x80000000; \ _ContVal_ |= cFlagsToSet; \ if ( shouldReturn ) { return; } \ @@ -377,14 +377,14 @@ void SUBA_S() { void LWC1() { u32 addr; addr = cpuRegs.GPR.r[_Rs_].UL[0] + (s16)(cpuRegs.code & 0xffff); // force sign extension to 32bit - if (addr & 0x00000003) { Console::Error( "FPU (LWC1 Opcode): Invalid Unaligned Memory Address" ); return; } // Should signal an exception? + if (addr & 0x00000003) { Console.Error( "FPU (LWC1 Opcode): Invalid Unaligned Memory Address" ); return; } // Should signal an exception? fpuRegs.fpr[_Rt_].UL = memRead32(addr); } void SWC1() { u32 addr; addr = cpuRegs.GPR.r[_Rs_].UL[0] + (s16)(cpuRegs.code & 0xffff); // force sign extension to 32bit - if (addr & 0x00000003) { Console::Error( "FPU (SWC1 Opcode): Invalid Unaligned Memory Address" ); return; } // Should signal an exception? + if (addr & 0x00000003) { Console.Error( "FPU (SWC1 Opcode): Invalid Unaligned Memory Address" ); return; } // Should signal an exception? memWrite32(addr, fpuRegs.fpr[_Rt_].UL); } diff --git a/pcsx2/FiFo.cpp b/pcsx2/FiFo.cpp index 811ffd4c81..3ebc2d18f7 100644 --- a/pcsx2/FiFo.cpp +++ b/pcsx2/FiFo.cpp @@ -60,7 +60,7 @@ void __fastcall ReadFIFO_page_5(u32 mem, u64 *out) VIF_LOG("ReadFIFO/VIF1, addr=0x%08X", mem); if( vif1Regs->stat & (VIF1_STAT_INT|VIF1_STAT_VSS|VIF1_STAT_VIS|VIF1_STAT_VFS) ) - DevCon::Notice( "Reading from vif1 fifo when stalled" ); + DevCon.Notice( "Reading from vif1 fifo when stalled" ); if (vif1Regs->stat & VIF1_STAT_FDR) { @@ -79,7 +79,7 @@ void __fastcall ReadFIFO_page_6(u32 mem, u64 *out) { jASSUME( (mem >= GIF_FIFO) && (mem < IPUout_FIFO) ); - DevCon::Notice( "ReadFIFO/GIF, addr=0x%x", mem ); + DevCon.Notice( "ReadFIFO/GIF, addr=0x%x", mem ); //out[0] = psHu64(mem ); //out[1] = psHu64(mem+8); @@ -143,9 +143,9 @@ void __fastcall WriteFIFO_page_5(u32 mem, const mem128_t *value) psHu64(0x5008) = value[1]; if(vif1Regs->stat & VIF1_STAT_FDR) - DevCon::Notice("writing to fifo when fdr is set!"); + DevCon.Notice("writing to fifo when fdr is set!"); if( vif1Regs->stat & (VIF1_STAT_INT | VIF1_STAT_VSS | VIF1_STAT_VIS | VIF1_STAT_VFS) ) - DevCon::Notice("writing to vif1 fifo when stalled"); + DevCon.Notice("writing to vif1 fifo when stalled"); vif1ch->qwc += 1; int ret = VIF1transfer((u32*)value, 4, 0); @@ -187,7 +187,7 @@ void __fastcall WriteFIFO_page_7(u32 mem, const mem128_t *value) if( mem == 0 ) { // Should this raise a PS2 exception or just ignore silently? - Console::Notice( "WriteFIFO/IPUout (ignored)" ); + Console.Notice( "WriteFIFO/IPUout (ignored)" ); } else { @@ -197,7 +197,7 @@ void __fastcall WriteFIFO_page_7(u32 mem, const mem128_t *value) //committing every 16 bytes while( FIFOto_write((u32*)value, 1) == 0 ) { - Console::WriteLn("IPU sleeping"); + Console.WriteLn("IPU sleeping"); Threading::Timeslice(); } } diff --git a/pcsx2/GS.cpp b/pcsx2/GS.cpp index 8bbaa88fed..1d630f0e7e 100644 --- a/pcsx2/GS.cpp +++ b/pcsx2/GS.cpp @@ -79,7 +79,7 @@ void gsSetRegionMode( GS_RegionMode region ) if( gsRegionMode == region ) return; gsRegionMode = region; - Console::WriteLn( "%s Display Mode Initialized.", (( gsRegionMode == Region_PAL ) ? "PAL" : "NTSC") ); + Console.WriteLn( "%s Display Mode Initialized.", (( gsRegionMode == Region_PAL ) ? "PAL" : "NTSC") ); UpdateVSyncRate(); } @@ -140,7 +140,7 @@ void gsCSRwrite(u32 value) else if( value & 0x100 ) // FLUSH { // Our emulated GS has no FIFO, but if it did, it would flush it here... - //Console::WriteLn("GS_CSR FLUSH GS fifo: %x (CSRr=%x)", value, GSCSRr); + //Console.WriteLn("GS_CSR FLUSH GS fifo: %x (CSRr=%x)", value, GSCSRr); } else { @@ -363,7 +363,7 @@ void gsSyncLimiterLostTime( s32 deltaTime ) if( !m_StrictSkipping ) return; - //Console::WriteLn("LostTime on the EE!"); + //Console.WriteLn("LostTime on the EE!"); mtgsThread.SendSimplePacket( GS_RINGTYPE_STARTTIME, @@ -414,7 +414,7 @@ __forceinline void gsFrameSkip( bool forceskip ) { if( !FramesToSkip ) { - //Console::Status( "- Skipping some VUs!" ); + //Console.Status( "- Skipping some VUs!" ); GSsetFrameSkip( 1 ); FramesToRender = noSkipFrames; @@ -482,7 +482,7 @@ __forceinline void gsFrameSkip( bool forceskip ) if( sSlowDeltaTime > (m_iSlowTicks + ((s64)GetTickFrequency() / 4)) ) { - //Console::Status( "Frameskip couldn't skip enough -- had to lose some time!" ); + //Console.Status( "Frameskip couldn't skip enough -- had to lose some time!" ); m_iSlowStart = iEnd - m_iSlowTicks; } @@ -492,7 +492,7 @@ __forceinline void gsFrameSkip( bool forceskip ) return; } - //Console::WriteLn( "Consecutive Frames -- Lateness: %d", (int)( sSlowDeltaTime / m_iSlowTicks ) ); + //Console.WriteLn( "Consecutive Frames -- Lateness: %d", (int)( sSlowDeltaTime / m_iSlowTicks ) ); // -- Consecutive frames section -- // Force-render consecutive frames without skipping. diff --git a/pcsx2/GS.h b/pcsx2/GS.h index 740d916217..df80020088 100644 --- a/pcsx2/GS.h +++ b/pcsx2/GS.h @@ -128,6 +128,7 @@ public: virtual ~mtgsThreadObject() throw(); void Start(); + void OnStart(); void PollStatus(); // Waits for the GS to empty out the entire ring buffer contents. @@ -166,7 +167,7 @@ protected: // Used internally by SendSimplePacket type functions uint _PrepForSimplePacket(); void _FinishSimplePacket( uint future_writepos ); - sptr ExecuteTask(); + void ExecuteTask(); }; PCSX2_ALIGNED16_EXTERN( mtgsThreadObject mtgsThread ); diff --git a/pcsx2/GSState.cpp b/pcsx2/GSState.cpp index c7f9451ec2..4e6a6e0a4e 100644 --- a/pcsx2/GSState.cpp +++ b/pcsx2/GSState.cpp @@ -72,8 +72,8 @@ void SaveGSState(const wxString& file) { if( g_SaveGSStream ) return; - Console::WriteLn( "Saving GS State..." ); - Console::WriteLn( wxsFormat( L"\t%s", file.c_str() ) ); + Console.WriteLn( "Saving GS State..." ); + Console.WriteLn( wxsFormat( L"\t%s", file.c_str() ) ); SafeArray buf; g_fGSSave = new memSavingState( buf ); @@ -88,7 +88,7 @@ void LoadGSState(const wxString& file) { int ret; - Console::Status( "Loading GS State..." ); + Console.Status( "Loading GS State..." ); wxString src( file ); @@ -260,7 +260,7 @@ void vSyncDebugStuff( uint frame ) if( --g_nLeftGSFrames <= 0 ) { safe_delete( g_fGSSave ); g_SaveGSStream = 0; - Console::WriteLn("Done saving GS stream"); + Console.WriteLn("Done saving GS stream"); } } #endif diff --git a/pcsx2/Gif.cpp b/pcsx2/Gif.cpp index a40b8e4c92..48152bee50 100644 --- a/pcsx2/Gif.cpp +++ b/pcsx2/Gif.cpp @@ -56,7 +56,7 @@ __forceinline void gsInterrupt() if (!(gif->chcr.STR)) { - //Console::WriteLn("Eh? why are you still interrupting! chcr %x, qwc %x, done = %x", gif->chcr._u32, gif->qwc, done); + //Console.WriteLn("Eh? why are you still interrupting! chcr %x, qwc %x, done = %x", gif->chcr._u32, gif->qwc, done); return; } @@ -71,7 +71,7 @@ __forceinline void gsInterrupt() { if (!dmacRegs->ctrl.DMAE) { - Console::Notice("gs dma masked, re-scheduling..."); + Console.Notice("gs dma masked, re-scheduling..."); // re-raise the int shortly in the future CPU_INT( 2, 64 ); return; @@ -121,7 +121,7 @@ int _GIFchain() //must increment madr and clear qwc, else it loops gif->madr += gif->qwc * 16; gif->qwc = 0; - Console::Notice( "Hackfix - NULL GIFchain" ); + Console.Notice( "Hackfix - NULL GIFchain" ); return -1; } @@ -180,13 +180,13 @@ void GIFdma() if (gifRegs->ctrl.PSE) // temporarily stop { - Console::WriteLn("Gif dma temp paused?"); + Console.WriteLn("Gif dma temp paused?"); return; } if ((dmacRegs->ctrl.STD == STD_GIF) && (prevcycles != 0)) { - Console::WriteLn("GS Stall Control Source = %x, Drain = %x\n MADR = %x, STADR = %x", (psHu32(0xe000) >> 4) & 0x3, (psHu32(0xe000) >> 6) & 0x3, gif->madr, psHu32(DMAC_STADR)); + Console.WriteLn("GS Stall Control Source = %x, Drain = %x\n MADR = %x, STADR = %x", (psHu32(0xe000) >> 4) & 0x3, (psHu32(0xe000) >> 6) & 0x3, gif->madr, psHu32(DMAC_STADR)); if ((gif->madr + (gif->qwc * 16)) > dmacRegs->stadr.ADDR) { @@ -242,7 +242,7 @@ void GIFdma() if ((dmacRegs->ctrl.STD == STD_GIF) && (gif->chcr.MOD == NORMAL_MODE)) { - Console::WriteLn("DMA Stall Control on GIF normal"); + Console.WriteLn("DMA Stall Control on GIF normal"); } GIFchain(); //Transfers the data set by the switch @@ -262,7 +262,7 @@ void GIFdma() if (!gspath3done && ((gif->madr + (gif->qwc * 16)) > dmacRegs->stadr.ADDR) && (id == 4)) { // stalled - Console::WriteLn("GS Stall Control Source = %x, Drain = %x\n MADR = %x, STADR = %x", (psHu32(0xe000) >> 4) & 0x3, (psHu32(0xe000) >> 6) & 0x3,gif->madr, psHu32(DMAC_STADR)); + Console.WriteLn("GS Stall Control Source = %x, Drain = %x\n MADR = %x, STADR = %x", (psHu32(0xe000) >> 4) & 0x3, (psHu32(0xe000) >> 6) & 0x3,gif->madr, psHu32(DMAC_STADR)); prevcycles = gscycles; gif->tadr -= 16; hwDmacIrq(DMAC_STALL_SIS); @@ -314,7 +314,7 @@ void dmaGIF() if (dmacRegs->ctrl.MFD == MFD_GIF) // GIF MFIFO { - //Console::WriteLn("GIF MFIFO"); + //Console.WriteLn("GIF MFIFO"); gifMFIFOInterrupt(); return; } @@ -434,7 +434,7 @@ void mfifoGIFtransfer(int qwc) { if (gif->tadr == spr0->madr) { - //if( gifqwc > 1 ) DevCon::WriteLn("gif mfifo tadr==madr but qwc = %d", gifqwc); + //if( gifqwc > 1 ) DevCon.WriteLn("gif mfifo tadr==madr but qwc = %d", gifqwc); hwDmacIrq(DMAC_MFIFO_EMPTY); gifstate |= GIF_STATE_EMPTY; return; @@ -498,7 +498,7 @@ void mfifoGIFtransfer(int qwc) FreezeRegs(1); if (mfifoGIFchain() == -1) { - Console::WriteLn("GIF dmaChain error size=%d, madr=%lx, tadr=%lx", gif->qwc, gif->madr, gif->tadr); + Console.WriteLn("GIF dmaChain error size=%d, madr=%lx, tadr=%lx", gif->qwc, gif->madr, gif->tadr); gifstate = GIF_STATE_STALL; } FreezeRegs(0); @@ -522,7 +522,7 @@ void gifMFIFOInterrupt() if (!(gif->chcr.STR)) { - Console::WriteLn("WTF GIFMFIFO"); + Console.WriteLn("WTF GIFMFIFO"); cpuRegs.interrupt &= ~(1 << 11); return; } @@ -538,7 +538,7 @@ void gifMFIFOInterrupt() { if (gifqwc <= 0) { - //Console::WriteLn("Empty"); + //Console.WriteLn("Empty"); gifstate |= GIF_STATE_EMPTY; gifRegs->stat.IMT = 0; // OPH=0 | APATH=0 hwDmacIrq(DMAC_MFIFO_EMPTY); @@ -551,11 +551,11 @@ void gifMFIFOInterrupt() #ifdef PCSX2_DEVBUILD if (gifstate == GIF_STATE_READY || gif->qwc > 0) { - Console::Error("gifMFIFO Panic > Shouldn't go here!"); + Console.Error("gifMFIFO Panic > Shouldn't go here!"); return; } #endif - //if(gifqwc > 0) Console::WriteLn("GIF MFIFO ending with stuff in it %x", gifqwc); + //if(gifqwc > 0) Console.WriteLn("GIF MFIFO ending with stuff in it %x", gifqwc); if (!gifmfifoirq) gifqwc = 0; gspath3done = false; diff --git a/pcsx2/Hw.cpp b/pcsx2/Hw.cpp index 547992ab59..71de79a9c7 100644 --- a/pcsx2/Hw.cpp +++ b/pcsx2/Hw.cpp @@ -75,7 +75,7 @@ __forceinline void intcInterrupt() if ((cpuRegs.CP0.n.Status.val & 0x400) != 0x400) return; if ((psHu32(INTC_STAT)) == 0) { - DevCon::Notice("*PCSX2*: intcInterrupt already cleared"); + DevCon.Notice("*PCSX2*: intcInterrupt already cleared"); return; } if ((psHu32(INTC_STAT) & psHu32(INTC_MASK)) == 0) return; @@ -188,7 +188,7 @@ bool hwDmacSrcChainWithStack(DMACh *dma, int id) { break; } default: { - Console::Notice("Call Stack Overflow (report if it fixes/breaks anything)"); + Console.Notice("Call Stack Overflow (report if it fixes/breaks anything)"); return true; //Return done } } @@ -218,7 +218,7 @@ bool hwDmacSrcChainWithStack(DMACh *dma, int id) { return true; //End Transfer } default: { //Else if ASR1 and ASR0 are messed up - //Console::Error("TAG_RET: ASR 1 & 0 == 1. This shouldn't happen!"); + //Console.Error("TAG_RET: ASR 1 & 0 == 1. This shouldn't happen!"); //dma->tadr += 16; //Clear tag address - Kills Klonoa 2 return true; //End Transfer } diff --git a/pcsx2/Hw.h b/pcsx2/Hw.h index 6abb7fe164..65b9b2ad97 100644 --- a/pcsx2/Hw.h +++ b/pcsx2/Hw.h @@ -467,7 +467,7 @@ static __forceinline u8* dmaGetAddr(u32 mem) mem &= ~0xf; if( (mem&0xffff0000) == 0x50000000 ) {// reserved scratch pad mem - Console::WriteLn("dmaGetAddr: reserved scratch pad mem"); + Console.WriteLn("dmaGetAddr: reserved scratch pad mem"); return NULL;//(u8*)&PS2MEM_SCRATCH[(mem) & 0x3ff0]; } @@ -477,7 +477,7 @@ static __forceinline u8* dmaGetAddr(u32 mem) // do manual LUT since IPU/SPR seems to use addrs 0x3000xxxx quite often // linux doesn't suffer from this because it has better vm support if( memLUT[ (p-PS2MEM_BASE)>>12 ].aPFNs == NULL ) { - Console::WriteLn("dmaGetAddr: memLUT PFN warning"); + Console.WriteLn("dmaGetAddr: memLUT PFN warning"); return NULL;//p; } @@ -501,7 +501,7 @@ static __forceinline void *dmaGetAddr(u32 addr) { ptr = (u8*)vtlb_GetPhyPtr(addr&0x1FFFFFF0); if (ptr == NULL) { - Console::Error( "*PCSX2*: DMA error: %8.8x", addr); + Console.Error( "*PCSX2*: DMA error: %8.8x", addr); return NULL; } return ptr; diff --git a/pcsx2/HwRead.cpp b/pcsx2/HwRead.cpp index e4f4a2e1c4..3e0f21ff98 100644 --- a/pcsx2/HwRead.cpp +++ b/pcsx2/HwRead.cpp @@ -55,7 +55,7 @@ __forceinline mem8_t hwRead8(u32 mem) u8 ret; if( mem >= IPU_CMD && mem < D0_CHCR ) - DevCon::Notice("Unexpected hwRead8 from 0x%x", mem); + DevCon.Notice("Unexpected hwRead8 from 0x%x", mem); switch (mem) { @@ -128,7 +128,7 @@ __forceinline mem16_t hwRead16(u32 mem) u16 ret; if( mem >= IPU_CMD && mem < D0_CHCR ) - Console::Notice("Unexpected hwRead16 from 0x%x", mem); + Console.Notice("Unexpected hwRead16 from 0x%x", mem); switch (mem) { diff --git a/pcsx2/HwWrite.cpp b/pcsx2/HwWrite.cpp index d5d076d394..33df800001 100644 --- a/pcsx2/HwWrite.cpp +++ b/pcsx2/HwWrite.cpp @@ -59,7 +59,7 @@ static __forceinline void DmaExec8( void (*func)(), u32 mem, u8 value ) psHu8(mem) = (u8)value; if ((psHu8(mem) & 0x1) && dmacRegs->ctrl.DMAE) { - /*Console::WriteLn("Running DMA 8 %x", psHu32(mem & ~0x1));*/ + /*Console.WriteLn("Running DMA 8 %x", psHu32(mem & ~0x1));*/ func(); } } @@ -86,7 +86,7 @@ static __forceinline void DmaExec16( void (*func)(), u32 mem, u16 value ) psHu16(mem) = (u16)value; if ((psHu16(mem) & 0x100) && dmacRegs->ctrl.DMAE) { - //Console::WriteLn("16bit DMA Start"); + //Console.WriteLn("16bit DMA Start"); func(); } } @@ -149,7 +149,7 @@ void hwWrite8(u32 mem, u8 value) } if( mem >= IPU_CMD && mem < D0_CHCR ) - DevCon::Notice( "hwWrite8 to 0x%x = 0x%x", mem, value ); + DevCon.Notice( "hwWrite8 to 0x%x = 0x%x", mem, value ); switch (mem) { case RCNT0_COUNT: rcntWcount(0, value); break; @@ -182,7 +182,7 @@ void hwWrite8(u32 mem, u8 value) ( value == '\n' && sio_count != 0 )) { sio_buffer[sio_count] = 0; - Console::WriteLn( Color_Cyan, sio_buffer ); + Console.WriteLn( Color_Cyan, sio_buffer ); sio_count = 0; } else if( value != '\n' ) @@ -199,7 +199,7 @@ void hwWrite8(u32 mem, u8 value) DMA_LOG("VIF0dma EXECUTE, value=0x%x", value); if ((value & 0x1) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("8 bit VIF0 DMA Start while DMAC Disabled\n"); + DevCon.Notice("8 bit VIF0 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x1; } DmaExec8(dmaVIF0, mem, value); @@ -209,7 +209,7 @@ void hwWrite8(u32 mem, u8 value) DMA_LOG("VIF1dma EXECUTE, value=0x%x", value); if ((value & 0x1) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("8 bit VIF1 DMA Start while DMAC Disabled\n"); + DevCon.Notice("8 bit VIF1 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x2; } if(value & 0x1) vif1.done = false; //This must be done here! some games (ala Crash of the Titans) pause the dma to start MFIFO @@ -220,7 +220,7 @@ void hwWrite8(u32 mem, u8 value) DMA_LOG("GSdma EXECUTE, value=0x%x", value); if ((value & 0x1) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("8 bit GIF DMA Start while DMAC Disabled\n"); + DevCon.Notice("8 bit GIF DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x4; } DmaExec8(dmaGIF, mem, value); @@ -230,7 +230,7 @@ void hwWrite8(u32 mem, u8 value) DMA_LOG("IPU0dma EXECUTE, value=0x%x", value); if ((value & 0x1) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("8 bit IPU0 DMA Start while DMAC Disabled\n"); + DevCon.Notice("8 bit IPU0 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x8; } DmaExec8(dmaIPU0, mem, value); @@ -240,7 +240,7 @@ void hwWrite8(u32 mem, u8 value) DMA_LOG("IPU1dma EXECUTE, value=0x%x", value); if ((value & 0x1) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("8 bit IPU1 DMA Start while DMAC Disabled\n"); + DevCon.Notice("8 bit IPU1 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x10; } DmaExec8(dmaIPU1, mem, value); @@ -251,7 +251,7 @@ void hwWrite8(u32 mem, u8 value) // if (value == 0) psxSu32(0x30) = 0x40000; if ((value & 0x1) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("8 bit SIF0 DMA Start while DMAC Disabled\n"); + DevCon.Notice("8 bit SIF0 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x20; } DmaExec8(dmaSIF0, mem, value); @@ -261,7 +261,7 @@ void hwWrite8(u32 mem, u8 value) DMA_LOG("SIF1dma EXECUTE, value=0x%x", value); if ((value & 0x1) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("8 bit SIF1 DMA Start while DMAC Disabled\n"); + DevCon.Notice("8 bit SIF1 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x40; } DmaExec8(dmaSIF1, mem, value); @@ -271,7 +271,7 @@ void hwWrite8(u32 mem, u8 value) DMA_LOG("SIF2dma EXECUTE, value=0x%x", value); if ((value & 0x1) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("8 bit SIF2 DMA Start while DMAC Disabled\n"); + DevCon.Notice("8 bit SIF2 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x80; } DmaExec8(dmaSIF2, mem, value); @@ -281,7 +281,7 @@ void hwWrite8(u32 mem, u8 value) DMA_LOG("fromSPRdma8 EXECUTE, value=0x%x", value); if ((value & 0x1) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("8 bit SPR0 DMA Start while DMAC Disabled\n"); + DevCon.Notice("8 bit SPR0 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x100; } DmaExec8(dmaSPR0, mem, value); @@ -291,7 +291,7 @@ void hwWrite8(u32 mem, u8 value) DMA_LOG("toSPRdma8 EXECUTE, value=0x%x", value); if ((value & 0x1) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("8 bit SPR1 DMA Start while DMAC Disabled\n"); + DevCon.Notice("8 bit SPR1 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x200; } DmaExec8(dmaSPR1, mem, value); @@ -350,7 +350,7 @@ void hwWrite8(u32 mem, u8 value) __forceinline void hwWrite16(u32 mem, u16 value) { if( mem >= IPU_CMD && mem < D0_CHCR ) - Console::Notice( "hwWrite16 to %x", mem ); + Console.Notice( "hwWrite16 to %x", mem ); switch(mem) { @@ -376,7 +376,7 @@ __forceinline void hwWrite16(u32 mem, u16 value) DMA_LOG("VIF0dma %lx", value); if ((value & 0x100) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("16 bit VIF0 DMA Start while DMAC Disabled\n"); + DevCon.Notice("16 bit VIF0 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x1; } DmaExec16(dmaVIF0, mem, value); @@ -386,7 +386,7 @@ __forceinline void hwWrite16(u32 mem, u16 value) DMA_LOG("VIF1dma CHCR %lx", value); if ((value & 0x100) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("16 bit VIF1 DMA Start while DMAC Disabled\n"); + DevCon.Notice("16 bit VIF1 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x2; } if(value & 0x100) vif1.done = false; //This must be done here! some games (ala Crash of the Titans) pause the dma to start MFIFO @@ -430,7 +430,7 @@ __forceinline void hwWrite16(u32 mem, u16 value) DMA_LOG("0x%8.8x hwWrite32: GSdma %lx", cpuRegs.cycle, value); if ((value & 0x100) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("16 bit GIF DMA Start while DMAC Disabled\n"); + DevCon.Notice("16 bit GIF DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x4; } DmaExec16(dmaGIF, mem, value); @@ -472,7 +472,7 @@ __forceinline void hwWrite16(u32 mem, u16 value) DMA_LOG("IPU0dma %lx", value); if ((value & 0x100) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("16 bit IPU0 DMA Start while DMAC Disabled\n"); + DevCon.Notice("16 bit IPU0 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x8; } DmaExec16(dmaIPU0, mem, value); @@ -504,7 +504,7 @@ __forceinline void hwWrite16(u32 mem, u16 value) DMA_LOG("IPU1dma %lx", value); if ((value & 0x100) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("16 bit IPU1 DMA Start while DMAC Disabled\n"); + DevCon.Notice("16 bit IPU1 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x10; } DmaExec16(dmaIPU1, mem, value); @@ -536,7 +536,7 @@ __forceinline void hwWrite16(u32 mem, u16 value) // if (value == 0) psxSu32(0x30) = 0x40000; if ((value & 0x100) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("16 bit SIF0 DMA Start while DMAC Disabled\n"); + DevCon.Notice("16 bit SIF0 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x20; } DmaExec16(dmaSIF0, mem, value); @@ -550,7 +550,7 @@ __forceinline void hwWrite16(u32 mem, u16 value) DMA_LOG("SIF1dma %lx", value); if ((value & 0x100) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("16 bit SIF1 DMA Start while DMAC Disabled\n"); + DevCon.Notice("16 bit SIF1 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x40; } DmaExec16(dmaSIF1, mem, value); @@ -582,7 +582,7 @@ __forceinline void hwWrite16(u32 mem, u16 value) DMA_LOG("SIF2dma %lx", value); if ((value & 0x100) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("16 bit SIF2 DMA Start while DMAC Disabled\n"); + DevCon.Notice("16 bit SIF2 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x80; } DmaExec16(dmaSIF2, mem, value); @@ -596,7 +596,7 @@ __forceinline void hwWrite16(u32 mem, u16 value) DMA_LOG("fromSPRdma %lx", value); if ((value & 0x100) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("16 bit SPR0 DMA Start while DMAC Disabled\n"); + DevCon.Notice("16 bit SPR0 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x100; } DmaExec16(dmaSPR0, mem, value); @@ -606,7 +606,7 @@ __forceinline void hwWrite16(u32 mem, u16 value) DMA_LOG("toSPRdma %lx", value); if ((value & 0x100) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("16 bit SPR1 DMA Start while DMAC Disabled\n"); + DevCon.Notice("16 bit SPR1 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x200; } DmaExec16(dmaSPR1, mem, value); @@ -744,7 +744,7 @@ void __fastcall hwWrite32_page_03( u32 mem, u32 value ) break; case GIF_STAT: // stat is readonly - DevCon::Notice("*PCSX2* GIFSTAT write value = 0x%x (readonly, ignored)", value); + DevCon.Notice("*PCSX2* GIFSTAT write value = 0x%x (readonly, ignored)", value); break; default: @@ -763,7 +763,7 @@ void __fastcall hwWrite32_page_0B( u32 mem, u32 value ) DMA_LOG("IPU0dma EXECUTE, value=0x%x\n", value); if ((value & 0x100) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("32 bit IPU0 DMA Start while DMAC Disabled\n"); + DevCon.Notice("32 bit IPU0 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x8; } DmaExec(dmaIPU0, mem, value); @@ -780,7 +780,7 @@ void __fastcall hwWrite32_page_0B( u32 mem, u32 value ) DMA_LOG("IPU1dma EXECUTE, value=0x%x\n", value); if ((value & 0x100) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("32 bit IPU1 DMA Start while DMAC Disabled\n"); + DevCon.Notice("32 bit IPU1 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x10; } DmaExec(dmaIPU1, mem, value); @@ -931,7 +931,7 @@ void __fastcall hwWrite32_generic( u32 mem, u32 value ) if ((value & 0x100) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("32 bit VIF0 DMA Start while DMAC Disabled\n"); + DevCon.Notice("32 bit VIF0 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x1; } @@ -944,7 +944,7 @@ void __fastcall hwWrite32_generic( u32 mem, u32 value ) if ((value & 0x100) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("32 bit VIF1 DMA Start while DMAC Disabled\n"); + DevCon.Notice("32 bit VIF1 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x2; } @@ -968,7 +968,7 @@ void __fastcall hwWrite32_generic( u32 mem, u32 value ) DMA_LOG("GIFdma EXECUTE, value=0x%x", value); if ((value & 0x100) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("32 bit GIF DMA Start while DMAC Disabled\n"); + DevCon.Notice("32 bit GIF DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x4; } DmaExec(dmaGIF, mem, value); @@ -987,7 +987,7 @@ void __fastcall hwWrite32_generic( u32 mem, u32 value ) //if (value == 0) psxSu32(0x30) = 0x40000; if ((value & 0x100) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("32 bit SIF0 DMA Start while DMAC Disabled\n"); + DevCon.Notice("32 bit SIF0 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x20; } DmaExec(dmaSIF0, mem, value); @@ -997,7 +997,7 @@ void __fastcall hwWrite32_generic( u32 mem, u32 value ) DMA_LOG("SIF1dma EXECUTE, value=0x%x", value); if ((value & 0x100) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("32 bit SIF1 DMA Start while DMAC Disabled\n"); + DevCon.Notice("32 bit SIF1 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x40; } DmaExec(dmaSIF1, mem, value); @@ -1012,7 +1012,7 @@ void __fastcall hwWrite32_generic( u32 mem, u32 value ) DMA_LOG("SIF2dma EXECUTE, value=0x%x", value); if ((value & 0x100) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("32 bit SIF2 DMA Start while DMAC Disabled\n"); + DevCon.Notice("32 bit SIF2 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x80; } DmaExec(dmaSIF2, mem, value); @@ -1022,7 +1022,7 @@ void __fastcall hwWrite32_generic( u32 mem, u32 value ) DMA_LOG("SPR0dma EXECUTE (fromSPR), value=0x%x", value); if ((value & 0x100) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("32 bit SPR0 DMA Start while DMAC Disabled\n"); + DevCon.Notice("32 bit SPR0 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x100; } DmaExec(dmaSPR0, mem, value); @@ -1032,7 +1032,7 @@ void __fastcall hwWrite32_generic( u32 mem, u32 value ) DMA_LOG("SPR1dma EXECUTE (toSPR), value=0x%x", value); if ((value & 0x100) && !dmacRegs->ctrl.DMAE) { - DevCon::Notice("32 bit SPR1 DMA Start while DMAC Disabled\n"); + DevCon.Notice("32 bit SPR1 DMA Start while DMAC Disabled\n"); QueuedDMA |= 0x200; } DmaExec(dmaSPR1, mem, value); @@ -1082,7 +1082,7 @@ void __fastcall hwWrite64_page_03( u32 mem, const mem64_t* srcval ) switch (mem) { case GIF_CTRL: - DevCon::Status("GIF_CTRL write 64", value); + DevCon.Status("GIF_CTRL write 64", value); psHu32(mem) = value & 0x8; if(value & 0x1) gsGIFReset(); @@ -1100,7 +1100,7 @@ void __fastcall hwWrite64_page_03( u32 mem, const mem64_t* srcval ) // set/clear bits 0 and 2 as per the GIF_MODE value. const u32 bitmask = GIF_MODE_M3R | GIF_MODE_IMT; - Console::Status("GIFMODE64 %x", value); + Console.Status("GIFMODE64 %x", value); psHu64(GIF_MODE) = value; psHu32(GIF_STAT) &= ~bitmask; diff --git a/pcsx2/IPU/IPU.cpp b/pcsx2/IPU/IPU.cpp index be7dfdda86..ca443c399f 100644 --- a/pcsx2/IPU/IPU.cpp +++ b/pcsx2/IPU/IPU.cpp @@ -164,24 +164,24 @@ void ipuShutdown() void ReportIPU() { - Console::WriteLn("g_nDMATransfer = 0x%x.", g_nDMATransfer._u32); - Console::WriteLn("FIreadpos = 0x%x, FIwritepos = 0x%x.", FIreadpos, FIwritepos); - Console::WriteLn("fifo_input = 0x%x.", fifo_input); - Console::WriteLn("FOreadpos = 0x%x, FOwritepos = 0x%x.", FOreadpos, FOwritepos); - Console::WriteLn("fifo_output = 0x%x.", fifo_output); - Console::WriteLn("g_BP = 0x%x.", g_BP); - Console::WriteLn("niq = 0x%x, iq = 0x%x.", niq, iq); - Console::WriteLn("vqclut = 0x%x.", vqclut); - Console::WriteLn("s_thresh = 0x%x.", s_thresh); - Console::WriteLn("coded_block_pattern = 0x%x.", coded_block_pattern); - Console::WriteLn("g_decoder = 0x%x.", g_decoder); - Console::WriteLn("mpeg2_scan_norm = 0x%x, mpeg2_scan_alt = 0x%x.", mpeg2_scan_norm, mpeg2_scan_alt); - Console::WriteLn("g_nCmdPos = 0x%x.", g_nCmdPos); - Console::WriteLn("g_nCmdIndex = 0x%x.", g_nCmdIndex); - Console::WriteLn("ipuCurCmd = 0x%x.", ipuCurCmd); - Console::WriteLn("_readbits = 0x%x.", _readbits); - Console::WriteLn("temp will equal 0x%x.", readbits - _readbits); - Console::WriteLn(""); + Console.WriteLn("g_nDMATransfer = 0x%x.", g_nDMATransfer._u32); + Console.WriteLn("FIreadpos = 0x%x, FIwritepos = 0x%x.", FIreadpos, FIwritepos); + Console.WriteLn("fifo_input = 0x%x.", fifo_input); + Console.WriteLn("FOreadpos = 0x%x, FOwritepos = 0x%x.", FOreadpos, FOwritepos); + Console.WriteLn("fifo_output = 0x%x.", fifo_output); + Console.WriteLn("g_BP = 0x%x.", g_BP); + Console.WriteLn("niq = 0x%x, iq = 0x%x.", niq, iq); + Console.WriteLn("vqclut = 0x%x.", vqclut); + Console.WriteLn("s_thresh = 0x%x.", s_thresh); + Console.WriteLn("coded_block_pattern = 0x%x.", coded_block_pattern); + Console.WriteLn("g_decoder = 0x%x.", g_decoder); + Console.WriteLn("mpeg2_scan_norm = 0x%x, mpeg2_scan_alt = 0x%x.", mpeg2_scan_norm, mpeg2_scan_alt); + Console.WriteLn("g_nCmdPos = 0x%x.", g_nCmdPos); + Console.WriteLn("g_nCmdIndex = 0x%x.", g_nCmdIndex); + Console.WriteLn("ipuCurCmd = 0x%x.", ipuCurCmd); + Console.WriteLn("_readbits = 0x%x.", _readbits); + Console.WriteLn("temp will equal 0x%x.", readbits - _readbits); + Console.WriteLn(""); } // fixme - ipuFreeze looks fairly broken. Should probably take a closer look at some point. @@ -284,11 +284,11 @@ __forceinline u64 ipuRead64(u32 mem) break; ipucase(IPU_CTRL): - DevCon::Notice("reading 64bit IPU ctrl"); + DevCon.Notice("reading 64bit IPU ctrl"); break; ipucase(IPU_BP): - DevCon::Notice("reading 64bit IPU top"); + DevCon.Notice("reading 64bit IPU top"); break; ipucase(IPU_TOP): // IPU_TOP @@ -346,7 +346,7 @@ __forceinline void ipuWrite32(u32 mem, u32 value) ipuRegs->ctrl._u32 = (value & 0x47f30000) | (ipuRegs->ctrl._u32 & 0x8000ffff); if (ipuRegs->ctrl.IDP == 3) { - Console::WriteLn("IPU Invalid Intra DC Precision, switching to 9 bits"); + Console.WriteLn("IPU Invalid Intra DC Precision, switching to 9 bits"); ipuRegs->ctrl.IDP = 1; } @@ -665,7 +665,7 @@ static BOOL __fastcall ipuCSC(u32 val) if (csc.DTE) IPU_LOG("Dithering enabled."); - //Console::WriteLn("CSC"); + //Console.WriteLn("CSC"); for (;g_nCmdIndex < (int)csc.MBC; g_nCmdIndex++) { @@ -773,7 +773,7 @@ __forceinline void IPU_INTERRUPT() //dma void IPUCMD_WRITE(u32 val) { // don't process anything if currently busy - if (ipuRegs->ctrl.BUSY) Console::WriteLn("IPU BUSY!"); // wait for thread + if (ipuRegs->ctrl.BUSY) Console.WriteLn("IPU BUSY!"); // wait for thread ipuRegs->ctrl.ECD = 0; ipuRegs->ctrl.SCD = 0; //clear ECD/SCD @@ -969,7 +969,7 @@ void IPUWorker() return; default: - Console::WriteLn("Unknown IPU command: %x", ipuRegs->cmd.CMD); + Console.WriteLn("Unknown IPU command: %x", ipuRegs->cmd.CMD); break; } @@ -1284,7 +1284,7 @@ void __fastcall ipu_dither(const macroblock_rgb32* rgb32, macroblock_rgb16 *rgb1 void __fastcall ipu_vq(macroblock_rgb16 *rgb16, u8* indx4) { - Console::Error("IPU: VQ not implemented"); + Console.Error("IPU: VQ not implemented"); } void __fastcall ipu_copy(const macroblock_8 *mb8, macroblock_16 *mb16) @@ -1361,7 +1361,7 @@ static __forceinline bool IPU1chain(int &totalqwc) if (pMem == NULL) { - Console::Error("ipu1dma NULL!"); + Console.Error("ipu1dma NULL!"); return true; } @@ -1430,7 +1430,7 @@ static __forceinline bool ipuDmacSrcChain(DMACh *tag, u32 *ptag) break; default: - Console::Error("IPU ERROR: different transfer mode!, Please report to PCSX2 Team"); + Console.Error("IPU ERROR: different transfer mode!, Please report to PCSX2 Team"); break; } @@ -1469,7 +1469,7 @@ int IPU1dma() //Check TIE bit of CHCR and IRQ bit of tag if (ipu1dma->chcr.TIE && (g_nDMATransfer.DOTIE1)) { - Console::WriteLn("IPU1 TIE"); + Console.WriteLn("IPU1 TIE"); IPU_INT_TO(totalqwc * BIAS); g_nDMATransfer.TIE1 = 1; @@ -1517,7 +1517,7 @@ int IPU1dma() // Normal Mode & qwc is finished if ((ipu1dma->chcr.MOD == NORMAL_MODE) && (ipu1dma->qwc == 0)) { - //Console::WriteLn("ipu1 normal empty qwc?"); + //Console.WriteLn("ipu1 normal empty qwc?"); return totalqwc; } @@ -1553,7 +1553,7 @@ int IPU1dma() //Check TIE bit of CHCR and IRQ bit of tag if (g_nDMATransfer.DOTIE1) { - Console::WriteLn("IPU1 TIE"); + Console.WriteLn("IPU1 TIE"); if (IPU1chain(totalqwc)) return totalqwc; @@ -1619,7 +1619,7 @@ int FIFOfrom_write(const u32 *value, int size) ipuRegs->ctrl.OFC += firsttrans; IPU0dma(); - //Console::WriteLn("Written %d qwords, %d", firsttrans,ipuRegs->ctrl.OFC); + //Console.WriteLn("Written %d qwords, %d", firsttrans,ipuRegs->ctrl.OFC); return firsttrans; } diff --git a/pcsx2/Interpreter.cpp b/pcsx2/Interpreter.cpp index de87b658c8..d479a1682e 100644 --- a/pcsx2/Interpreter.cpp +++ b/pcsx2/Interpreter.cpp @@ -35,7 +35,7 @@ static std::string disOut; static void debugI() { if( !IsDevBuild ) return; - if( cpuRegs.GPR.n.r0.UD[0] || cpuRegs.GPR.n.r0.UD[1] ) Console::Error("R0 is not zero!!!!"); + if( cpuRegs.GPR.n.r0.UD[0] || cpuRegs.GPR.n.r0.UD[1] ) Console.Error("R0 is not zero!!!!"); } //long int runs=0; @@ -51,7 +51,7 @@ static void execI() //runs++; //if (runs > 1599999999){ //leave some time to startup the testgame // if (opcode.Name[0] == 'L') { //find all opcodes beginning with "L" - // Console::WriteLn ("Load %s", opcode.Name); + // Console.WriteLn ("Load %s", opcode.Name); // } //} @@ -97,7 +97,7 @@ static void __fastcall doBranch( u32 target ) void __fastcall intDoBranch(u32 target) { - //Console::WriteLn("Interpreter Branch "); + //Console.WriteLn("Interpreter Branch "); _doBranch_shared( target ); if( Cpu == &intCpu ) diff --git a/pcsx2/IopBios.cpp b/pcsx2/IopBios.cpp index e27ac5db0e..81ed9e8fae 100644 --- a/pcsx2/IopBios.cpp +++ b/pcsx2/IopBios.cpp @@ -178,7 +178,7 @@ void bios_write() // 0x35/0x03 // fixme: This should use %s with a length parameter (but I forget the exact syntax while (a2 > 0) { - Console::Write("%c", *ptr++); + Console.Write("%c", *ptr++); a2--; } } @@ -291,19 +291,19 @@ _start: // Note: Use Read to obtain a write pointer here, since we're just writing back the // temp buffer we saved earlier. memcpy( (void*)iopVirtMemR(sp), save, 4*4); - Console::Write( Color_Cyan, "%s", tmp); + Console.Write( Color_Cyan, "%s", tmp); pc0 = ra; } void bios_putchar () // 3d { - Console::Write( Color_Cyan, "%c", a0 ); + Console.Write( Color_Cyan, "%c", a0 ); pc0 = ra; } void bios_puts () // 3e/3f { - Console::Write( Color_Cyan, Ra0 ); + Console.Write( Color_Cyan, Ra0 ); pc0 = ra; } diff --git a/pcsx2/IopCounters.cpp b/pcsx2/IopCounters.cpp index 72e8305d0e..2d1fad3714 100644 --- a/pcsx2/IopCounters.cpp +++ b/pcsx2/IopCounters.cpp @@ -187,7 +187,7 @@ static void __fastcall _rcntTestTarget( int i ) psxCounters[i].count -= psxCounters[i].target; if(!(psxCounters[i].mode & 0x40)) { - Console::WriteLn("Counter %x repeat intr not set on zero ret, ignoring target", i); + Console.WriteLn("Counter %x repeat intr not set on zero ret, ignoring target", i); psxCounters[i].target |= IOPCNT_FUTURE_TARGET; } } else psxCounters[i].target |= IOPCNT_FUTURE_TARGET; @@ -637,7 +637,7 @@ __forceinline void psxRcntWmode32( int index, u32 value ) // Need to set a rate and target if((counter.mode & 0x7) == 0x7 || (counter.mode & 0x7) == 0x1) { - Console::WriteLn( "Gate set on IOP Counter %d, disabling", index ); + Console.WriteLn( "Gate set on IOP Counter %d, disabling", index ); counter.mode |= IOPCNT_STOPPED; } } diff --git a/pcsx2/IopDma.cpp b/pcsx2/IopDma.cpp index 367de8e3c2..9a62eed464 100644 --- a/pcsx2/IopDma.cpp +++ b/pcsx2/IopDma.cpp @@ -30,9 +30,9 @@ static void __fastcall psxDmaGeneric(u32 madr, u32 bcr, u32 chcr, u32 spuCore, _ { const char dmaNum = spuCore ? '7' : '4'; - /*if (chcr & 0x400) DevCon::Status("SPU 2 DMA %c linked list chain mode! chcr = %x madr = %x bcr = %x\n", dmaNum, chcr, madr, bcr); - if (chcr & 0x40000000) DevCon::Notice("SPU 2 DMA %c Unusual bit set on 'to' direction chcr = %x madr = %x bcr = %x\n", dmaNum, chcr, madr, bcr); - if ((chcr & 0x1) == 0) DevCon::Status("SPU 2 DMA %c loading from spu2 memory chcr = %x madr = %x bcr = %x\n", dmaNum, chcr, madr, bcr);*/ + /*if (chcr & 0x400) DevCon.Status("SPU 2 DMA %c linked list chain mode! chcr = %x madr = %x bcr = %x\n", dmaNum, chcr, madr, bcr); + if (chcr & 0x40000000) DevCon.Notice("SPU 2 DMA %c Unusual bit set on 'to' direction chcr = %x madr = %x bcr = %x\n", dmaNum, chcr, madr, bcr); + if ((chcr & 0x1) == 0) DevCon.Status("SPU 2 DMA %c loading from spu2 memory chcr = %x madr = %x bcr = %x\n", dmaNum, chcr, madr, bcr);*/ const int size = (bcr >> 16) * (bcr & 0xFFFF); @@ -41,7 +41,7 @@ static void __fastcall psxDmaGeneric(u32 madr, u32 bcr, u32 chcr, u32 spuCore, _ if (SPU2async) { SPU2async(psxRegs.cycle - psxCounters[6].sCycleT); - //Console::Status("cycles sent to SPU2 %x\n", psxRegs.cycle - psxCounters[6].sCycleT); + //Console.Status("cycles sent to SPU2 %x\n", psxRegs.cycle - psxCounters[6].sCycleT); psxCounters[6].sCycleT = psxRegs.cycle; psxCounters[6].CycleT = size * 3; @@ -53,7 +53,7 @@ static void __fastcall psxDmaGeneric(u32 madr, u32 bcr, u32 chcr, u32 spuCore, _ if((g_psxNextBranchCycle - psxNextsCounter) > (u32)psxNextCounter) { - //DevCon::Notice("SPU2async Setting new counter branch, old %x new %x ((%x - %x = %x) > %x delta)", g_psxNextBranchCycle, psxNextsCounter + psxNextCounter, g_psxNextBranchCycle, psxNextsCounter, (g_psxNextBranchCycle - psxNextsCounter), psxNextCounter); + //DevCon.Notice("SPU2async Setting new counter branch, old %x new %x ((%x - %x = %x) > %x delta)", g_psxNextBranchCycle, psxNextsCounter + psxNextCounter, g_psxNextBranchCycle, psxNextsCounter, (g_psxNextBranchCycle - psxNextsCounter), psxNextCounter); g_psxNextBranchCycle = psxNextsCounter + psxNextCounter; } } @@ -72,7 +72,7 @@ static void __fastcall psxDmaGeneric(u32 madr, u32 bcr, u32 chcr, u32 spuCore, _ break; default: - Console::Error("*** DMA %c - SPU unknown *** %x addr = %x size = %x", dmaNum, chcr, madr, bcr); + Console.Error("*** DMA %c - SPU unknown *** %x addr = %x size = %x", dmaNum, chcr, madr, bcr); break; } } @@ -277,7 +277,7 @@ s32 spu2DmaRead(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed) if (SPU2async) { SPU2async(psxRegs.cycle - psxCounters[6].sCycleT); - //Console::Status("cycles sent to SPU2 %x\n", psxRegs.cycle - psxCounters[6].sCycleT); + //Console.Status("cycles sent to SPU2 %x\n", psxRegs.cycle - psxCounters[6].sCycleT); psxCounters[6].sCycleT = psxRegs.cycle; psxCounters[6].CycleT = bytes * 3; @@ -315,7 +315,7 @@ s32 spu2DmaWrite(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed) if (SPU2async) { SPU2async(psxRegs.cycle - psxCounters[6].sCycleT); - //Console::Status("cycles sent to SPU2 %x\n", psxRegs.cycle - psxCounters[6].sCycleT); + //Console.Status("cycles sent to SPU2 %x\n", psxRegs.cycle - psxCounters[6].sCycleT); psxCounters[6].sCycleT = psxRegs.cycle; psxCounters[6].CycleT = bytes * 3; @@ -478,7 +478,7 @@ void IopDmaUpdate(u32 elapsed) s32 errDmaRead(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed) { - Console::Error("ERROR: Tried to read using DMA %d (%s). Ignoring.", 0, channel, IopDmaNames[channel]); + Console.Error("ERROR: Tried to read using DMA %d (%s). Ignoring.", 0, channel, IopDmaNames[channel]); *bytesProcessed = bytesLeft; return 0; @@ -486,7 +486,7 @@ s32 errDmaRead(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed) s32 errDmaWrite(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed) { - Console::Error("ERROR: Tried to write using DMA %d (%s). Ignoring.", 0, channel, IopDmaNames[channel]); + Console.Error("ERROR: Tried to write using DMA %d (%s). Ignoring.", 0, channel, IopDmaNames[channel]); *bytesProcessed = bytesLeft; return 0; diff --git a/pcsx2/IopHw.cpp b/pcsx2/IopHw.cpp index c347ed98f6..da9714584b 100644 --- a/pcsx2/IopHw.cpp +++ b/pcsx2/IopHw.cpp @@ -69,7 +69,7 @@ u8 psxHwRead8(u32 add) { case IOP_T5_COUNT: case IOP_T5_MODE: case IOP_T5_TARGET: - DevCon::Notice( "IOP Counter Read8 from addr0x%x = 0x%x", add, psxHu8(add) ); + DevCon.Notice( "IOP Counter Read8 from addr0x%x = 0x%x", add, psxHu8(add) ); return psxHu8(add); #endif @@ -623,7 +623,7 @@ void psxHwWrite8(u32 add, u8 value) { USBwrite8(add, value); return; } if((add & 0xf) == 0xa) - Console::Error("8bit write (possible chcr set) to addr 0x%x = 0x%x", add, value ); + Console.Error("8bit write (possible chcr set) to addr 0x%x = 0x%x", add, value ); switch (add) { case 0x1f801040: @@ -649,7 +649,7 @@ void psxHwWrite8(u32 add, u8 value) { case IOP_T5_COUNT: case IOP_T5_MODE: case IOP_T5_TARGET: - DevCon::Notice( "IOP Counter Write8 to addr 0x%x = 0x%x", add, value ); + DevCon.Notice( "IOP Counter Write8 to addr 0x%x = 0x%x", add, value ); psxHu8(add) = value; return; @@ -673,7 +673,7 @@ void psxHwWrite8(u32 add, u8 value) { ( value == '\n' && g_pbufi != 0 ) ) { g_pbuf[g_pbufi] = 0; - DevCon::WriteLn( Color_Cyan, "%s", g_pbuf ); + DevCon.WriteLn( Color_Cyan, "%s", g_pbuf ); g_pbufi = 0; } else if( value != '\n' ) @@ -703,7 +703,7 @@ void psxHwWrite16(u32 add, u16 value) { USBwrite16(add, value); return; } - if((add & 0xf) == 0x9) DevCon::WriteLn("16bit write (possible chcr set) %x value %x", add, value); + if((add & 0xf) == 0x9) DevCon.WriteLn("16bit write (possible chcr set) %x value %x", add, value); switch (add) { case 0x1f801040: @@ -1236,7 +1236,7 @@ void psxHwWrite32(u32 add, u32 value) { //------------------------------------------------------------------ case 0x1f8014c0: PSXHW_LOG("RTC_HOLDMODE 32bit write %lx", value); - Console::Notice("** RTC_HOLDMODE 32bit write %lx", value); + Console.Notice("** RTC_HOLDMODE 32bit write %lx", value); break; case 0x1f801450: @@ -1341,10 +1341,10 @@ void psxDmaInterrupt2(int n) if (HW_DMA_ICR2 & (1 << (16 + n))) { /* if (HW_DMA_ICR2 & (1 << (24 + n))) { - Console::WriteLn("*PCSX2*: HW_DMA_ICR2 n=%d already set", n); + Console.WriteLn("*PCSX2*: HW_DMA_ICR2 n=%d already set", n); } if (psxHu32(0x1070) & 8) { - Console::WriteLn("*PCSX2*: psxHu32(0x1070) 8 already set (n=%d)", n); + Console.WriteLn("*PCSX2*: psxHu32(0x1070) 8 already set (n=%d)", n); }*/ HW_DMA_ICR2|= (1 << (24 + n)); psxRegs.CP0.n.Cause |= 1 << (16 + n); diff --git a/pcsx2/IopMem.cpp b/pcsx2/IopMem.cpp index f10be0b522..7808309d34 100644 --- a/pcsx2/IopMem.cpp +++ b/pcsx2/IopMem.cpp @@ -57,7 +57,7 @@ void psxMemReset() jASSUME( psxMemWLUT != NULL ); jASSUME( m_psxAllMem != NULL ); - DbgCon::Status( "psxMemReset > Resetting core memory!" ); + DbgCon.Status( "psxMemReset > Resetting core memory!" ); memzero_ptr<0x2000 * sizeof(uptr) * 2>( psxMemWLUT ); // clears both allocations, RLUT and WLUT memzero_ptr( m_psxAllMem ); @@ -343,7 +343,7 @@ void iopMemWrite8(u32 mem, u8 value) { if (t == 0x1d00) { - Console::WriteLn("sw8 [0x%08X]=0x%08X", mem, value); + Console.WriteLn("sw8 [0x%08X]=0x%08X", mem, value); psxSu8(mem) = value; return; } @@ -391,7 +391,7 @@ void iopMemWrite16(u32 mem, u16 value) u8* p = (u8 *)(psxMemWLUT[mem >> 16]); if (p != NULL && !(psxRegs.CP0.n.Status & 0x10000) ) { - if( t==0x1D00 ) Console::WriteLn("sw16 [0x%08X]=0x%08X", mem, value); + if( t==0x1D00 ) Console.WriteLn("sw16 [0x%08X]=0x%08X", mem, value); *(u16 *)(p + (mem & 0xffff)) = value; psxCpu->Clear(mem&~3, 1); } diff --git a/pcsx2/IopSio2.cpp b/pcsx2/IopSio2.cpp index dd979ac402..37691dbca6 100644 --- a/pcsx2/IopSio2.cpp +++ b/pcsx2/IopSio2.cpp @@ -52,7 +52,7 @@ only recv2 & dataout influences padman void sio2Reset() { - DevCon::Status( "Sio2 Reset" ); + DevCon.Status( "Sio2 Reset" ); memzero(sio2); sio2.packet.recvVal1 = 0x1D100; // Nothing is connected at start } @@ -155,7 +155,7 @@ void sio2_serialIn(u8 value){ sioWrite8(value); if (sio2.packet.sendSize > BUFSIZE) {//asadr - Console::Notice("*PCSX2*: sendSize >= %d", BUFSIZE); + Console.Notice("*PCSX2*: sendSize >= %d", BUFSIZE); } else { sio2.buf[sio2.packet.sendSize] = sioRead8(); sio2.packet.sendSize++; @@ -182,7 +182,7 @@ void sio2_fifoIn(u8 value){ SIODMAWrite(value); if (sio2.packet.sendSize > BUFSIZE) {//asadr - Console::WriteLn("*PCSX2*: sendSize >= %d", BUFSIZE); + Console.WriteLn("*PCSX2*: sendSize >= %d", BUFSIZE); } else { sio2.buf[sio2.packet.sendSize] = sioRead8(); sio2.packet.sendSize++; @@ -194,7 +194,7 @@ u8 sio2_fifoOut(){ //PAD_LOG("READING %x\n",sio2.buf[sio2.recvIndex]); return sio2.buf[sio2.recvIndex++]; } else { - Console::Error( "*PCSX2*: buffer overrun" ); + Console.Error( "*PCSX2*: buffer overrun" ); } return 0; // No Data } diff --git a/pcsx2/Linux/LnxHostSys.cpp b/pcsx2/Linux/LnxHostSys.cpp index c915ecb0b8..8d7f374f10 100644 --- a/pcsx2/Linux/LnxHostSys.cpp +++ b/pcsx2/Linux/LnxHostSys.cpp @@ -44,7 +44,7 @@ void SysPageFaultExceptionFilter( int signal, siginfo_t *info, void * ) // get bad virtual address uptr offset = (u8*)info->si_addr - psM; - DevCon::Status( "Protected memory cleanup. Offset 0x%x", offset ); + DevCon.Status( "Protected memory cleanup. Offset 0x%x", offset ); if (offset>=Ps2MemSize::Base) { diff --git a/pcsx2/MMI.cpp b/pcsx2/MMI.cpp index bd74cee999..bfa4a4ef5f 100644 --- a/pcsx2/MMI.cpp +++ b/pcsx2/MMI.cpp @@ -1028,9 +1028,9 @@ void QFSRV() { // JayteeMaster: changed a bit to avoid screw up cpuRegs.GPR.r[_Rd_].UD[1] = cpuRegs.GPR.r[_Rt_].UD[1]; //saZero++; //if( saZero >= 388800 ) - //Console::WriteLn( "SA Is Zero, Bitch: %d zeros and counting.", saZero ); + //Console.WriteLn( "SA Is Zero, Bitch: %d zeros and counting.", saZero ); } else { - //Console::WriteLn( "SA Properly Valued at: %d (after %d zeros)", sa_amt, saZero ); + //Console.WriteLn( "SA Properly Valued at: %d (after %d zeros)", sa_amt, saZero ); //saZero = 0; if (sa_amt < 64) { /* diff --git a/pcsx2/MTGS.cpp b/pcsx2/MTGS.cpp index c75553d3b4..acfcbe5de9 100644 --- a/pcsx2/MTGS.cpp +++ b/pcsx2/MTGS.cpp @@ -33,7 +33,7 @@ using namespace Threading; using namespace std; #ifdef DEBUG -#define MTGS_LOG Console::WriteLn +#define MTGS_LOG Console.WriteLn #else #define MTGS_LOG 0&& #endif @@ -79,6 +79,8 @@ struct MTGS_BufferedData }; PCSX2_ALIGNED( 32, static MTGS_BufferedData RingBuffer ); +extern bool renderswitch; +static volatile bool gsIsOpened = false; #ifdef RINGBUF_DEBUG_STACK @@ -112,7 +114,15 @@ mtgsThreadObject::mtgsThreadObject() : void mtgsThreadObject::Start() { - m_returncode = 0; + _parent::Start(); + m_ExecMode = ExecMode_Suspending; + SetEvent(); +} + +void mtgsThreadObject::OnStart() +{ + gsIsOpened = false; + m_RingPos = 0; m_WritePos = 0; @@ -123,19 +133,12 @@ void mtgsThreadObject::Start() m_packet_size = 0; m_packet_ringpos = 0; - _parent::Start(); - m_ExecMode = ExecMode_Suspending; - SetEvent(); + _parent::OnStart(); } void mtgsThreadObject::PollStatus() { - if( m_ExecMode == ExecMode_NoThreadYet ) - { - if( m_returncode != 0 ) // means the thread failed to init the GS plugin - throw Exception::PluginOpenError( PluginId_GS ); - } - + RethrowException(); } mtgsThreadObject::~mtgsThreadObject() throw() @@ -172,7 +175,7 @@ void mtgsThreadObject::PostVsyncEnd( bool updategs ) if( m_WritePos == volatize( m_RingPos ) ) { // MTGS ringbuffer is empty, but we still have queued frames in the counter? Ouch! - Console::Error( "MTGS > Queued framecount mismatch = %d", m_QueuedFrames ); + Console.Error( "MTGS > Queued framecount mismatch = %d", m_QueuedFrames ); m_QueuedFrames = 0; break; } @@ -182,7 +185,7 @@ void mtgsThreadObject::PostVsyncEnd( bool updategs ) m_lock_FrameQueueCounter.Lock(); m_QueuedFrames++; - //Console::Status( " >> Frame Added!" ); + //Console.Status( " >> Frame Added!" ); m_lock_FrameQueueCounter.Unlock(); SendSimplePacket( GS_RINGTYPE_VSYNC, @@ -199,13 +202,11 @@ struct PacketTagType u32 data[3]; }; -extern bool renderswitch; -static volatile long gsIsOpened = 0; - static void _clean_close_gs( void* obj ) { - int result = _InterlockedExchange( &gsIsOpened, 0 ); - if( result && (g_plugins != NULL) ) + if( !gsIsOpened ) return; + gsIsOpened = false; + if( g_plugins != NULL ) g_plugins->m_info[PluginId_GS].CommonBindings.Close(); } @@ -224,33 +225,34 @@ void mtgsThreadObject::OpenPlugin() GSirqCallback( dummyIrqCallback ); if( renderswitch ) - Console::WriteLn( "\t\tForced software switch enabled." ); + Console.WriteLn( "\t\tForced software switch enabled." ); + + int result; if( GSopen2 != NULL ) - m_returncode = GSopen2( (void*)&pDsp, 1 | (renderswitch ? 4 : 0) ); + result = GSopen2( (void*)&pDsp, 1 | (renderswitch ? 4 : 0) ); else - m_returncode = GSopen( (void*)&pDsp, "PCSX2", renderswitch ? 2 : 1 ); + result = GSopen( (void*)&pDsp, "PCSX2", renderswitch ? 2 : 1 ); - gsIsOpened = 1; - m_sem_OpenDone.Post(); - - if( m_returncode != 0 ) + if( result != 0 ) { - DevCon::WriteLn( "MTGS: GSopen Finished, return code: 0x%x", m_returncode ); - pthread_exit( (void*)m_returncode ); + DevCon.WriteLn( "GSopen Failed: return code: 0x%x", result ); + throw Exception::PluginOpenError( PluginId_GS ); } + gsIsOpened = true; + m_sem_OpenDone.Post(); + GSCSRr = 0x551B4000; // 0x55190000 GSsetGameCRC( ElfCRC, 0 ); } -sptr mtgsThreadObject::ExecuteTask() +void mtgsThreadObject::ExecuteTask() { #ifdef RINGBUF_DEBUG_STACK PacketTagType prevCmd; #endif - gsIsOpened = false; pthread_cleanup_push( _clean_close_gs, this ); while( true ) { @@ -263,7 +265,7 @@ sptr mtgsThreadObject::ExecuteTask() // ever be modified by this thread. while( m_RingPos != volatize(m_WritePos)) { - wxASSERT( m_RingPos < RingBufferSize ); + pxAssert( m_RingPos < RingBufferSize ); const PacketTagType& tag = (PacketTagType&)RingBuffer[m_RingPos]; u32 ringposinc = 1; @@ -275,9 +277,9 @@ sptr mtgsThreadObject::ExecuteTask() uptr stackpos = ringposStack.back(); if( stackpos != m_RingPos ) { - Console::Error( "MTGS Ringbuffer Critical Failure ---> %x to %x (prevCmd: %x)\n", stackpos, m_RingPos, prevCmd.command ); + Console.Error( "MTGS Ringbuffer Critical Failure ---> %x to %x (prevCmd: %x)\n", stackpos, m_RingPos, prevCmd.command ); } - wxASSERT( stackpos == m_RingPos ); + pxAssert( stackpos == m_RingPos ); prevCmd = tag; ringposStack.pop_back(); m_lock_Stack.Unlock(); @@ -333,7 +335,7 @@ sptr mtgsThreadObject::ExecuteTask() m_lock_FrameQueueCounter.Lock(); AtomicDecrement( m_QueuedFrames ); jASSUME( m_QueuedFrames >= 0 ); - //Console::Status( " << Frame Removed!" ); + //Console.Status( " << Frame Removed!" ); m_lock_FrameQueueCounter.Unlock(); if( PADupdate != NULL ) @@ -408,8 +410,8 @@ sptr mtgsThreadObject::ExecuteTask() #ifdef PCSX2_DEVBUILD default: - Console::Error("GSThreadProc, bad packet (%x) at m_RingPos: %x, m_WritePos: %x", tag.command, m_RingPos, m_WritePos); - wxASSERT_MSG( false, L"Bad packet encountered in the MTGS Ringbuffer." ); + Console.Error("GSThreadProc, bad packet (%x) at m_RingPos: %x, m_WritePos: %x", tag.command, m_RingPos, m_WritePos); + pxFail( "Bad packet encountered in the MTGS Ringbuffer." ); m_RingPos = m_WritePos; continue; #else @@ -419,15 +421,13 @@ sptr mtgsThreadObject::ExecuteTask() } uint newringpos = m_RingPos + ringposinc; - wxASSERT( newringpos <= RingBufferSize ); + pxAssert( newringpos <= RingBufferSize ); newringpos &= RingBufferMask; AtomicExchange( m_RingPos, newringpos ); } m_RingBufferIsBusy = false; } pthread_cleanup_pop( true ); - - return 0; } void mtgsThreadObject::OnSuspendInThread() @@ -445,7 +445,7 @@ void mtgsThreadObject::OnResumeInThread() // Used primarily for plugin startup/shutdown. void mtgsThreadObject::WaitGS() { - DevAssert( !IsSelf(), "This method is only allowed from threads *not* named MTGS." ); + pxAssertDev( !IsSelf(), "This method is only allowed from threads *not* named MTGS." ); if( IsSuspended() ) return; @@ -465,7 +465,7 @@ void mtgsThreadObject::SetEvent() void mtgsThreadObject::PrepEventWait() { - //Console::Notice( "MTGS Stall! EE waits for nothing! ... except your GPU sometimes." ); + //Console.Notice( "MTGS Stall! EE waits for nothing! ... except your GPU sometimes." ); SetEvent(); Timeslice(); } @@ -531,7 +531,7 @@ void mtgsThreadObject::SendDataPacket() m_CopyDataTally += m_packet_size; if( ( m_CopyDataTally > 0x8000 ) || ( ++m_CopyCommandTally > 16 ) ) { - //Console::Status( "MTGS Kick! DataSize : 0x%5.8x, CommandTally : %d", m_CopyDataTally, m_CopyCommandTally ); + //Console.Status( "MTGS Kick! DataSize : 0x%5.8x, CommandTally : %d", m_CopyDataTally, m_CopyCommandTally ); SetEvent(); } } @@ -579,7 +579,7 @@ int mtgsThreadObject::PrepDataPacket( GIF_PATH pathidx, const u8* srcdata, u32 s } if (ringtx_s>=128*1024*1024) { - Console::Status("GSRingBufCopy:128MB in %d tx -> b/tx: AVG = %.2f , max = %d, min = %d",ringtx_c,ringtx_s/(float)ringtx_c,ringtx_s_max,ringtx_s_min); + Console.Status("GSRingBufCopy:128MB in %d tx -> b/tx: AVG = %.2f , max = %d, min = %d",ringtx_c,ringtx_s/(float)ringtx_c,ringtx_s_max,ringtx_s_min); for (int i=0;i<32;i++) { u32 total_bucket=0; @@ -590,15 +590,15 @@ int mtgsThreadObject::PrepDataPacket( GIF_PATH pathidx, const u8* srcdata, u32 s { total_bucket+=ringtx_inf[i][j]; bucket_subitems++; - Console::Notice("GSRingBufCopy :tx [%d,%d] algn %d : count= %d [%.2f%%]",1< Perfect Fit!"); + //Console.WriteLn( "MTGS > Perfect Fit!"); PrepEventWait(); while( true ) diff --git a/pcsx2/Memory.cpp b/pcsx2/Memory.cpp index 807fa97648..6418c34b9b 100644 --- a/pcsx2/Memory.cpp +++ b/pcsx2/Memory.cpp @@ -95,7 +95,7 @@ u8 *psS = NULL; //0.015 mb, scratch pad void MyMemCheck(u32 mem) { if( mem == 0x1c02f2a0 ) - Console::WriteLn("yo; (mem == 0x1c02f2a0) in MyMemCheck..."); + Console.WriteLn("yo; (mem == 0x1c02f2a0) in MyMemCheck..."); } ///////////////////////////// @@ -218,7 +218,7 @@ mem8_t __fastcall _ext_memRead8 (u32 mem) case 7: // dev9 { mem8_t retval = DEV9read8(mem & ~0xa4000000); - Console::WriteLn("DEV9 read8 %8.8lx: %2.2lx", mem & ~0xa4000000, retval); + Console.WriteLn("DEV9 read8 %8.8lx: %2.2lx", mem & ~0xa4000000, retval); return retval; } } @@ -248,7 +248,7 @@ mem16_t __fastcall _ext_memRead16(u32 mem) case 7: // dev9 { mem16_t retval = DEV9read16(mem & ~0xa4000000); - Console::WriteLn("DEV9 read16 %8.8lx: %4.4lx", mem & ~0xa4000000, retval); + Console.WriteLn("DEV9 read16 %8.8lx: %4.4lx", mem & ~0xa4000000, retval); return retval; } @@ -270,7 +270,7 @@ mem32_t __fastcall _ext_memRead32(u32 mem) case 7: // dev9 { mem32_t retval = DEV9read32(mem & ~0xa4000000); - Console::WriteLn("DEV9 read32 %8.8lx: %8.8lx", mem & ~0xa4000000, retval); + Console.WriteLn("DEV9 read32 %8.8lx: %8.8lx", mem & ~0xa4000000, retval); return retval; } } @@ -322,7 +322,7 @@ void __fastcall _ext_memWrite8 (u32 mem, mem8_t value) gsWrite8(mem, value); return; case 7: // dev9 DEV9write8(mem & ~0xa4000000, value); - Console::WriteLn("DEV9 write8 %8.8lx: %2.2lx", mem & ~0xa4000000, value); + Console.WriteLn("DEV9 write8 %8.8lx: %2.2lx", mem & ~0xa4000000, value); return; } @@ -345,7 +345,7 @@ void __fastcall _ext_memWrite16(u32 mem, mem16_t value) gsWrite16(mem, value); return; case 7: // dev9 DEV9write16(mem & ~0xa4000000, value); - Console::WriteLn("DEV9 write16 %8.8lx: %4.4lx", mem & ~0xa4000000, value); + Console.WriteLn("DEV9 write16 %8.8lx: %4.4lx", mem & ~0xa4000000, value); return; case 8: // spu2 SPU2write(mem, value); return; @@ -362,7 +362,7 @@ void __fastcall _ext_memWrite32(u32 mem, mem32_t value) gsWrite32(mem, value); return; case 7: // dev9 DEV9write32(mem & ~0xa4000000, value); - Console::WriteLn("DEV9 write32 %8.8lx: %8.8lx", mem & ~0xa4000000, value); + Console.WriteLn("DEV9 write32 %8.8lx: %8.8lx", mem & ~0xa4000000, value); return; } MEM_LOG("Unknown Memory write32 to address %x with data %8.8x", mem, value); @@ -546,7 +546,7 @@ void __fastcall vuMicroWrite128(u32 addr,const mem128_t* data) void memSetPageAddr(u32 vaddr, u32 paddr) { - //Console::WriteLn("memSetPageAddr: %8.8x -> %8.8x", vaddr, paddr); + //Console.WriteLn("memSetPageAddr: %8.8x -> %8.8x", vaddr, paddr); vtlb_VMap(vaddr,paddr,0x1000); @@ -554,7 +554,7 @@ void memSetPageAddr(u32 vaddr, u32 paddr) void memClearPageAddr(u32 vaddr) { - //Console::WriteLn("memClearPageAddr: %8.8x", vaddr); + //Console.WriteLn("memClearPageAddr: %8.8x", vaddr); vtlb_VMapUnmap(vaddr,0x1000); // -> whut ? @@ -851,9 +851,9 @@ void mmap_MarkCountedRamPage( u32 paddr ) return; // skip town if we're already protected. if( m_PageProtectInfo[rampage].Mode == ProtMode_Manual ) - DbgCon::WriteLn( "dyna_page_reset @ 0x%05x", paddr>>12 ); + DbgCon.WriteLn( "dyna_page_reset @ 0x%05x", paddr>>12 ); else - DbgCon::WriteLn( "Write-protected page @ 0x%05x", paddr>>12 ); + DbgCon.WriteLn( "Write-protected page @ 0x%05x", paddr>>12 ); m_PageProtectInfo[rampage].Mode = ProtMode_Write; HostSys::MemProtect( &psM[rampage<<12], 1, Protect_ReadOnly ); @@ -871,7 +871,7 @@ void mmap_ClearCpuBlock( uint offset ) jASSUME( m_PageProtectInfo[rampage].Mode != ProtMode_Manual ); //#ifndef __LINUX__ // this function is called from the signal handler - //DbgCon::WriteLn( "Manual page @ 0x%05x", m_PageProtectInfo[rampage].ReverseRamMap>>12 ); + //DbgCon.WriteLn( "Manual page @ 0x%05x", m_PageProtectInfo[rampage].ReverseRamMap>>12 ); //#endif HostSys::MemProtect( &psM[rampage<<12], 1, Protect_ReadWrite ); @@ -884,7 +884,7 @@ void mmap_ClearCpuBlock( uint offset ) // to ensure the EErec is also reset in conjunction with calling this function. void mmap_ResetBlockTracking() { - DevCon::WriteLn( "vtlb/mmap: Block Tracking reset..." ); + DevCon.WriteLn( "vtlb/mmap: Block Tracking reset..." ); memzero( m_PageProtectInfo ); HostSys::MemProtect( psM, Ps2MemSize::Base, Protect_ReadWrite ); } diff --git a/pcsx2/Patch.cpp b/pcsx2/Patch.cpp index e071ab81f3..b02fcf3107 100644 --- a/pcsx2/Patch.cpp +++ b/pcsx2/Patch.cpp @@ -437,7 +437,7 @@ void applypatch(int place) { int i; - if (place == 0) Console::WriteLn(" patchnumber: %d", patchnumber); + if (place == 0) Console.WriteLn(" patchnumber: %d", patchnumber); for ( i = 0; i < patchnumber; i++ ) { @@ -447,15 +447,15 @@ void applypatch(int place) void patchFunc_comment( char * text1, char * text2 ) { - Console::WriteLn( "comment: %s", text2 ); + Console.WriteLn( "comment: %s", text2 ); } void patchFunc_gametitle( char * text1, char * text2 ) { - Console::WriteLn( "gametitle: %s", text2 ); + Console.WriteLn( "gametitle: %s", text2 ); strgametitle.FromAscii( text2 ); - Console::SetTitle( strgametitle ); + Console.SetTitle( strgametitle ); } void patchFunc_patch( char * cmd, char * param ) @@ -466,7 +466,7 @@ void patchFunc_patch( char * cmd, char * param ) { // TODO : Use wxLogError for this, once we have full unicode compliance on cmd/params vars. //wxLogError( L"Patch ERROR: Maximum number of patches reached: %s=%s", cmd, param ); - Console::Error( "Patch ERROR: Maximum number of patches reached: %s=%s", cmd, param ); + Console.Error( "Patch ERROR: Maximum number of patches reached: %s=%s", cmd, param ); return; } @@ -483,7 +483,7 @@ void patchFunc_patch( char * cmd, char * param ) patch[ patchnumber ].cpu = (patch_cpu_type)PatchTableExecute( pText, NULL, cpuCore ); if ( patch[ patchnumber ].cpu == 0 ) { - Console::Error( "Unrecognized patch '%s'", pText ); + Console.Error( "Unrecognized patch '%s'", pText ); return; } @@ -496,7 +496,7 @@ void patchFunc_patch( char * cmd, char * param ) patch[ patchnumber ].type = (patch_data_type)PatchTableExecute( pText, NULL, dataType ); if ( patch[ patchnumber ].type == 0 ) { - Console::Error( "Unrecognized patch '%s'", pText ); + Console.Error( "Unrecognized patch '%s'", pText ); return; } @@ -648,7 +648,7 @@ void inifile_read( const char * name ) if( !f1 ) { - Console::WriteLn("No patch found. Resuming execution without a patch (this is NOT an error)." ); + Console.WriteLn("No patch found. Resuming execution without a patch (this is NOT an error)." ); return; } @@ -666,7 +666,7 @@ int AddPatch(int Mode, int Place, int Address, int Size, u64 data) if ( patchnumber >= MAX_PATCH ) { - Console::Error( "Patch ERROR: Maximum number of patches reached."); + Console.Error( "Patch ERROR: Maximum number of patches reached."); return -1; } @@ -723,7 +723,7 @@ void patchFunc_roundmode( char * cmd, char * param ) if( type == 0xffff ) { - Console::WriteLn("bad argument (%s) to round mode! skipping...\n", pText); + Console.WriteLn("bad argument (%s) to round mode! skipping...\n", pText); break; } diff --git a/pcsx2/Patch.h b/pcsx2/Patch.h index 6498fb8dd6..6d6a624f33 100644 --- a/pcsx2/Patch.h +++ b/pcsx2/Patch.h @@ -28,7 +28,7 @@ while ( *param && ( *param != ',' ) ) param++; \ if ( *param ) param++; \ while ( *param && ( *param == ' ' ) ) param++; \ - if ( *param == 0 ) { Console::Error( _( "Not enough params for inicommand" ) ); return; } + if ( *param == 0 ) { Console.Error( _( "Not enough params for inicommand" ) ); return; } // // Enums diff --git a/pcsx2/Pcsx2Config.cpp b/pcsx2/Pcsx2Config.cpp index 880c23bafd..c65972bb70 100644 --- a/pcsx2/Pcsx2Config.cpp +++ b/pcsx2/Pcsx2Config.cpp @@ -172,6 +172,12 @@ void Pcsx2Config::LoadSave( IniInterface& ini ) ini.Flush(); } +bool Pcsx2Config::MultitapEnabled( uint port ) const +{ + pxAssert( port < 2 ); + return (port==0) ? MultitapPort0_Enabled : MultitapPort1_Enabled; +} + void Pcsx2Config::Load( const wxString& srcfile ) { //m_IsLoaded = true; diff --git a/pcsx2/PluginManager.cpp b/pcsx2/PluginManager.cpp index 5d42a3caaa..a6b3992ace 100644 --- a/pcsx2/PluginManager.cpp +++ b/pcsx2/PluginManager.cpp @@ -162,7 +162,7 @@ static void CALLBACK GS_printf(int timeout, char *fmt, ...) vsprintf(msg, fmt, list); va_end(list); - Console::WriteLn(msg); + Console.WriteLn(msg); } // PAD @@ -662,13 +662,13 @@ static void PS2E_CALLBACK pcsx2_OSD_WriteLn( int icon, const char* msg ) PluginManager::PluginManager( const wxString (&folders)[PluginId_Count] ) { - Console::Status( "Loading plugins..." ); + Console.Status( "Loading plugins..." ); const PluginInfo* pi = tbl_PluginInfo; do { const PluginsEnum_t pid = pi->id; - Console::WriteLn( "\tBinding %s\t: %s ", tbl_PluginInfo[pid].shortname, folders[pid].ToUTF8().data() ); + Console.WriteLn( "\tBinding %s\t: %s ", tbl_PluginInfo[pid].shortname, folders[pid].ToUTF8().data() ); if( folders[pid].IsEmpty() ) throw Exception::InvalidArgument( "Empty plugin filename." ); @@ -705,7 +705,7 @@ PluginManager::PluginManager( const wxString (&folders)[PluginId_Count] ) PADinit = (_PADinit)m_info[PluginId_PAD].CommonBindings.Init; m_info[PluginId_PAD].CommonBindings.Init = _hack_PADinit; - Console::Status( "Plugins loaded successfully.\n" ); + Console.Status( "Plugins loaded successfully.\n" ); // HACK! Manually bind the Internal MemoryCard plugin for now, until // we get things more completed in the new plugin api. @@ -887,7 +887,7 @@ void PluginManager::Open( PluginsEnum_t pid ) { if( m_info[pid].IsOpened ) return; - Console::WriteLn( "\tOpening %s", tbl_PluginInfo[pid].shortname ); + Console.WriteLn( "\tOpening %s", tbl_PluginInfo[pid].shortname ); // Each Open needs to be called explicitly. >_< @@ -911,7 +911,7 @@ void PluginManager::Open( PluginsEnum_t pid ) void PluginManager::Open() { - Console::Status( "Opening plugins..." ); + Console.Status( "Opening plugins..." ); const PluginInfo* pi = tbl_PluginInfo; do { Open( pi->id ); @@ -924,13 +924,13 @@ void PluginManager::Open() if (GSopen2) mtgsThread.WaitForOpen(); mtgsThread.PollStatus(); - Console::Status( "Plugins opened successfully." ); + Console.Status( "Plugins opened successfully." ); } void PluginManager::Close( PluginsEnum_t pid ) { if( !m_info[pid].IsOpened ) return; - Console::Status( "\tClosing %s", tbl_PluginInfo[pid].shortname ); + Console.Status( "\tClosing %s", tbl_PluginInfo[pid].shortname ); if( pid == PluginId_GS ) { @@ -948,7 +948,7 @@ void PluginManager::Close( PluginsEnum_t pid ) void PluginManager::Close( bool closegs ) { - DbgCon::Status( "Closing plugins..." ); + DbgCon.Status( "Closing plugins..." ); // Close plugins in reverse order of the initialization procedure. @@ -958,7 +958,7 @@ void PluginManager::Close( bool closegs ) Close( tbl_PluginInfo[i].id ); } - DbgCon::Status( "Plugins closed successfully." ); + DbgCon.Status( "Plugins closed successfully." ); } // Initializes all plugins. Plugin initialization should be done once for every new emulation @@ -979,10 +979,10 @@ void PluginManager::Init() if( m_info[pid].IsInitialized ) continue; if( !printlog ) { - Console::Status( "Initializing plugins..." ); + Console.Status( "Initializing plugins..." ); printlog = true; } - Console::WriteLn( "\tInit %s", tbl_PluginInfo[pid].shortname ); + Console.WriteLn( "\tInit %s", tbl_PluginInfo[pid].shortname ); m_info[pid].IsInitialized = true; if( 0 != m_info[pid].CommonBindings.Init() ) throw Exception::PluginInitError( pid ); @@ -999,7 +999,7 @@ void PluginManager::Init() } if( printlog ) - Console::Status( "Plugins initialized successfully.\n" ); + Console.Status( "Plugins initialized successfully.\n" ); } // Shuts down all plugins. Plugins are closed first, if necessary. @@ -1013,7 +1013,7 @@ void PluginManager::Shutdown() mtgsThread.Cancel(); // speedier shutdown! Close(); - DbgCon::Status( "Shutting down plugins..." ); + DbgCon.Status( "Shutting down plugins..." ); // Shutdown plugins in reverse order (probably doesn't matter... // ... but what the heck, right?) @@ -1022,7 +1022,7 @@ void PluginManager::Shutdown() { const PluginsEnum_t pid = tbl_PluginInfo[i].id; if( !m_info[pid].IsInitialized ) continue; - DevCon::WriteLn( "\tShutdown %s", tbl_PluginInfo[pid].shortname ); + DevCon.WriteLn( "\tShutdown %s", tbl_PluginInfo[pid].shortname ); m_info[pid].IsInitialized = false; m_info[pid].CommonBindings.Shutdown(); } @@ -1035,7 +1035,7 @@ void PluginManager::Shutdown() SysPlugins.Mcd = NULL; } - DbgCon::Status( "Plugins shutdown successfully." ); + DbgCon.Status( "Plugins shutdown successfully." ); } // For internal use only, unless you're the MTGS. Then it's for you too! @@ -1063,7 +1063,7 @@ bool PluginManager::DoFreeze( PluginsEnum_t pid, int mode, freezeData* data ) // void PluginManager::Freeze( PluginsEnum_t pid, SaveStateBase& state ) { - Console::WriteLn( "\t%s %s", state.IsSaving() ? "Saving" : "Loading", + Console.WriteLn( "\t%s %s", state.IsSaving() ? "Saving" : "Loading", tbl_PluginInfo[pid].shortname ); freezeData fP = { 0, NULL }; @@ -1078,7 +1078,7 @@ void PluginManager::Freeze( PluginsEnum_t pid, SaveStateBase& state ) // no state data to read, but the plugin expects some state data. // Issue a warning to console... if( fP.size != 0 ) - Console::Notice( "\tWarning: No data for this plugin was found. Plugin status may be unpredictable." ); + Console.Notice( "\tWarning: No data for this plugin was found. Plugin status may be unpredictable." ); return; // Note: Size mismatch check could also be done here on loading, but diff --git a/pcsx2/Plugins.h b/pcsx2/Plugins.h index 0e3e06edcf..aa91c8af5d 100644 --- a/pcsx2/Plugins.h +++ b/pcsx2/Plugins.h @@ -228,17 +228,17 @@ public: PluginManagerBase() {} virtual ~PluginManagerBase() {} - virtual void Init() { wxASSERT_MSG( false, L"Null PluginManager!" ); } + virtual void Init() { pxFail( "Null PluginManager!" ); } virtual void Shutdown() {} virtual void Open() { } - virtual void Open( PluginsEnum_t pid ) { wxASSERT_MSG( false, L"Null PluginManager!" ); } + virtual void Open( PluginsEnum_t pid ) { pxFail( "Null PluginManager!" ); } virtual void Close( PluginsEnum_t pid ) {} virtual void Close( bool closegs=true ) {} - virtual void Freeze( PluginsEnum_t pid, SaveStateBase& state ) { wxASSERT_MSG( false, L"Null PluginManager!" ); } + virtual void Freeze( PluginsEnum_t pid, SaveStateBase& state ) { pxFail( "Null PluginManager!" ); } virtual bool DoFreeze( PluginsEnum_t pid, int mode, freezeData* data ) { - wxASSERT_MSG( false, L"Null PluginManager!" ); + pxFail( "Null PluginManager!" ); return false; } diff --git a/pcsx2/PrecompiledHeader.h b/pcsx2/PrecompiledHeader.h index a6cc27a5f9..3212393c92 100644 --- a/pcsx2/PrecompiledHeader.h +++ b/pcsx2/PrecompiledHeader.h @@ -69,10 +69,6 @@ typedef int BOOL; #define TRUE 1 #define FALSE 0 -#ifndef wxASSERT_MSG_A -# define wxASSERT_MSG_A( cond, msg ) wxASSERT_MSG( cond, wxString::FromAscii(msg).c_str() ); -#endif - ////////////////////////////////////////////////////////////////////////////////////////// // Begin Pcsx2 Includes: Add items here that are local to Pcsx2 but stay relatively // unchanged for long periods of time, or happen to be used by almost everything, so they @@ -82,6 +78,8 @@ typedef int BOOL; #include "Pcsx2Defs.h" #include "i18n.h" #include "Config.h" + +#include "Utilities/Assertions.h" #include "Utilities/wxBaseTools.h" #include "Utilities/ScopedPtr.h" #include "Utilities/Path.h" diff --git a/pcsx2/R3000A.cpp b/pcsx2/R3000A.cpp index a9b5481c87..c13184ce6f 100644 --- a/pcsx2/R3000A.cpp +++ b/pcsx2/R3000A.cpp @@ -72,7 +72,7 @@ void psxShutdown() { void psxException(u32 code, u32 bd) { // PSXCPU_LOG("psxException %x: %x, %x", code, psxHu32(0x1070), psxHu32(0x1074)); - //Console::WriteLn("!! psxException %x: %x, %x", code, psxHu32(0x1070), psxHu32(0x1074)); + //Console.WriteLn("!! psxException %x: %x, %x", code, psxHu32(0x1070), psxHu32(0x1074)); // Set the Cause psxRegs.CP0.n.Cause &= ~0x7f; psxRegs.CP0.n.Cause |= code; @@ -166,7 +166,7 @@ __forceinline void PSX_INT( IopEventId n, s32 ecycle ) // Exception: IRQ16 - SIO - it drops ints like crazy when handling PAD stuff. //if( /*n!=16 &&*/ psxRegs.interrupt & (1< Twice-thrown int on IRQ %d", n ); + // Console.WriteLn( "***** IOP > Twice-thrown int on IRQ %d", n ); psxRegs.interrupt |= 1 << n; @@ -266,7 +266,7 @@ void iopTestIntc() cpuSetNextBranchDelta( 16 ); iopBranchAction = true; - //Console::Error( "** IOP Needs an EE EventText, kthx ** %d", psxCycleEE ); + //Console.Error( "** IOP Needs an EE EventText, kthx ** %d", psxCycleEE ); // Note: No need to set the iop's branch delta here, since the EE // will run an IOP branch test regardless. diff --git a/pcsx2/R3000AInterpreter.cpp b/pcsx2/R3000AInterpreter.cpp index 582364f3f7..b347792304 100644 --- a/pcsx2/R3000AInterpreter.cpp +++ b/pcsx2/R3000AInterpreter.cpp @@ -217,7 +217,7 @@ void zeroEx() fname = irxlibs[i].names[code]; //if( strcmp(fname, "setIOPrcvaddr") == 0 ) { -// Console::WriteLn("yo"); +// Console.WriteLn("yo"); // varLog |= 0x100000; // Log = 1; // } @@ -258,15 +258,15 @@ void zeroEx() } if (!strncmp(lib, "loadcore", 8) && code == 6) { - DevCon::WriteLn("loadcore RegisterLibraryEntries (%x): %8.8s", psxRegs.pc, iopVirtMemR(psxRegs.GPR.n.a0+12)); + DevCon.WriteLn("loadcore RegisterLibraryEntries (%x): %8.8s", psxRegs.pc, iopVirtMemR(psxRegs.GPR.n.a0+12)); } if (!strncmp(lib, "intrman", 7) && code == 4) { - DevCon::WriteLn("intrman RegisterIntrHandler (%x): intr %s, handler %x", psxRegs.pc, intrname[psxRegs.GPR.n.a0], psxRegs.GPR.n.a2); + DevCon.WriteLn("intrman RegisterIntrHandler (%x): intr %s, handler %x", psxRegs.pc, intrname[psxRegs.GPR.n.a0], psxRegs.GPR.n.a2); } if (!strncmp(lib, "sifcmd", 6) && code == 17) { - DevCon::WriteLn("sifcmd sceSifRegisterRpc (%x): rpc_id %x", psxRegs.pc, psxRegs.GPR.n.a1); + DevCon.WriteLn("sifcmd sceSifRegisterRpc (%x): rpc_id %x", psxRegs.pc, psxRegs.GPR.n.a1); } if (!strncmp(lib, "sysclib", 8)) diff --git a/pcsx2/R3000AOpcodeTables.cpp b/pcsx2/R3000AOpcodeTables.cpp index ded950d7e7..29b3845845 100644 --- a/pcsx2/R3000AOpcodeTables.cpp +++ b/pcsx2/R3000AOpcodeTables.cpp @@ -156,7 +156,7 @@ void psxSYSCALL() { } void psxRFE() { -// Console::WriteLn("RFE\n"); +// Console.WriteLn("RFE\n"); psxRegs.CP0.n.Status = (psxRegs.CP0.n.Status & 0xfffffff0) | ((psxRegs.CP0.n.Status & 0x3c) >> 2); // Log=0; @@ -300,7 +300,7 @@ void psxCTC0() { _rFs_ = _u32(_rRt_); } * Format: ? * *********************************************************/ void psxNULL() { -Console::Notice("psx: Unimplemented op %x", psxRegs.code); +Console.Notice("psx: Unimplemented op %x", psxRegs.code); } void psxSPECIAL() { diff --git a/pcsx2/R5900.cpp b/pcsx2/R5900.cpp index abb4e28480..2e0bfef4ad 100644 --- a/pcsx2/R5900.cpp +++ b/pcsx2/R5900.cpp @@ -113,12 +113,12 @@ __releaseinline void cpuException(u32 code, u32 bd) errLevel2 = TRUE; checkStatus = (cpuRegs.CP0.n.Status.b.DEV == 0); // for perf/debug exceptions - Console::Error("*PCSX2* FIX ME: Level 2 cpuException"); + Console.Error("*PCSX2* FIX ME: Level 2 cpuException"); if ((code & 0x38000) <= 0x8000 ) { //Reset / NMI cpuRegs.pc = 0xBFC00000; - Console::Notice("Reset request"); + Console.Notice("Reset request"); UpdateCP0Status(); return; } @@ -127,7 +127,7 @@ __releaseinline void cpuException(u32 code, u32 bd) else if((code & 0x38000) == 0x18000) offset = 0x100; //Debug else - Console::Error("Unknown Level 2 Exception!! Cause %x", code); + Console.Error("Unknown Level 2 Exception!! Cause %x", code); } if (cpuRegs.CP0.n.Status.b.EXL == 0) @@ -135,7 +135,7 @@ __releaseinline void cpuException(u32 code, u32 bd) cpuRegs.CP0.n.Status.b.EXL = 1; if (bd) { - Console::Notice("branch delay!!"); + Console.Notice("branch delay!!"); cpuRegs.CP0.n.EPC = cpuRegs.pc - 4; cpuRegs.CP0.n.Cause |= 0x80000000; } @@ -148,7 +148,7 @@ __releaseinline void cpuException(u32 code, u32 bd) else { offset = 0x180; //Override the cause - if (errLevel2) Console::Notice("cpuException: Status.EXL = 1 cause %x", code); + if (errLevel2) Console.Notice("cpuException: Status.EXL = 1 cause %x", code); } if (checkStatus) @@ -161,10 +161,10 @@ __releaseinline void cpuException(u32 code, u32 bd) void cpuTlbMiss(u32 addr, u32 bd, u32 excode) { - Console::Error("cpuTlbMiss pc:%x, cycl:%x, addr: %x, status=%x, code=%x", + Console.Error("cpuTlbMiss pc:%x, cycl:%x, addr: %x, status=%x, code=%x", cpuRegs.pc, cpuRegs.cycle, addr, cpuRegs.CP0.n.Status.val, excode); - if (bd) Console::Notice("branch delay!!"); + if (bd) Console.Notice("branch delay!!"); assert(0); // temporary @@ -201,7 +201,7 @@ __forceinline void _cpuTestMissingINTC() { if (cpuRegs.CP0.n.Status.val & 0x400 && psHu32(INTC_STAT) & psHu32(INTC_MASK)) { if ((cpuRegs.interrupt & (1 << 30)) == 0) { - Console::Error("*PCSX2*: Error, missing INTC Interrupt"); + Console.Error("*PCSX2*: Error, missing INTC Interrupt"); } } } @@ -211,7 +211,7 @@ __forceinline void _cpuTestMissingDMAC() { (psHu16(0xe012) & psHu16(0xe010) || psHu16(0xe010) & 0x8000)) { if ((cpuRegs.interrupt & (1 << 31)) == 0) { - Console::Error("*PCSX2*: Error, missing DMAC Interrupt"); + Console.Error("*PCSX2*: Error, missing DMAC Interrupt"); } } } @@ -319,7 +319,7 @@ static __forceinline void _cpuTestTIMR() if ( (cpuRegs.CP0.n.Status.val & 0x8000) && cpuRegs.CP0.n.Count >= cpuRegs.CP0.n.Compare && cpuRegs.CP0.n.Count < cpuRegs.CP0.n.Compare+1000 ) { - Console::Status("timr intr: %x, %x", cpuRegs.CP0.n.Count, cpuRegs.CP0.n.Compare); + Console.Status("timr intr: %x, %x", cpuRegs.CP0.n.Count, cpuRegs.CP0.n.Compare); cpuException(0x808000, cpuRegs.branch); } } @@ -396,7 +396,7 @@ __forceinline void _cpuBranchTest_Shared() if( iopBranchAction ) { //if( EEsCycle < -450 ) - // Console::WriteLn( " IOP ahead by: %d cycles", -EEsCycle ); + // Console.WriteLn( " IOP ahead by: %d cycles", -EEsCycle ); // Experimental and Probably Unnecessry Logic --> // Check if the EE already has an exception pending, and if so we shouldn't @@ -420,7 +420,7 @@ __forceinline void _cpuBranchTest_Shared() int cycleCount = std::min( EEsCycle, (s32)(eeWaitCycles>>4) ); int cyclesRun = cycleCount - psxCpu->ExecuteBlock( cycleCount ); EEsCycle -= cyclesRun; - //Console::Notice( "IOP Exception-Pending Execution -- EEsCycle: %d", EEsCycle ); + //Console.Notice( "IOP Exception-Pending Execution -- EEsCycle: %d", EEsCycle ); } else*/ { @@ -456,7 +456,7 @@ __forceinline void _cpuBranchTest_Shared() // IOP extra timeslices in short order. cpuSetNextBranchDelta( 48 ); - //Console::Notice( "EE ahead of the IOP -- Rapid Branch! %d", EEsCycle ); + //Console.Notice( "EE ahead of the IOP -- Rapid Branch! %d", EEsCycle ); } // The IOP could be running ahead/behind of us, so adjust the iop's next branch by its @@ -556,7 +556,7 @@ void cpuExecuteBios() // Set the video mode to user's default request: gsSetRegionMode( (GS_RegionMode)EmuConfig.Video.DefaultRegionMode ); - Console::Status( "Executing Bios Stub..." ); + Console.Status( "Executing Bios Stub..." ); PCSX2_MEM_PROTECT_BEGIN(); g_ExecBiosHack = true; @@ -588,7 +588,7 @@ void cpuExecuteBios() // with new faster versions: Cpu->Reset(); - Console::Notice("Execute Bios Stub Complete"); + Console.Notice("Execute Bios Stub Complete"); //GSprintf(5, "PCSX2 " PCSX2_VERSION "\nExecuteBios Complete\n"); } diff --git a/pcsx2/R5900OpcodeImpl.cpp b/pcsx2/R5900OpcodeImpl.cpp index df3ae57229..68bc17ba7e 100644 --- a/pcsx2/R5900OpcodeImpl.cpp +++ b/pcsx2/R5900OpcodeImpl.cpp @@ -136,9 +136,9 @@ void Unknown() { CPU_LOG("%8.8lx: Unknown opcode called", cpuRegs.pc); } -void MMI_Unknown() { Console::Notice("Unknown MMI opcode called"); } -void COP0_Unknown() { Console::Notice("Unknown COP0 opcode called"); } -void COP1_Unknown() { Console::Notice("Unknown FPU/COP1 opcode called"); } +void MMI_Unknown() { Console.Notice("Unknown MMI opcode called"); } +void COP0_Unknown() { Console.Notice("Unknown COP0 opcode called"); } +void COP1_Unknown() { Console.Notice("Unknown FPU/COP1 opcode called"); } @@ -761,7 +761,7 @@ int __Deci2Call(int call, u32 *addr) else { deci2handler = NULL; - DevCon::Notice( "Deci2Call.Open > NULL address ignored." ); + DevCon.Notice( "Deci2Call.Open > NULL address ignored." ); } return 1; @@ -780,7 +780,7 @@ int __Deci2Call(int call, u32 *addr) deci2addr[3], deci2addr[2], deci2addr[1], deci2addr[0]); // cpuRegs.pc = deci2handler; -// Console::WriteLn("deci2msg: %s", (char*)PSM(deci2addr[4]+0xc)); +// Console.WriteLn("deci2msg: %s", (char*)PSM(deci2addr[4]+0xc)); if (deci2addr == NULL) return 1; if (deci2addr[1]>0xc){ u8* pdeciaddr = (u8*)dmaGetAddr(deci2addr[4]+0xc); @@ -790,7 +790,7 @@ int __Deci2Call(int call, u32 *addr) pdeciaddr += (deci2addr[4]+0xc)%16; memcpy(deci2buffer, pdeciaddr, deci2addr[1]-0xc); deci2buffer[deci2addr[1]-0xc>=255?255:deci2addr[1]-0xc]='\0'; - Console::Write( Color_Cyan, deci2buffer ); + Console.Write( Color_Cyan, deci2buffer ); } deci2addr[3] = 0; return 1; @@ -809,7 +809,7 @@ int __Deci2Call(int call, u32 *addr) case 0x10://kputs if( addr != NULL ) - Console::Write( Color_Cyan, "%s", PSM(*addr)); + Console.Write( Color_Cyan, "%s", PSM(*addr)); return 1; } @@ -831,7 +831,7 @@ void SYSCALL() if (call == 0x7c) { if(cpuRegs.GPR.n.a0.UL[0] == 0x10) - Console::Write( Color_Cyan, (char*)PSM(memRead32(cpuRegs.GPR.n.a1.UL[0])) ); + Console.Write( Color_Cyan, (char*)PSM(memRead32(cpuRegs.GPR.n.a1.UL[0])) ); else __Deci2Call( cpuRegs.GPR.n.a0.UL[0], (u32*)PSM(cpuRegs.GPR.n.a1.UL[0]) ); } diff --git a/pcsx2/RecoverySystem.cpp b/pcsx2/RecoverySystem.cpp index 2aeb46da7d..5266aaec09 100644 --- a/pcsx2/RecoverySystem.cpp +++ b/pcsx2/RecoverySystem.cpp @@ -31,6 +31,9 @@ static bool state_buffer_lock = false; // form the main thread. bool sys_resume_lock = false; +// -------------------------------------------------------------------------------------- +// StateThread_Freeze +// -------------------------------------------------------------------------------------- class StateThread_Freeze : public PersistentThread { typedef PersistentThread _parent; @@ -38,9 +41,9 @@ class StateThread_Freeze : public PersistentThread public: StateThread_Freeze( const wxString& file ) { - m_name = L"SaveState::CopyAndZip"; + m_name = L"SaveState::Freeze"; - DevAssert( wxThread::IsMain(), "StateThread creation is allowed from the Main thread only." ); + AllowFromMainThreadOnly(); if( state_buffer_lock ) throw Exception::RuntimeError( "Cannot save state; a previous save or load action is already in progress." ); @@ -49,22 +52,63 @@ public: } protected: - sptr ExecuteTask() + void OnStart() {} + void ExecuteTask() { memSavingState( state_buffer ).FreezeAll(); - return 0; } - void DoThreadCleanup() + void OnThreadCleanup() { wxCommandEvent evt( pxEVT_FreezeFinished ); evt.SetClientData( this ); wxGetApp().AddPendingEvent( evt ); - _parent::DoThreadCleanup(); + _parent::OnThreadCleanup(); } }; +// -------------------------------------------------------------------------------------- +// +// -------------------------------------------------------------------------------------- +class StateThread_Thaw : public PersistentThread +{ + typedef PersistentThread _parent; + +public: + StateThread_Thaw( const wxString& file ) + { + m_name = L"SaveState::Thaw"; + + AllowFromMainThreadOnly(); + if( state_buffer_lock ) + throw Exception::RuntimeError( "Cannot sload state; a previous save or load action is already in progress." ); + + Start(); + sys_resume_lock = true; + } + +protected: + void OnStart() {} + + void ExecuteTask() + { + memSavingState( state_buffer ).FreezeAll(); + } + + void OnThreadCleanup() + { + wxCommandEvent evt( pxEVT_FreezeFinished ); + evt.SetClientData( this ); + wxGetApp().AddPendingEvent( evt ); + + _parent::OnThreadCleanup(); + } +}; + +// -------------------------------------------------------------------------------------- +// +// -------------------------------------------------------------------------------------- class StateThread_ZipToDisk : public PersistentThread { typedef PersistentThread _parent; @@ -77,7 +121,7 @@ public: { m_name = L"SaveState::ZipToDisk"; - DevAssert( wxThread::IsMain(), "StateThread creation is allowed from the Main thread only." ); + AllowFromMainThreadOnly(); if( state_buffer_lock ) throw Exception::RuntimeError( "Cannot save state; a previous save or load action is already in progress." ); @@ -101,26 +145,29 @@ public: } protected: - sptr ExecuteTask() + void OnStart() {} + + void ExecuteTask() { Sleep( 2 ); if( gzwrite( (gzFile)m_gzfp, state_buffer.GetPtr(), state_buffer.GetSizeInBytes() ) < state_buffer.GetSizeInBytes() ) throw Exception::BadStream(); - - return 0; } - void DoThreadCleanup() + void OnThreadCleanup() { wxCommandEvent evt( pxEVT_FreezeFinished ); evt.SetClientData( this ); // tells message to clean us up. wxGetApp().AddPendingEvent( evt ); - _parent::DoThreadCleanup(); + _parent::OnThreadCleanup(); } }; +// -------------------------------------------------------------------------------------- +// +// -------------------------------------------------------------------------------------- class StateThread_UnzipFromDisk : public PersistentThread { typedef PersistentThread _parent; @@ -133,7 +180,7 @@ public: { m_name = L"SaveState::UnzipFromDisk"; - DevAssert( wxThread::IsMain(), "StateThread creation is allowed from the Main thread only." ); + AllowFromMainThreadOnly(); if( state_buffer_lock ) throw Exception::RuntimeError( "Cannot save state; a previous save or load action is already in progress." ); @@ -157,7 +204,9 @@ public: } protected: - sptr ExecuteTask() + void OnStart() {} + + void ExecuteTask() { // fixme: should start initially with the file size, and then grow from there. @@ -171,13 +220,13 @@ protected: } while( !gzeof(m_gzfp) ); } - void DoThreadCleanup() + void OnThreadCleanup() { wxCommandEvent evt( pxEVT_ThawFinished ); evt.SetClientData( this ); // tells message to clean us up. wxGetApp().AddPendingEvent( evt ); - _parent::DoThreadCleanup(); + _parent::OnThreadCleanup(); } }; @@ -187,32 +236,51 @@ void Pcsx2App::OnFreezeFinished( wxCommandEvent& evt ) state_buffer_lock = false; SysClearExecutionCache(); - SysResume(); + sCoreThread.Resume(); - if( PersistentThread* thread = (PersistentThread*)evt.GetClientData() ) - { - delete thread; - } + delete (PersistentThread*)evt.GetClientData(); } void Pcsx2App::OnThawFinished( wxCommandEvent& evt ) { + PersistentThread* thr = (PersistentThread*)evt.GetClientData(); + if( thr == NULL ) + { + pxAssert( false ); + return; + } + + /*catch( Exception::BadSavedState& ex) + { + // At this point we can return control back to the user, no questions asked. + // StateLoadErrors are only thorwn if the load failed prior to any virtual + // machine memory contents being changed. (usually missing file errors) + + Console.Notice( ex.FormatDiagnosticMessage() ); + sCoreThread.Resume(); + }*/ + state_buffer.Dispose(); state_buffer_lock = false; SysClearExecutionCache(); - SysResume(); + sCoreThread.Resume(); - if( PersistentThread* thread = (PersistentThread*)evt.GetClientData() ) - { - delete thread; - } + delete (PersistentThread*)evt.GetClientData(); } void StateCopy_SaveToFile( const wxString& file ) { if( state_buffer_lock ) return; - // [TODO] Implement optional 7zip compression here? + new StateThread_ZipToDisk( file ); +} + +void StateCopy_LoadFromFile( const wxString& file ) +{ + if( state_buffer_lock ) return; + + sCoreThread.ShortSuspend(); + new StateThread_UnzipFromDisk( file ); } // Saves recovery state info to the given saveslot, or saves the active emulation state diff --git a/pcsx2/SPR.cpp b/pcsx2/SPR.cpp index cfd8e9c228..1cac26802d 100644 --- a/pcsx2/SPR.cpp +++ b/pcsx2/SPR.cpp @@ -38,12 +38,12 @@ static void TestClearVUs(u32 madr, u32 size) { if (madr < 0x11004000) { - DbgCon::Notice("scratch pad clearing vu0"); + DbgCon.Notice("scratch pad clearing vu0"); CpuVU0.Clear(madr&0xfff, size); } else if (madr >= 0x11008000 && madr < 0x1100c000) { - DbgCon::Notice("scratch pad clearing vu1"); + DbgCon.Notice("scratch pad clearing vu1"); CpuVU1.Clear(madr&0x3fff, size); } } @@ -62,7 +62,7 @@ int _SPR0chain() case MFD_VIF1: case MFD_GIF: if ((spr0->madr & ~dmacRegs->rbsr.RMSK) != dmacRegs->rbor.ADDR) - Console::WriteLn("SPR MFIFO Write outside MFIFO area"); + Console.WriteLn("SPR MFIFO Write outside MFIFO area"); else mfifotransferred += spr0->qwc; @@ -101,7 +101,7 @@ void _SPR0interleave() u32 *pMem; if (tqwc == 0) tqwc = qwc; - //Console::WriteLn("dmaSPR0 interleave"); + //Console.WriteLn("dmaSPR0 interleave"); SPR_LOG("SPR0 interleave size=%d, tqwc=%d, sqwc=%d, addr=%lx sadr=%lx", spr0->qwc, tqwc, sqwc, spr0->madr, spr0->sadr); @@ -138,7 +138,7 @@ static __forceinline void _dmaSPR0() { if (dmacRegs->ctrl.STS == STS_fromSPR) { - Console::WriteLn("SPR0 stall %d", dmacRegs->ctrl.STS); + Console.WriteLn("SPR0 stall %d", dmacRegs->ctrl.STS); } // Transfer Dn_QWC from SPR to Dn_MADR @@ -176,7 +176,7 @@ static __forceinline void _dmaSPR0() if (dmacRegs->ctrl.STS == STS_fromSPR) // STS == fromSPR { - Console::WriteLn("SPR stall control"); + Console.WriteLn("SPR stall control"); } switch (id) @@ -196,7 +196,7 @@ static __forceinline void _dmaSPR0() SPR0chain(); if (spr0->chcr.TIE && Tag::IRQ(ptag)) //Check TIE bit of CHCR and IRQ bit of tag { - //Console::WriteLn("SPR0 TIE"); + //Console.WriteLn("SPR0 TIE"); done = TRUE; } @@ -231,9 +231,9 @@ void SPRFROMinterrupt() { case MFD_GIF: { - if ((spr0->madr & ~dmacRegs->rbsr.RMSK) != dmacRegs->rbor.ADDR) Console::WriteLn("GIF MFIFO Write outside MFIFO area"); + if ((spr0->madr & ~dmacRegs->rbsr.RMSK) != dmacRegs->rbor.ADDR) Console.WriteLn("GIF MFIFO Write outside MFIFO area"); spr0->madr = dmacRegs->rbor.ADDR + (spr0->madr & dmacRegs->rbsr.RMSK); - //Console::WriteLn("mfifoGIFtransfer %x madr %x, tadr %x", gif->chcr._u32, gif->madr, gif->tadr); + //Console.WriteLn("mfifoGIFtransfer %x madr %x, tadr %x", gif->chcr._u32, gif->madr, gif->tadr); mfifoGIFtransfer(mfifotransferred); mfifotransferred = 0; if (gif->chcr.STR) return; @@ -241,9 +241,9 @@ void SPRFROMinterrupt() } case MFD_VIF1: { - if ((spr0->madr & ~psHu32(DMAC_RBSR)) != psHu32(DMAC_RBOR)) Console::WriteLn("VIF MFIFO Write outside MFIFO area"); + if ((spr0->madr & ~psHu32(DMAC_RBSR)) != psHu32(DMAC_RBOR)) Console.WriteLn("VIF MFIFO Write outside MFIFO area"); spr0->madr = dmacRegs->rbor.ADDR + (spr0->madr & dmacRegs->rbsr.RMSK); - //Console::WriteLn("mfifoVIF1transfer %x madr %x, tadr %x", vif1ch->chcr._u32, vif1ch->madr, vif1ch->tadr); + //Console.WriteLn("mfifoVIF1transfer %x madr %x, tadr %x", vif1ch->chcr._u32, vif1ch->madr, vif1ch->tadr); mfifoVIF1transfer(mfifotransferred); mfifotransferred = 0; if (vif1ch->chcr.STR) return; @@ -386,7 +386,7 @@ void _dmaSPR1() // toSPR work function { SPR_LOG("dmaIrq Set"); - //Console::WriteLn("SPR1 TIE"); + //Console.WriteLn("SPR1 TIE"); done = true; } diff --git a/pcsx2/SaveState.cpp b/pcsx2/SaveState.cpp index fcea759343..54a06ef309 100644 --- a/pcsx2/SaveState.cpp +++ b/pcsx2/SaveState.cpp @@ -76,7 +76,8 @@ void SaveStateBase::PrepBlock( int size ) void SaveStateBase::FreezeTag( const char* src ) { - wxASSERT( strlen(src) < (sizeof( m_tagspace )-1) ); + const int allowedlen = sizeof( m_tagspace )-1; + pxAssertDev( strlen(src) < allowedlen, wxsFormat( L"Tag name exceeds the allowed length of %d chars.", allowedlen) ); memzero( m_tagspace ); strcpy( m_tagspace, src ); @@ -84,7 +85,7 @@ void SaveStateBase::FreezeTag( const char* src ) if( strcmp( m_tagspace, src ) != 0 ) { - wxASSERT_MSG( false, L"Savestate data corruption detected while reading tag" ); + pxFail( "Savestate data corruption detected while reading tag" ); throw Exception::BadSavedState( // Untranslated diagnostic msg (use default msg for translation) L"Savestate data corruption detected while reading tag: " + wxString::FromAscii(src) @@ -118,7 +119,7 @@ void SaveStateBase::FreezeBios() { if( memcmp( descin, desccmp, 128 ) != 0 ) { - Console::Error( + Console.Error( "\n\tWarning: BIOS Version Mismatch, savestate may be unstable!\n" "\t\tCurrent Version: %s\n" "\t\tSavestate Version: %s\n", @@ -240,7 +241,7 @@ bool SaveStateBase::FreezeSection() FreezeMainMemory(); int realsectsize = m_idx - seekpos; - wxASSERT( sectlen == realsectsize ); + pxAssert( sectlen == realsectsize ); m_sectid++; } break; @@ -311,7 +312,7 @@ bool SaveStateBase::FreezeSection() case FreezeId_Unknown: default: - wxASSERT( IsSaving() ); + pxAssert( IsSaving() ); // Skip unknown sections with a warning log. // Maybe it'll work! (haha?) @@ -321,7 +322,7 @@ bool SaveStateBase::FreezeSection() Freeze( size ); m_tagspace[sizeof(m_tagspace)-1] = 0; - Console::Notice( + Console.Notice( "Warning: Unknown tag encountered while loading savestate; going to ignore it!\n" "\tTagname: %s, Size: %d", m_tagspace, size ); diff --git a/pcsx2/SaveState.h b/pcsx2/SaveState.h index a202999a4d..e0b5c062eb 100644 --- a/pcsx2/SaveState.h +++ b/pcsx2/SaveState.h @@ -200,6 +200,7 @@ extern bool StateCopy_HasPartialState(); extern void StateCopy_FreezeToMem(); extern void StateCopy_ThawFromMem(); extern void StateCopy_SaveToFile( const wxString& file ); +extern void StateCopy_LoadFromFile( const wxString& file ); extern void StateCopy_SaveToSlot( uint num ); extern void StateCopy_Clear(); diff --git a/pcsx2/Sif.cpp b/pcsx2/Sif.cpp index 6a57f8bd5e..b95ac85105 100644 --- a/pcsx2/Sif.cpp +++ b/pcsx2/Sif.cpp @@ -296,7 +296,7 @@ __forceinline void SIF1Dma() if (sif1dma->chcr.TTE) { - Console::WriteLn("SIF1 TTE"); + Console.WriteLn("SIF1 TTE"); SIF1write(ptag + 2, 2); } @@ -338,11 +338,11 @@ __forceinline void SIF1Dma() break; default: - Console::WriteLn("Bad addr1 source chain"); + Console.WriteLn("Bad addr1 source chain"); } if ((sif1dma->chcr.TIE) && (Tag::IRQ(ptag))) { - Console::WriteLn("SIF1 TIE"); + Console.WriteLn("SIF1 TIE"); sif1.end = 1; } } @@ -495,7 +495,7 @@ __forceinline void dmaSIF2() sif2dma->chcr.STR = 0; hwDmacIrq(DMAC_SIF2); - Console::WriteLn("*PCSX2*: dmaSIF2"); + Console.WriteLn("*PCSX2*: dmaSIF2"); } diff --git a/pcsx2/Sio.cpp b/pcsx2/Sio.cpp index 848e35e92f..9808fe3bdb 100644 --- a/pcsx2/Sio.cpp +++ b/pcsx2/Sio.cpp @@ -382,7 +382,7 @@ void SIO_CommandWrite(u8 value,int way) { sio.buf[2]='+'; sio.buf[3]=sio.terminator; //if (sio.k != 0 || (sio.sector & 0xf) != 0) - // Console::Notice("saving : odd position for erase."); + // Console.Notice("saving : odd position for erase."); _EraseMCDBlock((512+16)*(sio.sector&~0xf)); diff --git a/pcsx2/SourceLog.cpp b/pcsx2/SourceLog.cpp index ea53f764f0..ceacc2f12e 100644 --- a/pcsx2/SourceLog.cpp +++ b/pcsx2/SourceLog.cpp @@ -71,7 +71,7 @@ void __Log( const char* fmt, ... ) #ifdef PCSX2_DEVBUILD if (varLog.LogToConsole) // log to console enabled? { - Console::Write(tmp); + Console.Write(tmp); } else if( emuLog != NULL ) // manually write to the logfile. @@ -111,7 +111,7 @@ static __forceinline void _vSourceLog( u16 protocol, u8 source, u32 cpuPc, u32 c if (varLog.LogToConsole) // log to console enabled? { - Console::WriteLn(tmp); + Console.WriteLn(tmp); } else if( emuLog != NULL ) // manually write to the logfile. { diff --git a/pcsx2/Stats.cpp b/pcsx2/Stats.cpp index 39fa8f22e6..427cf9cc2b 100644 --- a/pcsx2/Stats.cpp +++ b/pcsx2/Stats.cpp @@ -41,7 +41,7 @@ void statsClose() { #else f = fopen(LOGS_DIR "/stats.txt", "w"); #endif - if (!f) { Console::WriteLn("Can't open stats.txt"); return; } + if (!f) { Console.WriteLn("Can't open stats.txt"); return; } fprintf(f, "-- PCSX2 v%s statics--\n\n", PCSX2_VERSION); fprintf(f, "Ran for %d seconds\n", t); fprintf(f, "Total VSyncs: %d (%s)\n", stats.vsyncCount, Config.PsxType ? "PAL" : "NTSC"); diff --git a/pcsx2/System.cpp b/pcsx2/System.cpp index e274bd2eba..5c2b73487d 100644 --- a/pcsx2/System.cpp +++ b/pcsx2/System.cpp @@ -42,20 +42,18 @@ SessionOverrideFlags g_Session = {false}; // This function should be called once during program execution. void SysDetect() { - using namespace Console; - - Notice("PCSX2 %d.%d.%d.r%d %s - compiled on " __DATE__, PCSX2_VersionHi, PCSX2_VersionMid, PCSX2_VersionLo, + Console.Notice("PCSX2 %d.%d.%d.r%d %s - compiled on " __DATE__, PCSX2_VersionHi, PCSX2_VersionMid, PCSX2_VersionLo, SVN_REV, SVN_MODS ? "(modded)" : "" ); - Notice("Savestate version: %x", g_SaveVersion); + Console.Notice("Savestate version: %x", g_SaveVersion); cpudetectInit(); - SetColor( Color_Black ); + Console.SetColor( Color_Black ); - WriteLn( "x86Init:" ); - WriteLn( wxsFormat( + Console.WriteLn( "x86Init:" ); + Console.WriteLn( wxsFormat( L"\tCPU vendor name = %s\n" L"\tFamilyID = %x\n" L"\tx86Family = %s\n" @@ -92,11 +90,11 @@ void SysDetect() JoinString( result[0], features[0], L".. " ); JoinString( result[1], features[1], L".. " ); - WriteLn( L"Features Detected:\n\t" + result[0] + (result[1].IsEmpty() ? L"" : (L"\n\t" + result[1])) + L"\n" ); + Console.WriteLn( L"Features Detected:\n\t" + result[0] + (result[1].IsEmpty() ? L"" : (L"\n\t" + result[1])) + L"\n" ); //if ( x86caps.VendorName[0] == 'A' ) //AMD cpu - Console::ClearColor(); + Console.ClearColor(); } // returns the translated error message for the Virtual Machine failing to allocate! @@ -110,7 +108,7 @@ static wxString GetMemoryErrorVM() SysCoreAllocations::SysCoreAllocations() { - Console::Status( "Initializing PS2 virtual machine..." ); + Console.Status( "Initializing PS2 virtual machine..." ); RecSuccess_EE = false; RecSuccess_IOP = false; @@ -148,7 +146,7 @@ SysCoreAllocations::SysCoreAllocations() ); } - Console::Status( "Allocating memory for recompilers..." ); + Console.Status( "Allocating memory for recompilers..." ); try { @@ -157,7 +155,7 @@ SysCoreAllocations::SysCoreAllocations() } catch( Exception::BaseException& ex ) { - Console::Error( L"EE Recompiler Allocation Failed:\n" + ex.FormatDiagnosticMessage() ); + Console.Error( L"EE Recompiler Allocation Failed:\n" + ex.FormatDiagnosticMessage() ); recCpu.Shutdown(); } @@ -168,7 +166,7 @@ SysCoreAllocations::SysCoreAllocations() } catch( Exception::BaseException& ex ) { - Console::Error( L"IOP Recompiler Allocation Failed:\n" + ex.FormatDiagnosticMessage() ); + Console.Error( L"IOP Recompiler Allocation Failed:\n" + ex.FormatDiagnosticMessage() ); psxRec.Shutdown(); } @@ -181,7 +179,7 @@ SysCoreAllocations::SysCoreAllocations() } catch( Exception::BaseException& ex ) { - Console::Error( L"VU0 Recompiler Allocation Failed:\n" + ex.FormatDiagnosticMessage() ); + Console.Error( L"VU0 Recompiler Allocation Failed:\n" + ex.FormatDiagnosticMessage() ); VU0micro::recShutdown(); } @@ -192,7 +190,7 @@ SysCoreAllocations::SysCoreAllocations() } catch( Exception::BaseException& ex ) { - Console::Error( L"VU1 Recompiler Allocation Failed:\n" + ex.FormatDiagnosticMessage() ); + Console.Error( L"VU1 Recompiler Allocation Failed:\n" + ex.FormatDiagnosticMessage() ); VU1micro::recShutdown(); } @@ -252,13 +250,6 @@ void SysClearExecutionCache() vuMicroCpuReset(); } -void SysLoadState( const wxString& srcfile ) -{ - //SysClearExecutionCache(); - //cpuReset(); - //joe.FreezeAll(); -} - // Maps a block of memory for use as a recompiled code buffer, and ensures that the // allocation is below a certain memory address (specified in "bounds" parameter). // The allocated block has code execution privileges. @@ -269,7 +260,7 @@ u8 *SysMmapEx(uptr base, u32 size, uptr bounds, const char *caller) if( (Mem == NULL) || (bounds != 0 && (((uptr)Mem + size) > bounds)) ) { - DevCon::Notice( "First try failed allocating %s at address 0x%x", caller, base ); + DevCon.Notice( "First try failed allocating %s at address 0x%x", caller, base ); // memory allocation *must* have the top bit clear, so let's try again // with NULL (let the OS pick something for us). @@ -279,7 +270,7 @@ u8 *SysMmapEx(uptr base, u32 size, uptr bounds, const char *caller) Mem = (u8*)HostSys::Mmap( NULL, size ); if( bounds != 0 && (((uptr)Mem + size) > bounds) ) { - DevCon::Error( "Fatal Error:\n\tSecond try failed allocating %s, block ptr 0x%x does not meet required criteria.", caller, Mem ); + DevCon.Error( "Fatal Error:\n\tSecond try failed allocating %s, block ptr 0x%x does not meet required criteria.", caller, Mem ); SafeSysMunmap( Mem, size ); // returns NULL, caller should throw an exception. diff --git a/pcsx2/System.h b/pcsx2/System.h index f296977c28..8f3052b2ac 100644 --- a/pcsx2/System.h +++ b/pcsx2/System.h @@ -55,8 +55,6 @@ protected: extern void SysDetect(); // Detects cpu type and fills cpuInfo structs. - -extern void SysLoadState( const wxString& file ); extern void SysClearExecutionCache(); // clears recompiled execution caches! diff --git a/pcsx2/System/SysThreads.cpp b/pcsx2/System/SysThreads.cpp index 99690938e1..e05ee901c0 100644 --- a/pcsx2/System/SysThreads.cpp +++ b/pcsx2/System/SysThreads.cpp @@ -45,14 +45,14 @@ SysSuspendableThread::~SysSuspendableThread() throw() { } -void SysSuspendableThread::Start() +void SysSuspendableThread::OnStart() { - if( !DevAssert( m_ExecMode == ExecMode_NoThreadYet, "SysSustainableThread:Start(): Invalid execution mode" ) ) return; + if( !pxAssertDev( m_ExecMode == ExecMode_NoThreadYet, "SysSustainableThread:Start(): Invalid execution mode" ) ) return; m_ResumeEvent.Reset(); m_SuspendEvent.Reset(); - _parent::Start(); + _parent::OnStart(); } @@ -79,7 +79,7 @@ void SysSuspendableThread::Suspend( bool isBlocking ) if( m_ExecMode == ExecMode_Running ) m_ExecMode = ExecMode_Suspending; - DevAssert( m_ExecMode == ExecMode_Suspending, "ExecMode should be nothing other than Suspended..." ); + pxAssertDev( m_ExecMode == ExecMode_Suspending, "ExecMode should be nothing other than Suspended..." ); } m_sem_event.Post(); m_SuspendEvent.WaitGui(); @@ -120,7 +120,7 @@ void SysSuspendableThread::Resume() } } - DevAssert( m_ExecMode == ExecMode_Suspended, + pxAssertDev( m_ExecMode == ExecMode_Suspended, "SysSuspendableThread is not in a suspended/idle state? wtf!" ); m_ExecMode = ExecMode_Running; @@ -136,11 +136,11 @@ void SysSuspendableThread::Resume() // (Called from the context of this thread only) // -------------------------------------------------------------------------------------- -void SysSuspendableThread::DoThreadCleanup() +void SysSuspendableThread::OnThreadCleanup() { ScopedLock locker( m_lock_ExecMode ); m_ExecMode = ExecMode_NoThreadYet; - _parent::DoThreadCleanup(); + _parent::OnThreadCleanup(); } void SysSuspendableThread::StateCheck( bool isCancelable ) @@ -162,7 +162,7 @@ void SysSuspendableThread::StateCheck( bool isCancelable ) case ExecMode_NoThreadYet: // threads should never have this state set while the thread is in any way // active or alive. (for obvious reasons!!) - DevAssert( false, "Invalid execution state detected." ); + pxFailDev( "Invalid execution state detected." ); break; #endif @@ -272,7 +272,7 @@ void SysCoreThread::ApplySettings( const Pcsx2Config& src ) // -------------------------------------------------------------------------------------- SysCoreThread& SysCoreThread::Get() { - wxASSERT_MSG( tls_coreThread != NULL, L"This function must be called from the context of a running SysCoreThread." ); + pxAssertMsg( tls_coreThread != NULL, L"This function must be called from the context of a running SysCoreThread." ); return *tls_coreThread; } @@ -350,10 +350,10 @@ void SysCoreThread::CpuExecute() static void _cet_callback_cleanup( void* handle ) { - ((SysCoreThread*)handle)->DoThreadCleanup(); + ((SysCoreThread*)handle)->OnThreadCleanup(); } -sptr SysCoreThread::ExecuteTask() +void SysCoreThread::ExecuteTask() { tls_coreThread = this; @@ -361,8 +361,6 @@ sptr SysCoreThread::ExecuteTask() CpuInitializeMess(); StateCheck(); CpuExecute(); - - return 0; } void SysCoreThread::OnSuspendInThread() @@ -378,9 +376,9 @@ void SysCoreThread::OnResumeInThread() // Invoked by the pthread_exit or pthread_cancel -void SysCoreThread::DoThreadCleanup() +void SysCoreThread::OnThreadCleanup() { m_plugins.Shutdown(); - _parent::DoThreadCleanup(); + _parent::OnThreadCleanup(); } diff --git a/pcsx2/System/SysThreads.h b/pcsx2/System/SysThreads.h index fbd1e600aa..51204cfc37 100644 --- a/pcsx2/System/SysThreads.h +++ b/pcsx2/System/SysThreads.h @@ -61,17 +61,16 @@ public: virtual void Resume(); virtual void StateCheck( bool isCancelable = true ); - virtual void DoThreadCleanup(); + virtual void OnThreadCleanup(); // This function is called by Resume immediately prior to releasing the suspension of // the core emulation thread. You should overload this rather than Resume(), since // Resume() has a lot of checks and balances to prevent re-entrance and race conditions. virtual void OnResumeReady() {} - + + virtual void OnStart(); + protected: - // Marked as protected because user code should call Resume instead, which performs - // a thread-safe check/init/resume procedure. - virtual void Start(); // Extending classes should implement this, but should not call it. The parent class // handles invocation by the following guidelines: Called *in thread* from StateCheck() @@ -107,7 +106,7 @@ public: virtual ~SysCoreThread() throw(); virtual void ApplySettings( const Pcsx2Config& src ); - virtual void DoThreadCleanup(); + virtual void OnThreadCleanup(); virtual void ShortSuspend(); virtual void OnResumeReady(); @@ -118,5 +117,5 @@ protected: virtual void Start(); virtual void OnSuspendInThread(); virtual void OnResumeInThread(); - virtual sptr ExecuteTask(); + virtual void ExecuteTask(); }; diff --git a/pcsx2/Tags.h b/pcsx2/Tags.h index 2d35eb566f..cc9c3eee15 100644 --- a/pcsx2/Tags.h +++ b/pcsx2/Tags.h @@ -117,7 +117,7 @@ namespace Tag { if (ptag == NULL) // Is ptag empty? { - Console::Error("%s BUSERR", s); + Console.Error("%s BUSERR", s); UpperTransfer(tag, ptag); // Set BEIS (BUSERR) in DMAC_STAT register @@ -177,21 +177,21 @@ static __forceinline void PrintCHCR(const char* s, DMACh *tag) u8 num_addr = tag->chcr.ASP; u32 mode = tag->chcr.MOD; - Console::Write("%s chcr %s mem: ", s, (tag->chcr.DIR) ? "from" : "to"); + Console.Write("%s chcr %s mem: ", s, (tag->chcr.DIR) ? "from" : "to"); if (mode == NORMAL_MODE) - Console::Write(" normal mode; "); + Console.Write(" normal mode; "); else if (mode == CHAIN_MODE) - Console::Write(" chain mode; "); + Console.Write(" chain mode; "); else if (mode == INTERLEAVE_MODE) - Console::Write(" interleave mode; "); + Console.Write(" interleave mode; "); else - Console::Write(" ?? mode; "); + Console.Write(" ?? mode; "); - if (num_addr != 0) Console::Write("ASP = %d;", num_addr); - if (tag->chcr.TTE) Console::Write("TTE;"); - if (tag->chcr.TIE) Console::Write("TIE;"); - if (tag->chcr.STR) Console::Write(" (DMA started)."); else Console::Write(" (DMA stopped)."); - Console::WriteLn(""); + if (num_addr != 0) Console.Write("ASP = %d;", num_addr); + if (tag->chcr.TTE) Console.Write("TTE;"); + if (tag->chcr.TIE) Console.Write("TIE;"); + if (tag->chcr.STR) Console.Write(" (DMA started)."); else Console.Write(" (DMA stopped)."); + Console.Newline(); } diff --git a/pcsx2/VU0.cpp b/pcsx2/VU0.cpp index ce4fa05137..3ac31f2e8b 100644 --- a/pcsx2/VU0.cpp +++ b/pcsx2/VU0.cpp @@ -75,7 +75,7 @@ __forceinline void _vu0run(bool breakOnMbit) { do { // knockout kings 2002 loops here with sVU if (breakOnMbit && (VU0.cycle-startcycle > 0x1000)) { - Console::Notice("VU0 perma-stall, breaking execution..."); + Console.Notice("VU0 perma-stall, breaking execution..."); break; // mVU will never get here (it handles mBit internally) } CpuVU0.ExecuteBlock(); @@ -159,17 +159,17 @@ void CTC2() { case REG_FBRST: VU0.VI[REG_FBRST].UL = cpuRegs.GPR.r[_Rt_].UL[0] & 0x0C0C; if (cpuRegs.GPR.r[_Rt_].UL[0] & 0x1) { // VU0 Force Break - Console::Error("fixme: VU0 Force Break"); + Console.Error("fixme: VU0 Force Break"); } if (cpuRegs.GPR.r[_Rt_].UL[0] & 0x2) { // VU0 Reset - //Console::WriteLn("fixme: VU0 Reset"); + //Console.WriteLn("fixme: VU0 Reset"); vu0ResetRegs(); } if (cpuRegs.GPR.r[_Rt_].UL[0] & 0x100) { // VU1 Force Break - Console::Error("fixme: VU1 Force Break"); + Console.Error("fixme: VU1 Force Break"); } if (cpuRegs.GPR.r[_Rt_].UL[0] & 0x200) { // VU1 Reset -// Console::WriteLn("fixme: VU1 Reset"); +// Console.WriteLn("fixme: VU1 Reset"); vu1ResetRegs(); } break; @@ -354,7 +354,7 @@ void vu0Finish() if(VU0.VI[REG_VPU_STAT].UL & 0x1) { VU0.VI[REG_VPU_STAT].UL &= ~1; // this log tends to spam a lot (MGS3) - //Console::Notice("vu0Finish > stall aborted by force."); + //Console.Notice("vu0Finish > stall aborted by force."); } } } diff --git a/pcsx2/VU0micro.cpp b/pcsx2/VU0micro.cpp index 569ef0902c..c2a5eaf6f3 100644 --- a/pcsx2/VU0micro.cpp +++ b/pcsx2/VU0micro.cpp @@ -54,7 +54,7 @@ void vu0ExecMicro(u32 addr) { VUM_LOG("vu0ExecMicro %x", addr); if(VU0.VI[REG_VPU_STAT].UL & 0x1) { - DevCon::Notice("vu0ExecMicro > Stalling for previous microprogram to finish"); + DevCon.Notice("vu0ExecMicro > Stalling for previous microprogram to finish"); vu0Finish(); } VU0.VI[REG_VPU_STAT].UL|= 0x1; diff --git a/pcsx2/VU0microInterp.cpp b/pcsx2/VU0microInterp.cpp index 46ca37c034..27ac602315 100644 --- a/pcsx2/VU0microInterp.cpp +++ b/pcsx2/VU0microInterp.cpp @@ -52,7 +52,7 @@ static void _vu0Exec(VURegs* VU) if(VU0.VI[REG_TPC].UL >= VU0.maxmicro){ #ifdef CPU_LOG - Console::WriteLn("VU0 memory overflow!!: %x", VU->VI[REG_TPC].UL); + Console.WriteLn("VU0 memory overflow!!: %x", VU->VI[REG_TPC].UL); #endif VU0.VI[REG_VPU_STAT].UL&= ~0x1; VU->cycle++; @@ -67,7 +67,7 @@ static void _vu0Exec(VURegs* VU) } if (ptr[1] & 0x20000000) { /* M flag */ VU->flags|= VUFLAG_MFLAGSET; -// Console::WriteLn("fixme: M flag set"); +// Console.WriteLn("fixme: M flag set"); } if (ptr[1] & 0x10000000) { /* D flag */ if (VU0.VI[REG_FBRST].UL & 0x4) { @@ -106,19 +106,19 @@ static void _vu0Exec(VURegs* VU) vfreg = 0; vireg = 0; if (uregs.VFwrite) { if (lregs.VFwrite == uregs.VFwrite) { -// Console::Notice("*PCSX2*: Warning, VF write to the same reg in both lower/upper cycle"); +// Console.Notice("*PCSX2*: Warning, VF write to the same reg in both lower/upper cycle"); discard = 1; } if (lregs.VFread0 == uregs.VFwrite || lregs.VFread1 == uregs.VFwrite) { -// Console::WriteLn("saving reg %d at pc=%x", i, VU->VI[REG_TPC].UL); +// Console.WriteLn("saving reg %d at pc=%x", i, VU->VI[REG_TPC].UL); _VF = VU->VF[uregs.VFwrite]; vfreg = uregs.VFwrite; } } if (uregs.VIread & (1 << REG_CLIP_FLAG)) { if (lregs.VIwrite & (1 << REG_CLIP_FLAG)) { - Console::Notice("*PCSX2*: Warning, VI write to the same reg in both lower/upper cycle"); + Console.Notice("*PCSX2*: Warning, VI write to the same reg in both lower/upper cycle"); discard = 1; } if (lregs.VIread & (1 << REG_CLIP_FLAG)) { @@ -176,7 +176,7 @@ void vu0Exec(VURegs* VU) { if (VU->VI[REG_TPC].UL >= VU->maxmicro) { #ifdef CPU_LOG - Console::Notice("VU0 memory overflow!!: %x", VU->VI[REG_TPC].UL); + Console.Notice("VU0 memory overflow!!: %x", VU->VI[REG_TPC].UL); #endif VU0.VI[REG_VPU_STAT].UL&= ~0x1; } else { @@ -184,11 +184,11 @@ void vu0Exec(VURegs* VU) } VU->cycle++; - if (VU->VI[0].UL != 0) DbgCon::Error("VI[0] != 0!!!!\n"); - if (VU->VF[0].f.x != 0.0f) DbgCon::Error("VF[0].x != 0.0!!!!\n"); - if (VU->VF[0].f.y != 0.0f) DbgCon::Error("VF[0].y != 0.0!!!!\n"); - if (VU->VF[0].f.z != 0.0f) DbgCon::Error("VF[0].z != 0.0!!!!\n"); - if (VU->VF[0].f.w != 1.0f) DbgCon::Error("VF[0].w != 1.0!!!!\n"); + if (VU->VI[0].UL != 0) DbgCon.Error("VI[0] != 0!!!!\n"); + if (VU->VF[0].f.x != 0.0f) DbgCon.Error("VF[0].x != 0.0!!!!\n"); + if (VU->VF[0].f.y != 0.0f) DbgCon.Error("VF[0].y != 0.0!!!!\n"); + if (VU->VF[0].f.z != 0.0f) DbgCon.Error("VF[0].z != 0.0!!!!\n"); + if (VU->VF[0].f.w != 1.0f) DbgCon.Error("VF[0].w != 1.0!!!!\n"); } namespace VU0micro diff --git a/pcsx2/VU1microInterp.cpp b/pcsx2/VU1microInterp.cpp index 3794fafbcc..c30ee20910 100644 --- a/pcsx2/VU1microInterp.cpp +++ b/pcsx2/VU1microInterp.cpp @@ -102,19 +102,19 @@ static void _vu1Exec(VURegs* VU) vfreg = 0; vireg = 0; if (uregs.VFwrite) { if (lregs.VFwrite == uregs.VFwrite) { -// Console::Notice("*PCSX2*: Warning, VF write to the same reg in both lower/upper cycle"); +// Console.Notice("*PCSX2*: Warning, VF write to the same reg in both lower/upper cycle"); discard = 1; } if (lregs.VFread0 == uregs.VFwrite || lregs.VFread1 == uregs.VFwrite) { -// Console::WriteLn("saving reg %d at pc=%x", i, VU->VI[REG_TPC].UL); +// Console.WriteLn("saving reg %d at pc=%x", i, VU->VI[REG_TPC].UL); _VF = VU->VF[uregs.VFwrite]; vfreg = uregs.VFwrite; } } if (uregs.VIread & (1 << REG_CLIP_FLAG)) { if (lregs.VIwrite & (1 << REG_CLIP_FLAG)) { - Console::Notice("*PCSX2*: Warning, VI write to the same reg in both lower/upper cycle"); + Console.Notice("*PCSX2*: Warning, VI write to the same reg in both lower/upper cycle"); discard = 1; } if (lregs.VIread & (1 << REG_CLIP_FLAG)) { @@ -170,11 +170,11 @@ void vu1Exec(VURegs* VU) _vu1Exec(VU); VU->cycle++; - if (VU->VI[0].UL != 0) DbgCon::Error("VI[0] != 0!!!!\n"); - if (VU->VF[0].f.x != 0.0f) DbgCon::Error("VF[0].x != 0.0!!!!\n"); - if (VU->VF[0].f.y != 0.0f) DbgCon::Error("VF[0].y != 0.0!!!!\n"); - if (VU->VF[0].f.z != 0.0f) DbgCon::Error("VF[0].z != 0.0!!!!\n"); - if (VU->VF[0].f.w != 1.0f) DbgCon::Error("VF[0].w != 1.0!!!!\n"); + if (VU->VI[0].UL != 0) DbgCon.Error("VI[0] != 0!!!!\n"); + if (VU->VF[0].f.x != 0.0f) DbgCon.Error("VF[0].x != 0.0!!!!\n"); + if (VU->VF[0].f.y != 0.0f) DbgCon.Error("VF[0].y != 0.0!!!!\n"); + if (VU->VF[0].f.z != 0.0f) DbgCon.Error("VF[0].z != 0.0!!!!\n"); + if (VU->VF[0].f.w != 1.0f) DbgCon.Error("VF[0].w != 1.0!!!!\n"); } namespace VU1micro diff --git a/pcsx2/VUops.cpp b/pcsx2/VUops.cpp index 0d7e475cd7..573c014cc2 100644 --- a/pcsx2/VUops.cpp +++ b/pcsx2/VUops.cpp @@ -179,7 +179,7 @@ static __releaseinline void __fastcall _vuFMACAdd(VURegs * VU, int reg, int xyzw if (VU->fmac[i].enable == 1) continue; break; } - //if (i==8) Console::Error("*PCSX2*: error , out of fmacs %d", VU->cycle); + //if (i==8) Console.Error("*PCSX2*: error , out of fmacs %d", VU->cycle); VUM_LOG("adding FMAC pipe[%d]; xyzw=%x", i, xyzw); @@ -2064,10 +2064,10 @@ void _vuXGKICK(VURegs * VU) if((size << 4) > (u32)(0x4000-((VU->VI[_Is_].US[0]*16) & 0x3fff))) { - //DevCon::Notice("addr + Size = 0x%x, transferring %x then doing %x", ((VU->VI[_Is_].US[0]*16) & 0x3fff) + (size << 4), (0x4000-((VU->VI[_Is_].US[0]*16) & 0x3fff)) >> 4, size - (0x4000-((VU->VI[_Is_].US[0]*16) & 0x3fff) >> 4)); + //DevCon.Notice("addr + Size = 0x%x, transferring %x then doing %x", ((VU->VI[_Is_].US[0]*16) & 0x3fff) + (size << 4), (0x4000-((VU->VI[_Is_].US[0]*16) & 0x3fff)) >> 4, size - (0x4000-((VU->VI[_Is_].US[0]*16) & 0x3fff) >> 4)); memcpy_aligned(pmem, (u8*)VU->Mem+((VU->VI[_Is_].US[0]*16) & 0x3fff), 0x4000-((VU->VI[_Is_].US[0]*16) & 0x3fff)); size -= (0x4000-((VU->VI[_Is_].US[0]*16) & 0x3fff)) >> 4; - //DevCon::Notice("Size left %x", size); + //DevCon.Notice("Size left %x", size); pmem += 0x4000-((VU->VI[_Is_].US[0]*16) & 0x3fff); memcpy_aligned(pmem, (u8*)VU->Mem, size<<4); } diff --git a/pcsx2/Vif.cpp b/pcsx2/Vif.cpp index a390aa7945..c5033b85a8 100644 --- a/pcsx2/Vif.cpp +++ b/pcsx2/Vif.cpp @@ -582,7 +582,7 @@ void mfifoVIF1transfer(int qwc) int temp = vif1ch->madr; //Temporarily Store ADDR vif1ch->madr = qwctag(vif1ch->tadr + 16); //Set MADR to QW following the tag vif1ch->tadr = temp; //Copy temporarily stored ADDR to Tag - if ((temp & dmacRegs->rbsr.RMSK) != dmacRegs->rbor.ADDR) Console::WriteLn("Next tag = %x outside ring %x size %x", temp, psHu32(DMAC_RBOR), psHu32(DMAC_RBSR)); + if ((temp & dmacRegs->rbsr.RMSK) != dmacRegs->rbor.ADDR) Console.WriteLn("Next tag = %x outside ring %x size %x", temp, psHu32(DMAC_RBOR), psHu32(DMAC_RBSR)); vif1.done = false; break; } @@ -660,7 +660,7 @@ void vifMFIFOInterrupt() case 0: //Set up transfer if (vif1ch->tadr == spr0->madr) { - // Console::WriteLn("Empty 1"); + // Console.WriteLn("Empty 1"); vifqwc = 0; vif1.inprogress |= 0x10; vif1Regs->stat &= ~VIF1_STAT_FQC; // FQC=0 @@ -685,7 +685,7 @@ void vifMFIFOInterrupt() /*if (vifqwc <= 0) { - //Console::WriteLn("Empty 2"); + //Console.WriteLn("Empty 2"); //vif1.inprogress |= 0x10; vif1Regs->stat &= ~VIF1_STAT_FQC; // FQC=0 hwDmacIrq(DMAC_MFIFO_EMPTY); diff --git a/pcsx2/VifDma.cpp b/pcsx2/VifDma.cpp index f90ac050a6..efa9e44e3e 100644 --- a/pcsx2/VifDma.cpp +++ b/pcsx2/VifDma.cpp @@ -308,7 +308,7 @@ static void ProcessMemSkip(int size, unsigned int unpackType, const unsigned int VIFUNPACK_LOG("Processing V4-5 skip, size = %d", size); break; default: - Console::WriteLn("Invalid unpack type %x", unpackType); + Console.WriteLn("Invalid unpack type %x", unpackType); break; } @@ -389,14 +389,14 @@ static int VIFalign(u32 *data, vifCode *v, unsigned int size, const unsigned int //This is just to make sure the alignment isnt loopy on a split packet if(vifRegs->offset != ((vif->tag.addr & 0xf) >> 2)) { - DevCon::Error("Warning: Unpack alignment error"); + DevCon.Error("Warning: Unpack alignment error"); } VIFUNPACK_LOG("Aligning packet size = %d offset %d addr %x", size, vifRegs->offset, vif->tag.addr); if (((u32)size / (u32)ft->dsize) < ((u32)ft->qsize - vifRegs->offset)) { - DevCon::Error("Wasn't enough left size/dsize = %x left to write %x", (size / ft->dsize), (ft->qsize - vifRegs->offset)); + DevCon.Error("Wasn't enough left size/dsize = %x left to write %x", (size / ft->dsize), (ft->qsize - vifRegs->offset)); } unpacksize = min((size / ft->dsize), (ft->qsize - vifRegs->offset)); @@ -413,7 +413,7 @@ static int VIFalign(u32 *data, vifCode *v, unsigned int size, const unsigned int } else { - DevCon::Notice("Offset = %x", vifRegs->offset); + DevCon.Notice("Offset = %x", vifRegs->offset); vif->tag.addr += unpacksize * 4; return size>>2; } @@ -521,7 +521,7 @@ static int VIFalign(u32 *data, vifCode *v, unsigned int size, const unsigned int /* unpack one qword */ if(vif->tag.addr + ((size / ft->dsize) * 4) >= (u32)(VIFdmanum ? 0x4000 : 0x1000)) { - //DevCon::Notice("Overflow"); + //DevCon.Notice("Overflow"); vif->tag.addr &= (u32)(VIFdmanum ? 0x3fff : 0xfff); dest = (u32*)(VU->Mem + v->addr); } @@ -607,7 +607,7 @@ static void VIFunpack(u32 *data, vifCode *v, unsigned int size, const unsigned i { if (v->addr >= memlimit) { - //DevCon::Notice("Overflown at the start"); + //DevCon.Notice("Overflown at the start"); v->addr &= (memlimit - 1); dest = (u32*)(VU->Mem + v->addr); } @@ -633,7 +633,7 @@ static void VIFunpack(u32 *data, vifCode *v, unsigned int size, const unsigned i } else { - //DevCon::Notice("VIF%x Unpack ending %x > %x", VIFdmanum, tempsize, VIFdmanum ? 0x4000 : 0x1000); + //DevCon.Notice("VIF%x Unpack ending %x > %x", VIFdmanum, tempsize, VIFdmanum ? 0x4000 : 0x1000); tempsize = size; size = 0; } @@ -745,7 +745,7 @@ static void VIFunpack(u32 *data, vifCode *v, unsigned int size, const unsigned i int incdest = ((vifRegs->cycle.cl - vifRegs->cycle.wl) << 2) + 4; size = 0; int addrstart = v->addr; - if((tempsize >> 2) != vif->tag.size) DevCon::Notice("split when size != tagsize"); + if((tempsize >> 2) != vif->tag.size) DevCon.Notice("split when size != tagsize"); VIFUNPACK_LOG("sorting tempsize :p, size %d, vifnum %d, addr %x", tempsize, vifRegs->num, vif->tag.addr); @@ -753,7 +753,7 @@ static void VIFunpack(u32 *data, vifCode *v, unsigned int size, const unsigned i { if(v->addr >= memlimit) { - DevCon::Notice("Mem limit ovf"); + DevCon.Notice("Mem limit ovf"); v->addr &= (memlimit - 1); dest = (u32*)(VU->Mem + v->addr); } @@ -819,9 +819,9 @@ static void VIFunpack(u32 *data, vifCode *v, unsigned int size, const unsigned i if(vifRegs->cycle.cl > 0) // Quicker and avoids zero division :P if((u32)(((size / ft->gsize) / vifRegs->cycle.cl) * vifRegs->cycle.wl) < vifRegs->num) - DevCon::Notice("Filling write warning! %x < %x and CL = %x WL = %x", (size / ft->gsize), vifRegs->num, vifRegs->cycle.cl, vifRegs->cycle.wl); + DevCon.Notice("Filling write warning! %x < %x and CL = %x WL = %x", (size / ft->gsize), vifRegs->num, vifRegs->cycle.cl, vifRegs->cycle.wl); - //DevCon::Notice("filling write %d cl %d, wl %d mask %x mode %x unpacktype %x addr %x", vifRegs->num, vifRegs->cycle.cl, vifRegs->cycle.wl, vifRegs->mask, vifRegs->mode, unpackType, vif->tag.addr); + //DevCon.Notice("filling write %d cl %d, wl %d mask %x mode %x unpacktype %x addr %x", vifRegs->num, vifRegs->cycle.cl, vifRegs->cycle.wl, vifRegs->mask, vifRegs->mode, unpackType, vif->tag.addr); while (vifRegs->num > 0) { if (vif->cl == vifRegs->cycle.wl) @@ -878,7 +878,7 @@ static void vuExecMicro(u32 addr, const u32 VIFdmanum) } if (VU->vifRegs->itops > (VIFdmanum ? 0x3ffu : 0xffu)) - Console::WriteLn("VIF%d ITOP overrun! %x", VIFdmanum, VU->vifRegs->itops); + Console.WriteLn("VIF%d ITOP overrun! %x", VIFdmanum, VU->vifRegs->itops); VU->vifRegs->itop = VU->vifRegs->itops; @@ -926,7 +926,7 @@ static __forceinline void vif0UNPACK(u32 *data) if (vif0Regs->cycle.wl == 0 && vif0Regs->cycle.wl < vif0Regs->cycle.cl) { - Console::WriteLn("Vif0 CL %d, WL %d", vif0Regs->cycle.cl, vif0Regs->cycle.wl); + Console.WriteLn("Vif0 CL %d, WL %d", vif0Regs->cycle.cl, vif0Regs->cycle.wl); vif0.cmd &= ~0x7f; return; } @@ -960,7 +960,7 @@ static __forceinline void vif0UNPACK(u32 *data) static __forceinline void vif0mpgTransfer(u32 addr, u32 *data, int size) { - /* Console::WriteLn("vif0mpgTransfer addr=%x; size=%x", addr, size); + /* Console.WriteLn("vif0mpgTransfer addr=%x; size=%x", addr, size); { FILE *f = fopen("vu1.raw", "wb"); fwrite(data, 1, size*4, f); @@ -980,7 +980,7 @@ static __forceinline void vif0mpgTransfer(u32 addr, u32 *data, int size) static int __fastcall Vif0TransNull(u32 *data) // Shouldnt go here { - Console::WriteLn("VIF0 Shouldnt go here CMD = %x", vif0Regs->code); + Console.WriteLn("VIF0 Shouldnt go here CMD = %x", vif0Regs->code); vif0.cmd = 0; return 0; } @@ -1065,7 +1065,7 @@ static int __fastcall Vif0TransMPG(u32 *data) // MPG { if (vif0.vifpacketsize < vif0.tag.size) { - if((vif0.tag.addr + vif0.vifpacketsize) > 0x1000) DevCon::Notice("Vif0 MPG Split Overflow"); + if((vif0.tag.addr + vif0.vifpacketsize) > 0x1000) DevCon.Notice("Vif0 MPG Split Overflow"); vif0mpgTransfer(vif0.tag.addr, data, vif0.vifpacketsize); vif0.tag.addr += vif0.vifpacketsize << 2; @@ -1077,7 +1077,7 @@ static int __fastcall Vif0TransMPG(u32 *data) // MPG { int ret; - if((vif0.tag.addr + vif0.tag.size) > 0x1000) DevCon::Notice("Vif0 MPG Overflow"); + if((vif0.tag.addr + vif0.tag.size) > 0x1000) DevCon.Notice("Vif0 MPG Overflow"); vif0mpgTransfer(vif0.tag.addr, data, vif0.tag.size); ret = vif0.tag.size; @@ -1222,7 +1222,7 @@ static void Vif0CMDNull() // invalid opcode // if ME1, then force the vif to interrupt if (!(vif0Regs->err.ME1)) //Ignore vifcode and tag mismatch error { - Console::WriteLn("UNKNOWN VifCmd: %x", vif0.cmd); + Console.WriteLn("UNKNOWN VifCmd: %x", vif0.cmd); vif0Regs->stat |= VIF0_STAT_ER1; vif0.irq++; } @@ -1252,7 +1252,7 @@ int VIF0transfer(u32 *data, int size, int istag) continue; } - if (vif0.tag.size != 0) Console::WriteLn("no vif0 cmd but tag size is left last cmd read %x", vif0Regs->code); + if (vif0.tag.size != 0) Console.WriteLn("no vif0 cmd but tag size is left last cmd read %x", vif0Regs->code); // if interrupt and new cmd is NOT MARK if (vif0.irq) break; @@ -1274,7 +1274,7 @@ int VIF0transfer(u32 *data, int size, int istag) { if (!(vif0Regs->err.ME1)) //Ignore vifcode and tag mismatch error { - Console::WriteLn("UNKNOWN VifCmd: %x", vif0.cmd); + Console.WriteLn("UNKNOWN VifCmd: %x", vif0.cmd); vif0Regs->stat |= VIF0_STAT_ER1; vif0.irq++; } @@ -1315,7 +1315,7 @@ int VIF0transfer(u32 *data, int size, int istag) vif0.vifstalled = true; if (((vif0Regs->code >> 24) & 0x7f) != 0x7)vif0Regs->stat |= VIF0_STAT_VIS; - //else Console::WriteLn("VIF0 IRQ on MARK"); + //else Console.WriteLn("VIF0 IRQ on MARK"); // spiderman doesn't break on qw boundaries vif0.irqoffset = transferred % 4; // cannot lose the offset @@ -1326,7 +1326,7 @@ int VIF0transfer(u32 *data, int size, int istag) vif0ch->madr += (transferred << 4); vif0ch->qwc -= transferred; } - //else Console::WriteLn("Stall on vif0, FromSPR = %x, Vif0MADR = %x Sif0MADR = %x STADR = %x", psHu32(0x1000d010), vif0ch->madr, psHu32(0x1000c010), psHu32(DMAC_STADR)); + //else Console.WriteLn("Stall on vif0, FromSPR = %x, Vif0MADR = %x Sif0MADR = %x STADR = %x", psHu32(0x1000d010), vif0ch->madr, psHu32(0x1000c010), psHu32(DMAC_STADR)); return -2; } @@ -1440,14 +1440,14 @@ void vif0Interrupt() } } - if (!vif0ch->chcr.STR) Console::WriteLn("Vif0 running when CHCR = %x", vif0ch->chcr._u32); + if (!vif0ch->chcr.STR) Console.WriteLn("Vif0 running when CHCR = %x", vif0ch->chcr._u32); if ((vif0ch->chcr.MOD == CHAIN_MODE) && (!vif0.done) && (!vif0.vifstalled)) { if (!(dmacRegs->ctrl.DMAE)) { - Console::WriteLn("vif0 dma masked"); + Console.WriteLn("vif0 dma masked"); return; } @@ -1460,8 +1460,8 @@ void vif0Interrupt() return; } - if (vif0ch->qwc > 0) Console::WriteLn("VIF0 Ending with QWC left"); - if (vif0.cmd != 0) Console::WriteLn("vif0.cmd still set %x", vif0.cmd); + if (vif0ch->qwc > 0) Console.WriteLn("VIF0 Ending with QWC left"); + if (vif0.cmd != 0) Console.WriteLn("vif0.cmd still set %x", vif0.cmd); vif0ch->chcr.STR = 0; hwDmacIrq(DMAC_VIF0); @@ -1519,7 +1519,7 @@ void dmaVIF0() { if (_VIF0chain() == -2) { - Console::WriteLn("Stall on normal %x", vif0Regs->stat); + Console.WriteLn("Stall on normal %x", vif0Regs->stat); vif0.vifstalled = true; return; } @@ -1552,7 +1552,7 @@ void vif0Write32(u32 mem, u32 value) if (value & 0x1) { /* Reset VIF */ - //Console::WriteLn("Vif0 Reset %x", vif0Regs->stat); + //Console.WriteLn("Vif0 Reset %x", vif0Regs->stat); memzero(vif0); vif0ch->qwc = 0; //? cpuRegs.interrupt &= ~1; //Stop all vif0 DMA's @@ -1571,7 +1571,7 @@ void vif0Write32(u32 mem, u32 value) vif0Regs->stat |= VIF0_STAT_VFS; vif0Regs->stat &= ~VIF0_STAT_VPS; vif0.vifstalled = true; - Console::WriteLn("vif0 force break"); + Console.WriteLn("vif0 force break"); } if (value & 0x4) @@ -1638,7 +1638,7 @@ void vif0Write32(u32 mem, u32 value) break; default: - Console::WriteLn("Unknown Vif0 write to %x", mem); + Console.WriteLn("Unknown Vif0 write to %x", mem); psHu32(mem) = value; break; } @@ -1695,7 +1695,7 @@ static __forceinline void vif1UNPACK(u32 *data) { if (vif1Regs->cycle.wl < vif1Regs->cycle.cl) { - Console::WriteLn("Vif1 CL %d, WL %d", vif1Regs->cycle.cl, vif1Regs->cycle.wl); + Console.WriteLn("Vif1 CL %d, WL %d", vif1Regs->cycle.cl, vif1Regs->cycle.wl); vif1.cmd &= ~0x7f; return; } @@ -1734,7 +1734,7 @@ static __forceinline void vif1UNPACK(u32 *data) static __forceinline void vif1mpgTransfer(u32 addr, u32 *data, int size) { - /* Console::WriteLn("vif1mpgTransfer addr=%x; size=%x", addr, size); + /* Console.WriteLn("vif1mpgTransfer addr=%x; size=%x", addr, size); { FILE *f = fopen("vu1.raw", "wb"); fwrite(data, 1, size*4, f); @@ -1754,7 +1754,7 @@ static __forceinline void vif1mpgTransfer(u32 addr, u32 *data, int size) static int __fastcall Vif1TransNull(u32 *data) // Shouldnt go here { - Console::WriteLn("Shouldnt go here CMD = %x", vif1Regs->code); + Console.WriteLn("Shouldnt go here CMD = %x", vif1Regs->code); vif1.cmd = 0; return 0; } @@ -1836,7 +1836,7 @@ static int __fastcall Vif1TransMPG(u32 *data) { if (vif1.vifpacketsize < vif1.tag.size) { - if((vif1.tag.addr + vif1.vifpacketsize) > 0x4000) DevCon::Notice("Vif1 MPG Split Overflow"); + if((vif1.tag.addr + vif1.vifpacketsize) > 0x4000) DevCon.Notice("Vif1 MPG Split Overflow"); vif1mpgTransfer(vif1.tag.addr, data, vif1.vifpacketsize); vif1.tag.addr += vif1.vifpacketsize << 2; vif1.tag.size -= vif1.vifpacketsize; @@ -1845,7 +1845,7 @@ static int __fastcall Vif1TransMPG(u32 *data) else { int ret; - if((vif1.tag.addr + vif1.tag.size) > 0x4000) DevCon::Notice("Vif1 MPG Overflow"); + if((vif1.tag.addr + vif1.tag.size) > 0x4000) DevCon.Notice("Vif1 MPG Overflow"); vif1mpgTransfer(vif1.tag.addr, data, vif1.tag.size); ret = vif1.tag.size; vif1.tag.size = 0; @@ -2037,7 +2037,7 @@ u8 schedulepath3msk = 0; void Vif1MskPath3() // MSKPATH3 { vif1Regs->mskpath3 = schedulepath3msk & 0x1; - //Console::WriteLn("VIF MSKPATH3 %x", vif1Regs->mskpath3); + //Console.WriteLn("VIF MSKPATH3 %x", vif1Regs->mskpath3); if (vif1Regs->mskpath3) { @@ -2146,7 +2146,7 @@ static void Vif1CMDNull() // invalid opcode if (!(vif1Regs->err.ME1)) //Ignore vifcode and tag mismatch error { - Console::WriteLn("UNKNOWN VifCmd: %x\n", vif1.cmd); + Console.WriteLn("UNKNOWN VifCmd: %x\n", vif1.cmd); vif1Regs->stat |= VIF1_STAT_ER1; vif1.irq++; } @@ -2224,7 +2224,7 @@ int VIF1transfer(u32 *data, int size, int istag) continue; } - if (vif1.tag.size != 0) DevCon::Error("no vif1 cmd but tag size is left last cmd read %x", vif1Regs->code); + if (vif1.tag.size != 0) DevCon.Error("no vif1 cmd but tag size is left last cmd read %x", vif1Regs->code); if (vif1.irq) break; @@ -2244,7 +2244,7 @@ int VIF1transfer(u32 *data, int size, int istag) { if (!(vif0Regs->err.ME1)) //Ignore vifcode and tag mismatch error { - Console::WriteLn("UNKNOWN VifCmd: %x", vif1.cmd); + Console.WriteLn("UNKNOWN VifCmd: %x", vif1.cmd); vif1Regs->stat |= VIF1_STAT_ER1; vif1.irq++; } @@ -2297,7 +2297,7 @@ int VIF1transfer(u32 *data, int size, int istag) vif1ch->qwc -= transferred; if ((vif1ch->qwc == 0) && (vif1.irqoffset == 0)) vif1.inprogress = 0; - //Console::WriteLn("Stall on vif1, FromSPR = %x, Vif1MADR = %x Sif0MADR = %x STADR = %x", psHu32(0x1000d010), vif1ch->madr, psHu32(0x1000c010), psHu32(DMAC_STADR)); + //Console.WriteLn("Stall on vif1, FromSPR = %x, Vif1MADR = %x Sif0MADR = %x STADR = %x", psHu32(0x1000d010), vif1ch->madr, psHu32(0x1000c010), psHu32(DMAC_STADR)); return -2; } @@ -2330,7 +2330,7 @@ void vif1TransferFromMemory() // VIF from gsMemory if (pMem == NULL) //Is vif0ptag empty? { - Console::WriteLn("Vif1 Tag BUSERR"); + Console.WriteLn("Vif1 Tag BUSERR"); dmacRegs->stat.BEIS = 1; //If yes, set BEIS (BUSERR) in DMAC_STAT register vif1.done = true; vif1Regs->stat &= ~VIF1_STAT_FQC; @@ -2510,7 +2510,7 @@ __forceinline void vif1Interrupt() } - if (!(vif1ch->chcr.STR)) Console::WriteLn("Vif1 running when CHCR == %x", vif1ch->chcr._u32); + if (!(vif1ch->chcr.STR)) Console.WriteLn("Vif1 running when CHCR == %x", vif1ch->chcr._u32); if (vif1.irq && vif1.tag.size == 0) { @@ -2546,7 +2546,7 @@ __forceinline void vif1Interrupt() if (!(dmacRegs->ctrl.DMAE)) { - Console::WriteLn("vif1 dma masked"); + Console.WriteLn("vif1 dma masked"); return; } @@ -2562,8 +2562,8 @@ __forceinline void vif1Interrupt() return; //Dont want to end if vif is stalled. } #ifdef PCSX2_DEVBUILD - if (vif1ch->qwc > 0) Console::WriteLn("VIF1 Ending with %x QWC left"); - if (vif1.cmd != 0) Console::WriteLn("vif1.cmd still set %x tag size %x", vif1.cmd, vif1.tag.size); + if (vif1ch->qwc > 0) Console.WriteLn("VIF1 Ending with %x QWC left"); + if (vif1.cmd != 0) Console.WriteLn("vif1.cmd still set %x tag size %x", vif1.cmd, vif1.tag.size); #endif vif1Regs->stat &= ~VIF1_STAT_VPS; //Vif goes idle as the stall happened between commands; @@ -2590,9 +2590,9 @@ void dmaVIF1() if (dmacRegs->ctrl.MFD == MFD_VIF1) // VIF MFIFO { - //Console::WriteLn("VIFMFIFO\n"); + //Console.WriteLn("VIFMFIFO\n"); // Test changed because the Final Fantasy 12 opening somehow has the tag in *Undefined* mode, which is not in the documentation that I saw. - if (vif1ch->chcr.MOD == NORMAL_MODE) Console::WriteLn("MFIFO mode is normal (which isn't normal here)! %x", vif1ch->chcr); + if (vif1ch->chcr.MOD == NORMAL_MODE) Console.WriteLn("MFIFO mode is normal (which isn't normal here)! %x", vif1ch->chcr); vifMFIFOInterrupt(); return; } @@ -2600,7 +2600,7 @@ void dmaVIF1() #ifdef PCSX2_DEVBUILD if (dmacRegs->ctrl.STD == STD_VIF1) { - //DevCon::WriteLn("VIF Stall Control Source = %x, Drain = %x", (psHu32(0xe000) >> 4) & 0x3, (psHu32(0xe000) >> 6) & 0x3); + //DevCon.WriteLn("VIF Stall Control Source = %x, Drain = %x", (psHu32(0xe000) >> 4) & 0x3, (psHu32(0xe000) >> 6) & 0x3); } #endif @@ -2608,7 +2608,7 @@ void dmaVIF1() { if (dmacRegs->ctrl.STD == STD_VIF1) - Console::WriteLn("DMA Stall Control on VIF1 normal"); + Console.WriteLn("DMA Stall Control on VIF1 normal"); if (vif1ch->chcr.DIR) // to Memory vif1.dmamode = VIF_NORMAL_TO_MEM_MODE; @@ -2675,7 +2675,7 @@ void vif1Write32(u32 mem, u32 value) vif1Regs->stat &= ~VIF1_STAT_VPS; cpuRegs.interrupt &= ~((1 << 1) | (1 << 10)); //Stop all vif1 DMA's vif1.vifstalled = true; - Console::WriteLn("vif1 force break"); + Console.WriteLn("vif1 force break"); } if (value & 0x4) @@ -2710,7 +2710,7 @@ void vif1Write32(u32 mem, u32 value) // loop necessary for spiderman if ((psHu32(DMAC_CTRL) & 0xC) == 0x8) { - //Console::WriteLn("MFIFO Stall"); + //Console.WriteLn("MFIFO Stall"); CPU_INT(10, vif1ch->qwc * BIAS); } else @@ -2741,7 +2741,7 @@ void vif1Write32(u32 mem, u32 value) // different so can't be stalled if (vif1Regs->stat & (VIF1_STAT_INT | VIF1_STAT_VSS | VIF1_STAT_VIS | VIF1_STAT_VFS)) { - DevCon::WriteLn("changing dir when vif1 fifo stalled"); + DevCon.WriteLn("changing dir when vif1 fifo stalled"); } } #endif @@ -2781,7 +2781,7 @@ void vif1Write32(u32 mem, u32 value) break; default: - Console::WriteLn("Unknown Vif1 write to %x", mem); + Console.WriteLn("Unknown Vif1 write to %x", mem); psHu32(mem) = value; break; } diff --git a/pcsx2/gui/App.h b/pcsx2/gui/App.h index 533efe1a98..4718e482b0 100644 --- a/pcsx2/gui/App.h +++ b/pcsx2/gui/App.h @@ -35,6 +35,9 @@ class AppCoreThread; #include "System.h" #include "System/SysThreads.h" +#define AllowFromMainThreadOnly() \ + pxAssertMsg( wxThread::IsMain(), "Thread affinity violation: Call allowed from main thread only." ) + BEGIN_DECLARE_EVENT_TYPES() DECLARE_EVENT_TYPE( pxEVT_SemaphorePing, -1 ) DECLARE_EVENT_TYPE( pxEVT_OpenModalDialog, -1 ) @@ -45,6 +48,12 @@ BEGIN_DECLARE_EVENT_TYPES() DECLARE_EVENT_TYPE( pxEVT_ThawFinished, -1 ) END_DECLARE_EVENT_TYPES() +// This is used when the GS plugin is handling its own window. Messages from the PAD +// are piped through to an app-level message handler, which dispatches them through +// the universal Accelerator table. +static const int pxID_PadHandler_Keydown = 8030; + + // ------------------------------------------------------------------------ // All Menu Options for the Main Window! :D // ------------------------------------------------------------------------ @@ -338,7 +347,6 @@ public: void SysExecute(); void SysExecute( CDVD_SourceType cdvdsrc ); void SysReset(); - bool SysIsActive() const; const wxBitmap& GetLogoBitmap(); wxImageList& GetImgList_Config(); @@ -346,17 +354,19 @@ public: const AppImageIds& GetImgId() const { return m_ImageId; } - bool HasMainFrame() const { return m_MainFrame != NULL; } - bool HasCoreThread() const { return m_CoreThread != NULL; } - MainEmuFrame& GetMainFrame() const; SysCoreThread& GetCoreThread() const; - MainEmuFrame& GetMainFrameOrExcept() const; - SysCoreThread& GetCoreThreadOrExcept() const; + + bool HasMainFrame() const { return m_MainFrame != NULL; } + bool HasCoreThread() const { return m_CoreThread != NULL; } + + MainEmuFrame* GetMainFramePtr() const { return m_MainFrame; } + SysCoreThread* GetCoreThreadPtr() const { return m_CoreThread; } void OpenGsFrame(); void OnGsFrameClosed(); - + void OnMainFrameClosed(); + // -------------------------------------------------------------------------- // Overrides of wxApp virtuals: // -------------------------------------------------------------------------- @@ -375,9 +385,12 @@ public: // Console / Program Logging Helpers // ---------------------------------------------------------------------------- ConsoleLogFrame* GetProgramLog(); - void CloseProgramLog(); void ProgramLog_CountMsg(); void ProgramLog_PostEvent( wxEvent& evt ); + void EnableConsoleLogging() const; + void DisableWindowLogging() const; + void DisableDiskLogging() const; + void OnProgramLogClosed(); protected: void InitDefaultGlobalAccelerators(); @@ -433,29 +446,52 @@ public: virtual ~AppCoreThread() throw(); virtual void Suspend( bool isBlocking=true ); + virtual void Resume(); virtual void StateCheck( bool isCancelable=true ); virtual void ApplySettings( const Pcsx2Config& src ); protected: virtual void OnResumeReady(); - virtual void DoThreadCleanup(); - sptr ExecuteTask(); + virtual void OnThreadCleanup(); + virtual void ExecuteTask(); }; DECLARE_APP(Pcsx2App) -class EntryGuard -{ -public: - int& Counter; - EntryGuard( int& counter ) : Counter( counter ) - { ++Counter; } +// -------------------------------------------------------------------------------------- +// s* macros! ['s' stands for 'shortcut'] +// -------------------------------------------------------------------------------------- +// Use these for "silent fail" invocation of PCSX2 Application-related constructs. If the +// construct (albeit wxApp, MainFrame, CoreThread, etc) is null, the requested method will +// not be invoked, and an optional "else" clause cn be affixed for handling the end case. +// +// Usage Examples: +// sCoreThread.Suspend(); // Suspends the CoreThread, or does nothing if the CoreThread handle is NULL +// sCoreThread.Suspend(); else Console.WriteLn( "Judge Wapner" ); // 'else' clause for handling NULL scenarios. +// +// Note! These macros are not "syntax complete", which means they could generat unexpected +// syntax errors in some situatins, and more importantly they cannot be used for invoking +// functions with return values. +// +// Rationale: There are a lot of situations where we want to invoke a void-style method on +// various volatile object pointers (App, Corethread, MainFrame, etc). Typically if these +// objects are NULL the most intuitive response is to simply ignore the call request and +// continue running silently. These macros make that possible without any extra boilerplate +// conditionals or temp variable defines in the code. +// +#define sApp \ + if( Pcsx2App* __app_ = (Pcsx2App*)wxApp::GetInstance() ) (*__app_) - virtual ~EntryGuard() throw() - { --Counter; } +#define sCoreThread \ + if( SysCoreThread* __thread_ = GetCoreThreadPtr() ) (*__thread_) - bool IsReentrant() const { return Counter > 1; } -}; +#define sMainFrame \ + if( MainEmuFrame* __frame_ = GetMainFramePtr() ) (*__frame_) + + +// -------------------------------------------------------------------------------------- +// External App-related Globals and Shortcuts +// -------------------------------------------------------------------------------------- extern bool sys_resume_lock; @@ -473,14 +509,12 @@ extern void AppApplySettings( const AppConfig* oldconf=NULL ); extern bool SysHasValidState(); extern void SysStatus( const wxString& text ); -extern void SysSuspend( bool closePlugins = true ); -extern void SysResume(); -extern void SysReset(); -extern void SysExecute(); -extern void SysExecute( CDVD_SourceType cdvdsrc ); extern bool HasMainFrame(); extern bool HasCoreThread(); extern MainEmuFrame& GetMainFrame(); extern SysCoreThread& GetCoreThread(); + +extern MainEmuFrame* GetMainFramePtr(); +extern SysCoreThread* GetCoreThreadPtr(); diff --git a/pcsx2/gui/AppAssert.cpp b/pcsx2/gui/AppAssert.cpp index 618c917f32..02a635d6e3 100644 --- a/pcsx2/gui/AppAssert.cpp +++ b/pcsx2/gui/AppAssert.cpp @@ -105,8 +105,8 @@ void Pcsx2App::OnAssertFailure( const wxChar *file, int line, const wxChar *func wxString trace( L"Call stack:\n" + pxGetStackTrace() ); wxMessageOutputDebug().Printf( dbgmsg ); - Console::Error( dbgmsg ); - Console::WriteLn( trace ); + Console.Error( dbgmsg ); + Console.WriteLn( trace ); int retval = Msgbox::Assertion( dbgmsg, trace ); diff --git a/pcsx2/gui/AppConfig.cpp b/pcsx2/gui/AppConfig.cpp index 0b5fbf8a69..5da111ff57 100644 --- a/pcsx2/gui/AppConfig.cpp +++ b/pcsx2/gui/AppConfig.cpp @@ -532,6 +532,8 @@ void AppConfig_OnChangedSettingsFolder( bool overwrite ) wxString newlogname( Path::Combine( g_Conf->Folders.Logs.ToString(), L"emuLog.txt" ) ); + wxGetApp().DisableDiskLogging(); + if( emuLog != NULL ) { if( emuLogName != newlogname ) @@ -544,6 +546,7 @@ void AppConfig_OnChangedSettingsFolder( bool overwrite ) if( emuLog == NULL ) { emuLogName = newlogname; - emuLog = fopen( emuLogName.ToUTF8().data(), "wb" ); + emuLog = fopen( toUTF8(emuLogName), "wb" ); } + wxGetApp().EnableConsoleLogging(); } diff --git a/pcsx2/gui/AppInit.cpp b/pcsx2/gui/AppInit.cpp new file mode 100644 index 0000000000..4da439576e --- /dev/null +++ b/pcsx2/gui/AppInit.cpp @@ -0,0 +1,380 @@ +/* PCSX2 - PS2 Emulator for PCs + * Copyright (C) 2002-2009 PCSX2 Dev Team + * + * PCSX2 is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * PCSX2 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 PCSX2. + * If not, see . + */ + +#include "PrecompiledHeader.h" +#include "IniInterface.h" +#include "MainFrame.h" +#include "ConsoleLogger.h" +#include "DebugTools/Debug.h" +#include "Dialogs/ModalPopups.h" + +#include +#include +#include + +static bool m_ForceWizard = false; + +namespace Exception +{ + // -------------------------------------------------------------------------- + // Exception used to perform an "errorless" termination of the app during OnInit + // procedures. This happens when a user cancels out of startup prompts/wizards. + // + class StartupAborted : public BaseException + { + public: + DEFINE_EXCEPTION_COPYTORS( StartupAborted ) + + StartupAborted( const wxString& msg_eng=L"Startup initialization was aborted by the user." ) + { + // english messages only for this exception. + BaseException::InitBaseEx( msg_eng, msg_eng ); + } + }; +} + +void Pcsx2App::OpenWizardConsole() +{ + if( !IsDebugBuild ) return; + g_Conf->ProgLogBox.Visible = true; + m_ProgramLogBox = new ConsoleLogFrame( NULL, L"PCSX2 Program Log", g_Conf->ProgLogBox ); +} + +// User mode settings can't be stored in the CWD for two reasons: +// (a) the user may not have permission to do so (most obvious) +// (b) it would result in sloppy usermode.ini found all over a hard drive if people runs the +// exe from many locations (ugh). +// +// So better to use the registry on Win32 and a "default ini location" config file under Linux, +// and store the usermode settings for the CWD based on the CWD's hash. +// +void Pcsx2App::ReadUserModeSettings() +{ + wxString cwd( wxGetCwd() ); + u32 hashres = HashTools::Hash( (char*)cwd.c_str(), cwd.Length() ); + + wxDirName usrlocaldir( wxStandardPaths::Get().GetUserLocalDataDir() ); + if( !usrlocaldir.Exists() ) + { + Console.Status( L"Creating UserLocalData folder: " + usrlocaldir.ToString() ); + usrlocaldir.Mkdir(); + } + + wxFileName usermodefile( FilenameDefs::GetUsermodeConfig() ); + usermodefile.SetPath( usrlocaldir.ToString() ); + ScopedPtr conf_usermode( OpenFileConfig( usermodefile.GetFullPath() ) ); + + wxString groupname( wxsFormat( L"CWD.%08x", hashres ) ); + + if( m_ForceWizard || !conf_usermode->HasGroup( groupname ) ) + { + // first time startup, so give the user the choice of user mode: + OpenWizardConsole(); + FirstTimeWizard wiz( NULL ); + if( !wiz.RunWizard( wiz.GetUsermodePage() ) ) + throw Exception::StartupAborted( L"Startup aborted: User canceled FirstTime Wizard." ); + + // Save user's new settings + IniSaver saver( *conf_usermode ); + g_Conf->LoadSaveUserMode( saver, groupname ); + AppConfig_OnChangedSettingsFolder( true ); + AppSaveSettings(); + } + else + { + // usermode.ini exists -- assume Documents mode, unless the ini explicitly + // specifies otherwise. + UseAdminMode = false; + + IniLoader loader( *conf_usermode ); + g_Conf->LoadSaveUserMode( loader, groupname ); + + if( !wxFile::Exists( GetSettingsFilename() ) ) + { + // user wiped their pcsx2.ini -- needs a reconfiguration via wizard! + // (we skip the first page since it's a usermode.ini thing) + + OpenWizardConsole(); + FirstTimeWizard wiz( NULL ); + if( !wiz.RunWizard( wiz.GetPostUsermodePage() ) ) + throw Exception::StartupAborted( L"Startup aborted: User canceled Configuration Wizard." ); + + // Save user's new settings + IniSaver saver( *conf_usermode ); + g_Conf->LoadSaveUserMode( saver, groupname ); + AppConfig_OnChangedSettingsFolder( true ); + AppSaveSettings(); + } + } +} + +void Pcsx2App::OnInitCmdLine( wxCmdLineParser& parser ) +{ + parser.SetLogo( (wxString)L" >> PCSX2 -- A Playstation2 Emulator for the PC <<\n\n" + + _("All options are for the current session only and will not be saved.\n") + ); + + parser.AddParam( _("IsoFile"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL ); + + parser.AddSwitch( L"h", L"help", _("displays this list of command line options"), wxCMD_LINE_OPTION_HELP ); + + parser.AddSwitch( wxEmptyString,L"nogui", _("disables display of the gui while running games") ); + parser.AddSwitch( wxEmptyString,L"skipbios",_("skips standard BIOS splash screens and software checks") ); + parser.AddOption( wxEmptyString,L"elf", _("executes an ELF image"), wxCMD_LINE_VAL_STRING ); + parser.AddSwitch( wxEmptyString,L"nodisc", _("boots an empty dvd tray; use to enter the PS2 system menu") ); + parser.AddSwitch( wxEmptyString,L"usecd", _("boots from the configured CDVD plugin (ignores IsoFile parameter)") ); + + parser.AddOption( wxEmptyString,L"cfgpath", _("changes the configuration file path"), wxCMD_LINE_VAL_STRING ); + parser.AddOption( wxEmptyString,L"cfg", _("specifies the PCSX2 configuration file to use [not implemented]"), wxCMD_LINE_VAL_STRING ); + + parser.AddSwitch( wxEmptyString,L"forcewiz",_("Forces PCSX2 to start the First-time Wizard") ); + + const PluginInfo* pi = tbl_PluginInfo; do { + parser.AddOption( wxEmptyString, pi->GetShortname().Lower(), + wxsFormat( _("specify the file to use as the %s plugin"), pi->GetShortname().c_str() ) + ); + } while( ++pi, pi->shortname != NULL ); + + parser.SetSwitchChars( L"-" ); +} + +bool Pcsx2App::OnCmdLineError( wxCmdLineParser& parser ) +{ + wxApp::OnCmdLineError( parser ); + return false; +} + +bool Pcsx2App::OnCmdLineParsed( wxCmdLineParser& parser ) +{ + if( parser.GetParamCount() >= 1 ) + { + // [TODO] : Unnamed parameter is taken as an "autorun" option for a cdvd/iso. + parser.GetParam( 0 ); + } + + // Suppress wxWidgets automatic options parsing since none of them pertain to PCSX2 needs. + //wxApp::OnCmdLineParsed( parser ); + + //bool yay = parser.Found(L"nogui"); + m_ForceWizard = parser.Found( L"forcewiz" ); + + const PluginInfo* pi = tbl_PluginInfo; do + { + wxString dest; + if( !parser.Found( pi->GetShortname().Lower(), &dest ) ) continue; + + OverrideOptions.Filenames.Plugins[pi->id] = dest; + + if( wxFileExists( dest ) ) + Console.Notice( pi->GetShortname() + L" override: " + dest ); + else + { + bool result = Msgbox::OkCancel( + wxsFormat( _("Plugin Override Error! Specified %s plugin does not exist:\n\n"), pi->GetShortname().c_str() ) + + dest + + _("Press OK to use the default configured plugin, or Cancel to close."), + _("Plugin Override Error - PCSX2"), wxICON_ERROR + ); + + if( !result ) return false; + } + } while( ++pi, pi->shortname != NULL ); + + parser.Found( L"cfgpath", &OverrideOptions.SettingsFolder ); + + return true; +} + +typedef void (wxEvtHandler::*pxMessageBoxEventFunction)(pxMessageBoxEvent&); + +// ------------------------------------------------------------------------ +bool Pcsx2App::OnInit() +{ + g_Conf = new AppConfig(); + EnableConsoleLogging(); + + wxInitAllImageHandlers(); + if( !wxApp::OnInit() ) return false; + + m_StdoutRedirHandle = NewPipeRedir(stdout); + m_StderrRedirHandle = NewPipeRedir(stderr); + wxLocale::AddCatalogLookupPathPrefix( wxGetCwd() ); + +#define pxMessageBoxEventThing(func) \ + (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(pxMessageBoxEventFunction, &func ) + + Connect( pxEVT_MSGBOX, pxMessageBoxEventThing( Pcsx2App::OnMessageBox ) ); + Connect( pxEVT_CallStackBox, pxMessageBoxEventThing( Pcsx2App::OnMessageBox ) ); + Connect( pxEVT_SemaphorePing, wxCommandEventHandler( Pcsx2App::OnSemaphorePing ) ); + Connect( pxEVT_OpenModalDialog, wxCommandEventHandler( Pcsx2App::OnOpenModalDialog ) ); + Connect( pxEVT_ReloadPlugins, wxCommandEventHandler( Pcsx2App::OnReloadPlugins ) ); + Connect( pxEVT_LoadPluginsComplete, wxCommandEventHandler( Pcsx2App::OnLoadPluginsComplete ) ); + + Connect( pxEVT_FreezeFinished, wxCommandEventHandler( Pcsx2App::OnCoreThreadTerminated ) ); + + Connect( pxEVT_FreezeFinished, wxCommandEventHandler( Pcsx2App::OnFreezeFinished ) ); + Connect( pxEVT_ThawFinished, wxCommandEventHandler( Pcsx2App::OnThawFinished ) ); + + Connect( pxID_PadHandler_Keydown, wxEVT_KEY_DOWN, wxKeyEventHandler( Pcsx2App::OnEmuKeyDown ) ); + + // User/Admin Mode Dual Setup: + // PCSX2 now supports two fundamental modes of operation. The default is Classic mode, + // which uses the Current Working Directory (CWD) for all user data files, and requires + // Admin access on Vista (and some Linux as well). The second mode is the Vista- + // compatible \documents folder usage. The mode is determined by the presence and + // contents of a usermode.ini file in the CWD. If the ini file is missing, we assume + // the user is setting up a classic install. If the ini is present, we read the value of + // the UserMode and SettingsPath vars. + // + // Conveniently this dual mode setup applies equally well to most modern Linux distros. + + try + { + InitDefaultGlobalAccelerators(); + + delete wxLog::SetActiveTarget( new pxLogConsole() ); + ReadUserModeSettings(); + + AppConfig_OnChangedSettingsFolder(); + + m_MainFrame = new MainEmuFrame( NULL, L"PCSX2" ); + + if( m_ProgramLogBox ) + { + wxWindow* deleteme = m_ProgramLogBox; + OnProgramLogClosed(); + delete deleteme; + g_Conf->ProgLogBox.Visible = true; + } + + m_ProgramLogBox = new ConsoleLogFrame( m_MainFrame, L"PCSX2 Program Log", g_Conf->ProgLogBox ); + EnableConsoleLogging(); + + SetTopWindow( m_MainFrame ); // not really needed... + SetExitOnFrameDelete( true ); // but being explicit doesn't hurt... + m_MainFrame->Show(); + + SysDetect(); + AppApplySettings(); + + m_CoreAllocs = new SysCoreAllocations(); + + if( m_CoreAllocs->HadSomeFailures( g_Conf->EmuOptions.Cpu.Recompiler ) ) + { + wxString message( _("The following cpu recompilers failed to initialize and will not be available:\n\n") ); + + if( !m_CoreAllocs->RecSuccess_EE ) + { + message += L"\t* R5900 (EE)\n"; + g_Session.ForceDisableEErec = true; + } + + if( !m_CoreAllocs->RecSuccess_IOP ) + { + message += L"\t* R3000A (IOP)\n"; + g_Session.ForceDisableIOPrec = true; + } + + if( !m_CoreAllocs->RecSuccess_VU0 ) + { + message += L"\t* VU0\n"; + g_Session.ForceDisableVU0rec = true; + } + + if( !m_CoreAllocs->RecSuccess_VU1 ) + { + message += L"\t* VU1\n"; + g_Session.ForceDisableVU1rec = true; + } + + message += pxE( ".Popup Error:EmuCore:MemoryForRecs", + L"These errors are the result of memory allocation failures (see the program log for details). " + L"Closing out some memory hogging background tasks may resolve this error.\n\n" + L"These recompilers have been disabled and interpreters will be used in their place. " + L"Interpreters can be very slow, so don't get too excited. Press OK to continue or CANCEL to close PCSX2." + ); + + if( !Msgbox::OkCancel( message, _("PCSX2 Initialization Error"), wxICON_ERROR ) ) + return false; + } + + LoadPluginsPassive(); + } + // ---------------------------------------------------------------------------- + catch( Exception::StartupAborted& ex ) + { + Console.Notice( ex.FormatDiagnosticMessage() ); + return false; + } + // ---------------------------------------------------------------------------- + // Failures on the core initialization procedure (typically OutOfMemory errors) are bad, + // since it means the emulator is completely non-functional. Let's pop up an error and + // exit gracefully-ish. + // + catch( Exception::RuntimeError& ex ) + { + Console.Error( ex.FormatDiagnosticMessage() ); + Msgbox::Alert( ex.FormatDisplayMessage() + L"\n\nPress OK to close PCSX2.", + _("PCSX2 Critical Error"), wxICON_ERROR ); + return false; + } + return true; +} + +void Pcsx2App::CleanupMess() +{ + if( m_CorePlugins ) + { + m_CorePlugins->Close(); + m_CorePlugins->Shutdown(); + } + + // Notice: deleting the plugin manager (unloading plugins) here causes Lilypad to crash, + // likely due to some pending message in the queue that references lilypad procs. + // We don't need to unload plugins anyway tho -- shutdown is plenty safe enough for + // closing out all the windows. So just leave it be and let the plugins get unloaded + // during the wxApp destructor. -- air + + // FIXME: performing a wxYield() here may fix that problem. -- air +} + +Pcsx2App::Pcsx2App() : + m_MainFrame( NULL ) +, m_gsFrame( NULL ) +, m_ProgramLogBox( NULL ) +, m_ConfigImages( 32, 32 ) +, m_ConfigImagesAreLoaded( false ) +, m_ToolbarImages( NULL ) +, m_Bitmap_Logo( NULL ) +{ + SetAppName( L"pcsx2" ); + BuildCommandHash(); +} + +Pcsx2App::~Pcsx2App() +{ + // Typically OnExit cleans everything up before we get here, *unless* we cancel + // out of program startup in OnInit (return false) -- then remaining cleanup needs + // to happen here in the destructor. + + CleanupMess(); + Console_SetActiveHandler( ConsoleWriter_Null ); + + if( emuLog != NULL ) + { + fclose( emuLog ); + emuLog = NULL; + } +} diff --git a/pcsx2/gui/AppMain.cpp b/pcsx2/gui/AppMain.cpp index e2b2d2e9ca..f37e604869 100644 --- a/pcsx2/gui/AppMain.cpp +++ b/pcsx2/gui/AppMain.cpp @@ -18,19 +18,13 @@ #include "MainFrame.h" #include "Plugins.h" #include "SaveState.h" -#include "ConsoleLogger.h" #include "Dialogs/ModalPopups.h" #include "Dialogs/ConfigurationDialog.h" #include "Dialogs/LogOptionsDialog.h" -#include "Utilities/ScopedPtr.h" #include "Utilities/HashMap.h" -#include -#include -#include - IMPLEMENT_APP(Pcsx2App) DEFINE_EVENT_TYPE( pxEVT_SemaphorePing ); @@ -48,25 +42,6 @@ bool UseDefaultSettingsFolder = true; ScopedPtr g_Conf; ConfigOverrides OverrideOptions; -namespace Exception -{ - // -------------------------------------------------------------------------- - // Exception used to perform an "errorless" termination of the app during OnInit - // procedures. This happens when a user cancels out of startup prompts/wizards. - // - class StartupAborted : public BaseException - { - public: - DEFINE_EXCEPTION_COPYTORS( StartupAborted ) - - StartupAborted( const wxString& msg_eng=L"Startup initialization was aborted by the user." ) - { - // english messages only for this exception. - BaseException::InitBaseEx( msg_eng, msg_eng ); - } - }; -} - AppCoreThread::AppCoreThread( PluginManager& plugins ) : SysCoreThread( plugins ) , m_kevt() @@ -91,10 +66,21 @@ void AppCoreThread::Suspend( bool isBlocking ) m_kevt.m_altDown = false; } +void AppCoreThread::Resume() +{ + // Thread control (suspend / resume) should only be performed from the main/gui thread. + if( !AllowFromMainThreadOnly() ) return; + + if( sys_resume_lock ) + { + Console.WriteLn( "SysResume: State is locked, ignoring Resume request!" ); + return; + } + _parent::Resume(); +} + void AppCoreThread::OnResumeReady() { - if( !DevAssert( wxThread::IsMain(), "SysCoreThread can only be resumed from the main/gui thread." ) ) return; - if( m_shortSuspend ) return; ApplySettings( g_Conf->EmuOptions ); @@ -110,18 +96,13 @@ void AppCoreThread::OnResumeReady() // Typically the thread handles all its own errors, so there's no need to have error // handling here. However it's a good idea to update the status of the GUI to reflect // the new (lack of) thread status, so this posts a message to the App to do so. -void AppCoreThread::DoThreadCleanup() +void AppCoreThread::OnThreadCleanup() { wxCommandEvent evt( pxEVT_AppCoreThread_Terminated ); wxGetApp().AddPendingEvent( evt ); - _parent::DoThreadCleanup(); + _parent::OnThreadCleanup(); } -// This is used when the GS plugin is handling its own window. Messages from the PAD -// are piped through to an app-level message handler, which dispatches them through -// the universal Accelerator table. -static const int pxID_PadHandler_Keydown = 8030; - #ifdef __WXGTK__ extern int TranslateGDKtoWXK( u32 keysym ); #endif @@ -168,19 +149,11 @@ void AppCoreThread::ApplySettings( const Pcsx2Config& src ) // usually the desired behavior) will be ignored. static int localc = 0; - EntryGuard guard( localc ); + RecursionGuard guard( localc ); if(guard.IsReentrant()) return; SysCoreThread::ApplySettings( src ); } -// Returns true if there is a "valid" virtual machine state from the user's perspective. This -// means the user has started the emulator and not issued a full reset. -__forceinline bool SysHasValidState() -{ - bool isRunning = HasCoreThread() ? GetCoreThread().IsRunning() : false; - return isRunning || StateCopy_HasFullState(); -} - bool HandlePluginError( Exception::PluginError& ex ) { if( pxDialogExists( DialogId_CoreSettings ) ) return true; @@ -200,7 +173,7 @@ bool HandlePluginError( Exception::PluginError& ex ) return result; } -sptr AppCoreThread::ExecuteTask() +void AppCoreThread::ExecuteTask() { try { @@ -233,7 +206,7 @@ sptr AppCoreThread::ExecuteTask() catch( Exception::PluginError& ex ) { m_plugins.Close(); - Console::Error( ex.FormatDiagnosticMessage() ); + Console.Error( ex.FormatDiagnosticMessage() ); Msgbox::Alert( ex.FormatDisplayMessage(), _("Plugin Open Error") ); /*if( HandlePluginError( ex ) ) @@ -251,300 +224,12 @@ sptr AppCoreThread::ExecuteTask() m_plugins.Close(); Msgbox::Alert( ex.FormatDisplayMessage() ); } - - return 0; -} - - -void Pcsx2App::OpenWizardConsole() -{ - if( !IsDebugBuild ) return; - g_Conf->ProgLogBox.Visible = true; - m_ProgramLogBox = new ConsoleLogFrame( NULL, L"PCSX2 Program Log", g_Conf->ProgLogBox ); -} - -static bool m_ForceWizard = false; - -// User mode settings can't be stored in the CWD for two reasons: -// (a) the user may not have permission to do so (most obvious) -// (b) it would result in sloppy usermode.ini found all over a hard drive if people runs the -// exe from many locations (ugh). -// -// So better to use the registry on Win32 and a "default ini location" config file under Linux, -// and store the usermode settings for the CWD based on the CWD's hash. -// -void Pcsx2App::ReadUserModeSettings() -{ - wxString cwd( wxGetCwd() ); - u32 hashres = HashTools::Hash( (char*)cwd.c_str(), cwd.Length() ); - - wxDirName usrlocaldir( wxStandardPaths::Get().GetUserLocalDataDir() ); - if( !usrlocaldir.Exists() ) - { - Console::Status( L"Creating UserLocalData folder: " + usrlocaldir.ToString() ); - usrlocaldir.Mkdir(); - } - - wxFileName usermodefile( FilenameDefs::GetUsermodeConfig() ); - usermodefile.SetPath( usrlocaldir.ToString() ); - ScopedPtr conf_usermode( OpenFileConfig( usermodefile.GetFullPath() ) ); - - wxString groupname( wxsFormat( L"CWD.%08x", hashres ) ); - - if( m_ForceWizard || !conf_usermode->HasGroup( groupname ) ) - { - // first time startup, so give the user the choice of user mode: - OpenWizardConsole(); - FirstTimeWizard wiz( NULL ); - if( !wiz.RunWizard( wiz.GetUsermodePage() ) ) - throw Exception::StartupAborted( L"Startup aborted: User canceled FirstTime Wizard." ); - - // Save user's new settings - IniSaver saver( *conf_usermode ); - g_Conf->LoadSaveUserMode( saver, groupname ); - AppConfig_OnChangedSettingsFolder( true ); - AppSaveSettings(); - } - else - { - // usermode.ini exists -- assume Documents mode, unless the ini explicitly - // specifies otherwise. - UseAdminMode = false; - - IniLoader loader( *conf_usermode ); - g_Conf->LoadSaveUserMode( loader, groupname ); - - if( !wxFile::Exists( GetSettingsFilename() ) ) - { - // user wiped their pcsx2.ini -- needs a reconfiguration via wizard! - // (we skip the first page since it's a usermode.ini thing) - - OpenWizardConsole(); - FirstTimeWizard wiz( NULL ); - if( !wiz.RunWizard( wiz.GetPostUsermodePage() ) ) - throw Exception::StartupAborted( L"Startup aborted: User canceled Configuration Wizard." ); - - // Save user's new settings - IniSaver saver( *conf_usermode ); - g_Conf->LoadSaveUserMode( saver, groupname ); - AppConfig_OnChangedSettingsFolder( true ); - AppSaveSettings(); - } - } -} - -void Pcsx2App::OnInitCmdLine( wxCmdLineParser& parser ) -{ - parser.SetLogo( (wxString)L" >> PCSX2 -- A Playstation2 Emulator for the PC <<\n\n" + - _("All options are for the current session only and will not be saved.\n") - ); - - parser.AddParam( _("IsoFile"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL ); - - parser.AddSwitch( L"h", L"help", _("displays this list of command line options"), wxCMD_LINE_OPTION_HELP ); - - parser.AddSwitch( wxEmptyString,L"nogui", _("disables display of the gui while running games") ); - parser.AddSwitch( wxEmptyString,L"skipbios",_("skips standard BIOS splash screens and software checks") ); - parser.AddOption( wxEmptyString,L"elf", _("executes an ELF image"), wxCMD_LINE_VAL_STRING ); - parser.AddSwitch( wxEmptyString,L"nodisc", _("boots an empty dvd tray; use to enter the PS2 system menu") ); - parser.AddSwitch( wxEmptyString,L"usecd", _("boots from the configured CDVD plugin (ignores IsoFile parameter)") ); - - parser.AddOption( wxEmptyString,L"cfgpath", _("changes the configuration file path"), wxCMD_LINE_VAL_STRING ); - parser.AddOption( wxEmptyString,L"cfg", _("specifies the PCSX2 configuration file to use [not implemented]"), wxCMD_LINE_VAL_STRING ); - - parser.AddSwitch( wxEmptyString,L"forcewiz",_("Forces PCSX2 to start the First-time Wizard") ); - - const PluginInfo* pi = tbl_PluginInfo; do { - parser.AddOption( wxEmptyString, pi->GetShortname().Lower(), - wxsFormat( _("specify the file to use as the %s plugin"), pi->GetShortname().c_str() ) - ); - } while( ++pi, pi->shortname != NULL ); - - parser.SetSwitchChars( L"-" ); -} - -bool Pcsx2App::OnCmdLineError( wxCmdLineParser& parser ) -{ - wxApp::OnCmdLineError( parser ); - return false; -} - -bool Pcsx2App::OnCmdLineParsed( wxCmdLineParser& parser ) -{ - if( parser.GetParamCount() >= 1 ) - { - // [TODO] : Unnamed parameter is taken as an "autorun" option for a cdvd/iso. - parser.GetParam( 0 ); - } - - // Suppress wxWidgets automatic options parsing since none of them pertain to PCSX2 needs. - //wxApp::OnCmdLineParsed( parser ); - - //bool yay = parser.Found(L"nogui"); - m_ForceWizard = parser.Found( L"forcewiz" ); - - const PluginInfo* pi = tbl_PluginInfo; do - { - wxString dest; - if( !parser.Found( pi->GetShortname().Lower(), &dest ) ) continue; - - OverrideOptions.Filenames.Plugins[pi->id] = dest; - - if( wxFileExists( dest ) ) - Console::Notice( pi->GetShortname() + L" override: " + dest ); - else - { - bool result = Msgbox::OkCancel( - wxsFormat( _("Plugin Override Error! Specified %s plugin does not exist:\n\n"), pi->GetShortname().c_str() ) + - dest + - _("Press OK to use the default configured plugin, or Cancel to close."), - _("Plugin Override Error - PCSX2"), wxICON_ERROR - ); - - if( !result ) return false; - } - } while( ++pi, pi->shortname != NULL ); - - parser.Found( L"cfgpath", &OverrideOptions.SettingsFolder ); - - return true; -} - -typedef void (wxEvtHandler::*pxMessageBoxEventFunction)(pxMessageBoxEvent&); - -// ------------------------------------------------------------------------ -bool Pcsx2App::OnInit() -{ - wxInitAllImageHandlers(); - if( !wxApp::OnInit() ) return false; - - g_Conf = new AppConfig(); - - m_StdoutRedirHandle = NewPipeRedir(stdout); - m_StderrRedirHandle = NewPipeRedir(stderr); - wxLocale::AddCatalogLookupPathPrefix( wxGetCwd() ); - -#define pxMessageBoxEventThing(func) \ - (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(pxMessageBoxEventFunction, &func ) - - Connect( pxEVT_MSGBOX, pxMessageBoxEventThing( Pcsx2App::OnMessageBox ) ); - Connect( pxEVT_CallStackBox, pxMessageBoxEventThing( Pcsx2App::OnMessageBox ) ); - Connect( pxEVT_SemaphorePing, wxCommandEventHandler( Pcsx2App::OnSemaphorePing ) ); - Connect( pxEVT_OpenModalDialog, wxCommandEventHandler( Pcsx2App::OnOpenModalDialog ) ); - Connect( pxEVT_ReloadPlugins, wxCommandEventHandler( Pcsx2App::OnReloadPlugins ) ); - Connect( pxEVT_LoadPluginsComplete, wxCommandEventHandler( Pcsx2App::OnLoadPluginsComplete ) ); - - Connect( pxEVT_FreezeFinished, wxCommandEventHandler( Pcsx2App::OnFreezeFinished ) ); - Connect( pxEVT_ThawFinished, wxCommandEventHandler( Pcsx2App::OnThawFinished ) ); - - Connect( pxID_PadHandler_Keydown, wxEVT_KEY_DOWN, wxKeyEventHandler( Pcsx2App::OnEmuKeyDown ) ); - - // User/Admin Mode Dual Setup: - // PCSX2 now supports two fundamental modes of operation. The default is Classic mode, - // which uses the Current Working Directory (CWD) for all user data files, and requires - // Admin access on Vista (and some Linux as well). The second mode is the Vista- - // compatible \documents folder usage. The mode is determined by the presence and - // contents of a usermode.ini file in the CWD. If the ini file is missing, we assume - // the user is setting up a classic install. If the ini is present, we read the value of - // the UserMode and SettingsPath vars. - // - // Conveniently this dual mode setup applies equally well to most modern Linux distros. - - try - { - InitDefaultGlobalAccelerators(); - - delete wxLog::SetActiveTarget( new pxLogConsole() ); - ReadUserModeSettings(); - - AppConfig_OnChangedSettingsFolder(); - - m_MainFrame = new MainEmuFrame( NULL, L"PCSX2" ); - - if( m_ProgramLogBox ) - { - delete m_ProgramLogBox; - g_Conf->ProgLogBox.Visible = true; - } - - m_ProgramLogBox = new ConsoleLogFrame( m_MainFrame, L"PCSX2 Program Log", g_Conf->ProgLogBox ); - - SetTopWindow( m_MainFrame ); // not really needed... - SetExitOnFrameDelete( true ); // but being explicit doesn't hurt... - m_MainFrame->Show(); - - SysDetect(); - AppApplySettings(); - - m_CoreAllocs = new SysCoreAllocations(); - - if( m_CoreAllocs->HadSomeFailures( g_Conf->EmuOptions.Cpu.Recompiler ) ) - { - wxString message( _("The following cpu recompilers failed to initialize and will not be available:\n\n") ); - - if( !m_CoreAllocs->RecSuccess_EE ) - { - message += L"\t* R5900 (EE)\n"; - g_Session.ForceDisableEErec = true; - } - - if( !m_CoreAllocs->RecSuccess_IOP ) - { - message += L"\t* R3000A (IOP)\n"; - g_Session.ForceDisableIOPrec = true; - } - - if( !m_CoreAllocs->RecSuccess_VU0 ) - { - message += L"\t* VU0\n"; - g_Session.ForceDisableVU0rec = true; - } - - if( !m_CoreAllocs->RecSuccess_VU1 ) - { - message += L"\t* VU1\n"; - g_Session.ForceDisableVU1rec = true; - } - - message += pxE( ".Popup Error:EmuCore:MemoryForRecs", - L"These errors are the result of memory allocation failures (see the program log for details). " - L"Closing out some memory hogging background tasks may resolve this error.\n\n" - L"These recompilers have been disabled and interpreters will be used in their place. " - L"Interpreters can be very slow, so don't get too excited. Press OK to continue or CANCEL to close PCSX2." - ); - - if( !Msgbox::OkCancel( message, _("PCSX2 Initialization Error"), wxICON_ERROR ) ) - return false; - } - - LoadPluginsPassive(); - } - // ---------------------------------------------------------------------------- - catch( Exception::StartupAborted& ex ) - { - Console::Notice( ex.FormatDiagnosticMessage() ); - return false; - } - // ---------------------------------------------------------------------------- - // Failures on the core initialization procedure (typically OutOfMemory errors) are bad, - // since it means the emulator is completely non-functional. Let's pop up an error and - // exit gracefully-ish. - // - catch( Exception::RuntimeError& ex ) - { - Console::Error( ex.FormatDiagnosticMessage() ); - Msgbox::Alert( ex.FormatDisplayMessage() + L"\n\nPress OK to close PCSX2.", - _("PCSX2 Critical Error"), wxICON_ERROR ); - return false; - } - return true; } // Allows for activating menu actions from anywhere in PCSX2. // And it's Thread Safe! void Pcsx2App::PostMenuAction( MenuIdentifiers menu_id ) const { - wxASSERT( m_MainFrame != NULL ); if( m_MainFrame == NULL ) return; wxCommandEvent joe( wxEVT_COMMAND_MENU_SELECTED, menu_id ); @@ -570,7 +255,7 @@ void Pcsx2App::PostPadKey( wxKeyEvent& evt ) int Pcsx2App::ThreadedModalDialog( DialogIdentifiers dialogId ) { - wxASSERT( !wxThread::IsMain() ); // don't call me from MainThread! + AllowFromMainThreadOnly(); MsgboxEventResult result; wxCommandEvent joe( pxEVT_OpenModalDialog, dialogId ); @@ -601,6 +286,7 @@ void Pcsx2App::Ping() const // Invoked by the AppCoreThread when the thread has terminated itself. void Pcsx2App::OnCoreThreadTerminated( wxCommandEvent& evt ) { + if( HasMainFrame() ) GetMainFrame().ApplySettings(); m_CoreThread = NULL; @@ -621,7 +307,7 @@ void Pcsx2App::OnOpenModalDialog( wxCommandEvent& evt ) case DialogId_CoreSettings: { static int _guard = 0; - EntryGuard guard( _guard ); + RecursionGuard guard( _guard ); if( guard.IsReentrant() ) return; evtres.result = ConfigurationDialog().ShowModal(); } @@ -630,7 +316,7 @@ void Pcsx2App::OnOpenModalDialog( wxCommandEvent& evt ) case DialogId_BiosSelector: { static int _guard = 0; - EntryGuard guard( _guard ); + RecursionGuard guard( _guard ); if( guard.IsReentrant() ) return; evtres.result = BiosSelectorDialog().ShowModal(); } @@ -639,7 +325,7 @@ void Pcsx2App::OnOpenModalDialog( wxCommandEvent& evt ) case DialogId_LogOptions: { static int _guard = 0; - EntryGuard guard( _guard ); + RecursionGuard guard( _guard ); if( guard.IsReentrant() ) return; evtres.result = LogOptionsDialog().ShowModal(); } @@ -648,7 +334,7 @@ void Pcsx2App::OnOpenModalDialog( wxCommandEvent& evt ) case DialogId_About: { static int _guard = 0; - EntryGuard guard( _guard ); + RecursionGuard guard( _guard ); if( guard.IsReentrant() ) return; evtres.result = AboutBoxDialog().ShowModal(); } @@ -677,30 +363,12 @@ void Pcsx2App::OnEmuKeyDown( wxKeyEvent& evt ) if( cmd != NULL ) { - DbgCon::WriteLn( "(app) Invoking command: %s", cmd->Id ); + DbgCon.WriteLn( "(app) Invoking command: %s", cmd->Id ); cmd->Invoke(); } } -void Pcsx2App::CleanupMess() -{ - if( m_CorePlugins ) - { - m_CorePlugins->Close(); - m_CorePlugins->Shutdown(); - } - - // Notice: deleting the plugin manager (unloading plugins) here causes Lilypad to crash, - // likely due to some pending message in the queue that references lilypad procs. - // We don't need to unload plugins anyway tho -- shutdown is plenty safe enough for - // closing out all the windows. So just leave it be and let the plugins get unloaded - // during the wxApp destructor. -- air - - m_ProgramLogBox = NULL; - m_MainFrame = NULL; -} - void Pcsx2App::HandleEvent(wxEvtHandler *handler, wxEventFunction func, wxEvent& event) const { try @@ -710,10 +378,10 @@ void Pcsx2App::HandleEvent(wxEvtHandler *handler, wxEventFunction func, wxEvent& // ---------------------------------------------------------------------------- catch( Exception::PluginError& ex ) { - Console::Error( ex.FormatDiagnosticMessage() ); + Console.Error( ex.FormatDiagnosticMessage() ); if( !HandlePluginError( ex ) ) { - Console::Error( L"User-canceled plugin configuration after load failure. Plugins not loaded!" ); + Console.Error( L"User-canceled plugin configuration after load failure. Plugins not loaded!" ); Msgbox::Alert( _("Warning! Plugins have not been loaded. PCSX2 will be inoperable.") ); } } @@ -723,7 +391,7 @@ void Pcsx2App::HandleEvent(wxEvtHandler *handler, wxEventFunction func, wxEvent& // Runtime errors which have been unhandled should still be safe to recover from, // so lets issue a message to the user and then continue the message pump. - Console::Error( ex.FormatDiagnosticMessage() ); + Console.Error( ex.FormatDiagnosticMessage() ); Msgbox::Alert( ex.FormatDisplayMessage() ); } } @@ -756,61 +424,31 @@ int Pcsx2App::OnExit() return wxApp::OnExit(); } -Pcsx2App::Pcsx2App() : - m_MainFrame( NULL ) -, m_gsFrame( NULL ) -, m_ProgramLogBox( NULL ) -, m_ConfigImages( 32, 32 ) -, m_ConfigImagesAreLoaded( false ) -, m_ToolbarImages( NULL ) -, m_Bitmap_Logo( NULL ) -{ - SetAppName( L"pcsx2" ); - BuildCommandHash(); -} - -Pcsx2App::~Pcsx2App() -{ - // Typically OnExit cleans everything up before we get here, *unless* we cancel - // out of program startup in OnInit (return false) -- then remaining cleanup needs - // to happen here in the destructor. - - CleanupMess(); -} - +// This method generates debug assertions if the MainFrame handle is NULL (typically +// indicating that PCSX2 is running in NoGUI mode, or that the main frame has been +// closed). In most cases you'll want to use HasMainFrame() to test for thread +// validity first, or use GetMainFramePtr() and manually check for NULL (choice +// is a matter of programmer preference). MainEmuFrame& Pcsx2App::GetMainFrame() const { - wxASSERT( ((uptr)GetTopWindow()) == ((uptr)m_MainFrame) ); - wxASSERT( m_MainFrame != NULL ); + pxAssert( ((uptr)GetTopWindow()) == ((uptr)m_MainFrame) ); + pxAssert( m_MainFrame != NULL ); return *m_MainFrame; } +// This method generates debug assertions if the CoreThread handle is NULL (typically +// indicating that there is no active emulation session). In most cases you'll want +// to use HasCoreThread() to test for thread validity first, or use GetCoreThreadPtr() +// and manually check for NULL (choice is a matter of programmer preference). SysCoreThread& Pcsx2App::GetCoreThread() const { - wxASSERT( m_CoreThread != NULL ); - return *m_CoreThread; -} - - -MainEmuFrame& Pcsx2App::GetMainFrameOrExcept() const -{ - if( m_MainFrame == NULL ) - throw Exception::ObjectIsNull( "main application frame" ); - - return *m_MainFrame; -} - -SysCoreThread& Pcsx2App::GetCoreThreadOrExcept() const -{ - if( !m_CoreThread ) - throw Exception::ObjectIsNull( "core emulation thread" ); - + pxAssert( m_CoreThread != NULL ); return *m_CoreThread; } void AppApplySettings( const AppConfig* oldconf ) { - DevAssert( wxThread::IsMain(), "ApplySettings valid from the GUI thread only." ); + AllowFromMainThreadOnly(); // Ensure existence of necessary documents folders. Plugins and other parts // of PCSX2 rely on them. @@ -868,60 +506,6 @@ void AppSaveSettings() GetMainFrame().SaveRecentIsoList( *conf ); } -// -------------------------------------------------------------------------------------- -// Sys/Core API and Shortcuts (for wxGetApp()) -// -------------------------------------------------------------------------------------- - -// Executes the emulator using a saved/existing virtual machine state and currently -// configured CDVD source device. -void Pcsx2App::SysExecute() -{ - if( sys_resume_lock ) - { - Console::WriteLn( "SysExecute: State is locked, ignoring Execute request!" ); - return; - } - - SysReset(); - LoadPluginsImmediate(); - m_CoreThread = new AppCoreThread( *m_CorePlugins ); - m_CoreThread->Resume(); -} - -// Executes the specified cdvd source and optional elf file. This command performs a -// full closure of any existing VM state and starts a fresh VM with the requested -// sources. -void Pcsx2App::SysExecute( CDVD_SourceType cdvdsrc ) -{ - if( sys_resume_lock ) - { - Console::WriteLn( "SysExecute: State is locked, ignoring Execute request!" ); - return; - } - - SysReset(); - LoadPluginsImmediate(); - CDVDsys_SetFile( CDVDsrc_Iso, g_Conf->CurrentIso ); - CDVDsys_ChangeSource( cdvdsrc ); - - m_CoreThread = new AppCoreThread( *m_CorePlugins ); - m_CoreThread->Resume(); -} - -void Pcsx2App::SysReset() -{ - m_CoreThread = NULL; -} - -// Returns the state of the emulated system (Virtual Machine). Returns true if the -// system is active, or is in the process of reporting or handling an error. Returns -// false if there is no active system (thread is shutdown or hasn't been started). -bool Pcsx2App::SysIsActive() const -{ - return m_CoreThread && m_CoreThread->IsRunning(); -} - - void Pcsx2App::OpenGsFrame() { if( m_gsFrame != NULL ) return; @@ -942,67 +526,104 @@ void Pcsx2App::OnGsFrameClosed() m_gsFrame = NULL; } +void Pcsx2App::OnProgramLogClosed() +{ + if( m_ProgramLogBox == NULL ) return; + DisableWindowLogging(); + m_ProgramLogBox = NULL; +} + +void Pcsx2App::OnMainFrameClosed() +{ + // Nothing threaded depends on the mainframe (yet) -- it all passes through the main wxApp + // message handler. But that might change in the future. + if( m_MainFrame == NULL ) return; + m_MainFrame = NULL; +} + + + +// -------------------------------------------------------------------------------------- +// Sys/Core API and Shortcuts (for wxGetApp()) +// -------------------------------------------------------------------------------------- + +// Executes the emulator using a saved/existing virtual machine state and currently +// configured CDVD source device. +void Pcsx2App::SysExecute() +{ + if( sys_resume_lock ) + { + Console.WriteLn( "SysExecute: State is locked, ignoring Execute request!" ); + return; + } + + SysReset(); + LoadPluginsImmediate(); + m_CoreThread = new AppCoreThread( *m_CorePlugins ); + m_CoreThread->Resume(); +} + +// Executes the specified cdvd source and optional elf file. This command performs a +// full closure of any existing VM state and starts a fresh VM with the requested +// sources. +void Pcsx2App::SysExecute( CDVD_SourceType cdvdsrc ) +{ + if( sys_resume_lock ) + { + Console.WriteLn( "SysExecute: State is locked, ignoring Execute request!" ); + return; + } + + SysReset(); + LoadPluginsImmediate(); + CDVDsys_SetFile( CDVDsrc_Iso, g_Conf->CurrentIso ); + CDVDsys_ChangeSource( cdvdsrc ); + + m_CoreThread = new AppCoreThread( *m_CorePlugins ); + m_CoreThread->Resume(); +} + +void Pcsx2App::SysReset() +{ + m_CoreThread = NULL; +} + +// Returns true if there is a "valid" virtual machine state from the user's perspective. This +// means the user has started the emulator and not issued a full reset. +// Thread Safety: The state of the system can change in parallel to execution of the +// main thread. If you need to perform an extended length activity on the execution +// state (such as saving it), you *must* suspend the Corethread first! +__forceinline bool SysHasValidState() +{ + bool isRunning = HasCoreThread() ? GetCoreThread().IsRunning() : false; + return isRunning || StateCopy_HasFullState(); +} // Writes text to console and updates the window status bar and/or HUD or whateverness. // FIXME: This probably isn't thread safe. >_< void SysStatus( const wxString& text ) { // mirror output to the console! - Console::Status( text.c_str() ); + Console.Status( text.c_str() ); if( HasMainFrame() ) GetMainFrame().SetStatusText( text ); } -// Executes the emulator using a saved/existing virtual machine state and currently -// configured CDVD source device. -void SysExecute() -{ - wxGetApp().SysExecute(); -} - -void SysExecute( CDVD_SourceType cdvdsrc ) -{ - wxGetApp().SysExecute( cdvdsrc ); -} - -void SysResume() -{ - if( !HasCoreThread() ) return; - - if( sys_resume_lock ) - { - Console::WriteLn( "SysResume: State is locked, ignoring Resume request!" ); - return; - } - - GetCoreThread().Resume(); -} - -void SysSuspend( bool closePlugins ) -{ - if( !HasCoreThread() ) return; - - if( closePlugins ) - GetCoreThread().Suspend(); - else - GetCoreThread().ShortSuspend(); -} - -void SysReset() -{ - wxGetApp().SysReset(); -} - bool HasMainFrame() { - return wxGetApp().HasMainFrame(); + return wxTheApp && wxGetApp().HasMainFrame(); } bool HasCoreThread() { - return wxGetApp().HasCoreThread(); + return wxTheApp && wxGetApp().HasCoreThread(); } +// This method generates debug assertions if either the wxApp or MainFrame handles are +// NULL (typically indicating that PCSX2 is running in NoGUI mode, or that the main +// frame has been closed). In most cases you'll want to use HasMainFrame() to test +// for gui validity first, or use GetMainFramePtr() and manually check for NULL (choice +// is a matter of programmer preference). MainEmuFrame& GetMainFrame() { return wxGetApp().GetMainFrame(); @@ -1012,3 +633,18 @@ SysCoreThread& GetCoreThread() { return wxGetApp().GetCoreThread(); } + +// Returns a pointer to the main frame of the GUI (frame may be hidden from view), or +// NULL if no main frame exists (NoGUI mode and/or the frame has been destroyed). If +// the wxApp is NULL then this will also return NULL. +MainEmuFrame* GetMainFramePtr() +{ + return wxTheApp ? wxGetApp().GetMainFramePtr() : NULL; +} + +// Returns a pointer to the CoreThread of the GUI (thread may be stopped or suspended), +// or NULL if no core thread exists, or if the wxApp is also NULL. +SysCoreThread* GetCoreThreadPtr() +{ + return wxTheApp ? wxGetApp().GetCoreThreadPtr() : NULL; +} diff --git a/pcsx2/gui/AppRes.cpp b/pcsx2/gui/AppRes.cpp index ce3f412153..d57e45392b 100644 --- a/pcsx2/gui/AppRes.cpp +++ b/pcsx2/gui/AppRes.cpp @@ -80,7 +80,7 @@ const wxBitmap& Pcsx2App::GetLogoBitmap() //wxFileInputStream stream( zipped.ToString() ) //wxZipInputStream zstream( stream ); - Console::Error( "Loading themes from zipfile is not supported yet.\nFalling back on default theme." ); + Console.Error( "Loading themes from zipfile is not supported yet.\nFalling back on default theme." ); } // Overrides zipfile settings (fix when zipfile support added) diff --git a/pcsx2/gui/ConsoleLogger.cpp b/pcsx2/gui/ConsoleLogger.cpp index 599be60233..5836c39f5d 100644 --- a/pcsx2/gui/ConsoleLogger.cpp +++ b/pcsx2/gui/ConsoleLogger.cpp @@ -23,8 +23,6 @@ #include #include -using Console::Colors; - BEGIN_DECLARE_EVENT_TYPES() DECLARE_EVENT_TYPE(wxEVT_LOG_Write, -1) DECLARE_EVENT_TYPE(wxEVT_LOG_Newline, -1) @@ -73,12 +71,12 @@ void pxLogConsole::DoLog( wxLogLevel level, const wxChar *szString, time_t t ) case wxLOG_FatalError: // This one is unused by wx, and unused by PCSX2 (we prefer exceptions, thanks). - DevAssert( false, "Stop using FatalError and use assertions or exceptions instead." ); + pxFailDev( "Stop using FatalError and use assertions or exceptions instead." ); break; case wxLOG_Status: // Also unsed by wx, and unused by PCSX2 also (we prefer direct API calls to our main window!) - DevAssert( false, "Stop using wxLogStatus just access the Pcsx2App functions directly instead." ); + pxFailDev( "Stop using wxLogStatus just access the Pcsx2App functions directly instead." ); break; case wxLOG_Info: @@ -86,22 +84,22 @@ void pxLogConsole::DoLog( wxLogLevel level, const wxChar *szString, time_t t ) // fallthrough! case wxLOG_Message: - Console::WriteLn( wxString(L"wx > ") + szString ); + Console.WriteLn( wxString(L"wx > ") + szString ); break; case wxLOG_Error: - Console::Error( wxString(L"wx > ") + szString ); + Console.Error( wxString(L"wx > ") + szString ); break; case wxLOG_Warning: - Console::Notice( wxString(L"wx > ") + szString ); + Console.Notice( wxString(L"wx > ") + szString ); break; } } // ---------------------------------------------------------------------------- -sptr ConsoleTestThread::ExecuteTask() +void ConsoleTestThread::ExecuteTask() { static int numtrack = 0; @@ -109,11 +107,10 @@ sptr ConsoleTestThread::ExecuteTask() { // Two lines, both formatted, and varied colors. This makes for a fairly realistic // worst case scenario (without being entirely unrealistic). - Console::WriteLn( wxsFormat( L"This is a threaded logging test. Something bad could happen... %d", ++numtrack ) ); - Console::Status( wxsFormat( L"Testing high stress loads %s", L"(multi-color)" ) ); + Console.WriteLn( wxsFormat( L"This is a threaded logging test. Something bad could happen... %d", ++numtrack ) ); + Console.Status( wxsFormat( L"Testing high stress loads %s", L"(multi-color)" ) ); Sleep( 0 ); } - return 0; } // ---------------------------------------------------------------------------- @@ -212,7 +209,7 @@ void ConsoleLogFrame::ColorArray::SetFont( int fontsize ) Create( fontsize ); } -static const Console::Colors DefaultConsoleColor = Color_White; +static const ConsoleColors DefaultConsoleColor = Color_White; enum MenuIDs_t { @@ -297,9 +294,10 @@ ConsoleLogFrame::ConsoleLogFrame( MainEmuFrame *parent, const wxString& title, A ConsoleLogFrame::~ConsoleLogFrame() { safe_delete( m_threadlogger ); + wxGetApp().OnProgramLogClosed(); } -void ConsoleLogFrame::SetColor( Colors color ) +void ConsoleLogFrame::SetColor( ConsoleColors color ) { if( color != m_curcolor ) m_TextCtrl.SetDefaultStyle( m_ColorTable[m_curcolor=color] ); @@ -335,7 +333,7 @@ void ConsoleLogFrame::Write( const wxString& text ) // Implementation note: Calls SetColor and Write( text ). Override those virtuals // and this one will magically follow suite. :) -void ConsoleLogFrame::Write( Colors color, const wxString& text ) +void ConsoleLogFrame::Write( ConsoleColors color, const wxString& text ) { SetColor( color ); Write( text ); @@ -383,7 +381,7 @@ void ConsoleLogFrame::OnMoveAround( wxMoveEvent& evt ) wxRect snapzone( topright - wxSize( 8,8 ), wxSize( 16,16 ) ); m_conf.AutoDock = snapzone.Contains( GetPosition() ); - //Console::WriteLn( "DockCheck: %d", g_Conf->ConLogBox.AutoDock ); + //Console.WriteLn( "DockCheck: %d", g_Conf->ConLogBox.AutoDock ); if( m_conf.AutoDock ) { SetPosition( topright + wxSize( 1,0 ) ); @@ -407,6 +405,7 @@ void ConsoleLogFrame::OnCloseWindow(wxCloseEvent& event) else { safe_delete( m_threadlogger ); + wxGetApp().OnProgramLogClosed(); event.Skip(); } } @@ -476,12 +475,12 @@ void ConsoleLogFrame::OnFontSize( wxMenuEvent& evt ) } // ---------------------------------------------------------------------------- -// Logging Events (typically recieved from Console class interfaces) +// Logging Events (typically received from Console class interfaces) // ---------------------------------------------------------------------------- void ConsoleLogFrame::OnWrite( wxCommandEvent& event ) { - Write( (Colors)event.GetExtraLong(), event.GetString() ); + Write( (ConsoleColors)event.GetExtraLong(), event.GetString() ); DoMessage(); } @@ -532,7 +531,7 @@ void ConsoleLogFrame::CountMessage() // void ConsoleLogFrame::DoMessage() { - wxASSERT_MSG( wxThread::IsMain(), L"DoMessage must only be called from the main gui thread!" ); + AllowFromMainThreadOnly(); int cur = _InterlockedDecrement( &m_msgcounter ); @@ -552,144 +551,188 @@ void ConsoleLogFrame::DoMessage() } } + ConsoleLogFrame* Pcsx2App::GetProgramLog() { return m_ProgramLogBox; } -void Pcsx2App::CloseProgramLog() -{ - if( m_ProgramLogBox == NULL ) return; - - m_ProgramLogBox->Close(); - - // disable future console log messages from being sent to the window. - m_ProgramLogBox = NULL; -} - void Pcsx2App::ProgramLog_CountMsg() { - if ((wxTheApp == NULL) || ( m_ProgramLogBox == NULL )) return; + // New console log object model makes this check obsolete: + //if( m_ProgramLogBox == NULL ) return; m_ProgramLogBox->CountMessage(); } void Pcsx2App::ProgramLog_PostEvent( wxEvent& evt ) { - if ((wxTheApp == NULL) || ( m_ProgramLogBox == NULL )) return; + // New console log object model makes this check obsolete: + //if( m_ProgramLogBox == NULL ) return; m_ProgramLogBox->GetEventHandler()->AddPendingEvent( evt ); } -////////////////////////////////////////////////////////////////////////////////////////// -// -namespace Console +// -------------------------------------------------------------------------------------- +// ConsoleImpl_ToFile +// -------------------------------------------------------------------------------------- +static void __concall _immediate_logger( const char* src ) { - // thread-local console color storage. - static __threadlocal Colors th_CurrentColor = DefaultConsoleColor; - - static Threading::MutexLock immediate_log_lock; - - // performs immediate thread-safe (mutex locked) logging to disk and to the Linux console. - // Many platforms still do not provide thread-safe implementations of fputs or printf, so - // they are implemented here using a mutex lock for maximum safety. - static void _immediate_logger( const char* src ) - { - - ScopedLock locker( immediate_log_lock ); - - if( emuLog != NULL ) - fputs( src, emuLog ); // fputs does not do automatic newlines, so it's ok! - - // Linux has a handy dandy universal console... - // [TODO] make this a configurable option? Do we care? :) #ifdef __LINUX__ - // puts does automatic newlines, which we don't want here - - /*if (strchr(src, '\n')) - { - fputs( "PCSX2 > ", stdout ); - fputs( src , stdout); - } - else - {*/ - fputs( src, stdout ); - //} + fputs( src, stdout ); #endif + px_fputs( emuLog, src ); +} - } +static void __concall ConsoleToFile_Newline() +{ +#ifdef __LINUX__ + fputc( '\n', stdout ); + fputc( '\n', emuLog ); +#else + fputs( "\r\n", emuLog ); +#endif +} - static void _immediate_logger( const wxString& src ) - { - _immediate_logger( src.ToUTF8().data() ); - } +static void __concall ConsoleToFile_DoWrite( const wxString& fmt ) +{ + _immediate_logger( toUTF8(fmt) ); +} - void __fastcall SetTitle( const wxString& title ) - { - if( wxTheApp == NULL ) return; +static void __concall ConsoleToFile_DoWriteLn( const wxString& fmt ) +{ + _immediate_logger( toUTF8(fmt) ); + ConsoleToFile_Newline(); - wxCommandEvent evt( wxEVT_SetTitleText ); - evt.SetString( title ); - wxGetApp().ProgramLog_PostEvent( evt ); - } + if( emuLog != NULL ) + fflush( emuLog ); +} - void __fastcall SetColor( Colors color ) - { - th_CurrentColor = color; - } +extern const IConsoleWriter ConsoleWriter_File; +const IConsoleWriter ConsoleWriter_File = +{ + ConsoleToFile_DoWrite, + ConsoleToFile_DoWriteLn, + ConsoleToFile_Newline, - void ClearColor() - { - th_CurrentColor = DefaultConsoleColor; - } + ConsoleWriter_Null.SetTitle, + ConsoleWriter_Null.SetColor, + ConsoleWriter_Null.ClearColor, +}; - bool Newline() - { - _immediate_logger( "\n" ); +// thread-local console color storage. +static __threadlocal ConsoleColors th_CurrentColor = DefaultConsoleColor; - if( wxTheApp == NULL ) return false; +// -------------------------------------------------------------------------------------- +// ConsoleToWindow Implementations +// -------------------------------------------------------------------------------------- +static void __concall ConsoleToWindow_SetTitle( const wxString& title ) +{ + wxCommandEvent evt( wxEVT_SetTitleText ); + evt.SetString( title ); + wxGetApp().ProgramLog_PostEvent( evt ); +} - wxCommandEvent evt( wxEVT_LOG_Newline ); - wxGetApp().ProgramLog_PostEvent( evt ); - wxGetApp().ProgramLog_CountMsg(); +static void __concall ConsoleToWindow_SetColor( ConsoleColors color ) +{ + th_CurrentColor = color; +} - return false; - } +static void __concall ConsoleToWindow_ClearColor() +{ + th_CurrentColor = DefaultConsoleColor; +} - bool __fastcall Write( const wxString& fmt ) - { - _immediate_logger( fmt ); +template< const IConsoleWriter& secondary > +static void __concall ConsoleToWindow_Newline() +{ + secondary.Newline(); - if( wxTheApp == NULL ) return false; + wxCommandEvent evt( wxEVT_LOG_Newline ); + ((Pcsx2App&)*wxTheApp).ProgramLog_PostEvent( evt ); + ((Pcsx2App&)*wxTheApp).ProgramLog_CountMsg(); +} - wxCommandEvent evt( wxEVT_LOG_Write ); - evt.SetString( fmt ); - evt.SetExtraLong( th_CurrentColor ); - wxGetApp().ProgramLog_PostEvent( evt ); - wxGetApp().ProgramLog_CountMsg(); +template< const IConsoleWriter& secondary > +static void __concall ConsoleToWindow_DoWrite( const wxString& fmt ) +{ + secondary.DoWrite( fmt ); - return false; - } + wxCommandEvent evt( wxEVT_LOG_Write ); + evt.SetString( fmt ); + evt.SetExtraLong( th_CurrentColor ); + ((Pcsx2App&)*wxTheApp).ProgramLog_PostEvent( evt ); + ((Pcsx2App&)*wxTheApp).ProgramLog_CountMsg(); +} - bool __fastcall WriteLn( const wxString& fmt ) - { - const wxString fmtline( fmt + L"\n" ); - //_immediate_logger( "PCSX2 > "); - _immediate_logger( fmtline ); +template< const IConsoleWriter& secondary > +static void __concall ConsoleToWindow_DoWriteLn( const wxString& fmt ) +{ + secondary.DoWriteLn( fmt ); - if( emuLog != NULL ) - fflush( emuLog ); + // Implementation note: I've duplicated Write+Newline behavior here to avoid polluting + // the message pump with lots of erroneous messages (Newlines can be bound into Write message). - // Implementation note: I've duplicated Write+Newline behavior here to avoid polluting - // the message pump with lots of erroneous messages (Newlines can be bound into Write message). + wxCommandEvent evt( wxEVT_LOG_Write ); + evt.SetString( fmt + L"\n" ); + evt.SetExtraLong( th_CurrentColor ); + ((Pcsx2App&)*wxTheApp).ProgramLog_PostEvent( evt ); + ((Pcsx2App&)*wxTheApp).ProgramLog_CountMsg(); +} - if( wxTheApp == NULL ) return false; - wxCommandEvent evt( wxEVT_LOG_Write ); - evt.SetString( fmtline ); - evt.SetExtraLong( th_CurrentColor ); - wxGetApp().ProgramLog_PostEvent( evt ); - wxGetApp().ProgramLog_CountMsg(); +typedef void __concall DoWriteFn(const wxString&); - return false; - } +static const IConsoleWriter ConsoleWriter_Window = +{ + ConsoleToWindow_DoWrite, + ConsoleToWindow_DoWriteLn, + ConsoleToWindow_Newline, + + ConsoleToWindow_SetTitle, + ConsoleToWindow_SetColor, + ConsoleToWindow_ClearColor, +}; + +static const IConsoleWriter ConsoleWriter_WindowAndFile = +{ + ConsoleToWindow_DoWrite, + ConsoleToWindow_DoWriteLn, + ConsoleToWindow_Newline, + + ConsoleToWindow_SetTitle, + ConsoleToWindow_SetColor, + ConsoleToWindow_ClearColor, +}; + +void Pcsx2App::EnableConsoleLogging() const +{ + if( emuLog ) + Console_SetActiveHandler( (m_ProgramLogBox!=NULL) ? (IConsoleWriter&)ConsoleWriter_WindowAndFile : (IConsoleWriter&)ConsoleWriter_File ); + else + Console_SetActiveHandler( (m_ProgramLogBox!=NULL) ? (IConsoleWriter&)ConsoleWriter_Window : (IConsoleWriter&)ConsoleWriter_Buffered ); +} + +// Used to disable the emuLog disk logger, typically used when disabling or re-initializing the +// emuLog file handle. Call SetConsoleLogging to re-enable the disk logger when finished. +void Pcsx2App::DisableDiskLogging() const +{ + Console_SetActiveHandler( (m_ProgramLogBox!=NULL) ? (IConsoleWriter&)ConsoleWriter_Window : (IConsoleWriter&)ConsoleWriter_Buffered ); + + // Semi-hack: It's possible, however very unlikely, that a secondary thread could attempt + // to write to the logfile just before we disable logging, and would thus have a pending write + // operation to emuLog file handle at the same time we're trying to re-initialize it. The CRT + // has some guards of its own, and PCSX2 itself typically suspends the "log happy" threads + // when changing settings, so the chance for problems is low. We minimize it further here + // by sleeping off 5ms, which should allow any pending log-to-disk events to finish up. + // + // (the most ideal solution would be a mutex lock in the Disk logger itself, but for now I + // am going to try and keep the logger lock-free and use this semi-hack instead). + + Threading::Sleep( 5 ); +} + +void Pcsx2App::DisableWindowLogging() const +{ + Console_SetActiveHandler( (emuLog!=NULL) ? (IConsoleWriter&)ConsoleWriter_File : (IConsoleWriter&)ConsoleWriter_Buffered ); + Threading::Sleep( 5 ); } DEFINE_EVENT_TYPE( pxEVT_MSGBOX ); @@ -875,5 +918,4 @@ namespace Msgbox { CallStack( src.FormatDisplayMessage(), src.FormatDiagnosticMessage(), wxEmptyString, L"PCSX2 Unhandled Exception", wxOK ); } - } diff --git a/pcsx2/gui/ConsoleLogger.h b/pcsx2/gui/ConsoleLogger.h index 699b9c3303..2ad88a1108 100644 --- a/pcsx2/gui/ConsoleLogger.h +++ b/pcsx2/gui/ConsoleLogger.h @@ -70,7 +70,7 @@ class ConsoleTestThread : public Threading::PersistentThread { protected: volatile bool m_done; - sptr ExecuteTask(); + void ExecuteTask(); public: ConsoleTestThread() : @@ -82,6 +82,10 @@ public: { m_done = true; } + + protected: + void OnStart() {} + void OnThreadCleanup() {} }; // -------------------------------------------------------------------------------------- @@ -113,7 +117,7 @@ protected: void SetFont( const wxFont& font ); void SetFont( int fontsize ); - const wxTextAttr& operator[]( Console::Colors coloridx ) const + const wxTextAttr& operator[]( ConsoleColors coloridx ) const { return m_table[(int)coloridx]; } @@ -123,7 +127,7 @@ protected: ConLogConfig& m_conf; wxTextCtrl& m_TextCtrl; ColorArray m_ColorTable; - Console::Colors m_curcolor; + ConsoleColors m_curcolor; volatile long m_msgcounter; // used to track queued messages and throttle load placed on the gui message pump Semaphore m_semaphore; @@ -137,7 +141,7 @@ public: virtual ~ConsoleLogFrame(); virtual void Write( const wxString& text ); - virtual void SetColor( Console::Colors color ); + virtual void SetColor( ConsoleColors color ); virtual void ClearColor(); virtual void DockedMove(); @@ -145,7 +149,7 @@ public: // (settings change if the user moves the window or changes the font size) const ConLogConfig& GetConfig() const { return m_conf; } - void Write( Console::Colors color, const wxString& text ); + void Write( ConsoleColors color, const wxString& text ); void Newline(); void CountMessage(); void DoMessage(); diff --git a/pcsx2/gui/FrameForGS.cpp b/pcsx2/gui/FrameForGS.cpp index 0894cb67d0..c17ae3b699 100644 --- a/pcsx2/gui/FrameForGS.cpp +++ b/pcsx2/gui/FrameForGS.cpp @@ -76,7 +76,7 @@ void GSFrame::OnKeyDown( wxKeyEvent& evt ) if( cmd != NULL ) { - DbgCon::WriteLn( "(gsFrame) Invoking command: %s", cmd->Id ); + DbgCon.WriteLn( "(gsFrame) Invoking command: %s", cmd->Id ); cmd->Invoke(); } } diff --git a/pcsx2/gui/GlobalCommands.cpp b/pcsx2/gui/GlobalCommands.cpp index 1be0c86bc3..ec872aaeb4 100644 --- a/pcsx2/gui/GlobalCommands.cpp +++ b/pcsx2/gui/GlobalCommands.cpp @@ -89,9 +89,9 @@ namespace Implementations void Sys_RenderToggle() { if( !HasCoreThread() ) return; - SysSuspend(); + sCoreThread.Suspend(); renderswitch = !renderswitch; - SysResume(); + sCoreThread.Resume(); } void Sys_LoggingToggle() @@ -150,7 +150,7 @@ namespace Implementations { #ifdef PCSX2_DEVBUILD iDumpRegisters(cpuRegs.pc, 0); - Console::Notice("hardware registers dumped EE:%x, IOP:%x\n", cpuRegs.pc, psxRegs.pc); + Console.Notice("hardware registers dumped EE:%x, IOP:%x\n", cpuRegs.pc, psxRegs.pc); #endif } } @@ -260,7 +260,7 @@ void AcceleratorDictionary::Map( const KeyAcceleratorCode& acode, const char *se if( result != NULL ) { - Console::Notice( wxsFormat( + Console.Notice( wxsFormat( L"Kbd Accelerator '%s' is mapped multiple times.\n" L"\t'Command %s' is being replaced by '%s'", acode.ToString().c_str(), wxString::FromUTF8( result->Id ).c_str(), searchfor ) @@ -271,7 +271,7 @@ void AcceleratorDictionary::Map( const KeyAcceleratorCode& acode, const char *se if( result == NULL ) { - Console::Notice( wxsFormat( L"Kbd Accelerator '%s' is mapped to unknown command '%s'", + Console.Notice( wxsFormat( L"Kbd Accelerator '%s' is mapped to unknown command '%s'", acode.ToString().c_str(), wxString::FromUTF8( searchfor ).c_str() ) ); } diff --git a/pcsx2/gui/IniInterface.cpp b/pcsx2/gui/IniInterface.cpp index 9abde6c06f..f2c0ab1d17 100644 --- a/pcsx2/gui/IniInterface.cpp +++ b/pcsx2/gui/IniInterface.cpp @@ -174,7 +174,7 @@ void IniLoader::_EnumEntry( const wxString& var, int& value, const wxChar* const if( enumArray[i] == NULL ) { - Console::Notice( wxsFormat( L"Loadini Warning: Unrecognized value '%s' on key '%s'\n\tUsing the default setting of '%s'.", + Console.Notice( wxsFormat( L"Loadini Warning: Unrecognized value '%s' on key '%s'\n\tUsing the default setting of '%s'.", retval.c_str(), var.c_str(), enumArray[defvalue] ) ); value = defvalue; @@ -258,7 +258,7 @@ void IniSaver::_EnumEntry( const wxString& var, int& value, const wxChar* const* const int cnt = _calcEnumLength( enumArray ); if( value >= cnt ) { - Console::Notice( wxsFormat( + Console.Notice( wxsFormat( L"Settings Warning: An illegal enumerated index was detected when saving '%s'\n" L"\tIllegal Value: %d\n" L"\tUsing Default: %d (%s)\n", @@ -266,7 +266,7 @@ void IniSaver::_EnumEntry( const wxString& var, int& value, const wxChar* const* ); // Cause a debug assertion, since this is a fully recoverable error. - wxASSERT( value < cnt ); + pxAssert( value < cnt ); value = defvalue; } diff --git a/pcsx2/gui/MainFrame.cpp b/pcsx2/gui/MainFrame.cpp index 1026875668..dd36f1f5d7 100644 --- a/pcsx2/gui/MainFrame.cpp +++ b/pcsx2/gui/MainFrame.cpp @@ -140,11 +140,22 @@ void MainEmuFrame::PopulatePadMenu() // void MainEmuFrame::OnCloseWindow(wxCloseEvent& evt) { - if( !wxGetApp().PrepForExit() ) - evt.Veto( evt.CanVeto() ); + bool isClosing = false; + + if( !evt.CanVeto() ) + { + // Mandatory destruction... + isClosing = true; + } + else + { + isClosing = wxGetApp().PrepForExit(); + if( !isClosing ) evt.Veto( true ); + } + + sApp.OnMainFrameClosed(); evt.Skip(); - //Destroy(); } void MainEmuFrame::OnMoveAround( wxMoveEvent& evt ) @@ -153,7 +164,7 @@ void MainEmuFrame::OnMoveAround( wxMoveEvent& evt ) // while the logger spams itself) // ... makes for a good test of the message pump's responsiveness. if( EnableThreadedLoggingTest ) - Console::Notice( "Threaded Logging Test! (a window move event)" ); + Console.Notice( "Threaded Logging Test! (a window move event)" ); // evt.GetPosition() returns the client area position, not the window frame position. // So read the window's screen-relative position directly. @@ -466,7 +477,7 @@ void MainEmuFrame::ReloadRecentLists() // to make a clone copy of this complex object. ;) wxConfigBase* cfg = wxConfigBase::Get( false ); - wxASSERT( cfg != NULL ); + pxAssert( cfg != NULL ); if( m_RecentIsoList ) m_RecentIsoList->Save( *cfg ); diff --git a/pcsx2/gui/MainMenuClicks.cpp b/pcsx2/gui/MainMenuClicks.cpp index 5da37c5680..ca6a36d98b 100644 --- a/pcsx2/gui/MainMenuClicks.cpp +++ b/pcsx2/gui/MainMenuClicks.cpp @@ -82,13 +82,13 @@ bool MainEmuFrame::_DoSelectIsoBrowser() void MainEmuFrame::Menu_BootCdvd_Click( wxCommandEvent &event ) { - SysSuspend(); + sCoreThread.Suspend(); if( !wxFileExists( g_Conf->CurrentIso ) ) { if( !_DoSelectIsoBrowser() ) { - SysResume(); + sCoreThread.Resume(); return; } } @@ -100,7 +100,7 @@ void MainEmuFrame::Menu_BootCdvd_Click( wxCommandEvent &event ) if( !result ) { - SysResume(); + sCoreThread.Resume(); return; } } @@ -108,33 +108,33 @@ void MainEmuFrame::Menu_BootCdvd_Click( wxCommandEvent &event ) g_Conf->EmuOptions.SkipBiosSplash = GetMenuBar()->IsChecked( MenuId_SkipBiosToggle ); AppSaveSettings(); - SysExecute( g_Conf->CdvdSource ); + sApp.SysExecute( g_Conf->CdvdSource ); } void MainEmuFrame::Menu_IsoBrowse_Click( wxCommandEvent &event ) { - SysSuspend(); + sCoreThread.Suspend(); _DoSelectIsoBrowser(); - SysResume(); + sCoreThread.Resume(); } void MainEmuFrame::Menu_RunIso_Click( wxCommandEvent &event ) { - SysSuspend(); + sCoreThread.Suspend(); if( !_DoSelectIsoBrowser() ) { - SysResume(); + sCoreThread.Resume(); return; } - SysExecute( CDVDsrc_Iso ); + sApp.SysExecute( CDVDsrc_Iso ); } void MainEmuFrame::Menu_IsoRecent_Click(wxCommandEvent &event) { - //Console::Status( "%d", event.GetId() - g_RecentIsoList->GetBaseId() ); - //Console::WriteLn( Color_Magenta, g_RecentIsoList->GetHistoryFile( event.GetId() - g_RecentIsoList->GetBaseId() ) ); + //Console.Status( "%d", event.GetId() - g_RecentIsoList->GetBaseId() ); + //Console.WriteLn( Color_Magenta, g_RecentIsoList->GetHistoryFile( event.GetId() - g_RecentIsoList->GetBaseId() ) ); } #include "IniInterface.h" @@ -174,12 +174,12 @@ void MainEmuFrame::Menu_SaveStates_Click(wxCommandEvent &event) void MainEmuFrame::Menu_LoadStateOther_Click(wxCommandEvent &event) { - Console::WriteLn("If this were hooked up, it would load a savestate file."); + Console.WriteLn("If this were hooked up, it would load a savestate file."); } void MainEmuFrame::Menu_SaveStateOther_Click(wxCommandEvent &event) { - Console::WriteLn("If this were hooked up, it would save a savestate file."); + Console.WriteLn("If this were hooked up, it would save a savestate file."); } void MainEmuFrame::Menu_Exit_Click(wxCommandEvent &event) @@ -190,12 +190,13 @@ void MainEmuFrame::Menu_Exit_Click(wxCommandEvent &event) void MainEmuFrame::Menu_SuspendResume_Click(wxCommandEvent &event) { if( !SysHasValidState() ) return; - if( !HasCoreThread() ) return; - - if( GetCoreThread().IsSuspended() ) - SysResume(); - else - SysSuspend(); + if( SysCoreThread* thr = GetCoreThreadPtr() ) + { + if( thr->IsSuspended() ) + thr->Resume(); + else + thr->Suspend(); + } } void MainEmuFrame::Menu_EmuReset_Click(wxCommandEvent &event) @@ -203,10 +204,10 @@ void MainEmuFrame::Menu_EmuReset_Click(wxCommandEvent &event) if( !SysHasValidState() ) return; bool wasSuspended = HasCoreThread() ? GetCoreThread().IsSuspended() : true; - SysReset(); + sApp.SysReset(); if( !wasSuspended ) - SysExecute(); + sApp.SysExecute(); } void MainEmuFrame::Menu_ConfigPlugin_Click(wxCommandEvent &event) diff --git a/pcsx2/gui/MemoryCardFile.cpp b/pcsx2/gui/MemoryCardFile.cpp index 736bf9f5c5..dfdddf27e7 100644 --- a/pcsx2/gui/MemoryCardFile.cpp +++ b/pcsx2/gui/MemoryCardFile.cpp @@ -166,7 +166,7 @@ s32 FileMemoryCard::Read( uint port, uint slot, u8 *dest, u32 adr, int size ) wxFile& mcfp( m_file[port][slot] ); if( !mcfp.IsOpened() ) { - DevCon::Error( "MemoryCard: Ignoring attempted read from disabled card." ); + DevCon.Error( "MemoryCard: Ignoring attempted read from disabled card." ); memset(dest, 0, size); return 1; } @@ -180,7 +180,7 @@ s32 FileMemoryCard::Save( uint port, uint slot, const u8 *src, u32 adr, int size if( !mcfp.IsOpened() ) { - DevCon::Error( "MemoryCard: Ignoring attempted save/write to disabled card." ); + DevCon.Error( "MemoryCard: Ignoring attempted save/write to disabled card." ); return 1; } @@ -191,7 +191,7 @@ s32 FileMemoryCard::Save( uint port, uint slot, const u8 *src, u32 adr, int size for (int i=0; iIsChecked() ); } diff --git a/pcsx2/gui/Panels/MiscPanelStuff.cpp b/pcsx2/gui/Panels/MiscPanelStuff.cpp index 2dd494fcc0..31e5444cba 100644 --- a/pcsx2/gui/Panels/MiscPanelStuff.cpp +++ b/pcsx2/gui/Panels/MiscPanelStuff.cpp @@ -32,20 +32,20 @@ Panels::StaticApplyState Panels::g_ApplyState; // void Panels::StaticApplyState::DoCleanup() throw() { - wxASSERT_MSG( PanelList.size() != 0, L"PanelList list hasn't been cleaned up." ); + pxAssertMsg( PanelList.size() != 0, L"PanelList list hasn't been cleaned up." ); PanelList.clear(); ParentBook = NULL; } void Panels::StaticApplyState::StartBook( wxBookCtrlBase* book ) { - DevAssert( ParentBook == NULL, "An ApplicableConfig session is already in progress." ); + pxAssertDev( ParentBook == NULL, "An ApplicableConfig session is already in progress." ); ParentBook = book; } void Panels::StaticApplyState::StartWizard() { - DevAssert( ParentBook == NULL, "An ApplicableConfig session is already in progress." ); + pxAssertDev( ParentBook == NULL, "An ApplicableConfig session is already in progress." ); } // ----------------------------------------------------------------------- @@ -74,7 +74,7 @@ bool Panels::StaticApplyState::ApplyPage( int pageid, bool saveOnSuccess ) PanelApplyList_t::iterator yay = PanelList.begin(); while( yay != PanelList.end() ) { - //DbgCon::Status( L"Writing settings for: " + (*yay)->GetLabel() ); + //DbgCon.Status( L"Writing settings for: " + (*yay)->GetLabel() ); if( (pageid < 0) || (*yay)->IsOnPage( pageid ) ) (*yay)->Apply(); yay++; diff --git a/pcsx2/gui/Panels/PluginSelectorPanel.cpp b/pcsx2/gui/Panels/PluginSelectorPanel.cpp index bb672c13a7..ad29624807 100644 --- a/pcsx2/gui/Panels/PluginSelectorPanel.cpp +++ b/pcsx2/gui/Panels/PluginSelectorPanel.cpp @@ -108,7 +108,7 @@ public: if ( ((version >> 16)&0xff) == tbl_PluginInfo[pluginTypeIndex].version ) return true; - Console::Notice("%s Plugin %s: Version %x != %x", info.shortname, m_plugpath.c_str(), 0xff&(version >> 16), info.version); + Console.Notice("%s Plugin %s: Version %x != %x", info.shortname, m_plugpath.c_str(), 0xff&(version >> 16), info.version); } return false; } @@ -123,7 +123,7 @@ public: wxString GetName() const { - wxASSERT( m_GetLibName != NULL ); + pxAssert( m_GetLibName != NULL ); return wxString::FromAscii(m_GetLibName()); } @@ -315,7 +315,7 @@ void Panels::PluginSelectorPanel::Apply() // [TODO] : Post notice that this shuts down existing emulation, and may not safely recover. } - wxGetApp().SysReset(); + sApp.SysReset(); } if( !wxGetApp().m_CorePlugins ) @@ -345,6 +345,9 @@ void Panels::PluginSelectorPanel::CancelRefresh() { } +// This method is a callback from the BaseSelectorPanel. It is called when the page is shown +// and the page's enumerated selections are valid (meaning we should start our enumeration +// thread!) void Panels::PluginSelectorPanel::DoRefresh() { m_ComponentBoxes.Reset(); @@ -374,7 +377,7 @@ void Panels::PluginSelectorPanel::DoRefresh() bool Panels::PluginSelectorPanel::ValidateEnumerationStatus() { - m_EnumeratorThread = NULL; // make sure the thread is STOPPED, just in case... + if( m_EnumeratorThread ) return true; // Cant reset file lists while we're busy enumerating... bool validated = true; @@ -451,6 +454,10 @@ void Panels::PluginSelectorPanel::OnProgress( wxCommandEvent& evt ) { if( !m_FileList ) return; + // The thread can get canceled and replaced with a new thread, which means all + // pending messages should be ignored. + if( m_EnumeratorThread != (EnumThread*)evt.GetClientData() ) return; + const size_t evtidx = evt.GetExtraLong(); if( DisableThreading ) @@ -473,7 +480,7 @@ void Panels::PluginSelectorPanel::OnProgress( wxCommandEvent& evt ) if( result.TypeMask == 0 ) { - Console::Error( L"Some kinda plugin failure: " + (*m_FileList)[evtidx] ); + Console.Error( L"Some kinda plugin failure: " + (*m_FileList)[evtidx] ); } for( int i=0; iAddPendingEvent( yay ); } -sptr Panels::PluginSelectorPanel::EnumThread::ExecuteTask() +void Panels::PluginSelectorPanel::EnumThread::ExecuteTask() { - DevCon::Status( "Plugin Enumeration Thread started..." ); + DevCon.Status( "Plugin Enumeration Thread started..." ); wxGetApp().Ping(); // gives the gui thread some time to refresh Sleep( 3 ); @@ -558,11 +566,12 @@ sptr Panels::PluginSelectorPanel::EnumThread::ExecuteTask() DoNextPlugin( curidx ); if( (curidx & 3) == 3 ) wxGetApp().Ping(); // gives the gui thread some time to refresh pthread_testcancel(); + Sleep(150); } wxCommandEvent done( pxEVT_EnumerationFinished ); + done.SetClientData( this ); m_master.GetEventHandler()->AddPendingEvent( done ); - DevCon::Status( "Plugin Enumeration Thread complete!" ); - return 0; + DevCon.Status( "Plugin Enumeration Thread complete!" ); } diff --git a/pcsx2/gui/Plugins.cpp b/pcsx2/gui/Plugins.cpp index fd852de38a..aa71caaa4f 100644 --- a/pcsx2/gui/Plugins.cpp +++ b/pcsx2/gui/Plugins.cpp @@ -60,7 +60,9 @@ public: virtual ~LoadPluginsTask() throw(); protected: - int ExecuteTask(); + void OnStart() {} + void OnThreadCleanup() {} + void ExecuteTask(); }; static ScopedPtr _loadTask; @@ -74,7 +76,7 @@ LoadPluginsTask::~LoadPluginsTask() throw() _loadTask = NULL; } -int LoadPluginsTask::ExecuteTask() +void LoadPluginsTask::ExecuteTask() { wxGetApp().Ping(); Sleep(3); @@ -105,7 +107,6 @@ int LoadPluginsTask::ExecuteTask() // anything else leave unhandled so that the debugger catches it! wxGetApp().AddPendingEvent( evt ); - return 0; } ///////////////////////////////////////////////////////////////////////////////////////// @@ -188,13 +189,13 @@ void LoadPluginsPassive() // then no action is performed. void LoadPluginsImmediate() { - wxASSERT( wxThread::IsMain() ); + AllowFromMainThreadOnly(); if( g_plugins ) return; static int _reentrant = 0; - EntryGuard guard( _reentrant ); + RecursionGuard guard( _reentrant ); - wxASSERT( !guard.IsReentrant() ); + pxAssertMsg( !guard.IsReentrant(), "Recrsive calls to this function are prohibited." ); wxGetApp().ReloadPlugins(); while( _loadTask ) { diff --git a/pcsx2/gui/Saveslots.cpp b/pcsx2/gui/Saveslots.cpp index 99ebe3a7af..386e374f3d 100644 --- a/pcsx2/gui/Saveslots.cpp +++ b/pcsx2/gui/Saveslots.cpp @@ -23,24 +23,16 @@ StartupParams g_Startup; - // returns true if the new state was loaded, or false if nothing happened. void States_Load( const wxString& file ) { - SysSuspend(); + sCoreThread.ShortSuspend(); try { - SysLoadState( file ); - SysStatus( wxsFormat( _("Loaded State %s"), wxFileName( file ).GetFullName().c_str() ) ); - } - catch( Exception::BadSavedState& ex) - { - // At this point we can return control back to the user, no questions asked. - // StateLoadErrors are only thorwn if the load failed prior to any virtual machine - // memory contents being changed. (usually missing file errors) - - Console::Notice( ex.FormatDiagnosticMessage() ); + StateCopy_LoadFromFile( file ); + //SysLoadState( file ); + //SysStatus( wxsFormat( _("Loaded State %s"), wxFileName( file ).GetFullName().c_str() ) ); } catch( Exception::BaseException& ) { @@ -48,7 +40,7 @@ void States_Load( const wxString& file ) //StateRecovery::Recover(); } - SysExecute(); + sApp.SysExecute(); } // Save state save-to-file (or slot) helpers. @@ -62,7 +54,7 @@ void States_Save( const wxString& file ) try { - Console::Status( wxsFormat( L"Saving savestate to file: %s", file.c_str() ) ); + Console.Status( wxsFormat( L"Saving savestate to file: %s", file.c_str() ) ); StateCopy_SaveToFile( file ); SysStatus( wxsFormat( _("State saved to file: %s"), wxFileName( file ).GetFullName().c_str() ) ); } @@ -78,7 +70,7 @@ void States_Save( const wxString& file ) L"\n\n" + _("Error details:") + ex.DisplayMessage() );*/ - Console::Error( wxsFormat( + Console.Error( wxsFormat( L"An error occurred while trying to save to file %s\n", file.c_str() ) + L"Your emulation state has not been saved!\n" L"\nError: " + ex.FormatDiagnosticMessage() @@ -103,7 +95,7 @@ bool States_isSlotUsed(int num) void States_FreezeCurrentSlot() { - Console::Status( "Saving savestate to slot %d...", StatesC ); + Console.Status( "Saving savestate to slot %d...", StatesC ); States_Save( SaveStateBase::GetFilename( StatesC ) ); } @@ -113,18 +105,18 @@ void States_DefrostCurrentSlot() if( !wxFileExists( file ) ) { - Console::Notice( "Savestate slot %d is empty.", StatesC ); + Console.Notice( "Savestate slot %d is empty.", StatesC ); return; } - Console::Status( "Loading savestate from slot %d...", StatesC ); + Console.Status( "Loading savestate from slot %d...", StatesC ); States_Load( file ); - SysStatus( wxsFormat( _("Loaded State (slot %d)"), StatesC ) ); + //SysStatus( wxsFormat( _("Loaded State (slot %d)"), StatesC ) ); } static void OnSlotChanged() { - Console::Notice( " > Selected savestate slot %d", StatesC); + Console.Notice( " > Selected savestate slot %d", StatesC); if( GSchangeSaveState != NULL ) GSchangeSaveState(StatesC, SaveStateBase::GetFilename(StatesC).mb_str()); diff --git a/pcsx2/gui/i18n.cpp b/pcsx2/gui/i18n.cpp index 781a67f684..22aec960b0 100644 --- a/pcsx2/gui/i18n.cpp +++ b/pcsx2/gui/i18n.cpp @@ -140,8 +140,8 @@ const wxChar* __fastcall pxGetTranslation( const wxChar* message ) { if( wxStrlen( message ) > 96 ) { - Console::Notice( "pxGetTranslation: Long message detected, maybe use pxE() instead?" ); - Console::Status( wxsFormat( L"\tMessage: %s", message ) ); + Console.Notice( "pxGetTranslation: Long message detected, maybe use pxE() instead?" ); + Console.Status( wxsFormat( L"\tMessage: %s", message ) ); } } return wxGetTranslation( message ); @@ -152,7 +152,7 @@ bool i18n_SetLanguage( int wxLangId ) { if( !wxLocale::IsAvailable( wxLangId ) ) { - Console::Notice( "Invalid Language Identifier (wxID=%d).", wxLangId ); + Console.Notice( "Invalid Language Identifier (wxID=%d).", wxLangId ); return false; } @@ -160,7 +160,7 @@ bool i18n_SetLanguage( int wxLangId ) if( !locale->IsOk() ) { - Console::Notice( wxsFormat( L"SetLanguage: '%s' [%s] is not supported by the operating system", + Console.Notice( wxsFormat( L"SetLanguage: '%s' [%s] is not supported by the operating system", wxLocale::GetLanguageName( locale->GetLanguage() ).c_str(), locale->GetCanonicalName().c_str() ) ); @@ -170,7 +170,7 @@ bool i18n_SetLanguage( int wxLangId ) if( !IsEnglish(wxLangId) && !locale->AddCatalog( L"pcsx2main" ) ) { - Console::Notice( wxsFormat( L"SetLanguage: Cannot find pcsx2main.mo file for language '%s' [%s]", + Console.Notice( wxsFormat( L"SetLanguage: Cannot find pcsx2main.mo file for language '%s' [%s]", wxLocale::GetLanguageName( locale->GetLanguage() ).c_str(), locale->GetCanonicalName().c_str() ) ); safe_delete( locale ); diff --git a/pcsx2/gui/wxHelpers.cpp b/pcsx2/gui/wxHelpers.cpp index 6a8dee0039..2aa6e9c163 100644 --- a/pcsx2/gui/wxHelpers.cpp +++ b/pcsx2/gui/wxHelpers.cpp @@ -283,7 +283,7 @@ wxDialogWithHelpers::wxDialogWithHelpers( wxWindow* parent, int id, const wxStr wxDialogWithHelpers::~wxDialogWithHelpers() throw() { --m_DialogIdents[GetId()]; - wxASSERT( m_DialogIdents[GetId()] >= 0 ); + pxAssert( m_DialogIdents[GetId()] >= 0 ); } // ------------------------------------------------------------------------ diff --git a/pcsx2/ps2/BiosTools.cpp b/pcsx2/ps2/BiosTools.cpp index 413a545399..66ba6370bb 100644 --- a/pcsx2/ps2/BiosTools.cpp +++ b/pcsx2/ps2/BiosTools.cpp @@ -122,7 +122,7 @@ static void loadBiosRom( const wxChar *ext, u8 *dest, s64 maxSize ) Bios1 = Path::ReplaceExtension( Bios, ext ); if( (filesize=Path::GetFileSize( Bios1 ) ) <= 0 ) { - Console::Notice( "Load Bios Warning: %s not found (this is not an error!)", wxString(ext).ToAscii().data() ); + Console.Notice( "Load Bios Warning: %s not found (this is not an error!)", wxString(ext).ToAscii().data() ); return; } } @@ -145,7 +145,7 @@ static void loadBiosRom( const wxChar *ext, u8 *dest, s64 maxSize ) // void LoadBIOS() { - DevAssert( PS2MEM_ROM != NULL, "PS2 system memory has not been initialized yet." ); + pxAssertDev( PS2MEM_ROM != NULL, "PS2 system memory has not been initialized yet." ); wxString Bios( g_Conf->FullpathToBios() ); @@ -167,7 +167,7 @@ void LoadBIOS() } BiosVersion = GetBiosVersion(); - Console::Status("Bios Version %d.%d", BiosVersion >> 8, BiosVersion & 0xff); + Console.Status("Bios Version %d.%d", BiosVersion >> 8, BiosVersion & 0xff); //injectIRX("host.irx"); //not fully tested; still buggy diff --git a/pcsx2/ps2/GIFpath.cpp b/pcsx2/ps2/GIFpath.cpp index ce13a325ee..1eb3442868 100644 --- a/pcsx2/ps2/GIFpath.cpp +++ b/pcsx2/ps2/GIFpath.cpp @@ -184,7 +184,7 @@ static void __fastcall RegHandlerUNMAPPED(const u32* data) // Not sure what it's trying to accomplish exactly. Ignoring seems to work fine. if( regidx != 0x7f ) - Console::Notice( "Ignoring Unmapped GIFtag Register, Index = %02x", regidx ); + Console.Notice( "Ignoring Unmapped GIFtag Register, Index = %02x", regidx ); } #define INSERT_UNMAPPED_4 RegHandlerUNMAPPED, RegHandlerUNMAPPED, RegHandlerUNMAPPED, RegHandlerUNMAPPED, diff --git a/pcsx2/ps2/Iop/IopHwRead.cpp b/pcsx2/ps2/Iop/IopHwRead.cpp index cc30d76720..e931d2044a 100644 --- a/pcsx2/ps2/Iop/IopHwRead.cpp +++ b/pcsx2/ps2/Iop/IopHwRead.cpp @@ -48,12 +48,12 @@ mem8_t __fastcall iopHwRead8_Page1( u32 addr ) default: if( masked_addr >= 0x100 && masked_addr < 0x130 ) { - DevCon::Notice( "HwRead8 from Counter16 [ignored], addr 0x%08x = 0x%02x", addr, psxHu8(addr) ); + DevCon.Notice( "HwRead8 from Counter16 [ignored], addr 0x%08x = 0x%02x", addr, psxHu8(addr) ); ret = psxHu8( addr ); } else if( masked_addr >= 0x480 && masked_addr < 0x4a0 ) { - DevCon::Notice( "HwRead8 from Counter32 [ignored], addr 0x%08x = 0x%02x", addr, psxHu8(addr) ); + DevCon.Notice( "HwRead8 from Counter32 [ignored], addr 0x%08x = 0x%02x", addr, psxHu8(addr) ); ret = psxHu8( addr ); } else if( (masked_addr >= pgmsk(HW_USB_START)) && (masked_addr < pgmsk(HW_USB_END)) ) @@ -213,7 +213,7 @@ static __forceinline T _HwRead_16or32_Page1( u32 addr ) ret = SPU2read( addr ); else { - DevCon::Notice( "HwRead32 from SPU2? (addr=0x%08X) .. What manner of trickery is this?!", addr ); + DevCon.Notice( "HwRead32 from SPU2? (addr=0x%08X) .. What manner of trickery is this?!", addr ); ret = psxHu32(addr); } } diff --git a/pcsx2/ps2/Iop/IopHwWrite.cpp b/pcsx2/ps2/Iop/IopHwWrite.cpp index 5e6805bea2..447ceb5109 100644 --- a/pcsx2/ps2/Iop/IopHwWrite.cpp +++ b/pcsx2/ps2/Iop/IopHwWrite.cpp @@ -81,12 +81,12 @@ void __fastcall iopHwWrite8_Page1( u32 addr, mem8_t val ) default: if( masked_addr >= 0x100 && masked_addr < 0x130 ) { - DevCon::Notice( "HwWrite8 to Counter16 [ignored], addr 0x%08x = 0x%02x", addr, psxHu8(addr) ); + DevCon.Notice( "HwWrite8 to Counter16 [ignored], addr 0x%08x = 0x%02x", addr, psxHu8(addr) ); psxHu8( addr ) = val; } else if( masked_addr >= 0x480 && masked_addr < 0x4a0 ) { - DevCon::Notice( "HwWrite8 to Counter32 [ignored], addr 0x%08x = 0x%02x", addr, psxHu8(addr) ); + DevCon.Notice( "HwWrite8 to Counter32 [ignored], addr 0x%08x = 0x%02x", addr, psxHu8(addr) ); psxHu8( addr ) = val; } else if( masked_addr >= pgmsk(HW_USB_START) && masked_addr < pgmsk(HW_USB_END) ) @@ -119,7 +119,7 @@ void __fastcall iopHwWrite8_Page3( u32 addr, mem8_t val ) ( val == '\n' && g_pbufi != 0 ) ) { g_pbuf[g_pbufi] = 0; - DevCon::WriteLn( Color_Cyan, g_pbuf ); + DevCon.WriteLn( Color_Cyan, g_pbuf ); g_pbufi = 0; } else if( val != '\n' ) @@ -237,7 +237,7 @@ static __forceinline void _HwWrite_16or32_Page1( u32 addr, T val ) SPU2write( addr, val ); else { - DevCon::Notice( "HwWrite32 to SPU2? (addr=0x%08X) .. What manner of trickery is this?!", addr ); + DevCon.Notice( "HwWrite32 to SPU2? (addr=0x%08X) .. What manner of trickery is this?!", addr ); //psxHu(addr) = val; } } diff --git a/pcsx2/vtlb.cpp b/pcsx2/vtlb.cpp index abd53c4a4c..00c2ba4521 100644 --- a/pcsx2/vtlb.cpp +++ b/pcsx2/vtlb.cpp @@ -76,7 +76,7 @@ __forceinline DataType __fastcall MemOp_r0(u32 addr) //has to: translate, find function, call function u32 hand=(u8)vmv; u32 paddr=ppf-hand+0x80000000; - //Console::WriteLn("Translated 0x%08X to 0x%08X", addr,paddr); + //Console.WriteLn("Translated 0x%08X to 0x%08X", addr,paddr); //return reinterpret_cast::HandlerType*>(vtlbdata.RWFT[TemplateHelper::sidx][0][hand])(paddr,data); switch( DataSize ) @@ -110,7 +110,7 @@ __forceinline void __fastcall MemOp_r1(u32 addr, DataType* data) //has to: translate, find function, call function u32 hand=(u8)vmv; u32 paddr=ppf-hand+0x80000000; - //Console::WriteLn("Translated 0x%08X to 0x%08X", addr,paddr); + //Console.WriteLn("Translated 0x%08X to 0x%08X", addr,paddr); //return reinterpret_cast::HandlerType*>(RWFT[TemplateHelper::sidx][0][hand])(paddr,data); switch( DataSize ) @@ -138,7 +138,7 @@ __forceinline void __fastcall MemOp_w0(u32 addr, DataType data) //has to: translate, find function, call function u32 hand=(u8)vmv; u32 paddr=ppf-hand+0x80000000; - //Console::WriteLn("Translated 0x%08X to 0x%08X", addr,paddr); + //Console.WriteLn("Translated 0x%08X to 0x%08X", addr,paddr); switch( DataSize ) { @@ -169,7 +169,7 @@ __forceinline void __fastcall MemOp_w1(u32 addr,const DataType* data) //has to: translate, find function, call function u32 hand=(u8)vmv; u32 paddr=ppf-hand+0x80000000; - //Console::WriteLn("Translated 0x%08X to 0x%08X", addr,paddr); + //Console.WriteLn("Translated 0x%08X to 0x%08X", addr,paddr); switch( DataSize ) { case 64: return ((vtlbMemW64FP*)vtlbdata.RWFT[3][1][hand])(paddr, data); @@ -233,7 +233,7 @@ static const char* _getModeStr( u32 mode ) // Generates a tlbMiss Exception static __forceinline void vtlb_Miss(u32 addr,u32 mode) { - //Console::Error( "vtlb miss : addr 0x%X, mode %d [%s]", addr, mode, _getModeStr(mode) ); + //Console.Error( "vtlb miss : addr 0x%X, mode %d [%s]", addr, mode, _getModeStr(mode) ); //verify(false); throw R5900Exception::TLBMiss( addr, !!mode ); } @@ -242,7 +242,7 @@ static __forceinline void vtlb_Miss(u32 addr,u32 mode) // Eventually should generate a BusError exception. static __forceinline void vtlb_BusError(u32 addr,u32 mode) { - //Console::Error( "vtlb bus error : addr 0x%X, mode %d\n", addr, _getModeStr(mode) ); + //Console.Error( "vtlb bus error : addr 0x%X, mode %d\n", addr, _getModeStr(mode) ); //verify(false); throw R5900Exception::BusError( addr, !!mode ); } @@ -292,17 +292,17 @@ template void __fastcall vtlbUnmappedPWrite128(u32 addr,const mem128_t* data) { vtlb_BusError(addr|saddr,1); } ///// VTLB mapping errors (unmapped address spaces) -mem8_t __fastcall vtlbDefaultPhyRead8(u32 addr) { Console::Error("vtlbDefaultPhyRead8: 0x%X",addr); verify(false); return -1; } -mem16_t __fastcall vtlbDefaultPhyRead16(u32 addr) { Console::Error("vtlbDefaultPhyRead16: 0x%X",addr); verify(false); return -1; } -mem32_t __fastcall vtlbDefaultPhyRead32(u32 addr) { Console::Error("vtlbDefaultPhyRead32: 0x%X",addr); verify(false); return -1; } -void __fastcall vtlbDefaultPhyRead64(u32 addr,mem64_t* data) { Console::Error("vtlbDefaultPhyRead64: 0x%X",addr); verify(false); } -void __fastcall vtlbDefaultPhyRead128(u32 addr,mem128_t* data) { Console::Error("vtlbDefaultPhyRead128: 0x%X",addr); verify(false); } +mem8_t __fastcall vtlbDefaultPhyRead8(u32 addr) { Console.Error("vtlbDefaultPhyRead8: 0x%X",addr); verify(false); return -1; } +mem16_t __fastcall vtlbDefaultPhyRead16(u32 addr) { Console.Error("vtlbDefaultPhyRead16: 0x%X",addr); verify(false); return -1; } +mem32_t __fastcall vtlbDefaultPhyRead32(u32 addr) { Console.Error("vtlbDefaultPhyRead32: 0x%X",addr); verify(false); return -1; } +void __fastcall vtlbDefaultPhyRead64(u32 addr,mem64_t* data) { Console.Error("vtlbDefaultPhyRead64: 0x%X",addr); verify(false); } +void __fastcall vtlbDefaultPhyRead128(u32 addr,mem128_t* data) { Console.Error("vtlbDefaultPhyRead128: 0x%X",addr); verify(false); } -void __fastcall vtlbDefaultPhyWrite8(u32 addr,mem8_t data) { Console::Error("vtlbDefaultPhyWrite8: 0x%X",addr); verify(false); } -void __fastcall vtlbDefaultPhyWrite16(u32 addr,mem16_t data) { Console::Error("vtlbDefaultPhyWrite16: 0x%X",addr); verify(false); } -void __fastcall vtlbDefaultPhyWrite32(u32 addr,mem32_t data) { Console::Error("vtlbDefaultPhyWrite32: 0x%X",addr); verify(false); } -void __fastcall vtlbDefaultPhyWrite64(u32 addr,const mem64_t* data) { Console::Error("vtlbDefaultPhyWrite64: 0x%X",addr); verify(false); } -void __fastcall vtlbDefaultPhyWrite128(u32 addr,const mem128_t* data) { Console::Error("vtlbDefaultPhyWrite128: 0x%X",addr); verify(false); } +void __fastcall vtlbDefaultPhyWrite8(u32 addr,mem8_t data) { Console.Error("vtlbDefaultPhyWrite8: 0x%X",addr); verify(false); } +void __fastcall vtlbDefaultPhyWrite16(u32 addr,mem16_t data) { Console.Error("vtlbDefaultPhyWrite16: 0x%X",addr); verify(false); } +void __fastcall vtlbDefaultPhyWrite32(u32 addr,mem32_t data) { Console.Error("vtlbDefaultPhyWrite32: 0x%X",addr); verify(false); } +void __fastcall vtlbDefaultPhyWrite64(u32 addr,const mem64_t* data) { Console.Error("vtlbDefaultPhyWrite64: 0x%X",addr); verify(false); } +void __fastcall vtlbDefaultPhyWrite128(u32 addr,const mem128_t* data) { Console.Error("vtlbDefaultPhyWrite128: 0x%X",addr); verify(false); } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/pcsx2/windows/SamplProf.cpp b/pcsx2/windows/SamplProf.cpp index abd5f0e0fa..b276067b21 100644 --- a/pcsx2/windows/SamplProf.cpp +++ b/pcsx2/windows/SamplProf.cpp @@ -231,7 +231,7 @@ int __stdcall ProfilerThread(void* nada) rv += lst[i].ToString(tick_count); } - Console::WriteLn("+Sampling Profiler Results-\n%s\n+>", rv.ToAscii().data() ); + Console.WriteLn("+Sampling Profiler Results-\n%s\n+>", rv.ToAscii().data() ); tick_count=0; @@ -265,7 +265,7 @@ void ProfilerInit() if (ProfRunning) return; - //Console::Msg( "Profiler Thread Initializing..." ); + //Console.Msg( "Profiler Thread Initializing..." ); ProfRunning=true; DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), @@ -279,12 +279,12 @@ void ProfilerInit() hProfThread=CreateThread(0,0,(LPTHREAD_START_ROUTINE)ProfilerThread,0,0,0); SetThreadPriority(hProfThread,THREAD_PRIORITY_HIGHEST); - //Console::WriteLn( " Done!" ); + //Console.WriteLn( " Done!" ); } void ProfilerTerm() { - //Console::Msg( "Profiler Terminating..." ); + //Console.Msg( "Profiler Terminating..." ); if (!ProfRunning) return; @@ -304,7 +304,7 @@ void ProfilerTerm() CloseHandle( hMtgsThread ); DeleteCriticalSection( &ProfModulesLock ); - //Console::WriteLn( " Done!" ); + //Console.WriteLn( " Done!" ); } void ProfilerSetEnabled(bool Enabled) diff --git a/pcsx2/windows/VCprojects/pcsx2_2008.vcproj b/pcsx2/windows/VCprojects/pcsx2_2008.vcproj index 68c150c80f..7c441412d0 100644 --- a/pcsx2/windows/VCprojects/pcsx2_2008.vcproj +++ b/pcsx2/windows/VCprojects/pcsx2_2008.vcproj @@ -510,10 +510,6 @@ RelativePath="..\..\PluginManager.cpp" > - - @@ -1914,6 +1910,10 @@ RelativePath="..\..\gui\AppConfig.cpp" > + + @@ -1962,6 +1962,10 @@ RelativePath="..\..\gui\Plugins.cpp" > + + diff --git a/pcsx2/windows/WinCompressNTFS.cpp b/pcsx2/windows/WinCompressNTFS.cpp index 49ba610d8d..72f6f676c7 100644 --- a/pcsx2/windows/WinCompressNTFS.cpp +++ b/pcsx2/windows/WinCompressNTFS.cpp @@ -98,7 +98,7 @@ bool StreamException_LogFromErrno( const wxString& streamname, const wxChar* act } catch( Exception::Stream& ex ) { - Console::Notice( wxsFormat( L"%s: %s", action, ex.FormatDiagnosticMessage().c_str() ) ); + Console.Notice( wxsFormat( L"%s: %s", action, ex.FormatDiagnosticMessage().c_str() ) ); return true; } return false; @@ -113,7 +113,7 @@ bool StreamException_LogLastError( const wxString& streamname, const wxChar* act } catch( Exception::Stream& ex ) { - Console::Notice( wxsFormat( L"%s: %s", action, ex.FormatDiagnosticMessage().c_str() ) ); + Console.Notice( wxsFormat( L"%s: %s", action, ex.FormatDiagnosticMessage().c_str() ) ); return true; } return false; diff --git a/pcsx2/windows/WinConsolePipe.cpp b/pcsx2/windows/WinConsolePipe.cpp index 10df8db824..bcadd4fbf5 100644 --- a/pcsx2/windows/WinConsolePipe.cpp +++ b/pcsx2/windows/WinConsolePipe.cpp @@ -89,17 +89,17 @@ static __forceinline void CreatePipe( HANDLE& ph_Pipe, HANDLE& ph_File ) ph_Pipe = CreateNamedPipe(s_PipeName, PIPE_ACCESS_DUPLEX, 0, 1, 2048, 2048, 0, &k_Secur); if (ph_Pipe == INVALID_HANDLE_VALUE) - throw Exception::Win32Error( "Error creating Named Pipe." ); + throw Exception::Win32Error( "CreateNamedPipe failed." ); ph_File = CreateFile(s_PipeName, GENERIC_READ|GENERIC_WRITE, 0, &k_Secur, OPEN_EXISTING, 0, NULL); if (ph_File == INVALID_HANDLE_VALUE) - throw Exception::Win32Error( "Error creating Pipe Reader." ); + throw Exception::Win32Error( "CreateFile to pipe failed." ); if (!ConnectNamedPipe(ph_Pipe, NULL)) { if (GetLastError() != ERROR_PIPE_CONNECTED) - throw Exception::Win32Error( "Error connecting Pipe." ); + throw Exception::Win32Error( "ConnectNamedPipe failed." ); } SetHandleInformation(ph_Pipe, HANDLE_FLAG_INHERIT, 0); @@ -108,7 +108,7 @@ static __forceinline void CreatePipe( HANDLE& ph_Pipe, HANDLE& ph_File ) // Reads from the Pipe and appends the read data to ps_Data // returns TRUE if something was printed to console, or false if the stdout/err were idle. -static __forceinline bool ReadPipe(HANDLE h_Pipe, Console::Colors color ) +static __forceinline bool ReadPipe(HANDLE h_Pipe, ConsoleColors color ) { if( h_Pipe == INVALID_HANDLE_VALUE ) return false; @@ -129,13 +129,13 @@ static __forceinline bool ReadPipe(HANDLE h_Pipe, Console::Colors color ) if (!ReadFile(h_Pipe, s8_Buf, sizeof(s8_Buf)-1, &u32_Read, NULL)) { if (GetLastError() != ERROR_IO_PENDING) - throw Exception::Win32Error( "Error reading Pipe." ); + throw Exception::Win32Error( "ReadFile from pipe failed." ); } // ATTENTION: The Console always prints ANSI to the pipe independent if compiled as UNICODE or MBCS! s8_Buf[u32_Read] = 0; OemToCharA(s8_Buf, s8_Buf); // convert DOS codepage -> ANSI - Console::Write( color, s8_Buf ); // convert ANSI -> Unicode if compiled as Unicode + Console.Write( color, s8_Buf ); // convert ANSI -> Unicode if compiled as Unicode } while (u32_Read == sizeof(s8_Buf)-1); @@ -144,12 +144,14 @@ static __forceinline bool ReadPipe(HANDLE h_Pipe, Console::Colors color ) class WinPipeThread : public PersistentThread { + typedef PersistentThread _parent; + protected: const HANDLE& m_outpipe; - const Console::Colors m_color; + const ConsoleColors m_color; public: - WinPipeThread( const HANDLE& outpipe, Console::Colors color ) : + WinPipeThread( const HANDLE& outpipe, ConsoleColors color ) : m_outpipe( outpipe ) , m_color( color ) { @@ -158,11 +160,13 @@ public: virtual ~WinPipeThread() throw() { - PersistentThread::Cancel(); + _parent::Cancel(); } protected: - int ExecuteTask() + void OnStart() {} + + void ExecuteTask() { try { @@ -178,10 +182,11 @@ protected: { // Log error, and fail silently. It's not really important if the // pipe fails. PCSX2 will run fine without it in any case. - Console::Error( ex.FormatDiagnosticMessage() ); - return -2; + Console.Error( ex.FormatDiagnosticMessage() ); } } + + void OnThreadCleanup() { } }; class WinPipeRedirection : public PipeRedirectionBase @@ -212,7 +217,7 @@ WinPipeRedirection::WinPipeRedirection( FILE* stdstream ) : { try { - wxASSERT( stdstream == stderr || stdstream == stdout ); + pxAssert( (stdstream == stderr) || (stdstream == stdout) ); DWORD stdhandle = ( stdstream == stderr ) ? STD_ERROR_HANDLE : STD_OUTPUT_HANDLE; CreatePipe( m_pipe, m_file ); @@ -221,27 +226,33 @@ WinPipeRedirection::WinPipeRedirection( FILE* stdstream ) : // In some cases GetStdHandle can fail, even when the one we just assigned above is valid. HANDLE newhandle = GetStdHandle(stdhandle); if( newhandle == INVALID_HANDLE_VALUE ) - throw Exception::Win32Error( "PipeRedirection: GetStdHandle failed." ); + throw Exception::Win32Error( "GetStdHandle failed." ); if( newhandle == NULL ) - throw Exception::RuntimeError( "PipeRedirection: GetStdHandle returned NULL." ); // not a Win32error (no error code) + throw Exception::RuntimeError( "GetStdHandle returned NULL." ); // not a Win32error (no error code) m_crtFile = _open_osfhandle( (intptr_t)newhandle, _O_TEXT ); if( m_crtFile == -1 ) - throw Exception::RuntimeError( "PipeRedirection: _open_osfhandle returned -1." ); + throw Exception::RuntimeError( "_open_osfhandle returned -1." ); m_fp = _fdopen( m_crtFile, "w" ); if( m_fp == NULL ) - throw Exception::RuntimeError( "PipeRedirection: _fdopen returned NULL." ); + throw Exception::RuntimeError( "_fdopen returned NULL." ); *stdstream = *m_fp; setvbuf( stdstream, NULL, _IONBF, 0 ); m_Thread.Start(); } + catch( Exception::BaseException& ex ) + { + Cleanup(); + ex.DiagMsg() = (wxString)((stdstream==stdout) ? L"STDOUT" : L"STDERR") + L" Redirection Init failed: " + ex.DiagMsg(); + throw; + } catch( ... ) { - Cleanup(); throw; + throw; } } @@ -280,7 +291,7 @@ PipeRedirectionBase* NewPipeRedir( FILE* stdstream ) catch( Exception::RuntimeError& ex ) { // Entirely non-critical errors. Log 'em and move along. - Console::Error( ex.FormatDiagnosticMessage() ); + Console.Error( ex.FormatDiagnosticMessage() ); } return NULL; diff --git a/pcsx2/x86/iCOP2.cpp b/pcsx2/x86/iCOP2.cpp index 4a1c73bc44..6e532b1133 100644 --- a/pcsx2/x86/iCOP2.cpp +++ b/pcsx2/x86/iCOP2.cpp @@ -58,10 +58,10 @@ void recCOP2_SPECIAL(s32 info); void recCOP2_BC2(s32 info); void recCOP2_SPECIAL2(s32 info); void rec_C2UNK( s32 info ) { - Console::Error("Cop2 bad opcode: %x", cpuRegs.code); + Console.Error("Cop2 bad opcode: %x", cpuRegs.code); } void _vuRegs_C2UNK(VURegs * VU, _VURegsNum *VUregsn) { - Console::Error("Cop2 bad _vuRegs code:%x", cpuRegs.code); + Console.Error("Cop2 bad _vuRegs code:%x", cpuRegs.code); } static void recCFC2(s32 info) diff --git a/pcsx2/x86/iCore.cpp b/pcsx2/x86/iCore.cpp index d7e52b3dbc..ab293e9ef0 100644 --- a/pcsx2/x86/iCore.cpp +++ b/pcsx2/x86/iCore.cpp @@ -136,7 +136,7 @@ int _getFreeXMMreg() _freeXMMreg(tempi); return tempi; } - Console::Error("*PCSX2*: XMM Reg Allocation Error in _getFreeXMMreg()!"); + Console.Error("*PCSX2*: XMM Reg Allocation Error in _getFreeXMMreg()!"); return -1; } diff --git a/pcsx2/x86/iFPU.cpp b/pcsx2/x86/iFPU.cpp index 33b9572ff1..8beae7df2e 100644 --- a/pcsx2/x86/iFPU.cpp +++ b/pcsx2/x86/iFPU.cpp @@ -379,7 +379,7 @@ __forceinline void fpuFloat4(int regd) { // +NaN -> +fMax, -NaN -> -fMax, +Inf - _freeXMMreg(t1reg); } else { - Console::Error("fpuFloat2() allocation error"); + Console.Error("fpuFloat2() allocation error"); t1reg = (regd == 0) ? 1 : 0; // get a temp reg thats not regd SSE_MOVAPS_XMM_to_M128( (uptr)&FPU_FLOAT_TEMP[0], t1reg ); // backup data in t1reg to a temp address SSE_MOVSS_XMM_to_XMM(t1reg, regd); @@ -459,9 +459,9 @@ void FPU_ADD_SUB(int regd, int regt, int issub) int temp2 = _allocX86reg(-1, X86TYPE_TEMP, 0, 0); //receives regt int xmmtemp = _allocTempXMMreg(XMMT_FPS, -1); //temporary for anding with regd/regt - if (tempecx != ECX) { Console::Error("FPU: ADD/SUB Allocation Error!"); tempecx = ECX;} - if (temp2 == -1) { Console::Error("FPU: ADD/SUB Allocation Error!"); temp2 = EAX;} - if (xmmtemp == -1) { Console::Error("FPU: ADD/SUB Allocation Error!"); xmmtemp = XMM0;} + if (tempecx != ECX) { Console.Error("FPU: ADD/SUB Allocation Error!"); tempecx = ECX;} + if (temp2 == -1) { Console.Error("FPU: ADD/SUB Allocation Error!"); temp2 = EAX;} + if (xmmtemp == -1) { Console.Error("FPU: ADD/SUB Allocation Error!"); xmmtemp = XMM0;} SSE2_MOVD_XMM_to_R(tempecx, regd); SSE2_MOVD_XMM_to_R(temp2, regt); @@ -646,7 +646,7 @@ static void (*recComOpXMM_to_XMM[] )(x86SSERegType, x86SSERegType) = { int recCommutativeOp(int info, int regd, int op) { int t0reg = _allocTempXMMreg(XMMT_FPS, -1); - //if (t0reg == -1) {Console::WriteLn("FPU: CommutativeOp Allocation Error!");} + //if (t0reg == -1) {Console.WriteLn("FPU: CommutativeOp Allocation Error!");} switch(info & (PROCESS_EE_S|PROCESS_EE_T) ) { case PROCESS_EE_S: @@ -685,7 +685,7 @@ int recCommutativeOp(int info, int regd, int op) } break; default: - Console::Status("FPU: recCommutativeOp case 4"); + Console.Status("FPU: recCommutativeOp case 4"); SSE_MOVSS_M32_to_XMM(regd, (uptr)&fpuRegs.fpr[_Fs_]); SSE_MOVSS_M32_to_XMM(t0reg, (uptr)&fpuRegs.fpr[_Ft_]); if (CHECK_FPU_EXTRA_OVERFLOW || (op >= 2)) { fpuFloat2(regd); fpuFloat2(t0reg); } @@ -770,7 +770,7 @@ void recC_EQ_xmm(int info) int tempReg; int t0reg; - //Console::WriteLn("recC_EQ_xmm()"); + //Console.WriteLn("recC_EQ_xmm()"); switch(info & (PROCESS_EE_S|PROCESS_EE_T) ) { case PROCESS_EE_S: @@ -801,9 +801,9 @@ void recC_EQ_xmm(int info) SSE_UCOMISS_XMM_to_XMM(EEREC_S, EEREC_T); break; default: - Console::Status("recC_EQ_xmm: Default"); + Console.Status("recC_EQ_xmm: Default"); tempReg = _allocX86reg(-1, X86TYPE_TEMP, 0, 0); - if (tempReg < 0) {Console::Error("FPU: DIV Allocation Error!"); tempReg = EAX;} + if (tempReg < 0) {Console.Error("FPU: DIV Allocation Error!"); tempReg = EAX;} MOV32MtoR(tempReg, (uptr)&fpuRegs.fpr[_Fs_]); CMP32MtoR(tempReg, (uptr)&fpuRegs.fpr[_Ft_]); @@ -840,7 +840,7 @@ void recC_LE_xmm(int info ) int tempReg; //tempX86reg int t0reg; //tempXMMreg - //Console::WriteLn("recC_LE_xmm()"); + //Console.WriteLn("recC_LE_xmm()"); switch(info & (PROCESS_EE_S|PROCESS_EE_T) ) { case PROCESS_EE_S: @@ -881,9 +881,9 @@ void recC_LE_xmm(int info ) SSE_UCOMISS_XMM_to_XMM(EEREC_S, EEREC_T); break; default: // Untested and incorrect, but this case is never reached AFAIK (cottonvibes) - Console::Status("recC_LE_xmm: Default"); + Console.Status("recC_LE_xmm: Default"); tempReg = _allocX86reg(-1, X86TYPE_TEMP, 0, 0); - if (tempReg < 0) {Console::Error("FPU: DIV Allocation Error!"); tempReg = EAX;} + if (tempReg < 0) {Console.Error("FPU: DIV Allocation Error!"); tempReg = EAX;} MOV32MtoR(tempReg, (uptr)&fpuRegs.fpr[_Fs_]); CMP32MtoR(tempReg, (uptr)&fpuRegs.fpr[_Ft_]); @@ -914,7 +914,7 @@ void recC_LT_xmm(int info) int tempReg; int t0reg; - //Console::WriteLn("recC_LT_xmm()"); + //Console.WriteLn("recC_LT_xmm()"); switch(info & (PROCESS_EE_S|PROCESS_EE_T) ) { case PROCESS_EE_S: @@ -957,9 +957,9 @@ void recC_LT_xmm(int info) SSE_UCOMISS_XMM_to_XMM(EEREC_S, EEREC_T); break; default: - Console::Status("recC_LT_xmm: Default"); + Console.Status("recC_LT_xmm: Default"); tempReg = _allocX86reg(-1, X86TYPE_TEMP, 0, 0); - if (tempReg < 0) {Console::Error("FPU: DIV Allocation Error!"); tempReg = EAX;} + if (tempReg < 0) {Console.Error("FPU: DIV Allocation Error!"); tempReg = EAX;} MOV32MtoR(tempReg, (uptr)&fpuRegs.fpr[_Fs_]); CMP32MtoR(tempReg, (uptr)&fpuRegs.fpr[_Ft_]); @@ -1049,8 +1049,8 @@ void recDIVhelper1(int regd, int regt) // Sets flags u32 *ajmp32, *bjmp32; int t1reg = _allocTempXMMreg(XMMT_FPS, -1); int tempReg = _allocX86reg(-1, X86TYPE_TEMP, 0, 0); - //if (t1reg == -1) {Console::Error("FPU: DIV Allocation Error!");} - if (tempReg == -1) {Console::Error("FPU: DIV Allocation Error!"); tempReg = EAX;} + //if (t1reg == -1) {Console.Error("FPU: DIV Allocation Error!");} + if (tempReg == -1) {Console.Error("FPU: DIV Allocation Error!"); tempReg = EAX;} AND32ItoM((uptr)&fpuRegs.fprc[31], ~(FPUflagI|FPUflagD)); // Clear I and D flags @@ -1105,11 +1105,11 @@ void recDIV_S_xmm(int info) static u32 PCSX2_ALIGNED16(roundmode_temp[4]) = { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }; int roundmodeFlag = 0; int t0reg = _allocTempXMMreg(XMMT_FPS, -1); - //if (t0reg == -1) {Console::Error("FPU: DIV Allocation Error!");} - //Console::WriteLn("DIV"); + //if (t0reg == -1) {Console.Error("FPU: DIV Allocation Error!");} + //Console.WriteLn("DIV"); if ((g_sseMXCSR & 0x00006000) != 0x00000000) { // Set roundmode to nearest if it isn't already - //Console::WriteLn("div to nearest"); + //Console.WriteLn("div to nearest"); roundmode_temp[0] = (g_sseMXCSR & 0xFFFF9FFF); // Set new roundmode roundmode_temp[1] = g_sseMXCSR; // Backup old Roundmode SSE_LDMXCSR ((uptr)&roundmode_temp[0]); // Recompile Roundmode Change @@ -1118,14 +1118,14 @@ void recDIV_S_xmm(int info) switch(info & (PROCESS_EE_S|PROCESS_EE_T) ) { case PROCESS_EE_S: - //Console::WriteLn("FPU: DIV case 1"); + //Console.WriteLn("FPU: DIV case 1"); SSE_MOVSS_XMM_to_XMM(EEREC_D, EEREC_S); SSE_MOVSS_M32_to_XMM(t0reg, (uptr)&fpuRegs.fpr[_Ft_]); if (CHECK_FPU_EXTRA_FLAGS) recDIVhelper1(EEREC_D, t0reg); else recDIVhelper2(EEREC_D, t0reg); break; case PROCESS_EE_T: - //Console::WriteLn("FPU: DIV case 2"); + //Console.WriteLn("FPU: DIV case 2"); if (EEREC_D == EEREC_T) { SSE_MOVSS_XMM_to_XMM(t0reg, EEREC_T); SSE_MOVSS_M32_to_XMM(EEREC_D, (uptr)&fpuRegs.fpr[_Fs_]); @@ -1139,7 +1139,7 @@ void recDIV_S_xmm(int info) } break; case (PROCESS_EE_S|PROCESS_EE_T): - //Console::WriteLn("FPU: DIV case 3"); + //Console.WriteLn("FPU: DIV case 3"); if (EEREC_D == EEREC_T) { SSE_MOVSS_XMM_to_XMM(t0reg, EEREC_T); SSE_MOVSS_XMM_to_XMM(EEREC_D, EEREC_S); @@ -1153,7 +1153,7 @@ void recDIV_S_xmm(int info) } break; default: - //Console::WriteLn("FPU: DIV case 4"); + //Console.WriteLn("FPU: DIV case 4"); SSE_MOVSS_M32_to_XMM(t0reg, (uptr)&fpuRegs.fpr[_Ft_]); SSE_MOVSS_M32_to_XMM(EEREC_D, (uptr)&fpuRegs.fpr[_Fs_]); if (CHECK_FPU_EXTRA_FLAGS) recDIVhelper1(EEREC_D, t0reg); @@ -1591,19 +1591,19 @@ void recSUBhelper(int regd, int regt) void recSUBop(int info, int regd) { int t0reg = _allocTempXMMreg(XMMT_FPS, -1); - //if (t0reg == -1) {Console::Error("FPU: SUB Allocation Error!");} + //if (t0reg == -1) {Console.Error("FPU: SUB Allocation Error!");} //AND32ItoM((uptr)&fpuRegs.fprc[31], ~(FPUflagO|FPUflagU)); // Clear O and U flags switch(info & (PROCESS_EE_S|PROCESS_EE_T) ) { case PROCESS_EE_S: - //Console::WriteLn("FPU: SUB case 1"); + //Console.WriteLn("FPU: SUB case 1"); if (regd != EEREC_S) SSE_MOVSS_XMM_to_XMM(regd, EEREC_S); SSE_MOVSS_M32_to_XMM(t0reg, (uptr)&fpuRegs.fpr[_Ft_]); recSUBhelper(regd, t0reg); break; case PROCESS_EE_T: - //Console::WriteLn("FPU: SUB case 2"); + //Console.WriteLn("FPU: SUB case 2"); if (regd == EEREC_T) { SSE_MOVSS_XMM_to_XMM(t0reg, EEREC_T); SSE_MOVSS_M32_to_XMM(regd, (uptr)&fpuRegs.fpr[_Fs_]); @@ -1615,7 +1615,7 @@ void recSUBop(int info, int regd) } break; case (PROCESS_EE_S|PROCESS_EE_T): - //Console::WriteLn("FPU: SUB case 3"); + //Console.WriteLn("FPU: SUB case 3"); if (regd == EEREC_T) { SSE_MOVSS_XMM_to_XMM(t0reg, EEREC_T); SSE_MOVSS_XMM_to_XMM(regd, EEREC_S); @@ -1627,7 +1627,7 @@ void recSUBop(int info, int regd) } break; default: - Console::Notice("FPU: SUB case 4"); + Console.Notice("FPU: SUB case 4"); SSE_MOVSS_M32_to_XMM(t0reg, (uptr)&fpuRegs.fpr[_Ft_]); SSE_MOVSS_M32_to_XMM(regd, (uptr)&fpuRegs.fpr[_Fs_]); recSUBhelper(regd, t0reg); @@ -1663,10 +1663,10 @@ void recSQRT_S_xmm(int info) u8* pjmp; static u32 PCSX2_ALIGNED16(roundmode_temp[4]) = { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }; int roundmodeFlag = 0; - //Console::WriteLn("FPU: SQRT"); + //Console.WriteLn("FPU: SQRT"); if ((g_sseMXCSR & 0x00006000) != 0x00000000) { // Set roundmode to nearest if it isn't already - //Console::WriteLn("sqrt to nearest"); + //Console.WriteLn("sqrt to nearest"); roundmode_temp[0] = (g_sseMXCSR & 0xFFFF9FFF); // Set new roundmode roundmode_temp[1] = g_sseMXCSR; // Backup old Roundmode SSE_LDMXCSR ((uptr)&roundmode_temp[0]); // Recompile Roundmode Change @@ -1678,7 +1678,7 @@ void recSQRT_S_xmm(int info) if (CHECK_FPU_EXTRA_FLAGS) { int tempReg = _allocX86reg(-1, X86TYPE_TEMP, 0, 0); - if (tempReg == -1) {Console::Error("FPU: SQRT Allocation Error!"); tempReg = EAX;} + if (tempReg == -1) {Console.Error("FPU: SQRT Allocation Error!"); tempReg = EAX;} AND32ItoM((uptr)&fpuRegs.fprc[31], ~(FPUflagI|FPUflagD)); // Clear I and D flags @@ -1717,8 +1717,8 @@ void recRSQRThelper1(int regd, int t0reg) // Preforms the RSQRT function when re u8 *qjmp1, *qjmp2; int t1reg = _allocTempXMMreg(XMMT_FPS, -1); int tempReg = _allocX86reg(-1, X86TYPE_TEMP, 0, 0); - //if (t1reg == -1) {Console::Error("FPU: RSQRT Allocation Error!");} - if (tempReg == -1) {Console::Error("FPU: RSQRT Allocation Error!"); tempReg = EAX;} + //if (t1reg == -1) {Console.Error("FPU: RSQRT Allocation Error!");} + if (tempReg == -1) {Console.Error("FPU: RSQRT Allocation Error!"); tempReg = EAX;} AND32ItoM((uptr)&fpuRegs.fprc[31], ~(FPUflagI|FPUflagD)); // Clear I and D flags @@ -1784,33 +1784,33 @@ void recRSQRThelper2(int regd, int t0reg) // Preforms the RSQRT function when re void recRSQRT_S_xmm(int info) { int t0reg = _allocTempXMMreg(XMMT_FPS, -1); - //if (t0reg == -1) {Console::Error("FPU: RSQRT Allocation Error!");} - //Console::WriteLn("FPU: RSQRT"); + //if (t0reg == -1) {Console.Error("FPU: RSQRT Allocation Error!");} + //Console.WriteLn("FPU: RSQRT"); switch(info & (PROCESS_EE_S|PROCESS_EE_T) ) { case PROCESS_EE_S: - //Console::WriteLn("FPU: RSQRT case 1"); + //Console.WriteLn("FPU: RSQRT case 1"); SSE_MOVSS_XMM_to_XMM(EEREC_D, EEREC_S); SSE_MOVSS_M32_to_XMM(t0reg, (uptr)&fpuRegs.fpr[_Ft_]); if (CHECK_FPU_EXTRA_FLAGS) recRSQRThelper1(EEREC_D, t0reg); else recRSQRThelper2(EEREC_D, t0reg); break; case PROCESS_EE_T: - //Console::WriteLn("FPU: RSQRT case 2"); + //Console.WriteLn("FPU: RSQRT case 2"); SSE_MOVSS_XMM_to_XMM(t0reg, EEREC_T); SSE_MOVSS_M32_to_XMM(EEREC_D, (uptr)&fpuRegs.fpr[_Fs_]); if (CHECK_FPU_EXTRA_FLAGS) recRSQRThelper1(EEREC_D, t0reg); else recRSQRThelper2(EEREC_D, t0reg); break; case (PROCESS_EE_S|PROCESS_EE_T): - //Console::WriteLn("FPU: RSQRT case 3"); + //Console.WriteLn("FPU: RSQRT case 3"); SSE_MOVSS_XMM_to_XMM(t0reg, EEREC_T); SSE_MOVSS_XMM_to_XMM(EEREC_D, EEREC_S); if (CHECK_FPU_EXTRA_FLAGS) recRSQRThelper1(EEREC_D, t0reg); else recRSQRThelper2(EEREC_D, t0reg); break; default: - //Console::WriteLn("FPU: RSQRT case 4"); + //Console.WriteLn("FPU: RSQRT case 4"); SSE_MOVSS_M32_to_XMM(t0reg, (uptr)&fpuRegs.fpr[_Ft_]); SSE_MOVSS_M32_to_XMM(EEREC_D, (uptr)&fpuRegs.fpr[_Fs_]); if (CHECK_FPU_EXTRA_FLAGS) recRSQRThelper1(EEREC_D, t0reg); diff --git a/pcsx2/x86/iFPUd.cpp b/pcsx2/x86/iFPUd.cpp index 810dcf543f..a0f544df2d 100644 --- a/pcsx2/x86/iFPUd.cpp +++ b/pcsx2/x86/iFPUd.cpp @@ -308,9 +308,9 @@ void FPU_ADD_SUB(int tempd, int tempt) //tempd and tempt are overwritten, they a int temp2 = _allocX86reg(-1, X86TYPE_TEMP, 0, 0); //receives regt int xmmtemp = _allocTempXMMreg(XMMT_FPS, -1); //temporary for anding with regd/regt - if (tempecx != ECX) { Console::Error("FPU: ADD/SUB Allocation Error!"); tempecx = ECX;} - if (temp2 == -1) { Console::Error("FPU: ADD/SUB Allocation Error!"); temp2 = EAX;} - if (xmmtemp == -1) { Console::Error("FPU: ADD/SUB Allocation Error!"); xmmtemp = XMM0;} + if (tempecx != ECX) { Console.Error("FPU: ADD/SUB Allocation Error!"); tempecx = ECX;} + if (temp2 == -1) { Console.Error("FPU: ADD/SUB Allocation Error!"); temp2 = EAX;} + if (xmmtemp == -1) { Console.Error("FPU: ADD/SUB Allocation Error!"); xmmtemp = XMM0;} SSE2_MOVD_XMM_to_R(tempecx, tempd); SSE2_MOVD_XMM_to_R(temp2, tempt); @@ -554,8 +554,8 @@ void recDIVhelper1(int regd, int regt) // Sets flags u32 *ajmp32, *bjmp32; int t1reg = _allocTempXMMreg(XMMT_FPS, -1); int tempReg = _allocX86reg(-1, X86TYPE_TEMP, 0, 0); - if (t1reg == -1) {Console::Error("FPU: DIV Allocation Error!");} - if (tempReg == -1) {Console::Error("FPU: DIV Allocation Error!"); tempReg = EAX;} + if (t1reg == -1) {Console.Error("FPU: DIV Allocation Error!");} + if (tempReg == -1) {Console.Error("FPU: DIV Allocation Error!"); tempReg = EAX;} AND32ItoM((uptr)&fpuRegs.fprc[31], ~(FPUflagI|FPUflagD)); // Clear I and D flags @@ -611,11 +611,11 @@ void recDIV_S_xmm(int info) { static u32 PCSX2_ALIGNED16(roundmode_temp[4]) = { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }; int roundmodeFlag = 0; - //if (t0reg == -1) {Console::Error("FPU: DIV Allocation Error!");} - //Console::WriteLn("DIV"); + //if (t0reg == -1) {Console.Error("FPU: DIV Allocation Error!");} + //Console.WriteLn("DIV"); if ((g_sseMXCSR & 0x00006000) != 0x00000000) { // Set roundmode to nearest if it isn't already - //Console::WriteLn("div to nearest"); + //Console.WriteLn("div to nearest"); roundmode_temp[0] = (g_sseMXCSR & 0xFFFF9FFF); // Set new roundmode roundmode_temp[1] = g_sseMXCSR; // Backup old Roundmode SSE_LDMXCSR ((uptr)&roundmode_temp[0]); // Recompile Roundmode Change @@ -872,13 +872,13 @@ void recSQRT_S_xmm(int info) static u32 PCSX2_ALIGNED16(roundmode_temp[4]) = { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }; int roundmodeFlag = 0; int tempReg = _allocX86reg(-1, X86TYPE_TEMP, 0, 0); - if (tempReg == -1) {Console::Error("FPU: SQRT Allocation Error!"); tempReg = EAX;} + if (tempReg == -1) {Console.Error("FPU: SQRT Allocation Error!"); tempReg = EAX;} int t1reg = _allocTempXMMreg(XMMT_FPS, -1); - if (t1reg == -1) {Console::Error("FPU: SQRT Allocation Error!");} - //Console::WriteLn("FPU: SQRT"); + if (t1reg == -1) {Console.Error("FPU: SQRT Allocation Error!");} + //Console.WriteLn("FPU: SQRT"); if ((g_sseMXCSR & 0x00006000) != 0x00000000) { // Set roundmode to nearest if it isn't already - //Console::WriteLn("sqrt to nearest"); + //Console.WriteLn("sqrt to nearest"); roundmode_temp[0] = (g_sseMXCSR & 0xFFFF9FFF); // Set new roundmode roundmode_temp[1] = g_sseMXCSR; // Backup old Roundmode SSE_LDMXCSR ((uptr)&roundmode_temp[0]); // Recompile Roundmode Change @@ -931,8 +931,8 @@ void recRSQRThelper1(int regd, int regt) // Preforms the RSQRT function when reg u32 *pjmp32; int t1reg = _allocTempXMMreg(XMMT_FPS, -1); int tempReg = _allocX86reg(-1, X86TYPE_TEMP, 0, 0); - if (t1reg == -1) {Console::Error("FPU: RSQRT Allocation Error!");} - if (tempReg == -1) {Console::Error("FPU: RSQRT Allocation Error!"); tempReg = EAX;} + if (t1reg == -1) {Console.Error("FPU: RSQRT Allocation Error!");} + if (tempReg == -1) {Console.Error("FPU: RSQRT Allocation Error!"); tempReg = EAX;} AND32ItoM((uptr)&fpuRegs.fprc[31], ~(FPUflagI|FPUflagD)); // Clear I and D flags @@ -998,7 +998,7 @@ void recRSQRT_S_xmm(int info) static u32 PCSX2_ALIGNED16(roundmode_temp[4]) = { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }; int roundmodeFlag = 0; if ((g_sseMXCSR & 0x00006000) != 0x00000000) { // Set roundmode to nearest if it isn't already - //Console::WriteLn("rsqrt to nearest"); + //Console.WriteLn("rsqrt to nearest"); roundmode_temp[0] = (g_sseMXCSR & 0xFFFF9FFF); // Set new roundmode roundmode_temp[1] = g_sseMXCSR; // Backup old Roundmode SSE_LDMXCSR ((uptr)&roundmode_temp[0]); // Recompile Roundmode Change diff --git a/pcsx2/x86/iMMI.cpp b/pcsx2/x86/iMMI.cpp index 0a36ebdb7a..7f505ec27f 100644 --- a/pcsx2/x86/iMMI.cpp +++ b/pcsx2/x86/iMMI.cpp @@ -242,7 +242,7 @@ void recPMFHL() } break; default: - Console::Error("PMFHL?? *pcsx2 head esplode!*"); + Console.Error("PMFHL?? *pcsx2 head esplode!*"); assert(0); } @@ -1507,7 +1507,7 @@ void recPEXTUH() void recQFSRV() { if ( !_Rd_ ) return; - //Console::WriteLn("recQFSRV()"); + //Console.WriteLn("recQFSRV()"); int info = eeRecompileCodeXMM( XMMINFO_READS | XMMINFO_READT | XMMINFO_WRITED ); diff --git a/pcsx2/x86/iR3000A.cpp b/pcsx2/x86/iR3000A.cpp index 2dd2e7acc8..ae3ea7c94d 100644 --- a/pcsx2/x86/iR3000A.cpp +++ b/pcsx2/x86/iR3000A.cpp @@ -151,7 +151,7 @@ static void iIopDumpBlock( int startpc, u8 * ptr ) u8 used[34]; int numused, count; - Console::WriteLn( "dump1 %x:%x, %x", startpc, psxpc, psxRegs.cycle ); + Console.WriteLn( "dump1 %x:%x, %x", startpc, psxpc, psxRegs.cycle ); g_Conf->Folders.Logs.Mkdir(); wxString filename( Path::Combine( g_Conf->Folders.Logs, wxsFormat( L"psxdump%.8X.txt", startpc ) ) ); @@ -559,7 +559,7 @@ void recResetIOP() jASSUME( recMem != NULL ); jASSUME( m_recBlockAlloc != NULL ); - DevCon::Status( "iR3000A Resetting recompiler memory and structures" ); + DevCon.Status( "iR3000A Resetting recompiler memory and structures" ); memset_8<0xcc,RECMEM_SIZE>( recMem ); // 0xcc is INT3 iopClearRecLUT((BASEBLOCK*)m_recBlockAlloc, @@ -716,7 +716,7 @@ static __forceinline u32 psxRecClearMem(u32 pc) blockidx=0; while(BASEBLOCKEX* pexblock = recBlocks[blockidx++]) if (pc >= pexblock->startpc && pc < pexblock->startpc + pexblock->size * 4) { - Console::Error("Impossible block clearing failure"); + Console.Error("Impossible block clearing failure"); jASSUME(0); } #endif @@ -838,7 +838,7 @@ static void checkcodefn() #else __asm__("movl %%eax, %[pctemp]" : : [pctemp]"m"(pctemp) ); #endif - Console::WriteLn("iop code changed! %x", pctemp); + Console.WriteLn("iop code changed! %x", pctemp); } #endif #endif diff --git a/pcsx2/x86/iR3000Atables.cpp b/pcsx2/x86/iR3000Atables.cpp index b8cd86dad2..00ac859299 100644 --- a/pcsx2/x86/iR3000Atables.cpp +++ b/pcsx2/x86/iR3000Atables.cpp @@ -1788,7 +1788,7 @@ static void rpsxCOP0() { rpsxCP0[_Rs_](); } //static void rpsxBASIC() { rpsxCP2BSC[_Rs_](); } static void rpsxNULL() { - Console::WriteLn("psxUNK: %8.8x", psxRegs.code); + Console.WriteLn("psxUNK: %8.8x", psxRegs.code); } void (*rpsxBSC[64])() = { diff --git a/pcsx2/x86/iR5900Misc.cpp b/pcsx2/x86/iR5900Misc.cpp index cd16944288..3d929d764f 100644 --- a/pcsx2/x86/iR5900Misc.cpp +++ b/pcsx2/x86/iR5900Misc.cpp @@ -148,32 +148,32 @@ void recMTSAH( void ) //////////////////////////////////////////////////// void recNULL( void ) { - Console::Error("EE: Unimplemented op %x", cpuRegs.code); + Console.Error("EE: Unimplemented op %x", cpuRegs.code); } //////////////////////////////////////////////////// void recUnknown() { // TODO : Unknown ops should throw an exception. - Console::Error("EE: Unrecognized op %x", cpuRegs.code); + Console.Error("EE: Unrecognized op %x", cpuRegs.code); } void recMMI_Unknown() { // TODO : Unknown ops should throw an exception. - Console::Error("EE: Unrecognized MMI op %x", cpuRegs.code); + Console.Error("EE: Unrecognized MMI op %x", cpuRegs.code); } void recCOP0_Unknown() { // TODO : Unknown ops should throw an exception. - Console::Error("EE: Unrecognized COP0 op %x", cpuRegs.code); + Console.Error("EE: Unrecognized COP0 op %x", cpuRegs.code); } void recCOP1_Unknown() { // TODO : Unknown ops should throw an exception. - Console::Error("EE: Unrecognized FPU/COP1 op %x", cpuRegs.code); + Console.Error("EE: Unrecognized FPU/COP1 op %x", cpuRegs.code); } /********************************************************** diff --git a/pcsx2/x86/iVU1micro.cpp b/pcsx2/x86/iVU1micro.cpp index b9c648881a..9375ec6533 100644 --- a/pcsx2/x86/iVU1micro.cpp +++ b/pcsx2/x86/iVU1micro.cpp @@ -97,8 +97,8 @@ static u32 runCount = 0; #define fABS(aInt) (aInt & 0x7fffffff) //#define cmpU(uA, uB) (fABS(uA) != fABS(uB)) #define cmpU(uA, uB) (uA != uB) -#define cmpA Console::Error -#define cmpB Console::WriteLn +#define cmpA Console.Error +#define cmpB Console.WriteLn #define cmpPrint(cond) { \ if (cond) { \ cmpA("%s", str1); \ @@ -123,7 +123,7 @@ namespace VU1micro { if((VU0.VI[REG_VPU_STAT].UL & 0x100) == 0) return; assert((VU1.VI[ REG_TPC ].UL&7) == 0); - if (VU1.VI[REG_TPC].UL >= VU1.maxmicro) { Console::Error("VU1 memory overflow!!: %x", VU1.VI[REG_TPC].UL); } + if (VU1.VI[REG_TPC].UL >= VU1.maxmicro) { Console.Error("VU1 memory overflow!!: %x", VU1.VI[REG_TPC].UL); } #ifdef DEBUG_COMPARE SysPrintf("(%08d) StartPC = 0x%04x\n", runAmount, VU1.VI[REG_TPC].UL); @@ -152,14 +152,14 @@ namespace VU1micro char str2[150]; SysPrintf("\n\n"); SysPrintf("-----------------------------------------------\n"); - Console::Notice("Problem Occurred!"); + Console.Notice("Problem Occurred!"); SysPrintf("-----------------------------------------------\n"); SysPrintf("runCount = %d\n", runCount); SysPrintf("StartPC [%04x]\n", ((VURegs*)backVUregs)->VI[REG_TPC].UL); SysPrintf("-----------------------------------------------\n\n"); SysPrintf("-----------------------------------------------\n"); - Console::Notice("Super VU / Micro VU"); + Console.Notice("Super VU / Micro VU"); SysPrintf("-----------------------------------------------\n"); for (int i = 0; i < 32; i++) { @@ -280,7 +280,7 @@ namespace VU1micro if (useMVU1) runVUrec(VU1.VI[REG_TPC].UL, 3000000, 1); else { if (VU1.VI[REG_TPC].UL >= VU1.maxmicro) { - Console::Error("VU1 memory overflow!!: %x", VU1.VI[REG_TPC].UL); + Console.Error("VU1 memory overflow!!: %x", VU1.VI[REG_TPC].UL); } do { // while loop needed since not always will return finished SuperVUExecuteProgram(VU1.VI[REG_TPC].UL & 0x3fff, 1); diff --git a/pcsx2/x86/ix86-32/iCore-32.cpp b/pcsx2/x86/ix86-32/iCore-32.cpp index 955d2d10c9..82640ab25f 100644 --- a/pcsx2/x86/ix86-32/iCore-32.cpp +++ b/pcsx2/x86/ix86-32/iCore-32.cpp @@ -156,7 +156,7 @@ int _getFreeX86reg(int mode) _freeX86reg(tempi); return tempi; } - Console::Error("*PCSX2*: x86 error"); + Console.Error("*PCSX2*: x86 error"); assert(0); return -1; @@ -547,7 +547,7 @@ int _getFreeMMXreg() _freeMMXreg(tempi); return tempi; } - Console::Error("*PCSX2*: mmx error"); + Console.Error("*PCSX2*: mmx error"); assert(0); return -1; diff --git a/pcsx2/x86/ix86-32/iR5900-32.cpp b/pcsx2/x86/ix86-32/iR5900-32.cpp index 75e0c55c4d..0c0e225776 100644 --- a/pcsx2/x86/ix86-32/iR5900-32.cpp +++ b/pcsx2/x86/ix86-32/iR5900-32.cpp @@ -284,7 +284,7 @@ u32* recGetImm64(u32 hi, u32 lo) if (recConstBufPtr >= recConstBuf + RECCONSTBUF_SIZE) { - Console::Status( "EErec const buffer filled; Resetting..." ); + Console.Status( "EErec const buffer filled; Resetting..." ); throw Exception::ForceDispatcherReg(); /*for (u32 *p = recConstBuf; p < recConstBuf + RECCONSTBUF_SIZE; p += 2) @@ -305,7 +305,7 @@ u32* recGetImm64(u32 hi, u32 lo) imm64[0] = lo; imm64[1] = hi; - //Console::Notice("Consts allocated: %d of %u", (recConstBufPtr - recConstBuf) / 2, count); + //Console.Notice("Consts allocated: %d of %u", (recConstBufPtr - recConstBuf) / 2, count); return imm64; } @@ -395,7 +395,7 @@ volatile bool eeRecIsReset = false; //////////////////////////////////////////////////// void recResetEE( void ) { - Console::Status( "Issuing EE/iR5900-32 Recompiler Reset [mem/structure cleanup]" ); + Console.Status( "Issuing EE/iR5900-32 Recompiler Reset [mem/structure cleanup]" ); eeRecIsReset = true; maxrecmem = 0; @@ -491,8 +491,8 @@ void recEventTest() // dont' remove this check unless doing an official release if( g_globalXMMSaved || g_globalMMXSaved) { - DevCon::Error("PCSX2 Foopah! Frozen regs have not been restored!!!"); - DevCon::Error("g_globalXMMSaved = %d,g_globalMMXSaved = %d", g_globalXMMSaved, g_globalMMXSaved); + DevCon.Error("PCSX2 Foopah! Frozen regs have not been restored!!!"); + DevCon.Error("g_globalXMMSaved = %d,g_globalMMXSaved = %d", g_globalXMMSaved, g_globalMMXSaved); } assert( !g_globalXMMSaved && !g_globalMMXSaved); #endif @@ -743,8 +743,8 @@ void recClear(u32 addr, u32 size) u32 blockend = pexblock->startpc + pexblock->size * 4; if (pexblock->startpc >= addr && pexblock->startpc < addr + size * 4 || pexblock->startpc < addr && blockend > addr) { - Console::Error( "Impossible block clearing failure" ); - wxASSERT_MSG( false, L"Impossible block clearing failure" ); + Console.Error( "Impossible block clearing failure" ); + pxFail( "Impossible block clearing failure" ); } } #endif @@ -893,12 +893,12 @@ void iFlushCall(int flushtype) // int i; // for(i = 0; i < 32; ++i ) { // if( fpuRegs.fpr[i].UL== 0x7f800000 || fpuRegs.fpr[i].UL == 0xffc00000) { -// Console::WriteLn("bad fpu: %x %x %x", i, cpuRegs.cycle, g_lastpc); +// Console.WriteLn("bad fpu: %x %x %x", i, cpuRegs.cycle, g_lastpc); // } // // if( VU0.VF[i].UL[0] == 0xffc00000 || //(VU0.VF[i].UL[1]&0xffc00000) == 0xffc00000 || // VU0.VF[i].UL[0] == 0x7f800000) { -// Console::WriteLn("bad vu0: %x %x %x", i, cpuRegs.cycle, g_lastpc); +// Console.WriteLn("bad vu0: %x %x %x", i, cpuRegs.cycle, g_lastpc); // } // } //} @@ -1045,7 +1045,7 @@ static void checkcodefn() __asm__("movl %%eax, %[pctemp]" : [pctemp]"=m"(pctemp) ); #endif - Console::Error("code changed! %x", pctemp); + Console.Error("code changed! %x", pctemp); assert(0); } @@ -1115,7 +1115,7 @@ void recompileNextInstruction(int delayslot) case 1: switch(_Rt_) { case 0: case 1: case 2: case 3: case 0x10: case 0x11: case 0x12: case 0x13: - Console::Notice("branch %x in delay slot!", cpuRegs.code); + Console.Notice("branch %x in delay slot!", cpuRegs.code); _clearNeededX86regs(); _clearNeededMMXregs(); _clearNeededXMMregs(); @@ -1124,7 +1124,7 @@ void recompileNextInstruction(int delayslot) break; case 2: case 3: case 4: case 5: case 6: case 7: case 0x14: case 0x15: case 0x16: case 0x17: - Console::Notice("branch %x in delay slot!", cpuRegs.code); + Console.Notice("branch %x in delay slot!", cpuRegs.code); _clearNeededX86regs(); _clearNeededMMXregs(); _clearNeededXMMregs(); @@ -1187,14 +1187,14 @@ static void printfn() u32 s_recblocks[] = {0}; void badespfn() { - Console::Error("Bad esp!"); + Console.Error("Bad esp!"); assert(0); } // Called when a block under manual protection fails it's pre-execution integrity check. void __fastcall dyna_block_discard(u32 start,u32 sz) { - DevCon::WriteLn("dyna_block_discard .. start=0x%08X size=%d", start, sz*4); + DevCon.WriteLn("dyna_block_discard .. start=0x%08X size=%d", start, sz*4); recClear(start, sz); } @@ -1227,7 +1227,7 @@ void recRecompile( const u32 startpc ) recResetEE(); } if ( (recConstBufPtr - recConstBuf) >= RECCONSTBUF_SIZE - 64 ) { - DevCon::WriteLn("EE recompiler stack reset"); + DevCon.WriteLn("EE recompiler stack reset"); recResetEE(); } @@ -1291,7 +1291,7 @@ void recRecompile( const u32 startpc ) willbranch3 = 1; s_nEndBlock = i; - //DevCon::Notice( "Pagesplit @ %08X : size=%d insts", startpc, (i-startpc) / 4 ); + //DevCon.Notice( "Pagesplit @ %08X : size=%d insts", startpc, (i-startpc) / 4 ); break; } @@ -1513,12 +1513,12 @@ StartRecomp: xJC( dyna_page_reset ); // note: clearcnt is measured per-page, not per-block! - //DbgCon::WriteLn( "Manual block @ %08X : size=%3d page/offs=%05X/%03X inpgsz=%d clearcnt=%d", + //DbgCon.WriteLn( "Manual block @ %08X : size=%3d page/offs=%05X/%03X inpgsz=%d clearcnt=%d", // startpc, sz, inpage_ptr>>12, inpage_ptr&0xfff, inpage_sz, manual_counter[inpage_ptr >> 12] ); } else { - DbgCon::Notice( "Uncounted Manual block @ %08X : size=%3d page/offs=%05X/%03X inpgsz=%d", + DbgCon.Notice( "Uncounted Manual block @ %08X : size=%3d page/offs=%05X/%03X inpgsz=%d", startpc, sz, inpage_ptr>>12, inpage_ptr&0xfff, pgsz, inpage_sz ); } diff --git a/pcsx2/x86/ix86-32/iR5900Branch.cpp b/pcsx2/x86/ix86-32/iR5900Branch.cpp index 350b61e8bb..88e8006116 100644 --- a/pcsx2/x86/ix86-32/iR5900Branch.cpp +++ b/pcsx2/x86/ix86-32/iR5900Branch.cpp @@ -490,7 +490,7 @@ EERECOMPILE_CODE0(BNEL, XMMINFO_READS|XMMINFO_READT); //////////////////////////////////////////////////// //void recBLTZAL( void ) //{ -// Console::WriteLn("BLTZAL"); +// Console.WriteLn("BLTZAL"); // _eeFlushAllUnused(); // MOV32ItoM( (int)&cpuRegs.code, cpuRegs.code ); // MOV32ItoM( (int)&cpuRegs.pc, pc ); diff --git a/pcsx2/x86/ix86-32/iR5900LoadStore.cpp b/pcsx2/x86/ix86-32/iR5900LoadStore.cpp index 0c84228334..29b997c910 100644 --- a/pcsx2/x86/ix86-32/iR5900LoadStore.cpp +++ b/pcsx2/x86/ix86-32/iR5900LoadStore.cpp @@ -184,7 +184,7 @@ void assertmem() { __asm mov s_tempaddr, ecx __asm mov s_bCachingMem, edx - Console::Error("%x(%x) not mem write!", s_tempaddr, s_bCachingMem); + Console.Error("%x(%x) not mem write!", s_tempaddr, s_bCachingMem); assert(0); } diff --git a/pcsx2/x86/ix86-32/recVTLB.cpp b/pcsx2/x86/ix86-32/recVTLB.cpp index 01d999417b..51253094a6 100644 --- a/pcsx2/x86/ix86-32/recVTLB.cpp +++ b/pcsx2/x86/ix86-32/recVTLB.cpp @@ -121,7 +121,7 @@ void iMOV64_Smart( const ModSibBase& destRm, const ModSibBase& srcRm ) //has to: translate, find function, call function u32 hand=(u8)vmv; u32 paddr=ppf-hand+0x80000000; - //Console::WriteLn("Translated 0x%08X to 0x%08X",params addr,paddr); + //Console.WriteLn("Translated 0x%08X to 0x%08X",params addr,paddr); return reinterpret_cast::HandlerType*>(RWFT[TemplateHelper::sidx][0][hand])(paddr,data); } diff --git a/pcsx2/x86/microVU.cpp b/pcsx2/x86/microVU.cpp index 4cb1625ddf..8dc6fb0319 100644 --- a/pcsx2/x86/microVU.cpp +++ b/pcsx2/x86/microVU.cpp @@ -175,7 +175,7 @@ microVUf(int) mVUfindLeastUsedProg() { mVU->prog.prog[i].isOld = 0; mVU->prog.prog[i].used = 1; mVUsortProg(mVU, i); - Console::Notice("microVU%d: Cached MicroPrograms = [%03d] [%03d]", vuIndex, i+1, mVU->prog.total+1); + Console.Notice("microVU%d: Cached MicroPrograms = [%03d] [%03d]", vuIndex, i+1, mVU->prog.total+1); return i; } } @@ -192,7 +192,7 @@ microVUf(int) mVUfindLeastUsedProg() { mVU->prog.prog[pIdx].isOld = 0; mVU->prog.prog[pIdx].used = 1; mVUsortProg(mVU, pIdx); - Console::Notice("microVU%d: Cached MicroPrograms = [%03d] [%03d]", vuIndex, pIdx+1, mVU->prog.total+1); + Console.Notice("microVU%d: Cached MicroPrograms = [%03d] [%03d]", vuIndex, pIdx+1, mVU->prog.total+1); return pIdx; } @@ -208,11 +208,11 @@ microVUt(void) mVUvsyncUpdate(mV) { mVU->prog.total--; if (!mVU->index) mVUclearProg<0>(i); else mVUclearProg<1>(i); - DevCon::Status("microVU%d: Killing Dead Program [%03d]", mVU->index, i+1); + DevCon.Status("microVU%d: Killing Dead Program [%03d]", mVU->index, i+1); } else if (((mVU->prog.curFrame - mVU->prog.prog[i].frame) >= (30 * 1)) && !mVU->prog.prog[i].isOld) { mVU->prog.prog[i].isOld = 1; - //DevCon::Status("microVU%d: Aging Old Program [%03d]", mVU->index, i+1); + //DevCon.Status("microVU%d: Aging Old Program [%03d]", mVU->index, i+1); } } mVU->prog.curFrame++; @@ -222,7 +222,7 @@ microVUf(bool) mVUcmpPartial(int progIndex) { microVU* mVU = mVUx; for (int i = 0; i <= mVUprogI.ranges.total; i++) { if ((mVUprogI.ranges.range[i][0] < 0) - || (mVUprogI.ranges.range[i][1] < 0)) { DevCon::Error("microVU%d: Negative Range![%d][%d]", mVU->index, i, mVUprogI.ranges.total); } + || (mVUprogI.ranges.range[i][1] < 0)) { DevCon.Error("microVU%d: Negative Range![%d][%d]", mVU->index, i, mVUprogI.ranges.total); } if (memcmp_mmx(cmpOffset(mVUprogI.data), cmpOffset(mVU->regs->Micro), ((mVUprogI.ranges.range[i][1] + 8) - mVUprogI.ranges.range[i][0]))) { return 0; } diff --git a/pcsx2/x86/microVU.h b/pcsx2/x86/microVU.h index df2348cee0..1fcd4f4b97 100644 --- a/pcsx2/x86/microVU.h +++ b/pcsx2/x86/microVU.h @@ -97,7 +97,7 @@ public: if (listI < 7) return; microBlockLink* linkI = &blockList; for (int i = 0; i <= listI; i++) { - DevCon::Status("[%04x][Block #%d][q=%02d][p=%02d][xgkick=%d][vi15=%08x][viBackup=%02d][flags=%02x][exactMatch=%x]", + DevCon.Status("[%04x][Block #%d][q=%02d][p=%02d][xgkick=%d][vi15=%08x][viBackup=%02d][flags=%02x][exactMatch=%x]", pc, i, linkI->block->pState.q, linkI->block->pState.p, linkI->block->pState.xgkick, linkI->block->pState.vi15, linkI->block->pState.viBackUp, linkI->block->pState.flags, linkI->block->pState.needExactMatch); linkI = linkI->next; diff --git a/pcsx2/x86/microVU_Alloc.inl b/pcsx2/x86/microVU_Alloc.inl index db98a14b35..bcf65f2206 100644 --- a/pcsx2/x86/microVU_Alloc.inl +++ b/pcsx2/x86/microVU_Alloc.inl @@ -30,7 +30,7 @@ case 2: regX = gprF2; break; \ case 3: regX = gprF3; break; \ default: \ - Console::Error("microVU Error: fInst = %d", fInst); \ + Console.Error("microVU Error: fInst = %d", fInst); \ regX = gprF0; \ break; \ } \ diff --git a/pcsx2/x86/microVU_Analyze.inl b/pcsx2/x86/microVU_Analyze.inl index 0cee8206a0..30d3935b98 100644 --- a/pcsx2/x86/microVU_Analyze.inl +++ b/pcsx2/x86/microVU_Analyze.inl @@ -380,7 +380,7 @@ microVUt(void) analyzeBranchVI(mV, int xReg, bool &infoVar) { infoVar = 1; } iPC = bPC; - DevCon::Status("microVU%d: Branch VI-Delay (%d) [%04x]", getIndex, i, xPC); + DevCon.Status("microVU%d: Branch VI-Delay (%d) [%04x]", getIndex, i, xPC); } else iPC = bPC; } @@ -394,7 +394,7 @@ microVUt(int) mVUbranchCheck(mV) { incPC(2); mVUlow.evilBranch = 1; mVUregs.blockType = 2; - DevCon::Status("microVU%d Warning: Branch in Branch delay slot! [%04x]", mVU->index, xPC); + DevCon.Status("microVU%d Warning: Branch in Branch delay slot! [%04x]", mVU->index, xPC); return 1; } incPC(2); @@ -431,7 +431,7 @@ microVUt(void) mVUanalyzeJump(mV, int Is, int It, bool isJALR) { if (mVUconstReg[Is].isValid && !CHECK_VU_CONSTHACK) { mVUlow.constJump.isValid = 1; mVUlow.constJump.regValue = mVUconstReg[Is].regValue; - //DevCon::Status("microVU%d: Constant JR/JALR Address Optimization", mVU->index); + //DevCon.Status("microVU%d: Constant JR/JALR Address Optimization", mVU->index); } analyzeVIreg1(Is, mVUlow.VI_read[0]); if (isJALR) { diff --git a/pcsx2/x86/microVU_Compile.inl b/pcsx2/x86/microVU_Compile.inl index b13a9be26c..5e19caf816 100644 --- a/pcsx2/x86/microVU_Compile.inl +++ b/pcsx2/x86/microVU_Compile.inl @@ -65,7 +65,7 @@ microVUt(void) mVUsetupRange(mV, s32 pc, bool isStartPC) { mVUcurProg.ranges.total = 0; mVUrange[0] = 0; mVUrange[1] = mVU->microMemSize - 8; - DevCon::Status("microVU%d: Prog Range List Full", mVU->index); + DevCon.Status("microVU%d: Prog Range List Full", mVU->index); } } else { @@ -79,7 +79,7 @@ microVUt(void) mVUsetupRange(mV, s32 pc, bool isStartPC) { && (mVUcurProg.ranges.range[i][1] <= rEnd)){ mVUcurProg.ranges.range[i][1] = pc; mergedRange = 1; - //DevCon::Status("microVU%d: Prog Range Merging", mVU->index); + //DevCon.Status("microVU%d: Prog Range Merging", mVU->index); } } if (mergedRange) { @@ -89,7 +89,7 @@ microVUt(void) mVUsetupRange(mV, s32 pc, bool isStartPC) { } } else { - DevCon::Status("microVU%d: Prog Range Wrap [%04x] [%d]", mVU->index, mVUrange[0], mVUrange[1]); + DevCon.Status("microVU%d: Prog Range Wrap [%04x] [%d]", mVU->index, mVUrange[0], mVUrange[1]); mVUrange[1] = mVU->microMemSize - 8; if (mVUcurProg.ranges.total < mVUcurProg.ranges.max) { mVUcurProg.ranges.total++; @@ -100,16 +100,16 @@ microVUt(void) mVUsetupRange(mV, s32 pc, bool isStartPC) { mVUcurProg.ranges.total = 0; mVUrange[0] = 0; mVUrange[1] = mVU->microMemSize - 8; - DevCon::Status("microVU%d: Prog Range List Full", mVU->index); + DevCon.Status("microVU%d: Prog Range List Full", mVU->index); } } } } microVUt(void) startLoop(mV) { - if (curI & _Mbit_) { Console::Status("microVU%d: M-bit set!", getIndex); } - if (curI & _Dbit_) { DevCon::Status ("microVU%d: D-bit set!", getIndex); } - if (curI & _Tbit_) { DevCon::Status ("microVU%d: T-bit set!", getIndex); } + if (curI & _Mbit_) { Console.Status("microVU%d: M-bit set!", getIndex); } + if (curI & _Dbit_) { DevCon.Status ("microVU%d: D-bit set!", getIndex); } + if (curI & _Tbit_) { DevCon.Status ("microVU%d: T-bit set!", getIndex); } memset(&mVUinfo, 0, sizeof(mVUinfo)); memset(&mVUregsTemp, 0, sizeof(mVUregsTemp)); } @@ -121,7 +121,7 @@ microVUt(void) doIbit(mV) { mVU->regAlloc->clearRegVF(33); if (CHECK_VU_OVERFLOW && ((curI & 0x7fffffff) >= 0x7f800000)) { - Console::Status("microVU%d: Clamping I Reg", mVU->index); + Console.Status("microVU%d: Clamping I Reg", mVU->index); tempI = (0x80000000 & curI) | 0x7f7fffff; // Clamp I Reg } else tempI = curI; @@ -133,7 +133,7 @@ microVUt(void) doIbit(mV) { microVUt(void) doSwapOp(mV) { if (mVUinfo.backupVF && !mVUlow.noWriteVF) { - DevCon::Status("microVU%d: Backing Up VF Reg [%04x]", getIndex, xPC); + DevCon.Status("microVU%d: Backing Up VF Reg [%04x]", getIndex, xPC); int t1 = mVU->regAlloc->allocReg(mVUlow.VF_write.reg); int t2 = mVU->regAlloc->allocReg(); SSE_MOVAPS_XMM_to_XMM(t2, t1); @@ -158,7 +158,7 @@ microVUt(void) branchWarning(mV) { incPC(-2); if (mVUup.eBit && mVUbranch) { incPC(2); - Console::Error("microVU%d Warning: Branch in E-bit delay slot! [%04x]", mVU->index, xPC); + Console.Error("microVU%d Warning: Branch in E-bit delay slot! [%04x]", mVU->index, xPC); mVUlow.isNOP = 1; } else incPC(2); @@ -178,11 +178,11 @@ microVUt(void) eBitPass1(mV, int& branch) { } microVUt(void) eBitWarning(mV) { - if (mVUpBlock->pState.blockType == 1) Console::Error("microVU%d Warning: Branch, E-bit, Branch! [%04x]", mVU->index, xPC); - if (mVUpBlock->pState.blockType == 2) Console::Error("microVU%d Warning: Branch, Branch, Branch! [%04x]", mVU->index, xPC); + if (mVUpBlock->pState.blockType == 1) Console.Error("microVU%d Warning: Branch, E-bit, Branch! [%04x]", mVU->index, xPC); + if (mVUpBlock->pState.blockType == 2) Console.Error("microVU%d Warning: Branch, Branch, Branch! [%04x]", mVU->index, xPC); incPC(2); if (curI & _Ebit_) { - DevCon::Status("microVU%d: E-bit in Branch delay slot! [%04x]", mVU->index, xPC); + DevCon.Status("microVU%d: E-bit in Branch delay slot! [%04x]", mVU->index, xPC); mVUregs.blockType = 1; } incPC(-2); @@ -276,10 +276,10 @@ microVUt(void) mVUsetCycles(mV) { tCycles(mVUregs.xgkick, mVUregsTemp.xgkick); } -void __fastcall mVUwarning0(mV) { Console::Error("microVU0 Warning: Exiting from Possible Infinite Loop [%04x] [%x]", xPC, mVU->prog.cur); } -void __fastcall mVUwarning1(mV) { Console::Error("microVU1 Warning: Exiting from Possible Infinite Loop [%04x] [%x]", xPC, mVU->prog.cur); } -void __fastcall mVUprintPC1(u32 PC) { Console::Write("Block PC [%04x] ", PC); } -void __fastcall mVUprintPC2(u32 PC) { Console::Write("[%04x]\n", PC); } +void __fastcall mVUwarning0(mV) { Console.Error("microVU0 Warning: Exiting from Possible Infinite Loop [%04x] [%x]", xPC, mVU->prog.cur); } +void __fastcall mVUwarning1(mV) { Console.Error("microVU1 Warning: Exiting from Possible Infinite Loop [%04x] [%x]", xPC, mVU->prog.cur); } +void __fastcall mVUprintPC1(u32 PC) { Console.Write("Block PC [%04x] ", PC); } +void __fastcall mVUprintPC2(u32 PC) { Console.Write("[%04x]\n", PC); } microVUt(void) mVUtestCycles(mV) { u32* vu0jmp; @@ -403,7 +403,7 @@ microVUr(void*) mVUcompile(microVU* mVU, u32 startPC, uptr pState) { } } } - if ((x == endCount) && (x!=1)) { Console::Error("microVU%d: Possible infinite compiling loop!", mVU->index); } + if ((x == endCount) && (x!=1)) { Console.Error("microVU%d: Possible infinite compiling loop!", mVU->index); } // E-bit End mVUsetupRange(mVU, xPC-8, 0); @@ -415,7 +415,7 @@ microVUr(void*) mVUcompile(microVU* mVU, u32 startPC, uptr pState) { microVUt(void*) mVUblockFetch(microVU* mVU, u32 startPC, uptr pState) { using namespace x86Emitter; - if (startPC > mVU->microMemSize-8) { DevCon::Error("microVU%d: invalid startPC [%04x]", mVU->index, startPC); } + if (startPC > mVU->microMemSize-8) { DevCon.Error("microVU%d: invalid startPC [%04x]", mVU->index, startPC); } startPC &= mVU->microMemSize-8; blockCreate(startPC/8); diff --git a/pcsx2/x86/microVU_Flags.inl b/pcsx2/x86/microVU_Flags.inl index 097687ee71..e126bf6a80 100644 --- a/pcsx2/x86/microVU_Flags.inl +++ b/pcsx2/x86/microVU_Flags.inl @@ -50,7 +50,7 @@ microVUt(void) mVUstatusFlagOp(mV) { } } iPC = curPC; - DevCon::Status("microVU%d: FSSET Optimization", getIndex); + DevCon.Status("microVU%d: FSSET Optimization", getIndex); } int findFlagInst(int* fFlag, int cycles) { diff --git a/pcsx2/x86/microVU_IR.h b/pcsx2/x86/microVU_IR.h index abcb5d7cfc..8c999c64f6 100644 --- a/pcsx2/x86/microVU_IR.h +++ b/pcsx2/x86/microVU_IR.h @@ -203,7 +203,7 @@ private: } } int x = findFreeRegRec(0); - if (x < 0) { DevCon::Error("microVU Allocation Error!"); return 0; } + if (x < 0) { DevCon.Error("microVU Allocation Error!"); return 0; } return x; } @@ -244,7 +244,7 @@ public: for (int i = 0; i < xmmTotal; i++) { if ((i == reg) || xmmReg[i].isNeeded) continue; if (xmmReg[i].reg == xmmReg[reg].reg) { - if (xmmReg[i].xyzw && xmmReg[i].xyzw < 0xf) DevCon::Error("microVU Error: writeBackReg() [%d]", xmmReg[i].reg); + if (xmmReg[i].xyzw && xmmReg[i].xyzw < 0xf) DevCon.Error("microVU Error: writeBackReg() [%d]", xmmReg[i].reg); clearReg(i); // Invalidate any Cached Regs of same vf Reg } } @@ -268,7 +268,7 @@ public: for (int i = 0; i < xmmTotal; i++) { // Invalidate any other read-only regs of same vfReg if (i == reg) continue; if (xmmReg[i].reg == xmmReg[reg].reg) { - if (xmmReg[i].xyzw && xmmReg[i].xyzw < 0xf) DevCon::Error("microVU Error: clearNeeded() [%d]", xmmReg[i].reg); + if (xmmReg[i].xyzw && xmmReg[i].xyzw < 0xf) DevCon.Error("microVU Error: clearNeeded() [%d]", xmmReg[i].reg); if (mergeRegs == 1) { mVUmergeRegs(i, reg, xmmReg[reg].xyzw, 1); xmmReg[i].xyzw = 0xf; diff --git a/pcsx2/x86/microVU_Lower.inl b/pcsx2/x86/microVU_Lower.inl index 1399df9afa..beb4504479 100644 --- a/pcsx2/x86/microVU_Lower.inl +++ b/pcsx2/x86/microVU_Lower.inl @@ -1112,7 +1112,7 @@ void __fastcall mVU_XGKICK_(u32 addr) { if (size > diff) { // fixme: one of these days the following *16's will get cleaned up when we introduce // a special qwc/simd16 optimized version of memcpy_aligned. :) - //DevCon::Status("XGkick Wrap!"); + //DevCon.Status("XGkick Wrap!"); memcpy_aligned(pDest, microVU1.regs->Mem + (addr*16), diff*16); size -= diff; pDest += diff*16; diff --git a/pcsx2/x86/microVU_Macro.inl b/pcsx2/x86/microVU_Macro.inl index 38dcdf7e49..9f75089f49 100644 --- a/pcsx2/x86/microVU_Macro.inl +++ b/pcsx2/x86/microVU_Macro.inl @@ -29,7 +29,7 @@ extern void _vu0FinishMicro(); using namespace R5900::Dynarec; #define printCOP2 0&& -//#define printCOP2 DevCon::Status +//#define printCOP2 DevCon.Status void setupMacroOp(int mode, const char* opName) { printCOP2(opName); @@ -373,7 +373,7 @@ void recCOP2_BC2(); void recCOP2_SPEC1(); void recCOP2_SPEC2(); void rec_C2UNK() { - Console::Error("Cop2 bad opcode: %x", cpuRegs.code); + Console.Error("Cop2 bad opcode: %x", cpuRegs.code); } // This is called by EE Recs to setup sVU info, this isn't needed for mVU Macro (cottonvibes) diff --git a/pcsx2/x86/microVU_Misc.h b/pcsx2/x86/microVU_Misc.h index 7aa8bbf6bb..43e776e9cf 100644 --- a/pcsx2/x86/microVU_Misc.h +++ b/pcsx2/x86/microVU_Misc.h @@ -252,7 +252,7 @@ typedef u32 (__fastcall *mVUCall)(void*, void*); // Debug Stuff... #ifdef mVUdebug -#define mVUprint Console::Status +#define mVUprint Console.Status #else #define mVUprint 0&& #endif @@ -284,7 +284,7 @@ typedef u32 (__fastcall *mVUCall)(void*, void*); #define mVUcacheCheck(ptr, start, limit) { \ uptr diff = ptr - start; \ if (diff >= limit) { \ - Console::Status("microVU%d: Program cache limit reached. Size = 0x%x", mVU->index, diff); \ + Console.Status("microVU%d: Program cache limit reached. Size = 0x%x", mVU->index, diff); \ mVUreset(mVU); \ } \ } diff --git a/pcsx2/x86/microVU_Tables.inl b/pcsx2/x86/microVU_Tables.inl index 3c3de488ff..9f487dd854 100644 --- a/pcsx2/x86/microVU_Tables.inl +++ b/pcsx2/x86/microVU_Tables.inl @@ -211,7 +211,7 @@ mVUop(mVULowerOP_T3_11) { mVULowerOP_T3_11_OPCODE [((mVU->code >> 6) & 0x1f)](mX mVUop(mVUopU) { mVU_UPPER_OPCODE [ (mVU->code & 0x3f) ](mX); } // Gets Upper Opcode mVUop(mVUopL) { mVULOWER_OPCODE [ (mVU->code >> 25) ](mX); } // Gets Lower Opcode mVUop(mVUunknown) { - pass2 { Console::Error("microVU%d: Unknown Micro VU opcode called (%x) [%04x]\n", getIndex, mVU->code, xPC); } + pass2 { Console.Error("microVU%d: Unknown Micro VU opcode called (%x) [%04x]\n", getIndex, mVU->code, xPC); } pass3 { mVUlog("Unknown", mVU->code); } } diff --git a/pcsx2/x86/sVU_Lower.cpp b/pcsx2/x86/sVU_Lower.cpp index eab8c84a65..f4a567b14e 100644 --- a/pcsx2/x86/sVU_Lower.cpp +++ b/pcsx2/x86/sVU_Lower.cpp @@ -90,7 +90,7 @@ void recVUMI_DIV(VURegs *VU, int info) u8 *pjmp, *pjmp1; u32 *ajmp32, *bjmp32; - //Console::WriteLn("recVUMI_DIV()"); + //Console.WriteLn("recVUMI_DIV()"); AND32ItoM(VU_VI_ADDR(REG_STATUS_FLAG, 2), 0xFCF); // Clear D/I flags // FT can be zero here! so we need to check if its zero and set the correct flag. @@ -153,7 +153,7 @@ void recVUMI_DIV(VURegs *VU, int info) void recVUMI_SQRT( VURegs *VU, int info ) { u8* pjmp; - //Console::WriteLn("recVUMI_SQRT()"); + //Console.WriteLn("recVUMI_SQRT()"); _unpackVFSS_xyzw(EEREC_TEMP, EEREC_T, _Ftf_); AND32ItoM(VU_VI_ADDR(REG_STATUS_FLAG, 2), 0xFCF); // Clear D/I flags @@ -182,7 +182,7 @@ void recVUMI_RSQRT(VURegs *VU, int info) u8 *ajmp8, *bjmp8; u8 *qjmp1, *qjmp2; int t1reg, t1boolean; - //Console::WriteLn("recVUMI_RSQRT()"); + //Console.WriteLn("recVUMI_RSQRT()"); _unpackVFSS_xyzw(EEREC_TEMP, EEREC_T, _Ftf_); AND32ItoM(VU_VI_ADDR(REG_STATUS_FLAG, 2), 0xFCF); // Clear D/I flags @@ -291,7 +291,7 @@ void recVUMI_IADDI(VURegs *VU, int info) s16 imm; if ( _It_ == 0 ) return; - //Console::WriteLn("recVUMI_IADDI"); + //Console.WriteLn("recVUMI_IADDI"); imm = ( VU->code >> 6 ) & 0x1f; imm = ( imm & 0x10 ? 0xfff0 : 0) | ( imm & 0xf ); _addISIMMtoIT(VU, imm, info); @@ -307,7 +307,7 @@ void recVUMI_IADDIU(VURegs *VU, int info) s16 imm; if ( _It_ == 0 ) return; - //Console::WriteLn("recVUMI_IADDIU"); + //Console.WriteLn("recVUMI_IADDIU"); imm = ( ( VU->code >> 10 ) & 0x7800 ) | ( VU->code & 0x7ff ); _addISIMMtoIT(VU, imm, info); } @@ -321,7 +321,7 @@ void recVUMI_IADD( VURegs *VU, int info ) { int idreg, isreg = -1, itreg = -1; if ( _Id_ == 0 ) return; - //Console::WriteLn("recVUMI_IADD"); + //Console.WriteLn("recVUMI_IADD"); if ( ( _It_ == 0 ) && ( _Is_ == 0 ) ) { idreg = ALLOCVI(_Id_, MODE_WRITE); XOR32RtoR(idreg, idreg); @@ -367,7 +367,7 @@ void recVUMI_IAND( VURegs *VU, int info ) { int idreg, isreg = -1, itreg = -1; if ( _Id_ == 0 ) return; - //Console::WriteLn("recVUMI_IAND"); + //Console.WriteLn("recVUMI_IAND"); if ( ( _Is_ == 0 ) || ( _It_ == 0 ) ) { idreg = ALLOCVI(_Id_, MODE_WRITE); XOR32RtoR(idreg, idreg); @@ -398,7 +398,7 @@ void recVUMI_IOR( VURegs *VU, int info ) { int idreg, isreg = -1, itreg = -1; if ( _Id_ == 0 ) return; - //Console::WriteLn("recVUMI_IOR"); + //Console.WriteLn("recVUMI_IOR"); if ( ( _It_ == 0 ) && ( _Is_ == 0 ) ) { idreg = ALLOCVI(_Id_, MODE_WRITE); XOR32RtoR(idreg, idreg); @@ -446,7 +446,7 @@ void recVUMI_ISUB( VURegs *VU, int info ) { int idreg, isreg = -1, itreg = -1; if ( _Id_ == 0 ) return; - //Console::WriteLn("recVUMI_ISUB"); + //Console.WriteLn("recVUMI_ISUB"); if ( ( _It_ == 0 ) && ( _Is_ == 0 ) ) { idreg = ALLOCVI(_Id_, MODE_WRITE); XOR32RtoR(idreg, idreg); @@ -498,7 +498,7 @@ void recVUMI_ISUBIU( VURegs *VU, int info ) s16 imm; if ( _It_ == 0 ) return; - //Console::WriteLn("recVUMI_ISUBIU"); + //Console.WriteLn("recVUMI_ISUBIU"); imm = ( ( VU->code >> 10 ) & 0x7800 ) | ( VU->code & 0x7ff ); imm = -imm; _addISIMMtoIT(VU, imm, info); @@ -512,7 +512,7 @@ void recVUMI_ISUBIU( VURegs *VU, int info ) void recVUMI_MOVE( VURegs *VU, int info ) { if ( (_Ft_ == 0) || (_X_Y_Z_W == 0) ) return; - //Console::WriteLn("recVUMI_MOVE"); + //Console.WriteLn("recVUMI_MOVE"); if (_X_Y_Z_W == 0x8) SSE_MOVSS_XMM_to_XMM(EEREC_T, EEREC_S); else if (_X_Y_Z_W == 0xf) SSE_MOVAPS_XMM_to_XMM(EEREC_T, EEREC_S); else { @@ -529,7 +529,7 @@ void recVUMI_MOVE( VURegs *VU, int info ) void recVUMI_MFIR( VURegs *VU, int info ) { if ( (_Ft_ == 0) || (_X_Y_Z_W == 0) ) return; - //Console::WriteLn("recVUMI_MFIR"); + //Console.WriteLn("recVUMI_MFIR"); _deleteX86reg(X86TYPE_VI|((VU==&VU1)?X86TYPE_VU1:0), _Is_, 1); if( _XYZW_SS ) { @@ -560,7 +560,7 @@ void recVUMI_MFIR( VURegs *VU, int info ) void recVUMI_MTIR( VURegs *VU, int info ) { if ( _It_ == 0 ) return; - //Console::WriteLn("recVUMI_MTIR"); + //Console.WriteLn("recVUMI_MTIR"); _deleteX86reg(X86TYPE_VI|((VU==&VU1)?X86TYPE_VU1:0), _It_, 2); if( _Fsf_ == 0 ) { @@ -582,7 +582,7 @@ void recVUMI_MTIR( VURegs *VU, int info ) void recVUMI_MR32( VURegs *VU, int info ) { if ( (_Ft_ == 0) || (_X_Y_Z_W == 0) ) return; - //Console::WriteLn("recVUMI_MR32"); + //Console.WriteLn("recVUMI_MR32"); if (_X_Y_Z_W != 0xf) { SSE_MOVAPS_XMM_to_XMM(EEREC_TEMP, EEREC_S); SSE_SHUFPS_XMM_to_XMM(EEREC_TEMP, EEREC_TEMP, 0x39); @@ -720,7 +720,7 @@ void recVUMI_LQ(VURegs *VU, int info) { s16 imm; if ( _Ft_ == 0 ) return; - //Console::WriteLn("recVUMI_LQ"); + //Console.WriteLn("recVUMI_LQ"); imm = (VU->code & 0x400) ? (VU->code & 0x3ff) | 0xfc00 : (VU->code & 0x3ff); if (_Is_ == 0) { _loadEAX(VU, -1, (uptr)GET_VU_MEM(VU, (u32)imm*16), info); @@ -739,7 +739,7 @@ void recVUMI_LQ(VURegs *VU, int info) void recVUMI_LQD( VURegs *VU, int info ) { int isreg; - //Console::WriteLn("recVUMI_LQD"); + //Console.WriteLn("recVUMI_LQD"); if ( _Is_ != 0 ) { isreg = ALLOCVI(_Is_, MODE_READ|MODE_WRITE); SUB16ItoR( isreg, 1 ); @@ -759,7 +759,7 @@ void recVUMI_LQD( VURegs *VU, int info ) void recVUMI_LQI(VURegs *VU, int info) { int isreg; - //Console::WriteLn("recVUMI_LQI"); + //Console.WriteLn("recVUMI_LQI"); if ( _Ft_ == 0 ) { if( _Is_ != 0 ) { if( (isreg = _checkX86reg(X86TYPE_VI|(VU==&VU1?X86TYPE_VU1:0), _Is_, MODE_WRITE|MODE_READ)) >= 0 ) { @@ -945,7 +945,7 @@ void _saveEAX(VURegs *VU, int x86reg, uptr offset, int info) void recVUMI_SQ(VURegs *VU, int info) { s16 imm; - //Console::WriteLn("recVUMI_SQ"); + //Console.WriteLn("recVUMI_SQ"); imm = ( VU->code & 0x400) ? ( VU->code & 0x3ff) | 0xfc00 : ( VU->code & 0x3ff); if ( _It_ == 0 ) _saveEAX(VU, -1, (uptr)GET_VU_MEM(VU, (int)imm * 16), info); else { @@ -961,7 +961,7 @@ void recVUMI_SQ(VURegs *VU, int info) //------------------------------------------------------------------ void recVUMI_SQD(VURegs *VU, int info) { - //Console::WriteLn("recVUMI_SQD"); + //Console.WriteLn("recVUMI_SQD"); if (_It_ == 0) _saveEAX(VU, -1, (uptr)VU->Mem, info); else { int itreg = ALLOCVI(_It_, MODE_READ|MODE_WRITE); @@ -977,7 +977,7 @@ void recVUMI_SQD(VURegs *VU, int info) //------------------------------------------------------------------ void recVUMI_SQI(VURegs *VU, int info) { - //Console::WriteLn("recVUMI_SQI"); + //Console.WriteLn("recVUMI_SQI"); if (_It_ == 0) _saveEAX(VU, -1, (uptr)VU->Mem, info); else { int itreg = ALLOCVI(_It_, MODE_READ|MODE_WRITE); @@ -997,7 +997,7 @@ void recVUMI_ILW(VURegs *VU, int info) s16 imm, off; if ( ( _It_ == 0 ) || ( _X_Y_Z_W == 0 ) ) return; - //Console::WriteLn("recVUMI_ILW"); + //Console.WriteLn("recVUMI_ILW"); imm = ( VU->code & 0x400) ? ( VU->code & 0x3ff) | 0xfc00 : ( VU->code & 0x3ff); if (_X) off = 0; else if (_Y) off = 4; @@ -1024,7 +1024,7 @@ void recVUMI_ILW(VURegs *VU, int info) void recVUMI_ISW( VURegs *VU, int info ) { s16 imm; - //Console::WriteLn("recVUMI_ISW"); + //Console.WriteLn("recVUMI_ISW"); imm = ( VU->code & 0x400) ? ( VU->code & 0x3ff) | 0xfc00 : ( VU->code & 0x3ff); if (_Is_ == 0) { @@ -1062,7 +1062,7 @@ void recVUMI_ILWR( VURegs *VU, int info ) int off, itreg; if ( ( _It_ == 0 ) || ( _X_Y_Z_W == 0 ) ) return; - //Console::WriteLn("recVUMI_ILWR"); + //Console.WriteLn("recVUMI_ILWR"); if (_X) off = 0; else if (_Y) off = 4; else if (_Z) off = 8; @@ -1088,7 +1088,7 @@ void recVUMI_ILWR( VURegs *VU, int info ) void recVUMI_ISWR( VURegs *VU, int info ) { int itreg; - //Console::WriteLn("recVUMI_ISWR"); + //Console.WriteLn("recVUMI_ISWR"); ADD_VI_NEEDED(_Is_); itreg = ALLOCVI(_It_, MODE_READ); @@ -1117,7 +1117,7 @@ void recVUMI_ISWR( VURegs *VU, int info ) //------------------------------------------------------------------ void recVUMI_RINIT(VURegs *VU, int info) { - //Console::WriteLn("recVUMI_RINIT()"); + //Console.WriteLn("recVUMI_RINIT()"); if( (xmmregs[EEREC_S].mode & MODE_WRITE) && (xmmregs[EEREC_S].mode & MODE_NOFLUSH) ) { _deleteX86reg(X86TYPE_VI|(VU==&VU1?X86TYPE_VU1:0), REG_R, 2); _unpackVFSS_xyzw(EEREC_TEMP, EEREC_S, _Fsf_); @@ -1149,7 +1149,7 @@ void recVUMI_RINIT(VURegs *VU, int info) //------------------------------------------------------------------ void recVUMI_RGET(VURegs *VU, int info) { - //Console::WriteLn("recVUMI_RGET()"); + //Console.WriteLn("recVUMI_RGET()"); if ( (_Ft_ == 0) || (_X_Y_Z_W == 0) ) return; _deleteX86reg(X86TYPE_VI|(VU==&VU1?X86TYPE_VU1:0), REG_R, 1); @@ -1173,7 +1173,7 @@ void recVUMI_RGET(VURegs *VU, int info) void recVUMI_RNEXT( VURegs *VU, int info ) { int rreg, x86temp0, x86temp1; - //Console::WriteLn("recVUMI_RNEXT()"); + //Console.WriteLn("recVUMI_RNEXT()"); rreg = ALLOCVI(REG_R, MODE_WRITE|MODE_READ); @@ -1214,7 +1214,7 @@ void recVUMI_RNEXT( VURegs *VU, int info ) //------------------------------------------------------------------ void recVUMI_RXOR( VURegs *VU, int info ) { - //Console::WriteLn("recVUMI_RXOR()"); + //Console.WriteLn("recVUMI_RXOR()"); if( (xmmregs[EEREC_S].mode & MODE_WRITE) && (xmmregs[EEREC_S].mode & MODE_NOFLUSH) ) { _deleteX86reg(X86TYPE_VI|(VU==&VU1?X86TYPE_VU1:0), REG_R, 1); _unpackVFSS_xyzw(EEREC_TEMP, EEREC_S, _Fsf_); @@ -1247,7 +1247,7 @@ void recVUMI_RXOR( VURegs *VU, int info ) //------------------------------------------------------------------ void recVUMI_WAITQ( VURegs *VU, int info ) { - //Console::WriteLn("recVUMI_WAITQ"); + //Console.WriteLn("recVUMI_WAITQ"); // if( info & PROCESS_VU_SUPER ) { // //CALLFunc(waitqfn); // SuperVUFlush(0, 1); @@ -1263,7 +1263,7 @@ void recVUMI_FSAND( VURegs *VU, int info ) { int itreg; u16 imm; - //Console::WriteLn("recVUMI_FSAND"); + //Console.WriteLn("recVUMI_FSAND"); imm = (((VU->code >> 21 ) & 0x1) << 11) | (VU->code & 0x7ff); if(_It_ == 0) return; @@ -1282,7 +1282,7 @@ void recVUMI_FSEQ( VURegs *VU, int info ) int itreg; u16 imm; if ( _It_ == 0 ) return; - //Console::WriteLn("recVUMI_FSEQ"); + //Console.WriteLn("recVUMI_FSEQ"); imm = (((VU->code >> 21 ) & 0x1) << 11) | (VU->code & 0x7ff); itreg = ALLOCVI(_It_, MODE_WRITE|MODE_8BITREG); @@ -1303,7 +1303,7 @@ void recVUMI_FSOR( VURegs *VU, int info ) int itreg; u32 imm; if(_It_ == 0) return; - //Console::WriteLn("recVUMI_FSOR"); + //Console.WriteLn("recVUMI_FSOR"); imm = (((VU->code >> 21 ) & 0x1) << 11) | (VU->code & 0x7ff); itreg = ALLOCVI(_It_, MODE_WRITE); @@ -1323,7 +1323,7 @@ void recVUMI_FSSET(VURegs *VU, int info) u32 prevaddr = VU_VI_ADDR(REG_STATUS_FLAG, 2); u16 imm = 0; - //Console::WriteLn("recVUMI_FSSET"); + //Console.WriteLn("recVUMI_FSSET"); imm = (((VU->code >> 21 ) & 0x1) << 11) | (VU->code & 0x7FF); // keep the low 6 bits ONLY if the upper instruction is an fmac instruction (otherwise rewrite) - metal gear solid 3 @@ -1347,7 +1347,7 @@ void recVUMI_FMAND( VURegs *VU, int info ) { int isreg, itreg; if ( _It_ == 0 ) return; - //Console::WriteLn("recVUMI_FMAND"); + //Console.WriteLn("recVUMI_FMAND"); isreg = _checkX86reg(X86TYPE_VI|(VU==&VU1?X86TYPE_VU1:0), _Is_, MODE_READ); itreg = ALLOCVI(_It_, MODE_WRITE);//|MODE_8BITREG); @@ -1368,7 +1368,7 @@ void recVUMI_FMEQ( VURegs *VU, int info ) { int itreg, isreg; if ( _It_ == 0 ) return; - //Console::WriteLn("recVUMI_FMEQ"); + //Console.WriteLn("recVUMI_FMEQ"); if( _It_ == _Is_ ) { itreg = ALLOCVI(_It_, MODE_WRITE|MODE_READ);//|MODE_8BITREG @@ -1397,7 +1397,7 @@ void recVUMI_FMOR( VURegs *VU, int info ) { int isreg, itreg; if ( _It_ == 0 ) return; - //Console::WriteLn("recVUMI_FMOR"); + //Console.WriteLn("recVUMI_FMOR"); if( _Is_ == 0 ) { itreg = ALLOCVI(_It_, MODE_WRITE);//|MODE_8BITREG); MOVZX32M16toR( itreg, VU_VI_ADDR(REG_MAC_FLAG, 1) ); @@ -1427,7 +1427,7 @@ void recVUMI_FMOR( VURegs *VU, int info ) void recVUMI_FCAND( VURegs *VU, int info ) { int itreg = ALLOCVI(1, MODE_WRITE|MODE_8BITREG); - //Console::WriteLn("recVUMI_FCAND"); + //Console.WriteLn("recVUMI_FCAND"); MOV32MtoR( EAX, VU_VI_ADDR(REG_CLIP_FLAG, 1) ); XOR32RtoR( itreg, itreg ); AND32ItoR( EAX, VU->code & 0xFFFFFF ); @@ -1443,7 +1443,7 @@ void recVUMI_FCAND( VURegs *VU, int info ) void recVUMI_FCEQ( VURegs *VU, int info ) { int itreg = ALLOCVI(1, MODE_WRITE|MODE_8BITREG); - //Console::WriteLn("recVUMI_FCEQ"); + //Console.WriteLn("recVUMI_FCEQ"); MOV32MtoR( EAX, VU_VI_ADDR(REG_CLIP_FLAG, 1) ); AND32ItoR( EAX, 0xffffff ); XOR32RtoR( itreg, itreg ); @@ -1460,7 +1460,7 @@ void recVUMI_FCEQ( VURegs *VU, int info ) void recVUMI_FCOR( VURegs *VU, int info ) { int itreg; - //Console::WriteLn("recVUMI_FCOR"); + //Console.WriteLn("recVUMI_FCOR"); itreg = ALLOCVI(1, MODE_WRITE); MOV32MtoR( itreg, VU_VI_ADDR(REG_CLIP_FLAG, 1) ); OR32ItoR ( itreg, VU->code ); @@ -1477,7 +1477,7 @@ void recVUMI_FCOR( VURegs *VU, int info ) void recVUMI_FCSET( VURegs *VU, int info ) { u32 addr = VU_VI_ADDR(REG_CLIP_FLAG, 0); - //Console::WriteLn("recVUMI_FCSET"); + //Console.WriteLn("recVUMI_FCSET"); MOV32ItoM(addr ? addr : VU_VI_ADDR(REG_CLIP_FLAG, 2), VU->code&0xffffff ); if( !(info & (PROCESS_VU_SUPER|PROCESS_VU_COP2)) ) @@ -1493,7 +1493,7 @@ void recVUMI_FCGET( VURegs *VU, int info ) { int itreg; if(_It_ == 0) return; - //Console::WriteLn("recVUMI_FCGET"); + //Console.WriteLn("recVUMI_FCGET"); itreg = ALLOCVI(_It_, MODE_WRITE); MOV32MtoR(itreg, VU_VI_ADDR(REG_CLIP_FLAG, 1)); @@ -1515,7 +1515,7 @@ void recVUMI_FCGET( VURegs *VU, int info ) void recVUMI_MFP(VURegs *VU, int info) { if ( (_Ft_ == 0) || (_X_Y_Z_W == 0) ) return; - //Console::WriteLn("recVUMI_MFP"); + //Console.WriteLn("recVUMI_MFP"); if( _XYZW_SS ) { _vuFlipRegSS(VU, EEREC_T); SSE_MOVSS_M32_to_XMM(EEREC_TEMP, VU_VI_ADDR(REG_P, 1)); @@ -1541,7 +1541,7 @@ void recVUMI_MFP(VURegs *VU, int info) static PCSX2_ALIGNED16(float s_tempmem[4]); void recVUMI_WAITP(VURegs *VU, int info) { - //Console::WriteLn("recVUMI_WAITP"); + //Console.WriteLn("recVUMI_WAITP"); // if( info & PROCESS_VU_SUPER ) // SuperVUFlush(1, 1); } @@ -1555,7 +1555,7 @@ void recVUMI_WAITP(VURegs *VU, int info) //------------------------------------------------------------------ void vuSqSumXYZ(int regd, int regs, int regtemp) // regd.x = x ^ 2 + y ^ 2 + z ^ 2 { - //Console::WriteLn("VU: SUMXYZ"); + //Console.WriteLn("VU: SUMXYZ"); if( x86caps.hasStreamingSIMD4Extensions ) { SSE_MOVAPS_XMM_to_XMM(regd, regs); @@ -1590,10 +1590,10 @@ void vuSqSumXYZ(int regd, int regs, int regtemp) // regd.x = x ^ 2 + y ^ 2 + z //------------------------------------------------------------------ void recVUMI_ESADD( VURegs *VU, int info) { - //Console::WriteLn("VU: ESADD"); + //Console.WriteLn("VU: ESADD"); assert( VU == &VU1 ); if( EEREC_TEMP == EEREC_D ) { // special code to reset P ( FixMe: don't know if this is still needed! (cottonvibes) ) - Console::Notice("ESADD: Resetting P reg!!!\n"); + Console.Notice("ESADD: Resetting P reg!!!\n"); MOV32ItoM(VU_VI_ADDR(REG_P, 0), 0); return; } @@ -1609,7 +1609,7 @@ void recVUMI_ESADD( VURegs *VU, int info) //------------------------------------------------------------------ void recVUMI_ERSADD( VURegs *VU, int info ) { - //Console::WriteLn("VU: ERSADD"); + //Console.WriteLn("VU: ERSADD"); assert( VU == &VU1 ); vuSqSumXYZ(EEREC_D, EEREC_S, EEREC_TEMP); // don't use RCPSS (very bad precision) @@ -1626,7 +1626,7 @@ void recVUMI_ERSADD( VURegs *VU, int info ) //------------------------------------------------------------------ void recVUMI_ELENG( VURegs *VU, int info ) { - //Console::WriteLn("VU: ELENG"); + //Console.WriteLn("VU: ELENG"); assert( VU == &VU1 ); vuSqSumXYZ(EEREC_D, EEREC_S, EEREC_TEMP); if (CHECK_VU_OVERFLOW) SSE_MINSS_M32_to_XMM(EEREC_D, (uptr)g_maxvals); // Only need to do positive clamp since (x ^ 2 + y ^ 2 + z ^ 2) is positive @@ -1641,7 +1641,7 @@ void recVUMI_ELENG( VURegs *VU, int info ) //------------------------------------------------------------------ void recVUMI_ERLENG( VURegs *VU, int info ) { - //Console::WriteLn("VU: ERLENG"); + //Console.WriteLn("VU: ERLENG"); assert( VU == &VU1 ); vuSqSumXYZ(EEREC_D, EEREC_S, EEREC_TEMP); if (CHECK_VU_OVERFLOW) SSE_MINSS_M32_to_XMM(EEREC_D, (uptr)g_maxvals); // Only need to do positive clamp since (x ^ 2 + y ^ 2 + z ^ 2) is positive @@ -1660,7 +1660,7 @@ void recVUMI_ERLENG( VURegs *VU, int info ) void recVUMI_EATANxy( VURegs *VU, int info ) { assert( VU == &VU1 ); - //Console::WriteLn("recVUMI_EATANxy"); + //Console.WriteLn("recVUMI_EATANxy"); if( (xmmregs[EEREC_S].mode & MODE_WRITE) && (xmmregs[EEREC_S].mode&MODE_NOFLUSH) ) { SSE_MOVLPS_XMM_to_M64((uptr)s_tempmem, EEREC_S); FLD32((uptr)&s_tempmem[0]); @@ -1688,7 +1688,7 @@ void recVUMI_EATANxy( VURegs *VU, int info ) void recVUMI_EATANxz( VURegs *VU, int info ) { assert( VU == &VU1 ); - //Console::WriteLn("recVUMI_EATANxz"); + //Console.WriteLn("recVUMI_EATANxz"); if( (xmmregs[EEREC_S].mode & MODE_WRITE) && (xmmregs[EEREC_S].mode&MODE_NOFLUSH) ) { SSE_MOVLPS_XMM_to_M64((uptr)s_tempmem, EEREC_S); FLD32((uptr)&s_tempmem[0]); @@ -1714,7 +1714,7 @@ void recVUMI_EATANxz( VURegs *VU, int info ) //------------------------------------------------------------------ void recVUMI_ESUM( VURegs *VU, int info ) { - //Console::WriteLn("VU: ESUM"); + //Console.WriteLn("VU: ESUM"); assert( VU == &VU1 ); if( x86caps.hasStreamingSIMD3Extensions ) { @@ -1743,7 +1743,7 @@ void recVUMI_ESUM( VURegs *VU, int info ) void recVUMI_ERCPR( VURegs *VU, int info ) { assert( VU == &VU1 ); - //Console::WriteLn("VU1: ERCPR"); + //Console.WriteLn("VU1: ERCPR"); // don't use RCPSS (very bad precision) switch ( _Fsf_ ) { @@ -1788,7 +1788,7 @@ void recVUMI_ESQRT( VURegs *VU, int info ) { assert( VU == &VU1 ); - //Console::WriteLn("VU1: ESQRT"); + //Console.WriteLn("VU1: ESQRT"); _unpackVFSS_xyzw(EEREC_TEMP, EEREC_S, _Fsf_); SSE_ANDPS_M128_to_XMM(EEREC_TEMP, (uptr)const_clip); // abs(x) if (CHECK_VU_OVERFLOW) SSE_MINSS_M32_to_XMM(EEREC_TEMP, (uptr)g_maxvals); // Only need to do positive clamp @@ -1807,7 +1807,7 @@ void recVUMI_ERSQRT( VURegs *VU, int info ) int t1reg = _vuGetTempXMMreg(info); assert( VU == &VU1 ); - //Console::WriteLn("VU1: ERSQRT"); + //Console.WriteLn("VU1: ERSQRT"); _unpackVFSS_xyzw(EEREC_TEMP, EEREC_S, _Fsf_); SSE_ANDPS_M128_to_XMM(EEREC_TEMP, (uptr)const_clip); // abs(x) @@ -1841,7 +1841,7 @@ void recVUMI_ESIN( VURegs *VU, int info ) { assert( VU == &VU1 ); - //Console::WriteLn("recVUMI_ESIN"); + //Console.WriteLn("recVUMI_ESIN"); if( (xmmregs[EEREC_S].mode & MODE_WRITE) && (xmmregs[EEREC_S].mode&MODE_NOFLUSH) ) { switch(_Fsf_) { case 0: SSE_MOVSS_XMM_to_M32((uptr)s_tempmem, EEREC_S); @@ -1872,7 +1872,7 @@ void recVUMI_EATAN( VURegs *VU, int info ) { assert( VU == &VU1 ); - //Console::WriteLn("recVUMI_EATAN"); + //Console.WriteLn("recVUMI_EATAN"); if( (xmmregs[EEREC_S].mode & MODE_WRITE) && (xmmregs[EEREC_S].mode&MODE_NOFLUSH) ) { switch(_Fsf_) { case 0: SSE_MOVSS_XMM_to_M32((uptr)s_tempmem, EEREC_S); @@ -1902,7 +1902,7 @@ void recVUMI_EATAN( VURegs *VU, int info ) void recVUMI_EEXP( VURegs *VU, int info ) { assert( VU == &VU1 ); - //Console::WriteLn("recVUMI_EEXP"); + //Console.WriteLn("recVUMI_EEXP"); FLDL2E(); if( (xmmregs[EEREC_S].mode & MODE_WRITE) && (xmmregs[EEREC_S].mode&MODE_NOFLUSH) ) { @@ -1945,7 +1945,7 @@ void recVUMI_XITOP( VURegs *VU, int info ) { int itreg; if (_It_ == 0) return; - //Console::WriteLn("recVUMI_XITOP"); + //Console.WriteLn("recVUMI_XITOP"); itreg = ALLOCVI(_It_, MODE_WRITE); MOVZX32M16toR( itreg, (uptr)&VU->vifRegs->itop ); } @@ -1959,7 +1959,7 @@ void recVUMI_XTOP( VURegs *VU, int info ) { int itreg; if ( _It_ == 0 ) return; - //Console::WriteLn("recVUMI_XTOP"); + //Console.WriteLn("recVUMI_XTOP"); itreg = ALLOCVI(_It_, MODE_WRITE); MOVZX32M16toR( itreg, (uptr)&VU->vifRegs->top ); } @@ -1981,10 +1981,10 @@ void VU1XGKICK_MTGSTransfer(u32 *pMem, u32 addr) if((size << 4) > (0x4000-(addr&0x3fff))) { - //DevCon::Notice("addr + Size = 0x%x, transferring %x then doing %x", (addr&0x3fff) + (size << 4), (0x4000-(addr&0x3fff)) >> 4, size - ((0x4000-(addr&0x3fff)) >> 4)); + //DevCon.Notice("addr + Size = 0x%x, transferring %x then doing %x", (addr&0x3fff) + (size << 4), (0x4000-(addr&0x3fff)) >> 4, size - ((0x4000-(addr&0x3fff)) >> 4)); memcpy_aligned(pmem, (u8*)pMem+addr, 0x4000-(addr&0x3fff)); size -= (0x4000-(addr&0x3fff)) >> 4; - //DevCon::Notice("Size left %x", size); + //DevCon.Notice("Size left %x", size); pmem += 0x4000-(addr&0x3fff); memcpy_aligned(pmem, (u8*)pMem, size<<4); } diff --git a/pcsx2/x86/sVU_Micro.cpp b/pcsx2/x86/sVU_Micro.cpp index 9ff1ad0d23..0173bb61fe 100644 --- a/pcsx2/x86/sVU_Micro.cpp +++ b/pcsx2/x86/sVU_Micro.cpp @@ -162,13 +162,13 @@ void _recvuFDIVflush(VURegs * VU, bool intermediate) { if( intermediate ) { if ((vucycle - VU->fdiv.sCycle) > VU->fdiv.Cycle) { -// Console::WriteLn("flushing FDIV pipe"); +// Console.WriteLn("flushing FDIV pipe"); VU->fdiv.enable = 0; } } else { if ((vucycle - VU->fdiv.sCycle) >= VU->fdiv.Cycle) { -// Console::WriteLn("flushing FDIV pipe"); +// Console.WriteLn("flushing FDIV pipe"); VU->fdiv.enable = 0; } } @@ -179,13 +179,13 @@ void _recvuEFUflush(VURegs * VU, bool intermediate) { if( intermediate ) { if ((vucycle - VU->efu.sCycle) > VU->efu.Cycle) { -// Console::WriteLn("flushing FDIV pipe"); +// Console.WriteLn("flushing FDIV pipe"); VU->efu.enable = 0; } } else { if ((vucycle - VU->efu.sCycle) >= VU->efu.Cycle) { -// Console::WriteLn("flushing FDIV pipe"); +// Console.WriteLn("flushing FDIV pipe"); VU->efu.enable = 0; } } @@ -292,7 +292,7 @@ void _recvuFMACAdd(VURegs * VU, int reg, int xyzw) { break; } - if (i==8) Console::Error("*PCSX2*: error , out of fmacs"); + if (i==8) Console.Error("*PCSX2*: error , out of fmacs"); // VUM_LOG("adding FMAC pipe[%d]; reg %d", i, reg); VU->fmac[i].enable = 1; @@ -303,14 +303,14 @@ void _recvuFMACAdd(VURegs * VU, int reg, int xyzw) { } void _recvuFDIVAdd(VURegs * VU, int cycles) { -// Console::WriteLn("adding FDIV pipe"); +// Console.WriteLn("adding FDIV pipe"); VU->fdiv.enable = 1; VU->fdiv.sCycle = vucycle; VU->fdiv.Cycle = cycles; } void _recvuEFUAdd(VURegs * VU, int cycles) { -// Console::WriteLn("adding EFU pipe"); +// Console.WriteLn("adding EFU pipe"); VU->efu.enable = 1; VU->efu.sCycle = vucycle; VU->efu.Cycle = cycles; @@ -325,7 +325,7 @@ void _recvuIALUAdd(VURegs * VU, int reg, int cycles) { break; } - if (i==8) Console::Error("*PCSX2*: error , out of ialus"); + if (i==8) Console.Error("*PCSX2*: error , out of ialus"); VU->ialu[i].enable = 1; VU->ialu[i].sCycle = vucycle; @@ -389,7 +389,7 @@ void _recvuFlushFDIV(VURegs * VU) { if (VU->fdiv.enable == 0) return; cycle = VU->fdiv.Cycle + 1 - (vucycle - VU->fdiv.sCycle); //VU->fdiv.Cycle contains the latency minus 1 (6 or 12) -// Console::WriteLn("waiting FDIV pipe %d", cycle); +// Console.WriteLn("waiting FDIV pipe %d", cycle); VU->fdiv.enable = 0; vucycle+= cycle; } @@ -400,7 +400,7 @@ void _recvuFlushEFU(VURegs * VU) { if (VU->efu.enable == 0) return; cycle = VU->efu.Cycle - (vucycle - VU->efu.sCycle); -// Console::WriteLn("waiting FDIV pipe %d", cycle); +// Console.WriteLn("waiting FDIV pipe %d", cycle); VU->efu.enable = 0; vucycle+= cycle; } @@ -1725,9 +1725,9 @@ void testPrintOverflow() { tempRegX[2] &= 0xff800000; tempRegX[3] &= 0xff800000; if ( (tempRegX[0] == 0x7f800000) || (tempRegX[1] == 0x7f800000) || (tempRegX[2] == 0x7f800000) || (tempRegX[3] == 0x7f800000) ) - Console::Notice( "VU OVERFLOW!: Changing to +Fmax!!!!!!!!!!!!" ); + Console.Notice( "VU OVERFLOW!: Changing to +Fmax!!!!!!!!!!!!" ); if ( (tempRegX[0] == 0xff800000) || (tempRegX[1] == 0xff800000) || (tempRegX[2] == 0xff800000) || (tempRegX[3] == 0xff800000) ) - Console::Notice( "VU OVERFLOW!: Changing to -Fmax!!!!!!!!!!!!" ); + Console.Notice( "VU OVERFLOW!: Changing to -Fmax!!!!!!!!!!!!" ); } // Outputs to the console when overflow has occured. diff --git a/pcsx2/x86/sVU_Upper.cpp b/pcsx2/x86/sVU_Upper.cpp index bce564d7dc..d11f9e2618 100644 --- a/pcsx2/x86/sVU_Upper.cpp +++ b/pcsx2/x86/sVU_Upper.cpp @@ -153,7 +153,7 @@ void recUpdateFlags(VURegs * VU, int reg, int info) return; } - //Console::WriteLn ("recUpdateFlags"); + //Console.WriteLn ("recUpdateFlags"); macaddr = VU_VI_ADDR(REG_MAC_FLAG, 0); stataddr = VU_VI_ADDR(REG_STATUS_FLAG, 0); // write address @@ -161,7 +161,7 @@ void recUpdateFlags(VURegs * VU, int reg, int info) if( stataddr == 0 ) stataddr = prevstataddr; if( macaddr == 0 ) { - Console::WriteLn( "VU ALLOCATION WARNING: Using Mac Flag Previous Address!" ); + Console.WriteLn( "VU ALLOCATION WARNING: Using Mac Flag Previous Address!" ); macaddr = VU_VI_ADDR(REG_MAC_FLAG, 2); } @@ -171,7 +171,7 @@ void recUpdateFlags(VURegs * VU, int reg, int info) if (reg == EEREC_TEMP) { t1reg = _vuGetTempXMMreg(info); if (t1reg < 0) { - //Console::WriteLn( "VU ALLOCATION ERROR: Temp reg can't be allocated!!!!" ); + //Console.WriteLn( "VU ALLOCATION ERROR: Temp reg can't be allocated!!!!" ); t1reg = (reg == 0) ? 1 : 0; // Make t1reg != reg SSE_MOVAPS_XMM_to_M128( (uptr)TEMPXMMData, t1reg ); // Backup data to temp address t1regBoolean = 1; @@ -609,7 +609,7 @@ void SSE_SUBSS_M32_to_XMM_custom(int info, int regd, int regt) { //------------------------------------------------------------------ void recVUMI_ABS(VURegs *VU, int info) { - //Console::WriteLn("recVUMI_ABS()"); + //Console.WriteLn("recVUMI_ABS()"); if ( (_Ft_ == 0) || (_X_Y_Z_W == 0) ) return; if ((_X_Y_Z_W == 0x8) || (_X_Y_Z_W == 0xf)) { @@ -631,7 +631,7 @@ void recVUMI_ABS(VURegs *VU, int info) PCSX2_ALIGNED16(float s_two[4]) = {0,0,0,2}; void recVUMI_ADD(VURegs *VU, int info) { - //Console::WriteLn("recVUMI_ADD()"); + //Console.WriteLn("recVUMI_ADD()"); if ( _X_Y_Z_W == 0 ) goto flagUpdate; // Don't do anything and just clear flags if ( !_Fd_ ) info = (info & ~PROCESS_EE_SET_D(0xf)) | PROCESS_EE_SET_D(EEREC_TEMP); @@ -675,7 +675,7 @@ flagUpdate: void recVUMI_ADD_iq(VURegs *VU, uptr addr, int info) { - //Console::WriteLn("recVUMI_ADD_iq()"); + //Console.WriteLn("recVUMI_ADD_iq()"); if ( _X_Y_Z_W == 0 ) goto flagUpdate; if ( !_Fd_ ) info = (info & ~PROCESS_EE_SET_D(0xf)) | PROCESS_EE_SET_D(EEREC_TEMP); if (CHECK_VU_EXTRA_OVERFLOW) { @@ -735,7 +735,7 @@ flagUpdate: void recVUMI_ADD_xyzw(VURegs *VU, int xyzw, int info) { - //Console::WriteLn("recVUMI_ADD_xyzw()"); + //Console.WriteLn("recVUMI_ADD_xyzw()"); if ( _X_Y_Z_W == 0 ) goto flagUpdate; if ( !_Fd_ ) info = (info & ~PROCESS_EE_SET_D(0xf)) | PROCESS_EE_SET_D(EEREC_TEMP); if (CHECK_VU_EXTRA_OVERFLOW) { @@ -799,7 +799,7 @@ void recVUMI_ADDw(VURegs *VU, int info) { recVUMI_ADD_xyzw(VU, 3, info); } //------------------------------------------------------------------ void recVUMI_ADDA(VURegs *VU, int info) { - //Console::WriteLn("recVUMI_ADDA()"); + //Console.WriteLn("recVUMI_ADDA()"); if ( _X_Y_Z_W == 0 ) goto flagUpdate; if (CHECK_VU_EXTRA_OVERFLOW) { if (_Fs_) vuFloat5_useEAX( EEREC_S, EEREC_TEMP, _X_Y_Z_W ); @@ -834,7 +834,7 @@ flagUpdate: void recVUMI_ADDA_iq(VURegs *VU, uptr addr, int info) { - //Console::WriteLn("recVUMI_ADDA_iq()"); + //Console.WriteLn("recVUMI_ADDA_iq()"); if ( _X_Y_Z_W == 0 ) goto flagUpdate; if (CHECK_VU_EXTRA_OVERFLOW) { vuFloat3(addr); @@ -886,7 +886,7 @@ flagUpdate: void recVUMI_ADDA_xyzw(VURegs *VU, int xyzw, int info) { - //Console::WriteLn("recVUMI_ADDA_xyzw()"); + //Console.WriteLn("recVUMI_ADDA_xyzw()"); if ( _X_Y_Z_W == 0 ) goto flagUpdate; if (CHECK_VU_EXTRA_OVERFLOW) { if (_Fs_) vuFloat5_useEAX( EEREC_S, EEREC_TEMP, _X_Y_Z_W ); @@ -944,7 +944,7 @@ void recVUMI_ADDAw(VURegs *VU, int info) { recVUMI_ADDA_xyzw(VU, 3, info); } //------------------------------------------------------------------ void recVUMI_SUB(VURegs *VU, int info) { - //Console::WriteLn("recVUMI_SUB()"); + //Console.WriteLn("recVUMI_SUB()"); if ( _X_Y_Z_W == 0 ) goto flagUpdate; if ( !_Fd_ ) info = (info & ~PROCESS_EE_SET_D(0xf)) | PROCESS_EE_SET_D(EEREC_TEMP); @@ -1003,7 +1003,7 @@ flagUpdate: void recVUMI_SUB_iq(VURegs *VU, uptr addr, int info) { - //Console::WriteLn("recVUMI_SUB_iq()"); + //Console.WriteLn("recVUMI_SUB_iq()"); if ( _X_Y_Z_W == 0 ) goto flagUpdate; if (CHECK_VU_EXTRA_OVERFLOW) { vuFloat3(addr); @@ -1076,7 +1076,7 @@ flagUpdate: void recVUMI_SUB_xyzw(VURegs *VU, int xyzw, int info) { - //Console::WriteLn("recVUMI_SUB_xyzw()"); + //Console.WriteLn("recVUMI_SUB_xyzw()"); if ( _X_Y_Z_W == 0 ) goto flagUpdate; if ( !_Fd_ ) info = (info & ~PROCESS_EE_SET_D(0xf)) | PROCESS_EE_SET_D(EEREC_TEMP); if (CHECK_VU_EXTRA_OVERFLOW) { @@ -1154,7 +1154,7 @@ void recVUMI_SUBw(VURegs *VU, int info) { recVUMI_SUB_xyzw(VU, 3, info); } //------------------------------------------------------------------ void recVUMI_SUBA(VURegs *VU, int info) { - //Console::WriteLn("recVUMI_SUBA()"); + //Console.WriteLn("recVUMI_SUBA()"); if ( _X_Y_Z_W == 0 ) goto flagUpdate; if (CHECK_VU_EXTRA_OVERFLOW) { if (_Fs_) vuFloat5_useEAX( EEREC_S, EEREC_TEMP, _X_Y_Z_W ); @@ -1201,7 +1201,7 @@ flagUpdate: void recVUMI_SUBA_iq(VURegs *VU, uptr addr, int info) { - //Console::WriteLn ("recVUMI_SUBA_iq"); + //Console.WriteLn ("recVUMI_SUBA_iq"); if (CHECK_VU_EXTRA_OVERFLOW) { vuFloat3(addr); if (_Fs_) vuFloat5_useEAX( EEREC_S, EEREC_TEMP, _X_Y_Z_W ); @@ -1258,7 +1258,7 @@ void recVUMI_SUBA_iq(VURegs *VU, uptr addr, int info) void recVUMI_SUBA_xyzw(VURegs *VU, int xyzw, int info) { - //Console::WriteLn ("recVUMI_SUBA_xyzw"); + //Console.WriteLn ("recVUMI_SUBA_xyzw"); if (CHECK_VU_EXTRA_OVERFLOW) { if (_Fs_) vuFloat5_useEAX( EEREC_S, EEREC_TEMP, _X_Y_Z_W ); if (_Ft_) vuFloat5_useEAX( EEREC_T, EEREC_TEMP, ( 1 << (3 - xyzw) ) ); @@ -1317,7 +1317,7 @@ void recVUMI_SUBAw(VURegs *VU, int info) { recVUMI_SUBA_xyzw(VU, 3, info); } //------------------------------------------------------------------ void recVUMI_MUL_toD(VURegs *VU, int regd, int info) { - //Console::WriteLn ("recVUMI_MUL_toD"); + //Console.WriteLn ("recVUMI_MUL_toD"); if (CHECK_VU_EXTRA_OVERFLOW) { if (_Fs_) vuFloat5_useEAX( EEREC_S, EEREC_TEMP, _X_Y_Z_W ); if (_Ft_) vuFloat5_useEAX( EEREC_T, EEREC_TEMP, _X_Y_Z_W ); @@ -1358,7 +1358,7 @@ void recVUMI_MUL_toD(VURegs *VU, int regd, int info) void recVUMI_MUL_iq_toD(VURegs *VU, uptr addr, int regd, int info) { - //Console::WriteLn ("recVUMI_MUL_iq_toD"); + //Console.WriteLn ("recVUMI_MUL_iq_toD"); if (CHECK_VU_EXTRA_OVERFLOW) { vuFloat3(addr); if (_Fs_) vuFloat5_useEAX( EEREC_S, EEREC_TEMP, _X_Y_Z_W ); @@ -1414,7 +1414,7 @@ void recVUMI_MUL_iq_toD(VURegs *VU, uptr addr, int regd, int info) void recVUMI_MUL_xyzw_toD(VURegs *VU, int xyzw, int regd, int info) { - //Console::WriteLn ("recVUMI_MUL_xyzw_toD"); + //Console.WriteLn ("recVUMI_MUL_xyzw_toD"); if (CHECK_VU_EXTRA_OVERFLOW) { if (_Ft_) vuFloat5_useEAX( EEREC_T, EEREC_TEMP, ( 1 << (3 - xyzw) ) ); } @@ -1482,7 +1482,7 @@ void recVUMI_MUL_xyzw_toD(VURegs *VU, int xyzw, int regd, int info) void recVUMI_MUL(VURegs *VU, int info) { - //Console::WriteLn ("recVUMI_MUL"); + //Console.WriteLn ("recVUMI_MUL"); if( !_Fd_ ) info |= PROCESS_EE_SET_D(EEREC_TEMP); recVUMI_MUL_toD(VU, EEREC_D, info); recUpdateFlags(VU, EEREC_D, info); @@ -1490,7 +1490,7 @@ void recVUMI_MUL(VURegs *VU, int info) void recVUMI_MUL_iq(VURegs *VU, int addr, int info) { - //Console::WriteLn ("recVUMI_MUL_iq"); + //Console.WriteLn ("recVUMI_MUL_iq"); if( !_Fd_ ) info |= PROCESS_EE_SET_D(EEREC_TEMP); recVUMI_MUL_iq_toD(VU, addr, EEREC_D, info); recUpdateFlags(VU, EEREC_D, info); @@ -1499,7 +1499,7 @@ void recVUMI_MUL_iq(VURegs *VU, int addr, int info) void recVUMI_MUL_xyzw(VURegs *VU, int xyzw, int info) { - //Console::WriteLn ("recVUMI_MUL_xyzw"); + //Console.WriteLn ("recVUMI_MUL_xyzw"); if( !_Fd_ ) info |= PROCESS_EE_SET_D(EEREC_TEMP); recVUMI_MUL_xyzw_toD(VU, xyzw, EEREC_D, info); recUpdateFlags(VU, EEREC_D, info); @@ -1519,21 +1519,21 @@ void recVUMI_MULw(VURegs *VU, int info) { recVUMI_MUL_xyzw(VU, 3, info); } //------------------------------------------------------------------ void recVUMI_MULA( VURegs *VU, int info ) { - //Console::WriteLn ("recVUMI_MULA"); + //Console.WriteLn ("recVUMI_MULA"); recVUMI_MUL_toD(VU, EEREC_ACC, info); recUpdateFlags(VU, EEREC_ACC, info); } void recVUMI_MULA_iq(VURegs *VU, int addr, int info) { - //Console::WriteLn ("recVUMI_MULA_iq"); + //Console.WriteLn ("recVUMI_MULA_iq"); recVUMI_MUL_iq_toD(VU, addr, EEREC_ACC, info); recUpdateFlags(VU, EEREC_ACC, info); } void recVUMI_MULA_xyzw(VURegs *VU, int xyzw, int info) { - //Console::WriteLn ("recVUMI_MULA_xyzw"); + //Console.WriteLn ("recVUMI_MULA_xyzw"); recVUMI_MUL_xyzw_toD(VU, xyzw, EEREC_ACC, info); recUpdateFlags(VU, EEREC_ACC, info); } @@ -1552,7 +1552,7 @@ void recVUMI_MULAw(VURegs *VU, int info) { recVUMI_MULA_xyzw(VU, 3, info); } //------------------------------------------------------------------ void recVUMI_MADD_toD(VURegs *VU, int regd, int info) { - //Console::WriteLn ("recVUMI_MADD_toD"); + //Console.WriteLn ("recVUMI_MADD_toD"); if (CHECK_VU_EXTRA_OVERFLOW) { if (_Fs_) vuFloat5_useEAX( EEREC_S, EEREC_TEMP, _X_Y_Z_W ); if (_Ft_) vuFloat5_useEAX( EEREC_T, EEREC_TEMP, _X_Y_Z_W ); @@ -1620,7 +1620,7 @@ void recVUMI_MADD_toD(VURegs *VU, int regd, int info) void recVUMI_MADD_iq_toD(VURegs *VU, uptr addr, int regd, int info) { - //Console::WriteLn ("recVUMI_MADD_iq_toD"); + //Console.WriteLn ("recVUMI_MADD_iq_toD"); if (CHECK_VU_EXTRA_OVERFLOW) { vuFloat3(addr); if (_Fs_) vuFloat5_useEAX( EEREC_S, EEREC_TEMP, _X_Y_Z_W ); @@ -1718,7 +1718,7 @@ void recVUMI_MADD_iq_toD(VURegs *VU, uptr addr, int regd, int info) void recVUMI_MADD_xyzw_toD(VURegs *VU, int xyzw, int regd, int info) { - //Console::WriteLn ("recVUMI_MADD_xyzw_toD"); + //Console.WriteLn ("recVUMI_MADD_xyzw_toD"); if (CHECK_VU_EXTRA_OVERFLOW) { if (_Ft_) vuFloat5_useEAX( EEREC_T, EEREC_TEMP, ( 1 << (3 - xyzw) ) ); vuFloat5_useEAX( EEREC_ACC, EEREC_TEMP, _X_Y_Z_W ); @@ -1831,7 +1831,7 @@ void recVUMI_MADD_xyzw_toD(VURegs *VU, int xyzw, int regd, int info) void recVUMI_MADD(VURegs *VU, int info) { - //Console::WriteLn ("recVUMI_MADD"); + //Console.WriteLn ("recVUMI_MADD"); if( !_Fd_ ) info |= PROCESS_EE_SET_D(EEREC_TEMP); recVUMI_MADD_toD(VU, EEREC_D, info); recUpdateFlags(VU, EEREC_D, info); @@ -1839,7 +1839,7 @@ void recVUMI_MADD(VURegs *VU, int info) void recVUMI_MADD_iq(VURegs *VU, int addr, int info) { - //Console::WriteLn ("recVUMI_MADD_iq"); + //Console.WriteLn ("recVUMI_MADD_iq"); if( !_Fd_ ) info |= PROCESS_EE_SET_D(EEREC_TEMP); recVUMI_MADD_iq_toD(VU, addr, EEREC_D, info); recUpdateFlags(VU, EEREC_D, info); @@ -1847,7 +1847,7 @@ void recVUMI_MADD_iq(VURegs *VU, int addr, int info) void recVUMI_MADD_xyzw(VURegs *VU, int xyzw, int info) { - //Console::WriteLn ("recVUMI_MADD_xyzw"); + //Console.WriteLn ("recVUMI_MADD_xyzw"); if( !_Fd_ ) info |= PROCESS_EE_SET_D(EEREC_TEMP); recVUMI_MADD_xyzw_toD(VU, xyzw, EEREC_D, info); recUpdateFlags(VU, EEREC_D, info); @@ -1868,49 +1868,49 @@ void recVUMI_MADDw(VURegs *VU, int info) { recVUMI_MADD_xyzw(VU, 3, info); } //------------------------------------------------------------------ void recVUMI_MADDA( VURegs *VU, int info ) { - //Console::WriteLn ("recVUMI_MADDA"); + //Console.WriteLn ("recVUMI_MADDA"); recVUMI_MADD_toD(VU, EEREC_ACC, info); recUpdateFlags(VU, EEREC_ACC, info); } void recVUMI_MADDAi( VURegs *VU , int info) { - //Console::WriteLn ("recVUMI_MADDAi"); + //Console.WriteLn ("recVUMI_MADDAi"); recVUMI_MADD_iq_toD( VU, VU_VI_ADDR(REG_I, 1), EEREC_ACC, info); recUpdateFlags(VU, EEREC_ACC, info); } void recVUMI_MADDAq( VURegs *VU , int info) { - //Console::WriteLn ("recVUMI_MADDAq "); + //Console.WriteLn ("recVUMI_MADDAq "); recVUMI_MADD_iq_toD( VU, VU_REGQ_ADDR, EEREC_ACC, info); recUpdateFlags(VU, EEREC_ACC, info); } void recVUMI_MADDAx( VURegs *VU , int info) { - //Console::WriteLn ("recVUMI_MADDAx"); + //Console.WriteLn ("recVUMI_MADDAx"); recVUMI_MADD_xyzw_toD(VU, 0, EEREC_ACC, info); recUpdateFlags(VU, EEREC_ACC, info); } void recVUMI_MADDAy( VURegs *VU , int info) { - //Console::WriteLn ("recVUMI_MADDAy"); + //Console.WriteLn ("recVUMI_MADDAy"); recVUMI_MADD_xyzw_toD(VU, 1, EEREC_ACC, info); recUpdateFlags(VU, EEREC_ACC, info); } void recVUMI_MADDAz( VURegs *VU , int info) { - //Console::WriteLn ("recVUMI_MADDAz"); + //Console.WriteLn ("recVUMI_MADDAz"); recVUMI_MADD_xyzw_toD(VU, 2, EEREC_ACC, info); recUpdateFlags(VU, EEREC_ACC, info); } void recVUMI_MADDAw( VURegs *VU , int info) { - //Console::WriteLn ("recVUMI_MADDAw"); + //Console.WriteLn ("recVUMI_MADDAw"); recVUMI_MADD_xyzw_toD(VU, 3, EEREC_ACC, info); recUpdateFlags(VU, EEREC_ACC, info); } @@ -1922,7 +1922,7 @@ void recVUMI_MADDAw( VURegs *VU , int info) //------------------------------------------------------------------ void recVUMI_MSUB_toD(VURegs *VU, int regd, int info) { - //Console::WriteLn ("recVUMI_MSUB_toD"); + //Console.WriteLn ("recVUMI_MSUB_toD"); if (CHECK_VU_EXTRA_OVERFLOW) { if (_Fs_) vuFloat5_useEAX( EEREC_S, EEREC_TEMP, _X_Y_Z_W ); if (_Ft_) vuFloat5_useEAX( EEREC_T, EEREC_TEMP, _X_Y_Z_W ); @@ -1983,7 +1983,7 @@ void recVUMI_MSUB_toD(VURegs *VU, int regd, int info) void recVUMI_MSUB_temp_toD(VURegs *VU, int regd, int info) { - //Console::WriteLn ("recVUMI_MSUB_temp_toD"); + //Console.WriteLn ("recVUMI_MSUB_temp_toD"); if (_X_Y_Z_W != 0xf) { int t1reg = _vuGetTempXMMreg(info); @@ -2035,7 +2035,7 @@ void recVUMI_MSUB_temp_toD(VURegs *VU, int regd, int info) void recVUMI_MSUB_iq_toD(VURegs *VU, int regd, int addr, int info) { - //Console::WriteLn ("recVUMI_MSUB_iq_toD"); + //Console.WriteLn ("recVUMI_MSUB_iq_toD"); if (CHECK_VU_EXTRA_OVERFLOW) { if (_Fs_) vuFloat5_useEAX( EEREC_S, EEREC_TEMP, _X_Y_Z_W ); vuFloat5_useEAX( EEREC_ACC, EEREC_TEMP, _X_Y_Z_W ); @@ -2048,7 +2048,7 @@ void recVUMI_MSUB_iq_toD(VURegs *VU, int regd, int addr, int info) void recVUMI_MSUB_xyzw_toD(VURegs *VU, int regd, int xyzw, int info) { - //Console::WriteLn ("recVUMI_MSUB_xyzw_toD"); + //Console.WriteLn ("recVUMI_MSUB_xyzw_toD"); if (CHECK_VU_EXTRA_OVERFLOW) { if (_Fs_) vuFloat5_useEAX( EEREC_S, EEREC_TEMP, _X_Y_Z_W ); if (_Ft_) vuFloat5_useEAX( EEREC_T, EEREC_TEMP, 1 << (3 - xyzw)); @@ -2060,7 +2060,7 @@ void recVUMI_MSUB_xyzw_toD(VURegs *VU, int regd, int xyzw, int info) void recVUMI_MSUB(VURegs *VU, int info) { - //Console::WriteLn ("recVUMI_MSUB"); + //Console.WriteLn ("recVUMI_MSUB"); if( !_Fd_ ) info |= PROCESS_EE_SET_D(EEREC_TEMP); recVUMI_MSUB_toD(VU, EEREC_D, info); recUpdateFlags(VU, EEREC_D, info); @@ -2068,7 +2068,7 @@ void recVUMI_MSUB(VURegs *VU, int info) void recVUMI_MSUB_iq(VURegs *VU, int addr, int info) { - //Console::WriteLn ("recVUMI_MSUB_iq"); + //Console.WriteLn ("recVUMI_MSUB_iq"); if( !_Fd_ ) info |= PROCESS_EE_SET_D(EEREC_TEMP); recVUMI_MSUB_iq_toD(VU, EEREC_D, addr, info); recUpdateFlags(VU, EEREC_D, info); @@ -2078,7 +2078,7 @@ void recVUMI_MSUBi(VURegs *VU, int info) { recVUMI_MSUB_iq(VU, VU_VI_ADDR(REG_I, void recVUMI_MSUBq(VURegs *VU, int info) { recVUMI_MSUB_iq(VU, VU_REGQ_ADDR, info); } void recVUMI_MSUBx(VURegs *VU, int info) { - //Console::WriteLn ("recVUMI_MSUBx"); + //Console.WriteLn ("recVUMI_MSUBx"); if( !_Fd_ ) info |= PROCESS_EE_SET_D(EEREC_TEMP); recVUMI_MSUB_xyzw_toD(VU, EEREC_D, 0, info); recUpdateFlags(VU, EEREC_D, info); @@ -2086,7 +2086,7 @@ void recVUMI_MSUBx(VURegs *VU, int info) void recVUMI_MSUBy(VURegs *VU, int info) { - //Console::WriteLn ("recVUMI_MSUBy"); + //Console.WriteLn ("recVUMI_MSUBy"); if( !_Fd_ ) info |= PROCESS_EE_SET_D(EEREC_TEMP); recVUMI_MSUB_xyzw_toD(VU, EEREC_D, 1, info); recUpdateFlags(VU, EEREC_D, info); @@ -2094,7 +2094,7 @@ void recVUMI_MSUBy(VURegs *VU, int info) void recVUMI_MSUBz(VURegs *VU, int info) { - //Console::WriteLn ("recVUMI_MSUBz"); + //Console.WriteLn ("recVUMI_MSUBz"); if( !_Fd_ ) info |= PROCESS_EE_SET_D(EEREC_TEMP); recVUMI_MSUB_xyzw_toD(VU, EEREC_D, 2, info); recUpdateFlags(VU, EEREC_D, info); @@ -2102,7 +2102,7 @@ void recVUMI_MSUBz(VURegs *VU, int info) void recVUMI_MSUBw(VURegs *VU, int info) { - //Console::WriteLn ("recVUMI_MSUBw"); + //Console.WriteLn ("recVUMI_MSUBw"); if( !_Fd_ ) info |= PROCESS_EE_SET_D(EEREC_TEMP); recVUMI_MSUB_xyzw_toD(VU, EEREC_D, 3, info); recUpdateFlags(VU, EEREC_D, info); @@ -2115,49 +2115,49 @@ void recVUMI_MSUBw(VURegs *VU, int info) //------------------------------------------------------------------ void recVUMI_MSUBA( VURegs *VU, int info ) { - //Console::WriteLn ("recVUMI_MSUBA"); + //Console.WriteLn ("recVUMI_MSUBA"); recVUMI_MSUB_toD(VU, EEREC_ACC, info); recUpdateFlags(VU, EEREC_ACC, info); } void recVUMI_MSUBAi( VURegs *VU, int info ) { - //Console::WriteLn ("recVUMI_MSUBAi "); + //Console.WriteLn ("recVUMI_MSUBAi "); recVUMI_MSUB_iq_toD( VU, EEREC_ACC, VU_VI_ADDR(REG_I, 1), info ); recUpdateFlags(VU, EEREC_ACC, info); } void recVUMI_MSUBAq( VURegs *VU, int info ) { - //Console::WriteLn ("recVUMI_MSUBAq"); + //Console.WriteLn ("recVUMI_MSUBAq"); recVUMI_MSUB_iq_toD( VU, EEREC_ACC, VU_REGQ_ADDR, info ); recUpdateFlags(VU, EEREC_ACC, info); } void recVUMI_MSUBAx( VURegs *VU, int info ) { - //Console::WriteLn ("recVUMI_MSUBAx"); + //Console.WriteLn ("recVUMI_MSUBAx"); recVUMI_MSUB_xyzw_toD(VU, EEREC_ACC, 0, info); recUpdateFlags(VU, EEREC_ACC, info); } void recVUMI_MSUBAy( VURegs *VU, int info ) { - //Console::WriteLn ("recVUMI_MSUBAy"); + //Console.WriteLn ("recVUMI_MSUBAy"); recVUMI_MSUB_xyzw_toD(VU, EEREC_ACC, 1, info); recUpdateFlags(VU, EEREC_ACC, info); } void recVUMI_MSUBAz( VURegs *VU, int info ) { - //Console::WriteLn ("recVUMI_MSUBAz "); + //Console.WriteLn ("recVUMI_MSUBAz "); recVUMI_MSUB_xyzw_toD(VU, EEREC_ACC, 2, info); recUpdateFlags(VU, EEREC_ACC, info); } void recVUMI_MSUBAw( VURegs *VU, int info ) { - //Console::WriteLn ("recVUMI_MSUBAw"); + //Console.WriteLn ("recVUMI_MSUBAw"); recVUMI_MSUB_xyzw_toD(VU, EEREC_ACC, 3, info); recUpdateFlags(VU, EEREC_ACC, info); } @@ -2273,7 +2273,7 @@ void MINMAXlogical(VURegs *VU, int info, int min, int mode, uptr addr = 0, int x void recVUMI_MAX(VURegs *VU, int info) { if ( _Fd_ == 0 ) return; - //Console::WriteLn ("recVUMI_MAX"); + //Console.WriteLn ("recVUMI_MAX"); if (MINMAXFIX) MINMAXlogical(VU, info, 0, 0); @@ -2311,7 +2311,7 @@ void recVUMI_MAX(VURegs *VU, int info) void recVUMI_MAX_iq(VURegs *VU, uptr addr, int info) { if ( _Fd_ == 0 ) return; - //Console::WriteLn ("recVUMI_MAX_iq"); + //Console.WriteLn ("recVUMI_MAX_iq"); if (MINMAXFIX) MINMAXlogical(VU, info, 0, 1, addr); @@ -2374,7 +2374,7 @@ void recVUMI_MAX_iq(VURegs *VU, uptr addr, int info) void recVUMI_MAX_xyzw(VURegs *VU, int xyzw, int info) { if ( _Fd_ == 0 ) return; - //Console::WriteLn ("recVUMI_MAX_xyzw"); + //Console.WriteLn ("recVUMI_MAX_xyzw"); if (_Fs_ == 0 && _Ft_ == 0) { @@ -2458,7 +2458,7 @@ void recVUMI_MAXw(VURegs *VU, int info) { recVUMI_MAX_xyzw(VU, 3, info); } void recVUMI_MINI(VURegs *VU, int info) { if ( _Fd_ == 0 ) return; - //Console::WriteLn ("recVUMI_MINI"); + //Console.WriteLn ("recVUMI_MINI"); if (MINMAXFIX) MINMAXlogical(VU, info, 1, 0); @@ -2502,7 +2502,7 @@ void recVUMI_MINI(VURegs *VU, int info) void recVUMI_MINI_iq(VURegs *VU, uptr addr, int info) { if ( _Fd_ == 0 ) return; - //Console::WriteLn ("recVUMI_MINI_iq"); + //Console.WriteLn ("recVUMI_MINI_iq"); if (MINMAXFIX) MINMAXlogical(VU, info, 1, 1, addr); @@ -2566,7 +2566,7 @@ void recVUMI_MINI_iq(VURegs *VU, uptr addr, int info) void recVUMI_MINI_xyzw(VURegs *VU, int xyzw, int info) { if ( _Fd_ == 0 ) return; - //Console::WriteLn ("recVUMI_MINI_xyzw"); + //Console.WriteLn ("recVUMI_MINI_xyzw"); if (_Fs_ == 0 && _Ft_ == 0) { @@ -2638,7 +2638,7 @@ void recVUMI_MINIw(VURegs *VU, int info) { recVUMI_MINI_xyzw(VU, 3, info); } //------------------------------------------------------------------ void recVUMI_OPMULA( VURegs *VU, int info ) { - //Console::WriteLn ("recVUMI_OPMULA"); + //Console.WriteLn ("recVUMI_OPMULA"); if (CHECK_VU_EXTRA_OVERFLOW) { if (_Fs_) vuFloat5_useEAX( EEREC_S, EEREC_TEMP, 0xE); if (_Ft_) vuFloat5_useEAX( EEREC_T, EEREC_TEMP, 0xE); @@ -2665,7 +2665,7 @@ void recVUMI_OPMULA( VURegs *VU, int info ) //------------------------------------------------------------------ void recVUMI_OPMSUB( VURegs *VU, int info ) { - //Console::WriteLn ("recVUMI_OPMSUB"); + //Console.WriteLn ("recVUMI_OPMSUB"); if (CHECK_VU_EXTRA_OVERFLOW) { if (_Fs_) vuFloat5_useEAX( EEREC_S, EEREC_TEMP, 0xE); if (_Ft_) vuFloat5_useEAX( EEREC_T, EEREC_TEMP, 0xE); @@ -2695,7 +2695,7 @@ void recVUMI_OPMSUB( VURegs *VU, int info ) //------------------------------------------------------------------ void recVUMI_NOP( VURegs *VU, int info ) { - //Console::WriteLn ("recVUMI_NOP"); + //Console.WriteLn ("recVUMI_NOP"); } //------------------------------------------------------------------ @@ -2707,7 +2707,7 @@ static const PCSX2_ALIGNED16(int rec_const_0x8000000[4]) = { 0x80000000, 0x80000 void recVUMI_FTOI_Saturate(int rec_s, int rec_t, int rec_tmp1, int rec_tmp2) { - //Console::WriteLn ("recVUMI_FTOI_Saturate"); + //Console.WriteLn ("recVUMI_FTOI_Saturate"); //Duplicate the xor'd sign bit to the whole value //FFFF FFFF for positive, 0 for negative SSE_MOVAPS_XMM_to_XMM(rec_tmp1, rec_s); @@ -2742,7 +2742,7 @@ void recVUMI_FTOI0(VURegs *VU, int info) if ( _Ft_ == 0 ) return; - //Console::WriteLn ("recVUMI_FTOI0"); + //Console.WriteLn ("recVUMI_FTOI0"); if (_X_Y_Z_W != 0xf) { SSE_MOVAPS_XMM_to_XMM(EEREC_TEMP, EEREC_S); @@ -2843,7 +2843,7 @@ void recVUMI_FTOIX(VURegs *VU, int addr, int info) if ( _Ft_ == 0 ) return; - //Console::WriteLn ("recVUMI_FTOIX"); + //Console.WriteLn ("recVUMI_FTOIX"); if (_X_Y_Z_W != 0xf) { SSE_MOVAPS_XMM_to_XMM(EEREC_TEMP, EEREC_S); SSE_MULPS_M128_to_XMM(EEREC_TEMP, addr); @@ -2953,7 +2953,7 @@ void recVUMI_ITOF0( VURegs *VU, int info ) { if ( _Ft_ == 0 ) return; - //Console::WriteLn ("recVUMI_ITOF0"); + //Console.WriteLn ("recVUMI_ITOF0"); if (_X_Y_Z_W != 0xf) { SSE2_CVTDQ2PS_XMM_to_XMM(EEREC_TEMP, EEREC_S); vuFloat_useEAX( info, EEREC_TEMP, 15); // Clamp infinities @@ -2970,7 +2970,7 @@ void recVUMI_ITOFX(VURegs *VU, int addr, int info) { if ( _Ft_ == 0 ) return; - //Console::WriteLn ("recVUMI_ITOFX"); + //Console.WriteLn ("recVUMI_ITOFX"); if (_X_Y_Z_W != 0xf) { SSE2_CVTDQ2PS_XMM_to_XMM(EEREC_TEMP, EEREC_S); SSE_MULPS_M128_to_XMM(EEREC_TEMP, addr); @@ -3004,7 +3004,7 @@ void recVUMI_CLIP(VURegs *VU, int info) u32 prevclipaddr = VU_VI_ADDR(REG_CLIP_FLAG, 2); if( clipaddr == 0 ) { // battle star has a clip right before fcset - Console::WriteLn("skipping vu clip"); + Console.WriteLn("skipping vu clip"); return; } @@ -3021,7 +3021,7 @@ void recVUMI_CLIP(VURegs *VU, int info) x86temp1 = ALLOCTEMPX86(MODE_8BITREG); x86temp2 = ALLOCTEMPX86(MODE_8BITREG); - //if ( (x86temp1 == 0) || (x86temp2 == 0) ) Console::Error("VU CLIP Allocation Error: EAX being allocated!"); + //if ( (x86temp1 == 0) || (x86temp2 == 0) ) Console.Error("VU CLIP Allocation Error: EAX being allocated!"); _freeXMMreg(t1reg); // These should have been freed at allocation in eeVURecompileCode() _freeXMMreg(t2reg); // but if they've been used since then, then free them. (just doing this incase :p (cottonvibes)) diff --git a/pcsx2/x86/sVU_zerorec.cpp b/pcsx2/x86/sVU_zerorec.cpp index f555574b19..2eb31c706d 100644 --- a/pcsx2/x86/sVU_zerorec.cpp +++ b/pcsx2/x86/sVU_zerorec.cpp @@ -1,4631 +1,4631 @@ -/* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2009 PCSX2 Dev Team - * - * PCSX2 is free software: you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * PCSX2 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 PCSX2. - * If not, see . - */ - -// Super VU recompiler - author: zerofrog(@gmail.com) - -#include "PrecompiledHeader.h" - -#include -#include -#include -#include - -#include "Utilities/AsciiFile.h" - -#ifndef _WIN32 -#include -#endif - -#include "Common.h" - +/* PCSX2 - PS2 Emulator for PCs + * Copyright (C) 2002-2009 PCSX2 Dev Team + * + * PCSX2 is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * PCSX2 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 PCSX2. + * If not, see . + */ + +// Super VU recompiler - author: zerofrog(@gmail.com) + +#include "PrecompiledHeader.h" + +#include +#include +#include +#include + +#include "Utilities/AsciiFile.h" + +#ifndef _WIN32 +#include +#endif + +#include "Common.h" + #include "GS.h" #include "Gif.h" #include "VU.h" - -#include "R5900.h" -#include "iR5900.h" - -#include "sVU_zerorec.h" -#include "SamplProf.h" -#include "NakedAsm.h" -#include "AppConfig.h" - -using namespace std; - -// temporary externs -extern void iDumpVU0Registers(); -extern void iDumpVU1Registers(); - -// SuperVURec optimization options, uncomment only for debugging purposes -#define SUPERVU_CACHING // vu programs are saved and queried via memcompare (should be no reason to disable this) -#define SUPERVU_WRITEBACKS // don't flush the writebacks after every block -#define SUPERVU_X86CACHING // use x86reg caching (faster) (not really. rather lots slower :p (rama) ) -#define SUPERVU_VIBRANCHDELAY // when integers are modified right before a branch that uses the integer, - // the old integer value is used in the branch, fixes kh2 - -#define SUPERVU_PROPAGATEFLAGS // the correct behavior of VUs, for some reason superman breaks gfx with it on... - -// registers won't be flushed at block boundaries (faster) (nothing noticable speed-wise, causes SPS in Ratchet and clank (Nneeve) ) -#ifndef PCSX2_DEBUG -//#define SUPERVU_INTERCACHING -#endif - -#define SUPERVU_CHECKCONDITION 0 // has to be 0!! - -#define VU_EXESIZE 0x00800000 - -#define _Imm11_ (s32)( (vucode & 0x400) ? (0xfffffc00 | (vucode & 0x3ff)) : (vucode & 0x3ff) ) -#define _UImm11_ (s32)(vucode & 0x7ff) - -#define _Ft_ ((VU->code >> 16) & 0x1F) // The rt part of the instruction register -#define _Fs_ ((VU->code >> 11) & 0x1F) // The rd part of the instruction register -#define _Fd_ ((VU->code >> 6) & 0x1F) // The sa part of the instruction register -#define _It_ (_Ft_ & 15) -#define _Is_ (_Fs_ & 15) -#define _Id_ (_Fd_ & 15) - -static const u32 QWaitTimes[] = { 6, 12 }; -static const u32 PWaitTimes[] = { 53, 43, 28, 23, 17, 11, 10 }; - -static u32 s_vuInfo; // info passed into rec insts - -static const u32 s_MemSize[2] = {VU0_MEMSIZE, VU1_MEMSIZE}; -static u8* s_recVUMem = NULL, *s_recVUPtr = NULL; - -// tables which are defined at the bottom of this massive file. -extern void (*recVU_UPPER_OPCODE[64])(VURegs* VU, s32 info); -extern void (*recVU_LOWER_OPCODE[128])(VURegs* VU, s32 info); - -#define INST_Q_READ 0x0001 // flush Q -#define INST_P_READ 0x0002 // flush P -#define INST_BRANCH_DELAY 0x0004 -#define INST_CLIP_WRITE 0x0040 // inst writes CLIP in the future -#define INST_STATUS_WRITE 0x0080 -#define INST_MAC_WRITE 0x0100 -#define INST_Q_WRITE 0x0200 -#define INST_CACHE_VI 0x0400 // write old vi value to s_VIBranchDelay - -// Let's tempt fate by defining two different constants with almost identical names -#define INST_DUMMY_ 0x8000 -#define INST_DUMMY 0x83c0 - -#define VFFREE_INVALID0 0x80000000 // (vffree[i]&0xf) is invalid - -//#define FORIT(it, v) for(it = (v).begin(); it != (v).end(); ++(it)) - -#ifdef PCSX2_DEBUG -u32 s_vucount = 0; - -static u32 g_vu1lastrec = 0, skipparent = -1; -static u32 s_svulast = 0, s_vufnheader; -static u32 badaddrs[][2] = {0, 0xffff}; -#endif - -union VURecRegs -{ - struct - { - u16 reg; - u16 type; - }; - u32 id; -}; - -#define SUPERVU_XGKICKDELAY 1 // yes this is needed as default (wipeout) - -class VuBaseBlock; - -struct VuFunctionHeader -{ - struct RANGE - { - RANGE() : pmem(NULL) {} - - u16 start, size; - void* pmem; // all the mem - }; - - VuFunctionHeader() : pprogfunc(NULL), startpc(0xffffffff) {} - ~VuFunctionHeader() - { - for (vector::iterator it = ranges.begin(); it != ranges.end(); ++it) - { - free(it->pmem); - } - } - - // returns true if the checksum for the current mem is the same as this fn - bool IsSame(void* pmem); - - u32 startpc; - void* pprogfunc; - - vector ranges; -}; - -struct VuBlockHeader -{ - VuBaseBlock* pblock; - u32 delay; -}; - -// one vu inst (lower and upper) -class VuInstruction -{ - public: - VuInstruction() - { - memzero(*this); - nParentPc = -1; - vicached = -1; - } - - int nParentPc; // used for syncing with flag writes, -1 for no parent - - _vuopinfo info; - - _VURegsNum regs[2]; // [0] - lower, [1] - upper - u32 livevars[2]; // live variables right before this inst, [0] - inst, [1] - float - u32 addvars[2]; // live variables to add - u32 usedvars[2]; // set if var is used in the future including vars used in this inst - u32 keepvars[2]; - u16 pqcycles; // the number of cycles to stall if function writes to the regs - u16 type; // INST_ - - u32 pClipWrite, pMACWrite, pStatusWrite; // addrs to write the flags - u32 vffree[2]; - s8 vfwrite[2], vfread0[2], vfread1[2], vfacc[2]; - s8 vfflush[2]; // extra flush regs - s8 vicached; // if >= 0, then use the cached integer s_VIBranchDelay - VuInstruction *pPrevInst; - - int SetCachedRegs(int upper, u32 vuxyz); - void Recompile(list::iterator& itinst, u32 vuxyz); -}; - -enum BlockType -{ - BLOCKTYPE_EOP = 0x01, // at least one of the children of the block contains eop (or the block itself) - BLOCKTYPE_FUNCTION = 0x02, - BLOCKTYPE_HASEOP = 0x04, // last inst of block is an eop - BLOCKTYPE_MACFLAGS = 0x08, - BLOCKTYPE_ANALYZED = 0x40, - BLOCKTYPE_IGNORE = 0x80, // special for recursive fns - BLOCKTYPE_ANALYZEDPARENT = 0x100 -}; - -// base block used when recompiling -class VuBaseBlock -{ - public: - typedef list LISTBLOCKS; - - VuBaseBlock(); - - // returns true if the leads to a EOP (ALL VU blocks must ret true) - void AssignVFRegs(); - void AssignVIRegs(int parent); - - list::iterator GetInstIterAtPc(int instpc); - void GetInstsAtPc(int instpc, list& listinsts); - - void Recompile(); - - u16 type; // BLOCKTYPE_ - u16 id; - u16 startpc; - u16 endpc; // first inst not in block - void* pcode; // x86 code pointer - void* pendcode; // end of the x86 code pointer - int cycles; - list insts; - list parents; - LISTBLOCKS blocks; // blocks branches to - u32* pChildJumps[4]; // addrs that need to be filled with the children's start addrs - // if highest bit is set, addr needs to be relational - u32 vuxyz; // corresponding bit is set if reg's xyz channels are used only - u32 vuxy; // corresponding bit is set if reg's xyz channels are used only - - _xmmregs startregs[iREGCNT_XMM], endregs[iREGCNT_XMM]; - int nStartx86, nEndx86; // indices into s_vecRegArray - - int allocX86Regs; - int prevFlagsOutOfBlock; -}; - -struct WRITEBACK -{ - WRITEBACK() : nParentPc(0), cycle(0) //, pStatusWrite(NULL), pMACWrite(NULL) - { - viwrite[0] = viwrite[1] = 0; - viread[0] = viread[1] = 0; - } - - void InitInst(VuInstruction* pinst, int cycle) const - { - u32 write = viwrite[0] | viwrite[1]; - pinst->type = ((write & (1 << REG_CLIP_FLAG)) ? INST_CLIP_WRITE : 0) | - ((write & (1 << REG_MAC_FLAG)) ? INST_MAC_WRITE : 0) | - ((write & (1 << REG_STATUS_FLAG)) ? INST_STATUS_WRITE : 0) | - ((write & (1 << REG_Q)) ? INST_Q_WRITE : 0); - pinst->nParentPc = nParentPc; - pinst->info.cycle = cycle; - for (int i = 0; i < 2; ++i) - { - pinst->regs[i].VIwrite = viwrite[i]; - pinst->regs[i].VIread = viread[i]; - } - } - - static int SortWritebacks(const WRITEBACK& w1, const WRITEBACK& w2) - { - return w1.cycle < w2.cycle; - } - - int nParentPc; - int cycle; - u32 viwrite[2]; - u32 viread[2]; -}; - -struct VUPIPELINES -{ - fmacPipe fmac[8]; - fdivPipe fdiv; - efuPipe efu; - ialuPipe ialu[8]; - list< WRITEBACK > listWritebacks; -}; - -VuBaseBlock::VuBaseBlock() -{ - type = 0; - endpc = 0; - cycles = 0; - pcode = NULL; - id = 0; - memzero(pChildJumps); - memzero(startregs); - memzero(endregs); - allocX86Regs = nStartx86 = nEndx86 = -1; - prevFlagsOutOfBlock = 0; -} - -#define SUPERVU_STACKSIZE 0x1000 - -static list s_listVUHeaders[2]; -static list* s_plistCachedHeaders[2] = {NULL, NULL}; -static VuFunctionHeader** recVUHeaders[2] = {NULL, NULL}; -static VuBlockHeader* recVUBlocks[2] = {NULL, NULL}; -static u8* recVUStack = NULL, *recVUStackPtr = NULL; -static vector<_x86regs> s_vecRegArray(128); - -static VURegs* VU = NULL; -static list s_listBlocks; -static u32 s_vu = 0; -static u32 s_UnconditionalDelay = 0; // 1 if there are two sequential branches and the last is unconditional -static u32 g_nLastBlockExecuted = 0; - -static VuFunctionHeader* SuperVURecompileProgram(u32 startpc, int vuindex); -static VuBaseBlock* SuperVUBuildBlocks(VuBaseBlock* parent, u32 startpc, const VUPIPELINES& pipes); -static void SuperVUInitLiveness(VuBaseBlock* pblock); -static void SuperVULivenessAnalysis(); -static void SuperVUEliminateDeadCode(); -static void SuperVUAssignRegs(); - -//void SuperVUFreeXMMreg(int xmmreg, int xmmtype, int reg); -#define SuperVUFreeXMMreg 0&& -void SuperVUFreeXMMregs(u32* livevars); - -static u32* SuperVUStaticAlloc(u32 size); -static void SuperVURecompile(); - -// allocate VU resources -void SuperVUAlloc(int vuindex) -{ - // The old -1 crap has been depreciated on this function. Please - // specify either 0 or 1, thanks. - jASSUME(vuindex >= 0); - - // upper 4 bits must be zero! - if (s_recVUMem == NULL) - { - // upper 4 bits must be zero! - // Changed "first try base" to 0xf1e0000, since 0x0c000000 liked to fail a lot. (cottonvibes) - s_recVUMem = SysMmapEx(0xf1e0000, VU_EXESIZE, 0x10000000, "SuperVUAlloc"); - - if (s_recVUMem == NULL) - { - throw Exception::OutOfMemory( - // untranslated diagnostic msg, use exception's default for translation - wxsFormat( L"SuperVU failed to allocate recompiler memory (addr: 0x%x)", (u32)s_recVUMem ), - _("An out of memory error occured while attempting to reserve memory for the core recompilers.") - ); - } - - ProfilerRegisterSource("VURec", s_recVUMem, VU_EXESIZE); - - if (recVUStack == NULL) recVUStack = new u8[SUPERVU_STACKSIZE * 4]; - } - - if (vuindex >= 0) - { - jASSUME(s_recVUMem != NULL); - - if (recVUHeaders[vuindex] == NULL) - recVUHeaders[vuindex] = new VuFunctionHeader* [s_MemSize[vuindex] / 8]; - if (recVUBlocks[vuindex] == NULL) - recVUBlocks[vuindex] = new VuBlockHeader[s_MemSize[vuindex] / 8]; - if (s_plistCachedHeaders[vuindex] == NULL) - s_plistCachedHeaders[vuindex] = new list[s_MemSize[vuindex] / 8]; - } -} - -void DestroyCachedHeaders(int vuindex, int j) -{ - list::iterator it = s_plistCachedHeaders[vuindex][j].begin(); - - while (it != s_plistCachedHeaders[vuindex][j].end()) - { - delete *it; - it++; - } - - s_plistCachedHeaders[vuindex][j].clear(); -} - -void DestroyVUHeaders(int vuindex) -{ - list::iterator it = s_listVUHeaders[vuindex].begin(); - - while (it != s_listVUHeaders[vuindex].end()) - { - delete *it; - it++; - } - - s_listVUHeaders[vuindex].clear(); -} - -// destroy VU resources -void SuperVUDestroy(int vuindex) -{ - list::iterator it; - - if (vuindex < 0) - { - SuperVUDestroy(0); - SuperVUDestroy(1); - ProfilerTerminateSource("VURec"); - SafeSysMunmap(s_recVUMem, VU_EXESIZE); - safe_delete_array(recVUStack); - } - else - { - safe_delete_array(recVUHeaders[vuindex]); - safe_delete_array(recVUBlocks[vuindex]); - - if (s_plistCachedHeaders[vuindex] != NULL) - { - for (u32 j = 0; j < s_MemSize[vuindex] / 8; ++j) - { - DestroyCachedHeaders(vuindex, j); - } - safe_delete_array(s_plistCachedHeaders[vuindex]); - } - DestroyVUHeaders(vuindex); - } -} - -// reset VU -void SuperVUReset(int vuindex) -{ -#ifdef PCSX2_DEBUG - s_vucount = 0; -#endif - - if (s_recVUMem == NULL) - return; - - //jASSUME( s_recVUMem != NULL ); - - if (vuindex < 0) - { - DbgCon::Status("SuperVU reset > Resetting recompiler memory and structures."); - - // Does this cause problems on VU recompiler resets? It could, if the VU works like - // the EE used to, and actually tries to re-enter the recBlock after issuing a clear. (air) - - //memset_8<0xcd, VU_EXESIZE>(s_recVUMem); - memzero_ptr(recVUStack); - - s_recVUPtr = s_recVUMem; - } - else - { - DbgCon::Status("SuperVU reset [VU%d] > Resetting the recs and junk", vuindex); - list::iterator it; - if (recVUHeaders[vuindex]) memset(recVUHeaders[vuindex], 0, sizeof(VuFunctionHeader*) * (s_MemSize[vuindex] / 8)); - if (recVUBlocks[vuindex]) memset(recVUBlocks[vuindex], 0, sizeof(VuBlockHeader) * (s_MemSize[vuindex] / 8)); - - if (s_plistCachedHeaders[vuindex] != NULL) - { - for (u32 j = 0; j < s_MemSize[vuindex] / 8; ++j) - { - DestroyCachedHeaders(vuindex, j); - } - } - DestroyVUHeaders(vuindex); - } -} - -// clear the block and any joining blocks -void __fastcall SuperVUClear(u32 startpc, u32 size, int vuindex) -{ - vector::iterator itrange; - list::iterator it = s_listVUHeaders[vuindex].begin(); - u32 endpc = startpc + (size + (8 - (size & 7))); // Adding this code to ensure size is always a multiple of 8, it can be simplified to startpc+size if size is always a multiple of 8 (cottonvibes) - while (it != s_listVUHeaders[vuindex].end()) - { - - // for every fn, check if it has code in the range - for(itrange = (*it)->ranges.begin(); itrange != (*it)->ranges.end(); itrange++) - { - if (startpc < (u32)itrange->start + itrange->size && itrange->start < endpc) - break; - } - - if (itrange != (*it)->ranges.end()) - { - recVUHeaders[vuindex][(*it)->startpc/8] = NULL; -#ifdef SUPERVU_CACHING - list* plist = &s_plistCachedHeaders[vuindex][(*it)->startpc/8]; - plist->push_back(*it); - if (plist->size() > 30) - { - // list is too big, delete - //Console::Notice("Performance warning: deleting cached VU program!"); - delete plist->front(); - plist->pop_front(); - } - it = s_listVUHeaders[vuindex].erase(it); -#else - delete *it; - it = s_listVUHeaders[vuindex].erase(it); -#endif - } - else ++it; - } -} - -static VuFunctionHeader* s_pFnHeader = NULL; -static VuBaseBlock* s_pCurBlock = NULL; -static VuInstruction* s_pCurInst = NULL; -static u32 s_StatusRead = 0, s_MACRead = 0, s_ClipRead = 0; // read addrs -static u32 s_PrevStatusWrite = 0, s_PrevMACWrite = 0, s_PrevClipWrite = 0, s_PrevIWrite = 0; -static u32 s_WriteToReadQ = 0; - -static u32 s_VIBranchDelay = 0; //Value of register to use in a vi branch delayed situation - - -u32 s_TotalVUCycles; // total cycles since start of program execution - - -u32 SuperVUGetVIAddr(int reg, int read) -{ - assert(s_pCurInst != NULL); - - switch (reg) - { - case REG_STATUS_FLAG: - { - u32 addr = (read == 2) ? s_PrevStatusWrite : (read ? s_StatusRead : s_pCurInst->pStatusWrite); - assert(!read || addr != 0); - return addr; - } - case REG_MAC_FLAG: - { - u32 addr = (read == 2) ? s_PrevMACWrite : (read ? s_MACRead : s_pCurInst->pMACWrite); - return addr; - } - case REG_CLIP_FLAG: - { - u32 addr = (read == 2) ? s_PrevClipWrite : (read ? s_ClipRead : s_pCurInst->pClipWrite); - assert(!read || addr != 0); - return addr; - } - case REG_Q: - return (read || s_WriteToReadQ) ? (uptr)&VU->VI[REG_Q] : (uptr)&VU->q; - case REG_P: - return read ? (uptr)&VU->VI[REG_P] : (uptr)&VU->p; - case REG_I: - return s_PrevIWrite; - } - -#ifdef SUPERVU_VIBRANCHDELAY - if ((read != 0) && (s_pCurInst->regs[0].pipe == VUPIPE_BRANCH) && (s_pCurInst->vicached >= 0) && (s_pCurInst->vicached == reg)) - { - return (uptr)&s_VIBranchDelay; // test for branch delays - } -#endif - - return (uptr)&VU->VI[reg]; -} - -void SuperVUDumpBlock(list& blocks, int vuindex) -{ - u32 *mem; - u32 i; - - g_Conf->Folders.Logs.Mkdir(); - AsciiFile eff( - Path::Combine( g_Conf->Folders.Logs, wxsFormat(L"svu%cdump%.4X.txt", s_vu?L'0':L'1', s_pFnHeader->startpc) ), - wxFile::write - ); - - eff.Printf("Format: upper_inst lower_inst\ntype f:vf_live_vars vf_used_vars i:vi_live_vars vi_used_vars inst_cycle pq_inst\n"); - eff.Printf("Type: %.2x - qread, %.2x - pread, %.2x - clip_write, %.2x - status_write\n" - "%.2x - mac_write, %.2x -qflush\n", - INST_Q_READ, INST_P_READ, INST_CLIP_WRITE, INST_STATUS_WRITE, INST_MAC_WRITE, INST_Q_WRITE); - eff.Printf("XMM: Upper: read0 read1 write acc temp; Lower: read0 read1 write acc temp\n\n"); - - list::iterator itblock; - list::iterator itinst; - VuBaseBlock::LISTBLOCKS::iterator itchild; - - for(itblock = blocks.begin(); itblock != blocks.end(); itblock++) - { - eff.Printf( "block:%c %x-%x; children: ", ((*itblock)->type&BLOCKTYPE_HASEOP) ? '*' : ' ', - (*itblock)->startpc, (*itblock)->endpc - 8); - - for(itchild = (*itblock)->blocks.begin(); itchild != (*itblock)->blocks.end(); itchild++) - { - eff.Printf("%x ", (*itchild)->startpc); - } - eff.Printf("; vuxyz = %x, vuxy = %x\n", (*itblock)->vuxyz&(*itblock)->insts.front().usedvars[1], - (*itblock)->vuxy&(*itblock)->insts.front().usedvars[1]); - - itinst = (*itblock)->insts.begin(); - i = (*itblock)->startpc; - while (itinst != (*itblock)->insts.end()) - { - assert(i <= (*itblock)->endpc); - if (itinst->type & INST_DUMMY) - { - if (itinst->nParentPc >= 0 && !(itinst->type&INST_DUMMY_)) - { - // search for the parent - eff.Printf("writeback 0x%x (%x)\n", itinst->type, itinst->nParentPc); - } - } - else - { - mem = (u32*) & VU->Micro[i]; - char* pstr = disVU1MicroUF(mem[1], i + 4); - eff.Printf( "%.4x: %-40s", i, pstr); - if (mem[1] & 0x80000000) eff.Printf( " I=%f(%.8x)\n", *(float*)mem, mem[0]); - else eff.Printf( "%s\n", disVU1MicroLF(mem[0], i)); - i += 8; - } - - ++itinst; - } - - eff.Printf("\n"); - - _x86regs* pregs; - if ((*itblock)->nStartx86 >= 0 || (*itblock)->nEndx86 >= 0) - { - eff.Printf( "X86: AX CX DX BX SP BP SI DI\n"); - } - - if ((*itblock)->nStartx86 >= 0) - { - pregs = &s_vecRegArray[(*itblock)->nStartx86]; - eff.Printf( "STR: "); - for (i = 0; i < iREGCNT_GPR; ++i) - { - if (pregs[i].inuse) - eff.Printf( "%.2d ", pregs[i].reg); - else - eff.Printf( "-1 "); - } - eff.Printf( "\n"); - } - - if ((*itblock)->nEndx86 >= 0) - { - eff.Printf( "END: "); - pregs = &s_vecRegArray[(*itblock)->nEndx86]; - for (i = 0; i < iREGCNT_GPR; ++i) - { - if (pregs[i].inuse) - eff.Printf( "%.2d ", pregs[i].reg); - else - eff.Printf( "-1 "); - } - eff.Printf( "\n"); - } - - itinst = (*itblock)->insts.begin(); - for (i = (*itblock)->startpc; i < (*itblock)->endpc; ++itinst) - { - - if (itinst->type & INST_DUMMY) - { - } - else - { - char str[256]; - sprintf(str, "%.4x:%x f:%.8x_%.8x", i, itinst->type, itinst->livevars[1], itinst->usedvars[1]); - eff.Printf( "%-46s i:%.8x_%.8x c:%d pq:%d\n", str, - itinst->livevars[0], itinst->usedvars[0], (int)itinst->info.cycle, (int)itinst->pqcycles); - - sprintf(str, "XMM r0:%d r1:%d w:%d a:%d t:%x;", - itinst->vfread0[1], itinst->vfread1[1], itinst->vfwrite[1], itinst->vfacc[1], itinst->vffree[1]); - eff.Printf( "%-46s r0:%d r1:%d w:%d a:%d t:%x\n", str, - itinst->vfread0[0], itinst->vfread1[0], itinst->vfwrite[0], itinst->vfacc[0], itinst->vffree[0]); - i += 8; - } - } - -// -#if 0 // __LINUX__ - - // dump the asm - if ((*itblock)->pcode != NULL) - { - char command[255]; - FILE* fasm = fopen("mydump1", "wb"); - //Console::WriteLn("writing: %x, %x", (*itblock)->startpc, (uptr)(*itblock)->pendcode - (uptr)(*itblock)->pcode); - fwrite((*itblock)->pcode, 1, (uptr)(*itblock)->pendcode - (uptr)(*itblock)->pcode, fasm); - fclose(fasm); - sprintf(command, "objdump -D --target=binary --architecture=i386 -M intel mydump1 > tempdump"); - system(command); - fasm = fopen("tempdump", "r"); - // read all of it and write it to f - fseek(fasm, 0, SEEK_END); - vector vbuffer(ftell(fasm)); - fseek(fasm, 0, SEEK_SET); - fread(&vbuffer[0], vbuffer.size(), 1, fasm); - - fprintf(f, "\n\n"); - fwrite(&vbuffer[0], vbuffer.size(), 1, f); - fclose(fasm); - } -#endif - - eff.Printf("\n---------------\n"); - } -} - -// uncomment to count svu exec time -//#define SUPERVU_COUNT - -// Private methods -void* SuperVUGetProgram(u32 startpc, int vuindex) -{ - assert(startpc < s_MemSize[vuindex]); - assert((startpc % 8) == 0); - assert(recVUHeaders[vuindex] != NULL); - VuFunctionHeader** pheader = &recVUHeaders[vuindex][startpc/8]; - - if (*pheader == NULL) - { - -#ifdef SUPERVU_CACHING - void* pmem = (vuindex & 1) ? VU1.Micro : VU0.Micro; - // check if program exists in cache - list::iterator it; - for(it = s_plistCachedHeaders[vuindex][startpc/8].begin(); it != s_plistCachedHeaders[vuindex][startpc/8].end(); it++) - { - if ((*it)->IsSame(pmem)) - { - // found, transfer to regular lists - void* pfn = (*it)->pprogfunc; - recVUHeaders[vuindex][startpc/8] = *it; - s_listVUHeaders[vuindex].push_back(*it); - s_plistCachedHeaders[vuindex][startpc/8].erase(it); - return pfn; - } - } -#endif - - *pheader = SuperVURecompileProgram(startpc, vuindex); - - if (*pheader == NULL) - { - assert(s_TotalVUCycles > 0); - if (vuindex) - VU1.VI[REG_TPC].UL = startpc; - else - VU0.VI[REG_TPC].UL = startpc; - - return (void*)SuperVUEndProgram; - } - - assert((*pheader)->pprogfunc != NULL); - } - //else assert( (*pheader)->IsSame((vuindex&1) ? VU1.Micro : VU0.Micro) ); - - assert((*pheader)->startpc == startpc); - - return (*pheader)->pprogfunc; -} - -bool VuFunctionHeader::IsSame(void* pmem) -{ -#ifdef SUPERVU_CACHING - vector::iterator it; - for(it = ranges.begin(); it != ranges.end(); it++) - { - if (memcmp_mmx((u8*)pmem + it->start, it->pmem, it->size)) - return false; - } -#endif - return true; -} - -list::iterator VuBaseBlock::GetInstIterAtPc(int instpc) -{ - assert(instpc >= 0); - - u32 curpc = startpc; - list::iterator it; - for (it = insts.begin(); it != insts.end(); ++it) - { - if (it->type & INST_DUMMY) continue; - if (curpc == instpc) break; - curpc += 8; - } - - if (it != insts.end()) return it; - - assert(0); - return insts.begin(); -} - -void VuBaseBlock::GetInstsAtPc(int instpc, list& listinsts) -{ - assert(instpc >= 0); - - listinsts.clear(); - - u32 curpc = startpc; - list::iterator it; - for (it = insts.begin(); it != insts.end(); ++it) - { - if (it->type & INST_DUMMY) continue; - if (curpc == instpc) break; - curpc += 8; - } - - if (it != insts.end()) - { - listinsts.push_back(&(*it)); - return; - } - - // look for the pc in other blocks - for (list::iterator itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); ++itblock) - { - if (*itblock == this) continue; - - if (instpc >= (*itblock)->startpc && instpc < (*itblock)->endpc) - { - listinsts.push_back(&(*(*itblock)->GetInstIterAtPc(instpc))); - } - } - - assert(listinsts.size() > 0); -} - -static VuFunctionHeader* SuperVURecompileProgram(u32 startpc, int vuindex) -{ - assert(vuindex < 2); - assert(s_recVUPtr != NULL); - //Console::WriteLn("svu%c rec: %x", '0'+vuindex, startpc); - - // if recPtr reached the mem limit reset whole mem - if (((uptr)s_recVUPtr - (uptr)s_recVUMem) >= VU_EXESIZE - 0x40000) - { - //Console::WriteLn("SuperVU reset mem"); - SuperVUReset(0); - SuperVUReset(1); - SuperVUReset(-1); - if (s_TotalVUCycles > 0) - { - // already executing, so return NULL - return NULL; - } - } - - list::iterator itblock; - - s_vu = vuindex; - VU = s_vu ? &VU1 : &VU0; - s_pFnHeader = new VuFunctionHeader(); - s_listVUHeaders[vuindex].push_back(s_pFnHeader); - s_pFnHeader->startpc = startpc; - - memset(recVUBlocks[s_vu], 0, sizeof(VuBlockHeader) * (s_MemSize[s_vu] / 8)); - - // analyze the global graph - s_listBlocks.clear(); - VUPIPELINES pipes; - memzero(pipes.fmac); - memzero(pipes.fdiv); - memzero(pipes.efu); - memzero(pipes.ialu); - SuperVUBuildBlocks(NULL, startpc, pipes); - - // fill parents - VuBaseBlock::LISTBLOCKS::iterator itchild; - for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) - { - for(itchild = (*itblock)->blocks.begin(); itchild != (*itblock)->blocks.end(); itchild++) - { - (*itchild)->parents.push_back(*itblock); - } - - //(*itblock)->type &= ~(BLOCKTYPE_IGNORE|BLOCKTYPE_ANALYZED); - } - - assert(s_listBlocks.front()->startpc == startpc); - s_listBlocks.front()->type |= BLOCKTYPE_FUNCTION; - - for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) - { - SuperVUInitLiveness(*itblock); - } - - SuperVULivenessAnalysis(); - SuperVUEliminateDeadCode(); - SuperVUAssignRegs(); - -#ifdef PCSX2_DEBUG - if ((s_vu && (vudump&1)) || (!s_vu && (vudump&16))) SuperVUDumpBlock(s_listBlocks, s_vu); -#endif - - // code generation - x86SetPtr(s_recVUPtr); - branch = 0; - - SuperVURecompile(); - - s_recVUPtr = x86Ptr; - - // set the function's range - VuFunctionHeader::RANGE r; - s_pFnHeader->ranges.reserve(s_listBlocks.size()); - - for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) - { - r.start = (*itblock)->startpc; - r.size = (*itblock)->endpc - (*itblock)->startpc; -#ifdef SUPERVU_CACHING - //memxor_mmx(r.checksum, &VU->Micro[r.start], r.size); - r.pmem = malloc(r.size); - memcpy_fast(r.pmem, &VU->Micro[r.start], r.size); -#endif - s_pFnHeader->ranges.push_back(r); - } - -#if defined(PCSX2_DEBUG) && defined(__LINUX__) - // dump at the end to capture the actual code - if ((s_vu && (vudump&1)) || (!s_vu && (vudump&16))) SuperVUDumpBlock(s_listBlocks, s_vu); -#endif - - // destroy - for (list::iterator itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); ++itblock) - { - delete *itblock; - } - s_listBlocks.clear(); - - assert(s_recVUPtr < s_recVUMem + VU_EXESIZE); - - return s_pFnHeader; -} - -static int _recbranchAddr(u32 vucode) -{ - s32 bpc = pc + (_Imm11_ << 3); - /* - if ( bpc < 0 ) { - Console::WriteLn("zerorec branch warning: bpc < 0 ( %x ); Using unsigned imm11", bpc); - bpc = pc + (_UImm11_ << 3); - }*/ - bpc &= (s_MemSize[s_vu] - 1); - - return bpc; -} - -// return inst that flushes everything -static VuInstruction SuperVUFlushInst() -{ - VuInstruction inst; - // don't need to read q/p - inst.type = INST_DUMMY_;//|INST_Q_READ|INST_P_READ; - return inst; -} - -void SuperVUAddWritebacks(VuBaseBlock* pblock, const list& listWritebacks) -{ -#ifdef SUPERVU_WRITEBACKS - // regardless of repetition, add the pipes (for selfloops) - list::const_iterator itwriteback = listWritebacks.begin(); - list::iterator itinst = pblock->insts.begin(), itinst2; - - while (itwriteback != listWritebacks.end()) - { - if (itinst != pblock->insts.end() && (itinst->info.cycle < itwriteback->cycle || (itinst->type&INST_DUMMY))) - { - ++itinst; - continue; - } - - itinst2 = pblock->insts.insert(itinst, VuInstruction()); - itwriteback->InitInst(&(*itinst2), vucycle); - ++itwriteback; - } -#endif -} - -#ifdef SUPERVU_VIBRANCHDELAY -static VuInstruction* getDelayInst(VuInstruction* pInst) -{ - // check for the N cycle branch delay - // example of 2 cycles delay (monster house) : - // sqi vi05 - // sqi vi05 - // ibeq vi05, vi03 - // The ibeq should read the vi05 before the first sqi - - //more info: - - // iaddiu vi01, 0, 1 - // ibeq vi01, 0 <- reads vi01 before the iaddiu - - // iaddiu vi01, 0, 1 - // iaddiu vi01, vi01, 1 - // iaddiu vi01, vi01, 1 - // ibeq vi01, 0 <- reads vi01 before the last two iaddiu's (so the value read is 1) - - // ilw vi02, addr - // iaddiu vi01, 0, 1 - // ibeq vi01, vi02 <- reads current values of both vi01 and vi02 because the branch instruction stalls - - int delay = 1; - VuInstruction* pDelayInst = NULL; - VuInstruction* pTargetInst = pInst->pPrevInst; - while (1) - { - if (pTargetInst != NULL - && pTargetInst->info.cycle + delay == pInst->info.cycle - && (pTargetInst->regs[0].pipe == VUPIPE_IALU || pTargetInst->regs[0].pipe == VUPIPE_FMAC) - && ((pTargetInst->regs[0].VIwrite & pInst->regs[0].VIread) & 0xffff) - && (delay == 1 || ((pTargetInst->regs[0].VIwrite & pInst->regs[0].VIread) & 0xffff) == ((pTargetInst->regs[0].VIwrite & pInst->pPrevInst->regs[0].VIread) & 0xffff)) - && !(pTargetInst->regs[0].VIread&((1 << REG_STATUS_FLAG) | (1 << REG_MAC_FLAG) | (1 << REG_CLIP_FLAG)))) - { - pDelayInst = pTargetInst; - pTargetInst = pTargetInst->pPrevInst; - delay++; - if (delay == 5) //maximum delay is 4 (length of the pipeline) - { - DevCon::WriteLn("supervu: cycle branch delay maximum (4) is reached"); - break; - } - } - else break; - } - if (delay > 1) DevCon::WriteLn("supervu: %d cycle branch delay detected: %x %x", delay - 1, pc, s_pFnHeader->startpc); - return pDelayInst; -} -#endif - -static VuBaseBlock* SuperVUBuildBlocks(VuBaseBlock* parent, u32 startpc, const VUPIPELINES& pipes) -{ - // check if block already exists - //Console::WriteLn("startpc %x", startpc); - startpc &= (s_vu ? 0x3fff : 0xfff); - VuBlockHeader* pbh = &recVUBlocks[s_vu][startpc/8]; - - if (pbh->pblock != NULL) - { - - VuBaseBlock* pblock = pbh->pblock; - list::iterator itinst; - - if (pblock->startpc == startpc) - { - SuperVUAddWritebacks(pblock, pipes.listWritebacks); - return pblock; - } - - // have to divide the blocks, pnewblock is first block - assert(startpc > pblock->startpc); - assert(startpc < pblock->endpc); - - u32 dummyinst = (startpc - pblock->startpc) >> 3; - - // count inst non-dummy insts - itinst = pblock->insts.begin(); - int cycleoff = 0; - - while (dummyinst > 0) - { - if (itinst->type & INST_DUMMY) - ++itinst; - else - { - cycleoff = itinst->info.cycle; - ++itinst; - --dummyinst; - } - } - - // NOTE: still leaves insts with their writebacks in different blocks - while (itinst->type & INST_DUMMY) - ++itinst; - - // the difference in cycles between dummy insts (naruto utlimate ninja) - int cyclediff = 0; - if (parent == pblock) - cyclediff = itinst->info.cycle - cycleoff; - cycleoff = itinst->info.cycle; - - // new block - VuBaseBlock* pnewblock = new VuBaseBlock(); - s_listBlocks.push_back(pnewblock); - - pnewblock->startpc = startpc; - pnewblock->endpc = pblock->endpc; - pnewblock->cycles = pblock->cycles - cycleoff + cyclediff; - - pnewblock->blocks.splice(pnewblock->blocks.end(), pblock->blocks); - pnewblock->insts.splice(pnewblock->insts.end(), pblock->insts, itinst, pblock->insts.end()); - pnewblock->type = pblock->type; - - // any writebacks in the next 3 cycles also belong to original block -// for(itinst = pnewblock->insts.begin(); itinst != pnewblock->insts.end(); ) { -// if( (itinst->type & INST_DUMMY) && itinst->nParentPc >= 0 && itinst->nParentPc < (int)startpc ) { -// -// if( !(itinst->type & INST_Q_WRITE) ) -// pblock->insts.push_back(*itinst); -// itinst = pnewblock->insts.erase(itinst); -// continue; -// } -// -// ++itinst; -// } - - pbh = &recVUBlocks[s_vu][startpc/8]; - for (u32 inst = startpc; inst < pblock->endpc; inst += 8) - { - if (pbh->pblock == pblock) - pbh->pblock = pnewblock; - ++pbh; - } - - for(itinst = pnewblock->insts.begin(); itinst != pnewblock->insts.end(); itinst++) - { - itinst->info.cycle -= cycleoff; - } - - SuperVUAddWritebacks(pnewblock, pipes.listWritebacks); - - // old block - pblock->blocks.push_back(pnewblock); - pblock->endpc = startpc; - pblock->cycles = cycleoff; - pblock->type &= BLOCKTYPE_MACFLAGS; - //pblock->insts.push_back(SuperVUFlushInst()); //don't need - - return pnewblock; - } - - VuBaseBlock* pblock = new VuBaseBlock(); - s_listBlocks.push_back(pblock); - - int i = 0; - branch = 0; - pc = startpc; - pblock->startpc = startpc; - - // clear stalls (might be a prob) - memcpy(VU->fmac, pipes.fmac, sizeof(pipes.fmac)); - memcpy(&VU->fdiv, &pipes.fdiv, sizeof(pipes.fdiv)); - memcpy(&VU->efu, &pipes.efu, sizeof(pipes.efu)); - memcpy(VU->ialu, pipes.ialu, sizeof(pipes.ialu)); -// memset(VU->fmac, 0, sizeof(VU->fmac)); -// memset(&VU->fdiv, 0, sizeof(VU->fdiv)); -// memset(&VU->efu, 0, sizeof(VU->efu)); - - vucycle = 0; - - u8 macflags = 0; - - list< WRITEBACK > listWritebacks; - list< WRITEBACK >::iterator itwriteback; - list::iterator itinst; - u32 hasSecondBranch = 0; - u32 needFullStatusFlag = 0; - -#ifdef SUPERVU_WRITEBACKS - listWritebacks = pipes.listWritebacks; -#endif - - // first analysis pass for status flags - while (1) - { - u32* ptr = (u32*) & VU->Micro[pc]; - pc += 8; - int prevbranch = branch; - - if (ptr[1] & 0x40000000) - branch = 1; - - if (!(ptr[1] & 0x80000000)) // not I - { - switch (ptr[0] >> 25) - { - case 0x24: // jr - case 0x25: // jalr - case 0x20: // B - case 0x21: // BAL - case 0x28: // IBEQ - case 0x2f: // IBGEZ - case 0x2d: // IBGTZ - case 0x2e: // IBLEZ - case 0x2c: // IBLTZ - case 0x29: // IBNE - branch = 1; - break; - - case 0x14: // fseq - case 0x17: // fsor - //needFullStatusFlag = 2; - break; - - case 0x16: // fsand - if ((ptr[0]&0xc0)) - { - // sometimes full sticky bits are needed (simple series 2000 - oane chapara) - //Console::WriteLn("needSticky: %x-%x", s_pFnHeader->startpc, startpc); - needFullStatusFlag = 2; - } - break; - } - } - - if (prevbranch) - break; - - if (pc >= s_MemSize[s_vu]) - { - Console::Error("inf vu0 prog %x", startpc); - break; - } - } - - // second full pass - pc = startpc; - branch = 0; - VuInstruction* pprevinst = NULL, *pinst = NULL; - - while (1) - { - - if (pc == s_MemSize[s_vu]) - { - branch |= 8; - break; - } - - if (!branch && pbh->pblock != NULL) - { - pblock->blocks.push_back(pbh->pblock); - break; - } - - int prevbranch = branch; - - if (!prevbranch) - { - pbh->pblock = pblock; - } - else assert(prevbranch || pbh->pblock == NULL); - - pblock->insts.push_back(VuInstruction()); - - pprevinst = pinst; - pinst = &pblock->insts.back(); - pinst->pPrevInst = pprevinst; - SuperVUAnalyzeOp(VU, &pinst->info, pinst->regs); - -#ifdef SUPERVU_VIBRANCHDELAY - if (pinst->regs[0].pipe == VUPIPE_BRANCH && pblock->insts.size() > 1) - { - - VuInstruction* pdelayinst = getDelayInst(pinst); - if (pdelayinst) - { - pdelayinst->type |= INST_CACHE_VI; - - // find the correct register - u32 mask = pdelayinst->regs[0].VIwrite & pinst->regs[0].VIread; - for (int i = 0; i < 16; ++i) - { - if (mask & (1 << i)) - { - pdelayinst->vicached = i; - break; - } - } - - pinst->vicached = pdelayinst->vicached; - } - } -#endif - - if (prevbranch) - { - if (pinst->regs[0].pipe == VUPIPE_BRANCH) - hasSecondBranch = 1; - pinst->type |= INST_BRANCH_DELAY; - } - - // check write back - for (itwriteback = listWritebacks.begin(); itwriteback != listWritebacks.end();) - { - if (pinst->info.cycle >= itwriteback->cycle) - { - itinst = pblock->insts.insert(--pblock->insts.end(), VuInstruction()); - itwriteback->InitInst(&(*itinst), pinst->info.cycle); - itwriteback = listWritebacks.erase(itwriteback); - } - else ++itwriteback; - } - - // add new writebacks - WRITEBACK w; - const u32 allflags = (1 << REG_CLIP_FLAG) | (1 << REG_MAC_FLAG) | (1 << REG_STATUS_FLAG); - for (int j = 0; j < 2; ++j) w.viwrite[j] = pinst->regs[j].VIwrite & allflags; - - if (pinst->info.macflag & VUOP_WRITE) w.viwrite[1] |= (1 << REG_MAC_FLAG); - if (pinst->info.statusflag & VUOP_WRITE) w.viwrite[1] |= (1 << REG_STATUS_FLAG); - - if ((pinst->info.macflag | pinst->info.statusflag) & VUOP_READ) - macflags = 1; - if (pinst->regs[0].VIread & ((1 << REG_MAC_FLAG) | (1 << REG_STATUS_FLAG))) - macflags = 1; - -// if( pinst->regs[1].pipe == VUPIPE_FMAC && (pinst->regs[1].VFwrite==0&&!(pinst->regs[1].VIwrite&(1<regs[0].VIread |= (1<VIwrite |= lregs->VIwrite & (1<info.statusflag&VUOP_WRITE) && !(pinst->regs[0].VIwrite&(1 << REG_STATUS_FLAG))) && needFullStatusFlag) - { - // don't read if first inst - if (needFullStatusFlag == 1) - w.viread[1] |= (1 << REG_STATUS_FLAG); - else --needFullStatusFlag; - } - - for (int j = 0; j < 2; ++j) - { - w.viread[j] |= pinst->regs[j].VIread & allflags; - - if ((pinst->regs[j].VIread&(1 << REG_STATUS_FLAG)) && (pinst->regs[j].VIwrite&(1 << REG_STATUS_FLAG))) - { - // don't need the read anymore - pinst->regs[j].VIread &= ~(1 << REG_STATUS_FLAG); - } - if ((pinst->regs[j].VIread&(1 << REG_MAC_FLAG)) && (pinst->regs[j].VIwrite&(1 << REG_MAC_FLAG))) - { - // don't need the read anymore - pinst->regs[j].VIread &= ~(1 << REG_MAC_FLAG); - } - - pinst->regs[j].VIwrite &= ~allflags; - } - - if (pinst->info.macflag & VUOP_READ) w.viread[1] |= 1 << REG_MAC_FLAG; - if (pinst->info.statusflag & VUOP_READ) w.viread[1] |= 1 << REG_STATUS_FLAG; - - w.nParentPc = pc - 8; - w.cycle = pinst->info.cycle + 4; - listWritebacks.push_back(w); - } - - if (pinst->info.q&VUOP_READ) pinst->type |= INST_Q_READ; - if (pinst->info.p&VUOP_READ) pinst->type |= INST_P_READ; - - if (pinst->info.q&VUOP_WRITE) - { - pinst->pqcycles = QWaitTimes[pinst->info.pqinst] + 1; - - memset(&w, 0, sizeof(w)); - w.nParentPc = pc - 8; - w.cycle = pinst->info.cycle + pinst->pqcycles; - w.viwrite[0] = 1 << REG_Q; - listWritebacks.push_back(w); - } - if (pinst->info.p&VUOP_WRITE) - pinst->pqcycles = PWaitTimes[pinst->info.pqinst] + 1; - - if (prevbranch) - { - break; - } - - // make sure there is always a branch - // sensible soccer overflows on vu0, so increase the limit... - if ((s_vu == 1 && i >= 0x799) || (s_vu == 0 && i >= 0x201)) - { - Console::Error("VuRec base block doesn't terminate!"); - assert(0); - break; - } - - i++; - pbh++; - } - - if (macflags) - pblock->type |= BLOCKTYPE_MACFLAGS; - - pblock->endpc = pc; - u32 lastpc = pc; - - pblock->cycles = vucycle; - -#ifdef SUPERVU_WRITEBACKS - if (!branch || (branch&8)) -#endif - { - // flush writebacks - if (listWritebacks.size() > 0) - { - listWritebacks.sort(WRITEBACK::SortWritebacks); - for (itwriteback = listWritebacks.begin(); itwriteback != listWritebacks.end(); ++itwriteback) - { - if (itwriteback->viwrite[0] & (1 << REG_Q)) - { - // ignore all Q writebacks - continue; - } - - pblock->insts.push_back(VuInstruction()); - itwriteback->InitInst(&pblock->insts.back(), vucycle); - } - - listWritebacks.clear(); - } - } - - if (!branch) return pblock; - - if (branch & 8) - { - // what if also a jump? - pblock->type |= BLOCKTYPE_EOP | BLOCKTYPE_HASEOP; - - // add an instruction to flush p and q (if written) - pblock->insts.push_back(SuperVUFlushInst()); - return pblock; - } - - // it is a (cond) branch or a jump - u32 vucode = *(u32*)(VU->Micro + lastpc - 16); - int bpc = _recbranchAddr(vucode) - 8; - - VUPIPELINES newpipes; - memcpy(newpipes.fmac, VU->fmac, sizeof(newpipes.fmac)); - memcpy(&newpipes.fdiv, &VU->fdiv, sizeof(newpipes.fdiv)); - memcpy(&newpipes.efu, &VU->efu, sizeof(newpipes.efu)); - memcpy(newpipes.ialu, VU->ialu, sizeof(newpipes.ialu)); - - for (i = 0; i < 8; ++i) newpipes.fmac[i].sCycle -= vucycle; - newpipes.fdiv.sCycle -= vucycle; - newpipes.efu.sCycle -= vucycle; - for (i = 0; i < 8; ++i) newpipes.ialu[i].sCycle -= vucycle; - - if (listWritebacks.size() > 0) - { - // flush all when jumping, send down the pipe when in branching - bool bFlushWritebacks = (vucode >> 25) == 0x24 || (vucode >> 25) == 0x25;//||(vucode>>25)==0x20||(vucode>>25)==0x21; - - listWritebacks.sort(WRITEBACK::SortWritebacks); - for (itwriteback = listWritebacks.begin(); itwriteback != listWritebacks.end(); ++itwriteback) - { - if (itwriteback->viwrite[0] & (1 << REG_Q)) - { - // ignore all Q writebacks - continue; - } - - if (itwriteback->cycle < vucycle || bFlushWritebacks) - { - pblock->insts.push_back(VuInstruction()); - itwriteback->InitInst(&pblock->insts.back(), vucycle); - } - else - { - newpipes.listWritebacks.push_back(*itwriteback); - newpipes.listWritebacks.back().cycle -= vucycle; - } - } - } - - if (newpipes.listWritebacks.size() > 0) // other blocks might read the mac flags - pblock->type |= BLOCKTYPE_MACFLAGS; - - u32 firstbranch = vucode >> 25; - switch (firstbranch) - { - case 0x24: // jr - pblock->type |= BLOCKTYPE_EOP; // jump out of procedure, since not returning, set EOP - pblock->insts.push_back(SuperVUFlushInst()); - firstbranch = 0xff; //Non-Conditional Jump - break; - - case 0x25: // jalr - { - // linking, so will return to procedure - pblock->insts.push_back(SuperVUFlushInst()); - - VuBaseBlock* pjumpblock = SuperVUBuildBlocks(pblock, lastpc, newpipes); - - // update pblock since could have changed - pblock = recVUBlocks[s_vu][lastpc/8-2].pblock; - assert(pblock != NULL); - - pblock->blocks.push_back(pjumpblock); - firstbranch = 0xff; //Non-Conditional Jump - break; - } - case 0x20: // B - { - VuBaseBlock* pbranchblock = SuperVUBuildBlocks(pblock, bpc, newpipes); - - // update pblock since could have changed - pblock = recVUBlocks[s_vu][lastpc/8-2].pblock; - assert(pblock != NULL); - - pblock->blocks.push_back(pbranchblock); - firstbranch = 0xff; //Non-Conditional Jump - break; - } - case 0x21: // BAL - { - VuBaseBlock* pbranchblock = SuperVUBuildBlocks(pblock, bpc, newpipes); - - // update pblock since could have changed - pblock = recVUBlocks[s_vu][lastpc/8-2].pblock; - assert(pblock != NULL); - pblock->blocks.push_back(pbranchblock); - firstbranch = 0xff; //Non-Conditional Jump - break; - } - case 0x28: // IBEQ - case 0x2f: // IBGEZ - case 0x2d: // IBGTZ - case 0x2e: // IBLEZ - case 0x2c: // IBLTZ - case 0x29: // IBNE - { - VuBaseBlock* pbranchblock = SuperVUBuildBlocks(pblock, bpc, newpipes); - - // update pblock since could have changed - pblock = recVUBlocks[s_vu][lastpc/8-2].pblock; - assert(pblock != NULL); - pblock->blocks.push_back(pbranchblock); - - // if has a second branch that is B or BAL, skip this - u32 secondbranch = (*(u32*)(VU->Micro + lastpc - 8)) >> 25; - if (!hasSecondBranch || (secondbranch != 0x21 && secondbranch != 0x20)) - { - pbranchblock = SuperVUBuildBlocks(pblock, lastpc, newpipes); - - pblock = recVUBlocks[s_vu][lastpc/8-2].pblock; - pblock->blocks.push_back(pbranchblock); - } - - break; - } - default: - assert(pblock->blocks.size() == 1); - break; - } - - pblock = recVUBlocks[s_vu][lastpc/8-2].pblock; - -#ifdef SUPERVU_VIBRANCHDELAY -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -///// NOTE! This could still be a hack for KH2/GoW, but until we know how it properly works, this will do for now./// -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - if (hasSecondBranch && firstbranch != 0xff) //check the previous jump was conditional and there is a second branch - { -#else - if (hasSecondBranch) - { -#endif - - u32 vucode = *(u32*)(VU->Micro + lastpc - 8); - pc = lastpc; - int bpc = _recbranchAddr(vucode); - - switch (vucode >> 25) - { - case 0x24: // jr - Console::Error("svurec bad jr jump!"); - assert(0); - break; - - case 0x25: // jalr - { - Console::Error("svurec bad jalr jump!"); - assert(0); - break; - } - case 0x20: // B - { - VuBaseBlock* pbranchblock = SuperVUBuildBlocks(pblock, bpc, newpipes); - - // update pblock since could have changed - pblock = recVUBlocks[s_vu][lastpc/8-2].pblock; - - pblock->blocks.push_back(pbranchblock); - break; - } - case 0x21: // BAL - { - VuBaseBlock* pbranchblock = SuperVUBuildBlocks(pblock, bpc, newpipes); - - // replace instead of pushing a new block - pblock = recVUBlocks[s_vu][lastpc/8-2].pblock; - pblock->blocks.push_back(pbranchblock); - break; - } - case 0x28: // IBEQ - case 0x2f: // IBGEZ - case 0x2d: // IBGTZ - case 0x2e: // IBLEZ - case 0x2c: // IBLTZ - case 0x29: // IBNE - { - VuBaseBlock* pbranchblock = SuperVUBuildBlocks(pblock, bpc, newpipes); - - // update pblock since could have changed - pblock = recVUBlocks[s_vu][lastpc/8-2].pblock; - pblock->blocks.push_back(pbranchblock); - - // only add the block if the previous branch doesn't include the next instruction (ie, if a direct jump) - if (firstbranch == 0x24 || firstbranch == 0x25 || firstbranch == 0x20 || firstbranch == 0x21) - { - pbranchblock = SuperVUBuildBlocks(pblock, lastpc, newpipes); - - pblock = recVUBlocks[s_vu][lastpc/8-2].pblock; - pblock->blocks.push_back(pbranchblock); - } - - break; - } - - jNO_DEFAULT; - } - } - - return recVUBlocks[s_vu][startpc/8].pblock; -} - -static void SuperVUInitLiveness(VuBaseBlock* pblock) -{ - list::iterator itinst, itnext; - - assert(pblock->insts.size() > 0); - - for (itinst = pblock->insts.begin(); itinst != pblock->insts.end(); ++itinst) - { - - if (itinst->type & INST_DUMMY_) - { - itinst->addvars[0] = itinst->addvars[1] = 0xffffffff; - itinst->livevars[0] = itinst->livevars[1] = 0xffffffff; - itinst->keepvars[0] = itinst->keepvars[1] = 0xffffffff; - itinst->usedvars[0] = itinst->usedvars[1] = 0; - } - else - { - itinst->addvars[0] = itinst->regs[0].VIread | itinst->regs[1].VIread; - itinst->addvars[1] = (itinst->regs[0].VFread0 ? (1 << itinst->regs[0].VFread0) : 0) | - (itinst->regs[0].VFread1 ? (1 << itinst->regs[0].VFread1) : 0) | - (itinst->regs[1].VFread0 ? (1 << itinst->regs[1].VFread0) : 0) | - (itinst->regs[1].VFread1 ? (1 << itinst->regs[1].VFread1) : 0); - - // vf0 is not handled by VFread - if (!itinst->regs[0].VFread0 && (itinst->regs[0].VIread & (1 << REG_VF0_FLAG))) itinst->addvars[1] |= 1; - if (!itinst->regs[1].VFread0 && (itinst->regs[1].VIread & (1 << REG_VF0_FLAG))) itinst->addvars[1] |= 1; - if (!itinst->regs[0].VFread1 && (itinst->regs[0].VIread & (1 << REG_VF0_FLAG)) && itinst->regs[0].VFr1xyzw != 0xff) itinst->addvars[1] |= 1; - if (!itinst->regs[1].VFread1 && (itinst->regs[1].VIread & (1 << REG_VF0_FLAG)) && itinst->regs[1].VFr1xyzw != 0xff) itinst->addvars[1] |= 1; - - - u32 vfwrite = 0; - if (itinst->regs[0].VFwrite != 0) - { - if (itinst->regs[0].VFwxyzw != 0xf) itinst->addvars[1] |= 1 << itinst->regs[0].VFwrite; - else vfwrite |= 1 << itinst->regs[0].VFwrite; - } - if (itinst->regs[1].VFwrite != 0) - { - if (itinst->regs[1].VFwxyzw != 0xf) itinst->addvars[1] |= 1 << itinst->regs[1].VFwrite; - else vfwrite |= 1 << itinst->regs[1].VFwrite; - } - if ((itinst->regs[1].VIwrite & (1 << REG_ACC_FLAG)) && itinst->regs[1].VFwxyzw != 0xf) - itinst->addvars[1] |= 1 << REG_ACC_FLAG; - - u32 viwrite = (itinst->regs[0].VIwrite | itinst->regs[1].VIwrite); - - itinst->usedvars[0] = itinst->addvars[0] | viwrite; - itinst->usedvars[1] = itinst->addvars[1] | vfwrite; - -// itinst->addvars[0] &= ~viwrite; -// itinst->addvars[1] &= ~vfwrite; - itinst->keepvars[0] = ~viwrite; - itinst->keepvars[1] = ~vfwrite; - } - } - - itinst = --pblock->insts.end(); - while (itinst != pblock->insts.begin()) - { - itnext = itinst; - --itnext; - - itnext->usedvars[0] |= itinst->usedvars[0]; - itnext->usedvars[1] |= itinst->usedvars[1]; - - itinst = itnext; - } -} - -u32 COMPUTE_LIVE(u32 R, u32 K, u32 L) -{ - u32 live = R | ((L) & (K)); - // special process mac and status flags - // only propagate liveness if doesn't write to the flag - if (!(L&(1 << REG_STATUS_FLAG)) && !(K&(1 << REG_STATUS_FLAG))) - live &= ~(1 << REG_STATUS_FLAG); - if (!(L&(1 << REG_MAC_FLAG)) && !(K&(1 << REG_MAC_FLAG))) - live &= ~(1 << REG_MAC_FLAG); - return live;//|(1<::reverse_iterator itblock; - list::iterator itinst, itnext; - VuBaseBlock::LISTBLOCKS::iterator itchild; - - u32 livevars[2]; - - do - { - changed = FALSE; - for (itblock = s_listBlocks.rbegin(); itblock != s_listBlocks.rend(); ++itblock) - { - - u32 newlive; - VuBaseBlock* pb = *itblock; - - // the last inst relies on the neighbor's insts - itinst = --pb->insts.end(); - - if (pb->blocks.size() > 0) - { - livevars[0] = 0; - livevars[1] = 0; - for (itchild = pb->blocks.begin(); itchild != pb->blocks.end(); ++itchild) - { - VuInstruction& front = (*itchild)->insts.front(); - livevars[0] |= front.livevars[0]; - livevars[1] |= front.livevars[1]; - } - - newlive = COMPUTE_LIVE(itinst->addvars[0], itinst->keepvars[0], livevars[0]); - - // should propagate status flags whose parent insts are not in this block -// if( itinst->nParentPc >= 0 && (itinst->type & (INST_STATUS_WRITE|INST_MAC_WRITE)) ) -// newlive |= livevars[0]&((1<livevars[0] != newlive) - { - changed = TRUE; - itinst->livevars[0] = newlive; - } - - newlive = COMPUTE_LIVE(itinst->addvars[1], itinst->keepvars[1], livevars[1]); - if (itinst->livevars[1] != newlive) - { - changed = TRUE; - itinst->livevars[1] = newlive; - } - } - - while (itinst != pb->insts.begin()) - { - - itnext = itinst; - --itnext; - - newlive = COMPUTE_LIVE(itnext->addvars[0], itnext->keepvars[0], itinst->livevars[0]); - - // should propagate status flags whose parent insts are not in this block -// if( itnext->nParentPc >= 0 && (itnext->type & (INST_STATUS_WRITE|INST_MAC_WRITE)) && !(itinst->type & (INST_STATUS_WRITE|INST_MAC_WRITE)) ) -// newlive |= itinst->livevars[0]&((1<livevars[0] != newlive) - { - changed = TRUE; - itnext->livevars[0] = newlive; - itnext->livevars[1] = COMPUTE_LIVE(itnext->addvars[1], itnext->keepvars[1], itinst->livevars[1]); - } - else - { - newlive = COMPUTE_LIVE(itnext->addvars[1], itnext->keepvars[1], itinst->livevars[1]); - if (itnext->livevars[1] != newlive) - { - changed = TRUE; - itnext->livevars[1] = newlive; - } - } - - itinst = itnext; - } - -// if( (livevars[0] | itinst->livevars[0]) != itinst->livevars[0] ) { -// changed = TRUE; -// itinst->livevars[0] |= livevars[0]; -// } -// if( (livevars[1] | itinst->livevars[1]) != itinst->livevars[1] ) { -// changed = TRUE; -// itinst->livevars[1] |= livevars[1]; -// } -// -// while( itinst != pb->insts.begin() ) { -// -// itnext = itinst; --itnext; -// if( (itnext->livevars[0] | (itinst->livevars[0] & itnext->keepvars[0])) != itnext->livevars[0] ) { -// changed = TRUE; -// itnext->livevars[0] |= itinst->livevars[0] & itnext->keepvars[0]; -// itnext->livevars[1] |= itinst->livevars[1] & itnext->keepvars[1]; -// } -// else if( (itnext->livevars[1] | (itinst->livevars[1] & itnext->keepvars[1])) != itnext->livevars[1] ) { -// changed = TRUE; -// itnext->livevars[1] |= itinst->livevars[1] & itnext->keepvars[1]; -// } -// -// itinst = itnext; -// } - } - - } - while (changed); -} - -static void SuperVUEliminateDeadCode() -{ - list::iterator itblock; - VuBaseBlock::LISTBLOCKS::iterator itchild; - list::iterator itinst, itnext; - list listParents; - list::iterator itparent; - - for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) - { - -#ifdef PCSX2_DEBUG - u32 startpc = (*itblock)->startpc; - u32 curpc = startpc; -#endif - - itnext = (*itblock)->insts.begin(); - itinst = itnext++; - while (itnext != (*itblock)->insts.end()) - { - if (itinst->type & (INST_CLIP_WRITE | INST_MAC_WRITE | INST_STATUS_WRITE)) - { - u32 live0 = itnext->livevars[0]; - if (itinst->nParentPc >= 0 && itnext->nParentPc >= 0 && itinst->nParentPc != itnext->nParentPc) // superman returns - { - // take the live vars from the next next inst - list::iterator itnextnext = itnext; - ++itnextnext; - if (itnextnext != (*itblock)->insts.end()) - { - live0 = itnextnext->livevars[0]; - } - } - - itinst->regs[0].VIwrite &= live0; - itinst->regs[1].VIwrite &= live0; - - u32 viwrite = itinst->regs[0].VIwrite | itinst->regs[1].VIwrite; - - (*itblock)->GetInstsAtPc(itinst->nParentPc, listParents); - int removetype = 0; - - for(itparent = listParents.begin(); itparent != listParents.end(); itparent++) - { - VuInstruction* parent = *itparent; - - if (viwrite & (1 << REG_CLIP_FLAG)) - { - parent->regs[0].VIwrite |= (itinst->regs[0].VIwrite & (1 << REG_CLIP_FLAG)); - parent->regs[1].VIwrite |= (itinst->regs[1].VIwrite & (1 << REG_CLIP_FLAG)); - } - else - removetype |= INST_CLIP_WRITE; - - if (parent->info.macflag && (itinst->type & INST_MAC_WRITE)) - { - if (!(viwrite&(1 << REG_MAC_FLAG))) - { - //parent->info.macflag = 0; - // parent->regs[0].VIwrite &= ~(1<regs[1].VIwrite &= ~(1<regs[0].VIwrite & (1 << REG_MAC_FLAG)) && !(parent->regs[1].VIwrite & (1 << REG_MAC_FLAG))); -#endif - // if VUPIPE_FMAC and destination is vf00, probably need to keep the mac flag - if (parent->regs[1].pipe == VUPIPE_FMAC && (parent->regs[1].VFwrite == 0 && !(parent->regs[1].VIwrite&(1 << REG_ACC_FLAG)))) - { - parent->regs[0].VIwrite |= ((1 << REG_MAC_FLAG)); - parent->regs[1].VIwrite |= ((1 << REG_MAC_FLAG)); - } - else - removetype |= INST_MAC_WRITE; - } - else - { - parent->regs[0].VIwrite |= (itinst->regs[0].VIwrite & (1 << REG_MAC_FLAG)); - parent->regs[1].VIwrite |= (itinst->regs[1].VIwrite & (1 << REG_MAC_FLAG)); - } - } - else removetype |= INST_MAC_WRITE; - - if (parent->info.statusflag && (itinst->type & INST_STATUS_WRITE)) - { - if (!(viwrite&(1 << REG_STATUS_FLAG))) - { - //parent->info.statusflag = 0; - // parent->regs[0].VIwrite &= ~(1<regs[1].VIwrite &= ~(1<regs[0].VIwrite & (1 << REG_STATUS_FLAG)) && !(parent->regs[1].VIwrite & (1 << REG_STATUS_FLAG))); -#endif - if (parent->regs[1].pipe == VUPIPE_FMAC && (parent->regs[1].VFwrite == 0 && !(parent->regs[1].VIwrite&(1 << REG_ACC_FLAG)))) - { - parent->regs[0].VIwrite |= ((1 << REG_STATUS_FLAG)); - parent->regs[1].VIwrite |= ((1 << REG_STATUS_FLAG)); - } - else - removetype |= INST_STATUS_WRITE; - } - else - { - parent->regs[0].VIwrite |= (itinst->regs[0].VIwrite & (1 << REG_STATUS_FLAG)); - parent->regs[1].VIwrite |= (itinst->regs[1].VIwrite & (1 << REG_STATUS_FLAG)); - } - } - else removetype |= INST_STATUS_WRITE; - } - - itinst->type &= ~removetype; - if (itinst->type == 0) - { - itnext = (*itblock)->insts.erase(itinst); - itinst = itnext++; - continue; - } - } -#ifdef PCSX2_DEBUG - else - { - curpc += 8; - } -#endif - itinst = itnext; - ++itnext; - } - - if (itinst->type & INST_DUMMY) - { - // last inst with the children - u32 mask = 0; - for (itchild = (*itblock)->blocks.begin(); itchild != (*itblock)->blocks.end(); ++itchild) - { - mask |= (*itchild)->insts.front().livevars[0]; - } - itinst->regs[0].VIwrite &= mask; - itinst->regs[1].VIwrite &= mask; - u32 viwrite = itinst->regs[0].VIwrite | itinst->regs[1].VIwrite; - - if (itinst->nParentPc >= 0) - { - - (*itblock)->GetInstsAtPc(itinst->nParentPc, listParents); - int removetype = 0; - - for(itparent = listParents.begin(); itparent != listParents.end(); itparent++) - { - VuInstruction* parent = *itparent; - - if (viwrite & (1 << REG_CLIP_FLAG)) - { - parent->regs[0].VIwrite |= (itinst->regs[0].VIwrite & (1 << REG_CLIP_FLAG)); - parent->regs[1].VIwrite |= (itinst->regs[1].VIwrite & (1 << REG_CLIP_FLAG)); - } - else removetype |= INST_CLIP_WRITE; - - if (parent->info.macflag && (itinst->type & INST_MAC_WRITE)) - { - if (!(viwrite&(1 << REG_MAC_FLAG))) - { - //parent->info.macflag = 0; -#ifndef SUPERVU_WRITEBACKS - assert(!(parent->regs[0].VIwrite & (1 << REG_MAC_FLAG)) && !(parent->regs[1].VIwrite & (1 << REG_MAC_FLAG))); -#endif - removetype |= INST_MAC_WRITE; - } - else - { - parent->regs[0].VIwrite |= (itinst->regs[0].VIwrite & (1 << REG_MAC_FLAG)); - parent->regs[1].VIwrite |= (itinst->regs[1].VIwrite & (1 << REG_MAC_FLAG)); - } - } - else removetype |= INST_MAC_WRITE; - - if (parent->info.statusflag && (itinst->type & INST_STATUS_WRITE)) - { - if (!(viwrite&(1 << REG_STATUS_FLAG))) - { - //parent->info.statusflag = 0; -#ifndef SUPERVU_WRITEBACKS - assert(!(parent->regs[0].VIwrite & (1 << REG_STATUS_FLAG)) && !(parent->regs[1].VIwrite & (1 << REG_STATUS_FLAG))); -#endif - removetype |= INST_STATUS_WRITE; - } - else - { - parent->regs[0].VIwrite |= (itinst->regs[0].VIwrite & (1 << REG_STATUS_FLAG)); - parent->regs[1].VIwrite |= (itinst->regs[1].VIwrite & (1 << REG_STATUS_FLAG)); - } - } - else removetype |= INST_STATUS_WRITE; - } - - itinst->type &= ~removetype; - if (itinst->type == 0) - { - (*itblock)->insts.erase(itinst); - } - } - } - } -} - -void VuBaseBlock::AssignVFRegs() -{ - int i; - VuBaseBlock::LISTBLOCKS::iterator itchild; - list::iterator itblock; - list::iterator itinst, itnext, itinst2; - - // init the start regs - if (type & BLOCKTYPE_ANALYZED) return; // nothing changed - memcpy(xmmregs, startregs, sizeof(xmmregs)); - - if (type & BLOCKTYPE_ANALYZED) - { - // check if changed - for (i = 0; i < iREGCNT_XMM; ++i) - { - if (xmmregs[i].inuse != startregs[i].inuse) - break; - if (xmmregs[i].inuse && (xmmregs[i].reg != startregs[i].reg || xmmregs[i].type != startregs[i].type)) - break; - } - - if (i == iREGCNT_XMM) return; // nothing changed - } - - u8* oldX86 = x86Ptr; - - for(itinst = insts.begin(); itinst != insts.end(); itinst++) - { - - if (itinst->type & INST_DUMMY) continue; - - // reserve, go from upper to lower - int lastwrite = -1; - - for (i = 1; i >= 0; --i) - { - _VURegsNum* regs = itinst->regs + i; - - - // redo the counters so that the proper regs are released - for (int j = 0; j < iREGCNT_XMM; ++j) - { - if (xmmregs[j].inuse) - { - if (xmmregs[j].type == XMMTYPE_VFREG) - { - int count = 0; - itinst2 = itinst; - - if (i) - { - if (itinst2->regs[0].VFread0 == xmmregs[j].reg || itinst2->regs[0].VFread1 == xmmregs[j].reg || itinst2->regs[0].VFwrite == xmmregs[j].reg) - { - itinst2 = insts.end(); - break; - } - else - { - ++count; - ++itinst2; - } - } - - while (itinst2 != insts.end()) - { - if (itinst2->regs[0].VFread0 == xmmregs[j].reg || itinst2->regs[0].VFread1 == xmmregs[j].reg || itinst2->regs[0].VFwrite == xmmregs[j].reg || - itinst2->regs[1].VFread0 == xmmregs[j].reg || itinst2->regs[1].VFread1 == xmmregs[j].reg || itinst2->regs[1].VFwrite == xmmregs[j].reg) - break; - - ++count; - ++itinst2; - } - xmmregs[j].counter = 1000 - count; - } - else - { - assert(xmmregs[j].type == XMMTYPE_ACC); - - int count = 0; - itinst2 = itinst; - - if (i) ++itinst2; // acc isn't used in lower insts - - while (itinst2 != insts.end()) - { - assert(!((itinst2->regs[0].VIread | itinst2->regs[0].VIwrite) & (1 << REG_ACC_FLAG))); - - if ((itinst2->regs[1].VIread | itinst2->regs[1].VIwrite) & (1 << REG_ACC_FLAG)) - break; - - ++count; - ++itinst2; - } - - xmmregs[j].counter = 1000 - count; - } - } - } - - if (regs->VFread0) _addNeededVFtoXMMreg(regs->VFread0); - if (regs->VFread1) _addNeededVFtoXMMreg(regs->VFread1); - if (regs->VFwrite) _addNeededVFtoXMMreg(regs->VFwrite); - if (regs->VIread & (1 << REG_ACC_FLAG)) _addNeededACCtoXMMreg(); - if (regs->VIread & (1 << REG_VF0_FLAG)) _addNeededVFtoXMMreg(0); - - // alloc - itinst->vfread0[i] = itinst->vfread1[i] = itinst->vfwrite[i] = itinst->vfacc[i] = -1; - itinst->vfflush[i] = -1; - - if (regs->VFread0) - itinst->vfread0[i] = _allocVFtoXMMreg(VU, -1, regs->VFread0, 0); - else if (regs->VIread & (1 << REG_VF0_FLAG)) - itinst->vfread0[i] = _allocVFtoXMMreg(VU, -1, 0, 0); - - if (regs->VFread1) - itinst->vfread1[i] = _allocVFtoXMMreg(VU, -1, regs->VFread1, 0); - else if ((regs->VIread & (1 << REG_VF0_FLAG)) && regs->VFr1xyzw != 0xff) - itinst->vfread1[i] = _allocVFtoXMMreg(VU, -1, 0, 0); - - if (regs->VIread & (1 << REG_ACC_FLAG)) itinst->vfacc[i] = _allocACCtoXMMreg(VU, -1, 0); - - int reusereg = -1; // 0 - VFwrite, 1 - VFAcc - - if (regs->VFwrite) - { - assert(!(regs->VIwrite&(1 << REG_ACC_FLAG))); - - if (regs->VFwxyzw == 0xf) - { - itinst->vfwrite[i] = _checkXMMreg(XMMTYPE_VFREG, regs->VFwrite, 0); - if (itinst->vfwrite[i] < 0) reusereg = 0; - } - else - { - itinst->vfwrite[i] = _allocVFtoXMMreg(VU, -1, regs->VFwrite, 0); - } - } - else if (regs->VIwrite & (1 << REG_ACC_FLAG)) - { - - if (regs->VFwxyzw == 0xf) - { - itinst->vfacc[i] = _checkXMMreg(XMMTYPE_ACC, 0, 0); - if (itinst->vfacc[i] < 0) reusereg = 1; - } - else - { - itinst->vfacc[i] = _allocACCtoXMMreg(VU, -1, 0); - } - } - - if (reusereg >= 0) - { - // reuse - itnext = itinst; - itnext++; - - u8 type = reusereg ? XMMTYPE_ACC : XMMTYPE_VFREG; - u8 reg = reusereg ? 0 : regs->VFwrite; - - if (itinst->vfacc[i] >= 0 && lastwrite != itinst->vfacc[i] && - (itnext == insts.end() || ((regs->VIread&(1 << REG_ACC_FLAG)) && (!(itnext->usedvars[0]&(1 << REG_ACC_FLAG)) || !(itnext->livevars[0]&(1 << REG_ACC_FLAG)))))) - { - - assert(reusereg == 0); - if (itnext == insts.end() || (itnext->livevars[0]&(1 << REG_ACC_FLAG))) _freeXMMreg(itinst->vfacc[i]); - xmmregs[itinst->vfacc[i]].inuse = 1; - xmmregs[itinst->vfacc[i]].reg = reg; - xmmregs[itinst->vfacc[i]].type = type; - xmmregs[itinst->vfacc[i]].mode = 0; - itinst->vfwrite[i] = itinst->vfacc[i]; - } - else if (itinst->vfread0[i] >= 0 && lastwrite != itinst->vfread0[i] && - (itnext == insts.end() || (regs->VFread0 > 0 && (!(itnext->usedvars[1]&(1 << regs->VFread0)) || !(itnext->livevars[1]&(1 << regs->VFread0)))))) - { - - if (itnext == insts.end() || (itnext->livevars[1]®s->VFread0)) _freeXMMreg(itinst->vfread0[i]); - - xmmregs[itinst->vfread0[i]].inuse = 1; - xmmregs[itinst->vfread0[i]].reg = reg; - xmmregs[itinst->vfread0[i]].type = type; - xmmregs[itinst->vfread0[i]].mode = 0; - - if (reusereg) - itinst->vfacc[i] = itinst->vfread0[i]; - else - itinst->vfwrite[i] = itinst->vfread0[i]; - } - else if (itinst->vfread1[i] >= 0 && lastwrite != itinst->vfread1[i] && - (itnext == insts.end() || (regs->VFread1 > 0 && (!(itnext->usedvars[1]&(1 << regs->VFread1)) || !(itnext->livevars[1]&(1 << regs->VFread1)))))) - { - - if (itnext == insts.end() || (itnext->livevars[1]®s->VFread1)) _freeXMMreg(itinst->vfread1[i]); - - xmmregs[itinst->vfread1[i]].inuse = 1; - xmmregs[itinst->vfread1[i]].reg = reg; - xmmregs[itinst->vfread1[i]].type = type; - xmmregs[itinst->vfread1[i]].mode = 0; - if (reusereg) - itinst->vfacc[i] = itinst->vfread1[i]; - else - itinst->vfwrite[i] = itinst->vfread1[i]; - } - else - { - if (reusereg) - itinst->vfacc[i] = _allocACCtoXMMreg(VU, -1, 0); - else - itinst->vfwrite[i] = _allocVFtoXMMreg(VU, -1, regs->VFwrite, 0); - } - } - - if (itinst->vfwrite[i] >= 0) lastwrite = itinst->vfwrite[i]; - else if (itinst->vfacc[i] >= 0) lastwrite = itinst->vfacc[i]; - - // always alloc at least 1 temp reg - int free0 = (i || regs->VFwrite || regs->VFread0 || regs->VFread1 || (regs->VIwrite & (1 << REG_ACC_FLAG)) || (regs->VIread & (1 << REG_VF0_FLAG))) - ? _allocTempXMMreg(XMMT_FPS, -1) : -1; - int free1 = 0, free2 = 0; - - if (i == 0 && itinst->vfwrite[1] >= 0 && (itinst->vfread0[0] == itinst->vfwrite[1] || itinst->vfread1[0] == itinst->vfwrite[1])) - { - itinst->vfflush[i] = _allocTempXMMreg(XMMT_FPS, -1); - } - - if (i == 1 && (regs->VIwrite & (1 << REG_CLIP_FLAG))) - { - // CLIP inst, need two extra regs - if (free0 < 0) free0 = _allocTempXMMreg(XMMT_FPS, -1); - - free1 = _allocTempXMMreg(XMMT_FPS, -1); - free2 = _allocTempXMMreg(XMMT_FPS, -1); - _freeXMMreg(free1); - _freeXMMreg(free2); - } - else if (regs->VIwrite & (1 << REG_P)) - { - // EFU inst, need extra reg - free1 = _allocTempXMMreg(XMMT_FPS, -1); - if (free0 == -1) free0 = free1; - _freeXMMreg(free1); - } - - if (itinst->vfflush[i] >= 0) _freeXMMreg(itinst->vfflush[i]); - if (free0 >= 0) _freeXMMreg(free0); - - itinst->vffree[i] = (free0 & 0xf) | (free1 << 8) | (free2 << 16); - if (free0 == -1) itinst->vffree[i] |= VFFREE_INVALID0; - - _clearNeededXMMregs(); - } - } - - assert(x86Ptr == oldX86); - u32 analyzechildren = !(type & BLOCKTYPE_ANALYZED); - type |= BLOCKTYPE_ANALYZED; - - //memset(endregs, 0, sizeof(endregs)); - - if (analyzechildren) - { - for(itchild = blocks.begin(); itchild != blocks.end(); itchild++) - { - (*itchild)->AssignVFRegs(); - } - } -} - -struct MARKOVBLANKET -{ - list parents; - list children; -}; - -static MARKOVBLANKET s_markov; - -void VuBaseBlock::AssignVIRegs(int parent) -{ - const int maxregs = 6; - - if (parent) - { - if ((type&BLOCKTYPE_ANALYZEDPARENT)) - return; - - type |= BLOCKTYPE_ANALYZEDPARENT; - s_markov.parents.push_back(this); - for (LISTBLOCKS::iterator it = blocks.begin(); it != blocks.end(); ++it) - { - (*it)->AssignVIRegs(0); - } - return; - } - - if ((type&BLOCKTYPE_ANALYZED)) - return; - - // child - assert(allocX86Regs == -1); - allocX86Regs = s_vecRegArray.size(); - s_vecRegArray.resize(allocX86Regs + iREGCNT_GPR); - - _x86regs* pregs = &s_vecRegArray[allocX86Regs]; - memset(pregs, 0, sizeof(_x86regs)*iREGCNT_GPR); - - assert(parents.size() > 0); - - list::iterator itparent; - u32 usedvars = insts.front().usedvars[0]; - u32 livevars = insts.front().livevars[0]; - - if (parents.size() > 0) - { - u32 usedvars2 = 0xffffffff; - - for(itparent = parents.begin(); itparent != parents.end(); itparent++) - { - usedvars2 &= (*itparent)->insts.front().usedvars[0]; - } - - usedvars |= usedvars2; - } - - usedvars &= livevars; - - // currently order doesn't matter - int num = 0; - - if (usedvars) - { - for (int i = 1; i < 16; ++i) - { - if (usedvars & (1 << i)) - { - pregs[num].inuse = 1; - pregs[num].reg = i; - - livevars &= ~(1 << i); - - if (++num >= maxregs) break; - } - } - } - - if (num < maxregs) - { - livevars &= ~usedvars; - livevars &= insts.back().usedvars[0]; - - if (livevars) - { - for (int i = 1; i < 16; ++i) - { - if (livevars & (1 << i)) - { - pregs[num].inuse = 1; - pregs[num].reg = i; - - if (++num >= maxregs) break; - } - } - } - } - - s_markov.children.push_back(this); - type |= BLOCKTYPE_ANALYZED; - - for(itparent = parents.begin(); itparent != parents.end(); itparent++) - { - (*itparent)->AssignVIRegs(1); - } -} - -static void SuperVUAssignRegs() -{ - list::iterator itblock, itblock2; - - for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) - { - (*itblock)->type &= ~BLOCKTYPE_ANALYZED; - } - s_listBlocks.front()->AssignVFRegs(); - - // VI assignments, find markov blanket for each node in the graph - // then allocate regs based on the commonly used ones -#ifdef SUPERVU_X86CACHING - for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) - { - (*itblock)->type &= ~(BLOCKTYPE_ANALYZED | BLOCKTYPE_ANALYZEDPARENT); - } - s_vecRegArray.resize(0); - u8 usedregs[16]; - - // note: first block always has to start with no alloc regs - bool bfirst = true; - - for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) - { - - if (!((*itblock)->type & BLOCKTYPE_ANALYZED)) - { - - if ((*itblock)->parents.size() == 0) - { - (*itblock)->type |= BLOCKTYPE_ANALYZED; - bfirst = false; - continue; - } - - s_markov.children.clear(); - s_markov.parents.clear(); - (*itblock)->AssignVIRegs(0); - - // assign the regs - int regid = s_vecRegArray.size(); - s_vecRegArray.resize(regid + iREGCNT_GPR); - - _x86regs* mergedx86 = &s_vecRegArray[regid]; - memset(mergedx86, 0, sizeof(_x86regs)*iREGCNT_GPR); - - if (!bfirst) - { - *(u32*)usedregs = *((u32*)usedregs + 1) = *((u32*)usedregs + 2) = *((u32*)usedregs + 3) = 0; - - for(itblock2 = s_markov.children.begin(); itblock2 != s_markov.children.end(); itblock2++) - { - assert((*itblock2)->allocX86Regs >= 0); - _x86regs* pregs = &s_vecRegArray[(*itblock2)->allocX86Regs]; - for (int i = 0; i < iREGCNT_GPR; ++i) - { - if (pregs[i].inuse && pregs[i].reg < 16) - { - //assert( pregs[i].reg < 16); - usedregs[pregs[i].reg]++; - } - } - } - - int num = 1; - for (int i = 0; i < 16; ++i) - { - if (usedregs[i] == s_markov.children.size()) - { - // use - mergedx86[num].inuse = 1; - mergedx86[num].reg = i; - mergedx86[num].type = (s_vu ? X86TYPE_VU1 : 0) | X86TYPE_VI; - mergedx86[num].mode = MODE_READ; - if (++num >= iREGCNT_GPR) - break; - if (num == ESP) - ++num; - } - } - - for(itblock2 = s_markov.children.begin(); itblock2 != s_markov.children.end(); itblock2++) - { - assert((*itblock2)->nStartx86 == -1); - (*itblock2)->nStartx86 = regid; - } - - for(itblock2 = s_markov.parents.begin(); itblock2 != s_markov.parents.end(); itblock2++) - { - assert((*itblock2)->nEndx86 == -1); - (*itblock2)->nEndx86 = regid; - } - } - - bfirst = false; - } - } -#endif -} - -////////////////// -// Recompilation -////////////////// - -// cycles in which the last Q,P regs were finished (written to VU->VI[]) -// the write occurs before the instruction is executed at that cycle -// compare with s_TotalVUCycles -// if less than 0, already flushed -int s_writeQ, s_writeP; - -// declare the saved registers -uptr s_vu1esp, s_callstack;//, s_vu1esp -uptr s_vu1ebp, s_vuebx, s_vuedi, s_vu1esi; - -static int s_recWriteQ, s_recWriteP; // wait times during recompilation -static int s_needFlush; // first bit - Q, second bit - P, third bit - Q has been written, fourth bit - P has been written - -static int s_JumpX86; -static int s_ScheduleXGKICK = 0, s_XGKICKReg = -1; - -void recVUMI_XGKICK_(VURegs *VU); - -void SuperVUCleanupProgram(u32 startpc, int vuindex) -{ -#ifdef SUPERVU_COUNT - QueryPerformanceCounter(&svufinal); - svutime += (u32)(svufinal.QuadPart - svubase.QuadPart); -#endif - - assert(s_vu1esp == 0); - - VU = vuindex ? &VU1 : &VU0; - VU->cycle += s_TotalVUCycles; - - //VU cycle stealing hack, 3000 cycle maximum so it doesn't get out of hand - if (s_TotalVUCycles < 3000) - cpuRegs.cycle += s_TotalVUCycles * EmuConfig.Speedhacks.VUCycleSteal; - else - cpuRegs.cycle += 3000 * EmuConfig.Speedhacks.VUCycleSteal; - - if ((int)s_writeQ > 0) VU->VI[REG_Q] = VU->q; - if ((int)s_writeP > 0) - { - assert(VU == &VU1); - VU1.VI[REG_P] = VU1.p; // only VU1 - } - - //memset(recVUStack, 0, SUPERVU_STACKSIZE * 4); - - // Could clear allocation info to prevent possibly bad data being used in other parts of pcsx2; - // not doing this because it's slow and not needed (rama) - // _initXMMregs(); - // _initMMXregs(); - // _initX86regs(); -} - -#if defined(_MSC_VER) - -// entry point of all vu programs from emulator calls -__declspec(naked) void SuperVUExecuteProgram(u32 startpc, int vuindex) -{ - __asm - { - mov eax, dword ptr [esp] - mov s_TotalVUCycles, 0 // necessary to be here! - add esp, 4 - mov s_callstack, eax - call SuperVUGetProgram - - // save cpu state - mov s_vu1ebp, ebp - mov s_vu1esi, esi // have to save even in Release - mov s_vuedi, edi // have to save even in Release - mov s_vuebx, ebx - } -#ifdef PCSX2_DEBUG - __asm - { - mov s_vu1esp, esp - } -#endif - - __asm - { - //stmxcsr s_ssecsr - ldmxcsr g_sseVUMXCSR - - // init vars - mov s_writeQ, 0xffffffff - mov s_writeP, 0xffffffff - - jmp eax - } -} - -// exit point of all vu programs -__declspec(naked) static void SuperVUEndProgram() -{ - __asm - { - // restore cpu state - ldmxcsr g_sseMXCSR - - mov ebp, s_vu1ebp - mov esi, s_vu1esi - mov edi, s_vuedi - mov ebx, s_vuebx - } - -#ifdef PCSX2_DEBUG - __asm - { - sub s_vu1esp, esp - } -#endif - - __asm - { - call SuperVUCleanupProgram - jmp s_callstack // so returns correctly - } -} - -#endif - -// Flushes P/Q regs -void SuperVUFlush(int p, int wait) -{ - u8* pjmp[3]; - if (!(s_needFlush&(1 << p))) return; - - int recwait = p ? s_recWriteP : s_recWriteQ; - if (!wait && s_pCurInst->info.cycle < recwait) return; - - if (recwait == 0) - { - // write didn't happen this block - MOV32MtoR(EAX, p ? (uptr)&s_writeP : (uptr)&s_writeQ); - OR32RtoR(EAX, EAX); - pjmp[0] = JS8(0); - - if (s_pCurInst->info.cycle) SUB32ItoR(EAX, s_pCurInst->info.cycle); - - // if writeQ <= total+offset - if (!wait) // only write back if time is up - { - CMP32MtoR(EAX, (uptr)&s_TotalVUCycles); - pjmp[1] = JG8(0); - } - else - { - // add (writeQ-total-offset) to s_TotalVUCycles - // necessary? - CMP32MtoR(EAX, (uptr)&s_TotalVUCycles); - pjmp[2] = JLE8(0); - MOV32RtoM((uptr)&s_TotalVUCycles, EAX); - x86SetJ8(pjmp[2]); - } - } - else if (wait && s_pCurInst->info.cycle < recwait) - { - ADD32ItoM((uptr)&s_TotalVUCycles, recwait); - } - - MOV32MtoR(EAX, SuperVUGetVIAddr(p ? REG_P : REG_Q, 0)); - MOV32ItoM(p ? (uptr)&s_writeP : (uptr)&s_writeQ, 0x80000000); - MOV32RtoM(SuperVUGetVIAddr(p ? REG_P : REG_Q, 1), EAX); - - if (recwait == 0) - { - if (!wait) x86SetJ8(pjmp[1]); - x86SetJ8(pjmp[0]); - } - - if (wait || (!p && recwait == 0 && s_pCurInst->info.cycle >= 12) || (!p && recwait > 0 && s_pCurInst->info.cycle >= recwait)) - s_needFlush &= ~(1 << p); -} - -// executed only once per program -static u32* SuperVUStaticAlloc(u32 size) -{ - assert(recVUStackPtr + size <= recVUStack + SUPERVU_STACKSIZE); - // always zero - if (size == 4) *(u32*)recVUStackPtr = 0; - else memset(recVUStackPtr, 0, size); - recVUStackPtr += size; - return (u32*)(recVUStackPtr - size); -} - -static void SuperVURecompile() -{ - // save cpu state - recVUStackPtr = recVUStack; - - _initXMMregs(); - - list::iterator itblock; - - for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) - { - (*itblock)->type &= ~BLOCKTYPE_ANALYZED; - } - - s_listBlocks.front()->Recompile(); - - // make sure everything compiled - for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) - { - assert(((*itblock)->type & BLOCKTYPE_ANALYZED) && (*itblock)->pcode != NULL); - } - - // link all blocks - for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) - { - VuBaseBlock::LISTBLOCKS::iterator itchild; - - assert((*itblock)->blocks.size() <= ArraySize((*itblock)->pChildJumps)); - - int i = 0; - for(itchild = (*itblock)->blocks.begin(); itchild != (*itblock)->blocks.end(); itchild++) - { - - if ((u32)(uptr)(*itblock)->pChildJumps[i] == 0xffffffff) - continue; - - if ((*itblock)->pChildJumps[i] == NULL) - { - VuBaseBlock* pchild = *itchild; - - if (pchild->type & BLOCKTYPE_HASEOP) - { - assert(pchild->blocks.size() == 0); - - AND32ItoM((uptr)&VU0.VI[ REG_VPU_STAT ].UL, s_vu ? ~0x100 : ~0x001); // E flag - AND32ItoM((uptr)&VU->vifRegs->stat, ~VIF1_STAT_VEW); - - MOV32ItoM((uptr)&VU->VI[REG_TPC], pchild->endpc); - JMP32((uptr)SuperVUEndProgram - ((uptr)x86Ptr + 5)); - } - // only other case is when there are two branches - else - { - assert((*itblock)->insts.back().regs[0].pipe == VUPIPE_BRANCH); - } - - continue; - } - - if ((u32)(uptr)(*itblock)->pChildJumps[i] & 0x80000000) - { - // relative - assert((uptr)(*itblock)->pChildJumps[i] <= 0xffffffff); - (*itblock)->pChildJumps[i] = (u32*)((uptr)(*itblock)->pChildJumps[i] & 0x7fffffff); - *(*itblock)->pChildJumps[i] = (uptr)(*itchild)->pcode - ((uptr)(*itblock)->pChildJumps[i] + 4); - } - else - { - *(*itblock)->pChildJumps[i] = (uptr)(*itchild)->pcode; - } - - ++i; - } - } - - s_pFnHeader->pprogfunc = s_listBlocks.front()->pcode; -} - -// debug - - -u32 s_saveecx, s_saveedx, s_saveebx, s_saveesi, s_saveedi, s_saveebp; -u32 g_curdebugvu; - -//float vuDouble(u32 f); - -#if defined(_MSC_VER) -__declspec(naked) static void svudispfn() -{ - __asm - { - mov g_curdebugvu, eax - mov s_saveecx, ecx - mov s_saveedx, edx - mov s_saveebx, ebx - mov s_saveesi, esi - mov s_saveedi, edi - mov s_saveebp, ebp - } -#else - -void svudispfntemp() -{ -#endif - -#ifdef PCSX2_DEBUG - static u32 i; - - if (((vudump&8) && g_curdebugvu) || ((vudump&0x80) && !g_curdebugvu)) //&& g_vu1lastrec != g_vu1last ) { - { - - if (skipparent != g_vu1lastrec) - { - for (i = 0; i < ArraySize(badaddrs); ++i) - { - if (s_svulast == badaddrs[i][1] && g_vu1lastrec == badaddrs[i][0]) - break; - } - - if (i == ArraySize(badaddrs)) - { - //static int curesp; - //__asm mov curesp, esp - //Console::WriteLn("tVU: %x %x %x", s_svulast, s_vucount, s_vufnheader); - if (g_curdebugvu) iDumpVU1Registers(); - else iDumpVU0Registers(); - s_vucount++; - } - } - - g_vu1lastrec = s_svulast; - } -#endif - -#if defined(_MSC_VER) - __asm - { - mov ecx, s_saveecx - mov edx, s_saveedx - mov ebx, s_saveebx - mov esi, s_saveesi - mov edi, s_saveedi - mov ebp, s_saveebp - ret - } -#endif -} - -// frees all regs taking into account the livevars -void SuperVUFreeXMMregs(u32* livevars) -{ - for (int i = 0; i < iREGCNT_XMM; ++i) - { - if (xmmregs[i].inuse) - { - // same reg - if ((xmmregs[i].mode & MODE_WRITE)) - { - -#ifdef SUPERVU_INTERCACHING - if (xmmregs[i].type == XMMTYPE_VFREG) - { - if (!(livevars[1] & (1 << xmmregs[i].reg))) continue; - } - else if (xmmregs[i].type == XMMTYPE_ACC) - { - if (!(livevars[0] & (1 << REG_ACC_FLAG))) continue; - } -#endif - - if (xmmregs[i].mode & MODE_VUXYZ) - { - // ALWAYS update - u32 addr = xmmregs[i].type == XMMTYPE_VFREG ? (uptr) & VU->VF[xmmregs[i].reg] : (uptr) & VU->ACC; - - if (xmmregs[i].mode & MODE_VUZ) - { - SSE_MOVHPS_XMM_to_M64(addr, (x86SSERegType)i); - SSE_SHUFPS_M128_to_XMM((x86SSERegType)i, addr, 0xc4); - } - else - { - SSE_MOVHPS_M64_to_XMM((x86SSERegType)i, addr + 8); - } - - xmmregs[i].mode &= ~MODE_VUXYZ; - } - - _freeXMMreg(i); - } - } - } - - //_freeXMMregs(); -} - -void SuperVUTestVU0Condition(u32 incstack) -{ - if (s_vu && !SUPERVU_CHECKCONDITION) return; // vu0 only - - CMP32ItoM((uptr)&s_TotalVUCycles, 512); // sometimes games spin on vu0, so be careful with this value - // woody hangs if too high - - if (incstack) - { - u8* ptr = JB8(0); - - ADD32ItoR(ESP, incstack); - //CALLFunc((u32)timeout); - JMP32((uptr)SuperVUEndProgram - ((uptr)x86Ptr + 5)); - - x86SetJ8(ptr); - } - else JAE32((uptr)SuperVUEndProgram - ((uptr)x86Ptr + 6)); -} - -void VuBaseBlock::Recompile() -{ - if (type & BLOCKTYPE_ANALYZED) return; - - x86Align(16); - pcode = x86Ptr; - -#ifdef PCSX2_DEBUG - MOV32ItoM((uptr)&s_vufnheader, s_pFnHeader->startpc); - MOV32ItoM((uptr)&VU->VI[REG_TPC], startpc); - MOV32ItoM((uptr)&s_svulast, startpc); - - list::iterator itparent; - for (itparent = parents.begin(); itparent != parents.end(); ++itparent) - { - if ((*itparent)->blocks.size() == 1 && (*itparent)->blocks.front()->startpc == startpc && - ((*itparent)->insts.size() < 2 || (----(*itparent)->insts.end())->regs[0].pipe != VUPIPE_BRANCH)) - { - MOV32ItoM((uptr)&skipparent, (*itparent)->startpc); - break; - } - } - - if (itparent == parents.end()) MOV32ItoM((uptr)&skipparent, -1); - - MOV32ItoR(EAX, s_vu); - CALLFunc((uptr)svudispfn); -#endif - - s_pCurBlock = this; - s_needFlush = 3; - pc = startpc; - branch = 0; - s_recWriteQ = s_recWriteP = 0; - s_XGKICKReg = -1; - s_ScheduleXGKICK = 0; - - s_ClipRead = s_PrevClipWrite = (uptr) & VU->VI[REG_CLIP_FLAG]; - s_StatusRead = s_PrevStatusWrite = (uptr) & VU->VI[REG_STATUS_FLAG]; - s_MACRead = s_PrevMACWrite = (uptr) & VU->VI[REG_MAC_FLAG]; - s_PrevIWrite = (uptr) & VU->VI[REG_I]; - s_JumpX86 = 0; - s_UnconditionalDelay = 0; - - memcpy(xmmregs, startregs, sizeof(xmmregs)); -#ifdef SUPERVU_X86CACHING - if (nStartx86 >= 0) - memcpy(x86regs, &s_vecRegArray[nStartx86], sizeof(x86regs)); - else - _initX86regs(); -#else - _initX86regs(); -#endif - - list::iterator itinst; - for(itinst = insts.begin(); itinst != insts.end(); itinst++) - { - s_pCurInst = &(*itinst); - if (s_JumpX86 > 0) - { - if (!x86regs[s_JumpX86].inuse) - { - // load - s_JumpX86 = _allocX86reg(-1, X86TYPE_VUJUMP, 0, MODE_READ); - } - x86regs[s_JumpX86].needed = 1; - } - - if (s_ScheduleXGKICK && s_XGKICKReg > 0) - { - assert(x86regs[s_XGKICKReg].inuse); - x86regs[s_XGKICKReg].needed = 1; - } - itinst->Recompile(itinst, vuxyz); - - if (s_ScheduleXGKICK > 0) - { - if (s_ScheduleXGKICK-- == 1) - { - recVUMI_XGKICK_(VU); - } - } - } - assert(pc == endpc); - assert(s_ScheduleXGKICK == 0); - - // flush flags - if (s_PrevClipWrite != (uptr)&VU->VI[REG_CLIP_FLAG]) - { - MOV32MtoR(EAX, s_PrevClipWrite); - MOV32RtoM((uptr)&VU->VI[REG_CLIP_FLAG], EAX); - } - if (s_PrevStatusWrite != (uptr)&VU->VI[REG_STATUS_FLAG]) - { - MOV32MtoR(EAX, s_PrevStatusWrite); - MOV32RtoM((uptr)&VU->VI[REG_STATUS_FLAG], EAX); - } - if (s_PrevMACWrite != (uptr)&VU->VI[REG_MAC_FLAG]) - { - MOV32MtoR(EAX, s_PrevMACWrite); - MOV32RtoM((uptr)&VU->VI[REG_MAC_FLAG], EAX); - } -// if( s_StatusRead != (uptr)&VU->VI[REG_STATUS_FLAG] ) { -// // only lower 8 bits valid! -// MOVZX32M8toR(EAX, s_StatusRead); -// MOV32RtoM((uptr)&VU->VI[REG_STATUS_FLAG], EAX); -// } -// if( s_MACRead != (uptr)&VU->VI[REG_MAC_FLAG] ) { -// // only lower 8 bits valid! -// MOVZX32M8toR(EAX, s_MACRead); -// MOV32RtoM((uptr)&VU->VI[REG_MAC_FLAG], EAX); -// } - if (s_PrevIWrite != (uptr)&VU->VI[REG_I]) - { - MOV32ItoM((uptr)&VU->VI[REG_I], *(u32*)s_PrevIWrite); // never changes - } - - ADD32ItoM((uptr)&s_TotalVUCycles, cycles); - - // compute branches, jumps, eop - if (type & BLOCKTYPE_HASEOP) - { - // end - _freeXMMregs(); - _freeX86regs(); - AND32ItoM((uptr)&VU0.VI[ REG_VPU_STAT ].UL, s_vu ? ~0x100 : ~0x001); // E flag - AND32ItoM((uptr)&VU->vifRegs->stat, ~VIF1_STAT_VEW); - - if (!branch) MOV32ItoM((uptr)&VU->VI[REG_TPC], endpc); - - JMP32((uptr)SuperVUEndProgram - ((uptr)x86Ptr + 5)); - } - else - { - - u32 livevars[2] = {0}; - - list::iterator lastinst = GetInstIterAtPc(endpc - 8); - lastinst++; - - if (lastinst != insts.end()) - { - livevars[0] = lastinst->livevars[0]; - livevars[1] = lastinst->livevars[1]; - } - else - { - // take from children - if (blocks.size() > 0) - { - LISTBLOCKS::iterator itchild; - for(itchild = blocks.begin(); itchild != blocks.end(); itchild++) - { - livevars[0] |= (*itchild)->insts.front().livevars[0]; - livevars[1] |= (*itchild)->insts.front().livevars[1]; - } - } - else - { - livevars[0] = ~0; - livevars[1] = ~0; - } - } - - SuperVUFreeXMMregs(livevars); - - // get rid of any writes, otherwise _freeX86regs will write - x86regs[s_JumpX86].mode &= ~MODE_WRITE; - - if (branch == 1) - { - if (!x86regs[s_JumpX86].inuse) - { - assert(x86regs[s_JumpX86].type == X86TYPE_VUJUMP); - s_JumpX86 = 0xffffffff; // notify to jump from g_recWriteback - } - } - - // align VI regs -#ifdef SUPERVU_X86CACHING - if (nEndx86 >= 0) - { - _x86regs* endx86 = &s_vecRegArray[nEndx86]; - for (int i = 0; i < iREGCNT_GPR; ++i) - { - if (endx86[i].inuse) - { - - if (s_JumpX86 == i && x86regs[s_JumpX86].inuse) - { - x86regs[s_JumpX86].inuse = 0; - x86regs[EAX].inuse = 1; - MOV32RtoR(EAX, s_JumpX86); - s_JumpX86 = EAX; - } - - if (x86regs[i].inuse) - { - if (x86regs[i].type == endx86[i].type && x86regs[i].reg == endx86[i].reg) - { - _freeX86reg(i); - // will continue to use it - continue; - } - -#ifdef SUPERVU_INTERCACHING - if (x86regs[i].type == (X86TYPE_VI | (s_vu ? X86TYPE_VU1 : 0))) - { - if (livevars[0] & (1 << x86regs[i].reg)) - _freeX86reg(i); - else - x86regs[i].inuse = 0; - } - else -#endif - { - _freeX86reg(i); - } - } - - // realloc - _allocX86reg(i, endx86[i].type, endx86[i].reg, MODE_READ); - if (x86regs[i].mode & MODE_WRITE) - { - _freeX86reg(i); - x86regs[i].inuse = 1; - } - } - else _freeX86reg(i); - } - } - else _freeX86regs(); -#else - _freeX86regs(); -#endif - - // store the last block executed - MOV32ItoM((uptr)&g_nLastBlockExecuted, s_pCurBlock->startpc); - - switch (branch) - { - case 1: // branch, esi has new prog - - SuperVUTestVU0Condition(0); - - if (s_JumpX86 == 0xffffffff) - JMP32M((uptr)&g_recWriteback); - else - JMPR(s_JumpX86); - - break; - case 4: // jalr - pChildJumps[0] = (u32*)0xffffffff; - // fall through - - case 0x10: // jump, esi has new vupc - { - _freeXMMregs(); - _freeX86regs(); - - SuperVUTestVU0Condition(8); - - // already onto stack - CALLFunc((uptr)SuperVUGetProgram); - ADD32ItoR(ESP, 8); - JMPR(EAX); - break; - } - - case 0x13: // jr with uncon branch, uncond branch takes precendence (dropship) - { -// s32 delta = (s32)(VU->code & 0x400 ? 0xfffffc00 | (VU->code & 0x3ff) : VU->code & 0x3ff) << 3; -// ADD32ItoRmOffset(ESP, delta, 0); - - ADD32ItoR(ESP, 8); // restore - pChildJumps[0] = (u32*)((uptr)JMP32(0) | 0x80000000); - break; - } - case 0: - case 3: // unconditional branch - pChildJumps[s_UnconditionalDelay] = (u32*)((uptr)JMP32(0) | 0x80000000); - break; - - default: - DevCon::Error("Bad branch %x\n", branch); - assert(0); - break; - } - } - - pendcode = x86Ptr; - type |= BLOCKTYPE_ANALYZED; - - LISTBLOCKS::iterator itchild; - for(itchild = blocks.begin(); itchild != blocks.end(); itchild++) - { - (*itchild)->Recompile(); - } -} - -#define GET_VUXYZMODE(reg) 0//((vuxyz&(1<<(reg)))?MODE_VUXYZ:0) - -int VuInstruction::SetCachedRegs(int upper, u32 vuxyz) -{ - if (vfread0[upper] >= 0) - { - SuperVUFreeXMMreg(vfread0[upper], XMMTYPE_VFREG, regs[upper].VFread0); - _allocVFtoXMMreg(VU, vfread0[upper], regs[upper].VFread0, MODE_READ | GET_VUXYZMODE(regs[upper].VFread0)); - } - if (vfread1[upper] >= 0) - { - SuperVUFreeXMMreg(vfread1[upper], XMMTYPE_VFREG, regs[upper].VFread1); - _allocVFtoXMMreg(VU, vfread1[upper], regs[upper].VFread1, MODE_READ | GET_VUXYZMODE(regs[upper].VFread1)); - } - if (vfacc[upper] >= 0 && (regs[upper].VIread&(1 << REG_ACC_FLAG))) - { - SuperVUFreeXMMreg(vfacc[upper], XMMTYPE_ACC, 0); - _allocACCtoXMMreg(VU, vfacc[upper], MODE_READ); - } - if (vfwrite[upper] >= 0) - { - assert(regs[upper].VFwrite > 0); - SuperVUFreeXMMreg(vfwrite[upper], XMMTYPE_VFREG, regs[upper].VFwrite); - _allocVFtoXMMreg(VU, vfwrite[upper], regs[upper].VFwrite, - MODE_WRITE | (regs[upper].VFwxyzw != 0xf ? MODE_READ : 0) | GET_VUXYZMODE(regs[upper].VFwrite)); - } - if (vfacc[upper] >= 0 && (regs[upper].VIwrite&(1 << REG_ACC_FLAG))) - { - SuperVUFreeXMMreg(vfacc[upper], XMMTYPE_ACC, 0); - _allocACCtoXMMreg(VU, vfacc[upper], MODE_WRITE | (regs[upper].VFwxyzw != 0xf ? MODE_READ : 0)); - } - - int info = PROCESS_VU_SUPER; - if (vfread0[upper] >= 0) info |= PROCESS_EE_SET_S(vfread0[upper]); - if (vfread1[upper] >= 0) info |= PROCESS_EE_SET_T(vfread1[upper]); - if (vfacc[upper] >= 0) info |= PROCESS_VU_SET_ACC(vfacc[upper]); - if (vfwrite[upper] >= 0) - { - if (regs[upper].VFwrite == _Ft_ && vfread1[upper] < 0) - { - info |= PROCESS_EE_SET_T(vfwrite[upper]); - } - else - { - assert(regs[upper].VFwrite == _Fd_); - info |= PROCESS_EE_SET_D(vfwrite[upper]); - } - } - - if (!(vffree[upper]&VFFREE_INVALID0)) - { - SuperVUFreeXMMreg(vffree[upper]&0xf, XMMTYPE_TEMP, 0); - _allocTempXMMreg(XMMT_FPS, vffree[upper]&0xf); - } - info |= PROCESS_VU_SET_TEMP(vffree[upper] & 0xf); - - if (vfflush[upper] >= 0) - { - SuperVUFreeXMMreg(vfflush[upper], XMMTYPE_TEMP, 0); - _allocTempXMMreg(XMMT_FPS, vfflush[upper]); - } - - if (upper && (regs[upper].VIwrite & (1 << REG_CLIP_FLAG))) - { - // CLIP inst, need two extra temp registers, put it EEREC_D and EEREC_ACC - assert(vfwrite[upper] == -1); - SuperVUFreeXMMreg((vffree[upper] >> 8)&0xf, XMMTYPE_TEMP, 0); - _allocTempXMMreg(XMMT_FPS, (vffree[upper] >> 8)&0xf); - info |= PROCESS_EE_SET_D((vffree[upper] >> 8) & 0xf); - - SuperVUFreeXMMreg((vffree[upper] >> 16)&0xf, XMMTYPE_TEMP, 0); - _allocTempXMMreg(XMMT_FPS, (vffree[upper] >> 16)&0xf); - info |= PROCESS_EE_SET_ACC((vffree[upper] >> 16) & 0xf); - - _freeXMMreg((vffree[upper] >> 8)&0xf); // don't need anymore - _freeXMMreg((vffree[upper] >> 16)&0xf); // don't need anymore - } - else if (regs[upper].VIwrite & (1 << REG_P)) - { - SuperVUFreeXMMreg((vffree[upper] >> 8)&0xf, XMMTYPE_TEMP, 0); - _allocTempXMMreg(XMMT_FPS, (vffree[upper] >> 8)&0xf); - info |= PROCESS_EE_SET_D((vffree[upper] >> 8) & 0xf); - _freeXMMreg((vffree[upper] >> 8)&0xf); // don't need anymore - } - - if (vfflush[upper] >= 0) _freeXMMreg(vfflush[upper]); - if (!(vffree[upper]&VFFREE_INVALID0)) - _freeXMMreg(vffree[upper]&0xf); // don't need anymore - - if ((regs[0].VIwrite | regs[1].VIwrite) & ((1 << REG_STATUS_FLAG) | (1 << REG_MAC_FLAG))) - info |= PROCESS_VU_UPDATEFLAGS; - - return info; -} - -void VuInstruction::Recompile(list::iterator& itinst, u32 vuxyz) -{ - //static PCSX2_ALIGNED16(VECTOR _VF); - //static PCSX2_ALIGNED16(VECTOR _VFc); - u32 *ptr; - u8* pjmp; - int vfregstore = 0; - - assert(s_pCurInst == this); - s_WriteToReadQ = 0; - - ptr = (u32*) & VU->Micro[ pc ]; - - if (type & INST_Q_READ) - SuperVUFlush(0, (ptr[0] == 0x800003bf) || !!(regs[0].VIwrite & (1 << REG_Q))); - if (type & INST_P_READ) - SuperVUFlush(1, (ptr[0] == 0x800007bf) || !!(regs[0].VIwrite & (1 << REG_P))); - - if (type & INST_DUMMY) - { - - // find nParentPc - VuInstruction* pparentinst = NULL; - - // if true, will check if parent block was executed before getting the results of the flags (superman returns) - int nParentCheckForExecution = -1; - -// int badaddrs[] = { -// 0x60,0x68,0x70,0x60,0x68,0x70,0x88,0x90,0x98,0x98,0xa8,0xb8,0x88,0x90, -// 0x4a8,0x4a8,0x398,0x3a0,0x3a8,0xa0 -// }; - -#ifdef SUPERVU_PROPAGATEFLAGS - if (nParentPc != -1 && (nParentPc < s_pCurBlock->startpc || nParentPc >= (int)pc)) - { - -// if( !s_vu ) { -// for(int j = 0; j < ARRAYSIZE(badaddrs); ++j) { -// if( badaddrs[j] == nParentPc ) -// goto NoParent; -// } -// } - - list::iterator itblock; - for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) - { - if (nParentPc >= (*itblock)->startpc && nParentPc < (*itblock)->endpc) - { - pparentinst = &(*(*itblock)->GetInstIterAtPc(nParentPc)); - //if( !s_vu ) SysPrintf("%x ", nParentPc); - if (find(s_pCurBlock->parents.begin(), s_pCurBlock->parents.end(), *itblock) != s_pCurBlock->parents.end()) - nParentCheckForExecution = (*itblock)->startpc; - break; - } - } - - assert(pparentinst != NULL); - } -#endif - - if (type & INST_CLIP_WRITE) - { - if (nParentPc < s_pCurBlock->startpc || nParentPc >= (int)pc) - { - - if (!CHECK_VUCLIPFLAGHACK && pparentinst != NULL) - { - - if (nParentCheckForExecution >= 0) - { - if (pparentinst->pClipWrite == 0) - pparentinst->pClipWrite = (uptr)SuperVUStaticAlloc(4); - - if (s_ClipRead == 0) - s_ClipRead = (uptr) & VU->VI[REG_CLIP_FLAG]; - - CMP32ItoM((uptr)&g_nLastBlockExecuted, nParentCheckForExecution); - u8* jptr = JNE8(0); - CMP32ItoM((uptr)&s_ClipRead, (uptr)&VU->VI[REG_CLIP_FLAG]); - u8* jptr2 = JE8(0); - MOV32MtoR(EAX, pparentinst->pClipWrite); - MOV32RtoM(s_ClipRead, EAX); - x86SetJ8(jptr); - x86SetJ8(jptr2); - } - } - else s_ClipRead = (uptr) & VU->VI[REG_CLIP_FLAG]; - } - else - { - s_ClipRead = s_pCurBlock->GetInstIterAtPc(nParentPc)->pClipWrite; - if (s_ClipRead == 0) Console::WriteLn("super ClipRead allocation error!"); - } - } - - // before modifying, check if they will ever be read - if (s_pCurBlock->type & BLOCKTYPE_MACFLAGS) - { - - u8 outofblock = 0; - if (type & INST_STATUS_WRITE) - { - - if (nParentPc < s_pCurBlock->startpc || nParentPc >= (int)pc) - { - - // reading from out of this block, so already flushed to mem - if (pparentinst != NULL) //&& pparentinst->pStatusWrite != NULL ) { - { - - // might not have processed it yet, so reserve a mem loc - if (pparentinst->pStatusWrite == 0) - { - pparentinst->pStatusWrite = (uptr)SuperVUStaticAlloc(4); - //MOV32ItoM(pparentinst->pStatusWrite, 0); - } - -// if( s_pCurBlock->prevFlagsOutOfBlock && s_StatusRead != NULL ) { -// // or instead since don't now which parent we came from -// MOV32MtoR(EAX, pparentinst->pStatusWrite); -// OR32RtoM(s_StatusRead, EAX); -// MOV32ItoM(pparentinst->pStatusWrite, 0); -// } - - if (nParentCheckForExecution >= 0) - { - - // don't now which parent we came from, so have to check -// uptr tempstatus = (uptr)SuperVUStaticAlloc(4); -// if( s_StatusRead != NULL ) -// MOV32MtoR(EAX, s_StatusRead); -// else -// MOV32MtoR(EAX, (uptr)&VU->VI[REG_STATUS_FLAG]); -// s_StatusRead = tempstatus; - - if (s_StatusRead == 0) - s_StatusRead = (uptr) & VU->VI[REG_STATUS_FLAG]; - - CMP32ItoM((uptr)&g_nLastBlockExecuted, nParentCheckForExecution); - u8* jptr = JNE8(0); - MOV32MtoR(EAX, pparentinst->pStatusWrite); - MOV32ItoM(pparentinst->pStatusWrite, 0); - MOV32RtoM(s_StatusRead, EAX); - x86SetJ8(jptr); - } - else - { - uptr tempstatus = (uptr)SuperVUStaticAlloc(4); - MOV32MtoR(EAX, pparentinst->pStatusWrite); - MOV32RtoM(tempstatus, EAX); - MOV32ItoM(pparentinst->pStatusWrite, 0); - s_StatusRead = tempstatus; - } - - outofblock = 2; - } - else - s_StatusRead = (uptr) & VU->VI[REG_STATUS_FLAG]; - } - else - { - s_StatusRead = s_pCurBlock->GetInstIterAtPc(nParentPc)->pStatusWrite; - if (s_StatusRead == 0) Console::WriteLn("super StatusRead allocation error!"); -// if( pc >= (u32)s_pCurBlock->endpc-8 ) { -// // towards the end, so variable might be leaded to another block (silent hill 4) -// uptr tempstatus = (uptr)SuperVUStaticAlloc(4); -// MOV32MtoR(EAX, s_StatusRead); -// MOV32RtoM(tempstatus, EAX); -// MOV32ItoM(s_StatusRead, 0); -// s_StatusRead = tempstatus; -// } - } - } - if (type & INST_MAC_WRITE) - { - - if (nParentPc < s_pCurBlock->startpc || nParentPc >= (int)pc) - { - // reading from out of this block, so already flushed to mem - - if (pparentinst != NULL) //&& pparentinst->pMACWrite != NULL ) { - { - // necessary for (katamari) - // towards the end, so variable might be leaked to another block (silent hill 4) - - // might not have processed it yet, so reserve a mem loc - if (pparentinst->pMACWrite == 0) - { - pparentinst->pMACWrite = (uptr)SuperVUStaticAlloc(4); - //MOV32ItoM(pparentinst->pMACWrite, 0); - } - -// if( s_pCurBlock->prevFlagsOutOfBlock && s_MACRead != NULL ) { -// // or instead since don't now which parent we came from -// MOV32MtoR(EAX, pparentinst->pMACWrite); -// OR32RtoM(s_MACRead, EAX); -// MOV32ItoM(pparentinst->pMACWrite, 0); -// } - if (nParentCheckForExecution >= 0) - { - - // don't now which parent we came from, so have to check -// uptr tempmac = (uptr)SuperVUStaticAlloc(4); -// if( s_MACRead != NULL ) -// MOV32MtoR(EAX, s_MACRead); -// else -// MOV32MtoR(EAX, (uptr)&VU->VI[REG_MAC_FLAG]); -// s_MACRead = tempmac; - - if (s_MACRead == 0) s_MACRead = (uptr) & VU->VI[REG_MAC_FLAG]; - - CMP32ItoM((uptr)&g_nLastBlockExecuted, nParentCheckForExecution); - u8* jptr = JNE8(0); - MOV32MtoR(EAX, pparentinst->pMACWrite); - MOV32ItoM(pparentinst->pMACWrite, 0); - MOV32RtoM(s_MACRead, EAX); - x86SetJ8(jptr); - } - else - { - uptr tempMAC = (uptr)SuperVUStaticAlloc(4); - MOV32MtoR(EAX, pparentinst->pMACWrite); - MOV32RtoM(tempMAC, EAX); - MOV32ItoM(pparentinst->pMACWrite, 0); - s_MACRead = tempMAC; - } - - outofblock = 2; - } - else - s_MACRead = (uptr) & VU->VI[REG_MAC_FLAG]; - -// if( pc >= (u32)s_pCurBlock->endpc-8 ) { -// // towards the end, so variable might be leaked to another block (silent hill 4) -// uptr tempMAC = (uptr)SuperVUStaticAlloc(4); -// MOV32MtoR(EAX, s_MACRead); -// MOV32RtoM(tempMAC, EAX); -// MOV32ItoM(s_MACRead, 0); -// s_MACRead = tempMAC; -// } - } - else - { - s_MACRead = s_pCurBlock->GetInstIterAtPc(nParentPc)->pMACWrite; - } - } - - s_pCurBlock->prevFlagsOutOfBlock = outofblock; - } - else if (pparentinst != NULL) - { - // make sure to reset the mac and status flags! (katamari) - if (pparentinst->pStatusWrite) - MOV32ItoM(pparentinst->pStatusWrite, 0); - if (pparentinst->pMACWrite) - MOV32ItoM(pparentinst->pMACWrite, 0); - } - - assert(s_ClipRead != 0); - assert(s_MACRead != 0); - assert(s_StatusRead != 0); - - return; - } - - s_pCurBlock->prevFlagsOutOfBlock = 0; - - if( IsDebugBuild ) - MOV32ItoR(EAX, pc); - - assert(!(type & (INST_CLIP_WRITE | INST_STATUS_WRITE | INST_MAC_WRITE))); - pc += 8; - - list::const_iterator itinst2; - - if ((regs[0].VIwrite | regs[1].VIwrite) & ((1 << REG_MAC_FLAG) | (1 << REG_STATUS_FLAG))) - { - if (s_pCurBlock->type & BLOCKTYPE_MACFLAGS) - { - if (pMACWrite == 0) - { - pMACWrite = (uptr)SuperVUStaticAlloc(4); - //MOV32ItoM(pMACWrite, 0); - } - if (pStatusWrite == 0) - { - pStatusWrite = (uptr)SuperVUStaticAlloc(4); - //MOV32ItoM(pStatusWrite, 0); - } - } - else - { - assert(s_StatusRead == (uptr)&VU->VI[REG_STATUS_FLAG]); - assert(s_MACRead == (uptr)&VU->VI[REG_MAC_FLAG]); - pMACWrite = s_MACRead; - pStatusWrite = s_StatusRead; - } - } - - if ((pClipWrite == 0) && ((regs[0].VIwrite | regs[1].VIwrite) & (1 << REG_CLIP_FLAG))) - { - pClipWrite = (uptr)SuperVUStaticAlloc(4); - //MOV32ItoM(pClipWrite, 0); - } - -#ifdef SUPERVU_X86CACHING - // redo the counters so that the proper regs are released - for (int j = 0; j < iREGCNT_GPR; ++j) - { - if (x86regs[j].inuse && X86_ISVI(x86regs[j].type)) - { - int count = 0; - itinst2 = itinst; - - while (itinst2 != s_pCurBlock->insts.end()) - { - if ((itinst2->regs[0].VIread | itinst2->regs[0].VIwrite | itinst2->regs[1].VIread | itinst2->regs[1].VIwrite) && (1 << x86regs[j].reg)) - break; - - ++count; - ++itinst2; - } - - x86regs[j].counter = 1000 - count; - } - } -#endif - - if (s_vu == 0 && (ptr[1] & 0x20000000)) // M flag - { - OR8ItoM((uptr)&VU->flags, VUFLAG_MFLAGSET); - } - if (ptr[1] & 0x10000000) // D flag - { - TEST32ItoM((uptr)&VU0.VI[REG_FBRST].UL, s_vu ? 0x400 : 0x004); - u8* ptr = JZ8(0); - OR32ItoM((uptr)&VU0.VI[REG_VPU_STAT].UL, s_vu ? 0x200 : 0x002); - _callFunctionArg1((uptr)hwIntcIrq, MEM_CONSTTAG, s_vu ? INTC_VU1 : INTC_VU0); - x86SetJ8(ptr); - } - if (ptr[1] & 0x08000000) // T flag - { - TEST32ItoM((uptr)&VU0.VI[REG_FBRST].UL, s_vu ? 0x800 : 0x008); - u8* ptr = JZ8(0); - OR32ItoM((uptr)&VU0.VI[REG_VPU_STAT].UL, s_vu ? 0x400 : 0x004); - _callFunctionArg1((uptr)hwIntcIrq, MEM_CONSTTAG, s_vu ? INTC_VU1 : INTC_VU0); - x86SetJ8(ptr); - } - - // check upper flags - if (ptr[1] & 0x80000000) // I flag - { - - assert(!(regs[0].VIwrite & ((1 << REG_Q) | (1 << REG_P)))); - - VU->code = ptr[1]; - s_vuInfo = SetCachedRegs(1, vuxyz); - if (s_JumpX86 > 0) x86regs[s_JumpX86].needed = 1; - if (s_ScheduleXGKICK && s_XGKICKReg > 0) x86regs[s_XGKICKReg].needed = 1; - - recVU_UPPER_OPCODE[ VU->code & 0x3f ](VU, s_vuInfo); - - s_PrevIWrite = (uptr)ptr; - _clearNeededXMMregs(); - _clearNeededX86regs(); - } - else - { - if (regs[0].VIwrite & (1 << REG_Q)) - { - - // search for all the insts between this inst and writeback - itinst2 = itinst; - ++itinst2; - u32 cacheq = (itinst2 == s_pCurBlock->insts.end()); - u32* codeptr2 = ptr + 2; - - while (itinst2 != s_pCurBlock->insts.end()) - { - if (!(itinst2->type & INST_DUMMY) && ((itinst2->regs[0].VIwrite&(1 << REG_Q)) || codeptr2[0] == 0x800003bf)) // waitq, or fdiv inst - { - break; - } - if ((itinst2->type & INST_Q_WRITE) && itinst2->nParentPc == pc - 8) - { - break; - } - if (itinst2->type & INST_Q_READ) - { - cacheq = 1; - break; - } - if (itinst2->type & INST_DUMMY) - { - ++itinst2; - continue; - } - codeptr2 += 2; - ++itinst2; - } - - if (itinst2 == s_pCurBlock->insts.end()) - cacheq = 1; - - int x86temp = -1; - if (cacheq) - x86temp = _allocX86reg(-1, X86TYPE_TEMP, 0, 0); - - // new is written so flush old - // if type & INST_Q_READ, already flushed - if (!(type & INST_Q_READ) && s_recWriteQ == 0) MOV32MtoR(EAX, (uptr)&s_writeQ); - - if (cacheq) - MOV32MtoR(x86temp, (uptr)&s_TotalVUCycles); - - if (!(type & INST_Q_READ)) - { - if (s_recWriteQ == 0) - { - OR32RtoR(EAX, EAX); - pjmp = JS8(0); - MOV32MtoR(EAX, SuperVUGetVIAddr(REG_Q, 0)); - MOV32RtoM(SuperVUGetVIAddr(REG_Q, 1), EAX); - x86SetJ8(pjmp); - } - else if (s_needFlush & 1) - { - MOV32MtoR(EAX, SuperVUGetVIAddr(REG_Q, 0)); - MOV32RtoM(SuperVUGetVIAddr(REG_Q, 1), EAX); - s_needFlush &= ~1; - } - } - - // write new Q - if (cacheq) - { - assert(s_pCurInst->pqcycles > 1); - ADD32ItoR(x86temp, s_pCurInst->info.cycle + s_pCurInst->pqcycles); - MOV32RtoM((uptr)&s_writeQ, x86temp); - s_needFlush |= 1; - } - else - { - // won't be writing back - s_WriteToReadQ = 1; - s_needFlush &= ~1; - MOV32ItoM((uptr)&s_writeQ, 0x80000001); - } - - s_recWriteQ = s_pCurInst->info.cycle + s_pCurInst->pqcycles; - - if (x86temp >= 0) - _freeX86reg(x86temp); - } - - if (regs[0].VIwrite & (1 << REG_P)) - { - int x86temp = _allocX86reg(-1, X86TYPE_TEMP, 0, 0); - - // new is written so flush old - if (!(type & INST_P_READ) && s_recWriteP == 0) - MOV32MtoR(EAX, (uptr)&s_writeP); - MOV32MtoR(x86temp, (uptr)&s_TotalVUCycles); - - if (!(type & INST_P_READ)) - { - if (s_recWriteP == 0) - { - OR32RtoR(EAX, EAX); - pjmp = JS8(0); - MOV32MtoR(EAX, SuperVUGetVIAddr(REG_P, 0)); - MOV32RtoM(SuperVUGetVIAddr(REG_P, 1), EAX); - x86SetJ8(pjmp); - } - else if (s_needFlush & 2) - { - MOV32MtoR(EAX, SuperVUGetVIAddr(REG_P, 0)); - MOV32RtoM(SuperVUGetVIAddr(REG_P, 1), EAX); - s_needFlush &= ~2; - } - } - - // write new P - assert(s_pCurInst->pqcycles > 1); - ADD32ItoR(x86temp, s_pCurInst->info.cycle + s_pCurInst->pqcycles); - MOV32RtoM((uptr)&s_writeP, x86temp); - s_needFlush |= 2; - - s_recWriteP = s_pCurInst->info.cycle + s_pCurInst->pqcycles; - - _freeX86reg(x86temp); - } - - // waitq - if (ptr[0] == 0x800003bf) SuperVUFlush(0, 1); - // waitp - if (ptr[0] == 0x800007bf) SuperVUFlush(1, 1); - -#ifdef PCSX2_DEVBUILD - if (regs[1].VIread & regs[0].VIwrite & ~((1 << REG_Q) | (1 << REG_P) | (1 << REG_VF0_FLAG) | (1 << REG_ACC_FLAG))) - { - Console::Notice("*PCSX2*: Warning, VI write to the same reg %x in both lower/upper cycle %x", regs[1].VIread & regs[0].VIwrite, s_pCurBlock->startpc); - } -#endif - - u32 modewrite = 0; - if (vfwrite[1] >= 0 && xmmregs[vfwrite[1]].inuse && xmmregs[vfwrite[1]].type == XMMTYPE_VFREG && xmmregs[vfwrite[1]].reg == regs[1].VFwrite) - modewrite = xmmregs[vfwrite[1]].mode & MODE_WRITE; - - VU->code = ptr[1]; - s_vuInfo = SetCachedRegs(1, vuxyz); - - if (vfwrite[1] >= 0) - { - assert(regs[1].VFwrite > 0); - - if (vfwrite[0] == vfwrite[1]) - { - //Console::WriteLn("*PCSX2*: Warning, VF write to the same reg in both lower/upper cycle %x", s_pCurBlock->startpc); - } - - if (vfread0[0] == vfwrite[1] || vfread1[0] == vfwrite[1]) - { - assert(regs[0].VFread0 == regs[1].VFwrite || regs[0].VFread1 == regs[1].VFwrite); - assert(vfflush[0] >= 0); - if (modewrite) - { - SSE_MOVAPS_XMM_to_M128((uptr)&VU->VF[regs[1].VFwrite], (x86SSERegType)vfwrite[1]); - } - vfregstore = 1; - } - } - - if (s_JumpX86 > 0) x86regs[s_JumpX86].needed = 1; - if (s_ScheduleXGKICK && s_XGKICKReg > 0) x86regs[s_XGKICKReg].needed = 1; - - recVU_UPPER_OPCODE[ VU->code & 0x3f ](VU, s_vuInfo); - _clearNeededXMMregs(); - _clearNeededX86regs(); - - // necessary because status can be set by both upper and lower - if (regs[1].VIwrite & (1 << REG_STATUS_FLAG)) - { - assert(pStatusWrite != 0); - s_PrevStatusWrite = pStatusWrite; - } - - VU->code = ptr[0]; - s_vuInfo = SetCachedRegs(0, vuxyz); - - if (vfregstore) - { - // load - SSE_MOVAPS_M128_to_XMM(vfflush[0], (uptr)&VU->VF[regs[1].VFwrite]); - - assert(xmmregs[vfwrite[1]].mode & MODE_WRITE); - - // replace with vfflush - if (_Fs_ == regs[1].VFwrite) - { - s_vuInfo &= ~PROCESS_EE_SET_S(0xf); - s_vuInfo |= PROCESS_EE_SET_S(vfflush[0]); - } - if (_Ft_ == regs[1].VFwrite) - { - s_vuInfo &= ~PROCESS_EE_SET_T(0xf); - s_vuInfo |= PROCESS_EE_SET_T(vfflush[0]); - } - - xmmregs[vfflush[0]].mode |= MODE_NOFLUSH | MODE_WRITE; // so that lower inst doesn't flush - } - - // notify vuinsts that upper inst is a fmac - if (regs[1].pipe == VUPIPE_FMAC) - s_vuInfo |= PROCESS_VU_SET_FMAC(); - - if (s_JumpX86 > 0) x86regs[s_JumpX86].needed = 1; - if (s_ScheduleXGKICK && s_XGKICKReg > 0) x86regs[s_XGKICKReg].needed = 1; - -#ifdef SUPERVU_VIBRANCHDELAY - if (type & INST_CACHE_VI) - { - assert(vicached >= 0); - int cachedreg = _allocX86reg(-1, X86TYPE_VI | (s_vu ? X86TYPE_VU1 : 0), vicached, MODE_READ); - MOV32RtoM((uptr)&s_VIBranchDelay, cachedreg); - } -#endif - - // check if inst before branch and the write is the same as the read in the branch (wipeout) -// int oldreg=0; -// if( pc == s_pCurBlock->endpc-16 ) { -// itinst2 = itinst; ++itinst2; -// if( itinst2->regs[0].pipe == VUPIPE_BRANCH && (itinst->regs[0].VIwrite&itinst2->regs[0].VIread) ) { -// -// CALLFunc((u32)branchfn); -// assert( itinst->regs[0].VIwrite & 0xffff ); -// Console::WriteLn("vi write before branch"); -// for(s_CacheVIReg = 0; s_CacheVIReg < 16; ++s_CacheVIReg) { -// if( itinst->regs[0].VIwrite & (1<endpc-8 && s_CacheVIReg >= 0 ) { -// assert( s_CacheVIX86 > 0 && x86regs[s_CacheVIX86].inuse && x86regs[s_CacheVIX86].reg == s_CacheVIReg && x86regs[s_CacheVIX86].type == X86TYPE_VITEMP ); -// -// oldreg = _allocX86reg(-1, X86TYPE_VI|(s_vu?X86TYPE_VU1:0), s_CacheVIReg, MODE_READ); -// x86regs[s_CacheVIX86].needed = 1; -// assert( x86regs[oldreg].mode & MODE_WRITE ); -// -// x86regs[s_CacheVIX86].type = X86TYPE_VI|(s_vu?X86TYPE_VU1:0); -// x86regs[oldreg].type = X86TYPE_VITEMP; -// } - - recVU_LOWER_OPCODE[ VU->code >> 25 ](VU, s_vuInfo); - -// if( pc == s_pCurBlock->endpc-8 && s_CacheVIReg >= 0 ) { -// // revert -// x86regs[s_CacheVIX86].inuse = 0; -// x86regs[oldreg].type = X86TYPE_VI|(s_vu?X86TYPE_VU1:0); -// } - - _clearNeededXMMregs(); - _clearNeededX86regs(); - } - - // clip is always written so ok - if ((regs[0].VIwrite | regs[1].VIwrite) & (1 << REG_CLIP_FLAG)) - { - assert(pClipWrite != 0); - s_PrevClipWrite = pClipWrite; - } - - if ((regs[0].VIwrite | regs[1].VIwrite) & (1 << REG_STATUS_FLAG)) - { - assert(pStatusWrite != 0); - s_PrevStatusWrite = pStatusWrite; - } - - if ((regs[0].VIwrite | regs[1].VIwrite) & (1 << REG_MAC_FLAG)) - { - assert(pMACWrite != 0); - s_PrevMACWrite = pMACWrite; - } -} - -/////////////////////////////////// -// Super VU Recompilation Tables // -/////////////////////////////////// - -void recVUMI_BranchHandle() -{ - int bpc = _recbranchAddr(VU->code); - int curjump = 0; - - if (s_pCurInst->type & INST_BRANCH_DELAY) - { - assert((branch&0x17) != 0x10 && (branch&0x17) != 4); // no jump handlig for now - - if ((branch & 0x7) == 3) - { - // previous was a direct jump - curjump = 1; - } - else if (branch & 1) curjump = 2; - } - - assert(s_JumpX86 > 0); - - if ((s_pCurBlock->type & BLOCKTYPE_HASEOP) || s_vu == 0 || SUPERVU_CHECKCONDITION) - MOV32ItoM(SuperVUGetVIAddr(REG_TPC, 0), bpc); - MOV32ItoR(s_JumpX86, 1); // use 1 to disable optimization to XOR - s_pCurBlock->pChildJumps[curjump] = (u32*)x86Ptr - 1; - - if (!(s_pCurInst->type & INST_BRANCH_DELAY)) - { - j8Ptr[1] = JMP8(0); - x86SetJ8(j8Ptr[ 0 ]); - - if ((s_pCurBlock->type & BLOCKTYPE_HASEOP) || s_vu == 0 || SUPERVU_CHECKCONDITION) - MOV32ItoM(SuperVUGetVIAddr(REG_TPC, 0), pc + 8); - MOV32ItoR(s_JumpX86, 1); // use 1 to disable optimization to XOR - s_pCurBlock->pChildJumps[curjump+1] = (u32*)x86Ptr - 1; - - x86SetJ8(j8Ptr[ 1 ]); - } - else - x86SetJ8(j8Ptr[ 0 ]); - - branch |= 1; -} - -// supervu specific insts -void recVUMI_IBQ_prep() -{ - int isreg, itreg; - - if (_Is_ == 0) - { -#ifdef SUPERVU_VIBRANCHDELAY - if (s_pCurInst->vicached >= 0 && s_pCurInst->vicached == _It_) - { - itreg = -1; - } - else -#endif - { - itreg = _checkX86reg(X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _It_, MODE_READ); - } - - s_JumpX86 = _allocX86reg(-1, X86TYPE_VUJUMP, 0, MODE_WRITE); - - if (itreg >= 0) - { - CMP16ItoR(itreg, 0); - } - else CMP16ItoM(SuperVUGetVIAddr(_It_, 1), 0); - } - else if (_It_ == 0) - { -#ifdef SUPERVU_VIBRANCHDELAY - if (s_pCurInst->vicached >= 0 && s_pCurInst->vicached == _Is_) - { - isreg = -1; - } - else -#endif - { - isreg = _checkX86reg(X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _Is_, MODE_READ); - } - - s_JumpX86 = _allocX86reg(-1, X86TYPE_VUJUMP, 0, MODE_WRITE); - - if (isreg >= 0) - { - CMP16ItoR(isreg, 0); - } - else CMP16ItoM(SuperVUGetVIAddr(_Is_, 1), 0); - - } - else - { - _addNeededX86reg(X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _It_); - -#ifdef SUPERVU_VIBRANCHDELAY - if (s_pCurInst->vicached >= 0 && s_pCurInst->vicached == _Is_) - { - isreg = -1; - } - else -#endif - { - isreg = _checkX86reg(X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _Is_, MODE_READ); - } - -#ifdef SUPERVU_VIBRANCHDELAY - if (s_pCurInst->vicached >= 0 && s_pCurInst->vicached == _It_) - { - itreg = -1; - - if (isreg <= 0) - { - // allocate fsreg - if (s_pCurInst->vicached >= 0 && s_pCurInst->vicached == _Is_) - { - isreg = _allocX86reg(-1, X86TYPE_TEMP, 0, MODE_READ | MODE_WRITE); - MOV32MtoR(isreg, SuperVUGetVIAddr(_Is_, 1)); - } - else - isreg = _allocX86reg(-1, X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _Is_, MODE_READ); - } - } - else -#endif - { - itreg = _checkX86reg(X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _It_, MODE_READ); - } - - s_JumpX86 = _allocX86reg(-1, X86TYPE_VUJUMP, 0, MODE_WRITE); - - if (isreg >= 0) - { - if (itreg >= 0) - { - CMP16RtoR(isreg, itreg); - } - else CMP16MtoR(isreg, SuperVUGetVIAddr(_It_, 1)); - } - else if (itreg >= 0) - { - CMP16MtoR(itreg, SuperVUGetVIAddr(_Is_, 1)); - } - else - { - isreg = _allocX86reg(-1, X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _Is_, MODE_READ); - CMP16MtoR(isreg, SuperVUGetVIAddr(_It_, 1)); - } - } -} - -void recVUMI_IBEQ(VURegs* vuu, s32 info) -{ - recVUMI_IBQ_prep(); - j8Ptr[ 0 ] = JNE8(0); - recVUMI_BranchHandle(); -} - -void recVUMI_IBGEZ(VURegs* vuu, s32 info) -{ - int isreg; - s_JumpX86 = _allocX86reg(-1, X86TYPE_VUJUMP, 0, MODE_WRITE); - -#ifdef SUPERVU_VIBRANCHDELAY - if (s_pCurInst->vicached >= 0 && s_pCurInst->vicached == _Is_) - { - isreg = -1; - } - else -#endif - { - isreg = _checkX86reg(X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _Is_, MODE_READ); - } - - if (isreg >= 0) - { - TEST16RtoR(isreg, isreg); - j8Ptr[ 0 ] = JS8(0); - } - else - { - CMP16ItoM(SuperVUGetVIAddr(_Is_, 1), 0x0); - j8Ptr[ 0 ] = JL8(0); - } - - recVUMI_BranchHandle(); -} - -void recVUMI_IBGTZ(VURegs* vuu, s32 info) -{ - int isreg; - s_JumpX86 = _allocX86reg(-1, X86TYPE_VUJUMP, 0, MODE_WRITE); - -#ifdef SUPERVU_VIBRANCHDELAY - if (s_pCurInst->vicached >= 0 && s_pCurInst->vicached == _Is_) - { - isreg = -1; - } - else -#endif - { - isreg = _checkX86reg(X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _Is_, MODE_READ); - } - - if (isreg >= 0) - { - CMP16ItoR(isreg, 0); - j8Ptr[ 0 ] = JLE8(0); - } - else - { - CMP16ItoM(SuperVUGetVIAddr(_Is_, 1), 0x0); - j8Ptr[ 0 ] = JLE8(0); - } - recVUMI_BranchHandle(); -} - -void recVUMI_IBLEZ(VURegs* vuu, s32 info) -{ - int isreg; - s_JumpX86 = _allocX86reg(-1, X86TYPE_VUJUMP, 0, MODE_WRITE); - -#ifdef SUPERVU_VIBRANCHDELAY - if (s_pCurInst->vicached >= 0 && s_pCurInst->vicached == _Is_) - { - isreg = -1; - } - else -#endif - { - isreg = _checkX86reg(X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _Is_, MODE_READ); - } - - if (isreg >= 0) - { - CMP16ItoR(isreg, 0); - j8Ptr[ 0 ] = JG8(0); - } - else - { - CMP16ItoM(SuperVUGetVIAddr(_Is_, 1), 0x0); - j8Ptr[ 0 ] = JG8(0); - } - recVUMI_BranchHandle(); -} - -void recVUMI_IBLTZ(VURegs* vuu, s32 info) -{ - int isreg; - s_JumpX86 = _allocX86reg(-1, X86TYPE_VUJUMP, 0, MODE_WRITE); - -#ifdef SUPERVU_VIBRANCHDELAY - if (s_pCurInst->vicached >= 0 && s_pCurInst->vicached == _Is_) - { - isreg = -1; - } - else -#endif - { - isreg = _checkX86reg(X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _Is_, MODE_READ); - } - - if (isreg >= 0) - { - TEST16RtoR(isreg, isreg); - j8Ptr[ 0 ] = JNS8(0); - } - else - { - CMP16ItoM(SuperVUGetVIAddr(_Is_, 1), 0x0); - j8Ptr[ 0 ] = JGE8(0); - } - recVUMI_BranchHandle(); -} - -void recVUMI_IBNE(VURegs* vuu, s32 info) -{ - recVUMI_IBQ_prep(); - j8Ptr[ 0 ] = JE8(0); - recVUMI_BranchHandle(); -} - -void recVUMI_B(VURegs* vuu, s32 info) -{ - // supervu will take care of the rest - int bpc = _recbranchAddr(VU->code); - if ((s_pCurBlock->type & BLOCKTYPE_HASEOP) || s_vu == 0 || SUPERVU_CHECKCONDITION) - MOV32ItoM(SuperVUGetVIAddr(REG_TPC, 0), bpc); - - // loops to self, so check condition - if (bpc == s_pCurBlock->startpc && (s_vu == 0 || SUPERVU_CHECKCONDITION)) - { - SuperVUTestVU0Condition(0); - } - - if (s_pCurBlock->blocks.size() > 1) - { - s_JumpX86 = _allocX86reg(-1, X86TYPE_VUJUMP, 0, MODE_WRITE); - MOV32ItoR(s_JumpX86, 1); - s_pCurBlock->pChildJumps[(s_pCurInst->type & INST_BRANCH_DELAY)?1:0] = (u32*)x86Ptr - 1; - s_UnconditionalDelay = 1; - } - - branch |= 3; -} - -void recVUMI_BAL(VURegs* vuu, s32 info) -{ - int bpc = _recbranchAddr(VU->code); - if ((s_pCurBlock->type & BLOCKTYPE_HASEOP) || s_vu == 0 || SUPERVU_CHECKCONDITION) - MOV32ItoM(SuperVUGetVIAddr(REG_TPC, 0), bpc); - - // loops to self, so check condition - if (bpc == s_pCurBlock->startpc && (s_vu == 0 || SUPERVU_CHECKCONDITION)) - { - SuperVUTestVU0Condition(0); - } - - if (_It_) - { - _deleteX86reg(X86TYPE_VI | (s_vu ? X86TYPE_VU1 : 0), _It_, 2); - MOV16ItoM(SuperVUGetVIAddr(_It_, 0), (pc + 8) >> 3); - } - - if (s_pCurBlock->blocks.size() > 1) - { - s_JumpX86 = _allocX86reg(-1, X86TYPE_VUJUMP, 0, MODE_WRITE); - MOV32ItoR(s_JumpX86, 1); - s_pCurBlock->pChildJumps[(s_pCurInst->type & INST_BRANCH_DELAY)?1:0] = (u32*)x86Ptr - 1; - s_UnconditionalDelay = 1; - } - - branch |= 3; -} - -void recVUMI_JR(VURegs* vuu, s32 info) -{ - int isreg = _allocX86reg(-1, X86TYPE_VI | (s_vu ? X86TYPE_VU1 : 0), _Is_, MODE_READ); - LEA32RStoR(EAX, isreg, 3); - - //Mask the address to something valid - if (vuu == &VU0) - AND32ItoR(EAX, 0xfff); - else - AND32ItoR(EAX, 0x3fff); - - if ((s_pCurBlock->type & BLOCKTYPE_HASEOP) || s_vu == 0) MOV32RtoM(SuperVUGetVIAddr(REG_TPC, 0), EAX); - - if (!(s_pCurBlock->type & BLOCKTYPE_HASEOP)) - { - PUSH32I(s_vu); - PUSH32R(EAX); - } - branch |= 0x10; // 0x08 is reserved -} - -void recVUMI_JALR(VURegs* vuu, s32 info) -{ - _addNeededX86reg(X86TYPE_VI | (s_vu ? X86TYPE_VU1 : 0), _It_); - - int isreg = _allocX86reg(-1, X86TYPE_VI | (s_vu ? X86TYPE_VU1 : 0), _Is_, MODE_READ); - LEA32RStoR(EAX, isreg, 3); - - //Mask the address to something valid - if (vuu == &VU0) - AND32ItoR(EAX, 0xfff); - else - AND32ItoR(EAX, 0x3fff); - - if (_It_) - { - _deleteX86reg(X86TYPE_VI | (s_vu ? X86TYPE_VU1 : 0), _It_, 2); - MOV16ItoM(SuperVUGetVIAddr(_It_, 0), (pc + 8) >> 3); - } - - if ((s_pCurBlock->type & BLOCKTYPE_HASEOP) || s_vu == 0) MOV32RtoM(SuperVUGetVIAddr(REG_TPC, 0), EAX); - - if (!(s_pCurBlock->type & BLOCKTYPE_HASEOP)) - { - PUSH32I(s_vu); - PUSH32R(EAX); - } - - branch |= 4; -} - -void recVUMI_XGKICK_(VURegs *VU) -{ - assert(s_XGKICKReg > 0 && x86regs[s_XGKICKReg].inuse && x86regs[s_XGKICKReg].type == X86TYPE_VITEMP); - - x86regs[s_XGKICKReg].inuse = 0; // so free doesn't flush - _freeX86regs(); - _freeXMMregs(); - - OR32ItoM((uptr)&psHu32(GIF_STAT), (GIF_STAT_APATH1 | GIF_STAT_OPH)); // Set PATH1 GIF Status Flags - PUSH32R(s_XGKICKReg); - PUSH32I((uptr)VU->Mem); - - CALLFunc((uptr)VU1XGKICK_MTGSTransfer); - ADD32ItoR(ESP, 8); - AND32ItoM((uptr)&psHu32(GIF_STAT), ~(GIF_STAT_APATH1 | GIF_STAT_OPH)); // Clear PATH1 GIF Status Flags - s_ScheduleXGKICK = 0; -} - -void recVUMI_XGKICK(VURegs *VU, int info) -{ - if (s_ScheduleXGKICK) { - // second xgkick, so launch the first - recVUMI_XGKICK_(VU); - } - - int isreg = _allocX86reg(X86ARG2, X86TYPE_VI | (s_vu ? X86TYPE_VU1 : 0), _Is_, MODE_READ); - _freeX86reg(isreg); // flush - x86regs[isreg].inuse = 1; - x86regs[isreg].type = X86TYPE_VITEMP; - x86regs[isreg].needed = 1; - x86regs[isreg].mode = MODE_WRITE | MODE_READ; - SHL32ItoR(isreg, 4); - AND32ItoR(isreg, 0x3fff); - s_XGKICKReg = isreg; - - if (!SUPERVU_XGKICKDELAY || pc == s_pCurBlock->endpc) { - recVUMI_XGKICK_(VU); - } - else { - s_ScheduleXGKICK = (CHECK_XGKICKHACK) ? (min((u32)4, (s_pCurBlock->endpc-pc)/8)) : 2; - } -} - -void recVU_UPPER_FD_00(VURegs* VU, s32 info); -void recVU_UPPER_FD_01(VURegs* VU, s32 info); -void recVU_UPPER_FD_10(VURegs* VU, s32 info); -void recVU_UPPER_FD_11(VURegs* VU, s32 info); -void recVULowerOP(VURegs* VU, s32 info); -void recVULowerOP_T3_00(VURegs* VU, s32 info); -void recVULowerOP_T3_01(VURegs* VU, s32 info); -void recVULowerOP_T3_10(VURegs* VU, s32 info); -void recVULowerOP_T3_11(VURegs* VU, s32 info); -void recVUunknown(VURegs* VU, s32 info); - -void (*recVU_LOWER_OPCODE[128])(VURegs* VU, s32 info) = -{ - recVUMI_LQ , recVUMI_SQ , recVUunknown , recVUunknown, - recVUMI_ILW , recVUMI_ISW , recVUunknown , recVUunknown, - recVUMI_IADDIU, recVUMI_ISUBIU, recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUMI_FCEQ , recVUMI_FCSET , recVUMI_FCAND, recVUMI_FCOR, /* 0x10 */ - recVUMI_FSEQ , recVUMI_FSSET , recVUMI_FSAND, recVUMI_FSOR, - recVUMI_FMEQ , recVUunknown , recVUMI_FMAND, recVUMI_FMOR, - recVUMI_FCGET , recVUunknown , recVUunknown , recVUunknown, - recVUMI_B , recVUMI_BAL , recVUunknown , recVUunknown, /* 0x20 */ - recVUMI_JR , recVUMI_JALR , recVUunknown , recVUunknown, - recVUMI_IBEQ , recVUMI_IBNE , recVUunknown , recVUunknown, - recVUMI_IBLTZ , recVUMI_IBGTZ , recVUMI_IBLEZ, recVUMI_IBGEZ, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, /* 0x30 */ - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVULowerOP , recVUunknown , recVUunknown , recVUunknown, /* 0x40*/ - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, /* 0x50 */ - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, /* 0x60 */ - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, /* 0x70 */ - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, -}; - -void (*recVULowerOP_T3_00_OPCODE[32])(VURegs* VU, s32 info) = -{ - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUMI_MOVE , recVUMI_LQI , recVUMI_DIV , recVUMI_MTIR, - recVUMI_RNEXT , recVUunknown , recVUunknown , recVUunknown, /* 0x10 */ - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUMI_MFP , recVUMI_XTOP , recVUMI_XGKICK, - recVUMI_ESADD , recVUMI_EATANxy, recVUMI_ESQRT, recVUMI_ESIN, -}; - -void (*recVULowerOP_T3_01_OPCODE[32])(VURegs* VU, s32 info) = -{ - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUMI_MR32 , recVUMI_SQI , recVUMI_SQRT , recVUMI_MFIR, - recVUMI_RGET , recVUunknown , recVUunknown , recVUunknown, /* 0x10 */ - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUMI_XITOP, recVUunknown, - recVUMI_ERSADD, recVUMI_EATANxz, recVUMI_ERSQRT, recVUMI_EATAN, -}; - -void (*recVULowerOP_T3_10_OPCODE[32])(VURegs* VU, s32 info) = -{ - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUMI_LQD , recVUMI_RSQRT, recVUMI_ILWR, - recVUMI_RINIT , recVUunknown , recVUunknown , recVUunknown, /* 0x10 */ - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUMI_ELENG , recVUMI_ESUM , recVUMI_ERCPR, recVUMI_EEXP, -}; - -void (*recVULowerOP_T3_11_OPCODE[32])(VURegs* VU, s32 info) = -{ - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUMI_SQD , recVUMI_WAITQ, recVUMI_ISWR, - recVUMI_RXOR , recVUunknown , recVUunknown , recVUunknown, /* 0x10 */ - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUMI_ERLENG, recVUunknown , recVUMI_WAITP, recVUunknown, -}; - -void (*recVULowerOP_OPCODE[64])(VURegs* VU, s32 info) = -{ - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, /* 0x10 */ - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, /* 0x20 */ - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUMI_IADD , recVUMI_ISUB , recVUMI_IADDI, recVUunknown, /* 0x30 */ - recVUMI_IAND , recVUMI_IOR , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVULowerOP_T3_00, recVULowerOP_T3_01, recVULowerOP_T3_10, recVULowerOP_T3_11, -}; - -void (*recVU_UPPER_OPCODE[64])(VURegs* VU, s32 info) = -{ - recVUMI_ADDx , recVUMI_ADDy , recVUMI_ADDz , recVUMI_ADDw, - recVUMI_SUBx , recVUMI_SUBy , recVUMI_SUBz , recVUMI_SUBw, - recVUMI_MADDx , recVUMI_MADDy , recVUMI_MADDz , recVUMI_MADDw, - recVUMI_MSUBx , recVUMI_MSUBy , recVUMI_MSUBz , recVUMI_MSUBw, - recVUMI_MAXx , recVUMI_MAXy , recVUMI_MAXz , recVUMI_MAXw, /* 0x10 */ - recVUMI_MINIx , recVUMI_MINIy , recVUMI_MINIz , recVUMI_MINIw, - recVUMI_MULx , recVUMI_MULy , recVUMI_MULz , recVUMI_MULw, - recVUMI_MULq , recVUMI_MAXi , recVUMI_MULi , recVUMI_MINIi, - recVUMI_ADDq , recVUMI_MADDq , recVUMI_ADDi , recVUMI_MADDi, /* 0x20 */ - recVUMI_SUBq , recVUMI_MSUBq , recVUMI_SUBi , recVUMI_MSUBi, - recVUMI_ADD , recVUMI_MADD , recVUMI_MUL , recVUMI_MAX, - recVUMI_SUB , recVUMI_MSUB , recVUMI_OPMSUB, recVUMI_MINI, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, /* 0x30 */ - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVUunknown , recVUunknown , recVUunknown , recVUunknown, - recVU_UPPER_FD_00, recVU_UPPER_FD_01, recVU_UPPER_FD_10, recVU_UPPER_FD_11, -}; - -void (*recVU_UPPER_FD_00_TABLE[32])(VURegs* VU, s32 info) = -{ - recVUMI_ADDAx, recVUMI_SUBAx , recVUMI_MADDAx, recVUMI_MSUBAx, - recVUMI_ITOF0, recVUMI_FTOI0, recVUMI_MULAx , recVUMI_MULAq , - recVUMI_ADDAq, recVUMI_SUBAq, recVUMI_ADDA , recVUMI_SUBA , - recVUunknown , recVUunknown , recVUunknown , recVUunknown , - recVUunknown , recVUunknown , recVUunknown , recVUunknown , - recVUunknown , recVUunknown , recVUunknown , recVUunknown , - recVUunknown , recVUunknown , recVUunknown , recVUunknown , - recVUunknown , recVUunknown , recVUunknown , recVUunknown , -}; - -void (*recVU_UPPER_FD_01_TABLE[32])(VURegs* VU, s32 info) = -{ - recVUMI_ADDAy , recVUMI_SUBAy , recVUMI_MADDAy, recVUMI_MSUBAy, - recVUMI_ITOF4 , recVUMI_FTOI4 , recVUMI_MULAy , recVUMI_ABS , - recVUMI_MADDAq, recVUMI_MSUBAq, recVUMI_MADDA , recVUMI_MSUBA , - recVUunknown , recVUunknown , recVUunknown , recVUunknown , - recVUunknown , recVUunknown , recVUunknown , recVUunknown , - recVUunknown , recVUunknown , recVUunknown , recVUunknown , - recVUunknown , recVUunknown , recVUunknown , recVUunknown , - recVUunknown , recVUunknown , recVUunknown , recVUunknown , -}; - -void (*recVU_UPPER_FD_10_TABLE[32])(VURegs* VU, s32 info) = -{ - recVUMI_ADDAz , recVUMI_SUBAz , recVUMI_MADDAz, recVUMI_MSUBAz, - recVUMI_ITOF12, recVUMI_FTOI12, recVUMI_MULAz , recVUMI_MULAi , - recVUMI_ADDAi, recVUMI_SUBAi , recVUMI_MULA , recVUMI_OPMULA, - recVUunknown , recVUunknown , recVUunknown , recVUunknown , - recVUunknown , recVUunknown , recVUunknown , recVUunknown , - recVUunknown , recVUunknown , recVUunknown , recVUunknown , - recVUunknown , recVUunknown , recVUunknown , recVUunknown , - recVUunknown , recVUunknown , recVUunknown , recVUunknown , -}; - -void (*recVU_UPPER_FD_11_TABLE[32])(VURegs* VU, s32 info) = -{ - recVUMI_ADDAw , recVUMI_SUBAw , recVUMI_MADDAw, recVUMI_MSUBAw, - recVUMI_ITOF15, recVUMI_FTOI15, recVUMI_MULAw , recVUMI_CLIP , - recVUMI_MADDAi, recVUMI_MSUBAi, recVUunknown , recVUMI_NOP , - recVUunknown , recVUunknown , recVUunknown , recVUunknown , - recVUunknown , recVUunknown , recVUunknown , recVUunknown , - recVUunknown , recVUunknown , recVUunknown , recVUunknown , - recVUunknown , recVUunknown , recVUunknown , recVUunknown , - recVUunknown , recVUunknown , recVUunknown , recVUunknown , -}; - -void recVU_UPPER_FD_00(VURegs* VU, s32 info) -{ - recVU_UPPER_FD_00_TABLE[(VU->code >> 6) & 0x1f ](VU, info); -} - -void recVU_UPPER_FD_01(VURegs* VU, s32 info) -{ - recVU_UPPER_FD_01_TABLE[(VU->code >> 6) & 0x1f ](VU, info); -} - -void recVU_UPPER_FD_10(VURegs* VU, s32 info) -{ - recVU_UPPER_FD_10_TABLE[(VU->code >> 6) & 0x1f ](VU, info); -} - -void recVU_UPPER_FD_11(VURegs* VU, s32 info) -{ - recVU_UPPER_FD_11_TABLE[(VU->code >> 6) & 0x1f ](VU, info); -} - -void recVULowerOP(VURegs* VU, s32 info) -{ - recVULowerOP_OPCODE[ VU->code & 0x3f ](VU, info); -} - -void recVULowerOP_T3_00(VURegs* VU, s32 info) -{ - recVULowerOP_T3_00_OPCODE[(VU->code >> 6) & 0x1f ](VU, info); -} - -void recVULowerOP_T3_01(VURegs* VU, s32 info) -{ - recVULowerOP_T3_01_OPCODE[(VU->code >> 6) & 0x1f ](VU, info); -} - -void recVULowerOP_T3_10(VURegs* VU, s32 info) -{ - recVULowerOP_T3_10_OPCODE[(VU->code >> 6) & 0x1f ](VU, info); -} - -void recVULowerOP_T3_11(VURegs* VU, s32 info) -{ - recVULowerOP_T3_11_OPCODE[(VU->code >> 6) & 0x1f ](VU, info); -} - -void recVUunknown(VURegs* VU, s32 info) -{ - Console::Notice("Unknown SVU micromode opcode called"); -} + +#include "R5900.h" +#include "iR5900.h" + +#include "sVU_zerorec.h" +#include "SamplProf.h" +#include "NakedAsm.h" +#include "AppConfig.h" + +using namespace std; + +// temporary externs +extern void iDumpVU0Registers(); +extern void iDumpVU1Registers(); + +// SuperVURec optimization options, uncomment only for debugging purposes +#define SUPERVU_CACHING // vu programs are saved and queried via memcompare (should be no reason to disable this) +#define SUPERVU_WRITEBACKS // don't flush the writebacks after every block +#define SUPERVU_X86CACHING // use x86reg caching (faster) (not really. rather lots slower :p (rama) ) +#define SUPERVU_VIBRANCHDELAY // when integers are modified right before a branch that uses the integer, + // the old integer value is used in the branch, fixes kh2 + +#define SUPERVU_PROPAGATEFLAGS // the correct behavior of VUs, for some reason superman breaks gfx with it on... + +// registers won't be flushed at block boundaries (faster) (nothing noticable speed-wise, causes SPS in Ratchet and clank (Nneeve) ) +#ifndef PCSX2_DEBUG +//#define SUPERVU_INTERCACHING +#endif + +#define SUPERVU_CHECKCONDITION 0 // has to be 0!! + +#define VU_EXESIZE 0x00800000 + +#define _Imm11_ (s32)( (vucode & 0x400) ? (0xfffffc00 | (vucode & 0x3ff)) : (vucode & 0x3ff) ) +#define _UImm11_ (s32)(vucode & 0x7ff) + +#define _Ft_ ((VU->code >> 16) & 0x1F) // The rt part of the instruction register +#define _Fs_ ((VU->code >> 11) & 0x1F) // The rd part of the instruction register +#define _Fd_ ((VU->code >> 6) & 0x1F) // The sa part of the instruction register +#define _It_ (_Ft_ & 15) +#define _Is_ (_Fs_ & 15) +#define _Id_ (_Fd_ & 15) + +static const u32 QWaitTimes[] = { 6, 12 }; +static const u32 PWaitTimes[] = { 53, 43, 28, 23, 17, 11, 10 }; + +static u32 s_vuInfo; // info passed into rec insts + +static const u32 s_MemSize[2] = {VU0_MEMSIZE, VU1_MEMSIZE}; +static u8* s_recVUMem = NULL, *s_recVUPtr = NULL; + +// tables which are defined at the bottom of this massive file. +extern void (*recVU_UPPER_OPCODE[64])(VURegs* VU, s32 info); +extern void (*recVU_LOWER_OPCODE[128])(VURegs* VU, s32 info); + +#define INST_Q_READ 0x0001 // flush Q +#define INST_P_READ 0x0002 // flush P +#define INST_BRANCH_DELAY 0x0004 +#define INST_CLIP_WRITE 0x0040 // inst writes CLIP in the future +#define INST_STATUS_WRITE 0x0080 +#define INST_MAC_WRITE 0x0100 +#define INST_Q_WRITE 0x0200 +#define INST_CACHE_VI 0x0400 // write old vi value to s_VIBranchDelay + +// Let's tempt fate by defining two different constants with almost identical names +#define INST_DUMMY_ 0x8000 +#define INST_DUMMY 0x83c0 + +#define VFFREE_INVALID0 0x80000000 // (vffree[i]&0xf) is invalid + +//#define FORIT(it, v) for(it = (v).begin(); it != (v).end(); ++(it)) + +#ifdef PCSX2_DEBUG +u32 s_vucount = 0; + +static u32 g_vu1lastrec = 0, skipparent = -1; +static u32 s_svulast = 0, s_vufnheader; +static u32 badaddrs[][2] = {0, 0xffff}; +#endif + +union VURecRegs +{ + struct + { + u16 reg; + u16 type; + }; + u32 id; +}; + +#define SUPERVU_XGKICKDELAY 1 // yes this is needed as default (wipeout) + +class VuBaseBlock; + +struct VuFunctionHeader +{ + struct RANGE + { + RANGE() : pmem(NULL) {} + + u16 start, size; + void* pmem; // all the mem + }; + + VuFunctionHeader() : pprogfunc(NULL), startpc(0xffffffff) {} + ~VuFunctionHeader() + { + for (vector::iterator it = ranges.begin(); it != ranges.end(); ++it) + { + free(it->pmem); + } + } + + // returns true if the checksum for the current mem is the same as this fn + bool IsSame(void* pmem); + + u32 startpc; + void* pprogfunc; + + vector ranges; +}; + +struct VuBlockHeader +{ + VuBaseBlock* pblock; + u32 delay; +}; + +// one vu inst (lower and upper) +class VuInstruction +{ + public: + VuInstruction() + { + memzero(*this); + nParentPc = -1; + vicached = -1; + } + + int nParentPc; // used for syncing with flag writes, -1 for no parent + + _vuopinfo info; + + _VURegsNum regs[2]; // [0] - lower, [1] - upper + u32 livevars[2]; // live variables right before this inst, [0] - inst, [1] - float + u32 addvars[2]; // live variables to add + u32 usedvars[2]; // set if var is used in the future including vars used in this inst + u32 keepvars[2]; + u16 pqcycles; // the number of cycles to stall if function writes to the regs + u16 type; // INST_ + + u32 pClipWrite, pMACWrite, pStatusWrite; // addrs to write the flags + u32 vffree[2]; + s8 vfwrite[2], vfread0[2], vfread1[2], vfacc[2]; + s8 vfflush[2]; // extra flush regs + s8 vicached; // if >= 0, then use the cached integer s_VIBranchDelay + VuInstruction *pPrevInst; + + int SetCachedRegs(int upper, u32 vuxyz); + void Recompile(list::iterator& itinst, u32 vuxyz); +}; + +enum BlockType +{ + BLOCKTYPE_EOP = 0x01, // at least one of the children of the block contains eop (or the block itself) + BLOCKTYPE_FUNCTION = 0x02, + BLOCKTYPE_HASEOP = 0x04, // last inst of block is an eop + BLOCKTYPE_MACFLAGS = 0x08, + BLOCKTYPE_ANALYZED = 0x40, + BLOCKTYPE_IGNORE = 0x80, // special for recursive fns + BLOCKTYPE_ANALYZEDPARENT = 0x100 +}; + +// base block used when recompiling +class VuBaseBlock +{ + public: + typedef list LISTBLOCKS; + + VuBaseBlock(); + + // returns true if the leads to a EOP (ALL VU blocks must ret true) + void AssignVFRegs(); + void AssignVIRegs(int parent); + + list::iterator GetInstIterAtPc(int instpc); + void GetInstsAtPc(int instpc, list& listinsts); + + void Recompile(); + + u16 type; // BLOCKTYPE_ + u16 id; + u16 startpc; + u16 endpc; // first inst not in block + void* pcode; // x86 code pointer + void* pendcode; // end of the x86 code pointer + int cycles; + list insts; + list parents; + LISTBLOCKS blocks; // blocks branches to + u32* pChildJumps[4]; // addrs that need to be filled with the children's start addrs + // if highest bit is set, addr needs to be relational + u32 vuxyz; // corresponding bit is set if reg's xyz channels are used only + u32 vuxy; // corresponding bit is set if reg's xyz channels are used only + + _xmmregs startregs[iREGCNT_XMM], endregs[iREGCNT_XMM]; + int nStartx86, nEndx86; // indices into s_vecRegArray + + int allocX86Regs; + int prevFlagsOutOfBlock; +}; + +struct WRITEBACK +{ + WRITEBACK() : nParentPc(0), cycle(0) //, pStatusWrite(NULL), pMACWrite(NULL) + { + viwrite[0] = viwrite[1] = 0; + viread[0] = viread[1] = 0; + } + + void InitInst(VuInstruction* pinst, int cycle) const + { + u32 write = viwrite[0] | viwrite[1]; + pinst->type = ((write & (1 << REG_CLIP_FLAG)) ? INST_CLIP_WRITE : 0) | + ((write & (1 << REG_MAC_FLAG)) ? INST_MAC_WRITE : 0) | + ((write & (1 << REG_STATUS_FLAG)) ? INST_STATUS_WRITE : 0) | + ((write & (1 << REG_Q)) ? INST_Q_WRITE : 0); + pinst->nParentPc = nParentPc; + pinst->info.cycle = cycle; + for (int i = 0; i < 2; ++i) + { + pinst->regs[i].VIwrite = viwrite[i]; + pinst->regs[i].VIread = viread[i]; + } + } + + static int SortWritebacks(const WRITEBACK& w1, const WRITEBACK& w2) + { + return w1.cycle < w2.cycle; + } + + int nParentPc; + int cycle; + u32 viwrite[2]; + u32 viread[2]; +}; + +struct VUPIPELINES +{ + fmacPipe fmac[8]; + fdivPipe fdiv; + efuPipe efu; + ialuPipe ialu[8]; + list< WRITEBACK > listWritebacks; +}; + +VuBaseBlock::VuBaseBlock() +{ + type = 0; + endpc = 0; + cycles = 0; + pcode = NULL; + id = 0; + memzero(pChildJumps); + memzero(startregs); + memzero(endregs); + allocX86Regs = nStartx86 = nEndx86 = -1; + prevFlagsOutOfBlock = 0; +} + +#define SUPERVU_STACKSIZE 0x1000 + +static list s_listVUHeaders[2]; +static list* s_plistCachedHeaders[2] = {NULL, NULL}; +static VuFunctionHeader** recVUHeaders[2] = {NULL, NULL}; +static VuBlockHeader* recVUBlocks[2] = {NULL, NULL}; +static u8* recVUStack = NULL, *recVUStackPtr = NULL; +static vector<_x86regs> s_vecRegArray(128); + +static VURegs* VU = NULL; +static list s_listBlocks; +static u32 s_vu = 0; +static u32 s_UnconditionalDelay = 0; // 1 if there are two sequential branches and the last is unconditional +static u32 g_nLastBlockExecuted = 0; + +static VuFunctionHeader* SuperVURecompileProgram(u32 startpc, int vuindex); +static VuBaseBlock* SuperVUBuildBlocks(VuBaseBlock* parent, u32 startpc, const VUPIPELINES& pipes); +static void SuperVUInitLiveness(VuBaseBlock* pblock); +static void SuperVULivenessAnalysis(); +static void SuperVUEliminateDeadCode(); +static void SuperVUAssignRegs(); + +//void SuperVUFreeXMMreg(int xmmreg, int xmmtype, int reg); +#define SuperVUFreeXMMreg 0&& +void SuperVUFreeXMMregs(u32* livevars); + +static u32* SuperVUStaticAlloc(u32 size); +static void SuperVURecompile(); + +// allocate VU resources +void SuperVUAlloc(int vuindex) +{ + // The old -1 crap has been depreciated on this function. Please + // specify either 0 or 1, thanks. + jASSUME(vuindex >= 0); + + // upper 4 bits must be zero! + if (s_recVUMem == NULL) + { + // upper 4 bits must be zero! + // Changed "first try base" to 0xf1e0000, since 0x0c000000 liked to fail a lot. (cottonvibes) + s_recVUMem = SysMmapEx(0xf1e0000, VU_EXESIZE, 0x10000000, "SuperVUAlloc"); + + if (s_recVUMem == NULL) + { + throw Exception::OutOfMemory( + // untranslated diagnostic msg, use exception's default for translation + wxsFormat( L"SuperVU failed to allocate recompiler memory (addr: 0x%x)", (u32)s_recVUMem ), + _("An out of memory error occured while attempting to reserve memory for the core recompilers.") + ); + } + + ProfilerRegisterSource("VURec", s_recVUMem, VU_EXESIZE); + + if (recVUStack == NULL) recVUStack = new u8[SUPERVU_STACKSIZE * 4]; + } + + if (vuindex >= 0) + { + jASSUME(s_recVUMem != NULL); + + if (recVUHeaders[vuindex] == NULL) + recVUHeaders[vuindex] = new VuFunctionHeader* [s_MemSize[vuindex] / 8]; + if (recVUBlocks[vuindex] == NULL) + recVUBlocks[vuindex] = new VuBlockHeader[s_MemSize[vuindex] / 8]; + if (s_plistCachedHeaders[vuindex] == NULL) + s_plistCachedHeaders[vuindex] = new list[s_MemSize[vuindex] / 8]; + } +} + +void DestroyCachedHeaders(int vuindex, int j) +{ + list::iterator it = s_plistCachedHeaders[vuindex][j].begin(); + + while (it != s_plistCachedHeaders[vuindex][j].end()) + { + delete *it; + it++; + } + + s_plistCachedHeaders[vuindex][j].clear(); +} + +void DestroyVUHeaders(int vuindex) +{ + list::iterator it = s_listVUHeaders[vuindex].begin(); + + while (it != s_listVUHeaders[vuindex].end()) + { + delete *it; + it++; + } + + s_listVUHeaders[vuindex].clear(); +} + +// destroy VU resources +void SuperVUDestroy(int vuindex) +{ + list::iterator it; + + if (vuindex < 0) + { + SuperVUDestroy(0); + SuperVUDestroy(1); + ProfilerTerminateSource("VURec"); + SafeSysMunmap(s_recVUMem, VU_EXESIZE); + safe_delete_array(recVUStack); + } + else + { + safe_delete_array(recVUHeaders[vuindex]); + safe_delete_array(recVUBlocks[vuindex]); + + if (s_plistCachedHeaders[vuindex] != NULL) + { + for (u32 j = 0; j < s_MemSize[vuindex] / 8; ++j) + { + DestroyCachedHeaders(vuindex, j); + } + safe_delete_array(s_plistCachedHeaders[vuindex]); + } + DestroyVUHeaders(vuindex); + } +} + +// reset VU +void SuperVUReset(int vuindex) +{ +#ifdef PCSX2_DEBUG + s_vucount = 0; +#endif + + if (s_recVUMem == NULL) + return; + + //jASSUME( s_recVUMem != NULL ); + + if (vuindex < 0) + { + DbgCon.Status("SuperVU reset > Resetting recompiler memory and structures."); + + // Does this cause problems on VU recompiler resets? It could, if the VU works like + // the EE used to, and actually tries to re-enter the recBlock after issuing a clear. (air) + + //memset_8<0xcd, VU_EXESIZE>(s_recVUMem); + memzero_ptr(recVUStack); + + s_recVUPtr = s_recVUMem; + } + else + { + DbgCon.Status("SuperVU reset [VU%d] > Resetting the recs and junk", vuindex); + list::iterator it; + if (recVUHeaders[vuindex]) memset(recVUHeaders[vuindex], 0, sizeof(VuFunctionHeader*) * (s_MemSize[vuindex] / 8)); + if (recVUBlocks[vuindex]) memset(recVUBlocks[vuindex], 0, sizeof(VuBlockHeader) * (s_MemSize[vuindex] / 8)); + + if (s_plistCachedHeaders[vuindex] != NULL) + { + for (u32 j = 0; j < s_MemSize[vuindex] / 8; ++j) + { + DestroyCachedHeaders(vuindex, j); + } + } + DestroyVUHeaders(vuindex); + } +} + +// clear the block and any joining blocks +void __fastcall SuperVUClear(u32 startpc, u32 size, int vuindex) +{ + vector::iterator itrange; + list::iterator it = s_listVUHeaders[vuindex].begin(); + u32 endpc = startpc + (size + (8 - (size & 7))); // Adding this code to ensure size is always a multiple of 8, it can be simplified to startpc+size if size is always a multiple of 8 (cottonvibes) + while (it != s_listVUHeaders[vuindex].end()) + { + + // for every fn, check if it has code in the range + for(itrange = (*it)->ranges.begin(); itrange != (*it)->ranges.end(); itrange++) + { + if (startpc < (u32)itrange->start + itrange->size && itrange->start < endpc) + break; + } + + if (itrange != (*it)->ranges.end()) + { + recVUHeaders[vuindex][(*it)->startpc/8] = NULL; +#ifdef SUPERVU_CACHING + list* plist = &s_plistCachedHeaders[vuindex][(*it)->startpc/8]; + plist->push_back(*it); + if (plist->size() > 30) + { + // list is too big, delete + //Console.Notice("Performance warning: deleting cached VU program!"); + delete plist->front(); + plist->pop_front(); + } + it = s_listVUHeaders[vuindex].erase(it); +#else + delete *it; + it = s_listVUHeaders[vuindex].erase(it); +#endif + } + else ++it; + } +} + +static VuFunctionHeader* s_pFnHeader = NULL; +static VuBaseBlock* s_pCurBlock = NULL; +static VuInstruction* s_pCurInst = NULL; +static u32 s_StatusRead = 0, s_MACRead = 0, s_ClipRead = 0; // read addrs +static u32 s_PrevStatusWrite = 0, s_PrevMACWrite = 0, s_PrevClipWrite = 0, s_PrevIWrite = 0; +static u32 s_WriteToReadQ = 0; + +static u32 s_VIBranchDelay = 0; //Value of register to use in a vi branch delayed situation + + +u32 s_TotalVUCycles; // total cycles since start of program execution + + +u32 SuperVUGetVIAddr(int reg, int read) +{ + assert(s_pCurInst != NULL); + + switch (reg) + { + case REG_STATUS_FLAG: + { + u32 addr = (read == 2) ? s_PrevStatusWrite : (read ? s_StatusRead : s_pCurInst->pStatusWrite); + assert(!read || addr != 0); + return addr; + } + case REG_MAC_FLAG: + { + u32 addr = (read == 2) ? s_PrevMACWrite : (read ? s_MACRead : s_pCurInst->pMACWrite); + return addr; + } + case REG_CLIP_FLAG: + { + u32 addr = (read == 2) ? s_PrevClipWrite : (read ? s_ClipRead : s_pCurInst->pClipWrite); + assert(!read || addr != 0); + return addr; + } + case REG_Q: + return (read || s_WriteToReadQ) ? (uptr)&VU->VI[REG_Q] : (uptr)&VU->q; + case REG_P: + return read ? (uptr)&VU->VI[REG_P] : (uptr)&VU->p; + case REG_I: + return s_PrevIWrite; + } + +#ifdef SUPERVU_VIBRANCHDELAY + if ((read != 0) && (s_pCurInst->regs[0].pipe == VUPIPE_BRANCH) && (s_pCurInst->vicached >= 0) && (s_pCurInst->vicached == reg)) + { + return (uptr)&s_VIBranchDelay; // test for branch delays + } +#endif + + return (uptr)&VU->VI[reg]; +} + +void SuperVUDumpBlock(list& blocks, int vuindex) +{ + u32 *mem; + u32 i; + + g_Conf->Folders.Logs.Mkdir(); + AsciiFile eff( + Path::Combine( g_Conf->Folders.Logs, wxsFormat(L"svu%cdump%.4X.txt", s_vu?L'0':L'1', s_pFnHeader->startpc) ), + wxFile::write + ); + + eff.Printf("Format: upper_inst lower_inst\ntype f:vf_live_vars vf_used_vars i:vi_live_vars vi_used_vars inst_cycle pq_inst\n"); + eff.Printf("Type: %.2x - qread, %.2x - pread, %.2x - clip_write, %.2x - status_write\n" + "%.2x - mac_write, %.2x -qflush\n", + INST_Q_READ, INST_P_READ, INST_CLIP_WRITE, INST_STATUS_WRITE, INST_MAC_WRITE, INST_Q_WRITE); + eff.Printf("XMM: Upper: read0 read1 write acc temp; Lower: read0 read1 write acc temp\n\n"); + + list::iterator itblock; + list::iterator itinst; + VuBaseBlock::LISTBLOCKS::iterator itchild; + + for(itblock = blocks.begin(); itblock != blocks.end(); itblock++) + { + eff.Printf( "block:%c %x-%x; children: ", ((*itblock)->type&BLOCKTYPE_HASEOP) ? '*' : ' ', + (*itblock)->startpc, (*itblock)->endpc - 8); + + for(itchild = (*itblock)->blocks.begin(); itchild != (*itblock)->blocks.end(); itchild++) + { + eff.Printf("%x ", (*itchild)->startpc); + } + eff.Printf("; vuxyz = %x, vuxy = %x\n", (*itblock)->vuxyz&(*itblock)->insts.front().usedvars[1], + (*itblock)->vuxy&(*itblock)->insts.front().usedvars[1]); + + itinst = (*itblock)->insts.begin(); + i = (*itblock)->startpc; + while (itinst != (*itblock)->insts.end()) + { + assert(i <= (*itblock)->endpc); + if (itinst->type & INST_DUMMY) + { + if (itinst->nParentPc >= 0 && !(itinst->type&INST_DUMMY_)) + { + // search for the parent + eff.Printf("writeback 0x%x (%x)\n", itinst->type, itinst->nParentPc); + } + } + else + { + mem = (u32*) & VU->Micro[i]; + char* pstr = disVU1MicroUF(mem[1], i + 4); + eff.Printf( "%.4x: %-40s", i, pstr); + if (mem[1] & 0x80000000) eff.Printf( " I=%f(%.8x)\n", *(float*)mem, mem[0]); + else eff.Printf( "%s\n", disVU1MicroLF(mem[0], i)); + i += 8; + } + + ++itinst; + } + + eff.Printf("\n"); + + _x86regs* pregs; + if ((*itblock)->nStartx86 >= 0 || (*itblock)->nEndx86 >= 0) + { + eff.Printf( "X86: AX CX DX BX SP BP SI DI\n"); + } + + if ((*itblock)->nStartx86 >= 0) + { + pregs = &s_vecRegArray[(*itblock)->nStartx86]; + eff.Printf( "STR: "); + for (i = 0; i < iREGCNT_GPR; ++i) + { + if (pregs[i].inuse) + eff.Printf( "%.2d ", pregs[i].reg); + else + eff.Printf( "-1 "); + } + eff.Printf( "\n"); + } + + if ((*itblock)->nEndx86 >= 0) + { + eff.Printf( "END: "); + pregs = &s_vecRegArray[(*itblock)->nEndx86]; + for (i = 0; i < iREGCNT_GPR; ++i) + { + if (pregs[i].inuse) + eff.Printf( "%.2d ", pregs[i].reg); + else + eff.Printf( "-1 "); + } + eff.Printf( "\n"); + } + + itinst = (*itblock)->insts.begin(); + for (i = (*itblock)->startpc; i < (*itblock)->endpc; ++itinst) + { + + if (itinst->type & INST_DUMMY) + { + } + else + { + char str[256]; + sprintf(str, "%.4x:%x f:%.8x_%.8x", i, itinst->type, itinst->livevars[1], itinst->usedvars[1]); + eff.Printf( "%-46s i:%.8x_%.8x c:%d pq:%d\n", str, + itinst->livevars[0], itinst->usedvars[0], (int)itinst->info.cycle, (int)itinst->pqcycles); + + sprintf(str, "XMM r0:%d r1:%d w:%d a:%d t:%x;", + itinst->vfread0[1], itinst->vfread1[1], itinst->vfwrite[1], itinst->vfacc[1], itinst->vffree[1]); + eff.Printf( "%-46s r0:%d r1:%d w:%d a:%d t:%x\n", str, + itinst->vfread0[0], itinst->vfread1[0], itinst->vfwrite[0], itinst->vfacc[0], itinst->vffree[0]); + i += 8; + } + } + +// +#if 0 // __LINUX__ + + // dump the asm + if ((*itblock)->pcode != NULL) + { + char command[255]; + FILE* fasm = fopen("mydump1", "wb"); + //Console.WriteLn("writing: %x, %x", (*itblock)->startpc, (uptr)(*itblock)->pendcode - (uptr)(*itblock)->pcode); + fwrite((*itblock)->pcode, 1, (uptr)(*itblock)->pendcode - (uptr)(*itblock)->pcode, fasm); + fclose(fasm); + sprintf(command, "objdump -D --target=binary --architecture=i386 -M intel mydump1 > tempdump"); + system(command); + fasm = fopen("tempdump", "r"); + // read all of it and write it to f + fseek(fasm, 0, SEEK_END); + vector vbuffer(ftell(fasm)); + fseek(fasm, 0, SEEK_SET); + fread(&vbuffer[0], vbuffer.size(), 1, fasm); + + fprintf(f, "\n\n"); + fwrite(&vbuffer[0], vbuffer.size(), 1, f); + fclose(fasm); + } +#endif + + eff.Printf("\n---------------\n"); + } +} + +// uncomment to count svu exec time +//#define SUPERVU_COUNT + +// Private methods +void* SuperVUGetProgram(u32 startpc, int vuindex) +{ + assert(startpc < s_MemSize[vuindex]); + assert((startpc % 8) == 0); + assert(recVUHeaders[vuindex] != NULL); + VuFunctionHeader** pheader = &recVUHeaders[vuindex][startpc/8]; + + if (*pheader == NULL) + { + +#ifdef SUPERVU_CACHING + void* pmem = (vuindex & 1) ? VU1.Micro : VU0.Micro; + // check if program exists in cache + list::iterator it; + for(it = s_plistCachedHeaders[vuindex][startpc/8].begin(); it != s_plistCachedHeaders[vuindex][startpc/8].end(); it++) + { + if ((*it)->IsSame(pmem)) + { + // found, transfer to regular lists + void* pfn = (*it)->pprogfunc; + recVUHeaders[vuindex][startpc/8] = *it; + s_listVUHeaders[vuindex].push_back(*it); + s_plistCachedHeaders[vuindex][startpc/8].erase(it); + return pfn; + } + } +#endif + + *pheader = SuperVURecompileProgram(startpc, vuindex); + + if (*pheader == NULL) + { + assert(s_TotalVUCycles > 0); + if (vuindex) + VU1.VI[REG_TPC].UL = startpc; + else + VU0.VI[REG_TPC].UL = startpc; + + return (void*)SuperVUEndProgram; + } + + assert((*pheader)->pprogfunc != NULL); + } + //else assert( (*pheader)->IsSame((vuindex&1) ? VU1.Micro : VU0.Micro) ); + + assert((*pheader)->startpc == startpc); + + return (*pheader)->pprogfunc; +} + +bool VuFunctionHeader::IsSame(void* pmem) +{ +#ifdef SUPERVU_CACHING + vector::iterator it; + for(it = ranges.begin(); it != ranges.end(); it++) + { + if (memcmp_mmx((u8*)pmem + it->start, it->pmem, it->size)) + return false; + } +#endif + return true; +} + +list::iterator VuBaseBlock::GetInstIterAtPc(int instpc) +{ + assert(instpc >= 0); + + u32 curpc = startpc; + list::iterator it; + for (it = insts.begin(); it != insts.end(); ++it) + { + if (it->type & INST_DUMMY) continue; + if (curpc == instpc) break; + curpc += 8; + } + + if (it != insts.end()) return it; + + assert(0); + return insts.begin(); +} + +void VuBaseBlock::GetInstsAtPc(int instpc, list& listinsts) +{ + assert(instpc >= 0); + + listinsts.clear(); + + u32 curpc = startpc; + list::iterator it; + for (it = insts.begin(); it != insts.end(); ++it) + { + if (it->type & INST_DUMMY) continue; + if (curpc == instpc) break; + curpc += 8; + } + + if (it != insts.end()) + { + listinsts.push_back(&(*it)); + return; + } + + // look for the pc in other blocks + for (list::iterator itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); ++itblock) + { + if (*itblock == this) continue; + + if (instpc >= (*itblock)->startpc && instpc < (*itblock)->endpc) + { + listinsts.push_back(&(*(*itblock)->GetInstIterAtPc(instpc))); + } + } + + assert(listinsts.size() > 0); +} + +static VuFunctionHeader* SuperVURecompileProgram(u32 startpc, int vuindex) +{ + assert(vuindex < 2); + assert(s_recVUPtr != NULL); + //Console.WriteLn("svu%c rec: %x", '0'+vuindex, startpc); + + // if recPtr reached the mem limit reset whole mem + if (((uptr)s_recVUPtr - (uptr)s_recVUMem) >= VU_EXESIZE - 0x40000) + { + //Console.WriteLn("SuperVU reset mem"); + SuperVUReset(0); + SuperVUReset(1); + SuperVUReset(-1); + if (s_TotalVUCycles > 0) + { + // already executing, so return NULL + return NULL; + } + } + + list::iterator itblock; + + s_vu = vuindex; + VU = s_vu ? &VU1 : &VU0; + s_pFnHeader = new VuFunctionHeader(); + s_listVUHeaders[vuindex].push_back(s_pFnHeader); + s_pFnHeader->startpc = startpc; + + memset(recVUBlocks[s_vu], 0, sizeof(VuBlockHeader) * (s_MemSize[s_vu] / 8)); + + // analyze the global graph + s_listBlocks.clear(); + VUPIPELINES pipes; + memzero(pipes.fmac); + memzero(pipes.fdiv); + memzero(pipes.efu); + memzero(pipes.ialu); + SuperVUBuildBlocks(NULL, startpc, pipes); + + // fill parents + VuBaseBlock::LISTBLOCKS::iterator itchild; + for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) + { + for(itchild = (*itblock)->blocks.begin(); itchild != (*itblock)->blocks.end(); itchild++) + { + (*itchild)->parents.push_back(*itblock); + } + + //(*itblock)->type &= ~(BLOCKTYPE_IGNORE|BLOCKTYPE_ANALYZED); + } + + assert(s_listBlocks.front()->startpc == startpc); + s_listBlocks.front()->type |= BLOCKTYPE_FUNCTION; + + for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) + { + SuperVUInitLiveness(*itblock); + } + + SuperVULivenessAnalysis(); + SuperVUEliminateDeadCode(); + SuperVUAssignRegs(); + +#ifdef PCSX2_DEBUG + if ((s_vu && (vudump&1)) || (!s_vu && (vudump&16))) SuperVUDumpBlock(s_listBlocks, s_vu); +#endif + + // code generation + x86SetPtr(s_recVUPtr); + branch = 0; + + SuperVURecompile(); + + s_recVUPtr = x86Ptr; + + // set the function's range + VuFunctionHeader::RANGE r; + s_pFnHeader->ranges.reserve(s_listBlocks.size()); + + for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) + { + r.start = (*itblock)->startpc; + r.size = (*itblock)->endpc - (*itblock)->startpc; +#ifdef SUPERVU_CACHING + //memxor_mmx(r.checksum, &VU->Micro[r.start], r.size); + r.pmem = malloc(r.size); + memcpy_fast(r.pmem, &VU->Micro[r.start], r.size); +#endif + s_pFnHeader->ranges.push_back(r); + } + +#if defined(PCSX2_DEBUG) && defined(__LINUX__) + // dump at the end to capture the actual code + if ((s_vu && (vudump&1)) || (!s_vu && (vudump&16))) SuperVUDumpBlock(s_listBlocks, s_vu); +#endif + + // destroy + for (list::iterator itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); ++itblock) + { + delete *itblock; + } + s_listBlocks.clear(); + + assert(s_recVUPtr < s_recVUMem + VU_EXESIZE); + + return s_pFnHeader; +} + +static int _recbranchAddr(u32 vucode) +{ + s32 bpc = pc + (_Imm11_ << 3); + /* + if ( bpc < 0 ) { + Console.WriteLn("zerorec branch warning: bpc < 0 ( %x ); Using unsigned imm11", bpc); + bpc = pc + (_UImm11_ << 3); + }*/ + bpc &= (s_MemSize[s_vu] - 1); + + return bpc; +} + +// return inst that flushes everything +static VuInstruction SuperVUFlushInst() +{ + VuInstruction inst; + // don't need to read q/p + inst.type = INST_DUMMY_;//|INST_Q_READ|INST_P_READ; + return inst; +} + +void SuperVUAddWritebacks(VuBaseBlock* pblock, const list& listWritebacks) +{ +#ifdef SUPERVU_WRITEBACKS + // regardless of repetition, add the pipes (for selfloops) + list::const_iterator itwriteback = listWritebacks.begin(); + list::iterator itinst = pblock->insts.begin(), itinst2; + + while (itwriteback != listWritebacks.end()) + { + if (itinst != pblock->insts.end() && (itinst->info.cycle < itwriteback->cycle || (itinst->type&INST_DUMMY))) + { + ++itinst; + continue; + } + + itinst2 = pblock->insts.insert(itinst, VuInstruction()); + itwriteback->InitInst(&(*itinst2), vucycle); + ++itwriteback; + } +#endif +} + +#ifdef SUPERVU_VIBRANCHDELAY +static VuInstruction* getDelayInst(VuInstruction* pInst) +{ + // check for the N cycle branch delay + // example of 2 cycles delay (monster house) : + // sqi vi05 + // sqi vi05 + // ibeq vi05, vi03 + // The ibeq should read the vi05 before the first sqi + + //more info: + + // iaddiu vi01, 0, 1 + // ibeq vi01, 0 <- reads vi01 before the iaddiu + + // iaddiu vi01, 0, 1 + // iaddiu vi01, vi01, 1 + // iaddiu vi01, vi01, 1 + // ibeq vi01, 0 <- reads vi01 before the last two iaddiu's (so the value read is 1) + + // ilw vi02, addr + // iaddiu vi01, 0, 1 + // ibeq vi01, vi02 <- reads current values of both vi01 and vi02 because the branch instruction stalls + + int delay = 1; + VuInstruction* pDelayInst = NULL; + VuInstruction* pTargetInst = pInst->pPrevInst; + while (1) + { + if (pTargetInst != NULL + && pTargetInst->info.cycle + delay == pInst->info.cycle + && (pTargetInst->regs[0].pipe == VUPIPE_IALU || pTargetInst->regs[0].pipe == VUPIPE_FMAC) + && ((pTargetInst->regs[0].VIwrite & pInst->regs[0].VIread) & 0xffff) + && (delay == 1 || ((pTargetInst->regs[0].VIwrite & pInst->regs[0].VIread) & 0xffff) == ((pTargetInst->regs[0].VIwrite & pInst->pPrevInst->regs[0].VIread) & 0xffff)) + && !(pTargetInst->regs[0].VIread&((1 << REG_STATUS_FLAG) | (1 << REG_MAC_FLAG) | (1 << REG_CLIP_FLAG)))) + { + pDelayInst = pTargetInst; + pTargetInst = pTargetInst->pPrevInst; + delay++; + if (delay == 5) //maximum delay is 4 (length of the pipeline) + { + DevCon.WriteLn("supervu: cycle branch delay maximum (4) is reached"); + break; + } + } + else break; + } + if (delay > 1) DevCon.WriteLn("supervu: %d cycle branch delay detected: %x %x", delay - 1, pc, s_pFnHeader->startpc); + return pDelayInst; +} +#endif + +static VuBaseBlock* SuperVUBuildBlocks(VuBaseBlock* parent, u32 startpc, const VUPIPELINES& pipes) +{ + // check if block already exists + //Console.WriteLn("startpc %x", startpc); + startpc &= (s_vu ? 0x3fff : 0xfff); + VuBlockHeader* pbh = &recVUBlocks[s_vu][startpc/8]; + + if (pbh->pblock != NULL) + { + + VuBaseBlock* pblock = pbh->pblock; + list::iterator itinst; + + if (pblock->startpc == startpc) + { + SuperVUAddWritebacks(pblock, pipes.listWritebacks); + return pblock; + } + + // have to divide the blocks, pnewblock is first block + assert(startpc > pblock->startpc); + assert(startpc < pblock->endpc); + + u32 dummyinst = (startpc - pblock->startpc) >> 3; + + // count inst non-dummy insts + itinst = pblock->insts.begin(); + int cycleoff = 0; + + while (dummyinst > 0) + { + if (itinst->type & INST_DUMMY) + ++itinst; + else + { + cycleoff = itinst->info.cycle; + ++itinst; + --dummyinst; + } + } + + // NOTE: still leaves insts with their writebacks in different blocks + while (itinst->type & INST_DUMMY) + ++itinst; + + // the difference in cycles between dummy insts (naruto utlimate ninja) + int cyclediff = 0; + if (parent == pblock) + cyclediff = itinst->info.cycle - cycleoff; + cycleoff = itinst->info.cycle; + + // new block + VuBaseBlock* pnewblock = new VuBaseBlock(); + s_listBlocks.push_back(pnewblock); + + pnewblock->startpc = startpc; + pnewblock->endpc = pblock->endpc; + pnewblock->cycles = pblock->cycles - cycleoff + cyclediff; + + pnewblock->blocks.splice(pnewblock->blocks.end(), pblock->blocks); + pnewblock->insts.splice(pnewblock->insts.end(), pblock->insts, itinst, pblock->insts.end()); + pnewblock->type = pblock->type; + + // any writebacks in the next 3 cycles also belong to original block +// for(itinst = pnewblock->insts.begin(); itinst != pnewblock->insts.end(); ) { +// if( (itinst->type & INST_DUMMY) && itinst->nParentPc >= 0 && itinst->nParentPc < (int)startpc ) { +// +// if( !(itinst->type & INST_Q_WRITE) ) +// pblock->insts.push_back(*itinst); +// itinst = pnewblock->insts.erase(itinst); +// continue; +// } +// +// ++itinst; +// } + + pbh = &recVUBlocks[s_vu][startpc/8]; + for (u32 inst = startpc; inst < pblock->endpc; inst += 8) + { + if (pbh->pblock == pblock) + pbh->pblock = pnewblock; + ++pbh; + } + + for(itinst = pnewblock->insts.begin(); itinst != pnewblock->insts.end(); itinst++) + { + itinst->info.cycle -= cycleoff; + } + + SuperVUAddWritebacks(pnewblock, pipes.listWritebacks); + + // old block + pblock->blocks.push_back(pnewblock); + pblock->endpc = startpc; + pblock->cycles = cycleoff; + pblock->type &= BLOCKTYPE_MACFLAGS; + //pblock->insts.push_back(SuperVUFlushInst()); //don't need + + return pnewblock; + } + + VuBaseBlock* pblock = new VuBaseBlock(); + s_listBlocks.push_back(pblock); + + int i = 0; + branch = 0; + pc = startpc; + pblock->startpc = startpc; + + // clear stalls (might be a prob) + memcpy(VU->fmac, pipes.fmac, sizeof(pipes.fmac)); + memcpy(&VU->fdiv, &pipes.fdiv, sizeof(pipes.fdiv)); + memcpy(&VU->efu, &pipes.efu, sizeof(pipes.efu)); + memcpy(VU->ialu, pipes.ialu, sizeof(pipes.ialu)); +// memset(VU->fmac, 0, sizeof(VU->fmac)); +// memset(&VU->fdiv, 0, sizeof(VU->fdiv)); +// memset(&VU->efu, 0, sizeof(VU->efu)); + + vucycle = 0; + + u8 macflags = 0; + + list< WRITEBACK > listWritebacks; + list< WRITEBACK >::iterator itwriteback; + list::iterator itinst; + u32 hasSecondBranch = 0; + u32 needFullStatusFlag = 0; + +#ifdef SUPERVU_WRITEBACKS + listWritebacks = pipes.listWritebacks; +#endif + + // first analysis pass for status flags + while (1) + { + u32* ptr = (u32*) & VU->Micro[pc]; + pc += 8; + int prevbranch = branch; + + if (ptr[1] & 0x40000000) + branch = 1; + + if (!(ptr[1] & 0x80000000)) // not I + { + switch (ptr[0] >> 25) + { + case 0x24: // jr + case 0x25: // jalr + case 0x20: // B + case 0x21: // BAL + case 0x28: // IBEQ + case 0x2f: // IBGEZ + case 0x2d: // IBGTZ + case 0x2e: // IBLEZ + case 0x2c: // IBLTZ + case 0x29: // IBNE + branch = 1; + break; + + case 0x14: // fseq + case 0x17: // fsor + //needFullStatusFlag = 2; + break; + + case 0x16: // fsand + if ((ptr[0]&0xc0)) + { + // sometimes full sticky bits are needed (simple series 2000 - oane chapara) + //Console.WriteLn("needSticky: %x-%x", s_pFnHeader->startpc, startpc); + needFullStatusFlag = 2; + } + break; + } + } + + if (prevbranch) + break; + + if (pc >= s_MemSize[s_vu]) + { + Console.Error("inf vu0 prog %x", startpc); + break; + } + } + + // second full pass + pc = startpc; + branch = 0; + VuInstruction* pprevinst = NULL, *pinst = NULL; + + while (1) + { + + if (pc == s_MemSize[s_vu]) + { + branch |= 8; + break; + } + + if (!branch && pbh->pblock != NULL) + { + pblock->blocks.push_back(pbh->pblock); + break; + } + + int prevbranch = branch; + + if (!prevbranch) + { + pbh->pblock = pblock; + } + else assert(prevbranch || pbh->pblock == NULL); + + pblock->insts.push_back(VuInstruction()); + + pprevinst = pinst; + pinst = &pblock->insts.back(); + pinst->pPrevInst = pprevinst; + SuperVUAnalyzeOp(VU, &pinst->info, pinst->regs); + +#ifdef SUPERVU_VIBRANCHDELAY + if (pinst->regs[0].pipe == VUPIPE_BRANCH && pblock->insts.size() > 1) + { + + VuInstruction* pdelayinst = getDelayInst(pinst); + if (pdelayinst) + { + pdelayinst->type |= INST_CACHE_VI; + + // find the correct register + u32 mask = pdelayinst->regs[0].VIwrite & pinst->regs[0].VIread; + for (int i = 0; i < 16; ++i) + { + if (mask & (1 << i)) + { + pdelayinst->vicached = i; + break; + } + } + + pinst->vicached = pdelayinst->vicached; + } + } +#endif + + if (prevbranch) + { + if (pinst->regs[0].pipe == VUPIPE_BRANCH) + hasSecondBranch = 1; + pinst->type |= INST_BRANCH_DELAY; + } + + // check write back + for (itwriteback = listWritebacks.begin(); itwriteback != listWritebacks.end();) + { + if (pinst->info.cycle >= itwriteback->cycle) + { + itinst = pblock->insts.insert(--pblock->insts.end(), VuInstruction()); + itwriteback->InitInst(&(*itinst), pinst->info.cycle); + itwriteback = listWritebacks.erase(itwriteback); + } + else ++itwriteback; + } + + // add new writebacks + WRITEBACK w; + const u32 allflags = (1 << REG_CLIP_FLAG) | (1 << REG_MAC_FLAG) | (1 << REG_STATUS_FLAG); + for (int j = 0; j < 2; ++j) w.viwrite[j] = pinst->regs[j].VIwrite & allflags; + + if (pinst->info.macflag & VUOP_WRITE) w.viwrite[1] |= (1 << REG_MAC_FLAG); + if (pinst->info.statusflag & VUOP_WRITE) w.viwrite[1] |= (1 << REG_STATUS_FLAG); + + if ((pinst->info.macflag | pinst->info.statusflag) & VUOP_READ) + macflags = 1; + if (pinst->regs[0].VIread & ((1 << REG_MAC_FLAG) | (1 << REG_STATUS_FLAG))) + macflags = 1; + +// if( pinst->regs[1].pipe == VUPIPE_FMAC && (pinst->regs[1].VFwrite==0&&!(pinst->regs[1].VIwrite&(1<regs[0].VIread |= (1<VIwrite |= lregs->VIwrite & (1<info.statusflag&VUOP_WRITE) && !(pinst->regs[0].VIwrite&(1 << REG_STATUS_FLAG))) && needFullStatusFlag) + { + // don't read if first inst + if (needFullStatusFlag == 1) + w.viread[1] |= (1 << REG_STATUS_FLAG); + else --needFullStatusFlag; + } + + for (int j = 0; j < 2; ++j) + { + w.viread[j] |= pinst->regs[j].VIread & allflags; + + if ((pinst->regs[j].VIread&(1 << REG_STATUS_FLAG)) && (pinst->regs[j].VIwrite&(1 << REG_STATUS_FLAG))) + { + // don't need the read anymore + pinst->regs[j].VIread &= ~(1 << REG_STATUS_FLAG); + } + if ((pinst->regs[j].VIread&(1 << REG_MAC_FLAG)) && (pinst->regs[j].VIwrite&(1 << REG_MAC_FLAG))) + { + // don't need the read anymore + pinst->regs[j].VIread &= ~(1 << REG_MAC_FLAG); + } + + pinst->regs[j].VIwrite &= ~allflags; + } + + if (pinst->info.macflag & VUOP_READ) w.viread[1] |= 1 << REG_MAC_FLAG; + if (pinst->info.statusflag & VUOP_READ) w.viread[1] |= 1 << REG_STATUS_FLAG; + + w.nParentPc = pc - 8; + w.cycle = pinst->info.cycle + 4; + listWritebacks.push_back(w); + } + + if (pinst->info.q&VUOP_READ) pinst->type |= INST_Q_READ; + if (pinst->info.p&VUOP_READ) pinst->type |= INST_P_READ; + + if (pinst->info.q&VUOP_WRITE) + { + pinst->pqcycles = QWaitTimes[pinst->info.pqinst] + 1; + + memset(&w, 0, sizeof(w)); + w.nParentPc = pc - 8; + w.cycle = pinst->info.cycle + pinst->pqcycles; + w.viwrite[0] = 1 << REG_Q; + listWritebacks.push_back(w); + } + if (pinst->info.p&VUOP_WRITE) + pinst->pqcycles = PWaitTimes[pinst->info.pqinst] + 1; + + if (prevbranch) + { + break; + } + + // make sure there is always a branch + // sensible soccer overflows on vu0, so increase the limit... + if ((s_vu == 1 && i >= 0x799) || (s_vu == 0 && i >= 0x201)) + { + Console.Error("VuRec base block doesn't terminate!"); + assert(0); + break; + } + + i++; + pbh++; + } + + if (macflags) + pblock->type |= BLOCKTYPE_MACFLAGS; + + pblock->endpc = pc; + u32 lastpc = pc; + + pblock->cycles = vucycle; + +#ifdef SUPERVU_WRITEBACKS + if (!branch || (branch&8)) +#endif + { + // flush writebacks + if (listWritebacks.size() > 0) + { + listWritebacks.sort(WRITEBACK::SortWritebacks); + for (itwriteback = listWritebacks.begin(); itwriteback != listWritebacks.end(); ++itwriteback) + { + if (itwriteback->viwrite[0] & (1 << REG_Q)) + { + // ignore all Q writebacks + continue; + } + + pblock->insts.push_back(VuInstruction()); + itwriteback->InitInst(&pblock->insts.back(), vucycle); + } + + listWritebacks.clear(); + } + } + + if (!branch) return pblock; + + if (branch & 8) + { + // what if also a jump? + pblock->type |= BLOCKTYPE_EOP | BLOCKTYPE_HASEOP; + + // add an instruction to flush p and q (if written) + pblock->insts.push_back(SuperVUFlushInst()); + return pblock; + } + + // it is a (cond) branch or a jump + u32 vucode = *(u32*)(VU->Micro + lastpc - 16); + int bpc = _recbranchAddr(vucode) - 8; + + VUPIPELINES newpipes; + memcpy(newpipes.fmac, VU->fmac, sizeof(newpipes.fmac)); + memcpy(&newpipes.fdiv, &VU->fdiv, sizeof(newpipes.fdiv)); + memcpy(&newpipes.efu, &VU->efu, sizeof(newpipes.efu)); + memcpy(newpipes.ialu, VU->ialu, sizeof(newpipes.ialu)); + + for (i = 0; i < 8; ++i) newpipes.fmac[i].sCycle -= vucycle; + newpipes.fdiv.sCycle -= vucycle; + newpipes.efu.sCycle -= vucycle; + for (i = 0; i < 8; ++i) newpipes.ialu[i].sCycle -= vucycle; + + if (listWritebacks.size() > 0) + { + // flush all when jumping, send down the pipe when in branching + bool bFlushWritebacks = (vucode >> 25) == 0x24 || (vucode >> 25) == 0x25;//||(vucode>>25)==0x20||(vucode>>25)==0x21; + + listWritebacks.sort(WRITEBACK::SortWritebacks); + for (itwriteback = listWritebacks.begin(); itwriteback != listWritebacks.end(); ++itwriteback) + { + if (itwriteback->viwrite[0] & (1 << REG_Q)) + { + // ignore all Q writebacks + continue; + } + + if (itwriteback->cycle < vucycle || bFlushWritebacks) + { + pblock->insts.push_back(VuInstruction()); + itwriteback->InitInst(&pblock->insts.back(), vucycle); + } + else + { + newpipes.listWritebacks.push_back(*itwriteback); + newpipes.listWritebacks.back().cycle -= vucycle; + } + } + } + + if (newpipes.listWritebacks.size() > 0) // other blocks might read the mac flags + pblock->type |= BLOCKTYPE_MACFLAGS; + + u32 firstbranch = vucode >> 25; + switch (firstbranch) + { + case 0x24: // jr + pblock->type |= BLOCKTYPE_EOP; // jump out of procedure, since not returning, set EOP + pblock->insts.push_back(SuperVUFlushInst()); + firstbranch = 0xff; //Non-Conditional Jump + break; + + case 0x25: // jalr + { + // linking, so will return to procedure + pblock->insts.push_back(SuperVUFlushInst()); + + VuBaseBlock* pjumpblock = SuperVUBuildBlocks(pblock, lastpc, newpipes); + + // update pblock since could have changed + pblock = recVUBlocks[s_vu][lastpc/8-2].pblock; + assert(pblock != NULL); + + pblock->blocks.push_back(pjumpblock); + firstbranch = 0xff; //Non-Conditional Jump + break; + } + case 0x20: // B + { + VuBaseBlock* pbranchblock = SuperVUBuildBlocks(pblock, bpc, newpipes); + + // update pblock since could have changed + pblock = recVUBlocks[s_vu][lastpc/8-2].pblock; + assert(pblock != NULL); + + pblock->blocks.push_back(pbranchblock); + firstbranch = 0xff; //Non-Conditional Jump + break; + } + case 0x21: // BAL + { + VuBaseBlock* pbranchblock = SuperVUBuildBlocks(pblock, bpc, newpipes); + + // update pblock since could have changed + pblock = recVUBlocks[s_vu][lastpc/8-2].pblock; + assert(pblock != NULL); + pblock->blocks.push_back(pbranchblock); + firstbranch = 0xff; //Non-Conditional Jump + break; + } + case 0x28: // IBEQ + case 0x2f: // IBGEZ + case 0x2d: // IBGTZ + case 0x2e: // IBLEZ + case 0x2c: // IBLTZ + case 0x29: // IBNE + { + VuBaseBlock* pbranchblock = SuperVUBuildBlocks(pblock, bpc, newpipes); + + // update pblock since could have changed + pblock = recVUBlocks[s_vu][lastpc/8-2].pblock; + assert(pblock != NULL); + pblock->blocks.push_back(pbranchblock); + + // if has a second branch that is B or BAL, skip this + u32 secondbranch = (*(u32*)(VU->Micro + lastpc - 8)) >> 25; + if (!hasSecondBranch || (secondbranch != 0x21 && secondbranch != 0x20)) + { + pbranchblock = SuperVUBuildBlocks(pblock, lastpc, newpipes); + + pblock = recVUBlocks[s_vu][lastpc/8-2].pblock; + pblock->blocks.push_back(pbranchblock); + } + + break; + } + default: + assert(pblock->blocks.size() == 1); + break; + } + + pblock = recVUBlocks[s_vu][lastpc/8-2].pblock; + +#ifdef SUPERVU_VIBRANCHDELAY +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +///// NOTE! This could still be a hack for KH2/GoW, but until we know how it properly works, this will do for now./// +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + if (hasSecondBranch && firstbranch != 0xff) //check the previous jump was conditional and there is a second branch + { +#else + if (hasSecondBranch) + { +#endif + + u32 vucode = *(u32*)(VU->Micro + lastpc - 8); + pc = lastpc; + int bpc = _recbranchAddr(vucode); + + switch (vucode >> 25) + { + case 0x24: // jr + Console.Error("svurec bad jr jump!"); + assert(0); + break; + + case 0x25: // jalr + { + Console.Error("svurec bad jalr jump!"); + assert(0); + break; + } + case 0x20: // B + { + VuBaseBlock* pbranchblock = SuperVUBuildBlocks(pblock, bpc, newpipes); + + // update pblock since could have changed + pblock = recVUBlocks[s_vu][lastpc/8-2].pblock; + + pblock->blocks.push_back(pbranchblock); + break; + } + case 0x21: // BAL + { + VuBaseBlock* pbranchblock = SuperVUBuildBlocks(pblock, bpc, newpipes); + + // replace instead of pushing a new block + pblock = recVUBlocks[s_vu][lastpc/8-2].pblock; + pblock->blocks.push_back(pbranchblock); + break; + } + case 0x28: // IBEQ + case 0x2f: // IBGEZ + case 0x2d: // IBGTZ + case 0x2e: // IBLEZ + case 0x2c: // IBLTZ + case 0x29: // IBNE + { + VuBaseBlock* pbranchblock = SuperVUBuildBlocks(pblock, bpc, newpipes); + + // update pblock since could have changed + pblock = recVUBlocks[s_vu][lastpc/8-2].pblock; + pblock->blocks.push_back(pbranchblock); + + // only add the block if the previous branch doesn't include the next instruction (ie, if a direct jump) + if (firstbranch == 0x24 || firstbranch == 0x25 || firstbranch == 0x20 || firstbranch == 0x21) + { + pbranchblock = SuperVUBuildBlocks(pblock, lastpc, newpipes); + + pblock = recVUBlocks[s_vu][lastpc/8-2].pblock; + pblock->blocks.push_back(pbranchblock); + } + + break; + } + + jNO_DEFAULT; + } + } + + return recVUBlocks[s_vu][startpc/8].pblock; +} + +static void SuperVUInitLiveness(VuBaseBlock* pblock) +{ + list::iterator itinst, itnext; + + assert(pblock->insts.size() > 0); + + for (itinst = pblock->insts.begin(); itinst != pblock->insts.end(); ++itinst) + { + + if (itinst->type & INST_DUMMY_) + { + itinst->addvars[0] = itinst->addvars[1] = 0xffffffff; + itinst->livevars[0] = itinst->livevars[1] = 0xffffffff; + itinst->keepvars[0] = itinst->keepvars[1] = 0xffffffff; + itinst->usedvars[0] = itinst->usedvars[1] = 0; + } + else + { + itinst->addvars[0] = itinst->regs[0].VIread | itinst->regs[1].VIread; + itinst->addvars[1] = (itinst->regs[0].VFread0 ? (1 << itinst->regs[0].VFread0) : 0) | + (itinst->regs[0].VFread1 ? (1 << itinst->regs[0].VFread1) : 0) | + (itinst->regs[1].VFread0 ? (1 << itinst->regs[1].VFread0) : 0) | + (itinst->regs[1].VFread1 ? (1 << itinst->regs[1].VFread1) : 0); + + // vf0 is not handled by VFread + if (!itinst->regs[0].VFread0 && (itinst->regs[0].VIread & (1 << REG_VF0_FLAG))) itinst->addvars[1] |= 1; + if (!itinst->regs[1].VFread0 && (itinst->regs[1].VIread & (1 << REG_VF0_FLAG))) itinst->addvars[1] |= 1; + if (!itinst->regs[0].VFread1 && (itinst->regs[0].VIread & (1 << REG_VF0_FLAG)) && itinst->regs[0].VFr1xyzw != 0xff) itinst->addvars[1] |= 1; + if (!itinst->regs[1].VFread1 && (itinst->regs[1].VIread & (1 << REG_VF0_FLAG)) && itinst->regs[1].VFr1xyzw != 0xff) itinst->addvars[1] |= 1; + + + u32 vfwrite = 0; + if (itinst->regs[0].VFwrite != 0) + { + if (itinst->regs[0].VFwxyzw != 0xf) itinst->addvars[1] |= 1 << itinst->regs[0].VFwrite; + else vfwrite |= 1 << itinst->regs[0].VFwrite; + } + if (itinst->regs[1].VFwrite != 0) + { + if (itinst->regs[1].VFwxyzw != 0xf) itinst->addvars[1] |= 1 << itinst->regs[1].VFwrite; + else vfwrite |= 1 << itinst->regs[1].VFwrite; + } + if ((itinst->regs[1].VIwrite & (1 << REG_ACC_FLAG)) && itinst->regs[1].VFwxyzw != 0xf) + itinst->addvars[1] |= 1 << REG_ACC_FLAG; + + u32 viwrite = (itinst->regs[0].VIwrite | itinst->regs[1].VIwrite); + + itinst->usedvars[0] = itinst->addvars[0] | viwrite; + itinst->usedvars[1] = itinst->addvars[1] | vfwrite; + +// itinst->addvars[0] &= ~viwrite; +// itinst->addvars[1] &= ~vfwrite; + itinst->keepvars[0] = ~viwrite; + itinst->keepvars[1] = ~vfwrite; + } + } + + itinst = --pblock->insts.end(); + while (itinst != pblock->insts.begin()) + { + itnext = itinst; + --itnext; + + itnext->usedvars[0] |= itinst->usedvars[0]; + itnext->usedvars[1] |= itinst->usedvars[1]; + + itinst = itnext; + } +} + +u32 COMPUTE_LIVE(u32 R, u32 K, u32 L) +{ + u32 live = R | ((L) & (K)); + // special process mac and status flags + // only propagate liveness if doesn't write to the flag + if (!(L&(1 << REG_STATUS_FLAG)) && !(K&(1 << REG_STATUS_FLAG))) + live &= ~(1 << REG_STATUS_FLAG); + if (!(L&(1 << REG_MAC_FLAG)) && !(K&(1 << REG_MAC_FLAG))) + live &= ~(1 << REG_MAC_FLAG); + return live;//|(1<::reverse_iterator itblock; + list::iterator itinst, itnext; + VuBaseBlock::LISTBLOCKS::iterator itchild; + + u32 livevars[2]; + + do + { + changed = FALSE; + for (itblock = s_listBlocks.rbegin(); itblock != s_listBlocks.rend(); ++itblock) + { + + u32 newlive; + VuBaseBlock* pb = *itblock; + + // the last inst relies on the neighbor's insts + itinst = --pb->insts.end(); + + if (pb->blocks.size() > 0) + { + livevars[0] = 0; + livevars[1] = 0; + for (itchild = pb->blocks.begin(); itchild != pb->blocks.end(); ++itchild) + { + VuInstruction& front = (*itchild)->insts.front(); + livevars[0] |= front.livevars[0]; + livevars[1] |= front.livevars[1]; + } + + newlive = COMPUTE_LIVE(itinst->addvars[0], itinst->keepvars[0], livevars[0]); + + // should propagate status flags whose parent insts are not in this block +// if( itinst->nParentPc >= 0 && (itinst->type & (INST_STATUS_WRITE|INST_MAC_WRITE)) ) +// newlive |= livevars[0]&((1<livevars[0] != newlive) + { + changed = TRUE; + itinst->livevars[0] = newlive; + } + + newlive = COMPUTE_LIVE(itinst->addvars[1], itinst->keepvars[1], livevars[1]); + if (itinst->livevars[1] != newlive) + { + changed = TRUE; + itinst->livevars[1] = newlive; + } + } + + while (itinst != pb->insts.begin()) + { + + itnext = itinst; + --itnext; + + newlive = COMPUTE_LIVE(itnext->addvars[0], itnext->keepvars[0], itinst->livevars[0]); + + // should propagate status flags whose parent insts are not in this block +// if( itnext->nParentPc >= 0 && (itnext->type & (INST_STATUS_WRITE|INST_MAC_WRITE)) && !(itinst->type & (INST_STATUS_WRITE|INST_MAC_WRITE)) ) +// newlive |= itinst->livevars[0]&((1<livevars[0] != newlive) + { + changed = TRUE; + itnext->livevars[0] = newlive; + itnext->livevars[1] = COMPUTE_LIVE(itnext->addvars[1], itnext->keepvars[1], itinst->livevars[1]); + } + else + { + newlive = COMPUTE_LIVE(itnext->addvars[1], itnext->keepvars[1], itinst->livevars[1]); + if (itnext->livevars[1] != newlive) + { + changed = TRUE; + itnext->livevars[1] = newlive; + } + } + + itinst = itnext; + } + +// if( (livevars[0] | itinst->livevars[0]) != itinst->livevars[0] ) { +// changed = TRUE; +// itinst->livevars[0] |= livevars[0]; +// } +// if( (livevars[1] | itinst->livevars[1]) != itinst->livevars[1] ) { +// changed = TRUE; +// itinst->livevars[1] |= livevars[1]; +// } +// +// while( itinst != pb->insts.begin() ) { +// +// itnext = itinst; --itnext; +// if( (itnext->livevars[0] | (itinst->livevars[0] & itnext->keepvars[0])) != itnext->livevars[0] ) { +// changed = TRUE; +// itnext->livevars[0] |= itinst->livevars[0] & itnext->keepvars[0]; +// itnext->livevars[1] |= itinst->livevars[1] & itnext->keepvars[1]; +// } +// else if( (itnext->livevars[1] | (itinst->livevars[1] & itnext->keepvars[1])) != itnext->livevars[1] ) { +// changed = TRUE; +// itnext->livevars[1] |= itinst->livevars[1] & itnext->keepvars[1]; +// } +// +// itinst = itnext; +// } + } + + } + while (changed); +} + +static void SuperVUEliminateDeadCode() +{ + list::iterator itblock; + VuBaseBlock::LISTBLOCKS::iterator itchild; + list::iterator itinst, itnext; + list listParents; + list::iterator itparent; + + for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) + { + +#ifdef PCSX2_DEBUG + u32 startpc = (*itblock)->startpc; + u32 curpc = startpc; +#endif + + itnext = (*itblock)->insts.begin(); + itinst = itnext++; + while (itnext != (*itblock)->insts.end()) + { + if (itinst->type & (INST_CLIP_WRITE | INST_MAC_WRITE | INST_STATUS_WRITE)) + { + u32 live0 = itnext->livevars[0]; + if (itinst->nParentPc >= 0 && itnext->nParentPc >= 0 && itinst->nParentPc != itnext->nParentPc) // superman returns + { + // take the live vars from the next next inst + list::iterator itnextnext = itnext; + ++itnextnext; + if (itnextnext != (*itblock)->insts.end()) + { + live0 = itnextnext->livevars[0]; + } + } + + itinst->regs[0].VIwrite &= live0; + itinst->regs[1].VIwrite &= live0; + + u32 viwrite = itinst->regs[0].VIwrite | itinst->regs[1].VIwrite; + + (*itblock)->GetInstsAtPc(itinst->nParentPc, listParents); + int removetype = 0; + + for(itparent = listParents.begin(); itparent != listParents.end(); itparent++) + { + VuInstruction* parent = *itparent; + + if (viwrite & (1 << REG_CLIP_FLAG)) + { + parent->regs[0].VIwrite |= (itinst->regs[0].VIwrite & (1 << REG_CLIP_FLAG)); + parent->regs[1].VIwrite |= (itinst->regs[1].VIwrite & (1 << REG_CLIP_FLAG)); + } + else + removetype |= INST_CLIP_WRITE; + + if (parent->info.macflag && (itinst->type & INST_MAC_WRITE)) + { + if (!(viwrite&(1 << REG_MAC_FLAG))) + { + //parent->info.macflag = 0; + // parent->regs[0].VIwrite &= ~(1<regs[1].VIwrite &= ~(1<regs[0].VIwrite & (1 << REG_MAC_FLAG)) && !(parent->regs[1].VIwrite & (1 << REG_MAC_FLAG))); +#endif + // if VUPIPE_FMAC and destination is vf00, probably need to keep the mac flag + if (parent->regs[1].pipe == VUPIPE_FMAC && (parent->regs[1].VFwrite == 0 && !(parent->regs[1].VIwrite&(1 << REG_ACC_FLAG)))) + { + parent->regs[0].VIwrite |= ((1 << REG_MAC_FLAG)); + parent->regs[1].VIwrite |= ((1 << REG_MAC_FLAG)); + } + else + removetype |= INST_MAC_WRITE; + } + else + { + parent->regs[0].VIwrite |= (itinst->regs[0].VIwrite & (1 << REG_MAC_FLAG)); + parent->regs[1].VIwrite |= (itinst->regs[1].VIwrite & (1 << REG_MAC_FLAG)); + } + } + else removetype |= INST_MAC_WRITE; + + if (parent->info.statusflag && (itinst->type & INST_STATUS_WRITE)) + { + if (!(viwrite&(1 << REG_STATUS_FLAG))) + { + //parent->info.statusflag = 0; + // parent->regs[0].VIwrite &= ~(1<regs[1].VIwrite &= ~(1<regs[0].VIwrite & (1 << REG_STATUS_FLAG)) && !(parent->regs[1].VIwrite & (1 << REG_STATUS_FLAG))); +#endif + if (parent->regs[1].pipe == VUPIPE_FMAC && (parent->regs[1].VFwrite == 0 && !(parent->regs[1].VIwrite&(1 << REG_ACC_FLAG)))) + { + parent->regs[0].VIwrite |= ((1 << REG_STATUS_FLAG)); + parent->regs[1].VIwrite |= ((1 << REG_STATUS_FLAG)); + } + else + removetype |= INST_STATUS_WRITE; + } + else + { + parent->regs[0].VIwrite |= (itinst->regs[0].VIwrite & (1 << REG_STATUS_FLAG)); + parent->regs[1].VIwrite |= (itinst->regs[1].VIwrite & (1 << REG_STATUS_FLAG)); + } + } + else removetype |= INST_STATUS_WRITE; + } + + itinst->type &= ~removetype; + if (itinst->type == 0) + { + itnext = (*itblock)->insts.erase(itinst); + itinst = itnext++; + continue; + } + } +#ifdef PCSX2_DEBUG + else + { + curpc += 8; + } +#endif + itinst = itnext; + ++itnext; + } + + if (itinst->type & INST_DUMMY) + { + // last inst with the children + u32 mask = 0; + for (itchild = (*itblock)->blocks.begin(); itchild != (*itblock)->blocks.end(); ++itchild) + { + mask |= (*itchild)->insts.front().livevars[0]; + } + itinst->regs[0].VIwrite &= mask; + itinst->regs[1].VIwrite &= mask; + u32 viwrite = itinst->regs[0].VIwrite | itinst->regs[1].VIwrite; + + if (itinst->nParentPc >= 0) + { + + (*itblock)->GetInstsAtPc(itinst->nParentPc, listParents); + int removetype = 0; + + for(itparent = listParents.begin(); itparent != listParents.end(); itparent++) + { + VuInstruction* parent = *itparent; + + if (viwrite & (1 << REG_CLIP_FLAG)) + { + parent->regs[0].VIwrite |= (itinst->regs[0].VIwrite & (1 << REG_CLIP_FLAG)); + parent->regs[1].VIwrite |= (itinst->regs[1].VIwrite & (1 << REG_CLIP_FLAG)); + } + else removetype |= INST_CLIP_WRITE; + + if (parent->info.macflag && (itinst->type & INST_MAC_WRITE)) + { + if (!(viwrite&(1 << REG_MAC_FLAG))) + { + //parent->info.macflag = 0; +#ifndef SUPERVU_WRITEBACKS + assert(!(parent->regs[0].VIwrite & (1 << REG_MAC_FLAG)) && !(parent->regs[1].VIwrite & (1 << REG_MAC_FLAG))); +#endif + removetype |= INST_MAC_WRITE; + } + else + { + parent->regs[0].VIwrite |= (itinst->regs[0].VIwrite & (1 << REG_MAC_FLAG)); + parent->regs[1].VIwrite |= (itinst->regs[1].VIwrite & (1 << REG_MAC_FLAG)); + } + } + else removetype |= INST_MAC_WRITE; + + if (parent->info.statusflag && (itinst->type & INST_STATUS_WRITE)) + { + if (!(viwrite&(1 << REG_STATUS_FLAG))) + { + //parent->info.statusflag = 0; +#ifndef SUPERVU_WRITEBACKS + assert(!(parent->regs[0].VIwrite & (1 << REG_STATUS_FLAG)) && !(parent->regs[1].VIwrite & (1 << REG_STATUS_FLAG))); +#endif + removetype |= INST_STATUS_WRITE; + } + else + { + parent->regs[0].VIwrite |= (itinst->regs[0].VIwrite & (1 << REG_STATUS_FLAG)); + parent->regs[1].VIwrite |= (itinst->regs[1].VIwrite & (1 << REG_STATUS_FLAG)); + } + } + else removetype |= INST_STATUS_WRITE; + } + + itinst->type &= ~removetype; + if (itinst->type == 0) + { + (*itblock)->insts.erase(itinst); + } + } + } + } +} + +void VuBaseBlock::AssignVFRegs() +{ + int i; + VuBaseBlock::LISTBLOCKS::iterator itchild; + list::iterator itblock; + list::iterator itinst, itnext, itinst2; + + // init the start regs + if (type & BLOCKTYPE_ANALYZED) return; // nothing changed + memcpy(xmmregs, startregs, sizeof(xmmregs)); + + if (type & BLOCKTYPE_ANALYZED) + { + // check if changed + for (i = 0; i < iREGCNT_XMM; ++i) + { + if (xmmregs[i].inuse != startregs[i].inuse) + break; + if (xmmregs[i].inuse && (xmmregs[i].reg != startregs[i].reg || xmmregs[i].type != startregs[i].type)) + break; + } + + if (i == iREGCNT_XMM) return; // nothing changed + } + + u8* oldX86 = x86Ptr; + + for(itinst = insts.begin(); itinst != insts.end(); itinst++) + { + + if (itinst->type & INST_DUMMY) continue; + + // reserve, go from upper to lower + int lastwrite = -1; + + for (i = 1; i >= 0; --i) + { + _VURegsNum* regs = itinst->regs + i; + + + // redo the counters so that the proper regs are released + for (int j = 0; j < iREGCNT_XMM; ++j) + { + if (xmmregs[j].inuse) + { + if (xmmregs[j].type == XMMTYPE_VFREG) + { + int count = 0; + itinst2 = itinst; + + if (i) + { + if (itinst2->regs[0].VFread0 == xmmregs[j].reg || itinst2->regs[0].VFread1 == xmmregs[j].reg || itinst2->regs[0].VFwrite == xmmregs[j].reg) + { + itinst2 = insts.end(); + break; + } + else + { + ++count; + ++itinst2; + } + } + + while (itinst2 != insts.end()) + { + if (itinst2->regs[0].VFread0 == xmmregs[j].reg || itinst2->regs[0].VFread1 == xmmregs[j].reg || itinst2->regs[0].VFwrite == xmmregs[j].reg || + itinst2->regs[1].VFread0 == xmmregs[j].reg || itinst2->regs[1].VFread1 == xmmregs[j].reg || itinst2->regs[1].VFwrite == xmmregs[j].reg) + break; + + ++count; + ++itinst2; + } + xmmregs[j].counter = 1000 - count; + } + else + { + assert(xmmregs[j].type == XMMTYPE_ACC); + + int count = 0; + itinst2 = itinst; + + if (i) ++itinst2; // acc isn't used in lower insts + + while (itinst2 != insts.end()) + { + assert(!((itinst2->regs[0].VIread | itinst2->regs[0].VIwrite) & (1 << REG_ACC_FLAG))); + + if ((itinst2->regs[1].VIread | itinst2->regs[1].VIwrite) & (1 << REG_ACC_FLAG)) + break; + + ++count; + ++itinst2; + } + + xmmregs[j].counter = 1000 - count; + } + } + } + + if (regs->VFread0) _addNeededVFtoXMMreg(regs->VFread0); + if (regs->VFread1) _addNeededVFtoXMMreg(regs->VFread1); + if (regs->VFwrite) _addNeededVFtoXMMreg(regs->VFwrite); + if (regs->VIread & (1 << REG_ACC_FLAG)) _addNeededACCtoXMMreg(); + if (regs->VIread & (1 << REG_VF0_FLAG)) _addNeededVFtoXMMreg(0); + + // alloc + itinst->vfread0[i] = itinst->vfread1[i] = itinst->vfwrite[i] = itinst->vfacc[i] = -1; + itinst->vfflush[i] = -1; + + if (regs->VFread0) + itinst->vfread0[i] = _allocVFtoXMMreg(VU, -1, regs->VFread0, 0); + else if (regs->VIread & (1 << REG_VF0_FLAG)) + itinst->vfread0[i] = _allocVFtoXMMreg(VU, -1, 0, 0); + + if (regs->VFread1) + itinst->vfread1[i] = _allocVFtoXMMreg(VU, -1, regs->VFread1, 0); + else if ((regs->VIread & (1 << REG_VF0_FLAG)) && regs->VFr1xyzw != 0xff) + itinst->vfread1[i] = _allocVFtoXMMreg(VU, -1, 0, 0); + + if (regs->VIread & (1 << REG_ACC_FLAG)) itinst->vfacc[i] = _allocACCtoXMMreg(VU, -1, 0); + + int reusereg = -1; // 0 - VFwrite, 1 - VFAcc + + if (regs->VFwrite) + { + assert(!(regs->VIwrite&(1 << REG_ACC_FLAG))); + + if (regs->VFwxyzw == 0xf) + { + itinst->vfwrite[i] = _checkXMMreg(XMMTYPE_VFREG, regs->VFwrite, 0); + if (itinst->vfwrite[i] < 0) reusereg = 0; + } + else + { + itinst->vfwrite[i] = _allocVFtoXMMreg(VU, -1, regs->VFwrite, 0); + } + } + else if (regs->VIwrite & (1 << REG_ACC_FLAG)) + { + + if (regs->VFwxyzw == 0xf) + { + itinst->vfacc[i] = _checkXMMreg(XMMTYPE_ACC, 0, 0); + if (itinst->vfacc[i] < 0) reusereg = 1; + } + else + { + itinst->vfacc[i] = _allocACCtoXMMreg(VU, -1, 0); + } + } + + if (reusereg >= 0) + { + // reuse + itnext = itinst; + itnext++; + + u8 type = reusereg ? XMMTYPE_ACC : XMMTYPE_VFREG; + u8 reg = reusereg ? 0 : regs->VFwrite; + + if (itinst->vfacc[i] >= 0 && lastwrite != itinst->vfacc[i] && + (itnext == insts.end() || ((regs->VIread&(1 << REG_ACC_FLAG)) && (!(itnext->usedvars[0]&(1 << REG_ACC_FLAG)) || !(itnext->livevars[0]&(1 << REG_ACC_FLAG)))))) + { + + assert(reusereg == 0); + if (itnext == insts.end() || (itnext->livevars[0]&(1 << REG_ACC_FLAG))) _freeXMMreg(itinst->vfacc[i]); + xmmregs[itinst->vfacc[i]].inuse = 1; + xmmregs[itinst->vfacc[i]].reg = reg; + xmmregs[itinst->vfacc[i]].type = type; + xmmregs[itinst->vfacc[i]].mode = 0; + itinst->vfwrite[i] = itinst->vfacc[i]; + } + else if (itinst->vfread0[i] >= 0 && lastwrite != itinst->vfread0[i] && + (itnext == insts.end() || (regs->VFread0 > 0 && (!(itnext->usedvars[1]&(1 << regs->VFread0)) || !(itnext->livevars[1]&(1 << regs->VFread0)))))) + { + + if (itnext == insts.end() || (itnext->livevars[1]®s->VFread0)) _freeXMMreg(itinst->vfread0[i]); + + xmmregs[itinst->vfread0[i]].inuse = 1; + xmmregs[itinst->vfread0[i]].reg = reg; + xmmregs[itinst->vfread0[i]].type = type; + xmmregs[itinst->vfread0[i]].mode = 0; + + if (reusereg) + itinst->vfacc[i] = itinst->vfread0[i]; + else + itinst->vfwrite[i] = itinst->vfread0[i]; + } + else if (itinst->vfread1[i] >= 0 && lastwrite != itinst->vfread1[i] && + (itnext == insts.end() || (regs->VFread1 > 0 && (!(itnext->usedvars[1]&(1 << regs->VFread1)) || !(itnext->livevars[1]&(1 << regs->VFread1)))))) + { + + if (itnext == insts.end() || (itnext->livevars[1]®s->VFread1)) _freeXMMreg(itinst->vfread1[i]); + + xmmregs[itinst->vfread1[i]].inuse = 1; + xmmregs[itinst->vfread1[i]].reg = reg; + xmmregs[itinst->vfread1[i]].type = type; + xmmregs[itinst->vfread1[i]].mode = 0; + if (reusereg) + itinst->vfacc[i] = itinst->vfread1[i]; + else + itinst->vfwrite[i] = itinst->vfread1[i]; + } + else + { + if (reusereg) + itinst->vfacc[i] = _allocACCtoXMMreg(VU, -1, 0); + else + itinst->vfwrite[i] = _allocVFtoXMMreg(VU, -1, regs->VFwrite, 0); + } + } + + if (itinst->vfwrite[i] >= 0) lastwrite = itinst->vfwrite[i]; + else if (itinst->vfacc[i] >= 0) lastwrite = itinst->vfacc[i]; + + // always alloc at least 1 temp reg + int free0 = (i || regs->VFwrite || regs->VFread0 || regs->VFread1 || (regs->VIwrite & (1 << REG_ACC_FLAG)) || (regs->VIread & (1 << REG_VF0_FLAG))) + ? _allocTempXMMreg(XMMT_FPS, -1) : -1; + int free1 = 0, free2 = 0; + + if (i == 0 && itinst->vfwrite[1] >= 0 && (itinst->vfread0[0] == itinst->vfwrite[1] || itinst->vfread1[0] == itinst->vfwrite[1])) + { + itinst->vfflush[i] = _allocTempXMMreg(XMMT_FPS, -1); + } + + if (i == 1 && (regs->VIwrite & (1 << REG_CLIP_FLAG))) + { + // CLIP inst, need two extra regs + if (free0 < 0) free0 = _allocTempXMMreg(XMMT_FPS, -1); + + free1 = _allocTempXMMreg(XMMT_FPS, -1); + free2 = _allocTempXMMreg(XMMT_FPS, -1); + _freeXMMreg(free1); + _freeXMMreg(free2); + } + else if (regs->VIwrite & (1 << REG_P)) + { + // EFU inst, need extra reg + free1 = _allocTempXMMreg(XMMT_FPS, -1); + if (free0 == -1) free0 = free1; + _freeXMMreg(free1); + } + + if (itinst->vfflush[i] >= 0) _freeXMMreg(itinst->vfflush[i]); + if (free0 >= 0) _freeXMMreg(free0); + + itinst->vffree[i] = (free0 & 0xf) | (free1 << 8) | (free2 << 16); + if (free0 == -1) itinst->vffree[i] |= VFFREE_INVALID0; + + _clearNeededXMMregs(); + } + } + + assert(x86Ptr == oldX86); + u32 analyzechildren = !(type & BLOCKTYPE_ANALYZED); + type |= BLOCKTYPE_ANALYZED; + + //memset(endregs, 0, sizeof(endregs)); + + if (analyzechildren) + { + for(itchild = blocks.begin(); itchild != blocks.end(); itchild++) + { + (*itchild)->AssignVFRegs(); + } + } +} + +struct MARKOVBLANKET +{ + list parents; + list children; +}; + +static MARKOVBLANKET s_markov; + +void VuBaseBlock::AssignVIRegs(int parent) +{ + const int maxregs = 6; + + if (parent) + { + if ((type&BLOCKTYPE_ANALYZEDPARENT)) + return; + + type |= BLOCKTYPE_ANALYZEDPARENT; + s_markov.parents.push_back(this); + for (LISTBLOCKS::iterator it = blocks.begin(); it != blocks.end(); ++it) + { + (*it)->AssignVIRegs(0); + } + return; + } + + if ((type&BLOCKTYPE_ANALYZED)) + return; + + // child + assert(allocX86Regs == -1); + allocX86Regs = s_vecRegArray.size(); + s_vecRegArray.resize(allocX86Regs + iREGCNT_GPR); + + _x86regs* pregs = &s_vecRegArray[allocX86Regs]; + memset(pregs, 0, sizeof(_x86regs)*iREGCNT_GPR); + + assert(parents.size() > 0); + + list::iterator itparent; + u32 usedvars = insts.front().usedvars[0]; + u32 livevars = insts.front().livevars[0]; + + if (parents.size() > 0) + { + u32 usedvars2 = 0xffffffff; + + for(itparent = parents.begin(); itparent != parents.end(); itparent++) + { + usedvars2 &= (*itparent)->insts.front().usedvars[0]; + } + + usedvars |= usedvars2; + } + + usedvars &= livevars; + + // currently order doesn't matter + int num = 0; + + if (usedvars) + { + for (int i = 1; i < 16; ++i) + { + if (usedvars & (1 << i)) + { + pregs[num].inuse = 1; + pregs[num].reg = i; + + livevars &= ~(1 << i); + + if (++num >= maxregs) break; + } + } + } + + if (num < maxregs) + { + livevars &= ~usedvars; + livevars &= insts.back().usedvars[0]; + + if (livevars) + { + for (int i = 1; i < 16; ++i) + { + if (livevars & (1 << i)) + { + pregs[num].inuse = 1; + pregs[num].reg = i; + + if (++num >= maxregs) break; + } + } + } + } + + s_markov.children.push_back(this); + type |= BLOCKTYPE_ANALYZED; + + for(itparent = parents.begin(); itparent != parents.end(); itparent++) + { + (*itparent)->AssignVIRegs(1); + } +} + +static void SuperVUAssignRegs() +{ + list::iterator itblock, itblock2; + + for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) + { + (*itblock)->type &= ~BLOCKTYPE_ANALYZED; + } + s_listBlocks.front()->AssignVFRegs(); + + // VI assignments, find markov blanket for each node in the graph + // then allocate regs based on the commonly used ones +#ifdef SUPERVU_X86CACHING + for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) + { + (*itblock)->type &= ~(BLOCKTYPE_ANALYZED | BLOCKTYPE_ANALYZEDPARENT); + } + s_vecRegArray.resize(0); + u8 usedregs[16]; + + // note: first block always has to start with no alloc regs + bool bfirst = true; + + for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) + { + + if (!((*itblock)->type & BLOCKTYPE_ANALYZED)) + { + + if ((*itblock)->parents.size() == 0) + { + (*itblock)->type |= BLOCKTYPE_ANALYZED; + bfirst = false; + continue; + } + + s_markov.children.clear(); + s_markov.parents.clear(); + (*itblock)->AssignVIRegs(0); + + // assign the regs + int regid = s_vecRegArray.size(); + s_vecRegArray.resize(regid + iREGCNT_GPR); + + _x86regs* mergedx86 = &s_vecRegArray[regid]; + memset(mergedx86, 0, sizeof(_x86regs)*iREGCNT_GPR); + + if (!bfirst) + { + *(u32*)usedregs = *((u32*)usedregs + 1) = *((u32*)usedregs + 2) = *((u32*)usedregs + 3) = 0; + + for(itblock2 = s_markov.children.begin(); itblock2 != s_markov.children.end(); itblock2++) + { + assert((*itblock2)->allocX86Regs >= 0); + _x86regs* pregs = &s_vecRegArray[(*itblock2)->allocX86Regs]; + for (int i = 0; i < iREGCNT_GPR; ++i) + { + if (pregs[i].inuse && pregs[i].reg < 16) + { + //assert( pregs[i].reg < 16); + usedregs[pregs[i].reg]++; + } + } + } + + int num = 1; + for (int i = 0; i < 16; ++i) + { + if (usedregs[i] == s_markov.children.size()) + { + // use + mergedx86[num].inuse = 1; + mergedx86[num].reg = i; + mergedx86[num].type = (s_vu ? X86TYPE_VU1 : 0) | X86TYPE_VI; + mergedx86[num].mode = MODE_READ; + if (++num >= iREGCNT_GPR) + break; + if (num == ESP) + ++num; + } + } + + for(itblock2 = s_markov.children.begin(); itblock2 != s_markov.children.end(); itblock2++) + { + assert((*itblock2)->nStartx86 == -1); + (*itblock2)->nStartx86 = regid; + } + + for(itblock2 = s_markov.parents.begin(); itblock2 != s_markov.parents.end(); itblock2++) + { + assert((*itblock2)->nEndx86 == -1); + (*itblock2)->nEndx86 = regid; + } + } + + bfirst = false; + } + } +#endif +} + +////////////////// +// Recompilation +////////////////// + +// cycles in which the last Q,P regs were finished (written to VU->VI[]) +// the write occurs before the instruction is executed at that cycle +// compare with s_TotalVUCycles +// if less than 0, already flushed +int s_writeQ, s_writeP; + +// declare the saved registers +uptr s_vu1esp, s_callstack;//, s_vu1esp +uptr s_vu1ebp, s_vuebx, s_vuedi, s_vu1esi; + +static int s_recWriteQ, s_recWriteP; // wait times during recompilation +static int s_needFlush; // first bit - Q, second bit - P, third bit - Q has been written, fourth bit - P has been written + +static int s_JumpX86; +static int s_ScheduleXGKICK = 0, s_XGKICKReg = -1; + +void recVUMI_XGKICK_(VURegs *VU); + +void SuperVUCleanupProgram(u32 startpc, int vuindex) +{ +#ifdef SUPERVU_COUNT + QueryPerformanceCounter(&svufinal); + svutime += (u32)(svufinal.QuadPart - svubase.QuadPart); +#endif + + assert(s_vu1esp == 0); + + VU = vuindex ? &VU1 : &VU0; + VU->cycle += s_TotalVUCycles; + + //VU cycle stealing hack, 3000 cycle maximum so it doesn't get out of hand + if (s_TotalVUCycles < 3000) + cpuRegs.cycle += s_TotalVUCycles * EmuConfig.Speedhacks.VUCycleSteal; + else + cpuRegs.cycle += 3000 * EmuConfig.Speedhacks.VUCycleSteal; + + if ((int)s_writeQ > 0) VU->VI[REG_Q] = VU->q; + if ((int)s_writeP > 0) + { + assert(VU == &VU1); + VU1.VI[REG_P] = VU1.p; // only VU1 + } + + //memset(recVUStack, 0, SUPERVU_STACKSIZE * 4); + + // Could clear allocation info to prevent possibly bad data being used in other parts of pcsx2; + // not doing this because it's slow and not needed (rama) + // _initXMMregs(); + // _initMMXregs(); + // _initX86regs(); +} + +#if defined(_MSC_VER) + +// entry point of all vu programs from emulator calls +__declspec(naked) void SuperVUExecuteProgram(u32 startpc, int vuindex) +{ + __asm + { + mov eax, dword ptr [esp] + mov s_TotalVUCycles, 0 // necessary to be here! + add esp, 4 + mov s_callstack, eax + call SuperVUGetProgram + + // save cpu state + mov s_vu1ebp, ebp + mov s_vu1esi, esi // have to save even in Release + mov s_vuedi, edi // have to save even in Release + mov s_vuebx, ebx + } +#ifdef PCSX2_DEBUG + __asm + { + mov s_vu1esp, esp + } +#endif + + __asm + { + //stmxcsr s_ssecsr + ldmxcsr g_sseVUMXCSR + + // init vars + mov s_writeQ, 0xffffffff + mov s_writeP, 0xffffffff + + jmp eax + } +} + +// exit point of all vu programs +__declspec(naked) static void SuperVUEndProgram() +{ + __asm + { + // restore cpu state + ldmxcsr g_sseMXCSR + + mov ebp, s_vu1ebp + mov esi, s_vu1esi + mov edi, s_vuedi + mov ebx, s_vuebx + } + +#ifdef PCSX2_DEBUG + __asm + { + sub s_vu1esp, esp + } +#endif + + __asm + { + call SuperVUCleanupProgram + jmp s_callstack // so returns correctly + } +} + +#endif + +// Flushes P/Q regs +void SuperVUFlush(int p, int wait) +{ + u8* pjmp[3]; + if (!(s_needFlush&(1 << p))) return; + + int recwait = p ? s_recWriteP : s_recWriteQ; + if (!wait && s_pCurInst->info.cycle < recwait) return; + + if (recwait == 0) + { + // write didn't happen this block + MOV32MtoR(EAX, p ? (uptr)&s_writeP : (uptr)&s_writeQ); + OR32RtoR(EAX, EAX); + pjmp[0] = JS8(0); + + if (s_pCurInst->info.cycle) SUB32ItoR(EAX, s_pCurInst->info.cycle); + + // if writeQ <= total+offset + if (!wait) // only write back if time is up + { + CMP32MtoR(EAX, (uptr)&s_TotalVUCycles); + pjmp[1] = JG8(0); + } + else + { + // add (writeQ-total-offset) to s_TotalVUCycles + // necessary? + CMP32MtoR(EAX, (uptr)&s_TotalVUCycles); + pjmp[2] = JLE8(0); + MOV32RtoM((uptr)&s_TotalVUCycles, EAX); + x86SetJ8(pjmp[2]); + } + } + else if (wait && s_pCurInst->info.cycle < recwait) + { + ADD32ItoM((uptr)&s_TotalVUCycles, recwait); + } + + MOV32MtoR(EAX, SuperVUGetVIAddr(p ? REG_P : REG_Q, 0)); + MOV32ItoM(p ? (uptr)&s_writeP : (uptr)&s_writeQ, 0x80000000); + MOV32RtoM(SuperVUGetVIAddr(p ? REG_P : REG_Q, 1), EAX); + + if (recwait == 0) + { + if (!wait) x86SetJ8(pjmp[1]); + x86SetJ8(pjmp[0]); + } + + if (wait || (!p && recwait == 0 && s_pCurInst->info.cycle >= 12) || (!p && recwait > 0 && s_pCurInst->info.cycle >= recwait)) + s_needFlush &= ~(1 << p); +} + +// executed only once per program +static u32* SuperVUStaticAlloc(u32 size) +{ + assert(recVUStackPtr + size <= recVUStack + SUPERVU_STACKSIZE); + // always zero + if (size == 4) *(u32*)recVUStackPtr = 0; + else memset(recVUStackPtr, 0, size); + recVUStackPtr += size; + return (u32*)(recVUStackPtr - size); +} + +static void SuperVURecompile() +{ + // save cpu state + recVUStackPtr = recVUStack; + + _initXMMregs(); + + list::iterator itblock; + + for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) + { + (*itblock)->type &= ~BLOCKTYPE_ANALYZED; + } + + s_listBlocks.front()->Recompile(); + + // make sure everything compiled + for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) + { + assert(((*itblock)->type & BLOCKTYPE_ANALYZED) && (*itblock)->pcode != NULL); + } + + // link all blocks + for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) + { + VuBaseBlock::LISTBLOCKS::iterator itchild; + + assert((*itblock)->blocks.size() <= ArraySize((*itblock)->pChildJumps)); + + int i = 0; + for(itchild = (*itblock)->blocks.begin(); itchild != (*itblock)->blocks.end(); itchild++) + { + + if ((u32)(uptr)(*itblock)->pChildJumps[i] == 0xffffffff) + continue; + + if ((*itblock)->pChildJumps[i] == NULL) + { + VuBaseBlock* pchild = *itchild; + + if (pchild->type & BLOCKTYPE_HASEOP) + { + assert(pchild->blocks.size() == 0); + + AND32ItoM((uptr)&VU0.VI[ REG_VPU_STAT ].UL, s_vu ? ~0x100 : ~0x001); // E flag + AND32ItoM((uptr)&VU->vifRegs->stat, ~VIF1_STAT_VEW); + + MOV32ItoM((uptr)&VU->VI[REG_TPC], pchild->endpc); + JMP32((uptr)SuperVUEndProgram - ((uptr)x86Ptr + 5)); + } + // only other case is when there are two branches + else + { + assert((*itblock)->insts.back().regs[0].pipe == VUPIPE_BRANCH); + } + + continue; + } + + if ((u32)(uptr)(*itblock)->pChildJumps[i] & 0x80000000) + { + // relative + assert((uptr)(*itblock)->pChildJumps[i] <= 0xffffffff); + (*itblock)->pChildJumps[i] = (u32*)((uptr)(*itblock)->pChildJumps[i] & 0x7fffffff); + *(*itblock)->pChildJumps[i] = (uptr)(*itchild)->pcode - ((uptr)(*itblock)->pChildJumps[i] + 4); + } + else + { + *(*itblock)->pChildJumps[i] = (uptr)(*itchild)->pcode; + } + + ++i; + } + } + + s_pFnHeader->pprogfunc = s_listBlocks.front()->pcode; +} + +// debug + + +u32 s_saveecx, s_saveedx, s_saveebx, s_saveesi, s_saveedi, s_saveebp; +u32 g_curdebugvu; + +//float vuDouble(u32 f); + +#if defined(_MSC_VER) +__declspec(naked) static void svudispfn() +{ + __asm + { + mov g_curdebugvu, eax + mov s_saveecx, ecx + mov s_saveedx, edx + mov s_saveebx, ebx + mov s_saveesi, esi + mov s_saveedi, edi + mov s_saveebp, ebp + } +#else + +void svudispfntemp() +{ +#endif + +#ifdef PCSX2_DEBUG + static u32 i; + + if (((vudump&8) && g_curdebugvu) || ((vudump&0x80) && !g_curdebugvu)) //&& g_vu1lastrec != g_vu1last ) { + { + + if (skipparent != g_vu1lastrec) + { + for (i = 0; i < ArraySize(badaddrs); ++i) + { + if (s_svulast == badaddrs[i][1] && g_vu1lastrec == badaddrs[i][0]) + break; + } + + if (i == ArraySize(badaddrs)) + { + //static int curesp; + //__asm mov curesp, esp + //Console.WriteLn("tVU: %x %x %x", s_svulast, s_vucount, s_vufnheader); + if (g_curdebugvu) iDumpVU1Registers(); + else iDumpVU0Registers(); + s_vucount++; + } + } + + g_vu1lastrec = s_svulast; + } +#endif + +#if defined(_MSC_VER) + __asm + { + mov ecx, s_saveecx + mov edx, s_saveedx + mov ebx, s_saveebx + mov esi, s_saveesi + mov edi, s_saveedi + mov ebp, s_saveebp + ret + } +#endif +} + +// frees all regs taking into account the livevars +void SuperVUFreeXMMregs(u32* livevars) +{ + for (int i = 0; i < iREGCNT_XMM; ++i) + { + if (xmmregs[i].inuse) + { + // same reg + if ((xmmregs[i].mode & MODE_WRITE)) + { + +#ifdef SUPERVU_INTERCACHING + if (xmmregs[i].type == XMMTYPE_VFREG) + { + if (!(livevars[1] & (1 << xmmregs[i].reg))) continue; + } + else if (xmmregs[i].type == XMMTYPE_ACC) + { + if (!(livevars[0] & (1 << REG_ACC_FLAG))) continue; + } +#endif + + if (xmmregs[i].mode & MODE_VUXYZ) + { + // ALWAYS update + u32 addr = xmmregs[i].type == XMMTYPE_VFREG ? (uptr) & VU->VF[xmmregs[i].reg] : (uptr) & VU->ACC; + + if (xmmregs[i].mode & MODE_VUZ) + { + SSE_MOVHPS_XMM_to_M64(addr, (x86SSERegType)i); + SSE_SHUFPS_M128_to_XMM((x86SSERegType)i, addr, 0xc4); + } + else + { + SSE_MOVHPS_M64_to_XMM((x86SSERegType)i, addr + 8); + } + + xmmregs[i].mode &= ~MODE_VUXYZ; + } + + _freeXMMreg(i); + } + } + } + + //_freeXMMregs(); +} + +void SuperVUTestVU0Condition(u32 incstack) +{ + if (s_vu && !SUPERVU_CHECKCONDITION) return; // vu0 only + + CMP32ItoM((uptr)&s_TotalVUCycles, 512); // sometimes games spin on vu0, so be careful with this value + // woody hangs if too high + + if (incstack) + { + u8* ptr = JB8(0); + + ADD32ItoR(ESP, incstack); + //CALLFunc((u32)timeout); + JMP32((uptr)SuperVUEndProgram - ((uptr)x86Ptr + 5)); + + x86SetJ8(ptr); + } + else JAE32((uptr)SuperVUEndProgram - ((uptr)x86Ptr + 6)); +} + +void VuBaseBlock::Recompile() +{ + if (type & BLOCKTYPE_ANALYZED) return; + + x86Align(16); + pcode = x86Ptr; + +#ifdef PCSX2_DEBUG + MOV32ItoM((uptr)&s_vufnheader, s_pFnHeader->startpc); + MOV32ItoM((uptr)&VU->VI[REG_TPC], startpc); + MOV32ItoM((uptr)&s_svulast, startpc); + + list::iterator itparent; + for (itparent = parents.begin(); itparent != parents.end(); ++itparent) + { + if ((*itparent)->blocks.size() == 1 && (*itparent)->blocks.front()->startpc == startpc && + ((*itparent)->insts.size() < 2 || (----(*itparent)->insts.end())->regs[0].pipe != VUPIPE_BRANCH)) + { + MOV32ItoM((uptr)&skipparent, (*itparent)->startpc); + break; + } + } + + if (itparent == parents.end()) MOV32ItoM((uptr)&skipparent, -1); + + MOV32ItoR(EAX, s_vu); + CALLFunc((uptr)svudispfn); +#endif + + s_pCurBlock = this; + s_needFlush = 3; + pc = startpc; + branch = 0; + s_recWriteQ = s_recWriteP = 0; + s_XGKICKReg = -1; + s_ScheduleXGKICK = 0; + + s_ClipRead = s_PrevClipWrite = (uptr) & VU->VI[REG_CLIP_FLAG]; + s_StatusRead = s_PrevStatusWrite = (uptr) & VU->VI[REG_STATUS_FLAG]; + s_MACRead = s_PrevMACWrite = (uptr) & VU->VI[REG_MAC_FLAG]; + s_PrevIWrite = (uptr) & VU->VI[REG_I]; + s_JumpX86 = 0; + s_UnconditionalDelay = 0; + + memcpy(xmmregs, startregs, sizeof(xmmregs)); +#ifdef SUPERVU_X86CACHING + if (nStartx86 >= 0) + memcpy(x86regs, &s_vecRegArray[nStartx86], sizeof(x86regs)); + else + _initX86regs(); +#else + _initX86regs(); +#endif + + list::iterator itinst; + for(itinst = insts.begin(); itinst != insts.end(); itinst++) + { + s_pCurInst = &(*itinst); + if (s_JumpX86 > 0) + { + if (!x86regs[s_JumpX86].inuse) + { + // load + s_JumpX86 = _allocX86reg(-1, X86TYPE_VUJUMP, 0, MODE_READ); + } + x86regs[s_JumpX86].needed = 1; + } + + if (s_ScheduleXGKICK && s_XGKICKReg > 0) + { + assert(x86regs[s_XGKICKReg].inuse); + x86regs[s_XGKICKReg].needed = 1; + } + itinst->Recompile(itinst, vuxyz); + + if (s_ScheduleXGKICK > 0) + { + if (s_ScheduleXGKICK-- == 1) + { + recVUMI_XGKICK_(VU); + } + } + } + assert(pc == endpc); + assert(s_ScheduleXGKICK == 0); + + // flush flags + if (s_PrevClipWrite != (uptr)&VU->VI[REG_CLIP_FLAG]) + { + MOV32MtoR(EAX, s_PrevClipWrite); + MOV32RtoM((uptr)&VU->VI[REG_CLIP_FLAG], EAX); + } + if (s_PrevStatusWrite != (uptr)&VU->VI[REG_STATUS_FLAG]) + { + MOV32MtoR(EAX, s_PrevStatusWrite); + MOV32RtoM((uptr)&VU->VI[REG_STATUS_FLAG], EAX); + } + if (s_PrevMACWrite != (uptr)&VU->VI[REG_MAC_FLAG]) + { + MOV32MtoR(EAX, s_PrevMACWrite); + MOV32RtoM((uptr)&VU->VI[REG_MAC_FLAG], EAX); + } +// if( s_StatusRead != (uptr)&VU->VI[REG_STATUS_FLAG] ) { +// // only lower 8 bits valid! +// MOVZX32M8toR(EAX, s_StatusRead); +// MOV32RtoM((uptr)&VU->VI[REG_STATUS_FLAG], EAX); +// } +// if( s_MACRead != (uptr)&VU->VI[REG_MAC_FLAG] ) { +// // only lower 8 bits valid! +// MOVZX32M8toR(EAX, s_MACRead); +// MOV32RtoM((uptr)&VU->VI[REG_MAC_FLAG], EAX); +// } + if (s_PrevIWrite != (uptr)&VU->VI[REG_I]) + { + MOV32ItoM((uptr)&VU->VI[REG_I], *(u32*)s_PrevIWrite); // never changes + } + + ADD32ItoM((uptr)&s_TotalVUCycles, cycles); + + // compute branches, jumps, eop + if (type & BLOCKTYPE_HASEOP) + { + // end + _freeXMMregs(); + _freeX86regs(); + AND32ItoM((uptr)&VU0.VI[ REG_VPU_STAT ].UL, s_vu ? ~0x100 : ~0x001); // E flag + AND32ItoM((uptr)&VU->vifRegs->stat, ~VIF1_STAT_VEW); + + if (!branch) MOV32ItoM((uptr)&VU->VI[REG_TPC], endpc); + + JMP32((uptr)SuperVUEndProgram - ((uptr)x86Ptr + 5)); + } + else + { + + u32 livevars[2] = {0}; + + list::iterator lastinst = GetInstIterAtPc(endpc - 8); + lastinst++; + + if (lastinst != insts.end()) + { + livevars[0] = lastinst->livevars[0]; + livevars[1] = lastinst->livevars[1]; + } + else + { + // take from children + if (blocks.size() > 0) + { + LISTBLOCKS::iterator itchild; + for(itchild = blocks.begin(); itchild != blocks.end(); itchild++) + { + livevars[0] |= (*itchild)->insts.front().livevars[0]; + livevars[1] |= (*itchild)->insts.front().livevars[1]; + } + } + else + { + livevars[0] = ~0; + livevars[1] = ~0; + } + } + + SuperVUFreeXMMregs(livevars); + + // get rid of any writes, otherwise _freeX86regs will write + x86regs[s_JumpX86].mode &= ~MODE_WRITE; + + if (branch == 1) + { + if (!x86regs[s_JumpX86].inuse) + { + assert(x86regs[s_JumpX86].type == X86TYPE_VUJUMP); + s_JumpX86 = 0xffffffff; // notify to jump from g_recWriteback + } + } + + // align VI regs +#ifdef SUPERVU_X86CACHING + if (nEndx86 >= 0) + { + _x86regs* endx86 = &s_vecRegArray[nEndx86]; + for (int i = 0; i < iREGCNT_GPR; ++i) + { + if (endx86[i].inuse) + { + + if (s_JumpX86 == i && x86regs[s_JumpX86].inuse) + { + x86regs[s_JumpX86].inuse = 0; + x86regs[EAX].inuse = 1; + MOV32RtoR(EAX, s_JumpX86); + s_JumpX86 = EAX; + } + + if (x86regs[i].inuse) + { + if (x86regs[i].type == endx86[i].type && x86regs[i].reg == endx86[i].reg) + { + _freeX86reg(i); + // will continue to use it + continue; + } + +#ifdef SUPERVU_INTERCACHING + if (x86regs[i].type == (X86TYPE_VI | (s_vu ? X86TYPE_VU1 : 0))) + { + if (livevars[0] & (1 << x86regs[i].reg)) + _freeX86reg(i); + else + x86regs[i].inuse = 0; + } + else +#endif + { + _freeX86reg(i); + } + } + + // realloc + _allocX86reg(i, endx86[i].type, endx86[i].reg, MODE_READ); + if (x86regs[i].mode & MODE_WRITE) + { + _freeX86reg(i); + x86regs[i].inuse = 1; + } + } + else _freeX86reg(i); + } + } + else _freeX86regs(); +#else + _freeX86regs(); +#endif + + // store the last block executed + MOV32ItoM((uptr)&g_nLastBlockExecuted, s_pCurBlock->startpc); + + switch (branch) + { + case 1: // branch, esi has new prog + + SuperVUTestVU0Condition(0); + + if (s_JumpX86 == 0xffffffff) + JMP32M((uptr)&g_recWriteback); + else + JMPR(s_JumpX86); + + break; + case 4: // jalr + pChildJumps[0] = (u32*)0xffffffff; + // fall through + + case 0x10: // jump, esi has new vupc + { + _freeXMMregs(); + _freeX86regs(); + + SuperVUTestVU0Condition(8); + + // already onto stack + CALLFunc((uptr)SuperVUGetProgram); + ADD32ItoR(ESP, 8); + JMPR(EAX); + break; + } + + case 0x13: // jr with uncon branch, uncond branch takes precendence (dropship) + { +// s32 delta = (s32)(VU->code & 0x400 ? 0xfffffc00 | (VU->code & 0x3ff) : VU->code & 0x3ff) << 3; +// ADD32ItoRmOffset(ESP, delta, 0); + + ADD32ItoR(ESP, 8); // restore + pChildJumps[0] = (u32*)((uptr)JMP32(0) | 0x80000000); + break; + } + case 0: + case 3: // unconditional branch + pChildJumps[s_UnconditionalDelay] = (u32*)((uptr)JMP32(0) | 0x80000000); + break; + + default: + DevCon.Error("Bad branch %x\n", branch); + assert(0); + break; + } + } + + pendcode = x86Ptr; + type |= BLOCKTYPE_ANALYZED; + + LISTBLOCKS::iterator itchild; + for(itchild = blocks.begin(); itchild != blocks.end(); itchild++) + { + (*itchild)->Recompile(); + } +} + +#define GET_VUXYZMODE(reg) 0//((vuxyz&(1<<(reg)))?MODE_VUXYZ:0) + +int VuInstruction::SetCachedRegs(int upper, u32 vuxyz) +{ + if (vfread0[upper] >= 0) + { + SuperVUFreeXMMreg(vfread0[upper], XMMTYPE_VFREG, regs[upper].VFread0); + _allocVFtoXMMreg(VU, vfread0[upper], regs[upper].VFread0, MODE_READ | GET_VUXYZMODE(regs[upper].VFread0)); + } + if (vfread1[upper] >= 0) + { + SuperVUFreeXMMreg(vfread1[upper], XMMTYPE_VFREG, regs[upper].VFread1); + _allocVFtoXMMreg(VU, vfread1[upper], regs[upper].VFread1, MODE_READ | GET_VUXYZMODE(regs[upper].VFread1)); + } + if (vfacc[upper] >= 0 && (regs[upper].VIread&(1 << REG_ACC_FLAG))) + { + SuperVUFreeXMMreg(vfacc[upper], XMMTYPE_ACC, 0); + _allocACCtoXMMreg(VU, vfacc[upper], MODE_READ); + } + if (vfwrite[upper] >= 0) + { + assert(regs[upper].VFwrite > 0); + SuperVUFreeXMMreg(vfwrite[upper], XMMTYPE_VFREG, regs[upper].VFwrite); + _allocVFtoXMMreg(VU, vfwrite[upper], regs[upper].VFwrite, + MODE_WRITE | (regs[upper].VFwxyzw != 0xf ? MODE_READ : 0) | GET_VUXYZMODE(regs[upper].VFwrite)); + } + if (vfacc[upper] >= 0 && (regs[upper].VIwrite&(1 << REG_ACC_FLAG))) + { + SuperVUFreeXMMreg(vfacc[upper], XMMTYPE_ACC, 0); + _allocACCtoXMMreg(VU, vfacc[upper], MODE_WRITE | (regs[upper].VFwxyzw != 0xf ? MODE_READ : 0)); + } + + int info = PROCESS_VU_SUPER; + if (vfread0[upper] >= 0) info |= PROCESS_EE_SET_S(vfread0[upper]); + if (vfread1[upper] >= 0) info |= PROCESS_EE_SET_T(vfread1[upper]); + if (vfacc[upper] >= 0) info |= PROCESS_VU_SET_ACC(vfacc[upper]); + if (vfwrite[upper] >= 0) + { + if (regs[upper].VFwrite == _Ft_ && vfread1[upper] < 0) + { + info |= PROCESS_EE_SET_T(vfwrite[upper]); + } + else + { + assert(regs[upper].VFwrite == _Fd_); + info |= PROCESS_EE_SET_D(vfwrite[upper]); + } + } + + if (!(vffree[upper]&VFFREE_INVALID0)) + { + SuperVUFreeXMMreg(vffree[upper]&0xf, XMMTYPE_TEMP, 0); + _allocTempXMMreg(XMMT_FPS, vffree[upper]&0xf); + } + info |= PROCESS_VU_SET_TEMP(vffree[upper] & 0xf); + + if (vfflush[upper] >= 0) + { + SuperVUFreeXMMreg(vfflush[upper], XMMTYPE_TEMP, 0); + _allocTempXMMreg(XMMT_FPS, vfflush[upper]); + } + + if (upper && (regs[upper].VIwrite & (1 << REG_CLIP_FLAG))) + { + // CLIP inst, need two extra temp registers, put it EEREC_D and EEREC_ACC + assert(vfwrite[upper] == -1); + SuperVUFreeXMMreg((vffree[upper] >> 8)&0xf, XMMTYPE_TEMP, 0); + _allocTempXMMreg(XMMT_FPS, (vffree[upper] >> 8)&0xf); + info |= PROCESS_EE_SET_D((vffree[upper] >> 8) & 0xf); + + SuperVUFreeXMMreg((vffree[upper] >> 16)&0xf, XMMTYPE_TEMP, 0); + _allocTempXMMreg(XMMT_FPS, (vffree[upper] >> 16)&0xf); + info |= PROCESS_EE_SET_ACC((vffree[upper] >> 16) & 0xf); + + _freeXMMreg((vffree[upper] >> 8)&0xf); // don't need anymore + _freeXMMreg((vffree[upper] >> 16)&0xf); // don't need anymore + } + else if (regs[upper].VIwrite & (1 << REG_P)) + { + SuperVUFreeXMMreg((vffree[upper] >> 8)&0xf, XMMTYPE_TEMP, 0); + _allocTempXMMreg(XMMT_FPS, (vffree[upper] >> 8)&0xf); + info |= PROCESS_EE_SET_D((vffree[upper] >> 8) & 0xf); + _freeXMMreg((vffree[upper] >> 8)&0xf); // don't need anymore + } + + if (vfflush[upper] >= 0) _freeXMMreg(vfflush[upper]); + if (!(vffree[upper]&VFFREE_INVALID0)) + _freeXMMreg(vffree[upper]&0xf); // don't need anymore + + if ((regs[0].VIwrite | regs[1].VIwrite) & ((1 << REG_STATUS_FLAG) | (1 << REG_MAC_FLAG))) + info |= PROCESS_VU_UPDATEFLAGS; + + return info; +} + +void VuInstruction::Recompile(list::iterator& itinst, u32 vuxyz) +{ + //static PCSX2_ALIGNED16(VECTOR _VF); + //static PCSX2_ALIGNED16(VECTOR _VFc); + u32 *ptr; + u8* pjmp; + int vfregstore = 0; + + assert(s_pCurInst == this); + s_WriteToReadQ = 0; + + ptr = (u32*) & VU->Micro[ pc ]; + + if (type & INST_Q_READ) + SuperVUFlush(0, (ptr[0] == 0x800003bf) || !!(regs[0].VIwrite & (1 << REG_Q))); + if (type & INST_P_READ) + SuperVUFlush(1, (ptr[0] == 0x800007bf) || !!(regs[0].VIwrite & (1 << REG_P))); + + if (type & INST_DUMMY) + { + + // find nParentPc + VuInstruction* pparentinst = NULL; + + // if true, will check if parent block was executed before getting the results of the flags (superman returns) + int nParentCheckForExecution = -1; + +// int badaddrs[] = { +// 0x60,0x68,0x70,0x60,0x68,0x70,0x88,0x90,0x98,0x98,0xa8,0xb8,0x88,0x90, +// 0x4a8,0x4a8,0x398,0x3a0,0x3a8,0xa0 +// }; + +#ifdef SUPERVU_PROPAGATEFLAGS + if (nParentPc != -1 && (nParentPc < s_pCurBlock->startpc || nParentPc >= (int)pc)) + { + +// if( !s_vu ) { +// for(int j = 0; j < ARRAYSIZE(badaddrs); ++j) { +// if( badaddrs[j] == nParentPc ) +// goto NoParent; +// } +// } + + list::iterator itblock; + for(itblock = s_listBlocks.begin(); itblock != s_listBlocks.end(); itblock++) + { + if (nParentPc >= (*itblock)->startpc && nParentPc < (*itblock)->endpc) + { + pparentinst = &(*(*itblock)->GetInstIterAtPc(nParentPc)); + //if( !s_vu ) SysPrintf("%x ", nParentPc); + if (find(s_pCurBlock->parents.begin(), s_pCurBlock->parents.end(), *itblock) != s_pCurBlock->parents.end()) + nParentCheckForExecution = (*itblock)->startpc; + break; + } + } + + assert(pparentinst != NULL); + } +#endif + + if (type & INST_CLIP_WRITE) + { + if (nParentPc < s_pCurBlock->startpc || nParentPc >= (int)pc) + { + + if (!CHECK_VUCLIPFLAGHACK && pparentinst != NULL) + { + + if (nParentCheckForExecution >= 0) + { + if (pparentinst->pClipWrite == 0) + pparentinst->pClipWrite = (uptr)SuperVUStaticAlloc(4); + + if (s_ClipRead == 0) + s_ClipRead = (uptr) & VU->VI[REG_CLIP_FLAG]; + + CMP32ItoM((uptr)&g_nLastBlockExecuted, nParentCheckForExecution); + u8* jptr = JNE8(0); + CMP32ItoM((uptr)&s_ClipRead, (uptr)&VU->VI[REG_CLIP_FLAG]); + u8* jptr2 = JE8(0); + MOV32MtoR(EAX, pparentinst->pClipWrite); + MOV32RtoM(s_ClipRead, EAX); + x86SetJ8(jptr); + x86SetJ8(jptr2); + } + } + else s_ClipRead = (uptr) & VU->VI[REG_CLIP_FLAG]; + } + else + { + s_ClipRead = s_pCurBlock->GetInstIterAtPc(nParentPc)->pClipWrite; + if (s_ClipRead == 0) Console.WriteLn("super ClipRead allocation error!"); + } + } + + // before modifying, check if they will ever be read + if (s_pCurBlock->type & BLOCKTYPE_MACFLAGS) + { + + u8 outofblock = 0; + if (type & INST_STATUS_WRITE) + { + + if (nParentPc < s_pCurBlock->startpc || nParentPc >= (int)pc) + { + + // reading from out of this block, so already flushed to mem + if (pparentinst != NULL) //&& pparentinst->pStatusWrite != NULL ) { + { + + // might not have processed it yet, so reserve a mem loc + if (pparentinst->pStatusWrite == 0) + { + pparentinst->pStatusWrite = (uptr)SuperVUStaticAlloc(4); + //MOV32ItoM(pparentinst->pStatusWrite, 0); + } + +// if( s_pCurBlock->prevFlagsOutOfBlock && s_StatusRead != NULL ) { +// // or instead since don't now which parent we came from +// MOV32MtoR(EAX, pparentinst->pStatusWrite); +// OR32RtoM(s_StatusRead, EAX); +// MOV32ItoM(pparentinst->pStatusWrite, 0); +// } + + if (nParentCheckForExecution >= 0) + { + + // don't now which parent we came from, so have to check +// uptr tempstatus = (uptr)SuperVUStaticAlloc(4); +// if( s_StatusRead != NULL ) +// MOV32MtoR(EAX, s_StatusRead); +// else +// MOV32MtoR(EAX, (uptr)&VU->VI[REG_STATUS_FLAG]); +// s_StatusRead = tempstatus; + + if (s_StatusRead == 0) + s_StatusRead = (uptr) & VU->VI[REG_STATUS_FLAG]; + + CMP32ItoM((uptr)&g_nLastBlockExecuted, nParentCheckForExecution); + u8* jptr = JNE8(0); + MOV32MtoR(EAX, pparentinst->pStatusWrite); + MOV32ItoM(pparentinst->pStatusWrite, 0); + MOV32RtoM(s_StatusRead, EAX); + x86SetJ8(jptr); + } + else + { + uptr tempstatus = (uptr)SuperVUStaticAlloc(4); + MOV32MtoR(EAX, pparentinst->pStatusWrite); + MOV32RtoM(tempstatus, EAX); + MOV32ItoM(pparentinst->pStatusWrite, 0); + s_StatusRead = tempstatus; + } + + outofblock = 2; + } + else + s_StatusRead = (uptr) & VU->VI[REG_STATUS_FLAG]; + } + else + { + s_StatusRead = s_pCurBlock->GetInstIterAtPc(nParentPc)->pStatusWrite; + if (s_StatusRead == 0) Console.WriteLn("super StatusRead allocation error!"); +// if( pc >= (u32)s_pCurBlock->endpc-8 ) { +// // towards the end, so variable might be leaded to another block (silent hill 4) +// uptr tempstatus = (uptr)SuperVUStaticAlloc(4); +// MOV32MtoR(EAX, s_StatusRead); +// MOV32RtoM(tempstatus, EAX); +// MOV32ItoM(s_StatusRead, 0); +// s_StatusRead = tempstatus; +// } + } + } + if (type & INST_MAC_WRITE) + { + + if (nParentPc < s_pCurBlock->startpc || nParentPc >= (int)pc) + { + // reading from out of this block, so already flushed to mem + + if (pparentinst != NULL) //&& pparentinst->pMACWrite != NULL ) { + { + // necessary for (katamari) + // towards the end, so variable might be leaked to another block (silent hill 4) + + // might not have processed it yet, so reserve a mem loc + if (pparentinst->pMACWrite == 0) + { + pparentinst->pMACWrite = (uptr)SuperVUStaticAlloc(4); + //MOV32ItoM(pparentinst->pMACWrite, 0); + } + +// if( s_pCurBlock->prevFlagsOutOfBlock && s_MACRead != NULL ) { +// // or instead since don't now which parent we came from +// MOV32MtoR(EAX, pparentinst->pMACWrite); +// OR32RtoM(s_MACRead, EAX); +// MOV32ItoM(pparentinst->pMACWrite, 0); +// } + if (nParentCheckForExecution >= 0) + { + + // don't now which parent we came from, so have to check +// uptr tempmac = (uptr)SuperVUStaticAlloc(4); +// if( s_MACRead != NULL ) +// MOV32MtoR(EAX, s_MACRead); +// else +// MOV32MtoR(EAX, (uptr)&VU->VI[REG_MAC_FLAG]); +// s_MACRead = tempmac; + + if (s_MACRead == 0) s_MACRead = (uptr) & VU->VI[REG_MAC_FLAG]; + + CMP32ItoM((uptr)&g_nLastBlockExecuted, nParentCheckForExecution); + u8* jptr = JNE8(0); + MOV32MtoR(EAX, pparentinst->pMACWrite); + MOV32ItoM(pparentinst->pMACWrite, 0); + MOV32RtoM(s_MACRead, EAX); + x86SetJ8(jptr); + } + else + { + uptr tempMAC = (uptr)SuperVUStaticAlloc(4); + MOV32MtoR(EAX, pparentinst->pMACWrite); + MOV32RtoM(tempMAC, EAX); + MOV32ItoM(pparentinst->pMACWrite, 0); + s_MACRead = tempMAC; + } + + outofblock = 2; + } + else + s_MACRead = (uptr) & VU->VI[REG_MAC_FLAG]; + +// if( pc >= (u32)s_pCurBlock->endpc-8 ) { +// // towards the end, so variable might be leaked to another block (silent hill 4) +// uptr tempMAC = (uptr)SuperVUStaticAlloc(4); +// MOV32MtoR(EAX, s_MACRead); +// MOV32RtoM(tempMAC, EAX); +// MOV32ItoM(s_MACRead, 0); +// s_MACRead = tempMAC; +// } + } + else + { + s_MACRead = s_pCurBlock->GetInstIterAtPc(nParentPc)->pMACWrite; + } + } + + s_pCurBlock->prevFlagsOutOfBlock = outofblock; + } + else if (pparentinst != NULL) + { + // make sure to reset the mac and status flags! (katamari) + if (pparentinst->pStatusWrite) + MOV32ItoM(pparentinst->pStatusWrite, 0); + if (pparentinst->pMACWrite) + MOV32ItoM(pparentinst->pMACWrite, 0); + } + + assert(s_ClipRead != 0); + assert(s_MACRead != 0); + assert(s_StatusRead != 0); + + return; + } + + s_pCurBlock->prevFlagsOutOfBlock = 0; + + if( IsDebugBuild ) + MOV32ItoR(EAX, pc); + + assert(!(type & (INST_CLIP_WRITE | INST_STATUS_WRITE | INST_MAC_WRITE))); + pc += 8; + + list::const_iterator itinst2; + + if ((regs[0].VIwrite | regs[1].VIwrite) & ((1 << REG_MAC_FLAG) | (1 << REG_STATUS_FLAG))) + { + if (s_pCurBlock->type & BLOCKTYPE_MACFLAGS) + { + if (pMACWrite == 0) + { + pMACWrite = (uptr)SuperVUStaticAlloc(4); + //MOV32ItoM(pMACWrite, 0); + } + if (pStatusWrite == 0) + { + pStatusWrite = (uptr)SuperVUStaticAlloc(4); + //MOV32ItoM(pStatusWrite, 0); + } + } + else + { + assert(s_StatusRead == (uptr)&VU->VI[REG_STATUS_FLAG]); + assert(s_MACRead == (uptr)&VU->VI[REG_MAC_FLAG]); + pMACWrite = s_MACRead; + pStatusWrite = s_StatusRead; + } + } + + if ((pClipWrite == 0) && ((regs[0].VIwrite | regs[1].VIwrite) & (1 << REG_CLIP_FLAG))) + { + pClipWrite = (uptr)SuperVUStaticAlloc(4); + //MOV32ItoM(pClipWrite, 0); + } + +#ifdef SUPERVU_X86CACHING + // redo the counters so that the proper regs are released + for (int j = 0; j < iREGCNT_GPR; ++j) + { + if (x86regs[j].inuse && X86_ISVI(x86regs[j].type)) + { + int count = 0; + itinst2 = itinst; + + while (itinst2 != s_pCurBlock->insts.end()) + { + if ((itinst2->regs[0].VIread | itinst2->regs[0].VIwrite | itinst2->regs[1].VIread | itinst2->regs[1].VIwrite) && (1 << x86regs[j].reg)) + break; + + ++count; + ++itinst2; + } + + x86regs[j].counter = 1000 - count; + } + } +#endif + + if (s_vu == 0 && (ptr[1] & 0x20000000)) // M flag + { + OR8ItoM((uptr)&VU->flags, VUFLAG_MFLAGSET); + } + if (ptr[1] & 0x10000000) // D flag + { + TEST32ItoM((uptr)&VU0.VI[REG_FBRST].UL, s_vu ? 0x400 : 0x004); + u8* ptr = JZ8(0); + OR32ItoM((uptr)&VU0.VI[REG_VPU_STAT].UL, s_vu ? 0x200 : 0x002); + _callFunctionArg1((uptr)hwIntcIrq, MEM_CONSTTAG, s_vu ? INTC_VU1 : INTC_VU0); + x86SetJ8(ptr); + } + if (ptr[1] & 0x08000000) // T flag + { + TEST32ItoM((uptr)&VU0.VI[REG_FBRST].UL, s_vu ? 0x800 : 0x008); + u8* ptr = JZ8(0); + OR32ItoM((uptr)&VU0.VI[REG_VPU_STAT].UL, s_vu ? 0x400 : 0x004); + _callFunctionArg1((uptr)hwIntcIrq, MEM_CONSTTAG, s_vu ? INTC_VU1 : INTC_VU0); + x86SetJ8(ptr); + } + + // check upper flags + if (ptr[1] & 0x80000000) // I flag + { + + assert(!(regs[0].VIwrite & ((1 << REG_Q) | (1 << REG_P)))); + + VU->code = ptr[1]; + s_vuInfo = SetCachedRegs(1, vuxyz); + if (s_JumpX86 > 0) x86regs[s_JumpX86].needed = 1; + if (s_ScheduleXGKICK && s_XGKICKReg > 0) x86regs[s_XGKICKReg].needed = 1; + + recVU_UPPER_OPCODE[ VU->code & 0x3f ](VU, s_vuInfo); + + s_PrevIWrite = (uptr)ptr; + _clearNeededXMMregs(); + _clearNeededX86regs(); + } + else + { + if (regs[0].VIwrite & (1 << REG_Q)) + { + + // search for all the insts between this inst and writeback + itinst2 = itinst; + ++itinst2; + u32 cacheq = (itinst2 == s_pCurBlock->insts.end()); + u32* codeptr2 = ptr + 2; + + while (itinst2 != s_pCurBlock->insts.end()) + { + if (!(itinst2->type & INST_DUMMY) && ((itinst2->regs[0].VIwrite&(1 << REG_Q)) || codeptr2[0] == 0x800003bf)) // waitq, or fdiv inst + { + break; + } + if ((itinst2->type & INST_Q_WRITE) && itinst2->nParentPc == pc - 8) + { + break; + } + if (itinst2->type & INST_Q_READ) + { + cacheq = 1; + break; + } + if (itinst2->type & INST_DUMMY) + { + ++itinst2; + continue; + } + codeptr2 += 2; + ++itinst2; + } + + if (itinst2 == s_pCurBlock->insts.end()) + cacheq = 1; + + int x86temp = -1; + if (cacheq) + x86temp = _allocX86reg(-1, X86TYPE_TEMP, 0, 0); + + // new is written so flush old + // if type & INST_Q_READ, already flushed + if (!(type & INST_Q_READ) && s_recWriteQ == 0) MOV32MtoR(EAX, (uptr)&s_writeQ); + + if (cacheq) + MOV32MtoR(x86temp, (uptr)&s_TotalVUCycles); + + if (!(type & INST_Q_READ)) + { + if (s_recWriteQ == 0) + { + OR32RtoR(EAX, EAX); + pjmp = JS8(0); + MOV32MtoR(EAX, SuperVUGetVIAddr(REG_Q, 0)); + MOV32RtoM(SuperVUGetVIAddr(REG_Q, 1), EAX); + x86SetJ8(pjmp); + } + else if (s_needFlush & 1) + { + MOV32MtoR(EAX, SuperVUGetVIAddr(REG_Q, 0)); + MOV32RtoM(SuperVUGetVIAddr(REG_Q, 1), EAX); + s_needFlush &= ~1; + } + } + + // write new Q + if (cacheq) + { + assert(s_pCurInst->pqcycles > 1); + ADD32ItoR(x86temp, s_pCurInst->info.cycle + s_pCurInst->pqcycles); + MOV32RtoM((uptr)&s_writeQ, x86temp); + s_needFlush |= 1; + } + else + { + // won't be writing back + s_WriteToReadQ = 1; + s_needFlush &= ~1; + MOV32ItoM((uptr)&s_writeQ, 0x80000001); + } + + s_recWriteQ = s_pCurInst->info.cycle + s_pCurInst->pqcycles; + + if (x86temp >= 0) + _freeX86reg(x86temp); + } + + if (regs[0].VIwrite & (1 << REG_P)) + { + int x86temp = _allocX86reg(-1, X86TYPE_TEMP, 0, 0); + + // new is written so flush old + if (!(type & INST_P_READ) && s_recWriteP == 0) + MOV32MtoR(EAX, (uptr)&s_writeP); + MOV32MtoR(x86temp, (uptr)&s_TotalVUCycles); + + if (!(type & INST_P_READ)) + { + if (s_recWriteP == 0) + { + OR32RtoR(EAX, EAX); + pjmp = JS8(0); + MOV32MtoR(EAX, SuperVUGetVIAddr(REG_P, 0)); + MOV32RtoM(SuperVUGetVIAddr(REG_P, 1), EAX); + x86SetJ8(pjmp); + } + else if (s_needFlush & 2) + { + MOV32MtoR(EAX, SuperVUGetVIAddr(REG_P, 0)); + MOV32RtoM(SuperVUGetVIAddr(REG_P, 1), EAX); + s_needFlush &= ~2; + } + } + + // write new P + assert(s_pCurInst->pqcycles > 1); + ADD32ItoR(x86temp, s_pCurInst->info.cycle + s_pCurInst->pqcycles); + MOV32RtoM((uptr)&s_writeP, x86temp); + s_needFlush |= 2; + + s_recWriteP = s_pCurInst->info.cycle + s_pCurInst->pqcycles; + + _freeX86reg(x86temp); + } + + // waitq + if (ptr[0] == 0x800003bf) SuperVUFlush(0, 1); + // waitp + if (ptr[0] == 0x800007bf) SuperVUFlush(1, 1); + +#ifdef PCSX2_DEVBUILD + if (regs[1].VIread & regs[0].VIwrite & ~((1 << REG_Q) | (1 << REG_P) | (1 << REG_VF0_FLAG) | (1 << REG_ACC_FLAG))) + { + Console.Notice("*PCSX2*: Warning, VI write to the same reg %x in both lower/upper cycle %x", regs[1].VIread & regs[0].VIwrite, s_pCurBlock->startpc); + } +#endif + + u32 modewrite = 0; + if (vfwrite[1] >= 0 && xmmregs[vfwrite[1]].inuse && xmmregs[vfwrite[1]].type == XMMTYPE_VFREG && xmmregs[vfwrite[1]].reg == regs[1].VFwrite) + modewrite = xmmregs[vfwrite[1]].mode & MODE_WRITE; + + VU->code = ptr[1]; + s_vuInfo = SetCachedRegs(1, vuxyz); + + if (vfwrite[1] >= 0) + { + assert(regs[1].VFwrite > 0); + + if (vfwrite[0] == vfwrite[1]) + { + //Console.WriteLn("*PCSX2*: Warning, VF write to the same reg in both lower/upper cycle %x", s_pCurBlock->startpc); + } + + if (vfread0[0] == vfwrite[1] || vfread1[0] == vfwrite[1]) + { + assert(regs[0].VFread0 == regs[1].VFwrite || regs[0].VFread1 == regs[1].VFwrite); + assert(vfflush[0] >= 0); + if (modewrite) + { + SSE_MOVAPS_XMM_to_M128((uptr)&VU->VF[regs[1].VFwrite], (x86SSERegType)vfwrite[1]); + } + vfregstore = 1; + } + } + + if (s_JumpX86 > 0) x86regs[s_JumpX86].needed = 1; + if (s_ScheduleXGKICK && s_XGKICKReg > 0) x86regs[s_XGKICKReg].needed = 1; + + recVU_UPPER_OPCODE[ VU->code & 0x3f ](VU, s_vuInfo); + _clearNeededXMMregs(); + _clearNeededX86regs(); + + // necessary because status can be set by both upper and lower + if (regs[1].VIwrite & (1 << REG_STATUS_FLAG)) + { + assert(pStatusWrite != 0); + s_PrevStatusWrite = pStatusWrite; + } + + VU->code = ptr[0]; + s_vuInfo = SetCachedRegs(0, vuxyz); + + if (vfregstore) + { + // load + SSE_MOVAPS_M128_to_XMM(vfflush[0], (uptr)&VU->VF[regs[1].VFwrite]); + + assert(xmmregs[vfwrite[1]].mode & MODE_WRITE); + + // replace with vfflush + if (_Fs_ == regs[1].VFwrite) + { + s_vuInfo &= ~PROCESS_EE_SET_S(0xf); + s_vuInfo |= PROCESS_EE_SET_S(vfflush[0]); + } + if (_Ft_ == regs[1].VFwrite) + { + s_vuInfo &= ~PROCESS_EE_SET_T(0xf); + s_vuInfo |= PROCESS_EE_SET_T(vfflush[0]); + } + + xmmregs[vfflush[0]].mode |= MODE_NOFLUSH | MODE_WRITE; // so that lower inst doesn't flush + } + + // notify vuinsts that upper inst is a fmac + if (regs[1].pipe == VUPIPE_FMAC) + s_vuInfo |= PROCESS_VU_SET_FMAC(); + + if (s_JumpX86 > 0) x86regs[s_JumpX86].needed = 1; + if (s_ScheduleXGKICK && s_XGKICKReg > 0) x86regs[s_XGKICKReg].needed = 1; + +#ifdef SUPERVU_VIBRANCHDELAY + if (type & INST_CACHE_VI) + { + assert(vicached >= 0); + int cachedreg = _allocX86reg(-1, X86TYPE_VI | (s_vu ? X86TYPE_VU1 : 0), vicached, MODE_READ); + MOV32RtoM((uptr)&s_VIBranchDelay, cachedreg); + } +#endif + + // check if inst before branch and the write is the same as the read in the branch (wipeout) +// int oldreg=0; +// if( pc == s_pCurBlock->endpc-16 ) { +// itinst2 = itinst; ++itinst2; +// if( itinst2->regs[0].pipe == VUPIPE_BRANCH && (itinst->regs[0].VIwrite&itinst2->regs[0].VIread) ) { +// +// CALLFunc((u32)branchfn); +// assert( itinst->regs[0].VIwrite & 0xffff ); +// Console.WriteLn("vi write before branch"); +// for(s_CacheVIReg = 0; s_CacheVIReg < 16; ++s_CacheVIReg) { +// if( itinst->regs[0].VIwrite & (1<endpc-8 && s_CacheVIReg >= 0 ) { +// assert( s_CacheVIX86 > 0 && x86regs[s_CacheVIX86].inuse && x86regs[s_CacheVIX86].reg == s_CacheVIReg && x86regs[s_CacheVIX86].type == X86TYPE_VITEMP ); +// +// oldreg = _allocX86reg(-1, X86TYPE_VI|(s_vu?X86TYPE_VU1:0), s_CacheVIReg, MODE_READ); +// x86regs[s_CacheVIX86].needed = 1; +// assert( x86regs[oldreg].mode & MODE_WRITE ); +// +// x86regs[s_CacheVIX86].type = X86TYPE_VI|(s_vu?X86TYPE_VU1:0); +// x86regs[oldreg].type = X86TYPE_VITEMP; +// } + + recVU_LOWER_OPCODE[ VU->code >> 25 ](VU, s_vuInfo); + +// if( pc == s_pCurBlock->endpc-8 && s_CacheVIReg >= 0 ) { +// // revert +// x86regs[s_CacheVIX86].inuse = 0; +// x86regs[oldreg].type = X86TYPE_VI|(s_vu?X86TYPE_VU1:0); +// } + + _clearNeededXMMregs(); + _clearNeededX86regs(); + } + + // clip is always written so ok + if ((regs[0].VIwrite | regs[1].VIwrite) & (1 << REG_CLIP_FLAG)) + { + assert(pClipWrite != 0); + s_PrevClipWrite = pClipWrite; + } + + if ((regs[0].VIwrite | regs[1].VIwrite) & (1 << REG_STATUS_FLAG)) + { + assert(pStatusWrite != 0); + s_PrevStatusWrite = pStatusWrite; + } + + if ((regs[0].VIwrite | regs[1].VIwrite) & (1 << REG_MAC_FLAG)) + { + assert(pMACWrite != 0); + s_PrevMACWrite = pMACWrite; + } +} + +/////////////////////////////////// +// Super VU Recompilation Tables // +/////////////////////////////////// + +void recVUMI_BranchHandle() +{ + int bpc = _recbranchAddr(VU->code); + int curjump = 0; + + if (s_pCurInst->type & INST_BRANCH_DELAY) + { + assert((branch&0x17) != 0x10 && (branch&0x17) != 4); // no jump handlig for now + + if ((branch & 0x7) == 3) + { + // previous was a direct jump + curjump = 1; + } + else if (branch & 1) curjump = 2; + } + + assert(s_JumpX86 > 0); + + if ((s_pCurBlock->type & BLOCKTYPE_HASEOP) || s_vu == 0 || SUPERVU_CHECKCONDITION) + MOV32ItoM(SuperVUGetVIAddr(REG_TPC, 0), bpc); + MOV32ItoR(s_JumpX86, 1); // use 1 to disable optimization to XOR + s_pCurBlock->pChildJumps[curjump] = (u32*)x86Ptr - 1; + + if (!(s_pCurInst->type & INST_BRANCH_DELAY)) + { + j8Ptr[1] = JMP8(0); + x86SetJ8(j8Ptr[ 0 ]); + + if ((s_pCurBlock->type & BLOCKTYPE_HASEOP) || s_vu == 0 || SUPERVU_CHECKCONDITION) + MOV32ItoM(SuperVUGetVIAddr(REG_TPC, 0), pc + 8); + MOV32ItoR(s_JumpX86, 1); // use 1 to disable optimization to XOR + s_pCurBlock->pChildJumps[curjump+1] = (u32*)x86Ptr - 1; + + x86SetJ8(j8Ptr[ 1 ]); + } + else + x86SetJ8(j8Ptr[ 0 ]); + + branch |= 1; +} + +// supervu specific insts +void recVUMI_IBQ_prep() +{ + int isreg, itreg; + + if (_Is_ == 0) + { +#ifdef SUPERVU_VIBRANCHDELAY + if (s_pCurInst->vicached >= 0 && s_pCurInst->vicached == _It_) + { + itreg = -1; + } + else +#endif + { + itreg = _checkX86reg(X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _It_, MODE_READ); + } + + s_JumpX86 = _allocX86reg(-1, X86TYPE_VUJUMP, 0, MODE_WRITE); + + if (itreg >= 0) + { + CMP16ItoR(itreg, 0); + } + else CMP16ItoM(SuperVUGetVIAddr(_It_, 1), 0); + } + else if (_It_ == 0) + { +#ifdef SUPERVU_VIBRANCHDELAY + if (s_pCurInst->vicached >= 0 && s_pCurInst->vicached == _Is_) + { + isreg = -1; + } + else +#endif + { + isreg = _checkX86reg(X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _Is_, MODE_READ); + } + + s_JumpX86 = _allocX86reg(-1, X86TYPE_VUJUMP, 0, MODE_WRITE); + + if (isreg >= 0) + { + CMP16ItoR(isreg, 0); + } + else CMP16ItoM(SuperVUGetVIAddr(_Is_, 1), 0); + + } + else + { + _addNeededX86reg(X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _It_); + +#ifdef SUPERVU_VIBRANCHDELAY + if (s_pCurInst->vicached >= 0 && s_pCurInst->vicached == _Is_) + { + isreg = -1; + } + else +#endif + { + isreg = _checkX86reg(X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _Is_, MODE_READ); + } + +#ifdef SUPERVU_VIBRANCHDELAY + if (s_pCurInst->vicached >= 0 && s_pCurInst->vicached == _It_) + { + itreg = -1; + + if (isreg <= 0) + { + // allocate fsreg + if (s_pCurInst->vicached >= 0 && s_pCurInst->vicached == _Is_) + { + isreg = _allocX86reg(-1, X86TYPE_TEMP, 0, MODE_READ | MODE_WRITE); + MOV32MtoR(isreg, SuperVUGetVIAddr(_Is_, 1)); + } + else + isreg = _allocX86reg(-1, X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _Is_, MODE_READ); + } + } + else +#endif + { + itreg = _checkX86reg(X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _It_, MODE_READ); + } + + s_JumpX86 = _allocX86reg(-1, X86TYPE_VUJUMP, 0, MODE_WRITE); + + if (isreg >= 0) + { + if (itreg >= 0) + { + CMP16RtoR(isreg, itreg); + } + else CMP16MtoR(isreg, SuperVUGetVIAddr(_It_, 1)); + } + else if (itreg >= 0) + { + CMP16MtoR(itreg, SuperVUGetVIAddr(_Is_, 1)); + } + else + { + isreg = _allocX86reg(-1, X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _Is_, MODE_READ); + CMP16MtoR(isreg, SuperVUGetVIAddr(_It_, 1)); + } + } +} + +void recVUMI_IBEQ(VURegs* vuu, s32 info) +{ + recVUMI_IBQ_prep(); + j8Ptr[ 0 ] = JNE8(0); + recVUMI_BranchHandle(); +} + +void recVUMI_IBGEZ(VURegs* vuu, s32 info) +{ + int isreg; + s_JumpX86 = _allocX86reg(-1, X86TYPE_VUJUMP, 0, MODE_WRITE); + +#ifdef SUPERVU_VIBRANCHDELAY + if (s_pCurInst->vicached >= 0 && s_pCurInst->vicached == _Is_) + { + isreg = -1; + } + else +#endif + { + isreg = _checkX86reg(X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _Is_, MODE_READ); + } + + if (isreg >= 0) + { + TEST16RtoR(isreg, isreg); + j8Ptr[ 0 ] = JS8(0); + } + else + { + CMP16ItoM(SuperVUGetVIAddr(_Is_, 1), 0x0); + j8Ptr[ 0 ] = JL8(0); + } + + recVUMI_BranchHandle(); +} + +void recVUMI_IBGTZ(VURegs* vuu, s32 info) +{ + int isreg; + s_JumpX86 = _allocX86reg(-1, X86TYPE_VUJUMP, 0, MODE_WRITE); + +#ifdef SUPERVU_VIBRANCHDELAY + if (s_pCurInst->vicached >= 0 && s_pCurInst->vicached == _Is_) + { + isreg = -1; + } + else +#endif + { + isreg = _checkX86reg(X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _Is_, MODE_READ); + } + + if (isreg >= 0) + { + CMP16ItoR(isreg, 0); + j8Ptr[ 0 ] = JLE8(0); + } + else + { + CMP16ItoM(SuperVUGetVIAddr(_Is_, 1), 0x0); + j8Ptr[ 0 ] = JLE8(0); + } + recVUMI_BranchHandle(); +} + +void recVUMI_IBLEZ(VURegs* vuu, s32 info) +{ + int isreg; + s_JumpX86 = _allocX86reg(-1, X86TYPE_VUJUMP, 0, MODE_WRITE); + +#ifdef SUPERVU_VIBRANCHDELAY + if (s_pCurInst->vicached >= 0 && s_pCurInst->vicached == _Is_) + { + isreg = -1; + } + else +#endif + { + isreg = _checkX86reg(X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _Is_, MODE_READ); + } + + if (isreg >= 0) + { + CMP16ItoR(isreg, 0); + j8Ptr[ 0 ] = JG8(0); + } + else + { + CMP16ItoM(SuperVUGetVIAddr(_Is_, 1), 0x0); + j8Ptr[ 0 ] = JG8(0); + } + recVUMI_BranchHandle(); +} + +void recVUMI_IBLTZ(VURegs* vuu, s32 info) +{ + int isreg; + s_JumpX86 = _allocX86reg(-1, X86TYPE_VUJUMP, 0, MODE_WRITE); + +#ifdef SUPERVU_VIBRANCHDELAY + if (s_pCurInst->vicached >= 0 && s_pCurInst->vicached == _Is_) + { + isreg = -1; + } + else +#endif + { + isreg = _checkX86reg(X86TYPE_VI | (VU == &VU1 ? X86TYPE_VU1 : 0), _Is_, MODE_READ); + } + + if (isreg >= 0) + { + TEST16RtoR(isreg, isreg); + j8Ptr[ 0 ] = JNS8(0); + } + else + { + CMP16ItoM(SuperVUGetVIAddr(_Is_, 1), 0x0); + j8Ptr[ 0 ] = JGE8(0); + } + recVUMI_BranchHandle(); +} + +void recVUMI_IBNE(VURegs* vuu, s32 info) +{ + recVUMI_IBQ_prep(); + j8Ptr[ 0 ] = JE8(0); + recVUMI_BranchHandle(); +} + +void recVUMI_B(VURegs* vuu, s32 info) +{ + // supervu will take care of the rest + int bpc = _recbranchAddr(VU->code); + if ((s_pCurBlock->type & BLOCKTYPE_HASEOP) || s_vu == 0 || SUPERVU_CHECKCONDITION) + MOV32ItoM(SuperVUGetVIAddr(REG_TPC, 0), bpc); + + // loops to self, so check condition + if (bpc == s_pCurBlock->startpc && (s_vu == 0 || SUPERVU_CHECKCONDITION)) + { + SuperVUTestVU0Condition(0); + } + + if (s_pCurBlock->blocks.size() > 1) + { + s_JumpX86 = _allocX86reg(-1, X86TYPE_VUJUMP, 0, MODE_WRITE); + MOV32ItoR(s_JumpX86, 1); + s_pCurBlock->pChildJumps[(s_pCurInst->type & INST_BRANCH_DELAY)?1:0] = (u32*)x86Ptr - 1; + s_UnconditionalDelay = 1; + } + + branch |= 3; +} + +void recVUMI_BAL(VURegs* vuu, s32 info) +{ + int bpc = _recbranchAddr(VU->code); + if ((s_pCurBlock->type & BLOCKTYPE_HASEOP) || s_vu == 0 || SUPERVU_CHECKCONDITION) + MOV32ItoM(SuperVUGetVIAddr(REG_TPC, 0), bpc); + + // loops to self, so check condition + if (bpc == s_pCurBlock->startpc && (s_vu == 0 || SUPERVU_CHECKCONDITION)) + { + SuperVUTestVU0Condition(0); + } + + if (_It_) + { + _deleteX86reg(X86TYPE_VI | (s_vu ? X86TYPE_VU1 : 0), _It_, 2); + MOV16ItoM(SuperVUGetVIAddr(_It_, 0), (pc + 8) >> 3); + } + + if (s_pCurBlock->blocks.size() > 1) + { + s_JumpX86 = _allocX86reg(-1, X86TYPE_VUJUMP, 0, MODE_WRITE); + MOV32ItoR(s_JumpX86, 1); + s_pCurBlock->pChildJumps[(s_pCurInst->type & INST_BRANCH_DELAY)?1:0] = (u32*)x86Ptr - 1; + s_UnconditionalDelay = 1; + } + + branch |= 3; +} + +void recVUMI_JR(VURegs* vuu, s32 info) +{ + int isreg = _allocX86reg(-1, X86TYPE_VI | (s_vu ? X86TYPE_VU1 : 0), _Is_, MODE_READ); + LEA32RStoR(EAX, isreg, 3); + + //Mask the address to something valid + if (vuu == &VU0) + AND32ItoR(EAX, 0xfff); + else + AND32ItoR(EAX, 0x3fff); + + if ((s_pCurBlock->type & BLOCKTYPE_HASEOP) || s_vu == 0) MOV32RtoM(SuperVUGetVIAddr(REG_TPC, 0), EAX); + + if (!(s_pCurBlock->type & BLOCKTYPE_HASEOP)) + { + PUSH32I(s_vu); + PUSH32R(EAX); + } + branch |= 0x10; // 0x08 is reserved +} + +void recVUMI_JALR(VURegs* vuu, s32 info) +{ + _addNeededX86reg(X86TYPE_VI | (s_vu ? X86TYPE_VU1 : 0), _It_); + + int isreg = _allocX86reg(-1, X86TYPE_VI | (s_vu ? X86TYPE_VU1 : 0), _Is_, MODE_READ); + LEA32RStoR(EAX, isreg, 3); + + //Mask the address to something valid + if (vuu == &VU0) + AND32ItoR(EAX, 0xfff); + else + AND32ItoR(EAX, 0x3fff); + + if (_It_) + { + _deleteX86reg(X86TYPE_VI | (s_vu ? X86TYPE_VU1 : 0), _It_, 2); + MOV16ItoM(SuperVUGetVIAddr(_It_, 0), (pc + 8) >> 3); + } + + if ((s_pCurBlock->type & BLOCKTYPE_HASEOP) || s_vu == 0) MOV32RtoM(SuperVUGetVIAddr(REG_TPC, 0), EAX); + + if (!(s_pCurBlock->type & BLOCKTYPE_HASEOP)) + { + PUSH32I(s_vu); + PUSH32R(EAX); + } + + branch |= 4; +} + +void recVUMI_XGKICK_(VURegs *VU) +{ + assert(s_XGKICKReg > 0 && x86regs[s_XGKICKReg].inuse && x86regs[s_XGKICKReg].type == X86TYPE_VITEMP); + + x86regs[s_XGKICKReg].inuse = 0; // so free doesn't flush + _freeX86regs(); + _freeXMMregs(); + + OR32ItoM((uptr)&psHu32(GIF_STAT), (GIF_STAT_APATH1 | GIF_STAT_OPH)); // Set PATH1 GIF Status Flags + PUSH32R(s_XGKICKReg); + PUSH32I((uptr)VU->Mem); + + CALLFunc((uptr)VU1XGKICK_MTGSTransfer); + ADD32ItoR(ESP, 8); + AND32ItoM((uptr)&psHu32(GIF_STAT), ~(GIF_STAT_APATH1 | GIF_STAT_OPH)); // Clear PATH1 GIF Status Flags + s_ScheduleXGKICK = 0; +} + +void recVUMI_XGKICK(VURegs *VU, int info) +{ + if (s_ScheduleXGKICK) { + // second xgkick, so launch the first + recVUMI_XGKICK_(VU); + } + + int isreg = _allocX86reg(X86ARG2, X86TYPE_VI | (s_vu ? X86TYPE_VU1 : 0), _Is_, MODE_READ); + _freeX86reg(isreg); // flush + x86regs[isreg].inuse = 1; + x86regs[isreg].type = X86TYPE_VITEMP; + x86regs[isreg].needed = 1; + x86regs[isreg].mode = MODE_WRITE | MODE_READ; + SHL32ItoR(isreg, 4); + AND32ItoR(isreg, 0x3fff); + s_XGKICKReg = isreg; + + if (!SUPERVU_XGKICKDELAY || pc == s_pCurBlock->endpc) { + recVUMI_XGKICK_(VU); + } + else { + s_ScheduleXGKICK = (CHECK_XGKICKHACK) ? (min((u32)4, (s_pCurBlock->endpc-pc)/8)) : 2; + } +} + +void recVU_UPPER_FD_00(VURegs* VU, s32 info); +void recVU_UPPER_FD_01(VURegs* VU, s32 info); +void recVU_UPPER_FD_10(VURegs* VU, s32 info); +void recVU_UPPER_FD_11(VURegs* VU, s32 info); +void recVULowerOP(VURegs* VU, s32 info); +void recVULowerOP_T3_00(VURegs* VU, s32 info); +void recVULowerOP_T3_01(VURegs* VU, s32 info); +void recVULowerOP_T3_10(VURegs* VU, s32 info); +void recVULowerOP_T3_11(VURegs* VU, s32 info); +void recVUunknown(VURegs* VU, s32 info); + +void (*recVU_LOWER_OPCODE[128])(VURegs* VU, s32 info) = +{ + recVUMI_LQ , recVUMI_SQ , recVUunknown , recVUunknown, + recVUMI_ILW , recVUMI_ISW , recVUunknown , recVUunknown, + recVUMI_IADDIU, recVUMI_ISUBIU, recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUMI_FCEQ , recVUMI_FCSET , recVUMI_FCAND, recVUMI_FCOR, /* 0x10 */ + recVUMI_FSEQ , recVUMI_FSSET , recVUMI_FSAND, recVUMI_FSOR, + recVUMI_FMEQ , recVUunknown , recVUMI_FMAND, recVUMI_FMOR, + recVUMI_FCGET , recVUunknown , recVUunknown , recVUunknown, + recVUMI_B , recVUMI_BAL , recVUunknown , recVUunknown, /* 0x20 */ + recVUMI_JR , recVUMI_JALR , recVUunknown , recVUunknown, + recVUMI_IBEQ , recVUMI_IBNE , recVUunknown , recVUunknown, + recVUMI_IBLTZ , recVUMI_IBGTZ , recVUMI_IBLEZ, recVUMI_IBGEZ, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, /* 0x30 */ + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVULowerOP , recVUunknown , recVUunknown , recVUunknown, /* 0x40*/ + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, /* 0x50 */ + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, /* 0x60 */ + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, /* 0x70 */ + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, +}; + +void (*recVULowerOP_T3_00_OPCODE[32])(VURegs* VU, s32 info) = +{ + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUMI_MOVE , recVUMI_LQI , recVUMI_DIV , recVUMI_MTIR, + recVUMI_RNEXT , recVUunknown , recVUunknown , recVUunknown, /* 0x10 */ + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUMI_MFP , recVUMI_XTOP , recVUMI_XGKICK, + recVUMI_ESADD , recVUMI_EATANxy, recVUMI_ESQRT, recVUMI_ESIN, +}; + +void (*recVULowerOP_T3_01_OPCODE[32])(VURegs* VU, s32 info) = +{ + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUMI_MR32 , recVUMI_SQI , recVUMI_SQRT , recVUMI_MFIR, + recVUMI_RGET , recVUunknown , recVUunknown , recVUunknown, /* 0x10 */ + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUMI_XITOP, recVUunknown, + recVUMI_ERSADD, recVUMI_EATANxz, recVUMI_ERSQRT, recVUMI_EATAN, +}; + +void (*recVULowerOP_T3_10_OPCODE[32])(VURegs* VU, s32 info) = +{ + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUMI_LQD , recVUMI_RSQRT, recVUMI_ILWR, + recVUMI_RINIT , recVUunknown , recVUunknown , recVUunknown, /* 0x10 */ + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUMI_ELENG , recVUMI_ESUM , recVUMI_ERCPR, recVUMI_EEXP, +}; + +void (*recVULowerOP_T3_11_OPCODE[32])(VURegs* VU, s32 info) = +{ + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUMI_SQD , recVUMI_WAITQ, recVUMI_ISWR, + recVUMI_RXOR , recVUunknown , recVUunknown , recVUunknown, /* 0x10 */ + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUMI_ERLENG, recVUunknown , recVUMI_WAITP, recVUunknown, +}; + +void (*recVULowerOP_OPCODE[64])(VURegs* VU, s32 info) = +{ + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, /* 0x10 */ + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, /* 0x20 */ + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUMI_IADD , recVUMI_ISUB , recVUMI_IADDI, recVUunknown, /* 0x30 */ + recVUMI_IAND , recVUMI_IOR , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVULowerOP_T3_00, recVULowerOP_T3_01, recVULowerOP_T3_10, recVULowerOP_T3_11, +}; + +void (*recVU_UPPER_OPCODE[64])(VURegs* VU, s32 info) = +{ + recVUMI_ADDx , recVUMI_ADDy , recVUMI_ADDz , recVUMI_ADDw, + recVUMI_SUBx , recVUMI_SUBy , recVUMI_SUBz , recVUMI_SUBw, + recVUMI_MADDx , recVUMI_MADDy , recVUMI_MADDz , recVUMI_MADDw, + recVUMI_MSUBx , recVUMI_MSUBy , recVUMI_MSUBz , recVUMI_MSUBw, + recVUMI_MAXx , recVUMI_MAXy , recVUMI_MAXz , recVUMI_MAXw, /* 0x10 */ + recVUMI_MINIx , recVUMI_MINIy , recVUMI_MINIz , recVUMI_MINIw, + recVUMI_MULx , recVUMI_MULy , recVUMI_MULz , recVUMI_MULw, + recVUMI_MULq , recVUMI_MAXi , recVUMI_MULi , recVUMI_MINIi, + recVUMI_ADDq , recVUMI_MADDq , recVUMI_ADDi , recVUMI_MADDi, /* 0x20 */ + recVUMI_SUBq , recVUMI_MSUBq , recVUMI_SUBi , recVUMI_MSUBi, + recVUMI_ADD , recVUMI_MADD , recVUMI_MUL , recVUMI_MAX, + recVUMI_SUB , recVUMI_MSUB , recVUMI_OPMSUB, recVUMI_MINI, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, /* 0x30 */ + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVUunknown , recVUunknown , recVUunknown , recVUunknown, + recVU_UPPER_FD_00, recVU_UPPER_FD_01, recVU_UPPER_FD_10, recVU_UPPER_FD_11, +}; + +void (*recVU_UPPER_FD_00_TABLE[32])(VURegs* VU, s32 info) = +{ + recVUMI_ADDAx, recVUMI_SUBAx , recVUMI_MADDAx, recVUMI_MSUBAx, + recVUMI_ITOF0, recVUMI_FTOI0, recVUMI_MULAx , recVUMI_MULAq , + recVUMI_ADDAq, recVUMI_SUBAq, recVUMI_ADDA , recVUMI_SUBA , + recVUunknown , recVUunknown , recVUunknown , recVUunknown , + recVUunknown , recVUunknown , recVUunknown , recVUunknown , + recVUunknown , recVUunknown , recVUunknown , recVUunknown , + recVUunknown , recVUunknown , recVUunknown , recVUunknown , + recVUunknown , recVUunknown , recVUunknown , recVUunknown , +}; + +void (*recVU_UPPER_FD_01_TABLE[32])(VURegs* VU, s32 info) = +{ + recVUMI_ADDAy , recVUMI_SUBAy , recVUMI_MADDAy, recVUMI_MSUBAy, + recVUMI_ITOF4 , recVUMI_FTOI4 , recVUMI_MULAy , recVUMI_ABS , + recVUMI_MADDAq, recVUMI_MSUBAq, recVUMI_MADDA , recVUMI_MSUBA , + recVUunknown , recVUunknown , recVUunknown , recVUunknown , + recVUunknown , recVUunknown , recVUunknown , recVUunknown , + recVUunknown , recVUunknown , recVUunknown , recVUunknown , + recVUunknown , recVUunknown , recVUunknown , recVUunknown , + recVUunknown , recVUunknown , recVUunknown , recVUunknown , +}; + +void (*recVU_UPPER_FD_10_TABLE[32])(VURegs* VU, s32 info) = +{ + recVUMI_ADDAz , recVUMI_SUBAz , recVUMI_MADDAz, recVUMI_MSUBAz, + recVUMI_ITOF12, recVUMI_FTOI12, recVUMI_MULAz , recVUMI_MULAi , + recVUMI_ADDAi, recVUMI_SUBAi , recVUMI_MULA , recVUMI_OPMULA, + recVUunknown , recVUunknown , recVUunknown , recVUunknown , + recVUunknown , recVUunknown , recVUunknown , recVUunknown , + recVUunknown , recVUunknown , recVUunknown , recVUunknown , + recVUunknown , recVUunknown , recVUunknown , recVUunknown , + recVUunknown , recVUunknown , recVUunknown , recVUunknown , +}; + +void (*recVU_UPPER_FD_11_TABLE[32])(VURegs* VU, s32 info) = +{ + recVUMI_ADDAw , recVUMI_SUBAw , recVUMI_MADDAw, recVUMI_MSUBAw, + recVUMI_ITOF15, recVUMI_FTOI15, recVUMI_MULAw , recVUMI_CLIP , + recVUMI_MADDAi, recVUMI_MSUBAi, recVUunknown , recVUMI_NOP , + recVUunknown , recVUunknown , recVUunknown , recVUunknown , + recVUunknown , recVUunknown , recVUunknown , recVUunknown , + recVUunknown , recVUunknown , recVUunknown , recVUunknown , + recVUunknown , recVUunknown , recVUunknown , recVUunknown , + recVUunknown , recVUunknown , recVUunknown , recVUunknown , +}; + +void recVU_UPPER_FD_00(VURegs* VU, s32 info) +{ + recVU_UPPER_FD_00_TABLE[(VU->code >> 6) & 0x1f ](VU, info); +} + +void recVU_UPPER_FD_01(VURegs* VU, s32 info) +{ + recVU_UPPER_FD_01_TABLE[(VU->code >> 6) & 0x1f ](VU, info); +} + +void recVU_UPPER_FD_10(VURegs* VU, s32 info) +{ + recVU_UPPER_FD_10_TABLE[(VU->code >> 6) & 0x1f ](VU, info); +} + +void recVU_UPPER_FD_11(VURegs* VU, s32 info) +{ + recVU_UPPER_FD_11_TABLE[(VU->code >> 6) & 0x1f ](VU, info); +} + +void recVULowerOP(VURegs* VU, s32 info) +{ + recVULowerOP_OPCODE[ VU->code & 0x3f ](VU, info); +} + +void recVULowerOP_T3_00(VURegs* VU, s32 info) +{ + recVULowerOP_T3_00_OPCODE[(VU->code >> 6) & 0x1f ](VU, info); +} + +void recVULowerOP_T3_01(VURegs* VU, s32 info) +{ + recVULowerOP_T3_01_OPCODE[(VU->code >> 6) & 0x1f ](VU, info); +} + +void recVULowerOP_T3_10(VURegs* VU, s32 info) +{ + recVULowerOP_T3_10_OPCODE[(VU->code >> 6) & 0x1f ](VU, info); +} + +void recVULowerOP_T3_11(VURegs* VU, s32 info) +{ + recVULowerOP_T3_11_OPCODE[(VU->code >> 6) & 0x1f ](VU, info); +} + +void recVUunknown(VURegs* VU, s32 info) +{ + Console.Notice("Unknown SVU micromode opcode called"); +} diff --git a/pcsx2/xmlpatchloader.cpp b/pcsx2/xmlpatchloader.cpp index 31ecccf0a3..d765ab30ef 100644 --- a/pcsx2/xmlpatchloader.cpp +++ b/pcsx2/xmlpatchloader.cpp @@ -73,18 +73,18 @@ int LoadPatch( const wxString& crc ) bool loadOkay = doc.LoadFile(); if ( !loadOkay ) { - //Console::Error("XML Patch Loader: Could not load file '%s'. Error='%s'.", pfile, doc.ErrorDesc() ); + //Console.Error("XML Patch Loader: Could not load file '%s'. Error='%s'.", pfile, doc.ErrorDesc() ); return -1; } else { - Console::WriteLn("XML Patch Loader: '%s' Found", pfile.c_str() ); + Console.WriteLn("XML Patch Loader: '%s' Found", pfile.c_str() ); } TiXmlNode *root = doc.FirstChild("GAME"); if(!root) { - Console::Error("XML Patch Loader: Root node is not GAME, invalid patch file."); + Console.Error("XML Patch Loader: Root node is not GAME, invalid patch file."); return -1; } @@ -92,7 +92,7 @@ int LoadPatch( const wxString& crc ) const char *title=rootelement->Attribute("title"); if(title) - Console::WriteLn("XML Patch Loader: Game Title: %s", title); + Console.WriteLn("XML Patch Loader: Game Title: %s", title); int result=LoadGroup(root,-1); if(result) { @@ -102,7 +102,7 @@ int LoadPatch( const wxString& crc ) wxString uTitle( wxString::FromAscii( title ) ); if( uTitle.IsEmpty() ) uTitle = L""; - Console::SetTitle( uTitle ); + Console.SetTitle( uTitle ); return 0; } @@ -114,7 +114,7 @@ int LoadGroup(TiXmlNode *group,int gParent) const char *gtitle=groupelement->Attribute("title"); if(gtitle) - Console::WriteLn("XML Patch Loader: Group Title: %s", gtitle); + Console.WriteLn("XML Patch Loader: Group Title: %s", gtitle); const char *enable=groupelement->Attribute("enabled"); bool gEnabled=true; @@ -122,7 +122,7 @@ int LoadGroup(TiXmlNode *group,int gParent) { if(strcmp(enable,"false")==0) { - Console::WriteLn("XML Patch Loader: Group is disabled."); + Console.WriteLn("XML Patch Loader: Group is disabled."); gEnabled=false; } } @@ -133,7 +133,7 @@ int LoadGroup(TiXmlNode *group,int gParent) TiXmlElement *cmelement = comment->ToElement(); const char *comment = cmelement->GetText(); if(comment) - Console::WriteLn("XML Patch Loader: Group Comment:\n%s\n---", comment); + Console.WriteLn("XML Patch Loader: Group Comment:\n%s\n---", comment); } string t; @@ -162,7 +162,7 @@ int LoadGroup(TiXmlNode *group,int gParent) if( pid != NULL ) sscanf(pid, "%x", &g_ZeroGSOptions); else - Console::WriteLn("zerogs attribute wrong"); + Console.WriteLn("zerogs attribute wrong"); } TiXmlNode *roundmode=group->FirstChild("ROUNDMODE"); @@ -210,7 +210,7 @@ int LoadGroup(TiXmlNode *group,int gParent) } } if(( eetype == 0xffff )||( vutype == 0xffff )) { - Console::Notice("XML Patch Loader: WARNING: Invalid value in ROUNDMODE."); + Console.Notice("XML Patch Loader: WARNING: Invalid value in ROUNDMODE."); } else { SetRoundMode(eetype,vutype); @@ -223,7 +223,7 @@ int LoadGroup(TiXmlNode *group,int gParent) TiXmlElement *celement = cpatch->ToElement(); if(!celement) { - Console::Error("XML Patch Loader: ERROR: Couldn't convert node to element." ); + Console.Error("XML Patch Loader: ERROR: Couldn't convert node to element." ); return -1; } @@ -237,7 +237,7 @@ int LoadGroup(TiXmlNode *group,int gParent) const char *value=celement->Attribute("value"); if(ptitle) { - Console::WriteLn("XML Patch Loader: Patch title: %s", ptitle); + Console.WriteLn("XML Patch Loader: Patch title: %s", ptitle); } bool penabled=gEnabled; @@ -245,7 +245,7 @@ int LoadGroup(TiXmlNode *group,int gParent) { if(strcmp(penable,"false")==0) { - Console::Notice("XML Patch Loader: Patch is disabled."); + Console.Notice("XML Patch Loader: Patch is disabled."); penabled=false; } } @@ -253,15 +253,15 @@ int LoadGroup(TiXmlNode *group,int gParent) if(!applymode) applymode="frame"; if(!place) place="EE"; if(!address) { - Console::Error("XML Patch Loader: ERROR: Patch doesn't contain an address."); + Console.Error("XML Patch Loader: ERROR: Patch doesn't contain an address."); return -1; } if(!value) { - Console::Error("XML Patch Loader: ERROR: Patch doesn't contain a value."); + Console.Error("XML Patch Loader: ERROR: Patch doesn't contain a value."); return -1; } if(!size) { - Console::Notice("XML Patch Loader: WARNING: Patch doesn't contain the size. Trying to deduce from the value size."); + Console.Notice("XML Patch Loader: WARNING: Patch doesn't contain the size. Trying to deduce from the value size."); switch(strlen(value)) { case 8: @@ -296,7 +296,7 @@ int LoadGroup(TiXmlNode *group,int gParent) patch[patchnumber].placetopatch=1; } else { - Console::Error("XML Patch Loader: ERROR: Invalid applymode attribute.\n"); + Console.Error("XML Patch Loader: ERROR: Invalid applymode attribute.\n"); patchnumber=0; return -1; } @@ -310,7 +310,7 @@ int LoadGroup(TiXmlNode *group,int gParent) patch[patchnumber].cpu= CPU_IOP; } else { - Console::Error("XML Patch Loader: ERROR: Invalid place attribute.\n"); + Console.Error("XML Patch Loader: ERROR: Invalid place attribute.\n"); patchnumber=0; return -1; } @@ -332,7 +332,7 @@ int LoadGroup(TiXmlNode *group,int gParent) patch[patchnumber].type = BYTE_T; } else { - Console::Error("XML Patch Loader: ERROR: Invalid size attribute.\n"); + Console.Error("XML Patch Loader: ERROR: Invalid size attribute.\n"); patchnumber=0; return -1; } diff --git a/pcsx2_suite_2008.sln b/pcsx2_suite_2008.sln index 0535b237ec..c44dbc5e99 100644 --- a/pcsx2_suite_2008.sln +++ b/pcsx2_suite_2008.sln @@ -118,7 +118,6 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "wx", "wx", "{62BF822E-6A12-49A8-BE8C-C55A9BCA24DA}" ProjectSection(SolutionItems) = preProject common\include\wx\folderdesc.txt = common\include\wx\folderdesc.txt - common\include\wx\scopedarray.h = common\include\wx\scopedarray.h common\include\wx\scopedptr.h = common\include\wx\scopedptr.h EndProjectSection EndProject @@ -242,8 +241,7 @@ Global {18E42F6F-3A62-41EE-B42F-79366C4F1E95}.Release SSSE3|x64.ActiveCfg = Release SSSE3|Win32 {18E42F6F-3A62-41EE-B42F-79366C4F1E95}.Release|Win32.ActiveCfg = Release|Win32 {18E42F6F-3A62-41EE-B42F-79366C4F1E95}.Release|Win32.Build.0 = Release|Win32 - {18E42F6F-3A62-41EE-B42F-79366C4F1E95}.Release|x64.ActiveCfg = Release|x64 - {18E42F6F-3A62-41EE-B42F-79366C4F1E95}.Release|x64.Build.0 = Release|x64 + {18E42F6F-3A62-41EE-B42F-79366C4F1E95}.Release|x64.ActiveCfg = Release|Win32 {E9B51944-7E6D-4BCD-83F2-7BBD5A46182D}.Debug|Win32.ActiveCfg = Debug|Win32 {E9B51944-7E6D-4BCD-83F2-7BBD5A46182D}.Debug|Win32.Build.0 = Debug|Win32 {E9B51944-7E6D-4BCD-83F2-7BBD5A46182D}.Debug|x64.ActiveCfg = Debug|Win32 @@ -315,8 +313,7 @@ Global {E4081455-398C-4610-A87C-90A8A7D72DC3}.Release SSSE3|x64.ActiveCfg = Release|Win32 {E4081455-398C-4610-A87C-90A8A7D72DC3}.Release|Win32.ActiveCfg = Release|Win32 {E4081455-398C-4610-A87C-90A8A7D72DC3}.Release|Win32.Build.0 = Release|Win32 - {E4081455-398C-4610-A87C-90A8A7D72DC3}.Release|x64.ActiveCfg = Release|x64 - {E4081455-398C-4610-A87C-90A8A7D72DC3}.Release|x64.Build.0 = Release|x64 + {E4081455-398C-4610-A87C-90A8A7D72DC3}.Release|x64.ActiveCfg = Release|Win32 {26511268-2902-4997-8421-ECD7055F9E28}.Debug|Win32.ActiveCfg = Debug|Win32 {26511268-2902-4997-8421-ECD7055F9E28}.Debug|Win32.Build.0 = Debug|Win32 {26511268-2902-4997-8421-ECD7055F9E28}.Debug|x64.ActiveCfg = Debug|Win32 @@ -387,8 +384,7 @@ Global {FCDF5AE2-EA47-4CC6-9F20-23A0517FEBCB}.Release SSSE3|x64.ActiveCfg = Release SSSE3|Win32 {FCDF5AE2-EA47-4CC6-9F20-23A0517FEBCB}.Release|Win32.ActiveCfg = Release|Win32 {FCDF5AE2-EA47-4CC6-9F20-23A0517FEBCB}.Release|Win32.Build.0 = Release|Win32 - {FCDF5AE2-EA47-4CC6-9F20-23A0517FEBCB}.Release|x64.ActiveCfg = Release|x64 - {FCDF5AE2-EA47-4CC6-9F20-23A0517FEBCB}.Release|x64.Build.0 = Release|x64 + {FCDF5AE2-EA47-4CC6-9F20-23A0517FEBCB}.Release|x64.ActiveCfg = Release|Win32 {F38D9DF0-F68D-49D9-B3A0-932E74FB74A0}.Debug|Win32.ActiveCfg = Release|Win32 {F38D9DF0-F68D-49D9-B3A0-932E74FB74A0}.Debug|Win32.Build.0 = Release|Win32 {F38D9DF0-F68D-49D9-B3A0-932E74FB74A0}.Debug|x64.ActiveCfg = Release|Win32