PageRenderTime 30ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/engine/battle/animations.asm

https://gitlab.com/eientei95/pokered-fr
Assembly | 2453 lines | 2146 code | 161 blank | 146 comment | 0 complexity | bc4c6b8a4abd0b99fd2859a010ddf5b9 MD5 | raw file
  1. ; Draws a "frame block". Frame blocks are blocks of tiles that are put
  2. ; together to form frames in battle animations.
  3. DrawFrameBlock:
  4. ld l,c
  5. ld h,b
  6. ld a,[hli]
  7. ld [wNumFBTiles],a
  8. ld a,[wFBDestAddr + 1]
  9. ld e,a
  10. ld a,[wFBDestAddr]
  11. ld d,a
  12. xor a
  13. ld [wFBTileCounter],a ; loop counter
  14. .loop
  15. ld a,[wFBTileCounter]
  16. inc a
  17. ld [wFBTileCounter],a
  18. ld a,[wSubAnimTransform]
  19. dec a
  20. jr z,.flipHorizontalAndVertical ; 1
  21. dec a
  22. jp z,.flipHorizontalTranslateDown ; 2
  23. dec a
  24. jr z,.flipBaseCoords ; 3
  25. .noTransformation
  26. ld a,[wBaseCoordY]
  27. add [hl]
  28. ld [de],a ; store Y
  29. inc hl
  30. inc de
  31. ld a,[wBaseCoordX]
  32. jr .finishCopying
  33. .flipBaseCoords
  34. ld a,[wBaseCoordY]
  35. ld b,a
  36. ld a,136
  37. sub b ; flip Y base coordinate
  38. add [hl] ; Y offset
  39. ld [de],a ; store Y
  40. inc hl
  41. inc de
  42. ld a,[wBaseCoordX]
  43. ld b,a
  44. ld a,168
  45. sub b ; flip X base coordinate
  46. .finishCopying ; finish copying values to OAM (when [wSubAnimTransform] not 1 or 2)
  47. add [hl] ; X offset
  48. ld [de],a ; store X
  49. inc hl
  50. inc de
  51. ld a,[hli]
  52. add a,$31 ; base tile ID for battle animations
  53. ld [de],a ; store tile ID
  54. inc de
  55. ld a,[hli]
  56. ld [de],a ; store flags
  57. inc de
  58. jp .nextTile
  59. .flipHorizontalAndVertical
  60. ld a,[wBaseCoordY]
  61. add [hl] ; Y offset
  62. ld b,a
  63. ld a,136
  64. sub b ; flip Y coordinate
  65. ld [de],a ; store Y
  66. inc hl
  67. inc de
  68. ld a,[wBaseCoordX]
  69. add [hl] ; X offset
  70. ld b,a
  71. ld a,168
  72. sub b ; flip X coordinate
  73. ld [de],a ; store X
  74. inc hl
  75. inc de
  76. ld a,[hli]
  77. add a,$31 ; base tile ID for battle animations
  78. ld [de],a ; store tile ID
  79. inc de
  80. ; toggle horizontal and vertical flip
  81. ld a,[hli] ; flags
  82. and a
  83. ld b,OAM_VFLIP | OAM_HFLIP
  84. jr z,.storeFlags1
  85. cp a,OAM_HFLIP
  86. ld b,OAM_VFLIP
  87. jr z,.storeFlags1
  88. cp a,OAM_VFLIP
  89. ld b,OAM_HFLIP
  90. jr z,.storeFlags1
  91. ld b,0
  92. .storeFlags1
  93. ld a,b
  94. ld [de],a
  95. inc de
  96. jp .nextTile
  97. .flipHorizontalTranslateDown
  98. ld a,[wBaseCoordY]
  99. add [hl]
  100. add a,40 ; translate Y coordinate downwards
  101. ld [de],a ; store Y
  102. inc hl
  103. inc de
  104. ld a,[wBaseCoordX]
  105. add [hl]
  106. ld b,a
  107. ld a,168
  108. sub b ; flip X coordinate
  109. ld [de],a ; store X
  110. inc hl
  111. inc de
  112. ld a,[hli]
  113. add a,$31 ; base tile ID for battle animations
  114. ld [de],a ; store tile ID
  115. inc de
  116. ld a,[hli]
  117. bit 5,a ; is horizontal flip enabled?
  118. jr nz,.disableHorizontalFlip
  119. .enableHorizontalFlip
  120. set 5,a
  121. jr .storeFlags2
  122. .disableHorizontalFlip
  123. res 5,a
  124. .storeFlags2
  125. ld [de],a
  126. inc de
  127. .nextTile
  128. ld a,[wFBTileCounter]
  129. ld c,a
  130. ld a,[wNumFBTiles]
  131. cp c
  132. jp nz,.loop ; go back up if there are more tiles to draw
  133. .afterDrawingTiles
  134. ld a,[wFBMode]
  135. cp a,2
  136. jr z,.advanceFrameBlockDestAddr; skip delay and don't clean OAM buffer
  137. ld a,[wSubAnimFrameDelay]
  138. ld c,a
  139. call DelayFrames
  140. ld a,[wFBMode]
  141. cp a,3
  142. jr z,.advanceFrameBlockDestAddr ; skip cleaning OAM buffer
  143. cp a,4
  144. jr z,.done ; skip cleaning OAM buffer and don't advance the frame block destination address
  145. ld a,[wAnimationID]
  146. cp a,GROWL
  147. jr z,.resetFrameBlockDestAddr
  148. call AnimationCleanOAM
  149. .resetFrameBlockDestAddr
  150. ld hl,wOAMBuffer ; OAM buffer
  151. ld a,l
  152. ld [wFBDestAddr + 1],a
  153. ld a,h
  154. ld [wFBDestAddr],a ; set destination address to beginning of OAM buffer
  155. ret
  156. .advanceFrameBlockDestAddr
  157. ld a,e
  158. ld [wFBDestAddr + 1],a
  159. ld a,d
  160. ld [wFBDestAddr],a
  161. .done
  162. ret
  163. PlayAnimation:
  164. xor a
  165. ld [$FF8B],a ; it looks like nothing reads this
  166. ld [wSubAnimTransform],a
  167. ld a,[wAnimationID] ; get animation number
  168. dec a
  169. ld l,a
  170. ld h,0
  171. add hl,hl
  172. ld de,AttackAnimationPointers ; animation command stream pointers
  173. add hl,de
  174. ld a,[hli]
  175. ld h,[hl]
  176. ld l,a
  177. .animationLoop
  178. ld a,[hli]
  179. cp a,$FF
  180. jr z,.AnimationOver
  181. cp a,$C0 ; is this subanimation or a special effect?
  182. jr c,.playSubanimation
  183. .doSpecialEffect
  184. ld c,a
  185. ld de,SpecialEffectPointers
  186. .searchSpecialEffectTableLoop
  187. ld a,[de]
  188. cp c
  189. jr z,.foundMatch
  190. inc de
  191. inc de
  192. inc de
  193. jr .searchSpecialEffectTableLoop
  194. .foundMatch
  195. ld a,[hli]
  196. cp a,$FF ; is there a sound to play?
  197. jr z,.skipPlayingSound
  198. ld [wAnimSoundID],a ; store sound
  199. push hl
  200. push de
  201. call GetMoveSound
  202. call PlaySound
  203. pop de
  204. pop hl
  205. .skipPlayingSound
  206. push hl
  207. inc de
  208. ld a,[de]
  209. ld l,a
  210. inc de
  211. ld a,[de]
  212. ld h,a
  213. ld de,.nextAnimationCommand
  214. push de
  215. jp [hl] ; jump to special effect function
  216. .playSubanimation
  217. ld c,a
  218. and a,%00111111
  219. ld [wSubAnimFrameDelay],a
  220. xor a
  221. sla c
  222. rla
  223. sla c
  224. rla
  225. ld [wWhichBattleAnimTileset],a
  226. ld a,[hli] ; sound
  227. ld [wAnimSoundID],a ; store sound
  228. ld a,[hli] ; subanimation ID
  229. ld c,l
  230. ld b,h
  231. ld l,a
  232. ld h,0
  233. add hl,hl
  234. ld de,SubanimationPointers
  235. add hl,de
  236. ld a,l
  237. ld [wSubAnimAddrPtr],a
  238. ld a,h
  239. ld [wSubAnimAddrPtr + 1],a
  240. ld l,c
  241. ld h,b
  242. push hl
  243. ld a,[rOBP0]
  244. push af
  245. ld a,[wAnimPalette]
  246. ld [rOBP0],a
  247. call LoadAnimationTileset
  248. call LoadSubanimation
  249. call PlaySubanimation
  250. pop af
  251. ld [rOBP0],a
  252. .nextAnimationCommand
  253. pop hl
  254. jr .animationLoop
  255. .AnimationOver
  256. ret
  257. LoadSubanimation:
  258. ld a,[wSubAnimAddrPtr + 1]
  259. ld h,a
  260. ld a,[wSubAnimAddrPtr]
  261. ld l,a
  262. ld a,[hli]
  263. ld e,a
  264. ld a,[hl]
  265. ld d,a ; de = address of subanimation
  266. ld a,[de]
  267. ld b,a
  268. and a,31
  269. ld [wSubAnimCounter],a ; number of frame blocks
  270. ld a,b
  271. and a,%11100000
  272. cp a,5 << 5 ; is subanimation type 5?
  273. jr nz,.isNotType5
  274. .isType5
  275. call GetSubanimationTransform2
  276. jr .saveTransformation
  277. .isNotType5
  278. call GetSubanimationTransform1
  279. .saveTransformation
  280. ; place the upper 3 bits of a into bits 0-2 of a before storing
  281. srl a
  282. swap a
  283. ld [wSubAnimTransform],a
  284. cp a,4 ; is the animation reversed?
  285. ld hl,0
  286. jr nz,.storeSubentryAddr
  287. ; if the animation is reversed, then place the initial subentry address at the end of the list of subentries
  288. ld a,[wSubAnimCounter]
  289. dec a
  290. ld bc,3
  291. .loop
  292. add hl,bc
  293. dec a
  294. jr nz,.loop
  295. .storeSubentryAddr
  296. inc de
  297. add hl,de
  298. ld a,l
  299. ld [wSubAnimSubEntryAddr],a
  300. ld a,h
  301. ld [wSubAnimSubEntryAddr + 1],a
  302. ret
  303. ; called if the subanimation type is not 5
  304. ; sets the transform to 0 (i.e. no transform) if it's the player's turn
  305. ; sets the transform to the subanimation type if it's the enemy's turn
  306. GetSubanimationTransform1:
  307. ld b,a
  308. ld a,[H_WHOSETURN]
  309. and a
  310. ld a,b
  311. ret nz
  312. xor a
  313. ret
  314. ; called if the subanimation type is 5
  315. ; sets the transform to 2 (i.e. horizontal and vertical flip) if it's the player's turn
  316. ; sets the transform to 0 (i.e. no transform) if it's the enemy's turn
  317. GetSubanimationTransform2:
  318. ld a,[H_WHOSETURN]
  319. and a
  320. ld a,2 << 5
  321. ret z
  322. xor a
  323. ret
  324. ; loads tile patterns for battle animations
  325. LoadAnimationTileset:
  326. ld a,[wWhichBattleAnimTileset]
  327. add a
  328. add a
  329. ld hl,AnimationTilesetPointers
  330. ld e,a
  331. ld d,0
  332. add hl,de
  333. ld a,[hli]
  334. ld [wTempTilesetNumTiles],a ; number of tiles
  335. ld a,[hli]
  336. ld e,a
  337. ld a,[hl]
  338. ld d,a ; de = address of tileset
  339. ld hl,vSprites + $310
  340. ld b, BANK(AnimationTileset1) ; ROM bank
  341. ld a,[wTempTilesetNumTiles]
  342. ld c,a ; number of tiles
  343. jp CopyVideoData ; load tileset
  344. AnimationTilesetPointers:
  345. db 79 ; number of tiles
  346. dw AnimationTileset1
  347. db $FF
  348. db 79 ; number of tiles
  349. dw AnimationTileset2
  350. db $FF
  351. db 64 ; number of tiles
  352. dw AnimationTileset1
  353. db $FF
  354. AnimationTileset1:
  355. INCBIN "gfx/attack_anim_1.2bpp"
  356. AnimationTileset2:
  357. INCBIN "gfx/attack_anim_2.2bpp"
  358. SlotMachineTiles2:
  359. IF DEF(_RED)
  360. INCBIN "gfx/red/slotmachine2.2bpp"
  361. ENDC
  362. IF DEF(_BLUE)
  363. INCBIN "gfx/blue/slotmachine2.2bpp"
  364. ENDC
  365. MoveAnimation:
  366. push hl
  367. push de
  368. push bc
  369. push af
  370. call WaitForSoundToFinish
  371. call SetAnimationPalette
  372. ld a,[wAnimationID]
  373. and a
  374. jr z, .animationFinished
  375. ; if throwing a Poké Ball, skip the regular animation code
  376. cp a,TOSS_ANIM
  377. jr nz, .moveAnimation
  378. ld de, .animationFinished
  379. push de
  380. jp TossBallAnimation
  381. .moveAnimation
  382. ; check if battle animations are disabled in the options
  383. ld a,[wOptions]
  384. bit 7,a
  385. jr nz, .animationsDisabled
  386. call ShareMoveAnimations
  387. call PlayAnimation
  388. jr .next4
  389. .animationsDisabled
  390. ld c,30
  391. call DelayFrames
  392. .next4
  393. call PlayApplyingAttackAnimation ; shake the screen or flash the pic in and out (to show damage)
  394. .animationFinished
  395. call WaitForSoundToFinish
  396. xor a
  397. ld [wSubAnimSubEntryAddr],a
  398. ld [wUnusedD09B],a
  399. ld [wSubAnimTransform],a
  400. dec a
  401. ld [wAnimSoundID],a
  402. pop af
  403. pop bc
  404. pop de
  405. pop hl
  406. ret
  407. ShareMoveAnimations:
  408. ; some moves just reuse animations from status conditions
  409. ld a,[H_WHOSETURN]
  410. and a
  411. ret z
  412. ; opponents turn
  413. ld a,[wAnimationID]
  414. cp a,AMNESIA
  415. ld b,CONF_ANIM
  416. jr z, .replaceAnim
  417. cp a,REST
  418. ld b,SLP_ANIM
  419. ret nz
  420. .replaceAnim
  421. ld a,b
  422. ld [wAnimationID],a
  423. ret
  424. PlayApplyingAttackAnimation:
  425. ; Generic animation that shows after the move's individual animation
  426. ; Different animation depending on whether the move has an additional effect and on whose turn it is
  427. ld a,[wAnimationType]
  428. and a
  429. ret z
  430. dec a
  431. add a
  432. ld c,a
  433. ld b,0
  434. ld hl,AnimationTypePointerTable
  435. add hl,bc
  436. ld a,[hli]
  437. ld h,[hl]
  438. ld l,a
  439. jp [hl]
  440. AnimationTypePointerTable:
  441. dw ShakeScreenVertically ; enemy mon has used a damaging move without a side effect
  442. dw ShakeScreenHorizontallyHeavy ; enemy mon has used a damaging move with a side effect
  443. dw ShakeScreenHorizontallySlow ; enemy mon has used a non-damaging move
  444. dw BlinkEnemyMonSprite ; player mon has used a damaging move without a side effect
  445. dw ShakeScreenHorizontallyLight ; player mon has used a damaging move with a side effect
  446. dw ShakeScreenHorizontallySlow2 ; player mon has used a non-damaging move
  447. ShakeScreenVertically:
  448. call PlayApplyingAttackSound
  449. ld b, 8
  450. jp AnimationShakeScreenVertically
  451. ShakeScreenHorizontallyHeavy:
  452. call PlayApplyingAttackSound
  453. ld b, 8
  454. jp AnimationShakeScreenHorizontallyFast
  455. ShakeScreenHorizontallySlow:
  456. lb bc, 6, 2
  457. jr AnimationShakeScreenHorizontallySlow
  458. BlinkEnemyMonSprite:
  459. call PlayApplyingAttackSound
  460. jp AnimationBlinkEnemyMon
  461. ShakeScreenHorizontallyLight:
  462. call PlayApplyingAttackSound
  463. ld b, 2
  464. jp AnimationShakeScreenHorizontallyFast
  465. ShakeScreenHorizontallySlow2:
  466. lb bc, 3, 2
  467. AnimationShakeScreenHorizontallySlow:
  468. push bc
  469. push bc
  470. .loop1
  471. ld a, [rWX]
  472. inc a
  473. ld [rWX], a
  474. ld c, 2
  475. call DelayFrames
  476. dec b
  477. jr nz, .loop1
  478. pop bc
  479. .loop2
  480. ld a, [rWX]
  481. dec a
  482. ld [rWX], a
  483. ld c, 2
  484. call DelayFrames
  485. dec b
  486. jr nz, .loop2
  487. pop bc
  488. dec c
  489. jr nz, AnimationShakeScreenHorizontallySlow
  490. ret
  491. SetAnimationPalette:
  492. ld a, [wOnSGB]
  493. and a
  494. ld a, $e4
  495. jr z, .notSGB
  496. ld a, $f0
  497. ld [wAnimPalette], a
  498. ld b, $e4
  499. ld a, [wAnimationID]
  500. cp TRADE_BALL_DROP_ANIM
  501. jr c, .next
  502. cp TRADE_BALL_POOF_ANIM + 1
  503. jr nc, .next
  504. ld b, $f0
  505. .next
  506. ld a, b
  507. ld [rOBP0], a
  508. ld a, $6c
  509. ld [rOBP1], a
  510. ret
  511. .notSGB
  512. ld a, $e4
  513. ld [wAnimPalette], a
  514. ld [rOBP0], a
  515. ld a, $6c
  516. ld [rOBP1], a
  517. ret
  518. PlaySubanimation:
  519. ld a,[wAnimSoundID]
  520. cp a,$FF
  521. jr z,.skipPlayingSound
  522. call GetMoveSound
  523. call PlaySound
  524. .skipPlayingSound
  525. ld hl,wOAMBuffer ; base address of OAM buffer
  526. ld a,l
  527. ld [wFBDestAddr + 1],a
  528. ld a,h
  529. ld [wFBDestAddr],a
  530. ld a,[wSubAnimSubEntryAddr + 1]
  531. ld h,a
  532. ld a,[wSubAnimSubEntryAddr]
  533. ld l,a
  534. .loop
  535. push hl
  536. ld c,[hl] ; frame block ID
  537. ld b,0
  538. ld hl,FrameBlockPointers
  539. add hl,bc
  540. add hl,bc
  541. ld a,[hli]
  542. ld c,a
  543. ld a,[hli]
  544. ld b,a
  545. pop hl
  546. inc hl
  547. push hl
  548. ld e,[hl] ; base coordinate ID
  549. ld d,0
  550. ld hl,FrameBlockBaseCoords ; base coordinate table
  551. add hl,de
  552. add hl,de
  553. ld a,[hli]
  554. ld [wBaseCoordY],a
  555. ld a,[hl]
  556. ld [wBaseCoordX],a
  557. pop hl
  558. inc hl
  559. ld a,[hl] ; frame block mode
  560. ld [wFBMode],a
  561. call DrawFrameBlock
  562. call DoSpecialEffectByAnimationId ; run animation-specific function (if there is one)
  563. ld a,[wSubAnimCounter]
  564. dec a
  565. ld [wSubAnimCounter],a
  566. ret z
  567. ld a,[wSubAnimSubEntryAddr + 1]
  568. ld h,a
  569. ld a,[wSubAnimSubEntryAddr]
  570. ld l,a
  571. ld a,[wSubAnimTransform]
  572. cp a,4 ; is the animation reversed?
  573. ld bc,3
  574. jr nz,.nextSubanimationSubentry
  575. ld bc,-3
  576. .nextSubanimationSubentry
  577. add hl,bc
  578. ld a,h
  579. ld [wSubAnimSubEntryAddr + 1],a
  580. ld a,l
  581. ld [wSubAnimSubEntryAddr],a
  582. jp .loop
  583. AnimationCleanOAM:
  584. push hl
  585. push de
  586. push bc
  587. push af
  588. call DelayFrame
  589. call ClearSprites
  590. pop af
  591. pop bc
  592. pop de
  593. pop hl
  594. ret
  595. ; this runs after each frame block is drawn in a subanimation
  596. ; it runs a particular special effect based on the animation ID
  597. DoSpecialEffectByAnimationId:
  598. push hl
  599. push de
  600. push bc
  601. ld a,[wAnimationID]
  602. ld hl,AnimationIdSpecialEffects
  603. ld de,3
  604. call IsInArray
  605. jr nc,.done
  606. inc hl
  607. ld a,[hli]
  608. ld h,[hl]
  609. ld l,a
  610. ld de,.done
  611. push de
  612. jp [hl]
  613. .done
  614. pop bc
  615. pop de
  616. pop hl
  617. ret
  618. ; Format: Animation ID (1 byte), Address (2 bytes)
  619. AnimationIdSpecialEffects:
  620. db MEGA_PUNCH
  621. dw AnimationFlashScreen
  622. db GUILLOTINE
  623. dw AnimationFlashScreen
  624. db MEGA_KICK
  625. dw AnimationFlashScreen
  626. db HEADBUTT
  627. dw AnimationFlashScreen
  628. db TAIL_WHIP
  629. dw TailWhipAnimationUnused
  630. db GROWL
  631. dw DoGrowlSpecialEffects
  632. db DISABLE
  633. dw AnimationFlashScreen
  634. db BLIZZARD
  635. dw DoBlizzardSpecialEffects
  636. db BUBBLEBEAM
  637. dw AnimationFlashScreen
  638. db HYPER_BEAM
  639. dw FlashScreenEveryFourFrameBlocks
  640. db THUNDERBOLT
  641. dw FlashScreenEveryEightFrameBlocks
  642. db REFLECT
  643. dw AnimationFlashScreen
  644. db SELFDESTRUCT
  645. dw DoExplodeSpecialEffects
  646. db SPORE
  647. dw AnimationFlashScreen
  648. db EXPLOSION
  649. dw DoExplodeSpecialEffects
  650. db ROCK_SLIDE
  651. dw DoRockSlideSpecialEffects
  652. db TRADE_BALL_DROP_ANIM
  653. dw TradeHidePokemon
  654. db TRADE_BALL_SHAKE_ANIM
  655. dw TradeShakePokeball
  656. db TRADE_BALL_TILT_ANIM
  657. dw TradeJumpPokeball
  658. db TOSS_ANIM
  659. dw DoBallTossSpecialEffects
  660. db SHAKE_ANIM
  661. dw DoBallShakeSpecialEffects
  662. db POOF_ANIM
  663. dw DoPoofSpecialEffects
  664. db GREATTOSS_ANIM
  665. dw DoBallTossSpecialEffects
  666. db ULTRATOSS_ANIM
  667. dw DoBallTossSpecialEffects
  668. db $FF ; terminator
  669. DoBallTossSpecialEffects:
  670. ld a,[wcf91]
  671. cp a,3 ; is it a Master Ball or Ultra Ball?
  672. jr nc,.skipFlashingEffect
  673. .flashingEffect ; do a flashing effect if it's Master Ball or Ultra Ball
  674. ld a,[rOBP0]
  675. xor a,%00111100 ; complement colors 1 and 2
  676. ld [rOBP0],a
  677. .skipFlashingEffect
  678. ld a,[wSubAnimCounter]
  679. cp a,11 ; is it the beginning of the subanimation?
  680. jr nz,.skipPlayingSound
  681. ; if it is the beginning of the subanimation, play a sound
  682. ld a,SFX_BALL_TOSS
  683. call PlaySound
  684. .skipPlayingSound
  685. ld a,[wIsInBattle]
  686. cp a,02 ; is it a trainer battle?
  687. jr z,.isTrainerBattle
  688. ld a,[wd11e]
  689. cp a,$10 ; is the enemy pokemon the Ghost Marowak?
  690. ret nz
  691. ; if the enemy pokemon is the Ghost Marowak, make it dodge during the last 3 frames
  692. ld a,[wSubAnimCounter]
  693. cp a,3
  694. jr z,.moveGhostMarowakLeft
  695. cp a,2
  696. jr z,.moveGhostMarowakLeft
  697. cp a,1
  698. ret nz
  699. .moveGhostMarowakLeft
  700. coord hl, 17, 0
  701. ld de,20
  702. lb bc, 7, 7
  703. .loop
  704. push hl
  705. push bc
  706. call AnimCopyRowRight ; move row of tiles left
  707. pop bc
  708. pop hl
  709. add hl,de
  710. dec b
  711. jr nz,.loop
  712. ld a,%00001000
  713. ld [rNR10],a ; Channel 1 sweep register
  714. ret
  715. .isTrainerBattle ; if it's a trainer battle, shorten the animation by one frame
  716. ld a,[wSubAnimCounter]
  717. cp a,3
  718. ret nz
  719. dec a
  720. ld [wSubAnimCounter],a
  721. ret
  722. DoBallShakeSpecialEffects:
  723. ld a,[wSubAnimCounter]
  724. cp a,4 ; is it the beginning of a shake?
  725. jr nz,.skipPlayingSound
  726. ; if it is the beginning of a shake, play a sound and wait 2/3 of a second
  727. ld a,SFX_TINK
  728. call PlaySound
  729. ld c,40
  730. call DelayFrames
  731. .skipPlayingSound
  732. ld a,[wSubAnimCounter]
  733. dec a
  734. ret nz
  735. ; if it's the end of the ball shaking subanimation, check if more shakes are left and restart the subanimation
  736. ld a,[wNumShakes] ; number of shakes
  737. dec a ; decrement number of shakes
  738. ld [wNumShakes],a
  739. ret z
  740. ; if there are shakes left, restart the subanimation
  741. ld a,[wSubAnimSubEntryAddr]
  742. ld l,a
  743. ld a,[wSubAnimSubEntryAddr + 1]
  744. ld h,a
  745. ld de,-(4 * 3) ; 4 subentries and 3 bytes per subentry
  746. add hl,de
  747. ld a,l
  748. ld [wSubAnimSubEntryAddr],a
  749. ld a,h
  750. ld [wSubAnimSubEntryAddr + 1],a
  751. ld a,5 ; number of subentries in the ball shaking subanimation plus one
  752. ld [wSubAnimCounter],a
  753. ret
  754. ; plays a sound after the second frame of the poof animation
  755. DoPoofSpecialEffects:
  756. ld a,[wSubAnimCounter]
  757. cp a,5
  758. ret nz
  759. ld a,SFX_BALL_POOF
  760. jp PlaySound
  761. DoRockSlideSpecialEffects:
  762. ld a,[wSubAnimCounter]
  763. cp a,12
  764. ret nc
  765. cp a,8
  766. jr nc,.shakeScreen
  767. cp a,1
  768. jp z,AnimationFlashScreen ; if it's the end of the subanimation, flash the screen
  769. ret
  770. ; if the subaninmation counter is between 8 and 11, shake the screen horizontally and vertically
  771. .shakeScreen
  772. ld b,1
  773. predef PredefShakeScreenHorizontally ; shake horizontally
  774. ld b,1
  775. predef_jump PredefShakeScreenVertically ; shake vertically
  776. FlashScreenEveryEightFrameBlocks:
  777. ld a,[wSubAnimCounter]
  778. and a,7 ; is the subanimation counter exactly 8?
  779. call z,AnimationFlashScreen ; if so, flash the screen
  780. ret
  781. ; flashes the screen if the subanimation counter is divisible by 4
  782. FlashScreenEveryFourFrameBlocks:
  783. ld a,[wSubAnimCounter]
  784. and a,3
  785. call z,AnimationFlashScreen
  786. ret
  787. ; used for Explosion and Selfdestruct
  788. DoExplodeSpecialEffects:
  789. ld a,[wSubAnimCounter]
  790. cp a,1 ; is it the end of the subanimation?
  791. jr nz,FlashScreenEveryFourFrameBlocks
  792. ; if it's the end of the subanimation, make the attacking pokemon disappear
  793. coord hl, 1, 5
  794. jp AnimationHideMonPic ; make pokemon disappear
  795. ; flashes the screen when subanimation counter is 1 modulo 4
  796. DoBlizzardSpecialEffects:
  797. ld a,[wSubAnimCounter]
  798. cp a,13
  799. jp z,AnimationFlashScreen
  800. cp a,9
  801. jp z,AnimationFlashScreen
  802. cp a,5
  803. jp z,AnimationFlashScreen
  804. cp a,1
  805. jp z,AnimationFlashScreen
  806. ret
  807. ; flashes the screen at 3 points in the subanimation
  808. ; unused
  809. FlashScreenUnused:
  810. ld a,[wSubAnimCounter]
  811. cp a,14
  812. jp z,AnimationFlashScreen
  813. cp a,9
  814. jp z,AnimationFlashScreen
  815. cp a,2
  816. jp z,AnimationFlashScreen
  817. ret
  818. ; function to make the pokemon disappear at the beginning of the animation
  819. TradeHidePokemon:
  820. ld a,[wSubAnimCounter]
  821. cp a,6
  822. ret nz
  823. ld a,2 * SCREEN_WIDTH + 7
  824. jp ClearMonPicFromTileMap ; make pokemon disappear
  825. ; function to make a shaking pokeball jump up at the end of the animation
  826. TradeShakePokeball:
  827. ld a,[wSubAnimCounter]
  828. cp a,1
  829. ret nz
  830. ; if it's the end of the animation, make the ball jump up
  831. ld de,BallMoveDistances1
  832. .loop
  833. ld hl,wOAMBuffer ; OAM buffer
  834. ld bc,4
  835. .innerLoop
  836. ld a,[de]
  837. cp a,$ff
  838. jr z,.done
  839. add [hl] ; add to Y value of OAM entry
  840. ld [hl],a
  841. add hl,bc
  842. ld a,l
  843. cp a,4 * 4 ; there are 4 entries, each 4 bytes
  844. jr nz,.innerLoop
  845. inc de
  846. push bc
  847. call Delay3
  848. pop bc
  849. jr .loop
  850. .done
  851. call AnimationCleanOAM
  852. ld a,SFX_TRADE_MACHINE
  853. jp PlaySound
  854. BallMoveDistances1:
  855. db -12,-12,-8
  856. db $ff ; terminator
  857. ; function to make the pokeball jump up
  858. TradeJumpPokeball:
  859. ld de,BallMoveDistances2
  860. .loop
  861. ld hl,wOAMBuffer ; OAM buffer
  862. ld bc,4
  863. .innerLoop
  864. ld a,[de]
  865. cp a,$ff
  866. jp z,ClearScreen
  867. add [hl]
  868. ld [hl],a
  869. add hl,bc
  870. ld a,l
  871. cp a,4 * 4 ; there are 4 entries, each 4 bytes
  872. jr nz,.innerLoop
  873. inc de
  874. push de
  875. ld a,[de]
  876. cp a,12
  877. jr z,.playSound
  878. cp a,$ff
  879. jr nz,.skipPlayingSound
  880. .playSound ; play sound if next move distance is 12 or this is the last one
  881. ld a,SFX_BATTLE_18
  882. call PlaySound
  883. .skipPlayingSound
  884. push bc
  885. ld c,5
  886. call DelayFrames
  887. pop bc
  888. ld a,[hSCX] ; background scroll X
  889. sub a,8 ; scroll to the left
  890. ld [hSCX],a
  891. pop de
  892. jr .loop
  893. BallMoveDistances2:
  894. db 11,12,-12,-7,7,12,-8,8
  895. db $ff ; terminator
  896. ; this function copies the current musical note graphic
  897. ; so that there are two musical notes flying towards the defending pokemon
  898. DoGrowlSpecialEffects:
  899. ld hl,wOAMBuffer ; OAM buffer
  900. ld de,wOAMBuffer + $10
  901. ld bc,$10
  902. call CopyData ; copy the musical note graphic
  903. ld a,[wSubAnimCounter]
  904. dec a
  905. call z,AnimationCleanOAM ; clean up at the end of the subanimation
  906. ret
  907. ; this is associated with Tail Whip, but Tail Whip doesn't use any subanimations
  908. TailWhipAnimationUnused:
  909. ld a,1
  910. ld [wSubAnimCounter],a
  911. ld c,20
  912. jp DelayFrames
  913. ; Format: Special Effect ID (1 byte), Address (2 bytes)
  914. SpecialEffectPointers:
  915. db SE_DARK_SCREEN_FLASH ; $FE
  916. dw AnimationFlashScreen
  917. db SE_DARK_SCREEN_PALETTE ; $FD
  918. dw AnimationDarkScreenPalette
  919. db SE_RESET_SCREEN_PALETTE ; $FC
  920. dw AnimationResetScreenPalette
  921. db SE_SHAKE_SCREEN ; $FB
  922. dw AnimationShakeScreen
  923. db SE_WATER_DROPLETS_EVERYWHERE ; $FA
  924. dw AnimationWaterDropletsEverywhere
  925. db SE_DARKEN_MON_PALETTE ; $F9
  926. dw AnimationDarkenMonPalette
  927. db SE_FLASH_SCREEN_LONG ; $F8
  928. dw AnimationFlashScreenLong
  929. db SE_SLIDE_MON_UP ; $F7
  930. dw AnimationSlideMonUp
  931. db SE_SLIDE_MON_DOWN ; $F6
  932. dw AnimationSlideMonDown
  933. db SE_FLASH_MON_PIC ; $F5
  934. dw AnimationFlashMonPic
  935. db SE_SLIDE_MON_OFF ; $F4
  936. dw AnimationSlideMonOff
  937. db SE_BLINK_MON ; $F3
  938. dw AnimationBlinkMon
  939. db SE_MOVE_MON_HORIZONTALLY ; $F2
  940. dw AnimationMoveMonHorizontally
  941. db SE_RESET_MON_POSITION ; $F1
  942. dw AnimationResetMonPosition
  943. db SE_LIGHT_SCREEN_PALETTE ; $F0
  944. dw AnimationLightScreenPalette
  945. db SE_HIDE_MON_PIC ; $EF
  946. dw AnimationHideMonPic
  947. db SE_SQUISH_MON_PIC ; $EE
  948. dw AnimationSquishMonPic
  949. db SE_SHOOT_BALLS_UPWARD ; $ED
  950. dw AnimationShootBallsUpward
  951. db SE_SHOOT_MANY_BALLS_UPWARD ; $EC
  952. dw AnimationShootManyBallsUpward
  953. db SE_BOUNCE_UP_AND_DOWN ; $EB
  954. dw AnimationBoundUpAndDown
  955. db SE_MINIMIZE_MON ; $EA
  956. dw AnimationMinimizeMon
  957. db SE_SLIDE_MON_DOWN_AND_HIDE ; $E9
  958. dw AnimationSlideMonDownAndHide
  959. db SE_TRANSFORM_MON ; $E8
  960. dw AnimationTransformMon
  961. db SE_LEAVES_FALLING ; $E7
  962. dw AnimationLeavesFalling
  963. db SE_PETALS_FALLING ; $E6
  964. dw AnimationPetalsFalling
  965. db SE_SLIDE_MON_HALF_OFF ; $E5
  966. dw AnimationSlideMonHalfOff
  967. db SE_SHAKE_ENEMY_HUD ; $E4
  968. dw AnimationShakeEnemyHUD
  969. db SE_SHAKE_ENEMY_HUD_2 ; unused--same pointer as SE_SHAKE_ENEMY_HUD ($E4)
  970. dw AnimationShakeEnemyHUD
  971. db SE_SPIRAL_BALLS_INWARD ; $E2
  972. dw AnimationSpiralBallsInward
  973. db SE_DELAY_ANIMATION_10 ; $E1
  974. dw AnimationDelay10
  975. db SE_FLASH_ENEMY_MON_PIC ; unused--same as SE_FLASH_MON_PIC ($F5), but for the enemy mon
  976. dw AnimationFlashEnemyMonPic
  977. db SE_HIDE_ENEMY_MON_PIC ; $DF
  978. dw AnimationHideEnemyMonPic
  979. db SE_BLINK_ENEMY_MON ; $DE
  980. dw AnimationBlinkEnemyMon
  981. db SE_SHOW_MON_PIC ; $DD
  982. dw AnimationShowMonPic
  983. db SE_SHOW_ENEMY_MON_PIC ; $DC
  984. dw AnimationShowEnemyMonPic
  985. db SE_SLIDE_ENEMY_MON_OFF ; $DB
  986. dw AnimationSlideEnemyMonOff
  987. db SE_SHAKE_BACK_AND_FORTH ; $DA
  988. dw AnimationShakeBackAndForth
  989. db SE_SUBSTITUTE_MON ; $D9
  990. dw AnimationSubstitute
  991. db SE_WAVY_SCREEN ; $D8
  992. dw AnimationWavyScreen
  993. db $FF
  994. AnimationDelay10:
  995. ld c,10
  996. jp DelayFrames
  997. ; calls a function with the turn flipped from player to enemy or vice versa
  998. ; input - hl - address of function to call
  999. CallWithTurnFlipped:
  1000. ld a,[H_WHOSETURN]
  1001. push af
  1002. xor a,1
  1003. ld [H_WHOSETURN],a
  1004. ld de,.returnAddress
  1005. push de
  1006. jp [hl]
  1007. .returnAddress
  1008. pop af
  1009. ld [H_WHOSETURN],a
  1010. ret
  1011. ; flashes the screen for an extended period (48 frames)
  1012. AnimationFlashScreenLong:
  1013. ld a,3 ; cycle through the palettes 3 times
  1014. ld [wFlashScreenLongCounter],a
  1015. ld a,[wOnSGB] ; running on SGB?
  1016. and a
  1017. ld hl,FlashScreenLongMonochrome
  1018. jr z,.loop
  1019. ld hl,FlashScreenLongSGB
  1020. .loop
  1021. push hl
  1022. .innerLoop
  1023. ld a,[hli]
  1024. cp a,$01 ; is it the end of the palettes?
  1025. jr z,.endOfPalettes
  1026. ld [rBGP],a
  1027. call FlashScreenLongDelay
  1028. jr .innerLoop
  1029. .endOfPalettes
  1030. ld a,[wFlashScreenLongCounter]
  1031. dec a
  1032. ld [wFlashScreenLongCounter],a
  1033. pop hl
  1034. jr nz,.loop
  1035. ret
  1036. ; BG palettes
  1037. FlashScreenLongMonochrome:
  1038. db %11111001 ; 3, 3, 2, 1
  1039. db %11111110 ; 3, 3, 3, 2
  1040. db %11111111 ; 3, 3, 3, 3
  1041. db %11111110 ; 3, 3, 3, 2
  1042. db %11111001 ; 3, 3, 2, 1
  1043. db %11100100 ; 3, 2, 1, 0
  1044. db %10010000 ; 2, 1, 0, 0
  1045. db %01000000 ; 1, 0, 0, 0
  1046. db %00000000 ; 0, 0, 0, 0
  1047. db %01000000 ; 1, 0, 0, 0
  1048. db %10010000 ; 2, 1, 0, 0
  1049. db %11100100 ; 3, 2, 1, 0
  1050. db $01 ; terminator
  1051. ; BG palettes
  1052. FlashScreenLongSGB:
  1053. db %11111000 ; 3, 3, 2, 0
  1054. db %11111100 ; 3, 3, 3, 0
  1055. db %11111111 ; 3, 3, 3, 3
  1056. db %11111100 ; 3, 3, 3, 0
  1057. db %11111000 ; 3, 3, 2, 0
  1058. db %11100100 ; 3, 2, 1, 0
  1059. db %10010000 ; 2, 1, 0, 0
  1060. db %01000000 ; 1, 0, 0, 0
  1061. db %00000000 ; 0, 0, 0, 0
  1062. db %01000000 ; 1, 0, 0, 0
  1063. db %10010000 ; 2, 1, 0, 0
  1064. db %11100100 ; 3, 2, 1, 0
  1065. db $01 ; terminator
  1066. ; causes a delay of 2 frames for the first cycle
  1067. ; causes a delay of 1 frame for the second and third cycles
  1068. FlashScreenLongDelay:
  1069. ld a,[wFlashScreenLongCounter]
  1070. cp a,4 ; never true since [wFlashScreenLongCounter] starts at 3
  1071. ld c,4
  1072. jr z,.delayFrames
  1073. cp a,3
  1074. ld c,2
  1075. jr z,.delayFrames
  1076. cp a,2 ; nothing is done with this
  1077. ld c,1
  1078. .delayFrames
  1079. jp DelayFrames
  1080. AnimationFlashScreen:
  1081. ld a,[rBGP]
  1082. push af ; save initial palette
  1083. ld a,%00011011 ; 0, 1, 2, 3 (inverted colors)
  1084. ld [rBGP],a
  1085. ld c,2
  1086. call DelayFrames
  1087. xor a ; white out background
  1088. ld [rBGP],a
  1089. ld c,2
  1090. call DelayFrames
  1091. pop af
  1092. ld [rBGP],a ; restore initial palette
  1093. ret
  1094. AnimationDarkScreenPalette:
  1095. ; Changes the screen's palette to a dark palette.
  1096. lb bc, $6f, $6f
  1097. jr SetAnimationBGPalette
  1098. AnimationDarkenMonPalette:
  1099. ; Darkens the mon sprite's palette.
  1100. lb bc, $f9, $f4
  1101. jr SetAnimationBGPalette
  1102. AnimationUnusedPalette1:
  1103. lb bc, $fe, $f8
  1104. jr SetAnimationBGPalette
  1105. AnimationUnusedPalette2:
  1106. lb bc, $ff, $ff
  1107. jr SetAnimationBGPalette
  1108. AnimationResetScreenPalette:
  1109. ; Restores the screen's palette to the normal palette.
  1110. lb bc, $e4, $e4
  1111. jr SetAnimationBGPalette
  1112. AnimationUnusedPalette3:
  1113. lb bc, $00, $00
  1114. jr SetAnimationBGPalette
  1115. AnimationLightScreenPalette:
  1116. ; Changes the screen to use a palette with light colors.
  1117. lb bc, $90, $90
  1118. jr SetAnimationBGPalette
  1119. AnimationUnusedPalette4:
  1120. lb bc, $40, $40
  1121. SetAnimationBGPalette:
  1122. ld a, [wOnSGB]
  1123. and a
  1124. ld a, b
  1125. jr z, .next
  1126. ld a, c
  1127. .next
  1128. ld [rBGP], a
  1129. ret
  1130. ld b, $5
  1131. AnimationShakeScreenVertically:
  1132. predef_jump PredefShakeScreenVertically
  1133. AnimationShakeScreen:
  1134. ; Shakes the screen for a while. Used in Earthquake/Fissure/etc. animations.
  1135. ld b, $8
  1136. AnimationShakeScreenHorizontallyFast:
  1137. predef_jump PredefShakeScreenHorizontally
  1138. AnimationWaterDropletsEverywhere:
  1139. ; Draws water droplets all over the screen and makes them
  1140. ; scroll. It's hard to describe, but it's the main animation
  1141. ; in Surf/Mist/Toxic.
  1142. xor a
  1143. ld [wWhichBattleAnimTileset], a
  1144. call LoadAnimationTileset
  1145. ld d, 32
  1146. ld a, -16
  1147. ld [wBaseCoordX], a
  1148. ld a, $71
  1149. ld [wDropletTile], a
  1150. .loop
  1151. ld a, 16
  1152. ld [wBaseCoordY], a
  1153. ld a, 0
  1154. ld [wUnusedD08A], a
  1155. call _AnimationWaterDroplets
  1156. ld a, 24
  1157. ld [wBaseCoordY], a
  1158. ld a, 32
  1159. ld [wUnusedD08A], a
  1160. call _AnimationWaterDroplets
  1161. dec d
  1162. jr nz, .loop
  1163. ret
  1164. _AnimationWaterDroplets:
  1165. ld hl, wOAMBuffer
  1166. .loop
  1167. ld a, [wBaseCoordY]
  1168. ld [hli], a ; Y
  1169. ld a, [wBaseCoordX]
  1170. add 27
  1171. ld [wBaseCoordX], a
  1172. ld [hli], a ; X
  1173. ld a, [wDropletTile]
  1174. ld [hli], a ; tile
  1175. xor a
  1176. ld [hli], a ; attribute
  1177. ld a, [wBaseCoordX]
  1178. cp 144
  1179. jr c, .loop
  1180. sub 168
  1181. ld [wBaseCoordX], a
  1182. ld a, [wBaseCoordY]
  1183. add 16
  1184. ld [wBaseCoordY], a
  1185. cp 112
  1186. jr c, .loop
  1187. call AnimationCleanOAM
  1188. jp DelayFrame
  1189. AnimationSlideMonUp:
  1190. ; Slides the mon's sprite upwards.
  1191. ld c, 7
  1192. ld a, [H_WHOSETURN]
  1193. and a
  1194. coord hl, 1, 6
  1195. coord de, 1, 5
  1196. ld a, $30
  1197. jr z, .next
  1198. coord hl, 12, 1
  1199. coord de, 12, 0
  1200. ld a, $ff
  1201. .next
  1202. ld [wSlideMonUpBottomRowLeftTile], a
  1203. jp _AnimationSlideMonUp
  1204. AnimationSlideMonDown:
  1205. ; Slides the mon's sprite down out of the screen.
  1206. xor a
  1207. call GetTileIDList
  1208. .loop
  1209. call GetMonSpriteTileMapPointerFromRowCount
  1210. push bc
  1211. push de
  1212. call CopyPicTiles
  1213. call Delay3
  1214. call AnimationHideMonPic
  1215. pop de
  1216. pop bc
  1217. dec b
  1218. jr nz, .loop
  1219. ret
  1220. AnimationSlideMonOff:
  1221. ; Slides the mon's sprite off the screen horizontally.
  1222. ld e, 8
  1223. ld a, 3
  1224. ld [wSlideMonDelay], a
  1225. jp _AnimationSlideMonOff
  1226. AnimationSlideEnemyMonOff:
  1227. ; Slides the enemy mon off the screen horizontally.
  1228. ld hl, AnimationSlideMonOff
  1229. jp CallWithTurnFlipped
  1230. _AnimationSlideMonUp:
  1231. push de
  1232. push hl
  1233. push bc
  1234. ; In each iteration, slide up all rows but the top one (which is overwritten).
  1235. ld b, 6
  1236. .slideLoop
  1237. push bc
  1238. push de
  1239. push hl
  1240. ld bc, 7
  1241. call CopyData
  1242. ; Note that de and hl are popped in the same order they are pushed, swapping
  1243. ; their values. When CopyData is called, hl points to a tile 1 row below
  1244. ; the one de points to. To maintain this relationship, after swapping, we add 2
  1245. ; rows to hl so that it is 1 row below again.
  1246. pop de
  1247. pop hl
  1248. ld bc, SCREEN_WIDTH * 2
  1249. add hl, bc
  1250. pop bc
  1251. dec b
  1252. jr nz, .slideLoop
  1253. ; Fill in the bottom row of the mon pic with the next row's tile IDs.
  1254. ld a, [H_WHOSETURN]
  1255. and a
  1256. coord hl, 1, 11
  1257. jr z, .next
  1258. coord hl, 12, 6
  1259. .next
  1260. ld a, [wSlideMonUpBottomRowLeftTile]
  1261. inc a
  1262. ld [wSlideMonUpBottomRowLeftTile], a
  1263. ld c, 7
  1264. .fillBottomRowLoop
  1265. ld [hli], a
  1266. add 7
  1267. dec c
  1268. jr nz, .fillBottomRowLoop
  1269. ld c, 2
  1270. call DelayFrames
  1271. pop bc
  1272. pop hl
  1273. pop de
  1274. dec c
  1275. jr nz, _AnimationSlideMonUp
  1276. ret
  1277. ShakeEnemyHUD_WritePlayerMonPicOAM:
  1278. ; Writes the OAM entries for a copy of the player mon's pic in OAM.
  1279. ; The top 5 rows are reproduced in OAM, although only 2 are actually needed.
  1280. ld a, $10
  1281. ld [wBaseCoordX], a
  1282. ld a, $30
  1283. ld [wBaseCoordY], a
  1284. ld hl, wOAMBuffer
  1285. ld d, 0
  1286. ld c, 7
  1287. .loop
  1288. ld a, [wBaseCoordY]
  1289. ld e, a
  1290. ld b, 5
  1291. .innerLoop
  1292. call BattleAnimWriteOAMEntry
  1293. inc d
  1294. dec b
  1295. jr nz, .innerLoop
  1296. dec c
  1297. ret z
  1298. inc d
  1299. inc d
  1300. ld a, [wBaseCoordX]
  1301. add 8
  1302. ld [wBaseCoordX], a
  1303. jr .loop
  1304. BattleAnimWriteOAMEntry:
  1305. ; Y coordinate = e (increased by 8 each call, before the write to OAM)
  1306. ; X coordinate = [wBaseCoordX]
  1307. ; tile = d
  1308. ; attributes = 0
  1309. ld a, e
  1310. add 8
  1311. ld e, a
  1312. ld [hli], a
  1313. ld a, [wBaseCoordX]
  1314. ld [hli], a
  1315. ld a, d
  1316. ld [hli], a
  1317. xor a
  1318. ld [hli], a
  1319. ret
  1320. AdjustOAMBlockXPos:
  1321. ld l, e
  1322. ld h, d
  1323. AdjustOAMBlockXPos2:
  1324. ld de, 4
  1325. .loop
  1326. ld a, [wCoordAdjustmentAmount]
  1327. ld b, a
  1328. ld a, [hl]
  1329. add b
  1330. cp 168
  1331. jr c, .skipPuttingEntryOffScreen
  1332. ; put off-screen if X >= 168
  1333. dec hl
  1334. ld a, 160
  1335. ld [hli], a
  1336. .skipPuttingEntryOffScreen
  1337. ld [hl], a
  1338. add hl, de
  1339. dec c
  1340. jr nz, .loop
  1341. ret
  1342. AdjustOAMBlockYPos:
  1343. ld l, e
  1344. ld h, d
  1345. AdjustOAMBlockYPos2:
  1346. ld de, 4
  1347. .loop
  1348. ld a, [wCoordAdjustmentAmount]
  1349. ld b, a
  1350. ld a, [hl]
  1351. add b
  1352. cp 112
  1353. jr c, .skipSettingPreviousEntrysAttribute
  1354. dec hl
  1355. ld a, 160 ; bug, sets previous OAM entry's attribute
  1356. ld [hli], a
  1357. .skipSettingPreviousEntrysAttribute
  1358. ld [hl], a
  1359. add hl, de
  1360. dec c
  1361. jr nz, .loop
  1362. ret
  1363. AnimationBlinkEnemyMon:
  1364. ; Make the enemy mon's sprite blink on and off for a second or two
  1365. ld hl, AnimationBlinkMon
  1366. jp CallWithTurnFlipped
  1367. AnimationBlinkMon:
  1368. ; Make the mon's sprite blink on and off for a second or two.
  1369. push af
  1370. ld c, 6
  1371. .loop
  1372. push bc
  1373. call AnimationHideMonPic
  1374. ld c, 5
  1375. call DelayFrames
  1376. call AnimationShowMonPic
  1377. ld c, 5
  1378. call DelayFrames
  1379. pop bc
  1380. dec c
  1381. jr nz, .loop
  1382. pop af
  1383. ret
  1384. AnimationFlashMonPic:
  1385. ; Flashes the mon's sprite on and off
  1386. ld a, [wBattleMonSpecies]
  1387. ld [wChangeMonPicPlayerTurnSpecies], a
  1388. ld a, [wEnemyMonSpecies]
  1389. ld [wChangeMonPicEnemyTurnSpecies], a
  1390. jp ChangeMonPic
  1391. AnimationFlashEnemyMonPic:
  1392. ; Flashes the enemy mon's sprite on and off
  1393. ld hl, AnimationFlashMonPic
  1394. jp CallWithTurnFlipped
  1395. AnimationShowMonPic:
  1396. xor a
  1397. call GetTileIDList
  1398. call GetMonSpriteTileMapPointerFromRowCount
  1399. call CopyPicTiles
  1400. jp Delay3
  1401. AnimationShowEnemyMonPic:
  1402. ; Shows the emenmy mon's front sprite. Used in animations like Seismic Toss
  1403. ; to make the mon's sprite reappear after disappears offscreen.
  1404. ld hl, AnimationShowMonPic
  1405. jp CallWithTurnFlipped
  1406. AnimationShakeBackAndForth:
  1407. ; Shakes the mon's sprite back and forth rapidly. This is used in Double Team.
  1408. ; The mon's sprite disappears after this animation.
  1409. ld a, [H_WHOSETURN]
  1410. and a
  1411. coord hl, 0, 5
  1412. coord de, 2, 5
  1413. jr z, .next
  1414. coord hl, 11, 0
  1415. coord de, 13, 0
  1416. .next
  1417. xor a
  1418. ld c, $10
  1419. .loop
  1420. push af
  1421. push bc
  1422. push de
  1423. push hl
  1424. push hl
  1425. push de
  1426. push af
  1427. push hl
  1428. push hl
  1429. call GetTileIDList
  1430. pop hl
  1431. call CopyPicTiles
  1432. call Delay3
  1433. pop hl
  1434. lb bc, 7, 9
  1435. call ClearScreenArea
  1436. pop af
  1437. call GetTileIDList
  1438. pop hl
  1439. call CopyPicTiles
  1440. call Delay3
  1441. pop hl
  1442. lb bc, 7, 9
  1443. call ClearScreenArea
  1444. pop hl
  1445. pop de
  1446. pop bc
  1447. pop af
  1448. dec c
  1449. jr nz, .loop
  1450. ret
  1451. AnimationMoveMonHorizontally:
  1452. ; Shifts the mon's sprite horizontally to a fixed location. Used by lots of
  1453. ; animations like Tackle/Body Slam.
  1454. call AnimationHideMonPic
  1455. ld a, [H_WHOSETURN]
  1456. and a
  1457. coord hl, 2, 5
  1458. jr z, .next
  1459. coord hl, 11, 0
  1460. .next
  1461. xor a
  1462. push hl
  1463. call GetTileIDList
  1464. pop hl
  1465. call CopyPicTiles
  1466. ld c, 3
  1467. jp DelayFrames
  1468. AnimationResetMonPosition:
  1469. ; Resets the mon's sprites to be located at the normal coordinates.
  1470. ld a, [H_WHOSETURN]
  1471. and a
  1472. ld a, 5 * SCREEN_WIDTH + 2
  1473. jr z, .next
  1474. ld a, 11
  1475. .next
  1476. call ClearMonPicFromTileMap
  1477. jp AnimationShowMonPic
  1478. AnimationSpiralBallsInward:
  1479. ; Creates an effect that looks like energy balls spiralling into the
  1480. ; player mon's sprite. Used in Focus Energy, for example.
  1481. ld a, [H_WHOSETURN]
  1482. and a
  1483. jr z, .playerTurn
  1484. ld a, -40
  1485. ld [wSpiralBallsBaseY], a
  1486. ld a, 80
  1487. ld [wSpiralBallsBaseX], a
  1488. jr .next
  1489. .playerTurn
  1490. xor a
  1491. ld [wSpiralBallsBaseY], a
  1492. ld [wSpiralBallsBaseX], a
  1493. .next
  1494. ld d, $7a ; ball tile
  1495. ld c, 3 ; number of balls
  1496. xor a
  1497. call InitMultipleObjectsOAM
  1498. ld hl, SpiralBallAnimationCoordinates
  1499. .loop
  1500. push hl
  1501. ld c, 3
  1502. ld de, wOAMBuffer
  1503. .innerLoop
  1504. ld a, [hl]
  1505. cp $ff
  1506. jr z, .done
  1507. ld a, [wSpiralBallsBaseY]
  1508. add [hl]
  1509. ld [de], a ; Y
  1510. inc de
  1511. inc hl
  1512. ld a, [wSpiralBallsBaseX]
  1513. add [hl]
  1514. ld [de], a ; X
  1515. inc hl
  1516. inc de
  1517. inc de
  1518. inc de
  1519. dec c
  1520. jr nz, .innerLoop
  1521. ld c, 5
  1522. call DelayFrames
  1523. pop hl
  1524. inc hl
  1525. inc hl
  1526. jr .loop
  1527. .done
  1528. pop hl
  1529. call AnimationCleanOAM
  1530. jp AnimationFlashScreen
  1531. SpiralBallAnimationCoordinates:
  1532. ; y, x pairs
  1533. ; This is the sequence of screen coordinates that the spiralling
  1534. ; balls are positioned at.
  1535. db $38, $28
  1536. db $40, $18
  1537. db $50, $10
  1538. db $60, $18
  1539. db $68, $28
  1540. db $60, $38
  1541. db $50, $40
  1542. db $40, $38
  1543. db $40, $28
  1544. db $46, $1E
  1545. db $50, $18
  1546. db $5B, $1E
  1547. db $60, $28
  1548. db $5B, $32
  1549. db $50, $38
  1550. db $46, $32
  1551. db $48, $28
  1552. db $50, $20
  1553. db $58, $28
  1554. db $50, $30
  1555. db $50, $28
  1556. db $FF ; list terminator
  1557. AnimationSquishMonPic:
  1558. ; Squishes the mon's sprite horizontally making it
  1559. ; disappear. Used by Teleport/Sky Attack animations.
  1560. ld c, 4
  1561. .loop
  1562. push bc
  1563. ld a, [H_WHOSETURN]
  1564. and a
  1565. jr z, .playerTurn
  1566. coord hl, 16, 0
  1567. coord de, 14, 0
  1568. jr .next
  1569. .playerTurn
  1570. coord hl, 5, 5
  1571. coord de, 3, 5
  1572. .next
  1573. push de
  1574. xor a ; left
  1575. ld [wSquishMonCurrentDirection], a
  1576. call _AnimationSquishMonPic
  1577. pop hl
  1578. ld a, 1 ; right
  1579. ld [wSquishMonCurrentDirection], a
  1580. call _AnimationSquishMonPic
  1581. pop bc
  1582. dec c
  1583. jr nz, .loop
  1584. call AnimationHideMonPic
  1585. ld c, 2
  1586. jp DelayFrame
  1587. _AnimationSquishMonPic:
  1588. ld c, 7
  1589. .loop
  1590. push bc
  1591. push hl
  1592. ld c, 3
  1593. ld a, [wSquishMonCurrentDirection]
  1594. cp 0
  1595. jr nz, .right
  1596. call AnimCopyRowLeft
  1597. dec hl
  1598. jr .next
  1599. .right
  1600. call AnimCopyRowRight
  1601. inc hl
  1602. .next
  1603. ld [hl], " "
  1604. pop hl
  1605. ld de, SCREEN_WIDTH
  1606. add hl, de
  1607. pop bc
  1608. dec c
  1609. jr nz, .loop
  1610. jp Delay3
  1611. AnimationShootBallsUpward:
  1612. ; Shoots one pillar of "energy" balls upwards. Used in Teleport/Sky Attack
  1613. ; animations.
  1614. ld a, [H_WHOSETURN]
  1615. and a
  1616. jr z, .playerTurn
  1617. lb bc, 0, 16 * 8
  1618. jr .next
  1619. .playerTurn
  1620. lb bc, 6 * 8, 5 * 8
  1621. .next
  1622. ld a, b
  1623. ld [wBaseCoordY], a
  1624. ld a, c
  1625. ld [wBaseCoordX], a
  1626. lb bc, 5, 1
  1627. call _AnimationShootBallsUpward
  1628. jp AnimationCleanOAM
  1629. _AnimationShootBallsUpward:
  1630. push bc
  1631. xor a
  1632. ld [wWhichBattleAnimTileset], a
  1633. call LoadAnimationTileset
  1634. pop bc
  1635. ld d, $7a ; ball tile
  1636. ld hl, wOAMBuffer
  1637. push bc
  1638. ld a, [wBaseCoordY]
  1639. ld e, a
  1640. .initOAMLoop
  1641. call BattleAnimWriteOAMEntry
  1642. dec b
  1643. jr nz, .initOAMLoop
  1644. call DelayFrame
  1645. pop bc
  1646. ld a, b
  1647. ld [wNumShootingBalls], a
  1648. .loop
  1649. push bc
  1650. ld hl, wOAMBuffer
  1651. .innerLoop
  1652. ld a, [wBaseCoordY]
  1653. add 8
  1654. ld e, a
  1655. ld a, [hl]
  1656. cp e ; has the ball reached the top?
  1657. jr z, .reachedTop
  1658. add -4 ; ball hasn't reached the top. move it up 4 pixels
  1659. ld [hl], a
  1660. jr .next
  1661. .reachedTop
  1662. ; remove the ball once it has reached the top
  1663. ld [hl], 0 ; put it off-screen
  1664. ld a, [wNumShootingBalls]
  1665. dec a
  1666. ld [wNumShootingBalls], a
  1667. .next
  1668. ld de, 4
  1669. add hl, de ; next OAM entry
  1670. dec b
  1671. jr nz, .innerLoop
  1672. call DelayFrames
  1673. pop bc
  1674. ld a, [wNumShootingBalls]
  1675. and a
  1676. jr nz, .loop
  1677. ret
  1678. AnimationShootManyBallsUpward:
  1679. ; Shoots several pillars of "energy" balls upward.
  1680. ld a, [H_WHOSETURN]
  1681. and a
  1682. ld hl, UpwardBallsAnimXCoordinatesPlayerTurn
  1683. ld a, $50 ; y coordinate for "energy" ball pillar
  1684. jr z, .player
  1685. ld hl, UpwardBallsAnimXCoordinatesEnemyTurn
  1686. ld a, $28 ; y coordinate for "energy" ball pillar
  1687. .player
  1688. ld [wSavedY], a
  1689. .loop
  1690. ld a, [wSavedY]
  1691. ld [wBaseCoordY], a
  1692. ld a, [hli]
  1693. cp $ff
  1694. jp z, AnimationCleanOAM
  1695. ld [wBaseCoordX], a
  1696. lb bc, 4, 1
  1697. push hl
  1698. call _AnimationShootBallsUpward
  1699. pop hl
  1700. jr .loop
  1701. UpwardBallsAnimXCoordinatesPlayerTurn:
  1702. ; List of x coordinates for each pillar of "energy" balls in the
  1703. ; AnimationShootManyBallsUpward animation. It's unused in the game.
  1704. db $10, $40, $28, $18, $38, $30
  1705. db $FF ; list terminator
  1706. UpwardBallsAnimXCoordinatesEnemyTurn:
  1707. ; List of x coordinates for each pillar of "energy" balls in the
  1708. ; AnimationShootManyBallsUpward animation. It's unused in the game.
  1709. db $60, $90, $78, $68, $88, $80
  1710. db $FF ; list terminator
  1711. AnimationMinimizeMon:
  1712. ; Changes the mon's sprite to a mini black sprite. Used by the
  1713. ; Minimize animation.
  1714. ld hl, wTempPic
  1715. push hl
  1716. xor a
  1717. ld bc, 7 * 7 * $10
  1718. call FillMemory
  1719. pop hl
  1720. ld de, $194
  1721. add hl, de
  1722. ld de, MinimizedMonSprite
  1723. ld c, MinimizedMonSpriteEnd - MinimizedMonSprite
  1724. .loop
  1725. ld a, [de]
  1726. ld [hli], a
  1727. ld [hli], a
  1728. inc de
  1729. dec c
  1730. jr nz, .loop
  1731. call CopyTempPicToMonPic
  1732. call Delay3
  1733. jp AnimationShowMonPic
  1734. MinimizedMonSprite:
  1735. INCBIN "gfx/minimized_mon_sprite.1bpp"
  1736. MinimizedMonSpriteEnd:
  1737. AnimationSlideMonDownAndHide:
  1738. ; Slides the mon's sprite down and disappears. Used in Acid Armor.
  1739. ld a, $1
  1740. ld c, $2
  1741. .loop
  1742. push bc
  1743. push af
  1744. call AnimationHideMonPic
  1745. pop af
  1746. push af
  1747. call GetTileIDList
  1748. call GetMonSpriteTileMapPointerFromRowCount
  1749. call CopyPicTiles
  1750. ld c, 8
  1751. call DelayFrames
  1752. pop af
  1753. inc a
  1754. pop bc
  1755. dec c
  1756. jr nz, .loop
  1757. call AnimationHideMonPic
  1758. ld hl, wTempPic
  1759. ld bc, $0310
  1760. xor a
  1761. call FillMemory
  1762. jp CopyTempPicToMonPic
  1763. _AnimationSlideMonOff:
  1764. ; Slides the mon's sprite off the screen horizontally by e tiles and waits
  1765. ; [wSlideMonDelay] V-blanks each time the pic is slid by one tile.
  1766. ld a, [H_WHOSETURN]
  1767. and a
  1768. jr z, .playerTurn
  1769. coord hl, 12, 0
  1770. jr .next
  1771. .playerTurn
  1772. coord hl, 0, 5
  1773. .next
  1774. ld d, 8 ; d's value is unused
  1775. .slideLoop ; iterates once for each time the pic slides by one tile
  1776. push hl
  1777. ld b, 7
  1778. .rowLoop ; iterates once for each row
  1779. ld c, 8
  1780. .tileLoop ; iterates once for each tile in the row
  1781. ld a, [H_WHOSETURN]
  1782. and a
  1783. jr z, .playerTurn2
  1784. call .EnemyNextTile
  1785. jr .next2
  1786. .playerTurn2
  1787. call .PlayerNextTile
  1788. .next2
  1789. ld [hli], a
  1790. dec c
  1791. jr nz, .tileLoop
  1792. push de
  1793. ld de, SCREEN_WIDTH - 8
  1794. add hl, de
  1795. pop de
  1796. dec b
  1797. jr nz, .rowLoop
  1798. ld a, [wSlideMonDelay]
  1799. ld c, a
  1800. call DelayFrames
  1801. pop hl
  1802. dec d
  1803. dec e
  1804. jr nz, .slideLoop
  1805. ret
  1806. ; Since mon pic tile numbers go from top to bottom, left to right in order,
  1807. ; adding the height of the mon pic in tiles to a tile number gives the tile
  1808. ; number of the tile one column to the right (and thus subtracting the height
  1809. ; gives the reverse). If the next tile would be past the edge of the pic, the 2
  1810. ; functions below catch it by checking if the tile number is within the valid
  1811. ; range and if not, replacing it with a blank tile.
  1812. .PlayerNextTile
  1813. ld a, [hl]
  1814. add 7
  1815. ; This is a bug. The lower right corner tile of the mon back pic is blanked
  1816. ; while the mon is sliding off the screen. It should compare with the max tile
  1817. ; plus one instead.
  1818. cp $61
  1819. ret c
  1820. ld a, " "
  1821. ret
  1822. .EnemyNextTile
  1823. ld a, [hl]
  1824. sub 7
  1825. ; This has the same problem as above, but it has no visible effect because
  1826. ; the lower right tile is in the first column to slide off the screen.
  1827. cp $30
  1828. ret c
  1829. ld a, " "
  1830. ret
  1831. AnimationSlideMonHalfOff:
  1832. ; Slides the mon's sprite halfway off the screen. It's used in Softboiled.
  1833. ld e, 4
  1834. ld a, 4
  1835. ld [wSlideMonDelay], a
  1836. call _AnimationSlideMonOff
  1837. jp Delay3
  1838. CopyTempPicToMonPic:
  1839. ld a, [H_WHOSETURN]
  1840. and a
  1841. ld hl, vBackPic ; player turn
  1842. jr z, .next
  1843. ld hl, vFrontPic ; enemy turn
  1844. .next
  1845. ld de, wTempPic
  1846. ld bc, 7 * 7
  1847. jp CopyVideoData
  1848. AnimationWavyScreen:
  1849. ; used in Psywave/Psychic etc.
  1850. ld hl, vBGMap0
  1851. call BattleAnimCopyTileMapToVRAM
  1852. call Delay3
  1853. xor a
  1854. ld [H_AUTOBGTRANSFERENABLED], a
  1855. ld a, SCREEN_HEIGHT_PIXELS
  1856. ld [hWY], a
  1857. ld d, $80 ; terminator
  1858. ld e, SCREEN_HEIGHT_PIXELS - 1
  1859. ld c, $ff
  1860. ld hl, WavyScreenLineOffsets
  1861. .loop
  1862. push hl
  1863. .innerLoop
  1864. call WavyScreen_SetSCX
  1865. ld a, [rLY]
  1866. cp e ; is it the last visible line in the frame?
  1867. jr nz, .innerLoop ; keep going if not
  1868. pop hl
  1869. inc hl
  1870. ld a, [hl]
  1871. cp d ; have we reached the end?
  1872. jr nz, .next
  1873. ld hl, WavyScreenLineOffsets ; go back to the beginning if so
  1874. .next
  1875. dec c
  1876. jr nz, .loop
  1877. xor a
  1878. ld [hWY], a
  1879. call SaveScreenTilesToBuffer2
  1880. call ClearScreen
  1881. ld a, 1
  1882. ld [H_AUTOBGTRANSFERENABLED], a
  1883. call Delay3
  1884. call LoadScreenTilesFromBuffer2
  1885. ld hl, vBGMap1
  1886. call BattleAnimCopyTileMapToVRAM
  1887. ret
  1888. WavyScreen_SetSCX:
  1889. ld a, [rSTAT]
  1890. and $3 ; is it H-blank?
  1891. jr nz, WavyScreen_SetSCX ; wait until it's H-blank
  1892. ld a, [hl]
  1893. ld [rSCX], a
  1894. inc hl
  1895. ld a, [hl]
  1896. cp d ; have we reached the end?
  1897. ret nz
  1898. ld hl, WavyScreenLineOffsets ; go back to the beginning if so
  1899. ret
  1900. WavyScreenLineOffsets:
  1901. ; Sequence of horizontal line pixel offsets for the wavy screen animation.
  1902. ; This sequence vaguely resembles a sine wave.
  1903. db 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1
  1904. db 0, 0, 0, 0, 0, -1, -1, -1, -2, -2, -2, -2, -2, -1, -1, -1
  1905. db $80 ; terminator
  1906. AnimationSubstitute:
  1907. ; Changes the pokemon's sprite to the mini sprite
  1908. ld hl, wTempPic
  1909. xor a
  1910. ld bc, $0310
  1911. call FillMemory
  1912. ld a, [H_WHOSETURN]
  1913. and a
  1914. jr z, .playerTurn
  1915. ld hl, SlowbroSprite ; facing down sprite
  1916. ld de, wTempPic + $120
  1917. call CopySlowbroSpriteData
  1918. ld hl, SlowbroSprite + $10
  1919. ld de, wTempPic + $120 + $70
  1920. call CopySlowbroSpriteData
  1921. ld hl, SlowbroSprite + $20
  1922. ld de, wTempPic + $120 + $10
  1923. call CopySlowbroSpriteData
  1924. ld hl, SlowbroSprite + $30
  1925. ld de, wTempPic + $120 + $10 + $70
  1926. call CopySlowbroSpriteData
  1927. jr .next
  1928. .playerTurn
  1929. ld hl, SlowbroSprite + $40 ; facing up sprite
  1930. ld de, wTempPic + $120 + $70
  1931. call CopySlowbroSpriteData
  1932. ld hl, SlowbroSprite + $50
  1933. ld de, wTempPic + $120 + $e0
  1934. call CopySlowbroSpriteData
  1935. ld hl, SlowbroSprite + $60
  1936. ld de, wTempPic + $120 + $80
  1937. call CopySlowbroSpriteData
  1938. ld hl, SlowbroSprite + $70
  1939. ld de, wTempPic + $120 + $f0
  1940. call CopySlowbroSpriteData
  1941. .next
  1942. call CopyTempPicToMonPic
  1943. jp AnimationShowMonPic
  1944. CopySlowbroSpriteData:
  1945. ld bc, $0010
  1946. ld a, BANK(SlowbroSprite)
  1947. jp FarCopyData2
  1948. HideSubstituteShowMonAnim:
  1949. ld a, [H_WHOSETURN]
  1950. and a
  1951. ld hl, wPlayerMonMinimized
  1952. ld a, [wPlayerBattleStatus2]
  1953. jr z, .next1
  1954. ld hl, wEnemyMonMinimized
  1955. ld a, [wEnemyBattleStatus2]
  1956. .next1
  1957. push hl
  1958. ; if the substitute broke, slide it down, else slide it offscreen horizontally
  1959. bit HasSubstituteUp, a
  1960. jr nz, .substituteStillUp
  1961. call AnimationSlideMonDown
  1962. jr .next2
  1963. .substituteStillUp
  1964. call AnimationSlideMonOff
  1965. .next2
  1966. pop hl
  1967. ld a, [hl]
  1968. and a
  1969. jp nz, AnimationMinimizeMon
  1970. call AnimationFlashMonPic
  1971. jp AnimationShowMonPic
  1972. ReshowSubstituteAnim:
  1973. call AnimationSlideMonOff
  1974. call AnimationSubstitute
  1975. jp AnimationShowMonPic
  1976. AnimationBoundUpAndDown:
  1977. ; Bounces the mon's sprite up and down several times. It is used
  1978. ; by Splash's animation.
  1979. ld c, 5
  1980. .loop
  1981. push bc
  1982. call AnimationSlideMonDown
  1983. pop bc
  1984. dec c
  1985. jr nz, .loop
  1986. jp AnimationShowMonPic
  1987. AnimationTransformMon:
  1988. ; Redraws this mon's sprite as the back/front sprite of the opposing mon.
  1989. ; Used in Transform.
  1990. ld a, [wEnemyMonSpecies]
  1991. ld [wChangeMonPicPlayerTurnSpecies], a
  1992. ld a, [wBattleMonSpecies]
  1993. ld [wChangeMonPicEnemyTurnSpecies], a
  1994. ChangeMonPic:
  1995. ld a, [H_WHOSETURN]
  1996. and a
  1997. jr z, .playerTurn
  1998. ld a, [wChangeMonPicEnemyTurnSpecies]
  1999. ld [wcf91], a
  2000. ld [wd0b5], a
  2001. xor a
  2002. ld [wSpriteFlipped], a
  2003. call GetMonHeader
  2004. coord hl, 12, 0
  2005. call LoadFrontSpriteByMonIndex
  2006. jr .done
  2007. .playerTurn
  2008. ld a, [wBattleMonSpecies2]
  2009. push af
  2010. ld a, [wChangeMonPicPlayerTurnSpecies]
  2011. ld [wBattleMonSpecies2], a
  2012. ld [wd0b5], a
  2013. call GetMonHeader
  2014. predef LoadMonBackPic
  2015. xor a
  2016. call GetTileIDList
  2017. call GetMonSpriteTileMapPointerFromRowCount
  2018. call CopyPicTiles
  2019. pop af
  2020. ld [wBattleMonSpecies2], a
  2021. .done
  2022. ld b, SET_PAL_BATTLE
  2023. jp RunPaletteCommand
  2024. AnimationHideEnemyMonPic:
  2025. ; Hides the enemy mon's sprite
  2026. xor a
  2027. ld [H_AUTOBGTRANSFERENABLED], a
  2028. ld hl, AnimationHideMonPic
  2029. call CallWithTurnFlipped
  2030. ld a, $1
  2031. ld [H_AUTOBGTRANSFERENABLED], a
  2032. jp Delay3
  2033. InitMultipleObjectsOAM:
  2034. ; Writes c OAM entries with tile d.
  2035. ; Sets their Y coordinates to sequential multiples of 8, starting from 0.
  2036. ; Sets their X coordinates to 0.
  2037. ; Loads animation tileset a.
  2038. push bc
  2039. push de
  2040. ld [wWhichBattleAnimTileset], a
  2041. call LoadAnimationTileset
  2042. pop de
  2043. pop bc
  2044. xor a
  2045. ld e, a
  2046. ld [wBaseCoordX], a
  2047. ld hl, wOAMBuffer
  2048. .loop
  2049. call BattleAnimWriteOAMEntry
  2050. dec c
  2051. jr nz, .loop
  2052. ret
  2053. AnimationHideMonPic:
  2054. ; Hides the mon's sprite.
  2055. ld a, [H_WHOSETURN]
  2056. and a
  2057. jr z, .playerTurn
  2058. ld a, 12
  2059. jr ClearMonPicFromTileMap
  2060. .playerTurn
  2061. ld a, 5 * SCREEN_WIDTH + 1
  2062. ClearMonPicFromTileMap:
  2063. push hl
  2064. push de
  2065. push bc
  2066. ld e, a
  2067. ld d, 0
  2068. coord hl, 0, 0
  2069. add hl, de
  2070. lb bc, 7, 7
  2071. call ClearScreenArea
  2072. pop bc
  2073. pop de
  2074. pop hl
  2075. ret
  2076. ; puts the tile map destination address of a mon sprite in hl, given the row count in b
  2077. ; The usual row count is 7, but it may be smaller when sliding a mon sprite in/out,
  2078. ; in order to show only a portion of the mon sprite.
  2079. GetMonSpriteTileMapPointerFromRowCount:
  2080. push de
  2081. ld a, [H_WHOSETURN]
  2082. and a
  2083. jr nz, .enemyTurn
  2084. ld a, 20 * 5 + 1
  2085. jr .next
  2086. .enemyTurn
  2087. ld a, 12
  2088. .next
  2089. coord hl, 0, 0
  2090. ld e, a
  2091. ld d, 0
  2092. add hl, de
  2093. ld a, 7
  2094. sub b
  2095. and a
  2096. jr z, .done
  2097. ld de, 20
  2098. .loop
  2099. add hl, de
  2100. dec a
  2101. jr nz, .loop
  2102. .done
  2103. pop de
  2104. ret
  2105. ; Input:
  2106. ; a = tile ID list index
  2107. ; Output:
  2108. ; de = tile ID list pointer
  2109. ; b = number of rows
  2110. ; c = number of columns
  2111. GetTileIDList:
  2112. ld hl, TileIDListPointerTable
  2113. ld e, a
  2114. ld d, 0
  2115. add hl, de
  2116. add hl, de
  2117. add hl, de
  2118. ld a, [hli]
  2119. ld e, a
  2120. ld a, [hli]
  2121. ld d, a
  2122. ld a, [hli]
  2123. ld b, a
  2124. and $f
  2125. ld c, a
  2126. ld a, b
  2127. swap a
  2128. and $f
  2129. ld b, a
  2130. ret
  2131. AnimCopyRowLeft:
  2132. ; copy a row of c tiles 1 tile left
  2133. ld a, [hld]
  2134. ld [hli], a
  2135. inc hl
  2136. dec c
  2137. jr nz, AnimCopyRowLeft
  2138. ret
  2139. AnimCopyRowRight:
  2140. ; copy a row of c tiles 1 tile right
  2141. ld a, [hli]
  2142. ld [hld], a
  2143. dec hl
  2144. dec c
  2145. jr nz, AnimCopyRowRight
  2146. ret
  2147. ; get the sound of the move id in b
  2148. GetMoveSoundB:
  2149. ld a, b
  2150. call GetMoveSound
  2151. ld b, a
  2152. ret
  2153. GetMoveSound:
  2154. ld hl,MoveSoundTable
  2155. ld e,a
  2156. ld d,0
  2157. add hl,de
  2158. add hl,de
  2159. add hl,de
  2160. ld a,[hli]
  2161. ld b,a
  2162. call IsCryMove
  2163. jr nc,.NotCryMove
  2164. ld a,[H_WHOSETURN]
  2165. and a
  2166. jr nz,.next
  2167. ld a,[wBattleMonSpecies] ; get number of current monster
  2168. jr .Continue
  2169. .next
  2170. ld a,[wEnemyMonSpecies]
  2171. .Continue
  2172. push hl
  2173. call GetCryData
  2174. ld b,a
  2175. pop hl
  2176. ld a,[wFrequencyModifier]
  2177. add [hl]
  2178. ld [wFrequencyModifier],a
  2179. inc hl
  2180. ld a,[wTempoModifier]
  2181. add [hl]
  2182. ld [wTempoModifier],a
  2183. jr .done
  2184. .NotCryMove
  2185. ld a,[hli]
  2186. ld [wFrequencyModifier],a
  2187. ld a,[hli]
  2188. ld [wTempoModifier],a
  2189. .done
  2190. ld a,b
  2191. ret
  2192. IsCryMove:
  2193. ; set carry if the move animation involves playing a monster cry
  2194. ld a,[wAnimationID]
  2195. cp a,GROWL
  2196. jr z,.CryMove
  2197. cp a,ROAR
  2198. jr z,.CryMove
  2199. and a ; clear carry
  2200. ret
  2201. .CryMove
  2202. scf
  2203. ret
  2204. MoveSoundTable:
  2205. ; ID, pitch mod, tempo mod
  2206. db SFX_POUND, $00,$80 ; POUND
  2207. db SFX_BATTLE_0C, $10,$80 ; KARATE_CHOP
  2208. db SFX_DOUBLESLAP, $00,$80 ; DOUBLESLAP
  2209. db SFX_BATTLE_0B, $01,$80 ; COMET_PUNCH
  2210. db SFX_BATTLE_0D, $00,$40 ; MEGA_PUNCH
  2211. db SFX_SILPH_SCOPE, $00,$ff ; PAY_DAY
  2212. db SFX_BATTLE_0D, $10,$60 ; FIRE_PUNCH
  2213. db SFX_BATTLE_0D, $20,$80 ; ICE_PUNCH
  2214. db SFX_BATTLE_0D, $00,$a0 ; THUNDERPUNCH
  2215. db SFX_DAMAGE, $00,$80 ; SCRATCH
  2216. db SFX_BATTLE_0F, $20,$40 ; VICEGRIP
  2217. db SFX_BATTLE_0F, $00,$80 ; GUILLOTINE
  2218. db SFX_BATTLE_0E, $00,$a0 ; RAZOR_WIND
  2219. db SFX_NOT_VERY_EFFECTIVE,$10,$c0 ; SWORDS_DANCE
  2220. db SFX_NOT_VERY_EFFECTIVE,$00,$a0 ; CUT
  2221. db SFX_BATTLE_12, $00,$c0 ; GUST
  2222. db SFX_BATTLE_12, $10,$a0 ; WING_ATTACK
  2223. db SFX_BATTLE_13, $00,$e0 ; WHIRLWIND
  2224. db SFX_NOT_VERY_EFFECTIVE,$20,$c0 ; FLY
  2225. db SFX_BATTLE_14, $00,$80 ; BIND
  2226. db SFX_BATTLE_22, $00,$80 ; SLAM
  2227. db SFX_VINE_WHIP, $01,$80 ; VINE_WHIP
  2228. db SFX_BATTLE_20, $00,$80 ; STOMP
  2229. db SFX_BATTLE_17, $f0,$40 ; DOUBLE_KICK
  2230. db SFX_SUPER_EFFECTIVE, $00,$80 ; MEGA_KICK
  2231. db SFX_BATTLE_17, $00,$80 ; JUMP_KICK
  2232. db SFX_BATTLE_21, $10,$80 ; ROLLING_KICK
  2233. db SFX_BATTLE_1B, $01,$a0 ; SAND_ATTACK
  2234. db SFX_BATTLE_18, $00,$80 ; HEADBUTT
  2235. db SFX_BATTLE_1E, $00,$60 ; HORN_ATTACK
  2236. db SFX_BATTLE_1E, $01,$40 ; FURY_ATTACK
  2237. db SFX_HORN_DRILL, $00,$a0 ; HORN_DRILL
  2238. db SFX_SUPER_EFFECTIVE, $10,$a0 ; TACKLE
  2239. db SFX_BATTLE_20, $00,$c0 ; BODY_SLAM
  2240. db SFX_BATTLE_14, $10,$60 ; WRAP
  2241. db SFX_SUPER_EFFECTIVE, $00,$a0 ; TAKE_DOWN
  2242. db SFX_BATTLE_22, $11,$c0 ; THRASH
  2243. db SFX_SUPER_EFFECTIVE, $20,$c0 ; DOUBLE_EDGE
  2244. db SFX_BATTLE_21, $00,$80 ; TAIL_WHIP
  2245. db SFX_BATTLE_1B, $00,$80 ; POISON_STING
  2246. db SFX_BATTLE_1B, $20,$c0 ; TWINEEDLE
  2247. db SFX_BATTLE_19, $00,$80 ; PIN_MISSILE
  2248. db SFX_BATTLE_31, $ff,$40 ; LEER
  2249. db SFX_BATTLE_1E, $00,$80 ; BITE
  2250. db SFX_BATTLE_0B, $00,$c0 ; GROWL
  2251. db SFX_BATTLE_0B, $00,$40 ; ROAR
  2252. db SFX_BATTLE_35, $00,$80 ; SING
  2253. db SFX_BATTLE_27, $40,$60 ; SUPERSONIC
  2254. db SFX_BATTLE_27, $00,$80 ; SONICBOOM
  2255. db SFX_BATTLE_27, $ff,$40 ; DISABLE
  2256. db SFX_BATTLE_2A, $80,$c0 ; ACID
  2257. db SFX_BATTLE_19, $10,$a0 ; EMBER
  2258. db SFX_BATTLE_19, $21,$e0 ; FLAMETHROWER
  2259. db SFX_BATTLE_29, $00,$80 ; MIST
  2260. db SFX_BATTLE_24, $20,$60 ; WATER_GUN
  2261. db SFX_BATTLE_2A, $00,$80 ; HYDRO_PUMP
  2262. db SFX_BATTLE_2C, $00,$80 ; SURF
  2263. db SFX_BATTLE_28, $40,$80 ; ICE_BEAM
  2264. db SFX_BATTLE_29, $f0,$e0 ; BLIZZARD
  2265. db SFX_PSYBEAM, $00,$80 ; PSYBEAM
  2266. db SFX_BATTLE_2A, $f0,$60 ; BUBBLEBEAM
  2267. db SFX_BATTLE_28, $00,$80 ; AURORA_BEAM
  2268. db SFX_BATTLE_36, $00,$80 ; HYPER_BEAM
  2269. db SFX_PECK,$01, $a0 ; PECK
  2270. db SFX_BATTLE_13, $f0,$20 ; DRILL_PECK
  2271. db SFX_BATTLE_23, $01,$c0 ; SUBMISSION
  2272. db SFX_BATTLE_23, $00,$80 ; LOW_KICK
  2273. db SFX_SUPER_EFFECTIVE, $00,$e0 ; COUNTER
  2274. db SFX_BATTLE_26, $01,$60 ; SEISMIC_TOSS
  2275. db SFX_BATTLE_26, $20,$40 ; STRENGTH
  2276. db SFX_BATTLE_24, $00,$80 ; ABSORB
  2277. db SFX_BATTLE_24, $40,$c0 ; MEGA_DRAIN
  2278. db SFX_BATTLE_1B, $03,$60 ; LEECH_SEED
  2279. db SFX_BATTLE_25, $11,$e0 ; GROWTH
  2280. db SFX_BATTLE_12, $20,$e0 ; RAZOR_LEAF
  2281. db SFX_BATTLE_2E, $00,$80 ; SOLARBEAM
  2282. db SFX_BATTLE_1C, $00,$80 ; POISONPOWDER
  2283. db SFX_BATTLE_1C, $11,$a0 ; STUN_SPORE
  2284. db SFX_BATTLE_1C, $01,$c0 ; SLEEP_POWDER
  2285. db SFX_BATTLE_13, $14,$c0 ; PETAL_DANCE
  2286. db SFX_BATTLE_1B, $02,$a0 ; STRING_SHOT
  2287. db SFX_BATTLE_29, $f0,$80 ; DRAGON_RAGE
  2288. db SFX_BATTLE_29, $20,$c0 ; FIRE_SPIN
  2289. db SFX_BATTLE_2F, $00,$20 ; THUNDERSHOCK
  2290. db SFX_BATTLE_2F, $20,$80 ; THUNDERBOLT
  2291. db SFX_BATTLE_2E, $12,$60 ; THUNDER_WAVE
  2292. db SF