Skip to content

Commit 47f91c4

Browse files
authored
interface API: add backup memory import/export functions (#930)
* Add backup memory import/export API to interface * Add documentation for backup import/export functions * Simplify API
1 parent 84676aa commit 47f91c4

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

desmume/src/frontend/interface/interface.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,28 @@ EXPORTED char* desmume_savestate_slot_date(int index)
287287
return savestates[index].date;
288288
}
289289

290+
EXPORTED BOOL desmume_backup_import_file(const char *filename, unsigned int force_size) {
291+
if (!nds.backupDevice.isBackupDeviceAvailable()) {
292+
return FALSE;
293+
}
294+
295+
bool success = nds.backupDevice.importData(filename, force_size);
296+
297+
if (success) {
298+
NDS_Reset();
299+
}
300+
301+
return success ? TRUE : FALSE;
302+
}
303+
304+
EXPORTED BOOL desmume_backup_export_file(const char *filename) {
305+
if (!nds.backupDevice.isBackupDeviceAvailable()) {
306+
return FALSE;
307+
}
308+
309+
return nds.backupDevice.exportData(filename) ? TRUE : FALSE;
310+
}
311+
290312
EXPORTED BOOL desmume_gpu_get_layer_main_enable_state(int layer_index)
291313
{
292314
return GPU->GetEngineMain()->GetLayerEnableState(layer_index);

desmume/src/frontend/interface/interface.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,27 @@ EXPORTED void desmume_savestate_slot_save(int index);
106106
EXPORTED BOOL desmume_savestate_slot_exists(int index);
107107
EXPORTED char* desmume_savestate_slot_date(int index);
108108

109+
// Battery save (backup memory) import/export
110+
111+
/**
112+
* Import battery save file with optional size override.
113+
* Supports .sav (raw), .dsv (DeSmuME), .duc (Action Replay), .dss (DSOrganize).
114+
* The emulator will automatically reset after successful import.
115+
*
116+
* @param filename Path to battery save file
117+
* @param force_size Backup size in bytes (0 = auto-detect, or explicit size like 524288 for 512KB)
118+
* @return TRUE on success, FALSE on failure
119+
*/
120+
EXPORTED BOOL desmume_backup_import_file(const char *filename, unsigned int force_size);
121+
122+
/**
123+
* Export current battery save to .dsv file.
124+
*
125+
* @param filename Destination path for .dsv file
126+
* @return TRUE on success, FALSE on failure
127+
*/
128+
EXPORTED BOOL desmume_backup_export_file(const char *filename);
129+
109130
EXPORTED BOOL desmume_gpu_get_layer_main_enable_state(int layer_index);
110131
EXPORTED BOOL desmume_gpu_get_layer_sub_enable_state(int layer_index);
111132
EXPORTED void desmume_gpu_set_layer_main_enable_state(int layer_index, BOOL the_state);

0 commit comments

Comments
 (0)