From 98743f7948cdcaf25d24b80f26220ddb3442050e Mon Sep 17 00:00:00 2001 From: Jaby Date: Tue, 17 Jan 2023 22:04:35 +0100 Subject: [PATCH] On a better way --- include/PSX/System/IOPorts/cd_io.hpp | 147 ++++++++++++++++++++++--- src/Library/src/BootLoader/cd_boot.cpp | 7 +- 2 files changed, 136 insertions(+), 18 deletions(-) diff --git a/include/PSX/System/IOPorts/cd_io.hpp b/include/PSX/System/IOPorts/cd_io.hpp index 5f210a55..f5753ced 100644 --- a/include/PSX/System/IOPorts/cd_io.hpp +++ b/include/PSX/System/IOPorts/cd_io.hpp @@ -11,6 +11,14 @@ namespace JabyEngine { Index3 = 3, }; + struct CDDAVolume { + typedef uint8_t Type; + + static constexpr uint8_t Off = 0x0; + static constexpr uint8_t Default = 0x80; + 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); @@ -33,6 +41,21 @@ namespace JabyEngine { static constexpr auto WantData = Bit(7); }; + struct SoundMapCoding : public ComplexBitMap { + static constexpr auto Stereo = Bit(0); + static constexpr auto Mono = !Stereo; + static constexpr auto SampleRate_18900hz = Bit(2); + static constexpr auto SampleRate_37800hz = !SampleRate_18900hz; + static constexpr auto BitsPerSample8 = Bit(4); + static constexpr auto BitsPerSample4 = !BitsPerSample8; + static constexpr auto Emphasis = Bit(6); + }; + + struct AudioVolumeApply : public ComplexBitMap { + static constexpr auto Mute = Bit(0); + static constexpr auto ApplyChanges = Bit(5); + }; + struct Interrupt { static void enable_all(VolatileBitMapPOD& port) { port.write({InterruptEnable::with(InterruptEnable::InterruptTypValue.max(), InterruptEnable::UnknownIRQ, InterruptEnable::CommandStartIRQ)}); @@ -47,39 +70,117 @@ namespace JabyEngine { } }; - typedef uint8_t ResponseFifo; - typedef uint8_t CommandFifo; - typedef uint8_t DataFifo; - typedef uint16_t DataFifo16; - typedef uint8_t ParameterFifo; + __declare_io_port_global(IndexStatus_t, IndexStatus, 0x1F801800); + + static constexpr auto IORegister1Adr = 0x1F801801; + static constexpr auto IORegister2Adr = 0x1F801802; + static constexpr auto IORegister3Adr = 0x1F801803; + + struct Index0 { + __declare_io_port_member_const_simple(uint8_t, ResponseFifo, IORegister1Adr); + __declare_io_port_member_simple(uint8_t, CommandFifo, IORegister1Adr); + + __declare_io_port_member_const_simple(uint8_t, DataFifo, IORegister2Adr); + __declare_io_port_member_const_simple(uint16_t, DataFifo16, IORegister2Adr); + }; + + typedef VolatilePOD ResponseFifo; + typedef VolatilePOD CommandFifo; + typedef VolatilePOD DataFifo; + typedef VolatilePOD DataFifo16; + typedef VolatilePOD ParameterFifo; + typedef VolatilePOD SoundMapDataOut; + typedef VolatilePOD VolumeRegister; + typedef VolatileBitMapPOD InterruptEnableRegister; + typedef VolatileBitMapPOD InterruptFlagRegister; + typedef VolatileBitMapPOD RequestRegister; + typedef VolatileBitMapPOD SoundMapCodingInfo; + typedef VolatileBitMapPOD AudioVolumeApplyChange; namespace Index0Types { struct __no_align IndexTriplet { - // Replace with proper types later union __no_align { - const VolatilePOD response_fifo; - VolatilePOD command; + const ResponseFifo response_fifo; + CommandFifo command; }; union __no_align { - const VolatilePOD data_fifo; - VolatilePOD parameter_fifo; + const DataFifo data_fifo; + ParameterFifo parameter_fifo; }; union __no_align { - const VolatileBitMapPOD irq_enable; - VolatileBitMapPOD request; + const InterruptEnableRegister irq_enable; + RequestRegister request; }; - - const VolatilePOD& get_data_fifo_16() const { - return *reinterpret_cast*>(&this->data_fifo); - } }; static_assert(sizeof(IndexTriplet) == 3); } - __declare_io_port_global(IndexStatus_t, IndexStatus, 0x1F801800); + namespace Index1Types { + struct __no_align IndexTriplet { + union __no_align { + const ResponseFifo response_fifo; + SoundMapDataOut sound_map_data_out; + }; + + union __no_align { + const DataFifo data_fifo; + InterruptEnableRegister irq_enable; + }; + + union __no_align { + InterruptFlagRegister irq_flag; + }; + }; + + static_assert(sizeof(IndexTriplet) == 3); + } + + namespace Index2Types { + struct __no_align IndexTriplet { + union __no_align { + const ResponseFifo response_fifo; + SoundMapCodingInfo sound_map_coding_info; + }; + + union __no_align { + const DataFifo data_fifo; + VolumeRegister left_cd_2_left_spu; + }; + + union __no_align { + const InterruptEnableRegister irq_enable; + VolumeRegister left_cd_2_right_spu; + }; + }; + + static_assert(sizeof(IndexTriplet) == 3); + } + + namespace Index3Types { + struct __no_align IndexTriplet { + union __no_align { + const ResponseFifo response_fifo; + VolumeRegister right_cd_2_right_spu; + }; + + union __no_align { + const DataFifo data_fifo; + VolumeRegister right_cd_2_left_spu; + }; + + union __no_align { + const InterruptFlagRegister irq_flag; + AudioVolumeApplyChange audio_volume_change; + }; + }; + + static_assert(sizeof(IndexTriplet) == 3); + } + + namespace Helper { template @@ -92,6 +193,18 @@ namespace JabyEngine { static Index0Types::IndexTriplet& change_to_index0() { return Helper::change_to(Index::Index0); } + + static Index1Types::IndexTriplet& change_to_index1() { + return Helper::change_to(Index::Index1); + } + + static Index2Types::IndexTriplet& change_to_index2() { + return Helper::change_to(Index::Index2); + } + + static Index3Types::IndexTriplet& change_to_index3() { + return Helper::change_to(Index::Index2); + } } } diff --git a/src/Library/src/BootLoader/cd_boot.cpp b/src/Library/src/BootLoader/cd_boot.cpp index 1fe899d6..0c2abcca 100644 --- a/src/Library/src/BootLoader/cd_boot.cpp +++ b/src/Library/src/BootLoader/cd_boot.cpp @@ -5,7 +5,12 @@ namespace JabyEngine { namespace boot { namespace CD { void setup() { - CD_IO::change_to_index0(); + + } + + uint16_t miau() { + CD_IO::Index0::DataFifo.read(); + return CD_IO::Index0::DataFifo16.read(); } } }