[Scummvm-cvs-logs] SF.net SVN: scummvm: [24395] scummvm/trunk/engines/scumm

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Fri Oct 20 21:44:44 CEST 2006


Revision: 24395
          http://svn.sourceforge.net/scummvm/?rev=24395&view=rev
Author:   fingolfin
Date:     2006-10-20 12:44:27 -0700 (Fri, 20 Oct 2006)

Log Message:
-----------
SCUMM: ArrayHeader related cleanup

Modified Paths:
--------------
    scummvm/trunk/engines/scumm/he/intern_he.h
    scummvm/trunk/engines/scumm/he/script_v100he.cpp
    scummvm/trunk/engines/scumm/he/script_v60he.cpp
    scummvm/trunk/engines/scumm/he/script_v70he.cpp
    scummvm/trunk/engines/scumm/he/script_v72he.cpp
    scummvm/trunk/engines/scumm/he/script_v80he.cpp
    scummvm/trunk/engines/scumm/intern.h
    scummvm/trunk/engines/scumm/resource.cpp
    scummvm/trunk/engines/scumm/script_v6.cpp
    scummvm/trunk/engines/scumm/script_v8.cpp
    scummvm/trunk/engines/scumm/scumm.cpp

Modified: scummvm/trunk/engines/scumm/he/intern_he.h
===================================================================
--- scummvm/trunk/engines/scumm/he/intern_he.h	2006-10-20 02:10:51 UTC (rev 24394)
+++ scummvm/trunk/engines/scumm/he/intern_he.h	2006-10-20 19:44:27 UTC (rev 24395)
@@ -276,7 +276,7 @@
 
 	virtual void redrawBGAreas();
 
-	ArrayHeader *defineArray(int array, int type, int dim2start, int dim2end, int dim1start, int dim1end);
+	byte *defineArray(int array, int type, int dim2start, int dim2end, int dim1start, int dim1end);
 	virtual int readArray(int array, int idx2, int idx1);
 	virtual void writeArray(int array, int idx2, int idx1, int value);
 	void redimArray(int arrayId, int newDim2start, int newDim2end,

Modified: scummvm/trunk/engines/scumm/he/script_v100he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/script_v100he.cpp	2006-10-20 02:10:51 UTC (rev 24394)
+++ scummvm/trunk/engines/scumm/he/script_v100he.cpp	2006-10-20 19:44:27 UTC (rev 24395)
@@ -580,7 +580,7 @@
 }
 
 void ScummEngine_v100he::o100_arrayOps() {
-	ArrayHeader *ah;
+	byte *data;
 	byte string[1024];
 	int dim1end, dim1start, dim2end, dim2start;
 	int id, len, b, c, list[128];
@@ -595,14 +595,14 @@
 	case 35:
 		decodeScriptString(string);
 		len = resStrLen(string);
-		ah = defineArray(array, kStringArray, 0, 0, 0, len);
-		memcpy(ah->data, string, len);
+		data = defineArray(array, kStringArray, 0, 0, 0, len);
+		memcpy(data, string, len);
 		break;
 	case 77:			// SO_ASSIGN_STRING
 		copyScriptString(string, sizeof(string));
 		len = resStrLen(string);
-		ah = defineArray(array, kStringArray, 0, 0, 0, len);
-		memcpy(ah->data, string, len);
+		data = defineArray(array, kStringArray, 0, 0, 0, len);
+		memcpy(data, string, len);
 		break;
 
 	case 128:		// SO_ASSIGN_2DIM_LIST

Modified: scummvm/trunk/engines/scumm/he/script_v60he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/script_v60he.cpp	2006-10-20 02:10:51 UTC (rev 24394)
+++ scummvm/trunk/engines/scumm/he/script_v60he.cpp	2006-10-20 19:44:27 UTC (rev 24395)
@@ -856,7 +856,7 @@
 
 void ScummEngine_v60he::o60_kernelGetFunctions() {
 	int args[29];
-	ArrayHeader *ah;
+	byte *data;
 	getStackList(args, ARRAYSIZE(args));
 
 	switch (args[0]) {
@@ -864,8 +864,8 @@
 		// Used to store images when decorating cake in
 		// Fatty Bear's Birthday Surprise
 		writeVar(0, 0);
-		ah = defineArray(0, kByteArray, 0, virtScreenSave(0, args[1], args[2], args[3], args[4]));
-		virtScreenSave(ah->data, args[1], args[2], args[3], args[4]);
+		data = defineArray(0, kByteArray, 0, virtScreenSave(0, args[1], args[2], args[3], args[4]));
+		virtScreenSave(data, args[1], args[2], args[3], args[4]);
 		push(readVar(0));
 		break;
 	default:
@@ -1078,8 +1078,8 @@
 		size = _hInFileTable[slot]->size() - _hInFileTable[slot]->pos();
 
 	writeVar(0, 0);
-	ArrayHeader *ah = defineArray(0, kByteArray, 0, size);
-	_hInFileTable[slot]->read(ah->data, size);
+	byte *data = defineArray(0, kByteArray, 0, size);
+	_hInFileTable[slot]->read(data, size);
 
 	return readVar(0);
 }

Modified: scummvm/trunk/engines/scumm/he/script_v70he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/script_v70he.cpp	2006-10-20 02:10:51 UTC (rev 24394)
+++ scummvm/trunk/engines/scumm/he/script_v70he.cpp	2006-10-20 19:44:27 UTC (rev 24395)
@@ -927,7 +927,7 @@
 
 void ScummEngine_v70he::o70_readINI() {
 	byte option[256];
-	ArrayHeader *ah;
+	byte *data;
 	const char *entry;
 	int len, type;
 
@@ -951,8 +951,8 @@
 
 		writeVar(0, 0);
 		len = resStrLen((const byte *)entry);
-		ah = defineArray(0, kStringArray, 0, len);
-		memcpy(ah->data, entry, len);
+		data = defineArray(0, kStringArray, 0, len);
+		memcpy(data, entry, len);
 
 		push(readVar(0));
 		break;

Modified: scummvm/trunk/engines/scumm/he/script_v72he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/script_v72he.cpp	2006-10-20 02:10:51 UTC (rev 24394)
+++ scummvm/trunk/engines/scumm/he/script_v72he.cpp	2006-10-20 19:44:27 UTC (rev 24395)
@@ -381,7 +381,7 @@
 
 static const int arrayDataSizes[] = { 0, 1, 4, 8, 8, 16, 32 };
 
-ScummEngine_v72he::ArrayHeader *ScummEngine_v72he::defineArray(int array, int type, int dim2start, int dim2end,
+byte *ScummEngine_v72he::defineArray(int array, int type, int dim2start, int dim2end,
 											int dim1start, int dim1end) {
 	int id;
 	int size;
@@ -427,7 +427,7 @@
 	ah->dim2start = TO_LE_32(dim2start);
 	ah->dim2end = TO_LE_32(dim2end);
 
-	return ah;
+	return ah->data;
 }
 
 int ScummEngine_v72he::readArray(int array, int idx2, int idx1) {
@@ -1395,7 +1395,7 @@
 }
 
 void ScummEngine_v72he::o72_arrayOps() {
-	ArrayHeader *ah;
+	byte *data;
 	byte string[1024];
 	int dim1end, dim1start, dim2end, dim2start;
 	int id, len, b, c, list[128];
@@ -1410,8 +1410,8 @@
 	case 7:			// SO_ASSIGN_STRING
 		copyScriptString(string, sizeof(string));
 		len = resStrLen(string);
-		ah = defineArray(array, kStringArray, 0, 0, 0, len);
-		memcpy(ah->data, string, len);
+		data = defineArray(array, kStringArray, 0, 0, 0, len);
+		memcpy(data, string, len);
 		break;
 
 	case 126:
@@ -1489,8 +1489,8 @@
 	case 194:
 		decodeScriptString(string);
 		len = resStrLen(string);
-		ah = defineArray(array, kStringArray, 0, 0, 0, len);
-		memcpy(ah->data, string, len);
+		data = defineArray(array, kStringArray, 0, 0, 0, len);
+		memcpy(data, string, len);
 		break;
 	case 208:		// SO_ASSIGN_INT_LIST
 		b = pop();
@@ -1661,14 +1661,14 @@
 
 void ScummEngine_v72he::o72_kernelGetFunctions() {
 	int args[29];
-	ArrayHeader *ah;
+	byte *data;
 	getStackList(args, ARRAYSIZE(args));
 
 	switch (args[0]) {
 	case 1:
 		writeVar(0, 0);
-		ah = defineArray(0, kByteArray, 0, 0, 0, virtScreenSave(0, args[1], args[2], args[3], args[4]));
-		virtScreenSave(ah->data, args[1], args[2], args[3], args[4]);
+		data = defineArray(0, kByteArray, 0, 0, 0, virtScreenSave(0, args[1], args[2], args[3], args[4]));
+		virtScreenSave(data, args[1], args[2], args[3], args[4]);
 		push(readVar(0));
 		break;
 	default:
@@ -1772,8 +1772,8 @@
 		size = _hInFileTable[slot]->size() - _hInFileTable[slot]->pos();
 
 	writeVar(0, 0);
-	ArrayHeader *ah = defineArray(0, kByteArray, 0, 0, 0, size);
-	_hInFileTable[slot]->read(ah->data, size + 1);
+	byte *data = defineArray(0, kByteArray, 0, 0, 0, size);
+	_hInFileTable[slot]->read(data, size + 1);
 
 	return readVar(0);
 }
@@ -2107,7 +2107,7 @@
 
 void ScummEngine_v72he::o72_readINI() {
 	byte option[128];
-	ArrayHeader *ah;
+	byte *data;
 	const char *entry;
 	int len;
 
@@ -2131,8 +2131,8 @@
 
 		writeVar(0, 0);
 		len = resStrLen((const byte *)entry);
-		ah = defineArray(0, kStringArray, 0, 0, 0, len);
-		memcpy(ah->data, entry, len);
+		data = defineArray(0, kStringArray, 0, 0, 0, len);
+		memcpy(data, entry, len);
 
 		push(readVar(0));
 		break;

Modified: scummvm/trunk/engines/scumm/he/script_v80he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/script_v80he.cpp	2006-10-20 02:10:51 UTC (rev 24394)
+++ scummvm/trunk/engines/scumm/he/script_v80he.cpp	2006-10-20 19:44:27 UTC (rev 24395)
@@ -447,7 +447,7 @@
 
 void ScummEngine_v80he::o80_readConfigFile() {
 	byte option[128], section[128], filename[256];
-	ArrayHeader *ah;
+	byte *data;
 	Common::String entry;
 	int len, r;
 
@@ -477,8 +477,8 @@
 
 		writeVar(0, 0);
 		len = resStrLen((const byte *)entry.c_str());
-		ah = defineArray(0, kStringArray, 0, 0, 0, len);
-		memcpy(ah->data, entry.c_str(), len);
+		data = defineArray(0, kStringArray, 0, 0, 0, len);
+		memcpy(data, entry.c_str(), len);
 		push(readVar(0));
 		break;
 	default:

Modified: scummvm/trunk/engines/scumm/intern.h
===================================================================
--- scummvm/trunk/engines/scumm/intern.h	2006-10-20 02:10:51 UTC (rev 24394)
+++ scummvm/trunk/engines/scumm/intern.h	2006-10-20 19:44:27 UTC (rev 24395)
@@ -630,7 +630,7 @@
 	int popRoomAndObj(int *room);
 
 	ArrayHeader *getArray(int array);
-	ArrayHeader *defineArray(int array, int type, int dim2, int dim1);
+	byte *defineArray(int array, int type, int dim2, int dim1);
 	int findFreeArrayId();
 	void nukeArray(int array);
 	virtual int readArray(int array, int index, int base);

Modified: scummvm/trunk/engines/scumm/resource.cpp
===================================================================
--- scummvm/trunk/engines/scumm/resource.cpp	2006-10-20 02:10:51 UTC (rev 24394)
+++ scummvm/trunk/engines/scumm/resource.cpp	2006-10-20 19:44:27 UTC (rev 24395)
@@ -764,7 +764,8 @@
 	byte *addr = getResourceAddress(rtString, i);
 	if (addr == NULL)
 		return NULL;
-	return ((ScummEngine_v6::ArrayHeader *)addr)->data;
+	// Skip over the ArrayHeader
+	return addr + 6;
 }
 
 byte *ScummEngine::getStringAddressVar(int i) {

Modified: scummvm/trunk/engines/scumm/script_v6.cpp
===================================================================
--- scummvm/trunk/engines/scumm/script_v6.cpp	2006-10-20 02:10:51 UTC (rev 24394)
+++ scummvm/trunk/engines/scumm/script_v6.cpp	2006-10-20 19:44:27 UTC (rev 24395)
@@ -397,7 +397,7 @@
 	return obj;
 }
 
-ScummEngine_v6::ArrayHeader *ScummEngine_v6::defineArray(int array, int type, int dim2, int dim1) {
+byte *ScummEngine_v6::defineArray(int array, int type, int dim2, int dim1) {
 	int id;
 	int size;
 	ArrayHeader *ah;
@@ -413,7 +413,7 @@
 		// integer arrays. There seems to be no reason for this, and it wastes
 		// space. However, we can't just remove this either, as that would
 		// break savegame compatibility. So do not touch this unless you are
-		// also adding code which updated old savegames, too. And of course
+		// also adding code which updates old savegames, too. And of course
 		// readArray() and writeArray() would have to be updated, too...
 		if (type != kStringArray)
 			type = kIntArray;
@@ -454,7 +454,7 @@
 	ah->dim1 = TO_LE_16(dim1 + 1);
 	ah->dim2 = TO_LE_16(dim2 + 1);
 
-	return ah;
+	return ah->data;
 }
 
 void ScummEngine_v6::nukeArray(int a) {
@@ -492,10 +492,11 @@
 	if (!ah)
 		return 0;
 
-	// Workaround for a long standing bug where we save array headers in native
-	// endianness, instead of a fixed endianness. We try to detect savegames
-	// which were created on a big endian system and convert them to little
-	// endian.
+	// Workaround for a long standing bug where we saved array headers in native
+	// endianness, instead of a fixed endianness. We now always store the
+	// dimensions in little endian byte order. But to stay compatible with older
+	// savegames, we try to detect savegames which were created on a big endian
+	// system and convert them to the proper little endian format on the fly.
 	if ((FROM_LE_16(ah->dim1) & 0xF000) || (FROM_LE_16(ah->dim2) & 0xF000) || (FROM_LE_16(ah->type) & 0xFF00)) {
 		SWAP16(ah->dim1);
 		SWAP16(ah->dim2);
@@ -518,6 +519,8 @@
 	// [03BD] (5D)           if ((localvar13 != -1) && (localvar14 != -1)) {
 	// [03CF] (B6)             printDebug.begin()
 	// ...
+	// So it checks for invalid array indices only *after* using them to access
+	// the array. Ouch.
 	if (_game.id == GID_FT && array == 447 && _currentRoom == 95 && vm.slot[_currentScript].number == 2010 && idx == -1 && base == -1) {
 		return 0;
 	}
@@ -2081,15 +2084,15 @@
 	byte subOp = fetchScriptByte();
 	int array = fetchScriptWord();
 	int b, c, d, len;
-	ArrayHeader *ah;
+	byte *data;
 	int list[128];
 
 	switch (subOp) {
 	case 205:		// SO_ASSIGN_STRING
 		b = pop();
 		len = resStrLen(_scriptPointer);
-		ah = defineArray(array, kStringArray, 0, len + 1);
-		copyScriptString(ah->data + b);
+		data = defineArray(array, kStringArray, 0, len + 1);
+		copyScriptString(data + b);
 		break;
 	case 208:		// SO_ASSIGN_INT_LIST
 		b = pop();
@@ -2961,7 +2964,7 @@
 
 	num = readArray(value, 0, 0);
 
-	ArrayHeader *ah = (ArrayHeader *)getResourceAddress(rtString, readVar(value));
+	ArrayHeader *ah = getArray(value);
 	dim1 = FROM_LE_16(ah->dim1) - 1;
 
 	if (dim1 < num) {

Modified: scummvm/trunk/engines/scumm/script_v8.cpp
===================================================================
--- scummvm/trunk/engines/scumm/script_v8.cpp	2006-10-20 02:10:51 UTC (rev 24394)
+++ scummvm/trunk/engines/scumm/script_v8.cpp	2006-10-20 19:44:27 UTC (rev 24395)
@@ -633,15 +633,15 @@
 	byte subOp = fetchScriptByte();
 	int array = fetchScriptWord();
 	int b, c, d, len;
-	ArrayHeader *ah;
+	byte *data;
 	int list[128];
 
 	switch (subOp) {
 	case 0x14:		// SO_ASSIGN_STRING
 		b = pop();
 		len = resStrLen(_scriptPointer);
-		ah = defineArray(array, kStringArray, 0, len + 1);
-		copyScriptString(ah->data + b);
+		data = defineArray(array, kStringArray, 0, len + 1);
+		copyScriptString(data + b);
 		break;
 	case 0x15:		// SO_ASSIGN_SCUMMVAR_LIST
 		b = pop();
@@ -1273,9 +1273,9 @@
 		{
 		int idx = args[1];
 		int value = args[2];
-		ArrayHeader *ah = (ArrayHeader *)getResourceAddress(rtString, idx);
+		const char *str = (const char *)getStringAddress(idx);
 
-		debugC(DEBUG_GENERAL,"o8_kernelSetFunctions: writeRegistryValue(%s, %d)", (char *)ah->data, value);
+		debugC(DEBUG_GENERAL,"o8_kernelSetFunctions: writeRegistryValue(%s, %d)", str, value);
 		}
 		break;
 	case 33:	// paletteSetIntensity
@@ -1371,22 +1371,22 @@
 	case 0xE0:		// readRegistryValue
 		{
 		int idx = args[1];
-		ArrayHeader *ah = (ArrayHeader *)getResourceAddress(rtString, idx);
-		if (!strcmp((char *)ah->data, "SFX Volume"))
+		const char *str = (const char *)getStringAddress(idx);
+		if (!strcmp(str, "SFX Volume"))
 			push(ConfMan.getInt("sfx_volume") / 2);
-		else if (!strcmp((char *)ah->data, "Voice Volume"))
+		else if (!strcmp(str, "Voice Volume"))
 			push(ConfMan.getInt("speech_volume") / 2);
-		else if (!strcmp((char *)ah->data, "Music Volume"))
+		else if (!strcmp(str, "Music Volume"))
 			push(ConfMan.getInt("music_volume") / 2);
-		else if (!strcmp((char *)ah->data, "Text Status"))
+		else if (!strcmp(str, "Text Status"))
 			push(ConfMan.getBool("subtitles"));
-		else if (!strcmp((char *)ah->data, "Object Names"))
+		else if (!strcmp(str, "Object Names"))
 			push(ConfMan.getBool("object_labels"));
-		else if (!strcmp((char *)ah->data, "Saveload Page"))
+		else if (!strcmp(str, "Saveload Page"))
 			push(14);
 		else 		// Use defaults
 			push(-1);
-		debugC(DEBUG_GENERAL,"o8_kernelGetFunctions: readRegistryValue(%s)", (char *)ah->data);
+		debugC(DEBUG_GENERAL,"o8_kernelGetFunctions: readRegistryValue(%s)", str);
 		}
 		break;
 	case 0xE1:		// imGetMusicPosition

Modified: scummvm/trunk/engines/scumm/scumm.cpp
===================================================================
--- scummvm/trunk/engines/scumm/scumm.cpp	2006-10-20 02:10:51 UTC (rev 24394)
+++ scummvm/trunk/engines/scumm/scumm.cpp	2006-10-20 19:44:27 UTC (rev 24395)
@@ -1405,8 +1405,8 @@
 
 	// Array 129 is set to base name
 	int len = strlen(_filenamePattern.pattern);
-	ArrayHeader *ah = defineArray(129, kStringArray, 0, 0, 0, len);
-	memcpy(ah->data, _filenamePattern.pattern, len);
+	byte *data = defineArray(129, kStringArray, 0, 0, 0, len);
+	memcpy(data, _filenamePattern.pattern, len);
 }
 #endif
 


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