Improve SPU code and support state of voice
This commit is contained in:
@@ -65,15 +65,6 @@ namespace JabyEngine {
|
||||
};
|
||||
}
|
||||
|
||||
struct ubus32_t {
|
||||
uint16_t low;
|
||||
uint16_t high;
|
||||
|
||||
static constexpr ubus32_t from(uint32_t value) {
|
||||
return {.low = static_cast<uint16_t>(value & 0xFFFF), .high = static_cast<uint16_t>(value >> 16)};
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct IOPort {
|
||||
using Value = T;
|
||||
@@ -89,25 +80,34 @@ namespace JabyEngine {
|
||||
};
|
||||
|
||||
template<>
|
||||
struct IOPort<ubus32_t> {
|
||||
using Value = ubus32_t;
|
||||
ubus32_t value;
|
||||
struct IOPort<uint32_t>;
|
||||
|
||||
ubus32_t read() const {
|
||||
auto*const cv_this = const_cast<const volatile IOPort<ubus32_t>*>(this);
|
||||
|
||||
return {.low = cv_this->value.low, .high = cv_this->value.high};
|
||||
template<typename T>
|
||||
struct IOPort32 {
|
||||
union ValueHelper {
|
||||
struct {
|
||||
uint16_t low;
|
||||
uint16_t high;
|
||||
};
|
||||
T value;
|
||||
};
|
||||
using Value = T;
|
||||
T value;
|
||||
|
||||
T read() const {
|
||||
const auto* cast_this = reinterpret_cast<const IOPort32<ValueHelper>*>(this);
|
||||
const volatile auto* cv_this = const_cast<volatile decltype(cast_this)>(cast_this);
|
||||
|
||||
return ValueHelper{.low = cv_this->value.low, .high = cv_this->value.high}.value;
|
||||
}
|
||||
|
||||
void write(ubus32_t value) {
|
||||
auto*const cv_this = const_cast<volatile IOPort<ubus32_t>*>(this);
|
||||
void write(T value) {
|
||||
const auto new_value = ValueHelper{.value = value};
|
||||
auto* cast_this = reinterpret_cast<IOPort32<ValueHelper>*>(this);
|
||||
volatile auto* v_this = const_cast<volatile decltype(cast_this)>(cast_this);
|
||||
|
||||
cv_this->value.low = value.low;
|
||||
cv_this->value.high = value.high;
|
||||
}
|
||||
|
||||
void write(uint32_t value) {
|
||||
IOPort<ubus32_t>::write(ubus32_t::from(value));
|
||||
v_this->value.low = new_value.low;
|
||||
v_this->value.high = new_value.high;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user