Handle 2bpp palettes

This commit is contained in:
Lior Halphon 2020-05-04 02:07:19 +03:00
parent b057e0d10a
commit 2225fd114c
2 changed files with 33 additions and 43 deletions

View File

@ -138,41 +138,24 @@ ENDC
; Expand Palettes ; Expand Palettes
ld de, AnimationColors ld de, AnimationColors
ld c, 8 ld c, 16
ld hl, BgPalettes ld hl, BgPalettes
xor a xor a
.expandPalettesLoop: .expandPalettesLoop:
IF !DEF(FAST)
cpl cpl
ENDC ; One white or black
; One white
ldi [hl], a ldi [hl], a
ldi [hl], a ldi [hl], a
IF DEF(FAST) ; One color
; 3 more whites push af
ldi [hl], a
ldi [hl], a
ldi [hl], a
ldi [hl], a
ldi [hl], a
ldi [hl], a
ELSE
; The actual color
ld a, [de] ld a, [de]
inc de inc de
ldi [hl], a ldi [hl], a
ld a, [de] ld a, [de]
inc de inc de
ldi [hl], a ldi [hl], a
pop af
xor a
; Two blacks
ldi [hl], a
ldi [hl], a
ldi [hl], a
ldi [hl], a
ENDC
dec c dec c
jr nz, .expandPalettesLoop jr nz, .expandPalettesLoop
@ -551,19 +534,20 @@ TrademarkSymbol:
SameBoyLogo: SameBoyLogo:
incbin "SameBoyLogo.pb12" incbin "SameBoyLogo.pb12"
AnimationColors: animation_color: MACRO
dw $7FFF ; White dw ((\1) >> 1) | $4210, (\1)
dw $774F ; Cyan ENDM
dw $22C7 ; Green
dw $039F ; Yellow
dw $017D ; Orange
dw $241D ; Red
dw $6D38 ; Purple
dw $7102 ; Blue
AnimationColorsEnd:
DMGPalettes: AnimationColors:
dw $7FFF, $32BF, $00D0, $0000 animation_color $7FFF, ($7FFF >> 1) ; White
animation_color $774F, ($774F >> 1) ; Cyan
animation_color $22C7, ($22C7 >> 1) ; Green
animation_color $039F, ($039F >> 1) ; Yellow
animation_color $017D, ($017D >> 1) ; Orange
animation_color $241D, ($241D >> 1) ; Red
animation_color $6D38, ($6D38 >> 1) ; Purple
animation_color $7102, ($7102 >> 1) ; Blue
AnimationColorsEnd:
; Helper Functions ; Helper Functions
DoubleBitsAndWriteRowTwice: DoubleBitsAndWriteRowTwice:
@ -1140,27 +1124,33 @@ ChangeAnimationPalette:
.isWhite .isWhite
push af push af
ld a, [hli] ld a, [hli]
push hl push hl
ld hl, BgPalettes ; First color, all palette ld hl, BgPalettes ; First color, all palettes
call ReplaceColorInAllPalettes
ld l, LOW(BgPalettes + 2) ; Second color, all palettes
call ReplaceColorInAllPalettes call ReplaceColorInAllPalettes
pop hl pop hl
ldh [BgPalettes + 2], a ; Second color, first palette ldh [BgPalettes + 6], a ; Fourth color, first palette
ld a, [hli] ld a, [hli]
push hl push hl
ld hl, BgPalettes + 1 ; First color, all palette ld hl, BgPalettes + 1 ; First color, all palettes
call ReplaceColorInAllPalettes
ld l, LOW(BgPalettes + 3) ; Second color, all palettes
call ReplaceColorInAllPalettes call ReplaceColorInAllPalettes
pop hl pop hl
ldh [BgPalettes + 3], a ; Second color, first palette ldh [BgPalettes + 7], a ; Fourth color, first palette
pop af pop af
jr z, .isNotWhite jr z, .isNotWhite
inc hl inc hl
inc hl inc hl
.isNotWhite .isNotWhite
ld a, [hli] ld a, [hli]
ldh [BgPalettes + 7 * 8 + 2], a ; Second color, 7th palette ldh [BgPalettes + 7 * 8 + 6], a ; Fourth color, 7th palette
ld a, [hli] ld a, [hli]
ldh [BgPalettes + 7 * 8 + 3], a ; Second color, 7th palette ldh [BgPalettes + 7 * 8 + 7], a ; Fourth color, 7th palette
ld a, [hli] ld a, [hli]
ldh [BgPalettes + 4], a ; Third color, first palette ldh [BgPalettes + 4], a ; Third color, first palette
ld a, [hl] ld a, [hl]
@ -1180,7 +1170,7 @@ ChangeAnimationPalette:
ReplaceColorInAllPalettes: ReplaceColorInAllPalettes:
ld de, 8 ld de, 8
ld c, 8 ld c, e
.loop .loop
ld [hl], a ld [hl], a
add hl, de add hl, de

View File

@ -63,6 +63,6 @@ def pb12(data):
_, infile, outfile = sys.argv _, infile, outfile = sys.argv
with open(infile, 'rb') as f: with open(infile, 'rb') as f:
data = f.read() data = f.read().rstrip(b'\x00')
with open(outfile, 'wb') as f: with open(outfile, 'wb') as f:
f.writelines(pb12(data)) f.writelines(pb12(data))