Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1
21#ifndef OPENSNES_TYPES_H
22#define OPENSNES_TYPES_H
23
24/*============================================================================
25 * Fixed-Width Integer Types
26 *============================================================================*/
27
43typedef signed char s8;
44
46typedef unsigned char u8;
47
49typedef signed short s16;
50
52typedef unsigned short u16;
53
59typedef signed int s32;
60
66typedef unsigned int u32;
67
/* end of types group */
69
70/*============================================================================
71 * Volatile Types
72 *============================================================================*/
73
83typedef volatile u8 vu8;
84typedef volatile u16 vu16;
85typedef volatile u32 vu32;
86typedef volatile s8 vs8;
87typedef volatile s16 vs16;
88typedef volatile s32 vs32;
89
92/*============================================================================
93 * Boolean Type
94 *============================================================================*/
95
112/*
113 * Bool type compatibility:
114 * - C11 compilers (cproc) have built-in bool/_Bool
115 * - Legacy compilers (816-tcc) need typedef
116 * We check for __STDC_VERSION__ >= C99 as indicator of modern compiler
117 */
118#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
119typedef unsigned char bool;
120#define false 0
121#define true 1
122#endif
123
124/* SNES-specific TRUE/FALSE (0xFF for TRUE is common in SNES code) */
125#define FALSE 0
126#define TRUE 0xFF
127
130/*============================================================================
131 * Common Macros
132 *============================================================================*/
133
141#ifndef NULL
142#define NULL ((void*)0)
143#endif
144
155#define BIT(n) (1 << (n))
156
162#define LO_BYTE(x) ((u8)((x) & 0xFF))
163
169#define HI_BYTE(x) ((u8)(((x) >> 8) & 0xFF))
170
177#define MAKE_WORD(lo, hi) ((u16)(((u8)(hi) << 8) | (u8)(lo)))
178
182#define MIN(a, b) (((a) < (b)) ? (a) : (b))
183
187#define MAX(a, b) (((a) > (b)) ? (a) : (b))
188
195#define CLAMP(x, lo, hi) (((x) < (lo)) ? (lo) : (((x) > (hi)) ? (hi) : (x)))
196
202#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
203
206/*============================================================================
207 * Function Pointer Types
208 *============================================================================*/
209
217typedef void (*VoidFn)(void);
218
221#endif /* OPENSNES_TYPES_H */
unsigned char bool
Definition types.h:119
void(* VoidFn)(void)
Void function taking no arguments.
Definition types.h:217
signed int s32
32-bit signed integer (-2147483648 to 2147483647)
Definition types.h:59
unsigned int u32
32-bit unsigned integer (0 to 4294967295)
Definition types.h:66
signed char s8
8-bit signed integer (-128 to 127)
Definition types.h:43
signed short s16
16-bit signed integer (-32768 to 32767)
Definition types.h:49
unsigned short u16
16-bit unsigned integer (0 to 65535)
Definition types.h:52
unsigned char u8
8-bit unsigned integer (0 to 255)
Definition types.h:46
volatile s8 vs8
Definition types.h:86
volatile u8 vu8
Definition types.h:83
volatile u16 vu16
Definition types.h:84
volatile s32 vs32
Definition types.h:88
volatile s16 vs16
Definition types.h:87
volatile u32 vu32
Definition types.h:85