Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .enum $0000 ;;start variables at ram location 0
- currentvirtpos .dsb 1 ; .rs 1 means reserve one byte of space
- .ende
- .ORG $7ff0
- Header: ; 16 byte .NES header (iNES format)
- .DB "NES", $1a
- .DB $02 ; size of PRG ROM in 16kb units
- .DB $01 ; size of CHR ROM in 8kb units
- .DB #%00000000 ; mapper 0
- .DB #%00000000 ; mapper 0
- .DB $00
- .DB $00
- .DB $00
- .DB $00
- .DB $00
- .DB $00
- .DB $00
- .DB $00
- .ORG $8000
- sprite_RAM = $0200
- ;;;;;;;;;;;;;;;
- .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 $0200, x
- STA $0400, x
- STA $0500, x
- STA $0600, x
- STA $0700, x
- LDA #$FE
- STA $0300, x
- INX
- BNE clrmem
- LDA #$00
- STA currentvirtpos
- 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
- 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 32, keep going down
- LDA #%10000000 ; enable NMI, sprites from Pattern Table 1
- STA $2000
- LDA #%00010000 ; enable sprites
- STA $2001
- Forever:
- JMP Forever ;jump back to Forever, infinite loop
- ;------------------------------------
- NMI:
- jsr updatesprites
- 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
- RTI ; return from interrupt
- ;;;;;;;;;;;;;;
- .org $E000
- palette:
- .db $0f,$03,$13,$23,$0f,$24,$21,$31,$0f,$03,$25,$26,$0f,$09,$19,$29
- .db $0f,$03,$13,$23,$0f,$24,$21,$31,$0f,$03,$25,$26,$0f,$09,$19,$29
- vertpos:
- .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
- .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
- .db $00,$00,$00,$00,$00,$00,$00,$00,$00
- .db $00,$00,$00,$00,$00,$00,$00,$00,$00
- .db $01,$01,$01,$01,$01,$01,$01,$01,$01
- .db $01,$01,$01,$01,$01,$01,$01,$01,$01
- .db $00,$00,$00,$00,$00,$00,$00,$00,$00
- .db $00,$00,$00,$00,$00,$00,$00,$00,$00
- .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
- .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
- .db $00,$00,$00,$00,$00,$00,$00,$00,$00
- .db $00,$00,$00,$00,$00,$00,$00,$00,$00
- .db $01,$01,$01,$01,$01,$01,$01,$01,$01
- .db $01,$01,$01,$01,$01,$01,$01,$01,$01
- .db $00,$00,$00,$00,$00,$00,$00,$00,$00
- .db $00,$00,$00,$00,$00,$00,$00,$00,$00
- .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
- .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
- .db $00,$00,$00,$00,$00,$00,$00,$00,$00
- .db $00,$00,$00,$00,$00,$00,$00,$00,$00
- .db $01,$01,$01,$01,$01,$01,$01,$01,$01
- .db $01,$01,$01,$01,$01,$01,$01,$01,$01
- .db $00,$00,$00,$00,$00,$00,$00,$00,$00
- .db $00,$00,$00,$00,$00,$00,$00,$00,$00
- .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
- .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF
- .db $00,$00,$00,$00,$00,$00,$00,$00,$00
- .db $00,$00,$00,$00,$00,$00,$00,$00,$00
- .db $01,$01,$01,$01,$01,$01,$01,$01,$01
- .db $01,$01,$01,$01,$01,$01,$01,$01,$01
- .db $00,$00,$00,$00,$00,$00,$00,$00,$00
- .db $00,$00,$00,$00,$00,$00,$00,$00,$00
- sprites:
- ;vert tile attr horiz
- .db $80, $00, $00, $a4
- .db $80, $01, $00, $c9
- .db $80, $02, $00, $84
- .db $80, $03, $00, $88
- ;------------------------------------
- updateconstants: ;constants for the use of the sprite_RAM constant
- .db $00 ;4 sprites for each meta sprite, so add $10 for each meta sprite we process
- ;------------------------------------
- updatesprites:
- 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 $0200 ; load sprite Y position
- CLC ; make sure the carry flag is clear
- ldx currentvirtpos
- ADC vertpos,x ; A = A plus vertposvalue
- STA $0200 ; save sprite Y position
- inc currentvirtpos
- LDA sprite_RAM ;vertical updates
- STA sprite_RAM+4
- CLC
- ADC #$8
- STA sprite_RAM+8
- STA sprite_RAM+12
- LDA sprite_RAM+3 ;horizontal updates
- STA sprite_RAM+11
- CLC
- ADC #$8
- STA sprite_RAM+7
- STA sprite_RAM+15
- rts
- ;------------------------------------
- ;------------------------------------
- .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
- ;;;;;;;;;;;;;;
- .incbin "mario.chr" ;includes 8KB graphics file from SMB1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement