8 #define RGB555(r, g, b) \
9 (((r) >> 3) | (((g) << 2) & 0x3e0) | (((b) << 7) & 0x7c00))
13 #define wait_vblank() \
15 while(REG_DISPSTAT & DISPSTAT_VBLANK); \
16 while(!(REG_DISPSTAT & DISPSTAT_VBLANK)); \
21 REG_DISPCNT = (REG_DISPCNT & 0xffef) | ((x) << 4); \
24 #define ARM_IWRAM __attribute__((noinline, target("arm"), section(".iwram")))
26 #else /* non-GBA build */
29 void present(int buf); /* defined in src/pc/main.c */
34 #define set_bg_color(idx, r, g, b) \
35 gba_bgpal[idx] = (uint16_t)(r) | ((uint16_t)(g) << 5) | ((uint16_t)(b) << 10)
37 extern int16_t sinlut[];
40 #define SINLUT_SIZE (1 << SINLUT_BITS)
43 ((int32_t)sinlut[((angle) >> (16 - SINLUT_BITS)) & (SINLUT_SIZE - 1)] << 1)
46 ((int32_t)sinlut[(((angle) >> (16 - SINLUT_BITS)) + (SINLUT_SIZE / 4)) & (SINLUT_SIZE - 1)] << 1)
48 int iwram_brk(void *addr);
49 void *iwram_sbrk(intptr_t delta);
51 void fillblock_16byte(void *dest, uint32_t val, int count);
56 int ispow2(unsigned int x);
58 /* Non-failing versions of malloc/calloc/realloc. They never return 0, they call
59 * demo_abort on failure. Use the macros, don't call the *_impl functions.
61 #define malloc_nf(sz) malloc_nf_impl(sz, __FILE__, __LINE__)
62 void *malloc_nf_impl(size_t sz, const char *file, int line);
63 #define calloc_nf(n, sz) calloc_nf_impl(n, sz, __FILE__, __LINE__)
64 void *calloc_nf_impl(size_t num, size_t sz, const char *file, int line);
65 #define realloc_nf(p, sz) realloc_nf_impl(p, sz, __FILE__, __LINE__)
66 void *realloc_nf_impl(void *p, size_t sz, const char *file, int line);
67 #define strdup_nf(s) strdup_nf_impl(s, __FILE__, __LINE__)
68 char *strdup_nf_impl(const char *s, const char *file, int line);