Advertisement
tehKaiN

ACE blitCopy

Jul 27th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.38 KB | None | 0 0
  1. /**
  2.  * Blit without mask - BltBitMap equivalent, but less safe
  3.  * Channels:
  4.  *  A: mask const, read disabled
  5.  *  B: src  read
  6.  *  C: dest read
  7.  *  D: dest write
  8.  * Descending mode is used under 2 cases:
  9.  *  - Blit needs shifting to left with previous data coming from right (ubSrcDelta > ubDstDelta)
  10.  *  - Ascending right mask shifted more than 16 bits
  11.  * Source and destination regions should not overlap.
  12.  * Function is slightly slower (~0.5 - 1.5ms) than bltBitMap:
  13.  *  - Pre-loop calculations take ~50us on ASC mode, ~80us on DESC mode
  14.  *  - Rewriting to assembly could speed things up a bit
  15.  */
  16. BYTE _blitCopy(
  17.     tBitMap *pSrc, WORD wSrcX, WORD wSrcY,
  18.     tBitMap *pDst, WORD wDstX, WORD wDstY, WORD wWidth, WORD wHeight,
  19.     UBYTE ubMinterm, UBYTE ubMask, UWORD uwLine, char *szFile
  20. ) {
  21.     if(!blitCheck(pSrc, wSrcX, wSrcY, pDst, wDstX, wDstY, wWidth, wHeight, uwLine, szFile))
  22.         return 0;
  23.     // Helper vars
  24.     UWORD uwBlitWords, uwBlitWidth, uwSrcOffs, uwDstOffs;
  25.     UBYTE ubShift, ubSrcDelta, ubDstDelta, ubWidthDelta, ubMaskFShift, ubMaskLShift, ubPlane;
  26.     // Blitter register values
  27.     UWORD uwBltCon0, uwBltCon1, uwFirstMask, uwLastMask;
  28.     WORD wSrcModulo, wDstModulo;
  29.        
  30.     ubSrcDelta = wSrcX & 0xF;
  31.     ubDstDelta = wDstX & 0xF;
  32.     ubWidthDelta = (ubSrcDelta + wWidth) & 0xF;
  33.  
  34.     if(ubSrcDelta > ubDstDelta || ((wWidth+ubDstDelta+15) & 0xFFF0)-(wWidth+ubSrcDelta) > 16) {
  35.         uwBlitWidth = (wWidth+(ubSrcDelta>ubDstDelta?ubSrcDelta:ubDstDelta)+15) & 0xFFF0;
  36.         uwBlitWords = uwBlitWidth >> 4;
  37.        
  38.         ubMaskFShift = ((ubWidthDelta+15)&0xF0)-ubWidthDelta;
  39.         ubMaskLShift = uwBlitWidth - (wWidth+ubMaskFShift);
  40.         uwFirstMask = 0xFFFF << ubMaskFShift;
  41.         uwLastMask = 0xFFFF >> ubMaskLShift;
  42.         if(ubMaskLShift > 16) // Fix for 2-word blits
  43.             uwFirstMask &= 0xFFFF >> (ubMaskLShift-16);
  44.        
  45.         ubShift = uwBlitWidth - (ubDstDelta+wWidth+ubMaskFShift);
  46.         uwBltCon1 = ubShift << BSHIFTSHIFT | BLITREVERSE;
  47.        
  48.         uwSrcOffs = pSrc->BytesPerRow * (wSrcY+wHeight-1) + ((wSrcX+wWidth+ubMaskFShift-1)>>3);
  49.         uwDstOffs = pDst->BytesPerRow * (wDstY+wHeight-1) + ((wDstX+wWidth+ubMaskFShift-1) >> 3);
  50.     }
  51.     else {
  52.         uwBlitWidth = (wWidth+ubDstDelta+15) & 0xFFF0;
  53.         uwBlitWords = uwBlitWidth >> 4;
  54.  
  55.         ubMaskFShift = ubSrcDelta;
  56.         ubMaskLShift = uwBlitWidth-(wWidth+ubSrcDelta);
  57.        
  58.         uwFirstMask = 0xFFFF >> ubMaskFShift;
  59.         uwLastMask = 0xFFFF << ubMaskLShift;
  60.  
  61.         ubShift = ubDstDelta-ubSrcDelta;
  62.         uwBltCon1 = ubShift << BSHIFTSHIFT;
  63.  
  64.         uwSrcOffs = pSrc->BytesPerRow * wSrcY + (wSrcX>>3);
  65.         uwDstOffs = pDst->BytesPerRow * wDstY + (wDstX>>3);
  66.     }
  67.    
  68.     uwBltCon0 = (ubShift << ASHIFTSHIFT) | USEB|USEC|USED | ubMinterm;
  69.     wSrcModulo = pSrc->BytesPerRow - (uwBlitWords<<1);
  70.     wDstModulo = pDst->BytesPerRow - (uwBlitWords<<1);
  71.    
  72.     ubMask &= 0xFF >> (8- (pSrc->Depth < pDst->Depth? pSrc->Depth: pDst->Depth));
  73.     ubPlane = 0;
  74.     while(ubMask) {
  75.         if(ubMask & 1)
  76.             g_sBlitManager.pBlitterSetFn(
  77.                 uwBltCon0, uwBltCon1,                  // bltconX
  78.                 uwFirstMask, uwLastMask,               // bltaXwm
  79.                 0, wSrcModulo, wDstModulo, wDstModulo, // bltXmod
  80.                 0,                                     // bltapt
  81.                 pSrc->Planes[ubPlane] + uwSrcOffs,     // bltbpt
  82.                 pDst->Planes[ubPlane] + uwDstOffs,     // bltcpt
  83.                 pDst->Planes[ubPlane] + uwDstOffs,     // bltdpt
  84.                 0xFFFF, 0, 0,                          // bltXdat
  85.                 (wHeight << 6) | uwBlitWords           // bltsize
  86.             );
  87.         ubMask >>= 1;
  88.         ++ubPlane;
  89.     }
  90.     return 1;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement