[Scummvm-cvs-logs] scummvm master -> ea8b6c8c6dd43ed0c645927966e4150cc987b5c6

bluegr md5 at scummvm.org
Wed Dec 14 23:13:14 CET 2011


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
ea8b6c8c6d DREAMWEB: Port 'findsetobject' and 'findexobject' to C++ and simplify compare()


Commit: ea8b6c8c6dd43ed0c645927966e4150cc987b5c6
    https://github.com/scummvm/scummvm/commit/ea8b6c8c6dd43ed0c645927966e4150cc987b5c6
Author: Filippos Karapetis (md5 at scummvm.org)
Date: 2011-12-14T14:12:25-08:00

Commit Message:
DREAMWEB: Port 'findsetobject' and 'findexobject' to C++ and simplify compare()

Changed paths:
    devtools/tasmrecover/tasm-recover
    engines/dreamweb/dreamgen.cpp
    engines/dreamweb/dreamgen.h
    engines/dreamweb/stubs.cpp
    engines/dreamweb/stubs.h
    engines/dreamweb/use.cpp



diff --git a/devtools/tasmrecover/tasm-recover b/devtools/tasmrecover/tasm-recover
index 2a8d0be..91aaccf 100755
--- a/devtools/tasmrecover/tasm-recover
+++ b/devtools/tasmrecover/tasm-recover
@@ -394,11 +394,13 @@ generator = cpp(context, "DreamGen", blacklist = [
 	'fillspace',
 	'finalframe',
 	'findallryan',
+	'findexobject',
 	'findlen',
 	'findnextcolon',
 	'findobname',
 	'findormake',
 	'findroominloc',
+	'findsetobject',
 	'findsource',
 	'findtext1',
 	'findxyfrompath',
diff --git a/engines/dreamweb/dreamgen.cpp b/engines/dreamweb/dreamgen.cpp
index 3831f38..fb232ce 100644
--- a/engines/dreamweb/dreamgen.cpp
+++ b/engines/dreamweb/dreamgen.cpp
@@ -3630,72 +3630,6 @@ doselob:
 	useRoutine();
 }
 
-void DreamGenContext::findSetObject() {
-	STACK_CHECK;
-	_sub(al, 'A');
-	_sub(ah, 'A');
-	_sub(cl, 'A');
-	_sub(ch, 'A');
-	es = data.word(kSetdat);
-	bx = 0;
-	dl = 0;
-findsetloop:
-	_cmp(al, es.byte(bx+12));
-	if (!flags.z())
-		goto nofind;
-	_cmp(ah, es.byte(bx+13));
-	if (!flags.z())
-		goto nofind;
-	_cmp(cl, es.byte(bx+14));
-	if (!flags.z())
-		goto nofind;
-	_cmp(ch, es.byte(bx+15));
-	if (!flags.z())
-		goto nofind;
-	al = dl;
-	return;
-nofind:
-	_add(bx, 64);
-	_inc(dl);
-	_cmp(dl, 128);
-	if (!flags.z())
-		goto findsetloop;
-	al = dl;
-}
-
-void DreamGenContext::findExObject() {
-	STACK_CHECK;
-	_sub(al, 'A');
-	_sub(ah, 'A');
-	_sub(cl, 'A');
-	_sub(ch, 'A');
-	es = data.word(kExtras);
-	bx = (0+2080+30000);
-	dl = 0;
-findexloop:
-	_cmp(al, es.byte(bx+12));
-	if (!flags.z())
-		goto nofindex;
-	_cmp(ah, es.byte(bx+13));
-	if (!flags.z())
-		goto nofindex;
-	_cmp(cl, es.byte(bx+14));
-	if (!flags.z())
-		goto nofindex;
-	_cmp(ch, es.byte(bx+15));
-	if (!flags.z())
-		goto nofindex;
-	al = dl;
-	return;
-nofindex:
-	_add(bx, 16);
-	_inc(dl);
-	_cmp(dl, (114));
-	if (!flags.z())
-		goto findexloop;
-	al = dl;
-}
-
 void DreamGenContext::isRyanHolding() {
 	STACK_CHECK;
 	_sub(al, 'A');
diff --git a/engines/dreamweb/dreamgen.h b/engines/dreamweb/dreamgen.h
index 8d23f97..2a8a6c6 100644
--- a/engines/dreamweb/dreamgen.h
+++ b/engines/dreamweb/dreamgen.h
@@ -537,7 +537,6 @@ public:
 	void lookAtPlace();
 	void findAllOpen();
 	void showSlots();
-	void findSetObject();
 	void deleteExObject();
 	void helicopter();
 	void getEitherAd();
@@ -562,7 +561,6 @@ public:
 	void useGun();
 	void useHandle();
 	void incRyanPage();
-	void findExObject();
 	void clearChanges();
 	void searchForFiles();
 	void getExAd();
diff --git a/engines/dreamweb/stubs.cpp b/engines/dreamweb/stubs.cpp
index 55e7916..21173f8 100644
--- a/engines/dreamweb/stubs.cpp
+++ b/engines/dreamweb/stubs.cpp
@@ -1755,19 +1755,64 @@ void DreamGenContext::printMessage(uint16 x, uint16 y, uint8 index, uint8 maxWid
 	printDirect(&string, x, &y, maxWidth, centered);
 }
 
+bool objectMatches(void *object, const char *id) {
+	const char *objId = (const char *)(((const uint8 *)object) + 12); // whether it is a DynObject or a SetObject
+	for (size_t i = 0; i < 4; ++i) {
+		if (id[i] != objId[i] + 'A')
+			return false;
+	}
+	return true;
+}
+
 void DreamGenContext::compare() {
 	char id[4] = { cl, ch, dl, dh };
 	flags._z = compare(al, ah, id);
 }
 
 bool DreamGenContext::compare(uint8 index, uint8 flag, const char id[4]) {
-	void *ptr = getAnyAdDir(index, flag);
-	const char *objId = (const char *)(((const uint8 *)ptr) + 12); // whether it is a DynObject or a SetObject
-	for (size_t i = 0; i < 4; ++i) {
-		if (id[i] != objId[i] + 'A')
-			return false;
-	}
-	return true;
+	return objectMatches(getAnyAdDir(index, flag), id);
+}
+
+void DreamGenContext::findSetObject() {
+	char id[5];
+	id[0] = al;
+	id[1] = ah;
+	id[2] = cl;
+	id[3] = ch;
+	id[4] = '\0';
+	al = findSetObject(id);
+}
+
+uint16 DreamGenContext::findSetObject(const char *id) {
+	uint16 index = 0;
+
+	do {
+		if (objectMatches(getSetAd(index), id))
+			return index;
+	} while (index++ < 128);
+
+	return index;	// 128, not found
+}
+
+void DreamGenContext::findExObject() {
+	char id[5];
+	id[0] = al;
+	id[1] = ah;
+	id[2] = cl;
+	id[3] = ch;
+	id[4] = '\0';
+	al = findExObject(id);
+}
+
+uint16 DreamGenContext::findExObject(const char *id) {
+	uint16 index = 0;
+
+	do {
+		if (objectMatches(getExAd(index), id))
+			return index;
+	} while (index++ < 114);
+
+	return index;	// 114, not found
 }
 
 bool DreamGenContext::isItDescribed(const ObjPos *pos) {
@@ -3344,8 +3389,7 @@ void DreamGenContext::openInv() {
 }
 
 void DreamGenContext::obsThatDoThings() {
-	char id[4] = { 'M', 'E', 'M', 'B' };	// TODO: convert to string with trailing zero
-	if (!compare(data.byte(kCommand), data.byte(kObjecttype), id))
+	if (!compare(data.byte(kCommand), data.byte(kObjecttype), "MEMB"))
 		return; // notlouiscard
 
 	if (DreamBase::getLocation(4) != 1) {
diff --git a/engines/dreamweb/stubs.h b/engines/dreamweb/stubs.h
index 089272b..6764c18 100644
--- a/engines/dreamweb/stubs.h
+++ b/engines/dreamweb/stubs.h
@@ -582,5 +582,9 @@
 	void runEndSeq();
 	void lookAtCard();
 	bool execCommand();
+	void findSetObject();
+	uint16 findSetObject(const char *id);
+	void findExObject();
+	uint16 findExObject(const char *id);
 
 #endif
diff --git a/engines/dreamweb/use.cpp b/engines/dreamweb/use.cpp
index 599cdf7..f5d631a 100644
--- a/engines/dreamweb/use.cpp
+++ b/engines/dreamweb/use.cpp
@@ -747,8 +747,7 @@ bool DreamGenContext::defaultUseHandler(const char *id) {
 }
 
 void DreamGenContext::useChurchGate() {
-	char id[4] = { 'C', 'U', 'T', 'T' };	// TODO: convert to string with trailing zero
-	if (defaultUseHandler(id))
+	if (defaultUseHandler("CUTT"))
 		return;
 
 	// Cut gate
@@ -784,8 +783,7 @@ void DreamGenContext::useFullCart() {
 }
 
 void DreamGenContext::useClearBox() {
-	char id[4] = { 'R', 'A', 'I', 'L' };	// TODO: convert to string with trailing zero
-	if (defaultUseHandler(id))
+	if (defaultUseHandler("RAIL"))
 		return;
 
 	// Open box
@@ -800,8 +798,7 @@ void DreamGenContext::useClearBox() {
 }
 
 void DreamGenContext::openTVDoor() {
-	char id[4] = { 'U', 'L', 'O', 'K' };	// TODO: convert to string with trailing zero
-	if (defaultUseHandler(id))
+	if (defaultUseHandler("ULOK"))
 		return;
 
 	// Key on TV
@@ -816,9 +813,7 @@ void DreamGenContext::usePlate() {
 		return;
 	}
 
-	char screw[4] = { 'S', 'C', 'R', 'W' };	// TODO: convert to string with trailing zero
-	char knife[4] = { 'K', 'N', 'F', 'E' };	// TODO: convert to string with trailing zero
-	if (compare(data.byte(kWithobject), data.byte(kWithtype), screw)) {
+	if (compare(data.byte(kWithobject), data.byte(kWithtype), "SCRW")) {
 		// Unscrew plate
 		playChannel1(20);
 		showFirstUse();
@@ -828,7 +823,7 @@ void DreamGenContext::usePlate() {
 		placeFreeObject(0);
 		data.byte(kProgresspoints)++;
 		data.byte(kGetback) = 1;
-	} else if (compare(data.byte(kWithobject), data.byte(kWithtype), knife)) {
+	} else if (compare(data.byte(kWithobject), data.byte(kWithtype), "KNFE")) {
 		// Tried knife
 		showPuzText(54, 300);
 		putBackObStuff();
@@ -845,8 +840,7 @@ void DreamGenContext::usePlinth() {
 		return;
 	}
 
-	char id[4] = { 'D', 'K', 'E', 'Y' };	// TODO: convert to string with trailing zero
-	if (!compare(data.byte(kWithobject), data.byte(kWithtype), id)) {
+	if (!compare(data.byte(kWithobject), data.byte(kWithtype), "DKEY")) {
 		// Wrong key
 		showFirstUse();
 		putBackObStuff();
@@ -864,8 +858,7 @@ void DreamGenContext::usePlinth() {
 }
 
 void DreamGenContext::useElvDoor() {
-	char id[4] = { 'A', 'X', 'E', 'D' };	// TODO: convert to string with trailing zero
-	if (defaultUseHandler(id))
+	if (defaultUseHandler("AXED"))
 		return;
 
 	// Axe on door
@@ -899,8 +892,7 @@ void DreamGenContext::useWinch() {
 	ah = 1;
 	checkInside();
 
-	char id[4] = { 'F', 'U', 'S', 'E' };	// TODO: convert to string with trailing zero
-	if (cl == kNumexobjects || !compare(cl, 4, id)) {
+	if (cl == kNumexobjects || !compare(cl, 4, "FUSE")) {
 		// No winch
 		showFirstUse();
 		putBackObStuff();
@@ -923,8 +915,7 @@ void DreamGenContext::useWinch() {
 }
 
 void DreamGenContext::useCart() {
-	char id[4] = { 'R', 'O', 'C', 'K' };	// TODO: convert to string with trailing zero
-	if (defaultUseHandler(id))
+	if (defaultUseHandler("ROCK"))
 		return;
 
 	DynObject *exObject = getExAd(data.byte(kWithobject));
@@ -959,8 +950,7 @@ void DreamGenContext::chewy() {
 }
 
 void DreamGenContext::useHole() {
-	char id[4] = { 'H', 'N', 'D', 'A' };	// TODO: convert to string with trailing zero
-	if (defaultUseHandler(id))
+	if (defaultUseHandler("HNDA"))
 		return;
 
 	showFirstUse();
@@ -972,8 +962,7 @@ void DreamGenContext::useHole() {
 }
 
 void DreamGenContext::openHotelDoor() {
-	char id[4] = { 'K', 'E', 'Y', 'A' };	// TODO: convert to string with trailing zero
-	if (defaultUseHandler(id))
+	if (defaultUseHandler("KEYA"))
 		return;
 
 	playChannel1(16);
@@ -983,8 +972,7 @@ void DreamGenContext::openHotelDoor() {
 }
 
 void DreamGenContext::openHotelDoor2() {
-	char id[4] = { 'K', 'E', 'Y', 'A' };	// TODO: convert to string with trailing zero
-	if (defaultUseHandler(id))
+	if (defaultUseHandler("KEYA"))
 		return;
 
 	playChannel1(16);
@@ -993,8 +981,7 @@ void DreamGenContext::openHotelDoor2() {
 }
 
 void DreamGenContext::grafittiDoor() {
-	char id[4] = { 'A', 'P', 'E', 'N' };	// TODO: convert to string with trailing zero
-	if (defaultUseHandler(id))
+	if (defaultUseHandler("APEN"))
 		return;
 
 	showFirstUse();
@@ -1002,8 +989,7 @@ void DreamGenContext::grafittiDoor() {
 }
 
 void DreamGenContext::usePoolReader() {
-	char id[4] = { 'M', 'E', 'M', 'B' };	// TODO: convert to string with trailing zero
-	if (defaultUseHandler(id))
+	if (defaultUseHandler("MEMB"))
 		return;
 
 	if (data.byte(kTalkedtoattendant) != 1) {
@@ -1019,8 +1005,7 @@ void DreamGenContext::usePoolReader() {
 }
 
 void DreamGenContext::useCardReader1() {
-	char id[4] = { 'C', 'S', 'H', 'R' };	// TODO: convert to string with trailing zero
-	if (defaultUseHandler(id))
+	if (defaultUseHandler("CSHR"))
 		return;
 
 	if (data.byte(kTalkedtosparky) == 0) {
@@ -1042,8 +1027,7 @@ void DreamGenContext::useCardReader1() {
 }
 
 void DreamGenContext::useCardReader2() {
-	char id[4] = { 'C', 'S', 'H', 'R' };	// TODO: convert to string with trailing zero
-	if (defaultUseHandler(id))
+	if (defaultUseHandler("CSHR"))
 		return;
 
 	if (data.byte(kTalkedtoboss) == 0) {
@@ -1070,8 +1054,7 @@ void DreamGenContext::useCardReader2() {
 }
 
 void DreamGenContext::useCardReader3() {
-	char id[4] = { 'C', 'S', 'H', 'R' };	// TODO: convert to string with trailing zero
-	if (defaultUseHandler(id))
+	if (defaultUseHandler("CSHR"))
 		return;
 
 	if (data.byte(kTalkedtorecep) == 0) {
@@ -1098,8 +1081,7 @@ void DreamGenContext::useLighter() {
 		return;
 	}
 
-	char id[4] = { 'S', 'M', 'K', 'E' };	// TODO: convert to string with trailing zero
-	if (!compare(data.byte(kWithobject), data.byte(kWithtype), id)) {
+	if (!compare(data.byte(kWithobject), data.byte(kWithtype), "SMKE")) {
 		showFirstUse();
 		putBackObStuff();
 	} else {
@@ -1116,8 +1098,7 @@ void DreamGenContext::useWire() {
 		return;
 	}
 
-	char knife[4] = { 'K', 'N', 'F', 'E' };	// TODO: convert to string with trailing zero
-	if (compare(data.byte(kWithobject), data.byte(kWithtype), knife)) {
+	if (compare(data.byte(kWithobject), data.byte(kWithtype), "KNFE")) {
 		removeSetObject(51);
 		placeSetObject(52);
 		showPuzText(11, 300);
@@ -1126,8 +1107,7 @@ void DreamGenContext::useWire() {
 		return;
 	}
 
-	char axe[4] = { 'A', 'X', 'E', 'D' };	// TODO: convert to string with trailing zero
-	if (compare(data.byte(kWithobject), data.byte(kWithtype), axe)) {
+	if (compare(data.byte(kWithobject), data.byte(kWithtype), "AXED")) {
 		showPuzText(16, 300);
 		putBackObStuff();
 		return;
@@ -1231,8 +1211,7 @@ void DreamGenContext::useControl() {
 		return;
 	}
 
-	char key[4] = { 'K', 'E', 'Y', 'A' };	// TODO: convert to string with trailing zero
-	if (compare(data.byte(kWithobject), data.byte(kWithtype), key)) {	// Right key
+	if (compare(data.byte(kWithobject), data.byte(kWithtype), "KEYA")) {	// Right key
 		playChannel1(16);
 		if (data.byte(kLocation) == 21) {	// Going down
 			showPuzText(3, 300);
@@ -1250,10 +1229,7 @@ void DreamGenContext::useControl() {
 	}
 
 	if (data.byte(kReallocation) == 21) {
-		char knife[4] = { 'K', 'N', 'F', 'E' };	// TODO: convert to string with trailing zero
-		char   axe[4] = { 'A', 'X', 'E', 'D' };	// TODO: convert to string with trailing zero
-
-		if (compare(data.byte(kWithobject), data.byte(kWithtype), knife)) {
+		if (compare(data.byte(kWithobject), data.byte(kWithtype), "KNFE")) {
 			// Jimmy controls
 			placeSetObject(50);
 			placeSetObject(51);
@@ -1265,7 +1241,7 @@ void DreamGenContext::useControl() {
 			showPuzText(10, 300);
 			data.byte(kProgresspoints)++;
 			data.byte(kGetback) = 1;
-		} else if (compare(data.byte(kWithobject), data.byte(kWithtype), axe)) {
+		} else if (compare(data.byte(kWithobject), data.byte(kWithtype), "AXED")) {
 			// Axe on controls
 			showPuzText(16, 300);
 			data.byte(kProgresspoints)++;
@@ -1288,8 +1264,7 @@ void DreamGenContext::useSLab() {
 		return;
 	}
 
-	char id[4] = { 'J', 'E', 'W', 'L' };	// TODO: convert to string with trailing zero
-	if (!compare(data.byte(kWithobject), data.byte(kWithtype), id)) {
+	if (!compare(data.byte(kWithobject), data.byte(kWithtype), "JEWL")) {
 		showPuzText(14, 300);
 		putBackObStuff();
 		return;
@@ -1321,17 +1296,14 @@ void DreamGenContext::usePipe() {
 		return;
 	}
 
-	char cupEmpty[4] = { 'C', 'U', 'P', 'E' };	// TODO: convert to string with trailing zero
-	char  cupFull[4] = { 'C', 'U', 'P', 'F' };	// TODO: convert to string with trailing zero
-
-	if (compare(data.byte(kWithobject), data.byte(kWithtype), cupEmpty)) {
+	if (compare(data.byte(kWithobject), data.byte(kWithtype), "CUPE")) {
 		// Fill cup
 		showPuzText(36, 300);
 		putBackObStuff();
 		DynObject *exObject = getExAd(data.byte(kWithobject));
 		exObject->id[3] = 'F'-'A';	// CUPE (empty cup) -> CUPF (full cup)
 		return;
-	} else if (compare(data.byte(kWithobject), data.byte(kWithtype), cupFull)) {
+	} else if (compare(data.byte(kWithobject), data.byte(kWithtype), "CUPF")) {
 		// Already full
 		showPuzText(35, 300);
 		putBackObStuff();
@@ -1348,10 +1320,7 @@ void DreamGenContext::useOpenBox() {
 		return;
 	}
 
-	char cupEmpty[4] = { 'C', 'U', 'P', 'E' };	// TODO: convert to string with trailing zero
-	char  cupFull[4] = { 'C', 'U', 'P', 'F' };	// TODO: convert to string with trailing zero
-
-	if (compare(data.byte(kWithobject), data.byte(kWithtype), cupFull)) {
+	if (compare(data.byte(kWithobject), data.byte(kWithtype), "CUPF")) {
 		// Destroy open box
 		data.byte(kProgresspoints)++;
 		showPuzText(37, 300);
@@ -1367,7 +1336,7 @@ void DreamGenContext::useOpenBox() {
 		return;
 	}
 
-	if (compare(data.byte(kWithobject), data.byte(kWithtype), cupEmpty)) {
+	if (compare(data.byte(kWithobject), data.byte(kWithtype), "CUPE")) {
 		// Open box wrong
 		showPuzText(38, 300);
 		putBackObStuff();
@@ -1383,10 +1352,7 @@ void DreamGenContext::runTap() {
 		return;
 	}
 
-	char cupEmpty[4] = { 'C', 'U', 'P', 'E' };	// TODO: convert to string with trailing zero
-	char  cupFull[4] = { 'C', 'U', 'P', 'F' };	// TODO: convert to string with trailing zero
-
-	if (compare(data.byte(kWithobject), data.byte(kWithtype), cupEmpty)) {
+	if (compare(data.byte(kWithobject), data.byte(kWithtype), "CUPE")) {
 		// Fill cup from tap
 		DynObject *exObject = getExAd(data.byte(kWithobject));
 		exObject->id[3] = 'F'-'A';	// CUPE (empty cup) -> CUPF (full cup)
@@ -1396,7 +1362,7 @@ void DreamGenContext::runTap() {
 		return;
 	}
 
-	if (compare(data.byte(kWithobject), data.byte(kWithtype), cupFull)) {
+	if (compare(data.byte(kWithobject), data.byte(kWithtype), "CUPF")) {
 		// Cup from tap full
 		showPuzText(58, 300);
 		putBackObStuff();






More information about the Scummvm-git-logs mailing list