From 2907d65a478da7774d48333c2a8e4281a169a447 Mon Sep 17 00:00:00 2001 From: Idain Date: Fri, 17 Nov 2023 14:24:09 -0400 Subject: [PATCH] Improve use of palette macro and use PAL_* constants (#1087) * Improve use of palette macro and use PAL_* constants * Use proper constant for battle stats (#1088) * Add suggestions about function names and variables * Add colors macro --------- Co-authored-by: vulcandth --- engine/battle_anims/bg_effects.asm | 40 +++++++++++++++--------------- engine/gfx/color.asm | 2 +- engine/gfx/crystal_layouts.asm | 2 +- engine/tilesets/timeofday_pals.asm | 4 +-- macros/gfx.asm | 1 + mobile/mobile_22.asm | 8 +++--- mobile/mobile_42.asm | 16 ++++++------ mobile/mobile_45_sprite_engine.asm | 2 +- mobile/mobile_5b.asm | 4 +-- 9 files changed, 40 insertions(+), 39 deletions(-) diff --git a/engine/battle_anims/bg_effects.asm b/engine/battle_anims/bg_effects.asm index 1e55b39e7..62eb95b77 100644 --- a/engine/battle_anims/bg_effects.asm +++ b/engine/battle_anims/bg_effects.asm @@ -2076,10 +2076,10 @@ BattleBGEffect_FadeMonsToBlackRepeating: add hl, de ld a, [hli] push hl - call BGEffects_LoadBGPal1_OBPal0 + call BGEffects_LoadEnemyPals pop hl ld a, [hl] - call BGEffects_LoadBGPal0_OBPal1 + call BGEffects_LoadPlayerPals ret .player_2 @@ -2087,17 +2087,17 @@ BattleBGEffect_FadeMonsToBlackRepeating: add hl, de ld a, [hli] push hl - call BGEffects_LoadBGPal0_OBPal1 + call BGEffects_LoadPlayerPals pop hl ld a, [hl] - call BGEffects_LoadBGPal1_OBPal0 + call BGEffects_LoadEnemyPals ret .cgb_two ld a, $e4 - call BGEffects_LoadBGPal0_OBPal1 + call BGEffects_LoadPlayerPals ld a, $e4 - call BGEffects_LoadBGPal1_OBPal0 + call BGEffects_LoadEnemyPals call EndBattleBGEffect ret @@ -2507,7 +2507,7 @@ BGEffect_RapidCyclePals: ld [hl], a call BattleBGEffect_GetFirstDMGPal jr c, .okay_2_cgb - call BGEffects_LoadBGPal0_OBPal1 + call BGEffects_LoadPlayerPals ret .okay_2_cgb @@ -2518,7 +2518,7 @@ BGEffect_RapidCyclePals: .two_cgb ld a, $e4 - call BGEffects_LoadBGPal0_OBPal1 + call BGEffects_LoadPlayerPals call EndBattleBGEffect ret @@ -2538,7 +2538,7 @@ BGEffect_RapidCyclePals: ld [hl], a call BattleBGEffect_GetFirstDMGPal jr c, .okay_4_cgb - call BGEffects_LoadBGPal1_OBPal0 + call BGEffects_LoadEnemyPals ret .okay_4_cgb @@ -2549,11 +2549,11 @@ BGEffect_RapidCyclePals: .four_cgb ld a, $e4 - call BGEffects_LoadBGPal1_OBPal0 + call BGEffects_LoadEnemyPals call EndBattleBGEffect ret -BGEffects_LoadBGPal0_OBPal1: +BGEffects_LoadPlayerPals: ld h, a ldh a, [rSVBK] push af @@ -2562,13 +2562,13 @@ BGEffects_LoadBGPal0_OBPal1: ld a, h push bc push af - ld hl, wBGPals2 - ld de, wBGPals1 + ld hl, wBGPals2 palette PAL_BATTLE_BG_PLAYER + ld de, wBGPals1 palette PAL_BATTLE_BG_PLAYER ld b, a ld c, $1 call CopyPals - ld hl, wOBPals2 palette 1 - ld de, wOBPals1 palette 1 + ld hl, wOBPals2 palette PAL_BATTLE_OB_PLAYER + ld de, wOBPals1 palette PAL_BATTLE_OB_PLAYER pop af ld b, a ld c, $1 @@ -2580,7 +2580,7 @@ BGEffects_LoadBGPal0_OBPal1: ldh [hCGBPalUpdate], a ret -BGEffects_LoadBGPal1_OBPal0: +BGEffects_LoadEnemyPals: ld h, a ldh a, [rSVBK] push af @@ -2589,13 +2589,13 @@ BGEffects_LoadBGPal1_OBPal0: ld a, h push bc push af - ld hl, wBGPals2 palette 1 - ld de, wBGPals1 palette 1 + ld hl, wBGPals2 palette PAL_BATTLE_BG_ENEMY + ld de, wBGPals1 palette PAL_BATTLE_BG_ENEMY ld b, a ld c, $1 call CopyPals - ld hl, wOBPals2 - ld de, wOBPals1 + ld hl, wOBPals2 palette PAL_BATTLE_OB_ENEMY + ld de, wOBPals1 palette PAL_BATTLE_OB_ENEMY pop af ld b, a ld c, $1 diff --git a/engine/gfx/color.asm b/engine/gfx/color.asm index 2ae8b0335..d88f85981 100644 --- a/engine/gfx/color.asm +++ b/engine/gfx/color.asm @@ -729,7 +729,7 @@ CGBCopyBattleObjectPals: ; unreferenced dec c jr nz, .loop ld hl, BattleObjectPals - ld de, wOBPals1 palette 2 + ld de, wOBPals1 palette PAL_BATTLE_OB_GRAY ld bc, 2 palettes ld a, BANK(wOBPals1) call FarCopyWRAM diff --git a/engine/gfx/crystal_layouts.asm b/engine/gfx/crystal_layouts.asm index f77d420f3..9c2755e3d 100644 --- a/engine/gfx/crystal_layouts.asm +++ b/engine/gfx/crystal_layouts.asm @@ -124,7 +124,7 @@ Palette_TextBG7: INCLUDE "gfx/font/bg_text.pal" Function49420:: - ld hl, MansionPalette1 + 8 palettes + ld hl, MansionPalette1 palette 8 ld de, wBGPals1 palette PAL_BG_ROOF ld bc, 1 palettes ld a, BANK(wBGPals1) diff --git a/engine/tilesets/timeofday_pals.asm b/engine/tilesets/timeofday_pals.asm index 214d2f743..12c44f377 100644 --- a/engine/tilesets/timeofday_pals.asm +++ b/engine/tilesets/timeofday_pals.asm @@ -168,14 +168,14 @@ FillWhiteBGColor: ld e, a ld a, [hli] ld d, a - ld hl, wBGPals1 + 1 palettes + ld hl, wBGPals1 palette 1 color 0 ld c, 6 .loop ld a, e ld [hli], a ld a, d ld [hli], a -rept 6 +rept 3 colors inc hl endr dec c diff --git a/macros/gfx.asm b/macros/gfx.asm index 630b131cd..93b96a518 100644 --- a/macros/gfx.asm +++ b/macros/gfx.asm @@ -22,6 +22,7 @@ DEF palblue EQUS "(1 << 10) *" DEF palettes EQUS "* PALETTE_SIZE" DEF palette EQUS "+ PALETTE_SIZE *" DEF color EQUS "+ PAL_COLOR_SIZE *" +DEF colors EQUS "* PAL_COLOR_SIZE" DEF tiles EQUS "* LEN_2BPP_TILE" DEF tile EQUS "+ LEN_2BPP_TILE *" diff --git a/mobile/mobile_22.asm b/mobile/mobile_22.asm index eb79f79de..a44604e82 100644 --- a/mobile/mobile_22.asm +++ b/mobile/mobile_22.asm @@ -641,7 +641,7 @@ Function894dc: ld bc, 3 palettes call CopyBytes ld hl, .Pals345 - ld de, wBGPals1 + 3 palettes + ld de, wBGPals1 palette 3 ld bc, 3 palettes call CopyBytes @@ -2056,7 +2056,7 @@ Function89d0d: jr nz, .loop ld hl, .Palette2 - ld de, wBGPals1 + 2 palettes + ld de, wBGPals1 palette 2 ld bc, 1 palettes call CopyBytes @@ -3232,7 +3232,7 @@ Function8a5b6: ld a, $5 ldh [rSVBK], a ld hl, Palette_8a5e5 - ld de, wBGPals1 + 4 palettes + ld de, wBGPals1 palette 4 ld bc, 3 palettes call CopyBytes ld hl, Palette_8a5fd @@ -3240,7 +3240,7 @@ Function8a5b6: ld bc, 1 palettes call CopyBytes ld hl, Palette_8a605 - ld de, wOBPals1 + 1 palettes + ld de, wOBPals1 palette 1 ld bc, 1 palettes call CopyBytes pop af diff --git a/mobile/mobile_42.asm b/mobile/mobile_42.asm index 558bfeb97..bd469ea7e 100644 --- a/mobile/mobile_42.asm +++ b/mobile/mobile_42.asm @@ -975,7 +975,7 @@ MobileTradeAnim_GiveTrademon1: MobileTradeAnim_GiveTrademon2: ld c, 40 - ld hl, wBGPals2 + 1 palettes + ld hl, wBGPals2 palette 1 call Function1082f0 call Function108af4 call Function108b5a @@ -1069,12 +1069,12 @@ MobileTradeAnim_GetTrademon1: MobileTradeAnim_GetTrademon2: ld c, 20 - ld hl, wBGPals2 + 1 palettes + ld hl, wBGPals2 palette 1 call Function1082fa ld de, SFX_GIVE_TRADEMON call PlaySFX ld c, 20 - ld hl, wBGPals2 + 1 palettes + ld hl, wBGPals2 palette 1 call Function1082fa call Function108af4 .asm_1088ad @@ -1439,8 +1439,8 @@ Function108b5a: ld a, $5 ldh [rSVBK], a ld de, palred 18 + palgreen 31 + palblue 15 - ld hl, wBGPals2 + 4 palettes - ld c, $10 + ld hl, wBGPals2 palette 4 + ld c, 2 palettes .loop ld a, e ld [hli], a @@ -1491,13 +1491,13 @@ Function108b98: and $1 xor d jr z, .asm_108bad - ld hl, Palette_108b98 + 1 palettes + ld hl, Palette_108b98 palette 1 jr .asm_108bb0 .asm_108bad ld hl, Palette_108b98 .asm_108bb0 - ld de, wBGPals1 + 7 palettes + ld de, wBGPals1 palette 7 ld bc, 8 palettes call CopyBytes pop af @@ -1724,7 +1724,7 @@ LoadMobileAdapterPalette: ld hl, MobileAdapterPalettes call AddNTimes ld a, BANK(wBGPals1) - ld de, wBGPals1 + 4 palettes + ld de, wBGPals1 palette 4 ld bc, 1 palettes call FarCopyWRAM ret diff --git a/mobile/mobile_45_sprite_engine.asm b/mobile/mobile_45_sprite_engine.asm index 6a0cb09c9..d316d6a78 100644 --- a/mobile/mobile_45_sprite_engine.asm +++ b/mobile/mobile_45_sprite_engine.asm @@ -515,7 +515,7 @@ Function1162cb: ld a, $5 ldh [rSVBK], a ld hl, PichuBorderMobileOBPalettes - ld de, wOBPals1 + 2 palettes + ld de, wOBPals1 palette 2 ld bc, 6 palettes call CopyBytes call SetPalettes diff --git a/mobile/mobile_5b.asm b/mobile/mobile_5b.asm index 1a363158b..c1f4228c7 100644 --- a/mobile/mobile_5b.asm +++ b/mobile/mobile_5b.asm @@ -676,13 +676,13 @@ Function16cc18: Function16cc25: ld hl, Unknown_16cfa9 - ld de, wBGPals1 + 1 palettes + ld de, wBGPals1 palette 1 call .CopyPal ld hl, Unknown_16cfb1 ld de, wOBPals1 call .CopyPal ld hl, Unknown_16cfb9 - ld de, wOBPals1 + 1 palettes + ld de, wOBPals1 palette 1 call .CopyPal ret