.include "testing.s"

reset:
        sei ; Ignore IRQs while starting up
        cld ; disabled decimal mode (iirc it doesn't work properly on NES anyway)
        ldx #$40
        stx $4017 ; Disable APU frame IRQ
        ldx #$ff
        txs ; Set stack pointer to 0x1ff
        inx ; Set x to zero
        stx $2000 ; Disable NMI (by writing zero)
        stx $4010 ; Disable DMC IRQs
        ldx #$08
        stx $2001 ; Disable rendering

        bit $2002 ; Clear vblank flag by reading ppu status
VBLANKWAIT1:
        bit $2002
        bpl VBLANKWAIT1
VBLANKWAIT2:
        bit $2002
        bpl VBLANKWAIT2

        lda #$3F
        sta PPUADDR
        lda #$00
        sta PPUADDR
        lda #$01
        ldx #$10
fill_loop:
        sta PPUDATA
        dex
        bne fill_loop

        lda #$3F
        sta PPUADDR
        lda #$10
        sta PPUADDR

        lda PPUDATA
        cmp #$01
        bne fail
        lda PPUDATA
        lda PPUDATA
        lda PPUDATA
        lda PPUDATA
        cmp #$01
        bne fail
        lda PPUDATA
        lda PPUDATA
        lda PPUDATA
        lda PPUDATA
        cmp #$01
        bne fail
        lda PPUDATA
        lda PPUDATA
        lda PPUDATA
        lda PPUDATA
        cmp #$01
        bne fail
        stp
        jmp $8000
fail:
        stp

nmi:
        stp

irq:
        stp
