Merge pull request #1344 from reicast/baka/emptyvmu
Maple: Corrected creation of empty VMU
This commit is contained in:
commit
6289c72a37
|
@ -272,24 +272,43 @@ struct maple_sega_vmu: maple_base
|
||||||
u8 lcd_data[192];
|
u8 lcd_data[192];
|
||||||
u8 lcd_data_decoded[48*32];
|
u8 lcd_data_decoded[48*32];
|
||||||
|
|
||||||
|
// creates an empty VMU
|
||||||
|
bool init_emptyvmu()
|
||||||
|
{
|
||||||
|
printf("Initialising empty VMU...\n");
|
||||||
|
|
||||||
|
uLongf dec_sz = sizeof(flash_data);
|
||||||
|
int rv = uncompress(flash_data, &dec_sz, vmu_default, sizeof(vmu_default));
|
||||||
|
|
||||||
|
verify(rv == Z_OK);
|
||||||
|
verify(dec_sz == sizeof(flash_data));
|
||||||
|
|
||||||
|
return (rv == Z_OK && dec_sz == sizeof(flash_data));
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnSetup()
|
virtual void OnSetup()
|
||||||
{
|
{
|
||||||
memset(flash_data,0,sizeof(flash_data));
|
memset(flash_data, 0, sizeof(flash_data));
|
||||||
memset(lcd_data,0,sizeof(lcd_data));
|
memset(lcd_data, 0, sizeof(lcd_data));
|
||||||
wchar tempy[512];
|
wchar tempy[512];
|
||||||
sprintf(tempy,"/vmu_save_%s.bin",logical_port);
|
sprintf(tempy, "/vmu_save_%s.bin", logical_port);
|
||||||
string apath=get_writable_data_path(tempy);
|
string apath = get_writable_data_path(tempy);
|
||||||
|
|
||||||
file=fopen(apath.c_str(),"rb+");
|
file = fopen(apath.c_str(), "rb+");
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
printf("Unable to open VMU save file \"%s\", creating new file\n",apath.c_str());
|
printf("Unable to open VMU save file \"%s\", creating new file\n",apath.c_str());
|
||||||
file=fopen(apath.c_str(),"wb");
|
file = fopen(apath.c_str(), "wb");
|
||||||
if (file) {
|
if (file) {
|
||||||
|
if (!init_emptyvmu())
|
||||||
|
printf("Failed to initialize an empty VMU, you should reformat it using the BIOS\n");
|
||||||
|
|
||||||
fwrite(flash_data, sizeof(flash_data), 1, file);
|
fwrite(flash_data, sizeof(flash_data), 1, file);
|
||||||
fseek(file,0,SEEK_SET);
|
fseek(file, 0, SEEK_SET);
|
||||||
} else {
|
}
|
||||||
printf("Unable to create vmu\n");
|
else
|
||||||
|
{
|
||||||
|
printf("Unable to create VMU!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,20 +318,33 @@ struct maple_sega_vmu: maple_base
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fread(flash_data,1,sizeof(flash_data),file);
|
fread(flash_data, 1, sizeof(flash_data), file);
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 sum = 0;
|
u8 sum = 0;
|
||||||
for (int i=0;i<sizeof(flash_data);i++)
|
for (int i = 0; i < sizeof(flash_data); i++)
|
||||||
sum|=flash_data[i];
|
sum |= flash_data[i];
|
||||||
|
|
||||||
if (sum == 0) {
|
if (sum == 0) {
|
||||||
printf("Initialising empty vmu...\n");
|
// This means the existing VMU file is completely empty and needs to be recreated
|
||||||
uLongf dec_sz = sizeof(flash_data);
|
|
||||||
int rv=uncompress(flash_data, &dec_sz, vmu_default, sizeof(vmu_default));
|
|
||||||
|
|
||||||
verify(rv == Z_OK);
|
if (init_emptyvmu())
|
||||||
verify(dec_sz == sizeof(flash_data));
|
{
|
||||||
|
if (!file)
|
||||||
|
file = fopen(apath.c_str(), "wb");
|
||||||
|
|
||||||
|
if (file) {
|
||||||
|
fwrite(flash_data, sizeof(flash_data), 1, file);
|
||||||
|
fseek(file, 0, SEEK_SET);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("Unable to create VMU!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Failed to initialize an empty VMU, you should reformat it using the BIOS\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue