diff options
author | Daniel Harding <33dannye@gmail.com> | 2021-05-13 14:57:10 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-13 14:57:10 -0500 |
commit | 0a3b84155b53785c974a2b352a6473124c56631b (patch) | |
tree | d1366c7304f19b15662d64e9b0edc1bd868df401 /src/engine | |
parent | 732a632a948595906df649252f66fdad5e2b4468 (diff) | |
parent | ef5a54d4d18baa51aea8552f184880e3ccd4d423 (diff) |
Merge pull request #104 from ElectroDeoxys/master
Complete disassembly of Bank 2
Diffstat (limited to 'src/engine')
-rw-r--r-- | src/engine/bank01.asm | 19 | ||||
-rw-r--r-- | src/engine/bank02.asm | 6426 | ||||
-rw-r--r-- | src/engine/bank03.asm | 14 | ||||
-rw-r--r-- | src/engine/bank06.asm | 245 | ||||
-rw-r--r-- | src/engine/bank1c.asm | 4 | ||||
-rw-r--r-- | src/engine/effect_functions.asm | 4 | ||||
-rw-r--r-- | src/engine/home.asm | 27 |
7 files changed, 5457 insertions, 1282 deletions
diff --git a/src/engine/bank01.asm b/src/engine/bank01.asm index c706842..449cd75 100644 --- a/src/engine/bank01.asm +++ b/src/engine/bank01.asm @@ -1813,7 +1813,7 @@ Func_4b60: ; 4b60 (1:4b60) call ChooseInitialArenaAndBenchPokemon call SwapTurn jp c, .asm_4c77 - call Func_311d + call DrawPlayAreaToPlacePrizeCards ldtx hl, PlacingThePrizesText call DrawWideTextBox_WaitForInput call ExchangeRNG @@ -3684,7 +3684,7 @@ Func_5805: ; 5805 (1:5805) ldtx hl, WillDrawNPrizesText call DrawWideTextBox_WaitForInput ld a, [wNumberPrizeCardsToTake] - call Func_310a + call SelectPrizeCards ld hl, hTemp_ffa0 ld d, [hl] inc hl @@ -8523,7 +8523,20 @@ Func_7576: ; 7576 (1:7576) ret ; 0x757b - INCROM $757b, $758a +Func_757b: ; 757b (1:757b) + farcall Func_19e42 + ret +; 0x7580 + +Func_7580: ; 7580 (1:7580) + farcall Func_1a162 + ret +; 0x7585 + +Func_7585: ; 7585 (1:7585) + farcall Func_1a270 + ret +; 0x758a Func_758a: ; 758a (1:758a) farcall Func_19eb4 diff --git a/src/engine/bank02.asm b/src/engine/bank02.asm index 3483af2..9afbaed 100644 --- a/src/engine/bank02.asm +++ b/src/engine/bank02.asm @@ -434,7 +434,7 @@ _DrawYourOrOppPlayAreaScreen: ; 8211 (2:4211) ; a = (6 - name text in tiles) / 2 + 4 ld d, a ; text horizontal alignment - ld e, $00 + ld e, 0 call InitTextPrinting ldtx hl, DuelistsPlayAreaText ldh a, [hWhoseTurn] @@ -512,7 +512,7 @@ DrawInPlayAreaScreen: ; 82ce (2:42ce) call DoFrame call EmptyScreen - ld a, $0a + ld a, CHECK_PLAY_AREA ld [wDuelDisplayedScreen], a call Set_OBJ_8x8 call LoadCursorTile @@ -1281,7 +1281,7 @@ HandleCheckMenuInput_YourOrOppPlayArea: ; 86ac (2:46ac) ld e, a .erase - ld a, $01 + ld a, TRUE ld [wPlaysSfx], a push de call EraseCheckMenuCursor_YourOrOppPlayArea @@ -1367,20 +1367,20 @@ DrawCheckMenuCursor_YourOrOppPlayArea: ; 8743 (2:4743) call WriteByteToBGMap0 or a ret +; 0x8760 DisplayCheckMenuCursor_YourOrOppPlayArea: ; 8760 (2:4760) ld a, SYM_CURSOR_R ; load cursor byte jr DrawCheckMenuCursor_YourOrOppPlayArea -; seems to be function to deal with the Peek menu -; to select a prize card to view -Func_8764: ; 8764 (2:4764) +; handles Peek Pkmn Power selection menus +_HandlePeekSelection: ; 8764 (2:4764) call Set_OBJ_8x8 call LoadCursorTile -; reset ce5c and ce56 +; reset ce5c and wIsSwapTurnPending xor a ld [wce5c], a - ld [wce56], a + ld [wIsSwapTurnPending], a ; draw play area screen for the turn player ldh a, [hWhoseTurn] @@ -1388,51 +1388,51 @@ Func_8764: ; 8764 (2:4764) ld l, a call DrawYourOrOppPlayAreaScreen -.swap - ld a, [wce56] +.check_swap + ld a, [wIsSwapTurnPending] or a - jr z, .draw_menu -; if ce56 != 0, swap turn + jr z, .draw_menu_1 +; if wIsSwapTurnPending is TRUE, swap turn call SwapTurn xor a - ld [wce56], a + ld [wIsSwapTurnPending], a -.draw_menu +; prompt player to choose either own Play Area or opponent's +.draw_menu_1 xor a - ld hl, PlayAreaMenuParameters + ld hl, .PlayAreaMenuParameters call InitializeMenuParameters call DrawWideTextBox - - ld hl, YourOrOppPlayAreaData + ld hl, .YourOrOppPlayAreaData call PlaceTextItems -.loop_1 +.loop_input_1 call DoFrame - call HandleMenuInput ; await input - jr nc, .loop_1 - cp $ff - jr z, .loop_1 + call HandleMenuInput + jr nc, .loop_input_1 + cp -1 + jr z, .loop_input_1 ; can't use B btn call EraseCursor ldh a, [hCurMenuItem] or a - jp nz, Func_8883 ; jump if not first option + jp nz, .PrepareYourPlayAreaSelection ; jump if not Opp Play Area -; hCurMenuItem = 0 +; own Play Area was chosen ld a, [wCheckMenuPlayAreaWhichDuelist] ld b, a ldh a, [hWhoseTurn] cp b - jr z, .text + jr z, .text_1 ; switch the play area to draw ld h, a ld l, a call DrawYourOrOppPlayAreaScreen xor a - ld [wce56], a + ld [wIsSwapTurnPending], a -.text +.text_1 call DrawWideTextBox lb de, 1, 14 call InitTextPrinting @@ -1440,43 +1440,43 @@ Func_8764: ; 8764 (2:4764) call ProcessTextFromID xor a - ld [wPrizeCardCursorPosition], a - ld de, Func_8764_TransitionTable - ld hl, wce53 + ld [wYourOrOppPlayAreaCurPosition], a + ld de, PeekYourPlayAreaTransitionTable + ld hl, wTransitionTablePtr ld [hl], e inc hl ld [hl], d -.loop_2 +.loop_input_2 ld a, $01 ld [wVBlankOAMCopyToggle], a call DoFrame - call Func_89ae - jr c, .asm_87e7 - jr .loop_2 -.asm_87e7 - cp $ff - jr nz, .asm_87f0 + call YourOrOppPlayAreaScreen_HandleInput + jr c, .selection_cancelled + jr .loop_input_2 +.selection_cancelled + cp -1 + jr nz, .selection_made call ZeroObjectPositionsWithCopyToggleOn - jr .swap -.asm_87f0 - ld hl, .asm_87f8 + jr .check_swap +.selection_made + ld hl, .SelectionFunctionTable call JumpToFunctionInTable - jr .loop_2 + jr .loop_input_2 -.asm_87f8 +.SelectionFunctionTable rept 6 - dw Func_8819 + dw .SelectedPrize endr - dw Func_883c - dw Func_8849 + dw .SelectedOppsHand + dw .SelectedDeck -YourOrOppPlayAreaData: ; 8808 (2:4808) +.YourOrOppPlayAreaData ; 8808 (2:4808) textitem 2, 14, YourPlayAreaText textitem 2, 16, OppPlayAreaText db $ff -PlayAreaMenuParameters: ; 8811 (2:4811) +.PlayAreaMenuParameters ; 8811 (2:4811) db 1, 14 ; cursor x, cursor y db 2 ; y displacement between items db 2 ; number of items @@ -1484,21 +1484,21 @@ PlayAreaMenuParameters: ; 8811 (2:4811) db SYM_SPACE ; tile behind cursor dw NULL ; function pointer if non-0 -Func_8819: ; 8819 (2:4819) - ld a, [wPrizeCardCursorPosition] +.SelectedPrize: ; 8819 (2:4819) + ld a, [wYourOrOppPlayAreaCurPosition] ld c, a - ld b, $01 + ld b, $1 ; left-shift b a number of times ; corresponding to this prize card -.loop +.loop_prize_bitmask or a - jr z, .asm_8827 + jr z, .got_prize_bitmask sla b dec a - jr .loop + jr .loop_prize_bitmask -.asm_8827 +.got_prize_bitmask ld a, DUELVARS_PRIZES call GetTurnDuelistVariable and b @@ -1510,17 +1510,17 @@ Func_8819: ; 8819 (2:4819) ld a, c add DUELVARS_PRIZE_CARDS call GetTurnDuelistVariable - jr Func_8855 + jr .ShowSelectedCard -Func_883c: ; 883c (2:483c) +.SelectedOppsHand ; 883c (2:483c) call CreateHandCardList ret c ld hl, wDuelTempList call ShuffleCards ld a, [hl] - jr Func_8855 + jr .ShowSelectedCard -Func_8849: ; 8849 (2:4849) +.SelectedDeck ; 8849 (2:4849) call CreateDeckCardList ret c ld a, %01111111 @@ -1533,11 +1533,12 @@ Func_8849: ; 8849 (2:4849) ; output: ; a = ce5c ; with upper bit set if turn was swapped -Func_8855: ; 8855 (2:4855) +.ShowSelectedCard ; 8855 (2:4855) ld b, a ld a, [wce5c] or a jr nz, .display + ; if wce5c is not set, set it as input deck index ld a, b ld [wce5c], a .display @@ -1549,8 +1550,8 @@ Func_8855: ; 8855 (2:4855) ld [wVBlankOAMCopyToggle], a pop af -; if ce56 != 0, swap turn - ld a, [wce56] +; if wIsSwapTurnPending is TRUE, swap turn + ld a, [wIsSwapTurnPending] or a jr z, .dont_swap call SwapTurn @@ -1561,26 +1562,28 @@ Func_8855: ; 8855 (2:4855) ld a, [wce5c] ret -Func_8883: ; 8883 (2:4883) +; prepare menu parameters to handle selection +; of player's own Play Area +.PrepareYourPlayAreaSelection: ; 8883 (2:4883) ld a, [wCheckMenuPlayAreaWhichDuelist] ld b, a ldh a, [hWhoseTurn] cp b - jr nz, .text + jr nz, .text_2 ld l, a cp PLAYER_TURN jr nz, .opponent ld a, OPPONENT_TURN - jr .draw + jr .draw_menu_2 .opponent ld a, PLAYER_TURN -.draw +.draw_menu_2 ld h, a call DrawYourOrOppPlayAreaScreen -.text +.text_2 call DrawWideTextBox lb de, 1, 14 call InitTextPrinting @@ -1588,19 +1591,19 @@ Func_8883: ; 8883 (2:4883) call ProcessTextFromID xor a - ld [wPrizeCardCursorPosition], a - ld de, Func_8883_TransitionTable - ld hl, wce53 + ld [wYourOrOppPlayAreaCurPosition], a + ld de, PeekOppPlayAreaTransitionTable + ld hl, wTransitionTablePtr ld [hl], e inc hl ld [hl], d call SwapTurn - ld a, $01 - ld [wce56], a - jp Func_8764.loop_2 + ld a, TRUE + ld [wIsSwapTurnPending], a ; mark pending to swap turn + jp .loop_input_2 -Func_8764_TransitionTable: ; 88c2 (2:48c2) +PeekYourPlayAreaTransitionTable: ; 88c2 (2:48c2) cursor_transition $08, $28, $00, $04, $02, $01, $07 cursor_transition $30, $28, $20, $05, $03, $07, $00 cursor_transition $08, $38, $00, $00, $04, $03, $07 @@ -1610,7 +1613,7 @@ Func_8764_TransitionTable: ; 88c2 (2:48c2) cursor_transition $78, $50, $00, $07, $07, $00, $01 cursor_transition $78, $28, $00, $07, $07, $00, $01 -Func_8883_TransitionTable: ; 88fa (2:48fa) +PeekOppPlayAreaTransitionTable: ; 88fa (2:48fa) cursor_transition $a0, $60, $20, $02, $04, $07, $01 cursor_transition $78, $60, $00, $03, $05, $00, $07 cursor_transition $a0, $50, $20, $04, $00, $06, $03 @@ -1620,8 +1623,68 @@ Func_8883_TransitionTable: ; 88fa (2:48fa) cursor_transition $08, $38, $00, $07, $07, $05, $04 cursor_transition $08, $60, $00, $06, $06, $01, $00 -Func_8932: ; 8932 (2:4932) - INCROM $8932, $8992 +_DrawAIPeekScreen: ; 8932 (2:4932) + push bc + call Set_OBJ_8x8 + call LoadCursorTile + xor a + ld [wIsSwapTurnPending], a + ldh a, [hWhoseTurn] + ld l, a + ld de, PeekYourPlayAreaTransitionTable + pop bc + bit AI_PEEK_TARGET_HAND_F, b + jr z, .draw_play_area + +; AI chose the hand + call SwapTurn + ld a, TRUE + ld [wIsSwapTurnPending], a ; mark pending to swap turn + ldh a, [hWhoseTurn] + ld de, PeekOppPlayAreaTransitionTable +.draw_play_area + ld h, a + push bc + push de + call DrawYourOrOppPlayAreaScreen + pop de + pop bc + +; get the right cursor position +; depending on what action the AI chose +; (prize card, hand, deck) + ld hl, wMenuInputTablePointer + ld [hl], e + inc hl + ld [hl], d + ld a, b + and $7f + cp $7f + jr nz, .prize_card +; cursor on the deck + ld a, $7 + ld [wYourOrOppPlayAreaCurPosition], a + jr .got_cursor_position +.prize_card + bit AI_PEEK_TARGET_PRIZE_F, a + jr z, .hand + and $3f + ld [wYourOrOppPlayAreaCurPosition], a + jr .got_cursor_position +.hand + ld a, $6 + ld [wYourOrOppPlayAreaCurPosition], a +.got_cursor_position + call YourOrOppPlayAreaScreen_HandleInput.draw_cursor + + ld a, $1 + ld [wVBlankOAMCopyToggle], a + ld a, [wIsSwapTurnPending] + or a + ret z + call SwapTurn + ret +; 0x8992 LoadCursorTile: ; 8992 (2:4992) ld de, v0Tiles0 @@ -1634,24 +1697,26 @@ LoadCursorTile: ; 8992 (2:4992) db $e0, $c0, $98, $b0, $84, $8c, $83, $82 db $86, $8f, $9d, $be, $f4, $f8, $50, $60 -; similar to OpenInPlayAreaScreen_HandleInput -Func_89ae: ; 89ae (2:49ae) +; handles input inside the "Your Play Area" or "Opp Play Area" screens +; returns carry if either A or B button were pressed +; returns -1 in a if B button was pressed +YourOrOppPlayAreaScreen_HandleInput: ; 89ae (2:49ae) xor a ld [wPlaysSfx], a - ld hl, wce53 +; get the transition data for the prize card with cursor + ld hl, wTransitionTablePtr ld e, [hl] inc hl ld d, [hl] - - ld a, [wPrizeCardCursorPosition] + ld a, [wYourOrOppPlayAreaCurPosition] ld [wPrizeCardCursorTemporaryPosition], a ld l, a - ld h, 7 + ld h, 7 ; length of each transition table item call HtimesL add hl, de -; hl = [wce53] + 7 * wce52 +; get the transition index related to the directional input ldh a, [hDPadHeld] or a jp z, .check_button @@ -1692,10 +1757,10 @@ Func_89ae: ; 89ae (2:49ae) ; left ld a, [hl] .process_dpad - ld [wPrizeCardCursorPosition], a - cp $08 ; if a >= 0x8 + ld [wYourOrOppPlayAreaCurPosition], a + cp $8 ; if a >= 0x8 jr nc, .next - ld b, $01 + ld b, $1 ; this loop equals to ; b = (1 << a) @@ -1716,7 +1781,7 @@ Func_89ae: ; 89ae (2:49ae) ; when no cards exist at the cursor, ld a, [wPrizeCardCursorTemporaryPosition] cp $06 - jr nz, Func_89ae + jr nz, YourOrOppPlayAreaScreen_HandleInput ; move once more in the direction (recursively) until it reaches an existing item. ; check if one of the dpad, left or right, is pressed. @@ -1725,37 +1790,44 @@ Func_89ae: ; 89ae (2:49ae) bit D_RIGHT_F, a jr nz, .left_or_right bit D_LEFT_F, a - jr z, Func_89ae + jr z, YourOrOppPlayAreaScreen_HandleInput .left_or_right + ; if started with 5 or 6 prize cards + ; can switch sides normally, ld a, [wDuelInitialPrizes] - cp $05 + cp PRIZES_5 jr nc, .next - ld a, [wPrizeCardCursorPosition] - cp $05 - jr nz, .asm_8a28 - ld a, $03 - ld [wPrizeCardCursorPosition], a - jr .asm_8a2d + ; else if it's last card, + ld a, [wYourOrOppPlayAreaCurPosition] + cp 5 + jr nz, .not_last_card + ; place it at pos 3 + ld a, 3 + ld [wYourOrOppPlayAreaCurPosition], a + jr .ok +.not_last_card + ; otherwise place at pos 2 + ld a, 2 + ld [wYourOrOppPlayAreaCurPosition], a -.asm_8a28 - ld a, $02 - ld [wPrizeCardCursorPosition], a -.asm_8a2d +.ok ld a, [wDuelInitialPrizes] - cp $03 - jr nc, .asm_8a3c - ld a, [wPrizeCardCursorPosition] - sub $02 - ld [wPrizeCardCursorPosition], a -.asm_8a3c - ld a, [wPrizeCardCursorPosition] + cp PRIZES_3 + jr nc, .handled_cursor_pos + ; in this case can just sub 2 from pos + ld a, [wYourOrOppPlayAreaCurPosition] + sub 2 + ld [wYourOrOppPlayAreaCurPosition], a + +.handled_cursor_pos + ld a, [wYourOrOppPlayAreaCurPosition] ld [wPrizeCardCursorTemporaryPosition], a - ld b, $01 + ld b, $1 jr .make_bitmask_loop .next - ld a, $01 + ld a, TRUE ld [wPlaysSfx], a ; reset cursor blink @@ -1778,7 +1850,7 @@ Func_89ae: ; 89ae (2:49ae) call .draw_cursor ld a, $01 call PlaySFXConfirmOrCancel - ld a, [wPrizeCardCursorPosition] + ld a, [wYourOrOppPlayAreaCurPosition] scf ret @@ -1798,16 +1870,16 @@ Func_89ae: ; 89ae (2:49ae) .draw_cursor call ZeroObjectPositions - ld hl, wce53 + ld hl, wTransitionTablePtr ld e, [hl] inc hl ld d, [hl] - ld a, [wPrizeCardCursorPosition] + ld a, [wYourOrOppPlayAreaCurPosition] ld l, a ld h, 7 call HtimesL add hl, de -; hl = [wce53] + 7 * wce52 +; hl = [wTransitionTablePtr] + 7 * wce52 ld d, [hl] inc hl @@ -1826,11 +1898,293 @@ ZeroObjectPositionsWithCopyToggleOn: ; 8aa1 (2:4aa1) ld [wVBlankOAMCopyToggle], a ret -Func_8aaa: ; 8aaa (2:4aaa) - INCROM $8aaa, $8b85 +; handles the screen for Player to select prize card(s) +_SelectPrizeCards: ; 8aaa (2:4aaa) + xor a + call GetFirstSetPrizeCard + ld [wYourOrOppPlayAreaCurPosition], a + ld de, hTempPlayAreaLocation_ffa1 + ld hl, wSelectedPrizeCardListPtr + ld [hl], e + inc hl + ld [hl], d + +.check_prize_cards_to_select + ld a, [wNumberOfPrizeCardsToSelect] + or a + jr z, .done_selection + ld a, DUELVARS_PRIZES + call GetTurnDuelistVariable + or a + jr nz, .got_prizes + +.done_selection + ld a, DUELVARS_PRIZES + call GetTurnDuelistVariable + ldh [hTemp_ffa0], a + ld a, [wSelectedPrizeCardListPtr + 0] + ld l, a + ld a, [wSelectedPrizeCardListPtr + 1] + ld h, a + ld [hl], $ff + ret + +.got_prizes + ldh a, [hWhoseTurn] + ld h, a + ld l, a + call DrawYourOrOppPlayAreaScreen + call DrawWideTextBox + lb de, 1, 14 + call InitTextPrinting + ldtx hl, PleaseChooseAPrizeText + call ProcessTextFromID + ld de, .cursor_transition_table + ld hl, wMenuInputTablePointer + ld [hl], e + inc hl + ld [hl], d +.loop_handle_input + ld a, $1 + ld [wVBlankOAMCopyToggle], a + call DoFrame + call YourOrOppPlayAreaScreen_HandleInput + jr nc, .loop_handle_input + cp $ff + jr z, .loop_handle_input + + call ZeroObjectPositionsWithCopyToggleOn + +; get prize bit mask that corresponds +; to the one pointed by the cursor + ld a, [wYourOrOppPlayAreaCurPosition] + ld c, a + ld b, $1 +.loop + or a + jr z, .got_prize_mask + sla b + dec a + jr .loop + +.got_prize_mask + ; if cursor prize is not set, + ; then return to input loop + ld a, DUELVARS_PRIZES + call GetTurnDuelistVariable + and b + jp z, .loop_handle_input ; can be jr + + ; remove prize + ld a, DUELVARS_PRIZES + call GetTurnDuelistVariable + sub b + ld [hl], a + + ; get its deck index + ld a, c + add DUELVARS_PRIZE_CARDS + call GetTurnDuelistVariable + + ld hl, wSelectedPrizeCardListPtr + ld e, [hl] + inc hl + ld d, [hl] + ld [de], a ; store deck index + inc de + ld [hl], d + dec hl + ld [hl], e + + ; add prize card to hand + call AddCardToHand + call LoadCardDataToBuffer1_FromDeckIndex + call Set_OBJ_8x16 + bank1call OpenCardPage_FromHand + ld a, [wNumberOfPrizeCardsToSelect] + dec a + ld [wNumberOfPrizeCardsToSelect], a + ld a, [wYourOrOppPlayAreaCurPosition] + call GetFirstSetPrizeCard + ld [wYourOrOppPlayAreaCurPosition], a + jp .check_prize_cards_to_select + +.cursor_transition_table + cursor_transition $08, $28, $00, $04, $02, $01, $01 + cursor_transition $30, $28, $20, $05, $03, $00, $00 + cursor_transition $08, $38, $00, $00, $04, $03, $03 + cursor_transition $30, $38, $20, $01, $05, $02, $02 + cursor_transition $08, $48, $00, $02, $00, $05, $05 + cursor_transition $30, $48, $20, $03, $01, $04, $04 +; 0x8b85 + +_DrawPlayAreaToPlacePrizeCards: ; 8b85 (2:4b85) + xor a + ld [wTileMapFill], a + call ZeroObjectPositions + call EmptyScreen + call LoadSymbolsFont + call LoadPlacingThePrizesScreenTiles + + ldh a, [hWhoseTurn] + ld [wCheckMenuPlayAreaWhichLayout], a + ld [wCheckMenuPlayAreaWhichDuelist], a + + lb de, 0, 10 + ld c, 3 + call DrawPlayArea_BenchCards + ld hl, .player_icon_coordinates + call DrawYourOrOppPlayArea_Icons.draw + lb de, 8, 6 + ld a, $a0 + lb hl, 1, 4 + lb bc, 4, 3 + call FillRectangle + + call SwapTurn + ld a, TRUE + ld [wIsSwapTurnPending], a ; mark pending to swap turn + ldh a, [hWhoseTurn] + ld [wCheckMenuPlayAreaWhichDuelist], a + lb de, 6, 0 + ld c, 3 + call DrawPlayArea_BenchCards + ld hl, .opp_icon_coordinates + call DrawYourOrOppPlayArea_Icons.draw + lb de, 8, 3 + ld a, $a0 + lb hl, 1, 4 + lb bc, 4, 3 + call FillRectangle + call SwapTurn + ret + +.player_icon_coordinates + db 15, 11 + db 15, 6 + db 15, 8 + +.opp_icon_coordinates + db 0, 0 + db 0, 4 + db 0, 2 +; 0x8bf2 + +; seems like a function to draw prize cards +; given a list of coordinates in hl +; unreferenced? +; hl = pointer to coords +Func_8bf2: ; 8bf2 (2:4bf2) + push hl + ld a, [wCheckMenuPlayAreaWhichDuelist] + ld h, a + ld l, DUELVARS_PRIZES + ld a, [hl] + pop hl + + ld b, 0 + push af +.loop_prize_cards + inc b + ld a, [wDuelInitialPrizes] + inc a + cp b + jr z, .done + pop af + srl a + push af + jr c, .not_taken + ; same tile whether the prize card is taken or not + ld a, $ac + jr .got_tile +.not_taken + ld a, $ac +.got_tile + ld e, [hl] + inc hl + ld d, [hl] + inc hl + push hl + push bc + lb hl, 0, 0 + lb bc, 1, 1 + call FillRectangle + ld a, [wConsole] + cp CONSOLE_CGB + jr nz, .skip_pal + ld a, $02 + lb bc, 1, 1 + lb hl, 0, 0 + call BankswitchVRAM1 + call FillRectangle + call BankswitchVRAM0 +.skip_pal + pop bc + pop hl + jr .loop_prize_cards +.done + pop af + ret +; 0x8c3f + +; unknown data +; unreferenced? +Data_8c3f: ; 8c3f (6:4c3f) + db $06, $05, $06, $06, $07, $05, $07, $06, $08, $05, $08, $06, $05, $0e, $05, $0d, $04, $0e, $04, $0d, $03, $0e, $03, $0d +; 0x8c57 + +; gets the first prize card index that is set +; beginning from index in register a +; a = prize card index +GetFirstSetPrizeCard: ; 8c57 (2:4c57) + push bc + push de + push hl + ld e, PRIZES_6 + ld c, a + ldh a, [hWhoseTurn] + ld h, a + ld l, DUELVARS_PRIZES + ld d, [hl] +.loop_prizes + call .GetPrizeMask + and d + jr nz, .done ; prize is set + dec e + jr nz, .next_prize + ld c, 0 + jr .done +.next_prize + inc c + ld a, PRIZES_6 + cp c + jr nz, .loop_prizes + ld c, 0 + jr .loop_prizes + +.done + ld a, c ; first prize index that is set + pop hl + pop de + pop bc + ret -Func_8b85: ; 8b85 (2:4b85) - INCROM $8b85, $8c8e +; returns 1 shifted left by c bits +.GetPrizeMask + push bc + ld a, c + ld b, $1 +.loop + or a + jr z, .got_mask + sla b + dec a + jr .loop +.got_mask + ld a, b + pop bc + ret +; 0x8c8e OpenGlossaryScreen_TransitionTable: cursor_transition $08, $28, $00, $04, $01, $05, $05 @@ -1845,7 +2199,7 @@ OpenGlossaryScreen_TransitionTable: cursor_transition $58, $68, $00, $08, $05, $04, $04 ; copies DECK_SIZE number of cards from de to hl in SRAM -Func_8cd4: ; 8cd4 (2:4cd4) +CopyDeckFromSRAM: ; 8cd4 (2:4cd4) push bc call EnableSRAM ld b, DECK_SIZE @@ -1862,31 +2216,35 @@ Func_8cd4: ; 8cd4 (2:4cd4) ret ; 0x8ce7 -Func_8ce7: ; 8ce7 (2:4ce7) +; clears some WRAM addresses to act as +; terminator bytes to wFilteredCardList and wCurDeckCards +WriteCardListsTerminatorBytes: ; 8ce7 (2:4ce7) xor a - ld hl, wceda + ld hl, wFilteredCardList ld bc, DECK_SIZE add hl, bc ld [hl], a ; wcf16 - ld hl, wcf17 - ld bc, $50 + ld hl, wCurDeckCards + ld bc, DECK_CONFIG_BUFFER_SIZE add hl, bc - ld [hl], a + ld [hl], a ; wCurDeckCardsTerminator ret ; 0x8cf9 +; inits some SRAM addresses Func_8cf9: ; 8cf9 (2:4cf9) call EnableSRAM xor a - ld hl, sb703 + ld hl, sHasPromotionalCards ld [hli], a - inc a + inc a ; $1 ld [hli], a ld [hli], a ld [hl], a - ld [sb701], a + ld [sUnnamedDeckCounter], a call DisableSRAM -; fallthrough +; ret missing +; unintentional fallthrough ; loads the Hard Cards icon gfx to v0Tiles2 LoadHandCardsIcon: ; 8d0b (2:4d0b) @@ -1899,7 +2257,7 @@ HandCardsGfx: ; 8d15 (2:4d15) INCBIN "gfx/hand_cards.2bpp" db $00 ; end of data -Func_8d56: ; 8d56 (2:4d56) +EmptyScreenAndLoadFontDuelAndHandCardsIcons: ; 8d56 (2:4d56) xor a ld [wTileMapFill], a call EmptyScreen @@ -1935,9 +2293,14 @@ Func_8d78: ; 8d78 (2:4d78) ret ; 0x8d9d -; copies 7 bytes from hl to wcfd1 -Func_8d9d: ; 8d9d (2:4d9d) - ld de, wcfd1 +; inits the following deck building params from hl: +; wMaxNumCardsAllowed +; wSameNameCardsLimit +; wIncludeCardsInDeck +; wDeckConfigurationMenuHandlerFunction +; wDeckConfigurationMenuTransitionTable +InitDeckBuildingParams: ; 8d9d (2:4d9d) + ld de, wMaxNumCardsAllowed ld b, $7 .loop ld a, [hli] @@ -1947,131 +2310,161 @@ Func_8d9d: ; 8d9d (2:4d9d) jr nz, .loop ret -Data_8da9: ; 8da9 (2:4da9) - db $50, $04, $01 +DeckBuildingParams: ; 8da9 (2:4da9) + db DECK_CONFIG_BUFFER_SIZE ; max number of cards + db MAX_NUM_SAME_NAME_CARDS ; max number of same name cards + db TRUE ; whether to include deck cards dw HandleDeckConfigurationMenu dw DeckConfigurationMenu_TransitionTable +; 0x8db0 - INCROM $8db0, $8db0 - -Func_8db0: ; 8db0 (2:4db0) - ld hl, Data_8da9 - call Func_8d9d - ld a, $ff - call Func_9168 +DeckSelectionMenu: ; 8db0 (2:4db0) + ld hl, DeckBuildingParams + call InitDeckBuildingParams + ld a, ALL_DECKS + call DrawDecksScreen xor a -Func_8dbc: ; 8dbc (2:4dbc) - ld hl, Unknown_8de2 +.init_menu_params + ld hl, .DeckSelectionMenuParameters call InitializeMenuParameters ldtx hl, PleaseSelectDeckText call DrawWideTextBox_PrintText -.asm_8dc8 +.loop_input call DoFrame - jr c, Func_8dbc - call Func_8dea - jr c, Func_8dbc + jr c, .init_menu_params ; reinit menu parameters + call HandleStartButtonInDeckSelectionMenu + jr c, .init_menu_params call HandleMenuInput - jr nc, .asm_8dc8 + jr nc, .loop_input ldh a, [hCurMenuItem] cp $ff - ret z - ld [wceb1], a - jp Func_8e42 - -Unknown_8de2: ; 8de2 (2:4de2) - INCROM $8de2, $8dea + ret z ; B btn returns +; A btn pressed on a deck + ld [wCurDeck], a + jp DeckSelectionSubMenu + +.DeckSelectionMenuParameters + db 1, 2 ; cursor x, cursor y + db 3 ; y displacement between items + db 4 ; number of items + db SYM_CURSOR_R ; cursor tile number + db SYM_SPACE ; tile behind cursor + dw NULL ; function pointer if non-0 -Func_8dea: ; 8dea (2:4dea) +; handles START button press when in deck selection menu +; does nothing if START button isn't pressed +; if a press was handled, returns carry +; prints "There is no deck here!" if the selected deck is empty +HandleStartButtonInDeckSelectionMenu: ; 8dea (2:4dea) ldh a, [hDPadHeld] and START - ret z + ret z ; skip + +; set menu item as current deck ld a, [wCurMenuItem] - ld [wceb1], a - call Func_8ff2 - jp nc, Func_8e05 + ld [wCurDeck], a + call CheckIfCurDeckIsValid + jp nc, .valid_deck ; can be jr + +; not a valid deck, cancel ld a, $ff ; cancel call PlaySFXConfirmOrCancel - call Func_8fe8 + call PrintThereIsNoDeckHereText scf ret -Func_8e05: ; 8e05 (2:4e05) +.valid_deck ld a, $1 call PlaySFXConfirmOrCancel call GetPointerToDeckCards push hl call GetPointerToDeckName pop de - call Func_8e1f - ld a, $ff - call Func_9168 - ld a, [wceb1] + call OpenDeckConfirmationMenu + ld a, ALL_DECKS + call DrawDecksScreen + ld a, [wCurDeck] scf ret +; 0x8e1f -; copies deck in hl to wcfb9 -; copies deck in de to wcf17 -Func_8e1f: ; 8e1f (2:4e1f) +OpenDeckConfirmationMenu: ; 8e1f (2:4e1f) +; copy deck name push de - ld de, wcfb9 + ld de, wCurDeckName call CopyListFromHLToDEInSRAM pop de - ld hl, wcf17 - call Func_8cd4 - ld a, 9 - ld hl, wcebb + +; copy deck cards + ld hl, wCurDeckCards + call CopyDeckFromSRAM + + ld a, NUM_FILTERS + ld hl, wCardFilterCounts call ClearNBytesFromHL ld a, DECK_SIZE - ld [wcecc], a - ld hl, wcebb + ld [wTotalCardCount], a + ld hl, wCardFilterCounts ld [hl], a - call Func_9e41 + call HandleDeckConfirmationMenu ret +; 0x8e42 -Func_8e42: ; 8e42 (2:4e42) +; handles the submenu when selecting a deck +; (Modify Deck, Select Deck, Change Name and Cancel) +DeckSelectionSubMenu: ; 8e42 (2:4e42) call DrawWideTextBox - ld hl, Unknown_9027 + ld hl, DeckSelectionData call PlaceTextItems call ResetCheckMenuCursorPositionAndBlink -.asm_8e4e +.loop_input call DoFrame call HandleCheckMenuInput - jp nc, .asm_8e4e + jp nc, .loop_input cp $ff - jr nz, .asm_8e64 + jr nz, .option_selected +; B btn pressed +; erase cursor and go back +; to deck selection handling call EraseCheckMenuCursor - ld a, [wceb1] - jp Func_8dbc -.asm_8e64 + ld a, [wCurDeck] + jp DeckSelectionMenu.init_menu_params + +.option_selected ld a, [wCheckMenuCursorXPosition] or a - jp nz, Func_8f8a + jp nz, DeckSelectionSubMenu_SelectOrCancel ld a, [wCheckMenuCursorYPosition] or a - jp nz, .asm_8ecf + jp nz, .ChangeName + +; Modify Deck +; read deck from SRAM +; TODO call GetPointerToDeckCards ld e, l ld d, h - ld hl, wcf17 - call Func_8cd4 + ld hl, wCurDeckCards + call CopyDeckFromSRAM ld a, 20 - ld hl, wcfb9 + ld hl, wCurDeckName call ClearNBytesFromHL - ld de, wcfb9 + ld de, wCurDeckName call GetPointerToDeckName call CopyListFromHLToDEInSRAM - call Func_9345 + + call HandleDeckBuildScreen jr nc, .asm_8ec4 call EnableSRAM - ld hl, wcf17 - call Func_910a + ld hl, wCurDeckCards + call DecrementDeckCardsInCollection call GetPointerToDeckCards - call Func_9152 + call AddDeckToCollection ld e, l ld d, h - ld hl, wcf17 - ld b, $3c + ld hl, wCurDeckCards + ld b, DECK_SIZE .asm_8ea9 ld a, [hli] ld [de], a @@ -2081,73 +2474,80 @@ Func_8e42: ; 8e42 (2:4e42) call GetPointerToDeckName ld d, h ld e, l - ld hl, wcfb9 + ld hl, wCurDeckName call CopyListFromHLToDE call GetPointerToDeckName ld a, [hl] call DisableSRAM or a - jr z, .asm_8edb + jr z, .get_input_deck_name .asm_8ec4 - ld a, $ff - call Func_9168 - ld a, [wceb1] - jp Func_8dbc -.asm_8ecf - call Func_8ff2 - jp nc, .asm_8edb - call Func_8fe8 - jp Func_8dbc -.asm_8edb + ld a, ALL_DECKS + call DrawDecksScreen + ld a, [wCurDeck] + jp DeckSelectionMenu.init_menu_params + +.ChangeName + call CheckIfCurDeckIsValid + jp nc, .get_input_deck_name + call PrintThereIsNoDeckHereText + jp DeckSelectionMenu.init_menu_params +.get_input_deck_name ld a, 20 - ld hl, wcfb9 + ld hl, wCurDeckName call ClearNBytesFromHL - ld de, wcfb9 + ld de, wCurDeckName call GetPointerToDeckName call CopyListFromHLToDEInSRAM - call Func_8f05 + call InputCurDeckName call GetPointerToDeckName ld d, h ld e, l - ld hl, wcfb9 + ld hl, wCurDeckName call CopyListFromHLToDEInSRAM - ld a, $ff - call Func_9168 - ld a, [wceb1] - jp Func_8dbc - -Func_8f05: ; 8f05 (2:4f05) - ld a, [wceb1] + ld a, ALL_DECKS + call DrawDecksScreen + ld a, [wCurDeck] + jp DeckSelectionMenu.init_menu_params + +; gets current deck's name from user input +InputCurDeckName: ; 8f05 (2:4f05) + ld a, [wCurDeck] or a - jr nz, .asm_8f10 - ; it refers to a data in the other bank without any bank desc. + jr nz, .deck_2 ld hl, Deck1Data - jr .asm_8f23 -.asm_8f10 + jr .got_deck_ptr +.deck_2 dec a - jr nz, .asm_8f18 + jr nz, .deck_3 ld hl, Deck2Data - jr .asm_8f23 -.asm_8f18 + jr .got_deck_ptr +.deck_3 dec a - jr nz, .asm_8f20 + jr nz, .deck_4 ld hl, Deck3Data - jr .asm_8f23 -.asm_8f20 + jr .got_deck_ptr +.deck_4 ld hl, Deck4Data -.asm_8f23 +.got_deck_ptr ld a, MAX_DECK_NAME_LENGTH lb bc, 4, 1 - ld de, wcfb9 + ld de, wCurDeckName farcall InputDeckName - ld a, [wcfb9] + ld a, [wCurDeckName] or a ret nz - call Func_8f38 + ; empty name + call .UnnamedDeck ret -Func_8f38: ; 8f38 (2:4f38) - ld hl, sb701 +; handles the naming of unnamed decks +; inputs as the deck name "DECK XXX" +; where XXX is the current unnamed deck counter +.UnnamedDeck +; read the current unnamed deck number +; and convert it to text + ld hl, sUnnamedDeckCounter call EnableSRAM ld a, [hli] ld h, [hl] @@ -2155,20 +2555,21 @@ Func_8f38: ; 8f38 (2:4f38) ld l, a ld de, wDefaultText call TwoByteNumberToText - ld hl, wcfb9 + + ld hl, wCurDeckName ld [hl], $6 inc hl - ld [hl], $44 + ld [hl], "D" inc hl - ld [hl], $65 + ld [hl], "e" inc hl - ld [hl], $63 + ld [hl], "c" inc hl - ld [hl], $6b + ld [hl], "k" inc hl - ld [hl], $20 + ld [hl], " " inc hl - ld de, wc592 + ld de, wDefaultText + 2 ld a, [de] inc de ld [hli], a @@ -2179,39 +2580,53 @@ Func_8f38: ; 8f38 (2:4f38) ld [hli], a xor a ld [hl], a - ld hl, sb701 + +; increment the unnamed deck counter + ld hl, sUnnamedDeckCounter call EnableSRAM ld e, [hl] inc hl ld d, [hl] - ld a, $3 +; capped at 999 + ld a, HIGH(MAX_UNNAMED_DECK_NUM) cp d - jr nz, .asm_8f82 - ld a, $e7 + jr nz, .incr_counter + ld a, LOW(MAX_UNNAMED_DECK_NUM) cp e - jr nz, .asm_8f82 - ld de, $0000 -.asm_8f82 + jr nz, .incr_counter + ; reset counter + ld de, 0 +.incr_counter inc de ld [hl], d dec hl ld [hl], e call DisableSRAM ret +; 0x8f8a -Func_8f8a: ; 8f8a (2:4f8a) +; handle deck selection sub-menu +; the option is either "Select Deck" or "Cancel" +; depending on the cursor Y pos +DeckSelectionSubMenu_SelectOrCancel: ; 8f8a (2:4f8a) ld a, [wCheckMenuCursorYPosition] or a - jp nz, Func_9026 - call Func_8ff2 - jp nc, Func_8f9d - call Func_8fe8 - jp Func_8dbc + jp nz, CancelDeckSelectionSubMenu + +; select deck + call CheckIfCurDeckIsValid + jp nc, .SelectDeck + ; invalid deck + call PrintThereIsNoDeckHereText + jp DeckSelectionMenu.init_menu_params -Func_8f9d: ; 8f9d (2:4f9d) +.SelectDeck call EnableSRAM ld a, [sCurrentlySelectedDeck] call DisableSRAM + +; draw empty rectangle on currently selected deck +; i.e. erase the Hand Cards Gfx icon ld h, $3 ld l, a call HtimesL @@ -2222,55 +2637,96 @@ Func_8f9d: ; 8f9d (2:4f9d) lb hl, 0, 0 lb bc, 2, 2 call FillRectangle - ld a, [wceb1] + +; set current deck as the selected deck +; and draw the Hand Cards Gfx icon + ld a, [wCurDeck] call EnableSRAM ld [sCurrentlySelectedDeck], a call DisableSRAM - call DrawHandCardsTileOnSelectedDeck + call DrawHandCardsTileOnCurDeck + +; print "<DECK> was chosen as the dueling deck!" call GetPointerToDeckName call EnableSRAM - call Func_9253 + call CopyDeckName call DisableSRAM xor a ld [wTxRam2], a ld [wTxRam2 + 1], a ldtx hl, ChosenAsDuelingDeckText call DrawWideTextBox_WaitForInput - ld a, [wceb1] - jp Func_8dbc + ld a, [wCurDeck] + jp DeckSelectionMenu.init_menu_params +; 0x8fe8 -Func_8fe8: ; 8fe8 (2:4fe8) +PrintThereIsNoDeckHereText: ; 8fe8 (2:4fe8) ldtx hl, ThereIsNoDeckHereText call DrawWideTextBox_WaitForInput - ld a, [wceb1] + ld a, [wCurDeck] ret -Func_8ff2: ; 8ff2 (2:4ff2) - ld a, [wceb1] - ld hl, wceb2 +; returns carry if deck in wCurDeck +; is not a valid deck +CheckIfCurDeckIsValid: ; 8ff2 (2:4ff2) + ld a, [wCurDeck] + ld hl, wDecksValid ld b, $0 ld c, a add hl, bc ld a, [hl] or a - ret nz + ret nz ; is valid scf - ret + ret ; is not valid ; 0x9001 - INCROM $9001, $9026 +; write to $d00a the decimal representation (number characters) +; of the value in hl +; unreferenced? +Func_9001: ; 9001 (2:5001) + ld de, $d00a + ld bc, -100 + call .GetNumberChar + ld bc, -10 + call .GetNumberChar + ld bc, -1 + call .GetNumberChar + ret + +.GetNumberChar + ld a, SYM_0 - 1 +.loop + inc a + add hl, bc + jr c, .loop + ld [de], a + inc de + ld a, l + sub c + ld l, a + ld a, h + sbc b + ld h, a + ret +; 0x9026 -Func_9026: ; 9026 (2:5026) +CancelDeckSelectionSubMenu: ; 9026 (2:5026) ret -Unknown_9027: ; 9027 (2:5027) - INCROM $9027, $9038 +DeckSelectionData: ; 9027 (2:5027) + textitem 2, 14, ModifyDeckText + textitem 12, 14, SelectDeckText + textitem 2, 16, ChangeNameText + textitem 12, 16, CancelText + db $ff +; 0x9038 -; return, in hl, the pointer to sDeckXName where X is [wceb1] + 1 +; return, in hl, the pointer to sDeckXName where X is [wCurDeck] + 1 GetPointerToDeckName: ; 9038 (2:5038) - ld a, [wceb1] + ld a, [wCurDeck] ld h, a - ld l, sDeck2Name - sDeck1Name + ld l, DECK_STRUCT_SIZE call HtimesL push de ld de, sDeck1Name @@ -2278,10 +2734,10 @@ GetPointerToDeckName: ; 9038 (2:5038) pop de ret -; return, in hl, the pointer to sDeckXCards where X is [wceb1] + 1 +; return, in hl, the pointer to sDeckXCards where X is [wCurDeck] + 1 GetPointerToDeckCards: ; 9048 (2:5048) push af - ld a, [wceb1] + ld a, [wCurDeck] ld h, a ld l, sDeck2Cards - sDeck1Cards call HtimesL @@ -2342,7 +2798,7 @@ HandleCheckMenuInput: ; 9065 (2:5065) ld e, a .okay - ld a, $01 + ld a, TRUE ld [wPlaysSfx], a push de call EraseCheckMenuCursor @@ -2442,14 +2898,17 @@ PlaySFXConfirmOrCancel: ; 90fb (2:50fb) pop af ret -Func_910a: ; 910a (2:510a) +; goes through whole deck in hl +; for each card ID, goes to its corresponding +; entry in sCardCollection and decrements its count +DecrementDeckCardsInCollection: ; 910a (2:510a) push hl ld b, $0 - ld d, $3c -.asm_910f + ld d, DECK_SIZE +.loop_deck ld a, [hli] or a - jr z, .asm_911e + jr z, .done ld c, a push hl ld hl, sCardCollection @@ -2457,17 +2916,24 @@ Func_910a: ; 910a (2:510a) dec [hl] pop hl dec d - jr nz, .asm_910f -.asm_911e + jr nz, .loop_deck +.done pop hl ret ; 0x9120 -Func_9120: ; 9120 (2:5120) +; like AddDeckToCollection, but takes care to +; check if increasing the collection count would +; go over MAX_AMOUNT_OF_CARD and caps it +; this is because it's used within Gift Center, +; so we cannot assume that the deck configuration +; won't make it go over MAX_AMOUNT_OF_CARD +; hl = deck configuration, with cards to add +AddGiftCenterDeckCardsToCollection: ; 9120 (2:5120) push hl - ld b, $00 + ld b, $0 ld d, DECK_SIZE -.asm_9125 +.loop_deck ld a, [hli] or a jr z, .done @@ -2475,42 +2941,46 @@ Func_9120: ; 9120 (2:5120) push hl push de push bc - ld a, $ff - call Func_a3ca + ld a, ALL_DECKS + call CreateCardCollectionListWithDeckCards pop bc pop de ld hl, wTempCardCollection add hl, bc ld a, [hl] - cp $63 - jr z, .asm_914c - call EnableSRAM + cp MAX_AMOUNT_OF_CARD + jr z, .next_card ; capped + call EnableSRAM ; no DisableSRAM ld hl, sCardCollection add hl, bc ld a, [hl] - cp $80 - jr nz, .asm_914b + cp CARD_NOT_OWNED + jr nz, .incr + ; not owned xor a ld [hl], a -.asm_914b +.incr inc [hl] -.asm_914c +.next_card pop hl dec d - jr nz, .asm_9125 + jr nz, .loop_deck .done pop hl ret ; 0x9152 -Func_9152: ; 9152 (2:5152) +; adds all cards in deck in hl to player's collection +; assumes SRAM is enabled +; hl = pointer to deck cards +AddDeckToCollection: ; 9152 (2:5152) push hl ld b, $0 ld d, DECK_SIZE -.asm_9157 +.loop_deck ld a, [hli] or a - jr z, .asm_9166 + jr z, .done ld c, a push hl ld hl, sCardCollection @@ -2518,14 +2988,17 @@ Func_9152: ; 9152 (2:5152) inc [hl] pop hl dec d - jr nz, .asm_9157 -.asm_9166 + jr nz, .loop_deck +.done pop hl ret -Func_9168: ; 9168 (2:5168) +; draws the screen which shows the player's current +; deck configurations +; a = DECK_* flags to pick which deck names to show +DrawDecksScreen: ; 9168 (2:5168) ld [hffb5], a - call Func_8d56 + call EmptyScreenAndLoadFontDuelAndHandCardsIcons lb de, 0, 0 lb bc, 20, 4 call DrawRegularTextBox @@ -2538,94 +3011,118 @@ Func_9168: ; 9168 (2:5168) lb de, 0, 9 lb bc, 20, 4 call DrawRegularTextBox - ld hl, Unknown_9242 + ld hl, DeckNameMenuData call PlaceTextItems - ld a, 4 - ld hl, wceb2 + +; mark all decks as invalid + ld a, NUM_DECKS + ld hl, wDecksValid call ClearNBytesFromHL + +; for each deck, check if it has cards and if so +; mark is as valid in wDecksValid + +; deck 1 ld a, [hffb5] ; should be ldh bit 0, a - jr z, .asm_91b0 + jr z, .skip_name_1 ld hl, sDeck1Name lb de, 6, 2 - call Func_926e -.asm_91b0 + call PrintDeckName +.skip_name_1 ld hl, sDeck1Cards - call Func_9314 - jr c, .asm_91bd - ld a, $1 - ld [wceb2], a -.asm_91bd + call CheckIfDeckHasCards + jr c, .deck_2 + ld a, TRUE + ld [wDeck1Valid], a + +.deck_2 ld a, [hffb5] ; should be ldh bit 1, a - jr z, .asm_91cd + jr z, .skip_name_2 ld hl, sDeck2Name lb de, 6, 5 - call Func_926e -.asm_91cd + call PrintDeckName +.skip_name_2 ld hl, sDeck2Cards - call Func_9314 - jr c, .asm_91da - ld a, $1 - ld [wceb3], a -.asm_91da + call CheckIfDeckHasCards + jr c, .deck_3 + ld a, TRUE + ld [wDeck2Valid], a + +.deck_3 ld a, [hffb5] ; should be ldh bit 2, a - jr z, .asm_91ea + jr z, .skip_name_3 ld hl, sDeck3Name lb de, 6, 8 - call Func_926e -.asm_91ea + call PrintDeckName +.skip_name_3 ld hl, sDeck3Cards - call Func_9314 - jr c, .asm_91f7 - ld a, $1 - ld [wceb4], a -.asm_91f7 + call CheckIfDeckHasCards + jr c, .deck_4 + ld a, TRUE + ld [wDeck3Valid], a + +.deck_4 ld a, [hffb5] ; should be ldh bit 3, a - jr z, .asm_9207 + jr z, .skip_name_4 ld hl, sDeck4Name lb de, 6, 11 - call Func_926e -.asm_9207 + call PrintDeckName +.skip_name_4 ld hl, sDeck4Cards - call Func_9314 - jr c, .asm_9214 - ld a, $1 - ld [wceb5], a -.asm_9214 + call CheckIfDeckHasCards + jr c, .place_cursor + ld a, TRUE + ld [wDeck4Valid], a + +.place_cursor +; places cursor on sCurrentlySelectedDeck +; if it's an empty deck, then advance the cursor +; until it's selecting a valid deck call EnableSRAM ld a, [sCurrentlySelectedDeck] ld c, a ld b, $0 - ld d, $2 -.asm_921f - ld hl, wceb2 + ld d, 2 +.check_valid_deck + ld hl, wDecksValid add hl, bc ld a, [hl] or a - jr nz, .asm_9234 + jr nz, .valid_selected_deck inc c - ld a, $4 + ld a, NUM_DECKS cp c - jr nz, .asm_921f - ld c, $0 + jr nz, .check_valid_deck + ld c, 0 ; roll back to deck 1 dec d - jr z, .asm_9234 - jr .asm_921f -.asm_9234 + jr z, .valid_selected_deck + jr .check_valid_deck + +.valid_selected_deck ld a, c ld [sCurrentlySelectedDeck], a call DisableSRAM - call DrawHandCardsTileOnSelectedDeck + call DrawHandCardsTileOnCurDeck call EnableLCD ret +; 0x9242 -Unknown_9242: ; 9242 (2:5242) - INCROM $9242, $9253 +DeckNameMenuData: ; 9242 (2:5242) + textitem 4, 2, Deck1Text + textitem 4, 5, Deck2Text + textitem 4, 8, Deck3Text + textitem 4, 11, Deck4Text + db $ff +; 0x9253 -Func_9253: ; 9253 (2:5253) +; copies text from hl to wDefaultText +; with " deck" appended to the end +; hl = ptr to deck name +CopyDeckName: ; 9253 (2:5253) ld de, wDefaultText call CopyListFromHLToDE ld hl, wDefaultText @@ -2635,16 +3132,22 @@ Func_9253: ; 9253 (2:5253) add hl, bc ld d, h ld e, l - ld hl, Data_92a7 + ld hl, DeckNameSuffix call CopyListFromHLToDE ret +; prints deck name given in hl in position de +; if it's an empty deck, print "NEW DECK" instead +; returns carry if it's an empty deck +; hl = deck name (sDeck1Name ~ sDeck4Name) ; de = coordinates to print text -Func_926e: ; 926e (2:526e) +PrintDeckName: ; 926e (2:526e) push hl - call Func_9314 + call CheckIfDeckHasCards pop hl - jr c, .asm_929c + jr c, .new_deck + +; print "<deck name> deck" push de ld de, wDefaultText call CopyListFromHLToDEInSRAM @@ -2655,7 +3158,7 @@ Func_926e: ; 926e (2:526e) add hl, bc ld d, h ld e, l - ld hl, Data_92a7 + ld hl, DeckNameSuffix call CopyListFromHLToDE pop de ld hl, wDefaultText @@ -2663,16 +3166,18 @@ Func_926e: ; 926e (2:526e) call ProcessText or a ret -.asm_929c + +.new_deck +; print "NEW DECK" call InitTextPrinting ldtx hl, NewDeckText call ProcessTextFromID scf ret -Data_92a7: ; 92a7 (2:52a7) +DeckNameSuffix: ; 92a7 (2:52a7) db " deck" - db TX_END + done ; copies a $00-terminated list from hl to de CopyListFromHLToDE: ; 92ad (2:52ad) @@ -2691,31 +3196,41 @@ CopyListFromHLToDEInSRAM: ; 92b4 (2:52b4) ret ; 0x92be -Func_92be: ; 92be (2:52be) +; appends text in hl to wDefaultText +; then adds "deck" to the end +; returns carry if deck has no cards +; hl = text to append +; de = input to InitTextPrinting +AppendDeckName: ; 92be (2:52be) push hl - call Func_9314 + call CheckIfDeckHasCards pop hl - ret c + ret c ; no cards + push de + ; append the text from hl ld de, wDefaultText call CopyListFromHLToDEInSRAM + + ; get string length (up to DECK_NAME_SIZE_WO_SUFFIX) ld hl, wDefaultText call GetTextLengthInTiles ld a, c - cp 21 - jr c, .asm_92d8 - ld c, 21 -.asm_92d8 + cp DECK_NAME_SIZE_WO_SUFFIX + jr c, .got_len + ld c, DECK_NAME_SIZE_WO_SUFFIX +.got_len ld b, $0 ld hl, wDefaultText add hl, bc ld d, h ld e, l + ; append "deck" starting from the given length ld hl, .text_start ld b, .text_end - .text_start call CopyNBytesFromHLToDE - xor a - ld [wc5aa], a + xor a ; TX_END + ld [wDefaultText + DECK_NAME_SIZE + 2], a pop de ld hl, wDefaultText call InitTextPrinting @@ -2728,23 +3243,31 @@ Func_92be: ; 92be (2:52be) .text_end ; 0x9314 -Func_9314: ; 9314 (2:5314) - ld bc, $0018 +; returns carry if the deck in hl +; is not valid, that is, has no cards +; alternatively, the direct address of the cards +; can be used, since DECK_SIZE > DECK_NAME_SIZE +; hl = deck name (sDeck1Name ~ sDeck4Name) +; or deck cards (sDeck1Cards ~ sDeck4Cards) +CheckIfDeckHasCards: ; 9314 (2:5314) + ld bc, DECK_NAME_SIZE add hl, bc call EnableSRAM ld a, [hl] call DisableSRAM + ; being max size means last char + ; is not TX_END, i.e. $0 or a - jr nz, .asm_9324 + jr nz, .max_size scf ret -.asm_9324 +.max_size or a ret ; calculates the y coordinate of the currently selected deck ; and draws the hands card tile at that position -DrawHandCardsTileOnSelectedDeck: ; 9326 (2:5326) +DrawHandCardsTileOnCurDeck: ; 9326 (2:5326) call EnableSRAM ld a, [sCurrentlySelectedDeck] call DisableSRAM @@ -2763,144 +3286,168 @@ DrawHandCardsTileAtDE: ; 9339 (2:5339) lb bc, 2, 2 call FillRectangle ret +; 0x9345 -Func_9345: ; 9345 (2:5345) - call Func_8ce7 +; handles user input when selecting a card filter +; when building a deck configuration +; the handling of selecting cards themselves from the list +; to add/remove to the deck is done in HandleDeckCardSelectionList +HandleDeckBuildScreen: ; 9345 (2:5345) + call WriteCardListsTerminatorBytes call CountNumberOfCardsForEachCardType .skip_count call DrawCardTypeIconsAndPrintCardCounts xor a - ld [wcea1], a - ld [wced3], a - call Func_993d + ld [wCardListVisibleOffset], a + ld [wCurCardTypeFilter], a ; FILTER_GRASS + call PrintFilteredCardList .skip_draw - ld hl, Data_9667 - call Func_9a6d + ld hl, FiltersCardSelectionParams + call InitCardSelectionParams .wait_input call DoFrame ldh a, [hDPadHeld] and START - jr z, .no_start_btn + jr z, .no_start_btn_1 ld a, $01 call PlaySFXConfirmOrCancel call ConfirmDeckConfiguration - ld a, [wced3] - ld [wNamingScreenCursorY], a + ld a, [wCurCardTypeFilter] + ld [wTempCardTypeFilter], a jr .wait_input -.no_start_btn - ld a, [wced3] + +.no_start_btn_1 + ld a, [wCurCardTypeFilter] ld b, a - ld a, [wNamingScreenCursorY] + ld a, [wTempCardTypeFilter] cp b jr z, .check_down_btn - ld [wced3], a - ld hl, wcea1 - ld [hl], $00 - call Func_993d - ld a, $09 - ld [wNamingScreenKeyboardHeight], a + ; need to refresh the filtered card list + ld [wCurCardTypeFilter], a + ld hl, wCardListVisibleOffset + ld [hl], 0 + call PrintFilteredCardList + ld a, NUM_FILTERS + ld [wCardListNumCursorPositions], a .check_down_btn ldh a, [hDPadHeld] and D_DOWN jr z, .no_down_btn - call Func_9ad7 - jr .asm_93a9 + call ConfirmSelectionAndReturnCarry + jr .jump_to_list + .no_down_btn - call Func_9a83 + call HandleCardSelectionInput jr nc, .wait_input ld a, [hffb3] - cp $ff - jp z, Func_9461 -.asm_93a9 - ld a, [wceab + 3] + cp $ff ; operation cancelled? + jp z, OpenDeckConfigurationMenu + +; input was made to jump to the card list +.jump_to_list + ld a, [wNumEntriesInCurFilter] or a jr z, .wait_input xor a -.asm_93b0 - ld hl, Data_9670 - call Func_9a6d - ld a, [wceab + 3] - ld [wcfe4 + 2], a - ld hl, wcecb +.wait_list_input + ld hl, FilteredCardListSelectionParams + call InitCardSelectionParams + ld a, [wNumEntriesInCurFilter] + ld [wNumCardListEntries], a + ld hl, wNumVisibleCardListEntries cp [hl] - jr nc, .asm_93c5 - ld [wNamingScreenKeyboardHeight], a -.asm_93c5 + jr nc, .ok + ; if total number of entries is greater than or equal to + ; the number of visible entries, then set number of cursor positions + ; as number of visible entries + ld [wCardListNumCursorPositions], a +.ok ld hl, PrintDeckBuildingCardList ld d, h ld a, l - ld hl, wcece + ld hl, wCardListUpdateFunction ld [hli], a ld [hl], d ld a, $01 ld [wced2], a -.asm_93d4 +.loop_input call DoFrame ldh a, [hDPadHeld] and START - jr z, .asm_93f0 + jr z, .no_start_btn_2 ld a, $01 call PlaySFXConfirmOrCancel - ld a, [wNamingScreenCursorY] - ld [wced5], a + + ; temporarily store current cursor position + ; to retrieve it later + ld a, [wCardListCursorPos] + ld [wTempFilteredCardListNumCursorPositions], a call ConfirmDeckConfiguration - ld a, [wced5] - jr .asm_93b0 -.asm_93f0 - call Func_9efc - jr c, .asm_93d4 - call Func_9b25 - jr c, .asm_9442 - jr .asm_93d4 -.asm_93fc + ld a, [wTempFilteredCardListNumCursorPositions] + jr .wait_list_input + +.no_start_btn_2 + call HandleSelectUpAndDownInList + jr c, .loop_input + call HandleDeckCardSelectionList + jr c, .selection_made + jr .loop_input + +.open_card_page ld a, $01 call PlaySFXConfirmOrCancel - ld a, [wNamingScreenKeyboardHeight] - ld [wcfdf], a - ld a, [wNamingScreenCursorY] - ld [wced4], a - ld de, wceda - ld hl, wcfd8 + ld a, [wCardListNumCursorPositions] + ld [wTempCardListNumCursorPositions], a + ld a, [wCardListCursorPos] + ld [wTempCardListCursorPos], a + + ; set wFilteredCardList as current card list + ; and show card page screen + ld de, wFilteredCardList + ld hl, wCurCardListPtr ld [hl], e inc hl ld [hl], d - call Func_9c3f + call OpenCardPageFromCardList call DrawCardTypeIconsAndPrintCardCounts - ld hl, Data_9667 - call Func_9a6d - ld a, [wced3] - ld [wNamingScreenCursorY], a - call Func_9b20 + + ld hl, FiltersCardSelectionParams + call InitCardSelectionParams + ld a, [wCurCardTypeFilter] + ld [wTempCardTypeFilter], a + call DrawHorizontalListCursor_Visible call PrintDeckBuildingCardList - ld hl, Data_9670 - call Func_9a6d - ld a, [wcfdf] - ld [wNamingScreenKeyboardHeight], a - ld a, [wced4] - ld [wNamingScreenCursorY], a - jr .asm_93d4 -.asm_9442 - call Func_9c0e - ld a, [wNamingScreenCursorY] - ld [wced4], a + ld hl, FilteredCardListSelectionParams + call InitCardSelectionParams + ld a, [wTempCardListNumCursorPositions] + ld [wCardListNumCursorPositions], a + ld a, [wTempCardListCursorPos] + ld [wCardListCursorPos], a + jr .loop_input + +.selection_made + call DrawListCursor_Invisible + ld a, [wCardListCursorPos] + ld [wTempCardListCursorPos], a ld a, [hffb3] cp $ff - jr nz, .asm_93fc - ld hl, Data_9667 - call Func_9a6d - ld a, [wced3] - ld [wNamingScreenCursorY], a + jr nz, .open_card_page + ; cancelled + ld hl, FiltersCardSelectionParams + call InitCardSelectionParams + ld a, [wCurCardTypeFilter] + ld [wTempCardTypeFilter], a jp .wait_input ; 0x9461 -Func_9461: ; 9461 (2:5461) +OpenDeckConfigurationMenu: ; 9461 (2:5461) xor a - ld [wPrizeCardCursorPosition], a - ld de, wcfd1 + 5 + ld [wYourOrOppPlayAreaCurPosition], a + ld de, wDeckConfigurationMenuTransitionTable ld hl, wMenuInputTablePointer ld a, [de] ld [hli], a @@ -2909,10 +3456,10 @@ Func_9461: ; 9461 (2:5461) ld [hl], a ld a, $ff ld [wDuelInitialPrizesUpperBitsSet], a -.asm_9475 +.skip_init xor a ld [wCheckMenuCursorBlinkCounter], a - ld hl, wcfd1 + 3 + ld hl, wDeckConfigurationMenuHandlerFunction ld a, [hli] ld h, [hl] ld l, a @@ -2930,28 +3477,28 @@ HandleDeckConfigurationMenu: ; 9480 (2:5480) ld a, $1 ld [wVBlankOAMCopyToggle], a call DoFrame - call Func_89ae + call YourOrOppPlayAreaScreen_HandleInput jr nc, .do_frame ld [wced6], a cp $ff jr nz, .asm_94b5 .draw_icons call DrawCardTypeIconsAndPrintCardCounts - ld a, [wced4] - ld [wNamingScreenCursorY], a - ld a, [wced3] - call Func_993d - jp Func_9345.skip_draw + ld a, [wTempCardListCursorPos] + ld [wCardListCursorPos], a + ld a, [wCurCardTypeFilter] + call PrintFilteredCardList + jp HandleDeckBuildScreen.skip_draw .asm_94b5 push af - call Func_89ae.draw_cursor + call YourOrOppPlayAreaScreen_HandleInput.draw_cursor ld a, $01 ld [wVBlankOAMCopyToggle], a pop af ld hl, .func_table call JumpToFunctionInTable - jr Func_9461.asm_9475 + jr OpenDeckConfigurationMenu.skip_init .func_table dw ConfirmDeckConfiguration ; Confirm @@ -2963,25 +3510,25 @@ HandleDeckConfigurationMenu: ; 9480 (2:5480) ; 0x94d3 ConfirmDeckConfiguration: ; 94d3 (2:54d3) - ld hl, wcea1 + ld hl, wCardListVisibleOffset ld a, [hl] ld hl, wced8 ld [hl], a - call Func_9e41 + call HandleDeckConfirmationMenu ld hl, wced8 ld a, [hl] - ld hl, wcea1 + ld hl, wCardListVisibleOffset ld [hl], a call DrawCardTypeIconsAndPrintCardCounts - ld hl, Data_9667 - call Func_9a6d - ld a, [wced3] - ld [wNamingScreenCursorY], a - call Func_9b20 - ld a, [wced3] - call Func_993d + ld hl, FiltersCardSelectionParams + call InitCardSelectionParams + ld a, [wCurCardTypeFilter] + ld [wTempCardTypeFilter], a + call DrawHorizontalListCursor_Visible + ld a, [wCurCardTypeFilter] + call PrintFilteredCardList ld a, [wced6] - ld [wNamingScreenCursorY], a + ld [wCardListCursorPos], a ret ; 0x9505 @@ -2990,23 +3537,25 @@ ModifyDeckConfiguration: ; 9505 (2:5505) jr HandleDeckConfigurationMenu.draw_icons ; 0x9509 -; returns carry set if player chose to save deck +; returns carry set if player chose to go back CancelDeckModifications: ; 9509 (2:5509) - call Func_95c1 - jr nc, .asm_9516 +; if deck was not changed, cancel modification immediately + call CheckIfCurrentDeckWasChanged + jr nc, .cancel_modification +; else prompt the player to confirm ldtx hl, QuitModifyingTheDeckText call YesOrNoMenuWithText jr c, SaveDeckConfiguration.go_back -.asm_9516 +.cancel_modification add sp, $2 or a ret SaveDeckConfiguration: ; 951a (2:551a) ; handle deck configuration size - ld a, [wcecc] + ld a, [wTotalCardCount] cp DECK_SIZE - jp z, .ask_to_save_deck ; should be jr + jp z, .ask_to_save_deck ; can be jr ldtx hl, ThisIsntA60CardDeckText call DrawWideTextBox_WaitForInput ldtx hl, ReturnToOriginalConfigurationText @@ -3025,7 +3574,7 @@ SaveDeckConfiguration: ; 951a (2:551a) ldtx hl, SaveThisDeckText call YesOrNoMenuWithText jr c, .go_back - call Func_9649 + call CheckIfThereAreAnyBasicCardsInDeck jr c, .set_carry ldtx hl, ThereAreNoBasicPokemonInThisDeckText call DrawWideTextBox_WaitForInput @@ -3036,7 +3585,7 @@ SaveDeckConfiguration: ; 951a (2:551a) call DrawCardTypeIconsAndPrintCardCounts call PrintDeckBuildingCardList ld a, [wced6] - ld [wNamingScreenCursorY], a + ld [wCardListCursorPos], a ret .set_carry @@ -3049,20 +3598,20 @@ DismantleDeck: ; 9566 (2:5566) ldtx hl, DismantleThisDeckText call YesOrNoMenuWithText jr c, SaveDeckConfiguration.go_back - call Func_9622 - jp nc, .Dismantle ; should be jr + call CheckIfHasOtherValidDecks + jp nc, .Dismantle ; can be jr ldtx hl, ThereIsOnly1DeckSoCannotBeDismantledText call DrawWideTextBox_WaitForInput call EmptyScreen - ld hl, Data_9667 - call Func_9a6d - ld a, [wced3] - ld [wNamingScreenCursorY], a - call Func_9b20 + ld hl, FiltersCardSelectionParams + call InitCardSelectionParams + ld a, [wCurCardTypeFilter] + ld [wTempCardTypeFilter], a + call DrawHorizontalListCursor_Visible call PrintDeckBuildingCardList call EnableLCD ld a, [wced6] - ld [wNamingScreenCursorY], a + ld [wCardListCursorPos], a ret .Dismantle @@ -3074,7 +3623,7 @@ DismantleDeck: ; 9566 (2:5566) ld a, NAME_BUFFER_LENGTH call ClearNBytesFromHL call GetPointerToDeckCards - call Func_9152 + call AddDeckToCollection ld a, DECK_SIZE call ClearNBytesFromHL .done_dismantle @@ -3084,40 +3633,42 @@ DismantleDeck: ; 9566 (2:5566) ; 0x95b9 ChangeDeckName: ; 95b9 (2:55b9) - call Func_8f05 + call InputCurDeckName add sp, $2 - jp Func_9345.skip_count + jp HandleDeckBuildScreen.skip_count ; 0x95c1 -Func_95c1: ; 95c1 (2:55c1) - ld a, [wcecc] +; returns carry if current deck was changed +; either through its card configuration or its name +CheckIfCurrentDeckWasChanged: ; 95c1 (2:55c1) + ld a, [wTotalCardCount] or a jr z, .skip_size_check cp DECK_SIZE - jr nz, .done + jr nz, .set_carry .skip_size_check -; copy the selected deck to wc590 +; copy the selected deck to wCurDeckCardChanges call GetPointerToDeckCards - ld de, wc590 + ld de, wCurDeckCardChanges ld b, DECK_SIZE call EnableSRAM call CopyNBytesFromHLToDE call DisableSRAM -; loops through cards in wcf17 -; then if that card is found in wc590 +; loops through cards in wCurDeckCards +; then if that card is found in wCurDeckCardChanges ; overwrite it by $0 ld a, $ff ld [wc5cc], a - ld de, wcf17 + ld de, wCurDeckCards .loop_outer ld a, [de] or a jr z, .check_empty ld b, a inc de - ld hl, wc590 + ld hl, wCurDeckCardChanges .loop_inner ld a, [hli] cp $ff @@ -3131,70 +3682,81 @@ Func_95c1: ; 95c1 (2:55c1) jr .loop_outer .check_empty - ld hl, wc590 + ld hl, wCurDeckCardChanges .loop_check_empty ld a, [hli] cp $ff jr z, .is_empty or a - jr nz, .done + jr nz, .set_carry jr .loop_check_empty -; wc590 is empty (all $0) .is_empty +; wCurDeckCardChanges is empty (all $0) +; check if name was changed call GetPointerToDeckName - ld de, wcfb9 + ld de, wCurDeckName call EnableSRAM -.asm_9610 +.loop_name ld a, [de] cp [hl] - jr nz, .done + jr nz, .set_carry inc de inc hl or a - jr nz, .asm_9610 + jr nz, .loop_name call DisableSRAM ret -.done + +.set_carry call DisableSRAM scf ret ; 0x9622 -Func_9622: ; 9622 (2:5622) - ld hl, wceb2 - ld bc, $0 +; returns carry if doesn't have a valid deck +; aside from the current deck +CheckIfHasOtherValidDecks: ; 9622 (2:5622) + ld hl, wDecksValid + lb bc, 0, 0 .loop inc b - ld a, $04 + ld a, NUM_DECKS cp b - jr c, .asm_963a + jr c, .check_has_cards ld a, [hli] or a jr z, .loop + ; is valid inc c - ld a, $01 + ld a, 1 cp c - jr nc, .loop + jr nc, .loop ; just 1 valid + ; at least 2 decks are valid .no_carry or a ret -.asm_963a + +.check_has_cards +; doesn't have at least 2 valid decks +; check if current deck is the only one +; that is valid (i.e. has cards) call GetPointerToDeckCards call EnableSRAM ld a, [hl] call DisableSRAM or a - jr z, .no_carry + jr z, .no_carry ; no cards + ; has cards, is the only valid deck! scf ret ; 0x9649 -; checks if wcf17 has any basics +; checks if wCurDeckCards has any basics ; returns carry set if there is at least ; 1 Basic Pokemon card -Func_9649: ; 9649 (2:5649) - ld hl, wcf17 +CheckIfThereAreAnyBasicCardsInDeck: ; 9649 (2:5649) + ld hl, wCurDeckCards .loop_cards ld a, [hli] ld e, a @@ -3216,11 +3778,25 @@ Func_9649: ; 9649 (2:5649) ret ; 0x9667 -Data_9667: ; 9667 (2:5667) - db $01, $01, $00, $02, $09, $2f, $00, $00, $00 - -Data_9670: ; 9670 (2:5670) - db $00, $07, $02, $00, $06, $0f, $00, $00, $00 +FiltersCardSelectionParams: ; 9667 (2:5667) + db 1 ; x pos + db 1 ; y pos + db 0 ; y spacing + db 2 ; x spacing + db NUM_FILTERS ; num entries + db SYM_CURSOR_D ; visible cusor tile + db SYM_SPACE ; invisible cusor tile + dw NULL ; wCardListHandlerFunction + +FilteredCardListSelectionParams: ; 9670 (2:5670) + db 0 ; x pos + db 7 ; y pos + db 2 ; y spacing + db 0 ; x spacing + db NUM_FILTERED_LIST_VISIBLE_CARDS ; num entries + db SYM_CURSOR_R ; visible cursor tile + db SYM_SPACE ; invisible cursor tile + dw NULL ; wCardListHandlerFunction DeckConfigurationMenu_TransitionTable: ; 9679 (2:5679) cursor_transition $10, $20, $00, $03, $03, $01, $02 @@ -3269,10 +3845,10 @@ FillBGMapLineWithA: ; 96c7 (2:56c7) ret ; 0x96e3 -; saves the count of each type of card that is in wcf17 -; stores these values in wcebb +; saves the count of each type of card that is in wCurDeckCards +; stores these values in wCardFilterCounts CountNumberOfCardsForEachCardType: ; 96e3 (2:56e3) - ld hl, wcebb + ld hl, wCardFilterCounts ld de, CardTypeFilters .loop ld a, [de] @@ -3411,13 +3987,13 @@ CreateFilteredCardList: ; 978b (2:578b) .loop_card_ids inc e call GetCardType - jr c, .add_terminator_byte + jr c, .store_count ld c, a ld a, b cp $ff jr z, .add_card - and $20 - cp $20 + and FILTER_ENERGY + cp FILTER_ENERGY jr z, .check_energy ld a, c cp b @@ -3456,9 +4032,9 @@ CreateFilteredCardList: ; 978b (2:578b) pop bc jr .loop_card_ids -.add_terminator_byte +.store_count ld a, l - ld [wceab + 3], a + ld [wNumEntriesInCurFilter], a ; add terminator bytes in both lists xor a ld c, l @@ -3544,13 +4120,12 @@ ClearNBytesFromHL: ; 9843 (2:5843) ret ; 0x9850 -; finds instance of e in list wcf17 -; returns the position in the list that it was found -; if not found, returns last position + 1 -Func_9850: ; 9850 (2:5850) +; returns the number of times that card e +; appears in wCurDeckCards +GetCountOfCardInCurDeck: ; 9850 (2:5850) push hl - ld hl, wcf17 - ld d, $00 + ld hl, wCurDeckCards + ld d, 0 .loop ld a, [hli] or a @@ -3613,7 +4188,7 @@ AppendOwnedCardCountAndStorageCountNumbers: ; 9880 (2:5880) jr .loop .print push de - call Func_9850 + call GetCountOfCardInCurDeck call ConvertToNumericalDigits ld [hl], TX_SYMBOL inc hl @@ -3689,7 +4264,7 @@ ConvertToNumericalDigits: ; 98c7 (2:58c7) ret ; 0x98dc -; counts the number of cards in wcf17 +; counts the number of cards in wCurDeckCards ; that are the same type as input in register a ; if input is $20, counts all energy cards instead ; input: @@ -3705,7 +4280,7 @@ CountNumberOfCardsOfType: ; 98dc (2:58dc) .loop_cards push hl push bc - ld bc, wcf17 + ld bc, wCurDeckCards add hl, bc ld a, [hl] pop bc @@ -3715,7 +4290,7 @@ CountNumberOfCardsOfType: ; 98dc (2:58dc) jr z, .done ; end of card list ; get card type and compare it with input type -; if input is $20, run a separate comparison +; if input is FILTER_ENERGY, run a separate comparison ; if it's the same type, increase the count ld e, a call GetCardType @@ -3723,8 +4298,8 @@ CountNumberOfCardsOfType: ; 98dc (2:58dc) push hl ld l, a ld a, b - and $20 - cp $20 + and FILTER_ENERGY + cp FILTER_ENERGY jr z, .check_energy ld a, l pop hl @@ -3758,7 +4333,7 @@ PrintCardTypeCounts: ; 9916 (2:5916) ld hl, wDefaultText .loop push hl - ld hl, wcebb + ld hl, wCardFilterCounts add hl, bc ld a, [hl] pop hl @@ -3766,7 +4341,7 @@ PrintCardTypeCounts: ; 9916 (2:5916) call ConvertToNumericalDigits pop bc inc c - ld a, $9 + ld a, NUM_FILTERS cp c jr nz, .loop ld [hl], TX_END @@ -3777,7 +4352,10 @@ PrintCardTypeCounts: ; 9916 (2:5916) ret ; 0x993d -Func_993d: ; 993d (2:593d) +; prints the list of cards, applying the filter from register a +; the counts of each card displayed is taken from wCurDeck +; a = card type filter +PrintFilteredCardList: ; 993d (2:593d) push af ld hl, CardTypeFilters ld b, $00 @@ -3790,24 +4368,25 @@ Func_993d: ; 993d (2:593d) call EnableSRAM ld hl, sCardCollection ld de, wTempCardCollection - ld b, $ff + ld b, CARD_COLLECTION_SIZE - 1 call CopyNBytesFromHLToDE call DisableSRAM - ld a, [wcfd1 + 2] + ld a, [wIncludeCardsInDeck] or a jr z, .ok call GetPointerToDeckCards ld d, h ld e, l - call GetDeckCardCounts + call IncrementDeckCardsInTempCollection .ok pop af + call CreateFilteredCardList - ld a, $06 - ld [wcecb], a - lb de, 1 ,7 - ld hl, wced0 + ld a, NUM_FILTERED_LIST_VISIBLE_CARDS + ld [wNumVisibleCardListEntries], a + lb de, 1, 7 + ld hl, wCardListCoords ld [hl], e inc hl ld [hl], d @@ -3818,36 +4397,36 @@ Func_993d: ; 993d (2:593d) ; used to filter the cards in the deck building/card selection screen CardTypeFilters: ; 997d (2:597d) - db TYPE_PKMN_GRASS - db TYPE_PKMN_FIRE - db TYPE_PKMN_WATER - db TYPE_PKMN_LIGHTNING - db TYPE_PKMN_FIGHTING - db TYPE_PKMN_PSYCHIC - db TYPE_PKMN_COLORLESS - db TYPE_TRAINER - db $20 + db FILTER_GRASS + db FILTER_FIRE + db FILTER_WATER + db FILTER_LIGHTNING + db FILTER_FIGHTING + db FILTER_PSYCHIC + db FILTER_COLORLESS + db FILTER_TRAINER + db FILTER_ENERGY db -1 ; end of list ; 0x9987 ; counts all the cards from each card type -; (stored in wcebb) and store it in wcecc +; (stored in wCardFilterCounts) and store it in wTotalCardCount ; also prints it in coordinates de PrintTotalCardCount: ; 9987 (2:5987) push de ld bc, $0 - ld hl, wcebb + ld hl, wCardFilterCounts .loop ld a, [hli] add b ld b, a inc c - ld a, $9 + ld a, NUM_FILTERS cp c jr nz, .loop ld hl, wDefaultText ld a, b - ld [wcecc], a + ld [wTotalCardCount], a push bc call ConvertToNumericalDigits pop bc @@ -3867,14 +4446,14 @@ PrintTotalCardCount: ; 9987 (2:5987) ; and Y is the storage count of that card PrintDeckBuildingCardList: ; 99b0 (2:59b0) push bc - ld hl, wced0 + ld hl, wCardListCoords ld e, [hl] inc hl ld d, [hl] ld b, 19 ; x coord ld c, e dec c - ld a, [wcea1] + ld a, [wCardListVisibleOffset] or a jr z, .no_cursor ld a, SYM_CURSOR_U @@ -3884,14 +4463,14 @@ PrintDeckBuildingCardList: ; 99b0 (2:59b0) .got_cursor_tile call WriteByteToBGMap0 -; iterates by decreasing value in wcecb +; iterates by decreasing value in wNumVisibleCardListEntries ; by 1 until it reaches 0 - ld a, [wcea1] + ld a, [wCardListVisibleOffset] ld c, a ld b, $0 ld hl, wFilteredCardList add hl, bc - ld a, [wcecb] + ld a, [wNumVisibleCardListEntries] .loop_filtered_cards push de or a @@ -3901,7 +4480,7 @@ PrintDeckBuildingCardList: ; 99b0 (2:59b0) or a jr z, .invalid_card ; card ID of 0 ld e, a - call Func_9a59 + call AddCardIDToVisibleList call LoadCardDataToBuffer1_FromCardID ld a, 13 push bc @@ -3941,14 +4520,14 @@ PrintDeckBuildingCardList: ; 99b0 (2:59b0) ; draw down cursor because ; there are still more cards ; to be scrolled down - xor a - ld [wcecd], a + xor a ; FALSE + ld [wUnableToScrollDown], a ld a, SYM_CURSOR_D jr .draw_cursor .cannot_scroll pop de - ld a, $01 - ld [wcecd], a + ld a, TRUE + ld [wUnableToScrollDown], a ld a, SYM_SPACE .draw_cursor ld b, 19 ; x coord @@ -4020,22 +4599,24 @@ Text_9a56: db TX_SYMBOL, TX_END Text_9a58: - db TX_END + done +; writes the card ID in register e to wVisibleListCardIDs +; given its position in the list in register b ; input: -; b = ? +; b = list position (starts from bottom) ; e = card ID -Func_9a59: ; 9a59 (2:5a59) +AddCardIDToVisibleList: ; 9a59 (2:5a59) push af push bc push hl - ld hl, wcec4 + ld hl, wVisibleListCardIDs ld c, b - ld a, [wcecb] + ld a, [wNumVisibleCardListEntries] sub c - ld c, a - ld b, $00 - add hl, bc ; = wcec4 + (wcecb - b) + ld c, a ; wNumVisibleCardListEntries - b + ld b, $0 + add hl, bc ld [hl], e pop hl pop bc @@ -4043,11 +4624,19 @@ Func_9a59: ; 9a59 (2:5a59) ret ; 0x9a6d -; copies 9 bytes from hl to wcea5 -Func_9a6d: ; 9a6d (2:5a6d) - ld [wNamingScreenCursorY], a +; copies data from hl to: +; wCardListCursorXPos +; wCardListCursorYPos +; wCardListYSpacing +; wCardListXSpacing +; wCardListNumCursorPositions +; wVisibleCursorTile +; wInvisibleCursorTile +; wCardListHandlerFunction +InitCardSelectionParams: ; 9a6d (2:5a6d) + ld [wCardListCursorPos], a ld [hffb3], a - ld de, wcea5 + ld de, wCardListCursorXPos ld b, $9 .loop ld a, [hli] @@ -4060,163 +4649,792 @@ Func_9a6d: ; 9a6d (2:5a6d) ret ; 0x9a83 -Func_9a83: ; 9a83 (2:5a83) - INCROM $9a83, $9ad7 +HandleCardSelectionInput: ; 9a83 (2:5a83) + xor a ; FALSE + ld [wPlaysSfx], a + ldh a, [hDPadHeld] + or a + jr z, .handle_ab_btns -Func_9ad7: ; 9ad7 (2:5ad7) - call Func_9b20 +; handle d-pad + ld b, a + ld a, [wCardListNumCursorPositions] + ld c, a + ld a, [wCardListCursorPos] + bit D_LEFT_F, b + jr z, .check_d_right + dec a + bit 7, a + jr z, .got_cursor_pos + ; if underflow, set to max cursor pos + ld a, [wCardListNumCursorPositions] + dec a + jr .got_cursor_pos +.check_d_right + bit D_RIGHT_F, b + jr z, .handle_ab_btns + inc a + cp c + jr c, .got_cursor_pos + ; if over max pos, set to pos 0 + xor a +.got_cursor_pos + push af + ld a, TRUE + ld [wPlaysSfx], a + call DrawHorizontalListCursor_Invisible + pop af + ld [wCardListCursorPos], a + xor a + ld [wCheckMenuCursorBlinkCounter], a + +.handle_ab_btns + ld a, [wCardListCursorPos] + ld [hffb3], a + ldh a, [hKeysPressed] + and A_BUTTON | B_BUTTON + jr z, HandleCardSelectionCursorBlink + and A_BUTTON + jr nz, ConfirmSelectionAndReturnCarry + ; b button + ld a, $ff + ld [hffb3], a + call PlaySFXConfirmOrCancel + scf + ret +; 0x9ad7 + +; outputs cursor position in e and selection in a +ConfirmSelectionAndReturnCarry: ; 9ad7 (2:5ad7) + call DrawHorizontalListCursor_Visible ld a, $01 call PlaySFXConfirmOrCancel - ld a, [wNamingScreenCursorY] + ld a, [wCardListCursorPos] ld e, a ld a, [hffb3] scf ret ; 0x9ae8 - INCROM $9ae8, $9b03 +HandleCardSelectionCursorBlink: ; 9ae8 (2:5ae8) + ld a, [wPlaysSfx] + or a + jr z, .skip_sfx + call PlaySFX +.skip_sfx + ld hl, wCheckMenuCursorBlinkCounter + ld a, [hl] + inc [hl] + and $0f + ret nz + ld a, [wVisibleCursorTile] + bit 4, [hl] + jr z, DrawHorizontalListCursor +; 0x9b00 + +DrawHorizontalListCursor_Invisible: ; 9b00 (2:5b00) + ld a, [wInvisibleCursorTile] +; fallthrough -Func_9b03: ; 9b03 (2:5b03) +; like DrawListCursor but only +; for lists with one line, and each entry +; being laid horizontally +; a = tile to write +DrawHorizontalListCursor: ; 9b03 (2:5b03) ld e, a - ld a, [wcea5 + 3] + ld a, [wCardListXSpacing] ld l, a - ld a, [wNamingScreenCursorY] + ld a, [wCardListCursorPos] ld h, a call HtimesL ld a, l - ld hl, wcea5 + ld hl, wCardListCursorXPos add [hl] - ld b, a - ld hl, wcea5 + 1 + ld b, a ; x coord + ld hl, wCardListCursorYPos ld a, [hl] - ld c, a + ld c, a ; y coord ld a, e call WriteByteToBGMap0 or a ret ; 0x9b20 -Func_9b20: ; 9b20 (2:5b20) - ld a, [wceaa] - jr Func_9b03 +DrawHorizontalListCursor_Visible: ; 9b20 (2:5b20) + ld a, [wVisibleCursorTile] + jr DrawHorizontalListCursor ; 0x9b25 -Func_9b25: ; 9b25 (2:5b25) - INCROM $9b25, $9c0e +; handles user input when selecting cards to add +; to deck configuration +; returns carry if a selection was made +; (either selected card or cancelled) +; outputs in a the list index if selection was made +; or $ff if operation was cancelled +HandleDeckCardSelectionList: ; 9b25 (2:5b25) + xor a ; FALSE + ld [wPlaysSfx], a + + ldh a, [hDPadHeld] + or a + jp z, .asm_9bb9 -Func_9c0e: ; 9c0e (2:5c0e) - INCROM $9c0e, $9c11 + ld b, a + ld a, [wCardListNumCursorPositions] + ld c, a + ld a, [wCardListCursorPos] + bit D_UP_F, b + jr z, .check_d_down + push af + ld a, TRUE + ld [wPlaysSfx], a + pop af + dec a + bit 7, a + jr z, .asm_9b8f + ld a, [wCardListVisibleOffset] + or a + jr z, .asm_9b5a + dec a + ld [wCardListVisibleOffset], a + ld hl, wCardListUpdateFunction + call CallIndirect + xor a + jr .asm_9b8f +.asm_9b5a + xor a + ld [wPlaysSfx], a + jr .asm_9b8f +.check_d_down + bit D_DOWN_F, b + jr z, .asm_9b9d + push af + ld a, TRUE + ld [wPlaysSfx], a + pop af + inc a + cp c + jr c, .asm_9b8f + push af + ld a, [wUnableToScrollDown] + or a + jr nz, .cannot_scroll_down + ld a, [wCardListVisibleOffset] + inc a + ld [wCardListVisibleOffset], a + ld hl, wCardListUpdateFunction + call CallIndirect + pop af + dec a + jr .asm_9b8f + +.cannot_scroll_down + pop af + dec a + push af + xor a ; FALSE + ld [wPlaysSfx], a + pop af + +.asm_9b8f + push af + call DrawListCursor_Invisible + pop af + ld [wCardListCursorPos], a + xor a + ld [wCheckMenuCursorBlinkCounter], a + jr .asm_9bb9 +.asm_9b9d + ld a, [wced2] + or a + jr z, .asm_9bb9 + + bit D_LEFT_F, b + jr z, .check_d_right + call GetSelectedVisibleCardID + call RemoveCardFromDeckAndUpdateCount + jr .asm_9bb9 +.check_d_right + bit D_RIGHT_F, b + jr z, .asm_9bb9 + call GetSelectedVisibleCardID + call AddCardToDeckAndUpdateCount + +.asm_9bb9 + ld a, [wCardListCursorPos] + ld [hffb3], a + ld hl, wCardListHandlerFunction + ld a, [hli] + or [hl] + jr z, .handle_ab_btns + + ; this code seemingly never runs + ; because wCardListHandlerFunction is always NULL + ld a, [hld] + ld l, [hl] + ld h, a + ld a, [hffb3] + call CallHL + jr nc, .handle_blink + +.select_card + call DrawListCursor_Visible + ld a, $01 + call PlaySFXConfirmOrCancel + ld a, [wCardListCursorPos] + ld e, a + ld a, [hffb3] + scf + ret + +.handle_ab_btns + ldh a, [hKeysPressed] + and A_BUTTON | B_BUTTON + jr z, .check_sfx + and A_BUTTON + jr nz, .select_card + ld a, $ff + ld [hffb3], a + call PlaySFXConfirmOrCancel + scf + ret + +.check_sfx + ld a, [wPlaysSfx] + or a + jr z, .handle_blink + call PlaySFX +.handle_blink + ld hl, wCheckMenuCursorBlinkCounter + ld a, [hl] + inc [hl] + and $0f + ret nz + ld a, [wVisibleCursorTile] + bit 4, [hl] + jr z, DrawListCursor +; fallthrough + +DrawListCursor_Invisible: ; 9c0e (2:5c0e) + ld a, [wInvisibleCursorTile] +; fallthrough + +; draws cursor considering wCardListCursorPos +; spaces each entry horizontally by wCardListXSpacing +; and vertically by wCardListYSpacing ; a = tile to write -Func_9c11: ; 9c11 (2:5c11) +DrawListCursor: ; 9c11 (2:5c11) ld e, a - ld a, [wcea5 + 3] + ld a, [wCardListXSpacing] ld l, a - ld a, [wNamingScreenCursorY] + ld a, [wCardListCursorPos] ld h, a call HtimesL ld a, l - ld hl, wcea5 + ld hl, wCardListCursorXPos add [hl] - ld b, a - ld a, [wcea5 + 2] + ld b, a ; x coord + ld a, [wCardListYSpacing] ld l, a - ld a, [wNamingScreenCursorY] + ld a, [wCardListCursorPos] ld h, a call HtimesL ld a, l - ld hl, wcea5 + 1 + ld hl, wCardListCursorYPos add [hl] - ld c, a + ld c, a ; y coord ld a, e call WriteByteToBGMap0 or a ret ; 0x9c3a -Func_9c3a: ; 9c3a (2:5c3a) - ld a, [wceaa] - jr Func_9c11 +DrawListCursor_Visible: ; 9c3a (2:5c3a) + ld a, [wVisibleCursorTile] + jr DrawListCursor ; 0x9c3f -Func_9c3f: ; 9c3f (2:5c3f) - INCROM $9c3f, $9e31 +OpenCardPageFromCardList: ; 9c3f (2:5c3f) +; get the card index that is selected +; and open its card page + ld hl, wCurCardListPtr + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [wCardListCursorPos] + ld c, a + ld b, $0 + add hl, bc + ld a, [wCardListVisibleOffset] + ld c, a + ld b, $0 + add hl, bc + ld e, [hl] + ld d, $0 + push de + call LoadCardDataToBuffer1_FromCardID + lb de, $38, $9f + call SetupText + bank1call OpenCardPage_FromCheckHandOrDiscardPile + pop de -Func_9e31: ; 9e31 (2:5e31) +.handle_input + ldh a, [hDPadHeld] + ld b, a + and A_BUTTON | B_BUTTON | SELECT | START + jp nz, .exit + +; check d-pad +; if UP or DOWN is pressed, change the +; card that is being shown, given the +; order in the current card list + xor a ; FALSE + ld [wPlaysSfx], a + ld a, [wCardListNumCursorPositions] + ld c, a + ld a, [wCardListCursorPos] + bit D_UP_F, b + jr z, .check_d_down + push af + ld a, TRUE + ld [wPlaysSfx], a + pop af + dec a + bit 7, a + jr z, .reopen_card_page + ld a, [wCardListVisibleOffset] + or a + jr z, .handle_regular_card_page_input + dec a + ld [wCardListVisibleOffset], a + xor a + jr .reopen_card_page + +.check_d_down + bit D_DOWN_F, b + jr z, .handle_regular_card_page_input + push af + ld a, TRUE + ld [wPlaysSfx], a + pop af + inc a + cp c + jr c, .reopen_card_page + push af + ld hl, wCurCardListPtr + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [wCardListCursorPos] + ld c, a + ld b, $0 + add hl, bc + ld a, [wCardListVisibleOffset] + inc a + ld c, a + ld b, $0 + add hl, bc + ld a, [hl] + or a + jr z, .skip_change_card + ld a, [wCardListVisibleOffset] + inc a + ld [wCardListVisibleOffset], a + pop af + dec a +.reopen_card_page + ld [wCardListCursorPos], a + ld a, [wPlaysSfx] + or a + jp z, OpenCardPageFromCardList + call PlaySFX + jp OpenCardPageFromCardList + +.skip_change_card + pop af + jr .handle_regular_card_page_input ; unnecessary jr +.handle_regular_card_page_input + push de + bank1call OpenCardPage.input_loop + pop de + jp .handle_input + +.exit + ld a, $1 + ld [wVBlankOAMCopyToggle], a + ld a, [wCardListCursorPos] + ld [wTempCardListCursorPos], a + ret +; 0x9ced + +; opens card page from the card list +; unreferenced? +Func_9ced: ; 9ced (2:5ced) + ld hl, wVisibleListCardIDs + ld a, [wCardListCursorPos] + ld c, a + ld b, $00 + add hl, bc + ld e, [hl] + inc hl + ld d, [hl] + call LoadCardDataToBuffer1_FromCardID + ld de, $389f + call SetupText + bank1call OpenCardPage_FromHand + ld a, $01 + ld [wVBlankOAMCopyToggle], a + ret +; 0x9d0c + +; adds card in register e to deck configuration +; and updates the values shown for its count +; in the card selection list +; input: +; e = card ID +AddCardToDeckAndUpdateCount: ; 9d0c (2:5d0c) + call TryAddCardToDeck + ret c ; failed to add card + push de + call PrintCardTypeCounts + lb de, 15, 0 + call PrintTotalCardCount + pop de + call GetCountOfCardInCurDeck + call PrintNumberValueInCursorYPos + ret +; 0x9d22 + +; tries to add card ID in register e to wCurDeckCards +; fails to add card if one of the following conditions are met: +; - total cards are equal to wMaxNumCardsAllowed +; - cards with the same name as it reached the allowed limit +; - player doesn't own more copies in the collection +; returns carry if fails +; otherwise, writes card ID to first empty slot in wCurDeckCards +; input: +; e = card ID +TryAddCardToDeck: ; 9d22 (2:5d22) + ld a, [wMaxNumCardsAllowed] + ld d, a + ld a, [wTotalCardCount] + cp d + jr nz, .not_equal + ; wMaxNumCardsAllowed == wTotalCardCount + scf + ret + +.not_equal + push de + call .CheckIfCanAddCardWithSameName + pop de + ret c ; cannot add more cards with this name + + push de + call GetCountOfCardInCurDeck + ld b, a + ld hl, wOwnedCardsCountList + ld d, $0 + ld a, [wCardListVisibleOffset] + ld e, a + add hl, de + ld a, [wCardListCursorPos] + ld e, a + add hl, de + ld d, [hl] + ld a, b + cp d + pop de + scf + ret z ; cannot add because player doesn't own more copies + + ld a, SFX_01 + call PlaySFX + push de + call .AddCardToCurDeck + ld a, [wCurCardTypeFilter] + ld c, a + ld b, $0 + ld hl, wCardFilterCounts + add hl, bc + inc [hl] + pop de + or a + ret + +; finds first empty slot in wCurDeckCards +; then writes the value in e to it +.AddCardToCurDeck + ld hl, wCurDeckCards +.loop + ld a, [hl] + or a + jr z, .empty + inc hl + jr .loop +.empty + ld [hl], e + inc hl + xor a + ld [hl], a + ret + +; returns carry if card ID in e cannot be +; added to the current deck configuration +; due to having reached the maximum number +; of cards allowed with that same name +; e = card id +.CheckIfCanAddCardWithSameName + call LoadCardDataToBuffer1_FromCardID + ld a, [wLoadedCard1Type] + cp TYPE_ENERGY_DOUBLE_COLORLESS + jr z, .double_colorless + ; basic energy cards have no limit + and TYPE_ENERGY + cp TYPE_ENERGY + jr z, .exit ; return if basic energy card +.double_colorless + +; compare this card's name to +; the names of cards in list wCurDeckCards + ld a, [wLoadedCard1Name + 0] + ld c, a + ld a, [wLoadedCard1Name + 1] + ld b, a + ld hl, wCurDeckCards + ld d, 0 + push de +.loop_cards + ld a, [hli] + or a + jr z, .exit_pop_de + ld e, a + ld d, $0 + call GetCardName + ld a, e + cp c + jr nz, .loop_cards + ld a, d + cp b + jr nz, .loop_cards + ; has same name + pop de + inc d ; increment counter of cards with this name + ld a, [wSameNameCardsLimit] + cp d + push de + jr nz, .loop_cards + ; reached the maximum number + ; of cards with same name allowed + pop de + scf + ret + +.exit_pop_de + pop de +.exit + or a + ret +; 0x9db3 + +; gets the element in wVisibleListCardIDs +; corresponding to index wCardListCursorPos +GetSelectedVisibleCardID: ; 9db3 (2:5db3) + ld hl, wVisibleListCardIDs + ld a, [wCardListCursorPos] + ld e, a + ld d, $00 + add hl, de + ld e, [hl] + ret +; 0x9dbf + +; appends the digits of value in register a to wDefaultText +; then prints it in cursor Y position +; a = value to convert to numerical digits +PrintNumberValueInCursorYPos: ; 9dbf (2:5dbf) + ld hl, wDefaultText + call ConvertToNumericalDigits + ld [hl], TX_END + ld a, [wCardListYSpacing] + ld l, a + ld a, [wCardListCursorPos] + ld h, a + call HtimesL + ld a, l + ld hl, wCardListCursorYPos + add [hl] + ld e, a + ld d, 14 + call InitTextPrinting + ld hl, wDefaultText + call ProcessText + ret +; 0x9de4 + +; removes card in register e from deck configuration +; and updates the values shown for its count +; in the card selection list +; input: +; e = card ID +RemoveCardFromDeckAndUpdateCount: ; 9de4 (2:5de4) + call RemoveCardFromDeck + ret nc + push de + call PrintCardTypeCounts + lb de, 15, 0 + call PrintTotalCardCount + pop de + call GetCountOfCardInCurDeck + call PrintNumberValueInCursorYPos + ret +; 0x9dfa + +; removes card ID in e from wCurDeckCards +RemoveCardFromDeck: ; 9dfa (2:5dfa) + push de + call GetCountOfCardInCurDeck + pop de + or a + ret z ; card is not in deck + ld a, SFX_01 + call PlaySFX + push de + call .RemoveCard + ld a, [wCurCardTypeFilter] + ld c, a + ld b, $0 + ld hl, wCardFilterCounts + add hl, bc + dec [hl] + pop de + scf + ret + +; remove first card instance of card ID in e +; and shift all elements up by one +.RemoveCard + ld hl, wCurDeckCards + ld d, 0 ; unnecessary +.loop_1 + inc d ; unnecessary + ld a, [hli] + cp e + jr nz, .loop_1 + ld c, l + ld b, h + dec bc + +.loop_2 + inc d ; unnecessary + ld a, [hli] + or a + jr z, .done + ld [bc], a + inc bc + jr .loop_2 + +.done + xor a + ld [bc], a + ret +; 0x9e31 + +UpdateConfirmationCardScreen: ; 9e31 (2:5e31) ld hl, hffb0 ld [hl], $01 - call Func_9fc0 + call PrintCurDeckNumberAndName ld hl, hffb0 ld [hl], $00 jp PrintConfirmationCardList ; 0x9e41 -Func_9e41: ; 9e41 (2:5e41) - ld a, [wcecc] +HandleDeckConfirmationMenu: ; 9e41 (2:5e41) +; if deck is empty, just show deck info header with empty card list + ld a, [wTotalCardCount] or a - jp z, Func_9f40 - call Func_a028 - call Func_a06e + jp z, ShowDeckInfoHeaderAndWaitForBButton + +; create list of all unique cards + call SortCurDeckCardsByID + call CreateCurDeckUniqueCardList xor a - ld [wcea1], a -.asm_9e52 - ld hl, Data_9eaf - call Func_9a6d - ld a, [wced9] - ld [wcfe4+ 2], a - cp $07 - jr c, .asm_9e64 - ld a, $07 -.asm_9e64 - ld [wNamingScreenKeyboardHeight], a - ld [wcecb], a - call Func_9f52 - ld hl, Func_9e31 + ld [wCardListVisibleOffset], a +.init_params + ld hl, .CardSelectionParams + call InitCardSelectionParams + ld a, [wNumUniqueCards] + ld [wNumCardListEntries], a + cp NUM_DECK_CONFIRMATION_VISIBLE_CARDS + jr c, .no_cap + ld a, NUM_DECK_CONFIRMATION_VISIBLE_CARDS +.no_cap + ld [wCardListNumCursorPositions], a + ld [wNumVisibleCardListEntries], a + call ShowConfirmationCardScreen + + ld hl, UpdateConfirmationCardScreen ld d, h ld a, l - ld hl, wcece + ld hl, wCardListUpdateFunction ld [hli], a ld [hl], d + xor a ld [wced2], a -.asm_9e7b +.loop_input call DoFrame - call Func_9b25 - jr c, .asm_9ea7 - call Func_9eb8 - jr c, .asm_9e7b + call HandleDeckCardSelectionList + jr c, .selection_made + call HandleLeftRightInCardList + jr c, .loop_input ldh a, [hDPadHeld] and START - jr z, .asm_9e7b + jr z, .loop_input -.asm_9e8e +.selected_card ld a, $01 call PlaySFXConfirmOrCancel - ld a, [wNamingScreenCursorY] + ld a, [wCardListCursorPos] ld [wced7], a + + ; set wOwnedCardsCountList as current card list + ; and show card page screen ld de, wOwnedCardsCountList - ld hl, wcfd8 + ld hl, wCurCardListPtr ld [hl], e inc hl ld [hl], d - call Func_9c3f - jr .asm_9e52 + call OpenCardPageFromCardList + jr .init_params -.asm_9ea7 +.selection_made ld a, [hffb3] cp $ff - ret z - jr .asm_9e8e -; 0x9eaf - -Data_9eaf: - db $00, $05, $02, $00, $07, $0f, $00, $00, $00 - -Func_9eb8: ; 9eb8 (2:5eb8) - ld a, [wNamingScreenKeyboardHeight] + ret z ; operation cancelled + jr .selected_card + +.CardSelectionParams + db 0 ; x pos + db 5 ; y pos + db 2 ; y spacing + db 0 ; x spacing + db 7 ; num entries + db SYM_CURSOR_R ; visible cursor tile + db SYM_SPACE ; invisible cursor tile + dw NULL ; wCardListHandlerFunction +; 0x9eb8 + +; handles pressing left/right in card lists +; scrolls up/down a number of wCardListNumCursorPositions +; entries respectively +; returns carry if scrolling happened +HandleLeftRightInCardList: ; 9eb8 (2:5eb8) + ld a, [wCardListNumCursorPositions] ld d, a - ld a, [wcea1] + ld a, [wCardListVisibleOffset] ld c, a ldh a, [hDPadHeld] cp D_RIGHT @@ -4227,43 +5445,92 @@ Func_9eb8: ; 9eb8 (2:5eb8) ret .right - ld a, [wcea1] + ld a, [wCardListVisibleOffset] add d ld b, a add d - ld hl, wcfe4 + 2 + ld hl, wNumCardListEntries cp [hl] - jr c, .asm_9ee8 - ld a, [wcfe4 + 2] + jr c, .got_new_pos + ld a, [wNumCardListEntries] sub d ld b, a - jr .asm_9ee8 + jr .got_new_pos .left - ld a, [wcea1] + ld a, [wCardListVisibleOffset] sub d ld b, a - jr nc, .asm_9ee8 - ld b, $00 -.asm_9ee8 + jr nc, .got_new_pos + ld b, 0 ; first index +.got_new_pos ld a, b - ld [wcea1], a + ld [wCardListVisibleOffset], a cp c jr z, .asm_9efa ld a, SFX_01 call PlaySFX - ld hl, wcece + ld hl, wCardListUpdateFunction call CallIndirect .asm_9efa scf ret ; 0x9efc -Func_9efc: ; 9efc (2:5efc) - INCROM $9efc, $9f40 +; handles scrolling up and down with Select button +; in this case, the cursor position goes up/down +; by wCardListNumCursorPositions entries respectively +; return carry if scrolling happened, otherwise no carry +HandleSelectUpAndDownInList: ; 9efc (2:5efc) + ld a, [wCardListNumCursorPositions] + ld d, a + ld a, [wCardListVisibleOffset] + ld c, a + ldh a, [hDPadHeld] + cp SELECT | D_DOWN + jr z, .sel_down + cp SELECT | D_UP + jr z, .sel_up + or a + ret + +.sel_down + ld a, [wCardListVisibleOffset] + add d + ld b, a ; wCardListVisibleOffset + wCardListNumCursorPositions + add d + ld hl, wNumCardListEntries + cp [hl] + jr c, .got_new_pos + ld a, [wNumCardListEntries] + sub d + ld b, a ; wNumCardListEntries - wCardListNumCursorPositions + jr .got_new_pos +.sel_up + ld a, [wCardListVisibleOffset] + sub d + ld b, a ; wCardListVisibleOffset - wCardListNumCursorPositions + jr nc, .got_new_pos + ld b, 0 ; go to first position -Func_9f40: ; 9f40 (2:5f40) - call Func_9f81 +.got_new_pos + ld a, b + ld [wCardListVisibleOffset], a + cp c + jr z, .set_carry + ld a, SFX_01 + call PlaySFX + ld hl, wCardListUpdateFunction + call CallIndirect +.set_carry + scf + ret +; 0x9f40 + +; simply draws the deck info header +; then awaits a b button press to exit +ShowDeckInfoHeaderAndWaitForBButton: ; 9f40 (2:5f40) + call ShowDeckInfoHeader .wait_input call DoFrame ldh a, [hKeysPressed] @@ -4274,10 +5541,10 @@ Func_9f40: ; 9f40 (2:5f40) ret ; 0x9f52 -Func_9f52: ; 9f52 (2:5f52) - call Func_9f81 +ShowConfirmationCardScreen: ; 9f52 (2:5f52) + call ShowDeckInfoHeader lb de, 3, 5 - ld hl, wced0 + ld hl, wCardListCoords ld [hl], e inc hl ld [hl], d @@ -4285,18 +5552,18 @@ Func_9f52: ; 9f52 (2:5f52) ret ; 0x9f62 -; counts all values stored in wcebb +; counts all values stored in wCardFilterCounts ; if the total count is 0, then ; prints "No cards chosen." -Func_9f62: ; 9f62 (2:5f62) +TallyCardsInCardFilterLists: ; 9f62 (2:5f62) lb bc, 0, 0 - ld hl, wcebb + ld hl, wCardFilterCounts .loop ld a, [hli] add b ld b, a inc c - ld a, $9 + ld a, NUM_FILTERS cp c jr nz, .loop ld a, b @@ -4309,16 +5576,22 @@ Func_9f62: ; 9f62 (2:5f62) ret ; 0x9f81 -Func_9f81: ; 9f81 (2:5f81) - call Func_8d56 +; draws a box on the top of the screen +; with wCurDeck's number, name and card count +; and draws the Hand Cards icon if it's +; the current dueling deck +ShowDeckInfoHeader: ; 9f81 (2:5f81) + call EmptyScreenAndLoadFontDuelAndHandCardsIcons lb de, 0, 0 lb bc, 20, 4 call DrawRegularTextBox - ld a, [wcfb9] + ld a, [wCurDeckName] or a - jp z, .print_card_count ; should be jr - call Func_9fc0 - ld a, [wceb1] + jp z, .print_card_count ; can be jr + +; draw hand cards icon if it's the current dueling deck + call PrintCurDeckNumberAndName + ld a, [wCurDeck] ld b, a call EnableSRAM ld a, [sCurrentlySelectedDeck] @@ -4333,40 +5606,49 @@ Func_9f81: ; 9f81 (2:5f81) call PrintTotalCardCount lb de, 16, 1 call PrintSlashSixty - call Func_9f62 + call TallyCardsInCardFilterLists call EnableLCD ret ; 0x9fc0 -Func_9fc0: ; 9fc0 (2:5fc0) - ld a, [wceb1] +; prints the name of wCurDeck in the form +; "X· <deck name> deck", where X is the number +; of the deck in the given menu +; if no current deck, print blank line +PrintCurDeckNumberAndName: ; 9fc0 (2:5fc0) + ld a, [wCurDeck] cp $ff - jr z, .asm_9fea + jr z, .skip_deck_numeral + +; print the deck number in the menu +; in the form "X·" lb de, 3, 2 call InitTextPrinting - ld a, [wceb1] + ld a, [wCurDeck] bit 7, a - jr z, .asm_9fd8 + jr z, .incr_by_one and $7f - jr .asm_9fd9 -.asm_9fd8 + jr .got_deck_numeral +.incr_by_one inc a -.asm_9fd9 +.got_deck_numeral ld hl, wDefaultText call ConvertToNumericalDigits - ld [hl], $77 + ld [hl], "FW0_·" inc hl ld [hl], TX_END ld hl, wDefaultText call ProcessText -.asm_9fea - ld hl, wcfb9 +.skip_deck_numeral + ld hl, wCurDeckName ld de, wDefaultText call CopyListFromHLToDE - ld a, [wceb1] + ld a, [wCurDeck] cp $ff - jr z, .asm_a01b + jr z, .blank_deck_name + +; print "<deck name> deck" ld hl, wDefaultText call GetTextLengthInTiles ld b, $0 @@ -4374,7 +5656,7 @@ Func_9fc0: ; 9fc0 (2:5fc0) add hl, bc ld d, h ld e, l - ld hl, Data_92a7 + ld hl, DeckNameSuffix call CopyListFromHLToDE lb de, 6, 2 ld hl, wDefaultText @@ -4382,7 +5664,7 @@ Func_9fc0: ; 9fc0 (2:5fc0) call ProcessText ret -.asm_a01b +.blank_deck_name lb de, 2, 2 ld hl, wDefaultText call InitTextPrinting @@ -4390,14 +5672,17 @@ Func_9fc0: ; 9fc0 (2:5fc0) ret ; 0xa028 -Func_a028: ; a028 (2:6028) - ld hl, wcf17 +; sorts wCurDeckCards by ID +SortCurDeckCardsByID: ; a028 (2:6028) +; wOpponentDeck is used to temporarily store deck's cards +; so that it can be later sorted by ID + ld hl, wCurDeckCards ld de, wOpponentDeck ld bc, wDuelTempList ld a, -1 ld [bc], a .loop_copy - inc a + inc a ; incr deck index push af ld a, [hli] ld [de], a @@ -4405,14 +5690,16 @@ Func_a028: ; a028 (2:6028) or a jr z, .sort_cards pop af - ld [bc], a + ld [bc], a ; store deck index inc bc jr .loop_copy .sort_cards pop af - ld a, $ff + ld a, $ff ; terminator byte for wDuelTempList ld [bc], a + +; force Opp Turn so that SortCardsInDuelTempListByID can be used ldh a, [hWhoseTurn] push af ld a, OPPONENT_TURN @@ -4421,9 +5708,13 @@ Func_a028: ; a028 (2:6028) pop af ldh [hWhoseTurn], a - ld hl, wcf17 +; given the ordered cards in wOpponentDeck, +; each entry in it corresponds to its deck index +; (first ordered card is deck index 0, second is deck index 1, etc) +; place these in this order in wCurDeckCards + ld hl, wCurDeckCards ld de, wDuelTempList -.asm_a058 +.loop_order_by_deck_index ld a, [de] cp $ff jr z, .done @@ -4436,7 +5727,7 @@ Func_a028: ; a028 (2:6028) pop hl ld [hli], a inc de - jr .asm_a058 + jr .loop_order_by_deck_index .done xor a @@ -4444,15 +5735,15 @@ Func_a028: ; a028 (2:6028) ret ; 0xa06e -; goes through list in wcf17, and for each card in it -; creates list in wTempHandCardList of all unique cards -; it finds (assuming wcf17 is sorted by ID) -; also counts the number of the different cards -Func_a06e: ; a06e (2:606e) +; goes through list in wCurDeckCards, and for each card in it +; creates list in wUniqueDeckCardList of all unique cards +; it finds (assuming wCurDeckCards is sorted by ID) +; also counts the total number of the different cards +CreateCurDeckUniqueCardList: ; a06e (2:606e) ld b, 0 ld c, $0 - ld hl, wcf17 - ld de, wTempHandCardList + ld hl, wCurDeckCards + ld de, wUniqueDeckCardList .loop ld a, [hli] cp c @@ -4466,7 +5757,7 @@ Func_a06e: ; a06e (2:606e) jr .loop .done ld a, b - ld [wced9], a + ld [wNumUniqueCards], a ret ; 0xa08a @@ -4476,14 +5767,14 @@ Func_a06e: ; a06e (2:606e) ; its count preceded by "x" PrintConfirmationCardList: ; a08a (2:608a) push bc - ld hl, wced0 + ld hl, wCardListCoords ld e, [hl] inc hl ld d, [hl] ld b, 19 ; x coord ld c, e dec c - ld a, [wcea1] + ld a, [wCardListVisibleOffset] or a jr z, .no_cursor ld a, SYM_CURSOR_U @@ -4493,14 +5784,14 @@ PrintConfirmationCardList: ; a08a (2:608a) .got_cursor_tile_1 call WriteByteToBGMap0 -; iterates by decreasing value in wcecb +; iterates by decreasing value in wNumVisibleCardListEntries ; by 1 until it reaches 0 - ld a, [wcea1] + ld a, [wCardListVisibleOffset] ld c, a ld b, $0 - ld hl, wTempHandCardList + ld hl, wOwnedCardsCountList add hl, bc - ld a, [wcecb] + ld a, [wNumVisibleCardListEntries] .loop_cards push de or a @@ -4510,7 +5801,7 @@ PrintConfirmationCardList: ; a08a (2:608a) or a jr z, .no_more_cards ld e, a - call Func_9a59 + call AddCardIDToVisibleList call LoadCardDataToBuffer1_FromCardID ; places in wDefaultText the card's name and level ; then appends at the end "x" with the count of that card @@ -4542,15 +5833,15 @@ PrintConfirmationCardList: ; a08a (2:608a) or a jr z, .no_more_cards pop de - xor a - ld [wcecd], a + xor a ; FALSE + ld [wUnableToScrollDown], a ld a, SYM_CURSOR_D jr .got_cursor_tile_2 .no_more_cards pop de - ld a, $01 - ld [wcecd], a + ld a, TRUE + ld [wUnableToScrollDown], a ld a, SYM_SPACE .got_cursor_tile_2 ld b, 19 ; x coord @@ -4575,7 +5866,7 @@ PrintConfirmationCardList: ; a08a (2:608a) inc hl jr .loop_search .found_card_id - call Func_9850 + call GetCountOfCardInCurDeck ld [hl], TX_SYMBOL inc hl ld [hl], SYM_CROSS @@ -4668,7 +5959,7 @@ GetCardTypeIconPalette: ; a173 (2:6173) cp b jr z, .done inc hl - jp .loop ; should be jr + jp .loop ; can be jr .done ld a, [hl] pop hl @@ -4692,26 +5983,29 @@ GetCardTypeIconPalette: ; a173 (2:6173) db $00, $ff ; 0xa1a2 -Func_a1a2: ; a1a2 (2:61a2) - ld hl, wcf17 - ld a, DECK_SIZE + $15 +; inits WRAM vars to start creating deck configuration to send +PrepareToBuildDeckConfigurationToSend: ; a1a2 (2:61a2) + ld hl, wCurDeckCards + ld a, wCurDeckCardsEnd - wCurDeckCards call ClearNBytesFromHL ld a, $ff - ld [wceb1], a + ld [wCurDeck], a ld hl, .text - ld de, wcfb9 + ld de, wCurDeckName call CopyListFromHLToDE - ld hl, .unknown_a1d8 - call Func_8d9d - call Func_9345 + ld hl, .DeckConfigurationParams + call InitDeckBuildingParams + call HandleDeckBuildScreen ret .text text "Cards chosen to send" - db TX_END + done -.unknown_a1d8 - db $3c, $3c, $00 +.DeckConfigurationParams + db DECK_SIZE ; max number of cards + db 60 ; max number of same name cards + db FALSE ; whether to include deck cards dw HandleSendDeckConfigurationMenu dw SendDeckConfigurationMenu_TransitionTable ; 0xa1df @@ -4739,21 +6033,21 @@ HandleSendDeckConfigurationMenu: ; a201 (2:6201) ld a, $01 ld [wVBlankOAMCopyToggle], a call DoFrame - call Func_89ae + call YourOrOppPlayAreaScreen_HandleInput jr nc, .loop_input ld [wced6], a cp $ff jr nz, .asm_a23b call DrawCardTypeIconsAndPrintCardCounts - ld a, [wced4] - ld [wNamingScreenCursorY], a - ld a, [wced3] - call Func_993d - jp Func_9345.skip_draw + ld a, [wTempCardListCursorPos] + ld [wCardListCursorPos], a + ld a, [wCurCardTypeFilter] + call PrintFilteredCardList + jp HandleDeckBuildScreen.skip_draw .asm_a23b ld hl, .func_table call JumpToFunctionInTable - jp Func_9461.asm_9475 + jp OpenDeckConfigurationMenu.skip_init .func_table dw ConfirmDeckConfiguration ; Confirm @@ -4762,24 +6056,24 @@ HandleSendDeckConfigurationMenu: ; a201 (2:6201) ; 0xa24a SendDeckConfiguration: ; a24a (2:624a) - ld a, [wcf17] + ld a, [wCurDeckCards] or a jr z, CancelSendDeckConfiguration xor a - ld [wcea1], a + ld [wCardListVisibleOffset], a ld hl, Data_b04a - call Func_9a6d - ld hl, wcf17 + call InitCardSelectionParams + ld hl, wCurDeckCards ld de, wDuelTempList call CopyListFromHLToDE - call Func_b131 + call PrintCardToSendText call Func_b088 call EnableLCD ldtx hl, SendTheseCardsText call YesOrNoMenuWithText jr nc, .asm_a279 add sp, $2 - jp Func_9345.skip_count + jp HandleDeckBuildScreen.skip_count .asm_a279 add sp, $2 scf @@ -4801,48 +6095,223 @@ CopyNBytesFromHLToDE: ; a281 (2:6281) ret ; 0xa288 -Func_a288: ; a288 (2:6288) - INCROM $a288, $a3ca +; handles the screen showing all the player's cards +HandlePlayersCardsScreen: ; a288 (2:6288) + call WriteCardListsTerminatorBytes + call PrintPlayersCardsHeaderInfo + xor a + ld [wCardListVisibleOffset], a + ld [wCurCardTypeFilter], a + call PrintFilteredCardSelectionList + call EnableLCD + xor a + ld hl, FiltersCardSelectionParams + call InitCardSelectionParams +.wait_input + call DoFrame + ld a, [wCurCardTypeFilter] + ld b, a + ld a, [wTempCardTypeFilter] + cp b + jr z, .check_d_down + ld [wCurCardTypeFilter], a + ld hl, wCardListVisibleOffset + ld [hl], $00 + call PrintFilteredCardSelectionList + + ld hl, hffb0 + ld [hl], $01 + call PrintPlayersCardsText + ld hl, hffb0 + ld [hl], $00 + + ld a, NUM_FILTERS + ld [wCardListNumCursorPositions], a +.check_d_down + ldh a, [hDPadHeld] + and D_DOWN + jr z, .no_d_down + call ConfirmSelectionAndReturnCarry + jr .jump_to_list + +.no_d_down + call HandleCardSelectionInput + jr nc, .wait_input + ld a, [hffb3] + cp $ff ; operation cancelled + jr nz, .jump_to_list + ret -Func_a3ca: ; a3ca (2:63ca) +.jump_to_list + ld a, [wNumEntriesInCurFilter] + or a + jr z, .wait_input + + xor a + ld hl, Data_a396 + call InitCardSelectionParams + ld a, [wNumEntriesInCurFilter] + ld [wNumCardListEntries], a + ld hl, wNumVisibleCardListEntries + cp [hl] + jr nc, .asm_a300 + ld [wCardListNumCursorPositions], a +.asm_a300 + ld hl, PrintCardSelectionList + ld d, h + ld a, l + ld hl, wCardListUpdateFunction + ld [hli], a + ld [hl], d + xor a + ld [wced2], a + +.loop_input + call DoFrame + call HandleSelectUpAndDownInList + jr c, .loop_input + call HandleDeckCardSelectionList + jr c, .asm_a36a + ldh a, [hDPadHeld] + and START + jr z, .loop_input + ; start btn pressed + +.open_card_page + ld a, $01 + call PlaySFXConfirmOrCancel + ld a, [wCardListNumCursorPositions] + ld [wTempCardListNumCursorPositions], a + ld a, [wCardListCursorPos] + ld [wTempCardListCursorPos], a + + ; set wFilteredCardList as current card list + ; and show card page screen + ld de, wFilteredCardList + ld hl, wCurCardListPtr + ld [hl], e + inc hl + ld [hl], d + call OpenCardPageFromCardList + call PrintPlayersCardsHeaderInfo + + ld hl, FiltersCardSelectionParams + call InitCardSelectionParams + ld a, [wCurCardTypeFilter] + ld [wTempCardTypeFilter], a + call DrawHorizontalListCursor_Visible + call PrintCardSelectionList + call EnableLCD + ld hl, Data_a396 + call InitCardSelectionParams + ld a, [wTempCardListNumCursorPositions] + ld [wCardListNumCursorPositions], a + ld a, [wTempCardListCursorPos] + ld [wCardListCursorPos], a + jr .loop_input + +.asm_a36a + call DrawListCursor_Invisible + ld a, [wCardListCursorPos] + ld [wTempCardListCursorPos], a + ld a, [hffb3] + cp $ff + jr nz, .open_card_page + ld hl, FiltersCardSelectionParams + call InitCardSelectionParams + ld a, [wCurCardTypeFilter] + ld [wTempCardTypeFilter], a + ld hl, hffb0 + ld [hl], $01 + call PrintPlayersCardsText + ld hl, hffb0 + ld [hl], $00 + jp .wait_input +; 0xa396 + +Data_a396: ; a396 (2:6396) + db 1 ; x pos + db 5 ; y pos + db 2 ; y spacing + db 0 ; x spacing + db 7 ; num entries + db SYM_CURSOR_R ; visible cursor tile + db SYM_SPACE ; invisible cursor tile + dw NULL ; wCardListHandlerFunction +; 0xa39f + +; a = which card type filter +PrintFilteredCardSelectionList: ; a39f (2:639f) + push af + ld hl, CardTypeFilters + ld b, $00 + ld c, a + add hl, bc + ld a, [hl] + push af + ld a, ALL_DECKS + call CreateCardCollectionListWithDeckCards + pop af + call CreateFilteredCardList + + ld a, NUM_DECK_CONFIRMATION_VISIBLE_CARDS + ld [wNumVisibleCardListEntries], a + lb de, 2, 5 + ld hl, wCardListCoords + ld [hl], e + inc hl + ld [hl], d + ld a, SYM_SPACE + ld [wCursorAlternateTile], a + call PrintCardSelectionList + pop af + ret +; 0xa3ca + +; outputs in wTempCardCollection all the cards in sCardCollection +; plus the cards that are being used in built decks +; a = DECK_* flags for which decks to include in the collection +CreateCardCollectionListWithDeckCards: ; a3ca (2:63ca) ld [hffb5], a +; copies sCardCollection to wTempCardCollection ld hl, sCardCollection ld de, wTempCardCollection - ld b, $ff + ld b, CARD_COLLECTION_SIZE - 1 call EnableSRAM call CopyNBytesFromHLToDE call DisableSRAM + ; deck_1 ld a, [hffb5] ; should be ldh - bit 0, a + bit DECK_1_F, a jr z, .deck_2 ld de, sDeck1Cards - call GetDeckCardCounts + call IncrementDeckCardsInTempCollection .deck_2 ld a, [hffb5] ; should be ldh - bit 1, a + bit DECK_2_F, a jr z, .deck_3 ld de, sDeck2Cards - call GetDeckCardCounts + call IncrementDeckCardsInTempCollection .deck_3 ld a, [hffb5] ; should be ldh - bit 2, a + bit DECK_3_F, a jr z, .deck_4 ld de, sDeck3Cards - call GetDeckCardCounts + call IncrementDeckCardsInTempCollection .deck_4 ld a, [hffb5] ; should be ldh - bit 3, a + bit DECK_4_F, a ret z ld de, sDeck4Cards - call GetDeckCardCounts + call IncrementDeckCardsInTempCollection ret ; 0xa412 -; goes through deck cards in de -; and gets the count of each card ID -; in wTempCardCollection in card collection order -GetDeckCardCounts: ; a412 (2:6412) +; goes through cards in deck in de +; and for each card ID, increments its corresponding +; entry in wTempCardCollection +IncrementDeckCardsInTempCollection: ; a412 (2:6412) call EnableSRAM ld bc, wTempCardCollection ld h, DECK_SIZE @@ -4871,13 +6340,13 @@ GetDeckCardCounts: ; a412 (2:6412) ; where X is the current count of that card PrintCardSelectionList: ; a42d (2:642d) push bc - ld hl, wced0 + ld hl, wCardListCoords ld e, [hl] inc hl ld d, [hl] ld b, 19 ; x coord ld c, e - ld a, [wcea1] + ld a, [wCardListVisibleOffset] or a jr z, .alternate_cursor_tile ld a, SYM_CURSOR_U @@ -4887,14 +6356,14 @@ PrintCardSelectionList: ; a42d (2:642d) .got_cursor_tile_1 call WriteByteToBGMap0 -; iterates by decreasing value in wcecb +; iterates by decreasing value in wNumVisibleCardListEntries ; by 1 until it reaches 0 - ld a, [wcea1] + ld a, [wCardListVisibleOffset] ld c, a ld b, $0 ld hl, wFilteredCardList add hl, bc - ld a, [wcecb] + ld a, [wNumVisibleCardListEntries] .loop_filtered_cards push de or a @@ -4904,7 +6373,7 @@ PrintCardSelectionList: ; a42d (2:642d) or a jr z, .invalid_card ; card ID of 0 ld e, a - call Func_9a59 + call AddCardIDToVisibleList call LoadCardDataToBuffer1_FromCardID ; places in wDefaultText the card's name and level ; then appends at the end the count of that card @@ -4946,14 +6415,14 @@ PrintCardSelectionList: ; a42d (2:642d) ; draw down cursor because ; there are still more cards ; to be scrolled down - xor a - ld [wcecd], a + xor a ; FALSE + ld [wUnableToScrollDown], a ld a, SYM_CURSOR_D jr .got_cursor_tile_2 .cannot_scroll pop de - ld a, $01 - ld [wcecd], a + ld a, TRUE + ld [wUnableToScrollDown], a ld a, [wCursorAlternateTile] .got_cursor_tile_2 ld b, 19 ; x coord @@ -4991,16 +6460,1602 @@ AppendOwnedCardCountNumber: ; a4ae (2:64ae) ret ; 0xa4c6 - INCROM $a4c6, $a913 +; print header info (card count and player name) +PrintPlayersCardsHeaderInfo: ; a4c6 (2:64c6) + call Set_OBJ_8x8 + call Func_8d78 +.skip_empty_screen + lb bc, 0, 4 + ld a, SYM_BOX_TOP + call FillBGMapLineWithA + call PrintTotalNumberOfCardsInCollection + call PrintPlayersCardsText + call DrawCardTypeIcons + ret +; 0xa4de + +; prints "<PLAYER>'s cards" +PrintPlayersCardsText: ; a4de (2:64de) + lb de, 1, 0 + call InitTextPrinting + ld de, wDefaultText + call CopyPlayerName + ld hl, wDefaultText + call ProcessText + ld hl, wDefaultText + call GetTextLengthInTiles + inc b + ld d, b + ld e, 0 + call InitTextPrinting + ldtx hl, SCardsText + call ProcessTextFromID + ret +; 0xa504 + +PrintTotalNumberOfCardsInCollection: ; a504 (2:6504) + ld a, ALL_DECKS + call CreateCardCollectionListWithDeckCards + +; count all the cards in collection + ld de, wTempCardCollection + 1 + ld b, 0 + ld hl, 0 +.loop_all_cards + ld a, [de] + inc de + and $7f + push bc + ld b, $00 + ld c, a + add hl, bc + pop bc + inc b + ld a, NUM_CARDS + cp b + jr nz, .loop_all_cards + +; hl = total number of cards in collection + call .GetTotalCountDigits + ld hl, wTempCardCollection + ld de, wOnesAndTensPlace + ld b, $00 + call .PlaceNumericalChar + call .PlaceNumericalChar + call .PlaceNumericalChar + call .PlaceNumericalChar + call .PlaceNumericalChar + ld a, $07 + ld [hli], a + ld [hl], TX_END + lb de, 13, 0 + call InitTextPrinting + ld hl, wTempCardCollection + call ProcessText + ret + +; places a numerical character in hl from de +; doesn't place a 0 if no non-0 +; numerical character has been placed before +; this makes it so that there are no +; 0s in more significant digits +.PlaceNumericalChar + ld [hl], TX_SYMBOL + inc hl + ld a, b + or a + jr z, .leading_num + ld a, [de] + inc de + ld [hli], a + ret +.leading_num +; don't place a 0 as a leading number + ld a, [de] + inc de + cp SYM_0 + jr z, .space_char + ld [hli], a + ld b, $01 ; at least one non-0 char was placed + ret +.space_char + xor a ; SYM_SPACE + ld [hli], a + ret + +; gets the digits in decimal form +; of value stored in hl +; stores the result in wOnesAndTensPlace +.GetTotalCountDigits + ld de, wOnesAndTensPlace + ld bc, -10000 + call .GetDigit + ld bc, -1000 + call .GetDigit + ld bc, -100 + call .GetDigit + ld bc, -10 + call .GetDigit + ld bc, -1 + call .GetDigit + ret + +.GetDigit + ld a, SYM_0 - 1 +.loop + inc a + add hl, bc + jr c, .loop + ld [de], a + inc de + ld a, l + sub c + ld l, a + ld a, h + sbc b + ld h, a + ret +; 0xa596 + +; fills wFilteredCardList and wOwnedCardsCountList +; with cards IDs and counts, respectively, +; from given Card Set in register a +; a = CARD_SET_* constant +CreateCardSetList: ; a596 (2:6596) + push af + ld a, DECK_SIZE + ld hl, wFilteredCardList + call ClearNBytesFromHL + ld a, DECK_SIZE + ld hl, wOwnedCardsCountList + call ClearNBytesFromHL + xor a + ld [wOwnedPhantomCardFlags], a + pop af + + ld hl, 0 + lb de, 0, 0 + ld b, a +.loop_all_cards + inc e + call LoadCardDataToBuffer1_FromCardID + jr c, .done_pkmn_cards + ld a, [wLoadedCard1Set] + and $f0 ; set 1 + swap a + cp b + jr nz, .loop_all_cards + +; it's same set as input + ld a, e + cp VENUSAUR1 + jp z, .SetVenusaur1OwnedFlag + cp MEW2 + jp z, .SetMew2OwnedFlag + + push bc + push hl + ld bc, wFilteredCardList + add hl, bc + ld [hl], e ; card ID + + ld hl, wTempCardCollection + add hl, de + ld a, [hl] + pop hl + push hl + ld bc, wOwnedCardsCountList + add hl, bc + ld [hl], a ; card count in collection + pop hl -Func_a913: ; a913 (2:6913) - INCROM $a913, $ad51 + inc l + pop bc + jr .loop_all_cards -Func_ad51: ; ad51 (2:6d51) - INCROM $ad51, $adfe +.done_pkmn_cards +; for the energy cards, put all basic energy cards in Colosseum +; and Double Colorless energy in Mystery + ld a, b + cp CARD_SET_MYSTERY + jr z, .mystery + or a + jr nz, .skip_energy_cards -Func_adfe: ; adfe (2:6dfe) - INCROM $adfe, $af1d +; colosseum +; places all basic energy cards in wFilteredCardList + lb de, 0, 0 +.loop_basic_energy_cards + inc e + ld a, e + cp DOUBLE_COLORLESS_ENERGY + jr z, .skip_energy_cards + push bc + push hl + ld bc, wFilteredCardList + add hl, bc + ld [hl], e + ld hl, wTempCardCollection + add hl, de + ld a, [hl] + pop hl + push hl + ld bc, wOwnedCardsCountList + add hl, bc + ld [hl], a + pop hl + inc l + pop bc + jr .loop_basic_energy_cards + +.mystery +; places double colorless energy card in wFilteredCardList + lb de, 0, 0 +.loop_find_double_colorless + inc e + ld a, e + cp BULBASAUR + jr z, .skip_energy_cards + cp DOUBLE_COLORLESS_ENERGY + jr nz, .loop_find_double_colorless + ; double colorless energy + push bc + push hl + ld bc, wFilteredCardList + add hl, bc + ld [hl], e + ld hl, wTempCardCollection + add hl, de + ld a, [hl] + pop hl + push hl + ld bc, wOwnedCardsCountList + add hl, bc + ld [hl], a + pop hl + inc l + pop bc + jr .loop_find_double_colorless + +.skip_energy_cards + ld a, [wOwnedPhantomCardFlags] + bit VENUSAUR_OWNED_PHANTOM_F, a + jr z, .check_mew + call .PlaceVenusaur1InList +.check_mew + bit MEW_OWNED_PHANTOM_F, a + jr z, .find_first_owned + call .PlaceMew2InList + +.find_first_owned + dec l + ld c, l + ld b, h +.loop_owned_cards + ld hl, wOwnedCardsCountList + add hl, bc + ld a, [hl] + cp CARD_NOT_OWNED + jr nz, .found_owned + dec c + jr .loop_owned_cards + +.found_owned + inc c + ld a, c + ld [wNumEntriesInCurFilter], a + xor a + ld hl, wFilteredCardList + add hl, bc + ld [hl], a + ld a, $ff ; terminator byte + ld hl, wOwnedCardsCountList + add hl, bc + ld [hl], a + ret + +.SetMew2OwnedFlag + ld a, (1 << MEW_OWNED_PHANTOM_F) +; fallthrough + +.SetPhantomOwnedFlag + push hl + push bc + ld b, a + ld hl, wTempCardCollection + add hl, de + ld a, [hl] + cp CARD_NOT_OWNED + jr z, .skip_set_flag + ld a, [wOwnedPhantomCardFlags] + or b + ld [wOwnedPhantomCardFlags], a +.skip_set_flag + pop bc + pop hl + jp .loop_all_cards + +.SetVenusaur1OwnedFlag + ld a, (1 << VENUSAUR_OWNED_PHANTOM_F) + jr .SetPhantomOwnedFlag + +.PlaceVenusaur1InList + push af + push hl + ld e, VENUSAUR1 +; fallthrough + +; places card in register e directly in the list +.PlaceCardInList + ld bc, wFilteredCardList + add hl, bc + ld [hl], e + pop hl + push hl + ld bc, wOwnedCardsCountList + add hl, bc + ld [hl], $01 + pop hl + inc l + pop af + ret + +.PlaceMew2InList + push af + push hl + ld e, MEW2 + jr .PlaceCardInList +; 0xa6a0 + +; a = CARD_SET_* constant +CreateCardSetListAndInitListCoords: ; a6a0 (2:66a0) + push af + ld hl, sCardCollection + ld de, wTempCardCollection + ld b, CARD_COLLECTION_SIZE - 1 + call EnableSRAM + call CopyNBytesFromHLToDE + call DisableSRAM + pop af + + push af + call .GetEntryPrefix + call CreateCardSetList + ld a, NUM_CARD_ALBUM_VISIBLE_CARDS + ld [wNumVisibleCardListEntries], a + lb de, 2, 4 + ld hl, wCardListCoords + ld [hl], e + inc hl + ld [hl], d + pop af + ret + +; places in entry name the prefix associated with the selected Card Set +; a = CARD_SET_* constant +.GetEntryPrefix + push af + cp CARD_SET_PROMOTIONAL + jr nz, .laboratory + lb de, 3, "FW3_P" + jr .got_prefix +.laboratory + cp CARD_SET_LABORATORY + jr nz, .mystery + lb de, 3, "FW3_D" + jr .got_prefix +.mystery + cp CARD_SET_MYSTERY + jr nz, .evolution + lb de, 3, "FW3_C" + jr .got_prefix +.evolution + cp CARD_SET_EVOLUTION + jr nz, .colosseum + lb de, 3, "FW3_B" + jr .got_prefix +.colosseum + lb de, 3, "FW3_A" + +.got_prefix + ld hl, wCurDeckName + ld [hl], d + inc hl + ld [hl], e + pop af + ret +; 0xa6fa + +; prints the cards being shown in the Card Album screen +; for the corresponding Card Set +PrintCardSetListEntries: ; a6fa (2:66fa) + push bc + ld hl, wCardListCoords + ld e, [hl] + inc hl + ld d, [hl] + ld b, $13 + ld c, e + dec c + dec c + +; draw up cursor on top right + ld a, [wCardListVisibleOffset] + or a + jr z, .no_up_cursor + ld a, SYM_CURSOR_U + jr .got_up_cursor_tile +.no_up_cursor + ld a, SYM_BOX_TOP_R +.got_up_cursor_tile + call WriteByteToBGMap0 + + ld a, [wCardListVisibleOffset] + ld l, a + ld h, $00 + ld a, [wNumVisibleCardListEntries] +.loop_visible_cards + push de + or a + jr z, .handle_down_cursor + ld b, a + ld de, wFilteredCardList + push hl + add hl, de + ld a, [hl] + pop hl + inc l + or a + jr z, .no_down_cursor + ld e, a + call AddCardIDToVisibleList + call LoadCardDataToBuffer1_FromCardID + push bc + push hl + ld de, wOwnedCardsCountList + add hl, de + dec hl + ld a, [hl] + cp CARD_NOT_OWNED + jr nz, .owned + ld hl, .EmptySlotText + ld de, wDefaultText + call CopyListFromHLToDE + jr .print_text +.owned + ld a, 13 + call CopyCardNameAndLevel +.print_text + pop hl + pop bc + pop de + push hl + call InitTextPrinting + pop hl + push hl + call .AppendCardListIndex + call ProcessText + ld hl, wDefaultText + jr .asm_a76d + + ; this code is never reached + pop de + push hl + call InitTextPrinting + ld hl, Text_9a36 + +.asm_a76d + call ProcessText + pop hl + ld a, b + dec a + inc e + inc e + jr .loop_visible_cards + +.handle_down_cursor + ld de, wFilteredCardList + add hl, de + ld a, [hl] + or a + jr z, .no_down_cursor + pop de + xor a ; FALSE + ld [wUnableToScrollDown], a + ld a, SYM_CURSOR_D + jr .got_down_cursor_tile +.no_down_cursor + pop de + ld a, TRUE + ld [wUnableToScrollDown], a + ld a, SYM_BOX_BTM_R +.got_down_cursor_tile + ld b, 19 + ld c, 17 + call WriteByteToBGMap0 + pop bc + ret + +.EmptySlotText + textfw0 "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-" + done + +; gets the index in the card list and adds it to wCurDeckName +.AppendCardListIndex + push bc + push de + ld de, wFilteredCardList + add hl, de + dec hl + ld a, [hl] + cp DOUBLE_COLORLESS_ENERGY + 1 + jr c, .energy_card + cp VENUSAUR1 + jr z, .phantom_card + cp MEW2 + jr z, .phantom_card + + ld a, [wNumVisibleCardListEntries] + sub b + ld hl, wCardListVisibleOffset + add [hl] + inc a + call CalculateOnesAndTensDigits + ld hl, wOnesAndTensPlace + ld a, [hli] + ld b, a + ld a, [hl] + or a + jr nz, .got_index + ld a, SYM_0 +.got_index + ld hl, wCurDeckName + 2 ; skip prefix + ld [hl], TX_SYMBOL + inc hl + ld [hli], a ; tens place + ld [hl], TX_SYMBOL + inc hl + ld a, b + ld [hli], a ; ones place + ld [hl], TX_SYMBOL + inc hl + xor a ; SYM_SPACE + ld [hli], a + ld [hl], a + ld hl, wCurDeckName + pop de + pop bc + ret + +.energy_card + call CalculateOnesAndTensDigits + ld hl, wOnesAndTensPlace + ld a, [hli] + ld b, a + ld hl, wCurDeckName + 2 + lb de, 3, "FW3_E" + ld [hl], d + inc hl + ld [hl], e + inc hl + ld [hl], TX_SYMBOL + inc hl + ld a, SYM_0 + ld [hli], a + ld [hl], TX_SYMBOL + inc hl + ld a, b + ld [hli], a + ld [hl], TX_SYMBOL + inc hl + xor a ; SYM_SPACE + ld [hli], a + ld [hl], a + ld hl, wCurDeckName + 2 + pop de + pop bc + ret + +.phantom_card +; phantom cards get only "✕✕" in their index number + ld hl, wCurDeckName + 2 + ld [hl], "FW0_✕" + inc hl + ld [hl], "FW0_✕" + inc hl + ld [hl], TX_SYMBOL + inc hl + xor a ; SYM_SPACE + ld [hli], a + ld [hl], a + ld hl, wCurDeckName + pop de + pop bc + ret +; 0xa828 + +; handles opening card page, and inputs when inside Card Album +HandleCardAlbumCardPage: ; a828 (2:6828) + ld a, [wCardListCursorPos] + ld b, a + ld a, [wCardListVisibleOffset] + add b + ld c, a + ld b, $00 + ld hl, wOwnedCardsCountList + add hl, bc + ld a, [hl] + cp CARD_NOT_OWNED + jr z, .handle_input + + ld hl, wCurCardListPtr + ld a, [hli] + ld h, [hl] + ld l, a + add hl, bc + ld e, [hl] + ld d, $00 + push de + call LoadCardDataToBuffer1_FromCardID + lb de, $38, $9f + call SetupText + bank1call OpenCardPage_FromCheckHandOrDiscardPile + pop de + +.handle_input + ldh a, [hDPadHeld] + ld b, a + and A_BUTTON | B_BUTTON | SELECT | START + jp nz, .exit + xor a ; FALSE + ld [wPlaysSfx], a + ld a, [wCardListNumCursorPositions] + ld c, a + ld a, [wCardListCursorPos] + bit D_UP_F, b + jr z, .check_d_down + + push af + ld a, TRUE + ld [wPlaysSfx], a + ld a, [wCardListCursorPos] + ld hl, wCardListVisibleOffset + add [hl] + ld hl, wFirstOwnedCardIndex + cp [hl] + jr z, .open_card_page_pop_af_2 + pop af + + dec a + bit 7, a + jr z, .got_new_pos + ld a, [wCardListVisibleOffset] + or a + jr z, .open_card_page + dec a + ld [wCardListVisibleOffset], a + xor a + jr .got_new_pos + +.check_d_down + bit D_DOWN_F, b + jr z, .asm_a8d6 + + push af + ld a, TRUE + ld [wPlaysSfx], a + pop af + + inc a + cp c + jr c, .got_new_pos + push af + ld hl, wCurCardListPtr + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [wCardListCursorPos] + ld c, a + ld b, $00 + add hl, bc + ld a, [wCardListVisibleOffset] + inc a + ld c, a + ld b, $00 + add hl, bc + ld a, [hl] + or a + jr z, .open_card_page_pop_af_1 + ld a, [wCardListVisibleOffset] + inc a + ld [wCardListVisibleOffset], a + pop af + dec a +.got_new_pos + ; loop back to the start + ld [wCardListCursorPos], a + ld a, [wPlaysSfx] + or a + jp z, HandleCardAlbumCardPage + call PlaySFX + jp HandleCardAlbumCardPage +.open_card_page_pop_af_1 + pop af + jr .open_card_page + +.asm_a8d6 + ld a, [wced2] + or a + jr z, .open_card_page + bit D_LEFT_F, b + jr z, .check_d_right + call RemoveCardFromDeck + jr .open_card_page +.check_d_right + bit D_RIGHT_F, b + jr z, .open_card_page + call TryAddCardToDeck + +.open_card_page_pop_af_2 + pop af +.open_card_page + push de + bank1call OpenCardPage.input_loop + pop de + jp .handle_input + +.exit + ld a, $01 + ld [wVBlankOAMCopyToggle], a + ld a, [wCardListCursorPos] + ld [wTempCardListCursorPos], a + ret +; 0xa901 + +GetFirstOwnedCardIndex: ; a901 (2:6901) + ld hl, wOwnedCardsCountList + ld b, 0 +.loop_cards + ld a, [hli] + cp CARD_NOT_OWNED + jr nz, .owned + inc b + jr .loop_cards +.owned + ld a, b + ld [wFirstOwnedCardIndex], a + ret +; 0xa913 + +HandleCardAlbumScreen: ; a913 (2:6913) + ld a, $01 + ld [hffb4], a ; should be ldh + + xor a +.album_card_list + ld hl, .MenuParameters + call InitializeMenuParameters + call .DrawCardAlbumScreen +.loop_input_1 + call DoFrame + call HandleMenuInput + jp nc, .loop_input_1 ; can be jr + ldh a, [hCurMenuItem] + cp $ff + ret z + + ; ignore input if this Card Set is unavailable + ld c, a + ld b, $0 + ld hl, wUnavailableAlbumCardSets + add hl, bc + ld a, [hl] + or a + jr nz, .loop_input_1 + + ld a, c + ld [wSelectedCardSet], a + call CreateCardSetListAndInitListCoords + call .PrintCardCount + xor a + ld [wCardListVisibleOffset], a + call PrintCardSetListEntries + call EnableLCD + ld a, [wNumEntriesInCurFilter] + or a + jr nz, .asm_a968 + +.loop_input_2 + call DoFrame + ldh a, [hKeysPressed] + and B_BUTTON + jr z, .loop_input_2 + ld a, $ff + call PlaySFXConfirmOrCancel + ldh a, [hCurMenuItem] + jp .album_card_list + +.asm_a968 + call .GetNumCardEntries + xor a + ld hl, .CardSelectionParams + call InitCardSelectionParams + ld a, [wNumEntriesInCurFilter] + ld hl, wNumVisibleCardListEntries + cp [hl] + jr nc, .asm_a97e + ld [wCardListNumCursorPositions], a +.asm_a97e + ld hl, PrintCardSetListEntries + ld d, h + ld a, l + ld hl, wCardListUpdateFunction + ld [hli], a + ld [hl], d + + xor a + ld [wced2], a +.loop_input_3 + call DoFrame + call HandleDeckCardSelectionList + jr c, .selection_made + call HandleLeftRightInCardList + jr c, .loop_input_3 + ldh a, [hDPadHeld] + and START + jr z, .loop_input_3 +.open_card_page + ld a, $01 + call PlaySFXConfirmOrCancel + ld a, [wCardListNumCursorPositions] + ld [wTempCardListNumCursorPositions], a + ld a, [wCardListCursorPos] + ld [wTempCardListCursorPos], a + ld c, a + ld a, [wCardListVisibleOffset] + add c + ld hl, wOwnedCardsCountList + ld c, a + ld b, $00 + add hl, bc + ld a, [hl] + cp CARD_NOT_OWNED + jr z, .loop_input_3 + + ; set wFilteredCardList as current card list + ld de, wFilteredCardList + ld hl, wCurCardListPtr + ld [hl], e + inc hl + ld [hl], d + + call GetFirstOwnedCardIndex + call HandleCardAlbumCardPage + call .PrintCardCount + call PrintCardSetListEntries + call EnableLCD + ld hl, .CardSelectionParams + call InitCardSelectionParams + ld a, [wTempCardListNumCursorPositions] + ld [wCardListNumCursorPositions], a + ld a, [wTempCardListCursorPos] + ld [wCardListCursorPos], a + jr .loop_input_3 + +.selection_made + call DrawListCursor_Invisible + ld a, [wCardListCursorPos] + ld [wTempCardListCursorPos], a + ld a, [hffb3] + cp $ff + jr nz, .open_card_page + ldh a, [hCurMenuItem] + jp .album_card_list + +.MenuParameters + db 3, 3 ; cursor x, cursor y + db 2 ; y displacement between items + db 5 ; number of items + db SYM_CURSOR_R ; cursor tile number + db SYM_SPACE ; tile behind cursor + dw NULL ; function pointer if non-0 + +.CardSelectionParams + db 1 ; x pos + db 4 ; y pos + db 2 ; y spacing + db 0 ; x spacing + db NUM_CARD_ALBUM_VISIBLE_CARDS ; num entries + db SYM_CURSOR_R ; visible cursor tile + db SYM_SPACE ; invisible cursor tile + dw NULL ; wCardListHandlerFunction + +.GetNumCardEntries + ld hl, wFilteredCardList + ld b, $00 +.loop_card_ids + ld a, [hli] + or a + jr z, .asm_aa1f + inc b + jr .loop_card_ids +.asm_aa1f + ld a, b + ld [wNumCardListEntries], a + ret + +; prints "X/Y" where X is number of cards owned in the set +; and Y is the total card count of the Card Set +.PrintCardCount + call Set_OBJ_8x8 + xor a + ld [wTileMapFill], a + call ZeroObjectPositions + call EmptyScreen + ld a, $01 + ld [wVBlankOAMCopyToggle], a + call LoadCursorTile + call LoadSymbolsFont + call LoadDuelCardSymbolTiles + bank1call SetDefaultPalettes + lb de, $3c, $ff + call SetupText + lb de, 1, 1 + call InitTextPrinting + +; print the total number of cards that are in the Card Set + ld a, [wSelectedCardSet] + cp CARD_SET_PROMOTIONAL + jr nz, .check_laboratory +; promotional + ldtx hl, Item5PromotionalCardText + ld e, NUM_CARDS_PROMOTIONAL - 2 ; minus the phantom cards + ld a, [wOwnedPhantomCardFlags] + bit VENUSAUR_OWNED_PHANTOM_F, a + jr z, .check_owns_mew + inc e +.check_owns_mew + bit MEW_OWNED_PHANTOM_F, a + jr z, .has_card_set_count + inc e + jr .has_card_set_count +.check_laboratory + cp CARD_SET_LABORATORY + jr nz, .check_mystery + ldtx hl, Item4LaboratoryText + ld e, NUM_CARDS_LABORATORY + jr .has_card_set_count +.check_mystery + cp CARD_SET_MYSTERY + jr nz, .check_evolution + ldtx hl, Item3MysteryText + ld e, NUM_CARDS_MYSTERY + jr .has_card_set_count +.check_evolution + cp CARD_SET_EVOLUTION + jr nz, .colosseum + ldtx hl, Item2EvolutionText + ld e, NUM_CARDS_EVOLUTION + jr .has_card_set_count +.colosseum + ldtx hl, Item1ColosseumText + ld e, NUM_CARDS_COLOSSEUM + +.has_card_set_count + push de + call ProcessTextFromID + call .CountOwnedCardsInSet + lb de, 14, 1 + call InitTextPrinting + + ld a, [wNumOwnedCardsInSet] + ld hl, wDefaultText + call ConvertToNumericalDigits + call CalculateOnesAndTensDigits + ld [hl], TX_SYMBOL + inc hl + ld [hl], SYM_SLASH + inc hl + pop de + + ld a, e + call ConvertToNumericalDigits + ld [hl], TX_END + ld hl, wDefaultText + call ProcessText + lb de, 0, 2 + lb bc, 20, 16 + call DrawRegularTextBox + call EnableLCD + ret + +; counts number of cards in wOwnedCardsCountList +; that is not set as CARD_NOT_OWNED +.CountOwnedCardsInSet + ld hl, wOwnedCardsCountList + ld b, 0 +.loop_card_count + ld a, [hli] + cp $ff + jr z, .got_num_owned_cards + cp CARD_NOT_OWNED + jr z, .loop_card_count + inc b + jr .loop_card_count +.got_num_owned_cards + ld a, b + ld [wNumOwnedCardsInSet], a + ret + +.DrawCardAlbumScreen + xor a + ld [wTileMapFill], a + call EmptyScreen + ld a, [hffb4] + dec a + jr nz, .skip_clear_screen + ld [hffb4], a + call Set_OBJ_8x8 + call ZeroObjectPositions + ld a, $01 + ld [wVBlankOAMCopyToggle], a + call LoadCursorTile + call LoadSymbolsFont + call LoadDuelCardSymbolTiles + bank1call SetDefaultPalettes + lb de, $3c, $ff + call SetupText + +.skip_clear_screen + lb de, 0, 0 + lb bc, 20, 13 + call DrawRegularTextBox + ld hl, .BoosterPacksMenuData + call PlaceTextItems + + ; set all Card Sets as available + ld a, NUM_CARD_SETS + ld hl, wUnavailableAlbumCardSets + call ClearNBytesFromHL + + ; check whether player has had promotional cards + call EnableSRAM + ld a, [sHasPromotionalCards] + call DisableSRAM + or a + jr nz, .has_promotional + + ; doesn't have promotional, check if + ; this is still the case by checking the collection + ld a, CARD_SET_PROMOTIONAL + call CreateCardSetListAndInitListCoords + ld a, [wFilteredCardList] + or a + jr nz, .set_has_promotional + ; still has no promotional, print empty Card Set name + ld a, TRUE + ld [wUnavailableAlbumCardSets + CARD_SET_PROMOTIONAL], a + ld e, 11 + ld d, 5 + call InitTextPrinting + ldtx hl, EmptyPromotionalCardText + call ProcessTextFromID + jr .has_promotional + +.set_has_promotional + call EnableSRAM + ld a, TRUE + ld [sHasPromotionalCards], a + call DisableSRAM +.has_promotional + ldtx hl, ViewWhichCardFileText + call DrawWideTextBox_PrintText + call EnableLCD + ret + +.BoosterPacksMenuData + textitem 7, 1, BoosterPackTitleText + textitem 5, 3, Item1ColosseumText + textitem 5, 5, Item2EvolutionText + textitem 5, 7, Item3MysteryText + textitem 5, 9, Item4LaboratoryText + textitem 5, 11, Item5PromotionalCardText + db $ff +; 0xab7b + +PrinterMenu_PokemonCards: ; ab7b (2:6b7b) + call WriteCardListsTerminatorBytes + call PrintPlayersCardsHeaderInfo + xor a + ld [wCardListVisibleOffset], a + ld [wCurCardTypeFilter], a + call PrintFilteredCardSelectionList + call EnableLCD + xor a + ld hl, FiltersCardSelectionParams + call InitCardSelectionParams + +.loop_frame_1 + call DoFrame + ld a, [wCurCardTypeFilter] + ld b, a + ld a, [wTempCardTypeFilter] + cp b + jr z, .handle_input + ld [wCurCardTypeFilter], a + ld hl, wCardListVisibleOffset + ld [hl], $00 + call PrintFilteredCardSelectionList + ld hl, hffb0 + ld [hl], $01 + call PrintPlayersCardsText + ld hl, hffb0 + ld [hl], $00 + ld a, NUM_FILTERS + ld [wCardListNumCursorPositions], a +.handle_input + ldh a, [hDPadHeld] + and D_DOWN + jr z, .asm_abca +; d_down + call ConfirmSelectionAndReturnCarry + jr .asm_abd7 +.asm_abca + call HandleCardSelectionInput + jr nc, .loop_frame_1 + ld a, [hffb3] + cp $ff + jr nz, .asm_abd7 + ret + +.asm_abd7 + ld a, [wNumEntriesInCurFilter] + or a + jr z, .loop_frame_1 + + xor a + ld hl, Data_a396 + call InitCardSelectionParams + ld a, [wNumEntriesInCurFilter] + ld [wNumCardListEntries], a + ld hl, wNumVisibleCardListEntries + cp [hl] + jr nc, .asm_abf6 + ld [wCardListNumCursorPositions], a + ld [wTempCardListNumCursorPositions], a +.asm_abf6 + ld hl, PrintCardSelectionList + ld d, h + ld a, l + ld hl, wCardListUpdateFunction + ld [hli], a + ld [hl], d + xor a + ld [wced2], a + +.loop_frame_2 + call DoFrame + call HandleSelectUpAndDownInList + jr c, .loop_frame_2 + call HandleDeckCardSelectionList + jr c, .asm_ac60 + ldh a, [hDPadHeld] + and START + jr z, .loop_frame_2 +; start btn + ld a, $01 + call PlaySFXConfirmOrCancel + ld a, [wCardListNumCursorPositions] + ld [wTempCardListNumCursorPositions], a + ld a, [wCardListCursorPos] + ld [wTempCardListCursorPos], a + + ; set wFilteredCardList as current card list + ; and show card page screen + ld de, wFilteredCardList + ld hl, wCurCardListPtr + ld [hl], e + inc hl + ld [hl], d + call OpenCardPageFromCardList + call PrintPlayersCardsHeaderInfo + +.asm_ac37 + ld hl, FiltersCardSelectionParams + call InitCardSelectionParams + ld a, [wCurCardTypeFilter] + ld [wTempCardTypeFilter], a + call DrawHorizontalListCursor_Visible + call PrintCardSelectionList + call EnableLCD + ld hl, Data_a396 + call InitCardSelectionParams + ld a, [wTempCardListNumCursorPositions] + ld [wCardListNumCursorPositions], a + ld a, [wTempCardListCursorPos] + ld [wCardListCursorPos], a + jr .loop_frame_2 + +.asm_ac60 + call DrawListCursor_Invisible + ld a, [wCardListNumCursorPositions] + ld [wTempCardListNumCursorPositions], a + ld a, [wCardListCursorPos] + ld [wTempCardListCursorPos], a + ld a, [hffb3] + cp $ff + jr nz, .asm_ac92 + + ld hl, FiltersCardSelectionParams + call InitCardSelectionParams + ld a, [wCurCardTypeFilter] + ld [wTempCardTypeFilter], a + ld hl, hffb0 + ld [hl], $01 + call PrintPlayersCardsText + ld hl, hffb0 + ld [hl], $00 + jp .loop_frame_1 + +.asm_ac92 + call DrawListCursor_Visible + call .Func_acde + lb de, 1, 1 + call InitTextPrinting + ldtx hl, PrintThisCardYesNoText + call ProcessTextFromID + ld a, $01 + ld hl, Data_ad05 + call InitCardSelectionParams +.loop_frame + call DoFrame + call HandleCardSelectionInput + jr nc, .loop_frame + ld a, [hffb3] + or a + jr nz, .asm_acd5 + ld hl, wFilteredCardList + ld a, [wTempCardListCursorPos] + ld c, a + ld b, $00 + add hl, bc + ld a, [wCardListVisibleOffset] + ld c, a + ld b, $00 + add hl, bc + ld a, [hl] + bank1call Func_758a + call PrintPlayersCardsHeaderInfo + jp .asm_ac37 + +.asm_acd5 + call .Func_acde + call PrintPlayersCardsHeaderInfo.skip_empty_screen + jp .asm_ac37 + +.Func_acde + xor a + lb hl, 0, 0 + lb de, 0, 0 + lb bc, 20, 4 + call FillRectangle + ld a, [wConsole] + cp CONSOLE_CGB + ret nz ; exit if not CGB + + xor a + lb hl, 0, 0 + lb de, 0, 0 + lb bc, 20, 4 + call BankswitchVRAM1 + call FillRectangle + call BankswitchVRAM0 + ret +; 0xad0e + +Data_ad05: ; ad05 (2:6d05) + db 3 ; x pos + db 3 ; y pos + db 0 ; y spacing + db 4 ; x spacing + db 2 ; num entries + db SYM_CURSOR_R ; visible cursor tile + db SYM_SPACE ; invisible cursor tile + dw NULL ; wCardListHandlerFunction +; 0xad0e + +PrinterMenu_CardList: ; ad0e (2:6d0e) + call WriteCardListsTerminatorBytes + call Set_OBJ_8x8 + call Func_8d78 + lb bc, 0, 4 + ld a, SYM_BOX_TOP + call FillBGMapLineWithA + + xor a + ld [wCardListVisibleOffset], a + ld [wCurCardTypeFilter], a + call PrintFilteredCardSelectionList + call EnableLCD + lb de, 1, 1 + call InitTextPrinting + ld hl, EnableLCD + call ProcessTextFromID + ld a, $01 + ld hl, Data_ad05 + call InitCardSelectionParams +.loop_frame + call DoFrame + call HandleCardSelectionInput + jr nc, .loop_frame + ld a, [hffb3] + or a + ret nz + bank1call Func_7585 + ret +; 0xad51 + +HandlePrinterMenu: ; ad51 (2:6d51) + bank1call Func_757b + ret c + xor a +.loop + ld hl, PrinterMenuParameters + call InitializeMenuParameters + call EmptyScreenAndLoadFontDuelAndHandCardsIcons + lb de, 4, 0 + lb bc, 12, 12 + call DrawRegularTextBox + lb de, 6, 2 + call InitTextPrinting + ldtx hl, PrintMenuItemsText + call ProcessTextFromID + ldtx hl, WhatWouldYouLikeToPrintText + call DrawWideTextBox_PrintText + call EnableLCD +.loop_input + call DoFrame + call HandleMenuInput + jr nc, .loop_input + ldh a, [hCurMenuItem] + cp $ff + call z, PrinterMenu_QuitPrint + ld [wcfe4], a + ld hl, PrinterMenuFunctionTable + call JumpToFunctionInTable + ld a, [wcfe4] + jr .loop +; 0xad9a + +PrinterMenu_QuitPrint: ; ad9a (2:6d9a) + add sp, $2 ; exit menu + ldtx hl, PleaseMakeSureToTurnGameBoyPrinterOffText + call DrawWideTextBox_WaitForInput + ret +; 0xada3 + +PrinterMenuFunctionTable: ; ada3 (2:6da3) + dw PrinterMenu_PokemonCards + dw PrinterMenu_DeckConfiguration + dw PrinterMenu_CardList + dw PrinterMenu_PrintQuality + dw PrinterMenu_QuitPrint +; 0xadad + +PrinterMenuParameters: ; adad (2:6dad) + db 5, 2 ; cursor x, cursor y + db 2 ; y displacement between items + db 5 ; number of items + db SYM_CURSOR_R ; cursor tile number + db SYM_SPACE ; tile behind cursor + dw NULL ; function pointer if non-0 +; 0xadb5 + +PrinterMenu_PrintQuality: ; adb5 (2:6db5) + ldtx hl, PleaseSetTheContrastText + call DrawWideTextBox_PrintText + call EnableSRAM + ld a, [sPrinterContrastLevel] + call DisableSRAM + ld hl, Data_adf5 + call InitCardSelectionParams +.loop_frame + call DoFrame + call HandleCardSelectionInput + jr nc, .loop_frame + ld a, [hffb3] + cp $ff + jr z, .asm_ade2 + call EnableSRAM + ld [sPrinterContrastLevel], a + call DisableSRAM +.asm_ade2 + add sp, $2 ; exit menu + ld a, [wcfe4] + ld hl, PrinterMenuParameters + call InitializeMenuParameters + ldtx hl, WhatWouldYouLikeToPrintText + call DrawWideTextBox_PrintText + jr HandlePrinterMenu.loop_input +; 0xadf5 + +Data_adf5: ; adf5 (2:6df5) + db 5 ; x pos + db 16 ; y pos + db 0 ; y spacing + db 2 ; x spacing + db 5 ; num entries + db SYM_CURSOR_R ; visible cursor tile + db SYM_SPACE ; invisible cursor tile + dw NULL ; wCardListHandlerFunction +; 0xadfe + +; handles printing and player input +; in the card confirmation list shown +; when cards are missing for some deck configuration +; hl = deck name +; de = deck cards +HandleDeckMissingCardsList: ; adfe (2:6dfe) +; read deck name from hl and cards from de + push de + ld de, wCurDeckName + call CopyListFromHLToDEInSRAM + pop de + ld hl, wCurDeckCards + call CopyDeckFromSRAM + + ld a, NUM_FILTERS + ld hl, wCardFilterCounts + call ClearNBytesFromHL + ld a, DECK_SIZE + ld [wTotalCardCount], a + ld hl, wCardFilterCounts + ld [hl], a + call .HandleList ; can skip call and fallthrough instead + ret + +.HandleList + call SortCurDeckCardsByID + call CreateCurDeckUniqueCardList + xor a + ld [wCardListVisibleOffset], a +.loop + ld hl, .DeckConfirmationCardSelectionParams + call InitCardSelectionParams + ld a, [wNumUniqueCards] + ld [wNumCardListEntries], a + cp $05 + jr c, .got_num_positions + ld a, $05 +.got_num_positions + ld [wCardListNumCursorPositions], a + ld [wNumVisibleCardListEntries], a + call .PrintTitleAndList + ld hl, wCardConfirmationText + ld a, [hli] + ld h, [hl] + ld l, a + call DrawWideTextBox_PrintText + +; set card update function + ld hl, .CardListUpdateFunction + ld d, h + ld a, l + ld hl, wCardListUpdateFunction + ld [hli], a + ld [hl], d + xor a + ld [wced2], a + +.loop_input + call DoFrame + call HandleDeckCardSelectionList + jr c, .selection_made + call HandleLeftRightInCardList + jr c, .loop_input + ldh a, [hDPadHeld] + and START + jr z, .loop_input + +.open_card_pge + ld a, $01 + call PlaySFXConfirmOrCancel + ld a, [wCardListCursorPos] + ld [wced7], a + + ; set wOwnedCardsCountList as current card list + ; and show card page screen + ld de, wOwnedCardsCountList + ld hl, wCurCardListPtr + ld [hl], e + inc hl + ld [hl], d + call OpenCardPageFromCardList + jr .loop + +.selection_made + ld a, [hffb3] + cp $ff + ret z + jr .open_card_pge + +.DeckConfirmationCardSelectionParams + db 0 ; x pos + db 3 ; y pos + db 2 ; y spacing + db 0 ; x spacing + db 5 ; num entries + db SYM_CURSOR_R ; visible cursor tile + db SYM_SPACE ; invisible cursor tile + dw NULL ; wCardListHandlerFunction + +.CardListUpdateFunction + ld hl, hffb0 + ld [hl], $01 + call .PrintDeckIndexAndName + lb de, 1, 14 + call InitTextPrinting + ld hl, wCardConfirmationText + ld a, [hli] + ld h, [hl] + ld l, a + call ProcessTextFromID + ld hl, hffb0 + ld [hl], $00 + jp PrintConfirmationCardList + +.PrintTitleAndList + call .ClearScreenAndPrintDeckTitle + lb de, 3, 3 + ld hl, wCardListCoords + ld [hl], e + inc hl + ld [hl], d + call PrintConfirmationCardList + ret + +.ClearScreenAndPrintDeckTitle + call EmptyScreenAndLoadFontDuelAndHandCardsIcons + call .PrintDeckIndexAndName + call EnableLCD + ret + +; prints text in the form "X.<DECK NAME> deck" +; where X is the deck index in the list +.PrintDeckIndexAndName + ld a, [wCurDeckName] + or a + ret z ; not a valid deck + lb de, 0, 1 + call InitTextPrinting + ld a, [wCurDeck] + inc a + ld hl, wDefaultText + call ConvertToNumericalDigits + ld [hl], "FW0_·" + inc hl + ld [hl], TX_END + ld hl, wDefaultText + call ProcessText + + ld hl, wCurDeckName + ld de, wDefaultText + call CopyListFromHLToDE + ld hl, wDefaultText + call GetTextLengthInTiles + ld b, $0 + ld hl, wDefaultText + add hl, bc + ld d, h + ld e, l + ld hl, DeckNameSuffix + call CopyListFromHLToDE + lb de, 3, 1 + ld hl, wDefaultText + call InitTextPrinting + call ProcessText + ret +; 0xaf1d Func_af1d: ; af1d (2:6f1d) xor a @@ -5030,14 +8085,14 @@ Func_af1d: ; af1d (2:6f1d) call DrawWideTextBox_WaitForInput call EnableLCD - call Func_a1a2 + call PrepareToBuildDeckConfigurationToSend jr c, .asm_af6b ld a, $01 or a ret .asm_af6b - ld hl, wcf17 + ld hl, wCurDeckCards ld de, wDuelTempList call CopyListFromHLToDE xor a @@ -5045,8 +8100,8 @@ Func_af1d: ; af1d (2:6f1d) bank1call Func_756c ret c call EnableSRAM - ld hl, wcf17 - call Func_910a + ld hl, wCurDeckCards + call DecrementDeckCardsInCollection call DisableSRAM call SaveGame ld hl, wNameBuffer @@ -5069,27 +8124,27 @@ Func_af98: ; af98 (2:6f98) call EnableSRAM ld hl, wDuelTempList - call Func_9120 + call AddGiftCenterDeckCardsToCollection call DisableSRAM call SaveGame xor a - ld [wcea1], a + ld [wCardListVisibleOffset], a ld hl, Data_b04a - call Func_9a6d - call Func_b141 + call InitCardSelectionParams + call PrintReceivedTheseCardsText call Func_b088 call EnableLCD - ld a, [wceab + 3] - ld [wcfe4 + 2], a - ld hl, wcecb + ld a, [wNumEntriesInCurFilter] + ld [wNumCardListEntries], a + ld hl, wNumVisibleCardListEntries cp [hl] jr nc, .asm_afd4 - ld [wNamingScreenKeyboardHeight], a + ld [wCardListNumCursorPositions], a .asm_afd4 - ld hl, Func_b053 + ld hl, ShowReceivedCardsList ld d, h ld a, l - ld hl, wcece + ld hl, wCardListUpdateFunction ld [hli], a ld [hl], d @@ -5097,9 +8152,9 @@ Func_af98: ; af98 (2:6f98) ld [wced2], a .asm_afe2 call DoFrame - call Func_9b25 + call HandleDeckCardSelectionList jr c, .asm_b02f - call Func_9eb8 + call HandleLeftRightInCardList jr c, .asm_afe2 ldh a, [hDPadHeld] and START @@ -5107,32 +8162,36 @@ Func_af98: ; af98 (2:6f98) .asm_aff5 ld a, $01 call PlaySFXConfirmOrCancel - ld a, [wNamingScreenCursorY] - ld [wced4], a + ld a, [wCardListCursorPos] + ld [wTempCardListCursorPos], a + + ; set wFilteredCardList as current card list + ; and show card page screen ld de, wFilteredCardList - ld hl, wcfd8 + ld hl, wCurCardListPtr ld [hl], e inc hl ld [hl], d - call Func_9c3f - call Func_b141 + call OpenCardPageFromCardList + call PrintReceivedTheseCardsText + call PrintCardSelectionList call EnableLCD ld hl, Data_b04a - call Func_9a6d - ld a, [wceab + 3] - ld hl, wcecb + call InitCardSelectionParams + ld a, [wNumEntriesInCurFilter] + ld hl, wNumVisibleCardListEntries cp [hl] jr nc, .asm_b027 - ld [wNamingScreenKeyboardHeight], a + ld [wCardListNumCursorPositions], a .asm_b027 - ld a, [wced4] - ld [wNamingScreenCursorY], a + ld a, [wTempCardListCursorPos] + ld [wCardListCursorPos], a jr .asm_afe2 .asm_b02f - call Func_9c0e - ld a, [wNamingScreenCursorY] - ld [wced4], a + call DrawListCursor_Invisible + ld a, [wCardListCursorPos] + ld [wTempCardListCursorPos], a ld a, [hffb3] cp $ff jr nz, .asm_aff5 @@ -5143,9 +8202,16 @@ Func_af98: ; af98 (2:6f98) ret Data_b04a: ; b04a (2:704a) - db $01, $03, $02, $00, $05, $0f, $00, $00, $00 - -Func_b053: ; b053 (2:7053) + db 1 ; x pos + db 3 ; y pos + db 2 ; y spacing + db 0 ; x spacing + db 5 ; num entries + db SYM_CURSOR_R ; visible cursor tile + db SYM_SPACE ; invisible cursor tile + dw NULL ; wCardListHandlerFunction + +ShowReceivedCardsList: ; b053 (2:7053) ld hl, hffb0 ld [hl], $01 lb de, 1, 1 @@ -5168,7 +8234,7 @@ Func_b053: ; b053 (2:7053) ; 0xb088 Func_b088: ; b088 (2:7088) - ld a, $ff + ld a, CARD_COLLECTION_SIZE - 1 ld hl, wTempCardCollection call ClearNBytesFromHL ld de, wDuelTempList @@ -5176,9 +8242,9 @@ Func_b088: ; b088 (2:7088) ld a, $ff call .Func_b0c0 ld a, $05 - ld [wcecb], a + ld [wNumVisibleCardListEntries], a lb de, 2, 3 - ld hl, wced0 + ld hl, wCardListCoords ld [hl], e inc hl ld [hl], d @@ -5224,8 +8290,8 @@ Func_b088: ; b088 (2:7088) ld a, b cp $ff jr z, .asm_b0fc - and $20 - cp $20 + and FILTER_ENERGY + cp FILTER_ENERGY jr z, .asm_b0f5 ld a, c cp b @@ -5261,7 +8327,7 @@ Func_b088: ; b088 (2:7088) .asm_b119 ld a, l - ld [wceab + 3], a + ld [wNumEntriesInCurFilter], a xor a ld c, l ld b, h @@ -5279,8 +8345,8 @@ Func_b088: ; b088 (2:7088) ret ; 0xb131 -Func_b131: ; b131 (2:7131) - call Func_b141.Func_b167 +PrintCardToSendText: ; b131 (2:7131) + call EmptyScreenAndDrawTextBox lb de, 1, 1 call InitTextPrinting ldtx hl, CardToSendText @@ -5288,8 +8354,8 @@ Func_b131: ; b131 (2:7131) ret ; 0xb141 -Func_b141: ; b141 (2:7141) - call .Func_b167 +PrintReceivedTheseCardsText: ; b141 (2:7141) + call EmptyScreenAndDrawTextBox lb de, 1, 1 call InitTextPrinting ldtx hl, CardReceivedText @@ -5303,11 +8369,12 @@ Func_b141: ; b141 (2:7141) ldtx hl, ReceivedTheseCardsFromText call DrawWideTextBox_PrintText ret +; 0xb167 -.Func_b167 +EmptyScreenAndDrawTextBox: ; b167 (2:7167) call Set_OBJ_8x8 call Func_8d78 - ld de, $0 + lb de, 0, 0 lb bc, 20, 13 call DrawRegularTextBox ret @@ -5337,123 +8404,141 @@ Func_b177: ; b177 (2:7177) dw Func_bc7a ; 0xb19d -Func_b19d: ; b19d (2:719d) +HandleDeckSaveMachineMenu: ; b19d (2:719d) xor a - ld [wcea1], a + ld [wCardListVisibleOffset], a ldtx de, DeckSaveMachineText - ld hl, wd0a2 + ld hl, wDeckMachineTitleText ld [hl], e inc hl ld [hl], d - call Func_b379 - ld a, $3c - ld [wd0a5], a + call ClearScreenAndDrawDeckMachineScreen + ld a, NUM_DECK_SAVE_MACHINE_SLOTS + ld [wNumDeckMachineEntries], a + xor a -.asm_b1b3 - ld hl, Data_b6fb - call Func_9a6d - call Func_b704 - call Func_b545 +.wait_input + ld hl, DeckMachineSelectionParams + call InitCardSelectionParams + call DrawListScrollArrows + call PrintNumSavedDecks ldtx hl, PleaseSelectDeckText call DrawWideTextBox_PrintText ldtx de, PleaseSelectDeckText - call Func_b285 - call Func_b29f - jr c, .asm_b1b3 + call InitDeckMachineDrawingParams + call HandleDeckMachineSelection + jr c, .wait_input cp $ff - ret z + ret z ; operation cancelled + ; get the index of selected deck ld b, a - ld a, [wcea1] + ld a, [wCardListVisibleOffset] add b - ld [wd088], a + ld [wSelectedDeckMachineEntry], a + call ResetCheckMenuCursorPositionAndBlink call DrawWideTextBox - ld hl, Unknown_b274 + ld hl, .DeckMachineMenuData call PlaceTextItems -.asm_b1e7 +.wait_input_submenu call DoFrame call HandleCheckMenuInput - jp nc, .asm_b1e7 + jp nc, .wait_input_submenu cp $ff - jr nz, .asm_b1fa - ld a, [wd086] - jp .asm_b1b3 + jr nz, .submenu_option_selected + ; return from submenu + ld a, [wTempDeckMachineCursorPos] + jp .wait_input -.asm_b1fa +.submenu_option_selected ld a, [wCheckMenuCursorYPosition] sla a ld hl, wCheckMenuCursorXPosition add [hl] or a - jr nz, .asm_b22c - call Func_b35b - jr nc, .asm_b216 - call Func_b592 - ld a, [wd086] - jp c, .asm_b1b3 - jr .asm_b25e - -.asm_b216 + jr nz, .ok_1 + +; Save a Deck + call CheckIfSelectedDeckMachineEntryIsEmpty + jr nc, .prompt_ok_if_deleted + call SaveDeckInDeckSaveMachine + ld a, [wTempDeckMachineCursorPos] + jp c, .wait_input + jr .return_to_list +.prompt_ok_if_deleted ldtx hl, OKIfFileDeletedText call YesOrNoMenuWithText - ld a, [wd086] - jr c, .asm_b1b3 - call Func_b592 - ld a, [wd086] - jp c, .asm_b1b3 - jr .asm_b25e - -.asm_b22c + ld a, [wTempDeckMachineCursorPos] + jr c, .wait_input + call SaveDeckInDeckSaveMachine + ld a, [wTempDeckMachineCursorPos] + jp c, .wait_input + jr .return_to_list + +.ok_1 cp $1 - jr nz, .asm_b24c - call Func_b35b - jr c, .asm_b240 - call Func_b6ca - ld a, [wd086] - jp c, .asm_b1b3 - jr .asm_b25e - -.asm_b240 + jr nz, .ok_2 + +; Delete a Deck + call CheckIfSelectedDeckMachineEntryIsEmpty + jr c, .is_empty + call TryDeleteSavedDeck + ld a, [wTempDeckMachineCursorPos] + jp c, .wait_input + jr .return_to_list + +.is_empty ld hl, WaitForVBlank call DrawWideTextBox_WaitForInput - ld a, [wd086] - jp .asm_b1b3 + ld a, [wTempDeckMachineCursorPos] + jp .wait_input -.asm_b24c +.ok_2 cp $2 - jr nz, .asm_b273 - call Func_b35b - jr c, .asm_b240 - call Func_b7c6 - ld a, [wd086] - jp nc, .asm_b1b3 - -.asm_b25e - ld a, [wd087] - ld [wcea1], a - call Func_b379 - call Func_b704 - call Func_b545 - ld a, [wd086] - jp .asm_b1b3 + jr nz, .cancel + +; Build a Deck + call CheckIfSelectedDeckMachineEntryIsEmpty + jr c, .is_empty + call TryBuildDeckMachineDeck + ld a, [wTempDeckMachineCursorPos] + jp nc, .wait_input + +.return_to_list + ld a, [wTempCardListVisibleOffset] + ld [wCardListVisibleOffset], a + call ClearScreenAndDrawDeckMachineScreen + call DrawListScrollArrows + call PrintNumSavedDecks + ld a, [wTempDeckMachineCursorPos] + jp .wait_input -.asm_b273 +.cancel ret -Unknown_b274: ; b274 (2:7274) - INCROM $b274, $b285 - -Func_b285: ; b285 (2:7285) - ld a, $05 - ld [wNamingScreenKeyboardHeight], a - ld hl, wd0a7 +.DeckMachineMenuData + textitem 2, 14, SaveADeckText + textitem 12, 14, DeleteADeckText + textitem 2, 16, BuildADeckText + textitem 12, 16, CancelText + db $ff +; 0xb285 + +; sets the number of cursor positions for deck machine menu, +; sets the text ID to show given by de +; and sets DrawDeckMachineScreen as the update function +; de = text ID +InitDeckMachineDrawingParams: ; b285 (2:7285) + ld a, NUM_DECK_MACHINE_SLOTS + ld [wCardListNumCursorPositions], a + ld hl, wDeckMachineText ld [hl], e inc hl ld [hl], d - ld hl, Func_b403 + ld hl, DrawDeckMachineScreen ld d, h ld a, l - ld hl, wcece + ld hl, wCardListUpdateFunction ld [hli], a ld [hl], d xor a @@ -5461,19 +8546,180 @@ Func_b285: ; b285 (2:7285) ret ; 0xb29f -Func_b29f: ; b29f (2:729f) - INCROM $b29f, $b35b +; handles player input inside the Deck Machine screen +; the Start button opens up the deck confirmation menu +; and returns carry +; otherwise, returns no carry and selection made in a +HandleDeckMachineSelection: ; b29f (2:729f) + call DoFrame + call HandleDeckCardSelectionList + jr c, .selection_made + + call .HandleListJumps + jr c, HandleDeckMachineSelection ; jump back to start + ldh a, [hDPadHeld] + and START + jr z, HandleDeckMachineSelection ; jump back to start + +; start btn + ld a, [wCardListVisibleOffset] + ld [wTempCardListVisibleOffset], a + ld b, a + ld a, [wCardListCursorPos] + ld [wTempDeckMachineCursorPos], a + add b + ld c, a + inc a + or $80 + ld [wCurDeck], a -Func_b35b: ; b35b (2:735b) - INCROM $b35b, $b379 + ; get pointer to selected deck cards + ; and if it's an empty deck, jump to start + sla c + ld b, $0 + ld hl, wMachineDeckPtrs + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + push hl + ld bc, DECK_NAME_SIZE + add hl, bc + ld d, h + ld e, l + call EnableSRAM + ld a, [hl] + call DisableSRAM + pop hl + or a + jr z, HandleDeckMachineSelection ; jump back to start + +; show deck confirmation screen with deck cards +; and return carry set + ld a, $01 + call PlaySFXConfirmOrCancel + call OpenDeckConfirmationMenu + ld a, [wTempCardListVisibleOffset] + ld [wCardListVisibleOffset], a + call ClearScreenAndDrawDeckMachineScreen + call DrawListScrollArrows + call PrintNumSavedDecks + ld a, [wTempDeckMachineCursorPos] + ld [wCardListCursorPos], a + scf + ret + +.selection_made + call DrawListCursor_Visible + ld a, [wCardListVisibleOffset] + ld [wTempCardListVisibleOffset], a + ld a, [wCardListCursorPos] + ld [wTempDeckMachineCursorPos], a + ld a, [hffb3] + or a + ret + +; handles right and left input for jumping several entries at once +; returns carry if jump was made +.HandleListJumps + ld a, [wCardListVisibleOffset] + ld c, a + ldh a, [hDPadHeld] + cp D_RIGHT + jr z, .d_right + cp D_LEFT + jr z, .d_left + or a + ret + +.d_right + ld a, [wCardListVisibleOffset] + add NUM_DECK_MACHINE_SLOTS + ld b, a + add NUM_DECK_MACHINE_SLOTS + ld hl, wNumDeckMachineEntries + cp [hl] + jr c, .got_new_pos + ld a, [wNumDeckMachineEntries] + sub NUM_DECK_MACHINE_SLOTS + ld b, a + jr .got_new_pos + +.d_left + ld a, [wCardListVisibleOffset] + sub NUM_DECK_MACHINE_SLOTS + ld b, a + jr nc, .got_new_pos + ld b, 0 ; first entry + +.got_new_pos + ld a, b + ld [wCardListVisibleOffset], a + cp c + jr z, .set_carry + ; play SFX if jump was made + ; and update UI + ld a, SFX_01 + call PlaySFX + call DrawDeckMachineScreen + call PrintNumSavedDecks +.set_carry + scf + ret +; 0xb35b + +; returns carry if deck corresponding to the +; entry selected in the Deck Machine menu is empty +CheckIfSelectedDeckMachineEntryIsEmpty: ; b35b (2:735b) + ld a, [wSelectedDeckMachineEntry] + sla a + ld l, a + ld h, $0 + ld bc, wMachineDeckPtrs + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + ld bc, DECK_NAME_SIZE + add hl, bc + call EnableSRAM + ld a, [hl] + call DisableSRAM + or a + ret nz ; is valid + scf + ret; is empty +; 0xb379 -Func_b379: ; b379 (2:7379) - INCROM $b379, $b3b3 +ClearScreenAndDrawDeckMachineScreen: ; b379 (2:7379) + call Set_OBJ_8x8 + xor a + ld [wTileMapFill], a + call ZeroObjectPositions + call EmptyScreen + ld a, $01 + ld [wVBlankOAMCopyToggle], a + call LoadSymbolsFont + call LoadDuelCardSymbolTiles + bank1call SetDefaultPalettes + lb de, $3c, $ff + call SetupText + lb de, 0, 0 + lb bc, 20, 13 + call DrawRegularTextBox + call SetDeckMachineTitleText + call GetSavedDeckPointers + call PrintVisibleDeckMachineEntries + call GetSavedDeckCount + call EnableLCD + ret +; 0xb3b3 -Func_b3b3: ; b3b3 (2:73b3) +; prints wDeckMachineTitleText as title text +SetDeckMachineTitleText: ; b3b3 (2:73b3) lb de, 1, 0 call InitTextPrinting - ld hl, wd0a2 + ld hl, wDeckMachineTitleText ld a, [hli] ld h, [hl] ld l, a @@ -5481,67 +8727,102 @@ Func_b3b3: ; b3b3 (2:73b3) ret ; 0xb3c3 - INCROM $b3c3, $b3e5 +; save all sSavedDecks pointers in wMachineDeckPtrs +GetSavedDeckPointers: ; b3c3 (2:73c3) + ld a, NUM_DECK_SAVE_MACHINE_SLOTS + add NUM_DECK_SAVE_MACHINE_SLOTS ; add a is better + ld hl, wMachineDeckPtrs + call ClearNBytesFromHL + ld de, wMachineDeckPtrs + ld hl, sSavedDecks + ld bc, DECK_STRUCT_SIZE + ld a, NUM_DECK_SAVE_MACHINE_SLOTS +.loop_saved_decks + push af + ld a, l + ld [de], a + inc de + ld a, h + ld [de], a + inc de + add hl, bc + pop af + dec a + jr nz, .loop_saved_decks + ret +; 0xb3e5 -Func_b3e5: ; b3e5 (2:73e5) - ld a, [wcea1] - ld de, $202 - ld b, $05 -.asm_b3ed +; given the cursor position in the deck machine menu +; prints the deck names of all entries that are visible +PrintVisibleDeckMachineEntries: ; b3e5 (2:73e5) + ld a, [wCardListVisibleOffset] + lb de, 2, 2 + ld b, NUM_DECK_MACHINE_VISIBLE_DECKS +.loop push af push bc push de - call Func_b424 + call PrintDeckMachineEntry pop de pop bc pop af - ret c + ret c ; jump never made? dec b - ret z + ret z ; no more entries inc a inc e inc e - jr .asm_b3ed + jr .loop ; 0xb3fe -Unknown_b3fe: ; b3fe (2:73fe) - INCROM $b3fe, $b403 +UpdateDeckMachineScrollArrowsAndEntries: ; b3fe (2:73fe) + call DrawListScrollArrows + jr PrintVisibleDeckMachineEntries +; 0xb403 -Func_b403: ; b403 (2:7403) - call Func_b704 +DrawDeckMachineScreen: ; b403 (2:7403) + call DrawListScrollArrows ld hl, hffb0 ld [hl], $01 - call Func_b3b3 + call SetDeckMachineTitleText lb de, 1, 14 call InitTextPrinting - ld hl, wd0a7 + ld hl, wDeckMachineText ld a, [hli] ld h, [hl] ld l, a call ProcessTextFromID ld hl, hffb0 ld [hl], $00 - jr Func_b3e5 + jr PrintVisibleDeckMachineEntries ; 0xb424 -Func_b424: ; b424 (2:7424) +; prints the deck name of the deck corresponding +; to index in register a, from wMachineDeckPtrs +; also checks whether the deck can be built +; either by dismantling other decks or not, +; and places the corresponding symbol next to the name +PrintDeckMachineEntry: ; b424 (2:7424) ld b, a push bc ld hl, wDefaultText inc a call ConvertToNumericalDigits - ld [hl], $77 + ld [hl], "FW0_·" inc hl - ld [hl], $00 + ld [hl], TX_END call InitTextPrinting ld hl, wDefaultText call ProcessText pop af + +; get the deck corresponding to input index +; and append its name to wDefaultText push af sla a ld l, a - ld h, $00 - ld bc, wd00d + ld h, $0 + ld bc, wMachineDeckPtrs add hl, bc ld a, [hli] ld h, [hl] @@ -5550,54 +8831,62 @@ Func_b424: ; b424 (2:7424) inc d inc d push de - call Func_92be + call AppendDeckName pop de pop bc - jr nc, .asm_b46b + jr nc, .valid_deck + +; invalid deck, give it the default +; empty deck name ("--------------") call InitTextPrinting - ldtx hl, Text025b + ldtx hl, EmptyDeckNameText call ProcessTextFromID ld d, 13 inc e call InitTextPrinting - ld hl, Text_b4d4 + ld hl, .text call ProcessText scf ret -.asm_b46b +.valid_deck push de push bc ld d, 18 call InitTextPrinting - ld a, $00 - call Func_b625 + +; print the symbol that symbolizes whether the deck can +; be built, or if another deck has to be dismantled to build it + ld a, $0 ; no decks dismantled + call CheckIfCanBuildSavedDeck pop bc ld hl, wDefaultText - jr c, .asm_b482 - ld de, $35f + jr c, .cannot_build + lb de, 3, "FW3_○" ; can build jr .asm_b4c2 - -.asm_b482 +.cannot_build push bc - ld a, $ff - call Func_b625 - jr c, .asm_b490 + ld a, ALL_DECKS + call CheckIfCanBuildSavedDeck + jr c, .cannot_build_at_all pop bc - ld de, $360 + lb de, 3, "FW3_❄" ; can build by dismantling jr .asm_b4c2 -.asm_b490 - ld de, $6c +.cannot_build_at_all + lb de, 0, "FW0_✕" ; cannot build even by dismantling call Func_22ca pop bc pop de + +; place in wDefaultText the number of cards +; that are needed in order to build the deck push bc ld d, 17 inc e call InitTextPrinting pop bc - call Func_b4e1 + call .GetNumCardsMissingToBuildDeck call CalculateOnesAndTensDigits ld hl, wOnesAndTensPlace ld a, [hli] @@ -5623,85 +8912,223 @@ Func_b424: ; b424 (2:7424) ld d, 13 inc e call InitTextPrinting - ld hl, Text_b4d4 + ld hl, .text call ProcessText or a ret -; 0xb4d4 -Text_b4d4: ; b4d4 (2:74d4) +.text db TX_SYMBOL, TX_END db TX_SYMBOL, TX_END db TX_SYMBOL, TX_END db TX_SYMBOL, TX_END db TX_SYMBOL, TX_END db TX_SYMBOL, TX_END - db TX_END -; 0xb4e1 + done -Func_b4e1: ; b4e1 (2:74e1) +; outputs in a the number of cards that the player does not own +; in order to build the deck entry from wMachineDeckPtrs +; given in register b +.GetNumCardsMissingToBuildDeck push bc - call Func_b644 - call Func_a3ca - call Func_b664 + call SafelySwitchToSRAM0 + call CreateCardCollectionListWithDeckCards + call SafelySwitchToTempSRAMBank pop bc + +; get address to cards for the corresponding deck entry sla b ld c, b ld b, $00 - ld hl, wd00d + ld hl, wMachineDeckPtrs add hl, bc ld a, [hli] ld h, [hl] ld l, a - ld bc, $18 + ld bc, DECK_NAME_SIZE add hl, bc + call EnableSRAM ld de, wTempCardCollection - ld bc, $0 -.asm_b505 + lb bc, 0, 0 +.loop inc b ld a, DECK_SIZE cp b - jr c, .asm_b520 + jr c, .done ld a, [hli] push hl ld l, a ld h, $00 add hl, de ld a, [hl] - and $7f + and CARD_COUNT_MASK or a - jr z, .asm_b51c + jr z, .none dec a ld [hl], a pop hl - jr .asm_b505 -.asm_b51c + jr .loop +.none inc c pop hl - jr .asm_b505 -.asm_b520 + jr .loop +.done ld a, c call DisableSRAM ret ; 0xb525 - INCROM $b525, $b545 +; counts how many decks in sSavedDecks are not empty +; stores value in wNumSavedDecks +GetSavedDeckCount: ; b525 (2:7525) + call EnableSRAM + ld hl, sSavedDecks + ld bc, DECK_STRUCT_SIZE + ld d, NUM_DECK_SAVE_MACHINE_SLOTS + ld e, 0 +.loop + ld a, [hl] + or a + jr z, .empty_slot + inc e +.empty_slot + dec d + jr z, .got_count + add hl, bc + jr .loop +.got_count + ld a, e + ld [wNumSavedDecks], a + call DisableSRAM + ret +; 0xb545 -Func_b545: ; b545 (2:7545) - INCROM $b545, $b592 +; prints "[wNumSavedDecks]/60" +PrintNumSavedDecks: ; b545 (2:7545) + ld a, [wNumSavedDecks] + ld hl, wDefaultText + call ConvertToNumericalDigits + ld a, TX_SYMBOL + ld [hli], a + ld a, SYM_SLASH + ld [hli], a + ld a, NUM_DECK_SAVE_MACHINE_SLOTS + call ConvertToNumericalDigits + ld [hl], TX_END + lb de, 14, 1 + call InitTextPrinting + ld hl, wDefaultText + call ProcessText + ret +; 0xb568 -Func_b592: ; b592 (2:7592) - INCROM $b592, $b611 +; prints "X/Y" where X is the current list index +; and Y is the total number of saved decks +; unreferenced? +Func_b568: ; b568 (2:7568) + ld a, [wCardListCursorPos] + ld b, a + ld a, [wCardListVisibleOffset] + add b + inc a + ld hl, wDefaultText + call ConvertToNumericalDigits + ld a, TX_SYMBOL + ld [hli], a + ld a, SYM_SLASH + ld [hli], a + ld a, [wNumSavedDecks] + call ConvertToNumericalDigits + ld [hl], TX_END + lb de, 14, 1 + call InitTextPrinting + ld hl, wDefaultText + call ProcessText + ret +; 0xb592 -Func_b611: ; b611 (2:7611) +; handles player choice in what deck to save +; in the Deck Save Machine +; assumes the slot to save was selected and +; is stored in wSelectedDeckMachineEntry +; if operation was successful, return carry +SaveDeckInDeckSaveMachine: ; b592 (2:7592) + ld a, ALL_DECKS + call DrawDecksScreen + xor a +.wait_input + ld hl, DeckMachineMenuParameters + call InitializeMenuParameters + ldtx hl, ChooseADeckToSaveText + call DrawWideTextBox_PrintText +.wait_submenu_input + call DoFrame + call HandleStartButtonInDeckSelectionMenu + jr c, .wait_input + call HandleMenuInput + jp nc, .wait_submenu_input ; can be jr + ldh a, [hCurMenuItem] + cp $ff + ret z ; operation cancelled + ld [wCurDeck], a + call CheckIfCurDeckIsValid + jp nc, .SaveDeckInSelectedEntry ; can be jr + ; is an empty deck + call PrintThereIsNoDeckHereText + ld a, [wCurDeck] + jr .wait_input + +; overwrites data in the selected deck in SRAM +; with the deck that was chosen, in wCurDeck +; then returns carry +.SaveDeckInSelectedEntry + call GetPointerToDeckName + call GetSelectedSavedDeckPtr + ld b, DECK_STRUCT_SIZE + call EnableSRAM + call CopyNBytesFromHLToDE + call DisableSRAM + + call ClearScreenAndDrawDeckMachineScreen + call DrawListScrollArrows + call PrintNumSavedDecks + ld a, [wTempDeckMachineCursorPos] + ld hl, DeckMachineSelectionParams + call InitCardSelectionParams + call DrawListCursor_Visible + call GetPointerToDeckName + call EnableSRAM + call CopyDeckName + call DisableSRAM + xor a + ld [wTxRam2 + 0], a + ld [wTxRam2 + 1], a + ldtx hl, SavedTheConfigurationForText + call DrawWideTextBox_WaitForInput + scf + ret +; 0xb609 + +DeckMachineMenuParameters: ; b609 (2:7609) + db 1, 2 ; cursor x, cursor y + db 3 ; y displacement between items + db 4 ; number of items + db SYM_CURSOR_R ; cursor tile number + db SYM_SPACE ; tile behind cursor + dw NULL ; function pointer if non-0 +; 0xb611 + +; outputs in de pointer of saved deck +; corresponding to index in wSelectedDeckMachineEntry +GetSelectedSavedDeckPtr: ; b611 (2:7611) push af push hl - ld a, [wd088] + ld a, [wSelectedDeckMachineEntry] sla a ld e, a ld d, $00 - ld hl, wd00d + ld hl, wMachineDeckPtrs add hl, de ld e, [hl] inc hl @@ -5711,236 +9138,881 @@ Func_b611: ; b611 (2:7611) ret ; 0xb625 -Func_b625: ; b625 (2:7625) - INCROM $b625, $b644 +; checks if it's possible to build saved deck with index b +; includes cards from already built decks from flags in a +; returns carry if cannot build the deck with the given criteria +; a = DECK_* flags for which decks to include in the collection +; b = saved deck index +CheckIfCanBuildSavedDeck: ; b625 (2:7625) + push bc + call SafelySwitchToSRAM0 + call CreateCardCollectionListWithDeckCards + call SafelySwitchToTempSRAMBank + pop bc + sla b + ld c, b + ld b, $0 + ld hl, wMachineDeckPtrs + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + ld bc, DECK_NAME_SIZE + add hl, bc + call CheckIfHasEnoughCardsToBuildDeck + ret +; 0xb644 -Func_b644: ; b644 (2:7644) - INCROM $b644, $b653 +; switches to SRAM bank 0 and stores current SRAM bank in wTempBankSRAM +; skips if current SRAM bank is already 0 +SafelySwitchToSRAM0: ; b644 (2:7644) + push af + ldh a, [hBankSRAM] + or a + jr z, .skip + ld [wTempBankSRAM], a + xor a + call BankswitchSRAM +.skip + pop af + ret +; 0xb653 -Func_b653: ; b653 (2:7653) - INCROM $b653, $b664 +; switches to SRAM bank 1 and stores current SRAM bank in wTempBankSRAM +; skips if current SRAM bank is already 1 +SafelySwitchToSRAM1: ; b653 (2:7653) + push af + ldh a, [hBankSRAM] + cp BANK("SRAM1") + jr z, .skip + ld [wTempBankSRAM], a + ld a, BANK("SRAM1") + call BankswitchSRAM +.skip + pop af + ret +; 0xb664 -Func_b664: ; b664 (2:7664) +SafelySwitchToTempSRAMBank: ; b664 (2:7664) push af push bc ldh a, [hBankSRAM] ld b, a - ld a, [wd0a4] + ld a, [wTempBankSRAM] cp b - jr z, .asm_b672 + jr z, .skip call BankswitchSRAM -.asm_b672 +.skip pop bc pop af ret ; 0xb675 - INCROM $b675, $b6ca +; returns carry if wTempCardCollection does not +; have enough cards to build deck pointed by hl +; hl = pointer to cards of deck to check +CheckIfHasEnoughCardsToBuildDeck: ; b675 (2:7675) + call EnableSRAM + ld de, wTempCardCollection + ld b, 0 +.loop + inc b + ld a, DECK_SIZE + cp b + jr c, .no_carry + ld a, [hli] + push hl + ld l, a + ld h, $00 + add hl, de + ld a, [hl] + or a + jr z, .set_carry + cp CARD_NOT_OWNED + jr z, .set_carry + dec a + ld [hl], a + pop hl + jr .loop + +.set_carry + pop hl + call DisableSRAM + scf + ret + +.no_carry + call DisableSRAM + or a + ret +; 0xb6a1 + +; outputs in a the first slot that is empty to build a deck +; if no empty slot is found, return carry +FindFirstEmptyDeckSlot: ; b6a1 (2:76a1) + ld hl, sDeck1Cards + ld a, [hl] + or a + jr nz, .check_deck_2 + xor a + ret + +.check_deck_2 + ld hl, sDeck2Cards + ld a, [hl] + or a + jr nz, .check_deck_3 + ld a, 1 + ret + +.check_deck_3 + ld hl, sDeck3Cards + ld a, [hl] + or a + jr nz, .check_deck_4 + ld a, 2 + ret + +.check_deck_4 + ld hl, sDeck4Cards + ld a, [hl] + or a + jr nz, .set_carry + ld a, 3 + ret + +.set_carry + scf + ret +; 0xb6ca + +; prompts the player whether to delete selected saved deck +; if player selects yes, clears memory in SRAM +; corresponding to that saved deck slot +; if player selects no, return carry +TryDeleteSavedDeck: ; b6ca (2:76ca) + ldtx hl, DoYouReallyWishToDeleteText + call YesOrNoMenuWithText + jr c, .no + call GetSelectedSavedDeckPtr + ld l, e + ld h, d + push hl + call EnableSRAM + call CopyDeckName + pop hl + ld a, DECK_STRUCT_SIZE + call ClearNBytesFromHL + call DisableSRAM + xor a + ld [wTxRam2 + 0], a + ld [wTxRam2 + 1], a + ldtx hl, DeletedTheConfigurationForText + call DrawWideTextBox_WaitForInput + or a + ret + +.no + ld a, [wCardListCursorPos] + scf + ret +; 0xb6fb + +DeckMachineSelectionParams: ; b6fb (2:76fb) + db 1 ; x pos + db 2 ; y pos + db 2 ; y spacing + db 0 ; x spacing + db 5 ; num entries + db SYM_CURSOR_R ; visible cursor tile + db SYM_SPACE ; invisible cursor tile + dw NULL ; wCardListHandlerFunction + +DrawListScrollArrows: ; b704 (2:7704) + ld a, [wCardListVisibleOffset] + or a + jr z, .no_up_cursor + ld a, SYM_CURSOR_U + jr .got_tile_1 +.no_up_cursor + ld a, SYM_BOX_RIGHT +.got_tile_1 + lb bc, 19, 1 + call WriteByteToBGMap0 + + ld a, [wCardListVisibleOffset] + add NUM_DECK_MACHINE_VISIBLE_DECKS + 1 + ld b, a + ld a, [wNumDeckMachineEntries] + cp b + jr c, .no_down_cursor + xor a ; FALSE + ld [wUnableToScrollDown], a + ld a, SYM_CURSOR_D + jr .got_tile_2 +.no_down_cursor + ld a, TRUE + ld [wUnableToScrollDown], a + ld a, SYM_BOX_RIGHT +.got_tile_2 + lb bc, 19, 11 + call WriteByteToBGMap0 + ret +; 0xb738 + +; handles the deck menu for when the player +; needs to make space for new deck to build +HandleDismantleDeckToMakeSpace: ; b738 (2:7738) + ldtx hl, YouMayOnlyCarry4DecksText + call DrawWideTextBox_WaitForInput + call SafelySwitchToSRAM0 + ld a, ALL_DECKS + call DrawDecksScreen + xor a +.init_menu_params + ld hl, DeckMachineMenuParameters + call InitializeMenuParameters + ldtx hl, ChooseADeckToDismantleText + call DrawWideTextBox_PrintText +.loop_input + call DoFrame + call HandleStartButtonInDeckSelectionMenu + jr c, .init_menu_params + call HandleMenuInput + jp nc, .loop_input ; can be jr + ldh a, [hCurMenuItem] + cp $ff + jr nz, .selected_deck + ; operation was cancelled + call SafelySwitchToTempSRAMBank + scf + ret + +.selected_deck + ld [wCurDeck], a + ldtx hl, DismantleThisDeckText + call YesOrNoMenuWithText + jr nc, .dismantle + ld a, [wCurDeck] + jr .init_menu_params + +.dismantle + call GetPointerToDeckName + push hl + ld de, wDismantledDeckName + call EnableSRAM + call CopyListFromHLToDE + pop hl + push hl + ld bc, DECK_NAME_SIZE + add hl, bc + call AddDeckToCollection + pop hl + ld a, DECK_STRUCT_SIZE + call ClearNBytesFromHL + call DisableSRAM + + ; redraw deck screen + ld a, ALL_DECKS + call DrawDecksScreen + ld a, [wCurDeck] + ld hl, DeckMachineMenuParameters + call InitializeMenuParameters + call DrawCursor2 + call SafelySwitchToTempSRAMBank + ld hl, wDismantledDeckName + call CopyDeckName + xor a + ld [wTxRam2 + 0], a + ld [wTxRam2 + 1], a + ldtx hl, DismantledDeckText + call DrawWideTextBox_WaitForInput + ld a, [wCurDeck] + ret +; 0xb7c6 + +; tries to build the deck in wSelectedDeckMachineEntry +; will check if can be built with or without dismantling +; prompts the player in case a deck has to be dismantled +; or, if it's impossible to build deck, shows missing cards list +TryBuildDeckMachineDeck: ; b7c6 (2:77c6) + ld a, [wSelectedDeckMachineEntry] + ld b, a + push bc + ld a, $0 + call CheckIfCanBuildSavedDeck + pop bc + jr nc, .build_deck + ld a, ALL_DECKS + call CheckIfCanBuildSavedDeck + jr c, .do_not_own_all_cards_needed + ; can only be built by dismantling some deck + ldtx hl, ThisDeckCanOnlyBeBuiltIfYouDismantleText + call DrawWideTextBox_WaitForInput + call .DismantleDecksNeededToBuild + jr nc, .build_deck + ; player chose not to dismantle -Func_b6ca: ; b6ca (2:76ca) - INCROM $b6ca, $b6fb +.set_carry_and_return + ld a, [wCardListCursorPos] + scf + ret -Data_b6fb: ; b6fb (2:76fb) - db $01, $02, $02, $00, $05, $0f, $00, $00, $00 +.do_not_own_all_cards_needed + ldtx hl, YouDoNotOwnAllCardsNeededToBuildThisDeckText + call DrawWideTextBox_WaitForInput + jp .ShowMissingCardList -Func_b704: ; b704 (2:7704) - INCROM $b704, $b7c6 +.build_deck + call EnableSRAM + call SafelySwitchToSRAM0 + call FindFirstEmptyDeckSlot + call SafelySwitchToTempSRAMBank + call DisableSRAM + jr nc, .got_deck_slot + call HandleDismantleDeckToMakeSpace + jr nc, .got_deck_slot + scf + ret -Func_b7c6: ; b7c6 (2:77c6) - INCROM $b7c6, $ba04 +.got_deck_slot + ld [wDeckSlotForNewDeck], a + ld a, [wSelectedDeckMachineEntry] + ld c, a + ld b, $0 + sla c + ld hl, wMachineDeckPtrs + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + + ; copy deck to buffer + ld de, wDeckToBuild + ld b, DECK_STRUCT_SIZE + call EnableSRAM + call CopyNBytesFromHLToDE + + ; remove the needed cards from collection + ld hl, wDeckToBuild + DECK_NAME_SIZE + call SafelySwitchToSRAM0 + call DecrementDeckCardsInCollection + + ; copy the deck cards from the buffer + ; to the deck slot that was chosen + ld a, [wDeckSlotForNewDeck] + ld l, a + ld h, DECK_STRUCT_SIZE + call HtimesL + ld bc, sBuiltDecks + add hl, bc + ld d, h + ld e, l + ld hl, wDeckToBuild + ld b, DECK_STRUCT_SIZE + call CopyNBytesFromHLToDE + call DisableSRAM -Func_ba04: ; ba04 (2:7a04) - ld a, [wd0a9] - ld hl, Data_bb83 + ; draw Decks screen + ld a, ALL_DECKS + call DrawDecksScreen + ld a, [wDeckSlotForNewDeck] + ld [wCurDeck], a + ld hl, DeckMachineMenuParameters + call InitializeMenuParameters + call DrawCursor2 + call GetPointerToDeckName + call EnableSRAM + call CopyDeckName + call DisableSRAM + call SafelySwitchToTempSRAMBank + xor a + ld [wTxRam2 + 0], a + ld [wTxRam2 + 1], a + ldtx hl, BuiltDeckText + call DrawWideTextBox_WaitForInput + scf + ret + +; asks the player for confirmation to dismantle decks +; needed to build the selected deck from the Deck Save Machine +; returns carry set if player selected "no" +; if player selected "yes", dismantle decks +.DismantleDecksNeededToBuild +; shows Decks screen with the names +; of the decks to be dismantled + farcall CheckWhichDecksToDismantleToBuildSavedDeck + call SafelySwitchToSRAM0 + call DrawDecksScreen + ldtx hl, DismantleTheseDecksText + call YesOrNoMenuWithText + jr nc, .yes +; no + call SafelySwitchToTempSRAMBank + scf + ret + +.yes + call EnableSRAM + ld a, [wDecksToBeDismantled] + bit DECK_1_F, a + jr z, .deck_2 + ld a, DECK_1_F + call .DismantleDeck +.deck_2 + ld a, [wDecksToBeDismantled] + bit DECK_2_F, a + jr z, .deck_3 + ld a, DECK_2_F + call .DismantleDeck +.deck_3 + ld a, [wDecksToBeDismantled] + bit DECK_3_F, a + jr z, .deck_4 + ld a, DECK_3_F + call .DismantleDeck +.deck_4 + ld a, [wDecksToBeDismantled] + bit DECK_4_F, a + jr z, .done_dismantling + ld a, DECK_4_F + call .DismantleDeck + +.done_dismantling + call DisableSRAM + ld a, [wDecksToBeDismantled] + call DrawDecksScreen + call SafelySwitchToTempSRAMBank + ldtx hl, DismantledTheDeckText + call DrawWideTextBox_WaitForInput + or a + ret + +; dismantles built deck given by a +; and adds its cards to the collection +; a = DECK_*_F to dismantle +.DismantleDeck + ld l, a + ld h, DECK_STRUCT_SIZE + call HtimesL + ld bc, sBuiltDecks + add hl, bc + push hl + ld bc, DECK_NAME_SIZE + add hl, bc + call AddDeckToCollection + pop hl + ld a, DECK_STRUCT_SIZE + call ClearNBytesFromHL + ret + +; collects cards missing from player's collection +; and shows its confirmation list +.ShowMissingCardList +; copy saved deck card from SRAM to wCurDeckCards +; and make unique card list sorted by ID + ld a, [wSelectedDeckMachineEntry] + ld [wCurDeck], a + call GetSelectedSavedDeckPtr + ld hl, DECK_NAME_SIZE + add hl, de + ld de, wCurDeckCards + ld b, DECK_SIZE + call EnableSRAM + call CopyNBytesFromHLToDE + call DisableSRAM + xor a ; terminator byte for deck + ld [wCurDeckCards + DECK_SIZE], a + call SortCurDeckCardsByID + call CreateCurDeckUniqueCardList + +; create collection card list, including +; the cards from all built decks + ld a, ALL_DECKS + call SafelySwitchToSRAM0 + call CreateCardCollectionListWithDeckCards + call SafelySwitchToTempSRAMBank + +; creates list in wFilteredCardList with +; cards that are missing to build this deck + ld hl, wUniqueDeckCardList + ld de, wFilteredCardList +.loop_deck_configuration + ld a, [hli] + or a + jr z, .finish_missing_card_list + ld b, a + push bc + push de + push hl + ld hl, wCurDeckCards + call .CheckIfCardIsMissing + pop hl + pop de + pop bc + jr nc, .loop_deck_configuration + ; this card is missing + ; store in wFilteredCardList this card ID + ; a number of times equal to the amount still needed + ld c, a + ld a, b +.loop_number_missing + ld [de], a + inc de + dec c + jr nz, .loop_number_missing + jr .loop_deck_configuration + +.finish_missing_card_list + xor a ; terminator byte + ld [de], a + + ldtx bc, TheseCardsAreNeededToBuildThisDeckText + ld hl, wCardConfirmationText + ld a, c + ld [hli], a + ld a, b + ld [hl], a + + call GetSelectedSavedDeckPtr + ld h, d + ld l, e + ld de, wFilteredCardList + call HandleDeckMissingCardsList + jp .set_carry_and_return + +; checks if player has enough cards with ID given in register a +; in the collection to build the deck and, if not, returns +; carry set and outputs in a the difference +; a = card ID +; hl = deck cards +.CheckIfCardIsMissing + call .GetCardCountFromDeck + ld hl, wTempCardCollection + push de + call .GetCardCountFromCollection + ld a, e + pop de + + ; d = card count in deck + ; a = card count in collection + cp d + jr c, .not_enough + or a + ret + +.not_enough +; needs more cards than player owns in collection +; return carry set and the number of cards needed + ld e, a + ld a, d + sub e + scf + ret z + +; returns in d the card count of card ID given in register a +; that is found in the card list in hl +; a = card ID +; hl = deck cards +.GetCardCountFromDeck + push af + ld e, a + ld d, 0 +.loop_deck_cards + ld a, [hli] + or a + jr z, .done_deck_cards + cp e + jr nz, .loop_deck_cards + inc d + jr .loop_deck_cards +.done_deck_cards + pop af + ret + +; returns in e the card count of card ID given in register a +; that is found in the card collection +; a = card ID +; hl = card collection +.GetCardCountFromCollection + push af + ld e, a + ld d, $0 + add hl, de + ld a, [hl] + and CARD_COUNT_MASK + ld e, a + pop af + ret +; 0xb991 + +PrinterMenu_DeckConfiguration: ; b991 (2:7991) + xor a + ld [wCardListVisibleOffset], a + call ClearScreenAndDrawDeckMachineScreen + ld a, DECK_SIZE + ld [wNumDeckMachineEntries], a + + xor a +.asm_b99e + ld hl, DeckMachineSelectionParams + call InitCardSelectionParams + call DrawListScrollArrows + call PrintNumSavedDecks + ldtx hl, PleaseChooseDeckConfigurationToPrintText + call DrawWideTextBox_PrintText + ldtx de, PleaseChooseDeckConfigurationToPrintText + call InitDeckMachineDrawingParams +.asm_b9b6 + call HandleDeckMachineSelection + jr c, .asm_b99e + cp $ff + ret z + + ld b, a + ld a, [wCardListVisibleOffset] + add b + ld [wSelectedDeckMachineEntry], a + call CheckIfSelectedDeckMachineEntryIsEmpty + jr c, .asm_b9b6 + call DrawWideTextBox + ldtx hl, PrintThisDeckText + call YesOrNoMenuWithText + jr c, .no + call GetSelectedSavedDeckPtr + ld hl, $18 + add hl, de + ld de, wCurDeckCards + ld b, DECK_SIZE + call EnableSRAM + call CopyNBytesFromHLToDE + call DisableSRAM + xor a ; terminator byte for deck + ld [wCurDeckCards + DECK_SIZE], a + call SortCurDeckCardsByID + ld a, [wSelectedDeckMachineEntry] + bank1call Func_7580 + call ClearScreenAndDrawDeckMachineScreen + +.no + ld a, [wTempDeckMachineCursorPos] + ld [wCardListCursorPos], a + jp .asm_b99e +; 0xba04 + +HandleAutoDeckMenu: ; ba04 (2:7a04) + ld a, [wCurAutoDeckMachine] + ld hl, .DeckMachineTitleTextList sla a ld c, a ld b, $0 add hl, bc - ld de, wd0a2 + ld de, wDeckMachineTitleText ld a, [hli] ld [de], a inc de ld a, [hl] ld [de], a xor a - ld [wcea1], a - call Func_bb97 - ld a, $5 - ld [wd0a5], a + ld [wCardListVisibleOffset], a + call .InitAutoDeckMenu + ld a, NUM_DECK_MACHINE_SLOTS + ld [wNumDeckMachineEntries], a xor a - ; fallthrough -Func_ba25: ; ba25 (2:7a25) - ld hl, Func_bb6e +.please_select_deck + ld hl, .MenuParameters call InitializeMenuParameters ldtx hl, PleaseSelectDeckText call DrawWideTextBox_PrintText - ld a, $5 - ld [wNamingScreenKeyboardHeight], a - ld hl, Unknown_b3fe + ld a, NUM_DECK_MACHINE_SLOTS + ld [wCardListNumCursorPositions], a + ld hl, UpdateDeckMachineScrollArrowsAndEntries ld d, h ld a, l - ld hl, wcece + ld hl, wCardListUpdateFunction ld [hli], a ld [hl], d -.asm_ba40 +.wait_input call DoFrame call HandleMenuInput - jr c, .asm_baa3 + jr c, .deck_selection_made + +; the following lines do nothing ldh a, [hDPadHeld] and D_UP | D_DOWN jr z, .asm_ba4e - .asm_ba4e + +; check whether to show deck confirmation list ldh a, [hDPadHeld] and START - jr z, .asm_ba40 - ld a, [wcea1] - ld [wd087], a + jr z, .wait_input + + ld a, [wCardListVisibleOffset] + ld [wTempCardListVisibleOffset], a ld b, a ld a, [wCurMenuItem] - ld [wd086], a + ld [wTempDeckMachineCursorPos], a add b ld c, a inc a or $80 - ld [wceb1], a + ld [wCurDeck], a sla c ld b, $0 - ld hl, wd00d + ld hl, wMachineDeckPtrs add hl, bc - call Func_b653 + call SafelySwitchToSRAM1 ld a, [hli] ld h, [hl] ld l, a push hl - ld bc, $0018 + ld bc, DECK_NAME_SIZE add hl, bc ld d, h ld e, l ld a, [hl] pop hl - call Func_b644 + call SafelySwitchToSRAM0 or a - jr z, .asm_ba40 + jr z, .wait_input ; invalid deck + + ; show confirmation list ld a, $1 call PlaySFXConfirmOrCancel - call Func_b653 - call Func_8e1f - call Func_b644 - ld a, [wd087] - ld [wcea1], a - call Func_bb97 - ld a, [wd086] - jp Func_ba25 - -.asm_baa3 + call SafelySwitchToSRAM1 + call OpenDeckConfirmationMenu + call SafelySwitchToSRAM0 + ld a, [wTempCardListVisibleOffset] + ld [wCardListVisibleOffset], a + call .InitAutoDeckMenu + ld a, [wTempDeckMachineCursorPos] + jp .please_select_deck + +.deck_selection_made call DrawCursor2 - ld a, [wcea1] - ld [wd087], a + ld a, [wCardListVisibleOffset] + ld [wTempCardListVisibleOffset], a ld a, [wCurMenuItem] - ld [wd086], a + ld [wTempDeckMachineCursorPos], a ldh a, [hCurMenuItem] cp $ff - jp z, .asm_bb0d - ld [wd088], a + jp z, .exit ; operation cancelled + ld [wSelectedDeckMachineEntry], a call ResetCheckMenuCursorPositionAndBlink xor a ld [wce5e], a call DrawWideTextBox - ld hl, Data_bb76 + ld hl, .DeckMachineMenuData call PlaceTextItems -.asm_bacc +.wait_submenu_input call DoFrame call HandleCheckMenuInput_YourOrOppPlayArea - jp nc, .asm_bacc + jp nc, .wait_submenu_input cp $ff - jr nz, .asm_badf - ld a, [wd086] - jp Func_ba25 + jr nz, .submenu_option_selected + ld a, [wTempDeckMachineCursorPos] + jp .please_select_deck -.asm_badf +.submenu_option_selected ld a, [wCheckMenuCursorYPosition] sla a ld hl, wCheckMenuCursorXPosition add [hl] or a jr nz, .asm_bb09 - call Func_b653 - call Func_b7c6 - call Func_b644 - ld a, [wd086] - jp nc, Func_ba25 - ld a, [wd087] - ld [wcea1], a - call Func_bb97 - ld a, [wd086] - jp Func_ba25 + +; Build a Deck + call SafelySwitchToSRAM1 + call TryBuildDeckMachineDeck + call SafelySwitchToSRAM0 + ld a, [wTempDeckMachineCursorPos] + jp nc, .please_select_deck + ld a, [wTempCardListVisibleOffset] + ld [wCardListVisibleOffset], a + call .InitAutoDeckMenu + ld a, [wTempDeckMachineCursorPos] + jp .please_select_deck .asm_bb09 cp $1 - jr nz, .asm_bb12 -.asm_bb0d + jr nz, .read_the_instructions +.exit xor a - ld [wd0a4], a + ld [wTempBankSRAM], a ret -.asm_bb12 - ld a, [wcea1] - ld [wd087], a +.read_the_instructions +; show card confirmation list + ld a, [wCardListVisibleOffset] + ld [wTempCardListVisibleOffset], a ld b, a ld a, [wCurMenuItem] - ld [wd086], a + ld [wTempDeckMachineCursorPos], a add b ld c, a - ld [wceb1], a + ld [wCurDeck], a sla c ld b, $0 - ld hl, wd00d + ld hl, wMachineDeckPtrs add hl, bc + + ; set the description text in text box push hl - ld hl, wd0aa + ld hl, wAutoDeckMachineTextDescriptions add hl, bc - ld bc, wcfda + ld bc, wCardConfirmationText ld a, [hli] ld [bc], a inc bc ld a, [hl] ld [bc], a pop hl - call Func_b653 + + call SafelySwitchToSRAM1 ld a, [hli] ld h, [hl] ld l, a push hl - ld bc, $0018 + ld bc, DECK_NAME_SIZE add hl, bc ld d, h ld e, l ld a, [hl] pop hl - call Func_b644 + call SafelySwitchToSRAM0 or a - jp z, .asm_ba40 + jp z, .wait_input ; invalid deck + + ; show confirmation list ld a, $1 call PlaySFXConfirmOrCancel - call Func_b653 + call SafelySwitchToSRAM1 xor a - call Func_adfe - call Func_b644 - ld a, [wd087] - ld [wcea1], a - call Func_bb97 - ld a, [wd086] - jp Func_ba25 - -Func_bb6e: ; bb6e (2:7b6e) - INCROM $bb6e, $bb76 + call HandleDeckMissingCardsList + call SafelySwitchToSRAM0 + ld a, [wTempCardListVisibleOffset] + ld [wCardListVisibleOffset], a + call .InitAutoDeckMenu + ld a, [wTempDeckMachineCursorPos] + jp .please_select_deck + +.MenuParameters + db 1, 2 ; cursor x, cursor y + db 2 ; y displacement between items + db 5 ; number of items + db SYM_CURSOR_R ; cursor tile number + db SYM_SPACE ; tile behind cursor + dw NULL ; function pointer if non-0 -Data_bb76: ; bb76 (2:7b76) - INCROM $bb76, $bb83 +.DeckMachineMenuData + textitem 2, 14, BuildADeckText + textitem 12, 14, CancelText + textitem 2, 16, ReadTheInstructionsText + db $ff -Data_bb83: ; bb83 (2:7b83) +.DeckMachineTitleTextList tx FightingMachineText tx RockMachineText tx WaterMachineText @@ -5952,32 +10024,88 @@ Data_bb83: ; bb83 (2:7b83) tx AutoMachineText tx LegendaryMachineText -Func_bb97: ; bb97 (2:7b97) - INCROM $bb97, $bc04 +; clears screen, loads the proper tiles +; prints the Auto Deck title and deck entries +; and creates the auto deck configurations +.InitAutoDeckMenu + call Set_OBJ_8x8 + xor a + ld [wTileMapFill], a + call ZeroObjectPositions + call EmptyScreen + ld a, $01 + ld [wVBlankOAMCopyToggle], a + call LoadSymbolsFont + call LoadDuelCardSymbolTiles + bank1call SetDefaultPalettes + lb de, $3c, $ff + call SetupText + lb de, 0, 0 + lb bc, 20, 13 + call DrawRegularTextBox + lb de, 1, 0 + call InitTextPrinting + ld hl, wDeckMachineTitleText + ld a, [hli] + ld h, [hl] + ld l, a + call ProcessTextFromID + call SafelySwitchToSRAM1 + farcall ReadAutoDeckConfiguration + call .CreateAutoDeckPointerList + call PrintVisibleDeckMachineEntries + call SafelySwitchToSRAM0 + call EnableLCD + ret + +; writes to wMachineDeckPtrs the pointers +; to the Auto Decks in sAutoDecks +.CreateAutoDeckPointerList + ld a, 2 * NUM_DECK_MACHINE_SLOTS + ld hl, wMachineDeckPtrs + call ClearNBytesFromHL + ld de, wMachineDeckPtrs + ld hl, sAutoDecks + ld bc, DECK_STRUCT_SIZE + ld a, NUM_DECK_MACHINE_SLOTS +.loop + push af + ld a, l + ld [de], a + inc de + ld a, h + ld [de], a + inc de + add hl, bc + pop af + dec a + jr nz, .loop + ret +; 0xbc04 Func_bc04: ; bc04 (2:7c04) xor a - ld [wcea1], a + ld [wCardListVisibleOffset], a ldtx de, DeckSaveMachineText - ld hl, wd0a2 + ld hl, wDeckMachineTitleText ld [hl], e inc hl ld [hl], d - call Func_b379 + call ClearScreenAndDrawDeckMachineScreen ld a, DECK_SIZE - ld [wd0a5], a + ld [wNumDeckMachineEntries], a xor a .asm_bc1a - ld hl, Data_b6fb - call Func_9a6d - call Func_b704 - call Func_b545 + ld hl, DeckMachineSelectionParams + call InitCardSelectionParams + call DrawListScrollArrows + call PrintNumSavedDecks ldtx hl, PleaseChooseADeckConfigurationToSendText call DrawWideTextBox_PrintText ldtx de, PleaseChooseADeckConfigurationToSendText - call Func_b285 + call InitDeckMachineDrawingParams .asm_bc32 - call Func_b29f + call HandleDeckMachineSelection jr c, .asm_bc1a cp $ff jr nz, .asm_bc3f @@ -5986,17 +10114,17 @@ Func_bc04: ; bc04 (2:7c04) ret .asm_bc3f ld b, a - ld a, [wcea1] + ld a, [wCardListVisibleOffset] add b - ld [wd088], a - call Func_b35b + ld [wSelectedDeckMachineEntry], a + call CheckIfSelectedDeckMachineEntryIsEmpty jr c, .asm_bc32 - call Func_b611 + call GetSelectedSavedDeckPtr ld l, e ld h, d ld de, wDuelTempList - ld b, $54 + ld b, DECK_STRUCT_SIZE call EnableSRAM call CopyNBytesFromHLToDE call DisableSRAM @@ -6006,7 +10134,7 @@ Func_bc04: ; bc04 (2:7c04) bank1call Func_7562 ret c - call Func_b611 + call GetSelectedSavedDeckPtr ld l, e ld h, d ld de, wDefaultText @@ -6019,26 +10147,26 @@ Func_bc04: ; bc04 (2:7c04) Func_bc7a: ; bc7a (2:7c7a) xor a - ld [wcea1], a + ld [wCardListVisibleOffset], a ldtx de, DeckSaveMachineText - ld hl, wd0a2 + ld hl, wDeckMachineTitleText ld [hl], e inc hl ld [hl], d - call Func_b379 + call ClearScreenAndDrawDeckMachineScreen ld a, DECK_SIZE - ld [wd0a5], a + ld [wNumDeckMachineEntries], a xor a .asm_bc90 - ld hl, Data_b6fb - call Func_9a6d - call Func_b704 - call Func_b545 + ld hl, DeckMachineSelectionParams + call InitCardSelectionParams + call DrawListScrollArrows + call PrintNumSavedDecks ldtx hl, PleaseChooseASaveSlotText call DrawWideTextBox_PrintText ldtx de, PleaseChooseASaveSlotText - call Func_b285 - call Func_b29f + call InitDeckMachineDrawingParams + call HandleDeckMachineSelection jr c, .asm_bc90 cp $ff jr nz, .asm_bcb5 @@ -6047,17 +10175,17 @@ Func_bc7a: ; bc7a (2:7c7a) ret .asm_bcb5 ld b, a - ld a, [wcea1] + ld a, [wCardListVisibleOffset] add b - ld [wd088], a - call Func_b35b + ld [wSelectedDeckMachineEntry], a + call CheckIfSelectedDeckMachineEntryIsEmpty jr nc, .asm_bcc4 jr .asm_bcd1 .asm_bcc4 ldtx hl, OKIfFileDeletedText call YesOrNoMenuWithText jr nc, .asm_bcd1 - ld a, [wNamingScreenCursorY] + ld a, [wCardListCursorPos] jr .asm_bc90 .asm_bcd1 xor a @@ -6067,18 +10195,18 @@ Func_bc7a: ; bc7a (2:7c7a) ret c call EnableSRAM ld hl, wDuelTempList - call Func_b611 - ld b, $54 + call GetSelectedSavedDeckPtr + ld b, DECK_STRUCT_SIZE call CopyNBytesFromHLToDE call DisableSRAM call SaveGame - call Func_b379 - ld a, [wNamingScreenCursorY] - ld hl, Data_b6fb - call Func_9a6d - call Func_b704 - call Func_b545 - call Func_9c3a + call ClearScreenAndDrawDeckMachineScreen + ld a, [wCardListCursorPos] + ld hl, DeckMachineSelectionParams + call InitCardSelectionParams + call DrawListScrollArrows + call PrintNumSavedDecks + call DrawListCursor_Visible ld hl, wNameBuffer ld de, wDefaultText call CopyListFromHLToDE @@ -6087,7 +10215,7 @@ Func_bc7a: ; bc7a (2:7c7a) ld [wTxRam2 + 1], a ldtx hl, ReceivedADeckConfigurationFromText call DrawWideTextBox_WaitForInput - call Func_b611 + call GetSelectedSavedDeckPtr ld l, e ld h, d ld de, wDefaultText diff --git a/src/engine/bank03.asm b/src/engine/bank03.asm index d2065ae..75e3081 100644 --- a/src/engine/bank03.asm +++ b/src/engine/bank03.asm @@ -1173,7 +1173,7 @@ Func_c7b8: ; c7b8 (3:47b8) ldh [hSCY], a call Set_OBJ_8x16 farcall Func_1288c - farcall Func_8db0 + farcall DeckSelectionMenu call Set_OBJ_8x8 ret @@ -1183,7 +1183,7 @@ Func_c7cc: ; c7cc (3:47cc) ldh [hSCY], a call Set_OBJ_8x16 farcall Func_1288c - farcall Func_a288 + farcall HandlePlayersCardsScreen call Set_OBJ_8x8 ret @@ -1254,7 +1254,7 @@ Func_c859: ; c859 (3:4859) ldh [hSCY], a call Set_OBJ_8x16 farcall Func_1288c - farcall Func_a913 + farcall HandleCardAlbumScreen call Set_OBJ_8x8 ret @@ -1272,7 +1272,7 @@ Func_c877: ; c877 (3:4877) ldh [hSCY], a call Set_OBJ_8x16 farcall Func_1288c - farcall Func_ad51 + farcall HandlePrinterMenu call Set_OBJ_8x8 call WhiteOutDMGPals call DoFrameIfLCDEnabled @@ -3124,11 +3124,11 @@ ScriptCommand_OpenDeckMachine: ; d336 (3:5336) or a jr z, .asm_d360 dec a - ld [wd0a9], a - farcall Func_ba04 + ld [wCurAutoDeckMachine], a + farcall HandleAutoDeckMenu jr .asm_d364 .asm_d360 - farcall Func_b19d + farcall HandleDeckSaveMachineMenu .asm_d364 call ResumeSong call Func_c2d4 diff --git a/src/engine/bank06.asm b/src/engine/bank06.asm index a03f631..1e728fd 100644 --- a/src/engine/bank06.asm +++ b/src/engine/bank06.asm @@ -746,7 +746,7 @@ OpenGlossaryScreen: ; 184c8 (6:44c8) and SELECT jr nz, .on_select - farcall Func_89ae + farcall YourOrOppPlayAreaScreen_HandleInput jr nc, .next cp -1 ; b button @@ -2050,29 +2050,32 @@ Func_1996e: ; 1996e (6:596e) ldh [hWhoseTurn], a ld hl, sCardCollection ld bc, $1607 -.asm_1997b +.loop_clear xor a ld [hli], a dec bc ld a, c or b - jr nz, .asm_1997b - ld a, $5 - ld hl, s0a350 + jr nz, .loop_clear + + ld a, CHARMANDER_AND_FRIENDS_DECK + ld hl, sSavedDeck1 call Func_199e0 - ld a, $7 - ld hl, s0a3a4 + ld a, SQUIRTLE_AND_FRIENDS_DECK + ld hl, sSavedDeck2 call Func_199e0 - ld a, $9 - ld hl, s0a3f8 + ld a, BULBASAUR_AND_FRIENDS_DECK + ld hl, sSavedDeck3 call Func_199e0 + call EnableSRAM ld hl, sCardCollection ld a, CARD_NOT_OWNED -.asm_199a2 +.loop_collection ld [hl], a inc l - jr nz, .asm_199a2 + jr nz, .loop_collection + ld hl, sCurrentDuel xor a ld [hli], a @@ -2080,15 +2083,16 @@ Func_1996e: ; 1996e (6:596e) ld [hl], a ld hl, sCardPopNameList - ld c, $10 -.asm_199b2 + ld c, CARDPOP_NAME_LIST_MAX_ELEMS +.loop_card_pop_names ld [hl], $0 - ld de, $0010 + ld de, NAME_BUFFER_LENGTH add hl, de dec c - jr nz, .asm_199b2 - ld a, $2 - ld [s0a003], a + jr nz, .loop_card_pop_names + + ld a, 2 + ld [sPrinterContrastLevel], a ld a, $2 ld [sTextSpeed], a ld [wTextSpeed], a @@ -2673,6 +2677,7 @@ CalculateNameHash: ; 19e32 (6:5e32) ret ; 0x19e42 +Func_19e42: ; 19e42 (6:5e42) INCROM $19e42, $19e5a ; shows message on screen depending on wPrinterStatus @@ -2955,7 +2960,7 @@ Func_1a035: ; 1a035 (6:6035) ld a, $10 ld [wce9b], a call EnableSRAM - ld a, [s0a003] + ld a, [sPrinterContrastLevel] ld [wce99], a call DisableSRAM ldh a, [hBankSRAM] @@ -3140,7 +3145,13 @@ Func_1a138: ; 1a138 (6:6138) db $00, $20, $40, $60, $7f ; 0x1a14b - INCROM $1a14b, $1a435 + INCROM $1a14b, $1a162 + +Func_1a162: ; 1a162 (6:6162) + INCROM $1a162, $1a270 + +Func_1a270: ; 1a270 (6:6270) + INCROM $1a270, $1a435 ; compresses $28 tiles in sGfxBuffer5 ; and writes it in sGfxBuffer5 + $28 tiles. @@ -3585,9 +3596,9 @@ InputPlayerName: ; 1a7a3 (6:67a3) ld a, $06 ld [wNamingScreenKeyboardHeight], a ld a, $0f - ld [wceaa], a + ld [wVisibleCursorTile], a ld a, $00 - ld [wceab], a + ld [wInvisibleCursorTile], a .loop ld a, $01 ld [wVBlankOAMCopyToggle], a @@ -3943,12 +3954,12 @@ NamingScreen_CheckButtonState: ; 1a908 (6:6908) inc [hl] and $0f ret nz - ld a, [wceaa] + ld a, [wVisibleCursorTile] bit 4, [hl] jr z, Func_1aa07.asm_6a0a Func_1aa07: ; 1aa07 (6:6a07) - ld a, [wceab] + ld a, [wInvisibleCursorTile] .asm_6a0a ld e, a ld a, [wNamingScreenCursorX] @@ -3967,7 +3978,7 @@ Func_1aa07: ; 1aa07 (6:6a07) ret Func_1aa23: ; 1aa23 (6:6a23) - ld a, [wceaa] + ld a, [wVisibleCursorTile] jr Func_1aa07.asm_6a0a Func_1aa28: ; 1aa28 (6:6a28) @@ -3979,7 +3990,7 @@ Func_1aa28: ; 1aa28 (6:6a28) call ZeroObjectPositions pop af ld b, a - ld a, [wceab] + ld a, [wInvisibleCursorTile] cp b jr z, .asm_6a60 ld a, [wNamingScreenBufferLength] @@ -4449,9 +4460,9 @@ InputDeckName: ; 1ad89 (6:6d89) ld a, $07 ld [wNamingScreenKeyboardHeight], a ld a, $0f - ld [wceaa], a + ld [wVisibleCursorTile], a ld a, $00 - ld [wceab], a + ld [wInvisibleCursorTile], a .loop ld a, $01 ld [wVBlankOAMCopyToggle], a @@ -4741,12 +4752,12 @@ Func_1aefb: ; 1aefb (6:6efb) inc [hl] and $0f ret nz - ld a, [wceaa] + ld a, [wVisibleCursorTile] bit 4, [hl] jr z, Func_1afa1.asm_6fa4 Func_1afa1: ; 1afa1 (6:6fa1) - ld a, [wceab] + ld a, [wInvisibleCursorTile] .asm_6fa4 ld e, a ld a, [wNamingScreenCursorX] @@ -4765,7 +4776,7 @@ Func_1afa1: ; 1afa1 (6:6fa1) ret Func_1afbd: ; 1afbd (6:6fbd) - ld a, [wceaa] + ld a, [wVisibleCursorTile] jr Func_1afa1.asm_6fa4 Func_1afc2: ; 1afc2 (6:6fc2) @@ -4777,7 +4788,7 @@ Func_1afc2: ; 1afc2 (6:6fc2) call ZeroObjectPositions pop af ld b, a - ld a, [wceab] + ld a, [wInvisibleCursorTile] cp b jr z, .asm_6ffb ld a, [wNamingScreenBufferLength] @@ -4914,30 +4925,32 @@ KeyboardData_Deck: ; 1b019 (6:7019) db $0e, $12, $02 db $10, $0f, $01 -; unknown data. -; needs analyze. -; (6:70d6) - INCROM $1b0d6, $1ba12 + ds 4 ; empty -Func_1ba12: ; 1ba12 (6:7a12) - push af - ld [bc], a +INCLUDE "data/auto_deck_card_lists.asm" +INCLUDE "data/auto_deck_machines.asm" + +; writes to sAutoDecks all the deck configurations +; from the Auto Deck Machine in wCurAutoDeckMachine +ReadAutoDeckConfiguration: ; 1ba14 (6:7a14) call EnableSRAM - ld a, [wd0a9] + ld a, [wCurAutoDeckMachine] ld l, a - ld h, $1e + ld h, 6 * NUM_DECK_MACHINE_SLOTS call HtimesL - ld bc, $78e8 + ld bc, AutoDeckMachineEntries add hl, bc - ld b, $00 -.asm_7a26 - call Func_1ba4c - call Func_1ba5b - call Func_1ba7d + ld b, 0 +.loop_decks + call .GetPointerToSRAMAutoDeck + call .ReadDeckConfiguration + call .ReadDeckName + + ; store deck description text ID push hl - ld de, wd0aa + ld de, wAutoDeckMachineTextDescriptions ld h, b - ld l, $02 + ld l, 2 call HtimesL add hl, de ld d, h @@ -4950,24 +4963,27 @@ Func_1ba12: ; 1ba12 (6:7a12) ld [de], a inc b ld a, b - cp $05 - jr nz, .asm_7a26 + cp NUM_DECK_MACHINE_SLOTS + jr nz, .loop_decks call DisableSRAM ret -Func_1ba4c: ; 1ba4c (6:7a4c) +; outputs in de the saved deck with index b +.GetPointerToSRAMAutoDeck push hl ld l, b - ld h, $54 + ld h, DECK_STRUCT_SIZE call HtimesL - ld de, s0a350 + ld de, sAutoDecks add hl, de ld d, h ld e, l pop hl ret -Func_1ba5b: ; 1ba5b (6:7a5b) +; writes the deck configuration in SRAM +; by reading the given deck card list +.ReadDeckConfiguration push hl push bc push de @@ -4976,24 +4992,24 @@ Func_1ba5b: ; 1ba5b (6:7a5b) inc hl ld d, [hl] pop hl - ld bc, $0018 + ld bc, DECK_NAME_SIZE add hl, bc -.asm_7a67 +.loop_create_deck ld a, [de] inc de - ld b, a + ld b, a ; card count or a - jr z, .asm_7a77 + jr z, .done_create_deck ld a, [de] inc de - ld c, a -.asm_7a70 + ld c, a ; card ID +.loop_card_count ld [hl], c inc hl dec b - jr nz, .asm_7a70 - jr .asm_7a67 -.asm_7a77 + jr nz, .loop_card_count + jr .loop_create_deck +.done_create_deck pop de pop bc pop hl @@ -5001,87 +5017,104 @@ Func_1ba5b: ; 1ba5b (6:7a5b) inc hl ret -Func_1ba7d: ; 1ba7d (6:7a7d) +.ReadDeckName push hl push bc push de ld a, [hli] ld h, [hl] ld l, a - ld de, wd089 + ld de, wDismantledDeckName call CopyText pop hl - ld de, wd089 -.asm_7a8d + ld de, wDismantledDeckName +.loop_copy_name ld a, [de] ld [hli], a or a - jr z, .asm_7a95 + jr z, .done_copy_name inc de - jr .asm_7a8d -.asm_7a95 + jr .loop_copy_name +.done_copy_name pop bc pop hl inc hl inc hl ret -; farcall from 0xb87e(2:787d): [EF|06|9A|7A] -Func_1ba9a: ; 1ba9a (6:7a9a) +; tries out all combinations of dismantling the player's decks +; in order to build the deck in wSelectedDeckMachineEntry +; if none of the combinations work, return carry set +; otherwise, return in a which deck flags should be dismantled +CheckWhichDecksToDismantleToBuildSavedDeck: ; 1ba9a (6:7a9a) xor a - ld [wd0a6], a - ld a, $01 -.asm_7aa0 - call Func_1bae4 + ld [wDecksToBeDismantled], a + +; first check if it can be built by +; only dismantling a single deck + ld a, DECK_1 +.loop_single_built_decks + call .CheckIfCanBuild ret nc - sla a - cp $10 - jr z, .asm_7aac - jr .asm_7aa0 -.asm_7aac - ld a, $03 - call Func_1bae4 + sla a ; next deck + cp (1 << NUM_DECKS) + jr z, .two_deck_combinations + jr .loop_single_built_decks + +.two_deck_combinations +; next check all two deck combinations + ld a, DECK_1 | DECK_2 + call .CheckIfCanBuild ret nc - ld a, $05 - call Func_1bae4 + ld a, DECK_1 | DECK_3 + call .CheckIfCanBuild ret nc - ld a, $09 - call Func_1bae4 + ld a, DECK_1 | DECK_4 + call .CheckIfCanBuild ret nc - ld a, $06 - call Func_1bae4 + ld a, DECK_2 | DECK_3 + call .CheckIfCanBuild ret nc - ld a, $0a - call Func_1bae4 + ld a, DECK_2 | DECK_4 + call .CheckIfCanBuild ret nc - ld a, $0c - call Func_1bae4 + ld a, DECK_3 | DECK_4 + call .CheckIfCanBuild ret nc - ld a, $f7 -.asm_7ad2 - call Func_1bae4 + +; all but one deck combinations + ld a, $ff ^ DECK_4 +.loop_three_deck_combinations + call .CheckIfCanBuild ret nc sra a cp $ff - jr z, .asm_7ade - jr .asm_7ad2 -.asm_7ade - call Func_1bae4 + jr z, .all_decks + jr .loop_three_deck_combinations + +.all_decks +; finally check if can be built by dismantling all decks + call .CheckIfCanBuild ret nc + +; none of the combinations work scf ret -Func_1bae4: ; 1bae4 (6:7ae4) +; returns carry if wSelectedDeckMachineEntry cannot be built +; by dismantling the decks given by register a +; a = DECK_* flags +.CheckIfCanBuild push af - ld hl, wd088 + ld hl, wSelectedDeckMachineEntry ld b, [hl] - farcall Func_b625 - jr c, .asm_7af5 + farcall CheckIfCanBuildSavedDeck + jr c, .cannot_build pop af - ld [wd0a6], a + ld [wDecksToBeDismantled], a or a ret -.asm_7af5 +.cannot_build pop af scf ret diff --git a/src/engine/bank1c.asm b/src/engine/bank1c.asm index 1c68fb5..e7eb5e5 100644 --- a/src/engine/bank1c.asm +++ b/src/engine/bank1c.asm @@ -430,7 +430,7 @@ ENDM border_medal_tile v0Tiles1 + $23a, $6a, $10 border_medal_tile v0Tiles1 + $23c, $6b, $10 -; FIGHTING_MEDAL +; PSYCHIC_MEDAL border_medal_tile v0Tiles1 + $2b8, $7e, $10 border_medal_tile v0Tiles1 + $2ba, $7f, $10 border_medal_tile v0Tiles1 + $2bc, $80, $10 @@ -452,7 +452,7 @@ ENDM border_medal_tile v0Tiles1 + $43a, $7c, $10 border_medal_tile v0Tiles1 + $43c, $7d, $10 -; PSYCHIC_MEDAL +; FIGHTING_MEDAL border_medal_tile v0Tiles1 + $4b8, $6c, $10 border_medal_tile v0Tiles1 + $4ba, $6d, $10 border_medal_tile v0Tiles1 + $4bc, $6e, $10 diff --git a/src/engine/effect_functions.asm b/src/engine/effect_functions.asm index b8b4914..f67a89b 100644 --- a/src/engine/effect_functions.asm +++ b/src/engine/effect_functions.asm @@ -6622,7 +6622,7 @@ Peek_SelectEffect: ; 2e2b4 (b:62b4) ; player call Func_3b31 - call Func_30e7 + call HandlePeekSelection ldh [hAIPkmnPowerEffectParam], a call SerialSend8Bytes ret @@ -6660,7 +6660,7 @@ Peek_SelectEffect: ; 2e2b4 (b:62b4) call SwapTurn ldh a, [hAIPkmnPowerEffectParam] xor $80 - call Func_30f9 + call DrawAIPeekScreen call SwapTurn ldtx hl, CardPeekWasUsedOnText call DrawWideTextBox_WaitForInput diff --git a/src/engine/home.asm b/src/engine/home.asm index b848287..0b60609 100644 --- a/src/engine/home.asm +++ b/src/engine/home.asm @@ -9303,46 +9303,47 @@ DrawPlayersPrizeAndBenchCards: ; 30d7 (0:30d7) call BankswitchROM ret -Func_30e7: ; 30e7 (0:30e7) +HandlePeekSelection: ; 30e7 (0:30e7) ldh a, [hBankROM] push af - ld a, BANK(Func_8764) + ld a, BANK(_HandlePeekSelection) call BankswitchROM - call Func_8764 + call _HandlePeekSelection ld b, a pop af call BankswitchROM ld a, b ret -Func_30f9: ; 30f9 (0:30f9) +DrawAIPeekScreen: ; 30f9 (0:30f9) ld b, a ldh a, [hBankROM] push af - ld a, BANK(Func_8932) + ld a, BANK(_DrawAIPeekScreen) call BankswitchROM - call Func_8932 + call _DrawAIPeekScreen pop af call BankswitchROM ret -Func_310a: ; 310a (0:310a) - ld [wce59], a +; a = number of prize cards for player to select to take +SelectPrizeCards: ; 310a (0:310a) + ld [wNumberOfPrizeCardsToSelect], a ldh a, [hBankROM] push af - ld a, BANK(Func_8aaa) + ld a, BANK(_SelectPrizeCards) call BankswitchROM - call Func_8aaa + call _SelectPrizeCards pop af call BankswitchROM ret -Func_311d: ; 311d (0:311d) +DrawPlayAreaToPlacePrizeCards: ; 311d (0:311d) ldh a, [hBankROM] push af - ld a, BANK(Func_8b85) + ld a, BANK(_DrawPlayAreaToPlacePrizeCards) call BankswitchROM - call Func_8b85 + call _DrawPlayAreaToPlacePrizeCards pop af call BankswitchROM ret |