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
- JSR InitializeTitle ; set up palettes, background/attributes for title
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;MAIN GAME LOGIC;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- MainLoop:
- CheckTitle:
- JSR WaitForNMI
- LDA gamestate
- CMP #STATETITLE
- BNE CheckPlaying
- JSR ReadController1
- LDA buttons1
- AND #%00010000 ; if START is pressed, turn off screen, update background and initialize sprites/variables
- 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 ;updating paddles/ball position data
- JSR MoveBall ;change direction of ball if a bounce occurs
- JSR MovePaddles ;checking for input and inc/dec paddle position variables
- JSR CheckCollisions ;checking for ball collisions with paddles or walls
- 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;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- .include "subroutines.asm"
- ;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;; DATA ;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;
- .bank 1
- .org $E000
- .include "data.asm"
- .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