- Clean up GBA Cartridge device code, and also add the ability to have the SRAM file be on a different file path from the ROM file.
- Force Rumble Pak to turn off rumble upon disconnect.
- Fix file path issue when trying to use a disk image file for an MPCF device.
This commit is contained in:
rogerman 2014-01-02 01:29:31 +00:00
parent 38f02e0804
commit e568f8c4fd
9 changed files with 83 additions and 54 deletions

View File

@ -320,51 +320,60 @@ public:
virtual Slot2Info const* info() virtual Slot2Info const* info()
{ {
static Slot2InfoSimple info("GBA cartridge", "GBA cartridge in slot", 0x03); static Slot2InfoSimple info("GBA Cartridge", "GBA cartridge in slot", 0x03);
return &info; return &info;
} }
virtual void connect() virtual void connect()
{ {
Close();
romSize = 0;
currentROMPos = 0;
sramSize = 0;
currentSRAMPos = 0;
if (gameInfo.romsize == 0)
{ {
return;
}
if (GBACartridge_RomPath.empty())
{
return;
}
if (!strcasecmp(GBACartridge_RomPath.c_str(), "self"))
{
GBACartridge_RomPath = path.path;
GBACartridge_SRAMPath = Path::GetFileNameWithoutExt(GBACartridge_RomPath) + "." + GBA_SRAM_FILE_EXT;
}
printf("GBASlot opening ROM: %s", GBACartridge_RomPath.c_str());
fROM = new EMUFILE_FILE(GBACartridge_RomPath, "rb");
if (fROM->fail())
{
printf(" - Failed\n");
Close(); Close();
romSize = 0;
currentROMPos = 0;
sramSize = 0;
currentSRAMPos = 0;
if (gameInfo.romsize == 0) return;
if (!strcasecmp(GBAgameName, "self"))
strcpy(GBAgameName, path.path.c_str());
if (!strlen(GBAgameName)) return;
printf("GBASlot opening ROM: %s", GBAgameName); return;
}
fROM = new EMUFILE_FILE(GBAgameName, "rb");
if (fROM->fail()) romSize = fROM->size();
goto FAIL; printf(" - Success (%u bytes)\n", romSize);
romSize = fROM->size(); // Load the GBA cartridge SRAM.
printf(" - Success (%u bytes)\n", romSize); fSRAM = new EMUFILE_FILE(GBACartridge_SRAMPath, "rb+");
if(fSRAM->fail())
//try loading the sram. build the filename from the rom, and expect it to be a .sav {
char *dot = strrchr(GBAgameName, '.'); delete fSRAM;
if(!dot) return; fSRAM = NULL;
printf("GBASlot did not load associated SRAM.\n");
std::string sram_fname = GBAgameName; }
sram_fname.resize(dot-GBAgameName); else
sram_fname += ".sav"; {
fSRAM = new EMUFILE_FILE(sram_fname.c_str(), "rb+");
if(fSRAM->fail())
{
delete fSRAM; fSRAM = NULL;
return;
}
sramSize = fSRAM->size(); sramSize = fSRAM->size();
saveType = getSaveTypeGBA(); saveType = getSaveTypeGBA();
printf("GBASlot found SRAM %s (%s - %u bytes)\n", sram_fname.c_str(), (saveType == 0xFF)?"Unknown":saveTypes[saveType], sramSize); printf("GBASlot found SRAM %s (%s - %u bytes)\n", GBACartridge_SRAMPath.c_str(), (saveType == 0xFF)?"Unknown":saveTypes[saveType], sramSize);
gbaFlash.size = sramSize; gbaFlash.size = sramSize;
if (gbaFlash.size <= (64 * 1024)) if (gbaFlash.size <= (64 * 1024))
{ {
@ -376,14 +385,7 @@ public:
gbaFlash.idDevice = 0x09; gbaFlash.idDevice = 0x09;
gbaFlash.idManufacturer = 0xC2; gbaFlash.idManufacturer = 0xC2;
} }
//success!
return;
} }
FAIL:
Close();
printf(" - Failed\n");
} }
virtual void disconnect() virtual void disconnect()

View File

@ -84,6 +84,15 @@ static BOOL cflash_init()
sFlashPath = CFlash_Path; sFlashPath = CFlash_Path;
INFO("Using CFlash directory: %s\n", sFlashPath.c_str()); INFO("Using CFlash directory: %s\n", sFlashPath.c_str());
} }
else if(CFlash_Mode == ADDON_CFLASH_MODE_File)
{
sFlashPath = CFlash_Path;
INFO("Using CFlash disk image file %s\n", sFlashPath.c_str());
}
else
{
return FALSE;
}
if (sFlashPath == "") return FALSE; if (sFlashPath == "") return FALSE;
@ -112,8 +121,6 @@ static BOOL cflash_init()
} }
else else
{ {
sFlashPath = CFlash_Path;
INFO("Using CFlash disk image file %s\n", sFlashPath.c_str());
file = new EMUFILE_FILE(sFlashPath.c_str(),"rb+"); file = new EMUFILE_FILE(sFlashPath.c_str(),"rb+");
if(file->fail()) if(file->fail())
{ {

View File

@ -38,6 +38,11 @@ public:
if (!FeedbackON) return; if (!FeedbackON) return;
FeedbackON(false); FeedbackON(false);
} }
virtual void disconnect()
{
FeedbackON(false);
}
virtual void writeWord(u8 PROCNUM, u32 addr, u16 val) virtual void writeWord(u8 PROCNUM, u32 addr, u16 val)
{ {

View File

@ -27,8 +27,9 @@ ADDON_CFLASH_MODE CFlash_Mode = ADDON_CFLASH_MODE_RomPath;
//it should be viewed as a parameter for the above. //it should be viewed as a parameter for the above.
std::string CFlash_Path; std::string CFlash_Path;
char GBAgameName[MAX_PATH] = {0}; // GBA file paths for cartridge and SRAM
std::string GBACartridge_RomPath;
std::string GBACartridge_SRAMPath;
ISlot2Interface* slot2_List[NDS_SLOT2_COUNT] = {0}; ISlot2Interface* slot2_List[NDS_SLOT2_COUNT] = {0};
@ -247,7 +248,7 @@ NDS_SLOT2_TYPE slot2_DetermineTypeByGameCode(const char *theGameCode)
{"CB6", NDS_SLOT2_PADDLE}, // Space Bust-A-Move {"CB6", NDS_SLOT2_PADDLE}, // Space Bust-A-Move
{"YXX", NDS_SLOT2_PADDLE}, // Space Invaders Extreme {"YXX", NDS_SLOT2_PADDLE}, // Space Invaders Extreme
{"CV8", NDS_SLOT2_PADDLE}, // Space Invaders Extreme 2 {"CV8", NDS_SLOT2_PADDLE}, // Space Invaders Extreme 2
{"AP2", NDS_SLOT2_RUMBLEPAK}, // Metroid Prime Hunters Pinball {"AP2", NDS_SLOT2_RUMBLEPAK}, // Metroid Prime Pinball
}; };
for(size_t i = 0; i < ARRAY_SIZE(gameCodeDeviceTypes); i++) for(size_t i = 0; i < ARRAY_SIZE(gameCodeDeviceTypes); i++)

View File

@ -22,6 +22,8 @@
#include "types.h" #include "types.h"
#include "debug.h" #include "debug.h"
#define GBA_SRAM_FILE_EXT "sav"
class Slot2Info class Slot2Info
{ {
public: public:
@ -134,7 +136,8 @@ bool slot2_read(u32 addr, T &val);
// ================================================================================= // =================================================================================
extern char GBAgameName[MAX_PATH]; // file name for GBA game (rom) extern std::string GBACartridge_RomPath;
extern std::string GBACartridge_SRAMPath;
extern void (*FeedbackON)(bool enable); // feedback on/off extern void (*FeedbackON)(bool enable); // feedback on/off
enum ADDON_CFLASH_MODE enum ADDON_CFLASH_MODE

View File

@ -43,6 +43,7 @@ SPaddle tmp_Paddle;
//they are named very verbosely to distinguish them from the currently-configured values in addons.cpp //they are named very verbosely to distinguish them from the currently-configured values in addons.cpp
std::string win32_CFlash_cfgDirectory, win32_CFlash_cfgFileName; std::string win32_CFlash_cfgDirectory, win32_CFlash_cfgFileName;
UINT win32_CFlash_cfgMode; UINT win32_CFlash_cfgMode;
std::string win32_GBA_cfgRomPath;
INT_PTR CALLBACK GbaSlotNone(HWND dialog, UINT msg,WPARAM wparam,LPARAM lparam) INT_PTR CALLBACK GbaSlotNone(HWND dialog, UINT msg,WPARAM wparam,LPARAM lparam)
{ {
@ -560,7 +561,7 @@ void GBAslotDialog(HWND hwnd)
last_type = temp_type; last_type = temp_type;
strcpy(tmp_cflash_filename, win32_CFlash_cfgFileName.c_str()); strcpy(tmp_cflash_filename, win32_CFlash_cfgFileName.c_str());
strcpy(tmp_cflash_path, win32_CFlash_cfgDirectory.c_str()); strcpy(tmp_cflash_path, win32_CFlash_cfgDirectory.c_str());
strcpy(tmp_gbagame_filename, GBAgameName); strcpy(tmp_gbagame_filename, win32_GBA_cfgRomPath.c_str());
memcpy(&tmp_Guitar, &Guitar, sizeof(Guitar)); memcpy(&tmp_Guitar, &Guitar, sizeof(Guitar));
memcpy(&tmp_Piano, &Piano, sizeof(Piano)); memcpy(&tmp_Piano, &Piano, sizeof(Piano));
memcpy(&tmp_Paddle, &Paddle, sizeof(Paddle)); memcpy(&tmp_Paddle, &Paddle, sizeof(Paddle));
@ -597,8 +598,9 @@ void GBAslotDialog(HWND hwnd)
WritePrivateProfileInt("Slot2.Paddle","INC",Paddle.INC,IniName); WritePrivateProfileInt("Slot2.Paddle","INC",Paddle.INC,IniName);
break; break;
case NDS_SLOT2_GBACART: case NDS_SLOT2_GBACART:
strcpy(GBAgameName, tmp_gbagame_filename); win32_GBA_cfgRomPath = tmp_gbagame_filename;
WritePrivateProfileString("Slot2.GBAgame","filename",GBAgameName,IniName); WritePrivateProfileString("Slot2.GBAgame", "filename", tmp_gbagame_filename, IniName);
WIN_InstallGBACartridge();
break; break;
case NDS_SLOT2_GUITARGRIP: case NDS_SLOT2_GUITARGRIP:
memcpy(&Guitar, &tmp_Guitar, sizeof(tmp_Guitar)); memcpy(&Guitar, &tmp_Guitar, sizeof(tmp_Guitar));

View File

@ -22,6 +22,7 @@
extern std::string win32_CFlash_cfgDirectory, win32_CFlash_cfgFileName; extern std::string win32_CFlash_cfgDirectory, win32_CFlash_cfgFileName;
extern UINT win32_CFlash_cfgMode; extern UINT win32_CFlash_cfgMode;
extern std::string win32_GBA_cfgRomPath;
extern void GBAslotDialog(HWND hwnd); extern void GBAslotDialog(HWND hwnd);

View File

@ -3170,10 +3170,11 @@ int _main()
win32_CFlash_cfgMode = GetPrivateProfileInt("Slot2.CFlash", "fileMode", ADDON_CFLASH_MODE_RomPath, IniName); win32_CFlash_cfgMode = GetPrivateProfileInt("Slot2.CFlash", "fileMode", ADDON_CFLASH_MODE_RomPath, IniName);
win32_CFlash_cfgDirectory = GetPrivateProfileStdString("Slot2.CFlash", "path", ""); win32_CFlash_cfgDirectory = GetPrivateProfileStdString("Slot2.CFlash", "path", "");
win32_CFlash_cfgFileName = GetPrivateProfileStdString("Slot2.CFlash", "filename", ""); win32_CFlash_cfgFileName = GetPrivateProfileStdString("Slot2.CFlash", "filename", "");
GetPrivateProfileString("Slot2.GBAgame", "filename", "", GBAgameName, MAX_PATH, IniName); win32_GBA_cfgRomPath = GetPrivateProfileStdString("Slot2.GBAgame", "filename", "");
cmdline.process_addonCommands(); cmdline.process_addonCommands();
WIN_InstallCFlash(); WIN_InstallCFlash();
WIN_InstallGBACartridge();
slot1_R4_path_type = cmdline._slot1_fat_dir_type; slot1_R4_path_type = cmdline._slot1_fat_dir_type;
@ -3200,7 +3201,7 @@ int _main()
if(cmdline.gbaslot_rom != "") if(cmdline.gbaslot_rom != "")
{ {
slot2_device_type = NDS_SLOT2_GBACART; slot2_device_type = NDS_SLOT2_GBACART;
strcpy(GBAgameName, cmdline.gbaslot_rom.c_str()); win32_GBA_cfgRomPath = cmdline.gbaslot_rom;
} }
switch (slot2_device_type) switch (slot2_device_type)
@ -3214,7 +3215,7 @@ int _main()
case NDS_SLOT2_RUMBLEPAK: case NDS_SLOT2_RUMBLEPAK:
break; break;
case NDS_SLOT2_GBACART: case NDS_SLOT2_GBACART:
if (!strlen(GBAgameName)) if (win32_GBA_cfgRomPath.empty())
{ {
slot2_device_type = NDS_SLOT2_NONE; slot2_device_type = NDS_SLOT2_NONE;
break; break;
@ -7180,6 +7181,12 @@ void WIN_InstallCFlash()
} }
} }
void WIN_InstallGBACartridge()
{
GBACartridge_RomPath = win32_GBA_cfgRomPath;
GBACartridge_SRAMPath = Path::GetFileNameWithoutExt(win32_GBA_cfgRomPath) + "." + GBA_SRAM_FILE_EXT;
}
// ================================================================= DDraw // ================================================================= DDraw
u32 DDRAW::create(HWND hwnd) u32 DDRAW::create(HWND hwnd)
{ {

View File

@ -67,6 +67,7 @@ extern int backupmemorytype;
extern u32 backupmemorysize; extern u32 backupmemorysize;
void WIN_InstallCFlash(); void WIN_InstallCFlash();
void WIN_InstallGBACartridge();
#define IDM_RECENT_RESERVED0 65500 #define IDM_RECENT_RESERVED0 65500
#define IDM_RECENT_RESERVED1 65501 #define IDM_RECENT_RESERVED1 65501