	title	Module from library BASE_4 : DSKGET
	name	('DSKGET')
	maclib	baselib.lib

; Module reads a byte from disk input buffer and if
; buffer empty, fills it with a new record

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

;		Version 1.3 March 1990

; ENTRY	The three locations below must be set up prior
;	calling the module

;	Defaults : Standard DMA buffer
;		   Standard FCB
;		   Pointer set to 128

; EXIT	Accu holds byte if carry flag reset
;	On error or physical end of file carry will be set

	entry	dskget

; The following entries must be set up by the caller:

	entry	rdbuf		; 16 bit read buffer address
	entry	rdbfp		;  8 bit relative pointer
	entry	rdfcb		; 16 bit FCB address

	extrn	curdma,setdma,dskred

dskget:
	ld	a,(rdbfp)	; Get buffer count
	cp	reclng		; Test full
	jr	nz,get
;
; Read a record from disk
;
	push	de
	push	hl
	call	curdma		; Get old pointer
	push	hl
	ld	de,(rdbuf)	; Get new buffer
	call	setdma
	ld	de,(rdfcb)	; Get FCB address
	call	dskred		; Read record
	pop	de
	push	af
	call	setdma		; Reset buffer
	pop	af
	pop	hl
	pop	de
	ret	c
get:
	push	de
	push	hl
	ld	d,0
	ld	e,a		; Get pointer
	ld	hl,(rdbuf)	; Get buffer base
	add	hl,de		; Make real
	inc	a
	ld	(rdbfp),a	; Update pointer
	ld	a,(hl)		; Get character
	pop	hl
	pop	de
	or	a
	ret

	dseg

rdbuf:
	dw	dma		; Address of buffer
rdbfp:
	db	reclng		; Buffer pointer
rdfcb:
	dw	fcb		; FCB Address

	end

