Merge pull request #171 from malikolivier/support-memcard2
authorTwinaphex <libretro@gmail.com>
Thu, 23 Aug 2018 10:01:47 +0000 (12:01 +0200)
committerGitHub <noreply@github.com>
Thu, 23 Aug 2018 10:01:47 +0000 (12:01 +0200)
Support memcard2

1  2 
frontend/libretro.c

@@@ -1807,12 -1638,44 +1808,47 @@@ static void check_system_specs(void
     environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level);
  }
  
+ static int init_memcards(void)
+ {
+       int ret = 0;
+       const char *dir;
+       struct retro_variable var = { .key="pcsx_rearmed_memcard2", .value=NULL };
+       static const char CARD2_FILE[] = "pcsx-card2.mcd";
+       McdDisable[0] = 0;
+       // Disable memcard 2 by default
+       McdDisable[1] = 1;
+       init_memcard(Mcd1Data);
+       // Memcard 2 is managed by the emulator on the filesystem,
+       // There is no need to initialize Mcd2Data like Mcd1Data.
+       if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
+               SysPrintf("Memcard 2: %s\n", var.value);
+               if (memcmp(var.value, "enabled", 7) == 0) {
+                       if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &dir) && dir) {
+                               if (strlen(dir) + strlen(CARD2_FILE) + 2 > sizeof(Config.Mcd2)) {
+                                       SysPrintf("Path '%s' is too long. Cannot use memcard 2. Use a shorter path.\n", dir);
+                                       ret = -1;
+                               } else {
+                                       McdDisable[1] = 0;
+                                       snprintf(Config.Mcd2, sizeof(Config.Mcd2), "%s/%s", dir, CARD2_FILE);
+                                       SysPrintf("Use memcard 2: %s\n", Config.Mcd2);
+                               }
+                       } else {
+                               SysPrintf("Could not get save directory! Could not create memcard 2.");
+                               ret = -1;
+                       }
+               }
+       }
+       return ret;
+ }
  void retro_init(void)
  {
 -      const char *bios[] = { "SCPH101", "SCPH7001", "SCPH5501", "SCPH1001" };
 +      const char *bios[] = {
 +              "SCPH101", "SCPH7001", "SCPH5501", "SCPH1001",
 +              "scph101", "scph7001", "scph5501", "scph1001"
 +      };
        const char *dir;
        char path[256];
        int i, ret;