Advertisement
Guest User

Zzap

a guest
Jul 19th, 2008
966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.29 KB | None | 0 0
  1. .inesprg 1 ; 1x 16KB PRG code
  2. .ineschr 1 ; 1x 8KB CHR data
  3. .inesmap 0 ; mapper 0 = NROM, no bank swapping
  4. .inesmir 1 ; background mirroring
  5.  
  6.  
  7. ;;;;;;;;;;;;;;;
  8.  
  9. .org $0000
  10. AddrLow: .rs 1
  11. AddrHigh: .rs 1
  12.  
  13. .bank 0
  14.  
  15. .org $C000
  16. RESET:
  17. SEI ; disable IRQs
  18. CLD ; disable decimal mode
  19. LDX #$40
  20. STX $4017 ; disable APU frame IRQ
  21. LDX #$FF
  22. TXS ; Set up stack
  23. INX ; now X = 0
  24. STX $2000 ; disable NMI
  25. STX $2001 ; disable rendering
  26. STX $4010 ; disable DMC IRQs
  27.  
  28. vblankwait1: ; First wait for vblank to make sure PPU is ready
  29. BIT $2002
  30. BPL vblankwait1
  31.  
  32. clrmem:
  33. LDA #$00
  34. STA $0000, x
  35. STA $0100, x
  36. STA $0300, x
  37. STA $0400, x
  38. STA $0500, x
  39. STA $0600, x
  40. STA $0700, x
  41. LDA #$FE
  42. STA $0200, x
  43. INX
  44. BNE clrmem
  45.  
  46. vblankwait2: ; Second wait for vblank, PPU is ready after this
  47. BIT $2002
  48. BPL vblankwait2
  49.  
  50.  
  51. LoadPalettes:
  52. LDA $2002 ; read PPU status to reset the high/low latch
  53. LDA #$3F
  54. STA $2006 ; write the high byte of $3F00 address
  55. LDA #$00
  56. STA $2006 ; write the low byte of $3F00 address
  57. LDX #$00 ; start out at 0
  58. LoadPalettesLoop:
  59. LDA palette, x ; load data from address (palette + the value in x)
  60. ; 1st time through loop it will load palette+0
  61. ; 2nd time through loop it will load palette+1
  62. ; 3rd time through loop it will load palette+2
  63. ; etc
  64. STA $2007 ; write to PPU
  65. INX ; X = X + 1
  66. CPX #$20 ; Compare X to hex $10, decimal 16 - copying 16 bytes = 4 sprites<- lol wut? It's CPXing to $20, but says $10. �\(�_O)/�
  67. BNE LoadPalettesLoop ; Branch to LoadPalettesLoop if compare was Not Equal to zero
  68. ; if compare was equal to 32, keep going down
  69.  
  70.  
  71.  
  72. LoadSprites:
  73. LDX #$00 ; start at 0
  74. LoadSpritesLoop:
  75. LDA sprites, x ; load data from address (sprites + x)
  76. STA $0200, x ; store into RAM address ($0200 + x)
  77. INX ; X = X + 1
  78. CPX #$10 ; Compare X to hex $10, decimal 16
  79. BNE LoadSpritesLoop ; Branch to LoadSpritesLoop if compare was Not Equal to zero
  80. ; if compare was equal to 16, keep going down
  81.  
  82.  
  83. LDA $2002
  84. LDA #$20
  85. STA $2006 ; write the high byte of $2000 address
  86. LDA #$00
  87. STA $2006 ; write the low byte of $2000 address
  88.  
  89. LDA #low(background)
  90. STA AddrLow
  91. LDA #high(background)
  92. STA AddrHigh
  93.  
  94. LDX #$04 ; Loop X 4 times
  95. LDY #$00 ; Loop Y 256 times
  96. LoadBackgroundsLoop:
  97. LDA [AddrLow],y
  98. STA $2007
  99. INY
  100. BNE LoadBackgroundsLoop
  101. ; Outer loop
  102. INC AddrHigh ; increment high byte of address backg to next 256 byte chunk
  103. DEX ; one chunk done so X = X - 1.
  104. BNE LoadBackgroundsLoop ; if X isn't zero, do again
  105.  
  106.  
  107. LDA $2002 ; Reset Scroll
  108. LDA #$00
  109. STA $2005
  110. STA $2005
  111. STA $2006
  112. STA $2006
  113.  
  114.  
  115. LDA #%10010000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
  116. STA $2000
  117.  
  118. LDA #%00011110 ; enable sprites, enable background, no clipping on left side
  119. STA $2001
  120.  
  121. Forever:
  122. JMP Forever ;jump back to Forever, infinite loop
  123.  
  124.  
  125.  
  126. NMI:
  127. LDA #$00
  128. STA $2003 ; set the low byte (00) of the RAM address
  129. LDA #$02
  130. STA $4014 ; set the high byte (02) of the RAM address, start the transfer
  131.  
  132.  
  133. LatchController:
  134. LDA #$01
  135. STA $4016
  136. LDA #$00
  137. STA $4016 ; tell both the controllers to latch buttons
  138.  
  139. ButtonA:
  140. LDA $4016 ; player 1 - A
  141. AND #%00000001 ; look only at bit 0
  142. BNE ButtonB
  143.  
  144. ; Button stuff here
  145.  
  146. ButtonB:
  147. LDA $4016 ; player 1 - B
  148. AND #%00000001 ; look only at bit 0
  149. BNE SelectButton
  150.  
  151. ; Button stuff here
  152.  
  153. SelectButton:
  154. LDA $4016 ; player 1 - Select
  155. AND #%00000001 ; look only at bit 0
  156. BNE StartButton
  157.  
  158. ; Button stuff here
  159.  
  160. StartButton:
  161. LDA $4016 ; player 1 - Start
  162. AND #%00000001 ; look only at bit 0
  163. BNE UpButton
  164.  
  165. ; Button stuff here
  166.  
  167. UpButton:
  168. LDA $4016 ; player 1 - Up
  169. AND #%00000001 ; look only at bit 0
  170. BNE DownButton
  171. LDA $0200 ; load sprite Y position
  172. CLC ; make sure the carry flag is clear
  173. ADC #$01 ; A = A + 1
  174. STA $0200 ; save sprite Y position
  175. LDA $0204 ; load sprite Y position
  176. CLC ; make sure the carry flag is clear
  177. ADC #$01 ; A = A + 1
  178. STA $0204 ; save sprite Y position
  179. LDA $0208 ; load sprite Y position
  180. CLC ; make sure the carry flag is clear
  181. ADC #$01 ; A = A + 1
  182. STA $0208 ; save sprite Y position
  183. LDA $020C ; load sprite Y position
  184. CLC ; make sure the carry flag is clear
  185. ADC #$01 ; A = A + 1
  186. STA $020C ; save sprite Y position
  187.  
  188. DownButton:
  189. LDA $4016 ; player 1 - Down
  190. AND #%00000001 ; look only at bit 0
  191. BNE LeftButton
  192. LDA $0200 ; load sprite Y position
  193. SEC ; make sure carry flag is set
  194. SBC #$01 ; A = A - 1
  195. STA $0200 ; save sprite Y position
  196. LDA $0204 ; load sprite Y position
  197. SEC ; make sure carry flag is set
  198. SBC #$01 ; A = A - 1
  199. STA $0204 ; save sprite Y position
  200. LDA $0208 ; load sprite Y position
  201. SEC ; make sure carry flag is set
  202. SBC #$01 ; A = A - 1
  203. STA $0208 ; save sprite Y position
  204. LDA $020C ; load sprite Y position
  205. SEC ; make sure carry flag is set
  206. SBC #$01 ; A = A - 1
  207. STA $020C ; save sprite Y position
  208.  
  209. LeftButton:
  210. LDA $4016 ; player 1 - Left
  211. AND #%00000001 ; look only at bit 0
  212. BNE RightButton
  213. LDA $0203 ; load sprite X position
  214. CLC ; make sure the carry flag is clear
  215. ADC #$01 ; A = A + 1
  216. STA $0203 ; save sprite X position
  217. LDA $0207 ; load sprite X position
  218. CLC ; make sure the carry flag is clear
  219. ADC #$01 ; A = A + 1
  220. STA $0207 ; save sprite X position
  221. LDA $020B ; load sprite X position
  222. CLC ; make sure the carry flag is clear
  223. ADC #$01 ; A = A + 1
  224. STA $020B ; save sprite X position
  225. LDA $020F ; load sprite X position
  226. CLC ; make sure the carry flag is clear
  227. ADC #$01 ; A = A + 1
  228. STA $020F ; save sprite X position
  229.  
  230. RightButton:
  231. LDA $4016 ; player 1 - Right
  232. AND #%00000001 ; look only at bit 0
  233. BNE NotRightButton
  234. LDA $0203 ; load sprite X position
  235. SEC ; make sure carry flag is set
  236. SBC #$01 ; A = A - 1
  237. STA $0203 ; save sprite X position
  238. LDA $0207 ; load sprite X position
  239. SEC ; make sure carry flag is set
  240. SBC #$01 ; A = A - 1
  241. STA $0207 ; save sprite X position
  242. LDA $020B ; load sprite X position
  243. SEC ; make sure carry flag is set
  244. SBC #$01 ; A = A - 1
  245. STA $020B ; save sprite X position
  246. LDA $020F ; load sprite X position
  247. SEC ; make sure carry flag is set
  248. SBC #$01 ; A = A - 1
  249. STA $020F ; save sprite X position
  250.  
  251. NotRightButton:
  252. JMP ButtonA
  253.  
  254. RTI ; return from interrupt
  255.  
  256. ;;;;;;;;;;;;;;
  257.  
  258.  
  259.  
  260. .bank 1
  261. .org $E000
  262. palette:
  263. .db $22,$29,$1A,$0F, $22,$36,$17,$0F, $22,$30,$21,$0F, $22,$27,$17,$0F ;;background palette
  264. .db $22,$12,$36,$15, $22,$02,$38,$3C, $22,$1C,$15,$14, $22,$02,$38,$3C ;;sprite palette
  265.  
  266. sprites:
  267. ;vert tile attr horiz
  268. .db $80, $32, $00, $80 ;sprite 0
  269. .db $80, $33, $00, $88 ;sprite 1
  270. .db $88, $34, $00, $80 ;sprite 2
  271. .db $88, $35, $00, $88 ;sprite 3
  272.  
  273.  
  274. background:
  275. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  276. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  277.  
  278. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 2
  279. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  280.  
  281. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  282. .db $24,$24,$24,$24,$24,$24,$24,$24,$36,$37,$24,$24,$24,$24,$24,$24 ;;all sky
  283.  
  284. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 2
  285. .db $24,$24,$24,$24,$24,$24,$24,$35,$25,$25,$38,$24,$24,$24,$24,$24 ;;all sky
  286.  
  287. .db $24,$24,$24,$24,$45,$45,$24,$24,$45,$45,$45,$45,$45,$45,$24,$24 ;;row 3
  288. .db $24,$24,$24,$24,$24,$24,$24,$39,$3A,$3B,$3C,$24,$53,$54,$24,$24 ;;some brick tops
  289.  
  290. .db $24,$24,$24,$24,$47,$47,$24,$24,$47,$47,$47,$47,$47,$47,$24,$24 ;;row 4
  291. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$55,$56,$24,$24 ;;brick bottoms
  292.  
  293. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  294. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  295.  
  296. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 2
  297. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  298.  
  299. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  300. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  301.  
  302. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  303. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  304.  
  305. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  306. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  307.  
  308. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  309. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  310.  
  311. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  312. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  313.  
  314. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  315. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  316.  
  317. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  318. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  319.  
  320. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  321. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  322.  
  323. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  324. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  325.  
  326. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 2
  327. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  328.  
  329. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  330. .db $24,$24,$24,$24,$24,$24,$24,$24,$36,$37,$24,$24,$24,$24,$24,$24 ;;all sky
  331.  
  332. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 2
  333. .db $24,$24,$24,$24,$24,$24,$24,$35,$25,$25,$38,$24,$24,$24,$24,$24 ;;all sky
  334.  
  335. .db $24,$24,$24,$24,$45,$45,$24,$24,$45,$45,$45,$45,$45,$45,$24,$24 ;;row 3
  336. .db $24,$24,$24,$24,$24,$24,$24,$39,$3A,$3B,$3C,$24,$53,$54,$24,$24 ;;some brick tops
  337.  
  338. .db $24,$24,$24,$24,$47,$47,$24,$24,$47,$47,$47,$47,$47,$47,$24,$24 ;;row 4
  339. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$55,$56,$24,$24 ;;brick bottoms
  340.  
  341. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  342. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  343.  
  344. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 2
  345. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  346.  
  347. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  348. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  349.  
  350. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  351. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  352.  
  353. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  354. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  355.  
  356. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  357. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  358.  
  359. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  360. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  361.  
  362. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  363. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  364.  
  365. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  366. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  367.  
  368. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  369. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  370.  
  371. attribute:
  372. .db %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000
  373. .db %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000
  374. .db %00000000, %00000000, %00000000, %00000000, %00000000, %10000000, %10100000, %00000000
  375. .db %00000000, %00000001, %00000101, %00000001, %00000000, %00001000, %00001010, %00000011
  376.  
  377. .db %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000
  378. .db %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000
  379. .db %00000000, %00000000, %00000000, %00000000, %00000000, %10000000, %10100000, %00000000
  380. .db %00000000, %00000001, %00000101, %00000001, %00000000, %00001000, %00001010, %00000011
  381.  
  382.  
  383.  
  384. .org $FFFA ;first of the three vectors starts here
  385. .dw NMI ;when an NMI happens (once per frame if enabled) the
  386. ;processor will jump to the label NMI:
  387. .dw RESET ;when the processor first turns on or is reset, it will jump
  388. ;to the label RESET:
  389. .dw 0 ;external interrupt IRQ is not used in this tutorial
  390.  
  391.  
  392. ;;;;;;;;;;;;;;
  393.  
  394.  
  395. .bank 2
  396. .org $0000
  397. .incbin "mario.chr" ;includes 8KB graphics file from SMB1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement