Advertisement
Romano338

Shell bro

Jul 30th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.86 KB | None | 0 0
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;; Bro sprite that throws a sprite.
  3. ;; What sprite is determined by the first extra property byte in the CFG editor and the
  4. ;; tables below
  5. ;;
  6. ;; Uses first extra bit: NO
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8.  
  9.  
  10. ;Tables indexed by first extra property byte
  11.  
  12. ;Currently:
  13. ; 0 - Green Shell
  14. ; 1 - Bob Omb
  15.  
  16. ;sprite to spawn
  17. SpriteToSpawn: db $04,$0D
  18. ;$14C8 state
  19. SpawnState: db $0A,$09
  20. ;$1540
  21. SpawnTimer: db $00,$A0
  22. ;Graphical Display Stuff:
  23. SpawnTile: db $8A,$CA
  24. SpawnProp: db $0A,$03
  25.  
  26.  
  27. !Throw_XOff = $07
  28. XThrowSpeed: db $32,$CE
  29.  
  30. !JUMP_TIMER = !163E ;Decrements itself per frame!!!!
  31. !RAM_ThrowTimer = !1504 ;DOESN'T decrement itself!!!!!!!
  32.  
  33.  
  34. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  35. ; Routine that spawns the sprite to be thrown
  36. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  37.  
  38.  
  39. SpawnThrowSprite:
  40. LDA !157C,x
  41. TAY
  42.  
  43. LDA Throw_Offset,y ; \ x offset from generator sprite
  44. STA $00 ; /
  45. LDA #$F2 ; \ y offset from generator sprite
  46. STA $01 ; /
  47. LDA XThrowSpeed,y ; \ initial x speed
  48. STA $02 ; /
  49. LDA #$F0 ; \ initial y speed
  50. STA $03 ; /
  51.  
  52. LDA !extra_bits,x ; \ put extra bit in carry
  53. LSR #3 ; / if set => spawn custom sprite.
  54.  
  55. LDA !extra_prop_1,x
  56. TAY
  57. LDA SpriteToSpawn,y
  58.  
  59. %SpawnSprite()
  60. BCS +
  61.  
  62. PHX
  63. LDA !extra_prop_1,x
  64. TAX
  65. LDA SpawnState,x ; \ if successful, set state
  66. STA !14C8,y ; /
  67. LDA SpawnTimer,x ; \ set explosion timer
  68. STA !1540,y ; /
  69. PLX
  70. + RTS
  71.  
  72.  
  73. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  74. ; sprite data
  75. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  76.  
  77. ;16x16 body tile, 8x8 foot tile 1, 8x8 foot tile 2, dummy
  78. TILEMAP: db $46,$4A,$7F,$00 ;walking 1
  79. db $46,$5A,$2F,$00 ;walking 2
  80. db $48,$4A,$7F,$00 ;throwing 1
  81. db $48,$5A,$2F,$00 ;throwing 2
  82.  
  83. HORZ_DISP: db $00,$00,$08 ;facing left
  84. db $00,$08,$00 ;facing right
  85. VERT_DISP: db $F8,$08,$08
  86. TILE_SIZE: db $02,$00,$00
  87.  
  88. PROPERTIES: db $40,$00 ;xyppccct format
  89.  
  90.  
  91. Throw_Offset: db $100-!Throw_XOff,!Throw_XOff
  92.  
  93. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  94. ; init JSL
  95. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  96.  
  97. print "INIT ",pc
  98. %SubHorzPos()
  99. TYA
  100. STA !157C,x
  101.  
  102. TXA ; \ use sprite index as base for a touch of randomness
  103. AND #$03 ; |
  104. ASL #5 ; |
  105. STA !JUMP_TIMER,x ; / jump timer randomly $00, $20, $40, $60
  106. CLC
  107. ADC #$32
  108. STA !RAM_ThrowTimer,x
  109.  
  110. RTL
  111.  
  112. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  113. ; main sprite JSL
  114. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  115.  
  116. print "MAIN ",pc
  117. PHB ; \
  118. PHK ; | main sprite function, just calls local subroutine
  119. PLB ; |
  120. JSR START_HB_CODE ; |
  121. PLB ; |
  122. RTL ; /
  123.  
  124. DecTimers:
  125. LDA !RAM_ThrowTimer,x
  126. BEQ .done
  127. DEC !RAM_ThrowTimer,x
  128. .done:
  129. RTS
  130.  
  131. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  132. ; main sprite routine
  133. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  134.  
  135. ;indexed by 151C
  136. X_SPEED: db $00,$F8,$00,$08 ;rest at bottom, moving up, rest at top, moving down
  137. TIME_IN_POS: db $48,$10,$48,$10 ;moving up, rest at top, moving down, rest at bottom
  138.  
  139. ;indexed by C2
  140. TIME_TILL_THROW: db $F7,$62
  141.  
  142. STAR:
  143. INC !RAM_ThrowTimer,x
  144. Return:
  145. RTS
  146.  
  147. START_HB_CODE:
  148.  
  149. JSR SUB_GFX ; draw hammer bro gfx
  150. LDA !14C8,x ; \ if hammer bro status != 8...
  151. CMP #$02 ; } ... not (killed with spin jump [4] or STAR[2])
  152. BEQ STAR
  153. CMP #$08
  154. BNE Return ; / ... RETURN
  155. LDA $9D ; \ if sprites locked...
  156. BNE Return ; / return
  157.  
  158. JSR DecTimers ; decrement timers (that aren't self decrementing)
  159.  
  160. LDA #$00 ; sub_off_screen_x0
  161. %SubOffScreen() ; only process hammer bro while on screen
  162.  
  163. %SubHorzPos() ; \ always face mario
  164. TYA ; |
  165. STA !157C,x ; /
  166.  
  167. ;1570 = on screen frame counter
  168. ;151C = speed phase
  169. ; 00 = stand still
  170. ; 01 = move back
  171. ; 02 = stand still
  172. ; 03 = move forward
  173. ;1602 = animation display frame counter
  174.  
  175. INC !1570,x ; increment number of frames hammer bro has been on screen
  176.  
  177. ;Code to handle the "base" animation frame to display
  178. ;$1602 will be either 0 or 1, throwing code may offset it by 2.
  179. LDA !151C,x ; \
  180. AND #$01 ; | skip if we're in a "stant still" phase
  181. BEQ + ; /
  182.  
  183. LDA !1570,x ; \ calculate which frame to show:
  184. LSR #3 ; |
  185. AND #$01 ; | update every 16 cycles if normal
  186. BRA ++ ; / skip ahead and just store
  187.  
  188. + LDA !151C,x ; \ if in "stand still phase 0", set frame to 0
  189. BEQ ++ ; |
  190. LDA #$01 ; | if in "stand still phase 2", set frame to 1
  191. ++ STA !1602,x ; / write frame to show
  192.  
  193. ;Code to handle the throw timer
  194. LDA !RAM_ThrowTimer,x ; \
  195. CMP #$22 ; | Check throw timer
  196. BCS Jumping ; | skip if it's more than the limit already
  197. INC !1602,x ; | if not, move animation frame into the "throwing" range.
  198. INC !1602,x ; /
  199.  
  200. LDA !RAM_ThrowTimer,x ; \
  201. BNE + ; | if it's not time to throw yet, skip over stuff
  202. LDY !C2,x ; | set throw timer again (depending on $C2)
  203. LDA TIME_TILL_THROW,y ; |
  204. STA !RAM_ThrowTimer,x ; /
  205. + CMP #$01 ; \
  206. BNE Jumping ; | when timer = 1
  207. LDA !C2,x ; | invert $C2 for next reset of timer
  208. EOR #$01 ; | and spawn the sprite
  209. STA !C2,x ; | if not, skip ahead.
  210. JSR SpawnThrowSprite ; /
  211.  
  212. ;Code to handle the jumping part.
  213. Jumping:
  214. LDA !JUMP_TIMER,x ; \ if timer still above $28
  215. CMP #$28 ; | just go to normal walking code
  216. BCS Speed ; /
  217. LDA !JUMP_TIMER,x ; \
  218. CMP #$21 ; | if timer is $21, do jump
  219. BNE .reset ; / if not, do skip
  220. LDA !1570,x ; \
  221. LSR A ; |
  222. AND #01 ; |
  223. BEQ .reset ; /
  224. LDA #$D0 ; \ set y speed
  225. STA !AA,x ; | and just move to updating speeds
  226. BRA Speed_apply ; /
  227.  
  228. .reset
  229. CMP #$00 ; \
  230. BNE Speed ; | check if it's time to reset the jump timer
  231. LDA #$FE ; | and do if so.
  232. STA !JUMP_TIMER,x ; /
  233.  
  234. ;Code to handle the sprite's back and forth movement.
  235. Speed:
  236. LDA !151C,x ; \ speed phase in Y
  237. TAY ; /
  238. LDA !1540,x ; \ change speed phase and reset timer if timer is up.
  239. BEQ .change ; /
  240. LDA X_SPEED,y ; \ set x speed based on phase.
  241. STA !B6,x ; /
  242. BRA .apply
  243.  
  244. .change
  245. LDA TIME_IN_POS,y ; \
  246. STA !1540,x ; | set turning timer (decrements itself)
  247. LDA !151C,x ; |
  248. INC A ; | and increment the speed phase.
  249. AND #$03 ; |
  250. STA !151C,x ; /
  251. .apply
  252. JSL $01802A ; update position based on speed values
  253.  
  254.  
  255. LDA !1588,x ; \ if hammer bro is not touching the side of an object...
  256. AND #$03 ; | skip ahead
  257. BEQ + ; /
  258. LDA !151C,x ; \
  259. INC A ; | if he is, move to next speed phase.
  260. AND #$03 ; |
  261. STA !151C,x ; /
  262. +
  263.  
  264. ;Code to handle basic contact routine
  265. JSL $018032 ; interact with other sprites
  266. JSL $01A7DC ; check for mario/hammer bro contact
  267. RTS
  268.  
  269.  
  270.  
  271. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  272. ; graphics routine
  273. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  274.  
  275. SUB_GFX:
  276. %GetDrawInfo() ; after: Y = index to sprite tile map ($300)
  277. ; $00 = sprite x position relative to screen boarder
  278. ; $01 = sprite y position relative to screen boarder
  279. SomeLabel:
  280. LDA !1602,x ; \
  281. ASL #2 ; | $03 = index to frame start (frame to show * 2 tile per frame)
  282. STA $03 ; /
  283. LDA !157C,x ; \ $02 = sprite direction
  284. STA $02 ; /
  285. PHX ; push sprite index
  286.  
  287. LDX #$02 ; loop counter = (number of tiles) - 1
  288. .loop
  289. PHX ; push current tile number
  290.  
  291. TXA ; \ put tile number in A
  292. LDX $02 ; |
  293. BNE + ; | and if sprite faces left, add 3
  294. CLC ; | and put it back in X
  295. ADC #$03 ; |
  296. + TAX ; /
  297. LDA $00 ; \ tile x position + offset depending on direction
  298. CLC : ADC HORZ_DISP,x ; |
  299. STA $0300|!Base2,y ; /
  300.  
  301. PLX ; get tile number back in X
  302.  
  303. LDA $01 ; \ tile y position = sprite y location ($01) + tile displacement
  304. CLC ; |
  305. ADC VERT_DISP,x ; |
  306. STA $0301|!Base2,y ; /
  307.  
  308. LDA TILE_SIZE,x ; get size for current tile
  309. PHX ; \ preserve A (tile size) and X (tile number)
  310. PHA ; /
  311. TYA ; \ get index to sprite property map ($460)...
  312. LSR A ; | ...we use the sprite OAM index...
  313. LSR A ; | ...and divide by 4 OAM has 4 bytes per slot and this only 1.
  314. TAX ; |
  315. PLA ; | store tile size (2 = 16x16, 0 = 8x8)
  316. STA $0460|!Base2,x ; /
  317. PLX ; restore tile number
  318.  
  319. PHX ; save tile number again
  320. TXA ; \ X = index to horizontal displacement
  321. ORA $03 ; | get index of tile (index to first tile of frame + current tile number)
  322. TAX ; /
  323.  
  324. LDA TILEMAP,x ; \ store tile
  325. STA $0302|!Base2,y ; /
  326.  
  327. LDX $02 ; \
  328. LDA PROPERTIES,x ; | get tile PROPERTIES using sprite direction
  329. LDX $15E9|!Base2 ; |
  330. ORA !15F6,x ; | get palette info
  331. ORA $64 ; | put in level PROPERTIES
  332. STA $0303|!Base2,y ; / store tile PROPERTIES
  333.  
  334. PLX ; \ pull, X = current tile of the frame we're drawing
  335. INY ; | increase index to sprite tile map ($300)...
  336. INY ; | ...we wrote 1 16x16 tile...
  337. INY ; | ...sprite OAM is 8x8...
  338. INY ; | ...so increment 4 times
  339. DEX ; | go to next tile of frame and loop
  340. BPL .loop ; /
  341.  
  342. PLX ; pull, X = sprite index
  343.  
  344. LDA !RAM_ThrowTimer,x
  345. CMP #$02
  346. BCC .DontShowTTile
  347. CMP #30
  348. BCS .DontShowTTile
  349. LDA !1602,x
  350. CMP #$02
  351. BCS .ShowThrowTile
  352.  
  353. .DontShowTTile
  354. LDY #$FF ; \ 02, because we didn't write to 460 yet
  355. LDA #$02 ; | A = number of tiles drawn - 1
  356. JSL $01B7B3 ; / don't draw if offscreen
  357. RTS ; RETURN
  358.  
  359. .ShowThrowTile
  360. PHX ; preserve sprite index
  361.  
  362. LDA !extra_prop_1,x
  363. TAX
  364. LDA SpawnTile,x
  365. STA $03
  366. LDA SpawnProp,x
  367. STA $04
  368.  
  369. LDA $00 ; \
  370. LDX $02 ; | x position + offset (depending on sprite direction)
  371. CLC : ADC Throw_Offset,x; |
  372. STA $0300|!Base2,y ; /
  373.  
  374. LDA $01 ; \
  375. CLC : ADC #$F2 ; | y position + offset
  376. STA $0301|!Base2,y ; /
  377.  
  378. LDA $03 ; \ store tile
  379. STA $0302|!Base2,y ; /
  380.  
  381. TYA ; \ get index to sprite property map ($460)...
  382. LSR A ; | ...we use the sprite OAM index...
  383. LSR A ; | ...and divide by 4 OAM has 4 bytes per slot and this only 1.
  384. TAX ; |
  385. LDA #$02 ; | store tile size (2 = 16x16, 0 = 8x8)
  386. STA $0460|!Base2,x ; /
  387.  
  388. LDA $04 ; \ load throw tile properties.
  389. BIT $02 ; | depending on sprite direction...
  390. BEQ + ; | ... add x-flip bit to properties
  391. ORA #$40 ; |
  392. + ORA $64 ; | put in level properties
  393. STA $0303|!Base2,y ; / store tile properties
  394.  
  395. PLX ; retore sprite index
  396.  
  397. LDY #$FF ; \
  398. LDA #$03 ; | A = number of tiles drawn - 1
  399. JSL $01B7B3 ; / don't draw if offscreen
  400. RTS ; RETURN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement