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

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Tue Dec 7 01:47:07 CET 2010


Revision: 54805
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54805&view=rev
Author:   thebluegr
Date:     2010-12-07 00:47:05 +0000 (Tue, 07 Dec 2010)

Log Message:
-----------
SCI: Removed the system strings code and replaced it with a much more simplified version, thus greatly simplifying handling of system strings

Modified Paths:
--------------
    scummvm/trunk/engines/sci/console.cpp
    scummvm/trunk/engines/sci/engine/kernel.cpp
    scummvm/trunk/engines/sci/engine/kfile.cpp
    scummvm/trunk/engines/sci/engine/klists.cpp
    scummvm/trunk/engines/sci/engine/kparse.cpp
    scummvm/trunk/engines/sci/engine/kstring.cpp
    scummvm/trunk/engines/sci/engine/savegame.cpp
    scummvm/trunk/engines/sci/engine/seg_manager.cpp
    scummvm/trunk/engines/sci/engine/seg_manager.h
    scummvm/trunk/engines/sci/engine/segment.cpp
    scummvm/trunk/engines/sci/engine/segment.h
    scummvm/trunk/engines/sci/parser/vocabulary.cpp
    scummvm/trunk/engines/sci/parser/vocabulary.h
    scummvm/trunk/engines/sci/sound/music.cpp

Modified: scummvm/trunk/engines/sci/console.cpp
===================================================================
--- scummvm/trunk/engines/sci/console.cpp	2010-12-06 23:15:25 UTC (rev 54804)
+++ scummvm/trunk/engines/sci/console.cpp	2010-12-07 00:47:05 UTC (rev 54805)
@@ -1616,10 +1616,6 @@
 				DebugPrintf("D  data stack (%d)", (*(DataStack *)mobj)._capacity);
 				break;
 
-			case SEG_TYPE_SYS_STRINGS:
-				DebugPrintf("Y  system string table");
-				break;
-
 			case SEG_TYPE_LISTS:
 				DebugPrintf("L  lists (%d)", (*(ListTable *)mobj).entries_used);
 				break;
@@ -1714,18 +1710,6 @@
 	}
 	break;
 
-	case SEG_TYPE_SYS_STRINGS: {
-		DebugPrintf("system string table - viewing currently disabled\n");
-#if 0
-		SystemStrings *strings = &(mobj->data.sys_strings);
-
-		for (int i = 0; i < SYS_STRINGS_MAX; i++)
-			if (strings->strings[i].name)
-				DebugPrintf("  %s[%d]=\"%s\"\n", strings->strings[i].name, strings->strings[i].max_size, strings->strings[i].value);
-#endif
-	}
-	break;
-
 	case SEG_TYPE_CLONES: {
 		CloneTable *ct = (CloneTable *)mobj;
 

Modified: scummvm/trunk/engines/sci/engine/kernel.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kernel.cpp	2010-12-06 23:15:25 UTC (rev 54804)
+++ scummvm/trunk/engines/sci/engine/kernel.cpp	2010-12-07 00:47:05 UTC (rev 54805)
@@ -384,7 +384,6 @@
 		break;
 	case SEG_TYPE_LOCALS:
 	case SEG_TYPE_STACK:
-	case SEG_TYPE_SYS_STRINGS:
 	case SEG_TYPE_DYNMEM:
 	case SEG_TYPE_HUNK:
 #ifdef ENABLE_SCI32

Modified: scummvm/trunk/engines/sci/engine/kfile.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kfile.cpp	2010-12-06 23:15:25 UTC (rev 54804)
+++ scummvm/trunk/engines/sci/engine/kfile.cpp	2010-12-07 00:47:05 UTC (rev 54805)
@@ -370,8 +370,7 @@
 	if (argc > 0)
 		warning("kGetSaveDir called with %d parameter(s): %04x:%04x", argc, PRINT_REG(argv[0]));
 #endif
-
-	return make_reg(s->_segMan->getSysStringsSegment(), SYS_STRING_SAVEDIR);
+		return s->_segMan->getSaveDirPtr();
 }
 
 reg_t kCheckFreeSpace(EngineState *s, int argc, reg_t *argv) {

Modified: scummvm/trunk/engines/sci/engine/klists.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/klists.cpp	2010-12-06 23:15:25 UTC (rev 54804)
+++ scummvm/trunk/engines/sci/engine/klists.cpp	2010-12-07 00:47:05 UTC (rev 54805)
@@ -635,10 +635,18 @@
 			return kString(s, argc, argv);
 	} else {
 		if (s->_segMan->getSegmentType(argv[1].segment) == SEG_TYPE_STRING ||
-			s->_segMan->getSegmentType(argv[1].segment) == SEG_TYPE_SYS_STRINGS ||
 			s->_segMan->getSegmentType(argv[1].segment) == SEG_TYPE_SCRIPT) {
 			return kString(s, argc, argv);
 		}
+
+#if 0
+		if (op == 6) {
+			if (s->_segMan->getSegmentType(argv[3].segment) == SEG_TYPE_STRING ||
+				s->_segMan->getSegmentType(argv[3].segment) == SEG_TYPE_SCRIPT) {
+				return kString(s, argc, argv);
+			}
+		}
+#endif
 	}
 
 	switch (op) {
@@ -694,11 +702,16 @@
 		return argv[1];
 	}
 	case 6: { // Cpy
+#if 0
 		if (argv[1].isNull() || argv[3].isNull()) {
 			warning("kArray(Cpy): Request to copy from or to a null pointer");
 			return NULL_REG;
 		}
+#endif
+
+		reg_t arrayHandle = argv[1];
 		SciArray<reg_t> *array1 = s->_segMan->lookupArray(argv[1]);
+		//SciArray<reg_t> *array1 = !argv[1].isNull() ? s->_segMan->lookupArray(argv[1]) : s->_segMan->allocateArray(&arrayHandle);
 		SciArray<reg_t> *array2 = s->_segMan->lookupArray(argv[3]);
 		uint32 index1 = argv[2].toUint16();
 		uint32 index2 = argv[4].toUint16();
@@ -716,7 +729,7 @@
 		for (uint16 i = 0; i < count; i++)
 			array1->setValue(i + index1, array2->getValue(i + index2));
 
-		return argv[1];
+		return arrayHandle;
 	}
 	case 7: // Cmp
 		// Not implemented in SSCI

Modified: scummvm/trunk/engines/sci/engine/kparse.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kparse.cpp	2010-12-06 23:15:25 UTC (rev 54804)
+++ scummvm/trunk/engines/sci/engine/kparse.cpp	2010-12-07 00:47:05 UTC (rev 54805)
@@ -97,7 +97,7 @@
 	g_sci->checkVocabularySwitch();
 	Vocabulary *voc = g_sci->getVocabulary();
 	voc->parser_event = event;
-	reg_t params[2] = { voc->parser_base, stringpos };
+	reg_t params[2] = { s->_segMan->getParserPtr(), stringpos };
 
 	ResultWordListList words;
 	bool res = voc->tokenizeString(words, string.c_str(), &error);
