[Scummvm-cvs-logs] SF.net SVN: scummvm:[52816] scummvm/trunk/backends/platform/psp

Bluddy at users.sourceforge.net Bluddy at users.sourceforge.net
Mon Sep 20 16:09:39 CEST 2010


Revision: 52816
          http://scummvm.svn.sourceforge.net/scummvm/?rev=52816&view=rev
Author:   Bluddy
Date:     2010-09-20 14:09:39 +0000 (Mon, 20 Sep 2010)

Log Message:
-----------
PSP: Split up PspMemory class.

PspMemorySwap is more specific ie. it only needs to be known by PSP files. It could be put in another file, but not worth the effort.

Modified Paths:
--------------
    scummvm/trunk/backends/platform/psp/display_client.cpp
    scummvm/trunk/backends/platform/psp/memory.cpp
    scummvm/trunk/backends/platform/psp/memory.h

Modified: scummvm/trunk/backends/platform/psp/display_client.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/display_client.cpp	2010-09-20 14:05:32 UTC (rev 52815)
+++ scummvm/trunk/backends/platform/psp/display_client.cpp	2010-09-20 14:09:39 UTC (rev 52816)
@@ -32,6 +32,7 @@
 #include "backends/platform/psp/psppixelformat.h"
 #include "backends/platform/psp/display_client.h"
 #include "backends/platform/psp/display_manager.h"
+#define PSP_INCLUDE_SWAP
 #include "backends/platform/psp/memory.h"
 
 //#define __PSP_DEBUG_FUNCS__	/* For debugging the stack */
