From b93120481e3a901fe8e2362a5b884d601122ed32 Mon Sep 17 00:00:00 2001 From: kub Date: Thu, 23 Jan 2025 21:58:44 +0100 Subject: [PATCH] platform, fix no cart sram for MSU/MD+ cartridges --- pico/cd/mcd.c | 18 ++++++++++-------- platform/common/emu.c | 8 ++++---- platform/libretro/libretro.c | 4 ++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/pico/cd/mcd.c b/pico/cd/mcd.c index 6c3548e3..de20b7b8 100644 --- a/pico/cd/mcd.c +++ b/pico/cd/mcd.c @@ -106,15 +106,17 @@ PICO_INTERNAL int PicoResetMCD(void) // reset button doesn't affect MCD hardware // use Pico.sv.data for RAM cart - if (PicoIn.opt & POPT_EN_MCD_RAMCART) { - if (Pico.sv.data == NULL) - Pico.sv.data = calloc(1, 0x12000); - } - else if (Pico.sv.data != NULL) { - free(Pico.sv.data); - Pico.sv.data = NULL; + if (Pico.romsize == 0) { + if (PicoIn.opt & POPT_EN_MCD_RAMCART) { + if (Pico.sv.data == NULL) + Pico.sv.data = calloc(1, 0x12000); + } + else if (Pico.sv.data != NULL) { + free(Pico.sv.data); + Pico.sv.data = NULL; + } + Pico.sv.start = Pico.sv.end = 0; // unused } - Pico.sv.start = Pico.sv.end = 0; // unused msd_reset(); return 0; diff --git a/platform/common/emu.c b/platform/common/emu.c index 1aa33459..627fc98c 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -868,9 +868,9 @@ char *emu_get_save_fname(int load, int is_sram, int slot, int *time) if (is_sram) { - strcpy(ext, (PicoIn.AHW & PAHW_MCD) ? ".brm" : ".srm"); + strcpy(ext, (PicoIn.AHW & PAHW_MCD) && Pico.romsize == 0 ? ".brm" : ".srm"); romfname_ext(saveFname, sizeof(static_buff), - (PicoIn.AHW & PAHW_MCD) ? "brm"PATH_SEP : "srm"PATH_SEP, ext); + (PicoIn.AHW & PAHW_MCD) && Pico.romsize == 0 ? "brm"PATH_SEP : "srm"PATH_SEP, ext); if (!load) return saveFname; @@ -944,7 +944,7 @@ int emu_save_load_game(int load, int sram) int sram_size; unsigned char *sram_data; int truncate = 1; - if (PicoIn.AHW & PAHW_MCD) + if ((PicoIn.AHW & PAHW_MCD) && Pico.romsize == 0) { if (PicoIn.opt & POPT_EN_MCD_RAMCART) { sram_size = 0x12000; @@ -971,7 +971,7 @@ int emu_save_load_game(int load, int sram) ret = fread(sram_data, 1, sram_size, sramFile); ret = ret > 0 ? 0 : -1; fclose(sramFile); - if ((PicoIn.AHW & PAHW_MCD) && (PicoIn.opt&POPT_EN_MCD_RAMCART)) + if ((PicoIn.AHW & PAHW_MCD) && Pico.romsize == 0 && (PicoIn.opt&POPT_EN_MCD_RAMCART)) memcpy(Pico_mcd->bram, sram_data, 0x2000); } else { // sram save needs some special processing diff --git a/platform/libretro/libretro.c b/platform/libretro/libretro.c index dd30ad13..82e72451 100644 --- a/platform/libretro/libretro.c +++ b/platform/libretro/libretro.c @@ -1680,7 +1680,7 @@ void *retro_get_memory_data(unsigned type) { case RETRO_MEMORY_SAVE_RAM: /* Note: MCD RAM cart uses Pico.sv.data */ - if ((PicoIn.AHW & PAHW_MCD) && + if ((PicoIn.AHW & PAHW_MCD) && Pico.romsize == 0 && !(PicoIn.opt & POPT_EN_MCD_RAMCART)) data = Pico_mcd->bram; else @@ -1716,7 +1716,7 @@ size_t retro_get_memory_size(unsigned type) case RETRO_MEMORY_SAVE_RAM: if (PicoIn.AHW & PAHW_MCD) { - if (PicoIn.opt & POPT_EN_MCD_RAMCART) + if (Pico.romsize == 0 && PicoIn.opt & POPT_EN_MCD_RAMCART) return 0x12000; else /* bram */ return 0x2000; -- 2.39.5