224 lines
7.8 KiB
C++
224 lines
7.8 KiB
C++
#ifndef __JABYENGINE_SPU_IO_HPP__
|
|
#define __JABYENGINE_SPU_IO_HPP__
|
|
#include "IOPort.hpp"
|
|
#include <limits.h>
|
|
|
|
#include "../../Auxiliary/io_class_helper.hpp"
|
|
|
|
namespace SPU {
|
|
struct __no_align ubus32_t
|
|
{
|
|
uint16_t low;
|
|
uint16_t high;
|
|
|
|
constexpr ubus32_t() : low(0), high(0) {
|
|
}
|
|
|
|
constexpr operator uint32_t() const {
|
|
return ((this->high << 16) | this->low);
|
|
}
|
|
|
|
constexpr void operator=(uint32_t value) {
|
|
this->low = (value & 0xFFFF);
|
|
this->high = (value >> 16);
|
|
}
|
|
|
|
constexpr void operator=(ubus32_t value) volatile {
|
|
this->low = value.low;
|
|
this->high = value.high;
|
|
}
|
|
};
|
|
|
|
enum Mode {
|
|
Linear = 0,
|
|
Exponential = 1,
|
|
};
|
|
|
|
struct __no_align SampleRate {
|
|
uint16_t raw_value = 0;
|
|
|
|
static constexpr SampleRate from_HZ(long double freq)
|
|
{
|
|
//SampleRate is defined as 4096 == 44100Hz
|
|
constexpr long double Base = (4096.0 / 44100.0);
|
|
|
|
return static_cast<SampleRate>(((freq*4096.0)/44100.0));
|
|
}
|
|
};
|
|
|
|
struct __no_align SweepVolume {
|
|
typedef int16_t VolumeStep;
|
|
|
|
static constexpr VolumeStep VolumeMax = 1000;
|
|
static constexpr VolumeStep SingleVolumeStep = (I16_MAX >> 1)/VolumeMax;
|
|
|
|
enum Direction {
|
|
Increase = 0,
|
|
Decrease = 1,
|
|
};
|
|
|
|
enum Phase {
|
|
Positive = 0,
|
|
Negative = 1,
|
|
};
|
|
|
|
int16_t raw_value = 0;
|
|
|
|
constexpr SweepVolume() = default;
|
|
|
|
constexpr auto& set_volume_percent(double percent) {
|
|
this->raw_value = bit::value::set_normalized(this->raw_value, static_cast<int16_t>((I16_MAX/100.0)*percent), __start_end_bit2_start_length(0, 14));
|
|
return *this;
|
|
}
|
|
|
|
constexpr auto& set_volume(int16_t volume) {
|
|
this->raw_value = bit::value::set_normalized(this->raw_value, static_cast<int16_t>((volume >> 1)), __start_end_bit2_start_length(0, 14));
|
|
return *this;
|
|
}
|
|
|
|
constexpr int16_t get_volume_step() const {
|
|
return bit::value::get_normalized(this->raw_value, __start_end_bit2_start_length(0, 14));
|
|
}
|
|
|
|
io_class__2option_map(volume_mode, sweep_mode, 15);
|
|
io_class__2option_map_getter(Mode, linear_sweep_mode, exponential_sweep_mode, sweep_mode_type, 14);
|
|
io_class__2option_map_getter(Direction, increase_sweep_mode, decrease_sweep_mode, sweep_mode_direction, 13);
|
|
io_class__2option_map_getter(Phase, positive_sweep_phase, negative_sweep_phase, sweep_phase, 12);
|
|
|
|
//Uses only 5bit of shift (0..1F (slow..fast))
|
|
constexpr auto& set_sweep_shift(uint8_5b shift) {
|
|
const int16_t crop_value = static_cast<int16_t>(shift); //(bit::value::crop_value(shift, 5));
|
|
this->raw_value = bit::value::set_normalized(this->raw_value, crop_value, __start_end_bit2_start_length(2, 6));
|
|
return *this;
|
|
}
|
|
|
|
constexpr uint8_5b get_sweep_shift() const {
|
|
return bit::value::get_normalized(this->raw_value, __start_end_bit2_start_length(2, 6));
|
|
}
|
|
|
|
//0..3 maps to => +7, +6, +5, +4 or -8, -7, -6, -5
|
|
constexpr auto& set_sweep_step(uint8_2b step) {
|
|
this->raw_value = bit::value::set_normalized(this->raw_value, static_cast<int16_t>(step), __start_end_bit2_start_length(0, 1));
|
|
return *this;
|
|
}
|
|
|
|
constexpr uint8_2b get_sweep_step() const {
|
|
return bit::value::get_normalized(this->raw_value, __start_end_bit2_start_length(0, 1));
|
|
}
|
|
};
|
|
|
|
struct __no_align ADSR {
|
|
ubus32_t raw_value;
|
|
};
|
|
|
|
struct __no_align KeyW {
|
|
ubus32_t raw_value;
|
|
|
|
constexpr KeyW() = default;
|
|
|
|
static constexpr KeyW All1() {
|
|
KeyW value;
|
|
|
|
value.raw_value = static_cast<uint32_t>(0xFFFFFFFF);
|
|
return value;
|
|
}
|
|
|
|
constexpr KeyW& set(size_t id) {
|
|
this->raw_value = bit::set<uint32_t>(this->raw_value, id);
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
struct __no_align KeyR {
|
|
ubus32_t raw_value;
|
|
|
|
constexpr bool is_set(size_t id) const {
|
|
return bit::is_set<uint32_t>(this->raw_value, id);
|
|
}
|
|
};
|
|
|
|
struct __no_align Key {
|
|
static inline __always_inline auto& on = *reinterpret_cast<KeyW*>(0x1F801D88);
|
|
static inline __always_inline auto& off = *reinterpret_cast<KeyW*>(0x1F801D8C);
|
|
static inline __always_inline auto& state = *reinterpret_cast<KeyR*>(0x1F801D9C);
|
|
};
|
|
|
|
struct __no_align Voice {
|
|
static constexpr size_t Count = 24;
|
|
static inline __always_inline auto& Channel = reinterpret_cast<Voice(&)[Count]>(*reinterpret_cast<Voice*>(0x1f801c00));
|
|
|
|
SweepVolume volumeLeft;
|
|
SweepVolume volumeRight;
|
|
SampleRate sampleRate;
|
|
uint16_t adr;
|
|
ADSR adsr;
|
|
SweepVolume currentVolume; //Not used
|
|
uint16_t repeatAdr;
|
|
};
|
|
|
|
struct MainVolume {
|
|
static inline __always_inline auto& Left = *reinterpret_cast<SweepVolume*>(0x1F801D80);
|
|
static inline __always_inline auto& Right = *reinterpret_cast<SweepVolume*>(0x1F801D82);
|
|
};
|
|
|
|
struct __no_align Control {
|
|
static inline __always_inline auto& Register = *reinterpret_cast<Control*>(0x1F801DAA);
|
|
|
|
enum TransferMode
|
|
{
|
|
Stop = 0,
|
|
ManualWrite = (1 << 4),
|
|
DMAWrite = (2 << 4),
|
|
DMARead = (3 << 4),
|
|
};
|
|
|
|
uint16_t raw_value = 0;
|
|
|
|
constexpr Control() = default;
|
|
|
|
io_class__2option_map(off, on, 15);
|
|
io_class__2option_map_getter_is(bool, mute, unmute, 14);
|
|
|
|
constexpr Control& set_noise_shift(uint8_4b shift) {
|
|
this->raw_value = bit::value::set_normalized(this->raw_value, static_cast<uint16_t>(shift), __start_end_bit2_start_length(10, 13));
|
|
return *this;
|
|
}
|
|
|
|
constexpr uint8_4b get_noise_shift() const {
|
|
return bit::value::get_normalized(this->raw_value, __start_end_bit2_start_length(10, 13));
|
|
}
|
|
|
|
constexpr Control& set_noise_step(uint8_2b step) {
|
|
this->raw_value = bit::value::set_normalized(this->raw_value, static_cast<uint16_t>(step), __start_end_bit2_start_length(8, 9));
|
|
return *this;
|
|
}
|
|
|
|
constexpr uint8_2b get_noise_step() const {
|
|
return bit::value::get_normalized(this->raw_value, __start_end_bit2_start_length(8, 9));
|
|
}
|
|
|
|
io_class__2option_map_getter_is(bool, reverb_disabled, reverb_enabled, 7);
|
|
io_class__2option_map(irq9_ack, irq9_enable, 6);
|
|
|
|
constexpr Control& set_transfer_mode(TransferMode mode) {
|
|
this->raw_value = bit::value::set_normalized(this->raw_value, static_cast<uint16_t>(mode), __start_end_bit2_start_length(4, 5));
|
|
return *this;
|
|
}
|
|
|
|
constexpr TransferMode get_transfer_mode() const {
|
|
return static_cast<TransferMode>(bit::value::get_normalized(this->raw_value, __start_end_bit2_start_length(4, 5)));
|
|
}
|
|
|
|
io_class__2option_map_getter_is(bool, external_reverb_off, external_reverb_on, 3);
|
|
io_class__2option_map_getter_is(bool, cd_reverb_off, cd_reverb_on, 2);
|
|
io_class__2option_map_getter_is(bool, external_audio_off, external_audio_on, 1);
|
|
io_class__2option_map_getter_is(bool, cd_audio_disable, cd_audio_enable, 0);
|
|
};
|
|
|
|
struct DataTransferControl {
|
|
static inline __always_inline auto& Register = *reinterpret_cast<IOPort<uint16_t>*>(0x1F801DAC);
|
|
static inline __always_inline volatile auto& vRegister = *reinterpret_cast<IOPort<uint16_t>*>(0x1F801DAC);
|
|
};
|
|
}
|
|
|
|
#endif //!__JABYENGINE_SPU_IO_HPP__
|