This is my updated code, works alot better thanks to part from DanSS on #nesdev EFnet. I made all the vblankwaits he had into a simple macro for calling.
Code:
.Segment "HEADER"
.byte "NES",$1A,16,0,$20,0,0,0,0,0,0,0,0,0
.Segment "PRG0"
.Segment "PRG1"
.Segment "PRG2"
.Segment "PRG3"
.Segment "PRG4"
.Segment "PRG5"
.Segment "THEGAME"
.Segment "PRG6"
.Segment "PRG7"
.Segment "PRG8"
.Segment "PRG9"
.Segment "PRGA"
.Segment "PRGB"
.Segment "PRGC"
.Segment "PRGD"
.Segment "PRGE"
.Segment "PRGBOOT"
; Macros for Usage by dmaresca
.macro vblankwait
bit $2002
bpl vblankwait
dex
bne vblankwait
.endmacro
RESET:
sei ; ignore 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
txa ; Set up accumulator
clrmem:
sta $000,x
sta $100,x
sta $200,x
sta $300,x
sta $400,x
sta $500,x
sta $600,x
sta $700,x ; Remove this if you're storing reset-persistent data
inx
bne clrmem
vblankwait1:
bit $2002
bpl vblankwait1
vblankwait2:
bit $2002
bpl vblankwait2
lda #%00000000
sta $2000 ; PPU Control Register 1
lda #%11101000
sta $2001 ; PPU Control Register 2
; Set the color to black (0F)
lda #$3F
sta $2006
lda #$00
sta $2006
lda #$0F ; Coconial Black Palette Color
sta $2007 ; Write Color to VRAM Register
ldx #$08 ; Screen color change timing
vblankwait
; Set the color to red (05)
lda #$3F
sta $2006
lda #$00
sta $2006
lda #$05 ; Dark Red Palette Color
sta $2007 ; Write Color to VRAM Register
ldx #$08 ; Screen color change timing
vblankwait
; Set the color to light blue (31)
lda #$3F
sta $2006
lda #$00
sta $2006
lda #$31 ; Dark Red Palette Color
sta $2007 ; Write Color to VRAM Register
stop:
jmp stop
NMI:
rti
IRQ:
rti
.Segment "SAMPLES"
.Segment "VECTORS"
.addr NMI
.addr RESET
.addr IRQ