Venrob

Bitwise functions

Dec 2nd, 2020
653
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Function to set Screen->D
  2. void setScreenD(int reg, bool state) //start
  3. {
  4.     #option BINARY_32BIT on
  5.    
  6.     int d = Div(reg, 32);
  7.     reg %= 32;
  8.    
  9.     if (state)
  10.         Screen->D[d] |= 1b<<reg;
  11.     else
  12.         Screen->D[d] ~= 1b<<reg;
  13.    
  14. }
  15. //end
  16.  
  17. // Function to get Screen->D
  18. bool getScreenD(int reg) //start
  19. {
  20.     #option BINARY_32BIT on
  21.    
  22.     int d = Div(reg, 32);
  23.     reg %= 32;
  24.    
  25.     return Screen->D[d] & (1b<<reg);
  26.    
  27. }
  28. //end
  29.  
  30. // Function to set Screen->D
  31. void setScreenD(int d, int bit, bool state) //start
  32. {
  33.     #option BINARY_32BIT on
  34.    
  35.     if (state)
  36.         Screen->D[d] |= bit;
  37.     else
  38.         Screen->D[d] ~= bit;
  39. }
  40. //end
  41.  
  42. // Function to get Screen->D
  43. int getScreenD(int d, int bit) //start
  44. {
  45.     #option BINARY_32BIT on
  46.    
  47.     return Screen->D[d] & bit;
  48. }
  49. //end
  50.  
  51. // Function to set an array bit
  52. void setBit(untyped arr, int reg, bool state) //start
  53. {
  54.     #option BINARY_32BIT on
  55.    
  56.     int d = Div(reg, 32);
  57.     reg %= 32;
  58.    
  59.     if (state)
  60.         arr[d] |= 1b<<reg;
  61.     else
  62.         arr[d] ~= 1b<<reg;
  63.    
  64. }
  65. //end
  66.  
  67. // Function to get an array bit
  68. bool getBit(untyped arr, int reg) //start
  69. {
  70.     #option BINARY_32BIT on
  71.    
  72.     int d = Div(reg, 32);
  73.     reg %= 32;
  74.    
  75.     return arr[d] & (1b<<reg);
  76.    
  77. }
  78. //end
  79.  
  80. // Function to set an array bit
  81. void setBit(untyped arr, int d, int bit, bool state) //start
  82. {
  83.     #option BINARY_32BIT on
  84.    
  85.     if (state)
  86.         arr[d] |= bit;
  87.     else
  88.         arr[d] ~= bit;
  89. }
  90. //end
  91.  
  92. // Function to get an array bit
  93. int getBit(untyped arr, int d, int bit) //start
  94. {
  95.     #option BINARY_32BIT on
  96.    
  97.     return arr[d] & bit;
  98. }
  99. //end
RAW Paste Data