[Scummvm-cvs-logs] SF.net SVN: scummvm:[39055] scummvm/trunk/engines/sci

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sun Mar 1 22:48:39 CET 2009


Revision: 39055
          http://scummvm.svn.sourceforge.net/scummvm/?rev=39055&view=rev
Author:   fingolfin
Date:     2009-03-01 21:48:39 +0000 (Sun, 01 Mar 2009)

Log Message:
-----------
SCI: Added kDebugLevelDclInflate; changed decompressors to *not* use fprintf or printf

Modified Paths:
--------------
    scummvm/trunk/engines/sci/sci.cpp
    scummvm/trunk/engines/sci/sci.h
    scummvm/trunk/engines/sci/scicore/decompress0.cpp
    scummvm/trunk/engines/sci/scicore/decompress01.cpp
    scummvm/trunk/engines/sci/scicore/decompress1.cpp
    scummvm/trunk/engines/sci/scicore/decompress11.cpp

Modified: scummvm/trunk/engines/sci/sci.cpp
===================================================================
--- scummvm/trunk/engines/sci/sci.cpp	2009-03-01 21:47:57 UTC (rev 39054)
+++ scummvm/trunk/engines/sci/sci.cpp	2009-03-01 21:48:39 UTC (rev 39055)
@@ -156,6 +156,7 @@
 	Common::addDebugChannel(kDebugLevelTime, "Time", "Time debugging");
 	Common::addDebugChannel(kDebugLevelRoom, "Room", "Room number debugging");
 	Common::addDebugChannel(kDebugLevelAvoidPath, "Pathfinding", "Pathfinding debugging");
+	Common::addDebugChannel(kDebugLevelDclInflate, "DCL", "DCL inflate debugging");
 
 	printf("SciEngine::SciEngine\n");
 }

Modified: scummvm/trunk/engines/sci/sci.h
===================================================================
--- scummvm/trunk/engines/sci/sci.h	2009-03-01 21:47:57 UTC (rev 39054)
+++ scummvm/trunk/engines/sci/sci.h	2009-03-01 21:48:39 UTC (rev 39055)
@@ -52,7 +52,8 @@
 	kDebugLevelFile       = 1 << 13,
 	kDebugLevelTime       = 1 << 14,
 	kDebugLevelRoom       = 1 << 15,
