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).

This commit is contained in:
zeromus 2009-07-01 05:51:42 +00:00
parent 5a0f4d989a
commit 2b83987056
25 changed files with 230 additions and 1398 deletions

View File

@ -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*)

View File

@ -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<ARMCPU_ARM9>(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;

View File

@ -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 \

View File

@ -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);

View File

@ -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);

View File

@ -1,3 +1,3 @@
#if defined(_MSC_VER) || defined(__INTEL_COMPILER)
#ifndef __GNUC__
#pragma pack(pop)
#endif

View File

@ -23,11 +23,16 @@
*/
#include "addons.h"
#include <string>
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];

View File

@ -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

View File

@ -24,9 +24,8 @@
*/
#include "../addons.h"
#include <string>
#include <string.h>
#ifdef EXPERIMENTAL_GBASLOT
#include "debug.h"
#include <errno.h>
#include <stdio.h>
@ -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",

View File

@ -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 <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#ifdef WIN32
#include <io.h>
#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 <unistd.h>
#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<i; j++)
files[numFiles].name[j] = fname[j];
for (; j<NAME_LEN; j++)
files[numFiles].name[j] = 0x20;
for (j=0; j<EXT_LEN; j++) {
if ((size_t)(j+i+1)>=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)i<strlen(entry->cFileName); 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<i; j++)
files[numFiles].name[j] = fname[j];
for (; j<NAME_LEN; j++)
files[numFiles].name[j] = 0x20;
for (j=0; j<EXT_LEN; j++) {
if ((size_t)(j+i+1)>=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<MAXFILES; i++) {
files[i].attrib = 0;
files[i].name[0] = FILE_FREE;
files[i].fileSize = 0;
fileLink[i].filesInDir = 0;
extraDirEntries[i] = NULL;
numExtraEntries[i] = 0;
}
//COMMENT OUT THIS LINE TO STOP THE IRRITATING FILESYSTEM SCANNING BEHAVIOR
list_files(sRomPath);
k = 0;
clusterNum = rootCluster = (SECRESV + SECPERFAT)/SECPERCLUS;
numClusters = 0;
clust = 0;
numRootFiles = 0;
// Allocate memory to hold information about the files
dirEntries = (DIR_ENT *) malloc(numFiles*sizeof(DIR_ENT));
if (dirEntries==NULL) {
return FALSE;
}
dirEntryLink = (FILE_INFO *) malloc(numFiles*sizeof(FILE_INFO));
if (dirEntryLink==NULL) {
free(dirEntries);
return FALSE;
}
dirEntriesInCluster = (int *) malloc(NUMCLUSTERS*sizeof(int));
if (dirEntriesInCluster==NULL) {
free(dirEntries);
free(dirEntryLink);
return FALSE;
}
dirEntryPtr = (DIR_ENT **) malloc(NUMCLUSTERS*sizeof(DIR_ENT*));
if (dirEntryPtr==NULL) {
free(dirEntries);
free(dirEntryLink);
free(dirEntriesInCluster);
return FALSE;
}
memset(dirEntriesInCluster, 0, NUMCLUSTERS*sizeof(int));
memset(dirEntryPtr, NULL, NUMCLUSTERS*sizeof(DIR_ENT*));
// Change the hierarchical layout to a flat one
for (i=0; i<=maxLevel; i++) {
clusterNum2 = clusterNum;
for (j=0; j<numFiles; j++) {
if (fileLink[j].parent == i) {
if (dirEntryPtr[clusterNum] == NULL)
dirEntryPtr[clusterNum] = &dirEntries[k];
dirEntryLink[k] = fileLink[j];
dirEntries[k++] = files[j];
if ((files[j].attrib & ATTRIB_LFN)==0) {
if (files[j].attrib & ATTRIB_DIR) {
if (strncmp((char*)&files[j].name[0],". ",NAME_LEN)==0) {
dirEntries[k-1].startCluster = dirEntryLink[k-1].level;
} else if (strncmp((char*)&files[j].name[0],".. ",NAME_LEN)==0) {
dirEntries[k-1].startCluster = dirEntryLink[k-1].parent;
} else {
clust++;
dirEntries[k-1].startCluster = clust;
l = (fileLink[fileLink[j].level].filesInDir)>>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<numFiles; i++) {
if (((dirEntries[i].attrib & ATTRIB_DIR)!=0) &&
((dirEntries[i].attrib & ATTRIB_LFN)==0)) {
if (dirEntries[i].startCluster > 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<numFiles; i++) {
if (((dirEntries[i].attrib & ATTRIB_DIR)==0) &&
((dirEntries[i].attrib & ATTRIB_LFN)==0)) {
dirEntries[i].startCluster = clust;
clust += (dirEntries[i].fileSize/(512*SECPERCLUS));
clust++;
}
}
lastFileDataCluster = clust-1;
// Set up the FAT16
memset(FAT16,0,SECPERFAT*256*sizeof(u16));
FAT16[0] = 0xFF01;
FAT16[1] = 0xFFFF;
for (i=2; i<=lastDirEntCluster; i++)
FAT16[i] = 0xFFFF;
k = 2;
for (i=0; i<numFiles; i++) {
if (((dirEntries[i].attrib & ATTRIB_LFN)==0) &&
(dirEntries[i].name[0] != FILE_FREE)) {
j = 0;
l = dirEntries[i].fileSize - (512*SECPERCLUS);
while (l > 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); i<NUMCLUSTERS; i++) {
if (dirEntriesInCluster[i]==256)
FAT16[i] = i+1;
}
return TRUE;
}
BOOL
cflash_init( const char *disk_image_filename) {
BOOL init_good = FALSE;
if ( disk_image_filename != NULL) {
CFLASHLOG("Using CFlash disk image file %s\n", disk_image_filename);
use_disk_image_file = 1;
disk_image = OPEN_FN( disk_image_filename, OPEN_MODE);
if ( disk_image != -1) {
file_size = LSEEK_FN( disk_image, 0, SEEK_END);
if (0 && file_size == -1) {
CFLASHLOG( "Error when seeking to end of disk image" );
} else {
LSEEK_FN( disk_image, 0, SEEK_SET);
CFLASHLOG( "Disk image size = %ld (%ld sectors)\n",
file_size, file_size / 512);
init_good = TRUE;
}
}
else {
CFLASHLOG("Failed to open file %s: \"%s\"\n",
disk_image_filename,
strerror( errno));
}
}
else {
cflashDeviceEnabled = FALSE;
currLBA = 0;
if (activeDirEnt != -1)
fclose(hFile);
activeDirEnt = -1;
fileStartLBA = fileEndLBA = 0xFFFFFFFF;
if (!cflash_build_fat())
return FALSE;
cf_reg_sts = 0x58; // READY
cflashDeviceEnabled = TRUE;
init_good = TRUE;
}
// READY
cf_reg_sts = 0x58;
currLBA = 0;
cf_reg_lba1 = cf_reg_lba2 =
cf_reg_lba3 = cf_reg_lba4 = 0;
return init_good;
}
/* Convert a space-padded 8.3 filename into an asciiz string */
static void fatstring_to_asciiz(int dirent,char *out,DIR_ENT *d) {
int i,j;
DIR_ENT *pd;
if (d == NULL)
pd = &dirEntries[dirent];
else
pd = d;
for (i=0; i<NAME_LEN; i++) {
if (pd->name[i] == ' ') break;
out[i] = pd->name[i];
}
if ((pd->attrib & 0x10)==0) {
out[i++] = '.';
for (j=0; j<EXT_LEN; j++) {
if (pd->ext[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<dirent; i++) {
if ((dirEntryLink[dirent].parent==dirEntryLink[i].level) &&
((dirEntries[i].attrib&ATTRIB_DIR)!=0)) {
fatstring_to_asciiz(i,dirname,NULL);
strncat(fpath,dirname,ARRAY_SIZE(fpath)-strlen(fpath));
strncat(fpath,DIR_SEP,ARRAY_SIZE(fpath)-strlen(fpath));
dirent = i;
break;
}
}
}
}
/* Read from a file using a 512 byte buffer */
static u16 fread_buffered(int dirent,u32 cluster,u32 offset) {
char fname[2*NAME_LEN+EXT_LEN];
size_t elems_read = 0;
offset += cluster*512*SECPERCLUS;
if (dirent == activeDirEnt) {
if ((offset < bufferStart) || (offset >= 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<numExtraEntries[cluster3])) {
p = (unsigned char*)extraDirEntries[cluster3];
ret_value = T1ReadWord(p, i * 32 + (currLBA & 0x1F));
} else if ((currLBA&0x1F)==0) {
ret_value = FILE_FREE;
} else {
ret_value = 0;
}
}
// Reading file data
} else if ((cluster2 > (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<numFiles; i++) {
if ((fileLBA>=(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, &sector_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; i<MAXFILES; i++) {
if (extraDirEntries[i] != NULL)
free(extraDirEntries[i]);
}
if (dirEntries != NULL)
free(dirEntries);
if (dirEntryLink != NULL)
free(dirEntryLink);
if (dirEntriesInCluster != NULL)
free(dirEntriesInCluster);
if (dirEntryPtr != NULL)
free(dirEntryPtr);
if (activeDirEnt != -1)
fclose(hFile);
}
}
}
#endif

View File

@ -1,28 +0,0 @@
/*
CFLASH.H
Mic, 2006
*/
#ifndef __CFLASH_H__
#define __CFLASH_H__
#include "common.h"
#ifndef EXPERIMENTAL_GBASLOT
#include "fat.h"
typedef struct {
int level,parent,filesInDir;
} FILE_INFO;
BOOL cflash_init( const char *disk_image_filename);
unsigned int cflash_read(unsigned int address);
void cflash_write(unsigned int address,unsigned int data);
void cflash_close( void);
#endif
#endif

View File

@ -46,7 +46,6 @@
#include "../MMU.h"
#include "../NDSSystem.h"
#include "../cflash.h"
#include "../debug.h"
#include "../sndsdl.h"
#include "../ctrlssdl.h"
@ -807,11 +806,7 @@ int main(int argc, char ** argv) {
backup_setManualBackupType(my_config.savetype);
#ifdef EXPERIMENTAL_GBASLOT
error = NDS_LoadROM( my_config.nds_file );
#else
error = NDS_LoadROM( my_config.nds_file, my_config.cflash_disk_image_file );
#endif
if (error < 0) {
fprintf(stderr, "error while loading %s\n", my_config.nds_file);
exit(-1);

View File

@ -27,10 +27,12 @@
#include "commandline.h"
#include "types.h"
#include "movie.h"
#include "addons.h"
CommandLine::CommandLine()
: error(NULL)
, ctx(g_option_context_new (""))
, is_cflash_configured(false)
{
load_slot = 0;
arm9_gdb_port = arm7_gdb_port = 0;
@ -45,6 +47,8 @@ CommandLine::~CommandLine()
static const char* _play_movie_file;
static const char* _record_movie_file;
static const char* _cflash_image;
static const char* _cflash_path;
void CommandLine::loadCommonOptions()
{
@ -57,6 +61,8 @@ void CommandLine::loadCommonOptions()
{ "play-movie", 0, 0, G_OPTION_ARG_FILENAME, &_play_movie_file, "Specifies a dsm format movie to play", "PATH_TO_PLAY_MOVIE"},
{ "record-movie", 0, 0, G_OPTION_ARG_FILENAME, &_record_movie_file, "Specifies a path to a new dsm format movie", "PATH_TO_RECORD_MOVIE"},
{ "start-paused", 0, 0, G_OPTION_ARG_NONE, &start_paused, "Indicates that emulation should start paused", "START_PAUSED"},
{ "cflash-image", 0, 0, G_OPTION_ARG_FILENAME, &_cflash_image, "Requests cflash in gbaslot with fat image at this path", "CFLASH_IMAGE"},
{ "cflash-path", 0, 0, G_OPTION_ARG_FILENAME, &_cflash_path, "Requests cflash in gbaslot with filesystem rooted at this path", "CFLASH_PATH"},
#ifdef GDB_STUB
{ "arm9gdb", 0, 0, G_OPTION_ARG_INT, &arm9_gdb_port, "Enable the ARM9 GDB stub on the given port", "PORT_NUM"},
{ "arm7gdb", 0, 0, G_OPTION_ARG_INT, &arm7_gdb_port, "Enable the ARM7 GDB stub on the given port", "PORT_NUM"},
@ -78,6 +84,9 @@ bool CommandLine::parse(int argc,char **argv)
if(_play_movie_file) play_movie_file = _play_movie_file;
if(_record_movie_file) record_movie_file = _record_movie_file;
if(_cflash_image) cflash_image = _cflash_image;
if(_cflash_path) cflash_path = _cflash_path;
if (argc == 2)
nds_file = argv[1];
@ -104,6 +113,11 @@ bool CommandLine::validate()
return false;
}
if(cflash_path != "" && cflash_image != "") {
g_printerr("Cannot specify both cflash-image and cflash-path.\n");
return false;
}
return true;
}
@ -125,3 +139,21 @@ void CommandLine::process_movieCommands()
FCEUI_SaveMovie(record_movie_file.c_str(), L"", 0, NULL);
}
}
void CommandLine::process_addonCommands()
{
if (cflash_image != "")
{
CFlash_Mode = ADDON_CFLASH_MODE_File;
CFlash_Path = cflash_image;
is_cflash_configured = true;
}
if (cflash_path != "")
{
CFlash_Mode = ADDON_CFLASH_MODE_Path;
CFlash_Path = cflash_path;
is_cflash_configured = true;
}
}

View File

@ -42,6 +42,8 @@ public:
std::string record_movie_file;
int arm9_gdb_port, arm7_gdb_port;
int start_paused;
std::string cflash_image;
std::string cflash_path;
//load up the common commandline options
void loadCommonOptions();
@ -53,6 +55,9 @@ public:
//process movie play/record commands
void process_movieCommands();
//etc.
void process_addonCommands();
bool is_cflash_configured;
//print a little help message for cases when erroneous commandlines are entered
void errorHelp(const char* binName);

View File

@ -75,7 +75,6 @@ void SetRomName(const char *filename);
extern void GetINIPath();
extern void WritePrivateProfileInt(char* appname, char* keyname, int val, char* file);
#define EXPERIMENTAL_GBASLOT 1
#else // non Windows
#define sscanf_s sscanf

View File

@ -21,43 +21,49 @@
// Boot Sector - must be packed
#if defined(_MSC_VER) || defined(__INTEL_COMPILER)
#pragma pack(push, 1)
#define DIR_SEP "\\"
#else
#define DIR_SEP "/"
#endif
#include "PACKED.h"
typedef struct
{
u8 jmpBoot[3];
u8 OEMName[8];
u8 jmpBoot[3] __PACKED;
u8 OEMName[8] __PACKED;
// BIOS Parameter Block
u16 bytesPerSector;
u8 sectorsPerCluster;
u16 reservedSectors;
u8 numFATs;
u16 rootEntries;
u16 numSectorsSmall;
u8 mediaDesc;
u16 sectorsPerFAT;
u16 sectorsPerTrk;
u16 numHeads;
u32 numHiddenSectors;
u32 numSectors;
u16 bytesPerSector __PACKED;
u8 sectorsPerCluster __PACKED;
u16 reservedSectors __PACKED;
u8 numFATs __PACKED;
u16 rootEntries __PACKED;
u16 numSectorsSmall __PACKED;
u8 mediaDesc __PACKED;
u16 sectorsPerFAT __PACKED;
u16 sectorsPerTrk __PACKED;
u16 numHeads __PACKED;
u32 numHiddenSectors __PACKED;
u32 numSectors __PACKED;
struct
{
// Ext BIOS Parameter Block for FAT16
u8 driveNumber;
u8 reserved1;
u8 extBootSig;
u32 volumeID;
u8 volumeLabel[11];
u8 fileSysType[8];
u8 driveNumber __PACKED;
u8 reserved1 __PACKED;
u8 extBootSig __PACKED;
u32 volumeID __PACKED;
u8 volumeLabel[11] __PACKED;
u8 fileSysType[8] __PACKED;
// Bootcode
u8 bootCode[448];
u16 signature;
} fat16;
u8 bootCode[448] __PACKED;
u16 signature __PACKED;
} __PACKED fat16;
} __PACKED BOOT_RECORD;
#pragma pack(pop)
#include "PACKED_END.h"
// Directory entry - must be packed
#pragma pack(push, 1)
#include "PACKED.h"
typedef struct
{
u8 name[NAME_LEN];
@ -74,58 +80,6 @@ typedef struct
u16 startCluster;
u32 fileSize;
} __PACKED DIR_ENT;
#pragma pack(pop)
#else
#define DIR_SEP "/"
typedef struct
{
u8 jmpBoot[3];
u8 OEMName[8];
// BIOS Parameter Block
u16 bytesPerSector;
u8 sectorsPerCluster;
u16 reservedSectors;
u8 numFATs;
u16 rootEntries;
u16 numSectorsSmall;
u8 mediaDesc;
u16 sectorsPerFAT;
u16 sectorsPerTrk;
u16 numHeads;
u32 numHiddenSectors;
u32 numSectors;
struct
{
// Ext BIOS Parameter Block for FAT16
u8 driveNumber;
u8 reserved1;
u8 extBootSig;
u32 volumeID;
u8 volumeLabel[11];
u8 fileSysType[8];
// Bootcode
u8 bootCode[448];
u16 signature;
} fat16;
} __PACKED BOOT_RECORD;
#include "PACKED_END.h"
// Directory entry - must be packed
typedef struct
{
u8 name[NAME_LEN];
u8 ext[EXT_LEN];
u8 attrib;
u8 reserved;
u8 cTime_ms;
u16 cTime;
u16 cDate;
u16 aDate;
u16 startClusterHigh;
u16 mTime;
u16 mDate;
u16 startCluster;
u32 fileSize;
} __PACKED DIR_ENT;
#endif
#endif
#endif //

View File

@ -63,11 +63,7 @@ int desmume_open(const char *filename)
int i;
noticed_3D=FALSE;
clear_savestates();
#ifdef EXPERIMENTAL_GBASLOT
i = NDS_LoadROM(filename);
#else
i = NDS_LoadROM(filename, NULL);
#endif
return i;
}

View File

@ -86,7 +86,6 @@ typedef union _callback_arg{
#include "../registers.h"
#include "../armcpu.h"
#include "../NDSSystem.h"
#include "../cflash.h"
#include "../sndsdl.h"
#include "../ctrlssdl.h"
#include "../types.h"

View File

@ -49,9 +49,7 @@
#include "commandline.h"
#ifdef EXPERIMENTAL_GBASLOT
#include "addons.h"
#endif
#ifdef GDB_STUB
#include "gdbstub.h"
@ -72,8 +70,6 @@
#define HAVE_TIMEOUT 1
#endif
static const char *bad_glob_cflash_disk_image_file;
#define SCREENS_PIXEL_SIZE (256*192*2)
#define SCREEN_BYTES_PER_PIXEL 3
#define GAP_SIZE 50
@ -425,7 +421,6 @@ fill_configured_features( struct configured_features *config,
"\t\t\t\t 4 = Italian\n"
"\t\t\t\t 5 = Spanish\n",
"LANG"},
{ "cflash", 0, 0, G_OPTION_ARG_FILENAME, &config->cflash_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){

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="Windows-1252"?>
<?xml version="1.0" encoding="shift_jis"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
@ -798,14 +798,6 @@
RelativePath="..\bits.h"
>
</File>
<File
RelativePath="..\cflash.cpp"
>
</File>
<File
RelativePath="..\cflash.h"
>
</File>
<File
RelativePath="..\cheatSystem.cpp"
>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="Windows-1252"?>
<?xml version="1.0" encoding="shift_jis"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
@ -321,10 +321,6 @@
RelativePath="..\bios.cpp"
>
</File>
<File
RelativePath="..\cflash.cpp"
>
</File>
<File
RelativePath="..\cheatSystem.cpp"
>
@ -1007,10 +1003,6 @@
RelativePath="..\bits.h"
>
</File>
<File
RelativePath="..\cflash.h"
>
</File>
<File
RelativePath="..\cheatSystem.h"
>

View File

@ -189,7 +189,6 @@
<ClCompile Include="..\armcpu.cpp" />
<ClCompile Include="..\arm_instructions.cpp" />
<ClCompile Include="..\bios.cpp" />
<ClCompile Include="..\cflash.cpp" />
<ClCompile Include="..\cheatSystem.cpp" />
<ClCompile Include="..\commandline.cpp">
<CallingConvention Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Cdecl</CallingConvention>
@ -300,7 +299,6 @@
<ClInclude Include="..\arm_instructions.h" />
<ClInclude Include="..\bios.h" />
<ClInclude Include="..\bits.h" />
<ClInclude Include="..\cflash.h" />
<ClInclude Include="..\cheatSystem.h" />
<ClInclude Include="..\commandline.h" />
<ClInclude Include="..\common.h" />

View File

@ -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)

View File

@ -21,6 +21,10 @@
#ifndef __GBASLOT_CONFIG_H_
#define __GBASLOT_CONFIG_H_
#include "../common.h"
#include <string>
extern std::string CFlashPath, CFlashName;
extern void GBAslotDialog(HWND hwnd);
#endif

View File

@ -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;
}