From a84b2c4f14ac1328960cfd3a50dbc2d9f694afd2 Mon Sep 17 00:00:00 2001 From: Jaby Date: Wed, 31 Aug 2022 22:00:38 +0200 Subject: [PATCH] SPU Controll Register --- include/PSX/Auxiliary/io_class_helper.hpp | 13 +++++- include/PSX/System/IOPorts/SPU_IO.hpp | 56 ++++++++++++++++++++++- include/PSX/jabyengine_defines.h | 1 + src/Library/src/BootLoader/boot_spu.cpp | 11 +++++ 4 files changed, 78 insertions(+), 3 deletions(-) diff --git a/include/PSX/Auxiliary/io_class_helper.hpp b/include/PSX/Auxiliary/io_class_helper.hpp index 9052fdb9..70eadd89 100644 --- a/include/PSX/Auxiliary/io_class_helper.hpp +++ b/include/PSX/Auxiliary/io_class_helper.hpp @@ -15,13 +15,22 @@ #define io_class__2option_map_getter(type, option0, option1, name, bit_num) \ io_class__2option_map(option0, option1, bit_num) \ - io_class__option_as(type, name, bit_num) + io_class__option_get(type, name, bit_num) -#define io_class__option_as(type, name, bit_num) \ +#define io_class__2option_map_getter_is(type, option0, option1, bit_num) \ + io_class__2option_map(option0, option1, bit_num) \ + io_class__option_is(type, option1, bit_num) + +#define io_class__option_get(type, name, bit_num) \ constexpr type get_##name() const { \ return static_cast(bit::is_set(this->raw_value, bit_num)); \ } +#define io_class__option_is(type, name, bit_num) \ + constexpr type is_##name() const { \ + return static_cast(bit::is_set(this->raw_value, bit_num)); \ + } + template static constexpr __always_inline void io_class__update_with(T& dst, const T& src) { typedef decltype(dst.raw_value) DST_VALUE; diff --git a/include/PSX/System/IOPorts/SPU_IO.hpp b/include/PSX/System/IOPorts/SPU_IO.hpp index 5d780ac4..0fbddfa0 100644 --- a/include/PSX/System/IOPorts/SPU_IO.hpp +++ b/include/PSX/System/IOPorts/SPU_IO.hpp @@ -106,7 +106,7 @@ namespace SPU { }; struct __no_align ADSR { - uint32_t raw_value = 0; + ubus32_t raw_value; }; struct __no_align KeyW { @@ -158,6 +158,60 @@ namespace SPU { static inline __always_inline auto& Left = *reinterpret_cast(0x1F801D80); static inline __always_inline auto& Right = *reinterpret_cast(0x1F801D82); }; + + struct __no_align Control { + static inline __always_inline auto& Register = *reinterpret_cast(0x1F801DAA); + + enum TransferMode + { + Stop = 0, + ManualWrite = (1 << 4), + DMAWrite = (2 << 4), + DMARead = (3 << 4), + }; + + uint16_t raw_value = 0; + + constexpr Control() = default; + + io_class__2option_map(off, on, 15); + io_class__2option_map_getter_is(bool, mute, unmute, 14); + + constexpr Control& set_noise_shift(uint8_4b shift) { + this->raw_value = bit::value::set_normalized(this->raw_value, static_cast(shift), __start_end_bit2_start_length(10, 13)); + return *this; + } + + constexpr uint8_4b get_noise_shift() const { + return bit::value::get_normalized(this->raw_value, __start_end_bit2_start_length(10, 13)); + } + + constexpr Control& set_noise_step(uint8_2b step) { + this->raw_value = bit::value::set_normalized(this->raw_value, static_cast(step), __start_end_bit2_start_length(8, 9)); + return *this; + } + + constexpr uint8_2b get_noise_step() const { + return bit::value::get_normalized(this->raw_value, __start_end_bit2_start_length(8, 9)); + } + + io_class__2option_map_getter_is(bool, reverb_disabled, reverb_enabled, 7); + io_class__2option_map(irq9_ack, irq9_enable, 6); + + constexpr Control& set_transfer_mode(TransferMode mode) { + this->raw_value = bit::value::set_normalized(this->raw_value, static_cast(mode), __start_end_bit2_start_length(4, 5)); + return *this; + } + + constexpr TransferMode get_transfer_mode() const { + return static_cast(bit::value::get_normalized(this->raw_value, __start_end_bit2_start_length(4, 5))); + } + + io_class__2option_map_getter_is(bool, external_reverb_off, external_reverb_on, 3); + io_class__2option_map_getter_is(bool, cd_reverb_off, cd_reverb_on, 2); + io_class__2option_map_getter_is(bool, external_audio_off, external_audio_on, 1); + io_class__2option_map_getter_is(bool, cd_audio_disable, cd_audio_enable, 0); + }; } #endif //!__JABYENGINE_SPU_IO_HPP__ \ No newline at end of file diff --git a/include/PSX/jabyengine_defines.h b/include/PSX/jabyengine_defines.h index 90d8539d..27d1d6b7 100644 --- a/include/PSX/jabyengine_defines.h +++ b/include/PSX/jabyengine_defines.h @@ -16,6 +16,7 @@ //uint_b; typedef uint8_t uint8_5b; +typedef uint8_t uint8_4b; typedef uint8_t uint8_2b; #endif //!__JABYENGINE_DEFINES__H \ No newline at end of file diff --git a/src/Library/src/BootLoader/boot_spu.cpp b/src/Library/src/BootLoader/boot_spu.cpp index d880f54d..448e2c25 100644 --- a/src/Library/src/BootLoader/boot_spu.cpp +++ b/src/Library/src/BootLoader/boot_spu.cpp @@ -24,12 +24,23 @@ namespace SPU { voice.repeatAdr = 0x200; } + static void enable_control() { + io_class__update_with(Control::Register, Control().set_on().set_unmute().set_cd_audio_enable()); + } + + static void disable_control() { + io_class__update_with(Control::Register, Control()); + } + void setup() { clear_main_volume(); clear_keys(); + disable_control(); for(auto& voice : Voice::Channel) { clear_voice(voice); } + + enable_control(); } } \ No newline at end of file