scePadRead,scePthreadYield implementations

This commit is contained in:
georgemoralis 2024-04-05 09:27:13 +03:00
parent 5409576197
commit 81143b4a9e
5 changed files with 94 additions and 3 deletions

View File

@ -19,6 +19,37 @@ void GameController::readState(State* state, bool* isConnected, int* connectedCo
*state = getLastState();
}
int GameController::ReadStates(State* states, int states_num, bool* isConnected,
int* connectedCount) {
std::scoped_lock lock{m_mutex};
*isConnected = m_connected;
*connectedCount = m_connected_count;
int ret_num = 0;
if (m_connected) {
if (m_states_num == 0) {
ret_num = 1;
states[0] = m_last_state;
} else {
for (uint32_t i = 0; i < m_states_num; i++) {
if (ret_num >= states_num) {
break;
}
auto index = (m_first_state + i) % MAX_STATES;
if (!m_private[index].obtained) {
m_private[index].obtained = true;
states[ret_num++] = m_states[index];
}
}
}
}
return ret_num;
}
State GameController::getLastState() const {
if (m_states_num == 0) {
return m_last_state;
@ -39,7 +70,7 @@ void GameController::addState(const State& state) {
m_states[index] = state;
m_last_state = state;
m_private[index].obtained = false;
m_states_num++;
}

View File

@ -20,11 +20,16 @@ public:
virtual ~GameController() = default;
void readState(State* state, bool* isConnected, int* connectedCount);
int ReadStates(State* states, int states_num, bool* isConnected, int* connectedCount);
State getLastState() const;
void checKButton(int id, u32 button, bool isPressed);
void addState(const State& state);
private:
struct StateInternal {
bool obtained = false;
};
std::mutex m_mutex;
bool m_connected = false;
State m_last_state;
@ -32,6 +37,7 @@ private:
u32 m_states_num = 0;
u32 m_first_state = 0;
State m_states[MAX_STATES];
StateInternal m_private[MAX_STATES];
};
} // namespace Emulator::Host::Controller

View File

@ -881,6 +881,10 @@ ScePthread PThreadPool::Create() {
return ret;
}
void PS4_SYSV_ABI scePthreadYield() {
sched_yield();
}
void pthreadSymbolsRegister(Loader::SymbolsResolver* sym) {
LIB_FUNCTION("4+h9EzwKF4I", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetschedpolicy);
LIB_FUNCTION("-Wreprtu0Qs", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetdetachstate);
@ -896,6 +900,8 @@ void pthreadSymbolsRegister(Loader::SymbolsResolver* sym) {
LIB_FUNCTION("bt3CTBKmGyI", "libkernel", 1, "libkernel", 1, 1, scePthreadSetaffinity);
LIB_FUNCTION("6UgtwV+0zb4", "libkernel", 1, "libkernel", 1, 1, scePthreadCreate);
LIB_FUNCTION("T72hz6ffq08", "libkernel", 1, "libkernel", 1, 1, scePthreadYield);
// mutex calls
LIB_FUNCTION("cmo1RIYva9o", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexInit);
LIB_FUNCTION("2Of0f+3mhhE", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexDestroy);

View File

@ -4,11 +4,11 @@
#pragma once
#define _TIMESPEC_DEFINED
#include <mutex>
#include <string>
#include <vector>
#include <pthread.h>
#include <sched.h>
#include <vector>
#include <mutex>
#include "common/types.h"
@ -88,6 +88,7 @@ struct PthreadCondAttrInternal {
class PThreadPool {
public:
ScePthread Create();
private:
std::vector<ScePthread> m_threads;
std::mutex m_mutex;

View File

@ -48,6 +48,51 @@ int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData) {
return SCE_OK;
}
int PS4_SYSV_ABI scePadRead(int handle, ScePadData* pData, int num) {
int connected_count = 0;
bool connected = false;
Emulator::Host::Controller::State states[64];
auto* controller = Common::Singleton<Emulator::Host::Controller::GameController>::Instance();
int ret_num = controller->ReadStates(states, num, &connected, &connected_count);
if (!connected) {
ret_num = 1;
}
for (int i = 0; i < ret_num; i++) {
pData[i].buttons = states[i].buttonsState;
pData[i].leftStick.x = 128; // dummy
pData[i].leftStick.y = 128; // dummy
pData[i].rightStick.x = 0; // dummy
pData[i].rightStick.y = 0; // dummy
pData[i].analogButtons.l2 = 0; // dummy
pData[i].analogButtons.r2 = 0; // dummy
pData[i].orientation.x = 0.0f;
pData[i].orientation.y = 0.0f;
pData[i].orientation.z = 0.0f;
pData[i].orientation.w = 1.0f;
pData[i].acceleration.x = 0.0f;
pData[i].acceleration.y = 0.0f;
pData[i].acceleration.z = 0.0f;
pData[i].angularVelocity.x = 0.0f;
pData[i].angularVelocity.y = 0.0f;
pData[i].angularVelocity.z = 0.0f;
pData[i].touchData.touchNum = 0;
pData[i].touchData.touch[0].x = 0;
pData[i].touchData.touch[0].y = 0;
pData[i].touchData.touch[0].id = 1;
pData[i].touchData.touch[1].x = 0;
pData[i].touchData.touch[1].y = 0;
pData[i].touchData.touch[1].id = 2;
pData[i].connected = connected;
pData[i].timestamp = states[i].time;
pData[i].connectedCount = connected_count;
pData[i].deviceUniqueDataLen = 0;
}
return ret_num;
}
s32 PS4_SYSV_ABI scePadGetControllerInformation(s32 handle, OrbisPadInformation* info) {
LOG_INFO(Lib_Pad, "called handle = {}", handle);
info->touchpadDensity = 1;
@ -72,6 +117,8 @@ void padSymbolsRegister(Core::Loader::SymbolsResolver* sym) {
LIB_FUNCTION("hv1luiJrqQM", "libScePad", 1, "libScePad", 1, 1, scePadInit);
LIB_FUNCTION("xk0AcarP3V4", "libScePad", 1, "libScePad", 1, 1, scePadOpen);
LIB_FUNCTION("YndgXqQVV7c", "libScePad", 1, "libScePad", 1, 1, scePadReadState);
LIB_FUNCTION("q1cHNfGycLI", "libScePad", 1, "libScePad", 1, 1, scePadRead);
LIB_FUNCTION("gjP9-KQzoUk", "libScePad", 1, "libScePad", 1, 1, scePadGetControllerInformation);
LIB_FUNCTION("clVvL4ZDntw", "libScePad", 1, "libScePad", 1, 1, scePadSetMotionSensorState);
}