(FILECREATED "20-May-85 18:53:50" {ERIS}<LISPCORE>LIBRARY>COLORNNGS.;8 15135  

      changes to:  (VARS COLORNNGSCOMS \COLORNNGS.LOCKEDVARS \COLORNNGS.LOCKEDFNS \DDLCOLOR.LOCKEDFNS)
		   (FNS \COLORNNGS.STARTCOLOR \COLORNNGS.SENDCOLORMAPENTRY \COLORNNGS.SENDPAGE 
			\COLORNNGS.UPDATEDAEMON \COLORNNGS.EVENTFN \DANDELIONUFOINITCOLOR NNGS.INIT 
			\DANDELION\STARTCOLOR \DANDELION\STOPCOLOR \DANDELION\SETSCREENCOLORMAP 
			\DANDELIONCOLORLEVEL \DANDELION\CONVERTCOLORMAPENTRY \DANDELIONROTATECOLORMAP 
			\DDLCOLOR.LOCKFNS PCSENDCOLORMAPENTRY \DANDELIONUFO.UPDATEDAEMON 
			\UFOCOLOR.EVENTFN \DANDELION\INITCOLORS \COLORNNGS.CMD \COLORNNGS.DEMO 
			\COLORNNGS.INITCOLOR \COLORNNGS.EXTRACTCOLORINTENSITY \COLORNNGS.STOPCOLOR 
			\COLORNNGS.SETSCREENCOLORMAP \COLORNNGS.COLORLEVEL 
			\COLORNNGS.CONVERTCOLORMAPENTRY \COLORNNGS.WRITELUT \COLORNNGS.ROTATECOLORMAP 
			\COLORNNGS.LOCKFNS \COLORNNGS.LOCKPAGES \REMOVE.PERIODIC.INTERRUPT 
			\INSTALL.PERIODIC.INTERRUPT \BITMAPPAGES \BitmapWords \DIRTYPAGEP 
			\MAKECLEANPAGE \MAKEDIRTYPAGE \COLORNNGS.INITCOLORS \RochesterWritePage)
		   (PROPS (\BUSBLTOUTBYTES ARGNAMES))

      previous date: "20-May-85 18:02:10" {ERIS}<LISPCORE>LIBRARY>COLORNNGS.;7)


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

(PRETTYCOMPRINT COLORNNGSCOMS)

(RPAQQ COLORNNGSCOMS ((* COLORNNGS -- Driver for the NNGS color card -- By Kelly Roach. *)
		      (FNS \COLORNNGS.CMD \COLORNNGS.DEMO)
		      (FNS \COLORNNGS.INITCOLOR)
		      (FNS \COLORNNGS.STARTCOLOR \COLORNNGS.STOPCOLOR \COLORNNGS.SENDCOLORMAPENTRY)
		      (FNS \COLORNNGS.LOCKFNS \COLORNNGS.LOCKPAGES)
		      (FNS \REMOVE.PERIODIC.INTERRUPT \INSTALL.PERIODIC.INTERRUPT)
		      (FNS \COLORNNGS.SENDPAGE)
		      (FNS \BITMAPPAGES \BitmapWords \DIRTYPAGEP \MAKECLEANPAGE \MAKEDIRTYPAGE 
			   \COLORNNGS.UPDATEDAEMON \COLORNNGS.EVENTFN \COLORNNGS.INITCOLORS)
		      (MACROS \DIRTYPAGEP)
		      (CONSTANTS \VMAP.NOTDIRTY)
		      (PROP ARGNAMES \BUSBLTOUTBYTES)
		      (FILES BUSMASTER)
		      (VARS \COLORNNGS.LOCKEDFNS \COLORNNGS.LOCKEDVARS)
		      (P (\COLORNNGS.LOCKFNS))
		      (DECLARE: DONTEVAL@COMPILE DOCOPY (P (\COLORNNGS.INITCOLOR)
							   (\CREATEDISPLAY (QUOTE COLORNNGSDISPLAY)
									   \COLORNNGSWSOPS 
									   \COLORNNGSWSDATA
									   (FUNCTION 
									       \COLORNNGS.EVENTFN)))))
)



(* COLORNNGS -- Driver for the NNGS color card -- By Kelly Roach. *)

(DEFINEQ

(\COLORNNGS.CMD
  (LAMBDA (ARG RESETFLG)
    (OR RESETFLG (until (EQ 0 (LOGAND 2 (BUS.READHL 12 0)))))
    (BUS.WRITEHL 12 1 (CAR ARG))
    (for X in (CDR ARG)
       do (until (EQ 0 (LOGAND 2 (BUS.READHL 12 0))))
	  (BUS.WRITEHL 12 0 X))))

(\COLORNNGS.DEMO
  (LAMBDA NIL
    (for I from 0 to 511 do (for J from 0 to 127 do (BUS.WRITEHL 10 (PLUS (TIMES 512 J)
									  I)
								 I)))
    (FOR I FROM 0 TO 255
       DO (BUS.WRITEHL 12 (PLUS 256 I)
		       I)
	  (BUS.WRITEHL 12 (PLUS 512 I)
		       I)
	  (BUS.WRITEHL 12 (PLUS 768 I)
		       I))))
)
(DEFINEQ

(\COLORNNGS.INITCOLOR
  (LAMBDA NIL                                                (* edited: "20-May-85 16:11")
    (DECLARE (GLOBALVARS \COLORNNGSWSOPS \COLORNNGSWSDATA))
    (SETQ \COLORNNGSWSOPS (create WSOPS
				  WSCHANGEBACKGROUND ←(FUNCTION COLORBACKGROUND)
				  WSCHANGEBACKGROUNDBORDER ←(FUNCTION NILL)
				  WSDISPLAYHEIGHT ←(FUNCTION NILL)
				  STARTCOLOR ←(FUNCTION \COLORNNGS.STARTCOLOR)
				  STOPCOLOR ←(FUNCTION \COLORNNGS.STOPCOLOR)
				  SETSCREENCOLORMAP ←(FUNCTION \COLORNNGS.SETSCREENCOLORMAP)
				  COLORLEVEL ←(FUNCTION \COLORNNGS.COLORLEVEL)
				  ROTATECOLORMAP ←(FUNCTION \COLORNNGS.ROTATECOLORMAP)))
    (SETQ \COLORNNGSWSDATA
      (create WSDATA
	      WSREGION ←(create REGION
				LEFT ← 0
				BOTTOM ← 0
				WIDTH ← 512
				HEIGHT ← 480)))))
)
(DEFINEQ

(\COLORNNGS.STARTCOLOR
  (LAMBDA (DISPLAY COLORMAP PTRTOBITS)                       (* edited: "20-May-85 18:50")
                                                             (* turns on the color display with a given colormap and
							     pointer to the screen bitmap.)
    (DECLARE (GLOBALVARS ColorScreenBitMap ColorScreenBitMapBase ColorScreenBitMapEnd 
			 ColorScreenBitMapEndPage ColorScreenBitMapBasePage ColorScreenBitMapPages 
			 \COLORNNGS.MOVELIMIT \COLORNNGS.LASTMOVEDPAGE \PERIODIC.INTERRUPT.FREQUENCY))
    (\COLORNNGS.INITCOLORS)
    (SETQ ColorScreenBitMapBase (fetch (BITMAP BITMAPBASE) of ColorScreenBitMap))
    (SETQ ColorScreenBitMapEnd (\ADDBASE ColorScreenBitMapBase (\BitmapWords ColorScreenBitMap)))
    (SETQ ColorScreenBitMapEndPage (fetch (POINTER PAGE#) of ColorScreenBitMapEnd))
    (SETQ ColorScreenBitMapBasePage (fetch (POINTER PAGE#) of ColorScreenBitMapBase))
    (SETQ ColorScreenBitMapPages (\BITMAPPAGES ColorScreenBitMap))
    (\TEMPLOCKPAGES ColorScreenBitMapBase ColorScreenBitMapPages)
    (SETQ \COLORNNGS.MOVELIMIT 20)                           (* move no more than 20 pages per go-round of 
							     \DDLCOLOR.UPDATEDAEMON)
    (SETQ \COLORNNGS.LASTMOVEDPAGE 0)
    (SETQ \PERIODIC.INTERRUPT.FREQUENCY 10)                  (* do update every 10 / 77 of a sec)
    (\INSTALL.PERIODIC.INTERRUPT (FUNCTION \COLORNNGS.UPDATEDAEMON))))

(\COLORNNGS.STOPCOLOR
  (LAMBDA (DISPLAY)                                          (* edited: "20-May-85 16:09")
                                                             (* turns the color display off unlocks the colormap and
							     clobbers it.)
    (COND
      ((COLORMAPP \SystemColorMap)
	(\UNLOCKPAGES \SystemColorMap 1)                     (* should turn color map to black 
							     (SCREENCOLORMAP BLACKMAP))
	(\REMOVE.PERIODIC.INTERRUPT (FUNCTION \COLORNNGS.UPDATEDAEMON))))
    (replace (DISPLAYSTATE RUNNING?) of (fetch (FDEV DEVICEINFO) of DISPLAY) with NIL)))

(\COLORNNGS.SENDCOLORMAPENTRY
  (LAMBDA (COLOR# RGB)                                       (* edited: "20-May-85 18:27")
    (PROG NIL
          (BUS.WRITEHL 12 (IPLUS 256 COLOR#)
		       (fetch (RGB RED) of RGB))
          (BUS.WRITEHL 12 (IPLUS 512 COLOR#)
		       (fetch (RGB GREEN) of RGB))
          (BUS.WRITEHL 12 (IPLUS 768 COLOR#)
		       (fetch (RGB BLUE) of RGB)))))
)
(DEFINEQ

(\COLORNNGS.LOCKFNS
  (LAMBDA NIL                                                (* edited: "20-May-85 16:16")
    (for FN in \COLORNNGS.LOCKEDFNS do (\LOCKFN FN))
    (for VAR in \COLORNNGS.LOCKEDVARS do (\LOCKVAR VAR))))

(\COLORNNGS.LOCKPAGES
  (LAMBDA NIL                                                (* hdj "16-Nov-84 16:10")
    (\TEMPLOCKPAGES ColorScreenBitMapBase ColorScreenBitMapPages)))
)
(DEFINEQ

(\REMOVE.PERIODIC.INTERRUPT
  (LAMBDA (INTERRUPT)
    (DECLARE (GLOBALVARS \PERIODIC.INTERRUPT))               (* hdj "31-Oct-84 17:08")
    (PROG1 \PERIODIC.INTERRUPT (SETQ \PERIODIC.INTERRUPT NIL))))

(\INSTALL.PERIODIC.INTERRUPT
  (LAMBDA (INTERRUPT)
    (DECLARE (GLOBALVARS \PERIODIC.INTERRUPT))               (* hdj "31-Oct-84 17:08")
    (PROG1 \PERIODIC.INTERRUPT (SETQ \PERIODIC.INTERRUPT INTERRUPT))))
)
(DEFINEQ

(\COLORNNGS.SENDPAGE
  (LAMBDA (AbsCurrPage CurrPageInBitMap)                     (* edited: "20-May-85 18:32")
    (BUS.WRITEHL 12 1797 (COND
		   ((EQ (LOGAND CurrPageInBitMap 128)
			0)
		     0)
		   (T 255)))
    (BUS.WRITEHL 12 1798 (COND
		   ((EQ (LOGAND CurrPageInBitMap 256)
			0)
		     0)
		   (T 255)))
    (\BUSBLTOUTBYTES (create POINTER
			     PAGE# ← AbsCurrPage)
		     10
		     (LLSH (LOGAND CurrPageInBitMap 127)
			   9)
		     WORDSPERPAGE)))
)
(DEFINEQ

(\BITMAPPAGES
  (LAMBDA (BITMAP)                                           (* hdj "23-Oct-84 11:47")
    (FOLDHI (ITIMES (fetch (BITMAP BITMAPRASTERWIDTH) of BITMAP)
		    (fetch (BITMAP BITMAPHEIGHT) of BITMAP))
	    WORDSPERPAGE)))

(\BitmapWords
  (LAMBDA (BM)                                               (* hdj "23-Oct-84 15:56")
    (ITIMES (fetch (BITMAP BITMAPRASTERWIDTH) of BM)
	    (fetch (BITMAP BITMAPHEIGHT) of BM))))

(\DIRTYPAGEP
  (LAMBDA (VPAGE)                                            (* hdj "19-Oct-84 12:31")
    (fetch (VMEMFLAGS DIRTY) of (\READFLAGS VPAGE))))

(\MAKECLEANPAGE
  (LAMBDA (VPAGE)                                            (* hdj "18-Oct-84 18:26")
    (\WRITEMAP VPAGE (\READRP VPAGE)
	       (LOGAND \VMAP.NOTDIRTY (\READFLAGS VPAGE)))))

(\MAKEDIRTYPAGE
  (LAMBDA (VPAGE)                                            (* hdj "18-Oct-84 18:27")
    (\WRITEMAP VPAGE (\READRP VPAGE)
	       (LOGOR \VMAP.DIRTY (\READFLAGS VPAGE)))))

(\COLORNNGS.UPDATEDAEMON
  (LAMBDA NIL                                                (* edited: "20-May-85 18:50")

          (* * Runs under periodic interrupt; flushes changed pages in local copy of PC framebuffer out to PC)


    (DECLARE (GLOBALVARS \COLORNNGS.LASTMOVEDPAGE \COLORNNGS.MOVELIMIT))
    (COND
      (\INTERRUPTABLE (PROGN (\REMOVE.PERIODIC.INTERRUPT (FUNCTION \COLORNNGS.UPDATEDAEMON))
			     (PROG (PagesMoved CurrPage StoppingPage LastMovedPage AbsCurrPage)
			           (SETQ PagesMoved 0)
			           (SETQ CurrPage (IREMAINDER (ADD1 \COLORNNGS.LASTMOVEDPAGE)
							      ColorScreenBitMapPages))
			           (SETQ StoppingPage \COLORNNGS.LASTMOVEDPAGE)
			           (SETQ LastMovedPage \COLORNNGS.LASTMOVEDPAGE)
			           (repeatuntil (OR (EQ PagesMoved \COLORNNGS.MOVELIMIT)
						    (EQ CurrPage StoppingPage))
				      do (SETQ AbsCurrPage (IPLUS ColorScreenBitMapBasePage CurrPage))
					 (COND
					   ((\DIRTYPAGEP AbsCurrPage)
					     (\COLORNNGS.SENDPAGE AbsCurrPage CurrPage)
					     (\MAKECLEANPAGE AbsCurrPage)
					     (SETQ PagesMoved (ADD1 PagesMoved))
					     (SETQ LastMovedPage CurrPage)))
					 (SETQ CurrPage (ADD1 CurrPage))
					 (COND
					   ((EQ CurrPage ColorScreenBitMapPages)
					     (SETQ CurrPage 0))))
			           (SETQ \COLORNNGS.LASTMOVEDPAGE LastMovedPage))
			     (\INSTALL.PERIODIC.INTERRUPT (FUNCTION \COLORNNGS.UPDATEDAEMON)))))))

(\COLORNNGS.EVENTFN
  (LAMBDA (DEVICE EVENT)                                     (* edited: "20-May-85 18:50")

          (* * if we are about to SYSOUT, MAKESYS, SAVEVM or LOGOUT we flush all local framebuffer pages to PC and mark all 
	  pages dirty so they get written out to vmem file. We turn off the update agent for the interim to avoid creating a 
	  race condition)



          (* * we only want to do it if the display is turned on, and not merely extant)


    (COND
      ((fetch (DISPLAYSTATE RUNNING?) of (fetch (FDEV DEVICEINFO) of DEVICE))
	(SELECTQ EVENT
		 ((BEFORELOGOUT BEFORESYSOUT BEFOREMAKESYS)
                                                             (* turn off display since we may awake on different 
							     machine)
                                                             (* will disable interrupt and thus avoid race 
							     condition)
		   (COLORDISPLAY NIL)
		   (for PAGE from ColorScreenBitMapBasePage to ColorScreenBitMapEndPage
		      do (\COLORNNGS.SENDPAGE PAGE (IDIFFERENCE PAGE ColorScreenBitMapBasePage))
			 (\MAKEDIRTYPAGE PAGE)))
		 (BEFORESAVEVM (\REMOVE.PERIODIC.INTERRUPT (QUOTE \COLORNNGS.UPDATEDAEMON))
                                                             (* disable interrupt to avoid race condition)
			       (for PAGE from ColorScreenBitMapBasePage to ColorScreenBitMapEndPage
				  do (\COLORNNGS.SENDPAGE PAGE (IDIFFERENCE PAGE 
									ColorScreenBitMapBasePage))
				     (\MAKEDIRTYPAGE PAGE)))
		 (AFTERSAVEVM                                (* lifted from \DisplayEventFn -
							     not sure it makes sense here)
			      (COND
				(\SystemColorMap             (* colordisplay was on. turn it off.
							     User may have moved to machine without color display)
						 (SETQ LastSystemColorMap \SystemColorMap)
						 (SETQ \SystemColorMap NIL)
						 (SETQ \COLORCURSORBM NIL))))
		 ((AFTERDOSYSOUT AFTERDOSAVEVM AFTERDOMAKESYS)
                                                             (* enable interrupt)
		   (\TEMPLOCKPAGES ColorScreenBitMapBase ColorScreenBitMapPages)
		   (SETQ \COLORNNGS.LASTMOVEDPAGE 0)
		   (\INSTALL.PERIODIC.INTERRUPT (QUOTE \COLORNNGS.UPDATEDAEMON)))
		 NIL)))))

(\COLORNNGS.INITCOLORS
  (LAMBDA NIL                                                (* edited: "20-May-85 16:08")
    (BUS.WRITEHL 12 1796 255)
    (BUS.WRITEHL 12 1799 255)
    (\COLORNNGS.CMD (QUOTE (0 31 62 100 8 5 3 240 64))
		    T)
    (\COLORNNGS.CMD (QUOTE (71 64)))
    (\COLORNNGS.CMD (QUOTE (111)))
    (\COLORNNGS.CMD (QUOTE (70 0)))
    (BUS.WRITEHL 12 1792 255)
    (BUS.WRITEHL 12 1793 255)
    (BUS.WRITEHL 12 1794 255)
    (BUS.WRITEHL 12 1795 255)
    (\COLORNNGS.CMD (QUOTE (75 0 192 0)))
    (\COLORNNGS.CMD (QUOTE (112 0 0 0 127)))
    (\COLORNNGS.CMD (QUOTE (120 255 255 255 255 255 255 255 255)))
    (\COLORNNGS.CMD (QUOTE (74 255 255)))
    (for I from 0 to 255
       do (BUS.WRITEHL 12 (IPLUS 256 I)
		       I)
	  (BUS.WRITEHL 12 (IPLUS 512 I)
		       I)
	  (BUS.WRITEHL 12 (IPLUS 768 I)
		       I))
    (\COLORNNGS.CMD (QUOTE (107)))
    (\COLORNNGS.CMD (QUOTE (13)))))
)
(DECLARE: EVAL@COMPILE 

(PUTPROPS \DIRTYPAGEP DMACRO ((VPAGE)
			      (fetch (VMEMFLAGS DIRTY)
				     of
				     (\READFLAGS VPAGE))))
)
(DECLARE: EVAL@COMPILE 

(RPAQQ \VMAP.NOTDIRTY -4097)

(CONSTANTS \VMAP.NOTDIRTY)
)

(PUTPROPS \BUSBLTOUTBYTES ARGNAMES (VMADDR BUSADDRHI BUSADDRLO NWORDS))
(FILESLOAD BUSMASTER)

(RPAQQ \COLORNNGS.LOCKEDFNS (\COLORNNGS.UPDATEDAEMON \REMOVE.PERIODIC.INTERRUPT \COLORNNGS.SENDPAGE 
						     \MAKECLEANPAGE \INSTALL.PERIODIC.INTERRUPT 
						     BUS.WRITE2 BUS.WRITE BUS.WRITEHL))

(RPAQQ \COLORNNGS.LOCKEDVARS (ColorScreenBitMapPages ColorScreenBitMapBasePage \COLORNNGS.MOVELIMIT 
						     \COLORNNGS.LASTMOVEDPAGE))
(\COLORNNGS.LOCKFNS)
(DECLARE: DONTEVAL@COMPILE DOCOPY 
(\COLORNNGS.INITCOLOR)
(\CREATEDISPLAY (QUOTE COLORNNGSDISPLAY)
		\COLORNNGSWSOPS \COLORNNGSWSDATA (FUNCTION \COLORNNGS.EVENTFN))
)
(PUTPROPS COLORNNGS COPYRIGHT ("Xerox Corporation" 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (2420 3147 (\COLORNNGS.CMD 2430 . 2742) (\COLORNNGS.DEMO 2744 . 3145)) (3148 4003 (
\COLORNNGS.INITCOLOR 3158 . 4001)) (4004 6611 (\COLORNNGS.STARTCOLOR 4014 . 5517) (
\COLORNNGS.STOPCOLOR 5519 . 6167) (\COLORNNGS.SENDCOLORMAPENTRY 6169 . 6609)) (6612 7076 (
\COLORNNGS.LOCKFNS 6622 . 6884) (\COLORNNGS.LOCKPAGES 6886 . 7074)) (7077 7556 (
\REMOVE.PERIODIC.INTERRUPT 7087 . 7316) (\INSTALL.PERIODIC.INTERRUPT 7318 . 7554)) (7557 8087 (
\COLORNNGS.SENDPAGE 7567 . 8085)) (8088 14183 (\BITMAPPAGES 8098 . 8359) (\BitmapWords 8361 . 8586) (
\DIRTYPAGEP 8588 . 8757) (\MAKECLEANPAGE 8759 . 8968) (\MAKEDIRTYPAGE 8970 . 9175) (
\COLORNNGS.UPDATEDAEMON 9177 . 10747) (\COLORNNGS.EVENTFN 10749 . 13127) (\COLORNNGS.INITCOLORS 13129
 . 14181)))))
STOP