Renaming sections, further dissolving main.asm

This commit is contained in:
PikalaxALT 2015-11-28 15:13:40 -05:00
parent 43903f543b
commit 8612a4a531
44 changed files with 1622 additions and 1594 deletions

@ -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

222
battle/ai/move.asm Executable file

@ -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

@ -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

@ -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

@ -1,4 +1,4 @@
SlideBattlePics: ; 4e980
BattleIntroSlidingPics: ; 4e980
ld a, [rSVBK]
push af
ld a, $5

@ -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

@ -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)

@ -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

@ -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

@ -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]

@ -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

@ -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

@ -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]

257
engine/learn.asm Executable file

@ -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

@ -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

196
engine/math.asm Executable file

@ -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

@ -670,7 +670,7 @@ InitPartyMenuGFX: ; 503e0
pop bc
dec c
jr nz, .loop
callab Function8cf69
callab PlaySpriteAnimations
ret
; 50405

@ -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

@ -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

@ -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

Some files were not shown because too many files have changed in this diff Show More