Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/link/cable_club.asm
1271 views
1
; performs the appropriate action when the player uses the gameboy on the table in the Colosseum or Trade Center
2
; In the Colosseum, it starts a battle. In the Trade Center, it displays the trade selection screen.
3
; Before doing either action, it swaps random numbers, trainer names and party data with the other gameboy.
4
CableClub_DoBattleOrTrade:
5
ld c, 80
6
call DelayFrames
7
call ClearScreen
8
call UpdateSprites
9
call LoadFontTilePatterns
10
call LoadHpBarAndStatusTilePatterns
11
call LoadTrainerInfoTextBoxTiles
12
hlcoord 3, 8
13
ld b, 2
14
ld c, 12
15
call CableClub_TextBoxBorder
16
hlcoord 4, 10
17
ld de, PleaseWaitString
18
call PlaceString
19
ld hl, wPlayerNumHits
20
xor a
21
ld [hli], a
22
ld [hl], $50
23
; fall through
24
25
; This is called after completing a trade.
26
CableClub_DoBattleOrTradeAgain:
27
ld hl, wSerialPlayerDataBlock
28
ld a, SERIAL_PREAMBLE_BYTE
29
ld b, 6
30
.writePlayerDataBlockPreambleLoop
31
ld [hli], a
32
dec b
33
jr nz, .writePlayerDataBlockPreambleLoop
34
ld hl, wSerialRandomNumberListBlock
35
ld a, SERIAL_PREAMBLE_BYTE
36
ld b, 7
37
.writeRandomNumberListPreambleLoop
38
ld [hli], a
39
dec b
40
jr nz, .writeRandomNumberListPreambleLoop
41
ld b, 10
42
.generateRandomNumberListLoop
43
call Random
44
cp SERIAL_PREAMBLE_BYTE ; all the random numbers have to be less than the preamble byte
45
jr nc, .generateRandomNumberListLoop
46
ld [hli], a
47
dec b
48
jr nz, .generateRandomNumberListLoop
49
ld hl, wSerialPartyMonsPatchList
50
ld a, SERIAL_PREAMBLE_BYTE
51
ld [hli], a
52
ld [hli], a
53
ld [hli], a
54
ld b, $c8
55
xor a
56
.zeroPlayerDataPatchListLoop
57
ld [hli], a
58
dec b
59
jr nz, .zeroPlayerDataPatchListLoop
60
ld hl, wLinkEnemyTrainerName
61
ld bc, wTrainerHeaderPtr - wLinkEnemyTrainerName
62
.zeroEnemyPartyLoop
63
xor a
64
ld [hli], a
65
dec bc
66
ld a, b
67
or c
68
jr nz, .zeroEnemyPartyLoop
69
ld hl, wPartyMons - 1
70
ld de, wSerialPartyMonsPatchList + 10
71
ld bc, 0
72
.patchPartyMonsLoop
73
inc c
74
ld a, c
75
cp SERIAL_PREAMBLE_BYTE
76
jr z, .startPatchListPart2
77
ld a, b
78
dec a ; are we in part 2 of the patch list?
79
jr nz, .checkPlayerDataByte ; jump if in part 1
80
; if we're in part 2
81
ld a, c
82
cp (wPartyMonOT - (wPartyMons - 1)) - (SERIAL_PREAMBLE_BYTE - 1)
83
jr z, .finishedPatchingPlayerData
84
.checkPlayerDataByte
85
inc hl
86
ld a, [hl]
87
cp SERIAL_NO_DATA_BYTE
88
jr nz, .patchPartyMonsLoop
89
; if the player data byte matches SERIAL_NO_DATA_BYTE, patch it with $FF and record the offset in the patch list
90
ld a, c
91
ld [de], a
92
inc de
93
ld [hl], $ff
94
jr .patchPartyMonsLoop
95
.startPatchListPart2
96
ld a, SERIAL_PATCH_LIST_PART_TERMINATOR
97
ld [de], a ; end of part 1
98
inc de
99
lb bc, 1, 0
100
jr .patchPartyMonsLoop
101
.finishedPatchingPlayerData
102
ld a, SERIAL_PATCH_LIST_PART_TERMINATOR
103
ld [de], a ; end of part 2
104
call Serial_SyncAndExchangeNybble
105
ldh a, [hSerialConnectionStatus]
106
cp USING_INTERNAL_CLOCK
107
jr nz, .skipSendingTwoZeroBytes
108
; if using internal clock
109
; send two zero bytes for syncing purposes?
110
call Delay3
111
xor a
112
ldh [hSerialSendData], a
113
ld a, SC_START | SC_INTERNAL
114
ldh [rSC], a
115
call DelayFrame
116
xor a
117
ldh [hSerialSendData], a
118
ld a, SC_START | SC_INTERNAL
119
ldh [rSC], a
120
.skipSendingTwoZeroBytes
121
call Delay3
122
ld a, IE_SERIAL
123
ldh [rIE], a
124
ld hl, wSerialRandomNumberListBlock
125
ld de, wSerialOtherGameboyRandomNumberListBlock
126
ld bc, SERIAL_RN_PREAMBLE_LENGTH + SERIAL_RNS_LENGTH
127
vc_hook Wireless_ExchangeBytes_RNG_state_unknown_Type5
128
call Serial_ExchangeBytes
129
ld a, SERIAL_NO_DATA_BYTE
130
ld [de], a
131
ld hl, wSerialPlayerDataBlock
132
ld de, wSerialEnemyDataBlock
133
ld bc, SERIAL_PREAMBLE_LENGTH + NAME_LENGTH + 1 + PARTY_LENGTH + 1 + (PARTYMON_STRUCT_LENGTH + NAME_LENGTH * 2) * PARTY_LENGTH + 3
134
vc_hook Wireless_ExchangeBytes_party_structs
135
call Serial_ExchangeBytes
136
ld a, SERIAL_NO_DATA_BYTE
137
ld [de], a
138
ld hl, wSerialPartyMonsPatchList
139
ld de, wSerialEnemyMonsPatchList
140
ld bc, 200
141
vc_hook Wireless_ExchangeBytes_patch_lists
142
call Serial_ExchangeBytes
143
ld a, IE_SERIAL | IE_TIMER | IE_VBLANK
144
ldh [rIE], a
145
ld a, SFX_STOP_ALL_MUSIC
146
call PlaySound
147
ldh a, [hSerialConnectionStatus]
148
cp USING_INTERNAL_CLOCK
149
jr z, .skipCopyingRandomNumberList ; the list generated by the gameboy clocking the connection is used by both gameboys
150
ld hl, wSerialOtherGameboyRandomNumberListBlock
151
.findStartOfRandomNumberListLoop
152
ld a, [hli]
153
and a
154
jr z, .findStartOfRandomNumberListLoop
155
cp SERIAL_PREAMBLE_BYTE
156
jr z, .findStartOfRandomNumberListLoop
157
cp SERIAL_NO_DATA_BYTE
158
jr z, .findStartOfRandomNumberListLoop
159
dec hl
160
ld de, wLinkBattleRandomNumberList
161
ld c, 10
162
.copyRandomNumberListLoop
163
ld a, [hli]
164
cp SERIAL_NO_DATA_BYTE
165
jr z, .copyRandomNumberListLoop
166
ld [de], a
167
inc de
168
dec c
169
jr nz, .copyRandomNumberListLoop
170
.skipCopyingRandomNumberList
171
ld hl, wSerialEnemyDataBlock + 3
172
.findStartOfEnemyNameLoop
173
ld a, [hli]
174
and a
175
jr z, .findStartOfEnemyNameLoop
176
cp SERIAL_PREAMBLE_BYTE
177
jr z, .findStartOfEnemyNameLoop
178
cp SERIAL_NO_DATA_BYTE
179
jr z, .findStartOfEnemyNameLoop
180
dec hl
181
ld de, wLinkEnemyTrainerName
182
ld c, NAME_LENGTH
183
.copyEnemyNameLoop
184
ld a, [hli]
185
cp SERIAL_NO_DATA_BYTE
186
jr z, .copyEnemyNameLoop
187
ld [de], a
188
inc de
189
dec c
190
jr nz, .copyEnemyNameLoop
191
ld de, wEnemyPartyCount
192
ld bc, wTrainerHeaderPtr - wEnemyPartyCount
193
.copyEnemyPartyLoop
194
ld a, [hli]
195
cp SERIAL_NO_DATA_BYTE
196
jr z, .copyEnemyPartyLoop
197
ld [de], a
198
inc de
199
dec bc
200
ld a, b
201
or c
202
jr nz, .copyEnemyPartyLoop
203
ld de, wSerialPartyMonsPatchList
204
ld hl, wPartyMons
205
ld c, 2 ; patch list has 2 parts
206
.unpatchPartyMonsLoop
207
ld a, [de]
208
inc de
209
and a
210
jr z, .unpatchPartyMonsLoop
211
cp SERIAL_PREAMBLE_BYTE
212
jr z, .unpatchPartyMonsLoop
213
cp SERIAL_NO_DATA_BYTE
214
jr z, .unpatchPartyMonsLoop
215
cp SERIAL_PATCH_LIST_PART_TERMINATOR
216
jr z, .finishedPartyMonsPatchListPart
217
push hl
218
push bc
219
ld b, 0
220
dec a
221
ld c, a
222
add hl, bc
223
ld a, SERIAL_NO_DATA_BYTE
224
ld [hl], a
225
pop bc
226
pop hl
227
jr .unpatchPartyMonsLoop
228
.finishedPartyMonsPatchListPart
229
ld hl, wPartyMons + (SERIAL_PREAMBLE_BYTE - 1)
230
dec c ; is there another part?
231
jr nz, .unpatchPartyMonsLoop
232
ld de, wSerialEnemyMonsPatchList
233
ld hl, wEnemyMons
234
ld c, 2 ; patch list has 2 parts
235
.unpatchEnemyMonsLoop
236
ld a, [de]
237
inc de
238
and a
239
jr z, .unpatchEnemyMonsLoop
240
cp SERIAL_PREAMBLE_BYTE
241
jr z, .unpatchEnemyMonsLoop
242
cp SERIAL_NO_DATA_BYTE
243
jr z, .unpatchEnemyMonsLoop
244
cp SERIAL_PATCH_LIST_PART_TERMINATOR
245
jr z, .finishedEnemyMonsPatchListPart
246
push hl
247
push bc
248
ld b, 0
249
dec a
250
ld c, a
251
add hl, bc
252
ld a, SERIAL_NO_DATA_BYTE
253
ld [hl], a
254
pop bc
255
pop hl
256
jr .unpatchEnemyMonsLoop
257
.finishedEnemyMonsPatchListPart
258
ld hl, wEnemyMons + (SERIAL_PREAMBLE_BYTE - 1)
259
dec c
260
jr nz, .unpatchEnemyMonsLoop
261
ld a, LOW(wEnemyMonOT)
262
ld [wUnusedNamePointer], a
263
ld a, HIGH(wEnemyMonOT)
264
ld [wUnusedNamePointer + 1], a
265
xor a
266
ld [wTradeCenterPointerTableIndex], a
267
ld a, SFX_STOP_ALL_MUSIC
268
call PlaySound
269
ldh a, [hSerialConnectionStatus]
270
cp USING_INTERNAL_CLOCK
271
ld c, 66
272
call z, DelayFrames ; delay if using internal clock
273
ld a, [wLinkState]
274
cp LINK_STATE_START_BATTLE
275
ld a, LINK_STATE_TRADING
276
ld [wLinkState], a
277
jr nz, .trading
278
ld a, LINK_STATE_BATTLING
279
ld [wLinkState], a
280
ld a, OPP_RIVAL1
281
ld [wCurOpponent], a
282
call ClearScreen
283
call Delay3
284
ld hl, wOptions
285
res BIT_BATTLE_ANIMATION, [hl]
286
predef InitOpponent
287
predef HealParty
288
jp ReturnToCableClubRoom
289
.trading
290
ld c, BANK(Music_GameCorner)
291
ld a, MUSIC_GAME_CORNER
292
call PlayMusic
293
jr CallCurrentTradeCenterFunction
294
295
PleaseWaitString:
296
db "PLEASE WAIT!@"
297
298
CallCurrentTradeCenterFunction:
299
ld hl, TradeCenterPointerTable
300
ld b, 0
301
ld a, [wTradeCenterPointerTableIndex]
302
cp $ff
303
jp z, DisplayTitleScreen
304
add a
305
ld c, a
306
add hl, bc
307
ld a, [hli]
308
ld h, [hl]
309
ld l, a
310
jp hl
311
312
TradeCenter_SelectMon:
313
call ClearScreen
314
call LoadTrainerInfoTextBoxTiles
315
call TradeCenter_DrawPartyLists
316
call TradeCenter_DrawCancelBox
317
xor a
318
ld hl, wSerialSyncAndExchangeNybbleReceiveData
319
ld [hli], a
320
ld [hli], a
321
ld [hli], a
322
ld [hl], a
323
ld [wMenuWatchMovingOutOfBounds], a
324
ld [wCurrentMenuItem], a
325
ld [wLastMenuItem], a
326
ld [wMenuJoypadPollCount], a
327
inc a
328
ld [wSerialExchangeNybbleSendData], a
329
jp .playerMonMenu
330
.enemyMonMenu
331
xor a
332
ld [wMenuWatchMovingOutOfBounds], a
333
inc a
334
ld [wWhichTradeMonSelectionMenu], a
335
ld a, PAD_DOWN | PAD_LEFT | PAD_A
336
ld [wMenuWatchedKeys], a
337
ld a, [wEnemyPartyCount]
338
ld [wMaxMenuItem], a
339
ld a, 9
340
ld [wTopMenuItemY], a
341
ld a, 1
342
ld [wTopMenuItemX], a
343
.enemyMonMenu_HandleInput
344
ld hl, hUILayoutFlags
345
set BIT_DOUBLE_SPACED_MENU, [hl]
346
call HandleMenuInput
347
ld hl, hUILayoutFlags
348
res BIT_DOUBLE_SPACED_MENU, [hl]
349
and a
350
jp z, .getNewInput
351
bit B_PAD_A, a
352
jr z, .enemyMonMenu_ANotPressed
353
; if A button pressed
354
ld a, [wMaxMenuItem]
355
ld c, a
356
ld a, [wCurrentMenuItem]
357
cp c
358
jr c, .displayEnemyMonStats
359
ld a, [wMaxMenuItem]
360
dec a
361
ld [wCurrentMenuItem], a
362
.displayEnemyMonStats
363
ld a, INIT_ENEMYOT_LIST
364
ld [wInitListType], a
365
callfar InitList ; the list isn't used
366
ld hl, wEnemyMons
367
call TradeCenter_DisplayStats
368
jp .getNewInput
369
.enemyMonMenu_ANotPressed
370
bit B_PAD_LEFT, a
371
jr z, .enemyMonMenu_LeftNotPressed
372
; if Left pressed, switch back to the player mon menu
373
xor a ; player mon menu
374
ld [wWhichTradeMonSelectionMenu], a
375
ld a, [wMenuCursorLocation]
376
ld l, a
377
ld a, [wMenuCursorLocation + 1]
378
ld h, a
379
ld a, [wTileBehindCursor]
380
ld [hl], a
381
ld a, [wCurrentMenuItem]
382
ld b, a
383
ld a, [wPartyCount]
384
dec a
385
cp b
386
jr nc, .playerMonMenu
387
ld [wCurrentMenuItem], a
388
jr .playerMonMenu
389
.enemyMonMenu_LeftNotPressed
390
bit B_PAD_DOWN, a
391
jp z, .getNewInput
392
jp .selectedCancelMenuItem ; jump if Down pressed
393
.playerMonMenu
394
xor a ; player mon menu
395
ld [wWhichTradeMonSelectionMenu], a
396
ld [wMenuWatchMovingOutOfBounds], a
397
ld a, PAD_DOWN | PAD_RIGHT | PAD_A
398
ld [wMenuWatchedKeys], a
399
ld a, [wPartyCount]
400
ld [wMaxMenuItem], a
401
ld a, 1
402
ld [wTopMenuItemY], a
403
ld a, 1
404
ld [wTopMenuItemX], a
405
hlcoord 1, 1
406
lb bc, 6, 1
407
call ClearScreenArea
408
.playerMonMenu_HandleInput
409
ld hl, hUILayoutFlags
410
set BIT_DOUBLE_SPACED_MENU, [hl]
411
call HandleMenuInput
412
ld hl, hUILayoutFlags
413
res BIT_DOUBLE_SPACED_MENU, [hl]
414
and a ; was anything pressed?
415
jr nz, .playerMonMenu_SomethingPressed
416
jp .getNewInput
417
.playerMonMenu_SomethingPressed
418
bit B_PAD_A, a
419
jr z, .playerMonMenu_ANotPressed
420
jp .chosePlayerMon ; jump if A button pressed
421
; unreachable code
422
ld a, INIT_PLAYEROT_LIST
423
ld [wInitListType], a
424
callfar InitList ; the list isn't used
425
call TradeCenter_DisplayStats
426
jp .getNewInput
427
.playerMonMenu_ANotPressed
428
bit B_PAD_RIGHT, a
429
jr z, .playerMonMenu_RightNotPressed
430
; if Right pressed, switch to the enemy mon menu
431
ld a, $1 ; enemy mon menu
432
ld [wWhichTradeMonSelectionMenu], a
433
ld a, [wMenuCursorLocation]
434
ld l, a
435
ld a, [wMenuCursorLocation + 1]
436
ld h, a
437
ld a, [wTileBehindCursor]
438
ld [hl], a
439
ld a, [wCurrentMenuItem]
440
ld b, a
441
ld a, [wEnemyPartyCount]
442
dec a
443
cp b
444
jr nc, .notPastLastEnemyMon
445
; when switching to the enemy mon menu, if the menu selection would be past the last enemy mon, select the last enemy mon
446
ld [wCurrentMenuItem], a
447
.notPastLastEnemyMon
448
jp .enemyMonMenu
449
.playerMonMenu_RightNotPressed
450
bit B_PAD_DOWN, a
451
jr z, .getNewInput
452
jp .selectedCancelMenuItem ; jump if Down pressed
453
.getNewInput
454
ld a, [wWhichTradeMonSelectionMenu]
455
and a
456
jp z, .playerMonMenu_HandleInput
457
jp .enemyMonMenu_HandleInput
458
.chosePlayerMon
459
call SaveScreenTilesToBuffer1
460
call PlaceUnfilledArrowMenuCursor
461
ld a, [wMaxMenuItem]
462
ld c, a
463
ld a, [wCurrentMenuItem]
464
cp c
465
jr c, .displayStatsTradeMenu
466
ld a, [wMaxMenuItem]
467
dec a
468
.displayStatsTradeMenu
469
push af
470
hlcoord 0, 14
471
ld b, 2
472
ld c, 18
473
call CableClub_TextBoxBorder
474
hlcoord 2, 16
475
ld de, .statsTrade
476
call PlaceString
477
xor a
478
ld [wCurrentMenuItem], a
479
ld [wLastMenuItem], a
480
ld [wMenuJoypadPollCount], a
481
ld [wMaxMenuItem], a
482
ld a, 16
483
ld [wTopMenuItemY], a
484
.selectStatsMenuItem
485
ld a, " "
486
ldcoord_a 11, 16
487
ld a, PAD_RIGHT | PAD_B | PAD_A
488
ld [wMenuWatchedKeys], a
489
ld a, 1
490
ld [wTopMenuItemX], a
491
call HandleMenuInput
492
bit B_PAD_RIGHT, a
493
jr nz, .selectTradeMenuItem
494
bit B_PAD_B, a
495
jr z, .displayPlayerMonStats
496
.cancelPlayerMonChoice
497
pop af
498
ld [wCurrentMenuItem], a
499
call LoadScreenTilesFromBuffer1
500
jp .playerMonMenu
501
.selectTradeMenuItem
502
ld a, " "
503
ldcoord_a 1, 16
504
ld a, PAD_LEFT | PAD_B | PAD_A
505
ld [wMenuWatchedKeys], a
506
ld a, 11
507
ld [wTopMenuItemX], a
508
call HandleMenuInput
509
bit B_PAD_LEFT, a
510
jr nz, .selectStatsMenuItem
511
bit B_PAD_B, a
512
jr nz, .cancelPlayerMonChoice
513
jr .choseTrade
514
.displayPlayerMonStats
515
pop af
516
ld [wCurrentMenuItem], a
517
ld a, INIT_PLAYEROT_LIST
518
ld [wInitListType], a
519
callfar InitList ; the list isn't used
520
call TradeCenter_DisplayStats
521
call LoadScreenTilesFromBuffer1
522
jp .playerMonMenu
523
.choseTrade
524
call PlaceUnfilledArrowMenuCursor
525
pop af
526
ld [wCurrentMenuItem], a
527
ld [wTradingWhichPlayerMon], a
528
ld [wSerialExchangeNybbleSendData], a
529
call Serial_PrintWaitingTextAndSyncAndExchangeNybble
530
ld a, [wSerialSyncAndExchangeNybbleReceiveData]
531
cp $f
532
jp z, CallCurrentTradeCenterFunction ; go back to the beginning of the trade selection menu if the other person cancelled
533
ld [wTradingWhichEnemyMon], a
534
call TradeCenter_PlaceSelectedEnemyMonMenuCursor
535
ld a, $1 ; TradeCenter_Trade
536
ld [wTradeCenterPointerTableIndex], a
537
jp CallCurrentTradeCenterFunction
538
.statsTrade
539
db "STATS TRADE@"
540
.selectedCancelMenuItem
541
ld a, [wCurrentMenuItem]
542
ld b, a
543
ld a, [wMaxMenuItem]
544
cp b
545
jp nz, .getNewInput
546
ld a, [wMenuCursorLocation]
547
ld l, a
548
ld a, [wMenuCursorLocation + 1]
549
ld h, a
550
ld a, " "
551
ld [hl], a
552
.cancelMenuItem_Loop
553
ld a, "▶" ; filled arrow cursor
554
ldcoord_a 1, 16
555
.cancelMenuItem_JoypadLoop
556
call JoypadLowSensitivity
557
ldh a, [hJoy5]
558
and a ; pressed anything?
559
jr z, .cancelMenuItem_JoypadLoop
560
bit B_PAD_A, a
561
jr nz, .cancelMenuItem_APressed
562
bit B_PAD_UP, a
563
jr z, .cancelMenuItem_JoypadLoop
564
; if Up pressed
565
ld a, " "
566
ldcoord_a 1, 16
567
ld a, [wPartyCount]
568
dec a
569
ld [wCurrentMenuItem], a
570
jp .playerMonMenu
571
.cancelMenuItem_APressed
572
ld a, "▷" ; unfilled arrow cursor
573
ldcoord_a 1, 16
574
ld a, $f
575
ld [wSerialExchangeNybbleSendData], a
576
call Serial_PrintWaitingTextAndSyncAndExchangeNybble
577
ld a, [wSerialSyncAndExchangeNybbleReceiveData]
578
cp $f ; did the other person choose Cancel too?
579
jr nz, .cancelMenuItem_Loop
580
; fall through
581
582
ReturnToCableClubRoom:
583
call GBPalWhiteOutWithDelay3
584
ld hl, wFontLoaded
585
ld a, [hl]
586
push af
587
push hl
588
res BIT_FONT_LOADED, [hl]
589
xor a
590
ld [wStatusFlags3], a ; clears BIT_INIT_TRADE_CENTER_FACING
591
dec a
592
ld [wDestinationWarpID], a
593
call LoadMapData
594
farcall ClearVariablesOnEnterMap
595
pop hl
596
pop af
597
ld [hl], a
598
call GBFadeInFromWhite
599
ret
600
601
TradeCenter_DrawCancelBox:
602
hlcoord 11, 15
603
ld a, $7e
604
ld bc, 2 * SCREEN_WIDTH + 9
605
call FillMemory
606
hlcoord 0, 15
607
ld b, 1
608
ld c, 9
609
call CableClub_TextBoxBorder
610
hlcoord 2, 16
611
ld de, CancelTextString
612
jp PlaceString
613
614
CancelTextString:
615
db "CANCEL@"
616
617
TradeCenter_PlaceSelectedEnemyMonMenuCursor:
618
ld a, [wSerialSyncAndExchangeNybbleReceiveData]
619
hlcoord 1, 9
620
ld bc, SCREEN_WIDTH
621
call AddNTimes
622
ld [hl], "▷" ; cursor
623
ret
624
625
TradeCenter_DisplayStats:
626
ld a, [wCurrentMenuItem]
627
ld [wWhichPokemon], a
628
predef StatusScreen
629
predef StatusScreen2
630
call GBPalNormal
631
call LoadTrainerInfoTextBoxTiles
632
call TradeCenter_DrawPartyLists
633
jp TradeCenter_DrawCancelBox
634
635
TradeCenter_DrawPartyLists:
636
hlcoord 0, 0
637
ld b, 6
638
ld c, 18
639
call CableClub_TextBoxBorder
640
hlcoord 0, 8
641
ld b, 6
642
ld c, 18
643
call CableClub_TextBoxBorder
644
hlcoord 5, 0
645
ld de, wPlayerName
646
call PlaceString
647
hlcoord 5, 8
648
ld de, wLinkEnemyTrainerName
649
call PlaceString
650
hlcoord 2, 1
651
ld de, wPartySpecies
652
call TradeCenter_PrintPartyListNames
653
hlcoord 2, 9
654
ld de, wEnemyPartySpecies
655
; fall through
656
657
TradeCenter_PrintPartyListNames:
658
ld c, $0
659
.loop
660
ld a, [de]
661
cp $ff
662
ret z
663
ld [wNamedObjectIndex], a
664
push bc
665
push hl
666
push de
667
push hl
668
ld a, c
669
ldh [hPastLeadingZeros], a
670
call GetMonName
671
pop hl
672
call PlaceString
673
pop de
674
inc de
675
pop hl
676
ld bc, 20
677
add hl, bc
678
pop bc
679
inc c
680
jr .loop
681
682
TradeCenter_Trade:
683
ld c, 100
684
call DelayFrames
685
xor a
686
ld [wSerialExchangeNybbleSendData + 1], a ; unnecessary
687
ld [wSerialExchangeNybbleReceiveData], a
688
ld [wMenuWatchMovingOutOfBounds], a
689
ld [wMenuJoypadPollCount], a
690
hlcoord 0, 12
691
ld b, 4
692
ld c, 18
693
call CableClub_TextBoxBorder
694
ld a, [wTradingWhichPlayerMon]
695
ld hl, wPartySpecies
696
ld c, a
697
ld b, 0
698
add hl, bc
699
ld a, [hl]
700
ld [wNamedObjectIndex], a
701
call GetMonName
702
ld hl, wNameBuffer
703
ld de, wNameOfPlayerMonToBeTraded
704
ld bc, NAME_LENGTH
705
call CopyData
706
ld a, [wTradingWhichEnemyMon]
707
ld hl, wEnemyPartySpecies
708
ld c, a
709
ld b, 0
710
add hl, bc
711
ld a, [hl]
712
ld [wNamedObjectIndex], a
713
call GetMonName
714
ld hl, WillBeTradedText
715
bccoord 1, 14
716
call TextCommandProcessor
717
call SaveScreenTilesToBuffer1
718
hlcoord 10, 7
719
lb bc, 8, 11
720
ld a, TRADE_CANCEL_MENU
721
ld [wTwoOptionMenuID], a
722
ld a, TWO_OPTION_MENU
723
ld [wTextBoxID], a
724
call DisplayTextBoxID
725
call LoadScreenTilesFromBuffer1
726
ld a, [wCurrentMenuItem]
727
and a
728
jr z, .tradeConfirmed
729
; if trade cancelled
730
ld a, $1
731
ld [wSerialExchangeNybbleSendData], a
732
hlcoord 0, 12
733
ld b, 4
734
ld c, 18
735
call CableClub_TextBoxBorder
736
hlcoord 1, 14
737
ld de, TradeCanceled
738
call PlaceString
739
call Serial_PrintWaitingTextAndSyncAndExchangeNybble
740
jp .tradeCancelled
741
.tradeConfirmed
742
ld a, $2
743
ld [wSerialExchangeNybbleSendData], a
744
call Serial_PrintWaitingTextAndSyncAndExchangeNybble
745
ld a, [wSerialSyncAndExchangeNybbleReceiveData]
746
dec a ; did the other person cancel?
747
jr nz, .doTrade
748
; if the other person cancelled
749
hlcoord 0, 12
750
ld b, 4
751
ld c, 18
752
call CableClub_TextBoxBorder
753
hlcoord 1, 14
754
ld de, TradeCanceled
755
call PlaceString
756
jp .tradeCancelled
757
.doTrade
758
ld a, [wTradingWhichPlayerMon]
759
ld hl, wPartyMonOT
760
call SkipFixedLengthTextEntries
761
ld de, wTradedPlayerMonOT
762
ld bc, NAME_LENGTH
763
call CopyData
764
ld hl, wPartyMon1Species
765
ld a, [wTradingWhichPlayerMon]
766
ld bc, wPartyMon2 - wPartyMon1
767
call AddNTimes
768
ld bc, wPartyMon1OTID - wPartyMon1
769
add hl, bc
770
ld a, [hli]
771
ld [wTradedPlayerMonOTID], a
772
ld a, [hl]
773
ld [wTradedPlayerMonOTID + 1], a
774
ld a, [wTradingWhichEnemyMon]
775
ld hl, wEnemyMonOT
776
call SkipFixedLengthTextEntries
777
ld de, wTradedEnemyMonOT
778
ld bc, NAME_LENGTH
779
call CopyData
780
ld hl, wEnemyMons
781
ld a, [wTradingWhichEnemyMon]
782
ld bc, wEnemyMon2 - wEnemyMon1
783
call AddNTimes
784
ld bc, wEnemyMon1OTID - wEnemyMon1
785
add hl, bc
786
ld a, [hli]
787
ld [wTradedEnemyMonOTID], a
788
ld a, [hl]
789
ld [wTradedEnemyMonOTID + 1], a
790
ld a, [wTradingWhichPlayerMon]
791
ld [wWhichPokemon], a
792
ld hl, wPartySpecies
793
ld b, 0
794
ld c, a
795
add hl, bc
796
ld a, [hl]
797
ld [wTradedPlayerMonSpecies], a
798
xor a
799
ld [wRemoveMonFromBox], a
800
call RemovePokemon
801
ld a, [wTradingWhichEnemyMon]
802
ld c, a
803
ld [wWhichPokemon], a
804
ld hl, wEnemyPartySpecies
805
ld d, 0
806
ld e, a
807
add hl, de
808
ld a, [hl]
809
ld [wCurPartySpecies], a
810
ld hl, wEnemyMons
811
ld a, c
812
ld bc, wEnemyMon2 - wEnemyMon1
813
call AddNTimes
814
ld de, wLoadedMon
815
ld bc, wEnemyMon2 - wEnemyMon1
816
call CopyData
817
call AddEnemyMonToPlayerParty
818
ld a, [wPartyCount]
819
dec a
820
ld [wWhichPokemon], a
821
ld a, TRUE
822
ld [wForceEvolution], a
823
ld a, [wTradingWhichEnemyMon]
824
ld hl, wEnemyPartySpecies
825
ld b, 0
826
ld c, a
827
add hl, bc
828
ld a, [hl]
829
ld [wTradedEnemyMonSpecies], a
830
ld a, 10
831
ld [wAudioFadeOutControl], a
832
ld a, BANK(Music_SafariZone)
833
ld [wAudioSavedROMBank], a
834
ld a, MUSIC_SAFARI_ZONE
835
ld [wNewSoundID], a
836
call PlaySound
837
ld c, 100
838
call DelayFrames
839
call ClearScreen
840
call LoadHpBarAndStatusTilePatterns
841
xor a
842
ld [wUnusedFlag], a
843
ldh a, [hSerialConnectionStatus]
844
cp USING_EXTERNAL_CLOCK
845
jr z, .usingExternalClock
846
predef InternalClockTradeAnim
847
jr .tradeCompleted
848
.usingExternalClock
849
predef ExternalClockTradeAnim
850
.tradeCompleted
851
callfar TryEvolvingMon
852
call ClearScreen
853
call LoadTrainerInfoTextBoxTiles
854
call Serial_PrintWaitingTextAndSyncAndExchangeNybble
855
ld c, 40
856
call DelayFrames
857
hlcoord 0, 12
858
ld b, 4
859
ld c, 18
860
call CableClub_TextBoxBorder
861
hlcoord 1, 14
862
ld de, TradeCompleted
863
call PlaceString
864
predef SavePartyAndDexData ; this allows reset into Pokecenter
865
vc_hook Trade_save_game_end
866
ld c, 50
867
call DelayFrames
868
xor a
869
ld [wTradeCenterPointerTableIndex], a
870
jp CableClub_DoBattleOrTradeAgain
871
.tradeCancelled
872
ld c, 100
873
call DelayFrames
874
xor a ; TradeCenter_SelectMon
875
ld [wTradeCenterPointerTableIndex], a
876
jp CallCurrentTradeCenterFunction
877
878
WillBeTradedText:
879
text_far _WillBeTradedText
880
text_end
881
882
TradeCompleted:
883
db "Trade completed!@"
884
885
TradeCanceled:
886
db "Too bad! The trade"
887
next "was canceled!@"
888
889
TradeCenterPointerTable:
890
dw TradeCenter_SelectMon
891
dw TradeCenter_Trade
892
893
CableClub_Run:
894
ld a, [wLinkState]
895
cp LINK_STATE_START_TRADE
896
jr z, .doBattleOrTrade
897
cp LINK_STATE_START_BATTLE
898
jr z, .doBattleOrTrade
899
cp LINK_STATE_RESET ; this is never used
900
ret nz
901
predef EmptyFunc
902
jp Init
903
.doBattleOrTrade
904
call CableClub_DoBattleOrTrade
905
ld hl, Club_GFX
906
ld a, h
907
ld [wTilesetGfxPtr + 1], a
908
ld a, l
909
ld [wTilesetGfxPtr], a
910
ld a, BANK(Club_GFX)
911
ld [wTilesetBank], a
912
ld hl, Club_Coll
913
ld a, h
914
ld [wTilesetCollisionPtr + 1], a
915
ld a, l
916
ld [wTilesetCollisionPtr], a
917
xor a
918
ld [wGrassRate], a
919
inc a ; LINK_STATE_IN_CABLE_CLUB
920
ld [wLinkState], a
921
ldh [hJoy5], a
922
ld a, 10
923
ld [wAudioFadeOutControl], a
924
ld a, BANK(Music_Celadon)
925
ld [wAudioSavedROMBank], a
926
ld a, MUSIC_CELADON
927
ld [wNewSoundID], a
928
jp PlaySound
929
930
EmptyFunc:
931
ret
932
933
Diploma_TextBoxBorder:
934
call GetPredefRegisters
935
936
; b = height
937
; c = width
938
CableClub_TextBoxBorder:
939
push hl
940
ld a, $78 ; border upper left corner tile
941
ld [hli], a
942
inc a ; border top horizontal line tile
943
call CableClub_DrawHorizontalLine
944
inc a ; border upper right corner tile
945
ld [hl], a
946
pop hl
947
ld de, 20
948
add hl, de
949
.loop
950
push hl
951
ld a, $7b ; border left vertical line tile
952
ld [hli], a
953
ld a, " "
954
call CableClub_DrawHorizontalLine
955
ld [hl], $77 ; border right vertical line tile
956
pop hl
957
ld de, 20
958
add hl, de
959
dec b
960
jr nz, .loop
961
ld a, $7c ; border lower left corner tile
962
ld [hli], a
963
ld a, $76 ; border bottom horizontal line tile
964
call CableClub_DrawHorizontalLine
965
ld [hl], $7d ; border lower right corner tile
966
ret
967
968
; c = width
969
CableClub_DrawHorizontalLine:
970
ld d, c
971
.loop
972
ld [hli], a
973
dec d
974
jr nz, .loop
975
ret
976
977
LoadTrainerInfoTextBoxTiles:
978
ld de, TrainerInfoTextBoxTileGraphics
979
ld hl, vChars2 tile $76
980
lb bc, BANK(TrainerInfoTextBoxTileGraphics), (TrainerInfoTextBoxTileGraphicsEnd - TrainerInfoTextBoxTileGraphics) / $10
981
jp CopyVideoData
982
983