home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / ibm / skyway / skyHdwr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-21  |  13.5 KB  |  431 lines

  1. /*
  2.  * $XConsortium: skyHdwr.c,v 1.4 91/09/13 14:28:20 rws Exp $
  3.  *
  4.  * Copyright IBM Corporation 1987,1988,1989,1990,1991
  5.  *
  6.  * All Rights Reserved
  7.  *
  8.  * License to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted,
  10.  * provided that the above copyright notice appear in all copies and that
  11.  * both that copyright notice and this permission notice appear in
  12.  * supporting documentation, and that the name of IBM not be
  13.  * used in advertising or publicity pertaining to distribution of the
  14.  * software without specific, written prior permission.
  15.  *
  16.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS, AND 
  18.  * NONINFRINGEMENT OF THIRD PARTY RIGHTS, IN NO EVENT SHALL
  19.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  20.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23.  * SOFTWARE.
  24.  *
  25. */
  26.  
  27. /*
  28.  * skyHdwr.c - initialize hardware registers
  29.  */
  30.  
  31. #include <sys/types.h>
  32. #include <sys/hft.h>
  33. #include <sys/entdisp.h>
  34.  
  35. #include "X.h"
  36. #include "screenint.h"
  37. #include "scrnintstr.h"
  38. #include "pixmapstr.h"
  39. #include "cursorstr.h"
  40. #include "ibmScreen.h"
  41. #include "ibmTrace.h"
  42.  
  43. #include "skyHdwr.h"
  44. #include "skyReg.h"
  45.  
  46. void SkywayFillSolid();
  47. static void SkywaySetCoprocessorInfo();
  48. volatile struct SkyCopRegs
  49. {
  50.         unsigned int  a;
  51.         unsigned int  b;
  52.     char          c;      
  53.     unsigned char d;    
  54.     short         e;   
  55.     short         f;   
  56.         unsigned char g;
  57.         unsigned char h;
  58.         short         pix_index; 
  59.         unsigned char i;
  60.         unsigned char j;   
  61.     char          *pixmap_base;
  62.     ulong         k;    
  63. };
  64.  
  65. int skyHdwrInit(index)
  66. int index ;
  67. {
  68.  
  69.    TRACE(("skyHdwrInit\n"));
  70.  
  71.    skywayWaitFifo2(index);
  72.    SKYWAY_CCC_REG(index) = Color_Cmp_Fal;
  73.    SKYWAY_MEM_REG(index) = 0x0b ;   /* Motorola order, 8 bits/pixel */
  74.    SkywaySetCoprocessorInfo(index);
  75.  
  76.    SkywayFillSolid(0,0x3,0xff,0,0,1280,1024,index);
  77.  
  78.    /* Set the io register pointers                    */
  79.    SKYWAY_SINDEX_REG(index) = 0x5600;/* disable the cursor in the DAC   */
  80.    SKYWAY_SINDEX_REG(index) = 0x6c04;
  81.    SKYWAY_SINDEX_REG(index) = 0x5061; /* set CRTC to prepare for reset  */
  82.    SKYWAY_SINDEX_REG(index) = 0x5060; /* set CRTC to reset              */
  83.  
  84.    SKYWAY_INT_REG(index) = 0x00 ;
  85.    SKYWAY_INS_REG(index) = 0xff ;    /* clear all interrupt status bits */
  86.    SKYWAY_VMC_REG(index) = 0x00 ;    /* disable virtual memory interrupts */
  87.    SKYWAY_VMS_REG(index) = 0xff ;    /* clear virtual memory interrupts */
  88.  
  89.    /* native motorola mode ; memory decoding enabled */
  90.  
  91.    SKYWAYSetMode(index,0x0c);
  92.  
  93.    SKYWAY_WINCTRL_REG(index) = 0;    /* No pc window */
  94.  
  95.    /* set the memory configuration register to 64 bit serializer width,
  96.       256K x 4 module type, and 64 bit physical width for 64 bit wide
  97.       serializer                                                        */
  98.  
  99.    SKYWAY_SINDEX_REG(index) = 0x009e;
  100.  
  101.    /* initialize the DAC                                                */
  102.  
  103. SKYWAY_SINDEX_REG(index) = 0x6006; /* Put '01000011'b into the Brooktree */
  104. SKYWAY_SINDEX_REG(index) = 0x6443; /* command register to initialize it. */
  105. SKYWAY_SINDEX_REG(index) = 0x6004; /* Turn on all bits in the read mask. */
  106. SKYWAY_SINDEX_REG(index) = 0x64FF;
  107. SKYWAY_SINDEX_REG(index) = 0x6005;      /*      60  INDX REG = 05 */
  108. SKYWAY_SINDEX_REG(index) = 0x6400;      /*      64  BLNK MSK = 00 */
  109. SKYWAY_SINDEX_REG(index) = 0x6007;      /*      60  INDX REG = 07 */
  110. SKYWAY_SINDEX_REG(index) = 0x6400;      /*      64  TEST REG = 00 */
  111.  
  112.    /* The following values are taken from the Addendum to the SKYWAY1
  113.     Video Subsystem Hardware Workbook dated October 3, 1988.    However */
  114.    /* some values are taken from swstew.c, and don't match the addendum */
  115.  
  116. SKYWAY_SINDEX_REG(index) = 0x5402;/* Clock Frequency must be set to 0x02 */
  117. SKYWAY_SINDEX_REG(index) = 0x3600;/* turn off the sprite control register */
  118. SKYWAY_SINDEX_REG(index) = 0x6400;/* use Brooktree Palette DAC control  */
  119.                             /* register to turn off palette mask    */
  120. SKYWAY_SINDEX_REG(index) = 0x5103;/* 8 bits/pixel, x1 scaling factors   */
  121. /* pass two start */
  122. SKYWAY_SINDEX_REG(index) = 0x0102;/* Set 0.25 clock increment on        */
  123. SKYWAY_SINDEX_REG(index) = 0x16db;
  124. SKYWAY_SINDEX_REG(index) = 0x18ac;
  125. SKYWAY_SINDEX_REG(index) = 0x1a93;
  126. SKYWAY_SINDEX_REG(index) = 0x1cc5;
  127. SKYWAY_SINDEX_REG(index) = 0x1e06;
  128. SKYWAY_SINDEX_REG(index) = 0x2a04;
  129. /* pass two end */
  130.  
  131. SKYWAY_SINDEX_REG(index) = 0x10db;/* 1760 pixels per scan line          */
  132. SKYWAY_SINDEX_REG(index) = 0x129f;/* 1280 pixels in active picture area */
  133. SKYWAY_SINDEX_REG(index) = 0x149f;/* 1280 is end of picture border area */
  134. SKYWAY_SINDEX_REG(index) = 0x201f;/* vertical total regs set to 0x41f,  */
  135. SKYWAY_SINDEX_REG(index) = 0x2104;/* which is 1056 lines                */
  136. SKYWAY_SINDEX_REG(index) = 0x22ff;/* vertical display end registers are */
  137. SKYWAY_SINDEX_REG (index)= 0x2303;/* set to 0x3ff, which is 1024 lines  */
  138. SKYWAY_SINDEX_REG(index) = 0x241f;/* vertical blanking start registers  */
  139. SKYWAY_SINDEX_REG(index) = 0x2504;/* are set to 0x041f                  */
  140. SKYWAY_SINDEX_REG(index) = 0x26ff;/* vertical blanking end registers are */
  141. SKYWAY_SINDEX_REG(index) = 0x2703;/* set to 0x03ff                      */
  142. SKYWAY_SINDEX_REG(index) = 0x2801;/* vertical sync pulse start registers*/
  143. SKYWAY_SINDEX_REG(index) = 0x2904;/* are set to 0x0401                  */
  144. SKYWAY_SINDEX_REG(index) = 0x4000;/* set the Start Address registers to */
  145. SKYWAY_SINDEX_REG(index) = 0x4100;/* define the start address of the    */
  146. SKYWAY_SINDEX_REG(index) = 0x4200;/* active picture to address 0        */
  147. SKYWAY_SINDEX_REG(index) = 0x43a0;/* buffer pitch registers set to 1280 */
  148. SKYWAY_SINDEX_REG(index) = 0x4400;/* pixels per scan line               */
  149. SKYWAY_SINDEX_REG(index) = 0x64ff;/* turn on palette mask               */
  150. SKYWAY_SINDEX_REG(index) = 0x2cff;/* vertical line compare lo           */
  151. SKYWAY_SINDEX_REG(index) = 0x2d07;/* vertical line compare hi           */
  152. SKYWAY_SINDEX_REG(index) = 0x5063;/* set Display Mode 1 register to:    */
  153.                             /*      Normal operation                */
  154.                             /*      No clock error                  */
  155.                             /*      Non interlaced                  */
  156.                             /*      Video Feature Interface disabled*/
  157.                             /*      Composite syncs enabled         */
  158.                             /*      + Vertical, - Horizontal        */
  159.                             /*         sync polarity                */
  160.  
  161.  
  162.    return( 0 );
  163.  
  164. }
  165.  
  166. static struct { unsigned short r,g,b;} installed[256];
  167.  
  168. skySetColor(number,red,green,blue,index)
  169.     register unsigned   number, red, green, blue;
  170.     int index ;
  171. {
  172.  
  173.     TRACE(("SkywaySetColor(%d,%d,%d,%d,%d)\n",number,red,green,blue,index));
  174.  
  175.     installed[number].r = red;
  176.     installed[number].g = green;
  177.     installed[number].b = blue;
  178.  
  179.     /* I don't know what this does, but it  */
  180.     /* prevents blinking from occurring     */
  181.  
  182.     SKYWAY_SINDEX_REG(index) = (SPINDEXLO << 8 ) | 0x07 ;
  183.     /* turn off mask */
  184.     SKYWAY_SINDEX_REG(index) = (PALETTEMASK << 8 ) | 0x00 ;
  185.  
  186.     SKYWAYSetColorIndex(index,number) ;
  187.     SKYWAYSetRGBColor(index,red,green,blue) ;
  188.  
  189.    return;
  190.  
  191. }
  192.  
  193. void
  194. SkywayTileRect(pTile, alu, pm, x, y, w, h, xSrc, ySrc )
  195.     PixmapPtr pTile;
  196.     int alu ;
  197.     unsigned long int pm ;
  198.     int x, y, w, h, xSrc, ySrc;
  199. {
  200.  
  201.  register unsigned char    *psrc, *pSRC ;
  202.  register volatile unsigned char *pdst, *pDST ;
  203.  int    xoff, yoff, i,j ;
  204.  int    index ;
  205.  
  206.  TRACE(("SkywayTileRect(0x%x,%d,0x%x,%d,%d,%d,%d,0x%x,0x%x)\n",
  207.         pTile,alu,pm,x,y,w,h,xSrc,ySrc));
  208.  
  209.  index = pTile->drawable.pScreen->myNum ;
  210.  skywayWaitFifo2(index);
  211.  
  212.  SKYWAYSetCCC(index,Color_Cmp_Fal);
  213.  SKYWAYSetALU(index,alu);
  214.  SKYWAYSetPlaneMask(index,pm & 0xffff);
  215.  
  216.  SKYWAYSetupScreenPixmap(index,PixSize8) ;  /* PixSize4 for skymono */
  217.  
  218.  SKYWAYSetPixmapDstOffset(index,x,y);
  219.  SKYWAYSetWidth(index,w - 1) ;
  220.  SKYWAYSetHeight(index,h - 1) ;
  221.  
  222.  /* Move data into adapter ; wait for DMA */
  223.  
  224.  skywayWaitFifo2(index);
  225.  
  226.  pSRC = (unsigned char *) pTile->devPrivate.ptr ;
  227.  pDST = (unsigned char *) SKYWAY_TILEOFFSET[index] ; 
  228.  
  229.  TRACE((" pTile->devKind is %d \n",pTile->devKind));
  230.  
  231.  for ( i = 0 ; i < pTile->drawable.height ; i++  )
  232.  {
  233.     psrc = pSRC ;
  234.     pdst = pDST ;
  235.  
  236.     for ( j =0 ; j < pTile->drawable.width ; j++)
  237.         *pdst++ = *psrc++ ;
  238.  
  239.         pSRC += pTile->devKind ;
  240.         pDST += pTile->drawable.width ;
  241.  
  242.  }
  243.  
  244.  /* src pattern */
  245.  
  246.  xoff = (x - xSrc) % pTile->drawable.width ;
  247.  yoff = (y - ySrc) % pTile->drawable.height ;
  248.  TRACE(("xoff is %d yoff is %d \n",xoff,yoff));
  249.  TRACE(("xSrc is %d ySrc is %d \n",xSrc,ySrc));
  250.  
  251.  SKYWAYSetPixmapIndex(index,PixMapA) ;
  252.  SKYWAYSetPixmapBase(index,SC_INVBASEOFFSET) ; 
  253.  SKYWAYSetPixmapWidth(index,pTile->drawable.width - 1) ;
  254.  SKYWAYSetPixmapHeight(index,pTile->drawable.height - 1) ;
  255.  SKYWAYSetPixmapFormat(index,MI1 | PixSize8) ;
  256.  SKYWAYSetPixmapSrcOffset(index,xoff, yoff);
  257.  
  258.  SKYWAY_PO_REG(index)   =   POSrcA | POForeSrc | POStepBlt |
  259.              PODestC | POPatFore |
  260.              POMaskDis | POModeAll | POOct0 ;
  261.  
  262.  skywayWaitFifo2(index);
  263.  
  264. }
  265.  
  266. void
  267. SkywayFillSolid( color, alu, pm, x, y, w, h,index)
  268.      int   color ;
  269.      unsigned int alu, pm ;
  270.      short  x, y ;
  271.      short  w, h ;
  272.      int    index ;
  273. {
  274.  
  275.  TRACE(("SkywayFillSolid: color %d, alu: %d, pm: %d xy(%d, %d) %dx%d\n",
  276.     color, alu, pm, x, y, w, h));
  277.  
  278.  skywayWaitFifo2(index);
  279.  
  280.  SKYWAYSetCCC(index,Color_Cmp_Fal);
  281.  SKYWAYSetALU(index,alu);
  282.  SKYWAYSetPlaneMask(index,pm & 0xffff);
  283.  SKYWAYSetForegroundColor(index,color);    
  284.  
  285.  /* Set the foreground field for the Pixel Operations Register to */
  286.  /* indicate the color is coming from a register */
  287.  
  288.  SKYWAYSetupScreenPixmap(index,PixSize8) ;
  289.  
  290.  SKYWAYSetPixmapDstOffset(index,x,y);
  291.  SKYWAYSetWidth(index,w - 1) ;
  292.  SKYWAYSetHeight(index,h - 1) ;
  293.  
  294.  SKYWAY_PO_REG(index)   =   POForeReg | POStepBlt |
  295.              PODestC | POPatFore |
  296.              POMaskDis | POModeAll | POOct0 ;
  297.  
  298.  skywayWaitFifo2(index);
  299.  
  300.  
  301. skywaySetupMask(xoff,yoff,width,height,pmask,index)
  302. int xoff,yoff,width,height,pmask ;
  303. int index ;
  304. {
  305.  
  306.     SKYWAY_PMI_REG(index) = PixMapD ;
  307.         SKYWAY_PMB_REG(index) = SKYWAY_MASKMAP_START ;
  308.         SKYWAY_PMW_REG(index) = width -  1 ;
  309.         SKYWAY_PMH_REG(index) = height - 1 ;
  310.         SKYWAY_PMF_REG(index) = MI1 | PixSize1 ;
  311.       SKYWAY_DSTX_REG(index) = xoff ;
  312.       SKYWAY_DSTY_REG(index) = yoff ;
  313.     SKYWAYSetPlaneMask(index,pmask & 0xffff);
  314.  
  315.       SKYWAY_PO_REG(index) |= POMaskEn ;   /* Dangerous */
  316.  
  317. }
  318.  
  319. void
  320. SkywayBitBlt(alu,pScreen,pmask,sx,sy,dx,dy,w,h)
  321.      int alu,pmask ;
  322.      ScreenPtr pScreen ;
  323.      int sx,sy,dx,dy,w,h;    
  324. {
  325.  short over_y, over_x;
  326.  unsigned int octant;
  327.  int index ;
  328.  
  329. TRACE(("SkywayBitBltXXXXXXX(0x%x,0x%x,%d,%d,%d,%d,%d,%d)\n",
  330.     alu,pmask,sx,sy,dx,dy,w,h));
  331.  
  332. index = pScreen->myNum ;
  333.  
  334.   /* BLT overlap codes */
  335.  
  336. #define D_NOT_OVER 0            /* no overlap */
  337. #define D_TOP_EDGE_OVER 1       /* source overlaps top of destination */
  338. #define D_BOTTOM_EDGE_OVER 2    /* source overlaps bottom of destination */
  339. #define D_LEFT_EDGE_OVER 1      /* source overlaps left of destination */
  340. #define D_RIGHT_EDGE_OVER 2     /* source overlaps right of destination */
  341.  
  342.  
  343.    /* Set up the source & destination offsets. */
  344.  
  345.     /* First determine whether the source and destination overlap. */
  346.     over_x = over_y = D_NOT_OVER;    /* initialize to no-overlap code */
  347.  
  348.     /* Check the y values. */
  349.     if (dy >= sy) {       /* maybe top of d is in s */
  350.     if (dy < (sy + h))    /* top of d is in s */
  351.         over_y = D_TOP_EDGE_OVER;
  352.     } else {        /* maybe bottom of d is in s */
  353.     if (sy < (dy + h))    /* bottom of d is in s */
  354.         over_y = D_BOTTOM_EDGE_OVER;
  355.     }
  356.  
  357.     /* Check the x values. */
  358.     if (dx >= sx) {       /* maybe left of d is in s */
  359.     if (dx < (sx + w))    /* left of d is in s */
  360.         over_x = D_LEFT_EDGE_OVER;
  361.     } else {        /* maybe right of d is in s */
  362.     if (sx < (dx + w))    /* right of d is in s */
  363.         over_x = D_RIGHT_EDGE_OVER;
  364.     }
  365.  
  366.     octant = POOct0;    /* in case no corners overlap */
  367.     if (over_y == D_TOP_EDGE_OVER) {
  368.     if (over_x == D_LEFT_EDGE_OVER) {
  369.         octant = POOct6;    /* upper left of d is in s */
  370.  
  371.         /* Point to the lower-right corner */
  372.         sx += (w - 1);
  373.         sy += (h - 1);
  374.         dx += (w - 1);
  375.         dy += (h - 1);
  376.     } else if (over_x == D_RIGHT_EDGE_OVER) {
  377.         octant = POOct2;    /* upper right of d is in s */
  378.  
  379.         /* Point to the bottom left corner */
  380.         sy += (h - 1);
  381.         dy += (h - 1);
  382.     }
  383.     } else if (over_y == D_BOTTOM_EDGE_OVER) {
  384.     if (over_x == D_LEFT_EDGE_OVER) {
  385.         octant = POOct4;    /* lower left of d is in s */
  386.  
  387.         /* Point to the upper right corner */
  388.         sx += (w - 1);
  389.         dx += (w - 1);
  390.     } else if (over_x == D_RIGHT_EDGE_OVER) {
  391.         octant = POOct0;    /* lower right of d is in s */
  392.  
  393.         /* Already pointing to the upper left corner... */
  394.     }
  395.     }
  396.  
  397. skywayWaitFifo2(index);
  398. SKYWAYSetupScreenPixmap(index,PixSize8) ;
  399.  
  400. SKYWAYSetPixmapSrcOffset(index,sx,sy);
  401. SKYWAYSetPixmapDstOffset(index,dx,dy);
  402. SKYWAYSetWidth(index,w - 1);
  403. SKYWAYSetHeight(index,h - 1);
  404.  
  405. /* Set up the plane mask and alu. */
  406.  
  407. SKYWAYSetPlaneMask(index,pmask & 0xffff);
  408. SKYWAYSetALU(index,alu);
  409. SKYWAYSetCCC(index,Color_Cmp_Fal); /* Disable */
  410.  
  411. /* Set up the pixel operations register and do the actual BLT... */
  412.  
  413. SKYWAY_PO_REG(index) = POForeSrc | POBackSrc | POStepBlt | POSrcC | PODestC |
  414.         POPatFore | POMaskDis | POModeAll | octant;
  415.  
  416. skywayWaitFifo2(index);
  417.  
  418. }
  419.  
  420. static void
  421. SkywaySetCoprocessorInfo(index)
  422. int index;
  423. {
  424.     volatile struct SkyCopRegs *cop;
  425.  
  426.     cop = (struct SkyCopRegs *) COPREG[index];
  427.     cop->pix_index    = PixMapC;
  428.     cop->pixmap_base= SKYWAY_VRAM_START[index];
  429. }
  430.