From 4add68c92ea27f643868f074633b5c97ce344582 Mon Sep 17 00:00:00 2001 From: windwakr <284886+windwakr@users.noreply.github.com> Date: Wed, 11 Oct 2023 22:14:58 -0400 Subject: [PATCH] Slot2: Slide Controller - add rumble Must be explicitly enabled by frontent --- desmume/src/addons/slot2_rumblepak.cpp | 2 -- desmume/src/addons/slot2_slideController.cpp | 35 +++++++++++++++++++- desmume/src/frontend/windows/main.cpp | 2 ++ desmume/src/slot2.cpp | 2 ++ desmume/src/slot2.h | 1 + 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/desmume/src/addons/slot2_rumblepak.cpp b/desmume/src/addons/slot2_rumblepak.cpp index e4c471900..e76c28127 100644 --- a/desmume/src/addons/slot2_rumblepak.cpp +++ b/desmume/src/addons/slot2_rumblepak.cpp @@ -18,8 +18,6 @@ #include "../slot2.h" -void (*FeedbackON)(bool enable) = NULL; - class Slot2_RumblePak : public ISlot2Interface { private: diff --git a/desmume/src/addons/slot2_slideController.cpp b/desmume/src/addons/slot2_slideController.cpp index 496e4bce1..1d9a0bdee 100644 --- a/desmume/src/addons/slot2_slideController.cpp +++ b/desmume/src/addons/slot2_slideController.cpp @@ -18,12 +18,14 @@ along with the this software. If not, see . */ -//Absolute barebones implementation of the Slide Controller add-on. Rumble is not implemented. +//Absolute barebones implementation of the Slide Controller add-on. //The game does a bunch of mystery reads of various sizes which have not been investigated at all. #include "../slot2.h" #include "../emufile.h" +static bool rumbleEnable = false; + static u8 xDelta; static u8 yDelta; //Product ID, Revision ID, Motion status, X delta, Y delta, Surface quality @@ -38,6 +40,8 @@ static u8 scRegs[18] = class Slot2_SlideController : public ISlot2Interface { private: + u8 old_rumble; + struct slideControllerSerial { u16 in_data; @@ -51,6 +55,10 @@ private: void slideCon_reset() { + old_rumble = 0; + if (FeedbackON) + FeedbackON(false); + xDelta = 0; yDelta = 0; @@ -76,6 +84,14 @@ private: u8 new_sck = (slideCon.in_data & 0x2) >> 1; //Serial data in bit 0 u8 sd = slideCon.in_data & 0x1; + //Rumble in bit 8 + u8 rumble = (slideCon.in_data & 0x100) >> 8; + + if (FeedbackON && rumbleEnable && (old_rumble != rumble)) + { + old_rumble = rumble; + FeedbackON(rumble); + } switch (slideCon.state) { @@ -175,6 +191,12 @@ public: slideCon_reset(); } + virtual void disconnect() + { + if (FeedbackON) + FeedbackON(false); + } + virtual void writeWord(u8 PROCNUM, u32 addr, u16 val) { if (addr == 0x081E0000) @@ -240,6 +262,10 @@ public: is.read_u8(slideCon.reg_sel); is.read_u8(slideCon.tmp); } + + old_rumble = 0; + if (FeedbackON) + FeedbackON(false); } }; @@ -253,3 +279,10 @@ void slideController_updateMotion(s8 x, s8 y) yDelta = (u8)y; } } + +void slideController_rumbleEnable(bool enable) +{ + rumbleEnable = enable; + if (FeedbackON && (enable == false)) + FeedbackON(false); +} diff --git a/desmume/src/frontend/windows/main.cpp b/desmume/src/frontend/windows/main.cpp index a3485210c..b37bb0ac3 100644 --- a/desmume/src/frontend/windows/main.cpp +++ b/desmume/src/frontend/windows/main.cpp @@ -2211,6 +2211,8 @@ int _main() slot2_HCV1000_barcode = GetPrivateProfileStdString("Slot2.HCV1000", "barcode", "").substr(0, 16); HCV1000_setBarcode(slot2_HCV1000_barcode); + slideController_rumbleEnable(GetPrivateProfileBool("Slot2.SlideController", "rumble", false, IniName)); + cmdline.process_addonCommands(); WIN_InstallCFlash(); WIN_InstallGBACartridge(); diff --git a/desmume/src/slot2.cpp b/desmume/src/slot2.cpp index dd361aa08..2ab33753f 100644 --- a/desmume/src/slot2.cpp +++ b/desmume/src/slot2.cpp @@ -33,6 +33,8 @@ std::string CFlash_Path; std::string GBACartridge_RomPath; std::string GBACartridge_SRAMPath; +void (*FeedbackON)(bool enable) = NULL; + ISlot2Interface* slot2_List[NDS_SLOT2_COUNT] = {0}; ISlot2Interface* slot2_device = NULL; diff --git a/desmume/src/slot2.h b/desmume/src/slot2.h index 634c4048a..0e95b01d1 100644 --- a/desmume/src/slot2.h +++ b/desmume/src/slot2.h @@ -162,4 +162,5 @@ extern void piano_setKey(bool c, bool cs, bool d, bool ds, bool e, bool f, bool extern void HCV1000_setReady(); extern void HCV1000_setBarcode(std::string barcode); extern void slideController_updateMotion(s8 x, s8 y); +extern void slideController_rumbleEnable(bool enable); #endif //__SLOT_H__