	
	.macro	rgbMul(rInOut)
		and	hold,rInOut,r5
		lsr	r10,last,16	;r10  = 0000 00RR
		and	r12,rInOut,r4	;r12  = 0000 00BB
		lsr	hold,rInOut,8	;hold = 0000 RRGG
		and	r11,last,$ff	;r11  = 0000 00GG
		
		;process
		
		fead		r10,r20		
		mul_fead	r10,r11,r20	;r * c
		mul_fead	r11,r12,r20	;g * c
		mul		r12		;b * c
		
		;
		
		lsr	r10,r10,8
		lsr	r11,r11,8
		lsr	r12,r12,8
			
		;assemble
		
		lsl	r10,r10,16	;00RR 0000
		lsl	hold,r11,8	;0000 GG00
		or	hold,last,r12	;0000 GGBB
		or	rInOut,last,r10	;00RR GGBB
	.endmacro
	
	org	hcoreStartPc
	
	.def	pixelCount	81000	;740*450/4	
	
	gssr	hold,0			;get core number
	cmpeq	last,0
	br.tc	notCoreZero
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	
	
	move	r20,0			;counter
	
doAgain	
	
	move	hold,testPic
	moveh	hold,last,>>testPic
	or	r0,last,0		;source
	
	move	hold,frame
	moveh	hold,last,>>frame
	or	r1,last,0		;dest
	
	move	hold,pixelCount
	moveh	hold,last,>>pixelCount	
	or	r2,last,0		;count
	
	move	hold,$ffff
	moveh	hold,last,$00ff	
	or	r5,last,0		;
	move	r4,$ff
	move	r3,1			;
	
	rqld	r0,0
	rqld	r0,2
	rqld	r0,4
	rqld	r0,6
	
loop
	ld	r13		;00RRGGBB
	;nop
	;nop
	ld	r14		;00RRGGBB
	;nop
	;nop
	ld	r15		;00RRGGBB
	;nop
	;nop
	ld	r16		;00RRGGBB
	;nop
	;nop
	
	cmpeq	r3,r2
	rqld.tc	r0,8		;request next
	rqld.tc	r0,10		;request next
	rqld.tc	r0,12		;request next
	rqld.tc	r0,14		;request next
	
	.execm	rgbMul(r13)
	.execm	rgbMul(r14)
	.execm	rgbMul(r15)
	.execm	rgbMul(r16)

	st	r13,r1,0
	st	r14,r1,2
	st	r15,r1,4
	st	r16,r1,6
	
	cmpeq	r3,r2
	br.tc	loop
	add	r3,r3,1		;delay slot
	add	r0,r0,8		;delay slot
	add	r1,r1,8		;delay slot
	nop			;delay slot
	
	add	hold,r20,1
	and	r20,last,$ff
	
	br	doAgain				
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	
	
	;loop forever
	
notCoreZero

	br	notCoreZero
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