@@ -154,7 +154,7 @@
 		// forgotten :)
 		writeSelectorValue(segMan, event, SELECTOR(claimed), 1);
 		if (error) {
-			s->_segMan->strcpy(voc->parser_base, error);
+			s->_segMan->strcpy(s->_segMan->getParserPtr(), error);
 			debugC(2, kDebugLevelParser, "Word unknown: %s", error);
 			/* Issue warning: */
 

Modified: scummvm/trunk/engines/sci/engine/kstring.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kstring.cpp	2010-12-06 23:15:25 UTC (rev 54804)
+++ scummvm/trunk/engines/sci/engine/kstring.cpp	2010-12-07 00:47:05 UTC (rev 54805)
@@ -706,34 +706,22 @@
 
 		// A count of -1 means fill the rest of the array
 		uint32 count = argv[5].toSint16() == -1 ? string2Size - index2 + 1 : argv[5].toUint16();
-	
-		// We have a special case here for argv[1] being a system string
-		if (argv[1].segment == s->_segMan->getSysStringsSegment()) {
-			// Resize if necessary
-			const uint16 sysStringId = argv[1].toUint16();
-			SystemString *sysString = s->_segMan->getSystemString(sysStringId);
-			assert(sysString);
-			if ((uint32)sysString->_maxSize < index1 + count) {
-				free(sysString->_value);
-				sysString->_maxSize = index1 + count;
-				sysString->_value = (char *)calloc(index1 + count, sizeof(char));
-			}
+		reg_t strAddress = argv[1];
 
-			strncpy(sysString->_value + index1, string2 + index2, count);
-		} else {
-			SciString *string1 = s->_segMan->lookupString(argv[1]);
+		SciString *string1 = s->_segMan->lookupString(argv[1]);
+		//SciString *string1 = !argv[1].isNull() ? s->_segMan->lookupString(argv[1]) : s->_segMan->allocateString(&strAddress);
 
-			if (string1->getSize() < index1 + count)
-				string1->setSize(index1 + count);
+		if (string1->getSize() < index1 + count)
+			string1->setSize(index1 + count);
 
-			// Note: We're accessing from c_str() here because the
-			// string's size ignores the trailing 0 and therefore
-			// triggers an assert when doing string2[i + index2].
-			for (uint16 i = 0; i < count; i++)
-				string1->setValue(i + index1, string2[i + index2]);
-		}
-		
-	} return argv[1];
+		// Note: We're accessing from c_str() here because the
+		// string's size ignores the trailing 0 and therefore
+		// triggers an assert when doing string2[i + index2].
+		for (uint16 i = 0; i < count; i++)
+			string1->setValue(i + index1, string2[i + index2]);
+	
+		return strAddress;
+	}
 	case 7: { // Cmp
 		Common::String string1 = argv[1].isNull() ? "" : s->_segMan->getString(argv[1]);
 		Common::String string2 = argv[2].isNull() ? "" : s->_segMan->getString(argv[2]);

Modified: scummvm/trunk/engines/sci/engine/savegame.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cpp	2010-12-06 23:15:25 UTC (rev 54804)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp	2010-12-07 00:47:05 UTC (rev 54805)
@@ -148,6 +148,23 @@
 		if (type == SEG_TYPE_HUNK)
 			continue;
 
+		// Don't save or load the obsolete system string segments
+		if (type == 5) {
+			if (s.isSaving()) {
+				continue;
+			} else {
+				// Old saved game. Skip the data.
+				Common::String tmp;
+				for (int i = 0; i < 4; i++) {
+					s.syncString(tmp);	// OBSOLETE: name
+					s.skip(4);			// OBSOLETE: maxSize
+					s.syncString(tmp);	// OBSOLETE: value
+				}
+				_heap[i] = NULL;	// set as freed
+				continue;
+			}
+		}
+
 		if (s.isLoading())
 			mobj = SegmentObj::createSegmentObj(type);
 
@@ -484,32 +501,6 @@
 	s.syncAsSint32LE(_markedAsDeleted);
 }
 
