shithub: pokecrystal

Download patch

ref: 0a244e043c83dff064d7e3ec054a587c7f999d0d
parent: 52605b764a6ecfb781ca9e70d51dad909dabe7c3
author: PikalaxALT <[email protected]>
date: Mon Oct 19 06:23:58 EDT 2015

Move battle start animation functions to its own file

--- a/battle/ai/items.asm
+++ b/battle/ai/items.asm
@@ -1,11 +1,11 @@
 AI_SwitchOrTryItem: ; 38000
 	and a
 
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	ret z
 
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	ret nz
 
@@ -731,7 +731,7 @@
 	callba Function3d57a
 	xor a
 	ld [wd264], a
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	ret nz
 	scf
--- a/battle/core.asm
+++ b/battle/core.asm
@@ -25,7 +25,7 @@
 .asm_3c021
 	ld a, d
 	ld [wBattleAction], a
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr z, .asm_3c031
 
@@ -34,7 +34,7 @@
 	jr z, .asm_3c04c
 
 .asm_3c031
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr z, .asm_3c047
 	xor a
@@ -97,7 +97,7 @@
 	call Function309d
 	call SetPlayerTurn
 	call SpikesDamage
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr z, .asm_3c0df
 	ld a, [$ffcb]
@@ -127,7 +127,7 @@
 	and $c0
 	add $2
 	ld [wd0ee], a
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	ld hl, BattleText_WildFled
 	jr z, .asm_3c115
@@ -438,7 +438,7 @@
 ; 3c300
 
 Function3c300: ; 3c300
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr z, .asm_3c30d
 	ld a, [wBattleAction]
@@ -456,7 +456,7 @@
 ; 3c314
 
 Function3c314: ; 3c314
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr z, .asm_3c35b
 	ld a, [wBattleAction]
@@ -778,7 +778,7 @@
 
 
 Function3c543: ; 3c543
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr nz, .Stay
 
@@ -1272,7 +1272,7 @@
 	xor a
 	ld [hli], a
 	ld [hl], a
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	ret z
 	ld hl, OTPartyMon1HP
@@ -1429,7 +1429,7 @@
 	jr z, .asm_3c99b
 	ld de, wc739
 	ld hl, wc735
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr z, .asm_3c99b
 	ld hl, OTPartyMon1PP
@@ -1518,7 +1518,7 @@
 	ld a, [hBattleTurn]
 	and a
 	jr z, .asm_3ca12
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr z, .asm_3ca14
 	call Function3df1f
@@ -1637,7 +1637,7 @@
 	xor a
 	ld [EnemyMonStatus], a
 
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr z, .asm_3caef
 	ld a, [CurOTMon]
@@ -2119,7 +2119,7 @@
 	ld c, 60
 	call DelayFrames
 
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr nz, .asm_3cd8c
 
@@ -2196,7 +2196,7 @@
 
 Function3ce01: ; 3ce01
 	call UpdateBattleMonInParty
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr z, .asm_3ce16
 	ld a, [CurOTMon]
@@ -2215,7 +2215,7 @@
 	ld [hl], a
 	call NewEnemyMonStatus
 	call BreakAttraction
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr z, .asm_3ce2f
 	jr .asm_3ce37
@@ -2240,7 +2240,7 @@
 	ld a, d
 	and a
 	ret z
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	call z, Function3d0ea
 	call EmptyBattleTextBox
@@ -2401,7 +2401,7 @@
 	call Function3e12e
 	call WaitBGMap
 	callba Function2c012
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr z, .asm_3cf6d
 	call Function3e8e4
@@ -2452,7 +2452,7 @@
 	ld a, $1
 	ld [wc6fd], a
 	ld [BattleEnded], a
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	ld a, b
 	call z, Function3d0ea
@@ -2461,7 +2461,7 @@
 	call StdBattleTextBox
 	call IsMobileBattle
 	jr z, .asm_3cff5
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	ret nz
 
@@ -2664,7 +2664,7 @@
 	call PlayMusic
 	call DelayFrame
 	ld de, MUSIC_WILD_VICTORY
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr nz, .asm_3d113
 	push de
@@ -2747,7 +2747,7 @@
 	db SABRINA
 	db BLAINE
 	db BLUE
-	db $ff
+	db -1
 
 
 Function3d14e: ; 3d14e
@@ -2768,7 +2768,7 @@
 	or [hl]
 	jr nz, .asm_3d185
 	call Function3ce01
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr nz, .asm_3d17f
 	ld a, $1
@@ -2842,7 +2842,7 @@
 Function3d1f8: ; 3d1f8
 	call EmptyBattleTextBox
 	call Function309d
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	and a
 	dec a
 	ret nz
@@ -2870,7 +2870,7 @@
 	call Function1d6e
 	call Function3d2f7
 	call ForcePickPartyMonInBattle
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr z, .asm_3d241
 	ld a, $1
@@ -2949,8 +2949,8 @@
 
 
 Function3d2e0: ; 3d2e0
-	ld a, [InLinkBattle]
-	cp $4
+	ld a, [wLinkMode]
+	cp LINK_MOBILE
 	jr nz, .asm_3d2ef ; It's not a mobile battle
 
 	ld a, [wcd2b]
@@ -2967,8 +2967,8 @@
 ; 3d2f1
 
 IsMobileBattle: ; 3d2f1
-	ld a, [InLinkBattle]
-	cp $4
+	ld a, [wLinkMode]
+	cp LINK_MOBILE
 	ret
 ; 3d2f7
 
@@ -3119,7 +3119,7 @@
 	ret
 
 .asm_3d3e3
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr nz, .LostLinkBattle
 
@@ -3337,7 +3337,7 @@
 ; 3d533
 
 Function3d533: ; 3d533
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr z, .asm_3d541
 
@@ -3630,7 +3630,7 @@
 	ld a, [PartyCount]
 	dec a
 	jp z, .asm_3d749
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jp nz, .asm_3d749
 	ld a, [Options]
@@ -3862,11 +3862,11 @@
 	cp BATTLETYPE_SUICUNE
 	jp z, .asm_3d98d
 
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jp nz, .asm_3d9a2
 
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jp nz, .asm_3d992
 
@@ -3979,7 +3979,7 @@
 	ret
 
 .asm_3d9a2
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	ld a, $2
 	jr z, .asm_3d9cf
@@ -4107,7 +4107,7 @@
 	bit SUBSTATUS_TRANSFORMED, a
 	ret z
 	ld hl, wc6f2
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	ret z
 	ld hl, OTPartyMon1DVs
@@ -4658,7 +4658,7 @@
 	call Function3df1f
 	xor a
 	ld [bc], a
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	ret z
 	ld [hl], $0
@@ -5127,7 +5127,7 @@
 	ld a, [InputType]
 	or a
 	jr z, .asm_3e171
-	callba Function1de294
+	callba _DudeAutoInput_DownA
 .asm_3e171
 
 	call LoadBattleMenu2
@@ -5183,7 +5183,7 @@
 ; 3e1c7
 
 BattleMenu_Pack: ; 3e1c7
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jp nz, ItemsCantBeUsed
 
@@ -5422,7 +5422,7 @@
 Function3e3ad: ; 3e3ad
 	ld a, 1
 	ld [wPlayerIsSwitching], a
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr z, .asm_3e3c1
 	call Function1d6e
@@ -5431,7 +5431,7 @@
 
 .asm_3e3c1
 	call Function3e7c1
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr nz, .asm_3e3cf
 
@@ -5650,7 +5650,7 @@
 	dec a
 	ld b, $c3
 	jr z, .asm_3e569
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr nz, .asm_3e569
 	ld b, $c7
@@ -5960,8 +5960,8 @@
 
 Function3e75f: ; 3e75f
 	hlcoord 5, 11
-	ld a, [InLinkBattle]
-	cp $4
+	ld a, [wLinkMode] ; What's the point of this check?
+	cp LINK_MOBILE
 	jr c, .ok
 	hlcoord 5, 11
 .ok
@@ -6034,7 +6034,7 @@
 	ld a, [wEnemyIsSwitching]
 	and a
 	ret nz
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr z, .asm_3e817
 	call EmptyBattleTextBox
@@ -6108,7 +6108,7 @@
 	jr .asm_3e8bd
 
 .asm_3e84f
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr nz, .asm_3e882
 .asm_3e855
@@ -6222,7 +6222,7 @@
 	call ByteFill
 
 ; We don't need to be here if we're in a link battle
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jp nz, Function3dabd
 
@@ -6244,7 +6244,7 @@
 ; Let's get the item:
 
 ; Is the item predetermined?
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr z, .WildItem
 
@@ -6293,7 +6293,7 @@
 ; Initialize DVs
 
 ; If we're in a trainer battle, DVs are predetermined
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	and a
 	jr z, .InitDVs
 
@@ -6320,7 +6320,7 @@
 ; See GetTrainerDVs for more on that
 	callba GetTrainerDVs
 ; These are the DVs we'll use if we're actually in a trainer battle
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr nz, .UpdateDVs
 
@@ -6396,7 +6396,7 @@
 
 
 ; We've still got more to do if we're dealing with a wild monster
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr nz, .Happiness
 
@@ -6496,7 +6496,7 @@
 
 ; If we're in a trainer battle,
 ; get the rest of the parameters from the party struct
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	cp a, TRAINER_BATTLE
 	jr z, .OpponentParty
 
@@ -6586,7 +6586,7 @@
 ; Get moves
 	ld de, EnemyMonMoves
 ; Are we in a trainer battle?
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	cp a, TRAINER_BATTLE
 	jr nz, .WildMoves
 ; Then copy moves from the party struct
@@ -6613,7 +6613,7 @@
 
 .PP
 ; Trainer battle?
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	cp a, TRAINER_BATTLE
 	jr z, .TrainerPP
 
@@ -6657,7 +6657,7 @@
 	call GetPokemonName
 
 ; Did we catch it?
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	and a
 	ret z
 
@@ -6725,7 +6725,7 @@
 	db EXEGGCUTE
 	db LEDYBA
 	db AIPOM
-	db $ff ; end
+	db -1 ; end
 
 .Day
 	db VENONAT
@@ -6733,7 +6733,7 @@
 	db NOCTOWL
 	db SPINARAK
 	db HERACROSS
-	db $ff ; end
+	db -1 ; end
 
 .Morn
 	db VENONAT
@@ -6741,7 +6741,7 @@
 	db NOCTOWL
 	db SPINARAK
 	db HERACROSS
-	db $ff ; end
+	db -1 ; end
 ; 3eb75
 
 
@@ -7116,7 +7116,7 @@
 
 ; The boosted stats are in order, except PlainBadge and MineralBadge's boosts are swapped.
 
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	ret nz
 
@@ -7237,7 +7237,7 @@
 ; To circumvent this a shared PRNG is used instead.
 
 ; But if we're in a non-link battle we're safe to use it
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jp z, Random
 
@@ -7338,7 +7338,7 @@
 
 Function3ee3b: ; 3ee3b
 ; Give experience.
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	ret nz
 
@@ -7452,7 +7452,7 @@
 
 .asm_3eee2
 	ld [StringBuffer2 + 2], a
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	call nz, DoubleExp
 	push bc
@@ -7977,7 +7977,7 @@
 
 
 SendOutPkmnText: ; 3f26d
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr z, .asm_3f27c
 
@@ -8446,7 +8446,7 @@
 	ld bc, 4 << 8 + 10
 	call ClearBox
 	call ClearSprites
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	cp $1
 	call z, UpdateEnemyHUD
 	ld a, $1
@@ -8521,10 +8521,10 @@
 	hlcoord 12, 0
 	lb bc, 7, 7
 	predef FillBox
-	ld a, $ff
+	ld a, -1
 	ld [CurOTMon], a
 	ld a, TRAINER_BATTLE
-	ld [IsInBattle], a
+	ld [wBattleMode], a
 
 	call IsJohtoGymLeader
 	jr nc, .done
@@ -8554,7 +8554,7 @@
 
 Function3f607: ; 3f607
 	ld a, $1
-	ld [IsInBattle], a
+	ld [wBattleMode], a
 	callba Function10605d
 	call LoadEnemyMon
 	ld hl, EnemyMonMoves
@@ -8647,7 +8647,7 @@
 ; 3f6a5
 
 Function3f6a5: ; 3f6a5
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr z, .asm_3f6b7
 	call Function3f759
@@ -8672,7 +8672,7 @@
 	call Function3f998
 	xor a
 	ld [Danger], a
-	ld [IsInBattle], a
+	ld [wBattleMode], a
 	ld [BattleType], a
 	ld [AttackMissed], a
 	ld [TempWildMonSpecies], a
@@ -8830,8 +8830,8 @@
 
 
 Function3f830: ; 3f830
-	ld a, [InLinkBattle]
-	cp $4
+	ld a, [wLinkMode]
+	cp LINK_MOBILE
 	ret
 ; 3f836
 
@@ -9478,7 +9478,7 @@
 
 
 BattleStartMessage: ; 3fc8b
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr z, .asm_3fcaa
 
--- a/battle/effect_commands.asm
+++ b/battle/effect_commands.asm
@@ -12,7 +12,7 @@
 DoEnemyTurn: ; 3400a
 	call SetEnemyTurn
 
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr z, DoTurn
 
@@ -696,7 +696,7 @@
 
 	; No obedience in link battles
 	; (since no handling exists for enemy)
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	ret nz
 
@@ -1080,7 +1080,7 @@
 	jr z, .asm_345a4
 
 ; skip this part entirely if wildbattle
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr z, .asm_345c5
 
@@ -3521,7 +3521,7 @@
 	inc l
 
 .asm_3536b
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp 3
 	jr z, .done
 
@@ -3835,11 +3835,11 @@
 	sub b
 	ld [DefaultFlypoint], a
 .asm_3550d
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr z, .asm_3556b
 
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr nz, .asm_35532
 
@@ -4825,7 +4825,7 @@
 
 	call Function372d8
 
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr z, .asm_35a83
 	call AnimateFailedMove
@@ -4888,7 +4888,7 @@
 	ld a, [hBattleTurn]
 	and a
 	jr z, .asm_35af6
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr nz, .asm_35af6
 	ld a, [hl]
@@ -5180,7 +5180,7 @@
 	ld a, [hBattleTurn]
 	and a
 	jr nz, .asm_35c81
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr nz, .asm_35c81
 	ld hl, wc739
@@ -5585,7 +5585,7 @@
 	jr z, .asm_35eec
 
 	; Not in link battle
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr nz, .asm_35eec
 
@@ -5683,7 +5683,7 @@
 	and a
 	jr z, .asm_35f89
 
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr nz, .asm_35f89
 
@@ -6331,7 +6331,7 @@
 	and a
 	jr z, .DidntMiss
 
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr nz, .DidntMiss
 
@@ -7124,7 +7124,7 @@
 	ld a, [hBattleTurn]
 	and a
 	jr nz, .asm_367bf
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr nz, .failed
 	ld a, [CurPartyLevel]
@@ -7149,7 +7149,7 @@
 	jp PrintButItFailed
 
 .asm_367bf
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr nz, .failed
 	ld a, [BattleMonLevel]
@@ -7214,7 +7214,7 @@
 	ld a, [AttackMissed]
 	and a
 	jr nz, .asm_36852 ; 36830 $20
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr nz, .asm_36869 ; 36836 $31
 	ld a, [CurPartyLevel]
@@ -7300,7 +7300,7 @@
 	and a
 	jr nz, .asm_368f3
 
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr nz, .asm_36908
 
@@ -7496,7 +7496,7 @@
 	dec a
 	jr .asm_36a3a
 .asm_36a0b
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	cp $1
 	jp z, .asm_36a1e
 	ld a, [OTPartyCount]
@@ -8177,7 +8177,7 @@
 	and a
 	jr z, .asm_36e0e
 
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr nz, .asm_36e0e
 
@@ -9281,7 +9281,7 @@
 	and a
 	jr z, .party
 
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr z, .done
 
@@ -9493,7 +9493,7 @@
 BattleCommand61: ; 37874
 ; present
 
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp $3
 	jr z, .asm_3787d
 	push bc
@@ -9502,7 +9502,7 @@
 
 	call BattleCommand07
 
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp $3
 	jr z, .asm_37889
 	pop de
@@ -9765,7 +9765,7 @@
 .Enemy
 
 ; Wildmons don't have anything to switch to
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a ; WILDMON
 	jp z, FailedBatonPass
 
@@ -9800,7 +9800,7 @@
 
 
 BatonPass_LinkPlayerSwitch: ; 37a67
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	ret z
 
@@ -9819,7 +9819,7 @@
 
 
 BatonPass_LinkEnemySwitch: ; 37a82
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	ret z
 
@@ -10057,7 +10057,7 @@
 	jr z, .Full
 
 ; Don't factor in time of day in link battles.
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr nz, .Weather
 
--- a/battle/effects/thief.asm
+++ b/battle/effects/thief.asm
@@ -30,11 +30,11 @@
 	and a
 	ret nz
 
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr z, .stealenemyitem
 
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	ret z
 
--- a/battle/misc.asm
+++ b/battle/misc.asm
@@ -161,7 +161,7 @@
 
 
 DoBadgeTypeBoosts: ; fbe24
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	ret nz
 
--- a/constants/battle_constants.asm
+++ b/constants/battle_constants.asm
@@ -315,3 +315,32 @@
 	const EFFECT_BEAT_UP
 	const EFFECT_FLY
 	const EFFECT_DEFENSE_CURL
+
+; Battle vars used in home/battle.asm
+	const_def
+	const PLAYER_SUBSTATUS_1
+	const ENEMY_SUBSTATUS_1
+	const PLAYER_SUBSTATUS_2
+	const ENEMY_SUBSTATUS_2
+	const PLAYER_SUBSTATUS_3
+	const ENEMY_SUBSTATUS_3
+	const PLAYER_SUBSTATUS_4
+	const ENEMY_SUBSTATUS_4
+	const PLAYER_SUBSTATUS_5
+	const ENEMY_SUBSTATUS_5
+	const PLAYER_STATUS
+	const ENEMY_STATUS
+	const PLAYER_MOVE_ANIMATION
+	const ENEMY_MOVE_ANIMATION
+	const PLAYER_MOVE_EFFECT
+	const ENEMY_MOVE_EFFECT
+	const PLAYER_MOVE_POWER
+	const ENEMY_MOVE_POWER
+	const PLAYER_MOVE_TYPE
+	const ENEMY_MOVE_TYPE
+	const PLAYER_CUR_MOVE
+	const ENEMY_CUR_MOVE
+	const PLAYER_COUNTER_MOVE
+	const ENEMY_COUNTER_MOVE
+	const PLAYER_LAST_MOVE
+	const ENEMY_LAST_MOVE
--- /dev/null
+++ b/engine/battle_start.asm
@@ -1,0 +1,872 @@
+Predef_StartBattle: ; 8c20f
+	call Function8c26d
+	ld a, [rBGP]
+	ld [wcfc7], a
+	ld a, [rOBP0]
+	ld [wcfc8], a
+	ld a, [rOBP1]
+	ld [wcfc9], a
+	call DelayFrame
+	ld hl, hVBlank
+	ld a, [hl]
+	push af
+	ld [hl], $1
+
+.loop
+	ld a, [wcf63]
+	bit 7, a
+	jr nz, .done
+	call FlashyTransitionToBattle
+	call DelayFrame
+	jr .loop
+
+.done
+	ld a, [rSVBK]
+	push af
+	ld a, $5
+	ld [rSVBK], a
+
+	ld hl, Unkn1Pals
+	ld bc, $0040
+	xor a
+	call ByteFill
+
+	pop af
+	ld [rSVBK], a
+
+	ld a, %11111111
+	ld [wcfc7], a
+	call DmgToCgbBGPals
+	call DelayFrame
+	xor a
+	ld [hLCDStatCustom], a
+	ld [hLCDStatCustom + 1], a
+	ld [hLCDStatCustom + 2], a
+	ld [hSCY], a
+
+	ld a, $1
+	ld [rSVBK], a
+	pop af
+	ld [hVBlank], a
+	call DelayFrame
+	ret
+; 8c26d
+
+Function8c26d: ; 8c26d
+	ld a, [wLinkMode]
+	cp LINK_MOBILE
+	jr z, .mobile
+	callba Function6454
+	call UpdateSprites
+	call DelayFrame
+	call Function8c2a0
+	call Function8cf4f
+	jr .resume
+
+.mobile
+	call LoadTrainerBattlePokeballTiles
+
+.resume
+	ld a, SCREEN_HEIGHT_PX
+	ld [hWY], a
+	call DelayFrame
+	xor a
+	ld [hBGMapMode], a
+	ld hl, wcf63
+	xor a
+rept 2
+	ld [hli], a
+endr
+	ld [hl], a
+	call WipeLYOverrides
+	ret
+; 8c2a0
+
+Function8c2a0: ; 8c2a0
+	call LoadTrainerBattlePokeballTiles
+	ld hl, VBGMap0
+	call Function8c2cf
+	ret
+; 8c2aa
+
+LoadTrainerBattlePokeballTiles:
+; Load the tiles used in the Pokeball Graphic that fills the screen
+; at the start of every Trainer battle.
+	ld de, TrainerBattlePokeballTiles
+	ld hl, VTiles1 tile $7e
+	ld b, BANK(TrainerBattlePokeballTiles)
+	ld c, 2
+	call Request2bpp
+
+	ld a, [rVBK]
+	push af
+	ld a, $1
+	ld [rVBK], a
+
+	ld de, TrainerBattlePokeballTiles
+	ld hl, VTiles4 tile $7e
+	ld b, BANK(TrainerBattlePokeballTiles)
+	ld c, 2
+	call Request2bpp
+
+	pop af
+	ld [rVBK], a
+	ret
+; 8c2cf
+
+Function8c2cf: ; 8c2cf
+	ld a, [rSVBK]
+	push af
+	ld a, $6
+	ld [rSVBK], a
+	push hl
+	ld hl, w6_d000
+	ld bc, $28 * $10
+
+.loop
+	ld [hl], -1
+	inc hl
+	dec bc
+	ld a, c
+	or b
+	jr nz, .loop
+
+	pop hl
+	ld de, w6_d000
+	ld b, BANK(Function8c2cf) ; BANK(@)
+	ld c, $28
+	call Request2bpp
+	pop af
+	ld [rSVBK], a
+	ret
+; 8c2f4
+
+TrainerBattlePokeballTiles: ; 8c2f4
+INCBIN "gfx/overworld/trainer_battle_pokeball_tiles.2bpp"
+
+
+FlashyTransitionToBattle: ; 8c314
+	ld a, [wcf63]
+	ld e, a
+	ld d, 0
+	ld hl, .jumptable
+rept 2
+	add hl, de
+endr
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+	jp [hl]
+; 8c323
+
+.jumptable: ; 8c323 (23:4323)
+	dw StartTrainerBattle_DetermineWhichAnimation ; 00
+
+	; Animation 1: cave
+	dw StartTrainerBattle_LoadPokeBallGraphics ; 01
+	dw StartTrainerBattle_SetUpBGMap ; 02
+	dw StartTrainerBattle_Flash ; 03
+	dw StartTrainerBattle_Flash ; 04
+	dw StartTrainerBattle_Flash ; 05
+	dw StartTrainerBattle_NextScene ; 06
+	dw StartTrainerBattle_SetUpForWavyOutro ; 07
+	dw StartTrainerBattle_SineWave ; 08
+
+	; Animation 2: cave, stronger
+	dw StartTrainerBattle_LoadPokeBallGraphics ; 09
+	dw StartTrainerBattle_SetUpBGMap ; 0a
+	dw StartTrainerBattle_Flash ; 0b
+	dw StartTrainerBattle_Flash ; 0c
+	dw StartTrainerBattle_Flash ; 0d
+	dw StartTrainerBattle_NextScene ; 0e
+	; There is no setup for this one
+	dw StartTrainerBattle_ZoomToBlack ; 0f
+
+	; Animation 3: no cave
+	dw StartTrainerBattle_LoadPokeBallGraphics ; 10
+	dw StartTrainerBattle_SetUpBGMap ; 11
+	dw StartTrainerBattle_Flash ; 12
+	dw StartTrainerBattle_Flash ; 13
+	dw StartTrainerBattle_Flash ; 14
+	dw StartTrainerBattle_NextScene ; 15
+	dw StartTrainerBattle_SetUpForSpinOutro ; 16
+	dw StartTrainerBattle_SpinToBlack ; 17
+
+	; Animation 4: no cave, stronger
+	dw StartTrainerBattle_LoadPokeBallGraphics ; 18
+	dw StartTrainerBattle_SetUpBGMap ; 19
+	dw StartTrainerBattle_Flash ; 1a
+	dw StartTrainerBattle_Flash ; 1b
+	dw StartTrainerBattle_Flash ; 1c
+	dw StartTrainerBattle_NextScene ; 1d
+	dw StartTrainerBattle_SetUpForRandomScatterOutro ; 1e
+	dw StartTrainerBattle_SpeckleToBlack ; 1f
+
+	; All animations jump to here.
+	dw StartTrainerBattle_Finish ; 20
+
+
+StartTrainerBattle_DetermineWhichAnimation: ; 8c365 (23:4365)
+; The screen flashes a different number of
+; times depending on the level of your lead
+; Pokemon relative to the opponent's.
+	ld de, 0
+	ld a, [BattleMonLevel]
+	add 3
+	ld hl, EnemyMonLevel
+	cp [hl]
+	jr nc, .okay
+	set 0, e
+.okay
+	ld a, [wPermission]
+	cp CAVE
+	jr z, .okay2
+	cp PERM_5
+	jr z, .okay2
+	cp DUNGEON
+	jr z, .okay2
+	set 1, e
+.okay2
+	ld hl, .StartingPoints
+	add hl, de
+	ld a, [hl]
+	ld [wcf63], a
+	ret
+; 8c38f (23:438f)
+
+.StartingPoints: ; 8c38f
+	db 1,  9
+	db 16, 24
+; 8c393
+
+StartTrainerBattle_Finish: ; 8c393 (23:4393)
+	call ClearSprites
+	ld a, $80
+	ld [wcf63], a
+	ret
+
+StartTrainerBattle_NextScene: ; 8c39c (23:439c)
+	ld hl, wcf63
+	inc [hl]
+	ret
+
+StartTrainerBattle_SetUpBGMap: ; 8c3a1 (23:43a1)
+	call StartTrainerBattle_NextScene
+	xor a
+	ld [wcf64], a
+	ld [hBGMapMode], a ; $ff00+$d4
+	ret
+
+StartTrainerBattle_Flash: ; 8c3ab (23:43ab)
+	call .DoFlashAnimation
+	ret nc
+	call StartTrainerBattle_NextScene
+	ret
+
+.DoFlashAnimation: ; 8c3b3 (23:43b3)
+	ld a, [wd847]
+	cp -1
+	jr z, .done
+	ld hl, wcf64
+	ld a, [hl]
+	inc [hl]
+	srl a
+	ld e, a
+	ld d, 0
+	ld hl, .pals
+	add hl, de
+	ld a, [hl]
+	cp %00000001
+	jr z, .done
+	ld [wcfc7], a
+	call DmgToCgbBGPals
+	and a
+	ret
+
+.done
+	xor a
+	ld [wcf64], a
+	scf
+	ret
+; 8c3db (23:43db)
+
+.pals: ; 8c3db
+	db %11111001 ; 3321
+	db %11111110 ; 3332
+	db %11111111 ; 3333
+	db %11111110 ; 3332
+	db %11111001 ; 3321
+	db %11100100 ; 3210
+	db %10010000 ; 2100
+	db %01000000 ; 1000
+	db %00000000 ; 0000
+	db %01000000 ; 1000
+	db %10010000 ; 2100
+	db %11100100 ; 3210
+	db %00000001 ; 0001
+; 8c3e8
+
+StartTrainerBattle_SetUpForWavyOutro: ; 8c3e8 (23:43e8)
+	callba Function5602
+	ld a, $5
+	ld [rSVBK], a ; $ff00+$70
+	call StartTrainerBattle_NextScene
+	ld a, $43
+	ld [hLCDStatCustom], a ; $ff00+$c6
+	xor a
+	ld [hLCDStatCustom + 1], a
+	ld a, $90
+	ld [hLCDStatCustom + 2], a
+	xor a
+	ld [wcf64], a
+	ld [wcf65], a
+	ret
+
+StartTrainerBattle_SineWave: ; 8c408 (23:4408)
+	ld a, [wcf64]
+	cp $60
+	jr nc, .end
+	call .DoSineWave
+	ret
+
+.end
+	ld a, $20
+	ld [wcf63], a
+	ret
+
+.DoSineWave: ; 8c419 (23:4419)
+	ld hl, wcf65
+	ld a, [hl]
+	inc [hl]
+	ld hl, wcf64
+	ld d, [hl]
+	add [hl]
+	ld [hl], a
+	ld a, $90
+	ld bc, wd100
+	ld e, $0
+
+.loop
+	push af
+	push de
+	ld a, e
+	call StartTrainerBattle_DrawSineWave
+	ld [bc], a
+	inc bc
+	pop de
+	ld a, e
+	add $2
+	ld e, a
+	pop af
+	dec a
+	jr nz, .loop
+	ret
+
+StartTrainerBattle_SetUpForSpinOutro: ; 8c43d (23:443d)
+	callba Function5602
+	ld a, $5
+	ld [rSVBK], a ; $ff00+$70
+	call StartTrainerBattle_NextScene
+	xor a
+	ld [wcf64], a
+	ret
+
+spintable_entry: MACRO
+	db \1
+	dw .wedge\2
+	dwcoord \3, \4
+ENDM
+
+; quadrants
+	const_def
+	const UPPER_LEFT
+	const UPPER_RIGHT
+	const LOWER_LEFT
+	const LOWER_RIGHT
+
+StartTrainerBattle_SpinToBlack: ; 8c44f (23:444f)
+	xor a
+	ld [hBGMapMode], a ; $ff00+$d4
+	ld a, [wcf64]
+	ld e, a
+	ld d, 0
+	ld hl, .spintable
+rept 5
+	add hl, de
+endr
+	ld a, [hli]
+	cp -1
+	jr z, .end
+	ld [wcf65], a
+	call .load
+	ld a, $1
+	ld [hBGMapMode], a ; $ff00+$d4
+	call DelayFrame
+	call DelayFrame
+	ld hl, wcf64
+	inc [hl]
+	ret
+
+.end
+	ld a, $1
+	ld [hBGMapMode], a ; $ff00+$d4
+	call DelayFrame
+	call DelayFrame
+	call DelayFrame
+	xor a
+	ld [hBGMapMode], a ; $ff00+$d4
+	ld a, $20
+	ld [wcf63], a
+	ret
+; 8c490 (23:4490)
+
+.spintable: ; 8c490
+	spintable_entry UPPER_LEFT,  1,  1,  6
+	spintable_entry UPPER_LEFT,  2,  0,  3
+	spintable_entry UPPER_LEFT,  3,  1,  0
+	spintable_entry UPPER_LEFT,  4,  5,  0
+	spintable_entry UPPER_LEFT,  5,  9,  0
+	spintable_entry UPPER_RIGHT, 5, 10,  0
+	spintable_entry UPPER_RIGHT, 4, 14,  0
+	spintable_entry UPPER_RIGHT, 3, 18,  0
+	spintable_entry UPPER_RIGHT, 2, 19,  3
+	spintable_entry UPPER_RIGHT, 1, 18,  6
+	spintable_entry LOWER_RIGHT, 1, 18, 11
+	spintable_entry LOWER_RIGHT, 2, 19, 14
+	spintable_entry LOWER_RIGHT, 3, 18, 17
+	spintable_entry LOWER_RIGHT, 4, 14, 17
+	spintable_entry LOWER_RIGHT, 5, 10, 17
+	spintable_entry LOWER_LEFT,  5,  9, 17
+	spintable_entry LOWER_LEFT,  4,  5, 17
+	spintable_entry LOWER_LEFT,  3,  1, 17
+	spintable_entry LOWER_LEFT,  2,  0, 14
+	spintable_entry LOWER_LEFT,  1,  1, 11
+	db -1
+; 8c4f5
+
+.load: ; 8c4f5 (23:44f5)
+	ld a, [hli]
+	ld e, a
+	ld a, [hli]
+	ld d, a
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+.loop
+	push hl
+	ld a, [de]
+	ld c, a
+	inc de
+.loop1
+	ld [hl], $ff
+	ld a, [wcf65]
+	bit 0, a
+	jr z, .leftside
+	inc hl
+	jr .okay1
+.leftside
+	dec hl
+.okay1
+	dec c
+	jr nz, .loop1
+	pop hl
+	ld a, [wcf65]
+	bit 1, a
+	ld bc, SCREEN_WIDTH
+	jr z, .upper
+	ld bc, -SCREEN_WIDTH
+.upper
+	add hl, bc
+	ld a, [de]
+	inc de
+	cp -1
+	ret z
+	and a
+	jr z, .loop
+	ld c, a
+.loop2
+	ld a, [wcf65]
+	bit 0, a
+	jr z, .leftside2
+	dec hl
+	jr .okay2
+.leftside2
+	inc hl
+.okay2
+	dec c
+	jr nz, .loop2
+	jr .loop
+; 8c538 (23:4538)
+
+.wedge1: db 2, 3, 5, 4, 9, -1
+.wedge2: db 1, 1, 2, 2, 4, 2, 4, 2, 3, -1
+.wedge3: db 2, 1, 3, 1, 4, 1, 4, 1, 4, 1, 3, 1, 2, 1, 1, 1, 1, -1
+.wedge4: db 4, 1, 4, 0, 3, 1, 3, 0, 2, 1, 2, 0, 1, -1
+.wedge5: db 4, 0, 3, 0, 3, 0, 2, 0, 2, 0, 1, 0, 1, 0, 1, -1
+; 8c578
+
+StartTrainerBattle_SetUpForRandomScatterOutro: ; 8c578 (23:4578)
+	callba Function5602
+	ld a, $5
+	ld [rSVBK], a ; $ff00+$70
+	call StartTrainerBattle_NextScene
+	ld a, $10
+	ld [wcf64], a
+	ld a, $1
+	ld [hBGMapMode], a ; $ff00+$d4
+	ret
+
+StartTrainerBattle_SpeckleToBlack: ; 8c58f (23:458f)
+	ld hl, wcf64
+	ld a, [hl]
+	and a
+	jr z, .done
+	dec [hl]
+	ld c, $c
+.loop
+	push bc
+	call .BlackOutRandomTile
+	pop bc
+	dec c
+	jr nz, .loop
+	ret
+
+.done
+	ld a, $1
+	ld [hBGMapMode], a ; $ff00+$d4
+	call DelayFrame
+	call DelayFrame
+	call DelayFrame
+	xor a
+	ld [hBGMapMode], a ; $ff00+$d4
+	ld a, $20
+	ld [wcf63], a
+	ret
+
+.BlackOutRandomTile: ; 8c5b8 (23:45b8)
+.y_loop
+	call Random
+	cp SCREEN_HEIGHT
+	jr nc, .y_loop
+	ld b, a
+
+.x_loop
+	call Random
+	cp SCREEN_WIDTH
+	jr nc, .x_loop
+	ld c, a
+
+	hlcoord 0, -1
+	ld de, SCREEN_WIDTH
+	inc b
+
+.row_loop
+	add hl, de
+	dec b
+	jr nz, .row_loop
+	add hl, bc
+
+; If the tile has already been blacked out,
+; sample a new tile
+	ld a, [hl]
+	cp $ff
+	jr z, .y_loop
+	ld [hl], $ff
+	ret
+
+StartTrainerBattle_LoadPokeBallGraphics: ; 8c5dc (23:45dc)
+	ld a, [OtherTrainerClass]
+	and a
+	jp z, .nextscene
+
+	xor a
+	ld [hBGMapMode], a ; $ff00+$d4
+	hlcoord 0, 0, AttrMap
+	ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
+	inc b
+	inc c
+	jr .enter_loop_midway
+
+.loop
+	ld a, [hl]
+	or %00000111
+	ld [hli], a
+.enter_loop_midway
+	dec c
+	jr nz, .loop
+	dec b
+	jr nz, .loop
+
+	call .loadpokeballgfx ; load a, [OtherTrainerClass] \ ld de, PokeBallTransition
+	hlcoord 2, 1
+
+	ld b, SCREEN_WIDTH - 4
+.loop2
+	push hl
+	ld c, 2
+.loop3
+	push hl
+	ld a, [de]
+	inc de
+.loop4
+; Loading is done bit by bit
+	and a
+	jr z, .done
+	sla a
+	jr nc, .no_load
+	ld [hl], $fe ; "8"
+.no_load
+	inc hl
+	jr .loop4
+
+.done
+	pop hl
+	push bc
+	ld bc, (SCREEN_WIDTH - 4) / 2
+	add hl, bc
+	pop bc
+	dec c
+	jr nz, .loop3
+
+	pop hl
+	push bc
+	ld bc, SCREEN_WIDTH
+	add hl, bc
+	pop bc
+	dec b
+	jr nz, .loop2
+
+	ld a, [hCGB] ; $ff00+$e6
+	and a
+	jr nz, .cgb
+	ld a, $1
+	ld [hBGMapMode], a ; $ff00+$d4
+	call DelayFrame
+	call DelayFrame
+	jr .nextscene
+
+.cgb
+	ld hl, .daypals
+	ld a, [TimeOfDayPal]
+	and (1 << 2) - 1
+	cp 3
+	jr nz, .daytime
+	ld hl, .nightpals
+.daytime
+	ld a, [rSVBK] ; $ff00+$70
+	push af
+	ld a, $5 ; WRAM5 = palettes
+	ld [rSVBK], a ; $ff00+$70
+	call .copypals
+	push hl
+	ld de, Unkn1Pals + 8 * 7
+	ld bc, $8
+	call CopyBytes
+	pop hl
+	ld de, BGPals + 8 * 7
+	ld bc, $8
+	call CopyBytes
+	pop af
+	ld [rSVBK], a ; $ff00+$70
+	ld a, $1
+	ld [hCGBPalUpdate], a ; $ff00+$e5
+	call DelayFrame
+	call Function8cf4f
+
+.nextscene: ; 8c673 (23:4673)
+	call StartTrainerBattle_NextScene
+	ret
+
+.copypals: ; 8c677 (23:4677)
+	ld de, Unkn1Pals + 8 * 7
+	call .copy
+	ld de, BGPals + 8 * 7
+	call .copy
+	ld de, Unkn2Pals + 8 * 6
+	call .copy
+	ld de, OBPals + 8 * 6
+	call .copy
+	ld de, Unkn2Pals + 8 * 7
+	call .copy
+	ld de, OBPals + 8 * 7
+
+.copy: ; 8c698 (23:4698)
+	push hl
+	ld bc, $8
+	call CopyBytes
+	pop hl
+	ret
+; 8c6a1 (23:46a1)
+
+.daypals: ; 8c6a1
+	RGB 31, 18, 29
+	RGB 31, 11, 15
+	RGB 31, 05, 05
+	RGB 07, 07, 07
+; 8c6a9
+
+.nightpals: ; 8c6a9
+	RGB 31, 18, 29
+	RGB 31, 05, 05
+	RGB 31, 05, 05
+	RGB 31, 05, 05
+
+.loadpokeballgfx:
+	ld a, [OtherTrainerClass]
+	ld de, PokeBallTransition
+	ret
+
+PokeBallTransition:
+	db %00000011, %11000000
+	db %00001111, %11110000
+	db %00111100, %00111100
+	db %00110000, %00001100
+	db %01100000, %00000110
+	db %01100011, %11000110
+	db %11000110, %01100011
+	db %11111100, %00111111
+	db %11111100, %00111111
+	db %11000110, %01100011
+	db %01100011, %11000110
+	db %01100000, %00000110
+	db %00110000, %00001100
+	db %00111100, %00111100
+	db %00001111, %11110000
+	db %00000011, %11000000
+
+WipeLYOverrides: ; 8c6d8
+	ld a, [rSVBK]
+	push af
+	ld a, $5
+	ld [rSVBK], a
+	ld hl, LYOverrides
+	call .wipe
+	ld hl, LYOverridesBackup
+	call .wipe
+	pop af
+	ld [rSVBK], a
+	ret
+; 8c6ef
+
+.wipe: ; 8c6ef
+	xor a
+	ld c, SCREEN_HEIGHT_PX
+.loop
+	ld [hli], a
+	dec c
+	jr nz, .loop
+	ret
+; 8c6f7
+
+
+StartTrainerBattle_DrawSineWave: ; 8c6f7 (23:46f7)
+	and (1 << 6) - 1
+	cp 1 << 5
+	jr nc, .okay
+	call .DoSineWave
+	ld a, h
+	ret
+
+.okay
+	and (1 << 5) - 1
+	call .DoSineWave
+	ld a, h
+	xor -1 ; cpl
+	inc a
+	ret
+
+.DoSineWave: ; 8c70c (23:470c)
+	ld e, a
+	ld a, d
+	ld d, 0
+	ld hl, .sinewave
+rept 2
+	add hl, de
+endr
+	ld e, [hl]
+	inc hl
+	ld d, [hl]
+	ld hl, 0
+.loop
+	srl a
+	jr nc, .skip
+	add hl, de
+.skip
+	sla e
+	rl d
+	and a
+	jr nz, .loop
+	ret
+; 8c728 (23:4728)
+
+.sinewave: ; 8c728
+	sine_wave $100
+; 8c768
+
+zoombox: macro
+; width, height, start y, start x
+	db \1, \2
+	dwcoord \3, \4
+endm
+
+StartTrainerBattle_ZoomToBlack: ; 8c768 (23:4768)
+	callba Function5602
+	ld de, .boxes
+
+.loop
+	ld a, [de]
+	cp -1
+	jr z, .done
+	inc de
+	ld c, a
+	ld a, [de]
+	inc de
+	ld b, a
+	ld a, [de]
+	inc de
+	ld l, a
+	ld a, [de]
+	inc de
+	ld h, a
+	xor a
+	ld [hBGMapMode], a ; $ff00+$d4
+	call .Copy
+	call WaitBGMap
+	jr .loop
+
+.done
+	ld a, $20
+	ld [wcf63], a
+	ret
+; 8c792 (23:4792)
+
+.boxes: ; 8c792
+	zoombox  4,  2,  8, 8
+	zoombox  6,  4,  7, 7
+	zoombox  8,  6,  6, 6
+	zoombox 10,  8,  5, 5
+	zoombox 12, 10,  4, 4
+	zoombox 14, 12,  3, 3
+	zoombox 16, 14,  2, 2
+	zoombox 18, 16,  1, 1
+	zoombox 20, 18,  0, 0
+	db -1
+; 8c7b7
+
+.Copy: ; 8c7b7 (23:47b7)
+	ld a, $ff
+.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
+; 8c7c9 (23:47c9)
--- a/engine/events.asm
+++ b/engine/events.asm
@@ -506,7 +506,7 @@
 ; 9693a
 
 Function9693a: ; 9693a
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr nz, .nothing
 
@@ -957,7 +957,7 @@
 
 
 CountStep: ; 96b79
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr nz, .done
 
--- a/engine/pack.asm
+++ b/engine/pack.asm
@@ -1112,7 +1112,7 @@
 	ld a, [InputType]
 	or a
 	jr z, .asm_107ca
-	callba Function1de28f
+	callba _DudeAutoInput_RightA
 
 .asm_107ca
 	call Function107d7
--- /dev/null
+++ b/gfx/overworld/trainer_battle_pokeball_tiles.2bpp
@@ -1,0 +1,1 @@
+����Á����ý�����������������
\ No newline at end of file
--- a/gfx/pics/animation.asm
+++ b/gfx/pics/animation.asm
@@ -3,7 +3,7 @@
 
 Functiond0000: ; d0000
 	hlcoord 12, 0
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	cp $1
 	jr z, .asm_d0012
 	ld e, $0
--- a/gfx/unknown/08c2f4.2bpp
+++ /dev/null
@@ -1,1 +1,0 @@
-����Á����ý�����������������
\ No newline at end of file
--- a/home/battle.asm
+++ b/home/battle.asm
@@ -106,7 +106,7 @@
 ; Update level, status, current HP
 
 ; No wildmons.
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	ret z
 
@@ -194,34 +194,6 @@
 	dw .status, .statusopp, .animation, .effect, .power, .type
 	dw .curmove, .lastcounter, .lastcounteropp, .lastmove, .lastmoveopp
 
-	const_def
-	const PLAYER_SUBSTATUS_1
-	const ENEMY_SUBSTATUS_1
-	const PLAYER_SUBSTATUS_2
-	const ENEMY_SUBSTATUS_2
-	const PLAYER_SUBSTATUS_3
-	const ENEMY_SUBSTATUS_3
-	const PLAYER_SUBSTATUS_4
-	const ENEMY_SUBSTATUS_4
-	const PLAYER_SUBSTATUS_5
-	const ENEMY_SUBSTATUS_5
-	const PLAYER_STATUS
-	const ENEMY_STATUS
-	const PLAYER_MOVE_ANIMATION
-	const ENEMY_MOVE_ANIMATION
-	const PLAYER_MOVE_EFFECT
-	const ENEMY_MOVE_EFFECT
-	const PLAYER_MOVE_POWER
-	const ENEMY_MOVE_POWER
-	const PLAYER_MOVE_TYPE
-	const ENEMY_MOVE_TYPE
-	const PLAYER_CUR_MOVE
-	const ENEMY_CUR_MOVE
-	const PLAYER_COUNTER_MOVE
-	const ENEMY_COUNTER_MOVE
-	const PLAYER_LAST_MOVE
-	const ENEMY_LAST_MOVE
-
 ;                       player                     enemy
 .substatus1     db PLAYER_SUBSTATUS_1,    ENEMY_SUBSTATUS_1
 .substatus1opp  db ENEMY_SUBSTATUS_1,     PLAYER_SUBSTATUS_1
@@ -293,8 +265,8 @@
 CELL_PHONE_BOTTOM EQU $5f
 
 	; For mobile link battles only.
-	ld a, [InLinkBattle]
-	cp 4
+	ld a, [wLinkMode]
+	cp LINK_MOBILE
 	ret c
 
 	; Draw a cell phone icon at the
--- a/home/copy.asm
+++ b/home/copy.asm
@@ -227,7 +227,7 @@
 
 	ld a, $8
 	ld [$ffd3], a
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp $4
 	jr nz, .okay
 	ld a, [$ffe9]
@@ -301,7 +301,7 @@
 
 	ld a, $8
 	ld [$ffd3], a
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp $4
 	jr nz, .NotMobile
 	ld a, [$ffe9]
--- a/home/joypad.asm
+++ b/home/joypad.asm
@@ -198,7 +198,7 @@
 .updateauto
 ; An input of $ff will end the stream.
 	ld a, [hli]
-	cp a, $ff
+	cp a, -1
 	jr z, .stopauto
 	ld b, a
 	
@@ -205,7 +205,7 @@
 ; A duration of $ff will end the stream indefinitely.
 	ld a, [hli]
 	ld [AutoInputLength], a
-	cp a, $ff
+	cp a, -1
 	jr nz, .next
 	
 ; The current input is overwritten.
@@ -362,17 +362,20 @@
 	push af
 	xor a
 	ld [hConnectionStripLength], a
-	ld a, $6
+	ld a, 6
 	ld [hConnectedMapWidth], a
-.asm_a8d
+
+.loop
 	push hl
 	hlcoord 18, 17
 	call Functionb06
 	pop hl
+
 	call JoyTextDelay
 	ld a, [hJoyLast]
-	and $3
-	jr z, .asm_a8d
+	and A_BUTTON | B_BUTTON
+	jr z, .loop
+
 	pop af
 	ld [hConnectedMapWidth], a
 	pop af
@@ -381,18 +384,19 @@
 ; aa5
 
 Functionaa5:: ; aa5
+.loop
 	call JoyTextDelay
 	ld a, [hJoyLast]
 	and A_BUTTON | B_BUTTON
-	jr z, Functionaa5
+	jr z, .loop
 	ret
 ; aaf
 
 KeepTextOpen:: ; aaf
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
-	jr nz, .asm_ac1
-	call Functionac6
+	jr nz, .link
+	call .wait_input
 	push de
 	ld de, SFX_READ_TEXT_2
 	call PlaySFX
@@ -399,12 +403,12 @@
 	pop de
 	ret
 
-.asm_ac1
+.link
 	ld c, 65
 	jp DelayFrames
 ; ac6
 
-Functionac6:: ; ac6
+.wait_input: ; ac6
 	ld a, [hOAMUpdate]
 	push af
 	ld a, $1
@@ -411,37 +415,38 @@
 	ld [hOAMUpdate], a
 	ld a, [InputType]
 	or a
