Skip to content

Commit

Permalink
AGBSAVE: allow injecting smaller saves
Browse files Browse the repository at this point in the history
  • Loading branch information
d0k3 committed Sep 21, 2017
1 parent c80ebb1 commit b3243a2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions source/utils/nandutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,18 @@ u32 InjectGbaVcSavegame(const char* path, const char* path_vcsave) {
if ((fvx_stat(path_vcsave, &fno) != FR_OK) || !GBASAVE_VALID(fno.fsize))
return 1; // bad size

// read AGBsave header, savegame to memory
if ((fvx_qread(path, agbsave, 0, sizeof(AgbSaveHeader), NULL) != FR_OK) || (ValidateAgbSaveHeader(agbsave) != 0) ||
(fvx_qread(path_vcsave, savegame, 0, agbsave->save_size, NULL) != FR_OK)) return 1; // not a proper savegame for header
// read AGBsave header to memory
if ((fvx_qread(path, agbsave, 0, sizeof(AgbSaveHeader), NULL) != FR_OK) ||
(ValidateAgbSaveHeader(agbsave) != 0)) return 1; // not a proper header

// read savegame to memory
u32 inject_save_size = min(agbsave->save_size, fno.fsize);
memset(savegame, 0xFF, agbsave->save_size); // pad with 0xFF
if (fvx_qread(path_vcsave, savegame, 0, inject_save_size, NULL) != FR_OK) return 1;

// byteswap for eeprom type saves (512 byte / 8 kB)
if ((agbsave->save_size == GBASAVE_EEPROM_512) || (agbsave->save_size == GBASAVE_EEPROM_8K)) {
for (u8* ptr = savegame; (ptr - savegame) < (int) agbsave->save_size; ptr += 8)
for (u8* ptr = savegame; (ptr - savegame) < (int) inject_save_size; ptr += 8)
*(u64*) (void*) ptr = getbe64(ptr);
}

Expand Down

0 comments on commit b3243a2

Please sign in to comment.