Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .inesprg 1 ; 1x 16KB PRG code
- .ineschr 1 ; 1x 8KB CHR data
- .inesmap 0 ; mapper 0 = NROM, no bank swapping
- .inesmir 1 ; background mirroring
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;VARIABLE DECLARATIONS;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- .rsset $0000 ;;start variables at ram location 0
- gamestate .rs 1 ; .rs 1 means reserve one byte of space
- ballx .rs 1 ; ball horizontal position
- bally .rs 1 ; ball vertical position
- ballup .rs 1 ; 1 = ball moving up
- balldown .rs 1 ; 1 = ball moving down
- ballleft .rs 1 ; 1 = ball moving left
- ballright .rs 1 ; 1 = ball moving right
- ballspeedx .rs 1 ; ball horizontal speed per frame
- ballspeedy .rs 1 ; ball vertical speed per frame
- paddle1ytop .rs 1 ; player 1 paddle top vertical position
- paddle2ytop .rs 1 ; player 2 paddle top vertical position
- paddle1ybot .rs 1 ; player 1 paddle bottom vertical position
- paddle2ybot .rs 1 ; player 2 paddle bottom vertical position
- paddle1speed .rs 1 ; player 1 paddle speed
- paddle2speed .rs 1 ; player 2 paddle speed
- buttons1 .rs 1 ; player 1 gamepad buttons, one bit per button
- buttons2 .rs 1 ; player 2 gamepad buttons, one bit per button
- score1 .rs 1 ; player 1 score, 0-15
- score2 .rs 1 ; player 2 score, 0-15
- score1Ones .rs 1 ; player 1's score's ones digit
- score1Tens .rs 1 ; player 1's score's tens digit
- score2Ones .rs 1 ; player 2's score's ones digit
- score2Tens .rs 1 ; player 2's score's tens digit
- AddrLow .rs 1
- AddrHigh .rs 1
- frameCounter .rs 1
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;CONSTANT DECLARATIONS;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- STATETITLE = $00 ; displaying title screen
- STATEPLAYING = $01 ; move paddles/ball, check for collisions
- STATEGAMEOVER = $02 ; displaying game over screen
- RIGHTWALL = $F4 ; when ball reaches one of these, do something
- TOPWALL = $20
- BOTTOMWALL = $E0
- LEFTWALL = $04
- PADDLE1X = $08 ; horizontal position for paddles, doesn't move
- PADDLE2X = $F0
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- .bank 0
- .org $C000
- RESET:
- SEI ; disable IRQs
- CLD ; disable decimal mode
- LDX #$40
- STX $4017 ; disable APU frame IRQ
- LDX #$FF
- TXS ; Set up stack
- INX ; now X = 0
- STX $2000 ; disable NMI
- STX $2001 ; disable rendering
- STX $4010 ; disable DMC IRQs
- vblankwait1: ; First wait for vblank to make sure PPU is ready
- BIT $2002
- BPL vblankwait1
- clrmem:
- LDA #$00
- STA $0000, x
- STA $0100, x
- STA $0300, x
- STA $0400, x
- STA $0500, x
- STA $0600, x
- STA $0700, x
- LDA #$FE
- STA $0200, x
- INX
- BNE clrmem
- vblankwait2: ; Second wait for vblank, PPU is ready after this
- BIT $2002
- BPL vblankwait2
- ;; LOAD PALETTES, BACKGROUND, ATTRIBUTES
- LoadPalettes:
- LDA $2002 ; read PPU status to reset the high/low latch
- LDA #$3F
- STA $2006 ; write the high byte of $3F00 address
- LDA #$00
- STA $2006 ; write the low byte of $3F00 address
- LDX #$00 ; start out at 0
- LoadPalettesLoop:
- LDA palette, x ; load data from address (palette + the value in x)
- ; 1st time through loop it will load palette+0
- ; 2nd time through loop it will load palette+1
- ; 3rd time through loop it will load palette+2
- ; etc
- STA $2007 ; write to PPU
- INX ; X = X + 1
- CPX #$20 ; Compare X to hex $20, decimal 32 - copying 32 bytes = 8 sprites
- BNE LoadPalettesLoop ; Branch to LoadPalettesLoop if compare was Not Equal to zero
- ; if compare was equal to 32, keep going down
- LoadTitleScreen:
- LDA $2002 ; read PPU status to reset the high/low latch
- LDA #$20
- STA $2006 ; write the high byte of $2000 address
- LDA #$00
- STA $2006 ; write the low byte of $2000 address
- LDA #low(title)
- STA AddrLow
- LDA #high(title)
- STA AddrHigh
- LDX #$04 ; Loop X 4 times
- LDY #$00 ; Loop Y 256 times
- LoadTitleLoop:
- LDA [AddrLow],y
- STA $2007
- INY
- BNE LoadTitleLoop
- ; Outer loop
- INC AddrHigh ; increment high byte of address backg to next 256 byte chunk
- DEX ; one chunk done so X = X - 1.
- BNE LoadTitleLoop ; if X isn't zero, do again
- ;;:Set starting game state
- LDA #STATETITLE
- STA gamestate
- ;;This is the PPU clean up section, so rendering the next frame starts properly.
- LDA #%10010000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
- STA $2000
- LDA #%00011110 ; enable sprites, enable background, no clipping on left side
- STA $2001
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;MAIN GAME LOGIC;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- MainLoop:
- CheckTitle:
- JSR WaitForNMI
- LDA gamestate
- CMP #STATETITLE
- BNE CheckPlaying
- JSR ReadController1
- LDA buttons1
- AND #%00010000
- BEQ CheckPlaying
- JSR InitializeGame
- CheckPlaying:
- JSR WaitForNMI
- LDA gamestate
- CMP #STATEPLAYING
- BNE CheckOver
- JSR ReadController1 ;;get the current button data for player 1
- JSR ReadController2 ;;get the current button data for player 2
- JSR UpdateSprites
- JSR MoveBall
- JSR MovePaddles
- JSR CheckCollisions
- CheckOver:
- LDA gamestate
- CMP #STATEGAMEOVER
- BNE MainLoop
- JMP MainLoop ;jump back to MainLoop, infinite loop, waiting for NMI
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;
- ;;NMI;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- NMI:
- INC frameCounter
- LDA #$00
- STA $2003 ; set the low byte (00) of the RAM address
- LDA #$02
- STA $4014 ; set the high byte (02) of the RAM address, start the transfer
- LDA #$00 ;;tell the ppu there is no background scrolling
- STA $2005
- STA $2005
- LDA #%00011110 ; enable sprites, disable background, no clipping on left side
- STA $2001
- RTI ; return from interrupt
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;
- ;;;;;SUBROUTINES;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;***************
- ;INITIALIZE GAME
- ;******************************************************************
- InitializeGame:
- LDA #$00
- STA $2000
- STA $2001
- ;;;;;;;;LOAD ALL BACKGROUND INFO FOR GAME PLAYING STATE
- LoadBackgroundScreen:
- LDA $2002 ; read PPU status to reset the high/low latch
- LDA #$20
- STA $2006 ; write the high byte of $2000 address
- LDA #$00
- STA $2006 ; write the low byte of $2000 address
- LDA #low(background)
- STA AddrLow
- LDA #high(background)
- STA AddrHigh
- LDX #$04 ; Loop X 4 times
- LDY #$00 ; Loop Y 256 times
- LoadBackgroundLoop:
- LDA [AddrLow],y
- STA $2007
- INY
- BNE LoadBackgroundLoop
- ; Outer loop
- INC AddrHigh ; increment high byte of address backg to next 256 byte chunk
- DEX ; one chunk done so X = X - 1.
- BNE LoadBackgroundLoop ; if X isn't zero, do again
- ;;;INITIALIZATION
- ;;BALL STATS
- LDA #$01 ; True
- STA balldown ; Here we set direction components of ball vector
- STA ballright
- LDA #$00 ; False
- STA ballup
- STA ballleft
- LDA #$78 ; Vertical center of screen
- STA bally
- LDA #$80 ; Horizontal center of screen
- STA ballx
- LDA #$01 ; Ball will move 1 pixel at a time
- STA ballspeedx
- STA ballspeedy
- LDA #$75 ; Ball will look like top of flagpole from SMB
- STA $0201
- LDA #$01 ; Ball will use first set of 4 colors from sprite palette
- STA $0202
- ;;;PADDLES Y-COORDINATES
- LDA #$70 ; Align top of paddle near center
- STA paddle1ytop
- STA paddle2ytop
- LDA #$90 ; Align bottom of paddle near center
- STA paddle1ybot
- STA paddle2ybot
- ;;;LOADING TILES FOR PADDLE GRAPHICS
- LDX #$00
- Load_Paddle_Tile:
- LDA #$5B ; In mario.chr this is one of the platform graphics from SMB
- STA $0205, x ; $0205 is paddle 1's top tile y-coordinate
- STA $0215, x ; $0215 is paddle 2's top tile y-coordinate
- INX
- INX
- INX ; Increasing X by 4 shifts over 4 bytes in memory to reach next y-coordinate for next paddle tile
- INX
- CPX #$10 ; Once we hit 16, we've loaded 4 tiles (each paddle is 4 tiles high)
- BNE Load_Paddle_Tile
- ;;;LOADING ATTRIBUTES FOR EACH PADDLE
- LDX #$00
- Load_Paddle_Attr:
- LDA #$01 ; Use the first set of 4 colors from sprites
- STA $0206, x ; $0206 is paddle 1's top tile attribute
- STA $0216, x ; $0216 is paddle 2's top tile attribute
- INX
- INX
- INX
- INX
- CPX #$10
- BNE Load_Paddle_Attr
- ;;;LOADING X-COORDINATES FOR EACH PADDLE
- LDX #$00
- Load_Paddle_X:
- LDA #PADDLE1X ; Paddles can't move horizontally
- STA $0207, x ; $0207 is paddle 1's top tile x-coordinate
- LDA #PADDLE2X
- STA $0217, x ; $0217 is paddle 2's top tile x-coordinate
- INX
- INX
- INX
- INX
- CPX #$10
- BNE Load_Paddle_X
- ;;;PADDLE SPEEDS
- Load_Paddle_Speeds:
- LDA #$01 ; Paddles can initially move 1 pixel per frame
- STA paddle1speed
- STA paddle2speed
- ;;Set scores
- LDA #$00
- STA score1Ones ; Zero out placeholders (these numbers are drawn to screen)
- STA score1Tens
- STA score2Ones
- STA score2Tens
- STA score1 ; Zero out actual scores which get checked for win conditions
- STA score2
- LDA #STATEPLAYING ; Change state to playing
- STA gamestate
- LDA #%10010000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
- STA $2000
- RTS
- ;******************************************************************
- ;***************
- ;UPDATE SPRITES
- ;******************************************************************
- UpdateSprites:
- LDA bally ; Update ball y-coordinate
- STA $0200
- LDA ballx ; Update ball x-coordinate
- STA $0203
- LDX #$00 ; Clear out indices
- LDY #$00
- Load_Paddle_Y:
- LDA paddle1ytop ; Load all y-coordinates for paddle 1 relative to the top tile y-coordinate
- CLC
- ADC vertical_offsets, y
- STA $0204, x
- LDA paddle2ytop ; Load all y-coordinates for paddle 2 relative to the top tile y-coordinate
- CLC
- ADC vertical_offsets, y
- STA $0214, x
- INX
- INX
- INX
- INX
- INY
- CPY #$04
- BNE Load_Paddle_Y
- RTS
- ;******************************************************************
- ;***************
- ;UPDATE SCORE
- ;******************************************************************
- UpdateScore:
- LDA #$00
- STA $2000
- STA $2001
- LDA $2002
- LDA #$20
- STA $2006
- LDA #$42
- STA $2006 ; start drawing player 1 score at PPU $2042
- LDA score1Tens ; first digit
- STA $2007 ; draw to background
- LDA score1Ones ; last digit
- STA $2007
- LDA $2002 ; start drawing player 2 score at PPU $203E
- LDA #$20
- STA $2006
- LDA #$5A
- STA $2006
- LDA score2Tens
- STA $2007
- LDA score2Ones
- STA $2007
- LDA #%10010000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
- STA $2000
- RTS
- ;******************************************************************
- ;***************
- ;INCREMENT SCORE 1
- ;******************************************************************
- IncrementScore1:
- Inc1Ones:
- LDA score1Ones ; load the lowest digit of the number
- CLC
- ADC #$01 ; add one
- STA score1Ones
- CMP #$0A ; check if it overflowed, now equals 10
- BNE Check1Score ; if there was no overflow, all done
- Inc1Tens:
- LDA #$00
- STA score1Ones ; wrap digit to 0
- LDA score1Tens ; load the next digit
- CLC
- ADC #$01 ; add one, the carry from previous digit
- STA score1Tens
- Check1Score:
- LDA score1 ; This variable will be used to check win conditions
- CLC
- ADC #$01
- STA score1
- CMP #$10 ; Compare to 16. If equal to 16, we have a winner
- BNE Inc1Done
- LDA STATEGAMEOVER
- STA gamestate
- Inc1Done:
- JSR PlayerScored
- RTS
- ;******************************************************************
- ;***************
- ;INCREMENT SCORE 2
- ;******************************************************************
- IncrementScore2:
- Inc2Ones:
- LDA score2Ones ; load the lowest digit of the number
- CLC
- ADC #$01 ; add one
- STA score2Ones
- CMP #$0A ; check if it overflowed, now equals 10
- BNE Check2Score ; if there was no overflow, all done
- Inc2Tens:
- LDA #$00
- STA score2Ones ; wrap digit to 0
- LDA score2Tens ; load the next digit
- CLC
- ADC #$01 ; add one, the carry from previous digit
- STA score2Tens
- Check2Score:
- LDA score2 ; This variable will be used to check win conditions
- CLC
- ADC #$01
- STA score2
- CMP #$10 ; Compare to 16. If equal to 16, we have a winner
- BNE Inc2Done
- LDA STATEGAMEOVER
- STA gamestate
- Inc2Done:
- JSR PlayerScored
- RTS
- ;******************************************************************
- ;***************
- ;READ CONTROLLER 1
- ;******************************************************************
- ;; In the following subroutines, we loop through controller input and store each button state in a bit
- ;; The order (from left to right) is: A, B, Select, Start, Up, Down, Left, Right
- ReadController1:
- LDA #$01
- STA $4016
- LDA #$00
- STA $4016
- LDX #$08
- ReadController1Loop:
- LDA $4016
- LSR A ; bit0 -> Carry
- ROL buttons1 ; bit0 <- Carry
- DEX
- BNE ReadController1Loop
- RTS
- ;******************************************************************
- ;***************
- ;READ CONTROLLER 2
- ;******************************************************************
- ReadController2:
- LDA #$01
- STA $4016
- LDA #$00
- STA $4016
- LDX #$08
- ReadController2Loop:
- LDA $4017
- LSR A ; bit0 -> Carry
- ROL buttons2 ; bit0 <- Carry
- DEX
- BNE ReadController2Loop
- RTS
- ;******************************************************************
- ;***************
- ;INCREASE BALL SPEED X
- ;******************************************************************
- IncreaseBallSpeedX:
- LDA ballspeedx
- CLC
- ADC #$01
- STA ballspeedx
- RTS
- ;******************************************************************
- ;***************
- ;INCREASE BALL SPEED Y
- ;******************************************************************
- IncreaseBallSpeedY:
- LDA ballspeedy
- CLC
- ADC #$01
- STA ballspeedy
- RTS
- ;******************************************************************
- ;***************
- ;PLAYER SCORED
- ;******************************************************************
- PlayerScored:
- JSR UpdateScore
- LDA #$01
- STA ballspeedx
- STA ballspeedy
- STA paddle1speed
- STA paddle2speed
- LDA #$78
- STA bally
- LDA #$80
- STA ballx
- RTS
- ;******************************************************************
- ;***************
- ;MOVE BALL
- ;******************************************************************
- MoveBall:
- MoveBallRight:
- LDA ballright
- BEQ MoveBallRightDone ;;if ballright=0, skip this section
- LDA ballx
- CLC
- ADC ballspeedx ;;ballx position = ballx + ballspeedx
- STA ballx
- LDA ballx
- CMP #RIGHTWALL
- BCC MoveBallRightDone ;;if ball x < right wall, still on screen, skip next section
- LDA #$00
- STA ballright
- LDA #$01
- STA ballleft ;;bounce, ball now moving left
- JSR IncrementScore1 ;;give point to player 1, reset ball
- MoveBallRightDone:
- MoveBallLeft:
- LDA ballleft
- BEQ MoveBallLeftDone ;;if ballleft=0, skip this section
- LDA ballx
- SEC
- SBC ballspeedx ;;ballx position = ballx - ballspeedx
- STA ballx
- LDA ballx
- CMP #LEFTWALL
- BCS MoveBallLeftDone ;;if ball x > left wall, still on screen, skip next section
- LDA #$01
- STA ballright
- LDA #$00
- STA ballleft ;;bounce, ball now moving right
- JSR IncrementScore2 ;;give point to player 2, reset ball
- MoveBallLeftDone:
- MoveBallUp:
- LDA ballup
- BEQ MoveBallUpDone ;;if ballup=0, skip this section
- LDA bally
- SEC
- SBC ballspeedy ;;bally position = bally - ballspeedy
- STA bally
- LDA bally
- CMP #TOPWALL
- BCS MoveBallUpDone ;;if ball y > top wall, still on screen, skip next section
- LDA #$01
- STA balldown
- LDA #$00
- STA ballup ;;bounce, ball now moving down
- MoveBallUpDone:
- MoveBallDown:
- LDA balldown
- BEQ MoveBallDownDone ;;if ballup=0, skip this section
- LDA bally
- CLC
- ADC ballspeedy ;;bally position = bally + ballspeedy
- STA bally
- LDA bally
- CMP #BOTTOMWALL
- BCC MoveBallDownDone ;;if ball y < bottom wall, still on screen, skip next section
- LDA #$00
- STA balldown
- LDA #$01
- STA ballup ;;bounce, ball now moving down
- MoveBallDownDone:
- RTS
- ;******************************************************************
- ;***************
- ;MOVE PADDLES
- ;******************************************************************
- MovePaddles:
- MovePaddle1Up:
- LDA buttons1
- AND #%00001000
- BEQ MovePaddle1UpDone ; Use BEQ because zero flag will be set if result of AND operation is false
- ;;if up button pressed, move paddle up
- LDA paddle1ytop
- SEC
- SBC paddle1speed
- STA paddle1ytop
- LDA paddle1ybot
- SEC
- SBC paddle1speed
- STA paddle1ybot
- ;; if paddle top > top wall
- LDA paddle1ytop
- CMP #TOPWALL
- BCS MovePaddle1UpDone
- LDA #TOPWALL
- STA paddle1ytop ;set top tile y-coordinate to TOPWALL
- CLC
- ADC #$20 ;bottom of paddle is 32 pixels below TOPWALL, so have to keep it set there
- STA paddle1ybot ;otherwise, bottom y-coordinate will decrease when up is pushed
- MovePaddle1UpDone:
- MovePaddle2Up:
- LDA buttons2
- AND #%00001000
- BEQ MovePaddle2UpDone
- ;; if up button pressed, move paddle up
- LDA paddle2ytop
- SEC
- SBC paddle2speed
- STA paddle2ytop
- LDA paddle2ybot
- SEC
- SBC paddle2speed
- STA paddle2ybot
- ;; if paddle top > top wall
- LDA paddle2ytop
- CMP #TOPWALL
- BCS MovePaddle2UpDone
- LDA #TOPWALL
- STA paddle2ytop ;set top tile y-coordinate to TOPWALL
- CLC
- ADC #$20 ;bottom of paddle is 32 pixels below TOPWALL, so have to keep it set there
- STA paddle2ybot ;otherwise, bottom y-coordinate will decrease when up is pushed
- MovePaddle2UpDone:
- MovePaddle1Down:
- LDA buttons1
- AND #%00000100
- BEQ MovePaddle1DownDone
- ;;if down button pressed
- LDA paddle1ytop
- CLC
- ADC paddle1speed
- STA paddle1ytop
- LDA paddle1ybot
- CLC
- ADC paddle1speed
- STA paddle1ybot
- ;; if paddle bottom < bottom wall
- LDA paddle1ybot
- CMP #BOTTOMWALL
- BCC MovePaddle1DownDone
- LDA #BOTTOMWALL ;set bottom tile y-coordinate to BOTTOMWALL
- STA paddle1ybot
- SEC
- SBC #$20 ;top of paddle is 32 pixels above BOTTOMWALL, so have to keep it set there
- STA paddle1ytop ;otherwise, top y-coordinate will increase when down is pushed
- MovePaddle1DownDone:
- MovePaddle2Down:
- LDA buttons2
- AND #%00000100
- BEQ MovePaddle2DownDone
- ;;if down button pressed
- LDA paddle2ytop
- CLC
- ADC paddle2speed
- STA paddle2ytop
- LDA paddle2ybot
- CLC
- ADC paddle2speed
- STA paddle2ybot
- ;; if paddle bottom < bottom wall
- LDA paddle2ybot
- CMP #BOTTOMWALL
- BCC MovePaddle2DownDone
- LDA #BOTTOMWALL
- STA paddle2ybot ;set bottom tile y-coordinate to BOTTOMWALL
- SEC
- SBC #$20 ;top of paddle is 32 pixels above BOTTOMWALL, so have to keep it set there
- STA paddle2ytop ;otherwise, top y-coordinate will increase when down is pushed
- MovePaddle2DownDone:
- RTS
- ;******************************************************************
- ;***************
- ;CHECK COLLISIONS
- ;******************************************************************
- CheckCollisions:
- CheckPaddle1Collision:
- ;;if ball x < paddle1x
- LDA ballx
- SEC
- SBC #$08
- CMP #PADDLE1X
- BCS CheckPaddle1CollisionDone
- ;; if ball y > paddle y top
- LDA bally
- CLC
- ADC #$08
- CMP paddle1ytop
- BCC CheckPaddle1CollisionDone
- ;; if ball y < paddle y bottom
- LDA bally
- SEC
- SBC #$08
- CMP paddle1ybot
- BCS CheckPaddle1CollisionDone
- ;; bounce, ball now moving right
- LDA #$01
- STA ballright
- LDA #$00
- STA ballleft
- JSR IncreaseBallSpeedX ; increase horizontal speed of ball
- LDA paddle1speed
- CLC
- ADC #$01
- STA paddle1speed ; increase paddle 1 speed
- CheckPaddle1CollisionDone:
- CheckPaddle2Collision:
- ;;if ball x < paddle1x
- LDA ballx
- CLC
- ADC #$08
- CMP #PADDLE2X
- BCC CheckPaddle2CollisionDone
- ;; if ball y > paddle y top
- LDA bally
- CLC
- ADC #$08
- CMP paddle2ytop
- BCC CheckPaddle2CollisionDone
- ;; if ball y < paddle y bottom
- LDA bally
- SEC
- SBC #$08
- CMP paddle2ybot
- BCS CheckPaddle2CollisionDone
- ;; bounce, ball now moving right
- LDA #$01
- STA ballleft
- LDA #$00
- STA ballright
- JSR IncreaseBallSpeedY ; increase vertical speed of ball
- LDA paddle2speed
- CLC
- ADC #$01
- STA paddle2speed ; increase paddle 2 speed
- CheckPaddle2CollisionDone:
- RTS
- ;******************************************************************
- ;***************
- ;WAIT FOR NMI
- ;******************************************************************
- WaitForNMI:
- LDA frameCounter
- WaitLoop:
- CMP frameCounter
- BEQ WaitLoop
- RTS
- ;******************************************************************
- ;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;; DATA ;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;
- .bank 1
- .org $E000
- palette:
- .db $22,$29,$1A,$0F, $22,$36,$17,$0F, $22,$30,$21,$0F, $22,$27,$17,$0F ;;background palette
- .db $22,$1C,$15,$14, $22,$02,$38,$3C, $22,$1C,$15,$14, $22,$02,$38,$3C ;;sprite palette
- sprites:
- ;vert tile attr horiz
- .db $80, $75, $00, $80 ;sprite 0
- vertical_offsets:
- .db $00, $08, $10, $18
- background:
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $19,$15,$0a,$22,$0e,$1b,$26,$01,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$19,$15,$0a,$22,$0e,$1b,$26,$02
- .db $26,$26,$00,$00,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$00,$00,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
- attributes:
- .db $01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01
- .db $01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01
- title:
- .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- .db $26,$26,$26,$26,$26,$26,$26,$25,$25,$26,$26,$26,$26,$26,$26,$25,$26,$26,$26,$25,$25,$25,$26,$26,$25,$25,$26,$26,$26,$26,$26,$25
- .db $26,$26,$26,$26,$26,$26,$26,$27,$26,$26,$26,$26,$26,$26,$26,$27,$26,$26,$26,$26,$25,$25,$26,$26,$25,$26,$26,$26,$26,$26,$26,$26
- .db $26,$26,$27,$27,$27,$26,$26,$27,$26,$26,$27,$27,$27,$26,$26,$27,$26,$26,$26,$26,$26,$25,$26,$27,$26,$26,$26,$27,$27,$27,$27,$25
- .db $26,$26,$27,$25,$25,$26,$26,$27,$26,$26,$27,$25,$25,$26,$26,$27,$26,$26,$26,$26,$26,$26,$26,$27,$26,$26,$26,$27,$25,$25,$25,$25
- .db $26,$26,$27,$25,$25,$26,$26,$27,$26,$26,$27,$25,$25,$26,$26,$27,$26,$26,$27,$26,$26,$26,$26,$27,$26,$26,$26,$27,$25,$26,$26,$26
- .db $26,$26,$26,$26,$26,$26,$26,$27,$26,$26,$26,$26,$26,$26,$26,$27,$26,$26,$27,$25,$26,$26,$26,$27,$26,$26,$26,$27,$25,$25,$26,$26
- .db $26,$26,$26,$26,$26,$26,$27,$27,$25,$26,$26,$26,$26,$26,$27,$27,$26,$26,$27,$25,$25,$26,$26,$27,$25,$26,$26,$26,$26,$26,$26,$27
- .db $26,$26,$26,$26,$27,$27,$27,$25,$25,$27,$27,$27,$27,$27,$27,$25,$27,$27,$27,$25,$25,$25,$27,$27,$25,$25,$26,$26,$26,$26,$27,$25
- .db $26,$26,$26,$26,$27,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- .db $26,$26,$26,$26,$27,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- .db $26,$26,$26,$26,$27,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- .db $25,$27,$27,$27,$27,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$19,$1b,$0e,$1c,$1c,$25,$1c,$1d,$0a,$1b,$1d,$2b,$25,$25,$25,$25,$25,$25,$25,$25
- .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
- titleattr:
- .db $03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03
- .db $03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03
- .org $FFFA ;first of the three vectors starts here
- .dw NMI ;when an NMI happens (once per frame if enabled) the
- ;processor will jump to the label NMI:
- .dw RESET ;when the processor first turns on or is reset, it will jump
- ;to the label RESET:
- .dw 0 ;external interrupt IRQ is not used in this tutorial
- ;;;;;;;;;;;;;;
- .bank 2
- .org $0000
- .incbin "mario.chr" ;includes 8KB graphics file from SMB1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement