Update SPU IO way
This commit is contained in:
@@ -6,151 +6,9 @@ namespace JabyEngine {
|
||||
namespace SPU_IO {
|
||||
using namespace SPU_IO_Values;
|
||||
|
||||
namespace MemoryMap {
|
||||
static constexpr uintptr_t ADPCM = 0x01000;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
__declare_io_value(DataTransferControl, uint16_t) {
|
||||
static constexpr DataTransferControl NormalTransferMode() {
|
||||
return DataTransferControl{0x0004};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_value(SimpleVolume, int16_t) {
|
||||
constexpr operator int16_t() const {
|
||||
return this->raw;
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_value(SampleRate, uint16_t) {
|
||||
static constexpr SampleRate from_HZ(uint32_t freq) {
|
||||
constexpr uint32_t Base1024Hz = static_cast<uint32_t>((4096.0/44100.0)*1024.0);
|
||||
return {static_cast<uint16_t>((freq >> 10)*Base1024Hz)};
|
||||
}
|
||||
|
||||
static constexpr SampleRate from_HZ(double freq) {
|
||||
//4096 == 44100Hz
|
||||
constexpr double Base = (4096.0 / 44100.0);
|
||||
return {static_cast<uint16_t>((freq*Base))};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_value(SweepVolume, int16_t) {
|
||||
// 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);
|
||||
};
|
||||
|
||||
__declare_io_value(SR, uint16_t) {
|
||||
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));
|
||||
};
|
||||
|
||||
__declare_io_value(AD, uint16_t) {
|
||||
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);
|
||||
};
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct Voice {
|
||||
IOPort<SweepVolume> volumeLeft; //Offset: 0x0
|
||||
IOPort<SweepVolume> volumeRight; //Offset: 0x2
|
||||
IOPort<SampleRate> sampleRate; //Offset: 0x4;
|
||||
IOPort<SRAM_Adr> adr; //Offset: 0x6
|
||||
IOPort<AD> ad; //Offset: 0x8
|
||||
IOPort<SR> sr; //Offset: 0xA
|
||||
IOPort<SimpleVolume> currentVolume; //Offset: 0xC
|
||||
IOPort<SRAM_Adr> repeatAdr; //Offset: 0xE
|
||||
|
||||
static constexpr SRAM_Adr start_adr() {
|
||||
return {0x200};
|
||||
}
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
// TODO: This is ubus32_t
|
||||
__declare_io_value(PMON, uint16_t) {
|
||||
static constexpr auto EnableBits = BitRange::from_to(1, 23);
|
||||
};
|
||||
|
||||
// TODO: This is ubus32_t
|
||||
__declare_io_value(NON, uint16_t) {
|
||||
static constexpr auto NoiseBits = BitRange::from_to(0, 23);
|
||||
};
|
||||
|
||||
static constexpr size_t VoiceCount = 24;
|
||||
static constexpr size_t ReverbCount = 1;
|
||||
|
||||
struct Key {
|
||||
__declare_io_port_w_type(inline, ubus32_t, On, 0x1F801D88);
|
||||
__declare_io_port_w_type(inline, ubus32_t, Off, 0x1F801D8C);
|
||||
__declare_io_port_w_type(inline, ubus32_t, Status, 0x1F801D9C);
|
||||
};
|
||||
|
||||
struct MainVolume {
|
||||
__declare_io_port_w_type(inline, SweepVolume, Left, 0x1F801D80);
|
||||
__declare_io_port_w_type(inline, SweepVolume, Right, 0x1F801D82);
|
||||
};
|
||||
|
||||
struct CDVolume {
|
||||
__declare_io_port_w_type(inline, SimpleVolume, Left, 0x1F801DB0);
|
||||
__declare_io_port_w_type(inline, SimpleVolume, Right, 0x1F801DB2);
|
||||
};
|
||||
|
||||
struct ExternalAudioInputVolume {
|
||||
__declare_io_port_w_type(inline, SimpleVolume, Left, 0x1F801DB4);
|
||||
__declare_io_port_w_type(inline, SimpleVolume, Right, 0x1F801DB6);
|
||||
};
|
||||
|
||||
struct Reverb {
|
||||
struct Volume {
|
||||
__declare_io_port_w_type(inline, SimpleVolume, Left, 0x1F801D84);
|
||||
__declare_io_port_w_type(inline, SimpleVolume, Right, 0x1F801D86);
|
||||
};
|
||||
__declare_io_port_w_type(inline, SRAM_Adr, WorkAreaAdr, 0x1F801DA2);
|
||||
};
|
||||
|
||||
static constexpr SimpleVolume operator""_vol(long double fraction) {
|
||||
return {static_cast<int16_t>(static_cast<long double>(I16_MAX)*fraction)};
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
struct ControlRegisterIO : public IOPort<SPU_IO_Values::ControlRegister> {
|
||||
using TransferMode = Value::RAMTransferMode;
|
||||
|
||||
@@ -160,30 +18,71 @@ namespace JabyEngine {
|
||||
}
|
||||
};
|
||||
|
||||
struct EchoIO : public IOPort<SPU_IO_Values::Echo> {
|
||||
using ADIO = IOPort<SPU_IO_Values::AD>;
|
||||
using DataTransferControlIO = IOPort<SPU_IO_Values::DataTransferControl>;
|
||||
using EchoIO = IOPort<SPU_IO_Values::Echo>;
|
||||
using KeyOffIO = IOPort<SPU_IO_Values::KeyOff>;
|
||||
using KeyOnIO = IOPort<SPU_IO_Values::KeyOn>;
|
||||
using KeyStatusIO = IOPort<SPU_IO_Values::KeyStatus>;
|
||||
using NoiseIO = IOPort<SPU_IO_Values::Noise>;
|
||||
using PitchModulationIO = IOPort<SPU_IO_Values::PitchModulation>;
|
||||
using SampleRateIO = IOPort<SPU_IO_Values::SampleRate>;
|
||||
using SimpleVolumeIO = IOPort<SPU_IO_Values::SimpleVolume>;
|
||||
using StatusRegisterIO = IOPort<SPU_IO_Values::StatusRegister>;
|
||||
using SRIO = IOPort<SPU_IO_Values::SR>;
|
||||
using SRAMAdrIO = IOPort<SPU_IO_Values::SRAMAdr>;
|
||||
using SweepVolumeIO = IOPort<SweepVolume>;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct Voice {
|
||||
SweepVolumeIO volumeLeft; //Offset: 0x0
|
||||
SweepVolumeIO volumeRight; //Offset: 0x2
|
||||
SampleRateIO sampleRate; //Offset: 0x4;
|
||||
SRAMAdrIO adr; //Offset: 0x6
|
||||
ADIO ad; //Offset: 0x8
|
||||
SRIO sr; //Offset: 0xA
|
||||
SimpleVolumeIO currentVolume; //Offset: 0xC
|
||||
SRAMAdrIO repeatAdr; //Offset: 0xE
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
static auto& Voice = __new_declare_io_port_array(struct Voice, VoiceCount, 0x1F801C00);
|
||||
static auto& PMON = __new_declare_io_port(PitchModulationIO, 0x1F801D90);
|
||||
static auto& NON = __new_declare_io_port(NoiseIO, 0x1F801D94);
|
||||
static auto& EON = __new_declare_io_port(EchoIO, 0x1F801D98);
|
||||
static auto& SRAMTransferAdr = __new_declare_io_port(SRAMAdrIO, 0x1F801DA6);
|
||||
static auto& ControlRegister = __new_declare_io_port(ControlRegisterIO, 0x1F801DAA);
|
||||
static auto& DataTransferControl = __new_declare_io_port(DataTransferControlIO, 0x1F801DAC);
|
||||
static auto& StatusRegister = __new_declare_io_port(StatusRegisterIO, 0x1F801DAE);
|
||||
|
||||
struct CDVolume {
|
||||
static inline auto& Left = __new_declare_io_port(SimpleVolumeIO, 0x1F801DB0);
|
||||
static inline auto& Right = __new_declare_io_port(SimpleVolumeIO, 0x1F801DB2);
|
||||
};
|
||||
|
||||
struct StatusRegisterIO : public IOPort<SPU_IO_Values::StatusRegister> {
|
||||
struct ExternalAudioInputVolume {
|
||||
static inline auto& Left = __new_declare_io_port(SimpleVolumeIO, 0x1F801DB4);
|
||||
static inline auto& Right = __new_declare_io_port(SimpleVolumeIO, 0x1F801DB6);
|
||||
};
|
||||
|
||||
struct SRAMTransferAddressIO : public IOPort<SPU_IO_Values::SRAM_Adr> {
|
||||
struct Key {
|
||||
static inline auto& On = __new_declare_io_port(KeyOnIO, 0x1F801D88);
|
||||
static inline auto& Off = __new_declare_io_port(KeyOffIO, 0x1F801D8C);
|
||||
static inline auto& Status = __new_declare_io_port(KeyStatusIO, 0x1F801D9C);
|
||||
};
|
||||
|
||||
|
||||
// TODO: The new way? v Parse with a Macro?
|
||||
static auto& EON = *reinterpret_cast<EchoIO*>(0x1F801D98);
|
||||
static auto& SRAMTransferAdr = *reinterpret_cast<SRAMTransferAddressIO*>(0x1F801DA6);
|
||||
static auto& ControlRegister = *reinterpret_cast<ControlRegisterIO*>(0x1F801DAA);
|
||||
static auto& StatusRegister = *reinterpret_cast<StatusRegisterIO*>(0x1F801DAE);
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
struct MainVolume {
|
||||
static inline auto& Left = __new_declare_io_port(SweepVolumeIO, 0x1F801D80);
|
||||
static inline auto& Right = __new_declare_io_port(SweepVolumeIO, 0x1F801D82);
|
||||
};
|
||||
|
||||
//__declare_io_port(, ControlRegister, 0x1F801DAA);
|
||||
__declare_io_port(, DataTransferControl, 0x1F801DAC);
|
||||
__declare_io_port(, PMON, 0x1F801D90);
|
||||
__declare_io_port(, NON, 0x1F801D94);
|
||||
//__declare_io_port(, EON, 0x1F801D98);
|
||||
|
||||
__declare_io_port_array(, Voice, VoiceCount, 0x1F801C00);
|
||||
struct Reverb {
|
||||
struct Volume {
|
||||
static inline auto& Left = __new_declare_io_port(SimpleVolumeIO, 0x1F801D84);
|
||||
static inline auto& Right = __new_declare_io_port(SimpleVolumeIO, 0x1F801D86);
|
||||
};
|
||||
static inline auto& On = EON;
|
||||
static inline auto& WorkAreaAdr = __new_declare_io_port(SRAMAdrIO, 0x1F801DA2);
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user