home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / d / ddx-mips.zip / MIPSFB.C < prev    next >
C/C++ Source or Header  |  1992-04-07  |  4KB  |  160 lines

  1. /*
  2.  * $XConsortium$
  3.  *
  4.  * Copyright 1991 MIPS Computer Systems, Inc.
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of MIPS not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  MIPS makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * MIPS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL MIPS
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  */
  23. #ident    "$Header: mipsFb.c,v 1.11 92/04/06 21:02:29 dd Exp $"
  24.  
  25. #include <sys/types.h>
  26.  
  27. #include <X.h>
  28. #include <Xproto.h>
  29. #include <misc.h>
  30. #include <input.h>
  31. #include <scrnintstr.h>
  32.  
  33. #include "mips.h"
  34. #include "mipsFb.h"
  35.  
  36. extern int defaultColorVisualClass;
  37. extern int mipsMonitorSize;
  38.  
  39. /* generic initialization for color FBs */
  40. mipsInitColor(pm)
  41.     MipsScreenPtr pm;
  42. {
  43.     pm->bitsPerPixel = 8;
  44. #if MIPS_4BIT
  45.     pm->depth = mipsCheckDepth(pm->fbnorm);
  46. #else
  47.     pm->depth = 8;
  48. #endif
  49.     pm->scr_width = 1280;
  50.     pm->scr_height = 1024;
  51.  
  52.     pm->dpi = mipsMonitorDPI(pm);
  53. }
  54.  
  55. /* ARGSUSED */
  56. int
  57. mipsMonitorDPI(pm)
  58.     MipsScreenPtr pm;
  59. {
  60.     switch (mipsMonitorSize) {
  61.     case 19:
  62.         return DPI_SONY19;
  63.     default:
  64.         return DPI_SONY16;
  65.     }
  66. }
  67.  
  68. #if MIPS_4BIT
  69.  
  70. /*
  71.  * Check 8 bit frame buffer to see how many planes are populated.
  72.  */
  73. static int
  74. mipsCheckDepth(fb)
  75.     volatile u_char *fb;
  76. {
  77.     int depth = 8;
  78.     u_char fb0, fb1;
  79.  
  80.     fb0 = fb[0];
  81.     fb1 = fb[1];
  82.     fb[0] = 0x5a;
  83.     fb[1] = 0xa5;
  84.  
  85.     if (fb[0] != 0x5a || fb[1] != 0xa5)
  86.         depth = 4;
  87.  
  88.     fb[0] = fb0;
  89.     fb[1] = fb1;
  90.  
  91.     return depth;
  92. }
  93.  
  94. /*
  95.  * Special CFB initialization code...
  96.  *
  97.  * To support 4 bit gray scale systems, we overwrite the visuals table
  98.  * in cfb/cfbscrinit.c.  This is not elegant but at least we don't
  99.  * have to modify the MIT code.
  100.  */
  101.  
  102. #define    PSZ    4
  103. #define _BP 8
  104. #define _RZ ((PSZ + 2) / 3)
  105. #define _RS 0
  106. #define _RM ((1 << _RZ) - 1)
  107. #define _GZ ((PSZ - _RZ + 1) / 2)
  108. #define _GS _RZ
  109. #define _GM (((1 << _GZ) - 1) << _GS)
  110. #define _BZ (PSZ - _RZ - _GZ)
  111. #define _BS (_RZ + _GZ)
  112. #define _BM (((1 << _BZ) - 1) << _BS)
  113. #define _CE (1 << _RZ)
  114.  
  115. static VisualRec visuals[] = {
  116. /* vid  class        bpRGB cmpE nplan rMask gMask bMask oRed oGreen oBlue */
  117. #ifndef STATIC_COLOR
  118.     0,  PseudoColor, _BP,  1<<PSZ,   PSZ,  0,   0,   0,   0,   0,   0,
  119. #ifndef X11R4
  120.     0,  DirectColor, _BP, _CE,       PSZ,  _RM, _GM, _BM, _RS, _GS, _BS,
  121. #endif /* !X11R4 */
  122.     0,  GrayScale,   _BP,  1<<PSZ,   PSZ,  0,   0,   0,   0,   0,   0,
  123.     0,  StaticGray,  _BP,  1<<PSZ,   PSZ,  0,   0,   0,   0,   0,   0,
  124. #endif
  125.     0,  StaticColor, _BP,  1<<PSZ,   PSZ,  _RM, _GM, _BM, _RS, _GS, _BS,
  126. #ifndef X11R4
  127.     0,  TrueColor,   _BP, _CE,       PSZ,  _RM, _GM, _BM, _RS, _GS, _BS
  128. #endif /* !X11R4 */
  129. };
  130.  
  131. #define    NUMVISUALS    ((sizeof visuals)/(sizeof visuals[0]))
  132.  
  133. mipsFixScreen4(pScreen)
  134.     ScreenPtr pScreen;
  135. {
  136.     VisualPtr oldvis;
  137.     int i;
  138.  
  139.     if (defaultColorVisualClass < 0)
  140.         defaultColorVisualClass = GrayScale;
  141.  
  142.     oldvis = pScreen->visuals;
  143.  
  144.     for (i = 0; i < NUMVISUALS; i++) {
  145.         oldvis[i].bitsPerRGBValue =
  146.             visuals[i].bitsPerRGBValue;
  147.         oldvis[i].ColormapEntries =
  148.             visuals[i].ColormapEntries;
  149.         oldvis[i].nplanes = visuals[i].nplanes;
  150.         oldvis[i].redMask = visuals[i].redMask;
  151.         oldvis[i].greenMask = visuals[i].greenMask;
  152.         oldvis[i].blueMask = visuals[i].blueMask;
  153.         oldvis[i].offsetRed = visuals[i].offsetRed;
  154.         oldvis[i].offsetGreen = visuals[i].offsetGreen;
  155.         oldvis[i].offsetBlue = visuals[i].offsetBlue;
  156.     }
  157. }
  158.  
  159. #endif /* MIPS_4BIT */
  160.