CrStart    =   $c19468
FillStart  =   $1c990



**********************************************************
*							 *
*	 	    DeCruncher Routine			 *
*							 *
*		   by FRYNS & DR. KAOS			 *
*							 *
*			   of				 *
*							 *
*			 WISDOM				 *
*							 *
*	     made for DR. FLAP of LOS AMIGOS		 *
*							 *
**********************************************************


;	  Read DeCruncher.TXT  for instructions

JMP	ERROR

************************************************************
*		Fyld hukommelsen			   *
************************************************************

F:
	move.l	#FillStart,a0
	move.l	#$7FF00,d1
	move.l	#$AA,d0
	move.l	#$FF0,d2
	move.l	#$dff180,a2
FilCon:
	move.w	d2,(a2)
	move.b	d0,(a0)+
	cmp.l	a0,d1
	bge	FilCon	
	rts

************************************************************
*		Find JMP Adressen			   *
************************************************************
J:
	move.l	#0,d0
	move.l	#0,d1
	move.l	#0,d2
	move.l	#0,d3
	move.l	#0,d4
	move.l	#0,d5
	move.l	#0,d6
	move.l	#0,d7
	move.l	#0,a0
	move.l	#0,a1
	move.l	#0,a2
	move.l	#0,a3
	move.l	#0,a4
	move.l	#0,a5
	move.l	#0,a6
	move.l	#CrStart,a0
	jsr	low
	move.l	#$4EF9,d0
	move.l	#$3000,d1
	move.l	#CrStart,a0
	move.l	a0,a1
	move.l	a0,a2
Find:
	Cmp.w	(a0),d0
	beq	Fundet
	addq.l	#2,a0
	dbra	d1,Find
	jmp	error		;	Not Crunched File

************************************************************
*		Indsaet RTS og find start adressen	   *
************************************************************

Fundet:
	move.l	a0,CrJMP
	move.w	#$4E75,(a0)+
	move.l	a0,APrgStart
	jsr	(a2)
	move.l	aPrgstart,a0
	move.l	(a0),d0
	move.l	d0,Prgstart
	move.l	prgstart,a0
	jsr	low
	move.l	d0,PMemType
	cmp.l	CMemType,d0
	beq	Sammen
	jmp	Decrunch	

************************************************************
*		I hvilken type MEM ligger programmet	   *
************************************************************

Low:
	move.l	#$7FF00,d0
	cmp.l	a0,d0
	ble	HighChip
	rts

HighChip:
	move.l	#$FFFFF,d0
	cmp.l	a0,d0
	ble	HighFast
	rts

HighFast:
	move.l	#$C7FFFF,d0
	cmp.l	a0,d0
	ble	Nowhere
	rts
	
Nowhere:
	jmp error		; Hvor fanden blev programmet af


************************************************************
*		Ligger de i samme MEM type		   *
************************************************************

sammen:
	move.l	CMemType,d0
	move.l	PMemType,d1
	cmp.l	d1,d0
	blt	Decrunch
	bgt	foer
	jmp	error

Foer:
	move.l	#CrStart,d0
	move.l	d0,PMemType
	jmp	Decrunch


************************************************************
*		Find programmets slut adresse		   *
************************************************************
	
Decrunch:	
	move.l	PMemType,a0
	subq.l	#2,a0
	move.l	PrgStart,a1
	move.l	#$0F0,d0
	move.l	#$dff180,a2
Loop2:
	move.w	d0,(a2)
	cmp.b	#$AA,-(a0)
	bne	Found
	cmp.l	a0,a1
	bne	Loop2
	jmp	error		; File is not where it says it is

************************************************************
*		Save file				   *
************************************************************

Found:
	addq.l	#1,a0
	move.l	a0,d0
	lsr.l	#2,d0
	lsl.l	#2,d0
	addq.l	#4,d0
	move.l	d0,PrgEnd
	move.l	PrgEnd,d0
	move.l	PrgStart,d1
	sub.l	d1,d0
	lsr.l	#2,d0
	move.l	d0,PrgLength
	move.l	d0,d1
	lsl.l	#2,d1
	add.l	#220,d1
	move.l	d1,SaveLength	
	add.l	d0,HUNKS_F0R+20
	add.l	d0,HUNKS_F0R+32
	Move.l	prgStart,HUNKS_F0R+38
	move.l	PrgEnd,HUNKS_F0R+44
	Move.l	prgStart,a0
	move.l	PrgEnd,a1
	Move.l	#HUNKS_F0R,a2
	move.l	#HUNKS_EFTER,a3
	move.l	#55,d0
	move.l	#163,d1
	sub.l	#164,a0
	move.l	a0,d4
LoopK:
	move.b	(a2)+,(a0)+
	dbf	d1,loopK
LoopE:
	move.b	(a3)+,(a1)+
	dbf	d0,loopE
	move.l	a1,d1
	move.l	d4,d0
	rts

************************************************************
*		Error indikator				   *
************************************************************


Error:
	move.l	#$F00,d1
	move.l	#$dff180,a1
Loo:	move.w	d1,(a1)
	btst	#6,$bfe001
	bne	loo	
	rts

SaveLength:
	dc.l	0
PrgLength:
	dc.l	0
PMemType:
	dc.l	0
CMemType:
	dc.l	0
CrJMP:
	dc.l	0
PrgStart:
	dc.l	0
APrgStart:
	dc.l	0
PrgEnd:
	dc.l	0


***************************************************
*		RUN PRG I HEX			  *
***************************************************

HUNKS_F0R:

	dc.l	$000003F3 , $00000000 , $00000002 , $00000000
	dc.l	$00000001 , $40000020 , $00000001 , $000003E9
	dc.l	$00000020 , $2C7C0004 , $80002A7C , $0007D800
	dc.l	$200E220D , $9280203C , $00000080 , $D2802841
	dc.l	$203C0000 , $0000B08D , $6E000022 , $203C0000
	dc.l	$0080B08E , $6E00002E , $60000002 , $204C224D
	dc.l	$1320B3CE , $6D00001A , $6000FFF6 , $207C0000
	dc.l	$0080224E , $12D8B3CD , $6E000006 , $6000FFF6
	dc.l	$204E4ED0 , $204E227C , $00000060 , $53891121
	dc.l	$B3FC0000 , $00486D00 , $00066000 , $FFF25288
	dc.l	$4ED04E75	; 164 bytes

HUNKS_EFTER:

	dc.l	$000003EC , $00000006
	dc.l	$00000000 , $00000014 , $0000001E , $0000002A
	dc.l	$0000004A , $00000064 , $0000006E , $00000000
	dc.l	$000003F2 , $000003EB , $00000001 , $000003F2
				; 56 bytes
