(FILECREATED "28-Aug-85 14:44:02" {ERIS}<SCHOEN>RS232>FXPRINTER.;5 26753  

      changes to:  (VARS FXPRINTERCOMS)
		   (FNS RS232.PRINT FX.PRESSBITMAP WINDOWDISPLAY COMBMDISPLAY \PRINTER.CRLF 
			GRAPHICS.MODE FBITMAP FXFITERROR BITMAPDISPLAY COMGRAPH.MODE FXPRINT 
			\PRINTER.COMMAND \PRINTER.HEADING BOLD.MODE COMMENT.MODE EXPANDED.MODE 
			STANDARD.MODE \PRINTER.INIT \PRINTER.PRINT.HEADING \PRINTER.TEXTINIT 
			RS232.PRINTFILE SELECT.MODE \PRINTER.MODE)

      previous date: "19-Nov-84 13:32:12" {ERIS}<LISP>INTERMEZZO>LIBRARY>FXPRINTER.;1)


(* Copyright (c) 1984, 1985 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT FXPRINTERCOMS)

(RPAQQ FXPRINTERCOMS ((ADDVARS (PRINTERTYPES ((FX.80 LOCALPRINTER)
					      (CANPRINT (TEXT BITMAP WINDOW))
					      (STATUS TRUE)
					      (PROPERTIES NILL)
					      (SEND FXPRINT)
					      (BITMAPSCALE NIL)
					      (BITMAPFILE (FX.PRESSBITMAP FILE BITMAP SCALEFACTOR 
									  REGION ROTATION TITLE))))
			       (PRINTFILETYPES (TEXT (TEST TEXTFILEP)
						     (EXTENSION (TEXT)))))
		      (P (PUTPROP 'FX.80 'PRINTERTYPE 'LOCALPRINTER))
		      (FNS * PRINTERFNS)
		      (INITVARS (DEFAULTPRINTERDEVICE (QUOTE TTY))
				(DEFAULTLOCALBAUDRATE NIL)
				(SUPPRESS.PAPER.ADJ.FLAG NIL))
		      (GLOBALVARS SUPPRESS.PAPER.ADJ.FLAG DEFAULTLOCALBAUDRATE DEFAULTPRINTERDEVICE)))

(ADDTOVAR PRINTERTYPES ((FX.80 LOCALPRINTER)
			(CANPRINT (TEXT BITMAP WINDOW))
			(STATUS TRUE)
			(PROPERTIES NILL)
			(SEND FXPRINT)
			(BITMAPSCALE NIL)
			(BITMAPFILE (FX.PRESSBITMAP FILE BITMAP SCALEFACTOR REGION ROTATION TITLE))))

(ADDTOVAR PRINTFILETYPES (TEXT (TEST TEXTFILEP)
			       (EXTENSION (TEXT))))
(PUTPROP 'FX.80 'PRINTERTYPE 'LOCALPRINTER)

(RPAQQ PRINTERFNS (RS232.PRINT RS232.PRINTFILE FBITMAP FX.PRESSBITMAP FXFITERROR FXPRINT 
			       BITMAPDISPLAY TEXTFILEP WINDOWDISPLAY WINDOW.TO.BITMAP BOLD.MODE 
			       COMBMDISPLAY COMGRAPH.MODE COMMENT.MODE EXPANDED.MODE GRAPHICS.MODE 
			       SELECT.MODE STANDARD.MODE \PRINTER.COMMAND \PRINTER.CRLF 
			       \PRINTER.HEADING \PRINTER.INIT \PRINTER.MODE \PRINTER.PRINT.HEADING 
			       \PRINTER.TEXTINIT))
(DEFINEQ

(RS232.PRINT
  (LAMBDA (FILENAME NOROTATE? STANDARD.SETUP COMPRESS? PRINTERDEVICE)
                                                             (* ejs: "28-Aug-85 14:41")
    (LET ((PRINTERSTREAM (OPENSTREAM (PACK* (QUOTE {)
					    (OR PRINTERDEVICE DEFAULTPRINTERDEVICE)
					    (QUOTE }))
				     (QUOTE OUTPUT))))
         (COND
	   ((BITMAPP FILENAME)
	     (FBITMAP FILENAME NOROTATE? COMPRESS? NIL PRINTERSTREAM))
	   ((WINDOWP FILENAME)
	     (WINDOWDISPLAY FILENAME NOROTATE? COMPRESS? NIL PRINTERSTREAM))
	   (T (RS232.PRINTFILE FILENAME PRINTERSTREAM)))
         (COND
	   ((fetch (FDEV BUFFERED) of (fetch (STREAM DEVICE) of PRINTERSTREAM))
	     (FORCEOUTPUT PRINTERSTREAM)))
     PRINTERSTREAM)))

(RS232.PRINTFILE
  (LAMBDA (FILENAME PRINTERSTREAM)                           (* ejs: "28-Aug-85 11:01")

          (* This function takes a file, opens it for stream input (in the function \PRINTER.FILEINIT), and prints that file 
	  on an Epson FX-80 Printer. A later version of this function will allow user interaction such that, if the user owns 
	  a printer other than the Epson, he/she will be able to specify the command characters that allow certain font and 
	  mode changes on her/his particular printer. NOTE: check the documentation for this program for the correct pin 
	  connections for you particular machine.)


    (PROG (FILE)
          (\PRINTER.TEXTINIT PRINTERSTREAM)                  (* This function initializes print modes and form feeds
							     on the Epson printer.)
          (\PRINTER.PRINT.HEADING FILENAME PRINTERSTREAM)    (* The function \PRINTER.PRINT.HEADING sets up the mode
							     for printing the heading, and calls the function that 
							     actually does the printing.)
          (CLOSEF? FILENAME)
          (SETQ FILE (OPENSTREAM FILENAME (QUOTE INPUT)
				 (QUOTE OLD)))
          (until (EOFP FILE) bind CHAR
	     do (SETQ CHAR (BIN FILE))
		(SELECT.MODE CHAR PRINTERSTREAM))
          (CLOSEF FILE))))

(FBITMAP
  (LAMBDA (BMAP NOROTATE? COMPRESS? NOERRORCHECK PRINTERSTREAM)
                                                             (* ejs: "28-Aug-85 12:33")

          (* This function takes a bit map, and, if the user doesn't make an explicit request (using a non-nil NOROTATE? 
	  argument), prints the image out rotated -90 degrees using the fast \GETBASEBYTE function.)


    (COND
      ((NULL COMPRESS?)
	(PROG ((HEIGHT (fetch BITMAPHEIGHT of BMAP))
	       (BASE (fetch BITMAPBASE of BMAP))
	       (BYTESPERROW (ITIMES 2 (fetch BITMAPRASTERWIDTH of BMAP)))
	       COLUMN J CNT OFFSET)
	      (COND
		(NOROTATE? (COND
			     ((AND (NULL NOERRORCHECK)
				   (GREATERP (FETCH BITMAPWIDTH OF BMAP)
					     576))
			       (FXFITERROR BMAP NOROTATE? COMPRESS? HEIGHT (FETCH BITMAPWIDTH
									      OF BMAP)
					   PRINTERSTREAM))
			     (T (BITMAPDISPLAY BMAP PRINTERSTREAM))))
		(T (COND
		     ((OR (LEQ HEIGHT 576)
			  NOERRORCHECK)
		       (\PRINTER.MODE (QUOTE UniDirectionalOn)
				      PRINTERSTREAM)
		       (\PRINTER.MODE (QUOTE EightSpacingOn)
				      PRINTERSTREAM)
		       (SETQ OFFSET BYTESPERROW)
		       (for COLUMN from 1 to BYTESPERROW
			  do (GRAPHICS.MODE HEIGHT PRINTERSTREAM)
			     (for J from HEIGHT to 1 by -1
				do (BOUT PRINTERSTREAM (\GETBASEBYTE BASE (IDIFFERENCE (ITIMES 
										      BYTESPERROW J)
										       OFFSET))))
			     (\PRINTER.CRLF PRINTERSTREAM)
			     (SETQ OFFSET (SUB1 OFFSET)))
		       (\PRINTER.MODE (QUOTE UniDirectionalOff)
				      PRINTERSTREAM))
		     (T (FXFITERROR BMAP NOROTATE? COMPRESS? HEIGHT (fetch BITMAPWIDTH of BMAP)
				    PRINTERSTREAM)))))))
      (T (COMBMDISPLAY BMAP NOROTATE? NOERRORCHECK PRINTERSTREAM)))))

(FX.PRESSBITMAP
  (LAMBDA (FILE BITMAP SCALEFACTOR REGION ROTATION TITLE)    (* ejs: "28-Aug-85 14:42")
    (PROG ((PRINTERSTREAM (OPENSTREAM (PACK* (QUOTE {)
					     (OR FILE DEFAULTPRINTERDEVICE)
					     (QUOTE }))
				      (QUOTE OUTPUT))))
          (COND
	    (REGION (SETQ NEWBITMAP (BITMAPCREATE (fetch (REGION WIDTH) of REGION)
						  (fetch (REGION HEIGHT) of REGION))))
	    (T (SETQ NEWBITMAP BITMAP)))
          (\PRINTER.INIT PRINTERSTREAM)
          (BITBLT BITMAP (fetch (REGION LEFT) of REGION)
		  (fetch (REGION BOTTOM) of REGION)
		  NEWBITMAP 0 0 (fetch (REGION WIDTH) of REGION)
		  (fetch (REGION HEIGHT) of REGION))
          (RETURN (PROG1 (FBITMAP NEWBITMAP ROTATION NIL NIL PRINTERSTREAM)
			 (CLOSEF PRINTERSTREAM))))))

(FXFITERROR
  (LAMBDA (BMAP NOROTATE? COMPRESS? Y X PRINTERSTREAM)       (* ejs: "28-Aug-85 12:19")
    (printout T "The bitmap will not fit on the page." T)
    (PROG (NROTATE NCOMPRESS USER?)
          (COND
	    ((GREATERP X 576)
	      (COND
		((OR (GREATERP Y 576)
		     COMPRESS?)
		  (SETQ NCOMPRESS T)
		  (COND
		    ((GREATERP X 960)

          (* Both height and width of the bitmap is too big; we thus compress it. Is the X length too long for even 
	  compression? Then rotate it, else preserve the old setting.)


		      (SETQ NROTATE NIL))
		    (T (SETQ NROTATE NOROTATE?))))
		(T (SETQ NROTATE NIL)
		   (SETQ NCOMPRESS COMPRESS?))))
	    ((GREATERP Y 576)
	      (COND
		((NULL NOROTATE?)
		  (SETQ NROTATE T)
		  (SETQ NCOMPRESS COMPRESS?))
		(T (SETQ NROTATE NOROTATE?)
		   (SETQ NCOMPRESS COMPRESS?))))
	    (T (SETQ NROTATE NOROTATE?)
	       (SETQ NCOMPRESS COMPRESS?)))
          (printout T "The following settings will work:" T "NOROTATE? " NROTATE T "COMPRESS? " 
		    NCOMPRESS T T)
          (SETQ USER? (ASKUSER 10 (QUOTE Y)
			       "Use these settings? "
			       (QUOTE ((Y "es
")
					(N "o
")
					(A "bort
")))))
          (COND
	    ((EQ (QUOTE N)
		 USER?)
	      (FBITMAP BMAP NOROTATE? COMPRESS? T PRINTERSTREAM))
	    ((EQ (QUOTE Y)
		 USER?)
	      (FBITMAP BMAP NROTATE NCOMPRESS NIL PRINTERSTREAM))
	    ((EQ (QUOTE A)
		 USER?)
	      (printout T T "Aborted." T)
	      (\PRINTER.MODE (QUOTE EightSpacingOn)
			     PRINTERSTREAM)
	      (\PRINTER.MODE (QUOTE UniDirectionalOff)
			     PRINTERSTREAM))))))

(FXPRINT
  (LAMBDA (HOST FILE PRINTOPTIONS)                           (* ejs: "28-Aug-85 12:27")
    (SETQ SAVED.SUPPRESS.FLAG SUPPRESS.PAPER.ADJ.FLAG)
    (COND
      ((NOT (NULL FILE))
	(COND
	  ((NOT (NULL (SETQ COUNTER (LISTGET PRINTOPTIONS '#COPIES))))
	    (PROG NIL
	      LOOP(COND
		    ((GEQ COUNTER 1)
		      (LET ((PRINTERSTREAM (RS232.PRINT FILE NIL NIL NIL HOST)))
		           (SETQ COUNTER (SUB1 COUNTER))
		           (BOUT PRINTERSTREAM (CHARCODE FF))
		           (SETQ SUPPRESS.PAPER.ADJ.FLAG T)
		           (CLOSEF PRINTERSTREAM))
		      (GO LOOP)))))
	  (T (LET ((PRINTERSTREAM (RS232.PRINT FILE NIL NIL NIL HOST)))
	          (BOUT PRINTERSTREAM (CHARCODE FF))
	          (CLOSEF PRINTERSTREAM))))))
    (SETQ SUPPRESS.PAPER.ADJ.FLAG SAVED.SUPPRESS.FLAG)))

(BITMAPDISPLAY
  (LAMBDA (BMAP STREAM)                                      (* ejs: "28-Aug-85 12:20")

          (* If the user specifies that the Bit Map is to be printed horizontally, then the slow method of printing the imapge
	  via BITMAPBIT is used.)


    (PROG ((WIDTH (fetch BITMAPWIDTH of BMAP))
	   CURRENTHT EXP X Y PRINTVAL)
          (\PRINTER.MODE 'UniDirectionalOn STREAM)
          (\PRINTER.MODE 'EightSpacingOn STREAM)
          (for CURRENTHT from HEIGHT to 0 by -8
	     do ((GRAPHICS.MODE WIDTH)
		 (for X from 1 to WIDTH do ((SETQ PRINTVAL 0)
					    (for EXP from 7 to 0 by -1
					       do ((SETQ Y (DIFFERENCE CURRENTHT (DIFFERENCE 7 EXP)))
						   (SETQ PRINTVAL
						     (IPLUS (ITIMES (EXPT 2 EXP)
								    (BITMAPBIT BMAP X Y))
							    PRINTVAL))))
					    (BOUT STREAM PRINTVAL)))
		 (\PRINTER.CRLF STREAM)))
          (\PRINTER.MODE 'UniDirectionalOff STREAM))))

(TEXTFILEP
  [LAMBDA (FILE)
    (EQ 'TEXT
	(GETFILEINFO FILE 'TYPE])

(WINDOWDISPLAY
  (LAMBDA (WINDOW NOROTATE? COMPRESS? PRINTERDEVICE)         (* ejs: "28-Aug-85 14:42")

          (* This function will print out a window onto the FX-80 printer using the RS232 Port. The image printed will either 
	  be printed straight across or rotated by a negative 90 degrees, depending on whether the user specifically requests 
	  no rotation in the initial function call.)


    (PROG (BITMAP (PRINTERSTREAM (OPENSTREAM (PACK* (QUOTE {)
						    (OR PRINTERDEVICE DEFAULTPRINTERDEVICE)
						    (QUOTE }))
					     (QUOTE OUTPUT))))
          (SETQ BITMAP (WINDOW.TO.BITMAP WINDOW))

          (* Because the function \GETBASEBYTE is much faster than BITMAPBIT, and can only work on bit maps, first this 
	  function changes the window into a bit map, using WINDOW.TO.BITMAP, then it performs functions upon the created bit 
	  map as if it had been called from RS232.PRINT.)


          (FBITMAP BITMAP NOROTATE? COMPRESS? NIL PRINTERSTREAM)
          (CLOSEF PRINTERSTREAM))))

(WINDOW.TO.BITMAP
  [LAMBDA (WINDOW)                                           (* JBleier "17-Feb-84 18:10")
    (PROG (BITMAP)
          [SETQ BITMAP (BITMAPCREATE (WINDOWPROP WINDOW (QUOTE WIDTH))
				     (WINDOWPROP WINDOW (QUOTE HEIGHT]
          (BITBLT WINDOW NIL NIL BITMAP)
          (RETURN BITMAP])

(BOLD.MODE
  (LAMBDA (STREAM)                                           (* ejs: "28-Aug-85 11:03")
                                                             (* Print Bold pitch)
    (\PRINTER.MODE (QUOTE ProportionalOff)
		   STREAM)
    (\PRINTER.MODE (QUOTE ExpandOff)
		   STREAM)
    (\PRINTER.MODE (QUOTE CompressedOn)
		   STREAM)
    (\PRINTER.MODE (QUOTE BoldOn)
		   STREAM)))

(COMBMDISPLAY
  (LAMBDA (BMAP NOROTATE? NOERRORCHECK PRINTERSTREAM)        (* ejs: "28-Aug-85 13:28")
    (PROG ((HEIGHT (fetch BITMAPHEIGHT of BMAP))
	   (WIDTH (fetch BITMAPWIDTH of BMAP))
	   PRINTVAL YPOS)
          (\PRINTER.MODE (QUOTE UniDirectionalOn)
			 PRINTERSTREAM)
          (COND
	    ((NULL NOROTATE?)                                (* The cheap man's way of rotating the object: rotate 
							     the height and width coordinates instead.)
	      (SETQ YPOS HEIGHT)                             (* YPOS is not being used at the moment;
							     it makes a wonderful temporary variable)
	      (SETQ HEIGHT WIDTH)
	      (SETQ WIDTH YPOS)))

          (* This method of printing out a bitmap is very slow; it requires two passes of the printer head to put down a line 
	  of information. But it is very compressed; the size is around 2/3 of normal.)


          (COND
	    ((AND (GREATERP WIDTH 960)
		  (NULL NOERRORCHECK))
	      (FXFITERROR BMAP NOROTATE? T (COND
			    (NOROTATE? HEIGHT)
			    (T WIDTH))
			  (COND
			    (NOROTATE? WIDTH)
			    (T HEIGHT))
			  PRINTERSTREAM))
	    (T
	      (for Q from HEIGHT to 0 by -24
		 do
		  (for I from Q to (IDIFFERENCE Q 12) by -12
		     do
		      (

          (* The reason for two passes is simple; the first pass uses the top 4 sets of pins (number 1, 3, 5, and 7), and the 
	  second pass uses the bottom 4 sets of pins (number 2, 4, 6, and 8). This makes it so the pins wear evenly while 
	  dumping large bitmaps.)


		       (for YY from 11 to 9 by -1
			  do
			   (COMGRAPH.MODE WIDTH PRINTERSTREAM)
			   (for X from 1 to WIDTH
			      do
			       ((SETQ PRINTVAL 0)
				(for Y from YY to 0 by -3
				   do ((SETQ YPOS (IDIFFERENCE I (IDIFFERENCE 11 Y)))
				       (SETQ PRINTVAL
					 (IPLUS PRINTVAL
						(ITIMES (CAR (NTH (COND
								    ((EQP I Q)
								      (QUOTE (1 4 16 64)))
								    (T (QUOTE (2 8 32 128))))
								  (ADD1 (IQUOTIENT Y 3))))
							(COND
							  (NOROTATE? (BITMAPBIT BMAP X YPOS))
							  (T (BITMAPBIT BMAP (IDIFFERENCE HEIGHT YPOS)
									X))))))))
				(BOUT PRINTERSTREAM PRINTVAL)))

          (* The printer now prints four rows of information per pass at the printer. This is to keep the proper aspect ratio 
	  (which turns out to be a 2/3 spacing per dot, where the dots on the printer head itself is 1, by definition.) So, 
	  the printer makes three passes at this spacing, and then does an EightSpace move; thus, 12 rows of dots are placed 
	  where 8 was before.)


			   (\PRINTER.COMMAND (CHARCODE "3")
					     PRINTERSTREAM)
			   (BOUT PRINTERSTREAM 2)
			   (\PRINTER.CRLF PRINTERSTREAM))

          (* The alternate 5 and 7 spacing is used because of the printer head; when a line is finished printing, the head is 
	  already 2 spaces down. Then, by going with 5 and 7, it is possible to switch the set of pins being used on the 
	  printer head. The printing is finished with eight-spacing, only to get things going right again.)


		       (\PRINTER.COMMAND (CHARCODE "A")
					 PRINTERSTREAM)
		       (BOUT PRINTERSTREAM (COND
			       ((EQP I Q)
				 7)
			       (T 5)))
		       (\PRINTER.CRLF PRINTERSTREAM))))
	      (\PRINTER.MODE (QUOTE EightSpacingOn)
			     PRINTERSTREAM)
	      (\PRINTER.MODE (QUOTE UniDirectionalOff)
			     PRINTERSTREAM)
	      (\PRINTER.CRLF PRINTERSTREAM))))))

(COMGRAPH.MODE
  (LAMBDA (WIDTH STREAM)                                     (* ejs: "28-Aug-85 12:21")
    (\PRINTER.COMMAND (CHARCODE "L")
		      STREAM)
    (COND
      ((LESSP WIDTH 256)
	(BOUT STREAM WIDTH)
	(BOUT STREAM 0))
      (T (BOUT STREAM (REMAINDER WIDTH 256))
	 (BOUT STREAM (IQUOTIENT WIDTH 256))))))

(COMMENT.MODE
  (LAMBDA (STREAM)                                           (* ejs: "28-Aug-85 11:04")
                                                             (* Print in subscripted, italicized, compressed pitch)
    (\PRINTER.MODE (QUOTE EliteOff)
		   STREAM)
    (\PRINTER.MODE (QUOTE BoldOff)
		   STREAM)
    (\PRINTER.MODE (QUOTE SubScriptOn)
		   STREAM)
    (\PRINTER.MODE (QUOTE ItalicOn)
		   STREAM)
    (\PRINTER.MODE (QUOTE CompressedOn)
		   STREAM)))

(EXPANDED.MODE
  (LAMBDA (STREAM)                                           (* ejs: "28-Aug-85 11:04")
                                                             (* Print in Expanded pitch)
    (\PRINTER.MODE (QUOTE BoldOff)
		   STREAM)
    (\PRINTER.MODE (QUOTE EliteOff)
		   STREAM)
    (\PRINTER.MODE (QUOTE ExpandOn)
		   STREAM)
    (\PRINTER.MODE (QUOTE ProportionalOn)
		   STREAM)))

(GRAPHICS.MODE
  (LAMBDA (ROWS STREAM)                                      (* ejs: "28-Aug-85 12:16")
    (\PRINTER.COMMAND (CHARCODE "*")
		      STREAM)
    (BOUT STREAM 5)
    (COND
      ((LESSP ROWS 256)
	(BOUT STREAM ROWS)
	(BOUT STREAM 0))
      (T (BOUT STREAM (REMAINDER ROWS 256))
	 (BOUT STREAM (IQUOTIENT ROWS 256))))))

(SELECT.MODE
  (LAMBDA (CHAR STREAM)                                      (* ejs: "28-Aug-85 11:02")
    (SELCHARQ CHAR
	      (↑F 

          (* If the character just received from the file is a ↑F, then the next character will dictate mode type.
	  Get that next character and find what mode type to send to the printer.)


		  (SETQ CHAR (BIN FILE))
		  (SELCHARQ CHAR
			    (↑B                              (* Print Bold)
				(BOLD.MODE STREAM))
			    (↑C                              (* Print Comments)
				(COMMENT.MODE STREAM))
			    (↑D                              (* Print Large)
				(EXPANDED.MODE STREAM))
			    (PROGN 

          (* If the mode is none of the above, then it is either standard mode (↑A), or unknown; in either case, use standard 
	  pitch.)


				   (STANDARD.MODE STREAM))))
	      (CR (\PRINTER.CRLF STREAM))
	      (BOUT STREAM CHAR))))

(STANDARD.MODE
  (LAMBDA (STREAM)                                           (* ejs: "28-Aug-85 11:05")

          (* Turn off all the previous switches, i.e., print in standard pica. (the function \PRINTER.MODE takes as its 
	  argument the mode switch direction, and sends code to the printer via the function \PRINTER.COMMAND that directs the
	  printer to perform the given operation.))


    (\PRINTER.MODE (QUOTE CompressedOn)
		   STREAM)
    (\PRINTER.MODE (QUOTE ItalicOff)
		   STREAM)
    (\PRINTER.MODE (QUOTE ScriptOff)
		   STREAM)
    (\PRINTER.MODE (QUOTE EliteOff)
		   STREAM)
    (\PRINTER.MODE (QUOTE ExpandOff)
		   STREAM)
    (\PRINTER.MODE (QUOTE BoldOff)
		   STREAM)
    (\PRINTER.MODE (QUOTE ProportionalOff)
		   STREAM)))

(\PRINTER.COMMAND
  (LAMBDA (CommandChar STREAM)                               (* ejs: "28-Aug-85 11:38")

          (* Send an Escape, to tell the printer there is to be a mode change, and the then specific mode change, as detailed 
	  in PRINTER.MODE.)


    (BOUT STREAM (CHARCODE ESC))
    (BOUT STREAM CommandChar)))

(\PRINTER.CRLF
  (LAMBDA (STREAM)                                           (* ejs: "28-Aug-85 13:30")
                                                             (* Send a carraige return/line feed to the printer;
							     the printer holds all incoming characters in its buffer
							     until it sees a CR/LF.)
    (BOUT STREAM (CHARCODE CR))
    (BOUT STREAM (CHARCODE LF))
    (COND
      ((fetch (FDEV BUFFERED) of (fetch (STREAM DEVICE) of STREAM))
	(FORCEOUTPUT STREAM)))
    (BLOCK)))

(\PRINTER.HEADING
  (LAMBDA (FILENAME STREAM)                                  (* ejs: "28-Aug-85 11:42")
    (PRIN1 "Listing of File " STREAM)
    (PRIN1 FILENAME STREAM)
    (PRIN1 " , " STREAM)
    (PRIN1 (DATE)
	   STREAM)
    (PRIN1 " by " STREAM)
    (PRIN1 (USERNAME)
	   STREAM)
    (\PRINTER.CRLF STREAM)
    (\PRINTER.CRLF STREAM)))

(\PRINTER.INIT
  (LAMBDA (STREAM)                                           (* ejs: "28-Aug-85 11:49")

          (* This function closes the file to be printed (if necessary.) It also allows the user to specify baud rate.
	  Default on the baud rate is 1200)


    (COND
      ((NULL SUPPRESS.PAPER.SET.FLAG)
	(PROG (BAUDRATE)
	  SLOWPERSON
	      (printout T T T 
		    "Set the paper in the printer so that it is about 1/2 inch above the ribbon."
			T "Remember to turn the printer off first." T T T)
	      (printout T T T)
	      (COND
		((NOT (EQ (ASKUSER 7 (QUOTE Y)
				   "Are you all set?(Y/N)")
			  (QUOTE Y)))
		  (GO SLOWPERSON))))))
    (COND
      (DEFAULTLOCALBAUDRATE (SETQ BAUDRATE DEFAULTLOCALBAUDRATE))
      (T (SETQ BAUDRATE (ASKUSER 60 1200 
		   "What Baud Rate do you want (make sure your printer is set to the same rate)?"
				 (QUOTE (300 1200 2400 4800 9600))))))
    (SELECTQ (fetch (FDEV DEVICENAME) of (fetch (STREAM DEVICE) of STREAM))
	     (RS232 (RS232C.SET.PARAMETERS (BQUOTE ((LINE.SPEED ,@ BAUDRATE)
						    (STOP.BITS . 1)
						    (CHAR.LENGTH . 8)
						    (DATA.TERMINAL.READY . T)
						    (FLOW.CONTROL 1 17 19)))))
	     (TTY (TTY.SET.PARAMETERS (BQUOTE ((LINE.SPEED ,@ BAUDRATE)
					       (STOP.BITS . 1)
					       (CHAR.LENGTH . 8)
					       (DATA.TERMINAL.READY . T)
					       (FLOW.CONTROL 1 17 19)))))
	     (ERROR "Unknown printer device" (fetch (FDEV DEVICENAME) of (fetch (STREAM DEVICE)
									    of STREAM))))))

(\PRINTER.MODE
  (LAMBDA (Mode STREAM)                                      (* ejs: "28-Aug-85 11:09")

          (* Ths function takes as its argument the mode for the printer to print in, and sends this to the printer via the 
	  function \PRINTER.COMMAND.)


    (SELECTQ Mode
	     (BoldOn (\PRINTER.COMMAND (CHARCODE "E")
				       STREAM))
	     (BoldOff (\PRINTER.COMMAND (CHARCODE "F")
					STREAM))
	     (CompressedOn (\PRINTER.COMMAND 15 STREAM))
	     (CompressedOff (BOUT STREAM 18))
	     (EliteOn (\PRINTER.COMMAND (CHARCODE "M")
					STREAM))
	     (EliteOff (\PRINTER.COMMAND (CHARCODE "P")
					 STREAM))
	     (ItalicOn (\PRINTER.COMMAND (CHARCODE "4")
					 STREAM))
	     (ItalicOff (\PRINTER.COMMAND (CHARCODE "5")
					  STREAM))
	     (PicaOn (\PRINTER.COMMAND (CHARCODE "P")
				       STREAM)
		     (BOUT STREAM 18))
	     (SubScriptOn (\PRINTER.COMMAND (CHARCODE "S")
					    STREAM)
			  (BOUT STREAM (CHARCODE "0")))
	     (ScriptOff (\PRINTER.COMMAND (CHARCODE "T")
					  STREAM))
	     (SuperScriptOn (\PRINTER.COMMAND (CHARCODE "S")
					      STREAM)
			    (BOUT STREAM (CHARCODE "1")))
	     (ExpandOn (\PRINTER.COMMAND (CHARCODE "W")
					 STREAM)
		       (BOUT STREAM (CHARCODE "1")))
	     (ExpandOff (\PRINTER.COMMAND (CHARCODE "W")
					  STREAM)
			(BOUT STREAM (CHARCODE "0"))
			T)
	     (ProportionalOn (\PRINTER.COMMAND (CHARCODE "p")
					       STREAM)
			     (BOUT STREAM (CHARCODE "1")))
	     (ProportionalOff (\PRINTER.COMMAND (CHARCODE "p")
						STREAM)
			      (BOUT STREAM (CHARCODE "0")))
	     (UniDirectionalOn (\PRINTER.COMMAND (CHARCODE "U")
						 STREAM)
			       (BOUT STREAM (CHARCODE "1")))
	     (UniDirectionalOff (\PRINTER.COMMAND (CHARCODE "U")
						  STREAM)
				(BOUT STREAM (CHARCODE "0")))
	     (SevenSpacingOn (\PRINTER.COMMAND (CHARCODE "1")
					       STREAM))
	     (EightSpacingOn (\PRINTER.COMMAND (CHARCODE "A")
					       STREAM)
			     (BOUT STREAM 8))
	     (NineSpacingOn (\PRINTER.COMMAND (CHARCODE "0")
					      STREAM))
	     (TwelveSpacingOn (\PRINTER.COMMAND (CHARCODE "2")
						STREAM))
	     NIL)))

(\PRINTER.PRINT.HEADING
  (LAMBDA (FILENAME STREAM)                                  (* ejs: "28-Aug-85 11:01")
    (\PRINTER.CRLF STREAM)
    (\PRINTER.MODE (QUOTE BoldOn)
		   STREAM)
    (\PRINTER.HEADING FILENAME STREAM)
    (\PRINTER.MODE (QUOTE BoldOff)
		   STREAM)
    (\PRINTER.CRLF STREAM)))

(\PRINTER.TEXTINIT
  (LAMBDA (STREAM)                                           (* ejs: "28-Aug-85 11:00")
                                                             (* Perform all of the initialization, including setting
							     the character modes for standard pitch, and making sure
							     that XON\XOFF protocol is used.)
    (\PRINTER.MODE (QUOTE BoldOff)
		   STREAM)
    (\PRINTER.MODE (QUOTE PicaOn)
		   STREAM)
    (\PRINTER.MODE (QUOTE ExpandOff)
		   STREAM)
    (\PRINTER.MODE (QUOTE CompressedOn)
		   STREAM)
    (\PRINTER.MODE (QUOTE ProportionalOff)
		   STREAM)
    (\PRINTER.MODE (QUOTE TwelveSpacingOn)
		   STREAM)
    (\PRINTER.COMMAND (CHARCODE "N")
		      STREAM)
    (BOUT STREAM 7)))
)

(RPAQ? DEFAULTPRINTERDEVICE (QUOTE TTY))

(RPAQ? DEFAULTLOCALBAUDRATE NIL)

(RPAQ? SUPPRESS.PAPER.ADJ.FLAG NIL)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS SUPPRESS.PAPER.ADJ.FLAG DEFAULTLOCALBAUDRATE DEFAULTPRINTERDEVICE)
)
(PUTPROPS FXPRINTER COPYRIGHT ("Xerox Corporation" 1984 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (2158 26427 (RS232.PRINT 2168 . 2961) (RS232.PRINTFILE 2963 . 4337) (FBITMAP 4339 . 6282
) (FX.PRESSBITMAP 6284 . 7160) (FXFITERROR 7162 . 8891) (FXPRINT 8893 . 9783) (BITMAPDISPLAY 9785 . 
10836) (TEXTFILEP 10838 . 10918) (WINDOWDISPLAY 10920 . 12001) (WINDOW.TO.BITMAP 12003 . 12320) (
BOLD.MODE 12322 . 12754) (COMBMDISPLAY 12756 . 16501) (COMGRAPH.MODE 16503 . 16867) (COMMENT.MODE 
16869 . 17391) (EXPANDED.MODE 17393 . 17831) (GRAPHICS.MODE 17833 . 18217) (SELECT.MODE 18219 . 19164)
 (STANDARD.MODE 19166 . 19991) (\PRINTER.COMMAND 19993 . 20342) (\PRINTER.CRLF 20344 . 20907) (
\PRINTER.HEADING 20909 . 21299) (\PRINTER.INIT 21301 . 22916) (\PRINTER.MODE 22918 . 25283) (
\PRINTER.PRINT.HEADING 25285 . 25622) (\PRINTER.TEXTINIT 25624 . 26425)))))
STOP