aboutsummaryrefslogtreecommitdiff
path: root/engines/macventure
diff options
context:
space:
mode:
authorBorja Lorente2016-08-17 17:19:05 +0200
committerBorja Lorente2016-08-19 16:30:25 +0200
commit69f2302a1adb9ead458e38a45429477eac2b6ce4 (patch)
treef036a4071033ba945337b55455951827a25b4dd1 /engines/macventure
parent97af2b6e14ab25e37aa0c3d226c0264ac2a8ec12 (diff)
downloadscummvm-rg350-69f2302a1adb9ead458e38a45429477eac2b6ce4.tar.gz
scummvm-rg350-69f2302a1adb9ead458e38a45429477eac2b6ce4.tar.bz2
scummvm-rg350-69f2302a1adb9ead458e38a45429477eac2b6ce4.zip
MACVENTURE: Remove JavaScript constructs
Diffstat (limited to 'engines/macventure')
-rw-r--r--engines/macventure/image.cpp2
-rw-r--r--engines/macventure/macventure.cpp2
-rw-r--r--engines/macventure/script.cpp16
-rw-r--r--engines/macventure/script.h1
-rw-r--r--engines/macventure/sound.cpp15
5 files changed, 24 insertions, 12 deletions
diff --git a/engines/macventure/image.cpp b/engines/macventure/image.cpp
index f0146e344a..aeb5a501a8 100644
--- a/engines/macventure/image.cpp
+++ b/engines/macventure/image.cpp
@@ -187,7 +187,7 @@ void ImageAsset::decodePPIC3(Common::BitStream &stream, Common::Array<byte> &dat
v = stream.getBits(bits);
while ((bits = loadBits[load++]) != 0xFF) {
huff.symbols[loadBits[load++]] = v % bits;
- v = (v / bits) | 0;
+ v = (bits != 0) ? (v / bits) : 0;
}
huff.symbols[loadBits[load++]] = v;
}
diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp
index e28bc4e9ba..b6fcba5d91 100644
--- a/engines/macventure/macventure.cpp
+++ b/engines/macventure/macventure.cpp
@@ -1043,7 +1043,7 @@ uint MacVentureEngine::getOverlapPercent(ObjID one, ObjID other) {
oneBounds.intersects(otherBounds)) {
uint areaOne = oneBounds.width() * oneBounds.height();
uint areaOther = otherBounds.width() * otherBounds.height();
- return (areaOther * 100 / areaOne) | 0;
+ return (areaOne != 0) ? (areaOther * 100 / areaOne) : 0;
}
return 0;
}
diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp
index e18bf65979..d3731489e4 100644
--- a/engines/macventure/script.cpp
+++ b/engines/macventure/script.cpp
@@ -525,6 +525,13 @@ int16 ScriptEngine::sumChildrenAttr(int16 obj, int16 attr, bool recursive) {
return sum;
}
+void ScriptEngine::ensureNonzeroDivisor(int16 divisor, byte opcode) {
+ // TODO Untested, since that occassion rarely comes up.
+ if (divisor == 0) {
+ error("SCRIPT: Attempt to divide by 0 in operation %x", opcode);
+ }
+}
+
void MacVenture::ScriptEngine::op80GATT(EngineState *state, EngineFrame *frame) {
int16 obj = state->pop();
int16 attr = state->pop();
@@ -704,7 +711,8 @@ void ScriptEngine::op9aMUL(EngineState *state, EngineFrame *frame) {
void ScriptEngine::op9bDIV(EngineState *state, EngineFrame *frame) {
int16 b = state->pop();
int16 a = state->pop();
- state->push((a / b) | 0);
+ ensureNonzeroDivisor(b, 0x9b);
+ state->push(a / b);
}
void ScriptEngine::op9cMOD(EngineState *state, EngineFrame *frame) {
@@ -716,8 +724,9 @@ void ScriptEngine::op9cMOD(EngineState *state, EngineFrame *frame) {
void ScriptEngine::op9dDMOD(EngineState *state, EngineFrame *frame) {
int16 b = state->pop();
int16 a = state->pop();
+ ensureNonzeroDivisor(b, 0x9d);
state->push(a % b);
- state->push((a / b) | 0);
+ state->push(a / b);
}
void ScriptEngine::op9eABS(EngineState *state, EngineFrame *frame) {
@@ -1166,8 +1175,9 @@ void ScriptEngine::ope2MDIV(EngineState *state, EngineFrame *frame) {
int16 a = state->pop();
a *= b;
int16 c = state->pop();
+ ensureNonzeroDivisor(c, 0xe2);
a /= c;
- state->push(a | 0);
+ state->push(a);
}
void ScriptEngine::ope3UPOB(EngineState *state, EngineFrame *frame) {
diff --git a/engines/macventure/script.h b/engines/macventure/script.h
index e5ad6e5f6c..0e81e41168 100644
--- a/engines/macventure/script.h
+++ b/engines/macventure/script.h
@@ -157,6 +157,7 @@ private:
int16 neg16(int16 val);
int16 neg8(int16 val);
int16 sumChildrenAttr(int16 obj, int16 attr, bool recursive);
+ void ensureNonzeroDivisor(int16 divisor, byte opcode);
// Opcodes
void op80GATT(EngineState *state, EngineFrame *frame); //get attribute
diff --git a/engines/macventure/sound.cpp b/engines/macventure/sound.cpp
index fd39e2bf5e..422e365790 100644
--- a/engines/macventure/sound.cpp
+++ b/engines/macventure/sound.cpp
@@ -126,7 +126,7 @@ void SoundAsset::decode10(Common::SeekableReadStream *stream) {
_length = stream->readUint32BE() * 2;
//Unused
stream->readUint16BE();
- _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0;
+ _frequency = (stream->readUint32BE() * 22100 / 0x10000);
byte ch = 0;
for (uint i = 0; i < _length; i++) {
if (i & 1) {
@@ -147,7 +147,7 @@ void SoundAsset::decode12(Common::SeekableReadStream *stream) {
stream->seek(base, SEEK_SET);
_length = stream->readUint32BE() - 6;
stream->readUint16BE();
- _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0;
+ _frequency = (stream->readUint32BE() * 22100 / 0x10000);
stream->seek(0xe2, SEEK_SET);
// TODO: Possible source of bugs, the original just assigns the seek to the scales
uint32 scales = stream->pos() + 0xe2;
@@ -191,7 +191,8 @@ void SoundAsset::decode18(Common::SeekableReadStream *stream) {
_length = stream->readUint32BE() * 2;
//Unused
stream->readUint16BE();
- _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0;
+ // TODO: It had `| 0` at the end of this line, possible source of bugs.
+ _frequency = (stream->readUint32BE() * 22100 / 0x10000);
byte ch = 0;
for (uint i = 0; i < _length; i++) {
if (i & 1) {
@@ -213,7 +214,7 @@ void SoundAsset::decode1a(Common::SeekableReadStream *stream) {
_length = stream->readUint32BE();
//Unused
stream->readUint16BE();
- _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0;
+ _frequency = (stream->readUint32BE() * 22100 / 0x10000);
byte ch = 0;
for (uint i = 0; i < _length; i++) {
if (i & 1) {
@@ -228,7 +229,7 @@ void SoundAsset::decode1a(Common::SeekableReadStream *stream) {
void SoundAsset::decode44(Common::SeekableReadStream *stream) {
stream->seek(0x5e, SEEK_SET);
_length = stream->readUint32BE();
- _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0;
+ _frequency = (stream->readUint32BE() * 22100 / 0x10000);
for (uint i = 0; i < _length; i++) {
_data.push_back(stream->readByte());
}
@@ -243,7 +244,7 @@ void SoundAsset::decode78(Common::SeekableReadStream *stream) {
//Unused
stream->readUint32BE();
_length = stream->readUint32BE();
- _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0;
+ _frequency = (stream->readUint32BE() * 22100 / 0x10000);
byte ch = 0;
for (uint i = 0; i < _length; i++) {
if (i & 1) {
@@ -264,7 +265,7 @@ void SoundAsset::decode7e(Common::SeekableReadStream *stream) {
//Unused
stream->readUint32BE();
_length = stream->readUint32BE();
- _frequency = (stream->readUint32BE() * 22100 / 0x10000) | 0;
+ _frequency = (stream->readUint32BE() * 22100 / 0x10000);
uint32 last = 0x80;
byte ch = 0;
for (uint i = 0; i < _length; i++) {