*	decruncher v1.1

*	changes made :	all fixed branches are now relatives
*			faster,shorter,easier to work with)

*******************************************************************************

read		equ	$5C6D4
lowwr		equ	$30000

		lea	read,a0
		lea	lowwr,a1
		move.l	-(a0),a2
		add.l	a1,a2
		move.l	-(a0),d5
		move.l	-(a0),d0
		eor.l	d0,d5

notfinished	lsr.l	#1,d0
		bne.S	notempty1
		bsr	getnextlwd
notempty1	bcs.S	bigone

		moveq	#8,d1
		moveq	#1,d3
		lsr.l	#1,d0
		bne.S	notempty2
		bsr	getnextlwd
notempty2	bcs.S	dodupl

		moveq	#3,d1
		clr.w	d4
dojmp		bsr	rdd1bits
		move.w	d2,d3
		add.w	d4,d3

getd3chr	moveq	#7,d1
get8bits	lsr.l	#1,d0
bne.S notempty3
bsr getnextlwd
notempty3:
roxl.l #1,d2
dbf d1,get8bits	

move.b d2,-(a2)
dbf d3,getd3chr	
bra nextcmd

bigjmp:
moveq #8,d1	
moveq #8,d4	
		
		
		
bra dojmp

bigone:
moveq #2,d1	
bsr rdd1bits
cmp.b #2,d2	
blt.S midjumps	
cmp.b #3,d2	
beq.S bigjmp	


moveq #8,d1	
bsr rdd1bits	
move.w d2,d3	
move.w #12,d1	
bra dodupl	

midjumps:
move.w #9,d1	
add.w d2,d1
addq #2,d2
move.w d2,d3	

dodupl:
bsr rdd1bits	
		
		
copyd3bytes:
subq #1,a2

move.b (a2,d2.w),(a2)

dbf d3,copyd3bytes

nextcmd:
cmp.l a2,a1
blt.L notfinished
tst.l d5
bne.S damage
illegal

damage:
move.w #$ffffffff,d0
damloop:
move.w d0,$dff180
subi.l #1,d0
bne.S damloop
illegal


getnextlwd:
move.l -(a0),d0
eor.l d0,d5
move.w #$10,ccr
roxr.l #1,d0
rts

rdd1bits:	
subq.w #1,d1
clr.w d2

getbits:
lsr.l #1,d0
bne.S notempty
move.l -(a0),d0
eor.l d0,d5
move.w #$10,ccr
roxr.l #1,d0

notempty:
roxl.l #1,d2
dbf d1,getbits
rts
