home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Games / Hexagonal CA / HexCA.c / GridCopy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-28  |  1.2 KB  |  47 lines  |  [TEXT/CWIE]

  1. /*
  2. "GridCopy.c"    by Alexander M Kasprzyk
  3.             ©1996
  4.  
  5. This file is part of my CA toolkit. The GridCopy function
  6. allows very rapid copying from one location in memory
  7. to another, and was designed for use in Cellular Automata
  8. programs.
  9.  
  10. Please feel free to contact me at:
  11. alex@kasprzyk.demon.co.uk
  12. */
  13.  
  14. #include "GridCopyPr.h"
  15.  
  16. // SetRBlockData -    call to set the RBlockData structure
  17. void SetRBlockData( register Size gridSize, register RBlockDataPtr gridMove )
  18. {
  19. #ifdef powerc
  20.     gridMove->ndouble = gridSize/8;
  21.     gridSize -= gridMove->ndouble * 8;
  22. #endif
  23.     gridMove->nlong = gridSize/4;
  24.     gridSize -= gridMove->nlong * 4;
  25.     gridMove->nshort = gridSize/2;
  26.     gridSize -= gridMove->nshort * 2;
  27.     gridMove->nchar = gridSize;
  28. }
  29.  
  30. // RBlockMove -    special block move call
  31. void RBlockMove( register Ptr srcPos, register Ptr dstPos, register RBlockDataPtr data )
  32. {
  33.     register long        count;
  34. #ifdef powerc
  35.     for( count = 0; count < data->ndouble; count++ )
  36.         *((double *)dstPos)++ = *((double *)srcPos)++;
  37.     if( data->nlong )
  38.         *((long *)dstPos)++ = *((long *)srcPos)++;
  39. #else
  40.     for( count = 0; count < data->nlong; count++ )
  41.         *((long *)dstPos)++ = *((long *)srcPos)++;
  42. #endif
  43.     if( data->nshort )
  44.         *((short *)dstPos)++ = *((short *)srcPos)++;
  45.     if( data->nchar )
  46.         *dstPos++ = *srcPos++;
  47. }