diff options
| author | iCatButler <i.am.catbutler@gmail.com> | 2018-03-19 07:39:08 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-03-19 07:39:08 +0000 |
| commit | 6f76041029393c6823973a29426b28c8c2d0b064 (patch) | |
| tree | 13c1bb5215c2510a7c430b59bc22df666cd2fbf3 /libpcsxcore/misc.c | |
| parent | 768332417644451d38ce1a737465656c7cc75de3 (diff) | |
| parent | 128d6afb179756513860187cf5e31d84d6d8cac4 (diff) | |
| download | pcsxr-6f76041029393c6823973a29426b28c8c2d0b064.tar.gz | |
Merge pull request #7 from loathingKernel/sync-with-codeplex
Sync with codeplex
Diffstat (limited to 'libpcsxcore/misc.c')
| -rwxr-xr-x | libpcsxcore/misc.c | 151 |
1 files changed, 138 insertions, 13 deletions
diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c index f54abeb6..3c3eb318 100755 --- a/libpcsxcore/misc.c +++ b/libpcsxcore/misc.c @@ -52,6 +52,10 @@ struct iso_directory_record { char name [1]; }; +//local extern +void trim_key(char *str, char key ); +void split( char* str, char key, char* pout ); + void mmssdd( char *b, char *p ) { int m, s, d; @@ -261,7 +265,9 @@ int LoadCdromFile(const char *filename, EXE_HEADER *head) { addr = head->t_addr; // Cache clear/invalidate dynarec/int. Fixes startup of Casper/X-Files and possibly others. +#ifdef PSXREC psxCpu->Clear(addr, size / 4); +#endif psxRegs.ICache_valid = FALSE; while (size) { @@ -356,13 +362,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 +378,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); @@ -531,6 +546,95 @@ int Load(const char *ExePath) { return retval; } +static int LoadBin( unsigned long addr, char* filename ) { + int result = -1; + + FILE *f; + long len; + unsigned long mem = addr & 0x001fffff; + + // Load binery files + f = fopen(filename, "rb"); + if (f != NULL) { + fseek(f,0,SEEK_END); + len = ftell(f); + fseek(f,0,SEEK_SET); + if( len + mem < 0x00200000 ) { + if( psxM ) { + int readsize = fread(psxM + mem, len, 1, f); + if( readsize == len ) + result = 0; + } + } + fclose(f); + } + + if( result == 0 ) + SysPrintf(_("ng Load Bin file: [0x%08x] : %s\n"), addr, filename ); + else + SysPrintf(_("ok Load Bin file: [0x%08x] : %s\n"), addr, filename ); + + return result; +} + +int LoadLdrFile(const char *LdrPath ) { + FILE * tmpFile; + int retval = 0; //-1 is error, 0 is success + + tmpFile = fopen(LdrPath, "rt"); + if (tmpFile == NULL) { + SysPrintf(_("Error opening file: %s.\n"), LdrPath); + retval = -1; + } else { + int index = 0; + char sztext[16][256]; + + memset( sztext, 0x00, sizeof(sztext) ); + + while(index <= 15 && fgets( &sztext[index][0], 254, tmpFile )) { + + char szaddr[256]; + char szpath[256]; + char* psrc = &sztext[index][0]; + char* paddr; + char* ppath; + int len; + unsigned long addr = 0L; + + memset( szaddr, 0x00, sizeof(szaddr)); + memset( szpath, 0x00, sizeof(szpath)); + + len = strlen( psrc ); + if( len > 0 ) { + trim( psrc ); + trim_key( psrc, '\t' ); + split( psrc, '\t', szaddr ); + + paddr = szaddr; + ppath = psrc + strlen(paddr); + + //getting address + trim( paddr ); + trim_key( paddr, '\t' ); + addr = strtoul(szaddr, NULL, 16); + if( addr != 0 ) { + //getting bin filepath in ldrfile + trim( ppath ); + trim_key( ppath, '\t' ); + memmove( szpath, ppath, sizeof(szpath)); + + //Load binary to main memory + LoadBin( addr, szpath ); + } + } + + index++; + } + } + + return retval; +} + // STATES #define PCSXR_HEADER_SZ (10) #define SZ_GPUPIC (128 * 96 * 3) @@ -612,7 +716,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 +739,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) { @@ -861,11 +965,15 @@ int RecvPcsxInfo() { // remove the leading and trailing spaces in a string void trim(char *str) { + trim_key( str, ' ' ); +} + +void trim_key(char *str, char key ) { int pos = 0; char *dest = str; // skip leading blanks - while (str[pos] <= ' ' && str[pos] > 0) + while (str[pos] <= key && str[pos] > 0) pos++; while (str[pos]) { @@ -876,10 +984,27 @@ void trim(char *str) { *(dest--) = '\0'; // store the null // remove trailing blanks - while (dest >= str && *dest <= ' ' && *dest > 0) + while (dest >= str && *dest <= key && *dest > 0) *(dest--) = '\0'; } +// split by the keys codes in strings +void split( char* str, char key, char* pout ) +{ + char* psrc = str; + char* pdst = pout; + int len = strlen(str); + int i; + for( i = 0; i < len; i++ ) { + if( psrc[i] == '\0' || psrc[i] == key ) { + *pdst = '\0'; + break; + } else { + *pdst++ = psrc[i]; + } + } +} + // lookup table for crc calculation static unsigned short crctab[256] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, |
