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

wonst719 at users.sourceforge.net wonst719 at users.sourceforge.net
Wed Sep 13 09:33:03 CEST 2006


Revision: 23870
          http://svn.sourceforge.net/scummvm/?rev=23870&view=rev
Author:   wonst719
Date:     2006-09-13 00:32:54 -0700 (Wed, 13 Sep 2006)

Log Message:
-----------
Implement file cache. needs some testing :)
Fix some bugs in memory management.

Modified Paths:
--------------
    scummvm/trunk/backends/platform/gp32/Makefile
    scummvm/trunk/backends/platform/gp32/gp32_main.cpp
    scummvm/trunk/backends/platform/gp32/gp32std.cpp
    scummvm/trunk/backends/platform/gp32/gp32std_file.cpp
    scummvm/trunk/backends/platform/gp32/gp32std_file.h
    scummvm/trunk/backends/platform/gp32/gp32std_memory.cpp

Modified: scummvm/trunk/backends/platform/gp32/Makefile
===================================================================
--- scummvm/trunk/backends/platform/gp32/Makefile	2006-09-10 23:57:52 UTC (rev 23869)
+++ scummvm/trunk/backends/platform/gp32/Makefile	2006-09-13 07:32:54 UTC (rev 23870)
@@ -28,7 +28,7 @@
 			-mno-thumb-interwork \
 			-I$(GPSDK)/include \
 			-g \
-			-O \
+			-O2 \
 			-fomit-frame-pointer
 #			-ffast-math \
 #			-fshort-double
@@ -92,9 +92,9 @@
 #LIBS		+=	-Lbackends/platform/gp32/gpmad -lgpmad
 
 # Support libminilzo.
-#DEFINES		+=	-DUSE_MINILZO
-#INCLUDES	+=	-Ibackends/platform/gp32/minilzo
-#LIBS		+=	-Lbackends/platform/gp32/minilzo -lminilzo
+DEFINES		+=	-DUSE_MINILZO
+INCLUDES	+=	-Ibackends/platform/gp32/minilzo
+LIBS		+=	-Lbackends/platform/gp32/minilzo -lminilzo
 
 # Support for 8:3 save files names (The GP32 uses FAT12/16 (no vFAT) for the file system).
 DEFINES		+=	-DSHORT_SAVENAMES
@@ -159,20 +159,16 @@
 DISABLE_SCUMM_7_8 = 1
 DISABLE_HE = 1
 
-# ???
-DISABLE_SIMON = 1
-DISABLE_SKY = 1
-DISABLE_QUEEN = 1
-DISABLE_GOB = 1
-DISABLE_LURE = 1
-DISABLE_CINE = 1
+#DISABLE_SIMON = 1
+#DISABLE_SKY = 1
+#DISABLE_QUEEN = 1
+#DISABLE_GOB = 1
+#DISABLE_LURE = 1
+#DISABLE_CINE = 1
+#DISABLE_SAGA = 1
+#DISABLE_KYRA = 1
+#DISABLE_AGI = 1
 
-# In-development engines below.
-# Disable for ALL release builds.
-DISABLE_SAGA = 1
-DISABLE_KYRA = 1
-DISABLE_AGI = 1
-
 # The engines below are not supported on the GP32 port so there is
 # no point compiling support into the binary.
 DISABLE_SWORD1 = 1

Modified: scummvm/trunk/backends/platform/gp32/gp32_main.cpp
===================================================================
--- scummvm/trunk/backends/platform/gp32/gp32_main.cpp	2006-09-10 23:57:52 UTC (rev 23869)
+++ scummvm/trunk/backends/platform/gp32/gp32_main.cpp	2006-09-13 07:32:54 UTC (rev 23870)
@@ -67,6 +67,7 @@
 	//doConfig
 	gp_initGammaTable((float)g_vars.gammaRamp / 10000);
 	gp_setCpuSpeed(g_vars.cpuSpeed);
+	GPDEBUG("Set CPU Speed: %d", g_vars.cpuSpeed);
 
 	// FOR DEBUG PURPOSE!
 	//int argc = 4;

