Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .inesprg 1 ; Specifies the number of code banks.
- .ineschr 1 ; Specifies the number of chr banks.
- .inesmap 0 ; Specifies the NES mapper used.
- .inesmir 1 ; Specifies VRAM mirroring of the banks.
- .bank 1
- .org $FFFA ; Start at $FFFA.
- .dw VBlank_Routine ; Location of NMI interrupt.
- .dw Init ; Code to run at reset.
- .dw 0 ; Address during BRK instruction.
- .bank 0
- .org $0000
- IsVBlank .db 0
- Ball_V .db 0
- Ball_H .db 0
- .org $0300 ; OAM copy location
- PlayerA_Y: .db 0 ; Y position of the player
- PlayerA_T: .db 0 ; Tile number of the player
- PlayerA_S: .db 0 ; Special byte of the player
- PlayerA_X: .db 0 ; X position of the player
- PlayerB_Y: .db 0 ; Y position of the player
- PlayerB_T: .db 0 ; Tile number of the player
- PlayerB_S: .db 0 ; Special byte of the player
- PlayerB_X: .db 0 ; X position of the player
- PlayerC_Y: .db 0 ; Y position of the player
- PlayerC_T: .db 0 ; Tile number of the player
- PlayerC_S: .db 0 ; Special byte of the player
- PlayerC_X: .db 0 ; X position of the player
- Ball_Y: .db 0
- Ball_T: .db 0
- Ball_S: .db 0
- Ball_X: .db 0
- .org $8000 ; Goto location $8000.
- VBlank_Routine:
- INC IsVBlank
- RTI ; Return from interrupt.
- Init:
- ; Initialise the PPU.
- LDA #%10001000 ; Load data for register #1 of the PPU into the accumulator.
- STA $2000 ; Saves accumulator to $2000.
- LDA #%10011010 ; Load data for register #2 of the PPU into the accumulator.
- STA $2001 ; Saves accumulator to $2001.
- LDX #$00
- ; Initialise colour palette.
- ; We want to access $3F00 in memory, but we cannot access the VRAM.
- ; What we do is use register $2006 and $2007 to read and write.
- ; $2006 - Set the location to read/write data.
- ; $2007 - Read/write location set in $2006.
- LDA #$3F
- STA $2006
- LDA #$00
- STA $2006
- LoadPalette:
- LDA TilePalette, x
- STA $2007
- INX
- CPX #32
- BNE LoadPalette
- ; Apply same sprite settings to all player pieces
- LDA #%00000000
- STA PlayerA_S
- STA PlayerB_S
- STA PlayerC_S
- LDA #%00000001
- STA Ball_S
- LDA #1
- STA PlayerB_T
- LDA #2
- STA PlayerC_T
- LDA #3
- STA Ball_T
- LDA #128
- STA Ball_X
- STA Ball_Y
- LDA #1
- STA Ball_H
- STA Ball_V
- LDA #216
- STA PlayerA_Y
- STA PlayerB_Y
- STA PlayerC_Y
- Loop:
- WaitVBlank:
- LDA IsVBlank
- CMP #1
- BNE WaitVBlank ; If comparison is false, then branch.
- DEC IsVBlank
- ; ///////////////////////////////////////////////////////////////////////////////////////
- ; Handle gamepad
- ; ///////////////////////////////////////////////////////////////////////////////////////
- ; Game pad is at $4016 - strobe it.
- LDA #$01
- STA $4016
- LDA #$00
- STA $4016
- ; Read every key and compare to #1 if needed.
- LDA $4016 ; A key.
- LDA $4016 ; B key.
- LDA $4016 ; Select key.
- LDA $4016 ; Start key.
- LDA $4016 ; Up key.
- LDA $4016 ; Down key.
- LDA $4016 ; Left key.
- AND #1
- BNE LeftPress
- LDA $4016 ; Right key.
- AND #1
- BNE RightPress
- JMP DefaultPress
- RightPress:
- LDA PlayerA_X
- ADC #1
- STA PlayerA_X
- ADC #8
- STA PlayerB_X
- ADC #8
- STA PlayerC_X
- JMP DefaultPress
- LeftPress:
- LDA PlayerA_X
- SBC #2
- STA PlayerA_X
- ADC #6
- STA PlayerB_X
- ADC #8
- STA PlayerC_X
- JMP DefaultPress
- DefaultPress:
- ; This will be reached either by default if nothings pressed, or after a key was pressed.
- LDA #8 ; Left boundary of the level
- CMP PlayerA_X
- BCS CatchL ; If accumulator is smaller than 8
- LDA PlayerC_X
- CMP #240
- BCS CatchR ; If 240 is smaller than acumulator
- JMP NoCatch
- CatchL:
- LDA #8
- STA PlayerA_X
- ADC #7
- STA PlayerB_X
- ADC #7
- STA PlayerC_X
- JMP NoCatch
- CatchR:
- LDA #240
- STA PlayerC_X
- SBC #8
- STA PlayerB_X
- SBC #8
- STA PlayerA_X
- NoCatch:
- NoReflect:
- ; ///////////////////////////////////////////////////////////////////////////////////////
- ; Draw sprites
- ; ///////////////////////////////////////////////////////////////////////////////////////
- LDA #3
- STA $4014
- JMP Loop
- TilePalette: .incbin "palette.pal" ; Include and label the palette we're using.
- .bank 2
- .org $0000
- .incbin "background.bkg" ; Includes backround binary data.
- .incbin "sprites.spr" ; Includes sprite binary data.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement