Add SAFE_DIV

This commit is contained in:
GriffinR
2021-03-19 18:17:43 -04:00
committed by huderlem
parent 28aff5b179
commit dfc6ee0e9e
6 changed files with 15 additions and 29 deletions

View File

@@ -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)