;This is the source to decrunch TetraCrunched data. it belongs to TETRAGON
;and all credits must go to then (or him) (????).
*--------------------------------------------------------------------------
	lea	proglist,a5		;actual programlist
	move.l	16(a5),a1		;pointer to crunched data
	bsr	decrunch
	move.l	(a5),a5
	; jsr	(a5)		;To run the program (which you crunched earlier)

	clr.l	d0
	rts

*--------------------------------------------------------------------------
proglist	dc.l	$90000	;low mem
	dc.l  	$140000	;high mem
	dc.l	$5b06d	;variabele in each file different (nr1)
	dc.l	$c4e8	;variabele in each file different (nr2)
	dc.l	cdata	;pointer to crunched data
	dc.l	-$5b	;variabele in each file different (nr3)

*--------------------------------------------------------------------------
decrunch	MOVEQ	#0,D7
	MOVEA.L	(a5),A4		;list (low mem)
	MOVEA.L	A4,A0
LC4327A	ADDA.L	12(a5),A0		;list (nr2)
	CMPA.L	A4,A1
	BGT.S	LC4328C
	MOVEA.L	A1,A0
	move.l	12(a5),a3		;list (nr2)
	ADDA.L	(A3),A0
	BRA.S	LC43292
LC4328C	MOVE.B	(A1)+,(A4)+
	CMPA.L	A0,A4
	BLT.S	LC4328C

LC43292	move.l	8(a5),a1	;list (nr1)		
	MOVEA.L	-(A0),A2
	ADDA.L	A1,A2
	MOVE.L	-(A0),D0
LC4329E	LSR.L	#1,D0
	BNE.S	LC432A4
	BSR.S	LC432D8
LC432A4	BCS.S	LC43310
	MOVEQ	#8,D1
	MOVEQ	#1,D3
	LSR.L	#1,D0
	BNE.S	LC432B0
	BSR.S	LC432D8
LC432B0	BCS.S	LC432EE
	MOVEQ	#3,D1
	MOVEQ	#0,D4
LC432B6	BSR.S	LC432FE
	MOVE.W	D2,D3
	ADD.W	D4,D3
LC432BC	MOVEQ	#7,D1
LC432BE	LSR.L	#1,D0
	BNE.S	LC432C4
	BSR.S	LC432D8
LC432C4	ROXL.L	#1,D2
	DBF	D1,LC432BE
	MOVE.B	D2,-(A2)
	DBF	D3,LC432BC
	BRA.S	LC432F8
LC432D2	MOVEQ	#7,D1
	MOVEQ	#8,D4
	BRA.S	LC432B6
LC432D8	MOVE.L	-(A0),D0
	MOVE.B	D0,D7
	MOVE.B	#$10,CCR
	ROXR.L	#1,D0
	RTS

LC432E6	MOVEQ	#9,D1
	MOVE.W	D2,D3
	ADD.W	D2,D1
	ADDQ.W	#2,D3
LC432EE	BSR.S	LC432FE
LC432F0	MOVE.B	-1(A2,D2.W),-(A2)
	DBF	D3,LC432F0
LC432F8	CMPA.L	A2,A1
	BLT.S	LC4329E
	BRA.S	LC43336
LC432FE	SUBQ.W	#1,D1
	MOVEQ	#0,D2
LC43302	LSR.L	#1,D0
	BNE.S	LC43308
	BSR.S	LC432D8
LC43308	ROXL.L	#1,D2
	DBF	D1,LC43302
	RTS

LC43310	MOVEQ	#2,D1
	BSR.S	LC432FE
	CMPI.B	#2,D2
	BLT.S	LC432E6
	CMPI.B	#3,D2
	BEQ.S	LC432D2
	MOVEQ	#8,D1
	BSR.S	LC432FE
	MOVE.W	D2,D3
	ADDQ.W	#4,D3
	MOVEQ	#$B,D1
	BRA.S	LC432EE
	MOVEA.L	(A4),A0
	DC.W	$4554
	ADDQ.W	#1,D1
	DC.W	$474F
	DC.W	$4E20
LC43336	MOVE.l	20(a5),D7	;list (nr3)

LC4333A	move.l	(a5),a0	;list (low mem)
	move.l	4(a5),a2	;list (high mem)
LC43344	MOVE.B	(A1)+,D0
	CMP.B	D7,D0
	BNE.S	LC4335A
	MOVEQ	#0,D1
	MOVE.B	(A1)+,D1
	BEQ.S	LC4335A
	MOVE.B	(A1)+,D0
	ADDQ.W	#1,D1
LC43354	MOVE.B	D0,(A0)+
	DBF	D1,LC43354

LC4335A	MOVE.B	D0,(A0)+
	CMPA.L	A2,A1
	BLT.S	LC43344
start	rts

cdata	;Place here the crunched tetradata, without the decrunch-header!!!
	;(Stripped with tetrasave)
        incbin "ram:sopp"