Y_Less

Memset

Oct 6th, 2012
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.21 KB | None | 0 0
  1.  
  2. /*----------------------------------------------------------------------------*\
  3. Function:
  4.     memset
  5.     rawMemset
  6. Params:
  7.     arr[], iAddress - Array or address to set to a value.
  8.     iSize - Number of cells to fill.
  9.     iValue - What to set the cells to.
  10. Return:
  11.     -
  12. Notes:
  13.     Based on code by Slice:
  14.    
  15.     http://forum.sa-mp.com/showthread.php?p=1606781#post1606781
  16.    
  17.     Modified to use binary flags instead of a loop.
  18. \*----------------------------------------------------------------------------*/
  19.  
  20. stock memset(arr[], size = sizeof (arr), val = 0)
  21. {
  22.     new
  23.         addr;
  24.     #emit LOAD.S.pri arr
  25.     #emit STOR.S.pri addr
  26.     rawMemset(addr, size, val);
  27.     return 0;
  28. }
  29.  
  30. stock rawMemset(iAddress, iSize, iValue)
  31. {
  32.     // Convert the size from cells to bytes.
  33.     iSize *= 4;
  34.     // Loop until there are only little bits left to fill.
  35.     while (iSize >= 4096)
  36.     {
  37.         // I have to do this because the FILL instruction doesn't accept a
  38.         // dynamic number.
  39.         #emit LOAD.S.alt iAddress
  40.         #emit LOAD.S.pri iValue
  41.         #emit FILL 4096
  42.         iSize    -= 4096;
  43.         iAddress += 4096;
  44.     }
  45.     if (iSize & 2048)
  46.     {
  47.         #emit LOAD.S.alt iAddress
  48.         #emit LOAD.S.pri iValue
  49.         #emit FILL 2048
  50.         iAddress += 2048;
  51.     }
  52.     if (iSize & 1024)
  53.     {
  54.         #emit LOAD.S.alt iAddress
  55.         #emit LOAD.S.pri iValue
  56.         #emit FILL 1024
  57.         iAddress += 1024;
  58.     }
  59.     if (iSize & 512)
  60.     {
  61.         #emit LOAD.S.alt iAddress
  62.         #emit LOAD.S.pri iValue
  63.         #emit FILL 512
  64.         iAddress += 512;
  65.     }
  66.     if (iSize & 256)
  67.     {
  68.         #emit LOAD.S.alt iAddress
  69.         #emit LOAD.S.pri iValue
  70.         #emit FILL 256
  71.         iAddress += 256;
  72.     }
  73.     if (iSize & 128)
  74.     {
  75.         #emit LOAD.S.alt iAddress
  76.         #emit LOAD.S.pri iValue
  77.         #emit FILL 128
  78.         iAddress += 128;
  79.     }
  80.     if (iSize & 64)
  81.     {
  82.         #emit LOAD.S.alt iAddress
  83.         #emit LOAD.S.pri iValue
  84.         #emit FILL 64
  85.         iAddress += 64;
  86.     }
  87.     if (iSize & 32)
  88.     {
  89.         #emit LOAD.S.alt iAddress
  90.         #emit LOAD.S.pri iValue
  91.         #emit FILL 32
  92.         iAddress += 32;
  93.     }
  94.     if (iSize & 16)
  95.     {
  96.         #emit LOAD.S.alt iAddress
  97.         #emit LOAD.S.pri iValue
  98.         #emit FILL 16
  99.         iAddress += 16;
  100.     }
  101.     if (iSize & 8)
  102.     {
  103.         #emit LOAD.S.alt iAddress
  104.         #emit LOAD.S.pri iValue
  105.         #emit FILL 8
  106.         iAddress += 8;
  107.     }
  108.     if (iSize & 4)
  109.     {
  110.         #emit LOAD.S.alt iAddress
  111.         #emit LOAD.S.pri iValue
  112.         #emit FILL 4
  113.         iAddress += 4;
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment