home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / mips / mipsFb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-18  |  4.7 KB  |  182 lines

  1. /*
  2.  * $XConsortium: mipsFb.c,v 1.4 91/07/18 22:58:16 keith Exp $
  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.4 91/07/18 22:58:16 keith Exp $"
  24.  
  25. #include <sys/types.h>
  26. #include <sysv/sys/grafreg.h>
  27. #include <sysv/sys/termio.h>
  28. #include <sysv/sys/kbd_ioctl.h>
  29.  
  30. #include <X.h>
  31. #include <Xproto.h>
  32. #include <misc.h>
  33. #include <colormapst.h>
  34. #include <input.h>
  35. #include <scrnintstr.h>
  36.  
  37. #include "mips.h"
  38. #include "mipsFb.h"
  39. #include "mipsKbd.h"
  40. #include "mipsIo.h"
  41.  
  42. extern int defaultColorVisualClass;
  43. extern int mipsMonitorSize;
  44.  
  45. static void mipsWriteCMapIoctl();
  46. static int mcfbCheckDepth();
  47.  
  48. /* generic initialization for color FBs */
  49. mipsInitColor(pm)
  50.     MipsScreenPtr pm;
  51. {
  52.     pm->bitsPerPixel = 8;
  53.     pm->depth = mipsCheckDepth(pm->fbnorm);
  54.     /* measured on 19" and 16" Sony monitors */
  55.     pm->dpi = mipsMonitorSize ? 96 : 110;
  56.     pm->scr_width = 1280;
  57.     pm->scr_height = 1024;
  58.  
  59.     /* need to open keyboard for colormap access */
  60.     openKeybd();
  61.  
  62.     pm->WriteCMap = mipsWriteCMapIoctl;
  63. }
  64.  
  65. /*ARGSUSED*/
  66. static void
  67. mipsWriteCMapIoctl(pm, pmap)
  68.     MipsScreenPtr pm;
  69.     ColormapPtr pmap;
  70. {
  71.     int n;
  72.     Entry *in;
  73.     unsigned char *out;
  74.     struct colorm cm;
  75.  
  76.     n = pmap->pVisual->ColormapEntries;
  77.     in = pmap->red;
  78.  
  79.     cm.cmstart = 0;
  80.     cm.cmcount = n;
  81.     out = cm.cmap;
  82.  
  83.     while (--n >= 0) {
  84.         out[0] = in->co.local.red >> 8;
  85.         out[1] = in->co.local.green >> 8;
  86.         out[2] = in->co.local.blue >> 8;
  87.         in++;
  88.         out += 3;
  89.     }
  90.  
  91.     if (keybdPriv.cap & DEV_COLORMAP)
  92.         if (sysvIoctl(keybdPriv.fd, KTCWRTCOLOR, &cm) < 0) {
  93.             keybdPriv.cap &= ~DEV_COLORMAP;
  94.             Error("KTCWRTCOLOR ioctl failed");
  95.         }
  96. }
  97.  
  98. /*
  99.  * Check 8 bit frame buffer to see how many planes are populated.
  100.  */
  101. static int
  102. mipsCheckDepth(fb)
  103.     volatile u_char *fb;
  104. {
  105.     int depth = 8;
  106.     u_char fb0, fb1;
  107.  
  108.     fb0 = fb[0];
  109.     fb1 = fb[1];
  110.     fb[0] = 0x5a;
  111.     fb[1] = 0xa5;
  112.  
  113.     if (fb[0] != 0x5a || fb[1] != 0xa5)
  114.         depth = 4;
  115.  
  116.     fb[0] = fb0;
  117.     fb[1] = fb1;
  118.  
  119.     return depth;
  120. }
  121.  
  122. /*
  123.  * Special CFB initialization code...
  124.  *
  125.  * To support 4 bit gray scale systems, we overwrite the visuals table
  126.  * in cfb/cfbscrinit.c.  This is not elegant but at least we don't
  127.  * have to modify the MIT code.
  128.  */
  129.  
  130. #define    PSZ    4
  131. #define _BP 8
  132. #define _RZ ((PSZ + 2) / 3)
  133. #define _RS 0
  134. #define _RM ((1 << _RZ) - 1)
  135. #define _GZ ((PSZ - _RZ + 1) / 2)
  136. #define _GS _RZ
  137. #define _GM (((1 << _GZ) - 1) << _GS)
  138. #define _BZ (PSZ - _RZ - _GZ)
  139. #define _BS (_RZ + _GZ)
  140. #define _BM (((1 << _BZ) - 1) << _BS)
  141. #define _CE (1 << _RZ)
  142.  
  143. static VisualRec visuals[] = {
  144. /* vid  class        bpRGB cmpE nplan rMask gMask bMask oRed oGreen oBlue */
  145. #ifndef STATIC_COLOR
  146.     0,  PseudoColor, _BP,  1<<PSZ,   PSZ,  0,   0,   0,   0,   0,   0,
  147.     0,  DirectColor, _BP, _CE,       PSZ,  _RM, _GM, _BM, _RS, _GS, _BS,
  148.     0,  GrayScale,   _BP,  1<<PSZ,   PSZ,  0,   0,   0,   0,   0,   0,
  149.     0,  StaticGray,  _BP,  1<<PSZ,   PSZ,  0,   0,   0,   0,   0,   0,
  150. #endif
  151.     0,  StaticColor, _BP,  1<<PSZ,   PSZ,  _RM, _GM, _BM, _RS, _GS, _BS,
  152.     0,  TrueColor,   _BP, _CE,       PSZ,  _RM, _GM, _BM, _RS, _GS, _BS
  153. };
  154.  
  155. #define    NUMVISUALS    ((sizeof visuals)/(sizeof visuals[0]))
  156.  
  157. mipsFixScreen4(pScreen)
  158.     ScreenPtr pScreen;
  159. {
  160.     VisualPtr oldvis;
  161.     int i;
  162.  
  163.     if (defaultColorVisualClass < 0)
  164.         defaultColorVisualClass = GrayScale;
  165.  
  166.     oldvis = pScreen->visuals;
  167.  
  168.     for (i = 0; i < NUMVISUALS; i++) {
  169.         oldvis[i].bitsPerRGBValue =
  170.             visuals[i].bitsPerRGBValue;
  171.         oldvis[i].ColormapEntries =
  172.             visuals[i].ColormapEntries;
  173.         oldvis[i].nplanes = visuals[i].nplanes;
  174.         oldvis[i].redMask = visuals[i].redMask;
  175.         oldvis[i].greenMask = visuals[i].greenMask;
  176.         oldvis[i].blueMask = visuals[i].blueMask;
  177.         oldvis[i].offsetRed = visuals[i].offsetRed;
  178.         oldvis[i].offsetGreen = visuals[i].offsetGreen;
  179.         oldvis[i].offsetBlue = visuals[i].offsetBlue;
  180.     }
  181. }
  182.