[Scummvm-cvs-logs] CVS: scummvm/saga script.h,1.17,1.18 sfuncs.cpp,1.20,1.21 sthread.cpp,1.27,1.28

Torbjörn Andersson eriktorbjorn at users.sourceforge.net
Sun Oct 3 10:18:35 CEST 2004


Update of /cvsroot/scummvm/scummvm/saga
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9242

Modified Files:
	script.h sfuncs.cpp sthread.cpp 
Log Message:
A few, mostly untested, fixes to the SAGA script engine:

* The frame pointer is updated. This won't make any difference since we
  don't actually *use* the frame pointer yet.
* Return values from script functions are handled like in the original now,
  i.e. the function sets thread->retVal and lets the call instruction push
  it onto the stack. (There are two call instructions, one that handles
  return values and one that doesn't, so the script function doesn't know
  if it should push or not.)
* Script return values are handled. 

None of this makes any noticeable difference to the ITE intro.


Index: script.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/script.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- script.h	25 Sep 2004 10:11:17 -0000	1.17
+++ script.h	3 Oct 2004 17:11:23 -0000	1.18
@@ -87,6 +87,8 @@
 	int stackPtr;
 	int framePtr;
 
+	SDataWord_T retVal;
+
 	SDataWord_T stackTop() {
 		return stackBuf[stackPtr];
 	}

Index: sfuncs.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/sfuncs.cpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- sfuncs.cpp	25 Sep 2004 10:11:17 -0000	1.20
+++ sfuncs.cpp	3 Oct 2004 17:11:23 -0000	1.21
@@ -149,8 +149,11 @@
 	// INCOMPLETE
 	SDataWord_T param1;
 	param1 = thread->pop();
-	thread->push(0);	// push for now to allow intro faire 
-									// setup to run completely
+
+	// FIXME: Incomplete, but returning 0 assures that the fair start
+	// script will run completely.
+
+	thread->retVal = 0;
 
 	return R_SUCCESS;
 }
@@ -637,7 +640,7 @@
 // game cinematic. Pushes a zero or positive value if the game 
 // has not been interrupted.
 int Script::SF_checkUserInterrupt(R_SCRIPTFUNC_PARAMS) {
-	thread->push(0);
+	thread->retVal = 0;
 
 	// INCOMPLETE
 

Index: sthread.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/sthread.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- sthread.cpp	23 Sep 2004 06:46:44 -0000	1.27
+++ sthread.cpp	3 Oct 2004 17:11:23 -0000	1.28
@@ -177,6 +177,7 @@
 	long iresult;
 
 	SDataWord_T data;
+	SDataWord_T scriptRetVal = 0;
 	int debug_print = 0;
 	int n_buf;
 	int bitstate;
@@ -296,8 +297,7 @@
 
 // CONTROL INSTRUCTIONS    
 
-			// (GOSB): Call subscript ?
-		case 0x17:
+		case 0x17: // (GOSB): Call subscript
 			{
 				int n_args;
 				int temp;
@@ -316,13 +316,12 @@
 				thread->i_offset = (unsigned long)param1;
 			}
 			break;
-			// (CALL): Call function
-		case 0x19:
-		case 0x18:
+		case 0x18: // (CALL): Call function
+		case 0x19: // (CALL_V): Call function and discard return value
 			{
 				int n_args;
 				uint16 func_num;
-				int FIXME_SHADOWED_result;
+				int sfuncRetVal;
 				SFunc_T sfunc;
 
 				n_args = scriptS.readByte();
@@ -342,30 +341,36 @@
 						thread->pop();
 					}
 				} else {
-					FIXME_SHADOWED_result = (this->*sfunc)(thread);
-					if (FIXME_SHADOWED_result != R_SUCCESS) {
+					sfuncRetVal = (this->*sfunc)(thread);
+					if (sfuncRetVal != R_SUCCESS) {
 						_vm->_console->print(S_WARN_PREFIX "%X: Script function %d failed.\n", thread->i_offset, func_num);
 					}
+
+					if (in_char == 0x18)
+						thread->push(thread->retVal);
 				}
 			}
 			break;
 		case 0x1A: // (ENTR) Enter the dragon
-			//data = scriptS.pos();
-			//thread->push(data);
-			
+			thread->push(thread->framePtr);
+			thread->framePtr = thread->stackPtr;
 			param1 = scriptS.readUint16LE();
+			thread->stackPtr -= (param1 / 2);
 			break;
 		case 0x1B: // Return with value
-			unhandled = 1;
-			break;
+			scriptRetVal = thread->pop();
+			// FALL THROUGH
 		case 0x1C: // Return with void
+			thread->stackPtr = thread->framePtr;
+			thread->framePtr = thread->pop();
 			if (thread->stackSize() == 0) {
 				_vm->_console->print("Script execution complete.");
 				thread->executing = 0;
 			} else {
-				data = thread->pop();
+				thread->i_offset = thread->pop();
 				/* int n_args = */ thread->pop();
-				thread->i_offset = data;
+				if (in_char == 0x1B)
+					thread->push(scriptRetVal);
 			}
 			break;
 
@@ -724,18 +729,14 @@
 			// (DLGO): Add a dialogue option to interface
 		case 0x56:
 			{
-				int FIXME_SHADOWED_param1;
-				int FIXME_SHADOWED_param2;
-				int FIXME_SHADOWED_param3;
-
 				printf("DLGO | ");
-				FIXME_SHADOWED_param1 = scriptS.readByte();
-				FIXME_SHADOWED_param2 = scriptS.readByte();
-				printf("%02X %02X ", FIXME_SHADOWED_param1, FIXME_SHADOWED_param2);
+				param1 = scriptS.readByte();
+				param2 = scriptS.readByte();
+				printf("%02X %02X ", param1, param2);
 
-				if (FIXME_SHADOWED_param2 > 0) {
-					FIXME_SHADOWED_param3 = scriptS.readUint16LE();
-					printf("%04X", FIXME_SHADOWED_param3);
+				if (param2 > 0) {
+					SDataWord_T param3 = scriptS.readUint16LE();
+					printf("%04X", param3);
 				}
 			}
 			break;





More information about the Scummvm-git-logs mailing list