; Verifies that reset doesn't alter any RAM.

.include "testing.s"
; patterns_bin "pat.bin"
.macro chr b,s
.repeat s
.byte b
.endrepeat
.endmacro
.pushseg
.segment "CHARS"
chr $FF,16 ; Full
chr $00,8
chr $FF,8 ; Gray
chr $55,16 ; Vertical stripes
chr $AA,16 ; Vertical stripes - reverse
.repeat 8
.byte $FF
.byte $00
.endrepeat ; Horizontal stripes
.repeat 8
.byte $00
.byte $FF
.endrepeat ; Horizontal stripes - reverse
.repeat 8
.byte $55
.byte $AA
.endrepeat ; Checkerboard
.repeat 8
.byte $AA
.byte $55
.endrepeat ; Checkerboard - reverse
.popseg

zp_res COUNT

reset:
	sei
	cld
	ldx #$FF
	txs

	; Init PPU
	bit PPUSTATUS
vwait1:
	bit PPUSTATUS
	bpl vwait1
vwait2:
	bit PPUSTATUS
	bpl vwait2

	lda #$00
	sta PPUCTRL ; NMI off, PPU slave, Small sprites, 0 addresses
	lda #$3F
	sta PPUADDR
	lda #$00
	sta PPUADDR ; Load $3F03
	lda #$01
	sta PPUDATA ; Load $16 into palette 0, color 0
	lda #$16
	sta PPUDATA ; Load $16 into palette 0, color 1
	sta PPUDATA ; Load $16 into palette 0, color 2
	sta PPUDATA ; Load $16 into palette 0, color 3
	lda #$0E
	sta PPUDATA ; Load $16 into palette 0, color 0
	lda #$0B
	sta PPUDATA ; Load $16 into palette 0, color 1
	sta PPUDATA ; Load $16 into palette 0, color 2
	sta PPUDATA ; Load $16 into palette 0, color 3
	lda #$0E
	sta PPUDATA ; Load $16 into palette 0, color 0
	lda #$0B
	sta PPUDATA ; Load $16 into palette 0, color 1
	sta PPUDATA ; Load $16 into palette 0, color 2
	sta PPUDATA ; Load $16 into palette 0, color 3
	lda #$0E
	sta PPUDATA ; Load $16 into palette 0, color 0
	lda #$0B
	sta PPUDATA ; Load $16 into palette 0, color 1
	sta PPUDATA ; Load $16 into palette 0, color 2
	sta PPUDATA ; Load $16 into palette 0, color 3

	lda #$20
	sta PPUADDR
	lda #$00
	sta PPUADDR ; Load $2000
	;lda #$01
	;sta PPUDATA ; Load $01 into name table 1
	lda #$06
	ldx #$00
fill_loop_0:
	sta PPUDATA ; Load $01 into name table 1
	dex
	bne fill_loop_0
	ldx #$00
fill_loop_1:
	sta PPUDATA ; Load $01 into name table 1
	dex
	bne fill_loop_1
	ldx #$00
fill_loop_2:
	sta PPUDATA ; Load $01 into name table 1
	dex
	bne fill_loop_2
	ldx #$C0
fill_loop_3:
	sta PPUDATA ; Load $01 into name table 1
	dex
	bne fill_loop_3
	lda #$41
	ldx #$40
fill_loop:
	sta PPUDATA ; Load $16 into palette 0, color 0
	dex
	bne fill_loop

	lda #$0A
	sta PPUMASK; No EM, only background rendering, normal color

	lda #$00
	sta PPUSCROLL
	sta PPUSCROLL
	lda #$80
	sta PPUCTRL ; NMI on, PPU slave, Small sprites, 0 addresses
loop:
	jmp loop

nmi:
	lda COUNT
	bne exit
	inc COUNT
	rti
exit:
	stp

irq:
	stp
