Advertisement
Guest User

Untitled

a guest
Sep 17th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.65 KB | None | 0 0
  1. print "INIT ",pc
  2. JSR SUB_HORZ_POS
  3. TYA
  4. STA $157C,x
  5. RTL
  6.  
  7. print "MAIN ",pc
  8. PHB
  9. PHK
  10. PLB
  11. JSR SPR_MAIN
  12. PLB
  13. RTL
  14.  
  15. RETURN: RTS
  16.  
  17. SPR_MAIN:
  18. JSR SPR_GFX
  19.  
  20. LDA $14C8,x
  21. CMP #$08
  22. BNE RETURN
  23. LDA $9D
  24. BNE RETURN
  25.  
  26. JSL $018032
  27.  
  28. LDA $1588,x
  29. AND #$03
  30. BEQ NOTWALL
  31.  
  32. LDA $157C,x
  33. EOR #$01
  34. STA $157C,x
  35.  
  36. NOTWALL:
  37. LDA $C2,x
  38. CMP #$01
  39. BNE NORMAL
  40. STZ $B6,x
  41. BRA CONTACT_STUFF
  42. RTS
  43. NORMAL:
  44. LDA $1588,x
  45. AND #$04
  46. BEQ CONTACT_STUFF
  47. LDY $157C,x
  48. LDA XSPD,y
  49. STA $B6,x
  50. LDA #$10
  51. STA $AA,x
  52.  
  53. CONTACT_STUFF:
  54. JSL $01802A
  55. JSL $01A7DC
  56. BCC NOCONTACT
  57.  
  58. LDA $1490
  59. BNE HasStar
  60. JSL $00F5B7
  61. RTS
  62.  
  63. HasStar:
  64. LDA #$02 ;\ Set the sprite status to ..
  65. STA $14C8,x ;/ Killed by a star.
  66. LDA #$D0 ;
  67. STA $AA,x ;/ Set Y speed so sprite falls down.
  68. INC $18D2 ; Increase number of consective enemies stomped/ killed by star.
  69. LDA $18D2 ; IF consecutive # of enemies killed by star/stomped ..
  70. CMP #$08 ; IS 8 ..
  71. BCC NotEight
  72. LDA #$08 ;\ Keep it static at 8, because you get 1-ups all the time afterwards.
  73. STA $18D2 ;/
  74. NotEight:
  75. JSL $02ACE5 ; This code calls the "give points" routine.
  76. LDY $18D2 ; Get consecutive # of enemies stomped in Y.
  77. CPY #$08 ; If it's less than 8 once again, return.
  78. BCC NoSound
  79. LDA StarSFX,y
  80. STA $1DF9
  81. RTS
  82. NoSound:
  83. LDA #$13
  84. STA $1DF9
  85. RTS ; Return.
  86.  
  87. StarSFX: db $00,$13,$14,$15,$16,$17,$18,$19
  88.  
  89. NOCONTACT:
  90. LDA $1534,x
  91. CMP #$BE
  92. BEQ SHOOTFIRE
  93. INC $1534,x
  94.  
  95. LDA $1594,x
  96. CMP #$50
  97. BEQ ENDNOW
  98. INC $1594,x
  99. RTS
  100. ENDNOW:
  101.  
  102. STZ $1594,x
  103. STZ $C2,x
  104. RTS
  105.  
  106. XSPD: db $10,$F0
  107.  
  108. SHOOTFIRE:
  109. PHY
  110. JSR SUB_HORZ_POS
  111. TYA
  112. STA $157C,x
  113. PLY
  114. LDA #$01
  115. STA $C2,x
  116.  
  117. STZ $1534,x
  118. LDY #$01 ; number of projectiles to spawn
  119. - TYA ; \
  120. STA $00 ; / get number within loop
  121. PHY
  122. JSR .spawnfireball ; spawn fireball
  123. PLY
  124. DEY
  125. BPL -
  126. RTS
  127.  
  128. .spawnfireball
  129. LDY #$07 ; number of slots to check for (#$07 = 8 slots; leaves the last 2 slots for Mario's fireballs)
  130. - LDA $170B,y
  131. BEQ Extra1
  132. DEY
  133. BPL -
  134. RTS
  135. Extra1:
  136. LDA #$02
  137. STA $170B,y
  138.  
  139. LDA $E4,x
  140. STA $171F,y
  141. LDA $14E0,x
  142. STA $1733,y
  143. LDA $D8,x
  144. STA $1715,y
  145. LDA $14D4,x
  146. STA $1729,y
  147.  
  148. PHY
  149. LDY $157C,x
  150. LDA .fireball_xspeed,y
  151. PLY
  152. STA $1747,y
  153. PHY
  154. LDY $00
  155. LDA .fireball_yspeed,y
  156. PLY
  157. STA $173D,y
  158.  
  159. LDA #$06
  160. STA $1DFC
  161. LDA #$FF
  162. STA $176F,y
  163. RTS
  164. .fireball_xspeed
  165. db $16,$EA
  166. .fireball_yspeed
  167. db $00,$FB
  168. ;;;;;;;;;;;;;; GFX ROUTINE ;;;;;;;;;;;;;;;;;;
  169.  
  170. TILEMAP:
  171. db $82,$8C ; FRAME 1
  172. db $84,$88 ; FRAME 2
  173.  
  174. PROP:
  175. db $00,$40
  176.  
  177. YDISP:
  178. db $10,$00 ; RIGHT
  179. db $10,$00 ; LEFT
  180.  
  181. SPR_GFX:
  182.  
  183. JSR GET_DRAW_INFO
  184.  
  185.  
  186. PHX
  187. LDA $157C,x
  188. STA $02
  189. TAX
  190. LDA PROP,x
  191. STA $0F
  192. PLX
  193.  
  194. LDA $14
  195. LSR #3
  196. CLC : ADC $15E9
  197. AND #$01 ; ANIMATE BETWEEN TWO FRAMES
  198. ASL A
  199. STA $03
  200.  
  201. LDA $C2,x
  202. CMP #$01
  203. BEQ SPR_GFX1
  204.  
  205. PHX
  206. LDX #$01 ; 2 TILES DRAWN SO LOOP ONCE
  207.  
  208. LOOP:
  209. LDA $00
  210. STA $0300,y
  211.  
  212. LDA $01
  213. SEC : SBC YDISP,x
  214. STA $0301,y
  215.  
  216. PHX
  217. LDX $15E9
  218. LDA $15F6,x
  219. ORA $0F
  220. ORA $64
  221. STA $0303,y
  222. PLX
  223.  
  224. PHX
  225. TXA
  226. CLC : ADC $03
  227. TAX
  228. LDA TILEMAP,x
  229. STA $0302,y
  230. PLX
  231.  
  232. INY #4
  233. DEX
  234.  
  235. BPL LOOP
  236.  
  237. PLX
  238.  
  239. LDY #$02 ; 16X16 TILES
  240. LDA #$01 ; 2 TILES DRAWN
  241. JSL $01B7B3
  242.  
  243. RTS
  244.  
  245.  
  246. ;;;;;;;;;;;;;;;
  247.  
  248. FIRE_TILEMAP:
  249. db $82,$86 ; FRAME 1
  250. db $84,$86 ; FRAME 2
  251.  
  252. SPR_GFX1:
  253. PHX
  254. LDX #$01 ; 2 TILES DRAWN SO LOOP ONCE
  255.  
  256. LOOP1:
  257. LDA $00
  258. STA $0300,y
  259.  
  260. LDA $01
  261. SEC : SBC YDISP,x
  262. STA $0301,y
  263.  
  264. PHX
  265. LDX $15E9
  266. LDA $15F6,x
  267. ORA $0F
  268. ORA $64
  269. STA $0303,y
  270. PLX
  271.  
  272. PHX
  273. TXA
  274. CLC : ADC $03
  275. TAX
  276. LDA FIRE_TILEMAP,x
  277. STA $0302,y
  278. PLX
  279.  
  280. INY #4
  281. DEX
  282.  
  283. BPL LOOP1
  284.  
  285. PLX
  286.  
  287. LDY #$02 ; 16X16 TILES
  288. LDA #$01 ; 2 TILES DRAWN
  289. JSL $01B7B3
  290.  
  291. RTS
  292.  
  293. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  294. ; GET_DRAW_INFO
  295. ; This is a helper for the graphics routine. It sets off screen flags, and sets up
  296. ; variables. It will return with the following:
  297. ;
  298. ; Y = index to sprite OAM ($300)
  299. ; $00 = sprite x position relative to screen boarder
  300. ; $01 = sprite y position relative to screen boarder
  301. ;
  302. ; It is adapted from the subroutine at $03B760
  303. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  304.  
  305. SPR_T1: db $0C,$1C
  306. SPR_T2: db $01,$02
  307.  
  308. GET_DRAW_INFO:
  309. STZ $186C,x ; reset sprite offscreen flag, vertical
  310. STZ $15A0,x ; reset sprite offscreen flag, horizontal
  311. LDA $E4,x ; \
  312. CMP $1A ; | set horizontal offscreen if necessary
  313. LDA $14E0,x ; |
  314. SBC $1B ; |
  315. BEQ .ON_SCREEN_X ; |
  316. INC $15A0,x ; /
  317.  
  318. .ON_SCREEN_X
  319. LDA $14E0,x ; \
  320. XBA ; |
  321. LDA $E4,x ; |
  322. REP #$20 ; |
  323. SEC ; |
  324. SBC $1A ; | mark sprite invalid if far enough off screen
  325. CLC ; |
  326. ADC.w #$0040 ; |
  327. CMP.w #$0180 ; |
  328. SEP #$20 ; |
  329. ROL A ; |
  330. AND #$01 ; |
  331. STA $15C4,x ; /
  332. BNE .INVALID ;
  333.  
  334. LDY #$00 ; \ set up loop:
  335. LDA $1662,x ; |
  336. AND #$20 ; | if not smushed (1662 & 0x20), go through loop twice
  337. BEQ .ON_SCREEN_LOOP ; | else, go through loop once
  338. INY ; /
  339. .ON_SCREEN_LOOP
  340. LDA $D8,x ; \
  341. CLC ; | set vertical offscreen if necessary
  342. ADC SPR_T1,y ; |
  343. PHP ; |
  344. CMP $1C ; | (vert screen boundry)
  345. ROL $00 ; |
  346. PLP ; |
  347. LDA $14D4,x ; |
  348. ADC #$00 ; |
  349. LSR $00 ; |
  350. SBC $1D ; |
  351. BEQ .ON_SCREEN_Y ; |
  352. LDA $186C,x ; | (vert offscreen)
  353. ORA SPR_T2,y ; |
  354. STA $186C,x ; |
  355. .ON_SCREEN_Y
  356. DEY ; |
  357. BPL .ON_SCREEN_LOOP ; /
  358.  
  359. LDY $15EA,x ; get offset to sprite OAM
  360. LDA $E4,x ; \
  361. SEC ; |
  362. SBC $1A ; | $00 = sprite x position relative to screen boarder
  363. STA $00 ; /
  364. LDA $D8,x ; \
  365. SEC ; |
  366. SBC $1C ; | $01 = sprite y position relative to screen boarder
  367. STA $01 ; /
  368. RTS ; return
  369.  
  370. .INVALID
  371. PLA ; \ return from *main gfx routine* subroutine...
  372. PLA ; | ...(not just this subroutine)
  373. RTS ; /
  374.  
  375.  
  376.  
  377. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  378. ; sub horz pos
  379. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  380.  
  381. SUB_HORZ_POS: LDY #$00
  382. LDA $94
  383. SEC
  384. SBC $E4,x
  385. STA $0F
  386. LDA $95
  387. SBC $14E0,x
  388. BPL SPR_L16
  389. INY
  390. SPR_L16: RTS
  391.  
  392.  
  393. recip_sqrt_lookup:
  394. dw $0000,$FFFF,$B505,$93CD,$8000,$727D,$6883,$60C2
  395. dw $5A82,$5555,$50F4,$4D30,$49E7,$4700,$446B,$4219
  396. dw $4000,$3E17,$3C57,$3ABB,$393E,$37DD,$3694,$3561
  397. dw $3441,$3333,$3235,$3144,$3061,$2F8A,$2EBD,$2DFB
  398. dw $2D41,$2C90,$2BE7,$2B46,$2AAB,$2A16,$2987,$28FE
  399. dw $287A,$27FB,$2780,$270A,$2698,$262A,$25BF,$2557
  400. dw $24F3,$2492,$2434,$23D9,$2380,$232A,$22D6,$2285
  401. dw $2236,$21E8,$219D,$2154,$210D,$20C7,$2083,$2041
  402. dw $2000,$1FC1,$1F83,$1F46,$1F0B,$1ED2,$1E99,$1E62
  403. dw $1E2B,$1DF6,$1DC2,$1D8F,$1D5D,$1D2D,$1CFC,$1CCD
  404. dw $1C9F,$1C72,$1C45,$1C1A,$1BEF,$1BC4,$1B9B,$1B72
  405. dw $1B4A,$1B23,$1AFC,$1AD6,$1AB1,$1A8C,$1A68,$1A44
  406. dw $1A21,$19FE,$19DC,$19BB,$199A,$1979,$1959,$1939
  407. dw $191A,$18FC,$18DD,$18C0,$18A2,$1885,$1869,$184C
  408. dw $1831,$1815,$17FA,$17DF,$17C5,$17AB,$1791,$1778
  409. dw $175F,$1746,$172D,$1715,$16FD,$16E6,$16CE,$16B7
  410. dw $16A1,$168A,$1674,$165E,$1648,$1633,$161D,$1608
  411. dw $15F4,$15DF,$15CB,$15B7,$15A3,$158F,$157C,$1568
  412. dw $1555,$1542,$1530,$151D,$150B,$14F9,$14E7,$14D5
  413. dw $14C4,$14B2,$14A1,$1490,$147F,$146E,$145E,$144D
  414. dw $143D,$142D,$141D,$140D,$13FE,$13EE,$13DF,$13CF
  415. dw $13C0,$13B1,$13A2,$1394,$1385,$1377,$1368,$135A
  416. dw $134C,$133E,$1330,$1322,$1315,$1307,$12FA,$12ED
  417. dw $12DF,$12D2,$12C5,$12B8,$12AC,$129F,$1292,$1286
  418. dw $127A,$126D,$1261,$1255,$1249,$123D,$1231,$1226
  419. dw $121A,$120F,$1203,$11F8,$11EC,$11E1,$11D6,$11CB
  420. dw $11C0,$11B5,$11AA,$11A0,$1195,$118A,$1180,$1176
  421. dw $116B,$1161,$1157,$114D,$1142,$1138,$112E,$1125
  422. dw $111B,$1111,$1107,$10FE,$10F4,$10EB,$10E1,$10D8
  423. dw $10CF,$10C5,$10BC,$10B3,$10AA,$10A1,$1098,$108F
  424. dw $1086,$107E,$1075,$106C,$1064,$105B,$1052,$104A
  425. dw $1042,$1039,$1031,$1029,$1020,$1018,$1010,$1008
  426.  
  427. aiming: PHX
  428. PHY
  429. PHP
  430. SEP #$30
  431. STA $0F
  432.  
  433. LDX #$00
  434. REP #$20
  435. LDA $00
  436. BPL .pos_dx
  437. EOR #$FFFF
  438. INC
  439. INX
  440. INX
  441. STA $00
  442. .pos_dx SEP #$20
  443. STA $4202
  444. STA $4203
  445.  
  446. NOP
  447. NOP
  448. NOP
  449. REP #$20
  450. LDA $4216
  451. STA $04
  452. LDA $02
  453. BPL .pos_dy
  454. EOR #$FFFF
  455. INC
  456. INX
  457. STA $02
  458. .pos_dy SEP #$20
  459. STA $4202
  460. STA $4203
  461. STX $0E
  462.  
  463. REP #$30
  464. LDA $04
  465. CLC
  466. ADC $4216
  467. LDY #$0000
  468. BCC .loop
  469. INY
  470. ROR
  471. LSR
  472. .loop CMP #$0100
  473. BCC +
  474. INY
  475. LSR
  476. LSR
  477. BRA .loop
  478. + CLC
  479. ASL
  480. TAX
  481. LDA recip_sqrt_lookup,x
  482. - DEY
  483. BMI +
  484. LSR
  485. BRA -
  486. + SEP #$30
  487.  
  488. STA $4202
  489. LDA $0F
  490. STA $4203
  491. NOP
  492. STZ $05
  493. STZ $07
  494. LDA $4217
  495. STA $04
  496. XBA
  497. STA $4202
  498. LDA $0F
  499. STA $4203
  500.  
  501. REP #$20
  502. LDA $04
  503. CLC
  504. ADC $4216
  505. STA $04
  506. SEP #$20
  507.  
  508. LDX #$02
  509. - LDA $04
  510. STA $4202
  511. LDA $00,x
  512. STA $4203
  513.  
  514. NOP
  515. NOP
  516. NOP
  517. NOP
  518.  
  519. LDA $4217
  520. STA $06
  521. LDA $05
  522. STA $4202
  523. LDA $00,x
  524. STA $4203
  525.  
  526. REP #$20
  527. LDA $06
  528. CLC
  529. ADC $4216
  530. SEP #$20
  531.  
  532. LSR $0E
  533. BCS +
  534. EOR #$FF
  535. INC
  536. + STA $00,x
  537. DEX
  538. DEX
  539. BPL -
  540.  
  541. PLP
  542. PLY
  543. PLX
  544. RTL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement