TITLE HANCREAT.EXE -- Creat disk file of names
;--------------------------------------------------
stack segment para stack 'stack'
      dw   80 dup(?)
stack ends
;--------------------------------------------------
dseg segment para 'data'
namepar   label  byte	      ;name parameter list
maxlen	  db  30
namelen	  db  ?
namerec	  db  30  dup(' '),0dh,0ah   ;entered name
			        ;CR/LF for writing
errcde	  db  0
handle	  dw  ?
pathnam	  db  'A:\NAME.DAT',0
prompt	  db  'name ?'
row	  db  01
opnmsg	  db  '*** open error ***',0dh,0ah
wrtmsg	  db  '*** write error ***',0dh,0ah
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	creath		;create file,set DTA
	cmp	errcde,0	;create error ?
	jz	contin		;yes,continue
	ret			;no,return to DOS
contin:	call	proch
	cmp	namelen,0	;end of input
	jne	contin		;no,continue
	call	clseh		;yes,close
	ret			;return to DOS
begin endp
;	create disk file
;--------------------------------------------------
creath proc near
	mov	ah,3ch		;request create
	mov	cx,0		;normal attribute
	lea	dx,pathnam
	int	21h
	jc	a1		;error ?
	mov	handle,ax	;no,save handle
	ret
a1:	lea	dx,opnmsg	;error message
	call	errm
	ret
creath endp
;	accept input
;--------------------------------------------------
proch proc near
	mov	ah,40h		;request display
	mov	bx,01		;01=output device
	mov	cx,06		;length of prompt
	lea	dx,prompt	;display prompt
	int	21h

	mov	ah,0ah		;request input
	lea	dx,namepar	;accept name

	int	21h
	cmp	namelen,0	;is there a name ?
	jne	b1		;yes
	ret			;no,exit
b1:	mov	al,20h		;blank for storing
	sub	ch,ch
	mov	cl,namelen	;length
	lea	di,namerec
	add	di,cx		;address + length
	neg	cx		;calculate remaining
	add	cx,30		;  length
	rep	stosb		;set to blank
	call	writh		;write disk record
	call	scrl		;check for scroll
	ret
proch   endp
;	check for scroll
;--------------------------------------------------
scrl proc near
	cmp	row,18		;bottom of screen ?
	jae	c1		;yes,bypass
	inc	row		;no,add to row
c1:	mov	ax,0601h	;scroll one row
	call	scren
	call	curs		;reset cursor
	ret
scrl endp
;	write disk record
;--------------------------------------------------
writh proc near
	mov	ah,40h		;request write
	mov	bx,handle
	mov	cx,32		;for name and CR/LF
	lea	dx,namerec
	int	21h
	jnc	d1		;valid write ?
	lea	dx,wrtmsg	;no
	call	errm		;call error routine
	mov	namelen,0
d1:	ret
writh endp
;	close disk file
;--------------------------------------------------
clseh proc near
	mov	namerec,1ah	;set EOF mark
	call	writh
	mov	ah,3eh		;request close
	mov	bx,handle
	int	21h
	ret
clseh endp
;	scroll screen
;--------------------------------------------------
scren proc near			;AX set on entry
	mov	bh,1eh		;set yellow on blue
	mov	cx,0
	mov	dx,184fh
	int	10h		;scroll
	ret
scren endp
;	set cursor
;--------------------------------------------------
curs proc near
	mov	ah,02
	mov	bh,0
	mov	dh,row		;set cursor
	mov	dl,0
	int	10h
	ret
curs endp
;	disk error routine
;--------------------------------------------------
errm proc near			;DX contains address
	mov	ah,40h		;  of message
	mov	bx,01		;handle
	mov	cx,21		;length
	int	21h
	mov	errcde,01	;set error code
	ret
errm endp
;--------------------------------------------------
cseg ends
     end   begin


	