- optimizing reads/writes NAND backup data.

This commit is contained in:
mtabachenko 2013-11-16 12:30:47 +00:00
parent 88e34db3e7
commit b5f78e2652
4 changed files with 63 additions and 10 deletions

View File

@ -119,6 +119,7 @@ public:
if (save_start_adr != (protocol.address & gameInfo.mask) - subAdr)
{
save_start_adr = save_adr = (protocol.address & gameInfo.mask) - subAdr;
MMU_new.backupDevice.seek(save_start_adr);
}
handle_save = 1;
break;
@ -140,6 +141,7 @@ public:
if (save_start_adr != (protocol.address & gameInfo.mask) - subAdr)
{
save_start_adr = save_adr = (protocol.address & gameInfo.mask) - subAdr;
MMU_new.backupDevice.seek(save_start_adr);
}
}
else
@ -151,6 +153,7 @@ public:
case 0xB2: //Set save position
mode = cmd;
save_start_adr = save_adr = (protocol.address & gameInfo.mask) - subAdr;
MMU_new.backupDevice.seek(save_start_adr);
handle_save = 1;
break;
}
@ -185,7 +188,7 @@ public:
{
MMU_new.backupDevice.ensure(save_adr+4, (u8)0);
val = MMU_new.backupDevice.readLong(save_adr, 0);
val = MMU_new.backupDevice.readLong(0);
save_adr += 4;
}
@ -246,7 +249,7 @@ public:
case 0x81: //Nand Write
MMU_new.backupDevice.ensure(adr+4, (u8)0);
MMU_new.backupDevice.writeLong(adr, val);
MMU_new.backupDevice.writeLong(val);
save_adr += 4;
break;

View File

@ -451,6 +451,28 @@ u32 BackupDevice::readLong(u32 addr, const u32 init)
return val;
}
u8 BackupDevice::readByte(const u8 init)
{
u8 val = init;
fpMC->read8le(&val);
return val;
}
u16 BackupDevice::readWord(const u16 init)
{
u16 val = init;
fpMC->read16le(&val);
return val;
}
u32 BackupDevice::readLong(const u32 init)
{
u32 val = init;
fpMC->read32le(&val);
return val;
}
bool BackupDevice::write(u8 val)
{
#ifdef _DONT_SAVE_BACKUP
@ -481,6 +503,22 @@ void BackupDevice::writeLong(u32 addr, u32 val)
fpMC->write32le(val);
}
void BackupDevice::writeByte(u8 val)
{
if (isMovieMode) return;
fpMC->write8le(val);
}
void BackupDevice::writeWord(u16 val)
{
if (isMovieMode) return;
fpMC->write16le(val);
}
void BackupDevice::writeLong(u32 val)
{
if (isMovieMode) return;
fpMC->write32le(val);
}
bool BackupDevice::saveBuffer(u8 *data, u32 size, bool _rewind, bool _truncate)
{
if (_rewind)
@ -942,19 +980,20 @@ u32 BackupDevice::importDataSize(const char *filename)
return 0;
}
u32 BackupDevice::importData(const char *filename, u32 force_size)
bool BackupDevice::importData(const char *filename, u32 force_size)
{
u32 res = 0;
bool res = false;
if (strlen(filename) < 4) return res;
if (memcmp(filename + strlen(filename) - 4, ".duc", 4) == 0)
res = import_duc(filename, force_size);
else
if (import_no_gba(filename, force_size))
res = 1;
res = true;
else
res = import_raw(filename, force_size);
if (res)
NDS_Reset();
return res;

View File

@ -68,14 +68,24 @@ public:
void reset_hardware();
std::string getFilename() { return filename; }
u8 readByte(u32 addr, const u8 init = 0xFF);
u16 readWord(u32 addr, const u16 init = 0xFFFF);
u32 readLong(u32 addr, const u32 init = 0xFFFFFFFF);
u8 readByte(u32 addr, const u8 init);
u16 readWord(u32 addr, const u16 init);
u32 readLong(u32 addr, const u32 init);
u8 readByte(const u8 init);
u16 readWord(const u16 init);
u32 readLong(const u32 init);
void writeByte(u32 addr, u8 val);
void writeWord(u32 addr, u16 val);
void writeLong(u32 addr, u32 val);
void writeByte(u8 val);
void writeWord(u16 val);
void writeLong(u32 val);
void seek(u32 pos) { fpMC->fseek(pos, SEEK_SET); }
void flushBackup() { fpMC->fflush(); }
u8 searchFileSaveType(u32 size);
@ -123,7 +133,7 @@ public:
bool isMovieMode;
u32 importDataSize(const char *filename);
u32 importData(const char *filename, u32 force_size = 0);
bool importData(const char *filename, u32 force_size = 0);
bool exportData(const char *filename);
private:

View File

@ -2942,6 +2942,7 @@ int _main()
CommonSettings.loadToMemory = GetPrivateProfileBool("General", "loadType", true, IniName);
CommonSettings.cheatsDisable = GetPrivateProfileBool("General", "cheatsDisable", false, IniName);
CommonSettings.autodetectBackupMethod = GetPrivateProfileInt("General", "autoDetectMethod", 0, IniName);
CommonSettings.backupSave = GetPrivateProfileBool("General", "backupSave", false, IniName);
ColorCtrl_Register();
if (!RegWndClass("DeSmuME", WindowProcedure, CS_DBLCLKS, LoadIcon(hAppInst, MAKEINTRESOURCE(ICONDESMUME))))