Advertisement
Guest User

Untitled

a guest
Aug 15th, 2011
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.72 KB | None | 0 0
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;; Shy Guy, by mikeyk
  3. ;;
  4. ;; Description: A Shy Guy with many available configurations.
  5. ;;
  6. ;; Note: When rideable, clipping tables values should be: 03 0A FE 0E
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8. ;; Uses first extra bit: NO
  9. ;;
  10. ;; Extra Property Byte 1
  11. ;; bit 0 - move fast
  12. ;; bit 1 - stay on ledges
  13. ;; bit 2 - follow mario
  14. ;; bit 3 - jump over shells
  15. ;; bit 4 - enable spin killing (if rideable)
  16. ;; bit 5 - can be carried (if rideable)
  17. ;;
  18. ;; Extra Property Byte 2
  19. ;; bit 0 - use turning image
  20. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  21.  
  22. UpdateSpritePos = $01802A
  23. SprSprInteract = $018032
  24. MarioSprInteract = $01A7DC
  25. GetSpriteClippingA = $03B69F
  26. CheckForContact = $03B72B
  27. DisplayContactGfx = $01AB99
  28. FinishOAMWrite = $01B7B3
  29. ShowSpinJumpStars = $07FC3B
  30. GivePoints = $02ACE5
  31. HurtMario = $00F5B7
  32.  
  33. ExtraProperty1 = $7FAB28
  34. ExtraProperty2 = $7FAB34
  35. RAM_SpriteDir = $157C
  36. RAM_SprTurnTimer = $15AC
  37.  
  38. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  39. ; sprite init JSL
  40. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  41.  
  42. dcb "INIT"
  43. LDA $167A,x
  44. STA $1528,x
  45.  
  46. LDA #$01
  47. STA $151C,x
  48.  
  49. JSR SubHorzPos ; Face Mario
  50. TYA
  51. STA $157C,x
  52. RTL
  53.  
  54. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  55. ; sprite code JSL
  56. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  57.  
  58. dcb "MAIN"
  59. PHB
  60. PHK
  61. PLB
  62. CMP #09
  63. BCS HandleStunnd
  64. JSR SpriteMainSub
  65. PLB
  66. RTL
  67.  
  68. HandleStunnd:
  69. LDA #$2C ; Play sound effect
  70. STA $1DF9
  71. LDA $167A,x ; Set to interact with Mario
  72. AND #$7F
  73. STA $167A,x
  74.  
  75. LDY $15EA,X ; Replace Goomba's tile
  76. PHX
  77. LDX Tilemap
  78. LDA $302,Y
  79. CMP #$A8
  80. BEQ SetTile
  81. LDX Tilemap+1
  82. SetTile:
  83. TXA
  84. STA $302,Y
  85. PLX
  86. PLB
  87. RTL
  88.  
  89. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  90. ; sprite main code
  91. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  92.  
  93. SpeedX:
  94. dcb $08,$F8,$0C,$F4
  95. KILLED_X_SPEED
  96. dcb $F0,$10
  97.  
  98. Return:
  99. RTS
  100. SpriteMainSub:
  101. JSR SubGfx
  102.  
  103. LDA $9D ; \ if sprites locked, return
  104. BNE Return ; /
  105. LDA $14C8,x
  106. CMP #$08
  107. BNE Return
  108.  
  109. JSR SubOffScreen ; handle off screen situation
  110. INC $1570,x
  111.  
  112. LDY $157C,x ; Set x speed based on direction
  113. LDA ExtraProperty1,x
  114. AND #$01
  115. BEQ NoFastSpeed ; Increase speed if bit 0 is set
  116. INY
  117. INY
  118. NoFastSpeed:
  119. LDA SpeedX,y
  120. STA $B6,x
  121.  
  122. JSL UpdateSpritePos ; Update position based on speed values
  123.  
  124. LDA $1588,x ; If sprite is in contact with an object...
  125. AND #$03
  126. BEQ NoObjContact
  127. JSR SetSpriteTurning ; ...change direction
  128. NoObjContact:
  129.  
  130. JSR MaybeStayOnLedges
  131.  
  132. LDA $1588,x ; if on the ground, reset the turn counter
  133. AND #$04
  134. BEQ NotOnGround
  135. STZ $AA,x
  136. STZ $151C,x ; Reset turning flag (used if sprite stays on ledges)
  137. JSR MaybeFaceMario
  138. JSR MaybeJumpShells
  139. NotOnGround:
  140.  
  141. LDA $1528,x
  142. STA $167A,x
  143.  
  144. JSL SprSprInteract ; Interact with other sprites
  145. JSL MarioSprInteract ; Check for mario/sprite contact (carry set = contact)
  146. BCC Return1 ; return if no contact
  147.  
  148. JSR SubVertPos ; \
  149. LDA $0E ; | if mario isn't above sprite, and there's vertical contact...
  150. CMP #$E6 ; | ... sprite wins
  151. BPL SpriteWins ; /
  152. LDA $7D ; \ if mario speed is upward, return
  153. BMI Return1 ; /
  154.  
  155. LDA ExtraProperty1,x ; Check property byte to see if sprite can be spin jumped
  156. AND #$10
  157. BEQ SpinKillDisabled
  158. LDA $140D ; Branch if mario is spin jumping
  159. BNE SpinKill
  160. SpinKillDisabled:
  161.  
  162. LDA $187A
  163. BNE RideSprite
  164. LDA ExtraProperty1,x
  165. AND #$20
  166. BEQ RideSprite
  167. BIT $16 ; Don't pick up sprite if not pressing button
  168. BVC RideSprite
  169. LDA #$0B ; Sprite status = Carried
  170. STA $14C8,x
  171. LDA #$FF ; Set time until recovery
  172. STA $1540,x
  173. RTS
  174.  
  175. RideSprite:
  176. LDA #$01 ; \ set "on sprite" flag
  177. STA $1471 ; /
  178. LDA #$06 ; Disable interactions for a few frames
  179. STA $154C,x
  180. STZ $7D ; Y speed = 0
  181. LDA #$E1 ; \
  182. LDY $187A ; | mario's y position += E1 or D1 depending if on yoshi
  183. BEQ NO_YOSHI ; |
  184. LDA #$D1 ; |
  185. NO_YOSHI:
  186. CLC ; |
  187. ADC $D8,x ; |
  188. STA $96 ; |
  189. LDA $14D4,x ; |
  190. ADC #$FF ; |
  191. STA $97 ; /
  192. LDY #$00 ; \
  193. LDA $1491 ; | $1491 == 01 or FF, depending on direction
  194. BPL LABEL9 ; | set mario's new x position
  195. DEY ; |
  196. LABEL9:
  197. CLC ; |
  198. ADC $94 ; |
  199. STA $94 ; |
  200. TYA ; |
  201. ADC $95 ; |
  202. STA $95 ; /
  203. RTS
  204.  
  205. SpriteWins:
  206. LDA $154C,x ; \ if disable interaction set...
  207. ORA $15D0,x ; | ...or sprite being eaten...
  208. BNE Return1 ; / ...return
  209. LDA $1490 ; Branch if Mario has a star
  210. BNE MarioHasStar
  211. JSL HurtMario
  212. Return1:
  213. RTS
  214.  
  215. SpinKill:
  216. JSR SUB_STOMP_PTS ; give mario points
  217. LDA #$F8 ; Set Mario Y speed
  218. STA $7D
  219. JSL DisplayContactGfx ; display contact graphic
  220. LDA #$04 ; \ status = 4 (being killed by spin jump)
  221. STA $14C8,x ; /
  222. LDA #$1F ; \ set spin jump animation timer
  223. STA $1540,x ; /
  224. JSL ShowSpinJumpStars
  225. LDA #$08 ; \ play sound effect
  226. STA $1DF9 ; /
  227. RTS ; return
  228.  
  229. MarioHasStar:
  230. LDA #$02 ; \ status = 2 (being killed by star)
  231. STA $14C8,x ; /
  232. LDA #$D0 ; \ set y speed
  233. STA $AA,x ; /
  234. JSR SubHorzPos ; get new direction
  235. LDA KILLED_X_SPEED,y ; \ set x speed based on direction
  236. STA $B6,x ; /
  237. INC $18D2 ; increment number consecutive enemies killed
  238. LDA $18D2 ; \
  239. CMP #$08 ; | if consecutive enemies stomped >= 8, reset to 8
  240. BCC NoReset ; |
  241. LDA #$08 ; |
  242. STA $18D2 ; /
  243. NoReset:
  244. JSL GivePoints
  245. LDY $18D2 ; \
  246. CPY #$08 ; | if consecutive enemies stomped < 8 ...
  247. BCS NO_SOUND2 ; |
  248. LDA STAR_SOUNDS,y ; | ... play sound effect
  249. STA $1DF9 ; /
  250. NO_SOUND2:
  251. RTS ; final return
  252.  
  253. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  254. ;;
  255. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  256.  
  257. MaybeStayOnLedges:
  258. LDA ExtraProperty1,x ; Stay on ledges if bit 1 is set
  259. AND #$02
  260. BEQ NoFlipDirection
  261. LDA $1588,x ; If the sprite is in the air
  262. ORA $151C,x ; and not already turning
  263. BNE NoFlipDirection
  264. JSR SetSpriteTurning ; flip direction
  265. LDA #$01 ; set turning flag
  266. STA $151C,x
  267. NoFlipDirection:
  268. RTS
  269.  
  270. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  271. ;;
  272. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  273.  
  274. MaybeFaceMario:
  275. LDA ExtraProperty1,x ; Face Mario if bit 2 is set
  276. AND #$04
  277. BEQ Return4
  278. LDA $1570,x
  279. AND #$7F
  280. BNE Return4
  281. LDA RAM_SpriteDir,x
  282. PHA
  283.  
  284. JSR SubHorzPos ; Face Mario
  285. TYA
  286. STA RAM_SpriteDir,X
  287.  
  288. PLA
  289. CMP RAM_SpriteDir,x
  290. BEQ Return4
  291. LDA #$08
  292. STA RAM_SprTurnTimer,x
  293. Return4:
  294. RTS
  295.  
  296. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  297. ;;
  298. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  299.  
  300. MaybeJumpShells:
  301. LDA ExtraProperty1,x ; Face Mario if bit 3 is set
  302. AND #$08
  303. BEQ Return4
  304. TXA ; \ Process every 4 frames
  305. EOR $13 ; |
  306. AND #$03 ; |
  307. BNE Return0188AB ; /
  308. LDY #$09 ; \ Loop over sprites:
  309. JumpLoopStart:
  310. LDA $14C8,Y ; |
  311. CMP #$0A ; | If sprite status = kicked, try to jump it
  312. BEQ HandleJumpOver ; |
  313. JumpLoopNext:
  314. DEY ; |
  315. BPL JumpLoopStart ; /
  316. Return0188AB:
  317. RTS ; Return
  318.  
  319. HandleJumpOver:
  320. LDA $00E4,Y
  321. SEC
  322. SBC #$1A
  323. STA $00
  324. LDA $14E0,Y
  325. SBC #$00
  326. STA $08
  327. LDA #$44
  328. STA $02
  329. LDA $00D8,Y
  330. STA $01
  331. LDA $14D4,Y
  332. STA $09
  333. LDA #$10
  334. STA $03
  335. JSL GetSpriteClippingA
  336. JSL CheckForContact
  337. BCC JumpLoopNext ; If not close to shell, go back to main loop
  338. LDA $1588,x ; \ If sprite not on ground, go back to main loop
  339. AND #$04 ; |
  340. BEQ JumpLoopNext ; /
  341. LDA $157C,Y ; \ If sprite not facing shell, don't jump
  342. CMP $157C,X ; |
  343. BEQ Return0188EB ; /
  344. LDA #$C0 ; \ Finally set jump speed
  345. STA $AA,X ; /
  346. Return0188EB:
  347. RTS ; Return
  348.  
  349. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  350. ;;
  351. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  352.  
  353. SetSpriteTurning:
  354. LDA #$08 ; Set turning timer
  355. STA RAM_SprTurnTimer,X
  356. LDA $157C,x
  357. EOR #$01
  358. STA $157C,x
  359. Return0190B1:
  360. RTS
  361.  
  362. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  363. ; sprite graphics routine
  364. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  365.  
  366. Tilemap:
  367. dcb $A8,$AA,$A8,$AA ; Walking 1, Walking 2, Killed, Turning
  368.  
  369. SubGfx:
  370. JSR GetDrawInfo
  371.  
  372. LDA $157C,x ; $02 = direction
  373. STA $02
  374.  
  375. LDA $14C8,x ; If killed...
  376. CMP #$02
  377. BNE NotKilled
  378. LDA #$02 ; ...set killed frame
  379. STA $03
  380. LDA $15F6,x ; ...flip vertically
  381. ORA #$80
  382. STA $15F6,x
  383. BRA DrawSprite
  384. NotKilled:
  385.  
  386. LDA ExtraProperty2,x
  387. AND #$01
  388. BEQ NotTurning
  389. LDA RAM_SprTurnTimer,x ; If turning...
  390. BEQ NotTurning
  391. LDA #$03 ; ...set turning frame
  392. STA $03
  393. BRA DrawSprite
  394. NotTurning:
  395.  
  396. LDA $14 ; Set walking frame based on frame counter
  397. LSR A
  398. LSR A
  399. LSR A
  400. CLC
  401. ADC $15E9
  402. AND #$01
  403. STA $03
  404.  
  405. DrawSprite:
  406. PHX
  407. LDA $00 ; Tile x position = sprite x location ($00)
  408. STA $0300,y
  409.  
  410. LDA $01 ; Tile y position = sprite y location ($01)
  411. STA $0301,y
  412.  
  413. LDA $15F6,x ; Yile properties xyppccct, format
  414. LDX $02 ; If direction == 0...
  415. BNE NoFlip
  416. ORA #$40 ; ...flip tile
  417. NoFlip:
  418. ORA $64 ; Add in tile priority of level
  419. STA $0303,y
  420.  
  421. LDX $03 ; Store tile
  422. LDA Tilemap,x
  423. STA $0302,y
  424. PLX
  425.  
  426. LDY #$02 ; Set tiles to 16x16
  427. LDA #$00 ; We drew 1 tile
  428. JSL FinishOAMWrite
  429. RTS
  430.  
  431.  
  432. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  433. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  434. ; routines below can be shared by all sprites. they are ripped from SMW
  435. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  436. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  437.  
  438. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  439. ; points routine
  440. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  441.  
  442. STAR_SOUNDS
  443. dcb $00,$13,$14,$15,$16,$17,$18,$19
  444.  
  445. SUB_STOMP_PTS:
  446. PHY
  447. LDA $1697 ; \
  448. CLC ; |
  449. ADC $1626,x ; / some enemies give higher pts/1ups quicker??
  450. INC $1697 ; increase consecutive enemies stomped
  451. TAY ;
  452. INY ;
  453. CPY #$08 ; \ if consecutive enemies stomped >= 8 ...
  454. BCS NO_SOUND ; / ... don't play sound
  455. LDA STAR_SOUNDS,y ; \ play sound effect
  456. STA $1DF9 ; /
  457. NO_SOUND:
  458. TYA ; \
  459. CMP #$08 ; | if consecutive enemies stomped >= 8, reset to 8
  460. BCC NO_RESET ; |
  461. LDA #$08 ; /
  462. NO_RESET:
  463. JSL GivePoints
  464. PLY
  465. RTS ; return
  466.  
  467. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  468. ; This routine determines if Mario is above or below the sprite. It sets the Y register
  469. ; to the direction such that the sprite would face Mario
  470. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  471.  
  472. SubVertPos:
  473. LDY #$00
  474. LDA $96
  475. SEC
  476. SBC $D8,x
  477. STA $0F
  478. LDA $97
  479. SBC $14D4,x
  480. BPL VertIncY
  481. INY
  482. VertIncY:
  483. RTS
  484.  
  485. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  486. ; This routine determines which side of the sprite Mario is on. It sets the Y register
  487. ; to the direction such that the sprite would face Mario
  488. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  489.  
  490. SubHorzPos:
  491. LDY #$00
  492. LDA $94
  493. SEC
  494. SBC $E4,x
  495. STA $0F
  496. LDA $95
  497. SBC $14E0,x
  498. BPL HorzIncY
  499. INY
  500. HorzIncY:
  501. RTS
  502.  
  503.  
  504. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  505. ; GET_DRAW_INFO
  506. ; This is a helper for the graphics routine. It sets off screen flags, and sets up
  507. ; variables. It will return with the following:
  508. ;
  509. ; Y = index to sprite OAM ($300)
  510. ; $00 = sprite x position relative to screen boarder
  511. ; $01 = sprite y position relative to screen boarder
  512. ;
  513. ; It is adapted from the subroutine at $03B760
  514. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  515.  
  516. DATA_03B75C:
  517. dcb $0C,$1C
  518. DATA_03B75E:
  519. dcb $01,$02
  520.  
  521. GetDrawInfo:
  522. STZ $186C,X ; Reset sprite offscreen flag, vertical
  523. STZ $15A0,X ; Reset sprite offscreen flag, horizontal
  524. LDA $E4,X ; \
  525. CMP $1A ; | Set horizontal offscreen if necessary
  526. LDA $14E0,X ; |
  527. SBC $1B ; |
  528. BEQ ADDR_03B774 ; |
  529. INC $15A0,X ; /
  530. ADDR_03B774:
  531. LDA $14E0,X ; \
  532. XBA ; | Mark sprite invalid if far enough off screen
  533. LDA $E4,X ; |
  534. REP #$20 ; Accum (16 bit)
  535. SEC ; |
  536. SBC $1A ; |
  537. CLC ; |
  538. ADC.W #$0040 ; |
  539. CMP.W #$0180 ; |
  540. SEP #$20 ; Accum (8 bit)
  541. ROL ; |
  542. AND.B #$01 ; |
  543. STA $15C4,X ; |
  544. BNE ADDR_03B7CF ; /
  545. LDY.B #$00 ; \ set up loop:
  546. LDA $1662,X ; |
  547. AND.B #$20 ; | if not smushed (1662 & 0x20), go through loop twice
  548. BEQ ADDR_03B79A ; | else, go through loop once
  549. INY ; /
  550. ADDR_03B79A:
  551. LDA $D8,X ; \
  552. CLC ; | set vertical offscree
  553. ADC DATA_03B75C,Y ; |
  554. PHP ; |
  555. CMP $1C ; | (vert screen boundry)
  556. ROL $00 ; |
  557. PLP ; |
  558. LDA $14D4,X ; |
  559. ADC.B #$00 ; |
  560. LSR $00 ; |
  561. SBC $1D ; |
  562. BEQ ADDR_03B7BA ; |
  563. LDA $186C,X ; | (vert offscreen)
  564. ORA DATA_03B75E,Y ; |
  565. STA $186C,X ; |
  566. ADDR_03B7BA:
  567. DEY ; |
  568. BPL ADDR_03B79A ; /
  569. LDY $15EA,X ; get offset to sprite OAM
  570. LDA $E4,X ; \
  571. SEC ; |
  572. SBC $1A ; |
  573. STA $00 ; / $00 = sprite x position relative to screen boarder
  574. LDA $D8,X ; \
  575. SEC ; |
  576. SBC $1C ; |
  577. STA $01 ; / $01 = sprite y position relative to screen boarder
  578. RTS ; Return
  579.  
  580. ADDR_03B7CF:
  581. PLA ; \ Return from *main gfx routine* subroutine...
  582. PLA ; | ...(not just this subroutine)
  583. RTS ; /
  584.  
  585.  
  586. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  587. ; SUB_OFF_SCREEN
  588. ; This subroutine deals with sprites that have moved off screen
  589. ; It is adapted from the subroutine at $01AC0D
  590. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  591.  
  592. DATA_01AC0D:
  593. dcb $40,$B0
  594. DATA_01AC0F:
  595. dcb $01,$FF
  596. DATA_01AC11:
  597. dcb $30,$C0
  598. DATA_01AC19:
  599. dcb $01,$FF
  600.  
  601. SubOffScreen:
  602. JSR IsSprOnScreen ; \ if sprite is not off screen, return
  603. BEQ Return01ACA4 ; /
  604. LDA $5B ; \ vertical level
  605. AND #$01 ; |
  606. BNE VerticalLevel ; /
  607. LDA $D8,X ; \
  608. CLC ; |
  609. ADC #$50 ; | if the sprite has gone off the bottom of the level...
  610. LDA $14D4,X ; | (if adding 0x50 to the sprite y position would make the high byte >= 2)
  611. ADC #$00 ; |
  612. CMP #$02 ; |
  613. BPL OffScrEraseSprite ; / ...erase the sprite
  614. LDA $167A,X ; \ if "process offscreen" flag is set, return
  615. AND #$04 ; |
  616. BNE Return01ACA4 ; /
  617. LDA $13
  618. AND #$01
  619. STA $01
  620. TAY
  621. LDA $1A
  622. CLC
  623. ADC DATA_01AC11,Y
  624. ROL $00
  625. CMP $E4,X
  626. PHP
  627. LDA $1B
  628. LSR $00
  629. ADC DATA_01AC19,Y
  630. PLP
  631. SBC $14E0,X
  632. STA $00
  633. LSR $01
  634. BCC ADDR_01AC7C
  635. EOR #$80
  636. STA $00
  637. ADDR_01AC7C:
  638. LDA $00
  639. BPL Return01ACA4
  640. OffScrEraseSprite:
  641. LDA $14C8,X ; \ If sprite status < 8, permanently erase sprite
  642. CMP #$08 ; |
  643. BCC OffScrKillSprite ; /
  644. LDY $161A,X
  645. CPY #$FF
  646. BEQ OffScrKillSprite
  647. LDA #$00
  648. STA $1938,Y
  649. OffScrKillSprite:
  650. STZ $14C8,X ; Erase sprite
  651. Return01ACA4:
  652. RTS
  653.  
  654. VerticalLevel:
  655. LDA $167A,X ; \ If "process offscreen" flag is set, return
  656. AND #$04 ; |
  657. BNE Return01ACA4 ; /
  658. LDA $13 ; \
  659. LSR ; |
  660. BCS Return01ACA4 ; /
  661. LDA $E4,X ; \
  662. CMP #$00 ; | If the sprite has gone off the side of the level...
  663. LDA $14E0,X ; |
  664. SBC #$00 ; |
  665. CMP #$02 ; |
  666. BCS OffScrEraseSprite ; / ...erase the sprite
  667. LDA $13
  668. LSR
  669. AND #$01
  670. STA $01
  671. TAY
  672. LDA $1C
  673. CLC
  674. ADC DATA_01AC0D,Y
  675. ROL $00
  676. CMP $D8,X
  677. PHP
  678. LDA $001D
  679. LSR $00
  680. ADC DATA_01AC0F,Y
  681. PLP
  682. SBC $14D4,X
  683. STA $00
  684. LDY $01
  685. BEQ ADDR_01ACF3
  686. EOR #$80
  687. STA $00
  688. ADDR_01ACF3:
  689. LDA $00
  690. BPL Return01ACA4
  691. BMI OffScrEraseSprite
  692.  
  693. IsSprOnScreen:
  694. LDA $15A0,X ; \ A = Current sprite is offscreen
  695. ORA $186C,X ; /
  696. RTS ; Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement