shithub: pokecrystal

Download patch

ref: 8612a4a531b755b1d323e834980dab5ae896499c
parent: 43903f543bb04344710d57862a2c5534fd3e5b4c
author: PikalaxALT <PikalaxALT@gmail.com>
date: Sat Nov 28 10:13:40 EST 2015

Renaming sections, further dissolving main.asm

--- a/battle/ai/items.asm
+++ b/battle/ai/items.asm
@@ -20,7 +20,7 @@
 	and a
 	jr nz, DontSwitch
 
-	ld hl, TrainerClassAttributes + 5
+	ld hl, TrainerClassAttributes + TRNATTR_AI_ITEM_SWITCH
 	ld a, [InBattleTowerBattle] ; Load always the first TrainerClass for BattleTower-Trainers
 	and a
 	jr nz, .ok
--- /dev/null
+++ b/battle/ai/move.asm
@@ -1,0 +1,222 @@
+AIChooseMove: ; 440ce
+; Score each move in EnemyMonMoves starting from Buffer1. Lower is better.
+; Pick the move with the lowest score.
+
+; Wildmons attack at random.
+	ld a, [wBattleMode]
+	dec a
+	ret z
+
+	ld a, [wLinkMode]
+	and a
+	ret nz
+
+; No use picking a move if there's no choice.
+	callba CheckSubstatus_RechargeChargedRampageBideRollout
+	ret nz
+
+
+; The default score is 20. Unusable moves are given a score of 80.
+	ld a, 20
+	ld hl, Buffer1
+rept 3
+	ld [hli], a
+endr
+	ld [hl], a
+
+; Don't pick disabled moves.
+	ld a, [EnemyDisabledMove]
+	and a
+	jr z, .CheckPP
+
+	ld hl, EnemyMonMoves
+	ld c, 0
+.CheckDisabledMove
+	cp [hl]
+	jr z, .ScoreDisabledMove
+	inc c
+	inc hl
+	jr .CheckDisabledMove
+.ScoreDisabledMove
+	ld hl, Buffer1
+	ld b, 0
+	add hl, bc
+	ld [hl], 80
+
+; Don't pick moves with 0 PP.
+.CheckPP
+	ld hl, Buffer1 - 1
+	ld de, EnemyMonPP
+	ld b, 0
+.CheckMovePP
+	inc b
+	ld a, b
+	cp EnemyMonMovesEnd - EnemyMonMoves + 1
+	jr z, .ApplyLayers
+	inc hl
+	ld a, [de]
+	inc de
+	and $3f
+	jr nz, .CheckMovePP
+	ld [hl], 80
+	jr .CheckMovePP
+
+
+; Apply AI scoring layers depending on the trainer class.
+.ApplyLayers
+	ld hl, TrainerClassAttributes + TRNATTR_AI_MOVE_WEIGHTS
+
+	; If we have a battle in BattleTower just load the Attributes of the first TrainerClass (Falkner)
+	; so we have always the same AI, regardless of the loaded class of trainer
+	ld a, [InBattleTowerBattle]
+	bit 0, a
+	jr nz, .battle_tower_skip
+
+	ld a, [TrainerClass]
+	dec a
+	ld bc, 7 ; Trainer2AI - Trainer1AI
+	call AddNTimes
+
+.battle_tower_skip
+	lb bc, CHECK_FLAG, 0
+	push bc
+	push hl
+
+.CheckLayer
+	pop hl
+	pop bc
+
+	ld a, c
+	cp 16 ; up to 16 scoring layers
+	jr z, .DecrementScores
+
+	push bc
+	ld d, BANK(TrainerClassAttributes)
+	predef FlagPredef
+	ld d, c
+	pop bc
+
+	inc c
+	push bc
+	push hl
+
+	ld a, d
+	and a
+	jr z, .CheckLayer
+
+	ld hl, AIScoringPointers
+	dec c
+	ld b, 0
+rept 2
+	add hl, bc
+endr
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+	ld a, BANK(AIScoring)
+	call FarCall_hl
+
+	jr .CheckLayer
+
+; Decrement the scores of all moves one by one until one reaches 0.
+.DecrementScores
+	ld hl, Buffer1
+	ld de, EnemyMonMoves
+	ld c, EnemyMonMovesEnd - EnemyMonMoves
+
+.DecrementNextScore
+	; If the enemy has no moves, this will infinite.
+	ld a, [de]
+	inc de
+	and a
+	jr z, .DecrementScores
+
+	; We are done whenever a score reaches 0
+	dec [hl]
+	jr z, .PickLowestScoreMoves
+
+	; If we just decremented the fourth move's score, go back to the first move
+	inc hl
+	dec c
+	jr z, .DecrementScores
+
+	jr .DecrementNextScore
+
+; In order to avoid bias towards the moves located first in memory, increment the scores
+; that were decremented one more time than the rest (in case there was a tie).
+; This means that the minimum score will be 1.
+.PickLowestScoreMoves
+	ld a, c
+
+.move_loop
+	inc [hl]
+	dec hl
+	inc a
+	cp NUM_MOVES + 1
+	jr nz, .move_loop
+
+	ld hl, Buffer1
+	ld de, EnemyMonMoves
+	ld c, NUM_MOVES
+
+; Give a score of 0 to a blank move	
+.loop2
+	ld a, [de]
+	and a
+	jr nz, .skip_load
+	ld [hl], a
+
+; Disregard the move if its score is not 1	
+.skip_load
+	ld a, [hl]
+	dec a
+	jr z, .keep
+	xor a
+	ld [hli], a
+	jr .after_toss
+
+.keep
+	ld a, [de]
+	ld [hli], a
+.after_toss
+	inc de
+	dec c
+	jr nz, .loop2
+
+; Randomly choose one of the moves with a score of 1 	
+.ChooseMove
+	ld hl, Buffer1
+	call Random
+	and 3
+	ld c, a
+	ld b, 0
+	add hl, bc
+	ld a, [hl]
+	and a
+	jr z, .ChooseMove
+
+	ld [CurEnemyMove], a
+	ld a, c
+	ld [CurEnemyMoveNum], a
+	ret
+; 441af
+
+
+AIScoringPointers: ; 441af
+	dw AI_Basic
+	dw AI_Setup
+	dw AI_Types
+	dw AI_Offensive
+	dw AI_Smart
+	dw AI_Opportunist
+	dw AI_Aggressive
+	dw AI_Cautious
+	dw AI_Status
+	dw AI_Risky
+	dw AI_None
+	dw AI_None
+	dw AI_None
+	dw AI_None
+	dw AI_None
+	dw AI_None
+; 441cf
--- a/battle/core.asm
+++ b/battle/core.asm
@@ -1,9 +1,6 @@
-BattleCore:
-
 ; Core components of the battle engine.
-
-
-SendOutFirstMons: ; 3c000
+BattleCore:
+DoBattle: ; 3c000
 	xor a
 	ld [wBattleParticipantsNotFainted], a
 	ld [wc6fc], a
@@ -83,8 +80,8 @@
 	ld [CurPartySpecies], a
 	ld [TempBattleMonSpecies], a
 	hlcoord 1, 5
-	ld a, $9
-	call Function3d490
+	ld a, 9
+	call SlideBattlePicOut
 	call LoadTileMapToTempTileMap
 	call ResetBattleParticipants
 	call InitBattleMon
@@ -113,7 +110,7 @@
 	call SpikesDamage
 
 .not_linked_2
-	jp Function3c12f
+	jp BattleTurn
 
 .tutorial_debug
 	jp BattleMenu
@@ -130,7 +127,7 @@
 	ld a, [wLinkMode]
 	and a
 	ld hl, BattleText_WildFled
-	jr z, .asm_3c115
+	jr z, .print_text
 
 	ld a, [wBattleResult]
 	and $c0
@@ -137,26 +134,26 @@
 	ld [wBattleResult], a
 	ld hl, BattleText_EnemyFled
 	call CheckMobileBattleError
-	jr nc, .asm_3c115
+	jr nc, .print_text
 
 	ld hl, wcd2a
 	bit 4, [hl]
-	jr nz, .asm_3c118
+	jr nz, .skip_text
 
 	ld hl, BattleText_LinkErrorBattleCanceled
 
-.asm_3c115
+.print_text
 	call StdBattleTextBox
 
-.asm_3c118
+.skip_text
 	call StopDangerSound
 	call CheckMobileBattleError
-	jr c, .asm_3c126
+	jr c, .skip_sfx
 
 	ld de, SFX_RUN
 	call PlaySFX
 
-.asm_3c126
+.skip_sfx
 	call SetPlayerTurn
 	ld a, 1
 	ld [BattleEnded], a
@@ -164,7 +161,7 @@
 ; 3c12f
 
 
-Function3c12f: ; 3c12f
+BattleTurn: ; 3c12f
 .loop
 	call MobileFn_3c1bf
 	call CheckContestBattleOver
@@ -2489,8 +2486,8 @@
 	bit 0, a
 	jr nz, .battle_tower
 
-	call Function3ebd8
-	ld c, $28
+	call BattleWinSlideInEnemyTrainerFrontpic
+	ld c, 40
 	call DelayFrames
 	ld a, [BattleType]
 	cp BATTLETYPE_CANLOSE
@@ -2506,7 +2503,7 @@
 	jp Function3d02b
 
 .mobile
-	call Function3ebd8
+	call BattleWinSlideInEnemyTrainerFrontpic
 	ld c, 40
 	call DelayFrames
 	ld c, $4
@@ -2514,7 +2511,7 @@
 	ret
 
 .battle_tower
-	call Function3ebd8
+	call BattleWinSlideInEnemyTrainerFrontpic
 	ld c, 40
 	call DelayFrames
 	call EmptyBattleTextBox
@@ -3111,7 +3108,7 @@
 	hlcoord 0, 0
 	lb bc, 8, 21
 	call ClearBox
-	call Function3ebd8
+	call BattleWinSlideInEnemyTrainerFrontpic
 
 	ld c, 40
 	call DelayFrames
@@ -3128,7 +3125,7 @@
 	hlcoord 0, 0
 	lb bc, 8, 21
 	call ClearBox
-	call Function3ebd8
+	call BattleWinSlideInEnemyTrainerFrontpic
 
 	ld c, 40
 	call DelayFrames
@@ -3180,7 +3177,7 @@
 	hlcoord 0, 0
 	lb bc, 8, 21
 	call ClearBox
-	call Function3ebd8
+	call BattleWinSlideInEnemyTrainerFrontpic
 
 	ld c, 40
 	call DelayFrames
@@ -3260,31 +3257,31 @@
 ; 3d490
 
 
-Function3d490: ; 3d490
+SlideBattlePicOut: ; 3d490
 	ld [hMapObjectIndexBuffer], a
 	ld c, a
-.asm_3d493
+.loop
 	push bc
 	push hl
 	ld b, $7
-.asm_3d497
+.loop2
 	push hl
-	call Function3d4ae
+	call .DoFrame
 	pop hl
 	ld de, SCREEN_WIDTH
 	add hl, de
 	dec b
-	jr nz, .asm_3d497
+	jr nz, .loop2
 	ld c, 2
 	call DelayFrames
 	pop hl
 	pop bc
 	dec c
-	jr nz, .asm_3d493
+	jr nz, .loop
 	ret
 ; 3d4ae
 
-Function3d4ae: ; 3d4ae
+.DoFrame: ; 3d4ae
 	ld a, [hMapObjectIndexBuffer]
 	ld c, a
 	cp $8
@@ -3413,8 +3410,8 @@
 	xor a
 	ld [wPlayerWrapCount], a
 	hlcoord 18, 0
-	ld a, $8
-	call Function3d490
+	ld a, 8
+	call SlideBattlePicOut
 	call EmptyBattleTextBox
 	jp LoadStandardMenuDataHeader
 ; 3d57a
@@ -4478,21 +4475,21 @@
 	call SetPlayerTurn
 	call HandleHPHealingItem
 	call UseHeldStatusHealingItem
-	call HandleStatusHealingItem
+	call UseConfusionHealingItem
 	call SetEnemyTurn
 	call HandleHPHealingItem
 	call UseHeldStatusHealingItem
-	jp HandleStatusHealingItem
+	jp UseConfusionHealingItem
 
 .player_1
 	call SetEnemyTurn
 	call HandleHPHealingItem
 	call UseHeldStatusHealingItem
-	call HandleStatusHealingItem
+	call UseConfusionHealingItem
 	call SetPlayerTurn
 	call HandleHPHealingItem
 	call UseHeldStatusHealingItem
-	jp HandleStatusHealingItem
+	jp UseConfusionHealingItem
 ; 3dd2f
 
 HandleHPHealingItem: ; 3dd2f
@@ -4672,7 +4669,7 @@
 ; 3de51
 
 
-HandleStatusHealingItem: ; 3de51
+UseConfusionHealingItem: ; 3de51
 	ld a, BATTLE_VARS_SUBSTATUS3_OPP
 	call GetBattleVar
 	bit SUBSTATUS_CONFUSED, a
@@ -4692,7 +4689,7 @@
 	res SUBSTATUS_CONFUSED, [hl]
 	call GetItemName
 	call ItemRecoveryAnim
-	ld hl, BattleText_0x80dab
+	ld hl, BattleText_ItemHealedConfusion
 	call StdBattleTextBox
 	ld a, [hBattleTurn]
 	and a
@@ -6874,7 +6871,7 @@
 	ret
 ; 3ebd8
 
-Function3ebd8: ; 3ebd8
+BattleWinSlideInEnemyTrainerFrontpic: ; 3ebd8
 	xor a
 	ld [TempEnemyMonSpecies], a
 	call FinishBattleAnim
@@ -6883,12 +6880,12 @@
 	ld de, VTiles2
 	callab GetTrainerPic
 	hlcoord 19, 0
-	ld c, $0
+	ld c, 0
 
 .outer_loop
 	inc c
 	ld a, c
-	cp $7
+	cp 7
 	ret z
 	xor a
 	ld [hBGMapMode], a
@@ -6898,9 +6895,9 @@
 	push hl
 
 .inner_loop
-	call Function3ec1a
+	call .CopyColumn
 	inc hl
-	ld a, $7
+	ld a, 7
 	add d
 	ld d, a
 	dec c
@@ -6908,7 +6905,7 @@
 
 	ld a, $1
 	ld [hBGMapMode], a
-	ld c, $4
+	ld c, 4
 	call DelayFrames
 	pop hl
 	pop bc
@@ -6916,11 +6913,11 @@
 	jr .outer_loop
 ; 3ec1a
 
-Function3ec1a: ; 3ec1a
+.CopyColumn: ; 3ec1a
 	push hl
 	push de
 	push bc
-	ld e, $7
+	ld e, 7
 
 .loop
 	ld [hl], d
@@ -6970,7 +6967,7 @@
 	ld [hli], a
 	or b
 	jr nz, .player_ok
-	ld b, $1
+	ld b, $1 ; min speed
 
 .player_ok
 	ld [hl], b
@@ -6991,7 +6988,7 @@
 	ld [hli], a
 	or b
 	jr nz, .enemy_ok
-	ld b, $1
+	ld b, $1 ; min speed
 
 .enemy_ok
 	ld [hl], b
@@ -7014,7 +7011,7 @@
 	ld [hli], a
 	or b
 	jr nz, .player_ok
-	ld b, $1
+	ld b, $1 ; min attack
 
 .player_ok
 	ld [hl], b
@@ -7033,7 +7030,7 @@
 	ld [hli], a
 	or b
 	jr nz, .enemy_ok
-	ld b, $1
+	ld b, $1 ; min attack
 
 .enemy_ok
 	ld [hl], b
@@ -7423,6 +7420,7 @@
 	and a
 	pop bc
 	jp z, .skip_stats
+
 	ld hl, MON_STAT_EXP + 1
 	add hl, bc
 	ld d, h
@@ -7767,23 +7765,25 @@
 ; 3f0d4
 
 Function3f0d4: ; 3f0d4
+; count number of battle participants
 	ld a, [wBattleParticipantsNotFainted]
 	ld b, a
-	ld c, $6
-	ld d, $0
-.asm_3f0dc
+	ld c, PARTY_LENGTH
+	ld d, 0
+.loop
 	xor a
 	srl b
 	adc d
 	ld d, a
 	dec c
-	jr nz, .asm_3f0dc
-	cp $2
+	jr nz, .loop
+	cp 2
 	ret c
+
 	ld [wd265], a
 	ld hl, EnemyMonBaseStats
-	ld c, $7
-.asm_3f0ef
+	ld c, EnemyMonEnd - EnemyMonBaseStats
+.loop2
 	xor a
 	ld [hDividend + 0], a
 	ld a, [hl]
