#ifndef __JABYENGINE_SPU_IO_HPP__ #define __JABYENGINE_SPU_IO_HPP__ #include "IOPort.hpp" #include namespace SPU { namespace Port { enum struct SweepMode { Linear = 0, Exponential = 1, }; enum struct SweepDirection { Increase = 0, Decrease = 1, }; enum struct SweepPhase { Posititve = 0, Negative = 1, }; //0..0x1F = Fast..Slow typedef uint8_t SweepShift; //0..3 = +7, +6, +5, +4 or -6, -7, -6, -5 typedef uint8_t SweepStep; struct __no_align SampleRate : public IOPort { __io_port_inherit(SampleRate); static constexpr SampleRate from_HZ(double freq) { //4096 == 44100Hz constexpr double Base = (4096.0 / 44100.0); return IOPort(static_cast((freq*Base))); } }; struct __no_align SweepVolume : public IOPort { __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); // 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); }; 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)); }; 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); }; struct __no_align Voice { SweepVolume volumeLeft; SweepVolume volumeRight; SampleRate sampleRate; IOPort adr; IOPort ad; IOPort sr; IOPort currentVolume; //Not used IOPort repeatAdr; }; namespace Key { __declare_io_port_global(ubus32_t, on, 0x1F801D88); __declare_io_port_global(ubus32_t, off, 0x1F801D8C); __declare_io_port_global(ubus32_t, status, 0x1F801D9C); } namespace MainVolume { __declare_io_port_global(SweepVolume, left, 0x1F801D80); __declare_io_port_global(SweepVolume, right, 0x1F801D82); } } } #endif //!__JABYENGINE_SPU_IO_HPP__