put some v2 code into share code

svn-id: r7148
This commit is contained in:
Paweł Kołodziejski 2003-04-27 07:52:26 +00:00
parent 5a687ff50f
commit caf6d74095
4 changed files with 58 additions and 82 deletions

View file

@ -194,11 +194,6 @@ protected:
virtual void setupOpcodes(); virtual void setupOpcodes();
virtual void executeOpcode(int i); virtual void executeOpcode(int i);
virtual const char *getOpcodeDesc(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 ifStateCommon(byte type);
virtual void ifNotStateCommon(byte type); virtual void ifNotStateCommon(byte type);
virtual void setStateCommon(byte type); virtual void setStateCommon(byte type);
@ -283,15 +278,12 @@ protected:
void o2_roomOps(); void o2_roomOps();
void o2_getDist(); void o2_getDist();
void o2_findObject(); void o2_findObject();
void o2_subtract();
void o2_cutscene(); void o2_cutscene();
void o2_increment();
void o2_chainScript(); void o2_chainScript();
void o2_pickupObject(); void o2_pickupObject();
void o2_actorFollowCamera(); void o2_actorFollowCamera();
void o2_setObjectName(); void o2_setObjectName();
void o2_getActorMoving(); void o2_getActorMoving();
void o2_add();
void o2_cursorCommand(); void o2_cursorCommand();
void o2_stopScript(); void o2_stopScript();
void o2_getActorFacing(); void o2_getActorFacing();
@ -304,7 +296,6 @@ protected:
void o2_delay(); void o2_delay();
void o2_stopSound(); void o2_stopSound();
void o2_endCutscene(); void o2_endCutscene();
void o2_decrement();
void o2_drawSentence(); void o2_drawSentence();
}; };

View file

@ -330,6 +330,25 @@ int Scumm::fetchScriptWordSigned() {
return (int16)fetchScriptWord(); 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 #ifndef BYPASS_COPY_PROT
#define BYPASS_COPY_PROT #define BYPASS_COPY_PROT
#endif #endif
@ -352,8 +371,13 @@ int Scumm::readVar(uint var) {
#endif #endif
checkRange(_numVariables - 1, 0, var, "Variable %d out of range(r)"); checkRange(_numVariables - 1, 0, var, "Variable %d out of range(r)");
if ((_features & GF_AFTER_V2) && (var >= 14) && (var <= 16)) {
return _vars[_vars[var]];
} else {
return _vars[var]; return _vars[var];
} }
}
if (var & 0x2000 && !(_features & GF_NEW_OPCODES)) { if (var & 0x2000 && !(_features & GF_NEW_OPCODES)) {
a = fetchScriptWord(); a = fetchScriptWord();
@ -470,9 +494,18 @@ void Scumm::writeVar(uint var, int value) {
error("Illegal varbits (w)"); error("Illegal varbits (w)");
} }
void Scumm::getResultPosDirect() {
_resultVarNumber = _vars[fetchScriptByte()];
}
void Scumm::getResultPos() { void Scumm::getResultPos() {
int a; int a;
if (_features & GF_AFTER_V2) {
_resultVarNumber = fetchScriptByte();
return;
}
_resultVarNumber = fetchScriptWord(); _resultVarNumber = fetchScriptWord();
if (_resultVarNumber & 0x2000) { if (_resultVarNumber & 0x2000) {
a = fetchScriptWord(); a = fetchScriptWord();

View file

@ -105,7 +105,7 @@ void Scumm_v2::setupOpcodes() {
/* 38 */ /* 38 */
OPCODE(o2_lessOrEqual), OPCODE(o2_lessOrEqual),
OPCODE(o2_doSentence), OPCODE(o2_doSentence),
OPCODE(o2_subtract), OPCODE(o5_subtract),
OPCODE(o2_waitForActor), OPCODE(o2_waitForActor),
/* 3C */ /* 3C */
OPCODE(o2_stopSound), OPCODE(o2_stopSound),
@ -120,7 +120,7 @@ void Scumm_v2::setupOpcodes() {
/* 44 */ /* 44 */
OPCODE(o2_isLess), OPCODE(o2_isLess),
OPCODE(o2_drawObject), OPCODE(o2_drawObject),
OPCODE(o2_increment), OPCODE(o5_increment),
OPCODE(o2_setState08), OPCODE(o2_setState08),
/* 48 */ /* 48 */
OPCODE(o2_isEqual), OPCODE(o2_isEqual),
@ -145,7 +145,7 @@ void Scumm_v2::setupOpcodes() {
/* 58 */ /* 58 */
OPCODE(beginOverride), OPCODE(beginOverride),
OPCODE(o2_doSentence), OPCODE(o2_doSentence),
OPCODE(o2_add), OPCODE(o5_add),
OPCODE(o2_setBitVar), OPCODE(o2_setBitVar),
/* 5C */ /* 5C */
OPCODE(o5_dummy), OPCODE(o5_dummy),
@ -265,7 +265,7 @@ void Scumm_v2::setupOpcodes() {
/* B8 */ /* B8 */
OPCODE(o2_lessOrEqual), OPCODE(o2_lessOrEqual),
OPCODE(o2_doSentence), OPCODE(o2_doSentence),
OPCODE(o2_subtract), OPCODE(o5_subtract),
OPCODE(o2_waitForActor), OPCODE(o2_waitForActor),
/* BC */ /* BC */
OPCODE(o2_stopSound), OPCODE(o2_stopSound),
@ -280,7 +280,7 @@ void Scumm_v2::setupOpcodes() {
/* C4 */ /* C4 */
OPCODE(o2_isLess), OPCODE(o2_isLess),
OPCODE(o2_drawObject), OPCODE(o2_drawObject),
OPCODE(o2_decrement), OPCODE(o5_decrement),
OPCODE(o2_clearState08), OPCODE(o2_clearState08),
/* C8 */ /* C8 */
OPCODE(o2_isEqual), OPCODE(o2_isEqual),
@ -305,7 +305,7 @@ void Scumm_v2::setupOpcodes() {
/* D8 */ /* D8 */
OPCODE(o2_printEgo), OPCODE(o2_printEgo),
OPCODE(o2_doSentence), OPCODE(o2_doSentence),
OPCODE(o2_add), OPCODE(o5_add),
OPCODE(o2_setBitVar), OPCODE(o2_setBitVar),
/* DC */ /* DC */
OPCODE(o5_dummy), OPCODE(o5_dummy),
@ -366,25 +366,6 @@ const char *Scumm_v2::getOpcodeDesc(int i) {
return _opcodesV2[i].desc; 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) { void Scumm_v2::setStateCommon(byte type) {
int obj = getVarOrDirectWord(0x80); int obj = getVarOrDirectWord(0x80);
putState(obj, getState(obj) | type); putState(obj, getState(obj) | type);
@ -433,32 +414,24 @@ void Scumm_v2::o2_clearState01() {
clearStateCommon(0x01); clearStateCommon(0x01);
} }
void Scumm_v2::getResultPos() { void Scumm_v2::o2_assignVarByteDirect() {
_resultVarNumber = fetchScriptByte(); getResultPosDirect();
} setResult(fetchScriptByte());
void Scumm_v2::getResultPosDirect() {
_resultVarNumber = _vars[fetchScriptByte()];
} }
void Scumm_v2::o2_assignVarWordDirect() { void Scumm_v2::o2_assignVarWordDirect() {
getResultPosDirect(); getResultPosDirect();
_vars[_resultVarNumber] = fetchScriptWord(); setResult(fetchScriptWord());
}
void Scumm_v2::o2_assignVarByteDirect() {
getResultPosDirect();
_vars[_resultVarNumber] = fetchScriptByte();
} }
void Scumm_v2::o2_assignVarByte() { void Scumm_v2::o2_assignVarByte() {
getResultPos(); getResultPos();
_vars[_resultVarNumber] = fetchScriptByte(); setResult(fetchScriptByte());
} }
void Scumm_v2::o2_assignVarWord() { void Scumm_v2::o2_assignVarWord() {
getResultPos(); getResultPos();
_vars[_resultVarNumber] = fetchScriptWord(); setResult(fetchScriptWord());
} }
void Scumm_v2::o2_setObjY() { void Scumm_v2::o2_setObjY() {
@ -746,7 +719,7 @@ void Scumm_v2::o2_verbOps() {
} }
void Scumm_v2::o2_isEqual() { void Scumm_v2::o2_isEqual() {
int a = getVar(); int a = readVar(fetchScriptByte());
int b = getVarOrDirectWord(0x80); int b = getVarOrDirectWord(0x80);
if (b == a) if (b == a)
@ -757,7 +730,7 @@ void Scumm_v2::o2_isEqual() {
} }
void Scumm_v2::o2_isGreater() { void Scumm_v2::o2_isGreater() {
int16 a = getVar(); int16 a = readVar(fetchScriptByte());
int16 b = getVarOrDirectWord(0x80); int16 b = getVarOrDirectWord(0x80);
if (b > a) if (b > a)
@ -767,7 +740,7 @@ void Scumm_v2::o2_isGreater() {
} }
void Scumm_v2::o2_isGreaterEqual() { void Scumm_v2::o2_isGreaterEqual() {
int16 a = getVar(); int16 a = readVar(fetchScriptByte());
int16 b = getVarOrDirectWord(0x80); int16 b = getVarOrDirectWord(0x80);
if (b >= a) if (b >= a)
@ -777,7 +750,7 @@ void Scumm_v2::o2_isGreaterEqual() {
} }
void Scumm_v2::o2_isLess() { void Scumm_v2::o2_isLess() {
int16 a = getVar(); int16 a = readVar(fetchScriptByte());
int16 b = getVarOrDirectWord(0x80); int16 b = getVarOrDirectWord(0x80);
if (b < a) if (b < a)
@ -787,7 +760,7 @@ void Scumm_v2::o2_isLess() {
} }
void Scumm_v2::o2_lessOrEqual() { void Scumm_v2::o2_lessOrEqual() {
int16 a = getVar(); int16 a = readVar(fetchScriptByte());
int16 b = getVarOrDirectWord(0x80); int16 b = getVarOrDirectWord(0x80);
if (b <= a) if (b <= a)
@ -797,7 +770,7 @@ void Scumm_v2::o2_lessOrEqual() {
} }
void Scumm_v2::o2_isNotEqual() { void Scumm_v2::o2_isNotEqual() {
int16 a = getVar(); int16 a = readVar(fetchScriptByte());
int16 b = getVarOrDirectWord(0x80); int16 b = getVarOrDirectWord(0x80);
if (b != a) if (b != a)
@ -807,7 +780,7 @@ void Scumm_v2::o2_isNotEqual() {
} }
void Scumm_v2::o2_notEqualZero() { void Scumm_v2::o2_notEqualZero() {
int a = getVar(); int a = readVar(fetchScriptByte());
if (a != 0) if (a != 0)
ignoreScriptWord(); ignoreScriptWord();
@ -816,7 +789,7 @@ void Scumm_v2::o2_notEqualZero() {
} }
void Scumm_v2::o2_equalZero() { void Scumm_v2::o2_equalZero() {
int a = getVar(); int a = readVar(fetchScriptByte());
if (a == 0) if (a == 0)
ignoreScriptWord(); ignoreScriptWord();
@ -1164,7 +1137,7 @@ void Scumm_v2::o2_setOwnerOf() {
} }
void Scumm_v2::o2_delayVariable() { void Scumm_v2::o2_delayVariable() {
vm.slot[_currentScript].delay = getVar(); vm.slot[_currentScript].delay = readVar(fetchScriptByte());
vm.slot[_currentScript].status = 1; vm.slot[_currentScript].status = 1;
o5_breakHere(); o5_breakHere();
} }
@ -1235,13 +1208,6 @@ void Scumm_v2::o2_findObject() {
_vars[_resultVarNumber] = findObject(x, y); _vars[_resultVarNumber] = findObject(x, y);
} }
void Scumm_v2::o2_subtract() {
int a;
getResultPos();
a = getVarOrDirectWord(0x80);
_vars[_resultVarNumber] -= a;
}
void Scumm_v2::o2_cutscene() { void Scumm_v2::o2_cutscene() {
// TODO // TODO
} }
@ -1250,16 +1216,6 @@ void Scumm_v2::o2_endCutscene() {
// TODO // TODO
} }
void Scumm_v2::o2_increment() {
getResultPos();
_vars[_resultVarNumber]++;
}
void Scumm_v2::o2_decrement() {
getResultPos();
_vars[_resultVarNumber]--;
}
void Scumm_v2::o2_chainScript() { void Scumm_v2::o2_chainScript() {
int data = getVarOrDirectByte(0x80); int data = getVarOrDirectByte(0x80);
int cur = _currentScript; int cur = _currentScript;
@ -1348,13 +1304,6 @@ void Scumm_v2::o2_getActorMoving() {
_vars[_resultVarNumber] = a->moving; _vars[_resultVarNumber] = a->moving;
} }
void Scumm_v2::o2_add() {
int a;
getResultPos();
a = getVarOrDirectWord(0x80);
_vars[_resultVarNumber] += a;
}
void Scumm_v2::o2_cursorCommand() { void Scumm_v2::o2_cursorCommand() {
getVarOrDirectWord(0x80); getVarOrDirectWord(0x80);
// TODO // TODO

View file

@ -512,9 +512,12 @@ protected:
void ignoreScriptWord() { fetchScriptWord(); } void ignoreScriptWord() { fetchScriptWord(); }
void ignoreScriptByte() { fetchScriptByte(); } void ignoreScriptByte() { fetchScriptByte(); }
void getResultPos(); void getResultPos();
void getResultPosDirect();
void setResult(int result); void setResult(int result);
void push(int a); void push(int a);
int pop(); int pop();
int getVarOrDirectByte(byte mask);
int getVarOrDirectWord(byte mask);
public: public:
virtual int readVar(uint var); // FIXME - should be protected, used in scumm/dialogs.cpp virtual int readVar(uint var); // FIXME - should be protected, used in scumm/dialogs.cpp
protected: protected: