From 9c6b47e0fa4e81300ad039562631db2d4397b236 Mon Sep 17 00:00:00 2001 From: Jaby Date: Wed, 6 Mar 2024 19:08:25 -0600 Subject: [PATCH] Set DMA priority --- include/PSX/System/IOPorts/dma_io.hpp | 38 ++++++++++++++++++++----- src/Library/src/BootLoader/dma_boot.cpp | 2 +- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/include/PSX/System/IOPorts/dma_io.hpp b/include/PSX/System/IOPorts/dma_io.hpp index 81e7f241..4f165905 100644 --- a/include/PSX/System/IOPorts/dma_io.hpp +++ b/include/PSX/System/IOPorts/dma_io.hpp @@ -109,25 +109,49 @@ namespace JabyEngine { static constexpr Priority LowestPriority = 7; __declare_io_value(DPCR, uint32_t) { - static constexpr auto OTCEnable = Bit(27); + struct DMASetting { + uint16_t master_bit; + + static constexpr DMASetting create(uint16_t master_bit) { + return DMASetting{master_bit}; + } + + constexpr BitRange::RangeValuePair turn_on(uint8_t priority) const { + return BitRange::from_to(this->master_bit - 3, this->master_bit).with(static_cast(0b1000 + (priority & 0b111))); + } + + constexpr ClearBit turn_off() const { + return ClearBit(this->master_bit); + } + }; + + static constexpr const auto OTC = DMASetting(27); + static constexpr const auto PIO = DMASetting(23); + static constexpr const auto SPU = DMASetting(19); + static constexpr const auto CDROM = DMASetting(15); + static constexpr const auto GPU = DMASetting(11); + static constexpr const auto MDEC_Out = DMASetting(7); + static constexpr const auto MDEC_In = DMASetting(3); + + static constexpr auto OTCEnabled = Bit(27); static constexpr auto OTCPriority = BitRange::from_to(24, 26); - static constexpr auto PIOEnable = Bit(23); + static constexpr auto PIOEnabled = Bit(23); static constexpr auto PIOPriority = BitRange::from_to(20, 22); - static constexpr auto SPUEnable = Bit(19); + static constexpr auto SPUEnabled = Bit(19); static constexpr auto SPUPriority = BitRange::from_to(16, 18); - static constexpr auto CDROMEnable = Bit(15); + static constexpr auto CDROMEnabled = Bit(15); static constexpr auto CDROMPriority = BitRange::from_to(12, 14); - static constexpr auto GPUEnable = Bit(11); + static constexpr auto GPUEnabled = Bit(11); static constexpr auto GPUPriority = BitRange::from_to(8, 10); - static constexpr auto MDECoutEnable = Bit(7); + static constexpr auto MDECoutEnabled = Bit(7); static constexpr auto MDECoutPriority = BitRange::from_to(4, 6); - static constexpr auto MDECinEnable = Bit(3); + static constexpr auto MDECinEnabled = Bit(3); static constexpr auto MDECinPriority = BitRange::from_to(0, 2); }; diff --git a/src/Library/src/BootLoader/dma_boot.cpp b/src/Library/src/BootLoader/dma_boot.cpp index 9f0f0029..b12fed47 100644 --- a/src/Library/src/BootLoader/dma_boot.cpp +++ b/src/Library/src/BootLoader/dma_boot.cpp @@ -4,7 +4,7 @@ namespace JabyEngine { namespace boot { namespace DMA { void setup() { - static constexpr auto EnableDMA = DMA_IO::DPCR::from(DMA_IO::DPCR::SPUEnable, DMA_IO::DPCR::GPUEnable, DMA_IO::DPCR::CDROMEnable); + static constexpr auto EnableDMA = DMA_IO::DPCR::from(DMA_IO::DPCR::SPU.turn_on(3), DMA_IO::DPCR::GPU.turn_on(3), DMA_IO::DPCR::CDROM.turn_on(3)); DMA_IO::DPCR.write(EnableDMA); }