(FILECREATED "10-FEB-84 22:00:26" {DSK}FXPRINTER.;19 16588  

      changes to:  (FNS FBITMAP RS232.PRINT)

      previous date: "10-FEB-84 14:19:19" {DSK}FXPRINTER.;14)


(PRETTYCOMPRINT FXPRINTERCOMS)

(RPAQQ FXPRINTERCOMS ([ADDVARS (PRINTERTYPES ((FX.80 LOCALPRINTER)
					      (CANPRINT (TEXT BITMAP WINDOW))
					      (STATUS TRUE)
					      (PROPERTIES NILL)
					      (SEND RS232.PRINT]
		      (VARS PRINTERFNS)
		      (FNS * PRINTERFNS)))

(ADDTOVAR PRINTERTYPES ((FX.80 LOCALPRINTER)
			(CANPRINT (TEXT BITMAP WINDOW))
			(STATUS TRUE)
			(PROPERTIES NILL)
			(SEND RS232.PRINT)))

(RPAQQ PRINTERFNS (RS232.PRINT RS232.PRINTFILE FBITMAP BITMAPDISPLAY WINDOWDISPLAY SETWPARAMS 
			       \PRINTER.MAP BOLD.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?)                               (* JBleier "10-FEB-84 15:19")
    (PROG NIL
      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)
          (COND
	    [(EQ (ASKUSER 60 (QUOTE Y)
			  "Are you all set?(Y/N)")
		 (QUOTE Y))
	      (\PRINTER.INIT)
	      (COND
		((BITMAPP FILENAME)
		  (FBITMAP FILENAME NOROTATE?))
		((WINDOWP FILENAME)
		  (WINDOWDISPLAY FILENAME NOROTATE?))
		(T (RS232.PRINTFILE FILENAME]
	    (T (GO SLOWPERSON])

(RS232.PRINTFILE
  [LAMBDA (FILENAME)                                         (* JBleier "20-Jan-84 18:16")

          (* 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)                                (* This function initializes print modes and form feeds 
							     on the Epson printer.)
          (\PRINTER.PRINT.HEADING FILENAME)                  (* 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])

(FBITMAP
  [LAMBDA (BMAP NOROTATE?)                                   (* JBleier "10-FEB-84 21:51")

          (* 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.)


    (PROG ((HEIGHT (fetch BITMAPHEIGHT of BMAP))
	   (BASE (fetch BITMAPBASE of BMAP))
	   (BYTESPERROW (ITIMES 2 (fetch BITMAPRASTERWIDTH of BMAP)))
	   COLUMN J CNT OFFSET)
          (COND
	    (NOROTATE? (BITMAPDISPLAY BMAP))
	    (T (\PRINTER.MODE (QUOTE UniDirectionalOn))
	       (\PRINTER.MODE (QUOTE EightSpacingOn))
	       (SETQ OFFSET BYTESPERROW)
	       (for COLUMN from 1 to BYTESPERROW
		  do (GRAPHICS.MODE HEIGHT)
		     (for J from HEIGHT to 1 by -1 do (RS232WRITEBYTE (\GETBASEBYTE
									BASE
									(IDIFFERENCE (ITIMES 
										      BYTESPERROW J)
										     OFFSET))
								      T))
		     (\PRINTER.CRLF)
		     (SETQ OFFSET (SUB1 OFFSET)))
	       (\PRINTER.MODE (QUOTE UniDirectionalOff])

(BITMAPDISPLAY
  [LAMBDA (BMAP)                                             (* JBleier "10-FEB-84 13:49")

          (* 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 (CURRENTHT EXP X Y PRINTVAL)
          (\PRINTER.MODE (QUOTE UniDirectionalOn))
          (\PRINTER.MODE (QUOTE EightSpacingOn))
          (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]
					    (RS232WRITEBYTE PRINTVAL T)))
		 (\PRINTER.CRLF)))
          (\PRINTER.MODE (QUOTE UniDirectionalOff])

(WINDOWDISPLAY
  [LAMBDA (WINDOW)                                           (* edited: "27-JAN-84 19:20")

          (* 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 90, depending on whether its width fits into 480 columns.)


    (PROG ((STEP1 -8)
	   STEP2 WIDTH HEIGHT UPPER LOWER NOROTATE)
          (COND
	    [(GREATERP (WINDOWPROP WINDOW (QUOTE WIDTH))
		       480)
	      (COND
		((GREATERP (WINDOWPROP WINDOW (QUOTE HEIGHT))
			   480)
		  (printout "This Window is too large for the paper..." T T)

          (* If both the height and the width of the window are greater than 480 columns, then the bitmap cannot be printed 
	  on 8.5 across paper, even after rotating the image.)


		  (RETURN T))
		(T (SETWPARAMS WINDOW (QUOTE HEIGHT)
			       (QUOTE WIDTH)
			       T]
	    (T (SETWPARAMS WINDOW (QUOTE WIDTH)
			   (QUOTE HEIGHT)
			   NIL)

          (* If only the width is more than the allowed number of columns, then set the parameters using SETWPARAMS so that 
	  the image is rotated by 90 degrees, then print the rotated image.)


	       ))
          (\PRINTER.MODE (QUOTE UniDirectionalOn))
          (\PRINTER.MODE (QUOTE EightSpacingOn))
          (\PRINTER.MAP WINDOW)
          (\PRINTER.MODE (QUOTE UniDirectionalOff])

(SETWPARAMS
  [LAMBDA (WINDOW W H ROTATE?)                               (* JBleier "20-Jan-84 18:09")

          (* This function sets the parameters for the image so that it either prints out straight, or rotated by 90 
	  degrees. it also sets the variable NOROTATE to either T or NIL, so that the function BITMAPBIT knows to get the 
	  bit for either the straight image (BITMAPBIT X Y) or the rotated one (BITMAPBIT Y X))


    (SETQ WIDTH (WINDOWPROP WINDOW W))
    (SETQ HEIGHT (WINDOWPROP WINDOW H))
    (COND
      (ROTATE? (SETQ UPPER 1)
	       (SETQ LOWER WIDTH)
	       (SETQ STEP2 -1)
	       (SETQ NOROTATE NIL))
      (T (SETQ UPPER WIDTH)
	 (SETQ LOWER 1)
	 (SETQ STEP2 1)
	 (SETQ NOROTATE T])

(\PRINTER.MAP
  [LAMBDA (MAP)                                              (* JBleier "20-Jan-84 18:53")

          (* This function is called by both WINDOWDISPLAY and BITMAPDISPLAY. Both of the above functions set up their local
	  parameters UPPER, LOWER, WIDTH and HEIGHT using either SETBMPARAMS or SETWPARAMS, depending on if the object to be
	  printed is a window or a bitmap. This function either prints out the object straight, or rotated ninety degrees, 
	  depending on how the parameters were set.)


    (PROG (CURRENTHT EXP X Y PRINTVAL)
          (for CURRENTHT from HEIGHT to 0 by STEP1
	     do ((GRAPHICS.MODE WIDTH)
		 (for X from LOWER to UPPER by STEP2
		    do ((SETQ PRINTVAL 0)
			[for EXP from 7 to 0 by -1
			   do ((SETQ Y (DIFFERENCE CURRENTHT (DIFFERENCE 7 EXP)))
			       (COND
				 (NOROTATE (SETQ PRINTVAL (IPLUS (ITIMES (EXPT 2 EXP)
									 (BITMAPBIT MAP X Y))
								 PRINTVAL)))
				 (T 

          (* If the image has been rotated, then just switching the parameters around is not enough;
	  the function BITMAPBIT must also be informed that it is to obtain the rotated bit, by switching the X and Y 
	  coordinates for it.)


				    (SETQ PRINTVAL (IPLUS (ITIMES (EXPT 2 EXP)
								  (BITMAPBIT MAP Y X))
							  PRINTVAL]
			(RS232WRITEBYTE PRINTVAL T)))
		 (\PRINTER.CRLF])

(BOLD.MODE
  [LAMBDA NIL                                                (* JBleier "20-Jan-84 18:17")
                                                             (* Print Bold pitch)
    (\PRINTER.MODE (QUOTE ProportionalOff))
    (\PRINTER.MODE (QUOTE ExpandOff))
    (\PRINTER.MODE (QUOTE CompressedOn))
    (\PRINTER.MODE (QUOTE BoldOn])

(COMMENT.MODE
  [LAMBDA NIL                                                (* JBleier "20-Jan-84 18:18")
                                                             (* Print in subscripted, italicized, compressed pitch)
    (\PRINTER.MODE (QUOTE EliteOff))
    (\PRINTER.MODE (QUOTE BoldOff))
    (\PRINTER.MODE (QUOTE SubScriptOn))
    (\PRINTER.MODE (QUOTE ItalicOn))
    (\PRINTER.MODE (QUOTE CompressedOn])

(EXPANDED.MODE
  [LAMBDA NIL                                                (* JBleier "20-Jan-84 18:18")
                                                             (* Print in Expanded pitch)
    (\PRINTER.MODE (QUOTE BoldOff))
    (\PRINTER.MODE (QUOTE EliteOff))
    (\PRINTER.MODE (QUOTE ExpandOn))
    (\PRINTER.MODE (QUOTE ProportionalOn])

(GRAPHICS.MODE
  [LAMBDA (ROWS)                                             (* edited: "15-JAN-84 17:55")
    (\PRINTER.COMMAND (CHARCODE "*"))
    (RS232WRITEBYTE 5 T)
    (COND
      ((LESSP ROWS 256)
	(RS232WRITEBYTE ROWS T)
	(RS232WRITEBYTE 0 T))
      (T (RS232WRITEBYTE (REMAINDER ROWS 256)
			 T)
	 (RS232WRITEBYTE (IQUOTIENT ROWS 256)
			 T])

(SELECT.MODE
  [LAMBDA (CHAR)                                             (* JBleier "20-Jan-84 18:23")
    (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))
			    (↑C                              (* Print Comments)
				(COMMENT.MODE))
			    (↑D                              (* Print Large)
				(EXPANDED.MODE))
			    (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]
	      (CR (\PRINTER.CRLF))
	      (RS232WRITEBYTE CHAR T])

(STANDARD.MODE
  [LAMBDA NIL                                                (* edited: "29-DEC-83 18:14")

          (* 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))
    (\PRINTER.MODE (QUOTE ItalicOff))
    (\PRINTER.MODE (QUOTE ScriptOff))
    (\PRINTER.MODE (QUOTE EliteOff))
    (\PRINTER.MODE (QUOTE ExpandOff))
    (\PRINTER.MODE (QUOTE BoldOff))
    (\PRINTER.MODE (QUOTE ProportionalOff])

(\PRINTER.COMMAND
  [LAMBDA (CommandChar)                                      (* JBleier "20-Jan-84 18:23")

          (* 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.)


    (RS232WRITEBYTE (CHARCODE ESC)
		    T)
    (RS232WRITEBYTE CommandChar T])

(\PRINTER.CRLF
  [LAMBDA NIL                                                (* JBleier "20-Jan-84 18:21")
                                                             (* Send a carraige return/line feed to the printer;
							     the printer holds all incoming characters in its buffer 
							     until it sees a CR/LF.)
    (RS232WRITEBYTE (CHARCODE CR))
    (RS232WRITEBYTE (CHARCODE LF))
    (RS232FORCEOUTPUT])

(\PRINTER.HEADING
  [LAMBDA (FILENAME)                                         (* edited: "29-DEC-83 19:15")
    (RS232WRITECHARS "Listing of File " T)
    (RS232WRITECHARS FILENAME T)
    (RS232WRITECHARS " , " T)
    (RS232WRITECHARS (DATE)
                     T)
    (RS232WRITECHARS " by " T)
    (RS232WRITECHARS (USERNAME)
                     T)
    (\PRINTER.CRLF)
    (\PRINTER.CRLF])

(\PRINTER.INIT
  [LAMBDA NIL                                                (* edited: "27-JAN-84 19:18")

          (* This function brings in the RS232 code (if necessary) and closes the file to printed (once again, if necessary)
. It also allows the user to specify baud rate. Default on the baud rate is 1200)


    (PROG (BAUDRATE)
          (printout T T T)
          (LOAD? (QUOTE RS232.DCOM))
          [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]
          (RS232INIT BAUDRATE 8 NIL 1 (QUOTE DTR))
          (SETQ RS232XON\XOFF? T])

(\PRINTER.MODE
  [LAMBDA (Mode)                                             (* JBleier "20-Jan-84 18:23")

          (* 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")))
	     (BoldOff (\PRINTER.COMMAND (CHARCODE "F")))
	     (CompressedOn (\PRINTER.COMMAND 15))
	     (CompressedOff (RS232WRITEBYTE 18 T))
	     (EliteOn (\PRINTER.COMMAND (CHARCODE "M")))
	     (EliteOff (\PRINTER.COMMAND (CHARCODE "P")))
	     (ItalicOn (\PRINTER.COMMAND (CHARCODE "4")))
	     (ItalicOff (\PRINTER.COMMAND (CHARCODE "5")))
	     (PicaOn (\PRINTER.COMMAND (CHARCODE "P"))
		     (RS232WRITEBYTE 18 T))
	     (SubScriptOn (\PRINTER.COMMAND (CHARCODE "S"))
			  (RS232WRITEBYTE (CHARCODE "0")
					  T))
	     (ScriptOff (\PRINTER.COMMAND (CHARCODE "T")))
	     (SuperScriptOn (\PRINTER.COMMAND (CHARCODE "S"))
			    (RS232WRITEBYTE (CHARCODE "1")
					    T))
	     (ExpandOn (\PRINTER.COMMAND (CHARCODE "W"))
		       (RS232WRITEBYTE (CHARCODE "1")
				       T))
	     (ExpandOff (\PRINTER.COMMAND (CHARCODE "W"))
			(RS232WRITEBYTE (CHARCODE "0"))
			T)
	     (ProportionalOn (\PRINTER.COMMAND (CHARCODE "p"))
			     (RS232WRITEBYTE (CHARCODE "1")
					     T))
	     (ProportionalOff (\PRINTER.COMMAND (CHARCODE "p"))
			      (RS232WRITEBYTE (CHARCODE "0")
					      T))
	     (UniDirectionalOn (\PRINTER.COMMAND (CHARCODE "U"))
			       (RS232WRITEBYTE (CHARCODE "1")
					       T))
	     (UniDirectionalOff (\PRINTER.COMMAND (CHARCODE "U"))
				(RS232WRITEBYTE (CHARCODE "0")
						T))
	     (SevenSpacingOn (\PRINTER.COMMAND (CHARCODE "1")))
	     (EightSpacingOn (\PRINTER.COMMAND (CHARCODE "A"))
			     (RS232WRITEBYTE 8 T))
	     (NineSpacingOn (\PRINTER.COMMAND (CHARCODE "0")))
	     NIL])

(\PRINTER.PRINT.HEADING
  [LAMBDA (FILENAME)                                         (* JBleier "20-Jan-84 18:14")
    (\PRINTER.CRLF)
    (\PRINTER.MODE (QUOTE BoldOn))
    (\PRINTER.HEADING FILENAME)
    (\PRINTER.MODE (QUOTE BoldOff))
    (\PRINTER.CRLF])

(\PRINTER.TEXTINIT
  [LAMBDA NIL                                                (* JBleier "20-Jan-84 18:13")
                                                             (* Perform all of the initialization, including setting 
							     the character modes for standard pitch, and making sure 
							     that XON\XOFF protocol is used.)
    (SETQ RS232XON\XOFF? T)
    (\PRINTER.MODE (QUOTE BoldOff))
    (\PRINTER.MODE (QUOTE PicaOn))
    (\PRINTER.MODE (QUOTE ExpandOff))
    (\PRINTER.MODE (QUOTE CompressedOn))
    (\PRINTER.MODE (QUOTE ProportionalOff))
    (\PRINTER.COMMAND (CHARCODE "N"))
    (RS232WRITEBYTE 7])
)
(DECLARE: DONTCOPY
  (FILEMAP (NIL (960 16566 (RS232.PRINT 970 . 1603) (RS232.PRINTFILE 1605 . 2900) (FBITMAP 2902 . 4048) 
(BITMAPDISPLAY 4050 . 5005) (WINDOWDISPLAY 5007 . 6426) (SETWPARAMS 6428 . 7158) (\PRINTER.MAP 7160 . 
8586) (BOLD.MODE 8588 . 8957) (COMMENT.MODE 8959 . 9402) (EXPANDED.MODE 9404 . 9779) (GRAPHICS.MODE 
9781 . 10143) (SELECT.MODE 10145 . 11042) (STANDARD.MODE 11044 . 11773) (\PRINTER.COMMAND 11775 . 
12130) (\PRINTER.CRLF 12132 . 12569) (\PRINTER.HEADING 12571 . 12981) (\PRINTER.INIT 12983 . 13651) (
\PRINTER.MODE 13653 . 15605) (\PRINTER.PRINT.HEADING 15607 . 15893) (\PRINTER.TEXTINIT 15895 . 16564))
)))
STOP