[comp.sources.atari.st] v02i034: prtset -- Set printer parameters

koreth@ssyx.ucsc.edu (Steven Grimm) (03/30/89)

Submitted-by: ntomczak@ualtavm.bitnet (Michal Jaegermann)
Posting-number: Volume 2, Issue 34
Archive-name: prtset

[Ha!  After weeks of trying, we've beaten you, BITNET!  I finally got this
 intact and unmangled!  Hahahhahahahahahahahaha....  Oh, sorry. -sg]

This is a small utility, meant mostly for shell scripts, but also for
an interactive use, which main purpose is to send all kind of weird
initialization codes to a printer.  For example, when I am printing
.dvi files produced by TeX I am using the following two Gulam aliases,
which include some of MY printer magic, initialize system and printer
properly and restore printer to a sane (more or less) state after dvi
driver is finished.

dvi	prtset -s -h1b\8 ; dvc
dvc	pushd d:\texbin ; gem dvi.prg ; prtset -c -h1b401b\M1b\90d ; popd

I am using command 'dvi' to start my previewer, with printer off, or to
print on a single-sheet paper, and command 'dvc' to print on a
continous one.  The other role of a prtset program is to set and check
proper configuration codes in situation when keeping around in memory
fat control.acc is not exactly what you would really want to do.  When
printer is not on line 'prtset' just returns.  It is written in
assembler, since I wanted it to be really small.  I bet that you will
find also some other ways to use it.

   Enjoy,

   Michal Jaegermann
   Myrias Research Corporation
   Edmonton, Alberta, CANADA
   myrias!mj@alberta

