Save 16 bytes in the CGB boot ROM

This commit is contained in:
Jakub Kądziołka 2020-05-08 13:48:31 +02:00
parent ccc7d2e887
commit 24220defd6
No known key found for this signature in database
GPG Key ID: E315A75846131564

View File

@ -181,8 +181,7 @@ ENDC
dec c dec c
jr nz, .expandPalettesLoop jr nz, .expandPalettesLoop
ld hl, BgPalettes call LoadPalettesFromHRAM
call LoadBGPalettes64
; Turn on LCD ; Turn on LCD
ld a, $91 ld a, $91
@ -530,7 +529,7 @@ Palettes:
dw $7FFF, $7FEA, $7D5F, $0000 ; CGA 1 dw $7FFF, $7FEA, $7D5F, $0000 ; CGA 1
dw $4778, $3290, $1D87, $0861 ; DMG LCD dw $4778, $3290, $1D87, $0861 ; DMG LCD
KeyCombinationPalettes KeyCombinationPalettes:
db 1 * 3 ; Right db 1 * 3 ; Right
db 48 * 3 ; Left db 48 * 3 ; Left
db 5 * 3 ; Up db 5 * 3 ; Up
@ -795,7 +794,6 @@ IF !DEF(FAST)
.fadeLoop .fadeLoop
ld c, 32 ; 32 colors to fade ld c, 32 ; 32 colors to fade
ld hl, BgPalettes ld hl, BgPalettes
push hl
.frameLoop .frameLoop
push bc push bc
@ -848,8 +846,7 @@ IF !DEF(FAST)
jr nz, .frameLoop jr nz, .frameLoop
call WaitFrame call WaitFrame
pop hl call LoadPalettesFromHRAM
call LoadBGPalettes64
call WaitFrame call WaitFrame
dec b dec b
jr nz, .fadeLoop jr nz, .fadeLoop
@ -907,7 +904,7 @@ ENDC
GetKeyComboPalette: GetKeyComboPalette:
ld hl, KeyCombinationPalettes - 1 ; Return value is 1-based, 0 means nothing down ld hl, KeyCombinationPalettes - 1 ; Return value is 1-based, 0 means nothing down
ld c ,a ld c, a
ld b, 0 ld b, 0
add hl, bc add hl, bc
ld a, [hl] ld a, [hl]
@ -1006,6 +1003,7 @@ GetPaletteIndex:
xor a xor a
ret ret
; optimizations in callers rely on this returning with b = 0
GetPaletteCombo: GetPaletteCombo:
ld hl, PaletteCombinations ld hl, PaletteCombinations
ld b, 0 ld b, 0
@ -1022,7 +1020,7 @@ LoadPalettesFromIndex: ; a = index of combination
ld a, [hli] ld a, [hli]
push hl push hl
ld hl, Palettes ld hl, Palettes
ld b, 0 ; b is already 0
ld c, a ld c, a
add hl, bc add hl, bc
ld d, 8 ld d, 8
@ -1035,15 +1033,15 @@ LoadPalettesFromIndex: ; a = index of combination
jr .loadObjPalette jr .loadObjPalette
.loadBGPalette .loadBGPalette
;BG Palette ;BG Palette
ld a, [hli] ld c, [hl]
; b is already 0
ld hl, Palettes ld hl, Palettes
ld b, 0
ld c, a
add hl, bc add hl, bc
ld d, 8 ld d, 8
jr LoadBGPalettes jr LoadBGPalettes
LoadBGPalettes64: LoadPalettesFromHRAM:
ld hl, BgPalettes
ld d, 64 ld d, 64
LoadBGPalettes: LoadBGPalettes:
@ -1076,6 +1074,7 @@ _ClearVRAMViaHDMA:
jr nz, .loop jr nz, .loop
ret ret
; clobbers AF and HL
GetInputPaletteIndex: GetInputPaletteIndex:
ld a, $20 ; Select directions ld a, $20 ; Select directions
ldh [$00], a ldh [$00], a
@ -1083,11 +1082,10 @@ GetInputPaletteIndex:
cpl cpl
and $F and $F
ret z ; No direction keys pressed, no palette ret z ; No direction keys pressed, no palette
push bc
ld c, 0
ld l, 0
.directionLoop .directionLoop
inc c inc l
rra rra
jr nc, .directionLoop jr nc, .directionLoop
@ -1100,15 +1098,13 @@ GetInputPaletteIndex:
rla rla
rla rla
and $C and $C
add c add l
ld b, a ld l, a
ldh a, [InputPalette] ldh a, [InputPalette]
ld c, a cp l
ld a, b
ldh [InputPalette], a
cp c
pop bc
ret z ; No change, don't load ret z ; No change, don't load
ld a, l
ldh [InputPalette], a
; Slide into change Animation Palette ; Slide into change Animation Palette
ChangeAnimationPalette: ChangeAnimationPalette:
@ -1118,10 +1114,8 @@ ChangeAnimationPalette:
call GetPaletteCombo call GetPaletteCombo
inc l inc l
inc l inc l
ld a, [hl] ld c, [hl]
ld hl, Palettes + 1 ld hl, Palettes + 1
ld b, 0
ld c, a
add hl, bc add hl, bc
ld a, [hld] ld a, [hld]
cp $7F ; Is white color? cp $7F ; Is white color?
@ -1186,8 +1180,7 @@ ChangeAnimationPalette:
call WaitFrame call WaitFrame
ld hl, BgPalettes call LoadPalettesFromHRAM
call LoadBGPalettes64
; Delay the wait loop while the user is selecting a palette ; Delay the wait loop while the user is selecting a palette
ld a, 45 ld a, 45
ldh [WaitLoopCounter], a ldh [WaitLoopCounter], a