summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/engine/bank01.asm482
-rw-r--r--src/engine/bank05.asm4
-rw-r--r--src/engine/bank07.asm48
-rw-r--r--src/engine/home.asm26
-rw-r--r--src/hram.asm4
-rw-r--r--src/sram.asm88
-rw-r--r--src/text/text1.asm4
-rw-r--r--src/text/text2.asm2
-rw-r--r--src/text/text_offsets.asm12
-rw-r--r--src/wram.asm28
10 files changed, 593 insertions, 105 deletions
diff --git a/src/engine/bank01.asm b/src/engine/bank01.asm
index 260801f..c01c433 100644
--- a/src/engine/bank01.asm
+++ b/src/engine/bank01.asm
@@ -1,5 +1,5 @@
; continuation of Bank0 Start
-; supposed to be the main loop, but the game never returns from _GameLoop anyway
+; meant as the main loop, but the game never returns from _GameLoop anyway
GameLoop: ; 4000 (1:4000)
di
ld sp, $e000
@@ -22,7 +22,7 @@ GameLoop: ; 4000 (1:4000)
farcall _GameLoop
jr GameLoop
.ask_erase_backup_ram
- call Func_405a
+ call SetupResetBackUpRamScreen
call EmptyScreen
ldtx hl, ResetBackUpRamText
call YesOrNoMenuWithText
@@ -41,7 +41,8 @@ Func_4050: ; 4050 (1:4050)
ld [wUppercaseHalfWidthLetters], a
ret
-Func_405a: ; 405a (1:405a)
+; basic setup to be able to print the ResetBackUpRamText in an empty screen
+SetupResetBackUpRamScreen: ; 405a (1:405a)
xor a ; SYM_SPACE
ld [wTileMapFill], a
call DisableLCD
@@ -58,10 +59,10 @@ CommentedOut_406e: ; 406e (1:406e)
; try to resume a saved duel from the main menu
TryContinueDuel: ; 406f (1:406f)
- call Func_420b
- call $66e9
+ call SetupDuel
+ call Func_66e9
ldtx hl, BackUpIsBrokenText
- jr c, FailedToContinueDuel
+ jr c, HandleFailedToContinueDuel
; fallthrough
_ContinueDuel: ; 407a (1:407a)
@@ -76,10 +77,10 @@ _ContinueDuel: ; 407a (1:407a)
xor a
ld [wDuelFinished], a
call DuelMainInterface
- jp MainDuelLoop.begin_turn
+ jp MainDuelLoop.between_turns
; 0x4097
-FailedToContinueDuel: ; 4097 (1:4097)
+HandleFailedToContinueDuel: ; 4097 (1:4097)
call DrawWideTextBox_WaitForInput
call ResetSerial
scf
@@ -99,8 +100,9 @@ StartDuel: ; 409f (1:409f)
call SwapTurn
call LoadOpponentDeck
call SwapTurn
- jr .continue
+ jr .decks_loaded
+; unreferenced?
ld a, MUSIC_DUEL_THEME_1
ld [wDuelTheme], a
ld hl, wOpponentName
@@ -109,7 +111,7 @@ StartDuel: ; 409f (1:409f)
ld [hl], a
ld [wIsPracticeDuel], a
-.continue
+.decks_loaded
ld hl, sp+$0
ld a, l
ld [wDuelReturnAddress], a
@@ -117,10 +119,10 @@ StartDuel: ; 409f (1:409f)
ld [wDuelReturnAddress + 1], a
xor a
ld [wCurrentDuelMenuItem], a
- call Func_420b
+ call SetupDuel
ld a, [wcc18]
ld [wDuelInitialPrizes], a
- call $70aa
+ call Func_70aa
ld a, [wDuelTheme]
call PlaySong
call Func_4b60
@@ -132,16 +134,16 @@ MainDuelLoop ; 40ee (1:40ee)
xor a
ld [wCurrentDuelMenuItem], a
call UpdateSubstatusConditions_StartOfTurn
- call $54c8
+ call DisplayDuelistsTurnScreen
call HandleTurn
-.begin_turn
+.between_turns
call ExchangeRNG
ld a, [wDuelFinished]
or a
jr nz, .duel_finished
call UpdateSubstatusConditions_EndOfTurn
- call $6baf
+ call HandleBetweenTurnsEvents
call Func_3b31
call ExchangeRNG
ld a, [wDuelFinished]
@@ -251,7 +253,7 @@ MainDuelLoop ; 40ee (1:40ee)
call DrawWideTextBox_WaitForInput
ld a, 1
ld [wDuelInitialPrizes], a
- call $70aa
+ call Func_70aa
ld a, [wDuelType]
cp DUELTYPE_LINK
jr z, .link_duel
@@ -276,7 +278,8 @@ MainDuelLoop ; 40ee (1:40ee)
ret
; 0x420b
-Func_420b: ; 420b (1:420b)
+; empty the screen, and setup text and graphics for a duel
+SetupDuel: ; 420b (1:420b)
xor a ; SYM_SPACE
ld [wTileMapFill], a
call ZeroObjectPositionsAndToggleOAMCopy
@@ -351,8 +354,8 @@ DuelMainInterface: ; 426d (1:426d)
call DrawWideTextBox_PrintTextNoDelay
call Func_2bbf
ld a, $ff
- ld [wcc11], a
- ld [wcc10], a
+ ld [wPlayerAttackingCardIndex], a
+ ld [wPlayerAttackingMoveIndex], a
ret
PrintDuelMenu: ; 4295 (1:4295)
@@ -2373,7 +2376,7 @@ Func_5284: ; 5284 (1:5284)
call Func_52bc
ld a, $02
call BankswitchSRAM
- ld de, sCurrentDuelData
+ ld de, sCurrentDuel
call $66ff
xor a
call BankswitchSRAM
@@ -2411,7 +2414,30 @@ Func_52bc: ; 52bc (1:52bc)
ret
; 0x52c5
- INCROM $52c5, $54e9
+ INCROM $52c5, $54c8
+
+; display BOXMSG_PLAYERS_TURN or BOXMSG_OPPONENTS_TURN and print
+; DuelistsTurnText in a textbox. also call ExchangeRNG.
+DisplayDuelistsTurnScreen: ; 54c8 (1:54c8)
+ call EmptyScreen
+ ld c, BOXMSG_PLAYERS_TURN
+ ldh a, [hWhoseTurn]
+ cp PLAYER_TURN
+ jr z, .got_turn
+ inc c ; BOXMSG_OPPONENTS_TURN
+.got_turn
+ ld a, c
+ call DrawDuelBoxMessage
+ ldtx hl, DuelistsTurnText
+ call DrawWideTextBox_WaitForInput
+ call ExchangeRNG
+ ret
+; 0x54e2
+
+Unknown_54e2: ; 54e2 (1:54e2)
+; ???
+ db $00, $0c, $06, $0f, $00, $00, $00
+; 0x54e9
DuelMenuData: ; 54e9 (1:54e9)
; x, y, text id
@@ -4141,12 +4167,12 @@ PrintUsedTrainerCardDescription: ; 6673 (1:6673)
ret
; 0x669d
-; save data of the current duel to sCurrentDuelData
+; save data of the current duel to sCurrentDuel
; byte 0 is $01, bytes 1 and 2 are the checksum, byte 3 is [wDuelType]
; next $33a bytes come from DuelDataToSave
SaveDuelData: ; 669d (1:669d)
farcall CommentedOut_1a6cc
- ld de, sCurrentDuelData
+ ld de, sCurrentDuel
; fallthrough
; save data of the current duel to de (in SRAM)
@@ -4162,14 +4188,14 @@ SaveDuelDataToDE: ; 66a4 (1:66a4)
ld hl, DuelDataToSave
push de
.save_duel_data_loop
- ; start copying data to de = sCurrentDuelData + 4
+ ; start copying data to de = sCurrentDuelData + $1
ld c, [hl]
inc hl
ld b, [hl]
inc hl
ld a, c
or b
- jr z, .asm_66c7
+ jr z, .data_done
push hl
push bc
ld c, [hl]
@@ -4182,9 +4208,9 @@ SaveDuelDataToDE: ; 66a4 (1:66a4)
inc hl
inc hl
jr .save_duel_data_loop
-.asm_66c7
+.data_done
pop hl
- ; hl = sCurrentDuelData + 4
+ ; save a checksum to hl = sCurrentDuelData + $1
lb de, $23, $45
ld bc, $334 ; misses last 6 bytes to calculate checksum
.checksum_loop
@@ -4200,18 +4226,70 @@ SaveDuelDataToDE: ; 66a4 (1:66a4)
jr nz, .checksum_loop
pop hl
ld a, $01
- ld [hli], a ; sCurrentDuelData
- ld [hl], e ; sCurrentDuelData + 1
+ ld [hli], a ; sCurrentDuel
+ ld [hl], e ; sCurrentDuelChecksum
inc hl
- ld [hl], d ; sCurrentDuelData + 2
+ ld [hl], d ; sCurrentDuelChecksum
inc hl
ld a, [wDuelType]
- ld [hl], a ; sCurrentDuelData + 3
+ ld [hl], a ; sCurrentDuelData
call DisableSRAM
ret
; 0x66e9
- INCROM $66e9, $6729
+Func_66e9: ; 66e9 (1:66e9)
+ ld hl, sCurrentDuel
+ call ValidateSavedDuelData
+ ret c
+ ld de, sCurrentDuel
+ call LoadSavedDuelData
+ call Func_3a45
+ ret nc
+ call Func_3a40
+ or a
+ ret
+; 0x66ff
+
+; load the data saved in sCurrentDuelData to WRAM according to the distribution
+; of DuelDataToSave. assumes saved data exists and that the checksum is valid.
+LoadSavedDuelData: ; 66ff (1:66ff)
+ call EnableSRAM
+ inc de
+ inc de
+ inc de
+ inc de
+ ld hl, DuelDataToSave
+.next_block
+ ld c, [hl]
+ inc hl
+ ld b, [hl]
+ inc hl
+ ld a, c
+ or b
+ jr z, .done
+ push hl
+ push bc
+ ld c, [hl]
+ inc hl
+ ld b, [hl]
+ inc hl
+ pop hl
+.copy_loop
+ ld a, [de]
+ inc de
+ ld [hli], a
+ dec bc
+ ld a, c
+ or b
+ jr nz, .copy_loop
+ pop hl
+ inc hl
+ inc hl
+ jr .next_block
+.done
+ call DisableSRAM
+ ret
+; 0x6729
DuelDataToSave: ; 6729 (1:6729)
; dw address, number_of_bytes_to_copy
@@ -4225,13 +4303,65 @@ DuelDataToSave: ; 6729 (1:6729)
dw $0000
; 0x6747
- INCROM $6747, $6785
+; return carry if there is no data saved at sCurrentDuel or if the checksum isn't correct,
+; or if the value saved from wDuelType is DUELTYPE_LINK
+ValidateSavedNonLinkDuelData: ; 6747 (1:6747)
+ call EnableSRAM
+ ld hl, sCurrentDuel
+ ld a, [sCurrentDuelData]
+ call DisableSRAM
+ cp DUELTYPE_LINK
+ jr nz, ValidateSavedDuelData
+ ; ignore any saved data of a link duel
+ scf
+ ret
+
+; return carry if there is no data saved at sCurrentDuel or if the checksum isn't correct
+; input: hl = sCurrentDuel
+ValidateSavedDuelData: ; 6759 (1:6759)
+ call EnableSRAM
+ push de
+ ld a, [hli]
+ or a
+ jr z, .no_saved_data
+ lb de, $23, $45
+ ld bc, $334
+ ld a, [hl]
+ sub e
+ ld e, a
+ inc hl
+ ld a, [hl]
+ xor d
+ ld d, a
+ inc hl
+ inc hl
+.loop
+ ld a, [hl]
+ add e
+ ld e, a
+ ld a, [hli]
+ xor d
+ ld d, a
+ dec bc
+ ld a, c
+ or b
+ jr nz, .loop
+ ld a, e
+ or d
+ jr z, .ok
+.no_saved_data
+ scf
+.ok
+ call DisableSRAM
+ pop de
+ ret
+; 0x6785
; discard data of a duel that was saved by SaveDuelData, by setting the first byte
-; of sCurrentDuelData to $00, and zeroing the checksum (next two bytes)
+; of sCurrentDuel to $00, and zeroing the checksum (next two bytes)
DiscardSavedDuelData: ; 6785 (1:6785)
call EnableSRAM
- ld hl, sCurrentDuelData
+ ld hl, sCurrentDuel
xor a
ld [hli], a
ld [hli], a
@@ -4614,11 +4744,11 @@ AIAction_6b3e: ; 6b3e (1:6b3e)
call CopyMoveDataAndDamage_FromDeckIndex
call SwapTurn
ldh a, [hTempCardIndex_ff9f]
- ld [wcc11], a
+ ld [wPlayerAttackingCardIndex], a
ld a, [wSelectedMoveIndex]
- ld [wcc10], a
+ ld [wPlayerAttackingMoveIndex], a
ld a, [wTempCardID_ccc2]
- ld [wcc12], a
+ ld [wPlayerAttackingCardID], a
call Func_16f6
pop bc
ld a, c
@@ -4657,7 +4787,248 @@ DrawWideTextBox_WaitForInput_Bank1: ; 6b9e (1:6b9e)
ret
; 0x6ba2
- INCROM $6ba2, $6d84
+Func_6ba2: ; 6ba2 (1:6ba2)
+ call DrawWideTextBox_PrintText
+ ld a, [wDuelistType]
+ cp DUELIST_TYPE_LINK_OPP
+ ret z
+ call WaitForWideTextBoxInput
+ ret
+; 0x6baf
+
+; apply and/or refresh status conditions and other events that trigger between turns
+HandleBetweenTurnsEvents: ; 6baf (1:6baf)
+ call IsArenaPokemonAsleepOrDoublePoisoned
+ jr c, .something_to_handle
+ cp PARALYZED
+ jr z, .something_to_handle
+ call SwapTurn
+ call IsArenaPokemonAsleepOrDoublePoisoned
+ call SwapTurn
+ jr c, .something_to_handle
+ call DiscardAttachedPluspowers
+ call SwapTurn
+ call DiscardAttachedDefenders
+ call SwapTurn
+ ret
+.something_to_handle
+ ; either:
+ ; 1. turn holder's arena Pokemon is paralyzed, asleep or double poisoned
+ ; 2. non-turn holder's arena Pokemon is asleep or double poisoned
+ call Func_3b21
+ call ZeroObjectPositionsAndToggleOAMCopy
+ call EmptyScreen
+ ld a, BOXMSG_BETWEEN_TURNS
+ call DrawDuelBoxMessage
+ ldtx hl, BetweenTurnsText
+ call DrawWideTextBox_WaitForInput
+ ld a, DUELVARS_ARENA_CARD
+ call GetTurnDuelistVariable
+ call GetCardIDFromDeckIndex
+ ld a, e
+ ld [wTempNonTurnDuelistCardID], a
+ ld l, DUELVARS_ARENA_CARD_STATUS
+ ld a, [hl]
+ or a
+ jr z, .asm_6c1a
+ call $6d3f
+ jr c, .asm_6c1a
+ call Func_6cfa
+ ld a, [hl]
+ and CNF_SLP_PRZ
+ cp PARALYZED
+ jr nz, .asm_6c1a
+ ld a, DOUBLE_POISONED
+ and [hl]
+ ld [hl], a
+ call Func_6c7e
+ ldtx hl, IsCuredOfParalysisText
+ call Func_6ce4
+ ld a, $3e
+ call Func_6cab
+ call WaitForWideTextBoxInput
+.asm_6c1a
+ call DiscardAttachedPluspowers
+ call SwapTurn
+ ld a, DUELVARS_ARENA_CARD
+ call GetTurnDuelistVariable
+ call GetCardIDFromDeckIndex
+ ld a, e
+ ld [wTempNonTurnDuelistCardID], a
+ ld l, DUELVARS_ARENA_CARD_STATUS
+ ld a, [hl]
+ or a
+ jr z, .asm_6c3a
+ call $6d3f
+ jr c, .asm_6c3a
+ call Func_6cfa
+.asm_6c3a
+ call DiscardAttachedDefenders
+ call SwapTurn
+ call $6e4c
+ ret
+; 0x6c44
+
+; discard any PLUSPOWER attached to the turn holder's arena and/or bench Pokemon
+DiscardAttachedPluspowers: ; 6c44 (1:6c44)
+ ld a, DUELVARS_ARENA_CARD_ATTACHED_PLUSPOWER
+ call GetTurnDuelistVariable
+ ld e, MAX_PLAY_AREA_POKEMON
+ xor a
+.unattach_pluspower_loop
+ ld [hli], a
+ dec e
+ jr nz, .unattach_pluspower_loop
+ ld de, PLUSPOWER
+ jp MoveCardToDiscardPileIfInArena
+; 0x6c56
+
+; discard any DEFENDER attached to the turn holder's arena and/or bench Pokemon
+DiscardAttachedDefenders: ; 6c56 (1:6c56)
+ ld a, DUELVARS_ARENA_CARD_ATTACHED_DEFENDER
+ call GetTurnDuelistVariable
+ ld e, MAX_PLAY_AREA_POKEMON
+ xor a
+.unattach_defender_loop
+ ld [hli], a
+ dec e
+ jr nz, .unattach_defender_loop
+ ld de, DEFENDER
+ jp MoveCardToDiscardPileIfInArena
+; 0x6c68
+
+; return carry if the turn holder's arena Pokemon card is double poisoned or asleep.
+; also, if confused, paralyzed, or asleep, return the status condition in a.
+IsArenaPokemonAsleepOrDoublePoisoned: ; 6c68 (1:6c68)
+ ld a, DUELVARS_ARENA_CARD_STATUS
+ call GetTurnDuelistVariable
+ or a
+ ret z
+ and DOUBLE_POISONED
+ jr nz, .set_carry
+ ld a, [hl]
+ and CNF_SLP_PRZ
+ cp ASLEEP
+ jr z, .set_carry
+ or a
+ ret
+.set_carry
+ scf
+ ret
+; 0x6c7e
+
+Func_6c7e: ; 6c7e (1:6c7e)
+ ld a, [wcac2]
+ cp $01
+ jr z, .asm_6c98
+ ld hl, wcc05
+ ldh a, [hWhoseTurn]
+ cp [hl]
+ jp z, DrawDuelMainScene
+ call SwapTurn
+ call DrawDuelMainScene
+ call SwapTurn
+ ret
+.asm_6c98
+ ld hl, wcc05
+ ldh a, [hWhoseTurn]
+ cp [hl]
+ jp z, DrawDuelHUDs
+ call SwapTurn
+ call DrawDuelHUDs
+ call SwapTurn
+ ret
+; 0x6cab
+
+Func_6cab: ; 6cab (1:6cab)
+ push af
+ ld a, [wDuelType]
+ or a
+ jr nz, .asm_6cc6
+ ld a, [wcc05]
+ cp PLAYER_TURN
+ jr z, .asm_6cc6
+ call SwapTurn
+ ldh a, [hWhoseTurn]
+ ld [wd4af], a
+ call SwapTurn
+ jr .asm_6ccb
+.asm_6cc6
+ ldh a, [hWhoseTurn]
+ ld [wd4af], a
+.asm_6ccb
+ xor a
+ ld [wd4b0], a
+ ld a, $00
+ ld [wd4ae], a
+ pop af
+ call Func_3b6a
+.asm_6cd8
+ call DoFrame
+ call Func_3b52
+ jr c, .asm_6cd8
+ call Func_6c7e.asm_6c98
+ ret
+; 0x6ce4
+
+; prints the name of the card at wTempNonTurnDuelistCardID in a text box
+Func_6ce4: ; 6ce4 (1:6ce4)
+ push hl
+ ld a, [wTempNonTurnDuelistCardID]
+ ld e, a
+ call LoadCardDataToBuffer1_FromCardID
+ ld hl, wLoadedCard1Name
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ call LoadTxRam2
+ pop hl
+ call DrawWideTextBox_PrintText
+ ret
+; 0x6cfa
+
+Func_6cfa: ; 6cfa (1:6cfa)
+ ld a, [hl]
+ and CNF_SLP_PRZ
+ cp ASLEEP
+ ret nz
+ push hl
+ ld a, [wTempNonTurnDuelistCardID]
+ ld e, a
+ call LoadCardDataToBuffer1_FromCardID
+ ld a, 18
+ call CopyCardNameAndLevel
+ ld [hl], TX_END
+ ld hl, wTxRam2
+ xor a
+ ld [hli], a
+ ld [hl], a
+ ldtx de, PokemonsSleepCheckText
+ call TossCoin
+ ld a, $03
+ ldtx hl, IsStillAsleepText
+ jr nc, .asm_6d2d
+ pop hl
+ push hl
+ ld a, DOUBLE_POISONED
+ and [hl]
+ ld [hl], a
+ ld a, $3e
+ ldtx hl, IsCuredOfSleepText
+.asm_6d2d
+ push af
+ push hl
+ call Func_6c7e
+ pop hl
+ call Func_6ce4
+ pop af
+ call Func_6cab
+ pop hl
+ call WaitForWideTextBoxInput
+ ret
+; 0x6d3f
+
+ INCROM $6d3f, $6d84
; given the deck index of a turn holder's card in register a,
; and a pointer in hl to the wLoadedCard* buffer where the card data is loaded,
@@ -4829,7 +5200,36 @@ PrintThereWasNoEffectFromStatusText: ; 700a (1:700a)
ret
; 0x7045
- INCROM $7045, $70e6
+ INCROM $7045, $70aa
+
+Func_70aa: ; 70aa (1:70aa)
+ xor a
+ ld [wDuelFinished], a
+ ld [wDuelTurns], a
+ ld [wcce7], a
+ ld a, $ff
+ ld [wcc0f], a
+ ld [wPlayerAttackingCardIndex], a
+ ld [wPlayerAttackingMoveIndex], a
+ call EnableSRAM
+ ld a, [s0a009]
+ ld [wccf2], a
+ call DisableSRAM
+ ld a, [wPlayerDuelistType]
+ cp DUELIST_TYPE_LINK_OPP
+ jr z, .set_duel_type
+ bit 7, a ; DUELIST_TYPE_AI_OPP
+ jr nz, .set_duel_type
+ ld a, [wOpponentDuelistType]
+ cp DUELIST_TYPE_LINK_OPP
+ jr z, .set_duel_type
+ bit 7, a ; DUELIST_TYPE_AI_OPP
+ jr nz, .set_duel_type
+ xor a
+.set_duel_type
+ ld [wDuelType], a
+ ret
+; 0x70e6
Func_70e6: ; 70e6 (1:70e6)
xor a
@@ -4933,7 +5333,7 @@ Func_7195: ; 7195 (1:7195)
ld a, [wccef]
or a
jr nz, .asm_71a9
- ld a, [wTempDamage_ccbf]
+ ld a, [wDealtDamage]
ld [hli], a
ld a, [wccc0]
ld [hl], a
diff --git a/src/engine/bank05.asm b/src/engine/bank05.asm
index 56174a6..464ce48 100644
--- a/src/engine/bank05.asm
+++ b/src/engine/bank05.asm
@@ -243,12 +243,12 @@ Func_15649: ; 15649 (5:5649)
ld [wcddb], a
ld [wcddc], a
ld [wce03], a
- ld a, [wcc10]
+ ld a, [wPlayerAttackingMoveIndex]
cp $ff
jr z, .asm_156b1
or a
jr z, .asm_156b1
- ld a, [wcc11]
+ ld a, [wPlayerAttackingCardIndex]
cp $ff
jr z, .asm_156b1
call SwapTurn
diff --git a/src/engine/bank07.asm b/src/engine/bank07.asm
index 0708c3d..dfae95a 100644
--- a/src/engine/bank07.asm
+++ b/src/engine/bank07.asm
@@ -367,7 +367,53 @@ Func_1c83d: ; 1c83d (7:483d)
ret
; 0x1c858
- INCROM $1c858, $1d078
+ INCROM $1c858, $1cb18
+
+Func_1cb18: ; 1cb18 (7:4b18)
+ push hl
+ push bc
+ push de
+ ld a, [wDoFrameFunction]
+ cp LOW(Func_3ba2)
+ jr nz, .asm_1cb5b
+ ld a, [wDoFrameFunction + 1]
+ cp HIGH(Func_3ba2)
+ jr nz, .asm_1cb5b
+ ld a, $ff
+ ld [wd4c0], a
+ ld a, [wd42a]
+ cp $ff
+ call nz, $4cd4
+ ld hl, wd423
+ ld c, $07
+.asm_1cb3b
+ push bc
+ ld a, [hl]
+ cp $ff
+ jr z, .asm_1cb4b
+ ld [wWhichSprite], a
+ farcall $4, $69fa
+ ld a, $ff
+ ld [hl], a
+.asm_1cb4b
+ pop bc
+ inc hl
+ dec c
+ jr nz, .asm_1cb3b
+ xor a
+ ld [wd4ac], a
+ ld [wd4ad], a
+.asm_1cb57
+ pop de
+ pop bc
+ pop hl
+ ret
+.asm_1cb5b
+ scf
+ jr .asm_1cb57
+; 0x1cb5e
+
+ INCROM $1cb5e, $1d078
Func_1d078: ; 1d078 (7:5078)
ld a, [wd627]
diff --git a/src/engine/home.asm b/src/engine/home.asm
index be9b1de..38a748e 100644
--- a/src/engine/home.asm
+++ b/src/engine/home.asm
@@ -2936,7 +2936,7 @@ SerialRecv8Bytes: ; 0fe9 (0:0fe9)
SaveDuelStateToSRAM: ; 100b (0:100b)
ld a, $2
call BankswitchSRAM
- ; save duel data to sCurrentDuelData
+ ; save duel data to sCurrentDuel
call SaveDuelData
xor a
call BankswitchSRAM
@@ -4376,7 +4376,7 @@ Func_161e: ; 161e (0:161e)
; - e into wSelectedMoveIndex and d into hTempCardIndex_ff9f
; - Move1 (if e == 0) or Move2 (if e == 1) data into wLoadedMove
; - Also from that move, its Damage field into wDamage
-; finally, clears wNoDamageOrEffect and wTempDamage_ccbf
+; finally, clears wNoDamageOrEffect and wDealtDamage
CopyMoveDataAndDamage_FromCardID: ; 16ad (0:16ad)
push de
push af
@@ -4395,7 +4395,7 @@ CopyMoveDataAndDamage_FromCardID: ; 16ad (0:16ad)
; - e into wSelectedMoveIndex and d into hTempCardIndex_ff9f
; - Move1 (if e == 0) or Move2 (if e == 1) data into wLoadedMove
; - Also from that move, its Damage field into wDamage
-; finally, clears wNoDamageOrEffect and wTempDamage_ccbf
+; finally, clears wNoDamageOrEffect and wDealtDamage
CopyMoveDataAndDamage_FromDeckIndex: ; 16c0 (0:16c0)
ld a, e
ld [wSelectedMoveIndex], a
@@ -4426,7 +4426,7 @@ CopyMoveDataAndDamage:
xor a
ld [hl], a
ld [wNoDamageOrEffect], a
- ld hl, wTempDamage_ccbf
+ ld hl, wDealtDamage
ld [hli], a
ld [hl], a
ret
@@ -4463,11 +4463,11 @@ Func_16f6: ; 16f6 (0:16f6)
; use attack or Pokemon Power
UseAttackOrPokemonPower: ; 1730 (0:1730)
ld a, [wSelectedMoveIndex]
- ld [wcc10], a
+ ld [wPlayerAttackingMoveIndex], a
ldh a, [hTempCardIndex_ff9f]
- ld [wcc11], a
+ ld [wPlayerAttackingCardIndex], a
ld a, [wTempCardID_ccc2]
- ld [wcc12], a
+ ld [wPlayerAttackingCardID], a
ld a, [wLoadedMoveCategory]
cp POKEMON_POWER
jp z, UsePokemonPower
@@ -4521,7 +4521,7 @@ Func_179a: ; 179a (0:179a)
call TryExecuteEffectCommandFunction
call ApplyDamageModifiers_DamageToTarget
call Func_189d
- ld hl, wTempDamage_ccbf
+ ld hl, wDealtDamage
ld [hl], e
inc hl
ld [hl], d
@@ -4636,9 +4636,9 @@ Func_1874: ; 1874 (0:1874)
push af
ld a, $1
ld [wccec], a
- ld a, [wcc11]
+ ld a, [wPlayerAttackingCardIndex]
ldh [hTempCardIndex_ff9f], a
- ld a, [wcc10]
+ ld a, [wPlayerAttackingMoveIndex]
ldh [hTemp_ffa0], a
ld a, $8
call SetAIAction_SerialSendDuelData
@@ -5105,8 +5105,8 @@ Func_1af3: ; 1af3 (0:1af3)
ld b, a
or a ; cp PLAY_AREA_ARENA
jr nz, .benched
- ; add damage at de to [wTempDamage_ccbf]
- ld hl, wTempDamage_ccbf
+ ; add damage at de to [wDealtDamage]
+ ld hl, wDealtDamage
ld a, e
add [hl]
ld [hli], a
@@ -10322,7 +10322,7 @@ HandleStrikesBack_AgainstResidualMove: ; 367b (0:367b)
ld a, [wLoadedMoveCategory]
and RESIDUAL
ret nz
- ld a, [wTempDamage_ccbf]
+ ld a, [wDealtDamage]
or a
ret z
call SwapTurn
diff --git a/src/hram.asm b/src/hram.asm
index 7f96ef5..f02b40c 100644
--- a/src/hram.asm
+++ b/src/hram.asm
@@ -77,7 +77,7 @@ hAIActionTableIndex:: ; ff9e
hTempCardIndex_ff9f:: ; ff9f
ds $1
-; multipurpose temp storage
+; multipurpose temp storage (card's deck index, selected move index, status condition...)
hTemp_ffa0:: ; ffa0
ds $1
@@ -89,7 +89,7 @@ hTempPlayAreaLocation_ffa1:: ; ffa1
hTempRetreatCostCards:: ; ffa2
ds $6
-; hffa8 through hffb0 appear to be related to text processing
+; hffa8 through hffb0 belong to the text engine
hffa8:: ; ffa8
ds $1
diff --git a/src/sram.asm b/src/sram.asm
index 9a8d752..fa58d07 100644
--- a/src/sram.asm
+++ b/src/sram.asm
@@ -1,45 +1,68 @@
SECTION "SRAM0", SRAM
-s0a000:: ds $3 ; a000
-
-s0a003:: ds $1 ; a003
-s0a004:: ds $1 ; a004
-s0a005:: ds $1 ; a005
-s0a006:: ds $1 ; a006
-s0a007:: ds $1 ; a007
-s0a008:: ds $1 ; a008
-s0a009:: ds $1 ; a009
-s0a00a:: ds $1 ; a00a
+s0a000:: ; a000
+ ds $3
+
+s0a003:: ; a003
+ ds $1
+s0a004:: ; a004
+ ds $1
+s0a005:: ; a005
+ ds $1
+s0a006:: ; a006
+ ds $1
+s0a007:: ; a007
+ ds $1
+s0a008:: ; a008
+ ds $1
+s0a009:: ; a009
+ ds $1
+s0a00a:: ; a00a
+ ds $1
ds $5
-sPlayerName:: ds $10 ; a010
+sPlayerName:: ; a010
+ ds $10
ds $e0
; for each card, how many (0-127) the player owns
; CARD_NOT_OWNED ($80) indicates that the player has not yet seen the card
-sCardCollection:: ds $100 ; a100
-
-sDeck1Name:: ds DECK_NAME_SIZE ; a200
-sDeck1Cards:: ds DECK_SIZE ; a218
-
-sDeck2Name:: ds DECK_NAME_SIZE ; a254
-sDeck2Cards:: ds DECK_SIZE ; a26c
-
-sDeck3Name:: ds DECK_NAME_SIZE ; a2a8
-sDeck3Cards:: ds DECK_SIZE ; a2c0
-
-sDeck4Name:: ds DECK_NAME_SIZE ; a2fc
-sDeck4Cards:: ds DECK_SIZE ; a314
-
-s0a350:: ds DECK_NAME_SIZE + DECK_SIZE ; a350
-s0a3a4:: ds DECK_NAME_SIZE + DECK_SIZE ; a3a4
-s0a3f8:: ds DECK_NAME_SIZE + DECK_SIZE ; a3f8
+sCardCollection:: ; a100
+ ds $100
+
+sDeck1Name:: ; a200
+ ds DECK_NAME_SIZE
+sDeck1Cards:: ; a218
+ ds DECK_SIZE
+
+sDeck2Name:: ; a254
+ ds DECK_NAME_SIZE
+sDeck2Cards:: ; a26c
+ ds DECK_SIZE
+
+sDeck3Name:: ; a2a8
+ ds DECK_NAME_SIZE
+sDeck3Cards:: ; a2c0
+ ds DECK_SIZE
+
+sDeck4Name:: ; a2fc
+ ds DECK_NAME_SIZE
+sDeck4Cards:: ; a314
+ ds DECK_SIZE
+
+s0a350:: ; a350
+ ds DECK_NAME_SIZE + DECK_SIZE
+s0a3a4:: ; a3a4
+ ds DECK_NAME_SIZE + DECK_SIZE
+s0a3f8:: ; a3f8
+ ds DECK_NAME_SIZE + DECK_SIZE
ds $12b4
-s0b700:: ds $1
+s0b700:: ; b700
+ ds $1
SECTION "SRAM1", SRAM
@@ -49,6 +72,11 @@ SECTION "SRAM2", SRAM
; saved data of the current duel, including a two-byte checksum
; see SaveDuelDataToDE
-sCurrentDuelData:: ds $33e ; bc00
+sCurrentDuel:: ; bc00
+ ds $1
+sCurrentDuelChecksum:: ; bc01
+ ds $2
+sCurrentDuelData:: ; bc04
+ ds $33b
SECTION "SRAM3", SRAM
diff --git a/src/text/text1.asm b/src/text/text1.asm
index f773960..d4124c2 100644
--- a/src/text/text1.asm
+++ b/src/text/text1.asm
@@ -171,7 +171,7 @@ IsCuredOfParalysisText: ; 36539 (d:6539)
line "cured of Paralysis."
done
-Text002b: ; 36553 (d:6553)
+BetweenTurnsText: ; 36553 (d:6553)
text "Between Turns."
done
@@ -406,7 +406,7 @@ FinishedTurnWithoutAttackingText: ; 36a74 (d:6a74)
line "without Attacking."
done
-Text005e: ; 36a9a (d:6a9a)
+DuelistsTurnText: ; 36a9a (d:6a9a)
text "<RAMNAME>'s Turn."
done
diff --git a/src/text/text2.asm b/src/text/text2.asm
index 5afb3c6..845e9c5 100644
--- a/src/text/text2.asm
+++ b/src/text/text2.asm
@@ -18,7 +18,7 @@ ConfusionCheckRetreatText: ; 380ac (e:40ac)
line "If Tails, unable to Retreat."
done
-Text00f9: ; 380db (e:40db)
+PokemonsSleepCheckText: ; 380db (e:40db)
text "<RAMTEXT>'s Sleep check."
done
diff --git a/src/text/text_offsets.asm b/src/text/text_offsets.asm
index e2e1725..5f817b6 100644
--- a/src/text/text_offsets.asm
+++ b/src/text/text_offsets.asm
@@ -44,7 +44,7 @@ TextOffsets:: ; 34000 (d:4000)
textpointer IsStillAsleepText ; 0x0028
textpointer IsCuredOfSleepText ; 0x0029
textpointer IsCuredOfParalysisText ; 0x002a
- textpointer Text002b ; 0x002b
+ textpointer BetweenTurnsText ; 0x002b
textpointer Text002c ; 0x002c
textpointer Text002d ; 0x002d
textpointer Text002e ; 0x002e
@@ -79,9 +79,9 @@ TextOffsets:: ; 34000 (d:4000)
textpointer Text004b ; 0x004b
textpointer Text004c ; 0x004c
textpointer Text004d ; 0x004d
- textpointer KnockOutText ; 0x004e
+ textpointer KnockOutText ; 0x004e
textpointer DamageToSelfDueToConfusionText ; 0x004f
- textpointer ChooseEnergyCardToDiscardText ; 0x0050
+ textpointer ChooseEnergyCardToDiscardText ; 0x0050
textpointer Text0051 ; 0x0051
textpointer Text0052 ; 0x0052
textpointer YouPlayFirstText ; 0x0053
@@ -95,7 +95,7 @@ TextOffsets:: ; 34000 (d:4000)
textpointer RetreatWasUnsuccessfulText ; 0x005b
textpointer WillUseThePokemonPowerText ; 0x005c
textpointer FinishedTurnWithoutAttackingText ; 0x005d
- textpointer Text005e ; 0x005e
+ textpointer DuelistsTurnText ; 0x005e
textpointer Text005f ; 0x005f
textpointer Text0060 ; 0x0060
textpointer PlacedOnTheBenchText ; 0x0061
@@ -192,7 +192,7 @@ TextOffsets:: ; 34000 (d:4000)
textpointer Text00bc ; 0x00bc
textpointer Text00bd ; 0x00bd
textpointer Text00be ; 0x00be
- textpointer EnergyCardsRequiredToRetreatText ; 0x00bf
+ textpointer EnergyCardsRequiredToRetreatText ; 0x00bf
textpointer NotEnoughEnergyCardsText ; 0x00c0
textpointer Text00c1 ; 0x00c1
textpointer Text00c2 ; 0x00c2
@@ -250,7 +250,7 @@ TextOffsets:: ; 34000 (d:4000)
textpointer TransparencyCheckText ; 0x00f6
textpointer ConfusionCheckDamageText ; 0x00f7
textpointer ConfusionCheckRetreatText ; 0x00f8
- textpointer Text00f9 ; 0x00f9
+ textpointer PokemonsSleepCheckText ; 0x00f9
textpointer Text00fa ; 0x00fa
textpointer Text00fb ; 0x00fb
textpointer Text00fc ; 0x00fc
diff --git a/src/wram.asm b/src/wram.asm
index ed4ab9a..0379dec 100644
--- a/src/wram.asm
+++ b/src/wram.asm
@@ -810,15 +810,21 @@ wDuelistType:: ; cc0d
wOpponentDeckID:: ; cc0e
ds $1
+wcc0f:: ; cc0f
ds $1
-wcc10:: ; cc10
+; index (0-1) of the move or Pokemon Power being used by the player's arena card
+; set to $ff when the duel starts and at the end of the opponent's turn
+wPlayerAttackingMoveIndex:: ; cc10
ds $1
-wcc11:: ; cc11
+; deck index of the player's arena card that is attacking or using a Pokemon Power
+; set to $ff when the duel starts and at the end of the opponent's turn
+wPlayerAttackingCardIndex:: ; cc11
ds $1
-wcc12:: ; cc12
+; ID of the player's arena card that is attacking or using a Pokemon Power
+wPlayerAttackingCardID:: ; cc12
ds $1
wIsPracticeDuel:: ; cc13
@@ -863,7 +869,7 @@ wLoadedCard2:: ; cc65
wLoadedMove:: ; cca6
move_data_struct wLoadedMove
-; damage dealt by an attack. little-endian
+; the damage field of an used move is loaded here
wDamage:: ; ccb9
ds $2
@@ -876,7 +882,8 @@ wccbc:: ; ccbc
ds $2
-wTempDamage_ccbf:: ; ccbf
+; damage dealt by an attack to a target
+wDealtDamage:: ; ccbf
ds $1
wccc0:: ; ccc0
@@ -926,7 +933,10 @@ wEffectFunctionsFeedback:: ; ccce
wIsDamageToSelf:: ; cce6
ds $1
- ds $2
+wcce7:: ; cce7
+ ds $1
+
+ ds $1
; used in CopyDeckData
wcce9:: ; cce9
@@ -1863,7 +1873,11 @@ wd4ac:: ; d4ac
wd4ad:: ; d4ad
ds $1
- ds $2
+wd4ae:: ; d4ae
+ ds $1
+
+wd4af:: ; d4af
+ ds $1
wd4b0:: ; d4b0
ds $1