Prepare SPU and IO Ports related code
This commit is contained in:
55
include/PSX/Auxiliary/bits.hpp
Normal file
55
include/PSX/Auxiliary/bits.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef __JABYENGINE_BITS_HPP__
|
||||
#define __JABYENGINE_BITS_HPP__
|
||||
#include "../jabyengine_defines.h"
|
||||
|
||||
namespace bit {
|
||||
template<typename T>
|
||||
static constexpr T set(T raw_value, size_t bit) {
|
||||
return (raw_value | (1 << bit));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static constexpr T clear(T raw_value, size_t bit) {
|
||||
return (raw_value & ~(1 << bit));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static constexpr bool is_set(T raw_value, size_t bit) {
|
||||
return static_cast<bool>(raw_value & (1 << bit));
|
||||
}
|
||||
|
||||
namespace value {
|
||||
template<typename T>
|
||||
static constexpr T crop_value(T raw_value, size_t length) {
|
||||
return (raw_value & ((1 << length) - 1));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static constexpr T range_mask(size_t start_bit, size_t length) {
|
||||
return (((1 << length) - 1) << start_bit);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static constexpr T clear_normalized(T raw_value, size_t start_bit, size_t length) {
|
||||
return (raw_value & ~range_mask<T>(start_bit, length));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static constexpr T set_normalized(T raw_value, T value, size_t start_bit, size_t length) {
|
||||
return (clear_normalized(raw_value, start_bit, length) | (value << start_bit));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static constexpr T get_normalized(T raw_value, size_t start_bit, size_t length) {
|
||||
return (raw_value & range_mask<T>(start_bit, length)) >> start_bit;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
static constexpr S cast(T value) {
|
||||
return *reinterpret_cast<S*>(&value);
|
||||
}
|
||||
}
|
||||
|
||||
#define __start_end_bit2_start_length(start_bit, end_bit) start_bit, (end_bit - start_bit + 1)
|
||||
#endif //!__JABYENGINE_BITS_HPP__
|
Reference in New Issue
Block a user