Advertisement
Guest User

Untitled

a guest
Oct 20th, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.32 KB | None | 0 0
  1. .enum $0000 ;;start variables at ram location 0
  2.  
  3. currentvirtpos .dsb 1 ; .rs 1 means reserve one byte of space
  4. .ende
  5.  
  6.  
  7. .ORG $7ff0
  8. Header: ; 16 byte .NES header (iNES format)
  9. .DB "NES", $1a
  10. .DB $02 ; size of PRG ROM in 16kb units
  11. .DB $01 ; size of CHR ROM in 8kb units
  12. .DB #%00000000 ; mapper 0
  13. .DB #%00000000 ; mapper 0
  14. .DB $00
  15. .DB $00
  16. .DB $00
  17. .DB $00
  18. .DB $00
  19. .DB $00
  20. .DB $00
  21. .DB $00
  22.  
  23. .ORG $8000
  24.  
  25. sprite_RAM = $0200
  26.  
  27.  
  28. ;;;;;;;;;;;;;;;
  29.  
  30. .org $C000
  31. RESET:
  32. SEI ; disable IRQs
  33. CLD ; disable decimal mode
  34. LDX #$40
  35. STX $4017 ; disable APU frame IRQ
  36. LDX #$FF
  37. TXS ; Set up stack
  38. INX ; now X = 0
  39. STX $2000 ; disable NMI
  40. STX $2001 ; disable rendering
  41. STX $4010 ; disable DMC IRQs
  42.  
  43. vblankwait1: ; First wait for vblank to make sure PPU is ready
  44. BIT $2002
  45. BPL vblankwait1
  46.  
  47. clrmem:
  48. LDA #$00
  49. STA $0000, x
  50. STA $0100, x
  51. STA $0200, x
  52. STA $0400, x
  53. STA $0500, x
  54. STA $0600, x
  55. STA $0700, x
  56. LDA #$FE
  57. STA $0300, x
  58. INX
  59. BNE clrmem
  60.  
  61. LDA #$00
  62. STA currentvirtpos
  63.  
  64. vblankwait2: ; Second wait for vblank, PPU is ready after this
  65. BIT $2002
  66. BPL vblankwait2
  67.  
  68.  
  69. LoadPalettes:
  70. LDA $2002 ; read PPU status to reset the high/low latch
  71. LDA #$3F
  72. STA $2006 ; write the high byte of $3F00 address
  73. LDA #$00
  74. STA $2006 ; write the low byte of $3F00 address
  75. LDX #$00 ; start out at 0
  76. LoadPalettesLoop:
  77. LDA palette, x ; load data from address (palette + the value in x)
  78. ; 1st time through loop it will load palette+0
  79. ; 2nd time through loop it will load palette+1
  80. ; 3rd time through loop it will load palette+2
  81. ; etc
  82. STA $2007 ; write to PPU
  83. INX ; X = X + 1
  84. CPX #$20 ; Compare X to hex $10, decimal 16 - copying 16 bytes = 4 sprites
  85. BNE LoadPalettesLoop ; Branch to LoadPalettesLoop if compare was Not Equal to zero
  86. ; if compare was equal to 32, keep going down
  87.  
  88.  
  89.  
  90. LoadSprites:
  91. LDX #$00 ; start at 0
  92. LoadSpritesLoop:
  93. LDA sprites, x ; load data from address (sprites + x)
  94. STA $0200, x ; store into RAM address ($0200 + x)
  95. INX ; X = X + 1
  96. CPX #$10 ; Compare X to hex $10, decimal 16
  97. BNE LoadSpritesLoop ; Branch to LoadSpritesLoop if compare was Not Equal to zero
  98. ; if compare was equal to 32, keep going down
  99.  
  100.  
  101.  
  102. LDA #%10000000 ; enable NMI, sprites from Pattern Table 1
  103. STA $2000
  104.  
  105. LDA #%00010000 ; enable sprites
  106. STA $2001
  107.  
  108. Forever:
  109. JMP Forever ;jump back to Forever, infinite loop
  110.  
  111.  
  112. ;------------------------------------
  113.  
  114. NMI:
  115. jsr updatesprites
  116.  
  117. LDA #$00
  118. STA $2003 ; set the low byte (00) of the RAM address
  119. LDA #$02
  120. STA $4014 ; set the high byte (02) of the RAM address, start the transfer
  121.  
  122. RTI ; return from interrupt
  123.  
  124. ;;;;;;;;;;;;;;
  125.  
  126. .org $E000
  127.  
  128. palette:
  129. .db $0f,$03,$13,$23,$0f,$24,$21,$31,$0f,$03,$25,$26,$0f,$09,$19,$29
  130. .db $0f,$03,$13,$23,$0f,$24,$21,$31,$0f,$03,$25,$26,$0f,$09,$19,$29
  131.  
  132. vertpos:
  133. .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
  134. .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
  135. .db $00,$00,$00,$00,$00,$00,$00,$00,$00
  136. .db $00,$00,$00,$00,$00,$00,$00,$00,$00
  137. .db $01,$01,$01,$01,$01,$01,$01,$01,$01
  138. .db $01,$01,$01,$01,$01,$01,$01,$01,$01
  139. .db $00,$00,$00,$00,$00,$00,$00,$00,$00
  140. .db $00,$00,$00,$00,$00,$00,$00,$00,$00
  141.  
  142. .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
  143. .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
  144. .db $00,$00,$00,$00,$00,$00,$00,$00,$00
  145. .db $00,$00,$00,$00,$00,$00,$00,$00,$00
  146. .db $01,$01,$01,$01,$01,$01,$01,$01,$01
  147. .db $01,$01,$01,$01,$01,$01,$01,$01,$01
  148. .db $00,$00,$00,$00,$00,$00,$00,$00,$00
  149. .db $00,$00,$00,$00,$00,$00,$00,$00,$00
  150.  
  151. .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
  152. .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
  153. .db $00,$00,$00,$00,$00,$00,$00,$00,$00
  154. .db $00,$00,$00,$00,$00,$00,$00,$00,$00
  155. .db $01,$01,$01,$01,$01,$01,$01,$01,$01
  156. .db $01,$01,$01,$01,$01,$01,$01,$01,$01
  157. .db $00,$00,$00,$00,$00,$00,$00,$00,$00
  158. .db $00,$00,$00,$00,$00,$00,$00,$00,$00
  159.  
  160. .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
  161. .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
  162. .db $00,$00,$00,$00,$00,$00,$00,$00,$00
  163. .db $00,$00,$00,$00,$00,$00,$00,$00,$00
  164. .db $01,$01,$01,$01,$01,$01,$01,$01,$01
  165. .db $01,$01,$01,$01,$01,$01,$01,$01,$01
  166. .db $00,$00,$00,$00,$00,$00,$00,$00,$00
  167. .db $00,$00,$00,$00,$00,$00,$00,$00,$00
  168.  
  169. sprites:
  170. ;vert tile attr horiz
  171. .db $80, $00, $00, $a4
  172. .db $80, $01, $00, $c9
  173. .db $80, $02, $00, $84
  174. .db $80, $03, $00, $88
  175.  
  176. ;------------------------------------
  177.  
  178. updateconstants: ;constants for the use of the sprite_RAM constant
  179. .db $00 ;4 sprites for each meta sprite, so add $10 for each meta sprite we process
  180.  
  181. ;------------------------------------
  182.  
  183. updatesprites:
  184.  
  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.  
  190. LDA $0200 ; load sprite Y position
  191. CLC ; make sure the carry flag is clear
  192.  
  193. ldx currentvirtpos
  194. ADC vertpos,x ; A = A plus vertposvalue
  195. STA $0200 ; save sprite Y position
  196. inc currentvirtpos
  197.  
  198. LDA sprite_RAM ;vertical updates
  199. STA sprite_RAM+4
  200. CLC
  201. ADC #$8
  202. STA sprite_RAM+8
  203. STA sprite_RAM+12
  204.  
  205. LDA sprite_RAM+3 ;horizontal updates
  206. STA sprite_RAM+11
  207. CLC
  208. ADC #$8
  209. STA sprite_RAM+7
  210. STA sprite_RAM+15
  211.  
  212. rts
  213.  
  214. ;------------------------------------
  215.  
  216.  
  217. ;------------------------------------
  218.  
  219.  
  220.  
  221. .org $FFFA ;first of the three vectors starts here
  222. .dw NMI ;when an NMI happens (once per frame if enabled) the
  223. ;processor will jump to the label NMI:
  224. .dw RESET ;when the processor first turns on or is reset, it will jump
  225. ;to the label RESET:
  226. .dw 0 ;external interrupt IRQ is not used in this tutorial
  227.  
  228.  
  229. ;;;;;;;;;;;;;;
  230.  
  231. .incbin "mario.chr" ;includes 8KB graphics file from SMB1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement