;**************************************************************************
;*
;* boot loader main test
;*
;* is loaded from bootLoader_2000_4_16.bin (will load 16 sectors (16*128 bytes) from sector 4 into address $2000 
;*
;**************************************************************************
	
	opt	h-
	opt	f+

	org	$2000			   ;prg start
	
	icl "custom.i"
	icl "bootLoader.i"

;-------- CODEADR is start segment

	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
	
	;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
	
loop	

?WaitVC0
        lda	VCOUNT		
        beq	?WaitVC0   	
?WaitVCnot0
        lda	VCOUNT		
        bne	?WaitVCnot0   
		
	;TBD	
		
	jmp	loop
	
	
	
;************************************************
;*
;* 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 $70		;8 blank lines	
	.byte $47,<charData,>charData   	;Mode 7 + LMS	 
	.rept 12
	.byte $7   
	.endr
	.byte $41,<displayList,>displayList ; wait vblank, restart same display list on next frame

charData

	.byte	">------------------<"
	.byte	">                  <"
	.byte	"> BOOT LOADER      <"
	.byte   "> TEST 1           <"
	.byte	">                  <"
	.byte	">                  <"
	.byte	">                  <"
	.byte   ">                  <"
	.byte	">                  <"
	.byte	">                  <"	
	.byte	">                  <" 
	.byte   ">                  <"	
	.byte	">------------------<"	
		
;************************************************
;*
;* dummy
;*
;************************************************
	
noKeyRead	
	rts	
	
	lda	#$0
	sta	HSCROL
	
bootEnd
.define	PADDING (16*128)-(bootEnd - $2000)

        .rept PADDING
        .byte 0
        .endr	
