#include <vstypes.h>


	 /* Super fast 32-bit DC blocker: only 5 clocks/sample */
/*
	void DcBlock32N(register __i0 struct DcBlock32 *mem,
		     	register __a1 s_int16 shiftRight,
			register __i2 s_int32 *d,
			register __a0 u_int16 n);
*/
	.sect code,DcBlock32N
	.export _DcBlock32N
_DcBlock32N:
	add a0,ones,a0; ldx (i6)+1,null
	stx b0,(I6)+1 ; sty b1,(I6)
	stx c0,(I6)+1 ; sty c1,(I6)
	stx d0,(I6)+1 ; sty d1,(I6)
	stx le,(I6)+1 ; sty ls,(I6)
	jns $1
	sty lc,(I6);	ldx (i0)+1,c0		// c: mem[0]

	sub null,a1,a1;	ldx (i0)+1,c1	// a1 = 1-a1 -> shift right

	ldx (i0)+1,d0	// d: mem[1]
	ldx (i0)-3,d1

	loop a0,$2-1
	sub c,d,b			// b: y = mem[0]-mem[1];

	ashl d,a1,d;	ldx (i2)+1,c0	// mem[1]>>=shiftRight
	add b,d,b;	ldx (i2)-1,c1	//    y += mem[1]>>shiftRight
	sub c,b,d 			//    mem[1] = x-y
	sat d,d;	stx d0,(i2)+1
	sub c,d,b;	stx d1,(i2)+1	// b: y = mem[0]-mem[1];

$2:
	stx c0,(i0)+1
	stx c1,(i0)+1
	stx d0,(i0)+1
	stx d1,(i0)+1
$1:
	ldy (I6)-1,lc
	ldx (I6)-1,le ; ldy (I6),ls
	ldx (I6)-1,d0 ; ldy (I6),d1
	ldx (I6)-1,c0 ; ldy (I6),c1
	jr
	ldx (I6)-1,b0 ; ldy (I6),b1


	.end

#if 0
	/********* EVERYTHING FROM NOW ON IS PURELY DECORATIONAL!!! **********/

	.sect code,Generic
	.export _Generic
_Generic:
	stx mr0,(I6)+1 ; sty i7,(I6)
	stx lr0,(I6)+1 ; sty i5,(I6)	// return address
	stx i0,(I6)+1 ; sty i1,(I6)
	stx i2,(I6)+1 ; sty i3,(I6)
	stx i4,(I6)+1 ; sty i5,(I6)
	stx a0,(I6)+1 ; sty a1,(I6)
	stx b0,(I6)+1 ; sty b1,(I6)
	stx c0,(I6)+1 ; sty c1,(I6)
	stx d0,(I6)+1 ; sty d1,(I6)
	stx le,(I6)+1 ; sty ls,(I6)
	stx lc,(I6)



	ldx (I6)-1,lc
	ldx (I6)-1,le ; ldy (I6),ls
	ldx (I6)-1,d0 ; ldy (I6),d1
	ldx (I6)-1,c0 ; ldy (I6),c1
	ldx (I6)-1,b0 ; ldy (I6),b1
	ldx (I6)-1,a0 ; ldy (I6),a1
	ldx (I6)-1,i4 ; ldy (I6),i5
	ldx (I6)-1,i2 ; ldy (I6),i3
	ldx (I6)-1,i0 ; ldy (I6),i1
	ldx (I6)-1,lr0 ; ldy (I6),i5
	jr
	ldx (I6)-1,mr0 ; ldy (I6),i7
#endif
