diff --git a/Makefile b/Makefile index 2b6aa311a..00c634b3e 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,8 @@ PNG_GFX := $(shell find gfx/ -type f -name '*.png') LZ_GFX := $(shell find gfx/ -type f -name '*.lz') TWOBPP_GFX := $(shell find gfx/ -type f -name '*.2bpp') -all: pokecrystal.gbc - cmp baserom.gbc $< +all: baserom.gbc pokecrystal.gbc + cmp baserom.gbc pokecrystal.gbc clean: rm -f pokecrystal.o pokecrystal.gbc @echo 'rm -f $(TEXTFILES:.asm=.tx)' @@ -19,6 +19,8 @@ pokecrystal.o: $(TEXTFILES:.asm=.tx) wram.asm constants.asm $(shell find constan .asm.tx: $(eval TEXTQUEUE := $(TEXTQUEUE) $<) @rm -f $@ +baserom.gbc: + python -c "import os; assert 'baserom.gbc' in os.listdir('.'), 'Wait! Need baserom.gbc first. Check README and INSTALL for details.';" pokecrystal.gbc: pokecrystal.o rgblink -n pokecrystal.sym -m pokecrystal.map -o $@ $< diff --git a/battle/ai/scoring.asm b/battle/ai/scoring.asm index b48e04bc6..3ad219851 100644 --- a/battle/ai/scoring.asm +++ b/battle/ai/scoring.asm @@ -129,7 +129,7 @@ AIScoring_RedStatMods: ; 385e0 jr .checkmove .discourage - call RNG + call Random cp 30 jr c, .checkmove inc [hl] @@ -430,7 +430,7 @@ AIScoring_LeechHit: ; 387f7 ret .asm_38815 - call RNG + call Random cp $64 ret c @@ -575,7 +575,7 @@ AIScoring_Explosion: ; 388a6 call AICheckEnemyQuarterHP ret nc - call RNG + call Random cp 20 ret c @@ -588,7 +588,7 @@ AIScoring_Explosion: ; 388a6 AIScoring_DreamEater: ; 388ca - call RNG + call Random cp $19 ret c @@ -612,7 +612,7 @@ AIScoring_EvasionUp: ; 388d4 bit 0, a jr nz, .asm_388ef - call RNG + call Random cp $b2 jr nc, .asm_38911 @@ -628,7 +628,7 @@ AIScoring_EvasionUp: ; 388d4 jr nc, .asm_3890f - call RNG + call Random cp $a jr c, .asm_388ef @@ -683,7 +683,7 @@ AIScoring_EvasionUp: ; 388d4 ret .asm_38938 - call RNG + call Random cp $50 ret c dec [hl] @@ -744,7 +744,7 @@ AIScoring_MirrorMove: ; 3895b call AICompareSpeed ret nc - call RNG + call Random cp $19 ret c @@ -766,7 +766,7 @@ AIScoring_AccuracyDown: ; 38985 bit 0, a jr nz, .asm_3899d - call RNG + call Random cp $b2 jr nc, .asm_389bf @@ -782,7 +782,7 @@ AIScoring_AccuracyDown: ; 38985 jr nc, .asm_389bd - call RNG + call Random cp $a jr c, .asm_3899d @@ -837,7 +837,7 @@ AIScoring_AccuracyDown: ; 38985 ret .asm_389e6 - call RNG + call Random cp $50 ret c dec [hl] @@ -878,7 +878,7 @@ AIScoring_Haze: ; 389f5 .asm_38a12 pop hl - call RNG + call Random cp $28 ret c dec [hl] @@ -894,7 +894,7 @@ AIScoring_Haze: ; 389f5 AIScoring_Bide: ; 38a1e call AICheckEnemyMaxHP ret c - call RNG + call Random cp $19 ret c inc [hl] @@ -926,7 +926,7 @@ AIScoring_Moonlight: ; 38a3a ret .asm_38a45 - call RNG + call Random cp $19 ret c dec [hl] @@ -948,7 +948,7 @@ AIScoring_LightScreen: AIScoring_Reflect: ; 38a54 call AICheckEnemyMaxHP ret c - call RNG + call Random cp $14 ret c inc [hl] @@ -1041,7 +1041,7 @@ AIScoring_Unused2B: ; 38a9c ret c .asm_38acd - call RNG + call Random cp $c8 ret c @@ -1061,7 +1061,7 @@ AIScoring_Unused2B: ; 38a9c AIScoring_Confuse: ; 38adb call AICheckPlayerHalfHP ret c - call RNG + call Random cp $19 jr c, .asm_38ae7 inc [hl] @@ -1156,7 +1156,7 @@ AIScoring_SpeedDownHit: ; 38b40 ret nz call AICompareSpeed ret c - call RNG + call Random cp 30 ret c dec [hl] @@ -1183,7 +1183,7 @@ AIScoring_HyperBeam: ; 38b63 ret .asm_38b72 - call RNG + call Random cp 40 ret c inc [hl] @@ -1334,7 +1334,7 @@ AIScoring_Counter: ; 38bf1 .asm_38c30 - call RNG + call Random cp $64 jr c, .asm_38c38 @@ -1388,7 +1388,7 @@ AIScoring_Encore: ; 38c3b jr nc, .asm_38c81 .asm_38c78 - call RNG + call Random cp $46 ret c dec [hl] @@ -1527,7 +1527,7 @@ AIScoring_Spite: ; 38cd5 cp $f jr nc, .asm_38d0b - call RNG + call Random cp $64 ret nc @@ -1536,7 +1536,7 @@ AIScoring_Spite: ; 38cd5 ret .asm_38d0d - call RNG + call Random cp $64 ret c dec [hl] @@ -1700,7 +1700,7 @@ AIScoring_Conversion2: ; 38d98 ret .asm_38dc9 - call RNG + call Random cp $19 ret c @@ -1722,7 +1722,7 @@ AIScoring_Disable: ; 38dd1 pop hl jr nc, .asm_38dee - call RNG + call Random cp 100 ret c dec [hl] @@ -1734,7 +1734,7 @@ AIScoring_Disable: ; 38dd1 ret nz .asm_38df3 - call RNG + call Random cp 20 ret c inc [hl] @@ -1961,7 +1961,7 @@ AIScoring_Protect: ; 38ed2 inc [hl] .asm_38f14 - call RNG + call Random cp 20 ret c inc [hl] @@ -1985,14 +1985,14 @@ AIScoring_Foresight: ; 38f1d cp GHOST jr z, .asm_38f41 - call RNG + call Random cp 20 ret c inc [hl] ret .asm_38f41 - call RNG + call Random cp 100 ret c dec [hl] @@ -2169,7 +2169,7 @@ AIScoring_Rollout: ; 38fef cp 8 jr nc, .asm_39020 - call RNG + call Random cp 200 ret nc dec [hl] @@ -2196,7 +2196,7 @@ AIScoring_Attract: ; 39026 ret .asm_39032 - call RNG + call Random cp 200 ret nc dec [hl] @@ -2558,7 +2558,7 @@ AIScoring_MirrorCoat: ; 3918b .asm_391ca - call RNG + call Random cp 100 jr c, .asm_391d2 dec [hl] @@ -2634,7 +2634,7 @@ AIScoring_Solarbeam: ; 3920b cp WEATHER_RAIN ret nz - call RNG + call Random cp 25 ; 1/10 ret c @@ -2657,7 +2657,7 @@ AIScoring_Thunder: ; 39225 cp WEATHER_SUN ret nz - call RNG + call Random cp 25 ; 1/10 ret c @@ -3150,7 +3150,7 @@ AIScoring_Cautious: ; 39418 pop hl jr nc, .asm_39425 - call RNG + call Random cp 230 ret nc @@ -3274,7 +3274,7 @@ AIScoring_Risky: ; 394a9 call AICheckEnemyMaxHP jr c, .nextmove - call RNG + call Random cp 200 ; 1/5 jr c, .nextmove @@ -3347,14 +3347,14 @@ AIGetEnemyMove: ; 39508 Function_0x39521: ; 39521 - call RNG + call Random cp 50 ; 1/5 ret ; 39527 Function_0x39527: ; 39527 - call RNG + call Random cp $80 ; 1/2 ret ; 3952d diff --git a/battle/effect_commands.asm b/battle/effect_commands.asm index afe822a16..94b54c0bd 100644 --- a/battle/effect_commands.asm +++ b/battle/effect_commands.asm @@ -154,7 +154,7 @@ CheckPlayerTurn: ; 'must recharge!' ld hl, MustRechargeText - call FarBattleTextBox + call StdBattleTextBox call CantMove jp Function0x34385 @@ -179,7 +179,7 @@ CheckPlayerTurn: .WokeUp ; 'woke up!' ld hl, WokeUpText - call FarBattleTextBox + call StdBattleTextBox call CantMove call UpdateBattleMonInParty @@ -195,7 +195,7 @@ CheckPlayerTurn: .FastAsleep ; 'fast asleep!' ld hl, FastAsleepText - call FarBattleTextBox + call StdBattleTextBox ; Snore and Sleep Talk bypass sleep. ld a, [CurPlayerMove] @@ -221,7 +221,7 @@ CheckPlayerTurn: ; 'frozen solid!' ld hl, FrozenSolidText - call FarBattleTextBox + call StdBattleTextBox call CantMove jp Function0x34385 @@ -236,7 +236,7 @@ CheckPlayerTurn: ; 'flinched!' ld hl, FlinchedText - call FarBattleTextBox + call StdBattleTextBox call CantMove jp Function0x34385 @@ -256,7 +256,7 @@ CheckPlayerTurn: ; 'disabled no more!' ld hl, DisabledNoMoreText - call FarBattleTextBox + call StdBattleTextBox .CheckConfused @@ -272,7 +272,7 @@ CheckPlayerTurn: ; 'confused no more!' ld hl, ConfusedNoMoreText - call FarBattleTextBox + call StdBattleTextBox jr .CheckAttract @@ -280,7 +280,7 @@ CheckPlayerTurn: .Confused ; 'confused!' ld hl, IsConfusedText - call FarBattleTextBox + call StdBattleTextBox xor a ld [$cfca], a @@ -288,7 +288,7 @@ CheckPlayerTurn: call FarPlayBattleAnimation ; 50% chance of hitting itself - call FarBattleRNG + call BattleRandom cp $80 jr nc, .CheckAttract @@ -310,7 +310,7 @@ CheckPlayerTurn: ; 'in love with' ld hl, InLoveWithText - call FarBattleTextBox + call StdBattleTextBox xor a ld [$cfca], a @@ -319,13 +319,13 @@ CheckPlayerTurn: call FarPlayBattleAnimation ; 50% chance of infatuation - call FarBattleRNG + call BattleRandom cp $80 jr c, .CheckDisabledMove ; 'infatuation kept it from attacking!' ld hl, InfatuationText - call FarBattleTextBox + call StdBattleTextBox call CantMove jp Function0x34385 @@ -353,13 +353,13 @@ CheckPlayerTurn: ret z ; 25% chance to be fully paralyzed - call FarBattleRNG + call BattleRandom cp $3f ret nc ; 'fully paralyzed!' ld hl, FullyParalyzedText - call FarBattleTextBox + call StdBattleTextBox call CantMove jp Function0x34385 ; 341f0 @@ -412,7 +412,7 @@ CheckEnemyTurn: ; 3421f ; 'must recharge!' ld hl, MustRechargeText - call FarBattleTextBox + call StdBattleTextBox call CantMove jp Function0x34385 @@ -429,7 +429,7 @@ CheckEnemyTurn: ; 3421f ; 'fast asleep!' ld hl, FastAsleepText - call FarBattleTextBox + call StdBattleTextBox xor a ld [$cfca], a ld de, ANIM_SLEEP @@ -440,7 +440,7 @@ CheckEnemyTurn: ; 3421f .WokeUp ; 'woke up!' ld hl, WokeUpText - call FarBattleTextBox + call StdBattleTextBox call CantMove call UpdateEnemyMonInParty ld hl, $6036 @@ -475,7 +475,7 @@ CheckEnemyTurn: ; 3421f ; 'frozen solid!' ld hl, FrozenSolidText - call FarBattleTextBox + call StdBattleTextBox call CantMove jp Function0x34385 @@ -489,7 +489,7 @@ CheckEnemyTurn: ; 3421f ; 'flinched!' ld hl, FlinchedText - call FarBattleTextBox + call StdBattleTextBox call CantMove jp Function0x34385 @@ -511,7 +511,7 @@ CheckEnemyTurn: ; 3421f ; 'disabled no more!' ld hl, DisabledNoMoreText - call FarBattleTextBox + call StdBattleTextBox .CheckConfused @@ -528,7 +528,7 @@ CheckEnemyTurn: ; 3421f ; 'confused no more!' ld hl, ConfusedNoMoreText - call FarBattleTextBox + call StdBattleTextBox jr .CheckAttract @@ -536,7 +536,7 @@ CheckEnemyTurn: ; 3421f .Confused ; 'confused!' ld hl, IsConfusedText - call FarBattleTextBox + call StdBattleTextBox xor a ld [$cfca], a @@ -544,7 +544,7 @@ CheckEnemyTurn: ; 3421f call FarPlayBattleAnimation ; 50% chance of hitting itself - call FarBattleRNG + call BattleRandom cp $80 jr nc, .CheckAttract @@ -555,7 +555,7 @@ CheckEnemyTurn: ; 3421f ; 'hurt itself in its confusion!' ld hl, HurtItselfText - call FarBattleTextBox + call StdBattleTextBox call Function0x355dd @@ -589,7 +589,7 @@ CheckEnemyTurn: ; 3421f ; 'in love with' ld hl, InLoveWithText - call FarBattleTextBox + call StdBattleTextBox xor a ld [$cfca], a @@ -598,13 +598,13 @@ CheckEnemyTurn: ; 3421f call FarPlayBattleAnimation ; 50% chance of infatuation - call FarBattleRNG + call BattleRandom cp $80 jr c, .CheckDisabledMove ; 'infatuation kept it from attacking!' ld hl, InfatuationText - call FarBattleTextBox + call StdBattleTextBox call CantMove jp Function0x34385 @@ -633,13 +633,13 @@ CheckEnemyTurn: ; 3421f ret z ; 25% chance to be fully paralyzed - call FarBattleRNG + call BattleRandom cp $3f ret nc ; 'fully paralyzed!' ld hl, FullyParalyzedText - call FarBattleTextBox + call StdBattleTextBox call CantMove @@ -668,7 +668,7 @@ MoveDisabled: ; 3438d ; 'disabled!' ld hl, DisabledMoveText - jp FarBattleTextBox + jp StdBattleTextBox ; 343a5 @@ -676,7 +676,7 @@ HitConfusion: ; 343a5 ; 'hurt itself in its confusion!' ld hl, HurtItselfText - call FarBattleTextBox + call StdBattleTextBox xor a ld [CriticalHit], a @@ -808,7 +808,7 @@ BattleCommand02: ; 343db ; Random number from 0 to obedience level + monster level .rand1 - call FarBattleRNG + call BattleRandom swap a cp b jr nc, .rand1 @@ -826,7 +826,7 @@ BattleCommand02: ; 343db ; Another random number from 0 to obedience level + monster level .rand2 - call FarBattleRNG + call BattleRandom cp b jr nc, .rand2 @@ -843,7 +843,7 @@ BattleCommand02: ; 343db ld b, a ; The chance of napping is the difference out of 256. - call FarBattleRNG + call BattleRandom swap a sub b jr c, .Nap @@ -854,7 +854,7 @@ BattleCommand02: ; 343db ; 'won't obey!' ld hl, WontObeyText - call FarBattleTextBox + call StdBattleTextBox call HitConfusion @@ -862,7 +862,7 @@ BattleCommand02: ; 343db .Nap - call FarBattleRNG + call BattleRandom add a swap a and 7 @@ -876,7 +876,7 @@ BattleCommand02: ; 343db .DoNothing - call FarBattleRNG + call BattleRandom and 3 ; 'loafing around!' @@ -898,7 +898,7 @@ BattleCommand02: ; 343db ld hl, IgnoredOrdersText .Print - call FarBattleTextBox + call StdBattleTextBox jp Function0x3450c @@ -964,7 +964,7 @@ BattleCommand02: ; 343db .RandomMove - call FarBattleRNG + call BattleRandom and 3 cp b @@ -1043,7 +1043,7 @@ IgnoreSleepOnly: ; 3451f ; 'ignored orders…sleeping!' ld hl, IgnoredSleepingText - call FarBattleTextBox + call StdBattleTextBox call EndMoveEffect @@ -1192,7 +1192,7 @@ BattleCommand04: ; 34555 ; 'but no pp is left for the move' ld hl, NoPPLeftText .print - call FarBattleTextBox + call StdBattleTextBox ld b, 1 ret ; 34602 @@ -1324,7 +1324,7 @@ BattleCommand05: ; 34631 ld hl, .Chances ld b, 0 add hl, bc - call FarBattleRNG + call BattleRandom cp [hl] ret nc ld a, 1 @@ -2338,7 +2338,7 @@ BattleCommand08: ; 34cfd ; Multiply by 85-100%... .loop - call FarBattleRNG + call BattleRandom rrca cp $d9 ; 85% jr c, .loop @@ -2423,7 +2423,7 @@ BattleCommand09: ; 34d32 cp $ff jr z, .Hit - call FarBattleRNG + call BattleRandom cp b jr nc, .Miss @@ -2471,7 +2471,7 @@ BattleCommand09: ; 34d32 ; 'protecting itself!' ld hl, ProtectingItselfText - call FarBattleTextBox + call StdBattleTextBox ld c, 40 call DelayFrames @@ -2701,7 +2701,7 @@ BattleCommand90: ; 34ecc ld hl, EnemyMoveEffectChance .asm_34ee1 - call FarBattleRNG + call BattleRandom cp [hl] pop hl ret c @@ -2986,7 +2986,7 @@ BattleCommand0e: ; 3505e cp HELD_FOCUS_BAND ld b, $0 jr nz, .asm_3508b ; 3507a $f - call FarBattleRNG + call BattleRandom cp c jr nc, .asm_3508b ; 35080 $9 call BattleCommand4b @@ -3014,7 +3014,7 @@ BattleCommand0e: ; 3505e dec a jr nz, .asm_350ab ; 350a3 $6 ld hl, EnduredText - jp FarBattleTextBox + jp StdBattleTextBox .asm_350ab call GetOpponentItem @@ -3023,7 +3023,7 @@ BattleCommand0e: ; 3505e call GetItemName ld hl, HungOnText - jp FarBattleTextBox + jp StdBattleTextBox .asm_50bb ld a, BATTLE_VARS_SUBSTATUS4_OPP @@ -3105,7 +3105,7 @@ Function0x350e4: ; 350e4 ld [hl], a .asm_3513e ld hl, CrashedText - call FarBattleTextBox + call StdBattleTextBox ld a, $1 ld [$c689], a call Function0x37e36 @@ -3123,7 +3123,7 @@ Function0x35157: ; 35157 ld h, d ld l, e .asm_35162 - jp FarBattleTextBox + jp StdBattleTextBox ; 35165 @@ -3157,7 +3157,7 @@ BattleCommand0f: ; 35175 ld a, [hli] ld h, [hl] ld l, a - call FarBattleTextBox + call StdBattleTextBox xor a ld [CriticalHit], a @@ -3211,7 +3211,7 @@ BattleCommand10: ; 351ad jr nc, .print ld hl, NotVeryEffectiveText ; 'not very effective' .print - jp FarBattleTextBox + jp StdBattleTextBox ; 351c0 @@ -3237,7 +3237,7 @@ BattleCommand11: ; 351c0 jr z, .asm_35231 ld hl, TookDownWithItText - call FarBattleTextBox + call StdBattleTextBox ld a, [hBattleTurn] and a @@ -3332,7 +3332,7 @@ BattleCommand12: ; 35250 call SwitchTurn ld hl, RageBuildingText - call FarBattleTextBox + call StdBattleTextBox jp SwitchTurn ; 3527b @@ -3822,7 +3822,7 @@ BattleCommanda1: ; 35461 ld a, $1 ld [$c72d], a ld hl, BeatUpAttackText - call FarBattleTextBox + call StdBattleTextBox ld a, [EnemyMonSpecies] ld [CurSpecies], a call $3856 @@ -3923,11 +3923,11 @@ BattleCommanda1: ; 35461 ld [$d265], a call $343b ld hl, BeatUpAttackText - call FarBattleTextBox + call StdBattleTextBox jp EnemyAttackDamage .asm_3557d ld hl, BeatUpAttackText - call FarBattleTextBox + call StdBattleTextBox ld a, [BattleMonSpecies] ld [CurSpecies], a call GetBaseData @@ -4332,7 +4332,7 @@ BattleCommand3f: ; 35726 add b ld b, a .asm_3575d - call FarBattleRNG + call BattleRandom and a jr z, .asm_3575d ; 35761 $fa cp b @@ -4555,7 +4555,7 @@ BattleCommand41: ; 35864 bit 4, [hl] jp nz, Function0x35923 set 4, [hl] - call FarBattleRNG + call BattleRandom and $3 inc a inc a @@ -4626,7 +4626,7 @@ BattleCommand41: ; 35864 call Function0x37e01 ld hl, GotAnEncoreText - jp FarBattleTextBox + jp StdBattleTextBox ; 35923 @@ -4673,7 +4673,7 @@ BattleCommand42: ; 35926 rst FarCall ld hl, SharedPainText - jp FarBattleTextBox + jp StdBattleTextBox .asm_3597d ld a, [hld] @@ -4782,7 +4782,7 @@ BattleCommand44: ; 359e6 call SwitchTurn .asm_35a13 - call FarBattleRNG + call BattleRandom and $1f cp $a jr c, .asm_35a24 ; 35a1a $8 @@ -4815,7 +4815,7 @@ BattleCommand44: ; 359e6 ld a, $29 call Predef ld hl, $5452 - jp FarBattleTextBox + jp StdBattleTextBox .asm_35a50 jp Function0x37354 ; 35a53 @@ -4835,7 +4835,7 @@ BattleCommand45: ; 35a53 call Function0x37e01 ld hl, TookAimText - jp FarBattleTextBox + jp StdBattleTextBox .asm_35a6e call Function0x37e77 @@ -4938,7 +4938,7 @@ BattleCommand46: ; 35a74 call Function0x37e01 ld hl, SketchedText - jp FarBattleTextBox + jp StdBattleTextBox .asm_35b10 call Function0x37e77 @@ -5005,7 +5005,7 @@ BattleCommand48: ; 35b33 dec hl .asm_35b62 push hl - call FarBattleRNG + call BattleRandom and $3 ld c, a ld b, $0 @@ -5131,7 +5131,7 @@ BattleCommand49: ; 35bff set 6, [hl] call Function0x37e01 ld hl, DestinyBondEffectText - jp FarBattleTextBox + jp StdBattleTextBox ; 35c0f @@ -5173,7 +5173,7 @@ BattleCommand4a: ; 35c0f jr z, .asm_35c91 ; 35c46 $49 push bc call GetMoveName - call FarBattleRNG + call BattleRandom and $3 inc a inc a @@ -5216,7 +5216,7 @@ BattleCommand4a: ; 35c0f ld a, d ld [$d265], a ld hl, SpiteEffectText - jp FarBattleTextBox + jp StdBattleTextBox .asm_35c91 jp PrintDidntAffect2 ; 35c94 @@ -5294,7 +5294,7 @@ BattleCommand4c: ; 35cc9 call Function0x37e01 ld hl, BellChimedText - call FarBattleTextBox + call StdBattleTextBox ld a, [hBattleTurn] and a @@ -5452,7 +5452,7 @@ Function0x35d7e: ; 35d7e Function0x35de0: ; 35de0 ld hl, SubTookDamageText - call FarBattleTextBox + call StdBattleTextBox ld de, $c6e0 ld a, [hBattleTurn] @@ -5479,7 +5479,7 @@ Function0x35de0: ; 35de0 res 4, [hl] ld hl, SubFadedText - call FarBattleTextBox + call StdBattleTextBox call SwitchTurn call BattleCommanda7 @@ -5576,7 +5576,7 @@ BattleCommand14: ; 35e5c ld b, $3 .asm_35ea4 - call FarBattleRNG + call BattleRandom and b jr z, .asm_35ea4 cp 7 @@ -5587,7 +5587,7 @@ BattleCommand14: ; 35e5c call RefreshBattleHuds ld hl, FellAsleepText - call FarBattleTextBox + call StdBattleTextBox ld a, $f ld hl, $5de9 @@ -5600,7 +5600,7 @@ BattleCommand14: ; 35e5c push hl call Function0x37e77 pop hl - jp FarBattleTextBox + jp StdBattleTextBox ; 35ece @@ -5625,7 +5625,7 @@ Function0x35ece: ; 35ece bit 5, a jr nz, .asm_35eec - call FarBattleRNG + call BattleRandom cp $40 ret c @@ -5664,7 +5664,7 @@ BattleCommand13: ; 35eee call RefreshBattleHuds ld hl, WasPoisonedText - call FarBattleTextBox + call StdBattleTextBox ld a, $f ld hl, $5de9 @@ -5715,7 +5715,7 @@ BattleCommand2f: ; 35f2c ld a, [PlayerSubStatus5] bit 5, a jr nz, .asm_35f89 ; 35f80 $7 - call FarBattleRNG + call BattleRandom cp $40 jr c, .asm_35fb8 ; 35f87 $2f .asm_35f89 @@ -5729,7 +5729,7 @@ BattleCommand2f: ; 35f2c call Function0x35fc0 ld hl, WasPoisonedText - call FarBattleTextBox + call StdBattleTextBox jr .asm_35fb1 ; 35fa2 $d .asm_35fa4 @@ -5739,7 +5739,7 @@ BattleCommand2f: ; 35f2c call Function0x35fc0 ld hl, BadlyPoisonedText - call FarBattleTextBox + call StdBattleTextBox .asm_35fb1 ld a, $f @@ -5751,7 +5751,7 @@ BattleCommand2f: ; 35f2c push hl call Function0x37e77 pop hl - jp FarBattleTextBox + jp StdBattleTextBox ; 35fc0 @@ -5807,7 +5807,7 @@ BattleCommand15: ; 35fff ; draintarget call Function0x36011 ld hl, SuckedHealthText - jp FarBattleTextBox + jp StdBattleTextBox ; 36008 @@ -5815,7 +5815,7 @@ BattleCommand16: ; 36008 ; eatdream call Function0x36011 ld hl, DreamEatenText - jp FarBattleTextBox + jp StdBattleTextBox ; 36011 @@ -5938,7 +5938,7 @@ BattleCommand17: ; 3608c call RefreshBattleHuds ld hl, WasBurnedText - call FarBattleTextBox + call StdBattleTextBox ld a, $f ld hl, $5de9 @@ -5970,7 +5970,7 @@ Defrost: ; 360dd call UpdateOpponentInParty ld hl, DefrostedOpponentText - jp FarBattleTextBox + jp StdBattleTextBox ; 36102 @@ -6011,7 +6011,7 @@ BattleCommand18: ; 36102 call RefreshBattleHuds ld hl, WasFrozenText - call FarBattleTextBox + call StdBattleTextBox ld a, $f ld hl, $5de9 @@ -6375,7 +6375,7 @@ BattleCommand1d: ; 362e3 cp EFFECT_ACCURACY_DOWN_HIT jr z, .DidntMiss - call FarBattleRNG + call BattleRandom cp $40 jr c, .Failed @@ -6596,7 +6596,7 @@ BattleCommand8e: ; 3644c inc b call GetStatName ld hl, WontRiseAnymoreText - jp FarBattleTextBox + jp StdBattleTextBox ; 3646a @@ -6612,14 +6612,14 @@ BattleCommand8f: ; 3646a jp z, TryPrintButItFailed dec a ld hl, ProtectedByMistText - jp z, FarBattleTextBox + jp z, StdBattleTextBox ld a, [LoweredStat] and $f ld b, a inc b call GetStatName ld hl, WontDropAnymoreText - jp FarBattleTextBox + jp StdBattleTextBox ; 3648f @@ -6789,7 +6789,7 @@ BattleCommandac: ; 3658f ; 1/3 chance of each status .loop - call FarBattleRNG + call BattleRandom swap a and 3 jr z, .loop @@ -6972,7 +6972,7 @@ BattleCommand21: ; 36671 res 0, [hl] ld hl, UnleashedEnergyText - call FarBattleTextBox + call StdBattleTextBox ld a, BATTLE_VARS_MOVE_POWER call GetBattleVarPair @@ -7018,7 +7018,7 @@ BattleCommand21: ; 36671 .asm_366dc ld hl, StoringEnergyText - call FarBattleTextBox + call StdBattleTextBox jp EndMoveEffect ; 366e5 @@ -7043,7 +7043,7 @@ BattleCommand22: ; 366e5 ld [de], a ld [PlayerMoveEffect], a ld [EnemyMoveEffect], a - call FarBattleRNG + call BattleRandom and $1 inc a inc a @@ -7080,7 +7080,7 @@ BattleCommand3e: ; 3671a pop af jr nz, .asm_3674c ; 3673f $b set 7, [hl] - call FarBattleRNG + call BattleRandom and $1 inc a inc a @@ -7110,7 +7110,7 @@ BattleCommand3d: ; 36751 ld a, BATTLE_VARS_SUBSTATUS3 call GetBattleVarPair set 1, [hl] - call FarBattleRNG + call BattleRandom and $1 inc a ld [de], a @@ -7152,7 +7152,7 @@ BattleCommanda0: ; 36778 ld c, a inc c .asm_367ac - call FarBattleRNG + call BattleRandom cp c jr nc, .asm_367ac ; 367b0 $fa srl b @@ -7177,7 +7177,7 @@ BattleCommanda0: ; 36778 ld c, a inc c .asm_367d2 - call FarBattleRNG + call BattleRandom cp c jr nc, .asm_367d2 ; 367d6 $fa srl b @@ -7199,7 +7199,7 @@ BattleCommanda0: ; 36778 call Function0x36804 ld hl, FledFromBattleText - jp FarBattleTextBox + jp StdBattleTextBox ; 36804 @@ -7242,7 +7242,7 @@ BattleCommand23: ; 3680f ld c, a inc c .asm_36845 - call FarBattleRNG + call BattleRandom cp c jr nc, .asm_36845 ; 36849 $fa srl b @@ -7282,7 +7282,7 @@ BattleCommand23: ; 3680f ld a, [CurOTMon] ld c, a .asm_3689a - call FarBattleRNG + call BattleRandom and $7 cp b jr nc, .asm_3689a ; 368a0 $f8 @@ -7305,7 +7305,7 @@ BattleCommand23: ; 3680f rst FarCall ld hl, DraggedOutText - call FarBattleTextBox + call StdBattleTextBox ld hl, $5c23 jp CallBankF @@ -7332,7 +7332,7 @@ BattleCommand23: ; 3680f ld c, a inc c .asm_368e6 - call FarBattleRNG + call BattleRandom cp c jr nc, .asm_368e6 @@ -7378,7 +7378,7 @@ BattleCommand23: ; 3680f ld a, [CurBattleMon] ld c, a .asm_3693a - call FarBattleRNG + call BattleRandom and $7 cp b jr nc, .asm_3693a @@ -7402,7 +7402,7 @@ BattleCommand23: ; 3680f call CallBankF ld hl, DraggedOutText - call FarBattleTextBox + call StdBattleTextBox ld hl, $5c23 jp CallBankF @@ -7428,7 +7428,7 @@ BattleCommand23: ; 3680f jr z, .asm_36991 ld hl, BlownAwayText .asm_36991 - jp FarBattleTextBox + jp StdBattleTextBox ; 36994 @@ -7496,7 +7496,7 @@ BattleCommand24: ; 369b6 cp EFFECT_TRIPLE_KICK jr nz, .asm_36a2b .asm_369ec - call FarBattleRNG + call BattleRandom and $3 jr z, .asm_369ec dec a @@ -7530,11 +7530,11 @@ BattleCommand24: ; 369b6 call BattleCommanda8 jp EndMoveEffect .asm_36a2b - call FarBattleRNG + call BattleRandom and $3 cp $2 jr c, .asm_36a39 ; 36a32 $5 - call FarBattleRNG + call BattleRandom and $3 .asm_36a39 inc a @@ -7569,7 +7569,7 @@ BattleCommand24: ; 369b6 call CleanGetBattleVarPair cp EFFECT_BEAT_UP jr z, .asm_36a67 - call FarBattleTextBox + call StdBattleTextBox .asm_36a67 pop bc @@ -7670,7 +7670,7 @@ BattleCommand4d: ; 36ac9 ld d, h ld e, l call GetUserItem - call FarBattleRNG + call BattleRandom cp c ret nc call EndRechargeOpp @@ -7767,7 +7767,7 @@ BattleCommand39: ; 36b4d ld hl, IgnoredOrders2Text ld a, [AlreadyDisobeyed] and a - call nz, FarBattleTextBox + call nz, StdBattleTextBox call BattleCommand0a xor a @@ -7917,7 +7917,7 @@ BattleCommand3b: ; 36c2d call CleanGetBattleVarPair bit 4, a ret nz - call FarBattleRNG + call BattleRandom and 3 inc a inc a @@ -7941,7 +7941,7 @@ BattleCommand3b: ; 36c2d ld a, [hli] ld h, [hl] ld l, a - jp FarBattleTextBox + jp StdBattleTextBox .Traps dbw BIND, UsedBindText ; 'used BIND on' @@ -7962,7 +7962,7 @@ BattleCommand28: ; 36c7e set 1, [hl] call Function0x37e01 ld hl, MistText - jp FarBattleTextBox + jp StdBattleTextBox .asm_36c92 call Function0x37e77 jp PrintButItFailed @@ -7979,7 +7979,7 @@ BattleCommand29: ; 36c98 set 2, [hl] call Function0x37e01 ld hl, GettingPumpedText - jp FarBattleTextBox + jp StdBattleTextBox .asm_36cac call Function0x37e77 jp PrintButItFailed @@ -8048,7 +8048,7 @@ BattleCommand27: ; 36cb2 call Predef call RefreshBattleHuds ld hl, RecoilText - jp FarBattleTextBox + jp StdBattleTextBox ; 36d1d @@ -8085,7 +8085,7 @@ BattleCommand2a: ; 36d3b call GetItemName call Function0x37e77 ld hl, ProtectedByText - jp FarBattleTextBox + jp StdBattleTextBox .asm_36d53 ld a, BATTLE_VARS_SUBSTATUS3_OPP @@ -8094,7 +8094,7 @@ BattleCommand2a: ; 36d3b jr z, .asm_36d65 call Function0x37e77 ld hl, AlreadyConfusedText - jp FarBattleTextBox + jp StdBattleTextBox .asm_36d65 call CheckSubstituteOpp @@ -8116,7 +8116,7 @@ Function0x36d70: ; 36d70 .asm_36d7b set 7, [hl] - call FarBattleRNG + call BattleRandom and 3 inc a inc a @@ -8137,7 +8137,7 @@ Function0x36d70: ; 36d70 call Function0x37e54 ld hl, BecameConfusedText - call FarBattleTextBox + call StdBattleTextBox call GetOpponentItem ld a, b @@ -8182,7 +8182,7 @@ BattleCommand30: ; 36dc7 call GetItemName call Function0x37e77 ld hl, ProtectedByText - jp FarBattleTextBox + jp StdBattleTextBox .asm_36def ld a, [hBattleTurn] and a @@ -8196,7 +8196,7 @@ BattleCommand30: ; 36dc7 ld a, [PlayerSubStatus5] bit 5, a jr nz, .asm_36e0e ; 36e05 $7 - call FarBattleRNG + call BattleRandom cp $40 jr c, .asm_36e52 ; 36e0c $44 .asm_36e0e @@ -8227,7 +8227,7 @@ BattleCommand30: ; 36dc7 .asm_36e49 call Function0x37e77 ld hl, AlreadyParalyzedText - jp FarBattleTextBox + jp StdBattleTextBox .asm_36e52 jp PrintDidntAffect2 .asm_36e55 @@ -8338,7 +8338,7 @@ BattleCommand31: ; 36e7c call BattleCommanda6 .asm_36eeb ld hl, MadeSubstituteText - call FarBattleTextBox + call StdBattleTextBox jp RefreshBattleHuds .asm_36ef4 call Function0x34548 @@ -8350,7 +8350,7 @@ BattleCommand31: ; 36e7c call nz, BattleCommand0c ld hl, TooWeakSubText .asm_36f08 - jp FarBattleTextBox + jp StdBattleTextBox ; 36f0b BattleCommand32: ; 36f0b @@ -8463,7 +8463,7 @@ BattleCommand33: ; 36f46 call GetMoveName call Function0x37e01 ld hl, LearnedMoveText - jp FarBattleTextBox + jp StdBattleTextBox .asm_36f9a jp Function0x37357 ; 36f9d @@ -8496,14 +8496,14 @@ BattleCommand35: ; 36f9d set 7, [hl] call Function0x37e01 ld hl, WasSeededText - jp FarBattleTextBox + jp StdBattleTextBox .asm_36fd2 call Function0x37e77 jp PrintDoesntAffect .asm_36fd8 call Function0x37e77 ld hl, EvadedText - jp FarBattleTextBox + jp StdBattleTextBox ; 36fe1 @@ -8558,7 +8558,7 @@ BattleCommand37: ; 36fed and a jr z, .asm_37059 ; 3702c $2b .asm_3702e - call FarBattleRNG + call BattleRandom and $7 jr z, .asm_3702e ; 37033 $f9 inc a @@ -8579,7 +8579,7 @@ BattleCommand37: ; 36fed ld [$d265], a call GetMoveName ld hl, WasDisabledText - jp FarBattleTextBox + jp StdBattleTextBox .asm_37059 jp Function0x37354 ; 3705c @@ -8608,7 +8608,7 @@ BattleCommand1e: ; 3705c inc [hl] .asm_37079 ld hl, CoinsScatteredText - jp FarBattleTextBox + jp StdBattleTextBox ; 3707f @@ -8677,7 +8677,7 @@ BattleCommand1f: ; 3707f call Function0x37e77 jp PrintButItFailed .asm_370d9 - call FarBattleRNG + call BattleRandom and $3 ld c, a ld b, $0 @@ -8706,7 +8706,7 @@ BattleCommand1f: ; 3707f rst FarCall call Function0x37e01 ld hl, TransformedTypeText - jp FarBattleTextBox + jp StdBattleTextBox ; 3710e @@ -8733,7 +8733,7 @@ BattleCommand20: ; 3710e call Function0x37e01 ld hl, EliminatedStatsText - jp FarBattleTextBox + jp StdBattleTextBox .Fill ld b, PlayerStatLevelsEnd - PlayerStatLevels @@ -8787,7 +8787,7 @@ BattleCommand2c: ; 3713e jr z, .asm_37186 ; 37181 $3 ld hl, RestedText .asm_37186 - call FarBattleTextBox + call StdBattleTextBox ld a, [hBattleTurn] and a jr nz, .asm_37193 ; 3718c $5 @@ -8816,12 +8816,12 @@ BattleCommand2c: ; 3713e call UpdateUserInParty call RefreshBattleHuds ld hl, RegainedHealthText - jp FarBattleTextBox + jp StdBattleTextBox .asm_371c4 call Function0x37e77 ld hl, HPIsFullText - jp FarBattleTextBox + jp StdBattleTextBox ; 371cd @@ -8958,7 +8958,7 @@ BattleCommand2d: ; 371cd ld a, $a4 call nz, Function0x37e44 ld hl, TransformedText - jp FarBattleTextBox + jp StdBattleTextBox ; 372c6 @@ -9056,7 +9056,7 @@ BattleCommand2e: ; 372fc .asm_37331 call Function0x37e01 - jp FarBattleTextBox + jp StdBattleTextBox .asm_37337 call Function0x37e77 @@ -9067,14 +9067,14 @@ BattleCommand2e: ; 372fc PrintDoesntAffect: ; 3733d ; 'it doesn't affect' ld hl, DoesntAffectText - jp FarBattleTextBox + jp StdBattleTextBox ; 37343 PrintNothingHappened: ; 37343 ; 'but nothing happened!' ld hl, NothingHappenedText - jp FarBattleTextBox + jp StdBattleTextBox ; 37349 @@ -9090,7 +9090,7 @@ TryPrintButItFailed: ; 37349 PrintButItFailed: ; 3734e ; 'but it failed!' ld hl, ButItFailedText - jp FarBattleTextBox + jp StdBattleTextBox ; 37354 @@ -9109,7 +9109,7 @@ Function0x37357: ; 37357 PrintDidntAffect: ; 37360 ; 'it didn't affect' ld hl, DidntAffect1Text - jp FarBattleTextBox + jp StdBattleTextBox ; 37366 @@ -9124,7 +9124,7 @@ PrintDidntAffect2: ; 37366 PrintParalyze: ; 37372 ; 'paralyzed! maybe it can't attack!' ld hl, ParalyzedText - jp FarBattleTextBox + jp StdBattleTextBox ; 37378 @@ -9189,7 +9189,7 @@ BattleCommand1b: ; 373c9 .asm_373de call Function0x37e77 ld hl, MirrorMoveFailedText - call FarBattleTextBox + call StdBattleTextBox jp EndMoveEffect .asm_373ea ld a, b @@ -9235,7 +9235,7 @@ BattleCommand34: ; 37418 call Function0x37e36 .GetMove - call FarBattleRNG + call BattleRandom ; No invalid moves. cp BEAT_UP + 1 @@ -9391,7 +9391,7 @@ BattleCommand50: ; 37492 .asm_374f8 call GetItemName ld hl, StoleText - jp FarBattleTextBox + jp StdBattleTextBox .asm_37501 ld a, 1 @@ -9422,7 +9422,7 @@ BattleCommand51: ; 37517 set 7, [hl] call Function0x37e01 ld hl, CantEscapeNowText - jp FarBattleTextBox + jp StdBattleTextBox .asm_37530 call Function0x37e77 jp PrintButItFailed @@ -9447,7 +9447,7 @@ BattleCommand52: ; 37536 set 0, [hl] call Function0x37e01 ld hl, StartedNightmareText - jp FarBattleTextBox + jp StdBattleTextBox .asm_3755d call Function0x37e77 jp PrintButItFailed @@ -9475,7 +9475,7 @@ BattleCommand53: ; 37563 .asm_3757f call RefreshBattleHuds ld hl, WasDefrostedText - jp FarBattleTextBox + jp StdBattleTextBox ; 37588 @@ -9536,7 +9536,7 @@ BattleCommand54: ; 37588 call CallBankF call UpdateUserInParty ld hl, PutACurseText - jp FarBattleTextBox + jp StdBattleTextBox .asm_37604 call Function0x37e77 jp PrintButItFailed @@ -9545,7 +9545,7 @@ BattleCommand54: ; 37588 call GetStatName call Function0x37e77 ld hl, WontRiseAnymoreText - jp FarBattleTextBox + jp StdBattleTextBox ; 37618 @@ -9559,7 +9559,7 @@ BattleCommand55: ; 37618 set 2, [hl] call Function0x37e01 ld hl, ProtectedItselfText - jp FarBattleTextBox + jp StdBattleTextBox ; 3762c @@ -9596,7 +9596,7 @@ Function0x3762c: ; 3762c jr .asm_37665 .asm_37656 - call FarBattleRNG + call BattleRandom and a jr z, .asm_37656 @@ -9631,7 +9631,7 @@ BattleCommand5a: ; 3766f set SUBSTATUS_ENDURE, [hl] call Function0x37e01 ld hl, BracedItselfText - jp FarBattleTextBox + jp StdBattleTextBox ; 37683 @@ -9651,7 +9651,7 @@ BattleCommand56: ; 37683 set 0, [hl] call Function0x37e01 ld hl, SpikesText - jp FarBattleTextBox + jp StdBattleTextBox .failed jp Function0x37354 @@ -9673,7 +9673,7 @@ BattleCommand57: ; 376a0 set SUBSTATUS_IDENTIFIED, [hl] call Function0x37e01 ld hl, IdentifiedText - jp FarBattleTextBox + jp StdBattleTextBox .asm_376bf jp Function0x37354 ; 376c2 @@ -9706,7 +9706,7 @@ BattleCommand58: ; 376c2 .asm_376e9 call Function0x37e01 ld hl, StartPerishText - jp FarBattleTextBox + jp StdBattleTextBox .asm_376f2 call Function0x37e77 jp PrintButItFailed @@ -9725,7 +9725,7 @@ BattleCommand59: ; 376f8 ld [WeatherCount], a call Function0x37e01 ld hl, SandstormBrewedText - jp FarBattleTextBox + jp StdBattleTextBox .asm_37712 call Function0x37e77 jp PrintButItFailed @@ -9911,7 +9911,7 @@ BattleCommand5f: ; 377ce ; 'fell in love!' ld hl, FellInLoveText - jp FarBattleTextBox + jp StdBattleTextBox .asm_377f2 jp Function0x37354 @@ -10029,7 +10029,7 @@ BattleCommand61: ; 37874 and a jp nz, Function0x37e77 push bc - call FarBattleRNG + call BattleRandom ld b, a ld hl, .table_37907 ld c, 0 @@ -10071,7 +10071,7 @@ BattleCommand61: ; 37874 call CallBankF call SwitchTurn ld hl, RegainedHealthText - call FarBattleTextBox + call StdBattleTextBox call SwitchTurn call UpdateOpponentInParty jr .asm_37904 ; 378f1 $11 @@ -10081,7 +10081,7 @@ BattleCommand61: ; 37874 jr nc, .asm_37904 ; 378f9 $9 call Function0x37e77 ld hl, RefusedGiftText - call FarBattleTextBox + call StdBattleTextBox .asm_37904 jp EndMoveEffect @@ -10141,7 +10141,7 @@ BattleCommand64: ; 37939 ld [de], a call Function0x37e01 ld hl, CoveredByVeilText - jp FarBattleTextBox + jp StdBattleTextBox .asm_3795c call Function0x37e77 jp PrintButItFailed @@ -10177,7 +10177,7 @@ BattleCommand65: ; 37972 ld [AttackMissed], a call BattleCommandaa ld hl, SafeguardProtectText - call FarBattleTextBox + call StdBattleTextBox jp EndMoveEffect ; 37991 @@ -10186,7 +10186,7 @@ BattleCommand66: ; 37991 ; getmagnitude push bc - call FarBattleRNG + call BattleRandom ld b, a ld hl, .Magnitudes .asm_37999 @@ -10204,7 +10204,7 @@ BattleCommand66: ; 37991 ld [$d265], a call BattleCommandaa ld hl, MagnitudeText - call FarBattleTextBox + call StdBattleTextBox pop de pop bc ret @@ -10485,7 +10485,7 @@ BattleCommand69: ; 37b39 jr z, .asm_37b4a ; 37b40 $8 res 7, [hl] ld hl, ShedLeechSeedText - call FarBattleTextBox + call StdBattleTextBox .asm_37b4a ld hl, PlayerScreens ld de, $c730 @@ -10500,7 +10500,7 @@ BattleCommand69: ; 37b39 res 0, [hl] ld hl, BlewSpikesText push de - call FarBattleTextBox + call StdBattleTextBox pop de .asm_37b69 ld a, [de] @@ -10509,7 +10509,7 @@ BattleCommand69: ; 37b39 xor a ld [de], a ld hl, ReleasedByText - jp FarBattleTextBox + jp StdBattleTextBox ; 37b74 @@ -10600,14 +10600,14 @@ BattleCommand6a6c: ; 37b7e ; 'regained health!' ld hl, RegainedHealthText - jp FarBattleTextBox + jp StdBattleTextBox .Full call Function0x37e77 ; 'hp is full!' ld hl, HPIsFullText - jp FarBattleTextBox + jp StdBattleTextBox .Multipliers dw GetEighthMaxHP @@ -10636,7 +10636,7 @@ BattleCommand6e: ; 37bf4 ld [WeatherCount], a call Function0x37e01 ld hl, DownpourText - jp FarBattleTextBox + jp StdBattleTextBox ; 37c07 @@ -10648,7 +10648,7 @@ BattleCommand6f: ; 37c07 ld [WeatherCount], a call Function0x37e01 ld hl, SunGotBrightText - jp FarBattleTextBox + jp StdBattleTextBox ; 37c1a @@ -10685,7 +10685,7 @@ BattleCommand95: ; 37c1a jr nz, .asm_37c41 ; 37c47 $f8 ld hl, BellyDrumText - jp FarBattleTextBox + jp StdBattleTextBox .asm_37c4f call Function0x37e77 jp PrintButItFailed @@ -10735,7 +10735,7 @@ BattleCommand96: ; 37c55 .asm_37c8c call Function0x37e01 ld hl, CopiedStatsText - jp FarBattleTextBox + jp StdBattleTextBox ; 37c95 @@ -10884,7 +10884,7 @@ BattleCommand9c: ; 37d34 call BattleCommand0a call BattleCommandaa ld hl, ForesawAttackText - call FarBattleTextBox + call StdBattleTextBox call BattleCommand0c ld de, $c727 ld a, [hBattleTurn] diff --git a/constants.asm b/constants.asm index e929a48f2..19049702e 100644 --- a/constants.asm +++ b/constants.asm @@ -13,6 +13,8 @@ INCLUDE "constants/map_constants.asm" INCLUDE "constants/item_constants.asm" INCLUDE "constants/trainer_constants.asm" INCLUDE "constants/script_constants.asm" +INCLUDE "constants/event_flags.asm" +INCLUDE "constants/engine_flags.asm" INCLUDE "constants/music_constants.asm" @@ -231,6 +233,7 @@ PREDEF_PRINT_MOVE_DESCRIPTION EQU $11 PREDEF_UPDATE_PLAYER_HUD EQU $12 PREDEF_FILL_BOX EQU $13 PREDEF_UPDATE_ENEMY_HUD EQU $15 +PREDEF_START_BATTLE EQU $16 PREDEF_FILL_IN_EXP_BAR EQU $17 PREDEF_FILLMOVES EQU $1B PREDEF_GET_GENDER EQU $24 @@ -243,6 +246,7 @@ PREDEF_PRINT_TYPE EQU $2B PREDEF_GET_UNOWN_LETTER EQU $2D PREDEF_LOAD_SGB_LAYOUT EQU $31 PREDEF_CHECK_CONTEST_MON EQU $33 +PREDEF_BATTLE_TRANSITION EQU $34 PREDEF_PARTYMON_ITEM_NAME EQU $3B PREDEF_DECOMPRESS EQU $40 diff --git a/constants/engine_flags.asm b/constants/engine_flags.asm new file mode 100644 index 000000000..826a33c17 --- /dev/null +++ b/constants/engine_flags.asm @@ -0,0 +1,163 @@ +ENGINE_RADIO_CARD EQU $00 +ENGINE_MAP_CARD EQU $01 +ENGINE_PHONE_CARD EQU $02 +ENGINE_EXPN_CARD EQU $03 +ENGINE_POKEGEAR EQU $04 +ENGINE_DAYCARE_MONS_ARE_COMPATIBLE EQU $05 +ENGINE_DAYCARE_MAN_HAS_MON EQU $06 +ENGINE_DAYCARE_LADY_HAS_MON EQU $07 +ENGINE_MOM_SAVING_MONEY EQU $08 +ENGINE_DST EQU $09 +ENGINE_0A EQU $0a +ENGINE_POKEDEX EQU $0b +ENGINE_UNOWN_DEX EQU $0c +ENGINE_POKERUS EQU $0d +ENGINE_ROCKET_SIGNAL_ON_CH20 EQU $0e +ENGINE_CREDITS_SKIP EQU $0f +ENGINE_BUG_CONTEST_ON EQU $10 +ENGINE_BUG_CONTEST_TIMER EQU $11 +ENGINE_ROCKETS_IN_RADIO_TOWER EQU $12 +ENGINE_BIKE_SHOP_CALL_ENABLED EQU $13 +ENGINE_14 EQU $14 +ENGINE_GIVE_POKERUS EQU $15 +ENGINE_16 EQU $16 +ENGINE_ROCKETS_IN_MAHOGANY EQU $17 +ENGINE_STRENGTH_ACTIVE EQU $18 +ENGINE_ALWAYS_ON_BIKE EQU $19 +ENGINE_DOWNHILL EQU $1a +ENGINE_ZEPHYRBADGE EQU $1b +ENGINE_HIVEBADGE EQU $1c +ENGINE_PLAINBADGE EQU $1d +ENGINE_FOGBADGE EQU $1e +ENGINE_MINERALBADGE EQU $1f +ENGINE_STORMBADGE EQU $20 +ENGINE_GLACIERBADGE EQU $21 +ENGINE_RISINGBADGE EQU $22 +ENGINE_BOULDERBADGE EQU $23 +ENGINE_CASCADEBADGE EQU $24 +ENGINE_THUNDERBADGE EQU $25 +ENGINE_RAINBOWBADGE EQU $26 +ENGINE_SOULBADGE EQU $27 +ENGINE_MARSHBADGE EQU $28 +ENGINE_VOLCANOBADGE EQU $29 +ENGINE_EARTHBADGE EQU $2a +ENGINE_UNLOCKED_UNOWNS_1 EQU $2b +ENGINE_UNLOCKED_UNOWNS_2 EQU $2c +ENGINE_UNLOCKED_UNOWNS_3 EQU $2d +ENGINE_UNLOCKED_UNOWNS_4 EQU $2e +ENGINE_UNLOCKED_UNOWNS_5 EQU $2f +ENGINE_UNLOCKED_UNOWNS_6 EQU $30 +ENGINE_UNLOCKED_UNOWNS_7 EQU $31 +ENGINE_UNLOCKED_UNOWNS_8 EQU $32 +ENGINE_FLYPOINT_KRISS_HOUSE EQU $33 +ENGINE_FLYPOINT_VIRIDIAN_POKECENTER EQU $34 +ENGINE_FLYPOINT_PALLET EQU $35 +ENGINE_FLYPOINT_VIRIDIAN EQU $36 +ENGINE_FLYPOINT_PEWTER EQU $37 +ENGINE_FLYPOINT_CERULEAN EQU $38 +ENGINE_FLYPOINT_ROCK_TUNNEL EQU $39 +ENGINE_FLYPOINT_VERMILION EQU $3a +ENGINE_FLYPOINT_LAVENDER EQU $3b +ENGINE_FLYPOINT_SAFFRON EQU $3c +ENGINE_FLYPOINT_CELADON EQU $3d +ENGINE_FLYPOINT_FUCHSIA EQU $3e +ENGINE_FLYPOINT_CINNABAR EQU $3f +ENGINE_FLYPOINT_INDIGO_PLATEAU EQU $40 +ENGINE_FLYPOINT_NEW_BARK EQU $41 +ENGINE_FLYPOINT_CHERRYGROVE EQU $42 +ENGINE_FLYPOINT_VIOLET EQU $43 +ENGINE_FLYPOINT_AZALEA EQU $44 +ENGINE_FLYPOINT_CIANWOOD EQU $45 +ENGINE_FLYPOINT_GOLDENROD EQU $46 +ENGINE_FLYPOINT_OLIVINE EQU $47 +ENGINE_FLYPOINT_ECRUTEAK EQU $48 +ENGINE_FLYPOINT_MAHOGANY EQU $49 +ENGINE_FLYPOINT_LAKE_OF_RAGE EQU $4a +ENGINE_FLYPOINT_BLACKTHORN EQU $4b +ENGINE_FLYPOINT_SILVER_CAVE EQU $4c +ENGINE_FLYPOINT_UNUSED EQU $4d +ENGINE_LUCKY_NUMBER_SHOW EQU $4e +ENGINE_4F EQU $4f +ENGINE_KURT_MAKING_BALLS EQU $50 +ENGINE_51 EQU $51 +ENGINE_SPECIAL_WILDDATA EQU $52 +ENGINE_TIME_CAPSULE EQU $53 +ENGINE_ALL_FRUIT_TREES EQU $54 +ENGINE_SHUCKLE_GIVEN EQU $55 +ENGINE_GOLDENROD_UNDERGROUND_MERCHANT_CLOSED EQU $56 +ENGINE_FOUGHT_IN_TRAINER_HALL_TODAY EQU $57 +ENGINE_MT_MOON_SQUARE_CLEFAIRY EQU $58 +ENGINE_UNION_CAVE_LAPRAS EQU $59 +ENGINE_GOLDENROD_UNDERGROUND_GOT_HAIRCUT EQU $5a +ENGINE_GOLDENROD_MALL_5F_HAPPINESS_EVENT EQU $5b +ENGINE_TEA_IN_BLUES_HOUSE EQU $5c +ENGINE_INDIGO_PLATEAU_RIVAL_FIGHT EQU $5d +ENGINE_5E EQU $5e +ENGINE_5F EQU $5f +ENGINE_60 EQU $60 +ENGINE_GOLDENROD_DEPT_STORE_SALE_IS_ON EQU $61 +ENGINE_62 EQU $62 +ENGINE_PLAYER_IS_FEMALE EQU $63 +ENGINE_HAVE_EXAMINED_GS_BALL EQU $64 +ENGINE_JACK EQU $65 +ENGINE_HUEY EQU $66 +ENGINE_GAVEN EQU $67 +ENGINE_BETH EQU $68 +ENGINE_JOSE EQU $69 +ENGINE_REENA EQU $6a +ENGINE_JOEY EQU $6b +ENGINE_WADE EQU $6c +ENGINE_RALPH EQU $6d +ENGINE_LIZ EQU $6e +ENGINE_ANTHONY EQU $6f +ENGINE_TODD EQU $70 +ENGINE_GINA EQU $71 +ENGINE_ARNIE EQU $72 +ENGINE_ALAN EQU $73 +ENGINE_DANA EQU $74 +ENGINE_CHAD EQU $75 +ENGINE_TULLY EQU $76 +ENGINE_BRENT EQU $77 +ENGINE_TIFFANY EQU $78 +ENGINE_VANCE EQU $79 +ENGINE_WILTON EQU $7a +ENGINE_PARRY EQU $7b +ENGINE_ERIN EQU $7c +ENGINE_BEVERLY_HAS_NUGGET EQU $7d +ENGINE_JOSE_HAS_STAR_PIECE EQU $7e +ENGINE_WADE_HAS_ITEM EQU $7f +ENGINE_GINA_HAS_LEAF_STONE EQU $80 +ENGINE_ALAN_HAS_FIRE_STONE EQU $81 +ENGINE_LIZ_HAS_THUNDERSTONE EQU $82 +ENGINE_DEREK_HAS_NUGGET EQU $83 +ENGINE_TULLY_HAS_WATER_STONE EQU $84 +ENGINE_TIFFANY_HAS_PINK_BOW EQU $85 +ENGINE_WILTON_HAS_ITEM EQU $86 +ENGINE_87 EQU $87 +ENGINE_88 EQU $88 +ENGINE_89 EQU $89 +ENGINE_8A EQU $8a +ENGINE_8B EQU $8b +ENGINE_8C EQU $8c +ENGINE_8D EQU $8d +ENGINE_8E EQU $8e +ENGINE_8F EQU $8f +ENGINE_90 EQU $90 +ENGINE_91 EQU $91 +ENGINE_92 EQU $92 +ENGINE_93 EQU $93 +ENGINE_94 EQU $94 +ENGINE_95 EQU $95 +ENGINE_96 EQU $96 +ENGINE_97 EQU $97 +ENGINE_98 EQU $98 +ENGINE_99 EQU $99 +ENGINE_9A EQU $9a +ENGINE_9B EQU $9b +ENGINE_9C EQU $9c +ENGINE_9D EQU $9d +ENGINE_9E EQU $9e +ENGINE_KRIS_IN_CABLE_CLUB EQU $9f +ENGINE_DUNSPARCE_SWARM EQU $a0 +ENGINE_YANMA_SWARM EQU $a1 + diff --git a/constants/event_flags.asm b/constants/event_flags.asm new file mode 100644 index 000000000..a533761fb --- /dev/null +++ b/constants/event_flags.asm @@ -0,0 +1,6 @@ +EVENT_FOUGHT_SUDOWOODO EQU $02a +EVENT_FOUGHT_HO_OH EQU $317 +EVENT_FOUGHT_LUGIA EQU $318 +EVENT_FOUGHT_SUICUNE EQU $335 +EVENT_FOUGHT_SNORLAX EQU $750 + diff --git a/constants/pokemon_constants.asm b/constants/pokemon_constants.asm index 40b450b85..29739ed46 100644 --- a/constants/pokemon_constants.asm +++ b/constants/pokemon_constants.asm @@ -1,3 +1,5 @@ +NUM_POKEMON EQU 251 + BULBASAUR EQU 1 IVYSAUR EQU 2 VENUSAUR EQU 3 diff --git a/engine/copy.asm b/engine/copy.asm new file mode 100644 index 000000000..c5ba92c65 --- /dev/null +++ b/engine/copy.asm @@ -0,0 +1,431 @@ +; Functions to copy data from ROM. + + +Functiondc9: ; dc9 + ld a, [rLCDC] + bit 7, a + jp z, Copy2bpp + + ld a, [hROMBank] + push af + ld a, BANK(Function104284) + rst Bankswitch + call Function104284 + pop af + rst Bankswitch + + ret +; ddc + +Functionddc: ; ddc + ld a, [rLCDC] + bit 7, a + jp z, Copy1bpp + + ld a, [hROMBank] + push af + ld a, BANK(Function1042b2) + rst Bankswitch + call Function1042b2 + pop af + rst Bankswitch + + ret +; def + +Functiondef: ; def + ld [hBuffer], a + ld a, [hROMBank] + push af + ld a, [hBuffer] + rst Bankswitch + call FarCopyBytesDouble + pop af + rst Bankswitch + ret +; dfd + +Functiondfd: ; dfd + dec c + ld a, [hBGMapMode] + push af + xor a + ld [hBGMapMode], a + ld a, [hROMBank] + push af + ld a, b + rst Bankswitch + +.asm_e09 + ld a, d + ld [rHDMA1], a + ld a, e + and $f0 + ld [rHDMA2], a + ld a, h + and $1f + ld [rHDMA3], a + ld a, l + and $f0 + ld [rHDMA4], a + ld a, c + cp $8 + jr c, .asm_e3c + sub $8 + ld c, a + ld a, $f + ld [hDMATransfer], a + call DelayFrame + ld a, l + add $0 + ld l, a + ld a, h + adc $1 + ld h, a + ld a, e + add $0 + ld e, a + ld a, d + adc $1 + ld d, a + jr .asm_e09 + +.asm_e3c + ld a, c + and $7f + ld [hDMATransfer], a + call DelayFrame + pop af + rst Bankswitch + + pop af + ld [hBGMapMode], a + ret +; e4a + + + +Functione4a: ; e4a + ld a, $5 + ld hl, $4135 + rst FarCall + ret +; e51 + + + +Functione51: ; e51 + ld a, $3e + ld hl, $7449 + rst FarCall + ret +; e58 + +Functione58: ; e58 + ld a, $3e + ld hl, $74be + rst FarCall + ret +; e5f + + + +Functione5f: ; e5f + ld a, $3e + ld hl, $748a + rst FarCall + ld a, $3e + ld hl, $74b0 + rst FarCall + ret +; e6c + +Functione6c: ; e6c + ld a, $3e + ld hl, $74b0 + rst FarCall + ret +; e73 + +Functione73: ; e73 + push de + ld a, $0 + call GetSRAMBank + push bc + ld de, $a000 + ld a, b + call FarDecompress + pop bc + pop hl + ld de, $a000 + call Request2bpp + call CloseSRAM + ret +; e8d + + + +FarCopyBytes: ; e8d +; copy bc bytes from a:hl to de + + ld [hBuffer], a + ld a, [hROMBank] + push af + ld a, [hBuffer] + rst Bankswitch + + call CopyBytes + + pop af + rst Bankswitch + ret +; 0xe9b + + +FarCopyBytesDouble: ; e9b +; Copy bc bytes from a:hl to bc*2 bytes at de, +; doubling each byte in the process. + + ld [hBuffer], a + ld a, [hROMBank] + push af + ld a, [hBuffer] + rst Bankswitch + +; switcheroo, de <> hl + ld a, h + ld h, d + ld d, a + ld a, l + ld l, e + ld e, a + + inc b + inc c + jr .dec + +.loop + ld a, [de] + inc de + ld [hli], a + ld [hli], a +.dec + dec c + jr nz, .loop + dec b + jr nz, .loop + + pop af + rst Bankswitch + ret +; 0xeba + + +Request2bpp: ; eba + ld a, [hBGMapMode] + push af + xor a + ld [hBGMapMode], a + + ld a, [hROMBank] + push af + ld a, b + rst Bankswitch + + ld a, [$ffd3] + push af + + ld a, $8 + ld [$ffd3], a + ld a, [InLinkBattle] + cp $4 + jr nz, .asm_edc + ld a, [$ffe9] + and a + jr nz, .asm_edc + ld a, $6 + ld [$ffd3], a + +.asm_edc + ld a, e + ld [$cf68], a + ld a, d + ld [$cf69], a + ld a, l + ld [$cf6a], a + ld a, h + ld [$cf6b], a + +.asm_eec + ld a, c + ld hl, $ffd3 + cp [hl] + jr nc, .asm_f08 + + ld [$cf67], a +.wait + call DelayFrame + ld a, [$cf67] + and a + jr nz, .wait + + pop af + ld [$ffd3], a + + pop af + rst Bankswitch + + pop af + ld [hBGMapMode], a + ret + +.asm_f08 + ld a, [$ffd3] + ld [$cf67], a +.asm_f0d + call DelayFrame + ld a, [$cf67] + and a + jr nz, .asm_f0d + ld a, c + ld hl, $ffd3 + sub [hl] + ld c, a + jr .asm_eec +; f1e + + +Request1bpp: ; f1e + ld a, [hBGMapMode] + push af + xor a + ld [hBGMapMode], a + + ld a, [hROMBank] + push af + ld a, b + rst Bankswitch + + ld a, [$ffd3] + push af + + ld a, $8 + ld [$ffd3], a + ld a, [InLinkBattle] + cp $4 + jr nz, .asm_f40 + ld a, [$ffe9] + and a + jr nz, .asm_f40 + ld a, $6 + ld [$ffd3], a + +.asm_f40 + ld a, e + ld [$cf6d], a + ld a, d + ld [$cf6e], a + ld a, l + ld [$cf6f], a + ld a, h + ld [$cf70], a +.asm_f50 + ld a, c + ld hl, $ffd3 + cp [hl] + jr nc, .asm_f6c + + ld [$cf6c], a +.wait + call DelayFrame + ld a, [$cf6c] + and a + jr nz, .wait + + pop af + ld [$ffd3], a + + pop af + rst Bankswitch + + pop af + ld [hBGMapMode], a + ret + +.asm_f6c + ld a, [$ffd3] + ld [$cf6c], a +.asm_f71 + call DelayFrame + ld a, [$cf6c] + and a + jr nz, .asm_f71 + ld a, c + ld hl, $ffd3 + sub [hl] + ld c, a + jr .asm_f50 +; f82 + + +Get2bpp: ; f82 + ld a, [rLCDC] + bit 7, a + jp nz, Request2bpp + +Copy2bpp: ; f89 +; copy c 2bpp tiles from b:de to hl + + push hl + ld h, d + ld l, e + pop de + +; bank + ld a, b + +; bc = c * $10 + push af + swap c + ld a, $f + and c + ld b, a + ld a, $f0 + and c + ld c, a + pop af + + jp FarCopyBytes +; f9d + + +Get1bpp: ; f9d + ld a, [rLCDC] + bit 7, a + jp nz, Request1bpp + +Copy1bpp: ; fa4 +; copy c 1bpp tiles from b:de to hl + + push de + ld d, h + ld e, l + +; bank + ld a, b + +; bc = c * $10 / 2 + push af + ld h, 0 + ld l, c + add hl, hl + add hl, hl + add hl, hl + ld b, h + ld c, l + pop af + + pop hl + jp FarCopyBytesDouble +; fb6 + diff --git a/engine/bittable2.asm b/engine/engine_flags.asm similarity index 100% rename from engine/bittable2.asm rename to engine/engine_flags.asm diff --git a/engine/fade.asm b/engine/fade.asm new file mode 100644 index 000000000..d67211e29 --- /dev/null +++ b/engine/fade.asm @@ -0,0 +1,134 @@ +; Functions to fade the screen in and out. + + +Function48c: ; 48c + ld a, [TimeOfDayPal] + ld b, a + ld hl, IncGradGBPalTable_11 + ld a, l + sub b + ld l, a + jr nc, .asm_499 + dec h + +.asm_499 + ld a, [hli] + ld [rBGP], a + ld a, [hli] + ld [rOBP0], a + ld a, [hli] + ld [rOBP1], a + ret +; 4a3 + + +Function4a3: ; 4a3 + ld a, [hCGB] + and a + jr z, .asm_4af + ld hl, IncGradGBPalTable_00 + ld b, 4 + jr FadeOut + +.asm_4af + ld hl, IncGradGBPalTable_08 + ld b, 4 + jr FadeOut +; 4b6 + +Function4b6: ; 4b6 + ld a, [hCGB] + and a + jr z, .asm_4c2 + ld hl, IncGradGBPalTable_05 + ld b, 3 + jr FadeOut + +.asm_4c2 + ld hl, IncGradGBPalTable_13 + ld b, 3 +; 4c7 + +FadeOut: ; 4c7 + push de + ld a, [hli] + call DmgToCgbBGPals + ld a, [hli] + ld e, a + ld a, [hli] + ld d, a + call DmgToCgbObjPals + ld c, 8 + call DelayFrames + pop de + dec b + jr nz, FadeOut + ret +; 4dd + +Function4dd: ; 4dd + ld a, [hCGB] + and a + jr z, .asm_4e9 + ld hl, IncGradGBPalTable_04 - 1 + ld b, 4 + jr FadeIn + +.asm_4e9 + ld hl, IncGradGBPalTable_12 - 1 + ld b, 4 + jr FadeIn +; 4f0 + +Function4f0: ; 4f0 + ld a, [hCGB] + and a + jr z, .asm_4fc + ld hl, IncGradGBPalTable_07 - 1 + ld b, 3 + jr FadeIn + +.asm_4fc + ld hl, IncGradGBPalTable_15 - 1 + ld b, 3 + ; fallthrough +; 501 + +FadeIn: ; 501 + push de + ld a, [hld] + ld d, a + ld a, [hld] + ld e, a + call DmgToCgbObjPals + ld a, [hld] + call DmgToCgbBGPals + ld c, 8 + call DelayFrames + pop de + dec b + jr nz, FadeIn + ret +; 517 + + +; 517 +IncGradGBPalTable_00: db %11111111, %11111111, %11111111 +IncGradGBPalTable_01: db %11111110, %11111110, %11111110 +IncGradGBPalTable_02: db %11111001, %11111001, %11111001 +IncGradGBPalTable_03: db %11100100, %11100100, %11100100 +IncGradGBPalTable_04: db %11100100, %11100100, %11100100 +IncGradGBPalTable_05: db %10010000, %10010000, %10010000 +IncGradGBPalTable_06: db %01000000, %01000000, %01000000 +IncGradGBPalTable_07: db %00000000, %00000000, %00000000 +; bgp obp1 obp2 +IncGradGBPalTable_08: db %11111111, %11111111, %11111111 +IncGradGBPalTable_09: db %11111110, %11111110, %11111000 +IncGradGBPalTable_10: db %11111001, %11100100, %11100100 +IncGradGBPalTable_11: db %11100100, %11010000, %11100000 +IncGradGBPalTable_12: db %11100100, %11010000, %11100000 +IncGradGBPalTable_13: db %10010000, %10000000, %10010000 +IncGradGBPalTable_14: db %01000000, %01000000, %01000000 +IncGradGBPalTable_15: db %00000000, %00000000, %00000000 +; 547 + diff --git a/engine/init.asm b/engine/init.asm index d7594ae1d..3104c416d 100644 --- a/engine/init.asm +++ b/engine/init.asm @@ -79,7 +79,7 @@ Init: ; 17d or c jr nz, .asm_1b1 - ld sp, Stack - 1 + ld sp, Stack ; Clear HRAM ld a, [hCGB] diff --git a/engine/joypad.asm b/engine/joypad.asm index 5266ef8a8..388c84e22 100644 --- a/engine/joypad.asm +++ b/engine/joypad.asm @@ -273,3 +273,219 @@ StopAutoInput: ; a0a ret ; a1b + +Functiona1b: ; a1b + + call DelayFrame + + push bc + call Functiona57 + pop bc + + ld a, [hJoyDown] + cp D_UP | SELECT | BUTTON_B + jr z, .asm_a34 + + ld a, [$ffa9] + and START | BUTTON_A + jr nz, .asm_a34 + + dec c + jr nz, Functiona1b + + and a + ret + +.asm_a34 + scf + ret +; a36 + + +Functiona36: ; a36 + call DelayFrame + call GetJoypadPublic + ld a, [hJoyPressed] + and BUTTON_A | BUTTON_B + ret nz + call RTC + jr Functiona36 +; a46 + +Functiona46: ; a46 + ld a, [hOAMUpdate] + push af + ld a, 1 + ld [hOAMUpdate], a + call WaitBGMap + call Functiona36 + pop af + ld [hOAMUpdate], a + ret +; a57 + +Functiona57: ; a57 + call GetJoypadPublic + ld a, [$ffaa] + and a + ld a, [hJoyPressed] + jr z, .asm_a63 + ld a, [hJoyDown] +.asm_a63 + ld [$ffa9], a + ld a, [hJoyPressed] + and a + jr z, .asm_a70 + ld a, 15 + ld [TextDelayFrames], a + ret + +.asm_a70 + ld a, [TextDelayFrames] + and a + jr z, .asm_a7a + xor a + ld [$ffa9], a + ret + +.asm_a7a + ld a, 5 + ld [TextDelayFrames], a + ret +; a80 + +Functiona80: ; a80 + ld a, [$ffaf] + push af + ld a, [$ffb0] + push af + xor a + ld [$ffaf], a + ld a, $6 + ld [$ffb0], a +.asm_a8d + push hl + ld hl, $c606 + call Functionb06 + pop hl + call Functiona57 + ld a, [$ffa9] + and $3 + jr z, .asm_a8d + pop af + ld [$ffb0], a + pop af + ld [$ffaf], a + ret +; aa5 + +Functionaa5: ; aa5 + call Functiona57 + ld a, [$ffa9] + and BUTTON_A | BUTTON_B + jr z, Functionaa5 + ret +; aaf + +Functionaaf: ; aaf + ld a, [InLinkBattle] + and a + jr nz, .asm_ac1 + call Functionac6 + push de + ld de, SFX_READ_TEXT_2 + call StartSFX + pop de + ret + +.asm_ac1 + ld c, 65 + jp DelayFrames +; ac6 + +Functionac6: ; ac6 + ld a, [hOAMUpdate] + push af + ld a, $1 + ld [hOAMUpdate], a + ld a, [InputType] + or a + jr z, .asm_ad9 + callba Function1de28a +.asm_ad9 + call Functionaf5 + call Functiona57 + ld a, [hJoyPressed] + and $3 + jr nz, .asm_af1 + call RTC + ld a, $1 + ld [hBGMapMode], a + call DelayFrame + jr .asm_ad9 + +.asm_af1 + pop af + ld [hOAMUpdate], a + ret +; af5 + +Functionaf5: ; af5 + ld a, [$ff9b] + and $10 + jr z, .asm_aff + ld a, $ee + jr .asm_b02 + +.asm_aff + ld a, [$c605] + +.asm_b02 + ld [$c606], a + ret +; b06 + +Functionb06: ; b06 + push bc + ld a, [hl] + ld b, a + ld a, $ee + cp b + pop bc + jr nz, .asm_b27 + ld a, [$ffaf] + dec a + ld [$ffaf], a + ret nz + ld a, [$ffb0] + dec a + ld [$ffb0], a + ret nz + ld a, $7a + ld [hl], a + ld a, $ff + ld [$ffaf], a + ld a, $6 + ld [$ffb0], a + ret + +.asm_b27 + ld a, [$ffaf] + and a + ret z + dec a + ld [$ffaf], a + ret nz + dec a + ld [$ffaf], a + ld a, [$ffb0] + dec a + ld [$ffb0], a + ret nz + ld a, $6 + ld [$ffb0], a + ld a, $ee + ld [hl], a + ret +; b40 + diff --git a/engine/lcd.asm b/engine/lcd.asm new file mode 100644 index 000000000..9c86eaa5c --- /dev/null +++ b/engine/lcd.asm @@ -0,0 +1,81 @@ +; LCD handling + + +Function547: ; 547 + ld a, [hLCDStatCustom] + cp rSCX & $ff + ret nz + ld c, a + ld a, [LYOverrides] + ld [$ff00+c], a + ret +; 552 + + +LCD: ; 552 + push af + ld a, [hLCDStatCustom] + and a + jr z, .done + +; At this point it's assumed we're in WRAM bank 5! + push bc + ld a, [rLY] + ld c, a + ld b, LYOverrides >> 8 + ld a, [bc] + ld b, a + ld a, [hLCDStatCustom] + ld c, a + ld a, b + ld [$ff00+c], a + pop bc + +.done + pop af + reti +; 568 + + +DisableLCD: ; 568 +; Turn the LCD off + +; Don't need to do anything if the LCD is already off + ld a, [rLCDC] + bit 7, a ; lcd enable + ret z + + xor a + ld [rIF], a + ld a, [rIE] + ld b, a + +; Disable VBlank + res 0, a ; vblank + ld [rIE], a + +.wait +; Wait until VBlank would normally happen + ld a, [rLY] + cp 145 + jr nz, .wait + + ld a, [rLCDC] + and %01111111 ; lcd enable off + ld [rLCDC], a + + xor a + ld [rIF], a + ld a, b + ld [rIE], a + ret +; 58a + + +EnableLCD: ; 58a + ld a, [rLCDC] + set 7, a ; lcd enable + ld [rLCDC], a + ret +; 591 + diff --git a/engine/palettes.asm b/engine/palettes.asm new file mode 100644 index 000000000..accaa96b5 --- /dev/null +++ b/engine/palettes.asm @@ -0,0 +1,347 @@ +; Functions dealing with palettes. + + +UpdatePalsIfCGB: ; c2f +; update bgp data from BGPals +; update obp data from OBPals +; return carry if successful + +; check cgb + ld a, [hCGB] + and a + ret z + + +UpdateCGBPals: ; c33 +; return carry if successful +; any pals to update? + ld a, [hCGBPalUpdate] + and a + ret z + + +ForceUpdateCGBPals: ; c37 + + ld a, [rSVBK] + push af + ld a, 5 ; BANK(BGPals) + ld [rSVBK], a + + ld hl, BGPals ; 5:d080 + +; copy 8 pals to bgpd + ld a, %10000000 ; auto increment, index 0 + ld [rBGPI], a + ld c, rBGPD % $100 + ld b, 4 ; NUM_PALS / 2 +.bgp + rept $10 + ld a, [hli] + ld [$ff00+c], a + endr + + dec b + jr nz, .bgp + +; hl is now 5:d0c0 OBPals + +; copy 8 pals to obpd + ld a, %10000000 ; auto increment, index 0 + ld [rOBPI], a + ld c, rOBPD - rJOYP + ld b, 4 ; NUM_PALS / 2 +.obp + rept $10 + ld a, [hli] + ld [$ff00+c], a + endr + + dec b + jr nz, .obp + + pop af + ld [rSVBK], a + +; clear pal update queue + xor a + ld [hCGBPalUpdate], a + + scf + ret +; c9f + + +DmgToCgbBGPals: ; c9f +; exists to forego reinserting cgb-converted image data + +; input: a -> bgp + + ld [rBGP], a + push af + + ld a, [hCGB] + and a + jr z, .end + + push hl + push de + push bc + ld a, [rSVBK] + push af + + ld a, 5 + ld [rSVBK], a + +; copy & reorder bg pal buffer + ld hl, BGPals ; to + ld de, Unkn1Pals ; from +; order + ld a, [rBGP] + ld b, a +; all pals + ld c, 8 + call CopyPals +; request pal update + ld a, 1 + ld [hCGBPalUpdate], a + + pop af + ld [rSVBK], a + pop bc + pop de + pop hl +.end + pop af + ret +; ccb + + +DmgToCgbObjPals: ; ccb +; exists to forego reinserting cgb-converted image data + +; input: d -> obp1 +; e -> obp2 + + ld a, e + ld [rOBP0], a + ld a, d + ld [rOBP1], a + + ld a, [hCGB] + and a + ret z + + push hl + push de + push bc + ld a, [rSVBK] + push af + + ld a, 5 + ld [rSVBK], a + +; copy & reorder obj pal buffer + ld hl, OBPals ; to + ld de, Unkn2Pals ; from +; order + ld a, [rOBP0] + ld b, a +; all pals + ld c, 8 + call CopyPals +; request pal update + ld a, 1 + ld [hCGBPalUpdate], a + + pop af + ld [rSVBK], a + pop bc + pop de + pop hl + ret +; cf8 + + +Functioncf8: ; cf8 + ld [rOBP0], a + push af + ld a, [hCGB] + and a + jr z, .asm_d22 + push hl + push de + push bc + ld a, [rSVBK] + push af + ld a, $5 + ld [rSVBK], a + ld hl, $d0c0 + ld de, MartPointer + ld a, [rOBP0] + ld b, a + ld c, $1 + call CopyPals + ld a, $1 + ld [hCGBPalUpdate], a + pop af + ld [rSVBK], a + pop bc + pop de + pop hl + +.asm_d22 + pop af + ret +; d24 + +Functiond24: ; d24 + ld [rOBP1], a + push af + ld a, [hCGB] + and a + jr z, .asm_d4e + push hl + push de + push bc + ld a, [rSVBK] + push af + ld a, $5 + ld [rSVBK], a + ld hl, $d0c8 + ld de, $d048 + ld a, [rOBP1] + ld b, a + ld c, $1 + call CopyPals + ld a, $1 + ld [hCGBPalUpdate], a + pop af + ld [rSVBK], a + pop bc + pop de + pop hl + +.asm_d4e + pop af + ret +; d50 + + + +CopyPals: ; d50 +; copy c palettes in order b from de to hl + + push bc + ld c, 4 ; NUM_PAL_COLORS +.loop + push de + push hl + +; get pal color + ld a, b + and %11 ; color +; 2 bytes per color + add a + ld l, a + ld h, 0 + add hl, de + ld e, [hl] + inc hl + ld d, [hl] + +; dest + pop hl +; write color + ld [hl], e + inc hl + ld [hl], d + inc hl +; next pal color + srl b + srl b +; source + pop de +; done pal? + dec c + jr nz, .loop + +; de += 8 (next pal) + ld a, 8 ; NUM_PAL_COLORS * 2 ; bytes per pal + add e + jr nc, .ok + inc d +.ok + ld e, a + +; how many more pals? + pop bc + dec c + jr nz, CopyPals + ret +; d79 + + +Functiond79: ; d79 + ld a, [hCGB] + and a + ret z + ld a, 1 + ld [rVBK], a + ld hl, VTiles0 + ld bc, $2000 + xor a + call ByteFill + ld a, 0 + ld [rVBK], a + ret +; d90 + + +Functiond90: ; d90 + ret +; d91 + + +Functiond91: ; d91 + ld a, [hCGB] + and a + ret z + ld a, [rSVBK] + push af + ld a, 5 ; BANK(BGPals) + ld [rSVBK], a + ld hl, BGPals + ld bc, $40 + $10 + xor a + call ByteFill + pop af + ld [rSVBK], a + ld a, 1 + ld [hCGBPalUpdate], a + call DelayFrame + ret +; db1 + + +Functiondb1: ; db1 + ld a, [hROMBank] + push af + ld a, BANK(Function4c000) + rst Bankswitch + call Function4c000 + pop af + rst Bankswitch + ret +; dbd + +Functiondbd: ; dbd + ld a, [hROMBank] + push af + ld a, BANK(Function4c03f) + rst Bankswitch + call Function4c03f + pop af + rst Bankswitch + ret +; dc9 + diff --git a/engine/scripting.asm b/engine/scripting.asm index 79fbe69ee..5d44d1a8e 100644 --- a/engine/scripting.asm +++ b/engine/scripting.asm @@ -308,7 +308,7 @@ Script_2writetext: ; 0x96e9b ld h, a ld a, [ScriptBank] ld b, a - call $269a + call Function269a ret ; 0x96eab @@ -323,7 +323,7 @@ Script_3writetext: ; 0x96eab ld l, a call GetScriptByte ld h, a - call $269a + call Function269a ret ; 0x96ebb @@ -348,7 +348,7 @@ Script_repeattext: ; 0x96ebb ld a, [hli] ld h, [hl] ld l, a - call $269a + call Function269a ret .asm_96ed8 ret @@ -357,7 +357,7 @@ Script_repeattext: ; 0x96ebb Script_closetext: ; 0x96ed9 ; script command 0x54 - jp $0a46 + jp Functiona46 ; 0x96edc Script_keeptextopen: ; 0x96edc @@ -367,8 +367,8 @@ Script_keeptextopen: ; 0x96edc push af ld a, $1 ld [$ffd8], a - call $31f6 - call $0aaf + call WaitBGMap + call Functionaaf pop af ld [$ffd8], a ret @@ -377,7 +377,7 @@ Script_keeptextopen: ; 0x96edc Script_yesorno: ; 0x96eed ; script command 0x4e - call $1dcf + call Function1dcf ld a, $0 jr c, .asm_96ef6 ; 0x96ef2 $2 ld a, $1 @@ -397,16 +397,16 @@ Script_loadmenudata: ; 0x96efa ld h, a ld de, $1d35 ld a, [ScriptBank] - call $26b7 - call $1ad2 + call Function26b7 + call Function1ad2 ret ; 0x96f0f Script_writebackup: ; 0x96f0f ; script command 0x50 - call $1c17 - call $1ad2 + call Function1c17 + call Function1ad2 ret ; 0x96f16 @@ -470,7 +470,7 @@ Script_storetext: ; 0x96f52 ; pointer (PointerLabelBeforeBank) ; memory (SingleByteParam) - call $106c + call Function106c call GetScriptByte ld c, a ld a, $47 @@ -539,7 +539,7 @@ Script_verbosegiveitem2: ; 0x96f8e ld a, [de] ld [$d10c], a ld hl, $d892 - call $2f66 + call Function2f66 ld a, $1 jr c, .asm_96fb0 ; 0x96fad $1 xor a @@ -561,7 +561,7 @@ Script_itemnotify: ; 0x96fc6 call CurItemName ld b, BANK(PutItemInPocketText) ld hl, PutItemInPocketText - call $269a + call Function269a ret ; 0x96fd5 @@ -572,7 +572,7 @@ Script_pocketisfull: ; 0x96fd5 call CurItemName ld b, BANK(PocketIsFullText) ld hl, PocketIsFullText - call $269a + call Function269a ret ; 0x96fe4 @@ -732,7 +732,7 @@ Script_askforphonenumber: ; 0x970be ; parameters: ; number (SingleByteParam) - call $1dcf + call Function1dcf jr c, .asm_970d6 ; 0x970c1 $13 call GetScriptByte ld c, a @@ -814,7 +814,7 @@ Script_trainertext: ; 0x9710f ld l, a ld a, [$d03e] ld b, a - call $269a + call Function269a ret ; 0x97125 @@ -843,7 +843,7 @@ Script_trainerstatus: ; 0x97132 ld d, [hl] call GetScriptByte ld b, a - call BitTable1Func + call EventFlagAction ld a, c and a ret z @@ -907,7 +907,7 @@ Script_playrammusic: ; 0x9717a Script_playmapmusic: ; 0x97185 ; script command 0x82 - call $3cdf + call Function3cdf ret ; 0x97189 @@ -988,7 +988,7 @@ Script_cry: ; 0x971d1 jr nz, .asm_971df ; 0x971da $3 ld a, [$c2dd] .asm_971df - call $37ce + call Function37ce ret ; 0x971e3 @@ -1039,7 +1039,7 @@ Function971fa: ; 971fa ld h, a ld a, [ScriptBank] ld b, a - call $26c7 + call Function26c7 ret c ld a, SCRIPT_WAIT_MOVEMENT ld [ScriptMode], a @@ -1145,13 +1145,13 @@ Script_spriteface: ; 0x97274 Unknown_0x9728b: ; 0x9728b ld a, d push de - call $18de + call Function18de jr c, .asm_972b9 ; 0x97290 $27 ld hl, $0000 add hl, bc ld a, [hl] push bc - call $1836 + call Function1836 pop bc jr c, .asm_972b9 ; 0x9729c $1b ld hl, $0004 @@ -1160,13 +1160,13 @@ Unknown_0x9728b: ; 0x9728b jr nz, .asm_972b9 ; 0x972a4 $13 pop de ld a, e - call $1af8 + call Function1af8 ld hl, $d0ed bit 6, [hl] jr nz, .asm_972b5 ; 0x972b0 $3 call Unknown_0x972bc .asm_972b5 - call $1ad2 + call Function1ad2 ret .asm_972b9 pop de @@ -1175,7 +1175,7 @@ Unknown_0x9728b: ; 0x9728b ; 0x972bc Unknown_0x972bc: ; 0x972bc - call $217a + call Function217a ld hl, TileMap ld bc, $0168 .asm_972c5 @@ -1211,7 +1211,7 @@ Script_appear: ; 0x972dd call GetScriptByte call Unknown_0x971e3 - call $1956 + call Function1956 ld a, [$ffaf] ld b, $0 call Unknown_0x9730b @@ -1229,7 +1229,7 @@ Script_disappear: ; 0x972ee jr nz, .asm_972fa ; 0x972f6 $2 ld a, [$ffe0] .asm_972fa - call $199f + call Function199f ld a, [$ffaf] ld b, $1 call Unknown_0x9730b @@ -1241,7 +1241,7 @@ Script_disappear: ; 0x972ee Unknown_0x9730b: ; 0x9730b push bc - call $18d2 + call GetMapObject ld hl, $000c add hl, bc pop bc @@ -1256,7 +1256,7 @@ Unknown_0x9730b: ; 0x9730b xor a ret .asm_97321 - call BitTable1Func + call EventFlagAction ret ; 0x97325 @@ -1497,9 +1497,9 @@ Script_loadtrainer: ; 0x97424 Script_startbattle: ; 0x97436 ; script command 0x5f - call $2879 - ld a, $16 - call $2d83 + call Function2879 + ld a, PREDEF_START_BATTLE + call Predef ld a, [$d0ee] and $3f ld [$c2dd], a @@ -1513,7 +1513,7 @@ Script_catchtutorial: ; 0x97447 call GetScriptByte ld [$d230], a - call $2879 + call Function2879 ld a, $13 ld hl, $6554 rst $8 @@ -1559,7 +1559,7 @@ Script_reloadmap: ; 0x97491 ld a, $f3 ld [$ff9f], a ld a, $1 - call $261b + call Function261b call StopScript ret ; 0x974a2 @@ -1835,7 +1835,7 @@ Script_priorityjump: ; 0x975aa Script_checktriggers: ; 0x975c2 ; script command 0x13 - call $211b + call Function211b jr z, .asm_975cb ; 0x975c5 $4 ld [$c2dd], a ret @@ -1855,7 +1855,7 @@ Script_checkmaptriggers: ; 0x975d1 ld b, a call GetScriptByte ld c, a - call $2147 + call Function2147 ld a, d or e jr z, .asm_975e5 ; 0x975de $5 @@ -1894,7 +1894,7 @@ Script_domaptrigger: ; 0x975f5 ; fallthrough Unknown_975fd: ; 0x975fd - call $2147 + call Function2147 ld a, d or e jr z, .asm_97608 ; 0x97602 $4 @@ -1988,7 +1988,7 @@ Script_random: ; 0x97640 ld b, a .asm_97653 push bc - call $2f8c + call Random pop bc ld a, [$ffe1] cp b @@ -1996,7 +1996,7 @@ Script_random: ; 0x97640 jr .asm_97666 ; 0x9765d $7 .asm_9765f push bc - call $2f8c + call Random pop bc ld a, [$ffe1] .asm_97666 @@ -2004,7 +2004,7 @@ Script_random: ; 0x97640 ld a, [$c2dd] ld c, a pop af - call $3110 + call SimpleDivide ld [$c2dd], a ret ; 0x97673 @@ -2091,7 +2091,7 @@ Script_pokenamemem: ; 0x976ae ld a, [$c2dd] .asm_976b7 ld [$d265], a - call $343b + call GetPokemonName ld de, StringBuffer1 Unknown_976c0: ; 0x976c0 @@ -2205,7 +2205,7 @@ Script_readmoney: ; 0x97732 call Unknown_0x97861 ld hl, StringBuffer1 ld bc, $4306 - call $3198 + call PrintNum ld de, StringBuffer1 jp Unknown_976c0 ; 0x97747 @@ -2217,9 +2217,9 @@ Script_readcoins: ; 0x97747 call Unknown_0x97771 ld hl, StringBuffer1 - ld de, $d855 + ld de, Coins ld bc, $4206 - call $3198 + call PrintNum ld de, StringBuffer1 jp Unknown_976c0 ; 0x9775c @@ -2233,7 +2233,7 @@ Script_RAM2MEM: ; 0x9775c ld de, $c2dd ld hl, StringBuffer1 ld bc, $4103 - call $3198 + call PrintNum ld de, StringBuffer1 jp Unknown_976c0 ; 0x97771 @@ -2320,7 +2320,7 @@ Script_giveitem: ; 0x977ca call GetScriptByte ld [$d10c], a ld hl, $d892 - call $2f66 + call Function2f66 jr nc, .asm_977eb ; 0x977e3 $6 ld a, $1 ld [$c2dd], a @@ -2346,7 +2346,7 @@ Script_takeitem: ; 0x977f0 ld a, $ff ld [$d107], a ld hl, $d892 - call $2f53 + call Function2f53 ret nc ld a, $1 ld [$c2dd], a @@ -2363,7 +2363,7 @@ Script_checkitem: ; 0x97812 call GetScriptByte ld [$d106], a ld hl, $d892 - call $2f79 + call PickUpItem ret nc ld a, $1 ld [$c2dd], a @@ -2677,7 +2677,7 @@ Script_setbit1: ; 0x97988 call GetScriptByte ld d, a ld b, $1 - call BitTable1Func + call EventFlagAction ret ; 0x97996 @@ -2691,7 +2691,7 @@ Script_clearbit1: ; 0x97996 call GetScriptByte ld d, a ld b, $0 - call BitTable1Func + call EventFlagAction ret ; 0x979a4 @@ -2705,7 +2705,7 @@ Script_checkbit1: ; 0x979a4 call GetScriptByte ld d, a ld b, $2 - call BitTable1Func + call EventFlagAction ld a, c and a jr z, .asm_979b7 ; 0x979b3 $2 @@ -2839,7 +2839,7 @@ Script_warp: ; 0x97a1d ld a, $f1 ld [$ff9f], a ld a, $1 - call $261b + call Function261b call StopScript ret .asm_97a4a @@ -2851,7 +2851,7 @@ Script_warp: ; 0x97a1d ld a, $fb ld [$ff9f], a ld a, $1 - call $261b + call Function261b call StopScript ret ; 0x97a65 @@ -2935,8 +2935,8 @@ Script_changemap: ; 0x97ab3 ld [$d1a1], a call GetScriptByte ld [$d1a2], a - call $24e4 - call $2879 + call Function24e4 + call Function2879 ret ; 0x97acc @@ -2953,10 +2953,10 @@ Script_changeblock: ; 0x97acc call GetScriptByte add $4 ld e, a - call $2a66 + call Function2a66 call GetScriptByte ld [hl], a - call $2879 + call Function2879 ret ; 0x97ae3 @@ -2965,19 +2965,19 @@ Script_reloadmappart: ; 0x97ae3 xor a ld [$ffd4], a - call $2173 - call $2914 + call Function2173 + call Function2914 ld a, $41 ld hl, $4061 rst $8 - call $1ad2 + call Function1ad2 ret ; 0x97af6 Script_warpcheck: ; 0x97af6 ; script command 0x8e - call $224a + call Function224a ret nc callba Function966d0 ret @@ -2996,7 +2996,7 @@ Script_newloadmap: ; 0x97b08 call GetScriptByte ld [$ff9f], a ld a, $1 - call $261b + call Function261b call StopScript ret ; 0x97b16 @@ -3011,7 +3011,7 @@ Script_reloadandreturn: ; 0x97b16 Script_loadfont: ; 0x97b1c ; script command 0x47 - call $2e08 + call Function2e08 ret ; 0x97b20 @@ -3020,7 +3020,7 @@ Script_refreshscreen: ; 0x97b20 ; parameters: ; dummy (SingleByteParam) - call $2dba + call ResetWindow call GetScriptByte ret ; 0x97b27 @@ -3043,8 +3043,8 @@ LoadMoveSpritesScript: ; 97b2e Script_loadmovesprites: ; 0x97b2f ; script command 0x49 - call $2e20 - call $2dcf + call Function2e20 + call Function2dcf ret ; 0x97b36 @@ -3206,7 +3206,7 @@ Script_credits: ; 0x97bf3 DisplayCredits: call Script_resetfuncs ld a, $3 - call $261b + call Function261b call StopScript ret ; 0x97c05 diff --git a/engine/serial.asm b/engine/serial.asm new file mode 100644 index 000000000..fca9d82c3 --- /dev/null +++ b/engine/serial.asm @@ -0,0 +1,408 @@ +Serial: ; 6ef +; The serial interrupt. + + push af + push bc + push de + push hl + + ld a, [$ffc9] + and a + jr nz, .asm_71c + + ld a, [$c2d4] + bit 0, a + jr nz, .asm_721 + + ld a, [$ffcb] + inc a + jr z, .asm_726 + + ld a, [rSB] + ld [hSerialReceive], a + + ld a, [hSerialSend] + ld [rSB], a + + ld a, [$ffcb] + cp $2 + jr z, .asm_752 + + ld a, 0 << rSC_ON + ld [rSC], a + ld a, 1 << rSC_ON + ld [rSC], a + jr .asm_752 + +.asm_71c + call Function3e80 + jr .asm_75a + +.asm_721 + call Function2057 + jr .asm_75a + +.asm_726 + ld a, [rSB] + cp $1 + jr z, .asm_730 + cp $2 + jr nz, .asm_752 + +.asm_730 + ld [hSerialReceive], a + ld [$ffcb], a + cp $2 + jr z, .asm_74f + + xor a + ld [rSB], a + ld a, $3 + ld [rDIV], a + +.asm_73f + ld a, [rDIV] + bit 7, a + jr nz, .asm_73f + + ld a, 0 << rSC_ON + ld [rSC], a + ld a, 1 << rSC_ON + ld [rSC], a + jr .asm_752 + +.asm_74f + xor a + ld [rSB], a + +.asm_752 + ld a, $1 + ld [$ffca], a + ld a, $fe + ld [hSerialSend], a + +.asm_75a + pop hl + pop de + pop bc + pop af + reti +; 75f + +Function75f: ; 75f + ld a, $1 + ld [$ffcc], a +.asm_763 + ld a, [hl] + ld [hSerialSend], a + call Function78a + push bc + ld b, a + inc hl + ld a, $30 +.asm_76e + dec a + jr nz, .asm_76e + ld a, [$ffcc] + and a + ld a, b + pop bc + jr z, .asm_782 + dec hl + cp $fd + jr nz, .asm_763 + xor a + ld [$ffcc], a + jr .asm_763 + +.asm_782 + ld [de], a + inc de + dec bc + ld a, b + or c + jr nz, .asm_763 + ret +; 78a + +Function78a: ; 78a + xor a + ld [$ffca], a + ld a, [$ffcb] + cp $2 + jr nz, .asm_79b + ld a, $1 + ld [rSC], a + ld a, $81 + ld [rSC], a + +.asm_79b + ld a, [$ffca] + and a + jr nz, .asm_7e5 + ld a, [$ffcb] + cp $1 + jr nz, .asm_7c0 + call Function82b + jr z, .asm_7c0 + call .asm_825 + push hl + ld hl, $cf5c + inc [hl] + jr nz, .asm_7b7 + dec hl + inc [hl] + +.asm_7b7 + pop hl + call Function82b + jr nz, .asm_79b + jp Function833 + +.asm_7c0 + ld a, [rIE] + and $f + cp $8 + jr nz, .asm_79b + ld a, [$cf5d] + dec a + ld [$cf5d], a + jr nz, .asm_79b + ld a, [$cf5e] + dec a + ld [$cf5e], a + jr nz, .asm_79b + ld a, [$ffcb] + cp $1 + jr z, .asm_7e5 + ld a, $ff +.asm_7e2 + dec a + jr nz, .asm_7e2 + +.asm_7e5 + xor a + ld [$ffca], a + ld a, [rIE] + and $f + sub $8 + jr nz, .asm_7f8 + ld [$cf5d], a + ld a, $50 + ld [$cf5e], a + +.asm_7f8 + ld a, [hSerialReceive] + cp $fe + ret nz + call Function82b + jr z, .asm_813 + push hl + ld hl, $cf5c + ld a, [hl] + dec a + ld [hld], a + inc a + jr nz, .asm_80d + dec [hl] + +.asm_80d + pop hl + call Function82b + jr z, Function833 + +.asm_813 + ld a, [rIE] + and $f + cp $8 + ld a, $fe + ret z + ld a, [hl] + ld [hSerialSend], a + call DelayFrame + jp Function78a + +.asm_825 + ld a, $f +.asm_827 + dec a + jr nz, .asm_827 + ret +; 82b + +Function82b: ; 82b + push hl + ld hl, $cf5b + ld a, [hli] + or [hl] + pop hl + ret +; 833 + +Function833: ; 833 + dec a + ld [$cf5b], a + ld [$cf5c], a + ret +; 83b + +Function83b: ; 83b + ld hl, $cf56 + ld de, $cf51 + ld c, $2 + ld a, $1 + ld [$ffcc], a +.asm_847 + call DelayFrame + ld a, [hl] + ld [hSerialSend], a + call Function78a + ld b, a + inc hl + ld a, [$ffcc] + and a + ld a, $0 + ld [$ffcc], a + jr nz, .asm_847 + ld a, b + ld [de], a + inc de + dec c + jr nz, .asm_847 + ret +; 862 + +Function862: ; 862 + call Function309d + callab Function4000 + call Function87d + jp Function30b4 +; 871 + + +Function871: ; 871 + call Function309d + callab Function4000 + jp Function87d +; 87d + + + +Function87d: ; 87d + ld a, $ff + ld [$cf52], a +.asm_882 + call Function8c1 + call DelayFrame + call Function82b + jr z, .asm_89e + push hl + ld hl, $cf5c + dec [hl] + jr nz, .asm_89d + dec hl + dec [hl] + jr nz, .asm_89d + pop hl + xor a + jp Function833 + +.asm_89d + pop hl + +.asm_89e + ld a, [$cf52] + inc a + jr z, .asm_882 + ld b, $a +.asm_8a6 + call DelayFrame + call Function8c1 + dec b + jr nz, .asm_8a6 + ld b, $a +.asm_8b1 + call DelayFrame + call Function908 + dec b + jr nz, .asm_8b1 + ld a, [$cf52] + ld [$cf51], a + ret +; 8c1 + +Function8c1: ; 8c1 + push bc + ld b, $60 + ld a, [InLinkBattle] + cp $1 + jr z, .asm_8d7 + ld b, $60 + jr c, .asm_8d7 + cp $2 + ld b, $70 + jr z, .asm_8d7 + ld b, $80 + +.asm_8d7 + call Function8f3 + ld a, [$cf56] + add b + ld [hSerialSend], a + ld a, [$ffcb] + cp $2 + jr nz, .asm_8ee + ld a, $1 + ld [rSC], a + ld a, $81 + ld [rSC], a + +.asm_8ee + call Function8f3 + pop bc + ret +; 8f3 + +Function8f3: ; 8f3 + ld a, [hSerialReceive] + ld [$cf51], a + and $f0 + cp b + ret nz + xor a + ld [hSerialReceive], a + ld a, [$cf51] + and $f + ld [$cf52], a + ret +; 908 + +Function908: ; 908 + xor a + ld [hSerialSend], a + ld a, [$ffcb] + cp $2 + ret nz + ld a, $1 + ld [rSC], a + ld a, $81 + ld [rSC], a + ret +; 919 + +Function919: ; 919 + ld a, [InLinkBattle] + and a + ret nz + ld a, $2 + ld [rSB], a + xor a + ld [hSerialReceive], a + ld a, $0 + ld [rSC], a + ld a, $80 + ld [rSC], a + ret +; 92e + + diff --git a/engine/time.asm b/engine/time.asm new file mode 100644 index 000000000..fff52b173 --- /dev/null +++ b/engine/time.asm @@ -0,0 +1,311 @@ +; Functions relating to the timer interrupt and the real-time-clock. + + +AskTimer: ; 591 + push af + ld a, [$ffe9] + and a + jr z, .asm_59a + call Timer + +.asm_59a + pop af + reti +; 59c + + +LatchClock: ; 59c +; latch clock counter data + ld a, 0 + ld [MBC3LatchClock], a + ld a, 1 + ld [MBC3LatchClock], a + ret +; 5a7 + + +UpdateTime: ; 5a7 + call GetClock + call FixDays + call FixTime + callba GetTimeOfDay + ret +; 5b7 + + +GetClock: ; 5b7 +; store clock data in hRTCDayHi-hRTCSeconds + +; enable clock r/w + ld a, SRAM_ENABLE + ld [MBC3SRamEnable], a + +; clock data is 'backwards' in hram + + call LatchClock + ld hl, MBC3SRamBank + ld de, MBC3RTC + + ld [hl], RTC_S + ld a, [de] + and $3f + ld [hRTCSeconds], a + + ld [hl], RTC_M + ld a, [de] + and $3f + ld [hRTCMinutes], a + + ld [hl], RTC_H + ld a, [de] + and $1f + ld [hRTCHours], a + + ld [hl], RTC_DL + ld a, [de] + ld [hRTCDayLo], a + + ld [hl], RTC_DH + ld a, [de] + ld [hRTCDayHi], a + +; unlatch clock / disable clock r/w + call CloseSRAM + ret +; 5e8 + + +FixDays: ; 5e8 +; fix day count +; mod by 140 + +; check if day count > 255 (bit 8 set) + ld a, [hRTCDayHi] ; DH + bit 0, a + jr z, .daylo +; reset dh (bit 8) + res 0, a + ld [hRTCDayHi], a ; DH + +; mod 140 +; mod twice since bit 8 (DH) was set + ld a, [hRTCDayLo] ; DL +.modh + sub 140 + jr nc, .modh +.modl + sub 140 + jr nc, .modl + add 140 + +; update dl + ld [hRTCDayLo], a ; DL + +; unknown output + ld a, $40 ; %1000000 + jr .set + +.daylo +; quit if fewer than 140 days have passed + ld a, [hRTCDayLo] ; DL + cp 140 + jr c, .quit + +; mod 140 +.mod + sub 140 + jr nc, .mod + add 140 + +; update dl + ld [hRTCDayLo], a ; DL + +; unknown output + ld a, $20 ; %100000 + +.set +; update clock with modded day value + push af + call SetClock + pop af + scf + ret + +.quit + xor a + ret +; 61d + + +FixTime: ; 61d +; add ingame time (set at newgame) to current time +; day hr min sec +; store time in CurDay, hHours, hMinutes, hSeconds + +; second + ld a, [hRTCSeconds] ; S + ld c, a + ld a, [StartSecond] + add c + sub 60 + jr nc, .updatesec + add 60 +.updatesec + ld [hSeconds], a + +; minute + ccf ; carry is set, so turn it off + ld a, [hRTCMinutes] ; M + ld c, a + ld a, [StartMinute] + adc c + sub 60 + jr nc, .updatemin + add 60 +.updatemin + ld [hMinutes], a + +; hour + ccf ; carry is set, so turn it off + ld a, [hRTCHours] ; H + ld c, a + ld a, [StartHour] + adc c + sub 24 + jr nc, .updatehr + add 24 +.updatehr + ld [hHours], a + +; day + ccf ; carry is set, so turn it off + ld a, [hRTCDayLo] ; DL + ld c, a + ld a, [StartDay] + adc c + ld [CurDay], a + ret +; 658 + +Function658: ; 658 + xor a + ld [StringBuffer2], a + ld a, $0 + ld [$d089], a + jr .asm_677 + + call UpdateTime + ld a, [hHours] + ld [$d087], a + ld a, [hMinutes] + ld [$d088], a + ld a, [hSeconds] + ld [$d089], a + jr .asm_677 + +.asm_677 + ld a, $5 + ld hl, $40ed + rst FarCall + ret +; 67e + + + +Function67e: ; 67e + call Function685 + call SetClock + ret +; 685 + +Function685: ; 685 + xor a + ld [hRTCSeconds], a + ld [hRTCMinutes], a + ld [hRTCHours], a + ld [hRTCDayLo], a + ld [hRTCDayHi], a + ret +; 691 + + +SetClock: ; 691 +; set clock data from hram + +; enable clock r/w + ld a, SRAM_ENABLE + ld [MBC3SRamEnable], a + +; set clock data +; stored 'backwards' in hram + + call LatchClock + ld hl, MBC3SRamBank + ld de, MBC3RTC + +; seems to be a halt check that got partially commented out +; this block is totally pointless + ld [hl], RTC_DH + ld a, [de] + bit 6, a ; halt + ld [de], a + +; seconds + ld [hl], RTC_S + ld a, [hRTCSeconds] + ld [de], a +; minutes + ld [hl], RTC_M + ld a, [hRTCMinutes] + ld [de], a +; hours + ld [hl], RTC_H + ld a, [hRTCHours] + ld [de], a +; day lo + ld [hl], RTC_DL + ld a, [hRTCDayLo] + ld [de], a +; day hi + ld [hl], RTC_DH + ld a, [hRTCDayHi] + res 6, a ; make sure timer is active + ld [de], a + +; cleanup + call CloseSRAM ; unlatch clock, disable clock r/w + ret +; 6c4 + + +Function6c4: ; 6c4 + xor a + push af + ld a, $0 + call GetSRAMBank + pop af + ld [$ac60], a + call CloseSRAM + ret +; 6d3 + +Function6d3: ; 6d3 + ld hl, $ac60 + push af + ld a, $0 + call GetSRAMBank + pop af + or [hl] + ld [hl], a + call CloseSRAM + ret +; 6e3 + +Function6e3: ; 6e3 + ld a, $0 + call GetSRAMBank + ld a, [$ac60] + call CloseSRAM + ret +; 6ef + diff --git a/engine/vblank.asm b/engine/vblank.asm index 6a319356c..44b3195f8 100644 --- a/engine/vblank.asm +++ b/engine/vblank.asm @@ -6,6 +6,8 @@ ; This prevents the display and audio output from lagging. + +VBlank: ; 283 push af push bc push de @@ -26,7 +28,7 @@ ld l, a ; down to business - call JpHl + call _hl_ ; since this is called once per frame call GameTimer diff --git a/extras b/extras index 4c56a6c57..4998994c9 160000 --- a/extras +++ b/extras @@ -1 +1 @@ -Subproject commit 4c56a6c57a4c21acff5dcf5aa1c23138f0a743c3 +Subproject commit 4998994c9a624f6298f8a54a665c788825c3e8f9 diff --git a/gbhw.asm b/gbhw.asm index 6f2c68c97..0f12e4842 100644 --- a/gbhw.asm +++ b/gbhw.asm @@ -21,15 +21,29 @@ RTC_DH EQU $0c ; Upper 1 bit of Day Counter, Carry Bit, Halt Flag ; Bit 6 Halt (0=Active, 1=Stop Timer) ; Bit 7 Day Counter Carry Bit (1=Counter Overflow) +; interrupt flags +VBLANK EQU 0 +LCD_STAT EQU 1 +TIMER EQU 2 +SERIAL EQU 3 +JOYPAD EQU 4 ; Hardware registers rJOYP EQU $ff00 ; Joypad (R/W) rSB EQU $ff01 ; Serial transfer data (R/W) rSC EQU $ff02 ; Serial Transfer Control (R/W) +rSC_ON EQU 7 +rSC_CGB EQU 1 +rSC_CLOCK EQU 0 rDIV EQU $ff04 ; Divider Register (R/W) rTIMA EQU $ff05 ; Timer counter (R/W) rTMA EQU $ff06 ; Timer Modulo (R/W) rTAC EQU $ff07 ; Timer Control (R/W) +rTAC_ON EQU 2 +rTAC_4096_HZ EQU 0 +rTAC_262144_HZ EQU 1 +rTAC_65536_HZ EQU 2 +rTAC_16384_HZ EQU 3 rIF EQU $ff0f ; Interrupt Flag (R/W) rNR10 EQU $ff10 ; Channel 1 Sweep register (R/W) rNR11 EQU $ff11 ; Channel 1 Sound length/Wave pattern duty (R/W) diff --git a/hram.asm b/hram.asm index d8e8d0f34..051d4186a 100644 --- a/hram.asm +++ b/hram.asm @@ -41,6 +41,9 @@ hMathBuffer EQU $ffb8 hLCDStatCustom EQU $ffc6 +hSerialSend EQU $ffcd +hSerialReceive EQU $ffce + hSCX EQU $ffcf hSCY EQU $ffd0 hWX EQU $ffd1 diff --git a/items/item_effects.asm b/items/item_effects.asm index cdca23be0..342f61926 100644 --- a/items/item_effects.asm +++ b/items/item_effects.asm @@ -166,7 +166,7 @@ ParkBall: ; e8a2 .asm_e98e ld b, a ld [MagikarpLength], a - call RNG + call Random cp b ld a, $0 @@ -1212,7 +1212,7 @@ BitterBerry: ; f16a call $7789 ld hl, $4d81 - call FarBattleTextBox + call StdBattleTextBox ld a, $0 diff --git a/main.asm b/main.asm index 13021b926..077205a37 100644 --- a/main.asm +++ b/main.asm @@ -4,7 +4,7 @@ SECTION "rst0",ROM0[$0] jp Start SECTION "rst8",ROM0[$8] ; FarCall - jp FarJpHl + jp FarCall_hl SECTION "rst10",ROM0[$10] ; Bankswitch ld [hROMBank], a @@ -38,13 +38,13 @@ SECTION "vblank",ROM0[$40] ; vblank interrupt jp VBlank SECTION "lcd",ROM0[$48] ; lcd interrupt - jp Function552 + jp LCD SECTION "timer",ROM0[$50] ; timer interrupt - jp Function3e93 + jp Timer SECTION "serial",ROM0[$58] ; serial interrupt - jp Function6ef + jp Serial SECTION "joypad",ROM0[$60] ; joypad interrupt jp JoypadInt @@ -58,7 +58,7 @@ SECTION "start",ROM0[$150] INCLUDE "engine/init.asm" -VBlank: ; 283 + INCLUDE "engine/vblank.asm" @@ -100,7 +100,6 @@ RTC: ; 46f ld a, [VramState] bit 0, a ; obj update ret z -; 47e TimeOfDayPals: ; 47e callab _TimeOfDayPals @@ -113,1987 +112,29 @@ Function485: ; 485 ret ; 48c -Function48c: ; 48c - ld a, [TimeOfDayPal] - ld b, a - ld hl, IncGradGBPalTable_11 - ld a, l - sub b - ld l, a - jr nc, .asm_499 - dec h -.asm_499 - ld a, [hli] - ld [rBGP], a - ld a, [hli] - ld [rOBP0], a - ld a, [hli] - ld [rOBP1], a - ret -; 4a3 +INCLUDE "engine/fade.asm" -Function4a3: ; 4a3 - ld a, [hCGB] - and a - jr z, .asm_4af - ld hl, IncGradGBPalTable_00 - ld b, $4 - jr Function4c7 +INCLUDE "engine/lcd.asm" -.asm_4af - ld hl, IncGradGBPalTable_08 - ld b, $4 - jr Function4c7 -; 4b6 -Function4b6: ; 4b6 - ld a, [hCGB] - and a - jr z, .asm_4c2 - ld hl, IncGradGBPalTable_05 - ld b, $3 - jr Function4c7 +INCLUDE "engine/time.asm" -.asm_4c2 - ld hl, IncGradGBPalTable_13 - ld b, $3 -; 4c7 - -Function4c7: ; 4c7 -.asm_4c7 - push de - ld a, [hli] - call DmgToCgbBGPals - ld a, [hli] - ld e, a - ld a, [hli] - ld d, a - call DmgToCgbObjPals - ld c, $8 - call DelayFrames - pop de - dec b - jr nz, .asm_4c7 - ret -; 4dd - -Function4dd: ; 4dd - ld a, [hCGB] - and a - jr z, .asm_4e9 - ld hl, IncGradGBPalTable_04 - 1 - ld b, $4 - jr Function501 - -.asm_4e9 - ld hl, IncGradGBPalTable_12 - 1 - ld b, $4 - jr Function501 -; 4f0 - -Function4f0: ; 4f0 - ld a, [hCGB] - and a - jr z, .asm_4fc - ld hl, IncGradGBPalTable_07 - 1 - ld b, $3 - jr Function501 - -.asm_4fc - ld hl, IncGradGBPalTable_15 - 1 - ld b, $3 - ; fallthrough -; 501 - -Function501: ; 501 - push de - ld a, [hld] - ld d, a - ld a, [hld] - ld e, a - call DmgToCgbObjPals - ld a, [hld] - call DmgToCgbBGPals - ld c, $8 - call DelayFrames - pop de - dec b - jr nz, Function501 - ret -; 517 - - -IncGradGBPalTable_00: ; 517 - db %11111111 ; bgp - db %11111111 ; obp1 - db %11111111 ; obp2 - ; and so on... -IncGradGBPalTable_01: ; 51a - db %11111110 - db %11111110 - db %11111110 -IncGradGBPalTable_02: ; 51d - db %11111001 - db %11111001 - db %11111001 -IncGradGBPalTable_03: ; 520 - db %11100100 - db %11100100 - db %11100100 -IncGradGBPalTable_04: ; 523 - db %11100100 - db %11100100 - db %11100100 -IncGradGBPalTable_05: ; 526 - db %10010000 - db %10010000 - db %10010000 -IncGradGBPalTable_06: ; 529 - db %01000000 - db %01000000 - db %01000000 -IncGradGBPalTable_07: ; 52c - db %00000000 - db %00000000 - db %00000000 -; 52f - -IncGradGBPalTable_08: ; 52f - db %11111111 - db %11111111 - db %11111111 -IncGradGBPalTable_09: ; 532 - db %11111110 - db %11111110 - db %11111000 -IncGradGBPalTable_10: ; 535 - db %11111001 - db %11100100 - db %11100100 -IncGradGBPalTable_11: ; 538 - db %11100100 - db %11010000 - db %11100000 -IncGradGBPalTable_12: ; 53b - db %11100100 - db %11010000 - db %11100000 -IncGradGBPalTable_13: ; 53e - db %10010000 - db %10000000 - db %10010000 -IncGradGBPalTable_14: ; 541 - db %01000000 - db %01000000 - db %01000000 -IncGradGBPalTable_15: ; 544 - db %00000000 - db %00000000 - db %00000000 -; 547 - - -Function547: ; 547 - ld a, [hLCDStatCustom] - cp $43 - ret nz - ld c, a - ld a, [$d100] - ld [$ff00+c], a - ret -; 552 - -Function552: ; 552 - push af - ld a, [hLCDStatCustom] - and a - jr z, .asm_566 - push bc - ld a, [rLY] - ld c, a - ld b, $d1 - ld a, [bc] - ld b, a - ld a, [hLCDStatCustom] - ld c, a - ld a, b - ld [$ff00+c], a - pop bc - -.asm_566 - pop af - reti -; 568 - - - -DisableLCD: ; 568 -; Turn the LCD off -; Most of this is just going through the motions - -; don't need to do anything if lcd is already off - ld a, [rLCDC] - bit 7, a ; lcd enable - ret z - -; reset ints - xor a - ld [rIF], a - -; save enabled ints - ld a, [rIE] - ld b, a - -; disable vblank - res 0, a ; vblank - ld [rIE], a - -.wait -; wait until vblank - ld a, [rLY] - cp 145 ; >144 (ensure beginning of vblank) - jr nz, .wait - -; turn lcd off - ld a, [rLCDC] - and %01111111 ; lcd enable off - ld [rLCDC], a - -; reset ints - xor a - ld [rIF], a - -; restore enabled ints - ld a, b - ld [rIE], a - ret -; 58a - - -EnableLCD: ; 58a - ld a, [rLCDC] - set 7, a ; lcd enable - ld [rLCDC], a - ret -; 591 - - -AskTimer: ; 591 - push af - ld a, [$ffe9] - and a - jr z, .asm_59a - call Function3e93 - -.asm_59a - pop af - reti -; 59c - - -LatchClock: ; 59c -; latch clock counter data - ld a, 0 - ld [MBC3LatchClock], a - ld a, 1 - ld [MBC3LatchClock], a - ret -; 5a7 - - -UpdateTime: ; 5a7 -; get rtc data - call GetClock -; condense days to one byte, update rtc w/ new day count - call FixDays -; add game time to rtc time - call FixTime -; update time of day (0 = morn, 1 = day, 2 = nite) - callba GetTimeOfDay - ret -; 5b7 - - -GetClock: ; 5b7 -; store clock data in hRTCDayHi-hRTCSeconds - -; enable clock r/w - ld a, SRAM_ENABLE - ld [MBC3SRamEnable], a - -; get clock data -; stored 'backwards' in hram - - call LatchClock - ld hl, MBC3SRamBank - ld de, MBC3RTC - -; seconds - ld [hl], RTC_S - ld a, [de] - and $3f - ld [hRTCSeconds], a -; minutes - ld [hl], RTC_M - ld a, [de] - and $3f - ld [hRTCMinutes], a -; hours - ld [hl], RTC_H - ld a, [de] - and $1f - ld [hRTCHours], a -; day lo - ld [hl], RTC_DL - ld a, [de] - ld [hRTCDayLo], a -; day hi - ld [hl], RTC_DH - ld a, [de] - ld [hRTCDayHi], a - -; cleanup - call CloseSRAM ; unlatch clock, disable clock r/w - ret -; 5e8 - - -FixDays: ; 5e8 -; fix day count -; mod by 140 - -; check if day count > 255 (bit 8 set) - ld a, [hRTCDayHi] ; DH - bit 0, a - jr z, .daylo -; reset dh (bit 8) - res 0, a - ld [hRTCDayHi], a ; DH - -; mod 140 -; mod twice since bit 8 (DH) was set - ld a, [hRTCDayLo] ; DL -.modh - sub 140 - jr nc, .modh -.modl - sub 140 - jr nc, .modl - add 140 - -; update dl - ld [hRTCDayLo], a ; DL - -; unknown output - ld a, $40 ; %1000000 - jr .set - -.daylo -; quit if fewer than 140 days have passed - ld a, [hRTCDayLo] ; DL - cp 140 - jr c, .quit - -; mod 140 -.mod - sub 140 - jr nc, .mod - add 140 - -; update dl - ld [hRTCDayLo], a ; DL - -; unknown output - ld a, $20 ; %100000 - -.set -; update clock with modded day value - push af - call SetClock - pop af - scf - ret - -.quit - xor a - ret -; 61d - - -FixTime: ; 61d -; add ingame time (set at newgame) to current time -; day hr min sec -; store time in CurDay, hHours, hMinutes, hSeconds - -; second - ld a, [hRTCSeconds] ; S - ld c, a - ld a, [StartSecond] - add c - sub 60 - jr nc, .updatesec - add 60 -.updatesec - ld [hSeconds], a - -; minute - ccf ; carry is set, so turn it off - ld a, [hRTCMinutes] ; M - ld c, a - ld a, [StartMinute] - adc c - sub 60 - jr nc, .updatemin - add 60 -.updatemin - ld [hMinutes], a - -; hour - ccf ; carry is set, so turn it off - ld a, [hRTCHours] ; H - ld c, a - ld a, [StartHour] - adc c - sub 24 - jr nc, .updatehr - add 24 -.updatehr - ld [hHours], a - -; day - ccf ; carry is set, so turn it off - ld a, [hRTCDayLo] ; DL - ld c, a - ld a, [StartDay] - adc c - ld [CurDay], a - ret -; 658 - -Function658: ; 658 - xor a - ld [StringBuffer2], a - ld a, $0 - ld [$d089], a - jr .asm_677 - - call UpdateTime - ld a, [hHours] - ld [$d087], a - ld a, [hMinutes] - ld [$d088], a - ld a, [hSeconds] - ld [$d089], a - jr .asm_677 - -.asm_677 - ld a, $5 - ld hl, $40ed - rst FarCall - ret -; 67e - - - -Function67e: ; 67e - call Function685 - call SetClock - ret -; 685 - -Function685: ; 685 - xor a - ld [hRTCSeconds], a - ld [hRTCMinutes], a - ld [hRTCHours], a - ld [hRTCDayLo], a - ld [hRTCDayHi], a - ret -; 691 - - -SetClock: ; 691 -; set clock data from hram - -; enable clock r/w - ld a, SRAM_ENABLE - ld [MBC3SRamEnable], a - -; set clock data -; stored 'backwards' in hram - - call LatchClock - ld hl, MBC3SRamBank - ld de, MBC3RTC - -; seems to be a halt check that got partially commented out -; this block is totally pointless - ld [hl], RTC_DH - ld a, [de] - bit 6, a ; halt - ld [de], a - -; seconds - ld [hl], RTC_S - ld a, [hRTCSeconds] - ld [de], a -; minutes - ld [hl], RTC_M - ld a, [hRTCMinutes] - ld [de], a -; hours - ld [hl], RTC_H - ld a, [hRTCHours] - ld [de], a -; day lo - ld [hl], RTC_DL - ld a, [hRTCDayLo] - ld [de], a -; day hi - ld [hl], RTC_DH - ld a, [hRTCDayHi] - res 6, a ; make sure timer is active - ld [de], a - -; cleanup - call CloseSRAM ; unlatch clock, disable clock r/w - ret -; 6c4 - - -Function6c4: ; 6c4 - xor a - push af - ld a, $0 - call GetSRAMBank - pop af - ld [$ac60], a - call CloseSRAM - ret -; 6d3 - -Function6d3: ; 6d3 - ld hl, $ac60 - push af - ld a, $0 - call GetSRAMBank - pop af - or [hl] - ld [hl], a - call CloseSRAM - ret -; 6e3 - -Function6e3: ; 6e3 - ld a, $0 - call GetSRAMBank - ld a, [$ac60] - call CloseSRAM - ret -; 6ef - - - -Function6ef: ; 6ef - push af - push bc - push de - push hl - ld a, [$ffc9] - and a - jr nz, .asm_71c - ld a, [$c2d4] - bit 0, a - jr nz, .asm_721 - ld a, [$ffcb] - inc a - jr z, .asm_726 - ld a, [rSB] - ld [$ffce], a - ld a, [$ffcd] - ld [rSB], a - ld a, [$ffcb] - cp $2 - jr z, .asm_752 - ld a, $0 - ld [rSC], a - ld a, $80 - ld [rSC], a - jr .asm_752 - -.asm_71c - call Function3e80 - jr .asm_75a - -.asm_721 - call Function2057 - jr .asm_75a - -.asm_726 - ld a, [rSB] - cp $1 - jr z, .asm_730 - cp $2 - jr nz, .asm_752 - -.asm_730 - ld [$ffce], a - ld [$ffcb], a - cp $2 - jr z, .asm_74f - xor a - ld [rSB], a - ld a, $3 - ld [rDIV], a -.asm_73f - ld a, [rDIV] - bit 7, a - jr nz, .asm_73f - ld a, $0 - ld [rSC], a - ld a, $80 - ld [rSC], a - jr .asm_752 - -.asm_74f - xor a - ld [rSB], a - -.asm_752 - ld a, $1 - ld [$ffca], a - ld a, $fe - ld [$ffcd], a - -.asm_75a - pop hl - pop de - pop bc - pop af - reti -; 75f - -Function75f: ; 75f - ld a, $1 - ld [$ffcc], a -.asm_763 - ld a, [hl] - ld [$ffcd], a - call $078a - push bc - ld b, a - inc hl - ld a, $30 -.asm_76e - dec a - jr nz, .asm_76e - ld a, [$ffcc] - and a - ld a, b - pop bc - jr z, .asm_782 - dec hl - cp $fd - jr nz, .asm_763 - xor a - ld [$ffcc], a - jr .asm_763 - -.asm_782 - ld [de], a - inc de - dec bc - ld a, b - or c - jr nz, .asm_763 - ret -; 78a - -Function78a: ; 78a - xor a - ld [$ffca], a - ld a, [$ffcb] - cp $2 - jr nz, .asm_79b - ld a, $1 - ld [rSC], a - ld a, $81 - ld [rSC], a - -.asm_79b - ld a, [$ffca] - and a - jr nz, .asm_7e5 - ld a, [$ffcb] - cp $1 - jr nz, .asm_7c0 - call $082b - jr z, .asm_7c0 - call $0825 - push hl - ld hl, $cf5c - inc [hl] - jr nz, .asm_7b7 - dec hl - inc [hl] - -.asm_7b7 - pop hl - call $082b - jr nz, .asm_79b - jp $0833 - -.asm_7c0 - ld a, [rIE] - and $f - cp $8 - jr nz, .asm_79b - ld a, [$cf5d] - dec a - ld [$cf5d], a - jr nz, .asm_79b - ld a, [$cf5e] - dec a - ld [$cf5e], a - jr nz, .asm_79b - ld a, [$ffcb] - cp $1 - jr z, .asm_7e5 - ld a, $ff -.asm_7e2 - dec a - jr nz, .asm_7e2 - -.asm_7e5 - xor a - ld [$ffca], a - ld a, [rIE] - and $f - sub $8 - jr nz, .asm_7f8 - ld [$cf5d], a - ld a, $50 - ld [$cf5e], a - -.asm_7f8 - ld a, [$ffce] - cp $fe - ret nz - call $082b - jr z, .asm_813 - push hl - ld hl, $cf5c - ld a, [hl] - dec a - ld [hld], a - inc a - jr nz, .asm_80d - dec [hl] - -.asm_80d - pop hl - call $082b - jr z, .asm_833 - -.asm_813 - ld a, [rIE] - and $f - cp $8 - ld a, $fe - ret z - ld a, [hl] - ld [$ffcd], a - call DelayFrame - jp $078a - - ld a, $f -.asm_827 - dec a - jr nz, .asm_827 - ret - - push hl - ld hl, $cf5b - ld a, [hli] - or [hl] - pop hl - ret - -.asm_833 - dec a - ld [$cf5b], a - ld [$cf5c], a - ret -; 83b - -Function83b: ; 83b - ld hl, $cf56 - ld de, $cf51 - ld c, $2 - ld a, $1 - ld [$ffcc], a -.asm_847 - call DelayFrame - ld a, [hl] - ld [$ffcd], a - call Function78a - ld b, a - inc hl - ld a, [$ffcc] - and a - ld a, $0 - ld [$ffcc], a - jr nz, .asm_847 - ld a, b - ld [de], a - inc de - dec c - jr nz, .asm_847 - ret -; 862 - -Function862: ; 862 - call Function309d - callab Function4000 - call Function87d - jp Function30b4 -; 871 - - -Function871: ; 871 - call Function309d - callab Function4000 - jp Function87d -; 87d - - - -Function87d: ; 87d - ld a, $ff - ld [$cf52], a -.asm_882 - call $08c1 - call DelayFrame - call $082b - jr z, .asm_89e - push hl - ld hl, $cf5c - dec [hl] - jr nz, .asm_89d - dec hl - dec [hl] - jr nz, .asm_89d - pop hl - xor a - jp $0833 - -.asm_89d - pop hl - -.asm_89e - ld a, [$cf52] - inc a - jr z, .asm_882 - ld b, $a -.asm_8a6 - call DelayFrame - call $08c1 - dec b - jr nz, .asm_8a6 - ld b, $a -.asm_8b1 - call DelayFrame - call $0908 - dec b - jr nz, .asm_8b1 - ld a, [$cf52] - ld [$cf51], a - ret -; 8c1 - -Function8c1: ; 8c1 - push bc - ld b, $60 - ld a, [InLinkBattle] - cp $1 - jr z, .asm_8d7 - ld b, $60 - jr c, .asm_8d7 - cp $2 - ld b, $70 - jr z, .asm_8d7 - ld b, $80 - -.asm_8d7 - call $08f3 - ld a, [$cf56] - add b - ld [$ffcd], a - ld a, [$ffcb] - cp $2 - jr nz, .asm_8ee - ld a, $1 - ld [rSC], a - ld a, $81 - ld [rSC], a - -.asm_8ee - call $08f3 - pop bc - ret -; 8f3 - -Function8f3: ; 8f3 - ld a, [$ffce] - ld [$cf51], a - and $f0 - cp b - ret nz - xor a - ld [$ffce], a - ld a, [$cf51] - and $f - ld [$cf52], a - ret -; 908 - -Function908: ; 908 - xor a - ld [$ffcd], a - ld a, [$ffcb] - cp $2 - ret nz - ld a, $1 - ld [rSC], a - ld a, $81 - ld [rSC], a - ret -; 919 - -Function919: ; 919 - ld a, [InLinkBattle] - and a - ret nz - ld a, $2 - ld [rSB], a - xor a - ld [$ffce], a - ld a, $0 - ld [rSC], a - ld a, $80 - ld [rSC], a - ret -; 92e +INCLUDE "engine/serial.asm" INCLUDE "engine/joypad.asm" -Functiona1b: ; a1b -.asm_a1b - call DelayFrame - push bc - call Functiona57 - pop bc - ld a, [hJoyDown] - cp $46 - jr z, .asm_a34 - ld a, [$ffa9] - and $9 - jr nz, .asm_a34 - dec c - jr nz, .asm_a1b - and a - ret - -.asm_a34 - scf - ret -; a36 - - - -Functiona36: ; a36 -.asm_a36 - call DelayFrame - call GetJoypadPublic - ld a, [hJoyPressed] - and $3 - ret nz - call RTC - jr .asm_a36 -; a46 - -Functiona46: ; a46 - ld a, [hOAMUpdate] - push af - ld a, $1 - ld [hOAMUpdate], a - call WaitBGMap - call $0a36 - pop af - ld [hOAMUpdate], a - ret -; a57 - - - -Functiona57: ; a57 - call GetJoypadPublic - ld a, [$ffaa] - and a - ld a, [hJoyPressed] - jr z, .asm_a63 - ld a, [hJoyDown] - -.asm_a63 - ld [$ffa9], a - ld a, [hJoyPressed] - and a - jr z, .asm_a70 - ld a, $f - ld [TextDelayFrames], a - ret - -.asm_a70 - ld a, [TextDelayFrames] - and a - jr z, .asm_a7a - xor a - ld [$ffa9], a - ret - -.asm_a7a - ld a, $5 - ld [TextDelayFrames], a - ret -; a80 - -Functiona80: ; a80 - ld a, [hConnectionStripLength] - push af - ld a, [hConnectedMapWidth] - push af - xor a - ld [hConnectionStripLength], a - ld a, $6 - ld [hConnectedMapWidth], a -.asm_a8d - push hl - ld hl, $c606 - call $0b06 - pop hl - call Functiona57 - ld a, [$ffa9] - and $3 - jr z, .asm_a8d - pop af - ld [hConnectedMapWidth], a - pop af - ld [hConnectionStripLength], a - ret -; aa5 - -Functionaa5: ; aa5 -.asm_aa5 - call Functiona57 - ld a, [$ffa9] - and $3 - jr z, .asm_aa5 - ret -; aaf - - - -Functionaaf: ; aaf - ld a, [InLinkBattle] - and a - jr nz, .asm_ac1 - call Functionac6 - push de - ld de, SFX_READ_TEXT_2 - call StartSFX - pop de - ret - -.asm_ac1 - ld c, $41 - jp DelayFrames -; ac6 - -Functionac6: ; ac6 - ld a, [hOAMUpdate] - push af - ld a, $1 - ld [hOAMUpdate], a - ld a, [InputType] - or a - jr z, .asm_ad9 - ld a, $77 - ld hl, $628a - rst FarCall - -.asm_ad9 - call Functionaf5 - call Functiona57 - ld a, [hJoyPressed] - and $3 - jr nz, .asm_af1 - call RTC - ld a, $1 - ld [hBGMapMode], a - call DelayFrame - jr .asm_ad9 - -.asm_af1 - pop af - ld [hOAMUpdate], a - ret -; af5 - -Functionaf5: ; af5 - ld a, [$ff9b] - and $10 - jr z, .asm_aff - ld a, $ee - jr .asm_b02 - -.asm_aff - ld a, [$c605] - -.asm_b02 - ld [$c606], a - ret -; b06 - -Functionb06: ; b06 - push bc - ld a, [hl] - ld b, a - ld a, $ee - cp b - pop bc - jr nz, .asm_b27 - ld a, [hConnectionStripLength] - dec a - ld [hConnectionStripLength], a - ret nz - ld a, [hConnectedMapWidth] - dec a - ld [hConnectedMapWidth], a - ret nz - ld a, $7a - ld [hl], a - ld a, $ff - ld [hConnectionStripLength], a - ld a, $6 - ld [hConnectedMapWidth], a - ret - -.asm_b27 - ld a, [hConnectionStripLength] - and a - ret z - dec a - ld [hConnectionStripLength], a - ret nz - dec a - ld [hConnectionStripLength], a - ld a, [hConnectedMapWidth] - dec a - ld [hConnectedMapWidth], a - ret nz - ld a, $6 - ld [hConnectedMapWidth], a - ld a, $ee - ld [hl], a - ret -; b40 - - INCLUDE "engine/decompress.asm" -UpdatePalsIfCGB: ; c2f -; update bgp data from BGPals -; update obp data from OBPals -; return carry if successful +INCLUDE "engine/palettes.asm" -; check cgb - ld a, [hCGB] - and a - ret z - -UpdateCGBPals: ; c33 -; return carry if successful -; any pals to update? - ld a, [hCGBPalUpdate] - and a - ret z - - -ForceUpdateCGBPals: ; c37 - - ld a, [rSVBK] - push af - ld a, 5 ; BANK(BGPals) - ld [rSVBK], a - - ld hl, BGPals ; 5:d080 - -; copy 8 pals to bgpd - ld a, %10000000 ; auto increment, index 0 - ld [rBGPI], a - ld c, rBGPD % $100 - ld b, 4 ; NUM_PALS / 2 -.bgp - rept $10 - ld a, [hli] - ld [$ff00+c], a - endr - - dec b - jr nz, .bgp - -; hl is now 5:d0c0 OBPals - -; copy 8 pals to obpd - ld a, %10000000 ; auto increment, index 0 - ld [rOBPI], a - ld c, rOBPD - rJOYP - ld b, 4 ; NUM_PALS / 2 -.obp - rept $10 - ld a, [hli] - ld [$ff00+c], a - endr - - dec b - jr nz, .obp - - pop af - ld [rSVBK], a - -; clear pal update queue - xor a - ld [hCGBPalUpdate], a - - scf - ret -; c9f - - -DmgToCgbBGPals: ; c9f -; exists to forego reinserting cgb-converted image data - -; input: a -> bgp - - ld [rBGP], a - push af - - ld a, [hCGB] - and a - jr z, .end - - push hl - push de - push bc - ld a, [rSVBK] - push af - - ld a, 5 - ld [rSVBK], a - -; copy & reorder bg pal buffer - ld hl, BGPals ; to - ld de, Unkn1Pals ; from -; order - ld a, [rBGP] - ld b, a -; all pals - ld c, 8 - call CopyPals -; request pal update - ld a, 1 - ld [hCGBPalUpdate], a - - pop af - ld [rSVBK], a - pop bc - pop de - pop hl -.end - pop af - ret -; ccb - - -DmgToCgbObjPals: ; ccb -; exists to forego reinserting cgb-converted image data - -; input: d -> obp1 -; e -> obp2 - - ld a, e - ld [rOBP0], a - ld a, d - ld [rOBP1], a - - ld a, [hCGB] - and a - ret z - - push hl - push de - push bc - ld a, [rSVBK] - push af - - ld a, 5 - ld [rSVBK], a - -; copy & reorder obj pal buffer - ld hl, OBPals ; to - ld de, Unkn2Pals ; from -; order - ld a, [rOBP0] - ld b, a -; all pals - ld c, 8 - call CopyPals -; request pal update - ld a, 1 - ld [hCGBPalUpdate], a - - pop af - ld [rSVBK], a - pop bc - pop de - pop hl - ret -; cf8 - - -Functioncf8: ; cf8 - ld [rOBP0], a - push af - ld a, [hCGB] - and a - jr z, .asm_d22 - push hl - push de - push bc - ld a, [rSVBK] - push af - ld a, $5 - ld [rSVBK], a - ld hl, $d0c0 - ld de, MartPointer - ld a, [rOBP0] - ld b, a - ld c, $1 - call CopyPals - ld a, $1 - ld [hCGBPalUpdate], a - pop af - ld [rSVBK], a - pop bc - pop de - pop hl - -.asm_d22 - pop af - ret -; d24 - -Functiond24: ; d24 - ld [rOBP1], a - push af - ld a, [hCGB] - and a - jr z, .asm_d4e - push hl - push de - push bc - ld a, [rSVBK] - push af - ld a, $5 - ld [rSVBK], a - ld hl, $d0c8 - ld de, $d048 - ld a, [rOBP1] - ld b, a - ld c, $1 - call CopyPals - ld a, $1 - ld [hCGBPalUpdate], a - pop af - ld [rSVBK], a - pop bc - pop de - pop hl - -.asm_d4e - pop af - ret -; d50 - - - -CopyPals: ; d50 -; copy c palettes in order b from de to hl - - push bc - ld c, 4 ; NUM_PAL_COLORS -.loop - push de - push hl - -; get pal color - ld a, b - and %11 ; color -; 2 bytes per color - add a - ld l, a - ld h, $0 - add hl, de - ld e, [hl] - inc hl - ld d, [hl] - -; dest - pop hl -; write color - ld [hl], e - inc hl - ld [hl], d - inc hl -; next pal color - srl b - srl b -; source - pop de -; done pal? - dec c - jr nz, .loop - -; de += 8 (next pal) - ld a, 8 ; NUM_PAL_COLORS * 2 ; bytes per pal - add e - jr nc, .ok - inc d -.ok - ld e, a - -; how many more pals? - pop bc - dec c - jr nz, CopyPals - ret -; d79 - - -Functiond79: ; d79 - ld a, [hCGB] - and a - ret z - ld a, $1 - ld [rVBK], a - ld hl, VTiles0 - ld bc, $2000 - xor a - call ByteFill - ld a, $0 - ld [rVBK], a - ret -; d90 - - -Functiond90: ; d90 - ret -; d91 - - -Functiond91: ; d91 - ld a, [hCGB] - and a - ret z - ld a, [rSVBK] - push af - ld a, $5 - ld [rSVBK], a - ld hl, $d080 - ld bc, $0050 - xor a - call ByteFill - pop af - ld [rSVBK], a - ld a, $1 - ld [hCGBPalUpdate], a - call DelayFrame - ret -; db1 - - -Functiondb1: ; db1 - ld a, [hROMBank] - push af - ld a, $13 - rst Bankswitch - - call $4000 - pop af - rst Bankswitch - - ret -; dbd - -Functiondbd: ; dbd - ld a, [hROMBank] - push af - ld a, $13 - rst Bankswitch - - call $403f - pop af - rst Bankswitch - - ret -; dc9 - - - -Functiondc9: ; dc9 - ld a, [rLCDC] - bit 7, a - jp z, Copy2bpp - - ld a, [hROMBank] - push af - ld a, BANK(Function104284) - rst Bankswitch - call Function104284 - pop af - rst Bankswitch - - ret -; ddc - -Functionddc: ; ddc - ld a, [rLCDC] - bit 7, a - jp z, Copy1bpp - - ld a, [hROMBank] - push af - ld a, BANK(Function1042b2) - rst Bankswitch - call Function1042b2 - pop af - rst Bankswitch - - ret -; def - -Functiondef: ; def - ld [hBuffer], a - ld a, [hROMBank] - push af - ld a, [hBuffer] - rst Bankswitch - call FarCopyBytesDouble - pop af - rst Bankswitch - ret -; dfd - -Functiondfd: ; dfd - dec c - ld a, [hBGMapMode] - push af - xor a - ld [hBGMapMode], a - ld a, [hROMBank] - push af - ld a, b - rst Bankswitch - -.asm_e09 - ld a, d - ld [rHDMA1], a - ld a, e - and $f0 - ld [rHDMA2], a - ld a, h - and $1f - ld [rHDMA3], a - ld a, l - and $f0 - ld [rHDMA4], a - ld a, c - cp $8 - jr c, .asm_e3c - sub $8 - ld c, a - ld a, $f - ld [hDMATransfer], a - call DelayFrame - ld a, l - add $0 - ld l, a - ld a, h - adc $1 - ld h, a - ld a, e - add $0 - ld e, a - ld a, d - adc $1 - ld d, a - jr .asm_e09 - -.asm_e3c - ld a, c - and $7f - ld [hDMATransfer], a - call DelayFrame - pop af - rst Bankswitch - - pop af - ld [hBGMapMode], a - ret -; e4a - - - -Functione4a: ; e4a - ld a, $5 - ld hl, $4135 - rst FarCall - ret -; e51 - - - -Functione51: ; e51 - ld a, $3e - ld hl, $7449 - rst FarCall - ret -; e58 - -Functione58: ; e58 - ld a, $3e - ld hl, $74be - rst FarCall - ret -; e5f - - - -Functione5f: ; e5f - ld a, $3e - ld hl, $748a - rst FarCall - ld a, $3e - ld hl, $74b0 - rst FarCall - ret -; e6c - -Functione6c: ; e6c - ld a, $3e - ld hl, $74b0 - rst FarCall - ret -; e73 - -Functione73: ; e73 - push de - ld a, $0 - call GetSRAMBank - push bc - ld de, $a000 - ld a, b - call FarDecompress - pop bc - pop hl - ld de, $a000 - call Request2bpp - call CloseSRAM - ret -; e8d - - - -FarCopyBytes: ; e8d -; copy bc bytes from a:hl to de - - ld [hBuffer], a - ld a, [hROMBank] - push af - ld a, [hBuffer] - rst Bankswitch - - call CopyBytes - - pop af - rst Bankswitch - ret -; 0xe9b - - -FarCopyBytesDouble: ; e9b -; Copy bc bytes from a:hl to bc*2 bytes at de, -; doubling each byte in the process. - - ld [hBuffer], a - ld a, [hROMBank] - push af - ld a, [hBuffer] - rst Bankswitch - -; switcheroo, de <> hl - ld a, h - ld h, d - ld d, a - ld a, l - ld l, e - ld e, a - - inc b - inc c - jr .dec - -.loop - ld a, [de] - inc de - ld [hli], a - ld [hli], a -.dec - dec c - jr nz, .loop - dec b - jr nz, .loop - - pop af - rst Bankswitch - ret -; 0xeba - - -Request2bpp: ; eba - ld a, [hBGMapMode] - push af - xor a - ld [hBGMapMode], a - - ld a, [hROMBank] - push af - ld a, b - rst Bankswitch - - ld a, [$ffd3] - push af - - ld a, $8 - ld [$ffd3], a - ld a, [InLinkBattle] - cp $4 - jr nz, .asm_edc - ld a, [$ffe9] - and a - jr nz, .asm_edc - ld a, $6 - ld [$ffd3], a - -.asm_edc - ld a, e - ld [$cf68], a - ld a, d - ld [$cf69], a - ld a, l - ld [$cf6a], a - ld a, h - ld [$cf6b], a - -.asm_eec - ld a, c - ld hl, $ffd3 - cp [hl] - jr nc, .asm_f08 - - ld [$cf67], a -.wait - call DelayFrame - ld a, [$cf67] - and a - jr nz, .wait - - pop af - ld [$ffd3], a - - pop af - rst Bankswitch - - pop af - ld [hBGMapMode], a - ret - -.asm_f08 - ld a, [$ffd3] - ld [$cf67], a -.asm_f0d - call DelayFrame - ld a, [$cf67] - and a - jr nz, .asm_f0d - ld a, c - ld hl, $ffd3 - sub [hl] - ld c, a - jr .asm_eec -; f1e - - -Request1bpp: ; f1e - ld a, [hBGMapMode] - push af - xor a - ld [hBGMapMode], a - - ld a, [hROMBank] - push af - ld a, b - rst Bankswitch - - ld a, [$ffd3] - push af - - ld a, $8 - ld [$ffd3], a - ld a, [InLinkBattle] - cp $4 - jr nz, .asm_f40 - ld a, [$ffe9] - and a - jr nz, .asm_f40 - ld a, $6 - ld [$ffd3], a - -.asm_f40 - ld a, e - ld [$cf6d], a - ld a, d - ld [$cf6e], a - ld a, l - ld [$cf6f], a - ld a, h - ld [$cf70], a -.asm_f50 - ld a, c - ld hl, $ffd3 - cp [hl] - jr nc, .asm_f6c - - ld [$cf6c], a -.wait - call DelayFrame - ld a, [$cf6c] - and a - jr nz, .wait - - pop af - ld [$ffd3], a - - pop af - rst Bankswitch - - pop af - ld [hBGMapMode], a - ret - -.asm_f6c - ld a, [$ffd3] - ld [$cf6c], a -.asm_f71 - call DelayFrame - ld a, [$cf6c] - and a - jr nz, .asm_f71 - ld a, c - ld hl, $ffd3 - sub [hl] - ld c, a - jr .asm_f50 -; f82 - - -Get2bpp: ; f82 - ld a, [rLCDC] - bit 7, a - jp nz, Request2bpp - -Copy2bpp: ; f89 -; copy c 2bpp tiles from b:de to hl - - push hl - ld h, d - ld l, e - pop de - -; bank - ld a, b - -; bc = c * $10 - push af - swap c - ld a, $f - and c - ld b, a - ld a, $f0 - and c - ld c, a - pop af - - jp FarCopyBytes -; f9d - - -Get1bpp: ; f9d - ld a, [rLCDC] - bit 7, a - jp nz, Request1bpp - -Copy1bpp: ; fa4 -; copy c 1bpp tiles from b:de to hl - - push de - ld d, h - ld e, l - -; bank - ld a, b - -; bc = c * $10 / 2 - push af - ld h, 0 - ld l, c - add hl, hl - add hl, hl - add hl, hl - ld b, h - ld c, l - pop af - - pop hl - jp FarCopyBytesDouble -; fb6 +INCLUDE "engine/copy.asm" INCLUDE "engine/text.asm" @@ -2380,51 +421,13 @@ UpdateBGMap: ; 164c .row ; write a row of 20 tiles +rept 9 pop de ld [hl], e inc l ld [hl], d inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l +endr pop de ld [hl], e inc l @@ -2487,6 +490,8 @@ GetTiles2: ; 1717 .loop ; put 1 tile (16 bytes) into hl from sp + +rept 3 pop de ld [hl], e inc l @@ -2496,24 +501,7 @@ GetTiles2: ; 1717 inc l ld [hl], d inc l - pop de - ld [hl], e - inc l - ld [hl], e - inc l - ld [hl], d - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], e - inc l - ld [hl], d - inc l - ld [hl], d - inc l +endr pop de ld [hl], e inc l @@ -2598,41 +586,13 @@ GetTiles: ; 177d .loop ; put 1 tile (16 bytes) into hl from sp +rept 7 pop de ld [hl], e inc l ld [hl], d inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l - pop de - ld [hl], e - inc l - ld [hl], d - inc l +endr pop de ld [hl], e inc l @@ -2708,12 +668,12 @@ SafeTileAnimation: ; 17d3 ; 17ff -Function17ff: ; 17ff +GetSpritePalette: ; 17ff push hl push de push bc ld c, a - callba GetSpritePalette + callba _GetSpritePalette ld a, c pop bc pop de @@ -2760,15 +720,17 @@ Function180e: ; 180e Function1836: ; 1836 push de push hl + ld b, a ld a, [hROMBank] push af - ld a, $5 + ld a, BANK(Function142a7) rst Bankswitch ld a, b - call $42a7 + call Function142a7 ld c, a + pop de ld a, d rst Bankswitch @@ -2778,6 +740,8 @@ Function1836: ; 1836 ret ; 184a + + Function184a: ; 184a ld a, [StandingTile] call GetTileCollision @@ -2788,14 +752,13 @@ Function184a: ; 184a Function1852: ; 1852 ld a, [StandingTile] call GetTileCollision - sub $1 + sub 1 ret z and a ret ; 185d - GetTileCollision: ; 185d ; Get the collision type of tile a. @@ -3234,12 +1197,13 @@ Function1a61: ; 1a61 ld l, a ld a, [hROMBank] push af - ld a, $1 + ld a, BANK(Data4273) rst Bankswitch - ld a, l push bc + call Function1a71 + pop bc pop af rst Bankswitch @@ -3253,8 +1217,8 @@ Function1a71: ; 1a71 ld [hl], a push de ld e, a - ld d, $0 - ld hl, $4274 + ld d, 0 + ld hl, Data4273 + 1 add hl, de add hl, de add hl, de @@ -3333,7 +1297,6 @@ Function1acc: ; 1acc ; 1ad2 - Function1ad2: ; 1ad2 ld a, [VramState] bit 0, a @@ -3344,7 +1307,6 @@ Function1ad2: ; 1ad2 ; 1ae5 - Function1ae5: ; 1ae5 ld bc, $0028 ld hl, $d4d6 @@ -3377,28 +1339,30 @@ Function1af8: ; 1af8 ; 1b07 - GetSpriteDirection: ; 1b07 ld hl, $0008 add hl, bc ld a, [hl] - and %00001100 + and $c ret ; 1b0f Function1b0f: ; 1b0f add $10 + +Function1b11: ; 1b11 ld e, a + ld a, [hROMBank] push af - ld a, $2 + ld a, BANK(Function84d9) rst Bankswitch - call $44d9 + call Function84d9 + pop af rst Bankswitch - ret ; 1b1e @@ -3610,9 +1574,7 @@ Function1c07: ; 0x1c07 ret Function1c10: ; 0x1c10 - ld hl, $446d - ld a, $9 - rst $8 + callab Function2446d ret Function1c17: ; 0x1c17 @@ -3968,14 +1930,18 @@ Function1db8: ; 0x1db8 ret ; 0x1dcf + Function1dcf: ; 1dcf ld bc, $0e07 - jr .asm_1dd9 +Function1dd2: ; 1dd2 + jr Function1dd9 + +Function1dd4: ; 1dd4 call LoadMenuDataHeader - jr .asm_1dfe + jr Function1dfe -.asm_1dd9 +Function1dd9: ; 1dd9 push bc ld hl, MenuDataHeader_0x1e1d call Function1d3c @@ -3997,7 +1963,7 @@ Function1dcf: ; 1dcf ld [$cf84], a call Function1c00 -.asm_1dfe +Function1dfe: ; 1dfe call Function1d81 push af ld c, $f @@ -4482,11 +2448,11 @@ AskSerial: ; 2063 ; 208a -Function208a: ; 208a +ResetGameTime: ; 208a xor a ld [GameTimeCap], a ld [GameTimeHours], a - ld [$d4c5], a + ld [GameTimeHours + 1], a ld [GameTimeMinutes], a ld [GameTimeSeconds], a ld [GameTimeFrames], a @@ -4712,7 +2678,7 @@ Function2147: ; 2147 Function2173: ; 2173 call Function217a - call $0db1 + call Functiondb1 ret ; 217a @@ -4744,9 +2710,13 @@ Function2198: ; 2198 ld d, a ld hl, EnemyMoveAnimation ld b, $5 + +.asm_21a5 push de push hl ld c, $6 + +.asm_21a9 push de push hl ld a, [de] @@ -4844,7 +2814,7 @@ Function2198: ; 2198 pop de inc de dec c - jp nz, $21a9 + jp nz, .asm_21a9 pop hl ld de, $0060 add hl, de @@ -4858,7 +2828,7 @@ Function2198: ; 2198 .asm_2225 dec b - jp nz, $21a5 + jp nz, .asm_21a5 ret ; 222a @@ -5614,7 +3584,7 @@ Function261b: ; 261b ret ; 261f -PushScriptPointer: ; 261f +CallScript: ; 261f ; Call a script at a:hl. ld [ScriptBank], a @@ -5635,7 +3605,7 @@ Function2631: ; 2631 and a ret nz call GetMapEventBank - jr PushScriptPointer + jr CallScript ; 263b Function263b: ; 263b @@ -5972,11 +3942,13 @@ Function27c0: ; 27c0 Function27d3: ; 27d3 ld hl, BGMapBufferPtrs push de - call $27df + call .asm_27df pop de ld a, $20 add e ld e, a + +.asm_27df ld c, $a .asm_27e1 ld a, e @@ -6613,16 +4585,19 @@ Function2b3c: ; 2b3c call Function2bae call Function1ad2 call Function1d7d - call $0d90 - jr .asm_2b5c + call Functiond90 + jr Function2b5c +; 2b4d +Function2b4d: ; 2b4d call WhiteBGMap call Function1d7d call Function2bae call Function1ad2 - call $0d90 + call Functiond90 +; 2b5c -.asm_2b5c +Function2b5c: ; 2b5c ld b, $9 call GetSGBLayout ld a, $12 @@ -6653,9 +4628,7 @@ Function2b74: ; 0x2b74 call Function3200 ld b, $9 call GetSGBLayout - ld a, $12 - ld hl, $5409 - rst $8 + callba Function49409 call Function485 call DelayFrame ld a, $1 @@ -6670,7 +4643,7 @@ Function2bae: ; 2bae ld a, $5 ld hl, $4168 rst FarCall - call $0e51 + call Functione51 call Functione5f ld a, [hROMBank] push af @@ -7042,27 +5015,28 @@ Function2d43: ; 2d43 ; 2d54 -FarJpDe: ; 2d54 +FarCall_de: ; 2d54 +; Call a:de. +; Preserves other registers. + ld [hBuffer], a ld a, [hROMBank] push af ld a, [hBuffer] rst Bankswitch - call Function2d61 - jr ReturnFarJump -; 2d61 + call .de + jr ReturnFarCall -Function2d61: ; 2d61 +.de push de ret ; 2d63 -FarJpHl: ; 2d63 -; Jump to a:hl. -; Preserves all registers besides a. +FarCall_hl: ; 2d63 +; Call a:hl. +; Preserves other registers. -; Switch to the new bank. ld [hBuffer], a ld a, [hROMBank] push af @@ -7071,7 +5045,7 @@ FarJpHl: ; 2d63 call Function2d82 ; 2d6e -ReturnFarJump: ; 2d6e +ReturnFarCall: ; 2d6e ; We want to retain the contents of f. ; To do this, we can pop to bc instead of af. @@ -7308,12 +5282,12 @@ Function2e5d: ; 2e5d ; 2e6f -BitTable1Func: ; 0x2e6f - ld hl, $da72 - call BitTableFunc +EventFlagAction: ; 0x2e6f + ld hl, EventFlags + call FlagAction ret -BitTableFunc: ; 0x2e76 +FlagAction: ; 0x2e76 ; Perform a function on a bit in memory. ; inputs: @@ -7383,9 +5357,9 @@ BitTableFunc: ; 0x2e76 Function2ead: ; 2ead - ld de, $000b - ld b, $2 - callba GetFlag2 + ld de, ENGINE_POKEDEX + ld b, CHECK_FLAG + callba EngineFlagAction ld a, c and a ret @@ -7575,20 +5549,20 @@ Function2f66: ; 2f66 ret ; 2f79 -Function2f79: ; 2f79 +PickUpItem: ; 2f79 push hl push de push bc ld a, [hROMBank] push af - ld a, BANK(Functiond244) + ld a, BANK(_PickUpItem) rst Bankswitch - call Functiond244 + call _PickUpItem + pop bc ld a, b rst Bankswitch - pop bc pop de pop hl @@ -7596,50 +5570,50 @@ Function2f79: ; 2f79 ; 2f8c -RNG: ; 2f8c +Random: ; 2f8c +; A simple hardware-based random number generator (RNG). + ; Two random numbers are generated by adding and subtracting ; the divider to the respective values every time it's called. -; The divider is a value that increments at a rate of 16384Hz. +; The divider is a register that increments at a rate of 16384Hz. ; For comparison, the Game Boy operates at a clock speed of 4.2MHz. -; Additionally, an equivalent function is called every frame. +; Additionally, an equivalent function is executed in VBlank. -; output: -; a: rand2 -; ffe1: rand1 -; ffe2: rand2 +; This leaves a with the value in hRandomSub. push bc -; Added value + ld a, [rDIV] ld b, a ld a, [hRandomAdd] adc b ld [hRandomAdd], a -; Subtracted value + ld a, [rDIV] ld b, a ld a, [hRandomSub] sbc b ld [hRandomSub], a + pop bc ret ; 2f9f -FarBattleRNG: ; 2f9f -; BattleRNG lives in another bank. -; It handles all RNG calls in the battle engine, -; allowing link battles to remain in sync using a shared PRNG. +BattleRandom: ; 2f9f +; _BattleRandom lives in another bank. -; Save bank - ld a, [hROMBank] ; bank +; It handles all RNG calls in the battle engine, allowing +; link battles to remain in sync using a shared PRNG. + + ld a, [hROMBank] push af -; Bankswitch - ld a, BANK(BattleRNG) + ld a, BANK(_BattleRandom) rst Bankswitch - call BattleRNG -; Restore bank + + call _BattleRandom + ld [$cfb6], a pop af rst Bankswitch @@ -7660,7 +5634,7 @@ Function2fb1: ; 2fb1 ld b, a push bc .asm_2fbb - call RNG + call Random ld a, [hRandomAdd] ld c, a add b @@ -7707,11 +5681,14 @@ CloseSRAM: ; 2fe1 ret ; 2fec -JpHl: ; 2fec + +; Register aliases + +_hl_: ; 2fec jp [hl] ; 2fed -JpDe: ; 2fed +_de_: ; 2fed push de ret ; 2fef @@ -8227,16 +6204,19 @@ Function31be: ; 31be ld a, [hli] ld h, [hl] ld l, a - call JpHl + + call _hl_ + pop hl ld a, h rst Bankswitch - ret ; 31cd Function31cd: ; 31cd ld a, [hROMBank] + +Function31cf: ; 31cf ld [$d0e8], a ld a, l ld [$d0e9], a @@ -8326,32 +6306,35 @@ Function321c: ; 321c and a jr z, .asm_322e ld a, [$c2ce] - cp $0 + cp 0 jr z, .asm_322e - ld a, $1 + ld a, 1 ld [hBGMapMode], a - jr .asm_323d + jr Function323d .asm_322e - ld a, $1 + ld a, 1 ld [hBGMapMode], a - ld c, $4 + ld c, 4 call DelayFrames ret +; 3238 +Function3238: ; 3238 ld a, [hCGB] and a jr z, WaitBGMap -.asm_323d - jr .asm_3246 +Function323d: ; 323d + jr Function3246 +; 323f - ld a, $41 - ld hl, $4000 - rst FarCall +Function323f: ; 323f + callba Function104000 ret +; 3246 -.asm_3246 +Function3246: ; 3246 ld a, [hBGMapMode] push af xor a @@ -8397,87 +6380,19 @@ Function327b: ; 327b ld c, $41 .asm_328c pop de -.asm_328d + +rept 9 +.loop\@ ld a, [$ff00+c] and b - jr nz, .asm_328d - ld [hl], e - inc l - ld [hl], d - inc l - pop de -.asm_3296 - ld a, [$ff00+c] - and b - jr nz, .asm_3296 - ld [hl], e - inc l - ld [hl], d - inc l - pop de -.asm_329f - ld a, [$ff00+c] - and b - jr nz, .asm_329f - ld [hl], e - inc l - ld [hl], d - inc l - pop de -.asm_32a8 - ld a, [$ff00+c] - and b - jr nz, .asm_32a8 - ld [hl], e - inc l - ld [hl], d - inc l - pop de -.asm_32b1 - ld a, [$ff00+c] - and b - jr nz, .asm_32b1 - ld [hl], e - inc l - ld [hl], d - inc l - pop de -.asm_32ba - ld a, [$ff00+c] - and b - jr nz, .asm_32ba - ld [hl], e - inc l - ld [hl], d - inc l - pop de -.asm_32c3 - ld a, [$ff00+c] - and b - jr nz, .asm_32c3 - ld [hl], e - inc l - ld [hl], d - inc l - pop de -.asm_32cc - ld a, [$ff00+c] - and b - jr nz, .asm_32cc - ld [hl], e - inc l - ld [hl], d - inc l - pop de -.asm_32d5 - ld a, [$ff00+c] - and b - jr nz, .asm_32d5 + jr nz, .loop\@ ld [hl], e inc l ld [hl], d inc l pop de +endr + .asm_32de ld a, [$ff00+c] and b @@ -8486,6 +6401,7 @@ Function327b: ; 327b inc l ld [hl], d inc l + ld de, $000c add hl, de ld a, [$ffd3] @@ -9264,7 +7180,7 @@ CheckTrainerBattle: ; 360d inc hl ld d, [hl] ld b, CHECK_FLAG - call BitTable1Func + call EventFlagAction ld a, c pop de pop bc @@ -9293,14 +7209,16 @@ CheckTrainerBattle: ; 360d ld [CurFruit], a ld a, c ld [MartPointer], a - jr .asm_367e + jr Function367e +; 3674 +Function3674: ; 3674 ld a, $1 ld [CurFruit], a ld a, $ff ld [MartPointer], a -.asm_367e +Function367e: ; 367e call GetMapEventBank ld [EngineBuffer1], a ld a, [$ffe0] @@ -9419,7 +7337,7 @@ Function36f5: ; 36f5 ld e, l push de ld b, $2 - call BitTable1Func + call EventFlagAction pop de ld a, c and a @@ -9456,19 +7374,20 @@ Function3718: ; 3718 -Function3741: ; 3741 +IsAPokemon: ; 3741 +; Return carry if species a is not a Pokemon. and a - jr z, .asm_374c - cp $fd - jr z, .asm_374e - cp $fc - jr c, .asm_374e + jr z, .NotAPokemon + cp EGG + jr z, .Pokemon + cp NUM_POKEMON + 1 + jr c, .Pokemon -.asm_374c +.NotAPokemon scf ret -.asm_374e +.Pokemon and a ret ; 3750 @@ -9539,8 +7458,10 @@ DrawHPBar: ; 3750 Function3786: ; 3786 ld a, $1 ld [$c2c6], a + +Function378b: ; 378b ld a, [CurPartySpecies] - call Function3741 + call IsAPokemon jr c, .asm_37ad push hl ld de, VTiles2 @@ -9676,21 +7597,22 @@ PrintLevel: ; 382d ; How many digits? ld c, 2 cp 100 - jr c, .print + jr c, Function3842 ; 3-digit numbers overwrite the :L. dec hl inc c - jr .print + jr Function3842 +; 383d -; -------- -; Unused: print :L and all 3 digits +Function383d: ; 383d +; Print :L and all 3 digits ld [hl], $6e inc hl ld c, 3 -; -------- +; 3842 -.print +Function3842: ; 3842 ld [$d265], a ld de, $d265 ld b, %01000001 ; flags @@ -10003,6 +7925,8 @@ UpdateBattleMonInParty: ; 399c ; Update level, status, current HP ld a, [CurBattleMon] + +Function399f: ; 399f ld hl, PartyMon1Level call GetPartyLocation @@ -10254,24 +8178,25 @@ MobileTextBorder: ; 3ab2 BattleTextBox: ; 3ac3 +; Open a textbox and print text at hl. push hl call SpeechTextBox call MobileTextBorder - call Function1ad2 ; UpdateSprites - call Function321c ; refresh? + call Function1ad2 + call Function321c pop hl call PrintTextBoxText ret ; 3ad5 -FarBattleTextBox: ; 3ad5 -; Open a textbox and print text at 20:hl. +StdBattleTextBox: ; 3ad5 +; Open a textbox and print battle text at 20:hl. ld a, [hROMBank] push af - ld a, $20 + ld a, BANK(BattleText) rst Bankswitch call BattleTextBox @@ -11024,28 +8949,36 @@ Function3e80: ; 3e80 ; 3e93 -Function3e93: ; 3e93 +Timer: ; 3e93 push af push bc push de push hl + ld a, [$ffe9] and a jr z, .asm_3ed2 + xor a ld [rTAC], a + +; Turn off timer interrupt ld a, [rIF] - and $1b + and 1 << VBLANK | 1 << LCD_STAT | 1 << SERIAL | 1 << JOYPAD ld [rIF], a + ld a, [$c86a] or a jr z, .asm_3ed2 + ld a, [$c822] bit 1, a jr nz, .asm_3eca + ld a, [rSC] - and $80 + and 1 << rSC_ON jr nz, .asm_3eca + ld a, [hROMBank] push af ld a, $44 @@ -11053,16 +8986,17 @@ Function3e93: ; 3e93 rst Bankswitch call $58de + pop bc ld a, b ld [$c981], a rst Bankswitch - .asm_3eca ld a, [rTMA] ld [rTIMA], a - ld a, $6 + + ld a, 1 << rTAC_ON | rTAC_65536_HZ ld [rTAC], a .asm_3ed2 @@ -11168,11 +9102,11 @@ Function3f47: ; 3f47 pop bc .asm_3f4c push bc - call $3f68 + call Function3f68 pop bc dec b jr nz, .asm_3f4c - call $3f60 + call Function3f60 ret ; 3f58 @@ -11180,18 +9114,20 @@ Function3f58: ; 3f58 ld a, $63 ld d, $62 ld e, $64 - jr .asm_3f6e + jr Function3f6e +Function3f60: ; 3f60 ld a, $68 ld d, $67 ld e, $69 - jr .asm_3f6e + jr Function3f6e +Function3f68: ; 3f68 ld a, $7f ld d, $65 ld e, $66 -.asm_3f6e +Function3f6e: ; 3f6e push hl ld [hl], d inc hl @@ -11757,7 +9693,7 @@ Function444d: ; 444d ld a, [hli] ld h, [hl] ld l, a - call JpHl + call _hl_ ret ; 445f @@ -12481,14 +10417,14 @@ Function4821: ; 4821 ; 4822 Function4822: ; 4822 - call RNG + call Random ld a, [hRandomAdd] and 1 jp Function4af0 ; 482c Function482c: ; 482c - call RNG + call Random ld a, [hRandomAdd] and 1 or 2 @@ -12496,14 +10432,14 @@ Function482c: ; 482c ; 4838 Function4838: ; 4838 - call RNG + call Random ld a, [hRandomAdd] and 3 jp Function4af0 ; 4842 Function4842: ; 4842 - call RNG + call Random ld a, [hRandomAdd] and $c ld hl, $0008 @@ -12518,7 +10454,7 @@ Function4851: ; 4851 ld a, [hl] and $c ld d, a - call RNG + call Random ld a, [hRandomAdd] and $c cp d @@ -13021,14 +10957,14 @@ Function4b17: ; 4b17 ; 4b1d Function4b1d: ; 4b1d - call RNG + call Random ld a, [hRandomAdd] and $7f jr Function4b2d ; 4b26 Function4b26: ; 4b26 - call RNG + call Random ld a, [hRandomAdd] and $1f ; fallthrough @@ -13240,7 +11176,7 @@ Function4c5d: ; 4c5d inc [hl] ld a, [hl] ld d, $60 - call $1b11 + call Function1b11 ld a, h sub $60 ld hl, $001a @@ -13313,7 +11249,7 @@ Function4cc9: ; 4cc9 inc [hl] ld a, [hl] ld d, $60 - call $1b11 + call Function1b11 ld a, h sub $60 ld hl, $001a @@ -13404,7 +11340,7 @@ Function4d4f: ; 4d4f inc [hl] ld a, [hl] ld d, $60 - call $1b11 + call Function1b11 ld a, h sub $60 ld hl, $001a @@ -15221,7 +13157,7 @@ Function5b44: ; 5b44 ld [$ffde], a call ClearTileMap call Functione5f - call $0e51 + call Functione51 call Function1fbf ret ; 5b54 @@ -15285,64 +13221,80 @@ Function5ba7: ; 5ba7 ; 5bae Function5bae: ; 5bae + ld hl, Sprites - ld bc, $0bcc + ld bc, Options - Sprites xor a call ByteFill + ld hl, $d000 - ld bc, $047b + ld bc, PlayerID - $d000 xor a call ByteFill + ld hl, PlayerID - ld bc, $0b7a + ld bc, $dff5 - PlayerID xor a call ByteFill + ld a, [rLY] ld [$ffe3], a call DelayFrame ld a, [hRandomSub] ld [PlayerID], a + ld a, [rLY] ld [$ffe3], a call DelayFrame ld a, [hRandomAdd] ld [PlayerID + 1], a - call RNG + + call Random ld [$d84a], a call DelayFrame - call RNG + call Random ld [$d84b], a + ld hl, PartyCount call Function5ca1 + xor a ld [$db72], a ld [$d4b4], a + call Function5ca6 - ld a, $1 + + ld a, 1 call GetSRAMBank - ld hl, $ad10 + ld hl, BoxCount call Function5ca1 call CloseSRAM + ld hl, NumItems call Function5ca1 + ld hl, NumKeyItems call Function5ca1 + ld hl, NumBalls call Function5ca1 - ld hl, $d8f1 + + ld hl, PCItems call Function5ca1 + xor a ld [RoamMon1Species], a ld [RoamMon2Species], a ld [RoamMon3Species], a - ld a, $ff + ld a, -1 ld [RoamMon1MapGroup], a ld [RoamMon2MapGroup], a ld [RoamMon3MapGroup], a ld [RoamMon1MapNumber], a ld [RoamMon2MapNumber], a ld [RoamMon3MapNumber], a - ld a, $0 + + ld a, 0 call GetSRAMBank ld hl, $abe2 xor a @@ -15350,38 +13302,50 @@ Function5bae: ; 5bae dec a ld [hl], a call CloseSRAM + call Function5d33 call Function5cd3 + xor a ld [MonType], a + ld [JohtoBadges], a ld [KantoBadges], a - ld [$d855], a - ld [$d856], a + + ld [Coins], a + ld [Coins + 1], a + ld [Money], a - ld a, $b - ld [$d84f], a - ld a, $b8 - ld [$d850], a + ld a, 3000 >> 8 + ld [Money + 1], a + ld a, 3000 & $ff + ld [Money + 2], a + xor a ld [$dc17], a + ld hl, $dc19 ld [hl], $0 inc hl ld [hl], $8 inc hl ld [hl], $fc + call Function5ce9 + ld a, $9 ld hl, $6751 rst FarCall + ld a, $11 ld hl, $4765 rst FarCall + ld a, $41 ld hl, $61c0 rst FarCall - call Function208a + + call ResetGameTime ret ; 5ca1 @@ -15497,9 +13461,9 @@ Function5d33: ; 5d33 jr z, .asm_5d55 ld a, b ld [$ac68], a - call RNG + call Random ld c, a - call RNG + call Random .asm_5d55 ld [$dc9f], a @@ -15638,7 +13602,7 @@ Function5e34: ; 5e34 ; 5e48 Function5e48: ; 5e48 - call $06e3 + call Function6e3 and $80 jr z, .asm_5e5b ld a, $8 @@ -15677,7 +13641,7 @@ Function5e5d: ; 5e5d ; 5e85 Function5e85: ; 5e85 - call $06e3 + call Function6e3 and $80 jr z, .asm_5e93 ld de, $0408 @@ -15847,14 +13811,14 @@ OakSpeech: ; 0x5f99 ld a, $24 ld hl, $4672 rst FarCall - call $04dd + call Function4dd call ClearTileMap ld de, MUSIC_ROUTE_30 call StartMusic - call $04a3 - call $04b6 + call Function4a3 + call Function4b6 xor a ld [CurPartySpecies], a ld a, POKEMON_PROF @@ -15867,7 +13831,7 @@ OakSpeech: ; 0x5f99 ld hl, OakText1 call PrintText - call $04b6 + call Function4b6 call ClearTileMap ld a, $c2 @@ -15890,7 +13854,7 @@ OakSpeech: ; 0x5f99 call PrintText ld hl, OakText4 call PrintText - call $04b6 + call Function4b6 call ClearTileMap xor a @@ -15905,7 +13869,7 @@ OakSpeech: ; 0x5f99 ld hl, OakText5 call PrintText - call $04b6 + call Function4b6 call ClearTileMap xor a @@ -15976,7 +13940,7 @@ NamePlayer: ; 0x6074 ld hl, $56c1 rst FarCall - call $04b6 + call Function4b6 call ClearTileMap call Functione5f @@ -16030,42 +13994,54 @@ Function60fa: ; 60fa ; 610f Function610f: ; 610f + ld a, [hROMBank] push af - ld a, $20 + + ld a, 0 << 7 | 32 ; fade out ld [MusicFade], a ld de, MUSIC_NONE ld a, e ld [MusicFadeIDLo], a ld a, d ld [MusicFadeIDHi], a + ld de, SFX_ESCAPE_ROPE call StartSFX pop af rst Bankswitch - ld c, $8 + ld c, 8 call DelayFrames + ld hl, $5249 ld b, $13 call Function61b4 - ld c, $8 + + ld c, 8 call DelayFrames + ld hl, $52d9 ld b, $13 call Function61b4 - ld c, $8 + + ld c, 8 call DelayFrames + ld hl, $c50a - ld b, $7 - ld c, $7 + ld b, 7 + ld c, 7 call ClearBox - ld c, $3 + + ld c, 3 call DelayFrames + call Function61cd call Functione5f - ld c, $32 + + ld c, 50 call DelayFrames + call Function4b6 call ClearTileMap ret @@ -16073,11 +14049,11 @@ Function610f: ; 610f Function616a: ; 616a ld hl, IntroFadePalettes - ld b, $6 + ld b, IntroFadePalettesEnd - IntroFadePalettes .asm_616f ld a, [hli] call DmgToCgbBGPals - ld c, $a + ld c, 10 call DelayFrames dec b jr nz, .asm_616f @@ -16091,6 +14067,7 @@ IntroFadePalettes: ; 0x617c db %11111000 db %11110100 db %11100100 +IntroFadePalettesEnd ; 6182 Function6182: ; 6182 @@ -16136,14 +14113,17 @@ Function61b4: ; 61b4 ; 61cd Function61cd: ; 61cd + callba GetPlayerIcon ld c, $c ld hl, VTiles0 call Request2bpp + ld hl, Sprites ld de, .data_61fe ld a, [de] inc de + ld c, a .asm_61e4 ld a, [de] @@ -16155,14 +14135,15 @@ Function61cd: ; 61cd ld a, [de] inc de ld [hli], a - ld b, $0 + + ld b, 0 ld a, [PlayerGender] bit 0, a jr z, .asm_61f8 - ld b, $1 - + ld b, 1 .asm_61f8 ld a, b + ld [hli], a dec c jr nz, .asm_61e4 @@ -16192,7 +14173,7 @@ Function620b: ; 620b push af ld a, $5 ld [rSVBK], a - call FarStartTitleScreen + call TitleScreen call DelayFrame .asm_6226 call Function627b @@ -16220,7 +14201,6 @@ Function620b: ; 620b cp $5 jr c, .asm_625e xor a - .asm_625e ld e, a ld d, 0 @@ -16242,8 +14222,8 @@ Function620b: ; 620b ; 6274 -FarStartTitleScreen: ; 6274 - callba StartTitleScreen +TitleScreen: ; 6274 + callba _TitleScreen ret ; 627b @@ -16635,7 +14615,7 @@ Function64cd: ; 64cd ld a, $90 ld [hWY], a call Function2e31 - call $0e51 + call Functione51 ret ; 64db @@ -17984,7 +15964,7 @@ DaycareStep: ; 7282 dec [hl] ret nz - call RNG + call Random ld [hl], a ld hl, $6e1d ld a, $5 @@ -18004,7 +15984,7 @@ DaycareStep: ; 7282 ld b, $a .asm_72f8 - call RNG + call Random cp b ret nc ld hl, DaycareMan @@ -18071,7 +16051,7 @@ SpecialGiveShuckle: ; 7305 ld de, SpecialShuckleOT call CopyName2 -; Bittable2 flag for this event. +; Engine flag for this event. ld hl, $dc1e set 5, [hl] @@ -18201,7 +16181,7 @@ Function7420: ; 7420 call GetCurNick call Function746e pop hl - call RNG + call Random .next sub [hl] jr c, .asm_7444 @@ -18443,7 +16423,7 @@ Function811d: ; 811d call Function180e ld [$c2f2], a ld a, [hl] - call Function17ff + call GetSpritePalette ld [$c2f3], a ld hl, $0008 add hl, bc @@ -18768,7 +16748,7 @@ Function831e: ; 831e call Function1b3f ld a, [CurFruit] dec a - jr z, .asm_833b + jr z, Function833b ld a, [$ffe0] ld b, a ld c, $0 @@ -18776,7 +16756,7 @@ Function831e: ; 831e call Function8341 call Function1b35 -.asm_833b +Function833b ld a, $47 call Function1b3f ret @@ -19110,14 +17090,14 @@ Function84d9: ; 84d9 Function84ef: ; 84ef ld e, a ld a, d - ld d, $0 + ld d, 0 ld hl, $450b add hl, de add hl, de ld e, [hl] inc hl ld d, [hl] - ld hl, $0000 + ld hl, 0 .asm_84fe srl a jr nc, .asm_8503 @@ -19196,7 +17176,7 @@ PredefPointers: ; 856b dwb FillBox, BANK(FillBox) dwb Function3d873, BANK(Function3d873) dwb Function3e036, BANK(Function3e036) ; UpdateEnemyHUD - dwb Function3f4c1, BANK(Function3f4c1) + dwb StartBattle, BANK(StartBattle) dwb FillInExpBar, BANK(FillInExpBar) dwb Function3f43d, BANK(Function3f43d) dwb Function3f47c, BANK(Function3f47c) @@ -19226,7 +17206,7 @@ PredefPointers: ; 856b dwb $464c, $02 ; LoadSGBLayout, BANK(LoadSGBLayout) dwb $5d11, $24 dwb CheckContestMon, BANK(CheckContestMon) - dwb $420f, $23 + dwb Function8c20f, BANK(Function8c20f) dwb $4000, $23 dwb $4000, $23 dwb Functioncc0d6, BANK(Functioncc0d6) @@ -20342,7 +18322,7 @@ SpecialsPointers: ; c029 dbw BANK(SpecialGameboyCheck),SpecialGameboyCheck dbw BANK(SpecialTrainerHouse),SpecialTrainerHouse dbw $05, $6dc7 - dbw BANK(SpecialRoamMons), SpecialRoamMons + dbw BANK(InitRoamMons), InitRoamMons dbw $03, $448f dbw $03, $449f dbw $03, $44ac @@ -20792,7 +18772,7 @@ Functionc6f5: ; c6f5 GetPartyNick: ; c706 ; write CurPartyMon nickname to StringBuffer1-3 ld hl, PartyMon1Nickname - ld a, $02 + ld a, BOXMON ld [MonType], a ld a, [CurPartyMon] call GetNick @@ -20804,12 +18784,11 @@ GetPartyNick: ; c706 ret ; c721 -CheckFlag2: ; c721 -; using bittable2 -; check flag id in de -; return carry if flag is not set - ld b, $02 ; check flag - callba GetFlag2 +CheckEngineFlag: ; c721 +; Check engine flag de +; Return carry if flag is not set + ld b, CHECK_FLAG + callba EngineFlagAction ld a, c and a jr nz, .isset @@ -20821,8 +18800,9 @@ CheckFlag2: ; c721 ; c731 CheckBadge: ; c731 -; input: a = badge flag id ($1b-$2b) - call CheckFlag2 +; Check engine flag a (ENGINE_ZEPHYRBADGE thru ENGINE_EARTHBADGE) +; Display "Badge required" text and return carry if the badge is not owned + call CheckEngineFlag ret nc ld hl, BadgeRequiredText call Function1d67 ; push text to queue @@ -20831,8 +18811,10 @@ CheckBadge: ; c731 ; c73d BadgeRequiredText: ; c73d - TX_FAR _BadgeRequiredText ; Sorry! A new BADGE - db "@" ; is required. + ; Sorry! A new BADGE + ; is required. + TX_FAR _BadgeRequiredText + db "@" ; c742 CheckPartyMove: ; c742 @@ -20882,12 +18864,15 @@ CheckPartyMove: ; c742 ; c779 Functionc779: ; c779 - ld hl, $4780 + ld hl, UnknownText_0xc780 call Function1d67 ret ; c780 -INCBIN "baserom.gbc", $c780, $c785 - $c780 +UnknownText_0xc780: ; 0xc780 + text_jump UnknownText_0x1c05c8, BANK(UnknownText_0x1c05c8) + db "@" +; 0xc785 Functionc785: ; c785 call Functionc6ea @@ -20922,7 +18907,7 @@ Functionc7ce: ; c7ce ld c, [hl] push hl ld hl, $4862 - call $4840 + call Functionc840 pop hl jr nc, .asm_c7fc ld a, l @@ -21012,10 +18997,9 @@ Functionc8ac: ; c8ac ; c8b5 Functionc8b5: ; c8b5 - ld de, $001b - ld a, $3 - ld hl, $4731 - rst FarCall +; Flash + ld de, ENGINE_ZEPHYRBADGE + callba CheckBadge jr c, .asm_c8dd push hl ld a, $22 @@ -21043,11 +19027,36 @@ Functionc8b5: ; c8b5 ; c8e0 Functionc8e0: ; c8e0 - ld hl, $48e6 + ld hl, UnknownScript_0xc8e6 jp Function31cd ; c8e6 -INCBIN "baserom.gbc", $c8e6, $c909 - $c8e6 +UnknownScript_0xc8e6: ; 0xc8e6 + reloadmappart + special $0035 + 2writetext UnknownText_0xc8f3 + 3callasm $23, $47e1 + loadmovesprites + end +; 0xc8f3 + +UnknownText_0xc8f3: ; 0xc8f3 + text_jump UnknownText_0x1c0609, BANK(UnknownText_0x1c0609) + start_asm +; 0xc8f8 + +Functionc8f8: ; c8f8 + call WaitSFX + ld de, SFX_FLASH + call StartSFX + call WaitSFX + ld hl, UnknownText_0xc908 + ret +; c908 + +UnknownText_0xc908: ; 0xc908 + db "@" +; 0xc909 Functionc909: ; c909 call Functionc6ea @@ -21175,8 +19184,8 @@ TrySurfOW: ; c9e7 call CheckDirection jr c, .quit - ld de, $1e ; FLAG_FOG_BADGE - call CheckFlag2 + ld de, ENGINE_FOGBADGE + call CheckEngineFlag jr c, .quit ld d, SURF @@ -21193,7 +19202,7 @@ TrySurfOW: ; c9e7 ld a, BANK(AskSurfScript) ld hl, AskSurfScript - call PushScriptPointer + call CallScript scf ret @@ -21239,13 +19248,13 @@ Functionca3b: ; ca3b Functionca52: ; ca52 ; Fly - ld de, $0020 ; storm badge + ld de, ENGINE_STORMBADGE call CheckBadge jr c, .asm_ca85 call GetMapPermission call CheckOutdoorMap jr z, .asm_ca64 - jr .asm_ca88 + jr .indoors .asm_ca64 xor a @@ -21267,7 +19276,7 @@ Functionca52: ; ca52 ld a, $82 ret -.asm_ca88 +.indoors ld a, $2 ret @@ -21279,7 +19288,7 @@ Functionca52: ; ca52 ; ca94 Functionca94: ; ca94 - ld hl, Datacaa3 + ld hl, UnknownScript_0xcaa3 call Function31cd ld a, $81 ret @@ -21291,8 +19300,29 @@ Functionca9d: ; ca9d ret ; caa3 -Datacaa3: ; caa3 -INCBIN "baserom.gbc", $caa3, $cade - $caa3 +UnknownScript_0xcaa3: ; 0xcaa3 + reloadmappart + 3callasm BANK(HideSprites), HideSprites + special $0035 + 3callasm $23, $4aed + 3call BANK(UnknownScript_0x122c1), UnknownScript_0x122c1 + special $0000 + 3callasm $05, $54f1 + writecode $8, $0 + newloadmap $fc + 3callasm $23, $4b33 + special $003b + 3callasm BANK(Functioncacb), Functioncacb + end +; 0xcacb + +Functioncacb: ; cacb + callba Function561d + call DelayFrame + call Functione4a + callba Function106594 + ret +; cade Functioncade: ; cade call Functioncae7 @@ -21302,15 +19332,14 @@ Functioncade: ; cade ; cae7 Functioncae7: ; cae7 - ld de, $0022 - ld a, $3 - ld hl, $4731 - rst FarCall +; Waterfall + ld de, ENGINE_RISINGBADGE + callba CheckBadge ld a, $80 ret c call Functioncb07 jr c, .asm_cb01 - ld hl, $4b1c + ld hl, UnknownScript_0xcb1c call Function31cd ld a, $81 ret @@ -21324,7 +19353,7 @@ Functioncae7: ; cae7 Functioncb07: ; cb07 ld a, [PlayerDirection] and $c - cp $4 + cp FACE_UP jr nz, .asm_cb1a ld a, [TileUp] call CheckWaterfallTile @@ -21337,7 +19366,9 @@ Functioncb07: ; cb07 ret ; cb1c -INCBIN "baserom.gbc", $cb1c, $cb20 - $cb1c +UnknownScript_0xcb1c: ; 0xcb1c + reloadmappart + special $0035 UnknownScript_0xcb20: ; 0xcb20 3callasm BANK(GetPartyNick), GetPartyNick @@ -21380,21 +19411,21 @@ TryWaterfallOW: ; cb56 ld d, WATERFALL call CheckPartyMove jr c, .asm_cb74 - ld de, $0022 - call CheckFlag2 + ld de, ENGINE_RISINGBADGE + call CheckEngineFlag jr c, .asm_cb74 call Functioncb07 jr c, .asm_cb74 ld a, BANK(UnknownScript_0xcb86) ld hl, UnknownScript_0xcb86 - call PushScriptPointer + call CallScript scf ret .asm_cb74 ld a, BANK(UnknownScript_0xcb7e) ld hl, UnknownScript_0xcb7e - call PushScriptPointer + call CallScript scf ret ; cb7e @@ -21434,7 +19465,7 @@ Functioncb95: ; cb95 .asm_cba1 ld [Buffer2], a .asm_cba4 - ld hl, $4bb2 + ld hl, Tablecbb2 call Functionc6f5 jr nc, .asm_cba4 and $7f @@ -21442,12 +19473,134 @@ Functioncb95: ; cb95 ret ; cbb2 -INCBIN "baserom.gbc", $cbb2, $cc61 - $cbb2 +Tablecbb2: ; cbb2 + dw Functioncbb8 + dw Functioncbd8 + dw Functioncc06 +; cbb8 + +Functioncbb8: ; cbb8 + call GetMapPermission + cp $4 + jr z, .asm_cbc6 + cp $7 + jr z, .asm_cbc6 +.asm_cbc3 + ld a, $2 + ret + +.asm_cbc6 + ld hl, $dca9 + ld a, [hli] + and a + jr z, .asm_cbc3 + ld a, [hli] + and a + jr z, .asm_cbc3 + ld a, [hl] + and a + jr z, .asm_cbc3 + ld a, $1 + ret +; cbd8 + +Functioncbd8: ; cbd8 + ld hl, $dca9 + ld de, $d146 + ld bc, $0003 + call CopyBytes + call GetPartyNick + ld a, [Buffer2] + cp $2 + jr nz, .asm_cbf7 + ld hl, UnknownScript_0xcc35 + call Function31cd + ld a, $81 + ret + +.asm_cbf7 + callba Function8ae4e + ld hl, UnknownScript_0xcc2b + call Function31cd + ld a, $81 + ret +; cc06 + +Functioncc06: ; cc06 + ld a, [Buffer2] + cp $2 + jr nz, .asm_cc19 + ld hl, UnknownText_0xcc26 + call Function1d4f + call Functiona80 + call Function1c17 + +.asm_cc19 + ld a, $80 + ret +; cc1c + +UnknownText_0xcc1c: ; 0xcc1c + ; used DIG! + text_jump UnknownText_0x1c06de, BANK(UnknownText_0x1c06de) + db "@" +; 0xcc21 + +UnknownText_0xcc21: ; 0xcc21 + ; used an ESCAPE ROPE. + text_jump UnknownText_0x1c06ed, BANK(UnknownText_0x1c06ed) + db "@" +; 0xcc26 + +UnknownText_0xcc26: ; 0xcc26 + ; Can't use that here. + text_jump UnknownText_0x1c0705, BANK(UnknownText_0x1c0705) + db "@" +; 0xcc2b + +UnknownScript_0xcc2b: ; 0xcc2b + reloadmappart + special $0035 + 2writetext UnknownText_0xcc21 + 2jump UnknownScript_0xcc3c +; 0xcc35 + +UnknownScript_0xcc35: ; 0xcc35 + reloadmappart + special $0035 + 2writetext UnknownText_0xcc1c + +UnknownScript_0xcc3c: ; 0xcc3c + closetext + loadmovesprites + playsound SFX_WARP_TO + applymovement $0, MovementData_0xcc59 + 3call BANK(UnknownScript_0x122c1), UnknownScript_0x122c1 + special $0000 + writecode $8, $0 + newloadmap $f5 + playsound SFX_WARP_FROM + applymovement $0, MovementData_0xcc5d + end +; 0xcc59 + +MovementData_0xcc59: ; 0xcc59 + step_wait5 + turn_away_down + hide_person + step_end +; 0xcc5d + +MovementData_0xcc5d: ; 0xcc5d + db $3c, $58 + turn_away_down + step_end +; 0xcc61 Functioncc61: ; cc61 call Functionc6ea .asm_cc64 - ld hl, $4c72 + ld hl, Tablecc72 call Functionc6f5 jr nc, .asm_cc64 and $7f @@ -21455,7 +19608,51 @@ Functioncc61: ; cc61 ret ; cc72 -INCBIN "baserom.gbc", $cc72, $cce5 - $cc72 +Tablecc72: ; cc72 + dw Functioncc78 + dw Functioncc9c + dw Functioncca8 +; cc78 + +Functioncc78: ; cc78 + call GetMapPermission + call CheckOutdoorMap + jr z, .asm_cc82 + jr .asm_cc99 + +.asm_cc82 + ld a, [$dcb2] + ld d, a + ld a, [$dcb3] + ld e, a + callba Function15344 + jr nc, .asm_cc99 + ld a, c + ld [$d001], a + ld a, $1 + ret + +.asm_cc99 + ld a, $2 + ret +; cc9c + +Functioncc9c: ; cc9c + call GetPartyNick + ld hl, $4cbb + call Function31cd + ld a, $81 + ret +; cca8 + +Functioncca8: ; cca8 + ld hl, $4cb6 + call Function1d67 + ld a, $80 + ret +; ccb1 + +INCBIN "baserom.gbc", $ccb1, $cce5 - $ccb1 Functioncce5: ; cce5 call Functionccee @@ -21465,7 +19662,8 @@ Functioncce5: ; cce5 ; ccee Functionccee: ; ccee - ld de, $001d +; Strength + ld de, ENGINE_PLAINBADGE call CheckBadge jr c, Functioncd06 jr Functioncd09 @@ -21489,13 +19687,20 @@ Functioncd06: ; cd06 ; cd09 Functioncd09: ; cd09 - ld hl, $4d29 + ld hl, UnknownScript_0xcd29 call Function31cd ld a, $81 ret ; cd12 -INCBIN "baserom.gbc", $cd12, $cd1d - $cd12 +Functioncd12: ; cd12 + ld hl, BikeFlags + set 0, [hl] + ld a, [CurPartyMon] + ld e, a + ld d, 0 + ; fallthrough +; cd1d Functioncd1d: ; cd1d ld hl, PartySpecies @@ -21506,7 +19711,30 @@ Functioncd1d: ; cd1d ret ; cd29 -INCBIN "baserom.gbc", $cd29, $cd9d - $cd29 +UnknownScript_0xcd29: ; 0xcd29 + reloadmappart + special $0035 + 3callasm BANK(Functioncd12), Functioncd12 + 2writetext UnknownText_0xcd41 + copybytetovar $d1ef + cry $0000 + pause 3 + 2writetext UnknownText_0xcd46 + loadmovesprites + end +; 0xcd41 + +UnknownText_0xcd41: ; 0xcd41 + text_jump UnknownText_0x1c0774, BANK(UnknownText_0x1c0774) + db $50 +; 0xcd46 + +UnknownText_0xcd46: ; 0xcd46 + text_jump UnknownText_0x1c0788, BANK(UnknownText_0x1c0788) + db $50 +; 0xcd4b + +INCBIN "baserom.gbc", $cd4b, $cd9d - $cd4b Functioncd9d: ; cd9d call Functionc6ea @@ -21537,7 +19765,7 @@ Functioncdde: ; cdde ld c, [hl] push hl ld hl, $48a4 - call $4840 + call Functionc840 pop hl jr nc, .asm_ce09 ld a, l @@ -21559,35 +19787,53 @@ Functioncdde: ; cdde INCBIN "baserom.gbc", $ce0b, $ce0f - $ce0b UnknownScript_0xce0f: ; 0xce0f - 3callasm $03, $4706 + 3callasm BANK(GetPartyNick), GetPartyNick 2writetext UnknownText_0xcdd9 reloadmappart - 3callasm $03, $4e1d + 3callasm BANK(Functionce1d), Functionce1d loadmovesprites end ; 0xce1d -INCBIN "baserom.gbc", $ce1d, $ce3e - $ce1d +Functionce1d: ; ce1d + ld hl, $d1ec + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [$d1ee] + ld [hl], a + xor a + ld [hBGMapMode], a + call Function2173 + ld a, [$d1ef] + ld e, a + ld a, $23 + ld hl, $47d4 + rst FarCall + call Function2879 + call Function2914 + ret +; ce3e TryWhirlpoolOW: ; ce3e ld d, WHIRLPOOL call CheckPartyMove jr c, .asm_ce5c - ld de, $0021 - call CheckFlag2 + ld de, ENGINE_GLACIERBADGE + call CheckEngineFlag jr c, .asm_ce5c call Functioncdde jr c, .asm_ce5c ld a, BANK(UnknownScript_0xce6e) ld hl, UnknownScript_0xce6e - call PushScriptPointer + call CallScript scf ret .asm_ce5c ld a, BANK(UnknownScript_0xce66) ld hl, UnknownScript_0xce66 - call PushScriptPointer + call CallScript scf ret ; ce66 @@ -21626,7 +19872,7 @@ Functionce86: ; ce86 call GetFacingTileCoord call CheckHeadbuttTreeTile jr nz, .asm_ce97 - ld hl, $4ea7 + ld hl, UnknownScript_0xcea7 call Function31cd ld a, $81 ret @@ -21637,7 +19883,38 @@ Functionce86: ; ce86 ret ; ce9d -INCBIN "baserom.gbc", $ce9d, $cec9 - $ce9d +UnknownText_0xce9d: ; 0xce9d + text_jump UnknownText_0x1c0897, BANK(UnknownText_0x1c0897) + db $50 +; 0xcea2 + +UnknownText_0xcea2: ; 0xcea2 + text_jump UnknownText_0x1c08ac, BANK(UnknownText_0x1c08ac) + db $50 +; 0xcea7 + +UnknownScript_0xcea7: ; 0xcea7 + reloadmappart + special $0035 + 3callasm BANK(GetPartyNick), GetPartyNick + 2writetext UnknownText_0xce9d + reloadmappart + 3callasm $23, $480a + 3callasm $2e, $41ea + iffalse UnknownScript_0xcec3 + loadmovesprites + battlecheck + startbattle + returnafterbattle + end +; 0xcec3 + +UnknownScript_0xcec3: ; 0xcec3 + 2writetext UnknownText_0xcea2 + closetext + loadmovesprites + end +; 0xcec9 TryHeadbuttOW: ; cec9 ld d, $1d @@ -21645,7 +19922,7 @@ TryHeadbuttOW: ; cec9 jr c, .asm_ceda ld a, $3 ld hl, $4edc - call PushScriptPointer + call CallScript scf ret @@ -21669,7 +19946,7 @@ Functioncef4: ; cef4 ld a, d cp $18 jr nz, .asm_cf07 - ld hl, $4f2e + ld hl, UnknownScript_0xcf2e call Function31cd ld a, $81 ret @@ -21702,7 +19979,37 @@ Functioncf0d: ; cf0d ret ; cf2e -INCBIN "baserom.gbc", $cf2e, $cf8e - $cf2e +UnknownScript_0xcf2e: ; 0xcf2e + reloadmappart + special $0035 + 3callasm BANK(GetPartyNick), GetPartyNick + 2writetext UnknownText_0xcf58 + loadmovesprites + special $003b + playsound SFX_STRENGTH + earthquake 84 + applymovement2 MovementData_0xcf55 + disappear $fe + 3callasm $2e, $4219 + copybytetovar $d22e + iffalse .done + battlecheck + startbattle + returnafterbattle +.done + end +; 0xcf55 + +MovementData_0xcf55: ; 0xcf55 + db $57, $0a + step_end + +UnknownText_0xcf58: ; 0xcf58 + text_jump UnknownText_0x1c08f0, BANK(UnknownText_0x1c08f0) + db $50 +; 0xcf5d + +INCBIN "baserom.gbc", $cf5d, $cf8e - $cf5d Functioncf8e: ; cf8e @@ -21720,6 +20027,7 @@ Functioncf8e: ; cf8e ret ; cfa5 + INCBIN "baserom.gbc", $cfa5, $d0b3 - $cfa5 @@ -21819,19 +20127,19 @@ TryCutOW: ; d186 ld d, CUT call CheckPartyMove jr c, .asm_d19f - ld de, $001c - call CheckFlag2 + ld de, ENGINE_HIVEBADGE + call CheckEngineFlag jr c, .asm_d19f ld a, BANK(UnknownScript_0xd1a9) ld hl, UnknownScript_0xd1a9 - call PushScriptPointer + call CallScript scf ret .asm_d19f ld a, BANK(UnknownScript_0xd1cd) ld hl, UnknownScript_0xd1cd - call PushScriptPointer + call CallScript scf ret ; d1a9 @@ -21968,7 +20276,7 @@ Functiond20d: ; d20d jp Functiond2ff ; d244 -Functiond244: ; d244 +_PickUpItem: ; d244 call Functiond27b jr nz, .asm_d278 push hl @@ -22688,9 +20996,9 @@ Functiond88c: ; d88c ld a, [IsInBattle] and a jr nz, .asm_d9f3 - call RNG + call Random ld b, a - call RNG + call Random ld c, a .asm_d9b5 @@ -22862,39 +21170,41 @@ INCBIN "baserom.gbc", $da96, $dcb6 - $da96 Functiondcb6: ; dcb6 + ld a, b - ld hl, $ad26 - ld bc, $0020 + ld hl, BoxMons + ld bc, BoxMon2 - BoxMon1 call AddNTimes ld b, h ld c, l - ld hl, $0017 + ld hl, BoxMon1PP - BoxMon1 add hl, bc push hl push bc ld de, TempMonPP - ld bc, $0004 + ld bc, NUM_MOVES call CopyBytes pop bc - ld hl, $0002 + ld hl, BoxMon1Moves - BoxMon1 add hl, bc push hl - ld de, TempMonMove1 - ld bc, $0004 + ld de, TempMonMoves + ld bc, NUM_MOVES call CopyBytes pop hl pop de + ld a, [$cfa9] push af ld a, [MonType] push af - ld b, $0 + ld b, 0 .asm_dcec ld a, [hli] and a jr z, .asm_dd18 ld [TempMonMove1], a - ld a, $2 + ld a, BOXMON ld [MonType], a ld a, b ld [$cfa9], a @@ -22916,7 +21226,7 @@ Functiondcb6: ; dcb6 inc de inc b ld a, b - cp $4 + cp NUM_MOVES jr c, .asm_dcec .asm_dd18 @@ -22927,15 +21237,16 @@ Functiondcb6: ; dcb6 ret ; dd21 + INCBIN "baserom.gbc", $dd21, $de6e - $dd21 Functionde6e: ; de6e - ld a, $1 + ld a, 1 ; BANK(BoxCount) call GetSRAMBank - ld de, $ad10 + ld de, BoxCount ld a, [de] - cp $14 + cp 20 jp nc, Functiondf42 inc a ld [de], a @@ -22952,21 +21263,21 @@ Functionde6e: ; de6e inc a jr nz, .asm_de85 call GetBaseData - call Functiondf47 + call ShiftBoxMon ld hl, PlayerName - ld de, $afa6 - ld bc, $000b + ld de, BoxMonOT + ld bc, BoxMon2OT - BoxMon1OT call CopyBytes ld a, [CurPartySpecies] ld [$d265], a call GetPokemonName - ld de, $b082 + ld de, BoxMon1Nickname ld hl, StringBuffer1 - ld bc, $000b + ld bc, BoxMon2Nickname - BoxMon1Nickname call CopyBytes - ld hl, EnemyMonSpecies - ld de, $ad26 - ld bc, $0006 + ld hl, EnemyMon + ld de, BoxMon1 + ld bc, 6 ; species + item + moves call CopyBytes ld hl, PlayerID ld a, [hli] @@ -23022,9 +21333,9 @@ Functionde6e: ; de6e dec a call SetSeenAndCaughtMon ld a, [CurPartySpecies] - cp $c9 + cp UNOWN jr nz, .asm_df20 - ld hl, $ad3b + ld hl, BoxMon1DVs ld a, $2d call Predef ld hl, $7a18 @@ -23032,15 +21343,15 @@ Functionde6e: ; de6e rst FarCall .asm_df20 - ld hl, $ad28 + ld hl, BoxMon1Moves ld de, TempMonMove1 - ld bc, $0004 + ld bc, NUM_MOVES call CopyBytes - ld hl, $ad3d + ld hl, BoxMon1PP ld de, TempMonPP - ld bc, $0004 + ld bc, NUM_MOVES call CopyBytes - ld b, $0 + ld b, 0 call Functiondcb6 call CloseSRAM scf @@ -23053,44 +21364,51 @@ Functiondf42: ; df42 ret ; df47 -Functiondf47: ; df47 - ld hl, $afa6 - ld bc, $000b - call $5f5f - ld hl, $b082 - ld bc, $000b - call $5f5f - ld hl, $ad26 - ld bc, $0020 - ld a, [$ad10] - cp $2 +ShiftBoxMon: ; df47 + ld hl, BoxMonOT + ld bc, BoxMon2OT - BoxMon1OT + call .asm_df5f + + ld hl, BoxMonNicknames + ld bc, BoxMon2Nickname - BoxMon1Nickname + call .asm_df5f + + ld hl, BoxMons + ld bc, BoxMon2 - BoxMon1 + +.asm_df5f + ld a, [BoxCount] + cp 2 ret c + push hl call AddNTimes dec hl ld e, l ld d, h pop hl - ld a, [$ad10] + + ld a, [BoxCount] dec a call AddNTimes dec hl + push hl - ld a, [$ad10] + ld a, [BoxCount] dec a - ld hl, $0000 + ld hl, 0 call AddNTimes ld c, l ld b, h pop hl -.asm_df83 +.loop ld a, [hld] ld [de], a dec de dec bc ld a, c or b - jr nz, .asm_df83 + jr nz, .loop ret ; df8c @@ -23187,13 +21505,16 @@ INCBIN "baserom.gbc", $e035, $e039 - $e035 Functione039: ; e039 + ld hl, PartyCount + ld a, [$d10b] and a jr z, .asm_e04a - ld a, $1 + + ld a, 1 ; BANK(BoxCount) call GetSRAMBank - ld hl, $ad10 + ld hl, BoxCount .asm_e04a ld a, [hl] @@ -23201,7 +21522,7 @@ Functione039: ; e039 ld [hli], a ld a, [CurPartyMon] ld c, a - ld b, $0 + ld b, 0 add hl, bc ld e, l ld d, h @@ -23217,7 +21538,7 @@ Functione039: ; e039 ld a, [$d10b] and a jr z, .asm_e06d - ld hl, $afa6 + ld hl, BoxMonOT ld d, $13 .asm_e06d @@ -23227,7 +21548,7 @@ Functione039: ; e039 cp d jr nz, .asm_e07e ld [hl], $ff - jp $60f0 + jp .asm_60f0 .asm_e07e ld d, h @@ -23238,17 +21559,17 @@ Functione039: ; e039 ld a, [$d10b] and a jr z, .asm_e090 - ld bc, $b082 - + ld bc, BoxMonNicknames .asm_e090 call CopyDataUntil - ld hl, PartyMon1Species - ld bc, $0030 + + ld hl, PartyMons + ld bc, PartyMon2 - PartyMon1 ld a, [$d10b] and a jr z, .asm_e0a5 - ld hl, $ad26 - ld bc, $0020 + ld hl, BoxMons + ld bc, BoxMon2 - BoxMon1 .asm_e0a5 ld a, [CurPartyMon] @@ -23258,13 +21579,13 @@ Functione039: ; e039 ld a, [$d10b] and a jr z, .asm_e0bc - ld bc, $0020 + ld bc, BoxMon2 - BoxMon1 add hl, bc - ld bc, $afa6 + ld bc, BoxMonOT jr .asm_e0c3 .asm_e0bc - ld bc, $0030 + ld bc, PartyMon2 - PartyMon1 add hl, bc ld bc, PartyMon1OT @@ -23274,24 +21595,26 @@ Functione039: ; e039 ld a, [$d10b] and a jr z, .asm_e0d2 - ld hl, $b082 + ld hl, BoxMonNicknames .asm_e0d2 - ld bc, $000b + ld bc, BoxMon2Nickname - BoxMon1Nickname ld a, [CurPartyMon] call AddNTimes ld d, h ld e, l - ld bc, $000b + ld bc, BoxMon2Nickname - BoxMon1Nickname add hl, bc - ld bc, $de83 + ld bc, PartyMonNicknamesEnd ld a, [$d10b] and a jr z, .asm_e0ed - ld bc, $b15e + ld bc, BoxMonNicknamesEnd .asm_e0ed call CopyDataUntil + +.asm_60f0 ld a, [$d10b] and a jp nz, CloseSRAM @@ -23702,9 +22025,9 @@ Functione277: ; e277 call GetFarByte ld b, a ld hl, $ad2c - call RNG + call Random ld [hli], a - call RNG + call Random ld [hl], a call CloseSRAM ld a, $13 @@ -23780,7 +22103,7 @@ Functione3de: ; e3de ld de, StringBuffer1 call InitName ld a, $4 - ld hl, $2b4d + ld hl, Function2b4d rst FarCall ret ; e3fd @@ -23870,7 +22193,7 @@ Functione6ce: ; e6ce ld hl, $4000 rst FarCall ld bc, $0e07 - call $1dd2 + call Function1dd2 ret c .asm_e6ea @@ -24283,22 +22606,22 @@ Functionf8ec: ; f8ec push af ld a, [MonType] and a - ld hl, PartyMon1Move1 - ld bc, $0030 + ld hl, PartyMon1Moves + ld bc, PartyMon2 - PartyMon1 jr z, .asm_f91a - ld hl, OTPartyMon1Move1 + ld hl, OTPartyMon1Moves dec a jr z, .asm_f91a - ld hl, TempMonMove1 + ld hl, TempMonMoves dec a jr z, .asm_f915 - ld hl, TempMonMove1 + ld hl, TempMonMoves dec a jr z, .asm_f915 - ld hl, BattleMonMove1 + ld hl, BattleMonMoves .asm_f915 - call $7969 + call Function7969 jr .asm_f91d .asm_f91a @@ -24320,7 +22643,7 @@ Functionf8ec: ; f8ec push bc ld bc, $0015 ld a, [MonType] - cp $4 + cp WILDMON jr nz, .asm_f942 ld bc, $0006 @@ -24349,6 +22672,8 @@ Functionf8ec: ; f8ec Functionf963: ; f963 ld a, [CurPartyMon] call AddNTimes + +Function7969: ; 7969 ld a, [$cfa9] ld c, a ld b, $0 @@ -24555,9 +22880,7 @@ Function107bb: ; 107bb ld a, [InputType] or a jr z, .asm_107ca - ld a, $77 - ld hl, $628f - rst FarCall + callba Function1de28f .asm_107ca call Function107d7 @@ -25059,7 +23382,7 @@ INCBIN "baserom.gbc", $11bf7, $11c51 - $11bf7 Function11c51: ; 11c51 call ClearSprites callab Function8cf53 - call $0e51 + call Functione51 call Functione5f ld de, $5e65 ld hl, $8eb0 @@ -25267,9 +23590,7 @@ StartMenu: ; 125cd call .DrawBugContestStatusBox call Function2e31 call Function2e20 - ld a, $1 - ld hl, $64bf - rst $8 + callba Function64bf call .DrawBugContestStatus call Function485 jr .Select @@ -25391,8 +23712,8 @@ StartMenu: ; 125cd call MenuFunc_1e7f call .DrawBugContestStatus call Function1ad2 - call $0d90 - call $2b5c + call Functiond90 + call Function2b5c ret ; 126d3 @@ -25661,7 +23982,7 @@ StartMenu_Quit: ; 128f0 jr c, .asm_12903 ld a, $4 ld hl, $760b - call $31cf + call Function31cf ld a, 4 ret .asm_12903 @@ -25756,7 +24077,7 @@ StartMenu_Pack: ; 1295b ld a, 0 ret .asm_12970 - call $2b4d + call Function2b4d ld a, 4 ret ; 12976 @@ -25813,7 +24134,7 @@ StartMenu_Pokemon: ; 12976 .quit ld a, b push af - call $2b4d + call Function2b4d pop af ret ; 129d5 @@ -25994,7 +24315,7 @@ GiveTakePartyMonItem: ; 12b60 call ClearPalettes call Function12ba9 call ClearPalettes - call $0e58 + call Functione58 call Function1c07 ld a, 0 ret @@ -26261,13 +24582,13 @@ Function12d45: ; 12d45 call LoadMenuDataHeader call Function1d81 call Function1c07 - jp c, $6dc6 + jp c, .asm_12dc6 ld a, [$cfa9] cp $1 jr z, .asm_12d6d cp $2 jr z, .asm_12d76 - jp $6dc6 + jp .asm_12dc6 .asm_12d6d ld a, $2e @@ -26277,24 +24598,24 @@ Function12d45: ; 12d45 ret .asm_12d76 - ld hl, $6df1 + ld hl, UnknownText_0x12df1 call Function12cf5 jr c, .asm_12d9a ld a, [CurPartyMon] ld b, a callba Function4456e jr c, .asm_12d92 - ld hl, $6dfb + ld hl, UnknownText_0x12dfb call Function1d67 jr .asm_12dc6 .asm_12d92 - ld hl, $6df6 + ld hl, UnknownText_0x12df6 call Function1d67 jr .asm_12dc6 .asm_12d9a - ld hl, $6de2 + ld hl, UnknownText_0x12de2 call Function12cf5 jr c, .asm_12dc6 call GetPartyItemLocation @@ -26305,12 +24626,12 @@ Function12d45: ; 12d45 call GetPartyItemLocation ld [hl], $0 call GetCurNick - ld hl, $6de7 + ld hl, UnknownText_0x12de7 call Function1d67 jr .asm_12dc6 .asm_12dbe - ld hl, $6dec + ld hl, UnknownText_0x12dec call Function1d67 jr .asm_12dc6 @@ -26319,7 +24640,39 @@ Function12d45: ; 12d45 ret ; 12dc9 -INCBIN "baserom.gbc", $12dc9, $12e00 - $12dc9 + +INCBIN "baserom.gbc", $12dc9, $12de2 - $12dc9 + + +UnknownText_0x12de2: ; 0x12de2 + text_jump UnknownText_0x1c1c22, BANK(UnknownText_0x1c1c22) + db "@" +; 0x12de7 + +UnknownText_0x12de7: ; 0x12de7 + text_jump UnknownText_0x1c1c47, BANK(UnknownText_0x1c1c47) + db "@" +; 0x12dec + +UnknownText_0x12dec: ; 0x12dec + text_jump UnknownText_0x1c1c62, BANK(UnknownText_0x1c1c62) + db "@" +; 0x12df1 + +UnknownText_0x12df1: ; 0x12df1 + text_jump UnknownText_0x1c1c86, BANK(UnknownText_0x1c1c86) + db "@" +; 0x12df6 + +UnknownText_0x12df6: ; 0x12df6 + text_jump UnknownText_0x1c1ca9, BANK(UnknownText_0x1c1ca9) + db "@" +; 0x12dfb + +UnknownText_0x12dfb: ; 0x12dfb + text_jump UnknownText_0x1c1cc4, BANK(UnknownText_0x1c1cc4) + db "@" +; 0x12e00 OpenPartyStats: ; 12e00 @@ -26397,9 +24750,7 @@ Function12e55: ; 12e55 ; 12e6a Function12e6a: ; 12e6a - ld a, $3 - ld hl, $4ce5 - rst FarCall + callba Functioncce5 ld a, [$d0ec] cp $1 jr nz, .asm_12e7c @@ -26579,7 +24930,7 @@ INCBIN "baserom.gbc", $12f5b, $12fba - $12f5b Function12fba: ; 12fba ld a, [CurPartySpecies] - cp $fd + cp EGG jr z, .asm_12fd2 ld hl, Options ld a, [hl] @@ -26692,13 +25043,13 @@ Function1308f: ; 1308f inc a ld [CurPartyMon], a ld c, a - ld b, $0 + ld b, 0 ld hl, PartySpecies add hl, bc ld a, [hl] cp $ff jr z, .asm_130a7 - cp $fd + cp EGG ret nz jr .asm_1308f @@ -26711,11 +25062,11 @@ Function1308f: ; 1308f dec a ld [CurPartyMon], a ld c, a - ld b, $0 + ld b, 0 ld hl, PartySpecies add hl, bc ld a, [hl] - cp $fd + cp EGG ret nz ld a, [CurPartyMon] and a @@ -26969,16 +25320,16 @@ Function132da: ; 132da ret z ld c, a ld e, a - ld d, $0 + ld d, 0 ld hl, PartyCount add hl, de .asm_132e7 ld a, [hl] and a jr z, .asm_132f3 - cp $fd + cp EGG jr z, .asm_132f3 - cp $fc + cp NUM_POKEMON + 1 jr c, .asm_132f8 .asm_132f3 @@ -27001,7 +25352,7 @@ Function132fe: ; 132fe cp c ret z ld e, c - ld d, $0 + ld d, 0 ld hl, PartySpecies add hl, de .asm_1330f @@ -27010,9 +25361,9 @@ Function132fe: ; 132fe ret z and a jr z, .asm_1331e - cp $fd + cp EGG jr z, .asm_1331e - cp $fc + cp NUM_POKEMON + 1 jr c, .asm_13321 .asm_1331e @@ -27020,8 +25371,8 @@ Function132fe: ; 132fe jr .asm_1330f .asm_13321 - ld hl, $c4b2 - ld [hl], $ed + hlcoord 18, 0 + ld [hl], "▶" ret ; 13327 @@ -27037,7 +25388,7 @@ SelectMenu: ; 13327 ld b, BANK(ItemMayBeRegisteredText) ld hl, ItemMayBeRegisteredText call Function269a - call $0a46 + call Functiona46 jp Function2dcf ; 13340 @@ -27392,7 +25743,7 @@ Function1353f: ; 1353f push hl ld a, [$d041] ld e, a - ld d, $0 + ld d, 0 ld hl, $d0f1 add hl, de ld a, [hl] @@ -27416,8 +25767,8 @@ Function1356b: ; 1356b Function13575: ; 13575 push de ld e, a - ld d, $0 - ld hl, $7583 + ld d, 0 + ld hl, .floors add hl, de add hl, de ld a, [hli] @@ -27427,7 +25778,60 @@ Function13575: ; 13575 ret ; 13583 -INCBIN "baserom.gbc", $13583, $135eb - $13583 +.floors + dw .b4f + dw .b3f + dw .b2f + dw .b1f + dw ._1f + dw ._2f + dw ._3f + dw ._4f + dw ._5f + dw ._6f + dw ._7f + dw ._8f + dw ._9f + dw ._10f + dw ._11f + dw .roof + +.b4f + db "B4F@" +.b3f + db "B3F@" +.b2f + db "B2F@" +.b1f + db "B1F@" +._1f + db "1F@" +._2f + db "2F@" +._3f + db "3F@" +._4f + db "4F@" +._5f + db "5F@" +._6f + db "6F@" +._7f + db "7F@" +._8f + db "8F@" +._9f + db "9F@" +._10f + db "10F@" +._11f + db "11F@" +.roof + db "ROOF@" +; 135db + + +INCBIN "baserom.gbc", $135db, $135eb - $135db UnknownScript_0x135eb: ; 0x135eb writecode $3, $6 @@ -27442,7 +25846,7 @@ UnknownScript_0x135eb: ; 0x135eb INCBIN "baserom.gbc", $135f8, $13603 - $135f8 UnknownScript_0x13603: ; 0x13603 - playsound $0027 + playsound SFX_ELEVATOR_END loadfont 2writetext UnknownText_0x13614 closetext @@ -27457,7 +25861,53 @@ UnknownText_0x13614: ; 0x13614 db $50 ; 0x13619 -INCBIN "baserom.gbc", $13619, $13b87 - $13619 +INCBIN "baserom.gbc", $13619, $1365b - $13619 + + +Function1365b: ; 1365b + ld a, c + ld de, .table2 - .table1 + ld hl, .table1 + call IsInArray + jr nc, .asm_1367f + + ld a, $c ; jumpstd + ld [$d03f], a + inc hl + ld a, [hli] + ld [$d03f + 1], a + ld a, [hli] + ld [$d03f + 2], a + ld a, BANK(UnknownScript_0x1369a) + ld hl, UnknownScript_0x1369a + call CallScript + scf + ret + +.asm_1367f + xor a + ret +; 13681 + +.table1 + dbw $91, $0003 ; bookshelf +.table2 + dbw $93, $0031 ; pc + dbw $94, $000b ; radio + dbw $95, $0007 ; map + dbw $96, $0006 ; merchandise + dbw $97, $0009 ; tv + dbw $9d, $0008 ; window + dbw $9f, $0005 ; incense burner + dbw $ff ; end +; 1369a + +UnknownScript_0x1369a: ; 0x1369a + 2jump $d03f +; 0x1369d + + +INCBIN "baserom.gbc", $1369d, $13b87 - $1369d GetSquareRoot: ; 13b87 @@ -27623,7 +26073,7 @@ Function1409b: ; 1409b ; 140ae Function140ae: ; 140ae - call $06e3 + call Function6e3 ld c, a and $c0 jr nz, .asm_140c8 @@ -28009,7 +26459,7 @@ Function142a7: ; 142a7 ; 142c4 -GetSpritePalette: ; 142c4 +_GetSpritePalette: ; 142c4 ld a, c call GetMonSprite jr c, .asm_142d8 @@ -30015,9 +28465,7 @@ Function157e9: ; 0x157e9 .askquantity ld hl, .HowManyText call Function1d4f - ld a, $9 - ld hl, $4fbf - rst $8 + callba Function24fbf call Function1c07 call Function1c07 jr c, .done @@ -30034,7 +28482,7 @@ Function157e9: ; 0x157e9 ld [$d10c], a ld a, [Buffer2] ld [$d107], a - ld hl, $d8f1 + ld hl, PCItems call Function2f53 ld a, $3b call Predef @@ -30075,7 +28523,7 @@ KrisTossItemMenu: ; 0x1585f .asm_15868 call Function15985 jr c, .asm_15878 - ld de, $d8f1 + ld de, PCItems ld a, $4 ld hl, $69f4 rst $8 @@ -30112,20 +28560,14 @@ KrisDepositItemMenu: ; 0x1588b jr c, .asm_158b6 call Function2ed3 call Function1d6e - ld a, $4 - ld hl, $46a5 - rst $8 + callba Function106a5 .asm_1589c - ld a, $4 - ld hl, $46be - rst $8 + callba Function106be ld a, [$cf66] and a jr z, .asm_158b3 call Function158cc - ld a, $4 - ld hl, CheckRegisteredItem - rst $8 + callba CheckRegisteredItem jr .asm_1589c .asm_158b3 @@ -30157,9 +28599,7 @@ Function158cc: ; 0x158cc push af ld a, $0 ld [$c2ce], a - ld a, $3 - ld hl, $5453 - rst $8 + callba CheckItemMenu ld a, [$d142] ld hl, JumpTable158e7 rst JumpTable @@ -30193,9 +28633,7 @@ JumpTable158e7: ; 0x158e7 ; 0x1590a Function1590a: ; 0x1590a - ld a, $3 - ld hl, $5427 - rst $8 + callba _CheckTossableItem ld a, [$d142] and a jr z, .asm_1591d @@ -30206,9 +28644,7 @@ Function1590a: ; 0x1590a .asm_1591d ld hl, .HowManyText call Function1d4f - ld a, $9 - ld hl, $4fbf - rst $8 + callba Function24fbf push af call Function1c07 call Function1c07 @@ -30220,7 +28656,7 @@ Function1590a: ; 0x1590a ld [Buffer1], a ld a, [$d107] ld [Buffer2], a - ld hl, $d8f1 + ld hl, PCItems call Function2f66 jr nc, .asm_15965 ld a, [Buffer1] @@ -30260,9 +28696,7 @@ Function1590a: ; 0x1590a KrisMailBoxMenu: ; 0x1597d - ld a, $11 - ld hl, $47a0 - rst $8 + callba _KrisMailBoxMenu xor a ret ; 0x15985 @@ -30354,7 +28788,7 @@ MenuData15a08: ; 0x15a08 db %10110000 db 4, 8 ; rows/cols? db 2 ; horizontal spacing? - dbw 0, $d8f1 + dbw 0, PCItems dbw BANK(Function24ab4), Function24ab4 dbw BANK(Function24ac3), Function24ac3 dbw BANK(Function244c3), Function244c3 @@ -30799,14 +29233,14 @@ Function15cef: ; 15cef ld d, $0 ld b, $1 ld hl, WalkingDirection - call BitTableFunc + call FlagAction call Function15fc3 ld de, Money ld bc, $ffc3 call Function15ffa ld a, $4 call Function15c7d - call $0a36 + call Functiona36 .asm_15d68 call SpeechTextBox @@ -30820,14 +29254,14 @@ Function15cef: ; 15cef .asm_15d6f ld a, $3 call Function15c7d - call $0a36 + call Functiona36 and a ret .asm_15d79 ld a, $2 call Function15c7d - call $0a36 + call Functiona36 and a ret ; 15d83 @@ -30861,7 +29295,7 @@ Function15da5: ; 15da5 ld d, $0 ld b, $2 ld hl, WalkingDirection - call BitTableFunc + call FlagAction ld a, c and a jr nz, .asm_15dd8 @@ -30889,7 +29323,7 @@ Function15da5: ; 15da5 .asm_15dd8 ld a, $5 call Function15c7d - call $0a36 + call Functiona36 scf ret ; 15de2 @@ -31010,7 +29444,7 @@ Function15efd: ; 15efd ld a, $9 ld hl, $4af0 rst FarCall - call $0a36 + call Functiona36 .asm_15f6e call Function1c07 @@ -31056,7 +29490,7 @@ Function15fc3: ; 15fc3 Function15fcd: ; 15fcd call Function1d4f - call $0a36 + call Functiona36 call Function1c07 ret ; 15fd7 @@ -31218,7 +29652,7 @@ Function16053: ; 16053 Function1606f: ; 1606f ld a, $2 - ld de, $d855 + ld de, Coins call $6055 ld a, $2 ld bc, $608d @@ -31243,7 +29677,7 @@ INCBIN "baserom.gbc", $1608d, $1608f - $1608d Function1608f: ; 1608f ld a, $2 - ld de, $d855 + ld de, Coins call $6037 jr nc, .asm_1609f xor a @@ -31260,7 +29694,7 @@ Function1608f: ; 1608f Function160a1: ; 160a1 ld a, $2 - ld de, $d855 + ld de, Coins jp $600d ; 160a9 @@ -33031,7 +31465,7 @@ Function24528: ; 24528 call Function2173 call Function321c call Function1ad2 - call $0e51 + call Functione51 ret ; 24547 @@ -33649,7 +32083,7 @@ Function24b25: ; 24b25 ld hl, $c4c5 ld de, String24b8e call PlaceString - ld de, $d855 + ld de, Coins ld bc, $0204 ld hl, $c4c1 call PrintNum @@ -33672,7 +32106,7 @@ Function24b4e: ; 24b4e ld de, CoinString call PlaceString ld hl, $c4eb - ld de, $d855 + ld de, Coins ld bc, $0204 call PrintNum ret @@ -33765,7 +32199,7 @@ Function24be7: ; 24be7 ld l, c inc hl ld c, $3 - call $3842 + call Function3842 .asm_24c3e pop af @@ -33802,7 +32236,7 @@ Function24c64: ; 24c64 push hl ld [CurItem], a ld hl, NumItems - call Function2f79 + call PickUpItem pop hl jr nc, .asm_24c89 ld a, [hl] @@ -34460,7 +32894,7 @@ Function25072: ; 25072 ld a, [$cf87] ld d, a ld a, [$cf8a] - call FarJpDe + call FarCall_de ret ; 25097 @@ -34544,7 +32978,7 @@ ProfOaksPC: ; 0x265d3 .shutdown ld hl, OakPCText4 call PrintText - call $0a36 + call Functiona36 call Function1c07 ret ; 0x265ee @@ -34554,7 +32988,7 @@ ProfOaksPCBoot ; 0x265ee call PrintText call Rate call StartSFX ; sfx loaded by previous Rate function call - call $0a36 + call Functiona36 call WaitSFX ret ; 0x26601 @@ -34566,7 +33000,7 @@ Function26601: ; 0x26601 call StartMusic pop de call StartSFX - call $0a36 + call Functiona36 call WaitSFX ret ; 0x26616 @@ -34586,7 +33020,7 @@ Rate: ; 0x26616 call ClearOakRatingBuffers ld hl, OakPCText3 call PrintText - call $0a36 + call Functiona36 ld a, [$d003] ld hl, OakRatings call FindOakRating @@ -34885,7 +33319,7 @@ Function26a3b: ; 26a3b push bc call Function26a30 pop bc - call BitTable1Func + call EventFlagAction ret ; 26a44 @@ -35266,30 +33700,95 @@ INCBIN "baserom.gbc", $27a28, $27a2d - $27a28 SECTION "bankA",ROMX,BANK[$A] -INCBIN "baserom.gbc", $28000, $2a111 - $28000 +INCBIN "baserom.gbc", $28000, $2a0e7 - $28000 + +Function2a0e7: ; 2a0e7 +; Try to trigger a wild encounter. + call Function2a103 + jr nc, .asm_2a0f8 + call Function2a14f + jr nz, .asm_2a0f8 + call Function2a1df + jr nc, .asm_2a0f8 + xor a + ret + +.asm_2a0f8 + xor a + ld [$d22e], a + ld [BattleType], a + ld a, 1 + and a + ret +; 2a103 + +Function2a103: ; 2a103 + call Function2a111 + call Function2a124 + call Function2a138 + call Random + cp b + ret +; 2a111 Function2a111: ; 2a111 ld hl, $d25a call Function1852 - ld a, $3 + ld a, 3 jr z, .asm_2a11e ld a, [TimeOfDay] - .asm_2a11e ld c, a - ld b, $0 + ld b, 0 add hl, bc ld b, [hl] ret ; 2a124 -INCBIN "baserom.gbc", $2a124, $2a14f - $2a124 +Function2a124: ; 2a124 +; Pokemon March and Ruins of Alph signal double encounter rate. +; Pokemon Lullaby halves encounter rate. + ld a, [CurMusic] + cp MUSIC_POKEMON_MARCH + jr z, .asm_2a135 + cp MUSIC_RUINS_OF_ALPH_RADIO + jr z, .asm_2a135 + cp MUSIC_POKEMON_LULLABY + ret nz + srl b + ret + +.asm_2a135 + sla b + ret +; 2a138 + +Function2a138: ; 2a138 +; Cleanse Tag halves encounter rate. + ld hl, PartyMon1Item + ld de, PartyMon2 - PartyMon1 + ld a, [PartyCount] + ld c, a +.next + ld a, [hl] + cp CLEANSE_TAG + jr z, .asm_2a14c + add hl, de + dec c + jr nz, .next + ret + +.asm_2a14c + srl b + ret +; 2a14f Function2a14f: ; 2a14f call Function2a200 - jp nc, $61c1 + jp nc, .asm_2a1c1 call Function2a2ce - jp c, $61c9 + jp c, .asm_2a1c9 + inc hl inc hl inc hl @@ -35299,15 +33798,15 @@ Function2a14f: ; 2a14f inc hl inc hl ld a, [TimeOfDay] - ld bc, $000e + ld bc, $e call AddNTimes ld de, $61cb .asm_2a174 push hl .asm_2a175 - call RNG - cp $64 + call Random + cp 100 jr nc, .asm_2a175 inc a ld b, a @@ -35322,24 +33821,25 @@ Function2a14f: ; 2a14f .asm_2a187 ld c, [hl] - ld b, $0 + ld b, 0 pop hl add hl, bc ld a, [hli] ld b, a call Function1852 jr nz, .asm_2a1aa - call RNG - cp $59 + + call Random + cp 89 jr c, .asm_2a1aa inc b - cp $a5 + cp 165 jr c, .asm_2a1aa inc b - cp $d8 + cp 216 jr c, .asm_2a1aa inc b - cp $f2 + cp 242 jr c, .asm_2a1aa inc b @@ -35349,9 +33849,11 @@ Function2a14f: ; 2a14f ld b, [hl] call Function2a4a0 jr c, .asm_2a1c1 + ld a, b - cp $c9 + cp UNOWN jr nz, .asm_2a1bf + ld a, [UnlockedUnowns] and a jr z, .asm_2a1c1 @@ -35360,43 +33862,79 @@ Function2a14f: ; 2a14f jr .asm_2a1c5 .asm_2a1c1 - ld a, $1 + ld a, 1 and a ret .asm_2a1c5 ld a, b ld [$d22e], a + +.asm_2a1c9 xor a ret ; 2a1cb -INCBIN "baserom.gbc", $2a1cb, $2a200 - $2a1cb + +INCBIN "baserom.gbc", $2a1cb, $2a1df - $2a1cb + + +Function2a1df: ; 2a1df + ld a, [$dca1] + and a + jr z, .asm_2a1fe + ld hl, PartyMon1CurHP + ld bc, PartyMon2 - PartyMon1 - 1 +.asm_2a1eb + ld a, [hli] + or [hl] + jr nz, .asm_2a1f2 + add hl, bc + jr .asm_2a1eb + +.asm_2a1f2 +; to PartyMonLevel + dec hl + dec hl + dec hl + dec hl + + ld a, [CurPartyLevel] + cp [hl] + jr nc, .asm_2a1fe + and a + ret + +.asm_2a1fe + scf + ret +; 2a200 Function2a200: ; 2a200 call Function1852 jr z, .asm_2a21d ld hl, WildMons5 ld bc, $002f - call $623d + call .asm_2a23d ret c ld hl, WildMons1 ld de, WildMons3 - call $6235 + call .asm_2a235 ld bc, $002f jr .asm_2a27a .asm_2a21d ld hl, WildMons6 ld bc, $0009 - call $623d + call .asm_2a23d ret c ld hl, WildMons2 ld de, WildMons4 - call $6235 + call .asm_2a235 ld bc, $0009 jr .asm_2a27a +.asm_2a235 call Function2f17 and a ret z @@ -35404,7 +33942,8 @@ Function2a200: ; 2a200 ld l, e ret - call $627f +.asm_2a23d + call Function2a27f push hl ld hl, $dc20 bit 2, [hl] @@ -35416,7 +33955,7 @@ Function2a200: ; 2a200 ld a, [$dfcd] cp e jr nz, .asm_2a25c - call $6288 + call Function2a288 jr nc, .asm_2a278 scf ret @@ -35433,7 +33972,7 @@ Function2a200: ; 2a200 ld a, [$dc5b] cp e jr nz, .asm_2a278 - call $6288 + call Function2a288 jr nc, .asm_2a278 scf ret @@ -35443,16 +33982,19 @@ Function2a200: ; 2a200 ret .asm_2a27a - call $627f - jr .asm_2a288 + call Function2a27f + jr Function2a288 +; 2a27f +Function2a27f: ; 2a27f ld a, [MapGroup] ld d, a ld a, [MapNumber] ld e, a ret +; 2a288 -.asm_2a288 +Function2a288: ; 2a288 push hl ld a, [hl] inc a @@ -35468,7 +34010,7 @@ Function2a200: ; 2a200 .asm_2a296 pop hl add hl, bc - jr .asm_2a288 + jr Function2a288 .asm_2a29a pop hl @@ -35481,9 +34023,9 @@ Function2a200: ; 2a200 ret ; 2a2a0 -SpecialRoamMons: ; 2a2a0 + +InitRoamMons: ; 2a2a0 ; initialize RoamMon structs -; include commented-out parts from the gs function ; species ld a, RAIKOU @@ -35531,17 +34073,17 @@ Function2a2ce: ; 2a2ce push hl call Function1852 jr z, .asm_2a30a - call $627f - call RNG - cp $64 + call Function2a27f + call Random + cp 100 jr nc, .asm_2a30a - and $3 + and 3 jr z, .asm_2a30a dec a ld hl, RoamMon1MapGroup ld c, a - ld b, $0 - ld a, $7 + ld b, 0 + ld a, 7 call AddNTimes ld a, d cp [hl] @@ -35557,7 +34099,7 @@ Function2a2ce: ; 2a2ce ld [$d22e], a ld a, [hl] ld [CurPartyLevel], a - ld a, $5 + ld a, BATTLETYPE_ROAMING ld [BattleType], a pop hl scf @@ -35641,7 +34183,7 @@ Function2a355: ; 2a355 .asm_2a36e ld h, d ld l, e - call RNG + call Random and $1f jr z, .asm_2a3cd and $3 @@ -35702,7 +34244,7 @@ Function2a355: ; 2a355 .asm_2a3cd ld hl, $640f .asm_2a3d0 - call RNG + call Random and $f cp $10 jr nc, .asm_2a3d0 @@ -36336,7 +34878,7 @@ Function2c7fb: ; 2c7fb callba PartyMenuSelect push af ld a, [CurPartySpecies] - cp $fd + cp EGG pop bc jr z, .asm_2c854 push bc @@ -36403,7 +34945,7 @@ Function2ed44: ; 2ed44 ld hl, StatusFlags2 bit 6, [hl] ret z - call RNG + call Random ld a, [hRandomAdd] and a ret nz @@ -36413,7 +34955,7 @@ Function2ed44: ; 2ed44 ld a, [PartyCount] ld b, a .asm_2ed70 - call RNG + call Random and $7 cp b jr nc, .asm_2ed70 @@ -36423,7 +34965,7 @@ Function2ed44: ; 2ed44 and $f0 ret nz .asm_2ed82 - call RNG + call Random and a jr z, .asm_2ed82 ld b, a @@ -36443,7 +34985,7 @@ Function2ed44: ; 2ed44 ret .asm_2ed9a - call RNG + call Random cp $55 ret nc ld a, [PartyCount] @@ -36453,7 +34995,7 @@ Function2ed44: ; 2ed44 ld a, b cp $2 jr c, .asm_2edc3 - call RNG + call Random cp $80 jr c, .asm_2edc3 .asm_2edb3 @@ -36506,7 +35048,7 @@ Function2ede6: ; 2ede6 ld hl, StatusFlags2 bit 6, [hl] ret z - call RNG + call Random cp $10 ret nc ld hl, PartyMons @@ -36554,13 +35096,14 @@ Function2ee18: ; 2ee18 ret ; 2ee2f + Function2ee2f: ; 2ee2f xor a ld [$ffde], a call DelayFrame - ld b, $6 + ld b, 6 ld hl, PartyMon1CurHP - ld de, $002f + ld de, PartyMon2 - PartyMon1 - 1 .asm_2ee3d ld a, [hli] or [hl] @@ -36570,16 +35113,14 @@ Function2ee2f: ; 2ee2f jr nz, .asm_2ee3d .asm_2ee45 - ld de, $fffd + ld de, PartyMon1Level - PartyMon1CurHP add hl, de ld a, [hl] ld [BattleMonLevel], a - ld a, $34 + ld a, PREDEF_BATTLE_TRANSITION call Predef - ld a, $f - ld hl, $6d9f - rst FarCall - ld a, $1 + callba Function3ed9f + ld a, 1 ld [hBGMapMode], a call ClearSprites call ClearTileMap @@ -36592,7 +35133,6 @@ Function2ee2f: ; 2ee2f ; 2ee6c - PlayBattleMusic: ; 2ee6c push hl @@ -36966,7 +35506,7 @@ Function38045: ; 38045 jp z, Function38041 cp $10 jr nz, .asm_38061 - call RNG + call Random cp $80 jr c, .asm_38077 jp Function38041 @@ -36974,13 +35514,13 @@ Function38045: ; 38045 .asm_38061 cp $20 jr nz, .asm_3806f - call RNG + call Random cp $c8 jr c, .asm_38077 jp Function38041 .asm_3806f - call RNG + call Random cp $a jp c, Function38041 @@ -36999,7 +35539,7 @@ Function38083: ; 38083 jp z, Function38041 cp $10 jr nz, .asm_3809f - call RNG + call Random cp $14 jr c, .asm_380b5 jp Function38041 @@ -37007,13 +35547,13 @@ Function38083: ; 38083 .asm_3809f cp $20 jr nz, .asm_380ad - call RNG + call Random cp $1e jr c, .asm_380b5 jp Function38041 .asm_380ad - call RNG + call Random cp $c8 jp c, Function38041 @@ -37032,7 +35572,7 @@ Function380c1: ; 380c1 jp z, Function38041 cp $10 jr nz, .asm_380dd - call RNG + call Random cp $32 jr c, .asm_380f3 jp Function38041 @@ -37040,13 +35580,13 @@ Function380c1: ; 380c1 .asm_380dd cp $20 jr nz, .asm_380eb - call RNG + call Random cp $80 jr c, .asm_380f3 jp Function38041 .asm_380eb - call RNG + call Random cp $32 jp c, Function38041 @@ -37822,7 +36362,7 @@ Function3c0e5: ; 3c0e5 ld hl, $5863 .asm_3c115 - call FarBattleTextBox + call StdBattleTextBox .asm_3c118 call Function3ceec @@ -38085,7 +36625,7 @@ Function3c27c: ; 3c27c ld [hl], a call GetItemName ld hl, $4bde - call FarBattleTextBox + call StdBattleTextBox callab BattleCommand8c pop af bit 7, a @@ -38096,7 +36636,7 @@ Function3c27c: ; 3c27c call Function3ee0f call Function3c8e4 ld hl, $4d97 - jp FarBattleTextBox + jp StdBattleTextBox ; 3c300 Function3c300: ; 3c300 @@ -38134,13 +36674,13 @@ Function3c314: ; 3c314 ld a, [$ffcb] cp $2 jr z, .asm_3c341 - call FarBattleRNG + call BattleRandom cp $80 jp c, $43f1 jp Function3c3f3 .asm_3c341 - call FarBattleRNG + call BattleRandom cp $80 jp c, Function3c3f3 jp $43f1 @@ -38172,7 +36712,7 @@ Function3c314: ; 3c314 ld a, b cp $4a jr z, .asm_3c39f - call FarBattleRNG + call BattleRandom cp e jr nc, .asm_3c3c5 jp $43f1 @@ -38181,7 +36721,7 @@ Function3c314: ; 3c314 ld a, b cp $4a jr nz, .asm_3c3c5 - call FarBattleRNG + call BattleRandom cp c jr nc, .asm_3c3c5 jp Function3c3f3 @@ -38190,19 +36730,19 @@ Function3c314: ; 3c314 ld a, [$ffcb] cp $2 jr z, .asm_3c3b5 - call FarBattleRNG + call BattleRandom cp c jp c, Function3c3f3 - call FarBattleRNG + call BattleRandom cp e jp c, $43f1 jr .asm_3c3c5 .asm_3c3b5 - call FarBattleRNG + call BattleRandom cp e jp c, $43f1 - call FarBattleRNG + call BattleRandom cp c jp c, Function3c3f3 jr .asm_3c3c5 @@ -38220,13 +36760,13 @@ Function3c314: ; 3c314 ld a, [$ffcb] cp $2 jr z, .asm_3c3e9 - call FarBattleRNG + call BattleRandom cp $80 jp c, $43f1 jp Function3c3f3 .asm_3c3e9 - call FarBattleRNG + call BattleRandom cp $80 jp c, Function3c3f3 scf @@ -38406,7 +36946,7 @@ Function3c4df: ; 3c4df res 4, [hl] call SetEnemyTurn ld hl, $4c8a - jp FarBattleTextBox + jp StdBattleTextBox .asm_3c518 ld hl, EnemySubStatus5 @@ -38430,7 +36970,7 @@ Function3c4df: ; 3c4df res 4, [hl] call SetPlayerTurn ld hl, $4c8a - jp FarBattleTextBox + jp StdBattleTextBox ; 3c543 @@ -38457,7 +36997,7 @@ Function3c543: ; 3c543 call IsInArray jr c, .Flee - call FarBattleRNG + call BattleRandom ld b, a cp $80 jr nc, .Stay @@ -38739,7 +37279,7 @@ Function3c716: ; 3c716 .asm_3c733 push de - call FarBattleTextBox + call StdBattleTextBox pop de xor a ld [$cfca], a @@ -38793,7 +37333,7 @@ Function3c716: ; 3c716 ld [hBGMapMode], a call Function3ccef ld hl, $480e - call FarBattleTextBox + call StdBattleTextBox .asm_3c7a1 call Function3c706 @@ -38809,7 +37349,7 @@ Function3c716: ; 3c716 call GetQuarterMaxHP call Function3cc3f ld hl, $4822 - call FarBattleTextBox + call StdBattleTextBox .asm_3c7c5 call Function3c706 @@ -38825,7 +37365,7 @@ Function3c716: ; 3c716 call GetQuarterMaxHP call Function3cc3f ld hl, $4836 - call FarBattleTextBox + call StdBattleTextBox .asm_3c7e9 ld hl, BattleMonHP @@ -38876,7 +37416,7 @@ Function3c801: ; 3c801 ld [$d265], a push af ld hl, $4864 - call FarBattleTextBox + call StdBattleTextBox pop af ret nz ld a, $0 @@ -38971,7 +37511,7 @@ Function3c874: ; 3c874 ld hl, $4df5 .asm_3c8e1 - jp FarBattleTextBox + jp StdBattleTextBox ; 3c8e4 Function3c8e4: ; 3c8e4 @@ -39024,7 +37564,7 @@ Function3c8eb: ; 3c8eb call Function3c8e4 call Function3ccef ld hl, $4880 - jp FarBattleTextBox + jp StdBattleTextBox ; 3c93c Function3c93c: ; 3c93c @@ -39163,7 +37703,7 @@ Function3c93c: ; 3c93c call Function3ddc8 call Function3c8e4 ld hl, $4899 - jp FarBattleTextBox + jp StdBattleTextBox ; 3ca26 Function3ca26: ; 3ca26 @@ -39194,7 +37734,7 @@ Function3ca26: ; 3ca26 cp $1 ret nz ld hl, $48b6 - call FarBattleTextBox + call StdBattleTextBox ld a, $10 call GetBattleVarPair push af @@ -39233,7 +37773,7 @@ Function3ca8f: ; 3ca8f ld a, [$c73f] and a ret nz - call FarBattleRNG + call BattleRandom cp $19 ret nc xor a @@ -39245,7 +37785,7 @@ Function3ca8f: ; 3ca8f call UpdateBattleHuds call SetEnemyTurn ld hl, $524b - jp FarBattleTextBox + jp StdBattleTextBox .asm_3cac9 ld a, [EnemyMonStatus] @@ -39254,7 +37794,7 @@ Function3ca8f: ; 3ca8f ld a, [$c740] and a ret nz - call FarBattleRNG + call BattleRandom cp $19 ret nc xor a @@ -39271,7 +37811,7 @@ Function3ca8f: ; 3ca8f call UpdateBattleHuds call SetPlayerTurn ld hl, $524b - jp FarBattleTextBox + jp StdBattleTextBox ; 3cafb Function3cafb: ; 3cafb @@ -39308,7 +37848,7 @@ Function3cafb: ; 3cafb .asm_3cb2e ld [hBattleTurn], a ld hl, $48d2 - jp FarBattleTextBox + jp StdBattleTextBox ; 3cb36 @@ -39365,7 +37905,7 @@ FadeLightScreen: ; 3cb80 push hl push de ld hl, BattleText_0x808e7 - call FarBattleTextBox + call StdBattleTextBox pop de pop hl ret @@ -39379,7 +37919,7 @@ FadeReflect: ; 3cb91 ret nz res SCREENS_REFLECT, [hl] ld hl, BattleText_0x80905 - jp FarBattleTextBox + jp StdBattleTextBox ; 3cb9e HandleWeather: ; 3cb9e @@ -39452,7 +37992,7 @@ HandleWeather: ; 3cb9e call Function3cc3f ld hl, BattleText_0x8084d - jp FarBattleTextBox + jp StdBattleTextBox .asm_3cc13 ld hl, .WeatherEndedMessages @@ -39471,7 +38011,7 @@ HandleWeather: ; 3cb9e ld a, [hli] ld h, [hl] ld l, a - jp FarBattleTextBox + jp StdBattleTextBox ; 3cc2d .WeatherMessages @@ -39982,7 +38522,7 @@ Function3cef1: ; 3cef1 ld bc, $050b call ClearBox ld hl, BattleText_0x80a75 - jp FarBattleTextBox + jp StdBattleTextBox ; 3cf14 Function3cf14: ; 3cf14 @@ -39996,7 +38536,7 @@ Function3cf14: ; 3cf14 ld bc, $040a call ClearBox ld hl, BattleText_0x809a8 - jp FarBattleTextBox + jp StdBattleTextBox ; 3cf35 Function3cf35: ; 3cf35 @@ -40081,7 +38621,7 @@ Function3cfa4: ; 3cfa4 call z, Function3d0ea callab Function39939 ld hl, BattleText_0x809da - call FarBattleTextBox + call StdBattleTextBox call Function3d2f1 jr z, .asm_3cff5 ld a, [InLinkBattle] @@ -40190,11 +38730,11 @@ Function3d02b: ; 3d02b ld a, [hli] ld h, [hl] ld l, a - jp FarBattleTextBox + jp StdBattleTextBox .asm_3d07b ld hl, BattleText_0x809be - jp FarBattleTextBox + jp StdBattleTextBox ; 3d081 Function3d081: ; 3d081 @@ -40474,10 +39014,10 @@ Function3d1f8: ; 3d1f8 dec a ret nz ld hl, BattleText_0x80a83 - call FarBattleTextBox + call StdBattleTextBox .asm_3d20a ld bc, $0107 - call $1dd2 + call Function1dd2 ld a, [$cfa9] jr c, .asm_3d217 and a @@ -40649,7 +39189,7 @@ Function3d34f: ; 3d34f cp [hl] jr nz, .asm_3d360 ld hl, BattleText_0x80c0d - call FarBattleTextBox + call StdBattleTextBox scf ret @@ -40737,7 +39277,7 @@ LostBattle: ; 3d38e ld a, $47 ld hl, $4000 rst FarCall - call $0a80 + call Functiona80 call ClearTileMap call WhiteBGMap ret @@ -40770,7 +39310,7 @@ LostBattle: ; 3d38e jr z, .asm_3d417 .asm_3d412 - call FarBattleTextBox + call StdBattleTextBox .end scf @@ -41192,7 +39732,7 @@ Function3d672: ; 3d672 .asm_3d6a7 ld a, [OTPartyCount] ld b, a - call FarBattleRNG + call BattleRandom and $7 cp b jr nc, .asm_3d6a7 @@ -41288,9 +39828,9 @@ Function3d74b: ; 3d74b push af callab Function39939 ld hl, BattleText_0x80aca - call FarBattleTextBox + call StdBattleTextBox ld bc, $0107 - call $1dd2 + call Function1dd2 ld a, [$cfa9] dec a jr nz, .asm_3d79a @@ -41339,7 +39879,7 @@ Function3d7a0: ; 3d7a0 Function3d7b8: ; 3d7b8 callab Function39939 ld hl, BattleText_0x80af8 - call FarBattleTextBox + call StdBattleTextBox jp WaitBGMap ; 3d7c7 @@ -41461,16 +40001,16 @@ Function3d887: ; 3d887 ld hl, PartySpecies ld a, [CurPartyMon] ld c, a - ld b, $0 + ld b, 0 add hl, bc ld a, [hl] - cp $fd + cp EGG ld hl, BattleText_0x80b26 jr z, .asm_3d8ae ld hl, BattleText_0x80b0b .asm_3d8ae - call FarBattleTextBox + call StdBattleTextBox .asm_3d8b1 xor a @@ -41524,7 +40064,7 @@ Function3d8b3: ; 3d8b3 call SetPlayerTurn call GetItemName ld hl, BattleText_0x80b89 - call FarBattleTextBox + call StdBattleTextBox jp .asm_3d9a2 .asm_3d916 @@ -41583,7 +40123,7 @@ Function3d8b3: ; 3d8b3 jr .asm_3d96c .asm_3d97a - call FarBattleRNG + call BattleRandom ld b, a ld a, [$ffb6] cp b @@ -41601,7 +40141,7 @@ Function3d8b3: ; 3d8b3 ld hl, BattleText_0x80b49 .asm_3d995 - call FarBattleTextBox + call StdBattleTextBox ld a, $1 ld [$d266], a call Function309d @@ -41644,7 +40184,7 @@ Function3d8b3: ; 3d8b3 pop de call WaitSFX ld hl, BattleText_0x80b77 - call FarBattleTextBox + call StdBattleTextBox call WaitSFX call Function309d scf @@ -41656,7 +40196,7 @@ Function3d8b3: ; 3d8b3 bit 4, [hl] jr nz, .asm_3da05 ld hl, BattleText_0x81863 - call FarBattleTextBox + call StdBattleTextBox .asm_3da05 call WaitSFX @@ -41949,7 +40489,7 @@ Function3dc23: ; 3dc23 ret z push bc ld hl, BattleText_0x80bae - call FarBattleTextBox + call StdBattleTextBox call GetEighthMaxHP call Function3cc39 pop hl @@ -41992,7 +40532,7 @@ Function3dc5b: ; 3dc5b and a jr z, .asm_3dcc0 ld a, [$c71a] - call $399f + call Function399f ld hl, BattleMonHP ld a, [hli] or [hl] @@ -42026,7 +40566,7 @@ Function3dc5b: ; 3dc5b ld hl, BattleText_0x809a8 .asm_3dcdf - call FarBattleTextBox + call StdBattleTextBox scf ret @@ -42162,7 +40702,7 @@ Function3dd2f: ; 3dd2f ld a, $9 rst FarCall ld hl, RecoveredUsingText - jp FarBattleTextBox + jp StdBattleTextBox ; 3ddc8 @@ -42273,7 +40813,7 @@ Function3de51: ; 3de51 call GetItemName call Function3ddc8 ld hl, BattleText_0x80dab - call FarBattleTextBox + call StdBattleTextBox ld a, [hBattleTurn] and a jr nz, .asm_3de90 @@ -42353,7 +40893,7 @@ Function3deb1: ; 3deb1 ld [de], a call GetItemName ld hl, BattleText_0x80bde - call FarBattleTextBox + call StdBattleTextBox callab BattleCommand8c ret @@ -42743,10 +41283,7 @@ Function3e139: ; 3e139 ld a, [InputType] or a jr z, .asm_3e171 - ld a, $77 - ld hl, $6294 - rst FarCall - + callba Function1de294 .asm_3e171 call Function3e19b ret c @@ -42792,7 +41329,7 @@ Function3e19b: ; 3e19b bit 4, [hl] jr nz, .asm_3e1c5 ld hl, $5863 - call FarBattleTextBox + call StdBattleTextBox ld c, $3c call DelayFrames @@ -42855,7 +41392,7 @@ Function3e1c7: ; 3e1c7 Function3e22b: ; 3e22b ld hl, BattleText_0x80bf3 - call FarBattleTextBox + call StdBattleTextBox jp Function3e139 ; 3e234 @@ -43010,7 +41547,7 @@ Function3e358: ; 3e358 cp d jr nz, .asm_3e36b ld hl, BattleText_0x80c0d - call FarBattleTextBox + call StdBattleTextBox jp $6299 .asm_3e36b @@ -43023,7 +41560,7 @@ Function3e358: ; 3e358 .asm_3e378 ld hl, BattleText_0x80c22 - call FarBattleTextBox + call StdBattleTextBox jp $6299 .asm_3e381 @@ -43383,7 +41920,7 @@ Function3e4bc: ; 3e4bc ld hl, Function3cc39 .asm_3e613 - call FarBattleTextBox + call StdBattleTextBox call Function30b4 jp Function3e4bc ; 3e61c @@ -43632,7 +42169,7 @@ Function3e786: ; 3e786 .asm_3e7b4 ld hl, BattleText_0x80c72 - call FarBattleTextBox + call StdBattleTextBox ld c, $3c call DelayFrames xor a @@ -43722,7 +42259,7 @@ Function3e7c1: ; 3e7c1 jr nz, .asm_3e882 .asm_3e855 ld hl, EnemyMonMove1 - call FarBattleRNG + call BattleRandom and $3 ld c, a ld b, $0 @@ -43824,7 +42361,7 @@ LoadEnemyMon: ; 3e8eb ; To do this we pull the species from TempEnemyMonSpecies ; Notes: -; FarBattleRNG is used to ensure sync between Game Boys +; BattleRandom is used to ensure sync between Game Boys ; Clear the whole EnemyMon struct xor a @@ -43883,13 +42420,13 @@ LoadEnemyMon: ; 3e8eb ; 2% Item2 ; 25% chance of getting an item - call FarBattleRNG + call BattleRandom cp a, $c0 ld a, NO_ITEM jr c, .UpdateItem ; From there, an 8% chance for Item2 - call FarBattleRNG + call BattleRandom cp a, $14 ; 8% of 25% = 2% Item2 ld a, [BaseItems] jr nc, .UpdateItem @@ -43969,10 +42506,10 @@ LoadEnemyMon: ; 3e8eb ; (HP is initialized at the end of the battle) call GetRoamMonDVs inc hl - call FarBattleRNG + call BattleRandom ld [hld], a ld c, a - call FarBattleRNG + call BattleRandom ld [hl], a ld b, a ; We're done with DVs @@ -43993,9 +42530,9 @@ LoadEnemyMon: ; 3e8eb .GenerateDVs ; Generate new random DVs - call FarBattleRNG + call BattleRandom ld b, a - call FarBattleRNG + call BattleRandom ld c, a .UpdateDVs @@ -44048,7 +42585,7 @@ LoadEnemyMon: ; 3e8eb jr nz, .CheckMagikarpArea ; 5% chance of skipping size checks - call RNG + call Random cp a, $0c ; / $100 jr c, .CheckMagikarpArea ; Try again if > 1614 @@ -44057,7 +42594,7 @@ LoadEnemyMon: ; 3e8eb jr nc, .GenerateDVs ; 20% chance of skipping this check - call RNG + call Random cp a, $32 ; / $100 jr c, .CheckMagikarpArea ; Try again if > 1598 @@ -44082,7 +42619,7 @@ LoadEnemyMon: ; 3e8eb cp a, MAP_LAKE_OF_RAGE jr z, .Happiness ; 40% chance of not flooring - call RNG + call Random cp a, $64 ; / $100 jr c, .Happiness ; Floor at length 1024 @@ -44853,14 +43390,14 @@ EmptyBattleTextBox: ; 3edd1 ; 3edd8 -BattleRNG: ; 3edd8 +_BattleRandom: ; 3edd8 ; If the normal RNG is used in a link battle it'll desync. ; To circumvent this a shared PRNG is used instead. ; But if we're in a non-link battle we're safe to use it ld a, [InLinkBattle] and a - jp z, RNG + jp z, Random ; The PRNG operates in streams of 10 values. @@ -45275,7 +43812,7 @@ Function3ee3b: ; 3ee3b call StartSFX call WaitSFX ld hl, BattleText_0x80c9c - call FarBattleTextBox + call StdBattleTextBox call Function309d .asm_3f057 @@ -45528,7 +44065,7 @@ Function3f136: ; 3f136 rst FarCall call WaitSFX ld hl, BattleText_0x80c9c - call FarBattleTextBox + call StdBattleTextBox pop de inc e ld b, $0 @@ -45817,7 +44354,7 @@ Function3f360: ; 3f360 push hl call Function30b4 pop hl - jp FarBattleTextBox + jp StdBattleTextBox ; 3f390 @@ -46026,7 +44563,7 @@ Function3f47c: ; 3f47c ; 3f4c1 -Function3f4c1: ; 3f4c1 +StartBattle: ; 3f4c1 ld a, [PartyCount] and a ret z @@ -46070,17 +44607,17 @@ Function3f4dd: ; 3f4dd ld hl, rLCDC res 6, [hl] call Function3fb6c - call $7c8b + call BattleStartMessage ld hl, rLCDC set 6, [hl] xor a ld [hBGMapMode], a call EmptyBattleTextBox - ld hl, $c535 - ld bc, $050b + hlcoord 9, 7 + ld bc, 5 << 8 + 11 call ClearBox - ld hl, $c4a1 - ld bc, $040a + hlcoord 1, 0 + ld bc, 4 << 8 + 10 call ClearBox call ClearSprites ld a, [IsInBattle] @@ -46376,7 +44913,7 @@ Function3f71d: ; 3f71d ld de, $d850 call Function3d0be ld hl, BattleText_0x80730 - call FarBattleTextBox + call StdBattleTextBox ld a, [$cfc0] bit 0, a ret z @@ -46672,7 +45209,7 @@ Function3f998: ; 3f998 ret .asm_3f9c4 - call FarBattleRNG + call BattleRandom and $f ret nz @@ -47135,7 +45672,7 @@ Function3fc5b: ; 3fc5b ; 3fc8b -BattleStartMessage ; 3fc8b +BattleStartMessage: ; 3fc8b ld a, [IsInBattle] dec a jr z, .asm_3fcaa @@ -47216,7 +45753,7 @@ BattleStartMessage ; 3fc8b ld hl, $4000 rst FarCall pop hl - call FarBattleTextBox + call StdBattleTextBox call Function3f830 ret nz @@ -47603,7 +46140,7 @@ Function414b7: ; 414b7 ; 414fb Function414fb: ; 414fb - call $0e51 + call Functione51 ld hl, VTiles1 ld bc, $0800 .asm_41504 @@ -48249,7 +46786,7 @@ GetPreEvolution: ; 42581 .asm_425a2 inc c ld a, c - cp CELEBI + cp NUM_POKEMON jr c, .asm_42583 and a ret @@ -48359,7 +46896,7 @@ GetFruitTreeFlag: ; 44078 ld e, a ld d, 0 ld hl, FruitTreeFlags - call BitTableFunc + call FlagAction pop de pop hl ret @@ -48554,7 +47091,7 @@ AIChooseMove: ; 440ce ld h, [hl] ld l, a ld a, BANK(AIScoring) - call FarJpHl + call FarCall_hl jr .CheckLayer @@ -48611,7 +47148,7 @@ AIChooseMove: ; 440ce .asm_44197 ld hl, Buffer1 - call RNG + call Random and 3 ld c, a ld b, 0 @@ -49097,32 +47634,20 @@ Function4484a: ; 0x4484a ld [PartyMenuActionText], a call WhiteBGMap .asm_448dc - ld a, $14 - ld hl, $404f - rst $8 - ld a, $14 - ld hl, $4405 - rst $8 - ld a, $14 - ld hl, $43e0 - rst $8 - ld a, $14 - ld hl, PickedFruitTree - rst $8 - ld a, $14 - ld hl, $449a - rst $8 + callba Function5004f + callba Function50405 + callba Function503e0 + callba WritePartyMenuTilemap + callba PrintPartyMenuText call WaitBGMap call Function32f9 call DelayFrame - ld a, $14 - ld hl, $4457 - rst $8 + callba PartyMenuSelect jr c, .asm_44939 ld a, [CurPartySpecies] - cp $fd + cp EGG jr z, .asm_44923 - ld a, $1 + ld a, PartyMon1Item - PartyMon1 call GetPartyParamLocation ld a, [hl] and a @@ -49606,7 +48131,7 @@ Function49e09: ; 49e09 Function49e27: ; 49e27 - call $06e3 + call Function6e3 and $80 jr nz, .asm_49e39 ld hl, $c5b8 @@ -49625,7 +48150,7 @@ Function49e3d: ; 49e3d ld a, [$cfcd] and a ret z - call $06e3 + call Function6e3 and $80 jp nz, Function49e75 call UpdateTime @@ -49700,7 +48225,7 @@ Function49ed0: ; 49ed0 ld [$ffde], a call ClearTileMap call Functione5f - call $0e51 + call Functione51 call Function1fbf ret ; 49ee0 @@ -51453,7 +49978,7 @@ StatsScreenInit: ; 4dc8a ld hl, $753e rst FarCall ; this loads graphics pop hl - call JpHl + call _hl_ call WhiteBGMap call ClearTileMap pop bc @@ -51980,8 +50505,8 @@ Function4e881: ; 4e881 call ClearTileMap call ClearSprites call DisableLCD - call $0e51 - call $0e58 + call Functione51 + call Functione58 ld hl, VBGMap0 ld bc, VBlank5 ld a, $7f @@ -52009,8 +50534,8 @@ Function4e8c2: ; 4e8c2 call ClearTileMap call ClearSprites call DisableLCD - call $0e51 - call $0e58 + call Functione51 + call Functione58 ld hl, VBGMap0 ld bc, VBlank5 ld a, $7f @@ -52421,7 +50946,7 @@ Function5003f: ; 5003f ; 5004f Function5004f: ; 5004f - call $0e58 + call Functione58 ld hl, $4ad1 ld a, $2 rst FarCall @@ -52897,14 +51422,14 @@ INCBIN "baserom.gbc", $5036b, $50389 - $5036b Function50389: ; 50389 - ld a, $d8 + ld a, PartySpecies & $ff add b ld e, a - ld a, $dc - adc $0 + ld a, PartySpecies >> 8 + adc 0 ld d, a ld a, [de] - cp $fd + cp EGG ret ; 50396 @@ -52915,7 +51440,7 @@ Function50396: ; 50396 ld a, [PartyMenuActionText] and $f ld e, a - ld d, $0 + ld d, 0 ld hl, $43b2 add hl, de add hl, de @@ -53168,7 +51693,7 @@ Function505da: ; 505da .asm_50622 ld a, $14 ld hl, UnknownScript_0x50669 - call PushScriptPointer + call CallScript scf ret @@ -53285,7 +51810,7 @@ Function506bc: ; 506bc UnknownScript_0x506c8: ; 0x506c8 reloadmappart special $0035 - 3callasm $03, $4706 + 3callasm BANK(GetPartyNick), GetPartyNick 2writetext UnknownText_0x50726 closetext 3callasm BANK(Function506ef), Function506ef @@ -53665,9 +52190,9 @@ Function508d5: ; 508d5 jr .asm_50905 .asm_508f1 - ld a, $1 + ld a, 1 ; BANK(BoxSpecies) call GetSRAMBank - ld hl, $ad11 + ld hl, BoxSpecies call .asm_50905 call CloseSRAM ret @@ -53961,13 +52486,13 @@ GetGender: ; 50bdd jr z, .PartyMon ; 2: BoxMon - ld hl, $ad26 + $15 ; BoxMon1DVs - ld bc, $20 ; BoxMon2 - BoxMon1 + ld hl, BoxMon1DVs + ld bc, BoxMon2 - BoxMon1 dec a jr z, .BoxMon ; 3: Unknown - ld hl, TempMonDVs ; DVBuffer + ld hl, TempMonDVs dec a jr z, .DVs @@ -55495,8 +54020,8 @@ Function80422: ; 80422 -GetFlag2: ; 80430 -; Do action b on flag de from BitTable2 +EngineFlagAction: ; 80430 +; Do action b on engine flag de ; ; b = 0: reset flag ; = 1: set flag @@ -55514,8 +54039,8 @@ GetFlag2: ; 80430 jr c, .read ; cp 0 can't set carry! jr .invalid -; There are only $a2 flags in BitTable2, so anything beyond that -; is invalid too. +; There are only $a2 engine flags, so +; anything beyond that is invalid too. .ceiling ld a, e @@ -55529,10 +54054,10 @@ GetFlag2: ; 80430 ld e, a ld d, a -; Read BitTable2 for this flag's location. +; Get this flag's location. .read - ld hl, BitTable2 + ld hl, EngineFlags ; location add hl, de add hl, de @@ -55580,13 +54105,14 @@ GetFlag2: ; 80430 ; 80462 -BitTable2: ; 80462 -INCLUDE "engine/bittable2.asm" +EngineFlags: ; 80462 +INCLUDE "engine/engine_flags.asm" ; 80648 INCBIN "baserom.gbc", $80648, $80730-$80648 +BattleText: INCLUDE "text/battle.asm" INCBIN "baserom.gbc", $818ac, $81fe3-$818ac @@ -56256,7 +54782,7 @@ Function864c3: ; 864c3 call Function86810 ld a, $4 ld [MusicFade], a - call $04b6 + call Function4b6 ld c, $8 call DelayFrames ret @@ -56291,12 +54817,12 @@ Function8653f: ; 8653f ld [de], a inc de ld hl, PartySpecies - ld c, $0 + ld c, 0 .asm_86556 ld a, [hli] cp $ff jr z, .asm_865b1 - cp $fd + cp EGG jr nz, .asm_86562 inc c jr .asm_86556 @@ -56411,7 +54937,7 @@ Function865b5: ; 865b5 ld a, $7f call ByteFill ld hl, $c50a - call $378b + call Function378b call WaitBGMap xor a ld [hBGMapMode], a @@ -56512,9 +55038,9 @@ Function86748: ; 86748 xor a ld [$c2c6], a ld hl, $c50a - call $378b + call Function378b ld a, [CurPartySpecies] - cp $fd + cp EGG jr z, .asm_867f8 ld hl, $c5a5 ld a, $74 @@ -56574,7 +55100,7 @@ Function86810: ; 86810 callba GetPlayerBackpic ld a, $31 ld [$ffad], a - ld hl, $c51e + hlcoord 6, 6 ld bc, $0606 ld a, $13 call Predef @@ -56601,7 +55127,7 @@ Function86810: ; 86810 rst FarCall xor a ld [$ffad], a - ld hl, $c510 + hlcoord 12, 5 ld bc, $0707 ld a, $13 call Predef @@ -56614,29 +55140,29 @@ Function86810: ; 86810 call Function86643 xor a ld [hBGMapMode], a - ld hl, $c4c8 + hlcoord 0, 2 ld bc, $0809 call TextBox - ld hl, $c590 + hlcoord 0, 12 ld bc, $0412 call TextBox - ld hl, $c4f2 + hlcoord 2, 4 ld de, PlayerName call PlaceString - ld hl, $c519 + hlcoord 1, 6 ld a, $73 ld [hli], a ld a, $74 ld [hli], a ld [hl], $f3 - ld hl, $c51c + hlcoord 4, 6 ld de, PlayerID ld bc, $8205 call PrintNum - ld hl, $c541 - ld de, $68ed + hlcoord 1, 8 + ld de, .PlayTime call PlaceString - ld hl, $c557 + hlcoord 3, 9 ld de, GameTimeHours ld bc, $0203 call PrintNum @@ -56650,7 +55176,10 @@ Function86810: ; 86810 ret ; 868ed -INCBIN "baserom.gbc", $868ed, $88000 - $868ed +.PlayTime + db "PLAY TIME@" +; 868f7 + SECTION "bank22",ROMX,BANK[$22] @@ -56900,8 +55429,9 @@ ClearScreenArea: ; 0x896ff ; hl = address of upper left corner of the area ; b = height ; c = width - ld a, $7f ; blank tile - ld de, 20 ; screen width + + ld a, " " ; blank tile + ld de, 20 ; screen width .loop push bc push hl @@ -56914,6 +55444,7 @@ ClearScreenArea: ; 0x896ff add hl, de dec b jr nz, .loop + dec hl inc c inc c @@ -56938,40 +55469,105 @@ SpecialHoOhChamber: ; 0x8addb jr nz, .done ; if not, we're done call GetSecondaryMapHeaderPointer ld de, $0326 - ld b, $1 - call BitTable1Func + ld b, SET_FLAG + call EventFlagAction .done ret ; 0x8adef -INCBIN "baserom.gbc", $8adef, $8ae30 - $8adef +Function8adef: ; 8adef + call GetSecondaryMapHeaderPointer + ld de, $0328 + ld b, CHECK_FLAG + call EventFlagAction + ld a, c + and a + jr nz, .asm_8ae2f + + ld a, WATER_STONE + ld [CurItem], a + ld hl, NumItems + call PickUpItem + jr c, .asm_8ae24 + + ld a, [PartyCount] + ld b, a + inc b +.asm_8ae10 + dec b + jr z, .asm_8ae2f + ld a, b + dec a + ld [CurPartyMon], a + push bc + ld a, $1 + call GetPartyParamLocation + pop bc + ld a, [hl] + cp $18 + jr nz, .asm_8ae10 + +.asm_8ae24 + call GetSecondaryMapHeaderPointer + ld de, $0328 + ld b, SET_FLAG + call EventFlagAction + +.asm_8ae2f + ret +; 8ae30 Function8ae30: ; 8ae30 push de push bc + call GetSecondaryMapHeaderPointer ld a, h - cp $58 + cp RuinsofAlphAerodactylChamber_SecondMapHeader >> 8 jr nz, .asm_8ae4a ld a, l - cp $e8 + cp RuinsofAlphAerodactylChamber_SecondMapHeader & $ff jr nz, .asm_8ae4a + ld de, $0329 - ld b, $1 - call BitTable1Func + ld b, SET_FLAG + call EventFlagAction + scf - jr .asm_8ae4b + jr .done .asm_8ae4a and a -.asm_8ae4b +.done pop bc pop de ret ; 8ae4e -INCBIN "baserom.gbc", $8ae4e, $8b170 - $8ae4e +Function8ae4e: ; 8ae4e + push hl + push de + + call GetSecondaryMapHeaderPointer + ld a, h + cp RuinsofAlphKabutoChamber_SecondMapHeader >> 8 + jr nz, .done + ld a, l + cp RuinsofAlphKabutoChamber_SecondMapHeader & $ff + jr nz, .done + + ld de, $0327 + ld b, SET_FLAG + call EventFlagAction + +.done + pop de + pop hl + ret +; 8ae68 + +INCBIN "baserom.gbc", $8ae68, $8b170 - $8ae68 SpecialDratini: ; 0x8b170 ; if ScriptVar is 0 or 1, change the moveset of the last Dratini in the party. @@ -57579,13 +56175,195 @@ GetTimePalFade: ; 8c17c db %00000000 ; 8c20f -INCBIN "baserom.gbc", $8c20f, $8c940 - $8c20f + +Function8c20f: ; 8c20f + call Function8c26d + ld a, [rBGP] + ld [$cfc7], a + ld a, [rOBP0] + ld [$cfc8], a + ld a, [rOBP1] + ld [$cfc9], a + call DelayFrame + ld hl, $ff9e + ld a, [hl] + push af + ld [hl], $1 +.asm_8c22b + ld a, [$cf63] + bit 7, a + jr nz, .asm_8c23a + call Function8c314 + call DelayFrame + jr .asm_8c22b + +.asm_8c23a + ld a, [rSVBK] + push af + ld a, $5 + ld [rSVBK], a + ld hl, Unkn1Pals + ld bc, $0040 + xor a + call ByteFill + pop af + ld [rSVBK], a + ld a, $ff + ld [$cfc7], a + call DmgToCgbBGPals + call DelayFrame + xor a + ld [hLCDStatCustom], a + ld [$ffc7], a + ld [$ffc8], a + ld [hSCY], a + ld a, $1 + ld [rSVBK], a + pop af + ld [$ff9e], a + call DelayFrame + ret +; 8c26d + +Function8c26d: ; 8c26d + ld a, [InLinkBattle] + cp $4 + jr z, .asm_8c288 + callba Function6454 + call Function1ad2 + call DelayFrame + call Function8c2a0 + call Function8cf4f + jr .asm_8c28b + +.asm_8c288 + call Function8c2aa + +.asm_8c28b + ld a, $90 + ld [hWY], a + call DelayFrame + xor a + ld [hBGMapMode], a + ld hl, $cf63 + xor a + ld [hli], a + ld [hli], a + ld [hl], a + call Function8c6d8 + ret +; 8c2a0 + +Function8c2a0: ; 8c2a0 + call Function8c2aa + ld hl, VBGMap0 + call Function8c2cf + ret +; 8c2aa + +Function8c2aa: ; 8c2aa + ld de, $42f4 + ld hl, $8fe0 + ld b, $23 + ld c, $2 + call Request2bpp + ld a, [rVBK] + push af + ld a, $1 + ld [rVBK], a + ld de, $42f4 + ld hl, $8fe0 + ld b, $23 + ld c, $2 + call Request2bpp + pop af + ld [rVBK], a + ret +; 8c2cf + +Function8c2cf: ; 8c2cf + ld a, [rSVBK] + push af + ld a, $6 + ld [rSVBK], a + push hl + ld hl, Unkn1Pals + ld bc, $0280 +.asm_8c2dd + ld [hl], $ff + inc hl + dec bc + ld a, c + or b + jr nz, .asm_8c2dd + pop hl + ld de, Unkn1Pals + ld b, $23 + ld c, $28 + call Request2bpp + pop af + ld [rSVBK], a + ret +; 8c2f4 + +INCBIN "baserom.gbc", $8c2f4, $8c314 - $8c2f4 + +Function8c314: ; 8c314 + ld a, [$cf63] + ld e, a + ld d, $0 + ld hl, $4323 + add hl, de + add hl, de + ld a, [hli] + ld h, [hl] + ld l, a + jp [hl] +; 8c323 + +INCBIN "baserom.gbc", $8c323, $8c6d8 - $8c323 + +Function8c6d8: ; 8c6d8 + ld a, [rSVBK] + push af + ld a, $5 + ld [rSVBK], a + ld hl, $d100 + call Function8c6ef + ld hl, $d200 + call Function8c6ef + pop af + ld [rSVBK], a + ret +; 8c6ef + +Function8c6ef: ; 8c6ef + xor a + ld c, $90 +.asm_8c6f2 + ld [hli], a + dec c + jr nz, .asm_8c6f2 + ret +; 8c6f7 + +INCBIN "baserom.gbc", $8c6f7, $8c7d4 - $8c6f7 + +Function8c7d4: ; 8c7d4 + call WaitSFX + ld de, $0053 + call StartSFX + call WaitSFX + ret +; 8c7e1 + +INCBIN "baserom.gbc", $8c7e1, $8c940 - $8c7e1 Function8c940: ; 8c940 ld a, e and $1 ld [$cf63], a - call $496d + call Function8c96d call WaitSFX ld de, $001e call StartSFX @@ -57595,10 +56373,10 @@ Function8c940: ; 8c940 jr nz, .asm_8c96c ld a, $90 ld [$c3b5], a - ld hl, $4f7a + ld hl, Function8cf7a ld a, $23 rst FarCall - call $4a0c + call Function8ca0c call DelayFrame jr .asm_8c952 @@ -57607,7 +56385,7 @@ Function8c940: ; 8c940 ; 8c96d Function8c96d: ; 8c96d - ld hl, $4f53 + ld hl, Function8cf53 ld a, $23 rst FarCall ld de, $49cc @@ -57636,7 +56414,12 @@ Function8ca0c: ; 8ca0c jp [hl] ; 8ca1b -INCBIN "baserom.gbc", $8ca1b, $8cf53 - $8ca1b +INCBIN "baserom.gbc", $8ca1b, $8cf4f - $8ca1b + +Function8cf4f: ; 8cf4f + call Function3238 + ret +; 8cf53 Function8cf53: ; 8cf53 @@ -57807,9 +56590,9 @@ INCBIN "baserom.gbc", $8d03d, $8d04c - $8d03d Function8d04c: ; 8d04c call Function8d0ec call Function8d132 - cp $fd + cp EGG jr z, .asm_8d0b9 - cp $fc + cp NUM_POKEMON + 1 jr z, .asm_8d0b6 call Function8d1a2 ld a, [$c3ba] @@ -60069,7 +58852,7 @@ CheckTileEvent: ; 96874 ld h, [hl] ld l, a call GetMapEventBank - call PushScriptPointer + call CallScript ret ; 968c7 @@ -60135,7 +58918,7 @@ Function968ec: ; 968ec call GetMapEventBank call GetFarHalfword call GetMapEventBank - call PushScriptPointer + call CallScript ld hl, ScriptFlags res 3, [hl] @@ -60152,7 +58935,7 @@ Function968ec: ; 968ec ld h, [hl] ld l, a ld a, [$d44e] - call PushScriptPointer + call CallScript scf ret @@ -60194,7 +58977,7 @@ Function9693a: ; 9693a .asm_96966 ld a, $4 ld hl, $75f8 - call PushScriptPointer + call CallScript scf ret ; 96970 @@ -60318,7 +59101,7 @@ TryObjectEvent: ; 969b5 ld h, [hl] ld l, a call GetMapEventBank - call PushScriptPointer + call CallScript ; ld a, -1 ret ; 96a12 @@ -60333,14 +59116,14 @@ TryObjectEvent: ; 969b5 ld de, EngineBuffer1 ld bc, 2 call FarCopyBytes - ld a, $3 + ld a, 3 scf ret ; 96a29 .two ; 96a29 - call $3674 - ld a, $2 + call Function3674 + ld a, 2 scf ret ; 96a30 @@ -60416,7 +59199,7 @@ TryReadSign: ; 96a38 ld h, [hl] ld l, a call GetMapEventBank - call PushScriptPointer + call CallScript scf ret @@ -60430,7 +59213,7 @@ TryReadSign: ; 96a38 call FarCopyBytes ld a, $4 ld hl, $7625 - call PushScriptPointer + call CallScript scf ret @@ -60461,7 +59244,7 @@ TryReadSign: ; 96a38 call GetMapEventBank call GetFarHalfword call GetMapEventBank - call PushScriptPointer + call CallScript scf ret @@ -60482,7 +59265,7 @@ CheckSignFlag: ; 96ad8 ld e, l ld d, h ld b, $2 - call BitTable1Func + call EventFlagAction ld a, c and a pop hl @@ -60541,7 +59324,7 @@ PlayerMovement: ; 96af0 ; force the player to move in some direction ld a, $4 ld hl, $653d - call PushScriptPointer + call CallScript ; ld a, -1 ld c, a scf @@ -60571,7 +59354,7 @@ CheckMenuOW: ; 96b30 ld a, BANK(StartMenuScript) ld hl, StartMenuScript - call PushScriptPointer + call CallScript scf ret @@ -60583,7 +59366,7 @@ CheckMenuOW: ; 96b30 call PlayTalkObject ld a, BANK(SelectMenuScript) ld hl, SelectMenuScript - call PushScriptPointer + call CallScript scf ret ; 96b58 @@ -60694,7 +59477,7 @@ Function96bd7: ; 96bd7 ret nz ld a, $4 ld hl, $7619 - call PushScriptPointer + call CallScript scf ret ; 96beb @@ -60883,7 +59666,7 @@ Function97c30: ; 97c30 ld h, [hl] ld l, a ld a, [$d45d] - call PushScriptPointer + call CallScript scf push af xor a @@ -60914,9 +59697,7 @@ Function97c5f: ; 97c5f call GetFacingTileCoord ld [EngineBuffer1], a ld c, a - ld a, $4 - ld hl, $765b - rst FarCall + callba Function1365b jr c, .asm_97cb9 call CheckCutTreeTile @@ -60962,7 +59743,10 @@ Function97c5f: ; 97c5f ret ; 97cc0 + Function97cc0: ; 97cc0 +; Rock Smash encounter + call Function968c7 jr c, .asm_97ce2 call Function97cfd @@ -60970,9 +59754,7 @@ Function97cc0: ; 97cc0 ld hl, StatusFlags2 bit 2, [hl] jr nz, .asm_97cdb - ld a, $a - ld hl, $60e7 - rst FarCall + callba Function2a0e7 jr nz, .asm_97ce2 jr .asm_97ce6 @@ -60987,22 +59769,22 @@ Function97cc0: ; 97cc0 ret .asm_97ce6 - ld a, BANK(UnknownScript_0x97cf9) - ld hl, UnknownScript_0x97cf9 + ld a, BANK(RockSmashBattleScript) + ld hl, RockSmashBattleScript jr .asm_97cf4 .asm_97ced - ld a, $4 - ld hl, Script_dotrigger + ld a, BANK(UnknownScript_0x135eb) + ld hl, UnknownScript_0x135eb jr .asm_97cf4 .asm_97cf4 - call PushScriptPointer + call CallScript scf ret ; 97cf9 -UnknownScript_0x97cf9: ; 97cf9 +RockSmashBattleScript: ; 97cf9 battlecheck startbattle returnafterbattle @@ -61047,7 +59829,7 @@ Function97d23: ; 97d23 Function97d31: ; 97d31 .asm_97d31 - call RNG + call Random cp 100 << 1 jr nc, .asm_97d31 srl a @@ -61074,7 +59856,7 @@ Function97d31: ; 97d31 .asm_97d54 ld c, a inc c - call RNG + call Random ld a, [hRandomAdd] call SimpleDivide add d @@ -61099,7 +59881,7 @@ Function97d64: ; 97d64 ld a, $a ld hl, $6138 rst FarCall - call RNG + call Random ld a, [hRandomAdd] cp b ret c @@ -63147,7 +61929,7 @@ Functionb8172: ; b8172 ld d, h ld e, l ld b, $2 - call BitTable1Func + call EventFlagAction ld a, c and a jr z, .asm_b81df @@ -63999,7 +62781,7 @@ Functioncc000: ; cc000 call WhiteBGMap call ClearTileMap call ClearSprites - call $0e58 + call Functione58 ld hl, Options ld a, [hl] push af @@ -64556,9 +63338,9 @@ INCBIN "baserom.gbc", $cc9c4, $cca09 - $cc9c4 Functioncca09: ; cca09 call Functionccaaa call Functionce7d1 - cp $fd + cp EGG jp z, $4aa5 - cp $fc + cp NUM_POKEMON + 1 jp z, $4aa2 push af ld hl, $d419 @@ -65219,7 +64001,7 @@ Options_TextSpeed: ; e42f5 ld e, [hl] inc hl ld d, [hl] - ld hl, $c4e7 + hlcoord 11, 3 call PlaceString and a ret @@ -65293,7 +64075,7 @@ Options_BattleScene: ; e4365 ld de, .Off .asm_e4390 - ld hl, $c50f + hlcoord 11, 5 call PlaceString and a ret @@ -65336,7 +64118,7 @@ Options_BattleStyle: ; e43a0 ld de, .Set .asm_e43c9 - ld hl, $c537 + hlcoord 11, 7 call PlaceString and a ret @@ -65386,7 +64168,7 @@ Options_Sound: ; e43dd ld de, .Stereo .asm_e440e - ld hl, $c55f + hlcoord 11, 9 call PlaceString and a ret @@ -65400,7 +64182,7 @@ Options_Sound: ; e43dd Options_Print: ; e4424 - call $4491 + call Functione4491 ld a, [hJoyPressed] bit 5, a jr nz, .asm_e443c @@ -65438,7 +64220,7 @@ Options_Print: ; e4424 ld e, [hl] inc hl ld d, [hl] - ld hl, $c587 + hlcoord 11, 11 call PlaceString and a ret @@ -65529,7 +64311,7 @@ Options_MenuAccount: ; e44c1 ld de, .On .asm_e44ea - ld hl, $c5af + hlcoord 11, 13 call PlaceString and a ret @@ -65637,7 +64419,7 @@ Functione452a: ; e452a ; e455c Functione455c: ; e455c - ld hl, $c4b5 + hlcoord 1, 1 ld de, $0014 ld c, $10 .asm_e4564 @@ -65645,7 +64427,7 @@ Functione455c: ; e455c add hl, de dec c jr nz, .asm_e4564 - ld hl, $c4c9 + hlcoord 1, 2 ld bc, $0028 ld a, [$cf63] call AddNTimes @@ -65776,8 +64558,8 @@ Functione465e: ; e465e Functione4670: ; e4670 ld a, [$cf63] ld e, a - ld d, $0 - ld hl, $467f + ld d, 0 + ld hl, .pointers add hl, de add hl, de ld a, [hli] @@ -65786,7 +64568,90 @@ Functione4670: ; e4670 jp [hl] ; e467f -INCBIN "baserom.gbc", $e467f, $e48ac - $e467f +.pointers + dw Functione468c + dw Functione468d + dw Functione46ba + dw Functione46dd +; e4687 + +Functione4687: ; e4687 + ld hl, $cf63 + inc [hl] + ret +; e468c + +Functione468c: ; e468c + ret +; e468d + +Functione468d: ; e468d + ld hl, $cf65 + ld a, [hl] + cp $20 + jr nc, .asm_e4697 + inc [hl] + ret + +.asm_e4697 + ld [hl], 0 + ld hl, .GAME_FREAK + decoord 5, 10 + ld bc, .end - .GAME_FREAK + call CopyBytes + call Functione4687 + ld de, SFX_GAME_FREAK_PRESENTS + call StartSFX + ret +; e46af + +.GAME_FREAK + ; G A M E _ F R E A K + db 0, 1, 2, 3, 13, 4, 5, 3, 1, 6 +.end + db "@" +; e46ba + +Functione46ba: ; e46ba + ld hl, $cf65 + ld a, [hl] + cp $40 + jr nc, .asm_e46c4 + inc [hl] + ret + +.asm_e46c4 + ld [hl], 0 + ld hl, .presents + decoord 7,11 + ld bc, .end - .presents + call CopyBytes + call Functione4687 + ret +; e46d6 + +.presents + db 7, 8, 9, 10, 11, 12 +.end + db "@" +; e46dd + +Functione46dd: ; e46dd + ld hl, $cf65 + ld a, [hl] + cp $80 + jr nc, .asm_e46e7 + inc [hl] + ret + +.asm_e46e7 + ld hl, $cf63 + set 7, [hl] + ret +; e46ed + + +INCBIN "baserom.gbc", $e46ed, $e48ac - $e46ed Functione48ac: ; e48ac @@ -65799,6 +64664,8 @@ Functione48ac: ; e48ac ld a, [$ff9e] push af call Functione4901 + +Functione48bc: ; e48bc call Functiona57 ld a, [$ffa9] and $f @@ -65809,7 +64676,7 @@ Functione48ac: ; e48ac call Functione490f callba Function8cf69 call DelayFrame - jp $48bc + jp Functione48bc .asm_e48db ld de, $0000 @@ -68073,7 +66940,7 @@ Functionfd0c3: ; fd0c3 ld [CurItem], a ld a, $1 ld [$d10c], a - ld hl, $d8f1 + ld hl, PCItems call Function2f66 ret ; fd0eb @@ -68977,7 +67844,7 @@ Function100b12: ; 100b12 ld hl, $4f2c ld a, $9 ld de, LoadMenuDataHeader - call FarJpDe + call FarCall_de ld a, $9 ld [$cf94], a ld a, [$d0d2] @@ -69145,7 +68012,7 @@ Function100bc2: ; 100bc2 ld hl, $4c39 .asm_100c6b - call FarBattleTextBox + call StdBattleTextBox call Function30b4 jp Function100bc2 ; 100c74 @@ -70817,7 +69684,7 @@ SECTION "bank43",ROMX,BANK[$43] INCBIN "baserom.gbc", $10c000, $10ed67 - $10c000 -StartTitleScreen: ; 10ed67 +_TitleScreen: ; 10ed67 call WhiteBGMap call ClearSprites @@ -70941,7 +69808,7 @@ StartTitleScreen: ; 10ed67 call DrawGraphic ; Draw copyright text - ld hl, $9c03 ; BG Map 1 (3,0) + ld hl, $9c03 ; BGMap1(3,0) ld bc, $010d ; 13x1 ld d, $c ld e, $10 @@ -70979,11 +69846,9 @@ StartTitleScreen: ; 10ed67 ; LY/SCX trickery starts here -; Save WRAM bank ld a, [rSVBK] push af -; WRAM bank 5 - ld a, 5 + ld a, 5 ; BANK(LYOverrides) ld [rSVBK], a ; Make alternating lines come in from opposite sides @@ -70991,28 +69856,27 @@ StartTitleScreen: ; 10ed67 ; ( This part is actually totally pointless, you can't ; see anything until these values are overwritten! ) - ld b, 40 ; alternate for 80 lines - ld hl, $d100 ; LY buffer + ld b, 80 / 2 ; alternate for 80 lines + ld hl, LYOverrides .loop ; $00 is the middle position - ld [hl], $70 ; coming from the left + ld [hl], +112 ; coming from the left inc hl - ld [hl], $90 ; coming from the right + ld [hl], -112 ; coming from the right inc hl dec b jr nz, .loop ; Make sure the rest of the buffer is empty - ld hl, $d150 + ld hl, LYOverrides + 80 xor a - ld bc, $0040 + ld bc, LYOverridesEnd - (LYOverrides + 80) call ByteFill ; Let LCD Stat know we're messing around with SCX ld a, rSCX - rJOYP ld [hLCDStatCustom], a -; Restore WRAM bank pop af ld [rSVBK], a @@ -71026,14 +69890,13 @@ StartTitleScreen: ; 10ed67 set 2, a ld [rLCDC], a -; - ld a, $70 + ld a, +112 ld [hSCX], a - ld a, $8 + ld a, 8 ld [hSCY], a - ld a, $7 + ld a, 7 ld [hWX], a - ld a, $90 + ld a, -112 ld [hWY], a ld a, $1 @@ -71625,7 +70488,7 @@ Function117c4a: add hl, de dec c jr nz, .asm_117c71 ; 0x117c7b $f4 - call $04b6 + call Function4b6 pop af ld [rSVBK], a ld a, $80 @@ -71815,7 +70678,107 @@ UnknownText_0x11ac1f: ; 0x11ac1f db "Please wait…", $57 ; 0x11ac3e -INCBIN "baserom.gbc", $11ac3e, $11bc9e - $11ac3e +INCBIN "baserom.gbc", $11ac3e, $11b98f - $11ac3e + +Function11b98f: ; 11b98f + ld hl, PartyCount + ld a, [hl] + ld e, a + inc [hl] + ld a, [BGMapBuffer] + ld l, a + ld a, [$cd21] + ld h, a + inc hl + ld bc, PartySpecies + ld d, e +.asm_11b9a2 + inc bc + dec d + jr nz, .asm_11b9a2 + ld a, e + ld [CurPartyMon], a + ld a, [hl] + ld [bc], a + inc bc + ld a, $ff + ld [bc], a + ld hl, PartyMon1Species + ld bc, $0030 + ld a, e + ld [$cd2a], a +.asm_11b9ba + add hl, bc + dec a + and a + jr nz, .asm_11b9ba + ld e, l + ld d, h + ld a, [CreditsTimer] + ld l, a + ld a, [$cd23] + ld h, a + ld bc, $0030 + call CopyBytes + ld hl, PartyMon1OT + ld bc, $000b + ld a, [$cd2a] +.asm_11b9d8 + add hl, bc + dec a + and a + jr nz, .asm_11b9d8 + ld e, l + ld d, h + ld a, [$cd24] + ld l, a + ld a, [$cd25] + ld h, a + ld bc, $000a + call CopyBytes + ld a, $50 + ld [de], a + ld hl, PartyMon1Nickname + ld bc, $000b + ld a, [$cd2a] +.asm_11b9f9 + add hl, bc + dec a + and a + jr nz, .asm_11b9f9 + ld e, l + ld d, h + ld a, [$cd26] + ld l, a + ld a, [$cd27] + ld h, a + ld bc, $000a + call CopyBytes + ld a, $50 + ld [de], a + ld hl, $a600 + ld bc, $002f + ld a, [$cd2a] +.asm_11ba1a + add hl, bc + dec a + and a + jr nz, .asm_11ba1a + ld a, $0 + call GetSRAMBank + ld e, l + ld d, h + ld a, [$cd28] + ld l, a + ld a, [$cd29] + ld h, a + ld bc, $002f + call CopyBytes + call CloseSRAM + ret +; 11ba38 + +INCBIN "baserom.gbc", $11ba38, $11bc9e - $11ba38 SECTION "bank47",ROMX,BANK[$47] @@ -72947,7 +71910,7 @@ Function17c000: ; 17c000 ld bc, $0310 xor a call ByteFill - call $0e51 + call Functione51 call Functione5f ld hl, $4b83 ld de, TileMap @@ -73544,22 +72507,26 @@ Function1de27f: ; 1de27f Function1de28a: ; 1de28a ld hl, DudeAutoInput_A - jr .asm_1de299 + jr Function1de299 +; 1de28f +Function1de28f: ; 1de28f ld hl, DudeAutoInput_RightA - jr .asm_1de299 + jr Function1de299 +; 1de294 +Function1de294: ; 1de294 ld hl, DudeAutoInput_DownA - jr .asm_1de299 + jr Function1de299 +; 1de299 -.asm_1de299 +Function1de299: ; 1de299 ld a, $77 call StartAutoInput ret ; 1de29f - DudeAutoInput_A: ; 1de29f db NO_INPUT, $50 db BUTTON_A, $00 @@ -73679,260 +72646,8 @@ INCBIN "baserom.gbc", $1f4018, $1f636a - $1f4018 SECTION "bank7E",ROMX,BANK[$7E] -Function1f8000: ; 1f8000 - ld a, [rSVBK] - push af - ld a, $3 - ld [rSVBK], a - xor a - ld hl, $d100 - ld bc, $00e0 - call ByteFill - ld a, $ff - ld [$d10c], a - ld [$d147], a - ld [$d182], a - ld de, $d100 - ld a, [hRandomAdd] - ld b, a -.asm_1f8022 - call RNG - ld a, [hRandomAdd] - add b - ld b, a - and $1f - cp $15 - jr nc, .asm_1f8022 - ld b, a - ld a, $1 - call GetSRAMBank - ld c, $7 - ld hl, $be48 -.asm_1f803a - ld a, [hli] - cp b - jr z, .asm_1f8022 - dec c - jr nz, .asm_1f803a - ld hl, $be48 - ld a, [$be46] - ld c, a - ld a, b - ld b, 0 - add hl, bc - ld [hl], a - call CloseSRAM - push af - ld hl, BattleTowerTrainers - ld bc, 11 - call AddNTimes - ld bc, 11 - call CopyBytes - call Function1f8081 - pop af - ld hl, Function1f8000 - ld bc, $0024 - call AddNTimes - ld bc, $0024 -.asm_1f8070 - ld a, $7c - call GetFarByte - ld [de], a - inc hl - inc de - dec bc - ld a, b - or c - jr nz, .asm_1f8070 - pop af - ld [rSVBK], a - ret -; 1f8081 - -Function1f8081: ; 1f8081 - ld c, $3 - push bc - ld a, $1 - call GetSRAMBank -.asm_1f8089 - ld a, [$d800] - dec a - ld hl, BattleTowerMons - ld bc, BattleTowerMons2 - BattleTowerMons1 - call AddNTimes - - ld a, [hRandomAdd] - ld b, a -.asm_1f8099 - call RNG - ld a, [hRandomAdd] - add b - ld b, a - and $1f - cp (BattleTowerMons2 - BattleTowerMons1) / ($3b) - jr nc, .asm_1f8099 - - ld bc, $3b - call AddNTimes - ld a, [hli] - ld b, a - ld a, [hld] - ld c, a - ld a, [$d10b] - cp b - jr z, .asm_1f8089 - ld a, [$d10c] - cp c - jr z, .asm_1f8089 - ld a, [$d146] - cp b - jr z, .asm_1f8089 - ld a, [$d147] - cp c - jr z, .asm_1f8089 - ld a, [$d181] - cp b - jr z, .asm_1f8089 - ld a, [$d182] - cp c - jr z, .asm_1f8089 - ld a, [$be51] - cp b - jr z, .asm_1f8089 - ld a, [$be52] - cp b - jr z, .asm_1f8089 - ld a, [$be53] - cp b - jr z, .asm_1f8089 - ld a, [$be54] - cp b - jr z, .asm_1f8089 - ld a, [$be55] - cp b - jr z, .asm_1f8089 - ld a, [$be56] - cp b - jr z, .asm_1f8089 - - ld bc, $3b - call CopyBytes - ld a, [$d265] - push af - push de - ld hl, -$3b - add hl, de - ld a, [hl] - ld [$d265], a - ld bc, $0030 - add hl, bc - push hl - call GetPokemonName - ld h, d - ld l, e - pop de - ld bc, $000b - call CopyBytes - pop de - pop af - ld [$d265], a - pop bc - dec c - jp nz, $4083 - ld a, [$be51] - ld [$be54], a - ld a, [$be52] - ld [$be55], a - ld a, [$be53] - ld [$be56], a - ld a, [$d10b] - ld [$be51], a - ld a, [$d146] - ld [$be52], a - ld a, [$d181] - ld [$be53], a - call CloseSRAM - ret -; 1f814e - -BattleTowerTrainers: ; 1f814e - db "HANSON@@@@", FISHER - db "SAWYER@@@@", POKEMANIAC - db "MASUDA@@@@", GUITARIST - db "NICKEL@@@@", SCIENTIST - db "OLSON@@@@@", POKEFANM - db "ZABOROWSKI", LASS - db "WRIGHT@@@@", YOUNGSTER - db "ALEXANDER@", HIKER - db "KAWAKAMI@@", TEACHER - db "BICKETT@@@", POKEFANM - db "SAITO@@@@@", KIMONO_GIRL - db "CRAWFORD@@", BOARDER - db "DIAZ@@@@@@", PICNICKER - db "ERICKSON@@", BIKER - db "FAIRFIELD@", JUGGLER - db "HUNTER@@@@", POKEFANF - db "HILL@@@@@@", FIREBREATHER - db "JAVIER@@@@", SWIMMERF - db "KAUFMAN@@@", SWIMMERM - db "LANCASTER@", SKIER - db "McMAHILL@@", CAMPER - db "OBRIEN@@@@", GENTLEMAN - db "FROST@@@@@", BEAUTY - db "MORSE@@@@@", SUPER_NERD - db "YUFUNE@@@@", BLACKBELT_T - db "RAJAN@@@@@", COOLTRAINERF - db "RODRIGUEZ@", OFFICER - db "SANTIAGO@@", PSYCHIC_T - db "STOCK@@@@@", POKEFANM - db "THURMAN@@@", SCIENTIST - db "VALENTINO@", BEAUTY - db "WAGNER@@@@", CAMPER - db "YATES@@@@@", BIRD_KEEPER - db "ANDREWS@@@", PICNICKER - db "BAHN@@@@@@", POKEMANIAC - db "MORI@@@@@@", SCIENTIST - db "BUCKMAN@@@", SAGE - db "COBB@@@@@@", SCHOOLBOY - db "HUGHES@@@@", FISHER - db "ARITA@@@@@", KIMONO_GIRL - db "EASTON@@@@", PSYCHIC_T - db "FREEMAN@@@", CAMPER - db "GIESE@@@@@", LASS - db "HATCHER@@@", GENTLEMAN - db "JACKSON@@@", POKEFANF - db "KAHN@@@@@@", POKEMANIAC - db "LEONG@@@@@", YOUNGSTER - db "MARINO@@@@", TEACHER - db "NEWMAN@@@@", SAILOR - db "NGUYEN@@@@", BLACKBELT_T - db "OGDEN@@@@@", SUPER_NERD - db "PARK@@@@@@", COOLTRAINERF - db "RAINE@@@@@", SWIMMERM - db "SELLS@@@@@", BIRD_KEEPER - db "ROCKWELL@@", BOARDER - db "THORNTON@@", LASS - db "TURNER@@@@", OFFICER - db "VAN DYKE@@", SKIER - db "WALKER@@@@", SCHOOLBOY - db "MEYER@@@@@", SWIMMERF - db "JOHNSON@@@", YOUNGSTER - db "ADAMS@@@@@", GUITARIST - db "SMITH@@@@@", BUG_CATCHER - db "TAJIRI@@@@", BUG_CATCHER - db "BAKER@@@@@", POKEMANIAC - db "COLLINS@@@", SCIENTIST - db "SMART@@@@@", SUPER_NERD - db "DYKSTRA@@@", SWIMMERF - db "EATON@@@@@", BIKER - db "WONG@@@@@@", FIREBREATHER -; 1f8450 - -BattleTowerMons: ; 1f8450 - INCLUDE "stats/battle_tower.asm" -; 1fb4b6 - -INCBIN "baserom.gbc", $1fb4b6, $1fb8a8 - $1fb4b6 +INCLUDE "stats/battle_tower.asm" +INCLUDE "stats/odd_eggs.asm" SECTION "bank7F",ROMX,BANK[$7F] diff --git a/preprocessor.py b/preprocessor.py index acf296e91..188db81a6 100644 --- a/preprocessor.py +++ b/preprocessor.py @@ -12,35 +12,46 @@ from extras.pokemontools.crystal import ( Signpost, PeopleEvent, DataByteWordMacro, - ItemFragment, text_command_classes, movement_command_classes, music_classes, effect_classes, ) -even_more_macros = [ - Warp, - XYTrigger, - Signpost, - PeopleEvent, - DataByteWordMacro, - ItemFragment, -] +def load_pokecrystal_macros(): + """ + Construct a list of macros that are needed for pokecrystal preprocessing. + """ + ourmacros = [] -macros = command_classes -macros += even_more_macros -macros += [each[1] for each in text_command_classes] -macros += movement_command_classes -macros += music_classes -macros += effect_classes + even_more_macros = [ + Warp, + XYTrigger, + Signpost, + PeopleEvent, + DataByteWordMacro, + ] -def preprocess(macros): + ourmacros += command_classes + ourmacros += even_more_macros + ourmacros += [each[1] for each in text_command_classes] + ourmacros += movement_command_classes + ourmacros += music_classes + ourmacros += effect_classes + + return ourmacros + +def preprocess(macro_table, lines=None): """ Entry point for the preprocessor. """ - return preprocessor.preprocess(macros) + return preprocessor.preprocess(macro_table, lines=lines) + +def main(): + macros = load_pokecrystal_macros() + macro_table = preprocessor.make_macro_table(macros) + preprocess(macro_table) # only run against stdin when not included as a module if __name__ == "__main__": - preprocess(macros) + main() diff --git a/prequeue.py b/prequeue.py index c9a9a8bcc..5c1a9f161 100644 --- a/prequeue.py +++ b/prequeue.py @@ -1,16 +1,28 @@ # coding: utf-8 - -# Starting a new python process to preprocess each source file -# creates too much overhead. Instead, a list of files to preprocess -# is fed into a script run from a single process. +""" +Starting a new python process to preprocess each source file creates too much +overhead. Instead, a list of files to preprocess is fed into a script run from +a single process. +""" import os import sys import preprocessor -if __name__ == '__main__': +def main(): + macros = preprocessor.load_pokecrystal_macros() + macro_table = preprocessor.preprocessor.make_macro_table(macros) + + stdout = sys.stdout + for source in sys.argv[1:]: dest = os.path.splitext(source)[0] + '.tx' sys.stdin = open(source, 'r') sys.stdout = open(dest, 'w') - preprocessor.preprocess(preprocessor.macros) + preprocessor.preprocess(macro_table) + + # reset stdout + sys.stdout = stdout + +if __name__ == '__main__': + main() diff --git a/stats/battle_tower.asm b/stats/battle_tower.asm index 4a74fe0f5..044f351f8 100644 --- a/stats/battle_tower.asm +++ b/stats/battle_tower.asm @@ -1,4 +1,254 @@ +Function1f8000: ; 1f8000 + ld a, [rSVBK] + push af + ld a, $3 + ld [rSVBK], a + xor a + ld hl, $d100 + ld bc, $00e0 + call ByteFill + ld a, $ff + ld [$d10c], a + ld [$d147], a + ld [$d182], a + ld de, $d100 + ld a, [hRandomAdd] + ld b, a +.asm_1f8022 + call Random + ld a, [hRandomAdd] + add b + ld b, a + and $1f + cp $15 + jr nc, .asm_1f8022 + ld b, a + ld a, $1 + call GetSRAMBank + ld c, $7 + ld hl, $be48 +.asm_1f803a + ld a, [hli] + cp b + jr z, .asm_1f8022 + dec c + jr nz, .asm_1f803a + ld hl, $be48 + ld a, [$be46] + ld c, a + ld a, b + ld b, 0 + add hl, bc + ld [hl], a + call CloseSRAM + push af + ld hl, BattleTowerTrainers + ld bc, 11 + call AddNTimes + ld bc, 11 + call CopyBytes + call Function1f8081 + pop af + ld hl, Function1f8000 + ld bc, $0024 + call AddNTimes + ld bc, $0024 +.asm_1f8070 + ld a, $7c + call GetFarByte + ld [de], a + inc hl + inc de + dec bc + ld a, b + or c + jr nz, .asm_1f8070 + pop af + ld [rSVBK], a + ret +; 1f8081 +Function1f8081: ; 1f8081 + ld c, $3 + push bc + ld a, $1 + call GetSRAMBank +.asm_1f8089 + ld a, [$d800] + dec a + ld hl, BattleTowerMons + ld bc, BattleTowerMons2 - BattleTowerMons1 + call AddNTimes + + ld a, [hRandomAdd] + ld b, a +.asm_1f8099 + call Random + ld a, [hRandomAdd] + add b + ld b, a + and $1f + cp (BattleTowerMons2 - BattleTowerMons1) / ($3b) + jr nc, .asm_1f8099 + + ld bc, $3b + call AddNTimes + ld a, [hli] + ld b, a + ld a, [hld] + ld c, a + ld a, [$d10b] + cp b + jr z, .asm_1f8089 + ld a, [$d10c] + cp c + jr z, .asm_1f8089 + ld a, [$d146] + cp b + jr z, .asm_1f8089 + ld a, [$d147] + cp c + jr z, .asm_1f8089 + ld a, [$d181] + cp b + jr z, .asm_1f8089 + ld a, [$d182] + cp c + jr z, .asm_1f8089 + ld a, [$be51] + cp b + jr z, .asm_1f8089 + ld a, [$be52] + cp b + jr z, .asm_1f8089 + ld a, [$be53] + cp b + jr z, .asm_1f8089 + ld a, [$be54] + cp b + jr z, .asm_1f8089 + ld a, [$be55] + cp b + jr z, .asm_1f8089 + ld a, [$be56] + cp b + jr z, .asm_1f8089 + + ld bc, $3b + call CopyBytes + ld a, [$d265] + push af + push de + ld hl, -$3b + add hl, de + ld a, [hl] + ld [$d265], a + ld bc, $0030 + add hl, bc + push hl + call GetPokemonName + ld h, d + ld l, e + pop de + ld bc, $000b + call CopyBytes + pop de + pop af + ld [$d265], a + pop bc + dec c + jp nz, $4083 + ld a, [$be51] + ld [$be54], a + ld a, [$be52] + ld [$be55], a + ld a, [$be53] + ld [$be56], a + ld a, [$d10b] + ld [$be51], a + ld a, [$d146] + ld [$be52], a + ld a, [$d181] + ld [$be53], a + call CloseSRAM + ret +; 1f814e + +BattleTowerTrainers: ; 1f814e + db "HANSON@@@@", FISHER + db "SAWYER@@@@", POKEMANIAC + db "MASUDA@@@@", GUITARIST + db "NICKEL@@@@", SCIENTIST + db "OLSON@@@@@", POKEFANM + db "ZABOROWSKI", LASS + db "WRIGHT@@@@", YOUNGSTER + db "ALEXANDER@", HIKER + db "KAWAKAMI@@", TEACHER + db "BICKETT@@@", POKEFANM + db "SAITO@@@@@", KIMONO_GIRL + db "CRAWFORD@@", BOARDER + db "DIAZ@@@@@@", PICNICKER + db "ERICKSON@@", BIKER + db "FAIRFIELD@", JUGGLER + db "HUNTER@@@@", POKEFANF + db "HILL@@@@@@", FIREBREATHER + db "JAVIER@@@@", SWIMMERF + db "KAUFMAN@@@", SWIMMERM + db "LANCASTER@", SKIER + db "McMAHILL@@", CAMPER + db "OBRIEN@@@@", GENTLEMAN + db "FROST@@@@@", BEAUTY + db "MORSE@@@@@", SUPER_NERD + db "YUFUNE@@@@", BLACKBELT_T + db "RAJAN@@@@@", COOLTRAINERF + db "RODRIGUEZ@", OFFICER + db "SANTIAGO@@", PSYCHIC_T + db "STOCK@@@@@", POKEFANM + db "THURMAN@@@", SCIENTIST + db "VALENTINO@", BEAUTY + db "WAGNER@@@@", CAMPER + db "YATES@@@@@", BIRD_KEEPER + db "ANDREWS@@@", PICNICKER + db "BAHN@@@@@@", POKEMANIAC + db "MORI@@@@@@", SCIENTIST + db "BUCKMAN@@@", SAGE + db "COBB@@@@@@", SCHOOLBOY + db "HUGHES@@@@", FISHER + db "ARITA@@@@@", KIMONO_GIRL + db "EASTON@@@@", PSYCHIC_T + db "FREEMAN@@@", CAMPER + db "GIESE@@@@@", LASS + db "HATCHER@@@", GENTLEMAN + db "JACKSON@@@", POKEFANF + db "KAHN@@@@@@", POKEMANIAC + db "LEONG@@@@@", YOUNGSTER + db "MARINO@@@@", TEACHER + db "NEWMAN@@@@", SAILOR + db "NGUYEN@@@@", BLACKBELT_T + db "OGDEN@@@@@", SUPER_NERD + db "PARK@@@@@@", COOLTRAINERF + db "RAINE@@@@@", SWIMMERM + db "SELLS@@@@@", BIRD_KEEPER + db "ROCKWELL@@", BOARDER + db "THORNTON@@", LASS + db "TURNER@@@@", OFFICER + db "VAN DYKE@@", SKIER + db "WALKER@@@@", SCHOOLBOY + db "MEYER@@@@@", SWIMMERF + db "JOHNSON@@@", YOUNGSTER + db "ADAMS@@@@@", GUITARIST + db "SMITH@@@@@", BUG_CATCHER + db "TAJIRI@@@@", BUG_CATCHER + db "BAKER@@@@@", POKEMANIAC + db "COLLINS@@@", SCIENTIST + db "SMART@@@@@", SUPER_NERD + db "DYKSTRA@@@", SWIMMERF + db "EATON@@@@@", BIKER + db "WONG@@@@@@", FIREBREATHER +; 1f8450 + + +BattleTowerMons: ; 1f8450 BattleTowerMons1: diff --git a/stats/odd_eggs.asm b/stats/odd_eggs.asm new file mode 100644 index 000000000..6922a2de7 --- /dev/null +++ b/stats/odd_eggs.asm @@ -0,0 +1,465 @@ +GiveOddEgg: ; 1fb4b6 + +; Figure out which egg to give. + call Random + ld hl, .Probabilities + ld c, 0 + ld b, c +.next + ld a, [hli] + ld e, a + ld a, [hli] + ld d, a + ld a, d + cp $ff + jr nz, .first + ld a, e + cp $ff + jr z, .done +.first + ld a, [hRandomSub] + cp d + jr c, .done + jr z, .second + jr .good +.second + ld a, [hRandomAdd] + cp e + jr c, .done + jr z, .done +.good + inc bc + jr .next +.done + + ld hl, OddEggs + ld a, OddEgg2 - OddEgg1 + call AddNTimes + ld de, EnemyMoveAnimation + ld bc, $0046 + call CopyBytes + ld a, EGG_TICKET + ld [CurItem], a + ld a, $1 + ld [$d10c], a + ld a, $ff + ld [$d107], a + ld hl, NumItems + call Function2f53 + ld a, EGG + ld [$cd2a], a + ld a, $29 + ld [$cd20], a + ld a, $cd + ld [$cd21], a + ld a, $8 + ld [$cd22], a + ld a, $c6 + ld [$cd23], a + + ld hl, .Odd + ld de, $cd2b + ld bc, $000b + call CopyBytes + + ld a, $2b + ld [$cd24], a + ld a, $cd + ld [$cd25], a + ld a, $38 + ld [$cd26], a + ld a, $c6 + ld [$cd27], a + callba Function11b98f + ret +; 1fb546 + +.Odd + db "ODD@@@@@@@@@" + +.Probabilities + dw $147a ; 92% -> 8% + dw $170a ; 91% -> 1% + dw $3fff ; 75% -> 16% + dw $47ad ; 72% -> 3% + dw $70a3 ; 56% -> 16% + dw $7851 ; 53% -> 3% + dw $9c28 ; 39% -> 14% + dw $a147 ; 37% -> 2% + dw $bae0 ; 27% -> 10% + dw $bfff ; 25% -> 2% + dw $deb7 ; 13% -> 12% + dw $e3d6 ; 11% -> 2% + dw $fd6f ; 1% -> 10% + dw $ffff ; 0% -> 1% +; 1fb56e + + +OddEggs: ; 1fb56e + +OddEgg1: + db PICHU + db NO_ITEM + db THUNDERSHOCK, CHARM, DIZZY_PUNCH, NONE + dw 02048 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $0, $0 ; DVs + db 30, 20, 10, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 17 ; Max HP + bigdw 9 ; Atk + bigdw 6 ; Def + bigdw 11 ; Spd + bigdw 8 ; SAtk + bigdw 8 ; SDef + db "EGG@@@@@@@@" + +OddEgg2: + db PICHU + db NO_ITEM + db THUNDERSHOCK, CHARM, DIZZY_PUNCH, NONE + dw 00256 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $2a, $aa ; DVs + db 30, 20, 10, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 17 ; Max HP + bigdw 9 ; Atk + bigdw 7 ; Def + bigdw 12 ; Spd + bigdw 9 ; SAtk + bigdw 9 ; SDef + db "EGG@@@@@@@@" + + db CLEFFA + db NO_ITEM + db POUND, CHARM, DIZZY_PUNCH, NONE + dw 04096 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $0, $0 ; DVs + db 35, 20, 10, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 20 ; Max HP + bigdw 7 ; Atk + bigdw 7 ; Def + bigdw 6 ; Spd + bigdw 9 ; SAtk + bigdw 10 ; SDef + db "EGG@@@@@@@@" + + db CLEFFA + db NO_ITEM + db POUND, CHARM, DIZZY_PUNCH, NONE + dw 00768 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $2a, $aa ; DVs + db 35, 20, 10, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 20 ; Max HP + bigdw 7 ; Atk + bigdw 8 ; Def + bigdw 7 ; Spd + bigdw 10 ; SAtk + bigdw 11 ; SDef + db "EGG@@@@@@@@" + + db IGGLYBUFF + db NO_ITEM + db SING, CHARM, DIZZY_PUNCH, NONE + dw 04096 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $0, $0 ; DVs + db 15, 20, 10, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 24 ; Max HP + bigdw 8 ; Atk + bigdw 6 ; Def + bigdw 6 ; Spd + bigdw 9 ; SAtk + bigdw 7 ; SDef + db "EGG@@@@@@@@" + + db IGGLYBUFF + db NO_ITEM + db SING, CHARM, DIZZY_PUNCH, NONE + dw 00768 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $2a, $aa ; DVs + db 15, 20, 10, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 24 ; Max HP + bigdw 8 ; Atk + bigdw 7 ; Def + bigdw 7 ; Spd + bigdw 10 ; SAtk + bigdw 8 ; SDef + db "EGG@@@@@@@@" + + db SMOOCHUM + db NO_ITEM + db POUND, LICK, DIZZY_PUNCH, NONE + dw 03584 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $0, $0 ; DVs + db 35, 30, 10, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 19 ; Max HP + bigdw 8 ; Atk + bigdw 6 ; Def + bigdw 11 ; Spd + bigdw 13 ; SAtk + bigdw 11 ; SDef + db "EGG@@@@@@@@" + + db SMOOCHUM + db NO_ITEM + db POUND, LICK, DIZZY_PUNCH, NONE + dw 00512 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $2a, $aa ; DVs + db 35, 30, 10, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 19 ; Max HP + bigdw 8 ; Atk + bigdw 7 ; Def + bigdw 12 ; Spd + bigdw 14 ; SAtk + bigdw 12 ; SDef + db "EGG@@@@@@@@" + + db MAGBY + db NO_ITEM + db EMBER, DIZZY_PUNCH, NONE, NONE + dw 02560 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $0, $0 ; DVs + db 25, 10, 0, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 19 ; Max HP + bigdw 12 ; Atk + bigdw 8 ; Def + bigdw 13 ; Spd + bigdw 12 ; SAtk + bigdw 10 ; SDef + db "EGG@@@@@@@@" + + db MAGBY + db NO_ITEM + db EMBER, DIZZY_PUNCH, NONE, NONE + dw 00512 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $2a, $aa ; DVs + db 25, 10, 0, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 19 ; Max HP + bigdw 12 ; Atk + bigdw 9 ; Def + bigdw 14 ; Spd + bigdw 13 ; SAtk + bigdw 11 ; SDef + db "EGG@@@@@@@@" + + db ELEKID + db NO_ITEM + db QUICK_ATTACK, LEER, DIZZY_PUNCH, NONE + dw 03072 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $0, $0 ; DVs + db 30, 30, 10, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 19 ; Max HP + bigdw 11 ; Atk + bigdw 8 ; Def + bigdw 14 ; Spd + bigdw 11 ; SAtk + bigdw 10 ; SDef + db "EGG@@@@@@@@" + + db ELEKID + db NO_ITEM + db QUICK_ATTACK, LEER, DIZZY_PUNCH, NONE + dw 00512 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $2a, $aa ; DVs + db 30, 30, 10, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 19 ; Max HP + bigdw 11 ; Atk + bigdw 9 ; Def + bigdw 15 ; Spd + bigdw 12 ; SAtk + bigdw 11 ; SDef + db "EGG@@@@@@@@" + + db TYROGUE + db NO_ITEM + db TACKLE, DIZZY_PUNCH, NONE, NONE + dw 02560 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $0, $0 ; DVs + db 35, 10, 0, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 18 ; Max HP + bigdw 8 ; Atk + bigdw 8 ; Def + bigdw 8 ; Spd + bigdw 8 ; SAtk + bigdw 8 ; SDef + db "EGG@@@@@@@@" + + db TYROGUE + db NO_ITEM + db TACKLE, DIZZY_PUNCH, NONE, NONE + dw 00256 ; OT ID + dt 125 ; Exp + ; Stat exp + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + bigdw 0 + db $2a, $aa ; DVs + db 35, 10, 0, 0 ; PP + db 20 ; Happiness + db 0, 0, 0 ; Pokerus, Caught data + db 5 ; Level + db 0, 0 ; Status + bigdw 0 ; HP + bigdw 18 ; Max HP + bigdw 8 ; Atk + bigdw 9 ; Def + bigdw 9 ; Spd + bigdw 9 ; SAtk + bigdw 9 ; SDef + db "EGG@@@@@@@@" + diff --git a/stats/wild/fish.asm b/stats/wild/fish.asm index 75f49d6c4..44a30a0b2 100644 --- a/stats/wild/fish.asm +++ b/stats/wild/fish.asm @@ -39,7 +39,7 @@ Fish: ; 9241a ; Fish for monsters with rod b from encounter data in FishGroup at hl. ; Return monster e at level d. - call RNG + call Random ; Got a bite? cp [hl] @@ -59,7 +59,7 @@ Fish: ; 9241a ld l, a ; Encounter chance for this monster: - call RNG + call Random .CheckEncounter cp [hl] diff --git a/wram.asm b/wram.asm index 014a86f6b..14fb8d5a3 100644 --- a/wram.asm +++ b/wram.asm @@ -13,9 +13,9 @@ VBGMap1: SECTION "WRAMBank0",WRAM0[$c000] -SECTION "stack",WRAM0[$c000] - ds $100 -Stack: ; c100 +SECTION "stack",WRAM0[$c0ff] +Stack: ; c0ff + ds -$100 SECTION "audio",WRAM0[$c100] @@ -1627,7 +1627,12 @@ SATURDAY EQU 6 PlayerSprite: ; d4d8 ds 1 - ds 5 + ds 3 + +PlayerPalette: ; d4dc + ds 1 + + ds 1 PlayerDirection: ; d4de ; uses bits 2 and 3 / $0c / %00001100 @@ -1637,8 +1642,17 @@ PlayerDirection: ; d4de ; $11 right ds 1 + ds 2 + +PlayerAction: ; d4e1 +; 1 standing +; 2 walking +; 4 spinning +; 6 fishing + ds 1 + + ds 2 -SECTION "MapEngine",WRAMX[$d4e4],BANK[1] StandingTile: ; d4e4 ds 1 StandingTile2: ; d4e5 @@ -1698,7 +1712,10 @@ StatusFlags2: ; d84d Money: ; d84e ds 3 - ds 6 + ds 4 + +Coins: ; d855 + ds 2 Badges: JohtoBadges: ; d857 @@ -1728,7 +1745,12 @@ NumBalls: ; d8d7 Balls: ; d8d8 ds 25 BallsEnd - + +PCItems: ; d8f1 + ds 101 +PCItemsEnd + + SECTION "overworld",WRAMX[$d95b],BANK[1] WhichRegisteredItem: ; d95b REGISTERED_POCKET EQU %11000000 @@ -1753,23 +1775,16 @@ UndergroundSwitchPositions: ; d963 FarfetchdPosition: ; d964 ds 1 ; which position the ilex farfetch'd is in -SECTION "Events",WRAMX[$dad4],BANK[1] +SECTION "Events",WRAMX[$da72],BANK[1] +EventFlags: ; da72 ;RoomDecorations: ; dac6 -; db 7 - -HoOhEvent: ; dad4 - ds 1 -LugiaEvent: ; dad5 - ds 1 - -; TODO -;SuicuneEvent: ; dad8 (tin tower) ;TeamRocketAzaleaTownAttackEvent: ; db51 -;SudowoodoEvent: ; db51 ;PoliceAtElmsLabEvent: ; db52 ;SalesmanMahoganyTownEvent: ; db5c ;RedGyaradosEvent: ; db5c + ds 250 +; db6c SECTION "BoxNames",WRAMX[$db75],BANK[1] ; 8 chars + $50 @@ -1982,6 +1997,7 @@ PartyMon5Nickname: ; de6d ds 11 PartyMon6Nickname: ; de78 ds 11 +PartyMonNicknamesEnd SECTION "Pokedex",WRAMX[$de99],BANK[1] PokedexSeen: ; de99 @@ -2090,12 +2106,189 @@ RoamMon3DVs: ; dfe2 SECTION "WRAMBank5",WRAMX[$d000],BANK[5] ; 8 4-color palettes -Unkn1Pals: +Unkn1Pals: ; d000 ds $40 -Unkn2Pals: +Unkn2Pals: ; d040 ds $40 -BGPals: +BGPals: ; d080 ds $40 -OBPals: +OBPals: ; d0c0 ds $40 +LYOverrides: ; d100 + ds 144 +LYOverridesEnd + + +SECTION "SRAMBank1",SRAM,BANK[1] + +SECTION "BoxMons",SRAM[$ad10],BANK[1] +BoxCount: ; ad10 + ds 1 +BoxSpecies: ; ad11 + ds 20 + ds 1 +BoxMons: +BoxMon1: +BoxMon1Species: ; ad26 + ds 1 +BoxMon1Item: ; ad27 + ds 1 +BoxMon1Moves: ; ad28 + ds 4 +BoxMon1ID: ; ad2c + ds 2 +BoxMon1Exp: ; ad2e + ds 3 +BoxMon1HPExp: ; ad31 + ds 2 +BoxMon1AtkExp: ; ad33 + ds 2 +BoxMon1DefExp: ; ad35 + ds 2 +BoxMon1SpdExp: ; ad37 + ds 2 +BoxMon1SpcExp: ; ad39 + ds 2 +BoxMon1DVs: ; ad3b + ds 2 +BoxMon1PP: ; ad3d + ds 4 +BoxMon1Happiness: ; ad41 + ds 1 +BoxMon1PokerusStatus: ; ad42 + ds 1 +BoxMon1CaughtData: +BoxMon1CaughtTime: +BoxMon1CaughtLevel: ; ad43 + ds 1 +BoxMon1CaughtGender: +BoxMon1CaughtLocation: ; ad44 + ds 1 +BoxMon1Level: ; ad45 + ds 1 + +BoxMon2: ; ad46 + ds 32 +BoxMon3: ; ad66 + ds 32 +BoxMon4: ; ad86 + ds 32 +BoxMon5: ; ada6 + ds 32 +BoxMon6: ; adc6 + ds 32 +BoxMon7: ; ade6 + ds 32 +BoxMon8: ; ae06 + ds 32 +BoxMon9: ; ae26 + ds 32 +BoxMon10: ; ae46 + ds 32 +BoxMon11: ; ae66 + ds 32 +BoxMon12: ; ae86 + ds 32 +BoxMon13: ; aea6 + ds 32 +BoxMon14: ; aec6 + ds 32 +BoxMon15: ; aee6 + ds 32 +BoxMon16: ; af06 + ds 32 +BoxMon17: ; af26 + ds 32 +BoxMon18: ; af46 + ds 32 +BoxMon19: ; af66 + ds 32 +BoxMon20: ; af86 + ds 32 + +BoxMonOT: +BoxMon1OT: ; afa6 + ds 11 +BoxMon2OT: ; afb1 + ds 11 +BoxMon3OT: ; afbc + ds 11 +BoxMon4OT: ; afc7 + ds 11 +BoxMon5OT: ; afd2 + ds 11 +BoxMon6OT: ; afdd + ds 11 +BoxMon7OT: ; afe8 + ds 11 +BoxMon8OT: ; aff3 + ds 11 +BoxMon9OT: ; affe + ds 11 +BoxMon10OT: ; b009 + ds 11 +BoxMon11OT: ; b014 + ds 11 +BoxMon12OT: ; b01f + ds 11 +BoxMon13OT: ; b02a + ds 11 +BoxMon14OT: ; b035 + ds 11 +BoxMon15OT: ; b040 + ds 11 +BoxMon16OT: ; b04b + ds 11 +BoxMon17OT: ; b056 + ds 11 +BoxMon18OT: ; b061 + ds 11 +BoxMon19OT: ; b06c + ds 11 +BoxMon20OT: ; b077 + ds 11 + +BoxMonNicknames: +BoxMon1Nickname: ; b082 + ds 11 +BoxMon2Nickname: ; b08d + ds 11 +BoxMon3Nickname: ; b098 + ds 11 +BoxMon4Nickname: ; b0a3 + ds 11 +BoxMon5Nickname: ; b0ae + ds 11 +BoxMon6Nickname: ; b0b9 + ds 11 +BoxMon7Nickname: ; b0c4 + ds 11 +BoxMon8Nickname: ; b0cf + ds 11 +BoxMon9Nickname: ; b0da + ds 11 +BoxMon10Nickname: ; b0e5 + ds 11 +BoxMon11Nickname: ; b0f0 + ds 11 +BoxMon12Nickname: ; b0fb + ds 11 +BoxMon13Nickname: ; b106 + ds 11 +BoxMon14Nickname: ; b111 + ds 11 +BoxMon15Nickname: ; b11c + ds 11 +BoxMon16Nickname: ; b127 + ds 11 +BoxMon17Nickname: ; b132 + ds 11 +BoxMon18Nickname: ; b13d + ds 11 +BoxMon19Nickname: ; b148 + ds 11 +BoxMon20Nickname: ; b153 + ds 11 +BoxMonNicknamesEnd +