Created
June 13, 2015 13:33
-
-
Save bashaus/8ea7b760b54ad19590b4 to your computer and use it in GitHub Desktop.
Game Boy Color fade script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <gb/gb.h> | |
#include "fade.h" | |
UWORD FadePalette[32] = { | |
RGB(30,0,0), RGB(0,30,0), RGB(0,0,30), RGB(0,0,0) | |
}; | |
void Fade(UWORD *org_p, FadeDirection direction, FadeColor color, UWORD speed) | |
{ | |
UBYTE i,x; | |
UWORD bit_mask; | |
bit_mask = (direction == FadeDirectionFrom) | |
? 0x0421 /* 0000010000100001 */ | |
: 0x4210; /* 0100001000010000 */ | |
for (i = 0; i < 5; i++) { /* 5 bits per color */ | |
for (x = 0; x < 32; x++) { | |
if (direction == FadeDirectionFrom && color == FadeColorBlack) { | |
/* fade from black */ | |
FadePalette[x] = org_p[x] & bit_mask; | |
} else if (direction == FadeDirectionFrom && color == FadeColorWhite) { | |
/* fade from white */ | |
FadePalette[x] = org_p[x] | (0x7FFF & ~bit_mask); | |
} else if (direction == FadeDirectionTo && color == FadeColorBlack) { | |
/* fade to black */ | |
FadePalette[x] = org_p[x] & ~bit_mask; | |
} else if (direction == FadeDirectionTo && color == FadeColorWhite) { | |
/* fade to white */ | |
FadePalette[x] = org_p[x] | bit_mask; | |
} | |
} | |
bit_mask |= (direction == FadeDirectionFrom) | |
? (bit_mask << 1) | |
: (bit_mask >> 1); | |
set_bkg_palette(0,8, &FadePalette[0]); | |
delay(speed); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _GBX_FADE_H | |
#define _GBX_FADE_H | |
typedef enum { | |
FadeDirectionFrom, | |
FadeDirectionTo | |
} FadeDirection; | |
typedef enum { | |
FadeColorBlack, | |
FadeColorWhite | |
} FadeColor; | |
void Fade(UWORD *org_p, FadeDirection direction, FadeColor color, UWORD speed); | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage: