Skip to content

Commit

Permalink
Merge pull request #6 from jdgleaver/disable-memcard
Browse files Browse the repository at this point in the history
Add option to remove memory cards
  • Loading branch information
jdgleaver committed Jul 14, 2021
2 parents 4a587ad + 2d22674 commit ab17108
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ int LoadPlugins(void) {
/* If we are using per-disk memory cards, defer
* loading until after the disk ID has been determined */
if ((Config.McdSlot1 != 0) && (Config.McdSlot2 != 0)) {
LoadMcd(MCD1, (char*)GetMemcardPath(1)); //Memcard 1
LoadMcd(MCD2, (char*)GetMemcardPath(2)); //Memcard 2
LoadMcd(MCD1, GetMemcardPath(1)); //Memcard 1
LoadMcd(MCD2, GetMemcardPath(2)); //Memcard 2
}

ret = CDR_init();
Expand Down
2 changes: 1 addition & 1 deletion src/plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,6 @@ s64 GetCdOpenCaseTime(void);
int ReloadCdromPlugin();

// Memcard functions
const char *GetMemcardPath(int slot);
char *GetMemcardPath(int slot);

#endif /* __PLUGINS_H__ */
16 changes: 10 additions & 6 deletions src/port/sdl/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1389,12 +1389,12 @@ static int McdSlot1_alter(u32 keys)
int slot = Config.McdSlot1;
if (keys & KEY_RIGHT)
{
if (++slot > 15) slot = 0;
if (++slot > 16) slot = -1;
}
else
if (keys & KEY_LEFT)
{
if (--slot < 0) slot = 15;
if (--slot < -1) slot = 16;
}
Config.McdSlot1 = slot;
update_memcards(1);
Expand All @@ -1404,7 +1404,9 @@ static int McdSlot1_alter(u32 keys)
static char *McdSlot1_show()
{
static char buf[32] = "\0";
if (Config.McdSlot1 == 0) {
if (Config.McdSlot1 == -1) {
strcpy(buf, "empty");
} else if (Config.McdSlot1 == 0) {
if (string_is_empty(CdromId)) {
strcpy(buf, "per-disk");
} else {
Expand All @@ -1421,12 +1423,12 @@ static int McdSlot2_alter(u32 keys)
int slot = Config.McdSlot2;
if (keys & KEY_RIGHT)
{
if (++slot > 16) slot = 0;
if (++slot > 16) slot = -1;
}
else
if (keys & KEY_LEFT)
{
if (--slot < 0) slot = 16;
if (--slot < -1) slot = 16;
}
Config.McdSlot2 = slot;
update_memcards(2);
Expand All @@ -1436,7 +1438,9 @@ static int McdSlot2_alter(u32 keys)
static char *McdSlot2_show()
{
static char buf[32] = "\0";
if (Config.McdSlot2 == 0) {
if (Config.McdSlot2 == -1) {
strcpy(buf, "empty");
} else if (Config.McdSlot2 == 0) {
if (string_is_empty(CdromId)) {
strcpy(buf, "per-disk");
} else {
Expand Down
30 changes: 21 additions & 9 deletions src/port/sdl/port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1132,19 +1132,29 @@ void video_clear_cache()
#endif
}

const char *GetMemcardPath(int slot) {
char *GetMemcardPath(int slot) {
switch(slot) {
case 1:
return McdPath1;
if (Config.McdSlot1 == -1) {
return NULL;
} else {
return McdPath1;
}
case 2:
return McdPath2;
if (Config.McdSlot2 == -1) {
return NULL;
} else {
return McdPath2;
}
}
return NULL;
}

void update_memcards(int load_mcd) {

if (Config.McdSlot1 == 0) {
if (Config.McdSlot1 == -1) {
McdPath1[0] = '\0';
} else if (Config.McdSlot1 == 0) {
if (string_is_empty(CdromId)) {
/* Fallback */
sprintf(McdPath1, "%s/%s", memcardsdir, "card1.mcd");
Expand All @@ -1155,7 +1165,9 @@ void update_memcards(int load_mcd) {
sprintf(McdPath1, "%s/mcd%03d.mcr", memcardsdir, (int)Config.McdSlot1);
}

if (Config.McdSlot2 == 0) {
if (Config.McdSlot2 == -1) {
McdPath2[0] = '\0';
} else if (Config.McdSlot2 == 0) {
if (string_is_empty(CdromId)) {
/* Fallback */
sprintf(McdPath2, "%s/%s", memcardsdir, "card2.mcd");
Expand All @@ -1167,9 +1179,9 @@ void update_memcards(int load_mcd) {
}

if (load_mcd & 1)
LoadMcd(MCD1, McdPath1); //Memcard 1
LoadMcd(MCD1, GetMemcardPath(1)); //Memcard 1
if (load_mcd & 2)
LoadMcd(MCD2, McdPath2); //Memcard 2
LoadMcd(MCD2, GetMemcardPath(2)); //Memcard 2
}

const char *bios_file_get() {
Expand Down Expand Up @@ -2004,8 +2016,8 @@ int main (int argc, char **argv)
* them now */
if ((Config.McdSlot1 == 0) || (Config.McdSlot2 == 0)) {
update_memcards(0);
LoadMcd(MCD1, (char*)GetMemcardPath(1)); //Memcard 1
LoadMcd(MCD2, (char*)GetMemcardPath(2)); //Memcard 2
LoadMcd(MCD1, GetMemcardPath(1)); //Memcard 1
LoadMcd(MCD2, GetMemcardPath(2)); //Memcard 2
}

Rumble_Init();
Expand Down
4 changes: 2 additions & 2 deletions src/psxcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ typedef struct {
boolean VSyncWA; /* 1=InuYasha Sengoku Battle Fix */
u8 Cpu; /* 0=recompiler, 1=interpreter */
u8 PsxType; /* 0=ntsc, 1=pal */
u8 McdSlot1; /* mcd slot 1, 0=CdromId.1.mcr, otherwise mcd%03u.mcr */
u8 McdSlot2; /* mcd slot 2, 0=CdromId.2.mcr, otherwise mcd%03u.mcr */
s8 McdSlot1; /* mcd slot 1, -1=empty, 0=CdromId.1.mcr, otherwise mcd%03u.mcr */
s8 McdSlot2; /* mcd slot 2, -1=empty, 0=CdromId.2.mcr, otherwise mcd%03u.mcr */

/* Gamepad combo used to open menu
* 0: L3 + R3
Expand Down

0 comments on commit ab17108

Please sign in to comment.