mirror of
https://github.com/libretro/scummvm.git
synced 2025-04-10 18:51:23 +00:00
another 19 opcodes
svn-id: r16616
This commit is contained in:
parent
4e7d58c843
commit
0030e821fe
@ -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;
|
||||
|
@ -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
|
||||
|
249
saga/sthread.cpp
249
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
|
||||
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;
|
||||
|
||||
// (ADD): Addition
|
||||
case 0x2C:
|
||||
param2 = thread->pop();
|
||||
param1 = thread->pop();
|
||||
iparam2 = (long)param2;
|
||||
iparam1 = (long)param1;
|
||||
iresult = iparam1 + iparam2;
|
||||
thread->push(iresult);
|
||||
// COMPARISION INSTRUCTIONS
|
||||
CASEOP(opEq)
|
||||
iparam2 = thread->pop();
|
||||
iparam1 = thread->pop();
|
||||
thread->push((iparam1 == iparam2) ? 1 : 0);
|
||||
break;
|
||||
// (SUB): Subtraction
|
||||
case 0x2D:
|
||||
param2 = thread->pop();
|
||||
param1 = thread->pop();
|
||||
iparam2 = (long)param2;
|
||||
iparam1 = (long)param1;
|
||||
iresult = iparam1 - iparam2;
|
||||
thread->push(iresult);
|
||||
CASEOP(opNe)
|
||||
iparam2 = thread->pop();
|
||||
iparam1 = thread->pop();
|
||||
thread->push((iparam1 != iparam2) ? 1 : 0);
|
||||
break;
|
||||
// (MULT): Integer multiplication
|
||||
case 0x2E:
|
||||
param2 = thread->pop();
|
||||
param1 = thread->pop();
|
||||
iparam2 = (long)param2;
|
||||
iparam1 = (long)param1;
|
||||
iresult = iparam1 * iparam2;
|
||||
thread->push(iresult);
|
||||
CASEOP(opGt)
|
||||
iparam2 = thread->pop();
|
||||
iparam1 = thread->pop();
|
||||
thread->push((iparam1 > iparam2) ? 1 : 0);
|
||||
break;
|
||||
// (DIV): Integer division
|
||||
case 0x2F:
|
||||
param2 = thread->pop();
|
||||
param1 = thread->pop();
|
||||
iparam2 = (long)param2;
|
||||
iparam1 = (long)param1;
|
||||
iresult = iparam1 / iparam2;
|
||||
thread->push(iresult);
|
||||
CASEOP(opLt)
|
||||
iparam2 = thread->pop();
|
||||
iparam1 = thread->pop();
|
||||
thread->push((iparam1 < iparam2) ? 1 : 0);
|
||||
break;
|
||||
// (MOD) Modulus
|
||||
case 0x30:
|
||||
param2 = thread->pop();
|
||||
param1 = thread->pop();
|
||||
iparam2 = (long)param2;
|
||||
iparam1 = (long)param1;
|
||||
iresult = iparam1 % iparam2;
|
||||
thread->push(iresult);
|
||||
CASEOP(opGe)
|
||||
iparam2 = thread->pop();
|
||||
iparam1 = thread->pop();
|
||||
thread->push((iparam1 >= iparam2) ? 1 : 0);
|
||||
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);
|
||||
CASEOP(opLe)
|
||||
iparam2 = thread->pop();
|
||||
iparam1 = thread->pop();
|
||||
thread->push((iparam1 <= iparam2) ? 1 : 0);
|
||||
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);
|
||||
|
||||
// SHIFT INSTRUCTIONS
|
||||
CASEOP(opRsh)
|
||||
iparam2 = thread->pop();
|
||||
iparam1 = thread->pop();
|
||||
iparam1 >>= iparam2;
|
||||
thread->push(iparam1);
|
||||
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(opLsh)
|
||||
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);
|
||||
CASEOP(opAnd)
|
||||
iparam2 = thread->pop();
|
||||
iparam1 = thread->pop();
|
||||
iparam1 &= iparam2;
|
||||
thread->push(iparam1);
|
||||
break;
|
||||
// (SHL) Binary shift left
|
||||
case 0x40:
|
||||
param2 = thread->pop();
|
||||
param1 = thread->pop();
|
||||
param1 <<= param2;
|
||||
thread->push(param1);
|
||||
CASEOP(opOr)
|
||||
iparam2 = thread->pop();
|
||||
iparam1 = thread->pop();
|
||||
iparam1 |= iparam2;
|
||||
thread->push(iparam1);
|
||||
break;
|
||||
// (AND) Binary AND
|
||||
case 0x41:
|
||||
param2 = thread->pop();
|
||||
param1 = thread->pop();
|
||||
param1 &= param2;
|
||||
thread->push(param1);
|
||||
break;
|
||||
// (OR) Binary OR
|
||||
case 0x42:
|
||||
param2 = thread->pop();
|
||||
param1 = thread->pop();
|
||||
param1 |= param2;
|
||||
thread->push(param1);
|
||||
break;
|
||||
// (XOR) Binary XOR
|
||||
case 0x43:
|
||||
param2 = thread->pop();
|
||||
param1 = thread->pop();
|
||||
param1 ^= param2;
|
||||
thread->push(param1);
|
||||
CASEOP(opXor)
|
||||
iparam2 = thread->pop();
|
||||
iparam1 = thread->pop();
|
||||
iparam1 ^= iparam2;
|
||||
thread->push(iparam1);
|
||||
break;
|
||||
|
||||
// BOOLEAN LOGIC INSTRUCTIONS
|
||||
|
||||
// (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
|
||||
|
Loading…
x
Reference in New Issue
Block a user