(FILECREATED "16-Feb-86 00:11:13" {ERIS}<LISPCORE>LIBRARY>BUSCOLOR.;7 13251  

      changes to:  (FNS \BUSCOLOR.UPDATEDAEMON)
                   (VARS \BUSCOLOR.LOCKEDFNS BUSCOLORCOMS)

      previous date: "10-Feb-86 12:31:55" {ERIS}<LISPCORE>LIBRARY>BUSCOLOR.;4)


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

(PRETTYCOMPRINT BUSCOLORCOMS)

(RPAQQ BUSCOLORCOMS ((* BUSCOLOR -- Update daemon for the BUSMASTER color cards -- By Kelly Roach 
                            and Herb Jellinek. *)
                         (FNS \BUSCOLOR.INIT)
                         (FNS \BUSCOLOR.STARTCOLOR \BUSCOLOR.STOPCOLOR)
                         (FNS \REMOVE.PERIODIC.INTERRUPT \INSTALL.PERIODIC.INTERRUPT)
                         (P (MOVD? (FUNCTION NILL)
                                   (FUNCTION \BUSCOLOR.SENDPAGE)))
                         (FNS \BUSCOLOR.BITMAPPAGES \BUSCOLOR.BITMAPWORDS \BUSCOLOR.DIRTYPAGEP 
                              \BUSCOLOR.MAKECLEANPAGE \BUSCOLOR.MAKEDIRTYPAGE \BUSCOLOR.UPDATEDAEMON 
                              \BUSCOLOR.EVENTFN)
                         (MACROS \BUSCOLOR.DIRTYPAGEP)
                         (CONSTANTS \VMAP.NOTDIRTY)
                         (PROP ARGNAMES \BUSBLTOUTBYTES)
                         (FILES BUSMASTER COLOR)
                         (DECLARE: DOEVAL@LOAD DONTEVAL@COMPILE DONTCOPY (FILES (LOADFROM)
                                                                                LLFAULT BUSMASTER))
                         (VARS \BUSCOLOR.LOCKEDFNS \BUSCOLOR.LOCKEDVARS)
                         (DECLARE: DONTEVAL@LOAD DONTEVAL@COMPILE DOCOPY (P (\BUSCOLOR.INIT)))))



(* BUSCOLOR -- Update daemon for the BUSMASTER color cards -- By Kelly Roach and Herb 
Jellinek. *)

(DEFINEQ

(\BUSCOLOR.INIT
  (LAMBDA NIL                                                (* kbr: " 1-Jul-85 18:19")
    (for FN in \BUSCOLOR.LOCKEDFNS do (\LOCKFN FN))
    (for VAR in \BUSCOLOR.LOCKEDVARS do (\LOCKVAR VAR))))
)
(DEFINEQ

(\BUSCOLOR.STARTCOLOR
  (LAMBDA (FDEV)                                                          (* kbr: 
                                                                          "10-Feb-86 12:01")
                                                                          (* turns on the color 
                                                                          display and allocates 
                                                                          color screen bitmap.
                                                                          *)
    (DECLARE (GLOBALVARS ColorScreenBitMap ColorScreenBitMapBase ColorScreenBitMapEnd 
                    ColorScreenBitMapEndPage ColorScreenBitMapBasePage ColorScreenBitMapPages 
                    \BUSCOLOR.MOVELIMIT \BUSCOLOR.LASTMOVEDPAGE \PERIODIC.INTERRUPT.FREQUENCY))
    (PROG (DISPLAYSTATE WSOPS)
          (COND
             ((EQ (MACHINETYPE)
                  (QUOTE DANDELION))
              (SETQ DISPLAYSTATE (fetch (FDEV DEVICEINFO) of FDEV))
              (SETQ WSOPS (fetch (FDEV WINDOWOPS) of FDEV))
              (replace (DISPLAYSTATE ONOFF) of DISPLAYSTATE with (QUOTE STARTCOLOR))
              (APPLY* (fetch (WSOPS STARTBOARD) of WSOPS))
              (MOVD (fetch (WSOPS SENDPAGE) of WSOPS)
                    (FUNCTION \BUSCOLOR.SENDPAGE))
              (MOVD (fetch (WSOPS PILOTBITBLT) of WSOPS)
                    (FUNCTION \SOFTCURSORPILOTBITBLT))                    (* Lock down memory for 
                                                                          the color screen bitmap.
                                                                          *)
              (SETQ ColorScreenBitMapBase (fetch (BITMAP BITMAPBASE) of ColorScreenBitMap))
              (SETQ.NOREF ColorScreenBitMapEnd (\ADDBASE ColorScreenBitMapBase (\BUSCOLOR.BITMAPWORDS 
                                                                                    ColorScreenBitMap
                                                                                      )))
              (SETQ ColorScreenBitMapEndPage (fetch (POINTER PAGE#) of ColorScreenBitMapEnd))
              (SETQ ColorScreenBitMapBasePage (fetch (POINTER PAGE#) of ColorScreenBitMapBase))
              (SETQ ColorScreenBitMapPages (\BUSCOLOR.BITMAPPAGES ColorScreenBitMap))
              (\LOCKPAGES ColorScreenBitMapBase ColorScreenBitMapPages)
              (SETQ \BUSCOLOR.MOVELIMIT 100)                              (* move no more than 100 
                                                                          pages per go-round of 
                                                                          \BUSCOLOR.UPDATEDAEMON)
              (SETQ \BUSCOLOR.LASTMOVEDPAGE 0)                            (* do update every 10 / 
                                                                          77 of a sec)
              (SETQ \PERIODIC.INTERRUPT.FREQUENCY 10)
              (for PAGE from ColorScreenBitMapBasePage to ColorScreenBitMapEndPage
                 do (\BUSCOLOR.MAKEDIRTYPAGE PAGE))
              (\INSTALL.PERIODIC.INTERRUPT (FUNCTION \BUSCOLOR.UPDATEDAEMON))
              (replace (DISPLAYSTATE ONOFF) of DISPLAYSTATE with (QUOTE ON)))))))

(\BUSCOLOR.STOPCOLOR
  (LAMBDA (FDEV)                                                          (* kbr: 
                                                                          "10-Feb-86 12:08")
                                                                          (* turns the color 
                                                                          display off)
    (PROG (DISPLAYSTATE)
          (SETQ DISPLAYSTATE (fetch (FDEV DEVICEINFO) of FDEV))
          (replace (DISPLAYSTATE ONOFF) of DISPLAYSTATE with (QUOTE STOPCOLOR))
          (\REMOVE.PERIODIC.INTERRUPT (FUNCTION \BUSCOLOR.UPDATEDAEMON))
          (for PAGE from ColorScreenBitMapBasePage to ColorScreenBitMapEndPage
             do (\BUSCOLOR.MAKEDIRTYPAGE PAGE))
          (\UNLOCKPAGES ColorScreenBitMapBase ColorScreenBitMapPages)
          (replace (DISPLAYSTATE ONOFF) of DISPLAYSTATE with (QUOTE OFF)))))
)
(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))))
)
(MOVD? (FUNCTION NILL)
       (FUNCTION \BUSCOLOR.SENDPAGE))
(DEFINEQ

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

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

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

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

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

(\BUSCOLOR.UPDATEDAEMON
  (LAMBDA NIL                                                         (* kbr: 
                                                                          "16-Feb-86 00:04")
                                                                          (* Runs under periodic 
                                                                          interrupt; flushes 
                                                                          changed pages in local 
                                                                          copy of PC framebuffer 
                                                                          out to PC *)
    (DECLARE (GLOBALVARS \BUSCOLOR.LASTMOVEDPAGE \BUSCOLOR.MOVELIMIT))
    (COND
       (\INTERRUPTABLE (UNINTERRUPTABLY
                           (\REMOVE.PERIODIC.INTERRUPT (FUNCTION \BUSCOLOR.UPDATEDAEMON))
                           (PROG (PAGESMOVED CURRPAGE ABSCURRPAGE)
                                 (SETQ CURRPAGE \BUSCOLOR.LASTMOVEDPAGE)
                                 (SETQ PAGESMOVED 0)
                                 (until (EQ (SETQ CURRPAGE (ADD1 CURRPAGE))
                                                ColorScreenBitMapPages)
                                    do (SETQ ABSCURRPAGE (IPLUS ColorScreenBitMapBasePage 
                                                                    CURRPAGE))
                                          (COND
                                             ((\BUSCOLOR.DIRTYPAGEP ABSCURRPAGE)
                                              (\BUSCOLOR.SENDPAGE (create POINTER
                                                                         PAGE# ← ABSCURRPAGE)
                                                     CURRPAGE)
                                              (\BUSCOLOR.MAKECLEANPAGE ABSCURRPAGE)
                                              (SETQ PAGESMOVED (ADD1 PAGESMOVED))
                                              (COND
                                                 ((EQ PAGESMOVED \BUSCOLOR.MOVELIMIT)
                                                  (RETURN))))) finally (SETQ CURRPAGE -1))
                                 (SETQ \BUSCOLOR.LASTMOVEDPAGE CURRPAGE))
                           (\INSTALL.PERIODIC.INTERRUPT (FUNCTION \BUSCOLOR.UPDATEDAEMON)))))))

(\BUSCOLOR.EVENTFN
  (LAMBDA (DEVICE EVENT)                                     (* kbr: "15-Jul-85 14:34")

          (* * 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
      ((EQ (fetch (DISPLAYSTATE ONOFF) of (fetch (FDEV DEVICEINFO) of DEVICE))
	   (QUOTE ON))
	(SELECTQ EVENT
		 ((BEFORELOGOUT BEFORESYSOUT BEFOREMAKESYS)
                                                             (* turn off display since we may awake on different 
							     machine)
                                                             (* will disable interrupt and thus avoid race 
							     condition)
		   (COLORDISPLAY (QUOTE OFF)))
		 (BEFORESAVEVM (\REMOVE.PERIODIC.INTERRUPT (QUOTE \BUSCOLOR.UPDATEDAEMON))
			       (for PAGE from ColorScreenBitMapBasePage to ColorScreenBitMapEndPage
				  do (\BUSCOLOR.MAKEDIRTYPAGE PAGE)))
		 ((AFTERLOGOUT AFTERSYSOUT AFTERMAKESYS)

          (* TBW: Implement these in a way that is color board and MACHINETYPE independent. Take into account that machine 
	  user has moved to may not have a color display or that the of color display has changed. Some changes may cause 
	  fields of FDEV to swap out. *)


		   NIL)
		 ((AFTERSAVEVM AFTERDOSAVEVM)
		   (SCREENCOLORMAP (SCREENCOLORMAP))
		   (for PAGE from ColorScreenBitMapBasePage to ColorScreenBitMapEndPage
		      do (\BUSCOLOR.MAKEDIRTYPAGE PAGE))
		   (\INSTALL.PERIODIC.INTERRUPT (QUOTE \BUSCOLOR.UPDATEDAEMON)))
		 NIL)))))
)
(DECLARE: EVAL@COMPILE 
(PUTPROPS \BUSCOLOR.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)
(DECLARE: DOEVAL@LOAD DONTEVAL@COMPILE DONTCOPY 
(FILESLOAD (LOADFROM)
       LLFAULT BUSMASTER)
)

(RPAQQ \BUSCOLOR.LOCKEDFNS (\BUSCOLOR.UPDATEDAEMON \REMOVE.PERIODIC.INTERRUPT \BUSCOLOR.SENDPAGE 
                                      \BUSCOLOR.MAKECLEANPAGE \INSTALL.PERIODIC.INTERRUPT PCBUS.WRITE 
                                      PCBUS.WRITEHL))

(RPAQQ \BUSCOLOR.LOCKEDVARS (ColorScreenBitMapPages ColorScreenBitMapBasePage \BUSCOLOR.MOVELIMIT 
                                       \BUSCOLOR.LASTMOVEDPAGE))
(DECLARE: DONTEVAL@LOAD DONTEVAL@COMPILE DOCOPY 
(\BUSCOLOR.INIT)
)
(PUTPROPS BUSCOLOR COPYRIGHT ("Xerox Corporation" 1985 1986))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1782 2047 (\BUSCOLOR.INIT 1792 . 2045)) (2048 6186 (\BUSCOLOR.STARTCOLOR 2058 . 5289) (
\BUSCOLOR.STOPCOLOR 5291 . 6184)) (6187 6666 (\REMOVE.PERIODIC.INTERRUPT 6197 . 6426) (
\INSTALL.PERIODIC.INTERRUPT 6428 . 6664)) (6728 12124 (\BUSCOLOR.BITMAPPAGES 6738 . 7008) (
\BUSCOLOR.BITMAPWORDS 7010 . 7244) (\BUSCOLOR.DIRTYPAGEP 7246 . 7424) (\BUSCOLOR.MAKECLEANPAGE 7426 . 
7644) (\BUSCOLOR.MAKEDIRTYPAGE 7646 . 7860) (\BUSCOLOR.UPDATEDAEMON 7862 . 10239) (\BUSCOLOR.EVENTFN 
10241 . 12122)))))
STOP