From 4047f9b7644ece47f0f4c7240641b7e9b4c52cd4 Mon Sep 17 00:00:00 2001 From: Ariel A <24759293+aarant@users.noreply.github.com> Date: Wed, 25 Dec 2024 19:48:54 -0500 Subject: [PATCH] feat: added FadeScreenHardware utility --- include/field_weather.h | 1 + include/palette.h | 2 +- src/field_weather.c | 29 +++++++++++++++++++++++++++++ src/palette.c | 5 +++-- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/include/field_weather.h b/include/field_weather.h index d741bdd2b0..a8550845cc 100644 --- a/include/field_weather.h +++ b/include/field_weather.h @@ -152,6 +152,7 @@ void SetCurrentAndNextWeatherNoDelay(u8 weather); void ApplyWeatherColorMapIfIdle(s8 colorMapIndex); void ApplyWeatherColorMapIfIdle_Gradual(u8 colorMapIndex, u8 targetColorMapIndex, u8 colorMapStepDelay); void FadeScreen(u8 mode, s8 delay); +u16 FadeScreenHardware(u8 mode, s8 delay); bool8 IsWeatherNotFadingIn(void); void UpdateSpritePaletteWithWeather(u8 spritePaletteIndex, bool8 allowFog); void ApplyWeatherColorMapToPal(u8 paletteIndex); diff --git a/include/palette.h b/include/palette.h index f86ab00a63..30592a4ecb 100644 --- a/include/palette.h +++ b/include/palette.h @@ -99,7 +99,7 @@ void InvertPlttBuffer(u32 selectedPalettes); void TintPlttBuffer(u32 selectedPalettes, s8 r, s8 g, s8 b); void UnfadePlttBuffer(u32 selectedPalettes); void BeginFastPaletteFade(u8 submode); -void BeginHardwarePaletteFade(u8 blendCnt, u8 delay, u8 y, u8 targetY, u8 shouldResetBlendRegisters); +void BeginHardwarePaletteFade(u16 blendCnt, u8 delay, u8 y, u8 targetY, u8 shouldResetBlendRegisters); void BlendPalettes(u32 selectedPalettes, u8 coeff, u16 color); void BlendPalettesFine(u32 palettes, u16 *src, u16 *dst, u32 coeff, u32 color); void BlendPalettesUnfaded(u32 selectedPalettes, u8 coeff, u16 color); diff --git a/src/field_weather.c b/src/field_weather.c index 9f41014ff3..2bcaa2f857 100644 --- a/src/field_weather.c +++ b/src/field_weather.c @@ -815,6 +815,35 @@ void FadeScreen(u8 mode, s8 delay) } } +// fades screen using BLDY +// Note: This enables blending in all windows; +// These bits may need to be disabled later +u16 FadeScreenHardware(u8 mode, s8 delay) { + u16 bldCnt = GetGpuReg(REG_OFFSET_BLDCNT) & BLDCNT_TGT2_ALL; + bldCnt |= BLDCNT_TGT1_ALL; + // enable blend in all windows + SetGpuRegBits(REG_OFFSET_WININ, WININ_WIN0_CLR | WININ_WIN1_CLR); + SetGpuRegBits(REG_OFFSET_WINOUT, WINOUT_WIN01_CLR); + + switch (mode) + { + case FADE_FROM_BLACK: + BeginHardwarePaletteFade(bldCnt | BLDCNT_EFFECT_DARKEN, delay, 16, 0, TRUE); + break; + case FADE_TO_BLACK: + BeginHardwarePaletteFade(bldCnt | BLDCNT_EFFECT_DARKEN, delay, 0, 16, FALSE); + break; + case FADE_FROM_WHITE: + BeginHardwarePaletteFade(bldCnt | BLDCNT_EFFECT_LIGHTEN, delay, 16, 0, TRUE); + break; + case FADE_TO_WHITE: + BeginHardwarePaletteFade(bldCnt | BLDCNT_EFFECT_LIGHTEN, delay, 0, 16, FALSE); + break; + } + + return 0; +} + bool8 IsWeatherNotFadingIn(void) { return (gWeatherPtr->palProcessingState != WEATHER_PAL_STATE_SCREEN_FADING_IN); diff --git a/src/palette.c b/src/palette.c index ddc0688209..3ea2a08195 100644 --- a/src/palette.c +++ b/src/palette.c @@ -896,7 +896,7 @@ static u8 UpdateFastPaletteFade(void) return gPaletteFade.active ? PALETTE_FADE_STATUS_ACTIVE : PALETTE_FADE_STATUS_DONE; } -void BeginHardwarePaletteFade(u8 blendCnt, u8 delay, u8 y, u8 targetY, u8 shouldResetBlendRegisters) +void BeginHardwarePaletteFade(u16 blendCnt, u8 delay, u8 y, u8 targetY, u8 shouldResetBlendRegisters) { gPaletteFade_blendCnt = blendCnt; gPaletteFade.delayCounter = delay; @@ -950,7 +950,8 @@ static u8 UpdateHardwarePaletteFade(void) { if (gPaletteFade.shouldResetBlendRegisters) { - gPaletteFade_blendCnt = 0; + // clear TGT1 + gPaletteFade_blendCnt &= ~0xFF; gPaletteFade.y = 0; } gPaletteFade.shouldResetBlendRegisters = FALSE;