summaryrefslogtreecommitdiff
path: root/include/global.h
diff options
context:
space:
mode:
authorGriffinR <griffin.g.richards@gmail.com>2021-03-19 18:17:43 -0400
committerhuderlem <huderlem@gmail.com>2021-03-21 13:43:14 -0500
commitdfc6ee0e9e20658a80e4080da16c2f6423b85457 (patch)
treec7b56332eb5fcb99e4b2b10ae7eb6ec59346f744 /include/global.h
parent28aff5b179d14aa8cb440d2f72c3e098482f6a75 (diff)
Add SAFE_DIV
Diffstat (limited to 'include/global.h')
-rw-r--r--include/global.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/include/global.h b/include/global.h
index 1992ff819..112d2cbc4 100644
--- a/include/global.h
+++ b/include/global.h
@@ -74,6 +74,14 @@
#define abs(x) (((x) < 0) ? -(x) : (x))
#endif
+// Used in cases where division by 0 can occur in the retail version.
+// Avoids invalid opcodes on some emulators, and the otherwise UB.
+#ifdef UBFIX
+#define SAFE_DIV(a, b) ((b) ? (a) / (b) : 0)
+#else
+#define SAFE_DIV(a, b) ((a) / (b))
+#endif
+
// Extracts the upper 16 bits of a 32-bit number
#define HIHALF(n) (((n) & 0xFFFF0000) >> 16)