diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index 0ff38f34e..837cd4b71 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -1090,7 +1090,7 @@ int NDS_ImportSave(const char *filename) return 0; if (memcmp(filename+strlen(filename)-4, ".duc", 4) == 0) - return mc_load_duc(&MMU.bupmem, filename); + return MMU_new.backupDevice.load_duc(filename); return 0; } diff --git a/desmume/src/mc.cpp b/desmume/src/mc.cpp index 1362319c9..f61d995a8 100644 --- a/desmume/src/mc.cpp +++ b/desmume/src/mc.cpp @@ -874,3 +874,39 @@ void BackupDevice::flush() LOG("Unable to open savefile %s\n",filename.c_str()); } } + +bool BackupDevice::load_duc(const char* filename) +{ + long size; + char id[16]; + FILE* file = fopen(filename, "rb"); + size_t elems_read = 0; + if(file == NULL) + return false; + + fseek(file, 0, SEEK_END); + size = ftell(file) - 500; + fseek(file, 0, SEEK_SET); + + // Make sure we really have the right file + elems_read += fread((void *)id, sizeof(char), 16, file); + + if (memcmp(id, "ARDS000000000001", 16) != 0) + { + LOG("Not recognized as a valid DUC file\n"); + fclose(file); + return false; + } + // Skip the rest of the header since we don't need it + fseek(file, 500, SEEK_SET); + + ensure((u32)size); + + fread(&data[0],1,size,file); + fclose(file); + + flush(); + + return true; + +} \ No newline at end of file diff --git a/desmume/src/mc.h b/desmume/src/mc.h index ead4e8aa7..8a30fec36 100644 --- a/desmume/src/mc.h +++ b/desmume/src/mc.h @@ -88,6 +88,8 @@ public: static u32 addr_size_for_old_save_size(int bupmem_size); static u32 addr_size_for_old_save_type(int bupmem_type); + bool load_duc(const char* filename); + private: BOOL write_enable; //is write enabled? u32 com; //persistent command actually handled