Advertisement
Guest User

Some Code-ish

a guest
May 22nd, 2014
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
  10. .bank 0
  11. .org $C000
  12. RESET:
  13. SEI ; disable IRQs
  14. CLD ; disable decimal mode
  15. LDX #$40
  16. STX $4017 ; disable APU frame IRQ
  17. LDX #$FF
  18. TXS ; Set up stack
  19. INX ; now X = 0
  20. STX $2000 ; disable NMI
  21. STX $2001 ; disable rendering
  22. STX $4010 ; disable DMC IRQs
  23.  
  24. vblankwait1: ; First wait for vblank to make sure PPU is ready
  25. BIT $2002
  26. BPL vblankwait1
  27.  
  28. clrmem:
  29. LDA #$00
  30. STA $0000, x
  31. STA $0100, x
  32. STA $0300, x
  33. STA $0400, x
  34. STA $0500, x
  35. STA $0600, x
  36. STA $0700, x
  37. LDA #$FE
  38. STA $0200, x
  39. INX
  40. BNE clrmem
  41.  
  42. vblankwait2: ; Second wait for vblank, PPU is ready after this
  43. BIT $2002
  44. BPL vblankwait2
  45.  
  46.  
  47. LoadPalettes:
  48. LDA $2002 ; read PPU status to reset the high/low latch
  49. LDA #$3F
  50. STA $2006 ; write the high byte of $3F00 address
  51. LDA #$00
  52. STA $2006 ; write the low byte of $3F00 address
  53. LDX #$00 ; start out at 0
  54. LoadPalettesLoop:
  55. LDA palette, x ; load data from address (palette + the value in x)
  56. ; 1st time through loop it will load palette+0
  57. ; 2nd time through loop it will load palette+1
  58. ; 3rd time through loop it will load palette+2
  59. ; etc
  60. STA $2007 ; write to PPU
  61. INX ; X = X + 1
  62. CPX #$20 ; Compare X to hex $10, decimal 16 - copying 16 bytes = 4 sprites
  63. BNE LoadPalettesLoop ; Branch to LoadPalettesLoop if compare was Not Equal to zero
  64. ; if compare was equal to 32, keep going down
  65.  
  66.  
  67.  
  68. LoadSprites:
  69. LDX #$00 ; start at 0
  70. LoadSpritesLoop:
  71. LDA sprites, x ; load data from address (sprites + x)
  72. STA $0200, x ; store into RAM address ($0200 + x)
  73. INX ; X = X + 1
  74. CPX #$20 ; Compare X to hex $10, decimal 16
  75. BNE LoadSpritesLoop ; Branch to LoadSpritesLoop if compare was Not Equal to zero
  76. ; if compare was equal to 16, keep going down
  77.  
  78.  
  79.  
  80. LoadBackground:
  81. LDA $2002 ; read PPU status to reset the high/low latch
  82. LDA #$20
  83. STA $2006 ; write the high byte of $2000 address
  84. LDA #$00
  85. STA $2006 ; write the low byte of $2000 address
  86. LDX #$00 ; start out at 0
  87. LoadBackgroundLoop:
  88. LDA background, x ; load data from address (background + the value in x)
  89. STA $2007 ; write to PPU
  90. INX ; X = X + 1
  91. CPX #$FF ; Compare X to hex $80, decimal 128 - copying 128 bytes
  92. BNE LoadBackgroundLoop ; Branch to LoadBackgroundLoop if compare was Not Equal to zero
  93. ; if compare was equal to 128, keep going down
  94.  
  95.  
  96. LoadAttribute:
  97. LDA $2002 ; read PPU status to reset the high/low latch
  98. LDA #$23
  99. STA $2006 ; write the high byte of $23C0 address
  100. LDA #$C0
  101. STA $2006 ; write the low byte of $23C0 address
  102. LDX #$00 ; start out at 0
  103. LoadAttributeLoop:
  104. LDA attribute, x ; load data from address (attribute + the value in x)
  105. STA $2007 ; write to PPU
  106. INX ; X = X + 1
  107. CPX #$08 ; Compare X to hex $08, decimal 8 - copying 8 bytes
  108. BNE LoadAttributeLoop ; Branch to LoadAttributeLoop if compare was Not Equal to zero
  109. ; if compare was equal to 128, keep going down
  110.  
  111.  
  112.  
  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.  
  172. ; Button stuff here
  173.  
  174. DownButton:
  175. LDA $4016 ; player 1 - Down
  176. AND #%00000001 ; look only at bit 0
  177. BNE LeftButton
  178.  
  179. ; Button stuff here
  180.  
  181. LeftButton:
  182. LDA $4016 ; player 1 - Left
  183. AND #%00000001 ; look only at bit 0
  184. BNE RightButton
  185. LDA $0203 ; load sprite X position
  186. CLC ; make sure the carry flag is clear
  187. ADC #$01 ; A = A + 1
  188. STA $0203 ; save sprite X position
  189. LDA $0207 ; load sprite X position
  190. CLC ; make sure the carry flag is clear
  191. ADC #$01 ; A = A + 1
  192. STA $0207 ; save sprite X position
  193. LDA $020B ; load sprite X position
  194. CLC ; make sure the carry flag is clear
  195. ADC #$01 ; A = A + 1
  196. STA $020B ; save sprite X position
  197. LDA $020F ; load sprite X position
  198. CLC ; make sure the carry flag is clear
  199. ADC #$01 ; A = A + 1
  200. STA $020F ; save sprite X position
  201. LDA $0213
  202. CLC
  203. ADC #$01
  204. STA $0213
  205. LDA $0217
  206. CLC
  207. ADC #$01
  208. STA $0217
  209. LDA $021B
  210. CLC
  211. ADC #$01
  212. STA $021B
  213. LDA $021F
  214. CLC
  215. ADC #$01
  216. STA $021F
  217.  
  218. RightButton:
  219. LDA $4016 ; player 1 - Right
  220. AND #%00000001 ; look only at bit 0
  221. BNE NotRightButton
  222. LDA $0203 ; load sprite X position
  223. SEC ; make sure carry flag is set
  224. SBC #$01 ; A = A - 1
  225. STA $0203 ; save sprite X position
  226. LDA $0207 ; load sprite X position
  227. SEC ; make sure carry flag is set
  228. SBC #$01 ; A = A - 1
  229. STA $0207 ; save sprite X position
  230. LDA $020B ; load sprite X position
  231. SEC ; make sure carry flag is set
  232. SBC #$01 ; A = A - 1
  233. STA $020B ; save sprite X position
  234. LDA $020F ; load sprite X position
  235. SEC ; make sure carry flag is set
  236. SBC #$01 ; A = A - 1
  237. STA $020F ; save sprite X position
  238. LDA $0213
  239. CLC
  240. ADC #$01
  241. STA $0213
  242. LDA $0217
  243. CLC
  244. ADC #$01
  245. STA $0217
  246. LDA $021B
  247. CLC
  248. ADC #$01
  249. STA $021B
  250. LDA $021F
  251. CLC
  252. ADC #$01
  253. STA $021F
  254.  
  255. NotRightButton:
  256. JMP ButtonA
  257.  
  258. RTI ; return from interrupt
  259.  
  260. ;;;;;;;;;;;;;;
  261.  
  262.  
  263. ;;;;;;;;;;;;;;
  264.  
  265.  
  266.  
  267. .bank 1
  268. .org $E000
  269. palette:
  270. .db $22,$0F,$27,$26, $22,$0F,$16,$26, $22,$30,$21,$0F, $22,$27,$17,$0F ;;background palette
  271. .db $22,$0F,$27,$1A, $22,$0F,$27,$26, $22,$1C,$15,$14, $22,$02,$38,$3C ;;sprite palette
  272.  
  273. sprites:
  274. ;vert tile attr horiz
  275. .db $80, $00, $00, $80 ;sprite 0
  276. .db $80, $01, $00, $88 ;sprite 1
  277. .db $88, $10, $00, $80 ;sprite 2
  278. .db $88, $11, $00, $88 ;sprite 3
  279. .db $90, $20, $00, $80 ;sprite 4
  280. .db $90, $21, $00, $88 ;sprite 5
  281. .db $98, $30, $00, $80 ;sprite 6
  282. .db $98, $31, $00, $88 ;sprite 7
  283.  
  284.  
  285. background:
  286. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
  287. .db $24,$24,$24,$24,$24,$24,$24,$24,$08,$09,$0A,$0B,$24,$24,$24,$24 ;;first tile of sun
  288.  
  289. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 2
  290. .db $24,$24,$24,$24,$24,$24,$24,$24,$18,$19,$1A,$1B,$24,$24,$24,$24 ;;second tile of sun
  291.  
  292. .db $24,$24,$24,$24,$24,$24,$01,$02,$01,$02,$24,$24,$01,$02,$01,$02 ;;row 3
  293. .db $24,$24,$01,$02,$01,$02,$24,$24,$28,$29,$2A,$2B,$24,$24,$24,$24 ;;third tile of sun with first tile of block
  294.  
  295. .db $24,$24,$24,$24,$24,$24,$11,$12,$11,$12,$24,$24,$11,$12,$11,$12 ;;row 4
  296. .db $24,$24,$11,$12,$11,$12,$24,$24,$38,$39,$3A,$3B,$24,$24,$24,$24 ;;forth and last tile of sun with the second and last tile of block
  297.  
  298. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 5
  299. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  300.  
  301. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 6
  302. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  303.  
  304. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 7
  305. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  306.  
  307. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 8
  308. .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
  309.  
  310. attribute:
  311. .db %00000000, %00010000, %01010000, %00010000, %00000000, %00000000, %00000000, %00110000
  312.  
  313. .db $24,$24,$24,$24, $47,$47,$24,$24 ,$47,$47,$47,$47, $47,$47,$24,$24 ,$24,$24,$24,$24 ,$24,$24,$24,$24, $24,$24,$24,$24, $55,$56,$24,$24 ;;brick bottoms
  314.  
  315.  
  316.  
  317. .org $FFFA ;first of the three vectors starts here
  318. .dw NMI ;when an NMI happens (once per frame if enabled) the
  319. ;processor will jump to the label NMI:
  320. .dw RESET ;when the processor first turns on or is reset, it will jump
  321. ;to the label RESET:
  322. .dw 0 ;external interrupt IRQ is not used in this tutorial
  323.  
  324.  
  325. ;;;;;;;;;;;;;;
  326.  
  327.  
  328. .bank 2
  329. .org $0000
  330. .incbin "eddinlevel.chr" ;includes 8KB graphics file from SMB1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement