	title	Module from library BASE_5 : RDRECF
	name	('RDRECF')
	maclib	baselib.lib

; Read a record with variable length

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

;		Version 1.0 December 1989

; ENTRY	Reg pair DE points to parameter block
;	Byte 0   Record length (1 .. 255)
;	Byte 1,2 Max record number (1 .. 65535)
;	Byte 3,4 FCB of file
;	Byte 5,6 Pointer to 128 byte buffer
;	Byte 7,8 Pointer to record data

; EXIT	Carry set on error, either disk or parameter error
;	Carry reset on successfull operation

	entry	rdrecf

	extrn	$rndrg,$tsrec,$gtphs,$gtrec
	extrn	$mvrec,$fxnxt,$bufsw,$bufrs

rdrecf:
	call	$rndrg		; Get regs
	call	$tsrec		; Test valid record number
	ret	c		; Exit on parameter error
	call	$bufsw		; Swap buffer
	call	$gtphs		; Get 'physical' sector
rdlop:
	push	de
	call	$gtrec		; Get a random record
	jr	c,rderr		; Exit on error
	call	$mvrec		; Move record to buffer
	jr	z,endred	; Ok, that's it
	call	$fxnxt		; Else fix for another record
	pop	de
	jr	rdlop
endred:
	or	a		; Reset error
rderr:
	push	af
	call	$bufrs		; Reset buffer
	pop	af
	pop	de
	ret

	end

