gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 0c243451c582c0420d674673d05091327327168d parent 94793354ab49de1004dcabb396281097660b061d Author: Michel Iwaniec <46843052+michel-iwaniec@users.noreply.github.com> Date: Sat, 19 Oct 2024 22:57:08 +0100 NES: Refactor NES palette setting functions for smaller code (#720) * Refactor set_bkg_palette / set_sprite_palette * Refactor set_bkg_palette_entry / set_sprite_palette_entry Diffstat:
| M | gbdk-lib/libc/targets/mos6502/nes/nes_palettes.s | 67 | ++++++++++++++++++++++++------------------------------------------- |
1 file changed, 24 insertions(+), 43 deletions(-)
diff --git a/gbdk-lib/libc/targets/mos6502/nes/nes_palettes.s b/gbdk-lib/libc/targets/mos6502/nes/nes_palettes.s @@ -13,19 +13,13 @@ ; void set_bkg_palette(uint8_t first_palette, uint8_t nb_palettes, palette_color_t *rgb_data) OLDCALL; _set_bkg_palette:: - pha - txa - asl - asl - sta *.num_entries - pla - asl - asl - tax - jmp .set_palette_impl - + clc + bcc .set_palette_impl ; void set_sprite_palette(uint8_t first_palette, uint8_t nb_palettes, palette_color_t *rgb_data) OLDCALL; _set_sprite_palette:: + sec +.set_palette_impl: + ror *REGTEMP pha txa asl @@ -34,11 +28,11 @@ _set_sprite_palette:: pla asl asl - adc #16 + bit *REGTEMP + bpl 0$ + ora #0x10 +0$: tax - ; jmp .set_palette_impl - -.set_palette_impl: ldy #0 2$: ; skip mirror entries @@ -58,43 +52,30 @@ _set_sprite_palette:: ; void set_bkg_palette_entry(uint8_t palette, uint8_t entry, palette_color_t rgb_data) OLDCALL; _set_bkg_palette_entry:: - ; Ignore entry 0 (unified background color) for all palettes except first - cpx #0 - bne 1$ - cmp #0 - beq 2$ - rts -1$: - dex - asl - asl clc - adc .identity,x - tax - lda *.src - sta __crt0_paletteShadow+1,x - rts -2$: - ; Set UBC - lda *.src - sta __crt0_paletteShadow - rts - + bcc .set_palette_entry ; void set_sprite_palette_entry(uint8_t palette, uint8_t entry, palette_color_t rgb_data) OLDCALL; _set_sprite_palette_entry:: - ; Ignore entry 0 (transparency encoding) - cpx #0 - bne 1$ - rts -1$: - dex + sec +.set_palette_entry:: + ror *REGTEMP asl asl clc adc .identity,x tax + bit *REGTEMP + bpl 0$ + ora #0x10 +0$: + tay + lda .paletteShadowLUT,y + bpl 1$ + rts +1$: + tax lda *.src - sta __crt0_paletteShadow+13,x + sta __crt0_paletteShadow,x rts .paletteShadowLUT:
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.