diff --git a/desmume/src/addons/slot1_retail_auto.cpp b/desmume/src/addons/slot1_retail_auto.cpp index 434fe3c56..6333495ff 100644 --- a/desmume/src/addons/slot1_retail_auto.cpp +++ b/desmume/src/addons/slot1_retail_auto.cpp @@ -51,7 +51,7 @@ public: mSelectedImplementation = slot1_List[selection]; mSelectedImplementation->connect(); printf("Slot1 auto-selected device type: %s\n",mSelectedImplementation->info()->name()); - + slot1_selected_id = selection; } virtual void disconnect() diff --git a/desmume/src/addons/slot2_auto.cpp b/desmume/src/addons/slot2_auto.cpp index da098dcce..1e0579f1f 100644 --- a/desmume/src/addons/slot2_auto.cpp +++ b/desmume/src/addons/slot2_auto.cpp @@ -79,6 +79,7 @@ public: mSelectedImplementation = slot2_List[selection]; mSelectedImplementation->connect(); printf("Slot2 auto-selected device type: %s\n", mSelectedImplementation->info()->name()); + slot2_selected_id = selection; #ifdef HOST_WINDOWS Guitar.Enabled = (selection == NDS_SLOT2_GUITARGRIP)?true:false; diff --git a/desmume/src/saves.cpp b/desmume/src/saves.cpp index 52820ba94..7b994206c 100644 --- a/desmume/src/saves.cpp +++ b/desmume/src/saves.cpp @@ -18,8 +18,6 @@ along with the this software. If not, see . */ -//MUST SAVE ADDONS! OMG HOW DID WE FORGET THAT - #ifdef HAVE_LIBZ #include #endif @@ -44,6 +42,7 @@ #include "mic.h" #include "MMU_timing.h" #include "slot1.h" +#include "slot2.h" #include "path.h" @@ -373,8 +372,12 @@ static bool s_slot1_loadstate(EMUFILE* is, int size) //version 0: if(version >= 0) { - int slotType = is->read32le(); - slot1_Change((NDS_SLOT1_TYPE)slotType); + u8 slotID = is->read32le(); + NDS_SLOT1_TYPE slotType = NDS_SLOT1_RETAIL_AUTO; + if (version >= 1) + slot1_getTypeByID(slotID, slotType); + + slot1_Change(slotType); EMUFILE_MEMORY temp; is->readMemoryStream(&temp); @@ -387,18 +390,52 @@ static bool s_slot1_loadstate(EMUFILE* is, int size) static void s_slot1_savestate(EMUFILE* os) { - u32 version = 0; + u32 version = 1; os->write32le(version); - //version 0: - int slotType = (int)slot1_GetCurrentType(); - os->write32le(slotType); + u8 slotID = (u8)slot1_List[slot1_GetCurrentType()]->info()->id(); + os->write32le(slotID); EMUFILE_MEMORY temp; slot1_Savestate(&temp); os->writeMemoryStream(&temp); } +static bool s_slot2_loadstate(EMUFILE* is, int size) +{ + u32 version = is->read32le(); + + //version 0: + if(version >= 0) + { + u8 slotID = is->read32le(); + NDS_SLOT2_TYPE slotType = NDS_SLOT2_AUTO; + slot2_getTypeByID(slotID, slotType); + + slot2_Change(slotType); + + EMUFILE_MEMORY temp; + is->readMemoryStream(&temp); + temp.fseek(0,SEEK_SET); + slot2_Loadstate(&temp); + } + + return true; +} + +static void s_slot2_savestate(EMUFILE* os) +{ + u32 version = 0; + os->write32le(version); + + u8 slotID = (u8)slot2_List[slot2_GetCurrentType()]->info()->id(); + os->write32le(slotID); + + EMUFILE_MEMORY temp; + slot2_Savestate(&temp); + os->writeMemoryStream(&temp); +} + static void mmu_savestate(EMUFILE* os) { u32 version = 8; @@ -988,8 +1025,8 @@ static void writechunks(EMUFILE* os) { savestate_WriteChunk(os,120,SF_RTC); savestate_WriteChunk(os,130,SF_NDS_HEADER); savestate_WriteChunk(os,140,s_slot1_savestate); + savestate_WriteChunk(os,150,s_slot2_savestate); // reserved for future versions - savestate_WriteChunk(os,150,reserveChunks); savestate_WriteChunk(os,160,reserveChunks); savestate_WriteChunk(os,170,reserveChunks); savestate_WriteChunk(os,180,reserveChunks); @@ -1039,8 +1076,8 @@ static bool ReadStateChunks(EMUFILE* is, s32 totalsize) case 120: if(!ReadStateChunk(is,SF_RTC,size)) ret=false; break; case 130: if(!ReadStateChunk(is,SF_HEADER,size)) ret=false; else haveInfo=true; break; case 140: if(!s_slot1_loadstate(is, size)) ret=false; break; + case 150: if(!s_slot2_loadstate(is, size)) ret=false; break; // reserved for future versions - case 150: case 160: case 170: case 180: @@ -1067,6 +1104,8 @@ static bool ReadStateChunks(EMUFILE* is, s32 totalsize) printf("\tDevice capacity: %dMb (real size %dMb)\n", ((128 * 1024) << header.cardSize) / (1024 * 1024), romsize / (1024 * 1024)); printf("\tCRC16: %04Xh\n", header.CRC16); printf("\tHeader CRC16: %04Xh\n", header.headerCRC16); + printf("\tSlot1: %s\n", slot1_List[slot1_GetCurrentType()]->info()->name()); + printf("\tSlot2: %s\n", slot2_List[slot2_GetCurrentType()]->info()->name()); if (gameInfo.romsize != romsize || memcmp(&gameInfo.header, &header, sizeof(header)) != 0) msgbox->warn("The savestate you are loading does not match the ROM you are running.\nYou should find the correct ROM"); diff --git a/desmume/src/slot1.cpp b/desmume/src/slot1.cpp index 7708b6d32..7403c5cd0 100644 --- a/desmume/src/slot1.cpp +++ b/desmume/src/slot1.cpp @@ -36,6 +36,8 @@ Since GCROMCTRL[26:24] can't represent 'data block size' of 1 or 2, it is assume #include "utils/vfat.h" #include "path.h" +NDS_SLOT1_TYPE slot1_selected_id = NDS_SLOT1_NONE; + bool slot1_R4_path_type = false; //------- @@ -189,6 +191,13 @@ NDS_SLOT1_TYPE slot1_GetCurrentType() return slot1_device_type; } +NDS_SLOT1_TYPE slot1_GetSelectedType() +{ + if (slot1_device_type == NDS_SLOT1_RETAIL_AUTO) + return slot1_selected_id; + return slot1_device_type; +} + void slot1_Savestate(EMUFILE* os) { slot1_device->savestate(os); diff --git a/desmume/src/slot1.h b/desmume/src/slot1.h index bf57539f9..0337a970b 100644 --- a/desmume/src/slot1.h +++ b/desmume/src/slot1.h @@ -108,6 +108,7 @@ enum NDS_SLOT1_TYPE extern ISlot1Interface* slot1_device; //the current slot1 device instance extern ISlot1Interface* slot1_List[NDS_SLOT1_COUNT]; +extern NDS_SLOT1_TYPE slot1_selected_id; void slot1_Init(); bool slot1_Connect(); @@ -129,6 +130,7 @@ bool slot1_ChangeByID(u8 ID); //check on the current device NDS_SLOT1_TYPE slot1_GetCurrentType(); +NDS_SLOT1_TYPE slot1_GetSelectedType(); extern bool slot1_R4_path_type; void slot1_SetFatDir(const std::string& dir, bool sameAsRom = false); diff --git a/desmume/src/slot2.cpp b/desmume/src/slot2.cpp index 7f4206c5c..eb5639336 100644 --- a/desmume/src/slot2.cpp +++ b/desmume/src/slot2.cpp @@ -19,6 +19,8 @@ #include "mem.h" #include "MMU.h" +NDS_SLOT2_TYPE slot2_selected_id = NDS_SLOT2_NONE; + //this is the currently-configured cflash mode ADDON_CFLASH_MODE CFlash_Mode = ADDON_CFLASH_MODE_RomPath; @@ -140,6 +142,14 @@ NDS_SLOT2_TYPE slot2_GetCurrentType() return slot2_device_type; } +NDS_SLOT2_TYPE slot2_GetSelectetType() +{ + if (slot2_device_type == NDS_SLOT2_AUTO) + return slot2_selected_id; + + return slot2_device_type; +} + void slot2_Savestate(EMUFILE* os) { slot2_device->savestate(os); diff --git a/desmume/src/slot2.h b/desmume/src/slot2.h index 621dff064..053ac28db 100644 --- a/desmume/src/slot2.h +++ b/desmume/src/slot2.h @@ -97,6 +97,7 @@ enum NDS_SLOT2_TYPE extern ISlot2Interface* slot2_device; //the current slot2 device instance extern ISlot2Interface* slot2_List[NDS_SLOT2_COUNT]; +extern NDS_SLOT2_TYPE slot2_selected_id; void slot2_Init(); bool slot2_Connect(); @@ -118,6 +119,7 @@ bool slot2_ChangeByID(u8 ID); //check on the current device NDS_SLOT2_TYPE slot2_GetCurrentType(); +NDS_SLOT2_TYPE slot2_GetSelectedType(); template bool slot2_write(u32 addr, T val);