Clear memory config when deiniting

This commit is contained in:
Jesse Talavera-Greenberg 2023-06-01 17:17:37 -04:00
parent fd4cf2a699
commit 5a31860579
3 changed files with 42 additions and 0 deletions

View File

@ -272,6 +272,7 @@ PUBLIC_SYMBOL bool retro_load_game_special(unsigned type, const struct retro_gam
PUBLIC_SYMBOL void retro_deinit(void) {
melonds::_base_directory.clear();
melonds::_save_directory.clear();
melonds::clear_memory_config();
Platform::DeInit();
}

View File

@ -116,3 +116,38 @@ PUBLIC_SYMBOL void retro_cheat_set(unsigned index, bool enabled, const char *cod
}
AREngine::RunCheat(curcode);
}
// TODO: See NDS.cpp for details on the memory maps (see ARM9Read8)
bool melonds::set_memory_descriptors() {
retro_memory_descriptor descriptors[] = {
{
.flags = RETRO_MEMDESC_SYSTEM_RAM,
.ptr = NDS::MainRAM,
.start = 0x02000000,
.select = 0,
.disconnect = Config::ConsoleType == DSi ? ~(size_t) 0xFFFFFF : ~(size_t) 0x3FFFFF,
.len = Config::ConsoleType == DSi ? DSI_MEMORY_SIZE : DS_MEMORY_SIZE,
.addrspace = "RAM",
},
{
.flags = RETRO_MEMDESC_SAVE_RAM,
.ptr = NDSCart::GetSaveMemory(),
.start = 0,
.select = 0,
.disconnect = 0,
.len = NDSCart::GetSaveMemoryLength(),
.addrspace = "SRAM",
},
};
retro_memory_map memory_map{
.descriptors = descriptors,
.num_descriptors = sizeof(descriptors) / sizeof(descriptors[0]),
};
return retro::environment(RETRO_ENVIRONMENT_SET_MEMORY_MAPS, &memory_map);
}
void melonds::clear_memory_config() {
_savestate_size = SAVESTATE_SIZE_UNKNOWN;
}

View File

@ -23,5 +23,11 @@ namespace melonds {
using std::size_t;
constexpr size_t DEFAULT_SERIALIZE_TEST_SIZE = 16 * 1024 * 1024; // 16 MiB
bool set_memory_descriptors();
constexpr unsigned NINTENDO_DS_MEMORY_SAVE_RAM = 0x101;
void clear_memory_config();
}
#endif //MELONDS_DS_MEMORY_HPP