Refactor Deck Save Machine engine

This commit is contained in:
earthoul 2026-02-08 00:11:48 +09:00
parent 00ccbbb6a4
commit 2d65b27799
No known key found for this signature in database
GPG Key ID: 9049439C902677E4
9 changed files with 944 additions and 673 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -5675,7 +5675,7 @@ CallMinicomMenuFunction:
MinicomDeckSaveMachine:
farcall ClearSpriteAnimsAndSetInitialGraphicsConfiguration
farcall Func_baec
farcall HandleDeckSaveMachineMenu
ret
MinicomCardAlbum:

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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]

View File

@ -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