mirror of
https://github.com/libretro/beetle-psx-libretro.git
synced 2025-02-11 12:05:58 +00:00
Experimental memcard 0 writing as SRAM
This commit is contained in:
parent
4bce30b487
commit
9fdabb31d8
52
libretro.cpp
52
libretro.cpp
@ -1403,7 +1403,9 @@ static void InitCommon(std::vector<CDIF *> *CDInterfaces, const bool EmulateMemc
|
||||
BIOSFile.read(BIOSROM->data8, 512 * 1024);
|
||||
}
|
||||
|
||||
for(i = 0; i < 8; i++)
|
||||
FIO->LoadMemcard(0);
|
||||
|
||||
for(i = 1; i < 8; i++)
|
||||
{
|
||||
char ext[64];
|
||||
trio_snprintf(ext, sizeof(ext), "%d.mcr", i);
|
||||
@ -1681,6 +1683,12 @@ static void CloseGame(void)
|
||||
int i;
|
||||
for(i = 0; i < 8; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
FIO->SaveMemcard(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
// If there's an error saving one memcard, don't skip trying to save the other, since it might succeed and
|
||||
// we can reduce potential data loss!
|
||||
try
|
||||
@ -2538,12 +2546,19 @@ void retro_run(void)
|
||||
if (log_cb)
|
||||
log_cb(RETRO_LOG_INFO, "Saving memcard %d...\n", i);
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
FIO->SaveMemcard(i);
|
||||
Memcard_SaveDelay[i] = -1;
|
||||
Memcard_PrevDC[i] = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
char ext[64];
|
||||
trio_snprintf(ext, sizeof(ext), "%d.mcr", i);
|
||||
FIO->SaveMemcard(i, MDFN_MakeFName(MDFNMKF_SAV, 0, ext).c_str());
|
||||
Memcard_SaveDelay[i] = -1;
|
||||
Memcard_PrevDC[i] = 0;
|
||||
//MDFN_DispMessage("Memcard %d saved.", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2833,14 +2848,39 @@ bool retro_unserialize(const void *data, size_t size)
|
||||
return MDFNSS_LoadSM(&st, 0, 0);
|
||||
}
|
||||
|
||||
void *retro_get_memory_data(unsigned)
|
||||
extern uint8_t mcbuf[8][1 << 17];
|
||||
|
||||
void *retro_get_memory_data(unsigned type)
|
||||
{
|
||||
return NULL;
|
||||
uint8_t *data;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case RETRO_MEMORY_SAVE_RAM:
|
||||
data = mcbuf[0];
|
||||
break;
|
||||
default:
|
||||
data = NULL;
|
||||
break;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
size_t retro_get_memory_size(unsigned)
|
||||
size_t retro_get_memory_size(unsigned type)
|
||||
{
|
||||
return 0;
|
||||
unsigned size;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case RETRO_MEMORY_SAVE_RAM:
|
||||
size = (1 << 17);
|
||||
break;
|
||||
default:
|
||||
size = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
void retro_cheat_reset(void)
|
||||
|
@ -32,6 +32,8 @@
|
||||
|
||||
#define PSX_FIODBGINFO(format, ...) { /* printf(format " -- timestamp=%d -- PAD temp\n", ## __VA_ARGS__, timestamp); */ }
|
||||
|
||||
uint8_t mcbuf[8][1 << 17];
|
||||
|
||||
namespace MDFN_IEN_PSX
|
||||
{
|
||||
|
||||
@ -856,7 +858,16 @@ uint64_t FrontIO::GetMemcardDirtyCount(unsigned int which)
|
||||
return(DevicesMC[which]->GetNVDirtyCount());
|
||||
}
|
||||
|
||||
uint8_t tmpbuf[8][1 << 17];
|
||||
void FrontIO::LoadMemcard(unsigned int which)
|
||||
{
|
||||
assert(which < 8);
|
||||
|
||||
if(DevicesMC[which]->GetNVSize())
|
||||
{
|
||||
DevicesMC[which]->WriteNV(&mcbuf[which][0], 0, (1 << 17));
|
||||
DevicesMC[which]->ResetNVDirtyCount(); // There's no need to rewrite the file if it's the same data.
|
||||
}
|
||||
}
|
||||
|
||||
void FrontIO::LoadMemcard(unsigned int which, const char *path)
|
||||
{
|
||||
@ -868,9 +879,9 @@ void FrontIO::LoadMemcard(unsigned int which, const char *path)
|
||||
{
|
||||
FileStream mf(path, FileStream::MODE_READ);
|
||||
|
||||
mf.read(&tmpbuf[which][0], (1 << 17));
|
||||
mf.read(&mcbuf[which][0], (1 << 17));
|
||||
|
||||
DevicesMC[which]->WriteNV(&tmpbuf[which][0], 0, (1 << 17));
|
||||
DevicesMC[which]->WriteNV(&mcbuf[which][0], 0, (1 << 17));
|
||||
DevicesMC[which]->ResetNVDirtyCount(); // There's no need to rewrite the file if it's the same data.
|
||||
}
|
||||
}
|
||||
@ -881,6 +892,17 @@ void FrontIO::LoadMemcard(unsigned int which, const char *path)
|
||||
}
|
||||
}
|
||||
|
||||
void FrontIO::SaveMemcard(unsigned int which)
|
||||
{
|
||||
assert(which < 8);
|
||||
|
||||
if(DevicesMC[which]->GetNVSize() && DevicesMC[which]->GetNVDirtyCount())
|
||||
{
|
||||
DevicesMC[which]->ReadNV(&mcbuf[which][0], 0, (1 << 17));
|
||||
DevicesMC[which]->ResetNVDirtyCount();
|
||||
}
|
||||
}
|
||||
|
||||
void FrontIO::SaveMemcard(unsigned int which, const char *path)
|
||||
{
|
||||
assert(which < 8);
|
||||
@ -889,8 +911,8 @@ void FrontIO::SaveMemcard(unsigned int which, const char *path)
|
||||
{
|
||||
FileStream mf(path, FileStream::MODE_WRITE); // TODO: MODE_WRITE_ATOMIC_OVERWRITE
|
||||
|
||||
DevicesMC[which]->ReadNV(&tmpbuf[which][0], 0, (1 << 17));
|
||||
mf.write(&tmpbuf[which][0], (1 << 17));
|
||||
DevicesMC[which]->ReadNV(&mcbuf[which][0], 0, (1 << 17));
|
||||
mf.write(&mcbuf[which][0], (1 << 17));
|
||||
|
||||
mf.close(); // Call before resetting the NV dirty count!
|
||||
|
||||
|
@ -84,7 +84,9 @@ class FrontIO
|
||||
|
||||
uint64_t GetMemcardDirtyCount(unsigned int which);
|
||||
void LoadMemcard(unsigned int which, const char *path);
|
||||
void LoadMemcard(unsigned int which);
|
||||
void SaveMemcard(unsigned int which, const char *path); //, bool force_save = false);
|
||||
void SaveMemcard(unsigned int which);
|
||||
|
||||
int StateAction(StateMem* sm, int load, int data_only);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user