Proper color mixing

This commit is contained in:
Lior Halphon 2020-05-06 01:06:22 +03:00
parent a3f261184d
commit 730567dc60

View File

@ -10,12 +10,24 @@ Start:
ld a, 2 ld a, 2
ld c, $70 ld c, $70
ld [c], a ld [c], a
; Clear RAM Bank 2 (Like the original boot ROM ; Clear RAM Bank 2 (Like the original boot ROM)
ld h, $D0 ld h, $D0
xor a
call ClearMemoryPage call ClearMemoryPage
ld [c], a ld [c], a
; Clear chosen input palette
ldh [InputPalette], a
; Clear title checksum
ldh [TitleChecksum], a
ld a, $80
ldh [$26], a
ldh [$11], a
ld a, $f3
ldh [$12], a
ldh [$25], a
ld a, $77
ldh [$24], a
ld hl, $FF30 ld hl, $FF30
; Init waveform ; Init waveform
ld c, $10 ld c, $10
@ -25,10 +37,6 @@ Start:
dec c dec c
jr nz, .waveformLoop jr nz, .waveformLoop
; Clear chosen input palette
ldh [InputPalette], a
; Clear title checksum
ldh [TitleChecksum], a
; Clear OAM ; Clear OAM
ld h, $fe ld h, $fe
@ -38,16 +46,6 @@ Start:
dec c dec c
jr nz, .clearOAMLoop jr nz, .clearOAMLoop
; Init Audio
ld a, $80
ldh [$26], a
ldh [$11], a
ld a, $f3
ldh [$12], a
ldh [$25], a
ld a, $77
ldh [$24], a
; Init BG palette ; Init BG palette
ld a, $fc ld a, $fc
ldh [$47], a ldh [$47], a
@ -142,25 +140,44 @@ ENDC
; Expand Palettes ; Expand Palettes
ld de, AnimationColors ld de, AnimationColors
ld c, 16 ld c, 8
ld hl, BgPalettes ld hl, BgPalettes
xor a xor a
.expandPalettesLoop: .expandPalettesLoop:
cpl cpl
; One white or black ; One white
ldi [hl], a ld [hli], a
ldi [hl], a ld [hli], a
; Mixed with white
ld a, [de]
inc e
or $20
ld b, a
ld a, [de]
dec e
or $84
rra
rr b
ld [hl], b
inc l
ld [hli], a
; One black
xor a
ld [hli], a
ld [hli], a
; One color ; One color
push af
ld a, [de] ld a, [de]
inc de inc e
ldi [hl], a ld [hli], a
ld a, [de] ld a, [de]
inc de inc e
ldi [hl], a ld [hli], a
pop af
xor a
dec c dec c
jr nz, .expandPalettesLoop jr nz, .expandPalettesLoop
@ -200,6 +217,9 @@ ELSE
call PlaySound call PlaySound
ENDC ENDC
call Preboot call Preboot
IF DEF(AGB)
ld b, 1
ENDC
; Will be filled with NOPs ; Will be filled with NOPs
@ -208,7 +228,6 @@ BootGame:
ldh [$50], a ldh [$50], a
SECTION "MoreStuff", ROM0[$200] SECTION "MoreStuff", ROM0[$200]
; Game Palettes Data ; Game Palettes Data
TitleChecksums: TitleChecksums:
db $00 ; Default db $00 ; Default
@ -512,23 +531,23 @@ Palettes:
dw $4778, $3290, $1D87, $0861 ; DMG LCD dw $4778, $3290, $1D87, $0861 ; DMG LCD
KeyCombinationPalettes KeyCombinationPalettes
db 1 ; Right db 1 * 3 ; Right
db 48 ; Left db 48 * 3 ; Left
db 5 ; Up db 5 * 3 ; Up
db 8 ; Down db 8 * 3 ; Down
db 0 ; Right + A db 0 * 3 ; Right + A
db 40 ; Left + A db 40 * 3 ; Left + A
db 43 ; Up + A db 43 * 3 ; Up + A
db 3 ; Down + A db 3 * 3 ; Down + A
db 6 ; Right + B db 6 * 3 ; Right + B
db 7 ; Left + B db 7 * 3 ; Left + B
db 28 ; Up + B db 28 * 3 ; Up + B
db 49 ; Down + B db 49 * 3 ; Down + B
; SameBoy "Exclusives" ; SameBoy "Exclusives"
db 51 ; Right + A + B db 51 * 3 ; Right + A + B
db 52 ; Left + A + B db 52 * 3 ; Left + A + B
db 53 ; Up + A + B db 53 * 3 ; Up + A + B
db 54 ; Down + A + B db 54 * 3 ; Down + A + B
TrademarkSymbol: TrademarkSymbol:
db $3c,$42,$b9,$a5,$b9,$a5,$42,$3c db $3c,$42,$b9,$a5,$b9,$a5,$42,$3c
@ -536,19 +555,16 @@ TrademarkSymbol:
SameBoyLogo: SameBoyLogo:
incbin "SameBoyLogo.pb12" incbin "SameBoyLogo.pb12"
animation_color: MACRO
dw ((\1) >> 1) | $4210, (\1)
ENDM
AnimationColors: AnimationColors:
animation_color $7FFF, ($7FFF >> 1) ; White dw $7FFF ; White
animation_color $774F, ($774F >> 1) ; Cyan dw $774F ; Cyan
animation_color $22C7, ($22C7 >> 1) ; Green dw $22C7 ; Green
animation_color $039F, ($039F >> 1) ; Yellow dw $039F ; Yellow
animation_color $017D, ($017D >> 1) ; Orange dw $017D ; Orange
animation_color $241D, ($241D >> 1) ; Red dw $241D ; Red
animation_color $6D38, ($6D38 >> 1) ; Purple dw $6D38 ; Purple
animation_color $7102, ($7102 >> 1) ; Blue dw $7102 ; Blue
AnimationColorsEnd: AnimationColorsEnd:
; Helper Functions ; Helper Functions
@ -842,11 +858,13 @@ ENDC
call ClearVRAMViaHDMA call ClearVRAMViaHDMA
call _ClearVRAMViaHDMA call _ClearVRAMViaHDMA
call ClearVRAMViaHDMA ; A = $40, so it's bank 0 call ClearVRAMViaHDMA ; A = $40, so it's bank 0
cpl
; A should be $FF ; A should be $FF
ldh [$00], a ldh [$00], a
; Final values for CGB mode ; Final values for CGB mode
ld de, $ff56 ld d, a
ld e, c
ld l, $0d ld l, $0d
ld a, [$143] ld a, [$143]
@ -870,7 +888,7 @@ IF DEF(AGB)
ld c, a ld c, a
add a, $11 add a, $11
ld h, c ld h, c
ld b, 1 ; B is set to 1 after ret
ELSE ELSE
; Set registers to match the original CGB boot ; Set registers to match the original CGB boot
; AF = $1180, C = 0 ; AF = $1180, C = 0
@ -990,11 +1008,6 @@ GetPaletteIndex:
ret ret
GetPaletteCombo: GetPaletteCombo:
ld b, a
; Multiply by 3
add b
add b
ld hl, PaletteCombinations ld hl, PaletteCombinations
ld b, 0 ld b, 0
ld c, a ld c, a
@ -1064,10 +1077,6 @@ _ClearVRAMViaHDMA:
jr nz, .loop jr nz, .loop
ret ret
HDMAData:
db $88, $00, $98, $A0, $12
db $88, $00, $80, $00, $40
GetInputPaletteIndex: GetInputPaletteIndex:
ld a, $20 ; Select directions ld a, $20 ; Select directions
ldh [$00], a ldh [$00], a
@ -1104,7 +1113,6 @@ GetInputPaletteIndex:
; Slide into change Animation Palette ; Slide into change Animation Palette
ChangeAnimationPalette: ChangeAnimationPalette:
push hl
push bc push bc
push de push de
call GetKeyComboPalette call GetKeyComboPalette
@ -1147,16 +1155,37 @@ ChangeAnimationPalette:
inc hl inc hl
inc hl inc hl
.isNotWhite .isNotWhite
; Mixing code by ISSOtm
ldh a, [BgPalettes + 7 * 8 + 2]
and ~$21
ld b, a
ld a, [hli]
and ~$21
add a, b
ld b, a
ld a, [BgPalettes + 7 * 8 + 3]
res 2, a ; and ~$04, but not touching carry
ld c, [hl]
res 2, c ; and ~$04, but not touching carry
adc a, c
rra ; Carry sort of "extends" the accumulator, we're bringing that bit back home
ld [BgPalettes + 7 * 8 + 3], a
ld a, b
rra
ld [BgPalettes + 7 * 8 + 2], a
dec l
ld a, [hli] ld a, [hli]
ldh [BgPalettes + 7 * 8 + 6], a ; Fourth color, 7th palette ldh [BgPalettes + 7 * 8 + 6], a ; Fourth color, 7th palette
ldh [BgPalettes + 7 * 8 + 2], a ; Second color, half, 7th palette; rough color mixing
ld a, [hli] ld a, [hli]
ldh [BgPalettes + 7 * 8 + 7], a ; Fourth 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, [hli]
ldh [BgPalettes + 5], a ; Third color, first palette ldh [BgPalettes + 5], a ; Third color, first palette
call WaitFrame call WaitFrame
ld hl, BgPalettes ld hl, BgPalettes
call LoadBGPalettes64 call LoadBGPalettes64
@ -1165,7 +1194,6 @@ ChangeAnimationPalette:
ldh [WaitLoopCounter], a ldh [WaitLoopCounter], a
pop de pop de
pop bc pop bc
pop hl
ret ret
ReplaceColorInAllPalettes: ReplaceColorInAllPalettes:
@ -1197,10 +1225,14 @@ LoadDMGTilemap:
pop af pop af
ret ret
HDMAData:
db $88, $00, $98, $A0, $12
db $88, $00, $80, $00, $40
SECTION "ROMMax", ROM0[$900] BootEnd:
; Prevent us from overflowing IF BootEnd > $900
ds 1 FAIL "BootROM overflowed: {BootEnd}"
ENDC
SECTION "HRAM", HRAM[$FF80] SECTION "HRAM", HRAM[$FF80]
TitleChecksum: TitleChecksum: