Clear VRAM correctly

This commit is contained in:
Lior Halphon 2020-05-04 23:54:43 +03:00
parent 72a90ba91c
commit f46f138e9f

View File

@ -16,6 +16,15 @@ Start:
xor a xor a
call ClearMemoryPage call ClearMemoryPage
ld [c], a ld [c], a
ld hl, $FF30
; Init waveform
ld c, $10
.waveformLoop
ldi [hl], a
cpl
dec c
jr nz, .waveformLoop
; Clear chosen input palette ; Clear chosen input palette
ldh [InputPalette], a ldh [InputPalette], a
@ -40,8 +49,6 @@ Start:
ld a, $77 ld a, $77
ldh [$24], a ldh [$24], a
call InitWaveform
; Init BG palette ; Init BG palette
ld a, $fc ld a, $fc
ldh [$47], a ldh [$47], a
@ -776,25 +783,68 @@ IF !DEF(FAST)
ld hl, BgPalettes ld hl, BgPalettes
.frameLoop .frameLoop
push bc push bc
call BrightenColor
; Brighten Color
ld a, [hli]
ld e, a
ld a, [hld]
ld d, a
; RGB(1,1,1)
ld bc, $421
; Is blue maxed?
ld a, e
and $1F
cp $1F
jr nz, .blueNotMaxed
dec c
.blueNotMaxed
; Is green maxed?
ld a, e
cp $E0
jr c, .greenNotMaxed
ld a, d
and $3
cp $3
jr nz, .greenNotMaxed
res 5, c
.greenNotMaxed
; Is red maxed?
ld a, d
and $7C
cp $7C
jr nz, .redNotMaxed
res 2, b
.redNotMaxed
; add de, bc
; ld [hli], de
ld a, e
add c
ld [hli], a
ld a, d
adc b
ld [hli], a
pop bc pop bc
dec c dec c
jr nz, .frameLoop jr nz, .frameLoop
call WaitFrame
call WaitFrame call WaitFrame
ld hl, BgPalettes ld hl, BgPalettes
call LoadBGPalettes64 call LoadBGPalettes64
call WaitFrame
dec b dec b
jr nz, .fadeLoop jr nz, .fadeLoop
ENDC ENDC
ld a, 1
call ClearVRAMViaHDMA call ClearVRAMViaHDMA
; Select the first bank call _ClearVRAMViaHDMA
xor a call ClearVRAMViaHDMA ; A = $40, so it's bank 0
ldh [$4F], a ; A should be $FF
cpl
ldh [$00], a ldh [$00], a
call ClearVRAMViaHDMA
; Final values for CGB mode ; Final values for CGB mode
ld de, $ff56 ld de, $ff56
@ -993,70 +1043,24 @@ LoadPalettes:
jr nz, .loop jr nz, .loop
ret ret
BrightenColor:
ld a, [hli]
ld e, a
ld a, [hld]
ld d, a
; RGB(1,1,1)
ld bc, $421
; Is blue maxed?
ld a, e
and $1F
cp $1F
jr nz, .blueNotMaxed
dec c
.blueNotMaxed
; Is green maxed?
ld a, e
cp $E0
jr c, .greenNotMaxed
ld a, d
and $3
cp $3
jr nz, .greenNotMaxed
res 5, c
.greenNotMaxed
; Is red maxed?
ld a, d
and $7C
cp $7C
jr nz, .redNotMaxed
res 2, b
.redNotMaxed
; add de, bc
; ld [hli], de
ld a, e
add c
ld [hli], a
ld a, d
adc b
ld [hli], a
ret
ClearVRAMViaHDMA: ClearVRAMViaHDMA:
ld hl, $FF51 ldh [$4F], a
ld hl, HDMAData
; Src _ClearVRAMViaHDMA:
ld a, $88 ld c, $51
ld [hli], a ld b, 5
xor a .loop
ld [hli], a ld a, [hli]
ldh [c], a
; Dest inc c
ld a, $98 dec b
ld [hli], a jr nz, .loop
ld a, $A0
ld [hli], a
; Do it
ld [hl], $12
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
@ -1196,17 +1200,6 @@ LoadDMGTilemap:
pop af pop af
ret ret
InitWaveform:
ld hl, $FF30
; Init waveform
xor a
ld c, $10
.waveformLoop
ldi [hl], a
cpl
dec c
jr nz, .waveformLoop
ret
SECTION "ROMMax", ROM0[$900] SECTION "ROMMax", ROM0[$900]
; Prevent us from overflowing ; Prevent us from overflowing