#ifndef __JABYENGINE_CD_IO_HPP__ #define __JABYENGINE_CD_IO_HPP__ #include "ioport.hpp" namespace JabyEngine { namespace CD_IO { enum struct Index { Index0 = 0, Index1 = 1, Index2 = 2, Index3 = 3, }; 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; struct InterruptEnable : public ComplexBitMap { static constexpr auto InterruptTypValue = BitRange::from_to(0, 2); static constexpr auto UnknownIRQ = Bit(3); static constexpr auto CommandStartIRQ = Bit(4); }; typedef InterruptEnable InterruptFlag; struct Request : public ComplexBitMap { static constexpr auto WantCommandStartIRQ = Bit(5); static constexpr auto WantData = Bit(7); }; struct Interrupt { static void enable_all(IOPortEx& port) { port.write({InterruptEnable::with(InterruptEnable::InterruptTypValue.max(), InterruptEnable::UnknownIRQ, InterruptEnable::CommandStartIRQ)}); } static uint8_t get_type(const IOPortEx& port) { return port.read().get_value(InterruptFlag::InterruptTypValue); } static void ack(IOPortEx& port) { port.write_range_value(InterruptFlag::InterruptTypValue.max()); } }; typedef uint8_t ResponseFifo; typedef uint8_t CommandFifo; typedef uint8_t DataFifo; typedef uint16_t DataFifo16; typedef uint8_t ParameterFifo; namespace Index0Types { struct __no_align IndexTriplet { // Replace with proper types later union __no_align { const IOPort response_fifo; IOPort command; }; union __no_align { const IOPort data_fifo; IOPort parameter_fifo; }; union __no_align { const IOPort irq_enable; IOPort request; }; const IOPort& 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 Helper { template static S& change_to(Index idx) { IndexStatus.write({static_cast(idx)}); return *reinterpret_cast(0x1F801801); } } static Index0Types::IndexTriplet& change_to_index0() { return Helper::change_to(Index::Index0); } } } #endif //!__JABYENGINE_CD_IO_HPP__