;note also test for dexti (decoder immediate extend (used for est))	
	
;*********************************************************************	
; includes
;*********************************************************************	

	.incdir	"F:\git\goldmomo_endlos\assembler_files\ucore\"
	.include "include\ucore_ctrl.i"

;*********************************************************************	
; sd header is placed here
;*********************************************************************	

	.include "boot_level_sdHeader.s"

;*********************************************************************
;* start at address 32 here
;*********************************************************************

	.def	picDataROM		$e0000000
	.def	picDataRAMSource	$d0014000
	.def	picDataRAMDest		$d0000000
start	
	cli
	
	;setup video (360x225)
	
	gpci	r7,2		;next 4 + X
	br	setupVideo
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	
	;copy pic (rom -> ram)
		
	movei	r0,picDataROM	;source
	movei	r1,>>picDataROM
	moveih	r0,>picDataROM
	moveih	r1,>>>picDataROM
		
	movei	r2,picDataRAMSource	;destination 
	movei	r3,>>picDataRAMSource
	moveih	r2,>picDataRAMSource
	moveih	r3,>>>picDataRAMSource	
	
	movei	r5,extCopy16
	nop
	moveih	r5,>extCopy16
	gpci	r7,2	;next 4 + X
	jmpi	r5,0
	movei	r4,$c6	;delay slot 	
	nop		;delay slot
	moveih	r4,$13	;delay slot
	nop		;delay slot
	
	
loop	
	;copy pic (ram -> ram)
		
	movei	r0,picDataRAMSource	;source
	movei	r1,>>picDataRAMSource
	moveih	r0,>picDataRAMSource
	moveih	r1,>>>picDataRAMSource
		
	movei	r2,picDataRAMDest	;destination 
	movei	r3,>>picDataRAMDest
	moveih	r2,>picDataRAMDest
	moveih	r3,>>>picDataRAMDest	
	
	movei	r5,extCopy16
	nop
	moveih	r5,>extCopy16
	gpci	r7,2	;next 4 + X
	jmpi	r5,0
	movei	r4,$c6	;delay slot 	
	nop		;delay slot
	moveih	r4,$13	;delay slot
	nop		;delay slot
	
	;test sw 0
	
waitLoop	
	dexti	>UcRSwichtWLedG
	movei	r0,UcRSwichtWLedG
	nop
	rqldi	r0,0
	nop
	nop
	ld	r0
	nop
	extri	r0,0
	brts	waitLoop
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	
	
	;

	br	loop	
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	
;******************************
;* extCopy16
;*
;* r1:r0 source
;* r3:r2	dest
;* r4 count - 1 (16 words per count)
;* 
		
extCopy16	

	push	r5
	push	r6
	
extCopy16Loop
	esadr	r1,r0
	
	erqldi	0
	erqldi	1
	erqldi	2
	erqldi	3
	erqldi	4
	erqldi	5
	erqldi	6
	erqldi	7
	erqldi	8
	erqldi	9
	erqldi	10
	erqldi	11
	erqldi	12
	erqldi	13
	erqldi	14
	erqldi	15
	
	esadr	r3,r2
	eld	r5
	eld	r6
	est	r5,0
	est	r6,1
	eld	r5
	eld	r6
	est	r5,2
	est	r6,3
	eld	r5
	eld	r6
	est	r5,4
	est	r6,5
	eld	r5
	eld	r6
	est	r5,6
	est	r6,7
	
	eld	r5
	eld	r6
	 
	dexti	1		;add 1<<3 (8) to next im3 value
	est	r5,0
	dexti	1
	est	r6,1
	eld	r5
	eld	r6
	dexti	1
	est	r5,2
	dexti	1
	est	r6,3
	eld	r5
	eld	r6
	dexti	1
	est	r5,4
	dexti	1
	est	r6,5
	eld	r5
	eld	r6
	dexti	1
	est	r5,6
	dexti	1
	est	r6,7
	

	subi	r4,1
	brts	extCopy16Loop
	addi	r0,16		;delay slot
	addtqi	r1,r1,0		;delay slot
	addi	r2,16		;delay slot
	addtqi	r3,r3,0		;delay slot
	
	rqpop
	rqpop
	jmpi	r7,0
	pop	r6	;delay slot
	pop	r7     	;delay slot
	nop		;delay slot
	nop		;delay slot		
	
;******************************
;*
;* setupVideo
;*

setupVideo

	
	movei	r0,videoDefault		;source
	movei	r1,UcTimer2Ctrl		;dest-1
	moveih	r0,>videoDefault
	moveih	r1,>UcTimer2Ctrl			
	movei	r2,26			;27-1
	
setupVideoLoop

	rqldi	r0,0
	addi	r0,1
	addi	r1,1
	ld	r3
	subi	r2,1
	brts	setupVideoLoop
	st	r1,r3	;delay slot
	nop		;delay slot
	nop		;delay slot
	nop		;delay slot
		
	jmpi	r7,0
	nop		;delay slot
	nop		;delay slot
	nop		;delay slot
	nop		;delay slot	
	
;*********************************************************************
;* data
;*********************************************************************
	
videoDefault		;AD NAME					NEW				DEFAULT
	
	word	$0001	;10 VIDEO_ON					1				1 (ON)
	word	$0097	;11 HSYNC (D = 11 .. 0)				152-1				152-1
	word	$017f	;12 HSTART (D = 11 .. 0)			384-1				384-1
	word	$017d	;13 HMEMSTART (D = 11 .. 0)			382-1				382-1
	word	$071f	;14 HSTOP (D = 11 .. 0)				1824-1				1824-1
	word	$076f	;15 HTOTAL (D = 11 .. 0)			1904-1				1904-1
	word	$0002	;16 VSYNC (D = 10 .. 0)				3-1				3-1
	word	$001e	;17 VSTART (D = 10 .. 0)			31-1				31-1
	word	$03a2	;18 VSTOP  (D = 10 .. 0)			931-1				931-1
	word	$03a3	;19 VTOTAL  (D = 10 .. 0)			932-1				932-1
	word	$0000	;1a LC ADDER LOW				$0000				$0000
	word	$0040	;1b LC ADDER HIGH				$0080				$0040	
	word	$0000	;1c LC ADDER LATCH				X				X
	word	$0000	;1d LC START (10 .. 0) Pixeloffset		$0000				$0000	
	word	$0000	;1e						X				X
	word	$0000	;1f						X				X
	word	$0008	;20 HLOADSTART 					8				8
	word	$00bc	;21 HLOADSTOP					360+8				180+8
	word	$001e	;22 VLOADSTART 					31-1				31-1
	word	$03a2	;23 VLOADSTOP 					931-1				931-1
	word	$0004	;24 VLOADNEXT					2				4
	word	$0000	;25 MEM_STARTADR_store low			$0000				$0000
	word	$d000	;26 MEM_STARTADR_store high			$f000				$f000
	word	$0000	;27 MEM_LINEOFFSET_store low			$0000				$0000
	word	$0000	;28 MEM_LINEOFFSET_store high			$0000				$0000
	word	$0002	;29 MEM_MODE_store 				2				2 (X1R5G5B5X1R5G5B5)
	word	$0000	;2a LATCH MEM_STARTADR/LINEOFFSET/MODE		X				X
		
	