From 0daaad8f45df4c79fd7d5d5ba7bcaa94912cca6f Mon Sep 17 00:00:00 2001 From: vulcandth Date: Thu, 19 Dec 2024 20:02:19 -0600 Subject: [PATCH] Optimize finding an empty pal slot --- engine/gfx/dynamic_pals.asm | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/engine/gfx/dynamic_pals.asm b/engine/gfx/dynamic_pals.asm index 81252da4f..40d472ef1 100644 --- a/engine/gfx/dynamic_pals.asm +++ b/engine/gfx/dynamic_pals.asm @@ -144,21 +144,19 @@ MarkUsedPal: push bc ; Pal is not already loaded, find a empty pal slot - lb bc, 0, 8 - ld hl, wUsedObjectPals - ld a, 1 - ld d, a -.search_again - ld a, d - and [hl] - jr z, .found_empty - ld a, d - rla - ld d, a + ld a, [wUsedObjectPals] + inc a + jr nz, .some_available + ld b, 7 + jr .unset_bit_found +.some_available + dec a + ld b, -1 +.bit_check_loop inc b - dec c - jr nz, .search_again -.found_empty + rrca + jr c, .bit_check_loop +.unset_bit_found ld a, b pop bc