1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
|
INCLUDE "data/glossary_menu_transitions.asm"
; copies DECK_SIZE number of cards from de to hl in SRAM
CopyDeckFromSRAM:
push bc
call EnableSRAM
ld b, DECK_SIZE
.loop
ld a, [de]
inc de
ld [hli], a
dec b
jr nz, .loop
xor a
ld [hl], a
call DisableSRAM
pop bc
ret
; clears some WRAM addresses to act as
; terminator bytes to wFilteredCardList and wCurDeckCards
WriteCardListsTerminatorBytes:
xor a
ld hl, wFilteredCardList
ld bc, DECK_SIZE
add hl, bc
ld [hl], a ; wcf16
ld hl, wCurDeckCards
ld bc, DECK_CONFIG_BUFFER_SIZE
add hl, bc
ld [hl], a ; wCurDeckCardsTerminator
ret
; inits some SRAM addresses
InitPromotionalCardAndDeckCounterSaveData:
call EnableSRAM
xor a
ld hl, sHasPromotionalCards
ld [hli], a
inc a ; $1
ld [hli], a ; sb704
ld [hli], a
ld [hl], a
ld [sUnnamedDeckCounter], a
call DisableSRAM
; ret missing
; unintentional fallthrough
; loads the Hard Cards icon gfx to v0Tiles2
LoadHandCardsIcon:
ld hl, HandCardsGfx
ld de, v0Tiles2 + $38 tiles
call CopyListFromHLToDE
ret
HandCardsGfx:
INCBIN "gfx/hand_cards.2bpp"
db $00 ; end of data
EmptyScreenAndLoadFontDuelAndHandCardsIcons:
xor a
ld [wTileMapFill], a
call EmptyScreen
call ZeroObjectPositions
ld a, $1
ld [wVBlankOAMCopyToggle], a
call LoadSymbolsFont
call LoadDuelCardSymbolTiles
call LoadHandCardsIcon
bank1call SetDefaultConsolePalettes
lb de, $3c, $bf
call SetupText
ret
; empties screen, zeroes object positions,
; loads cursor tile, symbol fonts, duel card symbols
; hand card icon and sets default palettes
Func_8d78:
xor a
ld [wTileMapFill], a
call ZeroObjectPositions
call EmptyScreen
ld a, $1
ld [wVBlankOAMCopyToggle], a
call LoadCursorTile
call LoadSymbolsFont
call LoadDuelCardSymbolTiles
call LoadHandCardsIcon
bank1call SetDefaultConsolePalettes
lb de, $3c, $bf
call SetupText
ret
; inits the following deck building params from hl:
; wMaxNumCardsAllowed
; wSameNameCardsLimit
; wIncludeCardsInDeck
; wDeckConfigurationMenuHandlerFunction
; wDeckConfigurationMenuTransitionTable
InitDeckBuildingParams:
ld de, wMaxNumCardsAllowed
ld b, $7
.loop
ld a, [hli]
ld [de], a
inc de
dec b
jr nz, .loop
ret
DeckBuildingParams:
db DECK_CONFIG_BUFFER_SIZE ; max number of cards
db MAX_NUM_SAME_NAME_CARDS ; max number of same name cards
db TRUE ; whether to include deck cards
dw HandleDeckConfigurationMenu
dw DeckConfigurationMenu_TransitionTable
DeckSelectionMenu:
ld hl, DeckBuildingParams
call InitDeckBuildingParams
ld a, ALL_DECKS
call DrawDecksScreen
xor a
.init_menu_params
ld hl, .DeckSelectionMenuParameters
call InitializeMenuParameters
ldtx hl, PleaseSelectDeckText
call DrawWideTextBox_PrintText
.loop_input
call DoFrame
jr c, .init_menu_params ; reinit menu parameters
call HandleStartButtonInDeckSelectionMenu
jr c, .init_menu_params
call HandleMenuInput
jr nc, .loop_input
ldh a, [hCurMenuItem]
cp $ff
ret z ; B btn returns
; A btn pressed on a deck
ld [wCurDeck], a
jp DeckSelectionSubMenu
.DeckSelectionMenuParameters
db 1, 2 ; cursor x, cursor y
db 3 ; y displacement between items
db 4 ; number of items
db SYM_CURSOR_R ; cursor tile number
db SYM_SPACE ; tile behind cursor
dw NULL ; function pointer if non-0
; handles START button press when in deck selection menu
; does nothing if START button isn't pressed
; if a press was handled, returns carry
; prints "There is no deck here!" if the selected deck is empty
HandleStartButtonInDeckSelectionMenu:
ldh a, [hDPadHeld]
and START
ret z ; skip
; set menu item as current deck
ld a, [wCurMenuItem]
ld [wCurDeck], a
call CheckIfCurDeckIsValid
jp nc, .valid_deck ; can be jr
; not a valid deck, cancel
ld a, $ff ; cancel
call PlaySFXConfirmOrCancel
call PrintThereIsNoDeckHereText
scf
ret
.valid_deck
ld a, $1
call PlaySFXConfirmOrCancel
call GetPointerToDeckCards
push hl
call GetPointerToDeckName
pop de
call OpenDeckConfirmationMenu
ld a, ALL_DECKS
call DrawDecksScreen
ld a, [wCurDeck]
scf
ret
OpenDeckConfirmationMenu:
; copy deck name
push de
ld de, wCurDeckName
call CopyListFromHLToDEInSRAM
pop de
; copy deck cards
ld hl, wCurDeckCards
call CopyDeckFromSRAM
ld a, NUM_FILTERS
ld hl, wCardFilterCounts
call ClearNBytesFromHL
ld a, DECK_SIZE
ld [wTotalCardCount], a
ld hl, wCardFilterCounts
ld [hl], a
call HandleDeckConfirmationMenu
ret
; handles the submenu when selecting a deck
; (Modify Deck, Select Deck, Change Name and Cancel)
DeckSelectionSubMenu:
call DrawWideTextBox
ld hl, DeckSelectionData
call PlaceTextItems
call ResetCheckMenuCursorPositionAndBlink
.loop_input
call DoFrame
call HandleCheckMenuInput
jp nc, .loop_input
cp $ff
jr nz, .option_selected
; B btn pressed
; erase cursor and go back
; to deck selection handling
call EraseCheckMenuCursor
ld a, [wCurDeck]
jp DeckSelectionMenu.init_menu_params
.option_selected
ld a, [wCheckMenuCursorXPosition]
or a
jp nz, DeckSelectionSubMenu_SelectOrCancel
ld a, [wCheckMenuCursorYPosition]
or a
jp nz, .ChangeName
; Modify Deck
; read deck from SRAM
; TODO
call GetPointerToDeckCards
ld e, l
ld d, h
ld hl, wCurDeckCards
call CopyDeckFromSRAM
ld a, 20
ld hl, wCurDeckName
call ClearNBytesFromHL
ld de, wCurDeckName
call GetPointerToDeckName
call CopyListFromHLToDEInSRAM
call HandleDeckBuildScreen
jr nc, .asm_8ec4
call EnableSRAM
ld hl, wCurDeckCards
call DecrementDeckCardsInCollection
call GetPointerToDeckCards
call AddDeckToCollection
ld e, l
ld d, h
ld hl, wCurDeckCards
ld b, DECK_SIZE
.asm_8ea9
ld a, [hli]
ld [de], a
inc de
dec b
jr nz, .asm_8ea9
call GetPointerToDeckName
ld d, h
ld e, l
ld hl, wCurDeckName
call CopyListFromHLToDE
call GetPointerToDeckName
ld a, [hl]
call DisableSRAM
or a
jr z, .get_input_deck_name
.asm_8ec4
ld a, ALL_DECKS
call DrawDecksScreen
ld a, [wCurDeck]
jp DeckSelectionMenu.init_menu_params
.ChangeName
call CheckIfCurDeckIsValid
jp nc, .get_input_deck_name
call PrintThereIsNoDeckHereText
jp DeckSelectionMenu.init_menu_params
.get_input_deck_name
ld a, 20
ld hl, wCurDeckName
call ClearNBytesFromHL
ld de, wCurDeckName
call GetPointerToDeckName
call CopyListFromHLToDEInSRAM
call InputCurDeckName
call GetPointerToDeckName
ld d, h
ld e, l
ld hl, wCurDeckName
call CopyListFromHLToDEInSRAM
ld a, ALL_DECKS
call DrawDecksScreen
ld a, [wCurDeck]
jp DeckSelectionMenu.init_menu_params
; gets current deck's name from user input
InputCurDeckName:
ld a, [wCurDeck]
or a
jr nz, .deck_2
ld hl, Deck1Data
jr .got_deck_ptr
.deck_2
dec a
jr nz, .deck_3
ld hl, Deck2Data
jr .got_deck_ptr
.deck_3
dec a
jr nz, .deck_4
ld hl, Deck3Data
jr .got_deck_ptr
.deck_4
ld hl, Deck4Data
.got_deck_ptr
ld a, MAX_DECK_NAME_LENGTH
lb bc, 4, 1
ld de, wCurDeckName
farcall InputDeckName
ld a, [wCurDeckName]
or a
ret nz
; empty name
call .UnnamedDeck
ret
; handles the naming of unnamed decks
; inputs as the deck name "DECK XXX"
; where XXX is the current unnamed deck counter
.UnnamedDeck
; read the current unnamed deck number
; and convert it to text
ld hl, sUnnamedDeckCounter
call EnableSRAM
ld a, [hli]
ld h, [hl]
call DisableSRAM
ld l, a
ld de, wDefaultText
call TwoByteNumberToText
ld hl, wCurDeckName
ld [hl], $6
inc hl
ld [hl], "D"
inc hl
ld [hl], "e"
inc hl
ld [hl], "c"
inc hl
ld [hl], "k"
inc hl
ld [hl], " "
inc hl
ld de, wDefaultText + 2
ld a, [de]
inc de
ld [hli], a
ld a, [de]
inc de
ld [hli], a
ld a, [de]
ld [hli], a
xor a
ld [hl], a
; increment the unnamed deck counter
ld hl, sUnnamedDeckCounter
call EnableSRAM
ld e, [hl]
inc hl
ld d, [hl]
; capped at 999
ld a, HIGH(MAX_UNNAMED_DECK_NUM)
cp d
jr nz, .incr_counter
ld a, LOW(MAX_UNNAMED_DECK_NUM)
cp e
jr nz, .incr_counter
; reset counter
ld de, 0
.incr_counter
inc de
ld [hl], d
dec hl
ld [hl], e
call DisableSRAM
ret
; handle deck selection sub-menu
; the option is either "Select Deck" or "Cancel"
; depending on the cursor Y pos
DeckSelectionSubMenu_SelectOrCancel:
ld a, [wCheckMenuCursorYPosition]
or a
jp nz, CancelDeckSelectionSubMenu
; select deck
call CheckIfCurDeckIsValid
jp nc, .SelectDeck
; invalid deck
call PrintThereIsNoDeckHereText
jp DeckSelectionMenu.init_menu_params
.SelectDeck
call EnableSRAM
ld a, [sCurrentlySelectedDeck]
call DisableSRAM
; draw empty rectangle on currently selected deck
; i.e. erase the Hand Cards Gfx icon
ld h, $3
ld l, a
call HtimesL
ld e, l
inc e
ld d, 2
xor a
lb hl, 0, 0
lb bc, 2, 2
call FillRectangle
; set current deck as the selected deck
; and draw the Hand Cards Gfx icon
ld a, [wCurDeck]
call EnableSRAM
ld [sCurrentlySelectedDeck], a
call DisableSRAM
call DrawHandCardsTileOnCurDeck
; print "<DECK> was chosen as the dueling deck!"
call GetPointerToDeckName
call EnableSRAM
call CopyDeckName
call DisableSRAM
xor a
ld [wTxRam2], a
ld [wTxRam2 + 1], a
ldtx hl, ChosenAsDuelingDeckText
call DrawWideTextBox_WaitForInput
ld a, [wCurDeck]
jp DeckSelectionMenu.init_menu_params
PrintThereIsNoDeckHereText:
ldtx hl, ThereIsNoDeckHereText
call DrawWideTextBox_WaitForInput
ld a, [wCurDeck]
ret
; returns carry if deck in wCurDeck
; is not a valid deck
CheckIfCurDeckIsValid:
ld a, [wCurDeck]
ld hl, wDecksValid
ld b, $0
ld c, a
add hl, bc
ld a, [hl]
or a
ret nz ; is valid
scf
ret ; is not valid
; write to $d00a the decimal representation (number characters)
; of the value in hl
; unreferenced?
Func_9001:
ld de, $d00a
ld bc, -100
call .GetNumberChar
ld bc, -10
call .GetNumberChar
ld bc, -1
call .GetNumberChar
ret
.GetNumberChar
ld a, SYM_0 - 1
.loop
inc a
add hl, bc
jr c, .loop
ld [de], a
inc de
ld a, l
sub c
ld l, a
ld a, h
sbc b
ld h, a
ret
CancelDeckSelectionSubMenu:
ret
DeckSelectionData:
textitem 2, 14, ModifyDeckText
textitem 12, 14, SelectDeckText
textitem 2, 16, ChangeNameText
textitem 12, 16, CancelText
db $ff
; return, in hl, the pointer to sDeckXName where X is [wCurDeck] + 1
GetPointerToDeckName:
ld a, [wCurDeck]
ld h, a
ld l, DECK_STRUCT_SIZE
call HtimesL
push de
ld de, sDeck1Name
add hl, de
pop de
ret
; return, in hl, the pointer to sDeckXCards where X is [wCurDeck] + 1
GetPointerToDeckCards:
push af
ld a, [wCurDeck]
ld h, a
ld l, sDeck2Cards - sDeck1Cards
call HtimesL
push de
ld de, sDeck1Cards
add hl, de
pop de
pop af
ret
ResetCheckMenuCursorPositionAndBlink:
xor a
ld [wCheckMenuCursorXPosition], a
ld [wCheckMenuCursorYPosition], a
ld [wCheckMenuCursorBlinkCounter], a
ret
|