diff --git a/desmume/src/frontend/interface/interface.cpp b/desmume/src/frontend/interface/interface.cpp index bb731db2c..4ba60554a 100644 --- a/desmume/src/frontend/interface/interface.cpp +++ b/desmume/src/frontend/interface/interface.cpp @@ -39,6 +39,7 @@ #define SCREENS_PIXEL_SIZE 98304 volatile bool execute = false; +static bool rom_opened = false; TieredRegion hooked_regions [HOOK_COUNT]; std::map hooks[HOOK_COUNT]; @@ -97,11 +98,23 @@ EXPORTED void desmume_set_language(u8 lang) EXPORTED int desmume_open(const char *filename) { int i; + if (rom_opened) { + NDS_FreeROM(); + } clear_savestates(); i = NDS_LoadROM(filename); + if (i > 0) { + rom_opened = true; + } return i; } +EXPORTED void desmume_close() +{ + NDS_FreeROM(); + rom_opened = false; +} + EXPORTED void desmume_set_savetype(int type) { backup_setManualBackupType(type); } diff --git a/desmume/src/frontend/interface/interface.h b/desmume/src/frontend/interface/interface.h index d595423c4..1b825247e 100755 --- a/desmume/src/frontend/interface/interface.h +++ b/desmume/src/frontend/interface/interface.h @@ -71,7 +71,10 @@ EXPORTED void desmume_free(void); // 0 = Japanese, 1 = English, 2 = French, 3 = German, 4 = Italian, 5 = Spanish EXPORTED void desmume_set_language(u8 language); +// Opens a new ROM, if a ROM was already opened, a new one is opened and the old was is automatically free'd. EXPORTED int desmume_open(const char *filename); +// Frees and closes a ROM opened with desmume_open. +EXPORTED void desmume_close(); EXPORTED void desmume_set_savetype(int type); EXPORTED void desmume_pause(void); EXPORTED void desmume_resume(void);