summaryrefslogtreecommitdiff
path: root/include/Runtime/platform.h
blob: ef6538bf0bf89d4791236b56b825936e5c7e8d10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#ifndef INCLUDE_RUNTIME_PLATFORM_H
#define INCLUDE_RUNTIME_PLATFORM_H

#if defined(__MWERKS__) || defined(__GNUC__)
#define MWERKS_GNUC
#endif

#include <stdbool.h>
#include <stddef.h>

/// A signed 8-bit integer
typedef signed char s8;

/// A signed 16-bit integer
typedef signed short s16;

/// A signed 32-bit integer
typedef signed long s32;

/// A signed 64-bit integer
typedef signed long long s64;

/// An unsigned 8-bit integer
typedef unsigned char u8;

/// An unsigned 16-bit integer
typedef unsigned short u16;

/// An unsigned 32-bit integer
typedef unsigned long u32;

/// An unsigned 64-bit integer
typedef unsigned long long u64;

/// An unsigned integer of platform-dependent size
typedef unsigned int uint;

/// A volatile, unsigned 8-bit integer
typedef volatile u8 vu8;

/// A volatile, unsigned 16-bit integer
typedef volatile u16 vu16;

/// A volatile, unsigned 32-bit integer
typedef volatile u32 vu32;

/// A volatile, unsigned 64-bit integer
typedef volatile u64 vu64;

/// A volatile, signed 8-bit integer
typedef volatile s8 vs8;

/// A volatile, signed 16-bit integer
typedef volatile s16 vs16;

/// A volatile, signed 32-bit integer
typedef volatile s32 vs32;

/// A volatile, signed 64-bit integer
typedef volatile s64 vs64;

/// A 32-bit floating-point number
typedef float f32;

/// A 64-bit floating-point number
typedef double f64;

/// A volatile 32-bit floating-point number
typedef volatile f32 vf32;

/// A volatile 64-bit floating-point number
typedef volatile f64 vf64;

/// The underlying type of an @c enum, used as a placeholder
typedef int enum_t;

/// A pointer to an unknown type
typedef void* unk_t;

/// A pointer to an unspecified type, used for polymorphic data
typedef void* any_t;

/// A label in a jump table
typedef void (*jmp_t)(void);

/// A jump table
typedef jmp_t jtbl_t[];

/// A @c void callback with no arguments.
typedef void (*Event)(void);

#if defined(__MWERKS__) && defined(__PPCGEKKO__)
#define MWERKS_GEKKO
#endif

#ifndef ATTRIBUTE_ALIGN
#if defined(__MWERKS__) || defined(__GNUC__)
#define ATTRIBUTE_ALIGN(num) __attribute__((aligned(num)))
#elif defined(_MSC_VER)
#define ATTRIBUTE_ALIGN(num)
#else
#error unknown compiler
#endif
#endif

#ifndef SECTION_INIT
#if defined(__MWERKS__) && !defined(M2CTX)
#define SECTION_INIT __declspec(section ".init")
#else
#define SECTION_INIT
#endif
#endif

#ifndef ATTRIBUTE_NORETURN
#if defined(__clang__) || defined(__GNUC__)
#define ATTRIBUTE_NORETURN __attribute__((noreturn))
#else
#define ATTRIBUTE_NORETURN
#endif
#endif

#ifdef PERMUTER
#define AT_ADDRESS(x) = FIXEDADDR(x)
#elif defined(__MWERKS__) && !defined(M2CTX)
#define AT_ADDRESS(x) : (x)
#else
#define AT_ADDRESS(x)
#endif

#ifndef UNK_SIZE_ARRAY
#if defined(__MWERKS__) && !defined(M2CTX)
#define UNK_SIZE_ARRAY []
#else
#define UNK_SIZE_ARRAY [0]
#endif
#endif

#ifdef __PPCGEKKO__
#define qr0 0
#define qr1 1
#define qr2 2
#define qr3 3
#define qr4 4
#define qr5 5
#define qr6 6
#define qr7 7
#endif

#define U8_MAX 0xFF
#define U16_MAX 0xFFFF
#define U32_MAX 0xFFFFFFFF
#define F32_MAX 3.4028235E38

#define FLAGS_ZERO 0
#define FLAGS_ANY(value, flag) ((value) & (flag))
#define FLAGS_NONE(value, flag) (!((value) & (flag)))
#define FLAGS_ALL(value, flag) (((value) & (flag)) == (flag))

#endif