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 / brcFillRct.c < prev    next >
C/C++ Source or Header  |  1991-10-04  |  27KB  |  1,124 lines

  1. /*
  2.  * $Id: brcFillRct.c,v 1.5 1991/10/04 03:51:01 mtranle Exp $
  3.  *
  4.  * Copyright IBM Corporation 1987,1988,1989
  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. /***********************************************************
  27. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  28. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  29.  
  30.             All Rights Reserved
  31.  
  32. Permission to use, copy, modify, and distribute this software and its
  33. documentation for any purpose and without fee is hereby granted,
  34. provided that the above copyright notice appear in all copies and that
  35. both that copyright notice and this permission notice appear in
  36. supporting documentation, and that the names of Digital or MIT not be
  37. used in advertising or publicity pertaining to distribution of the
  38. software without specific, written prior permission.
  39.  
  40. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  41. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  42. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  43. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  44. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  45. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  46. SOFTWARE.
  47.  
  48. ******************************************************************/
  49.  
  50. #include "X.h"
  51. #include "servermd.h"
  52. #include "pixmapstr.h"
  53. #include "gcstruct.h"
  54. #include "windowstr.h"
  55. #include "miscstruct.h"
  56. #include "regionstr.h"
  57. #include "scrnintstr.h"
  58.  
  59. #include "OScompiler.h"
  60. #include "x8514.h"
  61. #include "ibmTrace.h"
  62.  
  63. #include "ppc.h"
  64. extern int mfbGCPrivateIndex;
  65. extern int mergexlate[] ;
  66. extern int ibm8514cursorSemaphore ;
  67.  
  68. void ibm8514FillRectSolid();
  69. void ibm8514FillRectStippled();
  70. void ibm8514FillRectOpStippled();
  71. void ibm8514FillRectTiled();
  72. void ibm8514AreaFill();
  73.  
  74. #define NUM_STACK_RECTS    1024
  75.  
  76. /*
  77.  *    filled rectangles.
  78.  *    translate the rectangles, clip them, and call the
  79.  *    helper function in the GC.
  80.  */
  81. void
  82. ibm8514PolyFillRect( pDrawable, pGC, nrectFill, prectInit )
  83.      DrawablePtr pDrawable ;
  84.      GCPtr    pGC ;
  85.      int    nrectFill ;     /* number of rectangles to fill */
  86.      xRectangle    *prectInit ;      /* Pointer to first rectangle to fill */
  87. {
  88.     xRectangle        *prect ;            /* temporary */
  89.     RegionPtr       prgnClip ;
  90.     register BoxPtr pbox ;            /* used to clip with */
  91.     register BoxPtr pboxClipped ;
  92.     BoxPtr          pboxClippedBase ;
  93.     BoxPtr          pextent ;
  94.     BoxRec        stackRects[NUM_STACK_RECTS];
  95.     ppcPrivGC       *priv;
  96.     int             numRects;
  97.     void            (* BoxFill)() ;
  98.     int             n ;                /* spare counter */
  99.     int            xorg, yorg;
  100.  
  101.     TRACE(("ibm8514PolyFillRect(0x%x,0x%x,%d,0x%x)\n",pDrawable,pGC,
  102.        nrectFill,prectInit)) ;
  103.  
  104.     if ( pDrawable->type != DRAWABLE_WINDOW )
  105.     {
  106.     ErrorF("ibm8514PolyFillRect: Not a window\n") ;
  107.     return ;
  108.     }
  109.  
  110.     if ( ( pGC->alu == GXnoop ) || !pGC->planemask || !nrectFill )
  111.     return ;
  112.  
  113.     priv = (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr;
  114.     prgnClip = priv->pCompositeClip ;
  115.  
  116.     BoxFill = 0;
  117.     switch (pGC->fillStyle)
  118.     {
  119.       case FillSolid:
  120.     BoxFill = ibm8514FillRectSolid;
  121.     break;
  122.       case FillStippled:
  123.     BoxFill = ibm8514FillRectStippled;
  124.     break;
  125.       case FillOpaqueStippled:
  126.     BoxFill = ibm8514FillRectOpStippled;
  127.     break;
  128.       case FillTiled:
  129.     BoxFill = ibm8514FillRectTiled;
  130.     break;
  131.     }
  132.  
  133.     xorg = pDrawable->x;
  134.     yorg = pDrawable->y;
  135.     if (xorg || yorg)
  136.     {
  137.     prect = prectInit;
  138.     n = nrectFill;
  139.     while(n--)
  140.     {
  141.         prect->x += xorg ;
  142.         prect->y += yorg ;
  143.         prect++ ;
  144.     }
  145.     }
  146.  
  147.     prect = prectInit;
  148.  
  149.     numRects = REGION_NUM_RECTS(prgnClip) + nrectFill;
  150.  
  151.     if (numRects > NUM_STACK_RECTS)
  152.     {
  153.     pboxClippedBase = (BoxPtr)ALLOCATE_LOCAL(numRects * sizeof(BoxRec));
  154.     if (!pboxClippedBase)
  155.         return;
  156.     }
  157.     else
  158.     pboxClippedBase = stackRects;
  159.  
  160.     pboxClipped = pboxClippedBase;
  161.     
  162.     if (REGION_NUM_RECTS(prgnClip) == 1)
  163.     {
  164.     int x1, y1, x2, y2, bx2, by2;
  165.  
  166.     pextent = REGION_RECTS(prgnClip);
  167.     x1 = pextent->x1;
  168.     y1 = pextent->y1;
  169.     x2 = pextent->x2;
  170.     y2 = pextent->y2;
  171.         while (nrectFill--)
  172.         {
  173.         if ((pboxClipped->x1 = prect->x) < x1)
  174.         pboxClipped->x1 = x1;
  175.     
  176.         if ((pboxClipped->y1 = prect->y) < y1)
  177.         pboxClipped->y1 = y1;
  178.     
  179.         bx2 = (int) prect->x + (int) prect->width;
  180.         if (bx2 > x2)
  181.         bx2 = x2;
  182.         pboxClipped->x2 = bx2;
  183.     
  184.         by2 = (int) prect->y + (int) prect->height;
  185.         if (by2 > y2)
  186.         by2 = y2;
  187.         pboxClipped->y2 = by2;
  188.  
  189.         prect++;
  190.         if ((pboxClipped->x1 < pboxClipped->x2) &&
  191.         (pboxClipped->y1 < pboxClipped->y2))
  192.         {
  193.         pboxClipped++;
  194.         }
  195.         }
  196.     }
  197.     else
  198.     {
  199.     int x1, y1, x2, y2, bx2, by2;
  200.  
  201.     pextent = (*pGC->pScreen->RegionExtents)(prgnClip);
  202.     x1 = pextent->x1;
  203.     y1 = pextent->y1;
  204.     x2 = pextent->x2;
  205.     y2 = pextent->y2;
  206.         while (nrectFill--)
  207.         {
  208.         BoxRec box;
  209.     
  210.         if ((box.x1 = prect->x) < x1)
  211.         box.x1 = x1;
  212.     
  213.         if ((box.y1 = prect->y) < y1)
  214.         box.y1 = y1;
  215.     
  216.         bx2 = (int) prect->x + (int) prect->width;
  217.         if (bx2 > x2)
  218.         bx2 = x2;
  219.         box.x2 = bx2;
  220.     
  221.         by2 = (int) prect->y + (int) prect->height;
  222.         if (by2 > y2)
  223.         by2 = y2;
  224.         box.y2 = by2;
  225.     
  226.         prect++;
  227.     
  228.         if ((box.x1 >= box.x2) || (box.y1 >= box.y2))
  229.             continue;
  230.     
  231.         n = REGION_NUM_RECTS (prgnClip);
  232.         pbox = REGION_RECTS(prgnClip);
  233.     
  234.         /* clip the rectangle to each box in the clip region
  235.            this is logically equivalent to calling Intersect()
  236.         */
  237.         while(n--)
  238.         {
  239.         pboxClipped->x1 = MAX(box.x1, pbox->x1);
  240.         pboxClipped->y1 = MAX(box.y1, pbox->y1);
  241.         pboxClipped->x2 = MIN(box.x2, pbox->x2);
  242.         pboxClipped->y2 = MIN(box.y2, pbox->y2);
  243.         pbox++;
  244.  
  245.         /* see if clipping left anything */
  246.         if(pboxClipped->x1 < pboxClipped->x2 && 
  247.            pboxClipped->y1 < pboxClipped->y2)
  248.         {
  249.             pboxClipped++;
  250.         }
  251.         }
  252.         }
  253.     }
  254.     if (pboxClipped != pboxClippedBase)
  255.     (*BoxFill) (pDrawable, pboxClipped-pboxClippedBase, pboxClippedBase,
  256.             pGC);
  257.     if (pboxClippedBase != stackRects)
  258.         DEALLOCATE_LOCAL(pboxClippedBase);
  259. }
  260.  
  261.  
  262. /*
  263.  * Same as ibm8514CheckCursor but does it on the bounding box of a list
  264.  * of boxes pBox.
  265.  */
  266. int
  267. ibm8514CheckCursorInBoxes(nBox, pBox)
  268.      int            nBox;
  269.      BoxPtr         pBox;
  270. {
  271.     if (nBox == 1)
  272.     return ibm8514CheckCursor(pBox->x1, pBox->y1,
  273.                   pBox->x2 - pBox->x1 + 1,
  274.                   pBox->y2 - pBox->y1 + 1);
  275.     else
  276.     {
  277.     int xmin, xmax, ymin, ymax;
  278.     xmin = pBox->x1;
  279.     xmax = pBox->x2;
  280.     ymin = pBox->y1;
  281.     ymax = pBox->y2;
  282.     pBox++; nBox--;
  283.     for ( ; nBox ; nBox--, pBox++)
  284.     {
  285.         if (pBox->x1 < xmin) xmin = pBox->x1;
  286.         if (pBox->x2 > xmax) xmax = pBox->x2;
  287.         if (pBox->y1 < ymin) ymin = pBox->y1;
  288.         if (pBox->y2 > ymax) ymax = pBox->y2;
  289.     }
  290.     return ibm8514CheckCursor(xmin, ymin, xmax-xmin+1, ymax-ymin+1);
  291.     }
  292. }
  293.  
  294.  
  295. /*
  296.  * Handle Solid Rectangle Fill
  297.  */
  298. void
  299. ibm8514FillRectSolid(pWin, nBox, pBox, pGC)
  300.     WindowPtr        pWin;
  301.     GCPtr        pGC;
  302.     int            nBox;
  303.     BoxPtr        pBox;
  304. {
  305.     int       CursorIsSaved;
  306.     short     x, y, w, h;
  307.     ppcPrivGC *priv = (ppcPrivGC *)pGC->devPrivates[mfbGCPrivateIndex].ptr;
  308.  
  309.     if (priv->colorRrop.alu == GXnoop || !nBox)
  310.     return;
  311.  
  312.     CursorIsSaved = (!ibm8514cursorSemaphore &&
  313.              ibm8514CheckCursorInBoxes(nBox, pBox));
  314.     
  315.     ibm8514ATRNotBusy ;
  316.     ibm8514CheckQueue(3) ;
  317.     SETFN1(FNCOLOR1, mergexlate[priv->colorRrop.alu]);
  318.     SETCOL1(priv->colorRrop.fgPixel) ;
  319.     PLNWENBL(priv->colorRrop.planemask) ;
  320.     
  321.     for ( ; nBox; nBox--, pBox++)
  322.     {
  323.     if (!(w = pBox->x2 - (x = pBox->x1)) ||
  324.         !(h = pBox->y2 - (y = pBox->y1)))
  325.         continue;
  326.  
  327.     ibm8514CheckQueue(5) ;
  328.     SETY0(y) ;
  329.     SETX0(x) ;
  330.     SETLY(h-1) ;
  331.     SETLX(w-1) ;
  332.     COMMAND(0x80b3) ;    /* Horizontal Rect operation,
  333.                    DX = DY = 'increasing'*/
  334.     }
  335.  
  336.     ibm8514ClearQueue(2) ;
  337.     PLNWENBL( ibm8514ALLPLANES ) ;
  338.     SETFN1(FNCOLOR1, FNREPLACE) ;
  339.  
  340.     if (CursorIsSaved)
  341.     ibm8514ReplaceCursor() ;
  342. }
  343.  
  344.  
  345. /*
  346.  * Handle Stippled Rectangle Fill.
  347.  */
  348. void
  349. ibm8514FillRectStippled(pWin, nBox, pBox, pGC)
  350.     WindowPtr        pWin;
  351.     GCPtr        pGC;
  352.     int            nBox;
  353.     BoxPtr        pBox;
  354. {
  355.     int        CursorIsSaved;
  356.     short     x, y, w, h;
  357.     unsigned    short tlx, tly ;
  358.     short     xSrc, ySrc;
  359.     PixmapPtr    pStipple;
  360.     ppcPrivGC   *priv = (ppcPrivGC *)pGC->devPrivates[mfbGCPrivateIndex].ptr;
  361.  
  362.     int     hcount, vcount, vtarget, htarget, savehcount, savehtarget ;
  363.     int     maxhite, maxwid ;
  364.  
  365.     if (priv->colorRrop.alu == GXnoop || !nBox)
  366.     return;
  367.  
  368.     pStipple  = pGC->stipple;
  369.  
  370.     tlx = pStipple->drawable.width ;
  371.     tly = pStipple->drawable.height ;
  372.  
  373.     /* this replaces rotating the stipple. Instead we just adjust the offset
  374.      * at which we start grabbing bits from the stipple.
  375.      * Ensure that ppt->x - xSrc >= 0 and ppt->y - ySrc >= 0,
  376.      * so that iline and xrem always stay within the stipple bounds.
  377.      */
  378.  
  379.     xSrc = (pGC->patOrg.x % tlx) - tlx + pWin->drawable.x;
  380.     ySrc = (pGC->patOrg.y % tly) - tly + pWin->drawable.y;
  381.  
  382.     CursorIsSaved = (!ibm8514cursorSemaphore &&
  383.              ibm8514CheckCursorInBoxes(nBox, pBox));
  384.     ibm8514cursorSemaphore++;
  385.  
  386.     if ( ( tlx > MAXSTIPPLEWIDTH ) || ( tly > MAXSTIPPLEHEIGHT ) )
  387.     {
  388.     for ( ; nBox; nBox--, pBox++)
  389.     {
  390.         if (!(w = pBox->x2 - (x = pBox->x1)) ||
  391.         !(h = pBox->y2 - (y = pBox->y1)))
  392.         continue;
  393.         ibm8514UnnaturalStipple( pStipple,
  394.                     priv->colorRrop.fgPixel,
  395.                     priv->colorRrop.alu,
  396.                     priv->colorRrop.planemask,
  397.                     x, y, w, h, xSrc, ySrc) ;
  398.     }
  399.     }
  400.     else
  401.     {
  402.     int     stageMonoDone = 0;
  403.  
  404.     ibm8514ATRNotBusy ;
  405.     for ( ; nBox; nBox--, pBox++)
  406.     {
  407.         if (!(w = pBox->x2 - (x = pBox->x1)) ||
  408.         !(h = pBox->y2 - (y = pBox->y1)))
  409.         continue;
  410.  
  411.         if ( x < 0 )
  412.         {
  413.         w += x ;
  414.         x = 0 ;
  415.         }
  416.         if ( y < 0 )
  417.         {
  418.         h += y ;
  419.         y = 0 ;
  420.         }
  421.         w = MIN(_8514_SCREENWIDTH-x, w) ;
  422.         h = MIN(_8514_SCREENHEIGHT-y, h) ;
  423.  
  424.         if ( ( w <= 0) || (h <= 0)  )
  425.         continue ;
  426.  
  427.         if (!stageMonoDone)
  428.         {
  429.         ibm8514StageMono(tlx, tly, pStipple->devPrivate.ptr) ;
  430.         stageMonoDone++;
  431.         }
  432.         /*expand the tile to largest available size */
  433.         maxwid  = MIN(MAXSTIPPLEWIDTH, w) ;
  434.         maxhite = MIN(MAXSTIPPLEHEIGHT, h) ;
  435.  
  436.         if ( (tlx*2 <= maxwid) || ((tly*2) <= maxhite) )
  437.         {
  438.         ibm8514CheckQueue( 4 ) ;
  439.         PLNRENBL( MONO_STAGE_RPLANE ) ;
  440.         PLNWENBL( MONO_STAGE_WPLANE ) ;
  441.         SETFN1( FNCPYRCT, mergexlate[GXcopy] ) ;
  442.  
  443.         SETLY( tly-1 ) ;
  444.  
  445.         while ( tlx*2 <= maxwid )
  446.         {
  447.             /*
  448.              * ibm8514Bitblt( GXcopy, MONO_STAGE_RPLANE,
  449.              *       MONO_STAGE_WPLANE,
  450.              *     MONO_STAGE_X, MONO_STAGE_Y,
  451.              *     MONO_STAGE_X, tly+MONO_STAGE_Y,
  452.              *     tlx, tly)
  453.              */
  454.             ibm8514CheckQueue( 6 ) ;
  455.             SETX0( MONO_STAGE_X ) ;
  456.             SETX1( tlx + MONO_STAGE_X ) ;
  457.             SETLX( tlx-1 ) ;
  458.             SETY0( MONO_STAGE_Y ) ;
  459.             SETY1( MONO_STAGE_Y ) ;
  460.             COMMAND( 0xC0F3 ) ;
  461.         
  462.             tlx *= 2 ;
  463.         }
  464.  
  465.         ibm8514CheckQueue( 1 ) ;
  466.         SETLX( tlx-1 ) ;
  467.  
  468.         while ( tly*2 <= maxhite )
  469.         {
  470.             /*
  471.              * ibm8514Bitblt( GXcopy, MONO_STAGE_RPLANE,
  472.              *          MONO_STAGE_WPLANE,
  473.              *          MONO_STAGE_X, MONO_STAGE_Y,
  474.              *          MONO_STAGE_X, tly+MONO_STAGE_Y,
  475.              *          tlx, tly) ;
  476.              */
  477.             ibm8514CheckQueue( 6 ) ;
  478.             SETY0( MONO_STAGE_Y ) ;
  479.             SETY1( tly + MONO_STAGE_Y ) ;
  480.             SETLY( tly-1 ) ;
  481.             SETX0( MONO_STAGE_X ) ;
  482.             SETX1( MONO_STAGE_X ) ;
  483.             COMMAND( 0xC0F3 ) ;
  484.  
  485.             tly *= 2 ;
  486.         }
  487.         }
  488.         {
  489.         int    tmp = ( x - xSrc ) % tlx ;
  490.         if ( tmp < 0  )
  491.             tmp += tlx ;
  492.         savehtarget = htarget = x - tmp ;
  493.         }
  494.         {
  495.         int tmp = ( y - ySrc ) % tly ;
  496.         if ( tmp < 0  )
  497.             tmp += tly ;
  498.         vtarget = y - tmp ;
  499.         }
  500.  
  501.         savehcount = hcount = ((x+w-htarget)+tlx-1)/tlx ; /*tiles to fill horiz */
  502.         vcount = ((y+h-vtarget)+tly-1)/tly ; /*tiles it will take to fill vert */
  503.  
  504.         ibm8514ClearQueue(4) ;
  505.         SETXMAX(x+w-1) ;
  506.         SETYMAX(y+h-1) ;
  507.         SETXMIN(x) ;
  508.         SETYMIN(y) ;
  509.  
  510.         /* -- */
  511.         ibm8514CheckQueue( 6 ) ;
  512.         SETFN0( FNCOLOR0, FNNOP ) ;
  513.         SETFN1( FNCOLOR1, mergexlate[priv->colorRrop.alu] ) ;
  514.         PLNRENBL( MONO_STAGE_RPLANE ) ;
  515.         PLNWENBL( priv->colorRrop.planemask ) ;
  516.         SETMODE( M_CPYRCT ) ;
  517.         SETCOL1( priv->colorRrop.fgPixel ) ;
  518.  
  519.         ibm8514CheckQueue( 2 ) ;
  520.         SETLX( tlx-1 ) ;
  521.         SETLY( tly-1 ) ;
  522.  
  523.         while ( vcount-- )
  524.         {
  525.         while ( hcount-- )
  526.         {
  527.             /*
  528.              * ibm8514BlitFG( MONO_STAGE_RPLANE, pm, fg, alu,
  529.              *              MONO_STAGE_X, MONO_STAGE_Y,
  530.              *              htarget, vtarget, tlx, tly) ;
  531.              */
  532.             ibm8514CheckQueue( 5 ) ;
  533.             SETX0( MONO_STAGE_X ) ;
  534.             SETY0( MONO_STAGE_Y ) ;
  535.             SETX1( htarget ) ;
  536.             SETY1( vtarget ) ;
  537.             COMMAND( 0xC0F3 ) ;
  538.  
  539.             htarget += tlx ;
  540.         }
  541.         vtarget += tly ;
  542.         htarget = savehtarget ;
  543.         hcount  = savehcount ;
  544.         }
  545.  
  546.         ibm8514CheckQueue( 5 ) ;
  547.         PLNRENBL( RPLANES ) ;
  548.         PLNWENBL( WPLANES ) ;
  549.         SETFN0( FNCOLOR0, FNREPLACE ) ;
  550.         SETFN1( FNCOLOR1, FNREPLACE ) ;
  551.         SETMODE( M_ONES ) ;
  552.         /* -- */
  553.  
  554.         ibm8514ClearQueue(4) ;
  555.         SETXMAX(_8514_SCREENWIDTH-1) ;
  556.         SETYMAX( 1023 ) ;
  557.         SETXMIN(0) ;
  558.         SETYMIN(0) ;
  559.     }
  560.     }
  561.     if ( !(--ibm8514cursorSemaphore) && CursorIsSaved )
  562.     ibm8514ReplaceCursor() ;
  563. }
  564.  
  565.  
  566. /*
  567.  * Handle Opaque Stippled Rectangle Fill.
  568.  */
  569. void
  570. ibm8514FillRectOpStippled(pWin, nBox, pBox, pGC)
  571.     WindowPtr        pWin;
  572.     GCPtr        pGC;
  573.     int            nBox;
  574.     BoxPtr        pBox;
  575. {
  576.     int        CursorIsSaved;
  577.     short     x, y, w, h ;
  578.     short     xSrc, ySrc;
  579.     PixmapPtr    pStipple;
  580.     ppcPrivGC   *priv = (ppcPrivGC *)pGC->devPrivates[mfbGCPrivateIndex].ptr;
  581.     unsigned    short tlx, tly ;
  582.  
  583.     if (priv->colorRrop.alu == GXnoop || !nBox)
  584.     return;
  585.  
  586.     pStipple  = pGC->stipple;
  587.  
  588.     tlx = pStipple->drawable.width ;
  589.     tly = pStipple->drawable.height ;
  590.  
  591.     /* this replaces rotating the stipple. Instead we just adjust the offset
  592.      * at which we start grabbing bits from the stipple.
  593.      * Ensure that ppt->x - xSrc >= 0 and ppt->y - ySrc >= 0,
  594.      * so that iline and xrem always stay within the stipple bounds.
  595.      */
  596.  
  597.     xSrc = (pGC->patOrg.x % tlx) - tlx + pWin->drawable.x;
  598.     ySrc = (pGC->patOrg.y % tly) - tly + pWin->drawable.y;
  599.  
  600.     CursorIsSaved = (!ibm8514cursorSemaphore &&
  601.              ibm8514CheckCursorInBoxes(nBox, pBox));
  602.     ibm8514cursorSemaphore++;
  603.  
  604.     if ( ( tlx > MAXSTIPPLEWIDTH ) || ( tly > MAXSTIPPLEHEIGHT ) )
  605.     {
  606.     for ( ; nBox; nBox--, pBox++)
  607.     {
  608.         if (!(w = pBox->x2 - (x = pBox->x1)) ||
  609.         !(h = pBox->y2 - (y = pBox->y1)))
  610.         continue;
  611.  
  612.         ibm8514UnnaturalOpStipple( pStipple,
  613.                       priv->colorRrop.fgPixel,
  614.                       priv->colorRrop.bgPixel,
  615.                       priv->colorRrop.alu,
  616.                       priv->colorRrop.planemask,
  617.                       x, y, w, h, xSrc, ySrc) ;
  618.     }
  619.     }
  620.     else
  621.     {
  622.     int     hcount, vcount, vtarget, htarget, savehcount, savehtarget ;
  623.     int     maxhite, maxwid ;
  624.     int     stageMonoDone = 0;
  625.  
  626.     ibm8514ATRNotBusy ;
  627.     for ( ; nBox; nBox--, pBox++)
  628.     {
  629.         if (!(w = pBox->x2 - (x = pBox->x1)) ||
  630.         !(h = pBox->y2 - (y = pBox->y1)))
  631.         continue;
  632.  
  633.         if ( x < 0 )
  634.         {
  635.         w += x ;
  636.         x = 0 ;
  637.         }
  638.         if ( y < 0 )
  639.         {
  640.         h += y ;
  641.         y = 0 ;
  642.         }
  643.         w = MIN(_8514_SCREENWIDTH-x, w) ;
  644.         h = MIN(_8514_SCREENHEIGHT-y, h) ;
  645.  
  646.         if ( (w <= 0) || (h <= 0 )  )
  647.         continue ;
  648.  
  649.         if (!stageMonoDone)
  650.         {
  651.         ibm8514StageMono(tlx, tly, pStipple->devPrivate.ptr) ;
  652.         stageMonoDone++;
  653.         }
  654.         /*expand the tile to largest available size */
  655.         maxwid  = MIN(MAXSTIPPLEWIDTH, w) ;
  656.         maxhite = MIN(MAXSTIPPLEHEIGHT, h) ;
  657.  
  658.         if ( (tlx*2 <= maxwid) || (tly*2 <= maxhite) )
  659.         {
  660.         ibm8514CheckQueue( 4 ) ;
  661.         PLNRENBL( MONO_STAGE_RPLANE ) ;
  662.         PLNWENBL( MONO_STAGE_WPLANE ) ;
  663.         SETFN1( FNCPYRCT, mergexlate[GXcopy] ) ;
  664.  
  665.         SETLY( tly-1 ) ;
  666.  
  667.         while ( tlx*2 <= maxwid )
  668.         {
  669.             /*
  670.              * ibm8514Bitblt( GXcopy, MONO_STAGE_RPLANE,
  671.              *       MONO_STAGE_WPLANE,
  672.              *     MONO_STAGE_X, MONO_STAGE_Y,
  673.              *     MONO_STAGE_X, tly+MONO_STAGE_Y,
  674.              *     tlx, tly)
  675.              */
  676.             ibm8514CheckQueue( 6 ) ;
  677.             SETX0( MONO_STAGE_X ) ;
  678.             SETY0( MONO_STAGE_Y ) ;
  679.             SETX1( tlx + MONO_STAGE_X ) ;
  680.             SETY1( MONO_STAGE_Y ) ;
  681.             SETLX( tlx-1 ) ;
  682.             COMMAND( 0xC0F3 ) ;
  683.         
  684.             tlx *= 2 ;
  685.         }
  686.  
  687.         ibm8514CheckQueue( 1 ) ;
  688.         SETLX( tlx-1 ) ;
  689.  
  690.         while ( tly*2 <= maxhite )
  691.         {
  692.             /*
  693.              * ibm8514Bitblt( GXcopy, MONO_STAGE_RPLANE,
  694.              *          MONO_STAGE_WPLANE,
  695.              *          MONO_STAGE_X, MONO_STAGE_Y,
  696.              *          MONO_STAGE_X, tly+MONO_STAGE_Y,
  697.              *          tlx, tly) ;
  698.              */
  699.             ibm8514CheckQueue( 6 ) ;
  700.             SETX0( MONO_STAGE_X ) ;
  701.             SETY0( MONO_STAGE_Y ) ;
  702.             SETX1( MONO_STAGE_X ) ;
  703.             SETY1( tly + MONO_STAGE_Y ) ;
  704.             SETLY( tly-1 ) ;
  705.             COMMAND( 0xC0F3 ) ;
  706.  
  707.             tly *= 2 ;
  708.         }
  709.         }
  710.         {
  711.         int    tmp = ( x - xSrc ) % tlx ;
  712.         if ( tmp < 0  )
  713.             tmp += tlx ;
  714.         savehtarget = htarget = x - tmp ;
  715.         }
  716.         {
  717.         int tmp = ( y - ySrc ) % tly ;
  718.         if ( tmp < 0  )
  719.             tmp += tly ;
  720.         vtarget = y - tmp ;
  721.         }
  722.  
  723.         savehcount = hcount = ((x+w-htarget)+tlx-1)/tlx ; /*tiles to fill horiz */
  724.         vcount = ((y+h-vtarget)+tly-1)/tly ; /*tiles it will take to fill vert */
  725.  
  726.         ibm8514ClearQueue(4) ;
  727.         SETXMAX(x+w-1) ;
  728.         SETYMAX(y+h-1) ;
  729.         SETXMIN(x) ;
  730.         SETYMIN(y) ;
  731.  
  732.         /* -- */
  733.         ibm8514CheckQueue( 7 ) ;
  734.         SETFN0( FNCOLOR0, mergexlate[priv->colorRrop.alu] ) ;
  735.         SETFN1( FNCOLOR1, mergexlate[priv->colorRrop.alu] ) ;
  736.         SETCOL0( priv->colorRrop.bgPixel ) ;
  737.         SETCOL1( priv->colorRrop.fgPixel ) ;
  738.         PLNRENBL( MONO_STAGE_RPLANE ) ;
  739.         PLNWENBL( priv->colorRrop.planemask ) ;
  740.         SETMODE( M_CPYRCT ) ;
  741.  
  742.         ibm8514CheckQueue( 2 ) ;
  743.         SETLX( tlx-1 ) ;
  744.         SETLY( tly-1 ) ;
  745.  
  746.         while ( vcount-- )
  747.         {
  748.         while ( hcount-- )
  749.         {
  750.             /*
  751.              * ibm8514BlitFGBG(MONO_STAGE_RPLANE, planes, fg, bg,merge,
  752.              *        MONO_STAGE_X, MONO_STAGE_Y,
  753.              *        htarget, vtarget, tlx, tly) ;
  754.              */
  755.             ibm8514CheckQueue( 5 ) ;
  756.             SETX0( MONO_STAGE_X ) ;
  757.             SETY0( MONO_STAGE_Y ) ;
  758.             SETX1( htarget ) ;
  759.             SETY1( vtarget ) ;
  760.             COMMAND( 0xC0F3 ) ;
  761.  
  762.             htarget += tlx ;
  763.         }
  764.         vtarget += tly ;
  765.         htarget = savehtarget ;
  766.         hcount  = savehcount ;
  767.         }
  768.  
  769.         ibm8514CheckQueue( 5 ) ;
  770.         PLNRENBL( RPLANES ) ;
  771.         PLNWENBL( WPLANES ) ;
  772.         SETFN0( FNCOLOR0, FNREPLACE ) ;
  773.         SETFN1( FNCOLOR1, FNREPLACE ) ;
  774.         SETMODE( M_ONES ) ;
  775.         /* -- */
  776.  
  777.         ibm8514ClearQueue(4) ;
  778.         SETXMAX(_8514_SCREENWIDTH-1) ;
  779.         SETYMAX( 1023 ) ;
  780.         SETXMIN(0) ;
  781.         SETYMIN(0) ;
  782.     }
  783.     }
  784.     if ( !(--ibm8514cursorSemaphore) && CursorIsSaved  )
  785.     ibm8514ReplaceCursor() ;
  786. }
  787.  
  788. /*
  789.  * Handle Tile Rectangle Fill.
  790.  */
  791. void
  792. ibm8514FillRectTiled(pWin, nBox, pBox, pGC)
  793.     WindowPtr        pWin;
  794.     GCPtr        pGC;
  795.     int            nBox;
  796.     BoxPtr        pBox;
  797. {
  798.     int        CursorIsSaved;
  799.     short     x, y, w, h ;
  800.     short     xSrc, ySrc;
  801.     unsigned    short tlx, tly;
  802.     PixmapPtr    pTile;
  803.     ppcPrivGC   *priv = (ppcPrivGC *)pGC->devPrivates[mfbGCPrivateIndex].ptr;
  804.  
  805.  
  806.     if (priv->colorRrop.alu == GXnoop || !nBox)
  807.     return;
  808.  
  809.     switch (priv->colorRrop.alu)
  810.     {
  811.       case GXset:
  812.       case GXclear:
  813.       case GXinvert:
  814.     ibm8514FillRectSolid (pWin, nBox, pBox, pGC);
  815.     return;
  816.     }
  817.  
  818.     pTile = pGC->tile.pixmap;
  819.  
  820.     tlx = pTile->drawable.width ;
  821.     tly = pTile->drawable.height ;
  822.  
  823.     /* this replaces rotating the stipple. Instead we just adjust the offset
  824.      * at which we start grabbing bits from the stipple.
  825.      * Ensure that ppt->x - xSrc >= 0 and ppt->y - ySrc >= 0,
  826.      * so that iline and xrem always stay within the stipple bounds.
  827.      */
  828.  
  829.     xSrc = (pGC->patOrg.x % tlx) - tlx + pWin->drawable.x;
  830.     ySrc = (pGC->patOrg.y % tly) - tly + pWin->drawable.y;
  831.  
  832.     CursorIsSaved = (!ibm8514cursorSemaphore &&
  833.              ibm8514CheckCursorInBoxes(nBox, pBox));
  834.     ibm8514cursorSemaphore++;
  835.  
  836.     if ( ( tlx > MAXTILESIZE ) || ( tly > MAXTILESIZE ) )
  837.     {
  838.     for ( ; nBox; nBox--, pBox++)
  839.     {
  840.         if (!(w = pBox->x2 - (x = pBox->x1)) ||
  841.         !(h = pBox->y2 - (y = pBox->y1)))
  842.         continue;
  843.  
  844.         ppcTileRect( pTile, priv->colorRrop.alu, priv->colorRrop.planemask,
  845.              x, y, w, h, xSrc, ySrc) ;
  846.     }
  847.     }
  848.     else
  849.     {
  850.     int     htarget, tmp_w, tw, th, hoffset, voffset ;
  851.     int     maxhite, maxwid ;
  852.     int     drawColorImageDone = 0;
  853.  
  854.     ibm8514ATRNotBusy ;
  855.     for ( ; nBox; nBox--, pBox++)
  856.     {
  857.         if (!(w = pBox->x2 - (x = pBox->x1)) ||
  858.         !(h = pBox->y2 - (y = pBox->y1)))
  859.         continue;
  860.  
  861.         if ( x < 0 )
  862.         {
  863.         w += x ;
  864.         x = 0 ;
  865.         }
  866.         if ( y < 0 )
  867.         {
  868.         h += y ;
  869.         y = 0 ;
  870.         }
  871.         w = MIN(_8514_SCREENWIDTH-x, w) ;
  872.         h = MIN(_8514_SCREENHEIGHT-y, h) ;
  873.  
  874.         if ( (w <= 0) || (h <= 0 )  )
  875.         continue ;
  876.  
  877.         if ( !drawColorImageDone )
  878.         {
  879.         /* ALAS, ALACK, we are going to have to actually draw the silly
  880.          * thing N times.  I won't bother rotating it, I'll just draw
  881.          * to the origin points clipped to the desired box.  It's not
  882.          * clear when this is a win.
  883.          */
  884.         ibm8514DrawColorImage( TILE_X, TILE_Y, tlx, tly,
  885.                       pTile->devPrivate.ptr,
  886.                       pTile->devKind,
  887.                       GXcopy, ibm8514ALLPLANES ) ;
  888.         drawColorImageDone++;
  889.         }
  890.  
  891.         ibm8514CheckQueue( 2 ) ;
  892.         PLNRENBL( ibm8514ALLPLANES ) ;
  893.         PLNWENBL( ibm8514ALLPLANES ) ;
  894.  
  895.         /*expand the tile to largest available size */
  896.         maxwid  = MIN(MAXTILESIZE, w) ;
  897.         maxhite = MIN(MAXTILESIZE, h) ;
  898.         if ( (tlx*2 <= maxwid) || (tly*2 <= maxhite) )
  899.         {
  900.         ibm8514CheckQueue( 2 ) ;
  901.         SETFN1( FNCPYRCT, mergexlate[GXcopy] ) ;
  902.  
  903.         SETLY( tly-1 );
  904.  
  905.         while ( tlx*2 <= maxwid )
  906.         {
  907.             /*
  908.              * ibm8514Bitblt(GXcopy,ibm8514ALLPLANES,ibm8514ALLPLANES,
  909.              *          TILE_X,TILE_Y,tlx+TILE_X,TILE_Y, tlx, tly ) ;
  910.              */
  911.             ibm8514CheckQueue( 6 ) ;
  912.  
  913.             SETX0( TILE_X ) ;
  914.             SETX1( tlx + TILE_X ) ;
  915.             SETLX( tlx-1 ) ;
  916.             SETY0( TILE_Y ) ;
  917.             SETY1( TILE_Y ) ;
  918.             COMMAND( 0xC0F3 ) ;
  919.  
  920.             tlx *= 2 ;
  921.         }
  922.  
  923.         ibm8514CheckQueue( 1 ) ;
  924.         SETLX( tlx-1 ) ;
  925.  
  926.         while ( tly*2 <= maxhite )
  927.         {
  928.             /*
  929.              * ibm8514Bitblt(GXcopy,ibm8514ALLPLANES,ibm8514ALLPLANES,
  930.              *          TILE_X,TILE_Y,TILE_X,TILE_Y+tly,tlx,tly ) ;
  931.              */
  932.             ibm8514CheckQueue( 6 ) ;
  933.  
  934.             SETY0( TILE_Y ) ;
  935.             SETY1( tly + TILE_Y ) ;
  936.             SETLY( tly-1 ) ;
  937.             SETX0( TILE_X ) ;
  938.             SETX1( TILE_X ) ;
  939.             COMMAND( 0xC0F3 ) ;
  940.  
  941.             tly *= 2 ;
  942.         }
  943.         }
  944.         if ( ( hoffset = ( x - xSrc ) % tlx ) < 0 )
  945.         hoffset += tlx ;
  946.         if ( ( voffset = ( y - ySrc ) % tly ) < 0 )
  947.         voffset += tly ;
  948.  
  949.         /*
  950.          * -- ibm8514RotateTile( tlx, tly, hoffset, voffset ) --
  951.          */
  952.         /* DO BOTTOM RIGHT */
  953.         /* You definitely want to do this, even if hoffset==voffset==0.
  954.          *  This is to force *something* into the RotatedTile location
  955.          */
  956.         /*
  957.          * ibm8514Bitblt( GXcopy, ibm8514ALLPLANES, ibm8514ALLPLANES,
  958.          *          TILE_X + hoffset, TILE_Y + voffset,
  959.          *          ROTTILE_X, ROTTILE_Y,
  960.          *          tlx-hoffset, tly-voffset ) ;
  961.          */
  962.         ibm8514CheckQueue( 8 ) ;
  963.         SETFN1( FNCPYRCT, mergexlate[GXcopy] ) ;
  964.         
  965.         SETX0( TILE_X + hoffset ) ;
  966.         SETY0( TILE_Y + voffset ) ;
  967.         SETX1( ROTTILE_X ) ;
  968.         SETY1( ROTTILE_Y ) ;
  969.         SETLX( tlx-hoffset-1 ) ;
  970.         SETLY( tly-voffset-1 ) ;
  971.         COMMAND( 0xC0F3 ) ;
  972.         
  973.         
  974.         /* DO TOP RIGHT */
  975.         if (voffset)
  976.         {
  977.         /*
  978.          * ibm8514Bitblt(GXcopy,ibm8514ALLPLANES,ibm8514ALLPLANES,
  979.          *          TILE_X + hoffset, TILE_Y,
  980.          *          ROTTILE_X, ROTTILE_Y + tly-voffset,
  981.          *          tlx-hoffset, voffset ) ;
  982.          */
  983.         ibm8514CheckQueue( 6 ) ;
  984.         SETX0( TILE_X + hoffset ) ;
  985.         SETY0( TILE_Y ) ;
  986.         SETX1( ROTTILE_X ) ;
  987.         SETY1( ROTTILE_Y + tly-voffset ) ;
  988.         SETLY( voffset-1 ) ;
  989.         COMMAND( 0xC0F3 ) ;
  990.         }
  991.         
  992.         /* DO BOTTOM LEFT */
  993.         if (hoffset)
  994.         {
  995.         /*
  996.          * ibm8514Bitblt(GXcopy,ibm8514ALLPLANES,ibm8514ALLPLANES,
  997.          *          TILE_X , TILE_Y+voffset,
  998.          *          ROTTILE_X+tlx-hoffset, ROTTILE_Y,
  999.          *          hoffset, tly-voffset ) ;
  1000.          */
  1001.         ibm8514CheckQueue( 7 ) ;
  1002.         SETX0( TILE_X ) ;
  1003.         SETY0( TILE_Y + voffset ) ;
  1004.         SETX1( ROTTILE_X + tlx-hoffset ) ;
  1005.         SETY1( ROTTILE_Y ) ;
  1006.         SETLX( hoffset-1 ) ;
  1007.         SETLY( tly-voffset-1 ) ;
  1008.         COMMAND( 0xC0F3 ) ;
  1009.         
  1010.         
  1011.         /* DO TOP LEFT */
  1012.         if (voffset)
  1013.         {
  1014.             /*
  1015.              * ibm8514Bitblt(GXcopy,ibm8514ALLPLANES,
  1016.              *          ibm8514ALLPLANES,
  1017.              *          TILE_X , TILE_Y,
  1018.              *          ROTTILE_X+tlx-hoffset,
  1019.              *          ROTTILE_Y+tly-voffset,
  1020.              *          hoffset, voffset ) ;
  1021.              */
  1022.             ibm8514CheckQueue( 6 ) ;
  1023.             SETX0( TILE_X ) ;
  1024.             SETY0( TILE_Y ) ;
  1025.             SETX1( ROTTILE_X + tlx-hoffset ) ;
  1026.             SETY1( ROTTILE_Y + tly-voffset ) ;
  1027.             SETLY( voffset-1 ) ;
  1028.             COMMAND( 0xC0F3 ) ;
  1029.         }
  1030.         }
  1031.         /* -- */
  1032.         /*
  1033.          * For GXcopy and GXcopyInverted we could use a smarter
  1034.          * algorithm here like in ppcTile().
  1035.          */
  1036.         ibm8514CheckQueue( 2 ) ;
  1037.         PLNWENBL( priv->colorRrop.planemask ) ;
  1038.         SETFN1( FNCPYRCT, mergexlate[priv->colorRrop.alu] ) ;
  1039.  
  1040.         for ( ; h ; h -= th, y += th )
  1041.         {
  1042.         th = MIN( h, tly ) ;
  1043.  
  1044.         ibm8514CheckQueue( 1 ) ;
  1045.         SETLY( th - 1 ) ;
  1046.  
  1047.         for ( htarget = x, tmp_w = w ; tmp_w ;
  1048.               tmp_w -= tw, htarget += tlx )
  1049.         {
  1050.             /*
  1051.              * ibm8514Bitblt( merge, ibm8514ALLPLANES, planes,
  1052.              *          ROTTILE_X, ROTTILE_Y,
  1053.              *          htarget, y,
  1054.              *          tw = MIN( tmp_w, tlx ), th ) ;
  1055.              */
  1056.             ibm8514CheckQueue( 6 ) ;
  1057.             SETX0( ROTTILE_X ) ;
  1058.             SETY0( ROTTILE_Y ) ;
  1059.             SETX1( htarget ) ;
  1060.             SETY1( y ) ;
  1061.             SETLX( (tw = MIN( tmp_w, tlx )) - 1 ) ;
  1062.             COMMAND( 0xC0F3 ) ;
  1063.  
  1064.         }
  1065.         }
  1066.         ibm8514CheckQueue( 2 ) ;
  1067.         PLNWENBL( ibm8514ALLPLANES ) ;
  1068.         SETFN1( FNCOLOR1, FNREPLACE ) ; /* as expected elsewhere */
  1069.     }
  1070.     }
  1071.     if ( !(--ibm8514cursorSemaphore) && CursorIsSaved  )
  1072.     ibm8514ReplaceCursor() ;
  1073. }
  1074.  
  1075.  
  1076. /*
  1077.  * Generic Area Fill.
  1078.  * this is mainly a modified version of the function ppcFillArea().
  1079.  * We mostly handle here FillTiled and FillOpaqueStippled.
  1080.  */
  1081. void
  1082. ibm8514AreaFill(pWin, nBox, pBox, pGC)
  1083.     WindowPtr        pWin;
  1084.     GCPtr        pGC;
  1085.     int            nBox;
  1086.     BoxPtr        pBox;
  1087. {
  1088.     void     (*FillFunc)();
  1089.     ppcPrivGC     *priv = (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr;
  1090.  
  1091.     if (priv->colorRrop.alu == GXnoop || !nBox)
  1092.     return;
  1093.  
  1094.     switch (priv->colorRrop.fillStyle)
  1095.     {
  1096.       case FillOpaqueStippled:
  1097.     FillFunc = ibm8514FillRectOpStippled;
  1098.     break;
  1099.       case FillStippled:
  1100.     FillFunc = ibm8514FillRectStippled;
  1101.     break;
  1102.       case FillTiled:
  1103.     switch (priv->colorRrop.alu)
  1104.     {
  1105.       case GXset:
  1106.       case GXclear:
  1107.       case GXinvert:
  1108.         FillFunc = ibm8514FillRectSolid;
  1109.         break;
  1110.       default:
  1111.         FillFunc = ibm8514FillRectTiled;
  1112.     }
  1113.     break;
  1114.       case FillSolid:
  1115.     FillFunc = ibm8514FillRectSolid;
  1116.     break;
  1117.       default:
  1118.     FillFunc = NULL;
  1119.     }
  1120.     if (FillFunc)
  1121.     (*FillFunc)(pWin, nBox, pBox, pGC);
  1122. }
  1123.  
  1124.