2018-06-24 07:09:41 -07:00
|
|
|
ClearBGPalettes::
|
2018-04-04 21:35:14 -07:00
|
|
|
call ClearPalettes
|
2018-06-24 07:09:41 -07:00
|
|
|
WaitBGMap::
|
2018-04-04 21:35:14 -07:00
|
|
|
; Tell VBlank to update BG Map
|
|
|
|
ld a, 1 ; BG Map 0 tiles
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hBGMapMode], a
|
2018-04-04 21:35:14 -07:00
|
|
|
; Wait for it to do its magic
|
|
|
|
ld c, 4
|
|
|
|
call DelayFrames
|
2015-10-24 07:34:19 -07:00
|
|
|
ret
|
2018-04-04 21:35:14 -07:00
|
|
|
|
2018-06-24 17:10:37 -07:00
|
|
|
WaitBGMap2::
|
2018-04-04 21:35:14 -07:00
|
|
|
ld a, 2
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hBGMapMode], a
|
2018-04-04 21:35:14 -07:00
|
|
|
ld c, 4
|
|
|
|
call DelayFrames
|
|
|
|
|
|
|
|
ld a, 1
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hBGMapMode], a
|
2018-04-04 21:35:14 -07:00
|
|
|
ld c, 4
|
|
|
|
call DelayFrames
|
2015-10-24 07:34:19 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
ApplyTilemap::
|
2018-04-04 21:35:14 -07:00
|
|
|
ld a, [wSpriteUpdatesEnabled]
|
|
|
|
cp 0
|
2023-07-26 05:29:16 -07:00
|
|
|
jr z, .wait_bg_map
|
2018-04-04 21:35:14 -07:00
|
|
|
|
|
|
|
ld a, 1
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hBGMapMode], a
|
2018-04-04 21:35:14 -07:00
|
|
|
jr CopyTilemapAtOnce
|
|
|
|
|
2023-07-26 05:29:16 -07:00
|
|
|
.wait_bg_map
|
2018-04-04 21:35:14 -07:00
|
|
|
; WaitBGMap
|
|
|
|
ld a, 1
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hBGMapMode], a
|
2018-04-04 21:35:14 -07:00
|
|
|
ld c, 4
|
|
|
|
call DelayFrames
|
2015-10-24 07:34:19 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CopyTilemapAtOnce::
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hBGMapMode]
|
2018-04-04 21:35:14 -07:00
|
|
|
push af
|
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hBGMapMode], a
|
2013-11-26 03:44:05 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMapAnims]
|
2013-11-26 03:44:05 -08:00
|
|
|
push af
|
2018-04-04 21:35:14 -07:00
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMapAnims], a
|
2018-04-04 21:35:14 -07:00
|
|
|
|
2023-08-28 08:31:39 -07:00
|
|
|
call DelayFrame
|
|
|
|
|
2023-08-29 09:33:20 -07:00
|
|
|
ldh a, [hWindowHUDLY]
|
2023-08-28 08:31:39 -07:00
|
|
|
and a
|
|
|
|
jr z, .go
|
|
|
|
|
2023-08-29 09:33:20 -07:00
|
|
|
; wait until LCD interrupt has ocurred this frame ([rLY] - [hWindowHUDLY] >= 0)
|
2023-08-28 08:31:39 -07:00
|
|
|
.wait_lcd
|
2023-08-29 09:33:20 -07:00
|
|
|
; ldh a, [hWindowHUDLY]
|
2023-08-28 08:31:39 -07:00
|
|
|
ld b, a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [rLY]
|
2023-08-28 08:31:39 -07:00
|
|
|
sub b
|
|
|
|
jr c, .wait_lcd
|
2018-04-04 21:35:14 -07:00
|
|
|
|
2023-08-28 08:31:39 -07:00
|
|
|
.go
|
2018-04-04 21:35:14 -07:00
|
|
|
di
|
2020-05-16 19:25:52 -07:00
|
|
|
ld a, BANK(vBGMap2)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rVBK], a
|
2020-02-13 09:30:13 -08:00
|
|
|
hlcoord 0, 0, wAttrmap
|
2020-05-16 19:25:52 -07:00
|
|
|
call .CopyBGMapViaStack
|
|
|
|
ld a, BANK(vBGMap0)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rVBK], a
|
2018-04-04 21:35:14 -07:00
|
|
|
hlcoord 0, 0
|
2020-05-16 19:25:52 -07:00
|
|
|
call .CopyBGMapViaStack
|
2018-04-04 21:35:14 -07:00
|
|
|
ei
|
|
|
|
|
2013-11-26 03:44:05 -08:00
|
|
|
pop af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMapAnims], a
|
2018-04-04 21:35:14 -07:00
|
|
|
pop af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hBGMapMode], a
|
2013-11-26 03:44:05 -08:00
|
|
|
ret
|
2018-04-04 21:35:14 -07:00
|
|
|
|
2020-05-16 19:25:52 -07:00
|
|
|
.CopyBGMapViaStack:
|
2018-04-04 21:35:14 -07:00
|
|
|
; Copy all tiles to vBGMap
|
|
|
|
ld [hSPBuffer], sp
|
|
|
|
ld sp, hl
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hBGMapAddress + 1]
|
2018-04-04 21:35:14 -07:00
|
|
|
ld h, a
|
|
|
|
ld l, 0
|
|
|
|
ld a, SCREEN_HEIGHT
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hTilesPerCycle], a
|
2023-08-28 08:31:39 -07:00
|
|
|
ld b, 1 << rSTAT_BUSY ; not in v/hblank
|
2018-04-04 21:35:14 -07:00
|
|
|
ld c, LOW(rSTAT)
|
2013-11-26 03:44:05 -08:00
|
|
|
|
2015-11-10 13:53:37 -08:00
|
|
|
.loop
|
2018-04-04 21:35:14 -07:00
|
|
|
rept SCREEN_WIDTH / 2
|
|
|
|
pop de
|
2023-08-28 08:31:39 -07:00
|
|
|
; if not in v/hblank, wait until in v/hblank
|
2018-04-04 21:35:14 -07:00
|
|
|
.loop\@
|
2019-02-16 09:17:55 -08:00
|
|
|
ldh a, [c]
|
2018-04-04 21:35:14 -07:00
|
|
|
and b
|
|
|
|
jr nz, .loop\@
|
2020-05-16 19:25:52 -07:00
|
|
|
; load vBGMap
|
2018-04-04 21:35:14 -07:00
|
|
|
ld [hl], e
|
|
|
|
inc l
|
|
|
|
ld [hl], d
|
|
|
|
inc l
|
|
|
|
endr
|
|
|
|
|
|
|
|
ld de, BG_MAP_WIDTH - SCREEN_WIDTH
|
|
|
|
add hl, de
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hTilesPerCycle]
|
2018-04-04 21:35:14 -07:00
|
|
|
dec a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hTilesPerCycle], a
|
2015-11-10 13:53:37 -08:00
|
|
|
jr nz, .loop
|
2015-12-15 15:59:49 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hSPBuffer]
|
2018-04-04 21:35:14 -07:00
|
|
|
ld l, a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hSPBuffer + 1]
|
2018-04-04 21:35:14 -07:00
|
|
|
ld h, a
|
|
|
|
ld sp, hl
|
2013-11-26 03:44:05 -08:00
|
|
|
ret
|
2018-04-04 21:35:14 -07:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
SetPalettes::
|
2018-04-04 21:35:14 -07:00
|
|
|
; Inits the Palettes
|
|
|
|
; depending on the system the monochromes palettes or color palettes
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hCGB]
|
2018-04-04 21:35:14 -07:00
|
|
|
and a
|
|
|
|
jr nz, .SetPalettesForGameBoyColor
|
|
|
|
ld a, %11100100
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rBGP], a
|
2018-04-04 21:35:14 -07:00
|
|
|
ld a, %11010000
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rOBP0], a
|
|
|
|
ldh [rOBP1], a
|
2013-11-26 03:44:05 -08:00
|
|
|
ret
|
|
|
|
|
2018-04-04 21:35:14 -07:00
|
|
|
.SetPalettesForGameBoyColor:
|
|
|
|
push de
|
|
|
|
ld a, %11100100
|
|
|
|
call DmgToCgbBGPals
|
|
|
|
lb de, %11100100, %11100100
|
|
|
|
call DmgToCgbObjPals
|
|
|
|
pop de
|
|
|
|
ret
|
2013-11-26 03:44:05 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
ClearPalettes::
|
2018-04-04 21:35:14 -07:00
|
|
|
; Make all palettes white
|
2013-11-26 03:44:05 -08:00
|
|
|
|
2018-04-04 21:35:14 -07:00
|
|
|
; CGB: make all the palette colors white
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hCGB]
|
2018-04-04 21:35:14 -07:00
|
|
|
and a
|
|
|
|
jr nz, .cgb
|
2013-11-26 03:44:05 -08:00
|
|
|
|
2018-04-04 21:35:14 -07:00
|
|
|
; DMG: just change palettes to 0 (white)
|
2013-11-26 03:44:05 -08:00
|
|
|
xor a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rBGP], a
|
|
|
|
ldh [rOBP0], a
|
|
|
|
ldh [rOBP1], a
|
2013-11-26 03:44:05 -08:00
|
|
|
ret
|
|
|
|
|
2018-04-04 21:35:14 -07:00
|
|
|
.cgb
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [rSVBK]
|
2018-04-04 21:35:14 -07:00
|
|
|
push af
|
2013-11-26 03:44:05 -08:00
|
|
|
|
2018-04-04 21:35:14 -07:00
|
|
|
ld a, BANK(wBGPals2)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSVBK], a
|
2018-04-04 21:35:14 -07: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 11:28:22 -07:00
|
|
|
ldh [rSVBK], a
|
2018-04-04 21:35:14 -07:00
|
|
|
|
|
|
|
; Request palette update
|
2020-08-03 14:41:01 -07:00
|
|
|
ld a, TRUE
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hCGBPalUpdate], a
|
2013-11-26 03:44:05 -08:00
|
|
|
ret
|
2018-04-04 21:35:14 -07:00
|
|
|
|
2023-07-26 08:01:20 -07:00
|
|
|
GetMemCGBLayout::
|
|
|
|
ld b, CGB_DEFAULT
|
|
|
|
GetCGBLayout::
|
|
|
|
predef_jump LoadCGBLayout
|
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
|