From 491e231770cbff63c5c48f5a1b0f06c17aaeffd8 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Tue, 22 Aug 2023 23:59:59 +0300 Subject: [PATCH] implemented sceVideoOutOpen --- src/Core/PS4/HLE/ErrorCodes.h | 4 ++ .../HLE/Graphics/Objects/video_out_ctx.cpp | 29 +++++++++---- .../PS4/HLE/Graphics/Objects/video_out_ctx.h | 7 ++-- src/Core/PS4/HLE/Graphics/video_out.cpp | 41 +++++++++++++++++-- src/Core/PS4/HLE/Graphics/video_out.h | 5 +++ src/Core/PS4/HLE/LibSceVideoOut.cpp | 21 +--------- src/Core/PS4/HLE/LibSceVideoOut.h | 5 +-- src/main.cpp | 7 +++- 8 files changed, 82 insertions(+), 37 deletions(-) diff --git a/src/Core/PS4/HLE/ErrorCodes.h b/src/Core/PS4/HLE/ErrorCodes.h index de26175d..2ec6ec15 100644 --- a/src/Core/PS4/HLE/ErrorCodes.h +++ b/src/Core/PS4/HLE/ErrorCodes.h @@ -6,3 +6,7 @@ constexpr int SCE_KERNEL_ERROR_EFAULT = 0x8002000e; // Invalid address po constexpr int SCE_KERNEL_ERROR_EINVAL = 0x80020016; // null or invalid states constexpr int SCE_KERNEL_ERROR_EAGAIN = 0x80020023; // Memory cannot be allocated constexpr int SCE_KERNEL_ERROR_ENAMETOOLONG = 0x8002003f; // character strings exceeds valid size + +// videoOut +constexpr int SCE_VIDEO_OUT_ERROR_INVALID_VALUE = 0x80290001; // invalid argument +constexpr int SCE_VIDEO_OUT_ERROR_RESOURCE_BUSY = 0x80290009; // already opened 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 de9e81de..cf670a6b 100644 --- a/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp +++ b/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp @@ -3,12 +3,27 @@ namespace HLE::Graphics::Objects { void VideoOutCtx::Init(u32 width, u32 height) { - for (auto& video_ctx : m_video_out_ctx) { - video_ctx.m_resolution.fullWidth = width; - video_ctx.m_resolution.fullHeight = height; - video_ctx.m_resolution.paneWidth = width; - video_ctx.m_resolution.paneHeight = height; - } + m_video_out_ctx.m_resolution.fullWidth = width; + m_video_out_ctx.m_resolution.fullHeight = height; + m_video_out_ctx.m_resolution.paneWidth = width; + m_video_out_ctx.m_resolution.paneHeight = height; +} +int VideoOutCtx::Open() { + Lib::LockMutexGuard lock(m_mutex); + + int handle = -1; + + if (!m_video_out_ctx.isOpened) { + handle = 1;//positive return , should be more than 1 ? + } + + m_video_out_ctx.isOpened = true; + m_video_out_ctx.m_flip_status = SceVideoOutFlipStatus(); + m_video_out_ctx.m_flip_status.flipArg = -1; + m_video_out_ctx.m_flip_status.currentBuffer = -1; + m_video_out_ctx.m_flip_status.count = 0; + m_video_out_ctx.m_vblank_status = SceVideoOutVblankStatus(); + + return handle; } -void VideoOutCtx::Open() {} }; // namespace HLE::Graphics::Objects \ No newline at end of file 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 9c5fd9db..a5659fb0 100644 --- a/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h +++ b/src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h @@ -10,18 +10,19 @@ struct VideoConfigInternal { Lib::Mutex m_mutex; SceVideoOutResolutionStatus m_resolution; bool isOpened = false; + SceVideoOutFlipStatus m_flip_status; + SceVideoOutVblankStatus m_vblank_status; }; class VideoOutCtx { - static constexpr int MAX_VIDEO_OUT = 2; public: VideoOutCtx() {} virtual ~VideoOutCtx() {} void Init(u32 width, u32 height); - void Open(); + int Open(); private: Lib::Mutex m_mutex; - VideoConfigInternal m_video_out_ctx[MAX_VIDEO_OUT]; + VideoConfigInternal m_video_out_ctx; }; }; // namespace HLE::Graphics::Objects \ No newline at end of file diff --git a/src/Core/PS4/HLE/Graphics/video_out.cpp b/src/Core/PS4/HLE/Graphics/video_out.cpp index 889190ee..4fedea5e 100644 --- a/src/Core/PS4/HLE/Graphics/video_out.cpp +++ b/src/Core/PS4/HLE/Graphics/video_out.cpp @@ -7,10 +7,21 @@ #include #include +#include "Objects/video_out_ctx.h" +#include "Util/Singleton.h" +#include +#include +#include +#include + namespace HLE::Libs::Graphics::VideoOut { constexpr bool log_file_videoout = true; // disable it to disable logging +void videoOutInit(u32 width, u32 height) { + auto* videoOut = Singleton::Instance(); + videoOut->Init(width, height); +} std::string getPixelFormatString(s32 format) { switch (format) { case SCE_VIDEO_OUT_PIXEL_FORMAT_A8R8G8B8_SRGB: return "PIXEL_FORMAT_A8R8G8B8_SRGB"; @@ -56,7 +67,7 @@ s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(LibKernel::EventQueues::SceKernelEqueue } s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* const* addresses, s32 bufferNum, - const SceVideoOutBufferAttribute* attribute) { + const SceVideoOutBufferAttribute* attribute) { // BREAKPOINT(); PRINT_DUMMY_FUNCTION_NAME(); return 0; @@ -71,8 +82,7 @@ s32 PS4_SYSV_ABI sceVideoOutIsFlipPending(s32 handle) { PRINT_DUMMY_FUNCTION_NAME(); return 0; } -s32 PS4_SYSV_ABI sceVideoOutSubmitFlip(s32 handle, s32 bufferIndex, s32 flipMode, s64 flipArg) -{ +s32 PS4_SYSV_ABI sceVideoOutSubmitFlip(s32 handle, s32 bufferIndex, s32 flipMode, s64 flipArg) { // BREAKPOINT(); PRINT_DUMMY_FUNCTION_NAME(); return 0; @@ -87,4 +97,29 @@ s32 PS4_SYSV_ABI sceVideoOutGetResolutionStatus(s32 handle, SceVideoOutResolutio PRINT_DUMMY_FUNCTION_NAME(); return 0; } +s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 index, const void* param) { + PRINT_DUMMY_FUNCTION_NAME(); + if (userId != SCE_USER_SERVICE_USER_ID_SYSTEM) { + BREAKPOINT(); + } + if (busType != SCE_VIDEO_OUT_BUS_TYPE_MAIN) { + BREAKPOINT(); + } + if (index != 0) { + LOG_TRACE_IF(log_file_videoout, "sceVideoOutOpen index!=0\n"); + return SCE_VIDEO_OUT_ERROR_INVALID_VALUE; + } + if (param != nullptr) { + BREAKPOINT(); + } + auto* videoOut = Singleton::Instance(); + int handle = videoOut->Open(); + + if (handle < 0) { + LOG_TRACE_IF(log_file_videoout, "sceVideoOutOpen all available handles are open\n"); + return SCE_VIDEO_OUT_ERROR_RESOURCE_BUSY; //it is alreadyOpened + } + + return handle; +} } // namespace HLE::Libs::Graphics::VideoOut \ No newline at end of file diff --git a/src/Core/PS4/HLE/Graphics/video_out.h b/src/Core/PS4/HLE/Graphics/video_out.h index 657896fd..cbbf0795 100644 --- a/src/Core/PS4/HLE/Graphics/video_out.h +++ b/src/Core/PS4/HLE/Graphics/video_out.h @@ -6,6 +6,8 @@ namespace HLE::Libs::Graphics::VideoOut { +using SceUserServiceUserId = s32; //TODO move it to proper place + // SceVideoOutRefreshRate constexpr int SCE_VIDEO_OUT_REFRESH_RATE_UNKNOWN = 0; constexpr int SCE_VIDEO_OUT_REFRESH_RATE_23_98HZ = 1; @@ -77,6 +79,7 @@ struct SceVideoOutVblankStatus { u08 pad1[7] = {}; }; +void videoOutInit(u32 width, u32 height); std::string getPixelFormatString(s32 format); void PS4_SYSV_ABI sceVideoOutSetBufferAttribute(SceVideoOutBufferAttribute* attribute, u32 pixelFormat, u32 tilingMode, u32 aspectRatio, u32 width, @@ -89,4 +92,6 @@ s32 PS4_SYSV_ABI sceVideoOutIsFlipPending(s32 handle); s32 PS4_SYSV_ABI sceVideoOutSubmitFlip(s32 handle, s32 bufferIndex, s32 flipMode, s64 flipArg); s32 PS4_SYSV_ABI sceVideoOutGetFlipStatus(s32 handle, SceVideoOutFlipStatus* status); s32 PS4_SYSV_ABI sceVideoOutGetResolutionStatus(s32 handle, SceVideoOutResolutionStatus* status); +s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 index, const void* param); + } // namespace HLE::Libs::Graphics::VideoOut \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibSceVideoOut.cpp b/src/Core/PS4/HLE/LibSceVideoOut.cpp index 96ec0155..3ed1e7e5 100644 --- a/src/Core/PS4/HLE/LibSceVideoOut.cpp +++ b/src/Core/PS4/HLE/LibSceVideoOut.cpp @@ -4,30 +4,13 @@ #include "../../../Util/Log.h" #include "../Loader/Elf.h" +#include "Graphics/video_out.h" #include "Libs.h" #include "UserManagement/UsrMngCodes.h" #include "VideoOut/VideoOutCodes.h" -#include "Graphics/video_out.h" namespace HLE::Libs::LibSceVideoOut { -s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 index, const void* param) { - PRINT_DUMMY_FUNCTION_NAME(); - if (userId != SCE_USER_SERVICE_USER_ID_SYSTEM) { - BREAKPOINT(); - } - if (busType != SCE_VIDEO_OUT_BUS_TYPE_MAIN) { - BREAKPOINT(); - } - if (index != 0) { - BREAKPOINT(); - } - if (param != nullptr) { - BREAKPOINT(); - } - return 1; // dummy return TODO -} - void LibSceVideoOut_Register(SymbolsResolver* sym) { LIB_FUNCTION("SbU3dwp80lQ", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, HLE::Libs::Graphics::VideoOut::sceVideoOutGetFlipStatus); LIB_FUNCTION("U46NwOiJpys", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, HLE::Libs::Graphics::VideoOut::sceVideoOutSubmitFlip); @@ -36,7 +19,7 @@ void LibSceVideoOut_Register(SymbolsResolver* sym) { LIB_FUNCTION("CBiu4mCE1DA", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, HLE::Libs::Graphics::VideoOut::sceVideoOutSetFlipRate); LIB_FUNCTION("i6-sR91Wt-4", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, HLE::Libs::Graphics::VideoOut::sceVideoOutSetBufferAttribute); LIB_FUNCTION("6kPnj51T62Y", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, HLE::Libs::Graphics::VideoOut::sceVideoOutGetResolutionStatus); - LIB_FUNCTION("Up36PTk687E", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutOpen); + LIB_FUNCTION("Up36PTk687E", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, HLE::Libs::Graphics::VideoOut::sceVideoOutOpen); LIB_FUNCTION("zgXifHT9ErY", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, HLE::Libs::Graphics::VideoOut::sceVideoOutIsFlipPending); } diff --git a/src/Core/PS4/HLE/LibSceVideoOut.h b/src/Core/PS4/HLE/LibSceVideoOut.h index afecb8f7..a454040e 100644 --- a/src/Core/PS4/HLE/LibSceVideoOut.h +++ b/src/Core/PS4/HLE/LibSceVideoOut.h @@ -3,9 +3,6 @@ namespace HLE::Libs::LibSceVideoOut { -using SceUserServiceUserId = s32; //TODO move it to proper place - void LibSceVideoOut_Register(SymbolsResolver* sym); -//functions -s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 index, const void* param); + }; // namespace HLE::Libs::LibSceVideoOut \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 2e8af195..f13efd68 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,6 +33,8 @@ #include #include "discord.h" #include +#include + // Main code int main(int argc, char* argv[]) { @@ -42,10 +44,13 @@ int main(int argc, char* argv[]) } Config::load("config.toml"); logging::init(true); // init logging + auto width = Config::getScreenWidth(); + auto height = Config::getScreenHeight(); + 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