From ba03dcab26e3ac04d2d5524d860c6ca2a417036a Mon Sep 17 00:00:00 2001 From: Jaby Date: Fri, 2 Sep 2022 11:33:42 +0200 Subject: [PATCH] Clear Control Register --- include/PSX/System/IOPorts/SPU_IO.hpp | 71 +++++++++++++++++-------- src/Library/src/BootLoader/boot_spu.cpp | 7 ++- 2 files changed, 54 insertions(+), 24 deletions(-) diff --git a/include/PSX/System/IOPorts/SPU_IO.hpp b/include/PSX/System/IOPorts/SPU_IO.hpp index b5d11337..b9b26d21 100644 --- a/include/PSX/System/IOPorts/SPU_IO.hpp +++ b/include/PSX/System/IOPorts/SPU_IO.hpp @@ -5,26 +5,26 @@ namespace SPU { namespace Port { - enum struct SweepMode { + enum struct Mode { Linear = 0, Exponential = 1, }; - enum struct SweepDirection { + enum struct Direction { Increase = 0, Decrease = 1, }; - enum struct SweepPhase { + enum struct Phase { Posititve = 0, Negative = 1, }; //0..0x1F = Fast..Slow - typedef uint8_t SweepShift; + typedef uint8_t Shift; //0..3 = +7, +6, +5, +4 or -6, -7, -6, -5 - typedef uint8_t SweepStep; + typedef uint8_t Step; struct __no_align SampleRate : public IOPort { __io_port_inherit(SampleRate); @@ -41,32 +41,32 @@ namespace SPU { __io_port_inherit(SweepVolume); // For Volume Mode - static constexpr Bit ModeBit = 15; // 0 Volume Mode; 1 Sweep Mode - static constexpr BitRange VolumeRange = BitRange::from_to(0, 14); + static constexpr Bit SweepEnable = 15; // 0 Volume Mode; 1 Sweep Mode + static constexpr BitRange Volume = BitRange::from_to(0, 14); // For Sweep Mode - static constexpr Bit SweepModeBit = 14; - static constexpr Bit SweepDirectionBit = 13; - static constexpr Bit SweepPhaseBit = 12; - static constexpr BitRange SweepShiftRange = BitRange::from_to(2, 6); - static constexpr BitRange SweepStepRange = BitRange::from_to(0, 1); + static constexpr Bit SweepMode = 14; + static constexpr Bit SweepDirection = 13; + static constexpr Bit SweepPhase = 12; + static constexpr BitRange SweepShift = BitRange::from_to(2, 6); + static constexpr BitRange SweepStep = BitRange::from_to(0, 1); }; struct __no_align SR : public IOPort { - static constexpr Bit SustainModeBit = (31 - 16); - static constexpr Bit SustainDirectionBit = (30 - 16); - static constexpr BitRange SustainShiftRange = BitRange::from_to((24 - 16), (28 - 16)); - static constexpr BitRange SustainStepRange = BitRange::from_to((22 - 16), (23 - 16)); - static constexpr Bit ReleaseModeBit = (21 - 16); - static constexpr BitRange ReleaseShiftRange = BitRange::from_to((16 - 16), (20 - 16)); + static constexpr Bit SustainMode = (31 - 16); + static constexpr Bit SustainDirection = (30 - 16); + static constexpr BitRange SustainShift = BitRange::from_to((24 - 16), (28 - 16)); + static constexpr BitRange SustainStep = BitRange::from_to((22 - 16), (23 - 16)); + static constexpr Bit ReleaseMode = (21 - 16); + static constexpr BitRange ReleaseShift = BitRange::from_to((16 - 16), (20 - 16)); }; struct __no_align AD : public IOPort { - static constexpr Bit AttackModeBit = 15; - static constexpr BitRange AttackShiftRange = BitRange::from_to(10, 14); - static constexpr BitRange AttackStepRange = BitRange::from_to(8, 9); - static constexpr BitRange DecayShiftRange = BitRange::from_to(4, 7); - static constexpr BitRange SustainLevelRange = BitRange::from_to(0, 3); + static constexpr Bit AttackMode = 15; + static constexpr BitRange AttackShift = BitRange::from_to(10, 14); + static constexpr BitRange AttackStep = BitRange::from_to(8, 9); + static constexpr BitRange DecayShift = BitRange::from_to(4, 7); + static constexpr BitRange SustainLevel = BitRange::from_to(0, 3); }; struct __no_align Voice { @@ -80,6 +80,29 @@ namespace SPU { IOPort repeatAdr; }; + struct __no_align ControlRegister : public IOPort { + __io_port_inherit(ControlRegister); + + enum RAMTransferMode { + Stop = 0, + ManualWrite = 1, + DMAWrite = 2, + DMARead = 3 + }; + + static constexpr Bit Enable = 15; + static constexpr Bit Mute = 14; + static constexpr BitRange NoiseFrequcenyShift = BitRange::from_to(10, 13); + static constexpr BitRange NoiseFrequcenyStep = BitRange::from_to(8, 9); + static constexpr Bit ReverbMasterEnable = 7; + static constexpr Bit IRQ9Enable = 6; + static constexpr BitRange TransferMode = BitRange::from_to(4, 5); + static constexpr Bit ExternalAudioReverb = 3; + static constexpr Bit CDAudioReverb = 2; + static constexpr Bit ExternalAudioEnable = 1; + static constexpr Bit CDAudioEnable = 0; + }; + namespace Key { __declare_io_port_global(ubus32_t, on, 0x1F801D88); __declare_io_port_global(ubus32_t, off, 0x1F801D8C); @@ -90,6 +113,8 @@ namespace SPU { __declare_io_port_global(SweepVolume, left, 0x1F801D80); __declare_io_port_global(SweepVolume, right, 0x1F801D82); } + + __declare_io_port_global(ControlRegister, Control, 0x1F801DAA); } } diff --git a/src/Library/src/BootLoader/boot_spu.cpp b/src/Library/src/BootLoader/boot_spu.cpp index b1badfe4..ff4aead8 100644 --- a/src/Library/src/BootLoader/boot_spu.cpp +++ b/src/Library/src/BootLoader/boot_spu.cpp @@ -9,14 +9,19 @@ namespace SPU { } static void clear_main_volume() { - static constexpr auto StartVol = SweepVolume().clear_bit(SweepVolume::ModeBit).set_value(static_cast(I16_MAX >> 2), SweepVolume::VolumeRange); + static constexpr auto StartVol = SweepVolume().clear_bit(SweepVolume::SweepEnable).set_value(static_cast(I16_MAX >> 2), SweepVolume::Volume); MainVolume::left.write(StartVol); MainVolume::right.write(StartVol); } + static void clear_control_register() { + Control.write(ControlRegister()); + } + void setup() { clear_key(); clear_main_volume(); + clear_control_register(); } } \ No newline at end of file