diff --git a/include/PSX/Auxiliary/bits.hpp b/include/PSX/Auxiliary/bits.hpp index 6f6c1397..935d2700 100644 --- a/include/PSX/Auxiliary/bits.hpp +++ b/include/PSX/Auxiliary/bits.hpp @@ -2,53 +2,55 @@ #define __JABYENGINE_BITS_HPP__ #include "../jabyengine_defines.h" -namespace bit { - template - static constexpr T set(T raw_value, size_t bit) { - return (raw_value | (1 << bit)); - } - - template - static constexpr T clear(T raw_value, size_t bit) { - return (raw_value & ~(1 << bit)); - } - - template - static constexpr bool is_set(T raw_value, size_t bit) { - return static_cast(raw_value & (1 << bit)); - } - - namespace value { +namespace JabyEngine { + namespace bit { template - static constexpr T crop_value(T raw_value, size_t length) { - return (raw_value & ((1 << length) - 1)); + static constexpr T set(T raw_value, size_t bit) { + return (raw_value | (1 << bit)); } template - static constexpr T range_mask(size_t start_bit, size_t length) { - return (((1 << length) - 1) << start_bit); + static constexpr T clear(T raw_value, size_t bit) { + return (raw_value & ~(1 << bit)); } template - static constexpr T clear_normalized(T raw_value, size_t start_bit, size_t length) { - return (raw_value & ~range_mask(start_bit, length)); + static constexpr bool is_set(T raw_value, size_t bit) { + return static_cast(raw_value & (1 << bit)); } - template - 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)); + namespace value { + template + static constexpr T crop_value(T raw_value, size_t length) { + return (raw_value & ((1 << length) - 1)); + } + + template + static constexpr T range_mask(size_t start_bit, size_t length) { + return (((1 << length) - 1) << start_bit); + } + + template + static constexpr T clear_normalized(T raw_value, size_t start_bit, size_t length) { + return (raw_value & ~range_mask(start_bit, length)); + } + + template + 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 + static constexpr T get_normalized(T raw_value, size_t start_bit, size_t length) { + return (raw_value & range_mask(start_bit, length)) >> start_bit; + } } - template - static constexpr T get_normalized(T raw_value, size_t start_bit, size_t length) { - return (raw_value & range_mask(start_bit, length)) >> start_bit; + template + static constexpr S cast(T value) { + return *reinterpret_cast(&value); } } - - template - static constexpr S cast(T value) { - return *reinterpret_cast(&value); - } } #define __start_end_bit2_start_length(start_bit, end_bit) start_bit, (end_bit - start_bit + 1) diff --git a/include/PSX/Auxiliary/complex_bitmap.hpp b/include/PSX/Auxiliary/complex_bitmap.hpp index 96a7c045..d6de6485 100644 --- a/include/PSX/Auxiliary/complex_bitmap.hpp +++ b/include/PSX/Auxiliary/complex_bitmap.hpp @@ -2,194 +2,196 @@ #define __JABYENGINE_COMPLEX_BITMAP_HPP__ #include "bits.hpp" -struct ClearBitValue { - size_t bit; +namespace JabyEngine { + struct ClearBitValue { + size_t bit; - constexpr ClearBitValue(size_t bit) : bit(bit) { - } -}; + constexpr ClearBitValue(size_t bit) : bit(bit) { + } + }; -template -struct Bit { - typedef T ValueType; + template + struct Bit { + typedef T ValueType; - size_t value; + size_t value; - constexpr Bit(size_t value) : value(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 + struct BitRangeValue { + T value; + size_t begin; + size_t length; + }; + + template + struct BitRange { + typedef T ValueType; + + size_t begin; + size_t length; + + static constexpr BitRange from_to(size_t start, size_t end) { + return {start, (end - start + 1)}; + } + + constexpr BitRangeValue with(T value) const { + return {value, this->begin, this->length}; + } + }; + + template + static constexpr __always_inline BitRangeValue operator<<(const BitRange& range, T value) { + return BitRangeValue{value, range.begin, range.length}; } - constexpr operator size_t() const { - return this->value; - } + template + class ComplexBitMap { + public: + T raw; - constexpr ClearBitValue operator!() const { - return ClearBitValue(this->value); - } -}; + private: + template + constexpr __always_inline ComplexBitMap& set_va(const S& value) { + return this->set(value); + } -template -struct BitRangeValue { - T value; - size_t begin; - size_t length; -}; + template + constexpr __always_inline ComplexBitMap& set_va(const S& value, const ARGS&...args) { + return this->set_va(value).set_va(args...); + } -template -struct BitRange { - typedef T ValueType; + public: + template + static constexpr __always_inline ComplexBitMap with(ARGS...args) { + return ComplexBitMap().set_va(args...); + } - size_t begin; - size_t length; + //Accesssing bits + template + constexpr ComplexBitMap& set_bit(S bit) { + this->raw = bit::set(this->raw, static_cast(bit)); + return *this; + } - static constexpr BitRange from_to(size_t start, size_t end) { - return {start, (end - start + 1)}; - } + template + constexpr void set_bit(S bit) volatile { + this->raw = bit::set(this->raw, static_cast(bit)); + } - constexpr BitRangeValue with(T value) const { - return {value, this->begin, this->length}; - } -}; + template + constexpr ComplexBitMap& clear_bit(S bit) { + this->raw = bit::clear(this->raw, static_cast(bit)); + return *this; + } -template -static constexpr __always_inline BitRangeValue operator<<(const BitRange& range, T value) { - return BitRangeValue{value, range.begin, range.length}; + template + constexpr void clear_bit(S bit) volatile { + this->raw = bit::clear(this->raw, static_cast(bit)); + } + + template + constexpr bool is_bit_set(S bit) { + return bit::is_set(this->raw, static_cast(bit)); + } + + template + constexpr bool is_bit_set(S bit) const volatile { + return bit::is_set(this->raw, static_cast(bit)); + } + + //Accessing values + template + constexpr ComplexBitMap& set_value(S value, const BitRange& range) { + this->raw = bit::value::set_normalized(this->raw, static_cast(value), range.begin, range.length); + return *this; + } + + template + constexpr void set_value(S value, const BitRange& range) volatile { + this->raw = bit::value::set_normalized(this->raw, static_cast(value), range.begin, range.length); + } + + template + constexpr ComplexBitMap& clear_value(const BitRange& range) { + this->raw = bit::value::clear_normalized(this->raw, range.begin, range.length); + return *this; + } + + template + constexpr void clear_value(const BitRange& range) volatile { + this->raw = bit::value::clear_normalized(this->raw, range.begin, range.length); + } + + template + constexpr S get_value(const BitRange& range) const { + return static_cast(bit::value::get_normalized(this->raw, range.begin, range.length)); + } + + template + constexpr S get_value(const BitRange& range) const volatile { + return static_cast(bit::value::get_normalized(this->raw, range.begin, range.length)); + } + + //For easier checking + constexpr bool is(Bit bit) const { + return ComplexBitMap::is_bit_set(bit); + } + + constexpr bool is(Bit bit) const volatile { + return ComplexBitMap::is_bit_set(bit); + } + + // For easier constructing + template + constexpr __always_inline ComplexBitMap& set(const BitRange& range, T value) { + this->set_value(value, range); + return *this; + } + + template + constexpr __always_inline ComplexBitMap& set(const BitRangeValue& value) { + this->set_value(value.value, {value.begin, value.length}); + return *this; + } + + template + constexpr __always_inline ComplexBitMap& set(const Bit& bit) { + this->set_bit(bit.value); + return *this; + } + + constexpr __always_inline ComplexBitMap& set(const ClearBitValue& value) { + this->clear_bit(value.bit); + return *this; + } + + constexpr __always_inline ComplexBitMap& operator|(const BitRangeValue& value) { + this->set_value(value.value, value.range); + return *this; + } + + constexpr __always_inline ComplexBitMap& operator|(const Bit& bit) { + this->set_bit(bit.value); + return *this; + } + + constexpr __always_inline ComplexBitMap& operator|(const ClearBitValue& value) { + this->clear_bit(value.bit); + return *this; + } + }; } -template -class ComplexBitMap { -public: - T raw; - -private: - template - constexpr __always_inline ComplexBitMap& set_va(const S& value) { - return this->set(value); - } - - template - constexpr __always_inline ComplexBitMap& set_va(const S& value, const ARGS&...args) { - return this->set_va(value).set_va(args...); - } - -public: - template - static constexpr __always_inline ComplexBitMap with(ARGS...args) { - return ComplexBitMap().set_va(args...); - } - - //Accesssing bits - template - constexpr ComplexBitMap& set_bit(S bit) { - this->raw = bit::set(this->raw, static_cast(bit)); - return *this; - } - - template - constexpr void set_bit(S bit) volatile { - this->raw = bit::set(this->raw, static_cast(bit)); - } - - template - constexpr ComplexBitMap& clear_bit(S bit) { - this->raw = bit::clear(this->raw, static_cast(bit)); - return *this; - } - - template - constexpr void clear_bit(S bit) volatile { - this->raw = bit::clear(this->raw, static_cast(bit)); - } - - template - constexpr bool is_bit_set(S bit) { - return bit::is_set(this->raw, static_cast(bit)); - } - - template - constexpr bool is_bit_set(S bit) const volatile { - return bit::is_set(this->raw, static_cast(bit)); - } - - //Accessing values - template - constexpr ComplexBitMap& set_value(S value, const BitRange& range) { - this->raw = bit::value::set_normalized(this->raw, static_cast(value), range.begin, range.length); - return *this; - } - - template - constexpr void set_value(S value, const BitRange& range) volatile { - this->raw = bit::value::set_normalized(this->raw, static_cast(value), range.begin, range.length); - } - - template - constexpr ComplexBitMap& clear_value(const BitRange& range) { - this->raw = bit::value::clear_normalized(this->raw, range.begin, range.length); - return *this; - } - - template - constexpr void clear_value(const BitRange& range) volatile { - this->raw = bit::value::clear_normalized(this->raw, range.begin, range.length); - } - - template - constexpr S get_value(const BitRange& range) const { - return static_cast(bit::value::get_normalized(this->raw, range.begin, range.length)); - } - - template - constexpr S get_value(const BitRange& range) const volatile { - return static_cast(bit::value::get_normalized(this->raw, range.begin, range.length)); - } - - //For easier checking - constexpr bool is(Bit bit) const { - return ComplexBitMap::is_bit_set(bit); - } - - constexpr bool is(Bit bit) const volatile { - return ComplexBitMap::is_bit_set(bit); - } - - // For easier constructing - template - constexpr __always_inline ComplexBitMap& set(const BitRange& range, T value) { - this->set_value(value, range); - return *this; - } - - template - constexpr __always_inline ComplexBitMap& set(const BitRangeValue& value) { - this->set_value(value.value, {value.begin, value.length}); - return *this; - } - - template - constexpr __always_inline ComplexBitMap& set(const Bit& bit) { - this->set_bit(bit.value); - return *this; - } - - constexpr __always_inline ComplexBitMap& set(const ClearBitValue& value) { - this->clear_bit(value.bit); - return *this; - } - - constexpr __always_inline ComplexBitMap& operator|(const BitRangeValue& value) { - this->set_value(value.value, value.range); - return *this; - } - - constexpr __always_inline ComplexBitMap& operator|(const Bit& bit) { - this->set_bit(bit.value); - return *this; - } - - constexpr __always_inline ComplexBitMap& operator|(const ClearBitValue& value) { - this->clear_bit(value.bit); - return *this; - } -}; - #endif //!__JABYENGINE_COMPLEX_BITMAP_HPP__ \ No newline at end of file diff --git a/include/PSX/File/Processor/cd_file_processor.hpp b/include/PSX/File/Processor/cd_file_processor.hpp index cb0b3b1b..e7853ebd 100644 --- a/include/PSX/File/Processor/cd_file_processor.hpp +++ b/include/PSX/File/Processor/cd_file_processor.hpp @@ -3,30 +3,32 @@ #include "../cd_file_types.hpp" #include "file_processor.hpp" -namespace CDFileProcessor { - class State { - private: - FileProcessor::State file_processor_state; - const uint32_t* data_adr; +namespace JabyEngine { + namespace CDFileProcessor { + class State { + private: + FileProcessor::State file_processor_state; + const uint32_t* data_adr; - public: - State() = default; + public: + State() = default; - void setup(uint16_t lba, uint16_t size, const CDFile::Payload& payload); - bool process(); - }; + void setup(uint16_t lba, uint16_t size, const CDFile::Payload& payload); + bool process(); + }; - template - static void load_from_cd(const OverlayLBA* overlay_lbas, const CDFile (&cd_files)[Size]) { - State state; + template + static void load_from_cd(const OverlayLBA* overlay_lbas, const CDFile (&cd_files)[Size]) { + State state; - for(const auto& file : cd_files) { - const auto& lba_info = overlay_lbas[file.rel_lba_idx]; + for(const auto& file : cd_files) { + const auto& lba_info = overlay_lbas[file.rel_lba_idx]; - state.setup(lba_info.lba, lba_info.size, file.payload); - //while(state.process());??? - } - } + state.setup(lba_info.lba, lba_info.size, file.payload); + //while(state.process());??? + } + } + } } // This will be used as the file processor but will work on cd types diff --git a/include/PSX/File/Processor/file_processor.hpp b/include/PSX/File/Processor/file_processor.hpp index 602c6348..c283fbef 100644 --- a/include/PSX/File/Processor/file_processor.hpp +++ b/include/PSX/File/Processor/file_processor.hpp @@ -2,50 +2,51 @@ #define __JABYENGINE_FILE_PROCESSOR_HPP__ #include "../file_types.hpp" -namespace FileProcessor { - class State { - private: - struct Reserved { - uint32_t reserved[4]; - }; +namespace JabyEngine { + namespace FileProcessor { + class State { + private: + struct Reserved { + uint32_t reserved[4]; + }; - struct Configuration; - typedef bool (*ProcessRoutine)(Configuration&, Reserved&); + struct Configuration; + typedef bool (*ProcessRoutine)(Configuration&, Reserved&); - struct Configuration { - ProcessRoutine process_routine = nullptr; - const uint32_t* data_adr = nullptr; - size_t data_word_size = 0ull; + struct Configuration { + ProcessRoutine process_routine = nullptr; + const uint32_t* data_adr = nullptr; + size_t data_word_size = 0ull; + + template + static __always_inline Configuration from(bool (*process_routine)(Configuration&, T&), const uint32_t* data_adr) { + return {reinterpret_cast(process_routine), data_adr}; + } + + constexpr void processed(size_t words) { + this->data_adr += words; + this->data_word_size -= words; + } + }; + + private: + Configuration config; + Reserved reserved; template - static __always_inline Configuration from(bool (*process_routine)(Configuration&, T&), const uint32_t* data_adr) { - return {reinterpret_cast(process_routine), data_adr}; + static __always_inline State from(const T& reserved, const uint32_t* data_adr, bool (*process_routine)(Configuration&, T&)) { + return {Configuration::from(process_routine, data_adr), *reinterpret_cast(&reserved)}; + static_assert(sizeof(T) <= sizeof(Reserved)); } - - constexpr void processed(size_t words) { - this->data_adr += words; - this->data_word_size -= words; + + public: + bool process(size_t word_size) { + this->config.data_word_size += word_size; + return (*this->config.process_routine)(this->config, this->reserved); } }; - private: - Configuration config; - Reserved reserved; - - template - static __always_inline State from(const T& reserved, const uint32_t* data_adr, bool (*process_routine)(Configuration&, T&)) { - return {Configuration::from(process_routine, data_adr), *reinterpret_cast(&reserved)}; - static_assert(sizeof(T) <= sizeof(Reserved)); - } - - public: - bool process(size_t word_size) { - this->config.data_word_size += word_size; - return (*this->config.process_routine)(this->config, this->reserved); - } - }; - - State create(const uint32_t* data_adr, const SimpleTIM& file); + State create(const uint32_t* data_adr, const SimpleTIM& file); + } } - #endif // !__JABYENGINE_FILE_PROCESSOR_HPP__ \ No newline at end of file diff --git a/include/PSX/File/cd_file_types.hpp b/include/PSX/File/cd_file_types.hpp index 4a5bf26f..de663eff 100644 --- a/include/PSX/File/cd_file_types.hpp +++ b/include/PSX/File/cd_file_types.hpp @@ -3,25 +3,27 @@ #include "../Overlay/overlay.hpp" #include "file_types.hpp" -enum struct CDFileType : uint8_t { - SimpleTIM = 0, - Custom -}; - -struct __no_align CDFile { - union __no_align Payload { - uint32_t empty; - SimpleTIM simple_tim; +namespace JabyEngine { + enum struct CDFileType : uint8_t { + SimpleTIM = 0, + Custom }; - uint8_t rel_lba_idx; - CDFileType type; - Payload payload; -}; + struct __no_align CDFile { + union __no_align Payload { + uint32_t empty; + SimpleTIM simple_tim; + }; -namespace CDFileBuilder { - static constexpr CDFile simple_tim(uint8_t rel_lba_idx, SimpleTIM simple_tim) { - return CDFile{.rel_lba_idx = rel_lba_idx, .type = CDFileType::SimpleTIM, .payload = {.simple_tim = simple_tim}}; + uint8_t rel_lba_idx; + CDFileType type; + Payload payload; + }; + + namespace CDFileBuilder { + static constexpr CDFile simple_tim(uint8_t rel_lba_idx, SimpleTIM simple_tim) { + return CDFile{.rel_lba_idx = rel_lba_idx, .type = CDFileType::SimpleTIM, .payload = {.simple_tim = simple_tim}}; + } } } #endif //!__JABYENGINE_CD_FILE_TYPES_HPP__ \ No newline at end of file diff --git a/include/PSX/File/file_types.hpp b/include/PSX/File/file_types.hpp index beaf1c5e..bd64755f 100644 --- a/include/PSX/File/file_types.hpp +++ b/include/PSX/File/file_types.hpp @@ -3,35 +3,35 @@ #include "../Auxiliary/complex_bitmap.hpp" #include "../jabyengine_defines.h" -struct __no_align SimpleTIM : private ComplexBitMap { - static constexpr auto TextureX = BitRange(0, 8); - static constexpr auto TextureY = BitRange(9, 16); - static constexpr auto ClutX = BitRange(17, 22); - static constexpr auto ClutY = BitRange(23, 31); +namespace JabyEngine { + struct __no_align SimpleTIM : private ComplexBitMap { + static constexpr auto TextureX = BitRange(0, 8); + static constexpr auto TextureY = BitRange(9, 16); + static constexpr auto ClutX = BitRange(17, 22); + static constexpr auto ClutY = BitRange(23, 31); - constexpr SimpleTIM() { - this->raw = 0; - } + constexpr SimpleTIM() { + this->raw = 0; + } - constexpr SimpleTIM(uint16_t texX, uint16_t texY, uint16_t clutX, uint16_t clutY) : ComplexBitMap(ComplexBitMap::with(TextureX.with(texX >> 1), TextureY.with(texY >> 1), ClutX.with(clutX >> 4), ClutY.with(clutY))) { - } + constexpr SimpleTIM(uint16_t texX, uint16_t texY, uint16_t clutX, uint16_t clutY) : ComplexBitMap(ComplexBitMap::with(TextureX.with(texX >> 1), TextureY.with(texY >> 1), ClutX.with(clutX >> 4), ClutY.with(clutY))) { + } - constexpr uint16_t getTextureX() const { - return (ComplexBitMap::get_value(SimpleTIM::TextureX) << 1); - } + constexpr uint16_t getTextureX() const { + return (ComplexBitMap::get_value(SimpleTIM::TextureX) << 1); + } - constexpr uint16_t getTextureY() const { - return (ComplexBitMap::get_value(SimpleTIM::TextureY) << 1); - } - - constexpr uint16_t getClutX() const { - return (ComplexBitMap::get_value(SimpleTIM::ClutX) << 4); - } - - constexpr uint16_t getClutY() const { - return ComplexBitMap::get_value(SimpleTIM::ClutY); - } -}; + constexpr uint16_t getTextureY() const { + return (ComplexBitMap::get_value(SimpleTIM::TextureY) << 1); + } + constexpr uint16_t getClutX() const { + return (ComplexBitMap::get_value(SimpleTIM::ClutX) << 4); + } + constexpr uint16_t getClutY() const { + return ComplexBitMap::get_value(SimpleTIM::ClutY); + } + }; +} #endif // !__JABYENGINE_FILE_TYPES_HPP__ \ No newline at end of file diff --git a/include/PSX/GPU/gpu.hpp b/include/PSX/GPU/gpu.hpp index ffe2eb47..b89b2f20 100644 --- a/include/PSX/GPU/gpu.hpp +++ b/include/PSX/GPU/gpu.hpp @@ -10,32 +10,33 @@ #endif #endif -namespace GPU { - namespace Display { - #ifdef JABYENGINE_PAL - static constexpr size_t Width = 320; - static constexpr size_t Height = 256; - #else - static constexpr size_t Width = 320; - static constexpr size_t Height = 240; - #endif +namespace JabyEngine { + namespace GPU { + namespace Display { + #ifdef JABYENGINE_PAL + static constexpr size_t Width = 320; + static constexpr size_t Height = 256; + #else + static constexpr size_t Width = 320; + static constexpr size_t Height = 240; + #endif - static void enable() { - GP1.write(Command::GP1::SetDisplayState(DisplayState::On)); + static void enable() { + GP1.write(Command::GP1::SetDisplayState(DisplayState::On)); + } + + static void disable() { + GP1.write(Command::GP1::SetDisplayState(DisplayState::Off)); + } } - static void disable() { - GP1.write(Command::GP1::SetDisplayState(DisplayState::Off)); - } - } + namespace Screen { + extern uint8_t CurrentDisplayAreaID; - namespace Screen { - extern uint8_t CurrentDisplayAreaID; - - namespace Range { - void set_offset(uint16_t x, uint16_t y); + namespace Range { + void set_offset(uint16_t x, uint16_t y); + } } } } - #endif //!__JABYENGINE_GPU_HPP__ \ No newline at end of file diff --git a/include/PSX/GPU/gpu_types.hpp b/include/PSX/GPU/gpu_types.hpp index af57f1b2..814f7370 100644 --- a/include/PSX/GPU/gpu_types.hpp +++ b/include/PSX/GPU/gpu_types.hpp @@ -3,100 +3,101 @@ #include "../jabyengine_defines.h" #include "../Auxiliary/complex_bitmap.hpp" -namespace GPU { - struct Color24 { - uint8_t red = 0; - uint8_t green = 0; - uint8_t blue = 0; +namespace JabyEngine { + namespace GPU { + struct Color24 { + uint8_t red = 0; + uint8_t green = 0; + uint8_t blue = 0; - constexpr Color24() = default; - constexpr Color24(uint8_t r, uint8_t g, uint8_t b) : blue(b), green(g), red(r) { - } + constexpr Color24() = default; + constexpr Color24(uint8_t r, uint8_t g, uint8_t b) : blue(b), green(g), red(r) { + } - constexpr uint32_t raw() const { - return ((this->blue << 16) | (this->green << 8) | this->red); - } + constexpr uint32_t raw() const { + return ((this->blue << 16) | (this->green << 8) | this->red); + } - static constexpr Color24 Black() { - return Color24(0, 0, 0); - } + static constexpr Color24 Black() { + return Color24(0, 0, 0); + } - static constexpr Color24 White() { - return Color24(0xFF, 0xFF, 0xFF); - } + static constexpr Color24 White() { + return Color24(0xFF, 0xFF, 0xFF); + } - static constexpr Color24 Red() { - return Color24(0xFF, 0x0, 0x0); - } + static constexpr Color24 Red() { + return Color24(0xFF, 0x0, 0x0); + } - static constexpr Color24 Green() { - return Color24(0x0, 0xFF, 0x0); - } + static constexpr Color24 Green() { + return Color24(0x0, 0xFF, 0x0); + } - static constexpr Color24 Blue() { - return Color24(0x0, 0x0, 0xFF); - } - }; + static constexpr Color24 Blue() { + return Color24(0x0, 0x0, 0xFF); + } + }; - class Color { - private: - static constexpr auto RedRange = BitRange::from_to(0, 4); - static constexpr auto GreenRange = BitRange::from_to(5, 9); - static constexpr auto BlueRange = BitRange::from_to(10, 14); - static constexpr auto SemiTransperancyBit = Bit(15); + class Color { + private: + static constexpr auto RedRange = BitRange::from_to(0, 4); + static constexpr auto GreenRange = BitRange::from_to(5, 9); + static constexpr auto BlueRange = BitRange::from_to(10, 14); + static constexpr auto SemiTransperancyBit = Bit(15); - ComplexBitMap value = {0}; + ComplexBitMap value = {0}; - public: - static constexpr Color from_rgb(uint8_t r, uint8_t g, uint8_t b) { - return Color().set_red(r).set_green(g).set_blue(b); - } + public: + static constexpr Color from_rgb(uint8_t r, uint8_t g, uint8_t b) { + return Color().set_red(r).set_green(g).set_blue(b); + } - static constexpr Color from(const Color24& color) { - return Color::from_rgb(color.red, color.green, color.blue); - } + static constexpr Color from(const Color24& color) { + return Color::from_rgb(color.red, color.green, color.blue); + } - constexpr Color& set_red(uint8_t red) { - this->value.set_value(static_cast(red), RedRange); - return *this; - } + constexpr Color& set_red(uint8_t red) { + this->value.set_value(static_cast(red), RedRange); + return *this; + } - constexpr Color& set_green(uint8_t green) { - this->value.set_value(static_cast(green), GreenRange); - return *this; - } + constexpr Color& set_green(uint8_t green) { + this->value.set_value(static_cast(green), GreenRange); + return *this; + } - constexpr Color& set_blue(uint8_t blue) { - this->value.set_value(static_cast(blue), BlueRange); - return *this; - } - }; + constexpr Color& set_blue(uint8_t blue) { + this->value.set_value(static_cast(blue), BlueRange); + return *this; + } + }; - template - struct Position { - T x = 0; - T y = 0; + template + struct Position { + T x = 0; + T y = 0; - constexpr Position() = default; - constexpr Position(T x, T y) : x(x), y(y) { - } - }; + constexpr Position() = default; + constexpr Position(T x, T y) : x(x), y(y) { + } + }; - template - struct Size { - T width = 0; - T height = 0; + template + struct Size { + T width = 0; + T height = 0; - constexpr Size() = default; - constexpr Size(T w, T h) : width(w), height(h) { - } - }; + constexpr Size() = default; + constexpr Size(T w, T h) : width(w), height(h) { + } + }; - typedef Position PositionI16; - typedef Position PositionU16; + typedef Position PositionI16; + typedef Position PositionU16; - typedef Size SizeI16; - typedef Size SizeU16; + typedef Size SizeI16; + typedef Size SizeU16; + } } - #endif //!__JABYENGINE_GPU_TYPES_HPP__ \ No newline at end of file diff --git a/include/PSX/Overlay/overlay.hpp b/include/PSX/Overlay/overlay.hpp index affb1ac6..8e3f6356 100644 --- a/include/PSX/Overlay/overlay.hpp +++ b/include/PSX/Overlay/overlay.hpp @@ -2,14 +2,16 @@ #define __JABYENGINE_OVERLAY__HPP__ #include "../../stdint.h" -struct __attribute__((packed)) OverlayHeader { - void (*execute)(); - uint16_t lba_size; -}; +namespace JabyEngine { + struct __attribute__((packed)) OverlayHeader { + void (*execute)(); + uint16_t lba_size; + }; -// Maybe encode attributes like "isLZ4" into size parameter -struct __attribute__((packed)) OverlayLBA { - uint16_t lba; - uint16_t size; -}; + // Maybe encode attributes like "isLZ4" into size parameter + struct __attribute__((packed)) OverlayLBA { + uint16_t lba; + uint16_t size; + }; +} #endif //!__JABYENGINE_OVERLAY__HPP__ \ No newline at end of file diff --git a/include/PSX/Overlay/overlay_declaration.hpp b/include/PSX/Overlay/overlay_declaration.hpp index 28c78fa9..0b896dd5 100644 --- a/include/PSX/Overlay/overlay_declaration.hpp +++ b/include/PSX/Overlay/overlay_declaration.hpp @@ -3,12 +3,12 @@ // No include here because this header should be included in a namespace and we don't want multiple namespace definitions of OverlayHeader and OverlayLBA -extern const OverlayHeader overlay_header; -extern const OverlayLBA overlay_lba[]; +extern const JabyEngine::OverlayHeader overlay_header; +extern const JabyEngine::OverlayLBA overlay_lba[]; #define __declare_overlay_header(function, enum_struct) \ [[gnu::used]] \ -const OverlayHeader __section(".header") overlay_header = {.execute = &function, .lba_size = static_cast(enum_struct::EndOfRequest)}; \ +const JabyEngine::OverlayHeader __section(".header") overlay_header = {.execute = &function, .lba_size = static_cast(enum_struct::EndOfRequest)}; \ [[gnu::used]] \ -const OverlayLBA __section(".header.lbas") overlay_lba[static_cast(enum_struct::EndOfRequest)] = {0} +const JabyEngine::OverlayLBA __section(".header.lbas") overlay_lba[static_cast(enum_struct::EndOfRequest)] = {0} #endif //!__JABYENGINE_OVERLAY_DECLARATION__HPP__ \ No newline at end of file diff --git a/include/PSX/System/IOPorts/dma_io.hpp b/include/PSX/System/IOPorts/dma_io.hpp index b5e30c8a..ea16e67f 100644 --- a/include/PSX/System/IOPorts/dma_io.hpp +++ b/include/PSX/System/IOPorts/dma_io.hpp @@ -2,143 +2,144 @@ #define __JABYENGINE_DMA_IO_HPP__ #include "ioport.hpp" -namespace DMA { - struct __no_align MADR : public ComplexBitMap { - __io_port_inherit_complex_bit_map(MADR); +namespace JabyEngine { + namespace DMA { + struct __no_align MADR : public ComplexBitMap { + __io_port_inherit_complex_bit_map(MADR); - static constexpr auto MemoryAdr = BitRange::from_to(0, 23); - }; - - struct __no_align BCR : public ComplexBitMap { - __io_port_inherit_complex_bit_map(BCR); - - struct __no_align SyncMode0 { - static constexpr auto NumberOfWords = BitRange::from_to(0, 15); - static constexpr auto CD_OneBlock = Bit(16); + static constexpr auto MemoryAdr = BitRange::from_to(0, 23); }; - struct __no_align SyncMode1 : public ComplexBitMap { - __io_port_inherit_complex_bit_map(SyncMode1); + struct __no_align BCR : public ComplexBitMap { + __io_port_inherit_complex_bit_map(BCR); - static constexpr auto BlockSize = BitRange::from_to(0, 15); - static constexpr auto BlockAmount = BitRange::from_to(16, 31); + struct __no_align SyncMode0 { + static constexpr auto NumberOfWords = BitRange::from_to(0, 15); + static constexpr auto CD_OneBlock = Bit(16); + }; + + struct __no_align SyncMode1 : public ComplexBitMap { + __io_port_inherit_complex_bit_map(SyncMode1); + + static constexpr auto BlockSize = BitRange::from_to(0, 15); + static constexpr auto BlockAmount = BitRange::from_to(16, 31); + }; + + struct __no_align SyncMode2 { + }; }; - struct __no_align SyncMode2 { - }; - }; + struct __no_align CHCHR : public ComplexBitMap { + __io_port_inherit_complex_bit_map(CHCHR); - struct __no_align CHCHR : public ComplexBitMap { - __io_port_inherit_complex_bit_map(CHCHR); + enum _SyncMode { + Sync0 = 0, //Start immediately, + Sync1 = 1, //Sync blocks to DMA requests + Sync2 = 2, //Linked List + }; - enum _SyncMode { - Sync0 = 0, //Start immediately, - Sync1 = 1, //Sync blocks to DMA requests - Sync2 = 2, //Linked List + static constexpr auto ManualStart = Bit(28); + + static constexpr auto Start = Bit(24); + static constexpr auto Busy = Start; + + static constexpr auto ChoppingCPUWindowSize = BitRange::from_to(20, 22); + static constexpr auto ChoppingDMAWindowSize = BitRange::from_to(16, 18); + + static constexpr auto SyncMode = BitRange<_SyncMode>::from_to(9, 10); + static constexpr auto UseSyncMode0 = SyncMode.with(Sync0); + static constexpr auto UseSyncMode1 = SyncMode.with(Sync1); + static constexpr auto UseSyncMode2 = SyncMode.with(Sync2); + + static constexpr auto UseChopping = Bit(8); + + static constexpr auto MemoryAdrDecreaseBy4 = Bit(1); + static constexpr auto MemoryAdrIncreaseBy4 = !MemoryAdrDecreaseBy4; + + static constexpr auto FromMainRAM = Bit(0); + static constexpr auto ToMainRAM = !FromMainRAM; + + static constexpr CHCHR StartMDECin() { + return ComplexBitMap{0x01000201}; + } + + static constexpr CHCHR StartMDECout() { + return ComplexBitMap{0x01000200}; + } + + static constexpr CHCHR StartGPUReceive() { + return ComplexBitMap{0x01000201}; + } + + static constexpr CHCHR StartCDROM() { + return ComplexBitMap{0x11000000}; + } + + static constexpr CHCHR StartSPUReceive() { + return ComplexBitMap{0x01000201}; + } + + static constexpr CHCHR StartOTC() { + return ComplexBitMap{0x11000002}; + } }; - static constexpr auto ManualStart = Bit(28); + struct __no_align Registers { + IOPort adr; + IOPort block_ctrl; + IOPort channel_ctrl; + }; - static constexpr auto Start = Bit(24); - static constexpr auto Busy = Start; + //0: Highest, 7: Lowest + typedef uint32_t Priority; + static constexpr Priority HighestPriority = 0; + static constexpr Priority LowestPriority = 7; - static constexpr auto ChoppingCPUWindowSize = BitRange::from_to(20, 22); - static constexpr auto ChoppingDMAWindowSize = BitRange::from_to(16, 18); + struct __no_align DMAControlRegister : public ComplexBitMap { + __io_port_inherit_complex_bit_map(DMAControlRegister); - static constexpr auto SyncMode = BitRange<_SyncMode>::from_to(9, 10); - static constexpr auto UseSyncMode0 = SyncMode.with(Sync0); - static constexpr auto UseSyncMode1 = SyncMode.with(Sync1); - static constexpr auto UseSyncMode2 = SyncMode.with(Sync2); + static constexpr auto OTCEnable = Bit(27); + static constexpr auto OTCPriority = BitRange::from_to(24, 26); - static constexpr auto UseChopping = Bit(8); + static constexpr auto PIOEnable = Bit(23); + static constexpr auto PIOPriority = BitRange::from_to(20, 22); - static constexpr auto MemoryAdrDecreaseBy4 = Bit(1); - static constexpr auto MemoryAdrIncreaseBy4 = !MemoryAdrDecreaseBy4; + static constexpr auto SPUEnable = Bit(19); + static constexpr auto SPUPriority = BitRange::from_to(16, 18); - static constexpr auto FromMainRAM = Bit(0); - static constexpr auto ToMainRAM = !FromMainRAM; + static constexpr auto CDROMEnable = Bit(15); + static constexpr auto CDROMPriority = BitRange::from_to(12, 14); - static constexpr CHCHR StartMDECin() { - return ComplexBitMap{0x01000201}; - } + static constexpr auto GPUEnable = Bit(11); + static constexpr auto GPUPriority = BitRange::from_to(8, 10); - static constexpr CHCHR StartMDECout() { - return ComplexBitMap{0x01000200}; - } + static constexpr auto MDECoutEnable = Bit(7); + static constexpr auto MDECoutPriority = BitRange::from_to(4, 6); - static constexpr CHCHR StartGPUReceive() { - return ComplexBitMap{0x01000201}; - } + static constexpr auto MDECinEnable = Bit(3); + static constexpr auto MDECinPriority = BitRange::from_to(0, 2); + }; - static constexpr CHCHR StartCDROM() { - return ComplexBitMap{0x11000000}; - } + struct __no_align DMAInterruptRegister : public ComplexBitMap { + __io_port_inherit_complex_bit_map(DMAInterruptRegister); - static constexpr CHCHR StartSPUReceive() { - return ComplexBitMap{0x01000201}; - } + static constexpr auto MasterEnable = Bit(31); + static constexpr auto Flags = BitRange::from_to(24, 30); + static constexpr auto MasterEnableDPCR = Bit(23); + static constexpr auto EnableDPCR = BitRange::from_to(16, 22); + static constexpr auto ForceIRQ = Bit(15); + }; - static constexpr CHCHR StartOTC() { - return ComplexBitMap{0x11000002}; - } - }; + __declare_io_port_global(Registers, MDECin, 0x1F801080); + __declare_io_port_global(Registers, MDECout, 0x1F801090); + __declare_io_port_global_struct(Registers, GPU, 0x1F8010A0); + __declare_io_port_global(Registers, CDROM, 0x1F8010B0); + __declare_io_port_global(Registers, SPU, 0x1F8010C0); + __declare_io_port_global(Registers, PIO, 0x1F8010D0); + __declare_io_port_global(Registers, OTC, 0x1F8010E0); - struct __no_align Registers { - IOPort adr; - IOPort block_ctrl; - IOPort channel_ctrl; - }; - - //0: Highest, 7: Lowest - typedef uint32_t Priority; - static constexpr Priority HighestPriority = 0; - static constexpr Priority LowestPriority = 7; - - struct __no_align DMAControlRegister : public ComplexBitMap { - __io_port_inherit_complex_bit_map(DMAControlRegister); - - static constexpr auto OTCEnable = Bit(27); - static constexpr auto OTCPriority = BitRange::from_to(24, 26); - - static constexpr auto PIOEnable = Bit(23); - static constexpr auto PIOPriority = BitRange::from_to(20, 22); - - static constexpr auto SPUEnable = Bit(19); - static constexpr auto SPUPriority = BitRange::from_to(16, 18); - - static constexpr auto CDROMEnable = Bit(15); - static constexpr auto CDROMPriority = BitRange::from_to(12, 14); - - static constexpr auto GPUEnable = Bit(11); - static constexpr auto GPUPriority = BitRange::from_to(8, 10); - - static constexpr auto MDECoutEnable = Bit(7); - static constexpr auto MDECoutPriority = BitRange::from_to(4, 6); - - static constexpr auto MDECinEnable = Bit(3); - static constexpr auto MDECinPriority = BitRange::from_to(0, 2); - }; - - struct __no_align DMAInterruptRegister : public ComplexBitMap { - __io_port_inherit_complex_bit_map(DMAInterruptRegister); - - static constexpr auto MasterEnable = Bit(31); - static constexpr auto Flags = BitRange::from_to(24, 30); - static constexpr auto MasterEnableDPCR = Bit(23); - static constexpr auto EnableDPCR = BitRange::from_to(16, 22); - static constexpr auto ForceIRQ = Bit(15); - }; - - __declare_io_port_global(Registers, MDECin, 0x1F801080); - __declare_io_port_global(Registers, MDECout, 0x1F801090); - __declare_io_port_global_struct(Registers, GPU, 0x1F8010A0); - __declare_io_port_global(Registers, CDROM, 0x1F8010B0); - __declare_io_port_global(Registers, SPU, 0x1F8010C0); - __declare_io_port_global(Registers, PIO, 0x1F8010D0); - __declare_io_port_global(Registers, OTC, 0x1F8010E0); - - __declare_io_port_global(DMAControlRegister, DPCR, 0x1F8010F0); - __declare_io_port_global(DMAInterruptRegister, DICR, 0x1F8010F4); + __declare_io_port_global(DMAControlRegister, DPCR, 0x1F8010F0); + __declare_io_port_global(DMAInterruptRegister, DICR, 0x1F8010F4); + } } - #endif //!__JABYENGINE_DMA_IO_HPP__ \ No newline at end of file diff --git a/include/PSX/System/IOPorts/gpu_io.hpp b/include/PSX/System/IOPorts/gpu_io.hpp index c2b92dcb..7c4d2742 100644 --- a/include/PSX/System/IOPorts/gpu_io.hpp +++ b/include/PSX/System/IOPorts/gpu_io.hpp @@ -3,170 +3,171 @@ #include "ioport.hpp" #include "../../GPU/gpu_types.hpp" -namespace GPU { - enum struct SemiTransparency { - B_Half_add_F_Half = 0, - B_add_F = 1, - B_sub_F = 2, - B_add_F_Quarter = 3, - }; - - enum struct DisplayAreaColorDepth { - $15bit = 0, - $24bit = 1, - }; - - enum struct TexturePageColor { - $4bit = 0, - $8bit = 1, - $15bit = 2, - }; - - enum struct HorizontalResolution { - $256 = 0, - $320 = 1, - $512 = 2, - $640 = 3, - }; - - enum struct VerticalResolution { - $240 = 0, - $480 = 1 - }; - - enum struct DMADirection { - Off = 0, - Fifo = 1, - CPU2GPU = 2, - GPU2CPU = 3, - }; - - enum struct DisplayState { - On = 0, - Off = 1 - }; - - namespace Command { - struct __no_align GP0 : public ComplexBitMap { - __io_port_inherit_complex_bit_map(GP0); - - static constexpr GP0 QuickFill(Color24 color) { - return ComplexBitMap{(0x02 << 24) | color.raw()}; - } - - static constexpr GP0 CPU2VRAM_Blitting() { - return ComplexBitMap{(0b101u << 29)}; - } - - static constexpr GP0 DrawAreaTemplate(uint8_t code, uint16_t x, uint16_t y) { - constexpr auto Command = BitRange::from_to(24, 31); - constexpr auto Y = BitRange::from_to(10, 18); - constexpr auto X = BitRange::from_to(0, 9); - - return ComplexBitMap::with(Command.with(code), Y.with(y), X.with(x)); - } - - static constexpr GP0 DrawAreaTopLeft(uint16_t x, uint16_t y) { - return DrawAreaTemplate(0xE3, x, y); - } - - static constexpr GP0 DrawAreaBottomRight(uint16_t x, uint16_t y) { - return DrawAreaTemplate(0xE4, x, y); - } - - static constexpr GP0 TopLeftPosition(uint16_t x, uint16_t y) { - return ComplexBitMap{static_cast((y << 16u) | x)}; - } - - static constexpr GP0 WidthHeight(uint16_t w, uint16_t h) { - return ComplexBitMap{static_cast((h << 16u) | w)}; - } +namespace JabyEngine { + namespace GPU { + enum struct SemiTransparency { + B_Half_add_F_Half = 0, + B_add_F = 1, + B_sub_F = 2, + B_add_F_Quarter = 3, }; - struct __no_align GP1 : public ComplexBitMap { - __io_port_inherit_complex_bit_map(GP1); - - static constexpr uint32_t construct_cmd(uint8_t cmd, uint32_t value) { - return ((cmd << 24) | value); - } - - static constexpr GP1 Reset() { - return ComplexBitMap{0}; - } - - static constexpr GP1 ResetCMDBufer() { - return ComplexBitMap{construct_cmd(0x01, 0)}; - } - - static constexpr GP1 SetDisplayState(DisplayState state) { - return ComplexBitMap{construct_cmd(0x03, static_cast(state))}; - } - - static constexpr GP1 DMADirection(DMADirection dir) { - return ComplexBitMap{construct_cmd(0x04, static_cast(dir))}; - } - - static constexpr GP1 DisplayArea(uint16_t x, uint16_t y) { - constexpr auto X = BitRange::from_to(0, 9); - constexpr auto Y = BitRange::from_to(10, 18); - - return ComplexBitMap{construct_cmd(0x05, ComplexBitMap::with(X.with(x), Y.with(y)).raw)}; - } - - static constexpr GP1 HorizontalDisplayRange(uint32_t x1, uint32_t x2) { - constexpr auto X1 = BitRange::from_to(0, 11); - constexpr auto X2 = BitRange::from_to(12, 23); - - return ComplexBitMap{construct_cmd(0x06, ComplexBitMap::with(X1.with(x1), X2.with(x2)).raw)}; - } - - static constexpr GP1 VerticalDisplayRange(uint32_t y1, uint32_t y2) { - constexpr auto Y1 = BitRange::from_to(0, 9); - constexpr auto Y2 = BitRange::from_to(10, 19); - - return ComplexBitMap{construct_cmd(0x07, ComplexBitMap::with(Y1.with(y1), Y2.with(y2)).raw)}; - } - - static constexpr GP1 DisplayMode(uint32_t mode) { - return ComplexBitMap{construct_cmd(0x08, mode)}; - } + enum struct DisplayAreaColorDepth { + $15bit = 0, + $24bit = 1, }; + + enum struct TexturePageColor { + $4bit = 0, + $8bit = 1, + $15bit = 2, + }; + + enum struct HorizontalResolution { + $256 = 0, + $320 = 1, + $512 = 2, + $640 = 3, + }; + + enum struct VerticalResolution { + $240 = 0, + $480 = 1 + }; + + enum struct DMADirection { + Off = 0, + Fifo = 1, + CPU2GPU = 2, + GPU2CPU = 3, + }; + + enum struct DisplayState { + On = 0, + Off = 1 + }; + + namespace Command { + struct __no_align GP0 : public ComplexBitMap { + __io_port_inherit_complex_bit_map(GP0); + + static constexpr GP0 QuickFill(Color24 color) { + return ComplexBitMap{(0x02 << 24) | color.raw()}; + } + + static constexpr GP0 CPU2VRAM_Blitting() { + return ComplexBitMap{(0b101u << 29)}; + } + + static constexpr GP0 DrawAreaTemplate(uint8_t code, uint16_t x, uint16_t y) { + constexpr auto Command = BitRange::from_to(24, 31); + constexpr auto Y = BitRange::from_to(10, 18); + constexpr auto X = BitRange::from_to(0, 9); + + return ComplexBitMap::with(Command.with(code), Y.with(y), X.with(x)); + } + + static constexpr GP0 DrawAreaTopLeft(uint16_t x, uint16_t y) { + return DrawAreaTemplate(0xE3, x, y); + } + + static constexpr GP0 DrawAreaBottomRight(uint16_t x, uint16_t y) { + return DrawAreaTemplate(0xE4, x, y); + } + + static constexpr GP0 TopLeftPosition(uint16_t x, uint16_t y) { + return ComplexBitMap{static_cast((y << 16u) | x)}; + } + + static constexpr GP0 WidthHeight(uint16_t w, uint16_t h) { + return ComplexBitMap{static_cast((h << 16u) | w)}; + } + }; + + struct __no_align GP1 : public ComplexBitMap { + __io_port_inherit_complex_bit_map(GP1); + + static constexpr uint32_t construct_cmd(uint8_t cmd, uint32_t value) { + return ((cmd << 24) | value); + } + + static constexpr GP1 Reset() { + return ComplexBitMap{0}; + } + + static constexpr GP1 ResetCMDBufer() { + return ComplexBitMap{construct_cmd(0x01, 0)}; + } + + static constexpr GP1 SetDisplayState(DisplayState state) { + return ComplexBitMap{construct_cmd(0x03, static_cast(state))}; + } + + static constexpr GP1 DMADirection(DMADirection dir) { + return ComplexBitMap{construct_cmd(0x04, static_cast(dir))}; + } + + static constexpr GP1 DisplayArea(uint16_t x, uint16_t y) { + constexpr auto X = BitRange::from_to(0, 9); + constexpr auto Y = BitRange::from_to(10, 18); + + return ComplexBitMap{construct_cmd(0x05, ComplexBitMap::with(X.with(x), Y.with(y)).raw)}; + } + + static constexpr GP1 HorizontalDisplayRange(uint32_t x1, uint32_t x2) { + constexpr auto X1 = BitRange::from_to(0, 11); + constexpr auto X2 = BitRange::from_to(12, 23); + + return ComplexBitMap{construct_cmd(0x06, ComplexBitMap::with(X1.with(x1), X2.with(x2)).raw)}; + } + + static constexpr GP1 VerticalDisplayRange(uint32_t y1, uint32_t y2) { + constexpr auto Y1 = BitRange::from_to(0, 9); + constexpr auto Y2 = BitRange::from_to(10, 19); + + return ComplexBitMap{construct_cmd(0x07, ComplexBitMap::with(Y1.with(y1), Y2.with(y2)).raw)}; + } + + static constexpr GP1 DisplayMode(uint32_t mode) { + return ComplexBitMap{construct_cmd(0x08, mode)}; + } + }; + } + + struct __no_align GPUStatusRegister : public ComplexBitMap { + static constexpr auto DrawingOddLinesInterlaced = Bit(31); + static constexpr auto DMADirectionValue = BitRange::from_to(29, 30); + static constexpr auto DMAReady = Bit(28); + static constexpr auto VRAMtoCPUtransferReay = Bit(27); + static constexpr auto GP0ReadyForCMD = Bit(26); + static constexpr auto FifoNotFull = Bit(25); // Only for Fifo + static constexpr auto InterruptRequest = Bit(24); + static constexpr auto DisplayDisabled = Bit(23); + static constexpr auto VerticalInterlaceOn = Bit(22); + static constexpr auto DisplayAreaColorDepth = BitRange::from_to(21, 21); + static constexpr auto VideoModePal = Bit(20); + static constexpr auto VerticalResolutionValue = BitRange::from_to(19, 19); + static constexpr auto HorizontalResolutionValue = BitRange::from_to(17, 18); + static constexpr auto HorizontalResolution368 = Bit(16); + static constexpr auto TexturesDisabled = Bit(15); + static constexpr auto NotDrawingMaskedPixels = Bit(12); + static constexpr auto MaskBitSetDuringDrawEnabled = Bit(11); + static constexpr auto DrawingToDisplayAreadAllowed = Bit(10); + static constexpr auto DitherEnabled = Bit(9); + static constexpr auto TexturePageColorValue = BitRange::from_to(7, 8); + static constexpr auto SemiTransparencyValue = BitRange::from_to(5, 6); + static constexpr auto TexturePageY = BitRange::from_to(4, 4); // N*256 + static constexpr auto TexturePageX = BitRange::from_to(0, 3); // N*64 + + static constexpr auto VerticalResolution480 = Bit(19); + static constexpr auto TexturePageY256 = Bit(4); + }; + + __declare_io_port_global(Command::GP0, GP0, 0x1F801810); + __declare_io_port_global(Command::GP1, GP1, 0x1F801814); + + __declare_io_port_global_const(uint32_t, GPUREAD, 0x1F801810); + __declare_io_port_global_const(GPUStatusRegister, GPUSTAT, 0x1F801814); } - - struct __no_align GPUStatusRegister : public ComplexBitMap { - static constexpr auto DrawingOddLinesInterlaced = Bit(31); - static constexpr auto DMADirectionValue = BitRange::from_to(29, 30); - static constexpr auto DMAReady = Bit(28); - static constexpr auto VRAMtoCPUtransferReay = Bit(27); - static constexpr auto GP0ReadyForCMD = Bit(26); - static constexpr auto FifoNotFull = Bit(25); // Only for Fifo - static constexpr auto InterruptRequest = Bit(24); - static constexpr auto DisplayDisabled = Bit(23); - static constexpr auto VerticalInterlaceOn = Bit(22); - static constexpr auto DisplayAreaColorDepth = BitRange::from_to(21, 21); - static constexpr auto VideoModePal = Bit(20); - static constexpr auto VerticalResolutionValue = BitRange::from_to(19, 19); - static constexpr auto HorizontalResolutionValue = BitRange::from_to(17, 18); - static constexpr auto HorizontalResolution368 = Bit(16); - static constexpr auto TexturesDisabled = Bit(15); - static constexpr auto NotDrawingMaskedPixels = Bit(12); - static constexpr auto MaskBitSetDuringDrawEnabled = Bit(11); - static constexpr auto DrawingToDisplayAreadAllowed = Bit(10); - static constexpr auto DitherEnabled = Bit(9); - static constexpr auto TexturePageColorValue = BitRange::from_to(7, 8); - static constexpr auto SemiTransparencyValue = BitRange::from_to(5, 6); - static constexpr auto TexturePageY = BitRange::from_to(4, 4); // N*256 - static constexpr auto TexturePageX = BitRange::from_to(0, 3); // N*64 - - static constexpr auto VerticalResolution480 = Bit(19); - static constexpr auto TexturePageY256 = Bit(4); - }; - - __declare_io_port_global(Command::GP0, GP0, 0x1F801810); - __declare_io_port_global(Command::GP1, GP1, 0x1F801814); - - __declare_io_port_global_const(uint32_t, GPUREAD, 0x1F801810); - __declare_io_port_global_const(GPUStatusRegister, GPUSTAT, 0x1F801814); } - #endif //!__JABYENGINE_GPU_IO_HPP__ \ No newline at end of file diff --git a/include/PSX/System/IOPorts/ioport.hpp b/include/PSX/System/IOPorts/ioport.hpp index 427b7ced..772a3589 100644 --- a/include/PSX/System/IOPorts/ioport.hpp +++ b/include/PSX/System/IOPorts/ioport.hpp @@ -2,80 +2,81 @@ #define __JABYENGINE_IOPORT_HPP__ #include "../../Auxiliary/complex_bitmap.hpp" -template -class __no_align IOPort { -private: - T value; +namespace JabyEngine { + template + class __no_align IOPort { + private: + T value; -public: - //For easy access - constexpr T read() const { - return const_cast*>(this)->value; - } + public: + //For easy access + constexpr T read() const { + return const_cast*>(this)->value; + } - constexpr void write(T value) { - const_cast*>(this)->value = value; - } + constexpr void write(T value) { + const_cast*>(this)->value = value; + } - constexpr volatile T& ref() { - return const_cast*>(this)->value; - } + constexpr volatile T& ref() { + return const_cast*>(this)->value; + } - constexpr const volatile T& ref() const { - return const_cast*>(this)->value; - } -}; + constexpr const volatile T& ref() const { + return const_cast*>(this)->value; + } + }; -struct __no_align ubus32_t { - ComplexBitMap low; - ComplexBitMap high; + struct __no_align ubus32_t { + ComplexBitMap low; + ComplexBitMap high; - constexpr ubus32_t(uint32_t value) { - *this = value; - } + constexpr ubus32_t(uint32_t value) { + *this = value; + } - constexpr operator uint32_t() const { - return ((this->high.raw << 16) | this->low.raw); - } + constexpr operator uint32_t() const { + return ((this->high.raw << 16) | this->low.raw); + } - operator uint32_t() const volatile { - return ((this->high.raw << 16) | this->low.raw); - } + operator uint32_t() const volatile { + return ((this->high.raw << 16) | this->low.raw); + } - constexpr ubus32_t& operator=(uint32_t value) { - this->low.raw = (value & 0xFFFF); - this->high.raw = (value >> 16); + constexpr ubus32_t& operator=(uint32_t value) { + this->low.raw = (value & 0xFFFF); + this->high.raw = (value >> 16); - return *this; - } + return *this; + } - constexpr void operator=(uint32_t value) volatile { - this->low.raw = (value & 0xFFFF); - this->high.raw = (value >> 16); - } -}; -static constexpr uintptr_t IO_Base_Mask = 0xF0000000; -static constexpr uintptr_t IO_Base_Adr = 0x10000000; + constexpr void operator=(uint32_t value) volatile { + this->low.raw = (value & 0xFFFF); + this->high.raw = (value >> 16); + } + }; + static constexpr uintptr_t IO_Base_Mask = 0xF0000000; + static constexpr uintptr_t IO_Base_Adr = 0x10000000; -#define __io_port_adr(adr) (IO_Base_Adr + (adr & ~IO_Base_Mask)) -#define __declare_io_port_global_raw(cv, type, name, adr) static __always_inline cv auto& name = *reinterpret_cast*>(__io_port_adr(adr)) + #define __io_port_adr(adr) (IO_Base_Adr + (adr & ~IO_Base_Mask)) + #define __declare_io_port_global_raw(cv, type, name, adr) static __always_inline cv auto& name = *reinterpret_cast*>(__io_port_adr(adr)) -#define __declare_io_port_global(type, name, adr) __declare_io_port_global_raw(, 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(*reinterpret_cast((IO_Base_Adr + (adr & ~IO_Base_Mask)))) -#define __declare_io_port_global_struct(type, name, adr) static __always_inline auto& name = *reinterpret_cast(__io_port_adr(adr)) - -#define __io_port_inherit_complex_bit_map(name) \ - constexpr __always_inline name() = default; \ - constexpr __always_inline name(ComplexBitMap value) : ComplexBitMap(value) { \ - } \ - template \ - static constexpr __always_inline name with(ARGS...args) { \ - return {ComplexBitMap::with(args...)}; \ - }\ - template \ - constexpr void __always_inline operator=(ComplexBitMap value) volatile { \ - this->raw = value.raw; \ - } + #define __declare_io_port_global(type, name, adr) __declare_io_port_global_raw(, 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(*reinterpret_cast((IO_Base_Adr + (adr & ~IO_Base_Mask)))) + #define __declare_io_port_global_struct(type, name, adr) static __always_inline auto& name = *reinterpret_cast(__io_port_adr(adr)) + #define __io_port_inherit_complex_bit_map(name) \ + constexpr __always_inline name() = default; \ + constexpr __always_inline name(ComplexBitMap value) : ComplexBitMap(value) { \ + } \ + template \ + static constexpr __always_inline name with(ARGS...args) { \ + return {ComplexBitMap::with(args...)}; \ + }\ + template \ + constexpr void __always_inline operator=(ComplexBitMap value) volatile { \ + this->raw = value.raw; \ + } +} #endif //!__JABYENGINE_IOPORT_HPP__ \ No newline at end of file diff --git a/include/PSX/System/IOPorts/spu_io.hpp b/include/PSX/System/IOPorts/spu_io.hpp index 18b36ee1..650186bf 100644 --- a/include/PSX/System/IOPorts/spu_io.hpp +++ b/include/PSX/System/IOPorts/spu_io.hpp @@ -2,168 +2,169 @@ #define __JABYENGINE_SPU_IO_HPP__ #include "ioport.hpp" -namespace SPU { - enum struct Mode { - Linear = 0, - Exponential = 1, - }; - - enum struct Direction { - Increase = 0, - Decrease = 1, - }; - - enum struct Phase { - Posititve = 0, - Negative = 1, - }; - - //0..0x1F = Fast..Slow - typedef uint8_t Shift; - - //0..3 = +7, +6, +5, +4 or -6, -7, -6, -5 - typedef uint8_t Step; - - typedef int16_t SimpleVolume; - - struct __no_align SampleRate : public ComplexBitMap { - __io_port_inherit_complex_bit_map(SampleRate); - - static constexpr SampleRate from_HZ(double freq) { - //4096 == 44100Hz - constexpr double Base = (4096.0 / 44100.0); - - return ComplexBitMap{static_cast((freq*Base))}; - } - }; - - struct __no_align SweepVolume : public ComplexBitMap { - __io_port_inherit_complex_bit_map(SweepVolume); - - // For Volume Mode - static constexpr auto SweepEnable = Bit(15); - static constexpr auto VolumeEnable = !SweepEnable; - static constexpr auto Volume = BitRange::from_to(0, 14); - - // For Sweep Mode - static constexpr auto SweepMode = Bit(14); - static constexpr auto SweepDirection = Bit(13); - static constexpr auto SweepPhase = Bit(12); - static constexpr auto SweepShift = BitRange::from_to(2, 6); - static constexpr auto SweepStep = BitRange::from_to(0, 1); - }; - - struct __no_align SR : public ComplexBitMap { - __io_port_inherit_complex_bit_map(SR); - - static constexpr auto SustainMode = Bit(31 - 16); - static constexpr auto SustainDirection = Bit(30 - 16); - static constexpr auto SustainShift = BitRange::from_to((24 - 16), (28 - 16)); - static constexpr auto SustainStep = BitRange::from_to((22 - 16), (23 - 16)); - static constexpr auto ReleaseMode = Bit(21 - 16); - static constexpr auto ReleaseShift = BitRange::from_to((16 - 16), (20 - 16)); - }; - - struct __no_align AD : public ComplexBitMap { - __io_port_inherit_complex_bit_map(AD); - - static constexpr auto AttackMode = Bit(15); - static constexpr auto AttackShift = BitRange::from_to(10, 14); - static constexpr auto AttackStep = BitRange::from_to(8, 9); - static constexpr auto DecayShift = BitRange::from_to(4, 7); - static constexpr auto SustainLevel = BitRange::from_to(0, 3); - }; - - struct __no_align Voice { - IOPort volumeLeft; //Offset: 0x0 - IOPort volumeRight; //Offset: 0x2 - IOPort sampleRate; //Offset: 0x4; - IOPort adr; //Offset: 0x6 - IOPort ad; //Offset: 0x8 - IOPort sr; //Offset: 0xA - IOPort currentVolume; //Offset: 0xC - IOPort repeatAdr; //Offset: 0xE - }; - - struct __no_align ControlRegister : public ComplexBitMap { - __io_port_inherit_complex_bit_map(ControlRegister); - - enum RAMTransferMode { - Stop = 0, - ManualWrite = 1, - DMAWrite = 2, - DMARead = 3 +namespace JabyEngine { + namespace SPU { + enum struct Mode { + Linear = 0, + Exponential = 1, }; - static constexpr auto Enable = Bit(15); - static constexpr auto Unmute = Bit(14); - static constexpr auto NoiseFrequcenyShift = BitRange::from_to(10, 13); - static constexpr auto NoiseFrequcenyStep = BitRange::from_to(8, 9); - static constexpr auto ReverbMasterEnable = Bit(7); - static constexpr auto IRQ9Enable = Bit(6); - static constexpr auto TransferMode = BitRange::from_to(4, 5); - static constexpr auto ExternalAudioReverb = Bit(3); - static constexpr auto CDAudioReverb = Bit(2); - static constexpr auto ExternalAudioEnable = Bit(1); - static constexpr auto CDAudioEnable = Bit(0); - }; + enum struct Direction { + Increase = 0, + Decrease = 1, + }; - struct __no_align PitchModFlags : public ComplexBitMap { - __io_port_inherit_complex_bit_map(PitchModFlags); + enum struct Phase { + Posititve = 0, + Negative = 1, + }; - static constexpr BitRange EnableBits = BitRange::from_to(1, 23); - }; + //0..0x1F = Fast..Slow + typedef uint8_t Shift; - struct __no_align NoiseGenerator : public ComplexBitMap { - __io_port_inherit_complex_bit_map(NoiseGenerator); + //0..3 = +7, +6, +5, +4 or -6, -7, -6, -5 + typedef uint8_t Step; - static constexpr BitRange NoiseBits = BitRange::from_to(0, 23); - }; + typedef int16_t SimpleVolume; - struct __no_align EchoOn : public ComplexBitMap { - __io_port_inherit_complex_bit_map(EchoOn); + struct __no_align SampleRate : public ComplexBitMap { + __io_port_inherit_complex_bit_map(SampleRate); - static constexpr BitRange EchoBits = BitRange::from_to(0, 23); - }; + static constexpr SampleRate from_HZ(double freq) { + //4096 == 44100Hz + constexpr double Base = (4096.0 / 44100.0); - static constexpr size_t VoiceCount = 24; + return ComplexBitMap{static_cast((freq*Base))}; + } + }; - namespace Key { - __declare_io_port_global(ubus32_t, on, 0x1F801D88); - __declare_io_port_global(ubus32_t, off, 0x1F801D8C); - __declare_io_port_global(ubus32_t, status, 0x1F801D9C); - } + struct __no_align SweepVolume : public ComplexBitMap { + __io_port_inherit_complex_bit_map(SweepVolume); - namespace MainVolume { - __declare_io_port_global(SweepVolume, left, 0x1F801D80); - __declare_io_port_global(SweepVolume, right, 0x1F801D82); - } + // For Volume Mode + static constexpr auto SweepEnable = Bit(15); + static constexpr auto VolumeEnable = !SweepEnable; + static constexpr auto Volume = BitRange::from_to(0, 14); - namespace CDVolume { - __declare_io_port_global(SimpleVolume, left, 0x1F801DB0); - __declare_io_port_global(SimpleVolume, right, 0x1F801DB2); - } + // For Sweep Mode + static constexpr auto SweepMode = Bit(14); + static constexpr auto SweepDirection = Bit(13); + static constexpr auto SweepPhase = Bit(12); + static constexpr auto SweepShift = BitRange::from_to(2, 6); + static constexpr auto SweepStep = BitRange::from_to(0, 1); + }; - namespace ExternalAudioInputVolume { - __declare_io_port_global(SimpleVolume, left, 0x1F801DB4); - __declare_io_port_global(SimpleVolume, right, 0x1F801DB6); - } + struct __no_align SR : public ComplexBitMap { + __io_port_inherit_complex_bit_map(SR); + + static constexpr auto SustainMode = Bit(31 - 16); + static constexpr auto SustainDirection = Bit(30 - 16); + static constexpr auto SustainShift = BitRange::from_to((24 - 16), (28 - 16)); + static constexpr auto SustainStep = BitRange::from_to((22 - 16), (23 - 16)); + static constexpr auto ReleaseMode = Bit(21 - 16); + static constexpr auto ReleaseShift = BitRange::from_to((16 - 16), (20 - 16)); + }; - namespace Reverb { - namespace Volume { - __declare_io_port_global(SimpleVolume, left, 0x1F801D84); - __declare_io_port_global(SimpleVolume, right, 0x1F801D86); + struct __no_align AD : public ComplexBitMap { + __io_port_inherit_complex_bit_map(AD); + + static constexpr auto AttackMode = Bit(15); + static constexpr auto AttackShift = BitRange::from_to(10, 14); + static constexpr auto AttackStep = BitRange::from_to(8, 9); + static constexpr auto DecayShift = BitRange::from_to(4, 7); + static constexpr auto SustainLevel = BitRange::from_to(0, 3); + }; + + struct __no_align Voice { + IOPort volumeLeft; //Offset: 0x0 + IOPort volumeRight; //Offset: 0x2 + IOPort sampleRate; //Offset: 0x4; + IOPort adr; //Offset: 0x6 + IOPort ad; //Offset: 0x8 + IOPort sr; //Offset: 0xA + IOPort currentVolume; //Offset: 0xC + IOPort repeatAdr; //Offset: 0xE + }; + + struct __no_align ControlRegister : public ComplexBitMap { + __io_port_inherit_complex_bit_map(ControlRegister); + + enum RAMTransferMode { + Stop = 0, + ManualWrite = 1, + DMAWrite = 2, + DMARead = 3 + }; + + static constexpr auto Enable = Bit(15); + static constexpr auto Unmute = Bit(14); + static constexpr auto NoiseFrequcenyShift = BitRange::from_to(10, 13); + static constexpr auto NoiseFrequcenyStep = BitRange::from_to(8, 9); + static constexpr auto ReverbMasterEnable = Bit(7); + static constexpr auto IRQ9Enable = Bit(6); + static constexpr auto TransferMode = BitRange::from_to(4, 5); + static constexpr auto ExternalAudioReverb = Bit(3); + static constexpr auto CDAudioReverb = Bit(2); + static constexpr auto ExternalAudioEnable = Bit(1); + static constexpr auto CDAudioEnable = Bit(0); + }; + + struct __no_align PitchModFlags : public ComplexBitMap { + __io_port_inherit_complex_bit_map(PitchModFlags); + + static constexpr BitRange EnableBits = BitRange::from_to(1, 23); + }; + + struct __no_align NoiseGenerator : public ComplexBitMap { + __io_port_inherit_complex_bit_map(NoiseGenerator); + + static constexpr BitRange NoiseBits = BitRange::from_to(0, 23); + }; + + struct __no_align EchoOn : public ComplexBitMap { + __io_port_inherit_complex_bit_map(EchoOn); + + static constexpr BitRange EchoBits = BitRange::from_to(0, 23); + }; + + static constexpr size_t VoiceCount = 24; + + namespace Key { + __declare_io_port_global(ubus32_t, on, 0x1F801D88); + __declare_io_port_global(ubus32_t, off, 0x1F801D8C); + __declare_io_port_global(ubus32_t, status, 0x1F801D9C); } - __declare_io_port_global(uint16_t, work_area_adr, 0x1F801DA2); + + namespace MainVolume { + __declare_io_port_global(SweepVolume, left, 0x1F801D80); + __declare_io_port_global(SweepVolume, right, 0x1F801D82); + } + + namespace CDVolume { + __declare_io_port_global(SimpleVolume, left, 0x1F801DB0); + __declare_io_port_global(SimpleVolume, right, 0x1F801DB2); + } + + namespace ExternalAudioInputVolume { + __declare_io_port_global(SimpleVolume, left, 0x1F801DB4); + __declare_io_port_global(SimpleVolume, right, 0x1F801DB6); + } + + namespace Reverb { + namespace Volume { + __declare_io_port_global(SimpleVolume, left, 0x1F801D84); + __declare_io_port_global(SimpleVolume, right, 0x1F801D86); + } + __declare_io_port_global(uint16_t, work_area_adr, 0x1F801DA2); + } + + __declare_io_port_global(ControlRegister, Control, 0x1F801DAA); + __declare_io_port_global(uint16_t, DataTransferControl, 0x1F801DAC); + __declare_io_port_global(PitchModFlags, PMON, 0x1F801D90); + __declare_io_port_global(NoiseGenerator, NON, 0x1F801D94); + __declare_io_port_global(EchoOn, EON, 0x1F801D98); + + __declare_io_port_global_array(Voice, Voices, 0x1F801C00, VoiceCount); } - - __declare_io_port_global(ControlRegister, Control, 0x1F801DAA); - __declare_io_port_global(uint16_t, DataTransferControl, 0x1F801DAC); - __declare_io_port_global(PitchModFlags, PMON, 0x1F801D90); - __declare_io_port_global(NoiseGenerator, NON, 0x1F801D94); - __declare_io_port_global(EchoOn, EON, 0x1F801D98); - - __declare_io_port_global_array(Voice, Voices, 0x1F801C00, VoiceCount); } - #endif //!__JABYENGINE_SPU_IO_HPP__ \ No newline at end of file diff --git a/include/PSX/System/scratchpad.hpp b/include/PSX/System/scratchpad.hpp index dccde06e..4d1886aa 100644 --- a/include/PSX/System/scratchpad.hpp +++ b/include/PSX/System/scratchpad.hpp @@ -2,6 +2,7 @@ #define __JABYENGINE_SCRATCHPAD_HPP__ #include "../jabyengine_defines.h" -static __always_inline auto& ScratchPad = reinterpret_cast(*reinterpret_cast(0x1F800000)); - +namespace JabyEngine { + static __always_inline auto& ScratchPad = reinterpret_cast(*reinterpret_cast(0x1F800000)); +} #endif //!__JABYENGINE_SCRATCHPAD_HPP__ \ No newline at end of file diff --git a/include/PSX/jabyengine.h b/include/PSX/jabyengine.hpp similarity index 90% rename from include/PSX/jabyengine.h rename to include/PSX/jabyengine.hpp index a8509581..867d8f16 100644 --- a/include/PSX/jabyengine.h +++ b/include/PSX/jabyengine.hpp @@ -1,5 +1,5 @@ -#ifndef __JABYENGINE__H__ -#define __JABYENGINE__H__ +#ifndef __JABYENGINE__HPP__ +#define __JABYENGINE__HPP__ #include "../stdint.h" namespace JabyEngine { @@ -33,4 +33,4 @@ namespace JabyEngine { typedef NextRoutine::MainRoutine MainRoutine; } -#endif //!__JABYENGINE__H__ \ No newline at end of file +#endif //!__JABYENGINE__HPP__ \ No newline at end of file diff --git a/src/Library/include/BootLoader/boot_loader.hpp b/src/Library/include/BootLoader/boot_loader.hpp index 560e48e0..8bc018e9 100644 --- a/src/Library/include/BootLoader/boot_loader.hpp +++ b/src/Library/include/BootLoader/boot_loader.hpp @@ -1,23 +1,24 @@ #ifndef BOOT_LOADER_HPP #define BOOT_LOADER_HPP -#include +#include -namespace GPU { - void display_logo(); - void setup(); +namespace JabyEngine { + namespace GPU { + void display_logo(); + void setup(); + } + + namespace SPU { + void stop_voices(); + void setup(); + } + + namespace Setup { + JabyEngine::NextRoutine start(); + } + + namespace BootFile { + JabyEngine::NextRoutine setup(); + } } - -namespace SPU { - void stop_voices(); - void setup(); -} - -namespace Setup { - JabyEngine::NextRoutine start(); -} - -namespace BootFile { - JabyEngine::NextRoutine setup(); -} - #endif //!BOOT_LOADER_HPP \ No newline at end of file diff --git a/src/Library/include/CD/cd.hpp b/src/Library/include/CD/cd.hpp index 27a8e3d6..57868489 100644 --- a/src/Library/include/CD/cd.hpp +++ b/src/Library/include/CD/cd.hpp @@ -2,17 +2,18 @@ #define __JABYENGINE_CD_HPP__ #include -namespace CD { - namespace CircularBuffer { - extern uint8_t* write_ptr; - extern uint8_t* read_ptr; - extern uint8_t* end_ptr; +namespace JabyEngine { + namespace CD { + namespace CircularBuffer { + extern uint8_t* write_ptr; + extern uint8_t* read_ptr; + extern uint8_t* end_ptr; + } + + enum struct State { + }; + + extern State state; } - - enum struct State { - }; - - extern State state; } - #endif //!__JABYENGINE_CD_HPP__ \ No newline at end of file diff --git a/src/Library/include/GPU/gpu.hpp b/src/Library/include/GPU/gpu.hpp index 6092211a..aa947ef8 100644 --- a/src/Library/include/GPU/gpu.hpp +++ b/src/Library/include/GPU/gpu.hpp @@ -4,111 +4,113 @@ #include #include -namespace GPU { - namespace Screen { - struct Mode { - enum struct TVEncoding { - NTSC = 0, - PAL = 1, +namespace JabyEngine { + namespace GPU { + namespace Screen { + struct Mode { + enum struct TVEncoding { + NTSC = 0, + PAL = 1, + }; + + static constexpr auto HorizontalResolution368 = Bit(6); + static constexpr auto VerticalInterlace = Bit(5); + static constexpr auto DisplayAreaColorDepth = BitRange::from_to(4, 4); + static constexpr auto VideoMode = BitRange::from_to(3, 3); + static constexpr auto VerticalResolution = BitRange::from_to(2, 2); + static constexpr auto HorizontalResolution = BitRange::from_to(0, 1); + + static constexpr uint32_t PAL() { + return ComplexBitMap::with( + Mode::HorizontalResolution.with(GPU::HorizontalResolution::$320), + Mode::VerticalResolution.with(GPU::VerticalResolution::$240), + Mode::VideoMode.with(TVEncoding::PAL), + Mode::DisplayAreaColorDepth.with(GPU::DisplayAreaColorDepth::$15bit) + ).raw; + } + + static constexpr uint32_t NTSC() { + return ComplexBitMap::with( + Mode::HorizontalResolution.with(GPU::HorizontalResolution::$320), + Mode::VerticalResolution.with(GPU::VerticalResolution::$240), + Mode::VideoMode.with(TVEncoding::NTSC), + Mode::DisplayAreaColorDepth.with(GPU::DisplayAreaColorDepth::$15bit) + ).raw; + } }; - static constexpr auto HorizontalResolution368 = Bit(6); - static constexpr auto VerticalInterlace = Bit(5); - static constexpr auto DisplayAreaColorDepth = BitRange::from_to(4, 4); - static constexpr auto VideoMode = BitRange::from_to(3, 3); - static constexpr auto VerticalResolution = BitRange::from_to(2, 2); - static constexpr auto HorizontalResolution = BitRange::from_to(0, 1); + static void configurate() { + static constexpr uint16_t FirstVisiblePixelH = 0x260; - static constexpr uint32_t PAL() { - return ComplexBitMap::with( - Mode::HorizontalResolution.with(GPU::HorizontalResolution::$320), - Mode::VerticalResolution.with(GPU::VerticalResolution::$240), - Mode::VideoMode.with(TVEncoding::PAL), - Mode::DisplayAreaColorDepth.with(GPU::DisplayAreaColorDepth::$15bit) - ).raw; + #ifdef JABYENGINE_PAL + static constexpr uint16_t FirstVisiblePixelV = 0xA3; + + GP1.write(Command::GP1::DisplayMode(Mode::PAL())); + GPU::Screen::Range::set_offset(0, 0); + #else + static constexpr uint16_t FirstVisiblePixelV = 0x88; + + GP1.write(Command::GP1::DisplayMode(Mode::NTSC())); + GPU::Screen::set_offset(0, 5); //< Random values + #endif } - static constexpr uint32_t NTSC() { - return ComplexBitMap::with( - Mode::HorizontalResolution.with(GPU::HorizontalResolution::$320), - Mode::VerticalResolution.with(GPU::VerticalResolution::$240), - Mode::VideoMode.with(TVEncoding::NTSC), - Mode::DisplayAreaColorDepth.with(GPU::DisplayAreaColorDepth::$15bit) - ).raw; + void exchange_buffer_and_display(); + } + + static void set_draw_area(uint16_t x, uint16_t y) { + GP0.write(Command::GP0::DrawAreaTopLeft(x, y)); + GP0.write(Command::GP0::DrawAreaBottomRight((x + Display::Width), (y + Display::Height))); + } + + static void quick_fill_fast(const Color24& color, const PositionU16& pos, const SizeU16& size) { + GP0.write(Command::GP0::QuickFill(color)); + GP0.write(Command::GP0::TopLeftPosition(pos.x, pos.y)); + GP0.write(Command::GP0::WidthHeight(size.width, size.height)); + } + + static void reset_cmd_buffer() { + GP1.write(Command::GP1::ResetCMDBufer()); + } + + static void wait_ready_for_CMD() { + while(!GPUSTAT.ref().is(GPUStatusRegister::GP0ReadyForCMD)); + } + + namespace DMA { + static void wait() { + while(::JabyEngine::DMA::GPU.channel_ctrl.ref().is(::JabyEngine::DMA::CHCHR::Busy)); } - }; - static void configurate() { - static constexpr uint16_t FirstVisiblePixelH = 0x260; - - #ifdef JABYENGINE_PAL - static constexpr uint16_t FirstVisiblePixelV = 0xA3; - - GP1.write(Command::GP1::DisplayMode(Mode::PAL())); - GPU::Screen::Range::set_offset(0, 0); - #else - static constexpr uint16_t FirstVisiblePixelV = 0x88; - - GP1.write(Command::GP1::DisplayMode(Mode::NTSC())); - GPU::Screen::set_offset(0, 5); //< Random values - #endif - } - - void exchange_buffer_and_display(); - } - - static void set_draw_area(uint16_t x, uint16_t y) { - GP0.write(Command::GP0::DrawAreaTopLeft(x, y)); - GP0.write(Command::GP0::DrawAreaBottomRight((x + Display::Width), (y + Display::Height))); - } - - static void quick_fill_fast(const Color24& color, const PositionU16& pos, const SizeU16& size) { - GP0.write(Command::GP0::QuickFill(color)); - GP0.write(Command::GP0::TopLeftPosition(pos.x, pos.y)); - GP0.write(Command::GP0::WidthHeight(size.width, size.height)); - } - - static void reset_cmd_buffer() { - GP1.write(Command::GP1::ResetCMDBufer()); - } - - static void wait_ready_for_CMD() { - while(!GPUSTAT.ref().is(GPUStatusRegister::GP0ReadyForCMD)); - } - - namespace DMA { - static void wait() { - while(::DMA::GPU.channel_ctrl.ref().is(::DMA::CHCHR::Busy)); - } - - static void end() { - reset_cmd_buffer(); - } - - namespace Receive { - static void prepare() - { - GP1.write(Command::GP1::DMADirection(DMADirection::CPU2GPU)); + static void end() { reset_cmd_buffer(); } - static void set_src(uintptr_t adr) { - ::DMA::GPU.adr.ref().set_value(static_cast(adr), ::DMA::MADR::MemoryAdr); - } + namespace Receive { + static void prepare() + { + GP1.write(Command::GP1::DMADirection(DMADirection::CPU2GPU)); + reset_cmd_buffer(); + } - static void set_dst(const PositionU16& position, const SizeU16& size) { + static void set_src(uintptr_t adr) { + ::JabyEngine::DMA::GPU.adr.ref().set_value(static_cast(adr), ::JabyEngine::DMA::MADR::MemoryAdr); + } - wait_ready_for_CMD(); - GP0.write(Command::GP0::CPU2VRAM_Blitting()); - GP0.write(Command::GP0::TopLeftPosition(position.x, position.y)); - GP0.write(Command::GP0::WidthHeight(size.width, size.height)); - } + static void set_dst(const PositionU16& position, const SizeU16& size) { - static void start(uint16_t blockCount, uint16_t wordsPerBlock = 0x10) { - typedef ::DMA::BCR::SyncMode1 SyncMode1; + wait_ready_for_CMD(); + GP0.write(Command::GP0::CPU2VRAM_Blitting()); + GP0.write(Command::GP0::TopLeftPosition(position.x, position.y)); + GP0.write(Command::GP0::WidthHeight(size.width, size.height)); + } - ::DMA::GPU.block_ctrl.write(SyncMode1::with(SyncMode1::BlockSize.with(wordsPerBlock), SyncMode1::BlockAmount.with(blockCount))); - ::DMA::GPU.channel_ctrl.write(::DMA::CHCHR::StartGPUReceive()); + static void start(uint16_t blockCount, uint16_t wordsPerBlock = 0x10) { + typedef ::JabyEngine::DMA::BCR::SyncMode1 SyncMode1; + + ::JabyEngine::DMA::GPU.block_ctrl.write(SyncMode1::with(SyncMode1::BlockSize.with(wordsPerBlock), SyncMode1::BlockAmount.with(blockCount))); + ::JabyEngine::DMA::GPU.channel_ctrl.write(::JabyEngine::DMA::CHCHR::StartGPUReceive()); + } } } } diff --git a/src/Library/src/BootLoader/boot_file/main_boot.cpp b/src/Library/src/BootLoader/boot_file/main_boot.cpp index 9d87d864..b13f64b2 100644 --- a/src/Library/src/BootLoader/boot_file/main_boot.cpp +++ b/src/Library/src/BootLoader/boot_file/main_boot.cpp @@ -3,9 +3,11 @@ extern JabyEngine::NextRoutine main(); -namespace BootFile { - JabyEngine::NextRoutine setup() { - printf("Running main!\n"); - return JabyEngine::NextRoutine::from(main); +namespace JabyEngine { + namespace BootFile { + JabyEngine::NextRoutine setup() { + printf("Running main!\n"); + return JabyEngine::NextRoutine::from(main); + } } } \ No newline at end of file diff --git a/src/Library/src/BootLoader/boot_file/overlay_boot.cpp b/src/Library/src/BootLoader/boot_file/overlay_boot.cpp index 878f6bff..9276b5e6 100644 --- a/src/Library/src/BootLoader/boot_file/overlay_boot.cpp +++ b/src/Library/src/BootLoader/boot_file/overlay_boot.cpp @@ -1,9 +1,11 @@ #include "../../../include/BootLoader/boot_loader.hpp" #include -namespace BootFile { - JabyEngine::NextRoutine setup() { - printf("Overlay boot not implemented!\n"); - return JabyEngine::NextRoutine::null(); +namespace JabyEngine { + namespace BootFile { + JabyEngine::NextRoutine setup() { + printf("Overlay boot not implemented!\n"); + return JabyEngine::NextRoutine::null(); + } } } \ No newline at end of file diff --git a/src/Library/src/BootLoader/gpu_boot.cpp b/src/Library/src/BootLoader/gpu_boot.cpp index dd0d9841..12e91b52 100644 --- a/src/Library/src/BootLoader/gpu_boot.cpp +++ b/src/Library/src/BootLoader/gpu_boot.cpp @@ -8,21 +8,23 @@ #include "splash_image_ntsc_boot.hpp" #endif //JABYENGINE_PAL -namespace GPU { - void display_logo() { - // Upload SplashScreen picture - auto state = FileProcessor::create(reinterpret_cast(SplashScreen), SimpleTIM(32, 0, 0, 0)); - while(state.process((sizeof(SplashScreen)/sizeof(uint32_t)))); +namespace JabyEngine { + namespace GPU { + void display_logo() { + // Upload SplashScreen picture + auto state = FileProcessor::create(reinterpret_cast(SplashScreen), SimpleTIM(32, 0, 0, 0)); + while(state.process((sizeof(SplashScreen)/sizeof(uint32_t)))); - Display::enable(); - } + Display::enable(); + } - void setup() { - GP1.write(Command::GP1::Reset()); - Screen::configurate(); - Screen::exchange_buffer_and_display(); - - GPU::wait_ready_for_CMD(); - quick_fill_fast(Color24::Black(), PositionU16(32, 0), SizeU16(Display::Width, Display::Height)); + void setup() { + GP1.write(Command::GP1::Reset()); + Screen::configurate(); + Screen::exchange_buffer_and_display(); + + GPU::wait_ready_for_CMD(); + quick_fill_fast(Color24::Black(), PositionU16(32, 0), SizeU16(Display::Width, Display::Height)); + } } } \ No newline at end of file diff --git a/src/Library/src/BootLoader/spu_boot.cpp b/src/Library/src/BootLoader/spu_boot.cpp index 723550fb..37b98a7f 100644 --- a/src/Library/src/BootLoader/spu_boot.cpp +++ b/src/Library/src/BootLoader/spu_boot.cpp @@ -2,94 +2,98 @@ #include #include -namespace SPU { - static void clear_main_volume() { - static constexpr auto StartVol = SweepVolume::with(SweepVolume::VolumeEnable, SweepVolume::Volume.with(I16_MAX >> 2)); - - MainVolume::left.write(StartVol); - MainVolume::right.write(StartVol); - } - - static void clear_cd_and_ext_audio_volume() { - CDVolume::left.write(0); - CDVolume::right.write(0); - - ExternalAudioInputVolume::left.write(0); - ExternalAudioInputVolume::right.write(0); - } - - static void clear_control_register() { - Control.write(ControlRegister()); - } - - static void clear_voice() { - for(auto& voice : Voices) { - voice.volumeLeft.write(SweepVolume()); - voice.volumeRight.write(SweepVolume()); - voice.sampleRate.write(SampleRate()); - voice.ad.write(AD()); - voice.sr.write(SR()); - voice.currentVolume.write(SimpleVolume(0)); - - voice.adr.write(0x200); - voice.repeatAdr.write(0x200); - } - } - - static void clear_pmon() { - PMON.write(PitchModFlags()); - } - - static void clear_noise_and_echo() { - NON.write(NoiseGenerator()); - EON.write(EchoOn()); - } - - static void clear_reverb() { - Reverb::Volume::left.write(0); - Reverb::Volume::right.write(0); - Reverb::work_area_adr.write(0); - } - - static void setup_control_register() { - static constexpr auto SetupValue = ControlRegister::with(ControlRegister::Enable, ControlRegister::Unmute, ControlRegister::CDAudioEnable); - - Control.write(SetupValue); - } - - static void setup_data_transfer_control() { - static constexpr uint16_t RequiredValue = (2 << 1); +namespace JabyEngine { + namespace SPU { + using namespace JabyEngine; - DataTransferControl.write(RequiredValue); - } + static void clear_main_volume() { + static constexpr auto StartVol = SweepVolume::with(SweepVolume::VolumeEnable, SweepVolume::Volume.with(I16_MAX >> 2)); - static void wait_voices() { - static constexpr int16_t Treshhold = (I16_MAX*0.03); + MainVolume::left.write(StartVol); + MainVolume::right.write(StartVol); + } - try_again: - for(const auto& voice : Voices) { - if(voice.currentVolume.read() > Treshhold) { - goto try_again; + static void clear_cd_and_ext_audio_volume() { + CDVolume::left.write(0); + CDVolume::right.write(0); + + ExternalAudioInputVolume::left.write(0); + ExternalAudioInputVolume::right.write(0); + } + + static void clear_control_register() { + Control.write(ControlRegister()); + } + + static void clear_voice() { + for(auto& voice : Voices) { + voice.volumeLeft.write(SweepVolume()); + voice.volumeRight.write(SweepVolume()); + voice.sampleRate.write(SampleRate()); + voice.ad.write(AD()); + voice.sr.write(SR()); + voice.currentVolume.write(SimpleVolume(0)); + + voice.adr.write(0x200); + voice.repeatAdr.write(0x200); } } - } - void stop_voices() { - Key::off.write(UI32_MAX); - } + static void clear_pmon() { + PMON.write(PitchModFlags()); + } - void setup() { - wait_voices(); + static void clear_noise_and_echo() { + NON.write(NoiseGenerator()); + EON.write(EchoOn()); + } - clear_main_volume(); - clear_cd_and_ext_audio_volume(); - clear_control_register(); - clear_voice(); - clear_pmon(); - clear_noise_and_echo(); - clear_reverb(); + static void clear_reverb() { + Reverb::Volume::left.write(0); + Reverb::Volume::right.write(0); + Reverb::work_area_adr.write(0); + } - setup_data_transfer_control(); - setup_control_register(); + static void setup_control_register() { + static constexpr auto SetupValue = ControlRegister::with(ControlRegister::Enable, ControlRegister::Unmute, ControlRegister::CDAudioEnable); + + Control.write(SetupValue); + } + + static void setup_data_transfer_control() { + static constexpr uint16_t RequiredValue = (2 << 1); + + DataTransferControl.write(RequiredValue); + } + + static void wait_voices() { + static constexpr int16_t Treshhold = (I16_MAX*0.03); + + try_again: + for(const auto& voice : Voices) { + if(voice.currentVolume.read() > Treshhold) { + goto try_again; + } + } + } + + void stop_voices() { + Key::off.write(UI32_MAX); + } + + void setup() { + wait_voices(); + + clear_main_volume(); + clear_cd_and_ext_audio_volume(); + clear_control_register(); + clear_voice(); + clear_pmon(); + clear_noise_and_echo(); + clear_reverb(); + + setup_data_transfer_control(); + setup_control_register(); + } } } \ No newline at end of file diff --git a/src/Library/src/BootLoader/start_boot.cpp b/src/Library/src/BootLoader/start_boot.cpp index 33cc98d3..9c2d2597 100644 --- a/src/Library/src/BootLoader/start_boot.cpp +++ b/src/Library/src/BootLoader/start_boot.cpp @@ -2,21 +2,23 @@ #include #include -namespace Setup { - static void enable_DMA() { - DMA::DPCR.write(DMA::DPCR.read() | DMA::DMAControlRegister::SPUEnable | DMA::DMAControlRegister::GPUEnable); - } +namespace JabyEngine { + namespace Setup { + static void enable_DMA() { + DMA::DPCR.write(DMA::DPCR.read() | DMA::DMAControlRegister::SPUEnable | DMA::DMAControlRegister::GPUEnable); + } - JabyEngine::NextRoutine start() { - enable_DMA(); + JabyEngine::NextRoutine start() { + enable_DMA(); - SPU::stop_voices(); + SPU::stop_voices(); - GPU::setup(); - GPU::display_logo(); - //Pause?? + GPU::setup(); + GPU::display_logo(); + //Pause?? - SPU::setup(); - return BootFile::setup(); + SPU::setup(); + return BootFile::setup(); + } } } \ No newline at end of file diff --git a/src/Library/src/File/Processor/simplehelper.hpp b/src/Library/src/File/Processor/simplehelper.hpp index 2df13aac..2161513b 100644 --- a/src/Library/src/File/Processor/simplehelper.hpp +++ b/src/Library/src/File/Processor/simplehelper.hpp @@ -3,24 +3,25 @@ #define private public #include -namespace FileProcessor { - namespace Helper { - template - static void simple_read(T& dst, State::Configuration& config) { - static constexpr size_t UINT32_SIZE = (sizeof(T)/sizeof(uint32_t)); +namespace JabyEngine { + namespace FileProcessor { + namespace Helper { + template + static void simple_read(T& dst, State::Configuration& config) { + static constexpr size_t UINT32_SIZE = (sizeof(T)/sizeof(uint32_t)); - dst = *reinterpret_cast(config.data_adr); - config.processed(UINT32_SIZE); + dst = *reinterpret_cast(config.data_adr); + config.processed(UINT32_SIZE); - static_assert((UINT32_SIZE*sizeof(uint32_t)) == sizeof(T)); - } + static_assert((UINT32_SIZE*sizeof(uint32_t)) == sizeof(T)); + } - template - static bool exchange_and_execute_process_function(bool (*process_routine)(State::Configuration&, T&), State::Configuration& config, T& state) { - config.process_routine = reinterpret_cast(process_routine); - return process_routine(config, state); + template + static bool exchange_and_execute_process_function(bool (*process_routine)(State::Configuration&, T&), State::Configuration& config, T& state) { + config.process_routine = reinterpret_cast(process_routine); + return process_routine(config, state); + } } } } - #endif // !__JABYENGINE_INTERNAL_SIMPLE_HELPER_HPP__ \ No newline at end of file diff --git a/src/Library/src/File/Processor/tim_processor.cpp b/src/Library/src/File/Processor/tim_processor.cpp index 4ce91833..3a0ccc35 100644 --- a/src/Library/src/File/Processor/tim_processor.cpp +++ b/src/Library/src/File/Processor/tim_processor.cpp @@ -3,129 +3,130 @@ #include #include -namespace FileProcessor { - using GPU::PositionU16; - using GPU::SizeU16; +namespace JabyEngine { + namespace FileProcessor { + using GPU::PositionU16; + using GPU::SizeU16; - struct SimpleTIMSize : private SimpleTIM { - constexpr SimpleTIMSize() { + struct SimpleTIMSize : private SimpleTIM { + constexpr SimpleTIMSize() { + } + + constexpr uint16_t getTextureWidth() const { + return SimpleTIM::getTextureX(); + } + + constexpr uint16_t getTextureHeight() const { + return SimpleTIM::getTextureY(); + } + + constexpr uint16_t getClutWidth() const { + return SimpleTIM::getClutX(); + } + + constexpr uint16_t getClutHeight() const { + return SimpleTIM::getClutY(); + } + }; + + struct SimpleTIMState { + SimpleTIM dst_info; + SimpleTIMSize size_info; + size_t words_left; //32bit values + + constexpr SimpleTIMState(const SimpleTIM& dst_info) : dst_info(dst_info) { + } + }; + + static void set_gpu_receive(const uint32_t* src, uint16_t x, uint16_t y, uint16_t w, uint16_t h) { + GPU::DMA::Receive::prepare(); + GPU::DMA::Receive::set_dst(PositionU16(x, y), SizeU16(w, h)); + GPU::DMA::Receive::set_src(reinterpret_cast(src)); } - constexpr uint16_t getTextureWidth() const { - return SimpleTIM::getTextureX(); + static void set_gpu_receive_data(const uint32_t* src, SimpleTIMState& state, uint16_t width, uint16_t height) { + state.words_left = (width*height)/2; + set_gpu_receive(src, state.dst_info.getTextureX(), state.dst_info.getTextureY(), width, height); } - constexpr uint16_t getTextureHeight() const { - return SimpleTIM::getTextureY(); - } + static bool parse_data(State::Configuration& config, SimpleTIMState& state) { + const auto words_to_use = (config.data_word_size > state.words_left) ? state.words_left : config.data_word_size; + bool is_last = (words_to_use == state.words_left); + auto block_count = (words_to_use >> 4); - constexpr uint16_t getClutWidth() const { - return SimpleTIM::getClutX(); - } + while(block_count > 0) { + const auto block_send = (block_count > UI16_MAX) ? UI16_MAX : block_count; - constexpr uint16_t getClutHeight() const { - return SimpleTIM::getClutY(); - } - }; - - struct SimpleTIMState { - SimpleTIM dst_info; - SimpleTIMSize size_info; - size_t words_left; //32bit values - - constexpr SimpleTIMState(const SimpleTIM& dst_info) : dst_info(dst_info) { - } - }; - - static void set_gpu_receive(const uint32_t* src, uint16_t x, uint16_t y, uint16_t w, uint16_t h) { - GPU::DMA::Receive::prepare(); - GPU::DMA::Receive::set_dst(PositionU16(x, y), SizeU16(w, h)); - GPU::DMA::Receive::set_src(reinterpret_cast(src)); - } - - static void set_gpu_receive_data(const uint32_t* src, SimpleTIMState& state, uint16_t width, uint16_t height) { - state.words_left = (width*height)/2; - set_gpu_receive(src, state.dst_info.getTextureX(), state.dst_info.getTextureY(), width, height); - } - - static bool parse_data(State::Configuration& config, SimpleTIMState& state) { - const auto words_to_use = (config.data_word_size > state.words_left) ? state.words_left : config.data_word_size; - bool is_last = (words_to_use == state.words_left); - auto block_count = (words_to_use >> 4); - - while(block_count > 0) { - const auto block_send = (block_count > UI16_MAX) ? UI16_MAX : block_count; - - // Send data! - GPU::DMA::wait(); - GPU::DMA::Receive::start(block_send); - block_count -= block_send; - } - - if(is_last) { - // Send words - const auto last_words = (words_to_use & 0b1111); - if(last_words > 0) { + // Send data! GPU::DMA::wait(); - GPU::DMA::Receive::start(1, last_words); + GPU::DMA::Receive::start(block_send); + block_count -= block_send; } - GPU::DMA::wait(); - GPU::DMA::end(); + if(is_last) { + // Send words + const auto last_words = (words_to_use & 0b1111); + if(last_words > 0) { + GPU::DMA::wait(); + GPU::DMA::Receive::start(1, last_words); + } - state.words_left = 0; - config.processed(words_to_use); + GPU::DMA::wait(); + GPU::DMA::end(); - return false; - } + state.words_left = 0; + config.processed(words_to_use); - else { - const auto words_used = (words_to_use & ~0b1111); - - state.words_left -= words_used; - config.processed(words_used); - return true; - } - } - - static bool switch_state_parse_data(State::Configuration& config, SimpleTIMState& state) { - set_gpu_receive_data(config.data_adr, state, state.size_info.getTextureWidth(), state.size_info.getTextureHeight()); - return Helper::exchange_and_execute_process_function(parse_data, config, state); - } - - static bool parse_clut(State::Configuration& config, SimpleTIMState& state) { - if(parse_data(config, state)) { - return true; - } - - else { - return switch_state_parse_data(config, state); - } - } - - static bool parse_header(State::Configuration& config, SimpleTIMState& state) { - if(config.data_word_size >= (sizeof(SimpleTIMSize)/sizeof(uint32_t))) { - Helper::simple_read(state.size_info, config); - - //Check if we have a clut to care about - if(state.size_info.getClutWidth() > 0) { - //CLUTs are 16bit full color anyway - set_gpu_receive_data(config.data_adr, state, state.size_info.getClutWidth(), state.size_info.getClutHeight()); - return Helper::exchange_and_execute_process_function(parse_clut, config, state); + return false; + } + + else { + const auto words_used = (words_to_use & ~0b1111); + + state.words_left -= words_used; + config.processed(words_used); + return true; + } + } + + static bool switch_state_parse_data(State::Configuration& config, SimpleTIMState& state) { + set_gpu_receive_data(config.data_adr, state, state.size_info.getTextureWidth(), state.size_info.getTextureHeight()); + return Helper::exchange_and_execute_process_function(parse_data, config, state); + } + + static bool parse_clut(State::Configuration& config, SimpleTIMState& state) { + if(parse_data(config, state)) { + return true; } - //We have direct data else { return switch_state_parse_data(config, state); } } - return true; - } + static bool parse_header(State::Configuration& config, SimpleTIMState& state) { + if(config.data_word_size >= (sizeof(SimpleTIMSize)/sizeof(uint32_t))) { + Helper::simple_read(state.size_info, config); + + //Check if we have a clut to care about + if(state.size_info.getClutWidth() > 0) { + //CLUTs are 16bit full color anyway + set_gpu_receive_data(config.data_adr, state, state.size_info.getClutWidth(), state.size_info.getClutHeight()); + return Helper::exchange_and_execute_process_function(parse_clut, config, state); + } - State create(const uint32_t* data_adr, const SimpleTIM& file) { - return State::from(SimpleTIMState(file), data_adr, parse_header); + //We have direct data + else { + return switch_state_parse_data(config, state); + } + } + + return true; + } + + State create(const uint32_t* data_adr, const SimpleTIM& file) { + return State::from(SimpleTIMState(file), data_adr, parse_header); + } } } - #undef private \ No newline at end of file diff --git a/src/Library/src/GPU/GPU.cpp b/src/Library/src/GPU/GPU.cpp index 2e2428cf..a0df5cb6 100644 --- a/src/Library/src/GPU/GPU.cpp +++ b/src/Library/src/GPU/GPU.cpp @@ -1,36 +1,38 @@ #include "../include/GPU/gpu.hpp" -namespace GPU { - namespace Screen { - uint8_t CurrentDisplayAreaID = 1; //< Setup will call exchange and set it to 0 +namespace JabyEngine { + namespace GPU { + namespace Screen { + uint8_t CurrentDisplayAreaID = 1; //< Setup will call exchange and set it to 0 - namespace Range { - #ifdef JABYENGINE_PAL - static constexpr uint16_t ScanlinesV = 288; - #else - static constexpr uint16_t ScanlinesV = 240; - #endif //JABYENGINE_PAL + namespace Range { + #ifdef JABYENGINE_PAL + static constexpr uint16_t ScanlinesV = 288; + #else + static constexpr uint16_t ScanlinesV = 240; + #endif //JABYENGINE_PAL - #ifndef USE_NO$PSX - void set_offset(uint16_t x, uint16_t y) { - x += 78; - y += 43; + #ifndef USE_NO$PSX + void set_offset(uint16_t x, uint16_t y) { + x += 78; + y += 43; - GP1.write(Command::GP1::HorizontalDisplayRange((x << 3), (x + Display::Width) << 3)); - GP1.write(Command::GP1::VerticalDisplayRange(y, y + Display::Height)); - } - #else - void set_offset(uint16_t x, uint16_t y) { - GP1.write(Command::GP1::HorizontalDisplayRange(x, (x + Display::Width*8))); - GP1.write(Command::GP1::VerticalDisplayRange(y - (ScanlinesV/2), y + (ScanlinesV/2))); - } - #endif //USE_NO$PSX - } + GP1.write(Command::GP1::HorizontalDisplayRange((x << 3), (x + Display::Width) << 3)); + GP1.write(Command::GP1::VerticalDisplayRange(y, y + Display::Height)); + } + #else + void set_offset(uint16_t x, uint16_t y) { + GP1.write(Command::GP1::HorizontalDisplayRange(x, (x + Display::Width*8))); + GP1.write(Command::GP1::VerticalDisplayRange(y - (ScanlinesV/2), y + (ScanlinesV/2))); + } + #endif //USE_NO$PSX + } - void exchange_buffer_and_display() { - GPU::set_draw_area(0, (Display::Height*CurrentDisplayAreaID)); - CurrentDisplayAreaID ^= 1; - GP1.write(Command::GP1::DisplayArea(0, (Display::Height*CurrentDisplayAreaID))); + void exchange_buffer_and_display() { + GPU::set_draw_area(0, (Display::Height*CurrentDisplayAreaID)); + CurrentDisplayAreaID ^= 1; + GP1.write(Command::GP1::DisplayArea(0, (Display::Height*CurrentDisplayAreaID))); + } } } } \ No newline at end of file