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
	AND	A
	SBC	HL,DE
	JR	NZ,CORRL6
	LD	HL,DIR
	LD	A,(HL)
	CP	" "
	JR	NZ,CORRL4
	LD	(HL),#E5
	LD	BC,#0020
	ADD	HL,BC
	LD	A,(HL)
	CP	" "
	JR	NZ,CORRL4
	LD	(HL),#E5
	JR	CORRL4
CORRL6	LD	HL,DIR
	LD	A,(HL)
	CP	" "
	JR	NZ,CORRL4
	LD	(HL),"."
	LD	BC,#0020
	ADD	HL,BC
	LD	A,(HL)
	CP	" "
	JR	NZ,CORRL4
	LD	(HL),"."
	INC	HL
	LD	(HL),"."
CORRL4	POP	AF
	OUT	(PAGE3),A
	AND	A
	RET 

ENTRYBF
	DEFB	#00	;Entry lenght
	DEFB	#00	;XAR in	LBN
FCDSEC	DEFW	#00,#00	;Start sector (Intel)
	DEFW	#00,#00	;Start sector (Motorola)
FCDLEN	DEFW	#00,#00	;Lenght	file (Intel)
	DEFW	#00,#00	;Lenght	file (Motorola)
FCDYEAR	DEFB	#00	;Year
FCDMOUN	DEFB	#00	;Mount
FCDDAY	DEFB	#00	;Day
FCDHOUR	DEFB	#00	;Hour
FCDMIN	DEFB	#00	;Minute
FCDSECN	DEFB	#00	;Second
	DEFB	#00	;Reserve
FCDFLAG	DEFB	#00	;Flag
	DEFB	#00	;Interlive size
	DEFB	#00	;Interlive skip	factor
	DEFW	#0000	;Volume	Set Sequence (Intel)
	DEFW	#0000	;Volume	Set Sequence (Motorola)
FCDFLEN	DEFB	#00
DEFSA	EQU	$-ENTRYBF
FCDNAME	DEFS	#100-DEFSA

ROOTDIR	DEFW	0,0
ROOTLEN	DEFW	0,0


