mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-04 06:40:03 +00:00
Emulate GameCube memory card speeds
This commit is contained in:
parent
063f530d4c
commit
8a0093de23
@ -18,6 +18,7 @@
|
|||||||
#include "Core/HW/GCMemcardRaw.h"
|
#include "Core/HW/GCMemcardRaw.h"
|
||||||
#include "Core/HW/Memmap.h"
|
#include "Core/HW/Memmap.h"
|
||||||
#include "Core/HW/Sram.h"
|
#include "Core/HW/Sram.h"
|
||||||
|
#include "Core/HW/SystemTimers.h"
|
||||||
#include "DiscIO/NANDContentLoader.h"
|
#include "DiscIO/NANDContentLoader.h"
|
||||||
|
|
||||||
#define MC_STATUS_BUSY 0x80
|
#define MC_STATUS_BUSY 0x80
|
||||||
@ -28,6 +29,12 @@
|
|||||||
#define MC_STATUS_READY 0x01
|
#define MC_STATUS_READY 0x01
|
||||||
#define SIZE_TO_Mb (1024 * 8 * 16)
|
#define SIZE_TO_Mb (1024 * 8 * 16)
|
||||||
|
|
||||||
|
// These are rough estimates based on GameCube video evidence of memory card "speeds"
|
||||||
|
// This will need to be refined, and perhaps the idea behind the speed thing is wrong
|
||||||
|
// But it works with (near?) perfect speed as far as saving goes
|
||||||
|
static const float MC_TRANSFER_RATE_WRITE = 22.0f * 1024.0f;
|
||||||
|
static const float MC_TRANSFER_RATE_READ = 73.84f * 1024.0f;
|
||||||
|
|
||||||
void CEXIMemoryCard::FlushCallback(u64 userdata, int cyclesLate)
|
void CEXIMemoryCard::FlushCallback(u64 userdata, int cyclesLate)
|
||||||
{
|
{
|
||||||
// note that userdata is forbidden to be a pointer, due to the implementation of EventDoState
|
// note that userdata is forbidden to be a pointer, due to the implementation of EventDoState
|
||||||
@ -227,26 +234,47 @@ void CEXIMemoryCard::SetCS(int cs)
|
|||||||
|
|
||||||
//???
|
//???
|
||||||
|
|
||||||
CmdDoneLater(5000);
|
if (address >= MC_DATA_FILES)
|
||||||
|
CmdDoneLater(BLOCK_SIZE * (SystemTimers::GetTicksPerSecond() / MC_TRANSFER_RATE_WRITE));
|
||||||
|
else
|
||||||
|
CmdDoneLater(5000);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case cmdChipErase:
|
case cmdChipErase:
|
||||||
if (m_uPosition > 2)
|
if (m_uPosition > 2)
|
||||||
{
|
{
|
||||||
// TODO: Investigate on HW, I (LPFaint99) believe that this only erases the system area (Blocks 0-4)
|
// Clear only the system blocks
|
||||||
memorycard->ClearAll();
|
for (int i = 0; i < 5; i++)
|
||||||
|
memorycard->ClearBlock(BLOCK_SIZE * i);
|
||||||
|
|
||||||
status &= ~MC_STATUS_BUSY;
|
status &= ~MC_STATUS_BUSY;
|
||||||
m_bDirty = true;
|
m_bDirty = true;
|
||||||
|
|
||||||
|
if (address >= MC_DATA_FILES)
|
||||||
|
CmdDoneLater((BLOCK_SIZE * 5) * (SystemTimers::GetTicksPerSecond() / MC_TRANSFER_RATE_WRITE));
|
||||||
|
else
|
||||||
|
CmdDoneLater(5000);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case cmdReadArray:
|
||||||
|
if (m_uPosition > 8)
|
||||||
|
{
|
||||||
|
// Each read is 512 bytes
|
||||||
|
if (address >= MC_DATA_FILES)
|
||||||
|
CmdDoneLater(512 * (SystemTimers::GetTicksPerSecond() / MC_TRANSFER_RATE_READ));
|
||||||
|
else
|
||||||
|
CmdDoneLater(5000);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case cmdPageProgram:
|
case cmdPageProgram:
|
||||||
if (m_uPosition >= 5)
|
if (m_uPosition > 4)
|
||||||
{
|
{
|
||||||
int count = m_uPosition - 5;
|
int count = m_uPosition - 5;
|
||||||
int i=0;
|
int i=0;
|
||||||
status &= ~0x80;
|
status &= ~MC_STATUS_BUSY;
|
||||||
|
|
||||||
while (count--)
|
while (count--)
|
||||||
{
|
{
|
||||||
@ -255,7 +283,11 @@ void CEXIMemoryCard::SetCS(int cs)
|
|||||||
address = (address & ~0x1FF) | ((address+1) & 0x1FF);
|
address = (address & ~0x1FF) | ((address+1) & 0x1FF);
|
||||||
}
|
}
|
||||||
|
|
||||||
CmdDoneLater(5000);
|
// Each write is 128 bytes
|
||||||
|
if (address >= MC_DATA_FILES)
|
||||||
|
CmdDoneLater(128 * (SystemTimers::GetTicksPerSecond() / MC_TRANSFER_RATE_WRITE));
|
||||||
|
else
|
||||||
|
CmdDoneLater(5000);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,17 @@ private:
|
|||||||
// Variant of CmdDone which schedules an event later in the future to complete the command.
|
// Variant of CmdDone which schedules an event later in the future to complete the command.
|
||||||
void CmdDoneLater(u64 cycles);
|
void CmdDoneLater(u64 cycles);
|
||||||
|
|
||||||
|
// Memory card data layout
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
MC_DATA_HEADER = 0x0000,
|
||||||
|
MC_DATA_DIRECTORY = 0x2000,
|
||||||
|
MC_DATA_DIRECTORYBACKUP = 0x4000,
|
||||||
|
MC_DATA_BLOCKALLOCMAP = 0x6000,
|
||||||
|
MC_DATA_BLOCKALLOCMAPBACKUP = 0x8000,
|
||||||
|
MC_DATA_FILES = 0xA000,
|
||||||
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
cmdNintendoID = 0x00,
|
cmdNintendoID = 0x00,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user