Mesen-SX/Core/DmaController.h

65 lines
1.4 KiB
C
Raw Normal View History

2019-02-15 00:08:50 -05:00
#pragma once
#include "stdafx.h"
#include "CpuTypes.h"
2019-03-12 09:15:57 -04:00
#include "../Utilities/ISerializable.h"
2019-02-15 00:08:50 -05:00
class MemoryManager;
struct DmaChannelConfig
{
bool InvertDirection;
bool Decrement;
bool FixedTransfer;
bool HdmaIndirectAddressing;
2019-02-15 00:08:50 -05:00
uint8_t TransferMode;
uint16_t SrcAddress;
2019-02-21 07:55:53 -05:00
uint8_t SrcBank;
2019-02-15 00:08:50 -05:00
uint8_t DestAddress;
uint16_t TransferSize;
uint8_t HdmaBank;
uint16_t HdmaTableAddress;
uint8_t HdmaLineCounterAndRepeat;
bool DoTransfer;
bool HdmaFinished;
2019-02-21 07:55:53 -05:00
bool InterruptedByHdma;
2019-02-21 07:55:53 -05:00
bool UnusedFlag;
2019-02-15 00:08:50 -05:00
};
2019-03-12 09:15:57 -04:00
class DmaController : public ISerializable
2019-02-15 00:08:50 -05:00
{
private:
static constexpr uint8_t _transferByteCount[8] = { 1, 2, 2, 4, 4, 4, 2, 4 };
static constexpr uint8_t _transferOffset[8][4] = {
{ 0, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 1, 1 },
{ 0, 1, 2, 3 }, { 0, 1, 0, 1 }, { 0, 0, 0, 0 }, { 0, 0, 1, 1 }
};
bool _hdmaPending = false;
uint8_t _hdmaChannels = 0;
2019-02-15 00:08:50 -05:00
DmaChannelConfig _channel[8] = {};
2019-02-16 01:16:57 -05:00
MemoryManager *_memoryManager;
void CopyDmaByte(uint32_t addressBusA, uint16_t addressBusB, bool fromBtoA);
void RunSingleTransfer(DmaChannelConfig &channel);
void RunDma(DmaChannelConfig &channel);
void RunHdmaTransfer(DmaChannelConfig &channel);
2019-02-15 00:08:50 -05:00
public:
2019-02-16 01:16:57 -05:00
DmaController(MemoryManager *memoryManager);
void Reset();
void InitHdmaChannels();
void ProcessHdmaChannels();
2019-02-15 00:08:50 -05:00
void Write(uint16_t addr, uint8_t value);
2019-02-21 07:55:53 -05:00
uint8_t Read(uint16_t addr);
2019-03-12 09:15:57 -04:00
void Serialize(Serializer &s) override;
2019-02-15 00:08:50 -05:00
};