SSBM Decomp
Loading...
Searching...
No Matches
platform.h
Go to the documentation of this file.
1#ifndef RUNTIME_PLATFORM_H
2#define RUNTIME_PLATFORM_H
3
4#include <stdbool.h> // IWYU pragma: export
5#include <stddef.h> // IWYU pragma: export
6
7#include <dolphin/types.h> // IWYU pragma: export
8#include <sys/types.h> // IWYU pragma: export
9
14#undef BOOL
15
20#undef FALSE
21
26#undef TRUE
27
29typedef int enum_t;
30
32typedef void (*Event)(void);
33
34typedef bool (*Predicate)(void);
35
36#if defined(__MWERKS__) && defined(__PPCGEKKO__)
37#define MWERKS_GEKKO
38#endif
39
40#if defined(__MWERKS__) && !defined(M2CTX)
41#define ASM asm
42#else
43#define ASM
44#endif
45
46#ifndef UNUSED
47#if defined(__clang__) || defined(__GNUC__)
48#define UNUSED __attribute__((unused))
49#define ATTRIBUTE_NORETURN __attribute__((noreturn))
50#define ATTRIBUTE_NONSTRING __attribute__((nonstring))
51#else
52#define UNUSED
53#define ATTRIBUTE_NORETURN
54#define ATTRIBUTE_NONSTRING
55#endif
56#endif
57
58#ifndef ATTRIBUTE_ALIGN
59#if defined(__MWERKS__) || defined(__GNUC__)
60#define ATTRIBUTE_ALIGN(num) __attribute__((aligned(num)))
61#elif defined(_MSC_VER)
62#define ATTRIBUTE_ALIGN(num)
63#else
64#error unknown compiler
65#endif
66#endif
67
68#ifndef AT_ADDRESS
69#ifdef PERMUTER
70#define AT_ADDRESS(x) = FIXEDADDR(x)
71#elif defined(__MWERKS__) && !defined(M2CTX)
72#define AT_ADDRESS(x) : (x)
73#else
74#define AT_ADDRESS(x)
75#endif
76#endif
77
78#ifdef MWERKS_GEKKO
79#define qr0 0
80#define qr1 1
81#define qr2 2
82#define qr3 3
83#define qr4 4
84#define qr5 5
85#define qr6 6
86#define qr7 7
87#endif
88
89#define U8_MAX 0xFF
90#define U16_MAX 0xFFFF
91#define U32_MAX 0xFFFFFFFF
92#define U64_MAX 0xFFFFFFFFFFFFFFFF
93#define S8_MAX 0x7F
94#define S16_MAX 0x7FFF
95#define S32_MAX 0x7FFFFFFF
96#define F32_MAX 3.4028235e38f
97
98#define SQ(x) ((x) * (x))
99#define MIN(a, b) (((a) < (b)) ? (a) : (b))
100#define MAX(a, b) (((a) > (b)) ? (a) : (b))
102#define SAT_ADD(a, b, max) (((a) + (b) > (max)) ? (max) : (a) + (b))
103
104#ifdef __cplusplus
105#ifndef _Static_assert
106#define _Static_assert static_assert
107#endif
108#endif
109#ifdef M2CTX
110#define STATIC_ASSERT(cond)
111#elif defined(__MWERKS__)
112#define STATIC_ASSERT(cond) \
113 struct { \
114 int x[1 - 2 * !(cond)]; \
115 };
116#elif defined(LINT)
117#define STATIC_ASSERT(cond) _Static_assert((cond), "(" #cond ") failed")
118#else
119#define STATIC_ASSERT(cond)
120#endif
121
122#if defined(MUST_MATCH) || defined(LINT)
123#define ASSERT_SIZE(expr, size) STATIC_ASSERT(sizeof(expr) == size)
124#define ASSERT_OFFSET(type, member, offset) \
125 STATIC_ASSERT(offsetof(type, member) == offset)
126#else
127#define ASSERT_SIZE(expr, size)
128#define ASSERT_OFFSET(expr, member, offset)
129#endif
130
131#define RETURN_IF(cond) \
132 do { \
133 if ((cond)) { \
134 return; \
135 } \
136 } while (0)
137
138#if defined(__MWERKS__) && !defined(M2CTX)
139#define SDATA __declspec(section ".sdata")
140#define DATA __declspec(section ".data")
141#define WEAK __declspec(weak)
142#define SECTION_INIT __declspec(section ".init")
143#define SECTION_CTORS __declspec(section ".ctors")
144#define SECTION_DTORS __declspec(section ".dtors")
145#define ATTRIBUTE_RESTRICT __restrict
146#else
147#define SDATA
148#define DATA
149#define WEAK
150#define SECTION_INIT
151#define SECTION_CTORS
152#define SECTION_DTORS
153#define ATTRIBUTE_RESTRICT
154#endif
155
156#define M_PI 3.14159265358979323846
157#define M_PI_2 (M_PI / 2)
158
159#define M_TAU 6.283185307179586
160#define M_PI_3 (M_PI / 3)
161
162#define M_PI_F 3.14159265358979323846F
163#define M_TAU_F 6.283185307179586F
164#define M_PI_2_F (M_PI_F / 2.0F)
165#define M_PI_3_F (M_PI_F / 3.0F)
166
167#define M_PI_L 3.14159265358979323846L
168#define M_TAU_L 6.283185307179586L
169#define M_PI_2_L (M_PI_L / 2.0L)
170#define M_PI_3_L (M_PI_L / 3.0L)
171
172#define SIGNF(x) ((x) > 0.0f ? 1.0f : -1.0f)
173
174#define FLT_EPSILON 1.00000001335e-10F
175
176#define ABS(x) ((x) < 0 ? -(x) : (x))
177
178#ifndef ARRAY_SIZE
179#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
180#endif
181
182#endif
bool(* Predicate)(void)
Definition platform.h:34
int enum_t
The underlying type of an enum, used as a placeholder.
Definition platform.h:29
void(* Event)(void)
A void callback with no arguments.
Definition platform.h:32
int bool
A signed integer used to contain boolean values.
Definition stdbool.h:6