@@ -341,14 +342,14 @@
 	if (pitch == realWidthInBytes && pitch == recWidthInBytes) {
 		//memcpy(dst, buf, _pixelFormat.pixelsToBytes(recHeight * recWidth));
 		if (_pixelFormat.swapRB)
-			PspMemory::fastSwap(dst, buf, _pixelFormat.pixelsToBytes(recHeight * recWidth), _pixelFormat);
+			PspMemorySwap::fastSwap(dst, buf, _pixelFormat.pixelsToBytes(recHeight * recWidth), _pixelFormat);
 		else
 			PspMemory::fastCopy(dst, buf, _pixelFormat.pixelsToBytes(recHeight * recWidth));
 	} else {
 		do {
 			//memcpy(dst, buf, recWidthInBytes);
 			if (_pixelFormat.swapRB)
-				PspMemory::fastSwap(dst, buf, recWidthInBytes, _pixelFormat);
+				PspMemorySwap::fastSwap(dst, buf, recWidthInBytes, _pixelFormat);
 			else
 				PspMemory::fastCopy(dst, buf, recWidthInBytes);
 			buf += pitch;
@@ -370,7 +371,7 @@
 	do {
 		//memcpy(dst, src, sourceWidthInBytes);
 		if (_pixelFormat.swapRB)
-			PspMemory::fastSwap(dst, src, sourceWidthInBytes, _pixelFormat);
+			PspMemorySwap::fastSwap(dst, src, sourceWidthInBytes, _pixelFormat);
 		else
 			PspMemory::fastCopy(dst, src, sourceWidthInBytes);
 		src += realWidthInBytes;

Modified: scummvm/trunk/backends/platform/psp/memory.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/memory.cpp	2010-09-20 14:05:32 UTC (rev 52815)
+++ scummvm/trunk/backends/platform/psp/memory.cpp	2010-09-20 14:09:39 UTC (rev 52816)
@@ -26,6 +26,7 @@
 #include "common/scummsys.h"
 #include "common/singleton.h"
 #include "backends/platform/psp/psppixelformat.h"
+#define PSP_INCLUDE_SWAP
 #include "backends/platform/psp/memory.h"
 
 // Class Copier --------------------------------------------------------------------------
@@ -99,96 +100,6 @@
 #endif		
 }
 
-void PspMemory::testCopy(const byte *debugDst, const byte *debugSrc, uint32 debugBytes) {
-	
-	bool mismatch = false;
-	PSP_INFO_PRINT("testing fastCopy...");
-
-	for (uint32 i = 0; i < debugBytes; i++) {
-		if (debugDst[i] != debugSrc[i]) {
-			if (!mismatch) {
-				PSP_INFO_PRINT("**** mismatch in copy! ****\n");
-				PSP_INFO_PRINT("dst[%p], src[%p], bytes[%u]\n", debugDst, debugSrc, debugBytes);
-				mismatch = true;
-			}
-			PSP_INFO_PRINT("[%d]%x!=%x ", i, debugSrc[i], debugDst[i]);
-		}
-	}
-	if (mismatch) {
-		PSP_INFO_PRINT("\n");
-	} else {
-		PSP_INFO_PRINT("ok\n");
-	}	
-}
-
-// 
-// used to swap red and blue
-void PspMemory::swap(uint16 *dst16, const uint16 *src16, uint32 bytes, PSPPixelFormat &format) {
-	DEBUG_ENTER_FUNC();
-
-#ifdef TEST_MEMORY_COPY
-	uint32 debugBytes = bytes;
-	const uint16 *debugDst = dst16, *debugSrc = src16;
-#endif
-	
-	// align the destination pointer first
-	uint32 prefixDst = (((uint32)dst16) & 0x3);	// for swap, we can only have 2 or 0 as our prefix
-	
-	if (prefixDst) {
-		bytes -= prefixDst;						// remember we assume bytes > 4
-		*dst16++ = format.swapRedBlue16(*src16++);
-		
-		if (bytes < MIN_AMOUNT_FOR_COMPLEX_COPY) { // check if it's worthwhile to continue
-			swap16(dst16, src16, bytes, format);
-
-#ifdef TEST_MEMORY_COPY
-			testSwap(debugDst, debugSrc, debugBytes, format);
-#endif		
-			return;
-		}
-	}
-	
-	// check the source pointer alignment now
-	uint32 alignSrc = (((uint32)src16) & 0x3);
-	
-	if (alignSrc) {						// we'll need to realign our reads
-		PSP_DEBUG_PRINT("misaligned copy of %u bytes from %p to %p\n", bytes, src16, dst16);
-		swap32Misaligned((uint32 *)dst16, src16, bytes, format);
-	} else {
-		swap32Aligned((uint32 *)dst16, (const uint32 *)src16, bytes, format);
-	}
-	
-#ifdef TEST_MEMORY_COPY
-	testSwap(debugDst, debugSrc, debugBytes, format);
-#endif		
-	
-}
-
-void PspMemory::testSwap(const uint16 *debugDst, const uint16 *debugSrc, uint32 debugBytes, PSPPixelFormat &format) {
-	
-	bool mismatch = false;
-	PSP_INFO_PRINT("testing fastSwap...");
-	
-	uint32 shorts = debugBytes >> 1;
-
-	for (uint32 i = 0; i < shorts; i++) {
-		if (debugDst[i] != format.swapRedBlue16(debugSrc[i])) {
-			if (!mismatch) {
-				PSP_INFO_PRINT("**** mismatch in swap! ****\n");
-				PSP_INFO_PRINT("dst[%p], src[%p], bytes[%u]\n", debugDst, debugSrc, debugBytes);
-				mismatch = true;
-			}
-			PSP_INFO_PRINT("[%d]%x!=%x ", i<<1, format.swapRedBlue16(debugSrc[i]), debugDst[i]);
-		}
-	}
-	if (mismatch) {
-		PSP_INFO_PRINT("\n");
-	} else {
-		PSP_INFO_PRINT("ok\n");
-	}	
-}
-
-
 void PspMemory::copy32Aligned(uint32 *dst32, const uint32 *src32, uint32 bytes) {
 	PSP_DEBUG_PRINT("copy32Aligned(): dst32[%p], src32[%p], bytes[%d]\n", dst32, src32, bytes);
 
@@ -257,41 +168,6 @@
 	}
 }
 
-void PspMemory::swap32Aligned(uint32 *dst32, const uint32 *src32, uint32 bytes, PSPPixelFormat &format) {
-	DEBUG_ENTER_FUNC();
-	int words4 = bytes >> 4;
-	
-	// try blocks of 4 words at a time
-	while (words4--) {
-		uint32 a, b, c, d;
-		a = format.swapRedBlue32(src32[0]);
-		b = format.swapRedBlue32(src32[1]);
-		c = format.swapRedBlue32(src32[2]);
-		d = format.swapRedBlue32(src32[3]);
-		dst32[0] = a;
-		dst32[1] = b;
-		dst32[2] = c;
-		dst32[3] = d;
-		dst32 += 4;
-		src32 += 4;
-	}
-
-	uint32 bytesLeft = bytes & 0xF;
-	uint32 words = bytesLeft >> 2;
-	
-	// now just do words
-	while (words--) {
-		*dst32++ = format.swapRedBlue32(*src32++);
-	}	
-
-	bytesLeft = bytes & 0x3;
-	
-	if (bytesLeft) {	// for swap, can only be 1 short left
-		*((uint16 *)dst32) = format.swapRedBlue16(*((uint16 *)src32));
-	}
-}
-
-
 // More challenging -- need to shift
 // Assume dst is aligned
 void PspMemory::copy32Misaligned(uint32 *dst32, const byte *src, uint32 bytes, uint32 alignSrc) {
@@ -368,9 +244,132 @@
 	}
 }
 