-	jr z, .asm_ad9
-	callba Function1de28a
-.asm_ad9
-	call Functionaf5
+	jr z, .input_wait_loop
+	callba _DudeAutoInput_A
+
+.input_wait_loop
+	call .blink_cursor
 	call JoyTextDelay
 	ld a, [hJoyPressed]
-	and $3
-	jr nz, .asm_af1
+	and A_BUTTON | B_BUTTON
+	jr nz, .received_input
 	call RTC
 	ld a, $1
 	ld [hBGMapMode], a
 	call DelayFrame
-	jr .asm_ad9
+	jr .input_wait_loop
 
-.asm_af1
+.received_input
 	pop af
 	ld [hOAMUpdate], a
 	ret
 ; af5
 
-Functionaf5:: ; af5
+.blink_cursor: ; af5
 	ld a, [$ff9b]
-	and $10
-	jr z, .asm_aff
-	ld a, $ee
-	jr .asm_b02
+	and %00010000 ; bit 4, a
+	jr z, .cursor_off
+	ld a, "▼"
+	jr .load_cursor_state
 
-.asm_aff
+.cursor_off
 	ld a, [TileMap + 17 + 17 * SCREEN_WIDTH]
 
-.asm_b02
+.load_cursor_state
 	ld [TileMap + 18 + 17 * SCREEN_WIDTH], a
 	ret
 ; b06
@@ -450,7 +455,7 @@
 	push bc
 	ld a, [hl]
 	ld b, a
-	ld a, $ee
+	ld a, "▼"
 	cp b
 	pop bc
 	jr nz, .asm_b27
@@ -462,11 +467,11 @@
 	dec a
 	ld [hConnectedMapWidth], a
 	ret nz
-	ld a, $7a
+	ld a, "─"
 	ld [hl], a
-	ld a, $ff
+	ld a, -1
 	ld [hConnectionStripLength], a
-	ld a, $6
+	ld a, 6
 	ld [hConnectedMapWidth], a
 	ret
 
--- a/home/serial.asm
+++ b/home/serial.asm
@@ -334,7 +334,7 @@
 Function8c1:: ; 8c1
 	push bc
 	ld b, $60
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp $1
 	jr z, .asm_8d7
 	ld b, $60
@@ -391,7 +391,7 @@
 ; 919
 
 Function919:: ; 919
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	ret nz
 	ld a, $2
--- a/home/text.asm
+++ b/home/text.asm
@@ -389,7 +389,7 @@
 PlaceEnemysName:: ; 121b
 	push de
 
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr nz, .linkbattle
 
@@ -428,9 +428,9 @@
 	ld l, c
 	ld a, [PlayerGender]
 	bit 0, a
-	ld de, String12a5
+	ld de, String_kun
 	jr z, PlaceCommandCharacter
-	ld de, String12a6
+	ld de, String_chan
 	jr PlaceCommandCharacter
 
 
@@ -456,8 +456,8 @@
 Char35Text::
 Char36Text::
 Char37Text:: db "@" ; 12a4
-String12a5:: db "@" ; 12a5
-String12a6:: db "@" ; 12a6
+String_kun:: db "@" ; 12a5
+String_chan:: db "@" ; 12a6
 ; 12a7
 
 NextLineChar:: ; 12a7
@@ -483,31 +483,31 @@
 	add hl, bc
 	ld de, -SCREEN_WIDTH
 	ld c, 1
-.asm_12c4
+.loop
 	ld a, h
 	and a
-	jr nz, .asm_12cd
+	jr nz, .next
 	ld a, l
 	cp SCREEN_WIDTH
-	jr c, .asm_12d1
+	jr c, .done
 
-.asm_12cd
+.next
 	add hl, de
 	inc c
-	jr .asm_12c4
+	jr .loop
 
-.asm_12d1
+.done
 	hlcoord 0, 0
 	ld de, SCREEN_WIDTH
 	ld a, c
-.asm_12d8
+.loop2
 	and a
-	jr z, .asm_12df
+	jr z, .done2
 	add hl, de
 	dec a
-	jr .asm_12d8
+	jr .loop2
 
-.asm_12df
+.done2
 	pop de
 	inc de
 	ld a, [de]
@@ -529,20 +529,20 @@
 Paragraph:: ; 12f2
 	push de
 
-	ld a, [InLinkBattle]
-	cp $3
-	jr z, .asm_1301
-	cp $4
-	jr z, .asm_1301
-	call Function13c7
-.asm_1301
+	ld a, [wLinkMode]
+	cp LINK_COLOSSEUM
+	jr z, .linkbattle
+	cp LINK_MOBILE
+	jr z, .linkbattle
+	call LoadBlinkingCursor
 
+.linkbattle
 	call Function13b6
 	call KeepTextOpen
 	hlcoord TEXTBOX_INNERX, TEXTBOX_INNERY
 	lb bc, TEXTBOX_INNERH - 1, TEXTBOX_INNERW
 	call ClearBox
-	call Function13cd
+	call UnloadBlinkingCursor
 	ld c, 20
 	call DelayFrames
 	hlcoord TEXTBOX_INNERX, TEXTBOX_INNERY
@@ -552,12 +552,12 @@
 
 
 Char4B:: ; 131f
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	or a
-	jr nz, .asm_1328
-	call Function13c7
-.asm_1328
+	jr nz, .communication
+	call LoadBlinkingCursor
 
+.communication
 	call Function13b6
 
 	push de
@@ -564,14 +564,14 @@
 	call KeepTextOpen
 	pop de
 
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	or a
-	call z, Function13cd
+	call z, UnloadBlinkingCursor
 
 Char4C:: ; 1337
 	push de
-	call Function138c
-	call Function138c
+	call TextScroll
+	call TextScroll
 	hlcoord TEXTBOX_INNERX, TEXTBOX_INNERY + 2
 	pop de
 	jp NextChar
@@ -602,22 +602,22 @@
 ; 135a
 
 PromptText:: ; 135a
-	ld a, [InLinkBattle]
-	cp $3
+	ld a, [wLinkMode]
+	cp LINK_COLOSSEUM
 	jr z, .ok
-	cp $4
+	cp LINK_MOBILE
 	jr z, .ok
-	call Function13c7
-.ok
+	call LoadBlinkingCursor
 
+.ok
 	call Function13b6
 	call KeepTextOpen
-	ld a, [InLinkBattle]
-	cp $3
+	ld a, [wLinkMode]
+	cp LINK_COLOSSEUM
 	jr z, DoneText
-	cp $4
+	cp LINK_MOBILE
 	jr z, DoneText
-	call Function13cd
+	call UnloadBlinkingCursor
 
 DoneText:: ; 137c
 	pop hl
@@ -634,13 +634,15 @@
 	jp NextChar
 ; 138c
 
-Function138c:: ; 138c
+TextScroll:: ; 138c
 	hlcoord TEXTBOX_INNERX, TEXTBOX_INNERY
 	decoord TEXTBOX_INNERX, TEXTBOX_INNERY - 1
 	ld a, TEXTBOX_INNERH - 1
+
 .col
 	push af
 	ld c, TEXTBOX_INNERW
+
 .row
 	ld a, [hli]
 	ld [de], a
@@ -647,6 +649,7 @@
 	inc de
 	dec c
 	jr nz, .row
+
 rept 2
 	inc de
 endr
@@ -656,6 +659,7 @@
 	pop af
 	dec a
 	jr nz, .col
+
 	hlcoord TEXTBOX_INNERX, TEXTBOX_INNERY + 2
 	ld a, " "
 	ld bc, TEXTBOX_INNERW
@@ -671,7 +675,9 @@
 	push af
 	ld a, 1
 	ld [hOAMUpdate], a
+
 	call WaitBGMap
+
 	pop af
 	ld [hOAMUpdate], a
 	pop bc
@@ -682,15 +688,15 @@
 	ret
 ; 13c7
 
-Function13c7:: ; 13c7
+LoadBlinkingCursor:: ; 13c7
 	ld a, "▼"
-	ld [TileMap + 18 + 17 * SCREEN_WIDTH], a
+	ldcoord_a 18, 17
 	ret
 ; 13cd
 
-Function13cd:: ; 13cd
-	ld a, [TileMap + 17 + 17 * SCREEN_WIDTH]
-	ld [TileMap + 18 + 17 * SCREEN_WIDTH], a
+UnloadBlinkingCursor:: ; 13cd
+	lda_coord 17, 17
+	ldcoord_a 18, 17
 	ret
 ; 13d4
 
@@ -722,7 +728,7 @@
 	set 1, a
 	ld [TextBoxFrame + 1], a
 
-	call Function13f6
+	call DoTextUntilTerminator
 
 	pop af
 	ld [TextBoxFrame + 1], a
@@ -729,12 +735,12 @@
 	ret
 ; 13f6
 
-Function13f6:: ; 13f6
+DoTextUntilTerminator:: ; 13f6
 	ld a, [hli]
 	cp "@"
 	ret z
 	call .TextCommand
-	jr Function13f6
+	jr DoTextUntilTerminator
 
 .TextCommand:
 	push hl
@@ -757,19 +763,19 @@
 ; 1410
 
 TextCommands:: ; 1410
-	dw Text_00
-	dw Text_01
-	dw Text_02
-	dw Text_03
-	dw Text_04
-	dw Text_05
-	dw Text_06
-	dw Text_07
-	dw Text_08
-	dw Text_09
-	dw Text_0A
+	dw Text_TX
+	dw Text_TX_RAM
+	dw Text_TX_BCD
+	dw Text_TX_MOVE
+	dw Text_TX_BOX
+	dw Text_TX_LOW
+	dw Text_WAIT_BUTTON
+	dw Text_TX_SCROLL
+	dw Text_START_ASM
+	dw Text_TX_NUM
+	dw Text_TX_EXIT
 	dw Text_PlaySound ; $0b
-	dw Text_0C
+	dw Text_TX_DOTS
 	dw Text_0D
 	dw Text_PlaySound ; $0e
 	dw Text_PlaySound ; $0f
@@ -777,12 +783,12 @@
 	dw Text_PlaySound ; $11
 	dw Text_PlaySound ; $12
 	dw Text_PlaySound ; $13
-	dw Text_14
-	dw Text_15
-	dw Text_16
+	dw Text_TX_STRINGBUFFER
+	dw Text_TX_DAY
+	dw Text_TX_FAR
 ; 143e
 
-Text_00:: ; 143e
+Text_TX:: ; 143e
 ; TX
 ; write text until "@"
 ; [$00]["...@"]
@@ -798,7 +804,7 @@
 	ret
 ; 1449
 
-Text_01:: ; 1449
+Text_TX_RAM:: ; 1449
 ; text_from_ram
 ; write text from a ram address
 ; little endian
@@ -816,7 +822,7 @@
 	ret
 ; 1455
 
-Text_16:: ; 1455
+Text_TX_FAR:: ; 1455
 ; text_jump
 ; write text from a different bank
 ; little endian
@@ -837,7 +843,7 @@
 	push hl
 	ld h, d
 	ld l, e
-	call Function13f6
+	call DoTextUntilTerminator
 	pop hl
 
 	pop af
@@ -846,7 +852,7 @@
 	ret
 ; 1470
 
-Text_02:: ; 1470
+Text_TX_BCD:: ; 1470
 ; TX_BCD
 ; write bcd from address, typically ram
 ; [$02][addr][flags]
@@ -868,7 +874,7 @@
 	ret
 ; 1480
 
-Text_03:: ; 1480
+Text_TX_MOVE:: ; 1480
 ; TX_MOVE
 ; move to a new tile
 ; [$03][addr]
@@ -882,7 +888,7 @@
 	ret
 ; 148b
 
-Text_04:: ; 148b
+Text_TX_BOX:: ; 148b
 ; TX_BOX
 ; draw a box
 ; little endian
@@ -904,7 +910,7 @@
 	ret
 ; 149b
 
-Text_05:: ; 149b
+Text_TX_LOW:: ; 149b
 ; TX_LOW
 ; write text at (1,16)
 ; [$05]
@@ -913,39 +919,41 @@
 	ret
 ; 149f
 
-Text_06:: ; 149f
+Text_WAIT_BUTTON:: ; 149f
 ; TX_WAITBUTTON
 ; wait for button press
 ; show arrow
 ; [06]
 
-	ld a, [InLinkBattle]
-	cp $3
+	ld a, [wLinkMode]
+	cp LINK_COLOSSEUM
 	jp z, Text_0D
-	cp $4
+	cp LINK_MOBILE
 	jp z, Text_0D
 
 	push hl
-	call Function13c7
+	call LoadBlinkingCursor
 	push bc
 	call KeepTextOpen
 	pop bc
-	call Function13cd
+	call UnloadBlinkingCursor
 	pop hl
 	ret
 ; 14ba
 
-Text_07:: ; 14ba
+Text_TX_SCROLL:: ; 14ba
+; pushes text up two lines and sets the BC cursor to the border tile
+; below the first character column of the text box.
 	push hl
-	call Function13cd
-	call Function138c
-	call Function138c
+	call UnloadBlinkingCursor
+	call TextScroll
+	call TextScroll
 	pop hl
 	bccoord TEXTBOX_INNERX, TEXTBOX_INNERY + 2
 	ret
 ; 14c9
 
-Text_08:: ; 14c9
+Text_START_ASM:: ; 14c9
 ; TX_ASM
 
 	bit 7, h
@@ -958,7 +966,7 @@
 	ret
 ; 14d2
 
-Text_09:: ; 14d2
+Text_TX_NUM:: ; 14d2
 ; TX_NUM
 ; [$09][addr][hi:bytes lo:digits]
 	ld a, [hli]
@@ -984,7 +992,7 @@
 	ret
 ; 14ed
 
-Text_0A:: ; 14ed
+Text_TX_EXIT:: ; 14ed
 	push hl
 	push bc
 	call GetJoypad
@@ -1059,7 +1067,7 @@
 	db -1
 ; 1543
 
-Text_0C:: ; 1543
+Text_TX_DOTS:: ; 1543
 ; [$0C][num]
 	ld a, [hli]
 	ld d, a
@@ -1066,6 +1074,7 @@
 	push hl
 	ld h, b
 	ld l, c
+
 .loop
 	push de
 	ld a, "…"
@@ -1080,6 +1089,7 @@
 	pop de
 	dec d
 	jr nz, .loop
+
 	ld b, h
 	ld c, l
 	pop hl
@@ -1097,7 +1107,7 @@
 	ret
 ; 156a
 
-Text_14:: ; 156a
+Text_TX_STRINGBUFFER:: ; 156a
 ; Print a string from one of the following:
 ; 0: StringBuffer3
 ; 1: StringBuffer4
@@ -1127,7 +1137,7 @@
 	ret
 ; 1582
 
-Text_15:: ; 1582
+Text_TX_DAY:: ; 1582
 ; TX_DAY
 
 	call GetWeekday
--- a/items/item_effects.asm
+++ b/items/item_effects.asm
@@ -208,7 +208,7 @@
 MoonBall:
 LoveBall:
 ParkBall: ; e8a2
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jp nz, Functionf7a0
 
@@ -1657,7 +1657,7 @@
 	call Functionf30d
 	ld a, 1
 	ret nz
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	and a
 	jr z, .asm_f104
 
@@ -1936,7 +1936,7 @@
 	ret
 
 Functionf2a6: ; f2a6 (3:72a6)
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	and a
 	ret z
 	ld a, [CurPartyMon]
@@ -2280,7 +2280,7 @@
 
 
 PokeDoll: ; f48f
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr nz, .asm_f4a6
 	inc a
@@ -2362,7 +2362,7 @@
 
 
 PokeFlute: ; f50c
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	and a
 	jr nz, .asm_f512
 .asm_f512
@@ -2375,7 +2375,7 @@
 	ld hl, PartyMon1Status
 	call .Functionf554
 
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	cp WILD_BATTLE
 	jr z, .asm_f52b
 	ld hl, OTPartyMon1Status
@@ -2448,7 +2448,7 @@
 
 
 Function_0xf57b: ; f57b
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	and a
 	jr nz, .asm_f58c
 
@@ -2600,7 +2600,7 @@
 ; f652
 
 Functionf652: ; f652
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	and a
 	jr z, .asm_f66c
 	ld a, [CurPartyMon]
--- a/macros.asm
+++ b/macros.asm
@@ -111,11 +111,19 @@
 	endr
 	ENDM
 
