From 6e40dacdecc8e674313b61bd27ec12ab07902b0f Mon Sep 17 00:00:00 2001 From: Jaby Date: Sat, 21 Jan 2023 12:18:02 +0100 Subject: [PATCH] Finished CD_IOs --- include/PSX/System/IOPorts/cd_io.hpp | 182 +++++++++---------------- include/PSX/System/IOPorts/ioport.hpp | 8 +- src/Library/src/BootLoader/cd_boot.cpp | 9 +- 3 files changed, 74 insertions(+), 125 deletions(-) diff --git a/include/PSX/System/IOPorts/cd_io.hpp b/include/PSX/System/IOPorts/cd_io.hpp index f5753ced..c95c1d7a 100644 --- a/include/PSX/System/IOPorts/cd_io.hpp +++ b/include/PSX/System/IOPorts/cd_io.hpp @@ -4,7 +4,7 @@ namespace JabyEngine { namespace CD_IO { - enum struct Index { + enum Index { Index0 = 0, Index1 = 1, Index2 = 2, @@ -76,135 +76,87 @@ namespace JabyEngine { 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); + 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_port_member_const_simple(uint8_t, DataFifo, IORegister2Adr); - __declare_io_port_member_const_simple(uint16_t, DataFifo16, IORegister2Adr); + #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_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_index_io_port_const(InterruptEnableRegister_t, InterruptEnableRegister, IORegister3Adr); + __declare_index_io_port( RequestRegister_t, RequestRegister, IORegister3Adr); + + static void change_to() { + IndexStatus.write({static_cast(Index::Index0)}); + } }; - 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; + struct PortIndex1 { + __declare_index_io_port_const(ResponseFifo_t, ResponseFifo, IORegister1Adr); + __declare_index_io_port( SoundMapDataOut_t, SoundMapDataOut, IORegister1Adr); - namespace Index0Types { - struct __no_align IndexTriplet { - union __no_align { - const ResponseFifo response_fifo; - CommandFifo command; - }; + __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); - union __no_align { - const DataFifo data_fifo; - ParameterFifo parameter_fifo; - }; + __declare_index_io_port(InterruptFlagRegister_t, InterruptFlagRegister, IORegister3Adr); - union __no_align { - const InterruptEnableRegister irq_enable; - RequestRegister request; - }; - }; + static void change_to() { + IndexStatus.write({static_cast(Index::Index1)}); + } + }; - static_assert(sizeof(IndexTriplet) == 3); - } + struct PortIndex2 { + __declare_index_io_port_const(ResponseFifo_t, ResponseFifo, IORegister1Adr); + __declare_index_io_port( SoundMapCodingInfo_t, SoundMapCodingInfo, IORegister1Adr); - namespace Index1Types { - struct __no_align IndexTriplet { - union __no_align { - const ResponseFifo response_fifo; - SoundMapDataOut sound_map_data_out; - }; + __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); - union __no_align { - const DataFifo data_fifo; - InterruptEnableRegister irq_enable; - }; + __declare_index_io_port_const(InterruptEnableRegister_t, InterruptEnableRegister, IORegister3Adr); + __declare_index_io_port( VolumeRegister_t, LeftCD2RightSPU, IORegister3Adr); - 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 - static S& change_to(Index idx) { - IndexStatus.write({static_cast(idx)}); - return *reinterpret_cast(0x1F801801); + static void change_to() { + IndexStatus.write({static_cast(Index::Index2)}); } - } + }; - static Index0Types::IndexTriplet& change_to_index0() { - return Helper::change_to(Index::Index0); - } + struct PortIndex3 { + __declare_index_io_port_const(ResponseFifo_t, ResponseFifo, IORegister1Adr); + __declare_index_io_port( VolumeRegister_t, RightCD2RightSPU, IORegister1Adr); - static Index1Types::IndexTriplet& change_to_index1() { - return Helper::change_to(Index::Index1); - } + __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); - static Index2Types::IndexTriplet& change_to_index2() { - return Helper::change_to(Index::Index2); - } + __declare_index_io_port_const(InterruptFlagRegister_t, InterruptFlagRegister, IORegister3Adr); + __declare_index_io_port( AudioVolumeApplyChange_t, AudioVolumeApplyChange, IORegister3Adr); - static Index3Types::IndexTriplet& change_to_index3() { - return Helper::change_to(Index::Index2); - } + static void change_to() { + IndexStatus.write({static_cast(Index::Index3)}); + } + }; + + #undef __declare_index_io_port + #undef __declare_index_io_port_const } } diff --git a/include/PSX/System/IOPorts/ioport.hpp b/include/PSX/System/IOPorts/ioport.hpp index 94f8ea33..bec6bf78 100644 --- a/include/PSX/System/IOPorts/ioport.hpp +++ b/include/PSX/System/IOPorts/ioport.hpp @@ -80,14 +80,14 @@ namespace JabyEngine { #define __cast_io_adr_with_type(cv, type, name, adr) static __always_inline cv auto& name = *reinterpret_cast(__io_port_adr(adr)) - #define __declare_io_port_global(type, name, adr) __cast_io_adr_with_type(, VolatileBitMapPOD, name, adr) + #define __declare_io_port_global(type, name, adr) __cast_io_adr_with_type(, VolatileBitMapPOD, name, adr) #define __declare_io_port_global_const(type, name, adr) __cast_io_adr_with_type(const, VolatileBitMapPOD, name, adr) - #define __declare_io_port_global_simple(type, name, adr) __cast_io_adr_with_type(, VolatilePOD, name, adr) + #define __declare_io_port_global_simple(type, name, adr) __cast_io_adr_with_type(, VolatilePOD, name, adr) #define __declare_io_port_global_const_simple(type, name, adr) __cast_io_adr_with_type(const, VolatilePOD, name, adr) - #define __declare_io_port_member(type, name, adr) __cast_io_adr_with_type(inline, VolatileBitMapPOD, name, adr) + #define __declare_io_port_member(type, name, adr) __cast_io_adr_with_type(inline, VolatileBitMapPOD, name, adr) #define __declare_io_port_member_const(type, name, adr) __cast_io_adr_with_type(const inline, VolatileBitMapPOD, name, adr) - #define __declare_io_port_member_simple(type, name, adr) __cast_io_adr_with_type(inline, VolatilePOD, name, adr) + #define __declare_io_port_member_simple(type, name, adr) __cast_io_adr_with_type(inline, VolatilePOD, name, adr) #define __declare_io_port_member_const_simple(type, name, adr) __cast_io_adr_with_type(const inline, VolatilePOD, name, adr) #define __declare_io_port_global_array(type, name, adr, size) static __always_inline auto& name = reinterpret_cast(*reinterpret_cast(__io_port_adr(adr))) diff --git a/src/Library/src/BootLoader/cd_boot.cpp b/src/Library/src/BootLoader/cd_boot.cpp index 0c2abcca..a03e9c6e 100644 --- a/src/Library/src/BootLoader/cd_boot.cpp +++ b/src/Library/src/BootLoader/cd_boot.cpp @@ -5,12 +5,9 @@ namespace JabyEngine { namespace boot { namespace CD { void setup() { - - } - - uint16_t miau() { - CD_IO::Index0::DataFifo.read(); - return CD_IO::Index0::DataFifo16.read(); + CD_IO::PortIndex0::change_to(); + CD_IO::PortIndex0::DataFifo.read(); + CD_IO::PortIndex0::DataFifo16.read(); } } }