From 2b8398705643339f9fffd0ffe272d017a4e24987 Mon Sep 17 00:00:00 2001 From: zeromus Date: Wed, 1 Jul 2009 05:51:42 +0000 Subject: [PATCH] gbaslot is no longer experimental. old cflash system removed. clean up (hopefully) gbaslot cflash configuration system. common command line parsing for cflash. fix bug in cflash path mounting involving struct packing which failed in gcc (fat image mounting remains untested). --- desmume/configure.ac | 7 - desmume/src/MMU.cpp | 92 --- desmume/src/Makefile.am | 3 +- desmume/src/NDSSystem.cpp | 12 - desmume/src/NDSSystem.h | 5 - desmume/src/PACKED_END.h | 2 +- desmume/src/addons.cpp | 14 +- desmume/src/addons.h | 13 +- desmume/src/addons/compactFlash.cpp | 86 +-- desmume/src/cflash.cpp | 880 ----------------------- desmume/src/cflash.h | 28 - desmume/src/cli/main.cpp | 5 - desmume/src/commandline.cpp | 32 + desmume/src/commandline.h | 5 + desmume/src/common.h | 1 - desmume/src/fat.h | 114 +-- desmume/src/gtk-glade/desmume.cpp | 4 - desmume/src/gtk-glade/globals.h | 1 - desmume/src/gtk/main.cpp | 38 +- desmume/src/windows/DeSmuME_2005.vcproj | 10 +- desmume/src/windows/DeSmuME_2008.vcproj | 10 +- desmume/src/windows/DeSmuME_2010.vcxproj | 2 - desmume/src/windows/gbaslot_config.cpp | 35 +- desmume/src/windows/gbaslot_config.h | 4 + desmume/src/windows/main.cpp | 225 ++---- 25 files changed, 230 insertions(+), 1398 deletions(-) delete mode 100644 desmume/src/cflash.cpp delete mode 100644 desmume/src/cflash.h diff --git a/desmume/configure.ac b/desmume/configure.ac index 294968696..d50f3e6a2 100644 --- a/desmume/configure.ac +++ b/desmume/configure.ac @@ -200,13 +200,6 @@ AC_ARG_ENABLE(wifi, ]) ]) -dnl - gba slot support -AC_ARG_ENABLE(gbaslot, - [AC_HELP_STRING(--enable-gbaslot, enable experimental gba slot support)], - [ - AC_DEFINE(EXPERIMENTAL_GBASLOT) - ]) - dnl Set compiler library flags per target. case $target in *linux* | *bsd*) diff --git a/desmume/src/MMU.cpp b/desmume/src/MMU.cpp index f33ae0522..14460f4d4 100644 --- a/desmume/src/MMU.cpp +++ b/desmume/src/MMU.cpp @@ -33,9 +33,6 @@ #include "common.h" #include "debug.h" #include "NDSSystem.h" -#ifndef EXPERIMENTAL_GBASLOT -#include "cflash.h" -#endif #include "cp15.h" #include "wifi.h" #include "registers.h" @@ -1348,19 +1345,11 @@ void FASTCALL _MMU_ARM9_write08(u32 adr, u8 val) return; } -#ifdef EXPERIMENTAL_GBASLOT if ( (adr >= 0x08000000) && (adr < 0x0A010000) ) { addon.write08(adr, val); return; } -#else - // CFlash writing, Mic - if ((adr>=0x9000000)&&(adr<0x9900000)) { - cflash_write(adr,val); - return; - } -#endif adr &= 0x0FFFFFFF; @@ -1564,20 +1553,11 @@ void FASTCALL _MMU_ARM9_write16(u32 adr, u16 val) return; } -#ifdef EXPERIMENTAL_GBASLOT if ( (adr >= 0x08000000) && (adr < 0x0A010000) ) { addon.write16(adr, val); return; } -#else - // CFlash writing, Mic - if ((adr>=0x08800000)&&(adr<0x09900000)) - { - cflash_write(adr,val); - return; - } -#endif adr &= 0x0FFFFFFF; @@ -2158,19 +2138,11 @@ void FASTCALL _MMU_ARM9_write32(u32 adr, u32 val) //int zzz=9; } -#ifdef EXPERIMENTAL_GBASLOT if ( (adr >= 0x08000000) && (adr < 0x0A010000) ) { addon.write32(adr, val); return; } -#else - // CFlash writing, Mic - if ((adr>=0x9000000) && (adr<0x9900000)) { - cflash_write(adr,val); - return; - } -#endif adr &= 0x0FFFFFFF; @@ -2735,14 +2707,8 @@ u8 FASTCALL _MMU_ARM9_read08(u32 adr) if(adr<0x02000000) return T1ReadByte(ARM9Mem.ARM9_ITCM, adr&0x7FFF); -#ifdef EXPERIMENTAL_GBASLOT if ( (adr >= 0x08000000) && (adr < 0x0A010000) ) return addon.read08(adr); -#else - // CFlash reading, Mic - if ((adr>=0x9000000)&&(adr<0x9900000)) - return (unsigned char)cflash_read(adr); -#endif bool unmapped; adr = MMU_LCDmap(adr, unmapped); @@ -2759,14 +2725,8 @@ u16 FASTCALL _MMU_ARM9_read16(u32 adr) if(adr<0x02000000) return T1ReadWord(ARM9Mem.ARM9_ITCM, adr & 0x7FFF); -#ifdef EXPERIMENTAL_GBASLOT if ( (adr >= 0x08000000) && (adr < 0x0A010000) ) return addon.read16(adr); -#else - // CFlash reading, Mic - if ((adr>=0x08800000) && (adr<0x09900000)) - return (unsigned short)cflash_read(adr); -#endif adr &= 0x0FFFFFFF; @@ -2835,14 +2795,8 @@ u32 FASTCALL _MMU_ARM9_read32(u32 adr) if(adr<0x02000000) return T1ReadLong(ARM9Mem.ARM9_ITCM, adr&0x7FFF); -#ifdef EXPERIMENTAL_GBASLOT if ( (adr >= 0x08000000) && (adr < 0x0A010000) ) return addon.read32(adr); -#else - // CFlash reading, Mic - if ((adr>=0x9000000) && (adr<0x9900000)) - return (u32)cflash_read(adr); -#endif adr &= 0x0FFFFFFF; @@ -3021,20 +2975,11 @@ void FASTCALL _MMU_ARM7_write08(u32 adr, u8 val) { mmu_log_debug_ARM7(adr, "(write08) %0x%X", val); -#ifdef EXPERIMENTAL_GBASLOT if ( (adr >= 0x08000000) && (adr < 0x0A010000) ) { addon.write08(adr, val); return; } -#else - // CFlash writing, Mic - if ((adr>=0x9000000)&&(adr<0x9900000)) - { - cflash_write(adr,val); - return; - } -#endif adr &= 0x0FFFFFFF; // This is bad, remove it @@ -3094,20 +3039,11 @@ void FASTCALL _MMU_ARM7_write16(u32 adr, u16 val) { mmu_log_debug_ARM7(adr, "(write16) %0x%X", val); -#ifdef EXPERIMENTAL_GBASLOT if ( (adr >= 0x08000000) && (adr < 0x0A010000) ) { addon.write16(adr, val); return; } -#else - // CFlash writing, Mic - if ((adr>=0x08800000)&&(adr<0x09900000)) - { - cflash_write(adr,val); - return; - } -#endif #ifdef EXPERIMENTAL_WIFI @@ -3518,21 +3454,11 @@ void FASTCALL _MMU_ARM7_write32(u32 adr, u32 val) { mmu_log_debug_ARM7(adr, "(write32) %0x%X", val); -#ifdef EXPERIMENTAL_GBASLOT if ( (adr >= 0x08000000) && (adr < 0x0A010000) ) { addon.write32(adr, val); return; } -#else - // CFlash writing, Mic - if ((adr>=0x9000000)&&(adr<0x9900000)) { - cflash_write(adr,val); - return; - } -#endif - - #ifdef EXPERIMENTAL_WIFI if ((adr & 0xFF800000) == 0x04800000) @@ -3819,14 +3745,8 @@ u8 FASTCALL _MMU_ARM7_read08(u32 adr) } #endif -#ifdef EXPERIMENTAL_GBASLOT if ( (adr >= 0x08000000) && (adr < 0x0A010000) ) return addon.read08(adr); -#else - // CFlash reading, Mic - if ((adr>=0x9000000)&&(adr<0x9900000)) - return (unsigned char)cflash_read(adr); -#endif if (adr == REG_RTC) return (u8)rtcRead(); @@ -3847,14 +3767,8 @@ u16 FASTCALL _MMU_ARM7_read16(u32 adr) return WIFI_read16(&wifiMac,adr) ; #endif -#ifdef EXPERIMENTAL_GBASLOT if ( (adr >= 0x08000000) && (adr < 0x0A010000) ) return addon.read16(adr); -#else - // CFlash reading, Mic - if ((adr>=0x08800000)&&(adr<0x09900000)) - return (unsigned short)cflash_read(adr); -#endif adr &= 0x0FFFFFFF; @@ -3919,14 +3833,8 @@ u32 FASTCALL _MMU_ARM7_read32(u32 adr) return (WIFI_read16(&wifiMac,adr) | (WIFI_read16(&wifiMac,adr+2) << 16)); #endif -#ifdef EXPERIMENTAL_GBASLOT if ( (adr >= 0x08000000) && (adr < 0x0A010000) ) return addon.read32(adr); -#else - // CFlash reading, Mic - if ((adr>=0x9000000)&&(adr<0x9900000)) - return (u32)cflash_read(adr); -#endif adr &= 0x0FFFFFFF; diff --git a/desmume/src/Makefile.am b/desmume/src/Makefile.am index dc119f95a..c3dcfb956 100644 --- a/desmume/src/Makefile.am +++ b/desmume/src/Makefile.am @@ -15,7 +15,6 @@ libdesmume_a_SOURCES = \ armcpu.cpp armcpu.h ARM9.h \ arm_instructions.cpp arm_instructions.h \ bios.cpp bios.h bits.h cp15.cpp cp15.h \ - cflash.cpp cflash.h fs.h \ common.cpp common.h \ debug.cpp debug.h driver.h \ Disassembler.cpp Disassembler.h \ @@ -48,7 +47,7 @@ libdesmume_a_SOURCES = \ utils/decrypt/crc.cpp utils/decrypt/crc.h utils/decrypt/decrypt.cpp \ utils/decrypt/decrypt.h utils/decrypt/header.cpp utils/decrypt/header.h \ addons.cpp addons.h \ - addons/compactFlash.cpp addons/gbagame.cpp addons/none.cpp addons/rumblepak.cpp \ + addons/compactFlash.cpp addons/gbagame.cpp addons/none.cpp addons/rumblepak.cpp fs.h \ mic.cpp mic.h \ cheatSystem.cpp cheatSystem.h \ texcache.cpp texcache.h rasterize.cpp rasterize.h \ diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index 39c63509f..6ab93c992 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -31,9 +31,6 @@ #include "NDSSystem.h" #include "render3D.h" #include "MMU.h" -#ifndef EXPERIMENTAL_GBASLOT -#include "cflash.h" -#endif #include "ROMReader.h" #include "gfx3d.h" #include "utils/decrypt/decrypt.h" @@ -712,12 +709,7 @@ void GameInfo::populate() } } -#ifdef EXPERIMENTAL_GBASLOT int NDS_LoadROM( const char *filename) -#else -int NDS_LoadROM( const char *filename, - const char *cflash_disk_image_file) -#endif { int ret; int type; @@ -833,10 +825,6 @@ int NDS_LoadROM( const char *filename, NDS_SetROM(data, mask); NDS_Reset(); -#ifndef EXPERIMENTAL_GBASLOT - cflash_close(); - cflash_init(cflash_disk_image_file); -#endif free(noext); memset(buf, 0, MAX_PATH); diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index 08a4c4166..cdbc629d8 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -289,12 +289,7 @@ void NDS_releaseTouch(void); void NDS_setPad(bool R,bool L,bool D,bool U,bool T,bool S,bool B,bool A,bool Y,bool X,bool W,bool E,bool G, bool F); void NDS_setPadFromMovie(u16 pad); -#ifdef EXPERIMENTAL_GBASLOT int NDS_LoadROM(const char *filename); -#else -int NDS_LoadROM(const char *filename, - const char *cflash_disk_image_file); -#endif void NDS_FreeROM(void); void NDS_Reset(); int NDS_ImportSave(const char *filename); diff --git a/desmume/src/PACKED_END.h b/desmume/src/PACKED_END.h index 9d407a236..4c0798dd0 100644 --- a/desmume/src/PACKED_END.h +++ b/desmume/src/PACKED_END.h @@ -1,3 +1,3 @@ -#if defined(_MSC_VER) || defined(__INTEL_COMPILER) +#ifndef __GNUC__ #pragma pack(pop) #endif diff --git a/desmume/src/addons.cpp b/desmume/src/addons.cpp index d1abe9826..3aadbc369 100644 --- a/desmume/src/addons.cpp +++ b/desmume/src/addons.cpp @@ -23,11 +23,16 @@ */ #include "addons.h" +#include -char CFlashName[MAX_PATH]; -char CFlashPath[MAX_PATH]; -u8 CFlashUseRomPath = TRUE; -u8 CFlashUsePath = TRUE; +std::string CFlash_Path; +ADDON_CFLASH_MODE CFlash_Mode; + + +//char CFlashName[MAX_PATH]; +//char CFlashPath[MAX_PATH]; +//u8 CFlashUseRomPath = TRUE; +//u8 CFlashUsePath = TRUE; char GBAgameName[MAX_PATH]; @@ -63,6 +68,7 @@ void addonsReset() BOOL addonsChangePak(u8 type) { + printf("addonsChangePak\n"); if (type > NDS_ADDON_COUNT) return FALSE; addon.close(); addon = addonList[type]; diff --git a/desmume/src/addons.h b/desmume/src/addons.h index 0d14402bf..d011d2aee 100644 --- a/desmume/src/addons.h +++ b/desmume/src/addons.h @@ -69,14 +69,19 @@ enum { NDS_ADDON_COUNT // use for counter addons - MUST TO BE LAST!!! }; +enum ADDON_CFLASH_MODE +{ + ADDON_CFLASH_MODE_Path, ADDON_CFLASH_MODE_File, ADDON_CFLASH_MODE_RomPath +}; + +extern ADDON_CFLASH_MODE CFlash_Mode; +extern std::string CFlash_Path; +inline bool CFlash_IsUsingPath() { return CFlash_Mode==ADDON_CFLASH_MODE_Path || CFlash_Mode==ADDON_CFLASH_MODE_RomPath; } + extern ADDONINTERFACE addon; // current pak extern ADDONINTERFACE addonList[NDS_ADDON_COUNT]; // lists pointer on paks extern u8 addon_type; // current type pak -extern char CFlashName[MAX_PATH]; // path to compact flash img file -extern char CFlashPath[MAX_PATH]; // path to compact flash directory -extern u8 CFlashUsePath; // true is used path from CFlashPath for cflash folder -extern u8 CFlashUseRomPath; // true is used path to rom file for cflash folder extern char GBAgameName[MAX_PATH]; // file name for GBA game (rom) extern void (*FeedbackON)(BOOL enable); // feedback on/off diff --git a/desmume/src/addons/compactFlash.cpp b/desmume/src/addons/compactFlash.cpp index 094f8a170..246a70d58 100644 --- a/desmume/src/addons/compactFlash.cpp +++ b/desmume/src/addons/compactFlash.cpp @@ -24,9 +24,8 @@ */ #include "../addons.h" +#include #include -#ifdef EXPERIMENTAL_GBASLOT - #include "debug.h" #include #include @@ -102,7 +101,7 @@ static const int lfnPos[13] = {1,3,5,7,9,14,16,18,20,22,24,28,30}; #define BYTESPERCLUS (512*SECPERCLUS) #define DIRENTSPERCLUS ((BYTESPERCLUS)/32) -static BOOT_RECORD MBR; +BOOT_RECORD MBR; static DIR_ENT *files,*dirEntries,**dirEntryPtr; static FILE_INFO *fileLink,*dirEntryLink; static u32 filesysFAT,filesysRootDir,filesysData; @@ -112,7 +111,6 @@ static DIR_ENT *extraDirEntries[SECPERFAT*256]; static int numFiles,maxLevel,numRootFiles; static int *dirEntriesInCluster, clusterNum, firstDirEntCluster, lastDirEntCluster, lastFileDataCluster; -static char *sRomPath; static int activeDirEnt=-1; static u32 bufferStart; static u32 fileStartLBA,fileEndLBA; @@ -121,6 +119,8 @@ static FILE * hFile; static char fpath[255+1]; static BOOL cflashDeviceEnabled = FALSE; +static std::string sFlashPath; + // =========================== BOOL inited; @@ -273,6 +273,7 @@ static void list_files(const char *filepath) { fname = (strlen(entry.cAlternateFileName)>0) ? entry.cAlternateFileName : entry.cFileName; add_file(fname, &entry, fileLevel); + printf("cflash added %s\n",fname); if (numFiles==MAXFILES-1) break; @@ -281,7 +282,7 @@ static void list_files(const char *filepath) if (strlen(fname)+strlen(filepath)+2 < 256) { sprintf(SubDir, "%s%c%s", filepath, FS_SEPARATOR, fname); - list_files(SubDir); + list_files(SubDir); } } } @@ -298,7 +299,7 @@ static void list_files(const char *filepath) } // Set up the MBR, FAT and DIR_ENTs -static BOOL cflash_build_fat( void) +static BOOL cflash_build_fat() { int i,j,k,l, clust,numClusters, @@ -309,12 +310,6 @@ static BOOL cflash_build_fat( void) fileLevel = -1; maxLevel = -1; - if (CFlashUseRomPath) - sRomPath = pathToROM; - else - sRomPath = CFlashPath; - - files = (DIR_ENT *) malloc(MAXFILES*sizeof(DIR_ENT)); if (files == NULL) return FALSE; fileLink = (FILE_INFO *) malloc(MAXFILES*sizeof(FILE_INFO)); @@ -336,8 +331,7 @@ static BOOL cflash_build_fat( void) numExtraEntries[i] = 0; } - //COMMENT OUT THIS LINE TO STOP THE IRRITATING FILESYSTEM SCANNING BEHAVIOR - list_files(sRomPath); + list_files(sFlashPath.c_str()); k = 0; clusterNum = rootCluster = (SECRESV + SECPERFAT)/SECPERCLUS; @@ -512,11 +506,21 @@ static BOOL cflash_init() if (inited) return FALSE; BOOL init_good = FALSE; - if (CFlashUsePath) + printf("CFlash_Mode: %d\n",CFlash_Mode); + + if (CFlash_Mode == ADDON_CFLASH_MODE_RomPath) + { + sFlashPath = pathToROM; + printf("Using CFlash directory of rom: %s\n", sFlashPath.c_str()); + } + else if(CFlash_Mode == ADDON_CFLASH_MODE_Path) + { + sFlashPath = CFlash_Path; + printf("Using CFlash directory: %s\n", sFlashPath.c_str()); + } + + if(CFlash_IsUsingPath()) { - if (!strlen(CFlashPath)) CFlashUseRomPath = TRUE; - if (CFlashUseRomPath) - CFLASHLOG("Using CFlash directory of rom: %s\n", pathToROM); cflashDeviceEnabled = FALSE; currLBA = 0; @@ -524,8 +528,10 @@ static BOOL cflash_init() fclose(hFile); activeDirEnt = -1; fileStartLBA = fileEndLBA = 0xFFFFFFFF; - if (!cflash_build_fat()) + if (!cflash_build_fat()) { + printf("FAILED cflash_build_fat\n"); return FALSE; + } cf_reg_sts = 0x58; // READY cflashDeviceEnabled = TRUE; @@ -533,9 +539,9 @@ static BOOL cflash_init() } else { - if (!strlen(CFlashName)) return FALSE; - CFLASHLOG("Using CFlash disk image file %s\n", CFlashName); - disk_image = OPEN_FN( CFlashName, OPEN_MODE); + sFlashPath = CFlash_Path; + printf("Using CFlash disk image file %s\n", sFlashPath.c_str()); + disk_image = OPEN_FN( sFlashPath.c_str(), OPEN_MODE); if ( disk_image != -1) { @@ -553,7 +559,7 @@ static BOOL cflash_init() } else // TODO: create image if not exist - CFLASHLOG("Failed to open file %s: \"%s\"\n", CFlashName, strerror( errno)); + CFLASHLOG("Failed to open file %s: \"%s\"\n", sFlashPath.c_str(), strerror( errno)); } // READY @@ -645,7 +651,7 @@ static u16 fread_buffered(int dirent,u32 cluster,u32 offset) if (activeDirEnt != -1) fclose(hFile); - strncpy(fpath,sRomPath,ARRAY_SIZE(fpath)); + strncpy(fpath,sFlashPath.c_str(),ARRAY_SIZE(fpath)); strncat(fpath,DIR_SEP,ARRAY_SIZE(fpath)-strlen(fpath)); resolve_path(dirent); @@ -653,6 +659,7 @@ static u16 fread_buffered(int dirent,u32 cluster,u32 offset) fatstring_to_asciiz(dirent,fname,NULL); strncat(fpath,fname,ARRAY_SIZE(fpath)-strlen(fpath)); + printf("CFLASH Opening %s\n",fpath); hFile = fopen(fpath, "rb"); if (!hFile) return 0; bufferStart = offset; @@ -686,7 +693,7 @@ static unsigned int cflash_read(unsigned int address) case CF_REG_DATA: if (cf_reg_cmd == CF_CMD_READ) { - if (!CFlashUsePath) + if (!CFlash_IsUsingPath()) { if ( disk_image != -1) { @@ -832,7 +839,7 @@ static void cflash_write(unsigned int address,unsigned int data) case CF_REG_DATA: if (cf_reg_cmd == CF_CMD_WRITE) { - if (!CFlashUsePath) + if (!CFlash_IsUsingPath()) { sector_data[sector_write_index] = (data >> 0) & 0xff; sector_data[sector_write_index + 1] = (data >> 8) & 0xff; @@ -908,11 +915,11 @@ static void cflash_write(unsigned int address,unsigned int data) static void cflash_close( void) { if (!inited) return; - if (!CFlashUsePath) + if (!CFlash_IsUsingPath()) { - if ( disk_image != -1) + if (disk_image != -1) { - CLOSE_FN( disk_image); + CLOSE_FN(disk_image); disk_image = -1; } } @@ -947,8 +954,8 @@ static void cflash_close( void) static BOOL CFlash_init(void) { - CFlashUseRomPath = TRUE; - CFlashUsePath = TRUE; + printf("CFlash_init\n"); + cflash_init(); return TRUE; } @@ -1001,23 +1008,6 @@ static void CFlash_info(char *info) { strcpy(info, "Compact Flash memory in slot"); } -#else -static BOOL CFlash_init(void) { return TRUE; } -static void CFlash_reset(void) {} -static void CFlash_close(void) {} -static void CFlash_config(void){} -static void CFlash_write08(u32 adr, u8 val){} -static void CFlash_write16(u32 adr, u16 val){} -static void CFlash_write32(u32 adr, u32 val){} -static u8 CFlash_read08(u32 adr){return (0);} -static u16 CFlash_read16(u32 adr){return (0);} -static u32 CFlash_read32(u32 adr){return (0);} - -static void CFlash_info(char *info) -{ - strcpy(info, "Compact Flash memory in slot"); -} -#endif ADDONINTERFACE addonCFlash = { "Compact Flash", diff --git a/desmume/src/cflash.cpp b/desmume/src/cflash.cpp deleted file mode 100644 index a5bb8697f..000000000 --- a/desmume/src/cflash.cpp +++ /dev/null @@ -1,880 +0,0 @@ -/* Copyright (C) 2006 yopyop - yopyop156@ifrance.com - yopyop156.ifrance.com - - Copyright (C) 2006-2008 The DeSmuME Team - - This file is part of DeSmuME - - DeSmuME is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - DeSmuME is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with DeSmuME; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -/* - CFLASH.C - CompactFlash/FAT emulation routines for DeSmuME - /Mic, 2006 - - Logical memory layout: - - ---------------------- - | MBR | - ---------------------- - | FAT | - ---------------------- - | Root entries | - ---------------------- - | Subdirectories | - ---------------------- - | File data | - ---------------------- - -*/ -#include "common.h" - -#ifndef EXPERIMENTAL_GBASLOT - -#include -#include -#include -#include - -#include -#include -#ifdef WIN32 -#include -#define OPEN_MODE _O_RDWR | _O_BINARY - -#define OPEN_FN _open -#define CLOSE_FN _close -#define LSEEK_FN _lseek -#define WRITE_FN _write -#define READ_FN _read -#else -#include -#define OPEN_MODE O_RDWR - -#define OPEN_FN open -#define CLOSE_FN close -#define LSEEK_FN lseek -#define WRITE_FN write -#define READ_FN read -#endif - -#include "types.h" -#include "fs.h" -#include "MMU.h" -#include "cflash.h" -#include "NDSSystem.h" -#include "debug.h" - -static int use_disk_image_file = 0; - -/* Set up addresses for GBAMP */ -#define CF_REG_DATA 0x9000000 -#define CF_REG_ERR 0x9020000 -#define CF_REG_SEC 0x9040000 -#define CF_REG_LBA1 0x9060000 -#define CF_REG_LBA2 0x9080000 -#define CF_REG_LBA3 0x90A0000 -#define CF_REG_LBA4 0x90C0000 -#define CF_REG_CMD 0x90E0000 -#define CF_REG_STS 0x98C0000 - -// CF Card commands -#define CF_CMD_LBA 0xE0 -#define CF_CMD_READ 0x20 -#define CF_CMD_WRITE 0x30 - - -static int disk_image = -1; -static off_t file_size; - -static u16 cf_reg_sts, cf_reg_lba1, cf_reg_lba2, - cf_reg_lba3, cf_reg_lba4, cf_reg_cmd; -static off_t currLBA; - -#define SECPERFAT 128 -#define SECPERCLUS 16 -#define MAXFILES 32768 -#define SECRESV 2 -#define NUMSECTORS 0x80000 -#define NUMCLUSTERS (NUMSECTORS/SECPERCLUS) -#define BYTESPERCLUS (512*SECPERCLUS) -#define DIRENTSPERCLUS ((BYTESPERCLUS)/32) - - -static BOOT_RECORD MBR; -static DIR_ENT *files,*dirEntries,**dirEntryPtr; -static FILE_INFO *fileLink,*dirEntryLink; -static u32 filesysFAT,filesysRootDir,filesysData; -static u16 FAT16[SECPERFAT*256]; -static u16 numExtraEntries[SECPERFAT*256]; -static DIR_ENT *extraDirEntries[SECPERFAT*256]; -static int numFiles,maxLevel,numRootFiles; -static int *dirEntriesInCluster, clusterNum, firstDirEntCluster, - lastDirEntCluster, lastFileDataCluster; -static char *sRomPath; -static int activeDirEnt=-1; -static u32 bufferStart; -static u32 fileStartLBA,fileEndLBA; -static u16 freadBuffer[256]; -static FILE * hFile; -static char fpath[255+1]; -static BOOL cflashDeviceEnabled = FALSE; - -static int lfn_checksum( void) { - int i; - u8 chk; - - chk = 0; - for (i=0; i < (NAME_LEN + EXT_LEN); i++) { - chk = ((chk & 1) ? 0x80 : 0) + (chk >> 1) + (i < NAME_LEN ? files[numFiles].name[i] : files[numFiles].ext[i - NAME_LEN]); - } - return chk; -} - - -static const int lfnPos[13] = {1,3,5,7,9,14,16,18,20,22,24,28,30}; - - -/* Add a DIR_ENT for the files */ -static void add_file(char *fname, FsEntry * entry, int fileLevel) { - int i,j,k,n; - u8 chk; - - if (numFiles < MAXFILES-1) { - if (strcmp(fname,"..") != 0) { - for (i=strlen(fname)-1; i>=0; i--) - if (fname[i]=='.') break; - if ((i==0)&&(strcmp(fname,".")==0)) i = 1; - if (i<0) i = strlen(fname); - for (j=0; j=strlen(fname)) break; - files[numFiles].ext[j] = fname[j+i+1]; - } - for (; j<3; j++) - files[numFiles].ext[j] = 0x20; - - fileLink[fileLevel].filesInDir += 1; - - // See if LFN entries need to be added - if (strlen(entry->cAlternateFileName)>0) { - char *p = NULL; - - chk = lfn_checksum(); - k = (strlen(entry->cFileName)/13) + (((strlen(entry->cFileName)%13)!=0)?1:0); - numFiles += k; - - fileLink[fileLevel].filesInDir += k; - - n = 0; - j = 13; - for (i=0; (size_t)icFileName); i++) { - if (j == 13) { - n++; - p = (char*)&files[numFiles-n].name[0]; - fileLink[numFiles-n].parent = fileLevel; - p[0] = n; - ((DIR_ENT*)p)->attrib = ATTRIB_LFN; - p[0xD] = chk; - j = 0; - } - *(p + lfnPos[j]) = entry->cFileName[i]; - *(p + lfnPos[j]+1) = 0; - j++; - } - for (; j<13; j++) { - *(p + lfnPos[j]) = entry->cFileName[i]; - *(p + lfnPos[j]+1) = 0; - } - if (p != NULL) - p[0] |= 0x40; // END - for (i=strlen(fname)-1; i>=0; i--) - if (fname[i]=='.') break; - if ((i==0)&&(strcmp(fname,".")==0)) i = 1; - if (i<0) i = strlen(fname); - for (j=0; j=strlen(fname)) break; - files[numFiles].ext[j] = fname[j+i+1]; - } - for (; j<3; j++) - files[numFiles].ext[j] = 0x20; - } - - files[numFiles].fileSize = entry->fileSize; - - if (entry->flags & FS_IS_DIR) { - if (strcmp(fname,".")==0) - fileLink[numFiles].level = maxLevel; - else - fileLink[numFiles].level = maxLevel+1; - files[numFiles].attrib = ATTRIB_DIR; - } else { - files[numFiles].attrib = 0; - } - - fileLink[numFiles].parent = fileLevel; - - numFiles++; - } else if (fileLevel > 0) { - fileLink[fileLevel].filesInDir += 1; - strncpy((char*)&files[numFiles].name[0],".. ",NAME_LEN); - strncpy((char*)&files[numFiles].ext[0]," ",EXT_LEN); - fileLink[numFiles].parent = fileLevel; - files[numFiles].attrib = 0x10; - numFiles++; - } - } -} - - -/* List all files and subdirectories recursively */ -static void list_files(const char *filepath) { - char DirSpec[255+1], SubDir[255+1]; - FsEntry entry; - void * hFind; - char *fname; - u32 dwError; - int fileLevel; - - maxLevel++; - fileLevel = maxLevel; - - strncpy(DirSpec, filepath, ARRAY_SIZE(DirSpec)); - DirSpec[255] = 0 ; /* hard limit the string here */ - - hFind = FsReadFirst(DirSpec, &entry); - if (hFind == NULL) - return; - - fname = (strlen(entry.cAlternateFileName)>0) ? entry.cAlternateFileName : entry.cFileName; - add_file(fname, &entry, fileLevel); - - while (FsReadNext(hFind, &entry) != 0) { - fname = (strlen(entry.cAlternateFileName)>0) ? entry.cAlternateFileName : entry.cFileName; - add_file(fname, &entry, fileLevel); - - if (numFiles==MAXFILES-1) - break; - - if ((entry.flags & FS_IS_DIR) && (strcmp(fname, ".")) && (strcmp(fname, ".."))) { - if (strlen(fname)+strlen(filepath)+2 < 256) { - sprintf(SubDir, "%s%c%s", filepath, FS_SEPARATOR, fname); - list_files(SubDir); - } - } - } - - dwError = FsError(); - FsClose(hFind); - if (dwError != FS_ERR_NO_MORE_FILES) - return; - - if (numFiles < MAXFILES) { - fileLink[numFiles].parent = fileLevel; - files[numFiles++].name[0] = 0; - } -} - - - -/* Set up the MBR, FAT and DIR_ENTs */ -static BOOL cflash_build_fat( void) { - int i,j,k,l, - clust,numClusters, - clusterNum2,rootCluster; - int fileLevel; - - numFiles = 0; - fileLevel = -1; - maxLevel = -1; - - sRomPath = pathToROM; - files = (DIR_ENT *) malloc(MAXFILES*sizeof(DIR_ENT)); - if (files == NULL) - return FALSE; - fileLink = (FILE_INFO *) malloc(MAXFILES*sizeof(FILE_INFO)); - if (fileLink == NULL) { - free(files); - return FALSE; - } - - for (i=0; i>8; - clust += l; - numClusters += l; - } - } else { - dirEntries[k-1].startCluster = clusterNum; - } - } - if (i==0) numRootFiles++; - dirEntriesInCluster[clusterNum]++; - if (dirEntriesInCluster[clusterNum]==256) { - clusterNum++; - } - } - } - clusterNum = clusterNum2 + ((fileLink[i].filesInDir)>>8) + 1; - numClusters++; - } - - // Free the file indexing buffer - free(files); - free(fileLink); - - // Set up the MBR - MBR.bytesPerSector = 512; - MBR.numFATs = 1; - /* replaced strcpy with strncpy. It doesnt matter here, as the strings are constant */ - /* but we should extingish all unrestricted strcpy,strcat from the project */ - strncpy((char*)&MBR.OEMName[0],"DESMUM",8); - strncpy((char*)&MBR.fat16.fileSysType[0],"FAT16 ",8); - MBR.reservedSectors = SECRESV; - MBR.numSectors = 524288; - MBR.numSectorsSmall = 0; - MBR.sectorsPerCluster = SECPERCLUS; - MBR.sectorsPerFAT = SECPERFAT; - MBR.rootEntries = 512; - MBR.fat16.signature = 0xAA55; - MBR.mediaDesc = 1; - - filesysFAT = 0 + MBR.reservedSectors; - filesysRootDir = filesysFAT + (MBR.numFATs * MBR.sectorsPerFAT); - filesysData = filesysRootDir + ((MBR.rootEntries * sizeof(DIR_ENT)) / 512); - - // Set up the cluster values for all subdirectories - clust = filesysData / SECPERCLUS; - firstDirEntCluster = clust; - for (i=1; i rootCluster) - dirEntries[i].startCluster += clust-rootCluster; - } - } - lastDirEntCluster = clust+numClusters-1; - - // Set up the cluster values for all files - clust += numClusters; //clusterNum; - for (i=0; i 0) { - if (dirEntries[i].startCluster+j < MAXFILES) - FAT16[dirEntries[i].startCluster+j] = dirEntries[i].startCluster+j+1; - j++; - l -= (512*16); - } - if ((dirEntries[i].attrib & ATTRIB_DIR)==0) { - if (dirEntries[i].startCluster+j < MAXFILES) - FAT16[dirEntries[i].startCluster+j] = 0xFFFF; - } - k = dirEntries[i].startCluster+j; - } - } - - for (i=(filesysData/SECPERCLUS); iname[i] == ' ') break; - out[i] = pd->name[i]; - } - if ((pd->attrib & 0x10)==0) { - out[i++] = '.'; - for (j=0; jext[j] == ' ') break; - out[i++] = pd->ext[j]; - } - } - out[i] = '\0'; -} - - - -/* Resolve the path of a files by working backwards through the directory entries */ -static void resolve_path(int dirent) { - int i; - char dirname[128]; - - while (dirEntryLink[dirent].parent > 0) { - for (i=0; i= bufferStart + 512)) { - if (!hFile) { - CFLASHLOG("fread_buffered with hFile null with" - "offset %lu and bufferStart %lu\n", - offset, bufferStart); - return 0; - } - fseek(hFile, offset, SEEK_SET); - elems_read += fread(&freadBuffer, 1, 512, hFile); - bufferStart = offset; - } - - return freadBuffer[(offset-bufferStart)>>1]; - } - if (activeDirEnt != -1) - fclose(hFile); - - strncpy(fpath,sRomPath,ARRAY_SIZE(fpath)); - strncat(fpath,DIR_SEP,ARRAY_SIZE(fpath)-strlen(fpath)); - - resolve_path(dirent); - - fatstring_to_asciiz(dirent,fname,NULL); - strncat(fpath,fname,ARRAY_SIZE(fpath)-strlen(fpath)); - - hFile = fopen(fpath, "rb"); - if (!hFile) return 0; - bufferStart = offset; - fseek(hFile, offset, SEEK_SET); - elems_read += fread(&freadBuffer, 1, 512, hFile); - - bufferStart = offset; - activeDirEnt = dirent; - fileStartLBA = (dirEntries[dirent].startCluster*512*SECPERCLUS); - fileEndLBA = fileStartLBA + dirEntries[dirent].fileSize; - - return freadBuffer[(offset-bufferStart)>>1]; -} - -unsigned int -cflash_read(unsigned int address) { - unsigned int ret_value = 0; - size_t elems_read = 0; -#if 0 /* used by next if 0 block */ -#define BUFFERED_BLOCK_SIZE 512 - static u8 block_buffer[BUFFERED_BLOCK_SIZE]; - static s32 buffered_start_index = -1; -#endif - - switch ( address) { - case CF_REG_STS: - ret_value = cf_reg_sts; - break; - - case CF_REG_DATA: - if (cf_reg_cmd == CF_CMD_READ) { - if ( use_disk_image_file) { - if ( disk_image != -1) { - u8 data[2]; -#if 0 - if ( currLBA < buffered_start_index || - currLBA >= (buffered_start_index + BUFFERED_BLOCK_SIZE)) { - size_t read_bytes = 0; - LSEEK_FN( disk_image, currLBA, SEEK_SET); - - while ( read_bytes < BUFFERED_BLOCK_SIZE) { - size_t cur_read = - READ_FN( disk_image, &block_buffer[read_bytes], - BUFFERED_BLOCK_SIZE - read_bytes); - - if ( cur_read == -1) { - CFLASHLOG( "Error during read: %s\n", strerror(errno) ); - break; - } - read_bytes += cur_read; - } - - CFLASHLOG( "Read %d bytes\n", read_bytes); - - buffered_start_index = currLBA; - } - data[0] = block_buffer[currLBA - buffered_start_index]; - data[1] = block_buffer[currLBA + 1 - buffered_start_index]; -#else - LSEEK_FN( disk_image, currLBA, SEEK_SET); - elems_read += READ_FN( disk_image, data, 2); -#endif - ret_value = data[1] << 8 | - data[0]; - } - currLBA += 2; - } - else { - unsigned char *p; - int i; - u32 cluster,cluster2,cluster3,fileLBA; - cluster = (currLBA / (512 * SECPERCLUS)); - cluster2 = (((currLBA/512) - filesysData) / SECPERCLUS) + 2; - - // Reading from the MBR - if (currLBA < 512) { - p = (unsigned char*)&MBR; - ret_value = T1ReadWord(p, currLBA); - - // Reading the FAT - } else if (((u32)currLBA >= filesysFAT*512) && ((u32)currLBA < filesysRootDir*512)) { - p = (unsigned char*)&FAT16[0]; - ret_value = T1ReadWord(p, currLBA - filesysFAT * 512); - - // Reading directory entries - } else if (((u32)currLBA >= filesysRootDir*512) && - (cluster <= (u32)lastDirEntCluster)) { - cluster3 = ((currLBA - (SECRESV * 512)) / (512 * SECPERCLUS)); - i = (currLBA-(((cluster3-(filesysRootDir/SECPERCLUS))*SECPERCLUS+filesysRootDir)*512)); //(currLBA - cluster*BYTESPERCLUS); - if (i < (dirEntriesInCluster[cluster3]*32)) { - - p = (unsigned char*)dirEntryPtr[cluster3]; - ret_value = T1ReadWord(p, i); - } else { - i /= 32; - i -= dirEntriesInCluster[cluster3]; - if ((i>=0)&&(i (u32)lastDirEntCluster) && (cluster2 <= (u32)lastFileDataCluster)) { //else if ((cluster>lastDirEntCluster)&&(cluster<=lastFileDataCluster)) { - fileLBA = currLBA - (filesysData-32)*512; // 32 = # sectors used for the root entries - - // Check if the read is from the currently opened file - if ((fileLBA >= fileStartLBA) && (fileLBA < fileEndLBA)) { - cluster = (fileLBA / (512 * SECPERCLUS)); - ret_value = fread_buffered(activeDirEnt,cluster-dirEntries[activeDirEnt].startCluster,(fileLBA-fileStartLBA)&(BYTESPERCLUS-1)); - } else { - for (i=0; i=(u32)(dirEntries[i].startCluster*512*SECPERCLUS)) && - (fileLBA <(dirEntries[i].startCluster*512*SECPERCLUS)+dirEntries[i].fileSize) && - ((dirEntries[i].attrib & (ATTRIB_DIR|ATTRIB_LFN))==0)) { - cluster = (fileLBA / (512 * SECPERCLUS)); - ret_value = fread_buffered(i,cluster-dirEntries[i].startCluster,fileLBA&(BYTESPERCLUS-1)); - break; - } - } - } - } - currLBA += 2; - } - } - break; - - case CF_REG_CMD: - break; - - case CF_REG_LBA1: - ret_value = cf_reg_lba1; - break; - } - - return ret_value; -} - -void -cflash_write(unsigned int address,unsigned int data) { - static u8 sector_data[512]; - static u32 sector_write_index = 0; - - switch ( address) { - case CF_REG_STS: - cf_reg_sts = data&0xFFFF; - break; - - case CF_REG_DATA: - if ( use_disk_image_file) { - if (cf_reg_cmd == CF_CMD_WRITE) { - sector_data[sector_write_index] = (data >> 0) & 0xff; - sector_data[sector_write_index + 1] = (data >> 8) & 0xff; - - sector_write_index += 2; - - if ( sector_write_index == 512) { - CFLASHLOG( "Write sector to %ld\n", currLBA); - - if ( currLBA + 512 < file_size) { - size_t written = 0; - - if ( disk_image != -1) { - LSEEK_FN( disk_image, currLBA, SEEK_SET); - - while( written < 512) { - size_t cur_write = - WRITE_FN( disk_image, §or_data[written], 512 - written); - written += cur_write; - - if ( cur_write == (size_t)-1) { - break; - } - } - } - - CFLASHLOG("Wrote %u bytes\n", written); - } - currLBA += 512; - sector_write_index = 0; - } - } - } - break; - - case CF_REG_CMD: - cf_reg_cmd = data&0xFF; - cf_reg_sts = 0x58; // READY - break; - - case CF_REG_LBA1: - cf_reg_lba1 = data&0xFF; - currLBA = (currLBA&0xFFFFFF00)| cf_reg_lba1; - break; - - case CF_REG_LBA2: - cf_reg_lba2 = data&0xFF; - currLBA = (currLBA&0xFFFF00FF)|(cf_reg_lba2<<8); - break; - - case CF_REG_LBA3: - cf_reg_lba3 = data&0xFF; - currLBA = (currLBA&0xFF00FFFF)|(cf_reg_lba3<<16); - break; - - case CF_REG_LBA4: - cf_reg_lba4 = data&0xFF; - - if ( (cf_reg_lba4 & 0xf0) == CF_CMD_LBA) { - currLBA = (currLBA&0x00FFFFFF)|((cf_reg_lba4&0x0F)<<24); - currLBA *= 512; - sector_write_index = 0; - } - break; - } -} - -void -cflash_close( void) { - if ( use_disk_image_file) { - if ( disk_image != -1) { - CLOSE_FN( disk_image); - disk_image = -1; - } - } - else { - int i; - - if (cflashDeviceEnabled) { - cflashDeviceEnabled = FALSE; - - for (i=0; icflash_disk_image_file, "Enable disk image GBAMP compact flash emulation", "PATH_TO_DISK_IMAGE"}, #ifdef HAVE_TIMEOUT { "timeout", 0, 0, G_OPTION_ARG_INT, &config->timeout, "Quit desmume after the specified seconds for testing purpose.", "SECONDS"}, #endif @@ -578,14 +573,10 @@ static void ToggleStatusbarVisible(GtkToggleAction *action) -static int Open(const char *filename, const char *cflash_disk_image) +static int Open(const char *filename) { int res; -#ifdef EXPERIMENTAL_GBASLOT res = NDS_LoadROM( filename ); -#else - res = NDS_LoadROM( filename, cflash_disk_image ); -#endif if(res > 0) gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "cheatlist"), TRUE); return res; @@ -897,7 +888,7 @@ static void OpenNdsDialog() switch(gtk_dialog_run(GTK_DIALOG(pFileSelection))) { case GTK_RESPONSE_OK: sPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(pFileSelection)); - if(Open((const char*)sPath, bad_glob_cflash_disk_image_file) < 0) { + if(Open((const char*)sPath) < 0) { GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pFileSelection), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, @@ -1740,12 +1731,14 @@ common_gtk_main( struct configured_features *my_config) fw_config.language = my_config->firmware_language; } -#ifdef EXPERIMENTAL_GBASLOT - addon_type = NDS_ADDON_CFLASH; - if (my_config->cflash_disk_image_file != NULL) { - strncpy(CFlashName, my_config->cflash_disk_image_file, MAX_PATH); - } + //------------------addons---------- + my_config->process_addonCommands(); + addon_type = NDS_ADDON_NONE; + if(my_config->is_cflash_configured) + addon_type = NDS_ADDON_CFLASH; + + printf("addon_type: %d\n",addon_type); switch (addon_type) { case NDS_ADDON_CFLASH: case NDS_ADDON_RUMBLEPAK: @@ -1757,9 +1750,6 @@ common_gtk_main( struct configured_features *my_config) break; } addonsChangePak (addon_type); -#else - bad_glob_cflash_disk_image_file = my_config->cflash_disk_image_file; -#endif #ifdef GDB_STUB if ( my_config->arm9_gdb_port != 0) { @@ -1920,11 +1910,9 @@ common_gtk_main( struct configured_features *my_config) } } - /* - * Set the 3D emulation to use - */ + //Set the 3D emulation to use unsigned core = my_config->engine_3d; - /* setup the gdk 3D emulation; */ + // setup the gdk 3D emulation; #if defined(HAVE_LIBOSMESA) if(my_config->engine_3d == 2){ core = init_osmesa_3Demu() ? 2 : GPU3D_NULL; @@ -1938,9 +1926,9 @@ common_gtk_main( struct configured_features *my_config) backup_setManualBackupType(my_config->savetype); - /* Command line arg */ + // Command line arg if( my_config->nds_file != "") { - if(Open( my_config->nds_file.c_str(), my_config->cflash_disk_image_file) >= 0) { + if(Open( my_config->nds_file.c_str()) >= 0) { my_config->process_movieCommands(); if(my_config->load_slot){ diff --git a/desmume/src/windows/DeSmuME_2005.vcproj b/desmume/src/windows/DeSmuME_2005.vcproj index 3f05ead4b..74d43851e 100644 --- a/desmume/src/windows/DeSmuME_2005.vcproj +++ b/desmume/src/windows/DeSmuME_2005.vcproj @@ -1,4 +1,4 @@ - + - - - - diff --git a/desmume/src/windows/DeSmuME_2008.vcproj b/desmume/src/windows/DeSmuME_2008.vcproj index 52395a9f3..bb2eac60e 100644 --- a/desmume/src/windows/DeSmuME_2008.vcproj +++ b/desmume/src/windows/DeSmuME_2008.vcproj @@ -1,4 +1,4 @@ - + - - @@ -1007,10 +1003,6 @@ RelativePath="..\bits.h" > - - diff --git a/desmume/src/windows/DeSmuME_2010.vcxproj b/desmume/src/windows/DeSmuME_2010.vcxproj index 48934086d..5b37b3392 100644 --- a/desmume/src/windows/DeSmuME_2010.vcxproj +++ b/desmume/src/windows/DeSmuME_2010.vcxproj @@ -189,7 +189,6 @@ - Cdecl @@ -300,7 +299,6 @@ - diff --git a/desmume/src/windows/gbaslot_config.cpp b/desmume/src/windows/gbaslot_config.cpp index e170cb276..6260e9c7a 100644 --- a/desmume/src/windows/gbaslot_config.cpp +++ b/desmume/src/windows/gbaslot_config.cpp @@ -41,6 +41,8 @@ u8 tmp_CFlashUseRomPath; HWND OKbutton = NULL; bool _OKbutton = false; +std::string CFlashPath, CFlashName; + BOOL CALLBACK GbaSlotNone(HWND dialog, UINT msg,WPARAM wparam,LPARAM lparam) { switch(msg) @@ -398,11 +400,11 @@ void GBAslotDialog(HWND hwnd) { temp_type = addon_type; last_type = temp_type; - strcpy(tmp_cflash_filename, CFlashName); - strcpy(tmp_cflash_path, CFlashPath); + strcpy(tmp_cflash_filename, CFlashName.c_str()); + strcpy(tmp_cflash_path, CFlashPath.c_str()); strcpy(tmp_gbagame_filename, GBAgameName); - tmp_CFlashUseRomPath = CFlashUseRomPath; - tmp_CFlashUsePath = CFlashUsePath; + tmp_CFlashUseRomPath = (CFlash_Mode==ADDON_CFLASH_MODE_RomPath); + tmp_CFlashUsePath = (CFlash_Mode==ADDON_CFLASH_MODE_Path); _OKbutton = false; u32 res=DialogBox(hAppInst, MAKEINTRESOURCE(IDD_GBASLOT), hwnd, (DLGPROC) GbaSlotBox_Proc); if (res) @@ -412,22 +414,22 @@ void GBAslotDialog(HWND hwnd) case NDS_ADDON_NONE: break; case NDS_ADDON_CFLASH: - CFlashUsePath = tmp_CFlashUsePath; - WritePrivateProfileInt("GBAslot.CFlash","usePath",CFlashUsePath,IniName); + if(tmp_CFlashUsePath) CFlash_Mode=ADDON_CFLASH_MODE_Path; + WritePrivateProfileInt("GBAslot.CFlash","usePath",tmp_CFlashUsePath,IniName); if (tmp_CFlashUsePath) { if (tmp_CFlashUseRomPath) { - CFlashUseRomPath = tmp_CFlashUseRomPath; - WritePrivateProfileInt("GBAslot.CFlash","useRomPath",CFlashUseRomPath,IniName); + CFlash_Mode=ADDON_CFLASH_MODE_RomPath; + WritePrivateProfileInt("GBAslot.CFlash","useRomPath",tmp_CFlashUseRomPath,IniName); break; } - strcpy(CFlashPath, tmp_cflash_path); - WritePrivateProfileString("GBAslot.CFlash","path",CFlashPath,IniName); + CFlashPath = tmp_cflash_path; + WritePrivateProfileString("GBAslot.CFlash","path",tmp_cflash_path,IniName); break; } - strcpy(CFlashName, tmp_cflash_filename); - WritePrivateProfileString("GBAslot.CFlash","filename",CFlashName,IniName); + CFlashName = tmp_cflash_filename; + WritePrivateProfileString("GBAslot.CFlash","filename",tmp_cflash_filename,IniName); break; case NDS_ADDON_RUMBLEPAK: break; @@ -439,6 +441,15 @@ void GBAslotDialog(HWND hwnd) return; } WritePrivateProfileInt("GBAslot","type",temp_type,IniName); + + if(CFlash_Mode == ADDON_CFLASH_MODE_Path) + CFlash_Path = CFlashPath; + else if(CFlash_Mode == ADDON_CFLASH_MODE_RomPath) + CFlash_Path = ""; + else + CFlash_Path = CFlashName; + + addon_type = temp_type; addonsChangePak(addon_type); if (romloaded) diff --git a/desmume/src/windows/gbaslot_config.h b/desmume/src/windows/gbaslot_config.h index 9d9de875a..59f1092a0 100644 --- a/desmume/src/windows/gbaslot_config.h +++ b/desmume/src/windows/gbaslot_config.h @@ -21,6 +21,10 @@ #ifndef __GBASLOT_CONFIG_H_ #define __GBASLOT_CONFIG_H_ #include "../common.h" +#include + +extern std::string CFlashPath, CFlashName; extern void GBAslotDialog(HWND hwnd); + #endif diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index 0487bbd8b..f6f882626 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -41,11 +41,7 @@ #include "../NDSSystem.h" #include "../debug.h" #include "../saves.h" -#ifndef EXPERIMENTAL_GBASLOT -#include "../cflash.h" -#else #include "../addons.h" -#endif #include "resource.h" #include "memView.h" #include "disView.h" @@ -172,12 +168,6 @@ LPDIRECTDRAWCLIPPER lpDDClipBack=NULL; #define WM_CUSTKEYDOWN (WM_USER+50) #define WM_CUSTKEYUP (WM_USER+51) -#ifndef EXPERIMENTAL_GBASLOT -/* The compact flash disk image file */ -static const char *bad_glob_cflash_disk_image_file; -static char cflash_filename_buffer[512]; -#endif - /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); @@ -497,100 +487,6 @@ VOID CALLBACK KeyInputTimer( UINT idEvent, UINT uMsg, DWORD_PTR dwUser, DWORD_PT // } } -//static void -//init_configured_features( struct configured_features *config) { -// config->arm9_gdb_port = 0; -// config->arm7_gdb_port = 0; -// -// config->cflash_disk_image_file = NULL; -//} -// -// -//static int -//fill_configured_features( struct configured_features *config, LPSTR lpszArgument) { -// int good_args = 0; -// LPTSTR cmd_line; -// LPWSTR *argv; -// int argc; -// -// argv = CommandLineToArgvW( GetCommandLineW(), &argc); -// -// if ( argv != NULL) { -// int i; -// good_args = 1; -// for ( i = 1; i < argc && good_args; i++) { -// if ( wcsncmp( argv[i], L"--arm9gdb=", 10) == 0) { -// wchar_t *end_char; -// unsigned long port_num = wcstoul( &argv[i][10], &end_char, 10); -// -// if ( port_num > 0 && port_num < 65536) { -// config->arm9_gdb_port = port_num; -// } -// else { -// MessageBox(NULL,"ARM9 GDB stub port must be in the range 1 to 65535","Error",MB_OK); -// good_args = 0; -// } -// } -// else if ( wcsncmp( argv[i], L"--arm7gdb=", 10) == 0) { -// wchar_t *end_char; -// unsigned long port_num = wcstoul( &argv[i][10], &end_char, 10); -// -// if ( port_num > 0 && port_num < 65536) { -// config->arm7_gdb_port = port_num; -// } -// else { -// MessageBox(NULL,"ARM9 GDB stub port must be in the range 1 to 65535","Error",MB_OK); -// good_args = 0; -// } -// } -// -//#ifdef EXPERIMENTAL_GBASLOT -// else if ( wcsncmp( argv[i], L"--cflash=", 9) == 0) -// { -// char buf[512]; -// size_t convert_count = wcstombs(&buf[0], &argv[i][9], 512); -// if (convert_count > 0) -// { -// addon_type = NDS_ADDON_CFLASH; -// CFlashUsePath = FALSE; -// strcpy(CFlashName, buf); -// } -// } -// else if ( wcsncmp( argv[i], L"--gbagame=", 10) == 0) -// { -// char buf[512]; -// size_t convert_count = wcstombs(&buf[0], &argv[i][9], 512); -// if (convert_count > 0) -// { -// addon_type = NDS_ADDON_GBAGAME; -// strcpy(GBAgameName, buf); -// } -// } -// else if ( wcsncmp( argv[i], L"--rumble", 8) == 0) -// { -// addon_type = NDS_ADDON_RUMBLEPAK; -// } -//#else -// else if ( wcsncmp( argv[i], L"--cflash=", 9) == 0) { -// if ( config->cflash_disk_image_file == NULL) { -// size_t convert_count = wcstombs( &cflash_filename_buffer[0], &argv[i][9], 512); -// if ( convert_count > 0) { -// config->cflash_disk_image_file = cflash_filename_buffer; -// } -// } -// else { -// MessageBox(NULL,"CFlash disk image file already set","Error",MB_OK); -// good_args = 0; -// } -// } -//#endif -// } -// LocalFree( argv); -// } -// -// return good_args; -//} - // Rotation definitions short GPU_rotation = 0; DWORD GPU_width = 256; @@ -1368,21 +1264,13 @@ void LoadSaveStateInfo() -#ifdef EXPERIMENTAL_GBASLOT static BOOL LoadROM(const char * filename) -#else -static BOOL LoadROM(const char * filename, const char *cflash_disk_image) -#endif { ResetSaveStateTimes(); NDS_Pause(); //if (strcmp(filename,"")!=0) INFO("Attempting to load ROM: %s\n",filename); -#ifdef EXPERIMENTAL_GBASLOT if (NDS_LoadROM(filename) > 0) -#else - if (NDS_LoadROM(filename, cflash_disk_image) > 0) -#endif { INFO("Loading %s was successful\n",filename); LoadSaveStateInfo(); @@ -1567,6 +1455,12 @@ class WinDriver : public BaseDriver } }; +std::string GetPrivateProfileStdString(LPCSTR lpAppName,LPCSTR lpKeyName,LPCSTR lpDefault) +{ + static char buf[65536]; + GetPrivateProfileString(lpAppName, lpKeyName, lpDefault, buf, 65536, IniName); + return buf; +} int _main() { @@ -1596,39 +1490,27 @@ int _main() char text[80]; GetINIPath(); -#ifdef EXPERIMENTAL_GBASLOT + addon_type = GetPrivateProfileInt("GBAslot", "type", NDS_ADDON_NONE, IniName); - CFlashUsePath = GetPrivateProfileInt("GBAslot.CFlash", "usePath", 1, IniName); - CFlashUseRomPath = GetPrivateProfileInt("GBAslot.CFlash", "useRomPath", 1, IniName); - GetPrivateProfileString("GBAslot.CFlash", "path", "", CFlashPath, MAX_PATH, IniName); - GetPrivateProfileString("GBAslot.CFlash", "filename", "", CFlashName, MAX_PATH, IniName); + UINT CFlashUsePath = GetPrivateProfileInt("GBAslot.CFlash", "usePath", 1, IniName); + UINT CFlashUseRomPath = GetPrivateProfileInt("GBAslot.CFlash", "useRomPath", 1, IniName); + + CFlashPath = GetPrivateProfileStdString("GBAslot.CFlash", "path", ""); + CFlashName = GetPrivateProfileStdString("GBAslot.CFlash", "filename", ""); GetPrivateProfileString("GBAslot.GBAgame", "filename", "", GBAgameName, MAX_PATH, IniName); - switch (addon_type) - { - case NDS_ADDON_NONE: - break; - case NDS_ADDON_CFLASH: - if (!strlen(CFlashPath)) CFlashUseRomPath = TRUE; - if (!strlen(CFlashName)) CFlashUsePath = TRUE; - // TODO: check for file exist - break; - case NDS_ADDON_RUMBLEPAK: - break; - case NDS_ADDON_GBAGAME: - if (!strlen(GBAgameName)) - { - addon_type = NDS_ADDON_NONE; - break; - } - // TODO: check for file exist - break; - default: - addon_type = NDS_ADDON_NONE; - break; + if(CFlashUsePath) { + CFlash_Mode = ADDON_CFLASH_MODE_Path; + CFlash_Path = CFlashPath; } - addonsChangePak(addon_type); -#endif + else if(CFlashUseRomPath) { + CFlash_Mode = ADDON_CFLASH_MODE_RomPath; + } else { + CFlash_Path = CFlashName; + CFlash_Mode = ADDON_CFLASH_MODE_RomPath; + } + + //init_configured_features( &my_config); /*if ( !fill_configured_features( &my_config, lpszArgument)) { @@ -1700,14 +1582,8 @@ int _main() GetPrivateProfileString("General", "Language", "0", text, 80, IniName); SetLanguage(atoi(text)); -#ifndef EXPERIMENTAL_GBASLOT - bad_glob_cflash_disk_image_file = my_config.cflash_disk_image_file; -#endif - //hAccel = LoadAccelerators(hAppInst, MAKEINTRESOURCE(IDR_MAIN_ACCEL)); //Now that we have a hotkey system we down need the Accel table. Not deleting just yet though - - if(MenuInit() == 0) { MessageBox(NULL, "Error creating main menu", "DeSmuME", MB_OK); @@ -1739,10 +1615,6 @@ int _main() DragAcceptFiles(MainWindow->getHWnd(), TRUE); -#ifndef EXPERIMENTAL_GBASLOT - EnableMenuItem(mainMenu, IDM_GBASLOT, MF_GRAYED); -#endif - #ifdef EXPERIMENTAL_WIFI EnableMenuItem(mainMenu, IDM_WIFISETTINGS, MF_ENABLED); #endif @@ -1773,6 +1645,41 @@ int _main() ViewMatrices = new TOOLSCLASS(hAppInst, IDD_MATRIX_VIEWER, (DLGPROC) ViewMatricesProc); ViewLights = new TOOLSCLASS(hAppInst, IDD_LIGHT_VIEWER, (DLGPROC) ViewLightsProc); + + cmdline.process_addonCommands(); + if(cmdline.is_cflash_configured) + { + addon_type = NDS_ADDON_CFLASH; + //push the commandline-provided options into the current config slots + if(CFlash_Mode == ADDON_CFLASH_MODE_Path) + CFlashPath = CFlash_Path; + else + CFlashName = CFlash_Path; + } + + + switch (addon_type) + { + case NDS_ADDON_NONE: + break; + case NDS_ADDON_CFLASH: + break; + case NDS_ADDON_RUMBLEPAK: + break; + case NDS_ADDON_GBAGAME: + if (!strlen(GBAgameName)) + { + addon_type = NDS_ADDON_NONE; + break; + } + // TODO: check for file exist + break; + default: + addon_type = NDS_ADDON_NONE; + break; + } + addonsChangePak(addon_type); + #ifdef GDB_STUB if ( cmdline.arm9_gdb_port != 0) { arm9_gdb_stub = createStub_gdb( cmdline.arm9_gdb_port, @@ -1910,11 +1817,7 @@ int _main() if (cmdline.nds_file != "") { -#ifdef EXPERIMENTAL_GBASLOT if(LoadROM(cmdline.nds_file.c_str())) -#else - if(LoadROM(cmdline.nds_file.c_str(), bad_glob_cflash_disk_image_file)) -#endif { romloaded = TRUE; if(!cmdline.start_paused) @@ -2384,11 +2287,7 @@ void OpenRecentROM(int listNum) char filename[MAX_PATH]; strcpy(filename, RecentRoms[listNum].c_str()); //LOG("Attempting to load %s\n",filename); -#ifdef EXPERIMENTAL_GBASLOT if(LoadROM(filename)) -#else - if(LoadROM(filename, bad_glob_cflash_disk_image_file)) -#endif { romloaded = TRUE; } @@ -2508,11 +2407,7 @@ LRESULT OpenFile() // } //LOG("%s\r\n", filename); -#ifdef EXPERIMENTAL_GBASLOT if(LoadROM(PhysicalName)) -#else - if(LoadROM(filename, bad_glob_cflash_disk_image_file)) -#endif { romloaded = TRUE; NDS_UnPause(); @@ -2963,11 +2858,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM char filename[MAX_PATH] = ""; DragQueryFile((HDROP)wParam,0,filename,MAX_PATH); DragFinish((HDROP)wParam); -#ifdef EXPERIMENTAL_GBASLOT if(LoadROM(filename)) -#else - if(LoadROM(filename, bad_glob_cflash_disk_image_file)) -#endif { romloaded = TRUE; }