Advertisement
Guest User

Untitled

a guest
Feb 16th, 2012
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.       .inesprg 1   ; 1x 16KB PRG code
  3.       .ineschr 1   ; 1x  8KB CHR data
  4.       .inesmap 0   ; mapper 0 = NROM, no bank swapping
  5.       .inesmir 1   ; background mirroring
  6.      
  7.      
  8. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9. ;;;;;;;VARIABLE DECLARATIONS;;;;;;;
  10. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11.  
  12.       .rsset $0000  ;;start variables at ram location 0
  13.  
  14. gamestate       .rs 1  ; .rs 1 means reserve one byte of space
  15. ballx           .rs 1  ; ball horizontal position
  16. bally           .rs 1  ; ball vertical position
  17. ballup          .rs 1  ; 1 = ball moving up
  18. balldown        .rs 1  ; 1 = ball moving down
  19. ballleft        .rs 1  ; 1 = ball moving left
  20. ballright       .rs 1  ; 1 = ball moving right
  21. ballspeedx      .rs 1  ; ball horizontal speed per frame
  22. ballspeedy      .rs 1  ; ball vertical speed per frame
  23. paddle1ytop     .rs 1  ; player 1 paddle top vertical position
  24. paddle2ytop     .rs 1  ; player 2 paddle top vertical position
  25. paddle1ybot     .rs 1  ; player 1 paddle bottom vertical position
  26. paddle2ybot     .rs 1  ; player 2 paddle bottom vertical position
  27. paddle1speed    .rs 1  ; player 1 paddle speed
  28. paddle2speed    .rs 1  ; player 2 paddle speed
  29. buttons1        .rs 1  ; player 1 gamepad buttons, one bit per button
  30. buttons2        .rs 1  ; player 2 gamepad buttons, one bit per button
  31. score1          .rs 1  ; player 1 score, 0-15
  32. score2          .rs 1  ; player 2 score, 0-15
  33. score1Ones      .rs 1  ; player 1's score's ones digit
  34. score1Tens      .rs 1  ; player 1's score's tens digit
  35. score2Ones      .rs 1  ; player 2's score's ones digit
  36. score2Tens      .rs 1  ; player 2's score's tens digit
  37. AddrLow         .rs 1
  38. AddrHigh        .rs 1
  39. frameCounter    .rs 1
  40. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  48. ;;;;;;;;CONSTANT DECLARATIONS;;;;
  49. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  50. STATETITLE     = $00  ; displaying title screen
  51. STATEPLAYING   = $01  ; move paddles/ball, check for collisions
  52. STATEGAMEOVER  = $02  ; displaying game over screen
  53.  
  54. RIGHTWALL      = $F4  ; when ball reaches one of these, do something
  55. TOPWALL        = $20
  56. BOTTOMWALL     = $E0
  57. LEFTWALL       = $04
  58.  
  59. PADDLE1X       = $08  ; horizontal position for paddles, doesn't move
  60. PADDLE2X       = $F0
  61. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  62.  
  63.      
  64.      
  65.      
  66.       .bank 0
  67.       .org $C000
  68.     RESET:
  69.       SEI          ; disable IRQs
  70.       CLD          ; disable decimal mode
  71.       LDX #$40
  72.       STX $4017    ; disable APU frame IRQ
  73.       LDX #$FF
  74.       TXS          ; Set up stack
  75.       INX          ; now X = 0
  76.       STX $2000    ; disable NMI
  77.       STX $2001    ; disable rendering
  78.       STX $4010    ; disable DMC IRQs
  79.      
  80.     vblankwait1:       ; First wait for vblank to make sure PPU is ready
  81.       BIT $2002
  82.       BPL vblankwait1
  83.      
  84.     clrmem:
  85.       LDA #$00
  86.       STA $0000, x
  87.       STA $0100, x
  88.       STA $0300, x
  89.       STA $0400, x
  90.       STA $0500, x
  91.       STA $0600, x
  92.       STA $0700, x
  93.       LDA #$FE
  94.       STA $0200, x
  95.       INX
  96.       BNE clrmem
  97.        
  98.     vblankwait2:      ; Second wait for vblank, PPU is ready after this
  99.       BIT $2002
  100.       BPL vblankwait2
  101.  
  102.  
  103.      
  104.      JSR InitializeTitle ; set up palettes, background/attributes for title
  105.  
  106.  
  107.      
  108.  
  109. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  110. ;;;;;;;;;MAIN GAME LOGIC;;;;;;;;;;;;;;;;
  111. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  112.     MainLoop:
  113.     CheckTitle:
  114.       JSR WaitForNMI
  115.       LDA gamestate
  116.       CMP #STATETITLE
  117.       BNE CheckPlaying
  118.       JSR ReadController1
  119.       LDA buttons1
  120.       AND #%00010000        ; if START is pressed, turn off screen, update background and initialize sprites/variables
  121.       BEQ CheckPlaying
  122.       JSR InitializeGame
  123.     CheckPlaying:
  124.       JSR WaitForNMI
  125.       LDA gamestate
  126.       CMP #STATEPLAYING
  127.       BNE CheckOver
  128.       JSR ReadController1  ;;get the current button data for player 1
  129.       JSR ReadController2  ;;get the current button data for player 2
  130.       JSR UpdateSprites    ;updating paddles/ball position data
  131.       JSR MoveBall         ;change direction of ball if a bounce occurs
  132.       JSR MovePaddles      ;checking for input and inc/dec paddle position variables
  133.       JSR CheckCollisions  ;checking for ball collisions with paddles or walls
  134.     CheckOver:
  135.       LDA gamestate
  136.       CMP #STATEGAMEOVER
  137.       BNE MainLoop
  138.       JMP MainLoop     ;jump back to MainLoop, infinite loop, waiting for NMI
  139. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  140.      
  141.      
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150. ;;;;;;;;;;
  151. ;;NMI;;;;;
  152. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    
  153.     NMI:
  154.       INC frameCounter
  155.  
  156.       LDA #$00
  157.       STA $2003       ; set the low byte (00) of the RAM address
  158.       LDA #$02
  159.       STA $4014       ; set the high byte (02) of the RAM address, start the transfer
  160.      
  161.       LDA #$00        ;;tell the ppu there is no background scrolling
  162.       STA $2005
  163.       STA $2005
  164.  
  165.       LDA #%00011110   ; enable sprites, disable background, no clipping on left side
  166.       STA $2001
  167.  
  168.       RTI             ; return from interrupt
  169. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  170.      
  171.      
  172.      
  173.  
  174.  
  175. ;;;;;;;;;;;;;;;;;;;;;
  176. ;;;;;SUBROUTINES;;;;;
  177. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  178.    
  179.    
  180.     .include "subroutines.asm"
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187. ;;;;;;;;;;;;;;;;;;;;;;;;
  188. ;;;;;;;; DATA ;;;;;;;;;;
  189. ;;;;;;;;;;;;;;;;;;;;;;;;
  190.  
  191.  
  192.  
  193.       .bank 1
  194.       .org $E000
  195.       .include "data.asm"
  196.  
  197.       .org $FFFA     ;first of the three vectors starts here
  198.       .dw NMI        ;when an NMI happens (once per frame if enabled) the
  199.                        ;processor will jump to the label NMI:
  200.       .dw RESET      ;when the processor first turns on or is reset, it will jump
  201.                        ;to the label RESET:
  202.       .dw 0          ;external interrupt IRQ is not used in this tutorial
  203.      
  204.      
  205.     ;;;;;;;;;;;;;;  
  206.  
  207.  
  208.       .bank 2
  209.       .org $0000
  210.       .incbin "mario.chr"   ;includes 8KB graphics file from SMB1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement