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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sun Feb 7 13:15:59 CET 2010


Revision: 47961
          http://scummvm.svn.sourceforge.net/scummvm/?rev=47961&view=rev
Author:   fingolfin
Date:     2010-02-07 12:15:59 +0000 (Sun, 07 Feb 2010)

Log Message:
-----------
SCI: Add GameFeatures::getDetectionAddr auxillary method

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/features.cpp
    scummvm/trunk/engines/sci/engine/features.h

Modified: scummvm/trunk/engines/sci/engine/features.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/features.cpp	2010-02-07 12:15:35 UTC (rev 47960)
+++ scummvm/trunk/engines/sci/engine/features.cpp	2010-02-07 12:15:59 UTC (rev 47961)
@@ -43,36 +43,52 @@
 	_usesCdTrack = Common::File::exists("cdaudio.map");
 }
 
+reg_t GameFeatures::getDetectionAddr(const Common::String &objName, Selector slc, int methodNum) {
+	// Get address of target object
+	reg_t objAddr = _segMan->findObjectByName(objName);
+	reg_t addr;
+
+	if (objAddr.isNull()) {
+		warning("autoDetectFeature: %s object couldn't be found", objName.c_str());
+		return NULL_REG;
+	}
+
+	if (methodNum == -1) {
+		if (lookup_selector(_segMan, objAddr, slc, NULL, &addr) != kSelectorMethod) {
+			warning("autoDetectFeature: target selector is not a method of object %s", objName.c_str());
+			return NULL_REG;
+		}
+	} else {
+		addr = _segMan->getObject(objAddr)->getFunction(methodNum);
+	}
+
+	return addr;
+}
+
 bool GameFeatures::autoDetectFeature(FeatureDetection featureDetection, int methodNum) {
 	Common::String objName;
 	Selector slc = 0;
-	reg_t objAddr;
 
 	// Get address of target script
 	switch (featureDetection) {
 	case kDetectGfxFunctions:
 		objName = "Rm";
-		objAddr = _segMan->findObjectByName(objName);
 		slc = _kernel->_selectorCache.overlay;
 		break;
 	case kDetectMoveCountType:
 		objName = "Motion";
-		objAddr = _segMan->findObjectByName(objName);
 		slc = _kernel->_selectorCache.doit;
 		break;
 	case kDetectSoundType:
 		objName = "Sound";
-		objAddr = _segMan->findObjectByName(objName);
 		slc = _kernel->_selectorCache.play;
 		break;
 	case kDetectLofsType:
 		objName = "Game";
-		objAddr = _segMan->findObjectByName(objName);
 		break;
 #ifdef ENABLE_SCI32
 	case kDetectSci21KernelTable:
 		objName = "Sound";
-		objAddr = _segMan->findObjectByName(objName);
 		slc = _kernel->_selectorCache.play;
 		break;
 #endif
@@ -81,21 +97,9 @@
 		return false;
 	}
 
-	reg_t addr;
-	if (objAddr.isNull()) {
-		warning("autoDetectFeature: %s object couldn't be found", objName.c_str());
-		return false;
-	}
+	// Look up the address for the desired selector resp. method.
+	reg_t addr = getDetectionAddr(objName, slc, methodNum);
 
-	if (methodNum == -1) {
-		if (lookup_selector(_segMan, objAddr, slc, NULL, &addr) != kSelectorMethod) {
-			warning("autoDetectFeature: target selector is not a method of object %s", objName.c_str());
-			return false;
-		}
-	} else {
-		addr = _segMan->getObject(objAddr)->getFunction(methodNum);
-	}
-
 	int16 opparams[4];
 	byte opsize;
 	byte opcode;
@@ -104,10 +108,16 @@
 	uint16 intParam = 0xFFFF;	// Only used for kDetectSoundType
 	bool foundTarget = false;
 
-	do {
+	assert(script);
+
+	while (true) {
 		offset += readPMachineInstruction(script->_buf + offset, opsize, opparams);
 		opcode = opsize >> 1;
 
+		// Check for end of script
+		if (opcode == op_ret || offset >= script->_bufSize)
+			break;
+
 		switch (featureDetection) {
 		case kDetectGfxFunctions:
 			if (opcode == op_callk) {
@@ -147,10 +157,6 @@
 			if (opcode == op_pushi) {
 				// Load the pushi parameter
 				intParam = opparams[0];
-
-				// Sanity check
-				if (offset >= script->_bufSize)
-					break;
 			}
 
 
@@ -192,10 +198,6 @@
 				// Load lofs operand
 				uint16 lofs = opparams[0];
 
-				// Sanity check
-				if (offset >= script->_bufSize)
-					break;
-
 				// Check for going out of bounds when interpreting as abs/rel
 				if (lofs >= script->_bufSize)
 					_lofsType = SCI_VERSION_0_EARLY;
@@ -234,7 +236,7 @@
 		default:
 			break;
 		}
-	} while (opcode != op_ret && offset < script->_bufSize);
+	}
 
 	return false;	// not found
 }

Modified: scummvm/trunk/engines/sci/engine/features.h
===================================================================
--- scummvm/trunk/engines/sci/engine/features.h	2010-02-07 12:15:35 UTC (rev 47960)
+++ scummvm/trunk/engines/sci/engine/features.h	2010-02-07 12:15:59 UTC (rev 47961)
@@ -97,6 +97,8 @@
 	bool usesCdTrack() { return _usesCdTrack; }
 
 private:
+	reg_t getDetectionAddr(const Common::String &objName, Selector slc, int methodNum = -1);
+
 	bool autoDetectFeature(FeatureDetection featureDetection, int methodNum = -1);
 
 	SciVersion _doSoundType, _setCursorType, _lofsType, _gfxFunctionsType;


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