aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/cge2/vga13h.cpp45
-rw-r--r--engines/cge2/vga13h.h4
2 files changed, 47 insertions, 2 deletions
diff --git a/engines/cge2/vga13h.cpp b/engines/cge2/vga13h.cpp
index 9340abf09e..cdf683d380 100644
--- a/engines/cge2/vga13h.cpp
+++ b/engines/cge2/vga13h.cpp
@@ -45,6 +45,51 @@ void V3D::sync(Common::Serializer &s) {
_z.sync(s);
}
+FXP FXP::operator*(const FXP& x) const {
+ FXP y;
+ int32 t1 = (v >> 8) * x.v;
+ int32 t2 = (v & 0xFF) * x.v;
+
+ y.v = t1 + t2;
+ return y;
+}
+
+FXP FXP::operator/(const FXP& x) const {
+ FXP y;
+ if (x.v != 0) {
+ int32 v1 = this->v;
+ int32 v2 = x.v;
+ bool negFlag = false;
+
+ if (v1 < 0) {
+ v1 = -v1;
+ negFlag = true;
+ }
+ if (v2 < 0) {
+ v2 = -v2;
+ negFlag ^= true;
+ }
+
+ int32 v3 = v1 / v2;
+ v1 -= v3 * v2;
+ v3 <<= 8;
+
+ if (v1 < 0xFFFFFF) {
+ v1 <<= 8;
+ } else {
+ v2 >>= 8;
+ }
+ v3 += v1 / v2;
+
+ if (negFlag)
+ v3 = -v3;
+
+ y.v = v3;
+ }
+
+ return y;
+}
+
void FXP::sync(Common::Serializer &s) {
s.syncAsSint32LE(v);
}
diff --git a/engines/cge2/vga13h.h b/engines/cge2/vga13h.h
index f3354c5489..52efd39849 100644
--- a/engines/cge2/vga13h.h
+++ b/engines/cge2/vga13h.h
@@ -60,8 +60,8 @@ public:
FXP& operator=(const int& x) { v = x << 8; return *this; }
FXP operator+(const FXP& x) const { FXP y; y.v = v + x.v; return y; }
FXP operator-(const FXP& x) const { FXP y; y.v = v - x.v; return y; }
- FXP operator*(const FXP& x) const { FXP y; y.v = v * x.v / 256; return y; }
- FXP operator/(const FXP& x) const { FXP y; y.v = (x.v == 0) ? 0 : v * 256 / x.v; return y; }
+ FXP operator*(const FXP& x) const;
+ FXP operator/(const FXP& x) const;
//int& operator = (int& a, const FXP& b) { return a = b.i; }
friend int& operator+=(int& a, const FXP& b) { return a += b.trunc(); }