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

  1. /*-
  2.  * sunCG3C.c --
  3.  *    Functions to support the sun CG3 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. #include    "sun.h"
  35.  
  36. #include    <sys/mman.h>
  37. #include    <pixrect/memreg.h>
  38. /*
  39. #include    <sundev/cg4reg.h>
  40. */
  41. #include    "colormap.h"
  42. #include    "colormapst.h"
  43. #include    "resource.h"
  44. #include    <struct.h>
  45.  
  46. /*-
  47.  * The cg3 frame buffer is divided into several pieces.
  48.  *    1) an array of 8-bit pixels
  49.  *    2) a one-bit deep overlay plane
  50.  *    3) an enable plane
  51.  *    4) a colormap and status register
  52.  *
  53.  * XXX - put the cursor in the overlay plane
  54.  */
  55.  
  56. #define CG3A_HEIGHT      900 
  57. #define CG3A_WIDTH       1152
  58. #define CG3B_HEIGHT     768
  59. #define CG3B_WIDTH     1024
  60.  
  61. typedef struct cg3ac {
  62. #ifdef sparc
  63.     u_char mpixel[128*1024];        /* bit-per-pixel memory */
  64.     u_char epixel[128*1024];        /* enable plane */
  65. #endif
  66.         u_char cpixel[CG3A_HEIGHT][CG3A_WIDTH];   /* byte-per-pixel memory */
  67. } CG3AC, CG3ACRec, *CG3ACPtr;
  68.  
  69. typedef struct cg3bc {
  70. #ifdef sparc
  71.     u_char mpixel[128*1024];        /* bit-per-pixel memory */
  72.     u_char epixel[128*1024];        /* enable plane */
  73. #endif
  74.         u_char cpixel[CG3B_HEIGHT][CG3B_WIDTH];   /* byte-per-pixel memory */
  75. } CG3BC, CG3BCRec, *CG3BCPtr;
  76.  
  77. #define CG3AC_IMAGE(fb)      ((caddr_t)((fb)->cpixel))
  78. #define CG3AC_IMAGELEN       (((sizeof (CG3AC) + 4095)/4096)*4096)
  79. #define CG3BC_IMAGE(fb)      ((caddr_t)((fb)->cpixel))
  80. #define CG3BC_IMAGELEN       (((sizeof (CG3BC) + 4095)/4096)*4096)
  81.  
  82. /*-
  83.  *-----------------------------------------------------------------------
  84.  * sunCG3CInit --
  85.  *    Attempt to find and initialize a cg3 framebuffer
  86.  *
  87.  * Results:
  88.  *    TRUE if everything went ok. FALSE if not.
  89.  *
  90.  * Side Effects:
  91.  *    Most of the elements of the ScreenRec are filled in. Memory is
  92.  *    allocated for the frame buffer and the buffer is mapped. The
  93.  *    video is enabled for the frame buffer...
  94.  *
  95.  *-----------------------------------------------------------------------
  96.  */
  97. /*ARGSUSED*/
  98. static Bool
  99. sunCG3CInit (index, pScreen, argc, argv)
  100.     int              index;        /* The index of pScreen in the ScreenInfo */
  101.     ScreenPtr      pScreen;      /* The Screen to initialize */
  102.     int              argc;            /* The number of the Server's arguments. */
  103.     char          **argv;       /* The arguments themselves. Don't change! */
  104. {
  105.     if (!cfbScreenInit (pScreen, sunFbs[index].fb,
  106.             sunFbs[index].info.fb_width,
  107.             sunFbs[index].info.fb_height,
  108.             monitorResolution, monitorResolution,
  109.             sunFbs[index].info.fb_width))
  110.     return (FALSE);
  111.  
  112.     if (!sunScreenAllocate (pScreen))
  113.     return FALSE;
  114.  
  115.     sunCGScreenInit (pScreen);
  116.  
  117.     if (!sunScreenInit (pScreen))
  118.     return FALSE;
  119.  
  120.     sunSaveScreen (pScreen, SCREEN_SAVER_OFF);
  121.  
  122.     return cfbCreateDefColormap(pScreen);
  123. }
  124.  
  125. /*-
  126.  *-----------------------------------------------------------------------
  127.  * sunCG3CProbe --
  128.  *    Attempt to find and initialize a cg3 framebuffer
  129.  *
  130.  * Results:
  131.  *    TRUE if everything went ok. FALSE if not.
  132.  *
  133.  * Side Effects:
  134.  *    Memory is allocated for the frame buffer and the buffer is mapped.
  135.  *
  136.  *-----------------------------------------------------------------------
  137.  */
  138. /*ARGSUSED*/
  139. Bool
  140. sunCG3CProbe (pScreenInfo, index, fbNum, argc, argv)
  141.     ScreenInfo      *pScreenInfo;    /* The screenInfo struct */
  142.     int              index;        /* The index of pScreen in the ScreenInfo */
  143.     int              fbNum;        /* Index into the sunFbData array */
  144.     int              argc;            /* The number of the Server's arguments. */
  145.     char          **argv;       /* The arguments themselves. Don't change! */
  146. {
  147.     int         fd;
  148.     struct fbtype fbType;
  149.     pointer    fb;
  150.     CG3ACPtr CG3ACfb;
  151.     CG3BCPtr CG3BCfb;
  152.  
  153.     if ((fd = sunOpenFrameBuffer(FBTYPE_SUN3COLOR, &fbType, index, fbNum,
  154.                  argc, argv)) < 0)
  155.     return FALSE;
  156.  
  157. #ifdef    _MAP_NEW
  158.     if (fbType.fb_width == CG3A_WIDTH) {
  159.     if ((int)(CG3ACfb = (CG3ACPtr) mmap((caddr_t) 0,
  160.          CG3AC_IMAGELEN,
  161.          PROT_READ | PROT_WRITE,
  162.          MAP_SHARED | _MAP_NEW, fd, 0)) == -1) {
  163.         Error("Mapping cg3c");
  164.         (void) close(fd);
  165.         return FALSE;
  166.     }
  167.     fb = (pointer) CG3AC_IMAGE(CG3ACfb);
  168.     }
  169.     else if (fbType.fb_width == CG3B_WIDTH) {
  170.     if ((int)(CG3BCfb = (CG3BCPtr) mmap((caddr_t) 0,
  171.          CG3BC_IMAGELEN,
  172.          PROT_READ | PROT_WRITE,
  173.          MAP_SHARED | _MAP_NEW, fd, 0)) == -1) {
  174.         Error("Mapping cg3c");
  175.         (void) close(fd);
  176.         return FALSE;
  177.     }
  178.     fb = (pointer) CG3BC_IMAGE(CG3BCfb);
  179.     }
  180.     else {
  181.         Error("Mapping cg3c");
  182.         (void) close(fd);
  183.         return FALSE;
  184.     }
  185. #else    _MAP_NEW
  186.     if (fbType.fb_width == CG3A_WIDTH) {
  187.     CG3ACfb = (CG3ACPtr) valloc(CG3AC_MONOLEN + 
  188.         CG3AC_ENBLEN + CG3AC_IMAGELEN);
  189.     if (CG3ACfb == (CG3ACPtr) NULL) {
  190.         ErrorF("Could not allocate room for frame buffer.\n");
  191.         return FALSE;
  192.     }
  193.  
  194.     if (mmap((caddr_t) CG3ACfb, CG3AC_MONOLEN + 
  195.         CG3AC_ENBLEN + CG3AC_IMAGELEN,
  196.         PROT_READ | PROT_WRITE,
  197.         MAP_SHARED, fd, 0) < 0) {
  198.         Error("Mapping cg3c");
  199.         (void) close(fd);
  200.         return FALSE;
  201.     }
  202.     fb = (pointer) CG3AC_IMAGE(CG3ACfb);
  203.     }
  204.     else if (fbType.fb_width == CG3B_WIDTH) {
  205.     CG3BCfb = (CG3BCPtr) valloc(CG3BC_MONOLEN + 
  206.         CG3BC_ENBLEN + CG3BC_IMAGELEN);
  207.     if (CG3BCfb == (CG3BCPtr) NULL) {
  208.         ErrorF("Could not allocate room for frame buffer.\n");
  209.         return FALSE;
  210.     }
  211.  
  212.     if (mmap((caddr_t) CG3BCfb, CG3BC_MONOLEN + 
  213.         CG3BC_ENBLEN + CG3BC_IMAGELEN,
  214.         PROT_READ | PROT_WRITE,
  215.         MAP_SHARED, fd, 0) < 0) {
  216.         Error("Mapping cg3c");
  217.         (void) close(fd);
  218.         return FALSE;
  219.     }
  220.     fb = (pointer) CG3BC_IMAGE(CG3BCfb);
  221.     }
  222.     else {
  223.         Error("Mapping cg3c");
  224.         (void) close(fd);
  225.         return FALSE;
  226.     }
  227. #endif    _MAP_NEW
  228.  
  229.     sunFbs[index].fd = fd;
  230.     sunFbs[index].info = fbType;
  231.     sunFbs[index].fb = fb;
  232.     sunSupportsDepth8 = TRUE;
  233.     return TRUE;
  234. }
  235.  
  236. /*ARGSUSED*/
  237. Bool
  238. sunCG3CCreate(pScreenInfo, argc, argv)
  239.     ScreenInfo      *pScreenInfo;
  240.     int              argc;
  241.     char          **argv;
  242. {
  243.     return (AddScreen(sunCG3CInit, argc, argv) >= 0);
  244. }
  245.