Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;------------------------------------
- ; Constants
- ;------------------------------------
- PRG_COUNT = 1 ; 2 = 32KB
- MIRRORING = %0001 ; %0000 = horizontal, %0001 = vertical, %1000 = four-screen
- ;------------------------------------
- ; Variables
- ;------------------------------------
- .enum $0000
- ; Variables are declared using DSB/DSW i.e.:
- ;myVar0 .dsb 1
- ;myVar1 .dsb 3
- .ende
- ;------------------------------------
- ; iNES Header (NROM)
- ;------------------------------------
- .db "NES", $1a ; identification of the iNES header
- .db PRG_COUNT ; number of 16KB PRG-ROM pages
- .db $01 ; number of 8KB CHR-ROM pages
- .db $00 | MIRRORING ; mapper 0 and mirroring
- .dsb 9, $00 ; clear the remaining bytes
- ;------------------------------------
- ; Program Bank(s)
- ;------------------------------------
- .base $10000 - (PRG_COUNT * $4000)
- RESET: ; RESET subroutine.
- sei ; disable interrupts
- cld ; disable decimal mode
- ldx #$40
- stx $4017 ; disable APU frame interrupt
- ldx #$FF
- txs ; initialize stack
- inx ; X = 0
- stx $2000 ; disable NMI
- stx $2001 ; disable rendering
- stx $4010 ; disable DMC interrupts
- @vblankWait1:
- bit $2002
- bpl @vblankWait1 ; first wait for vblank to make sure PPU is ready
- @resetClearMem:
- 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 ; clear working RAM
- inx
- bne @resetClearMem
- @vblankWait2:
- bit $2002
- bpl @vblankWait2 ; second wait for vblank, PPU will be ready at this point
- LoadPalettes:
- lda $2002 ; read PPU status to reset the high/low latch
- lda #$3F ; write $3F00 into VRAM address
- sta $2006 ; low byte
- lda #$00
- sta $2006 ; high byte
- lda $25
- sta $2007
- ; ldx #$00
- ;@LoadPalettesLoop:
- ; lda bg_palette, x
- ; sta $2007 ; write to PPU
- ; inx
- ; cpx #$10 ; $10 = 16, copying 16 bytes = 4 sprites
- ; bne @LoadPalettesLoop
- INFLOOP: ; Game waits here forever so we can get NMIs 60 times a second.
- jmp INFLOOP
- NMI: ; Game loop (called from interrupt)
- rti
- IRQ: ; External interrupt requests handled here
- rti
- .base $E000 ; WAS: $10000 - ((PRG_COUNT - 1) * $4000)
- bg_palette:
- .db $22,$29,$1A,$0F
- .db $22,$36,$17,$0F
- .db $22,$30,$21,$0F
- .db $22,$27,$17,$0F
- sprite_palette:
- .db $22,$16,$27,$18
- .db $22,$1A,$30,$27
- .db $22,$16,$30,$27
- .db $22,$0F,$36,$17
- .org $FFFA ; location of interrupt vectors
- ;;; Interrupt Vectors ;;;
- .dw NMI ; once per frame
- .dw RESET ; when processor turns on or is reset
- .dw IRQ ; external interrupt IRQ unused so far.
- ;;;;;;;;;;;;;;;;;;;;;;;;;
- ;------------------------------------
- ; CHR-ROM bank
- ;------------------------------------
- .incbin mario.chr ; include graphics
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement