From 081a269f94ff115fb59e83418a94405bcb633ef0 Mon Sep 17 00:00:00 2001 From: mtabachenko Date: Sat, 17 Jan 2009 16:12:46 +0000 Subject: [PATCH] core: - cleanup LoadROM and adden paths variables; I changed file saves extension for different with others emuls. :) for saves (memory cards): dmc (DeSmuME memory card); for quick saves: dsx (DeSmuME saves when x-number of slot); for cheats: dct (DeSmuME cheats). may need later add import saves (memory card) from another emuls. --- desmume/src/MMU.cpp | 2 +- desmume/src/MMU.h | 3 - desmume/src/NDSSystem.cpp | 136 ++++++++++++---------------- desmume/src/NDSSystem.h | 2 + desmume/src/addons/compactFlash.cpp | 4 +- desmume/src/cflash.cpp | 2 +- desmume/src/cheatSystem.cpp | 1 - desmume/src/saves.cpp | 16 ++-- 8 files changed, 74 insertions(+), 92 deletions(-) diff --git a/desmume/src/MMU.cpp b/desmume/src/MMU.cpp index 0eb9fa746..b8a23fef3 100644 --- a/desmume/src/MMU.cpp +++ b/desmume/src/MMU.cpp @@ -214,8 +214,8 @@ void mmu_log_debug_ARM7(u32 adr, const char *fmt, ...) //#define LOG_DMA2 //#define LOG_DIV +// brrr... if remove next line - Castlevania DoS freeze when press "Start" ingame... ???! char szRomPath[512]; -char szRomBaseName[512]; #define DUP2(x) x, x #define DUP4(x) x, x, x, x diff --git a/desmume/src/MMU.h b/desmume/src/MMU.h index 0b742a64e..5c5cf9038 100644 --- a/desmume/src/MMU.h +++ b/desmume/src/MMU.h @@ -31,9 +31,6 @@ #include "ARM9.h" #include "mc.h" -extern char szRomPath[512]; -extern char szRomBaseName[512]; - /* theses macros are designed for reading/writing in memory (m is a pointer to memory, like MMU.MMU_MEM[proc], and a is an address, like 0x04000000 */ #define MEM_8(m, a) (((u8*)(m[((a)>>20)&0xff]))[((a)&0xfff)]) diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index 0f96d3fee..04a010f23 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -45,7 +45,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA static BOOL LidClosed = FALSE; static u8 countLid = 0; -static u8 pathToROMwithoutExt[MAX_PATH]; +char pathToROM[MAX_PATH]; +char pathFilenameToROMwithoutExt[MAX_PATH]; /* the count of bytes copied from the firmware into memory */ #define NDS_FW_USER_SETTINGS_MEM_BYTE_COUNT 0x70 @@ -311,7 +312,6 @@ void debug() //if((NDS_ARM9.R[15]>>28)) emu_halt(); } -#define DSGBA_EXTENSTION ".ds.gba" #define DSGBA_LOADER_SIZE 512 enum { @@ -343,39 +343,56 @@ int NDS_LoadROM( const char *filename, int bmtype, u32 bmsize, const char *cflash_disk_image_file) #endif { - int i; - int type; - char * p; - - ROMReader_struct * reader; - void* file; - u32 size, mask; - u8 *data; - char * noext; + int i; + int type; + ROMReader_struct *reader; + void *file; + u32 size, mask; + u8 *data; + char *noext; + char *buf[MAX_PATH]; + char extROM[MAX_PATH]; + char extROM2[5]; if (filename == NULL) return -1; + memset(extROM, 0, MAX_PATH); + memset(extROM2, 0, 5); + noext = strdup(filename); - reader = ROMReaderInit(&noext); + + for (int t = strlen(filename); t>0; t--) + if ( (filename[t] == '\\') || (filename[t] == '/') ) + { + strncpy((char *)pathToROM, filename, t+1); + break; + } + + for (int t = strlen(filename); t>0; t--) + if ( (filename[t] == '\\') || (filename[t] == '/') || (filename[t] == '.') ) + { + if (filename[t] != '.') return -1; + strncpy((char *)pathFilenameToROMwithoutExt, filename, t); + strncpy((char *)extROM, filename+t, strlen(filename) - t); + if (t>4) + strncpy((char *)extROM2, filename+(t-3), 3); + break; + } + type = ROM_NDS; - - p = noext; - p += strlen(p); - p -= strlen(DSGBA_EXTENSTION); - - if(memcmp(p, DSGBA_EXTENSTION, strlen(DSGBA_EXTENSTION)) == 0) - type = ROM_DSGBA; + if ( !strcmp((char *)extROM, ".gba") && !strcmp((char *)extROM2, ".ds")) + type = ROM_DSGBA; file = reader->Init(filename); - if (!file) { reader->DeInit(file); - free(noext); + delete [] noext; return -1; } + size = reader->Size(file); if(type == ROM_DSGBA) @@ -387,7 +404,7 @@ int NDS_LoadROM( const char *filename, int bmtype, u32 bmsize, //check that size is at least the size of the header if (size < 352+160) { reader->DeInit(file); - free(noext); + delete [] noext; return -1; } @@ -405,10 +422,11 @@ int NDS_LoadROM( const char *filename, int bmtype, u32 bmsize, if(MMU.CART_ROM != MMU.UNUSED_RAM) NDS_FreeROM(); - if ((data = (u8*)malloc(mask + 1)) == NULL) + data = new u8[mask + 1]; + if (!data) { reader->DeInit(file); - free(noext); + delete [] noext; return -1; } @@ -420,20 +438,6 @@ int NDS_LoadROM( const char *filename, int bmtype, u32 bmsize, #ifndef WORDS_BIGENDIAN DecryptSecureArea(data,size); #endif - for (int t = strlen(filename); t>0; t--) - if ( (filename[t] == '\\') || (filename[t] == '/') ) - { - strncpy(szRomPath, filename, t+1); - break; - } - - for (int t = strlen(filename); t>0; t--) - if ( (filename[t] == '\\') || (filename[t] == '/') || (filename[t] == '.') ) - { - if (filename[t] != '.') return -1; - strncpy((char *)pathToROMwithoutExt, filename, t+1); - break; - } MMU_unsetRom(); NDS_SetROM(data, mask); @@ -441,45 +445,19 @@ int NDS_LoadROM( const char *filename, int bmtype, u32 bmsize, #ifndef EXPERIMENTAL_GBASLOT cflash_close(); - cflash_init( cflash_disk_image_file); + cflash_init(cflash_disk_image_file); #endif + delete [] noext; - strncpy(szRomBaseName, filename, ARRAY_SIZE(szRomBaseName)); - - if(type == ROM_DSGBA) - szRomBaseName[strlen(szRomBaseName)-strlen(DSGBA_EXTENSTION)] = 0x00; - else - szRomBaseName[strlen(szRomBaseName)-4] = 0x00; - - cheatsInit((char *)pathToROMwithoutExt); - - // Setup Backup Memory - if(type == ROM_DSGBA) - { - /* be sure that we dont overwrite anything before stringstart */ - if (strlen(noext)>= strlen(DSGBA_EXTENSTION)) - strncpy(noext + strlen(noext) - strlen(DSGBA_EXTENSTION), ".sav",strlen(DSGBA_EXTENSTION)+1); - else - { - free(noext); - return -1; - } - } - else - { - /* be sure that we dont overwrite anything before stringstart */ - if (strlen(noext)>=4) - strncpy(noext + strlen(noext) - 4, ".sav",5); - else - { - free(noext); - return -1; - } - } + strcpy((char *)buf, (char *)pathFilenameToROMwithoutExt); + strcat((char *)buf, ".dmc"); // DeSmuME memory card :) mc_realloc(&MMU.bupmem, bmtype, bmsize); - mc_load_file(&MMU.bupmem, noext); - free(noext); + mc_load_file(&MMU.bupmem, (char *)buf); + + strcpy((char *)buf, (char *)pathFilenameToROMwithoutExt); + strcat((char *)buf, ".dct"); // DeSmuME cheat :) + cheatsInit((char *)buf); return i; } @@ -487,7 +465,7 @@ int NDS_LoadROM( const char *filename, int bmtype, u32 bmsize, void NDS_FreeROM(void) { if (MMU.CART_ROM != MMU.UNUSED_RAM) - free(MMU.CART_ROM); + delete [] MMU.CART_ROM; MMU_unsetRom(); if (MMU.bupmem.fp) fclose(MMU.bupmem.fp); @@ -1797,12 +1775,18 @@ void NDS_setPad(bool R,bool L,bool D,bool U,bool T,bool S,bool B,bool A,bool Y,b ((u16 *)ARM9Mem.ARM9_REG)[0x130>>1] = (u16)pad; ((u16 *)MMU.ARM7_REG)[0x130>>1] = (u16)pad; - // todo: mute sound when Lided close if (!f && !countLid) { LidClosed = (!LidClosed) & 0x01; - if (!LidClosed) + if (!LidClosed) + { + SPU_Pause(FALSE); NDS_makeARM7Int(22); + + } + else + SPU_Pause(TRUE); + countLid = 30; } else diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index 84d3a4995..8f955f8b9 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -33,6 +33,8 @@ extern volatile BOOL execute; extern BOOL click; +extern char pathToROM[MAX_PATH]; +extern char pathFilenameToROMwithoutExt[MAX_PATH]; /* * The firmware language values diff --git a/desmume/src/addons/compactFlash.cpp b/desmume/src/addons/compactFlash.cpp index 27ba0bdbd..01bfbaf2e 100644 --- a/desmume/src/addons/compactFlash.cpp +++ b/desmume/src/addons/compactFlash.cpp @@ -311,7 +311,7 @@ static BOOL cflash_build_fat( void) maxLevel = -1; if (CFlashUseRomPath) - sRomPath = szRomPath; // From MMU.cpp + sRomPath = pathToROM; else sRomPath = CFlashPath; @@ -517,7 +517,7 @@ BOOL cflash_init() { if (!strlen(CFlashPath)) CFlashUseRomPath = TRUE; if (CFlashUseRomPath) - CFLASHLOG("Using CFlash directory of rom: %s\n", szRomPath); + CFLASHLOG("Using CFlash directory of rom: %s\n", pathToROM); cflashDeviceEnabled = FALSE; currLBA = 0; diff --git a/desmume/src/cflash.cpp b/desmume/src/cflash.cpp index 492605434..cdd145ebd 100644 --- a/desmume/src/cflash.cpp +++ b/desmume/src/cflash.cpp @@ -309,7 +309,7 @@ static BOOL cflash_build_fat( void) { fileLevel = -1; maxLevel = -1; - sRomPath = szRomPath; // From MMU.cpp + sRomPath = pathToROM; files = (DIR_ENT *) malloc(MAXFILES*sizeof(DIR_ENT)); if (files == NULL) return FALSE; diff --git a/desmume/src/cheatSystem.cpp b/desmume/src/cheatSystem.cpp index 9cb06c3d4..cf390134a 100644 --- a/desmume/src/cheatSystem.cpp +++ b/desmume/src/cheatSystem.cpp @@ -44,7 +44,6 @@ void cheatsInit(char *path) cheatsNum = 0; cheatsCurrentGet = 0; strcpy((char *)cheatFilename, path); - strcat((char *)cheatFilename, "cht"); if (cheatsStack) delete [] cheatsStack; cheatsStack = NULL; diff --git a/desmume/src/saves.cpp b/desmume/src/saves.cpp index 7ac00236f..53c8fe0e1 100644 --- a/desmume/src/saves.cpp +++ b/desmume/src/saves.cpp @@ -396,9 +396,9 @@ void scan_savestates() for( i = 1; i <= NB_STATES; i++ ) { - strncpy(filename, szRomBaseName,MAX_PATH); + strncpy(filename, pathFilenameToROMwithoutExt, MAX_PATH); if (strlen(filename) + strlen(".dst") + strlen("-2147483648") /* = biggest string for i */ >MAX_PATH) return ; - sprintf(filename+strlen(filename), "%d.dst", i); + sprintf(filename+strlen(filename), ".ds%d", i); if( stat(filename,&sbuf) == -1 ) continue; savestates[i-1].exists = TRUE; strncpy(savestates[i-1].date, format_time(sbuf.st_mtime),40-strlen(savestates[i-1].date)); @@ -412,9 +412,9 @@ void savestate_slot(int num) struct stat sbuf; char filename[MAX_PATH]; - strncpy(filename, szRomBaseName,MAX_PATH); - if (strlen(filename) + strlen(".dst") + strlen("-2147483648") /* = biggest string for num */ >MAX_PATH) return ; - sprintf(filename+strlen(filename), "%d.dst", num); + strncpy(filename, pathFilenameToROMwithoutExt, MAX_PATH); + if (strlen(filename) + strlen(".dsx") + strlen("-2147483648") /* = biggest string for num */ >MAX_PATH) return ; + sprintf(filename+strlen(filename), ".ds%d", num); savestate_save(filename); savestates[num-1].exists = TRUE; @@ -425,9 +425,9 @@ void savestate_slot(int num) void loadstate_slot(int num) { char filename[MAX_PATH]; - strncpy(filename, szRomBaseName,MAX_PATH); - if (strlen(filename) + strlen(".dst") + strlen("-2147483648") /* = biggest string for num */ >MAX_PATH) return ; - sprintf(filename+strlen(filename), "%d.dst", num); + strncpy(filename, pathFilenameToROMwithoutExt, MAX_PATH); + if (strlen(filename) + strlen(".dsx") + strlen("-2147483648") /* = biggest string for num */ >MAX_PATH) return ; + sprintf(filename+strlen(filename), ".ds%d", num); savestate_load(filename); }