; decruncher

read  = $34028	; set end addr of your crunched file
; current adress is the one of an hires page called PAGE.CR
; if you want to test the decruncher use showmem at $30000
; load PAGE.CR at $30000 (command RI),assemble then
; type G S and watch in the memory

lowwr = $30000	; set destination address

s:
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
jsr getnextlwd
notempty1:
bcs.S bigone		

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

moveq #3,d1	
clr.w d4	

dojmp:		
		
jsr rdd1bits	
move.w d2,d3	
add.w d4,d3	

getd3chr:

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

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

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

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


moveq #8,d1	
jsr rdd1bits	
move.w d2,d3	
move.w #12,d1	
jmp dodupl	

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

dodupl:
jsr 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

; Written by LORD BLITTER

; Christian MORANT
; 8, av. des Pagodes
; 1020 Brussels
; Belgium

; official dealer : BS1
