pokecrystal-board/engine/gfx/color.asm

1341 lines
19 KiB
NASM
Raw Normal View History

INCLUDE "engine/gfx/sgb_layouts.asm"
2015-11-01 15:13:31 -08:00
SHINY_ATK_BIT EQU 5
SHINY_DEF_VAL EQU 10
SHINY_SPD_VAL EQU 10
SHINY_SPC_VAL EQU 10
CheckShininess:
; Check if a mon is shiny by DVs at bc.
; Return carry if shiny.
ld l, c
ld h, b
; Attack
ld a, [hl]
2015-11-01 15:13:31 -08:00
and 1 << SHINY_ATK_BIT
jr z, .not_shiny
; Defense
ld a, [hli]
and $f
2015-11-01 15:13:31 -08:00
cp SHINY_DEF_VAL
jr nz, .not_shiny
; Speed
ld a, [hl]
and $f0
2015-11-01 15:13:31 -08:00
cp SHINY_SPD_VAL << 4
jr nz, .not_shiny
; Special
ld a, [hl]
and $f
2015-11-01 15:13:31 -08:00
cp SHINY_SPC_VAL
jr nz, .not_shiny
; shiny
scf
ret
.not_shiny
and a
ret
2018-06-04 20:36:27 -07:00
Unused_CheckShininess:
; Return carry if the DVs at hl are all 10 or higher.
; Attack
ld a, [hl]
cp 10 << 4
jr c, .not_shiny
; Defense
ld a, [hli]
and $f
cp 10
jr c, .not_shiny
; Speed
ld a, [hl]
cp 10 << 4
jr c, .not_shiny
; Special
ld a, [hl]
and $f
cp 10
jr c, .not_shiny
; shiny
scf
ret
.not_shiny
and a
ret
SGB_ApplyCreditsPals: ; unreferenced
push de
push bc
2020-10-04 15:32:33 -07:00
ld hl, PalPacket_Pal01
ld de, wSGBPals
2015-11-16 13:01:45 -08:00
ld bc, PALPACKET_LENGTH
call CopyBytes
pop bc
pop de
ld a, c
ld [wSGBPals + 3], a
ld a, b
ld [wSGBPals + 4], a
ld a, e
ld [wSGBPals + 5], a
ld a, d
ld [wSGBPals + 6], a
ld hl, wSGBPals
call PushSGBPals
2020-10-04 15:32:33 -07:00
ld hl, BlkPacket_AllPal0
call PushSGBPals
ret
InitPartyMenuPalettes:
2018-01-17 21:16:03 -08:00
ld hl, PalPacket_PartyMenu + 1
call CopyFourPalettes
2015-12-28 07:57:04 -08:00
call InitPartyMenuOBPals
call WipeAttrmap
ret
; SGB layout for SCGB_PARTY_MENU_HP_BARS
2018-06-24 07:09:41 -07:00
SGB_ApplyPartyMenuHPPals:
2015-12-22 19:19:33 -08:00
ld hl, wHPPals
ld a, [wSGBPals]
ld e, a
ld d, 0
add hl, de
ld e, l
ld d, h
ld a, [de]
and a
ld e, $5
jr z, .okay
dec a
ld e, $a
jr z, .okay
ld e, $f
.okay
push de
ld hl, wSGBPals + 10
2015-12-09 15:25:44 -08:00
ld bc, $6
ld a, [wSGBPals]
call AddNTimes
pop de
ld [hl], e
ret
2020-10-04 19:34:50 -07:00
Intro_LoadMagikarpPalettes: ; unreferenced
call CheckCGB
ret z
2016-05-05 12:07:37 -07:00
; CGB only
2020-10-30 13:12:25 -07:00
ld hl, .MagikarpBGPal
2018-01-01 06:08:21 -08:00
ld de, wBGPals1
2015-12-09 15:25:44 -08:00
ld bc, 1 palettes
ld a, BANK(wBGPals1)
call FarCopyWRAM
2020-10-30 13:12:25 -07:00
ld hl, .MagikarpOBPal
2018-01-01 06:08:21 -08:00
ld de, wOBPals1
2015-12-09 15:25:44 -08:00
ld bc, 1 palettes
ld a, BANK(wOBPals1)
call FarCopyWRAM
2015-12-16 18:57:42 -08:00
call ApplyPals
2020-08-03 14:41:01 -07:00
ld a, TRUE
ldh [hCGBPalUpdate], a
ret
2020-10-30 13:12:25 -07:00
.MagikarpBGPal:
INCLUDE "gfx/intro/gs_magikarp_bg.pal"
.MagikarpOBPal:
INCLUDE "gfx/intro/gs_magikarp_ob.pal"
2015-12-09 15:25:44 -08:00
2020-10-04 19:34:50 -07:00
Intro_LoadAllPal0: ; unreferenced
call CheckCGB
ret nz
ldh a, [hSGB]
and a
ret z
2020-10-04 15:32:33 -07:00
ld hl, BlkPacket_AllPal0
jp PushSGBPals
2020-10-04 19:34:50 -07:00
Intro_LoadBetaIntroVenusaurPalettes: ; unreferenced
call CheckCGB
2016-01-04 05:43:55 -08:00
jr nz, .cgb
ldh a, [hSGB]
and a
ret z
ld hl, PalPacket_BetaIntroVenusaur
jp PushSGBPals
2016-01-04 05:43:55 -08:00
.cgb
2018-01-01 06:08:21 -08:00
ld de, wOBPals1
ld a, PREDEFPAL_BETA_INTRO_VENUSAUR
call GetPredefPal
jp LoadHLPaletteIntoDE
2020-10-04 19:34:50 -07:00
Intro_LoadPackPalettes: ; unreferenced
call CheckCGB
2016-01-04 05:43:55 -08:00
jr nz, .cgb
ldh a, [hSGB]
and a
ret z
2018-01-17 21:16:03 -08:00
ld hl, PalPacket_Pack
jp PushSGBPals
2016-01-04 05:43:55 -08:00
.cgb
2018-01-01 06:08:21 -08:00
ld de, wOBPals1
2018-01-18 12:06:43 -08:00
ld a, PREDEFPAL_PACK
call GetPredefPal
jp LoadHLPaletteIntoDE
GSIntro_LoadMonPalette: ; unreferenced
call CheckCGB
jr nz, .cgb
ldh a, [hSGB]
and a
ret z
ld a, c
push af
2020-10-04 15:32:33 -07:00
ld hl, PalPacket_Pal01
ld de, wSGBPals
2015-11-16 13:01:45 -08:00
ld bc, PALPACKET_LENGTH
call CopyBytes
pop af
call GetMonPalettePointer
ld a, [hli]
ld [wSGBPals + 3], a
ld a, [hli]
ld [wSGBPals + 4], a
ld a, [hli]
ld [wSGBPals + 5], a
ld a, [hl]
ld [wSGBPals + 6], a
ld hl, wSGBPals
jp PushSGBPals
.cgb
2018-01-01 06:08:21 -08:00
ld de, wOBPals1
ld a, c
call GetMonPalettePointer
2015-12-16 18:57:42 -08:00
call LoadPalette_White_Col1_Col2_Black
ret
LoadTrainerClassPaletteAsNthBGPal:
2018-01-23 14:39:09 -08:00
ld a, [wTrainerClass]
2015-12-16 18:57:42 -08:00
call GetTrainerPalettePointer
ld a, e
jr LoadNthMiddleBGPal
LoadMonPaletteAsNthBGPal:
2018-01-23 14:39:09 -08:00
ld a, [wCurPartySpecies]
call _GetMonPalettePointer
ld a, e
bit 7, a
jr z, LoadNthMiddleBGPal
and $7f
inc hl
inc hl
inc hl
inc hl
LoadNthMiddleBGPal:
push hl
2018-01-01 06:08:21 -08:00
ld hl, wBGPals1
ld de, 1 palettes
.loop
and a
jr z, .got_addr
add hl, de
dec a
jr .loop
.got_addr
ld e, l
ld d, h
pop hl
2015-12-16 18:57:42 -08:00
call LoadPalette_White_Col1_Col2_Black
ret
2020-10-04 19:34:50 -07:00
LoadBetaPokerPalettes: ; unreferenced
ldh a, [hCGB]
and a
jr nz, .cgb
2020-05-17 17:59:15 -07:00
ld hl, wBetaPokerSGBPals
jp PushSGBPals
.cgb
2020-05-17 17:59:15 -07:00
ld a, [wBetaPokerSGBCol]
ld c, a
2020-05-17 17:59:15 -07:00
ld a, [wBetaPokerSGBRow]
hlcoord 0, 0, wAttrmap
ld de, SCREEN_WIDTH
.loop
and a
jr z, .done
add hl, de
dec a
jr .loop
.done
2020-05-17 17:59:15 -07:00
ld b, 0
add hl, bc
lb bc, 6, 4
2020-05-17 17:59:15 -07:00
ld a, [wBetaPokerSGBAttr]
and $3
2015-11-12 21:49:27 -08:00
call FillBoxCGB
call CopyTilemapAtOnce
ret
ApplyMonOrTrainerPals:
call CheckCGB
ret z
ld a, e
and a
jr z, .get_trainer
2018-01-23 14:39:09 -08:00
ld a, [wCurPartySpecies]
call GetMonPalettePointer
jr .load_palettes
.get_trainer
2018-01-23 14:39:09 -08:00
ld a, [wTrainerClass]
2015-12-16 18:57:42 -08:00
call GetTrainerPalettePointer
.load_palettes
2018-01-01 06:08:21 -08:00
ld de, wBGPals1
2015-12-16 18:57:42 -08:00
call LoadPalette_White_Col1_Col2_Black
call WipeAttrmap
call ApplyAttrmap
2015-12-16 18:57:42 -08:00
call ApplyPals
ret
ApplyHPBarPals:
ld a, [wWhichHPBar]
and a
jr z, .Enemy
cp $1
jr z, .Player
cp $2
jr z, .PartyMenu
ret
.Enemy:
2018-01-22 16:40:17 -08:00
ld de, wBGPals2 palette PAL_BATTLE_BG_ENEMY_HP color 1
jr .okay
.Player:
2018-01-22 16:40:17 -08:00
ld de, wBGPals2 palette PAL_BATTLE_BG_PLAYER_HP color 1
.okay
ld l, c
ld h, $0
add hl, hl
2015-12-26 18:59:03 -08:00
add hl, hl
2017-12-15 19:36:33 -08:00
ld bc, HPBarPals
add hl, bc
ld bc, 4
ld a, BANK(wBGPals2)
call FarCopyWRAM
2020-08-03 14:41:01 -07:00
ld a, TRUE
ldh [hCGBPalUpdate], a
ret
.PartyMenu:
ld e, c
inc e
hlcoord 11, 1, wAttrmap
ld bc, 2 * SCREEN_WIDTH
2018-01-23 14:39:09 -08:00
ld a, [wCurPartyMon]
.loop
and a
jr z, .done
add hl, bc
dec a
jr .loop
.done
lb bc, 2, 8
ld a, e
2015-11-12 21:49:27 -08:00
call FillBoxCGB
ret
LoadStatsScreenPals:
call CheckCGB
ret z
2015-12-22 19:19:33 -08:00
ld hl, StatsScreenPals
ld b, 0
dec c
add hl, bc
2015-12-26 18:59:03 -08:00
add hl, bc
ldh a, [rSVBK]
push af
ld a, BANK(wBGPals1)
ldh [rSVBK], a
ld a, [hli]
2018-01-01 06:08:21 -08:00
ld [wBGPals1 palette 0], a
ld [wBGPals1 palette 2], a
ld a, [hl]
2018-01-01 06:08:21 -08:00
ld [wBGPals1 palette 0 + 1], a
ld [wBGPals1 palette 2 + 1], a
pop af
ldh [rSVBK], a
2015-12-16 18:57:42 -08:00
call ApplyPals
ld a, $1
ret
LoadMailPalettes:
ld l, e
ld h, 0
add hl, hl
add hl, hl
add hl, hl
ld de, .MailPals
add hl, de
call CheckCGB
jr nz, .cgb
push hl
2020-10-04 15:32:33 -07:00
ld hl, PalPacket_Pal01
ld de, wSGBPals
2015-11-16 13:01:45 -08:00
ld bc, PALPACKET_LENGTH
call CopyBytes
pop hl
inc hl
2015-12-26 18:59:03 -08:00
inc hl
ld a, [hli]
ld [wSGBPals + 3], a
ld a, [hli]
ld [wSGBPals + 4], a
ld a, [hli]
ld [wSGBPals + 5], a
ld a, [hli]
ld [wSGBPals + 6], a
ld hl, wSGBPals
call PushSGBPals
2020-10-04 15:32:33 -07:00
ld hl, BlkPacket_AllPal0
call PushSGBPals
ret
.cgb
2018-01-01 06:08:21 -08:00
ld de, wBGPals1
2015-12-09 15:25:44 -08:00
ld bc, 1 palettes
ld a, BANK(wBGPals1)
call FarCopyWRAM
2015-12-16 18:57:42 -08:00
call ApplyPals
call WipeAttrmap
call ApplyAttrmap
ret
.MailPals:
INCLUDE "gfx/mail/mail.pal"
2015-12-09 15:25:44 -08:00
INCLUDE "engine/gfx/cgb_layouts.asm"
CopyFourPalettes:
2018-01-01 06:08:21 -08:00
ld de, wBGPals1
ld c, 4
2013-12-24 14:11:52 -08:00
CopyPalettes:
.loop
push bc
ld a, [hli]
push hl
call GetPredefPal
call LoadHLPaletteIntoDE
pop hl
inc hl
pop bc
dec c
jr nz, .loop
ret
GetPredefPal:
ld l, a
ld h, 0
add hl, hl
2016-05-05 12:07:37 -07:00
add hl, hl
add hl, hl
2017-12-15 19:36:33 -08:00
ld bc, PredefPals
add hl, bc
ret
LoadHLPaletteIntoDE:
ldh a, [rSVBK]
push af
ld a, BANK(wOBPals1)
ldh [rSVBK], a
2018-01-26 18:25:49 -08:00
ld c, 1 palettes
.loop
ld a, [hli]
ld [de], a
inc de
dec c
jr nz, .loop
pop af
ldh [rSVBK], a
ret
LoadPalette_White_Col1_Col2_Black:
ldh a, [rSVBK]
push af
ld a, BANK(wBGPals1)
ldh [rSVBK], a
2015-12-16 18:57:42 -08:00
ld a, LOW(PALRGB_WHITE)
ld [de], a
inc de
ld a, HIGH(PALRGB_WHITE)
ld [de], a
inc de
2015-12-16 18:57:42 -08:00
2018-01-22 16:40:17 -08:00
ld c, 2 * PAL_COLOR_SIZE
.loop
ld a, [hli]
ld [de], a
inc de
dec c
jr nz, .loop
2015-12-16 18:57:42 -08:00
xor a
ld [de], a
inc de
ld [de], a
inc de
2015-12-16 18:57:42 -08:00
pop af
ldh [rSVBK], a
ret
FillBoxCGB:
.row
push bc
push hl
.col
ld [hli], a
dec c
jr nz, .col
pop hl
ld bc, SCREEN_WIDTH
add hl, bc
pop bc
dec b
jr nz, .row
ret
ResetBGPals:
push af
push bc
push de
push hl
ldh a, [rSVBK]
push af
ld a, BANK(wBGPals1)
ldh [rSVBK], a
2018-01-01 06:08:21 -08:00
ld hl, wBGPals1
2017-12-25 09:41:31 -08:00
ld c, 1 palettes
2015-11-20 12:15:32 -08:00
.loop
ld a, $ff
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
xor a
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
dec c
2015-11-20 12:15:32 -08:00
jr nz, .loop
pop af
ldh [rSVBK], a
pop hl
pop de
pop bc
pop af
ret
WipeAttrmap:
hlcoord 0, 0, wAttrmap
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
xor a
call ByteFill
ret
ApplyPals:
2018-01-01 06:08:21 -08:00
ld hl, wBGPals1
ld de, wBGPals2
2015-12-09 15:25:44 -08:00
ld bc, 16 palettes
ld a, BANK(wGBCPalettes)
call FarCopyWRAM
ret
ApplyAttrmap:
ldh a, [rLCDC]
2017-12-29 09:53:21 -08:00
bit rLCDC_ENABLE, a
2015-12-16 18:57:42 -08:00
jr z, .UpdateVBank1
ldh a, [hBGMapMode]
push af
ld a, $2
ldh [hBGMapMode], a
call DelayFrame
call DelayFrame
call DelayFrame
call DelayFrame
pop af
ldh [hBGMapMode], a
ret
.UpdateVBank1:
hlcoord 0, 0, wAttrmap
2015-11-20 08:47:52 -08:00
debgcoord 0, 0
2015-12-16 18:57:42 -08:00
ld b, SCREEN_HEIGHT
ld a, $1
ldh [rVBK], a
2015-12-16 18:57:42 -08:00
.row
ld c, SCREEN_WIDTH
.col
ld a, [hli]
ld [de], a
inc de
dec c
2015-12-16 18:57:42 -08:00
jr nz, .col
ld a, BG_MAP_WIDTH - SCREEN_WIDTH
add e
2015-12-16 18:57:42 -08:00
jr nc, .okay
inc d
2015-12-16 18:57:42 -08:00
.okay
ld e, a
dec b
2015-12-16 18:57:42 -08:00
jr nz, .row
ld a, $0
ldh [rVBK], a
ret
; CGB layout for SCGB_PARTY_MENU_HP_BARS
2018-06-24 07:09:41 -07:00
CGB_ApplyPartyMenuHPPals:
2015-12-22 19:19:33 -08:00
ld hl, wHPPals
ld a, [wSGBPals]
ld e, a
ld d, 0
add hl, de
ld e, l
ld d, h
ld a, [de]
inc a
ld e, a
hlcoord 11, 2, wAttrmap
2015-12-22 19:19:33 -08:00
ld bc, 2 * SCREEN_WIDTH
ld a, [wSGBPals]
2015-12-22 19:19:33 -08:00
.loop
and a
2015-12-22 19:19:33 -08:00
jr z, .done
add hl, bc
dec a
2015-12-22 19:19:33 -08:00
jr .loop
.done
lb bc, 2, 8
ld a, e
2015-11-12 21:49:27 -08:00
call FillBoxCGB
ret
InitPartyMenuOBPals:
2017-12-15 19:36:33 -08:00
ld hl, PartyMenuOBPals
2018-01-01 06:08:21 -08:00
ld de, wOBPals1
2015-12-09 15:25:44 -08:00
ld bc, 2 palettes
ld a, BANK(wOBPals1)
call FarCopyWRAM
ret
GetBattlemonBackpicPalettePointer:
push de
2017-12-24 09:47:30 -08:00
farcall GetPartyMonDVs
ld c, l
ld b, h
2018-01-23 14:39:09 -08:00
ld a, [wTempBattleMonSpecies]
2015-12-16 18:57:42 -08:00
call GetPlayerOrMonPalettePointer
pop de
ret
GetEnemyFrontpicPalettePointer:
push de
2017-12-24 09:47:30 -08:00
farcall GetEnemyMonDVs
ld c, l
ld b, h
2018-01-23 14:39:09 -08:00
ld a, [wTempEnemyMonSpecies]
2015-12-16 18:57:42 -08:00
call GetFrontpicPalettePointer
pop de
ret
GetPlayerOrMonPalettePointer:
and a
2015-12-16 18:57:42 -08:00
jp nz, GetMonNormalOrShinyPalettePointer
2015-10-24 07:34:19 -07:00
ld a, [wPlayerSpriteSetupFlags]
2018-01-22 11:34:55 -08:00
bit PLAYERSPRITESETUP_FEMALE_TO_MALE_F, a
2015-10-24 07:34:19 -07:00
jr nz, .male
ld a, [wPlayerGender]
and a
2015-10-24 07:34:19 -07:00
jr z, .male
ld hl, KrisPalette
ret
2015-10-24 07:34:19 -07:00
.male
2018-02-04 19:45:04 -08:00
ld hl, PlayerPalette
ret
GetFrontpicPalettePointer:
and a
2015-12-16 18:57:42 -08:00
jp nz, GetMonNormalOrShinyPalettePointer
2018-01-23 14:39:09 -08:00
ld a, [wTrainerClass]
GetTrainerPalettePointer:
ld l, a
ld h, 0
add hl, hl
add hl, hl
ld bc, TrainerPalettes
add hl, bc
ret
GetMonPalettePointer:
call _GetMonPalettePointer
ret
2020-10-05 13:15:57 -07:00
CGBCopyBattleObjectPals: ; unreferenced
; dummied out
ret
call CheckCGB
ret z
2017-12-25 09:41:31 -08:00
ld hl, BattleObjectPals
2020-10-05 13:15:57 -07:00
ld a, (1 << rOBPI_AUTO_INCREMENT) | $10
ldh [rOBPI], a
2015-12-16 18:57:42 -08:00
ld c, 6 palettes
.loop
ld a, [hli]
ldh [rOBPD], a
dec c
2015-12-16 18:57:42 -08:00
jr nz, .loop
2017-12-25 09:41:31 -08:00
ld hl, BattleObjectPals
2018-01-01 06:08:21 -08:00
ld de, wOBPals1 palette 2
2015-12-09 15:25:44 -08:00
ld bc, 2 palettes
ld a, BANK(wOBPals1)
call FarCopyWRAM
ret
2017-12-25 09:41:31 -08:00
BattleObjectPals:
INCLUDE "gfx/battle_anims/battle_anims.pal"
2015-12-09 15:25:44 -08:00
2020-10-05 17:10:01 -07:00
CGBCopyTwoPredefObjectPals: ; unreferenced
call CheckCGB
ret z
2020-10-05 13:15:57 -07:00
ld a, (1 << rOBPI_AUTO_INCREMENT) | $10
ldh [rOBPI], a
2018-01-17 21:16:03 -08:00
ld a, PREDEFPAL_TRADE_TUBE
call GetPredefPal
call .PushPalette
ld a, PREDEFPAL_RB_GREENMON
call GetPredefPal
call .PushPalette
ret
.PushPalette:
2015-12-16 18:57:42 -08:00
ld c, 1 palettes
.loop
ld a, [hli]
ldh [rOBPD], a
dec c
jr nz, .loop
ret
_GetMonPalettePointer:
ld l, a
ld h, 0
add hl, hl
add hl, hl
add hl, hl
ld bc, PokemonPalettes
add hl, bc
ret
GetMonNormalOrShinyPalettePointer:
push bc
call _GetMonPalettePointer
pop bc
push hl
call CheckShininess
pop hl
ret nc
2015-07-20 19:18:18 -07:00
rept 4
inc hl
2015-07-20 19:18:18 -07:00
endr
ret
PushSGBPals:
ld a, [wJoypadDisable]
push af
set JOYPAD_DISABLE_SGB_TRANSFER_F, a
ld [wJoypadDisable], a
call _PushSGBPals
pop af
ld [wJoypadDisable], a
ret
_PushSGBPals:
ld a, [hl]
and $7
ret z
ld b, a
.loop
push bc
xor a
ldh [rJOYP], a
ld a, $30
ldh [rJOYP], a
ld b, $10
.loop2
ld e, $8
ld a, [hli]
ld d, a
.loop3
bit 0, d
ld a, $10
jr nz, .okay
ld a, $20
.okay
ldh [rJOYP], a
ld a, $30
ldh [rJOYP], a
rr d
dec e
jr nz, .loop3
dec b
jr nz, .loop2
ld a, $20
ldh [rJOYP], a
ld a, $30
ldh [rJOYP], a
2015-12-22 19:19:33 -08:00
call SGBDelayCycles
pop bc
dec b
jr nz, .loop
ret
InitSGBBorder:
call CheckCGB
ret nz
2016-05-05 12:07:37 -07:00
; SGB/DMG only
di
ld a, [wJoypadDisable]
push af
set JOYPAD_DISABLE_SGB_TRANSFER_F, a
ld [wJoypadDisable], a
xor a
ldh [rJOYP], a
ldh [hSGB], a
call PushSGBBorderPalsAndWait
2016-05-05 12:07:37 -07:00
jr nc, .skip
ld a, $1
ldh [hSGB], a
call _InitSGBBorderPals
call SGBBorder_PushBGPals
2015-12-22 19:19:33 -08:00
call SGBDelayCycles
call SGB_ClearVRAM
call PushSGBBorder
2015-12-22 19:19:33 -08:00
call SGBDelayCycles
call SGB_ClearVRAM
ld hl, MaskEnCancelPacket
call _PushSGBPals
2016-05-05 12:07:37 -07:00
.skip
pop af
ld [wJoypadDisable], a
ei
ret
2016-05-05 12:07:37 -07:00
InitCGBPals::
call CheckCGB
ret z
2016-05-05 12:07:37 -07:00
; CGB only
2018-01-17 22:25:19 -08:00
ld a, BANK(vTiles3)
ldh [rVBK], a
2018-01-17 22:25:19 -08:00
ld hl, vTiles3
2016-01-04 05:43:55 -08:00
ld bc, $200 tiles
xor a
call ByteFill
2018-01-17 22:25:19 -08:00
ld a, BANK(vTiles0)
ldh [rVBK], a
ld a, 1 << rBGPI_AUTO_INCREMENT
ldh [rBGPI], a
2016-01-04 05:43:55 -08:00
ld c, 4 * 8
.bgpals_loop
ld a, LOW(PALRGB_WHITE)
ldh [rBGPD], a
ld a, HIGH(PALRGB_WHITE)
ldh [rBGPD], a
dec c
2016-01-04 05:43:55 -08:00
jr nz, .bgpals_loop
ld a, 1 << rOBPI_AUTO_INCREMENT
ldh [rOBPI], a
2016-01-04 05:43:55 -08:00
ld c, 4 * 8
.obpals_loop
ld a, LOW(PALRGB_WHITE)
ldh [rOBPD], a
ld a, HIGH(PALRGB_WHITE)
ldh [rOBPD], a
dec c
2016-01-04 05:43:55 -08:00
jr nz, .obpals_loop
ldh a, [rSVBK]
push af
ld a, BANK(wBGPals1)
ldh [rSVBK], a
2018-01-01 06:08:21 -08:00
ld hl, wBGPals1
2016-01-04 05:43:55 -08:00
call .LoadWhitePals
2018-01-01 06:08:21 -08:00
ld hl, wBGPals2
2016-01-04 05:43:55 -08:00
call .LoadWhitePals
pop af
ldh [rSVBK], a
ret
.LoadWhitePals:
2016-01-04 05:43:55 -08:00
ld c, 4 * 16
2015-11-20 12:15:32 -08:00
.loop
ld a, LOW(PALRGB_WHITE)
ld [hli], a
ld a, HIGH(PALRGB_WHITE)
ld [hli], a
dec c
2015-11-20 12:15:32 -08:00
jr nz, .loop
ret
_InitSGBBorderPals:
ld hl, .PacketPointerTable
2016-01-04 05:43:55 -08:00
ld c, 9
.loop
push bc
ld a, [hli]
push hl
ld h, [hl]
ld l, a
call _PushSGBPals
pop hl
inc hl
pop bc
dec c
2016-01-04 05:43:55 -08:00
jr nz, .loop
ret
.PacketPointerTable:
dw MaskEnFreezePacket
dw DataSndPacket1
dw DataSndPacket2
dw DataSndPacket3
dw DataSndPacket4
dw DataSndPacket5
dw DataSndPacket6
dw DataSndPacket7
dw DataSndPacket8
2020-10-05 13:15:57 -07:00
UpdateSGBBorder: ; unreferenced
di
xor a
ldh [rJOYP], a
ld hl, MaskEnFreezePacket
call _PushSGBPals
call PushSGBBorder
2015-12-22 19:19:33 -08:00
call SGBDelayCycles
call SGB_ClearVRAM
ld hl, MaskEnCancelPacket
call _PushSGBPals
ei
ret
PushSGBBorder:
2016-01-04 05:43:55 -08:00
call .LoadSGBBorderPointers
push de
call SGBBorder_YetMorePalPushing
pop hl
call SGBBorder_MorePalPushing
ret
.LoadSGBBorderPointers:
ld hl, SGBBorderGFX
ld de, SGBBorderMapAndPalettes
ret
SGB_ClearVRAM:
ld hl, VRAM_Begin
ld bc, VRAM_End - VRAM_Begin
xor a
call ByteFill
ret
PushSGBBorderPalsAndWait:
ld hl, MltReq2Packet
call _PushSGBPals
2015-12-22 19:19:33 -08:00
call SGBDelayCycles
ldh a, [rJOYP]
and $3
cp $3
jr nz, .carry
ld a, $20
ldh [rJOYP], a
ldh a, [rJOYP]
ldh a, [rJOYP]
2015-12-22 19:19:33 -08:00
call SGBDelayCycles
call SGBDelayCycles
ld a, $30
ldh [rJOYP], a
2015-12-22 19:19:33 -08:00
call SGBDelayCycles
call SGBDelayCycles
ld a, $10
ldh [rJOYP], a
2015-07-20 19:18:18 -07:00
rept 6
ldh a, [rJOYP]
2015-07-20 19:18:18 -07:00
endr
2015-12-22 19:19:33 -08:00
call SGBDelayCycles
call SGBDelayCycles
ld a, $30
ldh [rJOYP], a
ldh a, [rJOYP]
ldh a, [rJOYP]
ldh a, [rJOYP]
2015-12-22 19:19:33 -08:00
call SGBDelayCycles
call SGBDelayCycles
ldh a, [rJOYP]
and $3
cp $3
jr nz, .carry
call .FinalPush
and a
ret
.carry
call .FinalPush
scf
ret
.FinalPush:
ld hl, MltReq1Packet
call _PushSGBPals
vc_hook Network_RESET
2015-12-22 19:19:33 -08:00
jp SGBDelayCycles
SGBBorder_PushBGPals:
call DisableLCD
2016-05-05 12:07:37 -07:00
ld a, %11100100
ldh [rBGP], a
2017-12-15 19:36:33 -08:00
ld hl, PredefPals
2017-12-28 04:32:33 -08:00
ld de, vTiles1
ld bc, $100 tiles
call CopyData
call DrawDefaultTiles
2017-12-29 10:22:33 -08:00
ld a, LCDC_DEFAULT
ldh [rLCDC], a
ld hl, PalTrnPacket
call _PushSGBPals
xor a
ldh [rBGP], a
ret
SGBBorder_MorePalPushing:
call DisableLCD
ld a, $e4
ldh [rBGP], a
2017-12-28 04:32:33 -08:00
ld de, vTiles1
ld bc, (6 + SCREEN_WIDTH + 6) * 5 * 2
call CopyData
ld b, SCREEN_HEIGHT
.loop
push bc
ld bc, 6 * 2
call CopyData
ld bc, SCREEN_WIDTH * 2
call ClearBytes
ld bc, 6 * 2
call CopyData
pop bc
dec b
jr nz, .loop
ld bc, (6 + SCREEN_WIDTH + 6) * 5 * 2
call CopyData
2019-03-12 19:55:40 -07:00
ld bc, $100
call ClearBytes
2015-12-09 15:25:44 -08:00
ld bc, 16 palettes
call CopyData
call DrawDefaultTiles
2017-12-29 10:22:33 -08:00
ld a, LCDC_DEFAULT
ldh [rLCDC], a
ld hl, PctTrnPacket
call _PushSGBPals
xor a
ldh [rBGP], a
ret
SGBBorder_YetMorePalPushing:
call DisableLCD
2016-01-04 05:43:55 -08:00
ld a, %11100100
ldh [rBGP], a
2017-12-28 04:32:33 -08:00
ld de, vTiles1
ld b, $80
.loop
push bc
2016-01-04 05:43:55 -08:00
ld bc, 1 tiles
call CopyData
2016-01-04 05:43:55 -08:00
ld bc, 1 tiles
call ClearBytes
pop bc
dec b
jr nz, .loop
call DrawDefaultTiles
2017-12-29 10:22:33 -08:00
ld a, LCDC_DEFAULT
ldh [rLCDC], a
ld hl, ChrTrnPacket
call _PushSGBPals
xor a
ldh [rBGP], a
ret
CopyData:
; copy bc bytes of data from hl to de
2016-05-05 12:07:37 -07:00
.loop
ld a, [hli]
ld [de], a
inc de
dec bc
ld a, c
or b
2016-05-05 12:07:37 -07:00
jr nz, .loop
ret
ClearBytes:
; clear bc bytes of data starting from de
2016-05-05 12:07:37 -07:00
.loop
xor a
ld [de], a
inc de
dec bc
ld a, c
or b
2016-05-05 12:07:37 -07:00
jr nz, .loop
ret
DrawDefaultTiles:
; Draw 240 tiles (2/3 of the screen) from tiles in VRAM
2015-11-20 08:47:52 -08:00
hlbgcoord 0, 0 ; BG Map 0
2016-01-04 05:43:55 -08:00
ld de, BG_MAP_WIDTH - SCREEN_WIDTH
ld a, $80 ; starting tile
ld c, 12 + 1
.line
ld b, 20
.tile
ld [hli], a
inc a
dec b
jr nz, .tile
; next line
add hl, de
dec c
jr nz, .line
ret
SGBDelayCycles:
2015-12-22 19:19:33 -08:00
ld de, 7000
.wait
nop
nop
nop
dec de
ld a, d
or e
2015-12-22 19:19:33 -08:00
jr nz, .wait
ret
INCLUDE "gfx/sgb/blk_packets.asm"
INCLUDE "gfx/sgb/pal_packets.asm"
INCLUDE "data/sgb_ctrl_packets.asm"
2017-12-15 19:36:33 -08:00
PredefPals:
2021-10-24 15:25:44 -07:00
table_width PALETTE_SIZE, PredefPals
INCLUDE "gfx/sgb/predef.pal"
2021-10-24 15:25:44 -07:00
assert_table_length NUM_PREDEF_PALS
2015-12-09 15:25:44 -08:00
SGBBorderMapAndPalettes:
; interleaved tile ids and palette ids, without the center 20x18 screen area
INCBIN "gfx/sgb/sgb_border.sgb.tilemap"
; four SGB palettes of 16 colors each; only the first 4 colors are used
INCLUDE "gfx/sgb/sgb_border.pal"
2015-12-09 15:25:44 -08:00
SGBBorderGFX:
INCBIN "gfx/sgb/sgb_border.2bpp"
2017-12-15 19:36:33 -08:00
HPBarPals:
INCLUDE "gfx/battle/hp_bar.pal"
2017-12-15 19:36:33 -08:00
ExpBarPalette:
INCLUDE "gfx/battle/exp_bar.pal"
INCLUDE "data/pokemon/palettes.asm"
INCLUDE "data/trainers/palettes.asm"
LoadMapPals:
2017-12-24 09:47:30 -08:00
farcall LoadSpecialMapPalette
jr c, .got_pals
; Which palette group is based on whether we're outside or inside
ld a, [wEnvironment]
2014-03-01 22:22:33 -08:00
and 7
ld e, a
2014-03-01 22:22:33 -08:00
ld d, 0
2017-12-25 09:41:31 -08:00
ld hl, EnvironmentColorsPointers
add hl, de
2015-12-26 18:59:03 -08:00
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
; Futher refine by time of day
2018-01-23 14:39:09 -08:00
ld a, [wTimeOfDayPal]
2018-01-16 14:27:50 -08:00
maskbits NUM_DAYTIMES
add a
add a
add a
ld e, a
2014-03-01 22:22:33 -08:00
ld d, 0
add hl, de
ld e, l
ld d, h
ldh a, [rSVBK]
push af
ld a, BANK(wBGPals1)
ldh [rSVBK], a
2018-01-01 06:08:21 -08:00
ld hl, wBGPals1
ld b, 8
.outer_loop
ld a, [de] ; lookup index for TilesetBGPalette
push de
push hl
ld l, a
2014-03-01 22:22:33 -08:00
ld h, 0
add hl, hl
add hl, hl
add hl, hl
ld de, TilesetBGPalette
add hl, de
ld e, l
ld d, h
pop hl
ld c, 1 palettes
.inner_loop
ld a, [de]
inc de
ld [hli], a
dec c
jr nz, .inner_loop
pop de
inc de
dec b
jr nz, .outer_loop
pop af
ldh [rSVBK], a
.got_pals
2018-01-23 14:39:09 -08:00
ld a, [wTimeOfDayPal]
2018-01-16 14:27:50 -08:00
maskbits NUM_DAYTIMES
ld bc, 8 palettes
ld hl, MapObjectPals
call AddNTimes
2018-01-01 06:08:21 -08:00
ld de, wOBPals1
ld bc, 8 palettes
2018-01-01 06:08:21 -08:00
ld a, BANK(wOBPals1)
call FarCopyWRAM
ld a, [wEnvironment]
cp TOWN
jr z, .outside
cp ROUTE
ret nz
.outside
2018-01-23 14:39:09 -08:00
ld a, [wMapGroup]
ld l, a
ld h, 0
add hl, hl
add hl, hl
add hl, hl
ld de, RoofPals
add hl, de
2018-01-23 14:39:09 -08:00
ld a, [wTimeOfDayPal]
2018-01-16 14:27:50 -08:00
maskbits NUM_DAYTIMES
cp NITE_F
jr c, .morn_day
2015-07-20 19:18:18 -07:00
rept 4
inc hl
2015-07-20 19:18:18 -07:00
endr
.morn_day
2018-01-22 16:40:17 -08:00
ld de, wBGPals1 palette PAL_BG_ROOF color 1
ld bc, 4
ld a, BANK(wBGPals1)
call FarCopyWRAM
ret
2017-12-25 09:41:31 -08:00
INCLUDE "data/maps/environment_colors.asm"
2014-03-01 22:22:33 -08:00
2018-01-18 08:37:05 -08:00
PartyMenuBGMobilePalette:
INCLUDE "gfx/stats/party_menu_bg_mobile.pal"
2015-12-09 15:25:44 -08:00
2018-01-18 08:37:05 -08:00
PartyMenuBGPalette:
INCLUDE "gfx/stats/party_menu_bg.pal"
2015-12-09 15:25:44 -08:00
TilesetBGPalette:
INCLUDE "gfx/tilesets/bg_tiles.pal"
MapObjectPals::
INCLUDE "gfx/overworld/npc_sprites.pal"
RoofPals:
table_width PAL_COLOR_SIZE * 2 * 2, RoofPals
INCLUDE "gfx/tilesets/roofs.pal"
assert_table_length NUM_MAP_GROUPS + 1
2016-06-06 15:23:00 -07:00
DiplomaPalettes:
INCLUDE "gfx/diploma/diploma.pal"
2017-12-15 19:36:33 -08:00
PartyMenuOBPals:
2018-01-18 08:37:05 -08:00
INCLUDE "gfx/stats/party_menu_ob.pal"
UnusedBattleObjectPals: ; unreferenced
INCLUDE "gfx/battle_anims/unused_battle_anims.pal"
2018-01-17 21:16:03 -08:00
UnusedGSTitleBGPals:
INCLUDE "gfx/title/unused_gs_bg.pal"
2018-01-17 21:16:03 -08:00
UnusedGSTitleOBPals:
INCLUDE "gfx/title/unused_gs_fg.pal"
2015-12-09 15:25:44 -08:00
MalePokegearPals:
INCLUDE "gfx/pokegear/pokegear.pal"
2015-12-09 15:25:44 -08:00
FemalePokegearPals:
INCLUDE "gfx/pokegear/pokegear_f.pal"
2015-12-09 15:25:44 -08:00
BetaPokerPals:
INCLUDE "gfx/beta_poker/beta_poker.pal"
2015-12-09 15:25:44 -08:00
2017-12-10 17:50:08 -08:00
SlotMachinePals:
INCLUDE "gfx/slots/slots.pal"