+void PspMemory::testCopy(const byte *debugDst, const byte *debugSrc, uint32 debugBytes) {
+	
+	bool mismatch = false;
+	PSP_INFO_PRINT("testing fastCopy...");
+
+	for (uint32 i = 0; i < debugBytes; i++) {
+		if (debugDst[i] != debugSrc[i]) {
+			if (!mismatch) {
+				PSP_INFO_PRINT("**** mismatch in copy! ****\n");
+				PSP_INFO_PRINT("dst[%p], src[%p], bytes[%u]\n", debugDst, debugSrc, debugBytes);
+				mismatch = true;
+			}
+			PSP_INFO_PRINT("[%d]%x!=%x ", i, debugSrc[i], debugDst[i]);
+		}
+	}
+	if (mismatch) {
+		PSP_INFO_PRINT("\n");
+	} else {
+		PSP_INFO_PRINT("ok\n");
+	}	
+}
+
+// 
+// used to swap red and blue
+void PspMemorySwap::swap(uint16 *dst16, const uint16 *src16, uint32 bytes, PSPPixelFormat &format) {
+	DEBUG_ENTER_FUNC();
+
+#ifdef TEST_MEMORY_COPY
+	uint32 debugBytes = bytes;
+	const uint16 *debugDst = dst16, *debugSrc = src16;
+#endif
+	
+	// align the destination pointer first
+	uint32 prefixDst = (((uint32)dst16) & 0x3);	// for swap, we can only have 2 or 0 as our prefix
+	
+	if (prefixDst) {
+		bytes -= prefixDst;						// remember we assume bytes > 4
+		*dst16++ = format.swapRedBlue16(*src16++);
+		
+		if (bytes < MIN_AMOUNT_FOR_COMPLEX_COPY) { // check if it's worthwhile to continue
+			swap16(dst16, src16, bytes, format);
+
+#ifdef TEST_MEMORY_COPY
+			testSwap(debugDst, debugSrc, debugBytes, format);
+#endif		
+			return;
+		}
+	}
+	
+	// check the source pointer alignment now
+	uint32 alignSrc = (((uint32)src16) & 0x3);
+	
+	if (alignSrc) {						// we'll need to realign our reads
+		PSP_DEBUG_PRINT("misaligned copy of %u bytes from %p to %p\n", bytes, src16, dst16);
+		swap32Misaligned((uint32 *)dst16, src16, bytes, format);
+	} else {
+		swap32Aligned((uint32 *)dst16, (const uint32 *)src16, bytes, format);
+	}
+	
+#ifdef TEST_MEMORY_COPY
+	testSwap(debugDst, debugSrc, debugBytes, format);
+#endif		
+	
+}
+
+void PspMemorySwap::testSwap(const uint16 *debugDst, const uint16 *debugSrc, uint32 debugBytes, PSPPixelFormat &format) {
+	
+	bool mismatch = false;
+	PSP_INFO_PRINT("testing fastSwap...");
+	
+	uint32 shorts = debugBytes >> 1;
+
+	for (uint32 i = 0; i < shorts; i++) {
+		if (debugDst[i] != format.swapRedBlue16(debugSrc[i])) {
+			if (!mismatch) {
+				PSP_INFO_PRINT("**** mismatch in swap! ****\n");
+				PSP_INFO_PRINT("dst[%p], src[%p], bytes[%u]\n", debugDst, debugSrc, debugBytes);
+				mismatch = true;
+			}
+			PSP_INFO_PRINT("[%d]%x!=%x ", i<<1, format.swapRedBlue16(debugSrc[i]), debugDst[i]);
+		}
+	}
+	if (mismatch) {
+		PSP_INFO_PRINT("\n");
+	} else {
+		PSP_INFO_PRINT("ok\n");
+	}	
+}
+
+void PspMemorySwap::swap32Aligned(uint32 *dst32, const uint32 *src32, uint32 bytes, PSPPixelFormat &format) {
+	DEBUG_ENTER_FUNC();
+	int words4 = bytes >> 4;
+	
+	// try blocks of 4 words at a time
+	while (words4--) {
+		uint32 a, b, c, d;
+		a = format.swapRedBlue32(src32[0]);
+		b = format.swapRedBlue32(src32[1]);
+		c = format.swapRedBlue32(src32[2]);
+		d = format.swapRedBlue32(src32[3]);
+		dst32[0] = a;
+		dst32[1] = b;
+		dst32[2] = c;
+		dst32[3] = d;
+		dst32 += 4;
+		src32 += 4;
+	}
+
+	uint32 bytesLeft = bytes & 0xF;
+	uint32 words = bytesLeft >> 2;
+	
+	// now just do words
+	while (words--) {
+		*dst32++ = format.swapRedBlue32(*src32++);
+	}	
+
+	bytesLeft = bytes & 0x3;
+	
+	if (bytesLeft) {	// for swap, can only be 1 short left
+		*((uint16 *)dst32) = format.swapRedBlue16(*((uint16 *)src32));
+	}
+}
+
 // More challenging -- need to shift
 // We assume dst is aligned
