mirror of
https://github.com/dborth/fceugx.git
synced 2024-11-01 06:55:05 +01:00
Fixes to get it working (I think)
This commit is contained in:
parent
efd5bfa7b0
commit
20bebd6025
@ -87,13 +87,25 @@ bool SaveRAM (char * filepath, bool silent)
|
|||||||
|
|
||||||
if (goomba_is_sram(&tag))
|
if (goomba_is_sram(&tag))
|
||||||
{
|
{
|
||||||
goomba_cleanup(savebuffer);
|
void* gba_data = malloc(GOOMBA_COLOR_SRAM_SIZE);
|
||||||
|
|
||||||
|
file = fopen(filepath, "rb");
|
||||||
|
fread(gba_data, 1, GOOMBA_COLOR_SRAM_SIZE, file);
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
|
void* cleaned = goomba_cleanup(gba_data);
|
||||||
|
if (!cleaned) {
|
||||||
|
ErrorPrompt(goomba_last_error());
|
||||||
|
} else if (cleaned != gba_data) {
|
||||||
|
memcpy(gba_data, cleaned, GOOMBA_COLOR_SRAM_SIZE);
|
||||||
|
free(cleaned);
|
||||||
|
}
|
||||||
|
|
||||||
// Look for just one save file. If there aren't any, or there is more than one, don't read any data.
|
// Look for just one save file. If there aren't any, or there is more than one, don't read any data.
|
||||||
stateheader* sh1 = NULL;
|
stateheader* sh1 = NULL;
|
||||||
stateheader* sh2 = NULL;
|
stateheader* sh2 = NULL;
|
||||||
|
|
||||||
stateheader* sh = (stateheader*)(savebuffer + 4);
|
stateheader* sh = (stateheader*)(gba_data + 4);
|
||||||
while (sh && stateheader_plausible(sh)) {
|
while (sh && stateheader_plausible(sh)) {
|
||||||
if (little_endian_conv_16(sh->type) != GOOMBA_SRAMSAVE) {}
|
if (little_endian_conv_16(sh->type) != GOOMBA_SRAMSAVE) {}
|
||||||
else if (sh1 == NULL) {
|
else if (sh1 == NULL) {
|
||||||
@ -118,7 +130,11 @@ bool SaveRAM (char * filepath, bool silent)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char* newdata = goomba_new_sav(savebuffer, sh1, savebuffer, datasize);
|
char* newdata = goomba_new_sav(gba_data, sh1, savebuffer, datasize);
|
||||||
|
if (!newdata) {
|
||||||
|
ErrorPrompt(goomba_last_error());
|
||||||
|
datasize = 0;
|
||||||
|
} else {
|
||||||
memcpy(savebuffer, newdata, GOOMBA_COLOR_SRAM_SIZE);
|
memcpy(savebuffer, newdata, GOOMBA_COLOR_SRAM_SIZE);
|
||||||
datasize = GOOMBA_COLOR_SRAM_SIZE;
|
datasize = GOOMBA_COLOR_SRAM_SIZE;
|
||||||
free(newdata);
|
free(newdata);
|
||||||
@ -126,6 +142,7 @@ bool SaveRAM (char * filepath, bool silent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (datasize)
|
if (datasize)
|
||||||
{
|
{
|
||||||
@ -177,7 +194,13 @@ bool LoadRAM (char * filepath, bool silent)
|
|||||||
// Check to see if this is a PocketNES save file
|
// Check to see if this is a PocketNES save file
|
||||||
if (goomba_is_sram(savebuffer))
|
if (goomba_is_sram(savebuffer))
|
||||||
{
|
{
|
||||||
goomba_cleanup(savebuffer);
|
void* cleaned = goomba_cleanup(savebuffer);
|
||||||
|
if (!cleaned) {
|
||||||
|
ErrorPrompt(goomba_last_error());
|
||||||
|
} else if (cleaned != savebuffer) {
|
||||||
|
memcpy(savebuffer, cleaned, GOOMBA_COLOR_SRAM_SIZE);
|
||||||
|
free(cleaned);
|
||||||
|
}
|
||||||
|
|
||||||
// Look for just one save file. If there aren't any, or there is more than one, don't read any data.
|
// Look for just one save file. If there aren't any, or there is more than one, don't read any data.
|
||||||
stateheader* sh1 = NULL;
|
stateheader* sh1 = NULL;
|
||||||
@ -185,9 +208,7 @@ bool LoadRAM (char * filepath, bool silent)
|
|||||||
|
|
||||||
stateheader* sh = (stateheader*)(savebuffer + 4);
|
stateheader* sh = (stateheader*)(savebuffer + 4);
|
||||||
while (sh && stateheader_plausible(sh)) {
|
while (sh && stateheader_plausible(sh)) {
|
||||||
if (little_endian_conv_16(sh->type) != GOOMBA_SRAMSAVE) {
|
if (little_endian_conv_16(sh->type) != GOOMBA_SRAMSAVE) { }
|
||||||
InfoPrompt("Not sram");
|
|
||||||
}
|
|
||||||
else if (sh1 == NULL) {
|
else if (sh1 == NULL) {
|
||||||
sh1 = sh;
|
sh1 = sh;
|
||||||
}
|
}
|
||||||
|
@ -191,9 +191,12 @@ const stateheader* stateheader_first(const void* gba_data) {
|
|||||||
else if (check_le == POCKETNES_STATEID2) check++;
|
else if (check_le == POCKETNES_STATEID2) check++;
|
||||||
else if (check_le == SMSADVANCE_STATEID) check++;
|
else if (check_le == SMSADVANCE_STATEID) check++;
|
||||||
|
|
||||||
return stateheader_plausible(check)
|
if (stateheader_plausible(check)) {
|
||||||
? (stateheader*)check
|
return (stateheader*)check;
|
||||||
: NULL;
|
} else {
|
||||||
|
goomba_error("sh at %p not plausible - value: %08X", gba_data, *(uint32_t*)gba_data);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const stateheader** stateheader_scan(const void* gba_data) {
|
const stateheader** stateheader_scan(const void* gba_data) {
|
||||||
@ -202,6 +205,10 @@ const stateheader** stateheader_scan(const void* gba_data) {
|
|||||||
memset(headers, 0, psize * 64);
|
memset(headers, 0, psize * 64);
|
||||||
|
|
||||||
const stateheader* sh = stateheader_first(gba_data);
|
const stateheader* sh = stateheader_first(gba_data);
|
||||||
|
if (sh == NULL) {
|
||||||
|
free(headers);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (stateheader_plausible(sh) && i < 63) {
|
while (stateheader_plausible(sh) && i < 63) {
|
||||||
headers[i] = sh;
|
headers[i] = sh;
|
||||||
@ -289,12 +296,15 @@ char* goomba_cleanup(const void* gba_data_param) {
|
|||||||
goomba_configdata* gcd = NULL;
|
goomba_configdata* gcd = NULL;
|
||||||
smsadvance_configdata* scd = NULL;
|
smsadvance_configdata* scd = NULL;
|
||||||
|
|
||||||
if (cd->size == sizeof(goomba_configdata)) {
|
if (F16(cd->size) == sizeof(goomba_configdata)) {
|
||||||
gcd = (goomba_configdata*)cd;
|
gcd = (goomba_configdata*)cd;
|
||||||
checksum = F32(gcd->sram_checksum); // 0 = clean, postitive = unclean
|
checksum = F32(gcd->sram_checksum); // 0 = clean, postitive = unclean
|
||||||
} else if (cd->size == sizeof(smsadvance_configdata)) {
|
} else if (F16(cd->size) == sizeof(smsadvance_configdata)) {
|
||||||
scd = (smsadvance_configdata*)cd;
|
scd = (smsadvance_configdata*)cd;
|
||||||
checksum = F32(scd->sram_checksum); // 0 = clean, postitive = unclean
|
checksum = F32(scd->sram_checksum); // 0 = clean, postitive = unclean
|
||||||
|
} else {
|
||||||
|
goomba_error("Unrecognized size of configdata, cannot clean");
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j = 0; headers[j] != NULL; j++) {
|
for (j = 0; headers[j] != NULL; j++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user