OpenSNES
Modern Open-Source SNES Development SDK
Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1
20
21#ifndef OPENSNES_TYPES_H
22#define OPENSNES_TYPES_H
23
24/*============================================================================
25 * Fixed-Width Integer Types
26 *============================================================================*/
27
42
44typedef signed char s8;
45
47typedef unsigned char u8;
48
50typedef signed short s16;
51
53typedef unsigned short u16;
54
76#ifdef __OPENSNES__
77typedef signed long s32;
78#else
79typedef signed int s32;
80#endif
81
87#ifdef __OPENSNES__
88typedef unsigned long u32;
89#else
90typedef unsigned int u32;
91#endif
92 /* end of types group */
94
95/*============================================================================
96 * Volatile Types
97 *============================================================================*/
98
107
127#ifdef __OPENSNES__
128#define FAR __far
129#else
130#define FAR /* host compilers (the clang syntax lint) have no address spaces */
131#endif
132
146#ifdef __OPENSNES__
147#define RAM_CODE __ramcode
148#else
149#define RAM_CODE /* host compilers (the clang syntax lint) */
150#endif
151
152typedef volatile u8 vu8;
153typedef volatile u16 vu16;
154typedef volatile u32 vu32;
155typedef volatile s8 vs8;
156typedef volatile s16 vs16;
157typedef volatile s32 vs32;
158
160
161/*============================================================================
162 * Boolean Type
163 *============================================================================*/
164
180
181/*
182 * Bool type compatibility — CORRECTED 2026-09-20. C11 has `_Bool` built in,
183 * but `bool` / `true` / `false` come from <stdbool.h>, which this freestanding
184 * SDK does not ship: on cproc (the only supported compiler) `bool` is NOT
185 * defined, and the branch below — for pre-C99 compilers — is dead. No public
186 * function uses `bool`; every predicate returns `u8` 0 / 1 (unified
187 * 2026-09-22, API audit 3.2 — TRUE was 0xFF until then).
188 */
189#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
190typedef unsigned char bool;
191#define false 0
192#define true 1
193#endif
194
195/* TRUE is 1 since 2026-09-22. It was 0xFF (a PVSnesLib habit): `isPAL() ==
196 * 1` was false on PAL, and `if (x == TRUE)` failed on every predicate that
197 * returned 1. Every predicate of this SDK now returns 0 or 1, and the three
198 * that returned TRUE (isPAL, isInVBlank, padIsConnected) return 1. Compare
199 * with `if (pred())`, never with a literal — that works under both values. */
200#define FALSE 0
201#define TRUE 1
202
204
205/*============================================================================
206 * Common Macros
207 *============================================================================*/
208
214
216#ifndef NULL
217#define NULL ((void*)0)
218#endif
219
235#define BIT(n) (1u << (n))
236
242#define LO_BYTE(x) ((u8)((x) & 0xFF))
243
249#define HI_BYTE(x) ((u8)(((x) >> 8) & 0xFF))
250
257#define MAKE_WORD(lo, hi) ((u16)(((u8)(hi) << 8) | (u8)(lo)))
258
262#define MIN(a, b) (((a) < (b)) ? (a) : (b))
263
267#define MAX(a, b) (((a) > (b)) ? (a) : (b))
268
275#define CLAMP(x, lo, hi) (((x) < (lo)) ? (lo) : (((x) > (hi)) ? (hi) : (x)))
276
282#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
283
285
286/*============================================================================
287 * Function Pointer Types
288 *============================================================================*/
289
295
299typedef void (*VoidFn)(void);
300
302
303/*============================================================================
304 * Deprecation
305 *============================================================================*/
306
320#define OPENSNES_DEPRECATED(msg) __attribute__((deprecated(msg)))
321
322#endif /* OPENSNES_TYPES_H */
unsigned char bool
Definition types.h:190
void(* VoidFn)(void)
Void function taking no arguments (the generic name; a header that wants to say what the function is ...
Definition types.h:299
signed int s32
32-bit signed integer (-2147483648 to 2147483647)
Definition types.h:79
unsigned int u32
32-bit unsigned integer (0 to 4294967295)
Definition types.h:90
signed char s8
8-bit signed integer (-128 to 127)
Definition types.h:44
signed short s16
16-bit signed integer (-32768 to 32767)
Definition types.h:50
unsigned short u16
16-bit unsigned integer (0 to 65535)
Definition types.h:53
unsigned char u8
8-bit unsigned integer (0 to 255)
Definition types.h:47
volatile s8 vs8
Definition types.h:155
volatile u8 vu8
Definition types.h:152
volatile u16 vu16
Definition types.h:153
volatile s32 vs32
Definition types.h:157
volatile s16 vs16
Definition types.h:156
volatile u32 vu32
Definition types.h:154