/[pcsx2_0.9.7]/trunk/common/include/Pcsx2Types.h
ViewVC logotype

Diff of /trunk/common/include/Pcsx2Types.h

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

--- trunk/common/include/Pcsx2Types.h	2010/09/07 06:28:05	61
+++ trunk/common/include/Pcsx2Types.h	2010/09/07 11:08:22	62
@@ -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)
 
@@ -102,33 +109,71 @@
 #endif
 #endif
 
-//////////////////////////////////////////////////////////////////////////////////////////
-// A rough-and-ready cross platform 128-bit datatype, Non-SSE style.
-//
+// --------------------------------------------------------------------------------------
+//  u128 / s128 - A rough-and-ready cross platform 128-bit datatype, Non-SSE style.
+// --------------------------------------------------------------------------------------
 // Note: These structs don't provide any additional constructors because C++ doesn't allow
 // the use of datatypes with constructors in unions (and since unions aren't the primary
 // uses of these types, that means we can't have constructors). Embedded functions for
 // 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;
+	};
+
+	u64 _u64[2];
+	u32 _u32[4];
+	u16 _u16[8];
+	u8  _u8[16];
 
-	// Explicit conversion from u64
+	// Explicit conversion from u64. Zero-extends the source through 128 bits.
 	static u128 From64( u64 src )
 	{
-		u128 retval = { src, 0 };
+		u128 retval;
+		retval.lo = src;
+		retval.hi = 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 };
+		u128 retval;
+		retval._u32[0] = src;
+		retval._u32[1] = 0;
+		retval.hi = 0;
 		return retval;
 	}
+
+	operator u32() const { return _u32[0]; }
+	operator u16() const { return _u16[0]; }
+	operator u8() const { return _u8[0]; }
+	
+	bool operator==( const u128& right ) const
+	{
+		return (lo == right.lo) && (hi == right.hi);
+	}
+
+	bool operator!=( const u128& right ) const
+	{
+		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
@@ -149,19 +194,41 @@
 		s128 retval = { src, (src < 0) ? -1 : 0 };
 		return retval;
 	}
+
+	operator u32() const { return (s32)lo; }
+	operator u16() const { return (s16)lo; }
+	operator u8() const { return (s8)lo; }
+
+	bool operator==( const s128& right ) const
+	{
+		return (lo == right.lo) && (hi == right.hi);
+	}
+
+	bool operator!=( const s128& right ) const
+	{
+		return (lo != right.lo) && (hi != right.hi);
+	}
 };
 
 #else
 
 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;
 

 

  ViewVC Help
Powered by ViewVC 1.1.22