Skip to content

Instantly share code, notes, and snippets.

@ddribin
Created October 20, 2009 04:33
Show Gist options
  • Save ddribin/213995 to your computer and use it in GitHub Desktop.
Save ddribin/213995 to your computer and use it in GitHub Desktop.
.segment "HEADER"
.byte "NES", $1A ; iNES header identifier
.byte 2 ; 2x 16KB PRG code
.byte 1 ; 1x 8KB CHR data
.byte 0, 0 ; mapper 0, vertical mirroring
;;;;;;;;;;;;;;;
;;; "nes" linker config requires a STARTUP section, even if it's empty
.segment "STARTUP"
.segment "CODE"
reset:
sei ; disable IRQs
cld ; disable decimal mode
ldx #$40
stx $4017 ; dsiable APU frame IRQ
ldx #$ff ; Set up stack
txs ; +
inx ; now X = 0
stx $2000 ; disable NMI
stx $2001 ; disable rendering
stx $4010 ; disable DMC IRQs
@vblankwait1: ; First wait for vlbank 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
@vblankwait2: ; Second wait for vblank, PPU is ready after this
bit $2002
bpl @vblankwait2
.if 0 ; Enable this to work on Nestopia
lda #$3f ; Set PPU address to BG palette RAM ($3F00)
sta $2006
lda #$00
sta $2006
lda #$00
sta $2007
sta $2007
@vblankwait3:
bit $2002
bpl @vblankwait3
.endif
lda #%10000000 ; intensify blues
sta $2001
@forever:
jmp @forever
nmi:
rti
;;;;;;;;;;;;;;
.segment "VECTORS"
.word 0, 0, 0 ; Unused
;; When an NMI happens (once per frame if enabled) the label nmi:
.word nmi
;; When the processor first turns on or is reset, it will jump to the
;; label reset:
.word reset
;; External interrupt IRQ is not used in this tutorial
.word 0
;;;;;;;;;;;;;;
.segment "CHARS"
.incbin "mario.chr" ; includes 8KB graphics from SMB1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment