*** /tmp/,RCSt1594225	Mon Nov  4 17:41:14 1991
--- sunCG4C.c	Tue Jan  8 23:00:49 1991
***************
*** 36,49 ****
  #endif
  
  #include    "sun.h"
  
  #include    <sys/mman.h>
  #include    <pixrect/memreg.h>
  #include    <sundev/cg4reg.h>
  #include    "colormap.h"
  #include    "colormapst.h"
  #include    "resource.h"
- #include    <struct.h>
  
  /*-
   * The cg4 frame buffer is divided into several pieces.
--- 36,56 ----
  #endif
  
  #include    "sun.h"
+ #include    <sys/types.h>
  
+ #include "sys/fb.h"
+ #include "sys/ioctl.h"
+ #include "kernel/vmMach.h"
+ 
  #include    <sys/mman.h>
+ #ifndef	sprite
  #include    <pixrect/memreg.h>
  #include    <sundev/cg4reg.h>
+ #include    <struct.h>
+ #endif	sprite
  #include    "colormap.h"
  #include    "colormapst.h"
  #include    "resource.h"
  
  /*-
   * The cg4 frame buffer is divided into several pieces.
***************
*** 86,92 ****
      int		index, count;
      u_char	*rmap, *gmap, *bmap;
  {
!     struct fbcmap sunCmap;
  
      sunCmap.index = index;
      sunCmap.count = count;
--- 93,99 ----
      int		index, count;
      u_char	*rmap, *gmap, *bmap;
  {
!     fbcmap	sunCmap;
  
      sunCmap.index = index;
      sunCmap.count = count;
***************
*** 134,146 ****
  {
      int		state = on;
  
!     if (on != SCREEN_SAVER_ON) {
  	SetTimeSinceLastInputEvent();
  	state = 1;
!     } else {
  	state = 0;
      }
      (void) ioctl(sunFbs[pScreen->myNum].fd, FBIOSVIDEO, &state);
      return( TRUE );
  }
  
--- 141,161 ----
  {
      int		state = on;
  
!     switch (on) {
!     case SCREEN_SAVER_FORCER:
  	SetTimeSinceLastInputEvent();
  	state = 1;
! 	break;
!     case SCREEN_SAVER_OFF:
! 	state = 1;
! 	break;
!     case SCREEN_SAVER_ON:
!     default:
  	state = 0;
+ 	break;
      }
      (void) ioctl(sunFbs[pScreen->myNum].fd, FBIOSVIDEO, &state);
+ 
      return( TRUE );
  }
  
***************
*** 163,172 ****
--- 178,193 ----
      int		i;
      ScreenPtr	pScreen;
  {
+     u_char rmap[256], gmap[256], bmap[256];
      Bool    ret;
  
      pScreen->CloseScreen = (Bool (*)()) pScreen->devPrivates[sunCG4CScreenIndex].ptr;
      ret = (*pScreen->CloseScreen) (i, pScreen);
+ 
+     /* the following 2 lines are to fix rr clear_colormap bug */
+     rmap[255] = gmap[255] = bmap[255] = 0;
+     sunCG4CUpdateColormap(pScreen, 255, 1, rmap, gmap, bmap);
+ 
      sunCG4CInstalledMap = NULL;
      (void) (*pScreen->SaveScreen) (pScreen, SCREEN_SAVER_OFF);
      return ret;
***************
*** 347,353 ****
      int	    	  argc;	    	/* The number of the Server's arguments. */
      char    	  **argv;   	/* The arguments themselves. Don't change! */
  {
!     if (!cfbScreenInit (pScreen, (pointer)CG4Cfb->cpixel,
  			sunFbs[index].info.fb_width,
  			sunFbs[index].info.fb_height,
  			monitorResolution, monitorResolution,
--- 368,374 ----
      int	    	  argc;	    	/* The number of the Server's arguments. */
      char    	  **argv;   	/* The arguments themselves. Don't change! */
  {
!     if (!cfbScreenInit (pScreen, sunFbs[index].fb,
  			sunFbs[index].info.fb_width,
  			sunFbs[index].info.fb_height,
  			monitorResolution, monitorResolution,
***************
*** 385,397 ****
      ScreenPtr  pScreen;
      u_char     select;
  {
-     int index;
      register int    *j, *end;
  
!     index = pScreen->myNum;
!     CG4Cfb = (CG4CPtr) sunFbs[index].fb;
! 
!     j = (int *) CG4Cfb->epixel;
      end = j + (128 / sizeof (int)) * 1024;
      if (!select)                         
        while (j < end)
--- 406,416 ----
      ScreenPtr  pScreen;
      u_char     select;
  {
      register int    *j, *end;
  
! /* XXX This ifndef was commented out...  I stuck it back in til overlay works */
! #ifndef sprite
!     j = (int *) fb_Addr.fb_enable;
      end = j + (128 / sizeof (int)) * 1024;
      if (!select)                         
        while (j < end)
***************
*** 399,404 ****
--- 418,424 ----
      else
        while (j < end)
  	*j++ = ~0;
+ #endif
  }
  
  /*-
***************
*** 425,430 ****
--- 445,453 ----
  {
      int         fd;
      struct fbtype fbType;
+ #ifdef sprite
+     int		sizeToUse;
+ #endif /* sprite */
  
      if ((fd = sunOpenFrameBuffer(FBTYPE_SUN4COLOR, &fbType, index, fbNum,
  				 argc, argv)) < 0)
***************
*** 440,454 ****
--- 463,491 ----
  	return FALSE;
      }
  #else	_MAP_NEW
+ #ifdef sprite
+     sizeToUse = ((CG4C_MONOLEN + CG4C_ENBLEN + CG4C_IMAGELEN + VMMACH_SEG_SIZE)
+ 	    & ~(VMMACH_SEG_SIZE-1)) + VMMACH_SEG_SIZE;
+ 	    
+     CG4Cfb = (CG4CPtr) malloc(sizeToUse);
+ #else
      CG4Cfb = (CG4CPtr) valloc(CG4C_MONOLEN + CG4C_ENBLEN + CG4C_IMAGELEN);
+ #endif /* sprite */
      if (CG4Cfb == (CG4CPtr) NULL) {
  	ErrorF("Could not allocate room for frame buffer.\n");
  	return FALSE;
      }
  
+ #ifdef sprite
+     CG4Cfb = mmap((caddr_t) CG4Cfb, CG4C_MONOLEN + CG4C_ENBLEN + CG4C_IMAGELEN,
+ 	     PROT_READ | PROT_WRITE,
+ 	     MAP_SHARED, fd, 0);
+     if (CG4Cfb == (caddr_t) NULL) {
+ #else
      if (mmap((caddr_t) CG4Cfb, CG4C_MONOLEN + CG4C_ENBLEN + CG4C_IMAGELEN,
  	     PROT_READ | PROT_WRITE,
  	     MAP_SHARED, fd, 0) < 0) {
+ #endif /* sprite */
  	Error("Mapping cg4c");
  	(void) close(fd);
  	return FALSE;
***************
*** 455,465 ****
      }
  #endif	_MAP_NEW
  
-     sunFbs[index].fd = fd;
      sunFbs[index].info = fbType;
      sunFbs[index].fb = (pointer) CG4Cfb;
      sunFbs[index].EnterLeave = sunCG4CSwitch;
      sunSupportsDepth8 = TRUE;
      return TRUE;
  }
  
--- 492,506 ----
      }
  #endif	_MAP_NEW
  
      sunFbs[index].info = fbType;
+ #ifdef sprite
      sunFbs[index].fb = (pointer) CG4Cfb;
+ #else
+     sunFbs[index].fb = (pointer) fb_Addr.fb_buffer;
+ #endif /* sprite */
      sunFbs[index].EnterLeave = sunCG4CSwitch;
      sunSupportsDepth8 = TRUE;
+     sunFbs[index].fd = fd;
      return TRUE;
  }
  
