Create new IO Port
This commit is contained in:
parent
0f2e4e25ed
commit
71103bb4ab
|
@ -0,0 +1,112 @@
|
||||||
|
#ifndef __JABYENGINE_IOPORT_HPP__
|
||||||
|
#define __JABYENGINE_IOPORT_HPP__
|
||||||
|
#include "../../Auxiliary/bits.hpp"
|
||||||
|
|
||||||
|
struct BitRange {
|
||||||
|
size_t begin;
|
||||||
|
size_t length;
|
||||||
|
|
||||||
|
static constexpr BitRange from_to(size_t start, size_t end) {
|
||||||
|
return {start, (end - start + 1)};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class __no_align IOPort {
|
||||||
|
private:
|
||||||
|
T value = 0;
|
||||||
|
|
||||||
|
public:
|
||||||
|
constexpr IOPort() = default;
|
||||||
|
constexpr IOPort(T value) : value(value) {
|
||||||
|
}
|
||||||
|
|
||||||
|
//Accesssing bits
|
||||||
|
template<typename S>
|
||||||
|
constexpr IOPort<T>& set_bit(S bit) {
|
||||||
|
this->value = bit::set(this->value, static_cast<size_t>(bit));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr volatile IOPort<T>& set_bit(S bit) volatile {
|
||||||
|
this->value = bit::set(this->value, static_cast<size_t>(bit));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr IOPort<T>& clear_bit(S bit) {
|
||||||
|
this->value = bit::set(this->value, static_cast<size_t>(bit));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr volatile IOPort<T>& clear_bit(S bit) volatile {
|
||||||
|
this->value = bit::set(this->value, static_cast<size_t>(bit));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr bool is_bit_set(S bit) {
|
||||||
|
return bit::is_set(this->value, static_cast<size_t>(bit));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr bool is_bit_set(S bit) volatile {
|
||||||
|
return bit::is_set(this->value, static_cast<size_t>(bit));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Accessing values
|
||||||
|
template<typename S>
|
||||||
|
constexpr IOPort<T>& set_value(S value, const BitRange& range) {
|
||||||
|
this->value = bit::value::set_normalized(this->value, static_cast<T>(value), range.begin, range.length);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr volatile IOPort<T>& set_value(S value, const BitRange& range) volatile {
|
||||||
|
this->value = bit::value::set_normalized(this->value, static_cast<T>(value), range.begin, range.length);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr IOPort<T>& clear_value(const BitRange& range) {
|
||||||
|
this->value = bit::value::clear_normalized(this->value, range.begin, range.length);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr volatile IOPort<T>& clear_value(const BitRange& range) volatile {
|
||||||
|
this->value = bit::value::clear_normalized(this->value, range.begin, range.length);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr S get_value(const BitRange& range) {
|
||||||
|
return static_cast<S>(bit::value::get_normalized(this->value, range.begin, range.length));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr S get_value(const BitRange& range) volatile {
|
||||||
|
return static_cast<S>(bit::value::get_normalized(this->value, range.begin, range.length));
|
||||||
|
}
|
||||||
|
|
||||||
|
//For raw access
|
||||||
|
constexpr operator T() const {
|
||||||
|
return this->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr operator T() const volatile {
|
||||||
|
return this->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr IOPort<T>& operator=(T value) {
|
||||||
|
this->value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr volatile IOPort<T>& operator=(T value) volatile {
|
||||||
|
this->value = value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //!__JABYENGINE_IOPORT_HPP__
|
|
@ -1,4 +1,5 @@
|
||||||
#include <PSX/System/IOPorts/SPU_IO.hpp>
|
#include <PSX/System/IOPorts/SPU_IO.hpp>
|
||||||
|
#include <PSX/System/IOPorts/IOPort.hpp>
|
||||||
|
|
||||||
namespace SPU {
|
namespace SPU {
|
||||||
static void clear_main_volume() {
|
static void clear_main_volume() {
|
||||||
|
@ -32,7 +33,15 @@ namespace SPU {
|
||||||
io_class__update_with(Control::Register, Control());
|
io_class__update_with(Control::Register, Control());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test() {
|
||||||
|
static __always_inline volatile auto& Dino = *reinterpret_cast<IOPort<uint16_t>*>(0x120);
|
||||||
|
|
||||||
|
while(Dino.is_bit_set(0));
|
||||||
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
test();
|
||||||
|
|
||||||
clear_main_volume();
|
clear_main_volume();
|
||||||
clear_keys();
|
clear_keys();
|
||||||
disable_control();
|
disable_control();
|
||||||
|
|
Loading…
Reference in New Issue