From 2d65b27799730e4147bc2bf1df1a65b853e65d5c Mon Sep 17 00:00:00 2001 From: earthoul Date: Sun, 8 Feb 2026 00:11:48 +0900 Subject: [PATCH 1/9] Refactor Deck Save Machine engine --- src/constants/card_data_constants.asm | 6 + src/constants/menu_constants.asm | 12 + src/constants/sfx_constants.asm | 4 - src/engine/bank02.asm | 138 ++- src/engine/bank07.asm | 2 +- src/engine/bank0a.asm | 18 +- src/engine/bank0e.asm | 1353 ++++++++++++++----------- src/home/menus.asm | 6 +- src/wram.asm | 78 +- 9 files changed, 944 insertions(+), 673 deletions(-) diff --git a/src/constants/card_data_constants.asm b/src/constants/card_data_constants.asm index beba938..67e8260 100644 --- a/src/constants/card_data_constants.asm +++ b/src/constants/card_data_constants.asm @@ -7,6 +7,9 @@ DEF CARD_NOT_OWNED_F EQU 7 DEF CARD_NOT_OWNED EQU 1 << CARD_NOT_OWNED_F DEF CARD_COUNT_MASK EQU $7f +DEF CARD_COUNT_FROM_BUILT_DECKS EQU CARD_NOT_OWNED ; $80 +; on the other hand, counting all owned cards uses $0 and $ff inconsistently + ; sDeck* and generic deck constants DEF NUM_DECKS EQU 4 DEF DECK_NAME_SIZE EQU 24 @@ -17,7 +20,10 @@ DEF DECK_STRUCT_SIZE EQU DECK_NAME_SIZE + DECK_SIZE_BYTES DEF DECK_COMPRESSED_SIZE EQU ((DECK_SIZE + 7) / 8 + 1) * 8 DEF DECK_COMPRESSED_STRUCT_SIZE EQU DECK_NAME_SIZE + DECK_COMPRESSED_SIZE DEF DECK_CONFIG_BUFFER_SIZE EQU 80 +DEF DECK_TEMP_BUFFER_SIZE EQU 128 ; as DECK_COMPRESSED_STRUCT_SIZE + 32, DECK_SIZE_BYTES + 8, etc. +DEF DECK_BIG_TEMP_BUFFER_SIZE EQU 256 DEF MAX_NUM_SAME_NAME_CARDS EQU 4 +DEF MAX_NUM_SUB_ENERGY_CARDS EQU 9 DEF MAX_UNNAMED_DECK_NUM EQU 999 ; card data offsets (data/cards.asm and card_data_struct) diff --git a/src/constants/menu_constants.asm b/src/constants/menu_constants.asm index 80165d7..f0b4925 100644 --- a/src/constants/menu_constants.asm +++ b/src/constants/menu_constants.asm @@ -64,6 +64,13 @@ const MINICOMMENU_MAILBOX ; 1 const MINICOMMENU_CARD_ALBUM ; 2 +; deck save machine options + const_def + const DECKSAVEMACHINEMENU_SAVE ; 0 + const DECKSAVEMACHINEMENU_DELETE ; 1 + const DECKSAVEMACHINEMENU_BUILD ; 2 + const DECKSAVEMACHINEMENU_CANCEL ; 3 + ; mailbox options const_def const MAILBOXMENU_READ ; 0 @@ -99,6 +106,10 @@ const POPUPMENU_CARD_DUNGEON_QUEEN ; $9 const POPUPMENU_CARD_DUNGEON_PAWN ; $a +; for menu items, PlaySFXConfirmOrCancel, etc. +DEF MENU_CANCEL EQU -1 +DEF MENU_CONFIRM EQU 1 ; != -1, but uses 1 most of the time + ; filter types for CardTypeFilters ; used to categorise the different cards ; i.e. in the deck building screen @@ -121,6 +132,7 @@ DEF FILTER_ONLY_ENERGY EQU FILTER_ENERGY >> 4 ; 2, or any number > 1 DEF NUM_DECK_CONFIRMATION_VISIBLE_CARDS EQU 7 DEF NUM_FILTERED_LIST_VISIBLE_CARDS EQU 6 +DEF NUM_DECK_STATUS_LIST_VISIBLE_CARDS EQU 5 DEF NUM_DECK_SAVE_MACHINE_SLOTS EQU 50 DEF NUM_DECK_MACHINE_VISIBLE_DECKS EQU 5 diff --git a/src/constants/sfx_constants.asm b/src/constants/sfx_constants.asm index d334d20..0655e90 100644 --- a/src/constants/sfx_constants.asm +++ b/src/constants/sfx_constants.asm @@ -162,7 +162,3 @@ const SFX_GHOST_MASTER_DISAPPEAR ; $a0 DEF NUM_SFX EQU const_value - -; PlaySFXConfirmOrCancel args -DEF MENU_CANCEL EQU -1 -DEF MENU_CONFIRM EQU 1 ; != -1, but uses 1 most of the time diff --git a/src/engine/bank02.asm b/src/engine/bank02.asm index bb78577..5ce0fc7 100644 --- a/src/engine/bank02.asm +++ b/src/engine/bank02.asm @@ -1532,6 +1532,8 @@ DeckSelectScreenTextItems: textitem 12, 16, CancelDeckText textitems_end +; for X = [wCurDeck] + 1, +; return hl = sDeckX GetSRAMPointerToCurDeck: ld a, [wCurDeck] ld h, a @@ -1543,6 +1545,8 @@ GetSRAMPointerToCurDeck: pop de ret +; for X = [wCurDeck] + 1, +; return hl = sDeckXCards GetSRAMPointerToCurDeckCards: push af ld a, [wCurDeck] @@ -1689,7 +1693,7 @@ PlaySFXConfirmOrCancel: pop af ret -Func_9337: +DecrementDeckCardsInCollection_CopyDeckFromSRAM: push hl ld d, h ld e, l @@ -1749,7 +1753,7 @@ AddGiftCenterDeckCardsToCollection: push hl push de push bc - ld a, ALL_DECKS + ld a, $ff ; all owned cards call CreateCardCollectionListWithDeckCards pop bc pop de @@ -3585,10 +3589,10 @@ InitializeScrollMenuParameters: ret DeckMachineSelectionParams: - scrollmenu_params 1, 2, 2, 0, 5, SYM_CURSOR_R, SYM_SPACE, NULL -; 0x9eb5 + scrollmenu_params 1, 2, 2, 0, NUM_DECK_MACHINE_VISIBLE_DECKS, SYM_CURSOR_R, SYM_SPACE, NULL -SECTION "Bank 2@5ebe", ROMX[$5ebe], BANK[$2] +MenuParams_9eb5: + scrollmenu_params 1, 2, 2, 0, 4, SYM_CURSOR_R, SYM_SPACE, NULL HandleCardSelectionInput: xor a ; FALSE @@ -4336,7 +4340,7 @@ HandleDeckConfirmationMenu: ld a, MENU_CONFIRM call PlaySFXConfirmOrCancel ld a, [wCurScrollMenuItem] - ld [wced7], a + ld [wd11e], a ; set wOwnedCardsCountList as current card list ; and show card page screen @@ -4913,7 +4917,7 @@ GetCardTypeIconPalette: ; uses deck builder ui HandleGiftCenterSendCardsScreen: ld hl, wCurDeckCards - ld a, $81 + ld a, DECK_TEMP_BUFFER_SIZE + 1 call ClearNBytesFromHL ld a, $ff ld [wCurDeck], a @@ -5004,7 +5008,7 @@ HandleGiftCenterSendCardsMenu: call InitializeScrollMenuParameters ld hl, wCurDeckCards ld de, wTempSavedDeckCards - ld b, $82 + ld b, DECK_TEMP_BUFFER_SIZE + 2 call CopyBBytesFromHLToDE_Bank02 call PrintCardsToSendToPlayerText call Func_b81d @@ -5031,7 +5035,7 @@ Func_a6ef: ld [wScrollMenuScrollOffset], a ld hl, wCurDeckCards ld de, wTempSavedDeckCards - ld b, $82 + ld b, DECK_TEMP_BUFFER_SIZE + 2 call CopyBBytesFromHLToDE_Bank02 call EmptyScreenAndDrawTextBox call Func_b81d @@ -5039,7 +5043,7 @@ Func_a6ef: HandleBlackBoxSendCardsScreen: ld hl, wCurDeckCards - ld a, $81 + ld a, DECK_TEMP_BUFFER_SIZE + 1 call ClearNBytesFromHL ld a, $ff ld [wCurDeck], a @@ -5268,7 +5272,7 @@ PrintFilteredCardSelectionList: add hl, bc ld a, [hl] push af - ld a, ALL_DECKS + ld a, $ff ; all owned cards call CreateCardCollectionListWithDeckCards ld a, TRUE ld [wd121], a @@ -5289,16 +5293,16 @@ PrintFilteredCardSelectionList: ret ; creates a card collection list in wTempCardCollection -; if a is $80, only include cards that are in the -; built decks, otherwise include all owned cards +; if a = CARD_COUNT_FROM_BUILT_DECKS, only include cards used in the built decks +; otherwise include all owned cards CreateCardCollectionListWithDeckCards: - cp $80 + cp CARD_COUNT_FROM_BUILT_DECKS jr nz, .copy_card_collection ld hl, wTempCardCollection - xor a + xor a ; aka $100 bytes call ClearNBytesFromHL ld hl, wTempCardCollection + $100 - xor a + xor a ; aka $100 bytes call ClearNBytesFromHL ld a, ALL_DECKS ld [hffbf], a @@ -5311,11 +5315,11 @@ CreateCardCollectionListWithDeckCards: call EnableSRAM ld hl, sCardCollection ld de, wTempCardCollection - ld b, $00 ; aka $100 bytes + ld b, 0 ; aka $100 bytes call CopyBBytesFromHLToDE_Bank02 ld hl, sCardCollection + $100 ld de, wTempCardCollection + $100 - ld b, $00 ; aka $100 bytes + ld b, 0 ; aka $100 bytes call CopyBBytesFromHLToDE_Bank02 call DisableSRAM .deck_1 @@ -5546,7 +5550,7 @@ PrintPlayersCardsText: ret PrintTotalNumberOfCardsInCollection: - ld a, ALL_DECKS + ld a, $ff ; all owned cards call CreateCardCollectionListWithDeckCards ; count all the cards in collection @@ -5556,7 +5560,7 @@ PrintTotalNumberOfCardsInCollection: .loop_all_cards ld a, [bc] inc bc - and $7f + and CARD_COUNT_MASK push de ld d, $00 ld e, a @@ -7132,14 +7136,18 @@ PrinterMenu: .PrinterQualityMenuParams scrollmenu_params 5, 16, 0, 2, 5, SYM_CURSOR_R, SYM_SPACE, NULL -Func_b57c: +; unlike tcg1's HandleDeckMissingCardsList, +; it's now a multipurpose screen +HandleDeckStatusCardList: push de ld de, wCurDeckName call CopyListFromHLToDE pop de ld hl, wCurDeckCards call CopyDeckFromSRAM -.asm_b58a + ; fallthrough + +HandleDeckStatusCardList_Execute: ld a, NUM_FILTERS ld hl, wCardFilterCounts call ClearNBytesFromHL @@ -7147,10 +7155,10 @@ Func_b57c: ld [wTotalCardCount], a ld hl, wCardFilterCounts ld [hl], a - call Func_b5b1 + call _HandleDeckStatusCardList ret -Func_b59f: +HandleDeckStatusCardList_InSRAM: push de ld de, wCurDeckName call CopyListFromHLToDEInSRAM @@ -7158,30 +7166,32 @@ Func_b59f: ld de, wCurDeckCards ld b, $80 call CopyBBytesFromHLToDE_Bank02 - jr Func_b57c.asm_b58a + jr HandleDeckStatusCardList_Execute -Func_b5b1: +_HandleDeckStatusCardList: call SortCurDeckCardsByID call CreateCurDeckUniqueCardList xor a ld [wScrollMenuScrollOffset], a -.asm_b5bb - ld hl, $7621 +.init_params + ld hl, .menu_params call InitializeScrollMenuParameters ld a, [wNumUniqueCards] ld [wNumCardListEntries], a - cp $05 - jr c, .asm_b5cd - ld a, $05 -.asm_b5cd + cp NUM_DECK_STATUS_LIST_VISIBLE_CARDS + jr c, .no_cap + ld a, NUM_DECK_STATUS_LIST_VISIBLE_CARDS +.no_cap ld [wNumMenuItems], a ld [wNumVisibleCardListEntries], a - call Func_b649 - ld hl, wd38a + call .PrintTitleAndList + ld hl, wCardConfirmationText ld a, [hli] ld h, [hl] ld l, a call DrawWideTextBox_PrintText + +; set scroll func ld hl, PrintConfirmationCardList ld d, h ld a, l @@ -7190,38 +7200,57 @@ Func_b5b1: ld [hl], d xor a ld [wd119], a -.asm_b5ed + +.loop_input call DoFrame call HandleScrollListInput - jr c, .asm_b619 + jr c, .selection_made call HandleJumpListInput - jr c, .asm_b5ed + jr c, .loop_input ldh a, [hDPadHeld] and PAD_START - jr z, .asm_b5ed -.asm_b600 + jr z, .loop_input + +; using wUniqueDeckCardList +.open_card_page ld a, MENU_CONFIRM call PlaySFXConfirmOrCancel ld a, [wTempCardTypeFilter] - ld [wced7], a + ld [wd11e], a ld de, wUniqueDeckCardList ld hl, wCurCardListPtr ld [hl], e inc hl ld [hl], d call OpenCardPageFromCardList - jr .asm_b5bb -.asm_b619 + jr .init_params + +.selection_made ld a, [hCurMenuItem] - cp $ff + cp MENU_CANCEL ret z - jr .asm_b600 -; 0xb621 + jr .open_card_page -SECTION "Bank 2@7649", ROMX[$7649], BANK[$2] +.menu_params + scrollmenu_params 0, 3, 2, 0, NUM_DECK_STATUS_LIST_VISIBLE_CARDS, SYM_CURSOR_R, SYM_SPACE, NULL -Func_b649: - call Func_b659 +.ScrollFunc_TCG1: + ld hl, hffbb + ld [hl], $01 + call .PrintDeckIndexAndName + lb de, 1, 14 + call InitTextPrinting + ld hl, wCardConfirmationText + ld a, [hli] + ld h, [hl] + ld l, a + call ProcessTextFromID + ld hl, hffbb + ld [hl], $00 + jp PrintConfirmationCardList + +.PrintTitleAndList: + call .ClearScreenAndPrintDeckTitle lb de, 3, 3 ld hl, wCardListCoords ld [hl], e @@ -7230,16 +7259,16 @@ Func_b649: call PrintConfirmationCardList ret -Func_b659: +.ClearScreenAndPrintDeckTitle: call EmptyScreenAndLoadFontDuelAndHandCardsIcons - call Func_b663 + call .PrintDeckIndexAndName call EnableLCD ret -Func_b663: +.PrintDeckIndexAndName: ld a, [wCurDeckName] or a - ret z + ret z ; not a valid deck lb de, 0, 1 call InitTextPrinting ld a, [wCurDeck] @@ -7251,6 +7280,7 @@ Func_b663: ld [hl], TX_END ld hl, wDefaultText call ProcessText + ld hl, wCurDeckName ld de, wDefaultText call CopyListFromHLToDE @@ -7862,8 +7892,8 @@ DeckDiagnosisResult: pop af ret -Func_baec: - farcall Func_3ada1 +HandleDeckSaveMachineMenu: + farcall _HandleDeckSaveMachineMenu ret HandleAutoDeckMenu: diff --git a/src/engine/bank07.asm b/src/engine/bank07.asm index 129dbab..824428a 100644 --- a/src/engine/bank07.asm +++ b/src/engine/bank07.asm @@ -5675,7 +5675,7 @@ CallMinicomMenuFunction: MinicomDeckSaveMachine: farcall ClearSpriteAnimsAndSetInitialGraphicsConfiguration - farcall Func_baec + farcall HandleDeckSaveMachineMenu ret MinicomCardAlbum: diff --git a/src/engine/bank0a.asm b/src/engine/bank0a.asm index dd9ddbb..d3fa76d 100644 --- a/src/engine/bank0a.asm +++ b/src/engine/bank0a.asm @@ -3419,14 +3419,14 @@ Func_2bbbb: ld e, [hl] inc hl ld d, [hl] - ld hl, wc000 + ld hl, wDeckToBuild xor a - ld b, $82 + ld b, DECK_TEMP_BUFFER_SIZE + 2 .asm_2bbc8 ld [hli], a dec b jr nz, .asm_2bbc8 - ld hl, wc000 + ld hl, wDeckToBuild .asm_2bbcf ld a, [de] inc de @@ -3447,9 +3447,9 @@ Func_2bbbb: jr .asm_2bbcf .asm_2bbe2 pop hl - ld bc, $18 + ld bc, DECK_NAME_SIZE add hl, bc - ld de, wc000 + ld de, wDeckToBuild farcall SwitchToWRAM2 bank1call SaveDeckCards farcall SwitchToWRAM1 @@ -3600,10 +3600,10 @@ _HandleAutoDeckMenu: ld a, [wScrollMenuScrollOffset] ld [wd54a], a ld b, a - ld a, [wTempCardTypeFilter] + ld a, [wCurScrollMenuItem] ld [wd54b], a add b - ld hl, wd49f + ld hl, wNumCardsNeededToBuildDeckMachineDecks ld c, a ld b, $00 add hl, bc @@ -3651,7 +3651,7 @@ _HandleAutoDeckMenu: Func_2bd48: ld a, $08 - ld hl, wd49f + ld hl, wNumCardsNeededToBuildDeckMachineDecks farcall ClearNBytesFromHL ld a, $08 ld hl, wd4b4 @@ -3696,7 +3696,7 @@ Func_2bd7f: ret Func_2bd92: - ld hl, wd49f + ld hl, wNumCardsNeededToBuildDeckMachineDecks push bc ld a, b inc a diff --git a/src/engine/bank0e.asm b/src/engine/bank0e.asm index 55accb8..13ab07a 100644 --- a/src/engine/bank0e.asm +++ b/src/engine/bank0e.asm @@ -4848,7 +4848,7 @@ UpdateBoosterPackMenuArrows: call WriteByteToBGMap0 ret -Func_3ada1: +_HandleDeckSaveMachineMenu: xor a ld [wScrollMenuScrollOffset], a ldtx de, DeckSaveMachineText @@ -4859,8 +4859,9 @@ Func_3ada1: call ClearScreenAndDrawDeckMachineScreen ld a, NUM_DECK_SAVE_MACHINE_SLOTS ld [wNumDeckMachineEntries], a + xor a -.asm_3adb7 +.wait_input ld hl, DeckMachineSelectionParams farcall InitializeScrollMenuParameters call DrawListScrollArrows @@ -4870,82 +4871,102 @@ Func_3ada1: ldtx de, PleaseSelectDeckText call InitDeckMachineDrawingParams call HandleDeckMachineSelection - jr c, .asm_3adb7 - cp $ff + jr c, .wait_input + cp MENU_CANCEL ret z +; get deck index ld b, a ld a, [wScrollMenuScrollOffset] add b ld [wSelectedDeckMachineEntry], a + farcall ResetCheckMenuCursorPositionAndBlink call DrawWideTextBox - ld hl, $6e7b + ld hl, .text_items call PlaceTextItems -.asm_3aded: +.wait_input_submenu call DoFrame farcall HandleCheckMenuInput - jp nc, .asm_3aded - cp $ff - jr nz, .asm_3ae01 + jp nc, .wait_input_submenu + cp MENU_CANCEL + jr nz, .submenu_option_selected +; return from submenu ld a, [wTempScrollMenuItem] - jp .asm_3adb7 -.asm_3ae01 + jp .wait_input + +.submenu_option_selected ld a, [wCheckMenuCursorYPosition] sla a ld hl, wCheckMenuCursorXPosition add [hl] or a - jr nz, .asm_3ae33 + jr nz, .next_submenu_1 + +; save call CheckIfSelectedDeckMachineEntryIsEmpty - jr nc, .asm_3ae1d - call Func_3b2db + jr nc, .overwrite + call SaveDeckInDeckSaveMachine ld a, [wTempScrollMenuItem] - jp c, .asm_3adb7 - jr .asm_3ae65 -.asm_3ae1d + jp c, .wait_input + jr .return_to_list + +.overwrite ldtx hl, DeleteSavedDeckPromptText call YesOrNoMenuWithText ld a, [wTempScrollMenuItem] - jr c, .asm_3adb7 - call Func_3b2db + jr c, .wait_input + call SaveDeckInDeckSaveMachine ld a, [wTempScrollMenuItem] - jp c, .asm_3adb7 - jr .asm_3ae65 -.asm_3ae33 - cp $01 - jr nz, .asm_3ae53 + jp c, .wait_input + jr .return_to_list + +.next_submenu_1 + cp DECKSAVEMACHINEMENU_DELETE + jr nz, .next_submenu_2 + +; delete call CheckIfSelectedDeckMachineEntryIsEmpty - jr c, .asm_3ae47 - call Func_3b3fa + jr c, .is_empty + call TryDeleteSavedDeck ld a, [wTempScrollMenuItem] - jp c, .asm_3adb7 - jr .asm_3ae65 -.asm_3ae47 + jp c, .wait_input + jr .return_to_list + +.is_empty ldtx hl, NoDecksSavedToMachineText call DrawWideTextBox_WaitForInput ld a, [wTempScrollMenuItem] - jp .asm_3adb7 -.asm_3ae53 - cp $02 - jr nz, .asm_3ae7a + jp .wait_input + +.next_submenu_2 + cp DECKSAVEMACHINEMENU_BUILD + jr nz, .cancel + +; build call CheckIfSelectedDeckMachineEntryIsEmpty - jr c, .asm_3ae47 - call Func_3b4eb + jr c, .is_empty + call TryBuildDeckMachineDeck ld a, [wTempScrollMenuItem] - jp nc, .asm_3adb7 -.asm_3ae65 + jp nc, .wait_input + +.return_to_list ld a, [wTempScrollMenuScrollOffset] ld [wScrollMenuScrollOffset], a call ClearScreenAndDrawDeckMachineScreen call DrawListScrollArrows call PrintNumSavedDecks ld a, [wTempScrollMenuItem] - jp .asm_3adb7 -.asm_3ae7a - ret -; 0x3ae7b + jp .wait_input -SECTION "Bank e@6e8c", ROMX[$6e8c], BANK[$e] +.cancel + ret + +.text_items + textitem 2, 14, SaveDeckToMachineText ; DECKSAVEMACHINEMENU_SAVE + textitem 12, 14, DeleteDeckFromMachineText ; DECKSAVEMACHINEMENU_DELETE + textitem 2, 16, BuildDeckText ; DECKSAVEMACHINEMENU_BUILD + textitem 12, 16, CancelDeckText ; DECKSAVEMACHINEMENU_CANCEL + textitems_end ; sets the number of cursor positions for deck machine menu, ; sets the text ID to show given by de @@ -4968,7 +4989,7 @@ InitDeckMachineDrawingParams: ld [wd119], a ret - ; handles player input inside the Deck Machine screen +; handles player input inside the Deck Machine screen ; the Start button opens up the deck confirmation menu ; and returns carry ; otherwise, returns no carry and selection made in a @@ -4996,23 +5017,23 @@ HandleDeckMachineSelection: or $80 ld [wCurDeck], a - ; get pointer to selected deck cards - ; and if it's an empty deck, jump to start +; get pointer to selected deck cards +; and if it's an empty deck, jump to start ld a, c - call Func_3afb8 + call GetAndLoadSelectedMachineDeckPtr push hl farcall CheckIfDeckHasCards pop hl jr c, .start - -; show deck confirmation screen with deck cards -; and return carry set push hl ld bc, DECK_NAME_SIZE add hl, bc ld d, h ld e, l pop hl + +; show deck confirmation screen with deck cards +; and return carry set ld a, MENU_CONFIRM farcall PlaySFXConfirmOrCancel farcall OpenDeckConfirmationMenu @@ -5074,8 +5095,8 @@ HandleDeckMachineSelection: ld [wScrollMenuScrollOffset], a cp c jr z, .set_carry - ; play SFX if jump was made - ; and update UI + +; play SFX on jump and update UI ld a, SFX_CURSOR call PlaySFX call DrawDeckMachineScreen @@ -5088,7 +5109,7 @@ HandleDeckMachineSelection: ; entry selected in the Deck Machine menu is empty CheckIfSelectedDeckMachineEntryIsEmpty: ld a, [wSelectedDeckMachineEntry] - call Func_3afb8 + call GetAndLoadSelectedMachineDeckPtr farcall CheckIfDeckHasCards ret @@ -5097,7 +5118,7 @@ ClearScreenAndDrawDeckMachineScreen: ld [wTileMapFill], a call ZeroObjectPositions call EmptyScreen - ld a, $01 + ld a, TRUE ld [wVBlankOAMCopyToggle], a call LoadSymbolsFont call LoadDuelCardSymbolTiles @@ -5142,8 +5163,11 @@ CopyListFromHLToDE_Bank0e: inc de jr .loop -; a = deck index in wMachineDeckPtrs -Func_3afb8: +; return hl = wMachineDeckPtrs[a] +; if that points at wram (not at sram, etc.), +; also load its data to wSelectedMachineDeck and wBackup3DeckToBuild, +; and overwrite hl = wSelectedMachineDeck +GetAndLoadSelectedMachineDeckPtr: push bc push de add a ; *2 @@ -5160,27 +5184,27 @@ Func_3afb8: call SwitchToWRAM2 push hl - ld hl, wc000 - ld de, w2d58e - ld b, $80 + ld hl, wDeckToBuild + ld de, wBackup3DeckToBuild + ld b, DECK_TEMP_BUFFER_SIZE call CopyBBytesFromHLToDE_Bank0e pop hl - ld de, wc000 - ld b, $80 + ld de, wDeckToBuild + ld b, DECK_TEMP_BUFFER_SIZE call CopyBBytesFromHLToDE_Bank0e call SwitchToWRAM1 - ld hl, wc000 - ld de, wd4c8 - ld b, $80 + ld hl, wDeckToBuild + ld de, wSelectedMachineDeck + ld b, DECK_TEMP_BUFFER_SIZE call CopyBBytesFromHLToDE_Bank0e call SwitchToWRAM2 - ld hl, w2d58e - ld de, wc000 - ld b, $80 + ld hl, wBackup3DeckToBuild + ld de, wDeckToBuild + ld b, DECK_TEMP_BUFFER_SIZE call CopyBBytesFromHLToDE_Bank0e call SwitchToWRAM1 - ld hl, wd4c8 + ld hl, wSelectedMachineDeck .done pop de pop bc @@ -5231,9 +5255,10 @@ PrintVisibleDeckMachineEntries: inc e inc e jr .loop -; 0x3b043 -SECTION "Bank e@7048", ROMX[$7048], BANK[$e] +UpdateDeckMachineScrollArrowsAndEntries: + call DrawListScrollArrows + jr PrintVisibleDeckMachineEntries DrawDeckMachineScreen: call DrawListScrollArrows @@ -5312,10 +5337,10 @@ PrintDeckMachineEntry: ; get the deck corresponding to input index ; and append its name to wDefaultText push af - call Func_3afb8 - inc d - inc d + call GetAndLoadSelectedMachineDeckPtr +REPT 3 ; indent x inc d +ENDR push de farcall AppendDeckName pop de @@ -5330,53 +5355,52 @@ PrintDeckMachineEntry: ld d, 12 inc e call InitTextPrinting - ld hl, .text + ld hl, .spaces call ProcessText scf ret +; b = deck index .valid_deck push de push bc - ld a, $0 ; no decks dismantled + ld a, 0 ; no decks dismantled call CheckIfCanBuildSavedDeck pop bc ld hl, wDefaultText jr c, .cannot_build - ; deck can be built +; can build xor a - ld [wd49b], a - ld hl, wd49f + ld [wNumCardsNeededToBuildSelectedDeckUsedInBuiltDecks], a + ld hl, wNumCardsNeededToBuildDeckMachineDecks ld d, $00 ld e, b sla e ; *2 add hl, de ld [hl], a - ld [wd49e], a - ld hl, wd49f + ld [wNumCardsNeededToBuildSelectedDeckMissingInCardCollection], a + ld hl, wNumCardsNeededToBuildDeckMachineDecks ld d, $00 ld e, b sla e inc e ; *2 + 1 add hl, de ld [hl], a - ldfw de, "○" ; can build - jp .asm_3b18e + ldfw de, "○" ; "can build" symbol + jp .padding .cannot_build - ; deck cannot be built ldfw de, " " call Func_22ca - ; figure out how many cards are being - ; used on the other decks +; figure out how many cards are being used on the other decks push bc - call .CountCardsNeededToBuildInBuiltDecks - ld [wd49b], a + call CountCardsNeededToBuildInBuiltDecks + ld [wNumCardsNeededToBuildSelectedDeckUsedInBuiltDecks], a pop bc - ld hl, wd49f + ld hl, wNumCardsNeededToBuildDeckMachineDecks ld d, $00 ld e, b sla e ; *2 @@ -5384,11 +5408,11 @@ PrintDeckMachineEntry: ld [hl], a push bc - ld a, ALL_DECKS - call .CountCardsNeededToBuildInCardCollection - ld [wd49e], a + ld a, $ff ; all owned cards + call CountCardsNeededToBuildInCardCollection + ld [wNumCardsNeededToBuildSelectedDeckMissingInCardCollection], a pop bc - ld hl, wd49f + ld hl, wNumCardsNeededToBuildDeckMachineDecks ld d, $00 ld e, b sla e @@ -5402,68 +5426,71 @@ PrintDeckMachineEntry: ld d, 12 inc e call InitTextPrinting - ld hl, .text + ld hl, .spaces call ProcessText pop de pop af push de or a - jr z, .need_dismantle + jr z, .need_dismantle ; can build by dismantling - ; players doesn't own all necessary cards +; necessary cards missing in collection pop de push de inc e - ld d, $10 + ld d, 16 call InitTextPrinting - ldfw de, "×" + ldfw de, "×" ; "missing" symbol call Func_22ca - ld a, [wd49e] + ld a, [wNumCardsNeededToBuildSelectedDeckMissingInCardCollection] ld hl, wDefaultText farcall ConvertToNumericalDigits ld [hl], TX_END ld hl, wDefaultText call ProcessText +; necessary cards used in built decks .need_dismantle pop de - ld a, [wd49b] + ld a, [wNumCardsNeededToBuildSelectedDeckUsedInBuiltDecks] or a - jr z, .asm_3b18c + jr z, .printed_shortfall inc e ld d, 12 call InitTextPrinting - ldfw de, "※" + ldfw de, "※" ; REF_MARK, "used" symbol call Func_22ca - ld a, [wd49b] + ld a, [wNumCardsNeededToBuildSelectedDeckUsedInBuiltDecks] ld hl, wDefaultText farcall ConvertToNumericalDigits ld [hl], TX_END ld hl, wDefaultText call ProcessText -.asm_3b18c + +.printed_shortfall or a ret -.asm_3b18e +; clear the card-shortfall text area +.padding call Func_22ca pop de ld d, 12 inc e call InitTextPrinting - ld hl, .text + ld hl, .spaces call ProcessText or a ret -.text +.spaces REPT 7 db "" ENDR done ; de = card ID -.GetCardCountInScratchCardCollection: +GetCardCountInScratchCardCollection: call SwitchToWRAM2 push hl ld hl, wScratchCardCollection @@ -5474,7 +5501,7 @@ ENDR ret ; de = card ID -.DecrementCardCountInScratchCardCollection: +DecrementCardCountInScratchCardCollection: call SwitchToWRAM2 push hl ld hl, wScratchCardCollection @@ -5485,34 +5512,31 @@ ENDR ret ; b = saved deck index -.CountCardsNeededToBuildInBuiltDecks: +; return a = total number of cards required but already used in built decks +CountCardsNeededToBuildInBuiltDecks: push bc - ld a, $80 ; only cards that are in built decks - farcall CreateCardCollectionListWithDeckCards - ; copy to wScratchCardCollection +; set: +; wTempCardCollection = all owned cards +; wScratchCardCollection = all cards used in built decks + ld a, CARD_COUNT_FROM_BUILT_DECKS + farcall CreateCardCollectionListWithDeckCards call SwitchToWRAM2 ld hl, wTempCardCollection ld de, wScratchCardCollection - ld b, 0 ; $100 bytes + ld b, 0 ; aka $100 bytes call CopyBBytesFromHLToDE_Bank0e ld hl, wTempCardCollection + $100 ld de, wScratchCardCollection + $100 - ld b, 0 ; $100 bytes + ld b, 0 ; aka $100 bytes call CopyBBytesFromHLToDE_Bank0e call SwitchToWRAM1 - - xor a ; all owned cards + xor a farcall CreateCardCollectionListWithDeckCards + pop bc - - ; here, wTempCardCollection holds all cards that - ; the player owns, including in and out of decks - ; wScratchCardCollection holds all cards that - ; are in built decks only - ld a, b - call Func_3afb8 + call GetAndLoadSelectedMachineDeckPtr ld bc, DECK_NAME_SIZE add hl, bc ld d, h @@ -5524,7 +5548,7 @@ ENDR lb bc, DECK_SIZE + 1, 0 .loop_deck dec b - jr z, .got_count_1 + jr z, .got_count_already_in_use ld e, [hl] inc hl ld d, [hl] @@ -5540,43 +5564,46 @@ ENDR pop hl jr .loop_deck .zero_count - call .GetCardCountInScratchCardCollection + call GetCardCountInScratchCardCollection or a jr z, .next_card - call .DecrementCardCountInScratchCardCollection + call DecrementCardCountInScratchCardCollection inc c .next_card pop hl jr .loop_deck -.got_count_1 - ld a, c ; total number of cards found in built decks + +.got_count_already_in_use + ld a, c ret ; b = saved deck index -.CountCardsNeededToBuildInCardCollection: +; return a = total number of cards required but missing +CountCardsNeededToBuildInCardCollection: push bc farcall CreateCardCollectionListWithDeckCards pop bc ld a, b - call Func_3afb8 + call GetAndLoadSelectedMachineDeckPtr ld bc, DECK_NAME_SIZE add hl, bc ld d, h ld e, l ld hl, wTempSavedDeckCards farcall CopyDeckFromSRAM + ld hl, wTempSavedDeckCards lb bc, DECK_SIZE + 1, 0 .loop_collection dec b - jr z, .got_count_2 + jr z, .got_count_missing ld e, [hl] inc hl ld d, [hl] inc hl push hl - ld hl, wc000 + ld hl, wTempCardCollection add hl, de ld a, [hl] and CARD_COUNT_MASK @@ -5590,7 +5617,8 @@ ENDR inc c pop hl jr .loop_collection -.got_count_2 + +.got_count_missing ld a, c ret @@ -5635,46 +5663,72 @@ PrintNumSavedDecks: ld hl, wDefaultText call ProcessText ret -; 0x3b2af -SECTION "Bank e@72db", ROMX[$72db], BANK[$e] +; unused in tcg1 +PrintDeckIndexPerNumSavedDecks: + ld a, [wCurScrollMenuItem] + ld b, a + ld a, [wScrollMenuScrollOffset] + add b + inc a + ld hl, wDefaultText + farcall ConvertToNumericalDigits + ld a, TX_SYMBOL + ld [hli], a + ld a, SYM_SLASH + ld [hli], a + ld a, [wNumSavedDecks] + farcall ConvertToNumericalDigits + ld [hl], TX_END + lb de, 14, 1 + call InitTextPrinting + ld hl, wDefaultText + call ProcessText + ret -Func_3b2db: - ld a, $ff +; for the selected slot (wSelectedDeckMachineEntry), +; handle decks screen menu to choose a deck to save there +; set carry if successfully saved +SaveDeckInDeckSaveMachine: + ld a, ALL_DECKS farcall DrawDecksScreen xor a -.asm_3b2e2 - ld hl, $735e +.wait_input + ld hl, DecksScreenMenuParams call InitializeMenuParameters ldtx hl, ChooseDeckToSaveToMachineText call DrawWideTextBox_PrintText -.asm_3b2ee +.wait_submenu_input call DoFrame farcall HandleStartButtonInDeckSelectionMenu - jr c, .asm_3b2e2 + jr c, .wait_input call HandleMenuInput - jp nc, .asm_3b2ee + jp nc, .wait_submenu_input ldh a, [hCurScrollMenuItem] - cp $ff + cp MENU_CANCEL ret z ld [wCurDeck], a farcall CheckIfCurDeckIsEmpty - jp nc, Func_3b315 + jp nc, .SaveDeckInSelectedEntry ; can be jr farcall PrintThereIsNoDeckHereText ld a, [wCurDeck] - jr .asm_3b2e2 + jr .wait_input -Func_3b315: +; copy sDeckX (X = [wCurDeck]) data +; to sSavedDeckY (Y = [wSelectedDeckMachineEntry]), +; update screen ui, and set carry +.SaveDeckInSelectedEntry: farcall GetSRAMPointerToCurDeck push hl call GetSelectedSavedDeckPtr ld d, h ld e, l pop hl - ld b, $60 + ld b, DECK_COMPRESSED_STRUCT_SIZE call EnableSRAM call CopyBBytesFromHLToDE_Bank0e call DisableSRAM + call ClearScreenAndDrawDeckMachineScreen call DrawListScrollArrows call PrintNumSavedDecks @@ -5693,15 +5747,15 @@ Func_3b315: call DrawWideTextBox_WaitForInput scf ret -; 0x3b35e -SECTION "Bank e@7366", ROMX[$7366], BANK[$e] +DecksScreenMenuParams: + menu_params 1, 2, 3, NUM_DECKS, SYM_CURSOR_R, SYM_SPACE, NULL GetSelectedSavedDeckPtr: push af push de ld a, [wSelectedDeckMachineEntry] - call Func_3afb8 + call GetAndLoadSelectedMachineDeckPtr pop de pop af ret @@ -5716,7 +5770,7 @@ CheckIfCanBuildSavedDeck: farcall CreateCardCollectionListWithDeckCards pop bc ld a, b - call Func_3afb8 + call GetAndLoadSelectedMachineDeckPtr ld bc, DECK_NAME_SIZE add hl, bc call CheckIfHasEnoughCardsToBuildDeck @@ -5724,11 +5778,11 @@ CheckIfCanBuildSavedDeck: SwitchToWRAM1: push af - ld a, [wce4c] - cp $01 + ld a, [wTempBankWRAM] + cp BANK("WRAM1") jr z, .skip - ld a, $01 - ld [wce4c], a + ld a, BANK("WRAM1") + ld [wTempBankWRAM], a ldh [rWBK], a .skip pop af @@ -5736,11 +5790,11 @@ SwitchToWRAM1: SwitchToWRAM2: push af - ld a, [wce4c] - cp $02 + ld a, [wTempBankWRAM] + cp BANK("WRAM2") jr z, .skip - ld a, $02 - ld [wce4c], a + ld a, BANK("WRAM2") + ld [wTempBankWRAM], a ldh [rWBK], a .skip pop af @@ -5785,48 +5839,58 @@ CheckIfHasEnoughCardsToBuildDeck: or a ret -Func_3b3d1: - ld hl, sDeck1Name +; return a = DECK_*_F of the first empty slot +; set carry otherwise +FindFirstEmptyDeckSlot: + ld hl, sDeck1 ld a, [hl] or a - jr nz, .asm_3b3da - xor a + jr nz, .check_deck_2 + xor a ; DECK_1_F ret -.asm_3b3da - ld hl, sDeck2Name + +.check_deck_2 + ld hl, sDeck2 ld a, [hl] or a - jr nz, .asm_3b3e4 - ld a, $01 + jr nz, .check_deck_3 + ld a, DECK_2_F ret -.asm_3b3e4 - ld hl, sDeck3Name + +.check_deck_3 + ld hl, sDeck3 ld a, [hl] or a - jr nz, .asm_3b3ee - ld a, $02 + jr nz, .check_deck_4 + ld a, DECK_3_F ret -.asm_3b3ee - ld hl, sDeck4Name + +.check_deck_4 + ld hl, sDeck4 ld a, [hl] or a - jr nz, .asm_3b3f8 - ld a, $03 + jr nz, .no_empty + ld a, DECK_4_F ret -.asm_3b3f8 + +.no_empty scf ret -Func_3b3fa: +; for N = selected saved deck [wSelectedDeckMachineEntry], +; provide delete prompt +; if yes, clear sSavedDeckN +; if no, return a = menu item pos with carry +TryDeleteSavedDeck: ldtx hl, ConfirmDeletePromptText call YesOrNoMenuWithText - jr c, .asm_3b426 + jr c, .no call GetSelectedSavedDeckPtr push hl call EnableSRAM farcall CopyDeckName pop hl - ld a, $60 + ld a, DECK_COMPRESSED_STRUCT_SIZE farcall ClearNBytesFromHL call DisableSRAM xor a @@ -5836,8 +5900,9 @@ Func_3b3fa: call DrawWideTextBox_WaitForInput or a ret -.asm_3b426 - ld a, [wTempCardTypeFilter] + +.no + ld a, [wCurScrollMenuItem] scf ret @@ -5872,57 +5937,62 @@ DrawListScrollArrows: call WriteByteToBGMap0 ret -Func_3b45f: +; decks screen menu to make space for new deck to build +HandleDismantleDeckToMakeSpace: ldtx hl, YouMayOnlyCarry4DecksText call DrawWideTextBox_WaitForInput - ld a, $ff + ld a, ALL_DECKS farcall DrawDecksScreen xor a -.asm_3b46c - ld hl, $735e +.init_menu_params + ld hl, DecksScreenMenuParams call InitializeMenuParameters ldtx hl, ChooseDeckToDismantleText call DrawWideTextBox_PrintText -.asm_3b478 +.loop_input call DoFrame farcall HandleStartButtonInDeckSelectionMenu - jr c, .asm_3b46c + jr c, .init_menu_params call HandleMenuInput - jp nc, .asm_3b478 + jp nc, .loop_input ; can be jr ldh a, [hCurScrollMenuItem] - cp $ff - jr nz, .asm_3b48f + cp MENU_CANCEL + jr nz, .selected_deck scf ret -.asm_3b48f + +.selected_deck ld [wCurDeck], a ldtx hl, DeckBuildingDismantlePromptText call YesOrNoMenuWithText - jr nc, .asm_3b49f + jr nc, .dismantle ld a, [wCurDeck] - jr .asm_3b46c -.asm_3b49f + jr .init_menu_params + +.dismantle farcall GetSRAMPointerToCurDeck push hl - ld de, wd47e + ld de, wDismantledDeckName call EnableSRAM call CopyListFromHLToDE_Bank0e pop hl push hl - ld bc, $18 + ld bc, DECK_NAME_SIZE add hl, bc farcall AddDeckToCollection pop hl - ld a, $60 + ld a, DECK_COMPRESSED_STRUCT_SIZE farcall ClearNBytesFromHL call DisableSRAM - ld a, $ff + +; redraw decks screen + ld a, ALL_DECKS farcall DrawDecksScreen ld a, [wCurDeck] - ld hl, $735e + ld hl, DecksScreenMenuParams call InitializeMenuParameters call DrawCursor2 - ld hl, wd47e + ld hl, wDismantledDeckName farcall CopyDeckName xor a ld [wTxRam2], a @@ -5932,84 +6002,99 @@ Func_3b45f: ld a, [wCurDeck] ret -Func_3b4eb: +TryBuildDeckMachineDeck: call SwitchToWRAM2 xor a - ld [w2d280], a + ld [wNumRemainingBasicEnergyCardsForSubbedDeck], a call SwitchToWRAM1 ld a, [wSelectedDeckMachineEntry] - ld hl, wd49f - sla a + ld hl, wNumCardsNeededToBuildDeckMachineDecks + sla a ; *2 ld b, $00 ld c, a add hl, bc ld a, [hli] - ld [wd49b], a + ld [wNumCardsNeededToBuildSelectedDeckUsedInBuiltDecks], a ld a, [hl] - ld [wd49e], a + ld [wNumCardsNeededToBuildSelectedDeckMissingInCardCollection], a or a - jr nz, .asm_3b526 - ld a, [wd49b] + jr nz, .not_own_all_cards_needed + ld a, [wNumCardsNeededToBuildSelectedDeckUsedInBuiltDecks] or a - jr z, .asm_3b53a + jr z, .build_deck + +; can build by dismantling deck(s) ldtx hl, CannotBuildMustDismantleText call DrawWideTextBox_WaitForInput - call Func_3b9d6 - call Func_3b5f1 - jr nc, .asm_3b53a - call Func_3b661 - jr nc, .asm_3b53a + call ShowUsedCardListFromBuiltDecks + call .DismantleDecksNeededToBuild + jr nc, .build_deck + call .TryBuildSubbedDeck + jr nc, .build_deck ret -.asm_3b526 + +.not_own_all_cards_needed ldtx hl, YouDoNotOwnAllCardsNeededToBuildThisDeckText call DrawWideTextBox_WaitForInput - call Func_3b92b - ld a, [wd49b] + call ShowMissingCardList + ld a, [wNumCardsNeededToBuildSelectedDeckUsedInBuiltDecks] or a - call nz, Func_3b9d6 - call Func_3b661 + call nz, ShowUsedCardListFromBuiltDecks + call .TryBuildSubbedDeck ret c -.asm_3b53a +; fallthrough + +.build_deck call EnableSRAM - call Func_3b3d1 + call FindFirstEmptyDeckSlot call DisableSRAM - jr nc, .asm_3b54c - call Func_3b45f - jr nc, .asm_3b54c + jr nc, .got_deck_slot + call HandleDismantleDeckToMakeSpace + jr nc, .got_deck_slot scf ret -.asm_3b54c - ld [wd496], a + +.got_deck_slot + ld [wDeckSlotForNewDeck], a ld a, [wSelectedDeckMachineEntry] - call Func_3afb8 - ld de, wc000 - ld b, $60 + call GetAndLoadSelectedMachineDeckPtr + +; copy deck to buffer + ld de, wDeckToBuild + ld b, DECK_COMPRESSED_STRUCT_SIZE call EnableSRAM call CopyBBytesFromHLToDE_Bank0e + call SwitchToWRAM2 - ld a, [w2d280] + ld a, [wNumRemainingBasicEnergyCardsForSubbedDeck] or a - call nz, Func_3b7fc + call nz, SubInBasicEnergyInCurDeck + +; remove needed cards from collection call SwitchToWRAM1 - ld hl, $c018 - farcall Func_9337 - ld a, [wd496] + ld hl, wDeckToBuild + DECK_NAME_SIZE + farcall DecrementDeckCardsInCollection_CopyDeckFromSRAM + +; copy deck cards from buffer to selected deck slot + ld a, [wDeckSlotForNewDeck] ld l, a - ld h, $60 + ld h, DECK_COMPRESSED_STRUCT_SIZE call HtimesL - ld bc, sDeck1Name + ld bc, sBuiltDecks add hl, bc ld d, h ld e, l - ld hl, wc000 - ld b, $60 + ld hl, wDeckToBuild + ld b, DECK_COMPRESSED_STRUCT_SIZE call CopyBBytesFromHLToDE_Bank0e call DisableSRAM - ld a, $ff + +; draw decks screen + ld a, ALL_DECKS farcall DrawDecksScreen - ld a, [wd496] + ld a, [wDeckSlotForNewDeck] ld [wCurDeck], a - ld hl, $735e + ld hl, DecksScreenMenuParams call InitializeMenuParameters call DrawCursor2 farcall GetSRAMPointerToCurDeck @@ -6022,138 +6107,151 @@ Func_3b4eb: ldtx hl, BuiltDeckText call DrawWideTextBox_WaitForInput call SwitchToWRAM2 - ld a, [w2d280] + ld a, [wNumRemainingBasicEnergyCardsForSubbedDeck] or a call SwitchToWRAM1 - jr z, .asm_3b5ef + jr z, .done + +; built subbed deck call SwitchToWRAM2 - ld hl, w2d38e - ld de, wc000 - ld b, $80 + ld hl, wBackup2DeckToBuild + ld de, wDeckToBuild + ld b, DECK_TEMP_BUFFER_SIZE call CopyBBytesFromHLToDE_Bank0e call SwitchToWRAM1 ldtx bc, BuiltSubbedDeckWithTheseCardsText - ld hl, wd38a + ld hl, wCardConfirmationText ld a, c ld [hli], a ld a, b ld [hl], a call GetSelectedSavedDeckPtr - ld de, wc000 - farcall Func_b59f -.asm_3b5ef + ld de, wDeckToBuild + farcall HandleDeckStatusCardList_InSRAM + +.done scf ret -Func_3b5f1: - call Func_3bcd6 +.DismantleDecksNeededToBuild: + call CheckWhichDecksToDismantleToBuildSavedDeck farcall DrawDecksScreen ldtx hl, DismantleTheseDecksPromptText call YesOrNoMenuWithText - jr nc, .asm_3b601 + jr nc, .dismantle_yes ret -.asm_3b601 +.dismantle_yes call EnableSRAM - ld a, [wd49a] - bit 0, a - jr z, .asm_3b610 - ld a, $00 - call Func_3b646 -.asm_3b610 - ld a, [wd49a] - bit 1, a - jr z, .asm_3b61c - ld a, $01 - call Func_3b646 -.asm_3b61c - ld a, [wd49a] - bit 2, a - jr z, .asm_3b628 - ld a, $02 - call Func_3b646 -.asm_3b628 - ld a, [wd49a] - bit 3, a - jr z, .asm_3b634 - ld a, $03 - call Func_3b646 -.asm_3b634 +; dismantle deck 1 + ld a, [wDecksToBeDismantled] + bit DECK_1_F, a + jr z, .dismantle_deck_2 + ld a, DECK_1_F + call .DismantleDeck +.dismantle_deck_2 + ld a, [wDecksToBeDismantled] + bit DECK_2_F, a + jr z, .dismantle_deck_3 + ld a, DECK_2_F + call .DismantleDeck +.dismantle_deck_3 + ld a, [wDecksToBeDismantled] + bit DECK_3_F, a + jr z, .dismantle_deck_4 + ld a, DECK_3_F + call .DismantleDeck +.dismantle_deck_4 + ld a, [wDecksToBeDismantled] + bit DECK_4_F, a + jr z, .done_dismantling + ld a, DECK_4_F + call .DismantleDeck + +.done_dismantling call DisableSRAM - ld a, [wd49a] + ld a, [wDecksToBeDismantled] farcall DrawDecksScreen ldtx hl, DismantledTheseDecksText call DrawWideTextBox_WaitForInput or a ret -Func_3b646: +; a = DECK_*_F +.DismantleDeck: ld l, a - ld h, $60 + ld h, DECK_COMPRESSED_STRUCT_SIZE call HtimesL - ld bc, sDeck1Name + ld bc, sBuiltDecks add hl, bc push hl - ld bc, $18 + ld bc, DECK_NAME_SIZE add hl, bc farcall AddDeckToCollection pop hl - ld a, $60 + ld a, DECK_COMPRESSED_STRUCT_SIZE farcall ClearNBytesFromHL ret -Func_3b661: +.TryBuildSubbedDeck: ldtx hl, MaySubInEnergyCardsToBuildThisDeckText call DrawWideTextBox_WaitForInput ldtx hl, BuildSubbedDeckPromptText call YesOrNoMenuWithText ret c - ld a, [wd49b] - ld hl, wd49e + + ld a, [wNumCardsNeededToBuildSelectedDeckUsedInBuiltDecks] + ld hl, wNumCardsNeededToBuildSelectedDeckMissingInCardCollection add [hl] - cp $0a - jr c, .asm_3b681 + cp MAX_NUM_SUB_ENERGY_CARDS + 1 + jr c, .check_basic_energy_to_sub_in ldtx hl, CannotBuildLackingTooManyCardsText call DrawWideTextBox_WaitForInput scf ret -.asm_3b681 + +.check_basic_energy_to_sub_in push af - call Func_3b6c4 - call Func_3b75a + call OmitMissingCardsFromDeckAndBackup + call GetSumOfRemainingBasicEnergyCards pop bc - jr c, .asm_3b696 - cp b - jr nc, .asm_3b696 + jr c, .check_basic_pkmn_before_sub ; has 256+ energy cards + cp b ; required sub count + jr nc, .check_basic_pkmn_before_sub ldtx hl, CannotBuildLackingEnergyCardsText call DrawWideTextBox_WaitForInput scf ret -.asm_3b696 + +.check_basic_pkmn_before_sub call SwitchToWRAM2 - ld hl, w2d200 - ld de, wc000 - ld b, $80 + ld hl, wBackup1DeckToBuild + ld de, wDeckToBuild + ld b, DECK_TEMP_BUFFER_SIZE call CopyBBytesFromHLToDE_Bank0e call SwitchToWRAM1 - ld hl, wc000 + ld hl, wDeckToBuild ld de, wCurDeckCards - ld b, $80 + ld b, DECK_TEMP_BUFFER_SIZE call CopyBBytesFromHLToDE_Bank0e farcall CheckIfThereAreAnyBasicCardsInDeck - jr c, .asm_3b6c0 + jr c, .prepare_sub ldtx hl, CannotBuildLackingBasicPokemonText call DrawWideTextBox_WaitForInput scf ret -.asm_3b6c0 - call Func_3b79b + +.prepare_sub + call SortRemainingBasicEnergyCardsDescending ret -Func_3b6c4: +; list available cards for the target deck +; and load them into wDeckToBuild and wBackup1DeckToBuild, +; skipping all missing cards +OmitMissingCardsFromDeckAndBackup: ld a, [wSelectedDeckMachineEntry] ld [wCurDeck], a call GetSelectedSavedDeckPtr - ld de, $18 + ld de, DECK_NAME_SIZE add hl, de ld d, h ld e, l @@ -6161,13 +6259,16 @@ Func_3b6c4: farcall CopyDeckFromSRAM farcall SortCurDeckCardsByID farcall CreateCurDeckUniqueCardList + +; set wTempCardCollection = all owned cards xor a farcall CreateCardCollectionListWithDeckCards - ld hl, $0 -.asm_3b6ea + + ld hl, 0 +.loop_deck_configuration push hl ld l, h - ld h, $00 + ld h, 0 ld de, wUniqueDeckCardList add hl, de ld e, [hl] @@ -6176,19 +6277,20 @@ Func_3b6c4: pop hl inc h inc h - call Func_3b91d - jr c, .asm_3b720 + call CheckIfCardIDIsZero_Bank0e + jr c, .got_list push bc push de push hl ld hl, wCurDeckCards - call Func_3b746 + call .GetCardCountAvailable pop hl pop de pop bc - jr nc, .asm_3b6ea + jr nc, .loop_deck_configuration + ld c, a -.asm_3b70c +.loop_append push hl push de ld h, $00 @@ -6202,187 +6304,228 @@ Func_3b6c4: inc l inc l dec c - jr nz, .asm_3b70c - jr .asm_3b6ea -.asm_3b720 + jr nz, .loop_append + jr .loop_deck_configuration + +.got_list +; append null terminator ld h, $00 ld de, wTempCardList add hl, de xor a ld [hli], a ld [hl], a +; copy deck data ld hl, wTempCardList - ld de, wc000 - ld b, $80 + ld de, wDeckToBuild + ld b, DECK_TEMP_BUFFER_SIZE call CopyBBytesFromHLToDE_Bank0e call SwitchToWRAM2 - ld hl, wc000 - ld de, w2d200 - ld b, $80 + ld hl, wDeckToBuild + ld de, wBackup1DeckToBuild + ld b, DECK_TEMP_BUFFER_SIZE call CopyBBytesFromHLToDE_Bank0e call SwitchToWRAM1 ret -Func_3b746: - call Func_3b9ba - ld hl, wc000 +; hl = deck cards (wCurDeckCards) +; de = card id +; if owned count > 0, return a = min( (required count), (owned count) ) with carry +; if owned count = 0, return a = 0 (nc) +.GetCardCountAvailable: + call GetCardCountFromDeck + ld hl, wTempCardCollection ; all owned cards add hl, de ld a, [hl] - and $7f + and CARD_COUNT_MASK or a ret z + cp b - jr nc, .asm_3b757 + jr nc, .enough +; not enough but nonzero scf ret -.asm_3b757 +.enough ld a, b scf ret -Func_3b75a: +; for x[t] = {basic energy cards remaining after building wBackup1DeckToBuild}, +; calc sum(x) from grass to psychic with overflow check: +; if sum(x[0..k]) > 255 at t = k, return +; a = sum(x[0..k]) % 256 (with carry), +; b = sum(x[0..k-1]) +; otherwise return a = b = sum(x) +GetSumOfRemainingBasicEnergyCards: +; set wTempCardCollection = all owned cards xor a farcall CreateCardCollectionListWithDeckCards + call SwitchToWRAM2 - ld hl, w2d200 -.asm_3b765 + ld hl, wBackup1DeckToBuild +.loop_deck_cards ld e, [hl] inc hl ld d, [hl] inc hl - call Func_3b91d - jr c, .asm_3b77c + call CheckIfCardIDIsZero_Bank0e + jr c, .load_count push hl - ld hl, wc000 + ld hl, wTempCardCollection add hl, de ld a, [hl] - and $7f - jr z, .asm_3b779 + and CARD_COUNT_MASK + jr z, .next_card dec [hl] -.asm_3b779 +.next_card pop hl - jr .asm_3b765 -.asm_3b77c - ld hl, wc000 + 1 - ld de, w2d280 - ld b, $06 + jr .loop_deck_cards + +.load_count + ld hl, wTempCardCollection + GRASS_ENERGY + ld de, wNumRemainingBasicEnergyCardsForSubbedDeck + ld b, NUM_COLORED_TYPES call CopyBBytesFromHLToDE_Bank0e - ld hl, w2d280 - ld bc, $6 -.asm_3b78d + + ld hl, wNumRemainingBasicEnergyCardsForSubbedDeck + lb bc, 0, NUM_COLORED_TYPES +.loop_sum ld a, [hli] add b - jr c, .asm_3b797 + jr c, .done ld b, a dec c - jr nz, .asm_3b78d + jr nz, .loop_sum ld b, a or a -.asm_3b797 +.done call SwitchToWRAM1 ret -Func_3b79b: +; sort wNumRemainingBasicEnergyCardsForSubbedDeck in descending order +; and map its index array to wIndicesRemainingBasicEnergyCardsForSubbedDeck +SortRemainingBasicEnergyCardsDescending: call SwitchToWRAM2 ld a, $ff - ld [w2d286], a + ld [wNumRemainingBasicEnergyCardsForSubbedDeck + NUM_COLORED_TYPES], a xor a - ld hl, w2d287 - ld [hli], a + ld hl, wIndicesRemainingBasicEnergyCardsForSubbedDeck + ld [hli], a ; GRASS_ENERGY - GRASS_ENERGY inc a - ld [hli], a + ld [hli], a ; FIRE_ENERGY - GRASS_ENERGY inc a - ld [hli], a + ld [hli], a ; WATER_ENERGY - GRASS_ENERGY inc a - ld [hli], a + ld [hli], a ; LIGHTNING_ENERGY - GRASS_ENERGY inc a - ld [hli], a + ld [hli], a ; FIGHTING_ENERGY - GRASS_ENERGY inc a - ld [hl], a - ld de, $0 -.asm_3b7b5 - ld hl, w2d280 + ld [hl], a ; PSYCHIC_ENERGY - GRASS_ENERGY + + ld de, 0 +.loop_swap + ld hl, wNumRemainingBasicEnergyCardsForSubbedDeck add hl, de - call Func_3b7e4 + call .GetMaxNumAndIndex ld a, e add c ld c, a - ld hl, w2d280 + ld hl, wNumRemainingBasicEnergyCardsForSubbedDeck add hl, de ld a, [hl] ld [hl], b - ld b, $00 - ld hl, w2d280 + ld b, 0 + ld hl, wNumRemainingBasicEnergyCardsForSubbedDeck add hl, bc ld [hl], a - ld hl, w2d287 + ld hl, wIndicesRemainingBasicEnergyCardsForSubbedDeck add hl, de ld a, [hl] push hl - ld hl, w2d287 + ld hl, wIndicesRemainingBasicEnergyCardsForSubbedDeck add hl, bc ld c, [hl] ld [hl], a pop hl ld [hl], c inc e - ld a, $06 + ld a, NUM_COLORED_TYPES cp e - jr nz, .asm_3b7b5 + jr nz, .loop_swap call SwitchToWRAM1 ret -Func_3b7e4: +; from the current index and onwards, +; return b = max count, c = energy index of max count +.GetMaxNumAndIndex: push de - ld e, $00 - ld bc, $0 -.asm_3b7ea + ld e, 0 + lb bc, 0, 0 +.loop_energy ld a, [hli] cp $ff - jr z, .asm_3b7f9 - and $7f + jr z, .got_max + and CARD_COUNT_MASK cp b - jr c, .asm_3b7f6 + jr c, .next_energy ld b, a ld e, c -.asm_3b7f6 +.next_energy inc c - jr .asm_3b7ea -.asm_3b7f9 + jr .loop_energy +.got_max ld c, e pop de ret -Func_3b7fc: +; fill in missing card slots in the deck with remaining basic energy cards +; (already guaranteed of enough amount of replacements at this point), +; starting with the type of the most remaining +; bug: +; in the first iteration, skip type(s) of +; ( (*_ENERGY used in the deck) + 1) +; e.g. +; when the deck misses 9 cards +; and the remaining energy count is 50 fighting, 40 grass, 30 fire, …, +; if the deck has any lightning (LIGHTNING_ENERGY + 1 = FIGHTING_ENERGY), +; sub in 9 grass +; otherwise sub in 9 fighting +SubInBasicEnergyInCurDeck: call SwitchToWRAM2 - ld hl, wc000 - ld de, w2d28e - ld b, $00 + ld hl, wDeckToBuild + ld de, wBigBackupDeckToBuild + ld b, 0 ; aka $100 bytes call CopyBBytesFromHLToDE_Bank0e call SwitchToWRAM1 - call Func_3b6c4 - call Func_3b75a - call Func_3b79b + call OmitMissingCardsFromDeckAndBackup + call GetSumOfRemainingBasicEnergyCards + call SortRemainingBasicEnergyCardsDescending call SwitchToWRAM2 - ld hl, w2d28e - ld de, wc000 - ld b, $00 + ld hl, wBigBackupDeckToBuild + ld de, wDeckToBuild + ld b, 0 ; aka $100 bytes call CopyBBytesFromHLToDE_Bank0e + +; decompress wDeckToBuild deck config call SwitchToWRAM1 - ld de, $c018 + ld de, wDeckToBuild + DECK_NAME_SIZE ld hl, wTempSavedDeckCards farcall CopyDeckFromSRAM ld hl, wTempSavedDeckCards - ld de, $c018 - ld b, $80 + ld de, wDeckToBuild + DECK_NAME_SIZE + ld b, DECK_TEMP_BUFFER_SIZE call CopyBBytesFromHLToDE_Bank0e + +; copy wBackup1DeckToBuild (missing cards omitted) to wScratchCardCollection +; set b = card count call SwitchToWRAM2 - ld a, $80 + ld a, DECK_TEMP_BUFFER_SIZE ld hl, wScratchCardCollection farcall ClearNBytesFromHL - ld b, $00 - ld de, w2d200 -.asm_3b84d + ld b, 0 + ld de, wBackup1DeckToBuild +.loop_copy_and_count ld a, [de] inc de ld [hli], a @@ -6394,53 +6537,61 @@ Func_3b7fc: inc b ld e, c ld d, a - call Func_3b91d + call CheckIfCardIDIsZero_Bank0e pop de - jr nc, .asm_3b84d + jr nc, .loop_copy_and_count dec b dec hl dec hl + push hl ld a, $ff - ld [w2d28d], a - ld de, $0 -.asm_3b86a + ld [wIndicesRemainingBasicEnergyCardsForSubbedDeck + NUM_COLORED_TYPES], a + +; first iteration +; bug: skip all *_ENERGY of ( (*_ENERGY used in the deck) + 1) + ld de, 0 +.loop_energy push hl - ld hl, w2d287 + ld hl, wIndicesRemainingBasicEnergyCardsForSubbedDeck add hl, de ld a, [hl] cp $ff - jr z, .asm_3b882 - call Func_3b8c0 + jr z, .second_iteration + call .CheckEnergyInDeck pop hl - jr c, .asm_3b87f - call Func_3b8da - jr c, .asm_3b899 -.asm_3b87f + jr c, .next_energy + call .SubInCurBasicEnergy + jr c, .list_energy +.next_energy inc e - jr .asm_3b86a -.asm_3b882 + jr .loop_energy + +; ensure completion, with no skip logic +.second_iteration pop hl - ld de, $0 -.asm_3b886 + ld de, 0 +.loop_energy_2 push hl - ld hl, w2d287 + ld hl, wIndicesRemainingBasicEnergyCardsForSubbedDeck add hl, de ld a, [hl] cp $ff pop hl - jr z, .asm_3b899 - call Func_3b8da - jr c, .asm_3b899 + jr z, .list_energy + call .SubInCurBasicEnergy + jr c, .list_energy inc e - jr .asm_3b886 -.asm_3b899 - ld a, $80 - ld hl, w2d38e + jr .loop_energy_2 + +; list all energy subs at wBackup2DeckToBuild to display it later +.list_energy + ld a, DECK_TEMP_BUFFER_SIZE + ld hl, wBackup2DeckToBuild farcall ClearNBytesFromHL pop hl - ld bc, w2d38e -.asm_3b8a6 + ld bc, wBackup2DeckToBuild +.loop_list ld a, [hli] ld [bc], a inc bc @@ -6449,113 +6600,126 @@ Func_3b7fc: ld [bc], a inc bc ld d, a - call Func_3b91d - jr nc, .asm_3b8a6 - ld hl, $c018 + call CheckIfCardIDIsZero_Bank0e + jr nc, .loop_list + +; save result + ld hl, wDeckToBuild + DECK_NAME_SIZE ld de, wScratchCardCollection bank1call SaveDeckCards call SwitchToWRAM1 ret -Func_3b8c0: +; a = basic energy index [0, 5] +; bug: set carry if wDeckToBuild contains a card of id = a +; *_ENERGY card id is [1, 6], which is a mismatch +.CheckEnergyInDeck: push de - ld hl, $c018 -.asm_3b8c4 + ld hl, wDeckToBuild + DECK_NAME_SIZE +.loop_deck_cards ld e, [hl] inc hl ld d, [hl] inc hl - call Func_3b91d + call CheckIfCardIDIsZero_Bank0e ccf - jr nc, .asm_3b8d8 + jr nc, .checked_deck_cards cp e - jr nz, .asm_3b8c4 + jr nz, .loop_deck_cards ld e, a ld a, d or a ld a, e - jr nz, .asm_3b8c4 + jr nz, .loop_deck_cards scf -.asm_3b8d8 +.checked_deck_cards pop de ret -Func_3b8da: +; append current basic energy (e = offset) +; to the end of card list (wScratchCardCollection) +; if the deck is completed, set carry +; and overwrite the index in wIndicesRemainingBasicEnergyCardsForSubbedDeck +; with the final remaining count (!?) +.SubInCurBasicEnergy: push hl - ld hl, w2d280 + ld hl, wNumRemainingBasicEnergyCardsForSubbedDeck add hl, de ld a, [hl] - and $7f - jr z, .asm_3b90d + and CARD_COUNT_MASK + jr z, .exit_append ld c, a pop hl push de push hl - ld hl, w2d287 + ld hl, wIndicesRemainingBasicEnergyCardsForSubbedDeck add hl, de ld e, [hl] - inc e + inc e ; convert index to *_ENERGY card id ld d, $00 pop hl -.asm_3b8f1 +.loop_append ld [hl], e inc hl ld [hl], d inc hl inc b dec c - jr z, .asm_3b900 - ld a, $3c + jr z, .depleted + ld a, DECK_SIZE cp b - jr z, .asm_3b910 - jr .asm_3b8f1 -.asm_3b900 - ld a, $3c + jr z, .done_append + jr .loop_append + +.depleted + ld a, DECK_SIZE cp b - jr z, .asm_3b910 + jr z, .done_append pop de push hl - ld hl, w2d280 + ld hl, wNumRemainingBasicEnergyCardsForSubbedDeck add hl, de xor a ld [hl], a -.asm_3b90d +.exit_append pop hl or a ret -.asm_3b910 + +.done_append xor a ld [hli], a ld [hl], a pop de push hl - ld hl, w2d287 + ld hl, wIndicesRemainingBasicEnergyCardsForSubbedDeck add hl, de ld [hl], c pop hl scf ret -Func_3b91d: +; return carry if de (card id) = 0 +CheckIfCardIDIsZero_Bank0e: push af xor a cp d - jr nz, .asm_3b928 + jr nz, .false cp e - jr nz, .asm_3b928 + jr nz, .false pop af scf ret -.asm_3b928 +.false pop af or a ret -Func_3b92b: +ShowMissingCardList: ld a, [wSelectedDeckMachineEntry] ld [wCurDeck], a call GetSelectedSavedDeckPtr - ld de, $18 + ld de, DECK_NAME_SIZE add hl, de ld d, h ld e, l @@ -6563,10 +6727,13 @@ Func_3b92b: farcall CopyDeckFromSRAM farcall SortCurDeckCardsByID farcall CreateCurDeckUniqueCardList + +; set wTempCardCollection = all owned cards ld a, $ff farcall CreateCardCollectionListWithDeckCards - ld hl, $0 -.asm_3b952 + + ld hl, 0 +.loop_deck_configuration push hl ld l, h ld h, $00 @@ -6578,19 +6745,21 @@ Func_3b92b: pop hl inc h inc h - call Func_3b91d - jr c, .asm_3b988 + call CheckIfCardIDIsZero_Bank0e + jr c, .got_list push bc push de push hl ld hl, wCurDeckCards - call Func_3b9a6 + call .GetCardCountMissing pop hl pop de pop bc - jr nc, .asm_3b952 + jr nc, .loop_deck_configuration + +; list at wTempCardList cards missing ld c, a -.asm_3b974 +.loop_append push hl push de ld h, $00 @@ -6604,73 +6773,84 @@ Func_3b92b: inc l inc l dec c - jr nz, .asm_3b974 - jr .asm_3b952 -.asm_3b988 + jr nz, .loop_append + jr .loop_deck_configuration + +.got_list +; append null terminator ld h, $00 ld de, wTempCardList add hl, de xor a ld [hli], a ld [hl], a +; display list ldtx bc, LackTheseCardsToBuildThisDeckText - ld hl, wd38a + ld hl, wCardConfirmationText ld a, c ld [hli], a ld a, b ld [hl], a call GetSelectedSavedDeckPtr ld de, wTempCardList - farcall Func_b59f + farcall HandleDeckStatusCardList_InSRAM ret -Func_3b9a6: - call Func_3b9ba - ld hl, wc000 +; hl = deck cards (wCurDeckCards) +; de = card id +; if (required count) > (owned count), return a = (shortage count) with carry +; otherwise clear carry +.GetCardCountMissing: + call GetCardCountFromDeck + ld hl, wTempCardCollection ; all owned cards add hl, de ld a, [hl] - and $7f + and CARD_COUNT_MASK cp b - jr c, .asm_3b9b5 + jr c, .not_enough +; enough or a ret -.asm_3b9b5 +.not_enough ld e, a ld a, b sub e scf ret -Func_3b9ba: +; hl = deck cards (wCurDeckCards) +; de = card id +; return b = count of the card in hl +GetCardCountFromDeck: push de - ld b, $00 -.asm_3b9bd + ld b, 0 +.loop_list push de ld e, [hl] inc hl ld d, [hl] inc hl - call Func_3b91d + call CheckIfCardIDIsZero_Bank0e ld a, e ld c, d pop de - jr c, .asm_3b9d4 + jr c, .done cp e - jr nz, .asm_3b9bd + jr nz, .loop_list ld a, c cp d - jr nz, .asm_3b9bd + jr nz, .loop_list inc b - jr .asm_3b9bd -.asm_3b9d4 + jr .loop_list +.done pop de ret -Func_3b9d6: +ShowUsedCardListFromBuiltDecks: ld a, [wSelectedDeckMachineEntry] ld [wCurDeck], a call GetSelectedSavedDeckPtr - ld de, $18 + ld de, DECK_NAME_SIZE add hl, de ld d, h ld e, l @@ -6678,22 +6858,27 @@ Func_3b9d6: farcall CopyDeckFromSRAM farcall SortCurDeckCardsByID farcall CreateCurDeckUniqueCardList + +; set: +; wTempCardCollection = all cards used in built decks +; wScratchCardCollection = all owned cards xor a farcall CreateCardCollectionListWithDeckCards call SwitchToWRAM2 - ld hl, wc000 + ld hl, wTempCardCollection ld de, wScratchCardCollection - ld b, $00 + ld b, 0 ; aka $100 bytes call CopyBBytesFromHLToDE_Bank0e - ld hl, wc000 + $100 + ld hl, wTempCardCollection + $100 ld de, wScratchCardCollection + $100 - ld b, $00 + ld b, 0 ; aka $100 bytes call CopyBBytesFromHLToDE_Bank0e call SwitchToWRAM1 - ld a, $80 + ld a, CARD_COUNT_FROM_BUILT_DECKS farcall CreateCardCollectionListWithDeckCards - ld hl, $0 -.asm_3ba1e + + ld hl, 0 +.loop_deck_configuration push hl ld l, h ld h, $00 @@ -6705,19 +6890,21 @@ Func_3b9d6: pop hl inc h inc h - call Func_3b91d - jr c, .asm_3ba54 + call CheckIfCardIDIsZero_Bank0e + jr c, .got_list push bc push de push hl ld hl, wCurDeckCards - call Func_3ba7d + call .GetCardCountNeededToTakeFromBuiltDecks pop hl pop de pop bc - jr nc, .asm_3ba1e + jr nc, .loop_deck_configuration + +; list at wTempCardList cards needed from built decks ld c, a -.asm_3ba40 +.loop_append push hl push de ld h, $00 @@ -6731,55 +6918,65 @@ Func_3b9d6: inc l inc l dec c - jr nz, .asm_3ba40 - jr .asm_3ba1e -.asm_3ba54 + jr nz, .loop_append + jr .loop_deck_configuration + +.got_list +; append null terminator ld h, $00 ld de, wTempCardList add hl, de xor a ld [hli], a ld [hl], a - ld a, [wd49e] +; set up text + ld a, [wNumCardsNeededToBuildSelectedDeckMissingInCardCollection] or a - jr nz, .asm_3ba68 + jr nz, .also_not_enough_in_card_collection ldtx bc, UsingTheseCardsInOtherDecksText - jr .asm_3ba6b -.asm_3ba68 + jr .display_list +.also_not_enough_in_card_collection ldtx bc, UsingTheseCardsTooInOtherDecksText -.asm_3ba6b - ld hl, wd38a +.display_list + ld hl, wCardConfirmationText ld a, c ld [hli], a ld a, b ld [hl], a call GetSelectedSavedDeckPtr ld de, wTempCardList - farcall Func_b59f + farcall HandleDeckStatusCardList_InSRAM ret -Func_3ba7d: - call Func_3b9ba - call PrintDeckMachineEntry.GetCardCountInScratchCardCollection +; hl = deck cards (wCurDeckCards) +; de = card id +; if that card isn't enough and is used in built decks, +; return a = min( (card count used in built decks), (shortage count) ) with carry +; otherwise clear carry +.GetCardCountNeededToTakeFromBuiltDecks: + call GetCardCountFromDeck + call GetCardCountInScratchCardCollection ld c, a ld a, b sub c - jr z, .asm_3ba9a - jr c, .asm_3ba9a +; a = (shortage count) = (card count needed) - (owned count) + jr z, .no_cards_to_take + jr c, .no_cards_to_take +; not enough, check built decks ld b, a - ld hl, wc000 + ld hl, wTempCardCollection ; all cards used in built decks add hl, de ld a, [hl] - and $7f - jr z, .asm_3ba9a + and CARD_COUNT_MASK + jr z, .no_cards_to_take cp b - jr c, .asm_3ba98 + jr c, .got_count_to_take ld a, b -.asm_3ba98 +.got_count_to_take scf ret -.asm_3ba9a - or a +.no_cards_to_take + or a ; clear carry ret _PrinterMenu_DeckConfiguration: @@ -6832,6 +7029,7 @@ _PrinterMenu_DeckConfiguration: ld [wCurScrollMenuItem], a jp .start_selection +; auto deck machines Func_3bb09: ld a, [wd548] or a @@ -6857,13 +7055,13 @@ Func_3bb09: call Func_3bc95 xor a .asm_3bb30 - ld hl, $5eb5 + ld hl, MenuParams_9eb5 farcall InitializeScrollMenuParameters ldtx hl, PleaseSelectDeckText call DrawWideTextBox_PrintText ld a, [wNumDeckMachineEntries] ld [wNumMenuItems], a - ld a, $01 + ld a, TRUE ld [wUnableToScrollDown], a xor a ld [wd119], a @@ -6878,7 +7076,7 @@ Func_3bb09: ld a, [wScrollMenuScrollOffset] ld [wTempScrollMenuScrollOffset], a ld b, a - ld a, [wTempCardTypeFilter] + ld a, [wCurScrollMenuItem] ld [wTempScrollMenuItem], a add b ld c, a @@ -6886,7 +7084,7 @@ Func_3bb09: or $80 ld [wCurDeck], a ld a, c - call Func_3afb8 + call GetAndLoadSelectedMachineDeckPtr push hl farcall CheckIfDeckHasCards pop hl @@ -6904,13 +7102,13 @@ Func_3bb09: ld [wScrollMenuScrollOffset], a call Func_3bc95 ld a, [wTempScrollMenuItem] - ld [wTempCardTypeFilter], a + ld [wCurScrollMenuItem], a jp .asm_3bb30 .asm_3bba2 call HandleScrollMenu.draw_visible_cursor ld a, [wScrollMenuScrollOffset] ld [wTempScrollMenuScrollOffset], a - ld a, [wTempCardTypeFilter] + ld a, [wCurScrollMenuItem] ld [wTempScrollMenuItem], a ld a, [hCurMenuItem] cp $ff @@ -6936,11 +7134,11 @@ Func_3bb09: .asm_3bbe6 ld a, [wCheckMenuCursorYPosition] sla a - ld hl, wCurSongBankBackup + ld hl, wCheckMenuCursorXPosition add [hl] or a jr nz, .asm_3bc0a - call Func_3b4eb + call TryBuildDeckMachineDeck ld a, [wTempScrollMenuItem] jp nc, .asm_3bb30 ld a, [wTempScrollMenuScrollOffset] @@ -6957,7 +7155,7 @@ Func_3bb09: ld a, [wScrollMenuScrollOffset] ld [wTempScrollMenuScrollOffset], a ld b, a - ld a, [wTempCardTypeFilter] + ld a, [wCurScrollMenuItem] ld [wTempScrollMenuItem], a add b ld c, a @@ -6967,14 +7165,14 @@ Func_3bb09: ld b, $00 ld hl, wd4b4 add hl, bc - ld bc, wd38a + ld bc, wCardConfirmationText ld a, [hli] ld [bc], a inc bc ld a, [hl] ld [bc], a pop af - call Func_3afb8 + call GetAndLoadSelectedMachineDeckPtr push hl farcall CheckIfDeckHasCards pop hl @@ -6982,12 +7180,12 @@ Func_3bb09: ld a, MENU_CONFIRM farcall PlaySFXConfirmOrCancel push hl - ld de, $18 + ld de, DECK_NAME_SIZE add hl, de ld d, h ld e, l pop hl - farcall Func_b57c + farcall HandleDeckStatusCardList ld a, [wTempScrollMenuScrollOffset] ld [wScrollMenuScrollOffset], a call Func_3bc95 @@ -7024,61 +7222,72 @@ Func_3bc95: call EnableLCD ret -Func_3bcd6: +; to build wSelectedDeckMachineEntry, +; try out all combinations of dismantling decks +; if none of the combinations work, return carry set +; otherwise, return a = DECK_* flags to be dismantled +; and load it to wDecksToBeDismantled +CheckWhichDecksToDismantleToBuildSavedDeck: xor a - ld [wd49a], a - ld a, $01 -.asm_3bcdc - call Func_3bd28 + ld [wDecksToBeDismantled], a + +; single deck + ld a, DECK_1 +.loop_single_built_decks + call .CheckIfCanBuild ret nc - sla a - cp $10 - jr nz, .asm_3bcdc - ld a, $03 - call Func_3bd28 + sla a ; next deck + cp 1 << NUM_DECKS + jr nz, .loop_single_built_decks + +; two-deck combinations + ld a, DECK_1 | DECK_2 + call .CheckIfCanBuild ret nc - ld a, $05 - call Func_3bd28 + ld a, DECK_1 | DECK_3 + call .CheckIfCanBuild ret nc - ld a, $09 - call Func_3bd28 + ld a, DECK_1 | DECK_4 + call .CheckIfCanBuild ret nc - ld a, $06 - call Func_3bd28 + ld a, DECK_2 | DECK_3 + call .CheckIfCanBuild ret nc - ld a, $0a - call Func_3bd28 + ld a, DECK_2 | DECK_4 + call .CheckIfCanBuild ret nc - ld a, $0c - call Func_3bd28 + ld a, DECK_3 | DECK_4 + call .CheckIfCanBuild ret nc - ld a, $07 - call Func_3bd28 +; three-deck combinations + ld a, DECK_1 | DECK_2 | DECK_3 + call .CheckIfCanBuild ret nc - ld a, $0b - call Func_3bd28 + ld a, DECK_1 | DECK_2 | DECK_4 + call .CheckIfCanBuild ret nc - ld a, $0d - call Func_3bd28 + ld a, DECK_1 | DECK_3 | DECK_4 + call .CheckIfCanBuild ret nc - ld a, $0e - call Func_3bd28 + ld a, DECK_2 | DECK_3 | DECK_4 + call .CheckIfCanBuild ret nc - ld a, $ff - call Func_3bd28 +; all + ld a, ALL_DECKS + call .CheckIfCanBuild ret -Func_3bd28: +.CheckIfCanBuild: push af ld hl, wSelectedDeckMachineEntry ld b, [hl] call CheckIfCanBuildSavedDeck - jr c, .asm_3bd38 + jr c, .cannot_build pop af - ld [wd49a], a + ld [wDecksToBeDismantled], a or a ret -.asm_3bd38 +.cannot_build pop af scf ret @@ -7207,7 +7416,7 @@ ReceiveDeckConfigurationMenu: ldtx hl, DeleteSavedDeckPromptText call YesOrNoMenuWithText jr nc, .save - ld a, [wTempCardTypeFilter] + ld a, [wCurScrollMenuItem] jr .start_selection .save @@ -7227,7 +7436,7 @@ ReceiveDeckConfigurationMenu: call DisableSRAM call SaveGame call ClearScreenAndDrawDeckMachineScreen - ld a, [wTempCardTypeFilter] + ld a, [wCurScrollMenuItem] ld hl, DeckMachineSelectionParams farcall InitializeScrollMenuParameters call DrawListScrollArrows @@ -7253,14 +7462,14 @@ ReceiveDeckConfigurationMenu: SaveDeckDataToWRAM2: push de - ld de, wc000 + ld de, wDeckToBuild call CopyListFromHLToDE_Bank0e pop de - ld hl, wc000 + DECK_NAME_SIZE + ld hl, wDeckToBuild + DECK_NAME_SIZE bank1call SaveDeckCards call SwitchToWRAM2 - ld hl, wc000 - ld de, w2d28e + ld hl, wDeckToBuild + ld de, wBigBackupDeckToBuild ld b, DECK_COMPRESSED_STRUCT_SIZE call CopyBBytesFromHLToDE_Bank0e call SwitchToWRAM1 @@ -7307,7 +7516,7 @@ OpenDeckSaveMachineFromDeckBuilding: call GetSelectedSavedDeckPtr ld d, h ld e, l - ld hl, w2d28e + ld hl, wBigBackupDeckToBuild ld b, DECK_COMPRESSED_STRUCT_SIZE call EnableSRAM call SwitchToWRAM2 diff --git a/src/home/menus.asm b/src/home/menus.asm index b9a1457..ce25772 100644 --- a/src/home/menus.asm +++ b/src/home/menus.asm @@ -138,14 +138,14 @@ HandleMenuInput:: ; B button pressed ld a, [wCurMenuItem] ld e, a - ld a, $ff + ld a, MENU_CANCEL ldh [hCurScrollMenuItem], a call PlayOpenOrExitScreenSFX scf ret -; plays an "open screen" sound (SFX_CONFIRM) if [hCurScrollMenuItem] != 0xff -; plays an "exit screen" sound (SFX_CANCEL) if [hCurScrollMenuItem] == 0xff +; if [hCurScrollMenuItem] = MENU_CANCEL (exit), play SFX_CANCEL, +; otherwise (open) SFX_CONFIRM PlayOpenOrExitScreenSFX:: push af ldh a, [hCurScrollMenuItem] diff --git a/src/wram.asm b/src/wram.asm index 72596d4..d19e657 100644 --- a/src/wram.asm +++ b/src/wram.asm @@ -44,6 +44,12 @@ NEXTU wCardPopCandidateList:: ; c000 ds CARD_COLLECTION_SIZE +NEXTU + +; buffer to store a target deck +wDeckToBuild:: ; c000 + ds DECK_BIG_TEMP_BUFFER_SIZE + ENDU SECTION "WRAM0 Duels 1", WRAM0 @@ -1334,7 +1340,7 @@ wCardPopRecordType:: ; ce45 ds $6 ; padding to align to $20 -wce4c:: ; ce4c +wTempBankWRAM:: ; ce4c ds $1 wWRAMBank:: ; ce4d @@ -2007,7 +2013,8 @@ wTempFilteredCardListNumCursorPositions:: ; d11c wd11d:: ; d11d ds $1 -wced7:: ; d11e +; tcg1: wced7 +wd11e:: ; d11e ds $1 wCardListVisibleOffsetBackup:: ; d11f @@ -2032,7 +2039,7 @@ wTempCardList:: ; d122 ; holds cards for the current deck wCurDeckCards:: ; d1c4 - ds $a2 + ds 2 * (DECK_CONFIG_BUFFER_SIZE + 1) ; list of all the different cards in a deck configuration wUniqueDeckCardList:: ; d266 @@ -2103,7 +2110,7 @@ wCurCardListPtr:: ; d388 ds $1 -wd38a:: ; d38a +wCardConfirmationText:: ; d38a ds $2 ds $2 @@ -2210,10 +2217,11 @@ wTempScrollMenuScrollOffset:: ; d47c wSelectedDeckMachineEntry:: ; d47d ds $1 -wd47e:: ; d47e - ds $18 +wDismantledDeckName:: ; d47e + ds DECK_NAME_SIZE -wd496:: ; d496 +; which deck slot to be used to build a new deck +wDeckSlotForNewDeck:: ; d496 ds $1 wDeckMachineTitleText:: ; d497 @@ -2222,10 +2230,10 @@ wDeckMachineTitleText:: ; d497 wNumDeckMachineEntries:: ; d499 ds $1 -wd49a:: ; d49a +wDecksToBeDismantled:: ; d49a ds $1 -wd49b:: ; d49b +wNumCardsNeededToBuildSelectedDeckUsedInBuiltDecks:: ; d49b ds $1 ; text ID to print in the text box when @@ -2233,9 +2241,17 @@ wd49b:: ; d49b wDeckMachineText:: ; d49c ds $2 -wd49e:: ; d49e +wNumCardsNeededToBuildSelectedDeckMissingInCardCollection:: ; d49e ds $1 +UNION + +; cards used in built decks, cards missing +wNumCardsNeededToBuildDeckMachineDecks:: ; d49f + ds (1 + 1) * NUM_DECK_SAVE_MACHINE_SLOTS + +NEXTU + wd49f:: ; d49f ds $1 @@ -2249,8 +2265,10 @@ wd4b4:: ; d4b4 ds $c -wd4c8:: ; d4c8 - ds $80 +wSelectedMachineDeck:: ; d4c8 + ds DECK_TEMP_BUFFER_SIZE + +ENDU wd548:: ; d548 ds $2 @@ -3597,32 +3615,32 @@ SECTION "WRAM2", WRAMX wScratchCardCollection:: ; d000 ds CARD_COLLECTION_SIZE -w2d200:: ; d200 - ds $80 +wBackup1DeckToBuild:: ; d200 + ds DECK_TEMP_BUFFER_SIZE -w2d280:: ; d280 - ds $6 +; $ff-terminated array of basic energy amount available to sub in, +; first in card constant order (not in type-flag order), +; then sorted in descending order when processed +; also a subbed deck flag after the sort +wNumRemainingBasicEnergyCardsForSubbedDeck:: ; d280 + ds NUM_COLORED_TYPES + 1 -w2d286:: ; d286 - ds $1 +; $ff-terminated index array [0, 5] +; mapped when wNumRemainingBasicEnergyCardsForSubbedDeck is sorted +wIndicesRemainingBasicEnergyCardsForSubbedDeck:: ; d287 + ds NUM_COLORED_TYPES + 1 -w2d287:: ; d287 - ds $6 +wBigBackupDeckToBuild:: ; d28e + ds DECK_BIG_TEMP_BUFFER_SIZE -w2d28d:: ; d28d - ds $1 - -w2d28e:: ; d28e - ds $100 - -w2d38e:: ; d38e - ds $80 +wBackup2DeckToBuild:: ; d38e + ds DECK_TEMP_BUFFER_SIZE wAutoDecks:: ; d40e ds DECK_COMPRESSED_STRUCT_SIZE * NUM_AUTO_DECK_MACHINE_SLOTS -w2d58e:: ; d58e - ds $80 +wBackup3DeckToBuild:: ; d58e + ds DECK_TEMP_BUFFER_SIZE SECTION "WRAM3", WRAMX From 0417c81741e7cd15fb9cdd0cea3e68a6cd99273d Mon Sep 17 00:00:00 2001 From: earthoul Date: Sun, 8 Feb 2026 00:17:50 +0900 Subject: [PATCH 2/9] Misc refactoring --- src/constants/map_constants.asm | 4 ++-- src/constants/npc_constants.asm | 4 ++-- src/constants/ow_anim_constants.asm | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/constants/map_constants.asm b/src/constants/map_constants.asm index 33ddb7b..821612d 100644 --- a/src/constants/map_constants.asm +++ b/src/constants/map_constants.asm @@ -123,8 +123,8 @@ DEF GR_ISLAND EQU $1 const MAP_GR_CASTLE_ENTRANCE ; $71 const MAP_GR_CASTLE ; $72 const MAP_GR_CASTLE_BIRURITCHI ; $73 - -DEF MAP_NONE EQU -1 + const_def -1 + const MAP_NONE ; $ff ; MAP_GFX_* ; referenced in MapHeaders, and others. see also: data/map_gfx.asm diff --git a/src/constants/npc_constants.asm b/src/constants/npc_constants.asm index 9fbdbeb..616a201 100644 --- a/src/constants/npc_constants.asm +++ b/src/constants/npc_constants.asm @@ -331,8 +331,8 @@ DEF NUM_PICS EQU const_value const NPC_WHITE_CASTLE_COIN ; $e6 const NPC_PURPLE_CASTLE_COIN ; $e7 const NPC_STRONGHOLD_PLATFORM ; $e8 - -DEF NPC_NONE EQU -1 + const_def -1 + const NPC_NONE ; $ff ; grand masters const_def diff --git a/src/constants/ow_anim_constants.asm b/src/constants/ow_anim_constants.asm index 411645a..9156011 100644 --- a/src/constants/ow_anim_constants.asm +++ b/src/constants/ow_anim_constants.asm @@ -43,7 +43,7 @@ const OW_ANIM_29 ; $29 const OW_ANIM_2A ; $2a const OW_ANIM_2B ; $2b -DEF const_value = $ff + const_def -1 const OW_ANIM_NONE ; $ff const_def From 13f858def05d607970952e861299c51880490ad0 Mon Sep 17 00:00:00 2001 From: earthoul Date: Sun, 8 Feb 2026 12:17:57 +0900 Subject: [PATCH 3/9] A few more misc refactoring --- src/engine/bank02.asm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/engine/bank02.asm b/src/engine/bank02.asm index 5ce0fc7..2e6933b 100644 --- a/src/engine/bank02.asm +++ b/src/engine/bank02.asm @@ -1063,11 +1063,11 @@ CopyDeckFromSRAM: WriteCardListsTerminatorBytes: xor a ld hl, wTempCardList - ld bc, $80 + ld bc, DECK_TEMP_BUFFER_SIZE add hl, bc ld [hl], a ; terminating byte ld hl, wCurDeckCards - ld bc, $80 + ld bc, DECK_TEMP_BUFFER_SIZE add hl, bc ld [hl], a ; terminating byte ret @@ -3591,6 +3591,7 @@ InitializeScrollMenuParameters: DeckMachineSelectionParams: scrollmenu_params 1, 2, 2, 0, NUM_DECK_MACHINE_VISIBLE_DECKS, SYM_CURSOR_R, SYM_SPACE, NULL +; auto deck machines MenuParams_9eb5: scrollmenu_params 1, 2, 2, 0, 4, SYM_CURSOR_R, SYM_SPACE, NULL @@ -5554,7 +5555,7 @@ PrintTotalNumberOfCardsInCollection: call CreateCardCollectionListWithDeckCards ; count all the cards in collection - ld bc, wTempCardCollection + 1 + ld bc, wTempCardCollection + GRASS_ENERGY ld de, 0 ld hl, 0 .loop_all_cards @@ -6800,7 +6801,7 @@ CardAlbum: ; b = set .CheckHasCardFromSet: ld de, 0 - ld hl, wTempCardCollection + $1 + ld hl, wTempCardCollection + GRASS_ENERGY ld b, a .loop_card_ids inc de @@ -7164,7 +7165,7 @@ HandleDeckStatusCardList_InSRAM: call CopyListFromHLToDEInSRAM pop hl ld de, wCurDeckCards - ld b, $80 + ld b, DECK_TEMP_BUFFER_SIZE call CopyBBytesFromHLToDE_Bank02 jr HandleDeckStatusCardList_Execute From 9f8c43f8fba09f0a70e996b8cb61a00e98ea9c2f Mon Sep 17 00:00:00 2001 From: earthoul Date: Mon, 9 Feb 2026 02:59:35 +0900 Subject: [PATCH 4/9] Refactor Auto Deck Machine engine and fix related labels --- src/constants/card_data_constants.asm | 3 + src/constants/menu_constants.asm | 26 ++- src/data/auto_deck_machine.asm | 162 +++++++------- src/engine/bank02.asm | 224 ++++++++++++------- src/engine/bank03.asm | 130 ++++++------ src/engine/bank07.asm | 2 +- src/engine/bank0a.asm | 295 ++++++++++++++------------ src/engine/bank0e.asm | 232 ++++++++++++-------- src/engine/bank0f.asm | 8 +- src/text/text2.asm | 214 +++++++++---------- src/text/text_offsets.asm | 214 +++++++++---------- src/wram.asm | 35 +-- 12 files changed, 865 insertions(+), 680 deletions(-) diff --git a/src/constants/card_data_constants.asm b/src/constants/card_data_constants.asm index 67e8260..57c83fc 100644 --- a/src/constants/card_data_constants.asm +++ b/src/constants/card_data_constants.asm @@ -26,6 +26,9 @@ DEF MAX_NUM_SAME_NAME_CARDS EQU 4 DEF MAX_NUM_SUB_ENERGY_CARDS EQU 9 DEF MAX_UNNAMED_DECK_NUM EQU 999 +DEF MAX_NUM_AUTO_DECK_LIST_DIFFERENT_CARDS EQU 43 +DEF AUTO_DECK_LIST_BUFFER_SIZE EQU 3 * MAX_NUM_AUTO_DECK_LIST_DIFFERENT_CARDS + 1 + ; card data offsets (data/cards.asm and card_data_struct) RSRESET diff --git a/src/constants/menu_constants.asm b/src/constants/menu_constants.asm index f0b4925..5033482 100644 --- a/src/constants/menu_constants.asm +++ b/src/constants/menu_constants.asm @@ -71,6 +71,12 @@ const DECKSAVEMACHINEMENU_BUILD ; 2 const DECKSAVEMACHINEMENU_CANCEL ; 3 +; auto deck machine options + const_def + const AUTODECKMACHINEMENU_BUILD ; 0 + const AUTODECKMACHINEMENU_CANCEL ; 1 + const AUTODECKMACHINEMENU_READ ; 2 + ; mailbox options const_def const MAILBOXMENU_READ ; 0 @@ -135,9 +141,27 @@ DEF NUM_FILTERED_LIST_VISIBLE_CARDS EQU 6 DEF NUM_DECK_STATUS_LIST_VISIBLE_CARDS EQU 5 DEF NUM_DECK_SAVE_MACHINE_SLOTS EQU 50 -DEF NUM_DECK_MACHINE_VISIBLE_DECKS EQU 5 +DEF NUM_DECK_MACHINE_VISIBLE_SLOTS EQU 5 ; decks or categories DEF NUM_AUTO_DECK_MACHINE_SLOTS EQU 4 +; auto deck machine 1 + const_def + const AUTO_DECK_BASIC ; 0 + const AUTO_DECK_GIVEN ; 1 + const AUTO_DECK_FIGHTING ; 2 + const AUTO_DECK_GRASS ; 3 + const AUTO_DECK_WATER ; 4 + const AUTO_DECK_FIRE ; 5 + const AUTO_DECK_LIGHTNING ; 6 + const AUTO_DECK_PSYCHIC ; 7 +DEF NUM_AUTO_DECK_MACHINE_REGULAR_CATEGORIES EQU const_value ; shared with machine 2 + const AUTO_DECK_SPECIAL ; 8 + const AUTO_DECK_LEGENDARY ; 9 +DEF NUM_AUTO_DECK_MACHINE_CATEGORIES EQU const_value ; shared with machine 2 + +; auto_deck args +DEF AUTO_DECK_ENTRY_SIZE EQU 6 + ; deck flags const_def const DECK_1_F ; $0 diff --git a/src/data/auto_deck_machine.asm b/src/data/auto_deck_machine.asm index ba3b6a7..770233d 100644 --- a/src/data/auto_deck_machine.asm +++ b/src/data/auto_deck_machine.asm @@ -1,4 +1,4 @@ -; each Auto Deck Machine section has 4 deck entries +; each Auto Deck Machine category has 4 deck entries ; each entry consists of ; its card list (see data/auto_deck_card_lists.asm) and ; two text IDs for its name and description (flavor) text @@ -12,263 +12,263 @@ ENDM AutoDeckMachine1Entries: ; basic auto_deck MachineStarterDeckList, \ - MachineStarterDeckText, \ + MachineStarterDeckName, \ MachineStarterDeckDescriptionText auto_deck MachineElectricFireDeckList, \ - MachineElectricFireDeckText, \ + MachineElectricFireDeckName, \ MachineElectricFireDeckDescriptionText auto_deck MachineBattleWaterDeckList, \ - MachineBattleWaterDeckText, \ + MachineBattleWaterDeckName, \ MachineBattleWaterDeckDescriptionText auto_deck MachineEsperGreenDeckList, \ - MachineEsperGreenDeckText, \ + MachineEsperGreenDeckName, \ MachineEsperGreenDeckDescriptionText ; gifts auto_deck MachineSweatAntiGR1DeckList, \ - MachineSweatAntiGR1DeckText, \ + MachineSweatAntiGR1DeckName, \ MachineSweatAntiGR1DeckDescriptionText auto_deck MachineGiveInAntiGR2DeckList, \ - MachineGiveInAntiGR2DeckText, \ + MachineGiveInAntiGR2DeckName, \ MachineGiveInAntiGR2DeckDescriptionText auto_deck MachineVengefulAntiGR3DeckList, \ - MachineVengefulAntiGR3DeckText, \ + MachineVengefulAntiGR3DeckName, \ MachineVengefulAntiGR3DeckDescriptionText auto_deck MachineUnforgivingAntiGR4DeckList, \ - MachineUnforgivingAntiGR4DeckText, \ + MachineUnforgivingAntiGR4DeckName, \ MachineUnforgivingAntiGR4DeckDescriptionText ; fighting auto_deck MachineAwesomeFossilsDeckList, \ - MachineAwesomeFossilsDeckText, \ + MachineAwesomeFossilsDeckName, \ MachineAwesomeFossilsDeckDescriptionText auto_deck MachineNewMachokeDeckList, \ - MachineNewMachokeDeckText, \ + MachineNewMachokeDeckName, \ MachineNewMachokeDeckDescriptionText auto_deck MachineRockFestivalDeckList, \ - MachineRockFestivalDeckText, \ + MachineRockFestivalDeckName, \ MachineRockFestivalDeckDescriptionText auto_deck MachineJabHookDeckList, \ - MachineJabHookDeckText, \ + MachineJabHookDeckName, \ MachineJabHookDeckDescriptionText ; grass auto_deck MachineSteadyIncreaseDeckList, \ - MachineSteadyIncreaseDeckText, \ + MachineSteadyIncreaseDeckName, \ MachineSteadyIncreaseDeckDescriptionText auto_deck MachineGatheringNidoranDeckList, \ - MachineGatheringNidoranDeckText, \ + MachineGatheringNidoranDeckName, \ MachineGatheringNidoranDeckDescriptionText auto_deck MachineNationalParkDeckList, \ - MachineNationalParkDeckText, \ + MachineNationalParkDeckName, \ MachineNationalParkDeckDescriptionText auto_deck MachineSelectiveBreedingDeckList, \ - MachineSelectiveBreedingDeckText, \ + MachineSelectiveBreedingDeckName, \ MachineSelectiveBreedingDeckDescriptionText ; water auto_deck MachineSplashingAboutDeckList, \ - MachineSplashingAboutDeckText, \ + MachineSplashingAboutDeckName, \ MachineSplashingAboutDeckDescriptionText auto_deck MachineBeachDeckList, \ - MachineBeachDeckText, \ + MachineBeachDeckName, \ MachineBeachDeckDescriptionText auto_deck MachineInsulationDeckList, \ - MachineInsulationDeckText, \ + MachineInsulationDeckName, \ MachineInsulationDeckDescriptionText auto_deck MachineAntarcticDeckList, \ - MachineAntarcticDeckText, \ + MachineAntarcticDeckName, \ MachineAntarcticDeckDescriptionText ; fire auto_deck MachineFlameFestivalDeckList, \ - MachineFlameFestivalDeckText, \ + MachineFlameFestivalDeckName, \ MachineFlameFestivalDeckDescriptionText auto_deck MachineElectricCurrentShockDeckList, \ - MachineElectricCurrentShockDeckText, \ + MachineElectricCurrentShockDeckName, \ MachineElectricCurrentShockDeckDescriptionText auto_deck MachineRiskyBlazeDeckList, \ - MachineRiskyBlazeDeckText, \ + MachineRiskyBlazeDeckName, \ MachineRiskyBlazeDeckDescriptionText auto_deck MachineRagingCharizardDeckList, \ - MachineRagingCharizardDeckText, \ + MachineRagingCharizardDeckName, \ MachineRagingCharizardDeckDescriptionText ; lightning auto_deck MachineZapdosPowerPlantDeckList, \ - MachineZapdosPowerPlantDeckText, \ + MachineZapdosPowerPlantDeckName, \ MachineZapdosPowerPlantDeckDescriptionText auto_deck MachineElectricShockDeckList, \ - MachineElectricShockDeckText, \ + MachineElectricShockDeckName, \ MachineElectricShockDeckDescriptionText auto_deck MachineOverflowDeckList, \ - MachineOverflowDeckText, \ + MachineOverflowDeckName, \ MachineOverflowDeckDescriptionText auto_deck MachineTripleZapdosDeckList, \ - MachineTripleZapdosDeckText, \ + MachineTripleZapdosDeckName, \ MachineTripleZapdosDeckDescriptionText ; psychic auto_deck MachineSpecialBarrierDeckList, \ - MachineSpecialBarrierDeckText, \ + MachineSpecialBarrierDeckName, \ MachineSpecialBarrierDeckDescriptionText auto_deck MachineEvolutionProhibitedDeckList, \ - MachineEvolutionProhibitedDeckText, \ + MachineEvolutionProhibitedDeckName, \ MachineEvolutionProhibitedDeckDescriptionText auto_deck MachineGhostDeckList, \ - MachineGhostDeckText, \ + MachineGhostDeckName, \ MachineGhostDeckDescriptionText auto_deck MachinePuppetMasterDeckList, \ - MachinePuppetMasterDeckText, \ + MachinePuppetMasterDeckName, \ MachinePuppetMasterDeckDescriptionText ; special auto_deck MachineMewLv15DeckList, \ - MachineMewLv15DeckText, \ + MachineMewLv15DeckName, \ MachineMewLv15DeckDescriptionText auto_deck MachineVenusaurLv64DeckList, \ - MachineVenusaurLv64DeckText, \ + MachineVenusaurLv64DeckName, \ MachineVenusaurLv64DeckDescriptionText auto_deck MachineMutualDestructionDeckList, \ - MachineMutualDestructionDeckText, \ + MachineMutualDestructionDeckName, \ MachineMutualDestructionDeckDescriptionText auto_deck MachineEverybodySurfDeckList, \ - MachineEverybodySurfDeckText, \ + MachineEverybodySurfDeckName, \ MachineEverybodySurfDeckDescriptionText ; legendary auto_deck MachineGrandFireDeckList, \ - MachineGrandFireDeckText, \ + MachineGrandFireDeckName, \ MachineGrandFireDeckDescriptionText auto_deck MachineLegendaryFossilDeckList, \ - MachineLegendaryFossilDeckText, \ + MachineLegendaryFossilDeckName, \ MachineLegendaryFossilDeckDescriptionText auto_deck MachineWaterLegendDeckList, \ - MachineWaterLegendDeckText, \ + MachineWaterLegendDeckName, \ MachineWaterLegendDeckDescriptionText auto_deck MachineGreatDragonDeckList, \ - MachineGreatDragonDeckText, \ + MachineGreatDragonDeckName, \ MachineGreatDragonDeckDescriptionText AutoDeckMachine2Entries: ; dark grass auto_deck MachineInsectCollectionDeckList, \ - MachineInsectCollectionDeckText, \ + MachineInsectCollectionDeckName, \ MachineInsectCollectionDeckDescriptionText auto_deck MachineCaveExplorationDeckList, \ - MachineCaveExplorationDeckText, \ + MachineCaveExplorationDeckName, \ MachineCaveExplorationDeckDescriptionText auto_deck MachineOminousMeadowDeckList, \ - MachineOminousMeadowDeckText, \ + MachineOminousMeadowDeckName, \ MachineOminousMeadowDeckDescriptionText auto_deck MachineAtrociousWeezingDeckList, \ - MachineAtrociousWeezingDeckText, \ + MachineAtrociousWeezingDeckName, \ MachineAtrociousWeezingDeckDescriptionText ; dark lightning auto_deck MachineTheBenchIsAlsoASurpriseDeckList, \ - MachineTheBenchIsAlsoASurpriseDeckText, \ + MachineTheBenchIsAlsoASurpriseDeckName, \ MachineTheBenchIsAlsoASurpriseDeckDescriptionText auto_deck MachineEnergyConservationDeckList, \ - MachineEnergyConservationDeckText, \ + MachineEnergyConservationDeckName, \ MachineEnergyConservationDeckDescriptionText auto_deck MachineSonicboomDeckList, \ - MachineSonicboomDeckText, \ + MachineSonicboomDeckName, \ MachineSonicboomDeckDescriptionText auto_deck MachineRageOfTheHeavensDeckList, \ - MachineRageOfTheHeavensDeckText, \ + MachineRageOfTheHeavensDeckName, \ MachineRageOfTheHeavensDeckDescriptionText ; dark water auto_deck MachineDarkWaterDeckList, \ - MachineDarkWaterDeckText, \ + MachineDarkWaterDeckName, \ MachineDarkWaterDeckDescriptionText auto_deck MachineQuickFreezeDeckList, \ - MachineQuickFreezeDeckText, \ + MachineQuickFreezeDeckName, \ MachineQuickFreezeDeckDescriptionText auto_deck MachineWhirlpoolShowerDeckList, \ - MachineWhirlpoolShowerDeckText, \ + MachineWhirlpoolShowerDeckName, \ MachineWhirlpoolShowerDeckDescriptionText auto_deck MachineWaterGangDeckList, \ - MachineWaterGangDeckText, \ + MachineWaterGangDeckName, \ MachineWaterGangDeckDescriptionText ; dark fire auto_deck MachineFireballDeckList, \ - MachineFireballDeckText, \ + MachineFireballDeckName, \ MachineFireballDeckDescriptionText auto_deck MachineCompleteCombustionDeckList, \ - MachineCompleteCombustionDeckText, \ + MachineCompleteCombustionDeckName, \ MachineCompleteCombustionDeckDescriptionText auto_deck MachineOminousSpiritFlamesDeckList, \ - MachineOminousSpiritFlamesDeckText, \ + MachineOminousSpiritFlamesDeckName, \ MachineOminousSpiritFlamesDeckDescriptionText auto_deck MachineEternalFireDeckList, \ - MachineEternalFireDeckText, \ + MachineEternalFireDeckName, \ MachineEternalFireDeckDescriptionText ; dark fighting auto_deck MachineBewareTheTrapDeckList, \ - MachineBewareTheTrapDeckText, \ + MachineBewareTheTrapDeckName, \ MachineBewareTheTrapDeckDescriptionText auto_deck MachineOgresKickDeckList, \ - MachineOgresKickDeckText, \ + MachineOgresKickDeckName, \ MachineOgresKickDeckDescriptionText auto_deck MachineRockBlastDeckList, \ - MachineRockBlastDeckText, \ + MachineRockBlastDeckName, \ MachineRockBlastDeckDescriptionText auto_deck MachineHeavyWorkDeckList, \ - MachineHeavyWorkDeckText, \ + MachineHeavyWorkDeckName, \ MachineHeavyWorkDeckDescriptionText ; dark psychic auto_deck MachineSlowbrosFishingDeckList, \ - MachineSlowbrosFishingDeckText, \ + MachineSlowbrosFishingDeckName, \ MachineSlowbrosFishingDeckDescriptionText auto_deck MachineDirectHitDeckList, \ - MachineDirectHitDeckText, \ + MachineDirectHitDeckName, \ MachineDirectHitDeckDescriptionText auto_deck MachineBadDreamDeckList, \ - MachineBadDreamDeckText, \ + MachineBadDreamDeckName, \ MachineBadDreamDeckDescriptionText auto_deck MachineBenchPanicDeckList, \ - MachineBenchPanicDeckText, \ + MachineBenchPanicDeckName, \ MachineBenchPanicDeckDescriptionText ; colorless auto_deck MachineSnorlaxGuardDeckList, \ - MachineSnorlaxGuardDeckText, \ + MachineSnorlaxGuardDeckName, \ MachineSnorlaxGuardDeckDescriptionText auto_deck MachineEyeOfTheStormDeckList, \ - MachineEyeOfTheStormDeckText, \ + MachineEyeOfTheStormDeckName, \ MachineEyeOfTheStormDeckDescriptionText auto_deck MachineSuddenGrowthDeckList, \ - MachineSuddenGrowthDeckText, \ + MachineSuddenGrowthDeckName, \ MachineSuddenGrowthDeckDescriptionText auto_deck MachineKingDragoniteDeckList, \ - MachineKingDragoniteDeckText, \ + MachineKingDragoniteDeckName, \ MachineKingDragoniteDeckDescriptionText ; dark special auto_deck MachineDarkCharizardDeckList, \ - MachineDarkCharizardDeckText, \ + MachineDarkCharizardDeckName, \ MachineDarkCharizardDeckDescriptionText auto_deck MachineDarkBlastoiseDeckList, \ - MachineDarkBlastoiseDeckText, \ + MachineDarkBlastoiseDeckName, \ MachineDarkBlastoiseDeckDescriptionText auto_deck MachineDarkVenusaurDeckList, \ - MachineDarkVenusaurDeckText, \ + MachineDarkVenusaurDeckName, \ MachineDarkVenusaurDeckDescriptionText auto_deck MachineDarkDragoniteDeckList, \ - MachineDarkDragoniteDeckText, \ + MachineDarkDragoniteDeckName, \ MachineDarkDragoniteDeckDescriptionText ; rare auto_deck MachinePerfectHealthDeckList, \ - MachinePerfectHealthDeckText, \ + MachinePerfectHealthDeckName, \ MachinePerfectHealthDeckDescriptionText auto_deck MachineSuperSoakerDeckList, \ - MachineSuperSoakerDeckText, \ + MachineSuperSoakerDeckName, \ MachineSuperSoakerDeckDescriptionText auto_deck MachineHellsDemonDeckList, \ - MachineHellsDemonDeckText, \ + MachineHellsDemonDeckName, \ MachineHellsDemonDeckDescriptionText auto_deck MachinePremiumThunderDeckList, \ - MachinePremiumThunderDeckText, \ + MachinePremiumThunderDeckName, \ MachinePremiumThunderDeckDescriptionText ; mysterious auto_deck MachineMysteriousMewtwoDeckList, \ - MachineMysteriousMewtwoDeckText, \ + MachineMysteriousMewtwoDeckName, \ MachineMysteriousMewtwoDeckDescriptionText auto_deck MachineHeavenlyLugiaDeckList, \ - MachineHeavenlyLugiaDeckText, \ + MachineHeavenlyLugiaDeckName, \ MachineHeavenlyLugiaDeckDescriptionText auto_deck MachineBrutalTrainersDeckList, \ - MachineBrutalTrainersDeckText, \ + MachineBrutalTrainersDeckName, \ MachineBrutalTrainersDeckDescriptionText auto_deck MachineDreadfulParalysisDeckList, \ - MachineDreadfulParalysisDeckText, \ + MachineDreadfulParalysisDeckName, \ MachineDreadfulParalysisDeckDescriptionText diff --git a/src/engine/bank02.asm b/src/engine/bank02.asm index 2e6933b..59ffa43 100644 --- a/src/engine/bank02.asm +++ b/src/engine/bank02.asm @@ -525,143 +525,193 @@ PlayAreaIconCoordinates: db 0, 2 db 0, 6 db 0, 4 +; 0x877a SECTION "Bank 2@47d3", ROMX[$47d3], BANK[$2] -Func_87d3: +; handle player input in check menu +; works out which cursor coordinate to go to +; and sets carry flag if A or B is pressed +; returns a = MENU_CONFIRM if A pressed +; returns a = MENU_CANCEL if B pressed +HandleCheckMenuInput_YourOrOppPlayArea: xor a ld [wMenuInputSFX], a ld a, [wCheckMenuCursorXPosition] ld d, a ld a, [wCheckMenuCursorYPosition] ld e, a + ldh a, [hDPadHeld] or a - jr z, .asm_8852 + jr z, .no_pad ld a, [wd0cd] - and $80 + and %10000000 ldh a, [hDPadHeld] - jr nz, .asm_881c + jr nz, .check_vertical bit B_PAD_LEFT, a - jr nz, .asm_87f5 + jr nz, .horizontal bit B_PAD_RIGHT, a - jr z, .asm_881c -.asm_87f5 + jr z, .check_vertical + +; d = x, e = y + +.horizontal ld a, [wd0cd] - and $7f + and %01111111 cp $01 - jr z, .asm_8809 + jr z, .incr_y_wrap cp $02 - jr z, .asm_8810 + jr z, .toggle_x + +; if y != 0, y -= 1 ld a, e or a - jr z, .asm_8816 + jr z, .step_x_parity dec e - jr .asm_8816 -.asm_8809 + jr .step_x_parity + +; if y = 0, y += 1 +.incr_y_wrap ld a, e or a - jr nz, .asm_8816 + jr nz, .step_x_parity inc e - jr .asm_8816 -.asm_8810 - ld a, $01 + jr .step_x_parity + +; x = 1 - x +.toggle_x + ld a, 1 sub d ld d, a - jr .asm_883c -.asm_8816 + jr .erase + +; incr x if even, decr if odd +.step_x_parity ld a, d - xor $01 + xor 1 ld d, a - jr .asm_883c -.asm_881c - bit 6, a - jr nz, .asm_8824 - bit 7, a - jr z, .asm_8852 -.asm_8824 + jr .erase + +.check_vertical + bit B_PAD_UP, a + jr nz, .vertical + bit B_PAD_DOWN, a + jr z, .no_pad + +.vertical ld a, [wd0cd] - and $7f + and %01111111 cp $02 - jr z, .asm_8838 + jr z, .toggle_y + +; if x != 0, x -= 1 ld a, d or a - jr z, .asm_8832 + jr z, .step_y_parity dec d -.asm_8832 + +; incr y if even, decr if odd +.step_y_parity ld a, e - xor $01 + xor 1 ld e, a - jr .asm_883c -.asm_8838 - ld a, $01 + jr .erase + +; y = 1 - y +.toggle_y + ld a, 1 sub e ld e, a -.asm_883c + +.erase ld a, SFX_CURSOR ld [wMenuInputSFX], a push de - call .asm_8884 + call EraseCheckMenuCursor_YourOrOppPlayArea pop de + +; update x, y ld a, d ld [wCheckMenuCursorXPosition], a ld a, e ld [wCheckMenuCursorYPosition], a + +; reset blink xor a ld [wScrollMenuCursorBlinkCounter], a -.asm_8852 + +.no_pad ldh a, [hKeysPressed] and PAD_A | PAD_B - jr z, .asm_886d + jr z, .no_input and PAD_A - jr nz, .asm_8863 + jr nz, .a_btn_pressed + +; b btn pressed ld a, MENU_CANCEL call PlaySFXConfirmOrCancel scf ret -.asm_8863 - call .asm_88a3 + +.a_btn_pressed + call DisplayCheckMenuCursor_YourOrOppPlayArea ld a, MENU_CONFIRM call PlaySFXConfirmOrCancel scf ret -.asm_886d + +.no_input ld a, [wMenuInputSFX] or a - jr z, .asm_8876 + jr z, .check_blink call PlaySFX -.asm_8876 + +.check_blink ld hl, wScrollMenuCursorBlinkCounter ld a, [hl] inc [hl] - and $0f - ret nz - ld a, $0f - bit 4, [hl] - jr z, .asm_8886 -.asm_8884 - ld a, $00 -.asm_8886 + and %00001111 + ret nz ; only update cursor if blink's lower nibble is 0 + +; draw cursor + ld a, SYM_CURSOR_R + bit 4, [hl] ; only draw cursor if blink counter's fourth bit is not set + jr z, DrawCheckMenuCursor_YourOrOppPlayArea +; fallthrough + +; draw a space in the cursor position +EraseCheckMenuCursor_YourOrOppPlayArea: + ld a, SYM_SPACE +; fallthrough + +; for a = tile byte, +; draw it in the curosr position +; by converting the position to coordinates +DrawCheckMenuCursor_YourOrOppPlayArea: ld e, a - ld a, $0a + ld a, 10 ld l, a ld a, [wCheckMenuCursorXPosition] ld h, a call HtimesL ld a, l - add $01 + add 1 ld b, a ld a, [wCheckMenuCursorYPosition] sla a - add $0e + add 14 ld c, a + +; b = 10x + 1, c = 2y + 14 ld a, e call WriteByteToBGMap0 or a ret -.asm_88a3: - ld a, $0f - jr .asm_8886 + +DisplayCheckMenuCursor_YourOrOppPlayArea: + ld a, SYM_CURSOR_R + jr DrawCheckMenuCursor_YourOrOppPlayArea ; 0x88a7 SECTION "Bank 2@4acb", ROMX[$4acb], BANK[$2] @@ -1569,9 +1619,9 @@ ResetCheckMenuCursorPositionAndBlink: ; 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 +; and sets carry flag if A or B is pressed +; returns a = MENU_CONFIRM if A pressed +; returns a = MENU_CANCEL if B pressed HandleCheckMenuInput: xor a ld [wMenuInputSFX], a @@ -1579,6 +1629,7 @@ HandleCheckMenuInput: ld d, a ld a, [wCheckMenuCursorYPosition] ld e, a + ldh a, [hDPadHeld] or a jr z, .no_pad @@ -1586,49 +1637,67 @@ HandleCheckMenuInput: jr nz, .horizontal bit B_PAD_RIGHT, a jr z, .check_vertical + +; d = x, e = y + +; x coordinate +; incr if even, decr if odd .horizontal ld a, d - xor $01 ; flips x coordinate + xor 1 ld d, a - jr .okay + jr .erase + .check_vertical bit B_PAD_UP, a jr nz, .vertical bit B_PAD_DOWN, a jr z, .no_pad + +; y coordinate +; incr if even, decr if odd .vertical ld a, e - xor $01 ; flips y coordinate + xor 1 ld e, a -.okay + +.erase ld a, SFX_CURSOR ld [wMenuInputSFX], a push de call EraseCheckMenuCursor pop de + +; update x, y ld a, d ld [wCheckMenuCursorXPosition], a ld a, e ld [wCheckMenuCursorYPosition], a + +; reset blink xor a ld [wScrollMenuCursorBlinkCounter], a + .no_pad ldh a, [hKeysPressed] and PAD_A | PAD_B jr z, .no_input and PAD_A - jr nz, .a_press + jr nz, .a_btn_pressed + +; b btn pressed ld a, MENU_CANCEL call PlaySFXConfirmOrCancel scf ret -.a_press +.a_btn_pressed call DisplayCheckMenuCursor ld a, MENU_CONFIRM call PlaySFXConfirmOrCancel scf ret + .no_input ld a, [wMenuInputSFX] or a @@ -1646,14 +1715,14 @@ HandleCheckMenuInput: bit 4, [hl] ; only draw cursor if blink counter's fourth bit is not set jr z, DrawCheckMenuCursor -; draws in the cursor position +; draw a space in the cursor position EraseCheckMenuCursor: ld a, SYM_SPACE ; fallthrough -; draws in the cursor position -; input: -; a = tile byte to draw +; for a = tile byte, +; draw it in the curosr position +; by converting the position to coordinates DrawCheckMenuCursor: ld e, a ld a, 10 @@ -1668,6 +1737,8 @@ DrawCheckMenuCursor: sla a add 14 ld c, a + +; b = 10x + 1, c = 2y + 14 ld a, e call WriteByteToBGMap0 or a @@ -3589,11 +3660,10 @@ InitializeScrollMenuParameters: ret DeckMachineSelectionParams: - scrollmenu_params 1, 2, 2, 0, NUM_DECK_MACHINE_VISIBLE_DECKS, SYM_CURSOR_R, SYM_SPACE, NULL + scrollmenu_params 1, 2, 2, 0, NUM_DECK_MACHINE_VISIBLE_SLOTS, SYM_CURSOR_R, SYM_SPACE, NULL -; auto deck machines -MenuParams_9eb5: - scrollmenu_params 1, 2, 2, 0, 4, SYM_CURSOR_R, SYM_SPACE, NULL +AutoDeckMachineDeckSelectionParams: + scrollmenu_params 1, 2, 2, 0, NUM_AUTO_DECK_MACHINE_SLOTS, SYM_CURSOR_R, SYM_SPACE, NULL HandleCardSelectionInput: xor a ; FALSE @@ -7906,4 +7976,4 @@ PrinterMenu_DeckConfiguration: ret AutoDeckMachineMenuParams: - scrollmenu_params 4, 2, 2, 0, NUM_DECK_MACHINE_VISIBLE_DECKS, SYM_CURSOR_R, SYM_SPACE, NULL + scrollmenu_params 4, 2, 2, 0, NUM_DECK_MACHINE_VISIBLE_SLOTS, SYM_CURSOR_R, SYM_SPACE, NULL diff --git a/src/engine/bank03.asm b/src/engine/bank03.asm index 0d8c91d..66227d1 100644 --- a/src/engine/bank03.asm +++ b/src/engine/bank03.asm @@ -2319,23 +2319,27 @@ ENDR pop bc ret -; jump to .check_pointers[a], set carry if the event is set, clear carry if not -CheckTCGIslandMilestoneEvents: +; a = machine 1 category index +; jump to .event_table[a] +; return a = event flag(s), with carry if nz, with no carry otherwise +; single event check: category unlock +; multiple : per-deck unlock +CheckCurAutoDeckMachine1CategoryUnlockEvents: push bc push de push hl sla a - ld hl, .check_pointers + ld hl, .event_table add_hl_a ld a, [hli] ld h, [hl] ld l, a jp hl -.jump_set_carry: +.unlocked_from_start jp .set_carry -.check_four_tcgisland_coins: +.get_four_tcgisland_coins ld a, EVENT_GOT_KABUTO_COIN call GetEventValue push af @@ -2351,58 +2355,56 @@ CheckTCGIslandMilestoneEvents: ld c, 4 xor a ld d, a - ; fallthrough -.loop_bitmask_1 +.loop_bitmask_four_coins sla d pop af - jr z, .next_1 + jr z, .next_coin set 0, d - ; fallthrough -.next_1 +.next_coin dec c - jr nz, .loop_bitmask_1 + jr nz, .loop_bitmask_four_coins ld a, d or a jp nz, .set_carry jp .clear_carry -.check_gr_coin_top_left: +.get_gr_coin_top_left ld a, EVENT_GOT_GR_COIN_PIECE_TOP_LEFT call GetEventValue jp nz, .set_carry jp .clear_carry -.check_gr_coin_top_right: +.get_gr_coin_top_right ld a, EVENT_GOT_GR_COIN_PIECE_TOP_RIGHT call GetEventValue jp nz, .set_carry jp .clear_carry -.check_starmie_coin: +.get_starmie_coin ld a, EVENT_GOT_STARMIE_COIN call GetEventValue jp nz, .set_carry jp .clear_carry -.check_gr_coin_bottom_left: +.get_gr_coin_bottom_left ld a, EVENT_GOT_GR_COIN_PIECE_BOTTOM_LEFT call GetEventValue jp nz, .set_carry jp .clear_carry -.check_pikachu_coin: +.get_pikachu_coin ld a, EVENT_GOT_PIKACHU_COIN call GetEventValue jp nz, .set_carry jp .clear_carry -.check_gr_coin_bottom_right: +.get_gr_coin_bottom_right ld a, EVENT_GOT_GR_COIN_PIECE_BOTTOM_RIGHT call GetEventValue jp nz, .set_carry jp .clear_carry -.check_final_cup_or_postgame: +.win_final_cup_or_postgame ld a, EVENT_WON_FINAL_CUP call GetEventValue push af @@ -2412,37 +2414,35 @@ CheckTCGIslandMilestoneEvents: ld c, 2 xor a ld d, a - ; fallthrough -.loop_bitmask_2 +.loop_bitmask_events sla d sla d pop af - jr z, .next_2 + jr z, .next_event set 0, d set 1, d - ; fallthrough -.next_2 +.next_event dec c - jr nz, .loop_bitmask_2 + jr nz, .loop_bitmask_events ld a, d or a jp nz, .set_carry jp .clear_carry -.check_event_db: +.win_grand_master_cup: ld a, EVENT_WON_GRAND_MASTER_CUP call GetEventValue jp nz, .set_carry jp .clear_carry -.set_carry: +.set_carry pop hl pop de pop bc scf ret -.clear_carry: +.clear_carry pop hl pop de pop bc @@ -2450,99 +2450,101 @@ CheckTCGIslandMilestoneEvents: ccf ret -.check_pointers: - dw .jump_set_carry - dw .check_four_tcgisland_coins - dw .check_gr_coin_top_left - dw .check_gr_coin_top_right - dw .check_starmie_coin - dw .check_gr_coin_bottom_left - dw .check_pikachu_coin - dw .check_gr_coin_bottom_right - dw .check_final_cup_or_postgame - dw .check_event_db +.event_table + dw .unlocked_from_start + dw .get_four_tcgisland_coins + dw .get_gr_coin_top_left + dw .get_gr_coin_top_right + dw .get_starmie_coin + dw .get_gr_coin_bottom_left + dw .get_pikachu_coin + dw .get_gr_coin_bottom_right + dw .win_final_cup_or_postgame + dw .win_grand_master_cup -; jump to .check_pointers[a], set carry if the event is set, clear carry if not -CheckGRIslandMilestoneEvents: +; a = machine 2 category index +; jump to .event_table[a] +; return a = event flag(s) with carry if nz, with no carry otherwise +CheckCurAutoDeckMachine2CategoryUnlockEvents: push bc push de push hl sla a - ld hl, .check_pointers + ld hl, .event_table add_hl_a ld a, [hli] ld h, [hl] ld l, a jp hl -.check_golbat_coin: +.get_golbat_coin ld a, EVENT_GOT_GOLBAT_COIN call GetEventValue jp nz, .set_carry jp .clear_carry -.check_magnemite_coin: +.get_magnemite_coin ld a, EVENT_GOT_MAGNEMITE_COIN call GetEventValue jp nz, .set_carry jp .clear_carry -.check_psyduck_coin: +.get_psyduck_coin ld a, EVENT_GOT_PSYDUCK_COIN call GetEventValue jp nz, .set_carry jp .clear_carry -.check_magmar_coin: +.get_magmar_coin ld a, EVENT_GOT_MAGMAR_COIN call GetEventValue jp nz, .set_carry jp .clear_carry -.check_machamp_coin: +.get_machamp_coin ld a, EVENT_GOT_MACHAMP_COIN call GetEventValue jp nz, .set_carry jp .clear_carry -.check_mew_coin: +.get_mew_coin ld a, EVENT_GOT_MEW_COIN call GetEventValue jp nz, .set_carry jp .clear_carry -.check_snorlax_coin: +.get_snorlax_coin ld a, EVENT_GOT_SNORLAX_COIN call GetEventValue jp nz, .set_carry jp .clear_carry -.check_rui_roadblock: +.enter_biruritchi_room ld a, EVENT_GR_CASTLE_STAIRS_RUI_ROADBLOCK call GetEventValue jp nz, .set_carry jp .clear_carry -.check_battled_ishihara: +.battle_ishihara ld a, EVENT_BATTLED_ISHIHARA call GetEventValue jp nz, .set_carry jp .clear_carry -.check_postgame: +.postgame ld a, EVENT_MASONS_LAB_CHALLENGE_MACHINE_STATE call GetEventValue jp nz, .set_carry jp .clear_carry -.set_carry: +.set_carry pop hl pop de pop bc scf ret -.clear_carry: +.clear_carry pop hl pop de pop bc @@ -2550,17 +2552,17 @@ CheckGRIslandMilestoneEvents: ccf ret -.check_pointers: - dw .check_golbat_coin - dw .check_magnemite_coin - dw .check_psyduck_coin - dw .check_magmar_coin - dw .check_machamp_coin - dw .check_mew_coin - dw .check_snorlax_coin - dw .check_rui_roadblock - dw .check_battled_ishihara - dw .check_postgame +.event_table + dw .get_golbat_coin + dw .get_magnemite_coin + dw .get_psyduck_coin + dw .get_magmar_coin + dw .get_machamp_coin + dw .get_mew_coin + dw .get_snorlax_coin + dw .enter_biruritchi_room + dw .battle_ishihara + dw .postgame GetNumberOfDeckDiagnosisStepsUnlocked: push bc diff --git a/src/engine/bank07.asm b/src/engine/bank07.asm index 824428a..3949d52 100644 --- a/src/engine/bank07.asm +++ b/src/engine/bank07.asm @@ -5689,7 +5689,7 @@ Func_1e849: farcall Func_10252 ret -Func_1e855: +AutoDeckMachine: farcall Func_1022a farcall ClearSpriteAnimsAndSetInitialGraphicsConfiguration farcall HandleAutoDeckMenu diff --git a/src/engine/bank0a.asm b/src/engine/bank0a.asm index d3fa76d..4bc9a38 100644 --- a/src/engine/bank0a.asm +++ b/src/engine/bank0a.asm @@ -3316,31 +3316,34 @@ AIDeckSpecificBenchScore: INCLUDE "src/data/auto_deck_list.asm" INCLUDE "src/data/auto_deck_machine.asm" -Func_2bb32: +ReadAutoDeckConfiguration: call EnableSRAM - ld a, [wd4b3] + ld a, [wSelectedAutoDeckMachineCategory] ld l, a - ld h, 24 + ld h, AUTO_DECK_ENTRY_SIZE * NUM_AUTO_DECK_MACHINE_SLOTS call HtimesL - ld a, [wd548] + ld a, [wAutoDeckMachineIndex] or a jr nz, .machine_2 ; machine 1 ld bc, AutoDeckMachine1Entries - jr .got_addr + jr .set_entry_offset .machine_2 ld bc, AutoDeckMachine2Entries -.got_addr +.set_entry_offset add hl, bc - ld bc, $0 -.loop - call Func_2bb7f - call Func_2bbbb + +; hl = ptr to entries under selected category + lb bc, 0, 0 +.loop_decks + call .GetPointerToWRAMAutoDeck + call ReadCurAutoDeckConfiguration inc hl inc hl - call Func_2bbf9 + call ReadCurAutoDeckName +; set de = wAutoDeckMachineTexts[c], but verbosely push hl - ld de, wd4b4 + ld de, wAutoDeckMachineTexts ld h, c ld l, 2 call HtimesL @@ -3348,23 +3351,27 @@ Func_2bb32: ld d, h ld e, l pop hl +; load text ld a, [hli] ld [de], a inc de ld a, [hli] ld [de], a - call Func_2bb8e +; next deck + call .CheckPerDeckUnlockEvents inc b ld a, b - cp 4 - jr nz, .loop + cp NUM_AUTO_DECK_MACHINE_SLOTS + jr nz, .loop_decks ld a, c ld [wNumDeckMachineEntries], a call DisableSRAM ret -Func_2bb7f: +; c = deck position +; return de = deck +.GetPointerToWRAMAutoDeck: push hl ld l, c ld h, DECK_COMPRESSED_STRUCT_SIZE @@ -3376,42 +3383,45 @@ Func_2bb7f: pop hl ret -Func_2bb8e: - ld a, [wd4b3] - cp $01 - jr z, .asm_2bb9b - cp $08 - jr z, .asm_2bb9b +; checks for machine 1 +; harmless bug: +; machine 2 still checks them but doesn't get affected +.CheckPerDeckUnlockEvents: + ld a, [wSelectedAutoDeckMachineCategory] + cp AUTO_DECK_GIVEN + jr z, .per_deck_check + cp AUTO_DECK_SPECIAL + jr z, .per_deck_check inc c ret -.asm_2bb9b +.per_deck_check push de push hl push bc - ld a, [wd4b3] - farcall CheckTCGIslandMilestoneEvents + ld a, [wSelectedAutoDeckMachineCategory] + farcall CheckCurAutoDeckMachine1CategoryUnlockEvents inc b - ld e, $01 -.asm_2bba8 + ld e, 1 +.loop_bitmask dec b - jr z, .asm_2bbaf + jr z, .got_bitmask sla e - jr .asm_2bba8 -.asm_2bbaf + jr .loop_bitmask +.got_bitmask and e or a - jr z, .asm_2bbb7 + jr z, .skip_deck pop bc inc c - jr .asm_2bbb8 -.asm_2bbb7 + jr .done_per_deck_check +.skip_deck pop bc -.asm_2bbb8 +.done_per_deck_check pop hl pop de ret -Func_2bbbb: +ReadCurAutoDeckConfiguration: push hl push bc push de @@ -3421,31 +3431,34 @@ Func_2bbbb: ld d, [hl] ld hl, wDeckToBuild xor a - ld b, DECK_TEMP_BUFFER_SIZE + 2 -.asm_2bbc8 + ld b, AUTO_DECK_LIST_BUFFER_SIZE +.loop_init ld [hli], a dec b - jr nz, .asm_2bbc8 + jr nz, .loop_init + +; de = Machine*DeckList (card count, card id) ld hl, wDeckToBuild -.asm_2bbcf - ld a, [de] +.loop_create_deck + ld a, [de] ; card count inc de ld b, a or a - jr z, .asm_2bbe2 - ld a, [de] + jr z, .save_deck + ld a, [de] ; low(card id) inc de ld c, a - ld a, [de] + ld a, [de] ; high(card id) inc de -.asm_2bbda +.loop_card_count ld [hl], c inc hl ld [hli], a dec b - jr nz, .asm_2bbda - jr .asm_2bbcf -.asm_2bbe2 + jr nz, .loop_card_count + jr .loop_create_deck + +.save_deck pop hl ld bc, DECK_NAME_SIZE add hl, bc @@ -3458,7 +3471,7 @@ Func_2bbbb: pop hl ret -Func_2bbf9: +ReadCurAutoDeckName: push hl push bc push de @@ -3468,26 +3481,28 @@ Func_2bbf9: ld de, wDefaultText call CopyText pop hl + farcall SwitchToWRAM2 ld de, wDefaultText - ld b, $0f - ld c, $0e -.asm_2bc11 + ld b, TX_KATAKANA + ld c, TX_HIRAGANA +.loop_copy_name ld a, [de] inc de or a - jr z, .asm_2bc45 - cp $05 - jr z, .asm_2bc2f - cp $04 - jr z, .asm_2bc3a + jr z, .done_copy_name ; TX_END +; handle charmap, due to different TX_* usage + cp TX_SYMBOL + jr z, .symbol + cp TX_FULLWIDTH4 + jr z, .fw4 cp c - jr z, .asm_2bc26 + jr z, .kana ld [hl], b inc hl ld [hli], a - jr .asm_2bc11 -.asm_2bc26 + jr .loop_copy_name +.kana ld [hli], a ld a, [de] inc de @@ -3495,28 +3510,29 @@ Func_2bbf9: ld a, b ld b, c ld c, a - jr .asm_2bc11 -.asm_2bc2f + jr .loop_copy_name +.symbol ld [hli], a ld a, [de] inc de ld [hli], a ld a, [de] cp b - jr nz, .asm_2bc11 + jr nz, .loop_copy_name inc de - jr .asm_2bc11 -.asm_2bc3a + jr .loop_copy_name +.fw4 ld [hli], a ld a, [de] inc de ld [hli], a ld a, [de] cp b - jr nz, .asm_2bc11 + jr nz, .loop_copy_name inc de - jr .asm_2bc11 -.asm_2bc45 + jr .loop_copy_name + +.done_copy_name ld [hl], a farcall SwitchToWRAM1 pop bc @@ -3571,17 +3587,18 @@ Func_2bc4f: .MenuParameters: menu_params 1, 2, 3, NUM_DECKS, SYM_CURSOR_R, SYM_SPACE, NULL +; a = *_ISLAND _HandleAutoDeckMenu: - ld [wd548], a + ld [wAutoDeckMachineIndex], a xor a ld [wScrollMenuScrollOffset], a -.asm_2bca6 +.start ld hl, AutoDeckMachineMenuParams farcall InitializeScrollMenuParameters - ld a, NUM_DECK_MACHINE_VISIBLE_DECKS + ld a, NUM_DECK_MACHINE_VISIBLE_SLOTS ld [wNumMenuItems], a call .InitMenu - ld hl, Func_3bf5e + ld hl, UpdateDeckMachineScrollArrowsAndEntries ld d, h ld a, l ld hl, wScrollMenuScrollFunc @@ -3594,27 +3611,27 @@ _HandleAutoDeckMenu: farcall HandleScrollMenu jr nc, .wait_input ld a, [hCurMenuItem] - cp $ff - ret z ; cancel + cp MENU_CANCEL + ret z ld a, [wScrollMenuScrollOffset] - ld [wd54a], a + ld [wAutoDeckMachineScrollOffset], a ld b, a ld a, [wCurScrollMenuItem] - ld [wd54b], a + ld [wAutoDeckMachineScrollMenuItem], a add b - ld hl, wNumCardsNeededToBuildDeckMachineDecks + ld hl, wIndicesAutoDeckMachineUnlockedCategories ld c, a ld b, $00 add hl, bc ld a, [hl] dec a - ld [wd4b3], a - farcall Func_3bb09 - ld a, [wd54a] + ld [wSelectedAutoDeckMachineCategory], a + farcall _HandleAutoDeckSelectionMenu + ld a, [wAutoDeckMachineScrollOffset] ld [wScrollMenuScrollOffset], a - ld a, [wd54b] - jr .asm_2bca6 + ld a, [wAutoDeckMachineScrollMenuItem] + jr .start .InitMenu: xor a @@ -3632,7 +3649,7 @@ _HandleAutoDeckMenu: lb bc, 20, 13 call DrawRegularTextBox lb de, 1, 0 - ld a, [wd548] + ld a, [wAutoDeckMachineIndex] or a jr nz, .machine_2 ; machine 1 @@ -3642,36 +3659,38 @@ _HandleAutoDeckMenu: ldtx hl, AutoDeckMachine2Text .got_name call Func_2c4b - ldtx hl, ChooseDeckTypeText + ldtx hl, ChooseDeckCategoryText call DrawWideTextBox_PrintText call Func_2bd48 - farcall Func_3bf5e + farcall UpdateDeckMachineScrollArrowsAndEntries call EnableLCD ret Func_2bd48: - ld a, $08 - ld hl, wNumCardsNeededToBuildDeckMachineDecks + ld a, NUM_AUTO_DECK_MACHINE_REGULAR_CATEGORIES + ld hl, wIndicesAutoDeckMachineUnlockedCategories farcall ClearNBytesFromHL - ld a, $08 - ld hl, wd4b4 + ld a, 2 * 4 + ld hl, wAutoDeckMachineTexts farcall ClearNBytesFromHL - ld bc, $0 -.asm_2bd5d + + lb bc, 0, 0 +.loop_categories ld a, b push bc - call Func_2bd7f + call .CheckUnlockEvents pop bc - jr nc, .asm_2bd6b + jr nc, .next_category push bc - call Func_2bd92 + call .LoadIndexAndName pop bc inc c -.asm_2bd6b +.next_category inc b ld a, b - cp $0a - jr nz, .asm_2bd5d + cp NUM_AUTO_DECK_MACHINE_CATEGORIES + jr nz, .loop_categories + ld a, c ld [wNumDeckMachineEntries], a ld a, [wNumMenuItems] @@ -3681,22 +3700,28 @@ Func_2bd48: ld [wNumMenuItems], a ret -Func_2bd7f: +.CheckUnlockEvents: push af - ld a, [wd548] + ld a, [wAutoDeckMachineIndex] or a - jr nz, .machine_2 + jr nz, .is_unlocked_machine_2 ; machine 1 pop af - farcall CheckTCGIslandMilestoneEvents + farcall CheckCurAutoDeckMachine1CategoryUnlockEvents ret -.machine_2 +.is_unlocked_machine_2 pop af - farcall CheckGRIslandMilestoneEvents + farcall CheckCurAutoDeckMachine2CategoryUnlockEvents ret -Func_2bd92: - ld hl, wNumCardsNeededToBuildDeckMachineDecks +; b = category index +; c = position offset +; set: +; wIndicesAutoDeckMachineUnlockedCategories[c] = b + 1 +; wAutoDeckMachineTexts[c] = text id +.LoadIndexAndName: +; set index + ld hl, wIndicesAutoDeckMachineUnlockedCategories push bc ld a, b inc a @@ -3704,15 +3729,16 @@ Func_2bd92: add hl, bc pop bc ld [hl], a - ld a, [wd548] + + ld a, [wAutoDeckMachineIndex] or a - jr nz, .machine_2 + jr nz, .load_from_machine_2 ; machine 1 - ld hl, .Machine1SectionTitles - jr .got_addr -.machine_2 - ld hl, .Machine2SectionTitles -.got_addr + ld hl, .machine_1_category_titles + jr .set_name +.load_from_machine_2 + ld hl, .machine_2_category_titles +.set_name push bc ld c, b sla c @@ -3721,7 +3747,7 @@ Func_2bd92: pop bc ld e, l ld d, h - ld hl, wd4b4 + ld hl, wAutoDeckMachineTexts sla c ld b, 0 add hl, bc @@ -3732,26 +3758,27 @@ Func_2bd92: ld [hl], a ret -.Machine1SectionTitles: - tx BasicDeckMachineTextPadded - tx GivenDeckMachineTextPadded - tx FightingDeckMachineText - tx GrassDeckMachineText - tx WaterDeckMachineText - tx FireDeckMachineText - tx LightningDeckMachineText - tx PsychicDeckMachineText - tx SpecialDeckMachineTextPadded - tx LegendaryDeckMachineTextPadded +; category titles with padding +.machine_1_category_titles + tx AutoDeckMachine1BasicDecksTextPadded + tx AutoDeckMachine1GivenDecksTextPadded + tx AutoDeckMachine1FightingDecksText + tx AutoDeckMachine1GrassDecksText + tx AutoDeckMachine1WaterDecksText + tx AutoDeckMachine1FireDecksText + tx AutoDeckMachine1LightningDecksText + tx AutoDeckMachine1PsychicDecksText + tx AutoDeckMachine1SpecialDecksTextPadded + tx AutoDeckMachine1LegendaryDecksTextPadded -.Machine2SectionTitles: - tx DarkGrassDeckMachineText - tx DarkLightningDeckMachineText - tx DarkWaterDeckMachineText - tx DarkFireDeckMachineText - tx DarkFightingDeckMachineText - tx DarkPsychicDeckMachineText - tx ColorlessDeckMachineTextPadded - tx DarkSpecialDeckMachineText - tx RareCardDeckMachineText - tx MysteriousCardDeckMachineTextPadded +.machine_2_category_titles + tx AutoDeckMachine2DarkGrassDecksText + tx AutoDeckMachine2DarkLightningDecksText + tx AutoDeckMachine2DarkWaterDecksText + tx AutoDeckMachine2DarkFireDecksText + tx AutoDeckMachine2DarkFightingDecksText + tx AutoDeckMachine2DarkPsychicDecksText + tx AutoDeckMachine2ColorlessDecksTextPadded + tx AutoDeckMachine2DarkSpecialDecksText + tx AutoDeckMachine2RareCardDecksText + tx AutoDeckMachine2MysteriousCardDecksTextPadded diff --git a/src/engine/bank0e.asm b/src/engine/bank0e.asm index 13ab07a..836983d 100644 --- a/src/engine/bank0e.asm +++ b/src/engine/bank0e.asm @@ -4973,7 +4973,7 @@ _HandleDeckSaveMachineMenu: ; and sets DrawDeckMachineScreen as the update function ; de = text ID InitDeckMachineDrawingParams: - ld a, NUM_DECK_MACHINE_VISIBLE_DECKS + ld a, NUM_DECK_MACHINE_VISIBLE_SLOTS ld [wNumMenuItems], a ld hl, wDeckMachineText ld [hl], e @@ -5072,20 +5072,20 @@ HandleDeckMachineSelection: .d_right ld a, [wScrollMenuScrollOffset] - add NUM_DECK_MACHINE_VISIBLE_DECKS + add NUM_DECK_MACHINE_VISIBLE_SLOTS ld b, a - add NUM_DECK_MACHINE_VISIBLE_DECKS + add NUM_DECK_MACHINE_VISIBLE_SLOTS ld hl, wNumDeckMachineEntries cp [hl] jr c, .got_new_pos ld a, [wNumDeckMachineEntries] - sub NUM_DECK_MACHINE_VISIBLE_DECKS + sub NUM_DECK_MACHINE_VISIBLE_SLOTS ld b, a jr .got_new_pos .d_left ld a, [wScrollMenuScrollOffset] - sub NUM_DECK_MACHINE_VISIBLE_DECKS + sub NUM_DECK_MACHINE_VISIBLE_SLOTS ld b, a jr nc, .got_new_pos ld b, 0 ; first entry @@ -5239,7 +5239,7 @@ GetSavedDeckPointers: PrintVisibleDeckMachineEntries: ld a, [wScrollMenuScrollOffset] lb de, 2, 2 - ld b, NUM_DECK_MACHINE_VISIBLE_DECKS + ld b, NUM_DECK_MACHINE_VISIBLE_SLOTS .loop push af push bc @@ -5256,7 +5256,7 @@ PrintVisibleDeckMachineEntries: inc e jr .loop -UpdateDeckMachineScrollArrowsAndEntries: +UpdateDeckMachineScrollArrowsAndEntries_TCG1: call DrawListScrollArrows jr PrintVisibleDeckMachineEntries @@ -5278,7 +5278,7 @@ DrawDeckMachineScreen: ; update wScrollMenuScrollFunc to PrintVisibleAutoDeckMachineEntries ; and init wd119 -Func_3b069: +UpdateAutoDeckSelectionMenuScroll: ld hl, PrintVisibleAutoDeckMachineEntries ld d, h ld a, l @@ -5289,7 +5289,7 @@ Func_3b069: ld [wd119], a ret -; variant of PrintVisibleDeckMachineEntries for Auto Deck Machine sections +; variant of PrintVisibleDeckMachineEntries for Auto Deck Machine categories PrintVisibleAutoDeckMachineEntries: lb de, 2, 2 ld b, NUM_AUTO_DECK_MACHINE_SLOTS @@ -5919,7 +5919,7 @@ DrawListScrollArrows: call WriteByteToBGMap0 ld a, [wScrollMenuScrollOffset] - add NUM_DECK_MACHINE_VISIBLE_DECKS + 1 + add NUM_DECK_MACHINE_VISIBLE_SLOTS + 1 ld b, a ld a, [wNumDeckMachineEntries] cp b @@ -7029,17 +7029,17 @@ _PrinterMenu_DeckConfiguration: ld [wCurScrollMenuItem], a jp .start_selection -; auto deck machines -Func_3bb09: - ld a, [wd548] +_HandleAutoDeckSelectionMenu: + ld a, [wAutoDeckMachineIndex] or a - jr nz, .asm_3bb14 - ld hl, $7c6d - jr .asm_3bb17 -.asm_3bb14 - ld hl, $7c81 -.asm_3bb17 - ld a, [wd4b3] + jr nz, .machine_2 +; machine 1 + ld hl, .machine_1_category_titles + jr .launch +.machine_2 + ld hl, .machine_2_category_titles +.launch + ld a, [wSelectedAutoDeckMachineCategory] sla a ld c, a ld b, $00 @@ -7052,10 +7052,11 @@ Func_3bb09: ld [de], a xor a ld [wScrollMenuScrollOffset], a - call Func_3bc95 + call .InitAutoDeckMenu xor a -.asm_3bb30 - ld hl, MenuParams_9eb5 + +.please_select_deck + ld hl, AutoDeckMachineDeckSelectionParams farcall InitializeScrollMenuParameters ldtx hl, PleaseSelectDeckText call DrawWideTextBox_PrintText @@ -7065,14 +7066,17 @@ Func_3bb09: ld [wUnableToScrollDown], a xor a ld [wd119], a - call Func_3b069 -.asm_3bb4f + call UpdateAutoDeckSelectionMenuScroll + +.wait_input call DoFrame call HandleScrollMenu - jr c, .asm_3bba2 + jr c, .selected_deck + +; start btn to show full deck list ldh a, [hDPadHeld] and PAD_START - jr z, .asm_3bb4f + jr z, .wait_input ld a, [wScrollMenuScrollOffset] ld [wTempScrollMenuScrollOffset], a ld b, a @@ -7085,12 +7089,14 @@ Func_3bb09: ld [wCurDeck], a ld a, c call GetAndLoadSelectedMachineDeckPtr +; validity check just in case push hl farcall CheckIfDeckHasCards pop hl - jr c, .asm_3bb4f + jr c, .wait_input +; show full deck list push hl - ld bc, $18 + ld bc, DECK_NAME_SIZE add hl, bc ld d, h ld e, l @@ -7100,19 +7106,21 @@ Func_3bb09: farcall OpenDeckConfirmationMenu ld a, [wTempScrollMenuScrollOffset] ld [wScrollMenuScrollOffset], a - call Func_3bc95 + call .InitAutoDeckMenu ld a, [wTempScrollMenuItem] ld [wCurScrollMenuItem], a - jp .asm_3bb30 -.asm_3bba2 + jp .please_select_deck + +.selected_deck call HandleScrollMenu.draw_visible_cursor ld a, [wScrollMenuScrollOffset] ld [wTempScrollMenuScrollOffset], a ld a, [wCurScrollMenuItem] ld [wTempScrollMenuItem], a ld a, [hCurMenuItem] - cp $ff - jp z, .asm_3bc0e + cp MENU_CANCEL + jp z, .exit + ld b, a ld a, [wScrollMenuScrollOffset] add b @@ -7121,37 +7129,44 @@ Func_3bb09: xor a ld [wd0cd], a call DrawWideTextBox - ld hl, $7c60 + ld hl, .deck_options call PlaceTextItems -.asm_3bbd2 +.wait_submenu_input call DoFrame - farcall Func_87d3 - jp nc, .asm_3bbd2 - cp $ff - jr nz, .asm_3bbe6 + farcall HandleCheckMenuInput_YourOrOppPlayArea + jp nc, .wait_submenu_input + cp MENU_CANCEL + jr nz, .selected_submenu ld a, [wTempScrollMenuItem] - jp .asm_3bb30 -.asm_3bbe6 + jp .please_select_deck + +.selected_submenu ld a, [wCheckMenuCursorYPosition] sla a ld hl, wCheckMenuCursorXPosition add [hl] or a - jr nz, .asm_3bc0a + jr nz, .next_submenu + +; AUTODECKMACHINEMENU_BUILD call TryBuildDeckMachineDeck ld a, [wTempScrollMenuItem] - jp nc, .asm_3bb30 + jp nc, .please_select_deck ld a, [wTempScrollMenuScrollOffset] ld [wScrollMenuScrollOffset], a - call Func_3bc95 + call .InitAutoDeckMenu ld a, [wTempScrollMenuItem] - jp .asm_3bb30 -.asm_3bc0a - cp $01 - jr nz, .asm_3bc0f -.asm_3bc0e + jp .please_select_deck + +.next_submenu + cp AUTODECKMACHINEMENU_CANCEL + jr nz, .read_instructions + +.exit ret -.asm_3bc0f + +; AUTODECKMACHINEMENU_READ +.read_instructions ld a, [wScrollMenuScrollOffset] ld [wTempScrollMenuScrollOffset], a ld b, a @@ -7163,8 +7178,9 @@ Func_3bb09: push af sla c ld b, $00 - ld hl, wd4b4 + ld hl, wAutoDeckMachineTexts add hl, bc +; set description text ld bc, wCardConfirmationText ld a, [hli] ld [bc], a @@ -7173,10 +7189,12 @@ Func_3bb09: ld [bc], a pop af call GetAndLoadSelectedMachineDeckPtr +; validity check just in case push hl farcall CheckIfDeckHasCards pop hl - jp c, .asm_3bb4f + jp c, .wait_input +; show instructions (card list + description) ld a, MENU_CONFIRM farcall PlaySFXConfirmOrCancel push hl @@ -7188,14 +7206,42 @@ Func_3bb09: farcall HandleDeckStatusCardList ld a, [wTempScrollMenuScrollOffset] ld [wScrollMenuScrollOffset], a - call Func_3bc95 + call .InitAutoDeckMenu ld a, [wTempScrollMenuItem] - jp .asm_3bb30 -; 0x3bc60 + jp .please_select_deck -SECTION "Bank e@7c95", ROMX[$7c95], BANK[$e] +.deck_options + textitem 2, 14, BuildDeckText + textitem 12, 14, CancelDeckText + textitem 2, 16, DeckMachineReadInstructionsText + textitems_end -Func_3bc95: +; category titles for header, so no padding +.machine_1_category_titles + tx AutoDeckMachine1BasicDecksText + tx AutoDeckMachine1GivenDecksText + tx AutoDeckMachine1FightingDecksText + tx AutoDeckMachine1GrassDecksText + tx AutoDeckMachine1WaterDecksText + tx AutoDeckMachine1FireDecksText + tx AutoDeckMachine1LightningDecksText + tx AutoDeckMachine1PsychicDecksText + tx AutoDeckMachine1SpecialDecksText + tx AutoDeckMachine1LegendaryDecksText + +.machine_2_category_titles + tx AutoDeckMachine2DarkGrassDecksText + tx AutoDeckMachine2DarkLightningDecksText + tx AutoDeckMachine2DarkWaterDecksText + tx AutoDeckMachine2DarkFireDecksText + tx AutoDeckMachine2DarkFightingDecksText + tx AutoDeckMachine2DarkPsychicDecksText + tx AutoDeckMachine2ColorlessDecksText + tx AutoDeckMachine2DarkSpecialDecksText + tx AutoDeckMachine2RareCardDecksText + tx AutoDeckMachine2MysteriousCardDecksText + +.InitAutoDeckMenu: xor a ld [wTileMapFill], a call ZeroObjectPositions @@ -7216,7 +7262,7 @@ Func_3bc95: ld l, a lb de, 1, 0 call Func_2c4b - farcall Func_2bb32 + farcall ReadAutoDeckConfiguration call CreateAutoDeckPointerList call PrintVisibleAutoDeckMachineEntries call EnableLCD @@ -7546,25 +7592,27 @@ OpenDeckSaveMachineFromDeckBuilding: pop af ld [wCurDeck], a ret -; 0x3bf55 -SECTION "Bank e@7f5e", ROMX[$7f5e], BANK[$e] +Menu_3bf55: + textitem 2, 14, SaveDeckToMachineText + textitem 12, 14, CancelDeckText + textitems_end -Func_3bf5e: - call Func_3bf95 +UpdateDeckMachineScrollArrowsAndEntries: + call .DrawListScrollArrows ld a, [wNumDeckMachineEntries] - cp $05 - jr c, .asm_3bf6a - ld a, $05 -.asm_3bf6a + cp 5 + jr c, .got_count + ld a, 5 +.got_count ld b, a ld a, [wScrollMenuScrollOffset] - ld de, $602 -.asm_3bf71 + lb de, 6, 2 +.loop_print push af push bc push de - call Func_3bf81 + call .PrintDeckEntry pop de pop bc pop af @@ -7573,16 +7621,16 @@ Func_3bf5e: inc a inc e inc e - jr .asm_3bf71 + jr .loop_print -Func_3bf81: +.PrintDeckEntry: push af call InitTextPrinting pop af add a ld c, a ld b, $00 - ld hl, wd4b4 + ld hl, wAutoDeckMachineTexts add hl, bc ld a, [hli] ld h, [hl] @@ -7590,34 +7638,34 @@ Func_3bf81: call ProcessTextFromID ret -Func_3bf95: +.DrawListScrollArrows: ld a, [wScrollMenuScrollOffset] or a - jr z, .asm_3bf9f - ld a, $0d - jr .asm_3bfa1 -.asm_3bf9f - ld a, $1c -.asm_3bfa1 - ld bc, $1200 + jr z, .no_up_cursor + ld a, SYM_CURSOR_U + jr .draw_top +.no_up_cursor + ld a, SYM_BOX_TOP +.draw_top + lb bc, 18, 0 call WriteByteToBGMap0 + ld a, [wScrollMenuScrollOffset] - add $05 + add 5 ld b, a inc b ld a, [wNumDeckMachineEntries] cp b - jr c, .asm_3bfbc - xor a + jr c, .no_down_cursor + xor a ; FALSE ld [wUnableToScrollDown], a - ld a, $2f - jr .asm_3bfc3 -.asm_3bfbc - ld a, $01 + ld a, SYM_CURSOR_D + jr .draw_bottom +.no_down_cursor + ld a, TRUE ld [wUnableToScrollDown], a - ld a, $1c -.asm_3bfc3 - ld bc, $120c + ld a, SYM_BOX_TOP +.draw_bottom + lb bc, 18, 12 call WriteByteToBGMap0 ret -; 0x3bfca diff --git a/src/engine/bank0f.asm b/src/engine/bank0f.asm index 37d7d6c..efa51a8 100644 --- a/src/engine/bank0f.asm +++ b/src/engine/bank0f.asm @@ -843,8 +843,8 @@ Script_AutoDeckMachine1: call PauseSong ld a, MUSIC_DECK_MACHINE call PlaySong - xor a - farcall Func_1e855 + xor a ; TCG_ISLAND + farcall AutoDeckMachine call ResumeSong ret .cancel @@ -867,8 +867,8 @@ Script_AutoDeckMachine2: call PauseSong ld a, MUSIC_DECK_MACHINE call PlaySong - ld a, $01 - farcall Func_1e855 + ld a, GR_ISLAND + farcall AutoDeckMachine call ResumeSong ret .cancel diff --git a/src/text/text2.asm b/src/text/text2.asm index af9e819..d790e66 100644 --- a/src/text/text2.asm +++ b/src/text/text2.asm @@ -2125,7 +2125,7 @@ SubInEnergyCardsPromptText: textfw "エネルギーカードをだいようしますか?" done -ChooseDeckTypeText: +ChooseDeckCategoryText: textfw "デッキの しゅるいを" linefw "えらんでください" done @@ -2235,59 +2235,59 @@ AutoDeckMachine1Text: textfw "オートデッキマシン1" done -BasicDeckMachineText: +AutoDeckMachine1BasicDecksText: textfw "きほんデッキ" done -GivenDeckMachineText: +AutoDeckMachine1GivenDecksText: textfw "もらったデッキ" done -FightingDeckMachineText: +AutoDeckMachine1FightingDecksText: textfw "闘ポケモンのデッキ" done -GrassDeckMachineText: +AutoDeckMachine1GrassDecksText: textfw "草ポケモンのデッキ" done -WaterDeckMachineText: +AutoDeckMachine1WaterDecksText: textfw "水ポケモンのデッキ" done -FireDeckMachineText: +AutoDeckMachine1FireDecksText: textfw "炎ポケモンのデッキ" done -LightningDeckMachineText: +AutoDeckMachine1LightningDecksText: textfw "雷ポケモンのデッキ" done -PsychicDeckMachineText: +AutoDeckMachine1PsychicDecksText: textfw "超ポケモンのデッキ" done -SpecialDeckMachineText: +AutoDeckMachine1SpecialDecksText: textfw "スペシャルデッキ" done -LegendaryDeckMachineText: +AutoDeckMachine1LegendaryDecksText: textfw "伝説のデッキ" done -BasicDeckMachineTextPadded: +AutoDeckMachine1BasicDecksTextPadded: textfw "きほんデッキ " done -GivenDeckMachineTextPadded: +AutoDeckMachine1GivenDecksTextPadded: textfw "もらったデッキ " done -SpecialDeckMachineTextPadded: +AutoDeckMachine1SpecialDecksTextPadded: textfw "スペシャルデッキ " done -LegendaryDeckMachineTextPadded: +AutoDeckMachine1LegendaryDecksTextPadded: textfw "伝説のデッキ " done @@ -2295,211 +2295,211 @@ AutoDeckMachine2Text: textfw "オートデッキマシン2" done -DarkGrassDeckMachineText: +AutoDeckMachine2DarkGrassDecksText: textfw "わるい草ポケモンデッキ" done -DarkLightningDeckMachineText: +AutoDeckMachine2DarkLightningDecksText: textfw "わるい雷ポケモンデッキ" done -DarkWaterDeckMachineText: +AutoDeckMachine2DarkWaterDecksText: textfw "わるい水ポケモンデッキ" done -DarkFireDeckMachineText: +AutoDeckMachine2DarkFireDecksText: textfw "わるい炎ポケモンデッキ" done -DarkFightingDeckMachineText: +AutoDeckMachine2DarkFightingDecksText: textfw "わるい闘ポケモンデッキ" done -DarkPsychicDeckMachineText: +AutoDeckMachine2DarkPsychicDecksText: textfw "わるい超ポケモンデッキ" done -ColorlessDeckMachineText: +AutoDeckMachine2ColorlessDecksText: textfw "無色ポケモンデッキ" done -DarkSpecialDeckMachineText: +AutoDeckMachine2DarkSpecialDecksText: textfw "わるいスペシャルデッキ" done -RareCardDeckMachineText: +AutoDeckMachine2RareCardDecksText: textfw "めずらしいカードデッキ" done -MysteriousCardDeckMachineText: +AutoDeckMachine2MysteriousCardDecksText: textfw "なぞのカードデッキ" done -ColorlessDeckMachineTextPadded: +AutoDeckMachine2ColorlessDecksTextPadded: textfw "無色ポケモンデッキ " done -MysteriousCardDeckMachineTextPadded: +AutoDeckMachine2MysteriousCardDecksTextPadded: textfw "なぞのカードデッキ " done -MachineStarterDeckText: +MachineStarterDeckName: textfw "さいしょの" done -MachineElectricFireDeckText: +MachineElectricFireDeckName: textfw "エレキファイヤー" done -MachineBattleWaterDeckText: +MachineBattleWaterDeckName: textfw "バトルウォーター" done -MachineEsperGreenDeckText: +MachineEsperGreenDeckName: textfw "エスパーグリーン" done -MachineSweatAntiGR1DeckText: +MachineSweatAntiGR1DeckName: textfw "たおせ!GR1ごう" done -MachineGiveInAntiGR2DeckText: +MachineGiveInAntiGR2DeckName: textfw "まけろ!GR2ごう" done -MachineVengefulAntiGR3DeckText: +MachineVengefulAntiGR3DeckName: textfw "しかえしGR3ごう" done -MachineUnforgivingAntiGR4DeckText: +MachineUnforgivingAntiGR4DeckName: textfw "ゆるさんGR4ごう" done -MachineAwesomeFossilsDeckText: +MachineAwesomeFossilsDeckName: textfw "シブイかせき" done -MachineNewMachokeDeckText: +MachineNewMachokeDeckName: textfw "ニューゴーリキー" done -MachineRockFestivalDeckText: +MachineRockFestivalDeckName: textfw "ロックフェスティバル" done -MachineJabHookDeckText: +MachineJabHookDeckName: textfw "ジャブだフックだ!" done -MachineSteadyIncreaseDeckText: +MachineSteadyIncreaseDeckName: textfw "ドンドンぞうしょく" done -MachineGatheringNidoranDeckText: +MachineGatheringNidoranDeckName: textfw "あつまれニドラン" done -MachineNationalParkDeckText: +MachineNationalParkDeckName: textfw "しんりんこうえん" done -MachineSelectiveBreedingDeckText: +MachineSelectiveBreedingDeckName: textfw "ひんしゅかいりょう" done -MachineSplashingAboutDeckText: +MachineSplashingAboutDeckName: textfw "みずあそび" done -MachineBeachDeckText: +MachineBeachDeckName: textfw "なみうちぎわ" done -MachineInsulationDeckText: +MachineInsulationDeckName: textfw "ぜつえんたい" done -MachineAntarcticDeckText: +MachineAntarcticDeckName: textfw "なんきょく" done -MachineFlameFestivalDeckText: +MachineFlameFestivalDeckName: textfw "ほのおのおまつり" done -MachineElectricCurrentShockDeckText: +MachineElectricCurrentShockDeckName: textfw "でんりゅうひばな" done -MachineRiskyBlazeDeckText: +MachineRiskyBlazeDeckName: textfw "すてみのほのお" done -MachineRagingCharizardDeckText: +MachineRagingCharizardDeckName: textfw "リザードンおおあばれ" done -MachineZapdosPowerPlantDeckText: +MachineZapdosPowerPlantDeckName: textfw "サンダーはつでんしょ" done -MachineElectricShockDeckText: +MachineElectricShockDeckName: textfw "でんきショック" done -MachineOverflowDeckText: +MachineOverflowDeckName: textfw "オーバーフロー" done -MachineTripleZapdosDeckText: +MachineTripleZapdosDeckName: textfw "トリプルサンダー" done -MachineSpecialBarrierDeckText: +MachineSpecialBarrierDeckName: textfw "とくしゅバリヤー" done -MachineEvolutionProhibitedDeckText: +MachineEvolutionProhibitedDeckName: textfw "しんかふのう" done -MachineGhostDeckText: +MachineGhostDeckName: textfw "ゆうれい" done -MachinePuppetMasterDeckText: +MachinePuppetMasterDeckName: textfw "にんぎょうつかい" done -MachineMewLv15DeckText: +MachineMewLv15DeckName: textfw "ミュウ15" done -MachineVenusaurLv64DeckText: +MachineVenusaurLv64DeckName: textfw "フシギバナ64" done -MachineMutualDestructionDeckText: +MachineMutualDestructionDeckName: textfw "ともだおれ" done -MachineEverybodySurfDeckText: +MachineEverybodySurfDeckName: textfw "みんなでなみのり" done -MachineGrandFireDeckText: +MachineGrandFireDeckName: textfw "グランドファイヤー" done -MachineLegendaryFossilDeckText: +MachineLegendaryFossilDeckName: textfw "でんせつのかせき" done -MachineWaterLegendDeckText: +MachineWaterLegendDeckName: textfw "ウォーターレジェンド" done -MachineGreatDragonDeckText: +MachineGreatDragonDeckName: textfw "レジェンドドラゴン" done @@ -2703,164 +2703,164 @@ MachineGreatDragonDeckDescriptionText: linefw "きょうりょくポケモンで トドメだ!" done -MachineInsectCollectionDeckText: +MachineInsectCollectionDeckName: textfw "こんちゅうさいしゅう" done -MachineCaveExplorationDeckText: +MachineCaveExplorationDeckName: textfw "どうくつたんけん" done -MachineOminousMeadowDeckText: +MachineOminousMeadowDeckName: textfw "あやしいはなばたけ" done -MachineAtrociousWeezingDeckText: +MachineAtrociousWeezingDeckName: textfw "きょうあくマタドガス" done -MachineTheBenchIsAlsoASurpriseDeckText: +MachineTheBenchIsAlsoASurpriseDeckName: textfw "ベンチもビックリ" done -MachineEnergyConservationDeckText: +MachineEnergyConservationDeckName: textfw "しょうエネルギー" done -MachineSonicboomDeckText: +MachineSonicboomDeckName: textfw "ソニックブーム" done -MachineRageOfTheHeavensDeckText: +MachineRageOfTheHeavensDeckName: textfw "てんくうのいかり" done -MachineDarkWaterDeckText: +MachineDarkWaterDeckName: textfw "ダークウォーター" done -MachineQuickFreezeDeckText: +MachineQuickFreezeDeckName: textfw "きゅうそくれいとう" done -MachineWhirlpoolShowerDeckText: +MachineWhirlpoolShowerDeckName: textfw "うずしおのシャワー" done -MachineWaterGangDeckText: +MachineWaterGangDeckName: textfw "みずのギャングだん" done -MachineFireballDeckText: +MachineFireballDeckName: textfw "ファイヤーボール" done -MachineCompleteCombustionDeckText: +MachineCompleteCombustionDeckName: textfw "かんぜんねんしょう" done -MachineOminousSpiritFlamesDeckText: +MachineOminousSpiritFlamesDeckName: textfw "あやしいヒトダマ" done -MachineEternalFireDeckText: +MachineEternalFireDeckName: textfw "えいえんのファイヤー" done -MachineBewareTheTrapDeckText: +MachineBewareTheTrapDeckName: textfw "ワナにごちゅうい!" done -MachineOgresKickDeckText: +MachineOgresKickDeckName: textfw "キックのオニ" done -MachineRockBlastDeckText: +MachineRockBlastDeckName: textfw "ロックブラスト!" done -MachineHeavyWorkDeckText: +MachineHeavyWorkDeckName: ; the same as Full Strength Deck but renamed for Machine textfw "ちからわざ" done -MachineSlowbrosFishingDeckText: +MachineSlowbrosFishingDeckName: textfw "ヤドランともづり" done -MachineDirectHitDeckText: +MachineDirectHitDeckName: textfw "ちょくげき" done -MachineBadDreamDeckText: +MachineBadDreamDeckName: textfw "バッドドリーム" done -MachineBenchPanicDeckText: +MachineBenchPanicDeckName: textfw "ベンチはパニック!" done -MachineSnorlaxGuardDeckText: +MachineSnorlaxGuardDeckName: textfw "カビゴンとおせんぼ" done -MachineEyeOfTheStormDeckText: +MachineEyeOfTheStormDeckName: textfw "たいふうのめ" done -MachineSuddenGrowthDeckText: +MachineSuddenGrowthDeckName: textfw "きゅうせいちょう" done -MachineKingDragoniteDeckText: +MachineKingDragoniteDeckName: textfw "おうじゃカイリュー" done -MachineDarkCharizardDeckText: +MachineDarkCharizardDeckName: textfw "わるいリザードン!" done -MachineDarkBlastoiseDeckText: +MachineDarkBlastoiseDeckName: textfw "わるいカメックス!" done -MachineDarkVenusaurDeckText: +MachineDarkVenusaurDeckName: textfw "わるいフシギバナ!" done -MachineDarkDragoniteDeckText: +MachineDarkDragoniteDeckName: textfw "わるいカイリュー!" done -MachinePerfectHealthDeckText: +MachinePerfectHealthDeckName: textfw "けんこうゆうりょう" done -MachineSuperSoakerDeckText: +MachineSuperSoakerDeckName: textfw "スーパーみずでっぽう" done -MachineHellsDemonDeckText: +MachineHellsDemonDeckName: textfw "ちていのあくま" done -MachinePremiumThunderDeckText: +MachinePremiumThunderDeckName: textfw "プレミアムサンダー" done -MachineMysteriousMewtwoDeckText: +MachineMysteriousMewtwoDeckName: textfw "なぞのミュウツー" done -MachineHeavenlyLugiaDeckText: +MachineHeavenlyLugiaDeckName: textfw "てんくうのルギア" done -MachineBrutalTrainersDeckText: +MachineBrutalTrainersDeckName: textfw "きょうあくトレーナー" done -MachineDreadfulParalysisDeckText: +MachineDreadfulParalysisDeckName: textfw "きょうふのかなしばり" done diff --git a/src/text/text_offsets.asm b/src/text/text_offsets.asm index 23aeb25..8316581 100644 --- a/src/text/text_offsets.asm +++ b/src/text/text_offsets.asm @@ -760,7 +760,7 @@ TextOffsets:: textpointer CannotBuildLackingBasicPokemonText ; 0x02f2 textpointer BuiltSubbedDeckWithTheseCardsText ; 0x02f3 textpointer SubInEnergyCardsPromptText ; 0x02f4 - textpointer ChooseDeckTypeText ; 0x02f5 + textpointer ChooseDeckCategoryText ; 0x02f5 textpointer PrintThisCardPromptYesNoText ; 0x02f6 textpointer ChooseDeckConfigurationToPrintText ; 0x02f7 textpointer PrintThisDeckPromptText ; 0x02f8 @@ -782,73 +782,73 @@ TextOffsets:: textpointer ReceiveRecordsText ; 0x0308 textpointer ReceivedDeckConfigurationFromText ; 0x0309 textpointer AutoDeckMachine1Text ; 0x030a - textpointer BasicDeckMachineText ; 0x030b - textpointer GivenDeckMachineText ; 0x030c - textpointer FightingDeckMachineText ; 0x030d - textpointer GrassDeckMachineText ; 0x030e - textpointer WaterDeckMachineText ; 0x030f - textpointer FireDeckMachineText ; 0x0310 - textpointer LightningDeckMachineText ; 0x0311 - textpointer PsychicDeckMachineText ; 0x0312 - textpointer SpecialDeckMachineText ; 0x0313 - textpointer LegendaryDeckMachineText ; 0x0314 - textpointer BasicDeckMachineTextPadded ; 0x0315 - textpointer GivenDeckMachineTextPadded ; 0x0316 - textpointer SpecialDeckMachineTextPadded ; 0x0317 - textpointer LegendaryDeckMachineTextPadded ; 0x0318 + textpointer AutoDeckMachine1BasicDecksText ; 0x030b + textpointer AutoDeckMachine1GivenDecksText ; 0x030c + textpointer AutoDeckMachine1FightingDecksText ; 0x030d + textpointer AutoDeckMachine1GrassDecksText ; 0x030e + textpointer AutoDeckMachine1WaterDecksText ; 0x030f + textpointer AutoDeckMachine1FireDecksText ; 0x0310 + textpointer AutoDeckMachine1LightningDecksText ; 0x0311 + textpointer AutoDeckMachine1PsychicDecksText ; 0x0312 + textpointer AutoDeckMachine1SpecialDecksText ; 0x0313 + textpointer AutoDeckMachine1LegendaryDecksText ; 0x0314 + textpointer AutoDeckMachine1BasicDecksTextPadded ; 0x0315 + textpointer AutoDeckMachine1GivenDecksTextPadded ; 0x0316 + textpointer AutoDeckMachine1SpecialDecksTextPadded ; 0x0317 + textpointer AutoDeckMachine1LegendaryDecksTextPadded ; 0x0318 textpointer AutoDeckMachine2Text ; 0x0319 - textpointer DarkGrassDeckMachineText ; 0x031a - textpointer DarkLightningDeckMachineText ; 0x031b - textpointer DarkWaterDeckMachineText ; 0x031c - textpointer DarkFireDeckMachineText ; 0x031d - textpointer DarkFightingDeckMachineText ; 0x031e - textpointer DarkPsychicDeckMachineText ; 0x031f - textpointer ColorlessDeckMachineText ; 0x0320 - textpointer DarkSpecialDeckMachineText ; 0x0321 - textpointer RareCardDeckMachineText ; 0x0322 - textpointer MysteriousCardDeckMachineText ; 0x0323 - textpointer ColorlessDeckMachineTextPadded ; 0x0324 - textpointer MysteriousCardDeckMachineTextPadded ; 0x0325 - textpointer MachineStarterDeckText ; 0x0326 - textpointer MachineElectricFireDeckText ; 0x0327 - textpointer MachineBattleWaterDeckText ; 0x0328 - textpointer MachineEsperGreenDeckText ; 0x0329 - textpointer MachineSweatAntiGR1DeckText ; 0x032a - textpointer MachineGiveInAntiGR2DeckText ; 0x032b - textpointer MachineVengefulAntiGR3DeckText ; 0x032c - textpointer MachineUnforgivingAntiGR4DeckText ; 0x032d - textpointer MachineAwesomeFossilsDeckText ; 0x032e - textpointer MachineNewMachokeDeckText ; 0x032f - textpointer MachineRockFestivalDeckText ; 0x0330 - textpointer MachineJabHookDeckText ; 0x0331 - textpointer MachineSteadyIncreaseDeckText ; 0x0332 - textpointer MachineGatheringNidoranDeckText ; 0x0333 - textpointer MachineNationalParkDeckText ; 0x0334 - textpointer MachineSelectiveBreedingDeckText ; 0x0335 - textpointer MachineSplashingAboutDeckText ; 0x0336 - textpointer MachineBeachDeckText ; 0x0337 - textpointer MachineInsulationDeckText ; 0x0338 - textpointer MachineAntarcticDeckText ; 0x0339 - textpointer MachineFlameFestivalDeckText ; 0x033a - textpointer MachineElectricCurrentShockDeckText ; 0x033b - textpointer MachineRiskyBlazeDeckText ; 0x033c - textpointer MachineRagingCharizardDeckText ; 0x033d - textpointer MachineZapdosPowerPlantDeckText ; 0x033e - textpointer MachineElectricShockDeckText ; 0x033f - textpointer MachineOverflowDeckText ; 0x0340 - textpointer MachineTripleZapdosDeckText ; 0x0341 - textpointer MachineSpecialBarrierDeckText ; 0x0342 - textpointer MachineEvolutionProhibitedDeckText ; 0x0343 - textpointer MachineGhostDeckText ; 0x0344 - textpointer MachinePuppetMasterDeckText ; 0x0345 - textpointer MachineMewLv15DeckText ; 0x0346 - textpointer MachineVenusaurLv64DeckText ; 0x0347 - textpointer MachineMutualDestructionDeckText ; 0x0348 - textpointer MachineEverybodySurfDeckText ; 0x0349 - textpointer MachineGrandFireDeckText ; 0x034a - textpointer MachineLegendaryFossilDeckText ; 0x034b - textpointer MachineWaterLegendDeckText ; 0x034c - textpointer MachineGreatDragonDeckText ; 0x034d + textpointer AutoDeckMachine2DarkGrassDecksText ; 0x031a + textpointer AutoDeckMachine2DarkLightningDecksText ; 0x031b + textpointer AutoDeckMachine2DarkWaterDecksText ; 0x031c + textpointer AutoDeckMachine2DarkFireDecksText ; 0x031d + textpointer AutoDeckMachine2DarkFightingDecksText ; 0x031e + textpointer AutoDeckMachine2DarkPsychicDecksText ; 0x031f + textpointer AutoDeckMachine2ColorlessDecksText ; 0x0320 + textpointer AutoDeckMachine2DarkSpecialDecksText ; 0x0321 + textpointer AutoDeckMachine2RareCardDecksText ; 0x0322 + textpointer AutoDeckMachine2MysteriousCardDecksText ; 0x0323 + textpointer AutoDeckMachine2ColorlessDecksTextPadded ; 0x0324 + textpointer AutoDeckMachine2MysteriousCardDecksTextPadded ; 0x0325 + textpointer MachineStarterDeckName ; 0x0326 + textpointer MachineElectricFireDeckName ; 0x0327 + textpointer MachineBattleWaterDeckName ; 0x0328 + textpointer MachineEsperGreenDeckName ; 0x0329 + textpointer MachineSweatAntiGR1DeckName ; 0x032a + textpointer MachineGiveInAntiGR2DeckName ; 0x032b + textpointer MachineVengefulAntiGR3DeckName ; 0x032c + textpointer MachineUnforgivingAntiGR4DeckName ; 0x032d + textpointer MachineAwesomeFossilsDeckName ; 0x032e + textpointer MachineNewMachokeDeckName ; 0x032f + textpointer MachineRockFestivalDeckName ; 0x0330 + textpointer MachineJabHookDeckName ; 0x0331 + textpointer MachineSteadyIncreaseDeckName ; 0x0332 + textpointer MachineGatheringNidoranDeckName ; 0x0333 + textpointer MachineNationalParkDeckName ; 0x0334 + textpointer MachineSelectiveBreedingDeckName ; 0x0335 + textpointer MachineSplashingAboutDeckName ; 0x0336 + textpointer MachineBeachDeckName ; 0x0337 + textpointer MachineInsulationDeckName ; 0x0338 + textpointer MachineAntarcticDeckName ; 0x0339 + textpointer MachineFlameFestivalDeckName ; 0x033a + textpointer MachineElectricCurrentShockDeckName ; 0x033b + textpointer MachineRiskyBlazeDeckName ; 0x033c + textpointer MachineRagingCharizardDeckName ; 0x033d + textpointer MachineZapdosPowerPlantDeckName ; 0x033e + textpointer MachineElectricShockDeckName ; 0x033f + textpointer MachineOverflowDeckName ; 0x0340 + textpointer MachineTripleZapdosDeckName ; 0x0341 + textpointer MachineSpecialBarrierDeckName ; 0x0342 + textpointer MachineEvolutionProhibitedDeckName ; 0x0343 + textpointer MachineGhostDeckName ; 0x0344 + textpointer MachinePuppetMasterDeckName ; 0x0345 + textpointer MachineMewLv15DeckName ; 0x0346 + textpointer MachineVenusaurLv64DeckName ; 0x0347 + textpointer MachineMutualDestructionDeckName ; 0x0348 + textpointer MachineEverybodySurfDeckName ; 0x0349 + textpointer MachineGrandFireDeckName ; 0x034a + textpointer MachineLegendaryFossilDeckName ; 0x034b + textpointer MachineWaterLegendDeckName ; 0x034c + textpointer MachineGreatDragonDeckName ; 0x034d textpointer MachineStarterDeckDescriptionText ; 0x034e textpointer MachineElectricFireDeckDescriptionText ; 0x034f textpointer MachineBattleWaterDeckDescriptionText ; 0x0350 @@ -889,46 +889,46 @@ TextOffsets:: textpointer MachineLegendaryFossilDeckDescriptionText ; 0x0373 textpointer MachineWaterLegendDeckDescriptionText ; 0x0374 textpointer MachineGreatDragonDeckDescriptionText ; 0x0375 - textpointer MachineInsectCollectionDeckText ; 0x0376 - textpointer MachineCaveExplorationDeckText ; 0x0377 - textpointer MachineOminousMeadowDeckText ; 0x0378 - textpointer MachineAtrociousWeezingDeckText ; 0x0379 - textpointer MachineTheBenchIsAlsoASurpriseDeckText ; 0x037a - textpointer MachineEnergyConservationDeckText ; 0x037b - textpointer MachineSonicboomDeckText ; 0x037c - textpointer MachineRageOfTheHeavensDeckText ; 0x037d - textpointer MachineDarkWaterDeckText ; 0x037e - textpointer MachineQuickFreezeDeckText ; 0x037f - textpointer MachineWhirlpoolShowerDeckText ; 0x0380 - textpointer MachineWaterGangDeckText ; 0x0381 - textpointer MachineFireballDeckText ; 0x0382 - textpointer MachineCompleteCombustionDeckText ; 0x0383 - textpointer MachineOminousSpiritFlamesDeckText ; 0x0384 - textpointer MachineEternalFireDeckText ; 0x0385 - textpointer MachineBewareTheTrapDeckText ; 0x0386 - textpointer MachineOgresKickDeckText ; 0x0387 - textpointer MachineRockBlastDeckText ; 0x0388 - textpointer MachineHeavyWorkDeckText ; 0x0389 - textpointer MachineSlowbrosFishingDeckText ; 0x038a - textpointer MachineDirectHitDeckText ; 0x038b - textpointer MachineBadDreamDeckText ; 0x038c - textpointer MachineBenchPanicDeckText ; 0x038d - textpointer MachineSnorlaxGuardDeckText ; 0x038e - textpointer MachineEyeOfTheStormDeckText ; 0x038f - textpointer MachineSuddenGrowthDeckText ; 0x0390 - textpointer MachineKingDragoniteDeckText ; 0x0391 - textpointer MachineDarkCharizardDeckText ; 0x0392 - textpointer MachineDarkBlastoiseDeckText ; 0x0393 - textpointer MachineDarkVenusaurDeckText ; 0x0394 - textpointer MachineDarkDragoniteDeckText ; 0x0395 - textpointer MachinePerfectHealthDeckText ; 0x0396 - textpointer MachineSuperSoakerDeckText ; 0x0397 - textpointer MachineHellsDemonDeckText ; 0x0398 - textpointer MachinePremiumThunderDeckText ; 0x0399 - textpointer MachineMysteriousMewtwoDeckText ; 0x039a - textpointer MachineHeavenlyLugiaDeckText ; 0x039b - textpointer MachineBrutalTrainersDeckText ; 0x039c - textpointer MachineDreadfulParalysisDeckText ; 0x039d + textpointer MachineInsectCollectionDeckName ; 0x0376 + textpointer MachineCaveExplorationDeckName ; 0x0377 + textpointer MachineOminousMeadowDeckName ; 0x0378 + textpointer MachineAtrociousWeezingDeckName ; 0x0379 + textpointer MachineTheBenchIsAlsoASurpriseDeckName ; 0x037a + textpointer MachineEnergyConservationDeckName ; 0x037b + textpointer MachineSonicboomDeckName ; 0x037c + textpointer MachineRageOfTheHeavensDeckName ; 0x037d + textpointer MachineDarkWaterDeckName ; 0x037e + textpointer MachineQuickFreezeDeckName ; 0x037f + textpointer MachineWhirlpoolShowerDeckName ; 0x0380 + textpointer MachineWaterGangDeckName ; 0x0381 + textpointer MachineFireballDeckName ; 0x0382 + textpointer MachineCompleteCombustionDeckName ; 0x0383 + textpointer MachineOminousSpiritFlamesDeckName ; 0x0384 + textpointer MachineEternalFireDeckName ; 0x0385 + textpointer MachineBewareTheTrapDeckName ; 0x0386 + textpointer MachineOgresKickDeckName ; 0x0387 + textpointer MachineRockBlastDeckName ; 0x0388 + textpointer MachineHeavyWorkDeckName ; 0x0389 + textpointer MachineSlowbrosFishingDeckName ; 0x038a + textpointer MachineDirectHitDeckName ; 0x038b + textpointer MachineBadDreamDeckName ; 0x038c + textpointer MachineBenchPanicDeckName ; 0x038d + textpointer MachineSnorlaxGuardDeckName ; 0x038e + textpointer MachineEyeOfTheStormDeckName ; 0x038f + textpointer MachineSuddenGrowthDeckName ; 0x0390 + textpointer MachineKingDragoniteDeckName ; 0x0391 + textpointer MachineDarkCharizardDeckName ; 0x0392 + textpointer MachineDarkBlastoiseDeckName ; 0x0393 + textpointer MachineDarkVenusaurDeckName ; 0x0394 + textpointer MachineDarkDragoniteDeckName ; 0x0395 + textpointer MachinePerfectHealthDeckName ; 0x0396 + textpointer MachineSuperSoakerDeckName ; 0x0397 + textpointer MachineHellsDemonDeckName ; 0x0398 + textpointer MachinePremiumThunderDeckName ; 0x0399 + textpointer MachineMysteriousMewtwoDeckName ; 0x039a + textpointer MachineHeavenlyLugiaDeckName ; 0x039b + textpointer MachineBrutalTrainersDeckName ; 0x039c + textpointer MachineDreadfulParalysisDeckName ; 0x039d textpointer MachineInsectCollectionDeckDescriptionText ; 0x039e textpointer MachineCaveExplorationDeckDescriptionText ; 0x039f textpointer MachineOminousMeadowDeckDescriptionText ; 0x03a0 diff --git a/src/wram.asm b/src/wram.asm index d19e657..0fc51fd 100644 --- a/src/wram.asm +++ b/src/wram.asm @@ -2252,31 +2252,42 @@ wNumCardsNeededToBuildDeckMachineDecks:: ; d49f NEXTU -wd49f:: ; d49f +; store (index + 1) +wIndicesAutoDeckMachineUnlockedCategories:: ; d49f + ds NUM_AUTO_DECK_MACHINE_CATEGORIES + + ds $a + +; selected category index of current auto deck machine +wSelectedAutoDeckMachineCategory:: ; d4b3 ds $1 - ds $13 - -wd4b3:: ; d4b3 - ds $1 - -wd4b4:: ; d4b4 - ds $8 - - ds $c +; unlocked category names, description texts of current category, etc. +wAutoDeckMachineTexts:: ; d4b4 + ds 2 * NUM_AUTO_DECK_MACHINE_CATEGORIES wSelectedMachineDeck:: ; d4c8 ds DECK_TEMP_BUFFER_SIZE ENDU +UNION + +; *_ISLAND flag to switch machine 1 and 2 +wAutoDeckMachineIndex:: ; d548 + ds $1 + +NEXTU + wd548:: ; d548 ds $2 -wd54a:: ; d54a +ENDU + +wAutoDeckMachineScrollOffset:: ; d54a ds $1 -wd54b:: ; d54b +wAutoDeckMachineScrollMenuItem:: ; d54b ds $1 wNextGameEvent:: ; d54c From a75880fd5a9ca2bca871d31f725e70b218c9d1f1 Mon Sep 17 00:00:00 2001 From: earthoul Date: Mon, 9 Feb 2026 22:28:50 +0900 Subject: [PATCH 5/9] Refactor and fix filtered-list variants --- src/constants/menu_constants.asm | 4 + src/engine/bank02.asm | 162 +++++++++++++++++-------------- src/wram.asm | 3 +- 3 files changed, 93 insertions(+), 76 deletions(-) diff --git a/src/constants/menu_constants.asm b/src/constants/menu_constants.asm index 5033482..2cb88f8 100644 --- a/src/constants/menu_constants.asm +++ b/src/constants/menu_constants.asm @@ -130,6 +130,10 @@ DEF FILTER_TRAINER EQUS "TYPE_TRAINER" DEF FILTER_ENERGY EQU $20 DEF NUM_FILTERS EQU 9 +DEF NO_FILTERS EQU $ff + +DEF FILTERED_CARD_LIST_SIZE EQU 80 +DEF FILTERED_CARD_LIST_SIZE_BYTES EQU FILTERED_CARD_LIST_SIZE * 2 ; for FilterCardListInHL DEF FILTER_ONLY_PKMN EQU 0 diff --git a/src/engine/bank02.asm b/src/engine/bank02.asm index 59ffa43..744b0d0 100644 --- a/src/engine/bank02.asm +++ b/src/engine/bank02.asm @@ -1306,8 +1306,8 @@ DeckSelectionSubMenu: ld de, wCurDeckName call GetSRAMPointerToCurDeck call CopyListFromHLToDEInSRAM - xor a - ld [wd121], a + xor a ; FALSE + ld [wBillsComputerAllowedInCardList], a call HandleDeckBuildScreen jr nc, .asm_90cd @@ -2982,31 +2982,31 @@ PrintSlashSixty: call ProcessText ret -; creates two separate lists given the card type in register a -; if a card matches the card type given, then it's added to wTempCardList -; if a card has been owned by the player, and its card count is at least 1, -; (or in case it's 0 if it's in any deck configurations saved) -; then its collection count is also added to wTempCardList -; if input a is $ff, then all card types are included +; for a = card type (or NO_FILTERS), +; add to wTempCardList all matching cards +; (or all cards if NO_FILTERS; follow wBillsComputerAllowedInCardList); +; for each of them that is either in collection or in saved decks, +; write its collection count to wOwnedCardsCountList; +; and store the entry count in wNumEntriesInCurFilter CreateFilteredCardList: push af push bc push de push hl -; clear wOwnedCardsCountList and wTempCardList +; init both lists push af - ld a, $51 + ld a, FILTERED_CARD_LIST_SIZE + 1 ld hl, wOwnedCardsCountList call ClearNBytesFromHL - ld a, $a0 + ld a, FILTERED_CARD_LIST_SIZE_BYTES ld hl, wTempCardList call ClearNBytesFromHL pop af -; loops all cards in collection - ld hl, $0 - ld de, 0 +; loop all cards + ld hl, 0 + ld de, GRASS_ENERGY - 1 ld b, a ; input card type .loop_card_ids inc de @@ -3014,7 +3014,7 @@ CreateFilteredCardList: jr c, .store_count ld c, a ld a, b - cp $ff + cp NO_FILTERS jr z, .add_card and FILTER_ENERGY cp FILTER_ENERGY @@ -3043,21 +3043,21 @@ CreateFilteredCardList: ld a, [hl] pop hl cp CARD_NOT_OWNED - jr z, .next_card ; jump if never seen card + jr z, .next_card ; never seen this card or a - jr nz, .ok ; has at least 1 + jr nz, .check_bills_computer ; has at least 1 call .IsCardInAnyDeck - jr c, .next_card ; jump if not in any deck -.ok + jr c, .next_card ; not in any deck either +.check_bills_computer push af cp16 BILLS_COMPUTER - jr nz, .asm_9bb8 - ld a, [wd121] + jr nz, .set_count + ld a, [wBillsComputerAllowedInCardList] or a - jr nz, .asm_9bb8 + jr nz, .set_count pop af jr .next_card -.asm_9bb8 +.set_count pop af push hl @@ -3092,8 +3092,8 @@ CreateFilteredCardList: pop af ret -; returns carry if card ID in register e is not -; found in any of the decks saved in SRAM +; returns carry if input card ID in de +; is not found in any of the decks saved in SRAM .IsCardInAnyDeck: push af push hl @@ -3413,11 +3413,11 @@ PrintFilteredCardList: call EnableSRAM ld hl, sCardCollection ld de, wTempCardCollection - ld b, $00 + ld b, 0 ; aka $100 bytes call CopyBBytesFromHLToDE_Bank02 - ld hl, $a200 - ld de, $c100 - ld b, $00 + ld hl, sCardCollection + $100 + ld de, wTempCardCollection + $100 + ld b, 0 ; aka $100 bytes call CopyBBytesFromHLToDE_Bank02 call DisableSRAM @@ -4997,8 +4997,8 @@ HandleGiftCenterSendCardsScreen: call CopyListFromHLToDE ld hl, .params call InitDeckBuildingParams - ld a, $01 - ld [wd121], a + ld a, TRUE + ld [wBillsComputerAllowedInCardList], a call HandleDeckBuildScreen ret @@ -5082,7 +5082,7 @@ HandleGiftCenterSendCardsMenu: ld b, DECK_TEMP_BUFFER_SIZE + 2 call CopyBBytesFromHLToDE_Bank02 call PrintCardsToSendToPlayerText - call Func_b81d + call PrintCardSelectionList_TempSavedDeck call EnableLCD ldtx hl, SendTheseCardsToPlayerPromptText call YesOrNoMenuWithText @@ -5109,7 +5109,7 @@ Func_a6ef: ld b, DECK_TEMP_BUFFER_SIZE + 2 call CopyBBytesFromHLToDE_Bank02 call EmptyScreenAndDrawTextBox - call Func_b81d + call PrintCardSelectionList_TempSavedDeck ret HandleBlackBoxSendCardsScreen: @@ -5122,8 +5122,8 @@ HandleBlackBoxSendCardsScreen: ld [hl], TX_END ld hl, .params call InitDeckBuildingParams - ld a, $01 - ld [wd121], a + ld a, TRUE + ld [wBillsComputerAllowedInCardList], a call HandleDeckBuildScreen ret @@ -5346,7 +5346,7 @@ PrintFilteredCardSelectionList: ld a, $ff ; all owned cards call CreateCardCollectionListWithDeckCards ld a, TRUE - ld [wd121], a + ld [wBillsComputerAllowedInCardList], a pop af call CreateFilteredCardList @@ -7446,7 +7446,7 @@ GiftCenter_ReceiveCards: ld hl, GiftCenter_CardSelectionParams call InitializeScrollMenuParameters call PrintReceivedTheseCardsText - call Func_b81d + call PrintCardSelectionList_TempSavedDeck call EnableLCD ld a, [wNumEntriesInCurFilter] ld [wNumCardListEntries], a @@ -7539,7 +7539,8 @@ ShowReceivedCardsList: ld [hl], $00 jp PrintCardSelectionList -Func_b81d: +; for card lists using wTempSavedDeckCards +PrintCardSelectionList_TempSavedDeck: xor a ; aka $100 bytes ld hl, wTempCardCollection call ClearNBytesFromHL @@ -7547,10 +7548,10 @@ Func_b81d: ld hl, wTempCardCollection + $100 call ClearNBytesFromHL ld hl, wTempSavedDeckCards - call Func_b84d - ld a, $ff - call Func_b860 - ld a, $05 + call .CountCards + ld a, NO_FILTERS + call .CreateFilteredList + ld a, 5 ld [wNumVisibleCardListEntries], a lb de, 2, 3 ld hl, wCardListCoords @@ -7562,9 +7563,10 @@ Func_b81d: call PrintCardSelectionList ret -Func_b84d: - ld bc, wc000 -.asm_b850 +; set up wTempCardCollection from card list in hl (wTempSavedDeckCards) +.CountCards: + ld bc, wTempCardCollection +.loop_count ld e, [hl] inc hl ld d, [hl] @@ -7577,45 +7579,52 @@ Func_b84d: add hl, bc inc [hl] pop hl - jr .asm_b850 + jr .loop_count -Func_b860: +; simplified version of CreateFilteredCardList +; with wTempCardCollection prepared above +.CreateFilteredList: push af push bc push de push hl + +; init both lists push af - ld a, $51 - ld hl, wUniqueDeckCardList + ld a, FILTERED_CARD_LIST_SIZE + 1 + ld hl, wOwnedCardsCountList call ClearNBytesFromHL - ld a, $a0 + ld a, FILTERED_CARD_LIST_SIZE_BYTES ld hl, wTempCardList call ClearNBytesFromHL pop af - ld hl, $0 - ld de, $0 - ld b, a -.asm_b87d + +; loop all cards + ld hl, 0 + ld de, GRASS_ENERGY - 1 + ld b, a ; input card type +.loop_card_ids inc de call GetCardType - jr c, .asm_b8bc + jr c, .store_count ld c, a ld a, b - cp $ff - jr z, .asm_b89c - and $20 - cp $20 - jr z, .asm_b895 + cp NO_FILTERS + jr z, .add_card + and FILTER_ENERGY + cp FILTER_ENERGY + jr z, .check_energy ld a, c cp b - jr nz, .asm_b87d - jr .asm_b89c -.asm_b895 + jr nz, .loop_card_ids + jr .add_card +.check_energy ld a, c - and $08 - cp $08 - jr nz, .asm_b87d -.asm_b89c + and TYPE_ENERGY + cp TYPE_ENERGY + jr nz, .loop_card_ids + +.add_card push bc push hl add hl, hl @@ -7624,29 +7633,32 @@ Func_b860: ld [hl], e inc hl ld [hl], d - ld hl, wc000 + ld hl, wTempCardCollection add hl, de ld a, [hl] - and $7f + and CARD_COUNT_MASK pop hl or a - jr z, .asm_b8b9 + jr z, .next_card +; set count push hl - ld bc, wUniqueDeckCardList + ld bc, wOwnedCardsCountList add hl, bc ld [hl], a pop hl inc l -.asm_b8b9 +.next_card pop bc - jr .asm_b87d -.asm_b8bc + jr .loop_card_ids + +.store_count ld a, l ld [wNumEntriesInCurFilter], a +; add terminator bytes in both lists ld c, l ld b, h ld a, $ff - ld hl, wUniqueDeckCardList + ld hl, wOwnedCardsCountList add hl, bc ld [hl], a ld hl, wTempCardList diff --git a/src/wram.asm b/src/wram.asm index 0fc51fd..5b46e0a 100644 --- a/src/wram.asm +++ b/src/wram.asm @@ -2024,7 +2024,8 @@ wCardListVisibleOffsetBackup:: ; d11f wNumUniqueCards:: ; d120 ds $1 -wd121:: ; d121 +; flag for Bill's Computer +wBillsComputerAllowedInCardList:: ; d121 ds $1 ; cards that belong to a Booster Pack From 452d9be6eb7c533fa7b31f868d06fa880ecb5886 Mon Sep 17 00:00:00 2001 From: earthoul Date: Tue, 10 Feb 2026 01:11:37 +0900 Subject: [PATCH 6/9] Minor cleanups --- src/engine/bank02.asm | 129 +++++++++++++++++++++++------------------- 1 file changed, 71 insertions(+), 58 deletions(-) diff --git a/src/engine/bank02.asm b/src/engine/bank02.asm index 744b0d0..8e145c8 100644 --- a/src/engine/bank02.asm +++ b/src/engine/bank02.asm @@ -2402,7 +2402,7 @@ OpenDeckConfigurationMenu: jp hl HandleDeckConfigurationMenu: - call Func_98eb + call HandleDeckCardsBreakdown lb de, 0, 0 lb bc, 20, 6 call DrawRegularTextBox @@ -2410,7 +2410,7 @@ HandleDeckConfigurationMenu: call PlaceTextItems .do_frame - ld a, $01 + ld a, TRUE ld [wVBlankOAMCopyToggle], a call DoFrame call HandleMultiDirectionalMenu @@ -2429,7 +2429,7 @@ HandleDeckConfigurationMenu: .asm_9769 push af call HandleMultiDirectionalMenu.DrawCursor - ld a, $01 + ld a, TRUE ld [wVBlankOAMCopyToggle], a pop af ld hl, .function_table @@ -2558,38 +2558,38 @@ DismantleDeck: call GetSRAMPointerToCurDeck ld a, [hl] or a - jr z, .asm_9871 + jr z, .ask_to_save_to_machine push hl call GetSRAMPointerToCurDeckCards call AddDeckToCollection pop hl - ld a, $60 + ld a, DECK_COMPRESSED_STRUCT_SIZE call ClearNBytesFromHL -.asm_9871 +.ask_to_save_to_machine ldtx hl, DeckBuildingRevertAndSaveToMachinePromptText call YesOrNoMenuWithText - jr c, .asm_989d + jr c, .done_dismantle ld a, [wCurDeckName] or a - jr z, .asm_98a0 + jr z, .cannot_save ld a, [wTotalCardCount] cp DECK_SIZE - jp nz, .asm_98a0 + jp nz, .cannot_save call CheckIfThereAreAnyBasicCardsInDeck - jr nc, .asm_98a0 + jr nc, .cannot_save ld hl, wCurDeckName ld de, wCurDeckCards farcall SaveDeckDataToWRAM2 call DisableSRAM farcall OpenDeckSaveMachineFromDeckBuilding -.asm_989d +.done_dismantle add sp, $02 ret -.asm_98a0 +.cannot_save ldtx hl, DeckBuildingWarningIncompleteCannotSaveToMachineText call DrawWideTextBox_WaitForInput - jr .asm_989d + jr .done_dismantle ChangeDeckName: call InputCurDeckName @@ -2597,10 +2597,10 @@ ChangeDeckName: jp HandleDeckBuildScreen.skip_count ; de - coordinates -Func_98b0: +AppendDeckName_Breakdown: push de push hl - ld hl, .Data_98e8 + ld hl, .space ld de, wDefaultText call CopyListFromHLToDE pop hl @@ -2628,27 +2628,27 @@ Func_98b0: katakana " " done -.Data_98e8: +.space katakana " " done -Func_98eb: +HandleDeckCardsBreakdown: lb de, 0, 6 lb bc, 20, 12 call DrawRegularTextBox ld hl, wCurDeckName ld a, [hl] or a - jr z, .asm_9910 + jr z, .got_name lb de, 1, 6 - call Func_98b0 + call AppendDeckName_Breakdown ld hl, wCurDeckName call GetTextLengthInTiles ld a, 5 add b lb de, 1, 6 call ZeroAttributesAtDE -.asm_9910 +.got_name ld hl, wCurDeckCards farcall CheckDeck.asm_25461 lb de, 2, 8 @@ -2657,26 +2657,26 @@ Func_98eb: call ProcessTextFromID ld a, [wDeckCheckEnergyCount] lb de, 15, 8 - call Func_9951 + call .PrintNumber ld a, [wDeckCheckBasicCount] lb de, 15, 10 - call Func_9951 + call .PrintNumber ld a, [wDeckCheckStage1Count] lb de, 15, 12 - call Func_9951 + call .PrintNumber ld a, [wDeckCheckStage2Count] lb de, 15, 14 - call Func_9951 + call .PrintNumber ld a, [wDeckCheckTrainerCount] lb de, 15, 16 - call Func_9951 + call .PrintNumber ret -Func_9951: +.PrintNumber: push de ld hl, wDefaultText call ConvertToNumericalDigits - ld [hl], $00 + ld [hl], TX_END pop de call InitTextPrinting ld hl, wDefaultText @@ -2693,27 +2693,33 @@ CheckIfCurrentDeckWasChanged: jr nz, .set_carry .skip_size_check +; copy the selected deck to wDeckToBuild call GetSRAMPointerToCurDeckCards ld d, h ld e, l - ld hl, wTempCardCollection + ld hl, wDeckToBuild call EnableSRAM bank1call DecompressSRAMDeck call DisableSRAM + +; add terminating bytes ld a, $ff - ld [wTempCardCollection + DECK_SIZE_BYTES], a - ld [wTempCardCollection + DECK_SIZE_BYTES + 1], a + ld [wDeckToBuild + DECK_SIZE_BYTES], a + ld [wDeckToBuild + DECK_SIZE_BYTES + 1], a + +; for each card in wCurDeckCards, +; clear it if found in wDeckToBuild ld hl, wCurDeckCards -.asm_998b +.loop_deck_cards ld e, [hl] inc hl ld d, [hl] inc hl call CheckIfCardIDIsZero - jr c, .asm_99b7 + jr c, .check_empty push hl - ld hl, wTempCardCollection -.asm_9998 + ld hl, wDeckToBuild +.loop_diffs ld c, [hl] inc hl ld b, [hl] @@ -2721,38 +2727,41 @@ CheckIfCurrentDeckWasChanged: ld a, b cp $ff ld a, c - jr nz, .asm_99a9 + jr nz, .compare_card cp $ff - jr nz, .asm_99a9 + jr nz, .compare_card pop hl - jr .asm_998b -.asm_99a9 + jr .loop_deck_cards +.compare_card cp e - jr nz, .asm_9998 + jr nz, .loop_diffs ld a, b cp d - jr nz, .asm_9998 + jr nz, .loop_diffs +; found, clear it dec hl xor a ld [hld], a ld [hl], a pop hl - jr .asm_998b -.asm_99b7 - ld hl, wTempCardCollection -.asm_99ba + jr .loop_deck_cards + +.check_empty + ld hl, wDeckToBuild +.loop_check_empty ld e, [hl] inc hl ld d, [hl] inc hl cp16 $ffff - jr z, .asm_99d2 + jr z, .check_name call CheckIfCardIDIsZero jr nc, .set_carry or a jr nz, .set_carry - jr .asm_99ba -.asm_99d2 + jr .loop_check_empty + +.check_name call GetSRAMPointerToCurDeck ld de, wCurDeckName call EnableSRAM @@ -2766,6 +2775,7 @@ CheckIfCurrentDeckWasChanged: jr nz, .loop_name call DisableSRAM ret + .set_carry call DisableSRAM scf @@ -3073,7 +3083,7 @@ CreateFilteredCardList: .store_count ld a, l ld [wNumEntriesInCurFilter], a -; add terminator bytes in both lists +; add terminating bytes in both lists ld c, l ld b, h ld a, $ff @@ -3198,10 +3208,13 @@ GetCountOfCardInCurDeck: pop hl ret -Func_9c55: +; return total count of card ID in de +; look it up in wTempCardList +; then use the index to retrieve the count from wOwnedCardsCountList +GetOwnedCardCount: push hl push bc - ld hl, wBoosterPackCardList + ld hl, wTempCardList ld b, -1 .loop inc b @@ -3215,14 +3228,14 @@ Func_9c55: ld a, d pop de jr c, .zero ; not found - ; is valid ID, compare card ID +; is valid ID, compare card ID cp d jr nz, .loop ld a, c cp e jr nz, .loop - ; has same card ID, get its count - ld hl, wBoosterPackCardCounts +; has same card ID, get its count + ld hl, wOwnedCardsCountList ld c, b ld b, $00 add hl, bc @@ -3262,7 +3275,7 @@ AppendOwnedCardCountAndStorageCountNumbers: ld [hl], SYM_SLASH inc hl pop de - call Func_9c55 + call GetOwnedCardCount call ConvertToNumericalDigits ld [hl], TX_END pop hl @@ -3495,7 +3508,7 @@ PrintDeckBuildingCardList: ld e, [hl] inc hl ld d, [hl] - ld b, $13 + ld b, 19 ; x coord ld c, e dec c ld a, [wScrollMenuScrollOffset] @@ -5575,9 +5588,9 @@ AppendOwnedCardCountNumber: inc hl jr .loop .end - call Func_9c55 + call GetOwnedCardCount call ConvertToNumericalDigits - ld bc, $84 + ldfw bc, "枚" ld [hl], c inc hl ld [hl], b @@ -7654,7 +7667,7 @@ PrintCardSelectionList_TempSavedDeck: .store_count ld a, l ld [wNumEntriesInCurFilter], a -; add terminator bytes in both lists +; add terminating bytes in both lists ld c, l ld b, h ld a, $ff From 7b06fa3cae7869a7c57a6618ac318ae541c41633 Mon Sep 17 00:00:00 2001 From: earthoul Date: Tue, 10 Feb 2026 17:45:11 +0900 Subject: [PATCH 7/9] Relabel Auto Deck Machine unlockables --- src/constants/menu_constants.asm | 13 ++++ src/engine/bank03.asm | 115 ++++++++++++++++++------------- 2 files changed, 81 insertions(+), 47 deletions(-) diff --git a/src/constants/menu_constants.asm b/src/constants/menu_constants.asm index 2cb88f8..03566ce 100644 --- a/src/constants/menu_constants.asm +++ b/src/constants/menu_constants.asm @@ -163,6 +163,19 @@ DEF NUM_AUTO_DECK_MACHINE_REGULAR_CATEGORIES EQU const_value ; shared with machi const AUTO_DECK_LEGENDARY ; 9 DEF NUM_AUTO_DECK_MACHINE_CATEGORIES EQU const_value ; shared with machine 2 +; auto deck machine 2 + const_def + const AUTO_DECK_DARK_GRASS ; 0 + const AUTO_DECK_DARK_LIGHTNING ; 1 + const AUTO_DECK_DARK_WATER ; 2 + const AUTO_DECK_DARK_FIRE ; 3 + const AUTO_DECK_DARK_FIGHTING ; 4 + const AUTO_DECK_DARK_PSYCHIC ; 5 + const AUTO_DECK_COLORLESS ; 6 + const AUTO_DECK_DARK_SPECIAL ; 7 + const AUTO_DECK_SUPER_RARE ; 8 + const AUTO_DECK_MYSTERIOUS ; 9 + ; auto_deck args DEF AUTO_DECK_ENTRY_SIZE EQU 6 diff --git a/src/engine/bank03.asm b/src/engine/bank03.asm index 66227d1..ed6f55e 100644 --- a/src/engine/bank03.asm +++ b/src/engine/bank03.asm @@ -2320,7 +2320,7 @@ ENDR ret ; a = machine 1 category index -; jump to .event_table[a] +; jump to .category_table[a] ; return a = event flag(s), with carry if nz, with no carry otherwise ; single event check: category unlock ; multiple : per-deck unlock @@ -2329,17 +2329,19 @@ CheckCurAutoDeckMachine1CategoryUnlockEvents: push de push hl sla a - ld hl, .event_table + ld hl, .category_table add_hl_a ld a, [hli] ld h, [hl] ld l, a jp hl -.unlocked_from_start +; unlocked from start +.BasicDecks jp .set_carry -.get_four_tcgisland_coins +; received anti-GR decks, checked with coin flags +.AntiGRDecks ld a, EVENT_GOT_KABUTO_COIN call GetEventValue push af @@ -2368,43 +2370,51 @@ CheckCurAutoDeckMachine1CategoryUnlockEvents: jp nz, .set_carry jp .clear_carry -.get_gr_coin_top_left +; beat GR1 +.FightingDecks ld a, EVENT_GOT_GR_COIN_PIECE_TOP_LEFT call GetEventValue jp nz, .set_carry jp .clear_carry -.get_gr_coin_top_right +; beat GR2 +.GrassDecks ld a, EVENT_GOT_GR_COIN_PIECE_TOP_RIGHT call GetEventValue jp nz, .set_carry jp .clear_carry -.get_starmie_coin +; beat GR3 in Water Club +.WaterDecks ld a, EVENT_GOT_STARMIE_COIN call GetEventValue jp nz, .set_carry jp .clear_carry -.get_gr_coin_bottom_left +; beat GR3 in Fire Club +.FireDecks ld a, EVENT_GOT_GR_COIN_PIECE_BOTTOM_LEFT call GetEventValue jp nz, .set_carry jp .clear_carry -.get_pikachu_coin +; beat controlled Isaac +.LightningDecks ld a, EVENT_GOT_PIKACHU_COIN call GetEventValue jp nz, .set_carry jp .clear_carry -.get_gr_coin_bottom_right +; beat GR4 +.PsychicDecks ld a, EVENT_GOT_GR_COIN_PIECE_BOTTOM_RIGHT call GetEventValue jp nz, .set_carry jp .clear_carry -.win_final_cup_or_postgame +; won final cup / post-game +; each unlocks two decks +.SpecialDecks ld a, EVENT_WON_FINAL_CUP call GetEventValue push af @@ -2429,7 +2439,8 @@ CheckCurAutoDeckMachine1CategoryUnlockEvents: jp nz, .set_carry jp .clear_carry -.win_grand_master_cup: +; won grand master cup +.LegendaryDecks: ld a, EVENT_WON_GRAND_MASTER_CUP call GetEventValue jp nz, .set_carry @@ -2450,88 +2461,98 @@ CheckCurAutoDeckMachine1CategoryUnlockEvents: ccf ret -.event_table - dw .unlocked_from_start - dw .get_four_tcgisland_coins - dw .get_gr_coin_top_left - dw .get_gr_coin_top_right - dw .get_starmie_coin - dw .get_gr_coin_bottom_left - dw .get_pikachu_coin - dw .get_gr_coin_bottom_right - dw .win_final_cup_or_postgame - dw .win_grand_master_cup +.category_table + dw .BasicDecks ; AUTO_DECK_BASIC + dw .AntiGRDecks ; AUTO_DECK_GIVEN + dw .FightingDecks ; AUTO_DECK_FIGHTING + dw .GrassDecks ; AUTO_DECK_GRASS + dw .WaterDecks ; AUTO_DECK_WATER + dw .FireDecks ; AUTO_DECK_FIRE + dw .LightningDecks ; AUTO_DECK_LIGHTNING + dw .PsychicDecks ; AUTO_DECK_PSYCHIC + dw .SpecialDecks ; AUTO_DECK_SPECIAL + dw .LegendaryDecks ; AUTO_DECK_LEGENDARY ; a = machine 2 category index -; jump to .event_table[a] -; return a = event flag(s) with carry if nz, with no carry otherwise +; jump to .category_table[a] +; return a = event flag with carry if nz, with no carry otherwise CheckCurAutoDeckMachine2CategoryUnlockEvents: push bc push de push hl sla a - ld hl, .event_table + ld hl, .category_table add_hl_a ld a, [hli] ld h, [hl] ld l, a jp hl -.get_golbat_coin +; beat Morino +.DarkGrassDecks ld a, EVENT_GOT_GOLBAT_COIN call GetEventValue jp nz, .set_carry jp .clear_carry -.get_magnemite_coin +; beat Catherine +.DarkLightningDecks ld a, EVENT_GOT_MAGNEMITE_COIN call GetEventValue jp nz, .set_carry jp .clear_carry -.get_psyduck_coin +; beat Kanoko +.DarkWaterDecks ld a, EVENT_GOT_PSYDUCK_COIN call GetEventValue jp nz, .set_carry jp .clear_carry -.get_magmar_coin +; beat Hidero +.DarkFireDecks ld a, EVENT_GOT_MAGMAR_COIN call GetEventValue jp nz, .set_carry jp .clear_carry -.get_machamp_coin +; beat Kamiya +.DarkFightingDecks ld a, EVENT_GOT_MACHAMP_COIN call GetEventValue jp nz, .set_carry jp .clear_carry -.get_mew_coin +; beat Mami +.DarkPsychicDecks ld a, EVENT_GOT_MEW_COIN call GetEventValue jp nz, .set_carry jp .clear_carry -.get_snorlax_coin +; beat all three Colorless Altar guardians +.ColorlessDecks ld a, EVENT_GOT_SNORLAX_COIN call GetEventValue jp nz, .set_carry jp .clear_carry -.enter_biruritchi_room +; beat Rui +.DarkSpecialDecks ld a, EVENT_GR_CASTLE_STAIRS_RUI_ROADBLOCK call GetEventValue jp nz, .set_carry jp .clear_carry -.battle_ishihara +; battled Ishihara +.SuperRareDecks ld a, EVENT_BATTLED_ISHIHARA call GetEventValue jp nz, .set_carry jp .clear_carry -.postgame +; post-game +.MysteriousDecks ld a, EVENT_MASONS_LAB_CHALLENGE_MACHINE_STATE call GetEventValue jp nz, .set_carry @@ -2552,17 +2573,17 @@ CheckCurAutoDeckMachine2CategoryUnlockEvents: ccf ret -.event_table - dw .get_golbat_coin - dw .get_magnemite_coin - dw .get_psyduck_coin - dw .get_magmar_coin - dw .get_machamp_coin - dw .get_mew_coin - dw .get_snorlax_coin - dw .enter_biruritchi_room - dw .battle_ishihara - dw .postgame +.category_table + dw .DarkGrassDecks ; AUTO_DECK_DARK_GRASS + dw .DarkLightningDecks ; AUTO_DECK_DARK_LIGHTNING + dw .DarkWaterDecks ; AUTO_DECK_DARK_WATER + dw .DarkFireDecks ; AUTO_DECK_DARK_FIRE + dw .DarkFightingDecks ; AUTO_DECK_DARK_FIGHTING + dw .DarkPsychicDecks ; AUTO_DECK_DARK_PSYCHIC + dw .ColorlessDecks ; AUTO_DECK_COLORLESS + dw .DarkSpecialDecks ; AUTO_DECK_DARK_SPECIAL + dw .SuperRareDecks ; AUTO_DECK_SUPER_RARE + dw .MysteriousDecks ; AUTO_DECK_MYSTERIOUS GetNumberOfDeckDiagnosisStepsUnlocked: push bc From a26201e14a3688ae2367b2b08a5dd63eb14cc8f9 Mon Sep 17 00:00:00 2001 From: earthoul Date: Tue, 10 Feb 2026 17:58:30 +0900 Subject: [PATCH 8/9] Fix deck-name copy kana-switcher labels --- src/engine/bank0a.asm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/engine/bank0a.asm b/src/engine/bank0a.asm index 4bc9a38..c8d2779 100644 --- a/src/engine/bank0a.asm +++ b/src/engine/bank0a.asm @@ -3497,12 +3497,13 @@ ReadCurAutoDeckName: cp TX_FULLWIDTH4 jr z, .fw4 cp c - jr z, .kana + jr z, .kana_switch +; kana, no switch ld [hl], b inc hl ld [hli], a jr .loop_copy_name -.kana +.kana_switch ld [hli], a ld a, [de] inc de From 73d784616f7565b8d784bc57ec3ac5919ed7b30e Mon Sep 17 00:00:00 2001 From: earthoul Date: Sun, 15 Feb 2026 13:53:48 +0900 Subject: [PATCH 9/9] Fix typos Co-authored-by: dannye <33dannye@gmail.com> --- src/engine/bank02.asm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/bank02.asm b/src/engine/bank02.asm index 8e145c8..b324470 100644 --- a/src/engine/bank02.asm +++ b/src/engine/bank02.asm @@ -686,7 +686,7 @@ EraseCheckMenuCursor_YourOrOppPlayArea: ; fallthrough ; for a = tile byte, -; draw it in the curosr position +; draw it in the cursor position ; by converting the position to coordinates DrawCheckMenuCursor_YourOrOppPlayArea: ld e, a @@ -1721,7 +1721,7 @@ EraseCheckMenuCursor: ; fallthrough ; for a = tile byte, -; draw it in the curosr position +; draw it in the cursor position ; by converting the position to coordinates DrawCheckMenuCursor: ld e, a