Modified: scummvm/trunk/backends/platform/gp32/gp32std.cpp
===================================================================
--- scummvm/trunk/backends/platform/gp32/gp32std.cpp	2006-09-10 23:57:52 UTC (rev 23869)
+++ scummvm/trunk/backends/platform/gp32/gp32std.cpp	2006-09-13 07:32:54 UTC (rev 23870)
@@ -286,7 +286,7 @@
 }
 
 void NP(const char *fmt, ...) {
-	return;
+//	return;
 	char s[256];
 	va_list marker;
 
@@ -299,7 +299,7 @@
 }
 
 void LP(const char *fmt, ...) {
-	return;
+//	return;
 	char s[256];
 	va_list marker;
 
@@ -312,7 +312,7 @@
 }
 
 void SP(const char *fmt, ...) {
-	return;
+//	return;
 	char s[256];
 	va_list marker;
 
@@ -325,7 +325,7 @@
 }
 
 void BP(const char *fmt, ...) {
-	return;
+//	return;
 	char s[256];
 	va_list marker;
 

Modified: scummvm/trunk/backends/platform/gp32/gp32std_file.cpp
===================================================================
--- scummvm/trunk/backends/platform/gp32/gp32std_file.cpp	2006-09-10 23:57:52 UTC (rev 23869)
+++ scummvm/trunk/backends/platform/gp32/gp32std_file.cpp	2006-09-13 07:32:54 UTC (rev 23870)
@@ -38,11 +38,49 @@
 FILE *gp_stdin = NULL;
 
 // Cache Idea / Code borrowed from the ps2 port
-//#define USE_CACHE
+#define USE_CACHE
 
 //////////////////
 //File functions
 
+
+// CACHE
+inline bool gp_cacheInPos(GPFILE *stream)
+{
+	return (stream->cachePos <= stream->filePos && stream->filePos < stream->cachePos + stream->bytesInCache);
+}
+
+int gp_cacheMiss(GPFILE *stream)
+{
+	unsigned long readcount = 0;
+
+	int copyLen = stream->fileSize - stream->filePos;
+	if (copyLen > FCACHE_SIZE)
+		copyLen = FCACHE_SIZE;
+
+	stream->cachePos = stream->filePos;
+	stream->cacheBufOffs = 0;
+	stream->bytesInCache = copyLen;
+
+	ERR_CODE err = GpFileRead(stream->handle, stream->cacheData, copyLen, &readcount);
+
+	stream->physFilePos += copyLen;
+
+	return err;
+}
+
+int gp_flushWriteCache(GPFILE *stream) {
+	ERR_CODE err = GpFileWrite(stream->handle, stream->cacheData, stream->bytesInCache); // flush cache
+
+	stream->filePos += stream->bytesInCache;
+	stream->physFilePos += stream->bytesInCache;
+	stream->bytesInCache = 0;
+
+	return err;
+}
+
+///////////////////////////////////////////////////////////////
+
 GPFILE *gp_fopen(const char *fileName, const char *openMode) {
 	//FIXME: allocation, mode
 	uint32 mode;
@@ -88,6 +126,9 @@
 
 	file->mode = mode;
 	file->cachePos = 0;
+	file->filePos = 0;
+	file->cacheBufOffs = 0;
+	file->physFilePos = 0;
 	file->bytesInCache = 0;
 
 	return file;
@@ -106,9 +147,8 @@
 */
 
 #ifdef USE_CACHE
-	if (stream->cachePos && stream->mode == OPEN_W) {
-		GpFileWrite(stream->handle, (char *)stream->cacheData, stream->cachePos); // flush cache
-		stream->cachePos = 0;
+	if (stream->bytesInCache && stream->mode == OPEN_W) {
+		gp_flushWriteCache(stream);
 	}
 #endif
 
@@ -130,18 +170,38 @@
 		whence = FROM_END;
 		break;
 	}
-	return GpFileSeek(stream->handle, whence, offset, (long *)&stream->filePos);	//FIXME?
+
+	ERR_CODE err;
+#ifdef USE_CACHE
+	// need to flush cache
+	if (stream->mode == OPEN_W) { // write
+		gp_flushWriteCache(stream);
+		err = GpFileSeek(stream->handle, whence, offset, (long *)&stream->filePos);
+	} else { // read
+		if (whence == SEEK_CUR)
+			offset += stream->physFilePos - stream->filePos;
+
+		err = GpFileSeek(stream->handle, whence, offset, (long *)&stream->physFilePos);
+		stream->filePos = stream->physFilePos;
+
+		if (gp_cacheInPos(stream)) {
+		} else { // cache miss
+			gp_cacheMiss(stream);
+		}
+	}
+#endif
+
+	return 1;
+	//return 0;	//FIXME?
 }
 
 size_t gp_fread(void *ptr, size_t size, size_t n, GPFILE *stream) {
-	ulong readcount = 0;
-	int len = size * n;
-	
-#ifdef USE_CACHE
+	unsigned int len = size * n;
 	uint8 *dest = (uint8 *)ptr;
 
-	while (len && (stream->filePos != stream->fileSize)) {
-		if (stream->cachePos <= filePos && filePos < stream->cachePos + stream->bytesInCache) {
+#ifdef USE_CACHE
+	while (len && !gp_feof(stream)) {
+		if (gp_cacheInPos(stream)) {
 			uint32 startPos = (stream->cacheBufOffs + (stream->filePos - stream->cachePos)) % FCACHE_SIZE;
 			uint32 copyLen = stream->bytesInCache - (stream->filePos - stream->cachePos);
 			if (copyLen > len)
@@ -149,26 +209,28 @@
 			if (startPos + copyLen > FCACHE_SIZE)
 				copyLen = FCACHE_SIZE - startPos;
 
-			memcpy(dest, cacheData + startPos, copyLen);
+			memcpy(dest, stream->cacheData + startPos, copyLen);
 
-			filePos += copyLen;
+			stream->filePos += copyLen;
 			dest += copyLen;
 			len -= copyLen;
-		} else {
-#endif
-			ERR_CODE err = GpFileRead(stream->handle, ptr, len, &readcount);
-
-#ifdef USE_CACHE
-			stream->filePos += len;
+		} else { // cache miss or cache empty
+			gp_cacheMiss(stream);
 		}
 	}
+#else
+	ulong readcount = 0;
+	ERR_CODE err = GpFileRead(stream->handle, ptr, len, &readcount);
+	stream->physFilePos += len;
+	stream->filePos += len;
 #endif
 
-	return readcount / size;	//FIXME?
+	return 1; //readcount / size;	//FIXME
 }
 
 size_t gp_fwrite(const void *ptr, size_t size, size_t n, GPFILE *stream) {
 	int len = size * n;
+	uint8 *srcBuf = (uint8 *)ptr;
 
 	if (!stream) {
 		//warning("writing to null file");
@@ -176,31 +238,37 @@
 	}
 
 #ifdef USE_CACHE
-	if (stream->cachePos + len < FCACHE_SIZE) {
-		memcpy(stream->cacheData + stream->cachePos, ptr, len);
-		stream->cachePos += len;
-	} else {
-		if (stream->cachePos) {
-			GpFileWrite(stream->handle, stream->cacheData, stream->cachePos);	// flush cache
-			stream->cachePos = 0;
+	while (len) {
+		uint32 copyLen;
+		if (stream->bytesInCache + len > FCACHE_SIZE)
+			copyLen = FCACHE_SIZE - stream->bytesInCache;
+		else
+			copyLen = len;
+
+		srcBuf += copyLen;
+		len -= copyLen;
+
+		if (stream->bytesInCache == FCACHE_SIZE) {
+			ERR_CODE err = GpFileWrite(stream->handle, stream->cacheData, stream->bytesInCache); // flush cache
+			stream->filePos += stream->bytesInCache;
+			stream->physFilePos += stream->bytesInCache;
+			stream->bytesInCache = 0;
 		}
-
-#endif
-		ERR_CODE err = GpFileWrite(stream->handle, ptr, len);
-		if (!err)
-			return n;
-		else
-			return -err;
-#ifdef USE_CACHE
 	}
+#else
+	ERR_CODE err = GpFileWrite(stream->handle, ptr, len);
+	if (!err)
+		return n;
+	else
+		return -err;
 #endif
-	return 0;
+	return 1;
 }
 
-//FIXME? use standard func
 long gp_ftell(GPFILE *stream) {
 	ulong pos = 0;
-	ERR_CODE err = GpFileSeek(stream->handle, FROM_CURRENT, 0, (long*)&pos);
+	pos = stream->filePos;
+	//ERR_CODE err = GpFileSeek(stream->handle, FROM_CURRENT, 0, (long*)&pos);
 	return pos;
 }
 
@@ -209,7 +277,7 @@
 }
 
 int gp_feof(GPFILE *stream) {
-	return gp_ftell(stream) >= stream->fileSize;
+	return (unsigned long)gp_ftell(stream) >= stream->fileSize;
 }
 
 char gp_fgetc(GPFILE *stream) {

Modified: scummvm/trunk/backends/platform/gp32/gp32std_file.h
===================================================================
--- scummvm/trunk/backends/platform/gp32/gp32std_file.h	2006-09-10 23:57:52 UTC (rev 23869)
+++ scummvm/trunk/backends/platform/gp32/gp32std_file.h	2006-09-13 07:32:54 UTC (rev 23870)
@@ -33,6 +33,7 @@
 	unsigned long mode;
 	unsigned long fileSize;
 	unsigned long filePos;
+	unsigned long physFilePos;
 	unsigned long cachePos;
 	unsigned long cacheBufOffs;
 	unsigned long bytesInCache;

Modified: scummvm/trunk/backends/platform/gp32/gp32std_memory.cpp
===================================================================
--- scummvm/trunk/backends/platform/gp32/gp32std_memory.cpp	2006-09-10 23:57:52 UTC (rev 23869)
+++ scummvm/trunk/backends/platform/gp32/gp32std_memory.cpp	2006-09-13 07:32:54 UTC (rev 23870)
@@ -122,8 +122,10 @@
 			}
 			blk++;
 		}
-		if(i == prevBlock)
-			return NULL;
+		if(i == prevBlock) {
+			prevBlock = 0;
+			return gm_malloc(size);
+		}
 	}
 
 	byte *ptr = userMem + (i * USER_BLOCK_SIZE);
@@ -139,11 +141,13 @@
 
 void MemBlock::deleteBlock(void *dstBlock)
 {
+	// Faster method
 	uint32 np = (uint32) dstBlock - (uint32) userMem;
 
 	if ((np / USER_BLOCK_SIZE) * USER_BLOCK_SIZE != np) {
 		gm_free(dstBlock);
 //		warning("wrong block! (%d / %d)", (np / USER_BLOCK_SIZE) * USER_BLOCK_SIZE, np);
+		return;
 	}
 	int i = np / USER_BLOCK_SIZE;
 	if (i > NUM_BLOCK) {
@@ -201,10 +205,6 @@
 	int allocSize = ALIGNED_SIZE(size) + sizeof(uint32) + sizeof(uint32);
 	if (allocSize <= USER_BLOCK_SIZE) {
 		np = (uint32) MemBlock::addBlock(allocSize);
-		if (!np) {
-//			GPDEBUG("falling back to gm_malloc");
-			np = (uint32) gm_malloc(allocSize);
-		}
 	} else {
 		np = (uint32) gm_malloc(allocSize);
 	}
@@ -276,7 +276,7 @@
 int gUsedMem = 1024 * 1024;
 
 //#define CLEAN_MEMORY_WITH_0xE7
-#define CHECK_USED_MEMORY
+//#define CHECK_USED_MEMORY
 //#define CHECK_NEW_TIME
 //#define CHECK_NEW_SIZE
 


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