From 94aac3fccd00ed213749d9b59ec7ea9987ccc17a Mon Sep 17 00:00:00 2001 From: mtabachenko Date: Mon, 11 Nov 2013 09:19:20 +0000 Subject: [PATCH] Slot1: - add ID code to Slot2 devices; --- desmume/src/addons/slot2_auto.cpp | 5 +++- desmume/src/addons/slot2_expMemory.cpp | 2 +- desmume/src/addons/slot2_gbagame.cpp | 2 +- desmume/src/addons/slot2_guitarGrip.cpp | 2 +- desmume/src/addons/slot2_mpcf.cpp | 2 +- desmume/src/addons/slot2_none.cpp | 2 +- desmume/src/addons/slot2_paddle.cpp | 2 +- desmume/src/addons/slot2_passme.cpp | 2 +- desmume/src/addons/slot2_piano.cpp | 2 +- desmume/src/addons/slot2_rumblepak.cpp | 2 +- desmume/src/slot2.cpp | 20 ++++++++++++++++ desmume/src/slot2.h | 31 ++++++++++++++++--------- desmume/src/windows/gbaslot_config.cpp | 7 ++++-- desmume/src/windows/main.cpp | 14 +++++++---- 14 files changed, 67 insertions(+), 28 deletions(-) diff --git a/desmume/src/addons/slot2_auto.cpp b/desmume/src/addons/slot2_auto.cpp index 88337839e..71d4a3c29 100644 --- a/desmume/src/addons/slot2_auto.cpp +++ b/desmume/src/addons/slot2_auto.cpp @@ -33,7 +33,7 @@ public: virtual Slot2Info const* info() { - static Slot2InfoSimple info("Auto","Slot2 (auto-selection) device emulation"); + static Slot2InfoSimple info("Auto","Slot2 (auto-selection) device emulation", 0xFE); return &info; } @@ -43,6 +43,9 @@ public: NDS_SLOT2_TYPE selection = NDS_SLOT2_NONE; //check game ID in core emulator and select right implementation + if (gameInfo.romsize == 0) + {} + else if ((memcmp(gameInfo.header.gameCode, "UBR", 3) == 0)) selection = NDS_SLOT2_EXPMEMORY; // Opera Browser else if ((memcmp(gameInfo.header.gameCode, "YGH", 3) == 0)) selection = NDS_SLOT2_GUITARGRIP; // Guitar Hero - On Tour diff --git a/desmume/src/addons/slot2_expMemory.cpp b/desmume/src/addons/slot2_expMemory.cpp index 441707b12..099298a07 100644 --- a/desmume/src/addons/slot2_expMemory.cpp +++ b/desmume/src/addons/slot2_expMemory.cpp @@ -41,7 +41,7 @@ private: public: virtual Slot2Info const* info() { - static Slot2InfoSimple info("Memory Expansion Pak", "Official RAM expansion for Opera browser"); + static Slot2InfoSimple info("Memory Expansion Pak", "Official RAM expansion for Opera browser", 0x05); return &info; } diff --git a/desmume/src/addons/slot2_gbagame.cpp b/desmume/src/addons/slot2_gbagame.cpp index 16b55897c..85c209281 100644 --- a/desmume/src/addons/slot2_gbagame.cpp +++ b/desmume/src/addons/slot2_gbagame.cpp @@ -303,7 +303,7 @@ private: public: virtual Slot2Info const* info() { - static Slot2InfoSimple info("GBA cartridge", "GBA cartridge in slot"); + static Slot2InfoSimple info("GBA cartridge", "GBA cartridge in slot", 0x03); return &info; } diff --git a/desmume/src/addons/slot2_guitarGrip.cpp b/desmume/src/addons/slot2_guitarGrip.cpp index ce7ecbcb5..4b3799494 100644 --- a/desmume/src/addons/slot2_guitarGrip.cpp +++ b/desmume/src/addons/slot2_guitarGrip.cpp @@ -26,7 +26,7 @@ private: public: virtual Slot2Info const* info() { - static Slot2InfoSimple info("Guitar Grip", "Guitar Grip for Guitar Hero games"); + static Slot2InfoSimple info("Guitar Grip", "Guitar Grip for Guitar Hero games", 0x04); return &info; } diff --git a/desmume/src/addons/slot2_mpcf.cpp b/desmume/src/addons/slot2_mpcf.cpp index 36b377697..69e5bbc06 100644 --- a/desmume/src/addons/slot2_mpcf.cpp +++ b/desmume/src/addons/slot2_mpcf.cpp @@ -266,7 +266,7 @@ class Slot2_CFlash : public ISlot2Interface public: virtual Slot2Info const* info() { - static Slot2InfoSimple info("MPCF Flash Card Device", "MPCF Flash Card Device"); + static Slot2InfoSimple info("MPCF Flash Card Device", "MPCF Flash Card Device", 0x01); return &info; } diff --git a/desmume/src/addons/slot2_none.cpp b/desmume/src/addons/slot2_none.cpp index 92f2823c7..a71d06003 100644 --- a/desmume/src/addons/slot2_none.cpp +++ b/desmume/src/addons/slot2_none.cpp @@ -23,7 +23,7 @@ class Slot2_None : public ISlot2Interface public: virtual Slot2Info const* info() { - static Slot2InfoSimple info("None", "Slot2 no-device emulation"); + static Slot2InfoSimple info("None", "Slot2 no-device emulation", 0xFF); return &info; } }; diff --git a/desmume/src/addons/slot2_paddle.cpp b/desmume/src/addons/slot2_paddle.cpp index 3852604e2..2b60d56e0 100644 --- a/desmume/src/addons/slot2_paddle.cpp +++ b/desmume/src/addons/slot2_paddle.cpp @@ -56,7 +56,7 @@ private: public: virtual Slot2Info const* info() { - static Slot2InfoSimple info("Paddle", "Paddle"); + static Slot2InfoSimple info("Paddle", "Paddle", 0x07); return &info; } diff --git a/desmume/src/addons/slot2_passme.cpp b/desmume/src/addons/slot2_passme.cpp index 286853274..e6d58e826 100644 --- a/desmume/src/addons/slot2_passme.cpp +++ b/desmume/src/addons/slot2_passme.cpp @@ -24,7 +24,7 @@ class Slot2_PassME : public ISlot2Interface public: virtual Slot2Info const* info() { - static Slot2InfoSimple info("PassME", "PassME in GBA slot"); + static Slot2InfoSimple info("PassME", "PassME in GBA slot", 0x08); return &info; } diff --git a/desmume/src/addons/slot2_piano.cpp b/desmume/src/addons/slot2_piano.cpp index a542fa698..a4ef5886f 100644 --- a/desmume/src/addons/slot2_piano.cpp +++ b/desmume/src/addons/slot2_piano.cpp @@ -24,7 +24,7 @@ class Slot2_EasyPiano : public ISlot2Interface public: virtual Slot2Info const* info() { - static Slot2InfoSimple info("Piano", "Piano for EasyPiano"); + static Slot2InfoSimple info("Piano", "Piano for EasyPiano", 0x06); return &info; } diff --git a/desmume/src/addons/slot2_rumblepak.cpp b/desmume/src/addons/slot2_rumblepak.cpp index 440ba42f5..798e800a7 100644 --- a/desmume/src/addons/slot2_rumblepak.cpp +++ b/desmume/src/addons/slot2_rumblepak.cpp @@ -28,7 +28,7 @@ private: public: virtual Slot2Info const* info() { - static Slot2InfoSimple info("Rumble Pak", "NDS Rumble Pak (need joystick with Feedback)"); + static Slot2InfoSimple info("Rumble Pak", "NDS Rumble Pak (need joystick with Feedback)", 0x02); return &info; } diff --git a/desmume/src/slot2.cpp b/desmume/src/slot2.cpp index 60a5c84d2..2dbef1ce6 100644 --- a/desmume/src/slot2.cpp +++ b/desmume/src/slot2.cpp @@ -115,6 +115,26 @@ bool slot2_Change(NDS_SLOT2_TYPE changeToType) return true; } +bool getTypeByID(u8 ID, NDS_SLOT2_TYPE &type) +{ + for (u8 i = 0; i < NDS_SLOT2_COUNT; i++) + { + if (slot2_List[i]->info()->id() == ID) + { + type = (NDS_SLOT2_TYPE)i; + return true; + } + } + return false; +} + +bool slot2_ChangeByID(u8 ID) +{ + NDS_SLOT2_TYPE type = NDS_SLOT2_AUTO; + getTypeByID(ID, type); + return slot2_Change(type); +} + NDS_SLOT2_TYPE slot2_GetCurrentType() { return slot2_device_type; diff --git a/desmume/src/slot2.h b/desmume/src/slot2.h index 1acc15e67..952f26f43 100644 --- a/desmume/src/slot2.h +++ b/desmume/src/slot2.h @@ -27,20 +27,24 @@ class Slot2Info public: virtual const char* name() const = 0; virtual const char* descr() const = 0; + virtual const u8 id() const = 0; }; class Slot2InfoSimple : public Slot2Info { public: - Slot2InfoSimple(const char* _name, const char* _descr) + Slot2InfoSimple(const char* _name, const char* _descr, const u8 _id) : mName(_name) , mDescr(_descr) + , mID(_id) { } virtual const char* name() const { return mName; } virtual const char* descr() const { return mDescr; } + virtual const u8 id() const { return mID; } private: const char* mName, *mDescr; + const u8 mID; }; class ISlot2Interface @@ -78,16 +82,16 @@ typedef ISlot2Interface* TISlot2InterfaceConstructor(); enum NDS_SLOT2_TYPE { - NDS_SLOT2_NONE, - NDS_SLOT2_AUTO, - NDS_SLOT2_CFLASH, // compact flash - NDS_SLOT2_RUMBLEPAK, // rumble pack - NDS_SLOT2_GBACART, // GBA cartrindge in slot - NDS_SLOT2_GUITARGRIP, // Guitar Grip - NDS_SLOT2_EXPMEMORY, // Memory Expansion - NDS_SLOT2_EASYPIANO, // Easy Piano - NDS_SLOT2_PADDLE, - NDS_SLOT2_PASSME, // PassME + NDS_SLOT2_NONE, // 0xFF + NDS_SLOT2_AUTO, // 0xFE - Auto-select + NDS_SLOT2_CFLASH, // 0x01 - Compact flash + NDS_SLOT2_RUMBLEPAK, // 0x02 - RumblePak + NDS_SLOT2_GBACART, // 0x03 - GBA cartrindge in slot + NDS_SLOT2_GUITARGRIP, // 0x04 - Guitar Grip + NDS_SLOT2_EXPMEMORY, // 0x05 - Memory Expansion Pak + NDS_SLOT2_EASYPIANO, // 0x06 - Easy Piano + NDS_SLOT2_PADDLE, // 0x07 - Arkanoids DS paddle + NDS_SLOT2_PASSME, // 0x08 - PassME/Homebrew NDS_SLOT2_COUNT // use for counter addons - MUST TO BE LAST!!! }; @@ -107,6 +111,11 @@ void slot2_Reset(); //change the current device bool slot2_Change(NDS_SLOT2_TYPE type); +bool getTypeByID(u8 ID, NDS_SLOT2_TYPE &type); + +//change the current device by ID +bool slot2_ChangeByID(u8 ID); + //check on the current device NDS_SLOT2_TYPE slot2_GetCurrentType(); diff --git a/desmume/src/windows/gbaslot_config.cpp b/desmume/src/windows/gbaslot_config.cpp index 325088eb1..2fe738751 100644 --- a/desmume/src/windows/gbaslot_config.cpp +++ b/desmume/src/windows/gbaslot_config.cpp @@ -641,11 +641,14 @@ void GBAslotDialog(HWND hwnd) default: return; } - if (temp_type!=NDS_SLOT2_GUITARGRIP) + if (temp_type != NDS_SLOT2_GUITARGRIP) Guitar.Enabled = false; - WritePrivateProfileInt("Slot2","type",temp_type,IniName); + if (temp_type != NDS_SLOT2_EASYPIANO) + Piano.Enabled = false; slot2_Change((NDS_SLOT2_TYPE)temp_type); + WritePrivateProfileInt("Slot2", "id", slot2_List[(u8)slot2_GetCurrentType()]->info()->id(), IniName); + if (romloaded && needReset) NDS_Reset(); return; diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index bd107db3c..31444de08 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -3158,7 +3158,13 @@ int _main() cmdline._slot1_fat_dir_type = 0; slot1_R4_path_type = cmdline._slot1_fat_dir_type; - int slot2_device_type = (NDS_SLOT2_TYPE)GetPrivateProfileInt("Slot2", "type", NDS_SLOT2_AUTO, IniName); + slot1_Init(); + slot2_Init(); + + int slot2_device_id = (NDS_SLOT2_TYPE)GetPrivateProfileInt("Slot2", "id", slot2_List[NDS_SLOT2_AUTO]->info()->id(), IniName); + NDS_SLOT2_TYPE slot2_device_type = NDS_SLOT2_AUTO; + getTypeByID(slot2_device_id, slot2_device_type); + win32_CFlash_cfgMode = GetPrivateProfileInt("Slot2.CFlash", "fileMode", ADDON_CFLASH_MODE_RomPath, IniName); win32_CFlash_cfgDirectory = GetPrivateProfileStdString("Slot2.CFlash", "path", ""); win32_CFlash_cfgFileName = GetPrivateProfileStdString("Slot2.CFlash", "filename", ""); @@ -3178,16 +3184,14 @@ int _main() else win32_CFlash_cfgFileName = CFlash_Path; } - - slot1_Init(); + //override slot1 type with commandline, if present int slot1_device_type = (NDS_SLOT1_TYPE)GetPrivateProfileInt("Slot1", "type", NDS_SLOT1_RETAIL_AUTO, IniName); if(cmdline.slot1 != "") WritePrivateProfileInt("Slot1","type",slot1_device_type,IniName); else slot1_Change((NDS_SLOT1_TYPE)slot1_device_type); - - slot2_Init(); + if(cmdline.gbaslot_rom != "") { slot2_device_type = NDS_SLOT2_GBACART;