📄 hwstate.h
字号:
PARAMETERS : psFlags - The flag array we want to set the flag in
dwFlagNum - The flag-bit we want to set (0 based)
RETURNS : void
*****************************************************************************/
__inline void FlagArraySetFlag(PFLAGARRAY psFlags, DWORD dwFlagNum)
{
DWORD i;
/*
Get the index of the word in which we will set the flag
*/
i = dwFlagNum >> 5;
/*
Set the flag
*/
psFlags->pdwFlags[i] |= 0x1UL << (dwFlagNum & 31UL);
/*
Update the words used (i.e. contain at-least one set flag)
*/
psFlags->dwUsed |= 1UL << i;
}
/*****************************************************************************
FUNCTION : FlagArrayClearFlag
PURPOSE : Clear/reset a single flag in a flag-word array
PARAMETERS : psFlags - The flag array we want to clear the flag in
dwFlagNum - The flag-bit we want to clear (0 based)
RETURNS : void
*****************************************************************************/
__inline DWORD FlagArrayClearFlag(PFLAGARRAY psFlags, DWORD dwFlagNum)
{
DWORD i;
/*
Get the index of the word in-which we will clear the flag
*/
i = dwFlagNum >> 5;
/*
Clear the flag-bit
*/
psFlags->pdwFlags[i] &= ~(0x1UL << (dwFlagNum & 31UL));
/*
Update the words used (i.e. contain at-least one set flag)
*/
if (!psFlags->pdwFlags[i])
{
psFlags->dwUsed &= ~(1UL << i);
}
}
#endif
/*****************************************************************************
FUNCTION : FlagArraySetFlagRange
PURPOSE : Set a contiguous range of flags in a flag-word array
PARAMETERS : psFlags - The flag array we want to set the flags in
dwFirst - The first flag we want to set (0 based)
dwLast - The last flag we want to set
RETURNS : void
*****************************************************************************/
__inline void FlagArraySetFlagRange(PFLAGARRAY psFlags,
DWORD dwFirst,
DWORD dwLast)
{
DWORD dwLastMask;
DWORD dwFirstMask;
DWORD i;
/*
Get the index of the first flags-word we are going to modify
*/
i = dwFirst >> 5;
/*
Update the words-used to include all the flags we are about to set
*/
psFlags->dwUsed |= (2UL << (dwLast>>5)) - (1UL << i);
/*
Adjust 'last' to be the bit after the last flag we want to set
(this avoids having to shift by dwLast+1 wverywhere)
*/
dwLast++;
/*
Adjust range of flags so that it is relative to the first flag in
the first flags-word we are dealing with
*/
dwLast -= i << 5;
dwFirst -= i << 5;
/*
Set required flags in the first word
*/
if (dwLast > 31)
{
dwLastMask = 0UL;
}
else
{
dwLastMask = 1UL << dwLast;
}
if (dwFirst > 31)
{
dwFirstMask = 0UL;
}
else
{
dwFirstMask = 1UL << dwFirst;
}
psFlags->pdwFlags[i] |= dwLastMask - dwFirstMask;
/*
Set required flags in subsequent words
*/
while (dwLast > 32)
{
/*
Update for next flag-word
*/
dwLast -= 32;
i++;
/*
Set the requested flags in this flag-word
*/
if (dwLast > 31)
{
dwLastMask = 0UL;
}
else
{
dwLastMask = (0xFFFFFFFFUL << dwLast);
}
psFlags->pdwFlags[i] |= ~dwLastMask;
}
}
/*****************************************************************************
FUNCTION : FlagArrayClearFlagRange
PURPOSE : Clear/reset a contiguous range of flags in a flag-word array
PARAMETERS : psFlags - The flag array we want to clear the flags in
dwFirst - The first flag we want to clear (0 based)
dwLast - The last flag we want to clear
RETURNS : void
*****************************************************************************/
__inline void FlagArrayClearFlagRange(PFLAGARRAY psFlags,
DWORD dwFirst,
DWORD dwLast)
{
DWORD dwCleared;
DWORD dwLastMask;
DWORD dwFirstMask;
DWORD i;
/*
Get the index of the first word we are going to change
*/
i = dwFirst >> 5;
/*
Adjust last to be the bit after the last flag we want to set
(this avoids having to shift by dwLast+1 wverywhere)
*/
dwLast++;
/*
Initialise the group-flags word. This gets bits set corresponding
to the flags-words that no longer have any flags set as a result of
the bits we have cleared.
*/
dwCleared = 0;
/*
Adjust range of flags so that it is relative to the first flag in
the first flags-word we are dealing with
*/
dwLast -= (i << 5);
dwFirst -= (i << 5);
/*
Clear required flags in the first word
*/
if (dwLast > 31)
{
dwLastMask = 0UL;
}
else
{
dwLastMask = 1UL << dwLast;
}
if (dwFirst > 31)
{
dwFirstMask = 0UL;
}
else
{
dwFirstMask = 1UL << dwFirst;
}
psFlags->pdwFlags[i] &= ~(dwLastMask - dwFirstMask);
if (!psFlags->pdwFlags[i])
{
dwCleared |= 1 << i;
}
/*
Clear required flags in subsequent words
*/
while (dwLast > 32)
{
/*
Update for next flag-word
*/
dwLast -= 32;
i++;
/*
Clear the requested flags in this word and check if none are set now
*/
if (dwLast > 31)
{
dwLastMask = 0UL;
}
else
{
dwLastMask = 0xFFFFFFFFUL << dwLast;
}
psFlags->pdwFlags[i] &= dwLastMask;
if (!psFlags->pdwFlags[i])
{
dwCleared |= 1 << i;
}
}
/*
Update the used words (resetting the flags for all those words we
have just cleared completely)
*/
psFlags->dwUsed &= ~dwCleared;
}
/*****************************************************************************
FUNCTION : FlagArraySetFlags
PURPOSE : Set arbitrary flags in a flag-word array
PARAMETERS : psFlags - The flag array we want to set the flags in
psFlagsToSet - The flags we want to set
RETURNS : void
*****************************************************************************/
__inline void FlagArraySetFlags(PFLAGARRAY psFlags, PFLAGARRAY psFlagsToSet)
{
DWORD i;
/*
Update the flags words
*/
for (i = 0; i < (psFlags->dwSize>>5); i++)
{
psFlags->pdwFlags[i] |= psFlagsToSet->pdwFlags[i];
}
/*
Update the used words (any words in psFlagsToSet will now
be used in the psFlags)
*/
psFlags->dwUsed |= psFlagsToSet->dwUsed;
}
/*****************************************************************************
FUNCTION : FlagArrayClearFlags
PURPOSE : Clear/reset arbitrary flags in a flag-word array
PARAMETERS : psFlags - The flag array we want to clear the flags in
psFlagsToClear - The flags we want to clear
RETURNS : void
*****************************************************************************/
__inline void FlagArrayClearFlags(PFLAGARRAY psFlags,
PFLAGARRAY psFlagsToClear)
{
DWORD i;
/*
Update the flags words (clearing the corresponding bit in the 'used'
word for any words we clear completely).
*/
for (i = 0; i < (psFlags->dwSize>>5); i++)
{
psFlags->pdwFlags[i] &= ~psFlagsToClear->pdwFlags[i];
if (!psFlags->pdwFlags[i])
{
psFlags->dwUsed &= ~(1 << i);
}
}
}
/*****************************************************************************
FUNCTION : FlagArrayUpdate
PURPOSE : Updates the used/unused flags for a flags-word array
PARAMETERS : psFlags - The flag array to update
RETURNS : void
*****************************************************************************/
__inline void FlagArrayUpdate(PFLAGARRAY psFlags)
{
DWORD i;
/*
Check for any zero flag-words=
*/
psFlags->dwUsed = 0;
for (i = 0; i < (psFlags->dwSize>>5); i++)
{
if (psFlags->pdwFlags[i])
{
psFlags->dwUsed |= 1 << i;
}
}
}
#endif /* #if !defined(_HWSTATE_H_) */
/*****************************************************************************
End of file (HWState.h)
*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -