Prepare SPU and IO Ports related code
This commit is contained in:
parent
367e4d5b3f
commit
febdfb0162
|
@ -0,0 +1,55 @@
|
|||
#ifndef __JABYENGINE_BITS_HPP__
|
||||
#define __JABYENGINE_BITS_HPP__
|
||||
#include "../jabyengine_defines.h"
|
||||
|
||||
namespace bit {
|
||||
template<typename T>
|
||||
static constexpr T set(T raw_value, size_t bit) {
|
||||
return (raw_value | (1 << bit));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static constexpr T clear(T raw_value, size_t bit) {
|
||||
return (raw_value & ~(1 << bit));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static constexpr bool is_set(T raw_value, size_t bit) {
|
||||
return static_cast<bool>(raw_value & (1 << bit));
|
||||
}
|
||||
|
||||
namespace value {
|
||||
template<typename T>
|
||||
static constexpr T crop_value(T raw_value, size_t length) {
|
||||
return (raw_value & ((1 << length) - 1));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static constexpr T range_mask(size_t start_bit, size_t length) {
|
||||
return (((1 << length) - 1) << start_bit);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static constexpr T clear_normalized(T raw_value, size_t start_bit, size_t length) {
|
||||
return (raw_value & ~range_mask<T>(start_bit, length));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static constexpr T set_normalized(T raw_value, T value, size_t start_bit, size_t length) {
|
||||
return (clear_normalized(raw_value, start_bit, length) | (value << start_bit));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static constexpr T get_normalized(T raw_value, size_t start_bit, size_t length) {
|
||||
return (raw_value & range_mask<T>(start_bit, length)) >> start_bit;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
static constexpr S cast(T value) {
|
||||
return *reinterpret_cast<S*>(&value);
|
||||
}
|
||||
}
|
||||
|
||||
#define __start_end_bit2_start_length(start_bit, end_bit) start_bit, (end_bit - start_bit + 1)
|
||||
#endif //!__JABYENGINE_BITS_HPP__
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef __JABYENGINE_IO_CLASS_HELPER_HPP__
|
||||
#define __JABYENGINE_IO_CLASS_HELPER_HPP__
|
||||
#include "bits.hpp"
|
||||
|
||||
#define io_class__2option_map(option0, option1, bit_num) \
|
||||
constexpr void set_##option0() { \
|
||||
this->raw_value = bit::clear(this->raw_value, bit_num); \
|
||||
} \
|
||||
\
|
||||
constexpr void set_##option1() { \
|
||||
this->raw_value = bit::set(this->raw_value, bit_num); \
|
||||
}
|
||||
|
||||
#define io_class__2option_map_getter(type, option0, option1, name, bit_num) \
|
||||
io_class__2option_map(option0, option1, bit_num) \
|
||||
io_class__option_as(type, name, bit_num)
|
||||
|
||||
#define io_class__option_as(type, name, bit_num) \
|
||||
constexpr type get_##name() const { \
|
||||
return static_cast<type>(bit::is_set(this->raw_value, bit_num)); \
|
||||
}
|
||||
|
||||
#endif //!__JABYENGINE_IO_CLASS_HELPER_HPP__
|
|
@ -0,0 +1,83 @@
|
|||
#ifndef __JABYENGINE_SPU_PORTS_HPP__
|
||||
#define __JABYENGINE_SPU_PORTS_HPP__
|
||||
#include "../Auxiliary/io_class_helper.hpp"
|
||||
|
||||
namespace SPU {
|
||||
//SampleRate is defined as 4096 == 44100Hz
|
||||
struct __no_align SampleRate {
|
||||
uint16_t raw_value = 0;
|
||||
|
||||
static constexpr SampleRate from_HZ(long double freq)
|
||||
{
|
||||
constexpr long double Base = (4096.0 / 44100.0);
|
||||
|
||||
return static_cast<SampleRate>(((freq*4096.0)/44100.0));
|
||||
}
|
||||
};
|
||||
|
||||
struct __no_align SweepVolume {
|
||||
enum Type {
|
||||
Linear = 0,
|
||||
Exponential = 1,
|
||||
};
|
||||
|
||||
enum Direction {
|
||||
Increase = 0,
|
||||
Decrease = 1,
|
||||
};
|
||||
|
||||
enum Phase {
|
||||
Positive = 0,
|
||||
Negative = 1,
|
||||
};
|
||||
|
||||
uint16_t raw_value = 0;
|
||||
|
||||
constexpr SweepVolume() = default;
|
||||
|
||||
constexpr void set_volume(int16_t volume) {
|
||||
this->raw_value = bit::value::set_normalized(this->raw_value, bit::cast<uint16_t>(volume >> 1), __start_end_bit2_start_length(0, 14));
|
||||
}
|
||||
|
||||
constexpr int16_t get_volume() const {
|
||||
return bit::cast<int16_t>(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(Type, 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 void set_sweep_shift(uint8_5b shift) {
|
||||
const uint16_t crop_value = static_cast<uint16_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));
|
||||
}
|
||||
|
||||
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 void set_sweep_step(uint8_2b step) {
|
||||
this->raw_value = bit::value::set_normalized(this->raw_value, static_cast<uint16_t>(step), __start_end_bit2_start_length(0, 1));
|
||||
}
|
||||
|
||||
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 Voice {
|
||||
SweepVolume volumeLeft;
|
||||
SweepVolume volumeRight;
|
||||
/*VolatileValue<SampleRate> sampleRate;
|
||||
VolatileValue<uint16_t> adr;
|
||||
VolatileValue<uint16_t> ad; //0x...08: 15 - 0
|
||||
VolatileValue<uint16_t> sr; //0x...0A: 31 - 16
|
||||
VolatileValue<uint16_t> currentVolume; //Not used
|
||||
VolatileValue<uint16_t> repeatAdr;*/
|
||||
};
|
||||
}
|
||||
|
||||
#endif //!__JABYENGINE_SPU_PORTS_HPP__
|
|
@ -14,4 +14,8 @@
|
|||
#define __constexpr
|
||||
#endif
|
||||
|
||||
//uint<real bits>_<used bits>b;
|
||||
typedef uint8_t uint8_5b;
|
||||
typedef uint8_t uint8_2b;
|
||||
|
||||
#endif //!__JABYENGINE_DEFINES__H
|
|
@ -48,6 +48,7 @@ CCFLAGS += -ffunction-sections
|
|||
endif
|
||||
CCFLAGS += -mno-gpopt -fomit-frame-pointer
|
||||
CCFLAGS += -fno-builtin -fno-strict-aliasing -Wno-attributes
|
||||
CCFLAGS += -std=c++20
|
||||
CCFLAGS += $(ARCHFLAGS)
|
||||
|
||||
CCFLAGS += $(CCFLAGS_$(BUILD_PROFILE))
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
#include <PSX/SPU/SPU_Ports.hpp>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace JabyEngine {
|
||||
void start() {
|
||||
SPU::SweepVolume b;
|
||||
|
||||
b.set_volume(9);
|
||||
printf("Hello Planschbecken\n");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue