Skeetendo

’Cause all games were better on the GBC

You are not logged in.

#1 2016-12-24 05:20:41

Kuroko Aizawa
Member
Registered: 2011-12-01
Post 388/499

Pokemon Orange

Intro:
Pokémon Orange is a Crystal hack by Pia Carrot/Kuroko Aizawa. The aim of this hack is not only to create a great Orange Islands hack, but also to give me experience to work on Ancient Platinum and raise it to an even higher standard.

I started hacking 8 years ago after playing Pokémon Naranja on a cartridge, and since then I've always wanted to see a good Orange Islands hack completed. However, it's never happened to this extent, so I've decided to take matters into my own hands.

Story:
You are a kid from Valencia Island who wants to become a Pokémon Master, after hearing about a kid the same age named Red defeating the Indigo League 6 months ago. You set out on a journey to deliver the mysterious GS Ball to the esteemed Samson Oak, who is visiting the Orange Islands from the Alola region and to take on the Orange Crew! Play as Indigo or Orange, explore, fight goofy villains and walk into a fresh and nostalgic world to learn more about the wonderful world of Pokémon and to Catch 'em All!

Features:
The entire Orange Archipelago!
OI and Alolan Variants
Pinkan Berries that work!
Anime-based story in Gamefreak format
20th Movie inspired Ho-oh/Marshadow event
Dive and Rock Climb
Clock Reset NPC for flashcarts
Shiny Charm and Exp. All
...And much, much more!

Screenshots and Credits: https://www.pokecommunity.com/showthread.php?t=387653

Download: https://github.com/PiaCarrot/pokeorange … er/patches
Latest Download is HotY Nominee Edition.

Last edited by Kuroko Aizawa (2018-01-23 18:28:35)

Offline

#2 2016-12-24 06:00:08

Rangi
Member
Registered: 2016-05-09
Post 408/870

Re: Pokemon Orange

Sounds like a fun hack! A custom regional dex, plus variant forms, will be a refreshing change.

Can't help with the details right now, but the routine to edit is engine/color.asm:GetBattlemonBackpicPalettePointer.

The palm trees in your Pokécommunity thread have too little foliage. IMO a 2x4 tile tree isn't enough space. Here's a 4x4 devamped HG/SS one:

osj0r22.png

Edit: now using your custom grass.

JjR3Hq6.png

(The new Headbutt trees should probably also look less like scaled-down palm trees and more like shrubs.)

(Also, I like your new water color. Definitely looks more like the water on a tropical beach.)

Edit: And a Prof. Ivy sprite if you don't have one already:

lnQzqWO.png

Random details that it would be neat to change for the heck of it, to emphasize that this isn't a GSC Johto hack:

• The shape of the Pack image (imitate the RSE ones?)
• Text box frames (how about one that looks like tree wood?)
• The battle interface
• Any tile that looks different in Johto versus Kanto, can have a third look in the Orange Islands (bricks, grass, roofs, windows, trees, buoys, rocks, signs, etc)
• A round-cornered Pokédex? (I know, it's trivial, I just think of the Orange Islands as more relaxed/casual than elsewhere, and rounded stuff fits that...)

What's your plan for the Gym progression? Only four, with more sidequests in-between to help level up? Or an Alola-like system with a few "sub-bosses" before each boss/Kahuna/Leader?

Last edited by Rangi (2016-12-24 06:29:50)


Pokémon Polished Crystal (GitHub) — version 2.2.0 released
Pokémon Red★ and Blue★: Space World Edition (GitHub) — updated August 19!
Polished Map: pokered+pokecrystal map, tileset, and palette editor — version 3.5.1 released!

Offline

#3 2016-12-24 14:36:36

Kuroko Aizawa
Member
Registered: 2011-12-01
Post 389/499

Re: Pokemon Orange

Nice palm tree and Ivy sprite, will definitely use it.

Not sure about Pack image yet.
Will be leaning more towards an RSE-eque textbox frame
Battle interface will remain the same
New tileset will be used, although I suck at tiles so building won't be replaced for a while
How hard is that Dex to implement?

As for gym progression, essentially the latter, there will be plenty of rivals and side quests to do between gyms. Shamouti itself should take up a good hour of the players' time, and you can come back to do different parts of it. Red, Misty, Brock, Tracey Sketchit, Samson Oak, and the Rocket Trios (Jessie and James as well as Cassidy and Butch) all have roles in this game and will have scripted battles.

Last edited by Kuroko Aizawa (2016-12-24 14:42:20)

Offline

#4 2016-12-24 15:42:42

Rangi
Member
Registered: 2016-05-09
Post 409/870

Re: Pokemon Orange

The Pokédex is just an edit to gfx/misc/pokedex.2bpp.lz, rounding the four corner tiles off.

Recolored RSE tiles (from coastal/island parts like Dewford or Pacifidlog) would probably look good without too much effort, at least for buildings and objects. For textures like sand and water, most of them are 16x16 as opposed to GSC's 8x8, which might not be the aesthetic you want. Although I personally like the RSE water tile, especially since the player will spend a lot of time looking at the ocean.

H9Otq8P.png

More battles with named characters is fun. Will Shamouti Island involve Lawrence III? (Or is that a spoiler?)

Last edited by Rangi (2016-12-24 15:51:23)


Pokémon Polished Crystal (GitHub) — version 2.2.0 released
Pokémon Red★ and Blue★: Space World Edition (GitHub) — updated August 19!
Polished Map: pokered+pokecrystal map, tileset, and palette editor — version 3.5.1 released!

Offline

#5 2016-12-24 15:47:54

Kuroko Aizawa
Member
Registered: 2011-12-01
Post 390/499

Re: Pokemon Orange

Lawrence III Probably won't be involved, a lot of the events I am setting up will be custom. The current story will have something to do with Red, as he has caught the original 150 and is going to be in the OI searching for Mew.

Also, I've almost got this new Palm setup but I am having trouble rearranging tilesets. Do you have any experience with this?
8e66e1bfbe9e22ef54884355f6e82e9f.png

Offline

#6 2016-12-24 15:58:02

Rangi
Member
Registered: 2016-05-09
Post 410/870

Re: Pokemon Orange

I use metatiles.py to preview the metatilesets and Hex Workshop to assemble them, referring to a tilesheet like this. Also, all the tileset graphics are 128x96, storing 192 tiles (example), and using comet's tile extension hack to make use of all of them at once.

I hope there'll be a wide variety of Water Pokémon, including dual types. Lanturn, Starmie, Jellicent, Qwilfish, Ludicolo, Toxapek, Dhelmise (okay that's Grass/Ghost)...

(I'm working on a way to fit 255 Pokémon in the game, by not using $ff as an end-of-list marker in Bill's PC and using a flag separate from the species ID for Eggs. It's only two more Pokémon, but with much less effort than extending all the IDs to two bytes.)

Last edited by Rangi (2016-12-24 16:01:11)


Pokémon Polished Crystal (GitHub) — version 2.2.0 released
Pokémon Red★ and Blue★: Space World Edition (GitHub) — updated August 19!
Polished Map: pokered+pokecrystal map, tileset, and palette editor — version 3.5.1 released!

Offline

#7 2016-12-24 16:19:10

Kuroko Aizawa
Member
Registered: 2011-12-01
Post 391/499

Re: Pokemon Orange

Rangi wrote:

I use metatiles.py to preview the metatilesets and Hex Workshop to assemble them, referring to a tilesheet like this. Also, all the tileset graphics are 128x96, storing 192 tiles (example), and using comet's tile extension hack to make use of all of them at once.

I hope there'll be a wide variety of Water Pokémon, including dual types. Lanturn, Starmie, Jellicent, Qwilfish, Ludicolo, Toxapek, Dhelmise (okay that's Grass/Ghost)...

(I'm working on a way to fit 255 Pokémon in the game, by not using $ff as an end-of-list marker in Bill's PC and using a flag separate from the species ID for Eggs. It's only two more Pokémon, but with much less effort than extending all the IDs to two bytes.)

I'm hoping I can set water routes to have unique pools of pokemon rather than a global one. No one wants to face level 10 tentacool all game.

Offline

#8 2016-12-24 16:30:01

Rangi
Member
Registered: 2016-05-09
Post 412/870

Re: Pokemon Orange

Kuroko Aizawa wrote:

I'm hoping I can set water routes to have unique pools of pokemon rather than a global one. No one wants to face level 10 tentacool all game.

That shouldn't be a problem, just split the ocean into multiple connected maps and give each map its own set. Also maybe edit engine/wildmons.asm to make water behave the same way as grass, with seven Pokémon instead of three and different sets at morning/day/night.

(One issue with map connections: connected maps have to share the same few overworld sprites and the same tileset, because those only get reloaded when you warp to a new map. Caves and boathouses could play the role of gatehouses in keeping groups of maps separated.)


Pokémon Polished Crystal (GitHub) — version 2.2.0 released
Pokémon Red★ and Blue★: Space World Edition (GitHub) — updated August 19!
Polished Map: pokered+pokecrystal map, tileset, and palette editor — version 3.5.1 released!

Offline

#9 2016-12-24 17:29:04

Kuroko Aizawa
Member
Registered: 2011-12-01
Post 393/499

Re: Pokemon Orange

Oh yes, lots of dungeons are a must for a game like this. I will give that a try, hopefully it will not bug out on me.

QXFC2TW.pngowaO6NK.png

Edit: Also about the water I'm not sure how difficult it would be to add that water since its 4x bigger than the default water tiles, but that would look nice.

EDIT2: Got it to work, I also got rid of the Fog badge check for Surf, progression is smooth so far :)

Offline

#10 2016-12-24 17:30:23

Rangi
Member
Registered: 2016-05-09
Post 413/870

Re: Pokemon Orange

Pinkan Berry Grass/Dragon Exeggutor—excellent. (That would be a cool Sudowoodo-type obstacle...)

How about larger leaves for the thin palm trees too?

5GJ7mbI.png

About the water, you'd need to have four water tiles in the tileset, and edit tilesets/anims.asm to animate them. I can help with that part. Edit: Never mind. :)

Last edited by Rangi (2016-12-24 17:31:40)


Pokémon Polished Crystal (GitHub) — version 2.2.0 released
Pokémon Red★ and Blue★: Space World Edition (GitHub) — updated August 19!
Polished Map: pokered+pokecrystal map, tileset, and palette editor — version 3.5.1 released!

Offline

#11 2016-12-24 17:36:05

Kuroko Aizawa
Member
Registered: 2011-12-01
Post 394/499

Re: Pokemon Orange

Well, I thought I had the water encounters working until a level 27 pikachu appeared in New Bark Town (which has Route 29s wild table for testing), I'm thinking if I just set it to 7 Pokemon per route it will clear out the clutter. Sea shouldn't differ too much at night anyway.

And I like what you did with the thin palms. I think they can coexist with the HGSS one for some map variation. I think the hardest thing to implement is going to bridges, which I think would make for some really fun maps.

EDIT: Got them fixed, just had to change the encounter table for water pokemon to match grass.

Last edited by Kuroko Aizawa (2016-12-24 18:13:33)

Offline

#12 2016-12-24 19:08:43

Mateo
Member
From: The Sims 4
Registered: 2009-11-25
Post 3,448/3,578

Re: Pokemon Orange

RSE's water only uses 2 tiles though, and they don't have rotation/mirror effects applied to them, so you shouldn't really need 4 tiles to do what RSE did with 2. Just be careful devamping the animation and setup the blocks the same way.

Offline

#13 2016-12-24 19:32:20

Rangi
Member
Registered: 2016-05-09
Post 414/870

Re: Pokemon Orange

And I like what you did with the thin palms. I think they can coexist with the HGSS one for some map variation. I think the hardest thing to implement is going to bridges, which I think would make for some really fun maps.

You mean, bridges that you can walk under or over? That would be the first time ever for a Gen 2 game (unless Prism has some). Techniques that might work:

• xytriggers surrounding the bridge that execute changeblock commands
• A collision type that hides the player's sprite entirely (check out engine/map_objects.asm and engine/movement.asm and see how it handles tall grass)
• Setting the INVISIBLE bit for an object's first Flags byte (see wram.asm:ObjectStructs and the OBJECT_ constants in constants/map_constants.asm) will hide the object (doable with the hide_person and show_person movement commands)
• Flying, Teleporting, blacking out from poison damage, etc, should all be handled properly
• I think bridges over water would be more complicated than over land, but maybe not?

RSE's water only uses 2 tiles though, and they don't have rotation/mirror effects applied to them, so you shouldn't really need 4 tiles to do what RSE did with 2. Just be careful devamping the animation and setup the blocks the same way.

Oh, you're right. The water animation is 8 frames long, so something similar to tilesets/animations.asm:AnimateSproutPillarTile would work.

Last edited by Rangi (2016-12-24 19:39:35)


Pokémon Polished Crystal (GitHub) — version 2.2.0 released
Pokémon Red★ and Blue★: Space World Edition (GitHub) — updated August 19!
Polished Map: pokered+pokecrystal map, tileset, and palette editor — version 3.5.1 released!

Offline

#14 2016-12-24 19:41:25

Kuroko Aizawa
Member
Registered: 2011-12-01
Post 395/499

Re: Pokemon Orange

Yeah, gen 4 bridges might be hard to implement but I just want to make it so people can't sidestep off the bridge without making the map look hideous. Had a lot of issues with that mapping my demake of Platinum. Walking under them could be handled with warps (so that under a bridge is actually its own map).

I'll see about getting that RSE water in.

Offline

#15 2016-12-24 20:40:34

Rangi
Member
Registered: 2016-05-09
Post 415/870

Re: Pokemon Orange

I'll also be using that water for some non-Johto/Kanto locations, so here's my code from tilesets/animations.asm:

; this tileset has animated water and flowers
Tileset42Anim:
    dw RSEWaterFrames1, AnimateRSEWaterTile
    dw RSEWaterFrames2, AnimateRSEWaterTile
    dw NULL,  WaitTileAnimation
    dw NULL,  WaitTileAnimation
    dw NULL,  WaitTileAnimation
    dw NULL,  WaitTileAnimation
    dw NULL,  WaitTileAnimation
    dw NULL,  AnimateFlowerTile
    dw NULL,  WaitTileAnimation
    dw NULL,  WaitTileAnimation
    dw NULL,  WaitTileAnimation
    dw NULL,  StandingTileFrame8
    dw NULL,  DoneTileAnimation
AnimateRSEWaterTile:
; Draw a RSE water tile for the current frame in VRAM tile at de.
; based on AnimateWhirlpoolTile, but with 8 frames

; Struct:
;     VRAM address
;    Address of the first tile

; Only does one of 2 tiles at a time.

; Save sp in bc (see WriteTile).
    ld hl, [sp+0]
    ld b, h
    ld c, l

; de = VRAM address
    ld l, e
    ld h, d
    ld e, [hl]
    inc hl
    ld d, [hl]
    inc hl
; Tile address is now at hl.

; Get the tile for this frame.
    ld a, [TileAnimationTimer]
    and %111 ; 8 frames x2
    swap a  ; * 16 bytes per tile

    add [hl]
    inc hl
    ld h, [hl]
    ld l, a
    ld a, 0
    adc h
    ld h, a

; Stack now points to the desired frame.
    ld sp, hl

    ld l, e
    ld h, d

    jp WriteTile
RSEWaterFrames1: dw VTiles2 tile $14, RSEWaterTiles1
RSEWaterFrames2: dw VTiles2 tile $59, RSEWaterTiles2

; each file is just the 8 frames in a row
RSEWaterTiles1: INCBIN "gfx/tilesets/water/rse_water_1.2bpp"
RSEWaterTiles2: INCBIN "gfx/tilesets/water/rse_water_2.2bpp"

piNFhhC.png

Last edited by Rangi (2016-12-24 20:50:35)


Pokémon Polished Crystal (GitHub) — version 2.2.0 released
Pokémon Red★ and Blue★: Space World Edition (GitHub) — updated August 19!
Polished Map: pokered+pokecrystal map, tileset, and palette editor — version 3.5.1 released!

Offline

#16 2016-12-24 22:54:47

Kuroko Aizawa
Member
Registered: 2011-12-01
Post 396/499

Re: Pokemon Orange

Took forever to get the pattern right:
2RqkfVR.png

Offline

#17 2016-12-24 23:16:50

Rangi
Member
Registered: 2016-05-09
Post 416/870

Re: Pokemon Orange

Nice! It looks like the water palette isn't entirely updated, though. You could change the lightest "RGB 18, 19, 31" to "RGB 16, 26, 30", or something closer to the main shade.

Mind if I post some devamped house designs? (If this is meant to be your creative project, then no problem, but I'm fine with doing some graphics+programming if you want, as a break from other work. Anyway, I have zero ideas for map layouts or plot, so that's all on you. ;) Interested in posting map previews when they're done, like you were doing with Quasar?)


Pokémon Polished Crystal (GitHub) — version 2.2.0 released
Pokémon Red★ and Blue★: Space World Edition (GitHub) — updated August 19!
Polished Map: pokered+pokecrystal map, tileset, and palette editor — version 3.5.1 released!

Offline

#18 2016-12-24 23:17:14

bloodless
Member
From: Somewhere south of Never Land
Registered: 2016-05-06
Post 123/171

Re: Pokemon Orange

Regarding Pinkan pokemon one thing I would like to suggest for this game is that pokemon native to Pinkan island are permanently pink as is stated in the anime. I have a complete set of accurate Pinkan native pokemon in the devamp thread if you want to use them.

Edit: I believe I have some old OI maps lying around from when I tried to do this in gold a few years back, the elemental islands and a few others, if you'd like I can try to dig them out for you.

Last edited by bloodless (2016-12-24 23:20:15)


The saddest thing is there's no such thing as an ex addict. Either you're fighting addiction or you're not and if you start fighting you never stop. That's the nature of the monster.

Offline

#19 2016-12-24 23:53:22

Kuroko Aizawa
Member
Registered: 2011-12-01
Post 397/499

Re: Pokemon Orange

bloodless wrote:

Regarding Pinkan pokemon one thing I would like to suggest for this game is that pokemon native to Pinkan island are permanently pink as is stated in the anime. I have a complete set of accurate Pinkan native pokemon in the devamp thread if you want to use them.

Edit: I believe I have some old OI maps lying around from when I tried to do this in gold a few years back, the elemental islands and a few others, if you'd like I can try to dig them out for you.

This is no longer possible due to me making Pink a state that any Pokemon can obtain, and it is curable at a Pokemon center or by fainting. It can be used as a way to prevent any status ailments in battle and I kind of like it that way as of right now. As far as the maps, I'd love to see them, they always help me with directing the game towards better mapping.

Rangi wrote:

Nice! It looks like the water palette isn't entirely updated, though. You could change the lightest "RGB 18, 19, 31" to "RGB 16, 26, 30", or something closer to the main shade.

Mind if I post some devamped house designs? (If this is meant to be your creative project, then no problem, but I'm fine with doing some graphics+programming if you want, as a break from other work. Anyway, I have zero ideas for map layouts or plot, so that's all on you. ;) Interested in posting map previews when they're done, like you were doing with Quasar?)

