;*******************************************************************************
; C H A M E L E O N   DSP Assembler file                                       *
;*******************************************************************************
;Aleix Riera
;www.fjarre.com/~aleix
;aleix@fjarre.com
;*******************************************************************************
;MODULE: SUBTRACT
;
;	Fills the OutputStereoBuffer with InputBuffer minus the OpBuffer.
;
;	OutStereoBuffer[i] = InStereoBuffer[i] - OpBuffer[i]
;
; ARGUMENTS:
;	(X)   = InAddr (L)
;	(X+1) =	OpAddr (L)
;	(X+2) = OutAddr (L)
;
;*******************************************************************************
module_sub:
	define	R_InL			'R1'
	define	R_InR			'R5'
	define	R_OutL			'R2'
	define	R_OutR			'R6'
	define	R_OpL			'R3'
	define	R_OpR			'R7'

;===============================CODE=====================================

	MOVE	X:(R_X),R_InL
	MOVE	X:(R_X)+,R_InR
	MOVE	X:(R_X),R_OpL
	MOVE	X:(R_X)+,R_OpR
	MOVE	X:(R_X),R_OutL
	MOVE	X:(R_X),R_OutR

	MOVE		X:(R_InL)+,A
	MOVE		X:(R_OpL)+,X0		Y:(R_OpR)+,Y0
	.LOOP	#BUFFER_SIZE
	;----------------------------------------------------------------
	SUB	X0,A				Y:(R_InR)+,B
	SUB	Y0,B	X:(R_OpL)+,X0		Y:(R_OpR)+,Y0
	MOVE		A,X:(R_OutL)+
	MOVE		X:(R_InL)+,A		B,Y:(R_OutR)+
	;----------------------------------------------------------------
	.ENDL

;===============================CODE=====================================

	undef	R_InL
	undef	R_InR
	undef	R_OutL
	undef	R_OutR
	undef	R_OpL
	undef	R_OpR
	
	RTS