aboutsummaryrefslogtreecommitdiff
path: root/engines/cge2
diff options
context:
space:
mode:
authorPaul Gilbert2014-06-12 23:49:06 -0400
committerPaul Gilbert2014-06-12 23:49:06 -0400
commit162c840937027ae2935fddd7d660c28713a7b004 (patch)
tree5b392a6584296cdfa8c4f18b59ee046f6785f799 /engines/cge2
parentdfc94267d568a8e7b261961417fdf5716717cbd0 (diff)
downloadscummvm-rg350-162c840937027ae2935fddd7d660c28713a7b004.tar.gz
scummvm-rg350-162c840937027ae2935fddd7d660c28713a7b004.tar.bz2
scummvm-rg350-162c840937027ae2935fddd7d660c28713a7b004.zip
CGE2: Fix FXP initialiation and division operator
Diffstat (limited to 'engines/cge2')
-rw-r--r--engines/cge2/vga13h.h35
1 files changed, 19 insertions, 16 deletions
diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h
index 73667bca91..dee551fe82 100644
--- a/engines/cge2/vga13h.h
+++ b/engines/cge2/vga13h.h
@@ -58,7 +58,7 @@ class FXP // fixed point
int16 i;
long& Joined (void) const { return *(long *)&f; }
public:
- FXP (void) { }
+ FXP (void): f(0), i(0) { }
FXP (int i0, int f0 = 0) : i(i0), f((int) ((((long) f0) << 16)/100)) { }
FXP& operator = (const int& x) { i = x; f = 0; return *this; }
FXP operator + (const FXP& x) const { FXP y; y.Joined() = Joined()+x.Joined(); return y; }
@@ -74,22 +74,24 @@ public:
}
FXP operator / (const FXP& x) const {
FXP y; bool sign = false;
- long j = Joined(), jx = x.Joined();
- if (j < 0) {
- j = -j;
- sign ^= 1;
+ if (!x.empty()) {
+ long j = Joined(), jx = x.Joined();
+ if (j < 0) {
+ j = -j;
+ sign ^= 1;
+ }
+ if (jx < 0) {
+ jx = -jx;
+ sign ^= 1;
+ }
+ y.i = signed(j / jx);
+ long r = j - jx * y.i;
+ //-- binary division
+ y.f = unsigned((r << 4) / (jx >> 12));
+ //------------------
+ if (sign)
+ y.Joined() = -y.Joined();
}
- if (jx < 0) {
- jx = -jx;
- sign ^= 1;
- }
- y.i = signed(j / jx);
- long r = j - jx * y.i;
- //-- binary division
- y.f = unsigned((r << 4) / (jx >> 12));
- //------------------
- if (sign)
- y.Joined() = -y.Joined();
return y;
}
@@ -104,6 +106,7 @@ public:
friend bool operator > (const FXP &a, const FXP &b) { return (a.i > b.i) || ((a.i == b.i) && (a.f > b.f)); }
int trunc(void) const { return i; }
int round(void) const { return i + (f > 0x7FFF); }
+ bool empty() const { return i == 0 && f == 0; }
};
// From CGETYPE.H: