daily pastebin goal
47%
SHARE
TWEET

Paddle movement

Snakeruler Apr 2nd, 2016 29 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   .inesprg 1 ; Specifies the number of code banks.
  2.   .ineschr 1 ; Specifies the number of chr banks.
  3.   .inesmap 0 ; Specifies the NES mapper used.
  4.   .inesmir 1 ; Specifies VRAM mirroring of the banks.
  5.  
  6.   .bank 1
  7.   .org $FFFA ; Start at $FFFA.
  8.  
  9.   .dw VBlank_Routine ; Location of NMI interrupt.
  10.   .dw Init ; Code to run at reset.
  11.   .dw 0 ; Address during BRK instruction.
  12.  
  13.   .bank 0
  14.   .org $0000
  15.  
  16. IsVBlank .db 0
  17. Ball_V .db 0
  18. Ball_H .db 0
  19.  
  20.   .org $0300 ; OAM copy location
  21. PlayerA_Y: .db 0 ; Y position of the player
  22. PlayerA_T: .db 0 ; Tile number of the player
  23. PlayerA_S: .db 0 ; Special byte of the player
  24. PlayerA_X: .db 0 ; X position of the player
  25. PlayerB_Y: .db 0 ; Y position of the player
  26. PlayerB_T: .db 0 ; Tile number of the player
  27. PlayerB_S: .db 0 ; Special byte of the player
  28. PlayerB_X: .db 0 ; X position of the player
  29. PlayerC_Y: .db 0 ; Y position of the player
  30. PlayerC_T: .db 0 ; Tile number of the player
  31. PlayerC_S: .db 0 ; Special byte of the player
  32. PlayerC_X: .db 0 ; X position of the player
  33. Ball_Y: .db 0
  34. Ball_T: .db 0
  35. Ball_S: .db 0
  36. Ball_X: .db 0
  37.   .org $8000 ; Goto location $8000.
  38.  
  39. VBlank_Routine:
  40.   INC IsVBlank
  41.   RTI ; Return from interrupt.
  42.  
  43. Init:
  44.  
  45.   ; Initialise the PPU.
  46.   LDA #%10001000 ; Load data for register #1 of the PPU into the accumulator.
  47.   STA $2000 ; Saves accumulator to $2000.
  48.   LDA #%10011010 ; Load data for register #2 of the PPU into the accumulator.
  49.   STA $2001 ; Saves accumulator to $2001.
  50.   LDX #$00
  51.   ; Initialise colour palette.
  52.  
  53.   ; We want to access $3F00 in memory, but we cannot access the VRAM.
  54.   ; What we do is use register $2006 and $2007 to read and write.
  55.   ; $2006 - Set the location to read/write data.
  56.   ; $2007 - Read/write location set in $2006.
  57.   LDA #$3F
  58.   STA $2006
  59.   LDA #$00
  60.   STA $2006
  61.  
  62. LoadPalette:
  63.   LDA TilePalette, x
  64.   STA $2007
  65.   INX
  66.   CPX #32
  67.   BNE LoadPalette
  68.  
  69.   ; Apply same sprite settings to all player pieces
  70.   LDA #%00000000
  71.   STA PlayerA_S
  72.   STA PlayerB_S
  73.   STA PlayerC_S
  74.   LDA #%00000001
  75.   STA Ball_S
  76.  
  77.   LDA #1
  78.   STA PlayerB_T
  79.   LDA #2
  80.   STA PlayerC_T
  81.   LDA #3
  82.   STA Ball_T
  83.  
  84.   LDA #128
  85.   STA Ball_X
  86.   STA Ball_Y
  87.  
  88.   LDA #1
  89.   STA Ball_H
  90.   STA Ball_V
  91.  
  92.   LDA #216
  93.   STA PlayerA_Y
  94.   STA PlayerB_Y
  95.   STA PlayerC_Y
  96.  
  97. Loop:
  98.  
  99. WaitVBlank:
  100.   LDA IsVBlank
  101.   CMP #1
  102.   BNE WaitVBlank ; If comparison is false, then branch.
  103.   DEC IsVBlank
  104.  
  105.  
  106.  
  107.   ; ///////////////////////////////////////////////////////////////////////////////////////
  108.   ; Handle gamepad
  109.   ; ///////////////////////////////////////////////////////////////////////////////////////
  110.  
  111.   ; Game pad is at $4016 - strobe it.
  112.   LDA #$01
  113.   STA $4016
  114.   LDA #$00
  115.   STA $4016
  116.  
  117.   ; Read every key and compare to #1 if needed.
  118.   LDA $4016 ; A key.
  119.   LDA $4016 ; B key.
  120.   LDA $4016 ; Select key.
  121.   LDA $4016 ; Start key.
  122.   LDA $4016 ; Up key.
  123.   LDA $4016 ; Down key.
  124.   LDA $4016 ; Left key.
  125.   AND #1
  126.   BNE LeftPress
  127.   LDA $4016 ; Right key.
  128.   AND #1
  129.   BNE RightPress
  130.   JMP DefaultPress
  131.  
  132. RightPress:
  133.   LDA PlayerA_X
  134.   ADC #1
  135.   STA PlayerA_X
  136.   ADC #8
  137.   STA PlayerB_X
  138.   ADC #8
  139.   STA PlayerC_X
  140.   JMP DefaultPress
  141.  
  142. LeftPress:
  143.   LDA PlayerA_X
  144.   SBC #2
  145.   STA PlayerA_X
  146.   ADC #6
  147.   STA PlayerB_X
  148.   ADC #8
  149.   STA PlayerC_X
  150.   JMP DefaultPress
  151.  
  152. DefaultPress:
  153.   ; This will be reached either by default if nothings pressed, or after a key was pressed.  
  154.   LDA #8 ; Left boundary of the level
  155.   CMP PlayerA_X
  156.   BCS CatchL ; If accumulator is smaller than 8
  157.   LDA PlayerC_X
  158.   CMP #240
  159.   BCS CatchR ; If 240 is smaller than acumulator
  160.   JMP NoCatch
  161.  
  162. CatchL:
  163.   LDA #8
  164.   STA PlayerA_X
  165.   ADC #7
  166.   STA PlayerB_X
  167.   ADC #7
  168.   STA PlayerC_X
  169.   JMP NoCatch
  170.  
  171. CatchR:
  172.   LDA #240
  173.   STA PlayerC_X
  174.   SBC #8
  175.   STA PlayerB_X
  176.   SBC #8
  177.   STA PlayerA_X
  178. NoCatch:
  179.  
  180. NoReflect:
  181.   ; ///////////////////////////////////////////////////////////////////////////////////////
  182.   ; Draw sprites
  183.   ; ///////////////////////////////////////////////////////////////////////////////////////
  184.   LDA #3
  185.   STA $4014
  186.   JMP Loop
  187.  
  188. TilePalette: .incbin "palette.pal" ; Include and label the palette we're using.
  189.  
  190.   .bank 2
  191.   .org $0000
  192.   .incbin "background.bkg" ; Includes backround binary data.
  193.   .incbin "sprites.spr" ; Includes sprite binary data.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top