[Scummvm-git-logs] scummvm-tools master -> c48f216d7e9d9ca46afb40b6fc9a1cd3c51a1afd

sdelamarre noreply at scummvm.org
Fri Mar 17 00:34:55 UTC 2023


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

Summary:
c48f216d7e GOB: ensure degob gives opcode offsets from their beginning


Commit: c48f216d7e9d9ca46afb40b6fc9a1cd3c51a1afd
    https://github.com/scummvm/scummvm-tools/commit/c48f216d7e9d9ca46afb40b6fc9a1cd3c51a1afd
Author: Simon Delamarre (simon.delamarre14 at gmail.com)
Date: 2023-03-17T01:34:18+01:00

Commit Message:
GOB: ensure degob gives opcode offsets from their beginning

The displayed opcode offset was often taken mid-opcode ; printIndent() must precede the first read() call.

Changed paths:
    engines/gob/degob_script.cpp
    engines/gob/degob_script.h
    engines/gob/degob_script_v1.cpp
    engines/gob/degob_script_v2.cpp
    engines/gob/degob_script_v5.cpp
    engines/gob/degob_script_v6.cpp
    engines/gob/degob_script_v7.cpp


diff --git a/engines/gob/degob_script.cpp b/engines/gob/degob_script.cpp
index f93f5312..028c70fe 100644
--- a/engines/gob/degob_script.cpp
+++ b/engines/gob/degob_script.cpp
@@ -218,6 +218,11 @@ void Script::printIndent() const {
 	for (uint32 i = 0; i < _indent; i++)
 		putString("	");
 }
+void Script::printIndent(uint32 pos) const {
+	print("%08d:", pos);
+	for (uint32 i = 0; i < _indent; i++)
+		putString("	");
+}
 void Script::printLine(const char *str) const {
 	printIndent(); putString(str); putString("\n");
 }
diff --git a/engines/gob/degob_script.h b/engines/gob/degob_script.h
index 1ce5692f..9f280eb5 100644
--- a/engines/gob/degob_script.h
+++ b/engines/gob/degob_script.h
@@ -129,6 +129,7 @@ protected:
 	void putString(const char *s) const;
 	void print(const char *s, ...) const;
 	void printIndent() const;
+	void printIndent(uint32 pos) const;
 	void printLine(const char *s) const;
 	std::string printStr(const char *s, ...) const;
 
diff --git a/engines/gob/degob_script_v1.cpp b/engines/gob/degob_script_v1.cpp
index cf1e82c9..c8f3ea0e 100644
--- a/engines/gob/degob_script_v1.cpp
+++ b/engines/gob/degob_script_v1.cpp
@@ -741,9 +741,8 @@ void Script_v1::o1_goblinFunc(FuncParams &params) {
 }
 
 void Script_v1::o1_callSub(FuncParams &params) {
-	uint16 offset = readUint16();
-
 	printIndent();
+	uint16 offset = readUint16();
 
 	uint32 pos = getPos();
 
@@ -898,9 +897,9 @@ void Script_v1::o1_assign(FuncParams &params) {
 }
 
 void Script_v1::o1_palLoad(FuncParams &params) {
+	startFunc(params);
 	byte cmd = readUint8();
 
-	startFunc(params);
 	print("%d, %d", (cmd & 0x80) != 0, cmd & 0x7F);
 	endFunc();
 
@@ -1019,9 +1018,9 @@ void Script_v1::o1_loadSound(FuncParams &params) {
 }
 
 void Script_v1::o1_loadMult(FuncParams &params) {
+	startFunc(params);
 	uint16 id = readUint16();
 
-	startFunc(params);
 	print("%d", id);
 	endFunc();
 
diff --git a/engines/gob/degob_script_v2.cpp b/engines/gob/degob_script_v2.cpp
index 162737c6..1e4371b0 100644
--- a/engines/gob/degob_script_v2.cpp
+++ b/engines/gob/degob_script_v2.cpp
@@ -727,6 +727,7 @@ void Script_v2::o2_totSub(FuncParams &params) {
 }
 
 void Script_v2::o2_assign(FuncParams &params) {
+	uint32 pos = getPos();
 	uint8 type = peekUint8();
 	std::string varIndex = readVarIndex();
 
@@ -736,22 +737,29 @@ void Script_v2::o2_assign(FuncParams &params) {
 
 		for (uint16 i = 0; i < loopCount; i++) {
 			std::string expr = readExpr();
-			printIndent();
+			if (i == 0)
+				printIndent(pos);
+			else
+				printIndent();
 			print("%s[%d] = %s;\n", varIndex.c_str(), (type == 24) ? (i * 2) : i, expr.c_str());
 		}
 	} else {
 		std::string expr = readExpr();
 
-		printIndent();
+		printIndent(pos);
 		print("%s = %s;\n", varIndex.c_str(), expr.c_str());
 	}
 }
 
 void Script_v2::o2_pushVars(FuncParams &params) {
+	uint32 pos = getPos();
 	uint8 count = readUint8();
 
 	for (uint16 i = 0; i < count; i++) {
-		printIndent();
+		if (i == 0)
+			printIndent(pos);
+		else
+			printIndent();
 		if ((peekUint8() == 25) || (peekUint8() == 28)) {
 			print("push(%s, animDataSize);\n", readVarIndex().c_str());
 			skip(1);
@@ -761,10 +769,14 @@ void Script_v2::o2_pushVars(FuncParams &params) {
 }
 
 void Script_v2::o2_popVars(FuncParams &params) {
+	uint32 pos = getPos();
 	uint8 count = readUint8();
 
 	for (uint16 i = 0; i < count; i++) {
-		printIndent();
+		if (i == 0)
+			printIndent(pos);
+		else
+			printIndent();
 		print("pop(%s);\n", readVarIndex().c_str());
 	}
 }
@@ -776,6 +788,7 @@ void Script_v2::o2_loadSound(FuncParams &params) {
 void Script_v2::o2_loadMult(FuncParams &params) {
 	uint16 id;
 	bool hasImds;
+	startFunc(params);
 
 	id = readUint16();
 	if (id & 0x8000) {
@@ -783,7 +796,6 @@ void Script_v2::o2_loadMult(FuncParams &params) {
 		skip(1);
 	}
 
-	startFunc(params);
 	print("%d", id);
 	endFunc();
 
@@ -897,9 +909,9 @@ void Script_v2::o2_loadMapObjects(FuncParams &params) {
 }
 
 void Script_v2::o2_playMult(FuncParams &params) {
+	startFunc(params);
 	uint16 multData = readUint16();
 
-	startFunc(params);
 	print("%d, %d", multData >> 1, multData & 0x01);
 	endFunc();
 }
diff --git a/engines/gob/degob_script_v5.cpp b/engines/gob/degob_script_v5.cpp
index 8cf6eedd..82ffd8cf 100644
--- a/engines/gob/degob_script_v5.cpp
+++ b/engines/gob/degob_script_v5.cpp
@@ -705,9 +705,9 @@ void Script_v5::goblinOpcode(int i, FuncParams &params) {
 }
 
 void Script_v5::o5_spaceShooter(FuncParams &params) {
+	startFunc(params);
 	int16 paramCount = readUint16();
 
-	startFunc(params);
 	print("%d, ", params.extraData);
 	for (int i = 0; i < paramCount; i++) {
 		uint16 n = readUint16();
@@ -724,10 +724,10 @@ void Script_v5::o5_spaceShooter(FuncParams &params) {
 }
 
 void Script_v5::o5_istrlen(FuncParams &params) {
+	startFunc(params);
 	if (peekUint8() == 0x80)
 		skip(1);
 
-	startFunc(params);
 	print("%s, ", readVarIndex().c_str());
 	print("%s", readVarIndex().c_str());
 	endFunc();
diff --git a/engines/gob/degob_script_v6.cpp b/engines/gob/degob_script_v6.cpp
index 9979b28a..00ee6d91 100644
--- a/engines/gob/degob_script_v6.cpp
+++ b/engines/gob/degob_script_v6.cpp
@@ -705,9 +705,9 @@ void Script_v6::o6_createSprite(FuncParams &params) {
 	uint32 pos;
 
 	pos = getPos();
+	startFunc(params);
 	skip(1);
 
-	startFunc(params);
 	if (peekUint8() == 0) {
 		seek(pos);
 		print("%d, ", readUint16());
@@ -724,9 +724,9 @@ void Script_v6::o6_createSprite(FuncParams &params) {
 }
 
 void Script_v6::o6_loadCursor(FuncParams &params) {
+	startFunc(params);
 	int16 id = (int16) readUint16();
 
-	startFunc(params);
 	print("%d, ", id);
 	if (id == -1) {
 		print("%s, ", peekString());
@@ -744,6 +744,7 @@ void Script_v6::o6_loadCursor(FuncParams &params) {
 }
 
 void Script_v6::o6_assign(FuncParams &params) {
+	uint32 pos = getPos();
 	uint8 type = peekUint8();
 	uint16 var_0, var_4;
 	std::string varIndex = readVarIndex(&var_0, &var_4);
@@ -756,7 +757,7 @@ void Script_v6::o6_assign(FuncParams &params) {
 
 		varIndex2 = readVarIndex(&var_6, 0);
 
-		printIndent();
+		printIndent(pos);
 		print("memcpy(%s, %s, %d);\n", varIndex.c_str(), varIndex2.c_str(), var_6 * 4);
 
 		seek(savedPos);
@@ -774,7 +775,10 @@ void Script_v6::o6_assign(FuncParams &params) {
 			uint8 c = readUint8();
 			uint16 n = readUint16();
 
-			printIndent();
+			if (i == 0)
+				printIndent(pos);
+			else
+				printIndent();
 			print("memset(%s + %d, %d, %d);\n", varIndex.c_str(), off, c, n);
 
 			off += n;
@@ -785,13 +789,16 @@ void Script_v6::o6_assign(FuncParams &params) {
 
 		for (uint16 i = 0; i < loopCount; i++) {
 			std::string expr = readExpr();
-			printIndent();
+			if (i == 0)
+				printIndent(pos);
+			else
+				printIndent();
 			print("%s[%d] = %s;\n", varIndex.c_str(), (type == 24) ? (i * 2) : i, expr.c_str());
 		}
 	} else {
 		std::string expr = readExpr();
 
-		printIndent();
+		printIndent(pos);
 		print("%s = %s;\n", varIndex.c_str(), expr.c_str());
 	}
 }
diff --git a/engines/gob/degob_script_v7.cpp b/engines/gob/degob_script_v7.cpp
index 5eb12bcc..1c1ab069 100644
--- a/engines/gob/degob_script_v7.cpp
+++ b/engines/gob/degob_script_v7.cpp
@@ -706,9 +706,9 @@ void Script_v7::goblinOpcode(int i, FuncParams &params) {
 }
 
 void Script_v7::o7_loadCursor(FuncParams &params) {
-    int16 id = (int16) readUint16();
+	startFunc(params);
+	int16 id = (int16) readUint16();
 
-    startFunc(params);
     print("%d, ", id);
     if (id == -1) {
 	print("%s, ", peekString());




More information about the Scummvm-git-logs mailing list