;**************************************************************************
;*
;* simple hires 2c picture
;*
;**************************************************************************
	
	opt h+
		
	org $2000			   ;prg start
	
	icl "custom.i"

	cld
	
	;set display list (use shadow regs)
	
	lda	#<displayList
	sta	DLISTL	
	lda	#>displayList
	sta	DLISTH

	sei				  ;disable irqs
	lda	#$00
	sta	NMIEN			  ;NMIEN all off 
	sta	DMACTL			  ;DMACTL all off
	
	;vertical blank interrupt 
	
	lda 	#>vbi_irq
	sta	VVBLKIH	
	lda 	#<vbi_irq
	sta	VVBLKIL	

	;os key remove
	
	lda	#<noKeyRead
        sta	VSERINL        
        lda	#>noKeyRead
        sta	VSERINH        
	
	;chbase
	
	lda	#$E0
	sta	CHBASE
	
	;color setup
	
	lda	#$0	
	sta	COLBK
	lda	#$a	
	sta	COLPF0
	lda	#$e	
	sta	COLPF1
	lda	#$8	
	sta	COLPF2
	lda	#$88				
	sta	COLPF3
				
	;disable player/missile dma
	
	lda	#$00
	sta	GRACTL
	
	;chbase
	
	lda	#>gfx
	sta	CHBASE
	
	;setup displays
	   
	lda	#DMACTL_DL|DMACTL_PF_NORMAL		
		
		;enable display list dma 			
		;playfield normal display (40)
		
	sta	DMACTL	;DMACTL
		
	;enable ints
	
	lda	#NMIEN_VBI
	sta	NMIEN	;VBI
	
	;
	
	lda	#$0		;normal
	sta	PRIOR
	
	;int enable
	
	;cli
	
	;
	
loop	

?WaitVC0
        lda	VCOUNT		
        beq	?WaitVC0   	
?WaitVCnot0
        lda	VCOUNT		
        bne	?WaitVCnot0   
		
	;TBD	
		
	jmp	loop
	
;************************************************
;*
;* dummy
;*
;************************************************
	
noKeyRead	
	rts	
	
	lda	#$0
	sta	HSCROL	
	
;************************************************
;*
;* vertical blank interrupt (immidiate, x,y regs save bei os rom)
;*
;************************************************

vbi_irq
	
	;prolog (like XITVBL)
	
	pla					  
	tay
	pla					  
	tax
	pla					  
	rti
	
	; display list

	;7	6	5	4	3	2	1	0
	;DLI	LMS	VSCROLL	HSCOLL	Mode
	;
	;Mode 0 Blank lines 7..4 is count+1 of blank lines
	;Mode 1 JMP (use with LMS to set destination)
	;Mode $2-$f is ANTIC mode

	.align $400
	
displayList	 
	.byte 0			;Mode 0
	.byte $70		;8 blank lines	
	.byte $4f,<gfx,>gfx   	;Mode f + LMS	 
	.rept 101		;(101+1) * 40bytes = 4080
	.byte $f   
	.endr
	.byte $4f,<(gfx+4096+24),>(gfx+4096+24) ;Mode f + LMS skip one lone because 4096 border (4080 next is 4096+24 to met 40 byte per line)
	.rept 88		;89+1-1(skip) is remaining
	.byte $f   
	.endr
	
	.byte $41,<displayList,>displayList ; wait vblank, restart same display list on next frame
		
	org	$4000
		
	;gfx
	; ./gfxConv.exe -gm LINEAR -cm 1BIT -outfmt raw -i ../gfx/action_320_200_2c.png -o ../gfx/action_320_200_2c.raw
	;size 8000, 320x192 is 7680 bytes
gfx	
	ins	"gfx/action_320_200_2c.raw",0,7680	
	
	;0x5e00