(FILECREATED " 5-Dec-85 17:56:37" {ERIS}<LISPCORE>LIBRARY>COLORNNGS.;13 14635  

      changes to:  (FNS \COLORNNGS.STARTCOLOR \COLORNNGS.SETSCREENCOLORMAP \COLORNNGS.CMD)
		   (VARS COLORNNGSCOMS)

      previous date: " 5-Dec-85 15:13:27" {ERIS}<LISPCORE>LIBRARY>COLORNNGS.;9)


(* 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.SETSCREENCOLORMAP 
			     \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 COLOR)
			(VARS \COLORNNGS.LOCKEDFNS \COLORNNGS.LOCKEDVARS)
			(P (\COLORNNGS.LOCKFNS))
			(DECLARE: DONTEVAL@COMPILE DOCOPY (P (\COLORNNGS.INITCOLOR)
							     (\CREATEDISPLAY 'COLORNNGSDISPLAY 
									     \COLORNNGSWSOPS 
									     \COLORNNGSWSDATA
									     (FUNCTION 
									       \COLORNNGS.EVENTFN)))))
)



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

(DEFINEQ

(\COLORNNGS.CMD
  (LAMBDA (ARG RESETFLG)                                   (* kbr: " 5-Dec-85 16:35")
    (OR RESETFLG (until (EQ 0 (LOGAND 2 (PCBUS.READHL 12 0)))))
    (PCBUS.WRITEHL 12 1 (CAR ARG))
    (for X in (CDR ARG)
       do (until (EQ 0 (LOGAND 2 (PCBUS.READHL 12 0))))
	    (PCBUS.WRITEHL 12 0 X))))

(\COLORNNGS.DEMO
  (LAMBDA NIL
    (for I from 0 to 511 do (for J from 0 to 127 do (PCBUS.WRITEHL
								      10
								      (PLUS (TIMES 512 J)
									      I)
								      I)))
    (for I from 0 to 255
       do (PCBUS.WRITEHL 12 (PLUS 256 I)
			     I)
	    (PCBUS.WRITEHL 12 (PLUS 512 I)
			     I)
	    (PCBUS.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)                       (* kbr: " 5-Dec-85 17:56")
                                                             (* 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))
    (SCREENCOLORMAP COLORMAP)))

(\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.SETSCREENCOLORMAP
  (LAMBDA (DISPLAY COLORMAP)                                 (* kbr: " 5-Dec-85 17:02")
    (for COLOR from 0 to 255 do (\COLORNNGS.SENDCOLORMAPENTRY COLOR (ELT COLORMAP COLOR)))
    ))

(\COLORNNGS.SENDCOLORMAPENTRY
  (LAMBDA (COLOR# RGB)                                       (* edited: "20-May-85 18:27")
    (PROG NIL
	    (PCBUS.WRITEHL 12 (IPLUS 256 COLOR#)
			     (fetch (RGB RED) of RGB))
	    (PCBUS.WRITEHL 12 (IPLUS 512 COLOR#)
			     (fetch (RGB GREEN) of RGB))
	    (PCBUS.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")
    (PCBUS.WRITEHL 12 1797 (COND
		       ((EQ (LOGAND CurrPageInBitMap 128)
			      0)
			 0)
		       (T 255)))
    (PCBUS.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")
    (PCBUS.WRITEHL 12 1796 255)
    (PCBUS.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)))
    (PCBUS.WRITEHL 12 1792 255)
    (PCBUS.WRITEHL 12 1793 255)
    (PCBUS.WRITEHL 12 1794 255)
    (PCBUS.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 (PCBUS.WRITEHL 12 (IPLUS 256 I)
			     I)
	    (PCBUS.WRITEHL 12 (IPLUS 512 I)
			     I)
	    (PCBUS.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 COLOR)

(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 'COLORNNGSDISPLAY \COLORNNGSWSOPS \COLORNNGSWSDATA (FUNCTION \COLORNNGS.EVENTFN))
)
(PUTPROPS COLORNNGS COPYRIGHT ("Xerox Corporation" 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1476 2324 (\COLORNNGS.CMD 1486 . 1873) (\COLORNNGS.DEMO 1875 . 2322)) (2325 3180 (
\COLORNNGS.INITCOLOR 2335 . 3178)) (3181 6077 (\COLORNNGS.STARTCOLOR 3191 . 4746) (
\COLORNNGS.STOPCOLOR 4748 . 5396) (\COLORNNGS.SETSCREENCOLORMAP 5398 . 5645) (
\COLORNNGS.SENDCOLORMAPENTRY 5647 . 6075)) (6078 6542 (\COLORNNGS.LOCKFNS 6088 . 6350) (
\COLORNNGS.LOCKPAGES 6352 . 6540)) (6543 7022 (\REMOVE.PERIODIC.INTERRUPT 6553 . 6782) (
\INSTALL.PERIODIC.INTERRUPT 6784 . 7020)) (7023 7583 (\COLORNNGS.SENDPAGE 7033 . 7581)) (7584 13700 (
\BITMAPPAGES 7594 . 7855) (\BitmapWords 7857 . 8082) (\DIRTYPAGEP 8084 . 8253) (\MAKECLEANPAGE 8255 . 
8464) (\MAKEDIRTYPAGE 8466 . 8671) (\COLORNNGS.UPDATEDAEMON 8673 . 10243) (\COLORNNGS.EVENTFN 10245 . 
12623) (\COLORNNGS.INITCOLORS 12625 . 13698)))))
STOP