diff options
| author | iCatButler <i.am.catbutler@gmail.com> | 2016-04-01 12:14:52 +0100 |
|---|---|---|
| committer | iCatButler <i.am.catbutler@gmail.com> | 2016-04-01 12:14:52 +0100 |
| commit | f84c6902b40b678b2027a95cb4a80bbfb3270f9f (patch) | |
| tree | 3adceaa069f2f66d1a039951fea35d754cf64c67 /libpcsxcore | |
| parent | 3c0cd06addad4e0a957422ee9ecbeb12f24cffac (diff) | |
| parent | f671d256e7c1a3365cf2bbc89270363a17d66a1b (diff) | |
| download | pcsxr-f84c6902b40b678b2027a95cb4a80bbfb3270f9f.tar.gz | |
Merge pull request #1 from tapcio/master
Added my improvements and some fixes
Diffstat (limited to 'libpcsxcore')
| -rwxr-xr-x | libpcsxcore/cdriso.c | 306 | ||||
| -rwxr-xr-x | libpcsxcore/misc.c | 6 | ||||
| -rwxr-xr-x | libpcsxcore/psxbios.c | 12 | ||||
| -rwxr-xr-x | libpcsxcore/psxcommon.h | 3 | ||||
| -rwxr-xr-x | libpcsxcore/psxmem.c | 42 | ||||
| -rwxr-xr-x | libpcsxcore/r3000a.c | 1 | ||||
| -rwxr-xr-x | libpcsxcore/sio.c | 45 | ||||
| -rwxr-xr-x | libpcsxcore/sio.h | 2 |
8 files changed, 226 insertions, 191 deletions
diff --git a/libpcsxcore/cdriso.c b/libpcsxcore/cdriso.c index b7eedea2..af4205cf 100755 --- a/libpcsxcore/cdriso.c +++ b/libpcsxcore/cdriso.c @@ -470,6 +470,161 @@ static int parsetoc(const char *isofile) { return 0; } + +int(*cdimg_read_func_archive)(FILE *f, unsigned int base, void *dest, int sector) = NULL; +#ifdef HAVE_LIBARCHIVE +#include <archive.h> +#include <archive_entry.h> + +struct archive *a = NULL; +u32 len_uncompressed_buffer = 0; +void *cdimage_buffer_mem = NULL; +FILE* cdimage_buffer = NULL; //cdHandle to store file + +int aropen(FILE* fparchive, const char* _fn) { + s32 r; + u64 length = 0, length_peek; + boolean use_temp_file = FALSE; // TODO make a config param + static struct archive_entry *ae = NULL; + struct archive_entry *ae_peek; + + if (a == NULL && cdimage_buffer == NULL) { + // We open file twice. First to peek sizes. This nastyness due used interface. + a = archive_read_new(); + r = archive_read_support_compression_all(a); + r = archive_read_support_format_all(a); + //r = archive_read_support_filter_all(a); + //r = archive_read_support_format_raw(a); + //r = archive_read_open_FILE(a, archive); + archive_read_open_filename(a, _fn, 75 * CD_FRAMESIZE_RAW); + if (r != ARCHIVE_OK) { + SysPrintf("Archive open failed (%i).\n", r); + archive_read_free(a); + a = NULL; + return -1; + } + // Get the biggest file in archive + while ((r = archive_read_next_header(a, &ae_peek)) == ARCHIVE_OK) { + length_peek = archive_entry_size(ae_peek); + //printf("Entry canditate %s %i\n", archive_entry_pathname(ae_peek), length_peek); + length = MAX(length_peek, length); + ae = (ae == NULL ? ae_peek : ae); + } + archive_read_free(a); + if (ae == NULL) { + SysPrintf("Archive entry read failed (%i).\n", r); + a = NULL; + return -1; + } + //Now really open the file + a = archive_read_new(); + r = archive_read_support_compression_all(a); + r = archive_read_support_format_all(a); + archive_read_open_filename(a, _fn, 75 * CD_FRAMESIZE_RAW); + while ((r = archive_read_next_header(a, &ae)) == ARCHIVE_OK) { + length_peek = archive_entry_size(ae); + if (length_peek == length) { + //ae = ae_peek; + SysPrintf(" -- Selected entry %s %i", archive_entry_pathname(ae), length); + break; + } + } + + len_uncompressed_buffer = length ? length : 700 * 1024 * 1024; + } + + if (use_temp_file && (cdimage_buffer == NULL || cdHandle != cdimage_buffer)) { + cdimage_buffer = fopen("/tmp/pcsxr.tmp.bin", "w+b"); + } + else if (!use_temp_file && (cdimage_buffer == NULL || cdHandle != cdimage_buffer)) { + if (cdimage_buffer_mem == NULL && ((cdimage_buffer_mem = malloc(len_uncompressed_buffer)) == NULL)) { + SysMessage("Could not reserve enough memory for full image buffer.\n"); + exit(3); + } + //printf("Memory ok2 %u %p\n", len_uncompressed_buffer, cdimage_buffer_mem); + cdimage_buffer = fmemopen(cdimage_buffer_mem, len_uncompressed_buffer, "w+b"); + } + else { + + } + + if (cdHandle != cdimage_buffer) { + fclose(cdHandle); // opened thru archive so this not needed anymore + cdHandle = cdimage_buffer; + } + + return 0; +} + +static int cdread_archive(FILE *f, unsigned int base, void *dest, int sector) +{ + s32 r; + size_t size; + size_t readsize; + static off_t offset = 0; // w/o read always or static/ftell + const void *buff; + + // If not pointing to archive file but CDDA file or some other track + if (f != cdHandle) { + return cdimg_read_func_archive(f, base, dest, sector); + } + + // Jump if already completely read + if (a != NULL /*&& (ecm_file_detected || sector*CD_FRAMESIZE_RAW <= len_uncompressed_buffer)*/) { + readsize = (sector + 1) * CD_FRAMESIZE_RAW; + for (fseek(cdimage_buffer, offset, SEEK_SET); offset < readsize;) { + r = archive_read_data_block(a, &buff, &size, &offset); + offset += size; + SysPrintf("ReadArchive seek:%u(%u) cur:%u(%u)\r", sector, readsize / 1024, offset / CD_FRAMESIZE_RAW, offset / 1024); + fwrite(buff, size, 1, cdimage_buffer); + if (r != ARCHIVE_OK) { + //SysPrintf("End of archive.\n"); + archive_read_free(a); + a = NULL; + readsize = offset; + fflush(cdimage_buffer); + fseek(cdimage_buffer, 0, SEEK_SET); + } + } + } + else { + //SysPrintf("ReadSectorArchSector: %u(%u)\n", sector, sector*CD_FRAMESIZE_RAW); + } + + // TODO what causes req sector to be greater than CD size? + r = cdimg_read_func_archive(cdimage_buffer, base, dest, sector); + return r; +} +int handlearchive(const char *isoname, s32* accurate_length) { + u32 read_size = accurate_length ? MSF2SECT(70, 70, 16) : MSF2SECT(0, 0, 16); + int ret = -1; + if ((ret = aropen(cdHandle, isoname)) == 0) { + cdimg_read_func = cdread_archive; + SysPrintf("[+archive]"); + if (!ecm_file_detected) { +#ifndef ENABLE_ECM_FULL + //Detect ECM inside archive + cdimg_read_func_archive = cdread_normal; + cdread_archive(cdHandle, 0, cdbuffer, read_size); + if (handleecm("test.ecm", cdimage_buffer, accurate_length) != -1) { + cdimg_read_func_archive = cdread_ecm_decode; + cdimg_read_func = cdread_archive; + SysPrintf("[+ecm]"); + } +#endif + } + else { + SysPrintf("[+ecm]"); + } + } + return ret; +} +#else +int aropen(FILE* fparchive, const char* _fn) { return -1; } +static int cdread_archive(FILE *f, unsigned int base, void *dest, int sector) { return -1; } +int handlearchive(const char *isoname, s32* accurate_length) { return -1; } +#endif + // this function tries to get the .cue file of the given .bin // the necessary data is put into the ti (trackinformation)-array static int parsecue(const char *isofile) { @@ -1489,157 +1644,6 @@ int handleecm(const char *isoname, FILE* cdh, s32* accurate_length) { return -1; } -int (*cdimg_read_func_archive)(FILE *f, unsigned int base, void *dest, int sector) = NULL; -#ifdef HAVE_LIBARCHIVE -#include <archive.h> -#include <archive_entry.h> - -struct archive *a = NULL; -u32 len_uncompressed_buffer = 0; -void *cdimage_buffer_mem = NULL; -FILE* cdimage_buffer = NULL; //cdHandle to store file - -int aropen(FILE* fparchive, const char* _fn) { - s32 r; - u64 length = 0, length_peek; - boolean use_temp_file = FALSE; // TODO make a config param - static struct archive_entry *ae=NULL; - struct archive_entry *ae_peek; - - if (a == NULL && cdimage_buffer == NULL) { - // We open file twice. First to peek sizes. This nastyness due used interface. - a = archive_read_new(); - r = archive_read_support_compression_all(a); - r = archive_read_support_format_all(a); - //r = archive_read_support_filter_all(a); - //r = archive_read_support_format_raw(a); - //r = archive_read_open_FILE(a, archive); - archive_read_open_filename(a, _fn, 75*CD_FRAMESIZE_RAW); - if (r != ARCHIVE_OK) { - SysPrintf("Archive open failed (%i).\n", r); - archive_read_free(a); - a = NULL; - return -1; - } - // Get the biggest file in archive - while ((r=archive_read_next_header(a, &ae_peek)) == ARCHIVE_OK) { - length_peek = archive_entry_size(ae_peek); - //printf("Entry canditate %s %i\n", archive_entry_pathname(ae_peek), length_peek); - length = MAX(length_peek, length); - ae = (ae == NULL ? ae_peek : ae); - } - archive_read_free(a); - if (ae == NULL) { - SysPrintf("Archive entry read failed (%i).\n", r); - a = NULL; - return -1; - } - //Now really open the file - a = archive_read_new(); - r = archive_read_support_compression_all(a); - r = archive_read_support_format_all(a); - archive_read_open_filename(a, _fn, 75*CD_FRAMESIZE_RAW); - while ((r=archive_read_next_header(a, &ae)) == ARCHIVE_OK) { - length_peek = archive_entry_size(ae); - if (length_peek == length) { - //ae = ae_peek; - SysPrintf(" -- Selected entry %s %i", archive_entry_pathname(ae), length); - break; - } - } - - len_uncompressed_buffer = length?length:700*1024*1024; - } - - if (use_temp_file && (cdimage_buffer == NULL || cdHandle != cdimage_buffer)) { - cdimage_buffer = fopen("/tmp/pcsxr.tmp.bin", "w+b"); - } - else if (!use_temp_file && (cdimage_buffer == NULL || cdHandle != cdimage_buffer)) { - if (cdimage_buffer_mem == NULL && ((cdimage_buffer_mem = malloc(len_uncompressed_buffer)) == NULL)) { - SysMessage("Could not reserve enough memory for full image buffer.\n"); - exit(3); - } - //printf("Memory ok2 %u %p\n", len_uncompressed_buffer, cdimage_buffer_mem); - cdimage_buffer = fmemopen(cdimage_buffer_mem, len_uncompressed_buffer, "w+b"); - } else { - - } - - if (cdHandle != cdimage_buffer) { - fclose(cdHandle); // opened thru archive so this not needed anymore - cdHandle = cdimage_buffer; - } - - return 0; -} - -static int cdread_archive(FILE *f, unsigned int base, void *dest, int sector) -{ - s32 r; - size_t size; - size_t readsize; - static off_t offset = 0; // w/o read always or static/ftell - const void *buff; - - // If not pointing to archive file but CDDA file or some other track - if(f != cdHandle) { - return cdimg_read_func_archive(f, base, dest, sector); - } - - // Jump if already completely read - if (a != NULL /*&& (ecm_file_detected || sector*CD_FRAMESIZE_RAW <= len_uncompressed_buffer)*/) { - readsize = (sector+1) * CD_FRAMESIZE_RAW; - for (fseek(cdimage_buffer, offset, SEEK_SET); offset < readsize;) { - r = archive_read_data_block(a, &buff, &size, &offset); - offset += size; - SysPrintf("ReadArchive seek:%u(%u) cur:%u(%u)\r", sector, readsize/1024, offset/CD_FRAMESIZE_RAW, offset/1024); - fwrite(buff, size, 1, cdimage_buffer); - if (r != ARCHIVE_OK) { - //SysPrintf("End of archive.\n"); - archive_read_free(a); - a = NULL; - readsize = offset; - fflush(cdimage_buffer); - fseek(cdimage_buffer, 0, SEEK_SET); - } - } - } else { - //SysPrintf("ReadSectorArchSector: %u(%u)\n", sector, sector*CD_FRAMESIZE_RAW); - } - - // TODO what causes req sector to be greater than CD size? - r = cdimg_read_func_archive(cdimage_buffer, base, dest, sector); - return r; -} -int handlearchive(const char *isoname, s32* accurate_length) { - u32 read_size = accurate_length?MSF2SECT(70,70,16) : MSF2SECT(0,0,16); - int ret = -1; - if ((ret=aropen(cdHandle, isoname)) == 0) { - cdimg_read_func = cdread_archive; - SysPrintf("[+archive]"); - if (!ecm_file_detected) { -#ifndef ENABLE_ECM_FULL - //Detect ECM inside archive - cdimg_read_func_archive = cdread_normal; - cdread_archive(cdHandle, 0, cdbuffer, read_size); - if (handleecm("test.ecm", cdimage_buffer, accurate_length) != -1) { - cdimg_read_func_archive = cdread_ecm_decode; - cdimg_read_func = cdread_archive; - SysPrintf("[+ecm]"); - } -#endif - } else { - SysPrintf("[+ecm]"); - } - } - return ret; -} -#else -int aropen(FILE* fparchive, const char* _fn) {return -1;} -static int cdread_archive(FILE *f, unsigned int base, void *dest, int sector) {return -1;} -int handlearchive(const char *isoname, s32* accurate_length) {return -1;} -#endif - static unsigned char * CALLBACK ISOgetBuffer_compr(void) { return compr_img->buff_raw[compr_img->sector_in_blk] + 12; } diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c index 33944cd3..aee604e5 100755 --- a/libpcsxcore/misc.c +++ b/libpcsxcore/misc.c @@ -363,6 +363,12 @@ int CheckCdrom() { SysPrintf(_("CD-ROM ID: %.9s\n"), CdromId); SysPrintf(_("CD-ROM EXE Name: %.255s\n"), exename); + memset(Config.PsxExeName, 0, sizeof(Config.PsxExeName)); + strncpy(Config.PsxExeName, exename, 11); + + if(Config.PerGameMcd) + LoadMcds(Config.Mcd1, Config.Mcd2); + BuildPPFCache(); LoadSBI(NULL); diff --git a/libpcsxcore/psxbios.c b/libpcsxcore/psxbios.c index 2043ed90..1249f596 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(cfg, ptr, 128, 128 * 15); + SaveMcd(mcd, 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(Config.Mcd##mcd, Mcd##mcd##Data, offset, a2); \ + SaveMcd(mcd, Config.Mcd##mcd, Mcd##mcd##Data, offset, a2); \ if (FDesc[1 + mcd].mode & 0x8000) v0 = 0; \ else v0 = a2; \ DeliverEvent(0x11, 0x2); /* 0xf0000011, 0x0004 */ \ @@ -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(Config.Mcd##mcd, Mcd##mcd##Data, 128 * i + 0xa, 0x76); \ + SaveMcd(mcd, 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(Config.Mcd##mcd, Mcd##mcd##Data, 128 * i, 1); \ + SaveMcd(mcd, 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(Config.Mcd1, Mcd1Data, sect * MCD_SECT_SIZE, MCD_SECT_SIZE); + SaveMcd(1, Config.Mcd1, Mcd1Data, sect * MCD_SECT_SIZE, MCD_SECT_SIZE); } else { memcpy(Mcd2Data + (sect * MCD_SECT_SIZE), Ra2, MCD_SECT_SIZE); - SaveMcd(Config.Mcd2, Mcd2Data, sect * MCD_SECT_SIZE, MCD_SECT_SIZE); + SaveMcd(2, Config.Mcd2, Mcd2Data, sect * MCD_SECT_SIZE, MCD_SECT_SIZE); } DeliverEvent(0x11, 0x2); // 0xf0000011, 0x0004 diff --git a/libpcsxcore/psxcommon.h b/libpcsxcore/psxcommon.h index 3f13dfa8..65091a34 100755 --- a/libpcsxcore/psxcommon.h +++ b/libpcsxcore/psxcommon.h @@ -137,6 +137,7 @@ typedef struct { char PluginsDir[MAXPATHLEN]; char PatchesDir[MAXPATHLEN]; char IsoImgDir[MAXPATHLEN]; + char PsxExeName[12]; boolean Xa; boolean SioIrq; boolean Mdec; @@ -151,6 +152,7 @@ typedef struct { boolean UseNet; boolean VSyncWA; boolean NoMemcard; + boolean PerGameMcd; boolean Widescreen; boolean HideCursor; boolean SaveWindowPos; @@ -162,6 +164,7 @@ typedef struct { u32 AltSpeed1; // Percent relative to natural speed. u32 AltSpeed2; u8 HackFix; + u8 MemHack; #ifdef _WIN32 char Lang[256]; #endif diff --git a/libpcsxcore/psxmem.c b/libpcsxcore/psxmem.c index 285eaf67..bc2a0ca0 100755 --- a/libpcsxcore/psxmem.c +++ b/libpcsxcore/psxmem.c @@ -143,9 +143,10 @@ u8 psxMemRead8(u32 mem) { char *p; u32 t; - - psxRegs.cycle += 0; - + if (!Config.MemHack) + { + psxRegs.cycle += 0; + } t = mem >> 16; if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) { @@ -172,9 +173,10 @@ u16 psxMemRead16(u32 mem) { char *p; u32 t; - - psxRegs.cycle += 1; - + if (!Config.MemHack) + { + psxRegs.cycle += 1; + } t = mem >> 16; if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) { @@ -201,10 +203,11 @@ u32 psxMemRead32(u32 mem) { char *p; u32 t; + if (!Config.MemHack) + { + psxRegs.cycle += 1; + } - psxRegs.cycle += 1; - - t = mem >> 16; if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) { if ((mem & 0xffff) < 0x400) @@ -230,9 +233,10 @@ void psxMemWrite8(u32 mem, u8 value) { char *p; u32 t; - - psxRegs.cycle += 1; - + if (!Config.MemHack) + { + psxRegs.cycle += 1; + } t = mem >> 16; if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) { @@ -261,9 +265,10 @@ void psxMemWrite16(u32 mem, u16 value) { char *p; u32 t; - - psxRegs.cycle += 1; - + if (!Config.MemHack) + { + psxRegs.cycle += 1; + } t = mem >> 16; if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) { @@ -292,9 +297,10 @@ void psxMemWrite32(u32 mem, u32 value) { char *p; u32 t; - - psxRegs.cycle += 1; - + if (!Config.MemHack) + { + psxRegs.cycle += 1; + } // if ((mem&0x1fffff) == 0x71E18 || value == 0x48088800) SysPrintf("t2fix!!\n"); t = mem >> 16; diff --git a/libpcsxcore/r3000a.c b/libpcsxcore/r3000a.c index cb2f4025..be49540e 100755 --- a/libpcsxcore/r3000a.c +++ b/libpcsxcore/r3000a.c @@ -26,6 +26,7 @@ #include "mdec.h" #include "gpu.h" #include "gte.h" +#include "pgxp_gte.h" R3000Acpu *psxCpu = NULL; psxRegisters psxRegs; diff --git a/libpcsxcore/sio.c b/libpcsxcore/sio.c index e4b8fea1..dfa79bb1 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(Config.Mcd1, Mcd1Data, (adrL | (adrH << 8)) * 128, 128); + SaveMcd(1, Config.Mcd1, Mcd1Data, (adrL | (adrH << 8)) * 128, 128); break; case 0x2002: memcpy(Mcd2Data + (adrL | (adrH << 8)) * 128, &buf[1], 128); - SaveMcd(Config.Mcd2, Mcd2Data, (adrL | (adrH << 8)) * 128, 128); + SaveMcd(2, Config.Mcd2, Mcd2Data, (adrL | (adrH << 8)) * 128, 128); break; } } @@ -884,23 +884,29 @@ void sioInterrupt() { void LoadMcd(int mcd, char *str) { FILE *f; char *data = NULL; + char Mcd[MAXPATHLEN]; if (mcd == 1) data = Mcd1Data; if (mcd == 2) data = Mcd2Data; - if (*str == 0) { + 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) { SysPrintf(_("No memory card value was specified - card %i is not plugged.\n"), mcd); return; } - f = fopen(str, "rb"); + f = fopen(Mcd, "rb"); if (f == NULL) { - SysPrintf(_("The memory card %s doesn't exist - creating it\n"), str); - CreateMcd(str); - f = fopen(str, "rb"); + SysPrintf(_("The memory card %s doesn't exist - creating it\n"), Mcd); + CreateMcd(Mcd); + f = fopen(Mcd, "rb"); if (f != NULL) { struct stat buf; - if (stat(str, &buf) != -1) { + if (stat(Mcd, &buf) != -1) { if (buf.st_size == MCD_SIZE + 64) fseek(f, 64, SEEK_SET); else if(buf.st_size == MCD_SIZE + 3904) @@ -910,12 +916,12 @@ void LoadMcd(int mcd, char *str) { fclose(f); } else - SysMessage(_("Memory card %s failed to load!\n"), str); + SysMessage(_("Memory card %s failed to load!\n"), Mcd); } else { struct stat buf; - SysPrintf(_("Loading memory card %s\n"), str); - if (stat(str, &buf) != -1) { + SysPrintf(_("Loading memory card %s\n"), Mcd); + if (stat(Mcd, &buf) != -1) { if (buf.st_size == MCD_SIZE + 64) fseek(f, 64, SEEK_SET); else if(buf.st_size == MCD_SIZE + 3904) @@ -934,14 +940,20 @@ void LoadMcds(char *mcd1, char *mcd2) { LoadMcd(2, mcd2); } -void SaveMcd(char *mcd, char *data, uint32_t adr, int size) { +void SaveMcd(int mcd, char *str, 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) @@ -953,6 +965,9 @@ void SaveMcd(char *mcd, char *data, uint32_t adr, int size) { fwrite(data + adr, 1, size, f); fclose(f); + + SysPrintf(_("Saving memory card %s\n"), Mcd); + return; } @@ -965,7 +980,7 @@ void SaveMcd(char *mcd, char *data, uint32_t adr, int size) { } #endif - ConvertMcd(mcd, data); + ConvertMcd(str, data); } void CreateMcd(char *mcd) { diff --git a/libpcsxcore/sio.h b/libpcsxcore/sio.h index 64993992..b3897552 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(char *mcd, char *data, uint32_t adr, int size); +void SaveMcd(int mcd, char *str, char *data, uint32_t adr, int size); void CreateMcd(char *mcd); void ConvertMcd(char *mcd, char *data); |
