shithub: pokecrystal

Download patch

ref: 3713b71d9e3f3f1bc099d4704910cb9c1d172dcf
parent: 82f1534925c5fe1f0d876ea88119b0121cfa65a6
author: pikalaxalt <[email protected]>
date: Wed May 4 07:46:23 EDT 2016

More splitting of main.asm; remove unneeded rept 2

--- a/audio/engine.asm
+++ b/audio/engine.asm
@@ -1348,9 +1348,8 @@
 	ld d, 0
 	; load ptr to noise sample set in hl
 	ld hl, Drumkits
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -1363,9 +1362,8 @@
 	; use 'pitch' to seek noise sample set
 	ld e, a
 	ld d, 0
-rept 2
 	add hl, de
-endr
+	add hl, de
 	; load sample pointer into NoiseSampleAddress
 	ld a, [hli]
 	ld [NoiseSampleAddressLo], a
@@ -1387,9 +1385,8 @@
 	ld d, 0
 	; seek command pointer
 	ld hl, MusicCommands
-rept 2
 	add hl, de
-endr
+	add hl, de
 	; jump to the new pointer
 	ld a, [hli]
 	ld h, [hl]
@@ -1639,9 +1636,8 @@
 	inc hl
 	ld d, [hl]
 	; skip pointer
-rept 2
 	inc de
-endr
+	inc de
 	; update address
 	ld [hl], d
 	dec hl
@@ -1693,9 +1689,8 @@
 	inc hl
 	ld d, [hl]
 	; skip pointer
-rept 2
 	inc de
-endr
+	inc de
 	; update address
 	ld [hl], d
 	dec hl
@@ -2811,9 +2806,8 @@
 	ld c, a
 	ld b, 0
 	ld hl, ChannelPointers
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld c, [hl]
 	inc hl
 	ld b, [hl] ; bc = channel pointer
@@ -3282,9 +3276,8 @@
 ; doesn't seem to be used, but functionally identical to MapSetup_Sound_Off
 	ld hl, rNR50
 	xor a
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	ld a, $80
 	ld [hli], a
 	ld hl, rNR10
--- a/audio/music/goldenrodcity.asm
+++ b/audio/music/goldenrodcity.asm
@@ -275,9 +275,8 @@
 	vibrato $8, $23
 	notetype $c, $25
 Music_GoldenrodCity_branch_eb58c: ; eb58c
-rept 2
 	callchannel Music_GoldenrodCity_branch_eb5aa
-endr
+	callchannel Music_GoldenrodCity_branch_eb5aa
 	callchannel Music_GoldenrodCity_branch_eb5d2
 	note __, 3
 	octave 3
--- a/audio/music/johtowildbattle.asm
+++ b/audio/music/johtowildbattle.asm
@@ -492,9 +492,8 @@
 	note G_, 2
 	loopchannel 7, Music_JohtoWildBattle_branch_f5fdb
 	note F#, 4
-rept 2
 	callchannel Music_JohtoWildBattle_branch_f6055
-endr
+	callchannel Music_JohtoWildBattle_branch_f6055
 Music_JohtoWildBattle_branch_f5fe8: ; f5fe8
 	note D_, 2
 	note G_, 2
--- a/audio/music/kantowildbattle.asm
+++ b/audio/music/kantowildbattle.asm
@@ -325,25 +325,21 @@
 	note F_, 1
 	note F#, 1
 	notetype $6, $b7
-rept 2
 	callchannel Music_KantoWildBattle_branch_ed307
-endr
+	callchannel Music_KantoWildBattle_branch_ed307
 	forceoctave $1
-rept 2
 	callchannel Music_KantoWildBattle_branch_ed307
-endr
+	callchannel Music_KantoWildBattle_branch_ed307
 	forceoctave $0
 rept 4
 	callchannel Music_KantoWildBattle_branch_ed307
 endr
 	forceoctave $1
-rept 2
 	callchannel Music_KantoWildBattle_branch_ed307
-endr
+	callchannel Music_KantoWildBattle_branch_ed307
 	forceoctave $0
-rept 2
 	callchannel Music_KantoWildBattle_branch_ed307
-endr
+	callchannel Music_KantoWildBattle_branch_ed307
 	note __, 16
 	octave 3
 	note A#, 16
--- a/battle/ai/items.asm
+++ b/battle/ai/items.asm
@@ -216,9 +216,8 @@
 	pop de
 	pop hl
 
-rept 2
 	inc hl
-endr
+	inc hl
 	jr c, .loop
 
 .used_item
--- a/battle/ai/move.asm
+++ b/battle/ai/move.asm
@@ -107,9 +107,8 @@
 	ld hl, AIScoringPointers
 	dec c
 	ld b, 0
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/battle/ai/scoring.asm
+++ b/battle/ai/scoring.asm
@@ -133,9 +133,8 @@
 	call AI_50_50
 	jr c, .checkmove
 
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	jr .checkmove
 
 .discourage
@@ -142,9 +141,8 @@
 	call Random
 	cp 30
 	jr c, .checkmove
-rept 2
 	inc [hl]
-endr
+	inc [hl]
 	jr .checkmove
 ; 38635
 
@@ -264,9 +262,8 @@
 	and a
 	jr nz, .checkmove
 
-rept 2
 	inc [hl]
-endr
+	inc [hl]
 	jr .checkmove
 ; 386be
 
@@ -420,9 +417,8 @@
 .asm_387f0
 	call AI_50_50
 	ret c
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 ; 387f7
 
@@ -533,9 +529,8 @@
 	call AI_50_50
 	ret c
 
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 
 .asm_38882
@@ -560,9 +555,8 @@
 	cp 180
 	jr nc, .asm_3888b
 
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	jr .asm_3888b
 
 .asm_388a2
@@ -645,9 +639,8 @@
 	jr nc, .asm_38911
 
 .asm_388ef
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 
 .asm_388f2
@@ -676,9 +669,8 @@
 	jr c, .asm_38911
 
 .asm_3890f
-rept 2
 	inc [hl]
-endr
+	inc [hl]
 
 ; 30% chance to end up here if enemy's HP is full and player is not badly poisoned.
 ; 77% chance to end up here if enemy's HP is above 50% but not full.
@@ -722,9 +714,8 @@
 	call Random
 	cp $50
 	ret c
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 
 ; Player is seeded.
@@ -756,9 +747,8 @@
 	call AI_80_20
 	ret c
 
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 ; 3895b
 
@@ -828,9 +818,8 @@
 	jr nc, .asm_389bf
 
 .asm_3899d
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 
 .asm_389a0
@@ -859,9 +848,8 @@
 	jr c, .asm_389bf
 
 .asm_389bd
-rept 2
 	inc [hl]
-endr
+	inc [hl]
 
 ; We only end up here if the move has not been already encouraged.
 .asm_389bf
@@ -900,9 +888,8 @@
 	call Random
 	cp $50
 	ret c
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 
 ; Player is seeded.
@@ -1010,9 +997,8 @@
 	call Random
 	cp $19
 	ret c
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 ; 38a4e
 
@@ -1093,9 +1079,8 @@
 	ret nc
 	call AI_50_50
 	ret c
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 ; 38a9c
 
@@ -1200,9 +1185,8 @@
 .asm_38b09
 	call AI_80_20
 	ret c
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 
 .asm_38b10
@@ -1255,9 +1239,8 @@
 	ret nc
 	call AI_80_20
 	ret c
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 
 .asm_38b3a
@@ -1289,9 +1272,8 @@
 	call Random
 	cp 30
 	ret c
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 ; 38b5c
 
@@ -1528,9 +1510,8 @@
 	call Random
 	cp $46
 	ret c
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 
 .asm_38c81
@@ -1685,9 +1666,8 @@
 	call Random
 	cp $64
 	ret c
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 ; 38d16
 
@@ -1755,9 +1735,8 @@
 	ret z
 	call AI_50_50
 	ret c
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 
 .no_status
@@ -2007,15 +1986,13 @@
 	ret nc
 	call AI_80_20
 	ret c
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 
 .asm_38e90
-rept 2
 	inc [hl]
-endr
+	inc [hl]
 .asm_38e92
 	inc [hl]
 .asm_38e93
@@ -2065,9 +2042,8 @@
 	call AI_50_50
 	ret c
 
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 ; 38ed2
 
@@ -2119,9 +2095,8 @@
 	call Random
 	cp 20
 	ret c
-rept 2
 	inc [hl]
-endr
+	inc [hl]
 	ret
 ; 38f1d
 
@@ -2151,9 +2126,8 @@
 	call Random
 	cp 100
 	ret c
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 ; 38f4a
 
@@ -2272,9 +2246,8 @@
 	call AI_50_50
 	ret c
 
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 
 .asm_38fd8
@@ -2296,9 +2269,8 @@
 
 	cp 2
 	jr c, .end
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 
 	cp 3
 	jr c, .end
@@ -2344,9 +2316,8 @@
 	call Random
 	cp 200
 	ret nc
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 
 .asm_39020
@@ -2406,9 +2377,8 @@
 
 	call AICompareSpeed
 	ret nc
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 
 .could_dig
@@ -2455,9 +2425,8 @@
 .asm_3907d
 	call AI_50_50
 	ret c
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 ; 39084
 
@@ -2482,9 +2451,8 @@
 	call AI_80_20
 	ret c
 
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 ; 3909e
 
@@ -2636,9 +2604,8 @@
 	ret nz
 
 .good
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 ; 39134
 
@@ -2733,9 +2700,8 @@
 	ret
 
 .asm_39188
-rept 2
 	inc [hl]
-endr
+	inc [hl]
 	ret
 ; 3918b
 
@@ -2820,9 +2786,8 @@
 	call AICompareSpeed
 	ret nc
 
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 
 ; Try to predict if the player will use Fly this turn.
@@ -2849,9 +2814,8 @@
 	and 1 << SUBSTATUS_FLYING | 1 << SUBSTATUS_UNDERGROUND
 	ret z
 
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 ; 39200
 
@@ -2886,9 +2850,8 @@
 	cp 25 ; 1/10
 	ret c
 
-rept 2
 	inc [hl]
-endr
+	inc [hl]
 	ret
 
 .asm_3921e
@@ -2895,9 +2858,8 @@
 	call AI_80_20
 	ret c
 
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ret
 ; 39225
 
@@ -2991,9 +2953,8 @@
 	ld c, [hl]
 	sla c
 	rl b
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [hld]
 	cp c
 	ld a, [hl]
@@ -3013,9 +2974,8 @@
 	ld c, [hl]
 	sla c
 	rl b
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [hld]
 	cp c
 	ld a, [hl]
@@ -3039,9 +2999,8 @@
 	rl b
 	sla c
 	rl b
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [hld]
 	cp c
 	ld a, [hl]
@@ -3063,9 +3022,8 @@
 	rl b
 	sla c
 	rl b
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [hld]
 	cp c
 	ld a, [hl]
--- a/battle/ai/switch.asm
+++ b/battle/ai/switch.asm
@@ -626,9 +626,8 @@
 	ld b, [hl]
 	inc hl
 	ld c, [hl]
-rept 2
 	inc hl
-endr
+	inc hl
 ; hl = MaxHP + 1
 ; b = (4 * b) % $100 + (c & 3)
 ; c = c / 4
--- a/battle/hidden_power.asm
+++ b/battle/hidden_power.asm
@@ -45,9 +45,8 @@
 
 ; Multiply by 5
 	ld b, a
-rept 2
 	add a
-endr
+	add a
 	add b
 
 ; Add Special & 3
@@ -75,9 +74,8 @@
 	ld a, [hl]
 	and 3 << 4
 	swap a
-rept 2
 	add a
-endr
+	add a
 	or b
 
 ; Skip Normal
--- /dev/null
+++ b/battle/link_result.asm
@@ -1,0 +1,162 @@
+DetermineLinkBattleResult: ; 2b930
+	callba UpdateEnemyMonInParty
+	ld hl, PartyMon1HP
+	call .CountMonsRemaining
+	push bc
+	ld hl, OTPartyMon1HP
+	call .CountMonsRemaining
+	ld a, c
+	pop bc
+	cp c
+	jr z, .even_number_of_mons_remaining
+	jr c, .defeat
+	jr .victory
+
+.even_number_of_mons_remaining
+	call .BothSides_CheckNumberMonsAtFullHealth
+	jr z, .drawn
+	ld a, e
+	cp $1
+	jr z, .victory
+	cp $2
+	jr z, .defeat
+	ld hl, PartyMon1HP
+	call .CalcPercentHPRemaining
+	push de
+	ld hl, OTPartyMon1HP
+	call .CalcPercentHPRemaining
+	pop hl
+	ld a, d
+	cp h
+	jr c, .victory
+	jr z, .compare_lo
+	jr .defeat
+
+.compare_lo
+	ld a, e
+	cp l
+	jr z, .drawn
+	jr nc, .defeat
+
+.victory
+	ld a, [wBattleResult]
+	and $f0
+	ld [wBattleResult], a
+	ret
+
+.defeat
+	ld a, [wBattleResult]
+	and $f0
+	add $1
+	ld [wBattleResult], a
+	ret
+
+.drawn
+	ld a, [wBattleResult]
+	and $f0
+	add $2
+	ld [wBattleResult], a
+	ret
+
+.CountMonsRemaining: ; 2b995
+	ld c, 0
+	ld b, 3
+	ld de, PARTYMON_STRUCT_LENGTH - 1
+.loop
+	ld a, [hli]
+	or [hl]
+	jr nz, .not_fainted
+	inc c
+
+.not_fainted
+	add hl, de
+	dec b
+	jr nz, .loop
+	ret
+
+.CalcPercentHPRemaining: ; 2b9a6
+	ld de, 0
+	ld c, $3
+.loop2
+	ld a, [hli]
+	or [hl]
+	jr z, .next
+	dec hl
+	xor a
+	ld [hDividend + 0], a
+	ld a, [hli]
+	ld [hDividend + 1], a
+	ld a, [hli]
+	ld [hDividend + 2], a
+	xor a
+	ld [hDividend + 3], a
+	ld a, [hli]
+	ld b, a
+	ld a, [hld]
+	srl b
+	rr a
+	srl b
+	rr a
+	ld [hDivisor], a
+	ld b, $4
+	call Divide
+	ld a, [hQuotient + 2]
+	add e
+	ld e, a
+	ld a, [hQuotient + 1]
+	adc d
+	ld d, a
+	dec hl
+
+.next
+	push de
+	ld de, $2f
+	add hl, de
+	pop de
+	dec c
+	jr nz, .loop2
+	ret
+
+.BothSides_CheckNumberMonsAtFullHealth: ; 2b9e1
+	ld hl, PartyMon1HP
+	call .CheckFaintedOrFullHealth
+	jr nz, .finish ; we have a pokemon that's neither fainted nor at full health
+	ld hl, OTPartyMon1HP
+	call .CheckFaintedOrFullHealth
+	ld e, $1
+	ret
+
+.finish
+	ld hl, OTPartyMon1HP
+	call .CheckFaintedOrFullHealth
+	ld e, $0
+	ret nz ; we both have pokemon that are neither fainted nor at full health
+	ld e, $2
+	ld a, $1
+	and a
+	ret
+
+.CheckFaintedOrFullHealth: ; 2ba01
+	ld d, 3
+.loop3
+	ld a, [hli]
+	ld b, a
+	ld a, [hli]
+	ld c, a
+	or b
+	jr z, .fainted_or_full_health
+	ld a, [hli]
+	cp b
+	ret nz
+	ld a, [hld]
+	cp c
+	ret nz
+
+.fainted_or_full_health
+	push de
+	ld de, PARTYMON_STRUCT_LENGTH - 2
+	add hl, de
+	pop de
+	dec d
+	jr nz, .loop3
+	ret
--- a/battle/magikarp_length.asm
+++ b/battle/magikarp_length.asm
@@ -141,9 +141,8 @@
 	; hl = de * 10
 	ld h, d
 	ld l, e
-rept 2
 	add hl, hl
-endr
+	add hl, hl
 	add hl, de
 	add hl, hl
 
--- a/battle/misc.asm
+++ b/battle/misc.asm
@@ -72,9 +72,8 @@
 	jr z, .ApplyModifier
 
 .NextWeatherType:
-rept 2
 	inc de
-endr
+	inc de
 	jr .CheckWeatherType
 
 
@@ -99,9 +98,8 @@
 	jr z, .ApplyModifier
 
 .NextWeatherMove:
-rept 2
 	inc de
-endr
+	inc de
 	jr .CheckWeatherMove
 
 .ApplyModifier:
--- a/battle/sliding_intro.asm
+++ b/battle/sliding_intro.asm
@@ -39,12 +39,10 @@
 	ld a, d
 	ld [hSCX], a
 	call .subfunction5
-rept 2
 	inc e
-endr
-rept 2
+	inc e
 	dec d
-endr
+	dec d
 	pop af
 	push af
 	cp $1
@@ -66,9 +64,8 @@
 	ld c, $12 ; 18
 	ld de, $4
 .loop3
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	add hl, de
 	dec c
 	jr nz, .loop3
--- a/constants/cgb_constants.asm
+++ b/constants/cgb_constants.asm
@@ -24,7 +24,7 @@
 	const SCGB_POKEDEX_UNOWN_MODE
 	const SCGB_17
 	const SCGB_18
-	const SCGB_19
+	const SCGB_GAMEFREAK_LOGO
 	const SCGB_1A
 	const SCGB_1B
 	const SCGB_FRONTPICPALS
--- a/data/pokedex/entry_pointers.asm
+++ b/data/pokedex/entry_pointers.asm
@@ -1,3 +1,75 @@
+GetDexEntryPointer: ; 44333
+; return dex entry pointer b:de
+	push hl
+	ld hl, PokedexDataPointerTable
+	ld a, b
+	dec a
+	ld d, 0
+	ld e, a
+	add hl, de
+	add hl, de
+	ld e, [hl]
+	inc hl
+	ld d, [hl]
+	push de
+	rlca
+	rlca
+	and $3
+	ld hl, .PokedexEntryBanks
+	ld d, 0
+	ld e, a
+	add hl, de
+	ld b, [hl]
+	pop de
+	pop hl
+	ret
+
+.PokedexEntryBanks: ; 44351
+
+GLOBAL PokedexEntries1
+GLOBAL PokedexEntries2
+GLOBAL PokedexEntries3
+GLOBAL PokedexEntries4
+
+	db BANK(PokedexEntries1)
+	db BANK(PokedexEntries2)
+	db BANK(PokedexEntries3)
+	db BANK(PokedexEntries4)
+
+GetDexEntryPagePointer: ; 44355
+	call GetDexEntryPointer ; b:de
+	push hl
+	ld h, d
+	ld l, e
+; skip species name
+.loop1
+	ld a, b
+	call GetFarByte
+	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
+	inc hl
+	cp "@"
+	jr nz, .loop2
+
+.done
+	ld d, h
+	ld e, l
+	pop hl
+	ret
+
+PokedexDataPointerTable: ; 0x44378
 ; Pointers to all the Pokedex entries.
 
 	dw BulbasaurPokedexEntry
--- a/engine/anim_hp_bar.asm
+++ b/engine/anim_hp_bar.asm
@@ -273,9 +273,8 @@
 	push hl
 	add hl, de
 	ld a, " "
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	ld [hld], a
 	dec hl
 	ld a, [Buffer3]
--- a/engine/billspc.asm
+++ b/engine/billspc.asm
@@ -142,9 +142,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, BillsPCDepositJumptable
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -411,9 +410,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .dw
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -675,9 +673,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .Jumptable2
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -2010,9 +2007,8 @@
 
 .moving_to_box
 	ld hl, .Jumptable
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -2143,7 +2139,7 @@
 	ld hl, wBillsPC_ScrollPosition
 	add [hl]
 	ld [CurPartyMon], a
-	callba Function51322
+	callba InsertPokemonIntoBox
 	ret
 ; e3316
 
@@ -2172,7 +2168,7 @@
 	ld hl, wBillsPC_ScrollPosition
 	add [hl]
 	ld [CurPartyMon], a
-	callba Function5138b
+	callba InsertPokemonIntoParty
 	ret
 ; e3357
 
@@ -2256,9 +2252,8 @@
 BillsPC_Jumptable: ; e33df (38:73df)
 	ld e, a
 	ld d, $0
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/engine/breeding/egg.asm
+++ b/engine/breeding/egg.asm
@@ -442,9 +442,8 @@
 	ld c, a
 	ld b, 0
 	ld hl, EggMovePointers
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, BANK(EggMovePointers)
 	call GetFarHalfword
 .loop
@@ -477,9 +476,8 @@
 	ld c, a
 	ld b, 0
 	ld hl, EvosAttacksPointers
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, BANK(EvosAttacksPointers)
 	call GetFarHalfword
 .loop3
--- a/engine/card_flip.asm
+++ b/engine/card_flip.asm
@@ -71,9 +71,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .Jumptable
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -276,9 +275,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, wDeck
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [wCardFlipWhichCard]
 	ld e, a
 	add hl, de
@@ -442,9 +440,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .Deck
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld e, a
 	ld d, [hl]
@@ -675,9 +672,8 @@
 	and a
 	jr nz, .discarded2
 	hlcoord 13, 3
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld [hl], $36
 	ld bc, SCREEN_WIDTH
 	add hl, bc
@@ -686,9 +682,8 @@
 
 .discarded2
 	hlcoord 13, 3
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld [hl], $36
 	ld bc, SCREEN_WIDTH
 	add hl, bc
@@ -703,9 +698,8 @@
 	and a
 	jr nz, .discarded1
 	hlcoord 13, 4
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld [hl], $3b
 	ld bc, SCREEN_WIDTH
 	add hl, bc
@@ -714,9 +708,8 @@
 
 .discarded1
 	hlcoord 13, 4
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld [hl], $3d
 	ld bc, SCREEN_WIDTH
 	add hl, bc
@@ -731,9 +724,8 @@
 	and a
 	jr nz, .discarded4
 	hlcoord 13, 6
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld [hl], $36
 	ld bc, SCREEN_WIDTH
 	add hl, bc
@@ -742,9 +734,8 @@
 
 .discarded4
 	hlcoord 13, 6
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld [hl], $36
 	ld bc, SCREEN_WIDTH
 	add hl, bc
@@ -759,9 +750,8 @@
 	and a
 	jr nz, .discarded3
 	hlcoord 13, 7
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld [hl], $3c
 	ld bc, SCREEN_WIDTH
 	add hl, bc
@@ -770,9 +760,8 @@
 
 .discarded3
 	hlcoord 13, 7
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld [hl], $3d
 	ld bc, SCREEN_WIDTH
 	add hl, bc
@@ -787,9 +776,8 @@
 	and a
 	jr nz, .discarded6
 	hlcoord 13, 9
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld [hl], $36
 	ld bc, SCREEN_WIDTH
 	add hl, bc
@@ -798,9 +786,8 @@
 
 .discarded6
 	hlcoord 13, 9
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld [hl], $36
 	ld bc, SCREEN_WIDTH
 	add hl, bc
@@ -815,9 +802,8 @@
 	and a
 	jr nz, .discarded5
 	hlcoord 13, 10
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld [hl], $3c
 	ld bc, SCREEN_WIDTH
 	add hl, bc
@@ -826,9 +812,8 @@
 
 .discarded5
 	hlcoord 13, 10
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld [hl], $3d
 	ld bc, SCREEN_WIDTH
 	add hl, bc
@@ -1296,9 +1281,8 @@
 	ld [hl], a
 	cp $3
 	jr c, .left_to_number_gp
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	jp .play_sound
 
 .left_to_number_gp
@@ -1326,9 +1310,8 @@
 	ld [hl], a
 	cp $4
 	ret nc
-rept 2
 	inc [hl]
-endr
+	inc [hl]
 	jr .play_sound
 
 .d_up ; e090a
@@ -1357,9 +1340,8 @@
 	ld [hl], a
 	cp $3
 	jr c, .up_to_mon_group
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	jr .play_sound
 
 .up_to_mon_group
@@ -1387,9 +1369,8 @@
 	ld [hl], a
 	cp $6
 	ret nc
-rept 2
 	inc [hl]
-endr
+	inc [hl]
 
 .play_sound ; e0959
 	ld de, SFX_POKEBALLS_PLACED_ON_TABLE
@@ -1408,9 +1389,8 @@
 
 .skip
 	call CollapseCursorPosition
-rept 2
 	add hl, hl
-endr
+	add hl, hl
 	ld de, .OAMData
 	add hl, de
 	ld a, [hli]
--- a/engine/credits.asm
+++ b/engine/credits.asm
@@ -258,9 +258,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .Jumptable
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -326,9 +325,8 @@
 	cp $30
 	jr c, Credits_LYOverride
 	ld a, [wCreditsLYOverride]
-rept 2
 	dec a
-endr
+	dec a
 	ld [wCreditsLYOverride], a
 	ld hl, LYOverrides + $1f
 	call .Fill
@@ -398,9 +396,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, CreditsStrings
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld d, [hl]
 	ld e, a
@@ -741,9 +738,8 @@
 	ld [hl], a
 	ld a, [wCreditsBorderMon]
 	and 3
-rept 2
 	add a
-endr
+	add a
 	add e
 	add a
 	ld e, a
--- a/engine/crystal_intro.asm
+++ b/engine/crystal_intro.asm
@@ -13,7 +13,7 @@
 	ld a, $90
 	ld [hWY], a
 	call WaitBGMap
-	ld b, SCGB_19
+	ld b, SCGB_GAMEFREAK_LOGO
 	call GetSGBLayout
 	call SetPalettes
 	ld c, 10
@@ -82,13 +82,13 @@
 	depixel 10, 11, 4, 0
 	ld a, SPRITE_ANIM_INDEX_GAMEFREAK_LOGO
 	call _InitSpriteAnimStruct
-	ld hl, $7
+	ld hl, SPRITEANIMSTRUCT_YOFFSET
 	add hl, bc
 	ld [hl], $a0
-	ld hl, $c
+	ld hl, SPRITEANIMSTRUCT_0C
 	add hl, bc
 	ld [hl], $60
-	ld hl, $d
+	ld hl, SPRITEANIMSTRUCT_0D
 	add hl, bc
 	ld [hl], $30
 	xor a
@@ -101,7 +101,7 @@
 	ld [hBGMapMode], a
 	ld a, $90
 	ld [hWY], a
-	ld de, $e4e4
+	lb de, %11100100, %11100100
 	call DmgToCgbObjPals
 	ret
 ; e465e
@@ -120,9 +120,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .dw
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -218,9 +217,8 @@
 	ld e, [hl]
 	ld d, 0
 	ld hl, GameFreakLogoScenes
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -317,9 +315,8 @@
 	ld e, a
 	ld d, $0
 	ld hl, GameFreakLogoPalettes
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [rSVBK]
 	push af
 	ld a, $5
@@ -436,9 +433,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, IntroScenes
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -986,9 +982,8 @@
 	ret z
 	cp c
 	jr z, .playsound
-rept 2
 	inc hl
-endr
+	inc hl
 	jr .loop
 .playsound
 	ld a, [hli]
@@ -1667,9 +1662,8 @@
 	ld d, $0
 	ld hl, BGPals
 	add hl, de
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [wcf65]
 	and $3f
 	cp $1f
@@ -1698,9 +1692,8 @@
 
 	push hl
 	ld hl, .BWFade
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld d, [hl]
 	ld e, a
@@ -1712,9 +1705,8 @@
 
 	push hl
 	ld hl, .BlackLBlueFade
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld d, [hl]
 	ld e, a
@@ -1726,9 +1718,8 @@
 
 	push hl
 	ld hl, .BlackBlueFade
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld d, [hl]
 	ld e, a
@@ -2127,9 +2118,8 @@
 	; grass in the front
 	ld hl, LYOverrides + $5f
 	ld a, [hl]
-rept 2
 	inc a
-endr
+	inc a
 	ld bc, $31
 	call ByteFill
 	ld a, [LYOverrides + 0]
--- a/engine/debug.asm
+++ b/engine/debug.asm
@@ -300,9 +300,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, Jumptable_81acf
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -482,9 +481,8 @@
 	inc a
 	ld l, a
 	ld h, $0
-rept 2
 	add hl, hl
-endr
+	add hl, hl
 	ld de, OverworldMap
 	add hl, de
 	ld de, wc608
@@ -558,9 +556,8 @@
 	ld a, [wc608 + 3]
 	ld [hli], a
 	xor a
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	ld [hl], a
 	ld hl, wSGBPals
 	call Function81f0c
@@ -609,9 +606,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, Jumptable_81d02
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -855,9 +851,8 @@
 Function81e55: ; 81e55
 	cp $32
 	jr c, .asm_81e5b
-rept 2
 	inc a
-endr
+	inc a
 
 .asm_81e5b
 	add $bf
@@ -938,9 +933,8 @@
 	inc a
 	ld l, a
 	ld h, $0
-rept 2
 	add hl, hl
-endr
+	add hl, hl
 	ld de, OverworldMap
 	add hl, de
 	ld e, l
@@ -970,9 +964,8 @@
 	inc de
 	ld [hli], a
 	xor a
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	dec c
 	jr nz, .asm_81ee3
 	ret
@@ -1108,9 +1101,8 @@
 	ld a, b
 	ld [hli], a
 	ld a, [de]
-rept 2
 	add a
-endr
+	add a
 	add $18
 	ld [hli], a
 	xor a
@@ -1356,9 +1348,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .dw
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -1400,9 +1391,8 @@
 	ld e, a
 	ld d, $0
 	ld hl, wc608
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld e, l
 	ld d, h
 	call Function81ea5
@@ -1500,9 +1490,8 @@
 	ld c, a
 	ld b, $0
 	ld hl, wc608
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, e
 	ld [hli], a
 	ld [hl], d
--- /dev/null
+++ b/engine/delete_save_change_clock.asm
@@ -1,0 +1,298 @@
+_ResetClock: ; 4d3b1
+	callba BlankScreen
+	ld b, SCGB_08
+	call GetSGBLayout
+	call LoadStandardFont
+	call LoadFontsExtra
+	ld de, MUSIC_MAIN_MENU
+	call PlayMusic
+	ld hl, .text_askreset
+	call PrintText
+	ld hl, .NoYes_MenuDataHeader
+	call CopyMenuDataHeader
+	call VerticalMenu
+	ret c
+	ld a, [wMenuCursorY]
+	cp $1
+	ret z
+	call ClockResetPassword
+	jr c, .wrongpassword
+	ld a, BANK(sRTCStatusFlags)
+	call GetSRAMBank
+	ld a, $80
+	ld [sRTCStatusFlags], a
+	call CloseSRAM
+	ld hl, .text_okay
+	call PrintText
+	ret
+
+.wrongpassword
+	ld hl, .text_wrong
+	call PrintText
+	ret
+
+.text_okay ; 0x4d3fe
+	; Password OK. Select CONTINUE & reset settings.
+	text_jump UnknownText_0x1c55db
+	db "@"
+
+.text_wrong ; 0x4d403
+	; Wrong password!
+	text_jump UnknownText_0x1c560b
+	db "@"
+
+.text_askreset ; 0x4d408
+	; Reset the clock?
+	text_jump UnknownText_0x1c561c
+	db "@"
+
+.NoYes_MenuDataHeader: ; 0x4d40d
+	db $00 ; flags
+	db 07, 14 ; start coords
+	db 11, 19 ; end coords
+	dw .NoYes_MenuData2
+	db 1 ; default option
+
+.NoYes_MenuData2: ; 0x4d415
+	db $c0 ; flags
+	db 2 ; items
+	db "NO@"
+	db "YES@"
+
+ClockResetPassword: ; 4d41e
+	call .CalculatePassword
+	push de
+	ld hl, StringBuffer2
+	ld bc, 5
+	xor a
+	call ByteFill
+	ld a, $4
+	ld [StringBuffer2 + 5], a
+	ld hl, .pleaseenterpasswordtext
+	call PrintText
+.loop
+	call .updateIDdisplay
+.loop2
+	call JoyTextDelay
+	ld a, [hJoyLast]
+	ld b, a
+	and A_BUTTON
+	jr nz, .confirm
+	ld a, b
+	and D_PAD
+	jr z, .loop2
+	call .dpadinput
+	ld c, 3
+	call DelayFrames
+	jr .loop
+
+.confirm
+	call .ConvertDecIDToBytes
+	pop de
+	ld a, e
+	cp l
+	jr nz, .nope
+	ld a, d
+	cp h
+	jr nz, .nope
+	and a
+	ret
+
+.nope
+	scf
+	ret
+
+.pleaseenterpasswordtext ; 0x4d463
+	; Please enter the password.
+	text_jump UnknownText_0x1c562e
+	db "@"
+
+.updateIDdisplay ; 4d468
+	hlcoord 14, 15
+	ld de, StringBuffer2
+	ld c, 5
+.loop3
+	ld a, [de]
+	add "0"
+	ld [hli], a
+	inc de
+	dec c
+	jr nz, .loop3
+	hlcoord 14, 16
+	ld bc, 5
+	ld a, " "
+	call ByteFill
+	hlcoord 14, 16
+	ld a, [StringBuffer2 + 5]
+	ld e, a
+	ld d, $0
+	add hl, de
+	ld [hl], $61
+	ret
+
+.dpadinput ; 4d490
+	ld a, b
+	and D_LEFT
+	jr nz, .left
+	ld a, b
+	and D_RIGHT
+	jr nz, .right
+	ld a, b
+	and D_UP
+	jr nz, .up
+	ld a, b
+	and D_DOWN
+	jr nz, .down
+	ret
+
+.left
+	ld a, [StringBuffer2 + 5]
+	and a
+	ret z
+	dec a
+	ld [StringBuffer2 + 5], a
+	ret
+
+.right
+	ld a, [StringBuffer2 + 5]
+	cp $4
+	ret z
+	inc a
+	ld [StringBuffer2 + 5], a
+	ret
+
+.up
+	call .getcurrentdigit
+	ld a, [hl]
+	cp 9
+	jr z, .wraparound_up
+	inc a
+	ld [hl], a
+	ret
+
+.wraparound_up
+	ld [hl], $0
+	ret
+
+.down
+	call .getcurrentdigit
+	ld a, [hl]
+	and a
+	jr z, .wraparound_down
+	dec a
+	ld [hl], a
+	ret
+
+.wraparound_down
+	ld [hl], 9
+	ret
+
+.getcurrentdigit ; 4d4d5
+	ld a, [StringBuffer2 + 5]
+	ld e, a
+	ld d, $0
+	ld hl, StringBuffer2
+	add hl, de
+	ret
+
+.ConvertDecIDToBytes: ; 4d4e0
+	ld hl, 0
+	ld de, StringBuffer2 + 4
+	ld bc, 1
+	call .ConvertToBytes
+	ld bc, 10
+	call .ConvertToBytes
+	ld bc, 100
+	call .ConvertToBytes
+	ld bc, 1000
+	call .ConvertToBytes
+	ld bc, 10000
+.ConvertToBytes: ; 4d501
+	ld a, [de]
+	dec de
+	push hl
+	ld hl, 0
+	call AddNTimes
+	ld c, l
+	ld b, h
+	pop hl
+	add hl, bc
+	ret
+
+.CalculatePassword: ; 4d50f
+	ld a, BANK(sPlayerData)
+	call GetSRAMBank
+	ld de, 0
+	ld hl, sPlayerData + (PlayerID - wPlayerData)
+	ld c, $2
+	call .ComponentFromNumber
+	ld hl, sPlayerData + (PlayerName - wPlayerData)
+	ld c, $5 ; PLAYER_NAME_LENGTH_J
+	call .ComponentFromString
+	ld hl, sPlayerData + (Money - wPlayerData)
+	ld c, $3
+	call .ComponentFromNumber
+	call CloseSRAM
+	ret
+
+.ComponentFromNumber: ; 4d533
+	ld a, [hli]
+	add e
+	ld e, a
+	ld a, $0
+	adc d
+	ld d, a
+	dec c
+	jr nz, .ComponentFromNumber
+	ret
+
+.ComponentFromString: ; 4d53e
+	ld a, [hli]
+	cp "@"
+	ret z
+	add e
+	ld e, a
+	ld a, $0
+	adc d
+	ld d, a
+	dec c
+	jr nz, .ComponentFromString
+	ret
+
+_DeleteSaveData: ; 4d54c
+	callba BlankScreen
+	ld b, SCGB_08
+	call GetSGBLayout
+	call LoadStandardFont
+	call LoadFontsExtra
+	ld de, MUSIC_MAIN_MENU
+	call PlayMusic
+	ld hl, .Text_ClearAllSaveData
+	call PrintText
+	ld hl, .NoYesMenuDataHeader
+	call CopyMenuDataHeader
+	call VerticalMenu
+	ret c
+	ld a, [wMenuCursorY]
+	cp $1
+	ret z
+	callba EmptyAllSRAMBanks
+	ret
+
+.Text_ClearAllSaveData: ; 0x4d580
+	; Clear all save data?
+	text_jump UnknownText_0x1c564a
+	db "@"
+
+.NoYesMenuDataHeader: ; 0x4d585
+	db $00 ; flags
+	db 07, 14 ; start coords
+	db 11, 19 ; end coords
+	dw .MenuData2
+	db 1 ; default option
+
+.MenuData2: ; 0x4d58d
+	db $c0 ; flags
+	db 2 ; items
+	db "NO@"
+	db "YES@"
--- a/engine/events_3.asm
+++ b/engine/events_3.asm
@@ -184,12 +184,10 @@
 InitMapSignAttrMap: ; b8115
 	ld de, AttrMap - TileMap
 	add hl, de
-rept 2
 	inc b
-endr
-rept 2
+	inc b
 	inc c
-endr
+	inc c
 	ld a, $87
 .loop
 	push bc
@@ -261,15 +259,13 @@
 	jr .enterloop
 
 .continueloop
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 
 .enterloop
 	inc a
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	dec a
 	dec c
 	jr nz, .continueloop
@@ -522,9 +518,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, TreeMons
-rept 2
 	add hl, de
-endr
+	add hl, de
 
 	ld a, [hli]
 	ld h, [hl]
--- a/engine/evolution_animation.asm
+++ b/engine/evolution_animation.asm
@@ -187,9 +187,8 @@
 	call .Flash
 	pop bc
 	inc b
-rept 2
 	dec c
-endr
+	dec c
 	jr nz, .loop
 	and a
 	ret
@@ -344,9 +343,8 @@
 	ld a, [hVBlankCounter]
 	and %1110
 	srl a
-rept 2
 	inc a
-endr
+	inc a
 	and $7
 	ld b, a
 	ld hl, Sprites + 3 ; attributes
--- a/engine/evolve.asm
+++ b/engine/evolve.asm
@@ -46,9 +46,8 @@
 	ld b, 0
 	ld c, a
 	ld hl, EvosAttacksPointers
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -437,9 +436,8 @@
 	ld b, 0
 	ld c, a
 	ld hl, EvosAttacksPointers
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -638,9 +636,8 @@
 .loop ; For each Pokemon...
 	ld hl, EvosAttacksPointers
 	ld b, 0
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/engine/fish.asm
+++ b/engine/fish.asm
@@ -38,9 +38,8 @@
 	inc hl
 	ld e, b
 	ld d, 0
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -84,9 +83,8 @@
 	and 3
 	cp NITE
 	jr c, .time_species
-rept 2
 	inc hl
-endr
+	inc hl
 
 .time_species
 	ld d, [hl]
--- a/engine/healmachineanim.asm
+++ b/engine/healmachineanim.asm
@@ -25,9 +25,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .Pointers
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/engine/landmarks.asm
+++ b/engine/landmarks.asm
@@ -3,9 +3,8 @@
 	push hl
 	ld l, e
 	ld h, 0
-rept 2
 	add hl, hl
-endr
+	add hl, hl
 	ld de, Landmarks
 	add hl, de
 	ld a, [hli]
@@ -24,9 +23,8 @@
 
 	ld l, e
 	ld h, 0
-rept 2
 	add hl, hl
-endr
+	add hl, hl
 	ld de, Landmarks + 2
 	add hl, de
 	ld a, [hli]
--- a/engine/link.asm
+++ b/engine/link.asm
@@ -1094,14 +1094,12 @@
 	ld a, $46
 	ld [hli], a
 	xor a
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	ld [hl], a
 	pop hl
-rept 2
 	inc de
-endr
+	inc de
 	ret
 ; 28771
 
--- a/engine/mart.asm
+++ b/engine/mart.asm
@@ -145,9 +145,8 @@
 
 .IsAMart:
 	ld hl, Marts
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld e, [hl]
 	inc hl
 	ld d, [hl]
@@ -393,9 +392,8 @@
 	pop af
 	ld e, a
 	ld d, 0
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -405,9 +403,8 @@
 
 MartAskPurchaseQuantity: ; 15c91
 	call GetMartDialogGroup ; gets a pointer from GetMartDialogGroup.MartTextFunctionPointers
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [hl]
 	and a
 	jp z, StandardMartAskPurchaseQuantity
--- a/engine/move_mon.asm
+++ b/engine/move_mon.asm
@@ -654,7 +654,7 @@
 	ld a, [sBoxCount]
 	dec a
 	ld b, a
-	call Functiondcb6
+	call RestorePPofDepositedPokemon
 .CloseSRAM_And_ClearCarryFlag:
 	call CloseSRAM
 	and a
@@ -667,7 +667,7 @@
 	ret
 ; dcb6
 
-Functiondcb6: ; dcb6
+RestorePPofDepositedPokemon: ; dcb6
 	ld a, b
 	ld hl, sBoxMons
 	ld bc, BOXMON_STRUCT_LENGTH
@@ -696,10 +696,10 @@
 	ld a, [MonType]
 	push af
 	ld b, 0
-.asm_dcec
+.loop
 	ld a, [hli]
 	and a
-	jr z, .asm_dd18
+	jr z, .done
 	ld [TempMonMoves], a
 	ld a, BOXMON
 	ld [MonType], a
@@ -722,9 +722,9 @@
 	inc b
 	ld a, b
 	cp NUM_MOVES
-	jr c, .asm_dcec
+	jr c, .loop
 
-.asm_dd18
+.done
 	pop af
 	ld [MonType], a
 	pop af
@@ -1025,7 +1025,7 @@
 	call CopyBytes
 
 	ld b, 0
-	call Functiondcb6
+	call RestorePPofDepositedPokemon
 
 	call CloseSRAM
 	scf
--- /dev/null
+++ b/engine/move_mon_wo_mail.asm
@@ -1,0 +1,133 @@
+InsertPokemonIntoBox: ; 51322
+	ld a, BANK(sBoxCount)
+	call GetSRAMBank
+	ld hl, sBoxCount
+	call InsertSpeciesIntoBoxOrParty
+	ld a, [sBoxCount]
+	dec a
+	ld [wd265], a
+	ld hl, sBoxMonNicknames
+	ld bc, PKMN_NAME_LENGTH
+	ld de, wBufferMonNick
+	call InsertDataIntoBoxOrParty
+	ld a, [sBoxCount]
+	dec a
+	ld [wd265], a
+	ld hl, sBoxMonOT
+	ld bc, NAME_LENGTH
+	ld de, wBufferMonOT
+	call InsertDataIntoBoxOrParty
+	ld a, [sBoxCount]
+	dec a
+	ld [wd265], a
+	ld hl, sBoxMons
+	ld bc, BOXMON_STRUCT_LENGTH
+	ld de, wBufferMon
+	call InsertDataIntoBoxOrParty
+	ld hl, wBufferMonMoves
+	ld de, TempMonMoves
+	ld bc, NUM_MOVES
+	call CopyBytes
+	ld hl, wBufferMonPP
+	ld de, TempMonPP
+	ld bc, NUM_MOVES
+	call CopyBytes
+	ld a, [CurPartyMon]
+	ld b, a
+	callba RestorePPofDepositedPokemon
+	jp CloseSRAM
+
+InsertPokemonIntoParty: ; 5138b
+	ld hl, PartyCount
+	call InsertSpeciesIntoBoxOrParty
+	ld a, [PartyCount]
+	dec a
+	ld [wd265], a
+	ld hl, PartyMonNicknames
+	ld bc, PKMN_NAME_LENGTH
+	ld de, wBufferMonNick
+	call InsertDataIntoBoxOrParty
+	ld a, [PartyCount]
+	dec a
+	ld [wd265], a
+	ld hl, PartyMonOT
+	ld bc, NAME_LENGTH
+	ld de, wBufferMonOT
+	call InsertDataIntoBoxOrParty
+	ld a, [PartyCount]
+	dec a
+	ld [wd265], a
+	ld hl, PartyMons
+	ld bc, PARTYMON_STRUCT_LENGTH
+	ld de, wBufferMon
+	call InsertDataIntoBoxOrParty
+	ret
+
+InsertSpeciesIntoBoxOrParty: ; 513cb
+	inc [hl]
+	inc hl
+	ld a, [CurPartyMon]
+	ld c, a
+	ld b, 0
+	add hl, bc
+	ld a, [CurPartySpecies]
+	ld c, a
+.loop
+	ld a, [hl]
+	ld [hl], c
+	inc hl
+	inc c
+	ld c, a
+	jr nz, .loop
+	ret
+
+InsertDataIntoBoxOrParty: ; 513e0
+	push de
+	push hl
+	push bc
+	ld a, [wd265]
+	dec a
+	call AddNTimes
+	push hl
+	add hl, bc
+	ld d, h
+	ld e, l
+	pop hl
+.loop
+	push bc
+	ld a, [wd265]
+	ld b, a
+	ld a, [CurPartyMon]
+	cp b
+	pop bc
+	jr z, .insert
+	push hl
+	push de
+	push bc
+	call CopyBytes
+	pop bc
+	pop de
+	pop hl
+	push hl
+	ld a, l
+	sub c
+	ld l, a
+	ld a, h
+	sbc b
+	ld h, a
+	pop de
+	ld a, [wd265]
+	dec a
+	ld [wd265], a
+	jr .loop
+
+.insert
+	pop bc
+	pop hl
+	ld a, [CurPartyMon]
+	call AddNTimes
+	ld d, h
+	ld e, l
+	pop hl
+	call CopyBytes
+	ret
--- a/engine/namingscreen.asm
+++ b/engine/namingscreen.asm
@@ -65,9 +65,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .Jumptable
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -401,9 +400,8 @@
 	ld e, a
 	ld d, $0
 	ld hl, .Jumptable
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -662,9 +660,8 @@
 	jr nz, .asm_11ade
 	ld a, $4
 .asm_11ade
-rept 2
 	dec a
-endr
+	dec a
 	ld e, a
 	add a
 	add e
@@ -1164,9 +1161,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .Jumptable
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -1391,9 +1387,8 @@
 	jr nz, .wrap_around_command_left
 	ld a, $4
 .wrap_around_command_left
-rept 2
 	dec a
-endr
+	dec a
 	ld e, a
 	add a
 	add e
@@ -1476,9 +1471,8 @@
 	jr nz, .asm_121c3
 	push hl
 	ld hl, wNamingScreenCurrNameLength
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	jr .asm_121c8
 
 .asm_121c3
--- a/engine/npctrade.asm
+++ b/engine/npctrade.asm
@@ -311,9 +311,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, NPCTrades
-rept 2
 	add hl, de
-endr
+	add hl, de
 	pop de
 	add hl, de
 	ret
@@ -458,9 +457,8 @@
 	call AddNTimes
 	ld a, [wcf64]
 	ld c, a
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/engine/options_menu.asm
+++ b/engine/options_menu.asm
@@ -85,9 +85,8 @@
 	ld e, a ; copy it to de
 	ld d, 0
 	ld hl, .Pointers
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -143,9 +142,8 @@
 .NonePressed:
 	ld b, 0
 	ld hl, .Strings
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld e, [hl]
 	inc hl
 	ld d, [hl]
@@ -363,9 +361,8 @@
 .NonePressed:
 	ld b, $0
 	ld hl, .Strings
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld e, [hl]
 	inc hl
 	ld d, [hl]
--- a/engine/overworld.asm
+++ b/engine/overworld.asm
@@ -147,9 +147,8 @@
 	ld c, a
 	ld b, 0
 	ld hl, OutdoorSprites
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -364,9 +363,8 @@
 	jr z, .exists
 	and a
 	jr z, .new
-rept 2
 	inc hl
-endr
+	inc hl
 	dec c
 	jr nz, .loop
 
@@ -428,9 +426,8 @@
 	ld a, [de]
 	and a
 	jr nz, .FoundLastSprite
-rept 2
 	dec de
-endr
+	dec de
 	dec c
 	jr nz, .FindLastSprite
 .FoundLastSprite:
@@ -472,16 +469,14 @@
 ; Keep doing this until everything's in order.
 
 .loop
-rept 2
 	dec de
-endr
+	dec de
 	dec c
 	jr nz, .CheckFollowing
 
 	pop hl
-rept 2
 	inc hl
-endr
+	inc hl
 	pop de
 	pop bc
 	dec c
--- a/engine/pack.asm
+++ b/engine/pack.asm
@@ -1252,9 +1252,8 @@
 Pack_GetJumptablePointer: ; 1086b
 	ld e, a
 	ld d, 0
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -1300,9 +1299,8 @@
 	jr nz, .female
 .male_dude
 	ld hl, PackGFXPointers
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld e, a
 	ld d, [hl]
--- a/engine/party_menu.asm
+++ b/engine/party_menu.asm
@@ -110,9 +110,8 @@
 	jr nz, .loop
 
 .end
-rept 2
 	dec hl
-endr
+	dec hl
 	ld de, .CANCEL
 	call PlaceString
 	ret
@@ -219,9 +218,8 @@
 	pop de
 	ld a, "/"
 	ld [hli], a
-rept 2
 	inc de
-endr
+	inc de
 	lb bc, 2, 3
 	call PrintNum
 
@@ -390,9 +388,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, EvosAttacksPointers
-rept 2
 	add hl, de
-endr
+	add hl, de
 	call .DetermineCompatibility
 	pop hl
 	call PlaceString
@@ -426,19 +423,16 @@
 	ld a, [hli]
 	and a
 	jr z, .nope
-rept 2
 	inc hl
-endr
+	inc hl
 	cp EVOLVE_ITEM
 	jr nz, .loop2
-rept 2
 	dec hl
-endr
+	dec hl
 	ld a, [CurItem]
 	cp [hl]
-rept 2
 	inc hl
-endr
+	inc hl
 	jr nz, .loop2
 	ld de, .string_able
 	ret
@@ -613,9 +607,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .Pointers
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -794,9 +787,8 @@
 	ld hl, PartyMenuStrings
 	ld e, a
 	ld d, $0
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld d, [hl]
 	ld e, a
@@ -932,9 +924,8 @@
 .PrintText: ; 505c1
 	ld e, a
 	ld d, 0
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/engine/phone.asm
+++ b/engine/phone.asm
@@ -266,9 +266,8 @@
 	jr nc, .NoPhoneCall
 
 	call .DoSpecialPhoneCall
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [hli]
 	ld e, a
 	push hl
@@ -520,9 +519,8 @@
 	call Phone_CallerTextbox
 	hlcoord 1, 2
 	ld [hl], $62
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [PhoneScriptBank]
 	ld b, a
 	ld a, [PhoneCallerLo]
@@ -621,9 +619,8 @@
 	call Phone_CallerTextbox
 	hlcoord 1, 1
 	ld [hl], $62
-rept 2
 	inc hl
-endr
+	inc hl
 	ld d, h
 	ld e, l
 	pop bc
@@ -699,9 +696,8 @@
 	ld c, b
 	ld b, 0
 	ld hl, NonTrainerCallerNames
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld e, a
 	ld d, [hl]
--- a/engine/pokedex.asm
+++ b/engine/pokedex.asm
@@ -2385,9 +2385,8 @@
 Pokedex_LoadPointer: ; 41432
 	ld e, a
 	ld d, 0
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/engine/printer.asm
+++ b/engine/printer.asm
@@ -21,9 +21,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .Jumptable
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -1133,9 +1132,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, PrinterStatusStringPointers
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld e, [hl]
 	inc hl
 	ld d, [hl]
@@ -1166,9 +1164,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, PrinterStatusStringPointers
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld e, [hl]
 	inc hl
 	ld d, [hl]
--- a/engine/rtc.asm
+++ b/engine/rtc.asm
@@ -35,9 +35,8 @@
 	cp [hl]
 	jr c, .match
 ; else, get the next entry
-rept 2
 	inc hl
-endr
+	inc hl
 ; try again
 	jr .check
 
--- /dev/null
+++ b/engine/search2.asm
@@ -1,0 +1,134 @@
+_FindGreaterThanThatLevel: ; 4dbd2
+	ld hl, PartyMon1Level
+	call FindGreaterThanThatLevel
+	ret
+
+_FindAtLeastThatHappy: ; 4dbd9
+	ld hl, PartyMon1Happiness
+	call FindAtLeastThatHappy
+	ret
+
+_FindThatSpecies: ; 4dbe0
+	ld hl, PartyMon1Species
+	jp FindThatSpecies
+
+_FindThatSpeciesYourTrainerID: ; 4dbe6
+	ld hl, PartyMon1Species
+	call FindThatSpecies
+	ret z
+	ld a, c
+	ld hl, PartyMon1ID
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call AddNTimes
+	ld a, [PlayerID]
+	cp [hl]
+	jr nz, .nope
+	inc hl
+	ld a, [PlayerID + 1]
+	cp [hl]
+	jr nz, .nope
+	ld a, $1
+	and a
+	ret
+
+.nope
+	xor a
+	ret
+
+FindAtLeastThatHappy: ; 4dc0a
+; Sets the bits for the Pokemon that have a happiness greater than or equal to b.
+; The lowest bits are used.  Sets z if no Pokemon in your party is at least that happy.
+	ld c, $0
+	ld a, [PartyCount]
+	ld d, a
+.loop
+	ld a, d
+	dec a
+	push hl
+	push bc
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call AddNTimes
+	pop bc
+	ld a, b
+	cp [hl]
+	pop hl
+	jr z, .greater_equal
+	jr nc, .lower
+
+.greater_equal
+	ld a, c
+	or $1
+	ld c, a
+
+.lower
+	sla c
+	dec d
+	jr nz, .loop
+	call RetroactivelyIgnoreEggs
+	ld a, c
+	and a
+	ret
+
+FindGreaterThanThatLevel: ; 4dc31
+	ld c, $0
+	ld a, [PartyCount]
+	ld d, a
+.loop
+	ld a, d
+	dec a
+	push hl
+	push bc
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call AddNTimes
+	pop bc
+	ld a, b
+	cp [hl]
+	pop hl
+	jr c, .greater
+	ld a, c
+	or $1
+	ld c, a
+
+.greater
+	sla c
+	dec d
+	jr nz, .loop
+	call RetroactivelyIgnoreEggs
+	ld a, c
+	and a
+	ret
+
+FindThatSpecies: ; 4dc56
+; Find species b in your party.
+; If you have no Pokemon, returns c = -1 and z.
+; If that species is in your party, returns its location in c, and nz.
+; Otherwise, returns z.
+	ld c, -1
+	ld hl, PartySpecies
+.loop
+	ld a, [hli]
+	cp -1
+	ret z
+	inc c
+	cp b
+	jr nz, .loop
+	ld a, $1
+	and a
+	ret
+
+RetroactivelyIgnoreEggs: ; 4dc67
+	ld e, -2
+	ld hl, PartySpecies
+.loop
+	ld a, [hli]
+	cp -1
+	ret z
+	cp EGG
+	jr nz, .skip_notegg
+	ld a, c
+	and e
+	ld c, a
+
+.skip_notegg
+	rlc e
+	jr .loop
--- a/engine/selectmenu.asm
+++ b/engine/selectmenu.asm
@@ -45,9 +45,8 @@
 	inc hl
 	ld e, a
 	ld d, 0
-rept 2
 	add hl, de
-endr
+	add hl, de
 	call .IsSameItem
 	jr c, .NoRegisteredItem
 	and a
@@ -71,9 +70,8 @@
 	inc hl
 	ld e, a
 	ld d, 0
-rept 2
 	add hl, de
-endr
+	add hl, de
 	call .IsSameItem
 	jr c, .NoRegisteredItem
 	ret
--- a/engine/sprites.asm
+++ b/engine/sprites.asm
@@ -556,8 +556,8 @@
 	db SPRITE_ANIM_FRAMESET_07, SPRITE_ANIM_SEQ_04, $00 ; 01
 	db SPRITE_ANIM_FRAMESET_08, SPRITE_ANIM_SEQ_05, $05 ; 02
 	db SPRITE_ANIM_FRAMESET_GAMEFREAK_LOGO, SPRITE_ANIM_SEQ_GAMEFREAK_LOGO, $00 ; 03
-	db SPRITE_ANIM_FRAMESET_0B, SPRITE_ANIM_SEQ_07, $06 ; 04
-	db SPRITE_ANIM_FRAMESET_0C, SPRITE_ANIM_SEQ_08, $06 ; 05
+	db SPRITE_ANIM_FRAMESET_0B, SPRITE_ANIM_SEQ_07, $06 ; 04 gs intro star
+	db SPRITE_ANIM_FRAMESET_0C, SPRITE_ANIM_SEQ_08, $06 ; 05 gs intro sparkle
 	db SPRITE_ANIM_FRAMESET_SLOT_GOLEM, SPRITE_ANIM_SEQ_SLOT_GOLEM, $07 ; 06 slots golem
 	db SPRITE_ANIM_FRAMESET_SLOTS_CHANSEY, SPRITE_ANIM_SEQ_SLOTS_CHANSEY, $07 ; 07 slots chansey
 	db SPRITE_ANIM_FRAMESET_SLOTS_EGG, SPRITE_ANIM_SEQ_SLOTS_EGG, $07 ; 08 slots egg
--- a/engine/stats_screen.asm
+++ b/engine/stats_screen.asm
@@ -641,9 +641,8 @@
 	inc a
 	ld d, a
 	callba CalcExpAtLevel
-rept 2
 	ld hl, TempMonExp + 2
-endr
+	ld hl, TempMonExp + 2
 	ld a, [hQuotient + 2]
 	sub [hl]
 	dec hl
@@ -660,9 +659,8 @@
 .AlreadyAtMaxLevel:
 	ld hl, Buffer1 ; wd1ea (aliases: MagikarpLength)
 	xor a
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	ld [hl], a
 	ret
 ; 4e119 (13:6119)
--- a/engine/switch_items.asm
+++ b/engine/switch_items.asm
@@ -231,9 +231,8 @@
 	ld c, a
 	ld b, 0
 	ld hl, .spacing_dws
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld c, [hl]
 	inc hl
 	ld b, [hl]
--- a/engine/time.asm
+++ b/engine/time.asm
@@ -374,9 +374,8 @@
 ; 115d6
 
 CalcMinsHoursDaysSince: ; 115d6
-rept 2
 	inc hl
-endr
+	inc hl
 	xor a
 	jr _CalcMinsHoursDaysSince
 ; 115db
--- a/engine/time_capsule/conversion.asm
+++ b/engine/time_capsule/conversion.asm
@@ -46,9 +46,8 @@
 	ld [CurSpecies], a
 	call GetBaseData
 	ld hl, wLinkOTPartyMonTypes
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [BaseType1]
 	cp [hl]
 	jr nz, .abnormal
--- a/engine/timeofdaypals.asm
+++ b/engine/timeofdaypals.asm
@@ -245,9 +245,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .TimePalettes
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -346,9 +345,8 @@
 	ld c, a
 	ld b, $0
 	ld hl, .dmgfades
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/engine/timeset.asm
+++ b/engine/timeset.asm
@@ -200,9 +200,8 @@
 	push hl
 	call DisplayHourOClock
 	pop de
-rept 2
 	inc de
-endr
+	inc de
 	ld a, ":"
 	ld [de], a
 	inc de
@@ -521,9 +520,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .WeekdayStrings
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld d, [hl]
 	ld e, a
--- a/engine/title.asm
+++ b/engine/title.asm
@@ -351,9 +351,8 @@
 	ld b, a
 	ld a, e
 	ld [hli], a
-rept 2
 	inc e
-endr
+	inc e
 	ld a, $80
 	ld [hli], a
 	dec c
--- a/engine/tmhm2.asm
+++ b/engine/tmhm2.asm
@@ -581,9 +581,8 @@
 	dec a
 	ld c, a
 	ld b, 0
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld e, a
 	ld d, [hl]
--- a/engine/trade/animation.asm
+++ b/engine/trade/animation.asm
@@ -224,9 +224,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .JumpTable
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -519,9 +518,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, Jumptable_2928f
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -1105,9 +1103,8 @@
 	ld e, [hl]
 	ld d, 0
 	ld hl, Jumptable_29686
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/engine/unown_puzzle.asm
+++ b/engine/unown_puzzle.asm
@@ -178,9 +178,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .Jumptable
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -840,9 +839,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .LZPointers
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/engine/unowndex.asm
+++ b/engine/unowndex.asm
@@ -34,9 +34,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, UnownWords
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld e, a
 	ld d, [hl]
--- a/engine/warp_connection.asm
+++ b/engine/warp_connection.asm
@@ -369,7 +369,7 @@
 
 .left
 	ld a, [PlayerStandingMapX]
-	sub $4
+	sub 4
 	cp -1
 	jr z, .ok
 	and a
--- a/engine/wildmons.asm
+++ b/engine/wildmons.asm
@@ -108,9 +108,8 @@
 	ld a, [wNamedObjectIndexBuffer]
 	cp [hl]
 	jr z, .found
-rept 2
 	inc hl
-endr
+	inc hl
 	pop af
 	dec a
 	jr nz, .ScanMapLoop
@@ -274,9 +273,8 @@
 	call CheckOnWater
 	ld de, .WaterMonTable
 	jr z, .watermon
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [TimeOfDay]
 	ld bc, $e
 	call AddNTimes
@@ -702,9 +700,8 @@
 	inc hl
 	ld c, a
 	ld b, $0
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [wRoamMons_LastMapGroup]
 	cp [hl]
 	jr nz, .done
@@ -866,9 +863,8 @@
 	dec a
 	ld c, a
 	ld b, $0
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 ; We now have the pointer to one of the last (rarest) three wild Pokemon found in that area.
 	inc hl
 	ld c, [hl] ; Contains the species index of this rare Pokemon
@@ -942,9 +938,8 @@
 	and $3
 	ld c, a
 	ld b, $0
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	inc hl
 	ld a, [hl]
 	ld [wNamedObjectIndexBuffer], a
@@ -963,9 +958,8 @@
 	dec a
 	ld c, a
 	ld b, 0
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, BANK(TrainerGroups)
 	call GetFarHalfword
 
--- a/event/battle_tower.asm
+++ b/event/battle_tower.asm
@@ -200,13 +200,11 @@
 .PrintNthText: ; 8b2a9
 	push bc
 	call .GetTextPointers
-rept 2
 	inc hl
-endr
+	inc hl
 	ld b, $0
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	call .LoadTextPointer
 	call PrintText
 	pop bc
--- a/event/buena.asm
+++ b/event/buena.asm
@@ -322,9 +322,8 @@
 	ld hl, .prizes
 	ld b, 0
 	ld c, a
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ret
 ; 8b15e
 
--- a/event/bug_contest_2.asm
+++ b/event/bug_contest_2.asm
@@ -13,9 +13,8 @@
 	ld b, RESET_FLAG
 	call EventFlagAction
 	pop hl
-rept 2
 	inc hl
-endr
+	inc hl
 	pop bc
 	dec c
 	jr nz, .loop1
@@ -34,9 +33,8 @@
 	ld e, b
 	ld d, 0
 	ld hl, BugCatchingContestantEventFlagTable
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld e, [hl]
 	inc hl
 	ld d, [hl]
@@ -66,9 +64,8 @@
 	ld hl, BugCatchingContestantEventFlagTable
 	ld e, a
 	ld d, 0
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld e, [hl]
 	inc hl
 	ld d, [hl]
--- a/event/bug_contest_judging.asm
+++ b/event/bug_contest_judging.asm
@@ -85,9 +85,8 @@
 	ld c, a
 	ld b, 0
 	ld hl, BugContestantPointers
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -320,23 +319,20 @@
 	pop de
 	jr nz, .done
 	ld a, e
-rept 2
 	inc a
-endr
+	inc a
 	ld [wBugContestTempPersonID], a
 	dec a
 	ld c, a
 	ld b, 0
 	ld hl, BugContestantPointers
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
-rept 2
 	inc hl
-endr
+	inc hl
 .loop2
 	call Random
 	and 3
@@ -412,9 +408,8 @@
 	ld a, [wContestMonDVs + 0]
 	ld b, a
 	and 2
-rept 2
 	add a
-endr
+	add a
 	ld c, a
 
 	swap b
@@ -433,12 +428,10 @@
 	ld a, b
 	and 2
 	srl a
-rept 2
 	add c
-endr
-rept 2
+	add c
 	add d
-endr
+	add d
 
 	call .AddContestStat
 
--- a/event/celebi.asm
+++ b/event/celebi.asm
@@ -259,9 +259,8 @@
 	ld a, d
 	ld d, $0
 	ld hl, .sinewave
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld e, [hl]
 	inc hl
 	ld d, [hl]
--- a/event/dratini.asm
+++ b/event/dratini.asm
@@ -37,9 +37,8 @@
 
 	; get address of mon's first move
 	pop de
-rept 2
 	inc de
-endr
+	inc de
 
 .GiveMoves:
 	ld a, [hl]
--- a/event/elevator.asm
+++ b/event/elevator.asm
@@ -70,9 +70,8 @@
 	call GetFarByte
 	cp -1
 	jr z, .fail
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [wElevatorPointerBank]
 	call GetFarByte
 	inc hl
@@ -222,9 +221,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .floors
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/event/field_moves.asm
+++ b/event/field_moves.asm
@@ -164,9 +164,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .dw
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -192,9 +191,8 @@
 	ld [wcf64], a
 ; Cut_StartWaiting
 	ld hl, wJumptableIndex
-rept 2
 	inc [hl]
-endr
+	inc [hl]
 	ret
 
 Cut_SpawnAnimateLeaves: ; 8ca3c (23:4a3c)
@@ -269,9 +267,8 @@
 	add e
 	ld e, a
 	ld hl, .Coords
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld e, [hl]
 	inc hl
 	ld d, [hl]
--- a/event/halloffame.asm
+++ b/event/halloffame.asm
@@ -235,9 +235,8 @@
 	ld a, [hli]
 	ld [TempMonSpecies], a
 	ld [CurPartySpecies], a
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [hli]
 	ld [TempMonDVs], a
 	ld a, [hli]
@@ -298,9 +297,8 @@
 	ld a, [hSCX]
 	and a
 	ret z
-rept 2
 	dec a
-endr
+	dec a
 	ld [hSCX], a
 	call DelayFrame
 	jr .frontpicloop
--- a/event/kurt.asm
+++ b/event/kurt.asm
@@ -362,9 +362,8 @@
 	inc hl
 	ld c, a
 	ld b, $0
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	inc hl
 	ld a, [hl]
 	pop bc
@@ -379,9 +378,8 @@
 	ld c, a
 	ld b, $0
 	inc hl
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [CurItem]
 	ld c, a
 	ld a, [hli]
--- a/event/magikarp.asm
+++ b/event/magikarp.asm
@@ -250,9 +250,8 @@
 	; hl = de × 10
 	ld h, d
 	ld l, e
-rept 2
 	add hl, hl
-endr
+	add hl, hl
 	add hl, de
 	add hl, hl
 
--- a/event/magnet_train.asm
+++ b/event/magnet_train.asm
@@ -101,9 +101,8 @@
 	ld d, a
 	ld hl, wcf64
 	ld a, [hl]
-rept 2
 	add d
-endr
+	add d
 	ld [hl], a
 	ret
 
@@ -211,9 +210,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, MagnetTrainBGTiles
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld e, [hl]
 	inc hl
 	ld d, [hl]
@@ -296,9 +294,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .Jumptable
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -398,17 +395,15 @@
 	inc a
 	ld d, a
 	ld a, e
-rept 2
 	add d
-endr
+	add d
 	ld [wcf65], a
 	ld hl, wGlobalAnimXOffset
 	ld a, [wMagnetTrainDirection]
 	ld d, a
 	ld a, [hl]
-rept 2
 	add d
-endr
+	add d
 	ld [hl], a
 	ret
 
--- a/event/mom.asm
+++ b/event/mom.asm
@@ -23,9 +23,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .dw
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -143,9 +142,8 @@
 	call PrintText
 	xor a
 	ld hl, StringBuffer2
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	ld [hl], a
 	ld a, $5
 	ld [wcf64], a
@@ -211,9 +209,8 @@
 	call PrintText
 	xor a
 	ld hl, StringBuffer2
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	ld [hl], a
 	ld a, $5
 	ld [wcf64], a
--- a/event/poke_seer.asm
+++ b/event/poke_seer.asm
@@ -298,9 +298,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, SeerTexts
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/gfx/mail.asm
+++ b/gfx/mail.asm
@@ -90,9 +90,8 @@
 	cp -1
 	jr z, .invalid
 	inc c
-rept 2
 	inc hl
-endr
+	inc hl
 	jr .loop
 
 .invalid
@@ -931,9 +930,8 @@
 .loop
 	ld a, [de]
 	inc de
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	dec c
 	jr nz, .loop
 	ret
--- a/gfx/pics/animation.asm
+++ b/gfx/pics/animation.asm
@@ -110,9 +110,8 @@
 	ld c, e
 	ld b, 0
 	ld hl, PokeAnims
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld b, [hl]
 	ld c, a
@@ -513,9 +512,8 @@
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [wPokeAnimPointerBank]
 	call GetFarHalfword
 	ld a, l
@@ -537,9 +535,8 @@
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [wPokeAnimFramesBank]
 	call GetFarHalfword
 	ld a, [wPokeAnimFramesBank]
@@ -970,9 +967,8 @@
 	dec a
 	ld e, a
 	ld d, 0
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, c
 	ld [wPokeAnimPointerBank], a
 	call GetFarHalfword
@@ -1041,9 +1037,8 @@
 	dec a
 	ld e, a
 	ld d, 0
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, b
 	call GetFarHalfword
 	ld a, l
@@ -1081,9 +1076,8 @@
 	dec a
 	ld e, a
 	ld d, 0
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [wPokeAnimBitmaskBank]
 	call GetFarHalfword
 	ld a, l
--- a/home/battle.asm
+++ b/home/battle.asm
@@ -153,9 +153,8 @@
 	ld hl, .battlevarpairs
 	ld c, a
 	ld b, 0
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 
 	ld a, [hli]
 	ld h, [hl]
@@ -175,9 +174,8 @@
 	ld b, 0
 
 	ld hl, .vars
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 
 	ld a, [hli]
 	ld h, [hl]
--- a/home/copy.asm
+++ b/home/copy.asm
@@ -205,9 +205,8 @@
 .loop
 	ld a, [de]
 	inc de
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 .dec
 	dec c
 	jr nz, .loop
--- a/home/joypad.asm
+++ b/home/joypad.asm
@@ -42,9 +42,8 @@
 	ld a, R_DPAD
 	ld [rJOYP], a
 ; Read twice to give the request time to take.
-rept 2
 	ld a, [rJOYP]
-endr
+	ld a, [rJOYP]
 
 ; The Joypad register output is in the lo nybble (inversed).
 ; We make the hi nybble of our new container d-pad input.
@@ -209,9 +208,8 @@
 	jr nz, .next
 
 ; The current input is overwritten.
-rept 2
 	dec hl
-endr
+	dec hl
 	ld b, NO_INPUT
 	jr .finishauto
 
--- a/home/map_objects.asm
+++ b/home/map_objects.asm
@@ -28,9 +28,8 @@
 .loop
 	cp [hl]
 	jr z, .found
-rept 2
 	inc hl
-endr
+	inc hl
 	dec c
 	jr nz, .loop
 	ld a, [UsedSprites + 1]
@@ -503,9 +502,8 @@
 endr
 	ld a, BANK(SpriteMovementData)
 	call GetFarByte
-rept 2
 	add a
-endr
+	add a
 	and $c
 	pop de
 	pop bc
--- a/home/movement.asm
+++ b/home/movement.asm
@@ -107,9 +107,8 @@
 	push hl
 	ld l, b
 	ld h, 0
-rept 2
 	add hl, hl
-endr
+	add hl, hl
 	ld e, a
 	ld d, 0
 	add hl, de
@@ -148,9 +147,8 @@
 	dec b
 	jr nz, .loop
 	ld a, $1
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	xor a
 rept 3
 	ld [hli], a
--- a/home/text.asm
+++ b/home/text.asm
@@ -129,12 +129,10 @@
 ; Fill text box width c height b at hl with pal 7
 	ld de, AttrMap - TileMap
 	add hl, de
-rept 2
 	inc b
-endr
-rept 2
+	inc b
 	inc c
-endr
+	inc c
 	ld a, TEXTBOX_PAL
 .col
 	push bc
@@ -640,12 +638,10 @@
 	dec c
 	jr nz, .row
 
-rept 2
 	inc de
-endr
-rept 2
+	inc de
 	inc hl
-endr
+	inc hl
 	pop af
 	dec a
 	jr nz, .col
@@ -738,9 +734,8 @@
 	ld c, a
 	ld b, 0
 	ld hl, TextCommands
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld e, [hl]
 	inc hl
 	ld d, [hl]
@@ -1014,9 +1009,8 @@
 	jr z, .done
 	cp b
 	jr z, .play
-rept 2
 	inc hl
-endr
+	inc hl
 	jr .loop
 
 .play
@@ -1113,9 +1107,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, StringBufferPointers
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, BANK(StringBufferPointers)
 	call GetFarHalfword
 	ld d, h
@@ -1136,9 +1129,8 @@
 	ld c, a
 	ld b, 0
 	ld hl, .Days
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/home/vblank.asm
+++ b/home/vblank.asm
@@ -19,9 +19,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .VBlanks
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/items/item_descriptions.asm
+++ b/items/item_descriptions.asm
@@ -21,9 +21,8 @@
 	dec a
 	ld c, a
 	ld b, 0
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld e, [hl]
 	inc hl
 	ld d, [hl]
--- a/items/item_effects.asm
+++ b/items/item_effects.asm
@@ -253,9 +253,8 @@
 	jr z, .skip_or_return_from_ball_fn
 	cp c
 	jr z, .call_ball_function
-rept 2
 	inc hl
-endr
+	inc hl
 	jr .get_multiplier_loop
 
 .call_ball_function
@@ -288,9 +287,8 @@
 
 	ld h, d
 	ld l, e
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld d, h
 	ld e, l
 	ld a, d
@@ -805,9 +803,8 @@
 	dec a
 	ld e, a
 	ld d, 0
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, BANK(PokedexDataPointerTable)
 	call GetFarHalfword
 
@@ -820,9 +817,8 @@
 
 	call GetPokedexEntryBank
 	push bc
-rept 2
 	inc hl
-endr
+	inc hl
 	call GetFarHalfword
 
 	srl h
@@ -868,9 +864,8 @@
 	ld a, c
 	cp [hl]
 	jr c, .heavymon
-rept 2
 	inc hl
-endr
+	inc hl
 	jr .lookup
 
 .heavymon
@@ -929,9 +924,8 @@
 	ld c, a
 	ld b, 0
 	ld hl, EvosAttacksPointers
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, BANK(EvosAttacksPointers)
 	call GetFarHalfword
 	pop bc
@@ -2127,9 +2121,8 @@
 	jr z, .NotFound
 	cp d
 	jr z, .done
-rept 2
 	inc hl
-endr
+	inc hl
 	jr .next
 
 .NotFound:
@@ -2335,9 +2328,8 @@
 .loop
 	cp [hl]
 	jr z, .got_it
-rept 2
 	inc hl
-endr
+	inc hl
 	jr .loop
 
 .got_it
--- a/lib/mobile/main.asm
+++ b/lib/mobile/main.asm
@@ -681,9 +681,8 @@
 	ld hl, Unknown_112037
 	ld de, $cb74
 	call Function110000
-rept 2
 	inc de
-endr
+	inc de
 	pop hl
 	ld bc, 0
 	call Function110007
@@ -1127,9 +1126,8 @@
 	ld hl, Unknown_112072
 	ld b, $5
 	call Function110000
-rept 2
 	inc de
-endr
+	inc de
 	ld bc, $0001
 	ld hl, Unknown_11209e
 	call Function110007
@@ -1395,9 +1393,8 @@
 	ld hl, Unknown_112072
 	ld b, $5
 	call Function110000
-rept 2
 	inc de
-endr
+	inc de
 	ld hl, Unknown_1120c8
 	call Function110007
 	pop hl
@@ -1561,12 +1558,10 @@
 	ld [hli], a
 	ld a, d
 	ld [hli], a
-rept 2
 	inc de
-endr
-rept 2
+	inc de
 	dec bc
-endr
+	dec bc
 	ld hl, $c98f
 	ld a, e
 	ld [hli], a
@@ -1586,9 +1581,8 @@
 	xor a
 	ld [hli], a
 	xor a
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	xor a
 	ld [$c86b], a
 	ld de, $cb47
@@ -1628,9 +1622,8 @@
 	ld [hli], a
 	ld a, d
 	ld [hli], a
-rept 2
 	inc de
-endr
+	inc de
 	ld a, e
 	ld [hli], a
 	ld a, d
@@ -1641,9 +1634,8 @@
 	ld [$c86e], a
 	ld [$c86f], a
 	jr z, .asm_110b5c
-rept 2
 	dec bc
-endr
+	dec bc
 	ld a, [$c993]
 	or a
 	jp nz, .asm_110bd5
@@ -1909,12 +1901,10 @@
 	ld [hli], a
 	ld a, d
 	ld [hli], a
-rept 2
 	inc de
-endr
-rept 2
+	inc de
 	dec bc
-endr
+	dec bc
 	ld hl, $c98f
 	ld a, e
 	ld [hli], a
@@ -1934,9 +1924,8 @@
 	xor a
 	ld [hli], a
 	xor a
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	xor a
 	ld [$c86b], a
 	ld de, $cb47
@@ -2151,16 +2140,14 @@
 	ld [$c833], a
 	ld a, [hli]
 	ld [$c834], a
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, l
 	ld [$c97f], a
 	ld a, h
 	ld [$c980], a
-rept 2
 	dec hl
-endr
+	dec hl
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -2302,9 +2289,8 @@
 	ld [hli], a
 	ld a, d
 	ld [hli], a
-rept 2
 	inc hl
-endr
+	inc hl
 	xor a
 	ld [$c994], a
 
@@ -2350,9 +2336,8 @@
 	ld hl, $c866
 	ld b, $4
 	call Function110000
-rept 2
 	inc de
-endr
+	inc de
 	ld b, $6
 	call Function111f63
 	ld a, [$cabc]
@@ -2424,9 +2409,8 @@
 	ld [hli], a
 	ld a, d
 	ld [hli], a
-rept 2
 	inc de
-endr
+	inc de
 	ld a, e
 	ld [hli], a
 	ld a, d
@@ -2436,9 +2420,8 @@
 	or c
 	ld [$c86e], a
 	ld [$c86f], a
-rept 2
 	dec bc
-endr
+	dec bc
 	jp z, Function1111ca
 	ld a, [$c991]
 	or a
@@ -2741,16 +2724,14 @@
 	ld [$c833], a
 	ld a, [hli]
 	ld [$c834], a
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, l
 	ld [$c97f], a
 	ld a, h
 	ld [$c980], a
-rept 2
 	dec hl
-endr
+	dec hl
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -2828,9 +2809,8 @@
 	ld a, [hld]
 	cp $2f
 	jr nz, .asm_1112a4
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [hl]
 	cp $30
 	jr c, .asm_1112cc
@@ -2884,9 +2864,8 @@
 	ld [hli], a
 	ld a, d
 	ld [hli], a
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, e
 	ld [hli], a
 	ld a, d
@@ -2904,9 +2883,8 @@
 	ld [$c9ac], a
 	ld a, [hli]
 	ld [$c9ad], a
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [hli]
 	ld [$c876], a
 	ld a, [hl]
@@ -2922,9 +2900,8 @@
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -3114,9 +3091,8 @@
 	cp $81
 	jr nc, .asm_111485
 	ld c, a
-rept 2
 	inc a
-endr
+	inc a
 	ld [de], a
 	inc de
 	ld a, $ff
@@ -3128,9 +3104,8 @@
 	ld b, c
 	call Function110000
 	ld b, c
-rept 2
 	inc b
-endr
+	inc b
 	call Function111f63
 	ld hl, $c822
 	set 7, [hl]
@@ -3457,9 +3432,8 @@
 	ld a, b
 	srl a
 	srl a
-rept 2
 	add b
-endr
+	add b
 	ld [hl], a
 	ret
 
@@ -4126,9 +4100,8 @@
 	ld [$c800], a
 	xor a
 	ld hl, $c80a
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	ld [hl], a
 	ld hl, $c815
 	ld a, [$c820]
@@ -4331,9 +4304,8 @@
 .asm_111c52
 	ld b, a
 	ld a, [$ca3f]
-rept 2
 	dec a
-endr
+	dec a
 	cp b
 	jr c, .asm_111c6e
 .asm_111c5b
@@ -5604,9 +5576,8 @@
 	xor a
 	ld [hli], a
 	xor a
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	pop de
 	ld a, $1
 	ld [$c994], a
@@ -5731,24 +5702,21 @@
 	ld [hli], a
 	ld a, d
 	ld [hli], a
-rept 2
 	inc de
-endr
+	inc de
 	ld a, $80
 	ld [hli], a
 	ld a, $c8
 	ld [hli], a
-rept 2
 	dec bc
-endr
+	dec bc
 	ld a, $fa
 	ld [hli], a
 	ld a, $0
 	ld [hli], a
 	xor a
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	ld de, $cb47
 	ld hl, Unknown_112072
 	ld b, $6
@@ -6236,9 +6204,8 @@
 	ld de, $cb4c
 	ld a, $1
 	ld [de], a
-rept 2
 	inc de
-endr
+	inc de
 	ld b, $1
 	call Function111f63
 	jr .asm_112941
@@ -6471,9 +6438,8 @@
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, e
 	ld [hli], a
 	ld a, d
@@ -6970,9 +6936,8 @@
 	ld hl, $c821
 	res 2, [hl]
 	ld hl, $c86b
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 
 .asm_112d82
 	ld hl, $c86b
@@ -7131,9 +7096,8 @@
 	cp $1
 	ld a, $32
 	jr z, .asm_112e95
-rept 2
 	inc de
-endr
+	inc de
 	inc a
 
 .asm_112e95
@@ -7512,9 +7476,8 @@
 .asm_1130d6
 	ld a, [$c82b]
 	ld c, a
-rept 2
 	dec b
-endr
+	dec b
 	ld a, b
 	ld [$c82d], a
 	jr z, .asm_11310d
@@ -7522,9 +7485,8 @@
 	ld d, a
 	ld a, [$c872]
 	ld e, a
-rept 2
 	dec de
-endr
+	dec de
 	xor a
 	or d
 	jr nz, .asm_1130f5
@@ -7543,9 +7505,8 @@
 	ld e, a
 	ld a, [$c875]
 	ld d, a
-rept 2
 	inc de
-endr
+	inc de
 	call Function110000
 
 .asm_11310d
@@ -7658,9 +7619,8 @@
 	ld a, b
 	ld [de], a
 	inc de
-rept 2
 	dec b
-endr
+	dec b
 	call Function110000
 	xor a
 	ld [de], a
@@ -7682,9 +7642,8 @@
 	inc b
 	cp $a
 	jr nz, .asm_1131b7
-rept 2
 	inc hl
-endr
+	inc hl
 	dec b
 	ld c, b
 	call Function110000
@@ -7728,9 +7687,8 @@
 	ld hl, $c821
 	res 2, [hl]
 	ld hl, $c86b
-rept 2
 	dec [hl]
-endr
+	dec [hl]
 	ld a, $4
 	ret
 ; 113206
@@ -7753,9 +7711,8 @@
 	ld e, a
 	ld a, [$c875]
 	ld d, a
-rept 2
 	inc de
-endr
+	inc de
 	call Function110000
 	ld a, [$c991]
 	ld [$c993], a
@@ -8026,9 +7983,8 @@
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -8039,9 +7995,8 @@
 	ld a, [hld]
 	cp $2f
 	jr nz, .asm_11344c
-rept 2
 	inc hl
-endr
+	inc hl
 	ld e, l
 	ld d, h
 .asm_113455
@@ -8059,9 +8014,8 @@
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -8158,9 +8112,8 @@
 	ret
 
 .asm_1134f0
-rept 2
 	inc [hl]
-endr
+	inc [hl]
 	jr .asm_1134fc
 
 .asm_1134f4
@@ -9223,9 +9176,8 @@
 	ld a, $3f
 	and c
 	ld [hld], a
-rept 2
 	dec hl
-endr
+	dec hl
 	pop de
 	ld b, h
 	ld c, l
@@ -9572,9 +9524,8 @@
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [hld]
 	dec hl
 	xor $80
@@ -9615,9 +9566,8 @@
 	ld l, a
 	ld e, l
 	ld d, h
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld e, l
 	ld d, h
 	ld hl, $c815
@@ -9677,9 +9627,8 @@
 	ld l, a
 	ld e, l
 	ld d, h
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld e, l
 	ld d, h
 	ld hl, $c815
--- a/main.asm
+++ b/main.asm
@@ -1174,170 +1174,8 @@
 	ret
 
 INCLUDE "engine/wildmons.asm"
+INCLUDE "battle/link_result.asm"
 
-DetermineLinkBattleResult: ; 2b930
-	callba UpdateEnemyMonInParty
-	ld hl, PartyMon1HP
-	call .CountMonsRemaining
-	push bc
-	ld hl, OTPartyMon1HP
-	call .CountMonsRemaining
-	ld a, c
-	pop bc
-	cp c
-	jr z, .even_number_of_mons_remaining
-	jr c, .defeat
-	jr .victory
-
-.even_number_of_mons_remaining
-	call .BothSides_CheckNumberMonsAtFullHealth
-	jr z, .drawn
-	ld a, e
-	cp $1
-	jr z, .victory
-	cp $2
-	jr z, .defeat
-	ld hl, PartyMon1HP
-	call .CalcPercentHPRemaining
-	push de
-	ld hl, OTPartyMon1HP
-	call .CalcPercentHPRemaining
-	pop hl
-	ld a, d
-	cp h
-	jr c, .victory
-	jr z, .compare_lo
-	jr .defeat
-
-.compare_lo
-	ld a, e
-	cp l
-	jr z, .drawn
-	jr nc, .defeat
-
-.victory
-	ld a, [wBattleResult]
-	and $f0
-	ld [wBattleResult], a
-	ret
-
-.defeat
-	ld a, [wBattleResult]
-	and $f0
-	add $1
-	ld [wBattleResult], a
-	ret
-
-.drawn
-	ld a, [wBattleResult]
-	and $f0
-	add $2
-	ld [wBattleResult], a
-	ret
-
-.CountMonsRemaining: ; 2b995
-	ld c, 0
-	ld b, 3
-	ld de, PARTYMON_STRUCT_LENGTH - 1
-.loop
-	ld a, [hli]
-	or [hl]
-	jr nz, .not_fainted
-	inc c
-
-.not_fainted
-	add hl, de
-	dec b
-	jr nz, .loop
-	ret
-
-.CalcPercentHPRemaining: ; 2b9a6
-	ld de, 0
-	ld c, $3
-.loop2
-	ld a, [hli]
-	or [hl]
-	jr z, .next
-	dec hl
-	xor a
-	ld [hDividend + 0], a
-	ld a, [hli]
-	ld [hDividend + 1], a
-	ld a, [hli]
-	ld [hDividend + 2], a
-	xor a
-	ld [hDividend + 3], a
-	ld a, [hli]
-	ld b, a
-	ld a, [hld]
-	srl b
-	rr a
-	srl b
-	rr a
-	ld [hDivisor], a
-	ld b, $4
-	call Divide
-	ld a, [hQuotient + 2]
-	add e
-	ld e, a
-	ld a, [hQuotient + 1]
-	adc d
-	ld d, a
-	dec hl
-
-.next
-	push de
-	ld de, $2f
-	add hl, de
-	pop de
-	dec c
-	jr nz, .loop2
-	ret
-
-.BothSides_CheckNumberMonsAtFullHealth: ; 2b9e1
-	ld hl, PartyMon1HP
-	call .CheckFaintedOrFullHealth
-	jr nz, .finish ; we have a pokemon that's neither fainted nor at full health
-	ld hl, OTPartyMon1HP
-	call .CheckFaintedOrFullHealth
-	ld e, $1
-	ret
-
-.finish
-	ld hl, OTPartyMon1HP
-	call .CheckFaintedOrFullHealth
-	ld e, $0
-	ret nz ; we both have pokemon that are neither fainted nor at full health
-	ld e, $2
-	ld a, $1
-	and a
-	ret
-
-.CheckFaintedOrFullHealth: ; 2ba01
-	ld d, 3
-.loop3
-	ld a, [hli]
-	ld b, a
-	ld a, [hli]
-	ld c, a
-	or b
-	jr z, .fainted_or_full_health
-	ld a, [hli]
-	cp b
-	ret nz
-	ld a, [hld]
-	cp c
-	ret nz
-
-.fainted_or_full_health
-	push de
-	ld de, PARTYMON_STRUCT_LENGTH - 2
-	add hl, de
-	pop de
-	dec d
-	jr nz, .loop3
-	ret
-
 ChrisBackpic: ; 2ba1a
 INCBIN "gfx/misc/player.6x6.2bpp.lz"
 
@@ -2103,78 +1941,6 @@
 String_44331: ; 44331
 	db "#@"
 
-GetDexEntryPointer: ; 44333
-; return dex entry pointer b:de
-	push hl
-	ld hl, PokedexDataPointerTable
-	ld a, b
-	dec a
-	ld d, 0
-	ld e, a
-	add hl, de
-	add hl, de
-	ld e, [hl]
-	inc hl
-	ld d, [hl]
-	push de
-	rlca
-	rlca
-	and $3
-	ld hl, .PokedexEntryBanks
-	ld d, 0
-	ld e, a
-	add hl, de
-	ld b, [hl]
-	pop de
-	pop hl
-	ret
-
-.PokedexEntryBanks: ; 44351
-
-GLOBAL PokedexEntries1
-GLOBAL PokedexEntries2
-GLOBAL PokedexEntries3
-GLOBAL PokedexEntries4
-
-	db BANK(PokedexEntries1)
-	db BANK(PokedexEntries2)
-	db BANK(PokedexEntries3)
-	db BANK(PokedexEntries4)
-
-GetDexEntryPagePointer: ; 44355
-	call GetDexEntryPointer ; b:de
-	push hl
-	ld h, d
-	ld l, e
-; skip species name
-.loop1
-	ld a, b
-	call GetFarByte
-	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
-	inc hl
-	cp "@"
-	jr nz, .loop2
-
-.done
-	ld d, h
-	ld e, l
-	pop hl
-	ret
-
-PokedexDataPointerTable: ; 0x44378
 INCLUDE "data/pokedex/entry_pointers.asm"
 
 INCLUDE "engine/mail.asm"
@@ -2505,7 +2271,7 @@
 	and a
 	jp z, WaitBGMap
 
-; The following is a modified version of Function3246.
+; The following is a modified version of LoadEDTile.
 	ld a, [hBGMapMode]
 	push af
 	xor a
@@ -2646,7 +2412,7 @@
 	cp $0
 	jp z, WaitBGMap
 
-; What follows is a modified version of Function3246 (LoadEDTile).
+; What follows is a modified version of LoadEDTile.
 	ld a, [hBGMapMode]
 	push af
 	xor a
@@ -2817,305 +2583,8 @@
 	jr nz, .row_loop
 	ret
 
-_ResetClock: ; 4d3b1
-	callba BlankScreen
-	ld b, SCGB_08
-	call GetSGBLayout
-	call LoadStandardFont
-	call LoadFontsExtra
-	ld de, MUSIC_MAIN_MENU
-	call PlayMusic
-	ld hl, .text_askreset
-	call PrintText
-	ld hl, .NoYes_MenuDataHeader
-	call CopyMenuDataHeader
-	call VerticalMenu
-	ret c
-	ld a, [wMenuCursorY]
-	cp $1
-	ret z
-	call ClockResetPassword
-	jr c, .wrongpassword
-	ld a, BANK(sRTCStatusFlags)
-	call GetSRAMBank
-	ld a, $80
-	ld [sRTCStatusFlags], a
-	call CloseSRAM
-	ld hl, .text_okay
-	call PrintText
-	ret
+INCLUDE "engine/delete_save_change_clock.asm"
 
-.wrongpassword
-	ld hl, .text_wrong
-	call PrintText
-	ret
-
-.text_okay ; 0x4d3fe
-	; Password OK. Select CONTINUE & reset settings.
-	text_jump UnknownText_0x1c55db
-	db "@"
-
-.text_wrong ; 0x4d403
-	; Wrong password!
-	text_jump UnknownText_0x1c560b
-	db "@"
-
-.text_askreset ; 0x4d408
-	; Reset the clock?
-	text_jump UnknownText_0x1c561c
-	db "@"
-
-.NoYes_MenuDataHeader: ; 0x4d40d
-	db $00 ; flags
-	db 07, 14 ; start coords
-	db 11, 19 ; end coords
-	dw .NoYes_MenuData2
-	db 1 ; default option
-
-.NoYes_MenuData2: ; 0x4d415
-	db $c0 ; flags
-	db 2 ; items
-	db "NO@"
-	db "YES@"
-
-ClockResetPassword: ; 4d41e
-	call .CalculatePassword
-	push de
-	ld hl, StringBuffer2
-	ld bc, 5
-	xor a
-	call ByteFill
-	ld a, $4
-	ld [StringBuffer2 + 5], a
-	ld hl, .pleaseenterpasswordtext
-	call PrintText
-.loop
-	call .updateIDdisplay
-.loop2
-	call JoyTextDelay
-	ld a, [hJoyLast]
-	ld b, a
-	and A_BUTTON
-	jr nz, .confirm
-	ld a, b
-	and D_PAD
-	jr z, .loop2
-	call .dpadinput
-	ld c, 3
-	call DelayFrames
-	jr .loop
-
-.confirm
-	call .ConvertDecIDToBytes
-	pop de
-	ld a, e
-	cp l
-	jr nz, .nope
-	ld a, d
-	cp h
-	jr nz, .nope
-	and a
-	ret
-
-.nope
-	scf
-	ret
-
-.pleaseenterpasswordtext ; 0x4d463
-	; Please enter the password.
-	text_jump UnknownText_0x1c562e
-	db "@"
-
-.updateIDdisplay ; 4d468
-	hlcoord 14, 15
-	ld de, StringBuffer2
-	ld c, 5
-.loop3
-	ld a, [de]
-	add "0"
-	ld [hli], a
-	inc de
-	dec c
-	jr nz, .loop3
-	hlcoord 14, 16
-	ld bc, 5
-	ld a, " "
-	call ByteFill
-	hlcoord 14, 16
-	ld a, [StringBuffer2 + 5]
-	ld e, a
-	ld d, $0
-	add hl, de
-	ld [hl], $61
-	ret
-
-.dpadinput ; 4d490
-	ld a, b
-	and D_LEFT
-	jr nz, .left
-	ld a, b
-	and D_RIGHT
-	jr nz, .right
-	ld a, b
-	and D_UP
-	jr nz, .up
-	ld a, b
-	and D_DOWN
-	jr nz, .down
-	ret
-
-.left
-	ld a, [StringBuffer2 + 5]
-	and a
-	ret z
-	dec a
-	ld [StringBuffer2 + 5], a
-	ret
-
-.right
-	ld a, [StringBuffer2 + 5]
-	cp $4
-	ret z
-	inc a
-	ld [StringBuffer2 + 5], a
-	ret
-
-.up
-	call .getcurrentdigit
-	ld a, [hl]
-	cp 9
-	jr z, .wraparound_up
-	inc a
-	ld [hl], a
-	ret
-
-.wraparound_up
-	ld [hl], $0
-	ret
-
-.down
-	call .getcurrentdigit
-	ld a, [hl]
-	and a
-	jr z, .wraparound_down
-	dec a
-	ld [hl], a
-	ret
-
-.wraparound_down
-	ld [hl], 9
-	ret
-
-.getcurrentdigit ; 4d4d5
-	ld a, [StringBuffer2 + 5]
-	ld e, a
-	ld d, $0
-	ld hl, StringBuffer2
-	add hl, de
-	ret
-
-.ConvertDecIDToBytes: ; 4d4e0
-	ld hl, 0
-	ld de, StringBuffer2 + 4
-	ld bc, 1
-	call .ConvertToBytes
-	ld bc, 10
-	call .ConvertToBytes
-	ld bc, 100
-	call .ConvertToBytes
-	ld bc, 1000
-	call .ConvertToBytes
-	ld bc, 10000
-.ConvertToBytes: ; 4d501
-	ld a, [de]
-	dec de
-	push hl
-	ld hl, 0
-	call AddNTimes
-	ld c, l
-	ld b, h
-	pop hl
-	add hl, bc
-	ret
-
-.CalculatePassword: ; 4d50f
-	ld a, BANK(sPlayerData)
-	call GetSRAMBank
-	ld de, 0
-	ld hl, sPlayerData + (PlayerID - wPlayerData)
-	ld c, $2
-	call .ComponentFromNumber
-	ld hl, sPlayerData + (PlayerName - wPlayerData)
-	ld c, $5 ; PLAYER_NAME_LENGTH_J
-	call .ComponentFromString
-	ld hl, sPlayerData + (Money - wPlayerData)
-	ld c, $3
-	call .ComponentFromNumber
-	call CloseSRAM
-	ret
-
-.ComponentFromNumber: ; 4d533
-	ld a, [hli]
-	add e
-	ld e, a
-	ld a, $0
-	adc d
-	ld d, a
-	dec c
-	jr nz, .ComponentFromNumber
-	ret
-
-.ComponentFromString: ; 4d53e
-	ld a, [hli]
-	cp "@"
-	ret z
-	add e
-	ld e, a
-	ld a, $0
-	adc d
-	ld d, a
-	dec c
-	jr nz, .ComponentFromString
-	ret
-
-_DeleteSaveData: ; 4d54c
-	callba BlankScreen
-	ld b, SCGB_08
-	call GetSGBLayout
-	call LoadStandardFont
-	call LoadFontsExtra
-	ld de, MUSIC_MAIN_MENU
-	call PlayMusic
-	ld hl, .Text_ClearAllSaveData
-	call PrintText
-	ld hl, .NoYesMenuDataHeader
-	call CopyMenuDataHeader
-	call VerticalMenu
-	ret c
-	ld a, [wMenuCursorY]
-	cp $1
-	ret z
-	callba EmptyAllSRAMBanks
-	ret
-
-.Text_ClearAllSaveData: ; 0x4d580
-	; Clear all save data?
-	text_jump UnknownText_0x1c564a
-	db "@"
-
-.NoYesMenuDataHeader: ; 0x4d585
-	db $00 ; flags
-	db 07, 14 ; start coords
-	db 11, 19 ; end coords
-	dw .MenuData2
-	db 1 ; default option
-
-.MenuData2: ; 0x4d58d
-	db $c0 ; flags
-	db 2 ; items
-	db "NO@"
-	db "YES@"
-
 Tilesets::
 INCLUDE "tilesets/tileset_headers.asm"
 
@@ -3587,7 +3056,7 @@
 	ld de, wBufferMonOT
 	ld bc, NAME_LENGTH
 	call CopyBytes
-	callab Function51322
+	callab InsertPokemonIntoBox
 	ld a, [CurPartySpecies]
 	ld [wd265], a
 	call GetPokemonName
@@ -3730,141 +3199,7 @@
 	ld [CurPartyLevel], a
 	ret
 
-_FindGreaterThanThatLevel: ; 4dbd2
-	ld hl, PartyMon1Level
-	call FindGreaterThanThatLevel
-	ret
-
-_FindAtLeastThatHappy: ; 4dbd9
-	ld hl, PartyMon1Happiness
-	call FindAtLeastThatHappy
-	ret
-
-_FindThatSpecies: ; 4dbe0
-	ld hl, PartyMon1Species
-	jp FindThatSpecies
-
-_FindThatSpeciesYourTrainerID: ; 4dbe6
-	ld hl, PartyMon1Species
-	call FindThatSpecies
-	ret z
-	ld a, c
-	ld hl, PartyMon1ID
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call AddNTimes
-	ld a, [PlayerID]
-	cp [hl]
-	jr nz, .nope
-	inc hl
-	ld a, [PlayerID + 1]
-	cp [hl]
-	jr nz, .nope
-	ld a, $1
-	and a
-	ret
-
-.nope
-	xor a
-	ret
-
-FindAtLeastThatHappy: ; 4dc0a
-; Sets the bits for the Pokemon that have a happiness greater than or equal to b.
-; The lowest bits are used.  Sets z if no Pokemon in your party is at least that happy.
-	ld c, $0
-	ld a, [PartyCount]
-	ld d, a
-.loop
-	ld a, d
-	dec a
-	push hl
-	push bc
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call AddNTimes
-	pop bc
-	ld a, b
-	cp [hl]
-	pop hl
-	jr z, .greater_equal
-	jr nc, .lower
-
-.greater_equal
-	ld a, c
-	or $1
-	ld c, a
-
-.lower
-	sla c
-	dec d
-	jr nz, .loop
-	call RetroactivelyIgnoreEggs
-	ld a, c
-	and a
-	ret
-
-FindGreaterThanThatLevel: ; 4dc31
-	ld c, $0
-	ld a, [PartyCount]
-	ld d, a
-.loop
-	ld a, d
-	dec a
-	push hl
-	push bc
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call AddNTimes
-	pop bc
-	ld a, b
-	cp [hl]
-	pop hl
-	jr c, .greater
-	ld a, c
-	or $1
-	ld c, a
-
-.greater
-	sla c
-	dec d
-	jr nz, .loop
-	call RetroactivelyIgnoreEggs
-	ld a, c
-	and a
-	ret
-
-FindThatSpecies: ; 4dc56
-; Find species b in your party.
-; If you have no Pokemon, returns c = -1 and z.
-; If that species is in your party, returns its location in c, and nz.
-; Otherwise, returns z.
-	ld c, -1
-	ld hl, PartySpecies
-.loop
-	ld a, [hli]
-	cp -1
-	ret z
-	inc c
-	cp b
-	jr nz, .loop
-	ld a, $1
-	and a
-	ret
-
-RetroactivelyIgnoreEggs: ; 4dc67
-	ld e, -2
-	ld hl, PartySpecies
-.loop
-	ld a, [hli]
-	cp -1
-	ret z
-	cp EGG
-	jr nz, .skip_notegg
-	ld a, c
-	and e
-	ld c, a
-
-.skip_notegg
-	rlc e
-	jr .loop
-
+INCLUDE "engine/search2.asm"
 INCLUDE "engine/stats_screen.asm"
 
 CatchTutorial:: ; 4e554
@@ -5303,141 +4638,7 @@
 	ret
 
 INCLUDE "gfx/load_pics.asm"
-
-Function51322: ; 51322
-	ld a, BANK(sBoxCount)
-	call GetSRAMBank
-	ld hl, sBoxCount
-	call Function513cb
-	ld a, [sBoxCount]
-	dec a
-	ld [wd265], a
-	ld hl, sBoxMonNicknames
-	ld bc, PKMN_NAME_LENGTH
-	ld de, wBufferMonNick
-	call Function513e0
-	ld a, [sBoxCount]
-	dec a
-	ld [wd265], a
-	ld hl, sBoxMonOT
-	ld bc, NAME_LENGTH
-	ld de, wBufferMonOT
-	call Function513e0
-	ld a, [sBoxCount]
-	dec a
-	ld [wd265], a
-	ld hl, sBoxMons
-	ld bc, BOXMON_STRUCT_LENGTH
-	ld de, wBufferMon
-	call Function513e0
-	ld hl, wBufferMonMoves
-	ld de, TempMonMoves
-	ld bc, NUM_MOVES
-	call CopyBytes
-	ld hl, wBufferMonPP
-	ld de, TempMonPP
-	ld bc, NUM_MOVES
-	call CopyBytes
-	ld a, [CurPartyMon]
-	ld b, a
-	callba Functiondcb6
-	jp CloseSRAM
-
-Function5138b: ; 5138b
-	ld hl, PartyCount
-	call Function513cb
-	ld a, [PartyCount]
-	dec a
-	ld [wd265], a
-	ld hl, PartyMonNicknames
-	ld bc, PKMN_NAME_LENGTH
-	ld de, wBufferMonNick
-	call Function513e0
-	ld a, [PartyCount]
-	dec a
-	ld [wd265], a
-	ld hl, PartyMonOT
-	ld bc, NAME_LENGTH
-	ld de, wBufferMonOT
-	call Function513e0
-	ld a, [PartyCount]
-	dec a
-	ld [wd265], a
-	ld hl, PartyMons
-	ld bc, PARTYMON_STRUCT_LENGTH
-	ld de, wBufferMon
-	call Function513e0
-	ret
-
-Function513cb: ; 513cb
-	inc [hl]
-	inc hl
-	ld a, [CurPartyMon]
-	ld c, a
-	ld b, 0
-	add hl, bc
-	ld a, [CurPartySpecies]
-	ld c, a
-.asm_513d8
-	ld a, [hl]
-	ld [hl], c
-	inc hl
-	inc c
-	ld c, a
-	jr nz, .asm_513d8
-	ret
-
-Function513e0: ; 513e0
-	push de
-	push hl
-	push bc
-	ld a, [wd265]
-	dec a
-	call AddNTimes
-	push hl
-	add hl, bc
-	ld d, h
-	ld e, l
-	pop hl
-.asm_513ef
-	push bc
-	ld a, [wd265]
-	ld b, a
-	ld a, [CurPartyMon]
-	cp b
-	pop bc
-	jr z, .asm_51415
-	push hl
-	push de
-	push bc
-	call CopyBytes
-	pop bc
-	pop de
-	pop hl
-	push hl
-	ld a, l
-	sub c
-	ld l, a
-	ld a, h
-	sbc b
-	ld h, a
-	pop de
-	ld a, [wd265]
-	dec a
-	ld [wd265], a
-	jr .asm_513ef
-
-.asm_51415
-	pop bc
-	pop hl
-	ld a, [CurPartyMon]
-	call AddNTimes
-	ld d, h
-	ld e, l
-	pop hl
-	call CopyBytes
-	ret
-
+INCLUDE "engine/move_mon_wo_mail.asm"
 BaseData::
 INCLUDE "data/base_stats.asm"
 
@@ -5895,7 +5096,7 @@
 	ld a, [hCGB]
 	and a
 	ret nz
-	ret
+	ret ; ????
 
 .LoadPals: ; cbce5
 	ld a, [hCGB]
@@ -5904,9 +5105,9 @@
 	ld a, [TimeOfDayPal]
 	and $3
 	cp $3
-	ld a, $0
+	ld a, %00000000
 	jr z, .convert_pals
-	ld a, $aa
+	ld a, %10101010
 
 .convert_pals
 	call DmgToCgbBGPals
--- a/misc/battle_tower_47.asm
+++ b/misc/battle_tower_47.asm
@@ -61,9 +61,8 @@
 
 .okay2
 	push af
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld c, a
 	ld a, [hl]
@@ -72,9 +71,8 @@
 	pop af
 	ld c, a
 	ld b, 0
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld c, a
 	ld a, [hl]
--- a/misc/battle_tower_5c.asm
+++ b/misc/battle_tower_5c.asm
@@ -217,9 +217,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .dw
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -459,9 +458,8 @@
 	ld a, POUND
 	ld [hli], a
 	xor a
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	ld [hl], a
 	jr .done_moves
 
@@ -489,9 +487,8 @@
 	predef CalcPkmnStats
 	pop de
 	pop hl
-rept 2
 	dec de
-endr
+	dec de
 	ld a, [hli]
 	ld [de], a
 	inc de
@@ -690,9 +687,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .dw
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -908,9 +904,8 @@
 	ld [hli], a
 	dec c
 	jr nz, .clearbox_column
-rept 2
 	inc hl
-endr
+	inc hl
 	dec b
 	jr nz, .clearbox_row
 	ret
@@ -947,9 +942,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .dw
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -1393,9 +1387,8 @@
 	dec hl
 endr
 	ld a, "@"
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	pop hl
 	ld a, EGG_TICKET
 	ld [CurItem], a
@@ -1445,9 +1438,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, Jumptable_1709e7
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/misc/crystal_misc.asm
+++ b/misc/crystal_misc.asm
@@ -682,15 +682,13 @@
 Function17aac3: ; 17aac3 (5e:6ac3)
 	ld a, $b
 	push hl
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	pop hl
 	ld de, SCREEN_WIDTH
 	add hl, de
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	ret
 
 Function17aad0: ; 17aad0 (5e:6ad0)
--- a/misc/mobile_12_2.asm
+++ b/misc/mobile_12_2.asm
@@ -616,9 +616,8 @@
 	ld a, [wMenuCursorY]
 	ld [wMenuCursorY], a
 	ld a, [PartyCount]
-rept 2
 	inc a
-endr
+	inc a
 	ld b, a
 	ld a, [wMenuCursorY]
 	cp b
--- a/misc/mobile_22.asm
+++ b/misc/mobile_22.asm
@@ -669,9 +669,8 @@
 	ld c, d
 	ld b, 0
 	ld hl, .PalettePointers
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -787,9 +786,8 @@
 	ld a, [TrainerClass]
 	ld h, 0
 	ld l, a
-rept 2
 	add hl, hl
-endr
+	add hl, hl
 	ld de, TrainerPalettes
 	add hl, de
 	ld a, [rSVBK]
@@ -1043,9 +1041,8 @@
 Function896f5: ; 896f5
 	call Function8971f
 	call Function89736
-rept 2
 	inc hl
-endr
+	inc hl
 	ld b, 2
 
 ClearScreenArea: ; 0x896ff
@@ -1071,9 +1068,8 @@
 	jr nz, .loop
 
 	dec hl
-rept 2
 	inc c
-endr
+	inc c
 .asm_89713
 	ld a, $36
 	ld [hli], a
@@ -1107,9 +1103,8 @@
 
 Function89736: ; 89736
 	push hl
-rept 2
 	inc hl
-endr
+	inc hl
 	ld e, c
 	ld d, $0
 	add hl, de
@@ -1145,9 +1140,8 @@
 	ld [hli], a
 	ld a, $d
 	ld [hl], a
-rept 2
 	dec hl
-endr
+	dec hl
 	ld a, $4
 	ld e, $3
 .asm_89769
@@ -1912,9 +1906,8 @@
 	and a
 	jr z, .asm_89bae
 .asm_89ba9
-rept 2
 	inc hl
-endr
+	inc hl
 	dec a
 	jr nz, .asm_89ba9
 .asm_89bae
@@ -2523,9 +2516,8 @@
 	ld [hli], a
 	ld a, c
 	ld [hli], a
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, $8
 	add c
 	ld c, a
--- a/misc/mobile_22_2.asm
+++ b/misc/mobile_22_2.asm
@@ -314,9 +314,8 @@
 	ld hl, Unknown_8b529
 	call Function8b50a
 	push hl
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [hli]
 	ld b, a
 	ld a, [hl]
@@ -331,9 +330,8 @@
 	ld hl, Unknown_8b529
 	call Function8b50a
 	push hl
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [hli]
 	ld b, a
 	ld a, [hl]
@@ -698,12 +696,10 @@
 Function8b744: ; 8b744
 	ld de, AttrMap - TileMap
 	add hl, de
-rept 2
 	inc b
-endr
-rept 2
+	inc b
 	inc c
-endr
+	inc c
 	xor a
 .asm_8b74d
 	push bc
@@ -975,9 +971,8 @@
 	ld b, 0
 	ld c, a
 	ld hl, Unknown_8b903
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/misc/mobile_41.asm
+++ b/misc/mobile_41.asm
@@ -609,9 +609,8 @@
 rept 3
 	inc de
 endr
-rept 2
 	dec a
-endr
+	dec a
 
 .digit_loop
 	push af
--- a/misc/mobile_42.asm
+++ b/misc/mobile_42.asm
@@ -372,9 +372,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .Jumptable
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -955,9 +954,8 @@
 	ld a, [hSCX]
 	cp $e0
 	jr z, .loop2
-rept 2
 	dec a
-endr
+	dec a
 	ld [hSCX], a
 	cp $f8
 	jr nz, .next
@@ -974,9 +972,8 @@
 	ld a, [hSCY]
 	cp $f8
 	jr z, .done
-rept 2
 	dec a
-endr
+	dec a
 	ld [hSCY], a
 	cp $40
 	jr z, .init
@@ -1125,9 +1122,8 @@
 	ld a, [hSCY]
 	cp $78
 	jr z, .asm_1088ee
-rept 2
 	inc a
-endr
+	inc a
 	ld [hSCY], a
 	cp $30
 	jr z, .asm_1088c5
@@ -1166,9 +1162,8 @@
 	ld a, [hSCX]
 	cp $c
 	jr z, .asm_108906
-rept 2
 	inc a
-endr
+	inc a
 	ld [hSCX], a
 	cp -8
 	jr nz, .asm_1088e7
--- a/misc/mobile_45.asm
+++ b/misc/mobile_45.asm
@@ -153,9 +153,8 @@
 Function11425c: ; 11425c
 	ld [$dc02], a
 	pop af
-rept 2
 	ld [hFF8C], a
-endr
+	ld [hFF8C], a
 	ld [MBC3SRamBank], a
 	ret
 
@@ -632,9 +631,8 @@
 
 Function1144d1: ; 1144d1
 	call Function114561
-rept 2
 	dec de
-endr
+	dec de
 	push de
 rept 3
 	inc de
@@ -1006,9 +1004,8 @@
 	and a
 	jr nz, .asm_1146e8
 .asm_1146da
-rept 2
 	dec bc
-endr
+	dec bc
 	call Function1149cc
 	and a
 	jr nz, .asm_1146e4
@@ -1095,9 +1092,8 @@
 	ld a, [$dc0e]
 	cp $3
 	jr nz, .asm_114773
-rept 2
 	dec bc
-endr
+	dec bc
 
 .asm_114773
 	call Function1149cc
@@ -2069,9 +2065,8 @@
 	inc de
 	cp $3f
 	jr nz, .asm_114c62
-rept 2
 	dec de
-endr
+	dec de
 .asm_114c75
 	ld a, [hli]
 	cp $3f
@@ -2091,9 +2086,8 @@
 	ld a, [hli]
 	cp $3d
 	jr nz, .asm_114c84
-rept 2
 	dec bc
-endr
+	dec bc
 	ld a, l
 	ld [$dc03], a
 	ld a, h
@@ -2360,9 +2354,8 @@
 	add hl, de
 	ld b, h
 	ld c, l
-rept 2
 	inc bc
-endr
+	inc bc
 	xor a
 	ret
 
@@ -2563,9 +2556,8 @@
 	ld a, b
 	ld [hli], a
 	ld a, c
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	ld a, [de]
 	ld [hli], a
 	inc de
@@ -2970,9 +2962,8 @@
 
 .asm_11510b
 	pop hl
-rept 2
 	dec hl
-endr
+	dec hl
 	push de
 	call Function1158c2
 	pop de
@@ -3499,9 +3490,8 @@
 	ld e, [hl]
 	inc hl
 	ld d, [hl]
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [de]
 	ld [hli], a
 	inc de
@@ -4523,9 +4513,8 @@
 	ld a, $3f
 	and c
 	ld [hld], a
-rept 2
 	dec hl
-endr
+	dec hl
 	pop de
 	ld b, h
 	ld c, l
@@ -4581,9 +4570,8 @@
 	ld a, [hli]
 	ld c, a
 	ld b, [hl]
-rept 2
 	inc bc
-endr
+	inc bc
 	ld a, b
 	ld [hld], a
 	ld [hl], c
@@ -4864,9 +4852,8 @@
 	ld a, [wStartDay]
 	cp $4
 	jr z, .asm_115b43
-rept 2
 	inc hl
-endr
+	inc hl
 	jr .asm_115b43
 
 .asm_115b36
@@ -5048,9 +5035,8 @@
 	ret
 
 .asm_115c33
-rept 2
 	dec hl
-endr
+	dec hl
 	xor a
 	ld [hl], a
 	ld a, $1
@@ -5406,9 +5392,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, Jumptable_1165af
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -6941,9 +6926,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, Jumptable_117728
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -7430,9 +7414,8 @@
 	ld e, a
 	ld d, $0
 	ld hl, .Jumptable
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/misc/mobile_45_sprite_engine.asm
+++ b/misc/mobile_45_sprite_engine.asm
@@ -375,9 +375,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, .Jumptable
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/misc/mobile_5b.asm
+++ b/misc/mobile_5b.asm
@@ -356,9 +356,8 @@
 	call Function16cae8
 
 .asm_16c9e1
-rept 2
 	inc e
-endr
+	inc e
 	ld a, e
 	cp $8
 	jr nz, .asm_16c969
@@ -459,9 +458,8 @@
 	call Function16cae8
 
 .asm_16ca88
-rept 2
 	inc e
-endr
+	inc e
 	ld a, e
 	cp $8
 	jr nz, .asm_16ca28
--- a/misc/mobile_5c.asm
+++ b/misc/mobile_5c.asm
@@ -111,9 +111,8 @@
 	inc [hl]
 
 .asm_170c15
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [$a89b]
 	add [hl]
 	ld [hld], a
@@ -138,9 +137,8 @@
 	ld a, [hli]
 	ld b, a
 	ld c, [hl]
-rept 2
 	inc hl
-endr
+	inc hl
 	ld a, [hld]
 	sub c
 	ld c, a
@@ -370,9 +368,8 @@
 	ld e, a
 	ld d, 0
 	ld hl, Jumptable_171a45
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -732,9 +729,8 @@
 Function171cf0: ; 171cf0 (5c:5cf0)
 	xor a
 	hlcoord 4, 15
-rept 2
 	ld [hli], a
-endr
+	ld [hli], a
 	ld a, [wcd4b]
 	xor $1
 	ld [wcd4b], a
--- a/predef/cgb.asm
+++ b/predef/cgb.asm
@@ -58,7 +58,7 @@
 	dw _CGB_PokedexUnownMode
 	dw _CGB17
 	dw _CGB18
-	dw _CGB19
+	dw _CGB_GamefreakLogo ; called before copyright
 	dw _CGB1a
 	dw _CGB1b
 	dw _CGB_FrontpicPals
@@ -1002,7 +1002,7 @@
 	ret
 ; 94fa
 
-_CGB19: ; 94fa
+_CGB_GamefreakLogo: ; 94fa
 	ld de, UnknBGPals
 	ld a, $4e
 	call GetPredefPal
--- a/predef/sgb.asm
+++ b/predef/sgb.asm
@@ -75,9 +75,8 @@
 	ld a, [PlayerHPPal]
 	ld l, a
 	ld h, 0
-rept 2
 	add hl, hl
-endr
+	add hl, hl
 	ld de, Palettes_a8be
 	add hl, de
 
@@ -93,9 +92,8 @@
 	ld a, [EnemyHPPal]
 	ld l, a
 	ld h, 0
-rept 2
 	add hl, hl
-endr
+	add hl, hl
 
 	ld de, Palettes_a8be
 	add hl, de
@@ -148,9 +146,8 @@
 
 	ld hl, wSGBPals + 1
 	ld [hl], $10
-rept 2
 	inc hl
-endr
+	inc hl
 
 	ld a, [PlayerHPPal]
 	add $2f
@@ -174,9 +171,8 @@
 	ld a, [wcda1]
 	ld l, a
 	ld h, 0
-rept 2
 	add hl, hl
-endr
+	add hl, hl
 	ld de, Palettes_a8be
 	add hl, de
 	ld a, [hli]
--- a/rst.asm
+++ b/rst.asm
@@ -22,9 +22,8 @@
 	push de
 	ld e, a
 	ld d, 0
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/sram.asm
+++ b/sram.asm
@@ -83,7 +83,7 @@
 
 s0_b208:: ds 1 ; loaded with 99, used to check save corruption
 
-sBackupGameData::
+sBackupGameData:: ; b209
 sBackupPlayerData::  ds wPlayerDataEnd - wPlayerData
 sBackupMapData::     ds wMapDataEnd - wMapData
 sBackupPokemonData:: ds wPokemonDataEnd - wPokemonData
@@ -104,7 +104,7 @@
 
 s1_a008:: ds 1 ; loaded with 99, used to check save corruption
 
-sGameData::
+sGameData:: ; a009
 sPlayerData::  ds wPlayerDataEnd - wPlayerData
 sMapData::     ds wMapDataEnd - wMapData
 sPokemonData:: ds wPokemonDataEnd - wPokemonData
--- a/text/types.asm
+++ b/text/types.asm
@@ -85,9 +85,8 @@
 	ld hl, TypeNames
 	ld e, a
 	ld d, 0
-rept 2
 	add hl, de
-endr
+	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/tilesets/animations.asm
+++ b/tilesets/animations.asm
@@ -16,9 +16,8 @@
 	ld [hTileAnimFrame], a
 
 	ld h, 0
-rept 2
 	add hl, hl
-endr
+	add hl, hl
 	add hl, de
 
 ; 2-byte parameter
@@ -714,9 +713,8 @@
 	ld a, [TileAnimationTimer]
 	and 6
 	srl a
-rept 2
 	inc a
-endr
+	inc a
 	and 3
 	swap a
 	ld e, a
--- a/trainers/dvs.asm
+++ b/trainers/dvs.asm
@@ -8,9 +8,8 @@
 	ld b, 0
 
 	ld hl, TrainerClassDVs
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 
 	ld a, [hli]
 	ld b, a
--- a/trainers/read_party.asm
+++ b/trainers/read_party.asm
@@ -32,9 +32,8 @@
 	ld c, a
 	ld b, 0
 	ld hl, TrainerGroups
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -62,9 +61,8 @@
 	ld d, h
 	ld e, l
 	ld hl, TrainerTypes
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
@@ -364,9 +362,8 @@
 	push bc
 	ld b, 0
 	ld hl, TrainerGroups
-rept 2
 	add hl, bc
-endr
+	add hl, bc
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
--- a/wram.asm
+++ b/wram.asm
@@ -2661,7 +2661,7 @@
 wWhichMomItemSet:: ds 1 ; dc18
 MomItemTriggerBalance:: ds 3 ; dc19
 
-wDailyResetTimer:: ds 2
+wDailyResetTimer:: ds 2 ; dc1c
 DailyFlags:: ds 1
 WeeklyFlags:: ds 1
 SwarmFlags:: ds 1
@@ -2673,9 +2673,9 @@
 
 	ds 2
 
-wLuckyNumberDayBuffer:: ds 2
+wLuckyNumberDayBuffer:: ds 2 ; dc2d
 	ds 2
-wSpecialPhoneCallID:: ds 1
+wSpecialPhoneCallID:: ds 1 ; dc31
 	ds 3
 wBugContestStartTime:: ds 4 ; day, hour, min, sec ; dc35
 wUnusedTwoDayTimerOn:: ds 1 ; dc39