mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-25 07:10:00 -06:00
Implement Rumble Pak support. (#2101)
This commit is contained in:
@ -127,6 +127,8 @@ public:
|
||||
void inputInit();
|
||||
void inputDeInit();
|
||||
void inputLoadConfig();
|
||||
void inputRumbleStart(melonDS::u32 len_ms);
|
||||
void inputRumbleStop();
|
||||
|
||||
void setJoystick(int id);
|
||||
int getJoystickID() { return joystickID; }
|
||||
@ -291,6 +293,9 @@ private:
|
||||
|
||||
int joystickID;
|
||||
SDL_Joystick* joystick;
|
||||
SDL_GameController* controller;
|
||||
bool hasRumble = false;
|
||||
bool isRumbling = false;
|
||||
|
||||
melonDS::u32 keyInputMask, joyInputMask;
|
||||
melonDS::u32 keyHotkeyMask, joyHotkeyMask;
|
||||
|
@ -72,6 +72,9 @@ void EmuInstance::inputInit()
|
||||
lastHotkeyMask = 0;
|
||||
|
||||
joystick = nullptr;
|
||||
controller = nullptr;
|
||||
hasRumble = false;
|
||||
isRumbling = false;
|
||||
inputLoadConfig();
|
||||
}
|
||||
|
||||
@ -100,6 +103,24 @@ void EmuInstance::inputLoadConfig()
|
||||
setJoystick(localCfg.GetInt("JoystickID"));
|
||||
}
|
||||
|
||||
void EmuInstance::inputRumbleStart(melonDS::u32 len_ms)
|
||||
{
|
||||
if (controller && hasRumble && !isRumbling)
|
||||
{
|
||||
SDL_GameControllerRumble(controller, 0xFFFF, 0xFFFF, len_ms);
|
||||
isRumbling = true;
|
||||
}
|
||||
}
|
||||
|
||||
void EmuInstance::inputRumbleStop()
|
||||
{
|
||||
if (controller && hasRumble && isRumbling)
|
||||
{
|
||||
SDL_GameControllerRumble(controller, 0, 0, 0);
|
||||
isRumbling = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void EmuInstance::setJoystick(int id)
|
||||
{
|
||||
@ -109,12 +130,16 @@ void EmuInstance::setJoystick(int id)
|
||||
|
||||
void EmuInstance::openJoystick()
|
||||
{
|
||||
if (controller) SDL_GameControllerClose(controller);
|
||||
|
||||
if (joystick) SDL_JoystickClose(joystick);
|
||||
|
||||
int num = SDL_NumJoysticks();
|
||||
if (num < 1)
|
||||
{
|
||||
controller = nullptr;
|
||||
joystick = nullptr;
|
||||
hasRumble = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -122,10 +147,30 @@ void EmuInstance::openJoystick()
|
||||
joystickID = 0;
|
||||
|
||||
joystick = SDL_JoystickOpen(joystickID);
|
||||
|
||||
if (SDL_IsGameController(joystickID))
|
||||
{
|
||||
controller = SDL_GameControllerOpen(joystickID);
|
||||
}
|
||||
|
||||
if (controller)
|
||||
{
|
||||
if (SDL_GameControllerHasRumble(controller))
|
||||
{
|
||||
hasRumble = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EmuInstance::closeJoystick()
|
||||
{
|
||||
if (controller)
|
||||
{
|
||||
SDL_GameControllerClose(controller);
|
||||
controller = nullptr;
|
||||
hasRumble = false;
|
||||
}
|
||||
|
||||
if (joystick)
|
||||
{
|
||||
SDL_JoystickClose(joystick);
|
||||
|
@ -538,6 +538,16 @@ void Camera_CaptureFrame(int num, u32* frame, int width, int height, bool yuv, v
|
||||
return camManager[num]->captureFrame(frame, width, height, yuv);
|
||||
}
|
||||
|
||||
void Addon_RumbleStart(u32 len, void* userdata)
|
||||
{
|
||||
((EmuInstance*)userdata)->inputRumbleStart(len);
|
||||
}
|
||||
|
||||
void Addon_RumbleStop(void* userdata)
|
||||
{
|
||||
((EmuInstance*)userdata)->inputRumbleStop();
|
||||
}
|
||||
|
||||
DynamicLibrary* DynamicLibrary_Load(const char* lib)
|
||||
{
|
||||
return (DynamicLibrary*) SDL_LoadObject(lib);
|
||||
|
@ -312,6 +312,10 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
|
||||
actInsertGBAAddon[0] = submenu->addAction("Memory expansion");
|
||||
actInsertGBAAddon[0]->setData(QVariant(GBAAddon_RAMExpansion));
|
||||
connect(actInsertGBAAddon[0], &QAction::triggered, this, &MainWindow::onInsertGBAAddon);
|
||||
|
||||
actInsertGBAAddon[1] = submenu->addAction("Rumble Pak");
|
||||
actInsertGBAAddon[1]->setData(QVariant(GBAAddon_RumblePak));
|
||||
connect(actInsertGBAAddon[1], &QAction::triggered, this, &MainWindow::onInsertGBAAddon);
|
||||
}
|
||||
|
||||
actEjectGBACart = menu->addAction("Eject cart");
|
||||
|
@ -258,7 +258,7 @@ public:
|
||||
QAction* actEjectCart;
|
||||
QAction* actCurrentGBACart;
|
||||
QAction* actInsertGBACart;
|
||||
QAction* actInsertGBAAddon[1];
|
||||
QAction* actInsertGBAAddon[2];
|
||||
QAction* actEjectGBACart;
|
||||
QAction* actImportSavefile;
|
||||
QAction* actSaveState[9];
|
||||
|
Reference in New Issue
Block a user