Clear MainVolume and improve port code
This commit is contained in:
parent
5006c6e9c6
commit
d08b3e71bf
|
@ -52,13 +52,13 @@ public:
|
||||||
|
|
||||||
template<typename S>
|
template<typename S>
|
||||||
constexpr IOPort<T>& clear_bit(S bit) {
|
constexpr IOPort<T>& clear_bit(S bit) {
|
||||||
this->value = bit::set(this->value, static_cast<size_t>(bit));
|
this->value = bit::clear(this->value, static_cast<size_t>(bit));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename S>
|
template<typename S>
|
||||||
constexpr void clear_bit(S bit) volatile {
|
constexpr void clear_bit(S bit) volatile {
|
||||||
this->value = bit::set(this->value, static_cast<size_t>(bit));
|
this->value = bit::clear(this->value, static_cast<size_t>(bit));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename S>
|
template<typename S>
|
||||||
|
@ -164,4 +164,10 @@ static constexpr uintptr_t IO_Base_Mask = 0xF0000000;
|
||||||
static constexpr uintptr_t IO_Base_Adr = 0x10000000;
|
static constexpr uintptr_t IO_Base_Adr = 0x10000000;
|
||||||
|
|
||||||
#define __declare_io_port_global(type, name, adr) static __always_inline auto& name = *reinterpret_cast<IOPort<type>*>((IO_Base_Adr + (adr & ~IO_Base_Mask)))
|
#define __declare_io_port_global(type, name, adr) static __always_inline auto& name = *reinterpret_cast<IOPort<type>*>((IO_Base_Adr + (adr & ~IO_Base_Mask)))
|
||||||
|
#define __io_port_inherit(name) \
|
||||||
|
using IOPort::operator=; \
|
||||||
|
constexpr name() = default; \
|
||||||
|
constexpr name(IOPort value) : IOPort(value) { \
|
||||||
|
}
|
||||||
|
|
||||||
#endif //!__JABYENGINE_IOPORT_HPP__
|
#endif //!__JABYENGINE_IOPORT_HPP__
|
|
@ -4,6 +4,7 @@
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
namespace SPU {
|
namespace SPU {
|
||||||
|
namespace Port {
|
||||||
enum struct SweepMode {
|
enum struct SweepMode {
|
||||||
Linear = 0,
|
Linear = 0,
|
||||||
Exponential = 1,
|
Exponential = 1,
|
||||||
|
@ -26,17 +27,19 @@ namespace SPU {
|
||||||
typedef uint8_t SweepStep;
|
typedef uint8_t SweepStep;
|
||||||
|
|
||||||
struct __no_align SampleRate : public IOPort<uint16_t> {
|
struct __no_align SampleRate : public IOPort<uint16_t> {
|
||||||
using IOPort<uint16_t>::IOPort;
|
__io_port_inherit(SampleRate);
|
||||||
|
|
||||||
static constexpr SampleRate from_HZ(double freq) {
|
static constexpr SampleRate from_HZ(double freq) {
|
||||||
//4096 == 44100Hz
|
//4096 == 44100Hz
|
||||||
constexpr double Base = (4096.0 / 44100.0);
|
constexpr double Base = (4096.0 / 44100.0);
|
||||||
|
|
||||||
return static_cast<uint16_t>((freq*Base));
|
return IOPort(static_cast<uint16_t>((freq*Base)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct __no_align SweepVolume : public IOPort<int16_t> {
|
struct __no_align SweepVolume : public IOPort<int16_t> {
|
||||||
|
__io_port_inherit(SweepVolume);
|
||||||
|
|
||||||
// For Volume Mode
|
// For Volume Mode
|
||||||
static constexpr Bit<int16_t> ModeBit = 15; // 0 Volume Mode; 1 Sweep 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 BitRange<int16_t> VolumeRange = BitRange<int16_t>::from_to(0, 14);
|
||||||
|
@ -82,6 +85,12 @@ namespace SPU {
|
||||||
__declare_io_port_global(ubus32_t, off, 0x1F801D8C);
|
__declare_io_port_global(ubus32_t, off, 0x1F801D8C);
|
||||||
__declare_io_port_global(ubus32_t, status, 0x1F801D9C);
|
__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__
|
#endif //!__JABYENGINE_SPU_IO_HPP__
|
|
@ -2,11 +2,21 @@
|
||||||
#include <PSX/System/IOPorts/IOPort.hpp>
|
#include <PSX/System/IOPorts/IOPort.hpp>
|
||||||
|
|
||||||
namespace SPU {
|
namespace SPU {
|
||||||
|
using namespace Port;
|
||||||
|
|
||||||
static void clear_key() {
|
static void clear_key() {
|
||||||
Key::off.write(UI32_MAX);
|
Key::off.write(UI32_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
MainVolume::left.write(StartVol);
|
||||||
|
MainVolume::right.write(StartVol);
|
||||||
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
clear_key();
|
clear_key();
|
||||||
|
clear_main_volume();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue