Skip to content

Instantly share code, notes, and snippets.

@basxto
Last active July 30, 2019 18:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
GBDK fadeout for Game Boy and Game Boy Color
#include <gb/cgb.h>
static const UINT16 bg_palette[] = {RGB_WHITE, RGB_LIGHTGRAY, RGB_DARKGRAY, RGB_BLACK, RGB_BLACK, RGB_BLACK, RGB_BLACK};
...
void fadeout(){
for (i = 1; i != 4; ++i) {
// 0xFFE4 is 11'11 11'11 11'10 01'00
// (i << 1) is i*2
// each iteration the number gets shifted by 2 bits to the right
// each two bit pair represents a color on DMG
// BGP_REG is 8 bit and upper 8 bit will be discarded on cast
// i=0 would be 11'10 01'00
// i=1 is 11'11 10'01 etc.
BGP_REG = (0xFFE4 >> (i << 1));
// Sets palette #0 for Game Boy Color
// bg_palette is just the start address of the array
set_bkg_palette(0, 1, bg_palette + i);
performantdelay(100);
};
// don't use wait_vbl_done() until display is turned on again
DISPLAY_OFF;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment