summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpikalaxalt <PikalaxALT@gmail.com>2016-05-04 11:46:23 -0400
committerpikalaxalt <PikalaxALT@gmail.com>2016-05-04 11:46:23 -0400
commit3713b71d9e3f3f1bc099d4704910cb9c1d172dcf (patch)
tree03069bd1fb4576c16b773b23bab0071aabb7cabd
parent82f1534925c5fe1f0d876ea88119b0121cfa65a6 (diff)
More splitting of main.asm; remove unneeded rept 2
-rw-r--r--audio/engine.asm21
-rw-r--r--audio/music/goldenrodcity.asm3
-rw-r--r--audio/music/johtowildbattle.asm3
-rw-r--r--audio/music/kantowildbattle.asm12
-rw-r--r--battle/ai/items.asm3
-rwxr-xr-xbattle/ai/move.asm3
-rw-r--r--battle/ai/scoring.asm126
-rwxr-xr-xbattle/ai/switch.asm3
-rw-r--r--battle/hidden_power.asm6
-rwxr-xr-xbattle/link_result.asm162
-rw-r--r--battle/magikarp_length.asm3
-rw-r--r--battle/misc.asm6
-rwxr-xr-xbattle/sliding_intro.asm9
-rwxr-xr-xconstants/cgb_constants.asm2
-rw-r--r--data/pokedex/entry_pointers.asm72
-rwxr-xr-xengine/anim_hp_bar.asm3
-rwxr-xr-xengine/billspc.asm19
-rwxr-xr-xengine/breeding/egg.asm6
-rwxr-xr-xengine/card_flip.asm60
-rw-r--r--engine/credits.asm12
-rwxr-xr-xengine/crystal_intro.asm40
-rwxr-xr-xengine/debug.asm33
-rwxr-xr-xengine/delete_save_change_clock.asm298
-rwxr-xr-xengine/events_3.asm15
-rwxr-xr-xengine/evolution_animation.asm6
-rwxr-xr-xengine/evolve.asm9
-rw-r--r--engine/fish.asm6
-rwxr-xr-xengine/healmachineanim.asm3
-rw-r--r--engine/landmarks.asm6
-rwxr-xr-xengine/link.asm6
-rwxr-xr-xengine/mart.asm9
-rwxr-xr-xengine/move_mon.asm14
-rwxr-xr-xengine/move_mon_wo_mail.asm133
-rwxr-xr-xengine/namingscreen.asm18
-rwxr-xr-xengine/npctrade.asm6
-rwxr-xr-xengine/options_menu.asm9
-rwxr-xr-xengine/overworld.asm15
-rw-r--r--engine/pack.asm6
-rw-r--r--engine/party_menu.asm27
-rw-r--r--engine/phone.asm12
-rw-r--r--engine/pokedex.asm3
-rwxr-xr-xengine/printer.asm9
-rwxr-xr-xengine/rtc.asm3
-rwxr-xr-xengine/search2.asm134
-rwxr-xr-xengine/selectmenu.asm6
-rwxr-xr-xengine/sprites.asm4
-rwxr-xr-xengine/stats_screen.asm6
-rwxr-xr-xengine/switch_items.asm3
-rwxr-xr-xengine/time.asm3
-rwxr-xr-xengine/time_capsule/conversion.asm3
-rw-r--r--engine/timeofdaypals.asm6
-rwxr-xr-xengine/timeset.asm6
-rw-r--r--engine/title.asm3
-rwxr-xr-xengine/tmhm2.asm3
-rwxr-xr-xengine/trade/animation.asm9
-rwxr-xr-xengine/unown_puzzle.asm6
-rwxr-xr-xengine/unowndex.asm3
-rwxr-xr-xengine/warp_connection.asm2
-rwxr-xr-xengine/wildmons.asm18
-rw-r--r--event/battle_tower.asm6
-rw-r--r--event/buena.asm3
-rwxr-xr-xevent/bug_contest_2.asm9
-rwxr-xr-xevent/bug_contest_judging.asm21
-rwxr-xr-xevent/celebi.asm3
-rw-r--r--event/dratini.asm3
-rwxr-xr-xevent/elevator.asm6
-rwxr-xr-xevent/field_moves.asm9
-rwxr-xr-xevent/halloffame.asm6
-rw-r--r--event/kurt.asm6
-rw-r--r--event/magikarp.asm3
-rwxr-xr-xevent/magnet_train.asm15
-rw-r--r--event/mom.asm9
-rw-r--r--event/poke_seer.asm3
-rwxr-xr-xgfx/mail.asm6
-rw-r--r--gfx/pics/animation.asm18
-rw-r--r--home/battle.asm6
-rw-r--r--home/copy.asm3
-rw-r--r--home/joypad.asm6
-rw-r--r--home/map_objects.asm6
-rw-r--r--home/movement.asm6
-rw-r--r--home/text.asm24
-rw-r--r--home/vblank.asm3
-rw-r--r--items/item_descriptions.asm3
-rw-r--r--items/item_effects.asm24
-rw-r--r--lib/mobile/main.asm153
-rw-r--r--main.asm819
-rwxr-xr-xmisc/battle_tower_47.asm6
-rwxr-xr-xmisc/battle_tower_5c.asm24
-rw-r--r--misc/crystal_misc.asm6
-rwxr-xr-xmisc/mobile_12_2.asm3
-rw-r--r--misc/mobile_22.asm24
-rw-r--r--misc/mobile_22_2.asm15
-rwxr-xr-xmisc/mobile_41.asm3
-rw-r--r--misc/mobile_42.asm15
-rw-r--r--misc/mobile_45.asm51
-rwxr-xr-xmisc/mobile_45_sprite_engine.asm3
-rwxr-xr-xmisc/mobile_5b.asm6
-rwxr-xr-xmisc/mobile_5c.asm12
-rw-r--r--predef/cgb.asm4
-rw-r--r--predef/sgb.asm12
-rw-r--r--rst.asm3
-rw-r--r--sram.asm4
-rw-r--r--text/types.asm3
-rw-r--r--tilesets/animations.asm6
-rw-r--r--trainers/dvs.asm3
-rwxr-xr-xtrainers/read_party.asm9
-rw-r--r--wram.asm6
107 files changed, 1222 insertions, 1610 deletions
diff --git a/audio/engine.asm b/audio/engine.asm
index c8e976cc4..311b6e760 100644
--- a/audio/engine.asm
+++ b/audio/engine.asm
@@ -1348,9 +1348,8 @@ GetNoiseSample: ; e86c5
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 @@ endr
; 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 @@ ParseMusicCommand: ; e870f
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 @@ Music_JumpIf: ; e8817
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 @@ MusicEE; e883e
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 @@ LoadChannel: ; e8d1b
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 @@ ClearChannels:: ; e8fe9
; 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
diff --git a/audio/music/goldenrodcity.asm b/audio/music/goldenrodcity.asm
index 89ee7d5bb..d7318310e 100644
--- a/audio/music/goldenrodcity.asm
+++ b/audio/music/goldenrodcity.asm
@@ -275,9 +275,8 @@ Music_GoldenrodCity_Ch3: ; eb584
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
diff --git a/audio/music/johtowildbattle.asm b/audio/music/johtowildbattle.asm
index e775fa648..bcfde1824 100644
--- a/audio/music/johtowildbattle.asm
+++ b/audio/music/johtowildbattle.asm
@@ -492,9 +492,8 @@ Music_JohtoWildBattle_branch_f5fdb: ; f5fdb
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
diff --git a/audio/music/kantowildbattle.asm b/audio/music/kantowildbattle.asm
index f867e1273..5737f643b 100644
--- a/audio/music/kantowildbattle.asm
+++ b/audio/music/kantowildbattle.asm
@@ -325,25 +325,21 @@ Music_KantoWildBattle_branch_ed1c8: ; ed1c8
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
diff --git a/battle/ai/items.asm b/battle/ai/items.asm
index 16511de79..bd7f2d8d2 100644
--- a/battle/ai/items.asm
+++ b/battle/ai/items.asm
@@ -216,9 +216,8 @@ endr
pop de
pop hl
-rept 2
inc hl
-endr
+ inc hl
jr c, .loop
.used_item
diff --git a/battle/ai/move.asm b/battle/ai/move.asm
index 0d1c6c968..a267cad8c 100755
--- a/battle/ai/move.asm
+++ b/battle/ai/move.asm
@@ -107,9 +107,8 @@ endr
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
diff --git a/battle/ai/scoring.asm b/battle/ai/scoring.asm
index 9b8dd6e42..9f568e9fd 100644
--- a/battle/ai/scoring.asm
+++ b/battle/ai/scoring.asm
@@ -133,18 +133,16 @@ AI_Setup: ; 385e0
call AI_50_50
jr c, .checkmove
-rept 2
dec [hl]
-endr
+ dec [hl]
jr .checkmove
.discourage
call Random
cp 30
jr c, .checkmove
-rept 2
inc [hl]
-endr
+ inc [hl]
jr .checkmove
; 38635
@@ -264,9 +262,8 @@ AI_Offensive: ; 386a2
and a
jr nz, .checkmove
-rept 2
inc [hl]
-endr
+ inc [hl]
jr .checkmove
; 386be
@@ -420,9 +417,8 @@ AI_Smart_Sleep: ; 387e3
.asm_387f0
call AI_50_50
ret c
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
; 387f7
@@ -533,9 +529,8 @@ AI_Smart_LockOn: ; 3881d
call AI_50_50
ret c
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
.asm_38882
@@ -560,9 +555,8 @@ endr
cp 180
jr nc, .asm_3888b
-rept 2
dec [hl]
-endr
+ dec [hl]
jr .asm_3888b
.asm_388a2
@@ -645,9 +639,8 @@ AI_Smart_EvasionUp: ; 388d4
jr nc, .asm_38911
.asm_388ef
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
.asm_388f2
@@ -676,9 +669,8 @@ endr
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 @@ endr
call Random
cp $50
ret c
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
; Player is seeded.
@@ -756,9 +747,8 @@ AI_Smart_AlwaysHit: ; 38947
call AI_80_20
ret c
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
; 3895b
@@ -828,9 +818,8 @@ AI_Smart_AccuracyDown: ; 38985
jr nc, .asm_389bf
.asm_3899d
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
.asm_389a0
@@ -859,9 +848,8 @@ endr
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 @@ endr
call Random
cp $50
ret c
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
; Player is seeded.
@@ -1010,9 +997,8 @@ AI_Smart_Moonlight: ; 38a3a
call Random
cp $19
ret c
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
; 38a4e
@@ -1093,9 +1079,8 @@ AI_Smart_Bind: ; 38a71
ret nc
call AI_50_50
ret c
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
; 38a9c
@@ -1200,9 +1185,8 @@ AI_Smart_SpDefenseUp2: ; 38aed
.asm_38b09
call AI_80_20
ret c
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
.asm_38b10
@@ -1255,9 +1239,8 @@ AI_Smart_Paralyze: ; 38b26
ret nc
call AI_80_20
ret c
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
.asm_38b3a
@@ -1289,9 +1272,8 @@ AI_Smart_SpeedDownHit: ; 38b40
call Random
cp 30
ret c
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
; 38b5c
@@ -1528,9 +1510,8 @@ AI_Smart_Encore: ; 38c3b
call Random
cp $46
ret c
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
.asm_38c81
@@ -1685,9 +1666,8 @@ AI_Smart_Spite: ; 38cd5
call Random
cp $64
ret c
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
; 38d16
@@ -1755,9 +1735,8 @@ endr
ret z
call AI_50_50
ret c
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
.no_status
@@ -2007,15 +1986,13 @@ AI_Smart_Curse: ; 38e5c
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 @@ endr
call AI_50_50
ret c
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
; 38ed2
@@ -2119,9 +2095,8 @@ AI_Smart_Protect: ; 38ed2
call Random
cp 20
ret c
-rept 2
inc [hl]
-endr
+ inc [hl]
ret
; 38f1d
@@ -2151,9 +2126,8 @@ AI_Smart_Foresight: ; 38f1d
call Random
cp 100
ret c
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
; 38f4a
@@ -2272,9 +2246,8 @@ endr
call AI_50_50
ret c
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
.asm_38fd8
@@ -2296,9 +2269,8 @@ AI_Smart_FuryCutter: ; 38fdb
cp 2
jr c, .end
-rept 2
dec [hl]
-endr
+ dec [hl]
cp 3
jr c, .end
@@ -2344,9 +2316,8 @@ AI_Smart_Rollout: ; 38fef
call Random
cp 200
ret nc
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
.asm_39020
@@ -2406,9 +2377,8 @@ AI_Smart_Earthquake: ; 39044
call AICompareSpeed
ret nc
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
.could_dig
@@ -2455,9 +2425,8 @@ AI_Smart_Pursuit: ; 39072
.asm_3907d
call AI_50_50
ret c
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
; 39084
@@ -2482,9 +2451,8 @@ AI_Smart_RapidSpin: ; 39084
call AI_80_20
ret c
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
; 3909e
@@ -2636,9 +2604,8 @@ AIGoodWeatherType: ; 39122
ret nz
.good
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
; 39134
@@ -2733,9 +2700,8 @@ AI_Smart_PsychUp: ; 39152
ret
.asm_39188
-rept 2
inc [hl]
-endr
+ inc [hl]
ret
; 3918b
@@ -2820,9 +2786,8 @@ AI_Smart_Gust: ; 391d5
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 @@ AI_Smart_FutureSight: ; 391f3
and 1 << SUBSTATUS_FLYING | 1 << SUBSTATUS_UNDERGROUND
ret z
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
; 39200
@@ -2886,18 +2850,16 @@ AI_Smart_Solarbeam: ; 3920b
cp 25 ; 1/10
ret c
-rept 2
inc [hl]
-endr
+ inc [hl]
ret
.asm_3921e
call AI_80_20
ret c
-rept 2
dec [hl]
-endr
+ dec [hl]
ret
; 39225
@@ -2991,9 +2953,8 @@ AICheckPlayerHalfHP: ; 3926e
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 @@ AICheckEnemyHalfHP: ; 39281
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 @@ AICheckEnemyQuarterHP: ; 39298
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 @@ AICheckPlayerQuarterHP: ; 392b3
rl b
sla c
rl b
-rept 2
inc hl
-endr
+ inc hl
ld a, [hld]
cp c
ld a, [hl]
diff --git a/battle/ai/switch.asm b/battle/ai/switch.asm
index 8f5db7a54..3a0b27a0f 100755
--- a/battle/ai/switch.asm
+++ b/battle/ai/switch.asm
@@ -626,9 +626,8 @@ FindEnemyMonsWithEnoughHP: ; 34b77
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
diff --git a/battle/hidden_power.asm b/battle/hidden_power.asm
index 68b0e80f8..184c597d0 100644
--- a/battle/hidden_power.asm
+++ b/battle/hidden_power.asm
@@ -45,9 +45,8 @@ HiddenPowerDamage: ; fbced
; Multiply by 5
ld b, a
-rept 2
add a
-endr
+ add a
add b
; Add Special & 3
@@ -75,9 +74,8 @@ endr
ld a, [hl]
and 3 << 4
swap a
-rept 2
add a
-endr
+ add a
or b
; Skip Normal
diff --git a/battle/link_result.asm b/battle/link_result.asm
new file mode 100755
index 000000000..5739bbdc0
--- /dev/null
+++ b/battle/link_result.asm
@@ -0,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
diff --git a/battle/magikarp_length.asm b/battle/magikarp_length.asm
index 237450928..160912c53 100644
--- a/battle/magikarp_length.asm
+++ b/battle/magikarp_length.asm
@@ -141,9 +141,8 @@ CalcMagikarpLength: ; fbbfc
; hl = de * 10
ld h, d
ld l, e
-rept 2
add hl, hl
-endr
+ add hl, hl
add hl, de
add hl, hl
diff --git a/battle/misc.asm b/battle/misc.asm
index 97a11898e..0fed74e38 100644
--- a/battle/misc.asm
+++ b/battle/misc.asm
@@ -72,9 +72,8 @@ DoWeatherModifiers: ; fbda4
jr z, .ApplyModifier
.NextWeatherType:
-rept 2
inc de
-endr
+ inc de
jr .CheckWeatherType
@@ -99,9 +98,8 @@ endr
jr z, .ApplyModifier
.NextWeatherMove:
-rept 2
inc de
-endr
+ inc de
jr .CheckWeatherMove
.ApplyModifier:
diff --git a/battle/sliding_intro.asm b/battle/sliding_intro.asm
index 194a4cd1b..4b3be76c7 100755
--- a/battle/sliding_intro.asm
+++ b/battle/sliding_intro.asm
@@ -39,12 +39,10 @@ BattleIntroSlidingPics: ; 4e980
ld a, d
ld [hSCX], a
call .subfunction5
-rept 2
inc e
-endr
-rept 2
+ inc e
+ dec d
dec d
-endr
pop af
push af
cp $1
@@ -66,9 +64,8 @@ endr
ld c, $12 ; 18
ld de, $4
.loop3
-rept 2
dec [hl]
-endr
+ dec [hl]
add hl, de
dec c
jr nz, .loop3
diff --git a/constants/cgb_constants.asm b/constants/cgb_constants.asm
index 9363415a3..726099509 100755
--- 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
diff --git a/data/pokedex/entry_pointers.asm b/data/pokedex/entry_pointers.asm
index 4f0f8aff2..5a432e661 100644
--- 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
diff --git a/engine/anim_hp_bar.asm b/engine/anim_hp_bar.asm
index c8a543ba1..21a378dee 100755
--- a/engine/anim_hp_bar.asm
+++ b/engine/anim_hp_bar.asm
@@ -273,9 +273,8 @@ HPBarAnim_UpdateHPRemaining: ; d784
push hl
add hl, de
ld a, " "
-rept 2
ld [hli], a
-endr
+ ld [hli], a
ld [hld], a
dec hl
ld a, [Buffer3]
diff --git a/engine/billspc.asm b/engine/billspc.asm
index 5e9e7393b..3c8f7fc83 100755
--- a/engine/billspc.asm
+++ b/engine/billspc.asm
@@ -142,9 +142,8 @@ _DepositPKMN: ; e2391 (38:6391)
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 @@ BillsPC_Withdraw: ; e2675 (38:6675)
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 @@ _MovePKMNWithoutMail: ; e2759
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 @@ MovePKMNWitoutMail_InsertMon: ; e31e7
.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 @@ endr
ld hl, wBillsPC_ScrollPosition
add [hl]
ld [CurPartyMon], a
- callba Function51322
+ callba InsertPokemonIntoBox
ret
; e3316
@@ -2172,7 +2168,7 @@ endr
ld hl, wBillsPC_ScrollPosition
add [hl]
ld [CurPartyMon], a
- callba Function5138b
+ callba InsertPokemonIntoParty
ret
; e3357
@@ -2256,9 +2252,8 @@ BillsPC_ApplyPalettes: ; e33d0 (38:73d0)
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
diff --git a/engine/breeding/egg.asm b/engine/breeding/egg.asm
index b6f41743e..d86b1ef69 100755
--- a/engine/breeding/egg.asm
+++ b/engine/breeding/egg.asm
@@ -442,9 +442,8 @@ GLOBAL EggMoves
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 @@ endr
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
diff --git a/engine/card_flip.asm b/engine/card_flip.asm
index 2c334fc25..0479e8248 100755
--- a/engine/card_flip.asm
+++ b/engine/card_flip.asm
@@ -71,9 +71,8 @@ _CardFlip: ; e00ee (38:40ee)
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 @@ endr
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 @@ CardFlip_DisplayCardFaceUp: ; e03ec
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 @@ CardFlip_BlankDiscardedCardSlot: ; e0534
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 @@ endr
.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 @@ endr
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 @@ endr
.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 @@ endr
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 @@ endr
.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 @@ endr
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 @@ endr
.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 @@ endr
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 @@ endr
.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 @@ endr
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 @@ endr
.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 @@ ChooseCard_HandleJoypad: ; e089c
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 @@ endr
ld [hl], a
cp $4
ret nc
-rept 2
inc [hl]
-endr
+ inc [hl]
jr .play_sound
.d_up ; e090a
@@ -1357,9 +1340,8 @@ endr
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 @@ endr
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 @@ CardFlip_UpdateCursorOAM: ; e0960
.skip
call CollapseCursorPosition
-rept 2
add hl, hl
-endr
+ add hl, hl
ld de, .OAMData
add hl, de
ld a, [hli]
diff --git a/engine/credits.asm b/engine/credits.asm
index 9074b9c65..4fd41342f 100644
--- a/engine/credits.asm
+++ b/engine/credits.asm
@@ -258,9 +258,8 @@ Credits_Jumptable: ; 109926
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 @@ Credits_LYOverride: ; 109986 (42:5986)
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 @@ ParseCredits: ; 1099aa
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 @@ Credits_LoadBorderGFX: ; 109bca (42:5bca)
ld [hl], a
ld a, [wCreditsBorderMon]
and 3
-rept 2
add a
-endr
+ add a
add e
add a
ld e, a
diff --git a/engine/crystal_intro.asm b/engine/crystal_intro.asm
index 2be7a375e..c40062c1a 100755
--- a/engine/crystal_intro.asm
+++ b/engine/crystal_intro.asm
@@ -13,7 +13,7 @@ Copyright_GFPresents: ; e4579
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 @@ Copyright_GFPresents: ; e4579
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 @@ Copyright_GFPresents: ; e4579
ld [hBGMapMode], a
ld a, $90
ld [hWY], a
- ld de, $e4e4
+ lb de, %11100100, %11100100
call DmgToCgbObjPals
ret
; e465e
@@ -120,9 +120,8 @@ PlaceGameFreakPresents: ; e4670
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 @@ GameFreakLogoJumper: ; e46ed (39:46ed)
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 @@ GameFreakLogoScene4: ; e4776 (39:4776)
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 @@ IntroSceneJumper: ; e490f
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 @@ IntroScene12: ; e4cfa (39:4cfa)
ret z
cp c
jr z, .playsound
-rept 2
inc hl
-endr
+ inc hl
jr .loop
.playsound
ld a, [hli]
@@ -1667,9 +1662,8 @@ endr
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 @@ endr
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 @@ endr
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 @@ endr
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 @@ Intro_PerspectiveScrollBG: ; e552f (39:552f)
; 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]
diff --git a/engine/debug.asm b/engine/debug.asm
index a02f536db..79d477dc1 100755
--- a/engine/debug.asm
+++ b/engine/debug.asm
@@ -300,9 +300,8 @@ Function81a74: ; 81a74
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 @@ Function81bf4: ; 81bf4
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 @@ Function81c33: ; 81c33
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 @@ Function81cc2: ; 81cc2
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 @@ String_81e4d: db "おぼえられない@" ; cannot be taught
Function81e55: ; 81e55
cp $32
jr c, .asm_81e5b
-rept 2
inc a
-endr
+ inc a
.asm_81e5b
add $bf
@@ -938,9 +933,8 @@ Function81eca: ; 81eca
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 @@ Function81ee3: ; 81ee3
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 @@ Function81f5e: ; 81f5e
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 @@ Function822f0: ; 822f0
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 @@ Function82309: ; 82309
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 @@ Function82391: ; 82391
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
diff --git a/engine/delete_save_change_clock.asm b/engine/delete_save_change_clock.asm
new file mode 100755
index 000000000..b92698b49
--- /dev/null
+++ b/engine/delete_save_change_clock.asm
@@ -0,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@"
diff --git a/engine/events_3.asm b/engine/events_3.asm
index b1c142a27..7c737d1fb 100755
--- a/engine/events_3.asm
+++ b/engine/events_3.asm
@@ -184,12 +184,10 @@ PlaceMapNameCenterAlign: ; b80e1 (2e:40e1)
InitMapSignAttrMap: ; b8115
ld de, AttrMap - TileMap
add hl, de
-rept 2
inc b
-endr
-rept 2
+ inc b
+ inc c
inc c
-endr
ld a, $87
.loop
push bc
@@ -261,15 +259,13 @@ PlaceMapNameFrame: ; b812f
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 @@ GetTreeMons: ; b82d2
ld e, a
ld d, 0
ld hl, TreeMons
-rept 2
add hl, de
-endr
+ add hl, de
ld a, [hli]
ld h, [hl]
diff --git a/engine/evolution_animation.asm b/engine/evolution_animation.asm
index dc0ddd8f6..42df7eea4 100755
--- a/engine/evolution_animation.asm
+++ b/engine/evolution_animation.asm
@@ -187,9 +187,8 @@ EvolutionAnimation: ; 4e5e1
call .Flash
pop bc
inc b
-rept 2
dec c
-endr
+ dec c
jr nz, .loop
and a
ret
@@ -344,9 +343,8 @@ endr
ld a, [hVBlankCounter]
and %1110
srl a
-rept 2
inc a
-endr
+ inc a
and $7
ld b, a
ld hl, Sprites + 3 ; attributes
diff --git a/engine/evolve.asm b/engine/evolve.asm
index db7d7e946..9a70290f2 100755
--- a/engine/evolve.asm
+++ b/engine/evolve.asm
@@ -46,9 +46,8 @@ EvolveAfterBattle_MasterLoop
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 @@ LearnLevelMoves: ; 42487
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 @@ GetPreEvolution: ; 42581
.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
diff --git a/engine/fish.asm b/engine/fish.asm
index 6aeec10a6..e21bab03d 100644
--- a/engine/fish.asm
+++ b/engine/fish.asm
@@ -38,9 +38,8 @@ endr
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 @@ endr
and 3
cp NITE
jr c, .time_species
-rept 2
inc hl
-endr
+ inc hl
.time_species
ld d, [hl]
diff --git a/engine/healmachineanim.asm b/engine/healmachineanim.asm
index 01ed6d652..2b8f3b868 100755
--- a/engine/healmachineanim.asm
+++ b/engine/healmachineanim.asm
@@ -25,9 +25,8 @@ HealMachineAnim: ; 12324
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
diff --git a/engine/landmarks.asm b/engine/landmarks.asm
index 8fb7035f2..a0b4336aa 100644
--- a/engine/landmarks.asm
+++ b/engine/landmarks.asm
@@ -3,9 +3,8 @@ GetLandmarkCoords: ; 0x1ca896
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 @@ GetLandmarkName:: ; 0x1ca8a5
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]
diff --git a/engine/link.asm b/engine/link.asm
index 14c9c2f4d..788ee22a2 100755
--- a/engine/link.asm
+++ b/engine/link.asm
@@ -1094,14 +1094,12 @@ Function2868a: ; 2868a
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
diff --git a/engine/mart.asm b/engine/mart.asm
index f756d3bc2..dfe7d89cd 100755
--- a/engine/mart.asm
+++ b/engine/mart.asm
@@ -145,9 +145,8 @@ GetMart: ; 15b31
.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 @@ LoadBuyMenuText: ; 15c7d
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 @@ endr
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
diff --git a/engine/move_mon.asm b/engine/move_mon.asm
index 310eab8c2..100cb3f0e 100755
--- a/engine/move_mon.asm
+++ b/engine/move_mon.asm
@@ -654,7 +654,7 @@ SentGetPkmnIntoFromBox: ; db3f
ld a, [sBoxCount]
dec a
ld b, a
- call Functiondcb6
+ call RestorePPofDepositedPokemon
.CloseSRAM_And_ClearCarryFlag:
call CloseSRAM
and a
@@ -667,7 +667,7 @@ CloseSRAM_And_SetCarryFlag: ; dcb1
ret
; dcb6
-Functiondcb6: ; dcb6
+RestorePPofDepositedPokemon: ; dcb6
ld a, b
ld hl, sBoxMons
ld bc, BOXMON_STRUCT_LENGTH
@@ -696,10 +696,10 @@ Functiondcb6: ; dcb6
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 @@ Functiondcb6: ; dcb6
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 @@ SentPkmnIntoBox: ; de6e
call CopyBytes
ld b, 0
- call Functiondcb6
+ call RestorePPofDepositedPokemon
call CloseSRAM
scf
diff --git a/engine/move_mon_wo_mail.asm b/engine/move_mon_wo_mail.asm
new file mode 100755
index 000000000..d3b4e78a5
--- /dev/null
+++ b/engine/move_mon_wo_mail.asm
@@ -0,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
diff --git a/engine/namingscreen.asm b/engine/namingscreen.asm
index d9fe253fb..16a87b0c8 100755
--- a/engine/namingscreen.asm
+++ b/engine/namingscreen.asm
@@ -65,9 +65,8 @@ NamingScreen: ; 116c1
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 @@ NamingScreenJoypadLoop: ; 11915
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 @@ NamingScreen_AnimateCursor: ; 11a3b (4:5a3b)
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 @@ INCBIN "gfx/icon/mail2.2bpp"
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 @@ ComposeMail_AnimateCursor: ; 120c1 (4:60c1)
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 @@ MailComposition_TryAddLastCharacter: ; 121ac (4:61ac)
jr nz, .asm_121c3
push hl
ld hl, wNamingScreenCurrNameLength
-rept 2
dec [hl]
-endr
+ dec [hl]
jr .asm_121c8
.asm_121c3
diff --git a/engine/npctrade.asm b/engine/npctrade.asm
index a8d3b71aa..f28734ea9 100755
--- a/engine/npctrade.asm
+++ b/engine/npctrade.asm
@@ -311,9 +311,8 @@ GetTradeAttribute: ; 0xfcdc2
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 @@ PrintTradeText: ; fcf38
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
diff --git a/engine/options_menu.asm b/engine/options_menu.asm
index 00799395a..2986cc75b 100755
--- a/engine/options_menu.asm
+++ b/engine/options_menu.asm
@@ -85,9 +85,8 @@ GetOptionPointer: ; e42d6
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 @@ Options_TextSpeed: ; e42f5
.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 @@ Options_Print: ; e4424
.NonePressed:
ld b, $0
ld hl, .Strings
-rept 2
add hl, bc
-endr
+ add hl, bc
ld e, [hl]
inc hl
ld d, [hl]
diff --git a/engine/overworld.asm b/engine/overworld.asm
index 12c7f56c6..4d22e55b6 100755
--- a/engine/overworld.asm
+++ b/engine/overworld.asm
@@ -147,9 +147,8 @@ AddOutdoorSprites: ; 141ee
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 @@ AddSpriteGFX: ; 142e5
jr z, .exists
and a
jr z, .new
-rept 2
inc hl
-endr
+ inc hl
dec c
jr nz, .loop
@@ -428,9 +426,8 @@ SortUsedSprites: ; 1431e
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 @@ endr
; 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
diff --git a/engine/pack.asm b/engine/pack.asm
index ff80dce23..19b7fccbf 100644
--- a/engine/pack.asm
+++ b/engine/pack.asm
@@ -1252,9 +1252,8 @@ Pack_JumptableNext: ; 10866 (4:4866)
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 @@ DrawPackGFX: ; 1089d
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]
diff --git a/engine/party_menu.asm b/engine/party_menu.asm
index 934e1458a..985645a8c 100644
--- a/engine/party_menu.asm
+++ b/engine/party_menu.asm
@@ -110,9 +110,8 @@ PlacePartyNicknames: ; 5009b
jr nz, .loop
.end
-rept 2
dec hl
-endr
+ dec hl
ld de, .CANCEL
call PlaceString
ret
@@ -219,9 +218,8 @@ PlacePartyMenuHPDigits: ; 50138
pop de
ld a, "/"
ld [hli], a
-rept 2
inc de
-endr
+ inc de
lb bc, 2, 3
call PrintNum
@@ -390,9 +388,8 @@ PlacePartyMonEvoStoneCompatibility: ; 5022f
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 @@ endr
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 @@ GetPartyMenuTilemapPointers: ; 50396
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 @@ PrintPartyMenuText: ; 5049a
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 @@ PrintPartyMenuActionText: ; 50566
.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
diff --git a/engine/phone.asm b/engine/phone.asm
index 7f96dd2c3..9d1376a62 100644
--- a/engine/phone.asm
+++ b/engine/phone.asm
@@ -266,9 +266,8 @@ CheckSpecialPhoneCall:: ; 90136 (24:4136)
jr nc, .NoPhoneCall
call .DoSpecialPhoneCall
-rept 2
inc hl
-endr
+ inc hl
ld a, [hli]
ld e, a
push hl
@@ -520,9 +519,8 @@ Phone_CallerTextboxWithName2: ; 902c9
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 @@ Function90363: ; 90363 (24:4363)
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 @@ GetCallerName: ; 903a9 (24:43a9)
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]
diff --git a/engine/pokedex.asm b/engine/pokedex.asm
index 761b38874..95536a970 100644
--- a/engine/pokedex.asm
+++ b/engine/pokedex.asm
@@ -2385,9 +2385,8 @@ Pokedex_ApplyUsualPals: ; 41427
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
diff --git a/engine/printer.asm b/engine/printer.asm
index 876e59efc..409c8a461 100755
--- a/engine/printer.asm
+++ b/engine/printer.asm
@@ -21,9 +21,8 @@ Function84022: ; 84022
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 @@ Function84785: ; 84785
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 @@ Function847bd: ; 847bd
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]
diff --git a/engine/rtc.asm b/engine/rtc.asm
index 1f5e1e27c..3018b5301 100755
--- a/engine/rtc.asm
+++ b/engine/rtc.asm
@@ -35,9 +35,8 @@ GetTimeOfDay:: ; 14032
cp [hl]
jr c, .match
; else, get the next entry
-rept 2
inc hl
-endr
+ inc hl
; try again
jr .check
diff --git a/engine/search2.asm b/engine/search2.asm
new file mode 100755
index 000000000..9ef5491f0
--- /dev/null
+++ b/engine/search2.asm
@@ -0,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
diff --git a/engine/selectmenu.asm b/engine/selectmenu.asm
index 4e461a68e..838438a4c 100755
--- a/engine/selectmenu.asm
+++ b/engine/selectmenu.asm
@@ -45,9 +45,8 @@ CheckRegisteredItem: ; 13345
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 @@ endr
inc hl
ld e, a
ld d, 0
-rept 2
add hl, de
-endr
+ add hl, de
call .IsSameItem
jr c, .NoRegisteredItem
ret
diff --git a/engine/sprites.asm b/engine/sprites.asm
index 4335d45c5..b88c2a8ed 100755
--- a/engine/sprites.asm
+++ b/engine/sprites.asm
@@ -556,8 +556,8 @@ SpriteAnimSeqData: ; 8d1c4
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
diff --git a/engine/stats_screen.asm b/engine/stats_screen.asm
index e3bc6069c..dd9dd9a50 100755
--- a/engine/stats_screen.asm
+++ b/engine/stats_screen.asm
@@ -641,9 +641,8 @@ StatsScreen_LoadGFX: ; 4dfb6 (13:5fb6)
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 @@ endr
.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)
diff --git a/engine/switch_items.asm b/engine/switch_items.asm
index 0d4512876..b699d4719 100755
--- a/engine/switch_items.asm
+++ b/engine/switch_items.asm
@@ -231,9 +231,8 @@ ItemSwitch_ConvertSpacingToDW: ; 24a80 (9:4a80)
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]
diff --git a/engine/time.asm b/engine/time.asm
index 255346c0a..8ea807972 100755
--- a/engine/time.asm
+++ b/engine/time.asm
@@ -374,9 +374,8 @@ CalcHoursDaysSince: ; 115d2
; 115d6
CalcMinsHoursDaysSince: ; 115d6
-rept 2
inc hl
-endr
+ inc hl
xor a
jr _CalcMinsHoursDaysSince
; 115db
diff --git a/engine/time_capsule/conversion.asm b/engine/time_capsule/conversion.asm
index 5d093d515..a6c507dae 100755
--- a/engine/time_capsule/conversion.asm
+++ b/engine/time_capsule/conversion.asm
@@ -46,9 +46,8 @@ ValidateOTTrademon: ; fb57e
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
diff --git a/engine/timeofdaypals.asm b/engine/timeofdaypals.asm
index 1bfc2457b..3bba41f53 100644
--- a/engine/timeofdaypals.asm
+++ b/engine/timeofdaypals.asm
@@ -245,9 +245,8 @@ GetTimePalette: ; 8c117
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 @@ GetTimePalFade: ; 8c17c
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
diff --git a/engine/timeset.asm b/engine/timeset.asm
index fd6b2de94..65bd6aac9 100755
--- a/engine/timeset.asm
+++ b/engine/timeset.asm
@@ -200,9 +200,8 @@ UnreferencedFunction907f1: ; 907f1
push hl
call DisplayHourOClock
pop de
-rept 2
inc de
-endr
+ inc de
ld a, ":"
ld [de], a
inc de
@@ -521,9 +520,8 @@ Special_SetDayOfWeek: ; 90913
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
diff --git a/engine/title.asm b/engine/title.asm
index 30804fbe8..31fbe091e 100644
--- a/engine/title.asm
+++ b/engine/title.asm
@@ -351,9 +351,8 @@ InitializeBackground: ; 10ef06
ld b, a
ld a, e
ld [hli], a
-rept 2
inc e
-endr
+ inc e
ld a, $80
ld [hli], a
dec c
diff --git a/engine/tmhm2.asm b/engine/tmhm2.asm
index 289857623..7062149f8 100755
--- a/engine/tmhm2.asm
+++ b/engine/tmhm2.asm
@@ -581,9 +581,8 @@ PrintMoveDesc: ; 2cb3e
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]
diff --git a/engine/trade/animation.asm b/engine/trade/animation.asm
index 91e190075..228bb667c 100755
--- a/engine/trade/animation.asm
+++ b/engine/trade/animation.asm
@@ -224,9 +224,8 @@ DoTradeAnimation: ; 29082
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 @@ Function29281: ; 29281
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 @@ Function29676: ; 29676 (a:5676)
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
diff --git a/engine/unown_puzzle.asm b/engine/unown_puzzle.asm
index ada5244a7..5e9ec66c0 100755
--- a/engine/unown_puzzle.asm
+++ b/engine/unown_puzzle.asm
@@ -178,9 +178,8 @@ UnownPuzzleJumptable: ; e12ca
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 @@ LoadUnownPuzzlePiecesGFX: ; e17a3
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
diff --git a/engine/unowndex.asm b/engine/unowndex.asm
index 0b251da0b..d7fe63dc3 100755
--- a/engine/unowndex.asm
+++ b/engine/unowndex.asm
@@ -34,9 +34,8 @@ PrintUnownWord: ; fba2e (3e:7a2e)
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]
diff --git a/engine/warp_connection.asm b/engine/warp_connection.asm
index 9d1f35479..f0d5b5eab 100755
--- a/engine/warp_connection.asm
+++ b/engine/warp_connection.asm
@@ -369,7 +369,7 @@ CheckMovingOffEdgeOfMap:: ; 104820 (41:4820)
.left
ld a, [PlayerStandingMapX]
- sub $4
+ sub 4
cp -1
jr z, .ok
and a
diff --git a/engine/wildmons.asm b/engine/wildmons.asm
index 140de9205..557630686 100755
--- a/engine/wildmons.asm
+++ b/engine/wildmons.asm
@@ -108,9 +108,8 @@ endr
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 @@ endr
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 @@ UpdateRoamMons: ; 2a30d
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 @@ RandomPhoneRareWildMon: ; 2a4ab
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 @@ RandomPhoneWildMon: ; 2a51f
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 @@ RandomPhoneMon: ; 2a567
dec a
ld c, a
ld b, 0
-rept 2
add hl, bc
-endr
+ add hl, bc
ld a, BANK(TrainerGroups)
call GetFarHalfword
diff --git a/event/battle_tower.asm b/event/battle_tower.asm
index 091fe7fe1..0f4117c01 100644
--- a/event/battle_tower.asm
+++ b/event/battle_tower.asm
@@ -200,13 +200,11 @@ endr
.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
diff --git a/event/buena.asm b/event/buena.asm
index 5cff72d53..4802943f9 100644
--- a/event/buena.asm
+++ b/event/buena.asm
@@ -322,9 +322,8 @@ Buena_getprize: ; 8b154
ld hl, .prizes
ld b, 0
ld c, a
-rept 2
add hl, bc
-endr
+ add hl, bc
ret
; 8b15e
diff --git a/event/bug_contest_2.asm b/event/bug_contest_2.asm
index 72fa8a31b..493c69d0c 100755
--- a/event/bug_contest_2.asm
+++ b/event/bug_contest_2.asm
@@ -13,9 +13,8 @@ Special_SelectRandomBugContestContestants: ; 139a8
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 @@ endr
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 @@ Special_CheckBugContestContestantFlag: ; 139ed
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]
diff --git a/event/bug_contest_judging.asm b/event/bug_contest_judging.asm
index 420c46aac..be66b6ba0 100755
--- a/event/bug_contest_judging.asm
+++ b/event/bug_contest_judging.asm
@@ -85,9 +85,8 @@ LoadContestantName: ; 13730
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 @@ ComputeAIContestantScores: ; 138b0
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 @@ ContestScore: ; 13900
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 @@ endr
ld a, b
and 2
srl a
-rept 2
add c
-endr
-rept 2
+ add c
+ add d
add d
-endr
call .AddContestStat
diff --git a/event/celebi.asm b/event/celebi.asm
index c6d8346b0..2c2f6e57b 100755
--- a/event/celebi.asm
+++ b/event/celebi.asm
@@ -259,9 +259,8 @@ CelebiEvent_Cosine: ; 49b3b (12:5b3b)
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]
diff --git a/event/dratini.asm b/event/dratini.asm
index 5923ca363..f110b34ab 100644
--- a/event/dratini.asm
+++ b/event/dratini.asm
@@ -37,9 +37,8 @@ SpecialDratini: ; 0x8b170
; get address of mon's first move
pop de
-rept 2
inc de
-endr
+ inc de
.GiveMoves:
ld a, [hl]
diff --git a/event/elevator.asm b/event/elevator.asm
index 316bf382a..7626989b3 100755
--- a/event/elevator.asm
+++ b/event/elevator.asm
@@ -70,9 +70,8 @@ Elevator:: ; 1342d
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 @@ FloorToString: ; 13575
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
diff --git a/event/field_moves.asm b/event/field_moves.asm
index cf9e1bef0..1218a6f11 100755
--- a/event/field_moves.asm
+++ b/event/field_moves.asm
@@ -164,9 +164,8 @@ OWCutJumptable: ; 8ca0c
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 @@ Cut_SpawnAnimateTree: ; 8ca23 (23:4a23)
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 @@ Cut_GetLeafSpawnCoords: ; 8ca8e (23:4a8e)
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]
diff --git a/event/halloffame.asm b/event/halloffame.asm
index d6f2d15ed..2b2844f78 100755
--- a/event/halloffame.asm
+++ b/event/halloffame.asm
@@ -235,9 +235,8 @@ AnimateHOFMonEntrance: ; 865b5
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 @@ HOF_SlideFrontpic:
ld a, [hSCX]
and a
ret z
-rept 2
dec a
-endr
+ dec a
ld [hSCX], a
call DelayFrame
jr .frontpicloop
diff --git a/event/kurt.asm b/event/kurt.asm
index ac341de49..e1fff12c0 100644
--- a/event/kurt.asm
+++ b/event/kurt.asm
@@ -362,9 +362,8 @@ Kurt_GetAddressOfApricornQuantity: ; 88201
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 @@ Kurt_GetRidOfItem: ; 88211
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]
diff --git a/event/magikarp.asm b/event/magikarp.asm
index b9f73552c..4b024692f 100644
--- a/event/magikarp.asm
+++ b/event/magikarp.asm
@@ -250,9 +250,8 @@ CalcMagikarpLength: ; fbbfc
; hl = de × 10
ld h, d
ld l, e
-rept 2
add hl, hl
-endr
+ add hl, hl
add hl, de
add hl, hl
diff --git a/event/magnet_train.asm b/event/magnet_train.asm
index c074e6835..b03acb8b2 100755
--- a/event/magnet_train.asm
+++ b/event/magnet_train.asm
@@ -101,9 +101,8 @@ MagnetTrain_UpdateLYOverrides: ; 8cc99
ld d, a
ld hl, wcf64
ld a, [hl]
-rept 2
add d
-endr
+ add d
ld [hl], a
ret
@@ -211,9 +210,8 @@ GetMagnetTrainBGTiles: ; 8cd74
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 @@ MagnetTrain_Jumptable: ; 8cdf7
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 @@ endr
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
diff --git a/event/mom.asm b/event/mom.asm
index d2b7d2a7c..b899fd840 100644
--- a/event/mom.asm
+++ b/event/mom.asm
@@ -23,9 +23,8 @@ Special_BankOfMom: ; 16218
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 @@ endr
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 @@ endr
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
diff --git a/event/poke_seer.asm b/event/poke_seer.asm
index 2e942ef07..5e93acc5d 100644
--- a/event/poke_seer.asm
+++ b/event/poke_seer.asm
@@ -298,9 +298,8 @@ PrintSeerText: ; 4f26d
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
diff --git a/gfx/mail.asm b/gfx/mail.asm
index cb3c25bc8..c8e578d84 100755
--- a/gfx/mail.asm
+++ b/gfx/mail.asm
@@ -90,9 +90,8 @@ Functionb92b8: ; b92b8
cp -1
jr z, .invalid
inc c
-rept 2
inc hl
-endr
+ inc hl
jr .loop
.invalid
@@ -931,9 +930,8 @@ LoadMailGFX_Color3: ; b991e
.loop
ld a, [de]
inc de
-rept 2
ld [hli], a
-endr
+ ld [hli], a
dec c
jr nz, .loop
ret
diff --git a/gfx/pics/animation.asm b/gfx/pics/animation.asm
index 3284a271b..65522e9dc 100644
--- a/gfx/pics/animation.asm
+++ b/gfx/pics/animation.asm
@@ -110,9 +110,8 @@ LoadMonAnimation: ; d00a3
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 @@ Functiond02f8: ; d02f8
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 @@ Functiond031b: ; d031b
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 @@ GetMonAnimPointer: ; d055c
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 @@ GetMonFramesPointer: ; d05ce
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 @@ GetMonBitmaskPointer: ; d061b
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
diff --git a/home/battle.asm b/home/battle.asm
index ea228851e..e8aa0747c 100644
--- a/home/battle.asm
+++ b/home/battle.asm
@@ -153,9 +153,8 @@ GetBattleVarAddr:: ; 39e7
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 @@ endr
ld b, 0
ld hl, .vars
-rept 2
add hl, bc
-endr
+ add hl, bc
ld a, [hli]
ld h, [hl]
diff --git a/home/copy.asm b/home/copy.asm
index d4e3e2da7..183a19811 100644
--- a/home/copy.asm
+++ b/home/copy.asm
@@ -205,9 +205,8 @@ FarCopyBytesDouble:: ; e9b
.loop
ld a, [de]
inc de
-rept 2
ld [hli], a
-endr
+ ld [hli], a
.dec
dec c
jr nz, .loop
diff --git a/home/joypad.asm b/home/joypad.asm
index d66cdb662..0c0e30062 100644
--- a/home/joypad.asm
+++ b/home/joypad.asm
@@ -42,9 +42,8 @@ Joypad:: ; 935
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 @@ GetJoypad:: ; 984
jr nz, .next
; The current input is overwritten.
-rept 2
dec hl
-endr
+ dec hl
ld b, NO_INPUT
jr .finishauto
diff --git a/home/map_objects.asm b/home/map_objects.asm
index 3c70233eb..b3e544aac 100644
--- a/home/map_objects.asm
+++ b/home/map_objects.asm
@@ -28,9 +28,8 @@ GetSpriteVTile:: ; 180e
.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 @@ rept SPRITEMOVEDATA_FIELDS
endr
ld a, BANK(SpriteMovementData)
call GetFarByte
-rept 2
add a
-endr
+ add a
and $c
pop de
pop bc
diff --git a/home/movement.asm b/home/movement.asm
index 0e131e468..8471e81ca 100644
--- a/home/movement.asm
+++ b/home/movement.asm
@@ -107,9 +107,8 @@ ComputePathToWalkToPlayer:: ; 1b5f
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 @@ SetMenuAttributes:: ; 1bb1
dec b
jr nz, .loop
ld a, $1
-rept 2
ld [hli], a
-endr
+ ld [hli], a
xor a
rept 3
ld [hli], a
diff --git a/home/text.asm b/home/text.asm
index 6b4ce4f78..8632c2c65 100644
--- a/home/text.asm
+++ b/home/text.asm
@@ -129,12 +129,10 @@ TextBoxPalette:: ; 1024
; 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
inc c
-endr
ld a, TEXTBOX_PAL
.col
push bc
@@ -640,12 +638,10 @@ TextScroll:: ; 138c
dec c
jr nz, .row
-rept 2
inc de
-endr
-rept 2
+ inc de
+ inc hl
inc hl
-endr
pop af
dec a
jr nz, .col
@@ -738,9 +734,8 @@ DoTextUntilTerminator:: ; 13f6
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 @@ Text_PlaySound:: ; 1500
jr z, .done
cp b
jr z, .play
-rept 2
inc hl
-endr
+ inc hl
jr .loop
.play
@@ -1113,9 +1107,8 @@ Text_TX_STRINGBUFFER:: ; 156a
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 @@ Text_TX_DAY:: ; 1582
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
diff --git a/home/vblank.asm b/home/vblank.asm
index b93519298..cb8c5ba56 100644
--- a/home/vblank.asm
+++ b/home/vblank.asm
@@ -19,9 +19,8 @@ VBlank:: ; 283
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
diff --git a/items/item_descriptions.asm b/items/item_descriptions.asm
index 7ff574d11..40e91b2c9 100644
--- a/items/item_descriptions.asm
+++ b/items/item_descriptions.asm
@@ -21,9 +21,8 @@ PrintItemDescription: ; 0x1c8955
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]
diff --git a/items/item_effects.asm b/items/item_effects.asm
index ef05de8fd..7fde473ab 100644
--- a/items/item_effects.asm
+++ b/items/item_effects.asm
@@ -253,9 +253,8 @@ ParkBall: ; e8a2
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 @@ endr
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 @@ HeavyBallMultiplier:
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 @@ endr
call GetPokedexEntryBank
push bc
-rept 2
inc hl
-endr
+ inc hl
call GetFarHalfword
srl h
@@ -868,9 +864,8 @@ endr
ld a, c
cp [hl]
jr c, .heavymon
-rept 2
inc hl
-endr
+ inc hl
jr .lookup
.heavymon
@@ -929,9 +924,8 @@ GLOBAL EvosAttacksPointers
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 @@ GetHealingItemAmount: ; f395 (3:7395)
jr z, .NotFound
cp d
jr z, .done
-rept 2
inc hl
-endr
+ inc hl
jr .next
.NotFound:
@@ -2335,9 +2328,8 @@ XSpecial: ; f4c5
.loop
cp [hl]
jr z, .got_it
-rept 2
inc hl
-endr
+ inc hl
jr .loop
.got_it
diff --git a/lib/mobile/main.asm b/lib/mobile/main.asm
index de1dc854b..809e916b9 100644
--- a/lib/mobile/main.asm
+++ b/lib/mobile/main.asm
@@ -681,9 +681,8 @@ Function1103ac: ; 1103ac
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 @@ Function1106ef: ; 1106ef
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 @@ Function110905: ; 110905
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 @@ Function110a5b: ; 110a5b
ld [hli], a
ld a, d
ld [hli], a
-rept 2
inc de
-endr
-rept 2
+ inc de
+ dec bc
dec bc
-endr
ld hl, $c98f
ld a, e
ld [hli], a
@@ -1586,9 +1581,8 @@ endr
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 @@ Function110af4: ; 110af4
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 @@ endr
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 @@ Function110c9e: ; 110c9e
ld [hli], a
ld a, d
ld [hli], a
-rept 2
inc de
-endr
-rept 2
+ inc de
+ dec bc
dec bc
-endr
ld hl, $c98f
ld a, e
ld [hli], a
@@ -1934,9 +1924,8 @@ endr
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 @@ Function110ddd: ; 110ddd
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 @@ endr
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 @@ Function110f07: ; 110f07
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 @@ Function111044: ; 111044
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 @@ endr
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 @@ endr
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 @@ endr
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 @@ endr
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 @@ endr
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 @@ Function111335: ; 111335
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 @@ endr
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 @@ endr
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 @@ Function11164f: ; 11164f (44:564f)
ld a, b
srl a
srl a
-rept 2
add b
-endr
+ add b
ld [hl], a
ret
@@ -4126,9 +4100,8 @@ Function111abd: ; 111abd (44:5abd)
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 @@ Function111c17: ; 111c17 (44:5c17)
.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 @@ Function112451: ; 112451
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 @@ Function1125c7: ; 1125c7
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 @@ Function1128db: ; 1128db
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 @@ Function112a56: ; 112a56
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 @@ Function112d33: ; 112d33
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 @@ endr
cp $1
ld a, $32
jr z, .asm_112e95
-rept 2
inc de
-endr
+ inc de
inc a
.asm_112e95
@@ -7512,9 +7476,8 @@ Function113095: ; 113095
.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 @@ endr
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 @@ endr
ld e, a
ld a, [$c875]
ld d, a
-rept 2
inc de
-endr
+ inc de
call Function110000
.asm_11310d
@@ -7658,9 +7619,8 @@ Function113197: ; 113197
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 @@ Function1131a9: ; 1131a9
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 @@ endr
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 @@ Function113206: ; 113206
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 @@ Function1133fe: ; 1133fe
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 @@ endr
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 @@ endr
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 @@ Function1134cb: ; 1134cb
ret
.asm_1134f0
-rept 2
inc [hl]
-endr
+ inc [hl]
jr .asm_1134fc
.asm_1134f4
@@ -9223,9 +9176,8 @@ endr
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 @@ Function113ec7: ; 113ec7
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 @@ Function113ef2: ; 113ef2
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 @@ Function113f2d: ; 113f2d
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
diff --git a/main.asm b/main.asm
index 5b7c4d3ec..eebf7e9d9 100644
--- a/main.asm
+++ b/main.asm
@@ -1174,169 +1174,7 @@ Function29fe4: ; unreferenced
ret
INCLUDE "engine/wildmons.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
+INCLUDE "battle/link_result.asm"
ChrisBackpic: ; 2ba1a
INCBIN "gfx/misc/player.6x6.2bpp.lz"
@@ -2103,78 +1941,6 @@ DisplayDexEntry: ; 4424d
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 @@ SaveMenu_LoadEDTile: ; 4cf45 (13:4f45)
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 @@ PhoneRing_LoadEDTile: ; 4d188
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,304 +2583,7 @@ LinkTextbox2: ; 4d35b
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
-
-.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@"
+INCLUDE "engine/delete_save_change_clock.asm"
Tilesets::
INCLUDE "tilesets/tileset_headers.asm"
@@ -3587,7 +3056,7 @@ CheckPartyFullAfterContest: ; 4d9e5
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 @@ SetEggMonCaughtData: ; 4dbb8 (13:5bb8)
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 @@ _SwitchPartyMons:
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 @@ LoadPoisonBGPals: ; cbcdd
ld a, [hCGB]
and a
ret nz
- ret
+ ret ; ????
.LoadPals: ; cbce5
ld a, [hCGB]
@@ -5904,9 +5105,9 @@ LoadPoisonBGPals: ; cbcdd
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
diff --git a/misc/battle_tower_47.asm b/misc/battle_tower_47.asm
index a11f61064..1c83fabf5 100755
--- a/misc/battle_tower_47.asm
+++ b/misc/battle_tower_47.asm
@@ -61,9 +61,8 @@ ENDC
.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 @@ endr
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]
diff --git a/misc/battle_tower_5c.asm b/misc/battle_tower_5c.asm
index fb441a3f8..a3779e24f 100755
--- a/misc/battle_tower_5c.asm
+++ b/misc/battle_tower_5c.asm
@@ -217,9 +217,8 @@ _BattleTowerBattle: ; 17022c
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 @@ endr
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 @@ endr
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 @@ Function1704e1: ; 1704e1
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 @@ endr
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 @@ BattleTowerAction: ; 170687
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 @@ rept 4
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 @@ Function1709bb: ; 1709bb (5c:49bb) BattleTowerAction $10
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
diff --git a/misc/crystal_misc.asm b/misc/crystal_misc.asm
index 01538a3d6..8ff138869 100644
--- a/misc/crystal_misc.asm
+++ b/misc/crystal_misc.asm
@@ -682,15 +682,13 @@ Function17aaa9: ; 17aaa9 (5e:6aa9)
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)
diff --git a/misc/mobile_12_2.asm b/misc/mobile_12_2.asm
index 05e92cd55..dcf37aa70 100755
--- a/misc/mobile_12_2.asm
+++ b/misc/mobile_12_2.asm
@@ -616,9 +616,8 @@ Function4abc3: ; 4abc3
ld a, [wMenuCursorY]
ld [wMenuCursorY], a
ld a, [PartyCount]
-rept 2
inc a
-endr
+ inc a
ld b, a
ld a, [wMenuCursorY]
cp b
diff --git a/misc/mobile_22.asm b/misc/mobile_22.asm
index c9a844b42..3e2a9f30e 100644
--- a/misc/mobile_22.asm
+++ b/misc/mobile_22.asm
@@ -669,9 +669,8 @@ Function894dc: ; 894dc
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 @@ Function8956f: ; 8956f
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 @@ Function896eb: ; 896eb
Function896f5: ; 896f5
call Function8971f
call Function89736
-rept 2
inc hl
-endr
+ inc hl
ld b, 2
ClearScreenArea: ; 0x896ff
@@ -1071,9 +1068,8 @@ ClearScreenArea: ; 0x896ff
jr nz, .loop
dec hl
-rept 2
inc c
-endr
+ inc c
.asm_89713
ld a, $36
ld [hli], a
@@ -1107,9 +1103,8 @@ Function8971f: ; 8971f
Function89736: ; 89736
push hl
-rept 2
inc hl
-endr
+ inc hl
ld e, c
ld d, $0
add hl, de
@@ -1145,9 +1140,8 @@ Function8975b: ; 8975b
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 @@ Function89b97: ; 89b97 (22:5b97)
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 @@ Function89f77: ; 89f77 (22:5f77)
ld [hli], a
ld a, c
ld [hli], a
-rept 2
inc hl
-endr
+ inc hl
ld a, $8
add c
ld c, a
diff --git a/misc/mobile_22_2.asm b/misc/mobile_22_2.asm
index 880ae460a..616c16ae0 100644
--- a/misc/mobile_22_2.asm
+++ b/misc/mobile_22_2.asm
@@ -314,9 +314,8 @@ Function8b4d8: ; 8b4d8 (22:74d8)
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 @@ Function8b4ea: ; 8b4ea (22:74ea)
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 @@ Function8b73e: ; 8b73e
Function8b744: ; 8b744
ld de, AttrMap - TileMap
add hl, de
-rept 2
inc b
-endr
-rept 2
+ inc b
+ inc c
inc c
-endr
xor a
.asm_8b74d
push bc
@@ -975,9 +971,8 @@ Function8b8c8: ; 8b8c8
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
diff --git a/misc/mobile_41.asm b/misc/mobile_41.asm
index 44db58602..c14a0779f 100755
--- a/misc/mobile_41.asm
+++ b/misc/mobile_41.asm
@@ -609,9 +609,8 @@ _MobilePrintNum:: ; 1061ef
rept 3
inc de
endr
-rept 2
dec a
-endr
+ dec a
.digit_loop
push af
diff --git a/misc/mobile_42.asm b/misc/mobile_42.asm
index a24efd10c..af7953c76 100644
--- a/misc/mobile_42.asm
+++ b/misc/mobile_42.asm
@@ -372,9 +372,8 @@ MobileTradeAnim_JumptableLoop: ; 10824b
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 @@ MobileTradeAnim_GiveTrademon1: ; 108763
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 @@ endr
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 @@ MobileTradeAnim_GetTrademon2: ; 108894
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 @@ endr
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
diff --git a/misc/mobile_45.asm b/misc/mobile_45.asm
index 39d1f46ed..532a8c8cc 100644
--- a/misc/mobile_45.asm
+++ b/misc/mobile_45.asm
@@ -153,9 +153,8 @@ Function114243:: ; 114243
Function11425c: ; 11425c
ld [$dc02], a
pop af
-rept 2
ld [hFF8C], a
-endr
+ ld [hFF8C], a
ld [MBC3SRamBank], a
ret
@@ -632,9 +631,8 @@ Function1144c8: ; 1144c8
Function1144d1: ; 1144d1
call Function114561
-rept 2
dec de
-endr
+ dec de
push de
rept 3
inc de
@@ -1006,9 +1004,8 @@ Function1146a4: ; 1146a4
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 @@ Function1146fa: ; 1146fa
ld a, [$dc0e]
cp $3
jr nz, .asm_114773
-rept 2
dec bc
-endr
+ dec bc
.asm_114773
call Function1149cc
@@ -2069,9 +2065,8 @@ Function114c5e: ; 114c5e
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 @@ endr
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 @@ Function114d99: ; 114d99
add hl, de
ld b, h
ld c, l
-rept 2
inc bc
-endr
+ inc bc
xor a
ret
@@ -2563,9 +2556,8 @@ Function114ee9: ; 114ee9
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 @@ Function1150b3: ; 1150b3
.asm_11510b
pop hl
-rept 2
dec hl
-endr
+ dec hl
push de
call Function1158c2
pop de
@@ -3499,9 +3490,8 @@ Function1153b5: ; 1153b5
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 @@ endr
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 @@ endr
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 @@ Function115b00: ; 115b00
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 @@ Function115bc8: ; 115bc8
ret
.asm_115c33
-rept 2
dec hl
-endr
+ dec hl
xor a
ld [hl], a
ld a, $1
@@ -5406,9 +5392,8 @@ Function11659d: ; 11659d
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 @@ Function117719: ; 117719 (45:7719)
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 @@ Function117ae9: ; 0x117ae9
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
diff --git a/misc/mobile_45_sprite_engine.asm b/misc/mobile_45_sprite_engine.asm
index ab31a9bb9..d0183b2ca 100755
--- a/misc/mobile_45_sprite_engine.asm
+++ b/misc/mobile_45_sprite_engine.asm
@@ -375,9 +375,8 @@ Function1161b8: ; 1161b8
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
diff --git a/misc/mobile_5b.asm b/misc/mobile_5b.asm
index 24f2f9189..eca57e1c8 100755
--- a/misc/mobile_5b.asm
+++ b/misc/mobile_5b.asm
@@ -356,9 +356,8 @@ Function16c943: ; 16c943
call Function16cae8
.asm_16c9e1
-rept 2
inc e
-endr
+ inc e
ld a, e
cp $8
jr nz, .asm_16c969
@@ -459,9 +458,8 @@ Function16ca11: ; 16ca11
call Function16cae8
.asm_16ca88
-rept 2
inc e
-endr
+ inc e
ld a, e
cp $8
jr nz, .asm_16ca28
diff --git a/misc/mobile_5c.asm b/misc/mobile_5c.asm
index 8ecd35edf..fe8432262 100755
--- a/misc/mobile_5c.asm
+++ b/misc/mobile_5c.asm
@@ -111,9 +111,8 @@ Function170c06: ; 170c06
inc [hl]
.asm_170c15
-rept 2
inc hl
-endr
+ inc hl
ld a, [$a89b]
add [hl]
ld [hld], a
@@ -138,9 +137,8 @@ endr
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 @@ Function171a36: ; 171a36 (5c:5a36)
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 @@ Function171ccd: ; 171ccd (5c:5ccd)
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
diff --git a/predef/cgb.asm b/predef/cgb.asm
index addbcb0d5..4c164134b 100644
--- a/predef/cgb.asm
+++ b/predef/cgb.asm
@@ -58,7 +58,7 @@ Predef_LoadSGBLayoutCGB: ; 8d59
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 @@ _CGB13: ; 94d0
ret
; 94fa
-_CGB19: ; 94fa
+_CGB_GamefreakLogo: ; 94fa
ld de, UnknBGPals
ld a, $4e
call GetPredefPal
diff --git a/predef/sgb.asm b/predef/sgb.asm
index c79a173ba..f9e8348d9 100644
--- a/predef/sgb.asm
+++ b/predef/sgb.asm
@@ -75,9 +75,8 @@ Predef_LoadSGBLayout: ; 864c
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 @@ endr
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 @@ endr
ld hl, wSGBPals + 1
ld [hl], $10
-rept 2
inc hl
-endr
+ inc hl
ld a, [PlayerHPPal]
add $2f
@@ -174,9 +171,8 @@ endr
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]
diff --git a/rst.asm b/rst.asm
index ae9158b51..c54dc83e2 100644
--- a/rst.asm
+++ b/rst.asm
@@ -22,9 +22,8 @@ SECTION "rst28",ROM0[JumpTable]
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
diff --git a/sram.asm b/sram.asm
index 676453e93..27c258fa6 100644
--- a/sram.asm
+++ b/sram.asm
@@ -83,7 +83,7 @@ sBackupOptions:: ds OptionsEnd - Options
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 @@ sOptions:: ds OptionsEnd - Options
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
diff --git a/text/types.asm b/text/types.asm
index 7084b58eb..adc1b17ef 100644
--- a/text/types.asm
+++ b/text/types.asm
@@ -85,9 +85,8 @@ GetTypeName: ; 50964
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
diff --git a/tilesets/animations.asm b/tilesets/animations.asm
index 289638299..a4af6cbc0 100644
--- a/tilesets/animations.asm
+++ b/tilesets/animations.asm
@@ -16,9 +16,8 @@ _AnimateTileset:: ; fc000
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 @@ SafariFountainAnim1: ; fc5cc
ld a, [TileAnimationTimer]
and 6
srl a
-rept 2
inc a
-endr
+ inc a
and 3
swap a
ld e, a
diff --git a/trainers/dvs.asm b/trainers/dvs.asm
index 1169785d6..2975d60fe 100644
--- a/trainers/dvs.asm
+++ b/trainers/dvs.asm
@@ -8,9 +8,8 @@ GetTrainerDVs: ; 270c4
ld b, 0
ld hl, TrainerClassDVs
-rept 2
add hl, bc
-endr
+ add hl, bc
ld a, [hli]
ld b, a
diff --git a/trainers/read_party.asm b/trainers/read_party.asm
index af4e63cb9..1f4ec1c9b 100755
--- a/trainers/read_party.asm
+++ b/trainers/read_party.asm
@@ -32,9 +32,8 @@ ReadTrainerParty: ; 39771
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 @@ endr
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 @@ GetTrainerName:: ; 3994c
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
diff --git a/wram.asm b/wram.asm
index 11e86f2f0..ca877e5ab 100644
--- a/wram.asm
+++ b/wram.asm
@@ -2661,7 +2661,7 @@ wWhichMomItem:: ds 1 ; dc17
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 @@ FruitTreeFlags:: flag_array NUM_FRUIT_TREES ; dc27
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