Gameboy Development Forum

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.

Ads

#1 2019-06-01 16:18:28

ben0910
Member
Registered: 2019-04-21
Posts: 12

Background fade effect for color

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

 

#2 2019-06-03 04:59:11

esotericsean
Member
From: Buena Park, CA
Registered: 2018-01-14
Posts: 16
Website

Re: Background fade effect for color

I'm interested in doing this in GBDK. I can scroll through the bg color palettes, just like in this video.

Offline

 

#3 2019-06-03 11:35:19

bbbbbr
Member
Registered: 2019-03-04
Posts: 124

Re: Background fade effect for color

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

 

#4 2019-06-03 14:38:06

ben0910
Member
Registered: 2019-04-21
Posts: 12

Re: Background fade effect for color

Awesome, ill have to read through the ZGB code.

Offline

 

#5 2019-06-09 00:23:24

ben0910
Member
Registered: 2019-04-21
Posts: 12

Re: Background fade effect for color

Here is the solution i came up with.

Code:

#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

Code:

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

 

#6 2019-06-09 00:35:03

ben0910
Member
Registered: 2019-04-21
Posts: 12

Re: Background fade effect for color

I still need to work out fading to white

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson