TITLE HANREAD.EXE 
;--Read disk records created by hancreat
;--------------------------------------------------
stack segment para stack 'stack'
      dw   80 dup(?)
stack ends
;--------------------------------------------------
dseg segment para 'data'
endcde	 db  0
handle	 dw  ?
ioarea	 db  32 dup(' ')
pathnam	 db  'A:\NAME.DAT',0
openmsg	 db  '*** open error ***',0dh,0ah
readmsg	 db  '*** read error ***',0dh,0ah
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	ax,0600h
	call	scren		;clear screen
	call	curs		;set cursor
	call	openh		;open file,set DTA
	cmp	endcde,0	;valid open ?
	jnz	a1		;no,terminate
contin:	call	readh		;read disk record
	cmp	endcde,0	;normal read ?
	jnz	a1
	call	disph		;yes,display name
	jmp	contin		;continue
a1:	ret			;terminate
begin endp
;	open file
;--------------------------------------------------
openh proc near
	mov	ah,3dh		;request open
	mov	cx,0
	lea	dx,pathnam
	int	21h
	jc	b1		;error ?
	mov	handle,ax	;no,save handle
	ret
b1:	mov	endcde,01	;yes
	lea	dx,openmsg	;error message
	call	errm
	ret
openh endp
;	read disk record
;--------------------------------------------------
readh proc near
	mov	ah,3fh		;request read
	mov	bx,handle
	mov	cx,32		;for name and CR/LF
	lea	dx,ioarea
	int	21h
	jc	c1		;error on read ?
	cmp	ax,0		;end of file ?
	je	c2
	cmp	ioarea,1ah	;EOF marker ?
	je	c2
	ret
c1:	lea	dx,readmsg	;no,invalid read
	call	errm
c2:	mov	endcde,01	;force end
	ret
readh endp
;	display name
;--------------------------------------------------
disph proc near
	mov	ah,40h		;request display
	mov	bx,01		;set handle
	mov	cx,32		;end length
	lea	dx,ioarea
	int	21h
	cmp	row,20		;bottom of screen ?
	jae	d1		;yes,bypass
	inc	row
	ret
d1:	mov	ax,0601h
	call	scren		;scroll
	call	curs		;set cursor
	ret
disph endp
;	scroll screen
;--------------------------------------------------
scren proc near			;AX set on entry
	mov	bh,1eh		;set color
	mov	cx,0
	mov	dx,184fh	;request scroll
	int	10h
	ret
scren endp
;	set cursor
;--------------------------------------------------
curs proc near
	mov	ah,2		;request set cursor
	mov	bh,0
	mov	dh,row		;row
	mov	dl,0		;column
	int	10h
	ret
curs endp
;	disk error routine
;--------------------------------------------------
errm proc near
	mov	ah,40h		;DX contains address
	mov	bx,01		;handle
	mov	cx,20		;length of message
	int	21h
	ret
errm endp
;--------------------------------------------------
cseg ends
     end   begin
