execbase	equ	4
openlib	equ	-408
closelib	equ	-414
open	equ	-30
close	equ	-36
read	equ	-42
write	equ	-48
lock	equ	-84
unlock	equ	-90
allocmem	equ	-198
freemem	equ	-210
examine	equ	-102

	cmp.b 	#$0a,(a0)	
	beq 	uitleg		
	cmp.b 	#"?",(a0)
	beq 	uitleg
	
CONTINUE	move.l	#FileBuffel,a1
	move.l	a0,FileName
copy1:	move.b 	(a0)+,(a1)+
	cmp.b 	#$0a,(a0)
	bne	copy1
	move.b	#0,(a0)

	move.l 	execbase,a6
	lea 	libname,a1
	jsr 	openlib(a6)
	tst.l	d0
	beq	rtd
	move.l 	d0,dosbase
	
	move.l	dosbase,a6
	jsr 	-60(a6)
	move.l	d0,OutputHandle
	
	move.l	FileName,d1	
	move.l	#-2,d2
	move.l	dosbase,a6
	jsr	lock(a6)
	tst.l	d0
	beq	FileERROR
	move.l	d0,savelock
	
	move.l	savelock,d1
	move.l	#infoblock,d2
	move.l	dosbase,a6
	jsr	examine(a6)
	move.l	infoblock+124,d0
	move.l	d0,lengte
	move.l	$4,a6
	move.l	#$10000,d1
	jsr	allocmem(a6)		
	move.l	d0,HDDIR
	
	move.l	FileName,d1		
	move.l	#1005,d2
	move.l	dosbase,a6
	jsr	open(a6)
	tst.l	d0
	beq	filenietopen
	move.l	d0,filehandle
	
	move.l	d0,d1
	move.l	HDDIR,d2
	move.l	lengte,d3
	move.l	dosbase,a6
	jsr	read(a6)
	move.l	filehandle,d1
	move.l	dosbase,a6
	jsr	close(a6)

	move.l	dosbase,a6
	move.l	savelock,d1
	jsr	unlock(a6)

	move.l	HDDIR,a3
	move.l	a3,a4		
	move.l	a3,a5
	move.l	a3,d4
	move.l	lengte,d3
	add.l	d3,d4		
 	subq 	#1,d4	

START:	move.b	#"-",d3		
substart	cmp.b 	(a4)+,d3
	beq.s	FirstLine
	bra	substart

FirstLine:	addq	#2,a4		
	cmp.b	(a4),d3		
	bne	substart
DatumFound:	move.l	a4,a3
	sub	#28,a3
	addq	#4,a4		
	clr.l	d3
	clr.l	d5
	clr.l	d6
	move.b	#17,d5		
NaamCopy:	subq	#1,d5
	move.b	(a3)+,(a5)+
	cmp.b	#$20,(a3)
	bne	NaamCopy
	move.l	a3,a2		
ZKlengte	addq	#1,a2		
	cmp.b	#$30,(a2)
	blo	ZKlengte	
	cmp.b	#$39,(a2)
	bhi	ZKlengte
	move.l	a4,d6
	sub.b	#11,d6		
	move.l	d6,d3
	sub.l	a2,d6		
	subq	#7,d3
	move.l	d3,a2
	cmp.b	#4,d6
	blo.s	Bytes
	cmp.b	#7,d6
	blo.s	KiloBytes
	bra.s	MegaBytes

Spacefill	move.b	#$20,(a5)+
	dbra	d5,Spacefill
	rts
	
Bytes:	move.l	(a2),d6
	bsr	Spacefill
	move.l	d6,(a5)+
	move.b	#"B",(a5)+
	bra.s	LengteEnd
KiloBytes:	move.l	(a2),d6
	bsr	Spacefill
	move.l	d6,(a5)+
	move.b	#"K",(a5)+
	bra.s	LengteEnd
MegaBytes:	move.l	(a2),d6
	move.l	d6,(a5)+
	move.b	#"M",(a5)+
LengteEnd:	move.b	#$20,(a5)+
	
	
search1:	addq	#1,a4
	cmp.l	d4,a4
	beq	KLAAR
	cmp.b	#$A,(a4)
	beq	CommentEnd
	cmp.b	#$20,(a4)
	bne.s	charsrch
	
CharSrch2	addq	#1,a4
	cmp.b	#$20,(a4)
	beq.s	search1a
	subq	#1,a4
CharSrch2a	addq	#1,a4
CharSrch2b	cmp.b	#$30,(a4)
	blo.s	search1a
	cmp.b	#$7b,(a4)
	bhi.s	search1a
	cmp.b	#$39,(a4)
	blo.s	Found1
	cmp.b	#$60,(a4)
	bhi.s	Found1
	cmp.b	#$41,(a4)
	blo.s	search1a
	cmp.b	#$5b,(a4)
	bhi.s	search1a
Found1	subq	#1,a4
	bra	FoundOne
search1a	subq	#1,a4
	bra	search1


search2:	cmp.b	#".",(a4)		
	beq	CharSrch2		
	cmp.b	#"/",(a4)
	beq	CharSrch2a
	cmp.b	#"(",(a4)
	beq	CharSrch2
	cmp.b	#")",(a4)
	bne	search1
	addq	#1,a4
	cmp.b	#$20,(a4)
	beq	Found1
	cmp.b	#$a,(a4)
	beq	Found1
	bra	CharSrch2b		
	
	
charsrch:	cmp.b	#$30,(a4)		
	blo	search2	
	cmp.b	#":",(a4)
	beq	CharSrch2
	cmp.b	#$39,(a4)		
	bhi.s	Asrch
	bra.s	FoundOne
Asrch	cmp.b	#$41,(a4)		
	blo	search1
	cmp.b	#$5a,(a4)		
	bhi.s	asrch
	bra.s	FoundOne
asrch	cmp.b	#$61,(a4)		
	blo	search1
	cmp.b	#$7a,(a4)		
	bhi	search1
	bra.s	FoundOne
	even

CommentEnd:	addq	#1,a4
	cmp.b	#$a,(a4)
	beq	CommentEnd
	
cme:	add	#25,a4		
	cmp.b	#"-",(a4)		
	bne.s	cmee
	addq	#3,a4		
	cmp.b	#"-",(a4)
	bne.s	cmee
	move.b	#$a,(a5)+
	bra	DatumFound
cmee	addq	#1,a4
	bra	search1
	
	even
	
FoundOne:	move.b	(a4),(a5)+
	cmp.l	d4,a4		
	bhi.s	KLAAR
	bra	search1

	
KLAAR:	subq	#1,a5
	move.b	#$A,(a5)+
	move.l	a5,d5
	move.l	HDDIR,d6
	sub.l	d6,d5
	move.l	d5,lengte

	move.l	FileName,d1		
	move.l	#1006,d2
	move.l	dosbase,a6
	jsr	open(a6)
	tst.l	d0
	beq.s	filenietopen
	move.l	d0,filehandle
	
	move.l	d0,d1
	move.l	HDDIR,d2
	move.l	lengte,d3
	move.l	dosbase,a6
	jsr	write(a6)
	move.l	filehandle,d1
	move.l	dosbase,a6
	jsr	close(a6)

filenietopen: move.l	HDDIR,a1
	move.l	lengte,d0
	move.l	$4,a6
	jsr	freemem(a6)
	
locknietgelukt:
	move.l	dosbase,a1
	move.l	$4,a6
	jsr	closelib(a6)

rtd:	moveq	#0,d0
	rts

FileERROR:	move.l	#NAAMERROR,d2
	move.l	#NAAMlen,d3
	move.l	dosbase,a6
	move.l	OutputHandle,d1
	jsr	-48(a6)
	bra	locknietgelukt
			
uitleg:	move.l 	264(a2),a4
	move.l 	#12,d0
	jsr 	(a5)
	move.l 	-24(a2),a4
	move.l 	d0,d1
	move.l 	#text,d2
	move.l 	#textlen,d3
	move.l 	#12,d0
	jsr 	(a5)
	bra	rtd

text:	dc.b	$9B,"33;1m  FIDCON",$9B,"0m V0.3 Beta ",$0A
	dc.b	"syntax: FIDCON <name_filelist>"
CR:	dc.b	$0A
textlen	equ *-text

NAAMERROR:	dc.b	"File Error !!!!",$A
NAAMlen	equ *-NAAMERROR

prgname: 	dc.l	0
comment:	dc.l	0
	even
libname: 	dc.b 	"dos.library",0
dosbase:	dc.l 	0
HDDIR:	dc.l	0
savelock:	dc.l	0
lengte:	dc.l	0
filehandle:	dc.l	0
OutputHandle:	dc.l	0
FileName:	dc.l	0
	even
FileBuffel:	dc.b	40,0
	cnop	0,4
infoblock:	dcb.b	260,0
