Skip to content

Commit

Permalink
Merge pull request #327 from ichee/master
Browse files Browse the repository at this point in the history
Sega/Mega CD Add Configurable Backup Ram Cart size
  • Loading branch information
LibretroAdmin authored Apr 2, 2023
2 parents a9448d8 + 02c30b1 commit 3c7a0c4
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 33 deletions.
2 changes: 1 addition & 1 deletion core/cd_hw/cd_cart.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void cd_cart_init(void)
else
{
/* enable 512K backup RAM cartridge when booting from CD (Mode 2) */
scd.cartridge.id = 6;
scd.cartridge.id = cart_size;
}

/* RAM cartridge enabled ? */
Expand Down
1 change: 1 addition & 0 deletions core/genesis.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ extern uint8 zram[0x2000];
extern uint32 zbank;
extern uint8 zstate;
extern uint8 pico_current;
extern uint8_t cart_size;

/* Function prototypes */
extern void gen_init(void);
Expand Down
147 changes: 117 additions & 30 deletions libretro/libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ static uint8_t brm_format[0x40] =
0x53,0x45,0x47,0x41,0x5f,0x43,0x44,0x5f,0x52,0x4f,0x4d,0x00,0x01,0x00,0x00,0x00,
0x52,0x41,0x4d,0x5f,0x43,0x41,0x52,0x54,0x52,0x49,0x44,0x47,0x45,0x5f,0x5f,0x5f
};
uint8_t cart_size;

static bool is_running = 0;
static uint8_t temp[0x10000];
Expand Down Expand Up @@ -1327,42 +1328,128 @@ static void check_variables(bool first_run)
bool update_frameskip = false;
struct retro_variable var = {0};

var.key = "genesis_plus_gx_system_bram";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
if (first_run)
{
if (!var.value || !strcmp(var.value, "per bios"))
{
fill_pathname_join(CD_BRAM_EU, save_dir, "scd_E.brm", sizeof(CD_BRAM_EU));
fill_pathname_join(CD_BRAM_US, save_dir, "scd_U.brm", sizeof(CD_BRAM_US));
fill_pathname_join(CD_BRAM_JP, save_dir, "scd_J.brm", sizeof(CD_BRAM_JP));
}
else
{
char newpath[4096];
fill_pathname_join(newpath, save_dir, g_rom_name, sizeof(newpath));
strlcat(newpath, ".brm", sizeof(newpath));
strlcpy(CD_BRAM_EU, newpath, sizeof(CD_BRAM_EU));
strlcpy(CD_BRAM_US, newpath, sizeof(CD_BRAM_US));
strlcpy(CD_BRAM_JP, newpath, sizeof(CD_BRAM_JP));
}
var.key = "genesis_plus_gx_system_bram";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{
if (!var.value || !strcmp(var.value, "per bios"))
{
fill_pathname_join(CD_BRAM_EU, save_dir, "scd_E.brm", sizeof(CD_BRAM_EU));
fill_pathname_join(CD_BRAM_US, save_dir, "scd_U.brm", sizeof(CD_BRAM_US));
fill_pathname_join(CD_BRAM_JP, save_dir, "scd_J.brm", sizeof(CD_BRAM_JP));
}
else
{
char newpath[4096];
fill_pathname_join(newpath, save_dir, g_rom_name, sizeof(newpath));
strlcat(newpath, ".brm", sizeof(newpath));
strlcpy(CD_BRAM_EU, newpath, sizeof(CD_BRAM_EU));
strlcpy(CD_BRAM_US, newpath, sizeof(CD_BRAM_US));
strlcpy(CD_BRAM_JP, newpath, sizeof(CD_BRAM_JP));
}
}
}

var.key = "genesis_plus_gx_cart_bram";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
if (first_run)
{
if (!var.value || !strcmp(var.value, "per cart"))
{
fill_pathname_join(CART_BRAM, save_dir, "cart.brm", sizeof(CART_BRAM));
}
else
{
char newpath[4096];
fill_pathname_join(newpath, save_dir, g_rom_name, sizeof(newpath));
strlcat(newpath, "_cart.brm", sizeof(newpath));
strlcpy(CART_BRAM, newpath, sizeof(CART_BRAM));
}
var.key = "genesis_plus_gx_cart_size";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{
if (var.value && !strcmp(var.value, "disabled"))
cart_size = 0;
else if (var.value && !strcmp(var.value, "128k"))
cart_size = 1;
else if (var.value && !strcmp(var.value, "256k"))
cart_size = 2;
else if (var.value && !strcmp(var.value, "512k"))
cart_size = 3;
else if (var.value && !strcmp(var.value, "1meg"))
cart_size = 4;
else if (var.value && !strcmp(var.value, "2meg"))
cart_size = 5;
else if (var.value && !strcmp(var.value, "4meg"))
cart_size = 6;
}
}

if (first_run)
{
var.key = "genesis_plus_gx_cart_bram";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{
if ((!var.value || !strcmp(var.value, "per cart")) && cart_size == 1)
{
fill_pathname_join(CART_BRAM, save_dir, "128Kbit_cart.brm", sizeof(CART_BRAM));
}
else if ((!var.value || !strcmp(var.value, "per cart")) && cart_size == 2)
{
fill_pathname_join(CART_BRAM, save_dir, "256Kbit_cart.brm", sizeof(CART_BRAM));
}
else if ((!var.value || !strcmp(var.value, "per cart")) && cart_size == 3)
{
fill_pathname_join(CART_BRAM, save_dir, "512Kbit_cart.brm", sizeof(CART_BRAM));
}
else if ((!var.value || !strcmp(var.value, "per cart")) && cart_size == 4)
{
fill_pathname_join(CART_BRAM, save_dir, "1Mbit_cart.brm", sizeof(CART_BRAM));
}
else if ((!var.value || !strcmp(var.value, "per cart")) && cart_size == 5)
{
fill_pathname_join(CART_BRAM, save_dir, "2Mbit_cart.brm", sizeof(CART_BRAM));
}
else if ((!var.value || !strcmp(var.value, "per cart")) && cart_size == 6)
{
fill_pathname_join(CART_BRAM, save_dir, "4Mbit_cart.brm", sizeof(CART_BRAM));
}
else
{
if (cart_size == 1)
{
char newpath[4096];
fill_pathname_join(newpath, save_dir, g_rom_name, sizeof(newpath));
strlcat(newpath, "_128Kbit_cart.brm", sizeof(newpath));
strlcpy(CART_BRAM, newpath, sizeof(CART_BRAM));
}
else if (cart_size == 2)
{
char newpath[4096];
fill_pathname_join(newpath, save_dir, g_rom_name, sizeof(newpath));
strlcat(newpath, "_256Kbit_cart.brm", sizeof(newpath));
strlcpy(CART_BRAM, newpath, sizeof(CART_BRAM));
}
else if (cart_size == 3)
{
char newpath[4096];
fill_pathname_join(newpath, save_dir, g_rom_name, sizeof(newpath));
strlcat(newpath, "_512Kbit_cart.brm", sizeof(newpath));
strlcpy(CART_BRAM, newpath, sizeof(CART_BRAM));
}
else if (cart_size == 4)
{
char newpath[4096];
fill_pathname_join(newpath, save_dir, g_rom_name, sizeof(newpath));
strlcat(newpath, "_1Mbit_cart.brm", sizeof(newpath));
strlcpy(CART_BRAM, newpath, sizeof(CART_BRAM));
}
else if (cart_size == 5)
{
char newpath[4096];
fill_pathname_join(newpath, save_dir, g_rom_name, sizeof(newpath));
strlcat(newpath, "_2Mbit_cart.brm", sizeof(newpath));
strlcpy(CART_BRAM, newpath, sizeof(CART_BRAM));
}
else if (cart_size == 6)
{
char newpath[4096];
fill_pathname_join(newpath, save_dir, g_rom_name, sizeof(newpath));
strlcat(newpath, "_4Mbit_cart.brm", sizeof(newpath));
strlcpy(CART_BRAM, newpath, sizeof(CART_BRAM));
}
}
}
}

var.key = "genesis_plus_gx_system_hw";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{
Expand Down
23 changes: 21 additions & 2 deletions libretro/libretro_core_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
},
{
"genesis_plus_gx_system_bram",
"CD System BRAM",
"CD System BRAM (Requires Restart)",
NULL,
"When running Sega CD/Mega-CD content, specifies whether to share a single save file between all games from a specific region (Per-BIOS) or to create a separate save file for each game (Per-Game). Note that the Sega CD/Mega-CD has limited internal storage, sufficient only for a handful of titles. To avoid running out of space, the 'Per-Game' setting is recommended.",
NULL,
Expand All @@ -161,7 +161,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
},
{
"genesis_plus_gx_cart_bram",
"CD Backup Cart BRAM",
"CD Backup Cart BRAM (Requires Restart)",
NULL,
"When running Sega CD/Mega-CD content, specifies whether to share a single backup ram cart for all games (Per-Cart) or to create a separate backup ram cart for each game (Per-Game).",
NULL,
Expand All @@ -173,6 +173,25 @@ struct retro_core_option_v2_definition option_defs_us[] = {
},
"per cart"
},
{
"genesis_plus_gx_cart_size",
"CD Backup Cart BRAM Size (Requires Restart)",
NULL,
"Sets the backup ram cart size when running Sega CD/Mega-CD content. Useful when setting the backup ram cart to Per-Game to avoid multiple larger cart sizes.",
NULL,
"system",
{
{ "disabled", "Disabled" },
{ "128k", "128Kbit" },
{ "256k", "256Kbit" },
{ "512k", "512Kbit" },
{ "1meg", "1Mbit" },
{ "2meg", "2Mbit" },
{ "4meg", "4Mbit" },
{ NULL, NULL },
},
"4meg"
},
{
"genesis_plus_gx_add_on",
"CD add-on (MD mode) (Requires Restart)",
Expand Down

0 comments on commit 3c7a0c4

Please sign in to comment.