trade.asm 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. InternalClockTradeAnim:
  2. ; Do the trading animation with the player's gameboy on the left.
  3. ; In-game trades and internally clocked link cable trades use this.
  4. ld a, [wTradedPlayerMonSpecies]
  5. ld [wLeftGBMonSpecies], a
  6. ld a, [wTradedEnemyMonSpecies]
  7. ld [wRightGBMonSpecies], a
  8. ld de, InternalClockTradeFuncSequence
  9. jr TradeAnimCommon
  10. ExternalClockTradeAnim:
  11. ; Do the trading animation with the player's gameboy on the right.
  12. ; Externally clocked link cable trades use this.
  13. ld a, [wTradedEnemyMonSpecies]
  14. ld [wLeftGBMonSpecies], a
  15. ld a, [wTradedPlayerMonSpecies]
  16. ld [wRightGBMonSpecies], a
  17. ld de, ExternalClockTradeFuncSequence
  18. TradeAnimCommon:
  19. ld a, [wOptions]
  20. push af
  21. ld a, [hSCY]
  22. push af
  23. ld a, [hSCX]
  24. push af
  25. xor a
  26. ld [wOptions], a
  27. ld [hSCY], a
  28. ld [hSCX], a
  29. push de
  30. .loop
  31. pop de
  32. ld a, [de]
  33. cp $ff
  34. jr z, .done
  35. inc de
  36. push de
  37. ld hl, TradeFuncPointerTable
  38. add a
  39. ld c, a
  40. ld b, $0
  41. add hl, bc
  42. ld a, [hli]
  43. ld h, [hl]
  44. ld l, a
  45. ld de, .loop
  46. push de
  47. jp hl ; call trade func, which will return to the top of the loop
  48. .done
  49. pop af
  50. ld [hSCX], a
  51. pop af
  52. ld [hSCY], a
  53. pop af
  54. ld [wOptions], a
  55. ret
  56. addtradefunc: MACRO
  57. \1TradeFunc::
  58. dw \1
  59. ENDM
  60. tradefunc: MACRO
  61. db (\1TradeFunc - TradeFuncPointerTable) / 2
  62. ENDM
  63. ; The functions in the sequences below are executed in order by TradeFuncCommon.
  64. ; They are from opposite perspectives. The external clock one makes use of
  65. ; Trade_SwapNames to swap the player and enemy names for some functions.
  66. InternalClockTradeFuncSequence:
  67. tradefunc LoadTradingGFXAndMonNames
  68. tradefunc Trade_ShowPlayerMon
  69. tradefunc Trade_DrawOpenEndOfLinkCable
  70. tradefunc Trade_AnimateBallEnteringLinkCable
  71. tradefunc Trade_AnimLeftToRight
  72. tradefunc Trade_Delay100
  73. tradefunc Trade_ShowClearedWindow
  74. tradefunc PrintTradeWentToText
  75. tradefunc PrintTradeForSendsText
  76. tradefunc PrintTradeFarewellText
  77. tradefunc Trade_AnimRightToLeft
  78. tradefunc Trade_ShowClearedWindow
  79. tradefunc Trade_DrawOpenEndOfLinkCable
  80. tradefunc Trade_ShowEnemyMon
  81. tradefunc Trade_Delay100
  82. tradefunc Trade_Cleanup
  83. db $FF
  84. ExternalClockTradeFuncSequence:
  85. tradefunc LoadTradingGFXAndMonNames
  86. tradefunc Trade_ShowClearedWindow
  87. tradefunc PrintTradeWillTradeText
  88. tradefunc PrintTradeFarewellText
  89. tradefunc Trade_SwapNames
  90. tradefunc Trade_AnimLeftToRight
  91. tradefunc Trade_SwapNames
  92. tradefunc Trade_ShowClearedWindow
  93. tradefunc Trade_DrawOpenEndOfLinkCable
  94. tradefunc Trade_ShowEnemyMon
  95. tradefunc Trade_SlideTextBoxOffScreen
  96. tradefunc Trade_ShowPlayerMon
  97. tradefunc Trade_DrawOpenEndOfLinkCable
  98. tradefunc Trade_AnimateBallEnteringLinkCable
  99. tradefunc Trade_SwapNames
  100. tradefunc Trade_AnimRightToLeft
  101. tradefunc Trade_SwapNames
  102. tradefunc Trade_Delay100
  103. tradefunc Trade_ShowClearedWindow
  104. tradefunc PrintTradeWentToText
  105. tradefunc Trade_Cleanup
  106. db $FF
  107. TradeFuncPointerTable:
  108. addtradefunc LoadTradingGFXAndMonNames
  109. addtradefunc Trade_ShowPlayerMon
  110. addtradefunc Trade_DrawOpenEndOfLinkCable
  111. addtradefunc Trade_AnimateBallEnteringLinkCable
  112. addtradefunc Trade_ShowEnemyMon
  113. addtradefunc Trade_AnimLeftToRight
  114. addtradefunc Trade_AnimRightToLeft
  115. addtradefunc Trade_Delay100
  116. addtradefunc Trade_ShowClearedWindow
  117. addtradefunc PrintTradeWentToText
  118. addtradefunc PrintTradeForSendsText
  119. addtradefunc PrintTradeFarewellText
  120. addtradefunc PrintTradeTakeCareText
  121. addtradefunc PrintTradeWillTradeText
  122. addtradefunc Trade_Cleanup
  123. addtradefunc Trade_SlideTextBoxOffScreen
  124. addtradefunc Trade_SwapNames
  125. Trade_Delay100:
  126. ld c, 100
  127. jp DelayFrames
  128. Trade_CopyTileMapToVRAM:
  129. ld a, $1
  130. ld [H_AUTOBGTRANSFERENABLED], a
  131. call Delay3
  132. xor a
  133. ld [H_AUTOBGTRANSFERENABLED], a
  134. ret
  135. Trade_Delay80:
  136. ld c, 80
  137. jp DelayFrames
  138. Trade_ClearTileMap:
  139. coord hl, 0, 0
  140. ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
  141. ld a, " "
  142. jp FillMemory
  143. LoadTradingGFXAndMonNames:
  144. call Trade_ClearTileMap
  145. call DisableLCD
  146. ld hl, TradingAnimationGraphics
  147. ld de, vChars2 + $310
  148. ld bc, TradingAnimationGraphicsEnd - TradingAnimationGraphics
  149. ld a, BANK(TradingAnimationGraphics)
  150. call FarCopyData2
  151. ld hl, TradingAnimationGraphics2
  152. ld de, vSprites + $7c0
  153. ld bc, TradingAnimationGraphics2End - TradingAnimationGraphics2
  154. ld a, BANK(TradingAnimationGraphics2)
  155. call FarCopyData2
  156. ld hl, vBGMap0
  157. ld bc, $800
  158. ld a, " "
  159. call FillMemory
  160. call ClearSprites
  161. ld a, $ff
  162. ld [wUpdateSpritesEnabled], a
  163. ld hl, wd730
  164. set 6, [hl] ; turn on instant text printing
  165. ld a, [wOnSGB]
  166. and a
  167. ld a, $e4 ; non-SGB OBP0
  168. jr z, .next
  169. ld a, $f0 ; SGB OBP0
  170. .next
  171. ld [rOBP0], a
  172. call EnableLCD
  173. xor a
  174. ld [H_AUTOBGTRANSFERENABLED], a
  175. ld a, [wTradedPlayerMonSpecies]
  176. ld [wd11e], a
  177. call GetMonName
  178. ld hl, wcd6d
  179. ld de, wcf4b
  180. ld bc, NAME_LENGTH
  181. call CopyData
  182. ld a, [wTradedEnemyMonSpecies]
  183. ld [wd11e], a
  184. jp GetMonName
  185. Trade_LoadMonPartySpriteGfx:
  186. ld a, %11010000
  187. ld [rOBP1], a
  188. jpba LoadMonPartySpriteGfx
  189. Trade_SwapNames:
  190. ld hl, wPlayerName
  191. ld de, wBuffer
  192. ld bc, NAME_LENGTH
  193. call CopyData
  194. ld hl, wLinkEnemyTrainerName
  195. ld de, wPlayerName
  196. ld bc, NAME_LENGTH
  197. call CopyData
  198. ld hl, wBuffer
  199. ld de, wLinkEnemyTrainerName
  200. ld bc, NAME_LENGTH
  201. jp CopyData
  202. Trade_Cleanup:
  203. xor a
  204. call LoadGBPal
  205. ld hl, wd730
  206. res 6, [hl] ; turn off instant text printing
  207. ret
  208. Trade_ShowPlayerMon:
  209. ld a, %10101011
  210. ld [rLCDC], a
  211. ld a, $50
  212. ld [hWY], a
  213. ld a, $86
  214. ld [rWX], a
  215. ld [hSCX], a
  216. xor a
  217. ld [H_AUTOBGTRANSFERENABLED], a
  218. coord hl, 4, 0
  219. ld b, 6
  220. ld c, 10
  221. call TextBoxBorder
  222. call Trade_PrintPlayerMonInfoText
  223. ld b, vBGMap0 / $100
  224. call CopyScreenTileBufferToVRAM
  225. call ClearScreen
  226. ld a, [wTradedPlayerMonSpecies]
  227. call Trade_LoadMonSprite
  228. ld a, $7e
  229. .slideScreenLoop
  230. push af
  231. call DelayFrame
  232. pop af
  233. ld [rWX], a
  234. ld [hSCX], a
  235. dec a
  236. dec a
  237. and a
  238. jr nz, .slideScreenLoop
  239. call Trade_Delay80
  240. ld a, TRADE_BALL_POOF_ANIM
  241. call Trade_ShowAnimation
  242. ld a, TRADE_BALL_DROP_ANIM
  243. call Trade_ShowAnimation ; clears mon pic
  244. ld a, [wTradedPlayerMonSpecies]
  245. call PlayCry
  246. xor a
  247. ld [H_AUTOBGTRANSFERENABLED], a
  248. ret
  249. Trade_DrawOpenEndOfLinkCable:
  250. call Trade_ClearTileMap
  251. ld b, vBGMap0 / $100
  252. call CopyScreenTileBufferToVRAM
  253. ld b, SET_PAL_GENERIC
  254. call RunPaletteCommand
  255. ; This function call is pointless. It just copies blank tiles to VRAM that was
  256. ; already filled with blank tiles.
  257. ld hl, vBGMap1 + $8c
  258. call Trade_CopyCableTilesOffScreen
  259. ld a, $a0
  260. ld [hSCX], a
  261. call DelayFrame
  262. ld a, %10001011
  263. ld [rLCDC], a
  264. coord hl, 6, 2
  265. ld b, $7 ; open end of link cable tile ID list index
  266. call CopyTileIDsFromList_ZeroBaseTileID
  267. call Trade_CopyTileMapToVRAM
  268. ld a, SFX_HEAL_HP
  269. call PlaySound
  270. ld c, 20
  271. .loop
  272. ld a, [hSCX]
  273. add 4
  274. ld [hSCX], a
  275. dec c
  276. jr nz, .loop
  277. ret
  278. Trade_AnimateBallEnteringLinkCable:
  279. ld a, TRADE_BALL_SHAKE_ANIM
  280. call Trade_ShowAnimation
  281. ld c, 10
  282. call DelayFrames
  283. ld a, %11100100
  284. ld [rOBP0], a
  285. xor a
  286. ld [wLinkCableAnimBulgeToggle], a
  287. lb bc, $20, $60
  288. .moveBallInsideLinkCableLoop
  289. push bc
  290. xor a
  291. ld de, Trade_BallInsideLinkCableOAM
  292. call WriteOAMBlock
  293. ld a, [wLinkCableAnimBulgeToggle]
  294. xor $1
  295. ld [wLinkCableAnimBulgeToggle], a
  296. add $7e
  297. ld hl, wOAMBuffer + $02
  298. ld de, 4
  299. ld c, e
  300. .cycleLinkCableBulgeTile
  301. ld [hl], a
  302. add hl, de
  303. dec c
  304. jr nz, .cycleLinkCableBulgeTile
  305. call Delay3
  306. pop bc
  307. ld a, c
  308. add $4
  309. ld c, a
  310. cp $a0
  311. jr nc, .ballSpriteReachedEdgeOfScreen
  312. ld a, SFX_TINK
  313. call PlaySound
  314. jr .moveBallInsideLinkCableLoop
  315. .ballSpriteReachedEdgeOfScreen
  316. call ClearSprites
  317. ld a, $1
  318. ld [H_AUTOBGTRANSFERENABLED], a
  319. call ClearScreen
  320. ld b, $98
  321. call CopyScreenTileBufferToVRAM
  322. call Delay3
  323. xor a
  324. ld [H_AUTOBGTRANSFERENABLED], a
  325. ret
  326. Trade_BallInsideLinkCableOAM:
  327. db $7E,$00,$7E,$20
  328. db $7E,$40,$7E,$60
  329. Trade_ShowEnemyMon:
  330. ld a, TRADE_BALL_TILT_ANIM
  331. call Trade_ShowAnimation
  332. call Trade_ShowClearedWindow
  333. coord hl, 4, 10
  334. ld b, 6
  335. ld c, 10
  336. call TextBoxBorder
  337. call Trade_PrintEnemyMonInfoText
  338. call Trade_CopyTileMapToVRAM
  339. ld a, $1
  340. ld [H_AUTOBGTRANSFERENABLED], a
  341. ld a, [wTradedEnemyMonSpecies]
  342. call Trade_LoadMonSprite
  343. ld a, TRADE_BALL_POOF_ANIM
  344. call Trade_ShowAnimation
  345. ld a, $1
  346. ld [H_AUTOBGTRANSFERENABLED], a
  347. ld a, [wTradedEnemyMonSpecies]
  348. call PlayCry
  349. call Trade_Delay100
  350. coord hl, 4, 10
  351. lb bc, 8, 12
  352. call ClearScreenArea
  353. jp PrintTradeTakeCareText
  354. Trade_AnimLeftToRight:
  355. ; Animates the mon moving from the left GB to the right one.
  356. call Trade_InitGameboyTransferGfx
  357. ld a, $1
  358. ld [wTradedMonMovingRight], a
  359. ld a, %11100100
  360. ld [rOBP0], a
  361. ld a, $54
  362. ld [wBaseCoordX], a
  363. ld a, $1c
  364. ld [wBaseCoordY], a
  365. ld a, [wLeftGBMonSpecies]
  366. ld [wMonPartySpriteSpecies], a
  367. call Trade_WriteCircledMonOAM
  368. call Trade_DrawLeftGameboy
  369. call Trade_CopyTileMapToVRAM
  370. call Trade_DrawCableAcrossScreen
  371. ld hl, vBGMap1 + $8c
  372. call Trade_CopyCableTilesOffScreen
  373. ld b, $6
  374. call Trade_AnimMonMoveHorizontal
  375. ld a, $1
  376. ld [H_AUTOBGTRANSFERENABLED], a
  377. call Trade_DrawCableAcrossScreen
  378. ld b, $4
  379. call Trade_AnimMonMoveHorizontal
  380. call Trade_DrawRightGameboy
  381. ld b, $6
  382. call Trade_AnimMonMoveHorizontal
  383. xor a
  384. ld [H_AUTOBGTRANSFERENABLED], a
  385. call Trade_AnimMonMoveVertical
  386. jp ClearSprites
  387. Trade_AnimRightToLeft:
  388. ; Animates the mon moving from the right GB to the left one.
  389. call Trade_InitGameboyTransferGfx
  390. xor a
  391. ld [wTradedMonMovingRight], a
  392. ld a, $64
  393. ld [wBaseCoordX], a
  394. ld a, $44
  395. ld [wBaseCoordY], a
  396. ld a, [wRightGBMonSpecies]
  397. ld [wMonPartySpriteSpecies], a
  398. call Trade_WriteCircledMonOAM
  399. call Trade_DrawRightGameboy
  400. call Trade_CopyTileMapToVRAM
  401. call Trade_DrawCableAcrossScreen
  402. ld hl, vBGMap1 + $94
  403. call Trade_CopyCableTilesOffScreen
  404. call Trade_AnimMonMoveVertical
  405. ld b, $6
  406. call Trade_AnimMonMoveHorizontal
  407. ld a, $1
  408. ld [H_AUTOBGTRANSFERENABLED], a
  409. call Trade_DrawCableAcrossScreen
  410. ld b, $4
  411. call Trade_AnimMonMoveHorizontal
  412. call Trade_DrawLeftGameboy
  413. ld b, $6
  414. call Trade_AnimMonMoveHorizontal
  415. xor a
  416. ld [H_AUTOBGTRANSFERENABLED], a
  417. jp ClearSprites
  418. Trade_InitGameboyTransferGfx:
  419. ; Initialises the graphics for showing a mon moving between gameboys.
  420. ld a, $1
  421. ld [H_AUTOBGTRANSFERENABLED], a
  422. call ClearScreen
  423. xor a
  424. ld [H_AUTOBGTRANSFERENABLED], a
  425. call Trade_LoadMonPartySpriteGfx
  426. call DelayFrame
  427. ld a, %10101011
  428. ld [rLCDC], a
  429. xor a
  430. ld [hSCX], a
  431. ld a, $90
  432. ld [hWY], a
  433. ret
  434. Trade_DrawLeftGameboy:
  435. call Trade_ClearTileMap
  436. ; draw link cable
  437. coord hl, 11, 4
  438. ld a, $5d
  439. ld [hli], a
  440. ld a, $5e
  441. ld c, 8
  442. .loop
  443. ld [hli], a
  444. dec c
  445. jr nz, .loop
  446. ; draw gameboy pic
  447. coord hl, 5, 3
  448. ld b, $6
  449. call CopyTileIDsFromList_ZeroBaseTileID
  450. ; draw text box with player name below gameboy pic
  451. coord hl, 4, 12
  452. ld b, 2
  453. ld c, 7
  454. call TextBoxBorder
  455. coord hl, 5, 14
  456. ld de, wPlayerName
  457. call PlaceString
  458. jp DelayFrame
  459. Trade_DrawRightGameboy:
  460. call Trade_ClearTileMap
  461. ; draw horizontal segment of link cable
  462. coord hl, 0, 4
  463. ld a, $5e
  464. ld c, $e
  465. .loop
  466. ld [hli], a
  467. dec c
  468. jr nz, .loop
  469. ; draw vertical segment of link cable
  470. ld a, $5f
  471. ld [hl], a
  472. ld de, SCREEN_WIDTH
  473. add hl, de
  474. ld a, $61
  475. ld [hl], a
  476. add hl, de
  477. ld [hl], a
  478. add hl, de
  479. ld [hl], a
  480. add hl, de
  481. ld [hl], a
  482. add hl, de
  483. ld a, $60
  484. ld [hld], a
  485. ld a, $5d
  486. ld [hl], a
  487. ; draw gameboy pic
  488. coord hl, 7, 8
  489. ld b, $6
  490. call CopyTileIDsFromList_ZeroBaseTileID
  491. ; draw text box with enemy name above link cable
  492. coord hl, 6, 0
  493. ld b, 2
  494. ld c, 7
  495. call TextBoxBorder
  496. coord hl, 7, 2
  497. ld de, wLinkEnemyTrainerName
  498. call PlaceString
  499. jp DelayFrame
  500. Trade_DrawCableAcrossScreen:
  501. ; Draws the link cable across the screen.
  502. call Trade_ClearTileMap
  503. coord hl, 0, 4
  504. ld a, $5e
  505. ld c, SCREEN_WIDTH
  506. .loop
  507. ld [hli], a
  508. dec c
  509. jr nz, .loop
  510. ret
  511. Trade_CopyCableTilesOffScreen:
  512. ; This is used to copy the link cable tiles off screen so that the cable
  513. ; continues when the screen is scrolled.
  514. push hl
  515. coord hl, 0, 4
  516. call CopyToRedrawRowOrColumnSrcTiles
  517. pop hl
  518. ld a, h
  519. ld [hRedrawRowOrColumnDest + 1], a
  520. ld a, l
  521. ld [hRedrawRowOrColumnDest], a
  522. ld a, REDRAW_ROW
  523. ld [hRedrawRowOrColumnMode], a
  524. ld c, 10
  525. jp DelayFrames
  526. Trade_AnimMonMoveHorizontal:
  527. ; Animates the mon going through the link cable horizontally over a distance of
  528. ; b 16-pixel units.
  529. ld a, [wTradedMonMovingRight]
  530. ld e, a
  531. ld d, $8
  532. .scrollLoop
  533. ld a, e
  534. dec a
  535. jr z, .movingRight
  536. ; moving left
  537. ld a, [hSCX]
  538. sub $2
  539. jr .next
  540. .movingRight
  541. ld a, [hSCX]
  542. add $2
  543. .next
  544. ld [hSCX], a
  545. call DelayFrame
  546. dec d
  547. jr nz, .scrollLoop
  548. call Trade_AnimCircledMon
  549. dec b
  550. jr nz, Trade_AnimMonMoveHorizontal
  551. ret
  552. Trade_AnimCircledMon:
  553. ; Cycles between the two animation frames of the mon party sprite, cycles
  554. ; between a circle and an oval around the mon sprite, and makes the cable flash.
  555. push de
  556. push bc
  557. push hl
  558. ld a, [rBGP]
  559. xor $3c ; make link cable flash
  560. ld [rBGP], a
  561. ld hl, wOAMBuffer + $02
  562. ld de, $4
  563. ld c, $14
  564. .loop
  565. ld a, [hl]
  566. xor $40
  567. ld [hl], a
  568. add hl, de
  569. dec c
  570. jr nz, .loop
  571. pop hl
  572. pop bc
  573. pop de
  574. ret
  575. Trade_WriteCircledMonOAM:
  576. callba WriteMonPartySpriteOAMBySpecies
  577. call Trade_WriteCircleOAM
  578. Trade_AddOffsetsToOAMCoords:
  579. ld hl, wOAMBuffer
  580. ld c, $14
  581. .loop
  582. ld a, [wBaseCoordY]
  583. add [hl]
  584. ld [hli], a
  585. ld a, [wBaseCoordX]
  586. add [hl]
  587. ld [hli], a
  588. inc hl
  589. inc hl
  590. dec c
  591. jr nz, .loop
  592. ret
  593. Trade_AnimMonMoveVertical:
  594. ; Animates the mon going through the link cable vertically as well as
  595. ; horizontally for a bit. The last bit of horizontal movement (when moving
  596. ; right) or the first bit of horizontal movement (when moving left) are done
  597. ; here instead of Trade_AnimMonMoveHorizontal because this function moves the
  598. ; sprite itself rather than scrolling the screen around the sprite. Moving the
  599. ; sprite itself is necessary because the vertical segment of the link cable is
  600. ; to the right of the screen position that the mon sprite has when
  601. ; Trade_AnimMonMoveHorizontal is executing.
  602. ld a, [wTradedMonMovingRight]
  603. and a
  604. jr z, .movingLeft
  605. ; moving right
  606. lb bc, 4, 0 ; move right
  607. call .doAnim
  608. lb bc, 0, 10 ; move down
  609. jr .doAnim
  610. .movingLeft
  611. lb bc, 0, -10 ; move up
  612. call .doAnim
  613. lb bc, -4, 0 ; move left
  614. .doAnim
  615. ld a, b
  616. ld [wBaseCoordX], a
  617. ld a, c
  618. ld [wBaseCoordY], a
  619. ld d, $4
  620. .loop
  621. call Trade_AddOffsetsToOAMCoords
  622. call Trade_AnimCircledMon
  623. ld c, 8
  624. call DelayFrames
  625. dec d
  626. jr nz, .loop
  627. ret
  628. Trade_WriteCircleOAM:
  629. ; Writes the OAM blocks for the circle around the traded mon as it passes
  630. ; the link cable.
  631. ld hl, Trade_CircleOAMPointers
  632. ld c, $4
  633. xor a
  634. .loop
  635. push bc
  636. ld e, [hl]
  637. inc hl
  638. ld d, [hl]
  639. inc hl
  640. ld c, [hl]
  641. inc hl
  642. ld b, [hl]
  643. inc hl
  644. push hl
  645. inc a
  646. push af
  647. call WriteOAMBlock
  648. pop af
  649. pop hl
  650. pop bc
  651. dec c
  652. jr nz, .loop
  653. ret
  654. Trade_CircleOAMPointers:
  655. dw Trade_CircleOAM0
  656. db $08,$08
  657. dw Trade_CircleOAM1
  658. db $18,$08
  659. dw Trade_CircleOAM2
  660. db $08,$18
  661. dw Trade_CircleOAM3
  662. db $18,$18
  663. Trade_CircleOAM0:
  664. db $38,$10,$39,$10
  665. db $3A,$10,$3B,$10
  666. Trade_CircleOAM1:
  667. db $39,$30,$38,$30
  668. db $3B,$30,$3A,$30
  669. Trade_CircleOAM2:
  670. db $3A,$50,$3B,$50
  671. db $38,$50,$39,$50
  672. Trade_CircleOAM3:
  673. db $3B,$70,$3A,$70
  674. db $39,$70,$38,$70
  675. ; a = species
  676. Trade_LoadMonSprite:
  677. ld [wcf91], a
  678. ld [wd0b5], a
  679. ld [wWholeScreenPaletteMonSpecies], a
  680. ld b, SET_PAL_POKEMON_WHOLE_SCREEN
  681. ld c, 0
  682. call RunPaletteCommand
  683. ld a, [H_AUTOBGTRANSFERENABLED]
  684. xor $1
  685. ld [H_AUTOBGTRANSFERENABLED], a
  686. call GetMonHeader
  687. coord hl, 7, 2
  688. call LoadFlippedFrontSpriteByMonIndex
  689. ld c, 10
  690. jp DelayFrames
  691. Trade_ShowClearedWindow:
  692. ; clears the window and covers the BG entirely with the window
  693. ld a, $1
  694. ld [H_AUTOBGTRANSFERENABLED], a
  695. call ClearScreen
  696. ld a, %11100011
  697. ld [rLCDC], a
  698. ld a, $7
  699. ld [rWX], a
  700. xor a
  701. ld [hWY], a
  702. ld a, $90
  703. ld [hSCX], a
  704. ret
  705. Trade_SlideTextBoxOffScreen:
  706. ; Slides the window right until it's off screen. The window usually just has
  707. ; a text box at the bottom when this is called. However, when this is called
  708. ; after Trade_ShowEnemyMon in the external clock sequence, there is a mon pic
  709. ; above the text box and it is also scrolled off the screen.
  710. ld c, 50
  711. call DelayFrames
  712. .loop
  713. call DelayFrame
  714. ld a, [rWX]
  715. inc a
  716. inc a
  717. ld [rWX], a
  718. cp $a1
  719. jr nz, .loop
  720. call Trade_ClearTileMap
  721. ld c, 10
  722. call DelayFrames
  723. ld a, $7
  724. ld [rWX], a
  725. ret
  726. PrintTradeWentToText:
  727. ld hl, TradeWentToText
  728. call PrintText
  729. ld c, 200
  730. call DelayFrames
  731. jp Trade_SlideTextBoxOffScreen
  732. TradeWentToText:
  733. TX_FAR _TradeWentToText
  734. db "@"
  735. PrintTradeForSendsText:
  736. ld hl, TradeForText
  737. call PrintText
  738. call Trade_Delay80
  739. ld hl, TradeSendsText
  740. call PrintText
  741. jp Trade_Delay80
  742. TradeForText:
  743. TX_FAR _TradeForText
  744. db "@"
  745. TradeSendsText:
  746. TX_FAR _TradeSendsText
  747. db "@"
  748. PrintTradeFarewellText:
  749. ld hl, TradeWavesFarewellText
  750. call PrintText
  751. call Trade_Delay80
  752. ld hl, TradeTransferredText
  753. call PrintText
  754. call Trade_Delay80
  755. jp Trade_SlideTextBoxOffScreen
  756. TradeWavesFarewellText:
  757. TX_FAR _TradeWavesFarewellText
  758. db "@"
  759. TradeTransferredText:
  760. TX_FAR _TradeTransferredText
  761. db "@"
  762. PrintTradeTakeCareText:
  763. ld hl, TradeTakeCareText
  764. call PrintText
  765. jp Trade_Delay80
  766. TradeTakeCareText:
  767. TX_FAR _TradeTakeCareText
  768. db "@"
  769. PrintTradeWillTradeText:
  770. ld hl, TradeWillTradeText
  771. call PrintText
  772. call Trade_Delay80
  773. ld hl, TradeforText
  774. call PrintText
  775. jp Trade_Delay80
  776. TradeWillTradeText:
  777. TX_FAR _TradeWillTradeText
  778. db "@"
  779. TradeforText:
  780. TX_FAR _TradeforText
  781. db "@"
  782. Trade_ShowAnimation:
  783. ld [wAnimationID], a
  784. xor a
  785. ld [wAnimationType], a
  786. predef_jump MoveAnimation