From 71103bb4ab7d3e42d9175e2bcd5f28dc61da08f9 Mon Sep 17 00:00:00 2001 From: Jaby Date: Wed, 31 Aug 2022 22:51:13 +0200 Subject: [PATCH] Create new IO Port --- include/PSX/System/IOPorts/IOPort.hpp | 112 ++++++++++++++++++++++++ src/Library/src/BootLoader/boot_spu.cpp | 9 ++ 2 files changed, 121 insertions(+) create mode 100644 include/PSX/System/IOPorts/IOPort.hpp diff --git a/include/PSX/System/IOPorts/IOPort.hpp b/include/PSX/System/IOPorts/IOPort.hpp new file mode 100644 index 00000000..d44651c2 --- /dev/null +++ b/include/PSX/System/IOPorts/IOPort.hpp @@ -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 +class __no_align IOPort { +private: + T value = 0; + +public: + constexpr IOPort() = default; + constexpr IOPort(T value) : value(value) { + } + + //Accesssing bits + template + constexpr IOPort& set_bit(S bit) { + this->value = bit::set(this->value, static_cast(bit)); + return *this; + } + + template + constexpr volatile IOPort& set_bit(S bit) volatile { + this->value = bit::set(this->value, static_cast(bit)); + return *this; + } + + template + constexpr IOPort& clear_bit(S bit) { + this->value = bit::set(this->value, static_cast(bit)); + return *this; + } + + template + constexpr volatile IOPort& clear_bit(S bit) volatile { + this->value = bit::set(this->value, static_cast(bit)); + return *this; + } + + template + constexpr bool is_bit_set(S bit) { + return bit::is_set(this->value, static_cast(bit)); + } + + template + constexpr bool is_bit_set(S bit) volatile { + return bit::is_set(this->value, static_cast(bit)); + } + + //Accessing values + template + constexpr IOPort& set_value(S value, const BitRange& range) { + this->value = bit::value::set_normalized(this->value, static_cast(value), range.begin, range.length); + return *this; + } + + template + constexpr volatile IOPort& set_value(S value, const BitRange& range) volatile { + this->value = bit::value::set_normalized(this->value, static_cast(value), range.begin, range.length); + return *this; + } + + template + constexpr IOPort& clear_value(const BitRange& range) { + this->value = bit::value::clear_normalized(this->value, range.begin, range.length); + return *this; + } + + template + constexpr volatile IOPort& clear_value(const BitRange& range) volatile { + this->value = bit::value::clear_normalized(this->value, range.begin, range.length); + return *this; + } + + template + constexpr S get_value(const BitRange& range) { + return static_cast(bit::value::get_normalized(this->value, range.begin, range.length)); + } + + template + constexpr S get_value(const BitRange& range) volatile { + return static_cast(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& operator=(T value) { + this->value = value; + } + + constexpr volatile IOPort& operator=(T value) volatile { + this->value = value; + } +}; + +#endif //!__JABYENGINE_IOPORT_HPP__ \ No newline at end of file diff --git a/src/Library/src/BootLoader/boot_spu.cpp b/src/Library/src/BootLoader/boot_spu.cpp index e10dddb2..0970f2e4 100644 --- a/src/Library/src/BootLoader/boot_spu.cpp +++ b/src/Library/src/BootLoader/boot_spu.cpp @@ -1,4 +1,5 @@ #include +#include namespace SPU { static void clear_main_volume() { @@ -32,7 +33,15 @@ namespace SPU { io_class__update_with(Control::Register, Control()); } + void test() { + static __always_inline volatile auto& Dino = *reinterpret_cast*>(0x120); + + while(Dino.is_bit_set(0)); + } + void setup() { + test(); + clear_main_volume(); clear_keys(); disable_control();