mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-26 15:50:00 -06:00
attempt at syncing pause command between instances. works somewhat
This commit is contained in:
@ -22,6 +22,14 @@
|
|||||||
#include <QSharedMemory>
|
#include <QSharedMemory>
|
||||||
|
|
||||||
#include "IPC.h"
|
#include "IPC.h"
|
||||||
|
#include "Config.h"
|
||||||
|
//#include "Input.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Input
|
||||||
|
{
|
||||||
|
void ExtHotkeyPress(int id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace IPC
|
namespace IPC
|
||||||
@ -79,6 +87,15 @@ void Init()
|
|||||||
Buffer->lock();
|
Buffer->lock();
|
||||||
u8* data = (u8*)Buffer->data();
|
u8* data = (u8*)Buffer->data();
|
||||||
BufferHeader* header = (BufferHeader*)&data[0];
|
BufferHeader* header = (BufferHeader*)&data[0];
|
||||||
|
|
||||||
|
if (header->NumInstances == 0)
|
||||||
|
{
|
||||||
|
// initialize the FIFO
|
||||||
|
header->CommandWriteOffset = kCommandStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandReadOffset = header->CommandWriteOffset;
|
||||||
|
|
||||||
u16 mask = header->InstanceBitmask;
|
u16 mask = header->InstanceBitmask;
|
||||||
for (int i = 0; i < 16; i++)
|
for (int i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
@ -166,4 +183,85 @@ void FIFOWrite(void* buf, int len)
|
|||||||
header->CommandWriteOffset = offset;
|
header->CommandWriteOffset = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Process()
|
||||||
|
{
|
||||||
|
Buffer->lock();
|
||||||
|
u8* data = (u8*)Buffer->data();
|
||||||
|
BufferHeader* header = (BufferHeader*)&data[0];
|
||||||
|
|
||||||
|
// check if we got new commands
|
||||||
|
while (CommandReadOffset != header->CommandWriteOffset)
|
||||||
|
{
|
||||||
|
CommandHeader cmdheader;
|
||||||
|
u8 cmddata[kMaxCommandSize];
|
||||||
|
|
||||||
|
FIFORead(&cmdheader, sizeof(cmdheader));
|
||||||
|
|
||||||
|
if ((cmdheader.Magic != 0x4D434C4D) || (cmdheader.Length > kMaxCommandSize))
|
||||||
|
{
|
||||||
|
printf("IPC: !!! COMMAND BUFFER IS FUCKED. RESETTING\n");
|
||||||
|
CommandReadOffset = header->CommandWriteOffset;
|
||||||
|
Buffer->unlock();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmdheader.Length)
|
||||||
|
FIFORead(cmddata, cmdheader.Length);
|
||||||
|
|
||||||
|
if (!(cmdheader.Recipients & (1<<InstanceID)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// handle this command
|
||||||
|
switch (cmdheader.Command)
|
||||||
|
{
|
||||||
|
case Cmd_Pause:
|
||||||
|
Input::ExtHotkeyPress(HK_Pause);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Buffer->unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SendCommand(u16 recipients, u16 command, u16 len, void* cmddata)
|
||||||
|
{
|
||||||
|
Buffer->lock();
|
||||||
|
u8* data = (u8*)Buffer->data();
|
||||||
|
BufferHeader* header = (BufferHeader*)&data[0];
|
||||||
|
|
||||||
|
recipients &= header->InstanceBitmask;
|
||||||
|
recipients &= ~(1<<InstanceID);
|
||||||
|
if (!recipients)
|
||||||
|
{
|
||||||
|
Buffer->unlock();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len && cmddata==nullptr)
|
||||||
|
{
|
||||||
|
printf("IPC: ????? sending command with NULL buffer\n");
|
||||||
|
Buffer->unlock();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (len > kMaxCommandSize)
|
||||||
|
{
|
||||||
|
printf("IPC: command too long\n");
|
||||||
|
Buffer->unlock();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandHeader cmdheader;
|
||||||
|
cmdheader.Magic = 0x4D434C4D;
|
||||||
|
cmdheader.SenderID = InstanceID;
|
||||||
|
cmdheader.Recipients = recipients;
|
||||||
|
cmdheader.Command = command;
|
||||||
|
cmdheader.Length = len;
|
||||||
|
FIFOWrite(&cmdheader, sizeof(cmdheader));
|
||||||
|
if (len)
|
||||||
|
FIFOWrite(cmddata, len);
|
||||||
|
|
||||||
|
Buffer->unlock();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,11 +24,20 @@
|
|||||||
namespace IPC
|
namespace IPC
|
||||||
{
|
{
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
Cmd_Pause = 1,
|
||||||
|
};
|
||||||
|
|
||||||
extern int InstanceID;
|
extern int InstanceID;
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
void DeInit();
|
void DeInit();
|
||||||
|
|
||||||
|
void Process();
|
||||||
|
|
||||||
|
bool SendCommand(u16 recipients, u16 command, u16 len, void* data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // IPC_H
|
#endif // IPC_H
|
||||||
|
@ -30,7 +30,7 @@ int JoystickID;
|
|||||||
SDL_Joystick* Joystick = nullptr;
|
SDL_Joystick* Joystick = nullptr;
|
||||||
|
|
||||||
u32 KeyInputMask, JoyInputMask;
|
u32 KeyInputMask, JoyInputMask;
|
||||||
u32 KeyHotkeyMask, JoyHotkeyMask;
|
u32 KeyHotkeyMask, JoyHotkeyMask, ExtHotkeyMask;
|
||||||
u32 HotkeyMask, LastHotkeyMask;
|
u32 HotkeyMask, LastHotkeyMask;
|
||||||
u32 HotkeyPress, HotkeyRelease;
|
u32 HotkeyPress, HotkeyRelease;
|
||||||
|
|
||||||
@ -45,6 +45,7 @@ void Init()
|
|||||||
|
|
||||||
KeyHotkeyMask = 0;
|
KeyHotkeyMask = 0;
|
||||||
JoyHotkeyMask = 0;
|
JoyHotkeyMask = 0;
|
||||||
|
ExtHotkeyMask = 0;
|
||||||
HotkeyMask = 0;
|
HotkeyMask = 0;
|
||||||
LastHotkeyMask = 0;
|
LastHotkeyMask = 0;
|
||||||
}
|
}
|
||||||
@ -184,6 +185,11 @@ bool JoystickButtonDown(int val)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ExtHotkeyPress(int id)
|
||||||
|
{
|
||||||
|
ExtHotkeyMask |= (1<<id);
|
||||||
|
}
|
||||||
|
|
||||||
void Process()
|
void Process()
|
||||||
{
|
{
|
||||||
SDL_JoystickUpdate();
|
SDL_JoystickUpdate();
|
||||||
@ -214,10 +220,11 @@ void Process()
|
|||||||
if (JoystickButtonDown(Config::HKJoyMapping[i]))
|
if (JoystickButtonDown(Config::HKJoyMapping[i]))
|
||||||
JoyHotkeyMask |= (1<<i);
|
JoyHotkeyMask |= (1<<i);
|
||||||
|
|
||||||
HotkeyMask = KeyHotkeyMask | JoyHotkeyMask;
|
HotkeyMask = KeyHotkeyMask | JoyHotkeyMask | ExtHotkeyMask;
|
||||||
HotkeyPress = HotkeyMask & ~LastHotkeyMask;
|
HotkeyPress = HotkeyMask & ~LastHotkeyMask;
|
||||||
HotkeyRelease = LastHotkeyMask & ~HotkeyMask;
|
HotkeyRelease = LastHotkeyMask & ~HotkeyMask;
|
||||||
LastHotkeyMask = HotkeyMask;
|
LastHotkeyMask = HotkeyMask;
|
||||||
|
ExtHotkeyMask = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,6 +38,8 @@ void CloseJoystick();
|
|||||||
void KeyPress(QKeyEvent* event);
|
void KeyPress(QKeyEvent* event);
|
||||||
void KeyRelease(QKeyEvent* event);
|
void KeyRelease(QKeyEvent* event);
|
||||||
|
|
||||||
|
void ExtHotkeyPress(int id);
|
||||||
|
|
||||||
void Process();
|
void Process();
|
||||||
|
|
||||||
bool HotkeyDown(int id);
|
bool HotkeyDown(int id);
|
||||||
|
@ -87,6 +87,7 @@
|
|||||||
#include "SPU.h"
|
#include "SPU.h"
|
||||||
#include "Wifi.h"
|
#include "Wifi.h"
|
||||||
#include "Platform.h"
|
#include "Platform.h"
|
||||||
|
#include "IPC.h"
|
||||||
#include "LocalMP.h"
|
#include "LocalMP.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "DSi_I2C.h"
|
#include "DSi_I2C.h"
|
||||||
@ -356,6 +357,8 @@ void EmuThread::run()
|
|||||||
|
|
||||||
while (EmuRunning != emuStatus_Exit)
|
while (EmuRunning != emuStatus_Exit)
|
||||||
{
|
{
|
||||||
|
IPC::Process();
|
||||||
|
|
||||||
Input::Process();
|
Input::Process();
|
||||||
|
|
||||||
if (Input::HotkeyPressed(HK_FastForwardToggle)) emit windowLimitFPSChange();
|
if (Input::HotkeyPressed(HK_FastForwardToggle)) emit windowLimitFPSChange();
|
||||||
@ -2703,6 +2706,9 @@ void MainWindow::onPause(bool checked)
|
|||||||
OSD::AddMessage(0, "Resumed");
|
OSD::AddMessage(0, "Resumed");
|
||||||
pausedManually = false;
|
pausedManually = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Platform::InstanceID()==0) // HAX
|
||||||
|
IPC::SendCommand(0xFFFF, IPC::Cmd_Pause, 0, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onReset()
|
void MainWindow::onReset()
|
||||||
|
Reference in New Issue
Block a user