home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / ibm8514 / brcDash.c < prev    next >
C/C++ Source or Header  |  1991-09-20  |  18KB  |  800 lines

  1. /*
  2.  * $Id: brcDash.c,v 1.1 1991/09/20 19:10:24 mtranle Exp $
  3.  *
  4.  * Copyright IBM Corporation 1987,1990
  5.  *
  6.  * All Rights Reserved
  7.  *
  8.  * Permission 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 AND FITNESS. IN NO EVENT SHALL
  18.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  19.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22.  * SOFTWARE.
  23.  *
  24. */
  25. /*
  26.  * PRPQ 5799-PFF (C) COPYRIGHT IBM CORPORATION 1987,1990
  27.  * LICENSED MATERIALS - PROPERTY OF IBM
  28.  * REFER TO COPYRIGHT INSTRUCTIONS FORM NUMBER G120-2083
  29.  */
  30. /*
  31.  *  Hardware interface routines for IBM 8514/A adapter for
  32.  *  X.11 server(s) on IBM equipment.
  33.  *
  34.  */
  35.  
  36. /*
  37.  * SYNTAX ERROR THIS LINE because I havent finished cleaning this file for
  38.  * timing errors.  11/16/88  paquin
  39.  */
  40.  
  41. /***********************************************************
  42. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  43. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  44.  
  45.                         All Rights Reserved
  46.  
  47. Permission to use, copy, modify, and distribute this software and its 
  48. documentation for any purpose and without fee is hereby granted, 
  49. provided that the above copyright notice appear in all copies and that
  50. both that copyright notice and this permission notice appear in 
  51. supporting documentation, and that the names of Digital or MIT not be
  52. used in advertising or publicity pertaining to distribution of the
  53. software without specific, written prior permission.  
  54.  
  55. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  56. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  57. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  58. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  59. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  60. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  61. SOFTWARE.
  62.  
  63. ******************************************************************/
  64.  
  65. #include "X.h"
  66.  
  67. #include "misc.h"
  68. #include "gcstruct.h"
  69. #include "gc.h"
  70. #include "pixmap.h"
  71. #include "window.h"
  72. #include "windowstr.h"
  73. #include "pixmapstr.h"
  74. #include "regionstr.h"
  75. #include "scrnintstr.h"
  76. #include "mistruct.h"
  77.  
  78. #include "OScompiler.h"
  79.  
  80. #include "mfb.h"
  81. #include "ppc.h"
  82.  
  83. #include "x8514.h"
  84.  
  85. #define ACCESS_PIXEL (1 << 4)
  86.  
  87. #define barrel_shift8(v, s) \
  88.     (v = (v >> s) | (v << (8 - s)))
  89.  
  90. #define HARDWARE_PATTERN 0x01
  91.  
  92. typedef struct {
  93.     unsigned char    Flags;
  94.     unsigned short    Pattern;
  95. } ibm8514PrivGC;
  96.  
  97. typedef ibm8514PrivGC *ibm8514PrivGCPtr;
  98.  
  99. /* 
  100.  * ibm8514 dashed line
  101.  */
  102.  
  103. extern void ibm8514BresDash();
  104. extern void ibm8514HorzDash();
  105. extern void ibm8514VertDash();
  106.  
  107. #define X_AXIS 0
  108.  
  109. extern int mergexlate[];
  110. extern int ibm8514cursorSemaphore ;
  111.  
  112. /* NOTE
  113.    maybe OUTCODES should take box (the one that includes all
  114. edges) instead of pbox (the standard no-right-or-lower-edge one)?
  115. */
  116. #define OUTCODES(result, x, y, pbox) \
  117.     if (x < pbox->x1) \
  118.     result |= OUT_LEFT; \
  119.     else if (x >= pbox->x2) \
  120.     result |= OUT_RIGHT; \
  121.     if (y < pbox->y1) \
  122.     result |= OUT_ABOVE; \
  123.     else if (y >= pbox->y2) \
  124.     result |= OUT_BELOW;
  125.  
  126. void
  127. ibm8514ZeroDash(pDrawable, pGC, mode, npt, pptInit)
  128.     DrawablePtr pDrawable;
  129.     GCPtr pGC;
  130.     int mode;        /* Origin or Previous */
  131.     int npt;        /* number of points */
  132.     DDXPointPtr pptInit;
  133. {
  134.     int nboxInit;
  135.     int nbox;
  136.     BoxPtr pboxInit;
  137.     BoxPtr pbox;
  138.     int nptTmp;
  139.     DDXPointPtr ppt;        /* pointer to list of translated points */
  140.  
  141.     DDXPointRec pt1;
  142.     DDXPointRec pt2;
  143.  
  144.     unsigned int oc1;        /* outcode of point 1 */
  145.     unsigned int oc2;        /* outcode of point 2 */
  146.  
  147.     int xorg, yorg;        /* origin of window */
  148.  
  149.     int adx;        /* abs values of dx and dy */
  150.     int ady;
  151.     int signdx;        /* sign of dx and dy */
  152.     int signdy;
  153.     int e, e1, e2;        /* bresenham error and increments */
  154.     int len;            /* length of segment */
  155.  
  156.     int clipDone;        /* flag for clipping loop */
  157.     DDXPointRec pt1Orig;    /* unclipped start point */
  158.     DDXPointRec pt2Orig;    /* unclipped end point */
  159.     int err;            /* modified bresenham error term */
  160.     int clip1, clip2;        /* clippedness of the endpoints */
  161.  
  162.     int alu ;            /* Screen Raster-Op value */
  163.     long fg ;            /* foreground Pixel value */
  164.     long bg ;            /* background Pixel value */
  165.     unsigned long pm ;            /* plane mask */
  166.     int tmp;
  167.     int x1, x2, y1, y2;
  168.                 /* a bunch of temporaries */
  169.     void (* scrnFunc)();
  170.     ppcPrivGC *gcPriv;
  171.  
  172.     if ( pDrawable->type != DRAWABLE_WINDOW )
  173.     {
  174.     ErrorF("ibm8514ZeroDash: not a window\n");
  175.     return;
  176.     }
  177.  
  178.     gcPriv = ((ppcPrivGC *)pGC->devPrivates[mfbGCPrivateIndex].ptr ) ;
  179.     switch ( gcPriv->colorRrop.fillStyle ) {
  180.     case FillStippled :
  181.     case FillSolid : /* Can Use Optimized Color Raster-Op */
  182.         alu = gcPriv->colorRrop.alu ;
  183.         pm = gcPriv->colorRrop.planemask ;
  184.         if(pGC->lineStyle == LineOnOffDash){
  185.         ibm8514ClearQueue(1);
  186.         SETCOL1( gcPriv->colorRrop.fgPixel) ;
  187.         } else {
  188.             fg = gcPriv->colorRrop.fgPixel ;
  189.             bg = gcPriv->colorRrop.bgPixel ;
  190.         }
  191.         break ;
  192.     case FillOpaqueStippled :
  193.     case FillTiled : /* Can't Use Optimized Color Raster-Op */
  194.         alu = pGC->alu ;
  195.         pm = pGC->planemask ;
  196.         if(pGC->lineStyle == LineOnOffDash){
  197.         ibm8514ClearQueue(1);
  198.         SETCOL1(pGC->fgPixel);
  199.         } else {
  200.             fg = pGC->fgPixel ;
  201.             bg = pGC->bgPixel ;
  202.         }
  203.         break ;
  204.     }
  205.     if ( alu == GXnoop )
  206.     return ;
  207.  
  208.     pboxInit = REGION_RECTS(gcPriv->pCompositeClip) ;
  209.     nboxInit = REGION_NUM_RECTS(gcPriv->pCompositeClip) ;
  210.  
  211.     xorg = pDrawable->x ;
  212.     yorg = pDrawable->y ;
  213.  
  214.     /* translate the point list */
  215.     ppt = pptInit;
  216.     nptTmp = npt;
  217.     if (mode == CoordModeOrigin)
  218.     {
  219.     while(nptTmp--)
  220.     {
  221.         ppt->x += xorg;
  222.         ppt++->y += yorg;
  223.     }
  224.     }
  225.     else
  226.     {
  227.     ppt->x += xorg;
  228.     ppt->y += yorg;
  229.     nptTmp--;
  230.     while ( nptTmp-- )
  231.     {
  232.         ppt++;
  233.         ppt->x += (ppt-1)->x;
  234.         ppt->y += (ppt-1)->y;
  235.     }
  236.     }
  237.  
  238.     ppt = pptInit;
  239.     while ( --npt )
  240.     {
  241.     nbox = nboxInit;
  242.     pbox = pboxInit;
  243.  
  244.     pt1 = *ppt++;
  245.     pt2 = *ppt;
  246.  
  247.     if ( !( adx = ( pt2.x - pt1.x ) ) )
  248.     {
  249.         /* make the line go top to bottom of screen, keeping
  250.            endpoint semantics
  251.         */
  252.         if ( pt1.y > pt2.y )
  253.         {
  254.         tmp = pt2.y;
  255.         pt2.y = pt1.y + 1;
  256.         pt1.y = tmp + 1;
  257.         }
  258.  
  259.         /* get to first band that might contain part of line */
  260.         while ((nbox) && (pbox->y2 <= pt1.y))
  261.         {
  262.         pbox++;
  263.         nbox--;
  264.         }
  265.  
  266.         if ( nbox )
  267.         {
  268.         /* stop when lower edge of box is beyond end of line */
  269.         while ( ( nbox ) && ( pt2.y >= pbox->y1 ) ) {
  270.             if ( ( pt1.x >= pbox->x1 ) && ( pt1.x < pbox->x2 ) ) {
  271.             /* this box has part of the line in it */
  272.             if ( ( y1 = MAX( pt1.y, pbox->y1 ) )
  273.               != ( y2 = MIN( pt2.y, pbox->y2 ) ) ) {
  274.                 ibm8514VertDash( pGC, fg, bg,
  275.                 alu, pm, pt1.x, y1, y2 - y1 ) ;
  276.             }
  277.             }
  278.             nbox--;
  279.             pbox++;
  280.         }
  281.         }
  282.  
  283.     }
  284.     else if ( !( ady = ( pt2.y - pt1.y ) ) )
  285.     {
  286.         /* force line from left to right, keeping
  287.            endpoint semantics
  288.         */
  289.         if (pt1.x > pt2.x)
  290.         {
  291.         tmp = pt2.x;
  292.         pt2.x = pt1.x + 1;
  293.         pt1.x = tmp + 1;
  294.         }
  295.  
  296.         /* find the correct band */
  297.         while( nbox && (pbox->y2 <= pt1.y))
  298.         {
  299.         pbox++;
  300.         nbox--;
  301.         }
  302.  
  303.         /* try to draw the line, if we haven't gone beyond it */
  304.         if ((nbox) && (pbox->y1 <= pt1.y))
  305.         {
  306.         /* when we leave this band, we're done */
  307.         tmp = pbox->y1;
  308.         while((nbox) && (pbox->y1 == tmp))
  309.         {
  310.             if (pbox->x2 <= pt1.x)
  311.             {
  312.             /* skip boxes until one might contain start point */
  313.             nbox--;
  314.             pbox++;
  315.             continue;
  316.             }
  317.  
  318.             /* stop if left of box is beyond right of line */
  319.             if (pbox->x1 >= pt2.x)
  320.             {
  321.             nbox = 0;
  322.             continue;
  323.             }
  324.             if ( ( x1 = MAX( pt1.x, pbox->x1 ) )
  325.               != ( x2 = MIN( pt2.x, pbox->x2 ) ) ) {
  326.                     ibm8514HorzDash( pGC, fg, bg,
  327.                     alu, pm, x1, pt1.y, x2 - x1 ) ;
  328.             }
  329.             nbox--;
  330.             pbox++;
  331.         }
  332.         }
  333.     }
  334.     else    /* sloped line */
  335.     {
  336.         signdx = sign(adx);
  337.         signdy = sign(ady);
  338.         adx = ABS(adx);
  339.         ady = ABS(ady);
  340.  
  341.         if (adx > ady)
  342.         {
  343.         e1 = ady*2;
  344.         e2 = e1 - 2*adx;
  345.         e = e1 - adx;
  346.  
  347.         }
  348.         else
  349.         {
  350.         e1 = adx*2;
  351.         e2 = e1 - 2*ady;
  352.         e = e1 - ady;
  353.         }
  354.  
  355.         /* we have bresenham parameters and two points.
  356.            all we have to do now is clip and draw.
  357.         */
  358.  
  359.         pt1Orig = pt1;
  360.         pt2Orig = pt2;
  361.  
  362.         while(nbox--)
  363.         {
  364.  
  365.         BoxRec box;
  366.  
  367.         pt1 = pt1Orig;
  368.         pt2 = pt2Orig;
  369.         clipDone = 0;
  370.         box.x1 = pbox->x1;
  371.         box.y1 = pbox->y1;
  372.         box.x2 = pbox->x2-1;
  373.         box.y2 = pbox->y2-1;
  374.         clip1 = 0;
  375.         clip2 = 0;
  376.  
  377.         oc1 = 0;
  378.         oc2 = 0;
  379.         OUTCODES(oc1, pt1.x, pt1.y, pbox);
  380.         OUTCODES(oc2, pt2.x, pt2.y, pbox);
  381.  
  382.         if (oc1 & oc2)
  383.             clipDone = -1;
  384.         else if ((oc1 | oc2) == 0)
  385.             clipDone = 1;
  386.         else /* have to clip */
  387.             clipDone = mfbClipLine(pbox, box,
  388.                        &pt1Orig, &pt1, &pt2, 
  389.                        adx, ady, signdx, signdy,
  390.                        ( ( adx > ady ) ? X_AXIS : Y_AXIS ),
  391.                        &clip1, &clip2);
  392.  
  393.         if (clipDone == -1)
  394.         {
  395.             pbox++;
  396.         }
  397.         else
  398.         {
  399.             if ( adx > ady )
  400.             len = ABS(pt2.x - pt1.x);
  401.             else
  402.             len = ABS(pt2.y - pt1.y);
  403.  
  404.             len += (clip2 != 0);
  405.             if (len)
  406.             {
  407.             /* unwind bresenham error term to first point */
  408.             if (clip1)
  409.             {
  410.                 if ( adx > ady )
  411.                     err = e
  412.                     + ( ABS( pt1.y - pt1Orig.y ) * ( e2 - e1 ) )
  413.                     + ( ABS( pt1.x - pt1Orig.x ) * e1 ) ;
  414.                 else
  415.                     err = e
  416.                     + ( ABS( pt1.x - pt1Orig.x ) * ( e2 - e1 ) )
  417.                     + ( ABS( pt1.y - pt1Orig.y ) * e1 ) ;
  418.             }
  419.             else
  420.                 err = e;
  421.             ibm8514BresDash( pGC, fg, bg, alu, pm,
  422.                       signdx, signdy,
  423.                       ( ( adx > ady ) ? X_AXIS : Y_AXIS ),
  424.                       pt1.x, pt1.y, err, e1, e2, len ) ;
  425.             }
  426.  
  427.             /* if segment is unclipped, skip remaining rectangles */
  428.             if (!(clip1 || clip2))
  429.             break;
  430.             else
  431.             pbox++;
  432.         }
  433.         } /* while (nbox--) */
  434.     } /* sloped line */
  435.     } /* while (nline--) */
  436.  
  437.     /* paint the last point if the end style isn't CapNotLast.
  438.        (Assume that a projecting, butt, or round cap that is one
  439.         pixel wide is the same as the single pixel of the endpoint.)
  440.     */
  441.  
  442.     if ((pGC->capStyle != CapNotLast) &&
  443.     ((ppt->x != pptInit->x) ||
  444.      (ppt->y != pptInit->y)))
  445.     {
  446.     nbox = nboxInit;
  447.     pbox = pboxInit;
  448.     scrnFunc =
  449.      ( (ppcScrnPriv *)(pDrawable->pScreen->devPrivate))->solidFill ;
  450.     while (nbox--)
  451.     {
  452.         if ((ppt->x >= pbox->x1) &&
  453.         (ppt->y >= pbox->y1) &&
  454.         (ppt->x <  pbox->x2) &&
  455.         (ppt->y <  pbox->y2))
  456.         {
  457.         (* scrnFunc)( fg, alu, pm, ppt->x, ppt->y, 1, 1 ) ;
  458.         break;
  459.         }
  460.         else
  461.         pbox++;
  462.     }
  463.     }
  464.     return ;
  465. }
  466.  
  467. void
  468. ibm8514VertDash(pGC, fg, bg, alu, pm, x, y, len)
  469. GCPtr pGC;
  470. long fg;
  471. long bg;
  472. int alu;
  473. int pm;
  474. int x;
  475. int y;
  476. int len;
  477. {
  478.     int saved;
  479.     int l = pGC->dash[0];
  480.     int n = 0;
  481.     int togo = len;
  482.     int ndash = 0;
  483.     int command = 0x20df | ACCESS_PIXEL;
  484.  
  485.     y += pGC->dashOffset;
  486.  
  487.     saved =
  488.         !ibm8514cursorSemaphore && ibm8514CheckCursor( x,y,1,len ) ;
  489.  
  490.  
  491.     ibm8514ATRNotBusy;
  492.     ibm8514CheckQueue(5);
  493.     PLNWENBL(pm);
  494.     SETCOL1(fg);
  495.     SETFN1(FNCOLOR1,mergexlate[alu]);
  496.     SETX0(x);
  497.     SETY0(y);
  498.  
  499.     while(togo){
  500.         /* handle odd dash lists later */
  501.         if(n > pGC->numInDashList){
  502.             n = 0;
  503.         }
  504.         l = MIN(pGC->dash[n++], togo);
  505.         togo -= l;
  506.         if(pGC->lineStyle == LineOnOffDash){
  507.             if(ndash & 0x01)
  508.                 command = 0x20df | ACCESS_PIXEL;
  509.             else
  510.                 command = 0x20df  & ~ACCESS_PIXEL;
  511.             ibm8514ClearQueue(2);
  512.         } else {
  513.             ibm8514ClearQueue(4);
  514.             if(ndash & 0x01)
  515.                 SETCOL1(bg);
  516.             else
  517.                 SETCOL1(fg);
  518.  
  519.             /* this appears to be a stupid line.  tfp 11/16/88 */
  520.             SETFN1(FNCOLOR1,mergexlate[alu]);
  521.         }
  522.         ndash++;
  523.  
  524.         SETLX(l);
  525.         COMMAND(command);
  526.     }
  527.  
  528.     ibm8514ClearQueue(2);
  529.     SETFN1(FNCOLOR1,FNREPLACE);
  530.     PLNWENBL(WPLANES);
  531.     if (saved)
  532.             ibm8514ReplaceCursor();
  533. }
  534.  
  535. void
  536. ibm8514HorzDash(pGC, fg, bg, alu, pm, x, y, len)
  537. GCPtr pGC;
  538. long fg;
  539. long bg;
  540. int alu;
  541. unsigned long pm;
  542. int x;
  543. int y;
  544. int len;
  545. {
  546.     int l = pGC->dash[0];
  547.     int n = 0;
  548.     int ndash = 0;
  549.     int  command = 0x201f | ACCESS_PIXEL;
  550.     ppcPrivGCPtr ppcPriv =
  551.         (ppcPrivGCPtr)pGC->devPrivates[mfbGCPrivateIndex].ptr;
  552.     ibm8514PrivGCPtr ibm8514Priv = (ibm8514PrivGCPtr)ppcPriv->devPriv;
  553.     int togo = len;
  554.     int saved;
  555.  
  556.     unsigned char flags = ibm8514Priv->Flags;
  557.     unsigned short pattern = ibm8514Priv->Pattern;
  558.  
  559.     x += pGC->dashOffset;
  560.  
  561.     saved =
  562.         !ibm8514cursorSemaphore && ibm8514CheckCursor( x,y,len,1 ) ;
  563.  
  564.     ibm8514ATRNotBusy;
  565.     ibm8514CheckQueue(5);
  566.     PLNWENBL(pm);
  567.     SETCOL1(fg);
  568.     SETFN1(FNCOLOR1,mergexlate[alu]);
  569.     SETX0(x);
  570.     SETY0(y);
  571.     if(flags & HARDWARE_PATTERN){
  572.         ibm8514CheckQueue(5);
  573.         barrel_shift8(pattern, x % 8);
  574.         SETMODE(M_PATTS);
  575.         SETPAT0(pattern >> 3);
  576.         SETPAT1(pattern << 1);
  577.         SETCOL0(bg);
  578.         if(pGC->lineStyle == LineOnOffDash){
  579.             SETFN0(FNCOLOR0,mergexlate[GXnoop]);
  580.         } else {
  581.             SETFN0(FNCOLOR0,mergexlate[alu]);
  582.         }
  583.     }
  584.     while(togo){
  585.         /* handle odd dash lists later */
  586.         if(n > pGC->numInDashList){
  587.             n = 0;
  588.         }
  589.         l = MIN(pGC->dash[n++], togo);
  590.         togo -= l;
  591.         if(!(flags & HARDWARE_PATTERN)){
  592.             if(pGC->lineStyle == LineOnOffDash){
  593.                 if(ndash & 0x01){
  594.                     command = 0x201f | ACCESS_PIXEL;
  595.                 } else {
  596.                     command = 0x201f & ~ACCESS_PIXEL;
  597.                 }
  598.             } else {
  599.                 ibm8514ClearQueue(5);
  600.                 PLNWENBL(pm);
  601.                 if(ndash & 0x01){
  602.                     SETCOL1(bg);
  603.                 } else {
  604.                     SETCOL1(fg);
  605.                 }
  606.  
  607.                 /* why reset the fn1? tfp 11/16/88 */
  608.                 SETFN1(FNCOLOR1,mergexlate[alu]);
  609.                 SETX0(x);
  610.                 SETY0(y);
  611.             }
  612.         }
  613.         ndash++;
  614.         ibm8514ClearQueue(2);
  615.         SETLX(l);
  616.         COMMAND(command);
  617.     }
  618.     ibm8514ClearQueue(6);
  619.     SETMODE(M_ONES);
  620.     SETPAT0(0);
  621.     SETPAT1(0);
  622.     SETFN0(FNCOLOR0,FNREPLACE);
  623.     SETFN1(FNCOLOR1,FNREPLACE);
  624.     PLNWENBL(WPLANES);
  625.     if (saved)
  626.             ibm8514ReplaceCursor();
  627. }
  628.  
  629. void
  630. ibm8514BresDash( pGC, fg, bg, alu, pm, sdx, sdy, axis, x, y, et, e1, e2, len )
  631. GCPtr pGC;
  632. unsigned long int fg, bg;
  633. int alu ;
  634. unsigned long int pm ;
  635. int sdx, sdy, axis, x, y, et, e1, e2, len;
  636. {
  637.     int saved;
  638.     int togo = len;
  639.     int l = pGC->dash[0];
  640.     int n = 0;
  641.     int ndash = 0;
  642.     int  command;
  643.     ppcPrivGCPtr ppcPriv =
  644.         (ppcPrivGCPtr)pGC->devPrivates[mfbGCPrivateIndex].ptr;
  645.     ibm8514PrivGCPtr ibm8514Priv = (ibm8514PrivGCPtr)ppcPriv->devPriv;
  646.     unsigned char flags = ibm8514Priv->Flags;
  647.     unsigned short pattern = ibm8514Priv->Pattern;
  648.  
  649.     saved =
  650.         !ibm8514cursorSemaphore && ibm8514CheckCursor( x,y,len,len ) ;
  651.  
  652.     if (axis==X_AXIS){
  653.         y += pGC->dashOffset;
  654.         command = 0x2017; /* draw bres. line on X, W, LPN, */
  655.     } else {
  656.         x += pGC->dashOffset;
  657.         command = 0x2057; /* same, on Y */
  658.     }
  659.  
  660.     if (sdx > 0)
  661.         command |= 0x0020;
  662.     if (sdy > 0)
  663.         command |= 0x0080;
  664.  
  665.     ibm8514ClearQueue(2);
  666.     SETCOL1(fg);
  667.     SETFN1(FNCOLOR1,mergexlate[alu]);
  668.     if(axis == X_AXIS && flags & HARDWARE_PATTERN){
  669.         ibm8514ClearQueue(6);
  670.         barrel_shift8(pattern, x % 8);
  671.         SETMODE(M_PATTS);
  672.         SETPAT0(pattern >> 3);
  673.         SETPAT1(pattern << 1);
  674.         if(pGC->lineStyle == LineOnOffDash){
  675.             SETFN0(FNCOLOR0,mergexlate[GXnoop]);
  676.         } else {
  677.             SETCOL0(bg);
  678.             SETFN0(FNCOLOR0,mergexlate[alu]);
  679.         }
  680.     }
  681.     ibm8514ClearQueue(6);
  682.     PLNWENBL(pm);
  683.     SETET(et); 
  684.     SETK1(e1); 
  685.     SETK2(e2); 
  686.  
  687.     SETX0(x);
  688.     SETY0(y);
  689.  
  690.     while(togo){
  691.         /* handle odd dash lists later */
  692.         if(n > pGC->numInDashList){
  693.             n = 0;
  694.         }
  695.         l = MIN(pGC->dash[n++], togo);
  696.         togo -= l;
  697.         if(!(axis == X_AXIS && flags & HARDWARE_PATTERN)){
  698.             if(pGC->lineStyle == LineOnOffDash){
  699.                 if(ndash & 0x01)
  700.                     command |= ACCESS_PIXEL;
  701.                 else 
  702.                     command &= ~ACCESS_PIXEL;
  703.             } else {
  704.                 ibm8514ClearQueue(1);
  705.                 if(ndash & 0x01)
  706.                     SETCOL1(bg);
  707.                 else
  708.                     SETCOL1(fg);
  709.                 SETFN1(FNCOLOR1,mergexlate[alu]);
  710.             }
  711.         }
  712.  
  713.         ndash++;
  714.  
  715.         ibm8514ClearQueue(2);
  716.         /* going to use LAST PEL NULL in Line command to brecon */
  717.         SETLX(l);
  718.  
  719.         COMMAND(command);
  720.     }
  721.     ibm8514ClearQueue(6);
  722.     SETMODE(M_ONES);
  723.     SETPAT0(0);
  724.     SETPAT1(0);
  725.     SETFN0(FNCOLOR0,FNREPLACE);
  726.     SETFN1(FNCOLOR1,FNREPLACE);
  727.     PLNWENBL(WPLANES);
  728.     if (saved)
  729.             ibm8514ReplaceCursor();
  730. }
  731.  
  732. void
  733. ibm8514DestroyGCPriv( pGC )
  734.      GC *pGC;            /* ibm8514PrivGCPtr */
  735. {
  736.     if (pGC)
  737.     Xfree(pGC);
  738. }
  739.  
  740. #define barrel_shift8(v, s) \
  741.     (v = (v >> s) | (v << (8 - s)))
  742.  
  743. void
  744. ibm8514_do_dashline_gc(pGC)
  745. GCPtr pGC;
  746. {
  747.     unsigned int len = 0;
  748.     unsigned int n;
  749.     ibm8514PrivGCPtr ibm8514Priv =
  750.     (ibm8514PrivGCPtr) ( (ppcPrivGCPtr) pGC->devPrivates[mfbGCPrivateIndex].ptr )->devPriv;
  751.  
  752.     if (!ibm8514Priv)
  753.     {
  754.     ibm8514Priv = (ibm8514PrivGCPtr)malloc(sizeof(ibm8514PrivGC));
  755.     ibm8514Priv->Flags   = 0;
  756.     ibm8514Priv->Pattern = 0;
  757.     ( (ppcPrivGCPtr) pGC->devPrivates[mfbGCPrivateIndex].ptr )->devPriv =
  758.         (void *)ibm8514Priv;
  759.     }
  760.  
  761.     /* check for dash pattern useable to ibm8514 */
  762.     for ( n = 0 ; n < pGC->numInDashList ; n++ )
  763.     len += pGC->dash[n];
  764.  
  765.     if (    len == 2 ||
  766.     len == 4 ||
  767.     (len == 8 && ((pGC->numInDashList & 1) == 0)))
  768.     {
  769.     int bit;
  770.     int offset = 0;
  771.     unsigned char *dp = &pGC->dash[0];
  772.     unsigned short pattern;
  773.  
  774.     pattern = 0;
  775.     /* encode dash pattern into bitmask */
  776.     while (n-- > 0 && *dp != 0){
  777.         pattern |= ( ( ( 1 << *dp ) - 1 ) << offset ) ;
  778.         offset += *dp++;
  779.         if (n-- > 0)
  780.         offset += *dp++;
  781.     }
  782.     /* replicate pattern over full 8 bits */
  783.     for (bit = offset; bit < 8; bit++){
  784.         pattern |=
  785.         (pattern & (1 << bit - offset))
  786.             << offset;
  787.     }
  788.     /* shift pattern to implement offset - mod 8 */
  789.     /* is it legal for offset > length ?? */
  790.     if (pGC->dashOffset != 0)
  791.         barrel_shift8(pattern, pGC->dashOffset % 8);
  792.     ibm8514Priv->Pattern = pattern;
  793.     ibm8514Priv->Flags |= HARDWARE_PATTERN;
  794.     } else {
  795.     ibm8514Priv->Flags &= ~HARDWARE_PATTERN;
  796.     }
  797.     pGC->ops->Polylines = ibm8514ZeroDash;
  798.     return ;
  799. }
  800.