summaryrefslogtreecommitdiff
path: root/include/global.h
diff options
context:
space:
mode:
authorMarcus Huderle <huderlem@gmail.com>2018-10-11 12:27:06 -0500
committerMarcus Huderle <huderlem@gmail.com>2018-10-11 12:27:06 -0500
commitc0ce4f82ad10178eab328cb0da3f03639c3b5b8e (patch)
tree3996e049c7bf2dcbc17c651dc24628e92e80068e /include/global.h
parentad3ef8944eb4e1291c1ac9bcf06a9f5779b20c55 (diff)
Match first C function
Diffstat (limited to 'include/global.h')
-rwxr-xr-xinclude/global.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/include/global.h b/include/global.h
new file mode 100755
index 0000000..e7132a4
--- /dev/null
+++ b/include/global.h
@@ -0,0 +1,59 @@
+#ifndef GUARD_GLOBAL_H
+#define GUARD_GLOBAL_H
+
+#include <string.h>
+#include "gba/gba.h"
+
+// Prevent cross-jump optimization.
+#define BLOCK_CROSS_JUMP asm("");
+
+// to help in decompiling
+#define asm_comment(x) asm volatile("@ -- " x " -- ")
+#define asm_unified(x) asm(".syntax unified\n" x "\n.syntax divided")
+#define NAKED __attribute__((naked))
+
+// IDE support
+#if defined (__APPLE__) || defined (__CYGWIN__) || defined (_MSC_VER)
+#define _(x) x
+#define __(x) x
+#define INCBIN_U8 {0}
+#define INCBIN_U16 {0}
+#define INCBIN_U32 {0}
+#define INCBIN_S8 {0}
+#define INCBIN_S16 {0}
+#define INCBIN_S32 {0}
+#endif // IDE support
+
+#define ARRAY_COUNT(array) (size_t)(sizeof(array) / sizeof((array)[0]))
+
+#define SWAP(a, b, temp) \
+{ \
+ temp = a; \
+ a = b; \
+ b = temp; \
+}
+
+// useful math macros
+
+// Converts a number to Q8.8 fixed-point format
+#define Q_8_8(n) ((s16)((n) * 256))
+
+// Converts a number to Q4.12 fixed-point format
+#define Q_4_12(n) ((s16)((n) * 4096))
+
+// Converts a number to Q24.8 fixed-point format
+#define Q_24_8(n) ((s32)((n) * 256))
+
+// Converts a Q8.8 fixed-point format number to a regular integer
+#define Q_8_8_TO_INT(n) ((int)((n) / 256))
+
+// Converts a Q4.12 fixed-point format number to a regular integer
+#define Q_4_12_TO_INT(n) ((int)((n) / 4096))
+
+// Converts a Q24.8 fixed-point format number to a regular integer
+#define Q_24_8_TO_INT(n) ((int)((n) >> 8))
+
+#define min(a, b) ((a) < (b) ? (a) : (b))
+#define max(a, b) ((a) >= (b) ? (a) : (b))
+
+#endif // GUARD_GLOBAL_H