diff --git a/src/xenia/base/bit_field.h b/src/xenia/base/bit_field.h new file mode 100644 index 000000000..a089775c9 --- /dev/null +++ b/src/xenia/base/bit_field.h @@ -0,0 +1,42 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2017 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#ifndef XENIA_BASE_BIT_FIELD_H_ +#define XENIA_BASE_BIT_FIELD_H_ + +#include +#include +#include + +namespace xe { + +// Bitfield, where position starts at the LSB. +template +struct bf { + bf() = default; + inline operator T() const { return value(); } + + inline T value() const { + return static_cast((storage & mask()) >> position); + } + + // For enum values, we strip them down to an underlying type. + typedef + typename std::conditional::value, std::underlying_type, + std::identity>::type::type value_type; + inline value_type mask() const { + return (((value_type)~0) >> (8 * sizeof(value_type) - n_bits)) << position; + } + + value_type storage; +}; + +} // namespace xe + +#endif // XENIA_BASE_BIT_FIELD_H_ \ No newline at end of file diff --git a/src/xenia/base/debug_visualizers.natvis b/src/xenia/base/debug_visualizers.natvis index b5077dfc6..e0022ed70 100644 --- a/src/xenia/base/debug_visualizers.natvis +++ b/src/xenia/base/debug_visualizers.natvis @@ -67,5 +67,12 @@ {value} + + + + + {($T1)((storage & ((((value_type)~0) >> (8 * sizeof(value_type) - $T3)) << $T2)) >> $T2)} + +