2018-04-05 04:35:14 +00:00
|
|
|
ClearBGPalettes:: ; 31f3
|
|
|
|
call ClearPalettes
|
|
|
|
WaitBGMap:: ; 31f6
|
|
|
|
; Tell VBlank to update BG Map
|
|
|
|
ld a, 1 ; BG Map 0 tiles
|
|
|
|
ld [hBGMapMode], a
|
|
|
|
; Wait for it to do its magic
|
|
|
|
ld c, 4
|
|
|
|
call DelayFrames
|
2015-10-24 14:34:19 +00:00
|
|
|
ret
|
2018-04-05 04:35:14 +00:00
|
|
|
; 3200
|
|
|
|
|
|
|
|
WaitBGMap2:: ; 0x3200
|
|
|
|
ld a, [hCGB]
|
|
|
|
and a
|
|
|
|
jr z, .bg0
|
|
|
|
|
|
|
|
ld a, 2
|
|
|
|
ld [hBGMapMode], a
|
|
|
|
ld c, 4
|
|
|
|
call DelayFrames
|
|
|
|
|
|
|
|
.bg0
|
|
|
|
ld a, 1
|
|
|
|
ld [hBGMapMode], a
|
|
|
|
ld c, 4
|
|
|
|
call DelayFrames
|
2015-10-24 14:34:19 +00:00
|
|
|
ret
|
2018-04-05 04:35:14 +00:00
|
|
|
; 0x3218
|
2015-10-24 14:34:19 +00:00
|
|
|
|
2018-04-05 04:35:14 +00:00
|
|
|
IsCGB:: ; 3218
|
|
|
|
ld a, [hCGB]
|
|
|
|
and a
|
2015-10-24 14:34:19 +00:00
|
|
|
ret
|
2018-04-05 04:35:14 +00:00
|
|
|
; 321c
|
|
|
|
|
|
|
|
ApplyTilemap:: ; 321c
|
|
|
|
ld a, [hCGB]
|
|
|
|
and a
|
|
|
|
jr z, .dmg
|
|
|
|
|
|
|
|
ld a, [wSpriteUpdatesEnabled]
|
|
|
|
cp 0
|
|
|
|
jr z, .dmg
|
|
|
|
|
|
|
|
ld a, 1
|
|
|
|
ld [hBGMapMode], a
|
|
|
|
jr CopyTilemapAtOnce
|
|
|
|
|
|
|
|
.dmg
|
|
|
|
; WaitBGMap
|
|
|
|
ld a, 1
|
|
|
|
ld [hBGMapMode], a
|
|
|
|
ld c, 4
|
|
|
|
call DelayFrames
|
2015-10-24 14:34:19 +00:00
|
|
|
ret
|
2018-04-05 04:35:14 +00:00
|
|
|
; 3238
|
2015-10-24 14:34:19 +00:00
|
|
|
|
2018-04-05 04:35:14 +00:00
|
|
|
CGBOnly_CopyTilemapAtOnce:: ; 3238
|
|
|
|
ld a, [hCGB]
|
|
|
|
and a
|
|
|
|
jr z, WaitBGMap
|
2015-10-24 14:34:19 +00:00
|
|
|
|
2018-04-05 04:35:14 +00:00
|
|
|
CopyTilemapAtOnce:: ; 323d
|
|
|
|
jr .CopyTilemapAtOnce
|
|
|
|
; 323f
|
2013-11-26 11:44:05 +00:00
|
|
|
|
2018-04-05 04:35:14 +00:00
|
|
|
; unused
|
|
|
|
farcall HDMATransferAttrMapAndTileMapToWRAMBank3
|
2013-11-26 11:44:05 +00:00
|
|
|
ret
|
2018-04-05 04:35:14 +00:00
|
|
|
; 3246
|
2013-11-26 11:44:05 +00:00
|
|
|
|
2018-04-05 04:35:14 +00:00
|
|
|
.CopyTilemapAtOnce: ; 3246
|
|
|
|
ld a, [hBGMapMode]
|
|
|
|
push af
|
|
|
|
xor a
|
|
|
|
ld [hBGMapMode], a
|
2013-11-26 11:44:05 +00:00
|
|
|
|
2018-04-05 04:35:14 +00:00
|
|
|
ld a, [hMapAnims]
|
2013-11-26 11:44:05 +00:00
|
|
|
push af
|
2018-04-05 04:35:14 +00:00
|
|
|
xor a
|
|
|
|
ld [hMapAnims], a
|
|
|
|
|
|
|
|
.wait
|
|
|
|
ld a, [rLY]
|
|
|
|
cp $7f
|
|
|
|
jr c, .wait
|
|
|
|
|
|
|
|
di
|
|
|
|
ld a, BANK(vTiles3)
|
|
|
|
ld [rVBK], a
|
|
|
|
hlcoord 0, 0, wAttrMap
|
|
|
|
call .StackPointerMagic
|
|
|
|
ld a, BANK(vTiles0)
|
|
|
|
ld [rVBK], a
|
|
|
|
hlcoord 0, 0
|
|
|
|
call .StackPointerMagic
|
|
|
|
|
|
|
|
.wait2
|
|
|
|
ld a, [rLY]
|
|
|
|
cp $7f
|
|
|
|
jr c, .wait2
|
|
|
|
ei
|
|
|
|
|
2013-11-26 11:44:05 +00:00
|
|
|
pop af
|
2018-04-05 04:35:14 +00:00
|
|
|
ld [hMapAnims], a
|
|
|
|
pop af
|
|
|
|
ld [hBGMapMode], a
|
2013-11-26 11:44:05 +00:00
|
|
|
ret
|
2018-04-05 04:35:14 +00:00
|
|
|
; 327b
|
|
|
|
|
|
|
|
.StackPointerMagic: ; 327b
|
|
|
|
; Copy all tiles to vBGMap
|
|
|
|
ld [hSPBuffer], sp
|
|
|
|
ld sp, hl
|
|
|
|
ld a, [hBGMapAddress + 1]
|
|
|
|
ld h, a
|
|
|
|
ld l, 0
|
|
|
|
ld a, SCREEN_HEIGHT
|
|
|
|
ld [hTilesPerCycle], a
|
|
|
|
ld b, 1 << 1 ; not in v/hblank
|
|
|
|
ld c, LOW(rSTAT)
|
2013-11-26 11:44:05 +00:00
|
|
|
|
2015-11-10 21:53:37 +00:00
|
|
|
.loop
|
2018-04-05 04:35:14 +00:00
|
|
|
rept SCREEN_WIDTH / 2
|
|
|
|
pop de
|
|
|
|
; if in v/hblank, wait until not in v/hblank
|
|
|
|
.loop\@
|
|
|
|
ld a, [$ff00+c]
|
|
|
|
and b
|
|
|
|
jr nz, .loop\@
|
|
|
|
; load BGMap0
|
|
|
|
ld [hl], e
|
|
|
|
inc l
|
|
|
|
ld [hl], d
|
|
|
|
inc l
|
|
|
|
endr
|
|
|
|
|
|
|
|
ld de, BG_MAP_WIDTH - SCREEN_WIDTH
|
|
|
|
add hl, de
|
|
|
|
ld a, [hTilesPerCycle]
|
|
|
|
dec a
|
|
|
|
ld [hTilesPerCycle], a
|
2015-11-10 21:53:37 +00:00
|
|
|
jr nz, .loop
|
2015-12-15 23:59:49 +00:00
|
|
|
|
2018-04-05 04:35:14 +00:00
|
|
|
ld a, [hSPBuffer]
|
|
|
|
ld l, a
|
|
|
|
ld a, [hSPBuffer + 1]
|
|
|
|
ld h, a
|
|
|
|
ld sp, hl
|
2013-11-26 11:44:05 +00:00
|
|
|
ret
|
2018-04-05 04:35:14 +00:00
|
|
|
; 32f9
|
|
|
|
|
|
|
|
SetPalettes:: ; 32f9
|
|
|
|
; Inits the Palettes
|
|
|
|
; depending on the system the monochromes palettes or color palettes
|
|
|
|
ld a, [hCGB]
|
|
|
|
and a
|
|
|
|
jr nz, .SetPalettesForGameBoyColor
|
|
|
|
ld a, %11100100
|
|
|
|
ld [rBGP], a
|
|
|
|
ld a, %11010000
|
|
|
|
ld [rOBP0], a
|
|
|
|
ld [rOBP1], a
|
2013-11-26 11:44:05 +00:00
|
|
|
ret
|
|
|
|
|
2018-04-05 04:35:14 +00:00
|
|
|
.SetPalettesForGameBoyColor:
|
|
|
|
push de
|
|
|
|
ld a, %11100100
|
|
|
|
call DmgToCgbBGPals
|
|
|
|
lb de, %11100100, %11100100
|
|
|
|
call DmgToCgbObjPals
|
|
|
|
pop de
|
|
|
|
ret
|
|
|
|
; 3317
|
2013-11-26 11:44:05 +00:00
|
|
|
|
2018-04-05 04:35:14 +00:00
|
|
|
ClearPalettes:: ; 3317
|
|
|
|
; Make all palettes white
|
2013-11-26 11:44:05 +00:00
|
|
|
|
2018-04-05 04:35:14 +00:00
|
|
|
; CGB: make all the palette colors white
|
|
|
|
ld a, [hCGB]
|
|
|
|
and a
|
|
|
|
jr nz, .cgb
|
2013-11-26 11:44:05 +00:00
|
|
|
|
2018-04-05 04:35:14 +00:00
|
|
|
; DMG: just change palettes to 0 (white)
|
2013-11-26 11:44:05 +00:00
|
|
|
xor a
|
2018-04-05 04:35:14 +00:00
|
|
|
ld [rBGP], a
|
|
|
|
ld [rOBP0], a
|
|
|
|
ld [rOBP1], a
|
2013-11-26 11:44:05 +00:00
|
|
|
ret
|
|
|
|
|
2018-04-05 04:35:14 +00:00
|
|
|
.cgb
|
|
|
|
ld a, [rSVBK]
|
|
|
|
push af
|
2013-11-26 11:44:05 +00:00
|
|
|
|
2018-04-05 04:35:14 +00:00
|
|
|
ld a, BANK(wBGPals2)
|
|
|
|
ld [rSVBK], a
|
|
|
|
|
|
|
|
; Fill wBGPals2 and wOBPals2 with $ffff (white)
|
|
|
|
ld hl, wBGPals2
|
|
|
|
ld bc, 16 palettes
|
|
|
|
ld a, $ff
|
|
|
|
call ByteFill
|
|
|
|
|
|
|
|
pop af
|
|
|
|
ld [rSVBK], a
|
|
|
|
|
|
|
|
; Request palette update
|
|
|
|
ld a, 1
|
|
|
|
ld [hCGBPalUpdate], a
|
2013-11-26 11:44:05 +00:00
|
|
|
ret
|
2018-04-05 04:35:14 +00:00
|
|
|
; 333e
|
|
|
|
|
|
|
|
GetMemSGBLayout:: ; 333e
|
|
|
|
ld b, SCGB_RAM
|
|
|
|
GetSGBLayout:: ; 3340
|
|
|
|
; load sgb packets unless dmg
|
|
|
|
|
|
|
|
ld a, [hCGB]
|
|
|
|
and a
|
|
|
|
jr nz, .sgb
|
|
|
|
|
|
|
|
ld a, [hSGB]
|
|
|
|
and a
|
|
|
|
ret z
|
|
|
|
|
|
|
|
.sgb
|
|
|
|
predef_jump LoadSGBLayout
|
|
|
|
; 334e
|