Revert "Bus: Relax memory timing"

This reverts commit b5c799ba81.
This commit is contained in:
Connor McLaughlin 2019-11-17 22:11:16 +10:00
parent 38d0f46063
commit 19062e11b5
4 changed files with 35 additions and 72 deletions

View File

@ -104,6 +104,7 @@ private:
enum : u32 enum : u32
{ {
RAM_ACCESS_DELAY = 6, // Nocash docs say RAM takes 6 cycles to access.
MEMCTRL_REG_COUNT = 9 MEMCTRL_REG_COUNT = 9
}; };

View File

@ -22,8 +22,6 @@ TickCount Bus::DoRAMAccess(u32 offset, u32& value)
{ {
std::memcpy(&value, &m_ram[offset], sizeof(u32)); std::memcpy(&value, &m_ram[offset], sizeof(u32));
} }
return 3;
} }
else else
{ {
@ -40,10 +38,10 @@ TickCount Bus::DoRAMAccess(u32 offset, u32& value)
{ {
std::memcpy(&m_ram[offset], &value, sizeof(u32)); std::memcpy(&m_ram[offset], &value, sizeof(u32));
} }
// Technically RAM writes are buffered, and there's a maximum number of in-flight writes.
return 0;
} }
// Nocash docs say RAM takes 6 cycles to access.
return RAM_ACCESS_DELAY;
} }
template<MemoryAccessType type, MemoryAccessSize size> template<MemoryAccessType type, MemoryAccessSize size>
@ -107,33 +105,25 @@ TickCount Bus::DispatchAccess(PhysicalMemoryAddress address, u32& value)
else else
DoWriteMemoryControl(size, address & PAD_MASK, value); DoWriteMemoryControl(size, address & PAD_MASK, value);
return 0; return 1;
} }
else if (address < (PAD_BASE + PAD_SIZE)) else if (address < (PAD_BASE + PAD_SIZE))
{ {
if constexpr (type == MemoryAccessType::Read) if constexpr (type == MemoryAccessType::Read)
{
value = DoReadPad(size, address & PAD_MASK); value = DoReadPad(size, address & PAD_MASK);
return 1;
}
else else
{
DoWritePad(size, address & PAD_MASK, value); DoWritePad(size, address & PAD_MASK, value);
return 0;
} return 1;
} }
else if (address < (SIO_BASE + SIO_SIZE)) else if (address < (SIO_BASE + SIO_SIZE))
{ {
if constexpr (type == MemoryAccessType::Read) if constexpr (type == MemoryAccessType::Read)
{
value = DoReadSIO(size, address & SIO_MASK); value = DoReadSIO(size, address & SIO_MASK);
return 1;
}
else else
{
DoWriteSIO(size, address & SIO_MASK, value); DoWriteSIO(size, address & SIO_MASK, value);
return 0;
} return 1;
} }
else if (address < (MEMCTRL2_BASE + MEMCTRL2_SIZE)) else if (address < (MEMCTRL2_BASE + MEMCTRL2_SIZE))
{ {
@ -142,46 +132,34 @@ TickCount Bus::DispatchAccess(PhysicalMemoryAddress address, u32& value)
else else
DoWriteMemoryControl2(size, address & PAD_MASK, value); DoWriteMemoryControl2(size, address & PAD_MASK, value);
return 0; return 1;
} }
else if (address < (INTERRUPT_CONTROLLER_BASE + INTERRUPT_CONTROLLER_SIZE)) else if (address < (INTERRUPT_CONTROLLER_BASE + INTERRUPT_CONTROLLER_SIZE))
{ {
if constexpr (type == MemoryAccessType::Read) if constexpr (type == MemoryAccessType::Read)
{
value = DoReadInterruptController(size, address & INTERRUPT_CONTROLLER_MASK); value = DoReadInterruptController(size, address & INTERRUPT_CONTROLLER_MASK);
return 1;
}
else else
{
DoWriteInterruptController(size, address & INTERRUPT_CONTROLLER_MASK, value); DoWriteInterruptController(size, address & INTERRUPT_CONTROLLER_MASK, value);
return 0;
} return 1;
} }
else if (address < (DMA_BASE + DMA_SIZE)) else if (address < (DMA_BASE + DMA_SIZE))
{ {
if constexpr (type == MemoryAccessType::Read) if constexpr (type == MemoryAccessType::Read)
{
value = DoReadDMA(size, address & DMA_MASK); value = DoReadDMA(size, address & DMA_MASK);
return 1;
}
else else
{
DoWriteDMA(size, address & DMA_MASK, value); DoWriteDMA(size, address & DMA_MASK, value);
return 0;
} return 1;
} }
else if (address < (TIMERS_BASE + TIMERS_SIZE)) else if (address < (TIMERS_BASE + TIMERS_SIZE))
{ {
if constexpr (type == MemoryAccessType::Read) if constexpr (type == MemoryAccessType::Read)
{
value = DoReadTimers(size, address & TIMERS_MASK); value = DoReadTimers(size, address & TIMERS_MASK);
return 1;
}
else else
{
DoWriteTimers(size, address & TIMERS_MASK, value); DoWriteTimers(size, address & TIMERS_MASK, value);
return 0;
} return 1;
} }
else if (address < CDROM_BASE) else if (address < CDROM_BASE)
{ {
@ -190,41 +168,29 @@ TickCount Bus::DispatchAccess(PhysicalMemoryAddress address, u32& value)
else if (address < (CDROM_BASE + GPU_SIZE)) else if (address < (CDROM_BASE + GPU_SIZE))
{ {
if constexpr (type == MemoryAccessType::Read) if constexpr (type == MemoryAccessType::Read)
{
value = DoReadCDROM(size, address & CDROM_MASK); value = DoReadCDROM(size, address & CDROM_MASK);
return (TickCount(1) << static_cast<u8>(size));
}
else else
{
DoWriteCDROM(size, address & CDROM_MASK, value); DoWriteCDROM(size, address & CDROM_MASK, value);
return 0;
} return m_cdrom_access_time[static_cast<u32>(size)];
} }
else if (address < (GPU_BASE + GPU_SIZE)) else if (address < (GPU_BASE + GPU_SIZE))
{ {
if constexpr (type == MemoryAccessType::Read) if constexpr (type == MemoryAccessType::Read)
{
value = DoReadGPU(size, address & GPU_MASK); value = DoReadGPU(size, address & GPU_MASK);
return 1;
}
else else
{
DoWriteGPU(size, address & GPU_MASK, value); DoWriteGPU(size, address & GPU_MASK, value);
return 0;
} return 1;
} }
else if (address < (MDEC_BASE + MDEC_SIZE)) else if (address < (MDEC_BASE + MDEC_SIZE))
{ {
if constexpr (type == MemoryAccessType::Read) if constexpr (type == MemoryAccessType::Read)
{
value = DoReadMDEC(size, address & MDEC_MASK); value = DoReadMDEC(size, address & MDEC_MASK);
return 1;
}
else else
{
DoWriteMDEC(size, address & MDEC_MASK, value); DoWriteMDEC(size, address & MDEC_MASK, value);
return 0;
} return 1;
} }
else if (address < SPU_BASE) else if (address < SPU_BASE)
{ {
@ -233,15 +199,11 @@ TickCount Bus::DispatchAccess(PhysicalMemoryAddress address, u32& value)
else if (address < (SPU_BASE + SPU_SIZE)) else if (address < (SPU_BASE + SPU_SIZE))
{ {
if constexpr (type == MemoryAccessType::Read) if constexpr (type == MemoryAccessType::Read)
{
value = DoReadSPU(size, address & SPU_MASK); value = DoReadSPU(size, address & SPU_MASK);
return (size == MemoryAccessSize::Word) ? 36 : 16;
}
else else
{
DoWriteSPU(size, address & SPU_MASK, value); DoWriteSPU(size, address & SPU_MASK, value);
return 0;
} return m_spu_access_time[static_cast<u32>(size)];
} }
else if (address < EXP2_BASE) else if (address < EXP2_BASE)
{ {

View File

@ -128,7 +128,7 @@ bool Core::ReadMemoryByte(VirtualMemoryAddress addr, u8* value)
return false; return false;
} }
AddTicks(cycles); AddTicks(cycles - 1);
return true; return true;
} }
@ -146,7 +146,7 @@ bool Core::ReadMemoryHalfWord(VirtualMemoryAddress addr, u16* value)
return false; return false;
} }
AddTicks(cycles); AddTicks(cycles - 1);
return true; return true;
} }
@ -162,7 +162,7 @@ bool Core::ReadMemoryWord(VirtualMemoryAddress addr, u32* value)
return false; return false;
} }
AddTicks(cycles); AddTicks(cycles - 1);
return true; return true;
} }
@ -176,7 +176,7 @@ bool Core::WriteMemoryByte(VirtualMemoryAddress addr, u8 value)
return false; return false;
} }
AddTicks(cycles); AddTicks(cycles - 1);
return true; return true;
} }
@ -193,7 +193,7 @@ bool Core::WriteMemoryHalfWord(VirtualMemoryAddress addr, u16 value)
return false; return false;
} }
AddTicks(cycles); AddTicks(cycles - 1);
return cycles; return cycles;
} }
@ -209,7 +209,7 @@ bool Core::WriteMemoryWord(VirtualMemoryAddress addr, u32 value)
return false; return false;
} }
AddTicks(cycles); AddTicks(cycles - 1);
return true; return true;
} }

View File

@ -15,14 +15,14 @@ TickCount Core::DoMemoryAccess(VirtualMemoryAddress address, u32& value)
if constexpr (type == MemoryAccessType::Write) if constexpr (type == MemoryAccessType::Write)
{ {
if (m_cop0_regs.sr.Isc) if (m_cop0_regs.sr.Isc)
return 0; return 1;
} }
const PhysicalMemoryAddress phys_addr = address & UINT32_C(0x1FFFFFFF); const PhysicalMemoryAddress phys_addr = address & UINT32_C(0x1FFFFFFF);
if ((phys_addr & DCACHE_LOCATION_MASK) == DCACHE_LOCATION) if ((phys_addr & DCACHE_LOCATION_MASK) == DCACHE_LOCATION)
{ {
DoScratchpadAccess<type, size>(phys_addr, value); DoScratchpadAccess<type, size>(phys_addr, value);
return 0; return 1;
} }
return m_bus->DispatchAccess<type, size>(phys_addr, value); return m_bus->DispatchAccess<type, size>(phys_addr, value);
@ -41,14 +41,14 @@ TickCount Core::DoMemoryAccess(VirtualMemoryAddress address, u32& value)
if constexpr (type == MemoryAccessType::Write) if constexpr (type == MemoryAccessType::Write)
{ {
if (m_cop0_regs.sr.Isc) if (m_cop0_regs.sr.Isc)
return 0; return 1;
} }
const PhysicalMemoryAddress phys_addr = address & UINT32_C(0x1FFFFFFF); const PhysicalMemoryAddress phys_addr = address & UINT32_C(0x1FFFFFFF);
if ((phys_addr & DCACHE_LOCATION_MASK) == DCACHE_LOCATION) if ((phys_addr & DCACHE_LOCATION_MASK) == DCACHE_LOCATION)
{ {
DoScratchpadAccess<type, size>(phys_addr, value); DoScratchpadAccess<type, size>(phys_addr, value);
return 0; return 1;
} }
return m_bus->DispatchAccess<type, size>(phys_addr, value); return m_bus->DispatchAccess<type, size>(phys_addr, value);
@ -72,7 +72,7 @@ TickCount Core::DoMemoryAccess(VirtualMemoryAddress address, u32& value)
else else
WriteCacheControl(value); WriteCacheControl(value);
return 0; return 1;
} }
else else
{ {