attempt at syncing pause command between instances. works somewhat

This commit is contained in:
Arisotura 2023-02-15 18:24:24 +01:00
parent 5aa378d316
commit ea951d092e
5 changed files with 124 additions and 2 deletions

View File

@ -22,6 +22,14 @@
#include <QSharedMemory>
#include "IPC.h"
#include "Config.h"
//#include "Input.h"
namespace Input
{
void ExtHotkeyPress(int id);
}
namespace IPC
@ -79,6 +87,15 @@ void Init()
Buffer->lock();
u8* data = (u8*)Buffer->data();
BufferHeader* header = (BufferHeader*)&data[0];
if (header->NumInstances == 0)
{
// initialize the FIFO
header->CommandWriteOffset = kCommandStart;
}
CommandReadOffset = header->CommandWriteOffset;
u16 mask = header->InstanceBitmask;
for (int i = 0; i < 16; i++)
{
@ -166,4 +183,85 @@ void FIFOWrite(void* buf, int len)
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;
}
}

View File

@ -24,11 +24,20 @@
namespace IPC
{
enum
{
Cmd_Pause = 1,
};
extern int InstanceID;
void Init();
void DeInit();
void Process();
bool SendCommand(u16 recipients, u16 command, u16 len, void* data);
}
#endif // IPC_H

View File

@ -30,7 +30,7 @@ int JoystickID;
SDL_Joystick* Joystick = nullptr;
u32 KeyInputMask, JoyInputMask;
u32 KeyHotkeyMask, JoyHotkeyMask;
u32 KeyHotkeyMask, JoyHotkeyMask, ExtHotkeyMask;
u32 HotkeyMask, LastHotkeyMask;
u32 HotkeyPress, HotkeyRelease;
@ -45,6 +45,7 @@ void Init()
KeyHotkeyMask = 0;
JoyHotkeyMask = 0;
ExtHotkeyMask = 0;
HotkeyMask = 0;
LastHotkeyMask = 0;
}
@ -184,6 +185,11 @@ bool JoystickButtonDown(int val)
return false;
}
void ExtHotkeyPress(int id)
{
ExtHotkeyMask |= (1<<id);
}
void Process()
{
SDL_JoystickUpdate();
@ -214,10 +220,11 @@ void Process()
if (JoystickButtonDown(Config::HKJoyMapping[i]))
JoyHotkeyMask |= (1<<i);
HotkeyMask = KeyHotkeyMask | JoyHotkeyMask;
HotkeyMask = KeyHotkeyMask | JoyHotkeyMask | ExtHotkeyMask;
HotkeyPress = HotkeyMask & ~LastHotkeyMask;
HotkeyRelease = LastHotkeyMask & ~HotkeyMask;
LastHotkeyMask = HotkeyMask;
ExtHotkeyMask = 0;
}

View File

@ -38,6 +38,8 @@ void CloseJoystick();
void KeyPress(QKeyEvent* event);
void KeyRelease(QKeyEvent* event);
void ExtHotkeyPress(int id);
void Process();
bool HotkeyDown(int id);

View File

@ -87,6 +87,7 @@
#include "SPU.h"
#include "Wifi.h"
#include "Platform.h"
#include "IPC.h"
#include "LocalMP.h"
#include "Config.h"
#include "DSi_I2C.h"
@ -356,6 +357,8 @@ void EmuThread::run()
while (EmuRunning != emuStatus_Exit)
{
IPC::Process();
Input::Process();
if (Input::HotkeyPressed(HK_FastForwardToggle)) emit windowLimitFPSChange();
@ -2703,6 +2706,9 @@ void MainWindow::onPause(bool checked)
OSD::AddMessage(0, "Resumed");
pausedManually = false;
}
if (Platform::InstanceID()==0) // HAX
IPC::SendCommand(0xFFFF, IPC::Cmd_Pause, 0, nullptr);
}
void MainWindow::onReset()