bell	equ	7
cr	equ	13
lf	equ	10
tab	equ	9
LINES	equ	48
eol	equ	'$'
esc	equ	27
;
;---------------
;
LPRINT	MACRO	L1,L2,L3,L4,L5,L6	;LPRINT A CHARACTER MACRO

IFNB	<L1>			;SET AL TO THE OPTIONAL PARAMETER
	MOV	AL,L1
	ENDIF
	CALL	LPRINT1		;PRINT THE CHAR

IFNB	<L2>
	LPRINT	L2,L3,L4,L5,L6
	ENDIF

      	ENDM
;
;---------------
;
FORM_FEED	macro
	lprint	12
	endm
;
;---------------
;
SW_LF	macro
	lprint	esc,'J',24,cr
	endm
;
;---------------
;
SW_SET_BIT	macro
	lprint	esc,'K',cl,ch
	endm	      
;
;---------------
;
CSEG    SEGMENT	byte public 'CODE'
	ASSUME	CS:CSEG,DS:CSEG,ES:CSEG


	ORG	81H
fname	label	byte
	ORG	100H
START	PROC	NEAR
	jmp	start1

	DB	CR,'Public Domain SideWays (pd)1985 by Donavon Kuhn ',cr,lf,1AH
;
handle		dw	0
char_flag	db	0
end_of_file	db	0
column		dw	0
row		db	0
;
start1:
	lea	dx,inst
	mov	ah,9
	int	21h

	xor	bh,bh
	mov	bl,ds:[80h]		;get length of input filename
	lea	di,fname
	mov	byte ptr [di][bx],0	;make into an ASCIIZ string

;	open	i,1,fname
	lea	di,fname-1		;strip leading spaces
splp:
	inc	di
	cmp	byte ptr [di],' '
	jz	splp

	cmp	byte ptr [di],0
	jz	usage
	cmp	byte ptr [di],'?'
	jnz	no_usage

usage:
	lea	dx,usagestr
	jmp	error1

no_usage:
	mov	dx,di
	mov	ah,3dh
	mov	al,0
	int	21h
	mov	handle,ax
	jnc	no_open_err1
	jmp	error

no_open_err1:
	lea	dx,pausestr
	mov	ah,9
	int	21h

no_open_err:

	lea	di,line_ptr		;fill text buffer with spaces
	mov	al,0
	cld
	mov	cx,LINES*1024+LINES*2
	rep	stosb

	mov	row,0
	lea	di,text_buffer
	mov	bx,0

lflp:
	inc	row
	cmp	row,LINES+1		;reached max lines/page yet?
	jb	not_yet
	jmp	read_donono
not_yet:
	mov	line_ptr[bx],di		;pointer to the beginning of the line
	add	bx,2			;don't wreck BX!
	mov	column,0

charlp:
	push	bx
	mov	bx,handle
	mov	ah,3fh			;read char from file
	mov	cx,1
	lea	dx,inbuff
	int	21h
	pop	bx
	cmp	ax,1
	jz	read_ok
donejmp:
	mov	end_of_file,1
	jmp	read_done

read_ok:
	mov	al,byte ptr inbuff	;char in AL

	cmp	al,'Z'-64		;if CTRL-Z
	jz	donejmp	

	cmp	al,lf			;if a new line
	jz	lflp

	cmp	al,cr
	jnz	nocr
	mov	al,0
      	jmp	place
nocr:
	cmp	al,TAB
	jnz	notab
	mov	al,' '
tablp:	
	mov	[di],al
	inc	di
	inc	column
	call	colwidth
	test	column,7
	jnz	tablp	
	jmp	charlp

notab:
	cmp	al,'L'-64
	jz	read_done

	cmp	al,32
	jb	spacectrl

place: 
 	mov	[di],al
	inc	di
	inc	column
	call	cole
	th
spacectrl:
	jmp	charlp


cole
	th:
	cmp	column,1024
	jb	e
	thok
	lea	dx,tooe
	RLjmp	error1
e
	thok:
	ret



read_done:
	mov	ah,1
	int	16h
	jz	read_dd_dd1

	mov	ah,0
	int	16h
	cmp	al,27
	jne	read_d 1

	jmp	all_d_d_

read_done1:
	mov	cx,LINES*10
	SW_SET_BIT

	mov	cx,LINES
	lea	si,line_ptr+(LINES*2)-2
	mov	char_flag,0
prlp:
	mov	al,' '
	mov	di,[si]
	cmp	di,0
	jz	printit
	mov	al,[di]
	cmp	al,0
	jnz	notzero
	mov	word ptr [si],0
	mov	al,' '
	jmp	printit

notzero:
	incinciord ptr [si]
	mov	char_flag,1

printit:
	sub	al,32
	mov	ah,8
	mul	ah
	lea	di,swbit
	add	di,ax

	push	cx
	mov	cx,8
cxlp:
	mov	al,[di]
	inc	di
	lprint
	loop	cxlp
	pop	cx

	lprint	0,0

	sub	si,2
	loop	prlp

	SW_LF

	cmp	char_flag,0
	jz	next_page
	jmp	p	pne

next_page:

	FORM_FEED

	cmp	end_of_file,0
	jnz	all_done
	jmp	no_open_err

all_dall_da:
	mov	ax,4c00h
	int	21h

;
;-----------------
;
LPRINT1	PROC	NEAR		;LPRINT CHAR IN AL
	push	ax
	push	dx
	XOR	DX,DX
	XOR	AH,AH
	int	17h
	pop	dx
	pop	ax
	ret
LPRINT1 ENDP
;
;-----------------
;
inbuff	db	0

