aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorSven Hesse2009-06-15 23:07:38 +0000
committerSven Hesse2009-06-15 23:07:38 +0000
commit0906068bff35787c1fca599774ba2f062ae2a3cf (patch)
tree3e25aca82d793de801b6429bc71bcd876c673801 /engines
parent650f3a50d2acd1962501e9082e946e7ffa13ae13 (diff)
downloadscummvm-rg350-0906068bff35787c1fca599774ba2f062ae2a3cf.tar.gz
scummvm-rg350-0906068bff35787c1fca599774ba2f062ae2a3cf.tar.bz2
scummvm-rg350-0906068bff35787c1fca599774ba2f062ae2a3cf.zip
Merging parseValExpr and parseExpr
svn-id: r41562
Diffstat (limited to 'engines')
-rw-r--r--engines/gob/parse.cpp292
1 files changed, 2 insertions, 290 deletions
diff --git a/engines/gob/parse.cpp b/engines/gob/parse.cpp
index 0fa46097a3..cd70ceff5d 100644
--- a/engines/gob/parse.cpp
+++ b/engines/gob/parse.cpp
@@ -612,297 +612,9 @@ int16 Parse::parseVarIndex(uint16 *arg_0, uint16 *arg_4) {
}
int16 Parse::parseValExpr(byte stopToken) {
- int16 values[20];
- byte operStack[20];
- int16 *valPtr;
- byte *operPtr;
- byte *arrDesc;
- byte operation;
- int16 temp2;
- int16 dim;
- int16 dimCount;
- int16 temp;
- int16 offset;
- int16 stkPos;
- int16 brackPos;
- static int16 flag = 0;
- int16 oldflag;
- uint32 varPos = 0;
-
- memset(values, 0, 20 * sizeof(int16));
-
- oldflag = flag;
- if (flag == 0) {
- flag = 1;
- printExpr(stopToken);
- }
-
- stkPos = -1;
- operPtr = operStack - 1;
- valPtr = values - 1;
-
- while (1) {
- operation = *_vm->_global->_inter_execPtr++;
-
- while ((operation == 14) || (operation == 15)) {
- if (operation == 14) {
- uint16 n = _vm->_inter->load16();
- varPos += n * 4;
-
- _vm->_global->_inter_execPtr += 3;
- } else if (operation == 15) {
- uint16 n = _vm->_inter->load16();
- varPos += n * 4;
-
- uint16 var_0C = _vm->_inter->load16();
- uint8 var_A = *_vm->_global->_inter_execPtr++;
-
- byte *var_12 = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr += var_A;
-
- uint16 var_6 = 0;
-
- for (int i = 0; i < var_A; i++) {
- temp2 = parseValExpr(OP_END_MARKER);
-
- int16 ax = getOffset(temp2, var_12[i], varPos, 0, 0);
-
- var_6 = var_6 * var_12[i] + ax;
- }
-
- varPos += var_6 * var_0C * 4;
-
- _vm->_global->_inter_execPtr++;
- }
-
- debugC(2, kDebugParser, "parseValExpr: Prefix %d (%d)", varPos, operation);
-
- operation = *_vm->_global->_inter_execPtr++;
- }
-
- stkPos++;
- operPtr++;
- valPtr++;
-
- if ((operation >= OP_ARRAY_UINT8) && (operation <= OP_FUNC)) {
- *operPtr = OP_LOAD_IMM_INT16;
- switch (operation) {
- case OP_ARRAY_UINT8:
- case OP_ARRAY_UINT32:
- case OP_ARRAY_UINT16:
- case OP_ARRAY_STR:
- temp = _vm->_inter->load16();
- dimCount = *_vm->_global->_inter_execPtr++;
- arrDesc = _vm->_global->_inter_execPtr;
- _vm->_global->_inter_execPtr += dimCount;
- offset = 0;
- for (dim = 0; dim < dimCount; dim++) {
- temp2 = parseValExpr(OP_END_MARKER);
- offset = arrDesc[dim] * offset + temp2;
- }
- if (operation == OP_ARRAY_UINT8)
- *valPtr = (int8) READ_VARO_UINT8(varPos + temp + offset);
- else if (operation == OP_ARRAY_UINT32)
- *valPtr = (uint16) READ_VARO_UINT32(varPos + temp * 4 + offset * 4);
- else if (operation == OP_ARRAY_UINT16)
- *valPtr = READ_VARO_UINT16(varPos + temp * 2 + offset * 2);
- else if (operation == OP_ARRAY_STR) {
- _vm->_global->_inter_execPtr++;
- temp2 = parseValExpr(OP_END_MARKER);
- *valPtr = READ_VARO_UINT8(varPos + temp * 4 +
- offset * 4 * _vm->_global->_inter_animDataSize + temp2);
- }
- break;
-
- case OP_LOAD_VAR_INT16:
- *valPtr = READ_VARO_UINT16(varPos + _vm->_inter->load16() * 2);
- break;
-
- case OP_LOAD_VAR_INT8:
- *valPtr = (int8) READ_VARO_UINT8(varPos + _vm->_inter->load16());
- break;
-
- case OP_LOAD_IMM_INT32:
- *valPtr = (uint16) READ_LE_UINT32(varPos + _vm->_global->_inter_execPtr);
- _vm->_global->_inter_execPtr += 4;
- break;
-
- case OP_LOAD_IMM_INT16:
- *valPtr = _vm->_inter->load16();
- break;
-
- case OP_LOAD_IMM_INT8:
- *valPtr = (int8) *_vm->_global->_inter_execPtr++;
- break;
+ parseExpr(stopToken, 0);
- case 23:
- *valPtr = (uint16) READ_VARO_UINT32(varPos + _vm->_inter->load16() * 4);
- break;
-
- case 24:
- *valPtr = READ_VARO_UINT16(varPos + _vm->_inter->load16() * 4);
- break;
-
- case OP_LOAD_VAR_STR:
- temp = _vm->_inter->load16() * 4;
- _vm->_global->_inter_execPtr++;
- temp += parseValExpr(OP_END_MARKER);
- *valPtr = READ_VARO_UINT8(varPos + temp);
- break;
-
- case OP_FUNC:
- operation = *_vm->_global->_inter_execPtr++;
- parseExpr(OP_END_EXPR, 0);
-
- if (operation == FUNC_SQR) {
- _vm->_global->_inter_resVal =
- _vm->_global->_inter_resVal * _vm->_global->_inter_resVal;
- } else if (operation == FUNC_ABS) {
- if (_vm->_global->_inter_resVal < 0)
- _vm->_global->_inter_resVal = -_vm->_global->_inter_resVal;
- } else if (operation == FUNC_RAND) {
- _vm->_global->_inter_resVal =
- _vm->_util->getRandom(_vm->_global->_inter_resVal);
- }
- *valPtr = _vm->_global->_inter_resVal;
- break;
-
- } // switch
- if ((stkPos > 0) && (operPtr[-1] == OP_NEG)) {
- stkPos--;
- operPtr--;
- valPtr--;
- operPtr[0] = OP_LOAD_IMM_INT16;
- valPtr[0] = -valPtr[1];
- }
-
- if ((stkPos > 0) && (operPtr[-1] >= OP_MUL) && (operPtr[-1] <= OP_BITAND)) {
- stkPos -= 2;
- operPtr -= 2;
- valPtr -= 2;
-
- switch (operPtr[1]) {
- case OP_MUL:
- valPtr[0] *= valPtr[2];
- break;
-
- case OP_DIV:
- valPtr[0] /= valPtr[2];
- break;
-
- case OP_MOD:
- valPtr[0] %= valPtr[2];
- break;
-
- case OP_BITAND:
- valPtr[0] &= valPtr[2];
- break;
- }
- } // if ((stkPos > 0) && (cmdPtr[-1] >= OP_MUL) && (cmdPtr[-1] <= OP_BITAND))
- varPos = 0;
- continue;
- }
-
- if ((operation >= OP_NEG) && (operation <= OP_BEGIN_EXPR)) {
- *operPtr = operation;
- continue;
- }
-
- while (stkPos >= 2) {
- if (operPtr[-2] == OP_BEGIN_EXPR) {
- stkPos--;
- operPtr--;
- valPtr--;
-
- operPtr[-1] = operPtr[0];
- valPtr[-1] = valPtr[0];
- if ((stkPos > 1) && (operPtr[-2] == OP_NEG)) {
- operPtr[-2] = OP_LOAD_IMM_INT16;
- valPtr[-2] = -valPtr[-1];
-
- stkPos--;
- operPtr--;
- valPtr--;
- }
-
- if ((stkPos > 2) && (operPtr[-2] >= OP_MUL) && (operPtr[-2] <= OP_BITAND)) {
- stkPos -= 2;
- operPtr -= 2;
- valPtr -= 2;
- switch (operPtr[0]) {
- case OP_MUL:
- valPtr[-1] *= valPtr[1];
- break;
-
- case OP_DIV:
- valPtr[-1] /= valPtr[1];
- break;
-
- case OP_MOD:
- valPtr[-1] %= valPtr[1];
- break;
-
- case OP_BITAND:
- valPtr[-1] &= valPtr[1];
- break;
- }
- }
- if (operation == OP_END_EXPR)
- break;
- } // operPtr[-2] == OP_BEGIN_EXPR
-
- for (brackPos = (stkPos - 2); (brackPos > 0) &&
- (operStack[brackPos] < OP_OR) && (operStack[brackPos] != OP_BEGIN_EXPR);
- brackPos--)
- ;
-
- if ((operStack[brackPos] >= OP_OR) || (operStack[brackPos] == OP_BEGIN_EXPR))
- brackPos++;
-
- if ((operPtr[-2] < 2) || (operPtr[-2] > 8))
- break;
-
- stkPos -= 2;
- operPtr -= 2;
- valPtr -= 2;
- switch (operPtr[0]) {
- case OP_ADD:
- values[brackPos] += valPtr[1];
- continue;
- case OP_SUB:
- values[brackPos] -= valPtr[1];
- continue;
- case OP_BITOR:
- values[brackPos] |= valPtr[1];
- continue;
- case OP_MUL:
- valPtr[-1] *= valPtr[1];
- continue;
- case OP_DIV:
- valPtr[-1] /= valPtr[1];
- continue;
- case OP_MOD:
- valPtr[-1] %= valPtr[1];
- continue;
- case OP_BITAND:
- valPtr[-1] &= valPtr[1];
- continue;
- }
- }
-
- if (operation != OP_END_EXPR) {
- if (operation != stopToken) {
- debugC(5, kDebugParser, "stoptoken error: %d != %d",
- operation, stopToken);
- }
- flag = oldflag;
- return values[0];
- }
-
- stkPos--;
- operPtr--;
- valPtr--;
- }
+ return _vm->_global->_inter_resVal;
}
int16 Parse::parseExpr(byte stopToken, byte *arg_2) {