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 / brcStip.c < prev    next >
C/C++ Source or Header  |  1991-09-28  |  14KB  |  554 lines

  1. /*
  2.  * $Id: brcStip.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. /* DO STIPPLES!!!
  37.  */
  38.  
  39. #include "X.h"
  40. #include "servermd.h"
  41. #include "pixmap.h"
  42. #include "pixmapstr.h"
  43. #include "gcstruct.h"
  44.  
  45. #include "OScompiler.h"
  46.  
  47. #include "x8514.h"
  48.  
  49. #include "ibmTrace.h"
  50.  
  51. extern int ibm8514cursorSemaphore ;
  52. extern PixmapPtr mfbCopyPixmap() ;
  53.  
  54. void
  55. ibm8514UnnaturalOpStipple( pStipple, fg, bg, merge, planes,
  56.                x, y, w, h, xSrc, ySrc )
  57.      PixmapPtr pStipple ;
  58.      unsigned long int fg, bg ;
  59.      int merge ;
  60.      unsigned long int planes ;
  61.      int x, y, w, h, xSrc, ySrc ;
  62. {
  63.     int hcount, vcount, vtarget, htarget, savehcount, savehtarget, tlx, tly ;
  64.     int maxwid, heightleft, tmp, CursorIsSaved, yoffset, this_height ;
  65.     unsigned char *data ;
  66.  
  67.     if ( x < 0 )
  68.     {
  69.     w += x ;
  70.     x = 0 ;
  71.     }
  72.     if ( y < 0 )
  73.     {
  74.     h += y ;
  75.     y = 0 ;
  76.     }
  77.     w = MIN(_8514_SCREENWIDTH-x, w) ;
  78.     h = MIN(_8514_SCREENHEIGHT-y, h) ;
  79.  
  80.     if ( ( w <= 0 ) || ( h <= 0 )  )
  81.     return ;
  82.  
  83.     tlx = pStipple->drawable.width ;
  84.     tly = pStipple->drawable.height ;
  85.  
  86.     CursorIsSaved = !ibm8514cursorSemaphore
  87.     && ibm8514CheckCursor( x, y, x + w, y + h ) ;
  88.     ibm8514cursorSemaphore++ ;
  89.  
  90.     heightleft = h ;
  91.     yoffset = 0 ;
  92.  
  93.     data = pStipple->devPrivate.ptr ;
  94.     while ( heightleft > 0 )
  95.     {
  96.     this_height = MIN( heightleft, MAXSTIPPLEHEIGHT ) ;
  97.     ibm8514StageMono( tlx, this_height, data ) ;
  98.     /*expand the tile to largest available size */
  99.     maxwid = MIN( MAXSTIPPLEWIDTH, w ) ;
  100.     while ( tlx * 2 <= maxwid )
  101.     {
  102.         ibm8514Bitblt( GXcopy, MONO_STAGE_RPLANE, MONO_STAGE_WPLANE,
  103.               MONO_STAGE_X, MONO_STAGE_Y,
  104.               tlx + MONO_STAGE_X, MONO_STAGE_Y,
  105.               tlx, this_height ) ;
  106.         tlx *= 2 ;
  107.     }
  108.     tmp = ( x - xSrc ) % tlx ;
  109.     if ( tmp < 0  )
  110.         tmp += tlx ;
  111.     savehtarget = htarget = x - tmp ;
  112.  
  113.     tmp = ( y - ySrc ) % tly ;
  114.     if ( tmp < 0  )
  115.         tmp += tly ;
  116.     vtarget = y - tmp + yoffset ;
  117.  
  118.     /*tiles to fill horiz */
  119.     savehcount = hcount = ( ( x + w - htarget ) + tlx - 1 ) / tlx ;
  120.  
  121.     /* tiles it will take to fill vert */
  122.     vcount = ( ( y + h - vtarget ) + tly - 1 ) / tly ;
  123.  
  124.     ibm8514ClearQueue( 4 ) ;
  125.     SETXMAX( x + w - 1 ) ;
  126.     SETYMAX( y + h - 1 ) ;
  127.     SETXMIN( x ) ;
  128.     SETYMIN( y ) ;
  129.  
  130.     while ( vcount-- )
  131.     {
  132.         while ( hcount-- )
  133.         {
  134.         ibm8514BlitFGBG( MONO_STAGE_RPLANE, planes,
  135.                 fg, bg, merge,
  136.                 MONO_STAGE_X, MONO_STAGE_Y,
  137.                 htarget, vtarget, tlx, this_height ) ;
  138.         htarget += tlx ;
  139.         }
  140.         vtarget += tly ;
  141.         htarget = savehtarget ;
  142.         hcount = savehcount ;
  143.     }
  144.     yoffset += this_height ;
  145.     heightleft -= this_height ;
  146.     data += this_height * pStipple->devKind ;
  147.  
  148.     ibm8514ClearQueue( 4 ) ;
  149.     SETXMAX( _8514_SCREENWIDTH - 1 ) ;
  150.     SETYMAX( 1023 ) ;
  151.     SETXMIN( 0 ) ;
  152.     SETYMIN( 0 ) ;
  153.     }
  154.     if ( !--ibm8514cursorSemaphore && CursorIsSaved  )
  155.     ibm8514ReplaceCursor() ;
  156.  
  157.     return ;
  158. }
  159.  
  160. void
  161. ibm8514UnnaturalStipple(pStipple, fg, merge, planes, x, y, w, h, xSrc, ySrc )
  162.      PixmapPtr pStipple ;
  163.      unsigned long int fg ;
  164.      int merge ;
  165.      unsigned long int planes ;
  166.      int x, y, w, h, xSrc, ySrc ;
  167. {
  168.     int hcount, vcount, vtarget, htarget, savehcount, savehtarget, tlx, tly ;
  169.     int maxwid, heightleft, tmp, CursorIsSaved, yoffset, this_height ;
  170.     unsigned char *data ;
  171.  
  172.     if ( x < 0 )
  173.     {
  174.     w += x ;
  175.     x = 0 ;
  176.     }
  177.     if ( y < 0 )
  178.     {
  179.     h += y ;
  180.     y = 0 ;
  181.     }
  182.     w = MIN( _8514_SCREENWIDTH - x, w ) ;
  183.     h = MIN( _8514_SCREENHEIGHT - y, h ) ;
  184.  
  185.     if ( w <= 0 || h <= 0 )
  186.     return ;
  187.  
  188.     tlx = pStipple->drawable.width ;
  189.     tly = pStipple->drawable.height ;
  190.  
  191.     CursorIsSaved = !ibm8514cursorSemaphore
  192.     && ibm8514CheckCursor( x, y, x + w, y + h ) ;
  193.     ibm8514cursorSemaphore++ ;
  194.  
  195.     heightleft = h ;
  196.     yoffset = 0 ;
  197.  
  198.     data = pStipple->devPrivate.ptr ;
  199.     while ( heightleft > 0 )
  200.     {
  201.     this_height = MIN( heightleft, MAXSTIPPLEHEIGHT ) ;
  202.  
  203.     ibm8514StageMono( tlx, this_height, data ) ;
  204.  
  205.     /*expand the tile to largest available size */
  206.     maxwid = MIN( MAXSTIPPLEWIDTH, w ) ;
  207.     while ( tlx*2 <= maxwid )
  208.     {
  209.         ibm8514Bitblt( GXcopy, MONO_STAGE_RPLANE, MONO_STAGE_WPLANE,
  210.               MONO_STAGE_X, MONO_STAGE_Y,
  211.               tlx + MONO_STAGE_X, MONO_STAGE_Y,
  212.               tlx, this_height ) ;
  213.         tlx *= 2 ;
  214.     }
  215.     tmp = ( x - xSrc ) % tlx ;
  216.     if ( tmp < 0  )
  217.         tmp += tlx ;
  218.     savehtarget = htarget = x - tmp ;
  219.  
  220.     tmp = ( y - ySrc ) % tly ;
  221.     if ( tmp < 0  )
  222.         tmp += tly ;
  223.     vtarget =  y - tmp + yoffset ;
  224.  
  225.     /* tiles to fill horiz */
  226.     savehcount = hcount = ( ( x + w - htarget ) + tlx - 1 ) / tlx ;
  227.  
  228.     /* tiles it will take to fill vert */
  229.     vcount = ( ( y + h - vtarget ) + tly - 1 ) / tly ;
  230.  
  231.     ibm8514ClearQueue( 4 ) ;
  232.     SETXMAX( x + w - 1 ) ;
  233.     SETYMAX( y + h - 1 ) ;
  234.     SETXMIN( x ) ;
  235.     SETYMIN( y ) ;
  236.  
  237.     while ( vcount-- )
  238.     {
  239.         while ( hcount-- )
  240.         {
  241.         ibm8514BlitFG( MONO_STAGE_RPLANE, planes, fg, merge,
  242.                   MONO_STAGE_X, MONO_STAGE_Y,
  243.                   htarget, vtarget, tlx, this_height ) ;
  244.         htarget += tlx ;
  245.         }
  246.         vtarget += tly ;
  247.         htarget = savehtarget ;
  248.         hcount = savehcount ;
  249.     }
  250.     yoffset += this_height ;
  251.     heightleft -= this_height ;
  252.     data += this_height * pStipple->devKind ;
  253.  
  254.     ibm8514ClearQueue( 4 ) ;
  255.     SETXMAX( _8514_SCREENWIDTH - 1 ) ;
  256.     SETYMAX( 1023 ) ;
  257.     SETXMIN( 0 ) ;
  258.     SETYMIN( 0 ) ;
  259.     }
  260.  
  261.     if ( !--ibm8514cursorSemaphore && CursorIsSaved  )
  262.     ibm8514ReplaceCursor() ;
  263.     return ;
  264. }
  265.  
  266. void
  267. ibm8514Stipple(pStipple, fg, merge, planes, x, y, w, h, xSrc, ySrc )
  268.      PixmapPtr pStipple ;
  269.      unsigned long int fg ;
  270.      int merge ;
  271.      unsigned long int planes ;
  272.      int x, y, w, h, xSrc, ySrc ;
  273. {
  274.     int hcount, vcount, vtarget, htarget, savehcount, savehtarget, tlx, tly ;
  275.     int maxhite, maxwid ;
  276.     int tmp, CursorIsSaved ;
  277.     int xrot, yshift ;
  278.  
  279.     TRACE(("ibm8514Stipple(pStipple = x%x, fg=%d, merge= x%x, planes=x%02x, x=%d, y=%d, w=%d, h=%d, xSrc=%d, ySrc=%d\n)",
  280.        pStipple, fg, merge, planes, x, y, w, h, xSrc, ySrc)) ;
  281.     tlx = pStipple->drawable.width ;
  282.     tly = pStipple->drawable.height ;
  283.  
  284.     if ((x%4 == 0) && (w<=tlx) && (h<=tly) )
  285.     {
  286.     PixmapPtr pTmpStipple ;
  287.     int destroy=FALSE ;
  288.  
  289.     if (xrot = ((x-xSrc)%tlx) )
  290.     {
  291.         if (!(pTmpStipple = mfbCopyPixmap(pStipple)) )
  292.         {
  293.         ErrorF("Fail mfbCopyPixmap \"pTmpStipple\" \n") ;
  294.         return ;
  295.         }
  296.         destroy = TRUE ;
  297.         ppcRotBitmapRight(pTmpStipple, tlx-xrot) ;
  298.     }
  299.     if ( ( ((w+BITMAP_SCANLINE_PAD-1) >> LOG2_BITMAP_PAD)
  300.           << LOG2_BYTES_PER_SCANLINE_PAD )
  301.         < pStipple->devKind )
  302.     {
  303.         PixmapPtr ppcClipBitmap() ;
  304.         if (!destroy )
  305.         {
  306.         if (!(pTmpStipple = ppcClipBitmap(pStipple, w, h)) )
  307.         {
  308.             ErrorF("Fail ppcClipBitxmap\n") ;
  309.             return ;
  310.         }
  311.         destroy = TRUE ;
  312.         }
  313.         else
  314.         {
  315.         PixmapPtr pNew ;
  316.         if (!(pNew = ppcClipBitmap(pTmpStipple, w, h)) )
  317.         {
  318.             ErrorF("Fail ppcClipBitxmap\n") ;
  319.             mfbDestroyPixmap(pTmpStipple) ;
  320.             return ;
  321.         }
  322.         mfbDestroyPixmap(pTmpStipple) ;
  323.         pTmpStipple = pNew ;
  324.         }
  325.     }
  326.     if (!destroy )
  327.         pTmpStipple = pStipple ;
  328.  
  329.     yshift = ((y-ySrc)%tly) ;
  330.  
  331.     if ( yshift > h )
  332.     {
  333.         ibm8514DrawMonoImage( pTmpStipple->devPrivate.ptr
  334.                  + (yshift*pTmpStipple->devKind),
  335.                  x, y, w, h, fg, merge, planes ) ;
  336.     }
  337.     else
  338.     {
  339.         ibm8514DrawMonoImage( pTmpStipple->devPrivate.ptr, x, y+yshift,
  340.                  w, h-yshift, fg, merge, planes) ;
  341.         ibm8514DrawMonoImage( pTmpStipple->devPrivate.ptr
  342.                  + (yshift*pTmpStipple->devKind),
  343.                  x, y, w, yshift, fg, merge, planes ) ;
  344.         /*
  345.           WHATS WRONG WITH ALIGNMONOIMAGE HERE????
  346.           ALIGNMONOIMAGE DOESN'T TAKE A FG COLOR
  347.           */
  348.     }
  349.     if (destroy )
  350.         mfbDestroyPixmap(pTmpStipple) ;
  351.  
  352.     return ;
  353.     }
  354.  
  355.     if ( ( tlx > MAXSTIPPLEWIDTH ) || ( tly > MAXSTIPPLEHEIGHT ) )
  356.     {
  357.     ibm8514UnnaturalStipple( pStipple, fg, merge, planes,
  358.                 x, y, w, h, xSrc, ySrc) ;
  359.     return ;
  360.     }
  361.  
  362.     if ( x < 0 )
  363.     {
  364.     w += x ;
  365.     x = 0 ;
  366.     }
  367.     if ( y < 0 )
  368.     {
  369.     h += y ;
  370.     y = 0 ;
  371.     }
  372.     w = MIN(_8514_SCREENWIDTH-x, w) ;
  373.     h = MIN(_8514_SCREENHEIGHT-y, h) ;
  374.  
  375.     if ( ( w <= 0) || (h <= 0)  )
  376.     return ;
  377.  
  378.     ibm8514StageMono(tlx, tly, pStipple->devPrivate.ptr) ;
  379.  
  380.     /*expand the tile to largest available size */
  381.     maxwid = MIN(MAXSTIPPLEWIDTH, w) ;
  382.     while ( tlx*2 <= maxwid )
  383.     {
  384.     ibm8514Bitblt( GXcopy, MONO_STAGE_RPLANE, MONO_STAGE_WPLANE,
  385.               MONO_STAGE_X, MONO_STAGE_Y,
  386.               tlx + MONO_STAGE_X, MONO_STAGE_Y,
  387.               tlx, tly ) ;
  388.     tlx *= 2 ;
  389.     }
  390.     maxhite = MIN(MAXSTIPPLEHEIGHT, h) ;
  391.     while ( tly*2 <= maxhite )
  392.     {
  393.     ibm8514Bitblt( GXcopy, MONO_STAGE_RPLANE, MONO_STAGE_WPLANE,
  394.               MONO_STAGE_X, MONO_STAGE_Y,
  395.               MONO_STAGE_X, tly+MONO_STAGE_Y,
  396.               tlx, tly) ;
  397.     tly *= 2 ;
  398.     }
  399.  
  400.     tmp = ( x - xSrc ) % tlx ;
  401.     if ( tmp < 0  )
  402.     tmp += tlx ;
  403.     savehtarget = htarget = x - tmp ;
  404.     tmp = ( y - ySrc ) % tly ;
  405.     if ( tmp < 0  )
  406.     tmp += tly ;
  407.     vtarget = y - tmp ;
  408.  
  409.     savehcount = hcount = ((x+w-htarget)+tlx-1)/tlx ; /*tiles to fill horiz */
  410.     vcount = ((y+h-vtarget)+tly-1)/tly ; /*tiles it will take to fill vert */
  411.  
  412.     CursorIsSaved = !ibm8514cursorSemaphore
  413.     && ibm8514CheckCursor(htarget, vtarget, hcount*tlx, vcount*tly) ;
  414.     ibm8514cursorSemaphore++ ;
  415.  
  416.     ibm8514ClearQueue(4) ;
  417.     SETXMAX(x+w-1) ;
  418.     SETYMAX(y+h-1) ;
  419.     SETXMIN(x) ;
  420.     SETYMIN(y) ;
  421.  
  422.     while ( vcount-- )
  423.     {
  424.     while ( hcount-- )
  425.     {
  426.         ibm8514BlitFG( MONO_STAGE_RPLANE, planes, fg, merge,
  427.               MONO_STAGE_X, MONO_STAGE_Y,
  428.               htarget, vtarget, tlx, tly) ;
  429.         htarget += tlx ;
  430.     }
  431.     vtarget += tly ;
  432.     htarget = savehtarget ;
  433.     hcount = savehcount ;
  434.     }
  435.  
  436.     ibm8514ClearQueue(4) ;
  437.     SETXMAX(_8514_SCREENWIDTH-1) ;
  438.     SETYMAX( 1023 ) ;
  439.     SETXMIN(0) ;
  440.     SETYMIN(0) ;
  441.     if ( !(--ibm8514cursorSemaphore) && CursorIsSaved  )
  442.     ibm8514ReplaceCursor() ;
  443.     return ;
  444. }
  445.  
  446. void
  447. ibm8514OpStipple(pStipple, fg, bg, merge, planes, x, y, w, h, xSrc, ySrc )
  448.      PixmapPtr pStipple ;
  449.      unsigned long int fg, bg ;
  450.      int merge ;
  451.      unsigned long int planes ;
  452.      int x, y, w, h, xSrc, ySrc ;
  453. {
  454.     int hcount, vcount, vtarget, htarget, savehcount, savehtarget, tlx, tly ;
  455.     int maxhite, maxwid ;
  456.     int tmp, CursorIsSaved ;
  457.  
  458.     TRACE(("ibm8514Stipple(pStipple = x%x, fg=%d, merge= x%x, planes=x%02x, x=%d, y=%d, w=%d, h=%d, xSrc=%d, ySrc=%d\n",
  459.        pStipple, fg, merge, planes, x, y, w, h, xSrc, ySrc)) ;
  460.  
  461.     tlx = pStipple->drawable.width ;
  462.     tly = pStipple->drawable.height ;
  463.  
  464.     if ( ( tlx > MAXSTIPPLEWIDTH ) || ( tly > MAXSTIPPLEHEIGHT ) )
  465.     {
  466.     ibm8514UnnaturalOpStipple( pStipple, fg, bg, merge, planes,
  467.                   x, y, w, h, xSrc, ySrc ) ;
  468.     return ;
  469.     }
  470.  
  471.     if ( x < 0 )
  472.     {
  473.     w += x ;
  474.     x = 0 ;
  475.     }
  476.     if ( y < 0 )
  477.     {
  478.     h += y ;
  479.     y = 0 ;
  480.     }
  481.     w = MIN(_8514_SCREENWIDTH-x, w) ;
  482.     h = MIN(_8514_SCREENHEIGHT-y, h) ;
  483.  
  484.     if ( (w <= 0) || (h <= 0 )  )
  485.     return ;
  486.  
  487.     ibm8514StageMono(tlx, tly, pStipple->devPrivate.ptr) ;
  488.  
  489.     /*expand the tile to largest available size */
  490.     maxwid = MIN(MAXSTIPPLEWIDTH, w) ;
  491.     while ( tlx*2 <= maxwid )
  492.     {
  493.     ibm8514Bitblt(GXcopy, MONO_STAGE_RPLANE, MONO_STAGE_WPLANE,
  494.               MONO_STAGE_X, MONO_STAGE_Y,
  495.               tlx+MONO_STAGE_X, MONO_STAGE_Y,
  496.               tlx, tly) ;
  497.     tlx *= 2 ;
  498.     }
  499.     maxhite = MIN(MAXSTIPPLEHEIGHT, h) ;
  500.     while ( tly*2 <= maxhite )
  501.     {
  502.     ibm8514Bitblt(GXcopy, MONO_STAGE_RPLANE, MONO_STAGE_WPLANE,
  503.               MONO_STAGE_X, MONO_STAGE_Y,
  504.               MONO_STAGE_X, tly+MONO_STAGE_Y,
  505.               tlx, tly) ;
  506.     tly *= 2 ;
  507.     }
  508.  
  509.     tmp = ( x - xSrc ) % tlx ;
  510.     if ( tmp < 0  )
  511.     tmp += tlx ;
  512.     savehtarget = htarget =  x - tmp ;
  513.     tmp = ((y-ySrc)%tly) ;
  514.     if ( tmp < 0  )
  515.     tmp += tly ;
  516.     vtarget =  y - tmp ;
  517.  
  518.     savehcount = hcount = ((x+w-htarget)+tlx-1)/tlx ; /*tiles to fill horiz */
  519.     vcount = ((y+h-vtarget)+tly-1)/tly ; /*tiles it will take to fill vert */
  520.  
  521.     CursorIsSaved = !ibm8514cursorSemaphore
  522.     && ibm8514CheckCursor(htarget, vtarget, hcount*tlx, vcount*tly) ;
  523.     ibm8514cursorSemaphore++ ;
  524.  
  525.     ibm8514ClearQueue(4) ;
  526.     SETXMAX(x+w-1) ;
  527.     SETYMAX(y+h-1) ;
  528.     SETXMIN(x) ;
  529.     SETYMIN(y) ;
  530.  
  531.     while ( vcount-- )
  532.     {
  533.     while ( hcount-- )
  534.     {
  535.         ibm8514BlitFGBG(MONO_STAGE_RPLANE, planes, fg, bg, merge,
  536.                 MONO_STAGE_X, MONO_STAGE_Y,
  537.                 htarget, vtarget, tlx, tly) ;
  538.         htarget += tlx ;
  539.     }
  540.     vtarget += tly ;
  541.     htarget = savehtarget ;
  542.     hcount = savehcount ;
  543.     }
  544.  
  545.     ibm8514ClearQueue(4) ;
  546.     SETXMAX(_8514_SCREENWIDTH-1) ;
  547.     SETYMAX( 1023 ) ;
  548.     SETXMIN(0) ;
  549.     SETYMIN(0) ;
  550.     if ( !(--ibm8514cursorSemaphore) && CursorIsSaved  )
  551.     ibm8514ReplaceCursor() ;
  552.     return ;
  553. }
  554.