From 1cac8d394865444ee1f0061ff5c5b31023fa8679 Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Tue, 31 Aug 2010 05:14:00 +0000 Subject: [PATCH] * Added subdivided content to the u128 type (changed it from a struct to a union, added _u32[4], _u16[8], etc). * Added ToString methods to the u128 type. * Bugfixes for the FastFormat string utilities, namely when writing UTF8 content via the UTF16 formatter. * MSVC: Removed obsolete disabling of unsigned/signed mismatch warning (4018) git-svn-id: http://pcsx2.googlecode.com/svn/trunk@3703 96395faa-99c1-11dd-bbfe-3dabce05a288 --- common/include/Pcsx2Types.h | 66 +++++++++++++++++------ common/include/Utilities/StringHelpers.h | 21 +++----- common/src/Utilities/Console.cpp | 6 +-- common/src/Utilities/Exceptions.cpp | 13 +++-- common/src/Utilities/FastFormatString.cpp | 29 +++------- common/src/Utilities/StringHelpers.cpp | 36 +++++++++++++ pcsx2/CDVD/CDVDisoReader.h | 4 -- pcsx2/CDVD/IsoFileTools.h | 4 -- pcsx2/Dmac.h | 2 +- 9 files changed, 109 insertions(+), 72 deletions(-) diff --git a/common/include/Pcsx2Types.h b/common/include/Pcsx2Types.h index c30744d1c4..76147eed84 100644 --- a/common/include/Pcsx2Types.h +++ b/common/include/Pcsx2Types.h @@ -16,16 +16,23 @@ #ifndef __PCSX2TYPES_H__ #define __PCSX2TYPES_H__ -/* - * Based on PS2E Definitions by - linuzappz@hotmail.com, - * shadowpcsx2@yahoo.gr, - * and florinsasu@hotmail.com - */ +// -------------------------------------------------------------------------------------- +// Forward declarations +// -------------------------------------------------------------------------------------- +// Forward declarations for wxWidgets-supporting features. +// If you aren't linking against wxWidgets libraries, then functions that +// depend on these types will not be usable (they will yield linker errors). + +#ifdef __cplusplus + class wxString; + class FastFormatAscii; + class FastFormatUnicode; +#endif -////////////////////////////////////////////////////////////////////////////////////////// -// Basic Atomic Types +// -------------------------------------------------------------------------------------- +// Basic Atomic Types +// -------------------------------------------------------------------------------------- #if defined(_MSC_VER) @@ -111,19 +118,27 @@ typedef s32 sptr; // performing explicit conversion from 64 and 32 bit values are provided instead. // #ifdef __cplusplus -struct u128 +union u128 { - u64 lo; - u64 hi; + struct + { + u64 lo; + u64 hi; + }; - // Explicit conversion from u64 + u64 _u64[2]; + u32 _u32[4]; + u16 _u16[8]; + u8 _u8[16]; + + // Explicit conversion from u64. Zero-extends the source through 128 bits. static u128 From64( u64 src ) { u128 retval = { src, 0 }; return retval; } - // Explicit conversion from u32 + // Explicit conversion from u32. Zero-extends the source through 128 bits. static u128 From32( u32 src ) { u128 retval = { src, 0 }; @@ -143,6 +158,17 @@ struct u128 { return (lo != right.lo) && (hi != right.hi); } + + // In order for the following ToString() and WriteTo methods to be available, you must + // be linking to both wxWidgets and the pxWidgets extension library. If you are not + // using them, then you will need to provide your own implementations of these methods. + wxString ToString() const; + wxString ToString64() const; + wxString ToString8() const; + + void WriteTo( FastFormatAscii& dest ) const; + void WriteTo8( FastFormatAscii& dest ) const; + void WriteTo64( FastFormatAscii& dest ) const; }; struct s128 @@ -183,13 +209,21 @@ struct s128 typedef union _u128_t { - u64 lo; - u64 hi; + struct + { + u64 lo; + u64 hi; + }; + + u64 _u64[2]; + u32 _u32[4]; + u16 _u16[8]; + u8 _u8[16]; } u128; typedef union _s128_t { - s64 lo; + u64 lo; s64 hi; } s128; diff --git a/common/include/Utilities/StringHelpers.h b/common/include/Utilities/StringHelpers.h index 453b8ffb86..4e0ba0a720 100644 --- a/common/include/Utilities/StringHelpers.h +++ b/common/include/Utilities/StringHelpers.h @@ -127,11 +127,11 @@ public: FastFormatAscii& Write( const char* fmt, ... ); FastFormatAscii& WriteV( const char* fmt, va_list argptr ); - const char* GetResult() const; - operator const char*() const; + const char* c_str() const { return m_dest->GetPtr(); } + operator const char*() const { return m_dest->GetPtr(); } const wxString GetString() const; - operator wxString() const; + //operator wxString() const; }; class FastFormatUnicode @@ -149,18 +149,9 @@ public: FastFormatUnicode& WriteV( const char* fmt, va_list argptr ); FastFormatUnicode& WriteV( const wxChar* fmt, va_list argptr ); - const wxChar* GetResult() const; - const wxString GetString() const; - - operator const wxChar*() const - { - return (const wxChar*)m_dest->GetPtr(); - } - - operator wxString() const - { - return (const wxChar*)m_dest->GetPtr(); - } + const wxChar* c_str() const { return (const wxChar*)m_dest->GetPtr(); } + operator const wxChar*() const { return (const wxChar*)m_dest->GetPtr(); } + operator wxString() const { return (const wxChar*)m_dest->GetPtr(); } }; extern bool pxParseAssignmentString( const wxString& src, wxString& ldest, wxString& rdest ); diff --git a/common/src/Utilities/Console.cpp b/common/src/Utilities/Console.cpp index 11c3424b4d..bc75de447b 100644 --- a/common/src/Utilities/Console.cpp +++ b/common/src/Utilities/Console.cpp @@ -298,7 +298,7 @@ const IConsoleWriter ConsoleWriter_wxError = }; // ===================================================================================================== -// IConsoleWriter Implementations +// IConsoleWriter (implementations) // ===================================================================================================== // (all non-virtual members that do common work and then pass the result through DoWrite // or DoWriteLn) @@ -569,14 +569,14 @@ const NullConsoleWriter NullCon = {}; bool ConsoleLogSource::WriteV( ConsoleColors color, const char *fmt, va_list list ) const { ConsoleColorScope cs(color); - DoWrite( pxsFmtV(fmt,list).GetResult() ); + DoWrite( pxsFmtV(fmt,list).c_str() ); return false; } bool ConsoleLogSource::WriteV( ConsoleColors color, const wxChar *fmt, va_list list ) const { ConsoleColorScope cs(color); - DoWrite( pxsFmtV(fmt,list) ); + DoWrite( pxsFmtV(fmt,list).c_str() ); return false; } diff --git a/common/src/Utilities/Exceptions.cpp b/common/src/Utilities/Exceptions.cpp index 5c33bb3c7a..11b4ee1783 100644 --- a/common/src/Utilities/Exceptions.cpp +++ b/common/src/Utilities/Exceptions.cpp @@ -49,21 +49,20 @@ pxDoAssertFnType* pxDoAssert = pxAssertImpl_LogIt; // response times from the Output window... wxString DiagnosticOrigin::ToString( const wxChar* msg ) const { - wxString message; - message.reserve( 2048 ); + FastFormatUnicode message; - message.Printf( L"%s(%d) : assertion failed:\n", srcfile, line ); + message.Write( L"%s(%d) : assertion failed:\n", srcfile, line ); if( function != NULL ) - message += L" Function: " + fromUTF8(function) + L"\n"; + message.Write( " Function: %s\n", function ); - message += L" Thread: " + Threading::pxGetCurrentThreadName() + L"\n"; + message.Write(L" Thread: %s\n", Threading::pxGetCurrentThreadName().c_str() ); if( condition != NULL ) - message += L" Condition: " + wxString(condition) + L"\n"; + message.Write(L" Condition: %s\n", condition); if( msg != NULL ) - message += L" Message: " + wxString(msg) + L"\n"; + message.Write(L" Message: %s\n", msg); return message; } diff --git a/common/src/Utilities/FastFormatString.cpp b/common/src/Utilities/FastFormatString.cpp index a9d7f23d58..945fcec7d6 100644 --- a/common/src/Utilities/FastFormatString.cpp +++ b/common/src/Utilities/FastFormatString.cpp @@ -47,7 +47,7 @@ class FastFormatBuffers protected: typedef SafeAlignedArray BufferType; - static const uint BufferCount = 3; + static const uint BufferCount = 4; BufferType m_buffers[BufferCount]; uint m_curslot; @@ -63,8 +63,8 @@ public: { m_buffers[i].Name = wxsFormat(L"%s Formatting Buffer (slot%d)", (sizeof(CharType)==1) ? L"Ascii" : L"Unicode", i); - m_buffers[i].MakeRoomFor(1024); - m_buffers[i].ChunkSize = 4096; + m_buffers[i].MakeRoomFor(512); + m_buffers[i].ChunkSize = 2048; } m_curslot = 0; @@ -77,7 +77,7 @@ public: bool HasFreeBuffer() const { - return m_curslot < BufferCount; + return m_curslot < BufferCount-1; } BufferType& GrabBuffer() @@ -176,7 +176,7 @@ static __ri void format_that_unicode_mess( SafeArray& buffer, uint writepo while( true ) { int size = buffer.GetLength() / sizeof(wxChar); - int len = wxVsnprintf((wxChar*)buffer.GetPtr(writepos), size-writepos, fmt, argptr); + int len = wxVsnprintf((wxChar*)buffer.GetPtr(writepos*2), size-writepos, fmt, argptr); // some implementations of vsnprintf() don't NUL terminate // the string if there is not enough space for it so @@ -266,11 +266,6 @@ FastFormatUnicode& FastFormatUnicode::Write( const wxChar* fmt, ... ) return *this; } -const wxChar* FastFormatUnicode::GetResult() const -{ - return (wxChar*)m_dest->GetPtr(); -} - // -------------------------------------------------------------------------------------- // FastFormatAscii (implementations) @@ -294,10 +289,10 @@ const wxString FastFormatAscii::GetString() const return fromAscii(m_dest->GetPtr()); } -FastFormatAscii::operator wxString() const +/*FastFormatAscii::operator wxString() const { return fromAscii(m_dest->GetPtr()); -} +}*/ FastFormatAscii& FastFormatAscii::WriteV( const char* fmt, va_list argptr ) { @@ -314,13 +309,3 @@ FastFormatAscii& FastFormatAscii::Write( const char* fmt, ... ) return *this; } -const char* FastFormatAscii::GetResult() const -{ - return m_dest->GetPtr(); -} - -FastFormatAscii::operator const char*() const -{ - return m_dest->GetPtr(); -} - diff --git a/common/src/Utilities/StringHelpers.cpp b/common/src/Utilities/StringHelpers.cpp index f17026be04..1b4785fa8a 100644 --- a/common/src/Utilities/StringHelpers.cpp +++ b/common/src/Utilities/StringHelpers.cpp @@ -35,6 +35,42 @@ __fi wxString fromAscii( const char* src ) return wxString::FromAscii( src ); } +wxString u128::ToString() const +{ + return pxsFmt( L"0x%08X.%08X.%08X.%08X", _u32[0], _u32[1], _u32[2], _u32[3] ); +} + +wxString u128::ToString64() const +{ + return pxsFmt( L"0x%08X%08X.%08X%08X", _u32[0], _u32[1], _u32[2], _u32[3] ); +} + +wxString u128::ToString8() const +{ + FastFormatUnicode result; + result.Write( L"0x%02X.%02X", _u8[0], _u8[1] ); + for (uint i=2; i<16; i+=2) + result.Write( L".%02X.%02X", _u8[i], _u8[i+1] ); + return result; +} + +void u128::WriteTo( FastFormatAscii& dest ) const +{ + dest.Write( "0x%08X.%08X.%08X.%08X", _u32[0], _u32[1], _u32[2], _u32[3] ); +} + +void u128::WriteTo64( FastFormatAscii& dest ) const +{ + dest.Write( "0x%08X%08X.%08X%08X", _u32[0], _u32[1], _u32[2], _u32[3] ); +} + +void u128::WriteTo8( FastFormatAscii& dest ) const +{ + dest.Write( "0x%02X.%02X", _u8[0], _u8[1] ); + for (uint i=2; i<16; i+=2) + dest.Write( ".%02X.%02X", _u8[i], _u8[i+1] ); +} + // 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. diff --git a/pcsx2/CDVD/CDVDisoReader.h b/pcsx2/CDVD/CDVDisoReader.h index 5d6dceb8f5..e03ef00689 100644 --- a/pcsx2/CDVD/CDVDisoReader.h +++ b/pcsx2/CDVD/CDVDisoReader.h @@ -16,10 +16,6 @@ #ifndef __CDVD_ISO_READER_H__ #define __CDVD_ISO_READER_H__ -#ifdef _MSC_VER -#pragma warning(disable:4018) -#endif - #include #include "IopCommon.h" diff --git a/pcsx2/CDVD/IsoFileTools.h b/pcsx2/CDVD/IsoFileTools.h index 88e91109ac..5c4469469c 100644 --- a/pcsx2/CDVD/IsoFileTools.h +++ b/pcsx2/CDVD/IsoFileTools.h @@ -29,10 +29,6 @@ #define _FILE_OFFSET_BITS 64 -#ifdef _MSC_VER -# pragma warning(disable:4018) // disable signed/unsigned mismatch error -#endif - #include "IopCommon.h" #include diff --git a/pcsx2/Dmac.h b/pcsx2/Dmac.h index 13113b684d..0a8cc92e59 100644 --- a/pcsx2/Dmac.h +++ b/pcsx2/Dmac.h @@ -524,7 +524,7 @@ union tDMAC_ADDR wxCharBuffer ToUTF8(bool sprIsValid=true) const { - return FastFormatAscii().Write((sprIsValid && SPR) ? "0x%04X(SPR)" : "0x%08X", ADDR).GetResult(); + return FastFormatAscii().Write((sprIsValid && SPR) ? "0x%04X(SPR)" : "0x%08X", ADDR).c_str(); } };