
	.incdir	"F:\git\goldmomo_endlos\assembler_files\ucore\"
	.include "include\ucore_ctrl.i"
	
	nop
	
	;set video to 555
	
	movei	r0,2			;1x5r5g5b
	movei	r1,UcVideoMEMMode
	movei	r2,UcVideoMEMLatch
	moveih	r1,>UcVideoMEMMode		;8029 - video mode
	moveih	r2,>UcVideoMEMLatch		;802a - latch out
	
	st	r1,r0
	st	r2,r7

	; clear screen
	
	movei	r2,$00	;destination 
	movei	r3,$00
	moveih	r2,$00
	moveih	r3,$f0	;p(0,0) = f000 0000
	
	gpci	r7,2	;next 4 + X
	br	clearLoop
	movei	r1,$7f	; count		delay slot	
	movei	r0,$00	; value		delay slot
	moveih	r1,$9d	; count		delay slot
	nop		;		delay slot
	
	; set char
	
	movei	r2,$68	;source 
	movei	r3,$01
	moveih	r2,$50
	moveih	r3,$e0	;p(0,0) = e001 5068
	
	movei	r4,$00	;destination 
	movei	r5,$00
	moveih	r4,$00
	moveih	r5,$f0	;p(0,0) = f000 0000
	
	gpci	r7,2	;next 4 + X
	br	drawChar
	movei	r0,24	;value		delay slot	
	nop		;delay slot
	nop		;delay slot
	nop		;delay slot
	
	; set char
	
	movei	r2,$68	;source 
	movei	r3,$01
	moveih	r2,$50
	moveih	r3,$e0	;p(0,0) = e001 5068
	
	movei	r4,$08	;destination 
	movei	r5,$00
	moveih	r4,$00
	moveih	r5,$f0	;p(0,0) = f000 0000
	
	gpci	r7,2	;next 4 + X
	br	drawChar
	movei	r0,34	;value		delay slot	
	nop		;delay slot
	nop		;delay slot
	nop		;delay slot
	
end	br	end
	nop		;delay slot
	nop		;delay slot
	nop		;delay slot
	nop		;delay slot
	
;******************************
;*
;* r0 	 	value
;* r1		count-1 (32 bit (2 words))
;* r3:r2	dest
;
memset

clearLoop

	esadr	r3,r2
	est	r0,0
	est	r0,1
	subi	r1,1
	brts	clearLoop
	addi	r2,2	;delay slot
	addtqi	r3,r3,0	;delay slot
	nop		;delay slot
	nop		;delay slot
	
	jmpi	r7,0
	nop		;delay slot
	nop		;delay slot
	nop		;delay slot
	nop		;delay slot
	
;******************************
;*
;* r0 	 	value
;* r3:r2	source 	(font)
;* r5:r4	dest	(video buffer)

drawChar	

	push	r1
	push	r6
	
	muli	r0,8		;value * 8
	nop
	add	r2,r2,r0	;source 
	addtqi	r3,r3,0		;

	;

	movei	r0,15		;16 [y]

dcYloop	
	
	movei	r1,7		;8 [x]

	
dcXloop
	esadr	r3,r2
	erqldi	0
	eld	r6
	nop
	
	extri	r6,15
	brts	dcNoTransp
	nop		;delay slot
	nop		;delay slot
	nop		;delay slot
	nop		;delay slot
	
	movei	r6,0
	
dcNoTransp	
	
		
	esadr	r5,r4
	est	r6,0
	
	subi	r1,1		;x-
	brts	dcXloop
	addi	r4,1		;delay slot
	addtqi	r5,r5,0		;delay slot
	addi	r2,1		;delay slot
	addtqi	r3,r3,0		;delay slot
	
	addi	r4,$b0		;dest + 360-8
	addtqi	r5,r5,0		;
	addi	r4,$b0		;
	addtqi	r5,r5,0		;
	
	movei	r1,$e8
	nop
	moveih	r1,$2
	nop
	
	add	r2,r2,r1	;source + 752-8
	addtqi	r3,r3,0		;
	
	
	subi	r0,1		;y-
	brts	dcYloop
	nop		;delay slot
	nop		;delay slot
	nop		;delay slot
	nop		;delay slot
	
	rqpop
	rqpop
	jmpi	r7,0
	pop	r6	;delay slot
	pop	r1	;delay slot
	nop		;delay slot
	nop		;delay slot
