Clear Control Register

This commit is contained in:
jaby 2022-09-02 11:33:42 +02:00
parent dac33a77c6
commit 7071acead1
2 changed files with 54 additions and 24 deletions

View File

@ -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<uint16_t> {
__io_port_inherit(SampleRate);
@ -41,32 +41,32 @@ namespace SPU {
__io_port_inherit(SweepVolume);
// For Volume Mode
static constexpr Bit<int16_t> ModeBit = 15; // 0 Volume Mode; 1 Sweep Mode
static constexpr BitRange<int16_t> VolumeRange = BitRange<int16_t>::from_to(0, 14);
static constexpr Bit<int16_t> SweepEnable = 15; // 0 Volume Mode; 1 Sweep Mode
static constexpr BitRange<int16_t> Volume = BitRange<int16_t>::from_to(0, 14);
// For Sweep Mode
static constexpr Bit<SweepMode> SweepModeBit = 14;
static constexpr Bit<SweepDirection> SweepDirectionBit = 13;
static constexpr Bit<SweepPhase> SweepPhaseBit = 12;
static constexpr BitRange<SweepShift> SweepShiftRange = BitRange<SweepShift>::from_to(2, 6);
static constexpr BitRange<SweepStep> SweepStepRange = BitRange<SweepStep>::from_to(0, 1);
static constexpr Bit<Mode> SweepMode = 14;
static constexpr Bit<Direction> SweepDirection = 13;
static constexpr Bit<Phase> SweepPhase = 12;
static constexpr BitRange<Shift> SweepShift = BitRange<Shift>::from_to(2, 6);
static constexpr BitRange<Step> SweepStep = BitRange<Step>::from_to(0, 1);
};
struct __no_align SR : public IOPort<uint16_t> {
static constexpr Bit<SweepMode> SustainModeBit = (31 - 16);
static constexpr Bit<SweepDirection> SustainDirectionBit = (30 - 16);
static constexpr BitRange<SweepShift> SustainShiftRange = BitRange<SweepShift>::from_to((24 - 16), (28 - 16));
static constexpr BitRange<SweepStep> SustainStepRange = BitRange<SweepStep>::from_to((22 - 16), (23 - 16));
static constexpr Bit<SweepMode> ReleaseModeBit = (21 - 16);
static constexpr BitRange<SweepShift> ReleaseShiftRange = BitRange<SweepShift>::from_to((16 - 16), (20 - 16));
static constexpr Bit<Mode> SustainMode = (31 - 16);
static constexpr Bit<Direction> SustainDirection = (30 - 16);
static constexpr BitRange<Shift> SustainShift = BitRange<Shift>::from_to((24 - 16), (28 - 16));
static constexpr BitRange<Step> SustainStep = BitRange<Step>::from_to((22 - 16), (23 - 16));
static constexpr Bit<Mode> ReleaseMode = (21 - 16);
static constexpr BitRange<Shift> ReleaseShift = BitRange<Shift>::from_to((16 - 16), (20 - 16));
};
struct __no_align AD : public IOPort<uint16_t> {
static constexpr Bit<SweepMode> AttackModeBit = 15;
static constexpr BitRange<SweepShift> AttackShiftRange = BitRange<SweepShift>::from_to(10, 14);
static constexpr BitRange<SweepStep> AttackStepRange = BitRange<SweepStep>::from_to(8, 9);
static constexpr BitRange<SweepShift> DecayShiftRange = BitRange<SweepShift>::from_to(4, 7);
static constexpr BitRange<uint16_t> SustainLevelRange = BitRange<uint16_t>::from_to(0, 3);
static constexpr Bit<Mode> AttackMode = 15;
static constexpr BitRange<Shift> AttackShift = BitRange<Shift>::from_to(10, 14);
static constexpr BitRange<Step> AttackStep = BitRange<Step>::from_to(8, 9);
static constexpr BitRange<Shift> DecayShift = BitRange<Shift>::from_to(4, 7);
static constexpr BitRange<uint16_t> SustainLevel = BitRange<uint16_t>::from_to(0, 3);
};
struct __no_align Voice {
@ -80,6 +80,29 @@ namespace SPU {
IOPort<uint16_t> repeatAdr;
};
struct __no_align ControlRegister : public IOPort<uint16_t> {
__io_port_inherit(ControlRegister);
enum RAMTransferMode {
Stop = 0,
ManualWrite = 1,
DMAWrite = 2,
DMARead = 3
};
static constexpr Bit<uint16_t> Enable = 15;
static constexpr Bit<uint16_t> Mute = 14;
static constexpr BitRange<Shift> NoiseFrequcenyShift = BitRange<Shift>::from_to(10, 13);
static constexpr BitRange<Step> NoiseFrequcenyStep = BitRange<Step>::from_to(8, 9);
static constexpr Bit<uint16_t> ReverbMasterEnable = 7;
static constexpr Bit<uint16_t> IRQ9Enable = 6;
static constexpr BitRange<RAMTransferMode> TransferMode = BitRange<RAMTransferMode>::from_to(4, 5);
static constexpr Bit<uint16_t> ExternalAudioReverb = 3;
static constexpr Bit<uint16_t> CDAudioReverb = 2;
static constexpr Bit<uint16_t> ExternalAudioEnable = 1;
static constexpr Bit<uint16_t> 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);
}
}

View File

@ -9,14 +9,19 @@ namespace SPU {
}
static void clear_main_volume() {
static constexpr auto StartVol = SweepVolume().clear_bit(SweepVolume::ModeBit).set_value(static_cast<int16_t>(I16_MAX >> 2), SweepVolume::VolumeRange);
static constexpr auto StartVol = SweepVolume().clear_bit(SweepVolume::SweepEnable).set_value(static_cast<int16_t>(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();
}
}