@@ -7790,12 +7790,12 @@
 	ld [hDividend + 1], a
 	ld a, [wd265]
 	ld [hDivisor], a
-	ld b, $2
+	ld b, 2
 	call Divide
 	ld a, [hQuotient + 2]
 	ld [hli], a
 	dec c
-	jr nz, .asm_3f0ef
+	jr nz, .loop2
 	ret
 ; 3f106
 
@@ -7941,12 +7941,12 @@
 	call PrintPlayerHUD
 	ld hl, BattleMonNick
 	ld de, StringBuffer1
-	ld bc, $000b
+	ld bc, PKMN_NAME_LENGTH
 	call CopyBytes
 	call Function3dfe
 	ld de, SFX_HIT_END_OF_EXP_BAR
 	call PlaySFX
-	callba Function8e79d
+	callba AnimateEndOfExpBar
 	call WaitSFX
 	ld hl, BattleText_StringBuffer1GrewToLevel
 	call StdBattleTextBox
@@ -8481,7 +8481,7 @@
 	ld a, [TimeOfDayPal]
 	push af
 	call BattleIntro
-	call SendOutFirstMons
+	call DoBattle
 	call ExitBattle
 	pop af
 	ld [TimeOfDayPal], a
@@ -8490,9 +8490,9 @@
 ; 3f4d9
 
 
-_SendOutFirstMons: ; 3f4d9
+_DoBattle: ; 3f4d9
 ; unreferenced
-	call SendOutFirstMons
+	call DoBattle
 	ret
 ; 3f4dd
 
@@ -8586,7 +8586,7 @@
 	callba MobileFn_10606a
 	xor a
 	ld [TempEnemyMonSpecies], a
-	callab Function3957b
+	callab GetTrainerAttributes
 	callab ReadTrainerParty
 
 	ld a, [TrainerClass]
@@ -8746,7 +8746,7 @@
 	ret nz
 	call CheckPayDay
 	xor a
-	ld [wd1e9], a
+	ld [wForceEvolution], a
 	predef EvolveAfterBattle
 	callba Function2ed44
 	ret
@@ -9427,7 +9427,7 @@
 	call WaitBGMap
 	xor a
 	ld [hBGMapMode], a
-	callba SlideBattlePics
+	callba BattleIntroSlidingPics
 	ld a, $1
 	ld [hBGMapMode], a
 	ld a, $31
--- a/battle/effect_commands.asm
+++ b/battle/effect_commands.asm
@@ -7496,14 +7496,14 @@
 	ld a, BATTLE_VARS_MOVE_EFFECT
 	call GetBattleVar
 	cp EFFECT_CONFUSE_HIT
-	jr z, .asm_36d99
+	jr z, .got_effect
 	cp EFFECT_SNORE
-	jr z, .asm_36d99
+	jr z, .got_effect
 	cp EFFECT_SWAGGER
-	jr z, .asm_36d99
+	jr z, .got_effect
 	call AnimateCurrentMove
 
-.asm_36d99
+.got_effect
 	ld de, ANIM_CONFUSED
 	call PlayOpponentBattleAnim
 
@@ -7513,11 +7513,11 @@
 	call GetOpponentItem
 	ld a, b
 	cp HELD_HEAL_STATUS
-	jr z, .asm_36db0
+	jr z, .heal_confusion
 	cp HELD_HEAL_CONFUSION
 	ret nz
-.asm_36db0
-	ld hl, HandleStatusHealingItem
+.heal_confusion
+	ld hl, UseConfusionHealingItem
 	jp CallBattleCore
 ; 36db6
 
--- a/battle/sliding_intro.asm
+++ b/battle/sliding_intro.asm
@@ -1,4 +1,4 @@
-SlideBattlePics: ; 4e980
+BattleIntroSlidingPics: ; 4e980
 	ld a, [rSVBK]
 	push af
 	ld a, $5
--- a/constants/trainer_constants.asm
+++ b/constants/trainer_constants.asm
@@ -639,8 +639,8 @@
 	const TRNATTR_ITEM1
 	const TRNATTR_ITEM2
 	const TRNATTR_BASEMONEY
-	const TRNATTR_AI1
+	const TRNATTR_AI_MOVE_WEIGHTS
 	const TRNATTR_AI2
-	const TRNATTR_AI3
+	const TRNATTR_AI_ITEM_SWITCH
 	const TRNATTR_AI4
 NUM_TRAINER_ATTRIBUTES EQU const_value
--- a/engine/breeding/egg.asm
+++ b/engine/breeding/egg.asm
@@ -678,7 +678,7 @@
 	push hl
 	push de
 	push bc
-	callab Function8cf69
+	callab PlaySpriteAnimations
 	call DelayFrame
 	pop bc
 	pop de
@@ -789,9 +789,9 @@
 	ret nc
 	swap a
 	srl a
-	add $4c
+	add 9 * 8 + 4
 	ld d, a
-	ld e, $58
+	ld e, 11 * 8
 	ld a, SPRITE_ANIM_INDEX_19
 	call _InitSpriteAnimStruct
 	ld hl, $3
@@ -807,10 +807,10 @@
 
 Function173b3: ; 173b3 (5:73b3)
 	callba Function8cf53
-	ld hl, Unknown_173ef
+	ld hl, .SpriteData
 .loop
 	ld a, [hli]
-	cp $ff
+	cp -1
 	jr z, .done
 	ld e, a
 	ld a, [hli]
@@ -823,16 +823,16 @@
 	push bc
 	ld a, SPRITE_ANIM_INDEX_1C
 	call _InitSpriteAnimStruct
-	ld hl, $3
+	ld hl, SpriteAnim1TileID - SpriteAnim1
 	add hl, bc
 	ld [hl], $0
 	pop de
 	ld a, e
-	ld hl, $1
+	ld hl, SpriteAnim1Sprite01 - SpriteAnim1
 	add hl, bc
 	add [hl]
 	ld [hl], a
-	ld hl, $b
+	ld hl, SpriteAnim1Sprite0b - SpriteAnim1
 	add hl, bc
 	ld [hl], d
 	pop hl
@@ -844,19 +844,19 @@
 	ret
 ; 173ef (5:73ef)
 
-Unknown_173ef: ; 173ef
+.SpriteData: ; 173ef
 ; Probably OAM.
-	db $54, $48, $00, $3c
-	db $5c, $48, $01, $04
-	db $54, $50, $00, $30
-	db $5c, $50, $01, $10
-	db $54, $58, $02, $24
-	db $5c, $58, $03, $1c
-	db $50, $4c, $00, $36
-	db $60, $4c, $01, $0a
-	db $50, $54, $02, $2a
-	db $60, $54, $03, $16
-	db $ff
+	dsprite 10, 4,  9, 0, $00, $3c
+	dsprite 11, 4,  9, 0, $01, $04
+	dsprite 10, 4, 10, 0, $00, $30
+	dsprite 11, 4, 10, 0, $01, $10
+	dsprite 10, 4, 11, 0, $02, $24
+	dsprite 11, 4, 11, 0, $03, $1c
+	dsprite 10, 0,  9, 4, $00, $36
+	dsprite 12, 0,  9, 4, $01, $0a
+	dsprite 10, 0, 10, 4, $02, $2a
+	dsprite 12, 0, 10, 4, $03, $16
+	db -1
 ; 17418
 
 Function17418: ; 17418 (5:7418)
--- a/engine/crystal_intro.asm
+++ b/engine/crystal_intro.asm
@@ -52,7 +52,7 @@
 	bit 7, a
 	jr nz, .finish
 	call PlaceGameFreakPresents
-	callba Function8cf69
+	callba PlaySpriteAnimations
 	call DelayFrame
 	jr .joy_loop
 
@@ -406,7 +406,7 @@
 	bit 7, a
 	jr nz, .done
 	call IntroSceneJumper
-	callba Function8cf69
+	callba PlaySpriteAnimations
 	call DelayFrame
 	jp .loop
 
--- a/engine/debug.asm
+++ b/engine/debug.asm
@@ -425,7 +425,7 @@
 .asm_81b7a
 	ld a, [wd265]
 	ld [TrainerClass], a
-	callab Function3957b
+	callab GetTrainerAttributes
 	ld de, StringBuffer1
 	hlcoord 4, 1
 	call PlaceString
--- a/engine/dummy_game.asm
+++ b/engine/dummy_game.asm
@@ -47,7 +47,7 @@
 	bit 7, a
 	jr nz, .asm_e1ed0
 	call Functione1ed2
-	callab Function8cf69
+	callab PlaySpriteAnimations
 	call DelayFrame
 	and a
 	ret
@@ -89,7 +89,7 @@
 ; e1efb
 
 Functione1efb: ; e1efb
-	call Functione00ed
+	call ret_e00ed
 	jr nc, .asm_e1f06
 	ld hl, wJumptableIndex
 	set 7, [hl]
@@ -251,7 +251,7 @@
 	inc [hl]
 
 Functione2000: ; e2000
-	call Functione00ed
+	call ret_e00ed
 	jr nc, .asm_e200b
 	ld hl, wJumptableIndex
 	set 7, [hl]
--- a/engine/events.asm
+++ b/engine/events.asm
@@ -491,11 +491,11 @@
 	bit 3, [hl]
 	jr z, .nope
 
-	ld hl, ScriptDelay + 2
+	ld hl, wPriorityScriptAddr
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
-	ld a, [ScriptDelay + 1]
+	ld a, [wPriorityScriptBank]
 	call CallScript
 	scf
 	ret
--- a/engine/evolution_animation.asm
+++ b/engine/evolution_animation.asm
@@ -21,7 +21,7 @@
 	pop de
 	pop hl
 
-	ld a, [wd1ed]
+	ld a, [Buffer4]
 	and a
 	ret z
 
@@ -99,7 +99,7 @@
 
 	call .ReplaceFrontpic
 	xor a
-	ld [wd1ed], a
+	ld [Buffer4], a
 
 	ld a, [Buffer2]
 	ld [PlayerHPPal], a
@@ -136,7 +136,7 @@
 
 .cancel_evo
 	ld a, $1
-	ld [wd1ed], a
+	ld [Buffer4], a
 
 	ld a, [Buffer1]
 	ld [PlayerHPPal], a
@@ -252,7 +252,7 @@
 	ret
 
 .pressed_b
-	ld a, [wd1e9]
+	ld a, [wForceEvolution]
 	and a
 	jr nz, .loop3
 	scf
@@ -270,7 +270,7 @@
 ; 4e7a6
 
 Function4e7a6: ; 4e7a6
-	ld a, [wd1ed]
+	ld a, [Buffer4]
 	and a
 	ret nz
 	ld de, SFX_EVOLVED
@@ -286,7 +286,7 @@
 	jr .loop
 
 .done
-	ld c, $20
+	ld c, 32
 .loop2
 	call Function4e80c
 	dec c
@@ -299,7 +299,7 @@
 Function4e7cf: ; 4e7cf
 	ld hl, wJumptableIndex
 	ld a, [hl]
-	cp $20
+	cp 32
 	ret nc
 	ld d, a
 	inc [hl]
@@ -317,8 +317,8 @@
 
 Function4e7e8: ; 4e7e8
 	push de
-	lb de, $48, $58
-	ld a, $13
+	depixel 9, 11
+	ld a, SPRITE_ANIM_INDEX_13
 	call _InitSpriteAnimStruct
 	ld hl, $b
 	add hl, bc
@@ -339,7 +339,7 @@
 
 Function4e80c: ; 4e80c
 	push bc
-	callab Function8cf69
+	callab PlaySpriteAnimations
 	; a = (([hVBlankCounter] + 4) / 2) % NUM_PALETTES
 	ld a, [hVBlankCounter]
 	and $e
@@ -369,88 +369,3 @@
 EvolutionGFX:
 INCBIN "gfx/evo/bubble_large.2bpp"
 INCBIN "gfx/evo/bubble.2bpp"
-
-Function4e881: ; 4e881
-	call ClearBGPalettes
-	call ClearTileMap
-	call ClearSprites
-	call DisableLCD
-	call LoadStandardFont
-	call LoadFontsBattleExtra
-	hlbgcoord 0, 0
-	ld bc, VBGMap1 - VBGMap0
-	ld a, " "
-	call ByteFill
-	hlcoord 0, 0, AttrMap
-	ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
-	xor a
-	call ByteFill
-	xor a
-	ld [hSCY], a
-	ld [hSCX], a
-	call EnableLCD
-	ld hl, .SavingRecordDontTurnOff
-	call PrintText
-	call Function3200
-	call SetPalettes
-	ret
-; 4e8bd
-
-.SavingRecordDontTurnOff: ; 0x4e8bd
-	; SAVING RECORD… DON'T TURN OFF!
-	text_jump UnknownText_0x1bd39e
-	db "@"
-; 0x4e8c2
-
-
-Function4e8c2: ; 4e8c2
-	call ClearBGPalettes
-	call ClearTileMap
-	call ClearSprites
-	call DisableLCD
-	call LoadStandardFont
-	call LoadFontsBattleExtra
-	hlbgcoord 0, 0
-	ld bc, VBGMap1 - VBGMap0
-	ld a, " "
-	call ByteFill
-	hlcoord 0, 0, AttrMap
-	ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
-	xor a
-	call ByteFill
-	ld hl, wd000 ; UnknBGPals
-	ld c, 4 * $10
-.load_white_palettes
-	ld a, (palred 31 + palgreen 31 + palblue 31) % $100
-	ld [hli], a
-	ld a, (palred 31 + palgreen 31 + palblue 31) / $100
-	ld [hli], a
-	dec c
-	jr nz, .load_white_palettes
-	xor a
-	ld [hSCY], a
-	ld [hSCX], a
-	call EnableLCD
-	call Function3200
-	call SetPalettes
-	ret
-; 4e906
-
-Function4e906: ; 4e906
-	ld a, [rSVBK]
-	push af
-	ld a, $6
-	ld [rSVBK], a
-	ld hl, w6_d000
-	ld bc, w6_d400 - w6_d000
-	ld a, " "
-	call ByteFill
-	hlbgcoord 0, 0
-	ld de, w6_d000
-	ld b, $0
-	ld c, $40
-	call Request2bpp
-	pop af
-	ld [rSVBK], a
-	ret
-; 4e929
--- a/engine/evolve.asm
+++ b/engine/evolve.asm
@@ -78,7 +78,7 @@
 	cp EVOLVE_ITEM
 	jp z, .item
 
-	ld a, [wd1e9]
+	ld a, [wForceEvolution]
 	and a
 	jp nz, .dont_evolve_2
 
@@ -179,7 +179,7 @@
 	cp b
 	jp nz, .dont_evolve_3
 
-	ld a, [wd1e9]
+	ld a, [wForceEvolution]
 	and a
 	jp z, .dont_evolve_3
 	ld a, [wLinkMode]
