Making ComplexBitMap a POD part 1
This commit is contained in:
parent
9da81fc5d0
commit
fdf8ba0e9a
|
@ -0,0 +1,300 @@
|
||||||
|
#ifndef __JABYENGINE_COMPLEX_BITMAP_HPP__
|
||||||
|
#define __JABYENGINE_COMPLEX_BITMAP_HPP__
|
||||||
|
#include "bits.hpp"
|
||||||
|
|
||||||
|
struct ClearBitValue {
|
||||||
|
size_t bit;
|
||||||
|
|
||||||
|
constexpr ClearBitValue(size_t bit) : bit(bit) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct Bit {
|
||||||
|
typedef T ValueType;
|
||||||
|
|
||||||
|
size_t value;
|
||||||
|
|
||||||
|
constexpr Bit(size_t value) : value(value) {
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr operator size_t() const {
|
||||||
|
return this->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr ClearBitValue operator!() const {
|
||||||
|
return ClearBitValue(this->value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct BitRangeValue {
|
||||||
|
T value;
|
||||||
|
size_t begin;
|
||||||
|
size_t length;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct BitRange {
|
||||||
|
typedef T ValueType;
|
||||||
|
|
||||||
|
size_t begin;
|
||||||
|
size_t length;
|
||||||
|
|
||||||
|
static constexpr BitRange<T> from_to(size_t start, size_t end) {
|
||||||
|
return {start, (end - start + 1)};
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr BitRangeValue<T> with(T value) const {
|
||||||
|
return {value, this->begin, this->length};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static constexpr __always_inline BitRangeValue<T> operator<<(const BitRange<T>& range, T value) {
|
||||||
|
return BitRangeValue{value, range.begin, range.length};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class ComplexBitMap {
|
||||||
|
public:
|
||||||
|
T raw;
|
||||||
|
|
||||||
|
private:
|
||||||
|
template<typename S>
|
||||||
|
constexpr ComplexBitMap<T>& set_va(const S& value) {
|
||||||
|
return this->set(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S, typename...ARGS>
|
||||||
|
constexpr ComplexBitMap<T>& set_va(const S& value, const ARGS&...args) {
|
||||||
|
return this->set_va(value).set_va(args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
template<typename...ARGS>
|
||||||
|
static constexpr ComplexBitMap<T> with(ARGS...args) {
|
||||||
|
return ComplexBitMap().set_va(args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Accesssing bits
|
||||||
|
template<typename S>
|
||||||
|
constexpr ComplexBitMap<T>& set_bit(S bit) {
|
||||||
|
this->raw = bit::set(this->raw, static_cast<size_t>(bit));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr ComplexBitMap<T>& clear_bit(S bit) {
|
||||||
|
this->raw = bit::clear(this->raw, static_cast<size_t>(bit));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr bool is_bit_set(S bit) {
|
||||||
|
return bit::is_set(this->raw, static_cast<size_t>(bit));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Accessing values
|
||||||
|
template<typename S>
|
||||||
|
constexpr ComplexBitMap<T>& set_value(S value, const BitRange<S>& range) {
|
||||||
|
this->raw = bit::value::set_normalized(this->raw, static_cast<T>(value), range.begin, range.length);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr ComplexBitMap<T>& clear_value(const BitRange<S>& range) {
|
||||||
|
this->raw = bit::value::clear_normalized(this->raw, range.begin, range.length);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr S get_value(const BitRange<S>& range) {
|
||||||
|
return static_cast<S>(bit::value::get_normalized(this->raw, range.begin, range.length));
|
||||||
|
}
|
||||||
|
|
||||||
|
// For easier constructing
|
||||||
|
constexpr ComplexBitMap<T>& set(const BitRange<T>& range, T value) {
|
||||||
|
this->set_value(value, range);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr ComplexBitMap<T>& set(const BitRangeValue<T>& value) {
|
||||||
|
this->set_value(value.value, {value.begin, value.length});
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr ComplexBitMap<T>& set(const Bit<T>& bit) {
|
||||||
|
this->set_bit(bit.value);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr ComplexBitMap<T>& set(const ClearBitValue& value) {
|
||||||
|
this->clear_bit(value.bit);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr ComplexBitMap<T>& operator|(const BitRangeValue<T>& value) {
|
||||||
|
this->set_value(value.value, value.range);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr ComplexBitMap<T>& operator|(const Bit<T>& bit) {
|
||||||
|
this->set_bit(bit.value);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr ComplexBitMap<T>& operator|(const ClearBitValue& value) {
|
||||||
|
this->clear_bit(value.bit);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*template<typename T>
|
||||||
|
class ComplexBitMap {
|
||||||
|
public:
|
||||||
|
T value = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
template<typename S>
|
||||||
|
constexpr ComplexBitMap<T>& set_va(const S& value) {
|
||||||
|
return this->set(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S, typename...ARGS>
|
||||||
|
constexpr ComplexBitMap<T>& set_va(const S& value, const ARGS&...args) {
|
||||||
|
return this->set_va(value).set_va(args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
constexpr ComplexBitMap() = default;
|
||||||
|
constexpr ComplexBitMap(T value) : value(value) {
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename...ARGS>
|
||||||
|
static constexpr ComplexBitMap<T> with(ARGS...args) {
|
||||||
|
return ComplexBitMap().set_va(args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Accesssing bits
|
||||||
|
template<typename S>
|
||||||
|
constexpr ComplexBitMap<T>& set_bit(S bit) {
|
||||||
|
this->value = bit::set(this->value, static_cast<size_t>(bit));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr void set_bit(S bit) volatile {
|
||||||
|
this->value = bit::set(this->value, static_cast<size_t>(bit));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr ComplexBitMap<T>& clear_bit(S bit) {
|
||||||
|
this->value = bit::clear(this->value, static_cast<size_t>(bit));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr void clear_bit(S bit) volatile {
|
||||||
|
this->value = bit::clear(this->value, static_cast<size_t>(bit));
|
||||||
|
}
|
||||||
|
|
||||||
|
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 ComplexBitMap<T>& set_value(S value, const BitRange<S>& range) {
|
||||||
|
this->value = bit::value::set_normalized(this->value, static_cast<T>(value), range.begin, range.length);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr void set_value(S value, const BitRange<S>& range) volatile {
|
||||||
|
this->value = bit::value::set_normalized(this->value, static_cast<T>(value), range.begin, range.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr ComplexBitMap<T>& clear_value(const BitRange<S>& range) {
|
||||||
|
this->value = bit::value::clear_normalized(this->value, range.begin, range.length);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr void clear_value(const BitRange<S>& range) volatile {
|
||||||
|
this->value = bit::value::clear_normalized(this->value, range.begin, range.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr S get_value(const BitRange<S>& range) {
|
||||||
|
return static_cast<S>(bit::value::get_normalized(this->value, range.begin, range.length));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename S>
|
||||||
|
constexpr S get_value(const BitRange<S>& range) volatile {
|
||||||
|
return static_cast<S>(bit::value::get_normalized(this->value, range.begin, range.length));
|
||||||
|
}
|
||||||
|
|
||||||
|
// For easier constructing
|
||||||
|
constexpr ComplexBitMap<T>& set(const BitRange<T>& range, T value) {
|
||||||
|
this->set_value(value, range);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr ComplexBitMap<T>& set(const BitRangeValue<T>& value) {
|
||||||
|
this->set_value(value.value, {value.begin, value.length});
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr ComplexBitMap<T>& set(const Bit<T>& bit) {
|
||||||
|
this->set_bit(bit.value);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr ComplexBitMap<T>& set(const ClearBitValue& value) {
|
||||||
|
this->clear_bit(value.bit);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr ComplexBitMap<T>& operator|(const BitRangeValue<T>& value) {
|
||||||
|
this->set_value(value.value, value.range);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr ComplexBitMap<T>& operator|(const Bit<T>& bit) {
|
||||||
|
this->set_bit(bit.value);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr ComplexBitMap<T>& operator|(const ClearBitValue& value) {
|
||||||
|
this->clear_bit(value.bit);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//For raw access
|
||||||
|
constexpr operator T() const {
|
||||||
|
return this->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr operator T() const volatile {
|
||||||
|
return this->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr ComplexBitMap<T>& operator=(T value) {
|
||||||
|
this->value = value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr void operator=(T value) volatile {
|
||||||
|
this->value = value;
|
||||||
|
}
|
||||||
|
};*/
|
||||||
|
|
||||||
|
#endif //!__JABYENGINE_COMPLEX_BITMAP_HPP__
|
|
@ -1,39 +1,73 @@
|
||||||
#ifndef __JABYENGINE_GPU_TYPES_HPP__
|
#ifndef __JABYENGINE_GPU_TYPES_HPP__
|
||||||
#define __JABYENGINE_GPU_TYPES_HPP__
|
#define __JABYENGINE_GPU_TYPES_HPP__
|
||||||
#include "../jabyengine_defines.h"
|
#include "../jabyengine_defines.h"
|
||||||
|
#include "../Auxiliary/complex_bitmap.hpp"
|
||||||
|
|
||||||
namespace GPU {
|
namespace GPU {
|
||||||
struct Color {
|
struct Color24 {
|
||||||
uint8_t red = 0;
|
uint8_t red = 0;
|
||||||
uint8_t green = 0;
|
uint8_t green = 0;
|
||||||
uint8_t blue = 0;
|
uint8_t blue = 0;
|
||||||
|
|
||||||
constexpr Color() = default;
|
constexpr Color24() = default;
|
||||||
constexpr Color(uint8_t r, uint8_t g, uint8_t b) : blue(b), green(g), red(r) {
|
constexpr Color24(uint8_t r, uint8_t g, uint8_t b) : blue(b), green(g), red(r) {
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr uint32_t raw() const {
|
constexpr uint32_t raw() const {
|
||||||
return ((this->blue << 16) | (this->green << 8) | this->red);
|
return ((this->blue << 16) | (this->green << 8) | this->red);
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr Color Black() {
|
static constexpr Color24 Black() {
|
||||||
return Color(0, 0, 0);
|
return Color24(0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr Color White() {
|
static constexpr Color24 White() {
|
||||||
return Color(0xFF, 0xFF, 0xFF);
|
return Color24(0xFF, 0xFF, 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr Color Red() {
|
static constexpr Color24 Red() {
|
||||||
return Color(0xFF, 0x0, 0x0);
|
return Color24(0xFF, 0x0, 0x0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr Color Green() {
|
static constexpr Color24 Green() {
|
||||||
return Color(0x0, 0x0, 0xFF);
|
return Color24(0x0, 0x0, 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr Color Blue() {
|
static constexpr Color24 Blue() {
|
||||||
return Color(0x0, 0x0, 0xFF);
|
return Color24(0x0, 0x0, 0xFF);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class Color16 {
|
||||||
|
private:
|
||||||
|
static constexpr auto RedRange = BitRange<uint16_t>::from_to(0, 4);
|
||||||
|
static constexpr auto BlueRange = BitRange<uint16_t>::from_to(5, 9);
|
||||||
|
static constexpr auto GreenRange = BitRange<uint16_t>::from_to(10, 14);
|
||||||
|
static constexpr auto SemiTransperancyBit = Bit<uint16_t>(15);
|
||||||
|
|
||||||
|
ComplexBitMap<uint16_t> value = {0};
|
||||||
|
|
||||||
|
public:
|
||||||
|
constexpr Color16() = default;
|
||||||
|
constexpr Color16(uint8_t r, uint8_t g, uint8_t b) {
|
||||||
|
Color16::set_red(r);
|
||||||
|
Color16::set_green(g);
|
||||||
|
Color16::set_blue(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Color16(const Color24& color) : Color16(color.red, color.green, color.blue) {
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr void set_red(uint8_t red) {
|
||||||
|
this->value.set_value(static_cast<uint16_t>(red), RedRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr void set_green(uint8_t green) {
|
||||||
|
this->value.set_value(static_cast<uint16_t>(green), GreenRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr void set_blue(uint8_t blue) {
|
||||||
|
this->value.set_value(static_cast<uint16_t>(blue), BlueRange);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -58,27 +58,27 @@ namespace DMA {
|
||||||
static constexpr auto ToMainRAM = !FromMainRAM;
|
static constexpr auto ToMainRAM = !FromMainRAM;
|
||||||
|
|
||||||
static constexpr CHCHR StartMDECin() {
|
static constexpr CHCHR StartMDECin() {
|
||||||
return CHCHR(0x01000201);
|
return ComplexBitMap{0x01000201};
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr CHCHR StartMDECout() {
|
static constexpr CHCHR StartMDECout() {
|
||||||
return CHCHR(0x01000200);
|
return ComplexBitMap{0x01000200};
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr CHCHR StartGPUReceive() {
|
static constexpr CHCHR StartGPUReceive() {
|
||||||
return CHCHR(0x01000201);
|
return ComplexBitMap{0x01000201};
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr CHCHR StartCDROM() {
|
static constexpr CHCHR StartCDROM() {
|
||||||
return CHCHR(0x11000000);
|
return ComplexBitMap{0x11000000};
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr CHCHR StartSPUReceive() {
|
static constexpr CHCHR StartSPUReceive() {
|
||||||
return CHCHR(0x01000201);
|
return ComplexBitMap{0x01000201};
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr CHCHR StartOTC() {
|
static constexpr CHCHR StartOTC() {
|
||||||
return CHCHR(0x11000002);
|
return ComplexBitMap{0x11000002};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -46,16 +46,16 @@ namespace GPU {
|
||||||
struct __no_align GP0 : public ComplexBitMap<uint32_t> {
|
struct __no_align GP0 : public ComplexBitMap<uint32_t> {
|
||||||
__io_port_inherit_complex_bit_map(GP0);
|
__io_port_inherit_complex_bit_map(GP0);
|
||||||
|
|
||||||
static constexpr GP0 QuickFill(Color color) {
|
static constexpr GP0 QuickFill(Color24 color) {
|
||||||
return {(0x02 << 24) | color.raw()};
|
return ComplexBitMap{(0x02 << 24) | color.raw()};
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr GP0 TopLeftPosition(uint16_t x, uint16_t y) {
|
static constexpr GP0 TopLeftPosition(uint16_t x, uint16_t y) {
|
||||||
return {(y << 16) | x};
|
return ComplexBitMap{static_cast<uint16_t>((y << 16) | x)};
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr GP0 WidthHeight(uint16_t w, uint16_t h) {
|
static constexpr GP0 WidthHeight(uint16_t w, uint16_t h) {
|
||||||
return {(h << 16) | w};
|
return ComplexBitMap{static_cast<uint16_t>((h << 16) | w)};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -67,11 +67,11 @@ namespace GPU {
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr GP1 Reset() {
|
static constexpr GP1 Reset() {
|
||||||
return {0};
|
return ComplexBitMap{0};
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr GP1 SetDisplayState(DisplayState state) {
|
static constexpr GP1 SetDisplayState(DisplayState state) {
|
||||||
return {construct_cmd(0x03, static_cast<uint32_t>(state))};
|
return ComplexBitMap{construct_cmd(0x03, static_cast<uint32_t>(state))};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,205 +1,6 @@
|
||||||
#ifndef __JABYENGINE_IOPORT_HPP__
|
#ifndef __JABYENGINE_IOPORT_HPP__
|
||||||
#define __JABYENGINE_IOPORT_HPP__
|
#define __JABYENGINE_IOPORT_HPP__
|
||||||
#include "../../Auxiliary/bits.hpp"
|
#include "../../Auxiliary/complex_bitmap.hpp"
|
||||||
|
|
||||||
struct ClearBitValue {
|
|
||||||
size_t bit;
|
|
||||||
|
|
||||||
constexpr ClearBitValue(size_t bit) : bit(bit) {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct Bit {
|
|
||||||
typedef T ValueType;
|
|
||||||
|
|
||||||
size_t value;
|
|
||||||
|
|
||||||
constexpr Bit(size_t value) : value(value) {
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr operator size_t() const {
|
|
||||||
return this->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr ClearBitValue operator!() const {
|
|
||||||
return ClearBitValue(this->value);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct BitRangeValue {
|
|
||||||
T value;
|
|
||||||
size_t begin;
|
|
||||||
size_t length;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct BitRange {
|
|
||||||
typedef T ValueType;
|
|
||||||
|
|
||||||
size_t begin;
|
|
||||||
size_t length;
|
|
||||||
|
|
||||||
static constexpr BitRange<T> from_to(size_t start, size_t end) {
|
|
||||||
return {start, (end - start + 1)};
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr BitRangeValue<T> with(T value) const {
|
|
||||||
return {value, this->begin, this->length};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
static constexpr __always_inline BitRangeValue<T> operator<<(const BitRange<T>& range, T value) {
|
|
||||||
return BitRangeValue{value, range.begin, range.length};
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
class __no_align ComplexBitMap {
|
|
||||||
private:
|
|
||||||
T value = 0;
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr ComplexBitMap<T>& set_va(const S& value) {
|
|
||||||
return this->set(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S, typename...ARGS>
|
|
||||||
constexpr ComplexBitMap<T>& set_va(const S& value, const ARGS&...args) {
|
|
||||||
return this->set_va(value).set_va(args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
constexpr ComplexBitMap() = default;
|
|
||||||
constexpr ComplexBitMap(T value) : value(value) {
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename...ARGS>
|
|
||||||
static constexpr ComplexBitMap<T> with(ARGS...args) {
|
|
||||||
return ComplexBitMap().set_va(args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Accesssing bits
|
|
||||||
template<typename S>
|
|
||||||
constexpr ComplexBitMap<T>& set_bit(S bit) {
|
|
||||||
this->value = bit::set(this->value, static_cast<size_t>(bit));
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr void set_bit(S bit) volatile {
|
|
||||||
this->value = bit::set(this->value, static_cast<size_t>(bit));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr ComplexBitMap<T>& clear_bit(S bit) {
|
|
||||||
this->value = bit::clear(this->value, static_cast<size_t>(bit));
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr void clear_bit(S bit) volatile {
|
|
||||||
this->value = bit::clear(this->value, static_cast<size_t>(bit));
|
|
||||||
}
|
|
||||||
|
|
||||||
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 ComplexBitMap<T>& set_value(S value, const BitRange<S>& range) {
|
|
||||||
this->value = bit::value::set_normalized(this->value, static_cast<T>(value), range.begin, range.length);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr void set_value(S value, const BitRange<S>& range) volatile {
|
|
||||||
this->value = bit::value::set_normalized(this->value, static_cast<T>(value), range.begin, range.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr ComplexBitMap<T>& clear_value(const BitRange<S>& range) {
|
|
||||||
this->value = bit::value::clear_normalized(this->value, range.begin, range.length);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr void clear_value(const BitRange<S>& range) volatile {
|
|
||||||
this->value = bit::value::clear_normalized(this->value, range.begin, range.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr S get_value(const BitRange<S>& range) {
|
|
||||||
return static_cast<S>(bit::value::get_normalized(this->value, range.begin, range.length));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr S get_value(const BitRange<S>& range) volatile {
|
|
||||||
return static_cast<S>(bit::value::get_normalized(this->value, range.begin, range.length));
|
|
||||||
}
|
|
||||||
|
|
||||||
// For easier constructing
|
|
||||||
constexpr ComplexBitMap<T>& set(const BitRange<T>& range, T value) {
|
|
||||||
this->set_value(value, range);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr ComplexBitMap<T>& set(const BitRangeValue<T>& value) {
|
|
||||||
this->set_value(value.value, {value.begin, value.length});
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr ComplexBitMap<T>& set(const Bit<T>& bit) {
|
|
||||||
this->set_bit(bit.value);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr ComplexBitMap<T>& set(const ClearBitValue& value) {
|
|
||||||
this->clear_bit(value.bit);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr ComplexBitMap<T>& operator|(const BitRangeValue<T>& value) {
|
|
||||||
this->set_value(value.value, value.range);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr ComplexBitMap<T>& operator|(const Bit<T>& bit) {
|
|
||||||
this->set_bit(bit.value);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr ComplexBitMap<T>& operator|(const ClearBitValue& value) {
|
|
||||||
this->clear_bit(value.bit);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
//For raw access
|
|
||||||
constexpr operator T() const {
|
|
||||||
return this->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr operator T() const volatile {
|
|
||||||
return this->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr ComplexBitMap<T>& operator=(T value) {
|
|
||||||
this->value = value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr void operator=(T value) volatile {
|
|
||||||
this->value = value;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class __no_align IOPort {
|
class __no_align IOPort {
|
||||||
|
@ -230,23 +31,23 @@ struct __no_align ubus32_t {
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr operator uint32_t() const {
|
constexpr operator uint32_t() const {
|
||||||
return ((this->high << 16) | this->low);
|
return ((this->high.raw << 16) | this->low.raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr operator uint32_t() const volatile {
|
operator uint32_t() const volatile {
|
||||||
return ((this->high << 16) | this->low);
|
return ((this->high.raw << 16) | this->low.raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr ubus32_t& operator=(uint32_t value) {
|
constexpr ubus32_t& operator=(uint32_t value) {
|
||||||
this->low = (value & 0xFFFF);
|
this->low.raw = (value & 0xFFFF);
|
||||||
this->high = (value >> 16);
|
this->high.raw = (value >> 16);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr void operator=(uint32_t value) volatile {
|
constexpr void operator=(uint32_t value) volatile {
|
||||||
this->low = (value & 0xFFFF);
|
this->low.raw = (value & 0xFFFF);
|
||||||
this->high = (value >> 16);
|
this->high.raw = (value >> 16);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static constexpr uintptr_t IO_Base_Mask = 0xF0000000;
|
static constexpr uintptr_t IO_Base_Mask = 0xF0000000;
|
||||||
|
@ -257,12 +58,25 @@ static constexpr uintptr_t IO_Base_Adr = 0x10000000;
|
||||||
#define __declare_io_port_global_const(type, name, adr) __declare_io_port_global_raw(const, type, name, adr)
|
#define __declare_io_port_global_const(type, name, adr) __declare_io_port_global_raw(const, type, name, adr)
|
||||||
#define __declare_io_port_global_array(type, name, adr, size) static __always_inline auto& name = reinterpret_cast<type(&)[size]>(*reinterpret_cast<type*>((IO_Base_Adr + (adr & ~IO_Base_Mask))));
|
#define __declare_io_port_global_array(type, name, adr, size) static __always_inline auto& name = reinterpret_cast<type(&)[size]>(*reinterpret_cast<type*>((IO_Base_Adr + (adr & ~IO_Base_Mask))));
|
||||||
#define __io_port_inherit_complex_bit_map(name) \
|
#define __io_port_inherit_complex_bit_map(name) \
|
||||||
|
constexpr name() = default; \
|
||||||
|
constexpr name(ComplexBitMap value) : ComplexBitMap(value) { \
|
||||||
|
} \
|
||||||
|
template<typename...ARGS> \
|
||||||
|
static constexpr name with(ARGS...args) { \
|
||||||
|
return {ComplexBitMap::with(args...)}; \
|
||||||
|
}\
|
||||||
|
template<typename T> \
|
||||||
|
constexpr void operator=(ComplexBitMap<T> value) volatile { \
|
||||||
|
this->raw = value.raw; \
|
||||||
|
}
|
||||||
|
|
||||||
|
/*\
|
||||||
using ComplexBitMap::operator=; \
|
using ComplexBitMap::operator=; \
|
||||||
constexpr name() = default; \
|
constexpr name() = default; \
|
||||||
constexpr name(ComplexBitMap value) : ComplexBitMap(value) { \
|
constexpr name(ComplexBitMap value) : ComplexBitMap(value) { \
|
||||||
}\
|
}\
|
||||||
template<typename...ARGS> \
|
template<typename...ARGS> \
|
||||||
constexpr name(ARGS...args) : ComplexBitMap(args...) {\
|
constexpr name(ARGS...args) : ComplexBitMap(args...) {\
|
||||||
}
|
}*/
|
||||||
|
|
||||||
#endif //!__JABYENGINE_IOPORT_HPP__
|
#endif //!__JABYENGINE_IOPORT_HPP__
|
|
@ -34,7 +34,7 @@ namespace SPU {
|
||||||
//4096 == 44100Hz
|
//4096 == 44100Hz
|
||||||
constexpr double Base = (4096.0 / 44100.0);
|
constexpr double Base = (4096.0 / 44100.0);
|
||||||
|
|
||||||
return ComplexBitMap(static_cast<uint16_t>((freq*Base)));
|
return ComplexBitMap<uint16_t>{static_cast<uint16_t>((freq*Base))};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <PSX/System/IOPorts/GPU_IO.hpp>
|
#include <PSX/System/IOPorts/GPU_IO.hpp>
|
||||||
|
|
||||||
namespace GPU {
|
namespace GPU {
|
||||||
static void quick_fill_fast(const Color& color, const PositionU16& pos, const SizeU16& size) {
|
static void quick_fill_fast(const Color24& color, const PositionU16& pos, const SizeU16& size) {
|
||||||
Port::GP0.write(Port::Command::GP0::QuickFill(color));
|
Port::GP0.write(Port::Command::GP0::QuickFill(color));
|
||||||
Port::GP0.write(Port::Command::GP0::TopLeftPosition(pos.x, pos.y));
|
Port::GP0.write(Port::Command::GP0::TopLeftPosition(pos.x, pos.y));
|
||||||
Port::GP0.write(Port::Command::GP0::WidthHeight(size.width, size.height));
|
Port::GP0.write(Port::Command::GP0::WidthHeight(size.width, size.height));
|
||||||
|
|
|
@ -6,13 +6,13 @@ namespace GPU {
|
||||||
|
|
||||||
void display_logo() {
|
void display_logo() {
|
||||||
Display::disable();
|
Display::disable();
|
||||||
quick_fill_fast(Color(0x0, 0x80, 0x80), PositionU16(0, 0), SizeU16(640, 480));
|
quick_fill_fast(Color24(0x0, 0x80, 0x80), PositionU16(0, 0), SizeU16(640, 480));
|
||||||
Display::enable();
|
Display::enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Port::GP1.write(Port::Command::GP1::Reset());
|
Port::GP1.write(Port::Command::GP1::Reset());
|
||||||
|
|
||||||
quick_fill_fast(Color::Black(), PositionU16(0, 0), SizeU16(640, 480));
|
quick_fill_fast(Color24::Black(), PositionU16(0, 0), SizeU16(640, 480));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -33,7 +33,7 @@ namespace SPU {
|
||||||
voice.sampleRate.write(SampleRate());
|
voice.sampleRate.write(SampleRate());
|
||||||
voice.ad.write(AD());
|
voice.ad.write(AD());
|
||||||
voice.sr.write(SR());
|
voice.sr.write(SR());
|
||||||
voice.currentVolume.write(SweepVolume());
|
voice.currentVolume.write(SimpleVolume(0));
|
||||||
|
|
||||||
voice.adr.write(0x200);
|
voice.adr.write(0x200);
|
||||||
voice.repeatAdr.write(0x200);
|
voice.repeatAdr.write(0x200);
|
||||||
|
|
Loading…
Reference in New Issue