-static void sync_SystemString(Common::Serializer &s, SystemString &obj) {
-	s.syncString(obj._name);
-	s.syncAsSint32LE(obj._maxSize);
-
-	// Sync obj._value. We cannot use syncCStr as we must make sure that
-	// the allocated buffer has the correct size, i.e., obj._maxSize
-	Common::String tmp;
-	if (s.isSaving() && obj._value)
-		tmp = obj._value;
-	s.syncString(tmp);
-	if (s.isLoading()) {
-		if (!obj._maxSize) {
-			obj._value = NULL;
-		} else {
-			//free(*str);
-			obj._value = (char *)calloc(obj._maxSize, sizeof(char));
-			strncpy(obj._value, tmp.c_str(), obj._maxSize);
-		}
-	}
-}
-
-void SystemStrings::saveLoadWithSerializer(Common::Serializer &s) {
-	for (int i = 0; i < SYS_STRINGS_MAX; ++i)
-		sync_SystemString(s, _strings[i]);
-}
-
 void DynMem::saveLoadWithSerializer(Common::Serializer &s) {
 	s.syncAsSint32LE(_size);
 	s.syncString(_description);
@@ -891,6 +882,9 @@
 	delete s->_msgState;
 	s->_msgState = new MessageState(s->_segMan);
 
+	// System strings:
+	s->_segMan->initSysStrings();
+
 	s->abortScriptProcessing = kAbortLoadGame;
 
 	// signal restored game to game scripts

Modified: scummvm/trunk/engines/sci/engine/seg_manager.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/seg_manager.cpp	2010-12-06 23:15:25 UTC (rev 54804)
+++ scummvm/trunk/engines/sci/engine/seg_manager.cpp	2010-12-07 00:47:05 UTC (rev 54805)
@@ -82,22 +82,19 @@
 }
 
 void SegManager::initSysStrings() {
-	_sysStrings = (SystemStrings *)allocSegment(new SystemStrings(), &_sysStringsSegId);
+	if (getSciVersion() <= SCI_VERSION_1_1) {
+		// We need to allocate system strings in one segment, for compatibility reasons
+		allocDynmem(512, "system strings", &_saveDirPtr);
+		_parserPtr = make_reg(_saveDirPtr.segment, _saveDirPtr.offset + 256);
+#ifdef ENABLE_SCI32
+	} else {
+		SciString *saveDirString = allocateString(&_saveDirPtr);
+		saveDirString->setSize(256);
+		saveDirString->setValue(0, 0);
 
-	// Allocate static buffer for savegame and CWD directories
-	SystemString *strSaveDir = getSystemString(SYS_STRING_SAVEDIR);
-	strSaveDir->_name = "savedir";
-	strSaveDir->_maxSize = MAX_SAVE_DIR_SIZE;
-	strSaveDir->_value = (char *)calloc(MAX_SAVE_DIR_SIZE, sizeof(char));
-	// Set the savegame dir (actually, we set it to a fake value,
-	// since we cannot let the game control where saves are stored)
-	::strcpy(strSaveDir->_value, "");
-
-	// Allocate static buffer for the parser base
-	SystemString *strParserBase = getSystemString(SYS_STRING_PARSER_BASE);
-	strParserBase->_name = "parser-base";
-	strParserBase->_maxSize = MAX_PARSER_BASE;
-	strParserBase->_value = (char *)calloc(MAX_PARSER_BASE, sizeof(char));
+		_parserPtr = NULL_REG;	// no SCI2 game had a parser
+#endif
+	}
 }
 
 SegmentId SegManager::findFreeSegment() const {

Modified: scummvm/trunk/engines/sci/engine/seg_manager.h
===================================================================
--- scummvm/trunk/engines/sci/engine/seg_manager.h	2010-12-06 23:15:25 UTC (rev 54804)
+++ scummvm/trunk/engines/sci/engine/seg_manager.h	2010-12-07 00:47:05 UTC (rev 54805)
@@ -438,23 +438,9 @@
 	void setClassOffset(int index, reg_t offset) { _classTable[index].reg = offset;	}
 	void resizeClassTable(uint32 size) { _classTable.resize(size); }
 
-	/**
-	 * Obtains the system strings segment ID
-	 */
-	SegmentId getSysStringsSegment() { return _sysStringsSegId; }
+	reg_t getSaveDirPtr() const { return _saveDirPtr; }
+	reg_t getParserPtr() const { return _parserPtr; }
 
-	/**
-	 * Get a pointer to the system string with the specified index,
-	 * or NULL if that index is invalid.
-	 *
-	 * This method is currently only used by kString().
-	 */
-	SystemString *getSystemString(uint idx) const {
-		if (idx >= SYS_STRINGS_MAX)
-			return NULL;
-		return &_sysStrings->_strings[idx];
-	}
-
 #ifdef ENABLE_SCI32
 	SciArray<reg_t> *allocateArray(reg_t *addr);
 	SciArray<reg_t> *lookupArray(reg_t addr);
@@ -480,9 +466,9 @@
 	SegmentId _nodesSegId; ///< ID of the (a) node segment
 	SegmentId _hunksSegId; ///< ID of the (a) hunk segment
 
-	/* System strings */
-	SegmentId _sysStringsSegId;
-	SystemStrings *_sysStrings;
+	// Statically allocated memory for system strings
+	reg_t _saveDirPtr;
+	reg_t _parserPtr;
 
 #ifdef ENABLE_SCI32
 	SegmentId _arraysSegId;

Modified: scummvm/trunk/engines/sci/engine/segment.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/segment.cpp	2010-12-06 23:15:25 UTC (rev 54804)
+++ scummvm/trunk/engines/sci/engine/segment.cpp	2010-12-07 00:47:05 UTC (rev 54805)
@@ -52,9 +52,6 @@
 	case SEG_TYPE_LOCALS:
 		mem = new LocalVariables();
 		break;
-	case SEG_TYPE_SYS_STRINGS:
-		mem = new SystemStrings();
-		break;
 	case SEG_TYPE_STACK:
 		mem = new DataStack();
 		break;
@@ -99,9 +96,6 @@
 	case SEG_TYPE_LOCALS:
 		return "locals";
 		break;
-	case SEG_TYPE_SYS_STRINGS:
-		return "strings";
-		break;
 	case SEG_TYPE_STACK:
 		return "stack";
 		break;
@@ -201,28 +195,6 @@
 	return ret;
 }
 
-bool SystemStrings::isValidOffset(uint16 offset) const {
-	return offset < SYS_STRINGS_MAX && !_strings[offset]._name.empty();
-}
-
-SegmentRef SystemStrings::dereference(reg_t pointer) {
-	SegmentRef ret;
-	ret.isRaw = true;
-	ret.maxSize = _strings[pointer.offset]._maxSize;
-	if (isValidOffset(pointer.offset))
-		ret.raw = (byte *)(_strings[pointer.offset]._value);
-	else {
-		if (g_sci->getGameId() == GID_KQ5) {
-			// This occurs in KQ5CD when interacting with certain objects
-		} else {
-			error("SystemStrings::dereference(): Attempt to dereference invalid pointer %04x:%04x", PRINT_REG(pointer));
-		}
-	}
-
-	return ret;
-}
-
-
 //-------------------- clones --------------------
 
 Common::Array<reg_t> CloneTable::listAllOutgoingReferences(reg_t addr) const {

Modified: scummvm/trunk/engines/sci/engine/segment.h
===================================================================
--- scummvm/trunk/engines/sci/engine/segment.h	2010-12-06 23:15:25 UTC (rev 54804)
+++ scummvm/trunk/engines/sci/engine/segment.h	2010-12-07 00:47:05 UTC (rev 54805)
@@ -64,7 +64,7 @@
 	SEG_TYPE_CLONES = 2,
 	SEG_TYPE_LOCALS = 3,
 	SEG_TYPE_STACK = 4,
-	SEG_TYPE_SYS_STRINGS = 5,
+	// 5 used to be system strings,	now obsolete
 	SEG_TYPE_LISTS = 6,
 	SEG_TYPE_NODES = 7,
 	SEG_TYPE_HUNK = 8,
@@ -145,49 +145,6 @@
 	}
 };
 