--- /dev/null
+++ b/engine/learn.asm
@@ -1,0 +1,257 @@
+LearnMove: ; 6508
+	call LoadTileMapToTempTileMap
+	ld a, [CurPartyMon]
+	ld hl, PartyMonNicknames
+	call GetNick
+	ld hl, StringBuffer1
+	ld de, wd050_MonNick
+	ld bc, PKMN_NAME_LENGTH
+	call CopyBytes
+
+.loop
+	ld hl, PartyMon1Moves
+	ld bc, PARTYMON_STRUCT_LENGTH
+	ld a, [CurPartyMon]
+	call AddNTimes
+	ld d, h
+	ld e, l
+	ld b, NUM_MOVES
+; Get the first empty move slot.  This routine also serves to
+; determine whether the Pokemon learning the moves already has
+; all four slots occupied, in which case one would need to be
+; deleted.
+.next
+	ld a, [hl]
+	and a
+	jr z, .learn
+	inc hl
+	dec b
+	jr nz, .next
+; If we're here, we enter the routine for forgetting a move
+; to make room for the new move we're trying to learn.
+	push de
+	call ForgetMove
+	pop de
+	jp c, .cancel
+
+	push hl
+	push de
+	ld [wd265], a
+
+	ld b, a
+	ld a, [wBattleMode]
+	and a
+	jr z, .not_disabled
+	ld a, [DisabledMove]
+	cp b
+	jr nz, .not_disabled
+	xor a
+	ld [DisabledMove], a
+	ld [PlayerDisableCount], a
+.not_disabled
+
+	call GetMoveName
+	ld hl, UnknownText_0x6684 ; 1, 2 and…
+	call PrintText
+	pop de
+	pop hl
+
+.learn
+	ld a, [wd262]
+	ld [hl], a
+	ld bc, MON_PP - MON_MOVES
+	add hl, bc
+
+	push hl
+	push de
+	dec a
+	ld hl, Moves + MOVE_PP
+	ld bc, MOVE_LENGTH
+	call AddNTimes
+	ld a, BANK(Moves)
+	call GetFarByte
+	pop de
+	pop hl
+
+	ld [hl], a
+
+	ld a, [wBattleMode]
+	and a
+	jp z, .learned
+
+	ld a, [CurPartyMon]
+	ld b, a
+	ld a, [CurBattleMon]
+	cp b
+	jp nz, .learned
+
+	ld a, [PlayerSubStatus5]
+	bit SUBSTATUS_TRANSFORMED, a
+	jp nz, .learned
+
+	ld h, d
+	ld l, e
+	ld de, BattleMonMoves
+	ld bc, NUM_MOVES
+	call CopyBytes
+	ld bc, PartyMon1PP - (PartyMon1Moves + NUM_MOVES)
+	add hl, bc
+	ld de, BattleMonPP
+	ld bc, NUM_MOVES
+	call CopyBytes
+	jp .learned
+
+.cancel
+	ld hl, UnknownText_0x6675 ; Stop learning <MOVE>?
+	call PrintText
+	call YesNoBox
+	jp c, .loop
+
+	ld hl, UnknownText_0x667a ; <MON> did not learn <MOVE>.
+	call PrintText
+	ld b, 0
+	ret
+
+.learned
+	ld hl, UnknownText_0x666b ; <MON> learned <MOVE>!
+	call PrintText
+	ld b, 1
+	ret
+; 65d3
+
+ForgetMove: ; 65d3
+	push hl
+	ld hl, UnknownText_0x667f
+	call PrintText
+	call YesNoBox
+	pop hl
+	ret c
+	ld bc, -NUM_MOVES
+	add hl, bc
+	push hl
+	ld de, wListMoves_MoveIndicesBuffer
+	ld bc, NUM_MOVES
+	call CopyBytes
+	pop hl
+.loop
+	push hl
+	ld hl, UnknownText_0x6670
+	call PrintText
+	hlcoord 5, 2
+	ld b, NUM_MOVES * 2
+	ld c, MOVE_NAME_LENGTH
+	call TextBox
+	hlcoord 5 + 2, 2 + 2
+	ld a, SCREEN_WIDTH * 2
+	ld [Buffer1], a
+	predef ListMoves
+	; wMenuData3
+	ld a, $4
+	ld [wcfa1], a
+	ld a, $6
+	ld [wcfa2], a
+	ld a, [wd0eb]
+	inc a
+	ld [wcfa3], a
+	ld a, $1
+	ld [wcfa4], a
+	ld [MenuSelection2], a
+	ld [wcfaa], a
+	ld a, $3
+	ld [wcfa8], a
+	ld a, $20
+	ld [wcfa5], a
+	xor a
+	ld [wcfa6], a
+	ld a, $20
+	ld [wcfa7], a
+	call Function1bc9
+	push af
+	call Call_LoadTempTileMapToTileMap
+	pop af
+	pop hl
+	bit 1, a
+	jr nz, .cancel
+	push hl
+	ld a, [MenuSelection2]
+	dec a
+	ld c, a
+	ld b, 0
+	add hl, bc
+	ld a, [hl]
+	push af
+	push bc
+	call IsHMMove
+	pop bc
+	pop de
+	ld a, d
+	jr c, .hmmove
+	pop hl
+	add hl, bc
+	and a
+	ret
+
+.hmmove
+	ld hl, UnknownText_0x669a
+	call PrintText
+	pop hl
+	jr .loop
+
+.cancel
+	scf
+	ret
+; 666b
+
+UnknownText_0x666b: ; 666b
+; <MON> learned <MOVE>!
+	text_jump UnknownText_0x1c5660
+	db "@"
+; 6670
+
+UnknownText_0x6670: ; 6670
+; Which move should be forgotten?
+	text_jump UnknownText_0x1c5678
+	db "@"
+; 6675
+
+UnknownText_0x6675: ; 6675
+; Stop learning <MOVE>?
+	text_jump UnknownText_0x1c5699
+	db "@"
+; 667a
+
+UnknownText_0x667a: ; 667a
+; <MON> did not learn <MOVE>.
+	text_jump UnknownText_0x1c56af
+	db "@"
+; 667f
+
+UnknownText_0x667f: ; 667f
+; <MON> is trying to learn <MOVE>. But <MON> can't learn more than
+; four moves. Delete an older move to make room for <MOVE>?
+	text_jump UnknownText_0x1c56c9
+	db "@"
+; 6684
+
+UnknownText_0x6684: ; 6684
+	text_jump UnknownText_0x1c5740 ; 1, 2 and…
+	start_asm
+	push de
+	ld de, SFX_SWITCH_POKEMON
+	call PlaySFX
+	pop de
+	ld hl, UnknownText_0x6695
+	ret
+; 6695
+
+UnknownText_0x6695: ; 6695
+; Poof! <MON> forgot <MOVE>. And…
+	text_jump UnknownText_0x1c574e
+	db "@"
+; 669a
+
+UnknownText_0x669a: ; 669a
+; HM moves can't be forgotten now.
+	text_jump UnknownText_0x1c5772
+	db "@"
+; 669f
--- a/engine/link.asm
+++ b/engine/link.asm
@@ -1891,7 +1891,7 @@
 	dec a
 	ld [CurPartyMon], a
 	ld a, $1
-	ld [wd1e9], a
+	ld [wForceEvolution], a
 	ld a, [wd003]
 	push af
 	ld hl, OTPartySpecies
--- /dev/null
+++ b/engine/math.asm
@@ -1,0 +1,196 @@
+_Multiply:: ; 66de
+
+; hMultiplier is one byte.
+	ld a, 8
+	ld b, a
+
+	xor a
+	ld [hProduct], a
+	ld [hMathBuffer + 1], a
+	ld [hMathBuffer + 2], a
+	ld [hMathBuffer + 3], a
+	ld [hMathBuffer + 4], a
+
+
+.loop
+	ld a, [hMultiplier]
+	srl a
+	ld [hMultiplier], a
+	jr nc, .next
+
+	ld a, [hMathBuffer + 4]
+	ld c, a
+	ld a, [hMultiplicand + 2]
+	add c
+	ld [hMathBuffer + 4], a
+
+	ld a, [hMathBuffer + 3]
+	ld c, a
+	ld a, [hMultiplicand + 1]
+	adc c
+	ld [hMathBuffer + 3], a
+
+	ld a, [hMathBuffer + 2]
+	ld c, a
+	ld a, [hMultiplicand + 0]
+	adc c
+	ld [hMathBuffer + 2], a
+
+	ld a, [hMathBuffer + 1]
+	ld c, a
+	ld a, [hProduct]
+	adc c
+	ld [hMathBuffer + 1], a
+
+.next
+	dec b
+	jr z, .done
+
+
+; hMultiplicand <<= 1
+
+	ld a, [hMultiplicand + 2]
+	add a
+	ld [hMultiplicand + 2], a
+
+	ld a, [hMultiplicand + 1]
+	rla
+	ld [hMultiplicand + 1], a
+
+	ld a, [hMultiplicand + 0]
+	rla
+	ld [hMultiplicand + 0], a
+
+	ld a, [hProduct]
+	rla
+	ld [hProduct], a
+
+	jr .loop
+
+
+.done
+	ld a, [hMathBuffer + 4]
+	ld [hProduct + 3], a
+
+	ld a, [hMathBuffer + 3]
+	ld [hProduct + 2], a
+
+	ld a, [hMathBuffer + 2]
+	ld [hProduct + 1], a
+
+	ld a, [hMathBuffer + 1]
+	ld [hProduct + 0], a
+
+	ret
+; 673e
+
+
+_Divide:: ; 673e
+	xor a
+	ld [hMathBuffer + 0], a
+	ld [hMathBuffer + 1], a
+	ld [hMathBuffer + 2], a
+	ld [hMathBuffer + 3], a
+	ld [hMathBuffer + 4], a
+
+	ld a, 9
+	ld e, a
+
+.loop
+	ld a, [hMathBuffer + 0]
+	ld c, a
+	ld a, [hDividend + 1]
+	sub c
+	ld d, a
+
+	ld a, [hDivisor]
+	ld c, a
+	ld a, [hDividend + 0]
+	sbc c
+	jr c, .next
+
+	ld [hDividend + 0], a
+
+	ld a, d
+	ld [hDividend + 1], a
+
+	ld a, [hMathBuffer + 4]
+	inc a
+	ld [hMathBuffer + 4], a
+
+	jr .loop
+
+.next
+	ld a, b
+	cp 1
+	jr z, .done
+
+	ld a, [hMathBuffer + 4]
+	add a
+	ld [hMathBuffer + 4], a
+
+	ld a, [hMathBuffer + 3]
+	rla
+	ld [hMathBuffer + 3], a
+
+	ld a, [hMathBuffer + 2]
+	rla
+	ld [hMathBuffer + 2], a
+
+	ld a, [hMathBuffer + 1]
+	rla
+	ld [hMathBuffer + 1], a
+
+	dec e
+	jr nz, .next2
+
+	ld e, 8
+	ld a, [hMathBuffer + 0]
+	ld [hDivisor], a
+	xor a
+	ld [hMathBuffer + 0], a
+
+	ld a, [hDividend + 1]
+	ld [hDividend + 0], a
+
+	ld a, [hDividend + 2]
+	ld [hDividend + 1], a
+
+	ld a, [hDividend + 3]
+	ld [hDividend + 2], a
+
+.next2
+	ld a, e
+	cp 1
+	jr nz, .okay
+	dec b
+
+.okay
+	ld a, [hDivisor]
+	srl a
+	ld [hDivisor], a
+
+	ld a, [hMathBuffer + 0]
+	rr a
+	ld [hMathBuffer + 0], a
+
+	jr .loop
+
+.done
+	ld a, [hDividend + 1]
+	ld [hDivisor], a
+
+	ld a, [hMathBuffer + 4]
+	ld [hDividend + 3], a
+
+	ld a, [hMathBuffer + 3]
+	ld [hDividend + 2], a
+
+	ld a, [hMathBuffer + 2]
+	ld [hDividend + 1], a
+
+	ld a, [hMathBuffer + 1]
+	ld [hDividend + 0], a
+
+	ret
+; 67c1
--- a/engine/party_menu.asm
+++ b/engine/party_menu.asm
@@ -670,7 +670,7 @@
 	pop bc
 	dec c
 	jr nz, .loop
-	callab Function8cf69
+	callab PlaySpriteAnimations
 	ret
 ; 50405
 
--- a/engine/pokedex.asm
+++ b/engine/pokedex.asm
@@ -323,7 +323,7 @@
 	call Function4134f
 	call Function40bb1
 	ld [wc2d6], a
-	callba Function4424d
+	callba DisplayDexEntry
 	call Function40ba0
 	call WaitBGMap
 	ld a, $a7
@@ -378,7 +378,7 @@
 	ld [wPokedexStatus], a
 	call Function40bb1
 	ld [wc2d6], a
-	callba Function4424d
+	callba DisplayDexEntry
 	call WaitBGMap
 	ret
 ; 402aa
@@ -394,7 +394,7 @@
 	call Function41478
 	call Function40bb1
 	ld [wc2d6], a
-	callba Function4424d
+	callba DisplayDexEntry
 	call Function40ba0
 	call Function4143b
 	call WaitBGMap
@@ -498,7 +498,7 @@
 Function4038d: ; 4038d
 	call Function407fd
 	call Function40bb1
-	callba Function4424d
+	callba DisplayDexEntry
 	call Function40ba0
 	ret
 ; 4039d
@@ -621,8 +621,8 @@
 	ld [wc7d6], a
 	call Function40fa8
 	xor a
-	ld [wc7db], a
-	callba Function44207
+	ld [wDexSearchSlowpokeFrame], a
+	callba DoDexSearchSlowpokeFrame
 	call WaitBGMap
 	ld a, $10
 	call Function41423
@@ -679,7 +679,7 @@
 
 Function404b7: ; 404b7
 	call Function41086
-	callba Function441cf
+	callba AnimateDexSearchSlowpoke
 	ld a, [wc7d7]
 	and a
 	jr nz, .asm_404dc
@@ -2557,7 +2557,6 @@
 	ret
 ; 41a58
 
-
 Function41a58: ; 41a58 (10:5a58)
 	ld a, [UnownLetter]
 	push af
@@ -2576,3 +2575,68 @@
 	pop af
 	ld [UnownLetter], a
 	ret
+; 41a7f
+
+Function41a7f: ; 41a7f
+	xor a
+	ld [hBGMapMode], a
+	callba Function1de247
+	call Function41af7
+	call DisableLCD
+	call LoadStandardFont
+	call LoadFontsExtra
+	call Function414b7
+	call Function4147b
+	ld a, [wd265]
+	ld [CurPartySpecies], a
+	call Function407fd
+	call Function40ba0
+	hlcoord 0, 17
+	ld [hl], $3b
+	inc hl
+	ld bc, $13
+	ld a, " "
+	call ByteFill
+	callba DisplayDexEntry
+	call EnableLCD
+	call WaitBGMap
+	call GetBaseData
+	ld de, VTiles2
+	predef GetFrontpic
+	ld a, $4
+	call Function41423
+	ld a, [CurPartySpecies]
+	call PlayCry
+	ret
+; 41ad7
+
+
+Function41ad7: ; 41ad7 (10:5ad7)
+	ld a, $3
+	ld [hBGMapMode], a
+	ld c, 4
+	call DelayFrames
+	ret
+
+Function41ae1: ; 41ae1 (10:5ae1)
+	ld a, $4
+	ld [hBGMapMode], a
+	ld c, 4
+	call DelayFrames
+	ret
+
+Function41aeb: ; 41aeb (10:5aeb)
+	ld a, [hCGB]
+	and a
+	jr z, .asm_41af3
+	call Function41ae1
+.asm_41af3
+	call Function41ad7
+	ret
+
+
+Function41af7: ; 41af7
+	xor a
+	ld [hBGMapMode], a
+	ret
+; 41afb
--- a/engine/pokegear.asm
+++ b/engine/pokegear.asm
@@ -24,7 +24,7 @@
 	bit 7, a
 	jr nz, .done
 	call Function90f04
-	callba Function8cf69
+	callba PlaySpriteAnimations
 	call DelayFrame
 	jr .loop
 
@@ -1966,7 +1966,7 @@
 	jr nz, .pressedA
 	call FlyMapScroll
 	call GetMapCursorCoordinates
-	callba Function8cf69
+	callba PlaySpriteAnimations
 	call DelayFrame
 	jr .loop
 
@@ -2901,7 +2901,7 @@
 	jr nz, .pressedA
 	call Function923b8
 	call GetMapCursorCoordinates
-	callba Function8cf69
+	callba PlaySpriteAnimations
 	call DelayFrame
 	jr .loop
 
--- a/engine/printer.asm
+++ b/engine/printer.asm
@@ -672,7 +672,7 @@
 	call Function84000
 	ld a, $10
 	ld [wcbfa], a
-	callba Function1dc1b0
+	callba PrintPage1
 	call ClearTileMap
 	ld a, $e4
 	call DmgToCgbBGPals
@@ -694,7 +694,7 @@
 	call Function84000
 	ld a, $3
 	ld [wcbfa], a
-	callba Function1dc213
+	callba PrintPage2
 	call Function84742
 	ld a, $4
 	ld [wcf65], a
--- a/engine/scripting.asm
+++ b/engine/scripting.asm
@@ -316,11 +316,11 @@
 ;     text_pointer (RawTextPointerLabelParam)
 
 	ld a, [ScriptBank]
-	ld [wd44e], a
+	ld [wScriptTextBank], a
 	call GetScriptByte
-	ld [wd44f], a
+	ld [wScriptTextAddr], a
 	call GetScriptByte
-	ld [wd450], a
+	ld [wScriptTextAddr + 1], a
 	ld b, BANK(JumpTextFacePlayerScript)
 	ld hl, JumpTextFacePlayerScript
 	jp ScriptJump
@@ -332,11 +332,11 @@
 ;     text_pointer (RawTextPointerLabelParam)
 
 	ld a, [ScriptBank]
-	ld [wd44e], a
+	ld [wScriptTextBank], a
 	call GetScriptByte
-	ld [wd44f], a
+	ld [wScriptTextAddr], a
 	call GetScriptByte
-	ld [wd450], a
+	ld [wScriptTextAddr + 1], a
 	ld b, BANK(JumpTextScript)
 	ld hl, JumpTextScript
 	jp ScriptJump
@@ -361,11 +361,11 @@
 ;     text_pointer (PointerLabelBeforeBank)
 
 	call GetScriptByte
-	ld [wd44e], a
+	ld [wScriptTextBank], a
 	call GetScriptByte
-	ld [wd44f], a
+	ld [wScriptTextAddr], a
 	call GetScriptByte
-	ld [wd450], a
+	ld [wScriptTextAddr + 1], a
 	ld b, BANK(JumpTextScript)
 	ld hl, JumpTextScript
 	jp ScriptJump
@@ -419,7 +419,7 @@
 	ld a, l
 	cp -1
 	jr nz, .done
-	ld hl, wd44e
+	ld hl, wScriptTextBank
 	ld a, [hli]
 	ld b, a
 	ld a, [hli]
@@ -427,6 +427,7 @@
 	ld l, a
 	call MapTextbox
 	ret
+
 .done
 	ret
 ; 96ed9
@@ -1862,11 +1863,11 @@
 ;     pointer (ScriptPointerLabelParam)
 
 	ld a, [ScriptBank]
-	ld [wd44e], a
+	ld [wPriorityScriptBank], a
 	call GetScriptByte
-	ld [wd44f], a
+	ld [wPriorityScriptAddr], a
 	call GetScriptByte
-	ld [wd450], a
+	ld [wPriorityScriptAddr + 1], a
 	ld hl, ScriptFlags
 	set 3, [hl]
 	ret
@@ -3217,8 +3218,6 @@
 ; script command 0xa2
 
 	callba RedCredits
-	; fallthrough
-
 DisplayCredits:
 	call Script_resetfuncs
 	ld a, $3
--- a/engine/sprites.asm
+++ b/engine/sprites.asm
@@ -12,12 +12,12 @@
 ; 8cf62
 
 Function8cf62: ; 8cf62
-	call Function8cf69
+	call PlaySpriteAnimations
 	call DelayFrame
 	ret
 ; 8cf69
 
-Function8cf69: ; 8cf69
+PlaySpriteAnimations: ; 8cf69
 	push hl
 	push de
 	push bc
@@ -35,7 +35,7 @@
 ; 8cf7a
 
 Function8cf7a: ; 8cf7a
-	ld hl, wc314
+	ld hl, wSpriteAnimationStructs
 	ld e, 10 ; There are 10 structs here.
 
 .loop
@@ -114,10 +114,10 @@
 	ret
 
 InitSpriteAnimStruct:: ; 8cfd6
-; Find if there's any room in the wc314 array, which is 10x16
+; Find if there's any room in the wSpriteAnimationStructs array, which is 10x16
 	push de
 	push af
-	ld hl, wc314
+	ld hl, wSpriteAnimationStructs
 	ld e, 10
 .loop
 	ld a, [hl]
@@ -221,8 +221,8 @@
 
 
 Function8d03d: ; 8d03d (23:503d)
-; Clear the index field of every struct in the wc314 array.
-	ld hl, wc314
+; Clear the index field of every struct in the wSpriteAnimationStructs array.
+	ld hl, wSpriteAnimationStructs
 	ld bc, $10
 	ld e, 10
 	xor a
@@ -622,7 +622,7 @@
 	dw .sixteen
 	dw .seventeen
 	dw .eighteen
-	dw .nineteen
+	dw .nineteen    ; finish egg hatching animation
 	dw .twenty
 	dw .twentyone
 	dw .twentytwo   ; flying sprite
@@ -761,7 +761,7 @@
 	ld a, [hl]
 	add $3
 	ld [hl], a
-	call .asm_8d6de
+	call .ApplyYOffset
 	ld hl, $7
 	add hl, bc
 	ld [hl], a
@@ -779,7 +779,7 @@
 	inc a
 	ld [hl], a
 	ld d, $2
-	call .asm_8d6de
+	call .ApplyYOffset
 	ld hl, $7
 	add hl, bc
 	ld [hl], a
@@ -818,13 +818,13 @@
 	ld a, [hl]
 	push af
 	push de
-	call .asm_8d6de
+	call .ApplyYOffset
 	ld hl, $7
 	add hl, bc
 	ld [hl], a
 	pop de
 	pop af
-	call .asm_8d6e2
+	call .ApplyXOffset
 	ld hl, $6
 	add hl, bc
 	ld [hl], a
@@ -856,13 +856,13 @@
 	ld a, [hl]
 	push af
 	push de
-	call .asm_8d6de
+	call .ApplyYOffset
 	ld hl, $7
 	add hl, bc
 	ld [hl], a
 	pop de
 	pop af
-	call .asm_8d6e2
+	call .ApplyXOffset
 	ld hl, $6
 	add hl, bc
 	ld [hl], a
@@ -947,7 +947,7 @@
 .asm_8d462
 	ld a, e
 	ld d, $20
-	call .asm_8d6de
+	call .ApplyYOffset
 	ld hl, $7
 	add hl, bc
 	ld [hl], a
@@ -954,7 +954,7 @@
 	ret
 
 .thirteen: ; 8d46e (23:546e)
-	callab Functione00ed
+	callab ret_e00ed
 	ret
 
 .fifteen: ; 8d475 (23:5475)
@@ -1014,7 +1014,7 @@
 	jr c, .asm_8d4cd
 	dec [hl]
 	ld d, $28
-	call .asm_8d6de
+	call .ApplyYOffset
 	ld hl, $7
 	add hl, bc
 	ld [hl], a
@@ -1049,7 +1049,7 @@
 	ld hl, $c
 	add hl, bc
 	ld a, [hl]
-	call Function8e72c
+	call ApplyYOffset
 	ld hl, $7
 	add hl, bc
 	ld [hl], a
@@ -1108,33 +1108,36 @@
 	ret
 
 .nineteen: ; 8d54a (23:554a)
-	ld hl, $c
+	ld hl, SpriteAnim1Sprite0c - SpriteAnim1
 	add hl, bc
 	ld a, [hl]
 	cp $80
-	jr nc, .asm_8d574
+	jr nc, .finish_nineteen
 	ld d, a
 	add $8
 	ld [hl], a
-	ld hl, $b
+	ld hl, SpriteAnim1Sprite0b - SpriteAnim1
 	add hl, bc
 	ld a, [hl]
 	xor $20
 	ld [hl], a
+
 	push af
 	push de
-	call .asm_8d6de
-	ld hl, $7
+	call .ApplyYOffset
+	ld hl, SpriteAnim1YOffset - SpriteAnim1
 	add hl, bc
 	ld [hl], a
+
 	pop de
 	pop af
-	call .asm_8d6e2
-	ld hl, $6
+	call .ApplyXOffset
+	ld hl, SpriteAnim1XOffset - SpriteAnim1
 	add hl, bc
 	ld [hl], a
 	ret
-.asm_8d574
+
+.finish_nineteen
 	call Function8d036
 	ret
 
@@ -1165,13 +1168,13 @@
 endr
 	push af
 	push de
-	call .asm_8d6de
+	call .ApplyYOffset
 	ld hl, $7
 	add hl, bc
 	ld [hl], a
 	pop de
 	pop af
-	call .asm_8d6e2
+	call .ApplyXOffset
 	ld hl, $6
 	add hl, bc
 	ld [hl], a
@@ -1207,7 +1210,7 @@
 	add hl, bc
 	ld a, [hl]
 	inc [hl]
-	call .asm_8d6e2
+	call .ApplyXOffset
 	ld hl, $6
 	add hl, bc
 	ld [hl], a
@@ -1230,7 +1233,7 @@
 	add hl, bc
 	ld a, [hl]
 	inc [hl]
-	call .asm_8d6e2
+	call .ApplyXOffset
 	ld hl, $6
 	add hl, bc
 	ld [hl], a
@@ -1263,7 +1266,7 @@
 	add hl, bc
 	ld a, [hl]
 	inc [hl]
-	call .asm_8d6e2
+	call .ApplyXOffset
 	ld hl, $6
 	add hl, bc
 	ld [hl], a
@@ -1294,7 +1297,7 @@
 	xor $ff
 	inc a
 	ld d, $20
-	call .asm_8d6de
+	call .ApplyYOffset
 	ld hl, $7
 	add hl, bc
 	ld [hl], a
@@ -1313,7 +1316,7 @@
 	xor $ff
 	inc a
 	ld d, $20
-	call .asm_8d6de
+	call .ApplyYOffset
 	ld hl, $7
 	add hl, bc
 	ld [hl], a
@@ -1332,13 +1335,13 @@
 	ld a, [hl]
 	push af
 	push de
-	call .asm_8d6de
+	call .ApplyYOffset
 	ld hl, $7
 	add hl, bc
 	ld [hl], a
 	pop de
 	pop af
-	call .asm_8d6e2
+	call .ApplyXOffset
 	ld hl, $6
 	add hl, bc
 	ld [hl], a
@@ -1393,12 +1396,12 @@
 	ret
 ; 8d6de
 
-.asm_8d6de: ; 8d6de (23:56de)
-	call Function8e72c
+.ApplyYOffset: ; 8d6de (23:56de)
+	call ApplyYOffset
 	ret
 
-.asm_8d6e2: ; 8d6e2 (23:56e2)
-	call Function8e72a
+.ApplyXOffset: ; 8d6e2 (23:56e2)
+	call ApplyXOffset
 	ret
 ; 8d6e6 (23:56e6)
 
@@ -2839,17 +2842,17 @@
 	dbbw $10, $24, $672a ; 16-tile 2bpp at 24:672a (inside Function926f7)
 	dbbw $10, $21, $672a ; 16-tile 2bpp at 21:672a (inside Function8671c)
 
-Function8e72a: ; 8e72a
+ApplyXOffset: ; 8e72a
 	add $10
-Function8e72c: ; 8e72c
+ApplyYOffset: ; 8e72c
 	and $3f
 	cp $20
-	jr nc, .asm_8e737
+	jr nc, .xflip
 	call Function8e741
 	ld a, h
 	ret
 
-.asm_8e737
+.xflip
 	and $1f
 	call Function8e741
 	ld a, h
@@ -2862,7 +2865,7 @@
 	ld e, a
 	ld a, d
 	ld d, 0
-	ld hl, Unknown_8e75d
+	ld hl, .sinewave
 rept 2
 	add hl, de
 endr
@@ -2870,39 +2873,39 @@
 	inc hl
 	ld d, [hl]
 	ld hl, 0
-.asm_8e750
+.loop
 	srl a
-	jr nc, .asm_8e755
+	jr nc, .skip_add
 	add hl, de
 
-.asm_8e755
+.skip_add
 	sla e
 	rl d
 	and a
-	jr nz, .asm_8e750
+	jr nz, .loop
 	ret
 ; 8e75d
 
-Unknown_8e75d: ; 8e75d
+.sinewave: ; 8e75d
 	sine_wave $100
 
 
-Function8e79d: ; 8e79d
+AnimateEndOfExpBar: ; 8e79d
 	ld a, [hSGB]
-	ld de, GFX_8e7f4
+	ld de, EndOfExpBarGFX
 	and a
-	jr z, .asm_8e7a8
-	ld de, GFX_8e804
+	jr z, .load
+	ld de, SGBEndOfExpBarGFX
 
-.asm_8e7a8
-	ld hl, VTiles0
-	lb bc, BANK(GFX_8e7f4), 1
+.load
+	ld hl, VTiles0 tile $00
+	lb bc, BANK(EndOfExpBarGFX), 1
 	call Request2bpp
 	ld c, $8
 	ld d, $0
-.asm_8e7b5
+.loop
 	push bc
-	call Function8e7c6
+	call .AnimateFrame
 	call DelayFrame
 	pop bc
 rept 2
@@ -2909,15 +2912,15 @@
 	inc d
 endr
 	dec c
-	jr nz, .asm_8e7b5
+	jr nz, .loop
 	call ClearSprites
 	ret
 ; 8e7c6
 
-Function8e7c6: ; 8e7c6
+.AnimateFrame: ; 8e7c6
 	ld hl, Sprites
 	ld c, $8
-.asm_8e7cb
+.anim_loop
 	ld a, c
 	and a
 	ret z
@@ -2927,32 +2930,35 @@
 	sla a
 	sla a
 	push af
+
 	push de
 	push hl
-	call Function8e72c
+	call ApplyYOffset
 	pop hl
 	pop de
-	add $68
+	add 13 * 8
 	ld [hli], a
+
 	pop af
 	push de
 	push hl
-	call Function8e72a
+	call ApplyXOffset
 	pop hl
 	pop de
-	add $54
+	add 10 * 8 + 4
 	ld [hli], a
+
 	ld a, $0
 	ld [hli], a
-	ld a, $6
+	ld a, $6 ; OBJ 6
 	ld [hli], a
-	jr .asm_8e7cb
+	jr .anim_loop
 ; 8e7f4
 
-GFX_8e7f4: ; 8e7f4
-INCBIN "gfx/unknown/08e7f4.2bpp"
-GFX_8e804: ; 8e804
-INCBIN "gfx/unknown/08e804.2bpp"
+EndOfExpBarGFX: ; 8e7f4
+INCBIN "gfx/battle/expbarend.2bpp"
+SGBEndOfExpBarGFX: ; 8e804
+INCBIN "gfx/battle/expbarend_sgb.2bpp"
 
 ClearSpriteAnims: ; 8e814
 	push hl
--- a/engine/time_capsule/conversion.asm
+++ b/engine/time_capsule/conversion.asm
@@ -359,7 +359,7 @@
 	call WaitPressAorB_BlinkCursor
 	ld a, $1
 	ld [wPokedexStatus], a
-	callba Function4424d
+	callba DisplayDexEntry
 	call WaitPressAorB_BlinkCursor
 	pop af
 	ld [wPokedexStatus], a
--- a/engine/town_map.asm
+++ b/engine/town_map.asm
@@ -92,7 +92,7 @@
 	jr nz, .pressed_down
 .loop2
 	push de
-	callba Function8cf69
+	callba PlaySpriteAnimations
 	pop de
 	call DelayFrame
 	jr .loop
--- a/engine/trade/animation.asm
+++ b/engine/trade/animation.asm
@@ -206,7 +206,7 @@
 	bit 7, a
 	jr nz, .finished
 	call .DoTradeAnimCommand
-	callab Function8cf69
+	callab PlaySpriteAnimations
 	ld hl, wcf65
 	inc [hl]
 	call DelayFrame
--- a/event/magnet_train.asm
+++ b/event/magnet_train.asm
@@ -43,7 +43,7 @@
 	jr z, .initialize
 	bit 7, a
 	jr nz, .done
-	callab Function8cf69
+	callab PlaySpriteAnimations
 	call Function8cdf7
 	call Function8cc99
 	call Function3b0c
@@ -426,7 +426,7 @@
 ; 8ceae
 
 Function8ceae: ; 8ceae
-	callba Function8cf69
+	callba PlaySpriteAnimations
 	call Function8cdf7
 	call Function8cc99
 	call Function3b0c
binary files /dev/null b/gfx/battle/expbarend.2bpp differ
binary files /dev/null b/gfx/battle/expbarend_sgb.2bpp differ
binary files a/gfx/unknown/08e7f4.2bpp /dev/null differ
binary files a/gfx/unknown/08e804.2bpp /dev/null differ
--- a/home.asm
+++ b/home.asm
@@ -317,8 +317,8 @@
 ; 	mid:  3 frames
 ; 	slow: 5 frames
 
-; TextBoxFrame + 1[!0] and A or B override text speed with a one-frame delay.
-; Options[4] and TextBoxFrame + 1[!1] disable the delay.
+; TextBoxFlags[!0] and A or B override text speed with a one-frame delay.
+; Options[4] and TextBoxFlags[!1] disable the delay.
 
 	ld a, [Options]
 	bit NO_TEXT_SCROLL, a
@@ -325,7 +325,7 @@
 	ret nz
 
 ; non-scrolling text?
-	ld a, [TextBoxFrame + 1]
+	ld a, [TextBoxFlags]
 	bit 1, a
 	ret z
 
@@ -342,7 +342,7 @@
 	ld [hl], a
 
 ; force fast scroll?
-	ld a, [TextBoxFrame + 1]
+	ld a, [TextBoxFlags]
 	bit 0, a
 	jr z, .fast
 
--- a/home/text.asm
+++ b/home/text.asm
@@ -723,15 +723,15 @@
 
 
 PlaceWholeStringInBoxAtOnce:: ; 13e5
-	ld a, [TextBoxFrame + 1]
+	ld a, [TextBoxFlags]
 	push af
 	set 1, a
-	ld [TextBoxFrame + 1], a
+	ld [TextBoxFlags], a
 
 	call DoTextUntilTerminator
 
 	pop af
-	ld [TextBoxFrame + 1], a
+	ld [TextBoxFlags], a
 	ret
 ; 13f6
 
--- a/items/item_effects.asm
+++ b/items/item_effects.asm
@@ -1206,7 +1206,7 @@
 	jr z, .NoEffect
 
 	ld a, $1
