diff options
author | Simponic <loganthebean222@gmail.com> | 2020-08-07 22:40:00 -0600 |
---|---|---|
committer | Simponic <loganthebean222@gmail.com> | 2020-08-07 22:40:00 -0600 |
commit | 6a44a34e0ebb867753df26f1cb0a38f53420a606 (patch) | |
tree | 42eef181966046e4e3108b149738e70479e48c35 /include | |
download | geometry-dash-gba-6a44a34e0ebb867753df26f1cb0a38f53420a606.tar.gz geometry-dash-gba-6a44a34e0ebb867753df26f1cb0a38f53420a606.zip |
Added files
Diffstat (limited to 'include')
-rw-r--r-- | include/input.h | 135 | ||||
-rw-r--r-- | include/memdef.h | 212 | ||||
-rw-r--r-- | include/memmap.h | 97 | ||||
-rw-r--r-- | include/toolbox.h | 154 | ||||
-rw-r--r-- | include/types.h | 120 |
5 files changed, 718 insertions, 0 deletions
diff --git a/include/input.h b/include/input.h new file mode 100644 index 0000000..70b7a83 --- /dev/null +++ b/include/input.h @@ -0,0 +1,135 @@ +// +// Input header +// +//! \file tonc_input.h +//! \author J Vijn +//! \date 20060508 - 20060924 +// +// === NOTES === +// * This is a _small_ set of typedefs, #defines and inlines that can +// be found in tonclib, and might not represent the +// final forms. + + +#ifndef __INPUT__ +#define __INPUT__ + +#include "memmap.h" +#include "types.h" +#include "memdef.h" + + +INLINE int bit_tribool(u32 x, int plus, int minus); + +// === CONSTANTS ====================================================== + +typedef enum eKeyIndex +{ + KI_A=0, KI_B, KI_SELECT, KI_START, + KI_RIGHT, KI_LEFT, KI_UP, KI_DOWN, + KI_R, KI_L, KI_MAX +} eKeyIndex; + +// === MACROS ========================================================= + +// check which of the specified keys are down or up right now +#define KEY_DOWN_NOW(key) (~(REG_KEYINPUT) & key) +#define KEY_UP_NOW(key) ( (REG_KEYINPUT) & key) + +// test whether all keys are pressed, released, whatever. +// Example use: +// KEY_EQ(key_hit, KEY_L | KEY_R) +// will be true if and only if KEY_L and KEY_R are _both_ being pressed +#define KEY_EQ(key_fun, keys) ( key_fun(keys) == (keys) ) + +// === CLASSES ======================================================== +// === GLOBALS ======================================================== + +extern u16 __key_curr, __key_prev; // in tonc_core.c + +// === PROTOTYPES ===================================================== + +// --- synchronous key states --- +INLINE void key_poll(); +INLINE u32 key_curr_state(); +INLINE u32 key_prev_state(); + +INLINE u32 key_is_down(u32 key); // any of key currently down? +INLINE u32 key_is_up(u32 key); // any of key currently up? + +INLINE u32 key_was_down(u32 key); // any of key previously down? +INLINE u32 key_was_up(u32 key); // any of key previously up? + +INLINE u32 key_transit(u32 key); // any of key changing? +INLINE u32 key_held(u32 key); // any of key held down? +INLINE u32 key_hit(u32 key); // any of key being hit (going down)? +INLINE u32 key_released(u32 key); // any of key being released? + +// --- tribools --- +INLINE int key_tri_horz(); +INLINE int key_tri_vert(); +INLINE int key_tri_shoulder(); +INLINE int key_tri_fire(); + +// === INLINES========================================================= + +// --- keys ----------------------------------------------------------- + +//! Poll for keystates +INLINE void key_poll() +{ __key_prev= __key_curr; __key_curr= ~REG_KEYINPUT & KEY_MASK; } + +//! Get current keystate +INLINE u32 key_curr_state() { return __key_curr; } + +//! Get previous key state +INLINE u32 key_prev_state() { return __key_prev; } + +//! Gives the keys of \a key that are currently down +INLINE u32 key_is_down(u32 key) { return __key_curr & key; } + +//! Gives the keys of \a key that are currently up +INLINE u32 key_is_up(u32 key) { return ~__key_curr & key; } + +//! Gives the keys of \a key that were previously down +INLINE u32 key_was_down(u32 key) { return __key_prev & key; } + +//! Gives the keys of \a key that were previously down +INLINE u32 key_was_up(u32 key) { return ~__key_prev & key; } + +//! Gives the keys of \a key that are different from before +INLINE u32 key_transit(u32 key) +{ return (__key_curr^__key_prev) & key; } + +//! Gives the keys of \a key that are being held down +INLINE u32 key_held(u32 key) +{ return (__key_curr& __key_prev) & key; } + +//! Gives the keys of \a key that are pressed (down now but not before) +INLINE u32 key_hit(u32 key) +{ return (__key_curr&~__key_prev) & key; } + +//! Gives the keys of \a key that are being released +INLINE u32 key_released(u32 key) +{ return (~__key_curr&__key_prev) & key; } + +// --- tribools --- + +//! Horizontal tribool (right,left)=(+,-) +INLINE int key_tri_horz() +{ return bit_tribool(__key_curr, KI_RIGHT, KI_LEFT); } + +//! Vertical tribool (down,up)=(+,-) +INLINE int key_tri_vert() +{ return bit_tribool(__key_curr, KI_DOWN, KI_UP); } + +//! Shoulder-button tribool (R,L)=(+,-) +INLINE int key_tri_shoulder() +{ return bit_tribool(__key_curr, KI_R, KI_L); } + +//! Fire-button tribool (A,B)=(+,-) +INLINE int key_tri_fire() +{ return bit_tribool(__key_curr, KI_A, KI_B); } + + +#endif // __INPUT__ diff --git a/include/memdef.h b/include/memdef.h new file mode 100644 index 0000000..8fe432f --- /dev/null +++ b/include/memdef.h @@ -0,0 +1,212 @@ +// +// Memory map defines. All of them +// +//! \file tonc_memdef.h +//! \author J Vijn +//! \date 20060508 - 20060924 +// +// === NOTES === +// * This is a _small_ set of typedefs, #defines and inlines that can +// be found in tonclib, and might not represent the +// final forms. +// * '0'-defines are prefixed with '_', to indicate their zero-ness +// and presents a safety from things like doing `if(x&0)' + +#ifndef __MEMDEF__ +#define __MEMDEF__ + +// --- Prefixes --- +// REG_DISPCNT : DCNT +// REG_DISPSTAT : DSTAT + +// OAM attr 0 : OA0 +// OAM attr 1 : OA1 +// OAM attr 2 : OA2 + + +// --- REG_DISPCNT ----------------------------------------------------- + +#define DCNT_MODE0 0 //!< Mode 0; bg 0-4: reg +#define DCNT_MODE1 0x0001 //!< Mode 1; bg 0-1: reg; bg 2: affine +#define DCNT_MODE2 0x0002 //!< Mode 2; bg 2-2: affine +#define DCNT_MODE3 0x0003 //!< Mode 3; bg2: 240x160\@16 bitmap +#define DCNT_MODE4 0x0004 //!< Mode 4; bg2: 240x160\@8 bitmap +#define DCNT_MODE5 0x0005 //!< Mode 5; bg2: 160x128\@16 bitmap +#define DCNT_GB 0x0008 //!< (R) GBC indicator +#define DCNT_PAGE 0x0010 //!< Page indicator +#define DCNT_OAM_HBL 0x0020 //!< Allow OAM updates in HBlank +#define DCNT_OBJ_2D 0 //!< OBJ-VRAM as matrix +#define DCNT_OBJ_1D 0x0040 //!< OBJ-VRAM as array +#define DCNT_BLANK 0x0080 //!< Force screen blank +#define DCNT_BG0 0x0100 //!< Enable bg 0 +#define DCNT_BG1 0x0200 //!< Enable bg 1 +#define DCNT_BG2 0x0400 //!< Enable bg 2 +#define DCNT_BG3 0x0800 //!< Enable bg 3 +#define DCNT_OBJ 0x1000 //!< Enable objects +#define DCNT_WIN0 0x2000 //!< Enable window 0 +#define DCNT_WIN1 0x4000 //!< Enable window 1 +#define DCNT_WINOBJ 0x8000 //!< Enable object window + +#define DCNT_MODE_MASK 0x0007 +#define DCNT_MODE_SHIFT 0 +#define DCNT_MODE(n) ((n)<<DCNT_MODE_SHIFT) + +#define DCNT_LAYER_MASK 0x1F00 +#define DCNT_LAYER_SHIFT 8 +#define DCNT_LAYER(n) ((n)<<DCNT_LAYER_SHIFT) + +#define DCNT_WIN_MASK 0xE000 +#define DCNT_WIN_SHIFT 13 +#define DCNT_WIN(n) ((n)<<DCNT_WIN_SHIFT) + +#define DCNT_BUILD(mode, layer, win, obj1d, objhbl) \ +( \ + (((win)&7)<<13) | (((layer)&31)<<8) | (((obj1d)&1)<<6) \ + | (((oamhbl)&1)<<5) | ((mode)&7) \ +) + + +// --- REG_DISPSTAT ---------------------------------------------------- + +#define DSTAT_IN_VBL 0x0001 //!< Now in VBlank +#define DSTAT_IN_HBL 0x0002 //!< Now in HBlank +#define DSTAT_IN_VCT 0x0004 //!< Now in set VCount +#define DSTAT_VBL_IRQ 0x0008 //!< Enable VBlank irq +#define DSTAT_HBL_IRQ 0x0010 //!< Enable HBlank irq +#define DSTAT_VCT_IRQ 0x0020 //!< Enable VCount irq + +#define DSTAT_VCT_MASK 0xFF00 +#define DSTAT_VCT_SHIFT 8 +#define DSTAT_VCT(n) ((n)<<DSTAT_VCT_SHIFT) + + +// --- REG_KEYINPUT -------------------------------------------------------- + +#define KEY_A 0x0001 //!< Button A +#define KEY_B 0x0002 //!< Button B +#define KEY_SELECT 0x0004 //!< Select button +#define KEY_START 0x0008 //!< Start button +#define KEY_RIGHT 0x0010 //!< Right D-pad +#define KEY_LEFT 0x0020 //!< Left D-pad +#define KEY_UP 0x0040 //!< Up D-pad +#define KEY_DOWN 0x0080 //!< Down D-pad +#define KEY_R 0x0100 //!< Shoulder R +#define KEY_L 0x0200 //!< Shoulder L + +#define KEY_ANY 0x03FF //!< any key +#define KEY_DIR 0x00F0 //!< any-dpad +#define KEY_ACCEPT 0x0009 //!< A or start +#define KEY_CANCEL 0x0002 //!< B (well, it usually is) +#define KEY_SHOULDER 0x0300 //!< L or R + +#define KEY_RESET 0x000F //!< St+Se+A+B + +#define KEY_MASK 0x03FF + + +// --- OAM attribute 0 ------------------------------------------------- + +#define ATTR0_REG 0 //!< Regular object +#define ATTR0_AFF 0x0100 //!< Affine object +#define ATTR0_HIDE 0x0200 //!< Inactive object +#define ATTR0_AFF_DBL 0x0300 //!< Double-size affine object +#define ATTR0_AFF_DBL_BIT 0x0200 +#define ATTR0_BLEND 0x0400 //!< Enable blend +#define ATTR0_WINDOW 0x0800 //!< Use for object window +#define ATTR0_MOSAIC 0x1000 //!< Enable mosaic +#define ATTR0_4BPP 0 //!< Use 4bpp (16 color) tiles +#define ATTR0_8BPP 0x2000 //!< Use 8bpp (256 color) tiles +#define ATTR0_SQUARE 0 //!< Square shape +#define ATTR0_WIDE 0x4000 //!< Tall shape (height > width) +#define ATTR0_TALL 0x8000 //!< Wide shape (height < width) + +#define ATTR0_Y_MASK 0x00FF +#define ATTR0_Y_SHIFT 0 +#define ATTR0_Y(n) ((n)<<ATTR0_Y_SHIFT) + +#define ATTR0_MODE_MASK 0x0300 +#define ATTR0_MODE_SHIFT 8 +#define ATTR0_MODE(n) ((n)<<ATTR0_MODE_SHIFT) + +#define ATTR0_SHAPE_MASK 0xC000 +#define ATTR0_SHAPE_SHIFT 14 +#define ATTR0_SHAPE(n) ((n)<<ATTR0_SHAPE_SHIFT) + + +#define ATTR0_BUILD(y, shape, bpp, mode, mos, bld, win) \ +( \ + ((y)&255) | (((mode)&3)<<8) | (((bld)&1)<<10) | (((win)&1)<<11) \ + | (((mos)&1)<<12) | (((bpp)&8)<<10)| (((shape)&3)<<14) \ +) + + +// --- OAM attribute 1 ------------------------------------------------- + +#define ATTR1_HFLIP 0x1000 //!< Horizontal flip (reg obj only) +#define ATTR1_VFLIP 0x2000 //!< Vertical flip (reg obj only) +// Base sizes +#define ATTR1_SIZE_8 0 +#define ATTR1_SIZE_16 0x4000 +#define ATTR1_SIZE_32 0x8000 +#define ATTR1_SIZE_64 0xC000 +// Square sizes +#define ATTR1_SIZE_8x8 0 //!< Size flag for 8x8 px object +#define ATTR1_SIZE_16x16 0x4000 //!< Size flag for 16x16 px object +#define ATTR1_SIZE_32x32 0x8000 //!< Size flag for 32x32 px object +#define ATTR1_SIZE_64x64 0xC000 //!< Size flag for 64x64 px object +// Tall sizes +#define ATTR1_SIZE_8x16 0 //!< Size flag for 8x16 px object +#define ATTR1_SIZE_8x32 0x4000 //!< Size flag for 8x32 px object +#define ATTR1_SIZE_16x32 0x8000 //!< Size flag for 16x32 px object +#define ATTR1_SIZE_32x64 0xC000 //!< Size flag for 32x64 px object +// Wide sizes +#define ATTR1_SIZE_16x8 0 //!< Size flag for 16x8 px object +#define ATTR1_SIZE_32x8 0x4000 //!< Size flag for 32x8 px object +#define ATTR1_SIZE_32x16 0x8000 //!< Size flag for 32x16 px object +#define ATTR1_SIZE_64x32 0xC000 //!< Size flag for 64x64 px object + + +#define ATTR1_X_MASK 0x01FF +#define ATTR1_X_SHIFT 0 +#define ATTR1_X(n) ((n)<<ATTR1_X_SHIFT) + +#define ATTR1_AFF_ID_MASK 0x3E00 +#define ATTR1_AFF_ID_SHIFT 9 +#define ATTR1_AFF_ID(n) ((n)<<ATTR1_AFF_ID_SHIFT) + +#define ATTR1_FLIP_MASK 0x3000 +#define ATTR1_FLIP_SHIFT 12 +#define ATTR1_FLIP(n) ((n)<<ATTR1_FLIP_SHIFT) + +#define ATTR1_SIZE_MASK 0xC000 +#define ATTR1_SIZE_SHIFT 14 +#define ATTR1_SIZE(n) ((n)<<ATTR1_SIZE_SHIFT) + + +#define ATTR1_BUILDR(x, size, hflip, vflip) \ +( ((x)&511) | (((hflip)&1)<<12) | (((vflip)&1)<<13) | (((size)&3)<<14) ) + +#define ATTR1_BUILDA(x, size, affid) \ +( ((x)&511) | (((affid)&31)<<9) | (((size)&3)<<14) ) + + +// --- OAM attribute 2 ------------------------------------------------- + +#define ATTR2_ID_MASK 0x03FF +#define ATTR2_ID_SHIFT 0 +#define ATTR2_ID(n) ((n)<<ATTR2_ID_SHIFT) + +#define ATTR2_PRIO_MASK 0x0C00 +#define ATTR2_PRIO_SHIFT 10 +#define ATTR2_PRIO(n) ((n)<<ATTR2_PRIO_SHIFT) + +#define ATTR2_PALBANK_MASK 0xF000 +#define ATTR2_PALBANK_SHIFT 12 +#define ATTR2_PALBANK(n) ((n)<<ATTR2_PALBANK_SHIFT) + + +#define ATTR2_BUILD(id, pbank, prio) \ +( ((id)&0x3FF) | (((pbank)&15)<<12) | (((prio)&3)<<10) ) + + +#endif // __MEMDEF__ diff --git a/include/memmap.h b/include/memmap.h new file mode 100644 index 0000000..a473310 --- /dev/null +++ b/include/memmap.h @@ -0,0 +1,97 @@ +// +// GBA Memory map +// +//! \file tonc_memmap.h +//! \author J Vijn +//! \date 20060508 - 20060508 +// +// === NOTES === +// * This is a _small_ set of typedefs, #defines and inlines that can +// be found in tonclib, and might not represent the +// final forms. + +#ifndef __MEMMAP__ +#define __MEMMAP__ + + +// === MEMORY SECTIONS ================================================ + +// basic sections +#define MEM_IO 0x04000000 +#define MEM_PAL 0x05000000 // no 8bit write !! +#define MEM_VRAM 0x06000000 // no 8bit write !! +#define MEM_OAM 0x07000000 // no 8bit write !! + +// basic sizes +#define PAL_SIZE 0x00400 +#define VRAM_SIZE 0x18000 +#define OAM_SIZE 0x00400 + +// sub sizes +#define PAL_BG_SIZE 0x00200 +#define PAL_OBJ_SIZE 0x00200 +#define VRAM_BG_SIZE 0x10000 +#define VRAM_OBJ_SIZE 0x08000 +#define M3_SIZE 0x12C00 +#define M4_SIZE 0x09600 +#define M5_SIZE 0x0A000 +#define VRAM_PAGE_SIZE 0x0A000 + +// sub sections +#define REG_BASE MEM_IO + +#define MEM_PAL_OBJ (MEM_PAL + PAL_BG_SIZE) +#define MEM_VRAM_BACK (MEM_VRAM+ VRAM_PAGE_SIZE) +#define MEM_VRAM_OBJ (MEM_VRAM+ VRAM_BG_SIZE) + + +// === STRUCTURED MEMORY MAP ========================================== +// Heavily typedefed, watch your pointers +// Should simplify memory accesses + + +// --- PAL --- +// pal_bg_mem[y] = COLOR (color y) +#define pal_bg_mem ((COLOR*)MEM_PAL) +#define pal_obj_mem ((COLOR*)MEM_PAL_OBJ) + +// pal_bg_bank[y] = COLOR[] (bank y) +// pal_bg_bank[y][x] = COLOR (bank y, color x : color y*16+x) +#define pal_bg_bank ((PALBANK*)MEM_PAL) +#define pal_obj_bank ((PALBANK*)MEM_PAL_OBJ) + + +// --- VRAM --- +// tile_mem[y] = TILE[] (char block y) +// tile_mem[y][x] = TILE (char block y, tile x) +#define tile_mem ( (CHARBLOCK*)MEM_VRAM) +#define tile8_mem ((CHARBLOCK8*)MEM_VRAM) + +#define tile_mem_obj ( (CHARBLOCK*)MEM_VRAM_OBJ) +#define tile8_mem_obj ((CHARBLOCK8*)MEM_VRAM_OBJ) + +// vid_mem[a] = COLOR +#define vid_mem ((COLOR*)MEM_VRAM) + + +// --- OAM --- +// oatr_mem[a] = OBJ_ATTR (oam entry a) +#define oam_mem ((OBJ_ATTR*)MEM_OAM) +#define obj_mem ((OBJ_ATTR*)MEM_OAM) +#define obj_aff_mem ((OBJ_AFFINE*)MEM_OAM) + + +// === REGISTER LIST ================================================== + + +// === VIDEO REGISTERS === +#define REG_DISPCNT *(vu32*)(REG_BASE+0x0000) // display control +#define REG_DISPSTAT *(vu16*)(REG_BASE+0x0004) // display interupt status +#define REG_VCOUNT *(vu16*)(REG_BASE+0x0006) // vertical count + +// === KEYPAD === +#define REG_KEYINPUT *(vu16*)(REG_BASE+0x0130) // Key status +#define REG_KEYCNT *(vu16*)(REG_BASE+0x0132) + + +#endif // __MEMMAP__ diff --git a/include/toolbox.h b/include/toolbox.h new file mode 100644 index 0000000..064f0a3 --- /dev/null +++ b/include/toolbox.h @@ -0,0 +1,154 @@ +// +// toolbox.h: +// +// Tools header for obj_demo +// +// (20060211-20060924, cearn) +// +// === NOTES === +// * This is a _small_ set of typedefs, #defines and inlines that can +// be found in tonclib, and might not represent the +// final forms. + + +#ifndef TOOLBOX_H +#define TOOLBOX_H + +#include "types.h" // (tonc_types.h) +#include "memmap.h" // (tonc_memmap.h) +#include "memdef.h" // (tonc_memdef.h) +#include "input.h" // (tonc_input.h) + +// === (tonc_core.h) ================================================== + +// tribool: 1 if {plus} on, -1 if {minus} on, 0 if {plus}=={minus} +INLINE int bit_tribool(u32 x, int plus, int minus); + + +extern COLOR *vid_page; +extern u16 __key_curr, __key_prev; + + +// === (tonc_video.h) ================================================= + +// --- sizes --- +#define SCREEN_WIDTH 240 +#define SCREEN_HEIGHT 160 + +#define M3_WIDTH SCREEN_WIDTH +#define M3_HEIGHT SCREEN_HEIGHT +#define M4_WIDTH SCREEN_WIDTH +#define M4_HEIGHT SCREEN_HEIGHT +#define M5_WIDTH 160 +#define M5_HEIGHT 128 + +// --- colors --- + +#define CLR_BLACK 0x0000 +#define CLR_RED 0x001F +#define CLR_LIME 0x03E0 +#define CLR_YELLOW 0x03FF +#define CLR_BLUE 0x7C00 +#define CLR_MAG 0x7C1F +#define CLR_CYAN 0x7FE0 +#define CLR_WHITE 0x7FFF + +INLINE COLOR RGB15(u32 red, u32 green, u32 blue); + +INLINE void vid_vsync(); +u16 *vid_flip(); + + +// --- Objects --- + +void oam_init(OBJ_ATTR *obj, u32 count); +void oam_copy(OBJ_ATTR *dst, const OBJ_ATTR *src, u32 count); + +INLINE OBJ_ATTR *obj_set_attr(OBJ_ATTR *obj, u16 a0, u16 a1, u16 a2); +INLINE void obj_set_pos(OBJ_ATTR *obj, int x, int y); +INLINE void obj_hide(OBJ_ATTR *oatr); +INLINE void obj_unhide(OBJ_ATTR *obj, u16 mode); +void obj_copy(OBJ_ATTR *dst, const OBJ_ATTR *src, u32 count); + + +// === INLINES ======================================================== + +// --- (tonc_core.h) -------------------------------------------------- + +// --- Simple bit macros --- +#define BIT(n) ( 1<<(n) ) +#define BIT_SHIFT(a, n) ( (a)<<(n) ) +#define BIT_SET(word, flag) ( word |= (flag) ) +#define BIT_CLEAR(word, flag) ( word &= ~(flag) ) +#define BIT_FLIP(word, flag) ( word ^= (flag) ) +#define BIT_EQ(word, flag) ( ((word)&(flag)) == (flag) ) + +// some EVIL bit-field operations, >:) +// _x needs shifting +#define BFN_PREP(x, name) ( ((x)<<name##_SHIFT) & name##_MASK ) +#define BFN_GET(y, name) ( ((y) & name##_MASK)>>name##_SHIFT ) +#define BFN_SET(y, x, name) (y = ((y)&~name##_MASK) | BFN_PREP(x,name) ) + +// x already shifted +#define BFN_PREP2(x, name) ( (x) & name##_MASK ) +#define BFN_GET2(y, name) ( (y) & name##_MASK ) +#define BFN_SET2(y, x, name) (y = ((y)&~name##_MASK) | BFN_PREP2(x,name) ) + +//! Gives a tribool (-1, 0, or +1) depending on the state of some bits. +/*! Looks at the \a plus and \a minus bits of \a flags, and subtracts +* their status to give a +1, -1 or 0 result. Useful for direction flags. +* \param plus Bit number for positive result +* \param minus Bit number for negative result +* \return <b>+1</b> if \a plus bit is set but \a minus bit isn't<br> +* <b>-1</b> if \a minus bit is set and \a plus bit isn't</br> +* <b>0</b> if neither or both are set. +*/ +INLINE int bit_tribool(u32 flags, int plus, int minus) +{ return ((flags>>plus)&1) - ((flags>>minus)&1); } + + +// --- (tonc_video.h) ------------------------------------------------- + +//! Wait for next VBlank +INLINE void vid_vsync() +{ + while(REG_VCOUNT >= 160); // wait till VDraw + while(REG_VCOUNT < 160); // wait till VBlank +} + +//! Create a 15bit BGR color. +INLINE COLOR RGB15(u32 red, u32 green, u32 blue) +{ return red | (green<<5) | (blue<<10); } + + +// --- Objects --- + + +//! Set the attributes of an object. +INLINE OBJ_ATTR *obj_set_attr(OBJ_ATTR *obj, u16 a0, u16 a1, u16 a2) +{ + obj->attr0= a0; obj->attr1= a1; obj->attr2= a2; + return obj; +} + +//! Set the position of \a obj +INLINE void obj_set_pos(OBJ_ATTR *obj, int x, int y) +{ + BFN_SET(obj->attr0, y, ATTR0_Y); + BFN_SET(obj->attr1, x, ATTR1_X); +} + +//! Hide an object. +INLINE void obj_hide(OBJ_ATTR *obj) +{ BFN_SET2(obj->attr0, ATTR0_HIDE, ATTR0_MODE); } + +//! Unhide an object. +/*! \param obj Object to unhide. +* \param mode Object mode to unhide to. Necessary because this affects +* the affine-ness of the object. +*/ +INLINE void obj_unhide(OBJ_ATTR *obj, u16 mode) +{ BFN_SET2(obj->attr0, mode, ATTR0_MODE); } + + +#endif // TOOLBOX_H diff --git a/include/types.h b/include/types.h new file mode 100644 index 0000000..5ad8121 --- /dev/null +++ b/include/types.h @@ -0,0 +1,120 @@ +// +// Basic structs and typedefs +// +//! \file tonc_types.h +//! \author J Vijn +//! \date 20060508 - 20060508 +// +// === NOTES === +// * This is a _small_ set of typedefs, #defines and inlines that can +// be found in tonclib, and might not represent the +// final forms. + + +#ifndef __TYPES__ +#define __TYPES__ + + +// === GCC ATTRIBUTES ================================================= + +// alignment boundary +#define ALIGN(_n) __attribute__((aligned(_n))) +#define ALIGN4 __attribute__((aligned(4))) + +// pack aggregate members +#define PACKED __attribute__((packed)) + + +// === TYPES: ========================================================= + +// --- primary typedefs ----------------------------------------------- +typedef unsigned char u8, byte; +typedef unsigned short u16, hword; +typedef unsigned int u32, word; +typedef unsigned long long u64; + +typedef signed char s8; +typedef signed short s16; +typedef signed int s32; +typedef signed long long s64; + +// and volatiles for registers 'n stuff +typedef volatile u8 vu8; +typedef volatile u16 vu16; +typedef volatile u32 vu32; +typedef volatile u64 vu64; + +typedef volatile s8 vs8; +typedef volatile s16 vs16; +typedef volatile s32 vs32; +typedef volatile s64 vs64; + +// and consts too for parameters *sigh* +typedef const u8 cu8; +typedef const u16 cu16; +typedef const u32 cu32; +typedef const u64 cu64; + +typedef const s8 cs8; +typedef const s16 cs16; +typedef const s32 cs32; +typedef const s64 cs64; + +typedef struct { u32 data[8]; } BLOCK; + +// --- secondary typedefs --------------------------------------------- + +typedef u16 COLOR; + +// NOTE, u32[]! +typedef struct { u32 data[8]; } TILE, TILE4; +typedef struct { u32 data[16]; } TILE8; + + +// --- memory map structs -------------------------------------------- + +// --- PAL types --- +typedef COLOR PALBANK[16]; + +// --- VRAM types --- + +typedef COLOR M3LINE[240]; +typedef u8 M4LINE[240]; // NOTE u8, not u16!! +typedef COLOR M5LINE[160]; + +typedef TILE CHARBLOCK[512]; +typedef TILE8 CHARBLOCK8[256]; + +// --- OAM structs --- +// NOTE: OATR and OAFF are interlaced; when using affine objs, +// struct/DMA/mem copies will give bad results +typedef struct OBJ_ATTR +{ + u16 attr0; + u16 attr1; + u16 attr2; + s16 fill; +} ALIGN4 OBJ_ATTR; + +typedef struct OBJ_AFFINE +{ + u16 fill0[3]; s16 pa; + u16 fill1[3]; s16 pb; + u16 fill2[3]; s16 pc; + u16 fill3[3]; s16 pd; +} ALIGN4 OBJ_AFFINE; + + +// === DEFINES ======================================================== + +#ifndef NULL +#define NULL 0 +#endif + +// `inline' inlines the function when -O > 0 when called, +// but also creates a body for the function itself +// `static' removes the body as well +#define INLINE static inline + + +#endif // __TYPES__ |