pokecrystal-board/home/tilemap.asm

212 lines
3.1 KiB
NASM
Raw Normal View History

ClearBGMap0or2::
ld a, " "
FillBGMap0or2::
hlbgcoord 0, 0
ld bc, vBGMap1 - vBGMap0
jp ByteFill
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::
ld a, 2
ldh [hBGMapMode], a
ld c, 4
call DelayFrames
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
ApplyTilemap::
ld a, [wSpriteUpdatesEnabled]
cp 0
jr z, .wait_bg_map
ld a, 1
ldh [hBGMapMode], a
jr CopyTilemapAtOnce
.wait_bg_map
; 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
CopyTilemapAtOnce::
ldh a, [hBGMapMode]
push af
xor a
ldh [hBGMapMode], a
ldh a, [hMapAnims]
push af
xor a
ldh [hMapAnims], a
call DelayFrame
2023-08-29 09:33:20 -07:00
ldh a, [hWindowHUDLY]
and a
jr z, .go
2023-08-29 09:33:20 -07:00
; wait until LCD interrupt has ocurred this frame ([rLY] - [hWindowHUDLY] >= 0)
.wait_lcd
2023-08-29 09:33:20 -07:00
; ldh a, [hWindowHUDLY]
ld b, a
ldh a, [rLY]
sub b
jr c, .wait_lcd
.go
di
ld a, BANK(vBGMap2)
ldh [rVBK], a
hlcoord 0, 0, wAttrmap
call .CopyBGMapViaStack
ld a, BANK(vBGMap0)
ldh [rVBK], a
hlcoord 0, 0
call .CopyBGMapViaStack
ei
pop af
ldh [hMapAnims], a
pop af
ldh [hBGMapMode], a
ret
.CopyBGMapViaStack:
; 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 << rSTAT_BUSY ; not in v/hblank
ld c, LOW(rSTAT)
.loop
rept SCREEN_WIDTH / 2
pop de
; if not in v/hblank, wait until in v/hblank
.loop\@
2019-02-16 09:17:55 -08:00
ldh a, [c]
and b
jr nz, .loop\@
; load vBGMap
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
2024-02-10 15:16:00 -08:00
SetDefaultBGPAndOBP::
; Inits the Palettes
; depending on the system the monochromes palettes or color palettes
ldh a, [hCGB]
and a
2024-02-10 15:16:00 -08:00
jr nz, .SetDefaultBGPAndOBPForGameBoyColor
ld a, %11100100
ldh [rBGP], a
ld a, %11010000
ldh [rOBP0], a
ldh [rOBP1], a
ret
2024-02-10 15:16:00 -08:00
.SetDefaultBGPAndOBPForGameBoyColor:
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
2020-08-03 14:41:01 -07:00
ld a, TRUE
ldh [hCGBPalUpdate], a
ret
GetMemCGBLayout::
ld b, CGB_DEFAULT
GetCGBLayout::
predef_jump LoadCGBLayout
Small home/ reorganization Time to move everything out of home.asm: - InexplicablyEmptyFunction was moved to home/map.asm - The wDebugFlags functions and xor_a brothers were moved to home/flag.asm because they're all flag-related. - ret_2f3e was moved into home/region.asm - The register alias sisters were moved to a new file called home/call_regs.asm - IsInArray and SkipNames were joined by AddNTimes from home/math.asm into home/array.asm, as they're all used to index arrays. - CallPointerAt was moved into home/print_text.asm because given the contents of that file it doesn't feel very out of place (that file isn't very aptly named...) - CountSetBits was moved into home/pokedex_flags.asm because it's unique use is counting the amount of seen/caught mon in the podedex. GetWeekday was pulled into this by proximity. Other changes were also made: - PushLYOverrides was moved from home/sprite_anims.asm to home/battle.asm, because it's almost exclusively used for battle animations, with the lone exception being the Magnet Train. - home/copy.asm was renamed to home/gfx.asm, as it's all gfx-related - home/copy2.asm was renamed to home/copy.asm, now it's the only file called copy. - SetHPPal and GetHPPal were moved from home/hp_pals.asm to home/tilemap.asm, as they're attrmap related, like many functions in that file are. - home/rtc.asm was renamed to home/time_palettes.asm, as it had very little to do with the RTC at all, all RTC functions being in home/time.asm - home/handshake.asm was renamed to home/printer.asm. - home/mon_data_2.asm was renamed to home/mon_party.asm.
2020-02-21 14:48:51 -08:00
SetHPPal::
; Set palette for hp bar pixel length e at hl.
call GetHPPal
ld [hl], d
ret
GetHPPal::
; Get palette for hp bar pixel length e in d.
ld d, HP_GREEN
ld a, e
cp (HP_BAR_LENGTH_PX * 50 / 100) ; 24
ret nc
inc d ; HP_YELLOW
cp (HP_BAR_LENGTH_PX * 21 / 100) ; 10
ret nc
inc d ; HP_RED
ret