2018-06-24 14:09:41 +00:00
|
|
|
ClearBGPalettes::
|
2018-04-05 04:35:14 +00:00
|
|
|
call ClearPalettes
|
2018-06-24 14:09:41 +00:00
|
|
|
WaitBGMap::
|
2018-04-05 04:35:14 +00:00
|
|
|
; Tell VBlank to update BG Map
|
|
|
|
ld a, 1 ; BG Map 0 tiles
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hBGMapMode], a
|
2018-04-05 04:35:14 +00:00
|
|
|
; 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
|
|
|
|
2018-06-25 00:10:37 +00:00
|
|
|
WaitBGMap2::
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hCGB]
|
2018-04-05 04:35:14 +00:00
|
|
|
and a
|
|
|
|
jr z, .bg0
|
|
|
|
|
|
|
|
ld a, 2
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hBGMapMode], a
|
2018-04-05 04:35:14 +00:00
|
|
|
ld c, 4
|
|
|
|
call DelayFrames
|
|
|
|
|
|
|
|
.bg0
|
|
|
|
ld a, 1
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hBGMapMode], a
|
2018-04-05 04:35:14 +00:00
|
|
|
ld c, 4
|
|
|
|
call DelayFrames
|
2015-10-24 14:34:19 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
IsCGB::
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hCGB]
|
2018-04-05 04:35:14 +00:00
|
|
|
and a
|
2015-10-24 14:34:19 +00:00
|
|
|
ret
|
2018-04-05 04:35:14 +00:00
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
ApplyTilemap::
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hCGB]
|
2018-04-05 04:35:14 +00:00
|
|
|
and a
|
|
|
|
jr z, .dmg
|
|
|
|
|
|
|
|
ld a, [wSpriteUpdatesEnabled]
|
|
|
|
cp 0
|
|
|
|
jr z, .dmg
|
|
|
|
|
|
|
|
ld a, 1
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hBGMapMode], a
|
2018-04-05 04:35:14 +00:00
|
|
|
jr CopyTilemapAtOnce
|
|
|
|
|
|
|
|
.dmg
|
|
|
|
; WaitBGMap
|
|
|
|
ld a, 1
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hBGMapMode], a
|
2018-04-05 04:35:14 +00:00
|
|
|
ld c, 4
|
|
|
|
call DelayFrames
|
2015-10-24 14:34:19 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CGBOnly_CopyTilemapAtOnce::
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hCGB]
|
2018-04-05 04:35:14 +00:00
|
|
|
and a
|
|
|
|
jr z, WaitBGMap
|
2015-10-24 14:34:19 +00:00
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CopyTilemapAtOnce::
|
2018-04-05 04:35:14 +00:00
|
|
|
jr .CopyTilemapAtOnce
|
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-06-24 14:09:41 +00:00
|
|
|
.CopyTilemapAtOnce:
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hBGMapMode]
|
2018-04-05 04:35:14 +00:00
|
|
|
push af
|
|
|
|
xor a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hBGMapMode], a
|
2013-11-26 11:44:05 +00:00
|
|
|
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hMapAnims]
|
2013-11-26 11:44:05 +00:00
|
|
|
push af
|
2018-04-05 04:35:14 +00:00
|
|
|
xor a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hMapAnims], a
|
2018-04-05 04:35:14 +00:00
|
|
|
|
|
|
|
.wait
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [rLY]
|
2018-04-05 04:35:14 +00:00
|
|
|
cp $7f
|
|
|
|
jr c, .wait
|
|
|
|
|
|
|
|
di
|
|
|
|
ld a, BANK(vTiles3)
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2018-04-05 04:35:14 +00:00
|
|
|
hlcoord 0, 0, wAttrMap
|
|
|
|
call .StackPointerMagic
|
|
|
|
ld a, BANK(vTiles0)
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rVBK], a
|
2018-04-05 04:35:14 +00:00
|
|
|
hlcoord 0, 0
|
|
|
|
call .StackPointerMagic
|
|
|
|
|
|
|
|
.wait2
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [rLY]
|
2018-04-05 04:35:14 +00:00
|
|
|
cp $7f
|
|
|
|
jr c, .wait2
|
|
|
|
ei
|
|
|
|
|
2013-11-26 11:44:05 +00:00
|
|
|
pop af
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hMapAnims], a
|
2018-04-05 04:35:14 +00:00
|
|
|
pop af
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hBGMapMode], a
|
2013-11-26 11:44:05 +00:00
|
|
|
ret
|
2018-04-05 04:35:14 +00:00
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
.StackPointerMagic:
|
2018-04-05 04:35:14 +00:00
|
|
|
; Copy all tiles to vBGMap
|
|
|
|
ld [hSPBuffer], sp
|
|
|
|
ld sp, hl
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hBGMapAddress + 1]
|
2018-04-05 04:35:14 +00:00
|
|
|
ld h, a
|
|
|
|
ld l, 0
|
|
|
|
ld a, SCREEN_HEIGHT
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hTilesPerCycle], a
|
2018-04-05 04:35:14 +00:00
|
|
|
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
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hTilesPerCycle]
|
2018-04-05 04:35:14 +00:00
|
|
|
dec a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hTilesPerCycle], a
|
2015-11-10 21:53:37 +00:00
|
|
|
jr nz, .loop
|
2015-12-15 23:59:49 +00:00
|
|
|
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hSPBuffer]
|
2018-04-05 04:35:14 +00:00
|
|
|
ld l, a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hSPBuffer + 1]
|
2018-04-05 04:35:14 +00:00
|
|
|
ld h, a
|
|
|
|
ld sp, hl
|
2013-11-26 11:44:05 +00:00
|
|
|
ret
|
2018-04-05 04:35:14 +00:00
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
SetPalettes::
|
2018-04-05 04:35:14 +00:00
|
|
|
; Inits the Palettes
|
|
|
|
; depending on the system the monochromes palettes or color palettes
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hCGB]
|
2018-04-05 04:35:14 +00:00
|
|
|
and a
|
|
|
|
jr nz, .SetPalettesForGameBoyColor
|
|
|
|
ld a, %11100100
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rBGP], a
|
2018-04-05 04:35:14 +00:00
|
|
|
ld a, %11010000
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rOBP0], a
|
|
|
|
ldh [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
|
2013-11-26 11:44:05 +00:00
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
ClearPalettes::
|
2018-04-05 04:35:14 +00:00
|
|
|
; 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
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hCGB]
|
2018-04-05 04:35:14 +00:00
|
|
|
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-08-25 18:28:22 +00:00
|
|
|
ldh [rBGP], a
|
|
|
|
ldh [rOBP0], a
|
|
|
|
ldh [rOBP1], a
|
2013-11-26 11:44:05 +00:00
|
|
|
ret
|
|
|
|
|
2018-04-05 04:35:14 +00:00
|
|
|
.cgb
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [rSVBK]
|
2018-04-05 04:35:14 +00:00
|
|
|
push af
|
2013-11-26 11:44:05 +00:00
|
|
|
|
2018-04-05 04:35:14 +00:00
|
|
|
ld a, BANK(wBGPals2)
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rSVBK], a
|
2018-04-05 04:35:14 +00:00
|
|
|
|
|
|
|
; Fill wBGPals2 and wOBPals2 with $ffff (white)
|
|
|
|
ld hl, wBGPals2
|
|
|
|
ld bc, 16 palettes
|
|
|
|
ld a, $ff
|
|
|
|
call ByteFill
|
|
|
|
|
|
|
|
pop af
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [rSVBK], a
|
2018-04-05 04:35:14 +00:00
|
|
|
|
|
|
|
; Request palette update
|
|
|
|
ld a, 1
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hCGBPalUpdate], a
|
2013-11-26 11:44:05 +00:00
|
|
|
ret
|
2018-04-05 04:35:14 +00:00
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
GetMemSGBLayout::
|
2018-04-05 04:35:14 +00:00
|
|
|
ld b, SCGB_RAM
|
2018-06-24 14:09:41 +00:00
|
|
|
GetSGBLayout::
|
2018-04-05 04:35:14 +00:00
|
|
|
; load sgb packets unless dmg
|
|
|
|
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hCGB]
|
2018-04-05 04:35:14 +00:00
|
|
|
and a
|
|
|
|
jr nz, .sgb
|
|
|
|
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hSGB]
|
2018-04-05 04:35:14 +00:00
|
|
|
and a
|
|
|
|
ret z
|
|
|
|
|
|
|
|
.sgb
|
|
|
|
predef_jump LoadSGBLayout
|