Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)
You are not logged in.
Hello all,
I am trying to figure out how to create a fade from and too black effect for a colored background. I have been successful in manipulating the colors but i cannot figure out exactly how to achieve the desired effect.
Registers:
BCPS_REG
BCPD_REG
This code turned a part of the background white:
BCPS_REG = 0x06u;
BCPD_REG = 0xFFu;
BCPS_REG = 0x07u;
BCPD_REG = 0xFFu;
Any help would be greatly appreciated!
Thanks
Offline
I'm interested in doing this in GBDK. I can scroll through the bg color palettes, just like in this video.
Offline
ZGB appears to have support for Fade in/out on the color gameboy. Maybe the source will help you:
https://github.com/Zal0/ZGB/blob/b8cc0c … c/Fade_b.c
Offline
Awesome, ill have to read through the ZGB code.
Offline
Here is the solution i came up with.
#include <gb/gb.h>
#include <gb/cgb.h>
#define RGB2(r, g, b) ((UINT16)(r)) | (((UINT16)(g)) << 5) | ((((UINT16)(b)) << 8) << 2);
#define PAL_RED(C) (((C) ) & 0x1F)
#define PAL_GREEN(C) (((C) >> 5) & 0x1F)
#define PAL_BLUE(C) (((C) >> 10) & 0x1F)
const UINT16 blackPalette[4] = {0,0,0,0};
UINT16 fromToBlack(UINT8 step, UINT16 color) {
return RGB2(
PAL_RED(color) >> step,
PAL_GREEN(color) >> step,
PAL_BLUE(color) >> step
);
}
void fadeSetBlack() {
UINT8 pal;
for(pal = 0; pal != 8; pal++) {
set_bkg_palette(pal, 1, blackPalette);
}
}
void fadeIn(UINT16 palettes[][4], UINT16 speed) {
UINT8 i;
UINT8 c;
UINT8 pal;
UINT16 palette[4];
size_t length = sizeof(palettes[0]) / sizeof(palettes[0][0]);
// 5 fade steps
for(i = 0; i != 6; i ++) {
// loop through palettes passedin. always starting at 0
for(pal = 0; pal != length; pal++) {
// loop through the 4 colors of the palette
for(c = 0; c != 4; c++) {
// calculate the fade color from black
palette[c] = fromToBlack(5 - i, palettes[pal][c]);
}
set_bkg_palette(pal, 1, palette);
}
delay(speed);
}
}
void fadeOut(UINT16 palettes[][4], UINT16 speed) {
UINT8 i;
UINT8 c;
UINT8 pal;
UINT16 palette[4];
size_t length = sizeof(palettes[0]) / sizeof(palettes[0][0]);
// 5 fade steps
for(i = 0; i != 6; i ++) {
// loop through palettes passedin. always starting at 0
for(pal = 0; pal != length; pal++) {
// loop through the 4 colors of the palette
for(c = 0; c != 4; c++) {
// calculate the fade color to black
palette[c] = fromToBlack(i, palettes[pal][c]);
}
set_bkg_palette(pal, 1, palette);
}
delay(speed);
}
}
}Usage
const UINT16 allBGPalettes[2][4] = {
{
c11,
c12,
c13,
c14
},
{
c21,
c22,
c23,
c23
}
};
DISPLAY_ON;
fadeIn(allBGPalettes, 60);Last edited by ben0910 (2019-06-09 00:27:07)
Offline
I still need to work out fading to white
Offline