push changes

This commit is contained in:
liuk7071 2023-07-27 20:15:33 +02:00
parent 72b53dd947
commit e03bc1503d
3 changed files with 60 additions and 4 deletions

View file

@ -1 +1,32 @@
#include "dma.hpp"
#include "dma.hpp"
#include <memory.hpp>
DMA::DMA() {
//channels[6].doDMA = &otcDMA;
}
bool DMA::DMAChannel::shouldStartDMA() {
return chcr.enable && ((chcr.syncMode == 0) ? chcr.trigger.Value() : true);
}
/*void DMA::doDMA(int channel, Memory* memory) {
printf("%d", channel);
// If the dma func of the channel is null, it means it hasn't been implemented yet
if (!channels[channel].doDMA)
Helpers::panic("[DMA] Unimplemented DMA channel %d\n", channel);
channels[channel].doDMA(memory);
}*/
/*void DMA::otcDMA(Memory* memory) {
printf("panda...");
auto& dma = memory->dma;
constexpr auto ch = 6;
// OTC DMA is always sync mode 0 and backwards memory address step
switch (dma->channels[ch].chcr.syncMode) {
default:
Helpers::panic("[DMA] Unimplemented OTC DMA sync mode %d\n", dma->channels[ch].chcr.syncMode);
}
}*/

View file

@ -4,8 +4,13 @@
#include <BitField.hpp>
// Circular dependency
class Memory;
class DMA {
public:
DMA();
struct DMAChannel {
u32 madr;
@ -23,13 +28,25 @@ public:
BitField<9, 2, u32> syncMode;
BitField<16, 3, u32> choppingDmaSize;
BitField<20, 3, u32> choppingCpuSize;
BitField<24, 1, u32> busy;
BitField<24, 1, u32> enable;
BitField<28, 1, u32> trigger;
} chcr;
bool shouldStartDMA();
void (*doDMA)(Memory*);
};
DMAChannel channels[7];
u32 dpcr = 0;
u32 dicr = 0;
enum class SyncMode {
Block,
Sync,
LinkedList
};
/*void doDMA(int channel, Memory* memory);
static void otcDMA(Memory* memory);*/
};

View file

@ -188,13 +188,21 @@ void Memory::write(u32 vaddr, u32 data) {
else if (paddr == 0x1f801074) interrupt->writeImask(data);
// DMA
else if (Helpers::inRange<u32>(paddr, 0x1f801080, 0x1f8010e8)) {
printf("panda\n");
const auto channel = ((paddr >> 4) & 0xf) - 8;
Helpers::assert(channel < 8, "Tried to access %dth DMA channel", channel); // Should not get triggered
// TODO: /Ob2 doesnt work
switch (paddr & 0xf) {
case 0x0: dma->channels[channel].madr = data; break;
case 0x4: dma->channels[channel].bcr.raw = data; break;
case 0x8: dma->channels[channel].chcr.raw = data; break;
case 0x8: {
dma->channels[channel].chcr.raw = data;
if (dma->channels[channel].shouldStartDMA()) {
Helpers::panic("AAAAAAAAAAAA\n");
//dma->doDMA(channel, this);
}
break;
}
default: Helpers::panic("[FATAL] Unhandled DMA write32 0x%08x <- 0x%08x\n", paddr, data);
}
}