Advertisement
Guest User

Untitled

a guest
Oct 19th, 2015
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.43 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.  
  115.  
  116. NMI:
  117.  
  118.  
  119.  
  120. jsr update_enemy_sprites
  121. jsr movesprites
  122.  
  123.  
  124.  
  125.  
  126. LDA #$00
  127. STA $2003 ; set the low byte (00) of the RAM address
  128. LDA #$02
  129. STA $4014 ; set the high byte (02) of the RAM address, start the transfer
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. RTI ; return from interrupt
  138.  
  139. ;;;;;;;;;;;;;;
  140.  
  141. .org $E000
  142.  
  143. palette:
  144. .db $0f,$03,$13,$23,$0f,$24,$21,$31,$0f,$03,$25,$26,$0f,$09,$19,$29
  145. .db $0f,$03,$13,$23,$0f,$24,$21,$31,$0f,$03,$25,$26,$0f,$09,$19,$29
  146.  
  147. vertpos:
  148. .db $05,$05,$05,$05,$05,$05,$04,$04,$03,$03,$02,$02,$01,$01,$00,$00
  149. .db $00,$00,$Ff,$Ff,$Fe,$Fe,$Fd,$Fd,$Fc,$Fc,$FB,$FB,$FB,$FB,$FB,$FB
  150. .db $05,$05,$05,$05,$05,$05,$04,$04,$03,$03,$02,$02,$01,$01,$00,$00
  151. .db $00,$00,$Ff,$Ff,$Fe,$Fe,$Fd,$Fd,$Fc,$Fc,$FB,$FB,$FB,$FB,$FB,$FB
  152. .db $05,$05,$05,$05,$05,$05,$04,$04,$03,$03,$02,$02,$01,$01,$00,$00
  153. .db $00,$00,$Ff,$Ff,$Fe,$Fe,$Fd,$Fd,$Fc,$Fc,$FB,$FB,$FB,$FB,$FB,$FB
  154. .db $05,$05,$05,$05,$05,$05,$04,$04,$03,$03,$02,$02,$01,$01,$00,$00
  155. .db $00,$00,$Ff,$Ff,$Fe,$Fe,$Fd,$Fd,$Fc,$Fc,$FB,$FB,$FB,$FB,$FB,$FB
  156. .db $05,$05,$05,$05,$05,$05,$04,$04,$03,$03,$02,$02,$01,$01,$00,$00
  157. .db $00,$00,$Ff,$Ff,$Fe,$Fe,$Fd,$Fd,$Fc,$Fc,$FB,$FB,$FB,$FB,$FB,$FB
  158. .db $05,$05,$05,$05,$05,$05,$04,$04,$03,$03,$02,$02,$01,$01,$00,$00
  159. .db $00,$00,$Ff,$Ff,$Fe,$Fe,$Fd,$Fd,$Fc,$Fc,$FB,$FB,$FB,$FB,$FB,$FB
  160. .db $05,$05,$05,$05,$05,$05,$04,$04,$03,$03,$02,$02,$01,$01,$00,$00
  161. .db $00,$00,$Ff,$Ff,$Fe,$Fe,$Fd,$Fd,$Fc,$Fc,$FB,$FB,$FB,$FB,$FB,$FB
  162. .db $05,$05,$05,$05,$05,$05,$04,$04,$03,$03,$02,$02,$01,$01,$00,$00
  163. .db $00,$00,$Ff,$Ff,$Fe,$Fe,$Fd,$Fd,$Fc,$Fc,$FB,$FB,$FB,$FB,$FB,$FB
  164. .db $05,$05,$05,$05,$05,$05,$04,$04,$03,$03,$02,$02,$01,$01,$00,$00
  165. .db $00,$00,$Ff,$Ff,$Fe,$Fe,$Fd,$Fd,$Fc,$Fc,$FB,$FB,$FB,$FB,$FB,$FB
  166.  
  167. sprites:
  168. ;vert tile attr horiz
  169.  
  170.  
  171.  
  172. .db $08, $00, $00, $a4
  173. .db $08, $01, $00, $c9
  174. .db $08, $02, $00, $84
  175. .db $08, $03, $00, $88
  176.  
  177. ;------------------------------------
  178.  
  179. updateconstants: ;constants for the use of the sprite_RAM constant
  180. .db $00 ;4 sprites for each meta sprite, so add $10 for each meta sprite we process
  181.  
  182. ;------------------------------------
  183.  
  184. movesprites:
  185.  
  186. LDA $0203 ; load sprite X position
  187. SEC ; make sure the carry flag is clear
  188. SBC #$01 ; A = A - 1
  189. STA $0203 ; save sprite X position
  190.  
  191. LDA $0200 ; load sprite Y position
  192. CLC ; make sure the carry flag is clear
  193.  
  194. ldx currentvirtpos
  195. ADC vertpos,x ; A = A plus vertposvalue
  196. STA $0200 ; save sprite Y position
  197. inc currentvirtpos
  198.  
  199.  
  200. rts
  201.  
  202. ;------------------------------------
  203.  
  204.  
  205.  
  206. update_enemy_sprites: ;this routine updates the position of the meta sprites relative to each other
  207. LDA sprite_RAM ;vertical updates
  208. STA sprite_RAM+4
  209. CLC
  210. ADC #$8
  211. STA sprite_RAM+8
  212. STA sprite_RAM+12
  213.  
  214. LDA sprite_RAM+3 ;horizontal updates
  215. STA sprite_RAM+11
  216. CLC
  217. ADC #$8
  218. STA sprite_RAM+7
  219. STA sprite_RAM+15
  220.  
  221. RTS
  222.  
  223. ;------------------------------------
  224.  
  225.  
  226.  
  227. .org $FFFA ;first of the three vectors starts here
  228. .dw NMI ;when an NMI happens (once per frame if enabled) the
  229. ;processor will jump to the label NMI:
  230. .dw RESET ;when the processor first turns on or is reset, it will jump
  231. ;to the label RESET:
  232. .dw 0 ;external interrupt IRQ is not used in this tutorial
  233.  
  234.  
  235. ;;;;;;;;;;;;;;
  236.  
  237. .incbin "mario.chr" ;includes 8KB graphics file from SMB1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement