

	
	; BOB data struct	
	
	.def	csDestX			0	
	.def	csDestY			1	
	.def	csDrawWidth16		2
	.def	csDrawHeight		3	
	.def	csDestAdrHigh		4
	.def	csDestAdrLow		5
	.def	csDestWidth		6
	.def	csDestHeight		7
	.def	csSourceX		8	
	.def	csSourceY		9	
	.def	csSourceAdrHigh		10
	.def	csSourceAdrLow		11
	.def	csSourceWidth		12
	.def	csDrawFunction		13
	.def	csFlipXY		14	;0000 0000 0000 00XY
	.def	csTmpDestX		15	;temporary dont touch
	.def	csTmpDestY		16	;temporary dont touch
	.def	csTmpSourceX		17	;temporary dont touch
	.def	csTmpSourceY		18	;temporary dont touch
	.def	csTmpDrawHeight		19	;temporary dont touch


;******************************
;*
;* drawBob
;* 
;* r0 = copyStruct
;*	
;* return
;*
;* r0 = return code (only set by draws with test)
;*
	
drawBob

	;prolog

	push	r1
	push	r2
	push	r3
	push	r4
	push	r5
	push	r6
	push	r7
	
	;clear result (only set by draws with test)
	
	movei	r7,0	
	dexti	>copySolidResult
	movei	r1,copySolidResult
	nop
	st	r1,r7	;clear
	
	;start block
	
	rqldi	r0,csDestWidth
	rqldi	r0,csDestX
	rqldi	r0,csDrawWidth16
	ld	r5			;destwidth 
	ld	r1			;destx
	ld	r3			;drawwidth16	
	
	sub	r7,r5,r1		;(destwidth - destx)
	nop
	asri	r7,4			;blkCountMax = (destwidth - destx) >> 4;
	nop
	cmples	r7,r3			;	   blkCountMax <= drawwidth16 ?
	movets	r5,r7,r3		;r5 = blkStop =				 blkCountMax : drawwidth16
	nop
	push	r5
	
	;stop block
	
	movei	r7,0
	nop
	sub	r7,r7,r1		;-destx
	nop
	asri	r7,4			;4
	nop
	addi	r7,1
	movei	r2,0
	cmplosi	r1,0			;		destx < 0 ?
	movets  r2,r7,r2		;r2 = blkStart =			? (-destx >> 4)+1 : blkStart;
	nop
	push	r2
	
	;y underflow
	
	rqldi	r0,csDestY
	rqldi	r0,csDrawHeight
	rqldi	r0,csDestHeight
	ld	r4			;desty
	ld	r3			;drawheight
	ld	r6			;dest height
	
	movei	r2,0			
	add	r7,r3,r4		;r7 = drawheight+desty
	sub	r5,r2,r4		;r5 = -desty
	
	cmplosi	r4,0			;desty < 0 ?
	movets	r3,r7,r3		;		draw height =  drawheight+desty else draw height
	rqldi	r0,csSourceY		;									-- (optimized) internal y source offset
	movets	r5,r5,r2		;		source y    =  -desty else 0
	movets	r4,r2,r4		;		desty	    =  0 else desty
	ld	r2			;									-- 
	
	ssto	csTmpDestY
	stwo	r0,r4
	add	r5,r5,r2
	ssto	csTmpSourceY
	stwo	r0,r5
		
	;y overflow
	
	;subi	r6,1			;destHigh - 1 (as max)
	nop
	sub	r2,r6,r4		;csDestHeight - desty;	
	cmples	r6,r7			;		csDestHeight < (drawheight+desty) ?
	movets	r6,r2,r3		;drawHeight = 					  csDestHeight - drawHeight 
	
	;
	
	rqpop
	rqpop
	nop
	pop	r2		;blk start
	pop	r3		;blk stop
	
	subi	r6,1		;height - 1
	ssto	csTmpDrawHeight
	stwo	r0,r6
	cmplosi	r6,0			;draw height <0 (nothing to do)
	brts	noDrawBob
	rqldi	r0,csDestX	;delay slot
	nop			;delay slot
	nop			;delay slot
	ld	r1		;r1 = destX	delay slot
	
	or	r4,r2,r2	;blkStart 
	rqldi	r0,csSourceX	;internal X source offset
	muli	r4,16		;		blkStart * 16
	nop
	ld	r7
	nop
	add	r4,r4,r7		;real x source offset
	ssto	csTmpSourceX	;csTmpSourceX
	stwo	r0,r4
	
drawBobLoop
	
	cmplos	r2,r3		;(i) blk start < stop
	brtc	noDrawBob
	or	r4,r2,r2		;		delay slot
	nop				;		delay slot
	muli	r4,16			;i*16		delay slot
	nop				;		delay slot
	
	rqldi	r0,csDrawFunction	
	nop
	nop
	ld	r5			;draw function
	
	gpci	r7,2
	jmpi	r5,0		;jump draw function
	add	r4,r4,r1	;	+ destX	delay slot
	ssto	csTmpDestX	;		delay slot
	stwo	r0,r4		;store destx
	nop	;delay slot	;		delay slot
	
	rqldi	r0,csTmpSourceX
	nop
	nop
	ld	r4
	
	br	drawBobLoop
	addi	r2,1		;delay slot
	addi	r4,16		;delay slot
	ssto	csTmpSourceX	;delay slot
	stwo	r0,r4		;delay slot
		    
noDrawBob

	;get return code from draw functions
	
	dexti	>copySolidResult
	movei	r1,copySolidResult
	movei	r7,$7
	rqldi	r1,0
	nop
	nop
	ld	r0	;result
	nop
	lsri	r0,12		;TCCC RRRR GGGG BBBB -> 0000 0000 0000 TCCC
	nop
	and	r0,r0,r7	;0000 0000 0000 0CCC

	;dump
	
	;epilog
	
	rqpop
	rqpop
	rqpop
	poparqp	r7
	poparqp	r6
	poparqp	r5
	poparqp	r4
	pop	r3
	pop	r2
	pop	r1
	
	jmpi	r7,0
	nop		;delay slot
	nop		;delay slot	
	nop		;delay slot
	nop		;delay slot	
	
;******************************
;*
;* copySolid16xN
;* 
;* r0 = copyStruct
;*

copySolid16xN

	;prolog

	push	r1
	push	r2
	push	r3
	push	r4
	push	r5
	push	r6
	push	r7

	;
	
	rqldi	r0,csSourceAdrLow
	rqldi	r0,csSourceAdrHigh
	rqldi	r0,csSourceWidth
	ld	r2			;source low
	ld	r3			;source high
	ld	r4			;source width
	
	rqldi	r0,csTmpSourceY
	rqldi	r0,csTmpSourceX
	nop
	ld	r5			;source y
	ld	r6			;source x
		
	mul	r5,r5,r4		;source y * source width
	gmulhi	r1
	add	r5,r5,r6		;... + source x
	addtqi	r1,r1,0
	
	add	r2,r2,r5
	addt	r3,r3,r1		;add to source address
	
	;free   r1,r5,r6,r7
	
	rqldi	r0,csDestAdrLow
	rqldi	r0,csDestAdrHigh
	rqldi	r0,csDestWidth
	ld	r5			;destination low
	ld	r6			;destination high
	ld	r7			;destination width
	
	push	r0
	rqldi	r0,csTmpDestY
	rqldi	r0,csTmpDestX
	nop
	ld	r0			;dest y
	ld	r1			;dest x
	
	
	push	r7
	mul	r0,r0,r7		;dest y * dest width
	gmulhi	r7
	add	r0,r0,r1		;... + dest x
	addtqi	r7,r7,0
	
	add	r5,r5,r0
	addt	r6,r6,r7		;add to dest address
	
	rqpop
	rqpop
	nop
	pop	r7
	pop	r0
	
	;check x,y flip and jump to right function
	
	push	r2
	
	dexti	>copySolid16xNFlipFunctions
	movei	r2,copySolid16xNFlipFunctions
	rqldi	r0,csFlipXY
	nop
	nop
	ld	r1
	nop
	rqld	r2,r1
	nop
	nop
	ld	r2	
	
	rqpop
	jmpi	r2,0	
	nop		;delay slot
	pop	r2	;delay slot
	nop		;delay slot
	nop		;delay slot	

	;return
	
copySolid16xNEpilog
	
	;epilog
	
	rqpop
	rqpop
	rqpop
	pop	r7
	pop	r6
	pop	r5
	rqpop
	rqpop
	rqpop
	pop	r4
	pop	r3
	pop	r2
	
	rqpop
	jmpi	r7,0
	nop		;delay slot
	pop	r1	;delay slot
	nop		;delay slot
	nop		;delay slot	
	

copySolid16xNFlipFunctions
	
	word	copySolid16xNxy
	word	copySolid16xNxY
	word	copySolid16xNXy
	word	copySolid16xNXY
	
;******************************************************
;* x normal, y normal *********************************
;******************************************************
		
copySolid16xNxy
		
	rqldi	r0,csTmpDrawHeight
	subi	r4,8
	subi	r7,8			;dest width -8 (inner loop will add 8)
	ld	r1
	nop
	
copySolid16xNLoop
		
	edrqldi	r3,r2,0
	edrqldi	r3,r2,1
	edrqldi	r3,r2,2
	edrqldi	r3,r2,3
	edrqldi	r3,r2,4
	edrqldi	r3,r2,5
	edrqldi	r3,r2,6
	edrqldi	r3,r2,7
	addi	r2,8
	addtqi	r3,r3,0
	esadr	r6,r5
	edrqldi	r3,r2,0
	edrqldi	r3,r2,1
	edrqldi	r3,r2,2
	edrqldi	r3,r2,3
	edrqldi	r3,r2,4
	edrqldi	r3,r2,5
	edrqldi	r3,r2,6
	edrqldi	r3,r2,7
	
	push	r0
	push	r1
	addi	r5,8
	addtqi	r6,r6,0
	eld	r0
	eld	r1
	est	r0,0			;WTF
	est	r1,1
	eld	r0
	eld	r1
	est	r0,2
	est	r1,3
	eld	r0
	eld	r1
	est	r0,4
	est	r1,5
	eld	r0
	eld	r1
	est	r0,6
	est	r1,7
	esadr	r6,r5
	eld	r0
	eld	r1
	est	r0,0
	est	r1,1
	eld	r0
	eld	r1
	est	r0,2
	est	r1,3
	eld	r0
	eld	r1
	est	r0,4
	est	r1,5
	eld	r0
	eld	r1
	est	r0,6
	est	r1,7
	
	rqpop
	rqpop
	nop
	pop	r1
	pop	r0
	subi	r1,1
	brts	copySolid16xNLoop	
	add	r2,r2,r4	;delay slot
	addtqi	r3,r3,0		;delay slot
	add	r5,r5,r7	;delay slot
	addtqi	r6,r6,0		;delay slot
	
	br	copySolid16xNEpilog
	nop				;delay slot
	nop				;delay slot
	nop				;delay slot
	nop				;delay slot
	
;******************************************************
;* x normal, y flip *********************************
;******************************************************
		
copySolid16xNxY

	;
		
	push	r6
	push	r5
	push	r7
	push	r4
		
	rqldi	r0,csSourceY
	rqldi	r0,csTmpSourceY
	nop
	ld	r6
	ld	r7	
		
	rqldi	r0,csTmpDrawHeight
	rqldi	r0,csSourceWidth
	rqldi	r0,csDrawHeight
	ld	r1		;draw height tmp
	ld	r4		;source width
	ld	r5		;draw height 	
	
	;test source y shift
	
	cmpeq	r7,r6		;equal (so nothing to do)
	brts	copySolid16xNxYNoSourceYCorrection		;offset shift
	addqi	r7,r1,1		;delay slot
	nop			;delay slot
	add	r7,r7,r7	;delay slot
	nop			;delay slot
	
	sub	r5,r7,r5	;tmph-(h-tmph)+2 = 2*(tmph+1)-h
		
copySolid16xNxYNoSourceYCorrection	
	
	;
	
	nop
	subi	r5,1
	nop
	muls	r4,r4,r5
	gmulhi	r5
	
	add	r2,r2,r4
	addt	r3,r3,r5	;add to source
		
	rqpop
	rqpop
	rqpop
	pop	r4
	pop	r7
	pop	r5
	
	rqpop	
	addi	r4,8
	subi	r7,8			;dest width -8 (inner loop will add 8)
	pop	r6
	nop
	
copySolid16xNLoopFlipY
		
	edrqldi	r3,r2,0
	edrqldi	r3,r2,1
	edrqldi	r3,r2,2
	edrqldi	r3,r2,3
	edrqldi	r3,r2,4
	edrqldi	r3,r2,5
	edrqldi	r3,r2,6
	edrqldi	r3,r2,7
	addi	r2,8
	addtqi	r3,r3,0
	esadr	r6,r5
	edrqldi	r3,r2,0
	edrqldi	r3,r2,1
	edrqldi	r3,r2,2
	edrqldi	r3,r2,3
	edrqldi	r3,r2,4
	edrqldi	r3,r2,5
	edrqldi	r3,r2,6
	edrqldi	r3,r2,7
	
	push	r0
	push	r1
	addi	r5,8
	addtqi	r6,r6,0
	eld	r0
	eld	r1
	est	r0,0			;WTF
	est	r1,1
	eld	r0
	eld	r1
	est	r0,2
	est	r1,3
	eld	r0
	eld	r1
	est	r0,4
	est	r1,5
	eld	r0
	eld	r1
	est	r0,6
	est	r1,7
	esadr	r6,r5
	eld	r0
	eld	r1
	est	r0,0
	est	r1,1
	eld	r0
	eld	r1
	est	r0,2
	est	r1,3
	eld	r0
	eld	r1
	est	r0,4
	est	r1,5
	eld	r0
	eld	r1
	est	r0,6
	est	r1,7
	
	rqpop
	rqpop
	nop
	pop	r1
	pop	r0
	subi	r1,1
	brts	copySolid16xNLoopFlipY	
	sub	r2,r2,r4	;delay slot
	subtqi	r3,r3,0		;delay slot
	add	r5,r5,r7	;delay slot
	addtqi	r6,r6,0		;delay slot
	
	br	copySolid16xNEpilog
	nop				;delay slot
	nop				;delay slot
	nop				;delay slot
	nop				;delay slot	
	
;******************************************************
;* x flip, y normal ***********************************
;******************************************************
	
copySolid16xNXy	
	
	rqldi	r0,csTmpDrawHeight
	nop
	subi	r7,8			;dest width -8 (inner loop will add 8)
	ld	r1
	nop
	
copySolid16xNLoopFlipX
		
	esadr	r3,r2	
		
	erqldi	15
	erqldi	14
	erqldi	13
	erqldi	12
	erqldi	11
	erqldi	10
	erqldi	9
	erqldi	8
	
	erqldi	7
	erqldi	6
	erqldi	5
	erqldi	4
	erqldi	3
	erqldi	2
	erqldi	1
	erqldi	0
	
	esadr	r6,r5
	push	r0
	push	r1
	addi	r5,8
	addtqi	r6,r6,0
	eld	r0
	eld	r1
	est	r0,0			;WTF
	est	r1,1
	eld	r0
	eld	r1
	est	r0,2
	est	r1,3
	eld	r0
	eld	r1
	est	r0,4
	est	r1,5
	eld	r0
	eld	r1
	est	r0,6
	est	r1,7
	esadr	r6,r5
	eld	r0
	eld	r1
	est	r0,0
	est	r1,1
	eld	r0
	eld	r1
	est	r0,2
	est	r1,3
	eld	r0
	eld	r1
	est	r0,4
	est	r1,5
	eld	r0
	eld	r1
	est	r0,6
	est	r1,7
	
	rqpop
	rqpop
	nop
	pop	r1
	pop	r0
	subi	r1,1
	brts	copySolid16xNLoopFlipX	
	add	r2,r2,r4	;delay slot
	addtqi	r3,r3,0		;delay slot
	add	r5,r5,r7	;delay slot
	addtqi	r6,r6,0		;delay slot

	br	copySolid16xNEpilog
	nop				;delay slot
	nop				;delay slot
	nop				;delay slot
	nop				;delay slot
	
