From 95f1c14dcfd8ade8801031c50c037e89a4390e47 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 9 Oct 2023 20:39:12 +0300 Subject: [PATCH 1/4] added pad functions parameters --- src/Emulator/HLE/Libraries/LibPad/pad.cpp | 3 +- src/Emulator/HLE/Libraries/LibPad/pad.h | 97 ++++++++++++------- .../Libraries/LibUserService/user_service.h | 2 + 3 files changed, 65 insertions(+), 37 deletions(-) diff --git a/src/Emulator/HLE/Libraries/LibPad/pad.cpp b/src/Emulator/HLE/Libraries/LibPad/pad.cpp index 71b66b3d..f7a350ee 100644 --- a/src/Emulator/HLE/Libraries/LibPad/pad.cpp +++ b/src/Emulator/HLE/Libraries/LibPad/pad.cpp @@ -6,7 +6,8 @@ namespace Emulator::HLE::Libraries::LibPad { int PS4_SYSV_ABI scePadInit() { return SCE_OK; } -int PS4_SYSV_ABI scePadOpen(/* SceUserServiceUserId userId, int32_t type, int32_t index, const ScePadOpenParam* pParam*/) { +int PS4_SYSV_ABI scePadOpen(Emulator::HLE::Libraries::LibUserService::SceUserServiceUserId userId, s32 type, s32 index, + const ScePadOpenParam* pParam) { return 1; // dummy } diff --git a/src/Emulator/HLE/Libraries/LibPad/pad.h b/src/Emulator/HLE/Libraries/LibPad/pad.h index e28f2004..24440295 100644 --- a/src/Emulator/HLE/Libraries/LibPad/pad.h +++ b/src/Emulator/HLE/Libraries/LibPad/pad.h @@ -1,51 +1,76 @@ #pragma once #include "Core/PS4/Loader/SymbolsResolver.h" +#include namespace Emulator::HLE::Libraries::LibPad { +struct ScePadOpenParam { + u08 reserve[8]; +}; + +struct ScePadAnalogStick { + u08 x; + u08 y; +}; +struct ScePadAnalogButtons { + u08 l2; + u08 r2; + u08 padding[2]; +}; + +struct SceFQuaternion { + float x, y, z, w; +}; + +struct SceFVector3 { + float x, y, z; +}; + +struct ScePadTouch { + u16 x; + u16 y; + u08 id; + u08 reserve[3]; +}; + +constexpr int SCE_PAD_MAX_TOUCH_NUM = 2; + +typedef struct ScePadTouchData { + u08 touchNum; + u08 reserve[3]; + u32 reserve1; + ScePadTouch touch[SCE_PAD_MAX_TOUCH_NUM]; +} ScePadTouchData; + +struct ScePadExtensionUnitData { + u32 extensionUnitId; + u08 reserve[1]; + u08 dataLength; + u08 data[10]; +}; + struct ScePadData { u32 buttons; - u08 left_stick_x; - u08 left_stick_y; - u08 right_stick_x; - u08 right_stick_y; - u08 analog_buttons_l2; - u08 analog_buttons_r2; - u08 padding[2]; - float orientation_x; - float orientation_y; - float orientation_z; - float orientation_w; - float acceleration_x; - float acceleration_y; - float acceleration_z; - float angular_velocity_x; - float angular_velocity_y; - float angular_velocity_z; - u08 touch_data_touch_num; - u08 touch_data_reserve[3]; - u32 touch_data_reserve1; - u16 touch_data_touch0_x; - u16 touch_data_touch0_y; - u08 touch_data_touch0_id; - u08 touch_data_touch0_reserve[3]; - u16 touch_data_touch1_x; - u16 touch_data_touch1_y; - u08 touch_data_touch1_id; - u08 touch_data_touch1_reserve[3]; + ScePadAnalogStick leftStick; + ScePadAnalogStick rightStick; + ScePadAnalogButtons analogButtons; + SceFQuaternion orientation; + SceFVector3 acceleration; + SceFVector3 angularVelocity; + ScePadTouchData touchData; bool connected; u64 timestamp; - u32 extension_unit_data_extension_unit_id; - u08 extension_unit_data_reserve[1]; - u08 extension_unit_data_data_length; - u08 extension_unit_data_data[10]; - u08 connected_count; - u08 reserve[2]; - u08 device_unique_data_len; - u08 device_unique_data[12]; + ScePadExtensionUnitData extensionUnitData; + uint8_t connectedCount; + uint8_t reserve[2]; + uint8_t deviceUniqueDataLen; + uint8_t deviceUniqueData[12]; }; // hle functions int PS4_SYSV_ABI scePadInit(); +int PS4_SYSV_ABI scePadOpen(Emulator::HLE::Libraries::LibUserService::SceUserServiceUserId userId, s32 type, s32 index, + const ScePadOpenParam* pParam); +int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData); void libPad_Register(SymbolsResolver* sym); }; // namespace Emulator::HLE::Libraries::LibPad \ No newline at end of file diff --git a/src/Emulator/HLE/Libraries/LibUserService/user_service.h b/src/Emulator/HLE/Libraries/LibUserService/user_service.h index ecdcf044..6c22c217 100644 --- a/src/Emulator/HLE/Libraries/LibUserService/user_service.h +++ b/src/Emulator/HLE/Libraries/LibUserService/user_service.h @@ -3,6 +3,8 @@ namespace Emulator::HLE::Libraries::LibUserService { +using SceUserServiceUserId = s32; + struct SceUserServiceInitializeParams { s32 priority; }; From da9adf84c070e9c14f5d653d2f8098a645bf6fcf Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Fri, 13 Oct 2023 09:40:59 +0300 Subject: [PATCH 2/4] some work on pad emulation (WIP) --- CMakeLists.txt | 7 +++ .../HLE/Graphics/Objects/video_out_ctx.cpp | 2 +- .../PS4/HLE/Graphics/Objects/video_out_ctx.h | 2 +- src/Core/PS4/HLE/Graphics/graphics_render.cpp | 2 +- src/Core/PS4/HLE/Graphics/video_out.cpp | 2 +- src/Core/PS4/HLE/LibSceGnmDriver.cpp | 2 +- .../HLE/Libraries/LibPad/controller.cpp | 51 +++++++++++++++++++ .../HLE/Libraries/LibPad/controller.h | 33 ++++++++++++ src/Emulator/HLE/Libraries/LibPad/pad.cpp | 28 +++++++++- src/Emulator/HLE/Libraries/LibPad/pad.h | 24 ++++++++- src/Emulator/Util/singleton.h | 24 +++++++++ src/emulator.cpp | 37 +++++++++++--- src/emulator.h | 3 +- src/main.cpp | 47 +++++++++-------- src/vulkan_util.cpp | 40 +++++++-------- src/vulkan_util.h | 22 ++++---- 16 files changed, 255 insertions(+), 71 deletions(-) create mode 100644 src/Emulator/HLE/Libraries/LibPad/controller.cpp create mode 100644 src/Emulator/HLE/Libraries/LibPad/controller.h create mode 100644 src/Emulator/Util/singleton.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9062fb2c..dc6db498 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,17 +34,24 @@ set(USERSERVICE_SOURCES src/Emulator/HLE/Libraries/LibUserService/user_service.c set(PAD_SOURCES src/Emulator/HLE/Libraries/LibPad/pad.cpp src/Emulator/HLE/Libraries/LibPad/pad.h + src/Emulator/HLE/Libraries/LibPad/controller.cpp + src/Emulator/HLE/Libraries/LibPad/controller.h + ) set(SYSTEMSERVICE_SOURCES src/Emulator/HLE/Libraries/LibSystemService/system_service.cpp src/Emulator/HLE/Libraries/LibSystemService/system_service.h ) +set(UTIL_SOURCES src/Emulator/Util/singleton.h +) + add_executable(shadps4 ${LIBC_SOURCES} ${USERSERVICE_SOURCES} ${PAD_SOURCES} ${SYSTEMSERVICE_SOURCES} + ${UTIL_SOURCES} src/main.cpp src/types.h src/Core/FsFile.cpp diff --git a/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp b/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp index aa77713d..4beca2de 100644 --- a/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp +++ b/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp @@ -78,7 +78,7 @@ bool FlipQueue::flip(u32 micros) { auto* buffer = request.cfg->buffers[request.index].buffer_render; - Emulator::DrawBuffer(buffer); + Emu::DrawBuffer(buffer); m_mutex.LockMutex(); diff --git a/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h b/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h index 6ce3c755..7c2f93d6 100644 --- a/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h +++ b/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h @@ -64,7 +64,7 @@ class VideoOutCtx { Lib::LockMutexGuard lock(m_mutex); if (m_graphic_ctx == nullptr) { - m_graphic_ctx = Emulator::getGraphicCtx(); + m_graphic_ctx = Emu::getGraphicCtx(); } return m_graphic_ctx; diff --git a/src/Core/PS4/HLE/Graphics/graphics_render.cpp b/src/Core/PS4/HLE/Graphics/graphics_render.cpp index e02bdf7b..65a518e3 100644 --- a/src/Core/PS4/HLE/Graphics/graphics_render.cpp +++ b/src/Core/PS4/HLE/Graphics/graphics_render.cpp @@ -8,7 +8,7 @@ static thread_local GPU::CommandPool g_command_pool; void GPU::renderCreateCtx() { auto* render_ctx = Singleton::Instance(); - render_ctx->setGraphicCtx(Emulator::getGraphicCtx()); + render_ctx->setGraphicCtx(Emu::getGraphicCtx()); } void GPU::CommandBuffer::allocateBuffer() { diff --git a/src/Core/PS4/HLE/Graphics/video_out.cpp b/src/Core/PS4/HLE/Graphics/video_out.cpp index 1ffdb204..107c254e 100644 --- a/src/Core/PS4/HLE/Graphics/video_out.cpp +++ b/src/Core/PS4/HLE/Graphics/video_out.cpp @@ -164,7 +164,7 @@ s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* co int registration_index = ctx->buffers_registration_index++; - Emulator::checkAndWaitForGraphicsInit(); + Emu::checkAndWaitForGraphicsInit(); GPU::renderCreateCtx(); // try to calculate buffer size diff --git a/src/Core/PS4/HLE/LibSceGnmDriver.cpp b/src/Core/PS4/HLE/LibSceGnmDriver.cpp index 9744b23f..b87b290f 100644 --- a/src/Core/PS4/HLE/LibSceGnmDriver.cpp +++ b/src/Core/PS4/HLE/LibSceGnmDriver.cpp @@ -91,7 +91,7 @@ namespace HLE::Libs::LibSceGnmDriver { void sceGnmDriverTriggerCapture(){} void sceGnmEndWorkload(){} void sceGnmFlushGarlic() { PRINT_FUNCTION_NAME(); - GPU::flushGarlic(Emulator::getGraphicCtx()); + GPU::flushGarlic(Emu::getGraphicCtx()); } void sceGnmGetEqEventType(){} void sceGnmGetEqTimeStamp(){} diff --git a/src/Emulator/HLE/Libraries/LibPad/controller.cpp b/src/Emulator/HLE/Libraries/LibPad/controller.cpp new file mode 100644 index 00000000..04ae4a9a --- /dev/null +++ b/src/Emulator/HLE/Libraries/LibPad/controller.cpp @@ -0,0 +1,51 @@ +#include "controller.h" + +namespace Emulator::Host::Controller { +GameController::GameController() { m_states_num = 0; + m_last_state = State(); +} +void GameController::readState(State* state, bool* isConnected, int* connectedCount) { + Lib::LockMutexGuard lock(m_mutex); + + *isConnected = m_connected; + *connectedCount = m_connected_count; + *state = getLastState(); +} + +State GameController::getLastState() const { + if (m_states_num == 0) { + return m_last_state; + } + + auto last = (m_first_state + m_states_num - 1) % MAX_STATES; + + return m_states[last]; +} + +void GameController::addState(const State& state) { + if (m_states_num >= MAX_STATES) { + m_states_num = MAX_STATES - 1; + m_first_state = (m_first_state + 1) % MAX_STATES; + } + + auto index = (m_first_state + m_states_num) % MAX_STATES; + + m_states[index] = state; + m_last_state = state; + + m_states_num++; +} + +void GameController::checKButton(int id, u32 button, bool isPressed) { + Lib::LockMutexGuard lock(m_mutex); + auto state = getLastState(); + if (isPressed) { + state.buttonsState |= button; + } else { + state.buttonsState &= ~button; + } + + addState(state); +} + +} // namespace Emulator::Host::Controller \ No newline at end of file diff --git a/src/Emulator/HLE/Libraries/LibPad/controller.h b/src/Emulator/HLE/Libraries/LibPad/controller.h new file mode 100644 index 00000000..50dabcb2 --- /dev/null +++ b/src/Emulator/HLE/Libraries/LibPad/controller.h @@ -0,0 +1,33 @@ +#pragma once +#include +#include "Lib/Threads.h" + +namespace Emulator::Host::Controller { +struct State { + u32 buttonsState; +}; + +constexpr u32 MAX_STATES = 64; + +class GameController { + public: + GameController(); + virtual ~GameController() = default; + + void readState(State* state, bool* isConnected, int* connectedCount); + State getLastState() const; + void checKButton(int id, u32 button, bool isPressed); + void addState(const State& state); + + + private: + Lib::Mutex m_mutex; + bool m_connected = false; + State m_last_state; + int m_connected_count = 0; + u32 m_states_num = 0; + u32 m_first_state = 0; + State m_states[MAX_STATES]; +}; + +} // namespace Emulator::HLE::Libraries::Controller \ No newline at end of file diff --git a/src/Emulator/HLE/Libraries/LibPad/pad.cpp b/src/Emulator/HLE/Libraries/LibPad/pad.cpp index f7a350ee..6da03cf1 100644 --- a/src/Emulator/HLE/Libraries/LibPad/pad.cpp +++ b/src/Emulator/HLE/Libraries/LibPad/pad.cpp @@ -3,6 +3,9 @@ #include #include +#include "Emulator/Util/singleton.h" +#include "controller.h" + namespace Emulator::HLE::Libraries::LibPad { int PS4_SYSV_ABI scePadInit() { return SCE_OK; } @@ -12,7 +15,30 @@ int PS4_SYSV_ABI scePadOpen(Emulator::HLE::Libraries::LibUserService::SceUserSer } int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData) { - pData->connected = true; // make it think it is connected + auto* controller = singleton::instance(); + + int connectedCount = 0; + bool isConnected = false; + Emulator::Host::Controller::State state; + + controller->readState(&state, &isConnected, &connectedCount); + + pData->buttons = state.buttonsState; + pData->leftStick.x = 0; // dummy + pData->leftStick.y = 0; // dummy + pData->rightStick.x = 0; // dummy + pData->rightStick.y = 0; // dummy + pData->analogButtons.r2 = 0;//dummy + pData->analogButtons.l2 = 0;//dummy + pData->orientation.x = 0; + pData->orientation.y = 0; + pData->orientation.z = 0; + pData->orientation.w = 0; + + pData->connected = true; // isConnected; //TODO fix me proper + pData->connectedCount = 1;//connectedCount; + pData->deviceUniqueDataLen = 0; + return SCE_OK; } diff --git a/src/Emulator/HLE/Libraries/LibPad/pad.h b/src/Emulator/HLE/Libraries/LibPad/pad.h index 24440295..72d09726 100644 --- a/src/Emulator/HLE/Libraries/LibPad/pad.h +++ b/src/Emulator/HLE/Libraries/LibPad/pad.h @@ -1,9 +1,31 @@ #pragma once -#include "Core/PS4/Loader/SymbolsResolver.h" #include +#include + +#include "Core/PS4/Loader/SymbolsResolver.h" namespace Emulator::HLE::Libraries::LibPad { +typedef enum : u32 { + SCE_PAD_BUTTON_L3 = 0x00000002, + SCE_PAD_BUTTON_R3 = 0x00000004, + SCE_PAD_BUTTON_OPTIONS = 0x00000008, + SCE_PAD_BUTTON_UP = 0x00000010, + SCE_PAD_BUTTON_RIGHT = 0x00000020, + SCE_PAD_BUTTON_DOWN = 0x00000040, + SCE_PAD_BUTTON_LEFT = 0x00000080, + SCE_PAD_BUTTON_L2 = 0x00000100, + SCE_PAD_BUTTON_R2 = 0x00000200, + SCE_PAD_BUTTON_L1 = 0x00000400, + SCE_PAD_BUTTON_R1 = 0x00000800, + SCE_PAD_BUTTON_TRIANGLE = 0x00001000, + SCE_PAD_BUTTON_CIRCLE = 0x00002000, + SCE_PAD_BUTTON_CROSS = 0x00004000, + SCE_PAD_BUTTON_SQUARE = 0x00008000, + SCE_PAD_BUTTON_TOUCH_PAD = 0x00100000, + SCE_PAD_BUTTON_INTERCEPTED = 0x80000000, +} ScePadButton; + struct ScePadOpenParam { u08 reserve[8]; }; diff --git a/src/Emulator/Util/singleton.h b/src/Emulator/Util/singleton.h new file mode 100644 index 00000000..a401a380 --- /dev/null +++ b/src/Emulator/Util/singleton.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + +template +class singleton { + public: + static T* instance() { + if (!m_instance) { + m_instance = static_cast(std::malloc(sizeof(T))); + new (m_instance) T; + } + + return m_instance; + } + + protected: + singleton(); + ~singleton(); + + private: + static inline T* m_instance = nullptr; +}; \ No newline at end of file diff --git a/src/emulator.cpp b/src/emulator.cpp index 5c7fd71c..1ea83010 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -5,21 +5,23 @@ #include #include "Core/PS4/HLE/Graphics/video_out.h" +#include "Emulator/HLE/Libraries/LibPad/pad.h" #include "version.h" +#include -namespace Emulator { +namespace Emu { bool m_emu_needs_exit = false; void emuInit(u32 width, u32 height) { - auto* window_ctx = Singleton::Instance(); + auto* window_ctx = Singleton::Instance(); window_ctx->m_graphic_ctx.screen_width = width; window_ctx->m_graphic_ctx.screen_height = height; } void checkAndWaitForGraphicsInit() { - auto* window_ctx = Singleton::Instance(); + auto* window_ctx = Singleton::Instance(); Lib::LockMutexGuard lock(window_ctx->m_mutex); while (!window_ctx->m_is_graphic_initialized) { @@ -48,7 +50,7 @@ static void CreateSdlWindow(WindowCtx* ctx) { SDL_SetWindowResizable(ctx->m_window, SDL_FALSE); // we don't support resizable atm } void emuRun() { - auto* window_ctx = Singleton::Instance(); + auto* window_ctx = Singleton::Instance(); window_ctx->m_mutex.LockMutex(); { // init window and wait until init finishes @@ -82,7 +84,7 @@ void emuRun() { case SDL_EVENT_DID_ENTER_FOREGROUND: break; case SDL_EVENT_KEY_DOWN: - case SDL_EVENT_KEY_UP: break; + case SDL_EVENT_KEY_UP: keyboardEvent(&event); break; } continue; } @@ -96,14 +98,14 @@ void emuRun() { } HLE::Libs::Graphics::GraphicCtx* getGraphicCtx() { - auto* window_ctx = Singleton::Instance(); + auto* window_ctx = Singleton::Instance(); Lib::LockMutexGuard lock(window_ctx->m_mutex); return &window_ctx->m_graphic_ctx; } void DrawBuffer(HLE::Libs::Graphics::VideoOutVulkanImage* image) { - auto* window_ctx = Singleton::Instance(); + auto* window_ctx = Singleton::Instance(); if (window_ctx->is_window_hidden) { SDL_ShowWindow(window_ctx->m_window); window_ctx->is_window_hidden = false; @@ -198,4 +200,23 @@ void DrawBuffer(HLE::Libs::Graphics::VideoOutVulkanImage* image) { } } -} // namespace Emulator \ No newline at end of file +void keyboardEvent(SDL_Event* event) { + using Emulator::HLE::Libraries::LibPad::ScePadButton; + + if (event->type == SDL_EVENT_KEY_DOWN || event->type == SDL_EVENT_KEY_UP) { + u32 button = 0; + switch (event->key.keysym.sym) { + case SDLK_UP: button = ScePadButton::SCE_PAD_BUTTON_UP; break; + case SDLK_DOWN: button = ScePadButton::SCE_PAD_BUTTON_DOWN; break; + case SDLK_LEFT: button = ScePadButton::SCE_PAD_BUTTON_LEFT; break; + case SDLK_RIGHT: button = ScePadButton::SCE_PAD_BUTTON_RIGHT; break; + default: break; + } + if (button != 0) { + auto* controller = Singleton::Instance(); + controller->checKButton(0, button, event->type == SDL_EVENT_KEY_DOWN); + } + } +} + +} // namespace Emu \ No newline at end of file diff --git a/src/emulator.h b/src/emulator.h index b3d2c0e3..a929250d 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -5,7 +5,7 @@ #include -namespace Emulator { +namespace Emu { struct VulkanExt { bool enable_validation_layers = false; @@ -81,4 +81,5 @@ void emuRun(); void checkAndWaitForGraphicsInit(); HLE::Libs::Graphics::GraphicCtx* getGraphicCtx(); void DrawBuffer(HLE::Libs::Graphics::VideoOutVulkanImage* image); +void keyboardEvent(SDL_Event* event); } // namespace Emulator \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 58b25aa5..3cc8f3c5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,41 +3,43 @@ // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. // Read online: https://github.com/ocornut/imgui/tree/master/docs -#include "imgui.h" -#include "imgui_impl_sdl3.h" -#include "imgui_impl_opengl3.h" -#include #include +#include + +#include "imgui.h" +#include "imgui_impl_opengl3.h" +#include "imgui_impl_sdl3.h" #if defined(IMGUI_IMPL_OPENGL_ES2) #include #else #include #endif +#include + +#include "GUI/ElfViewer.h" #include "spdlog/spdlog.h" #include "types.h" -#include "GUI/ElfViewer.h" -#include // This example can also compile and run with Emscripten! See 'Makefile.emscripten' for details. #ifdef __EMSCRIPTEN__ #include "../libs/emscripten/emscripten_mainloop_stub.h" #endif -#include "Core/PS4/Linker.h" -#include "Util/Singleton.h" -#include -#include -#include -#include "Core/PS4/HLE/Libs.h" -#include "Lib/Threads.h" -#include -#include "discord.h" -#include #include +#include +#include +#include +#include +#include + +#include "Core/PS4/HLE/Libs.h" +#include "Core/PS4/Linker.h" +#include "Lib/Threads.h" +#include "Util/Singleton.h" +#include "discord.h" // Main code -int main(int argc, char* argv[]) -{ +int main(int argc, char* argv[]) { if (argc == 1) { printf("Usage: %s \n", argv[0]); return -1; @@ -46,7 +48,7 @@ int main(int argc, char* argv[]) logging::init(true); // init logging auto width = Config::getScreenWidth(); auto height = Config::getScreenHeight(); - Emulator::emuInit(width, height); + Emu::emuInit(width, height); HLE::Libs::Graphics::VideoOut::videoOutInit(width, height); Lib::InitThreads(); @@ -54,7 +56,7 @@ int main(int argc, char* argv[]) auto* linker = Singleton::Instance(); HLE::Libs::Init_HLE_Libs(linker->getHLESymbols()); - auto *module =linker->LoadModule(path);//load main executable + auto* module = linker->LoadModule(path); // load main executable Lib::Thread mainthread( [](void*) { auto* linker = Singleton::Instance(); @@ -65,12 +67,9 @@ int main(int argc, char* argv[]) Discord::RPC discordRPC; discordRPC.init(); discordRPC.update(Discord::RPCStatus::Idling, ""); - Emulator::emuRun(); + Emu::emuRun(); mainthread.JoinThread(); - - - #if 0 // Setup SDL if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMEPAD) != 0) diff --git a/src/vulkan_util.cpp b/src/vulkan_util.cpp index 42bf21eb..dac3e5fe 100644 --- a/src/vulkan_util.cpp +++ b/src/vulkan_util.cpp @@ -12,8 +12,8 @@ constexpr bool log_file_vulkanutil = true; // disable it to disable logging -void Graphics::Vulkan::vulkanCreate(Emulator::WindowCtx* ctx) { - Emulator::VulkanExt ext; +void Graphics::Vulkan::vulkanCreate(Emu::WindowCtx* ctx) { + Emu::VulkanExt ext; vulkanGetInstanceExtensions(&ext); VkApplicationInfo app_info{}; @@ -53,8 +53,8 @@ void Graphics::Vulkan::vulkanCreate(Emulator::WindowCtx* ctx) { std::vector device_extensions = {VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_EXT_DEPTH_CLIP_ENABLE_EXTENSION_NAME, VK_EXT_COLOR_WRITE_ENABLE_EXTENSION_NAME, "VK_KHR_maintenance1"}; - ctx->m_surface_capabilities = new Emulator::VulkanSurfaceCapabilities{}; - Emulator::VulkanQueues queues; + ctx->m_surface_capabilities = new Emu::VulkanSurfaceCapabilities{}; + Emu::VulkanQueues queues; vulkanFindCompatiblePhysicalDevice(ctx->m_graphic_ctx.m_instance, ctx->m_surface, device_extensions, ctx->m_surface_capabilities, &ctx->m_graphic_ctx.m_physical_device, &queues); @@ -79,11 +79,11 @@ void Graphics::Vulkan::vulkanCreate(Emulator::WindowCtx* ctx) { ctx->swapchain = vulkanCreateSwapchain(&ctx->m_graphic_ctx, 2); } -Emulator::VulkanSwapchain* Graphics::Vulkan::vulkanCreateSwapchain(HLE::Libs::Graphics::GraphicCtx* ctx, u32 image_count) { - auto* window_ctx = Singleton::Instance(); +Emu::VulkanSwapchain* Graphics::Vulkan::vulkanCreateSwapchain(HLE::Libs::Graphics::GraphicCtx* ctx, u32 image_count) { + auto* window_ctx = Singleton::Instance(); Lib::LockMutexGuard lock(window_ctx->m_mutex); - auto* s = new Emulator::VulkanSwapchain; + auto* s = new Emu::VulkanSwapchain; VkExtent2D extent{}; extent.width = clamp(ctx->screen_width, window_ctx->m_surface_capabilities->capabilities.minImageExtent.width, @@ -183,8 +183,8 @@ Emulator::VulkanSwapchain* Graphics::Vulkan::vulkanCreateSwapchain(HLE::Libs::Gr return s; } -void Graphics::Vulkan::vulkanCreateQueues(HLE::Libs::Graphics::GraphicCtx* ctx, const Emulator::VulkanQueues& queues) { - auto get_queue = [ctx](int id, const Emulator::VulkanQueueInfo& info, bool with_mutex = false) { +void Graphics::Vulkan::vulkanCreateQueues(HLE::Libs::Graphics::GraphicCtx* ctx, const Emu::VulkanQueues& queues) { + auto get_queue = [ctx](int id, const Emu::VulkanQueueInfo& info, bool with_mutex = false) { ctx->queues[id].family = info.family; ctx->queues[id].index = info.index; vkGetDeviceQueue(ctx->m_device, ctx->queues[id].family, ctx->queues[id].index, &ctx->queues[id].vk_queue); @@ -203,8 +203,8 @@ void Graphics::Vulkan::vulkanCreateQueues(HLE::Libs::Graphics::GraphicCtx* ctx, } } -VkDevice Graphics::Vulkan::vulkanCreateDevice(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const Emulator::VulkanExt* r, - const Emulator::VulkanQueues& queues, const std::vector& device_extensions) { +VkDevice Graphics::Vulkan::vulkanCreateDevice(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const Emu::VulkanExt* r, + const Emu::VulkanQueues& queues, const std::vector& device_extensions) { std::vector queue_create_info(queues.family_count); std::vector> queue_priority(queues.family_count); uint32_t queue_create_info_num = 0; @@ -247,7 +247,7 @@ VkDevice Graphics::Vulkan::vulkanCreateDevice(VkPhysicalDevice physical_device, return device; } -void Graphics::Vulkan::vulkanGetInstanceExtensions(Emulator::VulkanExt* ext) { +void Graphics::Vulkan::vulkanGetInstanceExtensions(Emu::VulkanExt* ext) { u32 required_extensions_count = 0; u32 available_extensions_count = 0; u32 available_layers_count = 0; @@ -283,8 +283,8 @@ void Graphics::Vulkan::vulkanGetInstanceExtensions(Emulator::VulkanExt* ext) { void Graphics::Vulkan::vulkanFindCompatiblePhysicalDevice(VkInstance instance, VkSurfaceKHR surface, const std::vector& device_extensions, - Emulator::VulkanSurfaceCapabilities* out_capabilities, VkPhysicalDevice* out_device, - Emulator::VulkanQueues* out_queues) { + Emu::VulkanSurfaceCapabilities* out_capabilities, VkPhysicalDevice* out_device, + Emu::VulkanQueues* out_queues) { u32 count_devices = 0; vkEnumeratePhysicalDevices(instance, &count_devices, nullptr); @@ -292,7 +292,7 @@ void Graphics::Vulkan::vulkanFindCompatiblePhysicalDevice(VkInstance instance, V vkEnumeratePhysicalDevices(instance, &count_devices, devices.data()); VkPhysicalDevice found_best_device = nullptr; - Emulator::VulkanQueues found_best_queues; + Emu::VulkanQueues found_best_queues; for (const auto& device : devices) { VkPhysicalDeviceProperties device_properties{}; @@ -316,8 +316,8 @@ void Graphics::Vulkan::vulkanFindCompatiblePhysicalDevice(VkInstance instance, V *out_queues = found_best_queues; } -Emulator::VulkanQueues Graphics::Vulkan::vulkanFindQueues(VkPhysicalDevice device, VkSurfaceKHR surface) { - Emulator::VulkanQueues qs; +Emu::VulkanQueues Graphics::Vulkan::vulkanFindQueues(VkPhysicalDevice device, VkSurfaceKHR surface) { + Emu::VulkanQueues qs; u32 queue_family_count = 0; vkGetPhysicalDeviceQueueFamilyProperties(device, &queue_family_count, nullptr); @@ -334,7 +334,7 @@ Emulator::VulkanQueues Graphics::Vulkan::vulkanFindQueues(VkPhysicalDevice devic LOG_INFO_IF(log_file_vulkanutil, "queue family: {}, count = {}, present = {}\n", string_VkQueueFlags(f.queueFlags).c_str(), f.queueCount, (presentation_supported == VK_TRUE ? "true" : "false")); for (uint32_t i = 0; i < f.queueCount; i++) { - Emulator::VulkanQueueInfo info; + Emu::VulkanQueueInfo info; info.family = family; info.index = i; info.is_graphics = (f.queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0; @@ -401,7 +401,7 @@ Emulator::VulkanQueues Graphics::Vulkan::vulkanFindQueues(VkPhysicalDevice devic } void Graphics::Vulkan::vulkanGetSurfaceCapabilities(VkPhysicalDevice physical_device, VkSurfaceKHR surface, - Emulator::VulkanSurfaceCapabilities* surfaceCap) { + Emu::VulkanSurfaceCapabilities* surfaceCap) { vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, surface, &surfaceCap->capabilities); uint32_t formats_count = 0; @@ -488,7 +488,7 @@ static void set_image_layout(VkCommandBuffer buffer, HLE::Libs::Graphics::Vulkan } void Graphics::Vulkan::vulkanBlitImage(GPU::CommandBuffer* buffer, HLE::Libs::Graphics::VulkanImage* src_image, - Emulator::VulkanSwapchain* dst_swapchain) { + Emu::VulkanSwapchain* dst_swapchain) { auto* vk_buffer = buffer->getPool()->buffers[buffer->getIndex()]; HLE::Libs::Graphics::VulkanImage swapchain_image(HLE::Libs::Graphics::VulkanImageType::Unknown); diff --git a/src/vulkan_util.h b/src/vulkan_util.h index e25d9880..6230e76b 100644 --- a/src/vulkan_util.h +++ b/src/vulkan_util.h @@ -26,18 +26,18 @@ const T& clamp(const T& x, const T& min, const T& max) { return x; } -void vulkanCreate(Emulator::WindowCtx* ctx); -void vulkanGetInstanceExtensions(Emulator::VulkanExt* ext); +void vulkanCreate(Emu::WindowCtx* ctx); +void vulkanGetInstanceExtensions(Emu::VulkanExt* ext); void vulkanFindCompatiblePhysicalDevice(VkInstance instance, VkSurfaceKHR surface, const std::vector& device_extensions, - Emulator::VulkanSurfaceCapabilities* out_capabilities, VkPhysicalDevice* out_device, - Emulator::VulkanQueues* out_queues); -VkDevice vulkanCreateDevice(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const Emulator::VulkanExt* r, - const Emulator::VulkanQueues& queues, const std::vector& device_extensions); -Emulator::VulkanQueues vulkanFindQueues(VkPhysicalDevice device, VkSurfaceKHR surface); -void vulkanGetSurfaceCapabilities(VkPhysicalDevice physical_device, VkSurfaceKHR surface, Emulator::VulkanSurfaceCapabilities* surfaceCap); -void vulkanCreateQueues(HLE::Libs::Graphics::GraphicCtx* ctx, const Emulator::VulkanQueues& queues); -Emulator::VulkanSwapchain* vulkanCreateSwapchain(HLE::Libs::Graphics::GraphicCtx* ctx, u32 image_count); -void vulkanBlitImage(GPU::CommandBuffer* buffer, HLE::Libs::Graphics::VulkanImage* src_image, Emulator::VulkanSwapchain* dst_swapchain); + Emu::VulkanSurfaceCapabilities* out_capabilities, VkPhysicalDevice* out_device, + Emu::VulkanQueues* out_queues); +VkDevice vulkanCreateDevice(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const Emu::VulkanExt* r, + const Emu::VulkanQueues& queues, const std::vector& device_extensions); +Emu::VulkanQueues vulkanFindQueues(VkPhysicalDevice device, VkSurfaceKHR surface); +void vulkanGetSurfaceCapabilities(VkPhysicalDevice physical_device, VkSurfaceKHR surface, Emu::VulkanSurfaceCapabilities* surfaceCap); +void vulkanCreateQueues(HLE::Libs::Graphics::GraphicCtx* ctx, const Emu::VulkanQueues& queues); +Emu::VulkanSwapchain* vulkanCreateSwapchain(HLE::Libs::Graphics::GraphicCtx* ctx, u32 image_count); +void vulkanBlitImage(GPU::CommandBuffer* buffer, HLE::Libs::Graphics::VulkanImage* src_image, Emu::VulkanSwapchain* dst_swapchain); void vulkanFillImage(HLE::Libs::Graphics::GraphicCtx* ctx, HLE::Libs::Graphics::VulkanImage* dst_image, const void* src_data, u64 size, u32 src_pitch, u64 dst_layout); void vulkanBufferToImage(GPU::CommandBuffer* buffer, HLE::Libs::Graphics::VulkanBuffer* src_buffer, u32 src_pitch, From e1b64617a80c57d9be4a3df20c4d369280b9f8a1 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Fri, 13 Oct 2023 17:44:15 +0300 Subject: [PATCH 3/4] pad somehow working --- src/Emulator/HLE/Libraries/LibPad/controller.h | 2 +- src/Emulator/HLE/Libraries/LibPad/pad.cpp | 14 +++++++++----- src/emulator.cpp | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Emulator/HLE/Libraries/LibPad/controller.h b/src/Emulator/HLE/Libraries/LibPad/controller.h index 50dabcb2..4158ef3c 100644 --- a/src/Emulator/HLE/Libraries/LibPad/controller.h +++ b/src/Emulator/HLE/Libraries/LibPad/controller.h @@ -4,7 +4,7 @@ namespace Emulator::Host::Controller { struct State { - u32 buttonsState; + u32 buttonsState =0; }; constexpr u32 MAX_STATES = 64; diff --git a/src/Emulator/HLE/Libraries/LibPad/pad.cpp b/src/Emulator/HLE/Libraries/LibPad/pad.cpp index 6da03cf1..26b252f0 100644 --- a/src/Emulator/HLE/Libraries/LibPad/pad.cpp +++ b/src/Emulator/HLE/Libraries/LibPad/pad.cpp @@ -3,10 +3,15 @@ #include #include -#include "Emulator/Util/singleton.h" +#include "Util/Singleton.h" #include "controller.h" +#include +#include namespace Emulator::HLE::Libraries::LibPad { + +constexpr bool log_file_pad = true; // disable it to disable logging + int PS4_SYSV_ABI scePadInit() { return SCE_OK; } int PS4_SYSV_ABI scePadOpen(Emulator::HLE::Libraries::LibUserService::SceUserServiceUserId userId, s32 type, s32 index, @@ -15,17 +20,16 @@ int PS4_SYSV_ABI scePadOpen(Emulator::HLE::Libraries::LibUserService::SceUserSer } int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData) { - auto* controller = singleton::instance(); + auto* controller = Singleton::Instance(); int connectedCount = 0; bool isConnected = false; Emulator::Host::Controller::State state; controller->readState(&state, &isConnected, &connectedCount); - pData->buttons = state.buttonsState; - pData->leftStick.x = 0; // dummy - pData->leftStick.y = 0; // dummy + pData->leftStick.x = 128; // dummy + pData->leftStick.y = 128; // dummy pData->rightStick.x = 0; // dummy pData->rightStick.y = 0; // dummy pData->analogButtons.r2 = 0;//dummy diff --git a/src/emulator.cpp b/src/emulator.cpp index 1ea83010..95735507 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -1,13 +1,13 @@ #include "emulator.h" #include +#include #include #include #include "Core/PS4/HLE/Graphics/video_out.h" #include "Emulator/HLE/Libraries/LibPad/pad.h" #include "version.h" -#include namespace Emu { From 5a905b0c4f175f018e06d91a5500a9dcb6df9994 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Fri, 13 Oct 2023 20:41:03 +0300 Subject: [PATCH 4/4] map for dpad keys to emulator --- src/emulator.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/emulator.cpp b/src/emulator.cpp index 95735507..bccabe81 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -210,6 +210,12 @@ void keyboardEvent(SDL_Event* event) { case SDLK_DOWN: button = ScePadButton::SCE_PAD_BUTTON_DOWN; break; case SDLK_LEFT: button = ScePadButton::SCE_PAD_BUTTON_LEFT; break; case SDLK_RIGHT: button = ScePadButton::SCE_PAD_BUTTON_RIGHT; break; + case SDLK_KP_8: button = ScePadButton ::SCE_PAD_BUTTON_TRIANGLE; break; + case SDLK_KP_6: button = ScePadButton ::SCE_PAD_BUTTON_CIRCLE; break; + case SDLK_KP_2: button = ScePadButton ::SCE_PAD_BUTTON_CROSS; break; + case SDLK_KP_4: button = ScePadButton ::SCE_PAD_BUTTON_SQUARE; break; + case SDLK_RETURN: button = ScePadButton ::SCE_PAD_BUTTON_OPTIONS; break; + default: break; } if (button != 0) {