-ldcoord: MACRO
+ldcoord_a: MACRO
 	if _NARG < 3
 	ld [TileMap + SCREEN_WIDTH * (\2) + (\1)], a
 	else
 	ld [\3 + SCREEN_WIDTH * (\2) + (\1)], a
+	endc
+	ENDM
+
+lda_coord: MACRO
+	if _NARG < 3
+	ld a, [TileMap + SCREEN_WIDTH * (\2) + (\1)]
+	else
+	ld a, [\3 + SCREEN_WIDTH * (\2) + (\1)]
 	endc
 	ENDM
 
--- a/main.asm
+++ b/main.asm
@@ -9,7 +9,7 @@
 	ld b, 1
 	ld c, 11
 
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	and a
 	jr z, .notinbattle
 
@@ -542,7 +542,7 @@
 .loop
 	xor a
 	ld [wc2c1], a
-	ld [InLinkBattle], a
+	ld [wLinkMode], a
 	ld hl, GameTimerPause
 	set 0, [hl]
 	res 7, [hl]
@@ -1620,7 +1620,7 @@
 	ld [wd265], a
 
 	ld b, a
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	and a
 	jr z, .not_disabled
 	ld a, [DisabledMove]
@@ -1656,7 +1656,7 @@
 
 	ld [hl], a
 
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	and a
 	jp z, .learned
 
@@ -2772,7 +2772,7 @@
 
 .done
 	ld [de], a
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	and a
 	ret z
 	ld a, [CurPartyMon]
@@ -8017,7 +8017,7 @@
 	ld a, [BaseDexNo]
 	ld [de], a
 	inc de
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	and a
 	ld a, $0
 	jr z, .skipitem
@@ -8029,7 +8029,7 @@
 	push de
 	ld h, d
 	ld l, e
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	and a
 	jr z, .randomlygeneratemoves
 	ld a, [MonType]
@@ -8108,7 +8108,7 @@
 	pop de
 	pop hl
 	push hl
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	and a
 	jr nz, .copywildmonstats
 	call Random
@@ -8213,7 +8213,7 @@
 	inc de
 
 .next2
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr nz, .generatestats
 	ld hl, EnemyMonMaxHP
@@ -9207,7 +9207,7 @@
 	ld a, [wd10b]
 	and a
 	jp nz, CloseSRAM
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	ret nz
 	ld a, BANK(s0_a600)
@@ -12723,7 +12723,7 @@
 	call .AppendMenuList
 .no_pokemon
 
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr nz, .no_pack
 	ld hl, StatusFlags2
@@ -12743,7 +12743,7 @@
 	ld a, 3 ; status
 	call .AppendMenuList
 
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr nz, .no_save
 	ld hl, StatusFlags2
@@ -13521,7 +13521,7 @@
 ; If in the time capsule or trade center,
 ; selecting the mail only allows you to
 ; read the mail.
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp LINK_TIMECAPSULE
 	jr z, .read
 	cp LINK_TRADECENTER
@@ -14103,7 +14103,7 @@
 	ld bc, $0015
 	add hl, bc
 	call Function1313a
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	jr z, .asm_13113
 	ld hl, BattleMonMoves
 	ld bc, $0020
@@ -24230,7 +24230,7 @@
 	ld a, [CurPartySpecies]
 	cp EGG
 	jr z, .egg
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr nz, .skip
 	ld a, PartyMon1Moves - PartyMon1
@@ -24264,7 +24264,7 @@
 	call Function24e83
 	ld a, $13
 	call Function24e83
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr nz, .skip2
 	push hl
@@ -27157,7 +27157,7 @@
 	ld a, [hBattleTurn]
 	and a
 	jr nz, .ourturn
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	jr z, .done
 
@@ -27245,7 +27245,7 @@
 	xor a
 	ld [hli], a
 	ld [hl], $50
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp LINK_TIMECAPSULE
 	jp nz, Function28177
 
@@ -27443,7 +27443,7 @@
 	ld de, wc6d0
 	ld bc, $00c8
 	call Function75f
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp LINK_TRADECENTER
 	jr nz, .asm_281fd
 	ld hl, wc9f4
@@ -27494,7 +27494,7 @@
 	ld hl, wc90f
 	dec c
 	jr nz, .asm_28224
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp LINK_TRADECENTER
 	jp nz, .asm_282fe
 	ld hl, wcb84
@@ -27628,7 +27628,7 @@
 	cp $2
 	ld c, 66
 	call z, DelayFrames
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp LINK_COLOSSEUM
 	jr nz, .asm_283a9
 	ld a, CAL
@@ -27811,7 +27811,7 @@
 	dec a
 	jr nz, .asm_2847f
 	push bc
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp LINK_TIMECAPSULE
 	ld b, $d
 	jr z, .asm_2847a
@@ -28042,7 +28042,7 @@
 	ld hl, PartyMonNicknames
 	ld bc, $0042
 	call CopyBytes
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp LINK_TRADECENTER
 	ret nz
 	ld de, wc9f4
@@ -28585,7 +28585,7 @@
 
 .asm_28946
 	ld a, $7f
-	ldcoord 11, 16
+	ldcoord_a 11, 16
 	ld a, $13
 	ld [wcfa8], a
 	ld a, $1
@@ -28617,7 +28617,7 @@
 
 .asm_2898d
 	ld a, $7f
-	ldcoord 1, 16
+	ldcoord_a 1, 16
 	ld a, $23
 	ld [wcfa8], a
 	ld a, $1
@@ -28763,7 +28763,7 @@
 Function28ade: ; 28ade
 .asm_28ade
 	ld a, $ed
-	ldcoord 9, 17
+	ldcoord_a 9, 17
 .asm_28ae3
 	call JoyTextDelay
 	ld a, [hJoyLast]
@@ -28773,7 +28773,7 @@
 	jr nz, .asm_28b0b
 	push af
 	ld a, " "
-	ldcoord 9, 17
+	ldcoord_a 9, 17
 	pop af
 	bit 6, a
 	jr z, .asm_28b03
@@ -28788,7 +28788,7 @@
 
 .asm_28b0b
 	ld a, $ec
-	ldcoord 9, 17
+	ldcoord_a 9, 17
 	ld a, $f
 	ld [wcf56], a
 	callba Function16d6ce
@@ -29162,7 +29162,7 @@
 	push bc
 	call Function862
 	pop bc
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp LINK_TIMECAPSULE
 	jr z, .asm_28e63
 	ld a, b
@@ -29188,7 +29188,7 @@
 	callba Function4d354
 	ld c, $32
 	call DelayFrames
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp LINK_TIMECAPSULE
 	jp z, Function2805d
 	jp Function28177
@@ -30455,7 +30455,7 @@
 ; 29701 (a:5701)
 
 Function29701: ; 29701
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp LINK_TIMECAPSULE
 	jr z, .asm_29725
 	ld hl, UnknownText_0x29737
@@ -30891,7 +30891,7 @@
 	xor a
 	ld [hVBlank], a
 	inc a
-	ld [InLinkBattle], a
+	ld [wLinkMode], a
 	ret
 ; 29c92
 
@@ -30939,7 +30939,7 @@
 	ld [hli], a
 	ld [hl], a
 	ld [hVBlank], a
-	ld [InLinkBattle], a
+	ld [wLinkMode], a
 	ret
 ; 29ce8
 
@@ -31211,7 +31211,7 @@
 	jr nz, .asm_29eaa
 	ld a, [wd265]
 	inc a
-	ld [InLinkBattle], a
+	ld [wLinkMode], a
 	xor a
 	ld [hVBlank], a
 	ld a, $1
@@ -31226,7 +31226,7 @@
 
 Special_TimeCapsule: ; 29eaf
 	ld a, LINK_TIMECAPSULE
-	ld [InLinkBattle], a
+	ld [wLinkMode], a
 	call Function2ed3
 	callab LinkCommunications
 	call Function2ee4
@@ -31237,7 +31237,7 @@
 
 Special_TradeCenter: ; 29ec4
 	ld a, LINK_TRADECENTER
-	ld [InLinkBattle], a
+	ld [wLinkMode], a
 	call Function2ed3
 	callab LinkCommunications
 	call Function2ee4
@@ -31248,7 +31248,7 @@
 
 Special_Colosseum: ; 29ed9
 	ld a, LINK_COLOSSEUM
-	ld [InLinkBattle], a
+	ld [wLinkMode], a
 	call Function2ed3
 	callab LinkCommunications
 	call Function2ee4
@@ -31259,7 +31259,7 @@
 
 Special_CloseLink: ; 29eee
 	xor a
-	ld [InLinkBattle], a
+	ld [wLinkMode], a
 	ld c, $3
 	call DelayFrames
 	jp Function29f04
@@ -32589,7 +32589,7 @@
 	ld [rOBP0], a
 	call Function2c165
 	call Function2c01c
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	ret z
 	jp Function2c03a
@@ -32730,7 +32730,7 @@
 	hlcoord 1, 2
 	ld de, 1
 	call Function2c0f1
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	ret nz
 	ld a, [TempEnemyMonSpecies]
@@ -34119,7 +34119,7 @@
 Function2ee18: ; 2ee18
 ; If we're not in a communications room,
 ; we don't need to be here.
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	ret z
 
@@ -34245,7 +34245,7 @@
 	jr .done
 
 .othertrainer
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr nz, .johtotrainer
 
@@ -34424,7 +34424,7 @@
 
 Function39550: ; 39550
 	ld hl, wd26b
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr nz, .ok
 
@@ -34476,7 +34476,7 @@
 	bit 0, a
 	ret nz
 
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	ret nz
 
@@ -35030,7 +35030,7 @@
 	cp EVOLVE_TRADE
 	jr z, .trade
 
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jp nz, .asm_423f9
 
@@ -35107,7 +35107,7 @@
 
 
 .trade
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jp z, .asm_423f9
 
@@ -35119,7 +35119,7 @@
 	inc a
 	jr z, .asm_422fd
 
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp LINK_TIMECAPSULE
 	jp z, .asm_423fa
 
@@ -35142,7 +35142,7 @@
 	ld a, [wd1e9]
 	and a
 	jp z, .asm_423fa
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jp nz, .asm_423fa
 	jr .asm_422fd
@@ -35303,10 +35303,10 @@
 	pop de
 	pop bc
 	pop hl
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	ret nz
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	and a
 	ret nz
 	ld a, [wd268]
@@ -35652,11 +35652,11 @@
 ; Pick the move with the lowest score.
 
 ; Wildmons attack at random.
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	dec a
 	ret z
 
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	ret nz
 
@@ -39350,8 +39350,8 @@
 	ld a, $4
 	call Function49336
 	ld a, $3
-	ldcoord 0, 1, AttrMap
-	ldcoord 0, 14, AttrMap
+	ldcoord_a 0, 1, AttrMap
+	ldcoord_a 0, 14, AttrMap
 	hlcoord 2, 0, AttrMap
 	ld bc, $0812
 	ld a, $5
@@ -43924,11 +43924,11 @@
 
 
 Function4dc7b: ; 4dc7b (13:5c7b)
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp LINK_MOBILE
 	jr nz, StatsScreenInit
 
-	ld a, [IsInBattle] ; wd22d (aliases: EnemyMonEnd)
+	ld a, [wBattleMode] ; wd22d (aliases: EnemyMonEnd)
 	and a
 	jr z, StatsScreenInit
 	jr Function4dc8f
@@ -45850,7 +45850,7 @@
 ; Return carry if battle scene is turned off.
 
 	ld a, 0
-	ld hl, InLinkBattle
+	ld hl, wLinkMode
 	call GetFarWRAMByte
 	cp LINK_MOBILE
 	jr z, .mobile
@@ -54146,1290 +54146,13 @@
 ; 8c001
 
 
-Function8c001:: ; 8c001
-	call UpdateTime
-	ld a, [TimeOfDay]
-	ld [CurTimeOfDay], a
-	call GetTimePalette
-	ld [TimeOfDayPal], a
-	ret
-; 8c011
+INCLUDE "engine/timeofdaypals.asm"
+INCLUDE "engine/battle_start.asm"
 
-
-_TimeOfDayPals:: ; 8c011
-; return carry if pals are changed
-
-; forced pals?
-	ld hl, wd846
-	bit 7, [hl]
-	jr nz, .dontchange
-
-; do we need to bother updating?
-	ld a, [TimeOfDay]
-	ld hl, CurTimeOfDay
-	cp [hl]
-	jr z, .dontchange
-
-; if so, the time of day has changed
-	ld a, [TimeOfDay]
-	ld [CurTimeOfDay], a
-
-; get palette id
-	call GetTimePalette
-
-; same palette as before?
-	ld hl, TimeOfDayPal
-	cp [hl]
-	jr z, .dontchange
-
-; update palette id
-	ld [TimeOfDayPal], a
-
-
-; save bg palette 8
-	ld hl, Unkn1Pals + 8 * 7 ; Unkn1Pals + 7 pals
-
-; save wram bank
-	ld a, [rSVBK]
-	ld b, a
-; wram bank 5
-	ld a, 5
-	ld [rSVBK], a
-
-; push palette
-	ld c, 4 ; NUM_PAL_COLORS
-.push
-	ld d, [hl]
-	inc hl
-	ld e, [hl]
-	inc hl
-	push de
-	dec c
-	jr nz, .push
-
-; restore wram bank
-	ld a, b
-	ld [rSVBK], a
-
-
-; update sgb pals
-	ld b, $9
-	call GetSGBLayout
-
-
-; restore bg palette 8
-	ld hl, Unkn2Pals - 1 ; last byte in Unkn1Pals
-
-; save wram bank
-	ld a, [rSVBK]
-	ld d, a
-; wram bank 5
-	ld a, 5
-	ld [rSVBK], a
-
-; pop palette
-	ld e, 4 ; NUM_PAL_COLORS
-.pop
-	pop bc
-	ld [hl], c
-	dec hl
-	ld [hl], b
-	dec hl
-	dec e
-	jr nz, .pop
-
-; restore wram bank
-	ld a, d
-	ld [rSVBK], a
-
-; update palettes
-	call _UpdateTimePals
-	call DelayFrame
-
-; successful change
-	scf
-	ret
-
-.dontchange
-; no change occurred
-	and a
-	ret
-; 8c070
-
-
-_UpdateTimePals:: ; 8c070
-	ld c, $9 ; normal
-	call GetTimePalFade
-	call DmgToCgbTimePals
-	ret
-; 8c079
-
-FadeInBGMap:: ; 8c079
-	ld c, $12
-	call GetTimePalFade
-	ld b, $4
-	call Function8c16d
-	ret
-; 8c084
-
-FadeBlackBGMap:: ; 8c084
-	call Function8c0c1
-	ld c, $9
-	call GetTimePalFade
-	ld b, $4
-	call Function8c15e
-	ret
-; 8c092
-
-Special_BattleTowerFade: ; 8c092
-	call Function8c0c1
-	ld c, $9
-	call GetTimePalFade
-	ld b, $4
-.asm_8c09c
-	call DmgToCgbTimePals
-rept 3
-	inc hl
-endr
-	ld c, $7
-	call DelayFrames
-	dec b
-	jr nz, .asm_8c09c
-	ret
-; 8c0ab
-
-Special_FadeInQuickly: ; 8c0ab
-	ld c, $0
-	call GetTimePalFade
-	ld b, $4
-	call Function8c15e
-	ret
-; 8c0b6
-
-Special_FadeBlackQuickly: ; 8c0b6
-	ld c, $9
-	call GetTimePalFade
-	ld b, $4
-	call Function8c16d
-	ret
-; 8c0c1
-
-
-Function8c0c1: ; 8c0c1
-	ld a, [rSVBK]
-	push af
-	ld a, $5
-	ld [rSVBK], a
-	ld hl, Unkn1Pals
-	ld a, [hli]
-	ld e, a
-	ld a, [hli]
-	ld d, a
-	ld hl, Unkn1Pals + 8
-	ld c, $6
-.asm_8c0d4
-	ld a, e
-	ld [hli], a
-	ld a, d
-	ld [hli], a
-rept 6
-	inc hl
-endr
-	dec c
-	jr nz, .asm_8c0d4
-	pop af
-	ld [rSVBK], a
-	ret
-; 8c0e5
-
-brightlevel: MACRO
-	db (\1 << 6) | (\2 << 4) | (\3 << 2) | \4
-ENDM
-
-Function8c0e5: ; 8c0e5
-	ld hl, .BrightnessLevels
-	ld a, [wc2d0]
-	cp $4 ; Dark cave, needs Flash
-	jr z, .DarkCave
-	and $7
-	add l
-	ld l, a
-	ld a, $0
-	adc h
-	ld h, a
-	ld a, [hl]
-	ld [wd847], a
-	ret
-.DarkCave
-	ld a, [StatusFlags]
-	bit 2, a
-	jr nz, .UsedFlash
-	ld a, $ff ; 3, 3, 3, 3
-	ld [wd847], a
-	ret
-.UsedFlash
-	ld a, $aa ; 2, 2, 2, 2
-	ld [wd847], a
-	ret
-; 8c10f (23:410f)
-
-.BrightnessLevels: ; 8c10f
-	brightlevel 3, 2, 1, 0
-	brightlevel 1, 1, 1, 1
-	brightlevel 2, 2, 2, 2
-	brightlevel 0, 0, 0, 0
-	brightlevel 3, 3, 3, 3
-	brightlevel 3, 2, 1, 0
-	brightlevel 3, 2, 1, 0
-	brightlevel 3, 2, 1, 0
-; 8c117
-
-GetTimePalette: ; 8c117
-	ld a, [TimeOfDay]
-	ld e, a
-	ld d, 0
-	ld hl, .TimePalettes
-rept 2
-	add hl, de
-endr
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-	jp [hl]
-; 8c126
-
-.TimePalettes
-	dw .MorningPalette
-	dw .DayPalette
-	dw .NitePalette
-	dw .DarknessPalette
-
-.MorningPalette
-	ld a, [wd847]
-	and %00000011 ; 0
-	ret
-
-.DayPalette
-	ld a, [wd847]
-	and %00001100 ; 1
-	srl a
-	srl a
-	ret
-
-.NitePalette
-	ld a, [wd847]
-	and %00110000 ; 2
-	swap a
-	ret
-
-.DarknessPalette
-	ld a, [wd847]
-	and %11000000 ; 3
-	rlca
-	rlca
-	ret
-; 8c14e
-
-
-DmgToCgbTimePals: ; 8c14e
-	push hl
-	push de
-	ld a, [hli]
-	call DmgToCgbBGPals
-	ld a, [hli]
-	ld e, a
-	ld a, [hli]
-	ld d, a
-	call DmgToCgbObjPals
-	pop de
-	pop hl
-	ret
-; 8c15e
-
-Function8c15e: ; 8c15e
-.asm_8c15e
-	call DmgToCgbTimePals
-rept 3
-	inc hl
-endr
-	ld c, $2
-	call DelayFrames
-	dec b
-	jr nz, .asm_8c15e
-	ret
-; 8c16d
-
-Function8c16d: ; 8c16d
-.asm_8c16d
-	call DmgToCgbTimePals
-rept 3
-	dec hl
-endr
-	ld c, $2
-	call DelayFrames
-	dec b
-	jr nz, .asm_8c16d
-	ret
-; 8c17c
-
-
-GetTimePalFade: ; 8c17c
-; check cgb
-	ld a, [hCGB]
-	and a
-	jr nz, .cgb
-
-; else: dmg
-
-; index
-	ld a, [TimeOfDayPal]
-	and %11
-
-; get fade table
-	push bc
-	ld c, a
-	ld b, $0
-	ld hl, .dmgfades
-rept 2
-	add hl, bc
-endr
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-	pop bc
-
-; get place in fade table
-	ld b, $0
-	add hl, bc
-	ret
-
-.cgb
-	ld hl, .cgbfade
-	ld b, $0
-	add hl, bc
-	ret
-
-.dmgfades
-	dw .morn
-	dw .day
-	dw .nite
-	dw .darkness
-
-.morn
-	db %11111111, %11111111, %11111111
-	db %11111110, %11111110, %11111110
-	db %11111001, %11100100, %11100100
-	db %11100100, %11010000, %11010000
-	db %10010000, %10000000, %10000000
-	db %01000000, %01000000, %01000000
-	db %00000000, %00000000, %00000000
-
-.day
-	db %11111111, %11111111, %11111111	
-	db %11111110, %11111110, %11111110	
-	db %11111001, %11100100, %11100100
-	db %11100100, %11010000, %11010000
-	db %10010000, %10000000, %10000000
-	db %01000000, %01000000, %01000000
-	db %00000000, %00000000, %00000000
-
-.nite
-	db %11111111, %11111111, %11111111
-	db %11111110, %11111110, %11111110
-	db %11111001, %11100100, %11100100
-	db %11101001, %11010000, %11010000
-	db %10010000, %10000000, %10000000
-	db %01000000, %01000000, %01000000
-	db %00000000, %00000000, %00000000
-
-.darkness
-	db %11111111, %11111111, %11111111
-	db %11111110, %11111110, %11111111
-	db %11111110, %11100100, %11111111
-	db %11111101, %11010000, %11111111
-	db %11111101, %10000000, %11111111
-	db %00000000, %01000000, %00000000
-	db %00000000, %00000000, %00000000
-
-.cgbfade
-	db %11111111, %11111111, %11111111
-	db %11111110, %11111110, %11111110
-	db %11111001, %11111001, %11111001
-	db %11100100, %11100100, %11100100
-	db %10010000, %10010000, %10010000
-	db %01000000, %01000000, %01000000
-	db %00000000, %00000000, %00000000
-; 8c20f
-
-
-Predef_StartBattle: ; 8c20f
-	call Function8c26d
-	ld a, [rBGP]
-	ld [wcfc7], a
-	ld a, [rOBP0]
-	ld [wcfc8], a
-	ld a, [rOBP1]
-	ld [wcfc9], a
-	call DelayFrame
-	ld hl, hVBlank
-	ld a, [hl]
-	push af
-	ld [hl], $1
-
-.loop
-	ld a, [wcf63]
-	bit 7, a
-	jr nz, .done
-	call FlashingPokeballAnimation
-	call DelayFrame
-	jr .loop
-
-.done
-	ld a, [rSVBK]
-	push af
-	ld a, $5
-	ld [rSVBK], a
-
-	ld hl, Unkn1Pals
-	ld bc, $0040
-	xor a
-	call ByteFill
-
-	pop af
-	ld [rSVBK], a
-
-	ld a, %11111111
-	ld [wcfc7], a
-	call DmgToCgbBGPals
-	call DelayFrame
-	xor a
-	ld [hLCDStatCustom], a
-	ld [hLCDStatCustom + 1], a
-	ld [hLCDStatCustom + 2], a
-	ld [hSCY], a
-
+Function8c7c9: ; unreferenced
 	ld a, $1
-	ld [rSVBK], a
-	pop af
-	ld [hVBlank], a
-	call DelayFrame
-	ret
-; 8c26d
-
-Function8c26d: ; 8c26d
-	ld a, [InLinkBattle]
-	cp LINK_MOBILE
-	jr z, .mobile
-	callba Function6454
-	call UpdateSprites
-	call DelayFrame
-	call Function8c2a0
-	call Function8cf4f
-	jr .resume
-
-.mobile
-	call Function8c2aa
-
-.resume
-	ld a, SCREEN_HEIGHT_PX
-	ld [hWY], a
-	call DelayFrame
-	xor a
 	ld [hBGMapMode], a
-	ld hl, wcf63
-	xor a
-rept 2
-	ld [hli], a
-endr
-	ld [hl], a
-	call WipeLYOverrides
-	ret
-; 8c2a0
-
-Function8c2a0: ; 8c2a0
-	call Function8c2aa
-	ld hl, VBGMap0
-	call Function8c2cf
-	ret
-; 8c2aa
-
-Function8c2aa: ; 8c2aa
-	ld de, GFX_8c2f4
-	ld hl, VTiles1 tile $7e
-	ld b, BANK(GFX_8c2f4)
-	ld c, 2
-	call Request2bpp
-
-	ld a, [rVBK]
-	push af
-	ld a, $1
-	ld [rVBK], a
-
-	ld de, GFX_8c2f4
-	ld hl, VTiles4 tile $7e
-	ld b, BANK(GFX_8c2f4)
-	ld c, 2
-	call Request2bpp
-
-	pop af
-	ld [rVBK], a
-	ret
-; 8c2cf
-
-Function8c2cf: ; 8c2cf
-	ld a, [rSVBK]
-	push af
-	ld a, $6
-	ld [rSVBK], a
-	push hl
-	ld hl, w6_d000
-	ld bc, $28 * $10
-
-.loop
-	ld [hl], -1
-	inc hl
-	dec bc
-	ld a, c
-	or b
-	jr nz, .loop
-
-	pop hl
-	ld de, w6_d000
-	ld b, BANK(Function8c2cf) ; BANK(@)
-	ld c, $28
-	call Request2bpp
-	pop af
-	ld [rSVBK], a
-	ret
-; 8c2f4
-
-GFX_8c2f4: ; 8c2f4
-INCBIN "gfx/unknown/08c2f4.2bpp"
-
-
-FlashingPokeballAnimation: ; 8c314
-	ld a, [wcf63]
-	ld e, a
-	ld d, 0
-	ld hl, .jumptable
-rept 2
-	add hl, de
-endr
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-	jp [hl]
-; 8c323
-
-.jumptable: ; 8c323 (23:4323)
-	dw StartTrainerBattle_DetermineWhichAnimation ; 00
-
-	; Animation 1: cave
-	dw StartTrainerBattle_LoadPokeBallGraphics ; 01
-	dw StartTrainerBattle_SetUpBGMap ; 02
-	dw StartTrainerBattle_Flash ; 03
-	dw StartTrainerBattle_Flash ; 04
-	dw StartTrainerBattle_Flash ; 05
-	dw StartTrainerBattle_NextScene ; 06
-	dw StartTrainerBattle_SetUpForWavyOutro ; 07
-	dw StartTrainerBattle_SineWave ; 08
-
-	; Animation 2: cave, stronger
-	dw StartTrainerBattle_LoadPokeBallGraphics ; 09
-	dw StartTrainerBattle_SetUpBGMap ; 0a
-	dw StartTrainerBattle_Flash ; 0b
-	dw StartTrainerBattle_Flash ; 0c
-	dw StartTrainerBattle_Flash ; 0d
-	dw StartTrainerBattle_NextScene ; 0e
-	; There is no setup for this one
-	dw StartTrainerBattle_ZoomToBlack ; 0f
-
-	; Animation 3: no cave
-	dw StartTrainerBattle_LoadPokeBallGraphics ; 10
-	dw StartTrainerBattle_SetUpBGMap ; 11
-	dw StartTrainerBattle_Flash ; 12
-	dw StartTrainerBattle_Flash ; 13
-	dw StartTrainerBattle_Flash ; 14
-	dw StartTrainerBattle_NextScene ; 15
-	dw StartTrainerBattle_SetUpForSpinOutro ; 16
-	dw StartTrainerBattle_SpinToBlack ; 17
-
-	; Animation 4: no cave, stronger
-	dw StartTrainerBattle_LoadPokeBallGraphics ; 18
-	dw StartTrainerBattle_SetUpBGMap ; 19
-	dw StartTrainerBattle_Flash ; 1a
-	dw StartTrainerBattle_Flash ; 1b
-	dw StartTrainerBattle_Flash ; 1c
-	dw StartTrainerBattle_NextScene ; 1d
-	dw StartTrainerBattle_SetUpForRandomScatterOutro ; 1e
-	dw StartTrainerBattle_SpeckleToBlack ; 1f
-
-	; All animations jump to here.
-	dw StartTrainerBattle_Finish ; 20
-
-
-StartTrainerBattle_DetermineWhichAnimation: ; 8c365 (23:4365)
-; The screen flashes a different number of
-; times depending on the level of your lead
-; Pokemon relative to the opponent's.
-	ld de, 0
-	ld a, [BattleMonLevel]
-	add 3
-	ld hl, EnemyMonLevel
-	cp [hl]
-	jr nc, .okay
-	set 0, e
-.okay
-	ld a, [wPermission]
-	cp CAVE
-	jr z, .okay2
-	cp PERM_5
-	jr z, .okay2
-	cp DUNGEON
-	jr z, .okay2
-	set 1, e
-.okay2
-	ld hl, .StartingPoints
-	add hl, de
-	ld a, [hl]
-	ld [wcf63], a
-	ret
-; 8c38f (23:438f)
-
-.StartingPoints: ; 8c38f
-	db 1,  9
-	db 16, 24
-; 8c393
-
-StartTrainerBattle_Finish: ; 8c393 (23:4393)
-	call ClearSprites
-	ld a, $80
-	ld [wcf63], a
-	ret
-
-StartTrainerBattle_NextScene: ; 8c39c (23:439c)
-	ld hl, wcf63
-	inc [hl]
-	ret
-
-StartTrainerBattle_SetUpBGMap: ; 8c3a1 (23:43a1)
-	call StartTrainerBattle_NextScene
-	xor a
-	ld [wcf64], a
-	ld [hBGMapMode], a ; $ff00+$d4
-	ret
-
-StartTrainerBattle_Flash: ; 8c3ab (23:43ab)
-	call Function8c3b3
-	ret nc
-	call StartTrainerBattle_NextScene
-	ret
-
-Function8c3b3: ; 8c3b3 (23:43b3)
-	ld a, [wd847]
-	cp -1
-	jr z, .done
-	ld hl, wcf64
-	ld a, [hl]
-	inc [hl]
-	srl a
-	ld e, a
-	ld d, 0
-	ld hl, .pals
-	add hl, de
-	ld a, [hl]
-	cp $1
-	jr z, .done
-	ld [wcfc7], a
-	call DmgToCgbBGPals
-	and a
-	ret
-
-.done
-	xor a
-	ld [wcf64], a
-	scf
-	ret
-; 8c3db (23:43db)
-
-.pals: ; 8c3db
-	db %11111001 ; 3321
-	db %11111110 ; 3332
-	db %11111111 ; 3333
-	db %11111110 ; 3332
-	db %11111001 ; 3321
-	db %11100100 ; 3210
-	db %10010000 ; 2100
-	db %01000000 ; 1000
-	db %00000000 ; 0000
-	db %01000000 ; 1000
-	db %10010000 ; 2100
-	db %11100100 ; 3210
-	db %00000001 ; 0001
-; 8c3e8
-
-StartTrainerBattle_SetUpForWavyOutro: ; 8c3e8 (23:43e8)
-	callba Function5602
-	ld a, $5
-	ld [rSVBK], a ; $ff00+$70
-	call StartTrainerBattle_NextScene
-	ld a, $43
-	ld [hLCDStatCustom], a ; $ff00+$c6
-	xor a
-	ld [hLCDStatCustom + 1], a
-	ld a, $90
-	ld [hLCDStatCustom + 2], a
-	xor a
-	ld [wcf64], a
-	ld [wcf65], a
-	ret
-
-StartTrainerBattle_SineWave: ; 8c408 (23:4408)
-	ld a, [wcf64]
-	cp $60
-	jr nc, .end
-	call .DoSineWave
-	ret
-
-.end
-	ld a, $20
-	ld [wcf63], a
-	ret
-
-.DoSineWave: ; 8c419 (23:4419)
-	ld hl, wcf65
-	ld a, [hl]
-	inc [hl]
-	ld hl, wcf64
-	ld d, [hl]
-	add [hl]
-	ld [hl], a
-	ld a, $90
-	ld bc, wd100
-	ld e, $0
-
-.loop
-	push af
-	push de
-	ld a, e
-	call StartTrainerBattle_DrawSineWave
-	ld [bc], a
-	inc bc
-	pop de
-	ld a, e
-	add $2
-	ld e, a
-	pop af
-	dec a
-	jr nz, .loop
-	ret
-
-StartTrainerBattle_SetUpForSpinOutro: ; 8c43d (23:443d)
-	callba Function5602
-	ld a, $5
-	ld [rSVBK], a ; $ff00+$70
-	call StartTrainerBattle_NextScene
-	xor a
-	ld [wcf64], a
-	ret
-
-spintable_entry: MACRO
-	db \1
-	dw .wedge\2
-	dwcoord \3, \4
-ENDM
-
-; quadrants
-	const_def
-	const UPPER_LEFT
-	const UPPER_RIGHT
-	const LOWER_LEFT
-	const LOWER_RIGHT
-
-StartTrainerBattle_SpinToBlack: ; 8c44f (23:444f)
-	xor a
-	ld [hBGMapMode], a ; $ff00+$d4
-	ld a, [wcf64]
-	ld e, a
-	ld d, 0
-	ld hl, .spintable
-rept 5
-	add hl, de
-endr
-	ld a, [hli]
-	cp -1
-	jr z, .end
-	ld [wcf65], a
-	call .load
-	ld a, $1
-	ld [hBGMapMode], a ; $ff00+$d4
-	call DelayFrame
-	call DelayFrame
-	ld hl, wcf64
-	inc [hl]
-	ret
-
-.end
-	ld a, $1
-	ld [hBGMapMode], a ; $ff00+$d4
-	call DelayFrame
-	call DelayFrame
-	call DelayFrame
-	xor a
-	ld [hBGMapMode], a ; $ff00+$d4
-	ld a, $20
-	ld [wcf63], a
-	ret
-; 8c490 (23:4490)
-
-.spintable: ; 8c490
-	spintable_entry UPPER_LEFT,  1,  1,  6
-	spintable_entry UPPER_LEFT,  2,  0,  3
-	spintable_entry UPPER_LEFT,  3,  1,  0
-	spintable_entry UPPER_LEFT,  4,  5,  0
-	spintable_entry UPPER_LEFT,  5,  9,  0
-	spintable_entry UPPER_RIGHT, 5, 10,  0
-	spintable_entry UPPER_RIGHT, 4, 14,  0
-	spintable_entry UPPER_RIGHT, 3, 18,  0
-	spintable_entry UPPER_RIGHT, 2, 19,  3
-	spintable_entry UPPER_RIGHT, 1, 18,  6
-	spintable_entry LOWER_RIGHT, 1, 18, 11
-	spintable_entry LOWER_RIGHT, 2, 19, 14
-	spintable_entry LOWER_RIGHT, 3, 18, 17
-	spintable_entry LOWER_RIGHT, 4, 14, 17
-	spintable_entry LOWER_RIGHT, 5, 10, 17
-	spintable_entry LOWER_LEFT,  5,  9, 17
-	spintable_entry LOWER_LEFT,  4,  5, 17
-	spintable_entry LOWER_LEFT,  3,  1, 17
-	spintable_entry LOWER_LEFT,  2,  0, 14
-	spintable_entry LOWER_LEFT,  1,  1, 11
-	db -1
-; 8c4f5
-
-.load: ; 8c4f5 (23:44f5)
-	ld a, [hli]
-	ld e, a
-	ld a, [hli]
-	ld d, a
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-.loop
-	push hl
-	ld a, [de]
-	ld c, a
-	inc de
-.loop1
-	ld [hl], $ff
-	ld a, [wcf65]
-	bit 0, a
-	jr z, .leftside
-	inc hl
-	jr .okay1
-.leftside
-	dec hl
-.okay1
-	dec c
-	jr nz, .loop1
-	pop hl
-	ld a, [wcf65]
-	bit 1, a
-	ld bc, SCREEN_WIDTH
-	jr z, .upper
-	ld bc, -SCREEN_WIDTH
-.upper
-	add hl, bc
-	ld a, [de]
-	inc de
-	cp -1
-	ret z
-	and a
-	jr z, .loop
-	ld c, a
-.loop2
-	ld a, [wcf65]
-	bit 0, a
-	jr z, .leftside2
-	dec hl
-	jr .okay2
-.leftside2
-	inc hl
-.okay2
-	dec c
-	jr nz, .loop2
-	jr .loop
-; 8c538 (23:4538)
-
-.wedge1: db 2, 3, 5, 4, 9, -1
-.wedge2: db 1, 1, 2, 2, 4, 2, 4, 2, 3, -1
-.wedge3: db 2, 1, 3, 1, 4, 1, 4, 1, 4, 1, 3, 1, 2, 1, 1, 1, 1, -1
-.wedge4: db 4, 1, 4, 0, 3, 1, 3, 0, 2, 1, 2, 0, 1, -1
-.wedge5: db 4, 0, 3, 0, 3, 0, 2, 0, 2, 0, 1, 0, 1, 0, 1, -1
-; 8c578
-
-StartTrainerBattle_SetUpForRandomScatterOutro: ; 8c578 (23:4578)
-	callba Function5602
-	ld a, $5
-	ld [rSVBK], a ; $ff00+$70
-	call StartTrainerBattle_NextScene
-	ld a, $10
-	ld [wcf64], a
-	ld a, $1
-	ld [hBGMapMode], a ; $ff00+$d4
-	ret
-
-StartTrainerBattle_SpeckleToBlack: ; 8c58f (23:458f)
-	ld hl, wcf64
-	ld a, [hl]
-	and a
-	jr z, .done
-	dec [hl]
-	ld c, $c
-.loop
-	push bc
-	call .BlackOutRandomTile
-	pop bc
-	dec c
-	jr nz, .loop
-	ret
-
-.done
-	ld a, $1
-	ld [hBGMapMode], a ; $ff00+$d4
-	call DelayFrame
-	call DelayFrame
-	call DelayFrame
-	xor a
-	ld [hBGMapMode], a ; $ff00+$d4
-	ld a, $20
-	ld [wcf63], a
-	ret
-
-.BlackOutRandomTile: ; 8c5b8 (23:45b8)
-.y_loop
-	call Random
-	cp SCREEN_HEIGHT
-	jr nc, .y_loop
-	ld b, a
-
-.x_loop
-	call Random
-	cp SCREEN_WIDTH
-	jr nc, .x_loop
-	ld c, a
-
-	hlcoord 0, -1
-	ld de, SCREEN_WIDTH
-	inc b
-
-.row_loop
-	add hl, de
-	dec b
-	jr nz, .row_loop
-	add hl, bc
-
-; If the tile has already been blacked out,
-; sample a new tile
-	ld a, [hl]
-	cp $ff
-	jr z, .y_loop
-	ld [hl], $ff
-	ret
-
-StartTrainerBattle_LoadPokeBallGraphics: ; 8c5dc (23:45dc)
-	ld a, [OtherTrainerClass]
-	and a
-	jp z, .nextscene
-	xor a
-	ld [hBGMapMode], a ; $ff00+$d4
-	hlcoord 0, 0, AttrMap
-	ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
-	inc b
-	inc c
-	jr .enter_loop_midway
-
-.loop
-	ld a, [hl]
-	or $7
-	ld [hli], a
-.enter_loop_midway
-	dec c
-	jr nz, .loop
-	dec b
-	jr nz, .loop
-	call .loadpokeballgfx
-	hlcoord 2, 1
-	ld b, $10
-.loop2
-	push hl
-	ld c, $2
-.loop3
-	push hl
-	ld a, [de]
-	inc de
-.loop4
-	and a
-	jr z, .asm_8c614
-	sla a
-	jr nc, .asm_8c611
-	ld [hl], $fe
-.asm_8c611
-	inc hl
-	jr .loop4
-.asm_8c614
-	pop hl
-	push bc
-	ld bc, $8
-	add hl, bc
-	pop bc
-	dec c
-	jr nz, .loop3
-	pop hl
-	push bc
-	ld bc, $14
-	add hl, bc
-	pop bc
-	dec b
-	jr nz, .loop2
-	ld a, [hCGB] ; $ff00+$e6
-	and a
-	jr nz, .cgb
-	ld a, $1
-	ld [hBGMapMode], a ; $ff00+$d4
-	call DelayFrame
-	call DelayFrame
-	jr .nextscene
-
-.cgb
-	ld hl, .daypals
-	ld a, [TimeOfDayPal]
-	and (1 << 2) - 1
-	cp 3
-	jr nz, .daytime
-	ld hl, .nightpals
-.daytime
-	ld a, [rSVBK] ; $ff00+$70
-	push af
-	ld a, $5 ; WRAM5 = palettes
-	ld [rSVBK], a ; $ff00+$70
-	call .copypals
-	push hl
-	ld de, Unkn1Pals + 8 * 7
-	ld bc, $8
-	call CopyBytes
-	pop hl
-	ld de, BGPals + 8 * 7
-	ld bc, $8
-	call CopyBytes
-	pop af
-	ld [rSVBK], a ; $ff00+$70
-	ld a, $1
-	ld [hCGBPalUpdate], a ; $ff00+$e5
-	call DelayFrame
-	call Function8cf4f
-
-.nextscene: ; 8c673 (23:4673)
-	call StartTrainerBattle_NextScene
-	ret
-
-.copypals: ; 8c677 (23:4677)
-	ld de, Unkn1Pals + 8 * 7
-	call .copy
-	ld de, BGPals + 8 * 7
-	call .copy
-	ld de, Unkn2Pals + 8 * 6
-	call .copy
-	ld de, OBPals + 8 * 6
-	call .copy
-	ld de, Unkn2Pals + 8 * 7
-	call .copy
-	ld de, OBPals + 8 * 7
-
-.copy: ; 8c698 (23:4698)
-	push hl
-	ld bc, $8
-	call CopyBytes
-	pop hl
-	ret
-; 8c6a1 (23:46a1)
-
-.daypals: ; 8c6a1
-	RGB 31, 18, 29
-	RGB 31, 11, 15
-	RGB 31, 05, 05
-	RGB 07, 07, 07
-; 8c6a9
-
-.nightpals: ; 8c6a9
-	RGB 31, 18, 29
-	RGB 31, 05, 05
-	RGB 31, 05, 05
-	RGB 31, 05, 05
-
-.loadpokeballgfx:
-	ld a, [OtherTrainerClass]
-	ld de, PokeBallTransition
-	ret
-
-PokeBallTransition:
-	db %00000011, %11000000
-	db %00001111, %11110000
-	db %00111100, %00111100
-	db %00110000, %00001100
-	db %01100000, %00000110
-	db %01100011, %11000110
-	db %11000110, %01100011
-	db %11111100, %00111111
-	db %11111100, %00111111
-	db %11000110, %01100011
-	db %01100011, %11000110
-	db %01100000, %00000110
-	db %00110000, %00001100
-	db %00111100, %00111100
-	db %00001111, %11110000
-	db %00000011, %11000000
-
-WipeLYOverrides: ; 8c6d8
-	ld a, [rSVBK]
-	push af
-	ld a, $5
-	ld [rSVBK], a
-	ld hl, LYOverrides
-	call .wipe
-	ld hl, LYOverridesBackup
-	call .wipe
-	pop af
-	ld [rSVBK], a
-	ret
-; 8c6ef
-
-.wipe: ; 8c6ef
-	xor a
-	ld c, SCREEN_HEIGHT_PX
-.loop
-	ld [hli], a
-	dec c
-	jr nz, .loop
-	ret
-; 8c6f7
-
-
-StartTrainerBattle_DrawSineWave: ; 8c6f7 (23:46f7)
-	and (1 << 6) - 1
-	cp 1 << 5
-	jr nc, .okay
-	call .DoSineWave
-	ld a, h
-	ret
-
-.okay
-	and (1 << 5) - 1
-	call .DoSineWave
-	ld a, h
-	xor -1 ; cpl
-	inc a
-	ret
-
-.DoSineWave: ; 8c70c (23:470c)
-	ld e, a
-	ld a, d
-	ld d, 0
-	ld hl, .sinewave
-rept 2
-	add hl, de
-endr
-	ld e, [hl]
-	inc hl
-	ld d, [hl]
-	ld hl, 0
-.loop
-	srl a
-	jr nc, .skip
-	add hl, de
-.skip
-	sla e
-	rl d
-	and a
-	jr nz, .loop
-	ret
-; 8c728 (23:4728)
-
-.sinewave: ; 8c728
-	sine_wave $100
-; 8c768
-
-zoombox: macro
-; width, height, start y, start x
-	db \1, \2
-	dwcoord \3, \4
-endm
-
-StartTrainerBattle_ZoomToBlack: ; 8c768 (23:4768)
-	callba Function5602
-	ld de, .boxes
-
-.loop
-	ld a, [de]
-	cp -1
-	jr z, .done
-	inc de
-	ld c, a
-	ld a, [de]
-	inc de
-	ld b, a
-	ld a, [de]
-	inc de
-	ld l, a
-	ld a, [de]
-	inc de
-	ld h, a
-	xor a
-	ld [hBGMapMode], a ; $ff00+$d4
-	call .Copy
 	call WaitBGMap
-	jr .loop
-
-.done
-	ld a, $20
-	ld [wcf63], a
-	ret
-; 8c792 (23:4792)
-
-.boxes: ; 8c792
-	zoombox  4,  2,  8, 8
-	zoombox  6,  4,  7, 7
-	zoombox  8,  6,  6, 6
-	zoombox 10,  8,  5, 5
-	zoombox 12, 10,  4, 4
-	zoombox 14, 12,  3, 3
-	zoombox 16, 14,  2, 2
-	zoombox 18, 16,  1, 1
-	zoombox 20, 18,  0, 0
-	db -1
-; 8c7b7
-
-.Copy: ; 8c7b7 (23:47b7)
-	ld a, $ff
-.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
-; 8c7c9 (23:47c9)
-
-Function8c7c9: ; 8c7c9
-	ld a, $1
-	ld [hBGMapMode], a
-	call WaitBGMap
 	xor a
 	ld [hBGMapMode], a
 	ret
@@ -55475,25 +54198,25 @@
 	ld a, $90
 	ld [wc3b5], a
 	callba Function8cf7a
-	call Function8c913
+	call GetHeadbuttTreeRelativeLocation
 	ld a, $20
 	ld [wcf64], a
 	call WaitSFX
 	ld de, SFX_SANDSTORM
 	call PlaySFX
-.asm_8c852
+.loop
 	ld hl, wcf64
 	ld a, [hl]
 	and a
-	jr z, .asm_8c86a
+	jr z, .done
 	dec [hl]
 	ld a, $90
 	ld [wc3b5], a
 	callba Function8cf7a
 	call DelayFrame
-	jr .asm_8c852
+	jr .loop
 
-.asm_8c86a
+.done
 	call Function2173
 	call WaitBGMap
 	xor a
@@ -55515,19 +54238,20 @@
 INCBIN "gfx/unknown/08c893.2bpp"
 ; 8c913
 
-Function8c913: ; 8c913
+GetHeadbuttTreeRelativeLocation: ; 8c913
 	xor a
 	ld [hBGMapMode], a
 	ld a, [PlayerDirection]
-	and $c
+	and %00001100
 	srl a
 	ld e, a
 	ld d, 0
-	ld hl, Unknown_8c938
+	ld hl, TreeRelativeLocationTable
 	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
+
 	ld a, $5
 	ld [hli], a
 	ld [hld], a
@@ -55541,12 +54265,13 @@
 	ret
 ; 8c938
 
-Unknown_8c938: ; 8c938
-	dwcoord 8, 10
-	dwcoord 8, 6
-	dwcoord 6, 8
-	dwcoord 10, 8
+TreeRelativeLocationTable: ; 8c938
+	dwcoord 8,     8 + 2 ; RIGHT
+	dwcoord 8,     8 - 2 ; LEFT
+	dwcoord 8 - 2, 8     ; DOWN
+	dwcoord 8 + 2, 8     ; UP
 ; 8c940
+; 8c940
 
 Function8c940: ; 8c940
 	ld a, e
@@ -56409,9 +55134,11 @@
 	push de
 	push bc
 	push af
+
 	ld a, $0
 	ld [wc3b5], a
 	call Function8cf7a
+
 	pop af
 	pop bc
 	pop de
@@ -56422,6 +55149,7 @@
 Function8cf7a: ; 8cf7a
 	ld hl, wPartyMonMenuIconAnims
 	ld e, 10 ; Do this first loop 10 times
+
 .loop
 	ld a, [hl]
 	and a
@@ -56444,6 +55172,7 @@
 	ld a, [wc3b5]
 	ld l, a
 	ld h, Sprites / $0100
+
 .loop2 ; Clear (Sprites + [wc3b5] --> SpritesEnd)
 	ld a, l
 	cp SpritesEnd % $0100
@@ -56458,7 +55187,8 @@
 
 Function8cfa8: ; 8cfa8 (23:4fa8)
 	ld hl, wPartyMonMenuIconAnims
-	ld e, $a
+	ld e, 10
+
 .loop
 	ld a, [hl]
 	and a
@@ -56472,21 +55202,24 @@
 	pop de
 	pop hl
 	jr c, .done
+
 .next
-	ld bc, $10
+	ld bc, $0010
 	add hl, bc
 	dec e
 	jr nz, .loop
+
 	ld a, [wc3b5]
 	ld l, a
-	ld h, $c4
+	ld h, Sprites / $100
 .loop2
 	ld a, l
-	cp $40
+	cp 4 * 16
 	jr nc, .done
 	xor a
 	ld [hli], a
 	jr .loop2
+
 .done
 	ret
 
@@ -57033,7 +55766,7 @@
 	ld hl, $7
 	add hl, bc
 	ld a, d
-	and $10
+	and $10 ; bit 4
 	jr z, .asm_8d2df
 	ld a, e
 	and a
@@ -59686,7 +58419,7 @@
 ; 8ea3f
 
 GetGFXUnlessMobile: ; 8ea3f
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp LINK_MOBILE
 	jp nz, Request2bpp
 	jp Functiondc9
@@ -60100,7 +58833,7 @@
 	ret
 
 Function90199: ; 90199 (24:4199)
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	and a
 	jr nz, .asm_901e7
 	call GetMapHeaderPhoneServiceNybble
@@ -65997,13 +64730,13 @@
 Function931ba: ; 931ba
 	ld a, [EffectFailed]
 	add $25
-	ldcoord 2, 13
+	ldcoord_a 2, 13
 	inc a
-	ldcoord 2, 14
+	ldcoord_a 2, 14
 	inc a
-	ldcoord 3, 13
+	ldcoord_a 3, 13
 	inc a
-	ldcoord 3, 14
+	ldcoord_a 3, 14
 	hlcoord 18, 17
 	ld [hl], $ee
 	ld hl, UnknownText_0x931db
@@ -77831,7 +76564,7 @@
 	ld a, [hl]
 	cp 101
 	jr nc, .asm_fb5db
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp LINK_TIMECAPSULE
 	jr nz, .asm_fb5d9
 	ld hl, OTPartySpecies
@@ -84400,22 +83133,22 @@
 
 
 
-Function1de28a:: ; 1de28a
+_DudeAutoInput_A:: ; 1de28a
 	ld hl, DudeAutoInput_A
-	jr Function1de299
+	jr _DudeAutoInput
 ; 1de28f
 
-Function1de28f: ; 1de28f
+_DudeAutoInput_RightA: ; 1de28f
 	ld hl, DudeAutoInput_RightA
-	jr Function1de299
+	jr _DudeAutoInput
 ; 1de294
 
-Function1de294: ; 1de294
+_DudeAutoInput_DownA: ; 1de294
 	ld hl, DudeAutoInput_DownA
-	jr Function1de299
+	jr _DudeAutoInput
 ; 1de299
 
-Function1de299: ; 1de299
+_DudeAutoInput: ; 1de299
 	ld a, BANK(DudeAutoInputs)
 	call StartAutoInput
 	ret
--- a/misc/crystal_misc.asm
+++ b/misc/crystal_misc.asm
@@ -19,6 +19,7 @@
 	pop de
 	xor a
 	ret
+
 .asm_17a6a6
 	scf
 	ret
@@ -82,6 +83,7 @@
 	inc c
 	and a
 	ret
+
 .asm_17a71d
 	ld [hl], $ff
 	scf
@@ -113,10 +115,12 @@
 	dec b
 	jr nz, .asm_17a732
 	ret
+
 .asm_17a748
 	ld a, $ff
 	ld [de], a
 	ret
+
 .asm_17a74c
 	ld a, $f0
 	or c
@@ -167,6 +171,7 @@
 	jr nz, .asm_17a79f
 	callba Function10402d
 	ret
+
 .asm_17a79f
 	callba Function104061
 	ret
@@ -297,41 +302,49 @@
 	jr nz, .asm_17a8a7
 	xor a
 	ret
+
 .asm_17a876
 	ld a, $9
 	call Function17aad0
 	scf
 	ret
+
 .asm_17a87d
 	ld a, $a
 	call Function17aad0
 	scf
 	ret
+
 .asm_17a884
 	ld a, $b
 	call Function17aad0
 	scf
 	ret
+
 .asm_17a88b
 	ld a, $c
 	call Function17aad0
 	scf
 	ret
+
 .asm_17a892
 	ld a, $5
 	call Function17aad0
 	scf
 	ret
+
 .asm_17a899
 	ld a, $6
 	call Function17aad0
 	scf
 	ret
+
 .asm_17a8a0
 	ld a, $7
 	call Function17aad0
 	scf
 	ret
+
 .asm_17a8a7
 	ld a, $8
 	call Function17aad0
@@ -347,6 +360,7 @@
 	jr nz, .asm_17a8d7
 	xor a
 	ret
+
 .asm_17a8bc
 	ld a, $b
 	ld [$d08a], a
@@ -355,6 +369,7 @@
 	call Function17aa88
 	scf
 	ret
+
 .asm_17a8cc
 	call Function17aad7
 	call Function17aa98
@@ -361,6 +376,7 @@
 	call Function17a8de
 	scf
 	ret
+
 .asm_17a8d7
 	ld a, $c
 	call Function17aad3
@@ -383,10 +399,12 @@
 	ld [$d087], a
 	call Function17aa88
 	ret
+
 .asm_17a8fd
 	call Function17a943
 	call Function17aa88
 	ret
+
 .asm_17a904
 	call Function17aad7
 	call Function17aa98
@@ -393,6 +411,7 @@
 	call Function17a91e
 	call Function17aa88
 	ret
+
 .asm_17a911
 	call Function17aa98
 	ld a, $5
@@ -409,6 +428,7 @@
 	ld [$d087], a
 	xor a
 	ret
+
 .asm_17a92c
 	call Function1d6e
 	call Function17a99e
@@ -436,6 +456,7 @@
 	ld [$d087], a
 	and a
 	ret
+
 .asm_17a95d
 	ld a, $5
 	ld [$d087], a
@@ -455,6 +476,7 @@
 	ld [hl], e
 	and a
 	ret
+
 .asm_17a979
 	scf
 	ret
@@ -479,6 +501,7 @@
 	dec c
 	jr nz, .asm_17a990
 	ret
+
 .asm_17a99d
 	ret
 
@@ -503,12 +526,13 @@
 	ld de, Sprites ; $c400
 	ld hl, $d088
 	bit 6, [hl]
-	jr nz, .asm_17a9df
+	jr nz, .bit_6_set
 	call Function17a9e3
 	call Function17aa22
 	call Function17a9f5
 	ret
-.asm_17a9df
+
+.bit_6_set
 	call Function17a9e3
 	ret
 
@@ -533,9 +557,9 @@
 	ld [$d08e], a
 	ld a, [$d08c]
 	cp $10
-	jr c, .asm_17aa0f
+	jr c, .okay
 	dec a
-.asm_17aa0f
+.okay
 	ld c, $8
 	call SimpleMultiply
 	add $18
@@ -581,7 +605,7 @@
 	add $10
 	ld c, a
 	ld a, [hli]
-.asm_17aa56
+.loop
 	push af
 	ld a, [hli]
 	add c
@@ -603,7 +627,7 @@
 	inc de
 	pop af
 	dec a
-	jr nz, .asm_17aa56
+	jr nz, .loop
 	ret
 ; 17aa72 (5e:6a72)
 
@@ -662,7 +686,7 @@
 	ld [hli], a
 endr
 	pop hl
-	ld de, $14
+	ld de, SCREEN_WIDTH
 	add hl, de
 rept 2
 	ld [hli], a
@@ -721,16 +745,20 @@
 	push af
 	ld a, $1
 	ld [rVBK], a ; $ff00+$4f
-	ld hl, VTiles2 tile $00
+
+	ld hl, VTiles5 tile $00
 	ld de, GFX_17afa5
 	lb bc, BANK(GFX_17afa5), $80
 	call Get2bpp
+
 	pop af
 	ld [rVBK], a ; $ff00+$4f
+
 	ld hl, VTiles0 tile $00
 	ld de, GFX_17afa5 + $4c0
 	lb bc, BANK(GFX_17afa5), 5
 	call Get2bpp
+
 	ld hl, VTiles0 tile $05
 	ld de, GFX_11601a
 	lb bc, BANK(GFX_11601a), 4
@@ -740,25 +768,30 @@
 Function17abcf: ; 17abcf (5e:6bcf)
 	ld a, [rSVBK] ; $ff00+$70
 	push af
-	ld a, $5
+	ld a, BANK(Unkn1Pals)
 	ld [rSVBK], a ; $ff00+$70
+
 	ld hl, Palette_17ac55
 	ld de, Unkn1Pals ; $d000
 	ld bc, $30
 	call CopyBytes
+
 	ld hl, Palette_17ac95
 	ld de, Unkn2Pals
 	ld bc, $40
 	call CopyBytes
+
 	ld hl, GFX_17afa5 + $510
-	ld de, $d048
+	ld de, Unkn2Pals + 2 * 4
 	ld bc, $10
 	call CopyBytes
+
 	ld hl, MapObjectPals + 8
-	ld de, $d058
+	ld de, Unkn2Pals + 6 * 4
 	ld bc, $8
 	ld a, BANK(MapObjectPals)
 	call FarCopyBytes
+
 	pop af
 	ld [rSVBK], a ; $ff00+$70
 	ret
@@ -767,8 +800,8 @@
 	call Function17ac1d
 	call Function17ac2a
 	hlcoord 0, 0
-	ld b, $2
-	ld c, $12
+	ld b, 2
+	ld c, SCREEN_WIDTH - 2
 	call Function17ac46
 	ret
 
@@ -775,7 +808,7 @@
 Function17ac1d: ; 17ac1d (5e:6c1d)
 	ld hl, Tilemap_17acd5
 	decoord 0, 4
-	ld bc, $118
+	ld bc, (SCREEN_HEIGHT - 4) * SCREEN_WIDTH
 	call CopyBytes
 	ret
 
@@ -782,11 +815,11 @@
 Function17ac2a: ; 17ac2a (5e:6c2a)
 	ld hl, Tilemap_17ae3d
 	decoord 0, 4, AttrMap
-	ld bc, $118
+	ld bc, (SCREEN_HEIGHT - 4) * SCREEN_WIDTH
 	call CopyBytes
 	hlcoord 0, 4, AttrMap
-	ld bc, $118
-.asm_17ac3c
+	ld bc, (SCREEN_HEIGHT - 4) * SCREEN_WIDTH
+.loop
 	ld a, [hl]
 	or $8
 	ld [hli], a
@@ -793,16 +826,17 @@
 	dec bc
 	ld a, b
 	or c
-	jr nz, .asm_17ac3c
+	jr nz, .loop
 	ret
 
 Function17ac46: ; 17ac46 (5e:6c46)
 	ld a, [$d088]
 	bit 4, a
-	jr nz, .asm_17ac51
+	jr nz, .bit_4_set
 	call TextBox
 	ret
-.asm_17ac51
+
+.bit_4_set
 	call Function3eea
 	ret
 ; 17ac55 (5e:6c55)
@@ -812,30 +846,37 @@
 	RGB  9, 10, 25
 	RGB 16, 19, 31
 	RGB 31, 31, 31
+
 	RGB  5, 11,  9
 	RGB  7, 14, 12
 	RGB 17, 24, 22
 	RGB 28, 31, 31
+
 	RGB  0,  0,  0
 	RGB  3,  0, 10
 	RGB  3,  3, 16
 	RGB  6,  8, 25
+
 	RGB  5, 11,  9
 	RGB 28, 31, 31
 	RGB  7, 14, 12
 	RGB 17, 24, 22
+
 	RGB  0,  0,  0
 	RGB  5,  2, 16
 	RGB  8,  8, 26
 	RGB 13,  9, 17
+
 	RGB  0,  0,  0
 	RGB  0,  0,  0
 	RGB  0,  0,  0
 	RGB  0,  0,  0
+
 	RGB  0,  0,  0
 	RGB  0,  0,  0
 	RGB  0,  0,  0
 	RGB  0,  0,  0
+
 	RGB  0,  0,  0
 	RGB  0,  0,  0
 	RGB  0,  0,  0
@@ -846,30 +887,37 @@
 	RGB  4,  3,  3
 	RGB 31, 13,  0
 	RGB 31, 31, 31
+
 	RGB 31, 31, 31
 	RGB  0,  0,  0
 	RGB 31, 31, 31
 	RGB 31, 31, 31
+
 	RGB 31,  0,  0
 	RGB 16,  3,  0
 	RGB 28, 19, 11
 	RGB 31, 31, 31
+
 	RGB 31, 16,  0
 	RGB  9,  6,  4
 	RGB 31, 16,  0
 	RGB 31, 24,  0
+
 	RGB 31, 18,  6
 	RGB  0,  3,  0
 	RGB  0,  9,  0
 	RGB  0, 12,  0
+
 	RGB  0, 16,  0
 	RGB  0, 22,  0
 	RGB  0, 25,  0
 	RGB  0, 27,  0
+
 	RGB  0, 31,  0
 	RGB  3, 31,  0
 	RGB  8, 31,  0
 	RGB 14, 31,  0
+
 	RGB 16, 31,  0
 	RGB 22, 31,  0
 	RGB 27, 31,  0
--- a/misc/mobile_40.asm
+++ b/misc/mobile_40.asm
@@ -168,10 +168,10 @@
 	ld [$ffc9], a
 	ld [$ffe9], a
 	ei
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	push af
 	xor a
-	ld [InLinkBattle], a
+	ld [wLinkMode], a
 	ld a, $4
 	ld [wPartyMonMenuIconAnims + 5], a
 	callba Function11619d
@@ -178,7 +178,7 @@
 	ld hl, wcd29
 	set 6, [hl]
 	pop af
-	ld [InLinkBattle], a
+	ld [wLinkMode], a
 	ret
 ; 100144
 
@@ -1612,7 +1612,7 @@
 	call Function100a2e
 	ld [wd431], a
 	callba Function4000
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp $4
 	jr nz, .asm_100a2a
 	call Function100a87
@@ -2134,7 +2134,7 @@
 
 
 Function100dc0: ; 100dc0
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp $4
 	jr nz, .asm_100dd0
 	ld hl, wcd2a
@@ -2770,13 +2770,13 @@
 	ld [wdc5f], a
 	ld [wdc60], a
 	ld a, $4
-	ld [InLinkBattle], a
+	ld [wLinkMode], a
 	ret
 ; 101220
 
 Function101220: ; 101220
 	xor a
-	ld [InLinkBattle], a
+	ld [wLinkMode], a
 	ret
 ; 101225
 
@@ -6802,7 +6802,7 @@
 	hlcoord 3, 10
 	ld b, $1
 	ld c, $b
-	ld a, [IsInBattle]
+	ld a, [wBattleMode]
 	and a
 	jr z, .asm_102e19
 	call TextBox
--- a/misc/mobile_45.asm
+++ b/misc/mobile_45.asm
@@ -5976,7 +5976,7 @@
 	pop af
 	ld [rSVBK], a
 	callba Function104061
-	ld a, [InLinkBattle]
+	ld a, [wLinkMode]
 	cp $4
 	jr z, .asm_11642a
 	ld a, $8
@@ -16146,10 +16146,10 @@
 	ld a, $1
 	ld [wd1e9], a
 	ld a, $2
-	ld [InLinkBattle], a
+	ld [wLinkMode], a
 	callba Function421d8
 	xor a
-	ld [InLinkBattle], a
+	ld [wLinkMode], a
 	callba Function14a58
 	ld a, $5
 	call GetSRAMBank
@@ -22841,7 +22841,7 @@
 	or $1
 	ld [InBattleTowerBattle], a
 	xor a
-	ld [InLinkBattle], a
+	ld [wLinkMode], a
 	callba Mobile_HealParty
 	callba HealParty
 	call Function1702b7
--- a/misc/mobile_5f.asm
+++ b/misc/mobile_5f.asm
@@ -300,10 +300,10 @@
 	ld a, $1
 	ld [wd1e9], a
 	ld a, $2
-	ld [InLinkBattle], a
+	ld [wLinkMode], a
 	callba Function421d8
 	xor a
-	ld [InLinkBattle], a
+	ld [wLinkMode], a
 	callba Function14a58
 	ld a, $5
 	call GetSRAMBank
--- a/wram.asm
+++ b/wram.asm
@@ -294,7 +294,7 @@
 wc2d8:: ds 1
 wc2d9:: ds 1
 wc2da:: ds 2
-InLinkBattle:: ; c2dc
+wLinkMode:: ; c2dc
 ; 0 not in link battle
 ; 1 link battle
 ; 4 mobile battle
@@ -1760,7 +1760,7 @@
 EnemyMonEnd::
 
 
-IsInBattle:: ; d22d
+wBattleMode:: ; d22d
 ; 0: overworld
 ; 1: wild battle
 ; 2: trainer battle