From dbbebc45954d881dda066299aa4ce2855935fb8c Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Wed, 4 Jan 2017 16:02:22 -0800 Subject: [PATCH] Libretro: Fix saving in GB games (fixes #486) --- CHANGES | 1 + src/platform/libretro/libretro.c | 33 ++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/CHANGES b/CHANGES index b19f2da83..dbb400deb 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,7 @@ Bugfixes: - ARM7: Fix MLA/*MULL/*MLAL timing - GBA: Fix multiboot ROM loading + - Libretro: Fix saving in GB games (fixes mgba.io/i/486) 0.5.2: (2016-12-31) Bugfixes: diff --git a/src/platform/libretro/libretro.c b/src/platform/libretro/libretro.c index c784cb4b3..aff64bd23 100644 --- a/src/platform/libretro/libretro.c +++ b/src/platform/libretro/libretro.c @@ -524,19 +524,28 @@ size_t retro_get_memory_size(unsigned id) { if (id != RETRO_MEMORY_SAVE_RAM) { return 0; } - switch (((struct GBA*) core->board)->memory.savedata.type) { - case SAVEDATA_AUTODETECT: - case SAVEDATA_FLASH1M: - return SIZE_CART_FLASH1M; - case SAVEDATA_FLASH512: - return SIZE_CART_FLASH512; - case SAVEDATA_EEPROM: - return SIZE_CART_EEPROM; - case SAVEDATA_SRAM: - return SIZE_CART_SRAM; - case SAVEDATA_FORCE_NONE: - return 0; +#ifdef M_CORE_GBA + if (core->platform(core) == PLATFORM_GBA) { + switch (((struct GBA*) core->board)->memory.savedata.type) { + case SAVEDATA_AUTODETECT: + case SAVEDATA_FLASH1M: + return SIZE_CART_FLASH1M; + case SAVEDATA_FLASH512: + return SIZE_CART_FLASH512; + case SAVEDATA_EEPROM: + return SIZE_CART_EEPROM; + case SAVEDATA_SRAM: + return SIZE_CART_SRAM; + case SAVEDATA_FORCE_NONE: + return 0; + } } +#endif +#ifdef M_CORE_GB + if (core->platform(core) == PLATFORM_GB) { + return ((struct GB*) core->board)->sramSize; + } +#endif return 0; }