On the contrary I appreciate any tiles as they are the one thing I can't sprite well. And absolutely, once my mapping gets to a significant point I will be posting some videos and screenshots.

EDIT: Much better
vfehUHq.png

Last edited by Kuroko Aizawa (2016-12-25 00:02:32)

Offline

#20 2016-12-25 01:22:58

bloodless
Member
From: Somewhere south of Never Land
Registered: 2016-05-06
Post 124/171

Re: Pokemon Orange

I've loved your Pinkan berry work since the day you posted the thread about it and if it has to he one or the other I'd choose the berry effect over the native forms but is there no way to have both?

I'll be posting a thread with my works tomorrow (there's a few OI treats in there too) if I can find the maps I'll attach them in that post or here. They're very incomplete but if I remember correctly I was exploring a sort of open ocean concept at the time before I gave up (gold was so very poorly documented back then and even now the Crystal dissasembly is far superior if I ever go back to work on it I'll definitely be moving to Crystal or Red).


The saddest thing is there's no such thing as an ex addict. Either you're fighting addiction or you're not and if you start fighting you never stop. That's the nature of the monster.

Offline

#21 2016-12-25 01:31:23

Kuroko Aizawa
Member
Registered: 2011-12-01
Post 398/499

Re: Pokemon Orange

bloodless wrote:

I've loved your Pinkan berry work since the day you posted the thread about it and if it has to he one or the other I'd choose the berry effect over the native forms but is there no way to have both?

Unless I made a third shiny form for Pinkan pokemon I doubt it, and that would probably cause issues with actual shiny Pokemon (say you find a shiny pinkan pokemon, its just going to be pink). I am going to make wild pokemon on Pinkan Island appear with PNK status, somehow. I'm looking at the headbutt code to see how I can do this.

I realize it's a highly desired feature and it's something people haven't really done without forking over a shiny palette for a scripted Ryhorn battle (cough Naranja), but it for certain isn't going to be a huge feature in the game and I want to maintain it as something fun for the player, as well as give reason to come back to Pinkan island.

Offline

#22 2016-12-25 02:16:20

Rangi
Member
Registered: 2016-05-09
Post 417/870

Re: Pokemon Orange

Crystal records the caught location, so you can find the CheckShininess calls in color.asm and add a CheckPinkan call afterwards, which returns the pink palette if the caught location is correct.


Pokémon Polished Crystal (GitHub) — version 2.2.0 released
Pokémon Red★ and Blue★: Space World Edition (GitHub) — updated August 19!
Polished Map: pokered+pokecrystal map, tileset, and palette editor — version 3.5.1 released!

Offline

#23 2016-12-25 02:18:36

Kuroko Aizawa
Member
Registered: 2011-12-01
Post 399/499

Re: Pokemon Orange

Rangi wrote:

Crystal records the caught location, so you can find the CheckShininess calls in color.asm and add a CheckPinkan call afterwards, which returns the pink palette if the caught location is correct.

Correct, although this would kill the part where the berry turns Pokemon pink temporarily, which is just a canon as the permanent Pink pokemon. Lesser of two evils I guess.

Also, I'm compiling a list of Pokemon to add to the game. Most gen 2 Pokemon will be replaced.

Offline

#24 2016-12-25 02:38:19

Rangi
Member
Registered: 2016-05-09
Post 418/870

Re: Pokemon Orange

Kuroko Aizawa wrote:
Rangi wrote:

Crystal records the caught location, so you can find the CheckShininess calls in color.asm and add a CheckPinkan call afterwards, which returns the pink palette if the caught location is correct.

Correct, although this would kill the part where the berry turns Pokemon pink temporarily, which is just a canon as the permanent Pink pokemon. Lesser of two evils I guess.

Also, I'm compiling a list of Pokemon to add to the game. Most gen 2 Pokemon will be replaced.

I meant both methods could coexist, but maybe that would seem inconsistent.

Not all Kanto Pokémon are fit for islands either. Check out the habitats.


Pokémon Polished Crystal (GitHub) — version 2.2.0 released
Pokémon Red★ and Blue★: Space World Edition (GitHub) — updated August 19!
Polished Map: pokered+pokecrystal map, tileset, and palette editor — version 3.5.1 released!

Offline

#25 2016-12-25 03:10:33

Kuroko Aizawa
Member
Registered: 2011-12-01
Post 400/499

Re: Pokemon Orange

Rangi wrote:
Kuroko Aizawa wrote:
Rangi wrote:

Crystal records the caught location, so you can find the CheckShininess calls in color.asm and add a CheckPinkan call afterwards, which returns the pink palette if the caught location is correct.

Correct, although this would kill the part where the berry turns Pokemon pink temporarily, which is just a canon as the permanent Pink pokemon. Lesser of two evils I guess.

Also, I'm compiling a list of Pokemon to add to the game. Most gen 2 Pokemon will be replaced.

I meant both methods could coexist, but maybe that would seem inconsistent.

Not all Kanto Pokémon are fit for islands either. Check out the habitats.

I'll look to add the check for caught location once battle palettes work, however as of right now I'm stumped. Any change I've tried so far just breaks battle palettes.

PALPACKET_LENGTH EQU $10
INCLUDE "predef/sgb.asm"

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]
    and 1 << SHINY_ATK_BIT
    jr z, .NotShiny

; Defense
    ld a, [hli]
    and $f
    cp  SHINY_DEF_VAL
    jr nz, .NotShiny

; Speed
    ld a, [hl]
    and $f0
    cp  SHINY_SPD_VAL << 4
    jr nz, .NotShiny

; Special
    ld a, [hl]
    and $f
    cp  SHINY_SPC_VAL
    jr nz, .NotShiny

.Shiny:
    scf
    ret

.NotShiny:
    and a
    ret

CheckContestMon:
; Check a mon's DVs at hl in the bug catching contest.
; Return carry if its DVs are good enough to place in the contest.

; Attack
    ld a, [hl]
    cp 10 << 4
    jr c, .Bad

; Defense
    ld a, [hli]
    and $f
    cp 10
    jr c, .Bad

; Speed
    ld a, [hl]
    cp 10 << 4
    jr c, .Bad

; Special
    ld a, [hl]
    and $f
    cp 10
    jr c, .Bad

.Good:
    scf
    ret

.Bad:
    and a
    ret

Function8aa4:
; XXX
    push de
    push bc
    ld hl, PalPacket_9ce6
    ld de, wSGBPals
    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_
    ld hl, BlkPacket_9a86
    call PushSGBPals_
    ret

InitPartyMenuPalettes:
    ld hl, PalPacket_9c56 + 1
    call CopyFourPalettes
    call InitPartyMenuOBPals
    call WipeAttrMap
    ret

SGB_ApplyPartyMenuHPPals: ; 8ade SGB layout $fc
    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
    ld bc, $6
    ld a, [wSGBPals]
    call AddNTimes
    pop de
    ld [hl], e
    ret

Function8b07:
; Unreferenced
    call CheckCGB
    ret z
; CGB only
    ld hl, .BGPal
    ld de, UnknBGPals
    ld bc, 1 palettes
    ld a, $5
    call FarCopyWRAM

    ld hl, .OBPal
    ld de, UnknOBPals
    ld bc, 1 palettes
    ld a, $5
    call FarCopyWRAM

    call ApplyPals
    ld a, $1
    ld [hCGBPalUpdate], a
    ret

.BGPal:
    RGB 31, 31, 31
    RGB 18, 23, 31
    RGB 15, 20, 31
    RGB 00, 00, 00

.OBPal:
    RGB 31, 31, 31
    RGB 31, 31, 12
    RGB 08, 16, 28
    RGB 00, 00, 00

Function8b3f:
; Unreferenced
    call CheckCGB
    ret nz
    ld a, [hSGB]
    and a
    ret z
    ld hl, BlkPacket_9a86
    jp PushSGBPals_

Function8b4d:
; XXX
    call CheckCGB
    jr nz, .cgb
    ld a, [hSGB]
    and a
    ret z
    ld hl, PalPacket_9c26
    jp PushSGBPals_

.cgb
    ld de, UnknOBPals
    ld a, $3b
    call GetPredefPal
    jp LoadHLPaletteIntoDE

Function8b67:
; XXX
    call CheckCGB
    jr nz, .cgb
    ld a, [hSGB]
    and a
    ret z
    ld hl, PalPacket_9c36
    jp PushSGBPals_

.cgb
    ld de, UnknOBPals
    ld a, $3c
    call GetPredefPal
    jp LoadHLPaletteIntoDE

Function8b81:
; XXX
    call CheckCGB
    jr nz, .cgb
    ld a, [hSGB]
    and a
    ret z
    ld a, c
    push af
    ld hl, PalPacket_9ce6
    ld de, wSGBPals
    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
    ld de, UnknOBPals
    ld a, c
    call GetMonPalettePointer_
    call LoadPalette_White_Col1_Col2_Black
    ret

LoadTrainerClassPaletteAsNthBGPal:
    ld a, [TrainerClass]
    call GetTrainerPalettePointer
    ld a, e
    jr got_palette_pointer_8bd7

LoadMonPaletteAsNthBGPal:
    ld a, [CurPartySpecies]
    call GetMonPalettePointer
    ld a, e
    bit 7, a
    jr z, got_palette_pointer_8bd7
    and $7f
    inc hl
    inc hl
    inc hl
    inc hl

got_palette_pointer_8bd7
    push hl
    ld hl, UnknBGPals
    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
    call LoadPalette_White_Col1_Col2_Black
    ret

Function8bec:
; XXX
    ld a, [hCGB]
    and a
    jr nz, .cgb
    ld hl, PlayerLightScreenCount
    jp PushSGBPals_

.cgb
    ld a, [EnemyLightScreenCount] ; col
    ld c, a
    ld a, [EnemyReflectCount] ; row
    hlcoord 0, 0, AttrMap
    ld de, SCREEN_WIDTH
.loop
    and a
    jr z, .done
    add hl, de
    dec a
    jr .loop

.done
    ld b, $0
    add hl, bc
    lb bc, 6, 4
    ld a, [EnemySafeguardCount] ; value
    and $3
    call FillBoxCGB
    call LoadEDTile
    ret

ApplyMonOrTrainerPals:
    call CheckCGB
    ret z
    ld a, e
    and a
    jr z, .get_trainer
    ld a, [CurPartySpecies]
    call GetMonPalettePointer_
    jr .load_palettes

.get_trainer
    ld a, [TrainerClass]
    call GetTrainerPalettePointer

.load_palettes
    ld de, UnknBGPals
    call LoadPalette_White_Col1_Col2_Black
    call WipeAttrMap
    call ApplyAttrMap
    call ApplyPals
    ret

ApplyHPBarPals:
    ld a, [wWhichHPBar]
    and a
    jr z, .Enemy
    cp $1
    jr z, .Player
    cp $2
    jr z, .PartyMenu
    ret

.Enemy:
    ld de, BGPals + 2 palettes + 2
    jr .okay

.Player:
    ld de, BGPals + 3 palettes + 2

.okay
    ld l, c
    ld h, $0
    add hl, hl
    add hl, hl
    ld bc, Palettes_a8be
    add hl, bc
    ld bc, 4
    ld a, $5
    call FarCopyWRAM
    ld a, $1
    ld [hCGBPalUpdate], a
    ret

.PartyMenu:
    ld e, c
    inc e
    hlcoord 11, 1, AttrMap
    ld bc, 2 * SCREEN_WIDTH
    ld a, [CurPartyMon]
.loop
    and a
    jr z, .done
    add hl, bc
    dec a
    jr .loop

.done
    lb bc, 2, 8
    ld a, e
    call FillBoxCGB
    ret

LoadStatsScreenPals:
    call CheckCGB
    ret z
    ld hl, StatsScreenPals
    ld b, 0
    dec c
    add hl, bc
    add hl, bc
    ld a, [rSVBK]
    push af
    ld a, $5
    ld [rSVBK], a
    ld a, [hli]
    ld [UnknBGPals], a
    ld [UnknBGPals + 8 * 2], a
    ld a, [hl]
    ld [UnknBGPals + 1], a
    ld [UnknBGPals + 8 * 2 + 1], a
    pop af
    ld [rSVBK], a
    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
    ld hl, PalPacket_9ce6
    ld de, wSGBPals
    ld bc, PALPACKET_LENGTH
    call CopyBytes
    pop hl
    inc hl
    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_
    ld hl, BlkPacket_9a86
    call PushSGBPals_
    ret

.cgb
    ld de, UnknBGPals
    ld bc, 1 palettes
    ld a, $5
    call FarCopyWRAM
    call ApplyPals
    call WipeAttrMap
    call ApplyAttrMap
    ret

.MailPals:
    RGB 20, 31, 11
    RGB 31, 19, 00
    RGB 31, 10, 09
    RGB 00, 00, 00

    RGB 15, 20, 31
    RGB 30, 26, 00
    RGB 31, 12, 00
    RGB 00, 00, 00

    RGB 24, 17, 31
    RGB 30, 26, 00
    RGB 08, 11, 31
    RGB 00, 00, 00

    RGB 31, 25, 17
    RGB 31, 18, 04
    RGB 28, 12, 05
    RGB 00, 00, 00

    RGB 19, 26, 31
    RGB 31, 05, 08
    RGB 31, 09, 31
    RGB 00, 00, 00

    RGB 31, 19, 28
    RGB 31, 21, 00
    RGB 12, 22, 00
    RGB 00, 00, 00

    RGB 19, 17, 23
    RGB 30, 26, 00
    RGB 31, 12, 00
    RGB 00, 00, 00

    RGB 07, 26, 31
    RGB 26, 26, 27
    RGB 31, 11, 11
    RGB 00, 00, 00

    RGB 21, 31, 21
    RGB 30, 26, 00
    RGB 31, 12, 00
    RGB 00, 00, 00

    RGB 07, 26, 31
    RGB 31, 31, 00
    RGB 00, 21, 00
    RGB 00, 00, 00

INCLUDE "predef/cgb.asm"

Function95f0:
; XXX
    ld hl, .Palette
    ld de, UnknBGPals
    ld bc, 8
    ld a, $5
    call FarCopyWRAM
    call ApplyPals
    call WipeAttrMap
    call ApplyAttrMap
    ret

.Palette:
    RGB 31, 31, 31
    RGB 09, 31, 31
    RGB 10, 12, 31
    RGB 00, 03, 19

CopyFourPalettes:
    ld de, UnknBGPals
    ld c, $4

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
    add hl, hl
    add hl, hl
    ld bc, Palettes_9df6
    add hl, bc
    ret

LoadHLPaletteIntoDE:
    ld a, [rSVBK]
    push af
    ld a, $5
    ld [rSVBK], a
    ld c, $8
.loop
    ld a, [hli]
    ld [de], a
    inc de
    dec c
    jr nz, .loop
    pop af
    ld [rSVBK], a
    ret

LoadPalette_White_Col1_Col2_Black:
    ld a, [rSVBK]
    push af
    ld a, $5
    ld [rSVBK], a

    ld a, $7fff % $100
    ld [de], a
    inc de
    ld a, $7fff / $100
    ld [de], a
    inc de

    ld c, 2 * 2
