summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStelios Tsampas <loathingkernel@gmail.com>2017-07-30 13:57:47 +0300
committerStelios Tsampas <loathingkernel@gmail.com>2017-07-30 17:18:07 +0300
commitdcf718bdd96c3bbe27e18200f6384cd43c95c111 (patch)
tree140b77d9d9e4dd940d85daf080cdc944f14984dd
parentb117a70fd03d780b5817c635d5c337c6ecc36d94 (diff)
* Revert parts of the per game memory card patch.
The previous implementation was doing file paths manipulation deep inside sio.c, and it was hardcoding windows style paths. This was breaking on linux in more than one ways and it is incompatible with the dynamic apppath handling from codeplex branch. Moreover, SaveMcd and LoadMcd functions already take memory card file paths as arguments, making any such logic redundant. This patch rewrites the global Config.Mcd# variables during game startup, which makes it more compatible across all platforms. It also has the added benefit that it doesn't update the configuration file with the each game's memory cards, i.e. at PCSXR startup the default memory cards will be loaded.
-rwxr-xr-xgui/Linux.h1
-rwxr-xr-xgui/LnxMain.c1
-rwxr-xr-xgui/MemcardDlg.c13
-rwxr-xr-xlibpcsxcore/misc.c31
-rwxr-xr-xlibpcsxcore/plugins.c14
-rwxr-xr-xlibpcsxcore/plugins.h2
-rwxr-xr-xlibpcsxcore/psxbios.c14
-rwxr-xr-xlibpcsxcore/psxmem.c13
-rwxr-xr-xlibpcsxcore/sio.c53
-rwxr-xr-xlibpcsxcore/sio.h2
10 files changed, 84 insertions, 60 deletions
diff --git a/gui/Linux.h b/gui/Linux.h
index db70a2a9..2a939050 100755
--- a/gui/Linux.h
+++ b/gui/Linux.h
@@ -29,6 +29,7 @@
#define DEFAULT_MEM_CARD_1 "/.pcsxr/memcards/card1.mcd"
#define DEFAULT_MEM_CARD_2 "/.pcsxr/memcards/card2.mcd"
#define MEMCARD_DIR "/.pcsxr/memcards/"
+#define MEMCARD_PERGAME_DIR "/.pcsxr/memcards/games"
#define PLUGINS_DIR "/.pcsxr/plugins/"
#define PLUGINS_CFG_DIR "/.pcsxr/plugins/cfg/"
#define PCSXR_DOT_DIR "/.pcsxr/"
diff --git a/gui/LnxMain.c b/gui/LnxMain.c
index a7f934ae..d6dd9316 100755
--- a/gui/LnxMain.c
+++ b/gui/LnxMain.c
@@ -83,6 +83,7 @@ static void CheckSubDir() {
CreateHomeConfigDir(BIOS_DIR);
CreateHomeConfigDir(MEMCARD_DIR);
+ CreateHomeConfigDir(MEMCARD_PERGAME_DIR);
CreateHomeConfigDir(STATES_DIR);
CreateHomeConfigDir(PLUGINS_DIR);
CreateHomeConfigDir(PLUGINS_CFG_DIR);
diff --git a/gui/MemcardDlg.c b/gui/MemcardDlg.c
index d3949565..666a21e0 100755
--- a/gui/MemcardDlg.c
+++ b/gui/MemcardDlg.c
@@ -443,7 +443,7 @@ static int GetFreeMemcardSlot(gint target_card, gint count, u8* blocks) {
return -1;
}
-void CopyMemcardData(gint dstmcd, char *from, char *to, gint srci, gint dsti,
+void CopyMemcardData(char *from, char *to, gint srci, gint dsti,
gchar *str, const u16 linkindex) {
u16* linkptr;
u8* checksumptr;
@@ -465,11 +465,11 @@ void CopyMemcardData(gint dstmcd, char *from, char *to, gint srci, gint dsti,
//printf("link = %i %i\n", dsti, linkindex);
}
- SaveMcd(dstmcd, (char *)str, to, dsti * 128, 128);
+ SaveMcd((char *)str, to, dsti * 128, 128);
// data
memcpy(to + dsti * 1024 * 8, from + srci * 1024 * 8, 1024 * 8);
- SaveMcd(dstmcd, (char *)str, to, dsti * 1024 * 8, 1024 * 8);
+ SaveMcd((char *)str, to, dsti * 1024 * 8, 1024 * 8);
//printf("data = %s\n", from + (srci+1) * 128);
}
@@ -550,7 +550,7 @@ static void OnMcd_CopyTo(GtkWidget *widget, gpointer user_data) {
for (j=0; srctbl[j] > 0; j++) {
// last parameter specifies link index (next block)
- CopyMemcardData(dstmcd, source, destination,
+ CopyMemcardData(source, destination,
srctbl[j], dsttbl[j], str, dsttbl[j+1]-1);
//printf("count = %i, indices=(%x,%x) jindex=%i\n", count, srctbl[j], dsttbl[j], j);
}
@@ -622,7 +622,7 @@ static void OnMemcardDelete(GtkWidget *widget, gpointer user_data) {
}
*ptr = xorsum;
- SaveMcd(memcard, (char *)filename, data, i * 128, 128);
+ SaveMcd((char *)filename, data, i * 128, 128);
// Check links
i = GETLINKFORBLOCK(data, i); //0...15 index when ++i at top of loop
@@ -753,9 +753,6 @@ void OnConf_Mcds() {
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
gtk_builder_get_object(builder, "GtkCheckButton_PerGameMcd")), Config.PerGameMcd);
- // Disable it because it is not working yet
- gtk_widget_set_sensitive(GTK_WIDGET(
- gtk_builder_get_object(builder, "GtkCheckButton_PerGameMcd")), FALSE);
LoadMcdDlg(dialog);
diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c
index f54abeb6..d8a7805c 100755
--- a/libpcsxcore/misc.c
+++ b/libpcsxcore/misc.c
@@ -356,13 +356,9 @@ int CheckCdrom() {
else Config.PsxType = PSX_TYPE_NTSC; // ntsc
}
-
- if (Config.OverClock == 0)
- {
+ if (Config.OverClock == 0) {
PsxClockSpeed = 33868800; // 33.8688 MHz (stock)
- }
- else
- {
+ } else {
PsxClockSpeed = 33868800 * Config.PsxClock;
}
@@ -376,9 +372,22 @@ int CheckCdrom() {
memset(Config.PsxExeName, 0, sizeof(Config.PsxExeName));
strncpy(Config.PsxExeName, exename, 11);
- if(Config.PerGameMcd)
- LoadMcds(Config.Mcd1, Config.Mcd2);
-
+ if(Config.PerGameMcd) {
+ char mcd1path[MAXPATHLEN] = { '\0' };
+ char mcd2path[MAXPATHLEN] = { '\0' };
+#ifdef _WINDOWS
+ sprintf(mcd1path, "memcards\\games\\%s-%02d.mcd", Config.PsxExeName, 1);
+ sprintf(mcd2path, "memcards\\games\\%s-%02d.mcd", Config.PsxExeName, 2);
+#else
+ //lk: dot paths should not be hardcoded here, this is for testing only
+ sprintf(mcd1path, "%s/.pcsxr/memcards/games/%s-%02d.mcd", getenv("HOME"), Config.PsxExeName, 1);
+ sprintf(mcd2path, "%s/.pcsxr/memcards/games/%s-%02d.mcd", getenv("HOME"), Config.PsxExeName, 2);
+#endif
+ strcpy(Config.Mcd1, mcd1path);
+ strcpy(Config.Mcd2, mcd2path);
+ LoadMcds(Config.Mcd1, Config.Mcd2);
+ }
+
BuildPPFCache();
LoadSBI(NULL);
@@ -612,7 +621,7 @@ int SaveStateMem(const u32 id) {
char name[32];
int ret = -1;
- snprintf(name, 32, SHM_SS_NAME_TEMPLATE, id);
+ snprintf(name, sizeof(name), SHM_SS_NAME_TEMPLATE, id);
int fd = shm_open(name, O_CREAT | O_RDWR | O_TRUNC, 0666);
if (fd >= 0) {
@@ -635,7 +644,7 @@ int LoadStateMem(const u32 id) {
char name[32];
int ret = -1;
- snprintf(name, 32, SHM_SS_NAME_TEMPLATE, id);
+ snprintf(name, sizeof(name), SHM_SS_NAME_TEMPLATE, id);
int fd = shm_open(name, O_RDONLY, 0444);
if (fd >= 0) {
diff --git a/libpcsxcore/plugins.c b/libpcsxcore/plugins.c
index 567630c8..c4fdae68 100755
--- a/libpcsxcore/plugins.c
+++ b/libpcsxcore/plugins.c
@@ -25,6 +25,7 @@
#include "cdriso.h"
static char IsoFile[MAXPATHLEN] = "";
+static char AppPath[MAXPATHLEN] = ""; //Application path(== pcsxr.exe directory)
static s64 cdOpenCaseTime = 0;
GPUupdateLace GPU_updateLace;
@@ -845,10 +846,23 @@ void SetIsoFile(const char *filename) {
strncpy(IsoFile, filename, MAXPATHLEN);
}
+// Set pcsxr.exe directory. This is not contain filename(and ext)).
+void SetAppPath(const char *apppath ) {
+ if (apppath == NULL) {
+ AppPath[0] = '\0';
+ return;
+ }
+ strncpy(AppPath, apppath, MAXPATHLEN);
+}
+
const char *GetIsoFile(void) {
return IsoFile;
}
+const char *GetAppPath(void) {
+ return AppPath;
+}
+
boolean UsingIso(void) {
return (IsoFile[0] != '\0' || Config.Cdr[0] == '\0');
}
diff --git a/libpcsxcore/plugins.h b/libpcsxcore/plugins.h
index b7ba4cd3..982d0978 100755
--- a/libpcsxcore/plugins.h
+++ b/libpcsxcore/plugins.h
@@ -422,7 +422,9 @@ extern SIO1registerCallback SIO1_registerCallback;
void CALLBACK clearDynarec(void);
void SetIsoFile(const char *filename);
+void SetAppPath(const char *filename);
const char *GetIsoFile(void);
+const char *GetAppPath(void);
boolean UsingIso(void);
void SetCdOpenCaseTime(s64 time);
diff --git a/libpcsxcore/psxbios.c b/libpcsxcore/psxbios.c
index 1249f596..61f9a463 100755
--- a/libpcsxcore/psxbios.c
+++ b/libpcsxcore/psxbios.c
@@ -1744,7 +1744,7 @@ static void buopen(int mcd, u8 *ptr, u8 *cfg)
SysPrintf("openC %s %d\n", ptr, nblk);
v0 = 1 + mcd;
/* just go ahead and resave them all */
- SaveMcd(mcd, cfg, ptr, 128, 128 * 15);
+ SaveMcd(cfg, ptr, 128, 128 * 15);
break;
}
/* shouldn't this return ENOSPC if i == 16? */
@@ -1839,7 +1839,7 @@ void psxBios_read() { // 0x34
ptr = Mcd##mcd##Data + offset; \
memcpy(ptr, Ra1, a2); \
FDesc[1 + mcd].offset += a2; \
- SaveMcd(mcd, Config.Mcd##mcd, Mcd##mcd##Data, offset, a2); \
+ SaveMcd(Config.Mcd##mcd, Mcd##mcd##Data, offset, a2); \
if (FDesc[1 + mcd].mode & 0x8000) v0 = 0; \
else v0 = a2; \
DeliverEvent(0x11, 0x2); /* 0xf0000011, 0x0004 */ \
@@ -1936,7 +1936,7 @@ int nfile;
ptr+= 0xa; \
if (pfile[0] == 0) { \
strncpy(dir->name, ptr, sizeof(dir->name)); \
- dir->name[sizeof(dir->name)] = '\0'; \
+ dir->name[sizeof(dir->name) - 1] = '\0'; \
} else for (i=0; i<20; i++) { \
if (pfile[i] == ptr[i]) { \
dir->name[i] = ptr[i]; continue; } \
@@ -2023,7 +2023,7 @@ void psxBios_nextfile() { // 43
memset(ptr+0xa+namelen, 0, 0x75-namelen); \
for (j=0; j<127; j++) xor^= ptr[j]; \
ptr[127] = xor; \
- SaveMcd(mcd, Config.Mcd##mcd, Mcd##mcd##Data, 128 * i + 0xa, 0x76); \
+ SaveMcd(Config.Mcd##mcd, Mcd##mcd##Data, 128 * i + 0xa, 0x76); \
v0 = 1; \
break; \
} \
@@ -2061,7 +2061,7 @@ void psxBios_rename() { // 44
if ((*ptr & 0xF0) != 0x50) continue; \
if (strcmp(Ra0+5, ptr+0xa)) continue; \
*ptr = (*ptr & 0xf) | 0xA0; \
- SaveMcd(mcd, Config.Mcd##mcd, Mcd##mcd##Data, 128 * i, 1); \
+ SaveMcd(Config.Mcd##mcd, Mcd##mcd##Data, 128 * i, 1); \
SysPrintf("delete %s\n", ptr+0xa); \
v0 = 1; \
break; \
@@ -2135,10 +2135,10 @@ void psxBios__card_write() { // 0x4e
if (port == 0) {
memcpy(Mcd1Data + (sect * MCD_SECT_SIZE), Ra2, MCD_SECT_SIZE);
- SaveMcd(1, Config.Mcd1, Mcd1Data, sect * MCD_SECT_SIZE, MCD_SECT_SIZE);
+ SaveMcd(Config.Mcd1, Mcd1Data, sect * MCD_SECT_SIZE, MCD_SECT_SIZE);
} else {
memcpy(Mcd2Data + (sect * MCD_SECT_SIZE), Ra2, MCD_SECT_SIZE);
- SaveMcd(2, Config.Mcd2, Mcd2Data, sect * MCD_SECT_SIZE, MCD_SECT_SIZE);
+ SaveMcd(Config.Mcd2, Mcd2Data, sect * MCD_SECT_SIZE, MCD_SECT_SIZE);
}
DeliverEvent(0x11, 0x2); // 0xf0000011, 0x0004
diff --git a/libpcsxcore/psxmem.c b/libpcsxcore/psxmem.c
index bc2a0ca0..ae2600ab 100755
--- a/libpcsxcore/psxmem.c
+++ b/libpcsxcore/psxmem.c
@@ -107,16 +107,22 @@ int psxMemInit() {
void psxMemReset() {
FILE *f = NULL;
- char bios[1024];
+ char bios[1024] = { '\0' };
memset(psxM, 0, 0x00200000);
memset(psxP, 0, 0x00010000);
// Load BIOS
if (strcmp(Config.Bios, "HLE") != 0) {
- sprintf(bios, "%s/%s", Config.BiosDir, Config.Bios);
- f = fopen(bios, "rb");
+ //AppPath's priority is high.
+ const char* apppath = GetAppPath();
+ if( strlen(apppath) > 0 )
+ strcat( strcat( strcat( bios, GetAppPath() ), "bios\\"), Config.Bios );
+ else
+ sprintf(bios, "%s/%s", Config.BiosDir, Config.Bios);
+
+ f = fopen(bios, "rb");
if (f == NULL) {
SysMessage(_("Could not open BIOS:\"%s\". Enabling HLE Bios!\n"), bios);
memset(psxR, 0, 0x80000);
@@ -125,6 +131,7 @@ void psxMemReset() {
fread(psxR, 1, 0x80000, f);
fclose(f);
Config.HLE = FALSE;
+ SysPrintf(_("Loaded BIOS: %s\n"), bios );
}
} else Config.HLE = TRUE;
}
diff --git a/libpcsxcore/sio.c b/libpcsxcore/sio.c
index dfa79bb1..76742352 100755
--- a/libpcsxcore/sio.c
+++ b/libpcsxcore/sio.c
@@ -801,11 +801,11 @@ unsigned char sioRead8() {
switch (CtrlReg & 0x2002) {
case 0x0002:
memcpy(Mcd1Data + (adrL | (adrH << 8)) * 128, &buf[1], 128);
- SaveMcd(1, Config.Mcd1, Mcd1Data, (adrL | (adrH << 8)) * 128, 128);
+ SaveMcd(Config.Mcd1, Mcd1Data, (adrL | (adrH << 8)) * 128, 128);
break;
case 0x2002:
memcpy(Mcd2Data + (adrL | (adrH << 8)) * 128, &buf[1], 128);
- SaveMcd(2, Config.Mcd2, Mcd2Data, (adrL | (adrH << 8)) * 128, 128);
+ SaveMcd(Config.Mcd2, Mcd2Data, (adrL | (adrH << 8)) * 128, 128);
break;
}
}
@@ -884,29 +884,30 @@ void sioInterrupt() {
void LoadMcd(int mcd, char *str) {
FILE *f;
char *data = NULL;
- char Mcd[MAXPATHLEN];
+ char filepath[MAXPATHLEN] = { '\0' };
+ const char *apppath = GetAppPath();
if (mcd == 1) data = Mcd1Data;
if (mcd == 2) data = Mcd2Data;
- if (Config.PerGameMcd && mcd && strlen(Config.PsxExeName))
- sprintf(Mcd, "memcards\\games\\%s-%02d.mcr", Config.PsxExeName, mcd-1);
- else
- strcpy(Mcd, str);
-
- if (*Mcd == 0) {
+ if (*str == 0) {
SysPrintf(_("No memory card value was specified - card %i is not plugged.\n"), mcd);
return;
}
- f = fopen(Mcd, "rb");
+
+ //Getting full application path.
+ memmove(filepath, apppath, strlen(apppath));
+ strcat(filepath, str);
+
+ f = fopen(filepath, "rb");
if (f == NULL) {
- SysPrintf(_("The memory card %s doesn't exist - creating it\n"), Mcd);
- CreateMcd(Mcd);
- f = fopen(Mcd, "rb");
+ SysPrintf(_("The memory card %s doesn't exist - creating it\n"), filepath);
+ CreateMcd(filepath);
+ f = fopen(filepath, "rb");
if (f != NULL) {
struct stat buf;
- if (stat(Mcd, &buf) != -1) {
+ if (stat(filepath, &buf) != -1) {
if (buf.st_size == MCD_SIZE + 64)
fseek(f, 64, SEEK_SET);
else if(buf.st_size == MCD_SIZE + 3904)
@@ -916,12 +917,12 @@ void LoadMcd(int mcd, char *str) {
fclose(f);
}
else
- SysMessage(_("Memory card %s failed to load!\n"), Mcd);
+ SysMessage(_("Memory card %s failed to load!\n"), filepath);
}
else {
struct stat buf;
- SysPrintf(_("Loading memory card %s\n"), Mcd);
- if (stat(Mcd, &buf) != -1) {
+ SysPrintf(_("Loading memory card %s\n"), filepath);
+ if (stat(filepath, &buf) != -1) {
if (buf.st_size == MCD_SIZE + 64)
fseek(f, 64, SEEK_SET);
else if(buf.st_size == MCD_SIZE + 3904)
@@ -940,20 +941,14 @@ void LoadMcds(char *mcd1, char *mcd2) {
LoadMcd(2, mcd2);
}
-void SaveMcd(int mcd, char *str, char *data, uint32_t adr, int size) {
+void SaveMcd(char *mcd, char *data, uint32_t adr, int size) {
FILE *f;
- char Mcd[MAXPATHLEN];
- if (Config.PerGameMcd && mcd && strlen(Config.PsxExeName))
- sprintf(Mcd, "memcards\\games\\%s-%02d.mcr", Config.PsxExeName, mcd-1);
- else
- strcpy(Mcd, str);
-
- f = fopen(Mcd, "r+b");
+ f = fopen(mcd, "r+b");
if (f != NULL) {
struct stat buf;
- if (stat(Mcd, &buf) != -1) {
+ if (stat(mcd, &buf) != -1) {
if (buf.st_size == MCD_SIZE + 64)
fseek(f, adr + 64, SEEK_SET);
else if (buf.st_size == MCD_SIZE + 3904)
@@ -965,9 +960,7 @@ void SaveMcd(int mcd, char *str, char *data, uint32_t adr, int size) {
fwrite(data + adr, 1, size, f);
fclose(f);
-
- SysPrintf(_("Saving memory card %s\n"), Mcd);
-
+ SysPrintf(_("Saving memory card %s\n"), mcd);
return;
}
@@ -980,7 +973,7 @@ void SaveMcd(int mcd, char *str, char *data, uint32_t adr, int size) {
}
#endif
- ConvertMcd(str, data);
+ ConvertMcd(mcd, data);
}
void CreateMcd(char *mcd) {
diff --git a/libpcsxcore/sio.h b/libpcsxcore/sio.h
index b3897552..64993992 100755
--- a/libpcsxcore/sio.h
+++ b/libpcsxcore/sio.h
@@ -55,7 +55,7 @@ int sioFreeze(gzFile f, int Mode);
void LoadMcd(int mcd, char *str);
void LoadMcds(char *mcd1, char *mcd2);
-void SaveMcd(int mcd, char *str, char *data, uint32_t adr, int size);
+void SaveMcd(char *mcd, char *data, uint32_t adr, int size);
void CreateMcd(char *mcd);
void ConvertMcd(char *mcd, char *data);