diff options
-rw-r--r-- | engines/gob/parse.cpp | 17 | ||||
-rw-r--r-- | engines/gob/parse.h | 2 | ||||
-rw-r--r-- | engines/gob/parse_v1.cpp | 93 | ||||
-rw-r--r-- | engines/gob/parse_v2.cpp | 97 |
4 files changed, 47 insertions, 162 deletions
diff --git a/engines/gob/parse.cpp b/engines/gob/parse.cpp index adff890507..3dfcc0bb47 100644 --- a/engines/gob/parse.cpp +++ b/engines/gob/parse.cpp @@ -456,4 +456,21 @@ void Parse::printVarIndex() { return; } +int Parse::cmpHelper(byte *operPtr, int32 *valPtr) { + byte var_C = operPtr[-3]; + int cmpTemp; + if (var_C == 20) { + cmpTemp = (int)valPtr[-3] - (int)valPtr[-1]; + } else if (var_C == 22) { + if ((char *)decodePtr(valPtr[-3]) != _vm->_global->_inter_resStr) { + strcpy(_vm->_global->_inter_resStr, (char *)decodePtr(valPtr[-3])); + valPtr[-3] = encodePtr((byte *) _vm->_global->_inter_resStr, kResStr); + } + cmpTemp = strcmp(_vm->_global->_inter_resStr, (char *)decodePtr(valPtr[-1])); + } + + return cmpTemp; +} + + } // End of namespace Gob diff --git a/engines/gob/parse.h b/engines/gob/parse.h index 738c956796..9bd8f6afab 100644 --- a/engines/gob/parse.h +++ b/engines/gob/parse.h @@ -63,6 +63,8 @@ protected: byte *decodePtr(int32 n); void printExpr_internal(char stopToken); + + int cmpHelper(byte *operPtr, int32 *valPtr); }; class Parse_v1 : public Parse { diff --git a/engines/gob/parse_v1.cpp b/engines/gob/parse_v1.cpp index f1b9ebbe7e..d25b2beb23 100644 --- a/engines/gob/parse_v1.cpp +++ b/engines/gob/parse_v1.cpp @@ -328,7 +328,6 @@ int16 Parse_v1::parseExpr(byte stopToken, byte *arg_2) { int32 *valPtr; byte *operPtr; byte *arrDescPtr; - byte var_C; byte operation; int16 dimCount; int16 temp; @@ -595,7 +594,7 @@ int16 Parse_v1::parseExpr(byte stopToken, byte *arg_2) { brackStart++; switch (operPtr[-2]) { - case 2: + case OP_ADD: if (operStack[brackStart] == 20) { values[brackStart] += valPtr[-1]; } else if (operStack[brackStart] == 22) { @@ -670,114 +669,42 @@ int16 Parse_v1::parseExpr(byte stopToken, byte *arg_2) { break; case 32: - var_C = operPtr[-3]; - operPtr[-3] = 23; - if (var_C == 20) { - if (valPtr[-3] < valPtr[-1]) - operPtr[-3] = 24; - } else if (var_C == 22) { - if ((char *) decodePtr(valPtr[-3]) != _vm->_global->_inter_resStr) { - strcpy(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr((byte *) _vm->_global->_inter_resStr, kResStr); - } - if (strcmp(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-1])) < 0) - operPtr[-3] = 24; - } + operPtr[-3] = (cmpHelper(operPtr, valPtr) < 0) ? 24 : 23; stkPos -= 2; operPtr -= 2; valPtr -= 2; break; case 33: - var_C = operPtr[-3]; - operPtr[-3] = 23; - if (var_C == 20) { - if (valPtr[-3] <= valPtr[-1]) - operPtr[-3] = 24; - } else if (var_C == 22) { - if ((char *) decodePtr(valPtr[-3]) != _vm->_global->_inter_resStr) { - strcpy(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr((byte *) _vm->_global->_inter_resStr, kResStr); - } - if (strcmp(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-1])) <= 0) - operPtr[-3] = 24; - } + operPtr[-3] = (cmpHelper(operPtr, valPtr) <= 0) ? 24 : 23; stkPos -= 2; operPtr -= 2; valPtr -= 2; break; case 34: - var_C = operPtr[-3]; - operPtr[-3] = 23; - if (var_C == 20) { - if (valPtr[-3] > valPtr[-1]) - operPtr[-3] = 24; - } else if (var_C == 22) { - if ((char *) decodePtr(valPtr[-3]) != _vm->_global->_inter_resStr) { - strcpy(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr((byte *) _vm->_global->_inter_resStr, kResStr); - } - if (strcmp(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-1])) > 0) - operPtr[-3] = 24; - } + operPtr[-3] = (cmpHelper(operPtr, valPtr) > 0) ? 24 : 23; stkPos -= 2; operPtr -= 2; valPtr -= 2; break; case 35: - var_C = operPtr[-3]; - operPtr[-3] = 23; - if (var_C == 20) { - if (valPtr[-3] >= valPtr[-1]) - operPtr[-3] = 24; - } else if (var_C == 22) { - if ((char *) decodePtr(valPtr[-3]) != _vm->_global->_inter_resStr) { - strcpy(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr((byte *) _vm->_global->_inter_resStr, kResStr); - } - if (strcmp(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-1])) >= 0) - operPtr[-3] = 24; - } + operPtr[-3] = (cmpHelper(operPtr, valPtr) >= 0) ? 24 : 23; stkPos -= 2; operPtr -= 2; valPtr -= 2; break; case 36: - var_C = operPtr[-3]; - operPtr[-3] = 23; - if (var_C == 20) { - if (valPtr[-3] == valPtr[-1]) - operPtr[-3] = 24; - } else if (var_C == 22) { - if ((char *) decodePtr(valPtr[-3]) != _vm->_global->_inter_resStr) { - strcpy(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr((byte *) _vm->_global->_inter_resStr, kResStr); - } - if (strcmp(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-1])) == 0) - operPtr[-3] = 24; - } + operPtr[-3] = (cmpHelper(operPtr, valPtr) == 0) ? 24 : 23; stkPos -= 2; operPtr -= 2; valPtr -= 2; break; case 37: - var_C = operPtr[-3]; - operPtr[-3] = 23; - if (var_C == 20) { - if (valPtr[-3] != valPtr[-1]) - operPtr[-3] = 24; - } else if (var_C == 22) { - if ((char *) decodePtr(valPtr[-3]) != _vm->_global->_inter_resStr) { - strcpy(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr((byte *) _vm->_global->_inter_resStr, kResStr); - } - if (strcmp(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-1])) != 0) - operPtr[-3] = 24; - } + operPtr[-3] = (cmpHelper(operPtr, valPtr) != 0) ? 24 : 23; stkPos -= 2; operPtr -= 2; valPtr -= 2; @@ -869,7 +796,7 @@ int16 Parse_v1::parseExpr(byte stopToken, byte *arg_2) { continue; if (stkPos > 2) { - if (operPtr[-2] == 2) { + if (operPtr[-2] == OP_ADD) { if (operPtr[-3] == 20) { valPtr[-3] += valPtr[-1]; } else if (operPtr[-3] == 22) { @@ -883,12 +810,12 @@ int16 Parse_v1::parseExpr(byte stopToken, byte *arg_2) { operPtr -= 2; valPtr -= 2; - } else if (operPtr[-2] == 3) { + } else if (operPtr[-2] == OP_SUB) { valPtr[-3] -= valPtr[-1]; stkPos -= 2; operPtr -= 2; valPtr -= 2; - } else if (operPtr[-2] == 4) { + } else if (operPtr[-2] == OP_BITOR) { valPtr[-3] |= valPtr[-1]; stkPos -= 2; operPtr -= 2; diff --git a/engines/gob/parse_v2.cpp b/engines/gob/parse_v2.cpp index 1e0617c3e7..1e06b26b5a 100644 --- a/engines/gob/parse_v2.cpp +++ b/engines/gob/parse_v2.cpp @@ -467,7 +467,6 @@ int16 Parse_v2::parseExpr(byte stopToken, byte *arg_2) { int32 *valPtr; byte *operPtr; byte *arrDescPtr; - byte var_C; byte operation; int16 dimCount; int16 temp; @@ -798,8 +797,10 @@ int16 Parse_v2::parseExpr(byte stopToken, byte *arg_2) { if ((operStack[brackStart] >= 30) || (operStack[brackStart] == 9)) brackStart++; + int cmpTemp; + switch (operPtr[-2]) { - case 2: + case OP_ADD: if (operStack[brackStart] == 20) { values[brackStart] += valPtr[-1]; } else if (operStack[brackStart] == 22) { @@ -874,115 +875,53 @@ int16 Parse_v2::parseExpr(byte stopToken, byte *arg_2) { break; case 32: - var_C = operPtr[-3]; - operPtr[-3] = 23; - if (var_C == 20) { - if (valPtr[-3] < valPtr[-1]) - operPtr[-3] = 24; - } else if (var_C == 22) { - if ((char *) decodePtr(valPtr[-3]) != _vm->_global->_inter_resStr) { - strcpy(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr((byte *) _vm->_global->_inter_resStr, kResStr); - } - if (strcmp(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-1])) < 0) - operPtr[-3] = 24; - } + operPtr[-3] = (cmpHelper(operPtr, valPtr) < 0) ? 24 : 23; stkPos -= 2; operPtr -= 2; valPtr -= 2; break; case 33: - var_C = operPtr[-3]; - operPtr[-3] = 23; - if (var_C == 20) { - if (valPtr[-3] <= valPtr[-1]) - operPtr[-3] = 24; - } else if (var_C == 22) { - if ((char *) decodePtr(valPtr[-3]) != _vm->_global->_inter_resStr) { - strcpy(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr((byte *) _vm->_global->_inter_resStr, kResStr); - } - if (strcmp(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-1])) <= 0) - operPtr[-3] = 24; - } + operPtr[-3] = (cmpHelper(operPtr, valPtr) <= 0) ? 24 : 23; stkPos -= 2; operPtr -= 2; valPtr -= 2; break; case 34: - var_C = operPtr[-3]; - operPtr[-3] = 23; - if (var_C == 20) { - if (valPtr[-3] > valPtr[-1]) - operPtr[-3] = 24; - } else if (var_C == 22) { - if ((char *) decodePtr(valPtr[-3]) != _vm->_global->_inter_resStr) { - strcpy(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr((byte *) _vm->_global->_inter_resStr, kResStr); - } - if (strcmp(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-1])) > 0) - operPtr[-3] = 24; - } + operPtr[-3] = (cmpHelper(operPtr, valPtr) > 0) ? 24 : 23; stkPos -= 2; operPtr -= 2; valPtr -= 2; break; case 35: - var_C = operPtr[-3]; - operPtr[-3] = 23; - if (var_C == 20) { - if (valPtr[-3] >= valPtr[-1]) - operPtr[-3] = 24; - } else if (var_C == 22) { - if ((char *) decodePtr(valPtr[-3]) != _vm->_global->_inter_resStr) { - strcpy(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr((byte *) _vm->_global->_inter_resStr, kResStr); - } - if (strcmp(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-1])) >= 0) - operPtr[-3] = 24; - } + operPtr[-3] = (cmpHelper(operPtr, valPtr) >= 0) ? 24 : 23; stkPos -= 2; operPtr -= 2; valPtr -= 2; break; case 36: - var_C = operPtr[-3]; - operPtr[-3] = 23; - if (var_C == 20) { - if (valPtr[-3] == valPtr[-1]) - operPtr[-3] = 24; - } else if (var_C == 22) { - if ((char *) decodePtr(valPtr[-3]) != _vm->_global->_inter_resStr) { - strcpy(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr((byte *) _vm->_global->_inter_resStr, kResStr); - } - if (strcmp(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-1])) == 0) - operPtr[-3] = 24; - } + operPtr[-3] = (cmpHelper(operPtr, valPtr) == 0) ? 24 : 23; stkPos -= 2; operPtr -= 2; valPtr -= 2; break; case 37: - var_C = operPtr[-3]; - operPtr[-3] = 23; - if (var_C == 20) { - if (valPtr[-3] != valPtr[-1]) - operPtr[-3] = 24; - } else if (var_C == 22) { + if (operPtr[-3] == 20) { + cmpTemp = valPtr[-3] - valPtr[-1]; + } else if (operPtr[-3] == 22) { if ((char *) decodePtr(valPtr[-3]) != _vm->_global->_inter_resStr) { strcpy(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-3])); valPtr[-3] = encodePtr((byte *) _vm->_global->_inter_resStr, kResStr); } - if (scumm_stricmp(_vm->_global->_inter_resStr, - (char *) decodePtr(valPtr[-1])) != 0) - operPtr[-3] = 24; + // FIXME: Why scumm_stricmp here and strcmp everywhere else? + cmpTemp = scumm_stricmp(_vm->_global->_inter_resStr, (char *) decodePtr(valPtr[-1])); } + operPtr[-3] = (cmpTemp != 0) ? 24 : 23; + //operPtr[-3] = (cmpHelper(operPtr, valPtr) != 0) ? 24 : 23; stkPos -= 2; operPtr -= 2; valPtr -= 2; @@ -1074,7 +1013,7 @@ int16 Parse_v2::parseExpr(byte stopToken, byte *arg_2) { continue; if (stkPos > 2) { - if (operPtr[-2] == 2) { + if (operPtr[-2] == OP_ADD) { if (operPtr[-3] == 20) { valPtr[-3] += valPtr[-1]; } else if (operPtr[-3] == 22) { @@ -1088,12 +1027,12 @@ int16 Parse_v2::parseExpr(byte stopToken, byte *arg_2) { operPtr -= 2; valPtr -= 2; - } else if (operPtr[-2] == 3) { + } else if (operPtr[-2] == OP_SUB) { valPtr[-3] -= valPtr[-1]; stkPos -= 2; operPtr -= 2; valPtr -= 2; - } else if (operPtr[-2] == 4) { + } else if (operPtr[-2] == OP_BITOR) { valPtr[-3] |= valPtr[-1]; stkPos -= 2; operPtr -= 2; |