#ifndef __JABYENGINE_SPU_IO_HPP__ #define __JABYENGINE_SPU_IO_HPP__ #include "ioport.hpp" namespace JabyEngine { namespace SPU_IO { 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; typedef volatile int16_t SimpleVolume_v; typedef volatile uint16_t Adr_v; typedef volatile uint16_t DataTransferControl_v; __declare_io_type(SampleRate, uint16_t, static constexpr Self from_HZ(double freq) { //4096 == 44100Hz constexpr double Base = (4096.0 / 44100.0); return {static_cast((freq*Base))}; } ); __declare_io_type(SweepVolume, int16_t, // For Volume Mode static constexpr auto SweepEnable = IOBitSet(15); static constexpr auto VolumeEnable = !SweepEnable; static constexpr auto Volume = IOValueSet::from_to(0, 14); // For Sweep Mode static constexpr auto SweepMode = IOBitSet(14); static constexpr auto SweepDirection = IOBitSet(13); static constexpr auto SweepPhase = IOBitSet(12); static constexpr auto SweepShift = IOValueSet::from_to(2, 6); static constexpr auto SweepStep = IOValueSet::from_to(0, 1); ); __declare_io_type(SR, uint16_t, static constexpr auto SustainMode = IOBitSet(31 - 16); static constexpr auto SustainDirection = IOBitSet(30 - 16); static constexpr auto SustainShift = IOValueSet::from_to((24 - 16), (28 - 16)); static constexpr auto SustainStep = IOValueSet::from_to((22 - 16), (23 - 16)); static constexpr auto ReleaseMode = IOBitSet(21 - 16); static constexpr auto ReleaseShift = IOValueSet::from_to((16 - 16), (20 - 16)); ); __declare_io_type(AD, uint16_t, static constexpr auto AttackMode = IOBitSet(15); static constexpr auto AttackShift = IOValueSet::from_to(10, 14); static constexpr auto AttackStep = IOValueSet::from_to(8, 9); static constexpr auto DecayShift = IOValueSet::from_to(4, 7); static constexpr auto SustainLevel = IOValueSet::from_to(0, 3); ); struct __no_align 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 }; __declare_io_type(ControlRegister, uint16_t, enum RAMTransferMode { Stop = 0, ManualWrite = 1, DMAWrite = 2, DMARead = 3 }; static constexpr auto Enable = IOBitSet(15); static constexpr auto Unmute = IOBitSet(14); static constexpr auto NoiseFrequcenyShift = IOValueSet::from_to(10, 13); static constexpr auto NoiseFrequcenyStep = IOValueSet::from_to(8, 9); static constexpr auto ReverbMasterEnable = IOBitSet(7); static constexpr auto IRQ9Enable = IOBitSet(6); static constexpr auto TransferMode = IOValueSet::from_to(4, 5); static constexpr auto ExternalAudioReverb = IOBitSet(3); static constexpr auto CDAudioReverb = IOBitSet(2); static constexpr auto ExternalAudioEnable = IOBitSet(1); static constexpr auto CDAudioEnable = IOBitSet(0); ); __declare_io_type(PMON, uint16_t, static constexpr auto EnableBits = IOValueSet::from_to(1, 23); ); __declare_io_type(NON, uint16_t, static constexpr auto NoiseBits = IOValueSet::from_to(0, 23); ); __declare_io_type(EON, uint16_t, static constexpr auto EchoBits = IOValueSet::from_to(0, 23); ); static constexpr size_t VoiceCount = 24; struct Key { __cast_io_adr_with_type(inline, ubus32_t, On, 0x1F801D88); __cast_io_adr_with_type(inline, ubus32_t, Off, 0x1F801D8C); __cast_io_adr_with_type(inline, ubus32_t, Status, 0x1F801D9C); }; struct MainVolume { __declare_new_named_io_port(SweepVolume, Left, 0x1F801D80); __declare_new_named_io_port(SweepVolume, Right, 0x1F801D82); }; struct CDVolume { __declare_new_named_io_port(SimpleVolume, Left, 0x1F801DB0); __declare_new_named_io_port(SimpleVolume, Right, 0x1F801DB2); }; struct ExternalAudioInputVolume { __declare_new_named_io_port(SimpleVolume, Left, 0x1F801DB4); __declare_new_named_io_port(SimpleVolume, Right, 0x1F801DB6); }; struct Reverb { struct Volume { __declare_new_named_io_port(SimpleVolume, Left, 0x1F801D84); __declare_new_named_io_port(SimpleVolume, Right, 0x1F801D86); }; __declare_new_named_io_port(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); __declare_new_io_port_array(Voice, 0x1F801C00, VoiceCount); } } #endif //!__JABYENGINE_SPU_IO_HPP__