summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorxCrystal <rgr.crystal@gmail.com>2019-07-22 22:46:14 +0200
committerxCrystal <rgr.crystal@gmail.com>2019-07-22 22:46:14 +0200
commita0bb31e3ad38896ae69ff1500346e3f732284773 (patch)
treec00a48b275009c84eb273054631aef56f90a492f /src
parent0e9c5aafbdf439f9e32fd4b8b484a9c7d188db5e (diff)
More duel related disassembly and documentation
Diffstat (limited to 'src')
-rw-r--r--src/constants/duel_constants.asm10
-rw-r--r--src/engine/bank01.asm152
-rw-r--r--src/engine/bank07.asm2
-rw-r--r--src/engine/effect_functions.asm77
-rw-r--r--src/engine/home.asm63
-rw-r--r--src/wram.asm13
6 files changed, 254 insertions, 63 deletions
diff --git a/src/constants/duel_constants.asm b/src/constants/duel_constants.asm
index dd448aa..0f80a73 100644
--- a/src/constants/duel_constants.asm
+++ b/src/constants/duel_constants.asm
@@ -13,9 +13,10 @@ DUELTYPE_PRACTICE EQU $80
; for normal duels (vs AI), wDuelType is $80 + [wOpponentDeckID]
; wDuelFinished constants
-TURN_PLAYER_WON EQU $1
-TURN_PLAYER_LOST EQU $2
-TURN_PLAYER_TIED EQU $3
+DUEL_NOT_FINISHED EQU $0
+TURN_PLAYER_WON EQU $1
+TURN_PLAYER_LOST EQU $2
+TURN_PLAYER_TIED EQU $3
; wDuelResult constants
DUEL_WIN EQU $0
@@ -244,3 +245,6 @@ SELECT_CHECK EQU $02
const PRACTICEDUEL_REPEAT_INSTRUCTIONS
const PRACTICEDUEL_PLAY_STARYU_FROM_BENCH
const PRACTICEDUEL_REPLACE_KNOCKED_OUT_POKEMON
+
+; wAnimationQueue length
+ANIMATION_QUEUE_LENGTH EQU 7
diff --git a/src/engine/bank01.asm b/src/engine/bank01.asm
index f0ac3ae..a0d736c 100644
--- a/src/engine/bank01.asm
+++ b/src/engine/bank01.asm
@@ -1545,7 +1545,7 @@ Func_49a8: ; 49a8 (1:49a8)
call DoFrame
call CheckSkipDelayAllowed
jr c, .asm_49c6
- call Func_3b52
+ call CheckAnyAnimationPlaying
jr c, .asm_49b9
.asm_49c6
call Func_3b31
@@ -2258,7 +2258,7 @@ Func_4e98: ; 4e98 (1:4e98)
call DoFrame
call CheckSkipDelayAllowed
jr c, .asm_4edd
- call Func_3b52
+ call CheckAnyAnimationPlaying
jr c, .asm_4ed0
.asm_4edd
call Func_3b31
@@ -2277,7 +2277,7 @@ Func_4e98: ; 4e98 (1:4e98)
call DoFrame
call CheckSkipDelayAllowed
jr c, .asm_4f28
- call Func_3b52
+ call CheckAnyAnimationPlaying
jr c, .asm_4ef4
ld hl, wNumCardsBeingDrawn
inc [hl]
@@ -2342,7 +2342,7 @@ Func_4f2d: ; 4f2d (1:4f2d)
call DoFrame
call CheckSkipDelayAllowed
jr c, .asm_4f7d
- call Func_3b52
+ call CheckAnyAnimationPlaying
jr c, .asm_4f70
.asm_4f7d
call Func_3b31
@@ -6496,7 +6496,7 @@ OppActionTable: ; 695e (1:695e)
dw OppAction_ExecuteTrainerCardEffectCommands
dw OppAction_BeginUseAttack
dw OppAction_UseAttack
- dw OppAction_DealAttackDamage
+ dw OppAction_PlayAttackAnimation_DealAttackDamage
dw OppAction_DrawCard
dw OppAction_UsePokemonPower
dw OppAction_ExecutePokemonPowerEffect
@@ -6679,15 +6679,15 @@ OppAction_UseAttack: ; 6a8c (1:6a8c)
ld [wSkipDuelistIsThinkingDelay], a
ret
.confusion_damage
- call DealConfusionDamageToSelf
+ call HandleConfusionDamageToSelf
; end the turn if dealing damage to self due to confusion
ld a, 1
ld [wOpponentTurnEnded], a
ret
; 0x6ab1
-OppAction_DealAttackDamage: ; 6ab1 (1:6ab1)
- call DealAttackDamage
+OppAction_PlayAttackAnimation_DealAttackDamage: ; 6ab1 (1:6ab1)
+ call PlayAttackAnimation_DealAttackDamage
ld a, 1
ld [wOpponentTurnEnded], a
ret
@@ -7016,7 +7016,7 @@ Func_6cab: ; 6cab (1:6cab)
call Func_3b6a
.asm_6cd8
call DoFrame
- call Func_3b52
+ call CheckAnyAnimationPlaying
jr c, .asm_6cd8
call Func_6c7e.asm_6c98
ret
@@ -7211,7 +7211,102 @@ ApplyStatusConditionToArenaPokemon: ; 6e38 (1:6e38)
; 0x6e49
Func_6e49: ; 6e49 (1:6e49)
- INCROM $6e49, $700a
+ call HandleDestinyBondSubstatus
+ call ClearDamageReductionSubstatus2OfKnockedOutPokemon
+ xor a
+ ld [wcce8], a
+ call SwapTurn
+ call Func_6ef6
+ call SwapTurn
+ ld a, [wcce8]
+ or a
+ jr z, .asm_6e86
+ call $6ff7
+ jr c, .asm_6e86
+ call $6fc7
+ ld c, a
+ call SwapTurn
+ call CountPrizes
+ call SwapTurn
+ dec a
+ cp c
+ jr c, .asm_6e86
+ ld a, c
+ call SwapTurn
+ call DrawPrizes
+ call SwapTurn
+ ld a, $01
+ jr .asm_6ecc
+.asm_6e86
+ call Func_6ef6
+ ld a, [wcce8]
+ cp $01
+ jr nz, .asm_6e9f
+ call SwapTurn
+ call $6ff7
+ call SwapTurn
+ jr c, .asm_6e9f
+ ld a, $02
+ jr .asm_6ecc
+.asm_6e9f
+ call SwapTurn
+ call $6eff
+ call SwapTurn
+ call $6eff
+ ld a, [wcce8]
+ or a
+ jr nz, .asm_6ec4
+ xor a
+.asm_6eb2
+ push af
+ call $6f08
+ call SwapTurn
+ call $6f08
+ call SwapTurn
+ call ShiftAllPokemonToFirstPlayAreaSlots
+ pop af
+ ret
+.asm_6ec4
+ ld e, a
+ ld d, $00
+ ld hl, Data_6ed2
+ add hl, de
+ ld a, [hl]
+.asm_6ecc
+ ld [wDuelFinished], a
+ scf
+ jr .asm_6eb2
+; 0x6ed2
+
+Data_6ed2: ; 6ed2 (1:6ed2)
+ db DUEL_NOT_FINISHED, TURN_PLAYER_LOST, TURN_PLAYER_WON, TURN_PLAYER_TIED
+ db TURN_PLAYER_LOST, TURN_PLAYER_LOST, TURN_PLAYER_TIED, TURN_PLAYER_LOST
+ db TURN_PLAYER_WON, TURN_PLAYER_TIED, TURN_PLAYER_WON, TURN_PLAYER_WON
+ db TURN_PLAYER_TIED, TURN_PLAYER_LOST, TURN_PLAYER_WON, TURN_PLAYER_TIED
+
+; clears SUBSTATUS2_REDUCE_BY_20, SUBSTATUS2_POUNCE, SUBSTATUS2_GROWL,
+; SUBSTATUS2_TAIL_WAG, and SUBSTATUS2_LEER for each arena Pokemon with 0 HP
+ClearDamageReductionSubstatus2OfKnockedOutPokemon: ; 6ee2 (1:6ee2)
+ call SwapTurn
+ call .clear
+ call SwapTurn
+.clear
+ ld a, DUELVARS_ARENA_CARD_HP
+ call GetNonTurnDuelistVariable
+ or a
+ ret nz
+ call ClearDamageReductionSubstatus2
+ ret
+; 0x6ef6
+
+Func_6ef6: ; 6ef6 (1:6ef6)
+ call $6fa5
+ ld hl, wcce8
+ rl [hl]
+ ret
+; 0x6eff
+
+ INCROM $6eff, $700a
; print one of the "There was no effect from" texts depending
; on the value at wNoEffectFromStatus (NO_STATUS or a status condition constant)
@@ -7391,15 +7486,17 @@ PrizeBitmasks: ; 715a (1:715a)
db %0, %1, %11, %111, %1111, %11111, %111111
; 0x7161
-Func_7161: ; 7161 (1:7161)
+; update the turn holder's DUELVARS_PRIZES following that duelist
+; drawing a number of prizes equal to register a
+DrawPrizes: ; 7161 (1:7161)
or a
ret z
ld c, a
call CountPrizes
sub c
- jr nc, .asm_716b
+ jr nc, .no_underflow
xor a
-.asm_716b
+.no_underflow
ld c, a
ld b, $00
ld hl, PrizeBitmasks
@@ -7555,7 +7652,7 @@ _TossCoin: ; 71ad (1:71ad)
.asm_725e
push de
call DoFrame
- call Func_3b52
+ call CheckAnyAnimationPlaying
pop de
jr c, .asm_725e
ld a, e
@@ -7709,18 +7806,21 @@ Func_741a: ; 741a (1:741a)
xor a
ld [wd4b0], a
push hl
- farcall $6, $4f9c
+ farcall Func_006_4f9c
pop hl
jr .loop
.done
ret
; 0x7469
-Func_7469: ; 7469 (1:7469)
+; this is a simple version of PlayAttackAnimation_DealAttackDamage that doesn't
+; take into account status conditions, damage modifiers, etc, for damage calculation.
+; used for confusion damage to self and for damage to benched Pokemon, for example
+PlayAttackAnimation_DealAttackDamageSimple: ; 7469 (1:7469)
push hl
push de
- call Func_7494
- call Func_7484
+ call PlayMoveAnimation
+ call WaitMoveAnimation
pop de
pop hl
call SubstractHP
@@ -7735,20 +7835,26 @@ Func_7469: ; 7469 (1:7469)
ret
; 0x7484
-Func_7484: ; 7484 (1:7484)
+; if [wLoadedMoveAnimation] != 0, wait until the animation is over
+WaitMoveAnimation: ; 7484 (1:7484)
ld a, [wLoadedMoveAnimation]
or a
ret z
push de
-.asm_748a
+.anim_loop
call DoFrame
- call Func_3b52
- jr c, .asm_748a
+ call CheckAnyAnimationPlaying
+ jr c, .anim_loop
pop de
ret
; 0x7494
-Func_7494: ; 7494 (1:7494)
+; play move animation
+; input:
+; - [wLoadedMoveAnimation]: animation to play
+; - de: damage dealt by the move (to display the animation with the number)
+; - c: a wDamageEffectiveness constant (to print WEAK or RESIST if necessary)
+PlayMoveAnimation: ; 7494 (1:7494)
ldh a, [hWhoseTurn]
push af
push hl
diff --git a/src/engine/bank07.asm b/src/engine/bank07.asm
index a79f27a..7c53b96 100644
--- a/src/engine/bank07.asm
+++ b/src/engine/bank07.asm
@@ -384,7 +384,7 @@ Func_1cb18: ; 1cb18 (7:4b18)
ld a, [wd42a]
cp $ff
call nz, $4cd4
- ld hl, wd423
+ ld hl, wAnimationQueue
ld c, $07
.asm_1cb3b
push bc
diff --git a/src/engine/effect_functions.asm b/src/engine/effect_functions.asm
index ab7bd38..116d545 100644
--- a/src/engine/effect_functions.asm
+++ b/src/engine/effect_functions.asm
@@ -109,7 +109,7 @@ Func_2c08a: ; 2c08a (b:408a)
Func_2c08c:
push de
push af
- ld a, $11
+ ld a, OPPACTION_TOSS_COIN_A_TIMES
call SetOppAction_SerialSendDuelData
pop af
pop de
@@ -130,7 +130,39 @@ SetWasUnsuccessful: ; 2c0a2 (b:40a2)
ret
; 0x2c0a8
- INCROM $2c0a8, $2c0d4
+Func_2c0a8: ; 2c0a8 (b:40a8)
+ ldh a, [hTemp_ffa0]
+ push af
+ ldh a, [hWhoseTurn]
+ ldh [hTemp_ffa0], a
+ ld a, OPPACTION_6B30
+ call SetOppAction_SerialSendDuelData
+ bank1call Func_4f2d
+ ld c, a
+ pop af
+ ldh [hTemp_ffa0], a
+ ld a, c
+ ret
+; 0x2c0bd
+
+Func_2c0bd: ; 2c0bd (b:40bd)
+ call ExchangeRNG
+ bank1call Func_4f2d
+ call ShuffleDeck
+ ret
+; 0x2c0c7
+
+Func_2c0c7: ; 2c0c7 (b:40c7)
+ ld a, DUELVARS_DUELIST_TYPE
+ call GetTurnDuelistVariable
+ cp DUELIST_TYPE_PLAYER
+ jr z, .player
+ or a
+ ret
+.player
+ scf
+ ret
+; 0x2c0d4
; Sets some flags for AI use
; if target poisoned
@@ -184,7 +216,46 @@ Func_2c0fb: ; 2c0fb (b:40fb)
ret
; 0x2c10b
- INCROM $2c10b, $2c140
+Func_2c10b: ; 2c10b (b:410b)
+ ldh [hTempPlayAreaLocation_ff9d], a
+ bank1call Func_61a1
+ bank1call PrintPlayAreaCardList_EnableLCD
+ bank1call Func_6194
+ ret
+; 0x2c117
+
+; deal damage to all the turn holder's benched Pokemon
+; input: a = amount of damage to deal to each Pokemon
+DealDamageToAllBenchedPokemon: ; 2c117 (b:4117)
+ ld e, a
+ ld d, $00
+ ld a, DUELVARS_NUMBER_OF_POKEMON_IN_PLAY_AREA
+ call GetTurnDuelistVariable
+ ld c, a
+ ld b, PLAY_AREA_ARENA
+ jr .skip_to_bench
+.loop
+ push bc
+ call DealDamageToPlayAreaPokemon
+ pop bc
+.skip_to_bench
+ inc b
+ dec c
+ jr nz, .loop
+ ret
+; 0x2c12e
+
+Func_2c12e: ; 2c12e (b:412e)
+ ld [wLoadedMoveAnimation], a
+ ldh a, [hTempPlayAreaLocation_ff9d]
+ ld b, a
+ ld c, $0 ; neither WEAKNESS nor RESISTANCE
+ ldh a, [hWhoseTurn]
+ ld h, a
+ bank1call PlayMoveAnimation
+ bank1call WaitMoveAnimation
+ ret
+; 0x2c140
; apply a status condition of type 1 identified by register a to the target
ApplySubstatus1ToDefendingCard: ; 2c140 (b:4140)
diff --git a/src/engine/home.asm b/src/engine/home.asm
index 5271270..e6247c9 100644
--- a/src/engine/home.asm
+++ b/src/engine/home.asm
@@ -3290,8 +3290,8 @@ MoveDiscardPileCardToHand: ; 1182 (0:1182)
ret
; 0x11a5
-; return in the z flag whether turn holder's prize a (0-7) has been taken or not
-; z: taken, nz: not taken
+; return in the z flag whether turn holder's prize a (0-7) has been drawn or not
+; z: drawn, nz: not drawn
CheckPrizeTaken: ; 11a5 (0:11a5)
ld e, a
ld d, 0
@@ -4293,9 +4293,9 @@ GetNonTurnDuelistVariable: ; 1611 (0:1611)
ldh a, [hWhoseTurn]
ld h, OPPONENT_TURN
cp PLAYER_TURN
- jr z, .asm_161c
+ jr z, .ok
ld h, PLAYER_TURN
-.asm_161c
+.ok
ld a, [hl]
ret
; 0x161e
@@ -4498,7 +4498,7 @@ UseAttackOrPokemonPower: ; 1730 (0:1730)
ld a, EFFECTCMDTYPE_DISCARD_ENERGY
call TryExecuteEffectCommandFunction
call CheckSelfConfusionDamage
- jp c, DealConfusionDamageToSelf
+ jp c, HandleConfusionDamageToSelf
call DrawDuelMainScene_PrintPokemonsAttackText
call WaitForWideTextBoxInput
call ExchangeRNG
@@ -4508,7 +4508,7 @@ UseAttackOrPokemonPower: ; 1730 (0:1730)
call SetOppAction_SerialSendDuelData
; fallthrough
-DealAttackDamage: ; 179a (0:179a)
+PlayAttackAnimation_DealAttackDamage: ; 179a (0:179a)
call Func_7415
ld a, [wLoadedMoveCategory]
and RESIDUAL
@@ -4534,9 +4534,9 @@ DealAttackDamage: ; 179a (0:179a)
call GetNonTurnDuelistVariable
push de
push hl
- call Func_7494
+ call PlayMoveAnimation
call Func_741a
- call Func_7484
+ call WaitMoveAnimation
pop hl
pop de
call SubstractHP
@@ -4579,9 +4579,11 @@ DisplayUsePokemonPowerScreen_WaitForInput: ; 1819 (0:1819)
push hl
call DisplayUsePokemonPowerScreen
pop hl
+; fallthrough
DrawWideTextBox_WaitForInput_ReturnCarry: ; 181e (0:181e)
call DrawWideTextBox_WaitForInput
+; fallthrough
ReturnCarry: ; 1821 (0:1821)
scf
@@ -4592,7 +4594,9 @@ ClearNonTurnTemporaryDuelvars_ResetCarry: ; 1823 (0:1823)
or a
ret
-DealConfusionDamageToSelf: ; 1828 (0:1828)
+; called when attacker deals damage to itself due to confusion
+; display the corresponding animation and deal damage to self
+HandleConfusionDamageToSelf: ; 1828 (0:1828)
bank1call DrawDuelMainScene
ld a, 1
ld [wIsDamageToSelf], a
@@ -4601,7 +4605,7 @@ DealConfusionDamageToSelf: ; 1828 (0:1828)
ld a, $75
ld [wLoadedMoveAnimation], a
ld a, 20 ; damage
- call Func_195c
+ call DealConfusionDamageToSelf
call Func_1bb4
call Func_6e49
bank1call ClearNonTurnTemporaryDuelvars
@@ -4775,8 +4779,7 @@ Func_1955: ; 1955 (0:1955)
pop af
; fallthrough
-; this function appears to handle dealing damage to self due to confusion
-Func_195c: ; 195c (0:195c)
+DealConfusionDamageToSelf: ; 195c (0:195c)
ld hl, wDamage
ld [hli], a
ld [hl], 0
@@ -4789,13 +4792,13 @@ Func_195c: ; 195c (0:195c)
push af
ld a, [wTempTurnDuelistCardID]
ld [wTempNonTurnDuelistCardID], a
- bank1call ApplyDamageModifiers_DamageToSelf ; switch to bank 1, but call a home func
+ bank1call ApplyDamageModifiers_DamageToSelf ; this is at bank 0
ld a, [wDamageEffectiveness]
ld c, a
ld b, $0
ld a, DUELVARS_ARENA_CARD_HP
call GetTurnDuelistVariable
- bank1call Func_7469
+ bank1call PlayAttackAnimation_DealAttackDamageSimple
call PrintKnockedOutIfHLZero
pop af
ld [wTempNonTurnDuelistCardID], a
@@ -5042,11 +5045,11 @@ PrintKnockedOut: ; 1ad3 (0:1ad3)
ret
; 0x1af3
-; seems to be a function to deal damage to a card, but can be used
-; to deal damage to a benched Pokemon.
+; deal damage to turn holder's Pokemon card at play area location at b (PLAY_AREA_*).
+; damage to deal is given in de.
; shows the defending player's play area screen when dealing the damage
-; instead of the main duel interface, and has a fixed move animation
-Func_1af3: ; 1af3 (0:1af3)
+; instead of the main duel interface, and has a fixed move animation.
+DealDamageToPlayAreaPokemon: ; 1af3 (0:1af3)
ld a, $78
ld [wLoadedMoveAnimation], a
ld a, b
@@ -5110,7 +5113,7 @@ Func_1af3: ; 1af3 (0:1af3)
ld b, a
or a ; cp PLAY_AREA_ARENA
jr nz, .benched
- ; add damage at de to [wDealtDamage]
+ ; if arena Pokemon, add damage at de to [wDealtDamage]
ld hl, wDealtDamage
ld a, e
add [hl]
@@ -5123,7 +5126,7 @@ Func_1af3: ; 1af3 (0:1af3)
add DUELVARS_ARENA_CARD_HP
call GetTurnDuelistVariable
push af
- bank1call Func_7469
+ bank1call PlayAttackAnimation_DealAttackDamageSimple
pop af
or a
jr z, .skip_knocked_out
@@ -10211,8 +10214,10 @@ IsPrehistoricPowerActive: ; 35b7 (0:35b7)
ret
; 0x35c7
-; clears some SUBSTATUS2 conditions from the turn holder's active Pokemon
-Func_35c7: ; 35c7 (0:35c7)
+; clears some SUBSTATUS2 conditions from the turn holder's active Pokemon.
+; more specifically, those conditions that reduce the damage from an attack
+; or prevent the opposing Pokemon from attacking the substatus condition inducer.
+ClearDamageReductionSubstatus2: ; 35c7 (0:35c7)
ld a, DUELVARS_ARENA_CARD_SUBSTATUS2
call GetTurnDuelistVariable
or a
@@ -11215,19 +11220,21 @@ Func_3b31: ; 3b31 (0:3b31)
call BankswitchROM
ret
-Func_3b52: ; 3b52 (0:3b52)
+; return nc if wd42a, wd4c0, and wAnimationQueue[] are all equal to $ff
+; nc means no animation is playing (or animation(s) has/have ended)
+CheckAnyAnimationPlaying: ; 3b52 (0:3b52)
push hl
push bc
ld a, [wd42a]
ld hl, wd4c0
and [hl]
- ld hl, wd423
- ld c, $7
-.asm_3b60
+ ld hl, wAnimationQueue
+ ld c, ANIMATION_QUEUE_LENGTH
+.loop
and [hl]
inc hl
dec c
- jr nz, .asm_3b60
+ jr nz, .loop
cp $ff
pop bc
pop hl
@@ -11250,7 +11257,7 @@ Func_3b6a: ; 3b6a (0:3b6a)
ld a, [wd4ac]
cp [hl]
jr nz, .asm_3b90
- call Func_3b52
+ call CheckAnyAnimationPlaying
jr nc, .asm_3b95
.asm_3b90
call $4a31
diff --git a/src/wram.asm b/src/wram.asm
index 4210cf7..38ebd4a 100644
--- a/src/wram.asm
+++ b/src/wram.asm
@@ -161,7 +161,7 @@ wPlayerArenaCardChangedResistance:: ; c2ea
wPlayerArenaCardSubstatus3:: ; c2eb
ds $1
-; Each bit represents a prize (1 = not taken ; 0 = taken)
+; each bit represents a prize that this duelist can draw (1 = not drawn ; 0 = drawn)
wPlayerPrizes:: ; c2ec
ds $1
@@ -982,6 +982,7 @@ wIsDamageToSelf:: ; cce6
wcce7:: ; cce7
ds $1
+wcce8:: ; cce8
ds $1
; used in CopyDeckData
@@ -1299,8 +1300,7 @@ wPrizeCardCursorPosition::
wce53:: ; ce53
ds $2
-; same as wDuelInitialPrizes but
-; with upper 2 bits set
+; same as wDuelInitialPrizes but with upper 2 bits set
wDuelInitialPrizesUpperBitsSet:: ; ce55
ds $1
@@ -1990,8 +1990,11 @@ wd421:: ; d421
wd422:: ; d422
ds $1
-wd423:: ; d423
- ds $7
+; holds a list of animations to play
+; as long as any of the slot isn't $ff, there's something to play
+; it may actually not be a queue
+wAnimationQueue:: ; d423
+ ds ANIMATION_QUEUE_LENGTH
wd42a:: ; d42a
ds $1