From ff1cf82089751a6b11d2397115acb91e2baa00c8 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sun, 3 Oct 2004 17:11:23 +0000 Subject: 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. svn-id: r15393 --- saga/script.h | 2 ++ saga/sfuncs.cpp | 9 ++++++--- saga/sthread.cpp | 51 ++++++++++++++++++++++++++------------------------- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/saga/script.h b/saga/script.h index 003299b4ef..91f4317964 100644 --- a/saga/script.h +++ b/saga/script.h @@ -87,6 +87,8 @@ struct R_SCRIPT_THREAD { int stackPtr; int framePtr; + SDataWord_T retVal; + SDataWord_T stackTop() { return stackBuf[stackPtr]; } diff --git a/saga/sfuncs.cpp b/saga/sfuncs.cpp index c2e7fae026..bb45c72048 100644 --- a/saga/sfuncs.cpp +++ b/saga/sfuncs.cpp @@ -149,8 +149,11 @@ int Script::SF_objectIsCarried(R_SCRIPTFUNC_PARAMS) { // 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 @@ int Script::SF_placeActor(R_SCRIPTFUNC_PARAMS) { // 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 diff --git a/saga/sthread.cpp b/saga/sthread.cpp index a3b7584f02..68adc7e565 100644 --- a/saga/sthread.cpp +++ b/saga/sthread.cpp @@ -177,6 +177,7 @@ int Script::SThreadRun(R_SCRIPT_THREAD *thread, int instr_limit, int msec) { long iresult; SDataWord_T data; + SDataWord_T scriptRetVal = 0; int debug_print = 0; int n_buf; int bitstate; @@ -296,8 +297,7 @@ int Script::SThreadRun(R_SCRIPT_THREAD *thread, int instr_limit, int msec) { // CONTROL INSTRUCTIONS - // (GOSB): Call subscript ? - case 0x17: + case 0x17: // (GOSB): Call subscript { int n_args; int temp; @@ -316,13 +316,12 @@ int Script::SThreadRun(R_SCRIPT_THREAD *thread, int instr_limit, int msec) { 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 @@ int Script::SThreadRun(R_SCRIPT_THREAD *thread, int instr_limit, int msec) { 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 @@ int Script::SThreadRun(R_SCRIPT_THREAD *thread, int instr_limit, int msec) { // (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; -- cgit v1.2.3