	;--------------------------------------
	;-- BYTEKILLER V2.0 DECRUNCH ROUTINE --
	;--------------------------------------

; little changes are made to allow it to use with SAS

		xdef	_Decrunch

		section	debytekiller,code

_Decrunch	movem.l	d2-d5/a2,-(sp)
						;in a0 obj (src)
						;in a1 Dest
		move.l	(a0)+,d0
		move.l	(a0)+,d1
		move.l	(a0)+,d5
		move.l	a1,a2			;in a2 dest
		add.l	d0,a0			;in a0 end of Source
		add.l	d1,a2			;in a2 end of dest

		move.l	-(a0),d0
		eor.l	d0,d5
L7F8		lsr.l	#1,d0
		bne.s	L800
		bsr.S	L8A0
L800		bcs.s	L83E
		moveq	#8,d1
		moveq	#1,d3
		lsr.l	#1,d0
		bne.s	L80E
		bsr.S	L8A0
L80E		bcs.s	L86A
		moveq	#3,d1
		clr.w	d4
L814		bsr.S	L8AC
		move.w	d2,d3
		add.w	d4,d3
L81C		moveq	#7,d1
L81E		lsr.l	#1,d0
		bne.s	L826
		bsr.S	L8A0
L826		roxl.l	#1,d2
		dbra	d1,L81E
		move.b	d2,-(a2)
		dbra	d3,L81C
		bra.S	L878
 
L836		moveq	#8,d1
		moveq	#8,d4
		bra.S	L814
 
L8AC		subq.w	#1,d1
		clr.w	d2
L8B0		lsr.l	#1,d0
		bne.s	L8BE
		move.l	-(a0),d0
		eor.l	d0,d5
		move.w	#$10,CCR
		roxr.l	#1,d0
L8BE		roxl.l	#1,d2
		dbra	d1,L8B0
		rts

L83E		moveq	#2,d1
		bsr.S	L8AC
		cmp.b	#2,d2
		blt.s	L860
		cmp.b	#3,d2
		beq.s	L836
		moveq	#8,d1
		bsr.S	L8AC
		move.w	d2,d3
		move.w	#$C,d1
		bra.S	L86A

L8A0		move.l	-(a0),d0
		eor.l	d0,d5
		move.w	#$10,CCR
		roxr.l	#1,d0
		rts

L860		move.w	#9,d1
		add.w	d2,d1
		addq.w	#2,d2
		move.w	d2,d3
L86A		bsr.S	L8AC
L86E		subq.w	#1,a2
		move.b	0(a2,d2.w),(a2)
		dbra	d3,L86E
L878		cmp.l	a2,a1
		blt.W	L7F8
		movem.l	(sp)+,d2-d5/a2
		rts

		END
