155 lines
5.6 KiB
C++
155 lines
5.6 KiB
C++
#ifndef __JABYENGINE_DMA_IO_HPP__
|
|
#define __JABYENGINE_DMA_IO_HPP__
|
|
#include "ioport.hpp"
|
|
|
|
namespace JabyEngine {
|
|
namespace DMA_IO {
|
|
__declare_io_type(MADR, uint32_t,
|
|
static constexpr auto MemoryAdr = BitRange::from_to(0, 23);
|
|
);
|
|
|
|
__declare_io_type(BCR, uint32_t,
|
|
struct SyncMode0 {
|
|
static constexpr auto NumberOfWords = BitRange::from_to(0, 15);
|
|
static constexpr auto CD_OneBlock = Bit(16);
|
|
|
|
static constexpr Self for_cd() {
|
|
// v Should be replaced with a named constant
|
|
return Self::from(SyncMode0::CD_OneBlock, SyncMode0::NumberOfWords.with(512));
|
|
}
|
|
};
|
|
|
|
struct SyncMode1 {
|
|
static constexpr auto BlockSize = BitRange::from_to(0, 15);
|
|
static constexpr auto BlockAmount = BitRange::from_to(16, 31);
|
|
};
|
|
|
|
struct SyncMode2 {
|
|
};
|
|
);
|
|
|
|
__declare_io_type(CHCHR, uint32_t,
|
|
enum SyncMode_t {
|
|
Sync0 = 0, //Start immediately,
|
|
Sync1 = 1, //Sync blocks to DMA requests
|
|
Sync2 = 2, //Linked List
|
|
};
|
|
|
|
static constexpr auto ManualStart = Bit(28);
|
|
|
|
static constexpr auto Start = Bit(24);
|
|
static constexpr auto Busy = Start;
|
|
|
|
static constexpr auto ChoppingCPUWindowSize = BitRange::from_to(20, 22);
|
|
static constexpr auto ChoppingDMAWindowSize = BitRange::from_to(16, 18);
|
|
|
|
static constexpr auto SyncMode = BitRange::from_to(9, 10);
|
|
static constexpr auto UseSyncMode0 = SyncMode.with(Sync0);
|
|
static constexpr auto UseSyncMode1 = SyncMode.with(Sync1);
|
|
static constexpr auto UseSyncMode2 = SyncMode.with(Sync2);
|
|
|
|
static constexpr auto UseChopping = Bit(8);
|
|
|
|
static constexpr auto MemoryAdrDecreaseBy4 = Bit(1);
|
|
static constexpr auto MemoryAdrIncreaseBy4 = !MemoryAdrDecreaseBy4;
|
|
|
|
static constexpr auto FromMainRAM = Bit(0);
|
|
static constexpr auto ToMainRAM = !FromMainRAM;
|
|
|
|
static constexpr Self StartMDECin() {
|
|
return Self{0x01000201};
|
|
}
|
|
|
|
static constexpr Self StartMDECout() {
|
|
return Self{0x01000200};
|
|
}
|
|
|
|
static constexpr Self StartGPUReceive() {
|
|
return Self{0x01000201};
|
|
}
|
|
|
|
static constexpr Self StartCDROM() {
|
|
return Self{0x11000000};
|
|
}
|
|
|
|
static constexpr Self StartSPUReceive() {
|
|
return Self{0x01000201};
|
|
}
|
|
|
|
static constexpr Self StartOTC() {
|
|
return Self{0x11000002};
|
|
}
|
|
);
|
|
|
|
struct __no_align Registers {
|
|
MADR_v adr;
|
|
BCR_v block_ctrl;
|
|
CHCHR_v channel_ctrl;
|
|
|
|
void set_adr(uintptr_t adr) {
|
|
this->adr.set(MADR_t::MemoryAdr.with(adr));
|
|
}
|
|
|
|
void wait() {
|
|
while(this->channel_ctrl.is_set(CHCHR_t::Busy));
|
|
}
|
|
};
|
|
|
|
// Those types do not need to be volatile because there members are
|
|
typedef Registers MDECin_v;
|
|
typedef Registers MDECout_v;
|
|
typedef Registers GPU_v;
|
|
typedef Registers CDROM_v;
|
|
typedef Registers SPU_v;
|
|
typedef Registers PIO_v;
|
|
typedef Registers OTC_v;
|
|
|
|
//0: Highest, 7: Lowest
|
|
typedef uint32_t Priority;
|
|
static constexpr Priority HighestPriority = 0;
|
|
static constexpr Priority LowestPriority = 7;
|
|
|
|
__declare_io_type(DPCR, uint32_t,
|
|
static constexpr auto OTCEnable = Bit(27);
|
|
static constexpr auto OTCPriority = BitRange::from_to(24, 26);
|
|
|
|
static constexpr auto PIOEnable = Bit(23);
|
|
static constexpr auto PIOPriority = BitRange::from_to(20, 22);
|
|
|
|
static constexpr auto SPUEnable = Bit(19);
|
|
static constexpr auto SPUPriority = BitRange::from_to(16, 18);
|
|
|
|
static constexpr auto CDROMEnable = Bit(15);
|
|
static constexpr auto CDROMPriority = BitRange::from_to(12, 14);
|
|
|
|
static constexpr auto GPUEnable = Bit(11);
|
|
static constexpr auto GPUPriority = BitRange::from_to(8, 10);
|
|
|
|
static constexpr auto MDECoutEnable = Bit(7);
|
|
static constexpr auto MDECoutPriority = BitRange::from_to(4, 6);
|
|
|
|
static constexpr auto MDECinEnable = Bit(3);
|
|
static constexpr auto MDECinPriority = BitRange::from_to(0, 2);
|
|
);
|
|
|
|
__declare_io_type(DICR, uint32_t,
|
|
static constexpr auto MasterEnable = Bit(31);
|
|
static constexpr auto Flags = BitRange::from_to(24, 30);
|
|
static constexpr auto MasterEnableDPCR = Bit(23);
|
|
static constexpr auto EnableDPCR = BitRange::from_to(16, 22);
|
|
static constexpr auto ForceIRQ = Bit(15);
|
|
);
|
|
|
|
__declare_new_io_port(MDECin, 0x1F801080);
|
|
__declare_new_io_port(MDECout, 0x1F801090);
|
|
__declare_new_io_port(GPU, 0x1F8010A0);
|
|
__declare_new_io_port(CDROM, 0x1F8010B0);
|
|
__declare_new_io_port(SPU, 0x1F8010C0);
|
|
__declare_new_io_port(PIO, 0x1F8010D0);
|
|
__declare_new_io_port(OTC, 0x1F8010E0);
|
|
|
|
__declare_new_io_port(DPCR, 0x1F8010F0);
|
|
__declare_new_io_port(DICR, 0x1F8010F4);
|
|
}
|
|
}
|
|
#endif //!__JABYENGINE_DMA_IO_HPP__
|