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