pokecrystal-board/home/tilemap.asm

219 lines
2.9 KiB
NASM
Raw Normal View History

2018-06-24 07:09:41 -07:00
ClearBGPalettes::
call ClearPalettes
2018-06-24 07:09:41 -07:00
WaitBGMap::
; Tell VBlank to update BG Map
ld a, 1 ; BG Map 0 tiles
ldh [hBGMapMode], a
; Wait for it to do its magic
ld c, 4
call DelayFrames
2015-10-24 07:34:19 -07:00
ret
WaitBGMap2::
ldh a, [hCGB]
and a
jr z, .bg0
ld a, 2
ldh [hBGMapMode], a
ld c, 4
call DelayFrames
.bg0
ld a, 1
ldh [hBGMapMode], a
ld c, 4
call DelayFrames
2015-10-24 07:34:19 -07:00
ret
2018-06-24 07:09:41 -07:00
IsCGB::
ldh a, [hCGB]
and a
2015-10-24 07:34:19 -07:00
ret
2018-06-24 07:09:41 -07:00
ApplyTilemap::
ldh a, [hCGB]
and a
jr z, .dmg
ld a, [wSpriteUpdatesEnabled]
cp 0
jr z, .dmg
ld a, 1
ldh [hBGMapMode], a
jr CopyTilemapAtOnce
.dmg
; WaitBGMap
ld a, 1
ldh [hBGMapMode], a
ld c, 4
call DelayFrames
2015-10-24 07:34:19 -07:00
ret
2018-06-24 07:09:41 -07:00
CGBOnly_CopyTilemapAtOnce::
ldh a, [hCGB]
and a
jr z, WaitBGMap
2015-10-24 07:34:19 -07:00
2018-06-24 07:09:41 -07:00
CopyTilemapAtOnce::
jr .CopyTilemapAtOnce
; unused
farcall HDMATransferAttrMapAndTileMapToWRAMBank3
ret
2018-06-24 07:09:41 -07:00
.CopyTilemapAtOnce:
ldh a, [hBGMapMode]
push af
xor a
ldh [hBGMapMode], a
ldh a, [hMapAnims]
push af
xor a
ldh [hMapAnims], a
.wait
ldh a, [rLY]
cp $7f
jr c, .wait
di
ld a, BANK(vTiles3)
ldh [rVBK], a
hlcoord 0, 0, wAttrMap
call .StackPointerMagic
ld a, BANK(vTiles0)
ldh [rVBK], a
hlcoord 0, 0
call .StackPointerMagic
.wait2
ldh a, [rLY]
cp $7f
jr c, .wait2
ei
pop af
ldh [hMapAnims], a
pop af
ldh [hBGMapMode], a
ret
2018-06-24 07:09:41 -07:00
.StackPointerMagic:
; Copy all tiles to vBGMap
ld [hSPBuffer], sp
ld sp, hl
ldh a, [hBGMapAddress + 1]
ld h, a
ld l, 0
ld a, SCREEN_HEIGHT
ldh [hTilesPerCycle], a
ld b, 1 << 1 ; not in v/hblank
ld c, LOW(rSTAT)
.loop
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
ldh a, [hTilesPerCycle]
dec a
ldh [hTilesPerCycle], a
jr nz, .loop
2015-12-15 15:59:49 -08:00
ldh a, [hSPBuffer]
ld l, a
ldh a, [hSPBuffer + 1]
ld h, a
ld sp, hl
ret
2018-06-24 07:09:41 -07:00
SetPalettes::
; Inits the Palettes
; depending on the system the monochromes palettes or color palettes
ldh a, [hCGB]
and a
jr nz, .SetPalettesForGameBoyColor
ld a, %11100100
ldh [rBGP], a
ld a, %11010000
ldh [rOBP0], a
ldh [rOBP1], a
ret
.SetPalettesForGameBoyColor:
push de
ld a, %11100100
call DmgToCgbBGPals
lb de, %11100100, %11100100
call DmgToCgbObjPals
pop de
ret
2018-06-24 07:09:41 -07:00
ClearPalettes::
; Make all palettes white
; CGB: make all the palette colors white
ldh a, [hCGB]
and a
jr nz, .cgb
; DMG: just change palettes to 0 (white)
xor a
ldh [rBGP], a
ldh [rOBP0], a
ldh [rOBP1], a
ret
.cgb
ldh a, [rSVBK]
push af
ld a, BANK(wBGPals2)
ldh [rSVBK], a
; Fill wBGPals2 and wOBPals2 with $ffff (white)
ld hl, wBGPals2
ld bc, 16 palettes
ld a, $ff
call ByteFill
pop af
ldh [rSVBK], a
; Request palette update
ld a, 1
ldh [hCGBPalUpdate], a
ret
2018-06-24 07:09:41 -07:00
GetMemSGBLayout::
ld b, SCGB_RAM
2018-06-24 07:09:41 -07:00
GetSGBLayout::
; load sgb packets unless dmg
ldh a, [hCGB]
and a
jr nz, .sgb
ldh a, [hSGB]
and a
ret z
.sgb
predef_jump LoadSGBLayout