Merge pull request #1344 from reicast/baka/emptyvmu

Maple: Corrected creation of empty VMU
This commit is contained in:
Abandoned Cart 2018-08-27 09:11:24 -04:00 committed by GitHub
commit 6289c72a37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 75 additions and 43 deletions

View File

@ -272,24 +272,43 @@ struct maple_sega_vmu: maple_base
u8 lcd_data[192];
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()
{
memset(flash_data,0,sizeof(flash_data));
memset(lcd_data,0,sizeof(lcd_data));
memset(flash_data, 0, sizeof(flash_data));
memset(lcd_data, 0, sizeof(lcd_data));
wchar tempy[512];
sprintf(tempy,"/vmu_save_%s.bin",logical_port);
string apath=get_writable_data_path(tempy);
sprintf(tempy, "/vmu_save_%s.bin", logical_port);
string apath = get_writable_data_path(tempy);
file=fopen(apath.c_str(),"rb+");
file = fopen(apath.c_str(), "rb+");
if (!file)
{
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 (!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);
fseek(file,0,SEEK_SET);
} else {
printf("Unable to create vmu\n");
fseek(file, 0, SEEK_SET);
}
else
{
printf("Unable to create VMU!\n");
}
}
@ -299,20 +318,33 @@ struct maple_sega_vmu: maple_base
}
else
{
fread(flash_data,1,sizeof(flash_data),file);
fread(flash_data, 1, sizeof(flash_data), file);
}
u8 sum = 0;
for (int i=0;i<sizeof(flash_data);i++)
sum|=flash_data[i];
for (int i = 0; i < sizeof(flash_data); i++)
sum |= flash_data[i];
if (sum == 0) {
printf("Initialising empty vmu...\n");
uLongf dec_sz = sizeof(flash_data);
int rv=uncompress(flash_data, &dec_sz, vmu_default, sizeof(vmu_default));
// This means the existing VMU file is completely empty and needs to be recreated
verify(rv == Z_OK);
verify(dec_sz == sizeof(flash_data));
if (init_emptyvmu())
{
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");
}
}
}