PAD: windows sstates support

This commit is contained in:
Gauvain 'GovanifY' Roussel-Tarbouriech 2020-12-11 20:32:42 +01:00 committed by lightningterror
parent afef852609
commit ce7fbe6398
3 changed files with 71 additions and 60 deletions

View File

@ -17,6 +17,8 @@
#pragma once
#include "PAD.h"
#ifdef __linux__
// Seriously why there is no standard
#include "stdint.h"
@ -140,56 +142,4 @@ extern Window GSwin;
extern HINSTANCE hInst;
#endif
// Needed for config screen
void GetNameAndVersionString(wchar_t *out);
typedef struct
{
unsigned char controllerType;
unsigned short buttonStatus;
unsigned char rightJoyX, rightJoyY, leftJoyX, leftJoyY;
unsigned char moveX, moveY;
unsigned char reserved[91];
} PadDataS;
EXPORT_C_(void)
PADupdate(int pad);
EXPORT_C_(u32)
PS2EgetLibType(void);
EXPORT_C_(u32)
PS2EgetLibVersion2(u32 type);
EXPORT_C_(char *)
PS2EgetLibName(void);
EXPORT_C_(void)
PADshutdown();
EXPORT_C_(s32)
PADinit(u32 flags);
EXPORT_C_(s32)
PADopen(void *pDsp);
EXPORT_C_(void)
PADclose();
EXPORT_C_(u8)
PADstartPoll(int pad);
EXPORT_C_(u8)
PADpoll(u8 value);
EXPORT_C_(u32)
PADquery();
EXPORT_C_(void)
PADabout();
EXPORT_C_(s32)
PADtest();
EXPORT_C_(keyEvent *)
PADkeyEvent();
EXPORT_C_(u32)
PADreadPort1(PadDataS *pads);
EXPORT_C_(u32)
PADreadPort2(PadDataS *pads);
EXPORT_C_(void)
PADconfigure();
EXPORT_C_(s32)
PADfreeze(int mode, freezeData *data);
EXPORT_C_(s32)
PADsetSlot(u8 port, u8 slot);
EXPORT_C_(s32)
PADqueryMtap(u8 port);
EXPORT_C_(void)
PADsetSettingsDir(const char *dir);
void GetNameAndVersionString(wchar_t *out);

View File

@ -39,6 +39,7 @@
#include "svnrev.h"
#include "DualShock3.h"
#include <timeapi.h>
#include "Utilities/pxStreams.h"
#define WMA_FORCE_UPDATE (WM_APP + 0x537)
#define FORCE_UPDATE_WPARAM ((WPARAM)0x74328943)
@ -1596,3 +1597,49 @@ s32 PADsetSlot(u8 port, u8 slot)
// return pads[port][slot].enabled | !slot;
return 1;
}
void PADDoFreezeOut(void* dest)
{
freezeData fP = { 0, (s8*)dest };
if (PADfreeze(FREEZE_SIZE, &fP) != 0)
return;
if (!fP.size)
return;
Console.Indent().WriteLn("Saving PAD");
if (PADfreeze(FREEZE_SAVE, &fP) != 0)
throw std::runtime_error(" * PAD: Error saving state!\n");
}
void PADDoFreezeIn(pxInputStream& infp)
{
freezeData fP = { 0, nullptr };
if (PADfreeze(FREEZE_SIZE, &fP) != 0)
fP.size = 0;
Console.Indent().WriteLn("Loading PAD");
if (!infp.IsOk() || !infp.Length())
{
// no state data to read, but PAD expects some state data?
// Issue a warning to console...
if (fP.size != 0)
Console.Indent().Warning("Warning: No data for PAD found. Status may be unpredictable.");
return;
// Note: Size mismatch check could also be done here on loading, but
// some plugins may have built-in version support for non-native formats or
// older versions of a different size... or could give different sizes depending
// on the status of the plugin when loading, so let's ignore it.
}
ScopedAlloc<s8> data(fP.size);
fP.data = data.GetPtr();
infp.Read(fP.data, fP.size);
if (PADfreeze(FREEZE_LOAD, &fP) != 0)
throw std::runtime_error(" * PAD: Error loading state!\n");
}

View File

@ -38,17 +38,31 @@
#include <queue>
s32 PADinit();
typedef struct
{
unsigned char controllerType;
unsigned short buttonStatus;
unsigned char rightJoyX, rightJoyY, leftJoyX, leftJoyY;
unsigned char moveX, moveY;
unsigned char reserved[91];
} PadDataS;
void PADupdate(int pad);
void PADshutdown();
s32 PADinit(u32 flags);
s32 PADopen(void* pDsp);
void PADclose();
u32 PADquery();
s32 PADsetSlot(u8 port, u8 slot);
s32 PADfreeze(int mode, freezeData* data);
u8 PADstartPoll(int pad);
u8 PADpoll(u8 value);
u32 PADquery();
keyEvent* PADkeyEvent();
void PADupdate(int pad);
u32 PADreadPort1(PadDataS* pads);
u32 PADreadPort2(PadDataS* pads);
void PADconfigure();
//void PADDoFreezeOut(void* dest);
//void PADDoFreezeIn(pxInputStream& infp);
s32 PADfreeze(int mode, freezeData* data);
s32 PADsetSlot(u8 port, u8 slot);
s32 PADqueryMtap(u8 port);
void PADsetSettingsDir(const char* dir);
void PADDoFreezeOut(void* dest);
void PADDoFreezeIn(pxInputStream& infp);