[Scummvm-cvs-logs] SF.net SVN: scummvm:[55277] scummvm/trunk/engines/gob
drmccoy at users.sourceforge.net
drmccoy at users.sourceforge.net
Mon Jan 17 14:37:15 CET 2011
Revision: 55277
http://scummvm.svn.sourceforge.net/scummvm/?rev=55277&view=rev
Author: drmccoy
Date: 2011-01-17 13:37:14 +0000 (Mon, 17 Jan 2011)
Log Message:
-----------
GOB: Make the variable stack endianness-independent
Since Urban Runner casts int16s to uint32 before pushing them onto the
stack and after popping assumes it's little endian, we have explicitely
preserve the variable space endianness while pushing/popping.
Modified Paths:
--------------
scummvm/trunk/engines/gob/inter.cpp
scummvm/trunk/engines/gob/inter.h
scummvm/trunk/engines/gob/inter_v2.cpp
scummvm/trunk/engines/gob/variables.cpp
scummvm/trunk/engines/gob/variables.h
Modified: scummvm/trunk/engines/gob/inter.cpp
===================================================================
--- scummvm/trunk/engines/gob/inter.cpp 2011-01-17 12:09:06 UTC (rev 55276)
+++ scummvm/trunk/engines/gob/inter.cpp 2011-01-17 13:37:14 UTC (rev 55277)
@@ -39,7 +39,7 @@
namespace Gob {
-Inter::Inter(GobEngine *vm) : _vm(vm) {
+Inter::Inter(GobEngine *vm) : _vm(vm), _varStack(600) {
_terminate = 0;
_break = false;
@@ -55,9 +55,6 @@
_soundEndTimeKey = 0;
_soundStopVal = 0;
- memset(_varStack, 0, 300);
- _varStackPos = 0;
-
_noBusyWait = false;
_variables = 0;
Modified: scummvm/trunk/engines/gob/inter.h
===================================================================
--- scummvm/trunk/engines/gob/inter.h 2011-01-17 12:09:06 UTC (rev 55276)
+++ scummvm/trunk/engines/gob/inter.h 2011-01-17 13:37:14 UTC (rev 55277)
@@ -129,8 +129,7 @@
int16 _animPalHighIndex[8];
int16 _animPalDir[8];
- byte _varStack[300];
- int16 _varStackPos;
+ VariableStack _varStack;
// The busy-wait detection in o1_keyFunc breaks fast scrolling in Ween
bool _noBusyWait;
Modified: scummvm/trunk/engines/gob/inter_v2.cpp
===================================================================
--- scummvm/trunk/engines/gob/inter_v2.cpp 2011-01-17 12:09:06 UTC (rev 55276)
+++ scummvm/trunk/engines/gob/inter_v2.cpp 2011-01-17 13:37:14 UTC (rev 55277)
@@ -609,49 +609,33 @@
}
void Inter_v2::o2_pushVars() {
- byte count;
- int16 varOff;
-
- count = _vm->_game->_script->readByte();
- for (int i = 0; i < count; i++, _varStackPos++) {
+ uint8 count = _vm->_game->_script->readByte();
+ for (int i = 0; i < count; i++) {
if ((_vm->_game->_script->peekByte() == 25) ||
(_vm->_game->_script->peekByte() == 28)) {
- varOff = _vm->_game->_script->readVarIndex();
+ int16 varOff = _vm->_game->_script->readVarIndex();
_vm->_game->_script->skip(1);
- _variables->copyTo(varOff, _varStack + _varStackPos, _vm->_global->_inter_animDataSize * 4);
+ _varStack.pushData(*_variables, varOff, _vm->_global->_inter_animDataSize * 4);
- _varStackPos += _vm->_global->_inter_animDataSize * 4;
- _varStack[_varStackPos] = _vm->_global->_inter_animDataSize * 4;
-
} else {
int16 value;
if (_vm->_game->_script->evalExpr(&value) != 20)
value = 0;
- uint32 value32 = ((uint16) value);
-
- memcpy(_varStack + _varStackPos, &value32, 4);
- _varStackPos += 4;
- _varStack[_varStackPos] = 4;
+ _varStack.pushInt((uint16)value);
}
}
}
void Inter_v2::o2_popVars() {
- byte count;
- int16 varOff;
- int16 size;
-
- count = _vm->_game->_script->readByte();
+ uint8 count = _vm->_game->_script->readByte();
for (int i = 0; i < count; i++) {
- varOff = _vm->_game->_script->readVarIndex();
- size = _varStack[--_varStackPos];
+ int16 varOff = _vm->_game->_script->readVarIndex();
- _varStackPos -= size;
- _variables->copyFrom(varOff, _varStack + _varStackPos, size);
+ _varStack.pop(*_variables, varOff);
}
}
Modified: scummvm/trunk/engines/gob/variables.cpp
===================================================================
--- scummvm/trunk/engines/gob/variables.cpp 2011-01-17 12:09:06 UTC (rev 55276)
+++ scummvm/trunk/engines/gob/variables.cpp 2011-01-17 13:37:14 UTC (rev 55277)
@@ -286,4 +286,65 @@
return (*this = (*this * value));
}
+
+VariableStack::VariableStack(uint32 size) : _size(size), _position(0) {
+ _stack = new byte[_size];
+
+ memset(_stack, 0, _size);
+}
+
+VariableStack::~VariableStack() {
+ delete[] _stack;
+}
+
+void VariableStack::pushData(const Variables &vars, uint32 offset, uint32 size) {
+ // Sanity checks
+ assert(size < 256);
+ assert((_position + size) < _size);
+
+ vars.copyTo(offset, _stack + _position, size);
+
+ _position += size;
+ _stack[_position++] = size;
+ _stack[_position++] = 0;
+}
+
+void VariableStack::pushInt(uint32 value) {
+ // Sanity check
+ assert((_position + 4) < _size);
+
+ memcpy(_stack + _position, &value, 4);
+
+ _position += 4;
+ _stack[_position++] = 4;
+ _stack[_position++] = 1;
+}
+
+void VariableStack::pop(Variables &vars, uint32 offset) {
+ // Sanity check
+ assert(_position >= 2);
+
+ bool isInt = _stack[--_position] == 1;
+ uint32 size = _stack[--_position];
+
+ // Sanity check
+ assert(_position >= size);
+
+ _position -= size;
+
+ if (isInt) {
+ // If it's an int, explicitely call the int variable writing method,
+ // to make sure the variable space endianness is preserved.
+
+ assert(size == 4);
+
+ uint32 value;
+ memcpy(&value, _stack + _position, 4);
+
+ vars.writeOff32(offset, value);
+ } else
+ // Otherwise, use do a raw copy
+ vars.copyFrom(offset, _stack + _position, size);
+}
+
} // End of namespace Gob
Modified: scummvm/trunk/engines/gob/variables.h
===================================================================
--- scummvm/trunk/engines/gob/variables.h 2011-01-17 12:09:06 UTC (rev 55276)
+++ scummvm/trunk/engines/gob/variables.h 2011-01-17 13:37:14 UTC (rev 55277)
@@ -148,6 +148,23 @@
Variables::Type _type;
};
+class VariableStack {
+public:
+ VariableStack(uint32 size);
+ ~VariableStack();
+
+ void pushData(const Variables &vars, uint32 offset, uint32 size);
+ void pushInt(uint32 value);
+
+ void pop(Variables &vars, uint32 offset);
+
+private:
+ byte *_stack;
+
+ uint32 _size;
+ uint32 _position;
+};
+
} // End of namespace Gob
#endif // GOB_VARIABLES_H
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list