;		*** DeCrunching and playroutine for STC ***

		bsr	stc_decrunch
;		...
;		MAIN PROGRAM
;		...
;		bsr	mt_music	(repeat every 1/50 seconds!)
;		....
;		....
;		bsr	mt_end
;
; You must allocate memory for decrunched module (size equal to 
; original module, size found on crunched module. See document.)
; Put address of crunched module to a0 and address of allocated memory
; to a1.
;
; Look at line #3 on a source code. As you see, you must add #8 to 
; startaddress of crunched module.

stc_decrunch:	move.l	DeCrunchBase(pc),a1     ;Address of memory to a1.
		move.l	#CrunchBase+8,a0	;Start of module to a0.
		lea	stc_e-3(pc),a4
		moveq	#0,d0
		move.l	CrunchBase+4,d1		; Original size to d1.
		moveq	#8,d2
		bsr.s	stc_c
		move.b	d3,(a1)+
		subq.l	#1,d1
stc_1:		moveq	#2,d2
		bsr.s	stc_c
		beq.s	stc_2
		cmpi.w	#2,d3
		blt.s	stc_8
		bgt.s	stc_3	
		moveq	#7,d2
		bra.s	stc_4

stc_3:		moveq	#2,d2
		bsr.s	stc_c
		move.l	d3,d2
		addq.l	#3,d2
stc_4:		move.b	-1(a1),d4
stc_5:		bsr.s	stc_c
		cmp.b	0(a4,d2.w),d3
		beq.s	stc_7
		blt.s	stc_6
		or.b	5(a4,d2.w),d3
stc_6:		add.b	d3,d4
		move.b	d4,(a1)+
		subq.l	#1,d1
		bne.s	stc_5
		bra.s	stc_7

stc_2:		bsr.s	stc_d
		sub.l	d5,d1
		moveq	#8,d2
stc_2b:		bsr.s	stc_c
		move.b	d3,(a1)+
		subq.l	#1,d5
		bne.s	stc_2b

stc_7:		nop		;  <---	If you want those decrunching colours
		tst.l	d1	;this would be a perfect place...
		bne.s	stc_1	;(You can try for example 'clr.w $dff180'
		rts		;or 'ror.w #1,$dff180' or 'move.w $dff006,$dff180')

stc_8:		bsr.s	stc_d
		sub.l	d5,d1
		moveq	#8,d2
		bsr.s	stc_c
stc_9:		move.b	d3,(a1)+
		subq.l	#1,d5
		bne.s	stc_9
		bra.s	stc_7

stc_c:		move.l	(a0),d3
		tst.w	d0
		beq.s	stc_a
		lsl.l	d0,d3
stc_a:		rol.l	d2,d3
		add.w	d2,d0
		cmpi.w	#16,d0
		blt.s	stc_b
		andi.w	#$f,d0
		addq.l	#2,a0
stc_b:		move.l	#$ffff0000,d6
		rol.l	d2,d6
		and.l	#$0000ffff,d6
		and.l	d6,d3
		rts

stc_d:		moveq	#6,d2
		bsr.s	stc_c
		move.l	d3,d5
		cmpi.w	#%111000,d5
		blt.s	stc_gl2
		cmpi.w	#%111011,d5
		blt.s	stc_gl1
		moveq	#16,d2
		bsr.s	stc_c
		lsl.l	#2,d3
		move.l	d3,d5
		moveq	#2,d2
		bsr.s	stc_c
		or.l	d3,d5
		bra.s	stc_gl2
stc_gl1:	andi.w	#3,d5
		lsl.l	#8,d5
		lsl.l	#2,d5
		moveq	#10,d2
		bsr.s	stc_c
		or.l	d3,d5
stc_gl2:	addq.l	#1,d5
		rts

stc_playbase:	dc.l	0
stc_e:		dc.b	%00000100,%00001000,%00010000,%00100000,%01000000
		dc.b	%11111000,%11110000,%11100000,%11000000,%10000000
mt_erotus:	equ	28