#!/bin/sh
# shar:	Shell Archiver  (v1.22)
#
#	Run the following text with /bin/sh to create:
#	  PRTSET.DOC
#	  PRTSET.S
#
sed 's/^X//' << 'SHAR_EOF' > PRTSET.DOC &&
X
X
X
XPRTSET		          ST USER MANUAL		  PRTSET
X
X
XNAME
X     prtset - a program to set, change and display system printer
X     	      information and to send printer control codes
X
XSYNOPSIS
X     prtset [-c][-o][-s ][-n<infocode>][-h<printcode>]
X
XDESCRIPTION
X     Prtset is a small program for a control of printing by mody-
X     fying a system printer information and sending printer codes
X     to your printer.  It is meant mostly for situations in which
X     you have better uses for memory then keeping around a bulky
X     accesory.  It can be used interactively, but the best place
X     for it is probably in shell scripts and command aliases.
X     Contrary to what you may think some programs do care how the
X     printer information was set.
X
X     The program checks if an printing device is on line.  If it
X     is not, then an attempt to send something to the printer will
X     be silently skipped, and prtset will return, possibly 
X     performing other requested actions.
X
XOPTIONS
X     The following are valid command-line options:
X
X     -n<infocode> No space between flag and code allowed.
X             Set printer information accordingly to infocode.
X	     An infocode is a two-digit hex number with a bit
X	     pattern set with a help of the following table:
X	     
X	             bit	 reset		  set
X	             --------------------------------
X		     0	    dot-matrix    daisy-wheel
X		     1		   b/w	       colour
X		     2	   1240 dots/l	   960 dots/l
X		     3		 draft	        final
X		     4	      parallel	       serial
X		     5	    continuous   single-sheet
X		     6-15          reserved
X
X     -o      Show an old configuration.  An output is a string
X             of 0's and 1's corresponding to reset and set bits
X	     in a system printer information.
X
X     -c      Switch to printing on countinuous paper
X
X     -s      Switch to printing on single-sheet paper
X
X     -h<printcode>     Send to the printer a string of characters 
X             defined by printcode. Characters in printcode are
X	     represented either as their two-digit hexadecimal
X	     codes, in either case, or literally as themselves, if
X	     preceded by an escape charater '\'.  Any non-escaped
X	     character, which is not a hexadecimal digit, will ter-
X	     minate printcode.  Remaining non-white space characters
X	     will be skipped.
X	     
XEXAMPLE
X    Configure a printer to Epson in NLQ mode on RS-232 port printing
X    on a fan-fold paper and set right print margin to 65 characters
X    (your control sequence may vary, check your printer manual).
X    
X             prtset -n1c -h1b\Q410d
X	     
X    Display old printer configuration and switch to printing on 
X    a single sheet paper
X
X	     prtset -o -s
X	     
XAUTHOR
X     prtset was written by Michal Jaegermann, September 1988.
X
XBUGS
X     A command line is processed sequentially from left to right.
X     Therefore the following will work:
X     
X             prtset -o -n2a -o -n1c -o -n00 -o
X
X     displaying printer configuration four times.  The same applies
X     to all other options.  This may be construed as a bug, or as
X     a feature - depending on a state of your mind.
X
X     Due to a well-know brain damage in a desktop the following,
X     executed from a command window,
X     
X             prtset -h\t\e\s\t0d0a
X
X     will print 'TEST', instead of 'test'.  Use a shell which will
X     leave your command line alone, or replace escaped lower case
X     characters with corresponding hexadecimal codes.
SHAR_EOF
chmod 0600 PRTSET.DOC || echo "restore of PRTSET.DOC fails"
sed 's/^X//' << 'SHAR_EOF' > PRTSET.S &&
XFrom @CORNELLC.ccs.cornell.edu:NTOMCZAK@UALTAVM Wed Mar 29 00:34:11 1989
XReceived: from CORNELLC.ccs.cornell.edu ([128.253.1.19]) by ssyx.ucsc.edu (4.0/1.1)
X	id AA06846; Wed, 29 Mar 89 00:34:04 PST
XMessage-Id: <8903290834.AA06846@ssyx.ucsc.edu>
XReceived: from UALTAVM by CORNELLC.ccs.cornell.edu (IBM VM SMTP R1.2.1MX) with BSMTP id 0401; Wed, 29 Mar 89 03:33:47 EST
XReceived: by UALTAVM (Mailer X1.25) id 6719; Wed, 29 Mar 89 01:32:37 MST
XDate:         Wed, 29 Mar 89 01:30:02 MST
XFrom: Michal Jaegermann <NTOMCZAK%UALTAVM.BITNET@CORNELLC.CIT.CORNELL.EDU>
XSubject:      Re:  prtset
XTo: Steven Grimm <koreth@ssyx>
XIn-Reply-To:  Your message of Tue, 28 Mar 89 21:58:33 PST
XStatus: R
X
X     Line noise was actually quite bad. :-).  Ok, here is the rest
X-------------------------------------------------------------------------
XSteve,
X
X   I've already seen posted other parts of this mailing.  This file
Xhas to be the most persistently refusing to transfer which I ever
Xseen. Hope that this clear ASCII text will get to you in more or less
Xone piece.
X
X   Regards,
X   Michal
X
X------- cut here ----------------
X
X*****************************************************************
X*								*
X*    prtset.s   version 1.1 					*
X*    Michal Jaegermann, September 1988				*
X*								*
X*    this software is released to a public domain -		*
X*    enjoy every way you like					*
X*                                                               *
X*****************************************************************
X
X* character codes
Xtab      equ   9
Xlf       equ   10
Xcr       equ   13
X
X* gemdos & (x)bios equates
Xgemdos   equ   1
Xbios     equ   13
Xxbios    equ   14
X
Xconin    equ   1
Xconout	 equ   2
Xauxout	 equ   4
Xprnout   equ   5
Xpoutst	 equ   $11
Xaoutst   equ   $13
Xcconws   equ   9
Xpterm    equ   $4c
Xsetprt	 equ   33
X
X	.text
Xinit:
X*	move.w	#-1,d0		; find current printer configuration
X	bsr	oldcnf
X	move.w	d0,prcnfg
X	move.w	#prnout,prdev
X	btst	#4,d0
X	beq.s	getarg
X	move.w	#auxout,prdev
Xgetarg:
X	move.l	4(sp),a6
X	adda.w	#$80,a6		; a6 points to argument string start
X	moveq.l	#0,d0
X	move.b	(a6)+,d0	; Get string length and
X	clr.b	(a6,d0.w)	; ensure '\0' termination
X	sf	somearg
Xnxtarg:
Xskipwh:
X	bsr	getch
Xtestch:
X	tst.b	d0
X	beq	done		; '\0' char is end of string
X	cmp.b	#' ',d0
X	beq	skipwh
X	cmp.b	#tab,d0
X	beq	skipwh
X	cmp.b	#'-',d0
X	beq	skipwh
X*
X	st	somearg
Xopto:
X	cmp.b	#'O',d0
X	bne.s	optn
X	bsr	shwcnf
X	bra.s	nxtarg
Xoptn:
X	cmp.b	#'N',d0
X	bne.s	optc
X	bsr	newcnf
X	bra.s   nxtarg
Xoptc:
X	cmp.b	#'C',d0		; using continuous paper
X	bne.s	opts
X	move.w	prcnfg,d0
X	bclr	#5,d0
X	bsr	prconf
X	bra.s	nxtarg
Xopts:
X	cmp.b	#'S',d0		; using single-sheet
X	bne.s	opthx
X	move.w	prcnfg,d0
X	bset	#5,d0
X	bsr	prconf
X	bra.s	nxtarg
X
Xopthx:
X	cmp.b	#'H',d0		; hex escape
X	bne.s	usage
X	bsr	sendc		; return code quietly ignored
X	bra.s	testch
X*
Xdone:
X	tst.b	somearg
X	beq.s	usage
X	move.w	#0,-(sp)	; clear status
X	bra.s	term
Xusage:
X	pea.l	usemsg		; If error in arg string show usage message
X	move.w	#cconws,-(sp)
X	trap	#gemdos
X	addq.l	#6,sp
X	move.w  #conin,-(sp)	; wait for keypress to mollify desktop
X	trap	#gemdos
X*	addq.l	#2,sp		; conin code doubles as an error status
X*	move.w	#1,-(sp)	; error status
Xterm:
X	move.w	#pterm,-(sp)
X	trap	#gemdos		; and terminate
X
Xgetch:
X*				; return in d0 next character
X*				; converting lower case to upper
X*				; condition code set EQ if char is NULL
X	move.b	(a6)+,d0
X	cmp.b	#'a',d0
X	blt.s	gcrtn
X	cmp.b	#'z',d0
X	bgt.s	gcrtn
X	eori.b	#$20,d0		; convert to uppercase
Xgcrtn:
X	tst.b	d0		; set condition codes
X	rts
X
X*				; set new printer configuration
Xprconf:
X	move.w	d0,-(sp)
X	andi.w  #$3f,d0		; only these bits meanigful
X	move.w  prcnfg,d1	; do not change reserved bits
X	andi.w  #%0111111111000000,d1
X	or.w    d1,d0
X	move.w	#setprt,-(sp)
X	trap	#xbios
X	addq.l	#4,sp
Xoldcnf:
X	moveq	#-1,d0		; check printer configuration
X	move.w  d0,-(sp)
X	move.w	#setprt,-(sp)
X	trap	#xbios
X	addq.l	#4,sp
X	move.w	d0,prcnfg	; store result in prcnfg
X	move.w	#prnout,prdev	; assume printer on parallel port
X	btst	#4,d0		; it this true?
X	beq.s	pcfret
X	move.w	#auxout,prdev   : no? - change output to aux
Xpcfret:
X	rts
X
Xcvthx:
X*       converts ascii character in d0 into hex digit left in d0
X*       sets HI condition code iff character is not convertible
X
X	subi.b	#'0',d0
X	cmpi.b	#9,d0
X	ble.s	cvret
X	subq.b	#7,d0		; diff between '9' and 'A'
X	cmp.b	#$0f,d0
Xcvret
X	rts
X
Xsendc:
X*     sends to a printer hex codes which follow option -h
X*     trailing single digit codes ok
X*     characters escaped with \ represent their own ascii codes
X*     string is terminated by any not escaped non-hex character
X*     and its remaining part skipped until blank is reached
X*     -- sendc returns the folowing info in register d1
X*		-1 - codes send succesfully
X*		 0 - cannot send to output device
X*		 1 - output device is off-line
X*
X*     Warning: lower case escaped characters will not work from
X*     a desktop, due to a brain damaged upper case conversion by GEM.
X*
X*			; check if otput device is available
X	moveq	#1,d1
X	move.w	#poutst,-(sp)
X	cmpi.w  #prnout,prdev
X	beq.s	chkdv
X	addq.w  #2,(sp)  ; ask for status of rs232
Xchkdv:
X	trap	#gemdos
X	addq.l	#2,sp
X	tst.w	d0
X	beq.s   skips
Xsndnxt:
X	bsr	getch
X	beq.s	sret
X	moveq	#0,d1
X	cmp.b   #'\',d0
X	bne.s	cnvt1
X	move.b  (a6)+,d0
X	beq.s	sret
X	move.b	d0,d1
X	bra.s	print0
Xcnvt1:
X	bsr.s	cvthx
X	bhi.s	skips
X	move.b	d0,d1
X	bsr	getch
X	bne.s	nxtcv
X	bsr	printc
X	moveq	#0,d0
X	bra.s	sret
Xnxtcv:
X	bsr.s	cvthx
X	bhi.s	prnt1
X	lsl.b	#4,d1
X	add.b	d0,d1
Xprint0:
X	bsr	printc
X	beq.s	skips
X	bra.s	sndnxt
Xprnt1:
X	bsr	printc
Xskips:
X	bsr	getch
X	beq.s   sret
X	cmpi.b  #' ',d0
X	bne.s	skips
X	cmpi.b	#tab,d0
X	bne.s	skips
Xsret:
X	rts
X
Xprintc:
X	move.w  d1,-(sp)
X	move.w  prdev,-(sp)
X	trap	#gemdos
X	addq.l	#4,sp
X	move.w  d0,d1		; move result flag to d1
X	rts
X
Xshwcnf:
X	move.w	prcnfg,d2
X	lsl.w   #8,d2
X	lsl.w   #2,d2
X	moveq	#5,d3
X	move.w  #'0',d4
Xnxtbit:
X	move.w	d4,-(sp)
X	lsl.w	#1,d2
X	bcc.s	show
X	addq.w	#1,(sp)
Xshow:
X	move.w	#conout,-(sp)
X	trap	#gemdos
X	addq.l	#4,sp
X	dbra	d3,nxtbit
X	pea.l	retmsg
X	move.w	#cconws,-(sp)
X	trap	#gemdos
X	addq.l	#6,sp
X	rts
X
Xnewcnf:
X	bsr	getch
X	beq.s	unget
X	bsr	cvthx
X	bhi.s	nret
X	move.b	d0,d1
X	bsr	getch
X	beq.s	unget
X	bsr	cvthx
X	bhi.s	nret
X	lsl.b	#4,d1
X	add.b	d0,d1
X	
X	move.w  d1,d0
X	bclr	#15,d0
X	bsr	prconf
Xnret:
X	rts
Xunget:
X	subq.l #1,a6	; we will test terminator once again
X	rts
X	
X	.data
X
Xusemsg:	dc.b  'usage: prtset [-c|-s] [-o|-n<hex>] [-h<hex>]',cr,lf
X	dc.b  tab,'-c|-s',tab,'continuous | single-sheet',cr,lf
X	dc.b  tab,'-o|-n',tab,'old | new configuration',cr,lf
X	dc.b  tab,'-h<hex>',tab,'codes to send',cr,lf
X	dc.b  tab,tab,'where codes are hex or \escaped literals'
Xretmsg:	dc.b  cr,lf,0
Xsomearg:
X	dc.b  0
X
X	.even
X	.bss
Xrpcnfg: ds.w  1
Xprdev:  ds.w  1
X	end	
X
SHAR_EOF
chmod 0600 PRTSET.S || echo "restore of PRTSET.S fails"
exit 0