inst	DB	'Public Domain SideWays (pd)1985 by Donavon Kuhn '
	db	cr,lf,cr,lf,eol

too
	jne	db	'Line width cannot   cede 1024 characters.',bell,cr,lf,eol
errmsg	db	'File not Found or Open Error.',bell,cr,lf,eol
pausestr	db	'Press ESC to Cancel',eol


error:
	lea	dx,errmsg
error1:
	mov	ah,9
	int	21h
	mov	ax,4c01h			;error with errorlevel 1
	int	21h
;
;
swbit:
	DB	0,0,0,0,0,0,0,0
	DB	0,16,0,16,16,56,56,16
	DB	0,0,0,0,0,36,36,36
	DB	0,36,36,126,36,126,36,36
	DB	0,24,124,2,60,64,62,24
	DB	0,70,38,16,8,100,98,0
	DB	0,118,136,136,86,48,72,48
	DB	0,0,0,0,0,32,16,16
	DB	0,16,,16,,64,64,64,4,416
	DB	0, 16,8,8,88,882
	DB	0,0,68,56,254,56,68,0
	DB	0,0,16,16,124,16,16,0
	DB	 16,16,0,0,0,0,0
	DB	0,0,0,0,126,0,0,0
	DB	0,16,16,0,0,0,0,0
	DB	0,64, 16,8,4,2,0
	DB	0,60,98,82,74,70,66,60
	DB	0,124,16,16,16,80,48,16
	DB	0,126,66,48,12,2,66,60
	DB	0,60,66,2,28,2,6e
	R0
	DB	0,28,8,254,72,40,24,8
	DB	0,60,66,2,2,124,64,126
	DB	0,60,66,66,124,24,22,28
	DB	0,16,16,16,8,4,66,126
	DB	0,60,66,66,60,66,6e
	R0
	DB	0,56,4,2,62
ee
	R0
	DB	0,16,16,0,0,16,16,0
	DB	 16,16,0,0,16,16,0
	DB	0,8,16,32,62,622,16,8
	DB	0,0,10,100,0,1 0,0
	DB	0,16,8,4,2,4,8,16
	DB	0,8,0,8,4,2,66,60
	DB	0,60,64,94,82,94
e0
	DB	0,6e
	R6,12e
	R6,66,36,24
	DB	0,12,12, ,,60,3 ,124
	DB	0,28,34,64,64,6 ,28
	DB	0,120,36,3 ,34,36,120
	DB	0,126,0,1040,56,40,34,126
	DB	0,112,2,240,56,40,34,126
	DB	0,30,34,78,64,6464,646,28
	DB	0,6e
	R6,66,126,126,1,66
	DB	0,56,16,16,16,16,16,56
	DB	0,56,68,68,4,4,4,14
	DB	0,99,36,40,48,40,36,98
	DB	0,12
	DB	0,12,32,32,,32,, 112
	DB	0,65,65,6all_da,73,85,99
	DB	0, ,66,70,74,82,98 , ,e
	R6,6e
	R6,36,24
	DB	0,1125,6a2,60,34,0,10124
	DB	0,3,60,74747
e0
	DB	0,114,12,40,60 ,0,10124
	DB	0,60,66,2,602,602
e0
	DB	0,28,8,,8,,8,73,127
	62
0,66,60,66,60 0
	DB	0,8,20 ,34,,6,6,34,
	DB	0,54,73,3,3,73,73, ,34,
	DB	0,34,,0,100,1008,20,34,34,
	DB	0,28, 8,2,2,5
	DB	0,127,33,13,13,4,66,127
	DB	0,120,64,64,34,,064,120 ,,4,8,16,32,64,128
	DB	0,120, 8, 8, 
	DB	0,0,0,0,130,68,40,16
	DB	255,0,0,0,0,0,0,0
	DB	0,0,0,0,0,0,0,0,016
	62
3,6e
	R2,2,60,0,0
	DB	0,46,49,49,46,32,32,96
	62
3
e4,6e
	R0,0,0
	DB	0,59,70,70,58,2,2,6
	DB	0,60,64,12e
	R6,60,0,0
	DB	0,56,16,16,16,16,16,18,12
	DB	124,2,62,62
e1,0,0
	DB	0,98 ,34,50,4 2,9,9,B	0, 6,16,16,48,48,4
	DB	60,66,66,2,2,6,0,2
	DB	0,38,40,48,40,36,32,9 	0,4916,16,16,16,48
	DB	0, , ,3,133,118,0,0,0,0, , 92,2,2 20,0,0,0,0,6e
	R0,e
	R0,eB	112,32,44,50,50,108,0,0
	DB	14,4,52,76,76,54, B	0,13,8 54,50,108,0,,624,24,264,664,66,0
	DB	0,12,1,1,6,124,16,16
	DB	0,58,78,78,66,,66,, ,  ,2,6,2,6,,54,73,73, ,34,, ,68,40,16,40,40,4 40,,6,6,0,0,0,0,0, 0,124, 16,8 16,8 	DB	0,3,816,16,96,16,16,12
	DB	0,16,16,16,0,16,16,116,16,110,4 8,,32,9,8,48
	DB	8
	DB	8,0, ,50
	DB	0,127
	DB	0,1275, ,0 ,00
;
;

line_ptr	label 0ord
usagestr:
	db	cr,lf
	db	'Usage:  PDSW filespec',cr,lf,cr,lf
	db	'Where: : :espec is the name of a file to be printed',cr,lf
	db	'        sideways to an Epson printer 20LPT1:
	DB	f,eol

text_buffer	equ line_ptr+LINES*2

;
;
START	ENDcole
CSEG	ENDS
	END	D	DRT

