cable_club.asm 21 KB

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