pokered/engine/gfx/palettes.asm

642 lines
11 KiB
NASM
Raw Normal View History

2016-06-12 00:24:04 +00:00
_RunPaletteCommand:
call GetPredefRegisters
2014-05-22 22:13:20 +00:00
ld a, b
cp SET_PAL_DEFAULT
jr nz, .not_default
ld a, [wDefaultPaletteCommand]
.not_default
cp SET_PAL_PARTY_MENU_HP_BARS
2015-08-12 09:16:56 +00:00
jp z, UpdatePartyMenuBlkPacket
2014-05-22 22:13:20 +00:00
ld l, a
2015-08-12 09:16:56 +00:00
ld h, 0
2014-05-22 22:13:20 +00:00
add hl, hl
2015-08-12 09:16:56 +00:00
ld de, SetPalFunctions
2014-05-22 22:13:20 +00:00
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
2015-08-12 09:16:56 +00:00
ld de, SendSGBPackets
2014-05-22 22:13:20 +00:00
push de
jp hl
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
SetPal_BattleBlack:
2014-05-22 22:13:20 +00:00
ld hl, PalPacket_Black
ld de, BlkPacket_Battle
ret
; uses PalPacket_Empty to build a packet based on mon IDs and health color
2016-06-12 00:24:04 +00:00
SetPal_Battle:
2014-05-22 22:13:20 +00:00
ld hl, PalPacket_Empty
2015-08-12 09:16:56 +00:00
ld de, wPalPacket
2014-05-22 22:13:20 +00:00
ld bc, $10
call CopyData
2015-08-31 02:38:41 +00:00
ld a, [wPlayerBattleStatus3]
ld hl, wBattleMonSpecies
2014-05-22 22:13:20 +00:00
call DeterminePaletteID
ld b, a
2015-08-31 02:38:41 +00:00
ld a, [wEnemyBattleStatus3]
ld hl, wEnemyMonSpecies2
2014-05-22 22:13:20 +00:00
call DeterminePaletteID
ld c, a
2015-08-12 09:16:56 +00:00
ld hl, wPalPacket + 1
ld a, [wPlayerHPBarColor]
2014-05-22 22:13:20 +00:00
add PAL_GREENBAR
ld [hli], a
inc hl
2015-08-12 09:16:56 +00:00
ld a, [wEnemyHPBarColor]
2014-05-22 22:13:20 +00:00
add PAL_GREENBAR
ld [hli], a
inc hl
ld a, b
ld [hli], a
inc hl
ld a, c
ld [hl], a
2015-08-12 09:16:56 +00:00
ld hl, wPalPacket
2014-05-22 22:13:20 +00:00
ld de, BlkPacket_Battle
2015-08-12 09:16:56 +00:00
ld a, SET_PAL_BATTLE
ld [wDefaultPaletteCommand], a
2014-05-22 22:13:20 +00:00
ret
2016-06-12 00:24:04 +00:00
SetPal_TownMap:
2014-05-22 22:13:20 +00:00
ld hl, PalPacket_TownMap
ld de, BlkPacket_WholeScreen
ret
; uses PalPacket_Empty to build a packet based the mon ID
2016-06-12 00:24:04 +00:00
SetPal_StatusScreen:
2014-05-22 22:13:20 +00:00
ld hl, PalPacket_Empty
2015-08-12 09:16:56 +00:00
ld de, wPalPacket
2014-05-22 22:13:20 +00:00
ld bc, $10
call CopyData
ld a, [wcf91]
cp NUM_POKEMON_INDEXES + 1
2014-05-22 22:13:20 +00:00
jr c, .pokemon
ld a, $1 ; not pokemon
.pokemon
call DeterminePaletteIDOutOfBattle
push af
2015-08-12 09:16:56 +00:00
ld hl, wPalPacket + 1
ld a, [wStatusScreenHPBarColor]
2015-06-12 16:42:57 +00:00
add PAL_GREENBAR
2014-05-22 22:13:20 +00:00
ld [hli], a
inc hl
pop af
ld [hl], a
2015-08-12 09:16:56 +00:00
ld hl, wPalPacket
2014-05-22 22:13:20 +00:00
ld de, BlkPacket_StatusScreen
ret
2016-06-12 00:24:04 +00:00
SetPal_PartyMenu:
2014-05-22 22:13:20 +00:00
ld hl, PalPacket_PartyMenu
2015-08-12 09:16:56 +00:00
ld de, wPartyMenuBlkPacket
2014-05-22 22:13:20 +00:00
ret
2016-06-12 00:24:04 +00:00
SetPal_Pokedex:
2014-05-22 22:13:20 +00:00
ld hl, PalPacket_Pokedex
2015-08-12 09:16:56 +00:00
ld de, wPalPacket
2014-05-22 22:13:20 +00:00
ld bc, $10
call CopyData
ld a, [wcf91]
2014-05-22 22:13:20 +00:00
call DeterminePaletteIDOutOfBattle
2015-08-12 09:16:56 +00:00
ld hl, wPalPacket + 3
2014-05-22 22:13:20 +00:00
ld [hl], a
2015-08-12 09:16:56 +00:00
ld hl, wPalPacket
2014-05-22 22:13:20 +00:00
ld de, BlkPacket_Pokedex
ret
2016-06-12 00:24:04 +00:00
SetPal_Slots:
2014-05-22 22:13:20 +00:00
ld hl, PalPacket_Slots
ld de, BlkPacket_Slots
ret
2016-06-12 00:24:04 +00:00
SetPal_TitleScreen:
2014-05-22 22:13:20 +00:00
ld hl, PalPacket_Titlescreen
ld de, BlkPacket_Titlescreen
ret
; used mostly for menus and the Oak intro
2016-06-12 00:24:04 +00:00
SetPal_Generic:
2014-05-22 22:13:20 +00:00
ld hl, PalPacket_Generic
ld de, BlkPacket_WholeScreen
ret
2016-06-12 00:24:04 +00:00
SetPal_NidorinoIntro:
2014-05-22 22:13:20 +00:00
ld hl, PalPacket_NidorinoIntro
ld de, BlkPacket_NidorinoIntro
ret
2016-06-12 00:24:04 +00:00
SetPal_GameFreakIntro:
2014-05-22 22:13:20 +00:00
ld hl, PalPacket_GameFreakIntro
ld de, BlkPacket_GameFreakIntro
2015-08-12 09:16:56 +00:00
ld a, SET_PAL_GENERIC
ld [wDefaultPaletteCommand], a
2014-05-22 22:13:20 +00:00
ret
; uses PalPacket_Empty to build a packet based on the current map
2016-06-12 00:24:04 +00:00
SetPal_Overworld:
2014-05-22 22:13:20 +00:00
ld hl, PalPacket_Empty
2015-08-12 09:16:56 +00:00
ld de, wPalPacket
2014-05-22 22:13:20 +00:00
ld bc, $10
call CopyData
2015-08-31 02:38:41 +00:00
ld a, [wCurMapTileset]
2014-05-22 22:13:20 +00:00
cp CEMETERY
jr z, .PokemonTowerOrAgatha
cp CAVERN
jr z, .caveOrBruno
2015-08-31 02:38:41 +00:00
ld a, [wCurMap]
cp FIRST_INDOOR_MAP
2014-05-22 22:13:20 +00:00
jr c, .townOrRoute
cp CERULEAN_CAVE_2F
2014-05-22 22:13:20 +00:00
jr c, .normalDungeonOrBuilding
cp CERULEAN_CAVE_1F + 1
2014-05-22 22:13:20 +00:00
jr c, .caveOrBruno
cp LORELEIS_ROOM
jr z, .Lorelei
cp BRUNOS_ROOM
jr z, .caveOrBruno
.normalDungeonOrBuilding
ld a, [wLastMap] ; town or route that current dungeon or building is located
.townOrRoute
cp NUM_CITY_MAPS
2014-05-22 22:13:20 +00:00
jr c, .town
ld a, PAL_ROUTE - 1
.town
2015-08-12 09:16:56 +00:00
inc a ; a town's palette ID is its map ID + 1
ld hl, wPalPacket + 1
2014-05-22 22:13:20 +00:00
ld [hld], a
ld de, BlkPacket_WholeScreen
2015-08-12 09:16:56 +00:00
ld a, SET_PAL_OVERWORLD
ld [wDefaultPaletteCommand], a
2014-05-22 22:13:20 +00:00
ret
.PokemonTowerOrAgatha
ld a, PAL_GREYMON - 1
jr .town
.caveOrBruno
ld a, PAL_CAVE - 1
jr .town
.Lorelei
xor a
jr .town
; used when a Pokemon is the only thing on the screen
; such as evolution, trading and the Hall of Fame
2016-06-12 00:24:04 +00:00
SetPal_PokemonWholeScreen:
2014-05-22 22:13:20 +00:00
push bc
ld hl, PalPacket_Empty
2015-08-12 09:16:56 +00:00
ld de, wPalPacket
2014-05-22 22:13:20 +00:00
ld bc, $10
call CopyData
pop bc
ld a, c
and a
2015-08-12 09:16:56 +00:00
ld a, PAL_BLACK
jr nz, .next
ld a, [wWholeScreenPaletteMonSpecies]
2014-05-22 22:13:20 +00:00
call DeterminePaletteIDOutOfBattle
2015-08-12 09:16:56 +00:00
.next
ld [wPalPacket + 1], a
ld hl, wPalPacket
2014-05-22 22:13:20 +00:00
ld de, BlkPacket_WholeScreen
ret
2016-06-12 00:24:04 +00:00
SetPal_TrainerCard:
2014-05-22 22:13:20 +00:00
ld hl, BlkPacket_TrainerCard
2015-08-12 09:16:56 +00:00
ld de, wTrainerCardBlkPacket
2014-05-22 22:13:20 +00:00
ld bc, $40
call CopyData
2015-08-12 09:16:56 +00:00
ld de, BadgeBlkDataLengths
ld hl, wTrainerCardBlkPacket + 2
2015-08-31 02:38:41 +00:00
ld a, [wObtainedBadges]
ld c, NUM_BADGES
2015-08-12 09:16:56 +00:00
.badgeLoop
2014-05-22 22:13:20 +00:00
srl a
push af
2015-08-12 09:16:56 +00:00
jr c, .haveBadge
; The player doens't have the badge, so zero the badge's blk data.
2014-05-22 22:13:20 +00:00
push bc
ld a, [de]
ld c, a
xor a
2015-08-12 09:16:56 +00:00
.zeroBadgeDataLoop
2014-05-22 22:13:20 +00:00
ld [hli], a
dec c
2015-08-12 09:16:56 +00:00
jr nz, .zeroBadgeDataLoop
2014-05-22 22:13:20 +00:00
pop bc
2015-08-12 09:16:56 +00:00
jr .nextBadge
.haveBadge
; The player does have the badge, so skip past the badge's blk data.
2014-05-22 22:13:20 +00:00
ld a, [de]
2015-08-12 09:16:56 +00:00
.skipBadgeDataLoop
2014-05-22 22:13:20 +00:00
inc hl
dec a
2015-08-12 09:16:56 +00:00
jr nz, .skipBadgeDataLoop
.nextBadge
2014-05-22 22:13:20 +00:00
pop af
inc de
dec c
2015-08-12 09:16:56 +00:00
jr nz, .badgeLoop
2014-05-22 22:13:20 +00:00
ld hl, PalPacket_TrainerCard
2015-08-12 09:16:56 +00:00
ld de, wTrainerCardBlkPacket
2014-05-22 22:13:20 +00:00
ret
2016-06-12 00:24:04 +00:00
SetPalFunctions:
; entries correspond to SET_PAL_* constants
2015-08-12 09:16:56 +00:00
dw SetPal_BattleBlack
dw SetPal_Battle
dw SetPal_TownMap
dw SetPal_StatusScreen
dw SetPal_Pokedex
dw SetPal_Slots
dw SetPal_TitleScreen
dw SetPal_NidorinoIntro
dw SetPal_Generic
dw SetPal_Overworld
dw SetPal_PartyMenu
dw SetPal_PokemonWholeScreen
dw SetPal_GameFreakIntro
dw SetPal_TrainerCard
; The length of the blk data of each badge on the Trainer Card.
; The Rainbow Badge has 3 entries because of its many colors.
2016-06-12 00:24:04 +00:00
BadgeBlkDataLengths:
2015-08-12 09:16:56 +00:00
db 6 ; Boulder Badge
db 6 ; Cascade Badge
db 6 ; Thunder Badge
db 6 * 3 ; Rainbow Badge
db 6 ; Soul Badge
db 6 ; Marsh Badge
db 6 ; Volcano Badge
db 6 ; Earth Badge
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
DeterminePaletteID:
2017-12-29 23:59:48 +00:00
bit TRANSFORMED, a ; a is battle status 3
2015-08-12 09:16:56 +00:00
ld a, PAL_GREYMON ; if the mon has used Transform, use Ditto's palette
2014-05-22 22:13:20 +00:00
ret nz
ld a, [hl]
2016-06-12 00:24:04 +00:00
DeterminePaletteIDOutOfBattle:
ld [wd11e], a
2015-08-12 09:16:56 +00:00
and a ; is the mon index 0?
jr z, .skipDexNumConversion
2014-05-22 22:13:20 +00:00
push bc
2015-08-12 09:16:56 +00:00
predef IndexToPokedex
2014-05-22 22:13:20 +00:00
pop bc
ld a, [wd11e]
2015-08-12 09:16:56 +00:00
.skipDexNumConversion
2014-05-22 22:13:20 +00:00
ld e, a
2015-08-12 09:16:56 +00:00
ld d, 0
ld hl, MonsterPalettes ; not just for Pokemon, Trainers use it too
2014-05-22 22:13:20 +00:00
add hl, de
ld a, [hl]
ret
2016-06-12 00:24:04 +00:00
InitPartyMenuBlkPacket:
ld hl, BlkPacket_PartyMenu
2015-08-12 09:16:56 +00:00
ld de, wPartyMenuBlkPacket
2014-05-22 22:13:20 +00:00
ld bc, $30
jp CopyData
2016-06-12 00:24:04 +00:00
UpdatePartyMenuBlkPacket:
2015-08-12 09:16:56 +00:00
; Update the blk packet with the palette of the HP bar that is
; specified in [wWhichPartyMenuHPBar].
ld hl, wPartyMenuHPBarColors
ld a, [wWhichPartyMenuHPBar]
2014-05-22 22:13:20 +00:00
ld e, a
2015-08-12 09:16:56 +00:00
ld d, 0
2014-05-22 22:13:20 +00:00
add hl, de
ld e, l
ld d, h
ld a, [de]
and a
2015-08-12 09:16:56 +00:00
ld e, (1 << 2) | 1 ; green
jr z, .next
2014-05-22 22:13:20 +00:00
dec a
2015-08-12 09:16:56 +00:00
ld e, (2 << 2) | 2 ; yellow
jr z, .next
ld e, (3 << 2) | 3 ; red
.next
2014-05-22 22:13:20 +00:00
push de
2015-08-12 09:16:56 +00:00
ld hl, wPartyMenuBlkPacket + 8 + 1
ld bc, 6
ld a, [wWhichPartyMenuHPBar]
2014-05-22 22:13:20 +00:00
call AddNTimes
pop de
ld [hl], e
ret
2016-06-12 00:24:04 +00:00
SendSGBPacket:
2014-05-22 22:13:20 +00:00
;check number of packets
ld a, [hl]
and $07
2014-05-22 22:13:20 +00:00
ret z
; store number of packets in B
ld b, a
2014-05-22 22:13:20 +00:00
.loop2
; save B for later use
push bc
2015-08-12 09:16:56 +00:00
; disable ReadJoypad to prevent it from interfering with sending the packet
ld a, 1
ldh [hDisableJoypadPolling], a
2014-05-22 22:13:20 +00:00
; send RESET signal (P14=LOW, P15=LOW)
xor a
ldh [rJOYP], a
2014-05-22 22:13:20 +00:00
; set P14=HIGH, P15=HIGH
ld a, $30
ldh [rJOYP], a
2014-05-22 22:13:20 +00:00
;load length of packets (16 bytes)
ld b, $10
2014-05-22 22:13:20 +00:00
.nextByte
;set bit counter (8 bits per byte)
ld e, $08
2014-05-22 22:13:20 +00:00
; get next byte in the packet
ld a, [hli]
ld d, a
2014-05-22 22:13:20 +00:00
.nextBit0
bit 0, d
2020-11-05 21:55:39 +00:00
; if 0th bit is not zero set P14=HIGH, P15=LOW (send bit 1)
ld a, $10
jr nz, .next0
2020-11-05 21:55:39 +00:00
; else (if 0th bit is zero) set P14=LOW, P15=HIGH (send bit 0)
ld a, $20
2014-05-22 22:13:20 +00:00
.next0
ldh [rJOYP], a
2014-05-22 22:13:20 +00:00
; must set P14=HIGH,P15=HIGH between each "pulse"
ld a, $30
ldh [rJOYP], a
2014-05-22 22:13:20 +00:00
; rotation will put next bit in 0th position (so we can always use command
2020-11-05 21:55:39 +00:00
; "bit 0, d" to fetch the bit that has to be sent)
2014-05-22 22:13:20 +00:00
rr d
; decrease bit counter so we know when we have sent all 8 bits of current byte
dec e
jr nz, .nextBit0
2014-05-22 22:13:20 +00:00
dec b
jr nz, .nextByte
2014-05-22 22:13:20 +00:00
; send bit 1 as a "stop bit" (end of parameter data)
ld a, $20
ldh [rJOYP], a
2014-05-22 22:13:20 +00:00
; set P14=HIGH,P15=HIGH
ld a, $30
ldh [rJOYP], a
2014-05-22 22:13:20 +00:00
xor a
ldh [hDisableJoypadPolling], a
2014-05-22 22:13:20 +00:00
; wait for about 70000 cycles
call Wait7000
; restore (previously pushed) number of packets
pop bc
dec b
; return if there are no more packets
ret z
; else send 16 more bytes
jr .loop2
2016-06-12 00:24:04 +00:00
LoadSGB:
2014-05-22 22:13:20 +00:00
xor a
2014-09-13 07:50:56 +00:00
ld [wOnSGB], a
2015-01-23 17:48:14 +00:00
call CheckSGB
2014-05-22 22:13:20 +00:00
ret nc
2015-08-12 09:16:56 +00:00
ld a, 1
2014-09-13 07:50:56 +00:00
ld [wOnSGB], a
ld a, [wGBC]
2014-05-22 22:13:20 +00:00
and a
2015-08-12 09:16:56 +00:00
jr z, .notGBC
2014-05-22 22:13:20 +00:00
ret
2015-08-12 09:16:56 +00:00
.notGBC
2014-05-22 22:13:20 +00:00
di
2015-08-12 09:16:56 +00:00
call PrepareSuperNintendoVRAMTransfer
2014-05-22 22:13:20 +00:00
ei
2015-08-12 09:16:56 +00:00
ld a, 1
ld [wCopyingSGBTileData], a
2014-06-07 05:08:06 +00:00
ld de, ChrTrnPacket
2014-05-22 22:13:20 +00:00
ld hl, SGBBorderGraphics
2015-08-12 09:16:56 +00:00
call CopyGfxToSuperNintendoVRAM
2014-05-22 22:13:20 +00:00
xor a
2015-08-12 09:16:56 +00:00
ld [wCopyingSGBTileData], a
2014-06-07 05:08:06 +00:00
ld de, PctTrnPacket
2014-05-22 22:13:20 +00:00
ld hl, BorderPalettes
2015-08-12 09:16:56 +00:00
call CopyGfxToSuperNintendoVRAM
2014-05-22 22:13:20 +00:00
xor a
2015-08-12 09:16:56 +00:00
ld [wCopyingSGBTileData], a
2014-06-07 05:08:06 +00:00
ld de, PalTrnPacket
2014-05-22 22:13:20 +00:00
ld hl, SuperPalettes
2015-08-12 09:16:56 +00:00
call CopyGfxToSuperNintendoVRAM
2014-05-23 22:34:35 +00:00
call ClearVram
2014-06-07 05:08:06 +00:00
ld hl, MaskEnCancelPacket
2014-05-22 22:13:20 +00:00
jp SendSGBPacket
2016-06-12 00:24:04 +00:00
PrepareSuperNintendoVRAMTransfer:
2015-08-12 09:16:56 +00:00
ld hl, .packetPointers
ld c, 9
.loop
2014-05-22 22:13:20 +00:00
push bc
ld a, [hli]
push hl
ld h, [hl]
ld l, a
call SendSGBPacket
pop hl
inc hl
pop bc
dec c
2015-08-12 09:16:56 +00:00
jr nz, .loop
2014-05-22 22:13:20 +00:00
ret
2015-08-12 09:16:56 +00:00
.packetPointers
; Only the first packet is needed.
2014-06-07 05:08:06 +00:00
dw MaskEnFreezePacket
2022-07-11 01:11:03 +00:00
dw DataSndPacket1
dw DataSndPacket2
dw DataSndPacket3
dw DataSndPacket4
dw DataSndPacket5
dw DataSndPacket6
dw DataSndPacket7
dw DataSndPacket8
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
CheckSGB:
2015-08-12 09:16:56 +00:00
; Returns whether the game is running on an SGB in carry.
2014-06-07 05:08:06 +00:00
ld hl, MltReq2Packet
2014-05-22 22:13:20 +00:00
di
call SendSGBPacket
2015-08-12 09:16:56 +00:00
ld a, 1
ldh [hDisableJoypadPolling], a
2014-05-22 22:13:20 +00:00
ei
call Wait7000
ldh a, [rJOYP]
2014-05-22 22:13:20 +00:00
and $3
cp $3
2015-08-12 09:16:56 +00:00
jr nz, .isSGB
2014-05-22 22:13:20 +00:00
ld a, $20
ldh [rJOYP], a
ldh a, [rJOYP]
ldh a, [rJOYP]
2014-05-22 22:13:20 +00:00
call Wait7000
call Wait7000
ld a, $30
ldh [rJOYP], a
2014-05-22 22:13:20 +00:00
call Wait7000
call Wait7000
ld a, $10
ldh [rJOYP], a
ldh a, [rJOYP]
ldh a, [rJOYP]
ldh a, [rJOYP]
ldh a, [rJOYP]
ldh a, [rJOYP]
ldh a, [rJOYP]
2014-05-22 22:13:20 +00:00
call Wait7000
vc_hook Unknown_network_reset
2014-05-22 22:13:20 +00:00
call Wait7000
ld a, $30
ldh [rJOYP], a
ldh a, [rJOYP]
ldh a, [rJOYP]
ldh a, [rJOYP]
2014-05-22 22:13:20 +00:00
call Wait7000
call Wait7000
ldh a, [rJOYP]
2014-05-22 22:13:20 +00:00
and $3
cp $3
2015-08-12 09:16:56 +00:00
jr nz, .isSGB
call SendMltReq1Packet
2014-05-22 22:13:20 +00:00
and a
ret
2015-08-12 09:16:56 +00:00
.isSGB
call SendMltReq1Packet
2014-05-22 22:13:20 +00:00
scf
ret
2016-06-12 00:24:04 +00:00
SendMltReq1Packet:
2014-06-07 05:08:06 +00:00
ld hl, MltReq1Packet
2014-05-22 22:13:20 +00:00
call SendSGBPacket
jp Wait7000
2016-06-12 00:24:04 +00:00
CopyGfxToSuperNintendoVRAM:
2014-05-22 22:13:20 +00:00
di
push de
call DisableLCD
ld a, $e4
ldh [rBGP], a
2014-05-29 08:31:46 +00:00
ld de, vChars1
2015-08-12 09:16:56 +00:00
ld a, [wCopyingSGBTileData]
2014-05-22 22:13:20 +00:00
and a
2015-08-12 09:16:56 +00:00
jr z, .notCopyingTileData
call CopySGBBorderTiles
jr .next
.notCopyingTileData
2014-05-22 22:13:20 +00:00
ld bc, $1000
call CopyData
2015-08-12 09:16:56 +00:00
.next
2014-05-29 08:31:46 +00:00
ld hl, vBGMap0
2014-05-22 22:13:20 +00:00
ld de, $c
ld a, $80
ld c, $d
2015-08-12 09:16:56 +00:00
.loop
2014-05-22 22:13:20 +00:00
ld b, $14
2015-08-12 09:16:56 +00:00
.innerLoop
2014-05-22 22:13:20 +00:00
ld [hli], a
inc a
dec b
2015-08-12 09:16:56 +00:00
jr nz, .innerLoop
2014-05-22 22:13:20 +00:00
add hl, de
dec c
2015-08-12 09:16:56 +00:00
jr nz, .loop
2014-05-22 22:13:20 +00:00
ld a, $e3
ldh [rLCDC], a
2014-05-22 22:13:20 +00:00
pop hl
call SendSGBPacket
xor a
ldh [rBGP], a
2014-05-22 22:13:20 +00:00
ei
ret
2016-06-12 00:24:04 +00:00
Wait7000:
2015-01-23 17:48:14 +00:00
; Each loop takes 9 cycles so this routine actually waits 63000 cycles.
2014-05-22 22:13:20 +00:00
ld de, 7000
.loop
nop
nop
nop
dec de
ld a, d
or e
jr nz, .loop
ret
2016-06-12 00:24:04 +00:00
SendSGBPackets:
ld a, [wGBC]
2014-05-22 22:13:20 +00:00
and a
2015-08-12 09:16:56 +00:00
jr z, .notGBC
2014-05-22 22:13:20 +00:00
push de
2015-08-12 09:16:56 +00:00
call InitGBCPalettes
2014-05-22 22:13:20 +00:00
pop hl
2020-07-15 17:35:39 +00:00
call EmptyFunc3
2014-05-22 22:13:20 +00:00
ret
2015-08-12 09:16:56 +00:00
.notGBC
2014-05-22 22:13:20 +00:00
push de
call SendSGBPacket
pop hl
jp SendSGBPacket
2016-06-12 00:24:04 +00:00
InitGBCPalettes:
2015-08-12 09:16:56 +00:00
ld a, $80 ; index 0 with auto-increment
ldh [rBGPI], a
2014-05-22 22:13:20 +00:00
inc hl
ld c, $20
2015-08-12 09:16:56 +00:00
.loop
2014-05-22 22:13:20 +00:00
ld a, [hli]
inc hl
add a
add a
add a
ld de, SuperPalettes
add e
2015-08-12 09:16:56 +00:00
jr nc, .noCarry
2014-05-22 22:13:20 +00:00
inc d
2015-08-12 09:16:56 +00:00
.noCarry
2014-05-22 22:13:20 +00:00
ld a, [de]
ldh [rBGPD], a
2014-05-22 22:13:20 +00:00
dec c
2015-08-12 09:16:56 +00:00
jr nz, .loop
2014-05-22 22:13:20 +00:00
ret
2020-07-15 17:35:39 +00:00
EmptyFunc3:
2014-05-22 22:13:20 +00:00
ret
2016-06-12 00:24:04 +00:00
CopySGBBorderTiles:
2015-08-12 09:16:56 +00:00
; SGB tile data is stored in a 4BPP planar format.
; Each tile is 32 bytes. The first 16 bytes contain bit planes 1 and 2, while
; the second 16 bytes contain bit planes 3 and 4.
; This function converts 2BPP planar data into this format by mapping
; 2BPP colors 0-3 to 4BPP colors 0-3. 4BPP colors 4-15 are not used.
ld b, 128
.tileLoop
; Copy bit planes 1 and 2 of the tile data.
ld c, 16
.copyLoop
2014-05-22 22:13:20 +00:00
ld a, [hli]
ld [de], a
inc de
dec c
2015-08-12 09:16:56 +00:00
jr nz, .copyLoop
; Zero bit planes 3 and 4.
ld c, 16
2014-05-22 22:13:20 +00:00
xor a
2015-08-12 09:16:56 +00:00
.zeroLoop
2014-05-22 22:13:20 +00:00
ld [de], a
inc de
dec c
2015-08-12 09:16:56 +00:00
jr nz, .zeroLoop
2014-05-22 22:13:20 +00:00
dec b
2015-08-12 09:16:56 +00:00
jr nz, .tileLoop
2014-05-22 22:13:20 +00:00
ret
INCLUDE "data/sgb/sgb_packets.asm"
2014-05-22 22:13:20 +00:00
INCLUDE "data/pokemon/palettes.asm"
2014-05-22 22:13:20 +00:00
INCLUDE "data/sgb/sgb_palettes.asm"
2014-05-22 22:13:20 +00:00
INCLUDE "data/sgb/sgb_border.asm"