-enum {
-	SYS_STRINGS_MAX = 4,
-
-	SYS_STRING_SAVEDIR = 0,
-	SYS_STRING_PARSER_BASE = 1,
-
-	MAX_PARSER_BASE = 64
-};
-
-struct SystemString {
-	Common::String _name;
-	int _maxSize;
-	char *_value;
-};
-
-struct SystemStrings : public SegmentObj {
-	SystemString _strings[SYS_STRINGS_MAX];
-
-public:
-	SystemStrings() : SegmentObj(SEG_TYPE_SYS_STRINGS) {
-		for (int i = 0; i < SYS_STRINGS_MAX; i++) {
-			_strings[i]._maxSize = 0;
-			_strings[i]._value = 0;
-		}
-	}
-	~SystemStrings() {
-		for (int i = 0; i < SYS_STRINGS_MAX; i++) {
-			SystemString *str = &_strings[i];
-			if (!str->_name.empty()) {
-				free(str->_value);
-				str->_value = NULL;
-
-				str->_maxSize = 0;
-			}
-		}
-	}
-
-	virtual bool isValidOffset(uint16 offset) const;
-	virtual SegmentRef dereference(reg_t pointer);
-
-	virtual void saveLoadWithSerializer(Common::Serializer &ser);
-};
-
 struct LocalVariables : public SegmentObj {
 	int script_id; /**< Script ID this local variable block belongs to */
 	Common::Array<reg_t> _locals;

Modified: scummvm/trunk/engines/sci/parser/vocabulary.cpp
===================================================================
--- scummvm/trunk/engines/sci/parser/vocabulary.cpp	2010-12-06 23:15:25 UTC (rev 54804)
+++ scummvm/trunk/engines/sci/parser/vocabulary.cpp	2010-12-07 00:47:05 UTC (rev 54805)
@@ -75,7 +75,6 @@
 
 	loadAltInputs();
 
-	parser_base = NULL_REG;
 	parser_event = NULL_REG;
 	parserIsValid = false;
 }
@@ -89,7 +88,6 @@
 void Vocabulary::reset() {
 	parserIsValid = false; // Invalidate parser
 	parser_event = NULL_REG; // Invalidate parser event
-	parser_base = make_reg(g_sci->getEngineState()->_segMan->getSysStringsSegment(), SYS_STRING_PARSER_BASE);
 }
 
 bool Vocabulary::loadParserWords() {

Modified: scummvm/trunk/engines/sci/parser/vocabulary.h
===================================================================
--- scummvm/trunk/engines/sci/parser/vocabulary.h	2010-12-06 23:15:25 UTC (rev 54804)
+++ scummvm/trunk/engines/sci/parser/vocabulary.h	2010-12-07 00:47:05 UTC (rev 54805)
@@ -359,7 +359,6 @@
 	ParseTreeNode _parserNodes[VOCAB_TREE_NODES]; /**< The parse tree */
 
 	// Parser data:
-	reg_t parser_base; /**< Base address for the parser error reporting mechanism */
 	reg_t parser_event; /**< The event passed to Parse() and later used by Said() */
 	bool parserIsValid; /**< If something has been correctly parsed */
 };

Modified: scummvm/trunk/engines/sci/sound/music.cpp
===================================================================
--- scummvm/trunk/engines/sci/sound/music.cpp	2010-12-06 23:15:25 UTC (rev 54804)
+++ scummvm/trunk/engines/sci/sound/music.cpp	2010-12-07 00:47:05 UTC (rev 54805)
@@ -343,7 +343,7 @@
 	}
 	// otherwise look for unused channel
 	for (int channelNr = _driverFirstChannel; channelNr < 15; channelNr++) {
-		if (channelNr == 9) // never map to channel 9 (precussion)
+		if (channelNr == 9) // never map to channel 9 (percussion)
 			continue;
 		if (!_usedChannel[channelNr]) {
 			_usedChannel[channelNr] = caller;


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