-void PspMemory::swap32Misaligned(uint32 *dst32, const uint16 *src16, uint32 bytes, PSPPixelFormat &format) {
+void PspMemorySwap::swap32Misaligned(uint32 *dst32, const uint16 *src16, uint32 bytes, PSPPixelFormat &format) {
 	DEBUG_ENTER_FUNC();
 
 	const uint32 shiftValue = 16;

Modified: scummvm/trunk/backends/platform/psp/memory.h
===================================================================
--- scummvm/trunk/backends/platform/psp/memory.h	2010-09-20 14:05:32 UTC (rev 52815)
+++ scummvm/trunk/backends/platform/psp/memory.h	2010-09-20 14:09:39 UTC (rev 52816)
@@ -40,28 +40,13 @@
 class PspMemory {
 private:
 	static void testCopy(const byte *debugDst, const byte *debugSrc, uint32 debugBytes);
-	static void testSwap(const uint16 *debugDst, const uint16 *debugSrc, uint32 debugBytes, PSPPixelFormat &format);
 	static void copy(byte *dst, const byte *src, uint32 bytes);
-	static void swap(uint16 *dst16, const uint16 *src16, uint32 bytes, PSPPixelFormat &format);
 	static void copy32Aligned(uint32 *dst32, const uint32 *src32, uint32 bytes);
-	static void swap32Aligned(uint32 *dst32, const uint32 *src32, uint32 bytes, PSPPixelFormat &format);
 	static void copy32Misaligned(uint32 *dst32, const byte *src, uint32 bytes, uint32 alignSrc);
-	static void swap32Misaligned(uint32 *dst32, const uint16 *src16, uint32 bytes, PSPPixelFormat &format);
-	static void copy16(uint16 *dst, const uint16 *src, uint32 bytes);
-
-	// For swapping, we know that we have multiples of 16 bits
-	static void swap16(uint16 *dst16, const uint16 *src16, uint32 bytes, PSPPixelFormat &format) {
-		PSP_DEBUG_PRINT("swap16 called with dst16[%p], src16[%p], bytes[%d]\n", dst16, src16, bytes);
-		uint32 shorts = bytes >> 1;
-
-		while (shorts--) {
-			*dst16++ = format.swapRedBlue16(*src16++);
-		}
-	}
 	
-	static void copy8(byte *dst, const byte *src, uint32 bytes) {
-		PSP_DEBUG_PRINT("copy8 called with dst[%p], src[%p], bytes[%d]\n", dst, src, bytes);
-		while (bytes--) {
+	static inline void copy8(byte *dst, const byte *src, int32 bytes) {
+		//PSP_DEBUG_PRINT("copy8 called with dst[%p], src[%p], bytes[%d]\n", dst, src, bytes);
+		for (;bytes; bytes--) {
 			*dst++ = *src++;
 		}
 	}
@@ -75,7 +60,32 @@
 			copy(dst, src, bytes);
 		}
 	}
+};
 
+#endif /* PSP_MEMORY_H */
+
+#if defined(PSP_INCLUDE_SWAP) && !defined(PSP_MEMORY_SWAP_H)
+#define PSP_MEMORY_SWAP_H
+
+//#include "backends/platform/psp/psppixelformat.h"
+
+class PspMemorySwap {
+private:
+	static void testSwap(const uint16 *debugDst, const uint16 *debugSrc, uint32 debugBytes, PSPPixelFormat &format);
+	static void swap(uint16 *dst16, const uint16 *src16, uint32 bytes, PSPPixelFormat &format);
+	static void swap32Aligned(uint32 *dst32, const uint32 *src32, uint32 bytes, PSPPixelFormat &format);
+	static void swap32Misaligned(uint32 *dst32, const uint16 *src16, uint32 bytes, PSPPixelFormat &format);
+	// For swapping, we know that we have multiples of 16 bits
+	static void swap16(uint16 *dst16, const uint16 *src16, uint32 bytes, PSPPixelFormat &format) {
+	PSP_DEBUG_PRINT("swap16 called with dst16[%p], src16[%p], bytes[%d]\n", dst16, src16, bytes);
+	uint32 shorts = bytes >> 1;
+
+	while (shorts--) {
+		*dst16++ = format.swapRedBlue16(*src16++);
+	}
+}
+
+public:
 	static void fastSwap(byte *dst, const byte *src, uint32 bytes, PSPPixelFormat &format) {
 		if (bytes < MIN_AMOUNT_FOR_COMPLEX_COPY * 2) {
 			swap16((uint16 *)dst, (uint16 *)src, bytes, format);
@@ -85,6 +95,6 @@
 	}
 };
 
-#endif /* PSP_MEMORY_H */
+#endif /* PSP_INCLUDE_SWAP */
 
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list