Advertisement
Guest User

Pong FrFixed

a guest
Aug 3rd, 2012
270
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. ;; DECLARE SOME VARIABLES HERE
  10.   .rsset $0000  ;;start variables at ram location 0
  11.  
  12. gamestate  .rs 1  ; .rs 1 means reserve one byte of space
  13. ballx      .rs 1  ; ball horizontal position
  14. bally      .rs 1  ; ball vertical position
  15. ballup     .rs 1  ; 1 = ball moving up
  16. balldown   .rs 1  ; 1 = ball moving down
  17. ballleft   .rs 1  ; 1 = ball moving left
  18. ballright  .rs 1  ; 1 = ball moving right
  19. ballspeedx .rs 1  ; ball horizontal speed per frame
  20. ballspeedy .rs 1  ; ball vertical speed per frame
  21. paddle1y      .rs 1  ; paddle vertical position
  22. paddle2y      .rs 1  ; paddle vertical position
  23. paddle1y2      .rs 1  ; paddle vertical position
  24. paddle2y2      .rs 1  ; paddle vertical position
  25. buttons1   .rs 1  ; player 1 gamepad buttons, one bit per button
  26. buttons2   .rs 1  ; player 2 gamepad buttons, one bit per button
  27. scoreOnes     .rs 1  ; byte for each digit in the decimal score
  28. scoreTens     .rs 1
  29. scoreHundreds .rs 1
  30. scoreOnes2     .rs 1  ; byte for each digit in the decimal score
  31. scoreTens2     .rs 1
  32. scoreHundreds2 .rs 1
  33.  
  34.  
  35. ;; DECLARE SOME CONSTANTS HERE
  36. STATETITLE     = $00  ; displaying title screen
  37. STATEPLAYING   = $01  ; move paddles/ball, check for collisions
  38. STATEGAMEOVER  = $02  ; displaying game over screen
  39.  
  40. RIGHTWALL      = $F4  ; when ball reaches one of these, do something
  41. TOPWALL        = $20
  42. BOTTOMWALL     = $E0
  43. LEFTWALL       = $04
  44.  
  45. PADDLE1X       = $08  ; horizontal position for paddles, doesnt move
  46. PADDLE2X       = $F0
  47.  
  48. PS1 = $01  ; paddle vertical speed per frame
  49. PS2 = $01  ; paddle vertical speed per frame
  50.  
  51. ;;;;;;;;;;;;;;;;;;
  52.  
  53.  
  54.  
  55.  
  56.   .bank 0
  57.   .org $C000
  58. RESET:
  59.   SEI          ; disable IRQs
  60.   CLD          ; disable decimal mode
  61.   LDX #$40
  62.   STX $4017    ; disable APU frame IRQ
  63.   LDX #$FF
  64.   TXS          ; Set up stack
  65.   INX          ; now X = 0
  66.   STX $2000    ; disable NMI
  67.   STX $2001    ; disable rendering
  68.   STX $4010    ; disable DMC IRQs
  69.  
  70. vblankwait1:       ; First wait for vblank to make sure PPU is ready
  71.   BIT $2002
  72.   BPL vblankwait1
  73.  
  74. clrmem:
  75.   LDA #$00
  76.   STA $0000, x
  77.   STA $0100, x
  78.   STA $0300, x
  79.   STA $0400, x
  80.   STA $0500, x
  81.   STA $0600, x
  82.   STA $0700, x
  83.   LDA #$FE
  84.   STA $0200, x
  85.   INX
  86.   BNE clrmem
  87.    
  88. vblankwait2:      ; Second wait for vblank, PPU is ready after this
  89.   BIT $2002
  90.   BPL vblankwait2
  91.  
  92.  
  93. LoadPalettes:
  94.   LDA $2002             ; read PPU status to reset the high/low latch
  95.   LDA #$3F
  96.   STA $2006             ; write the high byte of $3F00 address
  97.   LDA #$00
  98.   STA $2006             ; write the low byte of $3F00 address
  99.   LDX #$00              ; start out at 0
  100. LoadPalettesLoop:
  101.   LDA palette, x        ; load data from address (palette + the value in x)
  102.                           ; 1st time through loop it will load palette+0
  103.                           ; 2nd time through loop it will load palette+1
  104.                           ; 3rd time through loop it will load palette+2
  105.                           ; etc
  106.   STA $2007             ; write to PPU
  107.   INX                   ; X = X + 1
  108.   CPX #$20              ; Compare X to hex $10, decimal 16 - copying 16 bytes = 4 sprites
  109.   BNE LoadPalettesLoop  ; Branch to LoadPalettesLoop if compare was Not Equal to zero
  110.                         ; if compare was equal to 32, keep going down
  111.  
  112.  
  113.  
  114.  
  115.  
  116. ;;;Set some initial ball stats
  117.   LDA #$01
  118.   STA balldown
  119.   STA ballright
  120.   LDA #$00
  121.   STA ballup
  122.   STA ballleft
  123.  
  124.   LDA #$50
  125.   STA bally
  126.  
  127.   LDA #$80
  128.   STA ballx
  129.  
  130.   LDA #$06
  131.   STA ballspeedx
  132.   STA ballspeedy
  133.  
  134.   LDA #$50
  135.   STA paddle1y
  136.   STA paddle2y
  137.  
  138.   LDA #$58
  139.   STA paddle1y2
  140.   STA paddle2y2
  141.  
  142.  
  143.   ;;;Set initial score value
  144.   LDA #$00
  145.   STA scoreOnes
  146.   STA scoreTens
  147.   STA scoreHundreds
  148.   STA scoreOnes2
  149.   STA scoreTens2
  150.   STA scoreHundreds2
  151.  
  152.   ;;:Set starting game state
  153.   LDA #STATETITLE
  154.   STA gamestate
  155.  
  156.  
  157.              
  158.   LDA #%10010000   ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
  159.   STA $2000
  160.  
  161.   LDA #%00011110   ; enable sprites, enable background, no clipping on left side
  162.   STA $2001
  163.  
  164. Forever:
  165.   JMP Forever     ;jump back to Forever, infinite loop, waiting for NMI
  166.  
  167.  
  168.  
  169. NMI:
  170.   PLA                ;<--------------ADD THESE
  171.   PLA
  172.   PLA
  173.   LDA #$00
  174.   STA $2003       ; set the low byte (00) of the RAM address
  175.   LDA #$02
  176.   STA $4014       ; set the high byte (02) of the RAM address, start the transfer
  177.  
  178.   JSR DrawScore
  179.   JSR DrawScore2
  180.  
  181.   ;;This is the PPU clean up section, so rendering the next frame starts properly.
  182.   LDA #%10010000   ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
  183.   STA $2000
  184.   LDA #%00011110   ; enable sprites, enable background, no clipping on left side
  185.   STA $2001
  186.   LDA #$00        ;;tell the ppu there is no background scrolling
  187.   STA $2005
  188.   STA $2005
  189.    
  190.   ;;;all graphics updates done by here, run game engine
  191.  
  192.  
  193.   JSR ReadController1  ;;get the current button data for player 1
  194.   JSR ReadController2  ;;get the current button data for player 2
  195.  
  196.  
  197. GameEngine:  
  198.   LDA gamestate
  199.   CMP #STATETITLE
  200.   BEQ EngineTitle    ;;game is displaying title screen
  201.    
  202.   LDA gamestate
  203.   CMP #STATEGAMEOVER
  204.   BEQ EngineGameOver  ;;game is displaying ending screen
  205.  
  206.   LDA gamestate
  207.   CMP #STATEPLAYING
  208.   BEQ EnginePlaying   ;;game is playing
  209. GameEngineDone:  
  210.  
  211.   JSR UpdateSprites  ;;set ball/paddle sprites from positions
  212.  
  213.   JSR MovePaddle1  ;;get the current button data for player 1
  214.   JSR MovePaddle2  ;;get the current button data for player 2  
  215.   JSR CheckPaddleCollision
  216.  
  217. ;  RTI             ; return from interrupt
  218.   JMP Forever
  219.  
  220.  
  221.  
  222. ;;;;;;;;
  223.  
  224. EngineTitle:    
  225.         LDA buttons1
  226.         AND #%00010000
  227.         BEQ .return
  228.         LDA #STATEPLAYING
  229.         STA gamestate
  230.         JMP EnginePlaying
  231. .return
  232.         JMP GameEngine
  233.  
  234. ;;;;;;;;;
  235.  
  236. EngineGameOver:    
  237.         LDA buttons1
  238.         AND #%00010000
  239.         BEQ .return1
  240.         LDA #STATEPLAYING
  241.         STA gamestate
  242.         LDA #$00
  243.   STA scoreOnes
  244.   STA scoreTens
  245.   STA scoreHundreds
  246.   STA scoreOnes2
  247.   STA scoreTens2
  248.   STA scoreHundreds2
  249.         JMP EnginePlaying
  250. .return1
  251.         JMP GameEngine
  252.  
  253. ;;;;;;;;;;;
  254.  
  255. EnginePlaying:
  256.  
  257. MoveBallRight:
  258.   LDA ballright
  259.   BEQ MoveBallRightDone   ;;if ballright=0, skip this section
  260.  
  261.   LDA ballx
  262.   CLC
  263.   ADC ballspeedx        ;;ballx position = ballx + ballspeedx
  264.   STA ballx
  265.  
  266.   LDA ballx
  267.   CMP #RIGHTWALL
  268.   BCC MoveBallRightDone      ;;if ball x < right wall, still on screen, skip next section
  269.   LDA #$00
  270.   STA ballright
  271.   LDA #$01
  272.   STA ballleft         ;;bounce, ball now moving left
  273.   ;;in real game, give point to player 1, reset ball
  274.   jsr IncrementScore1
  275. MoveBallRightDone:
  276.  
  277.  
  278. MoveBallLeft:
  279.   LDA ballleft
  280.   BEQ MoveBallLeftDone   ;;if ballleft=0, skip this section
  281.  
  282.   LDA ballx
  283.   SEC
  284.   SBC ballspeedx        ;;ballx position = ballx - ballspeedx
  285.   STA ballx
  286.  
  287.   LDA ballx
  288.   CMP #LEFTWALL
  289.   BCS MoveBallLeftDone      ;;if ball x > left wall, still on screen, skip next section
  290.   LDA #$01
  291.   STA ballright
  292.   LDA #$00
  293.   STA ballleft         ;;bounce, ball now moving right
  294.   ;;in real game, give point to player 2, reset ball
  295.     jsr IncrementScore2
  296. MoveBallLeftDone:
  297.  
  298.  
  299. MoveBallUp:
  300.   LDA ballup
  301.   BEQ MoveBallUpDone   ;;if ballup=0, skip this section
  302.  
  303.   LDA bally
  304.   SEC
  305.   SBC ballspeedy        ;;bally position = bally - ballspeedy
  306.   STA bally
  307.  
  308.   LDA bally
  309.   CMP #TOPWALL
  310.   BCS MoveBallUpDone      ;;if ball y > top wall, still on screen, skip next section
  311.   LDA #$01
  312.   STA balldown
  313.   LDA #$00
  314.   STA ballup         ;;bounce, ball now moving down
  315. MoveBallUpDone:
  316.  
  317.  
  318. MoveBallDown:
  319.   LDA balldown
  320.   BEQ MoveBallDownDone   ;;if ballup=0, skip this section
  321.  
  322.   LDA bally
  323.   CLC
  324.   ADC ballspeedy        ;;bally position = bally + ballspeedy
  325.   STA bally
  326.  
  327.   LDA bally
  328.   CMP #BOTTOMWALL
  329.   BCC MoveBallDownDone      ;;if ball y < bottom wall, still on screen, skip next section
  330.   LDA #$00
  331.   STA balldown
  332.   LDA #$01
  333.   STA ballup         ;;bounce, ball now moving down
  334. MoveBallDownDone:
  335.   JMP GameEngineDone
  336.  
  337. MovePaddle1:
  338.  
  339.     lda buttons1        ;load the current button state for controller1
  340.     and #%00000100   ;isolate the bit representing "up", by clearing all the other bits
  341.     beq ReadDownDone          ;if the result was 0, then the "up" bit was clear (thus not pressed), so skip the following code
  342.     ;...
  343.  
  344.   LDA $0204 ; load sprite 2 position
  345.   CLC ; make sure carry flag is set
  346.   ADC #PS1 ; A = A - 1
  347.   STA $0204 ; save sprite 2 position
  348.   LDA $0204
  349.   STA paddle1y
  350.   LDA $020C ; load sprite 2 position
  351.   CLC ; make sure carry flag is set
  352.   ADC #PS1 ; A = A - 1
  353.   STA $020C ; save sprite 2 position
  354.   LDA $020C
  355.   STA paddle1y2
  356.   LDA paddle1y2
  357.   CMP #BOTTOMWALL
  358.   BCC ReadDownDone
  359.   SEC  ; make sure carry flag is set
  360.   SBC #$01 ; A = A - 1
  361.   STA paddle1y2
  362.   LDA paddle1y
  363.   SEC  ; make sure carry flag is set
  364.   SBC #$01 ; A = A - 1
  365.   STA paddle1y  
  366.  
  367. ;  LDA paddle1y
  368. ;  SEC
  369. ;  SBC PS1        ;;bally position = bally - ballspeedy
  370. ;  STA paddle1y
  371. ;
  372. ;  LDA paddle1y
  373. ;  CMP #TOPWALL
  374. ;  BCS ReadDownDone      ;;if ball y > top wall, still on screen, skip next section
  375. ;  LDA #$01
  376. ;  STA paddle1down
  377. ;  LDA #$00
  378. ;  STA paddle1down         ;;bounce, ball now moving down  
  379.  
  380. ReadDownDone:
  381.  
  382.     lda buttons1        ;load the current button state for controller1
  383.     and #%00001000   ;isolate the bit representing "up", by clearing all the other bits
  384.     beq ReadUpDone           ;if the result was 0, then the "up" bit was clear (thus not pressed), so skip the following code
  385.     ;...
  386.  
  387. ;  LDA $4016    
  388. ;  CMP #%00001000
  389. ;  BNE ReadUpDone
  390.   LDA $0204 ; load sprite 2 position
  391.   SEC ; make sure carry flag is set
  392.   SBC #PS1 ; A = A - 1
  393.   STA $0204 ; save sprite 2 position
  394.   LDA $0204
  395.   STA paddle1y
  396.   LDA $020C ; load sprite 2 position
  397.   SEC ; make sure carry flag is set
  398.   SBC #PS1 ; A = A - 1
  399.   STA $020C ; save sprite 2 position  
  400.   LDA $020C
  401.   STA paddle1y2
  402.   LDA paddle1y
  403.   CMP #TOPWALL
  404.   BCS ReadUpDone
  405.   CLC ; make sure carry flag is set
  406.   ADC #$01 ; A = A - 1
  407.   STA paddle1y
  408.   LDA paddle1y2  
  409.   CLC ; make sure carry flag is set
  410.   ADC #$01 ; A = A - 1
  411.   STA paddle1y2    
  412. ;  LDA paddle1y
  413. ;  SEC
  414. ;  SBC PS1        ;;bally position = bally - ballspeedy
  415. ;  STA paddle1y
  416. ;
  417. ;  LDA paddle1y
  418. ;  CMP #TOPWALL
  419. ;  BCS ReadUpDone      ;;if ball y > top wall, still on screen, skip next section
  420. ;  LDA #$01
  421. ;  STA paddle1down
  422. ;  LDA #$00
  423. ;  STA paddle1up         ;;bounce, ball now moving down
  424. ReadUpDone:    
  425.   RTS
  426.  
  427. MovePaddle2:
  428.  
  429.     lda buttons2        ;load the current button state for controller1
  430.     and #%00000100   ;isolate the bit representing "up", by clearing all the other bits
  431.     beq MovePaddleDownDone           ;if the result was 0, then the "up" bit was clear (thus not pressed), so skip the following code
  432.     ;...
  433.   LDA $0208 ; load sprite 2 position
  434.   CLC ; make sure carry flag is set
  435.   ADC #PS2 ; A = A - 1
  436.   STA $0208 ; save sprite 2 position
  437.   LDA $0208
  438.   STA paddle2y
  439.   LDA $0210 ; load sprite 2 position
  440.   CLC ; make sure carry flag is set
  441.   ADC #PS2 ; A = A - 1
  442.   STA $0210 ; save sprite 2 position
  443.   LDA $0210
  444.   STA paddle2y2  
  445.   LDA paddle2y2
  446.   CMP #BOTTOMWALL
  447.   BCC MovePaddleDownDone
  448.   SEC  ; make sure carry flag is set
  449.   SBC #$01 ; A = A - 1
  450.   STA paddle2y2
  451.   LDA paddle2y
  452.   SEC  ; make sure carry flag is set
  453.   SBC #$01 ; A = A - 1
  454.   STA paddle2y  
  455.  
  456. MovePaddleDownDone:
  457.  
  458.     lda buttons2        ;load the current button state for controller1
  459.     and #%00001000   ;isolate the bit representing "up", by clearing all the other bits
  460.     beq MovePaddleUpDone           ;if the result was 0, then the "up" bit was clear (thus not pressed), so skip the following code
  461.     ;...
  462.   LDA $0208 ; load sprite 2 position
  463.   SEC ; make sure carry flag is set
  464.   SBC #PS2 ; A = A - 1
  465.   STA $0208 ; save sprite 2 position
  466.   LDA $0208
  467.   STA paddle2y
  468.   LDA $0210 ; load sprite 2 position
  469.   SEC ; make sure carry flag is set
  470.   SBC #PS2 ; A = A - 1
  471.   STA $0210 ; save sprite 2 position
  472.   LDA $0210
  473.   STA paddle2y2  
  474.   LDA paddle2y
  475.   CMP #TOPWALL
  476.   BCS MovePaddleUpDone
  477.   CLC ; make sure carry flag is set
  478.   ADC #$01 ; A = A - 1
  479.   STA paddle2y
  480.   LDA paddle2y2
  481.   CLC ; make sure carry flag is set
  482.   ADC #$01 ; A = A - 1
  483.   STA paddle2y2  
  484.  
  485.   ;;if up button pressed
  486.   ;;  if paddle top > top wall
  487.   ;;    move paddle top and bottom up
  488. MovePaddleUpDone:
  489.   RTS
  490.  
  491.  
  492.  
  493. Skip:
  494.  
  495. CheckPaddleCollision:
  496.   LDA ballx
  497.   CMP #PADDLE1X+8
  498.   BCS CheckPaddleCollisionDone      ;;if ball x > left wall, still on screen, skip next section    
  499.   LDA bally
  500.   CMP paddle1y
  501.   BCS CheckPaddleCollisionDone      ;;if ball y > top wall, still on screen, skip next section  
  502.   LDA bally
  503.   CMP paddle1y2
  504.   BCC CheckPaddleCollisionDone      ;;if ball y < bottom wall, still on screen, skip next section  
  505. ;  LDA ballx
  506. ;  CLC
  507. ;  ADC ballspeedx        ;;ballx position = ballx - ballspeedx
  508. ;  STA ballx
  509.   LDA #$01
  510.   STA ballright  
  511.   LDA #$00
  512.   STA ballleft         ;;bounce, ball now moving right
  513.   LDA bally
  514.   CMP paddle1y2
  515.   BCS .point2
  516.   LDA #$01
  517.   STA ballup  
  518.   LDA #$00
  519.   STA balldown  
  520. ;  LDA bally
  521. ;  SEC
  522. ;  SBC ballspeedy        ;;bally position = bally - ballspeedy
  523. ;  STA bally
  524.   JMP CheckPaddleCollisionDone
  525. .point2
  526. ;  LDA #$01  
  527. ;  LDA bally
  528. ;  CLC
  529. ;  ADC ballspeedy        ;;bally position = bally - ballspeedy
  530. ;  STA bally
  531.   LDA #$01
  532.   STA balldown
  533.   LDA #$00
  534.   STA ballup  
  535.  
  536. ;  LDA #$00
  537. ;  STA ballleft
  538. ;  LDA #$00
  539. ;  STA balldown
  540. ;  LDA #$00
  541. ;  STA ballup  
  542. CheckPaddleCollisionDone:
  543.   RTS
  544. ;  JMP GameEngineDone
  545.  
  546.  
  547.  
  548.  
  549. UpdateSprites:
  550.   LDA bally  ;;update all ball sprite info
  551.   STA $0200
  552.  
  553.   LDA #$30
  554.   STA $0201
  555.  
  556.   LDA #$00
  557.   STA $0202
  558.  
  559.   LDA ballx
  560.   STA $0203
  561.  
  562.   LDA paddle1y  ;;update all ball sprite info
  563.   STA $0204
  564.  
  565.   LDA #$7F
  566.   STA $0205
  567.  
  568.   LDA #$10
  569.   STA $0206
  570.  
  571.   LDA #PADDLE1X
  572.   STA $0207
  573.  
  574.   LDA paddle1y2  ;;update all ball sprite info
  575.   STA $020C
  576.  
  577.   LDA #$7F
  578.   STA $020D
  579.  
  580.   LDA #$10
  581.   STA $020E
  582.  
  583.   LDA #PADDLE1X
  584.   STA $020F
  585.  
  586.   LDA paddle2y
  587.   STA $0208
  588.  
  589.   LDA #$7F
  590.   STA $0209
  591.  
  592.   LDA #$10
  593.   STA $020A
  594.  
  595.   LDA #PADDLE2X
  596.   STA $020B
  597.  
  598.   LDA paddle2y2
  599.   STA $0210
  600.  
  601.   LDA #$7F
  602.   STA $0211
  603.  
  604.   LDA #$10
  605.   STA $0212
  606.  
  607.   LDA #PADDLE2X
  608.   STA $0213  
  609.  
  610.   ;;update paddle sprites
  611.   RTS
  612.  
  613.  
  614. DrawScore:
  615.   LDA $2002
  616.   LDA #$20
  617.   STA $2006
  618.   LDA #$20
  619.   STA $2006          ; start drawing the score at PPU $2020
  620.  
  621. .Zero1  
  622.   LDA scoreHundreds      ; last digit  
  623.   cmp #$00
  624.   beq .pointa
  625.   cmp #$24
  626.   bne .point
  627.   LDA scoreTens      ; next digit
  628.   cmp #$00
  629.   bne .point
  630.   LDA #$24
  631.   STA scoreTens
  632.   JMP .point
  633. .pointa
  634.   LDA #$24
  635.   STA scoreHundreds
  636.  
  637. .point  
  638.   LDA scoreHundreds  ; get first digit
  639. ;  CLC
  640. ;  ADC #$30           ; add ascii offset  (this is UNUSED because the tiles for digits start at 0)
  641.   STA $2007          ; draw to background
  642.   LDA scoreTens      ; next digit
  643. ;  CLC
  644. ;  ADC #$30           ; add ascii offset
  645.   STA $2007
  646.   LDA scoreOnes      ; last digit
  647. ;  CLC
  648. ;  ADC #$30           ; add ascii offset
  649.   STA $2007
  650.   RTS
  651.  
  652. DrawScore2:
  653.   LDA $2002
  654.   LDA #$20
  655.   STA $2006
  656.   LDA #$3C
  657.   STA $2006          ; start drawing the score at PPU $203C
  658.  
  659. .Zero  
  660.   LDA scoreHundreds2      ; last digit  
  661.   cmp #$00
  662.   beq .point2b
  663.   cmp #$24
  664.   bne .point2
  665.   LDA scoreTens2      ; next digit
  666.   cmp #$00
  667.   bne .point2
  668.   LDA #$24
  669.   STA scoreTens2
  670.   JMP .point2
  671. .point2b
  672.   LDA #$24
  673.   STA scoreHundreds2
  674.  
  675. .point2
  676.   LDA scoreHundreds2  ; get first digit  
  677. ;  CLC
  678. ;  ADC #$30           ; add ascii offset  (this is UNUSED because the tiles for digits start at 0)
  679.   STA $2007          ; draw to background
  680.   LDA scoreTens2      ; next digit
  681. ;  CLC
  682. ;  ADC #$30           ; add ascii offset
  683.   STA $2007
  684.   LDA scoreOnes2      ; last digit
  685. ;  CLC
  686. ;  ADC #$30           ; add ascii offset
  687.   STA $2007
  688.   RTS
  689.  
  690.  
  691. IncrementScore1:
  692. IncOnes:
  693.   LDA scoreOnes      ; load the lowest digit of the number
  694.   CLC
  695.   ADC #$01           ; add one
  696.   STA scoreOnes
  697.   CMP #$0A           ; check if it overflowed, now equals 10
  698.   bne IncDone        ; if there was no overflow, all done
  699. IncTens:
  700.   LDA #$00
  701.   STA scoreOnes      ; wrap digit to 0
  702.   LDA scoreTens      ; load the next digit
  703.   cmp #$24
  704.   bne .add
  705.   sec
  706.   sbc #$24
  707.   STA scoreTens
  708. .add  
  709.   LDA scoreTens      ; load the next digit
  710.   CLC
  711.   ADC #$01           ; add one, the carry from previous digit
  712.   STA scoreTens
  713.   CMP #$0A           ; check if it overflowed, now equals 10
  714.   bne IncDone        ; if there was no overflow, all done
  715. IncHundreds:
  716.   LDA #$00
  717.   STA scoreTens      ; wrap digit to 0
  718.   LDA scoreHundreds  ; load the next digit
  719.   cmp #$24
  720.   bne .add1
  721.   sec
  722.   sbc #$24
  723.   STA scoreHundreds
  724. .add1  
  725.   LDA scoreHundreds  ; load the next digit
  726.   CLC
  727.   ADC #$01           ; add one, the carry from previous digit
  728.   STA scoreHundreds  
  729. IncDone:
  730.   JMP IncDone2
  731.  
  732. IncrementScore2:
  733. IncOnes2:
  734.   LDA scoreOnes2      ; load the lowest digit of the number
  735.   CLC
  736.   ADC #$01           ; add one
  737.   STA scoreOnes2
  738.   CMP #$0A           ; check if it overflowed, now equals 10
  739.   BNE IncDone2        ; if there was no overflow, all done
  740. IncTens2:
  741.   LDA #$00
  742.   STA scoreOnes2      ; wrap digit to 0
  743.   LDA scoreTens2      ; load the next digit
  744.   cmp #$24
  745.   bne .add
  746.   sec
  747.   sbc #$24
  748.   STA scoreTens2
  749. .add  
  750.   LDA scoreTens2      ; load the next digit
  751.   CLC
  752.   ADC #$01           ; add one, the carry from previous digit
  753.   STA scoreTens2
  754.   CMP #$0A           ; check if it overflowed, now equals 10
  755.   BNE IncDone2        ; if there was no overflow, all done
  756. IncHundreds2:
  757.   LDA #$00
  758.   STA scoreTens2      ; wrap digit to 0
  759.   LDA scoreHundreds2  ; load the next digit
  760.   cmp #$24
  761.   bne .add1
  762.   sec
  763.   sbc #$24
  764.   STA scoreHundreds2
  765. .add1  
  766.   LDA scoreHundreds2  ; load the next digit
  767.   CLC
  768.   ADC #$01           ; add one, the carry from previous digit
  769.   STA scoreHundreds2
  770. IncDone2:
  771.   LDA scoreHundreds
  772.   cmp #$01
  773.   BEQ GameOver
  774.   LDA scoreHundreds2
  775.   cmp #$01
  776.   BEQ GameOver  
  777.  
  778. ReadController1:
  779.   LDA #$01
  780.   STA $4016
  781.   LDA #$00
  782.   STA $4016
  783.   LDX #$08
  784. ReadController1Loop:
  785.   LDA $4016
  786.   LSR A            ; bit0 -> Carry
  787.   ROL buttons1     ; bit0 <- Carry
  788.   DEX
  789.   BNE ReadController1Loop
  790.   RTS
  791.  
  792. ReadController2:
  793.   LDA #$01
  794.   STA $4016
  795.   LDA #$00
  796.   STA $4016
  797.   LDX #$08
  798. ReadController2Loop:
  799.   LDA $4017
  800.   LSR A            ; bit0 -> Carry
  801.   ROL buttons2     ; bit0 <- Carry
  802.   DEX
  803.   BNE ReadController2Loop
  804.   RTS  
  805.  
  806. GameOver:
  807.         LDA #STATEGAMEOVER
  808.         STA gamestate
  809.         JMP GameEngine
  810.  
  811.    
  812.        
  813. ;;;;;;;;;;;;;;  
  814.  
  815.  
  816.  
  817.   .bank 1
  818.   .org $E000
  819. palette:
  820.   .db $22,$29,$1A,$0F,  $22,$36,$17,$0F,  $22,$30,$21,$0F,  $22,$27,$17,$0F   ;;background palette
  821.   .db $22,$1C,$15,$14,  $22,$02,$38,$3C,  $22,$1C,$15,$14,  $22,$02,$38,$3C   ;;sprite palette
  822.  
  823. sprites:
  824.      ;vert tile attr horiz
  825.         .db $52, $01, $00, $28 ; Player1 paddle top
  826.         .db $5A, $11, $00, $28 ; Player1 paddle bottom
  827.        
  828.         .db $52, $01, $01, $D8 ; Player2 paddle top
  829.         .db $5A, $11, $01, $D8 ; Player2 paddle bottom
  830.        
  831.         .db $74, $02, $02, $78 ; Ball
  832.  
  833.  
  834.  
  835.   .org $FFFA     ;first of the three vectors starts here
  836.   .dw NMI        ;when an NMI happens (once per frame if enabled) the
  837.                    ;processor will jump to the label NMI:
  838.   .dw RESET      ;when the processor first turns on or is reset, it will jump
  839.                    ;to the label RESET:
  840.   .dw 0          ;external interrupt IRQ is not used in this tutorial
  841.  
  842.  
  843. ;;;;;;;;;;;;;;  
  844.  
  845.  
  846.   .bank 2
  847.   .org $0000
  848.   .incbin "mario.chr"   ;includes 8KB graphics file from SMB1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement