diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f7b16fa..82488063 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ add_executable(shadps4 src/Core/PS4/HLE/Kernel/event_queues.h src/Core/PS4/HLE/Kernel/cpu_management.cpp src/Core/PS4/HLE/Kernel/cpu_management.h - "src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h" "src/debug.h" "src/Core/PS4/HLE/Kernel/memory_management.cpp" "src/Core/PS4/HLE/Kernel/memory_management.h" "src/Core/PS4/GPU/gpu_memory.cpp" "src/Core/PS4/GPU/gpu_memory.h" "src/emulator.cpp" "src/emulator.h" "src/Core/PS4/HLE/Kernel/Objects/event_queue.h" "src/Core/PS4/HLE/Kernel/Objects/event_queue.cpp" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h") + "src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h" "src/debug.h" "src/Core/PS4/HLE/Kernel/memory_management.cpp" "src/Core/PS4/HLE/Kernel/memory_management.h" "src/Core/PS4/GPU/gpu_memory.cpp" "src/Core/PS4/GPU/gpu_memory.h" "src/emulator.cpp" "src/emulator.h" "src/Core/PS4/HLE/Kernel/Objects/event_queue.h" "src/Core/PS4/HLE/Kernel/Objects/event_queue.cpp" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h" "src/Core/PS4/HLE/Graphics/graphics_ctx.h") find_package(OpenGL REQUIRED) target_link_libraries(shadps4 PUBLIC fmt mincore spdlog IMGUI SDL3-shared ${OPENGL_LIBRARY}) diff --git a/src/Core/PS4/HLE/Graphics/graphics_ctx.h b/src/Core/PS4/HLE/Graphics/graphics_ctx.h new file mode 100644 index 00000000..782b66f3 --- /dev/null +++ b/src/Core/PS4/HLE/Graphics/graphics_ctx.h @@ -0,0 +1,9 @@ +#pragma once +#include + +namespace HLE::Libs::Graphics { +struct GraphicCtx { + u32 screen_width = 0; + u32 screen_height = 0; +}; +} // namespace HLE::Libs::Graphics \ No newline at end of file diff --git a/src/emulator.cpp b/src/emulator.cpp index 98227499..1ae080bf 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -1,11 +1,53 @@ #include "emulator.h" + #include "Core/PS4/HLE/Graphics/video_out.h" namespace Emulator { -void emuInit() {} -void emuRun() { - for (;;) { - HLE::Libs::Graphics::VideoOut::videoOutFlip(100000);//flip every 0.1 sec - } + +static WindowCtx* g_window_ctx = nullptr; + +void emuInit(u32 width, u32 height) { + g_window_ctx = new WindowCtx; + + g_window_ctx->m_graphic_ctx.screen_width = width; + g_window_ctx->m_graphic_ctx.screen_height = height; } -} // namespace emulator \ No newline at end of file + +static void CreateSdlWindow(WindowCtx* ctx) { + int width = static_cast(ctx->m_graphic_ctx.screen_width); + int height = static_cast(ctx->m_graphic_ctx.screen_height); + + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + printf("%s\n", SDL_GetError()); + std::_Exit(0); + } + + ctx->m_window = SDL_CreateWindowWithPosition("shadps4", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, + (static_cast(SDL_WINDOW_HIDDEN) | static_cast(SDL_WINDOW_VULKAN))); + + ctx->is_window_hidden = true;//hide window until we need to show something (should draw something in buffers) + + if (ctx->m_window == nullptr) { + printf("%s\n", SDL_GetError()); + std::_Exit(0); + } + + SDL_SetWindowResizable(ctx->m_window, SDL_FALSE);//we don't support resizable atm + SDL_ShowWindow(g_window_ctx->m_window);//TODO should be removed just left it over to make it fancy :D +} +void emuRun() { + g_window_ctx->m_mutex.LockMutex(); + { + // init window and wait until init finishes + CreateSdlWindow(g_window_ctx); + g_window_ctx->m_is_graphic_initialized = true; + g_window_ctx->m_graphic_initialized_cond.SignalCondVar(); + } + g_window_ctx->m_mutex.UnlockMutex(); + + for (;;) { + HLE::Libs::Graphics::VideoOut::videoOutFlip(100000); // flip every 0.1 sec + } + std::_Exit(0); +} +} // namespace Emulator \ No newline at end of file diff --git a/src/emulator.h b/src/emulator.h index 99090aa9..5afa122a 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -1,6 +1,17 @@ #pragma once +#include +#include +#include namespace Emulator { -void emuInit(); +struct WindowCtx { + HLE::Libs::Graphics::GraphicCtx m_graphic_ctx; + Lib::Mutex m_mutex; + bool m_is_graphic_initialized = false; + Lib::ConditionVariable m_graphic_initialized_cond; + SDL_Window* m_window = nullptr; + bool is_window_hidden = true; +}; +void emuInit(u32 width, u32 height); void emuRun(); -} \ No newline at end of file +} // namespace Emulator \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index f13efd68..58b25aa5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,11 +46,12 @@ int main(int argc, char* argv[]) logging::init(true); // init logging auto width = Config::getScreenWidth(); auto height = Config::getScreenHeight(); + Emulator::emuInit(width, height); HLE::Libs::Graphics::VideoOut::videoOutInit(width, height); - Emulator::emuInit(); Lib::InitThreads(); const char* const path = argv[1]; // argument 1 is the path of self file to boot + auto* linker = Singleton::Instance(); HLE::Libs::Init_HLE_Libs(linker->getHLESymbols()); auto *module =linker->LoadModule(path);//load main executable