Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2011
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 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. ;; DECLARE SOME VARIABLES HERE
  10. .zp;The .rsset and .rs commands are what you have used before.
  11. ;They work just as well, but I prefer to choose where each variable goes
  12. ;It is up to you if you want to use the other syntax
  13.  
  14. vblank = $00;This variable is used to keep the frame rate fairly steady
  15. ballx = $01
  16. bally = $02
  17.  
  18. paddle1x = $03
  19. paddle1y = $04
  20.  
  21. paddle2x = $05
  22. paddle2y = $06
  23.  
  24. ;Zero page RAM locations $07-$FD are free
  25. buttons1 = $FE;Stores the buttons for player1
  26. buttons2 = $FF;Stores the buttons for player2
  27.  
  28. .code
  29. .bank 0
  30. .org $8000
  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. stx $4015 ;turn off sound
  43.  
  44. vblankwait1: ; First wait for vblank to make sure PPU is ready
  45. BIT $2002
  46. BPL vblankwait1
  47.  
  48. clrmem:
  49. LDA #$00
  50. STA $0000, x
  51. STA $0100, x
  52. STA $0300, x
  53. STA $0400, x
  54. STA $0500, x
  55. STA $0600, x
  56. STA $0700, x
  57. LDA #$FE
  58. STA $0200, x
  59. INX
  60. BNE clrmem
  61.  
  62. vblankwait2: ; Second wait for vblank, PPU is ready after this
  63. BIT $2002
  64. BPL vblankwait2
  65.  
  66.  
  67. LoadPalettes:
  68. LDA #$3F
  69. STA $2006 ; write the high byte of $3F00 address
  70. LDA #$00
  71. STA $2006 ; write the low byte of $3F00 address
  72. LDX #$00 ; start out at 0
  73. LoadPalettesLoop:
  74. LDA palette, x ; load data from address (palette + the value in x)
  75. ; 1st time through loop it will load palette+0
  76. ; 2nd time through loop it will load palette+1
  77. ; 3rd time through loop it will load palette+2
  78. ; etc
  79. STA $2007 ; write to PPU
  80. INX ; X = X + 1
  81. CPX #$20 ; Compare X to hex $10, decimal 16 - copying 16 bytes = 4 sprites
  82. BNE LoadPalettesLoop ; Branch to LoadPalettesLoop if compare was Not Equal to zero
  83. ; if compare was equal to 32, keep going down
  84.  
  85.  
  86. clearnametables:
  87. lda #$20
  88. sta $2006
  89. lda #$00
  90. sta $2006
  91.  
  92. tay
  93.  
  94. ldx #$0C
  95. clearnext:
  96. sta $2007
  97. iny
  98. bne clearnext
  99. dex
  100. bne clearnext
  101.  
  102. LDA #%10010000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
  103. STA $2000
  104.  
  105. LDA #%00011110 ; enable sprites, enable background, no clipping on left side
  106. STA $2001
  107.  
  108.  
  109.  
  110. ;;;Set some initial ball stats
  111. LDA #$50
  112. STA bally
  113.  
  114. LDA #$80
  115. STA ballx
  116.  
  117. main:
  118. lda vblank;This variable will be set to #$FF when the NMI occurs
  119. bpl main;But until it occurs, we will keep branching backwards.
  120. ;This ensures the game runs at a fixed frame rate.
  121.  
  122. lda #$00
  123. sta vblank;This makes vblank 0 again, so when we end up back
  124. ;At the start of the main loop, it will pause until the NMI occurs
  125.  
  126. JSR ReadController1 ;;get the current button data for player 1
  127. JSR ReadController2 ;;get the current button data for player 2
  128.  
  129. JMP main ;jump back to main
  130.  
  131.  
  132.  
  133. NMI:
  134. pha;This pushes a, x, and y to the stack.
  135. txa;Doing this saves them because the nmi will change them
  136. pha;And the NMI can potentially occur any time
  137. tya;while your program is being run
  138. pha
  139.  
  140. lda $2002;read PPU status to reset the high/low latch
  141.  
  142. LDA #$00
  143. STA $2003 ; set the low byte (00) of the RAM address
  144. LDA #$02
  145. STA $4014 ; set the high byte (02) of the RAM address, start the transfer
  146.  
  147. lda #$00
  148. sta $2005;Writes the x scroll low byte
  149. sta $2005;Writes the y scroll low byte
  150.  
  151. lda #$FF
  152. sta <vblank
  153.  
  154. pla;This pulls a, x, and y from the stack.
  155. tay;This is so when the nmi returns to the code
  156. pla;it interrupts, the expected values
  157. tax;will be there
  158. pla
  159.  
  160. RTI ; return from interrupt
  161.  
  162.  
  163. ReadController1:
  164. LDA #$01
  165. STA $4016
  166. LDA #$00
  167. STA $4016
  168. LDX #$08
  169. ReadController1Loop:
  170. LDA $4016
  171. LSR A ; bit0 -> Carry
  172. ROL buttons1 ; bit0 <- Carry
  173. DEX
  174. BNE ReadController1Loop
  175. RTS
  176.  
  177. ReadController2:
  178. LDA #$01
  179. STA $4016
  180. LDA #$00
  181. STA $4016
  182. LDX #$08
  183. ReadController2Loop:
  184. LDA $4017
  185. LSR A ; bit0 -> Carry
  186. ROL buttons2 ; bit0 <- Carry
  187. DEX
  188. BNE ReadController2Loop
  189. RTS
  190.  
  191.  
  192.  
  193.  
  194. ;;;;;;;;;;;;;;
  195.  
  196.  
  197.  
  198. .bank 1
  199. .org $E000
  200. palette:
  201. .db $22,$29,$1A,$0F, $22,$36,$17,$0F, $22,$30,$21,$0F, $22,$27,$17,$0F ;;background palette
  202. .db $22,$1C,$15,$14, $22,$02,$38,$3C, $22,$1C,$15,$14, $22,$02,$38,$3C ;;sprite palette
  203.  
  204.  
  205.  
  206. .org $FFFA ;first of the three vectors starts here
  207. .dw NMI ;when an NMI happens (once per frame if enabled) the
  208. ;processor will jump to the label NMI:
  209. .dw RESET ;when the processor first turns on or is reset, it will jump
  210. ;to the label RESET:
  211. .dw 0 ;external interrupt IRQ is not used in this tutorial
  212.  
  213.  
  214. ;;;;;;;;;;;;;;
  215.  
  216.  
  217. .bank 2
  218. .org $0000
  219. .incbin "mario.chr" ;includes 8KB graphics file from SMB1
  220.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement