Maple: Corrected creation of empty VMU
The VMU which was written to disk was never initialized and therefore consisted only of zeroes. After saving for the first time the VMU was corrupted. Changes: * Not only initialize the VMU in memory but also write the correct contents to disk * If an existing VMU consists only of zeroes overwrite it with the initial empty VMU
This commit is contained in:
parent
2703c6574e
commit
bc873cb228
|
@ -272,6 +272,20 @@ 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));
|
||||
|
@ -286,10 +300,15 @@ struct maple_sega_vmu: maple_base
|
|||
printf("Unable to open VMU save file \"%s\", creating new file\n",apath.c_str());
|
||||
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");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unable to create VMU!\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -307,12 +326,25 @@ struct maple_sega_vmu: maple_base
|
|||
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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue