Zal0 / ZGB

Game Boy / Color engine with lots of features
MIT License
706 stars 50 forks source link

FadeOut() is broken on DMG #43

Open mhughson opened 2 years ago

mhughson commented 2 years ago

The fade functions found in "Fade.h" appear to be broken when running the non-color version of a game. FadeIn() works (fading the screen to pure white, but FadeOut() appears to have no effect. If called after calling FadeIn() the screen stays pure white. If called without first calling FadeOut(), the color does not change.

I wrote a simple example game with this Update:

void UPDATE() {
    if(KEY_TICKED(J_START))
    {
        FadeIn();
    }

    if (KEY_TICKED(J_SELECT))
    {
        FadeOut();
    }

These 2 gifs are the same game compiled as Color and Non-Color. In both cases I press START and shortly after I press SELECT. Note that while both versions fade up to white, the DMG version does not fade back down.

gb1_dmg_broken_fade

gb1_color_working_fade

mhughson commented 2 years ago

NOTE: This can be worked around by forcefully setting the DMG palettes prior to calling FadeOut() like so:

    FadeIn();
    DISPLAY_OFF;

    ...

    // Fade function on DMG reads the colors directly from registers before fading.
    // As a result, the FadeOut fails when called after FadeIn() because it tries to fade to a solid
    // color.
    // To fix this, we set the real colors right before FadeOut to set the proper
    // destination colors.
    BGP_REG = OBP0_REG = OBP1_REG = PAL_DEF(0, 1, 2, 3);

    DISPLAY_ON;
    FadeOut();