	page	95,132
;
;                                                                          
;            }`J@RpNg@vg@[eBeB            
;                                                                          
;   Multicolumn Compact PRint utility   lboqDdwd  uP.SO    
;   ~           ~       ~~                                                 
;              Copyright (C) by n MY 1989-1990. All rights reserved.  
;
	public	namebuf
	public	namebufoff
	public	namebufseg
	public	nameptr
	public	nameptroff
	public	nameptrseg
	public	filebuf
	public	filebufoff
	public	filebufseg
	public	bitimg
	public	bitimgoff
	public	bitimgseg
	public	prtbuf
	public	prtbufoff
	public	prtbufseg
	public	pgbuf
	public	pgbufoff
	public	pgbufseg
	public	pgbufsiz
	public	allocnambuf
	public	freenambuf
	public	allocprtbuf
	public	freeprtbuf
	extrn	linsiz:word
	extrn	lincnt:word
	extrn	hdrprint:word
	extrn	hdrlinseg:word
	extrn	hdrln2seg:word
	extrn	pgwidth:word
	extrn	pghight:word
	extrn	clmpitch:word
	extrn	errorno:word
	extrn	abort:near
;
YES	equ	1
;
data	segment para	public	'DATA'
;
namebuf label	dword
namebufoff  dw	0
namebufseg  dw	0
;
nameptr label	dword
nameptroff  dw	0
nameptrseg  dw	0
;
filebuf label	dword
filebufoff  dw	0
filebufseg  dw	0
;
bitimg	label	dword
bitimgoff   dw	0
bitimgseg   dw	0
;
prtbuf	label	dword
prtbufoff   dw	0
prtbufseg   dw	0
;
pgbuf	label	dword
pgbufoff    dw	0
pgbufseg    dw	0
;
pgbufsiz    dw	?
;
allocmsg	db	'memory allocation error',0dh,0ah
alcmsgsiz   equ     $-allocmsg
;
data	ends
;
code	segment para	public	'CODE'
	assume	cs:code,ds:data
;
allocnambuf proc
;
	mov	bx,4096/16 	    ;file name build buffer size
	call	dosalloc
	mov	namebufseg,ax
;
	mov	bx,1024/16	    ;file name list pointer buffer size
	call	dosalloc
	mov	nameptrseg,ax
	ret
;
allocnambuf endp
;
freenambuf  proc
;
	mov	ah,49h
	mov	es,namebufseg
	int	21h
;
	mov	ah,49h
	mov	es,nameptrseg
	int	21h
	ret
;
freenambuf  endp
;
allocprtbuf    proc
;
	mov	bx,8192/16	    ;file read buffer size
	call	dosalloc
	mov	filebufseg,ax
;
	cmp	clmpitch,3
	jne	nobitaloc
;
	mov	ax,32		    ;buffer size for 1 column
	mul	linsiz
	and	dx,0fh
	or	ax,dx
	mov	cl,4
	ror	ax,cl
	mov	bx,ax
	call	dosalloc	    ;bit image buffer
	mov	bitimgseg,ax
;
	call	dosalloc	    ;print data buffer
	mov	prtbufseg,ax
;
nobitaloc:
	mov	ax,linsiz	      ;calculate page buffer size
	mul	lincnt
	mov	bx,ax
	shr	ax,1
	mov	pgbufsiz,ax
	cmp	hdrprint,YES
	jne	nohdrsiz
	add	bx,linsiz
	add	bx,linsiz
nohdrsiz:
	mov	cl,4
	shr	bx,cl
	call	dosalloc
	mov	pgbufseg,ax
;
	cmp	hdrprint,YES
	jne	nohdrstr
	mov	dx,pgbufsiz
	mov	cl,3
	shr	dx,cl
	add	ax,dx
	mov	dx,ax
	mov	hdrlinseg,ax
	mov	bx,linsiz
	mov	cl,4
	shr	bx,cl
	add	ax,bx
	mov	hdrln2seg,ax
	xor	ax,ax
	mov	di,ax
	mov	cx,linsiz
	mov	es,dx
	cld
    rep stosw
nohdrstr:
	ret
;
allocprtbuf endp
;
freeprtbuf  proc
;
	mov	ah,49h
	mov	es,filebufseg
	int	21h
;
	cmp	clmpitch,3
	jne	nobitfree
;
	mov	ah,49h
	mov	es,bitimgseg
	int	21h
;
	mov	ah,49h
	mov	es,prtbufseg
	int	21h
;
nobitfree:
	mov	ah,49h
	mov	es,pgbufseg
	int	21h
;
	ret
;
freeprtbuf  endp
;
dosalloc    proc
;
	mov	ah,48h
	int	21h
	jc	allocerr
	ret
allocerr:
	mov	errorno,ax
	mov	dx,offset allocmsg
	mov	cx,alcmsgsiz
	jmp	abort
;
dosalloc    endp
;
code	ends
	end
