;printing an ASCII file
dseg	segment
recarea	  db   512 dup(' ')  ;input area for ASCII file
prtline   db   80 dup(' ')   ;print line
count	  dw   0
dseg ends
;---------------------------------------------------------
cseg	segment
	assume cs:cseg,ds:dseg,es:dseg
main	proc far
	push	ds
	sub	ax,ax
	push	ax
	mov	ax,dseg
	mov	ds,ax
	mov	es,ax
        call	prtasc
        ret
main	endp
;-------------------------------------------------------
;Transfer data to print line:
prtasc proc near
	cld		     	;set left to right
	lea	si,recarea   	;initialize
p10:	lea	di,prtline
	mov	count,0
p20:	lea	dx,recarea+512
	cmp	si,dx	     	;end of record
	je	p70	     	;yes,exit
p30:	mov	bx,count
	cmp	bx,80	     	;at end of print line?
	jb	p40	     	;no,bypass
	mov	word ptr[di+bx],0d0ah  ;set CR/LF
	add	count,2
	call	subprt	     	;print this line
	lea	di,prtline   	;reinitialize
	mov	count,0
	mov	bx,0
p40:	lodsb		  	;[si] to al,inc si
	mov	[di+bx],al   	;char to print line
	inc	bx
	cmp	al,1ah	     	;end of file
	je	p70
	cmp	al,0ah
	jne	p50
	call	subprt	     	;print a line
	jmp	p10
p50:	cmp	al,09	     	;Tab char ?
	je	p60
	dec	bx	     	;yes,reset BX
	mov	byte ptr [di+bx],20h
                             	;clear Tab to blank
	and	bx,0fff8h    	;clear rightmost 3 bits
	add	bx,08	     	; & add 8-->Tab stop
p60:	mov	count,bx
        jmp	p20
p70:	mov	bx,count     	;end of file
	mov	byte ptr [di+bx],0ch  ;form feed
	call	subprt	     	;print last line
	ret
prtasc	endp
;---------------------------------------------------------
subprt  proc    near
	mov	cx,count     	;length
	inc	cx
	mov	bx,0
next:	mov	ah,5	     ;request print
	mov	dl,prtline[bx]
	int	21h
	inc	bx
	loop	next
	mov	ax,2020h     ;clear print line
	mov	cx,41
	lea	di,prtline
	rep	stosw
	ret
subprt	endp
;--------------------------------------------------------
cseg	ends
	end	main


 