diff options
author | Andrew Kurushin | 2005-01-22 15:28:24 +0000 |
---|---|---|
committer | Andrew Kurushin | 2005-01-22 15:28:24 +0000 |
commit | 0030e821fe0e417d96387d52ba0c6acf56f93cfe (patch) | |
tree | 111538bf3b7c9fd5c97f3b3a884b15f95dad4f9d | |
parent | 4e7d58c843680463b3c4d2cf39aa415dcfe024e5 (diff) | |
download | scummvm-rg350-0030e821fe0e417d96387d52ba0c6acf56f93cfe.tar.gz scummvm-rg350-0030e821fe0e417d96387d52ba0c6acf56f93cfe.tar.bz2 scummvm-rg350-0030e821fe0e417d96387d52ba0c6acf56f93cfe.zip |
another 19 opcodes
svn-id: r16616
-rw-r--r-- | saga/script.cpp | 86 | ||||
-rw-r--r-- | saga/script.h | 45 | ||||
-rw-r--r-- | saga/sthread.cpp | 261 |
3 files changed, 124 insertions, 268 deletions
diff --git a/saga/script.cpp b/saga/script.cpp index 3ebc7af395..dd775608d0 100644 --- a/saga/script.cpp +++ b/saga/script.cpp @@ -170,92 +170,6 @@ Script::~Script() { _initialized = false; } -/* -int Script::getWord(int bufNumber, int wordNumber, ScriptDataWord *data) { - if ((bufNumber < 0) || (bufNumber >= SCRIPT_DATABUF_NUM)) { - return FAILURE; - } - - if ((wordNumber < 0) || (wordNumber >= _dataBuf[bufNumber].length)) { - return FAILURE; - } - - if (data == NULL) { - return FAILURE; - } - - *data = _dataBuf[bufNumber].data[wordNumber]; - - return SUCCESS; -} - -int Script::putWord(int bufNumber, int wordNumber, ScriptDataWord data) { - if ((bufNumber < 0) || (bufNumber >= SCRIPT_DATABUF_NUM)) { - return FAILURE; - } - - if ((wordNumber < 0) || (wordNumber >= _dataBuf[bufNumber].length)) { - return FAILURE; - } - - _dataBuf[bufNumber].data[wordNumber] = data; - - return SUCCESS; -} - -int Script::setBit(int bufNumber, ScriptDataWord bitNumber, int bitState) { - int wordNumber; - int bitPos; - - ScriptDataWord bitPattern = 0x01; - - if ((bufNumber < 0) || (bufNumber >= SCRIPT_DATABUF_NUM)) { - return FAILURE; - } - - if (bitNumber >= (unsigned long)_dataBuf[bufNumber].length * (sizeof(ScriptDataWord) * CHAR_BIT)) { - return FAILURE; - } - - wordNumber = bitNumber / (sizeof(ScriptDataWord) * CHAR_BIT); - bitPos = bitNumber % (sizeof(ScriptDataWord) * CHAR_BIT); - - bitPattern <<= ((sizeof(ScriptDataWord) * CHAR_BIT) - (bitPos + 1)); - - if (bitState) { - _dataBuf[bufNumber].data[wordNumber] |= bitPattern; - } else { - _dataBuf[bufNumber].data[wordNumber] &= ~bitPattern; - } - - return SUCCESS; -} - -int Script::getBit(int bufNumber, ScriptDataWord bitNumber, int *bitState) { - int wordNumber; - int bitPos; - - ScriptDataWord bitPattern = 0x01; - - if ((bufNumber < 0) || (bufNumber >= SCRIPT_DATABUF_NUM)) { - return FAILURE; - } - - if (bitNumber >= (unsigned long)_dataBuf[bufNumber].length * (sizeof(ScriptDataWord) * CHAR_BIT)) { - return FAILURE; - } - - wordNumber = bitNumber / (sizeof(ScriptDataWord) * CHAR_BIT); - bitPos = bitNumber % (sizeof(ScriptDataWord) * CHAR_BIT); - - bitPattern <<= ((sizeof(ScriptDataWord) * CHAR_BIT) - (bitPos + 1)); - - - *bitState = (_dataBuf[bufNumber].data[wordNumber] & bitPattern) ? 1 : 0; - - return SUCCESS; -} -*/ void Script::loadModule(int scriptModuleNumber) { byte *resourcePointer; diff --git a/saga/script.h b/saga/script.h index ed58dffaf5..ffc3dca69a 100644 --- a/saga/script.h +++ b/saga/script.h @@ -152,6 +152,27 @@ enum OpCodes { opDecV = 0x29, opPostInc = 0x2A, opPostDec = 0x2B, + opAdd = 0x2C, + opSub = 0x2D, + opMul = 0x2E, + opDiv = 0x2F, + opMod = 0x30, +//... + opEq = 0x33, + opNe = 0x34, + opGt = 0x35, + opLt = 0x36, + opGe = 0x37, + opLe = 0x38, +//... + opRsh = 0x3F, + opLsh = 0x40, + opAnd = 0x41, + opOr = 0x42, + opXor = 0x43, + opLAnd = 0x44, + opLOr = 0x45, + opLXor = 0x46, //... opSpeak = 0x53, @@ -332,12 +353,6 @@ public: bool isInitialized() const { return _initialized; } bool isVoiceLUTPresent() const { return _voiceLUTPresent; } -/* ScriptData *currentScript() { return _currentScript; } - int getWord(int bufNumber, int wordNumber, ScriptDataWord *data); - int putWord(int bufNumber, int wordNumber, ScriptDataWord data); - int setBit(int bufNumber, ScriptDataWord bitNumber, int bitState); - int getBit(int bufNumber, ScriptDataWord bitNumber, int *bitState); */ -// const char * getScriptString(int index) const { return _currentScript->strings.getString(index); } void doVerb(); void showVerb(int statuscolor = -1); @@ -521,24 +536,6 @@ private: int SF_playVoice(SCRIPTFUNC_PARAMS); }; -/*inline int getSWord(ScriptDataWord word) { - uint16 uInt = word; - int sInt; - - if (uInt & 0x8000U) { - sInt = (int)(uInt - 0x8000U) - 0x7FFF - 1; - } else { - sInt = uInt; - } - - return sInt; -} - -inline uint getUWord(ScriptDataWord word) { - return (uint16) word; -} -*/ - } // End of namespace Saga #endif diff --git a/saga/sthread.cpp b/saga/sthread.cpp index ca2e106bbe..400efe766d 100644 --- a/saga/sthread.cpp +++ b/saga/sthread.cpp @@ -174,7 +174,7 @@ void Script::runThread(ScriptThread *thread, uint instructionLimit) { uint16 param2; int16 iparam1; int16 iparam2; - long iresult; +// long iresult; byte argumentsCount; uint16 functionNumber; @@ -294,7 +294,7 @@ void Script::runThread(ScriptThread *thread, uint instructionLimit) { *(uint16*)addr = thread->pop(); break; -// CONTROL INSTRUCTIONS +// FUNCTION CALL INSTRUCTIONS CASEOP(opCall) argumentsCount = scriptS.readByte(); param1 = scriptS.readByte(); @@ -467,173 +467,118 @@ void Script::runThread(ScriptThread *thread, uint instructionLimit) { break; // ARITHMETIC INSTRUCTIONS - - // (ADD): Addition - case 0x2C: - param2 = thread->pop(); - param1 = thread->pop(); - iparam2 = (long)param2; - iparam1 = (long)param1; - iresult = iparam1 + iparam2; - thread->push(iresult); - break; - // (SUB): Subtraction - case 0x2D: - param2 = thread->pop(); - param1 = thread->pop(); - iparam2 = (long)param2; - iparam1 = (long)param1; - iresult = iparam1 - iparam2; - thread->push(iresult); - break; - // (MULT): Integer multiplication - case 0x2E: - param2 = thread->pop(); - param1 = thread->pop(); - iparam2 = (long)param2; - iparam1 = (long)param1; - iresult = iparam1 * iparam2; - thread->push(iresult); - break; - // (DIV): Integer division - case 0x2F: - param2 = thread->pop(); - param1 = thread->pop(); - iparam2 = (long)param2; - iparam1 = (long)param1; - iresult = iparam1 / iparam2; - thread->push(iresult); - break; - // (MOD) Modulus - case 0x30: - param2 = thread->pop(); - param1 = thread->pop(); - iparam2 = (long)param2; - iparam1 = (long)param1; - iresult = iparam1 % iparam2; - thread->push(iresult); - break; - // (EQU) Test equality - case 0x33: - param2 = thread->pop(); - param1 = thread->pop(); - iparam2 = (long)param2; - iparam1 = (long)param1; - data = (iparam1 == iparam2) ? 1 : 0; - thread->push(data); - break; - // (NEQU) Test inequality - case 0x34: - param2 = thread->pop(); - param1 = thread->pop(); - iparam2 = (long)param2; - iparam1 = (long)param1; - data = (iparam1 != iparam2) ? 1 : 0; - thread->push(data); - break; - // (GRT) Test Greater-than - case 0x35: - param2 = thread->pop(); - param1 = thread->pop(); - iparam2 = (long)param2; - iparam1 = (long)param1; - data = (iparam1 > iparam2) ? 1 : 0; - thread->push(data); - break; - // (LST) Test Less-than - case 0x36: - param2 = thread->pop(); - param1 = thread->pop(); - iparam2 = (long)param2; - iparam1 = (long)param1; - data = (iparam1 < iparam2) ? 1 : 0; - thread->push(data); - break; - // (GRTE) Test Greater-than or Equal to - case 0x37: - param2 = thread->pop(); - param1 = thread->pop(); - iparam2 = (long)param2; - iparam1 = (long)param1; - data = (iparam1 >= iparam2) ? 1 : 0; - thread->push(data); - break; - // (LSTE) Test Less-than or Equal to - case 0x38: - param2 = thread->pop(); - param1 = thread->pop(); - iparam2 = (long)param2; - iparam1 = (long)param1; - data = (iparam1 <= iparam2) ? 1 : 0; - thread->push(data); + CASEOP(opAdd) + iparam2 = thread->pop(); + iparam1 = thread->pop(); + iparam1 += iparam2; + thread->push(iparam1); + break; + CASEOP(opSub) + iparam2 = thread->pop(); + iparam1 = thread->pop(); + iparam1 -= iparam2; + thread->push(iparam1); + break; + CASEOP(opMul) + iparam2 = thread->pop(); + iparam1 = thread->pop(); + iparam1 *= iparam2; + thread->push(iparam1); + break; + CASEOP(opDiv) + iparam2 = thread->pop(); + iparam1 = thread->pop(); + iparam1 /= iparam2; + thread->push(iparam1); + break; + CASEOP(opMod) + iparam2 = thread->pop(); + iparam1 = thread->pop(); + iparam1 %= iparam2; + thread->push(iparam1); break; -// BITWISE INSTRUCTIONS - - // (SHR): Arithmetic binary shift right - case 0x3F: - param2 = thread->pop(); - param1 = thread->pop(); - iparam2 = (long)param2; - // Preserve most significant bit - data = (0x01 << ((sizeof(param1) * CHAR_BIT) - 1)) & param1; - for (i = 0; i < (int)iparam2; i++) { - param1 >>= 1; - param1 |= data; - } - thread->push(param1); +// COMPARISION INSTRUCTIONS + CASEOP(opEq) + iparam2 = thread->pop(); + iparam1 = thread->pop(); + thread->push((iparam1 == iparam2) ? 1 : 0); break; - // (SHL) Binary shift left - case 0x40: - param2 = thread->pop(); - param1 = thread->pop(); - param1 <<= param2; - thread->push(param1); + CASEOP(opNe) + iparam2 = thread->pop(); + iparam1 = thread->pop(); + thread->push((iparam1 != iparam2) ? 1 : 0); break; - // (AND) Binary AND - case 0x41: - param2 = thread->pop(); - param1 = thread->pop(); - param1 &= param2; - thread->push(param1); + CASEOP(opGt) + iparam2 = thread->pop(); + iparam1 = thread->pop(); + thread->push((iparam1 > iparam2) ? 1 : 0); break; - // (OR) Binary OR - case 0x42: - param2 = thread->pop(); - param1 = thread->pop(); - param1 |= param2; - thread->push(param1); + CASEOP(opLt) + iparam2 = thread->pop(); + iparam1 = thread->pop(); + thread->push((iparam1 < iparam2) ? 1 : 0); break; - // (XOR) Binary XOR - case 0x43: - param2 = thread->pop(); - param1 = thread->pop(); - param1 ^= param2; - thread->push(param1); + CASEOP(opGe) + iparam2 = thread->pop(); + iparam1 = thread->pop(); + thread->push((iparam1 >= iparam2) ? 1 : 0); + break; + CASEOP(opLe) + iparam2 = thread->pop(); + iparam1 = thread->pop(); + thread->push((iparam1 <= iparam2) ? 1 : 0); + break; + +// SHIFT INSTRUCTIONS + CASEOP(opRsh) + iparam2 = thread->pop(); + iparam1 = thread->pop(); + iparam1 >>= iparam2; + thread->push(iparam1); + break; + CASEOP(opLsh) + iparam2 = thread->pop(); + iparam1 = thread->pop(); + iparam1 <<= iparam2; + thread->push(iparam1); break; -// BOOLEAN LOGIC INSTRUCTIONS +// BITWISE INSTRUCTIONS + CASEOP(opAnd) + iparam2 = thread->pop(); + iparam1 = thread->pop(); + iparam1 &= iparam2; + thread->push(iparam1); + break; + CASEOP(opOr) + iparam2 = thread->pop(); + iparam1 = thread->pop(); + iparam1 |= iparam2; + thread->push(iparam1); + break; + CASEOP(opXor) + iparam2 = thread->pop(); + iparam1 = thread->pop(); + iparam1 ^= iparam2; + thread->push(iparam1); + break; - // (LAND): Logical AND - case 0x44: - param2 = thread->pop(); - param1 = thread->pop(); - data = (param1 && param2) ? 1 : 0; - thread->push(data); +// LOGICAL INSTRUCTIONS + CASEOP(opLAnd) + iparam2 = thread->pop(); + iparam1 = thread->pop(); + thread->push((iparam1 && iparam2) ? 1 : 0); break; - // (LOR): Logical OR - case 0x45: - param2 = thread->pop(); - param1 = thread->pop(); - data = (param1 || param2) ? 1 : 0; - thread->push(data); + CASEOP(opLOr) + iparam2 = thread->pop(); + iparam1 = thread->pop(); + thread->push((iparam1 || iparam2) ? 1 : 0); break; - // (LXOR): Logical XOR - case 0x46: - param2 = thread->pop(); - param1 = thread->pop(); - data = ((param1) ? !(param2) : !!(param2)); - thread->push(data); + CASEOP(opLXor) + iparam2 = thread->pop(); + iparam1 = thread->pop(); + thread->push(((iparam1 && !iparam2) || (!iparam1 && iparam2)) ? 1 : 0); break; // GAME INSTRUCTIONS |