From f4cc1c5ea5183c7cf3072ed2049edef99a5f49d3 Mon Sep 17 00:00:00 2001 From: Jaby Date: Tue, 21 Mar 2023 20:39:51 +0100 Subject: [PATCH] Ported CDIOs --- include/PSX/System/IOPorts/cd_io.hpp | 180 ++++++++++++------------- include/PSX/System/IOPorts/ioport.hpp | 5 + src/Library/include/CD/cd_internal.hpp | 14 +- src/Library/src/BootLoader/cd_boot.cpp | 4 +- src/Library/src/CD/cd.cpp | 8 +- 5 files changed, 107 insertions(+), 104 deletions(-) diff --git a/include/PSX/System/IOPorts/cd_io.hpp b/include/PSX/System/IOPorts/cd_io.hpp index 416fdbab..1f4d0198 100644 --- a/include/PSX/System/IOPorts/cd_io.hpp +++ b/include/PSX/System/IOPorts/cd_io.hpp @@ -31,56 +31,54 @@ namespace JabyEngine { static constexpr uint8_t Max = 0xFF; }; - typedef struct IndexStatus : public ComplexBitMap { - static constexpr auto PortIndex = BitRange::from_to(0, 1); - static constexpr auto HasXAFifoData = Bit(2); - static constexpr auto IsParameterFifoEmpty = Bit(3); - static constexpr auto HasParameterFifoSpace = Bit(4); - static constexpr auto HasResponseFifoData = Bit(5); - static constexpr auto HasDataFifoData = Bit(6); - static constexpr auto IsTransmissionBusy = Bit(7); - } IndexStatus_t; + __declare_io_type(IndexStatus, uint8_t, + static constexpr auto PortIndex = IOValueSet::from_to(0, 1); + static constexpr auto HasXAFifoData = IOBitSet(2); + static constexpr auto IsParameterFifoEmpty = IOBitSet(3); + static constexpr auto HasParameterFifoSpace = IOBitSet(4); + static constexpr auto HasResponseFifoData = IOBitSet(5); + static constexpr auto HasDataFifoData = IOBitSet(6); + static constexpr auto IsTransmissionBusy = IOBitSet(7); + ); - struct InterruptEnable : public ComplexBitMap { - static constexpr auto InterruptTypValue = BitRange::from_to(0, 2); - static constexpr auto InterruptExtended = BitRange::from_to(0, 4); - static constexpr auto UnknownIRQ = Bit(3); - static constexpr auto CommandStartIRQ = Bit(4); - }; - typedef InterruptEnable InterruptFlag; + __declare_io_type(InterruptEnable, uint8_t, + static constexpr auto InterruptTypValue = IOValueSet::from_to(0, 2); + static constexpr auto InterruptExtended = IOValueSet::from_to(0, 4); + static constexpr auto UnknownIRQ = IOBitSet(3); + static constexpr auto CommandStartIRQ = IOBitSet(4); + ); + typedef InterruptEnable_v InterruptFlag_v; - struct Request : public ComplexBitMap { - static constexpr auto WantCommandStartIRQ = Bit(5); - static constexpr auto WantData = Bit(7); - }; + __declare_io_type(Request, uint8_t, + static constexpr auto WantCommandStartIRQ = IOBitSet(5); + static constexpr auto WantData = IOBitSet(7); + ); - struct SoundMapCoding : public ComplexBitMap { - static constexpr auto Stereo = Bit(0); + __declare_io_type(SoundMapCoding, uint8_t, + static constexpr auto Stereo = IOBitSet(0); static constexpr auto Mono = !Stereo; - static constexpr auto SampleRate_18900hz = Bit(2); + static constexpr auto SampleRate_18900hz = IOBitSet(2); static constexpr auto SampleRate_37800hz = !SampleRate_18900hz; - static constexpr auto BitsPerSample8 = Bit(4); + static constexpr auto BitsPerSample8 = IOBitSet(4); static constexpr auto BitsPerSample4 = !BitsPerSample8; - static constexpr auto Emphasis = Bit(6); - }; + static constexpr auto Emphasis = IOBitSet(6); + ); - struct AudioVolumeApply : public ComplexBitMap { - static constexpr auto Mute = Bit(0); - static constexpr auto ApplyChanges = Bit(5); - }; + __declare_io_type(AudioVolumeApply, uint8_t, + static constexpr auto Mute = IOBitSet(0); + static constexpr auto ApplyChanges = IOBitSet(5); + ); - typedef VolatilePOD ResponseFifo_t; - typedef VolatilePOD CommandFifo_t; - typedef VolatilePOD DataFifo_t; - typedef VolatilePOD DataFifo16_t; - typedef VolatilePOD ParameterFifo_t; - typedef VolatilePOD SoundMapDataOut_t; - typedef VolatilePOD VolumeRegister_t; - typedef VolatileBitMapPOD InterruptEnableRegister_t; - typedef VolatileBitMapPOD InterruptFlagRegister_t; - typedef VolatileBitMapPOD RequestRegister_t; - typedef VolatileBitMapPOD SoundMapCodingInfo_t; - typedef VolatileBitMapPOD AudioVolumeApplyChange_t; + __declare_io_type(ResponseFifo, uint8_t,); + __declare_io_type(CommandFifo, uint8_t,); + __declare_io_type(DataFifo, uint8_t,); + __declare_io_type(DataFifo16, uint16_t,); + __declare_io_type(ParameterFifo, uint8_t,); + __declare_io_type(SoundMapDataOut, uint8_t,); + __declare_io_type(LeftCD2LeftSPU, CDDAVolume::Type,); + __declare_io_type(LeftCD2RightSPU, CDDAVolume::Type,); + __declare_io_type(RightCD2RightSPU,CDDAVolume::Type,); + __declare_io_type(RightCD2LeftSPU, CDDAVolume::Type,); struct Interrupt { enum Type : uint8_t { @@ -92,110 +90,110 @@ namespace JabyEngine { DiskError = 5 }; - static void enable(InterruptEnableRegister_t& port) { - port.write(InterruptEnable::InterruptTypValue.max()); + static void enable(InterruptEnable_v& port) { + port.set(InterruptEnable_t::InterruptTypValue.range_max()); } - static void enable_extended(InterruptEnableRegister_t& port) { - port.write({InterruptEnable::with(InterruptEnable::InterruptTypValue.max(), InterruptEnable::UnknownIRQ, InterruptEnable::CommandStartIRQ)}); + static void enable_extended(InterruptEnable_v& port) { + port = *InterruptEnable_t::from(InterruptEnable_t::InterruptTypValue.range_max(), InterruptEnable_t::UnknownIRQ, InterruptEnable_t::CommandStartIRQ); } - static Type get_type(const InterruptFlagRegister_t& port) { - return static_cast(port.read().get_value(InterruptFlag::InterruptTypValue)); + static Type get_type(const InterruptFlag_v& port) { + return static_cast(port.get(InterruptFlag_v::InterruptTypValue)); } - static void ack(InterruptFlagRegister_t& port) { - port.write(InterruptFlag::InterruptTypValue.max()); + static void ack(InterruptFlag_v& port) { + port.set(InterruptFlag_v::InterruptTypValue.range_max()); } - static void ack_extended(InterruptFlagRegister_t& port) { - port.write({InterruptFlag::with(InterruptFlag::InterruptTypValue.max(), InterruptEnable::UnknownIRQ, InterruptEnable::CommandStartIRQ)}); + static void ack_extended(InterruptFlag_v& port) { + port = *InterruptFlag_v::from(InterruptFlag_v::InterruptTypValue.range_max(), InterruptEnable_v::UnknownIRQ, InterruptEnable_v::CommandStartIRQ); } }; struct Command { - struct Info { + struct Desc { uint8_t id; Interrupt::Type complete_irq; }; - static constexpr Info GetStat{0x01, Interrupt::Type::Acknowledge}; - static constexpr Info SetLoc{0x02, Interrupt::Type::Acknowledge}; - static constexpr Info ReadN{0x06, Interrupt::Type::DataReady}; - static constexpr Info Pause{0x09, Interrupt::Type::Complete}; - static constexpr Info Init{0x0A, Interrupt::Type::Complete}; - static constexpr Info SetMode{0x0E, Interrupt::Type::Acknowledge}; + static constexpr Desc GetStat{0x01, Interrupt::Type::Acknowledge}; + static constexpr Desc SetLoc{0x02, Interrupt::Type::Acknowledge}; + static constexpr Desc ReadN{0x06, Interrupt::Type::DataReady}; + static constexpr Desc Pause{0x09, Interrupt::Type::Complete}; + static constexpr Desc Init{0x0A, Interrupt::Type::Complete}; + static constexpr Desc SetMode{0x0E, Interrupt::Type::Acknowledge}; }; static constexpr auto IORegister1Adr = 0x1F801801; static constexpr auto IORegister2Adr = 0x1F801802; static constexpr auto IORegister3Adr = 0x1F801803; - __declare_io_port_global(IndexStatus_t, IndexStatus, 0x1F801800); + __declare_new_io_port(IndexStatus, 0x1F801800); #define __declare_index_io_port(type, name, adr) __cast_io_adr_with_type(inline, type, name, adr) #define __declare_index_io_port_const(type, name, adr) __cast_io_adr_with_type(const inline, type, name, adr) struct PortIndex0 { - __declare_index_io_port_const(ResponseFifo_t, ResponseFifo, IORegister1Adr); - __declare_index_io_port( CommandFifo_t, CommandFifo, IORegister1Adr); + __declare_new_const_io_port(ResponseFifo, IORegister1Adr); + __declare_new_io_port(CommandFifo, IORegister1Adr); - __declare_index_io_port_const(DataFifo_t, DataFifo, IORegister2Adr); - __declare_index_io_port_const(DataFifo16_t, DataFifo16, IORegister2Adr); - __declare_index_io_port( ParameterFifo_t, ParameterFifo, IORegister2Adr); + __declare_new_const_io_port(DataFifo, IORegister2Adr); + __declare_new_const_io_port(DataFifo16, IORegister2Adr); + __declare_new_io_port(ParameterFifo, IORegister2Adr); - __declare_index_io_port_const(InterruptEnableRegister_t, InterruptEnableRegister, IORegister3Adr); - __declare_index_io_port( RequestRegister_t, RequestRegister, IORegister3Adr); + __declare_new_const_io_port(InterruptEnable, IORegister3Adr); + __declare_new_io_port(Request, IORegister3Adr); static void change_to() { - IndexStatus.write({static_cast(Index::Index0)}); + IndexStatus = Index::Index0; } }; struct PortIndex1 { - __declare_index_io_port_const(ResponseFifo_t, ResponseFifo, IORegister1Adr); - __declare_index_io_port( SoundMapDataOut_t, SoundMapDataOut, IORegister1Adr); + __declare_new_const_io_port(ResponseFifo, IORegister1Adr); + __declare_new_io_port(SoundMapDataOut, IORegister1Adr); - __declare_index_io_port_const(DataFifo_t, DataFifo, IORegister2Adr); - __declare_index_io_port_const(DataFifo16_t, DataFifo16, IORegister2Adr); - __declare_index_io_port( InterruptEnableRegister_t, InterruptEnableRegister, IORegister2Adr); + __declare_new_const_io_port(DataFifo, IORegister2Adr); + __declare_new_const_io_port(DataFifo16, IORegister2Adr); + __declare_new_io_port(InterruptEnable, IORegister2Adr); - __declare_index_io_port(InterruptFlagRegister_t, InterruptFlagRegister, IORegister3Adr); + __declare_new_io_port(InterruptFlag, IORegister3Adr); static void change_to() { - IndexStatus.write({static_cast(Index::Index1)}); + IndexStatus = Index::Index1; } }; struct PortIndex2 { - __declare_index_io_port_const(ResponseFifo_t, ResponseFifo, IORegister1Adr); - __declare_index_io_port( SoundMapCodingInfo_t, SoundMapCodingInfo, IORegister1Adr); + __declare_new_const_io_port(ResponseFifo, IORegister1Adr); + __declare_new_io_port(SoundMapCoding, IORegister1Adr); - __declare_index_io_port_const(DataFifo_t, DataFifo, IORegister2Adr); - __declare_index_io_port_const(DataFifo16_t, DataFifo16, IORegister2Adr); - __declare_index_io_port( VolumeRegister_t, LeftCD2LeftSPU, IORegister2Adr); + __declare_new_const_io_port(DataFifo, IORegister2Adr); + __declare_new_const_io_port(DataFifo16, IORegister2Adr); + __declare_new_io_port(LeftCD2LeftSPU, IORegister2Adr); - __declare_index_io_port_const(InterruptEnableRegister_t, InterruptEnableRegister, IORegister3Adr); - __declare_index_io_port( VolumeRegister_t, LeftCD2RightSPU, IORegister3Adr); + __declare_new_const_io_port(InterruptEnable, IORegister3Adr); + __declare_new_io_port(LeftCD2RightSPU, IORegister3Adr); static void change_to() { - IndexStatus.write({static_cast(Index::Index2)}); + IndexStatus = Index::Index2; } }; struct PortIndex3 { - __declare_index_io_port_const(ResponseFifo_t, ResponseFifo, IORegister1Adr); - __declare_index_io_port( VolumeRegister_t, RightCD2RightSPU, IORegister1Adr); + __declare_new_const_io_port(ResponseFifo, IORegister1Adr); + __declare_new_io_port(RightCD2RightSPU, IORegister1Adr); - __declare_index_io_port_const(DataFifo_t, DataFifo, IORegister2Adr); - __declare_index_io_port_const(DataFifo16_t, DataFifo16, IORegister2Adr); - __declare_index_io_port( VolumeRegister_t, RightCD2LeftSPU, IORegister1Adr); + __declare_new_const_io_port(DataFifo, IORegister2Adr); + __declare_new_const_io_port(DataFifo16, IORegister2Adr); + __declare_new_io_port(RightCD2LeftSPU, IORegister1Adr); - __declare_index_io_port_const(InterruptFlagRegister_t, InterruptFlagRegister, IORegister3Adr); - __declare_index_io_port( AudioVolumeApplyChange_t, AudioVolumeApplyChange, IORegister3Adr); + __declare_new_const_io_port(InterruptFlag, IORegister3Adr); + __declare_new_io_port(AudioVolumeApply, IORegister3Adr); static void change_to() { - IndexStatus.write({static_cast(Index::Index3)}); + IndexStatus = Index::Index3; } }; diff --git a/include/PSX/System/IOPorts/ioport.hpp b/include/PSX/System/IOPorts/ioport.hpp index e0d03916..657c6d29 100644 --- a/include/PSX/System/IOPorts/ioport.hpp +++ b/include/PSX/System/IOPorts/ioport.hpp @@ -40,6 +40,11 @@ namespace JabyEngine { constexpr IOValueSetPair with(T value) const { return {*this, value}; } + + template + constexpr IOValueSetPair range_max() const { + return IOValueSet::with((1 << this->length) - 1); + } }; template diff --git a/src/Library/include/CD/cd_internal.hpp b/src/Library/include/CD/cd_internal.hpp index 0eed478a..3e05fb69 100644 --- a/src/Library/include/CD/cd_internal.hpp +++ b/src/Library/include/CD/cd_internal.hpp @@ -22,26 +22,26 @@ namespace JabyEngine { } template - static void send(CD_IO::CommandFifo_t& cmd_fifo, CD_IO::ParameterFifo_t& parameter_fifo, CD_IO::Command::Info cmd, ARGS...args) { - while(CD_IO::IndexStatus.read().is_bit_set(CD_IO::IndexStatus::IsTransmissionBusy)); + static void send(CD_IO::CommandFifo_v& cmd_fifo, CD_IO::ParameterFifo_v& parameter_fifo, CD_IO::Command::Desc cmd, ARGS...args) { + while(CD_IO::IndexStatus.is_set(CD_IO::IndexStatus_t::IsTransmissionBusy)); - (parameter_fifo.write(static_cast(args)), ...); - cmd_fifo.write(cmd.id); + ((parameter_fifo = args),...); + cmd_fifo = cmd.id; } template - static void send(CD_IO::Command::Info cmd, ARGS...args) { + static void send(CD_IO::Command::Desc cmd, ARGS...args) { send(T::CommandFifo, T::ParameterFifo, cmd, args...); } template - static void send_wait(CD_IO::CommandFifo_t& cmd_fifo, CD_IO::ParameterFifo_t& parameter_fifo, CD_IO::Command::Info cmd, ARGS...args) { + static void send_wait(CD_IO::CommandFifo_v& cmd_fifo, CD_IO::ParameterFifo_v& parameter_fifo, CD_IO::Command::Desc cmd, ARGS...args) { send(cmd_fifo, parameter_fifo, cmd, args...); wait_until(cmd.complete_irq); } template - static void send_wait(CD_IO::Command::Info cmd, ARGS...args) { + static void send_wait(CD_IO::Command::Desc cmd, ARGS...args) { send_wait(T::CommandFifo, T::ParameterFifo, cmd, args...); } }; diff --git a/src/Library/src/BootLoader/cd_boot.cpp b/src/Library/src/BootLoader/cd_boot.cpp index c7507534..e52d6ded 100644 --- a/src/Library/src/BootLoader/cd_boot.cpp +++ b/src/Library/src/BootLoader/cd_boot.cpp @@ -22,8 +22,8 @@ namespace JabyEngine { __syscall_SysEnqIntRP(CdromIoIrq, &::JabyEngine::CD::internal::callback); CD_IO::PortIndex1::change_to(); - CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlagRegister); - CD_IO::Interrupt::enable(CD_IO::PortIndex1::InterruptEnableRegister); + CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag); + CD_IO::Interrupt::enable(CD_IO::PortIndex1::InterruptEnable); Interrupt::ack_irq(Interrupt::CDROM); Interrupt::enable_irq(Interrupt::CDROM); diff --git a/src/Library/src/CD/cd.cpp b/src/Library/src/CD/cd.cpp index 24769bb1..e015bda8 100644 --- a/src/Library/src/CD/cd.cpp +++ b/src/Library/src/CD/cd.cpp @@ -31,12 +31,12 @@ namespace JabyEngine { }; if(Interrupt::is_irq(Interrupt::CDROM)) { - const uint8_t old_idx = (CD_IO::IndexStatus.read() & 0x3); + const uint8_t old_idx = (*CD_IO::IndexStatus & 0x3); CD_IO::PortIndex1::change_to(); - const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlagRegister); + const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag); last_interrupt = cur_irq; - CD_IO::Interrupt::ack(CD_IO::PortIndex1::InterruptFlagRegister); + CD_IO::Interrupt::ack(CD_IO::PortIndex1::InterruptFlag); if(cur_irq == CD_IO::Interrupt::DataReady) { //Obtain sector content here @@ -67,7 +67,7 @@ namespace JabyEngine { current_state = State::Error; } - CD_IO::IndexStatus.write({old_idx}); + CD_IO::IndexStatus = old_idx; return InterruptVerifierResult::ExecuteHandler; }