[libretro] fixed available system RAM size for SG-1000 games with extra on-board RAM

This commit is contained in:
ekeeke 2023-03-11 14:23:31 +01:00
parent 15b962ef9e
commit cc60ba57bf
4 changed files with 58 additions and 32 deletions

Binary file not shown.

View File

@ -2,7 +2,7 @@
* Genesis Plus
* SG-1000, Master System & Game Gear cartridge hardware support
*
* Copyright (C) 2007-2022 Eke-Eke (Genesis Plus GX)
* Copyright (C) 2007-2023 Eke-Eke (Genesis Plus GX)
*
* Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met:
@ -737,6 +737,24 @@ void sms_cart_switch(uint8 mode)
}
}
int sms_cart_ram_size(void)
{
if ((cart_rom.mapper == MAPPER_RAM_8K) || (cart_rom.mapper == MAPPER_RAM_8K_EXT1))
{
/* 8KB on-board RAM */
return 0x2000;
}
if (cart_rom.mapper == MAPPER_RAM_2K)
{
/* 2KB on-board RAM */
return 0x800;
}
/* no on-board RAM by default */
return 0;
}
int sms_cart_region_detect(void)
{
int i = sizeof(game_list) / sizeof(rominfo_t) - 1;

View File

@ -2,7 +2,7 @@
* Genesis Plus
* SG-1000, Master System & Game Gear cartridge hardware support
*
* Copyright (C) 2007-2022 Eke-Eke (Genesis Plus GX)
* Copyright (C) 2007-2023 Eke-Eke (Genesis Plus GX)
*
* Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met:
@ -47,6 +47,7 @@
extern void sms_cart_init(void);
extern void sms_cart_reset(void);
extern void sms_cart_switch(uint8 mode);
extern int sms_cart_ram_size(void);
extern int sms_cart_region_detect(void);
extern int sms_cart_context_save(uint8 *state);
extern int sms_cart_context_load(uint8 *state);

View File

@ -3402,39 +3402,46 @@ size_t retro_get_memory_size(unsigned id)
{
case RETRO_MEMORY_SAVE_RAM:
{
if (!sram.on)
return 0;
/* return 0 if SRAM is disabled */
if (!sram.on)
return 0;
/* if emulation is not running, we assume the frontend is requesting SRAM size for loading */
if (!is_running)
{
/* max supported size is returned */
return 0x10000;
}
/* otherwise, we assume this is for saving and we need to check if SRAM data has been modified */
/* this is obviously not %100 safe since the frontend could still be trying to load SRAM while emulation is running */
/* a better solution would be that the frontend itself checks if data has been modified before writing it to a file */
for (i=0xffff; i>=0; i--)
{
if (sram.sram[i] != 0xff)
{
/* only save modified size */
return (i+1);
}
}
}
case RETRO_MEMORY_SYSTEM_RAM:
if (system_hw == SYSTEM_SG)
return 0x00400;
else if (system_hw == SYSTEM_SGII)
return 0x00800;
else if (system_hw == SYSTEM_SGII_RAM_EXT || system_hw == SYSTEM_SMS || system_hw == SYSTEM_SMS2 || system_hw == SYSTEM_GG || system_hw == SYSTEM_GGMS || system_hw == SYSTEM_PBC)
return 0x02000;
else
/* if emulation is not running, we assume the frontend is requesting SRAM size for loading so max supported size is returned */
if (!is_running)
return 0x10000;
default:
/* otherwise, we assume this is for saving and we return the size of SRAM data that has actually been modified */
/* this is obviously not %100 safe since the frontend could still be trying to load SRAM while emulation is running */
/* a better solution would be that the frontend itself checks if data has been modified before writing it to a file */
for (i=0xffff; i>=0; i--)
if (sram.sram[i] != 0xff)
return (i+1);
/* return 0 if SRAM is not modified */
return 0;
}
case RETRO_MEMORY_SYSTEM_RAM:
{
/* 16-bit hardware */
if ((system_hw & SYSTEM_PBC) == SYSTEM_MD)
return 0x10000; /* 64KB internal RAM */
/* get 8-bit cartrige on-board RAM size */
i = sms_cart_ram_size();
if (i > 0)
return i + 0x2000; /* on-board RAM size + max 8KB internal RAM */
else if (system_hw == SYSTEM_SGII)
return 0x0800; /* 2KB internal RAM */
else if (system_hw == SYSTEM_SG)
return 0x0400; /* 1KB internal RAM */
else
return 0x2000; /* 8KB internal RAM */
}
default:
return 0;
}
}