diff options
author | Sven Hesse | 2006-02-02 21:12:00 +0000 |
---|---|---|
committer | Sven Hesse | 2006-02-02 21:12:00 +0000 |
commit | da33aa319bf5b5ae91650eaa9d24ef412a5d9af5 (patch) | |
tree | 402fb5253ac1d307f3d1370dae8b206879771ea1 | |
parent | d88462e7d68c4052fd2927ba7fc3be5566a1b9d9 (diff) | |
download | scummvm-rg350-da33aa319bf5b5ae91650eaa9d24ef412a5d9af5.tar.gz scummvm-rg350-da33aa319bf5b5ae91650eaa9d24ef412a5d9af5.tar.bz2 scummvm-rg350-da33aa319bf5b5ae91650eaa9d24ef412a5d9af5.zip |
Added/Changed o2_evaluateStore(), o2_palLoad(), o2_setRenderFlags(), o2_loadTot(), parseVarIndex(), parseValExpr() and parseExpr() for Gob2
svn-id: r20353
-rw-r--r-- | gob/draw.cpp | 75 | ||||
-rw-r--r-- | gob/draw.h | 1 | ||||
-rw-r--r-- | gob/gob.cpp | 9 | ||||
-rw-r--r-- | gob/inter.h | 5 | ||||
-rw-r--r-- | gob/inter_v1.cpp | 74 | ||||
-rw-r--r-- | gob/inter_v2.cpp | 291 | ||||
-rw-r--r-- | gob/module.mk | 2 | ||||
-rw-r--r-- | gob/parse.cpp | 849 | ||||
-rw-r--r-- | gob/parse.h | 27 |
9 files changed, 396 insertions, 937 deletions
diff --git a/gob/draw.cpp b/gob/draw.cpp index 3cfc999f3c..4b96c61758 100644 --- a/gob/draw.cpp +++ b/gob/draw.cpp @@ -693,81 +693,6 @@ void Draw::animateCursor(int16 cursor) { _cursorY = newY; } -void Draw::interPalLoad(void) { - int16 i; - int16 ind1; - int16 ind2; - byte cmd; - char *palPtr; - - cmd = *_vm->_global->_inter_execPtr++; - _applyPal = 0; - if (cmd & 0x80) - cmd &= 0x7f; - else - _applyPal = 1; - - if (cmd == 49) { - warning("inter_palLoad: cmd == 49 is not supported"); - //var_B = 1; - for (i = 0; i < 18; i++, _vm->_global->_inter_execPtr++) { - if (i < 2) { - if (_applyPal == 0) - continue; - - _unusedPalette1[i] = *_vm->_global->_inter_execPtr; - continue; - } - //if (*inter_execPtr != 0) - // var_B = 0; - - ind1 = *_vm->_global->_inter_execPtr >> 4; - ind2 = (*_vm->_global->_inter_execPtr & 0xf); - - _unusedPalette1[i] = - ((_palLoadData1[ind1] + _palLoadData2[ind2]) << 8) + - (_palLoadData2[ind1] + _palLoadData1[ind2]); - } - - _vm->_global->_pPaletteDesc->unused1 = _unusedPalette1; - } - - switch (cmd) { - case 52: - for (i = 0; i < 16; i++, _vm->_global->_inter_execPtr += 3) { - _vgaSmallPalette[i].red = _vm->_global->_inter_execPtr[0]; - _vgaSmallPalette[i].green = _vm->_global->_inter_execPtr[1]; - _vgaSmallPalette[i].blue = _vm->_global->_inter_execPtr[2]; - } - break; - - case 50: - for (i = 0; i < 16; i++, _vm->_global->_inter_execPtr++) - _unusedPalette2[i] = *_vm->_global->_inter_execPtr; - break; - - case 53: - palPtr = _vm->_game->loadTotResource(_vm->_inter->load16()); - memcpy((char *)_vgaPalette, palPtr, 768); - break; - - case 54: - memset((char *)_vgaPalette, 0, 768); - break; - } - if (!_applyPal) { - _vm->_global->_pPaletteDesc->unused2 = _unusedPalette2; - _vm->_global->_pPaletteDesc->unused1 = _unusedPalette1; - - if (_vm->_global->_videoMode != 0x13) - _vm->_global->_pPaletteDesc->vgaPal = (Video::Color *)_vgaSmallPalette; - else - _vm->_global->_pPaletteDesc->vgaPal = (Video::Color *)_vgaPalette; - - _vm->_palanim->fade((Video::PalDesc *) _vm->_global->_pPaletteDesc, 0, 0); - } -} - void Draw::printText(void) { int16 savedFlags; int16 ldestSpriteX; diff --git a/gob/draw.h b/gob/draw.h index de8ca65df4..0315e138a5 100644 --- a/gob/draw.h +++ b/gob/draw.h @@ -111,7 +111,6 @@ public: void spriteOperation(int16 operation); void animateCursor(int16 cursor); - void interPalLoad(void); void printText(void); Draw(GobEngine *vm); diff --git a/gob/gob.cpp b/gob/gob.cpp index 7ce0d6372b..eb8f94032c 100644 --- a/gob/gob.cpp +++ b/gob/gob.cpp @@ -298,14 +298,17 @@ int GobEngine::init(GameDetector &detector) { _mult = new Mult(this); _pack = new Pack(); _palanim = new PalAnim(this); - _parse = new Parse(this); _scenery = new Scenery(this); _gtimer = new GTimer(); _util = new Util(this); - if (_features & Gob::GF_GOB1) + if (_features & Gob::GF_GOB1) { _inter = new Inter_v1(this); - else if (_features & Gob::GF_GOB2) + _parse = new Parse_v1(this); + } + else if (_features & Gob::GF_GOB2) { _inter = new Inter_v2(this); + _parse = new Parse_v2(this); + } else error("GobEngine::init(): Unknown version of game engine"); if ((_features & Gob::GF_MAC) || (_features & Gob::GF_GOB1)) diff --git a/gob/inter.h b/gob/inter.h index 2cc9bc929d..48a5d3f6a1 100644 --- a/gob/inter.h +++ b/gob/inter.h @@ -300,6 +300,11 @@ protected: void o2_drawStub(void) { warning("Gob2 stub"); } void o2_stub0x80(void); + void o2_stub0x23(void); + bool o2_evaluateStore(char &cmdCount, int16 &counter, int16 &retFlag); + bool o2_palLoad(char &cmdCount, int16 &counter, int16 &retFlag); + void o2_setRenderFlags(void); + bool o2_loadTot(char &cmdCount, int16 &counter, int16 &retFlag); }; } // End of namespace Gob diff --git a/gob/inter_v1.cpp b/gob/inter_v1.cpp index 650246ead2..48ce9904e1 100644 --- a/gob/inter_v1.cpp +++ b/gob/inter_v1.cpp @@ -32,6 +32,7 @@ #include "gob/cdrom.h" #include "gob/music.h" #include "gob/map.h" +#include "gob/palanim.h" namespace Gob { @@ -1722,7 +1723,78 @@ bool Inter_v1::o1_callBool(char &cmdCount, int16 &counter, int16 &retFlag) { } bool Inter_v1::o1_palLoad(char &cmdCount, int16 &counter, int16 &retFlag) { - _vm->_draw->interPalLoad(); + int16 i; + int16 ind1; + int16 ind2; + byte cmd; + char *palPtr; + + cmd = *_vm->_global->_inter_execPtr++; + _vm->_draw->_applyPal = 0; + if (cmd & 0x80) + cmd &= 0x7f; + else + _vm->_draw->_applyPal = 1; + + if (cmd == 49) { + warning("o1_palLoad: cmd == 49 is not supported"); + //var_B = 1; + for (i = 0; i < 18; i++, _vm->_global->_inter_execPtr++) { + if (i < 2) { + if (_vm->_draw->_applyPal == 0) + continue; + + _vm->_draw->_unusedPalette1[i] = *_vm->_global->_inter_execPtr; + continue; + } + //if (*inter_execPtr != 0) + // var_B = 0; + + ind1 = *_vm->_global->_inter_execPtr >> 4; + ind2 = (*_vm->_global->_inter_execPtr & 0xf); + + _vm->_draw->_unusedPalette1[i] = + ((_vm->_draw->_palLoadData1[ind1] + _vm->_draw->_palLoadData2[ind2]) << 8) + + (_vm->_draw->_palLoadData2[ind1] + _vm->_draw->_palLoadData1[ind2]); + } + + _vm->_global->_pPaletteDesc->unused1 = _vm->_draw->_unusedPalette1; + } + + switch (cmd) { + case 52: + for (i = 0; i < 16; i++, _vm->_global->_inter_execPtr += 3) { + _vm->_draw->_vgaSmallPalette[i].red = _vm->_global->_inter_execPtr[0]; + _vm->_draw->_vgaSmallPalette[i].green = _vm->_global->_inter_execPtr[1]; + _vm->_draw->_vgaSmallPalette[i].blue = _vm->_global->_inter_execPtr[2]; + } + break; + + case 50: + for (i = 0; i < 16; i++, _vm->_global->_inter_execPtr++) + _vm->_draw->_unusedPalette2[i] = *_vm->_global->_inter_execPtr; + break; + + case 53: + palPtr = _vm->_game->loadTotResource(_vm->_inter->load16()); + memcpy((char *)_vm->_draw->_vgaPalette, palPtr, 768); + break; + + case 54: + memset((char *)_vm->_draw->_vgaPalette, 0, 768); + break; + } + if (!_vm->_draw->_applyPal) { + _vm->_global->_pPaletteDesc->unused2 = _vm->_draw->_unusedPalette2; + _vm->_global->_pPaletteDesc->unused1 = _vm->_draw->_unusedPalette1; + + if (_vm->_global->_videoMode != 0x13) + _vm->_global->_pPaletteDesc->vgaPal = (Video::Color *)_vm->_draw->_vgaSmallPalette; + else + _vm->_global->_pPaletteDesc->vgaPal = (Video::Color *)_vm->_draw->_vgaPalette; + + _vm->_palanim->fade((Video::PalDesc *) _vm->_global->_pPaletteDesc, 0, 0); + } return false; } diff --git a/gob/inter_v2.cpp b/gob/inter_v2.cpp index 338b70bf61..baa5eaddaf 100644 --- a/gob/inter_v2.cpp +++ b/gob/inter_v2.cpp @@ -30,6 +30,7 @@ #include "gob/mult.h" #include "gob/goblin.h" #include "gob/cdrom.h" +#include "gob/palanim.h" namespace Gob { @@ -128,7 +129,7 @@ void Inter_v2::setupOpcodes(void) { /* 08 */ OPCODE(o1_initCursorAnim), OPCODE(o1_clearCursorAnim), - OPCODE(o1_setRenderFlags), + OPCODE(o2_setRenderFlags), {NULL, ""}, /* 0C */ {NULL, ""}, @@ -159,7 +160,7 @@ void Inter_v2::setupOpcodes(void) { OPCODE(o2_drawStub), OPCODE(o2_drawStub), OPCODE(o2_drawStub), - OPCODE(o2_drawStub), + OPCODE(o2_stub0x23), /* 24 */ OPCODE(o2_drawStub), OPCODE(o2_drawStub), @@ -450,7 +451,7 @@ void Inter_v2::setupOpcodes(void) { OPCODE(o1_whileDo), /* 08 */ OPCODE(o1_callBool), - OPCODE(o1_evaluateStore), + OPCODE(o2_evaluateStore), OPCODE(o1_loadSpriteToPos), {NULL, ""}, /* 0C */ @@ -461,8 +462,8 @@ void Inter_v2::setupOpcodes(void) { /* 10 */ {NULL, ""}, OPCODE(o1_printText), - OPCODE(o1_loadTot), - OPCODE(o1_palLoad), + OPCODE(o2_loadTot), + OPCODE(o2_palLoad), /* 14 */ OPCODE(o1_keyFunc), OPCODE(o1_capturePush), @@ -712,4 +713,284 @@ void Inter_v2::o2_stub0x80(void) { warning("STUB: Gob2 drawOperation 0x80 (%d %d)", expr1, expr2); } +void Inter_v2::o2_stub0x23(void) { + byte result; + char str[40]; + + result = evalExpr(NULL); + strcpy(str, _vm->_global->_inter_resStr); + + warning("STUB: Gob2 drawOperation 0x23 (%d, \"%s\")", result, str); +} + +bool Inter_v2::o2_evaluateStore(char &cmdCount, int16 &counter, int16 &retFlag) { + char *savedPos; + int16 varOff; + int16 token; + int16 result; + byte loopCount; + + savedPos = _vm->_global->_inter_execPtr; + varOff = _vm->_parse->parseVarIndex(); + + if (*_vm->_global->_inter_execPtr == 99) { + _vm->_global->_inter_execPtr++; + loopCount = *_vm->_global->_inter_execPtr++; + } + else + loopCount = 1; + + for (int i = 0; i < loopCount; i++) { + token = evalExpr(&result); + switch (savedPos[0]) { + case 16: + case 18: + *(_vm->_global->_inter_variables + varOff + i) = _vm->_global->_inter_resVal; + break; + + case 17: + case 27: + *(uint16*)(_vm->_global->_inter_variables + varOff + i * 2) = _vm->_global->_inter_resVal; + break; + + case 23: + case 26: + WRITE_VAR_OFFSET(varOff + i * 4, _vm->_global->_inter_resVal); + break; + + case 24: + *(uint16*)(_vm->_global->_inter_variables + varOff + i * 4) = _vm->_global->_inter_resVal; + break; + + case 25: + case 28: + if (token == 20) + *(_vm->_global->_inter_variables + varOff) = result; + else + strcpy(_vm->_global->_inter_variables + varOff, _vm->_global->_inter_resStr); + break; + } + } + + return false; +} + +bool Inter_v2::o2_palLoad(char &cmdCount, int16 &counter, int16 &retFlag) { + int16 i; + int16 ind1; + int16 ind2; + byte cmd; + char *palPtr; + + cmd = *_vm->_global->_inter_execPtr++; + + switch(cmd & 0x7f) { + case 48: + if ((_vm->_global->_videoMode < 0x32) || (_vm->_global->_videoMode > 0x63)) { + _vm->_global->_inter_execPtr += 48; + return false; + } + break; + + case 49: + if ((_vm->_global->_videoMode != 5) && (_vm->_global->_videoMode != 7)) { + _vm->_global->_inter_execPtr += 18; + return false; + } + break; + + case 50: + if (_vm->_global->_videoMode != 0x0D) { // || (word_2D479 == 256) { + _vm->_global->_inter_execPtr += 16; + return false; + } + break; + + case 51: + if (_vm->_global->_videoMode < 0x64) { + _vm->_global->_inter_execPtr += 2; + return false; + } + break; + + case 52: + if (_vm->_global->_videoMode != 0x0D) { // || (word_2D479 == 256) { + _vm->_global->_inter_execPtr += 48; + return false; + } + break; + + case 53: + if (_vm->_global->_videoMode < 0x13) { + _vm->_global->_inter_execPtr += 2; + return false; + } + break; + + case 54: + if (_vm->_global->_videoMode < 0x13) { + return false; + } + break; + + case 61: + if (_vm->_global->_videoMode < 0x13) { + *_vm->_global->_inter_execPtr += 4; + return false; + } + break; + } + + if ((cmd & 0x7f) == 0x30) { + _vm->_global->_inter_execPtr += 48; + return false; + } + + _vm->_draw->_applyPal = 0; + if (cmd & 0x80) + cmd &= 0x7f; + else + _vm->_draw->_applyPal = 1; + + if (cmd == 49) { + int dl; + for (i = 2; i < 18; i++) { + dl = 1; + if(_vm->_global->_inter_execPtr[i] != 0) + dl = 0; + } + if (dl != 0) { + warning("GOB2 Stub! sub_27413"); +/* sub_27413(_draw_frontSurface); + byte_2E521 = 0; + _vm->_global->_inter_execPtr += 18; + break;*/ + } +// byte_2E521 = 1; + + for (i = 0; i < 18; i++, _vm->_global->_inter_execPtr++) { + if (i < 2) { + if (_vm->_draw->_applyPal == 0) + continue; + + _vm->_draw->_unusedPalette1[i] = *_vm->_global->_inter_execPtr; + continue; + } + + ind1 = *_vm->_global->_inter_execPtr >> 4; + ind2 = (*_vm->_global->_inter_execPtr & 0xf); + + _vm->_draw->_unusedPalette1[i] = + ((_vm->_draw->_palLoadData1[ind1] + _vm->_draw->_palLoadData2[ind2]) << 8) + + (_vm->_draw->_palLoadData2[ind1] + _vm->_draw->_palLoadData1[ind2]); + } + + _vm->_global->_pPaletteDesc->unused1 = _vm->_draw->_unusedPalette1; + _vm->_video->setFullPalette(_vm->_global->_pPaletteDesc); + return false; + } + + switch (cmd) { + case 50: + for (i = 0; i < 16; i++, _vm->_global->_inter_execPtr++) + _vm->_draw->_unusedPalette2[i] = *_vm->_global->_inter_execPtr; + break; + + case 52: + for (i = 0; i < 16; i++, _vm->_global->_inter_execPtr += 3) { + _vm->_draw->_vgaSmallPalette[i].red = _vm->_global->_inter_execPtr[0]; + _vm->_draw->_vgaSmallPalette[i].green = _vm->_global->_inter_execPtr[1]; + _vm->_draw->_vgaSmallPalette[i].blue = _vm->_global->_inter_execPtr[2]; + } + _vm->_global->_inter_execPtr += 48; + if (_vm->_global->_videoMode >= 0x13) + return false; + break; + + case 53: + palPtr = _vm->_game->loadTotResource(_vm->_inter->load16()); + memcpy((char *)_vm->_draw->_vgaPalette, palPtr, 768); + break; + + case 54: + memset((char *)_vm->_draw->_vgaPalette, 0, 768); + break; + + case 61: + ind1 = *_vm->_global->_inter_execPtr++; + ind2 = (*_vm->_global->_inter_execPtr++ - ind1 + 1) * 3; + palPtr = _vm->_game->loadTotResource(_vm->_inter->load16()); + memcpy((char *)_vm->_draw->_vgaPalette + ind1 * 3, palPtr + ind1 * 3, ind2); + if (_vm->_draw->_applyPal) { + _vm->_draw->_applyPal = 0; + _vm->_video->setFullPalette(_vm->_global->_pPaletteDesc); + return false; + } + break; + } + + if (!_vm->_draw->_applyPal) { + _vm->_global->_pPaletteDesc->unused2 = _vm->_draw->_unusedPalette2; + _vm->_global->_pPaletteDesc->unused1 = _vm->_draw->_unusedPalette1; + if (_vm->_global->_videoMode < 0x13) { + _vm->_global->_pPaletteDesc->vgaPal = (Video::Color *)_vm->_draw->_vgaSmallPalette; + _vm->_palanim->fade((Video::PalDesc *) _vm->_global->_pPaletteDesc, 0, 0); + return false; + } + if ((_vm->_global->_videoMode < 0x32) || (_vm->_global->_videoMode >= 0x64)) { + _vm->_global->_pPaletteDesc->vgaPal = (Video::Color *)_vm->_draw->_vgaPalette; + _vm->_palanim->fade((Video::PalDesc *) _vm->_global->_pPaletteDesc, 0, 0); + return false; + } + _vm->_global->_pPaletteDesc->vgaPal = (Video::Color *)_vm->_draw->_vgaSmallPalette; + _vm->_palanim->fade((Video::PalDesc *) _vm->_global->_pPaletteDesc, 0, 0); + } + + return false; +} + +void Inter_v2::o2_setRenderFlags(void) { + int16 expr; + + expr = _vm->_parse->parseValExpr(); + + if (expr & 0x8000) { + if (expr & 0x4000) + _vm->_draw->_renderFlags = _vm->_parse->parseValExpr(); + else + _vm->_draw->_renderFlags &= expr & 0x3fff; + } + else + _vm->_draw->_renderFlags |= expr & 0x3fff; +} + +bool Inter_v2::o2_loadTot(char &cmdCount, int16 &counter, int16 &retFlag) { + char buf[20]; + int8 size; + int16 i; + + if ((*_vm->_global->_inter_execPtr & 0x80) != 0) { + _vm->_global->_inter_execPtr++; + evalExpr(0); + strcpy(buf, _vm->_global->_inter_resStr); + } else { + size = *_vm->_global->_inter_execPtr++; + for (i = 0; i < size; i++) + buf[i] = *_vm->_global->_inter_execPtr++; + + buf[size] = 0; + } + + if (strcmp(buf, "INSTALL") == 0) { + warning("GOB2 Stub! word_2E515 = _inter_variables[0E8h]"); + } + + strcat(buf, ".tot"); + if (_terminate != 2) + _terminate = true; + strcpy(_vm->_game->_totToLoad, buf); + + return false; +} + } // End of namespace Gob diff --git a/gob/module.mk b/gob/module.mk index 9eedde2cdc..914931d775 100644 --- a/gob/module.mk +++ b/gob/module.mk @@ -20,6 +20,8 @@ MODULE_OBJS := \ gob/pack.o \ gob/palanim.o \ gob/parse.o \ + gob/parse_v1.o \ + gob/parse_v2.o \ gob/scenery.o \ gob/sound.o \ gob/timer.o \ diff --git a/gob/parse.cpp b/gob/parse.cpp index 23c68bc144..c122bd8ea0 100644 --- a/gob/parse.cpp +++ b/gob/parse.cpp @@ -70,576 +70,6 @@ char *Parse::decodePtr(int32 n) { return ptr + (n & 0x0FFFFFFF); } -int16 Parse::parseExpr(char stopToken, byte *arg_2) { - int32 values[20]; - byte operStack[20]; - int32 prevPrevVal; - int32 prevVal; - int32 curVal; - int32 *valPtr; - char *operPtr; - byte *arrDescPtr; - char var_C; - byte operation; - int16 dimCount; - int16 temp; - int16 temp2; - uint16 offset; - int16 dim; - char var_1A; - int16 stkPos; - int16 brackStart; - - stkPos = -1; - operPtr = (char *)(operStack - 1); - valPtr = values - 1; - - while (1) { - stkPos++; - operPtr++; - valPtr++; - operation = *_vm->_global->_inter_execPtr++; - if (operation >= 19 && operation <= 29) { - switch (operation) { - case 19: - *operPtr = 20; - *valPtr = READ_LE_UINT32(_vm->_global->_inter_execPtr); - _vm->_global->_inter_execPtr += 4; - break; - - case 20: - *operPtr = 20; - *valPtr = _vm->_inter->load16(); - break; - - case 22: - *operPtr = 22; - *valPtr = encodePtr(_vm->_global->_inter_execPtr, kExecPtr); - _vm->_global->_inter_execPtr += strlen(_vm->_global->_inter_execPtr) + 1; - break; - - case 23: - *operPtr = 20; - *valPtr = VAR(_vm->_inter->load16()); - break; - - case 25: - *operPtr = 22; - temp = _vm->_inter->load16() * 4; - *valPtr = encodePtr(_vm->_global->_inter_variables + temp, kInterVar); - if (*_vm->_global->_inter_execPtr == 13) { - _vm->_global->_inter_execPtr++; - temp += parseValExpr(12); - *operPtr = 20; - *valPtr = (uint8)*(_vm->_global->_inter_variables + temp); - } - break; - - case 26: - case 28: - *operPtr = operation - 6; - temp = _vm->_inter->load16(); - dimCount = *_vm->_global->_inter_execPtr++; - arrDescPtr = (byte *)_vm->_global->_inter_execPtr; - _vm->_global->_inter_execPtr += dimCount; - offset = 0; - dim = 0; - for (dim = 0; dim < dimCount; dim++) { - temp2 = parseValExpr(12); - offset = offset * arrDescPtr[dim] + temp2; - } - - if (operation == 26) { - *valPtr = VAR(temp + offset); - break; - } - *valPtr = encodePtr(_vm->_global->_inter_variables + temp * 4 + offset * _vm->_global->_inter_animDataSize * 4, kInterVar); - if (*_vm->_global->_inter_execPtr == 13) { - _vm->_global->_inter_execPtr++; - temp2 = parseValExpr(12); - *operPtr = 20; - *valPtr = (uint8)*(_vm->_global->_inter_variables + temp * 4 + offset * 4 * _vm->_global->_inter_animDataSize + temp2); - } - break; - - case 29: - operation = *_vm->_global->_inter_execPtr++; - parseExpr(10, 0); - - switch (operation) { - case 5: - _vm->_global->_inter_resVal = _vm->_global->_inter_resVal * _vm->_global->_inter_resVal; - break; - - case 0: - case 1: - case 6: - curVal = 1; - prevVal = 1; - - do { - prevPrevVal = prevVal; - prevVal = curVal; - curVal = (curVal + _vm->_global->_inter_resVal / curVal) / 2; - } while (curVal != prevVal && curVal != prevPrevVal); - _vm->_global->_inter_resVal = curVal; - break; - - case 10: - _vm->_global->_inter_resVal = _vm->_util->getRandom(_vm->_global->_inter_resVal); - break; - - case 7: - if (_vm->_global->_inter_resVal < 0) - _vm->_global->_inter_resVal = -_vm->_global->_inter_resVal; - break; - } - *operPtr = 20; - *valPtr = _vm->_global->_inter_resVal; - } - - if (stkPos > 0 && (operPtr[-1] == 1 || operPtr[-1] == 11)) { - stkPos--; - operPtr--; - valPtr--; - - if (*operPtr == 1) { - *operPtr = 20; - valPtr[0] = -valPtr[1]; - } else if (*operPtr == 11) { - if (operPtr[1] == 23) - *operPtr = 24; - else - *operPtr = 23; - } - } - - if (stkPos <= 0) - continue; - - switch (operPtr[-1]) { - case 2: - if (operPtr[-2] == 22) { - if (decodePtr(valPtr[-2]) != _vm->_global->_inter_resStr) { - strcpy(_vm->_global->_inter_resStr, decodePtr(valPtr[-2])); - valPtr[-2] = encodePtr(_vm->_global->_inter_resStr, kResStr); - } - strcat(_vm->_global->_inter_resStr, decodePtr(valPtr[0])); - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - } - break; - - case 5: - valPtr[-2] *= valPtr[0]; - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - break; - - case 6: - valPtr[-2] /= valPtr[0]; - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - break; - - case 7: - valPtr[-2] %= valPtr[0]; - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - break; - - case 8: - valPtr[-2] &= valPtr[0]; - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - break; - } - continue; - } // op>= 19 && op <= 29 - - if (operation == stopToken || operation == 30 || operation == 31 || operation == 10) { - while (stkPos >= 2) { - var_1A = 0; - if (operPtr[-2] == 9 && (operation == 10 || operation == stopToken)) { - operPtr[-2] = operPtr[-1]; - if (operPtr[-2] == 20 || operPtr[-2] == 22) - valPtr[-2] = valPtr[-1]; - - stkPos--; - operPtr--; - valPtr--; - - if (stkPos > 1) { - if (operPtr[-2] == 1) { - operPtr[-2] = 20; - valPtr[-2] = -valPtr[-1]; - stkPos--; - operPtr--; - valPtr--; - } else if (operPtr[-2] == 11) { - if (operPtr[-1] == 23) - operPtr[-2] = 24; - else - operPtr[-2] = 23; - - stkPos--; - operPtr--; - valPtr--; - } - } // stkPos > 1 - - if (stkPos > 2) { - switch (operPtr[-2]) { - case 5: - valPtr[-3] *= valPtr[-1]; - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - break; - case 6: - valPtr[-3] /= valPtr[-1]; - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - break; - - case 7: - valPtr[-3] %= valPtr[-1]; - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - break; - - case 8: - valPtr[-3] &= valPtr[-1]; - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - break; - } // switch - } // stkPos > 2 - - if (operation != stopToken) - break; - } // if (operPtr[-2] == 9 && ...) - - for (brackStart = stkPos - 2; brackStart > 0 && - operStack[brackStart] < 30 && - operStack[brackStart] != 9; brackStart--); - - if (operStack[brackStart] >= 30 || operStack[brackStart] == 9) - brackStart++; - - switch (operPtr[-2]) { - case 2: - if (operStack[brackStart] == 20) { - values[brackStart] += valPtr[-1]; - } else if (operStack[brackStart] == 22) { - if (decodePtr(values[brackStart]) != _vm->_global->_inter_resStr) { - strcpy(_vm->_global->_inter_resStr, decodePtr(values[brackStart])); - values[brackStart] = encodePtr(_vm->_global->_inter_resStr, kResStr); - } - strcat(_vm->_global->_inter_resStr, decodePtr(valPtr[-1])); - } - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - continue; - - case 3: - values[brackStart] -= valPtr[-1]; - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - continue; - - case 4: - values[brackStart] |= valPtr[-1]; - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - continue; - - case 5: - valPtr[-3] *= valPtr[-1]; - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - break; - - case 6: - valPtr[-3] /= valPtr[-1]; - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - break; - - case 7: - valPtr[-3] %= valPtr[-1]; - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - break; - - case 8: - valPtr[-3] &= valPtr[-1]; - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - break; - - case 30: - if (operPtr[-3] == 23) - operPtr[-3] = operPtr[-1]; - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - break; - - case 31: - if (operPtr[-3] == 24) - operPtr[-3] = operPtr[-1]; - stkPos -= 2; - operPtr -= 2; - valPtr -= 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 (decodePtr(valPtr[-3]) != _vm->_global->_inter_resStr) { - strcpy(_vm->_global->_inter_resStr, decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr(_vm->_global->_inter_resStr, kResStr); - } - if (strcmp(_vm->_global->_inter_resStr, decodePtr(valPtr[-1])) < 0) - operPtr[-3] = 24; - } - 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 (decodePtr(valPtr[-3]) != _vm->_global->_inter_resStr) { - strcpy(_vm->_global->_inter_resStr, decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr(_vm->_global->_inter_resStr, kResStr); - } - if (strcmp(_vm->_global->_inter_resStr, decodePtr(valPtr[-1])) <= 0) - operPtr[-3] = 24; - } - 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 (decodePtr(valPtr[-3]) != _vm->_global->_inter_resStr) { - strcpy(_vm->_global->_inter_resStr, decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr(_vm->_global->_inter_resStr, kResStr); - } - if (strcmp(_vm->_global->_inter_resStr, decodePtr(valPtr[-1])) > 0) - operPtr[-3] = 24; - } - 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 (decodePtr(valPtr[-3]) != _vm->_global->_inter_resStr) { - strcpy(_vm->_global->_inter_resStr, decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr(_vm->_global->_inter_resStr, kResStr); - } - if (strcmp(_vm->_global->_inter_resStr, decodePtr(valPtr[-1])) >= 0) - operPtr[-3] = 24; - } - 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 (decodePtr(valPtr[-3]) != _vm->_global->_inter_resStr) { - strcpy(_vm->_global->_inter_resStr, decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr(_vm->_global->_inter_resStr, kResStr); - } - if (strcmp(_vm->_global->_inter_resStr, decodePtr(valPtr[-1])) == 0) - operPtr[-3] = 24; - } - 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 (decodePtr(valPtr[-3]) != _vm->_global->_inter_resStr) { - strcpy(_vm->_global->_inter_resStr, decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr(_vm->_global->_inter_resStr, kResStr); - } - if (strcmp(_vm->_global->_inter_resStr, decodePtr(valPtr[-1])) != 0) - operPtr[-3] = 24; - } - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - break; - - default: - var_1A = 1; - break; - } // switch - - if (var_1A != 0) - break; - } // while (stkPos >= 2) - - if (operation == 30 || operation == 31) { - if (operPtr[-1] == 20) { - if (valPtr[-1] != 0) - operPtr[-1] = 24; - else - operPtr[-1] = 23; - } - - if ((operation == 30 && operPtr[-1] == 24) || - (operation == 31 && operPtr[-1] == 23)) { - if (stkPos > 1 && operPtr[-2] == 9) { - skipExpr(10); - operPtr[-2] = operPtr[-1]; - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - } else { - skipExpr(stopToken); - } - operation = _vm->_global->_inter_execPtr[-1]; - if (stkPos > 0 && operPtr[-1] == 11) { - if (operPtr[0] == 23) - operPtr[-1] = 24; - else - operPtr[-1] = 23; - - stkPos--; - operPtr--; - valPtr--; - } - } else - operPtr[0] = operation; - } else { - stkPos--; - operPtr--; - valPtr--; - } - - if (operation != stopToken) - continue; - - if (arg_2 != 0) - *arg_2 = operStack[0]; - - switch (operStack[0]) { - case 20: - _vm->_global->_inter_resVal = values[0]; - break; - - case 22: - if (decodePtr(values[0]) != _vm->_global->_inter_resStr) - strcpy(_vm->_global->_inter_resStr, decodePtr(values[0])); - break; - - case 11: - if (arg_2 != 0) - *arg_2 ^= 1; - break; - - case 23: - case 24: - break; - - default: - _vm->_global->_inter_resVal = 0; - if (arg_2 != 0) - *arg_2 = 20; - break; - } - return 0; - } // operation == stopToken || operation == 30 || operation == 31 || operation == 10 - - if (operation < 1 || operation > 11) { - if (operation < 32 || operation > 37) - continue; - - if (stkPos > 2) { - if (operPtr[-2] == 2) { - if (operPtr[-3] == 20) { - valPtr[-3] += valPtr[-1]; - } else if (operPtr[-3] == 22) { - if (decodePtr(valPtr[-3]) != _vm->_global->_inter_resStr) { - strcpy(_vm->_global->_inter_resStr, decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr(_vm->_global->_inter_resStr, kResStr); - } - strcat(_vm->_global->_inter_resStr, decodePtr(valPtr[-1])); - } - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - - } else if (operPtr[-2] == 3) { - valPtr[-3] -= valPtr[-1]; - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - } else if (operPtr[-2] == 4) { - valPtr[-3] |= valPtr[-1]; - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - } - } - } - *operPtr = operation; - } -} - void Parse::skipExpr(char stopToken) { int16 dimCount; char operation; @@ -715,285 +145,6 @@ void Parse::skipExpr(char stopToken) { } } -int16 Parse::parseValExpr(unsigned stopToken) { - int16 values[20]; - byte operStack[20]; - int16 *valPtr; - byte *operPtr; - byte *arrDesc; - unsigned operation; - int16 temp2; - int16 dim; - int16 dimCount; - int16 temp; - int16 offset; - int16 stkPos; - int16 brackPos; - static int16 flag = 0; - int16 oldflag; - - oldflag = flag; - if (flag == 0) { - flag = 1; - printExpr(stopToken); - } - - stkPos = -1; - operPtr = operStack - 1; - valPtr = values - 1; - - while (1) { - stkPos++; - operPtr++; - valPtr++; - - operation = *_vm->_global->_inter_execPtr++; - if (operation >= 19 && operation <= 29) { - *operPtr = 20; - switch (operation) { - case 19: - *valPtr = READ_LE_UINT32(_vm->_global->_inter_execPtr); - _vm->_global->_inter_execPtr += 4; - break; - - case 20: - *valPtr = _vm->_inter->load16(); - break; - - case 23: - *valPtr = (uint16)VAR(_vm->_inter->load16()); - break; - - case 25: - temp = _vm->_inter->load16() * 4; - _vm->_global->_inter_execPtr++; - temp += parseValExpr(12); - *valPtr = (uint8)*(_vm->_global->_inter_variables + temp); - break; - - case 26: - case 28: - temp = _vm->_inter->load16(); - dimCount = *_vm->_global->_inter_execPtr++; - arrDesc = (byte*)_vm->_global->_inter_execPtr; - _vm->_global->_inter_execPtr += dimCount; - offset = 0; - for (dim = 0; dim < dimCount; dim++) { - temp2 = parseValExpr(12); - offset = arrDesc[dim] * offset + temp2; - } - if (operation == 26) { - *valPtr = (uint16)VAR(temp + offset); - } else { - _vm->_global->_inter_execPtr++; - temp2 = parseValExpr(12); - *valPtr = (uint8)*(_vm->_global->_inter_variables + temp * 4 + offset * 4 * _vm->_global->_inter_animDataSize + temp2); - } - break; - - case 29: - operation = *_vm->_global->_inter_execPtr++; - parseExpr(10, 0); - - if (operation == 5) { - _vm->_global->_inter_resVal = _vm->_global->_inter_resVal * _vm->_global->_inter_resVal; - } else if (operation == 7) { - if (_vm->_global->_inter_resVal < 0) - _vm->_global->_inter_resVal = -_vm->_global->_inter_resVal; - } else if (operation == 10) { - _vm->_global->_inter_resVal = _vm->_util->getRandom(_vm->_global->_inter_resVal); - } - *valPtr = _vm->_global->_inter_resVal; - break; - - } // switch - if (stkPos > 0 && operPtr[-1] == 1) { - stkPos--; - operPtr--; - valPtr--; - operPtr[0] = 20; - valPtr[0] = -valPtr[1]; - } - - if (stkPos > 0 && operPtr[-1] > 4 && operPtr[-1] < 9) { - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - - switch (operPtr[1]) { - case 5: - valPtr[0] *= valPtr[2]; - break; - - case 6: - valPtr[0] /= valPtr[2]; - break; - - case 7: - valPtr[0] %= valPtr[2]; - break; - - case 8: - valPtr[0] &= valPtr[2]; - break; - } - } // if (stkPos > 0 && cmdPtr[-1] > 4 && cmdPtr[-1] < 9) - continue; - } - - if (operation >= 1 && operation <= 9) { - *operPtr = operation; - continue; - } - - while (stkPos >= 2) { - if (operPtr[-2] == 9) { - stkPos--; - operPtr--; - valPtr--; - - operPtr[-1] = operPtr[0]; - valPtr[-1] = valPtr[0]; - if (stkPos > 1 && operPtr[-2] == 1) { - valPtr[-2] = 20; - valPtr[-2] = -valPtr[-1]; - - stkPos--; - operPtr--; - valPtr--; - } - - if (stkPos > 2 && operPtr[-2] > 4 - && operPtr[-2] < 9) { - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - switch (operPtr[0]) { - case 5: - operPtr[-1] *= operPtr[1]; - break; - - case 6: - operPtr[-1] /= operPtr[1]; - break; - - case 7: - operPtr[-1] %= operPtr[1]; - break; - - case 8: - operPtr[-1] &= operPtr[1]; - break; - } - } - if (operation == 10) - break; - } // operPtr[-2] == 9 - - for (brackPos = stkPos - 2; brackPos > 0 && - operStack[brackPos] < 30 - && operStack[brackPos] != 9; brackPos--); - - if (operStack[brackPos] >= 30 - || operStack[brackPos] == 9) - brackPos++; - - if (operPtr[-2] < 2 || operPtr[-2] > 8) - break; - - stkPos -= 2; - operPtr -= 2; - valPtr -= 2; - switch (operPtr[0]) { - case 2: - values[brackPos] += valPtr[1]; - continue; - case 3: - values[brackPos] -= valPtr[1]; - continue; - case 4: - values[brackPos] |= valPtr[1]; - continue; - case 5: - valPtr[-1] *= valPtr[1]; - continue; - case 6: - valPtr[-1] /= valPtr[1]; - continue; - case 7: - valPtr[-1] %= valPtr[1]; - continue; - case 8: - valPtr[-1] &= valPtr[1]; - continue; - } - } - - if (operation != 10) { - if (operation != stopToken) { - debug(5, "stoptoken error: %d != %d", operation, stopToken); - } - flag = oldflag; - return values[0]; - } - - stkPos--; - operPtr--; - valPtr--; - } -} - -int16 Parse::parseVarIndex() { - int16 temp2; - char *arrDesc; - int16 dim; - int16 dimCount; - int16 operation; - int16 temp; - int16 offset; - int16 val; - - operation = *_vm->_global->_inter_execPtr++; - debug(5, "var parse = %d", operation); - switch (operation) { - case 23: - case 25: - temp = _vm->_inter->load16() * 4; - debug(5, "oper = %d", (int16)*_vm->_global->_inter_execPtr); - if (operation == 25 && *_vm->_global->_inter_execPtr == 13) { - _vm->_global->_inter_execPtr++; - val = parseValExpr(12); - temp += val; - debug(5, "parse subscript = %d", val); - } - return temp; - - case 26: - case 28: - temp = _vm->_inter->load16() * 4; - 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(12); - offset = arrDesc[dim] * offset + temp2; - } - offset *= 4; - if (operation != 28) - return temp + offset; - - if (*_vm->_global->_inter_execPtr == 13) { - _vm->_global->_inter_execPtr++; - temp += parseValExpr(12); - } - return offset * _vm->_global->_inter_animDataSize + temp; - - default: - return 0; - } -} - void Parse::printExpr(char stopToken) { int16 dimCount; char operation; diff --git a/gob/parse.h b/gob/parse.h index 0095739692..a6c481d94a 100644 --- a/gob/parse.h +++ b/gob/parse.h @@ -26,14 +26,15 @@ namespace Gob { class Parse { public: - int16 parseExpr(char stopToken, byte *resultPtr); void skipExpr(char stopToken); - int16 parseValExpr(unsigned stopToken=99); - int16 parseVarIndex(void); void printExpr(char stopToken); void printVarIndex(void); + virtual int16 parseVarIndex(void) = 0; + virtual int16 parseValExpr(unsigned stopToken=99) = 0; + virtual int16 parseExpr(char stopToken, byte *resultPtr) = 0; Parse(GobEngine *vm); + virtual ~Parse() {}; protected: enum PointerType { @@ -48,6 +49,26 @@ protected: char *decodePtr(int32 n); }; +class Parse_v1 : public Parse { +public: + Parse_v1(GobEngine *vm); + virtual ~Parse_v1() {}; + + virtual int16 parseVarIndex(void); + virtual int16 parseValExpr(unsigned stopToken=99); + virtual int16 parseExpr(char stopToken, byte *resultPtr); +}; + +class Parse_v2 : public Parse_v1 { +public: + Parse_v2(GobEngine *vm); + virtual ~Parse_v2() {}; + + virtual int16 parseVarIndex(void); + virtual int16 parseValExpr(unsigned stopToken=99); + virtual int16 parseExpr(char stopToken, byte *resultPtr); +}; + } // End of namespace Gob #endif |