gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 43dfccb83cdb36b6632733242a403c9798e40d97 parent ea81835299f96ec374550f6df8a79d928b5f5469 Author: bbbbbr <bbbbbr@users.noreply.github.com> Date: Sun, 12 Jun 2022 12:33:16 -0700 Merge pull request #379 from bbbbbr/examples_cgb_constants Docs & Examples: use new CGB flags (more), add doc refs Diffstat:
| M | gbdk-lib/examples/ap/colorbar/colorbar.c | 16 | ++++++++-------- |
| M | gbdk-lib/examples/ap/dscan/dscan.c | 32 | ++++++++++++++++---------------- |
| M | gbdk-lib/examples/cross-platform/logo/src/main.c | 2 | +- |
| M | gbdk-lib/examples/gb/apa_image/src/main.c | 4 | ++-- |
| M | gbdk-lib/examples/gb/colorbar/colorbar.c | 16 | ++++++++-------- |
| M | gbdk-lib/examples/gb/dscan/dscan.c | 32 | ++++++++++++++++---------------- |
| M | gbdk-lib/include/gb/cgb.h | 8 | ++++++++ |
| M | gbdk-lib/include/gb/gb.h | 36 | ++++++++++++++++++------------------ |
| M | gbdk-lib/include/gb/hardware.h | 5 | +++-- |
9 files changed, 80 insertions(+), 71 deletions(-)
diff --git a/gbdk-lib/examples/ap/colorbar/colorbar.c b/gbdk-lib/examples/ap/colorbar/colorbar.c @@ -43,14 +43,14 @@ const unsigned char bar_a[] = int main(void) { /* Transfer color palettes */ - set_bkg_palette( 7, 1, &bar_p[0] ); - set_bkg_palette( 6, 1, &bar_p[4] ); - set_bkg_palette( 5, 1, &bar_p[8] ); - set_bkg_palette( 4, 1, &bar_p[12] ); - set_bkg_palette( 3, 1, &bar_p[16] ); - set_bkg_palette( 2, 1, &bar_p[20] ); - set_bkg_palette( 1, 1, &bar_p[24] ); - set_bkg_palette( 0, 1, &bar_p[28] ); + set_bkg_palette( BKGF_CGB_PAL7, 1, &bar_p[0] ); + set_bkg_palette( BKGF_CGB_PAL6, 1, &bar_p[4] ); + set_bkg_palette( BKGF_CGB_PAL5, 1, &bar_p[8] ); + set_bkg_palette( BKGF_CGB_PAL4, 1, &bar_p[12] ); + set_bkg_palette( BKGF_CGB_PAL3, 1, &bar_p[16] ); + set_bkg_palette( BKGF_CGB_PAL2, 1, &bar_p[20] ); + set_bkg_palette( BKGF_CGB_PAL1, 1, &bar_p[24] ); + set_bkg_palette( BKGF_CGB_PAL0, 1, &bar_p[28] ); /* CHR code transfer */ set_bkg_data( 0x0, 32, bar_c ); diff --git a/gbdk-lib/examples/ap/dscan/dscan.c b/gbdk-lib/examples/ap/dscan/dscan.c @@ -219,22 +219,22 @@ void init_screen() if(DEVICE_SUPPORTS_COLOR) { /* Transfer color palette */ - set_bkg_palette( 0, 1, &bkg_p[0] ); - set_bkg_palette( 1, 1, &bkg_p[4] ); - set_bkg_palette( 2, 1, &bkg_p[8] ); - set_bkg_palette( 3, 1, &bkg_p[12] ); - set_bkg_palette( 4, 1, &bkg_p[16] ); - set_bkg_palette( 5, 1, &bkg_p[20] ); - set_bkg_palette( 6, 1, &bkg_p[24] ); - set_bkg_palette( 7, 1, &bkg_p[28] ); - set_sprite_palette( 0, 1, &obj_p[0] ); - set_sprite_palette( 1, 1, &obj_p[4] ); - set_sprite_palette( 2, 1, &obj_p[8] ); - set_sprite_palette( 3, 1, &obj_p[12] ); - set_sprite_palette( 4, 1, &obj_p[16] ); - set_sprite_palette( 5, 1, &obj_p[20] ); - set_sprite_palette( 6, 1, &obj_p[24] ); - set_sprite_palette( 7, 1, &obj_p[28] ); + set_bkg_palette( BKGF_CGB_PAL0, 1, &bkg_p[0] ); + set_bkg_palette( BKGF_CGB_PAL1, 1, &bkg_p[4] ); + set_bkg_palette( BKGF_CGB_PAL2, 1, &bkg_p[8] ); + set_bkg_palette( BKGF_CGB_PAL3, 1, &bkg_p[12] ); + set_bkg_palette( BKGF_CGB_PAL4, 1, &bkg_p[16] ); + set_bkg_palette( BKGF_CGB_PAL5, 1, &bkg_p[20] ); + set_bkg_palette( BKGF_CGB_PAL6, 1, &bkg_p[24] ); + set_bkg_palette( BKGF_CGB_PAL7, 1, &bkg_p[28] ); + set_sprite_palette( OAMF_CGB_PAL0, 1, &obj_p[0] ); + set_sprite_palette( OAMF_CGB_PAL1, 1, &obj_p[4] ); + set_sprite_palette( OAMF_CGB_PAL2, 1, &obj_p[8] ); + set_sprite_palette( OAMF_CGB_PAL3, 1, &obj_p[12] ); + set_sprite_palette( OAMF_CGB_PAL4, 1, &obj_p[16] ); + set_sprite_palette( OAMF_CGB_PAL5, 1, &obj_p[20] ); + set_sprite_palette( OAMF_CGB_PAL6, 1, &obj_p[24] ); + set_sprite_palette( OAMF_CGB_PAL7, 1, &obj_p[28] ); /* set attributes */ set_bkg_attr( 0, 0, 20, 18, bkg_c ); diff --git a/gbdk-lib/examples/cross-platform/logo/src/main.c b/gbdk-lib/examples/cross-platform/logo/src/main.c @@ -9,7 +9,7 @@ void main() { set_palette(0, GBDK_2020_logo_PALETTE_COUNT, GBDK_2020_logo_palettes); #elif defined(SYSTEM_CGB) if (_cpu == CGB_TYPE) { - set_bkg_palette(0, GBDK_2020_logo_PALETTE_COUNT, GBDK_2020_logo_palettes); + set_bkg_palette(BKGF_CGB_PAL0, GBDK_2020_logo_PALETTE_COUNT, GBDK_2020_logo_palettes); } #endif set_native_tile_data(0, GBDK_2020_logo_TILE_COUNT, GBDK_2020_logo_tiles); diff --git a/gbdk-lib/examples/gb/apa_image/src/main.c b/gbdk-lib/examples/gb/apa_image/src/main.c @@ -14,7 +14,7 @@ void main(void) { // Set the screen to black via the palettes to hide the image draw if (_cpu == CGB_TYPE) { - set_bkg_palette(CGB_BKG_PAL_0, CGB_ONE_PAL, cgb_pal_black); + set_bkg_palette(BKGF_CGB_PAL0, CGB_ONE_PAL, cgb_pal_black); } else { BGP_REG = DMG_PALETTE(DMG_BLACK, DMG_BLACK, DMG_BLACK, DMG_BLACK); } @@ -28,7 +28,7 @@ void main(void) // Then load the palettes at the start of a new frame wait_vbl_done(); if (_cpu == CGB_TYPE) { - set_bkg_palette(OAMF_CGB_PAL0, CGB_ONE_PAL, scenery_palettes); + set_bkg_palette(BKGF_CGB_PAL0, CGB_ONE_PAL, scenery_palettes); } else { BGP_REG = DMG_PALETTE(DMG_WHITE, DMG_LITE_GRAY, DMG_DARK_GRAY, DMG_BLACK); } diff --git a/gbdk-lib/examples/gb/colorbar/colorbar.c b/gbdk-lib/examples/gb/colorbar/colorbar.c @@ -43,14 +43,14 @@ const unsigned char bar_a[] = int main(void) { /* Transfer color palettes */ - set_bkg_palette( 7, 1, &bar_p[0] ); - set_bkg_palette( 6, 1, &bar_p[4] ); - set_bkg_palette( 5, 1, &bar_p[8] ); - set_bkg_palette( 4, 1, &bar_p[12] ); - set_bkg_palette( 3, 1, &bar_p[16] ); - set_bkg_palette( 2, 1, &bar_p[20] ); - set_bkg_palette( 1, 1, &bar_p[24] ); - set_bkg_palette( 0, 1, &bar_p[28] ); + set_bkg_palette( BKGF_CGB_PAL7, 1, &bar_p[0] ); + set_bkg_palette( BKGF_CGB_PAL6, 1, &bar_p[4] ); + set_bkg_palette( BKGF_CGB_PAL5, 1, &bar_p[8] ); + set_bkg_palette( BKGF_CGB_PAL4, 1, &bar_p[12] ); + set_bkg_palette( BKGF_CGB_PAL3, 1, &bar_p[16] ); + set_bkg_palette( BKGF_CGB_PAL2, 1, &bar_p[20] ); + set_bkg_palette( BKGF_CGB_PAL1, 1, &bar_p[24] ); + set_bkg_palette( BKGF_CGB_PAL0, 1, &bar_p[28] ); /* CHR code transfer */ set_bkg_data( 0x0, 32, bar_c ); diff --git a/gbdk-lib/examples/gb/dscan/dscan.c b/gbdk-lib/examples/gb/dscan/dscan.c @@ -219,22 +219,22 @@ void init_screen() if(DEVICE_SUPPORTS_COLOR) { /* Transfer color palette */ - set_bkg_palette( 0, 1, &bkg_p[0] ); - set_bkg_palette( 1, 1, &bkg_p[4] ); - set_bkg_palette( 2, 1, &bkg_p[8] ); - set_bkg_palette( 3, 1, &bkg_p[12] ); - set_bkg_palette( 4, 1, &bkg_p[16] ); - set_bkg_palette( 5, 1, &bkg_p[20] ); - set_bkg_palette( 6, 1, &bkg_p[24] ); - set_bkg_palette( 7, 1, &bkg_p[28] ); - set_sprite_palette( 0, 1, &obj_p[0] ); - set_sprite_palette( 1, 1, &obj_p[4] ); - set_sprite_palette( 2, 1, &obj_p[8] ); - set_sprite_palette( 3, 1, &obj_p[12] ); - set_sprite_palette( 4, 1, &obj_p[16] ); - set_sprite_palette( 5, 1, &obj_p[20] ); - set_sprite_palette( 6, 1, &obj_p[24] ); - set_sprite_palette( 7, 1, &obj_p[28] ); + set_bkg_palette( BKGF_CGB_PAL0, 1, &bkg_p[0] ); + set_bkg_palette( BKGF_CGB_PAL1, 1, &bkg_p[4] ); + set_bkg_palette( BKGF_CGB_PAL2, 1, &bkg_p[8] ); + set_bkg_palette( BKGF_CGB_PAL3, 1, &bkg_p[12] ); + set_bkg_palette( BKGF_CGB_PAL4, 1, &bkg_p[16] ); + set_bkg_palette( BKGF_CGB_PAL5, 1, &bkg_p[20] ); + set_bkg_palette( BKGF_CGB_PAL6, 1, &bkg_p[24] ); + set_bkg_palette( BKGF_CGB_PAL7, 1, &bkg_p[28] ); + set_sprite_palette( OAMF_CGB_PAL0, 1, &obj_p[0] ); + set_sprite_palette( OAMF_CGB_PAL1, 1, &obj_p[4] ); + set_sprite_palette( OAMF_CGB_PAL2, 1, &obj_p[8] ); + set_sprite_palette( OAMF_CGB_PAL3, 1, &obj_p[12] ); + set_sprite_palette( OAMF_CGB_PAL4, 1, &obj_p[16] ); + set_sprite_palette( OAMF_CGB_PAL5, 1, &obj_p[20] ); + set_sprite_palette( OAMF_CGB_PAL6, 1, &obj_p[24] ); + set_sprite_palette( OAMF_CGB_PAL7, 1, &obj_p[28] ); /* set attributes */ set_bkg_attr( 0, 0, 20, 18, bkg_c ); diff --git a/gbdk-lib/include/gb/cgb.h b/gbdk-lib/include/gb/cgb.h @@ -98,6 +98,8 @@ typedef uint16_t palette_color_t; /**< 16 bit color entry */ \li Each component (R, G, B) may have values from 0 - 31 (5 bits), 31 is brightest. @see RGB(), set_bkg_palette_entry() + @see BKGF_CGB_PAL0, BKGF_CGB_PAL1, BKGF_CGB_PAL2, BKGF_CGB_PAL3 + @see BKGF_CGB_PAL4, BKGF_CGB_PAL5, BKGF_CGB_PAL6, BKGF_CGB_PAL7 */ void set_bkg_palette(uint8_t first_palette, uint8_t nb_palettes, palette_color_t *rgb_data) OLDCALL; @@ -115,6 +117,8 @@ void set_bkg_palette(uint8_t first_palette, uint8_t nb_palettes, palette_color_t \li Each component (R, G, B) may have values from 0 - 31 (5 bits), 31 is brightest. @see RGB(), set_sprite_palette_entry() + @see OAMF_CGB_PAL0, OAMF_CGB_PAL1, OAMF_CGB_PAL2, OAMF_CGB_PAL3 + @see OAMF_CGB_PAL4, OAMF_CGB_PAL5, OAMF_CGB_PAL6, OAMF_CGB_PAL7 */ void set_sprite_palette(uint8_t first_palette, uint8_t nb_palettes, palette_color_t *rgb_data) OLDCALL; @@ -125,6 +129,8 @@ void set_sprite_palette(uint8_t first_palette, uint8_t nb_palettes, palette_colo @param rgb_data New color data in BGR 15bpp format. @see set_bkg_palette(), RGB() + @see BKGF_CGB_PAL0, BKGF_CGB_PAL1, BKGF_CGB_PAL2, BKGF_CGB_PAL3 + @see BKGF_CGB_PAL4, BKGF_CGB_PAL5, BKGF_CGB_PAL6, BKGF_CGB_PAL7 */ void set_bkg_palette_entry(uint8_t palette, uint8_t entry, uint16_t rgb_data) OLDCALL; @@ -136,6 +142,8 @@ void set_bkg_palette_entry(uint8_t palette, uint8_t entry, uint16_t rgb_data) OL @param rgb_data New color data in BGR 15bpp format. @see set_sprite_palette(), RGB() + @see OAMF_CGB_PAL0, OAMF_CGB_PAL1, OAMF_CGB_PAL2, OAMF_CGB_PAL3 + @see OAMF_CGB_PAL4, OAMF_CGB_PAL5, OAMF_CGB_PAL6, OAMF_CGB_PAL7 */ void set_sprite_palette_entry(uint8_t palette, uint8_t entry, uint16_t rgb_data) OLDCALL; diff --git a/gbdk-lib/include/gb/gb.h b/gbdk-lib/include/gb/gb.h @@ -868,8 +868,8 @@ inline void set_1bpp_colors(uint8_t fgcolor, uint8_t bgcolor) { Note: Sprite Tiles 128-255 share the same memory region as Background Tiles 128-255. GBC only: @ref VBK_REG determines which bank of Background tile patterns are written to. - \li VBK_REG=0 indicates the first bank - \li VBK_REG=1 indicates the second + \li VBK_REG = @ref VBK_BANK_0 indicates the first bank + \li VBK_REG = @ref VBK_BANK_1 indicates the second @see set_win_data, set_tile_data */ @@ -937,8 +937,8 @@ void get_bkg_data(uint8_t first_tile, uint8_t nb_tiles, uint8_t *data) OLDCALL P Note: Patterns 128-255 overlap with patterns 128-255 of the sprite Tile Pattern table. GBC only: @ref VBK_REG determines whether Tile Numbers or Tile Attributes get set. - \li VBK_REG=0 Tile Numbers are written - \li VBK_REG=1 Tile Attributes are written + \li VBK_REG = @ref VBK_TILES Tile Numbers are written + \li VBK_REG = @ref VBK_ATTRIBUTES Tile Attributes are written GBC Tile Attributes are defined as: \li Bit 7 - Priority flag. When this is set, it puts the tile above the sprites @@ -1216,8 +1216,8 @@ void get_win_data(uint8_t first_tile, uint8_t nb_tiles, uint8_t *data) OLDCALL P Note: Patterns 128-255 overlap with patterns 128-255 of the sprite Tile Pattern table. GBC only: @ref VBK_REG determines whether Tile Numbers or Tile Attributes get set. - \li VBK_REG=0 Tile Numbers are written - \li VBK_REG=1 Tile Attributes are written + \li VBK_REG = @ref VBK_TILES Tile Numbers are written + \li VBK_REG = @ref VBK_ATTRIBUTES Tile Attributes are written For more details about GBC Tile Attributes see @ref set_bkg_tiles. @@ -1280,8 +1280,8 @@ inline void set_win_based_tiles(uint8_t x, uint8_t y, uint8_t w, uint8_t h, cons the Left and Top edges. GBC only: @ref VBK_REG determines whether Tile Numbers or Tile Attributes get set. - \li VBK_REG=0 Tile Numbers are written - \li VBK_REG=1 Tile Attributes are written + \li VBK_REG = @ref VBK_TILES Tile Numbers are written + \li VBK_REG = @ref VBK_ATTRIBUTES Tile Attributes are written See @ref set_bkg_tiles for details about CGB attribute maps with @ref VBK_REG. @@ -1398,8 +1398,8 @@ inline void scroll_win(int8_t x, int8_t y) { Note: Sprite Tiles 128-255 share the same memory region as Background Tiles 128-255. GBC only: @ref VBK_REG determines which bank of Background tile patterns are written to. - \li VBK_REG=0 indicates the first bank - \li VBK_REG=1 indicates the second + \li VBK_REG = @ref VBK_BANK_0 indicates the first bank + \li VBK_REG = @ref VBK_BANK_1 indicates the second */ void set_sprite_data(uint8_t first_tile, uint8_t nb_tiles, const uint8_t *data) OLDCALL PRESERVES_REGS(b, c); #define set_sprite_2bpp_data set_sprite_data @@ -1617,8 +1617,8 @@ inline void hide_sprite(uint8_t nb) { Copies __len__ bytes from a buffer at __data__ to VRAM starting at __vram_addr__. GBC only: @ref VBK_REG determines which bank of Background tile patterns are written to. - \li VBK_REG=0 indicates the first bank - \li VBK_REG=1 indicates the second + \li VBK_REG = @ref VBK_BANK_0 indicates the first bank + \li VBK_REG = @ref VBK_BANK_1 indicates the second @see set_bkg_data, set_win_data, set_bkg_tiles, set_win_tiles, set_tile_data, set_tiles */ @@ -1635,8 +1635,8 @@ void set_data(uint8_t *vram_addr, const uint8_t *data, uint16_t len) OLDCALL PRE Copies __len__ bytes from VRAM starting at __vram_addr__ into a buffer at __data__. GBC only: @ref VBK_REG determines which bank of Background tile patterns are written to. - \li VBK_REG=0 indicates the first bank - \li VBK_REG=1 indicates the second + \li VBK_REG = @ref VBK_BANK_0 indicates the first bank + \li VBK_REG = @ref VBK_BANK_1 indicates the second @see get_bkg_data, get_win_data, get_bkg_tiles, get_win_tiles, get_tiles */ @@ -1651,8 +1651,8 @@ void get_data(uint8_t *data, uint8_t *vram_addr, uint16_t len) OLDCALL PRESERVES Copies __len__ bytes from or to VRAM starting at __sour__ into a buffer or to VRAM at __dest__. GBC only: @ref VBK_REG determines which bank of Background tile patterns are written to. - \li VBK_REG=0 indicates the first bank - \li VBK_REG=1 indicates the second + \li VBK_REG = @ref VBK_BANK_0 indicates the first bank + \li VBK_REG = @ref VBK_BANK_1 indicates the second */ void vmemcpy(uint8_t *dest, uint8_t *sour, uint16_t len) OLDCALL PRESERVES_REGS(b, c); @@ -1676,8 +1676,8 @@ void vmemcpy(uint8_t *dest, uint8_t *sour, uint16_t len) OLDCALL PRESERVES_REGS( There are two 32x32 Tile Maps in VRAM at addresses 9800h-9BFFh and 9C00h-9FFFh. GBC only: @ref VBK_REG determines whether Tile Numbers or Tile Attributes get set. - \li VBK_REG=0 Tile Numbers are written - \li VBK_REG=1 Tile Attributes are written + \li VBK_REG = @ref VBK_TILES Tile Numbers are written + \li VBK_REG = @ref VBK_ATTRIBUTES Tile Attributes are written @see set_bkg_tiles, set_win_tiles */ diff --git a/gbdk-lib/include/gb/hardware.h b/gbdk-lib/include/gb/hardware.h @@ -309,13 +309,13 @@ __REG KEY1_REG; /**< CPU speed */ #define KEY1F_DBLSPEED 0b10000000 #define KEY1F_PREPARE 0b00000001 -__REG VBK_REG; /**< VRAM bank select (CGB only)*/ +__REG VBK_REG; /**< VRAM bank select (CGB only) @see VBK_BANK_0, VBK_TILES, VBK_BANK_1, VBK_ATTRIBUTES */ #define rVBK VBK_REG #define VBK_BANK_0 0 /**< Select Regular Map and Normal Tiles (CGB Mode Only) */ #define VBK_TILES 0 /**< Select Regular Map and Normal Tiles (CGB Mode Only) */ #define VBK_BANK_1 1 /**< Select Map Attributes and Extra Tile Bank (CGB Mode Only)*/ -#define VBK_ATTRIBUTES 1 /**< Select Regular Map and Normal Tiles (CGB Mode Only) */ +#define VBK_ATTRIBUTES 1 /**< Select Map Attributes and Extra Tile Bank (CGB Mode Only) */ #define BKGF_PRI 0b10000000 /**< Background CGB BG and Window over Sprite priority Enabled */ #define BKGF_YFLIP 0b01000000 /**< Background CGB Y axis flip: Vertically mirrored */ @@ -362,6 +362,7 @@ __REG BCPS_REG; /**< BG color palette specification */ #define BCPSF_AUTOINC 0b10000000 __REG BCPD_REG; /**< BG color palette data */ #define rBCPD BCPD_REG + __REG OCPS_REG; /**< OBJ color palette specification */ #define rOCPS OCPS_REG
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.