MCPcopy Create free account
hub / github.com/diasurgical/devilution / GetBits

Function GetBits

3rdParty/StormLib/src/SBaseFileTable.cpp:83–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83void GetBits(
84 TBitArray * pArray,
85 unsigned int nBitPosition,
86 unsigned int nBitLength,
87 void * pvBuffer,
88 int nResultByteSize)
89{
90 unsigned char * pbBuffer = (unsigned char *)pvBuffer;
91 unsigned int nBytePosition0 = (nBitPosition / 8);
92 unsigned int nBytePosition1 = nBytePosition0 + 1;
93 unsigned int nByteLength = (nBitLength / 8);
94 unsigned int nBitOffset = (nBitPosition & 0x07);
95 unsigned char BitBuffer;
96
97 // Keep compiler happy for platforms where nResultByteSize is not used
98 nResultByteSize = nResultByteSize;
99
100#ifdef _DEBUG
101 // Check if the target is properly zeroed
102 for(int i = 0; i < nResultByteSize; i++)
103 assert(pbBuffer[i] == 0);
104#endif
105
106#ifndef PLATFORM_LITTLE_ENDIAN
107 // Adjust the buffer pointer for big endian platforms
108 pbBuffer += (nResultByteSize - 1);
109#endif
110
111 // Copy whole bytes, if any
112 while(nByteLength > 0)
113 {
114 // Is the current position in the Elements byte-aligned?
115 if(nBitOffset != 0)
116 {
117 BitBuffer = (unsigned char)((pArray->Elements[nBytePosition0] >> nBitOffset) | (pArray->Elements[nBytePosition1] << (0x08 - nBitOffset)));
118 }
119 else
120 {
121 BitBuffer = pArray->Elements[nBytePosition0];
122 }
123
124#ifdef PLATFORM_LITTLE_ENDIAN
125 *pbBuffer++ = BitBuffer;
126#else
127 *pbBuffer-- = BitBuffer;
128#endif
129
130 // Move byte positions and lengths
131 nBytePosition1++;
132 nBytePosition0++;
133 nByteLength--;
134 }
135
136 // Get the rest of the bits
137 nBitLength = (nBitLength & 0x07);
138 if(nBitLength != 0)
139 {
140 *pbBuffer = (unsigned char)(pArray->Elements[nBytePosition0] >> nBitOffset);

Callers 2

GetFileIndex_HetFunction · 0.85
BuildFileTable_HetBetFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected