diff --git a/include/PSX/System/IOPorts/ioport.hpp b/include/PSX/System/IOPorts/ioport.hpp index f3063032..5d388e82 100644 --- a/include/PSX/System/IOPorts/ioport.hpp +++ b/include/PSX/System/IOPorts/ioport.hpp @@ -118,10 +118,12 @@ namespace JabyEngine { } }; - #define __new_declare_io_value(name, type) struct name : public ::JabyEngine::New::internal::IOValue - #define __new_declare_value_at(cv, type, name, adr) static cv auto& name = *reinterpret_cast(IOAdress::patch_adr(adr)) + #define __new_declare_io_value(name, type) struct name : public ::JabyEngine::New::internal::IOValue + #define __new_declare_value_at(cv, type, name, adr) static cv auto& name = *reinterpret_cast(IOAdress::patch_adr(adr)) + #define __new_declare_array_at(cv, type, name, size, adr) static cv auto& name = reinterpret_cast(*reinterpret_cast(IOAdress::patch_adr(adr))) #define __new_declare_io_port_w_type(cv, type, name, adr) __new_declare_value_at(cv, ::JabyEngine::New::IOPort, name, adr) - #define __new_declare_io_port(cv, name, adr) __new_declare_io_port_w_type(cv, struct name, name, adr) + #define __new_declare_io_port(cv, name, adr) __new_declare_io_port_w_type(cv, struct name, name, adr) + #define __new_declare_io_port_array(cv, name, size, adr) __new_declare_array_at(cv, struct name, name, size, adr) } namespace IOPort { diff --git a/include/PSX/System/IOPorts/spu_io.hpp b/include/PSX/System/IOPorts/spu_io.hpp index c703f5b2..9f9a60cd 100644 --- a/include/PSX/System/IOPorts/spu_io.hpp +++ b/include/PSX/System/IOPorts/spu_io.hpp @@ -25,22 +25,27 @@ namespace JabyEngine { //0..3 = +7, +6, +5, +4 or -6, -7, -6, -5 typedef uint8_t Step; - typedef int16_t SimpleVolume; - typedef volatile int16_t SimpleVolume_v; + __new_declare_io_value(DataTransferControl, uint16_t) { + }; - typedef volatile uint16_t Adr_v; - typedef volatile uint16_t DataTransferControl_v; + __new_declare_io_value(SimpleVolume, int16_t) { + constexpr operator int16_t() const { + return this->raw; + } + }; + __new_declare_io_value(Adr, uint16_t) { + }; - __declare_io_type(SampleRate, uint16_t, - static constexpr Self from_HZ(double freq) { + __new_declare_io_value(SampleRate, uint16_t) { + static constexpr SampleRate from_HZ(double freq) { //4096 == 44100Hz constexpr double Base = (4096.0 / 44100.0); return {static_cast((freq*Base))}; } - ); + }; - __declare_io_type(SweepVolume, int16_t, + __new_declare_io_value(SweepVolume, int16_t) { // For Volume Mode static constexpr auto SweepEnable = Bit(15); static constexpr auto VolumeEnable = !SweepEnable; @@ -52,39 +57,43 @@ namespace JabyEngine { static constexpr auto SweepPhase = Bit(12); static constexpr auto SweepShift = BitRange::from_to(2, 6); static constexpr auto SweepStep = BitRange::from_to(0, 1); - ); + }; - __declare_io_type(SR, uint16_t, + __new_declare_io_value(SR, uint16_t) { 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)); - ); + }; - __declare_io_type(AD, uint16_t, + __new_declare_io_value(AD, uint16_t) { 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); - ); + }; #pragma pack(push, 1) - struct Voice_v { - SweepVolume_v volumeLeft; //Offset: 0x0 - SweepVolume_v volumeRight; //Offset: 0x2 - SampleRate_v sampleRate; //Offset: 0x4; - Adr_v adr; //Offset: 0x6 - AD_v ad; //Offset: 0x8 - SR_v sr; //Offset: 0xA - SimpleVolume_v currentVolume; //Offset: 0xC - Adr_v repeatAdr; //Offset: 0xE + struct Voice { + New::IOPort volumeLeft; //Offset: 0x0 + New::IOPort volumeRight; //Offset: 0x2 + New::IOPort sampleRate; //Offset: 0x4; + New::IOPort adr; //Offset: 0x6 + New::IOPort ad; //Offset: 0x8 + New::IOPort sr; //Offset: 0xA + New::IOPort currentVolume; //Offset: 0xC + New::IOPort repeatAdr; //Offset: 0xE + + static constexpr Adr start_adr() { + return {0x200}; + } }; #pragma pack(pop) - __declare_io_type(ControlRegister, uint16_t, + __new_declare_io_value(ControlRegister, uint16_t) { enum RAMTransferMode { Stop = 0, ManualWrite = 1, @@ -103,60 +112,58 @@ namespace JabyEngine { static constexpr auto CDAudioReverb = Bit(2); static constexpr auto ExternalAudioEnable = Bit(1); static constexpr auto CDAudioEnable = Bit(0); - ); + }; - __declare_io_type(PMON, uint16_t, + __new_declare_io_value(PMON, uint16_t) { static constexpr auto EnableBits = BitRange::from_to(1, 23); - ); + }; - __declare_io_type(NON, uint16_t, + __new_declare_io_value(NON, uint16_t) { static constexpr auto NoiseBits = BitRange::from_to(0, 23); - ); + }; - __declare_io_type(EON, uint16_t, + __new_declare_io_value(EON, uint16_t) { static constexpr auto EchoBits = BitRange::from_to(0, 23); - ); + }; static constexpr size_t VoiceCount = 24; - struct Key { - typedef ubus32_t ubus32_v; - - __declare_new_named_io_port(ubus32, On, 0x1F801D88); - __declare_new_named_io_port(ubus32, Off, 0x1F801D8C); - __declare_new_named_io_port(ubus32, Status, 0x1F801D9C); + struct Key { + __new_declare_io_port_w_type(inline, New::ubus32_t, On, 0x1F801D88); + __new_declare_io_port_w_type(inline, New::ubus32_t, Off, 0x1F801D8C); + __new_declare_io_port_w_type(inline, New::ubus32_t, Status, 0x1F801D9C); }; struct MainVolume { - __declare_new_named_io_port(SweepVolume, Left, 0x1F801D80); - __declare_new_named_io_port(SweepVolume, Right, 0x1F801D82); + __new_declare_io_port_w_type(inline, SweepVolume, Left, 0x1F801D80); + __new_declare_io_port_w_type(inline, SweepVolume, Right, 0x1F801D82); }; struct CDVolume { - __declare_new_named_io_port(SimpleVolume, Left, 0x1F801DB0); - __declare_new_named_io_port(SimpleVolume, Right, 0x1F801DB2); + __new_declare_io_port_w_type(inline, SimpleVolume, Left, 0x1F801DB0); + __new_declare_io_port_w_type(inline, SimpleVolume, Right, 0x1F801DB2); }; struct ExternalAudioInputVolume { - __declare_new_named_io_port(SimpleVolume, Left, 0x1F801DB4); - __declare_new_named_io_port(SimpleVolume, Right, 0x1F801DB6); + __new_declare_io_port_w_type(inline, SimpleVolume, Left, 0x1F801DB4); + __new_declare_io_port_w_type(inline, SimpleVolume, Right, 0x1F801DB6); }; struct Reverb { struct Volume { - __declare_new_named_io_port(SimpleVolume, Left, 0x1F801D84); - __declare_new_named_io_port(SimpleVolume, Right, 0x1F801D86); + __new_declare_io_port_w_type(inline, SimpleVolume, Left, 0x1F801D84); + __new_declare_io_port_w_type(inline, SimpleVolume, Right, 0x1F801D86); }; - __declare_new_named_io_port(Adr, WorkAreaAdr, 0x1F801DA2); + __new_declare_io_port_w_type(inline, Adr, WorkAreaAdr, 0x1F801DA2); }; - __declare_new_io_port(ControlRegister, 0x1F801DAA); - __declare_new_io_port(DataTransferControl, 0x1F801DAC); - __declare_new_io_port(PMON, 0x1F801D90); - __declare_new_io_port(NON, 0x1F801D94); - __declare_new_io_port(EON, 0x1F801D98); + __new_declare_io_port(, ControlRegister, 0x1F801DAA); + __new_declare_io_port(, DataTransferControl, 0x1F801DAC); + __new_declare_io_port(, PMON, 0x1F801D90); + __new_declare_io_port(, NON, 0x1F801D94); + __new_declare_io_port(, EON, 0x1F801D98); - __declare_new_io_port_array(Voice, 0x1F801C00, VoiceCount); + __new_declare_io_port_array(, Voice, VoiceCount, 0x1F801C00); } } #endif //!__JABYENGINE_SPU_IO_HPP__ \ 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 bff3a1d8..4b25d658 100644 --- a/src/Library/src/BootLoader/spu_boot.cpp +++ b/src/Library/src/BootLoader/spu_boot.cpp @@ -9,71 +9,71 @@ namespace JabyEngine { using namespace SPU_IO; static void clear_main_volume() { - static constexpr auto StartVol = SweepVolume_t::from(SweepVolume_t::VolumeEnable, SweepVolume_t::Volume.with(static_cast(I16_MAX >> 2))); + static constexpr auto StartVol = SweepVolume::from(SweepVolume::VolumeEnable, SweepVolume::Volume.with(static_cast(I16_MAX >> 2))); - MainVolume::Left = StartVol; - MainVolume::Right = StartVol; + MainVolume::Left.write(StartVol); + MainVolume::Right.write(StartVol); } static void clear_cd_and_ext_audio_volume() { - CDVolume::Left = 0; - CDVolume::Right = 0; + CDVolume::Left.write({0}); + CDVolume::Right.write({0}); - ExternalAudioInputVolume::Left = 0; - ExternalAudioInputVolume::Right = 0; + ExternalAudioInputVolume::Left.write({0}); + ExternalAudioInputVolume::Right.write({0}); } static void clear_control_register() { - ControlRegister = 0; + ControlRegister.write({0}); } static void clear_voice() { for(auto& voice : SPU_IO::Voice) { - voice.volumeLeft = SweepVolume_t(); - voice.volumeRight = SweepVolume_t(); - voice.sampleRate = SampleRate_t(); - voice.ad = AD_t(); - voice.sr = SR_t(); - voice.currentVolume = 0; + voice.volumeLeft.write({0}); + voice.volumeRight.write({0}); + voice.sampleRate.write({0}); + voice.ad.write({0}); + voice.sr.write({0}); + voice.currentVolume.write({0}); - voice.adr = 0x200; - voice.repeatAdr = 0x200; + voice.adr.write(Voice::start_adr()); + voice.repeatAdr.write(Voice::start_adr()); } } static void clear_pmon() { - SPU_IO::PMON = PMON_t(); + SPU_IO::PMON.write({0}); } static void clear_noise_and_echo() { - SPU_IO::NON = NON_t(); - SPU_IO::EON = EON_t(); + SPU_IO::NON.write({0}); + SPU_IO::EON.write({0}); } static void clear_reverb() { - Reverb::Volume::Left = 0; - Reverb::Volume::Right = 0; - Reverb::WorkAreaAdr = 0; + Reverb::Volume::Left.write({0}); + Reverb::Volume::Right.write({0}); + Reverb::WorkAreaAdr.write({0}); } static void setup_control_register() { - static constexpr auto SetupValue = ControlRegister_t::from(ControlRegister_t::Enable, ControlRegister_t::Unmute, ControlRegister_t::CDAudioEnable); + static constexpr auto SetupValue = ControlRegister::from(ControlRegister::Enable, ControlRegister::Unmute, ControlRegister::CDAudioEnable); - SPU_IO::ControlRegister = SetupValue; + SPU_IO::ControlRegister.write(SetupValue); } static void setup_data_transfer_control() { - static constexpr uint16_t RequiredValue = (2 << 1); + static constexpr struct DataTransferControl RequiredValue{(2 << 1)}; - DataTransferControl = RequiredValue; + DataTransferControl.write(RequiredValue); } static void wait_voices() { - static constexpr int16_t Treshhold = (I16_MAX*0.03); + static constexpr SimpleVolume Treshhold{static_cast(I16_MAX*0.03)}; try_again: for(const auto& voice : SPU_IO::Voice) { - if(voice.currentVolume > Treshhold) { + if(voice.currentVolume.read() > Treshhold) { goto try_again; } }