diff options
-rw-r--r-- | scumm/intern.h | 9 | ||||
-rw-r--r-- | scumm/script.cpp | 35 | ||||
-rw-r--r-- | scumm/script_v2.cpp | 93 | ||||
-rw-r--r-- | scumm/scumm.h | 3 |
4 files changed, 58 insertions, 82 deletions
diff --git a/scumm/intern.h b/scumm/intern.h index e73e592cd7..e094f9afc0 100644 --- a/scumm/intern.h +++ b/scumm/intern.h @@ -194,11 +194,6 @@ protected: virtual void setupOpcodes(); virtual void executeOpcode(int i); virtual const char *getOpcodeDesc(int i); - virtual void getResultPos(); - virtual void getResultPosDirect(); - virtual int getVar(); - virtual int getVarOrDirectByte(byte mask); - virtual int getVarOrDirectWord(byte mask); virtual void ifStateCommon(byte type); virtual void ifNotStateCommon(byte type); virtual void setStateCommon(byte type); @@ -283,15 +278,12 @@ protected: void o2_roomOps(); void o2_getDist(); void o2_findObject(); - void o2_subtract(); void o2_cutscene(); - void o2_increment(); void o2_chainScript(); void o2_pickupObject(); void o2_actorFollowCamera(); void o2_setObjectName(); void o2_getActorMoving(); - void o2_add(); void o2_cursorCommand(); void o2_stopScript(); void o2_getActorFacing(); @@ -304,7 +296,6 @@ protected: void o2_delay(); void o2_stopSound(); void o2_endCutscene(); - void o2_decrement(); void o2_drawSentence(); }; diff --git a/scumm/script.cpp b/scumm/script.cpp index 94d59b9672..2423774954 100644 --- a/scumm/script.cpp +++ b/scumm/script.cpp @@ -330,6 +330,25 @@ int Scumm::fetchScriptWordSigned() { return (int16)fetchScriptWord(); } +int Scumm::getVarOrDirectByte(byte mask) { + if (_opcode & mask) + if (_features & GF_AFTER_V2) + return readVar(fetchScriptByte()); + else + return readVar(fetchScriptWord()); + + return fetchScriptByte(); +} + +int Scumm::getVarOrDirectWord(byte mask) { + if (_opcode & mask) + if (_features & GF_AFTER_V2) + return readVar(fetchScriptByte()); + else + return readVar(fetchScriptWord()); + return fetchScriptWord(); +} + #ifndef BYPASS_COPY_PROT #define BYPASS_COPY_PROT #endif @@ -352,7 +371,12 @@ int Scumm::readVar(uint var) { #endif checkRange(_numVariables - 1, 0, var, "Variable %d out of range(r)"); - return _vars[var]; + + if ((_features & GF_AFTER_V2) && (var >= 14) && (var <= 16)) { + return _vars[_vars[var]]; + } else { + return _vars[var]; + } } if (var & 0x2000 && !(_features & GF_NEW_OPCODES)) { @@ -470,9 +494,18 @@ void Scumm::writeVar(uint var, int value) { error("Illegal varbits (w)"); } +void Scumm::getResultPosDirect() { + _resultVarNumber = _vars[fetchScriptByte()]; +} + void Scumm::getResultPos() { int a; + if (_features & GF_AFTER_V2) { + _resultVarNumber = fetchScriptByte(); + return; + } + _resultVarNumber = fetchScriptWord(); if (_resultVarNumber & 0x2000) { a = fetchScriptWord(); diff --git a/scumm/script_v2.cpp b/scumm/script_v2.cpp index 8839e2f94e..2d88945865 100644 --- a/scumm/script_v2.cpp +++ b/scumm/script_v2.cpp @@ -105,7 +105,7 @@ void Scumm_v2::setupOpcodes() { /* 38 */ OPCODE(o2_lessOrEqual), OPCODE(o2_doSentence), - OPCODE(o2_subtract), + OPCODE(o5_subtract), OPCODE(o2_waitForActor), /* 3C */ OPCODE(o2_stopSound), @@ -120,7 +120,7 @@ void Scumm_v2::setupOpcodes() { /* 44 */ OPCODE(o2_isLess), OPCODE(o2_drawObject), - OPCODE(o2_increment), + OPCODE(o5_increment), OPCODE(o2_setState08), /* 48 */ OPCODE(o2_isEqual), @@ -145,7 +145,7 @@ void Scumm_v2::setupOpcodes() { /* 58 */ OPCODE(beginOverride), OPCODE(o2_doSentence), - OPCODE(o2_add), + OPCODE(o5_add), OPCODE(o2_setBitVar), /* 5C */ OPCODE(o5_dummy), @@ -265,7 +265,7 @@ void Scumm_v2::setupOpcodes() { /* B8 */ OPCODE(o2_lessOrEqual), OPCODE(o2_doSentence), - OPCODE(o2_subtract), + OPCODE(o5_subtract), OPCODE(o2_waitForActor), /* BC */ OPCODE(o2_stopSound), @@ -280,7 +280,7 @@ void Scumm_v2::setupOpcodes() { /* C4 */ OPCODE(o2_isLess), OPCODE(o2_drawObject), - OPCODE(o2_decrement), + OPCODE(o5_decrement), OPCODE(o2_clearState08), /* C8 */ OPCODE(o2_isEqual), @@ -305,7 +305,7 @@ void Scumm_v2::setupOpcodes() { /* D8 */ OPCODE(o2_printEgo), OPCODE(o2_doSentence), - OPCODE(o2_add), + OPCODE(o5_add), OPCODE(o2_setBitVar), /* DC */ OPCODE(o5_dummy), @@ -366,25 +366,6 @@ const char *Scumm_v2::getOpcodeDesc(int i) { return _opcodesV2[i].desc; } -int Scumm_v2::getVar() { - int var_id = fetchScriptByte(); - if ((var_id >= 14) && (var_id <= 16)) - return _vars[_vars[var_id]]; - return _vars[var_id]; -} - -int Scumm_v2::getVarOrDirectByte(byte mask) { - if (_opcode & mask) - return getVar(); - return fetchScriptByte(); -} - -int Scumm_v2::getVarOrDirectWord(byte mask) { - if (_opcode & mask) - return getVar(); - return fetchScriptWord(); -} - void Scumm_v2::setStateCommon(byte type) { int obj = getVarOrDirectWord(0x80); putState(obj, getState(obj) | type); @@ -433,32 +414,24 @@ void Scumm_v2::o2_clearState01() { clearStateCommon(0x01); } -void Scumm_v2::getResultPos() { - _resultVarNumber = fetchScriptByte(); -} - -void Scumm_v2::getResultPosDirect() { - _resultVarNumber = _vars[fetchScriptByte()]; -} - -void Scumm_v2::o2_assignVarWordDirect() { +void Scumm_v2::o2_assignVarByteDirect() { getResultPosDirect(); - _vars[_resultVarNumber] = fetchScriptWord(); + setResult(fetchScriptByte()); } -void Scumm_v2::o2_assignVarByteDirect() { +void Scumm_v2::o2_assignVarWordDirect() { getResultPosDirect(); - _vars[_resultVarNumber] = fetchScriptByte(); + setResult(fetchScriptWord()); } void Scumm_v2::o2_assignVarByte() { getResultPos(); - _vars[_resultVarNumber] = fetchScriptByte(); + setResult(fetchScriptByte()); } void Scumm_v2::o2_assignVarWord() { getResultPos(); - _vars[_resultVarNumber] = fetchScriptWord(); + setResult(fetchScriptWord()); } void Scumm_v2::o2_setObjY() { @@ -746,7 +719,7 @@ void Scumm_v2::o2_verbOps() { } void Scumm_v2::o2_isEqual() { - int a = getVar(); + int a = readVar(fetchScriptByte()); int b = getVarOrDirectWord(0x80); if (b == a) @@ -757,7 +730,7 @@ void Scumm_v2::o2_isEqual() { } void Scumm_v2::o2_isGreater() { - int16 a = getVar(); + int16 a = readVar(fetchScriptByte()); int16 b = getVarOrDirectWord(0x80); if (b > a) @@ -767,7 +740,7 @@ void Scumm_v2::o2_isGreater() { } void Scumm_v2::o2_isGreaterEqual() { - int16 a = getVar(); + int16 a = readVar(fetchScriptByte()); int16 b = getVarOrDirectWord(0x80); if (b >= a) @@ -777,7 +750,7 @@ void Scumm_v2::o2_isGreaterEqual() { } void Scumm_v2::o2_isLess() { - int16 a = getVar(); + int16 a = readVar(fetchScriptByte()); int16 b = getVarOrDirectWord(0x80); if (b < a) @@ -787,7 +760,7 @@ void Scumm_v2::o2_isLess() { } void Scumm_v2::o2_lessOrEqual() { - int16 a = getVar(); + int16 a = readVar(fetchScriptByte()); int16 b = getVarOrDirectWord(0x80); if (b <= a) @@ -797,7 +770,7 @@ void Scumm_v2::o2_lessOrEqual() { } void Scumm_v2::o2_isNotEqual() { - int16 a = getVar(); + int16 a = readVar(fetchScriptByte()); int16 b = getVarOrDirectWord(0x80); if (b != a) @@ -807,7 +780,7 @@ void Scumm_v2::o2_isNotEqual() { } void Scumm_v2::o2_notEqualZero() { - int a = getVar(); + int a = readVar(fetchScriptByte()); if (a != 0) ignoreScriptWord(); @@ -816,7 +789,7 @@ void Scumm_v2::o2_notEqualZero() { } void Scumm_v2::o2_equalZero() { - int a = getVar(); + int a = readVar(fetchScriptByte()); if (a == 0) ignoreScriptWord(); @@ -1164,7 +1137,7 @@ void Scumm_v2::o2_setOwnerOf() { } void Scumm_v2::o2_delayVariable() { - vm.slot[_currentScript].delay = getVar(); + vm.slot[_currentScript].delay = readVar(fetchScriptByte()); vm.slot[_currentScript].status = 1; o5_breakHere(); } @@ -1235,13 +1208,6 @@ void Scumm_v2::o2_findObject() { _vars[_resultVarNumber] = findObject(x, y); } -void Scumm_v2::o2_subtract() { - int a; - getResultPos(); - a = getVarOrDirectWord(0x80); - _vars[_resultVarNumber] -= a; -} - void Scumm_v2::o2_cutscene() { // TODO } @@ -1250,16 +1216,6 @@ void Scumm_v2::o2_endCutscene() { // TODO } -void Scumm_v2::o2_increment() { - getResultPos(); - _vars[_resultVarNumber]++; -} - -void Scumm_v2::o2_decrement() { - getResultPos(); - _vars[_resultVarNumber]--; -} - void Scumm_v2::o2_chainScript() { int data = getVarOrDirectByte(0x80); int cur = _currentScript; @@ -1348,13 +1304,6 @@ void Scumm_v2::o2_getActorMoving() { _vars[_resultVarNumber] = a->moving; } -void Scumm_v2::o2_add() { - int a; - getResultPos(); - a = getVarOrDirectWord(0x80); - _vars[_resultVarNumber] += a; -} - void Scumm_v2::o2_cursorCommand() { getVarOrDirectWord(0x80); // TODO diff --git a/scumm/scumm.h b/scumm/scumm.h index 2c5ad3b8b6..86f3ee8fc1 100644 --- a/scumm/scumm.h +++ b/scumm/scumm.h @@ -512,9 +512,12 @@ protected: void ignoreScriptWord() { fetchScriptWord(); } void ignoreScriptByte() { fetchScriptByte(); } void getResultPos(); + void getResultPosDirect(); void setResult(int result); void push(int a); int pop(); + int getVarOrDirectByte(byte mask); + int getVarOrDirectWord(byte mask); public: virtual int readVar(uint var); // FIXME - should be protected, used in scumm/dialogs.cpp protected: |