home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / src / scanline.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-15  |  5.5 KB  |  231 lines

  1. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
  2. // Copyright (C) 1999-2003 Forgotten
  3. // Copyright (C) 2004 Forgotten and the VBA development team
  4.  
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2, or(at your option)
  8. // any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software Foundation,
  17. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18.  
  19. #include "System.h"
  20.  
  21. extern int RGB_LOW_BITS_MASK;
  22.  
  23. void Scanlines (u8 *srcPtr, u32 srcPitch, u8 *,
  24.                 u8 *dstPtr, u32 dstPitch, int width, int height)
  25. {
  26.   u8 *nextLine, *finish;
  27.   
  28.   nextLine = dstPtr + dstPitch;
  29.   
  30.   do {
  31.     u32 *bP = (u32 *) srcPtr;
  32.     u32 *dP = (u32 *) dstPtr;
  33.     u32 *nL = (u32 *) nextLine;
  34.     u32 currentPixel;
  35.     u32 nextPixel;
  36.     
  37.     finish = (u8 *) bP + ((width+2) << 1);
  38.     nextPixel = *bP++;
  39.     
  40.     do {
  41.       currentPixel = nextPixel;
  42.       nextPixel = *bP++;
  43.       u32 colorA, colorB;
  44.       
  45. #ifdef WORDS_BIGENDIAN
  46.       colorA = currentPixel >> 16;
  47.       colorB = currentPixel & 0xffff;
  48. #else
  49.       colorA = currentPixel & 0xffff;
  50.       colorB = currentPixel >> 16;
  51. #endif
  52.  
  53.       *(dP) = colorA | colorA<<16;
  54.       *(nL) = 0;
  55.  
  56. #ifdef WORDS_BIGENDIAN
  57.       colorA = nextPixel >> 16;
  58. #else
  59.       colorA = nextPixel & 0xffff;
  60. #endif
  61.  
  62.       *(dP + 1) = colorB | (colorB << 16);
  63.       *(nL + 1) = 0;
  64.       
  65.       dP += 2;
  66.       nL += 2;
  67.     } while ((u8 *) bP < finish);
  68.     
  69.     srcPtr += srcPitch;
  70.     dstPtr += dstPitch << 1;
  71.     nextLine += dstPitch << 1;
  72.   }
  73.   while (--height);
  74. }
  75.  
  76. void Scanlines32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
  77.                  u8 *dstPtr, u32 dstPitch, int width, int height)
  78. {
  79.   u8 *nextLine, *finish;
  80.   
  81.   nextLine = dstPtr + dstPitch;
  82.   
  83.   do {
  84.     u32 *bP = (u32 *) srcPtr;
  85.     u32 *dP = (u32 *) dstPtr;
  86.     u32 *nL = (u32 *) nextLine;
  87.     u32 currentPixel;
  88.     u32 nextPixel;
  89.     
  90.     finish = (u8 *) bP + ((width+1) << 2);
  91.     nextPixel = *bP++;
  92.     
  93.     do {
  94.       currentPixel = nextPixel;
  95.       nextPixel = *bP++;
  96.       
  97.       u32 colorA, colorB;
  98.         
  99.       colorA = currentPixel;
  100.       colorB = nextPixel;
  101.  
  102.       *(dP) = colorA;
  103.       *(dP+1) = colorA;
  104.       *(nL) = 0;
  105.       *(nL+1) = 0;
  106.  
  107.       *(dP + 2) = colorB;
  108.       *(dP + 3) = colorB;
  109.       *(nL+2) = 0;      
  110.       *(nL+3) = 0;
  111.       
  112.       nextPixel = *bP++;
  113.  
  114.       dP += 4;
  115.       nL += 4;
  116.     } while ((u8 *) bP < finish);
  117.     
  118.     srcPtr += srcPitch;
  119.     dstPtr += dstPitch << 1;
  120.     nextLine += dstPitch << 1;
  121.   }
  122.   while (--height);
  123. }
  124.  
  125. void ScanlinesTV(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
  126.                  u8 *dstPtr, u32 dstPitch, int width, int height)
  127. {
  128.   u8 *nextLine, *finish;
  129.   u32 colorMask = ~(RGB_LOW_BITS_MASK | (RGB_LOW_BITS_MASK << 16));
  130.   
  131.   nextLine = dstPtr + dstPitch;
  132.   
  133.   do {
  134.     u32 *bP = (u32 *) srcPtr;
  135.     u32 *dP = (u32 *) dstPtr;
  136.     u32 *nL = (u32 *) nextLine;
  137.     u32 currentPixel;
  138.     u32 nextPixel;
  139.     
  140.     finish = (u8 *) bP + ((width+2) << 1);
  141.     nextPixel = *bP++;
  142.     
  143.     do {
  144.       currentPixel = nextPixel;
  145.       nextPixel = *bP++;
  146.       
  147.       u32 colorA, colorB;
  148.  
  149. #ifdef WORDS_BIGENDIAN
  150.       colorA = currentPixel >> 16;
  151.       colorB = currentPixel & 0xFFFF;
  152. #else
  153.       colorA = currentPixel & 0xFFFF;
  154.       colorB = currentPixel >> 16;
  155. #endif
  156.       
  157.       *(dP) = colorA = colorA | ((((colorA & colorMask) >> 1) +
  158.                                   ((colorB & colorMask) >> 1))) << 16;
  159.       colorA = ((colorA & colorMask) >> 1);
  160.       colorA += ((colorA & colorMask) >> 1);
  161.       *(nL) = colorA;
  162.  
  163.       colorA = nextPixel & 0xFFFF;
  164.  
  165.       *(dP + 1) = colorB = colorB | ((((colorA & colorMask) >> 1) +
  166.                                       ((colorB & colorMask) >> 1))) << 16;
  167.       colorB = ((colorB & colorMask) >> 1);
  168.       colorB += ((colorB & colorMask) >> 1);
  169.  
  170.       *(nL + 1) = colorB;      
  171.       
  172.       dP += 2;
  173.       nL += 2;
  174.     } while ((u8 *) bP < finish);
  175.     
  176.     srcPtr += srcPitch;
  177.     dstPtr += dstPitch << 1;
  178.     nextLine += dstPitch << 1;
  179.   }
  180.   while (--height);
  181. }
  182.  
  183. void ScanlinesTV32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
  184.                    u8 *dstPtr, u32 dstPitch, int width, int height)
  185. {
  186.   u8 *nextLine, *finish;
  187.   u32 colorMask = ~RGB_LOW_BITS_MASK;
  188.   
  189.   nextLine = dstPtr + dstPitch;
  190.   
  191.   do {
  192.     u32 *bP = (u32 *) srcPtr;
  193.     u32 *dP = (u32 *) dstPtr;
  194.     u32 *nL = (u32 *) nextLine;
  195.     u32 currentPixel;
  196.     u32 nextPixel;
  197.     
  198.     finish = (u8 *) bP + ((width+1) << 2);
  199.     nextPixel = *bP++;
  200.     
  201.     do {
  202.       currentPixel = nextPixel;
  203.       nextPixel = *bP++;
  204.       
  205.       u32 colorA, colorB, temp;
  206.  
  207.       colorA = currentPixel;
  208.       colorB = nextPixel;
  209.       
  210.       *(dP) = colorA;
  211.       *(dP+1) = temp = ((colorA & colorMask) >> 1) +
  212.         ((colorB & colorMask) >> 1);
  213.       temp = ((temp & colorMask) >> 1);
  214.       temp += ((temp & colorMask) >> 1);
  215.       colorA = ((colorA & colorMask) >> 1);
  216.       colorA += ((colorA & colorMask) >> 1);
  217.  
  218.       *(nL) = colorA;
  219.       *(nL+1) = temp;
  220.  
  221.       dP += 2;
  222.       nL += 2;
  223.     } while ((u8 *) bP < finish);
  224.     
  225.     srcPtr += srcPitch;
  226.     dstPtr += dstPitch << 1;
  227.     nextLine += dstPitch << 1;
  228.   }
  229.   while (--height);
  230. }
  231.