Improve readability of code slightly

This commit is contained in:
Jaby 2023-03-21 21:51:56 +01:00
parent f4cc1c5ea5
commit 9a964a702e
11 changed files with 127 additions and 117 deletions

View File

@ -22,11 +22,11 @@ namespace JabyEngine {
#endif #endif
static void enable() { static void enable() {
GPU_IO::GP1 = *GPU_IO::Command::SetDisplayState(GPU_IO::DisplayState::On); GPU_IO::GP1 = GPU_IO::Command::SetDisplayState(GPU_IO::DisplayState::On);
} }
static void disable() { static void disable() {
GPU_IO::GP1 = *GPU_IO::Command::SetDisplayState(GPU_IO::DisplayState::Off); GPU_IO::GP1 = GPU_IO::Command::SetDisplayState(GPU_IO::DisplayState::Off);
} }
}; };

View File

@ -95,7 +95,7 @@ namespace JabyEngine {
} }
static void enable_extended(InterruptEnable_v& port) { static void enable_extended(InterruptEnable_v& port) {
port = *InterruptEnable_t::from(InterruptEnable_t::InterruptTypValue.range_max<uint8_t>(), InterruptEnable_t::UnknownIRQ, InterruptEnable_t::CommandStartIRQ); port = InterruptEnable_t::from(InterruptEnable_t::InterruptTypValue.range_max<uint8_t>(), InterruptEnable_t::UnknownIRQ, InterruptEnable_t::CommandStartIRQ);
} }
static Type get_type(const InterruptFlag_v& port) { static Type get_type(const InterruptFlag_v& port) {
@ -107,7 +107,7 @@ namespace JabyEngine {
} }
static void ack_extended(InterruptFlag_v& port) { static void ack_extended(InterruptFlag_v& port) {
port = *InterruptFlag_v::from(InterruptFlag_v::InterruptTypValue.range_max<uint8_t>(), InterruptEnable_v::UnknownIRQ, InterruptEnable_v::CommandStartIRQ); port = InterruptFlag_v::from(InterruptFlag_v::InterruptTypValue.range_max<uint8_t>(), InterruptEnable_v::UnknownIRQ, InterruptEnable_v::CommandStartIRQ);
} }
}; };

View File

@ -163,7 +163,7 @@ namespace JabyEngine {
} }
static constexpr GP1_t DisplayMode(DisplayMode_t mode) { static constexpr GP1_t DisplayMode(DisplayMode_t mode) {
return {Helper::construct_cmd(0x08, *mode)}; return {Helper::construct_cmd(0x08, mode)};
} }
}; };

View File

@ -47,15 +47,21 @@ namespace JabyEngine {
} }
}; };
template<typename T> namespace IOPort {
struct NormalValue { struct IOValueType {
typedef T Value; template<typename T>
}; struct Normal {
typedef T Value;
typedef T UnderlyingValue;
};
template<typename T> template<typename T>
struct VolatileValue { struct Volatile {
typedef volatile T Value; typedef volatile T Value;
}; typedef T UnderlyingValue;
};
};
}
#define __declare_new_named_io_port(type, name, adr) \ #define __declare_new_named_io_port(type, name, adr) \
static inline auto& name = *reinterpret_cast<type##_v*>(adr) static inline auto& name = *reinterpret_cast<type##_v*>(adr)
@ -69,73 +75,77 @@ namespace JabyEngine {
#define __declare_new_io_port_array(name, adr, size) \ #define __declare_new_io_port_array(name, adr, size) \
static inline auto& name = reinterpret_cast<name##_v(&)[size]>(*reinterpret_cast<name##_v*>(adr)) static inline auto& name = reinterpret_cast<name##_v(&)[size]>(*reinterpret_cast<name##_v*>(adr))
#define __declare_io_type(name, type, ...) \ #define __declare_io_type(name, type, ...) \
template<template<typename> typename T> \ /*We need this type to be a POD sadly*/ \
struct name##_io_base { \ template<template<typename> typename T> \
T<type>::Value raw_value = 0; \ struct name##_io_base { \
typedef name##_io_base Self; \ typedef T<type>::UnderlyingValue UnderlyingValue; \
\ typedef name##_io_base Self; \
__VA_ARGS__ \ \
template<typename...ARGS> \ T<type>::Value raw_value = 0; \
static constexpr name##_io_base from(const ARGS&...args) { \ \
return name##_io_base().set_va(args...); \ __VA_ARGS__ \
} \ \
constexpr name##_io_base& set(IOBitSet bit) { \ template<typename...ARGS> \
this->raw_value = bit::set(this->raw_value, bit.pos); \ static constexpr Self from(const ARGS&...args) { \
return *this; \ return Self().set_va(args...); \
} \ } \
\ \
constexpr name##_io_base& set(IOBitUnset bit) { \ constexpr Self& set(IOBitSet bit) { \
this->raw_value = bit::clear(this->raw_value, bit.pos); \ this->raw_value = bit::set(this->raw_value, bit.pos); \
return *this; \ return *this; \
} \ } \
\ \
constexpr name##_io_base& set(IOValueSet bits, type value) { \ constexpr Self& set(IOBitUnset bit) { \
this->raw_value = bit::value::set_normalized(this->raw_value, value, bits.pos, bits.length); \ this->raw_value = bit::clear(this->raw_value, bit.pos); \
return *this; \ return *this; \
} \ } \
\ \
template<typename S> \ constexpr Self& set(IOValueSet bits, UnderlyingValue value) { \
constexpr name##_io_base& set(const IOValueSet::IOValueSetPair<S>& value) { \ this->raw_value = bit::value::set_normalized(this->raw_value, value, bits.pos, bits.length); \
this->set(value.first, static_cast<type>(value.second)); \ return *this; \
return *this; \ } \
} \ \
\ template<typename S> \
template<typename S> \ constexpr Self& set(const IOValueSet::IOValueSetPair<S>& value) { \
constexpr name##_io_base& set_va(const S& head) { \ this->set(value.first, static_cast<UnderlyingValue>(value.second)); \
return this->set(head); \ return *this; \
} \ } \
template<typename S, typename...ARGS> \ \
constexpr name##_io_base& set_va(const S& head, const ARGS&...tail) { \ template<typename S> \
return this->set(head).set_va(tail...); \ constexpr Self& set_va(const S& head) { \
} \ return this->set(head); \
constexpr type get(IOValueSet bits) const { \ } \
return bit::value::get_normalized(this->raw_value, bits.pos, bits.length); \ \
} \ template<typename S, typename...ARGS> \
\ constexpr Self& set_va(const S& head, const ARGS&...tail) { \
\ return this->set(head).set_va(tail...); \
constexpr name##_io_base& clear(IOBitSet bit) { \ } \
this->raw_value = bit::clear(this->raw_value, bit.pos); \ \
return *this; \ constexpr UnderlyingValue get(IOValueSet bits) const { \
} \ return bit::value::get_normalized(this->raw_value, bits.pos, bits.length); \
\ } \
\ \
constexpr bool is_set(IOBitSet bit) const { \ constexpr Self& clear(IOBitSet bit) { \
return bit::is_set(this->raw_value, bit.pos); \ this->raw_value = bit::clear(this->raw_value, bit.pos); \
} \ return *this; \
\ } \
\ \
constexpr void operator=(type value) { \ constexpr bool is_set(IOBitSet bit) const { \
this->raw_value = value; \ return bit::is_set(this->raw_value, bit.pos); \
} \ } \
\ \
constexpr type operator*() const { \ constexpr void operator=(UnderlyingValue value) { \
return this->raw_value; \ this->raw_value = value; \
} \ } \
}; \ \
\ constexpr operator UnderlyingValue() const { \
typedef name##_io_base<VolatileValue> name##_v; \ return this->raw_value; \
typedef name##_io_base<NormalValue> name##_t \ } \
}; \
\
typedef name##_io_base<IOPort::IOValueType::Volatile> name##_v; \
typedef name##_io_base<IOPort::IOValueType::Normal> name##_t
template<typename T> template<typename T>
struct VolatilePOD { struct VolatilePOD {
@ -196,8 +206,8 @@ namespace JabyEngine {
} }
constexpr operator uint32_t() const { constexpr operator uint32_t() const {
const uint32_t high = *this->high; const uint32_t high = this->high;
const uint32_t low = *this->low; const uint32_t low = this->low;
return ((high << 16) | low); return ((high << 16) | low);
} }

View File

@ -47,7 +47,7 @@ namespace JabyEngine {
} }
constexpr void set_mode(CounterMode_t mode) { constexpr void set_mode(CounterMode_t mode) {
this->mode = *mode; this->mode = mode;
} }
}; };

View File

@ -14,12 +14,12 @@ namespace JabyEngine {
#ifdef JABYENGINE_PAL #ifdef JABYENGINE_PAL
static constexpr uint16_t FirstVisiblePixelV = 0xA3; static constexpr uint16_t FirstVisiblePixelV = 0xA3;
GPU_IO::GP1 = *GPU_IO::Command::DisplayMode(GPU_IO::DisplayMode_t::PAL()); GPU_IO::GP1 = GPU_IO::Command::DisplayMode(GPU_IO::DisplayMode_t::PAL());
GPU::Screen::set_offset(0, 0); GPU::Screen::set_offset(0, 0);
#else #else
static constexpr uint16_t FirstVisiblePixelV = 0x88; static constexpr uint16_t FirstVisiblePixelV = 0x88;
GPU_IO::GP1 = *GPU_IO::Command::DisplayMode(GPU_IO::DisplayMode_t::NTSC()); GPU_IO::GP1 = GPU_IO::Command::DisplayMode(GPU_IO::DisplayMode_t::NTSC());
GPU::Screen::set_offset(0, 5); //< Random values GPU::Screen::set_offset(0, 5); //< Random values
#endif #endif
} }
@ -28,18 +28,18 @@ namespace JabyEngine {
}; };
static void set_draw_area(uint16_t x, uint16_t y) { static void set_draw_area(uint16_t x, uint16_t y) {
GPU_IO::GP0 = *GPU_IO::Command::DrawAreaTopLeft(x, y); GPU_IO::GP0 = GPU_IO::Command::DrawAreaTopLeft(x, y);
GPU_IO::GP0 = *GPU_IO::Command::DrawAreaBottomRight((x + Display::Width), (y + Display::Height)); GPU_IO::GP0 = GPU_IO::Command::DrawAreaBottomRight((x + Display::Width), (y + Display::Height));
} }
static void quick_fill_fast(const Color24& color, const PositionU16& pos, const SizeU16& size) { static void quick_fill_fast(const Color24& color, const PositionU16& pos, const SizeU16& size) {
GPU_IO::GP0 = *GPU_IO::Command::QuickFill(color); GPU_IO::GP0 = GPU_IO::Command::QuickFill(color);
GPU_IO::GP0 = *GPU_IO::Command::TopLeftPosition(pos.x, pos.y); GPU_IO::GP0 = GPU_IO::Command::TopLeftPosition(pos.x, pos.y);
GPU_IO::GP0 = *GPU_IO::Command::WidthHeight(size.width, size.height); GPU_IO::GP0 = GPU_IO::Command::WidthHeight(size.width, size.height);
} }
static void reset_cmd_buffer() { static void reset_cmd_buffer() {
GPU_IO::GP1 = *GPU_IO::Command::ResetCMDBufer(); GPU_IO::GP1 = GPU_IO::Command::ResetCMDBufer();
} }
static void wait_ready_for_CMD() { static void wait_ready_for_CMD() {
@ -57,7 +57,7 @@ namespace JabyEngine {
namespace Receive { namespace Receive {
static void prepare() { static void prepare() {
GPU_IO::GP1 = *GPU_IO::Command::DMADirection(GPU_IO::DMADirection::CPU2GPU); GPU_IO::GP1 = GPU_IO::Command::DMADirection(GPU_IO::DMADirection::CPU2GPU);
reset_cmd_buffer(); reset_cmd_buffer();
} }
@ -67,16 +67,16 @@ namespace JabyEngine {
static void set_dst(const PositionU16& position, const SizeU16& size) { static void set_dst(const PositionU16& position, const SizeU16& size) {
wait_ready_for_CMD(); wait_ready_for_CMD();
GPU_IO::GP0 = *GPU_IO::Command::CPU2VRAM_Blitting(); GPU_IO::GP0 = GPU_IO::Command::CPU2VRAM_Blitting();
GPU_IO::GP0 = *GPU_IO::Command::TopLeftPosition(position.x, position.y); GPU_IO::GP0 = GPU_IO::Command::TopLeftPosition(position.x, position.y);
GPU_IO::GP0 = *GPU_IO::Command::WidthHeight(size.width, size.height); GPU_IO::GP0 = GPU_IO::Command::WidthHeight(size.width, size.height);
} }
static void start(uint16_t blockCount, uint16_t wordsPerBlock = 0x10) { static void start(uint16_t blockCount, uint16_t wordsPerBlock = 0x10) {
typedef DMA_IO::BCR_t::SyncMode1 SyncMode1; typedef DMA_IO::BCR_t::SyncMode1 SyncMode1;
DMA_IO::GPU.block_ctrl = *DMA_IO::BCR_t::from(SyncMode1::BlockSize.with(wordsPerBlock), SyncMode1::BlockAmount.with(blockCount)); DMA_IO::GPU.block_ctrl = DMA_IO::BCR_t::from(SyncMode1::BlockSize.with(wordsPerBlock), SyncMode1::BlockAmount.with(blockCount));
DMA_IO::GPU.channel_ctrl = *DMA_IO::CHCHR_t::StartGPUReceive(); DMA_IO::GPU.channel_ctrl = DMA_IO::CHCHR_t::StartGPUReceive();
} }
} }
} }

View File

@ -49,7 +49,7 @@ namespace JabyEngine {
} }
void setup() { void setup() {
GPU_IO::GP1 = *GPU_IO::Command::Reset(); GPU_IO::GP1 = GPU_IO::Command::Reset();
internal::Screen::configurate(); internal::Screen::configurate();
internal::Screen::exchange_buffer_and_display(); internal::Screen::exchange_buffer_and_display();

View File

@ -11,8 +11,8 @@ namespace JabyEngine {
static void clear_main_volume() { static void clear_main_volume() {
static constexpr auto StartVol = SweepVolume_t::from(SweepVolume_t::VolumeEnable, SweepVolume_t::Volume.with(static_cast<int16_t>(I16_MAX >> 2))); static constexpr auto StartVol = SweepVolume_t::from(SweepVolume_t::VolumeEnable, SweepVolume_t::Volume.with(static_cast<int16_t>(I16_MAX >> 2)));
MainVolume::Left = *StartVol; MainVolume::Left = StartVol;
MainVolume::Right = *StartVol; MainVolume::Right = StartVol;
} }
static void clear_cd_and_ext_audio_volume() { static void clear_cd_and_ext_audio_volume() {
@ -29,11 +29,11 @@ namespace JabyEngine {
static void clear_voice() { static void clear_voice() {
for(auto& voice : SPU_IO::Voice) { for(auto& voice : SPU_IO::Voice) {
voice.volumeLeft = *SweepVolume_t(); voice.volumeLeft = SweepVolume_t();
voice.volumeRight = *SweepVolume_t(); voice.volumeRight = SweepVolume_t();
voice.sampleRate = *SampleRate_t(); voice.sampleRate = SampleRate_t();
voice.ad = *AD_t(); voice.ad = AD_t();
voice.sr = *SR_t(); voice.sr = SR_t();
voice.currentVolume = 0; voice.currentVolume = 0;
voice.adr = 0x200; voice.adr = 0x200;
@ -42,12 +42,12 @@ namespace JabyEngine {
} }
static void clear_pmon() { static void clear_pmon() {
SPU_IO::PMON = *PMON_t(); SPU_IO::PMON = PMON_t();
} }
static void clear_noise_and_echo() { static void clear_noise_and_echo() {
SPU_IO::NON = *NON_t(); SPU_IO::NON = NON_t();
SPU_IO::EON = *EON_t(); SPU_IO::EON = EON_t();
} }
static void clear_reverb() { static void clear_reverb() {
@ -59,7 +59,7 @@ namespace JabyEngine {
static void setup_control_register() { static void setup_control_register() {
static constexpr auto SetupValue = ControlRegister_t::from(ControlRegister_t::Enable, ControlRegister_t::Unmute, ControlRegister_t::CDAudioEnable); static constexpr auto SetupValue = ControlRegister_t::from(ControlRegister_t::Enable, ControlRegister_t::Unmute, ControlRegister_t::CDAudioEnable);
SPU_IO::ControlRegister = *SetupValue; SPU_IO::ControlRegister = SetupValue;
} }
static void setup_data_transfer_control() { static void setup_data_transfer_control() {

View File

@ -9,8 +9,8 @@ namespace JabyEngine {
namespace boot { namespace boot {
namespace Start { namespace Start {
static void enable_DMA() { static void enable_DMA() {
const auto dpcr = DMA_IO::DPCR_t(*DMA_IO::DPCR).set(DMA_IO::DPCR_t::SPUEnable).set(DMA_IO::DPCR_t::GPUEnable); const auto dpcr = DMA_IO::DPCR_t(DMA_IO::DPCR).set(DMA_IO::DPCR_t::SPUEnable).set(DMA_IO::DPCR_t::GPUEnable);
DMA_IO::DPCR = *dpcr; DMA_IO::DPCR = dpcr;
} }
JabyEngine::NextRoutine setup() { JabyEngine::NextRoutine setup() {

View File

@ -31,7 +31,7 @@ namespace JabyEngine {
}; };
if(Interrupt::is_irq(Interrupt::CDROM)) { if(Interrupt::is_irq(Interrupt::CDROM)) {
const uint8_t old_idx = (*CD_IO::IndexStatus & 0x3); const uint8_t old_idx = (CD_IO::IndexStatus & 0x3);
CD_IO::PortIndex1::change_to(); CD_IO::PortIndex1::change_to();
const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag); const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag);

View File

@ -16,7 +16,7 @@ namespace JabyEngine {
void Screen :: exchange_buffer_and_display() { void Screen :: exchange_buffer_and_display() {
GPU::internal::set_draw_area(0, (Display::Height*PublicScreenClass::CurrentDisplayAreaID)); GPU::internal::set_draw_area(0, (Display::Height*PublicScreenClass::CurrentDisplayAreaID));
PublicScreenClass::CurrentDisplayAreaID ^= 1; PublicScreenClass::CurrentDisplayAreaID ^= 1;
GPU_IO::GP1 = *GPU_IO::Command::DisplayArea(0, (Display::Height*PublicScreenClass::CurrentDisplayAreaID)); GPU_IO::GP1 = GPU_IO::Command::DisplayArea(0, (Display::Height*PublicScreenClass::CurrentDisplayAreaID));
} }
} }
@ -25,13 +25,13 @@ namespace JabyEngine {
x += 78; x += 78;
y += 43; y += 43;
GPU_IO::GP1 = *GPU_IO::Command::HorizontalDisplayRange((x << 3), (x + Display::Width) << 3); GPU_IO::GP1 = GPU_IO::Command::HorizontalDisplayRange((x << 3), (x + Display::Width) << 3);
GPU_IO::GP1 = *GPU_IO::Command::VerticalDisplayRange(y, y + Display::Height); GPU_IO::GP1 = GPU_IO::Command::VerticalDisplayRange(y, y + Display::Height);
} }
#else #else
void Screen :: set_offset(uint16_t x, uint16_t y) { void Screen :: set_offset(uint16_t x, uint16_t y) {
GPU_IO::GP1 = *GPU_IO::Command::HorizontalDisplayRange(x, (x + Display::Width*8)); GPU_IO::GP1 = GPU_IO::Command::HorizontalDisplayRange(x, (x + Display::Width*8));
GPU_IO::GP1 = *GPU_IO::Command::VerticalDisplayRange(y - (ScanlinesV/2), y + (ScanlinesV/2)); GPU_IO::GP1 = GPU_IO::Command::VerticalDisplayRange(y - (ScanlinesV/2), y + (ScanlinesV/2));
} }
#endif //USE_NO$PSX #endif //USE_NO$PSX
} }