Advertisement
RyDeR_

rBits.inc

Aug 8th, 2011
4,898
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.12 KB | None | 0 0
  1. /*
  2.     SA-MP rBits Include
  3.     Copyright © 2011-2012 RyDeR`
  4. */
  5.  
  6. #if defined _Included_rBits
  7.     #endinput
  8. #else
  9.     #define _Included_rBits
  10. #endif
  11.  
  12. #define BIT_TAGS \
  13.     { Bit1, Bit2, Bit4, Bit8, Bit16 }
  14.        
  15. enum e_Bits {
  16.     Bit1,
  17.     Bit2,
  18.     Bit4,
  19.     Bit8,
  20.     Bit16,
  21.     Bit32
  22. };
  23.  
  24. #define Bit1:%0<%1> \
  25.     Bit1: %0[((%1) + 31) >>> _: Bit32]
  26.    
  27. #define Bit1_Set(%0,%1,%2) \
  28.     Bit_Set(%0, (%1), (%2), Bit1)
  29.    
  30. #define Bit1_Get(%0,%1) \
  31.     Bit_Get(%0, (%1), Bit1)
  32.  
  33. #define Bit2:%0<%1> \
  34.     Bit2: %0[((%1) + 15) >>> _: (Bit32 - Bit2)]
  35.    
  36. #define Bit2_Set(%0,%1,%2) \
  37.     Bit_Set(%0, (%1), (%2), Bit2)
  38.    
  39. #define Bit2_Get(%0,%1) \
  40.     Bit_Get(%0, (%1), Bit2)
  41.  
  42. #define Bit4:%0<%1> \
  43.     Bit4: %0[((%1) + 7) >>> _: (Bit32 - Bit4)]
  44.    
  45. #define Bit4_Set(%0,%1,%2) \
  46.     Bit_Set(%0, (%1), (%2), Bit4)
  47.    
  48. #define Bit4_Get(%0,%1) \
  49.     Bit_Get(%0, (%1), Bit4)
  50.  
  51. #define Bit8:%0<%1> \
  52.     Bit8: %0[(%1) char]
  53.    
  54. #define Bit8_Set(%0,%1,%2) \
  55.     (_: %0{(%1)} = (%2))
  56.    
  57. #define Bit8_Get(%0,%1) \
  58.     (_: %0{(%1)})
  59.    
  60. /*
  61. #define Bit8:%0<%1> \
  62.     Bit8: %0[((%1) + 3) >>> _: (Bit32 - Bit8)]
  63.    
  64. #define Bit8_Set(%0,%1,%2) \
  65.     Bit_Set(%0, (%1), (%2), Bit8)
  66.    
  67. #define Bit8_Get(%0,%1) \
  68.     Bit_Get(%0, (%1), Bit8)
  69. */
  70.  
  71. #define Bit16:%0<%1> \
  72.     Bit16: %0[((%1) + 1) >>> _: (Bit32 - Bit16)]
  73.    
  74. #define Bit16_Set(%0,%1,%2) \
  75.     Bit_Set(%0, (%1), (%2), Bit16)
  76.    
  77. #define Bit16_Get(%0,%1) \
  78.     Bit_Get(%0, (%1), Bit16)
  79.  
  80. stock Bit_Set(BIT_TAGS: abArray[], iIdx, const iValue, const e_Bits: iShift, const iSize = sizeof(abArray)) {
  81.     new
  82.         bVar = ((iIdx & ((1 << _: (Bit32 - iShift)) - 1)) << _: iShift),
  83.         bLim = ((1 << (1 << _: iShift)) - 1)
  84.     ;
  85.     iIdx = (iIdx >>> _: (Bit32 - iShift));
  86.    
  87.     if(!(-1 < iIdx < iSize)) {
  88.         return 0;
  89.     }
  90.     (_: abArray[iIdx] &= ~(bLim << bVar));
  91.     (_: abArray[iIdx] |= ((bLim & iValue) << bVar));
  92.    
  93.     return 1;
  94. }
  95.  
  96. stock Bit_Get(BIT_TAGS: abArray[], iIdx, const e_Bits: iShift, const iSize = sizeof(abArray)) {
  97.     new
  98.         bVar = ((iIdx & ((1 << _: (Bit32 - iShift)) - 1)) << _: iShift),
  99.         bLim = ((1 << (1 << _: iShift)) - 1)
  100.     ;
  101.     iIdx = (iIdx >>> _: (Bit32 - iShift));
  102.    
  103.     if(!(-1 < iIdx < iSize)) {
  104.         return 0;
  105.     }
  106.     return ((_: abArray[iIdx] >>> bVar) & bLim);
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement