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

  1. /*-
  2.  * sunBW2.c --
  3.  *    Functions for handling the sun BWTWO board.
  4.  *
  5.  * Copyright (c) 1987 by the Regents of the University of California
  6.  * Copyright (c) 1987 by Adam de Boor, UC Berkeley
  7.  *
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  *
  16.  *
  17.  */
  18.  
  19. /************************************************************
  20. Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
  21.  
  22.                     All Rights Reserved
  23.  
  24. Permission  to  use,  copy,  modify,  and  distribute   this
  25. software  and  its documentation for any purpose and without
  26. fee is hereby granted, provided that the above copyright no-
  27. tice  appear  in all copies and that both that copyright no-
  28. tice and this permission notice appear in  supporting  docu-
  29. mentation,  and  that the names of Sun or MIT not be used in
  30. advertising or publicity pertaining to distribution  of  the
  31. software  without specific prior written permission. Sun and
  32. M.I.T. make no representations about the suitability of this
  33. software for any purpose. It is provided "as is" without any
  34. express or implied warranty.
  35.  
  36. SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
  37. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
  38. NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
  39. ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  40. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
  41. PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
  42. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
  43. THE USE OR PERFORMANCE OF THIS SOFTWARE.
  44.  
  45. ********************************************************/
  46.  
  47.  
  48. #ifndef    lint
  49. static char sccsid[] = "%W %G Copyright 1987 Sun Micro";
  50. #endif
  51.  
  52. /*-
  53.  * Copyright (c) 1987 by Sun Microsystems,  Inc.
  54.  */
  55.  
  56. #include    "sun.h"
  57. #include    "resource.h"
  58.  
  59. #include    <sys/mman.h>
  60. #include    <sundev/bw2reg.h>
  61.  
  62. extern caddr_t mmap();
  63.  
  64. typedef struct bw2 {
  65.     u_char    image[BW2_FBSIZE];          /* Pixel buffer */
  66. } BW2, BW2Rec, *BW2Ptr;
  67.  
  68. typedef struct bw2hr {
  69.     u_char    image[BW2_FBSIZE_HIRES];          /* Pixel buffer */
  70. } BW2HR, BW2HRRec, *BW2HRPtr;
  71.  
  72. /*-
  73.  *-----------------------------------------------------------------------
  74.  * sunBW2Init --
  75.  *    Attempt to find and initialize a bw2 framebuffer
  76.  *
  77.  * Results:
  78.  *    None
  79.  *
  80.  * Side Effects:
  81.  *    Most of the elements of the ScreenRec are filled in.  The
  82.  *    video is enabled for the frame buffer...
  83.  *
  84.  *-----------------------------------------------------------------------
  85.  */
  86. /*ARGSUSED*/
  87. static Bool
  88. sunBW2Init (index, pScreen, argc, argv)
  89.     int              index;        /* The index of pScreen in the ScreenInfo */
  90.     ScreenPtr      pScreen;      /* The Screen to initialize */
  91.     int              argc;            /* The number of the Server's arguments. */
  92.     char          **argv;       /* The arguments themselves. Don't change! */
  93. {
  94.     if (!mfbScreenInit(pScreen,
  95.                sunFbs[index].fb,
  96.                sunFbs[index].info.fb_width,
  97.                sunFbs[index].info.fb_height,
  98.                monitorResolution, monitorResolution,
  99.                sunFbs[index].info.fb_width))
  100.     return (FALSE);
  101.  
  102.     if (!sunScreenAllocate (pScreen) || !sunScreenInit (pScreen))
  103.     return FALSE;
  104.  
  105.     pScreen->whitePixel = 0;
  106.     pScreen->blackPixel = 1;
  107.  
  108.     /*
  109.      * Enable video output...? 
  110.      */
  111.     (void) sunSaveScreen(pScreen, SCREEN_SAVER_OFF);
  112.  
  113.     return mfbCreateDefColormap(pScreen);
  114. }
  115.  
  116. /*-
  117.  *-----------------------------------------------------------------------
  118.  * sunBW2Probe --
  119.  *    Attempt to find and initialize a bw2 framebuffer
  120.  *
  121.  * Results:
  122.  *    None
  123.  *
  124.  * Side Effects:
  125.  *    Memory is allocated for the frame buffer and the buffer is mapped. 
  126.  *
  127.  *-----------------------------------------------------------------------
  128.  */
  129.  
  130. /*ARGSUSED*/
  131. Bool
  132. sunBW2Probe(pScreenInfo, index, fbNum, argc, argv)
  133.     ScreenInfo      *pScreenInfo;    /* The screenInfo struct */
  134.     int              index;        /* The index of pScreen in the ScreenInfo */
  135.     int              fbNum;        /* Index into the sunFbData array */
  136.     int              argc;            /* The number of the Server's arguments. */
  137.     char          **argv;       /* The arguments themselves. Don't change! */
  138. {
  139.     int         fd;
  140.     struct fbtype fbType;
  141.     int        pagemask, mapsize;
  142.     caddr_t    addr, mapaddr;
  143.  
  144.     if ((fd = sunOpenFrameBuffer(FBTYPE_SUN2BW, &fbType, index, fbNum,
  145.                  argc, argv)) < 0)
  146.     return FALSE;
  147.  
  148.     /*
  149.      * It's not precisely clear that we have to round up
  150.      * fb_size to the nearest page boundary but there are
  151.      * rumors that this is a good idea and that it shouldn't
  152.      * hurt anything.
  153.      */
  154.     pagemask = getpagesize() - 1;
  155.     mapsize = (fbType.fb_size + pagemask) & ~pagemask;
  156.     addr = 0;
  157.  
  158. #ifndef _MAP_NEW
  159.     /*
  160.      * If we are running pre-SunOS 4.0 then we first need to
  161.      * allocate some address range for mmap() to replace.
  162.      */
  163.     if ((addr = (caddr_t) valloc(mapsize)) == 0) {
  164.         ErrorF("Could not allocate room for frame buffer.\n");
  165.         (void) close(fd);
  166.         return FALSE;
  167.     }
  168. #endif _MAP_NEW
  169.  
  170.     /*
  171.      * In SunOS 4.0 the standard C library mmap() system call
  172.      * wrapper will automatically add a _MAP_NEW flag for us.
  173.      * In pre-4.0 mmap(), success returned 0 but now it returns the
  174.      * newly mapped starting address. The test for mapaddr
  175.      * being 0 below will handle this difference correctly.
  176.      */
  177.     if ((mapaddr = (caddr_t) mmap(addr, mapsize,
  178.         PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t)0)) == (caddr_t) -1) {
  179.         Error("mapping BW2");
  180.         (void) close(fd);
  181.         return FALSE;
  182.     }
  183.  
  184.     if (mapaddr == 0)
  185.         mapaddr = addr;
  186.  
  187.     sunFbs[index].fb = (pointer)mapaddr;
  188.     sunFbs[index].fd = fd;
  189.     sunFbs[index].info = fbType;
  190.     sunFbs[index].EnterLeave = NULL;
  191.     return TRUE;
  192. }
  193.  
  194. Bool
  195. sunBW2Create(pScreenInfo, argc, argv)
  196.     ScreenInfo      *pScreenInfo;
  197.     int              argc;
  198.     char          **argv;
  199. {
  200.     return (AddScreen(sunBW2Init, argc, argv) >= 0);
  201. }
  202.