	title	Module from library HILIB_2 : @FIND
	name	('@FIND')
	maclib	baselib.lib

; Language : BASIC

; Search file

; Copyright (C)	Werner Cirsovius
;		Hohe Weide 44
;		D-20253 Hamburg
;		Tel.: +49-40-4223247

;		Version 1.0, August 1987

; ENTRY	Reg pair HL points to string describing file
;	Reg pair DE points to resulting string
;	Reg B holds value indicating the number of search
;	calls to be performed

; EXIT	Resulting string empty if carry set, Accu holds 0
;	on no error else 64 (file name invalid)
;	Resulting string filled with exactly 12 bytes on
;	carry reset (8 bytes name, 3 bytes extension and dot)

; NOTE	The default FCB at 005ch will be overwritten

	entry	@find

	extrn	@assig,srcfrs,srcnxt

@find:
	xor	a
	ld	(de),a
	push	de
	ld	de,fcb
	call	@assig		; Assign file
	pop	de
	ld	a,64
	ret	c		; Error
	push	de
	ld	de,fcb
	call	srcfrs		; Try to find file
	pop	de
	ld	a,0
	ret	c		; Not found, return 0
	or	b		; Test number
	jr	z,assign
search:
	dec	b
	jr	z,assign	; Test done
	call	srcnxt		; Search new one
	ld	a,0
	jr	nc,search
	ret			; End if not found
assign:
	ld	bc,.nam
	ldir			; Get name
	ld	a,'.'
	ld	(de),a		; Set delimiter
	inc	de
	ld	bc,.ext
	ldir			; .. and extension
	xor	a
	ld	(de),a		; Close result
	ret

	end

