VERY experimental Nintendo Switch 2 emulator
C++
- refactored how service functions are called
bunneicd0664eb77e1
diff --git a/src/core/hle/service/apt.cpp b/src/core/hle/service/apt.cppindex 4f8d7248dd..4a1e8c992a 100644--- a/src/core/hle/service/apt.cpp+++ b/src/core/hle/service/apt.cpp@@ -13,16 +13,16 @@namespace APT_U {-void Initialize() {+void Initialize(Service::Interface* self) {NOTICE_LOG(OSHLE, "APT_U::Sync - Initialize");}-void GetLockHandle() {+void GetLockHandle(Service::Interface* self) {u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + Service::kCommandHeaderOffset);cmd_buff[5] = 0x00000000; // TODO: This should be an actual mutex handle}-const HLE::FunctionDef FunctionTable[] = {+const Interface::FunctionInfo FunctionTable[] = {{0x00010040, GetLockHandle, "GetLockHandle"},{0x00020080, Initialize, "Initialize"},{0x00030040, NULL, "Enable"},diff --git a/src/core/hle/service/apt.h b/src/core/hle/service/apt.hindex e74baac0c0..4c7dd07e7b 100644--- a/src/core/hle/service/apt.h+++ b/src/core/hle/service/apt.h@@ -32,10 +32,6 @@ public:std::string GetPortName() const {return "APT:U";}--private:-- DISALLOW_COPY_AND_ASSIGN(Interface);};} // namespacediff --git a/src/core/hle/service/hid.cpp b/src/core/hle/service/hid.cppindex 2d823dd16c..5542e5bf2f 100644--- a/src/core/hle/service/hid.cpp+++ b/src/core/hle/service/hid.cpp@@ -12,7 +12,7 @@namespace HID_User {-const HLE::FunctionDef FunctionTable[] = {+const Interface::FunctionInfo FunctionTable[] = {{0x000A0000, NULL, "GetIPCHandles"},{0x00110000, NULL, "EnableAccelerometer"},{0x00130000, NULL, "EnableGyroscopeLow"},diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.hindex 9cbf8b6fa9..9de17beab1 100644--- a/src/core/hle/service/service.h+++ b/src/core/hle/service/service.h@@ -25,7 +25,7 @@ static const int kCommandHeaderOffset = 0x80; ///< Offset into command bufferclass Manager;/// Interface to a CTROS service-class Interface {+class Interface : NonCopyable {friend class Manager;public:@@ -35,6 +35,14 @@ public:virtual ~Interface() {}+ typedef void (*Function)(Interface*);++ struct FunctionInfo {+ u32 id;+ Function func;+ std::string name;+ };+/*** Gets the UID for the serice* @return UID of service in native format@@ -51,6 +59,23 @@ public:return "[UNKNOWN SERVICE PORT]";}+ /// Allocates a new handle for the service+ Syscall::Handle NewHandle() {+ Syscall::Handle handle = (m_handles.size() << 16) | m_uid;+ m_handles.push_back(handle);+ return handle;+ }++ /// Frees a handle from the service+ void DeleteHandle(Syscall::Handle handle) {+ for(auto iter = m_handles.begin(); iter != m_handles.end(); ++iter) {+ if(*iter == handle) {+ m_handles.erase(iter);+ break;+ }+ }+ }+/*** Called when svcSendSyncRequest is called, loads command buffer and executes comand* @return Return result of svcSendSyncRequest passed back to user app@@ -70,16 +95,17 @@ public:return -1;}- itr->second.func();+ itr->second.func(this);return 0; // TODO: Implement return from actual function}protected:+/*** Registers the functions in the service*/- void Register(const HLE::FunctionDef* functions, int len) {+ void Register(const FunctionInfo* functions, int len) {for (int i = 0; i < len; i++) {m_functions[functions[i].id] = functions[i];}@@ -87,9 +113,9 @@ protected:private:u32 m_uid;- std::map<u32, HLE::FunctionDef> m_functions;-- DISALLOW_COPY_AND_ASSIGN(Interface);++ std::vector<Syscall::Handle> m_handles;+ std::map<u32, FunctionInfo> m_functions;};/// Simple class to manage accessing services from ports and UID handles@@ -126,8 +152,6 @@ private:std::vector<Interface*> m_services;std::map<std::string, u32> m_port_map;-- DISALLOW_COPY_AND_ASSIGN(Manager);};/// Initialize ServiceManagerdiff --git a/src/core/hle/service/srv.cpp b/src/core/hle/service/srv.cppindex 579ea4a344..9437868c56 100644--- a/src/core/hle/service/srv.cpp+++ b/src/core/hle/service/srv.cpp@@ -12,11 +12,11 @@namespace SRV {-void Initialize() {+void Initialize(Service::Interface* self) {NOTICE_LOG(OSHLE, "SRV::Sync - Initialize");}-void GetServiceHandle() {+void GetServiceHandle(Service::Interface* self) {Syscall::Result res = 0;u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + Service::kCommandHeaderOffset);@@ -37,7 +37,7 @@ void GetServiceHandle() {//return res;}-const HLE::FunctionDef FunctionTable[] = {+const Interface::FunctionInfo FunctionTable[] = {{0x00010002, Initialize, "Initialize"},{0x00020000, NULL, "GetProcSemaphore"},{0x00030100, NULL, "RegisterService"},