.loop
    ld a, [hli]
    ld [de], a
    inc de
    dec c
    jr nz, .loop

    xor a
    ld [de], a
    inc de
    ld [de], a
    inc de

    pop af
    ld [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

    ld a, [rSVBK]
    push af
    ld a, $5
    ld [rSVBK], a

    ld hl, UnknBGPals
    ld c, 8
.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
    jr nz, .loop

    pop af
    ld [rSVBK], a

    pop hl
    pop de
    pop bc
    pop af
    ret

WipeAttrMap:
    hlcoord 0, 0, AttrMap
    ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
    xor a
    call ByteFill
    ret

ApplyPals:
    ld hl, UnknBGPals
    ld de, BGPals
    ld bc, 16 palettes
    ld a, $5
    call FarCopyWRAM
    ret

ApplyAttrMap:
    ld a, [rLCDC]
    bit 7, a
    jr z, .UpdateVBank1
    ld a, [hBGMapMode]
    push af
    ld a, $2
    ld [hBGMapMode], a
    call DelayFrame
    call DelayFrame
    call DelayFrame
    call DelayFrame
    pop af
    ld [hBGMapMode], a
    ret

.UpdateVBank1:
    hlcoord 0, 0, AttrMap
    debgcoord 0, 0
    ld b, SCREEN_HEIGHT
    ld a, $1
    ld [rVBK], a
.row
    ld c, SCREEN_WIDTH
.col
    ld a, [hli]
    ld [de], a
    inc de
    dec c
    jr nz, .col
    ld a, BG_MAP_WIDTH - SCREEN_WIDTH
    add e
    jr nc, .okay
    inc d
.okay
    ld e, a
    dec b
    jr nz, .row
    ld a, $0
    ld [rVBK], a
    ret

CGB_ApplyPartyMenuHPPals: ; 96f3 CGB layout $fc
    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, AttrMap
    ld bc, 2 * SCREEN_WIDTH
    ld a, [wSGBPals]
.loop
    and a
    jr z, .done
    add hl, bc
    dec a
    jr .loop
.done
    lb bc, 2, 8
    ld a, e
    call FillBoxCGB
    ret

InitPartyMenuOBPals:
    ld hl, Palettes_b681
    ld de, UnknOBPals
    ld bc, 2 palettes
    ld a, $5
    call FarCopyWRAM
    ret

GetBattlemonBackpicPalettePointer:
    push de
    callba GetPartyMonDVs
    ld c, l
    ld b, h
    ld a, [TempBattleMonSpecies]
    call GetPlayerOrMonPalettePointer
    pop de
    ret

GetEnemyFrontpicPalettePointer:
    push de
    callba GetEnemyMonDVs
    ld c, l
    ld b, h
    ld a, [TempEnemyMonSpecies]
    call GetFrontpicPalettePointer
    pop de
    ret

GetPlayerOrMonPalettePointer:
    and a
    jp nz, GetMonNormalOrShinyPalettePointer
    ld a, [wPlayerSpriteSetupFlags]
    bit 2, a ; transformed to male
    jr nz, .male
    ld a, [PlayerGender]
    and a
    jr z, .male
    ld hl, KrisPalette
    ret

.male
    ld hl, PlayerPalette
    ret

GetFrontpicPalettePointer:
    and a
    jp nz, GetMonNormalOrShinyPalettePointer
    ld a, [TrainerClass]

GetTrainerPalettePointer:
    ld l, a
    ld h, 0
    add hl, hl
    add hl, hl
    ld bc, TrainerPalettes
    add hl, bc
    ret

GetMonPalettePointer_:
    call GetMonPalettePointer
    ret

Function9779: mobile
    call CheckCGB
    ret z
    ld hl, Palettes_979c
    ld a, $90
    ld [rOBPI], a
    ld c, 6 palettes
.loop
    ld a, [hli]
    ld [rOBPD], a
    dec c
    jr nz, .loop
    ld hl, Palettes_979c
    ld de, UnknOBPals + 8 * 2
    ld bc, 2 palettes
    ld a, $5
    call FarCopyWRAM
    ret

Palettes_979c:
    RGB 31, 31, 31
    RGB 25, 25, 25
    RGB 13, 13, 13
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 31, 07
    RGB 31, 16, 01
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 19, 24
    RGB 30, 10, 06
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 12, 25, 01
    RGB 05, 14, 00
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 08, 12, 31
    RGB 01, 04, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 24, 18, 07
    RGB 20, 15, 03
    RGB 00, 00, 00

Function97cc:
; XXX
    call CheckCGB
    ret z
    ld a, $90
    ld [rOBPI], a
    ld a, $1c
    call GetPredefPal
    call .PushPalette
    ld a, $21
    call GetPredefPal
    call .PushPalette
    ret

.PushPalette:
    ld c, 1 palettes
.loop
    ld a, [hli]
    ld [rOBPD], a
    dec c
    jr nz, .loop
    ret
    
CheckPink:
    push bc
rept 11
    inc bc
endr
    ld a, [bc]
    cp (1 << PNK)
    pop bc
    ret
    
; check if bc == BattleMonDVs
    push hl
    ld hl, BattleMonDVs
    ld a, h
    cp b
    jr nz, .bc_is_not_battlemondvs
    ld a, l
    cp c
    jr nz, .bc_is_not_battlemondvs
    ; over here you know that bc == BattleMonDVs
    jr .bc_uses_battle_struct

.bc_is_not_battlemondvs:
; check if bc == EnemyMonDVs
    ld hl, BattleMonDVs
    ld a, h
    cp b
    jr nz, .bc_is_not_enemymondvs_either
    ld a, l
    cp c
    jr nz, .bc_is_not_enemymondvs_either
    ; over here you know that bc == EnemyMonDVs

.bc_uses_battle_struct:
    pop hl
    ; add 8 to bc to get Status

.bc_is_not_enemymondvs_either:
    ; add 11 to bc to get Status
 
GetMonPalettePointer:
    push af
    call CheckPink ; return 0 in a if not pink, 1 if pink
    jr z, .pink
    pop af
    ld l, a
    ld h, $0
    add hl, hl
    add hl, hl
    add hl, hl
    ld bc, PokemonPalettes
    add hl, bc
    ret
 
.pink:
    pop af ; so we don't just leave that register pair that we pushed hanging around
    ld hl, PokemonPalettes
    ret

GetMonNormalOrShinyPalettePointer:
    push bc
    call GetMonPalettePointer
    pop bc
    push hl
    call CheckShininess
    pop hl
    ret nc
rept 4
    inc hl
endr
    ret

PushSGBPals_:
    ld a, [wcfbe]
    push af
    set 7, a
    ld [wcfbe], a
    call PushSGBPals
    pop af
    ld [wcfbe], a
    ret

PushSGBPals:
    ld a, [hl]
    and $7
    ret z
    ld b, a
.loop
    push bc
    xor a
    ld [rJOYP], a
    ld a, $30
    ld [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
    ld [rJOYP], a
    ld a, $30
    ld [rJOYP], a
    rr d
    dec e
    jr nz, .loop3
    dec b
    jr nz, .loop2
    ld a, $20
    ld [rJOYP], a
    ld a, $30
    ld [rJOYP], a
    call SGBDelayCycles
    pop bc
    dec b
    jr nz, .loop
    ret

InitSGBBorder:
    call CheckCGB
    ret nz
; SGB/DMG only
    di
    ld a, [wcfbe]
    push af
    set 7, a
    ld [wcfbe], a
    xor a
    ld [rJOYP], a
    ld [hSGB], a
    call PushSGBBorderPalsAndWait
    jr nc, .skip
    ld a, $1
    ld [hSGB], a
    call _InitSGBBorderPals
    call SGBBorder_PushBGPals
    call SGBDelayCycles
    call SGB_ClearVRAM
    call PushSGBBorder
    call SGBDelayCycles
    call SGB_ClearVRAM
    ld hl, PalPacket_9d66
    call PushSGBPals

.skip
    pop af
    ld [wcfbe], a
    ei
    ret

InitCGBPals::
    call CheckCGB
    ret z
; CGB only
    ld a, $1
    ld [rVBK], a
    ld hl, VTiles0
    ld bc, $200 tiles
    xor a
    call ByteFill
    ld a, $0
    ld [rVBK], a
    ld a, $80
    ld [rBGPI], a
    ld c, 4 * 8
.bgpals_loop
    ld a, $7fff % $100
    ld [rBGPD], a
    ld a, $7fff / $100
    ld [rBGPD], a
    dec c
    jr nz, .bgpals_loop
    ld a, $80
    ld [rOBPI], a
    ld c, 4 * 8
.obpals_loop
    ld a, $7fff % $100
    ld [rOBPD], a
    ld a, $7fff / $100
    ld [rOBPD], a
    dec c
    jr nz, .obpals_loop
    ld a, [rSVBK]
    push af
    ld a, $5
    ld [rSVBK], a
    ld hl, UnknBGPals
    call .LoadWhitePals
    ld hl, BGPals
    call .LoadWhitePals
    pop af
    ld [rSVBK], a
    ret

.LoadWhitePals:
    ld c, 4 * 16
.loop
    ld a, $7fff % $100
    ld [hli], a
    ld a, $7fff / $100
    ld [hli], a
    dec c
    jr nz, .loop
    ret

_InitSGBBorderPals:
    ld hl, .PalPacketPointerTable
    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
    jr nz, .loop
    ret

.PalPacketPointerTable:
    dw PalPacket_9d56
    dw PalPacket_9d76
    dw PalPacket_9d86
    dw PalPacket_9d96
    dw PalPacket_9da6
    dw PalPacket_9db6
    dw PalPacket_9dc6
    dw PalPacket_9dd6
    dw PalPacket_9de6

Function9911:
; XXX
    di
    xor a
    ld [rJOYP], a
    ld hl, PalPacket_9d56
    call PushSGBPals
    call PushSGBBorder
    call SGBDelayCycles
    call SGB_ClearVRAM
    ld hl, PalPacket_9d66
    call PushSGBPals
    ei
    ret

PushSGBBorder:
    call .LoadSGBBorderPointers
    push de
    call SGBBorder_YetMorePalPushing
    pop hl
    call SGBBorder_MorePalPushing
    ret

.LoadSGBBorderPointers:
    ld hl, SGBBorder
    ld de, SGBBorderMap
    ret

SGB_ClearVRAM:
    ld hl, VTiles0
    ld bc, $2000
    xor a
    call ByteFill
    ret

PushSGBBorderPalsAndWait:
    ld hl, PalPacket_9d26
    call PushSGBPals
    call SGBDelayCycles
    ld a, [rJOYP]
    and $3
    cp $3
    jr nz, .carry
    ld a, $20
    ld [rJOYP], a
    ld a, [rJOYP]
    ld a, [rJOYP]
    call SGBDelayCycles
    call SGBDelayCycles
    ld a, $30
    ld [rJOYP], a
    call SGBDelayCycles
    call SGBDelayCycles
    ld a, $10
    ld [rJOYP], a
rept 6
    ld a, [rJOYP]
endr
    call SGBDelayCycles
    call SGBDelayCycles
    ld a, $30
    ld [rJOYP], a
    ld a, [rJOYP]
    ld a, [rJOYP]
    ld a, [rJOYP]
    call SGBDelayCycles
    call SGBDelayCycles
    ld a, [rJOYP]
    and $3
    cp $3
    jr nz, .carry
    call .FinalPush
    and a
    ret

.carry
    call .FinalPush
    scf
    ret

.FinalPush:
    ld hl, PalPacket_9d16
    call PushSGBPals
    jp SGBDelayCycles

SGBBorder_PushBGPals:
    call DisableLCD
    ld a, %11100100
    ld [rBGP], a
    ld hl, Palettes_9df6
    ld de, VTiles1
    ld bc, $1000
    call CopyData
    call DrawDefaultTiles
    ld a, $e3
    ld [rLCDC], a
    ld hl, PalPacket_9d06
    call PushSGBPals
    xor a
    ld [rBGP], a
    ret

SGBBorder_MorePalPushing:
    call DisableLCD
    ld a, $e4
    ld [rBGP], a
    ld de, VTiles1
    ld bc, 20 tiles
    call CopyData
    ld b, 18
.loop
    push bc
    ld bc, $c
    call CopyData
    ld bc, $28
    call ClearBytes
    ld bc, $c
    call CopyData
    pop bc
    dec b
    jr nz, .loop
    ld bc, $140
    call CopyData
    ld bc, Start
    call ClearBytes
    ld bc, 16 palettes
    call CopyData
    call DrawDefaultTiles
    ld a, $e3
    ld [rLCDC], a
    ld hl, PalPacket_9d46
    call PushSGBPals
    xor a
    ld [rBGP], a
    ret

SGBBorder_YetMorePalPushing:
    call DisableLCD
    ld a, %11100100
    ld [rBGP], a
    ld de, VTiles1
    ld b, $80
.loop
    push bc
    ld bc, 1 tiles
    call CopyData
    ld bc, 1 tiles
    call ClearBytes
    pop bc
    dec b
    jr nz, .loop
    call DrawDefaultTiles
    ld a, $e3
    ld [rLCDC], a
    ld hl, PalPacket_9d36
    call PushSGBPals
    xor a
    ld [rBGP], a
    ret

CopyData: ; 0x9a52
; copy bc bytes of data from hl to de
.loop
    ld a, [hli]
    ld [de], a
    inc de
    dec bc
    ld a, c
    or b
    jr nz, .loop
    ret
; 0x9a5b

ClearBytes: ; 0x9a5b
; clear bc bytes of data starting from de
.loop
    xor a
    ld [de], a
    inc de
    dec bc
    ld a, c
    or b
    jr nz, .loop
    ret
; 0x9a64

DrawDefaultTiles: ; 0x9a64
; Draw 240 tiles (2/3 of the screen) from tiles in VRAM
    hlbgcoord 0, 0 ; BG Map 0
    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
; 0x9a7a

SGBDelayCycles:
    ld de, 7000
.wait
    nop
    nop
    nop
    dec de
    ld a, d
    or e
    jr nz, .wait
    ret

BlkPacket_9a86:
    db $21, $01, $03, $00, $00, $00, $13, $11, $00, $00, $00, $00, $00, $00, $00, $00

BlkPacket_9a96:
    db $21, $01, $07, $05, $00, $0a, $13, $0d, $00, $00, $00, $00, $00, $00, $00, $00

BlkPacket_9aa6:
    db $22, $05, $07, $0a, $00, $0c, $13, $11, $03, $05, $01, $00, $0a, $03, $03, $00
    db $0a, $08, $13, $0a, $03, $0a, $00, $04, $08, $0b, $03, $0f, $0b, $00, $13, $07

BlkPacket_9ac6:
    db $21, $01, $07, $05, $00, $01, $07, $07, $00, $00, $00, $00, $00, $00, $00, $00

BlkPacket_9ad6:
    db $21, $01, $07, $05, $0b, $01, $13, $02, $00, $00, $00, $00, $00, $00, $00, $00

BlkPacket_9ae6:
    db $21, $01, $07, $05, $01, $01, $08, $08, $00, $00, $00, $00, $00, $00, $00, $00

BlkPacket_9af6:
    db $21, $01, $07, $05, $07, $05, $0d, $0b, $00, $00, $00, $00, $00, $00, $00, $00

BlkPacket_9b06:
    db $22, $05, $03, $05, $00, $00, $13, $0b, $03, $0a, $00, $04, $13, $09, $02, $0f
    db $00, $06, $13, $07, $03, $00, $04, $04, $0f, $09, $03, $00, $00, $0c, $13, $11

BlkPacket_9b26:
    db $23, $07, $07, $10, $00, $00, $02, $0c, $02, $00, $0c, $00, $12, $01, $02, $00
    db $0c, $02, $12, $03, $02, $00, $0c, $04, $12, $05, $02, $00, $0c, $06, $12, $07
    db $02, $00, $0c, $08, $12, $09, $02, $00, $0c, $0a, $12, $0b, $00, $00, $00, $00

BlkPacket_9b56:
    db $22, $03, $07, $20, $00, $00, $13, $04, $03, $0f, $00, $06, $13, $11, $03, $05
    db $0f, $01, $12, $04, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00

BlkPacket_9b76:
    db $21, $01, $07, $10, $00, $00, $13, $05, $00, $00, $00, $00, $00, $00, $00, $00

BlkPacket_9b86:
    db $21, $02, $07, $0a, $00, $04, $13, $0d, $03, $05, $00, $06, $13, $0b, $00, $00

PalPacket_9b96:    db $51, $48, $00, $49, $00, $4a, $00, $4b, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9ba6:    db $51, $2b, $00, $24, $00, $20, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9bb6:    db $51, $41, $00, $42, $00, $43, $00, $44, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9bc6:    db $51, $4c, $00, $4c, $00, $4c, $00, $4c, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9bd6:    db $51, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9be6:    db $51, $36, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9bf6:    db $51, $37, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9c06:    db $51, $38, $00, $39, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9c16:    db $51, $3a, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9c26:    db $51, $3b, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9c36:    db $51, $3c, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9c46:    db $51, $39, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9c56:    db $51, $2e, $00, $2f, $00, $30, $00, $31, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9c66:    db $51, $1a, $00, $1a, $00, $1a, $00, $1a, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9c76:    db $51, $32, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9c86:    db $51, $3c, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9c96:    db $51, $3d, $00, $3e, $00, $3f, $00, $40, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9ca6:    db $51, $33, $00, $34, $00, $1b, $00, $1f, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9cb6:    db $51, $1b, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9cc6:    db $51, $1c, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9cd6:    db $51, $35, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9ce6:    db $01, $ff, $7f, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9cf6:    db $09, $ff, $7f, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9d06:    db $59, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9d16:    db $89, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9d26:    db $89, $01, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9d36:    db $99, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9d46:    db $a1, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9d56:    db $b9, $01, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9d66:    db $b9, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
PalPacket_9d76:    db $79, $5d, $08, $00, $0b, $8c, $d0, $f4, $60, $00, $00, $00, $00, $00, $00, $00
PalPacket_9d86:    db $79, $52, $08, $00, $0b, $a9, $e7, $9f, $01, $c0, $7e, $e8, $e8, $e8, $e8, $e0
PalPacket_9d96:    db $79, $47, $08, $00, $0b, $c4, $d0, $16, $a5, $cb, $c9, $05, $d0, $10, $a2, $28
PalPacket_9da6:    db $79, $3c, $08, $00, $0b, $f0, $12, $a5, $c9, $c9, $c8, $d0, $1c, $a5, $ca, $c9
PalPacket_9db6:    db $79, $31, $08, $00, $0b, $0c, $a5, $ca, $c9, $7e, $d0, $06, $a5, $cb, $c9, $7e
PalPacket_9dc6:    db $79, $26, $08, $00, $0b, $39, $cd, $48, $0c, $d0, $34, $a5, $c9, $c9, $80, $d0
PalPacket_9dd6:    db $79, $1b, $08, $00, $0b, $ea, $ea, $ea, $ea, $ea, $a9, $01, $cd, $4f, $0c, $d0
PalPacket_9de6:    db $79, $10, $08, $00, $0b, $4c, $20, $08, $ea, $ea, $ea, $ea, $ea, $60, $ea, $ea

Palettes_9df6:
    RGB 31, 31, 31
    RGB 22, 25, 19
    RGB 16, 21, 30
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 27, 28, 31
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 24, 28, 19
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 24, 24, 24
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 21, 23, 31
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 24, 21, 27
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 24, 16
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 25, 30, 26
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 25, 31
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 20, 19
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 26, 19
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 27, 28, 27
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 24, 30, 23
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 29, 24, 29
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 26, 23, 29
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 25, 23, 20
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 29, 26, 18
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 21, 18
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 26, 25, 31
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 22, 21, 31
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 22, 25, 21
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 21, 21, 22
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 20, 20
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 26, 26, 26
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 21, 14, 09
    RGB 15, 20, 20
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 12, 28, 22
    RGB 15, 20, 20
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 07, 07, 07
    RGB 02, 03, 03
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 30, 22, 17
    RGB 16, 14, 19
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 18, 20, 27
    RGB 11, 15, 23
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 20, 10
    RGB 26, 10, 06
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 21, 25, 29
    RGB 14, 19, 25
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 27, 22, 24
    RGB 21, 15, 23
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 28, 20, 15
    RGB 21, 14, 09
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 20, 26, 16
    RGB 09, 20, 11
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 30, 22, 24
    RGB 28, 15, 21
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 28, 14
    RGB 26, 20, 00
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 26, 21, 22
    RGB 15, 15, 18
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 23, 19, 13
    RGB 14, 12, 17
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 16, 18, 21
    RGB 10, 12, 18
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 22, 15, 16
    RGB 17, 02, 05
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 15, 20, 20
    RGB 05, 16, 16
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 23, 15, 19
    RGB 14, 04, 12
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 20, 17, 18
    RGB 18, 13, 11
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 23, 21, 16
    RGB 12, 12, 10
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 21, 25, 29
    RGB 30, 22, 24
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 26, 23, 16
    RGB 29, 14, 09
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 18, 18, 18
    RGB 10, 10, 10
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 30, 26, 15
    RGB 00, 23, 00
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 30, 26, 15
    RGB 31, 23, 00
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 30, 26, 15
    RGB 31, 00, 00
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 29, 26, 19
    RGB 27, 20, 14
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 24, 20, 10
    RGB 21, 00, 04
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 20, 10
    RGB 21, 00, 04
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 30, 26, 16
    RGB 16, 12, 09
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 15, 28, 26
    RGB 12, 22, 26
    RGB 03, 16, 14

    RGB 31, 31, 31
    RGB 15, 28, 26
    RGB 23, 24, 24
    RGB 00, 00, 00

    RGB 31, 31, 24
    RGB 07, 27, 19
    RGB 26, 20, 10
    RGB 19, 12, 08

    RGB 31, 31, 31
    RGB 31, 28, 14
    RGB 31, 13, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 16, 18, 21
    RGB 10, 12, 18
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 23, 21, 16
    RGB 12, 12, 10
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 14, 00
    RGB 07, 11, 15
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 26, 21, 22
    RGB 26, 10, 06
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 30, 27, 04
    RGB 24, 20, 11
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 13, 25
    RGB 24, 20, 11
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 16, 19, 29
    RGB 24, 20, 11
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 30, 22, 24
    RGB 18, 18, 18
    RGB 16, 10, 07

    RGB 31, 31, 31
    RGB 21, 25, 29
    RGB 18, 18, 18
    RGB 16, 10, 07

    RGB 31, 31, 31
    RGB 20, 26, 16
    RGB 18, 18, 18
    RGB 16, 10, 07

    RGB 31, 31, 31
    RGB 31, 28, 14
    RGB 18, 18, 18
    RGB 16, 10, 07

    RGB 31, 31, 31
    RGB 18, 18, 18
    RGB 26, 10, 06
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 30, 22, 24
    RGB 28, 15, 21
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 26, 20, 00
    RGB 16, 19, 29
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 16, 02, 30
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 16, 13, 04
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 28, 04, 02
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 18, 23, 31
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 24, 20, 11
    RGB 18, 13, 11
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 31, 31
    RGB 25, 30, 00
    RGB 25, 30, 00

    RGB 00, 00, 00
    RGB 08, 11, 11
    RGB 21, 21, 21
    RGB 31, 31, 31

SGBBorderMap:
    db $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $14, $14, $15, $14, $16, $14, $17, $14, $17, $54, $16, $54, $15, $54, $14, $54, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14
    db $01, $14, $02, $14, $03, $14, $03, $54, $02, $54, $01, $54, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $24, $14, $25, $14, $26, $14, $07, $14, $07, $54, $26, $54, $25, $54, $24, $54, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $54, $01, $14, $02, $14, $03, $14, $03, $54, $02, $54, $01, $54
    db $11, $14, $12, $14, $13, $14, $13, $54, $12, $54, $11, $54, $10, $54, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $24, $14, $34, $14, $35, $14, $35, $54, $34, $54, $33, $54, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $10, $14, $11, $14, $12, $14, $13, $14, $13, $54, $12, $54, $11, $54
    db $21, $14, $22, $14, $23, $14, $23, $54, $22, $54, $21, $54, $20, $54, $07, $14, $08, $14, $09, $14, $0a, $14, $0b, $14, $0c, $14, $0d, $14, $07, $14, $07, $14, $18, $14, $09, $14, $1a, $14, $1b, $14, $0d, $14, $0c, $14, $1c, $14, $29, $14, $07, $14, $20, $14, $21, $14, $22, $14, $23, $14, $23, $54, $22, $54, $21, $54
    db $31, $14, $32, $14, $07, $14, $07, $14, $32, $54, $36, $10, $38, $10, $38, $10, $38, $10, $38, $10, $38, $10, $38, $10, $38, $10, $38, $10, $38, $10, $38, $10, $38, $10, $38, $10, $38, $10, $38, $10, $38, $10, $38, $10, $38, $10, $38, $10, $38, $10, $38, $10, $27, $10, $32, $14, $07, $54, $07, $54, $32, $54, $31, $54
    db $05, $14, $06, $14, $07, $14, $07, $54, $06, $54, $1f, $10,                                                                                                                                                                                     $37, $10, $06, $14, $07, $14, $07, $54, $06, $54, $05, $54
    db $15, $14, $16, $14, $17, $14, $17, $54, $16, $54, $1f, $10,                                                                                                                                                                                     $37, $10, $16, $14, $17, $14, $17, $54, $16, $54, $15, $54
    db $25, $14, $26, $14, $07, $14, $07, $54, $26, $54, $1f, $10,                                                                                                                                                                                     $37, $10, $26, $14, $07, $14, $07, $54, $26, $54, $25, $54
    db $33, $14, $34, $14, $35, $14, $35, $54, $34, $54, $1f, $10,                                                                                                                                                                                     $37, $10, $34, $14, $35, $14, $35, $54, $34, $54, $33, $54
    db $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $1f, $10,                                                                                                                                                                                     $37, $10, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14
    db $02, $54, $01, $54, $07, $54, $07, $14, $07, $14, $1f, $10,                                                                                                                                                                                     $37, $10, $07, $14, $07, $14, $07, $14, $01, $14, $02, $14
    db $12, $54, $11, $54, $10, $54, $07, $14, $07, $14, $1f, $10,                                                                                                                                                                                     $37, $10, $07, $14, $07, $14, $10, $14, $11, $14, $12, $14
    db $22, $54, $21, $54, $20, $54, $07, $14, $07, $14, $1f, $10,                                                                                                                                                                                     $37, $10, $07, $14, $07, $14, $20, $14, $21, $14, $22, $14
    db $32, $54, $31, $54, $30, $54, $07, $14, $07, $14, $1f, $10,                                                                                                                                                                                     $37, $10, $07, $14, $07, $14, $30, $14, $31, $14, $32, $14
    db $06, $54, $05, $54, $04, $54, $07, $14, $07, $14, $1f, $10,                                                                                                                                                                                     $37, $10, $07, $14, $07, $14, $04, $14, $05, $14, $06, $14
    db $16, $54, $15, $54, $14, $54, $07, $14, $07, $14, $1f, $10,                                                                                                                                                                                     $37, $10, $07, $14, $07, $14, $14, $14, $15, $14, $16, $14
    db $26, $54, $25, $54, $24, $54, $07, $14, $07, $14, $1f, $10,                                                                                                                                                                                     $37, $10, $07, $14, $07, $14, $24, $14, $25, $14, $26, $14
    db $34, $54, $33, $54, $07, $54, $07, $14, $07, $14, $1f, $10,                                                                                                                                                                                     $37, $10, $07, $14, $07, $14, $07, $14, $33, $14, $34, $14
    db $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $1f, $10,                                                                                                                                                                                     $37, $10, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14
    db $01, $14, $02, $14, $03, $14, $03, $54, $02, $54, $1f, $10,                                                                                                                                                                                     $37, $10, $02, $14, $03, $14, $03, $54, $02, $54, $01, $54
    db $11, $14, $12, $14, $13, $14, $13, $54, $12, $54, $1f, $10,                                                                                                                                                                                     $37, $10, $12, $14, $13, $14, $13, $54, $12, $54, $11, $54
    db $21, $14, $22, $14, $23, $14, $23, $54, $22, $54, $1f, $10,                                                                                                                                                                                     $37, $10, $22, $14, $23, $14, $23, $54, $22, $54, $21, $54
    db $31, $14, $32, $14, $07, $14, $07, $14, $32, $54, $1f, $10,                                                                                                                                                                                     $37, $10, $32, $14, $07, $54, $07, $54, $32, $54, $31, $54
    db $05, $14, $06, $14, $07, $14, $07, $54, $06, $54, $2e, $10, $2f, $10, $2f, $10, $2f, $10, $2f, $10, $2f, $10, $2f, $10, $2f, $10, $2f, $10, $2f, $10, $2f, $10, $2f, $10, $2f, $10, $2f, $10, $2f, $10, $2f, $10, $2f, $10, $2f, $10, $2f, $10, $2f, $10, $2f, $10, $2d, $10, $06, $14, $07, $14, $07, $54, $06, $54, $05, $54
    db $15, $14, $16, $14, $17, $14, $17, $54, $16, $54, $15, $54, $14, $54, $07, $14, $07, $14, $39, $14, $0e, $14, $09, $14, $0f, $14, $28, $14, $07, $14, $19, $14, $0c, $14, $1c, $14, $29, $14, $2a, $14, $2b, $14, $2c, $14, $39, $14, $07, $14, $07, $14, $14, $14, $15, $14, $16, $14, $17, $14, $17, $54, $16, $54, $15, $54
    db $25, $14, $26, $14, $07, $14, $07, $54, $26, $54, $25, $54, $24, $54, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $01, $14, $02, $14, $03, $14, $03, $54, $02, $54, $01, $54, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $24, $14, $25, $14, $26, $14, $07, $14, $07, $54, $26, $54, $25, $54
    db $33, $14, $34, $14, $35, $14, $35, $54, $34, $54, $24, $54, $07, $54, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $10, $14, $11, $14, $12, $14, $13, $14, $13, $54, $12, $54, $11, $54, $10, $54, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $24, $14, $34, $14, $35, $14, $35, $54, $34, $54, $33, $54
    db $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $20, $14, $21, $14, $22, $14, $23, $14, $23, $54, $22, $54, $21, $54, $20, $54, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14, $07, $14

SGBBorderPalettes:
    RGB 24, 06, 06
    RGB 24, 24, 26
    RGB 14, 15, 20
    RGB 04, 07, 10

    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25

    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25

    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25

    RGB 18, 24, 18
    RGB 31, 26, 15
    RGB 26, 19, 10
    RGB 12, 07, 05

    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25

    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25

    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25

    RGB 18, 06, 31
    RGB 31, 31, 29
    RGB 31, 12, 00
    RGB 00, 00, 00

    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25

    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25

    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25

    RGB 12, 31, 06
    RGB 22, 26, 30
    RGB 16, 17, 21
    RGB 00, 03, 00

    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25

    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25

    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25
    RGB 31, 31, 25

SGBBorder:
INCBIN "gfx/misc/sgb_border.2bpp"

Palettes_a8be:
    RGB 30, 26, 15
    RGB 00, 23, 00

    RGB 30, 26, 15
    RGB 31, 21, 00

    RGB 30, 26, 15
    RGB 31, 00, 00

Palettes_a8ca:
    RGB 30, 26, 15
    RGB 04, 17, 31

INCLUDE "gfx/pics/palette_pointers.asm"

INCLUDE "gfx/trainers/palette_pointers.asm"

LoadMapPals:
    callba LoadSpecialMapPalette
    jr c, .got_pals

    ; Which palette group is based on whether we're outside or inside
    ld a, [wPermission]
    and 7
    ld e, a
    ld d, 0
    ld hl, .TilesetColorsPointers
    add hl, de
    add hl, de
    ld a, [hli]
    ld h, [hl]
    ld l, a
    ; Futher refine by time of day
    ld a, [TimeOfDayPal]
    and 3
    add a
    add a
    add a
    ld e, a
    ld d, 0
    add hl, de
    ld e, l
    ld d, h
    ; Switch to palettes WRAM bank
    ld a, [rSVBK]
    push af
    ld a, $5
    ld [rSVBK], a
    ld hl, UnknBGPals
    ld b, 8
.outer_loop
    ld a, [de] ; lookup index for TilesetBGPalette
    push de
    push hl
    ld l, a
    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
    ld [rSVBK], a

.got_pals
    ld a, [TimeOfDayPal]
    and 3
    ld bc, 8 palettes
    ld hl, MapObjectPals
    call AddNTimes
    ld de, UnknOBPals
    ld bc, 8 palettes
    ld a, $5 ; BANK(UnknOBPals)
    call FarCopyWRAM

    ld a, [wPermission]
    cp TOWN
    jr z, .outside
    cp ROUTE
    ret nz
.outside
    ld a, [MapGroup]
    ld l, a
    ld h, 0
    add hl, hl
    add hl, hl
    add hl, hl
    ld de, RoofPals
    add hl, de
    ld a, [TimeOfDayPal]
    and 3
    cp NITE
    jr c, .morn_day
rept 4
    inc hl
endr
.morn_day
    ld de, UnknBGPals + 6 palettes + 2
    ld bc, 4
    ld a, $5
    call FarCopyWRAM
    ret

.TilesetColorsPointers:
    dw .OutdoorColors ; unused
    dw .OutdoorColors ; TOWN
    dw .OutdoorColors ; ROUTE
    dw .IndoorColors ; INDOOR
    dw .DungeonColors ; CAVE
    dw .Perm5Colors ; PERM_5
    dw .IndoorColors ; GATE
    dw .DungeonColors ; DUNGEON

; Valid indices: $00 - $29
.OutdoorColors:
    db $00, $01, $02, $28, $04, $05, $06, $07 ; morn
    db $08, $09, $0a, $28, $0c, $0d, $0e, $0f ; day
    db $10, $11, $12, $29, $14, $15, $16, $17 ; nite
    db $18, $19, $1a, $1b, $1c, $1d, $1e, $1f ; dark

.IndoorColors:
    db $20, $21, $22, $23, $24, $25, $26, $07 ; morn
    db $20, $21, $22, $23, $24, $25, $26, $07 ; day
    db $10, $11, $12, $13, $14, $15, $16, $07 ; nite
    db $18, $19, $1a, $1b, $1c, $1d, $1e, $07 ; dark

.DungeonColors:
    db $00, $01, $02, $03, $04, $05, $06, $07 ; morn
    db $08, $09, $0a, $0b, $0c, $0d, $0e, $0f ; day
    db $10, $11, $12, $13, $14, $15, $16, $17 ; nite
    db $18, $19, $1a, $1b, $1c, $1d, $1e, $1f ; dark

.Perm5Colors:
    db $00, $01, $02, $03, $04, $05, $06, $07 ; morn
    db $08, $09, $0a, $0b, $0c, $0d, $0e, $0f ; day
    db $10, $11, $12, $13, $14, $15, $16, $17 ; nite
    db $18, $19, $1a, $1b, $1c, $1d, $1e, $1f ; dark

Palette_b309: ; b309 mobile
    RGB 31, 31, 31
    RGB 31, 19, 24
    RGB 30, 10, 06
    RGB 00, 00, 00

Palette_b311: ; b311 not mobile
    RGB 31, 31, 31
    RGB 17, 19, 31
    RGB 14, 16, 31
    RGB 00, 00, 00

TilesetBGPalette:
INCLUDE "tilesets/bg.pal"

MapObjectPals::
INCLUDE "tilesets/ob.pal"

RoofPals:
INCLUDE "tilesets/roof.pal"

DiplomaPalettes:
    RGB 27, 31, 27
    RGB 21, 21, 21
    RGB 13, 13, 13
    RGB 00, 00, 00

    RGB 27, 31, 27
    RGB 31, 07, 06
    RGB 20, 02, 03
    RGB 00, 00, 00

    RGB 27, 31, 27
    RGB 10, 31, 09
    RGB 04, 14, 01
    RGB 00, 00, 00

    RGB 27, 31, 27
    RGB 08, 12, 31
    RGB 01, 04, 31
    RGB 00, 00, 00

    RGB 27, 31, 27
    RGB 31, 31, 07
    RGB 31, 16, 01
    RGB 00, 00, 00

    RGB 27, 31, 27
    RGB 22, 16, 08
    RGB 13, 07, 01
    RGB 00, 00, 00

    RGB 27, 31, 27
    RGB 15, 31, 31
    RGB 05, 17, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 11, 11, 19
    RGB 07, 07, 12
    RGB 00, 00, 00

Palettes_b681:
    RGB 27, 31, 27
    RGB 31, 19, 10
    RGB 31, 07, 04
    RGB 00, 00, 00

    RGB 27, 31, 27
    RGB 31, 19, 10
    RGB 10, 14, 20
    RGB 00, 00, 00

    RGB 27, 31, 27
    RGB 31, 19, 10
    RGB 31, 07, 04
    RGB 00, 00, 00

    RGB 27, 31, 27
    RGB 31, 19, 10
    RGB 31, 07, 04
    RGB 00, 00, 00

    RGB 27, 31, 27
    RGB 31, 19, 10
    RGB 31, 07, 04
    RGB 00, 00, 00

    RGB 27, 31, 27
    RGB 31, 19, 10
    RGB 31, 07, 04
    RGB 00, 00, 00

    RGB 27, 31, 27
    RGB 31, 19, 10
    RGB 31, 07, 04
    RGB 00, 00, 00

    RGB 27, 31, 27
    RGB 31, 19, 10
    RGB 31, 07, 04
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 21, 21, 21
    RGB 13, 13, 13
    RGB 07, 07, 07

    RGB 31, 31, 31
    RGB 31, 31, 07
    RGB 31, 16, 01
    RGB 07, 07, 07

    RGB 31, 31, 31
    RGB 31, 19, 24
    RGB 30, 10, 06
    RGB 07, 07, 07

    RGB 31, 31, 31
    RGB 12, 25, 01
    RGB 05, 14, 00
    RGB 07, 07, 07

    RGB 31, 31, 31
    RGB 08, 12, 31
    RGB 01, 04, 31
    RGB 07, 07, 07

    RGB 31, 31, 31
    RGB 24, 18, 07
    RGB 20, 15, 03
    RGB 07, 07, 07

Palettes_b6f1:
    RGB 31, 31, 31
    RGB 18, 23, 31
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 22, 00, 31
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 00, 00
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 25, 22, 00
    RGB 15, 20, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 23, 26, 31
    RGB 18, 23, 31
    RGB 00, 00, 00

Palettes_b719:
    RGB 31, 31, 31
    RGB 07, 06, 03
    RGB 07, 06, 03
    RGB 07, 06, 03

    RGB 31, 31, 31
    RGB 31, 31, 00
    RGB 26, 22, 00
    RGB 00, 00, 00

MalePokegearPals:
    RGB 28, 31, 20
    RGB 21, 21, 21
    RGB 13, 13, 13
    RGB 00, 00, 00

    RGB 28, 31, 20
    RGB 00, 31, 00
    RGB 00, 00, 31
    RGB 00, 00, 00

    RGB 28, 31, 20
    RGB 00, 31, 00
    RGB 15, 07, 00
    RGB 00, 00, 00

    RGB 28, 31, 20
    RGB 31, 15, 00
    RGB 15, 07, 00
    RGB 00, 00, 00

    RGB 28, 31, 20
    RGB 00, 31, 00
    RGB 00, 00, 31
    RGB 31, 00, 00

    RGB 28, 31, 20
    RGB 00, 31, 00
    RGB 15, 07, 00
    RGB 31, 00, 00

FemalePokegearPals:
    RGB 28, 31, 20
    RGB 21, 21, 21
    RGB 13, 13, 13
    RGB 00, 00, 00

    RGB 28, 31, 20
    RGB 00, 31, 00
    RGB 00, 00, 31
    RGB 00, 00, 00

    RGB 28, 31, 20
    RGB 00, 31, 00
    RGB 15, 07, 00
    RGB 00, 00, 00

    RGB 28, 31, 20
    RGB 10, 18, 31
    RGB 13, 06, 31
    RGB 00, 00, 00

    RGB 28, 31, 20
    RGB 00, 31, 00
    RGB 00, 00, 31
    RGB 31, 00, 00

    RGB 28, 31, 20
    RGB 00, 31, 00
    RGB 15, 07, 00
    RGB 31, 00, 00

Palettes_b789:
    RGB 31, 31, 31
    RGB 30, 22, 24
    RGB 18, 18, 18
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 10, 11, 31
    RGB 18, 18, 18
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 12, 31, 11
    RGB 18, 18, 18
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 29, 26, 05
    RGB 18, 18, 18
    RGB 00, 00, 00

Palettes_b7a9:
    RGB 31, 31, 31
    RGB 24, 25, 28
    RGB 24, 24, 09
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 30, 10, 06
    RGB 24, 24, 09
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 15, 31, 00
    RGB 24, 24, 09
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 15, 31
    RGB 24, 24, 09
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 15, 21, 31
    RGB 24, 24, 09
    RGB 00, 00, 00

    RGB 31, 31, 11
    RGB 31, 31, 06
    RGB 24, 24, 09
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 16, 19, 29
    RGB 25, 22, 00
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 21, 21, 21
    RGB 13, 13, 13
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 30, 10, 06
    RGB 31, 00, 00
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 12, 25, 01
    RGB 05, 14, 00
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 12, 25, 01
    RGB 30, 10, 06
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 31, 06
    RGB 20, 15, 03
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 31, 06
    RGB 15, 21, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 31, 06
    RGB 20, 15, 03
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 24, 21
    RGB 31, 13, 31
    RGB 00, 00, 00

    RGB 31, 31, 31
    RGB 31, 31, 31
    RGB 00, 00, 00
    RGB 00, 00, 00

This is the entirety of color.asm In the mean time I'm just going to work on the dex and maps but yeah kind of sucks the palettes won't show in battle. Been trying at this for months now and I just don't get it.

Offline

Board footer

Powered by FluxBB