X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;ds=sidebyside;f=src%2Futil.h;h=264367be94a4082ad3f544e99e01f025334f8175;hb=77eea907b4ba007632e37588b6cd7eb66c9eab07;hp=18c513e2eb8fa869057a8e33da1def1a8d6990b0;hpb=41765ea063cbab26ae05e7259ffc8a7c85db2f5d;p=gbajam22 diff --git a/src/util.h b/src/util.h index 18c513e..264367b 100644 --- a/src/util.h +++ b/src/util.h @@ -3,6 +3,14 @@ #include #include +#include "gba.h" + +#define RGB555(r, g, b) \ + ((((uint16_t)(r) >> 3) & 0x1f) | \ + (((uint16_t)(g) << 2) & 0x3e0) | \ + (((uint16_t)(b) << 7) & 0x7c00)) + +#ifdef BUILD_GBA #define wait_vblank() \ do { \ @@ -12,19 +20,32 @@ #define present(x) \ do { \ - REG_DISPCNT = DISPCNT_BG2 | DISPCNT_OBJ | 4 | ((x) << 4); \ + REG_DISPCNT = (REG_DISPCNT & 0xffef) | ((x) << 4); \ } while(0) +#define ARM_IWRAM __attribute__((noinline, target("arm"), section(".iwram"))) + +#else /* non-GBA build */ +#define wait_vblank() + +void present(int buf); /* defined in src/pc/main.c */ + +#define ARM_IWRAM +#endif #define set_bg_color(idx, r, g, b) \ - do { \ - ((uint16_t*)CRAM_BG_ADDR)[idx] = (uint16_t)(r) | ((uint16_t)(g) << 5) | ((uint16_t)(b) << 10); \ - } while(0) + gba_bgpal[idx] = (uint16_t)(r) | ((uint16_t)(g) << 5) | ((uint16_t)(b) << 10) extern int16_t sinlut[]; -#define SIN(x) sinlut[(x) & 0xff] -#define COS(x) sinlut[((x) + 64) & 0xff] +#define SINLUT_BITS 8 +#define SINLUT_SIZE (1 << SINLUT_BITS) + +#define SIN(angle) \ + ((int32_t)sinlut[((angle) >> (16 - SINLUT_BITS)) & (SINLUT_SIZE - 1)] << 1) + +#define COS(angle) \ + ((int32_t)sinlut[(((angle) >> (16 - SINLUT_BITS)) + (SINLUT_SIZE / 4)) & (SINLUT_SIZE - 1)] << 1) int iwram_brk(void *addr); void *iwram_sbrk(intptr_t delta);