-	kDebugLevelAvoidPath  = 1 << 16
+	kDebugLevelAvoidPath  = 1 << 16,
+	kDebugLevelDclInflate = 1 << 17
 };
 
 struct GameFlags {

Modified: scummvm/trunk/engines/sci/scicore/decompress0.cpp
===================================================================
--- scummvm/trunk/engines/sci/scicore/decompress0.cpp	2009-03-01 21:47:57 UTC (rev 39054)
+++ scummvm/trunk/engines/sci/scicore/decompress0.cpp	2009-03-01 21:48:39 UTC (rev 39055)
@@ -102,7 +102,7 @@
 				if (token > 0xff) {
 					if (token >= tokenctr) {
 #ifdef _SCI_DECOMPRESS_DEBUG
-						fprintf(stderr, "decrypt1: Bad token %x!\n", token);
+						warning("decrypt1: Bad token %x", token);
 #endif
 						// Well this is really bad
 						// May be it should throw something like SCI_ERROR_DECOMPRESSION_INSANE
@@ -111,7 +111,7 @@
 						if (destctr + tokenlastlength > length) {
 #ifdef _SCI_DECOMPRESS_DEBUG
 							// For me this seems a normal situation, It's necessary to handle it
-							printf("decrypt1: Trying to write beyond the end of array(len=%d, destctr=%d, tok_len=%d)!\n",
+							warning("decrypt1: Trying to write beyond the end of array(len=%d, destctr=%d, tok_len=%d)",
 							       length, destctr, tokenlastlength);
 #endif
 							i = 0;
@@ -128,7 +128,7 @@
 					tokenlastlength = 1;
 					if (destctr >= length) {
 #ifdef _SCI_DECOMPRESS_DEBUG
-						printf("decrypt1: Try to write single byte beyond end of array!\n");
+						warning("decrypt1: Try to write single byte beyond end of array");
 #endif
 					} else
 						dest[destctr++] = (byte)token;
@@ -280,12 +280,11 @@
 
 
 #ifdef _SCI_DECOMPRESS_DEBUG
-	fprintf(stderr, "Resource %s.%03hi encrypted with method %hi at %.2f%%"
-	        " ratio\n",
+	debug("Resource %s.%03hi encrypted with method %hi at %.2f%% ratio",
 	        getResourceTypeName(result->type), result->number, compressionMethod,
 	        (result->size == 0) ? -1.0 :
 	        (100.0 * compressedLength / result->size));
-	fprintf(stderr, "  compressedLength = 0x%hx, actualLength=0x%hx\n",
+	debug("  compressedLength = 0x%hx, actualLength=0x%hx",
 	        compressedLength, result->size);
 #endif
 
@@ -325,8 +324,8 @@
 		break;
 
 	default:
-		fprintf(stderr, "Resource %s.%03hi: Compression method %hi not "
-		        "supported!\n", getResourceTypeName(result->type), result->number,
+		warning("Resource %s.%03hi: Compression method %hi not supported",
+		        getResourceTypeName(result->type), result->number,
 		        compressionMethod);
 		free(result->data);
 		result->data = 0; // So that we know that it didn't work

Modified: scummvm/trunk/engines/sci/scicore/decompress01.cpp
===================================================================
--- scummvm/trunk/engines/sci/scicore/decompress01.cpp	2009-03-01 21:47:57 UTC (rev 39054)
+++ scummvm/trunk/engines/sci/scicore/decompress01.cpp	2009-03-01 21:48:39 UTC (rev 39055)
@@ -427,7 +427,7 @@
 	for (l = 0;l < loopheaders;l++) {
 		if (lh_mask & lb) { // The loop is _not_ present
 			if (lh_last == -1) {
-				fprintf(stderr, "Error: While reordering view: Loop not present, but can't re-use last loop!\n");
+				warning("While reordering view: Loop not present, but can't re-use last loop");
 				lh_last = 0;
 			}
 			WRITE_LE_UINT16(lh_ptr, lh_last);
@@ -461,7 +461,7 @@
 	}
 
 	if (celindex < cel_total) {
-		fprintf(stderr, "View decompression generated too few (%d / %d) headers!\n", celindex, cel_total);
+		warning("View decompression generated too few (%d / %d) headers", celindex, cel_total);
 		return NULL;
 	}
 
@@ -539,12 +539,11 @@
 
 
 #ifdef _SCI_DECOMPRESS_DEBUG
-	fprintf(stderr, "Resource %s.%03hi encrypted with method SCI01/%hi at %.2f%%"
-	        " ratio\n",
+	debug("Resource %s.%03hi encrypted with method SCI01/%hi at %.2f%% ratio",
 	        sci_resource_types[result->type], result->number, compressionMethod,
 	        (result->size == 0) ? -1.0 :
 	        (100.0 * compressedLength / result->size));
-	fprintf(stderr, "  compressedLength = 0x%hx, actualLength=0x%hx\n",
+	debug("  compressedLength = 0x%hx, actualLength=0x%hx",
 	        compressedLength, result->size);
 #endif
 
@@ -612,8 +611,8 @@
 		break;
 
 	default:
-		fprintf(stderr, "Resource %s.%03hi: Compression method SCI1/%hi not "
-		        "supported!\n", getResourceTypeName(result->type), result->number,
+		warning("Resource %s.%03hi: Compression method SCI1/%hi not supported",
+		        getResourceTypeName(result->type), result->number,
 		        compressionMethod);
 		free(result->data);
 		result->data = 0; // So that we know that it didn't work

Modified: scummvm/trunk/engines/sci/scicore/decompress1.cpp
===================================================================
--- scummvm/trunk/engines/sci/scicore/decompress1.cpp	2009-03-01 21:47:57 UTC (rev 39054)
+++ scummvm/trunk/engines/sci/scicore/decompress1.cpp	2009-03-01 21:48:39 UTC (rev 39055)
@@ -25,9 +25,11 @@
 
 // Reads data from a resource file and stores the result in memory
 
+#include "common/debug.h"
 #include "common/stream.h"
 #include "common/util.h"
 
+#include "sci/sci.h"
 #include "sci/sci_memory.h"
 #include "sci/scicore/resource.h"
 
@@ -73,7 +75,7 @@
 	int i;
 
 	if (inp->bytepos + morebytes >= inp->length) {
-		fprintf(stderr, "read out-of-bounds with bytepos %d + morebytes %d >= length %d\n",
+		warning("read out-of-bounds with bytepos %d + morebytes %d >= length %d",
 		        inp->bytepos, morebytes, inp->length);
 		return -SCI_ERROR_DECOMPRESSION_OVERFLOW;
 	}
@@ -90,15 +92,13 @@
 	return result;
 }
 
-static int DEBUG_DCL_INFLATE = 0; // FIXME: Make this a define eventually
-
 static inline int getbits(struct bit_read_struct *inp, int bits) {
 	int morebytes = (bits + inp->bitpos - 1) >> 3;
 	int result = 0;
 	int i;
 
 	if (inp->bytepos + morebytes >= inp->length) {
-		fprintf(stderr, "read out-of-bounds with bytepos %d + morebytes %d >= length %d\n",
+		warning("read out-of-bounds with bytepos %d + morebytes %d >= length %d",
 		        inp->bytepos, morebytes, inp->length);
 		return -SCI_ERROR_DECOMPRESSION_OVERFLOW;
 	}
@@ -112,8 +112,7 @@
 	inp->bitpos += bits - (morebytes << 3);
 	inp->bytepos += morebytes;
 
-	if (DEBUG_DCL_INFLATE)
-		fprintf(stderr, "(%d:%04x)", bits, result);
+	debugC(kDebugLevelDclInflate, "(%d:%04x)", bits, result);
 
 	return result;
 }
@@ -124,15 +123,13 @@
 
 	while (!(tree[pos] & HUFFMAN_LEAF)) {
 		CALLC(bit = getbits(inp, 1));
-		if (DEBUG_DCL_INFLATE)
-			fprintf(stderr, "[%d]:%d->", pos, bit);
+		debugC(kDebugLevelDclInflate, "[%d]:%d->", pos, bit);
 		if (bit)
 			pos = tree[pos] & ~(~0 << BRANCH_SHIFT);
 		else
 			pos = tree[pos] >> BRANCH_SHIFT;
 	}
-	if (DEBUG_DCL_INFLATE)
-		fprintf(stderr, "=%02x\n", tree[pos] & 0xffff);
+	debugC(kDebugLevelDclInflate, "=%02x\n", tree[pos] & 0xffff);
 	return tree[pos] & 0xffff;
 }
 
@@ -149,23 +146,20 @@
 
 	if (mode == DCL_ASCII_MODE) {
 		warning("DCL-INFLATE: Decompressing ASCII mode (untested)");
-		//DEBUG_DCL_INFLATE = 1;
 	} else if (mode) {
 		warning("DCL-INFLATE: Error: Encountered mode %02x, expected 00 or 01\n", mode);
 		return 1;
 	}
 
-	if (DEBUG_DCL_INFLATE) {
-		int i;
-
-		for (i = 0; i < reader->length; i++) {
-			fprintf(stderr, "%02x ", reader->data[i]);
+	if (Common::isDebugChannelEnabled(kDebugLevelDclInflate)) {
+		for (int i = 0; i < reader->length; i++) {
+			debugC(kDebugLevelDclInflate, "%02x ", reader->data[i]);
 			if (!((i + 1) & 0x1f))
-				fprintf(stderr, "\n");
+				debugC(kDebugLevelDclInflate, "\n");
 		}
 
 
-		fprintf(stderr, "\n---\n");
+		debugC(kDebugLevelDclInflate, "\n---\n");
 	}
 
 
@@ -188,8 +182,7 @@
 				val_length += length_bonus;
 			}
 
-			if (DEBUG_DCL_INFLATE)
-				fprintf(stderr, " | ");
+			debugC(kDebugLevelDclInflate, " | ");
 
 			CALLC(value = huffman_lookup(reader, distance_tree));
 
@@ -206,16 +199,15 @@
 			}
 			++val_distance;
 
-			if (DEBUG_DCL_INFLATE)
-				fprintf(stderr, "\nCOPY(%d from %d)\n", val_length, val_distance);
+			debugC(kDebugLevelDclInflate, "\nCOPY(%d from %d)\n", val_length, val_distance);
 
 			if (val_length + write_pos > length) {
-				fprintf(stderr, "DCL-INFLATE Error: Write out of bounds while copying %d bytes\n", val_length);
+				warning("DCL-INFLATE Error: Write out of bounds while copying %d bytes", val_length);
 				return -SCI_ERROR_DECOMPRESSION_OVERFLOW;
 			}
 
 			if (write_pos < val_distance) {
-				fprintf(stderr, "DCL-INFLATE Error: Attempt to copy from before beginning of input stream\n");
+				warning("DCL-INFLATE Error: Attempt to copy from before beginning of input stream");
 				return -SCI_ERROR_DECOMPRESSION_INSANE;
 			}
 
@@ -224,11 +216,10 @@
 
 				memcpy(dest + write_pos, dest + write_pos - val_distance, copy_length);
 
-				if (DEBUG_DCL_INFLATE) {
-					int i;
-					for (i = 0; i < copy_length; i++)
-						fprintf(stderr, "\33[32;31m%02x\33[37;37m ", dest[write_pos + i]);
-					fprintf(stderr, "\n");
+				if (Common::isDebugChannelEnabled(kDebugLevelDclInflate)) {
+					for (int i = 0; i < copy_length; i++)
+						debugC(kDebugLevelDclInflate, "\33[32;31m%02x\33[37;37m ", dest[write_pos + i]);
+					debugC(kDebugLevelDclInflate, "\n");
 				}
 
 				val_length -= copy_length;
@@ -245,8 +236,7 @@
 
 			dest[write_pos++] = value;
 
-			if (DEBUG_DCL_INFLATE)
-				fprintf(stderr, "\33[32;31m%02x \33[37;37m", value);
+			debugC(kDebugLevelDclInflate, "\33[32;31m%02x \33[37;37m", value);
 		}
 	}
 
@@ -328,14 +318,13 @@
 
 
 #ifdef _SCI_DECOMPRESS_DEBUG
-	fprintf(stderr, "Resource %i.%s encrypted with method SCI1%c/%hi at %.2f%%"
-	        " ratio\n",
+	debug("Resource %i.%s encrypted with method SCI1%c/%hi at %.2f%% ratio",
 	        result->number, sci_resource_type_suffixes[result->type],
 	        early ? 'e' : 'l',
 	        compressionMethod,
 	        (result->size == 0) ? -1.0 :
 	        (100.0 * compressedLength / result->size));
-	fprintf(stderr, "  compressedLength = 0x%hx, actualLength=0x%hx\n",
+	debug("  compressedLength = 0x%hx, actualLength=0x%hx",
 	        compressedLength, result->size);
 #endif
 
@@ -402,8 +391,8 @@
 		break;
 
 	default:
-		fprintf(stderr, "Resource %s.%03hi: Compression method SCI1/%hi not "
-		        "supported!\n", getResourceTypeName(result->type), result->number,
+		warning("Resource %s.%03hi: Compression method SCI1/%hi not supported",
+		        getResourceTypeName(result->type), result->number,
 		        compressionMethod);
 		free(result->data);
 		result->data = 0; // So that we know that it didn't work

Modified: scummvm/trunk/engines/sci/scicore/decompress11.cpp
===================================================================
--- scummvm/trunk/engines/sci/scicore/decompress11.cpp	2009-03-01 21:47:57 UTC (rev 39054)
+++ scummvm/trunk/engines/sci/scicore/decompress11.cpp	2009-03-01 21:48:39 UTC (rev 39055)
@@ -32,8 +32,6 @@
 
 namespace Sci {
 
-#define DDEBUG if (0) printf
-
 void decryptinit3();
 int decrypt3(uint8* dest, uint8* src, int length, int complength);
 int decrypt4(uint8* dest, uint8* src, int length, int complength);
@@ -43,8 +41,6 @@
 	uint16 compressionMethod;
 	uint8 *buffer;
 
-	DDEBUG("d1");
-
 	result->id = stream.readByte();
 	if (stream.err())
 		return SCI_ERROR_IO_ERROR;
@@ -90,18 +86,15 @@
 	}
 
 #ifdef _SCI_DECOMPRESS_DEBUG
-	fprintf(stderr, "Resource %i.%s encrypted with method SCI1.1/%hi at %.2f%%"
-	        " ratio\n",
+	debug("Resource %i.%s encrypted with method SCI1.1/%hi at %.2f%% ratio",
 	        result->number, getResourceTypeSuffix(result->type),
 	        compressionMethod,
 	        (result->size == 0) ? -1.0 :
 	        (100.0 * compressedLength / result->size));
-	fprintf(stderr, "  compressedLength = 0x%hx, actualLength=0x%hx\n",
+	debug("  compressedLength = 0x%hx, actualLength=0x%hx",
 	        compressedLength, result->size);
 #endif
 
-	DDEBUG("/%d[%d]", compressionMethod, result->size);
-
 	switch (compressionMethod) {
 	case 0: // no compression
 		if (result->size != compressedLength) {
@@ -130,7 +123,7 @@
 
 	case 3:
 	case 4: // NYI
-		fprintf(stderr, "Resource %d.%s: Warning: compression type #%d not yet implemented\n",
+		warning("Resource %d.%s: Warning: compression type #%d not yet implemented",
 		        result->number, getResourceTypeSuffix(result->type), compressionMethod);
 		free(result->data);
 		result->data = NULL;
@@ -138,8 +131,8 @@
 		break;
 
 	default:
-		fprintf(stderr, "Resource %d.%s: Compression method SCI1/%hi not "
-		        "supported!\n", result->number, getResourceTypeSuffix(result->type),
+		warning("Resource %d.%s: Compression method SCI1/%hi not  supported",
+		        result->number, getResourceTypeSuffix(result->type),
 		        compressionMethod);
 		free(result->data);
 		result->data = NULL; // So that we know that it didn't work


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