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
- ;;;;;;;;;;;;;;;
- .org $0000
- AddrLow: .rs 1
- AddrHigh: .rs 1
- .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
- 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 $10, decimal 16 - copying 16 bytes = 4 sprites<- lol wut? It's CPXing to $20, but says $10. �\(�_O)/�
- BNE LoadPalettesLoop ; Branch to LoadPalettesLoop if compare was Not Equal to zero
- ; if compare was equal to 32, keep going down
- LoadSprites:
- LDX #$00 ; start at 0
- LoadSpritesLoop:
- LDA sprites, x ; load data from address (sprites + x)
- STA $0200, x ; store into RAM address ($0200 + x)
- INX ; X = X + 1
- CPX #$10 ; Compare X to hex $10, decimal 16
- BNE LoadSpritesLoop ; Branch to LoadSpritesLoop if compare was Not Equal to zero
- ; if compare was equal to 16, keep going down
- LDA $2002
- 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
- LoadBackgroundsLoop:
- LDA [AddrLow],y
- STA $2007
- INY
- BNE LoadBackgroundsLoop
- ; Outer loop
- INC AddrHigh ; increment high byte of address backg to next 256 byte chunk
- DEX ; one chunk done so X = X - 1.
- BNE LoadBackgroundsLoop ; if X isn't zero, do again
- LDA $2002 ; Reset Scroll
- LDA #$00
- STA $2005
- STA $2005
- STA $2006
- STA $2006
- 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
- Forever:
- JMP Forever ;jump back to Forever, infinite loop
- NMI:
- 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
- LatchController:
- LDA #$01
- STA $4016
- LDA #$00
- STA $4016 ; tell both the controllers to latch buttons
- ButtonA:
- LDA $4016 ; player 1 - A
- AND #%00000001 ; look only at bit 0
- BNE ButtonB
- ; Button stuff here
- ButtonB:
- LDA $4016 ; player 1 - B
- AND #%00000001 ; look only at bit 0
- BNE SelectButton
- ; Button stuff here
- SelectButton:
- LDA $4016 ; player 1 - Select
- AND #%00000001 ; look only at bit 0
- BNE StartButton
- ; Button stuff here
- StartButton:
- LDA $4016 ; player 1 - Start
- AND #%00000001 ; look only at bit 0
- BNE UpButton
- ; Button stuff here
- UpButton:
- LDA $4016 ; player 1 - Up
- AND #%00000001 ; look only at bit 0
- BNE DownButton
- LDA $0200 ; load sprite Y position
- CLC ; make sure the carry flag is clear
- ADC #$01 ; A = A + 1
- STA $0200 ; save sprite Y position
- LDA $0204 ; load sprite Y position
- CLC ; make sure the carry flag is clear
- ADC #$01 ; A = A + 1
- STA $0204 ; save sprite Y position
- LDA $0208 ; load sprite Y position
- CLC ; make sure the carry flag is clear
- ADC #$01 ; A = A + 1
- STA $0208 ; save sprite Y position
- LDA $020C ; load sprite Y position
- CLC ; make sure the carry flag is clear
- ADC #$01 ; A = A + 1
- STA $020C ; save sprite Y position
- DownButton:
- LDA $4016 ; player 1 - Down
- AND #%00000001 ; look only at bit 0
- BNE LeftButton
- LDA $0200 ; load sprite Y position
- SEC ; make sure carry flag is set
- SBC #$01 ; A = A - 1
- STA $0200 ; save sprite Y position
- LDA $0204 ; load sprite Y position
- SEC ; make sure carry flag is set
- SBC #$01 ; A = A - 1
- STA $0204 ; save sprite Y position
- LDA $0208 ; load sprite Y position
- SEC ; make sure carry flag is set
- SBC #$01 ; A = A - 1
- STA $0208 ; save sprite Y position
- LDA $020C ; load sprite Y position
- SEC ; make sure carry flag is set
- SBC #$01 ; A = A - 1
- STA $020C ; save sprite Y position
- LeftButton:
- LDA $4016 ; player 1 - Left
- AND #%00000001 ; look only at bit 0
- BNE RightButton
- LDA $0203 ; load sprite X position
- CLC ; make sure the carry flag is clear
- ADC #$01 ; A = A + 1
- STA $0203 ; save sprite X position
- LDA $0207 ; load sprite X position
- CLC ; make sure the carry flag is clear
- ADC #$01 ; A = A + 1
- STA $0207 ; save sprite X position
- LDA $020B ; load sprite X position
- CLC ; make sure the carry flag is clear
- ADC #$01 ; A = A + 1
- STA $020B ; save sprite X position
- LDA $020F ; load sprite X position
- CLC ; make sure the carry flag is clear
- ADC #$01 ; A = A + 1
- STA $020F ; save sprite X position
- RightButton:
- LDA $4016 ; player 1 - Right
- AND #%00000001 ; look only at bit 0
- BNE NotRightButton
- LDA $0203 ; load sprite X position
- SEC ; make sure carry flag is set
- SBC #$01 ; A = A - 1
- STA $0203 ; save sprite X position
- LDA $0207 ; load sprite X position
- SEC ; make sure carry flag is set
- SBC #$01 ; A = A - 1
- STA $0207 ; save sprite X position
- LDA $020B ; load sprite X position
- SEC ; make sure carry flag is set
- SBC #$01 ; A = A - 1
- STA $020B ; save sprite X position
- LDA $020F ; load sprite X position
- SEC ; make sure carry flag is set
- SBC #$01 ; A = A - 1
- STA $020F ; save sprite X position
- NotRightButton:
- JMP ButtonA
- RTI ; return from interrupt
- ;;;;;;;;;;;;;;
- .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,$12,$36,$15, $22,$02,$38,$3C, $22,$1C,$15,$14, $22,$02,$38,$3C ;;sprite palette
- sprites:
- ;vert tile attr horiz
- .db $80, $32, $00, $80 ;sprite 0
- .db $80, $33, $00, $88 ;sprite 1
- .db $88, $34, $00, $80 ;sprite 2
- .db $88, $35, $00, $88 ;sprite 3
- background:
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 2
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$36,$37,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 2
- .db $24,$24,$24,$24,$24,$24,$24,$35,$25,$25,$38,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$45,$45,$24,$24,$45,$45,$45,$45,$45,$45,$24,$24 ;;row 3
- .db $24,$24,$24,$24,$24,$24,$24,$39,$3A,$3B,$3C,$24,$53,$54,$24,$24 ;;some brick tops
- .db $24,$24,$24,$24,$47,$47,$24,$24,$47,$47,$47,$47,$47,$47,$24,$24 ;;row 4
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$55,$56,$24,$24 ;;brick bottoms
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 2
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 2
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$36,$37,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 2
- .db $24,$24,$24,$24,$24,$24,$24,$35,$25,$25,$38,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$45,$45,$24,$24,$45,$45,$45,$45,$45,$45,$24,$24 ;;row 3
- .db $24,$24,$24,$24,$24,$24,$24,$39,$3A,$3B,$3C,$24,$53,$54,$24,$24 ;;some brick tops
- .db $24,$24,$24,$24,$47,$47,$24,$24,$47,$47,$47,$47,$47,$47,$24,$24 ;;row 4
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$55,$56,$24,$24 ;;brick bottoms
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 2
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;row 1
- .db $24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24 ;;all sky
- attribute:
- .db %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000
- .db %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000
- .db %00000000, %00000000, %00000000, %00000000, %00000000, %10000000, %10100000, %00000000
- .db %00000000, %00000001, %00000101, %00000001, %00000000, %00001000, %00001010, %00000011
- .db %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000
- .db %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000, %00000000
- .db %00000000, %00000000, %00000000, %00000000, %00000000, %10000000, %10100000, %00000000
- .db %00000000, %00000001, %00000101, %00000001, %00000000, %00001000, %00001010, %00000011
- .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