-	ld [wd1e9], a
+	ld [wForceEvolution], a
 	callba EvolvePokemon
 
 	ld a, [wMonTriedToEvolve]
@@ -1447,7 +1447,7 @@
 	predef LearnLevelMoves
 
 	xor a
-	ld [wd1e9], a
+	ld [wForceEvolution], a
 	callba EvolvePokemon
 
 	jp UseDisposableItem
--- a/macros.asm
+++ b/macros.asm
@@ -238,3 +238,7 @@
 palred EQUS "$0400 *"
 palgreen EQUS "$0020 *"
 palblue EQUS "$0001 *"
+
+dsprite: MACRO
+	db \1 * 8 + \2, \3 * 8 + \4, \5, \6
+endm
--- a/main.asm
+++ b/main.asm
@@ -169,265 +169,8 @@
 	ret
 ; 6508
 
-LearnMove: ; 6508
-	call LoadTileMapToTempTileMap
-	ld a, [CurPartyMon]
-	ld hl, PartyMonNicknames
-	call GetNick
-	ld hl, StringBuffer1
-	ld de, wd050_MonNick
-	ld bc, PKMN_NAME_LENGTH
-	call CopyBytes
+INCLUDE "engine/learn.asm"
 
-.loop
-	ld hl, PartyMon1Moves
-	ld bc, PARTYMON_STRUCT_LENGTH
-	ld a, [CurPartyMon]
-	call AddNTimes
-	ld d, h
-	ld e, l
-	ld b, NUM_MOVES
-; Get the first empty move slot.  This routine also serves to
-; determine whether the Pokemon learning the moves already has
-; all four slots occupied, in which case one would need to be
-; deleted.
-.next
-	ld a, [hl]
-	and a
-	jr z, .learn
-	inc hl
-	dec b
-	jr nz, .next
-; If we're here, we enter the routine for forgetting a move
-; to make room for the new move we're trying to learn.
-	push de
-	call ForgetMove
-	pop de
-	jp c, .cancel
-
-	push hl
-	push de
-	ld [wd265], a
-
-	ld b, a
-	ld a, [wBattleMode]
-	and a
-	jr z, .not_disabled
-	ld a, [DisabledMove]
-	cp b
-	jr nz, .not_disabled
-	xor a
-	ld [DisabledMove], a
-	ld [PlayerDisableCount], a
-.not_disabled
-
-	call GetMoveName
-	ld hl, UnknownText_0x6684 ; 1, 2 and…
-	call PrintText
-	pop de
-	pop hl
-
-.learn
-	ld a, [wd262]
-	ld [hl], a
-	ld bc, MON_PP - MON_MOVES
-	add hl, bc
-
-	push hl
-	push de
-	dec a
-	ld hl, Moves + MOVE_PP
-	ld bc, MOVE_LENGTH
-	call AddNTimes
-	ld a, BANK(Moves)
-	call GetFarByte
-	pop de
-	pop hl
-
-	ld [hl], a
-
-	ld a, [wBattleMode]
-	and a
-	jp z, .learned
-
-	ld a, [CurPartyMon]
-	ld b, a
-	ld a, [CurBattleMon]
-	cp b
-	jp nz, .learned
-
-	ld a, [PlayerSubStatus5]
-	bit SUBSTATUS_TRANSFORMED, a
-	jp nz, .learned
-
-	ld h, d
-	ld l, e
-	ld de, BattleMonMoves
-	ld bc, NUM_MOVES
-	call CopyBytes
-	ld bc, PartyMon1PP - (PartyMon1Moves + NUM_MOVES)
-	add hl, bc
-	ld de, BattleMonPP
-	ld bc, NUM_MOVES
-	call CopyBytes
-	jp .learned
-
-.cancel
-	ld hl, UnknownText_0x6675 ; Stop learning <MOVE>?
-	call PrintText
-	call YesNoBox
-	jp c, .loop
-
-	ld hl, UnknownText_0x667a ; <MON> did not learn <MOVE>.
-	call PrintText
-	ld b, 0
-	ret
-
-.learned
-	ld hl, UnknownText_0x666b ; <MON> learned <MOVE>!
-	call PrintText
-	ld b, 1
-	ret
-; 65d3
-
-ForgetMove: ; 65d3
-	push hl
-	ld hl, UnknownText_0x667f
-	call PrintText
-	call YesNoBox
-	pop hl
-	ret c
-	ld bc, -NUM_MOVES
-	add hl, bc
-	push hl
-	ld de, wListMoves_MoveIndicesBuffer
-	ld bc, NUM_MOVES
-	call CopyBytes
-	pop hl
-.loop
-	push hl
-	ld hl, UnknownText_0x6670
-	call PrintText
-	hlcoord 5, 2
-	ld b, NUM_MOVES * 2
-	ld c, MOVE_NAME_LENGTH
-	call TextBox
-	hlcoord 5 + 2, 2 + 2
-	ld a, SCREEN_WIDTH * 2
-	ld [Buffer1], a
-	predef ListMoves
-	; wMenuData3
-	ld a, $4
-	ld [wcfa1], a
-	ld a, $6
-	ld [wcfa2], a
-	ld a, [wd0eb]
-	inc a
-	ld [wcfa3], a
-	ld a, $1
-	ld [wcfa4], a
-	ld [MenuSelection2], a
-	ld [wcfaa], a
-	ld a, $3
-	ld [wcfa8], a
-	ld a, $20
-	ld [wcfa5], a
-	xor a
-	ld [wcfa6], a
-	ld a, $20
-	ld [wcfa7], a
-	call Function1bc9
-	push af
-	call Call_LoadTempTileMapToTileMap
-	pop af
-	pop hl
-	bit 1, a
-	jr nz, .cancel
-	push hl
-	ld a, [MenuSelection2]
-	dec a
-	ld c, a
-	ld b, 0
-	add hl, bc
-	ld a, [hl]
-	push af
-	push bc
-	call IsHMMove
-	pop bc
-	pop de
-	ld a, d
-	jr c, .hmmove
-	pop hl
-	add hl, bc
-	and a
-	ret
-
-.hmmove
-	ld hl, UnknownText_0x669a
-	call PrintText
-	pop hl
-	jr .loop
-
-.cancel
-	scf
-	ret
-; 666b
-
-UnknownText_0x666b: ; 666b
-; <MON> learned <MOVE>!
-	text_jump UnknownText_0x1c5660
-	db "@"
-; 6670
-
-UnknownText_0x6670: ; 6670
-; Which move should be forgotten?
-	text_jump UnknownText_0x1c5678
-	db "@"
-; 6675
-
-UnknownText_0x6675: ; 6675
-; Stop learning <MOVE>?
-	text_jump UnknownText_0x1c5699
-	db "@"
-; 667a
-
-UnknownText_0x667a: ; 667a
-; <MON> did not learn <MOVE>.
-	text_jump UnknownText_0x1c56af
-	db "@"
-; 667f
-
-UnknownText_0x667f: ; 667f
-; <MON> is trying to learn <MOVE>. But <MON> can't learn more than
-; four moves. Delete an older move to make room for <MOVE>?
-	text_jump UnknownText_0x1c56c9
-	db "@"
-; 6684
-
-UnknownText_0x6684: ; 6684
-	text_jump UnknownText_0x1c5740 ; 1, 2 and…
-	start_asm
-	push de
-	ld de, SFX_SWITCH_POKEMON
-	call PlaySFX
-	pop de
-	ld hl, UnknownText_0x6695
-	ret
-; 6695
-
-UnknownText_0x6695: ; 6695
-; Poof! <MON> forgot <MOVE>. And…
-	text_jump UnknownText_0x1c574e
-	db "@"
-; 669a
-
-UnknownText_0x669a: ; 669a
-; HM moves can't be forgotten now.
-	text_jump UnknownText_0x1c5772
-	db "@"
-; 669f
-
-
 CheckNickErrors:: ; 669f
 ; error-check monster nick before use
 ; must be a peace offering to gamesharkers
@@ -494,216 +237,20 @@
 .textcommands ; 66cf
 ; table defining which characters are actually text commands
 ; format:
-	;   ≥    <
-	db $00, $05
-	db $14, $19
-	db $1d, $26
-	db $35, $3a
-	db $3f, $40
-	db $49, $5d
-	db $5e, $7f
-	db $ff ; end
+	;      ≥           <
+	db "<START>",  $04       + 1
+	db "<PLAY_G>", $18       + 1
+	db $1d,        "%"       + 1
+	db $35,        "<GREEN>" + 1
+	db "<ENEMY>",  "<ENEMY>" + 1
+	db $49,        "<TM>"    + 1
+	db "<ROCKET>", "┘"       + 1
+	db -1 ; end
 ; 66de
 
 
-_Multiply:: ; 66de
+INCLUDE "engine/math.asm"
 
-; hMultiplier is one byte.
-	ld a, 8
-	ld b, a
-
-	xor a
-	ld [hMultiplicand - 1], a
-	ld [hMathBuffer + 1], a
-	ld [hMathBuffer + 2], a
-	ld [hMathBuffer + 3], a
-	ld [hMathBuffer + 4], a
-
-
-.loop
-	ld a, [hMultiplier]
-	srl a
-	ld [hMultiplier], a
-	jr nc, .next
-
-	ld a, [hMathBuffer + 4]
-	ld c, a
-	ld a, [hMultiplicand + 2]
-	add c
-	ld [hMathBuffer + 4], a
-
-	ld a, [hMathBuffer + 3]
-	ld c, a
-	ld a, [hMultiplicand + 1]
-	adc c
-	ld [hMathBuffer + 3], a
-
-	ld a, [hMathBuffer + 2]
-	ld c, a
-	ld a, [hMultiplicand + 0]
-	adc c
-	ld [hMathBuffer + 2], a
-
-	ld a, [hMathBuffer + 1]
-	ld c, a
-	ld a, [hMultiplicand - 1]
-	adc c
-	ld [hMathBuffer + 1], a
-
-.next
-	dec b
-	jr z, .done
-
-
-; hMultiplicand <<= 1
-
-	ld a, [hMultiplicand + 2]
-	add a
-	ld [hMultiplicand + 2], a
-
-	ld a, [hMultiplicand + 1]
-	rla
-	ld [hMultiplicand + 1], a
-
-	ld a, [hMultiplicand + 0]
-	rla
-	ld [hMultiplicand + 0], a
-
-	ld a, [hMultiplicand - 1]
-	rla
-	ld [hMultiplicand - 1], a
-
-	jr .loop
-
-
-.done
-	ld a, [hMathBuffer + 4]
-	ld [hProduct + 3], a
-
-	ld a, [hMathBuffer + 3]
-	ld [hProduct + 2], a
-
-	ld a, [hMathBuffer + 2]
-	ld [hProduct + 1], a
-
-	ld a, [hMathBuffer + 1]
-	ld [hProduct + 0], a
-
-	ret
-; 673e
-
-
-_Divide:: ; 673e
-	xor a
-	ld [hMathBuffer + 0], a
-	ld [hMathBuffer + 1], a
-	ld [hMathBuffer + 2], a
-	ld [hMathBuffer + 3], a
-	ld [hMathBuffer + 4], a
-
-	ld a, 9
-	ld e, a
-
-.loop
-	ld a, [hMathBuffer + 0]
-	ld c, a
-	ld a, [hDividend + 1]
-	sub c
-	ld d, a
-
-	ld a, [hDivisor]
-	ld c, a
-	ld a, [hDividend + 0]
-	sbc c
-	jr c, .asm_6767
-
-	ld [hDividend + 0], a
-
-	ld a, d
-	ld [hDividend + 1], a
-
-	ld a, [hMathBuffer + 4]
-	inc a
-	ld [hMathBuffer + 4], a
-
-	jr .loop
-
-.asm_6767
-	ld a, b
-	cp 1
-	jr z, .done
-
-	ld a, [hMathBuffer + 4]
-	add a
-	ld [hMathBuffer + 4], a
-
-	ld a, [hMathBuffer + 3]
-	rla
-	ld [hMathBuffer + 3], a
-
-	ld a, [hMathBuffer + 2]
-	rla
-	ld [hMathBuffer + 2], a
-
-	ld a, [hMathBuffer + 1]
-	rla
-	ld [hMathBuffer + 1], a
-
-	dec e
-	jr nz, .asm_6798
-
-	ld e, 8
-	ld a, [hMathBuffer + 0]
-	ld [hDivisor], a
-	xor a
-	ld [hMathBuffer + 0], a
-
-	ld a, [hDividend + 1]
-	ld [hDividend + 0], a
-
-	ld a, [hDividend + 2]
-	ld [hDividend + 1], a
-
-	ld a, [hDividend + 3]
-	ld [hDividend + 2], a
-
-.asm_6798
-	ld a, e
-	cp 1
-	jr nz, .asm_679e
-	dec b
-
-.asm_679e
-	ld a, [hDivisor]
-	srl a
-	ld [hDivisor], a
-
-	ld a, [hMathBuffer + 0]
-	rr a
-	ld [hMathBuffer + 0], a
-
-	jr .loop
-
-.done
-	ld a, [hDividend + 1]
-	ld [hDivisor], a
-
-	ld a, [hMathBuffer + 4]
-	ld [hDividend + 3], a
-
-	ld a, [hMathBuffer + 3]
-	ld [hDividend + 2], a
-
-	ld a, [hMathBuffer + 2]
-	ld [hDividend + 1], a
-
-	ld a, [hMathBuffer + 1]
-	ld [hDividend + 0], a
-
-	ret
-; 67c1
-
-
 ItemAttributes: ; 67c1
 INCLUDE "items/item_attributes.asm"
 ; 6ec1
@@ -14291,12 +13838,12 @@
 INCLUDE "tilesets/data_4.asm"
 
 
-SECTION "bankD", ROMX, BANK[$D]
+SECTION "Effect Commands", ROMX, BANK[$D]
 
 INCLUDE "battle/effect_commands.asm"
 
 
-SECTION "bankE", ROMX, BANK[$E]
+SECTION "Enemy Trainers", ROMX, BANK[$E]
 
 INCLUDE "battle/ai/items.asm"
 
@@ -14326,8 +13873,8 @@
 	ret
 ; 39550
 
-Function39550: ; 39550
-	ld hl, wd26b
+GetOTName: ; 39550
+	ld hl, OTPlayerName
 	ld a, [wLinkMode]
 	and a
 	jr nz, .ok
@@ -14352,13 +13899,13 @@
 	ret
 ; 3957b
 
-Function3957b: ; 3957b
+GetTrainerAttributes: ; 3957b
 	ld a, [TrainerClass]
 	ld c, a
-	call Function39550
+	call GetOTName
 	ld a, [TrainerClass]
 	dec a
-	ld hl, TrainerClassAttributes
+	ld hl, TrainerClassAttributes + TRNATTR_ITEM1
 	ld bc, NUM_TRAINER_ATTRIBUTES
 	call AddNTimes
 	ld de, wEnemyTrainerItem1
@@ -14374,414 +13921,14 @@
 
 INCLUDE "trainers/attributes.asm"
 
+INCLUDE "trainers/read_party.asm"
 
-ReadTrainerParty: ; 39771
-	ld a, [InBattleTowerBattle]
-	bit 0, a
-	ret nz
-
-	ld a, [wLinkMode]
-	and a
-	ret nz
-
-	ld hl, OTPartyCount
-	xor a
-	ld [hli], a
-	dec a
-	ld [hl], a
-
-	ld hl, OTPartyMons
-	ld bc, OTPartyMonsEnd - OTPartyMons
-	xor a
-	call ByteFill
-
-	ld a, [OtherTrainerClass]
-	cp CAL
-	jr nz, .not_cal2
-	ld a, [OtherTrainerID]
-	cp CAL2
-	jr z, .cal2
-	ld a, [OtherTrainerClass]
-.not_cal2
-
-	dec a
-	ld c, a
-	ld b, 0
-	ld hl, TrainerGroups
-rept 2
-	add hl, bc
-endr
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-
-	ld a, [OtherTrainerID]
-	ld b, a
-.skip_trainer
-	dec b
-	jr z, .got_trainer
-.loop
-	ld a, [hli]
-	cp $ff
-	jr nz, .loop
-	jr .skip_trainer
-.got_trainer
-
-.skip_name
-	ld a, [hli]
-	cp "@"
-	jr nz, .skip_name
-
-	ld a, [hli]
-	ld c, a
-	ld b, 0
-	ld d, h
-	ld e, l
-	ld hl, TrainerTypes
-rept 2
-	add hl, bc
-endr
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-	ld bc, .done
-	push bc
-	jp [hl]
-
-.done
-	jp ComputeTrainerReward
-
-.cal2
-	ld a, BANK(sMysteryGiftTrainer)
-	call GetSRAMBank
-	ld de, sMysteryGiftTrainer
-	call TrainerType2
-	call CloseSRAM
-	jr .done
-; 397e3
-
-TrainerTypes: ; 397e3
-	dw TrainerType1 ; level, species
-	dw TrainerType2 ; level, species, moves
-	dw TrainerType3 ; level, species, item
-	dw TrainerType4 ; level, species, item, moves
-; 397eb
-
-TrainerType1: ; 397eb
-; normal (level, species)
-	ld h, d
-	ld l, e
-.loop
-	ld a, [hli]
-	cp $ff
-	ret z
-
-	ld [CurPartyLevel], a
-	ld a, [hli]
-	ld [CurPartySpecies], a
-	ld a, OTPARTYMON
-	ld [MonType], a
-	push hl
-	predef TryAddMonToParty
-	pop hl
-	jr .loop
-; 39806
-
-TrainerType2: ; 39806
-; moves
-	ld h, d
-	ld l, e
-.loop
-	ld a, [hli]
-	cp $ff
-	ret z
-
-	ld [CurPartyLevel], a
-	ld a, [hli]
-	ld [CurPartySpecies], a
-	ld a, OTPARTYMON
-	ld [MonType], a
-
-	push hl
-	predef TryAddMonToParty
-	ld a, [OTPartyCount]
-	dec a
-	ld hl, OTPartyMon1Moves
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call AddNTimes
-	ld d, h
-	ld e, l
-	pop hl
-
-	ld b, NUM_MOVES
-.copy_moves
-	ld a, [hli]
-	ld [de], a
-	inc de
-	dec b
-	jr nz, .copy_moves
-
-	push hl
-
-	ld a, [OTPartyCount]
-	dec a
-	ld hl, OTPartyMon1Species
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call AddNTimes
-	ld d, h
-	ld e, l
-	ld hl, MON_PP
-	add hl, de
-	push hl
-	ld hl, MON_MOVES
-	add hl, de
-	pop de
-
-	ld b, NUM_MOVES
-.copy_pp
-	ld a, [hli]
-	and a
-	jr z, .copied_pp
-
-	push hl
-	push bc
-	dec a
-	ld hl, Moves + MOVE_PP
-	ld bc, MOVE_LENGTH
-	call AddNTimes
-	ld a, BANK(Moves)
-	call GetFarByte
-	pop bc
-	pop hl
-
-	ld [de], a
-	inc de
-	dec b
-	jr nz, .copy_pp
-.copied_pp
-
-	pop hl
-	jr .loop
-; 39871
-
-TrainerType3: ; 39871
-; item
-	ld h, d
-	ld l, e
-.loop
-	ld a, [hli]
-	cp $ff
-	ret z
-
-	ld [CurPartyLevel], a
-	ld a, [hli]
-	ld [CurPartySpecies], a
-	ld a, OTPARTYMON
-	ld [MonType], a
-	push hl
-	predef TryAddMonToParty
-	ld a, [OTPartyCount]
-	dec a
-	ld hl, OTPartyMon1Item
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call AddNTimes
-	ld d, h
-	ld e, l
-	pop hl
-	ld a, [hli]
-	ld [de], a
-	jr .loop
-; 3989d (e:589d)
-
-TrainerType4: ; 3989d
-; item + moves
-	ld h, d
-	ld l, e
-.loop
-	ld a, [hli]
-	cp $ff
-	ret z
-
-	ld [CurPartyLevel], a
-	ld a, [hli]
-	ld [CurPartySpecies], a
-
-	ld a, OTPARTYMON
-	ld [MonType], a
-
-	push hl
-	predef TryAddMonToParty
-	ld a, [OTPartyCount]
-	dec a
-	ld hl, OTPartyMon1Item
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call AddNTimes
-	ld d, h
-	ld e, l
-	pop hl
-
-	ld a, [hli]
-	ld [de], a
-
-	push hl
-	ld a, [OTPartyCount]
-	dec a
-	ld hl, OTPartyMon1Moves
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call AddNTimes
-	ld d, h
-	ld e, l
-	pop hl
-
-	ld b, NUM_MOVES
-.copy_moves
-	ld a, [hli]
-	ld [de], a
-	inc de
-	dec b
-	jr nz, .copy_moves
-
-	push hl
-
-	ld a, [OTPartyCount]
-	dec a
-	ld hl, OTPartyMon1
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call AddNTimes
-	ld d, h
-	ld e, l
-	ld hl, MON_PP
-	add hl, de
-
-	push hl
-	ld hl, MON_MOVES
-	add hl, de
-	pop de
-
-	ld b, NUM_MOVES
-.copy_pp
-	ld a, [hli]
-	and a
-	jr z, .copied_pp
-
-	push hl
-	push bc
-	dec a
-	ld hl, Moves + MOVE_PP
-	ld bc, MOVE_LENGTH
-	call AddNTimes
-	ld a, BANK(Moves)
-	call GetFarByte
-	pop bc
-	pop hl
-
-	ld [de], a
-	inc de
-	dec b
-	jr nz, .copy_pp
-.copied_pp
-
-	pop hl
-	jr .loop
-; 3991b
-
-ComputeTrainerReward: ; 3991b (e:591b)
-	ld hl, hProduct
-	xor a
-rept 3
-	ld [hli], a
-endr
-	ld a, [wEnemyTrainerBaseReward]
-	ld [hli], a
-	ld a, [CurPartyLevel]
-	ld [hl], a
-	call Multiply
-	ld hl, wBattleReward
-	xor a
-	ld [hli], a
-	ld a, [hProduct + 2]
-	ld [hli], a
-	ld a, [hProduct + 3]
-	ld [hl], a
-	ret
-
-
-Battle_GetTrainerName:: ; 39939
-	ld a, [InBattleTowerBattle]
-	bit 0, a
-	ld hl, wd26b
-	jp nz, CopyTrainerName
-
-	ld a, [OtherTrainerID]
-	ld b, a
-	ld a, [OtherTrainerClass]
-	ld c, a
-
-GetTrainerName:: ; 3994c
-	ld a, c
-	cp CAL
-	jr nz, .not_cal2
-
-	ld a, BANK(sMysteryGiftTrainerHouseFlag)
-	call GetSRAMBank
-	ld a, [sMysteryGiftTrainerHouseFlag]
-	and a
-	call CloseSRAM
-	jr z, .not_cal2
-
-	ld a, BANK(sMysteryGiftPartnerName)
-	call GetSRAMBank
-	ld hl, sMysteryGiftPartnerName
-	call CopyTrainerName
-	jp CloseSRAM
-
-.not_cal2
-	dec c
-	push bc
-	ld b, 0
-	ld hl, TrainerGroups
-rept 2
-	add hl, bc
-endr
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-	pop bc
-
-.loop
-	dec b
-	jr z, CopyTrainerName
-
-.skip
-	ld a, [hli]
-	cp $ff
-	jr nz, .skip
-	jr .loop
-
-CopyTrainerName: ; 39984
-	ld de, StringBuffer1
-	push de
-	ld bc, NAME_LENGTH
-	call CopyBytes
-	pop de
-	ret
-; 39990
-
-Function39990: ; 39990
-; This function is useless.
-	ld de, StringBuffer1
-	push de
-	ld bc, NAME_LENGTH
-	pop de
-	ret
-; 39999
-
 INCLUDE "trainers/trainer_pointers.asm"
 
 INCLUDE "trainers/trainers.asm"
 
 
-SECTION "bankF", ROMX, BANK[$F]
+SECTION "Battle Core", ROMX, BANK[$F]
 
 INCLUDE "battle/core.asm"
 
@@ -14793,72 +13940,6 @@
 
 INCLUDE "engine/pokedex.asm"
 
-
-Function41a7f: ; 41a7f
-	xor a
-	ld [hBGMapMode], a
-	callba Function1de247
-	call Function41af7
-	call DisableLCD
-	call LoadStandardFont
-	call LoadFontsExtra
-	call Function414b7
-	call Function4147b
-	ld a, [wd265]
-	ld [CurPartySpecies], a
-	call Function407fd
-	call Function40ba0
-	hlcoord 0, 17
-	ld [hl], $3b
-	inc hl
-	ld bc, $13
-	ld a, " "
-	call ByteFill
-	callba Function4424d
-	call EnableLCD
-	call WaitBGMap
-	call GetBaseData
-	ld de, VTiles2
-	predef GetFrontpic
-	ld a, $4
-	call Function41423
-	ld a, [CurPartySpecies]
-	call PlayCry
-	ret
-; 41ad7
-
-
-Function41ad7: ; 41ad7 (10:5ad7)
-	ld a, $3
-	ld [hBGMapMode], a
-	ld c, 4
-	call DelayFrames
-	ret
-
-Function41ae1: ; 41ae1 (10:5ae1)
-	ld a, $4
-	ld [hBGMapMode], a
-	ld c, 4
-	call DelayFrames
-	ret
-
-Function41aeb: ; 41aeb (10:5aeb)
-	ld a, [hCGB]
-	and a
-	jr z, .asm_41af3
-	call Function41ae1
-.asm_41af3
-	call Function41ad7
-	ret
-
-
-Function41af7: ; 41af7
-	xor a
-	ld [hBGMapMode], a
-	ret
-; 41afb
-
-
 INCLUDE "battle/moves/moves.asm"
 
 INCLUDE "engine/evolve.asm"
@@ -14867,233 +13948,10 @@
 
 INCLUDE "engine/fruit_trees.asm"
 
+INCLUDE "battle/ai/move.asm"
 
-AIChooseMove: ; 440ce
-; Score each move in EnemyMonMoves starting from Buffer1. Lower is better.
-; Pick the move with the lowest score.
-
-; Wildmons attack at random.
-	ld a, [wBattleMode]
-	dec a
-	ret z
-
-	ld a, [wLinkMode]
-	and a
-	ret nz
-
-; No use picking a move if there's no choice.
-	callba CheckSubstatus_RechargeChargedRampageBideRollout
-	ret nz
-
-
-; The default score is 20. Unusable moves are given a score of 80.
-	ld a, 20
-	ld hl, Buffer1
-rept 3
-	ld [hli], a
-endr
-	ld [hl], a
-
-; Don't pick disabled moves.
-	ld a, [EnemyDisabledMove]
-	and a
-	jr z, .CheckPP
-
-	ld hl, EnemyMonMoves
-	ld c, 0
-.CheckDisabledMove
-	cp [hl]
-	jr z, .ScoreDisabledMove
-	inc c
-	inc hl
-	jr .CheckDisabledMove
-.ScoreDisabledMove
-	ld hl, Buffer1
-	ld b, 0
-	add hl, bc
-	ld [hl], 80
-
-; Don't pick moves with 0 PP.
-.CheckPP
-	ld hl, Buffer1 - 1
-	ld de, EnemyMonPP
-	ld b, 0
-.CheckMovePP
-	inc b
-	ld a, b
-	cp EnemyMonMovesEnd - EnemyMonMoves + 1
-	jr z, .ApplyLayers
-	inc hl
-	ld a, [de]
-	inc de
-	and $3f
-	jr nz, .CheckMovePP
-	ld [hl], 80
-	jr .CheckMovePP
-
-
-; Apply AI scoring layers depending on the trainer class.
-.ApplyLayers
-	ld hl, TrainerClassAttributes + 3
-
-	; If we have a battle in BattleTower just load the Attributes of the first TrainerClass (Falkner)
-	; so we have always the same AI, regardless of the loaded class of trainer
-	ld a, [InBattleTowerBattle]
-	bit 0, a
-	jr nz, .battle_tower_skip
-
-	ld a, [TrainerClass]
-	dec a
-	ld bc, 7 ; Trainer2AI - Trainer1AI
-	call AddNTimes
-
-.battle_tower_skip
-	lb bc, CHECK_FLAG, 0
-	push bc
-	push hl
-
-.CheckLayer
-	pop hl
-	pop bc
-
-	ld a, c
-	cp 16 ; up to 16 scoring layers
-	jr z, .DecrementScores
-
-	push bc
-	ld d, BANK(TrainerClassAttributes)
-	predef FlagPredef
-	ld d, c
-	pop bc
-
-	inc c
-	push bc
-	push hl
-
-	ld a, d
-	and a
-	jr z, .CheckLayer
-
-	ld hl, AIScoringPointers
-	dec c
-	ld b, 0
-rept 2
-	add hl, bc
-endr
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-	ld a, BANK(AIScoring)
-	call FarCall_hl
-
-	jr .CheckLayer
-
-; Decrement the scores of all moves one by one until one reaches 0.
-.DecrementScores
-	ld hl, Buffer1
-	ld de, EnemyMonMoves
-	ld c, EnemyMonMovesEnd - EnemyMonMoves
-
-.DecrementNextScore
-	; If the enemy has no moves, this will infinite.
-	ld a, [de]
-	inc de
-	and a
-	jr z, .DecrementScores
-
-	; We are done whenever a score reaches 0
-	dec [hl]
-	jr z, .PickLowestScoreMoves
-
-	; If we just decremented the fourth move's score, go back to the first move
-	inc hl
-	dec c
-	jr z, .DecrementScores
-
-	jr .DecrementNextScore
-
-; In order to avoid bias towards the moves located first in memory, increment the scores
-; that were decremented one more time than the rest (in case there was a tie).
-; This means that the minimum score will be 1.
-.PickLowestScoreMoves
-	ld a, c
-
-.move_loop
-	inc [hl]
-	dec hl
-	inc a
-	cp NUM_MOVES + 1
-	jr nz, .move_loop
-
-	ld hl, Buffer1
-	ld de, EnemyMonMoves
-	ld c, NUM_MOVES
-
-; Give a score of 0 to a blank move	
-.loop2
-	ld a, [de]
-	and a
-	jr nz, .skip_load
-	ld [hl], a
-
-; Disregard the move if its score is not 1	
-.skip_load
-	ld a, [hl]
-	dec a
-	jr z, .keep
-	xor a
-	ld [hli], a
-	jr .after_toss
-
-.keep
-	ld a, [de]
-	ld [hli], a
-.after_toss
-	inc de
-	dec c
-	jr nz, .loop2
-
-; Randomly choose one of the moves with a score of 1 	
-.ChooseMove
-	ld hl, Buffer1
-	call Random
-	and 3
-	ld c, a
-	ld b, 0
-	add hl, bc
-	ld a, [hl]
-	and a
-	jr z, .ChooseMove
-
-	ld [CurEnemyMove], a
-	ld a, c
-	ld [CurEnemyMoveNum], a
-	ret
-; 441af
-
-
-AIScoringPointers: ; 441af
-	dw AI_Basic
-	dw AI_Setup
-	dw AI_Types
-	dw AI_Offensive
-	dw AI_Smart
-	dw AI_Opportunist
-	dw AI_Aggressive
-	dw AI_Cautious
-	dw AI_Status
-	dw AI_Risky
-	dw AI_None
-	dw AI_None
-	dw AI_None
-	dw AI_None
-	dw AI_None
-	dw AI_None
-; 441cf
-
-
-Function441cf: ; 441cf
-	ld hl, Unknown_441fc
+AnimateDexSearchSlowpoke: ; 441cf
+	ld hl, .FrameIDs
 	ld b, 25
 .loop
 	ld a, [hli]
@@ -15101,16 +13959,16 @@
 	; Wrap around
 	cp $fe
 	jr nz, .ok
-	ld hl, Unknown_441fc
+	ld hl, .FrameIDs
 	ld a, [hli]
 .ok
 
-	ld [wc7db], a
+	ld [wDexSearchSlowpokeFrame], a
 	ld a, [hli]
 	ld c, a
 	push bc
 	push hl
-	call Function44207
+	call DoDexSearchSlowpokeFrame
 	pop hl
 	pop bc
 	call DelayFrames
@@ -15117,30 +13975,31 @@
 	dec b
 	jr nz, .loop
 	xor a
-	ld [wc7db], a
-	call Function44207
+	ld [wDexSearchSlowpokeFrame], a
+	call DoDexSearchSlowpokeFrame
 	ld c, 32
 	call DelayFrames
 	ret
 ; 441fc
 
-Unknown_441fc: ; 441fc
+.FrameIDs: ; 441fc
+	; frame ID, duration
 	db 0, 7
 	db 1, 7
 	db 2, 7
 	db 3, 7
 	db 4, 7
-	db $fe
+	db -2
 ; 44207
 
 
-Function44207: ; 44207
-	ld a, [wc7db]
-	ld hl, Unknown_44228
+DoDexSearchSlowpokeFrame: ; 44207
+	ld a, [wDexSearchSlowpokeFrame]
+	ld hl, .SpriteData
 	ld de, Sprites
-.asm_44210
+.loop
 	ld a, [hli]
-	cp $ff
+	cp -1
 	ret z
 	ld [de], a
 	inc de
@@ -15147,7 +14006,7 @@
 	ld a, [hli]
 	ld [de], a
 	inc de
-	ld a, [wc7db]
+	ld a, [wDexSearchSlowpokeFrame]
 	ld b, a
 	add a
 	add b
@@ -15158,44 +14017,46 @@
 	ld a, [hli]
 	ld [de], a
 	inc de
-	jr .asm_44210
+	jr .loop
 ; 44228
 
-Unknown_44228: ; 44228
-	db $58, $48, $00, $00
-	db $58, $50, $01, $00
-	db $58, $58, $02, $00
-	db $60, $48, $10, $00
-	db $60, $50, $11, $00
-	db $60, $58, $12, $00
-	db $68, $48, $20, $00
-	db $68, $50, $21, $00
-	db $68, $58, $22, $00
-	db $ff
+.SpriteData: ; 44228
+	dsprite 11, 0,  9, 0, $00, $00
+	dsprite 11, 0, 10, 0, $01, $00
+	dsprite 11, 0, 11, 0, $02, $00
+	dsprite 12, 0,  9, 0, $10, $00
+	dsprite 12, 0, 10, 0, $11, $00
+	dsprite 12, 0, 11, 0, $12, $00
+	dsprite 13, 0,  9, 0, $20, $00
+	dsprite 13, 0, 10, 0, $21, $00
+	dsprite 13, 0, 11, 0, $22, $00
+	db -1
 ; 4424d
 
-Function4424d: ; 4424d
+DisplayDexEntry: ; 4424d
 	call GetPokemonName
 	hlcoord 9, 3
-	call PlaceString
+	call PlaceString ; mon species
 	ld a, [wd265]
 	ld b, a
-	call Function44333
+	call GetDexEntryPointer
 	ld a, b
 	push af
 	hlcoord 9, 5
-	call FarString
+	call FarString ; dex species
 	ld h, b
 	ld l, c
 	push de
+; Print dex number
 	hlcoord 2, 8
-	ld a, $5c
+	ld a, $5c ; No
 	ld [hli], a
-	ld a, $5d
+	ld a, $5d ; .
 	ld [hli], a
 	ld de, wd265
 	lb bc, PRINTNUM_LEADINGZEROS | 1, 3
 	call PrintNum
+; Check to see if we caught it.  Get out of here if we haven't.
 	ld a, [wd265]
 	dec a
 	call CheckCaughtMon
@@ -15202,6 +14063,7 @@
 	pop hl
 	pop bc
 	ret z
+; Get the height of the Pokemon.
 	ld a, [CurPartySpecies]
 	ld [CurSpecies], a
 	inc hl
@@ -15217,7 +14079,7 @@
 endr
 	ld a, d
 	or e
-	jr z, .asm_442b0
+	jr z, .skip_height
 	push hl
 	push de
 	ld hl, [sp+$0]
@@ -15227,11 +14089,11 @@
 	lb bc, 2, 36
 	call PrintNum
 	hlcoord 14, 7
-	ld [hl], "<ROCKET>"
+	ld [hl], $5e ; ft symbol
 	pop af
 	pop hl
 
-.asm_442b0
+.skip_height
 	pop af
 	push af
 	inc hl
@@ -15242,32 +14104,34 @@
 	ld e, h
 	ld a, e
 	or d
-	jr z, .skip
+	jr z, .skip_weight
 	push de
 	ld hl, [sp+$0]
 	ld d, h
 	ld e, l
 	hlcoord 11, 9
-	lb bc, 2, 69
+	lb bc, 2, PRINTNUM_RIGHTALIGN | 5
 	call PrintNum
 	pop de
 
-.skip
+.skip_weight
+; Page 1
 	lb bc, 5, SCREEN_WIDTH - 2
 	hlcoord 2, 11
 	call ClearBox
 	hlcoord 1, 10
-	ld bc, $13
-	ld a, $61
+	ld bc, SCREEN_WIDTH - 1
+	ld a, $61 ; horizontal divider
 	call ByteFill
+	; page number
 	hlcoord 1, 9
-	ld [hl], "<CONT>"
+	ld [hl], $55
 	inc hl
-	ld [hl], "<CONT>"
+	ld [hl], $55
 	hlcoord 1, 10
-	ld [hl], "<......>"
+	ld [hl], $56 ; P.
 	inc hl
-	ld [hl], "<DONE>"
+	ld [hl], $57 ; 1
 	pop de
 	inc de
 	pop af
@@ -15278,6 +14142,8 @@
 	ld a, [wPokedexStatus]
 	or a
 	ret z
+
+; Page 2
 	push bc
 	push de
 	lb bc, 5, SCREEN_WIDTH - 2
@@ -15284,17 +14150,18 @@
 	hlcoord 2, 11
 	call ClearBox
 	hlcoord 1, 10
-	ld bc, $13
+	ld bc, SCREEN_WIDTH - 1
 	ld a, $61
 	call ByteFill
+	; page number
 	hlcoord 1, 9
-	ld [hl], "<CONT>"
+	ld [hl], $55
 	inc hl
-	ld [hl], "<CONT>"
+	ld [hl], $55
 	hlcoord 1, 10
-	ld [hl], "<......>"
+	ld [hl], $56 ; P.
 	inc hl
-	ld [hl], "<PROMPT>"
+	ld [hl], $58 ; 2
 	pop de
 	inc de
 	pop af
@@ -15307,7 +14174,8 @@
 	db "#@"
 ; 44333
 
-Function44333: ; 44333
+GetDexEntryPointer: ; 44333
+; return dex entry pointer b:de
 	push hl
 	ld hl, PokedexDataPointerTable
 	ld a, b
@@ -15324,7 +14192,7 @@
 	rlca
 	rlca
 	and $3
-	ld hl, PokedexEntryBanks
+	ld hl, .PokedexEntryBanks
 	ld d, 0
 	ld e, a
 	add hl, de
@@ -15334,7 +14202,7 @@
 	ret
 ; 44351
 
-PokedexEntryBanks: ; 44351
+.PokedexEntryBanks: ; 44351
 
 GLOBAL PokedexEntries1
 GLOBAL PokedexEntries2
@@ -15347,11 +14215,12 @@
 	db BANK(PokedexEntries4)
 ; 44355
 
-Function44355: ; 44355
-	call Function44333
+GetDexEntryPagePointer: ; 44355
+	call GetDexEntryPointer ; b:de
 	push hl
 	ld h, d
 	ld l, e
+; skip species name
 .loop1
 	ld a, b
 	call GetFarByte
@@ -15358,11 +14227,14 @@
 	inc hl
 	cp "@"
 	jr nz, .loop1
+; skip height and weight
 rept 4
 	inc hl
 endr
+; if c != 1: skip entry
 	dec c
 	jr z, .done
+; skip entry
 .loop2
 	ld a, b
 	call GetFarByte
@@ -17000,7 +15872,7 @@
 	jr nz, .loop
 
 	call Function4aa7a
-	callba Function8cf69
+	callba PlaySpriteAnimations
 	ret
 ; 4aafb
 
@@ -19233,6 +18105,92 @@
 
 INCLUDE "engine/evolution_animation.asm"
 
+Function4e881: ; 4e881
+	call ClearBGPalettes
+	call ClearTileMap
+	call ClearSprites
+	call DisableLCD
+	call LoadStandardFont
+	call LoadFontsBattleExtra
+	hlbgcoord 0, 0
+	ld bc, VBGMap1 - VBGMap0
+	ld a, " "
+	call ByteFill
+	hlcoord 0, 0, AttrMap
+	ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
+	xor a
+	call ByteFill
+	xor a
+	ld [hSCY], a
+	ld [hSCX], a
+	call EnableLCD
+	ld hl, .SavingRecordDontTurnOff
+	call PrintText
+	call Function3200
+	call SetPalettes
+	ret
+; 4e8bd
+
+.SavingRecordDontTurnOff: ; 0x4e8bd
+	; SAVING RECORD… DON'T TURN OFF!
+	text_jump UnknownText_0x1bd39e
+	db "@"
+; 0x4e8c2
+
+
+Function4e8c2: ; 4e8c2
+	call ClearBGPalettes
+	call ClearTileMap
+	call ClearSprites
+	call DisableLCD
+	call LoadStandardFont
+	call LoadFontsBattleExtra
+	hlbgcoord 0, 0
+	ld bc, VBGMap1 - VBGMap0
+	ld a, " "
+	call ByteFill
+	hlcoord 0, 0, AttrMap
+	ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
+	xor a
+	call ByteFill
+	ld hl, wd000 ; UnknBGPals
+	ld c, 4 * $10
+.load_white_palettes
+	ld a, (palred 31 + palgreen 31 + palblue 31) % $100
+	ld [hli], a
+	ld a, (palred 31 + palgreen 31 + palblue 31) / $100
+	ld [hli], a
+	dec c
+	jr nz, .load_white_palettes
+	xor a
+	ld [hSCY], a
+	ld [hSCX], a
+	call EnableLCD
+	call Function3200
+	call SetPalettes
+	ret
+; 4e906
+
+Function4e906: ; 4e906
+	ld a, [rSVBK]
+	push af
+	ld a, $6
+	ld [rSVBK], a
+	ld hl, w6_d000
+	ld bc, w6_d400 - w6_d000
+	ld a, " "
+	call ByteFill
+	hlbgcoord 0, 0
+	ld de, w6_d000
+	ld b, $0
+	ld c, $40
+	call Request2bpp
+	pop af
+	ld [rSVBK], a
+	ret
+; 4e929
+
+
 Function4e929: ; mobile function
 	ld h, b
 	ld l, c
@@ -23094,7 +22052,7 @@
 ; Graphics for an unused Game Corner
 ; game were meant to be here.
 
-Functione00ed: ; e00ed (38:40ed)
+ret_e00ed: ; e00ed (38:40ed)
 	ret
 ; e00ee (38:40ee)
 
@@ -24422,7 +23380,7 @@
 INCBIN "gfx/misc/unown_font.2bpp"
 ; 1dc1b0
 
-Function1dc1b0: ; 1dc1b0
+PrintPage1: ; 1dc1b0
 	hlcoord 0, 0
 	ld de, wca90
 	ld bc, 17 * SCREEN_WIDTH
@@ -24454,8 +23412,8 @@
 	push af
 	ld a, [wd265]
 	ld b, a
-	ld c, $1
-	callba Function44355
+	ld c, 1 ; get page 1
+	callba GetDexEntryPagePointer
 	pop af
 	ld a, b
 	ld hl, wcb6d
@@ -24465,16 +23423,16 @@
 	ld de, SCREEN_WIDTH
 	add hl, de
 	ld b, $f
-.asm_1dc20a
+.column_loop
 	ld [hl], $37
 	add hl, de
 	dec b
-	jr nz, .asm_1dc20a
+	jr nz, .column_loop
 	ld [hl], $3a
 	ret
 ; 1dc213
 
-Function1dc213: ; 1dc213
+PrintPage2: ; 1dc213
 	ld hl, wca90
 	ld bc, $a0
 	ld a, " "
@@ -24482,11 +23440,11 @@
 	ld hl, wca90
 	ld a, $36
 	ld b, $6
-	call Function1dc26a
+	call .FillColumn
 	ld hl, wcaa3
 	ld a, $37
 	ld b, $6
-	call Function1dc26a
+	call .FillColumn
 	ld hl, wcb08
 	ld [hl], $38
 	inc hl
@@ -24504,8 +23462,8 @@
 	push af
 	ld a, [wd265]
 	ld b, a
-	ld c, $2
-	callba Function44355
+	ld c, 2 ; get page 2
+	callba GetDexEntryPagePointer
 	pop af
 	ld hl, wcaa5
 	ld a, b
@@ -24513,14 +23471,14 @@
 	ret
 ; 1dc26a
 
-Function1dc26a: ; 1dc26a
+.FillColumn: ; 1dc26a
 	push de
 	ld de, SCREEN_WIDTH
-.asm_1dc26e
+.column_loop
 	ld [hl], a
 	add hl, de
 	dec b
-	jr nz, .asm_1dc26e
+	jr nz, .column_loop
 	pop de
 	ret
 ; 1dc275
--- a/maps/VioletPokeCenter1F.asm
+++ b/maps/VioletPokeCenter1F.asm
@@ -12,23 +12,23 @@
 .MapCallbacks:
 	db 0
 
-NurseScript_0x694c9:
+VioletPokeCenterNurse:
 	jumpstd pokecenternurse
 
-ScientistScript_0x694cc:
+VioletPokeCenter1F_ElmsAideScript:
 	faceplayer
 	loadfont
 	checkevent EVENT_REFUSED_TO_TAKE_EGG_FROM_ELMS_AIDE
-	iftrue UnknownScript_0x6953a
+	iftrue .SecondTimeAsking
 	writetext UnknownText_0x69555
-UnknownScript_0x694d7:
+.AskTakeEgg:
 	yesorno
-	iffalse UnknownScript_0x69531
+	iffalse .RefusedEgg
 	checkcode VAR_PARTYCOUNT
-	if_equal $6, UnknownScript_0x6952b
+	if_equal PARTY_LENGTH, .PartyFull
 	giveegg TOGEPI, 5
 	stringtotext .eggname, $1
-	scall UnknownScript_0x69527
+	scall .AideGivesEgg
 	setevent EVENT_GOT_TOGEPI_EGG_FROM_ELMS_AIDE
 	clearevent EVENT_ELMS_AIDE_IN_LAB
 	clearevent EVENT_TOGEPI_HATCHED
@@ -37,18 +37,18 @@
 	waitbutton
 	closetext
 	checkcode VAR_FACING
-	if_equal UP, .UnknownScript_0x69511
+	if_equal UP, .AideWalksAroundPlayer
 	spriteface PLAYER, DOWN
-	applymovement VIOLETPOKECENTER1F_SCIENTIST, MovementData_0x69549
+	applymovement VIOLETPOKECENTER1F_SCIENTIST, MovementData_AideWalksStraightOutOfPokecenter
 	playsound SFX_EXIT_BUILDING
 	disappear VIOLETPOKECENTER1F_SCIENTIST
 	waitsfx
 	end
 
-.UnknownScript_0x69511
-	applymovement VIOLETPOKECENTER1F_SCIENTIST, MovementData_0x6954e
+.AideWalksAroundPlayer
+	applymovement VIOLETPOKECENTER1F_SCIENTIST, MovementData_AideWalksLeftToExitPokecenter
 	spriteface PLAYER, DOWN
-	applymovement VIOLETPOKECENTER1F_SCIENTIST, MovementData_0x69551
+	applymovement VIOLETPOKECENTER1F_SCIENTIST, MovementData_AideFinishesLeavingPokecenter
 	playsound SFX_EXIT_BUILDING
 	disappear VIOLETPOKECENTER1F_SCIENTIST
 	waitsfx
@@ -57,17 +57,17 @@
 .eggname
 	db "EGG@"
 
-UnknownScript_0x69527:
+.AideGivesEgg:
 	jumpstd receivetogepiegg
 	end
 
-UnknownScript_0x6952b:
+.PartyFull:
 	writetext UnknownText_0x69693
 	waitbutton
 	closetext
 	end
 
-UnknownScript_0x69531:
+.RefusedEgg:
 	writetext UnknownText_0x696f2
 	waitbutton
 	closetext
@@ -74,9 +74,9 @@
 	setevent EVENT_REFUSED_TO_TAKE_EGG_FROM_ELMS_AIDE
 	end
 
-UnknownScript_0x6953a:
+.SecondTimeAsking:
 	writetext UnknownText_0x69712
-	jump UnknownScript_0x694d7
+	jump .AskTakeEgg
 
 GameboyKidScript_0x69540:
 	jumptextfaceplayer UnknownText_0x69809
@@ -87,7 +87,7 @@
 YoungsterScript_0x69546:
 	jumptextfaceplayer UnknownText_0x698b8
 
-MovementData_0x69549:
+MovementData_AideWalksStraightOutOfPokecenter:
 	step_down
 	step_down
 	step_down
@@ -94,12 +94,12 @@
 	step_down
 	step_end
 
-MovementData_0x6954e:
+MovementData_AideWalksLeftToExitPokecenter:
 	step_left
 	step_down
 	step_end
 
-MovementData_0x69551:
+MovementData_AideFinishesLeavingPokecenter:
 	step_down
 	step_down
 	step_down
@@ -233,8 +233,8 @@
 
 .PersonEvents:
 	db 5
-	person_event SPRITE_NURSE, 1, 3, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, 0, PERSONTYPE_SCRIPT, 0, NurseScript_0x694c9, -1
+	person_event SPRITE_NURSE, 1, 3, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, 0, PERSONTYPE_SCRIPT, 0, VioletPokeCenterNurse, -1
 	person_event SPRITE_GAMEBOY_KID, 6, 7, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, (1 << 3) | PAL_OW_GREEN, PERSONTYPE_SCRIPT, 0, GameboyKidScript_0x69540, -1
 	person_event SPRITE_GENTLEMAN, 4, 1, SPRITEMOVEDATA_SPINRANDOM_SLOW, 0, 0, -1, -1, 0, PERSONTYPE_SCRIPT, 0, GentlemanScript_0x69543, -1
 	person_event SPRITE_YOUNGSTER, 1, 8, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, (1 << 3) | PAL_OW_RED, PERSONTYPE_SCRIPT, 0, YoungsterScript_0x69546, -1
-	person_event SPRITE_SCIENTIST, 3, 4, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, (1 << 3) | PAL_OW_BLUE, PERSONTYPE_SCRIPT, 0, ScientistScript_0x694cc, EVENT_ELMS_AIDE_IN_VIOLET_POKEMON_CENTER
+	person_event SPRITE_SCIENTIST, 3, 4, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, (1 << 3) | PAL_OW_BLUE, PERSONTYPE_SCRIPT, 0, VioletPokeCenter1F_ElmsAideScript, EVENT_ELMS_AIDE_IN_VIOLET_POKEMON_CENTER
--- a/misc/fixed_words.asm
+++ b/misc/fixed_words.asm
@@ -362,7 +362,7 @@
 	bit 7, a
 	jr nz, .exit
 	call .DoJumptableFunction
-	callba Function8cf69
+	callba PlaySpriteAnimations
 	callba ReloadMapPart
 	jr .loop
 
--- a/misc/mobile_40.asm
+++ b/misc/mobile_40.asm
@@ -2011,7 +2011,7 @@
 	call Function100dd2
 	callba Function241ba
 	push bc
-	callba Function8cf69
+	callba PlaySpriteAnimations
 	callba Function10402d
 	call Function100dfd
 	pop bc
@@ -2065,7 +2065,7 @@
 	call Function100dd2
 	callba Function241ba
 	push bc
-	callba Function8cf69
+	callba PlaySpriteAnimations
 	callba Function10402d
 	call Function100dfd
 	pop bc
@@ -4059,7 +4059,7 @@
 	ld a, $1
 	ld [wc2d7], a
 	callba BattleIntro
-	callba SendOutFirstMons
+	callba DoBattle
 	callba ShowLinkBattleParticipantsAfterEnd
 	xor a
 	ld [wc2d7], a
@@ -6468,7 +6468,7 @@
 	dec a
 	ld [CurPartyMon], a
 	ld a, $1
-	ld [wd1e9], a
+	ld [wForceEvolution], a
 	callba EvolvePokemon
 	call Function102d9a
 	call Function102dd3
--- a/misc/mobile_42.asm
+++ b/misc/mobile_42.asm
@@ -400,7 +400,7 @@
 Function1082cc: ; 1082cc
 .asm_1082cc
 	push bc
-	callba Function8cf69
+	callba PlaySpriteAnimations
 	pop bc
 	call DelayFrame
 	dec c
@@ -410,7 +410,7 @@
 
 Function1082db: ; 1082db
 .asm_1082db
-	callba Function8cf69
+	callba PlaySpriteAnimations
 	callba Functiond00b4
 	callba Function10402d
 	jr nc, .asm_1082db
@@ -431,7 +431,7 @@
 	call Function108b78
 	push hl
 	push bc
-	callba Function8cf69
+	callba PlaySpriteAnimations
 	pop bc
 	pop hl
 	call DelayFrame
--- a/misc/mobile_45.asm
+++ b/misc/mobile_45.asm
@@ -7721,7 +7721,7 @@
 	bit 7, a
 	jr nz, .asm_117709
 	call Function117719
-	callba Function8cf69
+	callba PlaySpriteAnimations
 	callba ReloadMapPart
 	jr Function1176ee
 .asm_117709
--- a/misc/mobile_46.asm
+++ b/misc/mobile_46.asm
@@ -7679,7 +7679,7 @@
 	callba Function108016
 	callba Function17d1f1
 	ld a, $1
-	ld [wd1e9], a
+	ld [wForceEvolution], a
 	ld a, $2
 	ld [wLinkMode], a
 	callba EvolvePokemon
--- a/misc/mobile_5c.asm
+++ b/misc/mobile_5c.asm
@@ -422,7 +422,7 @@
 	bit 7, a
 	jr nz, .asm_171a2c
 	call Function171a36
-	callba Function8cf69
+	callba PlaySpriteAnimations
 	callba ReloadMapPart
 	jr Function171a11
 .asm_171a2c
--- a/misc/mobile_5f.asm
+++ b/misc/mobile_5f.asm
@@ -302,7 +302,7 @@
 	callba Function10804d
 	callba Function17d1f1
 	ld a, $1
-	ld [wd1e9], a
+	ld [wForceEvolution], a
 	ld a, $2
 	ld [wLinkMode], a
 	callba EvolvePokemon
--- a/text/battle.asm
+++ b/text/battle.asm
@@ -478,9 +478,9 @@
 	text "<TARGET>"
 	line "became confused!"
 	prompt
-; 0x80dab
+; ItemHealedConfusion
 
-BattleText_0x80dab: ; 0x80dab
+BattleText_ItemHealedConfusion: ; ItemHealedConfusion
 	text "A @"
 	text_from_ram StringBuffer1
 	text " rid"
--- /dev/null
+++ b/trainers/read_party.asm
@@ -1,0 +1,401 @@
+
+ReadTrainerParty: ; 39771
+	ld a, [InBattleTowerBattle]
+	bit 0, a
+	ret nz
+
+	ld a, [wLinkMode]
+	and a
+	ret nz
+
+	ld hl, OTPartyCount
+	xor a
+	ld [hli], a
+	dec a
+	ld [hl], a
+
+	ld hl, OTPartyMons
+	ld bc, OTPartyMonsEnd - OTPartyMons
+	xor a
+	call ByteFill
+
+	ld a, [OtherTrainerClass]
+	cp CAL
+	jr nz, .not_cal2
+	ld a, [OtherTrainerID]
+	cp CAL2
+	jr z, .cal2
+	ld a, [OtherTrainerClass]
+.not_cal2
+
+	dec a
+	ld c, a
+	ld b, 0
+	ld hl, TrainerGroups
+rept 2
+	add hl, bc
+endr
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+
+	ld a, [OtherTrainerID]
+	ld b, a
+.skip_trainer
+	dec b
+	jr z, .got_trainer
+.loop
+	ld a, [hli]
+	cp $ff
+	jr nz, .loop
+	jr .skip_trainer
+.got_trainer
+
+.skip_name
+	ld a, [hli]
+	cp "@"
+	jr nz, .skip_name
+
+	ld a, [hli]
+	ld c, a
+	ld b, 0
+	ld d, h
+	ld e, l
+	ld hl, TrainerTypes
+rept 2
+	add hl, bc
+endr
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+	ld bc, .done
+	push bc
+	jp [hl]
+
+.done
+	jp ComputeTrainerReward
+
+.cal2
+	ld a, BANK(sMysteryGiftTrainer)
+	call GetSRAMBank
+	ld de, sMysteryGiftTrainer
+	call TrainerType2
+	call CloseSRAM
+	jr .done
+; 397e3
+
+TrainerTypes: ; 397e3
+	dw TrainerType1 ; level, species
+	dw TrainerType2 ; level, species, moves
+	dw TrainerType3 ; level, species, item
+	dw TrainerType4 ; level, species, item, moves
+; 397eb
+
+TrainerType1: ; 397eb
+; normal (level, species)
+	ld h, d
+	ld l, e
+.loop
+	ld a, [hli]
+	cp $ff
+	ret z
+
+	ld [CurPartyLevel], a
+	ld a, [hli]
+	ld [CurPartySpecies], a
+	ld a, OTPARTYMON
+	ld [MonType], a
+	push hl
+	predef TryAddMonToParty
+	pop hl
+	jr .loop
+; 39806
+
+TrainerType2: ; 39806
+; moves
+	ld h, d
+	ld l, e
+.loop
+	ld a, [hli]
+	cp $ff
+	ret z
+
+	ld [CurPartyLevel], a
+	ld a, [hli]
+	ld [CurPartySpecies], a
+	ld a, OTPARTYMON
+	ld [MonType], a
+
+	push hl
+	predef TryAddMonToParty
+	ld a, [OTPartyCount]
+	dec a
+	ld hl, OTPartyMon1Moves
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call AddNTimes
+	ld d, h
+	ld e, l
+	pop hl
+
+	ld b, NUM_MOVES
+.copy_moves
+	ld a, [hli]
+	ld [de], a
+	inc de
+	dec b
+	jr nz, .copy_moves
+
+	push hl
+
+	ld a, [OTPartyCount]
+	dec a
+	ld hl, OTPartyMon1Species
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call AddNTimes
+	ld d, h
+	ld e, l
+	ld hl, MON_PP
+	add hl, de
+	push hl
+	ld hl, MON_MOVES
+	add hl, de
+	pop de
+
+	ld b, NUM_MOVES
+.copy_pp
+	ld a, [hli]
+	and a
+	jr z, .copied_pp
+
+	push hl
+	push bc
+	dec a
+	ld hl, Moves + MOVE_PP
+	ld bc, MOVE_LENGTH
+	call AddNTimes
+	ld a, BANK(Moves)
+	call GetFarByte
+	pop bc
+	pop hl
+
+	ld [de], a
+	inc de
+	dec b
+	jr nz, .copy_pp
+.copied_pp
+
+	pop hl
+	jr .loop
+; 39871
+
+TrainerType3: ; 39871
+; item
+	ld h, d
+	ld l, e
+.loop
+	ld a, [hli]
+	cp $ff
+	ret z
+
+	ld [CurPartyLevel], a
+	ld a, [hli]
+	ld [CurPartySpecies], a
+	ld a, OTPARTYMON
+	ld [MonType], a
+	push hl
+	predef TryAddMonToParty
+	ld a, [OTPartyCount]
+	dec a
+	ld hl, OTPartyMon1Item
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call AddNTimes
+	ld d, h
+	ld e, l
+	pop hl
+	ld a, [hli]
+	ld [de], a
+	jr .loop
+; 3989d (e:589d)
+
+TrainerType4: ; 3989d
+; item + moves
+	ld h, d
+	ld l, e
+.loop
+	ld a, [hli]
+	cp $ff
+	ret z
+
+	ld [CurPartyLevel], a
+	ld a, [hli]
+	ld [CurPartySpecies], a
+
+	ld a, OTPARTYMON
+	ld [MonType], a
+
+	push hl
+	predef TryAddMonToParty
+	ld a, [OTPartyCount]
+	dec a
+	ld hl, OTPartyMon1Item
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call AddNTimes
+	ld d, h
+	ld e, l
+	pop hl
+
+	ld a, [hli]
+	ld [de], a
+
+	push hl
+	ld a, [OTPartyCount]
+	dec a
+	ld hl, OTPartyMon1Moves
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call AddNTimes
+	ld d, h
+	ld e, l
+	pop hl
+
+	ld b, NUM_MOVES
+.copy_moves
+	ld a, [hli]
+	ld [de], a
+	inc de
+	dec b
+	jr nz, .copy_moves
+
+	push hl
+
+	ld a, [OTPartyCount]
+	dec a
+	ld hl, OTPartyMon1
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call AddNTimes
+	ld d, h
+	ld e, l
+	ld hl, MON_PP
+	add hl, de
+
+	push hl
+	ld hl, MON_MOVES
+	add hl, de
+	pop de
+
+	ld b, NUM_MOVES
+.copy_pp
+	ld a, [hli]
+	and a
+	jr z, .copied_pp
+
+	push hl
+	push bc
+	dec a
+	ld hl, Moves + MOVE_PP
+	ld bc, MOVE_LENGTH
+	call AddNTimes
+	ld a, BANK(Moves)
+	call GetFarByte
+	pop bc
+	pop hl
+
+	ld [de], a
+	inc de
+	dec b
+	jr nz, .copy_pp
+.copied_pp
+
+	pop hl
+	jr .loop
+; 3991b
+
+ComputeTrainerReward: ; 3991b (e:591b)
+	ld hl, hProduct
+	xor a
+rept 3
+	ld [hli], a
+endr
+	ld a, [wEnemyTrainerBaseReward]
+	ld [hli], a
+	ld a, [CurPartyLevel]
+	ld [hl], a
+	call Multiply
+	ld hl, wBattleReward
+	xor a
+	ld [hli], a
+	ld a, [hProduct + 2]
+	ld [hli], a
+	ld a, [hProduct + 3]
+	ld [hl], a
+	ret
+
+
+Battle_GetTrainerName:: ; 39939
+	ld a, [InBattleTowerBattle]
+	bit 0, a
+	ld hl, wd26b
+	jp nz, CopyTrainerName
+
+	ld a, [OtherTrainerID]
+	ld b, a
+	ld a, [OtherTrainerClass]
+	ld c, a
+
+GetTrainerName:: ; 3994c
+	ld a, c
+	cp CAL
+	jr nz, .not_cal2
+
+	ld a, BANK(sMysteryGiftTrainerHouseFlag)
+	call GetSRAMBank
+	ld a, [sMysteryGiftTrainerHouseFlag]
+	and a
+	call CloseSRAM
+	jr z, .not_cal2
+
+	ld a, BANK(sMysteryGiftPartnerName)
+	call GetSRAMBank
+	ld hl, sMysteryGiftPartnerName
+	call CopyTrainerName
+	jp CloseSRAM
+
+.not_cal2
+	dec c
+	push bc
+	ld b, 0
+	ld hl, TrainerGroups
+rept 2
+	add hl, bc
+endr
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+	pop bc
+
+.loop
+	dec b
+	jr z, CopyTrainerName
+
+.skip
+	ld a, [hli]
+	cp $ff
+	jr nz, .skip
+	jr .loop
+
+CopyTrainerName: ; 39984
+	ld de, StringBuffer1
+	push de
+	ld bc, NAME_LENGTH
+	call CopyBytes
+	pop de
+	ret
+; 39990
+
+Function39990: ; 39990
+; This function is useless.
+	ld de, StringBuffer1
+	push de
+	ld bc, NAME_LENGTH
+	pop de
+	ret
+; 39999
--- a/wram.asm
+++ b/wram.asm
@@ -1014,7 +1014,7 @@
 wc7d8:: ds 1
 wc7d9:: ds 1
 wc7da:: ds 1
-wc7db:: ds 1
+wDexSearchSlowpokeFrame:: ds 1
 wc7dc:: ds 1
 wc7dd:: ds 1
 wc7de:: ds 1
@@ -1493,7 +1493,7 @@
 TextBoxFrame:: ; cfce
 ; bits 0-2: textbox frame 0-7
 	ds 1
-
+TextBoxFlags::
 	ds 1
 
 GBPrinter:: ; cfd0
@@ -2011,7 +2011,7 @@
 EvolvableFlags:: ; d1e8
 	flag_array PARTY_LENGTH
 
-wd1e9:: ds 1
+wForceEvolution:: ds 1
 MagikarpLength::
 Buffer1:: ; d1ea
 	ds 1
@@ -2161,9 +2161,6 @@
 	ds 1
 
 	ds 1
-SECTION "Enemy Party", WRAMX, BANK [1]
-OTPlayerName:: ds NAME_LENGTH
-	ds OTPlayerName - @
 wPokedexShowPointerAddr::
 wd26b:: ds 1
 wd26c:: ds 1
@@ -2171,9 +2168,13 @@
 wd26d:: ds 1
 	ds 3
 wd271:: ds 5
-OTPlayerID::
 wd276:: ds 10
+	ds wd26b - @
 
+SECTION "Enemy Party", WRAMX, BANK [1]
+OTPlayerName:: ds NAME_LENGTH
+OTPlayerID:: ds 2
+	ds 8
 OTPartyCount::   ds 1 ; d280
 OTPartySpecies:: ds PARTY_LENGTH ; d281
 OTPartyEnd::     ds 1
@@ -2204,6 +2205,7 @@
 	ds 1
 
 ScriptFlags:: ; d434
+; bit 3: priority jump
 	ds 1
 ScriptFlags2:: ; d435
 	ds 1
@@ -2234,7 +2236,11 @@
 ScriptDelay:: ; d44d
 	ds 1
 
+wPriorityScriptBank::
+wScriptTextBank::
 wd44e:: ds 1
+wPriorityScriptAddr::
+wScriptTextAddr::
 wd44f:: ds 1
 wd450:: ds 1
 wd451:: ds 1