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