(FILECREATED "29-Jan-84 22:17:01" {PHYLUM}<BLUEBONNET>DMRUSSELL>8200SERVER.;5 14696  

      changes to:  (FNS Simulate8200StateChange)

      previous date: "26-SEP-83 16:07:37" {PHYLUM}<BLUEBONNET>DMRUSSELL>8200SERVER.;4)


(PRETTYCOMPRINT 8200SERVERCOMS)

(RPAQQ 8200SERVERCOMS [(FNS * 8200SERVERFNS)
		       (MACROS * 8200SERVERMACROS)
		       (VARS (Simulate8200 NIL))
		       (P (LOAD? 'EVALSERVER.DCOM])

(RPAQQ 8200SERVERFNS (ServerPush8200Button ServerRead8200 SimulateServerPush8200Button 
					   Simulate8200StateChange))
(DEFINEQ

(ServerPush8200Button
  [LAMBDA (button)                                           (* ref: "18-MAR-82 09:55")

          (* Send a signal to the "8200" that will have the effect of pushing the panel button specified by "button". 
"button" can be an integer 0,1,...,9, one of the globally specified buttons (e.g., CopyModeButton), or one of the atoms 
	  Blank, Clear, Copy, CopyMode, Output, PaperTray, Reduction, StartPrint, or StopPrint.)


    (Clear8200)
    (WRITEPRINTERPORT (SELECTQ button
			       (1 2048)
			       (2 2049)
			       (3 2050)
			       (4 2051)
			       (5 2052)
			       (6 2053)
			       (7 2054)
			       (8 2055)
			       (9 1024)
			       (0 1032)
			       ((Blank BlankButton)
				 1040)
			       ((StartPrint StartPrintButton)
				 1048)
			       ((StopPrint StopPrintButton)
				 1056)
			       ((Copy CopyButton)
				 1064)
			       ((CopyMode CopyModeButton)
				 1072)
			       ((Reduction ReductionButton)
				 1080)
			       ((Clear ClearButton)
				 512)
			       ((PaperTray PaperTrayButton)
				 576)
			       ((Output OutputButton)
				 640)
			       (PROG [(fix (FIXSPELL button NIL '(Blank StartPrint StopPrint Copy 
									CopyMode Reduction Clear 
									PaperTray Output BlankButton 
									StartPrintButton 
									StopPrintButton CopyButton 
									CopyModeButton 
									ReductionButton ClearButton 
									PaperTrayButton OutputButton]
				     (RETURN (if fix
						 then (Push8200Button fix)
					       else (HELP "Unknown arg to Push8200Button" button])

(ServerRead8200
  [LAMBDA NIL                                                (* DMR: "15-JUN-83 10:38")
                                                             (* Read a 30 byte status report from the 8200 copier.
							     Return a list containing the 30 bytes..)
    (PROG [byte (array (ARRAY 30 (QUOTE BYTE]
          (Clear8200)                                        (* If we are SIMULATING the 8200, instead of really 
							     sensing data, the var Simulate8200 will be T)
          (if Simulate8200
	      then (ERROR "ServerRead8200 Should not be called while simulating the 8200."))
          (repeatwhile (LOGAND byte 4096)=0 do byte←(READPRINTERPORT))
          (for i to 30
	     do (repeatwhile (LOGAND byte 2048)=0 do byte←(READPRINTERPORT))
		((ELT array i)←(LSH (LOGAND 1 byte)
				    7)+(LSH (LOGAND 2 byte)
					    5)+(LSH (LOGAND 4 byte)
						    3)+(LSH (LOGAND 8 byte)
							    1)+(LSH (LOGAND 16 byte)
								    -1)+(LSH (LOGAND 32 byte)
									     -3)+(LSH (LOGAND 64 byte)
										      -5)+(LSH
		   (LOGAND 128 byte)
		   -7)+ 0)
		(until (LOGAND (READPRINTERPORT)
			       2048)=0))
          (if (ELT array 30)=2
	      then (repeatwhile (LOGAND byte 4096)=0 do byte←(READPRINTERPORT))
		   (for i to 18
		      do (repeatwhile (LOGAND byte 2048)=0 do byte←(READPRINTERPORT))
			 (if i gt 15
			     then ((ELT array i)←(LOGOR (ELT array i)
							(LSH (LOGAND 1 byte)
							     7)+(LSH (LOGAND 2 byte)
								     5)+(LSH (LOGAND 4 byte)
									     3)+(LSH (LOGAND 8 byte)
										     1)+(LSH
							  (LOGAND 16 byte)
							  -1)+(LSH (LOGAND 32 byte)
								   -3)+(LSH (LOGAND 64 byte)
									    -5)+(LSH (LOGAND 128 byte)
										     -7)+ 0)))
			 (until (LOGAND (READPRINTERPORT)
					2048)=0)))
          (RETURN (for i to 30 collect (ELT array i])

(SimulateServerPush8200Button
  [LAMBDA (button)                                           (* edited: " 7-SEP-83 10:02")
                                                             (* Update the machineState inside of the JobState by 
							     accessing the array directly.)

          (* Send a signal to the "8200" that will have the effect of pushing the panel button specified by "button". 
"button" can be an integer 0,1,...,9, one of the globally specified buttons (e.g., CopyModeButton), or one of the atoms 
	  Blank, Clear, Copy, CopyMode, Output, PaperTray, Reduction, StartPrint, or StopPrint.)


    (PROG (ms (fetch machineState of JobState))
          (SELECTQ button
		   (1 2048)
		   (2 2049)
		   (3 2050)
		   (4 2051)
		   (5 2052)
		   (6 2053)
		   (7 2054)
		   (8 2055)
		   (9 1024)
		   (0 1032)
		   ((Blank BlankButton)
		     1040)
		   ((StartPrint StartPrintButton)
		     1048)
		   ((StopPrint StopPrintButton)
		     1056)
		   ((Copy CopyButton)
		     1064)
		   ((CopyMode CopyModeButton)
		     1072)
		   ((Reduction ReductionButton)
		     1080)
		   ((Clear ClearButton)
		     512)
		   ((PaperTray PaperTrayButton)
		     576)
		   ((Output OutputButton)
		     640)
		   (PROG [(fix (FIXSPELL button NIL
					 (QUOTE (Blank StartPrint StopPrint Copy CopyMode Reduction 
						       Clear PaperTray Output BlankButton 
						       StartPrintButton StopPrintButton CopyButton 
						       CopyModeButton ReductionButton ClearButton 
						       PaperTrayButton OutputButton]
		         (RETURN (if fix
				     then (Push8200Button fix)
				   else (HELP "Unknown arg to SimulateServerPush8200Button" button])

(Simulate8200StateChange
  [LAMBDA (array button)                                     (* JG "29-Jan-84 22:12")
                                                             (* Simulate the state changes of the 8200.0 This is 
							     called from UpdateMachineState and from 
							     PushSimulated8200Button)
    (PROG NIL
          (DECLARE (USEDFREE JobState))                      (* Catch the initial time thru and set up a dummy 
							     machine state. Do other initialization as well.)
          (COND
	    ((NULL (fetch machineState of JobState))         (* Initialize the machineState array here!)
	      (replace machineState of JobState with (ARRAY 30 NIL 0))
                                                             (* This set the output button to be 
							     (QUOTE CollatedUnstapled))
                                                             (* This also sets the PaperTray button to be 
							     (QUOTE Bottom))
	      (SETA (fetch machineState of JobState)
		    15
		    (PLUS 1 16))

          (* This sets both the CopyButton and the CopyMode button. CopyButton is set to (QUOTE Normal) and CopyModeButton 
	  is set to (QUOTE OneSidedCopies))


	      (SETA (fetch machineState of JobState)
		    17
		    (PLUS 32 4))                             (* This sets the ReductionButton to be FulSize)
	      (SETA (fetch machineState of JobState)
		    16 16)))

          (* If there are reasons why the machine is NotReady, check them again. If those conditions no longer hold, then 
	  remove them from the list of NotReadyReasons.)


          [COND
	    (NotReadyReasons (COND
			       ((NOT (EVAL (CAR NotReadyReasons)))
				 (replace State of JobState with 'Ready)
				 (SETQ NotReadyReasons (CDR NotReadyReasons]
          (UpdateStatusWindow)                               (* Component control for a simulated machine is nonsense
							     -- Don%'t simulate it.)
          [COND
	    ((EQ (fetch State of JobState)
		 'ComponentControl)
	      (replace State of JobState with 'Ready]        (* Set up the machine state when the user presses the 
							     Start button)
          [COND
	    ((EQUAL button 'StartPrint)
	      (SetBit array 19 64)
	      (replace State of JobState with 'Print]        (* terminate the printing ...)
          [COND
	    ((AND (EQUAL 0 (fetch numberOfCopiesSelected of JobState))
		  (EQUAL (fetch State of JobState)
			 'Printing))
	      (replace CopiesMade of JobState with T)
	      (replace State of JobState with 'Ready]        (* Subtract one copy from the total needed to be created
							     each cycle through the Simulator.)
          (COND
	    ((AND (NUMBERP (fetch numberOfCopiesSelected of JobState))
		  (GREATERP (fetch numberOfCopiesSelected of JobState)
			    0)
		  (EQUAL (fetch State of JobState)
			 'Printing))
	      (replace numberOfCopiesSelected of JobState with (SUB1 (fetch numberOfCopiesSelected
									of JobState)))
                                                             (* Simulate the 1/2 second wait for a copy to be made.)
	      (DISMISS 500)))                                (* Simulate the effect of pressing the CopyMode button)
          [COND
	    ((EQ button 'CopyModeButton)
	      (SELECTQ (fetch CopyMode of JobState)
		       (OneSidedCopies (PRINT "OneSidedCopies -> TwoSidedCopies")
                                                             (* turn off the bit that says OneSidedCopies)
				       (SetBitOff (fetch machineState of JobState)
						  17 4)      (* turn on the bit that says TwoSidedCopies)
				       (SetBit (fetch machineState of JobState)
					       17 1))
		       (TwoSidedCopies (PRINT "TwoSidedCopies -> TwoSidedOriginalsAndCopies")
                                                             (* turn off bit TwoSidedCopies)
				       (SetBitOff (fetch machineState of JobState)
						  17 1)      (* Turn on the bit that means 
							     TwoSidedCopiesAndOriginals)
				       (SetBit (fetch machineState of JobState)
					       15 4))
		       (TwoSidedCopiesAndOriginals (PRINT 
						   "TwoSidedCopiesAndOriginals -> OneSidedCopies")
                                                             (* turn off the bit that says TwoSidedCopiesAndOriginals
							     and ...)
						   (SetBitOff (fetch machineState of JobState)
							      15 4)
                                                             (* turn ON the bit that says OneSidedCopies)
						   (SetBit (fetch machineState of JobState)
							   17 4))
		       (HELP 
		     "Error in Simulate8200StateChange -- CopyModeButton of JobState is nonsense"]
          [COND
	    ((EQ button 'OutputButton)
	      (SELECTQ (fetch OutputButton of JobState)
		       (CollatedStapled (PRINT "CollatedStapled -> Uncollated")
                                                             (* turn off the bit that says CollatedStapled)
					(SetBitOff (fetch machineState of JobState)
						   15 128)   (* turn on the bit that says Uncollated)
					(SetBit (fetch machineState of JobState)
						15 2))
		       (Uncollated (PRINT "Uncollated -> CollatedStapled")
                                                             (* turn off bit Uncollated)
				   (SetBitOff (fetch machineState of JobState)
					      15 2)          (* Turn on the bit that means CollatedStapled)
				   (SetBit (fetch machineState of JobState)
					   15 1))
		       (CollatedUnstapled (PRINT "Uncollated -> CollatedStapled")
                                                             (* turn off the bit that says CollatedUnstapled and ...)
					  (SetBitOff (fetch machineState of JobState)
						     15 1)   (* turn ON the bit that says collatedStapled)
					  (SetBit (fetch machineState of JobState)
						  15 128))
		       (HELP 
		       "Error in Simulate8200StateChange -- OutputButton of JobState is nonsense"]
                                                             (* Simulate the effect of the Reduction button)
          [COND
	    ((EQ button 'ReductionButton)
	      (SELECTQ (fetch ReductionButton of JobState)
		       (FullSize (PRINT "Full Size -> 98 ")
                                                             (* turn off the bit that says FullSize)
				 (SetBitOff (fetch machineState of JobState)
					    16 16)           (* turn on the bit that says 98)
				 (SetBit (fetch machineState of JobState)
					 16 8))
		       (98 (PRINT "98 -> 74")                (* turn off bit 98 percent)
			   (SetBitOff (fetch machineState of JobState)
				      16 8)                  (* Turn on the bit that means 74 percent)
			   (SetBit (fetch machineState of JobState)
				   16 4))
		       (74 (PRINT "74 -> 65")                (* turn off the bit that says 74 and ...)
			   (SetBitOff (fetch machineState of JobState)
				      16 4)                  (* turn ON the bit that says 65)
			   (SetBit (fetch machineState of JobState)
				   16 2))
		       (74 (PRINT "65 -> FullSize")          (* turn off the bit that says 65 and ...)
			   (SetBitOff (fetch machineState of JobState)
				      16 2)                  (* turn ON the bit that says FullSize)
			   (SetBit (fetch machineState of JobState)
				   16 16))
		       (HELP 
		    "Error in Simulate8200StateChange -- ReductionButton of JobState is nonsense"]
                                                             (* Do some error checks)
                                                             (* If the RDH and the document cover are open, then the 
							     machine is NOT READY)
          [COND
	    ((AND (Get8200 (fetch machineState of JobState)
			   'RDHOpen)
		  (EQ (Get8200 (fetch machineState of JobState)
			       'CloseDocumentCover)
		      'off))                                 (* Make the state of the machine NotReady)
	      (replace State of JobState with 'NotReady)
	      (SETQ NotReadyReasons '((AND (Get8200 (fetch machineState of JobState)
						    'RDHOpen)
					   (EQ (Get8200 (fetch machineState of JobState)
							'CloseDocumentCover)
					       'off]
      NIL])
)

(RPAQQ 8200SERVERMACROS (Clear8200))
(DECLARE: EVAL@COMPILE 

(PUTPROPS Clear8200 MACRO (NIL (PROGN (DISMISS 100)
				      (WRITEPRINTERPORT 256)
				      (DISMISS 100))))
)

(RPAQQ Simulate8200 NIL)
(LOAD? 'EVALSERVER.DCOM)
(DECLARE: DONTCOPY
  (FILEMAP (NIL (549 14434 (ServerPush8200Button 559 . 2128) (ServerRead8200 2130 . 4082) (
SimulateServerPush8200Button 4084 . 5787) (Simulate8200StateChange 5789 . 14432)))))
STOP