home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / tek / pegInit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-27  |  50.6 KB  |  1,871 lines

  1. /* $XConsortium: pegInit.c,v 1.6 91/02/22 21:53:38 keith Exp $ */
  2. /***********************************************************
  3. Portions modified by Tektronix, Inc.  Copyright 1987 Tektronix, Inc.
  4.  
  5. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  6. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  7.  
  8.                         All Rights Reserved
  9.  
  10. Permission to use, copy, modify, and distribute this software and its 
  11. documentation for any purpose and without fee is hereby granted, 
  12. provided that the above copyright notice appear in all copies and that
  13. both that copyright notice and this permission notice appear in 
  14. supporting documentation, and that the names of Digital or MIT not be
  15. used in advertising or publicity pertaining to distribution of the
  16. software without specific, written prior permission.  
  17.  
  18. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  20. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  21. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  22. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  23. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  24. SOFTWARE.
  25.  
  26. ******************************************************************/
  27. #include "X.h"
  28. #include "Xproto.h"
  29. #include "screenint.h"
  30. #include "input.h"
  31. #include "cursor.h"
  32. #include "miscstruct.h"
  33. #include "scrnintstr.h"
  34. #include "servermd.h"
  35. #include "resource.h"
  36. #include "colormapst.h"
  37. #include "dixstruct.h"
  38. #include "mistruct.h"
  39. #include "peg.h"
  40. #ifdef NOTDEF
  41. #include "drawable.h"
  42. #include "pfb.h"
  43. #endif
  44.  
  45. #ifdef    UTEK
  46. #include "box/keyboard.h"
  47. #endif    /* UTEK */
  48.  
  49. #ifdef    UTEKV
  50. #include "redwing/keyboard.h"
  51. #endif    /* UTEKV */
  52.  
  53. #include <sys/time.h>
  54. #include <sys/resource.h>
  55.  
  56. #ifdef    UTEK
  57. #include <sys/mman.h>
  58. #endif    /* UTEK */
  59.  
  60. #ifdef    UTEKV
  61. #include <sys/ipc.h>
  62. #endif    /* UTEKV */
  63.  
  64. #include <sys/stat.h>
  65. #include <sys/file.h>
  66.  
  67. #ifdef    XDEBUG
  68. #include <sys/signal.h>
  69. #endif    /*XDEBUG */
  70.  
  71. #undef NULL            /* misc.h defines this, but so does stdio.h */
  72. #include <stdio.h>
  73.  
  74. #ifdef    UTEKV
  75. #include <sys/fcntl.h>
  76. #endif    /* UTEKV */
  77.  
  78. #ifdef    UTEKV
  79.  
  80.  
  81. #define DEBUG_ERRNO_IS_SET 1
  82. #define    DEBUG_SHMGET 1        /* add debug -shmget- & -shmat- messages */
  83. #define    DEBUG_VISUALSTUFF 1    /* add debug visual type stuff messages */
  84.  
  85.  extern int    shmget();    /* memory mapper */
  86.  extern caddr_t shmat();    /* memory attacher */
  87.  
  88. #ifndef    NBPC
  89. #define    NBPC    (4096)    /* number of bytes per click (page) */
  90. #endif    /* NBPC */
  91.  
  92. #ifndef    NCPS
  93. #define    NCPS    (1024)    /* number of clicks (pages) per segment */
  94. #endif    /* NCPS */
  95.  
  96. #ifndef    NBPS
  97. #define    NBPS    (NBPC*NCPS)    /* number of bytes per segment */
  98. #endif    /* NBPS */
  99.  
  100. /*
  101.  * Redwing display board type #2 "handy" definitions::
  102.  * (derived from "dislpay.h")
  103.  */
  104. #define    OFFSET_VIDEO_REG    (DS_VIDEO_CNTL_P - DS_DSP_BASE)
  105. #define    OFFSET_CDP_0_REG    (DS_CDP_0_P - DS_DSP_BASE)
  106. #define    OFFSET_STENCIL_FB    (DS_FB_STENCIL_P - DS_DSP_BASE)
  107. #define    OFFSET_TWO_COLOR_FB    (DS_FB_TWO_COLOR_P - DS_DSP_BASE)
  108. #define    OFFSET_PPM_FB        (DS_FB_PP_P - DS_DSP_BASE)
  109. #define    DS_NUMBER_OF_BYTES    (DS_FB_PP_HI_P+1-DS_DSP_BASE)
  110. #define    DS_NUMBER_OF_CLICKS    ((DS_NUMBER_OF_BYTES+(NBPC-1)) / NBPC)
  111. #define    DS_NUMBER_OF_SEGMENTS    ((DS_NUMBER_OF_CLICKS+(NCPS-1)) / NCPS)
  112.  
  113. /* 
  114.  * "shmget/shmat" flags:: Physical + Cache Inbibit + No Clear.
  115.  */
  116. #define PHYS_FLAGS     (IPC_PHYS | IPC_CI | IPC_NOCLEAR)
  117. #define PHYS_HIGH_ADDR    (0x60000000)  /* an area between u and display board */
  118.  
  119. #endif    /* UTEKV */
  120.  
  121. #define NUMSCREENS 1
  122.  
  123. static int FMonochrome = FALSE;
  124.  
  125. /*
  126.  * PixmapFormatRec is depth, bitsPerPixel, scanlinePad
  127.  */
  128.  
  129. static PixmapFormatRec    OneBitFormats[] = {
  130.     1, 1, BITMAP_SCANLINE_PAD,    /* 1-bit deep */
  131.     0
  132. };
  133.  
  134. static PixmapFormatRec    EightBitFormats[] = {
  135.     1, 1, BITMAP_SCANLINE_PAD,    /* 1-bit deep */
  136.     8, 8, BITMAP_SCANLINE_PAD,    /* 8-bit deep */
  137.     0
  138. };
  139.  
  140. #define    ROOTVISUAL    (0)
  141. #define    ArrayLength(list)    ((sizeof list)/(sizeof list[0]))
  142.  
  143. #define    TOGGLE        1
  144. #define    NUMBER        2
  145. #define    NUMBER_LIST    3
  146.  
  147. typedef struct _Control {
  148.     char    *envVar;    /* environment variable name to examine */
  149.     char    *fileVar;    /* control file variable to examine */
  150.     char    *defVal;    /* default value string */
  151.     union uval {        /* holds assignable addresses */
  152.         Bool    toggle;    /* for flavor = TOGGLE */
  153.         long    *nList;    /* for flavor = NUMBER_LIST */
  154.         long    number;    /* for flavor = NUMBER */
  155.     } *u;
  156.     long    *count;        /* addr of count for NUMBER_LIST */
  157.     int    flavor;        /* type of control variable. */
  158.     int    allocated;    /* u->nList is from Xalloc */
  159. } Control;
  160.  
  161. static Control    CList[] = {
  162.     {    "JOYPAN",
  163.     ".joydisk.pan",
  164.     "OFF",
  165.     (union uval *) &pegInfo.kv.panEnabled,
  166.     (long *) 0,
  167.     TOGGLE,0  },
  168.     {    "XPANSTOP",
  169.     ".joydisk.stop",
  170.     "ON",
  171.     (union uval *) &pegInfo.kv.panStop,
  172.     (long *) 0,
  173.     TOGGLE,0  },
  174.     {    "XPANINERTIA",
  175.     ".joydisk.inertia",
  176.     "1",
  177.     (union uval *) &pegInfo.kv.panInertia,
  178.     (long *) 0,
  179.     NUMBER,0  },
  180.     {    "XPANDELAYS",
  181.     ".joydisk.delays",
  182.     "128 64 48 48 32 32 16 1 1 1 1 1 1 1 1 1",    /* milliseconds */
  183.     (union uval *) &pegInfo.kv.panDelays,
  184.     &pegInfo.kv.nPanDelays,
  185.     NUMBER_LIST,0  },
  186.     {    "XPANDELTAX",
  187.     ".joydisk.xdeltas",
  188.     "1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8",
  189.     (union uval *) &pegInfo.kv.panDeltaX,
  190.     &pegInfo.kv.nPanDeltaX,
  191.     NUMBER_LIST,0  },
  192.     {    "XPANDELTAY",
  193.     ".joydisk.ydeltas",
  194.     "1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8",
  195.     (union uval *) &pegInfo.kv.panDeltaY,
  196.     &pegInfo.kv.nPanDeltaY,
  197.     NUMBER_LIST,0  },
  198.     {    "XKEYDELAYS",
  199.     ".keyrepeat",
  200.     "500 96 96 96 96 80 80 80 64 64 48 48 32 32", /* milliseconds */
  201.     (union uval *) &pegInfo.kv.keyDelays,
  202.     &pegInfo.kv.nKeyDelays,
  203.     NUMBER_LIST,0  },
  204.     { NULL }
  205. };
  206.  
  207. InitInfo    pegInfo;
  208. extern errno;
  209.  
  210.  
  211. /*
  212.  *    NAME
  213.  *        AbortDDX - Device dependent cleanup
  214.  *
  215.  *    SYNOPSIS
  216.  */
  217. void
  218. AbortDDX()
  219. /*
  220.  *    DESCRIPTION
  221.  *        Routine required for dix/ddx interface.  Called by
  222.  *        FatalError().  We don't need to do anything here
  223.  *        because closing /dev/xdev does it all.
  224.  *
  225.  *    RETURNS
  226.  *        None
  227.  *
  228.  */
  229. {
  230. }
  231.  
  232. /*
  233.  *    NAME
  234.  *        ddxGiveUp - Device dependent cleanup
  235.  *
  236.  *    SYNOPSIS
  237.  */
  238. void
  239. ddxGiveUp()
  240. /*
  241.  *    DESCRIPTION
  242.  *        Routine required for dix/ddx interface.  Called by
  243.  *        by dix before normal server death.
  244.  *        We don't need to do anything here
  245.  *        because closing /dev/xdev does it all.
  246.  *
  247.  *    RETURNS
  248.  *        None
  249.  *
  250.  */
  251. {
  252. }
  253.  
  254. /*
  255.  *    NAME
  256.  *        ddxProcessArgument - Process device-dependent command line args
  257.  *
  258.  *    SYNOPSIS
  259.  */
  260. int
  261. ddxProcessArgument (argc, argv, i)
  262.     /*ARGSUSED*/
  263.     int argc;
  264.     char *argv[];    /* in: commandline */
  265.     int i;        /* in: current index into argv */
  266. /*
  267.  *    DESCRIPTION
  268.  *        Process command line.    Part of dix/ddx interface.
  269.  *
  270.  *    RETURNS
  271.  *        0 if argument is not device dependent, otherwise
  272.  *        Count of number of elements of argv that are part of a 
  273.  *        device dependent commandline option.
  274.  *
  275.  */
  276. {
  277. #ifdef XDEBUG
  278.     if ( strncmp( argv[i], "-debug=", 7) == 0) {
  279.     sscanf(argv[ i ] + 7, "%x", &xflg_debug); 
  280.     return 1;
  281.     }
  282. #endif /* XDEBUG */
  283.     if ( strcmp( argv[i], "-mono") == 0) {
  284.     FMonochrome = TRUE;
  285.     return 1;
  286.     }
  287. #ifdef NOTDEF
  288.     if ( strcmp( argv[i], "-g") == 0) {
  289.     FGammaCorrectionDisabled = FALSE;
  290.     return 1;
  291.     }
  292. #endif
  293.  
  294.     return 0;
  295. }
  296.  
  297. /*
  298.  *    NAME
  299.  *        ddxUseMsg - print use of device dependent commandline options
  300.  *
  301.  *    SYNOPSIS
  302.  */
  303. void
  304. ddxUseMsg()
  305. /*
  306.  *    DESCRIPTION
  307.  *        Print out correct use of device dependent commandline options.
  308.  *        Part of dix/ddx interface.  Called by dix UseMsg routine.
  309.  *
  310.  *    RETURNS
  311.  *        None
  312.  *
  313.  */
  314. {
  315. #ifdef XDEBUG
  316.     ErrorF("-debug=hex mask        set debug bits; messages in /tmp/xdebug\n");
  317.     ErrorF("-mono                  use monochrome frame buffer\n");
  318. #endif /* XDEBUG */
  319.     ErrorF("-g                     enable gamma correction\n");
  320. }
  321.  
  322. /*
  323.  *    This function checks to see if the line L conforms to the syntax for
  324.  *    control option and value, and if so, puts these parsed out strings
  325.  *    in the string space referenced by O & V.
  326.  *    Returns success or failure (1 or 0).
  327.  */
  328. static Bool
  329. ParseOptionAndValue(L, O, V)
  330.     char *L;    /* in: line of text */
  331.     char *O;    /* in/out: pointer to Option */
  332.     char *V;    /* in/out: pointer to Value */
  333. {
  334.     char *ptr;
  335.     char *colon;
  336.     char *point;
  337.     /*
  338.      *    The assumed form is
  339.      *            [white].option1[.option2][white]:[white]<value>
  340.      *    where <value> is a series of one or more fields separated by white
  341.      *
  342.      *    Do some cheap checking for a colon and period
  343.      *    and their relative placement
  344.      */
  345.     if ((colon = index(L, ':')) == NULL)
  346.     return(False);
  347.     if ((point = index(L, '.')) == NULL)
  348.     return(False);
  349.     if (point > colon)
  350.     return(False);
  351.  
  352.     /*
  353.      *    Parse out the option
  354.      */
  355.     L += strspn(L, " \t");    /* first cut off leading white */ 
  356.     if ((ptr = strpbrk(L, " \t:")) == NULL) /* grab all up to separator */
  357.     return(0);        /* there at least better be a colon */
  358.     *ptr++ = '\0';        /* put null at first white or colon */
  359.     (void) strcpy(O, L);    /* passes so far, so copy it out */
  360.     /*
  361.      *    Parse out the value
  362.      */
  363.     strcpy(V, ptr + strspn(ptr, " \t:")); /* copy up to white and colon */
  364.     return(1);
  365. }
  366.  
  367. /*
  368.  *    This function fills an array of longs with V if all of V
  369.  *    is good, otherwise the array argument is returned unchanged.
  370.  *    The array is freed if it is changed.
  371.  */
  372. static void
  373. ConvertValues(param, value)
  374.     Control *param;    /* in/out: the address of the control parameter */
  375.     char    *value;    /* in: the value string composed of fields */
  376. {
  377.     /*
  378.      *    Rules:    If bad data anywhere, reject the whole value string
  379.      *        and dont change    array.
  380.      *        Bad data is any field not converting to a positive 
  381.      *        integer
  382.      */
  383.     long *tmpArray;
  384.     char *fieldPtr, *tmpValue;
  385.     int len = 0;
  386.  
  387.     /*
  388.      * We need to preserve the default value for possible server
  389.      * resets.  Therefore we copy the default string value to
  390.      * a local copy before calling strtok() which will alter the
  391.      * string contents.
  392.      */
  393.     tmpValue = (char *) Xalloc((strlen(value) + 1));
  394.     strcpy(tmpValue, value);
  395.     fieldPtr = strtok(tmpValue, " \t\n");
  396.  
  397.     if (param->flavor == TOGGLE || param->flavor == NUMBER) {
  398.     char *nextFieldPtr = strtok(0, " \t\n");
  399.  
  400.     if (nextFieldPtr == NULL) {/* nothing else trailing this */
  401.  
  402.         if (param->flavor == TOGGLE) {
  403.         if ((strcmp(fieldPtr, "ON") == 0)
  404.             || (strcmp(fieldPtr, "on") == 0))
  405.             param->u->toggle = True;
  406.         else if ((strcmp(fieldPtr, "OFF") == 0)
  407.             || (strcmp(fieldPtr, "off") == 0))
  408.             param->u->toggle = False;
  409.         }
  410.         else if (param->flavor == NUMBER) {
  411.         int number = atol(fieldPtr);
  412.         if (number != 0)
  413.             param->u->number = number;
  414.         }
  415.     }
  416.  
  417.     } else { /* must be a NUMBER_LIST */
  418.     assert (param->flavor == NUMBER_LIST);
  419.     tmpArray = (long *)Xalloc((len+1) * sizeof(long));
  420.     while (fieldPtr != NULL) {
  421.         tmpArray = (long *)Xrealloc(tmpArray, (len+2) * sizeof(long));
  422.         tmpArray[ len ] = atol(fieldPtr);
  423.  
  424.         /* if we've already parsed some numbers, error */
  425.         if (tmpArray[ len ] == 0) {
  426.         Xfree( (char *) tmpArray);
  427.         Xfree( tmpValue);
  428.         return;
  429.         }
  430.         fieldPtr = strtok(0, " \t\n");
  431.         len++;
  432.     }
  433.     if (param->u->nList && param->allocated)
  434.         Xfree( (char *) param->u->nList );
  435.     tmpArray[ len ] = 0;
  436.     param->u->nList = tmpArray;
  437.     param->allocated = TRUE;
  438.     *param->count = len;
  439.     }
  440.  
  441.     Xfree( tmpValue);
  442.     return;
  443. }
  444.  
  445. static ColormapPtr pegInstalledMap;
  446.  
  447. extern int TellLostMap(), TellGainedMap();
  448.  
  449. static void
  450. pegStoreColors (pmap, ndef, pdefs)
  451.     ColormapPtr    pmap;
  452.     int        ndef;
  453.     xColorItem    *pdefs;
  454. {
  455.     SvcColorDef    svcmap[256];
  456.     register int i;
  457.  
  458.     if (pmap != pegInstalledMap)
  459.     return;
  460.     for (i = 0; i < ndef; i++)
  461.     {
  462.     svcmap[i].pixel = pdefs->pixel;
  463.     svcmap[i].red = pdefs->red;
  464.     svcmap[i].green = pdefs->green;
  465.     svcmap[i].blue = pdefs->blue;
  466.     pdefs++;
  467.     }
  468.     SetColorMap (ndef, svcmap);
  469. }
  470.  
  471. static void
  472. pegInstallColormap (cmap)
  473.     ColormapPtr    cmap;
  474. {
  475.     register int i;
  476.     register Entry *pent;
  477.     register VisualPtr pVisual = cmap->pVisual;
  478.     SvcColorDef    svcmap[256];
  479.  
  480.     if (cmap == pegInstalledMap)
  481.     return;
  482.     if (pegInstalledMap)
  483.     WalkTree(pegInstalledMap->pScreen, TellLostMap,
  484.          (pointer) &(pegInstalledMap->mid));
  485.     if ((pVisual->class | DynamicClass) == DirectColor) {
  486.     for (i = 0; i < 256; i++) {
  487.         svcmap[i].pixel = i;
  488.         pent = &cmap->red[(i & pVisual->redMask) >>
  489.                   pVisual->offsetRed];
  490.         svcmap[i].red = pent->co.local.red;
  491.         pent = &cmap->green[(i & pVisual->greenMask) >>
  492.                 pVisual->offsetGreen];
  493.         svcmap[i].green = pent->co.local.green;
  494.         pent = &cmap->blue[(i & pVisual->blueMask) >>
  495.                    pVisual->offsetBlue];
  496.         svcmap[i].blue = pent->co.local.blue;
  497.     }
  498.     } else {
  499.     for (i = 0, pent = cmap->red;
  500.          i < pVisual->ColormapEntries;
  501.          i++, pent++) {
  502.         svcmap[i].pixel = i;
  503.         if (pent->fShared) {
  504.         svcmap[i].red = pent->co.shco.red->color;
  505.         svcmap[i].green = pent->co.shco.green->color;
  506.         svcmap[i].blue = pent->co.shco.blue->color;
  507.         }
  508.         else {
  509.         svcmap[i].red = pent->co.local.red;
  510.         svcmap[i].green = pent->co.local.green;
  511.         svcmap[i].blue = pent->co.local.blue;
  512.         }
  513.     }
  514.     }
  515.     pegInstalledMap = cmap;
  516.     SetColorMap (256, svcmap);
  517.     WalkTree(cmap->pScreen, TellGainedMap, (pointer) &(cmap->mid));
  518. }
  519.  
  520. static void
  521. pegUninstallColormap(cmap)
  522.     ColormapPtr    cmap;
  523. {
  524.     if (cmap == pegInstalledMap) {
  525.     Colormap defMapID = cmap->pScreen->defColormap;
  526.  
  527.     if (cmap->mid != defMapID) {
  528.         ColormapPtr defMap = (ColormapPtr) LookupIDByType(defMapID,
  529.                                   RT_COLORMAP);
  530.  
  531.         if (defMap)
  532.         (*cmap->pScreen->InstallColormap)(defMap);
  533.         else
  534.             ErrorF("peg: Can't find default colormap\n");
  535.     }
  536.     }
  537. }
  538.  
  539. pegListInstalledColormaps(pScreen, pCmapList)
  540.     ScreenPtr    pScreen;
  541.     Colormap    *pCmapList;
  542. {
  543.     *pCmapList = pegInstalledMap->mid;
  544.     return (1);
  545. }
  546.  
  547. /*
  548.  * This routine will eventually receive a signal, reinitializing the bell
  549.  * strings.  This way, bells could be configured by an external program
  550.  * and then signal X when it is ready.
  551.  */
  552. static void
  553. pegInitBells(sig)
  554.     int    sig;
  555. {
  556.     char    bellname[ BUFSIZ ], *string;
  557.     static Bool    initialized = FALSE;
  558.     struct stat    st;
  559.     int    fd, i, red;
  560.  
  561.     if (sig || ! initialized) {
  562.         initialized = TRUE;
  563.         pegInfo.bells.fd = -1;
  564.         for (i=0; i<8; i++) {
  565.             sprintf(bellname, BELLNAME, i);
  566. #ifdef    UTEK
  567.             fd = open(bellname, O_RDONLY);
  568. #endif    /* UTEK */
  569. #ifdef    UTEKV
  570.             fd = open(bellname, O_RDONLY);
  571. #endif    /* UTEKV */
  572.             if (fd < 0 || fstat(fd, &st) < 0) {
  573.                 if (fd >= 0)
  574.                     close(fd);
  575.                 Error(bellname);
  576.                 continue;
  577.             }
  578.             string = (char *)Xalloc(st.st_size);
  579.             if (string == NULL) {
  580.                 close(fd);
  581.                 ErrorF("can't alloc space for %s\n", bellname);
  582.                 continue;
  583.             }
  584.             red = read(fd, string, st.st_size);
  585.             close(fd);
  586.             if (red != st.st_size) {
  587.                 ErrorF("can't read from %s", bellname);
  588.                 Error("");
  589.                 continue;
  590.             }
  591. #ifdef NOTDEF
  592.             if (pegInfo.bells.str[ i ])
  593.                 Xfree (pegInfo.bells.str[ i ]);
  594. #endif
  595.             pegInfo.bells.len[ i ] = st.st_size;
  596.             pegInfo.bells.str[ i ] = string;
  597.         }
  598.  
  599.         if (pegInfo.bells.fd > 0)
  600.             close(pegInfo.bells.fd); /* just in case this helps */
  601. #ifdef    UTEK
  602.         pegInfo.bells.fd = open("/dev/bell", O_WRONLY);
  603. #endif    /* UTEK */
  604. #ifdef    UTEKV
  605.         pegInfo.bells.fd = open("/dev/bell", O_WRONLY);
  606. #endif    /* UTEKV */
  607.         if (pegInfo.bells.fd < 0)
  608.             Error("/dev/bell");
  609.         /*
  610.          * Insist on the file descriptor being > 0 so we can
  611.          * tell if it has been opened or not with having to initialize
  612.          * pegInfo.bells.fd to -1.
  613.          */
  614.         if (pegInfo.bells.fd == 0) {
  615.             fd = dup(pegInfo.bells.fd);
  616.             if (fd < 0)
  617.                 Error("dup on /dev/bell");
  618.             close(pegInfo.bells.fd);
  619.             pegInfo.bells.fd = fd;
  620.         }
  621.     }
  622. }
  623.  
  624.  
  625. /*
  626.  *    NAME
  627.  *        xtlInitBells - Initialization for XTL Keyboard bells.
  628.  *
  629.  *    SYNOPSIS
  630.  */
  631. static void
  632. xtlInitBells()
  633. /*
  634.  *    DESCRIPTION
  635.  *        Opens /dev/bell.
  636.  *
  637.  *    RETURNS
  638.  *        None
  639.  *
  640.  */
  641. {
  642.  
  643.     pegInfo.bells.fd = open("/dev/bell", O_WRONLY);
  644.     if (pegInfo.bells.fd < 0)
  645.     Error("/dev/bell");
  646. }
  647.  
  648. static Bool
  649. pegStructInit (pScreen, argc, argv)
  650.     ScreenPtr pScreen;
  651.     /*ARGSUSED*/
  652.     int argc;        /* these two may NOT be changed */
  653.     /*ARGSUSED*/
  654.     char **argv;
  655. {
  656.     int i;
  657.     FILE *filePtr;
  658.     char line[ BUFSIZ ];
  659.     char option[ BUFSIZ ];
  660.     char value[ BUFSIZ ];
  661.     char usrControlFile[ BUFSIZ ];
  662.     char *home, *envVal;
  663.     unsigned int pixMsk;
  664.  
  665. #ifdef XDEBUG
  666.  
  667.     extern int    SetDebug();
  668.  
  669. #ifdef    UTEK
  670.     signal(SIGIO, SetDebug);
  671. #endif    /* UTEK */
  672.  
  673. #ifdef    UTEKV
  674.     signal(SIGPOLL, SetDebug);
  675. #endif    /* UTEKV */
  676.  
  677. #endif /* XDEBUG */
  678.  
  679.     pegInfo.pScr = pScreen;
  680.  
  681.     /*
  682.      * Initialize the width and height variables.
  683.      * Perhaps save the current hardware CDP registers.
  684.      */
  685. #ifdef    UTEK
  686.     pegInfo.scrHeight = BITMAP_Y(pegInfo.softp);
  687.     pegInfo.width = BITMAP_X(pegInfo.softp);
  688.     pegInfo.height = BITMAP_Y(pegInfo.softp);
  689.     pegInfo.mmScreenX = MM_SCREEN_X(pegInfo.softp);
  690.     pegInfo.mmScreenY = MM_SCREEN_Y(pegInfo.softp);
  691.     pegInfo.entries = 1 << pegInfo.depth;
  692. #endif    /* UTEK */
  693.  
  694. #ifdef    UTEKV                       /* Redwing */
  695. #ifdef    M4810
  696.     pegInfo.scrHeight = BITMAP_Y(pegInfo.dsp);    /* 1024  (width set below)*/
  697.     pegInfo.width = BITMAP_X(pegInfo.dsp);    /* 2048 */
  698.     pegInfo.height = BITMAP_Y(pegInfo.dsp);    /* 1024 */
  699.     pegInfo.entries = 1 << pegInfo.depth;
  700. #endif    /* M4810 */
  701. #endif    /* UTEKV */
  702.  
  703.     /*
  704.      *    Process Control Variables
  705.      */
  706.     /* Set defaults */
  707.     for(i = 0; CList[i].envVar != NULL; i++) {
  708.     ConvertValues(&CList[i], CList[i].defVal);
  709.     }
  710.  
  711.     TekConfig(&pegInfo.mmScreenX, &pegInfo.mmScreenY);
  712.     /*
  713.      * If the Tek configuration database does not exist, we will not have
  714.      * the correct values for screen
  715.      * sizes.  The values should be -1 in this case; use these values instead:
  716.      * 4316/17 GMA-201/303 357mm (x) X 268mm (y)
  717.      * 4406    GMA-201     357mm (x) X 268mm (y)
  718.      * 4405/4315           235mm (x) X 175mm (y)
  719.      * 4319 (19")       343mm (x) X 274mm (y)
  720.      * XD88/10 Redwing (19") 343mm (x) X 274mm (y)
  721.      */
  722.  
  723. #ifdef    UTEK
  724.     switch (CPU_BOARD(pegInfo.softp)) { 
  725.     case HC_CPU_4406PLUS:
  726.     pegInfo.scrWidth = SCREEN_X(pegInfo.softp);
  727.     if (pegInfo.mmScreenX <= 0 || pegInfo.mmScreenY <= 0) {
  728.         pegInfo.mmScreenX = 357;
  729.         pegInfo.mmScreenY = 268;
  730.     }
  731.     break;
  732.     case HC_CPU_MULTIPLANE:
  733.     case HC_CPU_CROW:
  734.     pegInfo.scrWidth = SCREEN_X(pegInfo.softp);
  735.     if (pegInfo.mmScreenX <= 0 || pegInfo.mmScreenY <= 0) {
  736.         if (CPU_BOARD(pegInfo.softp) == HC_CPU_CROW) { /* 4319 */
  737.         pegInfo.mmScreenX = 343;
  738.         pegInfo.mmScreenY = 274;
  739.         } else { /* 4316/7 */
  740.         pegInfo.mmScreenX = 357;
  741.         pegInfo.mmScreenY = 268;
  742.         }
  743.     }
  744. #endif    /* UTEK */
  745.  
  746. #ifdef    UTEKV        /* only Redwing supported */
  747. #ifdef    M4810        /* only Redwing supported */
  748.     pegInfo.scrWidth = SCREEN_X(pegInfo.dsp);
  749.     pegInfo.mmScreenX = 343;    /* XD88/10 Redwing */
  750.     pegInfo.mmScreenY = 274;
  751. #endif    /* M4810 */
  752. #endif    /* UTEKV */
  753.  
  754.         /*
  755.          * If we are running with -mono option, then we need to initialize
  756.          * the CDP registers.  We should only need to do this once because
  757.          * the registers should never get changed.
  758.      *
  759.      * NOTE: A "feature" of UnlockDisplay() is that it resets all
  760.      * CDP registers to powerup defaults.  We must therefore set
  761.      * up our system to live with this.
  762.          */
  763. #ifdef UTEK
  764.     if (FMonochrome) {
  765.         int    i;
  766.  
  767.         printf ("Current write0Reg: 0x%x\n", pegInfo.cdpCtl->write0Reg);
  768.         printf ("Current write1Reg: 0x%x\n", pegInfo.cdpCtl->write1Reg);
  769.         printf ("Current planeEnableReg: 0x%x\n", pegInfo.cdpCtl->planeEnableReg);
  770.         printf ("Current filterReg: 0x%x\n", pegInfo.cdpCtl->filterReg);
  771.         printf ("Current maskRegSet: 0x%x\n", pegInfo.cdpCtl->maskRegSet);
  772.         for (i = 0; i < 5; i++)
  773.         printf ("Current extra[%d]: 0x%x\n", i, pegInfo.cdpCtl->pad[i]);
  774.  
  775.             pixMsk = (1 << N_PLANE(pegInfo.softp)) - 1;
  776.             pegInfo.cdpCtl->write1Reg = 0;        /* FOREGROUND */
  777.         if (DISPLAY_TYPE(pegInfo.softp) == 2)    /* (color) */
  778.         pegInfo.cdpCtl->write0Reg = 1;        /* BACKGROUND */
  779.         else
  780.         pegInfo.cdpCtl->write0Reg = pixMsk;    /* BACKGROUND */
  781.             pegInfo.cdpCtl->planeEnableReg = pixMsk;
  782.             pegInfo.cdpCtl->filterReg = 0;
  783.             pegInfo.cdpCtl->maskRegSet = ~0;
  784.         }
  785. #endif /* UTEK */
  786.  
  787. #ifdef UTEKV
  788.     if (FMonochrome) {
  789.             pixMsk = (1 << N_PLANE(pegInfo.dsp)) - 1;
  790.             pegInfo.cdpCtl->write1Reg = 0;        /* FOREGROUND */
  791.         if (DISPLAY_TYPE(pegInfo.dsp) == DISPLAY_2)    /* Redwing - color */
  792.         pegInfo.cdpCtl->write0Reg = 1;        /* BACKGROUND */
  793.         else
  794.         pegInfo.cdpCtl->write0Reg = pixMsk;    /* BACKGROUND */
  795.             pegInfo.cdpCtl->planeEnableReg = pixMsk;
  796.             pegInfo.cdpCtl->filterReg = 0;
  797.             pegInfo.cdpCtl->maskRegSet = ~0;
  798.         }
  799. #endif /* UTEKV */
  800.  
  801. #ifdef    UTEK
  802.     break;
  803.  
  804.     case HC_CPU_4405PLUS:
  805.     pegInfo.scrWidth = BITMAP_X(pegInfo.softp);
  806.     if (pegInfo.mmScreenX <= 0 || pegInfo.mmScreenY <= 0) {
  807.         pegInfo.mmScreenX = 235;
  808.         pegInfo.mmScreenY = 175;
  809.     }
  810. #endif    /* UTEK */
  811.  
  812.     CList[0].defVal = "ON"; /* panning is on for 4315 */
  813.     /*
  814.      * The 4315/4405+ workstations can use the X10 capability
  815.      * of customizing devices.  This is not present in any X11
  816.      * products.
  817.      */
  818.     /*
  819.      *    Process control files
  820.      */    
  821.     if ((filePtr = fopen(XSYSCONTROLS, "r")) != NULL) {
  822.         while (fgets(line, sizeof(line), filePtr) != NULL) {
  823.         if (ParseOptionAndValue(line, option, value)) {
  824.             for (i = 0; CList[i].envVar != (char *) NULL; i++)
  825.             if (strcmp(option, CList[i].fileVar) == 0)
  826.                 ConvertValues(&CList[i], value);
  827.         }
  828.         }
  829.         fclose(filePtr);
  830.     }
  831.  
  832.     home = getenv("HOME");
  833.     if (home != NULL) {
  834.         strcpy(usrControlFile, home);
  835.         strcat(usrControlFile, XUSRCONTROLS);
  836.     }
  837.  
  838.     if ((filePtr = fopen(usrControlFile, "r")) != NULL) {
  839.         while (fgets(line, sizeof(line), filePtr) != NULL) {
  840.         if (ParseOptionAndValue(line, option, value)) {
  841.             for (i = 0; strcmp(CList[i].envVar, (char *) NULL); i++)
  842.             if (strcmp(option, CList[i].fileVar) == 0)
  843.                 ConvertValues(&CList[i], value);
  844.         }
  845.         }
  846.         fclose(filePtr);
  847.     }
  848.  
  849.     /*
  850.      *    Process control environment variables
  851.      */
  852.     for (i = 0; strcmp(CList[i].envVar, (char *) NULL); i++)
  853.         if ((envVal = getenv(CList[i].envVar)) != NULL)
  854.         ConvertValues(&CList[i], envVal);
  855. #ifdef    UTEK
  856.     break;
  857.     default:
  858.     FatalError("cpu board unknown=%x\n", CPU_BOARD(pegInfo.softp));
  859.     /*NOTREACHED*/
  860.     }
  861. #endif    /* UTEK */
  862.  
  863.  
  864.     /*
  865.      * ensure that delay lists are correct.
  866.      */
  867.     if (pegInfo.kv.nPanDelays != pegInfo.kv.nPanDeltaX
  868.      || pegInfo.kv.nPanDelays != pegInfo.kv.nPanDeltaY) {
  869.     ErrorF("The number of pan deltas must equal the number");
  870.     ErrorF("of pan delays\n");
  871.     return (False);
  872.     }
  873.  
  874.     /*
  875.      * The Powerup Default Colormap is saved in this routine
  876.      * but is assumed to exist only for one screen.  If multiple screens
  877.      * are implemented, use arrays of size MAXSCREENS to store multiple
  878.      * default colormaps.
  879.      *
  880.      * These default entries will be used by
  881.      * pfbCreateColormap to initialize the colormaps.  The default
  882.      * entries use the X10 data structure ColorDef since that matches the 
  883.      * datastructure used by the SVC calls that manipulate the hardware
  884.      * colormaps.
  885.      *
  886.      * ColorDefDefault will be used by pfbCreateColormap.
  887.      * Note that they are allocated and assigned only once.
  888.      */
  889.     if (pegInfo.depth > 1 && pegInfo.colorDefDefault == NULL) {
  890.     int nEntries = pegInfo.entries;
  891.  
  892.     pegInfo.colorDefDefault =
  893.         (SvcColorDefPtr)Xalloc(sizeof(SvcColorDef)*pegInfo.entries);
  894.     if (pegInfo.colorDefDefault == NULL)
  895.         return (False);
  896.  
  897.     debug7(("pegScreenInit() - Get default hardware colormap\n"));
  898.  
  899.     /*
  900.      * Set machine default "powerup" colormap by passing NULL ptr::
  901.      */
  902.  
  903. #ifdef UTEKV
  904.     nEntries = 0;
  905.     if (SetColorMap(nEntries, (SvcColorDefPtr) 0 ) == -1) {
  906.         ErrorF("SetColorMap returned -failure-\n");
  907.         ErrorF("nEntries = %d\n", nEntries);
  908.         ErrorF("errno = %d\n", errno);
  909.         Error("\n");
  910.         return(False);
  911.       }
  912.  
  913.     /*
  914.      * Now fetch that machine default "powerup" colormap::
  915.      */
  916.     if (GetColorMap(&nEntries, pegInfo.colorDefDefault) == -1) {
  917.         ErrorF("GetColorMap returned -failure-\n");
  918.         ErrorF("errno = %d\n", errno);
  919.         Error("\n");
  920.         return(False);
  921.       }
  922. #else
  923.     /* original 4310 series code..... */
  924.     SetColorMap(nEntries, (SvcColorDefPtr) 0 );/* sets default color map */
  925.     GetColorMap(&nEntries, pegInfo.colorDefDefault);  /* returns cm_size */
  926. #endif
  927.  
  928.     assert(nEntries == pegInfo.entries);
  929.  
  930. #ifdef NOTDEF
  931.     debug7(("pegScreenInit() - Print ColorDefDefault\n"));
  932.     debugPrintCdef(nEntries,pegInfo.colorDefDefault);
  933. #endif
  934.     }
  935.  
  936.     return (True);
  937. }
  938.  
  939. #ifdef    UTEK
  940.  
  941. /*----------------------- M4310 series pegVmScreenInit -----------------------*/
  942.  
  943. static Bool
  944. pegVmScreenInit(argc, argv)
  945.     /*ARGSUSED*/
  946.     int argc;        /* these two may NOT be changed */
  947.     /*ARGSUSED*/
  948.     char **argv;
  949. {
  950.  
  951.     struct rlimit rl;
  952.     int    bitmapx = pegInfo.softp->sc_hdwr.screen_u.hc_screen.bitmap_x,
  953.     bitmapy = pegInfo.softp->sc_hdwr.screen_u.hc_screen.bitmap_y,
  954.     pixelSize,
  955.     twoColorSize,
  956.     configSize,
  957.     pageSize = getpagesize(),
  958.     offset;
  959.     long topAddr;    /* address calculation can get complex... */
  960.     caddr_t pixelFb = pegInfo.softp->sc_hdwr.screen_u.hc_screen.pixel_fb,
  961.         twoColorFb = pegInfo.softp->sc_hdwr.screen_u.hc_screen.fb_addr,
  962.         oneColorFb =
  963.         pegInfo.softp->sc_hdwr.screen_u.hc_screen.mono_stencil_fb,
  964.         videoCtlAddr = pegInfo.softp->sc_hdwr.screen_u.hc_screen.mono_ctl,
  965.         configAddr = pegInfo.softp->sc_info.sc_regs.config_physaddr;
  966.  
  967.     /*
  968.      * If the mapping is done, don't do it twice.
  969.      */
  970.     if (pegInfo.twoColorFb)
  971.     return (True);
  972.  
  973.     /*
  974.      * When we are all done, the stack will look like this for systems
  975.      * containing a packed mode frame buffer:
  976.      *    (frame buffers only shown here.  TOP is to left):
  977.      *
  978.      *        stack  unmapped  pixel-FB  1color-FB  2color-FB  page 
  979.      *              |        |                                      |
  980.      *    ---------------         ---------------------------------------
  981.      */
  982.  
  983.     rl.rlim_cur = STACK_SIZE;
  984.     rl.rlim_max = STACK_SIZE;
  985.     if (setrlimit(RLIMIT_STACK, &rl) < 0) {
  986.     ErrorF("Cannot set stack limit to 0x%x\n", STACK_SIZE);
  987.     return (False);
  988.     }
  989.  
  990.     /*
  991.      * The top of the frame buffer address space will be at least
  992.      * one page below the stack limit and page-aligned.  Use a stack
  993.      * variable address to start with.  Then assume that the top of
  994.      * the very stack is the page boundary above that.  Subtract off
  995.      * STACK_SIZE plus one page and that will be the address following
  996.      * the last byte in the first frame buffer.
  997.      */
  998.     topAddr = (long)&topAddr;
  999.     topAddr &= ( ~ (pageSize - 1));
  1000.     topAddr -= STACK_SIZE + pageSize;
  1001.  
  1002.     /*
  1003.      * Figure out the size needed for each frame buffer.  Note that the one
  1004.      * color frame buffer is the same size as the two color.
  1005.      */
  1006.     assert((bitmapx & 0x7) == 0);
  1007.     twoColorSize = (bitmapx >> 3) * bitmapy;
  1008.  
  1009.     if (pixelFb)
  1010.     pixelSize = (bitmapx * bitmapy * N_PLANE(pegInfo.softp)) / 8;
  1011.  
  1012.     /*
  1013.      * Now allocate space, moving downward from topAddr, starting with
  1014.      * the pixel framebuffer.
  1015.      */
  1016.     if (pixelFb) {
  1017.     topAddr -= pixelSize;
  1018.     /*
  1019.      * The 4316 and 4317 have a strange requirement that the frame
  1020.      * buffer be mapped at an ODD one-megabyte boundary.  This is
  1021.      * not true for Raven, et. al.
  1022.      */
  1023.     if (CPU_BOARD(pegInfo.softp) == HC_CPU_MULTIPLANE) {
  1024.         if (N_PLANE(pegInfo.softp) == 4) {
  1025.         topAddr &= ( ~ (ONE_MB - 1));    /* 1 Meg boundary */
  1026.         if ((topAddr & ONE_MB) == 0)
  1027.             topAddr -= ONE_MB;         /* odd 1 Meg boundary */
  1028.         }
  1029.         /* XXX
  1030.          *  This is only here for our Raven prototype.  The prototype must
  1031.          *  have a 4 MB alignment.  A real Raven doesn't need this special
  1032.          *  alignment.
  1033.          */
  1034.         else if (N_PLANE(pegInfo.softp) == 8) {
  1035.         topAddr &= ( ~ (FOUR_MB - 1));
  1036.         }
  1037.     }
  1038.     /*
  1039.      * Real Raven has no alignment restriction.  mmap has a page
  1040.      * alignment restriction.
  1041.      */
  1042.  
  1043.     pegInfo.pixelFb = (caddr_t)topAddr;
  1044.     if (mmap(M_PHYS, pixelFb, topAddr, pixelSize, SELF, SHARED) < 0) {
  1045.         ErrorF("Can't map pixel frame buffer\n");
  1046.         return (False);
  1047.     }
  1048.  
  1049.     topAddr = topAddr - twoColorSize;
  1050.     pegInfo.oneColorFb = (caddr_t)topAddr;
  1051.     if (mmap(M_PHYS, oneColorFb, topAddr, twoColorSize, SELF, SHARED) < 0) {
  1052.         ErrorF("Can't map one-color frame buffer\n");
  1053.         return (False);
  1054.     }
  1055.     }
  1056.  
  1057.     /*
  1058.      * The 4315 and 4406plus require that the frame buffer be mapped
  1059.      * at a boundary equal to the frame buffer size (256K).
  1060.      */
  1061.     if (CPU_BOARD(pegInfo.softp) == HC_CPU_4405PLUS
  1062.      || CPU_BOARD(pegInfo.softp) == HC_CPU_4406PLUS)
  1063.     topAddr &= ( ~ (twoColorSize - 1));
  1064.  
  1065.     topAddr = topAddr - twoColorSize;
  1066.     pegInfo.twoColorFb = (caddr_t)topAddr;
  1067.     if (mmap(M_PHYS, twoColorFb, topAddr, twoColorSize, SELF, SHARED) < 0) {
  1068.     ErrorF("Can't map two-color frame buffer\n");
  1069.     return (False);
  1070.     }
  1071.     /*
  1072.      * In many algorithms in pfb, we need to access one longword at a memory
  1073.      * location one longword less than the legitimate source address.  To
  1074.      * allow source drawables in the 2 color frame buffer, we need now to
  1075.      * allocate the memory word preceding twoColorFb.  We will actually
  1076.      * allocate a page because mmap requires us to use page aligned
  1077.      * addresses
  1078.      */
  1079.     topAddr -= pageSize;
  1080.     if (mmap(M_PHYS, twoColorFb, topAddr, pageSize, SELF, SHARED) < 0) {
  1081.     ErrorF("Can't map two-color frame buffer buffer\n");
  1082.     return (False);
  1083.     }
  1084.  
  1085.     /*
  1086.      * map software configuration block.
  1087.      * Note that we must align the hardware address on a page boundary,
  1088.      * remembering our offset.
  1089.      */
  1090.     configSize = (sizeof(struct soft_config) + pageSize - 1)
  1091.             & ( ~ (pageSize - 1));
  1092.     topAddr -= configSize + pageSize; /* skip one page */
  1093.     offset = (int)configAddr - ((int)configAddr & ~(pageSize-1));
  1094.     if (mmap(M_PHYS, configAddr-offset,
  1095.       topAddr, configSize, SELF, SHARED) < 0) {
  1096.     ErrorF("Can't map configuration block\n");
  1097.     return (False);
  1098.     }
  1099.  
  1100.     /* if they aren't identical, we mapped it wrong */
  1101.     assert(bcmp(topAddr+offset,pegInfo.softp,sizeof(struct soft_config)) == 0);
  1102.  
  1103.     pegInfo.softp = (struct soft_config *) (topAddr + offset);
  1104.     pegInfo.dsp = (XDisplayState *)pegInfo.softp->sc_eventque;
  1105.  
  1106.     /*
  1107.      * map video control register and
  1108.      *            setup pointer to kernel - video state shadow var..
  1109.      */
  1110.     topAddr -= pageSize * 2; /* skip one page */
  1111.     offset = (int)videoCtlAddr - ((int)videoCtlAddr & ~(pageSize-1));
  1112.     pegInfo.videoCtl = (caddr_t) topAddr + offset;
  1113.     if (mmap(M_PHYS, videoCtlAddr-offset, topAddr, pageSize, SELF, SHARED)<0) {
  1114.     ErrorF("Can't map video control register\n");
  1115.     return (False);
  1116.     }
  1117.     pegInfo.videostate = (unsigned short *) &pegInfo.softp->sc_videostate;
  1118.  
  1119.     /*
  1120.      * map Color Data Path (CDP) control register.
  1121.      */
  1122.     if (pixelFb) {
  1123.     caddr_t    cdpCtl;
  1124.  
  1125.     cdpCtl = (caddr_t)pegInfo.softp->sc_hdwr.screen_u.hc_screen.color_ctl;
  1126.     topAddr -= pageSize * 2; /* skip one page */
  1127.     offset = (int)cdpCtl - ((int)cdpCtl & ~(pageSize-1));
  1128.     pegInfo.cdpCtl = (COLOR_CNTL *) (topAddr + offset);
  1129.     if (mmap(M_PHYS, cdpCtl-offset, topAddr, pageSize, SELF, SHARED) < 0) {
  1130.         ErrorF("Can't map CDP\n");
  1131.         return (False);
  1132.     }
  1133.     }
  1134.     else {
  1135.     /* ???
  1136.      * This is here so that we can set color control registers harmlessly
  1137.      * on 4315/4406.  We can't set them willynilly on monochrome systems
  1138.      * because on n-plane systems in -mono mode, this could break stuff.
  1139.      * We could map cpdCtl to harmless memory on these systems too, but
  1140.      * do we want to lose the ability to set these regs on n-plane
  1141.      * systems?
  1142.      */
  1143.     pegInfo.cdpCtl = 
  1144.         (COLOR_CNTL *) Xalloc(sizeof(COLOR_CNTL));
  1145.     }
  1146.  
  1147.     return (True);
  1148. }
  1149.  
  1150. /*--------------- end of M4310 series pegVmScreenInit -----------------------*/
  1151.  
  1152. #endif    /* UTEK */
  1153.  
  1154.  
  1155.  
  1156. #ifdef    UTEKV
  1157. /*----------------------- M4810 series pegVmScreenInit -----------------------*/
  1158.  
  1159. static Bool
  1160. pegVmScreenInit(argc, argv)
  1161.     int argc;        /* these two may NOT be changed */
  1162.     char **argv;
  1163. {
  1164.  
  1165. #ifdef    M4810 /*------------- Redwing ---------------------------------------*/
  1166.  
  1167.     int    bitmapx, bitmapy, pixelSize, twoColorSize, configSize, pageSize, offset;
  1168.     int shMemId;    /* shared memory return id */
  1169.     caddr_t dspBaseAddr; /* mapped address of the base of the display board. */
  1170.     caddr_t caddrTemp;     /* handy reg */
  1171.     caddr_t segmentAddr; /* pleasant reg */
  1172.  
  1173.     /*
  1174.      * If the mapping is done, don't do it twice.
  1175.      */
  1176.     if (pegInfo.twoColorFb)
  1177.     return(True);
  1178.  
  1179.     /* 
  1180.      * Here is what is done in this "VmScreen" init code::
  1181.      *
  1182.      *    o   Fetch the X driver's physical address for the "shared memory"
  1183.      *        driver-to-server interface (display state and event queue).
  1184.      *        Note: This is done by making an ioctl call on the x-dev "eventFd"
  1185.      *        file descriptor.
  1186.      *
  1187.      *    o   Setup a shared/cache-inhibited/no-clear mapping of the
  1188.      *        "shared-memory" segment to a "higher" address. Note that the
  1189.      *        physical address of the "shared-memory" page(s) usually on the
  1190.      *        order of 0x0024A000/0x00024C000. This memory's "segment" will
  1191.      *        be mapped to a base of 0x60000000 (above the "u" area in kernel
  1192.      *      space however (0x40000000)
  1193.      *        and below the display board's base address: (0x80000000).
  1194.      *        "pegInit.dsp" points to this "shared-memory" "base".
  1195.      *        
  1196.      *        
  1197.      *    o   The Display Board's devices/memory/registers will be mapped
  1198.      *        into -one- segment, extending from "DS_DSP_BASE" (0x80000000)
  1199.      *        "DS_FB_PP_HI_P" (0x803fffff) (4MegaBytes);  mapped "two-to-one"
  1200.      *        at the same user virtual address as the kernel virtual address
  1201.      *        (and the same as the physical addresses).
  1202.      *
  1203.      *        Therefore, references to the individual display board devices
  1204.      *        will be from a device address calculated from the "segment base"
  1205.      *        plus the "offset" from the "base" address of the display board.
  1206.      *        
  1207.      *        
  1208.      *        
  1209.      *    o  Notes:
  1210.      *        1) NBPC (NumberOfBytesPerClick) = 4096 
  1211.      *        2) NCPS (NumberOfClicksPerSegment) = 1024
  1212.      *        
  1213.      *        
  1214.      *        
  1215.      *                            Steve Jensen
  1216.      */
  1217.  
  1218.  
  1219.     /* 
  1220.      *  Get page size... for future calculations.
  1221.      */ 
  1222.     pageSize = getpagesize();
  1223.     assert (pageSize == NBPC);
  1224.  
  1225.     /*
  1226.      * Get "shared" memory display structure/event buffer physical address.
  1227.      */
  1228.     if (ioctl(pegInfo.eventFd, CE_GETXDISPLAYSTRUCT, &caddrTemp) < 0) {
  1229.     ErrorF("CE_GETXDISPLAYSTRUCT returned value less than 0");
  1230.     Error("errno = ");
  1231.     return(False);
  1232.       }
  1233.  
  1234. #ifdef    DEBUG_SHMGET
  1235.     ErrorF("ioctl: CE_GETXDISPLAYSTRUCT returns -- \n");
  1236.     ErrorF("config. address = 0x%x\n", caddrTemp);
  1237.     ErrorF("\n");
  1238. #endif    /* DEBUG_SHMGET */
  1239.  
  1240.     /*
  1241.      * round size of displaystate to the greater page size boundary.
  1242.      */
  1243.     configSize = (sizeof(struct displaystate) + pageSize-1) & (~(pageSize-1));
  1244.     offset = (int) caddrTemp;    /* save the "offset" into 'the' segment */
  1245.  
  1246.     /*
  1247.      * map to segment aligned and a size of one segment.
  1248.      */
  1249.     shMemId = shmget(IPC_PRIVATE, NBPS, PHYS_FLAGS,
  1250.                  (int)caddrTemp & (~(NBPS-1)));
  1251.  
  1252.     if (shMemId == -1) {
  1253.     ErrorF("Can't -shmget- Xdriver shared block\n");
  1254.     ErrorF("mapping with: IPC_PRIVATE | IPC_CI | IPC_NOCLEAR\n");
  1255.     ErrorF("address = 0x%x\n", caddrTemp);
  1256.     Error("errno = ");
  1257.     return(False);
  1258.       }
  1259.  
  1260.     caddrTemp = ((caddr_t)(PHYS_HIGH_ADDR));
  1261.     segmentAddr = (caddr_t) (shmat(shMemId, caddrTemp, 0));
  1262.  
  1263.     if ((int) segmentAddr == -1) {
  1264.     ErrorF("Can't -shmat- shared segment\n");
  1265.     ErrorF("mapping with flags: 0\n");
  1266.     ErrorF("Id = 0x%x\n", shMemId);
  1267.     ErrorF("address = 0x%x\n", caddrTemp);
  1268.     ErrorF("segment address returned = 0x%x\n", segmentAddr);
  1269.     Error("errno = ");
  1270.     return(False);
  1271.       }
  1272.  
  1273.     /*
  1274.      * extract offset within segment::
  1275.      */
  1276.     offset = offset & (NBPS-1);
  1277.  
  1278.     /*
  1279.      * compute "real" address::
  1280.      */
  1281.     pegInfo.dsp = (XDisplayState *) (caddr_t) ((int) segmentAddr + offset);
  1282.  
  1283. #ifdef    DEBUG_SHMGET
  1284.     ErrorF("Mapping of shared segment sucessful.\n");
  1285.     ErrorF("shared segment mapped to virtual address = 0x%x\n", pegInfo.dsp);
  1286.     ErrorF("shared segment offset = 0x%x\n", offset);
  1287.     ErrorF("\n");
  1288. #endif    /* DEBUG_SHMGET */
  1289.  
  1290.     bitmapx = pegInfo.dsp->ds_fbBitmap_x;
  1291.     bitmapy = pegInfo.dsp->ds_fbBitmap_y;
  1292.  
  1293. #ifdef    DEBUG_SHMGET
  1294.     ErrorF("dumping -the- items of interest from -dsp-:\n");
  1295.     ErrorF("ds_maxx = %d\n", pegInfo.dsp->ds_maxx);
  1296.     ErrorF("ds_maxy = %d\n", pegInfo.dsp->ds_maxy);
  1297.     ErrorF("ds_minx = %d\n", pegInfo.dsp->ds_minx);
  1298.     ErrorF("ds_minxy= %d\n", pegInfo.dsp->ds_miny);
  1299.     ErrorF("ds_cWidth = %d\n", pegInfo.dsp->ds_cWidth);
  1300.     ErrorF("ds_cHeight = %d\n", pegInfo.dsp->ds_cHeight);
  1301.     ErrorF("ds_ltime = 0x%x\n", pegInfo.dsp->ds_ltime);
  1302.     ErrorF("ds_displayModel = %d\n", pegInfo.dsp->ds_displayModel);
  1303.     ErrorF("ds_ramdacDepth = %d\n", pegInfo.dsp->ds_ramdacDepth);
  1304.     ErrorF("ds_fbDepth = %d\n", pegInfo.dsp->ds_fbDepth);
  1305.     ErrorF("ds_fbBitmapx = %d\n", bitmapx);
  1306.     ErrorF("ds_fbBitmapy = %d\n", bitmapy);
  1307.     ErrorF("ds_fbScreen_x = %d\n", pegInfo.dsp->ds_fbScreen_x);
  1308.     ErrorF("ds_fbScreen_y = %d\n", pegInfo.dsp->ds_fbScreen_y);
  1309.     ErrorF("ds_fbLong_incr = %d\n", pegInfo.dsp->ds_fbLong_incr);
  1310.     ErrorF("ds_fbShort_incr = %d\n", pegInfo.dsp->ds_fbShort_incr);
  1311.     ErrorF("ds_fbByte_incr = %d\n", pegInfo.dsp->ds_fbByte_incr);
  1312.     ErrorF("\n");
  1313.     ErrorF("dumping -misc- items of interest from -dsp-:\n");
  1314.     ErrorF("videostate = 0x%x\n", pegInfo.dsp->videostate);
  1315.     ErrorF("keyboardlangidstyle = 0x%x\n", pegInfo.dsp->keyboardlangidstyle);
  1316.     ErrorF("xconsolepid = %d\n", pegInfo.dsp->xconsolepid);
  1317.     ErrorF("consolemsgbuffer = %d\n", ((int) pegInfo.dsp->consolemsgbuffer));
  1318.     ErrorF("\n");
  1319. #endif    /* DEBUG_SHMGET */
  1320.  
  1321.     assert(bitmapx != 0);
  1322.     assert(bitmapy != 0);
  1323.  
  1324.     shMemId = shmget(IPC_PRIVATE, DS_NUMBER_OF_BYTES, PHYS_FLAGS, DS_DSP_BASE);
  1325.     if (shMemId == -1) {
  1326.     ErrorF("Can't -shmget- display board\n");
  1327.     ErrorF("mapping with: IPC_PRIVATE | IPC_CI | IPC_NOCLEAR\n");
  1328.     ErrorF("size = 0x%x\n", DS_NUMBER_OF_BYTES);
  1329.     ErrorF("address = 0x%x\n", DS_DSP_BASE);
  1330.     Error("errno = ");
  1331.     return(False);
  1332.       }
  1333.  
  1334.     caddrTemp = shmat(shMemId, DS_DSP_BASE, 0);
  1335.     if ((int) caddrTemp == -1) { /* remember display board addrs = 0x80000000 */
  1336.     ErrorF("Can't -shmat- display board\n");
  1337.     ErrorF("mapping with flags: 0\n");
  1338.     ErrorF("Id = 0x%x\n", shMemId);
  1339.     ErrorF("address = 0x%x\n", DS_DSP_BASE);
  1340.     ErrorF("shmat returned = 0x%x\n", caddrTemp);
  1341.     Error("errno = ");
  1342.     return(False);
  1343.       }
  1344.  
  1345. #ifdef    DEBUG_SHMGET
  1346.     ErrorF("Display board mapped to address 0x%x  by -shmat-\n", caddrTemp);
  1347.     ErrorF("\n");
  1348. #endif    /* DEBUG_SHMGET */
  1349.  
  1350.     dspBaseAddr = caddrTemp;    /* establish the "display board" base address */
  1351.     pegInfo.twoColorFb = (caddr_t) ((int) dspBaseAddr + OFFSET_TWO_COLOR_FB);
  1352.     pegInfo.oneColorFb = (caddr_t) ((int) dspBaseAddr + OFFSET_STENCIL_FB);
  1353.     pegInfo.pixelFb = (caddr_t) ((int) dspBaseAddr + OFFSET_PPM_FB);
  1354.     pegInfo.cdpCtl = (COLOR_CNTL *) ((int) dspBaseAddr + OFFSET_CDP_0_REG);
  1355.     pegInfo.videoCtl = (caddr_t) ((int) dspBaseAddr + OFFSET_VIDEO_REG);
  1356.     pegInfo.videostate = (unsigned char *)
  1357.              &pegInfo.dsp->videostate; /* shadow reg */
  1358.  
  1359. #ifdef    DEBUG_SHMGET
  1360.     ErrorF("Display board is mapped at: 0x%x\n", dspBaseAddr);
  1361.     ErrorF("Two Color Frame buffer mapped at: 0x%x\n", pegInfo.twoColorFb);
  1362.     ErrorF("One Color/Stencil Frame buffer at: 0x%x\n", pegInfo.oneColorFb);
  1363.     ErrorF("PPM Frame buffer at: 0x%x\n", pegInfo.pixelFb);
  1364.     ErrorF("CDPs mapped at: 0x%x\n", pegInfo.cdpCtl);
  1365.     ErrorF("Video control-status register mapped at: 0x%x\n", pegInfo.videoCtl);
  1366.     ErrorF("Video control SHADOW var. mapped at: 0x%x\n", pegInfo.videostate);
  1367. #endif    /* DEBUG_SHMGET */
  1368.  
  1369.     /*
  1370.      * -Bill is going to think about this ... may mot be true for 88K blt code--
  1371.      *
  1372.      * In many algorithms in pfb, we need to access one longword at a memory
  1373.      * location one longword less than the legitimate source address.  To
  1374.      * allow source drawables in the 2 color frame buffer, we need now to
  1375.      * allocate the memory word preceding twoColorFb.  We will actually
  1376.      * allocate a page because mmap requires us to use page aligned
  1377.      * addresses
  1378.      */
  1379.  
  1380. #endif    /* M4810 **------------- Redwing -------------------------------------*/
  1381.  
  1382.     return (True);
  1383. }
  1384.  
  1385. /*--------------- end of M4810 series pegVmScreenInit -----------------------*/
  1386.  
  1387. #endif    /* UTEKV */
  1388.  
  1389. static Bool (*wrappedCloseScreen)();
  1390.  
  1391. static Bool
  1392. pegCloseScreen (i, pScreen)
  1393.     int        i;
  1394.     ScreenPtr    pScreen;
  1395. {
  1396.     int    ret;
  1397.  
  1398.     pScreen->CloseScreen = wrappedCloseScreen;
  1399.     ret =  (*pScreen->CloseScreen) (i, pScreen);
  1400.     (void) close (pegInfo.bells.fd);
  1401.     (void) close (pegInfo.eventFd);
  1402. }
  1403.  
  1404. /*
  1405.  * Screen Init for tek servers
  1406.  */
  1407. Bool
  1408. pegScreenInit (index, pScreen, argc, argv)
  1409.     int index;
  1410.     ScreenPtr pScreen;
  1411.     int argc;        /* these two may NOT be changed */
  1412.     char **argv;
  1413. {
  1414.     ColormapPtr    pColormap;
  1415.     CARD16    zero = 0, ones = ~0;
  1416.     int        i, j;
  1417.     int        useCfb;
  1418.     int        resolution;
  1419.  
  1420.     useCfb = pegInfo.depth != 1 && !FMonochrome;
  1421.  
  1422.     if (! pegVmScreenInit(argc, argv))
  1423.     return (False);
  1424.  
  1425.     if (! pegStructInit(pScreen, argc, argv))
  1426.     return (False);
  1427.  
  1428.     resolution = (254 * pegInfo.scrWidth) / (10 * pegInfo.mmScreenX);
  1429.  
  1430.     if (useCfb)
  1431.     {
  1432.     if (! cfbScreenInit (pScreen, (pointer) pegInfo.pixelFb,
  1433.                  pegInfo.scrWidth,
  1434.                  pegInfo.scrHeight,
  1435.                  resolution, resolution,
  1436.                  pegInfo.width))
  1437.         return FALSE;
  1438.         pScreen->InstallColormap    = pegInstallColormap;
  1439.         pScreen->UninstallColormap         = pegUninstallColormap;
  1440.         pScreen->ListInstalledColormaps    = pegListInstalledColormaps;
  1441.     pScreen->StoreColors            = pegStoreColors;
  1442.     }
  1443.     else
  1444.     {
  1445.     if (! mfbScreenInit (pScreen, (pointer) pegInfo.twoColorFb,
  1446.                  pegInfo.scrWidth,
  1447.                  pegInfo.scrHeight,
  1448.                  resolution, resolution,
  1449.                  pegInfo.width))
  1450.         return FALSE;
  1451.     }
  1452.  
  1453.     wrappedCloseScreen = pScreen->CloseScreen;
  1454.     pScreen->CloseScreen = pegCloseScreen;
  1455.  
  1456. #ifdef    UTEK
  1457.     /*
  1458.      * If display is a 4315,
  1459.      *    check if joydisk panning is enabled,
  1460.      *    set initial viewport to middle of display
  1461.      */
  1462.     if (CPU_BOARD(pegInfo.softp) == HC_CPU_4405PLUS) {
  1463.     SvcCursorXY vp;
  1464.  
  1465.     /*
  1466.      * Set the initial viewport to the middle of the screen
  1467.      */
  1468.     vp.x = pegInfo.dsp->ds_x - (pegInfo.softp->sc_vscreen_x>>1),
  1469.     vp.y = pegInfo.dsp->ds_y - (pegInfo.softp->sc_vscreen_y>>1);
  1470.     SetViewport(&vp);
  1471.     }
  1472. #endif    /* UTEK */
  1473.  
  1474.     ioctl(pegInfo.eventFd, CE_SETCONS, &pegInfo.consolePid);
  1475.     ioctl(pegInfo.eventFd, CE_EVENTS, NULL);
  1476.  
  1477.     /*
  1478.      * turn on screen.
  1479.      * X handles blanking, so turn off hardware screensaver
  1480.      * insure (one plane) screen 0 => black, 1=> white
  1481.      */
  1482.     DisplayOn();
  1483.     TimeoutOff();
  1484.  
  1485. #ifdef    UTEK
  1486.     if (CPU_BOARD(pegInfo.softp) == HC_CPU_4405PLUS || 
  1487.         CPU_BOARD(pegInfo.softp) == HC_CPU_4406PLUS)
  1488.     InvertVideo();
  1489. #endif    /* UTEK */
  1490.  
  1491.     pScreen->SaveScreen = pegSaveScreen;
  1492.  
  1493.     pScreen->DisplayCursor              = pegDisplayCursor;
  1494.     pScreen->RealizeCursor = pegRealizeCursor;
  1495.     pScreen->UnrealizeCursor = pegUnrealizeCursor;
  1496.     pScreen->SetCursorPosition = pegSetCursorPosition;
  1497.     pScreen->CursorLimits = pegCursorLimits;
  1498.     pScreen->PointerNonInterestBox = pegPointerNonInterestBox;
  1499.     pScreen->ConstrainCursor = pegConstrainCursor;
  1500.     pScreen->RecolorCursor = pegRecolorCursor;
  1501. /*
  1502.     pScreen->QueryBestSize = pegQueryBestSize;
  1503. */
  1504.  
  1505.     pScreen->mmWidth = pegInfo.mmScreenX;
  1506.     pScreen->mmHeight = pegInfo.mmScreenY;
  1507.  
  1508.     SaveScreens(SCREEN_SAVER_OFF, ScreenSaverReset);
  1509.  
  1510.     if (useCfb)
  1511.     {
  1512.     if (!cfbCreateDefColormap (pScreen))
  1513.         return FALSE;
  1514.     }
  1515.     else
  1516.     {
  1517.     pScreen->whitePixel = 0;
  1518.     pScreen->blackPixel = 1;
  1519.     if (!mfbCreateDefColormap (pScreen))
  1520.         return FALSE;
  1521.     }
  1522.  
  1523. #ifdef    UTEK
  1524.     /*
  1525.      * Change the graphics routines so that we
  1526.      * can deal with the cursor first.
  1527.      */
  1528.     if (pegInfo.softwareCursor)
  1529.     miDCInitialize ();        /* no interface yet */
  1530.  
  1531. #endif    /* UTEK */
  1532.     return TRUE;
  1533. }
  1534.  
  1535. void
  1536. InitOutput(screenInfo, argc, argv)
  1537.     ScreenInfo *screenInfo;
  1538.     int argc;
  1539.     char **argv;
  1540. {
  1541.     int i, cpu;
  1542.     PixmapFormatPtr    formats;
  1543.  
  1544. #ifdef    UTEK
  1545. #ifdef SABER
  1546.     static struct soft_config *soft_config_pointer = (struct soft_config *)0xff3b000;
  1547.     /* Hack - since Saber has its own C-runtime crt.o, it doesn't know about
  1548.        this global.  So I initialize it to the address observed when running a
  1549.        simple C program normally on a 4317. */
  1550. #else
  1551.     extern struct soft_config    *soft_config_pointer;
  1552. #endif /* SABER */
  1553. #endif    /* UTEK */
  1554.  
  1555. #ifdef XDEBUG
  1556.     setuid(0); /* for core dumps */
  1557. #endif /* XDEBUG */
  1558.  
  1559.     /*
  1560.      * We must open /dev/xdev before we set any CDP registers or set
  1561.      * any colormap entries because the "open" causes the kernel to
  1562.      * save the display state so that it can restore it when
  1563.      * xdev gets closed.
  1564.      */
  1565. #if defined UTEK | defined UTEKV
  1566.     if ((pegInfo.eventFd = open("/dev/xdev", O_RDONLY)) < 0) {
  1567.     FatalError("can't open /dev/xdev\n");
  1568.     }
  1569. #endif    /* UTEK | UTEKV*/
  1570.  
  1571. #ifdef    UTEK
  1572.     pegInfo.softp = soft_config_pointer;
  1573. #endif    /* UTEK */
  1574.  
  1575. #ifdef    UTEKV
  1576.     if ((pegInfo.eventFd = open("/dev/xdev", O_RDONLY)) < 0) {
  1577.     FatalError("can't open /dev/xdev\n");
  1578.     }
  1579. #endif    /* UTEKV */
  1580.  
  1581.     screenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
  1582.     screenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
  1583.     screenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
  1584.     screenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
  1585.  
  1586. #ifdef    UTEK
  1587.     /*
  1588.      * There are a variety of screens that we can configure for.
  1589.      * 4315, 4406, 4316, 4316 pretending to be mono, 4317 4317 pretending
  1590.      * to be 4316, 4317 pretending to be mono.  Choose here.
  1591.      * Note that a small number of important items in the pegInfo
  1592.      * structure are assigned here.  The rest are assigned in pegStructInit.
  1593.      */
  1594.     cpu = CPU_BOARD(pegInfo.softp);
  1595.     if (cpu == HC_CPU_4405PLUS
  1596.      || cpu == HC_CPU_4406PLUS
  1597.     ) {
  1598.     formats = OneBitFormats;
  1599.     pegInfo.depth = 1;
  1600.     pegInfo.fAvailableCDP = 0;
  1601.  
  1602.     if (cpu == HC_CPU_4405PLUS || cpu == HC_CPU_4406PLUS)
  1603.         pegInfo.softwareCursor = True;
  1604.  
  1605.     } else if (cpu == HC_CPU_MULTIPLANE || cpu == HC_CPU_CROW) {
  1606.     pegInfo.fAvailableCDP = 1;
  1607.     if (N_PLANE(pegInfo.softp) == 8) {
  1608.         formats = EightBitFormats;
  1609.         pegInfo.depth = 8;
  1610.     }
  1611.     else if (N_PLANE(pegInfo.softp) == 4) {
  1612.         FatalError("This server can only accomodate 1 or 8 bit screens\n");
  1613.     }
  1614.     } else if (cpu == HC_CPU_CEM) {
  1615.     FatalError("This server can only accomodate 4310 series machines\n", 
  1616.         pegInfo.softp->sc_hdwr.hc_cpu_board);
  1617.     } else {
  1618.     /* add blackbird, redwing here */
  1619.     FatalError("cpu board unknown=%x\n", 
  1620.         pegInfo.softp->sc_hdwr.hc_cpu_board);
  1621.     }
  1622.  
  1623. #endif    /* UTEK */
  1624.  
  1625. #ifdef    UTEKV
  1626. #ifdef    M4810
  1627. #ifdef notdef
  1628.  
  1629. ------ because the xdev mapping for the shared memeory has not happend YET !! --
  1630.  
  1631.     assert (N_PLANE(pegInfo.dsp) == 8);    /* hardwire display type #8 */
  1632.  
  1633.     pegInfo.fAvailableCDP = 1;        /* yep, its got CDPs */
  1634.  
  1635.     if (N_PLANE(pegInfo.dsp) == 8) {
  1636.         formats = EightBitFormats;
  1637.         pegInfo.depth = 8;
  1638.     }
  1639.  
  1640. #else  /* notdef */
  1641.  
  1642. /*
  1643.  *            hack for Redwing !!!!!!
  1644.  *
  1645.  *    --------- cheap hack for now .... fix the ordering of the shared memory
  1646.  *    -----------              later !!!!
  1647.  */
  1648.  
  1649.     pegInfo.fAvailableCDP = 1;
  1650.     formats = EightBitFormats;
  1651.     pegInfo.depth = 8;
  1652.  
  1653. #endif /* notdef */
  1654. #endif    /* M4810 */
  1655. #endif    /* UTEKV */
  1656.  
  1657.     pegInfo.entries = 1 << pegInfo.depth;
  1658.  
  1659.     for (i=0; formats[i].depth; i++)
  1660.     screenInfo->formats[i] = formats[i];
  1661.  
  1662.     screenInfo->numPixmapFormats = i;
  1663.  
  1664.     AddScreen(pegScreenInit, argc, argv);
  1665.     /*
  1666.      * smash the current time of day as the value is completely
  1667.      * bogus
  1668.      */
  1669.     currentTime.milliseconds = GetTimeInMillis();
  1670.     currentTime.months = 0;
  1671. }
  1672.  
  1673. void
  1674. pegEventInit()
  1675. {
  1676.     BoxRec    box;
  1677.     int        i;
  1678.  
  1679. #ifdef XPEG_TANDEM
  1680.     if (!pegTandem)
  1681.     {
  1682. #endif /* XPEG_TANDEM */
  1683.         pegInfo.queue = &pegInfo.dsp->ds_q;
  1684.                 /* 
  1685.                  * For redwing remember that this is
  1686.                  * mapped at 0x60000000 + the kernel
  1687.                  * virtual address.
  1688.                  */
  1689. #ifdef XPEG_TANDEM
  1690.     }
  1691.     else
  1692.     {
  1693.         pegInfo.queue = (EventQueue *)Xalloc(sizeof(EventQueue));
  1694.         pegInfo.queue->size = NXEVENTS;
  1695.         pegInfo.queue->events = (Event *)Xalloc(sizeof(Event) * NXEVENTS);
  1696.         pegInfo.queue->head = 0;
  1697.         pegInfo.queue->tail = 0;
  1698.         pegInfo.width = 640;
  1699.         pegInfo.height = 480;
  1700.     }
  1701. #endif /* XPEG_TANDEM */
  1702.     pegInfo.qLimit = pegInfo.queue->size - 1;
  1703.  
  1704.     /*
  1705.      * We're interested in everything.
  1706.      */
  1707.     box.y2 = box.y1 = box.x1 = box.x2 = 0;
  1708.     pegPointerNonInterestBox( pegInfo.pScr, &box);
  1709.  
  1710.     /*
  1711.      * initialize timeouts.
  1712.      */
  1713.     for (i=0; i < N_TIMERS; i++)
  1714.     pegInfo.kv.timer[ i ].key = -1;
  1715. }
  1716.  
  1717. void
  1718. InitInput(argc, argv)
  1719.     /*ARGSUSED*/
  1720.     int argc;
  1721.     /*ARGSUSED*/
  1722.     char **argv;
  1723. {
  1724.     DevicePtr p, k;
  1725.  
  1726.     /*
  1727.      * Initialize events and such...
  1728.      */
  1729. #ifdef XTESTEXT1
  1730. /*
  1731.  * For Tek workstations,
  1732.  *      Use BREAK key as COMMAND_KEY.
  1733.  *      This key has the same hardware code for 4315/6/7 keyboard
  1734.  *      as it does for xtal/tnt/Raven keyboard.
  1735.  *      We need to add 8 to the hardware key report to turn it into a X11
  1736.  *      keycode.
  1737.  */
  1738.     xtest_command_key = KEY_Break + 8;
  1739. #endif /* XTESTEXT1 */
  1740.  
  1741. #ifndef MOTION_BUFFER_OFF
  1742.     gfbInitMotionQueue(&pegInfo.motionQueue, MOTION_BUFFER_SIZE);
  1743. #endif /* MOTION_BUFFER_OFF */
  1744.  
  1745.     pegEventInit();
  1746.     InitKeybdState();
  1747.  
  1748. #ifdef    UTEK
  1749.     if ((KEYIDSTYLE(pegInfo.softp) ==  KB_STYLE_VT200) ||
  1750.     (KEYIDSTYLE(pegInfo.softp) ==  KB_STYLE_YELLOW_JACKET))
  1751. #endif    /* UTEK */
  1752.  
  1753. #ifdef    UTEKV
  1754.     if ((KEYIDSTYLE(pegInfo.dsp) ==  KB_STYLE_VT200) ||
  1755.     (KEYIDSTYLE(pegInfo.dsp) ==  KB_STYLE_YELLOW_JACKET))
  1756. #endif    /* UTEKV */
  1757.       {
  1758.     xtlInitBells();
  1759.     } else {
  1760.     pegInitBells(FALSE);
  1761.     }
  1762.  
  1763.     p = AddInputDevice(pegMouseProc, TRUE);
  1764.  
  1765.     k = AddInputDevice(pegKeybdProc, TRUE);
  1766.  
  1767.     RegisterPointerDevice(p);
  1768.     RegisterKeyboardDevice(k);
  1769. }
  1770.  
  1771. #ifdef XTESTEXT1
  1772. /*
  1773.  *    NAME
  1774.  *        pegInputSynthesisExt -- dummy routine for proper linking
  1775.  *
  1776.  *    SYNOPSIS
  1777.  */
  1778. pegInputSynthesisExt()
  1779. /*
  1780.  *    DESCRIPTION
  1781.  *        This routine exists just to cause linking of input
  1782.  *        synthesis extension routines residing in this directory.
  1783.  *        This routine should never get called.
  1784.  *
  1785.  *    RETURNS
  1786.  *        None
  1787.  *
  1788.  */
  1789. {
  1790. #ifdef    THIS_IS_BROKEN
  1791.     doassert();
  1792. #else    /* THIS_IS_BROKEN */
  1793.     assert(FALSE);
  1794. #endif    /* THIS_IS_BROKEN */
  1795.  
  1796.     XTestGenerateEvent(0, 0, 0, 0, 0);
  1797.     XTestJumpPointer(0, 0, 0);
  1798.     XTestGetPointerPos((short) 0, (short) 0);
  1799. }
  1800. #endif /* XTESTEXT1 */
  1801.  
  1802.  
  1803. /*
  1804.  *    NAME
  1805.  *        TekConfig - Do Tek-specific configuration
  1806.  *
  1807.  *    SYNOPSIS
  1808.  */
  1809. int
  1810. TekConfig(mmScreenX, mmScreenY)
  1811.     int *mmScreenX;        /* mm X dimension of screen */
  1812.     int *mmScreenY;        /* mm Y dimension of screen */
  1813. /*
  1814.  *    DESCRIPTION
  1815.  *        Get info from Tek-specific configuration file.
  1816.  *        Currently this is screen dimensions and gamma
  1817.  *        correction file.  If the database is accessed
  1818.  *        successfully, mmScreenX and mmScreenY will have
  1819.  *        correct values set; otherwise they will be set to -1.
  1820.  *
  1821.  *        Note: we used to use dbm for both displayenv database
  1822.  *        and rgb database.  This routine handled the problems
  1823.  *        associated with this in RCS rev: 1.27. 
  1824.  *
  1825.  *    RETURNS
  1826.  *        0 if database was accessed successfully
  1827.  *        -1 otherwise
  1828.  *
  1829.  */
  1830. {
  1831. #ifdef KNOW_NOW
  1832.     int ret;
  1833.     
  1834.     ret = DisplayEnv_init();
  1835.     if (ret != 0) {
  1836.     *mmScreenX = *mmScreenY = -1;
  1837.     } else {
  1838.     *mmScreenX = DisplayLookUpMillimeterRasterSizeX();
  1839.     *mmScreenY = DisplayLookUpMillimeterRasterSizeY();
  1840.     }
  1841. #else
  1842.     *mmScreenX = -1;
  1843.     *mmScreenY = -1;
  1844. #endif
  1845. }
  1846.  
  1847. /*
  1848.  *    NAME
  1849.  *        gfbNullFunction - Illegal function for unwanted function vectors
  1850.  *
  1851.  *    SYNOPSIS
  1852.  */
  1853. void
  1854. gfbNullFunction()
  1855. /*
  1856.  *    DESCRIPTION
  1857.  *        Call Fatal Error, warning that we shouldn't have gotten here.
  1858.  *        Use this as the value of a function vector which you don't
  1859.  *        want called.
  1860.  *
  1861.  *    RETURNS
  1862.  *        None
  1863.  *
  1864.  */
  1865. {
  1866. #ifdef XDEBUG
  1867.     FatalError("gfbNullFunction called.  Unused function vector dereferenced\n");
  1868. #endif /* XDEBUG */
  1869. }
  1870.  
  1871.