home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / ppc / emulTile.c < prev    next >
C/C++ Source or Header  |  1989-11-14  |  11KB  |  440 lines

  1. /*
  2.  * Copyright IBM Corporation 1987,1988,1989
  3.  *
  4.  * All Rights Reserved
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted,
  8.  * provided that the above copyright notice appear in all copies and that 
  9.  * both that copyright notice and this permission notice appear in
  10.  * supporting documentation, and that the name of IBM not be
  11.  * used in advertising or publicity pertaining to distribution of the
  12.  * software without specific, written prior permission.
  13.  *
  14.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  15.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  16.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  17.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  18.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  19.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  20.  * SOFTWARE.
  21.  *
  22. */
  23.  
  24. /* $Header: /andrew/X11/r3src/release/server/ddx/ibm/ppc/RCS/emulTile.c,v 30.0 89/01/23 19:28:31 paul Exp $ */
  25. /* $Source: /andrew/X11/r3src/release/server/ddx/ibm/ppc/RCS/emulTile.c,v $ */
  26.  
  27. #ifndef lint
  28. static char *rcsid = "$Header: /andrew/X11/r3src/release/server/ddx/ibm/ppc/RCS/emulTile.c,v 30.0 89/01/23 19:28:31 paul Exp $" ;
  29. #endif
  30.  
  31. /* ppc Tile
  32.  * P. Shupak 11/87
  33.  * Modified From original ppc Tile
  34.  * T. Paquin 9/87
  35.  * Uses private imageFill a bunch of times
  36.  */
  37.  
  38. #include "X.h"
  39. #include "pixmapstr.h"
  40. #include "pixmap.h"
  41. #include "scrnintstr.h"
  42. #include "gcstruct.h"
  43. #include "gc.h"
  44.  
  45. #include "OScompiler.h"
  46.  
  47. #include "ppcGCstr.h"
  48. #include "ppcScrn.h"
  49.  
  50. #include "ibmTrace.h"
  51.  
  52. extern void ErrorF() ;
  53.  
  54. static void
  55. DrawFirstTile( pTile, x, y, fnp, w, h, alu, planes, xOffset, yOffset )
  56. register PixmapPtr pTile ;
  57. register int x ;
  58. register int y ;
  59. register void (* fnp)() ;
  60. int w ;
  61. int h ;
  62. int alu ;
  63. unsigned long int planes ;
  64. int xOffset ;
  65. int yOffset ;
  66. {
  67. register int htarget ;
  68. register int vtarget ;
  69.  
  70.     if ( xOffset ) { /* Not X-Aligned */
  71.         if ( yOffset ) { /* Nor Y-Aligned */
  72.             htarget = MIN( pTile->drawable.width - xOffset, w ),
  73.             vtarget = MIN( pTile->drawable.height - yOffset, h ),
  74.             yOffset *= pTile->devKind ;
  75.             (* fnp)( x, y,
  76.                  htarget,
  77.                  vtarget,
  78.                  pTile->devPrivate.ptr + yOffset + xOffset,
  79.                  pTile->devKind,
  80.                  alu, planes ) ;
  81.             if ( w > htarget ) {
  82.                 w = MIN( w, pTile->drawable.width ) ;
  83.                 if ( h > vtarget ) {
  84.                     h = MIN( h, pTile->drawable.height ) ;
  85.                     (* fnp)( x, y + vtarget,
  86.                          htarget,
  87.                          h - vtarget,
  88.                          pTile->devPrivate.ptr + xOffset,
  89.                          pTile->devKind,
  90.                          alu, planes ) ;
  91.                     (* fnp)( x + htarget, y,
  92.                          w - htarget,
  93.                          vtarget,
  94.                          pTile->devPrivate.ptr + yOffset,
  95.                          pTile->devKind,
  96.                          alu, planes ) ;
  97.                     (* fnp)( x + htarget,
  98.                          y + vtarget,
  99.                          w - htarget,
  100.                          h - vtarget,
  101.                          pTile->devPrivate.ptr,
  102.                          pTile->devKind,
  103.                          alu, planes ) ;
  104.                 }
  105.                 else { /* h <= vtarget */
  106.                     (* fnp)( x + htarget, y,
  107.                          w - htarget,
  108.                          vtarget,
  109.                          pTile->devPrivate.ptr + yOffset,
  110.                          pTile->devKind,
  111.                          alu, planes ) ;
  112.                 }
  113.             }
  114.             else if ( h > vtarget ) {
  115.                 (* fnp)( x, y + vtarget,
  116.                      htarget,
  117.                      MIN( h, pTile->drawable.height ) - vtarget,
  118.                      pTile->devPrivate.ptr + xOffset,
  119.                      pTile->devKind,
  120.                      alu, planes ) ;
  121.                 vtarget = pTile->drawable.height ;
  122.             }
  123.         }
  124.         else { /* No Y Offset */
  125.             (* fnp)( x, y,
  126.                  htarget = MIN( pTile->drawable.width - xOffset, w ),
  127.                  vtarget = MIN( pTile->drawable.height, h ),
  128.                  pTile->devPrivate.ptr + xOffset,
  129.                  pTile->devKind,
  130.                  alu, planes ) ;
  131.             if ( w > htarget ) {
  132.                 (* fnp)( x + htarget, y,
  133.                      MIN( pTile->drawable.width, w ) - htarget,
  134.                      vtarget,
  135.                      pTile->devPrivate.ptr,
  136.                      pTile->devKind,
  137.                      alu, planes ) ;
  138.             }
  139.         }
  140.     }
  141.     else if ( yOffset ) {
  142.         (* fnp)( x, y,
  143.              htarget = MIN( pTile->drawable.width, w ),
  144.              vtarget = MIN( pTile->drawable.height - yOffset, h ),
  145.              pTile->devPrivate.ptr + ( yOffset * pTile->devKind ),
  146.              pTile->devKind,
  147.              alu, planes ) ;
  148.         if ( h > vtarget ) {
  149.             (* fnp)( x, y + vtarget,
  150.                  htarget,
  151.                  MIN( pTile->drawable.height, h ) - vtarget,
  152.                  pTile->devPrivate.ptr,
  153.                  pTile->devKind,
  154.                  alu, planes ) ;
  155.         }
  156.     }
  157.     else { /* NO Offset */
  158.         (* fnp)( x, y,
  159.              htarget = MIN( pTile->drawable.width, w ),
  160.              vtarget = MIN( pTile->drawable.height, h ),
  161.              pTile->devPrivate.ptr,
  162.              pTile->devKind,
  163.              alu, planes ) ;
  164.     }
  165.  
  166.     return ;
  167. }
  168.  
  169. void
  170. ppcTileRect( pTile, alu, planes, x, y, w, h, xSrc, ySrc )
  171. register PixmapPtr pTile ;
  172. const int alu ;
  173. const unsigned long int planes ;
  174. register int x, y, w, h ;
  175. int xSrc ;
  176. int ySrc ;
  177. {
  178. register int htarget ;
  179. register int vtarget ;
  180. register void (*fnp)() ;
  181. ScreenPtr pScreen ;
  182. int xOffset ;
  183. int yOffset ;
  184.  
  185. TRACE( ( "ppcTileRect(pTile=x%x,alu=x%x,planes=x%02x,x=%d,y=%d,w=%d,h=%d,xSrc=%d,ySrc=%d\n",
  186.         pTile, alu, planes, x, y, w, h, xSrc, ySrc ) ) ;
  187.  
  188.      pScreen = pTile->drawable.pScreen ;
  189.      switch ( alu ) {
  190.     case GXclear:        /* 0x0 Zero 0 */
  191.     case GXinvert:        /* 0xa NOT dst */
  192.     case GXset:        /* 0xf 1 */
  193.         (* ( ( (ppcScrnPriv *) (pScreen->devPrivate) )->solidFill ) )
  194.             ( 0xFF, alu, planes, x, y, w, h ) ;
  195.     case GXnoop:        /* 0x5 dst */
  196.         return ;
  197.     default:
  198.         break ;
  199. }
  200.  
  201.     if ( ( xOffset = ( x - xSrc ) ) > 0 )
  202.     xOffset %= pTile->drawable.width ;
  203.     else
  204.     xOffset = pTile->drawable.width - (( - xOffset ) % pTile->drawable.width ) ;
  205.  
  206.     if ( ( yOffset = ( y - ySrc ) ) > 0 )
  207.     yOffset %= pTile->drawable.height ;
  208. else
  209.     yOffset = pTile->drawable.height - (( - yOffset ) % pTile->drawable.height ) ;
  210.  
  211.      fnp = ( (ppcScrnPriv *) (pScreen->devPrivate) )->imageFill ;
  212.  
  213.      switch ( alu ) {
  214.     case GXcopyInverted:    /* 0xc NOT src */
  215.     case GXcopy:        /* 0x3 src */
  216.         /* Special Case Code */
  217.         DrawFirstTile( pTile, x, y, fnp, w, h,
  218.                    alu, planes, xOffset, yOffset ) ;
  219.         /* Here We Double The Size Of The BLIT Each Iteration */
  220.         (* ( (ppcScrnPriv *) ( pScreen->devPrivate ) )->replicateArea)(
  221.                 x, y, planes, w, h,
  222.                 MIN( w, pTile->drawable.width ), MIN( h, pTile->drawable.height ), pScreen ) ;
  223.         break ;
  224.     case GXnor:        /* 0x8 NOT src AND NOT dst */
  225.     case GXandReverse:    /* 0x2 src AND NOT dst */
  226.     case GXorReverse:    /* 0xb src OR NOT dst */
  227.     case GXnand:        /* 0xe NOT src OR NOT dst */
  228.     case GXandInverted:    /* 0x4 NOT src AND dst */
  229.     case GXand:        /* 0x1 src AND dst */
  230.     case GXequiv:        /* 0x9 NOT src XOR dst */
  231.     case GXxor:        /* 0x6 src XOR dst */
  232.     case GXorInverted:    /* 0xd NOT src OR dst */
  233.     case GXor:        /* 0x7 src OR dst */
  234.     default:
  235.         {
  236.         register unsigned char *data ;
  237.         register int savex ;
  238.         register int savey ;
  239.         register int hcount, vcount ;
  240.         int tmp ;
  241.         int savehcount ;
  242.         int savevcount ;
  243.     
  244.         htarget = x ;
  245.         vtarget = y ;
  246.         savex = MIN( w, pTile->drawable.width - xOffset ) ;
  247.         savey = MIN( h, pTile->drawable.height - yOffset ) ;
  248.         data = ( (unsigned char *) pTile->devPrivate.ptr )
  249.              + ( yOffset *= pTile->devKind )
  250.              + xOffset ;
  251.         /* FIRST DO TOP EDGE PIECE */
  252.         if ( yOffset ) {
  253.             /* DO TOP LEFT CORNER PIECE */
  254.             (* fnp)( htarget, vtarget,
  255.                  savex,
  256.                  savey,
  257.                  data,
  258.                  pTile->devKind,
  259.                  alu, planes ) ;
  260.             savevcount = ( h - savey ) / pTile->drawable.height ;
  261.             if ( xOffset ) {
  262.                 /* DO REST OF LEFT EDGE */
  263.                 vtarget += savey ; /* Next Line */
  264.                 for ( vcount = savevcount ;
  265.                       vcount-- ;
  266.                       vtarget += pTile->drawable.height ) {
  267.                     (* fnp)( htarget, vtarget,
  268.                          savex,
  269.                          pTile->drawable.height,
  270.                          data - yOffset,
  271.                          pTile->devKind,
  272.                          alu, planes ) ;
  273.                 }
  274.                 if ( tmp = y + h - vtarget )
  275.                     (* fnp)( htarget, vtarget,
  276.                          savex,
  277.                          tmp,
  278.                          data - yOffset,
  279.                          pTile->devKind,
  280.                          alu, planes ) ;
  281.                 /* The ENTIRE left edge is done ! */
  282.                 x += savex ;
  283.                 w -= savex ;
  284.                 data -= xOffset ;
  285.                 htarget += savex ;
  286.             }
  287.  
  288.             vtarget = y ;
  289.             /* DO REST OF TOP EDGE */
  290.             savehcount = ( x + w - htarget ) / pTile->drawable.height ;
  291.             for ( hcount = savehcount ;
  292.                   hcount-- ;
  293.                   htarget += pTile->drawable.width ) {
  294.                 (* fnp)( htarget, vtarget,
  295.                      pTile->drawable.width,
  296.                      savey,
  297.                      data,
  298.                      pTile->devKind,
  299.                      alu, planes ) ;
  300.             }
  301.             /* DO TOP RIGHT CORNER PIECE */
  302.             if ( savex = x + w - htarget ) {
  303.                 (* fnp)( htarget, vtarget,
  304.                      savex,
  305.                      savey,
  306.                      data,
  307.                      pTile->devKind,
  308.                      alu, planes ) ;
  309.                 /* DO REST OF RIGHT EDGE */
  310.                 data -= yOffset ;
  311.                 vtarget += savey ;
  312.                 for ( vcount = savevcount ;
  313.                       vcount-- ;
  314.                       vtarget += pTile->drawable.height ) {
  315.                     (* fnp)( htarget, vtarget,
  316.                          savex,
  317.                          pTile->drawable.height,
  318.                          data,
  319.                          pTile->devKind,
  320.                          alu, planes ) ;
  321.                 }
  322.                 if ( tmp = y + h - vtarget )
  323.                     (* fnp)( htarget, vtarget,
  324.                          savex,
  325.                          tmp,
  326.                          data,
  327.                          pTile->devKind,
  328.                          alu, planes ) ;
  329.                 /* The ENTIRE right edge is done ! */
  330.                 w -= savex ;
  331.             }
  332.             else
  333.                 data -= yOffset ;
  334.             y += savey ;
  335.             h -= savey ;
  336.         }
  337.         else if ( xOffset ) {
  338.             /* DO TOP LEFT CORNER PIECE */
  339.             (* fnp)( htarget, vtarget,
  340.                  savex,
  341.                  pTile->drawable.height,
  342.                  data,
  343.                  pTile->devKind,
  344.                  alu, planes ) ;
  345.             /* DO REST OF LEFT EDGE */
  346.             vtarget += pTile->drawable.height ; /* Next Line */
  347.             savevcount = ( h - pTile->drawable.height ) / pTile->drawable.height ;
  348.             for ( vcount = savevcount ;
  349.                   vcount-- ;
  350.                   vtarget += pTile->drawable.height ) {
  351.                 (* fnp)( htarget, vtarget,
  352.                      savex,
  353.                      pTile->drawable.height,
  354.                      data,
  355.                      pTile->devKind,
  356.                      alu, planes ) ;
  357.             }
  358.             if ( tmp = y + h - vtarget )
  359.                 (* fnp)( htarget, vtarget,
  360.                      savex,
  361.                      tmp,
  362.                      data,
  363.                      pTile->devKind,
  364.                      alu, planes ) ;
  365.             x += savex ;
  366.             w -= savex ;
  367.             data -= xOffset ;
  368.  
  369.             /* DO TOP RIGHT CORNER PIECE */
  370.             if ( savex = w % pTile->drawable.width ) {
  371.                 (* fnp)( htarget = x + w - savex,
  372.                      vtarget = y,
  373.                      savex,
  374.                      pTile->drawable.height,
  375.                      data,
  376.                      pTile->devKind,
  377.                      alu, planes ) ;
  378.                 /* DO REST OF RIGHT EDGE */
  379.                 vtarget += pTile->drawable.height ;
  380.                 for ( vcount = savevcount ;
  381.                       vcount-- ;
  382.                       vtarget += pTile->drawable.height ) {
  383.                     (* fnp)( htarget, vtarget,
  384.                          savex,
  385.                          pTile->drawable.height,
  386.                          data,
  387.                          pTile->devKind,
  388.                          alu, planes ) ;
  389.                 }
  390.                 if ( tmp )
  391.                     (* fnp)( htarget, vtarget,
  392.                          savex,
  393.                          tmp,
  394.                          data,
  395.                          pTile->devKind,
  396.                          alu, planes ) ;
  397.                 /* The ENTIRE right edge is done ! */
  398.                 w -= savex ;
  399.             }
  400.             savehcount = w / pTile->drawable.height ;
  401.         }
  402.         else {
  403.             savevcount = h / pTile->drawable.height ;
  404.             savehcount = w / pTile->drawable.height ;
  405.         }
  406.  
  407.         /* Fill The Center */
  408.         for ( vtarget = y, vcount = savevcount ;
  409.               vcount-- ;
  410.               vtarget += pTile->drawable.height ) {
  411.             for ( hcount = savehcount, htarget = x ;
  412.                   hcount-- ;
  413.                   htarget += pTile->drawable.width ) {
  414.                 (* fnp)( htarget, vtarget,
  415.                      pTile->drawable.width,
  416.                      pTile->drawable.height,
  417.                      data,
  418.                      pTile->devKind,
  419.                      alu, planes ) ;
  420.             }
  421.         }
  422.         /* Finally Fill The Bottom Row Center */
  423.         if ( savey = y + h - vtarget  )
  424.             for ( hcount = savehcount, htarget = x ;
  425.                   hcount-- ;
  426.                   htarget += pTile->drawable.width ) {
  427.                 (* fnp)( htarget, vtarget,
  428.                      pTile->drawable.width,
  429.                      savey,
  430.                      data,
  431.                      pTile->devKind,
  432.                      alu, planes ) ;
  433.             }
  434.         }
  435.     }
  436.     
  437.  
  438. return ;
  439. }
  440.