;******************************************************
;* x flip, y flip *************************************
;******************************************************
	
copySolid16xNXY	
	
	;
		
	push	r6
	push	r5
	push	r7
	push	r4
		
	rqldi	r0,csSourceY
	rqldi	r0,csTmpSourceY
	nop
	ld	r6
	ld	r7	
		
	rqldi	r0,csTmpDrawHeight
	rqldi	r0,csSourceWidth
	rqldi	r0,csDrawHeight
	ld	r1		;draw height tmp
	ld	r4		;source width
	ld	r5		;draw height 	
	
	;test source y shift
	
	cmpeq	r7,r6		;equal (so nothing to do)
	brts	copySolid16xNXYNoSourceYCorrection		;offset shift
	addqi	r7,r1,1		;delay slot
	nop			;delay slot
	add	r7,r7,r7	;delay slot
	nop			;delay slot
	
	sub	r5,r7,r5	;tmph-(h-tmph)+2 = 2*(tmph+1)-h
		
copySolid16xNXYNoSourceYCorrection	
	
	;
	
	nop
	subi	r5,1
	nop
	muls	r4,r4,r5
	gmulhi	r5
	
	add	r2,r2,r4
	addt	r3,r3,r5	;add to source
		
	rqpop
	rqpop
	rqpop
	pop	r4
	pop	r7
	pop	r5
	
	rqpop	
	nop
	subi	r7,8			;dest width -8 (inner loop will add 8)
	pop	r6
	nop
	
	
copySolid16xNLoopFlipXY
		
	esadr	r3,r2	
		
	erqldi	15
	erqldi	14
	erqldi	13
	erqldi	12
	erqldi	11
	erqldi	10
	erqldi	9
	erqldi	8
	
	erqldi	7
	erqldi	6
	erqldi	5
	erqldi	4
	erqldi	3
	erqldi	2
	erqldi	1
	erqldi	0
	
	esadr	r6,r5
	push	r0
	push	r1
	addi	r5,8
	addtqi	r6,r6,0
	eld	r0
	eld	r1
	est	r0,0			;WTF
	est	r1,1
	eld	r0
	eld	r1
	est	r0,2
	est	r1,3
	eld	r0
	eld	r1
	est	r0,4
	est	r1,5
	eld	r0
	eld	r1
	est	r0,6
	est	r1,7
	esadr	r6,r5
	eld	r0
	eld	r1
	est	r0,0
	est	r1,1
	eld	r0
	eld	r1
	est	r0,2
	est	r1,3
	eld	r0
	eld	r1
	est	r0,4
	est	r1,5
	eld	r0
	eld	r1
	est	r0,6
	est	r1,7
	
	rqpop
	rqpop
	nop
	pop	r1
	pop	r0
	subi	r1,1
	brts	copySolid16xNLoopFlipXY	
	sub	r2,r2,r4	;delay slot
	subtqi	r3,r3,0		;delay slot
	add	r5,r5,r7	;delay slot
	addtqi	r6,r6,0		;delay slot

	br	copySolid16xNEpilog
	nop				;delay slot
	nop				;delay slot
	nop				;delay slot
	nop				;delay slot	
	
;******************************
;*
;* copySolidTransparent16xN
;* 
;* r0 = copyStruct
;* r1 = y count-1	(trashed)
;*

copySolidTransparent16xN

	;prolog

	push	r1
	push	r2
	push	r3
	push	r4
	push	r5
	push	r6
	push	r7

	;
	
	rqldi	r0,csSourceAdrLow
	rqldi	r0,csSourceAdrHigh
	rqldi	r0,csSourceWidth
	ld	r2			;source low
	ld	r3			;source high
	ld	r4			;source width
	
	rqldi	r0,csTmpSourceY
	rqldi	r0,csTmpSourceX
	nop
	ld	r5			;source y
	ld	r6			;source x
	
	mul	r5,r5,r4		;source y * source width
	gmulhi	r1
	add	r5,r5,r6		;... + source x
	addtqi	r1,r1,0
	
	add	r2,r2,r5
	addt	r3,r3,r1		;add to source address
	
	;free   r1,r5,r6,r7
	
	rqldi	r0,csDestAdrLow
	rqldi	r0,csDestAdrHigh
	rqldi	r0,csDestWidth
	ld	r5			;destination low
	ld	r6			;destination high
	ld	r7			;destination width
	
	push	r0
	rqldi	r0,csTmpDestY
	rqldi	r0,csTmpDestX
	nop
	ld	r0			;dest y
	ld	r1			;dest x
	
	push	r7
	mul	r0,r0,r7		;dest y * dest width
	gmulhi	r7
	add	r0,r0,r1		;... + dest x
	addtqi	r7,r7,0
		
	add	r5,r5,r0
	addt	r6,r6,r7		;add to dest address
	
	rqpop
	rqpop
	nop
	pop	r7
	pop	r0
	nop
	
	rqldi	r0,csTmpDrawHeight
	subi	r4,8
	subi	r7,8			;dest width -8 (inner loop will add 8)
	ld	r1
	nop
	
copySolidTransparent16xNLoop
		
	edrqldi	r3,r2,0
	edrqldi	r3,r2,1
	edrqldi	r3,r2,2
	edrqldi	r3,r2,3
	edrqldi	r3,r2,4
	edrqldi	r3,r2,5
	edrqldi	r3,r2,6
	edrqldi	r3,r2,7
	addi	r2,8
	addtqi	r3,r3,0
	esadr	r6,r5
	edrqldi	r3,r2,0
	edrqldi	r3,r2,1
	edrqldi	r3,r2,2
	edrqldi	r3,r2,3
	edrqldi	r3,r2,4
	edrqldi	r3,r2,5
	edrqldi	r3,r2,6
	edrqldi	r3,r2,7
	
	push	r0
	push	r1
	addi	r5,8
	addtqi	r6,r6,0
	eld	r0
	eld	r1
	extri	r0,15
	estts	r0,0
	extri	r1,15
	estts	r1,1
	eld	r0
	eld	r1
	extri	r0,15
	estts	r0,2
	extri	r1,15
	estts	r1,3
	eld	r0
	eld	r1
	extri	r0,15
	estts	r0,4
	extri	r1,15
	estts	r1,5
	eld	r0
	eld	r1
	extri	r0,15
	estts	r0,6
	extri	r1,15
	estts	r1,7
	esadr	r6,r5
	eld	r0
	eld	r1
	extri	r0,15
	estts	r0,0
	extri	r1,15
	estts	r1,1
	eld	r0
	eld	r1
	extri	r0,15
	estts	r0,2
	extri	r1,15
	estts	r1,3
	eld	r0
	eld	r1
	extri	r0,15
	estts	r0,4
	extri	r1,15
	estts	r1,5
	eld	r0
	eld	r1
	extri	r0,15
	estts	r0,6
	extri	r1,15
	estts	r1,7
	
	rqpop
	rqpop
	nop
	pop	r1
	pop	r0
	subi	r1,1
	brts	copySolidTransparent16xNLoop	
	add	r2,r2,r4	;delay slot
	addtqi	r3,r3,0		;delay slot
	add	r5,r5,r7	;delay slot
	addtqi	r6,r6,0		;delay slot
	
	;epilog
	
	rqpop
	rqpop
	rqpop
	poparqp	r7
	poparqp	r6
	poparqp	r5
	poparqp	r4
	pop	r3
	pop	r2
	pop	r1
	
	jmpi	r7,0
	nop		;delay slot
	nop		;delay slot	
	nop		;delay slot
	nop		;delay slot
	
;******************************
;*
;* copySolidTransparentWithTest16xN
;* 
;* r0 = copyStruct
;* r1 = y count-1	(trashed)
;*

copySolidTransparentWithTest16xN

	;prolog

	push	r0
	push	r1
	push	r2
	push	r3
	push	r4
	push	r5
	push	r6
	push	r7

	;
	
	rqldi	r0,csSourceAdrLow
	rqldi	r0,csSourceAdrHigh
	rqldi	r0,csSourceWidth
	ld	r2			;source low
	ld	r3			;source high
	ld	r4			;source width
	
	rqldi	r0,csTmpSourceY
	rqldi	r0,csTmpSourceX
	nop
	ld	r5			;source y
	ld	r6			;source x
	
	mul	r5,r5,r4		;source y * source width
	gmulhi	r1
	add	r5,r5,r6		;... + source x
	addtqi	r1,r1,0
	
	add	r2,r2,r5
	addt	r3,r3,r1		;add to source address
	
	;free   r1,r5,r6,r7
	
	rqldi	r0,csDestAdrLow
	rqldi	r0,csDestAdrHigh
	rqldi	r0,csDestWidth
	ld	r5			;destination low
	ld	r6			;destination high
	ld	r7			;destination width
	
	push	r0
	rqldi	r0,csTmpDestY
	rqldi	r0,csTmpDestX
	nop
	ld	r0			;dest y
	ld	r1			;dest x
	
	push	r7
	mul	r0,r0,r7		;dest y * dest width
	gmulhi	r7
	add	r0,r0,r1		;... + dest x
	addtqi	r7,r7,0
		
	add	r5,r5,r0
	addt	r6,r6,r7		;add to dest address
	
	rqpop
	rqpop
	nop
	pop	r7
	pop	r0
	nop
	
	rqldi	r0,csTmpDrawHeight
	subi	r4,8
	subi	r7,8			;dest width -8 (inner loop will add 8)
	ld	r1
	
	;get last result and wide or again
	
	dexti	>copySolidResult
	movei	r0,copySolidResult
	nop
	rqldi	r0,0
	nop
	nop
	ld	r0
	nop
		
	;r0 	= code wide or
	;r1 	= loop count 
	;r3:r2 	= source
	;r4 	= source mod
	;r6:r5 	= destination	
	;r7 	= dest mod
	
copySolidTransparentWithTest16xNLoop
		
	edrqldi	r3,r2,0
	edrqldi	r6,r5,0
	edrqldi	r3,r2,1
	edrqldi	r6,r5,1
	edrqldi	r3,r2,2
	edrqldi	r6,r5,2
	edrqldi	r3,r2,3
	edrqldi	r6,r5,3
	edrqldi	r3,r2,4
	edrqldi	r6,r5,4
	edrqldi	r3,r2,5
	edrqldi	r6,r5,5
	edrqldi	r3,r2,6
	edrqldi	r6,r5,6
	edrqldi	r3,r2,7
	edrqldi	r6,r5,7
	
	esadr	r6,r5		;store address is esadr
	
	addi	r2,8
	addtqi	r3,r3,0
	addi	r5,8
	addtqi	r6,r6,0
	
	edrqldi	r3,r2,0
	edrqldi	r6,r5,0
	edrqldi	r3,r2,1
	edrqldi	r6,r5,1
	edrqldi	r3,r2,2
	edrqldi	r6,r5,2
	edrqldi	r3,r2,3
	edrqldi	r6,r5,3
	edrqldi	r3,r2,4
	edrqldi	r6,r5,4
	edrqldi	r3,r2,5
	edrqldi	r6,r5,5
	edrqldi	r3,r2,6
	edrqldi	r6,r5,6
	edrqldi	r3,r2,7
	edrqldi	r6,r5,7
	
	push	r2
	push	r1
	nop
	
	eld	r1	;source
	eld	r2	;dest
	extri	r1,15	;not transparent ?
	estts	r1,0	;	then store to dest
	orts	r0,r2	;	or dest value also to r0
	
	eld	r1	;source
	eld	r2	;dest
	extri	r1,15	;not transparent ?
	estts	r1,1	;	then store to dest
	orts	r0,r2	;	or dest value also to r0
	
	eld	r1	;source
	eld	r2	;dest
	extri	r1,15	;not transparent ?
	estts	r1,2	;	then store to dest
	orts	r0,r2	;	or dest value also to r0
	
	eld	r1	;source
	eld	r2	;dest
	extri	r1,15	;not transparent ?
	estts	r1,3	;	then store to dest
	orts	r0,r2	;	or dest value also to r0
	
	eld	r1	;source
	eld	r2	;dest
	extri	r1,15	;not transparent ?
	estts	r1,4	;	then store to dest
	orts	r0,r2	;	or dest value also to r0
	
	eld	r1	;source
	eld	r2	;dest
	extri	r1,15	;not transparent ?
	estts	r1,5	;	then store to dest
	orts	r0,r2	;	or dest value also to r0
	
	eld	r1	;source
	eld	r2	;dest
	extri	r1,15	;not transparent ?
	estts	r1,6	;	then store to dest
	orts	r0,r2	;	or dest value also to r0
	
	eld	r1	;source
	eld	r2	;dest
	extri	r1,15	;not transparent ?
	estts	r1,7	;	then store to dest
	orts	r0,r2	;	or dest value also to r0
	
	esadr	r6,r5		;store address is esadr
	
	eld	r1	;source
	eld	r2	;dest
	extri	r1,15	;not transparent ?
	estts	r1,0	;	then store to dest
	orts	r0,r2	;	or dest value also to r0
	
	eld	r1	;source
	eld	r2	;dest
	extri	r1,15	;not transparent ?
	estts	r1,1	;	then store to dest
	orts	r0,r2	;	or dest value also to r0
	
	eld	r1	;source
	eld	r2	;dest
	extri	r1,15	;not transparent ?
	estts	r1,2	;	then store to dest
	orts	r0,r2	;	or dest value also to r0
	
	eld	r1	;source
	eld	r2	;dest
	extri	r1,15	;not transparent ?
	estts	r1,3	;	then store to dest
	orts	r0,r2	;	or dest value also to r0
	
	eld	r1	;source
	eld	r2	;dest
	extri	r1,15	;not transparent ?
	estts	r1,4	;	then store to dest
	orts	r0,r2	;	or dest value also to r0
	
	eld	r1	;source
	eld	r2	;dest
	extri	r1,15	;not transparent ?
	estts	r1,5	;	then store to dest
	orts	r0,r2	;	or dest value also to r0
	
	eld	r1	;source
	eld	r2	;dest
	extri	r1,15	;not transparent ?
	estts	r1,6	;	then store to dest
	orts	r0,r2	;	or dest value also to r0
	
	eld	r1	;source
	eld	r2	;dest
	extri	r1,15	;not transparent ?
	estts	r1,7	;	then store to dest
	orts	r0,r2	;	or dest value also to r0
		
	rqpop
	rqpop
	nop
	pop	r1
	pop	r2
	
	subi	r1,1
	brts	copySolidTransparentWithTest16xNLoop	
	add	r2,r2,r4	;delay slot
	addtqi	r3,r3,0		;delay slot
	add	r5,r5,r7	;delay slot
	addtqi	r6,r6,0		;delay slot
	
	;store to copyResult
	
	dexti	>copySolidResult
	movei	r1,copySolidResult
	nop
	st	r1,r0
		
	;epilog
	
	rqpop
	rqpop
	rqpop
	poparqp	r7
	poparqp	r6
	poparqp	r5
	poparqp	r4
	poparqp	r3
	pop	r2
	pop	r1
	pop	r0
	
	jmpi	r7,0
	nop		;delay slot
	nop		;delay slot	
	nop		;delay slot
	nop		;delay slot		
	
;---------- data ----------
	
copySolidResult	word	0	
	
	