Merge pull request #4709 from lioncash/exi-device

EXI_Device: Minor cleanup
This commit is contained in:
Mat M 2017-01-29 19:50:42 -05:00 committed by GitHub
commit 548e2d6353
4 changed files with 96 additions and 56 deletions

View File

@ -231,10 +231,10 @@ void CEXIChannel::DoState(PointerWrap& p)
for (int device_index = 0; device_index < NUM_DEVICES; ++device_index)
{
std::unique_ptr<IEXIDevice>& device = m_devices[device_index];
TEXIDevices type = device->m_deviceType;
TEXIDevices type = device->m_device_type;
p.Do(type);
if (type == device->m_deviceType)
if (type == device->m_device_type)
{
device->DoState(p);
}

View File

@ -17,52 +17,90 @@
#include "Core/HW/EXI/EXI_DeviceMic.h"
#include "Core/HW/Memmap.h"
void IEXIDevice::ImmWrite(u32 _uData, u32 _uSize)
void IEXIDevice::ImmWrite(u32 data, u32 size)
{
while (_uSize--)
while (size--)
{
u8 uByte = _uData >> 24;
TransferByte(uByte);
_uData <<= 8;
u8 byte = data >> 24;
TransferByte(byte);
data <<= 8;
}
}
u32 IEXIDevice::ImmRead(u32 _uSize)
u32 IEXIDevice::ImmRead(u32 size)
{
u32 uResult = 0;
u32 uPosition = 0;
while (_uSize--)
u32 result = 0;
u32 position = 0;
while (size--)
{
u8 uByte = 0;
TransferByte(uByte);
uResult |= uByte << (24 - (uPosition++ * 8));
u8 byte = 0;
TransferByte(byte);
result |= byte << (24 - (position++ * 8));
}
return uResult;
return result;
}
void IEXIDevice::DMAWrite(u32 _uAddr, u32 _uSize)
void IEXIDevice::ImmReadWrite(u32& data, u32 size)
{
// _dbg_assert_(EXPANSIONINTERFACE, 0);
while (_uSize--)
}
void IEXIDevice::DMAWrite(u32 address, u32 size)
{
while (size--)
{
u8 uByte = Memory::Read_U8(_uAddr++);
TransferByte(uByte);
u8 byte = Memory::Read_U8(address++);
TransferByte(byte);
}
}
void IEXIDevice::DMARead(u32 _uAddr, u32 _uSize)
void IEXIDevice::DMARead(u32 address, u32 size)
{
// _dbg_assert_(EXPANSIONINTERFACE, 0);
while (_uSize--)
while (size--)
{
u8 uByte = 0;
TransferByte(uByte);
Memory::Write_U8(uByte, _uAddr++);
u8 byte = 0;
TransferByte(byte);
Memory::Write_U8(byte, address++);
}
}
IEXIDevice* IEXIDevice::FindDevice(TEXIDevices device_type, int custom_index)
{
return (device_type == m_device_type) ? this : nullptr;
}
bool IEXIDevice::UseDelayedTransferCompletion() const
{
return false;
}
bool IEXIDevice::IsPresent() const
{
return false;
}
void IEXIDevice::SetCS(int cs)
{
}
void IEXIDevice::DoState(PointerWrap& p)
{
}
void IEXIDevice::PauseAndLock(bool do_lock, bool resume_on_unlock)
{
}
bool IEXIDevice::IsInterruptSet()
{
return false;
}
void IEXIDevice::TransferByte(u8& byte)
{
}
// F A C T O R Y
std::unique_ptr<IEXIDevice> EXIDevice_Create(TEXIDevices device_type, const int channel_num)
std::unique_ptr<IEXIDevice> EXIDevice_Create(const TEXIDevices device_type, const int channel_num)
{
std::unique_ptr<IEXIDevice> result;
@ -111,7 +149,7 @@ std::unique_ptr<IEXIDevice> EXIDevice_Create(TEXIDevices device_type, const int
}
if (result != nullptr)
result->m_deviceType = device_type;
result->m_device_type = device_type;
return result;
}

View File

@ -25,40 +25,42 @@ enum TEXIDevices : int
// Converted to EXIDEVICE_MEMORYCARD internally.
EXIDEVICE_MEMORYCARDFOLDER,
EXIDEVICE_AGP,
EXIDEVICE_NONE = (u8)-1
EXIDEVICE_NONE = 0xFF
};
class IEXIDevice
{
private:
// Byte transfer function for this device
virtual void TransferByte(u8&) {}
public:
// Immediate copy functions
virtual void ImmWrite(u32 _uData, u32 _uSize);
virtual u32 ImmRead(u32 _uSize);
virtual void ImmReadWrite(u32& /*_uData*/, u32 /*_uSize*/) {}
// DMA copy functions
virtual void DMAWrite(u32 _uAddr, u32 _uSize);
virtual void DMARead(u32 _uAddr, u32 _uSize);
virtual ~IEXIDevice() = default;
virtual bool UseDelayedTransferCompletion() const { return false; }
virtual bool IsPresent() const { return false; }
virtual void SetCS(int) {}
virtual void DoState(PointerWrap&) {}
virtual void PauseAndLock(bool doLock, bool unpauseOnUnlock = true) {}
virtual IEXIDevice* FindDevice(TEXIDevices device_type, int customIndex = -1)
{
return (device_type == m_deviceType) ? this : nullptr;
}
// Immediate copy functions
virtual void ImmWrite(u32 data, u32 size);
virtual u32 ImmRead(u32 size);
virtual void ImmReadWrite(u32& data, u32 size);
// DMA copy functions
virtual void DMAWrite(u32 address, u32 size);
virtual void DMARead(u32 address, u32 size);
virtual IEXIDevice* FindDevice(TEXIDevices device_type, int custom_index = -1);
virtual bool UseDelayedTransferCompletion() const;
virtual bool IsPresent() const;
virtual void SetCS(int cs);
virtual void DoState(PointerWrap& p);
virtual void PauseAndLock(bool do_lock, bool resume_on_unlock = true);
// Is generating interrupt ?
virtual bool IsInterruptSet() { return false; }
virtual ~IEXIDevice() {}
// for savestates. storing it here seemed cleaner than requiring each implementation to report its
// type.
// I know this class is set up like an interface, but no code requires it to be strictly such.
TEXIDevices m_deviceType;
virtual bool IsInterruptSet();
// For savestates. storing it here seemed cleaner than requiring each implementation to report its
// type. I know this class is set up like an interface, but no code requires it to be strictly
// such.
TEXIDevices m_device_type;
private:
// Byte transfer function for this device
virtual void TransferByte(u8& byte);
};
std::unique_ptr<IEXIDevice> EXIDevice_Create(const TEXIDevices device_type, const int channel_num);
std::unique_ptr<IEXIDevice> EXIDevice_Create(TEXIDevices device_type, int channel_num);

View File

@ -488,7 +488,7 @@ void CEXIMemoryCard::DoState(PointerWrap& p)
IEXIDevice* CEXIMemoryCard::FindDevice(TEXIDevices device_type, int customIndex)
{
if (device_type != m_deviceType)
if (device_type != m_device_type)
return nullptr;
if (customIndex != card_index)
return nullptr;