home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / sun / sunCG4C.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-31  |  6.6 KB  |  227 lines

  1. /*-
  2.  * sunCG4C.c --
  3.  *    Functions to support the sun CG4 board as a memory frame buffer.
  4.  */
  5.  
  6. /************************************************************
  7. Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
  8.  
  9.                     All Rights Reserved
  10.  
  11. Permission  to  use,  copy,  modify,  and  distribute   this
  12. software  and  its documentation for any purpose and without
  13. fee is hereby granted, provided that the above copyright no-
  14. tice  appear  in all copies and that both that copyright no-
  15. tice and this permission notice appear in  supporting  docu-
  16. mentation,  and  that the names of Sun or MIT not be used in
  17. advertising or publicity pertaining to distribution  of  the
  18. software  without specific prior written permission. Sun and
  19. M.I.T. make no representations about the suitability of this
  20. software for any purpose. It is provided "as is" without any
  21. express or implied warranty.
  22.  
  23. SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
  24. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
  25. NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
  26. ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  27. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
  28. PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
  29. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
  30. THE USE OR PERFORMANCE OF THIS SOFTWARE.
  31.  
  32. ********************************************************/
  33.  
  34. #ifndef    lint
  35. static char sccsid[] = "@(#)sunCG4C.c    1.4 6/1/87 Copyright 1987 Sun Micro";
  36. #endif
  37.  
  38. #include    "sun.h"
  39.  
  40. #include    <sys/mman.h>
  41. #include    <pixrect/memreg.h>
  42. #include    <sundev/cg4reg.h>
  43. #include    "colormap.h"
  44. #include    "colormapst.h"
  45. #include    "resource.h"
  46. #include    <struct.h>
  47.  
  48. /*-
  49.  * The cg4 frame buffer is divided into several pieces.
  50.  *    1) an array of 8-bit pixels
  51.  *    2) a one-bit deep overlay plane
  52.  *    3) an enable plane
  53.  *    4) a colormap and status register
  54.  *
  55.  * XXX - put the cursor in the overlay plane
  56.  */
  57. #define    CG4_HEIGHT    900
  58. #define    CG4_WIDTH    1152
  59.  
  60. typedef struct cg4c {
  61.     u_char mpixel[128*1024];        /* bit-per-pixel memory */
  62.     u_char epixel[128*1024];        /* enable plane */
  63.     u_char cpixel[CG4_HEIGHT][CG4_WIDTH];    /* byte-per-pixel memory */
  64. } CG4C, CG4CRec, *CG4CPtr;
  65.  
  66. #define CG4C_IMAGE(fb)        ((caddr_t)((fb)->cpixel))
  67. #define CG4C_IMAGEOFF        ((off_t)0x0)
  68. #define CG4C_IMAGELEN        (((CG4_HEIGHT*CG4_WIDTH + 8191)/8192)*8192)
  69. #define    CG4C_MONO(fb)        ((caddr_t)(&(fb)->mpixel))
  70. #define    CG4C_MONOLEN        (128*1024)
  71. #define    CG4C_ENABLE(fb)        ((caddr_t)(&(fb)->epixel))
  72. #define    CG4C_ENBLEN        CG4C_MONOLEN
  73.  
  74. /*-
  75.  *-----------------------------------------------------------------------
  76.  * sunCG4CInit --
  77.  *    Attempt to find and initialize a cg4 framebuffer used as mono
  78.  *
  79.  * Results:
  80.  *    TRUE if everything went ok. FALSE if not.
  81.  *
  82.  * Side Effects:
  83.  *    Most of the elements of the ScreenRec are filled in. Memory is
  84.  *    allocated for the frame buffer and the buffer is mapped. The
  85.  *    video is enabled for the frame buffer...
  86.  *
  87.  *-----------------------------------------------------------------------
  88.  */
  89. /*ARGSUSED*/
  90. static Bool
  91. sunCG4CInit (index, pScreen, argc, argv)
  92.     int              index;        /* The index of pScreen in the ScreenInfo */
  93.     ScreenPtr      pScreen;      /* The Screen to initialize */
  94.     int              argc;            /* The number of the Server's arguments. */
  95.     char          **argv;       /* The arguments themselves. Don't change! */
  96. {
  97.     if (!cfbScreenInit (pScreen, CG4C_IMAGE((CG4CPtr)sunFbs[index].fb),
  98.             sunFbs[index].info.fb_width,
  99.             sunFbs[index].info.fb_height,
  100.             monitorResolution, monitorResolution,
  101.             sunFbs[index].info.fb_width))
  102.         return (FALSE);
  103.     
  104.     if (!sunScreenAllocate (pScreen))
  105.     return FALSE;
  106.  
  107.     sunCGScreenInit (pScreen);
  108.  
  109.     if (!sunScreenInit (pScreen))
  110.     return FALSE;
  111.  
  112.     sunSaveScreen( pScreen, SCREEN_SAVER_OFF );
  113.  
  114.     return cfbCreateDefColormap(pScreen);
  115. }
  116.  
  117. /*-
  118.  *--------------------------------------------------------------
  119.  * sunCG4CSwitch --
  120.  *      Enable or disable color plane 
  121.  *
  122.  * Results:
  123.  *      Color plane enabled for select =0, disabled otherwise.
  124.  *
  125.  *--------------------------------------------------------------
  126.  */
  127. static void
  128. sunCG4CSwitch (pScreen, select)
  129.     ScreenPtr  pScreen;
  130.     u_char     select;
  131. {
  132.     register int    *j, *end;
  133.     CG4CPtr        CG4Cfb;
  134.  
  135.     CG4Cfb = (CG4CPtr) sunFbs[pScreen->myNum].fb;
  136.  
  137.     j = (int *) CG4Cfb->epixel;
  138.     end = j + (128 / sizeof (int)) * 1024;
  139.     if (!select)                         
  140.       while (j < end)
  141.     *j++ = 0;
  142.     else
  143.       while (j < end)
  144.     *j++ = ~0;
  145. }
  146.  
  147. /*-
  148.  *-----------------------------------------------------------------------
  149.  * sunCG4CProbe --
  150.  *    Attempt to find and initialize a cg4 framebuffer used as mono
  151.  *
  152.  * Results:
  153.  *    TRUE if everything went ok. FALSE if not.
  154.  *
  155.  * Side Effects:
  156.  *    Memory is allocated for the frame buffer and the buffer is mapped.
  157.  *
  158.  *-----------------------------------------------------------------------
  159.  */
  160. /*ARGSUSED*/
  161. Bool
  162. sunCG4CProbe (pScreenInfo, index, fbNum, argc, argv)
  163.     ScreenInfo      *pScreenInfo;    /* The screenInfo struct */
  164.     int              index;        /* The index of pScreen in the ScreenInfo */
  165.     int              fbNum;        /* Index into the sunFbData array */
  166.     int              argc;            /* The number of the Server's arguments. */
  167.     char          **argv;       /* The arguments themselves. Don't change! */
  168. {
  169.     int         fd;
  170.     struct fbtype fbType;
  171.     CG4CPtr        CG4Cfb;
  172.  
  173.     if ((fd = sunOpenFrameBuffer(FBTYPE_SUN4COLOR, &fbType, index, fbNum,
  174.                  argc, argv)) < 0)
  175.     return FALSE;
  176.  
  177. #ifdef    _MAP_NEW
  178.     if ((int)(CG4Cfb = (CG4CPtr) mmap((caddr_t) 0,
  179.          CG4C_MONOLEN + CG4C_ENBLEN + CG4C_IMAGELEN,
  180.          PROT_READ | PROT_WRITE,
  181.          MAP_SHARED | _MAP_NEW, fd, 0)) == -1) {
  182.     Error("Mapping cg4c");
  183.     (void) close(fd);
  184.     return FALSE;
  185.     }
  186. #else    _MAP_NEW
  187.     CG4Cfb = (CG4CPtr) valloc(CG4C_MONOLEN + CG4C_ENBLEN + CG4C_IMAGELEN);
  188.     if (CG4Cfb == (CG4CPtr) NULL) {
  189.     ErrorF("Could not allocate room for frame buffer.\n");
  190.     return FALSE;
  191.     }
  192.  
  193.     if (mmap((caddr_t) CG4Cfb, CG4C_MONOLEN + CG4C_ENBLEN + CG4C_IMAGELEN,
  194.          PROT_READ | PROT_WRITE,
  195.          MAP_SHARED, fd, 0) < 0) {
  196.     Error("Mapping cg4c");
  197.     (void) close(fd);
  198.     return FALSE;
  199.     }
  200. #endif    _MAP_NEW
  201.  
  202.     sunFbs[index].fd = fd;
  203.     sunFbs[index].info = fbType;
  204.     sunFbs[index].fb = (pointer) CG4Cfb;
  205.     sunFbs[index].EnterLeave = sunCG4CSwitch;
  206.     sunSupportsDepth8 = TRUE;
  207.     return TRUE;
  208. }
  209.  
  210. Bool
  211. sunCG4CCreate(pScreenInfo, argc, argv)
  212.     ScreenInfo      *pScreenInfo;
  213.     int              argc;
  214.     char          **argv;
  215. {
  216.     int i;
  217.  
  218.     i = AddScreen(sunCG4CInit, argc, argv);
  219.     if (i >= 0)
  220.     {
  221.     /* Now set the enable plane for screen 0 */
  222.     sunCG4CSwitch(pScreenInfo->screens[i], i != 0);
  223.     return TRUE;
  224.     }
  225.     return FALSE;
  226. }
  227.