| 147 | } |
| 148 | |
| 149 | void SetBits( |
| 150 | TBitArray * pArray, |
| 151 | unsigned int nBitPosition, |
| 152 | unsigned int nBitLength, |
| 153 | void * pvBuffer, |
| 154 | int nResultByteSize) |
| 155 | { |
| 156 | unsigned char * pbBuffer = (unsigned char *)pvBuffer; |
| 157 | unsigned int nBytePosition = (nBitPosition / 8); |
| 158 | unsigned int nBitOffset = (nBitPosition & 0x07); |
| 159 | unsigned short BitBuffer = 0; |
| 160 | unsigned short AndMask = 0; |
| 161 | unsigned short OneByte = 0; |
| 162 | |
| 163 | // Keep compiler happy for platforms where nResultByteSize is not used |
| 164 | nResultByteSize = nResultByteSize; |
| 165 | |
| 166 | #ifndef PLATFORM_LITTLE_ENDIAN |
| 167 | // Adjust the buffer pointer for big endian platforms |
| 168 | pbBuffer += (nResultByteSize - 1); |
| 169 | #endif |
| 170 | |
| 171 | // Copy whole bytes, if any |
| 172 | while(nBitLength > 8) |
| 173 | { |
| 174 | // Reload the bit buffer |
| 175 | #ifdef PLATFORM_LITTLE_ENDIAN |
| 176 | OneByte = *pbBuffer++; |
| 177 | #else |
| 178 | OneByte = *pbBuffer--; |
| 179 | #endif |
| 180 | // Update the BitBuffer and AndMask for the bit array |
| 181 | BitBuffer = (BitBuffer >> 0x08) | (OneByte << nBitOffset); |
| 182 | AndMask = (AndMask >> 0x08) | (0x00FF << nBitOffset); |
| 183 | |
| 184 | // Update the byte in the array |
| 185 | pArray->Elements[nBytePosition] = (BYTE)((pArray->Elements[nBytePosition] & ~AndMask) | BitBuffer); |
| 186 | |
| 187 | // Move byte positions and lengths |
| 188 | nBytePosition++; |
| 189 | nBitLength -= 0x08; |
| 190 | } |
| 191 | |
| 192 | if(nBitLength != 0) |
| 193 | { |
| 194 | // Reload the bit buffer |
| 195 | OneByte = *pbBuffer; |
| 196 | |
| 197 | // Update the AND mask for the last bit |
| 198 | BitBuffer = (BitBuffer >> 0x08) | (OneByte << nBitOffset); |
| 199 | AndMask = (AndMask >> 0x08) | (SetBitsMask[nBitLength] << nBitOffset); |
| 200 | |
| 201 | // Update the byte in the array |
| 202 | pArray->Elements[nBytePosition] = (BYTE)((pArray->Elements[nBytePosition] & ~AndMask) | BitBuffer); |
| 203 | |
| 204 | // Update the next byte, if needed |
| 205 | if(AndMask & 0xFF00) |
| 206 | { |
no outgoing calls
no test coverage detected