(FILECREATED "25-Oct-84 17:32:23" {ERIS}<LISPCORE>SOURCES>DDLCOLORHAX.;9 11106  

      changes to:  (FNS \DDLCOLOR.UPDATEDAEMON)
		   (VARS DDLCOLORHAXCOMS FILELST)
		   (MACROS .INSTALL.PERIODIC.INTERRUPT .REMOVE.PERIODIC.INTERRUPT)

      previous date: "23-Oct-84 17:53:19" {ERIS}<LISPCORE>SOURCES>DDLCOLORHAX.;8)


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

(PRETTYCOMPRINT DDLCOLORHAXCOMS)

(RPAQQ DDLCOLORHAXCOMS ((FNS \BITMAPPAGES \BaseAddrOfPage \BitmapWords \DIRTYPAGEP \MAKECLEANPAGE 
			     \MAKEDIRTYPAGE \PixelBaseOnPage \PixelsOnPage \UsedWordsOnPage 
			     \DDLCOLOR.INIT \DDLCOLOR.TURNOFF \DDLCOLOR.UPDATEDAEMON 
			     \DDLCOLOR.AROUNDEXITFN)
			(MACROS .INSTALL.PERIODIC.INTERRUPT .REMOVE.PERIODIC.INTERRUPT 
				\BaseAddrOfPage \BitmapWords \PixelBaseOnPage \PixelsOnPage 
				\UsedWordsOnPage \MAKECLEANPAGE \MAKEDIRTYPAGE \DIRTYPAGEP)
			(PROP ARGNAMES \BUSBLT.OUTNYBBLES)
			(CONSTANTS DDLPIXELSPERPAGE DDLPIXELSPERWORD)))
(DEFINEQ

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

(\BaseAddrOfPage
  [LAMBDA (PAGE)                                             (* hdj "23-Oct-84 15:59")
    (create POINTER
	    PAGE# ← PAGE])

(\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])

(\PixelBaseOnPage
  [LAMBDA (Base BasePage CurrPage)
    (if (EQ CurrPage BasePage)
	then Base
      else (\BaseAddrOfPage CurrPage])

(\PixelsOnPage
  [LAMBDA (BitmapBase BitmapBasePage BitmapEnd BitmapEndPage Page#)
                                                             (* hdj "23-Oct-84 16:54")
    (UNFOLD (if (EQ Page# BitmapBasePage)
		then (IDIFFERENCE WORDSPERPAGE (fetch (POINTER WORDINPAGE) of BitmapBase))
	      elseif (EQ Page# BitmapEndPage)
		then (fetch (POINTER WORDINPAGE) of BitmapEnd)
	      else WORDSPERPAGE)
	    DDLPIXELSPERWORD])

(\UsedWordsOnPage
  [LAMBDA (BitmapBase BitmapBasePage BitmapEnd BitmapEndPage Page#)
                                                             (* hdj "23-Oct-84 16:48")
    (if (EQ Page# BitmapBasePage)
	then (IDIFFERENCE WORDSPERPAGE (fetch (POINTER WORDINPAGE) of BitmapBase))
      elseif (EQ Page# BitmapEndPage)
	then (fetch (POINTER WORDINPAGE) of BitmapEnd)
      else WORDSPERPAGE])

(\DDLCOLOR.INIT
  [LAMBDA NIL                                                (* hdj "23-Oct-84 16:25")

          (* * initialize dlion color)


    (OR (AND ColorScreenBitmap (BITMAPP ColorScreenBitmap)
	     (EQ (fetch (BITMAP BITMAPBITSPERPIXEL) of ColorScreenBitmap)
		 4)
	     (EQ (BITMAPHEIGHT ColorScreenBitmap)
		 480)
	     (EQ (BITMAPWIDTH ColorScreenBitmap)
		 640))
	(SETQ ColorScreenBitmap (BITMAPCREATE 640 480 4)))
    (SETQ ColorScreenBitmapBase (fetch (BITMAP BITMAPBASE) of ColorScreenBitmap))
    (SETQ ColorScreenBitmapBasePage (fetch (POINTER PAGE#) of ColorScreenBitmapBase))
    (SETQ ColorScreenBitmapEnd (\ADDBASE ColorScreenBitmapBase (\BitmapWords ColorScreenBitmap)))
    (SETQ ColorScreenBitmapEndPage (fetch (POINTER PAGE#) of ColorScreenBitmapEnd))
    (SETQ ColorScreenBitmapPages (\BITMAPPAGES ColorScreenBitmap))
    (\TEMPLOCKPAGES ColorScreenBitmapBase ColorScreenBitmapPages)
    (ADDTOVAR AROUNDEXITFNS \DDLCOLOR.AROUNDEXITFN)
    (SETQ \DDLCOLOR.MOVELIMIT 10)
    (SETQ \DDLCOLOR.LASTMOVEDPAGE 0)                         (* move no more than 10 pages per go-round of 
							     \DDLCOLOR.UPDATEDAEMON)
    (SETQ \PERIODIC.INTERRUPT.FREQUENCY 5)                   (* do update every 5 / 77 of a sec)
    (SETQ \PERIODIC.INTERRUPT (QUOTE \DDLCOLOR.UPDATEDAEMON])

(\DDLCOLOR.TURNOFF
  [LAMBDA NIL                                                (* hdj "22-Oct-84 16:25")

          (* * turn off dlion color display)


    (SETQ \PERIODIC.INTERRUPT NIL)
    (\TEMPUNLOCKPAGES (fetch (POINTER PAGE#) of (fetch (BITMAP BITMAPBASE) of ColorScreenBitmap))
		      (\BITMAPPAGES ColorScreenBitmap))
    (SETQ AROUNDEXITFNS (REMOVE (QUOTE \DDLCOLOR.AROUNDEXITFN)
				AROUNDEXITFNS))
    (SETQ ColorScreenBitmap NIL])

(\DDLCOLOR.UPDATEDAEMON
  [LAMBDA NIL                                                (* hdj "25-Oct-84 17:27")

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


    (DECLARE (GLOBALVARS \PERIODIC.INTERRUPT \DDLCOLOR.LASTMOVEDPAGE))
    (if \INTERRUPTABLE
	then (UNINTERRUPTABLY
                 (.REMOVE.PERIODIC.INTERRUPT (QUOTE \DDLCOLOR.UPDATEDAEMON))
		 (PROG ((PagesMoved 0)
			(CurrPage (ADD1 \DDLCOLOR.LASTMOVEDPAGE))
			(StoppingPage \DDLCOLOR.LASTMOVEDPAGE)
			(LastMovedPage \DDLCOLOR.LASTMOVEDPAGE)
			AbsCurrPage)
		       [repeatuntil (OR (EQ PagesMoved \DDLCOLOR.MOVELIMIT)
					(EQ CurrPage StoppingPage))
			  do (SETQ AbsCurrPage (IPLUS ColorBitmapBasePage CurrPage))
			     (if (\DIRTYPAGEP AbsCurrPage)
				 then (\BUSBLT.OUTNYBBLES (\PixelBaseOnPage ColorScreenBitmapBase 
									ColorScreenBitmapBasePage 
									    AbsCurrPage)
							  BUSADDRHI BUSADDRLO
							  (FOLDHI (\PixelsOnPage 
									    ColorScreenBitmapBase 
									ColorScreenBitmapBasePage 
									     ColorScreenBitmapEnd 
									 ColorScreenBitmapEndPage 
										 AbsCurrPage)
								  DDLPIXELSPERWORD))
				      (\MAKECLEANPAGE AbsCurrPage)
				      (add PagesMoved 1)
				      (SETQ LastMovedPage CurrPage)
			       else (SETQ CurrPage (IREMAINDER (ADD1 CurrPage)
							       ColorBitmapBasePage]
		       (SETQ \DDLCOLOR.LASTMOVEDPAGE LastMovedPage))
		 (.INSTALL.PERIODIC.INTERRUPT (QUOTE \DDLCOLOR.UPDATEDAEMON)))])

(\DDLCOLOR.AROUNDEXITFN
  [LAMBDA (EVENT)                                            (* hdj "23-Oct-84 16:59")

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


    (if (FMEMB EVENT (QUOTE (BEFORELOGOUT BEFORESYSOUT BEFORESAVEVM BEFOREMAKESYS)))
	then (SETQ \PERIODIC.INTERRUPT NIL)                  (* disable interrupt to avoid race condition)
	     (for PAGE from ColorScreenBitMapBasePage to ColorScreenBitMapEndPage
		do (\BUSBLT.OUTNYBBLES (\PixelBaseOnPage ColorScreenBitmapBase 
							 ColorScreenBitmapBasePage PAGE)
				       BUSADDRHI BUSADDRLO (\UsedWordsOnPage ColorScreenBitmapBase 
									ColorScreenBitmapBasePage 
									     ColorScreenBitMapEnd 
									 ColorScreenBitMapEndPage 
									     PAGE))
		   (\MAKEDIRTYPAGE PAGE))
      elseif (FMEMB EVENT (QUOTE (AFTERDOSYSOUT AFTERDOSAVEVM AFTERDOMAKESYS)))
	then (SETQ \PERIODIC.INTERRUPT (QUOTE \DDLCOLOR.UPDATEDAEMON)) 
                                                             (* enable interrupt)
      elseif (FMEMB EVENT (QUOTE (AFTERSYSOUT AFTERSAVEVM AFTERMAKESYS AFTERLOGOUT)))
	then                                                 (* CHECK FOR DLIONNESS, DO THE RIGHT THING)
	])
)
(DECLARE: EVAL@COMPILE 

(PUTPROPS .INSTALL.PERIODIC.INTERRUPT DMACRO ((INTERRUPT)
					      (SETQ \PERIODIC.INTERRUPT INTERRUPT)))

(PUTPROPS .REMOVE.PERIODIC.INTERRUPT MACRO ((INTERRUPT)
					    (SETQ \PERIODIC.INTERRUPT NIL)))

(PUTPROPS \BaseAddrOfPage DMACRO ((PAGE)
				  (CREATE POINTER PAGE# ← PAGE)))

(PUTPROPS \BitmapWords DMACRO (OPENLAMBDA (BM)
					  (ITIMES (fetch (BITMAP BITMAPRASTERWIDTH)
							 of BM)
						  (fetch (BITMAP BITMAPHEIGHT)
							 of BM))))

(PUTPROPS \PixelBaseOnPage DMACRO [LAMBDA (Base BasePage CurrPage)
					  (if (EQ CurrPage BasePage)
					      then Base else (\BaseAddrOfPage CurrPage])

(PUTPROPS \PixelsOnPage DMACRO (OPENLAMBDA (BitmapBase BitmapBasePage BitmapEnd BitmapEndPage Page#)
					   (UNFOLD (if (EQ Page# BitmapBasePage)
						       then
						       (IDIFFERENCE WORDSPERPAGE (fetch (POINTER
											  WORDINPAGE)
											of BitmapBase)
								    )
						       elseif
						       (EQ Page# BitmapEndPage)
						       then
						       (fetch (POINTER WORDINPAGE)
							      of BitmapEnd)
						       else WORDSPERPAGE)
						   DDLPIXELSPERWORD)))

(PUTPROPS \UsedWordsOnPage DMACRO (OPENLAMBDA (BitmapBase BitmapBasePage BitmapEnd BitmapEndPage 
							  Page#)
					      (if (EQ Page# BitmapBasePage)
						  then
						  (IDIFFERENCE WORDSPERPAGE (fetch (POINTER 
										       WORDINPAGE)
										   of BitmapBase))
						  elseif
						  (EQ Page# BitmapEndPage)
						  then
						  (fetch (POINTER WORDINPAGE)
							 of BitmapEnd)
						  else WORDSPERPAGE)))

(PUTPROPS \MAKECLEANPAGE MACRO [(VPAGE)
				(\WRITEMAP VPAGE (\READRP VPAGE)
					   (LOGAND \VMAP.NOTDIRTY (\READFLAGS VPAGE])

(PUTPROPS \MAKECLEANPAGE DMACRO [OPENLAMBDA (VPAGE)
					    (\WRITEMAP VPAGE (\READRP VPAGE)
						       (LOGAND \VMAP.NOTDIRTY (\READFLAGS VPAGE])

(PUTPROPS \MAKEDIRTYPAGE MACRO [(VPAGE)
				(\WRITEMAP VPAGE (\READRP VPAGE)
					   (LOGOR \VMAP.DIRTY (\READFLAGS VPAGE])

(PUTPROPS \MAKEDIRTYPAGE DMACRO [OPENLAMBDA (VPAGE)
					    (\WRITEMAP VPAGE (\READRP VPAGE)
						       (LOGOR \VMAP.DIRTY (\READFLAGS VPAGE])

(PUTPROPS \DIRTYPAGEP MACRO ((VPAGE)
			     (fetch (VMEMFLAGS DIRTY) of (\READFLAGS VPAGE))))

(PUTPROPS \DIRTYPAGEP DMACRO ((VPAGE)
			      (fetch (VMEMFLAGS DIRTY)
				     of
				     (\READFLAGS VPAGE))))
)

(PUTPROPS \BUSBLT.OUTNYBBLES ARGNAMES (VMADDR BUSADDRHI BUSADDRLO NWORDS))
(DECLARE: EVAL@COMPILE 

(RPAQQ DDLPIXELSPERPAGE 1024)

(RPAQQ DDLPIXELSPERWORD 4)

(CONSTANTS DDLPIXELSPERPAGE DDLPIXELSPERWORD)
)
(PUTPROPS DDLCOLORHAX COPYRIGHT ("Xerox Corporation" 1984))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (984 8402 (\BITMAPPAGES 994 . 1254) (\BaseAddrOfPage 1256 . 1411) (\BitmapWords 1413 . 
1636) (\DIRTYPAGEP 1638 . 1805) (\MAKECLEANPAGE 1807 . 2013) (\MAKEDIRTYPAGE 2015 . 2217) (
\PixelBaseOnPage 2219 . 2376) (\PixelsOnPage 2378 . 2860) (\UsedWordsOnPage 2862 . 3312) (
\DDLCOLOR.INIT 3314 . 4772) (\DDLCOLOR.TURNOFF 4774 . 5275) (\DDLCOLOR.UPDATEDAEMON 5277 . 6902) (
\DDLCOLOR.AROUNDEXITFN 6904 . 8400)))))
STOP