
TITLE FCBREAD.EXE -- Read records created by fcbwrite
stack segment para stack 'stack'
      dw  80 dup(?)
stack ends
;-----------------------------------------------------
dseg segment para 'data'
fcbrec label byte	      ;FCB for disk file
fcbdriv	 db  0		      ;drive C
fcbname	 db  'namefile'	      ;file name
fcbext	 db  'dat'	      ;extension
fcbblk	 dw  0		      ;current block #
fcbrcsz	 dw  0		      ;record size
	 dd  ?		      ;DOS file size
	 dw  ?		      ;DOS date
	 dt  ?		      ;DOS reserved
fcbsqrc	 db  0		      ;current record #
	 dd  ?		      ;relative record #

reclen	equ  32
namefld	 db  reclen dup(' '),13,10,'$'
endcde	 db  0
openmsg	 db  '*** open error ***','$'
readmsg	 db  '*** read error ***','$'
row	 db  0
dseg ends
;-------------------------------------------------
cseg segment para 'code'
begin proc far
	assume cs:cseg, ds:dseg, ss:stack, es:dseg
	push	ds
	sub	ax,ax
	push	ax
	mov	ax,dseg
	mov	ds,ax
	mov	es,ax
	mov	ah,06
	mov	al,00
	call	scro		;clear screen
	call	curs		;set cursor
	call	openf		;open file,set DTA
	cmp	endcde,00	;valid open?
	jnz	exit		;no,terminate
loop1:	call	readf		;read disk record
	cmp	endcde,00	;normal read?
	jnz	exit		;no,exit
	call	disp		;display name
	jmp	loop1		;continue
exit:	ret			;terminate
begin endp
;	open disk file :
;----------------------------------------------------
openf proc near
	lea	dx,fcbrec
	mov	ah,0fh		;request open
	int	21h
	cmp	al,00		;file found ?
	jnz	error		;no,error
	mov	fcbrcsz,reclen	;set record length
	mov	ah,1ah
	lea	dx,namefld	;set address of DTA
	int	21h
	ret
error:	mov	endcde,01	;error message
	lea	dx,openmsg
	call	errm
	ret
openf endp
;	read disk record :
;---------------------------------------------------
readf proc near
	mov	ah,14h		;request read
	lea	dx,fcbrec
	int	21h
	cmp	namefld,1ah	;EOF marker
	jne	tests		;no
	mov	endcde,01	;yes
	jmp	rend
tests:	cmp	al,0		;normal read ?
	jz	rend		;yes,exit
	mov	endcde,1	;no
	cmp	al,1		;end of file ?
	jz	rend		;yes, exit
	lea	dx,readmsg	;no,must be
	call	errm		;  invalid read
rend:	ret
readf endp
;	display record :
;------------------------------------------------
disp proc near
	mov	ah,09		;request display
	lea	dx,namefld
	int	21h
	cmp	row,20		;bottom of screen?
	jae	bottom		;yes
	inc	row		;no,inc row
	jmp	dend
bottom:	mov	ah,06
	mov	al,01
	call	scro		;scroll
	call	curs		;set cursor
dend:	ret
disp endp
;	scroll screen :
;--------------------------------------------------
scro proc near			;AX set on entry
	mov	bh,1eh		;set color
	mov	cx,0
	mov	dx,184fh	;request scroll
	int	10h
	ret
scro endp
;	set cursor :
;--------------------------------------------------
curs proc near
	mov	ah,02
	mov	bh,0
	mov	dh,row
	mov	dl,0
	int	10h
	ret
curs endp
;	disk error routine :
;--------------------------------------------------
errm proc near
	mov	ah,09		;DX contains addr
	int	21h		;  of message
	ret
errm endp
;--------------------------------------------------
cseg ends
     end begin
