#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; struct SampleRate : public ComplexBitMap { static constexpr SampleRate from_HZ(double freq) { //4096 == 44100Hz constexpr double Base = (4096.0 / 44100.0); return {static_cast((freq*Base))}; } }; struct SweepVolume : public ComplexBitMap { // 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 SR : public ComplexBitMap { 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 AD : public ComplexBitMap { 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 ControlRegister : public ComplexBitMap { 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 PitchModFlags : public ComplexBitMap { static constexpr BitRange EnableBits = BitRange::from_to(1, 23); }; struct NoiseGenerator : public ComplexBitMap { static constexpr BitRange NoiseBits = BitRange::from_to(0, 23); }; struct EchoOn : public ComplexBitMap { static constexpr BitRange EchoBits = BitRange::from_to(0, 23); }; static constexpr size_t VoiceCount = 24; struct Key { __declare_global_raw(inline, ubus32_t, On, 0x1F801D88); __declare_global_raw(inline, ubus32_t, Off, 0x1F801D8C); __declare_global_raw(inline, ubus32_t, Status, 0x1F801D9C); }; struct MainVolume { __declare_io_port_member(SweepVolume, Left, 0x1F801D80); __declare_io_port_member(SweepVolume, Right, 0x1F801D82); }; struct CDVolume { __declare_io_port_member_simple(SimpleVolume, Left, 0x1F801DB0); __declare_io_port_member_simple(SimpleVolume, Right, 0x1F801DB2); }; struct ExternalAudioInputVolume { __declare_io_port_member_simple(SimpleVolume, Left, 0x1F801DB4); __declare_io_port_member_simple(SimpleVolume, Right, 0x1F801DB6); }; struct Reverb { struct Volume { __declare_io_port_member_simple(SimpleVolume, Left, 0x1F801D84); __declare_io_port_member_simple(SimpleVolume, Right, 0x1F801D86); }; __declare_io_port_member_simple(uint16_t, WorkAreaAdr, 0x1F801DA2); }; __declare_io_port_global(ControlRegister, Control, 0x1F801DAA); __declare_io_port_global_simple(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(struct Voice, Voice, 0x1F801C00, VoiceCount); } } #endif //!__JABYENGINE_SPU_IO_HPP__