diff --git a/src/constants/menu_constants.asm b/src/constants/menu_constants.asm index 6f5e91c..4b0fcf3 100644 --- a/src/constants/menu_constants.asm +++ b/src/constants/menu_constants.asm @@ -55,6 +55,7 @@ DEF FILTER_ENERGY EQU $20 DEF NUM_FILTERS EQU 9 DEF NUM_DECK_CONFIRMATION_VISIBLE_CARDS EQU 7 +DEF NUM_FILTERED_LIST_VISIBLE_CARDS EQU 6 DEF NUM_DECK_SAVE_MACHINE_SLOTS EQU 50 DEF NUM_DECK_MACHINE_VISIBLE_DECKS EQU 5 diff --git a/src/constants/script_constants.asm b/src/constants/script_constants.asm index 9807bc0..0326590 100644 --- a/src/constants/script_constants.asm +++ b/src/constants/script_constants.asm @@ -330,7 +330,28 @@ ENDR DEF wD606_STRUCT_SIZE EQU $8 DEF SCRIPT_BUFFER_SIZE EQU $20 DEF SCRIPT_STACK_SIZE EQU $10 -DEF wDD37_BUFFER_SIZE EQU $19 + +DEF BLACK_BOX_CARDS_BUFFER_SIZE EQU $14 +DEF MAIL_QUEUE_BUFFER_SIZE EQU $19 +DEF NEW_MAIL EQU $ff +DEF NUM_UNIQUE_MAILS_IN_GAME EQU 29 +DEF MAIL_MAX_NUM EQU 8 +DEF MAIL_MAX_ON_SCREEN EQU 4 +DEF MAIL_BUFFER_SIZE EQU MAIL_MAX_NUM + 1 + +DEF B_MAIL_READ EQU 7 +DEF B_MAIL_PRIORITY_DELIVERY EQU 7 + +DEF B_MAIL_BOOSTER_PACK EQU 7 +DEF B_MAIL_GENERIC_CARD EQU 6 +DEF B_MAIL_BLACK_BOX EQU 5 +DEF B_MAIL_BILLS_PC EQU 4 + +DEF MAIL_COMMAND_GIVE_BOOSTER EQU 1 << B_MAIL_BOOSTER_PACK +DEF MAIL_COMMAND_GIVE_GENERIC_CARD EQU 1 << B_MAIL_GENERIC_CARD +DEF MAIL_COMMAND_GIVE_BLACK_BOX EQU 1 << B_MAIL_BLACK_BOX +DEF MAIL_COMMAND_GIVE_BILLS_PC EQU 1 << B_MAIL_BILLS_PC +DEF MAIL_TERMINATOR EQU $ffff ; TODO: Figure out why 2 is added in IngameCardPop const_def diff --git a/src/data/mail.asm b/src/data/mail.asm new file mode 100644 index 0000000..ef824cf --- /dev/null +++ b/src/data/mail.asm @@ -0,0 +1,345 @@ +MACRO end_mail + dw MAIL_TERMINATOR +ENDM + +MACRO no_card + dw $0000 +ENDM + +Mail: + dw .MailEmpty + dw .MailBlackBox + dw .MailBillsPCOutput + dw .MailMailboxIntro + dw .MailDeckDiagnosis1 + dw .MailDeckDiagnosis2 + dw .MailDeckDiagnosis3 + dw .MailDeckDiagnosis4 + dw .MailAutoDeckMachine1 + dw .MailAutoDeckMachine2 + dw .MailAutoDeckMachine3 + dw .MailAutoDeckMachine4 + dw .MailAutoDeckMachine5 + dw .MailChallengeMachine + dw .MailGRChallengeMachine + dw .MailGrandMasterCup + dw .MailRonaldsScoutGR1 + dw .MailRonaldsScoutGR2 + dw .MailRonaldsScoutGR3 + dw .MailRonaldsScoutGR4 + dw .MailRonaldsScoutMorino + dw .MailRonaldsScoutCatherine + dw .MailRonaldsScoutHidero + dw .MailRonaldsScoutKanoko + dw .MailRonaldsScoutKamiya + dw .MailRonaldsScoutMami + dw .MailRonaldsScoutColorlessAltar + dw .MailRonaldsScoutBiruritchi + dw .MailLinkDuel + +.MailEmpty + tx MailboxEmptySenderText + tx MailboxEmptySubjectText + end_mail + +.MailBlackBox + tx MailBlackBoxOutputSenderText + tx MailBlackBoxOutputSubjectText + tx MailBlackBoxOutputBody1Text + db $00, MAIL_COMMAND_GIVE_BLACK_BOX + tx MailBlackBoxOutputBody2Text + no_card + end_mail + +.MailBillsPCOutput + tx MailBillsPCOutputSenderText + tx MailBillsPCOutputSubjectText + tx MailBillsPCOutputBody1Text + db $00, MAIL_COMMAND_GIVE_BILLS_PC + tx MailBillsPCOutputBody2Text + no_card + end_mail + +.MailMailboxIntro + tx MailMailboxIntroSenderText + tx MailMailboxIntroSubjectText + tx MailMailboxIntroBody1Text + no_card + tx MailMailboxIntroBody2Text + no_card + tx MailMailboxIntroBody3Text + db BOOSTER_PRESENT_PACK_1, MAIL_COMMAND_GIVE_BOOSTER + end_mail + +.MailDeckDiagnosis1 + tx MailDeckDiagnosis1SenderText + tx MailDeckDiagnosis1SubjectText + tx MailDeckDiagnosis1Body1Text + no_card + tx MailDeckDiagnosis1Body2Text + no_card + tx MailDeckDiagnosis1Body3Text + no_card + tx MailDeckDiagnosis1Body4Text + no_card + end_mail + +.MailDeckDiagnosis2 + tx MailDeckDiagnosis2SenderText + tx MailDeckDiagnosis2SubjectText + tx MailDeckDiagnosis2Body1Text + no_card + tx MailDeckDiagnosis2Body2Text + no_card + tx MailDeckDiagnosis2Body3Text + no_card + tx MailDeckDiagnosis2Body4Text + no_card + end_mail + +.MailDeckDiagnosis3 + tx MailDeckDiagnosis3SenderText + tx MailDeckDiagnosis3SubjectText + tx MailDeckDiagnosis3Body1Text + no_card + tx MailDeckDiagnosis3Body2Text + no_card + tx MailDeckDiagnosis3Body3Text + no_card + end_mail + +.MailDeckDiagnosis4 + tx MailDeckDiagnosis4SenderText + tx MailDeckDiagnosis4SubjectText + tx MailDeckDiagnosis4Body1Text + no_card + tx MailDeckDiagnosis4Body2Text + no_card + end_mail + +.MailAutoDeckMachine1 + tx MailAutoDeckMachine1SenderText + tx MailAutoDeckMachine1SubjectText + tx MailAutoDeckMachine1Body1Text + no_card + tx MailAutoDeckMachine1Body2Text + no_card + tx MailAutoDeckMachine1Body3Text + db BOOSTER_BEGINNING_POKEMON, MAIL_COMMAND_GIVE_BOOSTER + end_mail + +.MailAutoDeckMachine2 + tx MailAutoDeckMachine2SenderText + tx MailAutoDeckMachine2SubjectText + tx MailAutoDeckMachine2Body1Text + no_card + tx MailAutoDeckMachine2Body2Text + db BOOSTER_LEGENDARY_POWER, MAIL_COMMAND_GIVE_BOOSTER + end_mail + +.MailAutoDeckMachine3 + tx MailAutoDeckMachine3SenderText + tx MailAutoDeckMachine3SubjectText + tx MailAutoDeckMachine3Body1Text + no_card + tx MailAutoDeckMachine3Body2Text + no_card + tx MailAutoDeckMachine3Body3Text + db BOOSTER_ISLAND_OF_FOSSIL, MAIL_COMMAND_GIVE_BOOSTER + end_mail + +.MailAutoDeckMachine4 + tx MailAutoDeckMachine4SenderText + tx MailAutoDeckMachine4SubjectText + tx MailAutoDeckMachine4Body1Text + no_card + tx MailAutoDeckMachine4Body2Text + no_card + tx MailAutoDeckMachine4Body3Text + db BOOSTER_SKY_FLYING_POKEMON, MAIL_COMMAND_GIVE_BOOSTER + end_mail + +.MailAutoDeckMachine5 + tx MailAutoDeckMachine5SenderText + tx MailAutoDeckMachine5SubjectText + tx MailAutoDeckMachine5Body1Text + no_card + tx MailAutoDeckMachine5Body2Text + no_card + tx MailAutoDeckMachine5Body3Text + no_card + end_mail + +.MailChallengeMachine + tx MailChallengeMachineSenderText + tx MailChallengeMachineSubjectText + tx MailChallengeMachineBody1Text + no_card + tx MailChallengeMachineBody2Text + no_card + end_mail + +.MailGRChallengeMachine + tx MailGRChallengeMachineSenderText + tx MailGRChallengeMachineSubjectText + tx MailGRChallengeMachineBody1Text + no_card + tx MailGRChallengeMachineBody2Text + no_card + tx MailGRChallengeMachineBody3Text + no_card + end_mail + +.MailGrandMasterCup + tx MailGrandMasterCupSenderText + tx MailGrandMasterCupSubjectText + tx MailGrandMasterCupBody1Text + no_card + tx MailGrandMasterCupBody2Text + no_card + end_mail + +.MailRonaldsScoutGR1 + tx MailRonaldsScoutGR1SenderText + tx MailRonaldsScoutGR1SubjectText + tx MailRonaldsScoutGR1Body1Text + no_card + tx MailRonaldsScoutGR1Body2Text + no_card + end_mail + +.MailRonaldsScoutGR2 + tx MailRonaldsScoutGR2SenderText + tx MailRonaldsScoutGR2SubjectText + tx MailRonaldsScoutGR2Body1Text + no_card + tx MailRonaldsScoutGR2Body2Text + no_card + end_mail + +.MailRonaldsScoutGR3 + tx MailRonaldsScoutGR3SenderText + tx MailRonaldsScoutGR3SubjectText + tx MailRonaldsScoutGR3Body1Text + no_card + tx MailRonaldsScoutGR3Body2Text + no_card + end_mail + +.MailRonaldsScoutGR4 + tx MailRonaldsScoutGR4SenderText + tx MailRonaldsScoutGR4SubjectText + tx MailRonaldsScoutGR4Body1Text + no_card + tx MailRonaldsScoutGR4Body2Text + no_card + end_mail + +.MailRonaldsScoutMorino + tx MailRonaldsScoutMorinoSenderText + tx MailRonaldsScoutMorinoSubjectText + tx MailRonaldsScoutMorinoBody1Text + no_card + tx MailRonaldsScoutMorinoBody2Text + no_card + tx MailRonaldsScoutMorinoBody3Text + no_card + tx MailRonaldsScoutMorinoBody4Text + no_card + end_mail + +.MailRonaldsScoutCatherine + tx MailRonaldsScoutCatherineSenderText + tx MailRonaldsScoutCatherineSubjectText + tx MailRonaldsScoutCatherineBody1Text + no_card + tx MailRonaldsScoutCatherineBody2Text + no_card + tx MailRonaldsScoutCatherineBody3Text + no_card + end_mail + +.MailRonaldsScoutHidero + tx MailRonaldsScoutHideroSenderText + tx MailRonaldsScoutHideroSubjectText + tx MailRonaldsScoutHideroBody1Text + no_card + tx MailRonaldsScoutHideroBody2Text + no_card + tx MailRonaldsScoutHideroBody3Text + no_card + end_mail + +.MailRonaldsScoutKanoko + tx MailRonaldsScoutKanokoSenderText + tx MailRonaldsScoutKanokoSubjectText + tx MailRonaldsScoutKanokoBody1Text + no_card + tx MailRonaldsScoutKanokoBody2Text + no_card + tx MailRonaldsScoutKanokoBody3Text + no_card + end_mail + +.MailRonaldsScoutKamiya + tx MailRonaldsScoutKamiyaSenderText + tx MailRonaldsScoutKamiyaSubjectText + tx MailRonaldsScoutKamiyaBody1Text + no_card + tx MailRonaldsScoutKamiyaBody2Text + no_card + tx MailRonaldsScoutKamiyaBody3Text + no_card + end_mail + +.MailRonaldsScoutMami + tx MailRonaldsScoutMamiSenderText + tx MailRonaldsScoutMamiSubjectText + tx MailRonaldsScoutMamiBody1Text + no_card + tx MailRonaldsScoutMamiBody2Text + no_card + tx MailRonaldsScoutMamiBody3Text + no_card + tx MailRonaldsScoutMamiBody4Text + no_card + tx MailRonaldsScoutMamiBody5Text + no_card + end_mail + +.MailRonaldsScoutColorlessAltar + tx MailRonaldsScoutColorlessAltarSenderText + tx MailRonaldsScoutColorlessAltarSubjectText + tx MailRonaldsScoutColorlessAltarBody1Text + no_card + tx MailRonaldsScoutColorlessAltarBody2Text + no_card + tx MailRonaldsScoutColorlessAltarBody3Text + no_card + tx MailRonaldsScoutColorlessAltarBody4Text + no_card + end_mail + +.MailRonaldsScoutBiruritchi + tx MailRonaldsScoutBiruritchiSenderText + tx MailRonaldsScoutBiruritchiSubjectText + tx MailRonaldsScoutBiruritchiBody1Text + no_card + tx MailRonaldsScoutBiruritchiBody2Text + no_card + tx MailRonaldsScoutBiruritchiBody3Text + no_card + tx MailRonaldsScoutBiruritchiBody4Text + no_card + tx MailRonaldsScoutBiruritchiBody5Text + no_card + end_mail + +.MailLinkDuel + tx MailLinkDuelSenderText + tx MailLinkDuelSubjectText + tx MailLinkDuelBody1Text + no_card + tx MailLinkDuelBody2Text + no_card + end_mail diff --git a/src/engine/bank02.asm b/src/engine/bank02.asm index 8092a87..cfa3139 100644 --- a/src/engine/bank02.asm +++ b/src/engine/bank02.asm @@ -132,9 +132,9 @@ SECTION "Bank 2@47d3", ROMX[$47d3], BANK[$2] Func_87d3: xor a ld [wMenuInputSFX], a - ld a, [wd0ef] + ld a, [wCheckMenuCursorXPosition] ld d, a - ld a, [wd0ef + 1] + ld a, [wCheckMenuCursorYPosition] ld e, a ldh a, [hDPadHeld] or a @@ -205,9 +205,9 @@ Func_87d3: call .asm_8884 pop de ld a, d - ld [wd0ef], a + ld [wCheckMenuCursorXPosition], a ld a, e - ld [wd0ef + 1], a + ld [wCheckMenuCursorYPosition], a xor a ld [wScrollMenuCursorBlinkCounter], a .asm_8852 @@ -246,13 +246,13 @@ Func_87d3: ld e, a ld a, $0a ld l, a - ld a, [wd0ef] + ld a, [wCheckMenuCursorXPosition] ld h, a call HtimesL ld a, l add $01 ld b, a - ld a, [wd0ef + 1] + ld a, [wCheckMenuCursorYPosition] sla a add $0e ld c, a @@ -533,7 +533,7 @@ Func_8f10: ld [hli], a ld [hli], a ld [hl], a - ld [s0b7a1], a + ld [sUnnamedDeckCounter], a call DisableSRAM ; fallthrough @@ -571,21 +571,62 @@ PrepareMenuGraphics: call SetupText ret -Func_8f6b: +; inits the following deck building params from hl: +; wMaxNumCardsAllowed +; wd381 +; wSameNameCardsLimit +; wIncludeCardsInDeck +; wDeckConfigurationMenuHandlerFunction +; wDeckConfigurationMenuTransitionTable +InitDeckBuildingParams: ld de, wMaxNumCardsAllowed - ld b, $08 -.asm_8f70 + ld b, 8 +.loop ld a, [hli] ld [de], a inc de dec b - jr nz, .asm_8f70 + jr nz, .loop ret -; 0x8f77 -SECTION "Bank 2@4fb9", ROMX[$4fb9], BANK[$2] +DeckBuildingParams: + db DECK_CONFIG_BUFFER_SIZE + db DECK_SIZE + db MAX_NUM_SAME_NAME_CARDS + db TRUE ; whether to include deck cards + dw HandleDeckConfigurationMenu + dw DeckConfigurationMenu_TransitionTable -Func_8fb9: +DeckSelectionMenu: + ld hl, DeckBuildingParams + call InitDeckBuildingParams + ld a, $ff + call DrawDecksScreen + xor a + +.init_menu_params + ld hl, .MenuParameters + call InitializeMenuParameters + ldtx hl, PleaseSelectDeckText + call DrawWideTextBox_PrintText +.loop_input + call DoFrame + jr c, .init_menu_params + call HandleStartButtonInDeckSelectionMenu + jr c, .init_menu_params + call HandleMenuInput + jr nc, .loop_input + ldh a, [hCurScrollMenuItem] + cp $ff + ret z ; B btn returns +; A btn pressed on a deck + ld [wCurDeck], a + jp DeckSelectionSubMenu + +.MenuParameters: + menu_parameters 1, 2, 3, NUM_DECKS, SYM_CURSOR_R, SYM_SPACE, NULL + +HandleStartButtonInDeckSelectionMenu: ldh a, [hDPadHeld] and PAD_START ret z @@ -595,7 +636,7 @@ Func_8fb9: jp nc, .valid_deck ; can be jr ld a, MENU_CANCEL call PlayConfirmOrCancelSFX - call Func_9215 + call PrintThereIsNoDeckHereText scf ret @@ -607,8 +648,8 @@ Func_8fb9: call GetSRAMPointerToCurDeck pop de call OpenDeckConfirmationMenu - ld a, $ff ; all decks - call DrawDeckSelectionMenu + ld a, ALL_DECKS + call DrawDecksScreen ld a, [wCurDeck] scf ret @@ -636,9 +677,266 @@ OpenDeckConfirmationMenu: ret ; 0x9014 -SECTION "Bank 2@5215", ROMX[$5215], BANK[$2] +SECTION "Bank 2@503f", ROMX[$503f], BANK[$2] -Func_9215: +; a - selected deck +; handles the submenu when selecting a deck +; (Modify Deck, Select Deck, Change Name and Cancel) +DeckSelectionSubMenu: + call DrawWideTextBox + ld hl, DeckSelectScreenTextItems + call PlaceTextItems + call ResetCheckMenuCursorPositionAndBlink +.loop_input: + call DoFrame + call HandleCheckMenuInput + jp nc, .loop_input + cp $ff + jr nz, .option_selected +; B btn pressed +; erase cursor and go back +; to deck selection handling + call EraseCheckMenuCursor + ld a, [wCurDeck] + jp DeckSelectionMenu.init_menu_params + +.option_selected + ld a, [wCheckMenuCursorXPosition] + or a + jp nz, DeckSelectionSubMenu_SelectOrCancel + ld a, [wCheckMenuCursorYPosition] + or a + jp nz, .ChangeName + + call GetSRAMPointerToCurDeckCards + ld e, l + ld d, h + ld hl, wCurDeckCards + call CopyDeckFromSRAM + ld de, wCurDeckName + call GetSRAMPointerToCurDeck + call CopyListFromHLToDEInSRAM + xor a + ld [wd121], a + + call HandleDeckBuildScreen + jr nc, .asm_90cd + call EnableSRAM + ld hl, wCurDeckCards + call DecrementDeckCardsInCollection + call GetSRAMPointerToCurDeckCards + call AddDeckToCollection + ld de, wCurDeckCards + bank1call SaveDeckCards + call GetSRAMPointerToCurDeck + ld d, h + ld e, l + ld hl, wCurDeckName + call CopyListFromHLToDE + call GetSRAMPointerToCurDeck + ld a, [hl] + call DisableSRAM + or a + jr z, .get_input_deck_name + ld a, [hffbf] + or a + jr z, .asm_90cd + call EnableSRAM + ld de, wCurDeckCards + farcall SaveDeckDataToWRAM2 + call DisableSRAM + farcall OpenDeckSaveMachineFromDeckBuilding +.asm_90cd + ld a, ALL_DECKS + call DrawDecksScreen + ld a, [wCurDeck] + jp DeckSelectionMenu.init_menu_params + +.ChangeName + xor a + ld [hffbf], a + call CheckIfCurDeckIsEmpty + jp nc, .get_input_deck_name + call PrintThereIsNoDeckHereText + jp DeckSelectionMenu.init_menu_params + +.get_input_deck_name + ld de, wCurDeckName + call GetSRAMPointerToCurDeck + call CopyListFromHLToDEInSRAM + call InputCurDeckName + call GetSRAMPointerToCurDeck + ld d, h + ld e, l + ld hl, wCurDeckName + call CopyListFromHLToDEInSRAM + ld a, [hffbf] + or a + jr z, .asm_9119 + call EnableSRAM + ld hl, wCurDeckName + ld de, wCurDeckCards + farcall SaveDeckDataToWRAM2 + call DisableSRAM + farcall OpenDeckSaveMachineFromDeckBuilding +.asm_9119 + ld a, ALL_DECKS + call DrawDecksScreen + ld a, [wCurDeck] + jp DeckSelectionMenu.init_menu_params + +InputCurDeckName: + ld a, [wCurDeck] + or a + jr nz, .try_deck_2 + ld hl, Deck1RenameText + jr .got_deck_ptr +.try_deck_2 + dec a + jr nz, .try_deck_3 + ld hl, Deck2RenameText + jr .got_deck_ptr +.try_deck_3 + dec a + jr nz, .try_deck_4 + ld hl, Deck3RenameText + jr .got_deck_ptr +.try_deck_4 + dec a + jr nz, .deck_5 + ld hl, Deck4RenameText + jr .got_deck_ptr +.deck_5 + ld hl, Deck5RenameText +.got_deck_ptr + ld a, DECK_NAME_SIZE_WO_SUFFIX + lb bc, 4, 1 + ld de, wCurDeckName + farcall InputName + ld a, [wCurDeckName] + or a + ret nz + call .UnnamedDeck + ret + +; handles the naming of unnamed decks +; inputs as the deck name " no XXX" +; where XXX is the current unnamed deck counter +.UnnamedDeck + ld hl, sUnnamedDeckCounter + call EnableSRAM + ld e, [hl] + inc hl + ld d, [hl] + push de + ld de, wCurDeckName + call CopyPlayerName + ld h, d + ld l, e + pop de + + ld [hl], TX_HIRAGANA + inc hl + ldfw [hl], "の" + inc hl + + push hl + ld h, d + ld l, e + call UnnamedDeckCounterToText + call DisableSRAM + pop hl + + ld a, [wTempUnnamedDeckCounter] + ld [hl], TX_SYMBOL + inc hl + ld [hli], a + ld a, [wTempUnnamedDeckCounter + 1] + ld [hl], TX_SYMBOL + inc hl + ld [hli], a + ld a, [wTempUnnamedDeckCounter + 2] + ld [hl], TX_SYMBOL + inc hl + ld [hli], a + xor a + ld [hl], a + +; increment the unnamed deck counter + ld hl, sUnnamedDeckCounter + call EnableSRAM + ld e, [hl] + inc hl + ld d, [hl] +; capped at 999 + ld a, HIGH(MAX_UNNAMED_DECK_NUM) + cp d + jr nz, .incr_counter + ld a, LOW(MAX_UNNAMED_DECK_NUM) + cp e + jr nz, .incr_counter + ; reset counter + ld de, 0 +.incr_counter + inc de + ld [hl], d + dec hl + ld [hl], e + call DisableSRAM + ret + +; handle deck selection sub-menu +; the option is either "Select Deck" or "Cancel" +; depending on the cursor Y pos +DeckSelectionSubMenu_SelectOrCancel: + ld a, [wCheckMenuCursorYPosition] + or a + jp nz, CancelDeckSelectionSubMenu + + call CheckIfCurDeckIsEmpty + jp nc, .SelectDeck + ; invalid deck + call PrintThereIsNoDeckHereText + jp DeckSelectionMenu.init_menu_params + +.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, $03 + ld l, a + call HtimesL + ld e, l + inc e + ld d, 2 + xor a + lb hl, 0, 0 + lb bc, 2, 2 + call FillRectangle + +; 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 DrawHandCardsTileOnCurDeck + call GetSRAMPointerToCurDeck + call EnableSRAM + call CopyDeckName + call DisableSRAM + xor a + ld [wTxRam2], a + ld [wTxRam2 + 1], a + ldtx hl, ChosenAsDuelingDeckText + call DrawWideTextBox_WaitForInput + ld a, [wCurDeck] + jp DeckSelectionMenu.init_menu_params + +PrintThereIsNoDeckHereText: ldtx hl, ThereIsNoDeckHereText call DrawWideTextBox_WaitForInput ld a, [wCurDeck] @@ -656,9 +954,43 @@ CheckIfCurDeckIsEmpty: ret nz scf ret -; 0x922e -SECTION "Bank 2@5265", ROMX[$5265], BANK[$2] +; convert the number at hl to text (ascii) format and write it to wTempUnnamedDeckCounter +UnnamedDeckCounterToText: + ld de, wTempUnnamedDeckCounter + ld bc, -100 + call .get_digit + ld bc, -10 + call .get_digit + ld bc, -1 + call .get_digit + ret + +.get_digit + ld a, SYM_0 - 1 +.subtract_loop + inc a + add hl, bc + jr c, .subtract_loop + ld [de], a + inc de + ld a, l + sub c + ld l, a + ld a, h + sbc b + ld h, a + ret + +CancelDeckSelectionSubMenu: + ret + +DeckSelectScreenTextItems: + textitem 2, 14, ModifyDeckText + textitem 12, 14, ChooseAsDuelingDeckText + textitem 2, 16, RenameDeckText + textitem 12, 16, CancelDeckText + db $ff GetSRAMPointerToCurDeck: ld a, [wCurDeck] @@ -684,106 +1016,122 @@ GetSRAMPointerToCurDeckCards: pop af ret -Func_9287: +ResetCheckMenuCursorPositionAndBlink: xor a - ld [wd0ef], a - ld [wd0ef + 1], a + ld [wCheckMenuCursorXPosition], a + ld [wCheckMenuCursorYPosition], a ld [wScrollMenuCursorBlinkCounter], a ret -Func_9292: +; handle player input in check menu +; works out which cursor coordinate to go to +; and sets carry flag if A or B are pressed +; returns a = $1 if A pressed +; returns a = $ff if B pressed +HandleCheckMenuInput: xor a ld [wMenuInputSFX], a - ld a, [wd0ef] + ld a, [wCheckMenuCursorXPosition] ld d, a - ld a, [wd0ef + 1] + ld a, [wCheckMenuCursorYPosition] ld e, a ldh a, [hDPadHeld] or a - jr z, .asm_92d3 + jr z, .no_pad bit B_PAD_LEFT, a - jr nz, .asm_92ab + jr nz, .horizontal bit B_PAD_RIGHT, a - jr z, .asm_92b1 -.asm_92ab + jr z, .check_vertical +.horizontal ld a, d - xor $01 + xor $01; flips x coordinate ld d, a - jr .asm_92bd -.asm_92b1 - bit 6, a - jr nz, .asm_92b9 - bit 7, a - jr z, .asm_92d3 -.asm_92b9 + jr .okay +.check_vertical + bit B_PAD_UP, a + jr nz, .vertical + bit B_PAD_DOWN, a + jr z, .no_pad +.vertical ld a, e - xor $01 + xor $01 ; flips y coordinate ld e, a -.asm_92bd +.okay ld a, SFX_CURSOR ld [wMenuInputSFX], a push de - call .asm_9305 + call EraseCheckMenuCursor pop de ld a, d - ld [wd0ef], a + ld [wCheckMenuCursorXPosition], a ld a, e - ld [wd0ef + 1], a + ld [wCheckMenuCursorYPosition], a xor a ld [wScrollMenuCursorBlinkCounter], a -.asm_92d3 +.no_pad ldh a, [hKeysPressed] and PAD_A | PAD_B - jr z, .asm_92ee + jr z, .no_input and PAD_A - jr nz, .asm_92e4 + jr nz, .a_press ld a, MENU_CANCEL call PlayConfirmOrCancelSFX scf ret -.asm_92e4 - call .asm_9324 + +.a_press + call DisplayCheckMenuCursor ld a, MENU_CONFIRM call PlayConfirmOrCancelSFX scf ret -.asm_92ee +.no_input ld a, [wMenuInputSFX] or a - jr z, .asm_92f7 + jr z, .check_blink call PlaySFX -.asm_92f7 + +.check_blink ld hl, wScrollMenuCursorBlinkCounter ld a, [hl] inc [hl] - and $0f - ret nz - ld a, $0f - bit 4, [hl] - jr z, .asm_9307 -.asm_9305 - ld a, $00 -.asm_9307 + and %00001111 + ret nz ; only update cursor if blink's lower nibble is 0 + + ld a, SYM_CURSOR_R + bit 4, [hl] ; only draw cursor if blink counter's fourth bit is not set + jr z, DrawCheckMenuCursor + +; draws in the cursor position +EraseCheckMenuCursor: + ld a, SYM_SPACE +; fallthrough + +; draws in the cursor position +; input: +; a = tile byte to draw +DrawCheckMenuCursor: ld e, a - ld a, $0a + ld a, 10 ld l, a - ld a, [wd0ef] + ld a, [wCheckMenuCursorXPosition] ld h, a call HtimesL ld a, l - add $01 + add 1 ld b, a - ld a, [wd0ef + 1] + ld a, [wCheckMenuCursorYPosition] sla a - add $0e + add 14 ld c, a ld a, e call WriteByteToBGMap0 or a ret -.asm_9324: - ld a, $0f - jr .asm_9307 + +DisplayCheckMenuCursor: + ld a, SYM_CURSOR_R + jr DrawCheckMenuCursor ; if a = MENU_CANCEL (-1), play SFX_CANCEL (usually following B button) ; else SFX_CONFIRM (usually following A button) @@ -809,13 +1157,19 @@ Func_9337: call CopyDeckFromSRAM call EnableSRAM ld hl, wTempSavedDeckCards +; fallthrough + +; goes through whole deck in hl +; for each card ID, goes to its corresponding +; entry in sCardCollection and decrements its count +_DecrementDeckCardsInCollection: ld b, DECK_SIZE -.asm_9348 +.loop ld e, [hl] inc hl ld d, [hl] call CheckIfCardIDIsZero - jr c, .asm_935b + jr c, .done inc hl push hl ld hl, sCardCollection @@ -823,15 +1177,26 @@ Func_9337: dec [hl] pop hl dec b - jr nz, .asm_9348 -.asm_935b + jr nz, .loop +.done pop hl ret ; 0x935d +; goes through whole deck in hl +; for each card ID, goes to its corresponding +; entry in sCardCollection and decrements its count +DecrementDeckCardsInCollection: + push hl + jr _DecrementDeckCardsInCollection +; 0x9360 + SECTION "Bank 2@5397", ROMX[$5397], BANK[$2] -Func_9397: +; adds all cards in deck in hl to player's collection +; Enables SRAM (contrary to this function in poketcg1) +; hl = pointer to deck cards +AddDeckToCollection: push hl ld d, h ld e, l @@ -840,12 +1205,12 @@ Func_9397: call EnableSRAM ld hl, wTempSavedDeckCards ld b, DECK_SIZE -.asm_93a8 +.loop_deck ld e, [hl] inc hl ld d, [hl] call CheckIfCardIDIsZero - jr c, .asm_93bb + jr c, .done inc hl push hl ld hl, sCardCollection @@ -853,12 +1218,15 @@ Func_9397: inc [hl] pop hl dec b - jr nz, .asm_93a8 -.asm_93bb + jr nz, .loop_deck +.done pop hl ret -DrawDeckSelectionMenu: +; draws the screen which shows the player's current +; deck configurations +; a = DECK_* flags to pick which deck names to show +DrawDecksScreen: ld [hffbf], a call EmptyScreenAndLoadFontDuelAndHandCardsIcons @@ -1187,89 +1555,106 @@ DrawHandCardsTileAtDE: call FillRectangle ret -Func_95d6: +HandleDeckBuildScreen: xor a ld [hffbf], a call WriteCardListsTerminatorBytes - call Func_9aaa - call Func_9a6d + call CountNumberOfCardsForEachCardType +.skip_count + call DrawCardTypeIconsAndPrintCardCounts + xor a ld [wScrollMenuScrollOffset], a - ld [wCurCardTypeFilter], a - call Func_9d41 + ld [wCurCardTypeFilter], a ; FILTER_GRASS + call PrintFilteredCardList + +.skip_draw ld hl, FiltersCardSelectionParams call InitializeScrollMenuParameters -.asm_95f3 +.wait_input call DoFrame ldh a, [hDPadHeld] and PAD_START - jr z, .asm_960c + jr z, .no_start_btn_1 ld a, MENU_CONFIRM call PlayConfirmOrCancelSFX - call Func_9787 + call ConfirmDeckConfiguration ld a, [wCurCardTypeFilter] ld [wTempCardTypeFilter], a - jr .asm_95f3 -.asm_960c + jr .wait_input + +.no_start_btn_1 ld a, [wCurCardTypeFilter] ld b, a ld a, [wTempCardTypeFilter] cp b - jr z, .asm_9626 + jr z, .check_down_btn + ; need to refresh the filtered card list ld [wCurCardTypeFilter], a ld hl, wScrollMenuScrollOffset - ld [hl], $00 - call Func_9d41 - ld a, $09 + ld [hl], 0 + call PrintFilteredCardList + ld a, NUM_FILTERS ld [wNumMenuItems], a -.asm_9626 + +.check_down_btn ldh a, [hDPadHeld] and PAD_DOWN - jr z, .asm_9631 + jr z, .no_down_btn call ConfirmSelectionAndReturnCarry - jr .asm_963e -.asm_9631 + jr .jump_to_list + +.no_down_btn call HandleCardSelectionInput - jr nc, .asm_95f3 + jr nc, .wait_input ld a, [hCurMenuItem] cp $ff - jp z, Func_9712 -.asm_963e + jp z, OpenDeckConfigurationMenu + +.jump_to_list ld a, [wNumEntriesInCurFilter] or a - jr z, .asm_95f3 + jr z, .wait_input xor a -.asm_9645 +.wait_list_input ld hl, $5a3a call InitializeScrollMenuParameters ld a, [wNumEntriesInCurFilter] ld [wNumCardListEntries], a ld hl, wNumVisibleCardListEntries cp [hl] - jr nc, .asm_965a + 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 [wNumMenuItems], a -.asm_965a - ld hl, Func_9dbf +.ok + ld hl, PrintDeckBuildingCardList ld d, h ld a, l ld hl, wScrollMenuScrollFunc ld [hli], a ld [hl], d + ld a, $01 ld [wd119], a -.asm_9669 +.loop_input call DoFrame ldh a, [hDPadHeld] and PAD_START - jr z, .asm_9685 + jr z, .no_start_btn_2 ld a, MENU_CONFIRM call PlayConfirmOrCancelSFX + + ; temporarily store current cursor position + ; to retrieve it later ld a, [wTempCardTypeFilter] - ld [wd11c], a - call Func_9787 - ld a, [wd11c] - jr .asm_9645 -.asm_9685 + ld [wTempFilteredCardListNumCursorPositions], a + call ConfirmDeckConfiguration + ld a, [wTempFilteredCardListNumCursorPositions] + jr .wait_list_input + +.no_start_btn_2 ldh a, [hDPadHeld] and PAD_UP jr z, .asm_96a0 @@ -1282,12 +1667,14 @@ Func_95d6: ld a, MENU_CANCEL call PlayConfirmOrCancelSFX jr .asm_96f3 + .asm_96a0 call HandleSelectUpAndDownInList - jr c, .asm_9669 + jr c, .loop_input call HandleScrollListInput jr c, .asm_96f3 - jr .asm_9669 + jr .loop_input + .asm_96ac ld a, MENU_CONFIRM call PlayConfirmOrCancelSFX @@ -1301,20 +1688,22 @@ Func_95d6: inc hl ld [hl], d call OpenCardPageFromCardList - call Func_9a6d + call DrawCardTypeIconsAndPrintCardCounts + ld hl, FiltersCardSelectionParams call InitializeScrollMenuParameters ld a, [wCurCardTypeFilter] ld [wTempCardTypeFilter], a call DrawHorizontalListCursor_Visible - call Func_9dbf + call PrintDeckBuildingCardList ld hl, $5a3a call InitializeScrollMenuParameters ld a, [wTempScrollMenuNumVisibleItems] ld [wNumMenuItems], a ld a, [wTempCurMenuItem] ld [wTempCardTypeFilter], a - jp .asm_9669 + jp .loop_input + .asm_96f3 call DrawListCursor_Invisible ld a, [wTempCardTypeFilter] @@ -1326,12 +1715,12 @@ Func_95d6: call InitializeScrollMenuParameters ld a, [wCurCardTypeFilter] ld [wTempCardTypeFilter], a - jp .asm_95f3 + jp .wait_input -Func_9712: +OpenDeckConfigurationMenu: xor a ld [wd0c1], a - ld de, wd386 + ld de, wDeckConfigurationMenuTransitionTable ld hl, wTransitionTablePtr ld a, [de] ld [hli], a @@ -1340,62 +1729,440 @@ Func_9712: ld [hl], a ld a, $ff ld [wd0c4], a + +.skip_init xor a ld [wScrollMenuCursorBlinkCounter], a - ld hl, wd384 + ld hl, wDeckConfigurationMenuHandlerFunction ld a, [hli] ld h, [hl] ld l, a jp hl -; 0x9731 -SECTION "Bank 2@5787", ROMX[$5787], BANK[$2] +HandleDeckConfigurationMenu: + call Func_98eb + lb de, 0, 0 + lb bc, 20, 6 + call DrawRegularTextBox + ld hl, DeckBuildMenuTextItems + call PlaceTextItems -Func_9787: +.do_frame + ld a, $01 + ld [wVBlankOAMCopyToggle], a + call DoFrame + call HandleMultiDirectionalMenu + jr nc, .do_frame + ld [wde84], a + cp $ff + jr nz, .asm_9769 +.draw_icons + call DrawCardTypeIconsAndPrintCardCounts + ld a, [wTempCurMenuItem] + ld [wTempCardTypeFilter], a + ld a, [wCurCardTypeFilter] + call PrintFilteredCardList + jp HandleDeckBuildScreen.skip_draw + +.asm_9769 + push af + call HandleMultiDirectionalMenu.DrawCursor + ld a, $01 + ld [wVBlankOAMCopyToggle], a + pop af + ld hl, .function_table + call JumpToFunctionInTable + jr OpenDeckConfigurationMenu.skip_init + +.function_table: + dw ConfirmDeckConfiguration + dw ModifyDeckConfiguration + dw ChangeDeckName + dw SaveDeckConfiguration + dw DismantleDeck + dw CancelDeckModifications + +ConfirmDeckConfiguration: ld hl, wScrollMenuScrollOffset ld a, [hl] - ld hl, wd11f + ld hl, wCardListVisibleOffsetBackup ld [hl], a call HandleDeckConfirmationMenu - ld hl, wd11f + ld hl, wCardListVisibleOffsetBackup ld a, [hl] ld hl, wScrollMenuScrollOffset ld [hl], a - call Func_9a6d + call DrawCardTypeIconsAndPrintCardCounts ld hl, FiltersCardSelectionParams call InitializeScrollMenuParameters ld a, [wCurCardTypeFilter] ld [wTempCardTypeFilter], a call DrawHorizontalListCursor_Visible ld a, [wCurCardTypeFilter] - call Func_9d41 + call PrintFilteredCardList ld a, [wde84] ld [wTempCardTypeFilter], a ret -; 0x97b9 -SECTION "Bank 2@5a0f", ROMX[$5a0f], BANK[$2] +ModifyDeckConfiguration: + add sp, $02 + jr HandleDeckConfigurationMenu.draw_icons -Func_9a0f: +; returns carry set if player chose to go back +CancelDeckModifications: +; if deck was not changed, cancel modification immediately + call CheckIfCurrentDeckWasChanged + jr nc, .cancel_modification + ldtx hl, DeckBuildingQuitPromptText + call YesOrNoMenuWithText + jr c, SaveDeckConfiguration.go_back +.cancel_modification + add sp, $02 + or a + ret + +SaveDeckConfiguration: +; handle deck configuration size + ld a, [wTotalCardCount] + cp DECK_SIZE + jp z, .ask_to_save_deck + ldtx hl, DeckBuildingWarningNot60CardsText + call DrawWideTextBox_WaitForInput + ldtx hl, DeckBuildingRevertPromptText + call YesOrNoMenuWithText + jr c, .print_deck_size_warning +; return no carry + add sp, $02 + or a + ret + +.print_deck_size_warning + ldtx hl, DeckBuildingWarningMustInclude60CardsText + call DrawWideTextBox_WaitForInput + jr .go_back + +.ask_to_save_deck + ldtx hl, DeckBuildingSavePromptText + call YesOrNoMenuWithText + jr c, .go_back + call CheckIfThereAreAnyBasicCardsInDeck + jr c, .ask_to_save_to_deck_machine + ldtx hl, DeckBuildingWarningNoBasicPokemonText + call DrawWideTextBox_WaitForInput + ldtx hl, DeckBuildingWarningMustIncludeBasicPokemonText + call DrawWideTextBox_WaitForInput + +.go_back + call DrawCardTypeIconsAndPrintCardCounts + call PrintDeckBuildingCardList + ld a, [wde84] + ld [wCardListCursorPos], a + ret + +.ask_to_save_to_deck_machine + ldtx hl, DeckBuildingSaveToMachinePromptText + call YesOrNoMenuWithText + jr c, .set_carry + ld a, $01 + ld [hffbf], a + +.set_carry + add sp, $02 + scf + ret + +DismantleDeck: + ldtx hl, DeckBuildingDismantlePromptText + call YesOrNoMenuWithText + jr c, SaveDeckConfiguration.go_back + call CheckIfHasOtherValidDecks + jp nc, .Dismantle + ldtx hl, DeckBuildingWarningTheOnlyDeckNotDismantleableText + call DrawWideTextBox_WaitForInput + call EmptyScreen + ld hl, FiltersCardSelectionParams + call InitializeScrollMenuParameters + ld a, [wCurCardTypeFilter] + ld [wCardListCursorPos], a + call DrawHorizontalListCursor_Visible + call PrintDeckBuildingCardList + call EnableLCD + ld a, [wde84] + ld [wCardListCursorPos], a + ret + +.Dismantle + call EnableSRAM + call GetSRAMPointerToCurDeck + ld a, [hl] + or a + jr z, .asm_9871 + push hl + call GetSRAMPointerToCurDeckCards + call AddDeckToCollection + pop hl + ld a, $60 + call ClearNBytesFromHL + +.asm_9871 + ldtx hl, DeckBuildingRevertAndSaveToMachinePromptText + call YesOrNoMenuWithText + jr c, .asm_989d + ld a, [wCurDeckName] + or a + jr z, .asm_98a0 + ld a, [wTotalCardCount] + cp DECK_SIZE + jp nz, .asm_98a0 + call CheckIfThereAreAnyBasicCardsInDeck + jr nc, .asm_98a0 + ld hl, wCurDeckName + ld de, wCurDeckCards + farcall SaveDeckDataToWRAM2 + call DisableSRAM + farcall OpenDeckSaveMachineFromDeckBuilding +.asm_989d + add sp, $02 + ret +.asm_98a0 + ldtx hl, DeckBuildingWarningIncompleteCannotSaveToMachineText + call DrawWideTextBox_WaitForInput + jr .asm_989d + +ChangeDeckName: + call InputCurDeckName + add sp, $02 + jp HandleDeckBuildScreen.skip_count + +; de - coordinates +Func_98b0: + push de + push hl + ld hl, .Data_98e8 + ld de, wDefaultText + call CopyListFromHLToDE + pop hl + call CopyListFromHLToDEInSRAM + ld hl, wDefaultText + call GetTextLengthInTiles + ld b, $00 + ld hl, wDefaultText + add hl, bc + ld d, h + ld e, l + ld hl, .DeckNameSuffix + call CopyListFromHLToDE + pop de + ld hl, wDefaultText + call InitTextPrinting + call ProcessText + or a + ret + +.DeckNameSuffix + katakana "デ" + katakana "ッ" + katakana "キ" + katakana " " + done + +.Data_98e8: + katakana " " + done + +Func_98eb: + lb de, 0, 6 + lb bc, 20, 12 + call DrawRegularTextBox + ld hl, wCurDeckName + ld a, [hl] + or a + jr z, .asm_9910 + lb de, 1, 6 + call Func_98b0 + ld hl, wCurDeckName + call GetTextLengthInTiles + ld a, 5 + add b + lb de, 1, 6 + call ZeroAttributesAtDE +.asm_9910 ld hl, wCurDeckCards -.asm_9a12 + farcall CheckDeck.asm_25461 + lb de, 2, 8 + call InitTextPrinting + ldtx hl, DeckDiagnosisBreakdownText + call ProcessTextFromID + ld a, [wDeckCheckEnergyCount] + ld de, $f08 + call Func_9951 + ld a, [wDeckCheckBasicCount] + ld de, $f0a + call Func_9951 + ld a, [wDeckCheckStage1Count] + ld de, $f0c + call Func_9951 + ld a, [wDeckCheckStage2Count] + ld de, $f0e + call Func_9951 + ld a, [wDeckCheckTrainerCount] + ld de, $f10 + call Func_9951 + ret + +Func_9951: + push de + ld hl, wDefaultText + call ConvertToNumericalDigits + ld [hl], $00 + pop de + call InitTextPrinting + ld hl, wDefaultText + call ProcessText + ret + +; returns carry if current deck was changed +; either through its card configuration or its name +CheckIfCurrentDeckWasChanged: + ld a, [wTotalCardCount] + or a + jr z, .skip_size_check + cp DECK_SIZE + jr nz, .set_carry + +.skip_size_check + call GetSRAMPointerToCurDeckCards + ld d, h + ld e, l + ld hl, wc000 + call EnableSRAM + bank1call DecompressSRAMDeck + call DisableSRAM + ld a, $ff + ld [$c078], a + ld [$c079], a + ld hl, wCurDeckCards +.asm_998b ld e, [hl] inc hl ld d, [hl] inc hl call CheckIfCardIDIsZero - jr c, .asm_9a2f - call LoadCardDataToBuffer1_FromCardID - jr c, .asm_9a2f - ld a, [wLoadedCard1Type] - and TYPE_ENERGY - jr nz, .asm_9a12 - ld a, [wLoadedCard1Stage] + jr c, .asm_99b7 + push hl + ld hl, wc000 +.asm_9998 + ld c, [hl] + inc hl + ld b, [hl] + inc hl + ld a, b + cp $ff + ld a, c + jr nz, .asm_99a9 + cp $ff + jr nz, .asm_99a9 + pop hl + jr .asm_998b +.asm_99a9 + cp e + jr nz, .asm_9998 + ld a, b + cp d + jr nz, .asm_9998 + dec hl + xor a + ld [hld], a + ld [hl], a + pop hl + jr .asm_998b +.asm_99b7 + ld hl, wc000 +.asm_99ba + ld e, [hl] + inc hl + ld d, [hl] + inc hl + cp16 $ffff + jr z, .asm_99d2 + call CheckIfCardIDIsZero + jr nc, .set_carry or a - jr nz, .asm_9a12 + jr nz, .set_carry + jr .asm_99ba +.asm_99d2 + call GetSRAMPointerToCurDeck + ld de, wCurDeckName + call EnableSRAM +.loop_name + ld a, [de] + cp [hl] + jr nz, .set_carry + inc de + inc hl + or a + jr nz, .loop_name + call DisableSRAM + ret +.set_carry + call DisableSRAM scf ret -.asm_9a2f + +; returns carry if doesn't have a valid deck +; aside from the current deck +CheckIfHasOtherValidDecks: + ld hl, wDecksValid + lb bc, 0, 0 +.loop + inc b + ld a, NUM_DECKS + cp b + jr c, .check_has_cards + ld a, [hli] + or a + jr z, .loop + ; is valid + inc c + ld a, 1 + cp c + jr nc, .loop; just 1 valid + ; at least 2 decks are valid +.no_carry + or a + ret + +.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 GetSRAMPointerToCurDeckCards + call CheckIfDeckHasCards + jr c, .no_carry ; no cards + ; has cards, is the only valid deck! + scf + ret + +CheckIfThereAreAnyBasicCardsInDeck: + ld hl, wCurDeckCards +.loop_cards + ld e, [hl] + inc hl + ld d, [hl] + inc hl + call CheckIfCardIDIsZero + jr c, .no_carry + call LoadCardDataToBuffer1_FromCardID + jr c, .no_carry + ld a, [wLoadedCard1Type] + and TYPE_ENERGY + jr nz, .loop_cards + ld a, [wLoadedCard1Stage] + or a + jr nz, .loop_cards + scf + ret +.no_carry or a ret @@ -1409,9 +2176,21 @@ FiltersCardSelectionParams: db SYM_SPACE ; invisible cursor tile dw NULL ; wCardListHandlerFunction -SECTION "Bank 2@5a6d", ROMX[$5a6d], BANK[$2] +SECTION "Bank 2@5a43", ROMX[$5a43], BANK[$2] -Func_9a6d: +DeckConfigurationMenu_TransitionTable: + cursor_transition $10, $20, $00, $03, $03, $01, $02 + cursor_transition $48, $20, $00, $04, $04, $02, $00 + cursor_transition $80, $20, $00, $05, $05, $00, $01 + cursor_transition $10, $30, $00, $00, $00, $04, $05 + cursor_transition $48, $30, $00, $01, $01, $05, $03 + cursor_transition $80, $30, $00, $02, $02, $03, $04 + +; draws each card type icon in a line +; the respective card counts underneath each icon +; and prints"X/60" in the upper-right corner, +; where X is the total card count +DrawCardTypeIconsAndPrintCardCounts: call PrepareMenuGraphics lb bc, 0, 5 ld a, SYM_BOX_TOP @@ -1443,17 +2222,19 @@ FillBGMapLineWithA: call BankswitchVRAM0 ret -Func_9aaa: +; saves the count of each type of card that is in wCurDeckCards +; stores these values in wCardFilterCounts +CountNumberOfCardsForEachCardType: ld hl, wCardFilterCounts ld de, CardTypeFilters -.asm_9ab0 +.loop ld a, [de] - cp $ff + cp -1 ret z inc de - call Func_9cdc + call CountNumberOfCardsOfType ld [hli], a - jr .asm_9ab0 + jr .loop ; a = byte to write ; b = number of bytes @@ -1520,9 +2301,15 @@ DrawCardTypeIcons: db ICON_TILE_TRAINER, 15, 2 db ICON_TILE_ENERGY, 17, 2 db $00 -; 0x9b18 -SECTION "Bank 2@5b31", ROMX[$5b31], BANK[$2] +DeckBuildMenuTextItems: + textitem 2, 2, DeckBuildingConfirmText + textitem 9, 2, DeckBuildingContinueModifyingText + textitem 16, 2, DeckBuildingNameText + textitem 2, 4, DeckBuildingSaveText + textitem 9, 4, DeckBuildingDismantleText + textitem 16, 4, CancelDeckText + db $ff ; prints "/60" to the coordinates given in de PrintSlashSixty: @@ -1794,22 +2581,27 @@ Func_9c55: pop hl ret -Func_9c80: +; appends text "X/Y", where X is the number of included cards +; and Y is the total number of cards in storage of a given card ID +; input: +; e = card ID +AppendOwnedCardCountAndStorageCountNumbers: push af push bc push de push hl -.asm_9c84 +; count how many bytes until $00 +.loop ld a, [hl] or a - jr z, .asm_9c8b + jr z, .print inc hl - jr .asm_9c84 -.asm_9c8b + jr .loop +.print push de call GetCountOfCardInCurDeck call ConvertToNumericalDigits - ld [hl], $05 + ld [hl], TX_SYMBOL inc hl ld [hl], SYM_SLASH inc hl @@ -1875,13 +2667,13 @@ ConvertToNumericalDigits: ld [hli], a ret -Func_9cdc: +CountNumberOfCardsOfType: push de push hl ld hl, $0 ld b, a ld c, $00 -.asm_9ce4 +.loop_cards push hl push bc ld bc, wCurDeckCards @@ -1894,30 +2686,32 @@ Func_9cdc: inc hl inc hl call CheckIfCardIDIsZero - jr c, .asm_9d16 + jr c, .done call GetCardType - jr c, .asm_9d16 + jr c, .done push hl ld l, a ld a, b - and $20 - cp $20 - jr z, .asm_9d0b + and FILTER_ENERGY + cp FILTER_ENERGY + jr z, .check_energy ld a, l pop hl cp b - jr nz, .asm_9ce4 - jr .asm_9d13 -.asm_9d0b + jr nz, .loop_cards + jr .incr_count + +; counts all energy cards as the same +.check_energy ld a, l pop hl - and $08 - cp $08 - jr nz, .asm_9ce4 -.asm_9d13 + and TYPE_ENERGY + cp TYPE_ENERGY + jr nz, .loop_cards +.incr_count inc c - jr .asm_9ce4 -.asm_9d16 + jr .loop_cards +.done ld a, c pop hl pop de @@ -1950,7 +2744,7 @@ PrintCardTypeCounts: call ProcessText ret -Func_9d41: +PrintFilteredCardList: push af ld hl, CardTypeFilters ld b, $00 @@ -1958,9 +2752,11 @@ Func_9d41: add hl, bc ld a, [hl] push af + +; copy sCardCollection to wTempCardCollection call EnableSRAM ld hl, sCardCollection - ld de, wc000 + ld de, wTempCardCollection ld b, $00 call CopyBBytesFromHLToDE_Bank02 ld hl, $a200 @@ -1968,24 +2764,25 @@ Func_9d41: ld b, $00 call CopyBBytesFromHLToDE_Bank02 call DisableSRAM - ld a, [wd383] + + ld a, [wIncludeCardsInDeck] or a - jr z, .asm_9d75 + jr z, .ok call GetSRAMPointerToCurDeckCards ld d, h ld e, l call IncrementDeckCardsInTempCollection -.asm_9d75 +.ok pop af call CreateFilteredCardList - ld a, $06 + 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 - call Func_9dbf + call PrintDeckBuildingCardList pop af ret @@ -2030,7 +2827,13 @@ PrintTotalCardCount: call ProcessText ret -Func_9dbf: +; prints the name, level and storage count of the cards +; that are visible in the list window +; in the form: +; CARD NAME/LEVEL X/Y +; where X is the current count of that card +; and Y is the storage count of that card +PrintDeckBuildingCardList: push bc ld hl, wCardListCoords ld e, [hl] @@ -2041,13 +2844,16 @@ Func_9dbf: dec c ld a, [wScrollMenuScrollOffset] or a - jr z, .asm_9dd4 + jr z, .no_cursor ld a, SYM_CURSOR_U - jr .asm_9dd6 -.asm_9dd4 + jr .got_cursor_tile +.no_cursor ld a, SYM_SPACE -.asm_9dd6 +.got_cursor_tile call WriteByteToBGMap0 + +; iterates by decreasing value in wNumVisibleCardListEntries +; by 1 until it reaches 0 ld a, [wScrollMenuScrollOffset] add a ld c, a @@ -2055,66 +2861,72 @@ Func_9dbf: ld hl, wTempCardList add hl, bc ld a, [wNumVisibleCardListEntries] -.asm_9de7 +.loop_filtered_cards push de or a - jr z, .asm_9e25 + jr z, .exit_loop ld b, a ld e, [hl] inc hl ld d, [hl] inc hl call CheckIfCardIDIsZero - jr c, .asm_9e13 + jr c, .invalid_card call AddCardIDToVisibleList call LoadCardDataToBuffer1_FromCardID - ld a, $0d + ld a, 13 push bc push hl push de call CopyCardNameAndLevel pop de - call Func_9c80 + call AppendOwnedCardCountAndStorageCountNumbers pop hl pop bc pop de push hl call InitTextPrinting ld hl, wDefaultText - jr .asm_9e1b -.asm_9e13 + jr .process_text + +.invalid_card pop de push hl call InitTextPrinting ld hl, Text_9e48 -.asm_9e1b +.process_text call ProcessText pop hl + ld a, b dec a inc e inc e - jr .asm_9de7 -.asm_9e25 + jr .loop_filtered_cards + +.exit_loop ld a, [hli] or a - jr nz, .asm_9e2d + jr nz, .can_scroll ld a, [hli] or a - jr z, .asm_9e36 -.asm_9e2d + jr z, .cannot_scroll +.can_scroll pop de - xor a +; draw down cursor because +; there are still more cards +; to be scrolled down + xor a ; FALSE ld [wUnableToScrollDown], a ld a, SYM_CURSOR_D - jr .asm_9e3e -.asm_9e36 + jr .draw_cursor +.cannot_scroll pop de - ld a, $01 + ld a, TRUE ld [wUnableToScrollDown], a - ld a, $00 -.asm_9e3e - ld b, $13 + ld a, SYM_SPACE +.draw_cursor + ld b, 19 ; x coord ld c, e dec c dec c @@ -3571,10 +4383,10 @@ Func_a705: ld hl, wCurDeckName ld [hl], TX_END ld hl, $6726 - call Func_8f6b + call InitDeckBuildingParams ld a, $01 ld [wd121], a - call Func_95d6 + call HandleDeckBuildScreen ret ; 0xa726 @@ -3588,9 +4400,131 @@ CopyBBytesFromHLToDE_Bank02: dec b jr nz, .loop ret -; 0xa786 -SECTION "Bank 2@689d", ROMX[$689d], BANK[$2] +Func_a786: + call WriteCardListsTerminatorBytes + call PrintPlayersCardsHeaderInfo + xor a + ld [wScrollMenuScrollOffset], a + ld [wCurCardTypeFilter], a + call PrintFilteredCardSelectionList + call EnableLCD + xor a + ld hl, FiltersCardSelectionParams + call InitializeScrollMenuParameters +.asm_a7a0 + call DoFrame + ld a, [wCurCardTypeFilter] + ld b, a + ld a, [wTempCardTypeFilter] + cp b + jr z, .asm_a7ca + ld [wCurCardTypeFilter], a + ld hl, wScrollMenuScrollOffset + ld [hl], $00 + call PrintFilteredCardSelectionList + ld hl, hffbb + ld [hl], $01 + call PrintPlayersCardsText + ld hl, hffbb + ld [hl], $00 + ld a, $09 + ld [wNumMenuItems], a +.asm_a7ca + ldh a, [hDPadHeld] + and PAD_DOWN + jr z, .asm_a7d5 + call ConfirmSelectionAndReturnCarry + jr .asm_a7e2 +.asm_a7d5 + call HandleCardSelectionInput + jr nc, .asm_a7a0 + ld a, [hCurMenuItem] + cp $ff + jr nz, .asm_a7e2 + ret +.asm_a7e2 + ld a, [wNumEntriesInCurFilter] + or a + jr z, .asm_a7a0 + xor a + ld hl, GeneralCardListMenuParams + call InitializeScrollMenuParameters + ld a, [wNumEntriesInCurFilter] + ld [wNumCardListEntries], a + ld hl, wNumVisibleCardListEntries + cp [hl] + jr nc, .asm_a7fe + ld [wNumMenuItems], a +.asm_a7fe + ld hl, GeneralCardListUpdateFunc + ld d, h + ld a, l + ld hl, wScrollMenuScrollFunc + ld [hli], a + ld [hl], d + xor a + ld [wd119], a +.asm_a80c + call DoFrame + ldh a, [hDPadHeld] + and PAD_UP + jr z, .asm_a825 + ld a, [wTempCardTypeFilter] + ld hl, wScrollMenuScrollOffset + add [hl] + jr nz, .asm_a825 + ld a, $ff + ld [hCurMenuItem], a + jr .asm_a87e +.asm_a825 + call HandleSelectUpAndDownInList + jr c, .asm_a80c + call HandleScrollListInput + jr c, .asm_a87e + ldh a, [hDPadHeld] + and PAD_START + jr z, .asm_a80c +.asm_a835 + ld a, MENU_CONFIRM + call PlayConfirmOrCancelSFX + ld a, [wNumMenuItems] + ld [wTempScrollMenuNumVisibleItems], a + ld a, [wTempCardTypeFilter] + ld [wTempCurMenuItem], a + ld de, wTempCardList + ld hl, wCurCardListPtr + ld [hl], e + inc hl + ld [hl], d + call OpenCardPageFromCardList + call PrintPlayersCardsHeaderInfo + ld hl, FiltersCardSelectionParams + call InitializeScrollMenuParameters + ld a, [wCurCardTypeFilter] + ld [wTempCardTypeFilter], a + call DrawHorizontalListCursor_Visible + call PrintCardSelectionList + call EnableLCD + ld hl, GeneralCardListMenuParams + call InitializeScrollMenuParameters + ld a, [wTempScrollMenuNumVisibleItems] + ld [wNumMenuItems], a + ld a, [wTempCurMenuItem] + ld [wTempCardTypeFilter], a + jr .asm_a80c +.asm_a87e + call DrawListCursor_Invisible + ld a, [wTempCardTypeFilter] + ld [wTempCurMenuItem], a + ld a, [hCurMenuItem] + cp $ff + jr nz, .asm_a835 + ld hl, FiltersCardSelectionParams + call InitializeScrollMenuParameters + ld a, [wCurCardTypeFilter] + ld [wTempCardTypeFilter], a + jp .asm_a7a0 GeneralCardListMenuParams: db 1 ; x pos diff --git a/src/engine/bank03.asm b/src/engine/bank03.asm index efd19a6..2ec2313 100644 --- a/src/engine/bank03.asm +++ b/src/engine/bank03.asm @@ -348,10 +348,10 @@ Func_c24d: ld [wd586], a ld [wCurOWLocation], a ld [wCurMusic], a - ld [wd611 + 0], a - ld [wd611 + 1], a - ld [wd613 + 0], a - ld [wd613 + 1], a + ld [wSentMailBitmask + 0], a + ld [wSentMailBitmask + 1], a + ld [wSentMailBitmask + 2], a + ld [wSentMailBitmask + 3], a call Func_ebc6 jr nc, .asm_c299 call Func_eb39 @@ -2836,7 +2836,7 @@ OverworldScriptTable: dw ScriptCommand_SetTextRAM2b ; $61 dw ScriptCommand_SetVariableTextRAM2b ; $62 dw ScriptCommand_ReplaceNPC ; $63 - dw ScriptCommand_64 ; $64 + dw ScriptCommand_SendMail ; $64 dw ScriptCommand_CheckNPCLoaded ; $65 dw ScriptCommand_GiveDeck ; $66 dw ScriptCommand_67 ; $67 @@ -4388,22 +4388,24 @@ ScriptCommand_ReplaceNPC: jp IncreaseScriptPointerBy3 ; for the buffer value n, -; - if n = 0 or n >= 29, skip -; - else, set bit (m-1) of [dw hl] and Func_1f24e, where -; - hl = wd611 and m = n if 0 < n <= 16, -; - hl = wd613 and m = n-16 if 16 < n < 29, +; - if n = 0 or n >= NUM_UNIQUE_MAILS_IN_GAME, skip +; - else, set bit (m-1) of [dw hl] and AddMailToQueue, where +; - hl = wSentMailBitmask and m = n if 0 < n <= 16, +; - hl = wSentMailBitmask + 2 and m = n-16 if 16 < n < NUM_UNIQUE_MAILS_IN_GAME, ; then IncreaseScriptPointerBy2 -ScriptCommand_64: +ScriptCommand_SendMail: call Get1ScriptArg_IncrIndexBy1 or a - jr z, .done - cp $1d - jr nc, .done - ld hl, wd611 + jr z, .done ; 0 is an invalid mail number + + cp NUM_UNIQUE_MAILS_IN_GAME + jr nc, .done ; mail > NUM_UNIQUE_MAILS_IN_GAME is another invalid mail number + + ld hl, wSentMailBitmask cp $10 + 1 jr c, .set_bitmask inc hl - inc hl ; wd613 + inc hl ; wSentMailBitmask + 2 sub $10 .set_bitmask ld de, 1 @@ -4414,7 +4416,7 @@ ScriptCommand_64: rl d jr .set_bitmask_loop .got_bitmask - ld a, [hli] + ld a, [hli] ; wSentMailBitmask or wSentMailBitmask + 2 ld c, a ld a, [hld] ld b, a @@ -4424,8 +4426,11 @@ ScriptCommand_64: ld a, b and d .checked_bit + ; if the bit is set then we have already sent this mail before. do not send again jr nz, .done -; set bit and call + + ; if we got here, this mail has never been sent before. + ; set the appropriate bit in the bitmask, and send the mail ld a, c or e ld c, a @@ -4436,7 +4441,7 @@ ScriptCommand_64: ld [hli], a ld [hl], b call Get1ScriptArg_IncrIndexBy1 - farcall Func_1f24e + farcall AddMailToQueue .done jp IncreaseScriptPointerBy2 @@ -5680,7 +5685,7 @@ Func_f085: dec c jr nz, .asm_f091 ld c, PAD_A | PAD_B - farcall Func_10221 + farcall WaitForButtonPress pop de ret ; 0xf0c3 diff --git a/src/engine/bank04.asm b/src/engine/bank04.asm index ad8353b..9242f59 100644 --- a/src/engine/bank04.asm +++ b/src/engine/bank04.asm @@ -189,7 +189,7 @@ SECTION "Bank 4@4221", ROMX[$4221], BANK[$4] ; waits until any of the keys ; in register c are pressed -Func_10221: +WaitForButtonPress: .loop call DoFrame ldh a, [hKeysPressed] @@ -1263,17 +1263,17 @@ Func_1081a: ret Func_10836: - ld hl, Data_1083d + ld hl, .function_map call CallMappedFunction ret -Data_1083d: ; pause menu - db $00, $07, $f2, $45 ; status - db $01, $07, $02, $45 ; diary - db $02, $04, $65, $48 ; deck - db $03, $07, $4f, $67 ; minicon - db $04, $07, $9a, $5c ; coin - db $05, $07, $6e, $41 ; settings +.function_map: ; pause menu + key_func $00, PauseMenuStatusScreen ; status + key_func $01, PauseMenuDiaryScreen ; diary + key_func $02, PauseMenuDeckScreen ; deck + key_func $03, PauseMenuMinicomScreen ; minicom + key_func $04, PauseMenuCoinScreen ; coin + key_func $05, PauseMenuConfigScreen ; config db $ff Func_10856: @@ -1283,7 +1283,29 @@ Func_10856: ret ; 0x10861 -SECTION "Bank 4@488a", ROMX[$488a], BANK[$4] +SECTION "Bank 4@4865", ROMX[$4865], BANK[$4] + +PauseMenuDeckScreen: + call Func_1022a + call ShowDeckSelectionMenuFromPauseMenu + call Func_10252 + ret + +ShowDeckSelectionMenuFromPauseMenu: + push af + push bc + push de + push hl + call SetFadePalsFrameFunc + farcall DeckSelectionMenu + farcall StartFadeToWhite + farcall WaitPalFading_Bank07 + call UnsetFadePalsFrameFunc + pop hl + pop de + pop bc + pop af + ret ZeroObjectPositionsAndEnableOBPFading: push af @@ -6303,7 +6325,7 @@ Func_131d7: ldtx hl, GameCenterBlackBoxSaveRequestText call PrintScrollableText_NoTextBoxLabelVRAM0 ld c, $00 - farcall Func_1c5a3 + farcall DrawSavePromptAndWaitForInput ret nc ldtx hl, GameCenterBlackBoxUnableSaveRequiredText call PrintScrollableText_NoTextBoxLabelVRAM0 @@ -6320,7 +6342,7 @@ Func_131eb: ret Func_131fd: - farcall Func_1f324 + farcall CheckForBlackBoxCardInMail ret nc ldtx hl, GameCenterBlackBoxUnableLastOutputRemainingText call PrintScrollableText_NoTextBoxLabelVRAM0 diff --git a/src/engine/bank06.asm b/src/engine/bank06.asm index 3d1894c..d8663f2 100644 --- a/src/engine/bank06.asm +++ b/src/engine/bank06.asm @@ -5965,9 +5965,31 @@ HandCardsGfx: WhatIsYourNameData: textitem 1, 1, WhatIsYourNameText db $ff ; end -; 0x1ae65 -SECTION "Bank 6@6e92", ROMX[$6e92], BANK[$6] +Deck1RenameText: + textitem 2, 1, Deck1Text + textitem 14, 1, DeckText + db $ff + +Deck2RenameText: + textitem 2, 1, Deck2Text + textitem 14, 1, DeckText + db $ff + +Deck3RenameText: + textitem 2, 1, Deck3Text + textitem 14, 1, DeckText + db $ff + +Deck4RenameText: + textitem 2, 1, Deck4Text + textitem 14, 1, DeckText + db $ff + +Deck5RenameText: + textitem 2, 1, Deck5Text + textitem 14, 1, DeckText + db $ff ; dupe of PlayConfirmOrCancelSFX in bank 2 ; if a = MENU_CANCEL (-1), play SFX_CANCEL (usually following B button) @@ -5993,6 +6015,13 @@ InputPlayerName: ld a, MAX_PLAYER_NAME_LENGTH ld hl, WhatIsYourNameData lb bc, 12, 1 +; fallthrough + +; a = maximum length of name (depending on whether player's or deck's). +; bc = position of name. +; de = dest. pointer. +; hl = pointer to text item of the question. +InputName: call InitializeInputName call Set_OBJ_8x8 diff --git a/src/engine/bank07.asm b/src/engine/bank07.asm index dc019cd..dd7702e 100644 --- a/src/engine/bank07.asm +++ b/src/engine/bank07.asm @@ -317,6 +317,15 @@ GetDuelistPortrait:: db PORTRAIT_DR_MASON ; DR_MASON_PIC ; 0x1c116 +SECTION "Bank 7@416e", ROMX[$416e], BANK[$7] + +PauseMenuConfigScreen: + farcall Func_1022a + call ShowConfigMenu + farcall Func_10252 + ret +; 0x1c17a + SECTION "Bank 7@417a", ROMX[$417a], BANK[$7] ShowConfigMenu: @@ -689,9 +698,80 @@ ConvertTextSpeedToMessageSpeedSetting: db 0, 1, 2, 0, 3, 0, 4 ; 0x1c45a -SECTION "Bank 7@45a3", ROMX[$45a3], BANK[$7] +SECTION "Bank 7@4502", ROMX[$4502], BANK[$7] -Func_1c5a3: +PauseMenuDiaryScreen: + farcall Func_1022a + call PushRegistersAndShowDiaryScreen + farcall Func_10252 + ret + +PushRegistersAndShowDiaryScreen: + push af + push bc + push de + push hl + call ShowDiaryScreen + pop hl + pop de + pop bc + pop af + ret + +ShowDiaryScreen: + farcall ClearSpriteAnimsAndSetInitialGraphicsConfiguration + farcall ClearSpriteAnims + call DrawDiaryStatusBox + farcall SetFadePalsFrameFunc + call StartFadeFromWhite + call WaitPalFading_Bank07 + ld c, $00 + call DrawSavePromptAndWaitForInput + call StartFadeToWhite + call WaitPalFading_Bank07 + farcall UnsetFadePalsFrameFunc + ret + +DrawDiaryStatusBox: + lb de, 0, 0 + lb bc, 20, 12 + call DrawRegularTextBoxVRAM0 + lb de, 0, 12 + lb bc, 20, 6 + call DrawRegularTextBoxVRAM0 + ld hl, .TextItems + call PlaceTextItemsVRAM0 + lb bc, 1, 3 + call DrawPlayerPortrait + ldtx hl, PlayerDiaryTitleText + lb de, 5, 1 + call PrintTextNoDelay_InitVRAM0 + ldtx hl, TxRam1Text + lb de, 11, 4 + call PrintTextNoDelay_InitVRAM0 + call CountEventCoinsObtained + ld l, a + ld h, $00 + lb de, 16, 6 + ld a, $02 + ld b, TRUE + call PrintNumber + lb de, 13, 10 + farcall PrintPlayTime + lb de, 12, 8 + farcall PrintCardAlbumProgress + ret + +.TextItems: + textitem 7, 4, PlayerDiaryNameText + textitem 7, 6, PlayerDiaryEventCoinText + textitem 18, 6, PlayerDiaryCardsUnitText + textitem 7, 8, PlayerDiaryAlbumText + textitem 7, 10, PlayerDiaryPlayTimeText + db $ff + +; c - ? +DrawSavePromptAndWaitForInput: push bc push de push hl @@ -740,9 +820,95 @@ Func_1c5d6: pop bc pop af ret -; 0x1c5f2 -SECTION "Bank 7@46bb", ROMX[$46bb], BANK[$7] +PauseMenuStatusScreen: + farcall Func_1022a + call PushRegistersAndShowStatusScreen + farcall Func_10252 + ret + +PushRegistersAndShowStatusScreen: + push af + push bc + push de + push hl + call ShowStatusScreen + pop hl + pop de + pop bc + pop af + ret + +ShowStatusScreen: + farcall ClearSpriteAnimsAndSetInitialGraphicsConfiguration + farcall ClearSpriteAnims + call DisableLCD + call DrawStatusScreenTopBox + call DrawStatusScreenBottomBox + call EnableLCD + farcall SetFrameFuncAndFadeFromWhite + ld c, PAD_A | PAD_B + farcall WaitForButtonPress + farcall FadeToWhiteAndUnsetFrameFunc + ret + +DrawStatusScreenTopBox: + lb de, 0, 0 + lb bc, 20, 8 + call DrawRegularTextBoxVRAM0 + ld hl, .TextItems + call PlaceTextItemsVRAM0 + lb bc, 1, 1 + call DrawPlayerPortrait + ldtx hl, TxRam1Text + lb de, 11, 2 + call PrintTextNoDelay_InitVRAM0 + lb de, 13, 6 + farcall PrintPlayTime + lb de, 12, 4 + farcall PrintCardAlbumProgress + ret + +.TextItems: + textitem 7, 2, PlayerDiaryNameText + textitem 7, 4, PlayerDiaryAlbumText + textitem 7, 6, PlayerDiaryPlayTimeText + db $ff + +DrawStatusScreenBottomBox: + lb de, 0, 8 + lb bc, 20, 10 + call DrawRegularTextBoxVRAM0 + lb de, 1, 8 + lb bc, 9, 1 + farcall FillBoxInBGMapWithZero + ld hl, .TextItems + call PlaceTextItemsVRAM0 + call Func_1dfb5 + call GetCoinName + lb de, 4, 12 + call InitTextPrinting_ProcessTextFromIDVRAM0 + call Func_1dfb5 + add $28 + lb de, 28, 108 + call CreateCoinAnimation + call CheckObtainedGRCoinPieces + add $40 + lb de, 28, 140 + call CreateCoinAnimation + call CheckObtainedGRCoinPieces + and a + jr z, .asm_1c6b1 + ldtx hl, PlayerStatusGRCoinText + lb de, 4, 14 + call InitTextPrinting_ProcessTextFromIDVRAM0 +.asm_1c6b1 + ret + +.TextItems: + textitem 1, 8, PlayerStatusEventCoinTitleText + textitem 4, 10, PlayerStatusCurrentCoinText + db $ff SetAllPaletteFadeConfigsToEnabled: call SetAllBGPaletteFadeConfigsToEnabled @@ -2838,7 +3004,7 @@ Func_1d475: farcall MaxOutEventValue farcall ClearGameCenterChips - call Func_1eca5 + call InitializeMailboxWRAM call Func_1d7a1 call Func_1d9f9 call Func_1dcb7 @@ -2848,7 +3014,7 @@ Func_1d475: farcall ClearCardPopNameList call EnableAnimations - call Func_1e767 + call ClearwMinicomMenuCursorPosition farcall Func_111f0 call InitDefaultConfigMenuSettings call SaveConfigMenuChoicesToSRAM @@ -3493,7 +3659,7 @@ Func_1da2a: ldtx de, ReceptionistText farcall PrintScrollableText_WithTextBoxLabelVRAM0 ld c, $01 - call Func_1c5a3 + call DrawSavePromptAndWaitForInput ret nc ldtx hl, GiftCenterServiceUnavailableSaveRequiredText ldtx de, ReceptionistText @@ -3718,7 +3884,7 @@ Func_1dc52: call Func_1dd89 ret -Func_1dc9a: +PauseMenuCoinScreen: farcall Func_1022a call ShowCoinMenuWithoutIncomingCoin farcall Func_10252 @@ -5376,29 +5542,139 @@ Func_1e73a: pop bc pop af ret -; 0x1e74f -SECTION "Bank 7@6767", ROMX[$6767], BANK[$7] - -Func_1e767: - xor a - ld [wdd07], a +PauseMenuMinicomScreen: + farcall Func_1022a + call PushRegistersAndShowMinicomScreen + farcall Func_10252 ret -; 0x1e76c -SECTION "Bank 7@6837", ROMX[$6837], BANK[$7] +PushRegistersAndShowMinicomScreen: + push af + push bc + push de + push hl + call ShowMinicomScreen + pop hl + pop de + pop bc + pop af + ret -Func_1e837: +ClearwMinicomMenuCursorPosition: + xor a + ld [wMinicomMenuCursorPosition], a + ret + +ShowMinicomScreen: + farcall ClearSpriteAnimsAndSetInitialGraphicsConfiguration + call DrawMinicomMainScreen + farcall SetFrameFuncAndFadeFromWhite +.loop + call HandleMinicomMenuBox + jr c, .end + call CallMinicomMenuFunction + jr c, .end + call DisableLCD + farcall ClearSpriteAnimsAndSetInitialGraphicsConfiguration + call DrawMinicomMainScreen + call EnableLCD + jr .loop +.end + farcall FadeToWhiteAndUnsetFrameFunc + ret + +DrawMinicomMainScreen: + ld b, BANK(.menu) + ld hl, .menu + lb de, 0, 3 + call LoadMenuBoxParams + ld a, [wMinicomMenuCursorPosition] + call DrawMenuBox + lb de, 0, 0 + lb bc, 20, 4 + call DrawRegularTextBoxVRAM0 + ldtx hl, PauseMenuMinicomText + lb de, 7, 2 + call InitTextPrinting_ProcessTextFromIDVRAM0 + lb de, 0, 12 + lb bc, 20, 6 + call DrawRegularTextBoxVRAM0 + ldtx hl, MinicomDialogText + lb de, 1, 14 + call InitTextPrinting_ProcessTextFromIDVRAM0 + call Func_1f309 + jr z, .done + ld b, BANK(.SpriteAnimGfxParams) + ld hl, .SpriteAnimGfxParams + ld d, 120 + ld e, 32 + ld a, $00 + ld c, $00 + call CreateSpriteAnim +.done + ret + +.menu: + menu_box_params TRUE, 20, 10, \ + SYM_CURSOR_R, SYM_SPACE, SYM_CURSOR_R, SYM_CURSOR_R, \ + PAD_A, PAD_B, FALSE, 1, NULL, NULL + textitem 3, 2, MinicomDeckSaveMachineText + textitem 3, 4, MinicomMailboxText + textitem 3, 6, MinicomCardAlbumText + textitem 3, 8, PCMenuShutdownText + db $ff + +.SpriteAnimGfxParams: + dw TILESET_SMALL_ENVELOPE + dw SPRITE_ANIM_AA + dw FRAMESET_173 + dw PALETTE_180 + +; return +; a - cursor position, used later in CallMinicomMenuFunction +HandleMinicomMenuBox: + ld a, [wMinicomMenuCursorPosition] + call HandleMenuBox + ld [wMinicomMenuCursorPosition], a + jr c, .cancel + push af + ld a, SFX_CONFIRM + call CallPlaySFX + pop af + ret +.cancel + push af + ld a, SFX_CANCEL + call CallPlaySFX + pop af + ret + +; a - function table index +CallMinicomMenuFunction: + ld hl, .minicom_functions + call CallMappedFunction + ret + +.minicom_functions: + key_func $00, MinicomDeckSaveMachine + key_func $01, MinicomMailbox + key_func $02, MinicomCardAlbum + db $ff + +MinicomDeckSaveMachine: farcall ClearSpriteAnimsAndSetInitialGraphicsConfiguration farcall Func_baec ret -; 0x1e840 -SECTION "Bank 7@6849", ROMX[$6849], BANK[$7] +MinicomCardAlbum: + farcall ClearSpriteAnimsAndSetInitialGraphicsConfiguration + farcall Func_a786 + ret Func_1e849: farcall Func_1022a - call Func_1e837 + call MinicomDeckSaveMachine farcall Func_10252 ret @@ -5595,7 +5871,7 @@ Func_1e99c: call LoadGfxPalettes farcall SetFrameFuncAndFadeFromWhite ld c, PAD_B - farcall Func_10221 + farcall WaitForButtonPress call Func_3f61 farcall FadeToWhiteAndUnsetFrameFunc ret @@ -5869,68 +6145,892 @@ Func_1ec0f: ret ; 0x1ec38 -SECTION "Bank 7@6ca5", ROMX[$6ca5], BANK[$7] +SECTION "Bank 7@6c96", ROMX[$6c96], BANK[$7] -Func_1eca5: +MinicomMailbox: + push af + push bc + push de + push hl + call MinicomMailboxNewMailScreen + call MinicomMailboxMainScreen + pop hl + pop de + pop bc + pop af + ret + +InitializeMailboxWRAM: push af push bc push de push hl xor a - ld [wdd36], a - ld [wdd50], a - ld [wdd5c], a - ld [wdd5d], a - ld [wdd5e], a - ld [wdd5b], a - ld [wdd5a], a - ld [wdd5f], a - ld [wdd60], a - ld [wdd73], a - ld [wdd74], a + ld [wNumMailInQueue], a + ld [wMailCount], a + ld [wMailboxPage], a + ld [wSelectedMailCursorPosition], a + ld [wMailOptionSelected], a + ld [wTempNumMailInQueue], a + ld [wNewMail], a + ld [wBlackBoxCardReceived], a + ld [wBlackBoxCardReceived + 1], a + ld [wBillsPCCardReceived], a + ld [wBillsPCCardReceived + 1], a xor a - ld hl, wdd37 - ld bc, $19 + ld hl, wMailQueue + ld bc, MAIL_QUEUE_BUFFER_SIZE call WriteBCBytesToHL xor a - ld hl, wdd51 - ld bc, $9 + ld hl, wMailList + ld bc, MAIL_BUFFER_SIZE call WriteBCBytesToHL pop hl pop de pop bc pop af ret -; 0x1ece4 -SECTION "Bank 7@724e", ROMX[$724e], BANK[$7] +; the screen after selecting the mailbox which has a large picture of a literal mailbox on it +MinicomMailboxNewMailScreen: + call DisableLCD + farcall ClearSpriteAnimsAndSetInitialGraphicsConfiguration + call CalculateMailboxStatus + call Func_1ed2d + call FlushAllPalettes + call EnableLCD + ld a, [wNewMail] + and a + jr z, .asm_1ed04 + push af + ld a, SFX_NEW_MAIL + call CallPlaySFX + pop af +.asm_1ed04 + call Func_1ed57 + call DisableLCD + xor a + ld [wNewMail], a + ld [wMailboxPage], a + ld [wSelectedMailCursorPosition], a + ld [wTempNumMailInQueue], a + ret -; input: a -; set carry if [wdd36] = wDD37_BUFFER_SIZE - 1 +CalculateMailboxStatus: + ld b, $00 + ld a, [wTempNumMailInQueue] + and a + jr nz, .asm_1ed28 + inc b + ld a, [wNewMail] + and a + jr nz, .asm_1ed28 + inc b +.asm_1ed28 + ld a, b + ld [wMailboxStatus], a + ret + +Func_1ed2d: + lb de, 0, 0 + lb bc, 20, 4 + call DrawRegularTextBoxVRAM0 + ldtx hl, MailboxTitleText + lb de, 6, 2 + call InitTextPrinting_ProcessTextFromIDVRAM0 + lb de, 0, 12 + lb bc, 20, 6 + call DrawRegularTextBoxVRAM0 + call Func_1ed5e + call LoadMailboxScene + ret + +LoadMailboxScene: + lb bc, 5, 5 + ld a, [hli] + call LoadScene + ret + +; hl - text +Func_1ed57: + ld a, [hli] + ld h, [hl] + ld l, a + farcall PrintScrollableText_NoTextBoxLabelVRAM0 +; fallthrough + +Func_1ed5e: + ld a, [wMailboxStatus] + add a + ld c, a + ld b, $00 + ld hl, .MailboxScenes + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + ret + +.MailboxScenes: + dw .SceneFull + dw .SceneGotMail + dw .SceneNoNewMail +.SceneFull + db SCENE_FULL_MAILBOX + tx MailboxFullWarningText +.SceneGotMail + db SCENE_GOT_MAIL + tx MailboxNewMailText +.SceneNoNewMail + db SCENE_MAILBOX + tx MailboxNoNewMailText +; 0x1ed7c + +SECTION "Bank 7@6da5", ROMX[$6da5], BANK[$7] + +MinicomMailboxMainScreen: + call DisableLCD + farcall ClearSpriteAnimsAndSetInitialGraphicsConfiguration + lb de, $40, $ff + call SetupText + call MinicomMailboxMainScreen_DrawTextBoxes + call FlushAllPalettes + call EnableLCD +.loop + call MailboxMainScreen + call Func_1eef8 + jr c, .done + call MailboxSelectedMail_LoadMenuBoxParams + call MailboxSelectedMail_HandleMenuBox + jr c, .loop + call MailboxSelectedMail_CallMappedFunction + jr .loop +.done + ret + +MinicomMailboxMainScreen_DrawTextBoxes: + lb de, 0, 4 + lb bc, 20, 14 + call DrawRegularTextBoxVRAM0 + lb de, 0, 0 + lb bc, 20, 5 + call DrawRegularTextBoxVRAM0 + ret + +MailboxMainScreen: + push af + push bc + push de + push hl + lb de, 1, 5 + ld b, BANK(MailboxMainScreenMenuBoxParams) + ld hl, MailboxMainScreenMenuBoxParams + call LoadMenuBoxParams + ld a, [wSelectedMailCursorPosition] + call DrawMenuBox + lb de, 0, 0 + lb bc, 20, 5 + call DrawRegularTextBoxVRAM0 + ldtx hl, MailboxChooseMailText + ld a, [wMailCount] + and a + jr nz, .asm_1ee0e + ldtx hl, MailboxEmptyText +.asm_1ee0e + lb de, 1, 2 + call InitTextPrinting_ProcessTextFromIDVRAM0 + ldtx hl, MailboxTitleText + lb de, 1, 0 + call Func_2c4b + ld a, [wMailboxPage] + add a + add a + ld c, a + ld b, $00 + ld hl, wMailList + add hl, bc + lb de, 2, 6 + ld c, MAIL_MAX_ON_SCREEN +.print_mail_loop + ld a, [hli] + and a + jr z, .count_mail_items_on_screen + call PrintMailSenderAndSubjectToScreen + dec c + jr nz, .print_mail_loop +.count_mail_items_on_screen + ld a, MAIL_MAX_ON_SCREEN + sub c + and a + jr nz, .done + inc a +.done + call SetMenuBoxNumItems + call Func_1ee97 + pop hl + pop de + pop bc + pop af + ret + +; a - mail ID to print +; de - coordinates passed to InitTextPrinting_ProcessTextFromIDVRAM0 +PrintMailSenderAndSubjectToScreen: + push bc + push hl + ldtx hl, MailboxSenderText + call InitTextPrinting_ProcessTextFromIDVRAM0 + inc e + ldtx hl, MailboxSubjectText + call InitTextPrinting_ProcessTextFromIDVRAM0 + and a + jr z, .asm_1ee68 + bit B_MAIL_READ, a + jr nz, .asm_1ee68 + dec d + ldtx hl, MailboxUnreadSymbolText + call InitTextPrinting_ProcessTextFromIDVRAM0 + inc d +.asm_1ee68 + ld hl, Mail + and %01111111 ; drop bit 7 (B_MAIL_READ) + ld c, a + ld b, $00 + sla c + rl b + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + ld a, d + add $05 + ld d, a + dec e + + push hl + ld a, [hli] + ld h, [hl] + ld l, a + ; sender + call InitTextPrinting_ProcessTextFromIDVRAM0 + + pop hl + inc hl + inc hl + inc e + ld a, [hli] + ld h, [hl] + ld l, a + ; subject + call InitTextPrinting_ProcessTextFromIDVRAM0 + inc e + inc e + ld a, d + sub $05 + ld d, a + pop hl + pop bc + ret + +Func_1ee97: + lb bc, 1, 17 + ld d, $1d + ld e, $01 + call Func_383b + ld a, [wMailboxPage] + cp $01 + jr nz, .asm_1eebd + lb bc, 1, 4 + ld d, $2f + ld e, $41 + call Func_383b + lb bc, 1, 17 + ld d, $1d + ld e, $01 + call Func_383b + ret +.asm_1eebd + ld a, [wMailCount] + cp $05 + ret c + lb bc, 1, 17 + ld d, $2f + ld e, $01 + call Func_383b + lb bc, 1, 4 + ld d, $1d + ld e, $01 + call Func_383b + ret + +; a menu box with blank text items that line up with mail items on screen +MailboxMainScreenMenuBoxParams: + menu_box_params FALSE, 18, 12, \ + SYM_CURSOR_R, SYM_SPACE, SYM_CURSOR_R, SYM_CURSOR_R, \ + PAD_A, PAD_B, FALSE, 1, UpdateMailboxPage, NULL + textitem 1, 1, SingleSpaceText + textitem 1, 4, SingleSpaceText + textitem 1, 7, SingleSpaceText + textitem 1, 10, SingleSpaceText + db $ff + +Func_1eef8: + ld a, [wSelectedMailCursorPosition] + call HandleMenuBox + ld [wSelectedMailCursorPosition], a + jr c, .asm_1ef22 + call GetSelectedMailPosition + ld c, a + ld b, $00 + ld hl, wMailList + add hl, bc + ld a, [hl] + and a + jr nz, .asm_1ef1a + push af + ld a, SFX_DENIED + call CallPlaySFX + pop af + jr Func_1eef8 +.asm_1ef1a + push af + ld a, SFX_CONFIRM + call CallPlaySFX + pop af + ret +.asm_1ef22 + push af + ld a, SFX_CANCEL + call CallPlaySFX + pop af + ret + +_UpdateMailboxPage:: + push af + push bc + push de + push hl + call GetMenuBoxFocusedItem + and $03 ; bottom-most mail item on the screen + cp 3 + call z, ScrollMailboxPageOnPadDown + call GetMenuBoxFocusedItem + and $03 + and a ; top mail item on the screen + call z, ScrollMailboxPageOnPadUp + pop hl + pop de + pop bc + pop af + ret + +ScrollMailboxPageOnPadDown: + ldh a, [hDPadHeld] + and PAD_DOWN + ret z + + ld a, [wMailboxPage] + cp 1 + ret z + + ld a, [wMailCount] + cp 5 + ret c + + push af + ld a, SFX_CURSOR + call CallPlaySFX + pop af + ld a, [wMailboxPage] + inc a + ld [wMailboxPage], a + xor a + ld [wSelectedMailCursorPosition], a + call MailboxMainScreen + call SetMenuBoxFocusedItem + call SetwDA37 + ret + +ScrollMailboxPageOnPadUp: + ldh a, [hDPadHeld] + and PAD_UP + ret z + + ld a, [wMailboxPage] + and a + ret z + + push af + ld a, SFX_CURSOR + call CallPlaySFX + pop af + ld a, [wMailboxPage] + dec a + ld [wMailboxPage], a + ld a, 3 + ld [wSelectedMailCursorPosition], a + call MailboxMainScreen + call SetMenuBoxFocusedItem + call SetwDA37 + ret +; 0x1ef9a + +SECTION "Bank 7@6fa4", ROMX[$6fa4], BANK[$7] + +MailboxSelectedMail_LoadMenuBoxParams: + lb de, 0, 0 + ld b, BANK(.menu_box_params) + ld hl, .menu_box_params + call LoadMenuBoxParams + xor a + call DrawMenuBox + ldtx hl, MailboxActionPromptText + lb de, 1, 1 + call InitTextPrinting_ProcessTextFromIDVRAM0 + ret + +.menu_box_params + menu_box_params TRUE, 20, 5, \ + SYM_CURSOR_R, SYM_SPACE, SYM_CURSOR_R, SYM_CURSOR_R, \ + PAD_A, PAD_B, TRUE, 0, NULL, NULL + textitem 2, 3, MailboxActionReadText + textitem 9, 3, MailboxActionDeleteText + textitem 16, 3, GiftCenterQuitText + db $ff + +MailboxSelectedMail_HandleMenuBox: + xor a + call HandleMenuBox + ld [wMailOptionSelected], a + ret + +MailboxSelectedMail_CallMappedFunction: + ld a, [wMailOptionSelected] + ld hl, .function_map + call CallMappedFunction + ret + +.function_map: + key_func $00, ReadMail + key_func $01, DeleteMail + db $ff + +ReadMail: + call DrawReadMailScreenHeader + call _ReadMail + ret + +; draws the box at the top that says the sender and subject +; does not actually fill in the sender and subject names though +DrawReadMailScreenHeader: + lb de, $40, $7f + call SetupText + lb de, 0, 0 + lb bc, 20, 5 + call DrawRegularTextBoxVRAM0 + ldtx hl, MailboxTitleText + lb de, 1, 0 + call Func_2c4b + ld hl, .text_items + call PlaceTextItemsVRAM0 + ret + +.text_items: + textitem 1, 2, MailboxSenderText + textitem 1, 3, MailboxSubjectText + db $ff + +_ReadMail: + lb bc, 1, 17 + ld d, $1d + ld e, $01 + call Func_383b + call GetSelectedMailPosition + ld c, a + ld b, $00 + ld hl, wMailList + add hl, bc + ld a, [hl] + ld [wMailId], a + set B_MAIL_READ, a ; mark mail as read + ld [hl], a + add a + ld c, a + ld b, $00 + ld hl, Mail + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [hli] + ld [wMailSenderText], a + ld a, [hli] + ld [wMailSenderText + 1], a + call PrintMailSender + ld a, [hli] + ld [wMailSubjectText], a + ld a, [hli] + ld [wMailSubjectText + 1], a + call PrintMailSubject +.read_mail_loop + ; mail is terminated with MAIL_TERMINATOR ($ffff) + ld a, [hl] + cp $ff + jr nz, .print_body + inc hl + ld a, [hld] + cp $ff + jr z, .done +.print_body + call PrintMailBodyPage + jr z, .asm_1f074 + push hl + call WaitForWideTextBoxInput + pop hl +.asm_1f074 + call GiveCardsAttachedToMailPage + jr .read_mail_loop +.done + ret + +PrintMailSender: + push hl + ld a, [wMailSenderText] + ld l, a + ld a, [wMailSenderText + 1] + ld h, a + lb de, 6, 2 + call InitTextPrinting_ProcessTextFromIDVRAM0 + pop hl + ret + +PrintMailSubject: + push hl + ld a, [wMailSubjectText] + ld l, a + ld a, [wMailSubjectText + 1] + ld h, a + lb de, 6, 3 + call InitTextPrinting_ProcessTextFromIDVRAM0 + pop hl + ret + +ClearMailBodyPage: + lb de, 1, 5 + lb bc, 18, 12 + farcall FillBoxInBGMapWithZero + ret + +; hl - mail body text +; fills the lower portion of the ReadMail screen with the mail body text at hl +; and then increments hl by 2 (advancing it to the next body page's text). +; prints nothing if value at hl is $0000 +; return +; - hl: input incremented by 2 +PrintMailBodyPage: + push hl + lb de, $80, $ff + call SetupText + pop hl + push hl + ld a, [hli] + ld h, [hl] + ld l, a + or h + jr z, .skip + call ClearMailBodyPage + lb de, 1, 6 + call PrintTextNoDelay_InitVRAM0 +.skip + pop hl + inc hl + inc hl + ret + +; give the card(s) attached to the current page of mail, if present +GiveCardsAttachedToMailPage: + push hl + ld a, [wMailId] + bit B_MAIL_READ, a + ; don't give out a card again if this mail has already been read + jr nz, .done + + ld a, [hli] + ld b, [hl] + ld c, a + or b + jr z, .done + bit B_MAIL_BOOSTER_PACK, b + jr nz, .give_booster + bit B_MAIL_GENERIC_CARD, b + jr nz, .give_generic_card + bit B_MAIL_BLACK_BOX, b + jr nz, .give_blackbox_cards + bit B_MAIL_BILLS_PC, b + jr nz, .give_billspc_card + +.done + pop hl + inc hl + inc hl + ret + +; gives the booster pack specified in the first byte of the command +.give_booster + call StartFadeToWhite + call WaitPalFading_Bank07 + ld a, c + ld b, $00 + call GiveBoosterPacks + call .redraw_mail_screen + jr .done + +; gives a card specified in the first byte of the command. +; this would effectively be a "hard-coded" card delivered with the mail. +; appears to be unused in the real game mail data +.give_generic_card + ld a, b + and %00111111 + ld d, a + ld e, c + call .give_card + call .redraw_mail_screen + jr .done + +; gives the cards attached to black box mail, found at [wBlackBoxCardReceived] +; clears out the cards by setting to $0000 as it gives them +.give_blackbox_cards + push hl + ld hl, wBlackBoxCardReceived +.blackbox_card_loop + xor a + ld e, [hl] + ld [hli], a + ld d, [hl] + ld [hli], a + ld a, d + or e + jr z, .loop_done + call .give_card + jr .blackbox_card_loop +.loop_done + pop hl + call .redraw_mail_screen + jr .done + +; gives the cards attached to bill's PC mail, found at [wBillsPCCardReceived] +.give_billspc_card + push hl + ld hl, wBillsPCCardReceived + xor a + ld e, [hl] + ld [hli], a + ld d, [hl] + ld [hli], a + call .give_card + pop hl + call .redraw_mail_screen + jr .done + +.give_card + call StartFadeToWhite + call WaitPalFading_Bank07 + push hl + farcall GetReceivedCardText + call AddCardToCollection + call Func_1d53a + pop hl + ret + +.redraw_mail_screen + inc hl + ld a, [hli] + ld b, a + ld a, [hl] + or b + jr z, .done + farcall ClearSpriteAnimsAndSetInitialGraphicsConfiguration + call DisableLCD + call MinicomMailboxMainScreen_DrawTextBoxes + call DrawReadMailScreenHeader + call PrintMailSender + call PrintMailSubject + call FlushAllPalettes + call EnableLCD + ret + +DeleteMail: + push af + push bc + push de + push hl + call GetSelectedMailPosition + ld c, a + ld b, $00 + ld hl, wMailList + add hl, bc + ld a, [hl] + ld [wMailId], a + call MailboxYesNoPrompt_DeleteConfirm + jr c, .asm_1f1ad + dec a + jr z, .asm_1f1ad + bit 7, [hl] + jr nz, .asm_1f187 + call MailboxYesNoPrompt_DeleteUnreadConfirm + jr c, .asm_1f1ad + dec a + jr z, .asm_1f1ad +.asm_1f187 + xor a + ld [hl], a + ld d, h + ld e, l + inc hl + ld a, $08 + sub c + and a + jr z, .asm_1f19d + ld c, a +.asm_1f193 + push af + ld a, [hli] + ld [de], a + inc de + pop af + dec a + jr nz, .asm_1f193 + xor a + ld [hl], a +.asm_1f19d + ld a, [wMailCount] + dec a + ld [wMailCount], a + call DeleteGameCenterMailedCard + call DrawMailDeletedTextBox + call Func_1f210 +.asm_1f1ad + pop hl + pop de + pop bc + pop af + ret + +DrawMailDeletedTextBox: + lb de, 0, 0 + lb bc, 20, 5 + call DrawRegularTextBoxVRAM0 + ldtx hl, MailboxDeletedText + lb de, 1, 2 + call InitTextPrinting_ProcessTextFromIDVRAM0 + ld a, 60 + call DoAFrames_WithPreCheck + ret + +MailboxYesNoPrompt_DeleteConfirm: + push hl + ldtx hl, MailboxActionDeleteConfirmText + call MailboxYesNoPrompt + pop hl + ret + +MailboxYesNoPrompt_DeleteUnreadConfirm: + push hl + ldtx hl, MailboxActionDeleteUnreadConfirmText + call MailboxYesNoPrompt + pop hl + ret + +; hl - text +MailboxYesNoPrompt: + push hl + ld b, BANK(.menu_box_params) + ld hl, .menu_box_params + lb de, 0, 0 + call LoadMenuBoxParams + pop hl + ld a, $01 + call DrawMenuBox + lb de, 1, 1 + call InitTextPrinting_ProcessTextFromIDVRAM0 + call HandleMenuBox + ret + +.menu_box_params + menu_box_params TRUE, 20, 5, \ + SYM_CURSOR_R, SYM_SPACE, SYM_CURSOR_R, SYM_CURSOR_R, \ + PAD_A, PAD_B, TRUE, 0, NULL, NULL + textitem 7, 3, PlayerDiaryPromptYesText + textitem 11, 3, PlayerDiaryPromptNoText + db $ff + +Func_1f210: + ld a, [wSelectedMailCursorPosition] + and a + jr nz, .asm_1f225 + ld a, [wMailboxPage] + and a + ret z + xor a + ld [wMailboxPage], a + ld a, $03 + ld [wSelectedMailCursorPosition], a + ret +.asm_1f225 + ld a, [wMailCount] + ld c, a + call GetSelectedMailPosition + cp c + ret c + ld a, [wSelectedMailCursorPosition] + dec a + ld [wSelectedMailCursorPosition], a + ret + +; if the current mail being read/acted on is from the game center, +; delete the card that is waiting to be collected. +DeleteGameCenterMailedCard: + ld a, [wMailId] + cp $01 ; black box mail id + jr nz, .asm_1f244 + ld de, $0 + call SetBlackBoxCard + ret +.asm_1f244 + cp $02 ; bill's PC mail id + ret nz + ld de, $0 + call SetBillsPCCard + ret + +; input: a - new mail to add to queue +; set carry and quit if mail queue is full, i.e. [wNumMailInQueue] = MAIL_QUEUE_BUFFER_SIZE - 1 ; else: -; - if bit 7 of a is 0, [wdd37 + [wdd36] ] = a -; - if bit 7 of a is 1, -; (the first byte in wdd37[n] whose bit 7 is 0) = a -; and shift the rest -; and increment [wdd36] by 1 -Func_1f24e: +; - if bit 7 (B_MAIL_PRIORITY_DELIVERY) of a is 0, add to the END of the mail queue +; - if bit 7 (B_MAIL_PRIORITY_DELIVERY) of a is 1, +; add to the FRONT of the mail queue and shift the rest +; this new mail will be inserted BETWEEN any current priority mail in the queue, and the non-priority +; finally, increment [wNumMailInQueue] by 1 +AddMailToQueue: push bc push de push hl ld e, a - ld a, [wdd36] - cp wDD37_BUFFER_SIZE - 1 - jr z, .set_carry - bit 7, e - call z, .not_bit7 - call nz, .has_bit7 - ld hl, wdd36 + ld a, [wNumMailInQueue] + cp MAIL_QUEUE_BUFFER_SIZE - 1 + jr z, .mail_queue_full + + bit B_MAIL_PRIORITY_DELIVERY, e + call z, .not_priority + call nz, .has_priority + + ld hl, wNumMailInQueue inc [hl] ; clear carry scf ccf jr .done -.set_carry +.mail_queue_full scf ; fallthrough .done @@ -5939,30 +7039,34 @@ Func_1f24e: pop bc ret -.not_bit7: +; if not priority mail, add it to the END of the mail queue +.not_priority: push af - ld a, [wdd36] + ld a, [wNumMailInQueue] ld c, a ld b, 0 - ld hl, wdd37 + ld hl, wMailQueue add hl, bc ld [hl], e pop af ret -.has_bit7: +; if mail is high priority, add it to the FRONT of the mail queue +; black box and bill's PC mail, for example, are sent as high priority +.has_priority: push af - ld hl, wdd37 - ld c, wDD37_BUFFER_SIZE - 1 + ld hl, wMailQueue + ld c, MAIL_QUEUE_BUFFER_SIZE - 1 + ; skip past other high priority mail .check_byte_loop - bit 7, [hl] + bit B_MAIL_PRIORITY_DELIVERY, [hl] jr z, .shift_loop inc hl dec c jr nz, .check_byte_loop .shift_loop ld b, [hl] - ld [hl], e + ld [hl], e ; at top of function, e was copied from input a (our new mail) ld e, b inc hl dec c @@ -5970,52 +7074,63 @@ Func_1f24e: pop af ret -Func_1f293: +DeliverMailFromQueue: push af push bc push de push hl - ld a, [wdd36] + ld a, [wNumMailInQueue] and a - jr z, .asm_1f2eb - ld a, $ff - ld [wdd5a], a - ld a, [wdd50] - cp $08 - jr z, .asm_1f2eb - ld de, wdd51 - ld hl, wdd37 - ld a, [wdd50] + jr z, .done + + ld a, NEW_MAIL + ld [wNewMail], a + ld a, [wMailCount] + cp MAIL_MAX_NUM + ; if the mailbox already has MAIL_MAX_NUM, can't deliver more mail + jr z, .done + + ld de, wMailList + ld hl, wMailQueue + ld a, [wMailCount] ld b, a - ld a, $08 + ld a, MAIL_MAX_NUM sub b - ld b, a - ld c, $00 -.asm_1f2b9 + ld b, a ; number of mail to insert + ld c, $00 ; counts how many times we insert mail in the loop + +.insert_new_mail_loop ld a, [hli] and a - jr z, .asm_1f2c6 - res 7, a - call .Func_1f2f6 + ; break the loop if the next mail in the queue is $00, i.e. we have drained the whole queue + jr z, .done_inserting_mail + ; reset bit 7, because when mail is in the mailbox it means it has been read (B_MAIL_READ) + res B_MAIL_PRIORITY_DELIVERY, a + call InsertNewMail inc c dec b - jr nz, .asm_1f2b9 -.asm_1f2c6 - ld a, [wdd50] + jr nz, .insert_new_mail_loop + ; fallthrough if b = 0; i.e. when we have filled up the mailbox again + +.done_inserting_mail + ; update the mail counts based on how many we inserted + ld a, [wMailCount] add c - ld [wdd50], a - ld a, [wdd36] + ld [wMailCount], a + ld a, [wNumMailInQueue] sub c - ld [wdd36], a - ld hl, wdd37 + ld [wNumMailInQueue], a + + ld hl, wMailQueue ld b, $00 add hl, bc - ld de, wdd37 - ld a, $18 + ld de, wMailQueue + ld a, MAIL_QUEUE_BUFFER_SIZE - 1 sub c ld c, a ld a, [hli] -.asm_1f2e2 + +.loop2 ld [de], a inc de ld b, [hl] @@ -6023,22 +7138,25 @@ Func_1f293: ld [hli], a ld a, b dec c - jr nz, .asm_1f2e2 -.asm_1f2eb - ld a, [wdd36] - ld [wdd5b], a + jr nz, .loop2 + +.done + ld a, [wNumMailInQueue] + ld [wTempNumMailInQueue], a pop hl pop de pop bc pop af ret -; shift data in de 1 byte right -.Func_1f2f6: +; a - new mail to add +; de - wMailList +; Shifts the mail list one byte to the right, and inserts (a) at the front +InsertNewMail: push bc push de push hl - ld c, $08 + ld c, MAIL_MAX_NUM .loop ld l, a ld a, [de] @@ -6055,33 +7173,36 @@ Func_1f293: ret Func_1f309: - ld a, [wdd5a] + ld a, [wNewMail] and a ret -Func_1f30e: +; de - card offset +SetBlackBoxCard: push af ld a, e - ld [wdd5f], a + ld [wBlackBoxCardReceived], a ld a, d - ld [wdd60], a + ld [wBlackBoxCardReceived + 1], a pop af ret -Func_1f319: +; de - card offset +SetBillsPCCard: push af ld a, e - ld [wdd73], a + ld [wBillsPCCardReceived], a ld a, d - ld [wdd74], a + ld [wBillsPCCardReceived + 1], a pop af ret -Func_1f324: +; set carry if there is a black box card +CheckForBlackBoxCardInMail: push bc - ld a, [wdd5f] + ld a, [wBlackBoxCardReceived] ld b, a - ld a, [wdd60] + ld a, [wBlackBoxCardReceived + 1] or b scf jr nz, .asm_1f331 @@ -6090,11 +7211,12 @@ Func_1f324: pop bc ret -Func_1f333: +; set carry if there is a bill's pc card +CheckForBillsPCCardInMail: push bc - ld a, [wdd73] + ld a, [wBillsPCCardReceived] ld b, a - ld a, [wdd74] + ld a, [wBillsPCCardReceived + 1] or b scf jr nz, .asm_1f340 @@ -6102,9 +7224,21 @@ Func_1f333: .asm_1f340 pop bc ret -; 0x1f342 -SECTION "Bank 7@757b", ROMX[$757b], BANK[$7] +; return +; a - position in the mail list of the currently selected mail item +GetSelectedMailPosition: + push bc + ld a, [wMailboxPage] + add a + add a + ld b, a + ld a, [wSelectedMailCursorPosition] + add b + pop bc + ret + +INCLUDE "data/mail.asm" Func_1f57b:: push af @@ -6650,9 +7784,9 @@ Func_1f8f7: jr c, .asm_1f914 ldtx hl, GameCenterToBeMailedText_2 farcall PrintScrollableText_NoTextBoxLabelVRAM0 - call Func_1f319 - ld a, $82 - call Func_1f24e + call SetBillsPCCard + ld a, $82 ; priority bill's PC mail + call AddMailToQueue .asm_1f914 farcall FadeToWhiteAndUnsetFrameFunc pop hl diff --git a/src/engine/bank09.asm b/src/engine/bank09.asm index f80fcb3..da77a82 100644 --- a/src/engine/bank09.asm +++ b/src/engine/bank09.asm @@ -2185,7 +2185,7 @@ CheckDeck: ; of each type there are (Basic, Stage1, Stage2, Energy, Trainer) ; and within Energy cards, count each color as well ; outputs all results in wDeckCheckCardCounts -.GetDeckCardCounts: +.GetDeckCardCounts ld e, l ld d, h ld hl, wPlayerDeck @@ -2195,6 +2195,7 @@ CheckDeck: call DisableSRAM pop hl +.asm_25461 push hl ld hl, wDeckCheckCardCounts ld c, wDeckCheckCardCountsEnd - wDeckCheckCardCounts @@ -4855,7 +4856,7 @@ Func_2612a: ldtx hl, GameCenterBillsPCStartPromptText call YesOrNoMenuWithText ret c - farcall Func_1f333 + farcall CheckForBillsPCCardInMail ldtx hl, GameCenterBillsPCUnableLastOutputRemainingText jr c, .asm_2619a farcall GetGameCenterChips diff --git a/src/engine/bank0a.asm b/src/engine/bank0a.asm index f182862..4e5fda3 100644 --- a/src/engine/bank0a.asm +++ b/src/engine/bank0a.asm @@ -3531,7 +3531,7 @@ Func_2bc4f: ld [hl], d ld a, $ff ; all decks - farcall DrawDeckSelectionMenu + farcall DrawDecksScreen xor a .asm_2bc5c ld hl, .MenuParameters @@ -3543,7 +3543,7 @@ Func_2bc4f: call DrawWideTextBox_PrintText .loop_input call DoFrame - farcall Func_8fb9 + farcall HandleStartButtonInDeckSelectionMenu jr c, .asm_2bc5c call HandleMenuInput jp nc, .loop_input ; can be jr @@ -3558,7 +3558,7 @@ Func_2bc4f: farcall CheckIfCurDeckIsEmpty jp nc, .valid ; can be jr ; deck is empty - farcall Func_9215 + farcall PrintThereIsNoDeckHereText jr .asm_2bc5c .valid diff --git a/src/engine/bank0b.asm b/src/engine/bank0b.asm index a80ef61..2e7a5ab 100644 --- a/src/engine/bank0b.asm +++ b/src/engine/bank0b.asm @@ -69,7 +69,7 @@ Func_2c0c8: Func_2c0d1: xor a start_script - script_command_64 $11 + send_mail $11 end_script ld a, EVENT_F5 farcall GetEventValue @@ -700,7 +700,7 @@ Func_2c584: xor a start_script wait_for_fade - script_command_64 $13 + send_mail $13 set_event EVENT_MET_GR4_LIGHTNING_CLUB set_active_npc NPC_GR_4, DialogGR4Text script_command_01 @@ -6031,7 +6031,7 @@ Func_2ed37: Func_2ed3e: xor a start_script - script_command_64 $12 + send_mail $12 end_script call WaterClubEntrance_ShouldRonaldAppear jr c, .quit @@ -6529,7 +6529,7 @@ Script_2f127: reset_event EVENT_TALKED_TO_KEN reset_event EVENT_TALKED_TO_ADAM reset_event EVENT_TALKED_TO_GR3_WATER_CLUB - script_command_64 $05 + send_mail $05 print_npc_text Text0833 script_command_02 set_active_npc_direction WEST @@ -7128,7 +7128,7 @@ Func_2f56e: Func_2f575: xor a start_script - script_command_64 $12 + send_mail $12 end_script call FireClubEntrance_ShouldRonaldAppear jr c, .quit @@ -8024,7 +8024,7 @@ Func_2fc29: ret Script_2fc3e: - script_command_64 $09 + send_mail $09 set_event EVENT_GOT_GR_COIN_PIECE_BOTTOM_LEFT print_npc_text Text0c6e give_coin COIN_GR_START + COIN_GR_PIECE3 diff --git a/src/engine/bank0c.asm b/src/engine/bank0c.asm index 0658031..b0b8bbe 100644 --- a/src/engine/bank0c.asm +++ b/src/engine/bank0c.asm @@ -234,7 +234,7 @@ Func_30192: Func_301c0: farcall Func_d683 - farcall Func_1f293 + farcall DeliverMailFromQueue call WaitPalFading .loop call DoFrame @@ -1784,7 +1784,7 @@ Func_317eb: ld a, [wd584] cp MAP_GRASS_FORT_ENTRANCE jr nz, .asm_317f6 - farcall Func_1f293 + farcall DeliverMailFromQueue .asm_317f6 ld bc, $3b ld a, $14 @@ -2552,7 +2552,7 @@ Func_31da0: script_jump_if_b0nz .ows_31dcb ask_question Text11ae, TRUE script_jump_if_b0z .ows_31dcb - script_command_64 $15 + send_mail $15 set_event EVENT_LIGHTNING_FORT_ENTRANCE_DOOR_STATE script_command_02 play_sfx SFX_DOORS @@ -2849,7 +2849,7 @@ Func_32016: ld a, [wd584] cp MAP_LIGHTNING_FORT_ENTRANCE jr nz, .asm_32021 - farcall Func_1f293 + farcall DeliverMailFromQueue .asm_32021 ld a, EVENT_RENNAS_ROOM_DOOR_STATE farcall GetEventValue @@ -3502,7 +3502,7 @@ Func_324e1: set_event EVENT_BEAT_CATHERINE set_var VAR_30, $01 set_var VAR_33, $00 - script_command_64 $07 + send_mail $07 print_npc_text Text11d6 give_booster_packs BoosterList_cd63 script_jump .ows_32524 @@ -3692,7 +3692,7 @@ Func_32664: script_jump_if_b0nz .ows_3268f ask_question Text0c83, TRUE script_jump_if_b0z .ows_3268f - script_command_64 $16 + send_mail $16 set_event EVENT_FIRE_FORT_ENTRANCE_DOOR_STATE script_command_02 play_sfx SFX_DOORS @@ -3936,7 +3936,7 @@ Func_3286d: ld a, [wd584] cp MAP_FIRE_FORT_ENTRANCE jr nz, .asm_32878 - farcall Func_1f293 + farcall DeliverMailFromQueue .asm_32878 ld a, EVENT_JES_ROOM_DOOR_STATE farcall GetEventValue @@ -5061,7 +5061,7 @@ Func_3308e: script_jump_if_b0nz .ows_330b9 ask_question Text1215, TRUE script_jump_if_b0z .ows_330b9 - script_command_64 $17 + send_mail $17 set_event EVENT_WATER_FORT_ENTRANCE_DOOR_STATE script_command_02 play_sfx SFX_DOORS @@ -5127,7 +5127,7 @@ Func_33129: ld a, [wd584] cp MAP_WATER_FORT_ENTRANCE jr nz, .asm_33134 - farcall Func_1f293 + farcall DeliverMailFromQueue .asm_33134 ld a, EVENT_MIYAJIMAS_ROOM_DOOR_STATE farcall GetEventValue @@ -5632,7 +5632,7 @@ Func_334b3: ret Script_334f6: - script_command_64 $18 + send_mail $18 script_command_02 play_sfx SFX_DOORS load_tilemap TILEMAP_094, $04, $07 diff --git a/src/engine/bank0d.asm b/src/engine/bank0d.asm index ccba43a..6b10327 100644 --- a/src/engine/bank0d.asm +++ b/src/engine/bank0d.asm @@ -1,7 +1,7 @@ Script_34000: wait_for_fade set_var VAR_TIMES_MET_RONALD, $01 - script_command_64 $10 + send_mail $10 set_active_npc NPC_RONALD, DialogRonaldText move_player .NPCMovement_34031, TRUE wait_for_player_animation @@ -265,7 +265,7 @@ Func_341f7: xor a start_script wait_for_fade - script_command_64 $06 + send_mail $06 set_var VAR_TIMES_MET_RONALD, $04 set_var VAR_28, $01 set_var VAR_2B, $00 @@ -394,7 +394,7 @@ Func_342ef: xor a start_script wait_for_fade - script_command_64 $14 + send_mail $14 set_var VAR_TIMES_MET_RONALD, $05 load_npc NPC_GR_X, 4, 15, SOUTH set_active_npc NPC_GR_X, DialogGRXText @@ -561,8 +561,8 @@ Func_3442d: xor a start_script wait_for_fade - script_command_64 $19 - script_command_64 $1a + send_mail $19 + send_mail $1a set_var VAR_TIMES_MET_RONALD, $07 script_command_01 print_npc_text Text1285 @@ -601,7 +601,7 @@ Func_3442d: Func_3448d: xor a start_script - script_command_64 $1b + send_mail $1b set_var VAR_TIMES_MET_RONALD, $08 play_song_next MUSIC_RONALD do_frames 60 @@ -1705,8 +1705,8 @@ Func_34d15: farcall Func_1312e jr c, .asm_34d2f farcall Func_4569f - ld a, $81 - farcall Func_1f24e + ld a, $81 ; priority black box mail + farcall AddMailToQueue .asm_34d2f ld a, $00 ld [wd582], a @@ -2830,7 +2830,7 @@ Func_35596: script_jump_if_b0nz .ows_355b4 set_event EVENT_BEAT_MORINO reset_event EVENT_TALKED_TO_MORINO - script_command_64 $0a + send_mail $0a print_npc_text Text0dc0 give_booster_packs BoosterList_cd59 script_jump .ows_355d1 @@ -3409,7 +3409,7 @@ Func_35a0d: ld a, [wd584] cp MAP_FIGHTING_FORT_ENTRANCE jr nz, .asm_35a18 - farcall Func_1f293 + farcall DeliverMailFromQueue .asm_35a18 ld a, EVENT_BEAT_KAMIYA farcall GetEventValue @@ -3630,7 +3630,7 @@ Func_35b82: end_script ret .ows_35bbf - script_command_64 $0b + send_mail $0b set_event EVENT_GOT_MACHAMP_COIN print_npc_text Text0c25 give_coin COIN_MACHAMP @@ -4628,7 +4628,7 @@ Func_3639f: ld a, [wd584] cp MAP_PSYCHIC_STRONGHOLD_ENTRANCE jr nz, .asm_363aa - farcall Func_1f293 + farcall DeliverMailFromQueue .asm_363aa xor a start_script @@ -6205,7 +6205,7 @@ Func_36fe9: ret Func_36ff2: - farcall Func_1f293 + farcall DeliverMailFromQueue ld a, EVENT_MET_COLORLESS_ALTAR_MEMBERS farcall GetEventValue jr nz, .asm_3700f @@ -7044,7 +7044,7 @@ Func_3766c: ld a, [wd584] cp MAP_GR_CASTLE_ENTRANCE jr nz, .asm_37677 - farcall Func_1f293 + farcall DeliverMailFromQueue .asm_37677 ld a, EVENT_MET_BIRURITCHI_AND_ADMINS farcall GetEventValue diff --git a/src/engine/bank0e.asm b/src/engine/bank0e.asm index 8143332..f8562b8 100644 --- a/src/engine/bank0e.asm +++ b/src/engine/bank0e.asm @@ -4857,7 +4857,7 @@ Func_3ada1: inc hl ld [hl], d call ClearScreenAndDrawDeckMachineScreen - ld a, $32 + ld a, NUM_DECK_SAVE_MACHINE_SLOTS ld [wNumDeckMachineEntries], a xor a .asm_3adb7 @@ -4877,22 +4877,22 @@ Func_3ada1: ld a, [wScrollMenuScrollOffset] add b ld [wSelectedDeckMachineEntry], a - farcall Func_9287 + farcall ResetCheckMenuCursorPositionAndBlink call DrawWideTextBox ld hl, $6e7b call PlaceTextItems .asm_3aded: call DoFrame - farcall Func_9292 + farcall HandleCheckMenuInput jp nc, .asm_3aded cp $ff jr nz, .asm_3ae01 ld a, [wTempScrollMenuItem] jp .asm_3adb7 .asm_3ae01 - ld a, [wMusicStereoPanningBackup] + ld a, [wCheckMenuCursorYPosition] sla a - ld hl, wCurSongBankBackup + ld hl, wCheckMenuCursorXPosition add [hl] or a jr nz, .asm_3ae33 @@ -5133,7 +5133,7 @@ CopyBBytesFromHLToDE_Bank0e: jr nz, .loop ret -Func_3afb1: +CopyListFromHLToDE_Bank0e: .asm_3afb1 ld a, [hli] ld [de], a @@ -5636,7 +5636,7 @@ SECTION "Bank e@72db", ROMX[$72db], BANK[$e] Func_3b2db: ld a, $ff - farcall DrawDeckSelectionMenu + farcall DrawDecksScreen xor a .asm_3b2e2 ld hl, $735e @@ -5645,7 +5645,7 @@ Func_3b2db: call DrawWideTextBox_PrintText .asm_3b2ee call DoFrame - farcall Func_8fb9 + farcall HandleStartButtonInDeckSelectionMenu jr c, .asm_3b2e2 call HandleMenuInput jp nc, .asm_3b2ee @@ -5655,7 +5655,7 @@ Func_3b2db: ld [wCurDeck], a farcall CheckIfCurDeckIsEmpty jp nc, Func_3b315 - farcall Func_9215 + farcall PrintThereIsNoDeckHereText ld a, [wCurDeck] jr .asm_3b2e2 @@ -5871,7 +5871,7 @@ Func_3b45f: ldtx hl, YouMayOnlyCarry4DecksText call DrawWideTextBox_WaitForInput ld a, $ff - farcall DrawDeckSelectionMenu + farcall DrawDecksScreen xor a .asm_3b46c ld hl, $735e @@ -5880,7 +5880,7 @@ Func_3b45f: call DrawWideTextBox_PrintText .asm_3b478 call DoFrame - farcall Func_8fb9 + farcall HandleStartButtonInDeckSelectionMenu jr c, .asm_3b46c call HandleMenuInput jp nc, .asm_3b478 @@ -5901,18 +5901,18 @@ Func_3b45f: push hl ld de, wd47e call EnableSRAM - call Func_3afb1 + call CopyListFromHLToDE_Bank0e pop hl push hl ld bc, $18 add hl, bc - farcall Func_9397 + farcall AddDeckToCollection pop hl ld a, $60 farcall ClearNBytesFromHL call DisableSRAM ld a, $ff - farcall DrawDeckSelectionMenu + farcall DrawDecksScreen ld a, [wCurDeck] ld hl, $735e call InitializeMenuParameters @@ -6001,7 +6001,7 @@ Func_3b4eb: call CopyBBytesFromHLToDE_Bank0e call DisableSRAM ld a, $ff - farcall DrawDeckSelectionMenu + farcall DrawDecksScreen ld a, [wd496] ld [wCurDeck], a ld hl, $735e @@ -6042,7 +6042,7 @@ Func_3b4eb: Func_3b5f1: call Func_3bcd6 - farcall DrawDeckSelectionMenu + farcall DrawDecksScreen ldtx hl, DismantleTheseDecksPromptText call YesOrNoMenuWithText jr nc, .asm_3b601 @@ -6075,7 +6075,7 @@ Func_3b5f1: .asm_3b634 call DisableSRAM ld a, [wd49a] - farcall DrawDeckSelectionMenu + farcall DrawDecksScreen ldtx hl, DismantledTheseDecksText call DrawWideTextBox_WaitForInput or a @@ -6090,7 +6090,7 @@ Func_3b646: push hl ld bc, $18 add hl, bc - farcall Func_9397 + farcall AddDeckToCollection pop hl ld a, $60 farcall ClearNBytesFromHL @@ -6134,7 +6134,7 @@ Func_3b661: ld de, wCurDeckCards ld b, $80 call CopyBBytesFromHLToDE_Bank0e - farcall Func_9a0f + farcall CheckIfThereAreAnyBasicCardsInDeck jr c, .asm_3b6c0 ldtx hl, CannotBuildLackingBasicPokemonText call DrawWideTextBox_WaitForInput @@ -6914,7 +6914,7 @@ Func_3bb09: ld a, [wScrollMenuScrollOffset] add b ld [wSelectedDeckMachineEntry], a - farcall Func_9287 + farcall ResetCheckMenuCursorPositionAndBlink xor a ld [wd0cd], a call DrawWideTextBox @@ -6929,7 +6929,7 @@ Func_3bb09: ld a, [wTempScrollMenuItem] jp .asm_3bb30 .asm_3bbe6 - ld a, [wMusicStereoPanningBackup] + ld a, [wCheckMenuCursorYPosition] sla a ld hl, wCurSongBankBackup add [hl] @@ -7101,6 +7101,96 @@ Func_3bd3b: ret ; 0x3bd5c +SECTION "Bank e@7e8d", ROMX[$7e8d], BANK[$e] + +SaveDeckDataToWRAM2: + push de + ld de, wc000 + call CopyListFromHLToDE_Bank0e + pop de + ld hl, wc000 + DECK_NAME_SIZE + bank1call SaveDeckCards + call SwitchToWRAM2 + ld hl, wc000 + ld de, w2d28e + ld b, DECK_COMPRESSED_STRUCT_SIZE + call CopyBBytesFromHLToDE_Bank0e + call SwitchToWRAM1 + ret + +OpenDeckSaveMachineFromDeckBuilding: + ld a, [wCurDeck] + push af + xor a + ld [wScrollMenuScrollOffset], a + ldtx de, DeckSaveMachineText + ld hl, wDeckMachineTitleText + ld [hl], e + inc hl + ld [hl], d + call ClearScreenAndDrawDeckMachineScreen + ld a, NUM_DECK_SAVE_MACHINE_SLOTS + ld [wNumDeckMachineEntries], a + xor a +.wait_input + ld hl, DeckMachineSelectionParams + farcall InitializeScrollMenuParameters + call DrawListScrollArrows + call PrintNumSavedDecks + ldtx hl, PleaseSelectDeckText + call DrawWideTextBox_PrintText + ldtx de, PleaseSelectDeckText + call InitDeckMachineDrawingParams + call HandleDeckMachineSelection + jr c, .wait_input + cp $ff + jr z, .cancel + ld b, a + ld a, [wScrollMenuScrollOffset] + add b + ld [wSelectedDeckMachineEntry], a + call CheckIfSelectedDeckMachineEntryIsEmpty + jr c, .save_deck + ldtx hl, DeleteSavedDeckPromptText + call YesOrNoMenuWithText + ld a, [wTempScrollMenuItem] + jr c, .wait_input +.save_deck + call GetSelectedSavedDeckPtr + ld d, h + ld e, l + ld hl, w2d28e + ld b, DECK_COMPRESSED_STRUCT_SIZE + call EnableSRAM + call SwitchToWRAM2 + call CopyBBytesFromHLToDE_Bank0e + call SwitchToWRAM1 + call DisableSRAM + call ClearScreenAndDrawDeckMachineScreen + call DrawListScrollArrows + call PrintNumSavedDecks + ld a, [wTempScrollMenuItem] + ld hl, DeckMachineSelectionParams + farcall InitializeScrollMenuParameters + call HandleScrollMenu.draw_visible_cursor + pop af + ld [wCurDeck], a + farcall GetSRAMPointerToCurDeck + call EnableSRAM + farcall CopyDeckName + call DisableSRAM + xor a + ld [wTxRam2], a + ld [wTxRam2 + 1], a + ldtx hl, SavedDeckToMachineText + call DrawWideTextBox_WaitForInput + ret +.cancel + pop af + ld [wCurDeck], a + ret +; 0x3bf55 + SECTION "Bank e@7f5e", ROMX[$7f5e], BANK[$e] Func_3bf5e: diff --git a/src/engine/bank0f.asm b/src/engine/bank0f.asm index e3e37c5..67131b6 100644 --- a/src/engine/bank0f.asm +++ b/src/engine/bank0f.asm @@ -230,7 +230,7 @@ Func_3c1d0: ask_question BattleCenterBeginPromptText, TRUE script_jump_if_b0z .ows_3c20b play_song MUSIC_CARD_POP - script_command_64 $1c + send_mail $1c script_command_02 link_duel script_jump_if_b1nz .ows_3c204 @@ -346,7 +346,7 @@ Func_3c1d0: get_var VAR_20 compare_loaded_var $05 script_jump_if_b0z .ows_3c2d8 - script_command_64 $0f + send_mail $0f .ows_3c2d8 script_ret diff --git a/src/engine/bank10.asm b/src/engine/bank10.asm index f5c025c..46636a6 100644 --- a/src/engine/bank10.asm +++ b/src/engine/bank10.asm @@ -860,7 +860,7 @@ Func_4053e: HandleTCGIslandInput: farcall Func_d683 - farcall Func_1f293 + farcall DeliverMailFromQueue call WaitPalFading .loop_input call DoFrame @@ -1514,9 +1514,9 @@ Func_40f46: wait_for_player_animation set_active_npc NPC_DR_MASON, DialogDrMasonText script_command_01 - script_command_64 $03 - script_command_64 $04 - script_command_64 $08 + send_mail $03 + send_mail $04 + send_mail $08 set_event EVENT_GOT_CHANSEY_COIN script_call .ows_40f83 script_call .ows_40fac @@ -1647,7 +1647,7 @@ Func_4101d: start_script set_event EVENT_EB set_var VAR_34, $01 - script_command_64 $0d + send_mail $0d end_script farcall Func_eff7 jr .asm_41073 @@ -3420,7 +3420,7 @@ Func_41d64: script_command_02 script_jump .ows_41d99 .ows_41d94 - script_command_64 $0e + send_mail $0e script_jump .ows_41d88 .ows_41d99 end_script @@ -5719,7 +5719,7 @@ Func_42fe1: script_jump Script_432a0 Script_43000: - script_command_64 $0c + send_mail $0c play_song_next MUSIC_HALL_OF_HONOR script_command_02 print_npc_text Text0927 diff --git a/src/engine/bank11.asm b/src/engine/bank11.asm index 5c0f369..64961d5 100644 --- a/src/engine/bank11.asm +++ b/src/engine/bank11.asm @@ -2023,7 +2023,7 @@ Func_456de: ld a, [hli] ld e, a ld d, [hl] - ld hl, wdd5f + ld hl, wBlackBoxCardReceived ld c, $03 .asm_45734 ld a, e @@ -2057,7 +2057,7 @@ Func_456de: ld a, [hli] ld e, a ld d, [hl] - ld hl, wdd5f + ld hl, wBlackBoxCardReceived ld c, $05 .asm_4576b ld a, e @@ -2080,7 +2080,7 @@ Func_456de: ld a, [hli] ld e, a ld d, [hl] - ld hl, wdd5f + ld hl, wBlackBoxCardReceived ld a, e ld [hli], a ld a, d @@ -2107,7 +2107,7 @@ Func_456de: ld a, [hli] ld e, a ld d, [hl] - ld hl, wdd5f + ld hl, wBlackBoxCardReceived ld a, e ld [hli], a ld a, d @@ -2137,7 +2137,7 @@ Func_456de: ld a, [hli] ld e, a ld d, [hl] - ld hl, wdd5f + ld hl, wBlackBoxCardReceived ld a, e ld [hli], a ld a, d @@ -2215,7 +2215,7 @@ Func_457ea: ld a, [hli] ld e, a ld d, [hl] - ld hl, wdd5f + ld hl, wBlackBoxCardReceived .asm_45858 ld a, e ld [hli], a @@ -2234,7 +2234,7 @@ Func_457ea: Func_45868: xor a - ld hl, wdd5f + ld hl, wBlackBoxCardReceived ld [hli], a ld [hl], a ld hl, BlackboxPromoCards @@ -2262,7 +2262,7 @@ Func_45868: ld a, [hld] ld d, a push hl - ld hl, wdd5f + ld hl, wBlackBoxCardReceived call AppendCardToListInHL ld hl, wCurDeckCards call Func_443bd @@ -2287,7 +2287,7 @@ Func_45868: or e jr z, .asm_458be push hl - ld hl, wdd5f + ld hl, wBlackBoxCardReceived call AppendCardToListInHL pop hl jr .asm_458ad @@ -2296,7 +2296,7 @@ Func_45868: Func_458bf: xor a - ld hl, wdd5f + ld hl, wBlackBoxCardReceived ld [hli], a ld [hl], a ld hl, wCurDeckCards @@ -2319,7 +2319,7 @@ Func_458bf: jr c, .asm_458c8 .asm_458e7 push hl - ld hl, wdd5f + ld hl, wBlackBoxCardReceived call AppendCardToListInHL pop hl jr .asm_458c8 @@ -2387,7 +2387,7 @@ Func_458bf: cp $02 jp nc, .asm_4593a push hl - ld hl, wdd5f + ld hl, wBlackBoxCardReceived call AppendCardToListInHL pop hl jr .asm_4593a @@ -2496,7 +2496,7 @@ Func_458bf: ld a, [hli] ld e, a ld d, [hl] - ld hl, wdd5f + ld hl, wBlackBoxCardReceived call AppendCardToListInHL dec c jr nz, .asm_459f7 @@ -2534,7 +2534,7 @@ Func_458bf: ld a, [hli] ld e, a ld d, [hl] - ld hl, wdd5f + ld hl, wBlackBoxCardReceived call AppendCardToListInHL dec c jr nz, .asm_45a3c @@ -2572,7 +2572,7 @@ Func_458bf: ld a, [hli] ld e, a ld d, [hl] - ld hl, wdd5f + ld hl, wBlackBoxCardReceived call AppendCardToListInHL dec c jr nz, .asm_45a81 @@ -2580,7 +2580,7 @@ Func_458bf: ret .asm_45a9c call Func_45bc3 - ld hl, wdd5f + ld hl, wBlackBoxCardReceived ld de, $a call AppendCardToListInHL jr .asm_45a9b @@ -2757,7 +2757,7 @@ Func_45bc3: push de push hl ld hl, wCurDeckCards - ld de, wdd5f + ld de, wBlackBoxCardReceived ld bc, $c call CopyDataHLtoDE_SaveRegisters pop hl diff --git a/src/engine/credits_commands.asm b/src/engine/credits_commands.asm index 05c01cd..edfffb5 100644 --- a/src/engine/credits_commands.asm +++ b/src/engine/credits_commands.asm @@ -344,7 +344,7 @@ Func_13ac1:: CreditsCmd_WaitInput: ld a, [wCreditsCmdArg1] ld c, a - call Func_10221 + call WaitForButtonPress ret CreditsCmd_MusicFadeOut: diff --git a/src/home/unsorted.asm b/src/home/unsorted.asm index 9dc9b08..82cba78 100644 --- a/src/home/unsorted.asm +++ b/src/home/unsorted.asm @@ -2664,8 +2664,8 @@ LoadScene:: farcall _LoadScene ret -Func_3e75:: - farcall $7, $6f2a +UpdateMailboxPage:: + farcall _UpdateMailboxPage ret Func_3e7a:: diff --git a/src/macros.asm b/src/macros.asm index 796b079..41238c9 100644 --- a/src/macros.asm +++ b/src/macros.asm @@ -4,6 +4,7 @@ INCLUDE "macros/code.asm" INCLUDE "macros/data.asm" INCLUDE "macros/animations.asm" INCLUDE "macros/map.asm" +INCLUDE "macros/menu.asm" INCLUDE "macros/scripts.asm" INCLUDE "macros/text.asm" INCLUDE "macros/wram.asm" diff --git a/src/macros/menu.asm b/src/macros/menu.asm new file mode 100644 index 0000000..0729bae --- /dev/null +++ b/src/macros/menu.asm @@ -0,0 +1,39 @@ +/* + \1 ; cursor x coordinate - int + \2 ; cursor y coordinate - int + \3 ; y displacement between items - int + \4 ; number of items - int + \5 ; cursor tile number - SYM_*, usually SYM_CURSOR_R + \6 ; tile behind cursor - SYM_*, usually SYM_SPACE + \7 ; function pointer if non-0 - function ptr or NULL + +8 bytes. Used by InitializeMenuParameters. +*/ +MACRO menu_parameters + db \1, \2, \3, \4, \5, \6 + dw \7 +ENDM + +/* + \1 ; skip clear - TRUE or FALSE + \2 ; width - int + \3 ; height - int + \4 ; blink cursor symbol - SYM_*, usually SYM_CURSOR_R + \5 ; space symbol - SYM_*, usually SYM_SPACE + \6 ; default cursor symbol - SYM_*, usually SYM_CURSOR_R + \7 ; selection cursor symbol - SYM_*, usually SYM_CURSOR_R + \8 ; press keys - PAD_*, usually PAD_A + \9 ; held keys - PAD_*, usually PAD_B + \10 ; has horizontal scroll - TRUE or FALSE + \11 ; vertical step - int + \12 ; update function - function ptr or NULL + \13 ; label text ID - text ptr or NULL + +15 bytes. Used by LoadMenuBoxParams. +Usually followed by a list of textitem macros, then $ff +*/ +MACRO menu_box_params + db \1, \2, \3, \4, \5, \6, \7, \8, \9, \<10>, \<11> + dw \<12> + tx \<13> +ENDM \ No newline at end of file diff --git a/src/macros/scripts.asm b/src/macros/scripts.asm index dc51c9b..2f04014 100644 --- a/src/macros/scripts.asm +++ b/src/macros/scripts.asm @@ -107,7 +107,7 @@ ENDM const ScriptCommand_SetTextRAM2b_index ; $61 const ScriptCommand_SetVariableTextRAM2b_index ; $62 const ScriptCommand_ReplaceNPC_index ; $63 - const ScriptCommand_64_index ; $64 + const ScriptCommand_SendMail_index ; $64 const ScriptCommand_CheckNPCLoaded_index ; $65 const ScriptCommand_GiveDeck_index ; $66 const ScriptCommand_67_index ; $67 @@ -664,8 +664,8 @@ MACRO replace_npc db \2 ; npc to load ENDM -MACRO script_command_64 - run_command ScriptCommand_64 +MACRO send_mail + run_command ScriptCommand_SendMail db \1 ENDM diff --git a/src/sram.asm b/src/sram.asm index 1975cfa..524ec66 100644 --- a/src/sram.asm +++ b/src/sram.asm @@ -71,10 +71,11 @@ ENDR sCurrentlySelectedDeck:: ; b7a0 ds $1 -s0b7a1:: ; b7a1 - ds $1 - - ds $1 +; keeps track of how many unnamed decks have been built +; as they suffix the number ### in the form of "の###デッキ" +; max number is MAX_UNNAMED_DECK_NUM +sUnnamedDeckCounter:: ; b7a1 + ds $2 ; each bit represents whether the player has ; obtained a card from a given set diff --git a/src/wram.asm b/src/wram.asm index 08dd6b9..3cabd9a 100644 --- a/src/wram.asm +++ b/src/wram.asm @@ -1819,6 +1819,8 @@ wNamingScreenCursorBlinkCounter:: ; d0e3 ; to check whether a new filter is to be applied wTempCardTypeFilter:: ; d0e4 +wCardListCursorPos:: ; d0e4 + wCurScrollMenuItem:: ; d0e4 wNamingScreenCursorY:: ; d0e4 @@ -1861,8 +1863,11 @@ wNumEntriesInCurFilter:: wBoosterPackCardListSize:: ; d0ee ds $1 -wd0ef:: ; d0ef - ds $2 +wCheckMenuCursorXPosition:: ; d0ef + ds $1 + +wCheckMenuCursorYPosition:: ; d0f0 + ds $1 ; deck selected by the player in the Decks screen wCurDeck:: ; d0f1 @@ -1940,7 +1945,7 @@ wCurCardTypeFilter:: ; d11a wTempCurMenuItem:: ; d11b ds $1 -wd11c:: ; d11c +wTempFilteredCardListNumCursorPositions:: ; d11c ds $1 ds $1 @@ -1948,7 +1953,7 @@ wd11c:: ; d11c wced7:: ; d11e ds $1 -wd11f:: ; d11f +wCardListVisibleOffsetBackup:: ; d11f ds $1 ; stores how many different cards there are in a deck @@ -2014,13 +2019,22 @@ wd381:: ; d381 wSameNameCardsLimit:: ; d382 ds $1 -wd383:: ; d383 +; whether to include the cards in the selected deck +; to appear in the filtered lists +; is TRUE when building a deck (since the cards should be shown for removal) +; is FALSE when choosing a deck configuration to send through Gift Center +; (can't select cards that are included in already built decks) +wIncludeCardsInDeck:: ; d383 ds $1 -wd384:: ; d384 +; pointer to a function that handles the menu +; when building a deck configuration +wDeckConfigurationMenuHandlerFunction:: ; d384 ds $2 -wd386:: ; d386 +; pointer to a transition table for the +; function in wDeckConfigurationMenuHandlerFunction +wDeckConfigurationMenuTransitionTable:: ; d386 ds $2 wCurCardListPtr:: ; d388 @@ -2106,6 +2120,8 @@ wNamingScreenNamePosition:: ; d3e9 wNamingScreenMode:: ; d3eb ds $1 +; see also sUnnamedDeckCounter +wTempUnnamedDeckCounter:: ; d3ec ds $3 wd3ef:: ; d3ef @@ -2363,11 +2379,11 @@ wScriptNPC:: ; d60e wScriptNPCName:: ; d60f ds $2 -wd611:: ; d611 - ds $2 - -wd613:: ; d613 - ds $2 +; a bitmask for every unique mail in the game (29 total). +; the corresponding bit is set when a mail is sent, and mask is checked before sending +; mail in event scripts. Mail that is not sent via event script skips the check. +wSentMailBitmask:: ; d611 + ds $4 wd615:: ; d615 ds $1 @@ -3194,7 +3210,7 @@ wdd05:: ; dd05 wdd06:: ; dd06 ds $1 -wdd07:: ; dd07 +wMinicomMenuCursorPosition:: ; dd07 ds $1 wCurBoosterPack:: ; dd08 @@ -3245,48 +3261,69 @@ wdd2e:: ; dd2e wdd2f:: ; dd2f ds $1 - ds $6 - -wdd36:: ; dd36 +; id of the mail item being read +wMailId:: ; dd30 ds $1 -wdd37:: ; dd37 - ds wDD37_BUFFER_SIZE - -wdd50:: ; dd50 +; 0 - mailbox full, 1 - new mail, 2 - no new mail +wMailboxStatus:: ; dd31 ds $1 -wdd51:: ; dd51 - ds $9 +; text offset of the sender line. displayed when reading a mail +wMailSenderText:: ; dd32 + ds $2 -wdd5a:: ; dd5a +; text offset of the subject line. displayed when reading a mail +wMailSubjectText:: ; dd34 + ds $2 + +; number of minicom mail queued to be delivered. mail is delivered when changing OW locations +wNumMailInQueue:: ; dd36 ds $1 -wdd5b:: ; dd5b +; list of mail items queued to be delivered +wMailQueue:: ; dd37 + ds MAIL_QUEUE_BUFFER_SIZE + +; total number of mail in your mailbox +wMailCount:: ; dd50 ds $1 -wdd5c:: ; dd5c +; list of mail items in the player's mailbox. holds up to 8 mail. +; Each byte is the id of a mail item. +; When mail is read, $80 is added to the id +wMailList:: ; dd51 + ds MAIL_BUFFER_SIZE + +; $ff when the player has new mail. set to 0 when opening mincom mail menu. affects the mailbox animation +wNewMail:: ; dd5a ds $1 -wdd5d:: ; dd5d +; copied from wNumMailInQueue when visiting world map. +; cleared after viewing the mailbox screen once. +; used to show the "mailbox full" graphic +wTempNumMailInQueue:: ; dd5b ds $1 -wdd5e:: ; dd5e +; which page of mail you are viewing. 0 or 1 +wMailboxPage:: ; dd5c ds $1 -wdd5f:: ; dd5f +; the mail you have selected to read/delete +wSelectedMailCursorPosition:: ; dd5d ds $1 -wdd60:: ; dd60 +; 0 - read mail, 1 - delete mail, 2 - quit +wMailOptionSelected:: ; dd5e ds $1 - ds $12 +; card offsets. the cards mailed to you after using the Game Center black box +wBlackBoxCardReceived:: ; dd5f + ds BLACK_BOX_CARDS_BUFFER_SIZE -wdd73:: ; dd73 - ds $1 - -wdd74:: ; dd74 - ds $1 +; card offset. the card mailed to you after using the Game Center Bill's PC +wBillsPCCardReceived:: ; dd73 + ds $2 wdd75:: ; dd75 ds $1 diff --git a/tools/script_extractor.py b/tools/script_extractor.py index 3e4d86c..0b4b1f2 100644 --- a/tools/script_extractor.py +++ b/tools/script_extractor.py @@ -126,7 +126,7 @@ script_commands = { 0x61: { "name": "set_text_ram2b", "params": [ "text" ] }, 0x62: { "name": "set_variable_text_ram2b", "params": [ "text", "text" ] }, 0x63: { "name": "replace_npc", "params": [ "npc", "npc" ] }, - 0x64: { "name": "script_command_64", "params": [ "byte" ] }, # ? + 0x64: { "name": "send_mail", "params": [ "byte" ] }, # ? 0x65: { "name": "check_npc_loaded", "params": [ "npc" ] }, 0x66: { "name": "give_deck", "params": [ "deck" ] }, 0x67: { "name": "script_command_67", "params": [ "byte", "byte" ] }, # ?