From 012cb4a7282c2fe30d3f8960b390a98c6e768fe8 Mon Sep 17 00:00:00 2001 From: TheTurtle Date: Sat, 30 Nov 2024 22:37:36 +0200 Subject: [PATCH] core: Library cleanup (#1631) * core: Split error codes into separate files * Reduces build times and is cleaner * core: Bring structs and enums to codebase style * core: More style changes --- CMakeLists.txt | 50 +- src/audio_core/sdl_audio.cpp | 166 ----- src/audio_core/sdl_audio.h | 39 -- src/common/memory_patcher.cpp | 10 +- src/core/cpu_patches.h | 2 + .../devtools/widget/imgui_memory_editor.h | 2 +- src/core/devtools/widget/text_editor.cpp | 2 +- src/core/file_format/playgo_chunk.h | 21 +- .../libraries/app_content/app_content.cpp | 59 +- src/core/libraries/app_content/app_content.h | 20 +- .../libraries/app_content/app_content_error.h | 11 + src/core/libraries/audio/audioout.cpp | 84 ++- src/core/libraries/audio/audioout.h | 56 +- src/core/libraries/audio/audioout_error.h | 34 + src/core/libraries/audio/sdl_audio.cpp | 141 ++++ src/core/libraries/audio/sdl_audio.h | 42 ++ src/core/libraries/audio3d/audio3d.cpp | 58 +- src/core/libraries/audio3d/audio3d.h | 123 ++-- src/core/libraries/audio3d/audio3d_error.h | 2 + src/core/libraries/audio3d/audio3d_impl.h | 2 +- src/core/libraries/avplayer/avplayer.cpp | 2 +- src/core/libraries/avplayer/avplayer.h | 106 +-- .../libraries/avplayer/avplayer_common.cpp | 12 +- src/core/libraries/avplayer/avplayer_error.h | 19 + src/core/libraries/avplayer/avplayer_impl.cpp | 2 +- .../libraries/avplayer/avplayer_source.cpp | 19 +- .../libraries/avplayer/avplayer_state.cpp | 33 +- src/core/libraries/avplayer/avplayer_state.h | 2 +- src/core/libraries/error_codes.h | 620 ------------------ src/core/libraries/fiber/fiber.cpp | 2 +- src/core/libraries/fiber/fiber.h | 7 +- src/core/libraries/fiber/fiber_error.h | 14 + src/core/libraries/gnmdriver/gnm_error.h | 2 + src/core/libraries/gnmdriver/gnmdriver.cpp | 3 +- src/core/libraries/ime/ime.cpp | 28 +- src/core/libraries/ime/ime.h | 37 +- src/core/libraries/ime/ime_common.h | 137 ++-- src/core/libraries/ime/ime_dialog.cpp | 58 +- src/core/libraries/ime/ime_dialog.h | 84 +-- src/core/libraries/ime/ime_dialog_ui.cpp | 68 +- src/core/libraries/ime/ime_dialog_ui.h | 4 +- src/core/libraries/ime/ime_error.h | 51 ++ src/core/libraries/ime/ime_ui.cpp | 38 +- src/core/libraries/kernel/equeue.cpp | 6 +- src/core/libraries/kernel/file_system.cpp | 50 +- src/core/libraries/kernel/file_system.h | 4 +- src/core/libraries/kernel/kernel.cpp | 35 +- src/core/libraries/kernel/kernel.h | 5 +- src/core/libraries/kernel/memory.cpp | 52 +- src/core/libraries/kernel/orbis_error.h | 108 +++ src/core/libraries/kernel/posix_error.h | 128 ++++ src/core/libraries/kernel/process.cpp | 4 +- src/core/libraries/kernel/threads/condvar.cpp | 2 +- .../libraries/kernel/threads/event_flag.cpp | 2 +- src/core/libraries/kernel/threads/mutex.cpp | 3 +- src/core/libraries/kernel/threads/pthread.cpp | 4 +- .../libraries/kernel/threads/pthread_attr.cpp | 2 +- .../libraries/kernel/threads/pthread_spec.cpp | 3 +- src/core/libraries/kernel/threads/rwlock.cpp | 2 +- .../libraries/kernel/threads/semaphore.cpp | 20 +- src/core/libraries/kernel/threads/sleepq.h | 7 +- .../libraries/kernel/threads/thread_state.cpp | 2 +- src/core/libraries/kernel/time.cpp | 24 +- src/core/libraries/kernel/time.h | 2 +- src/core/libraries/libpng/pngdec.cpp | 146 ++--- src/core/libraries/libpng/pngdec.h | 73 ++- src/core/libraries/libpng/pngdec_error.h | 17 + src/core/libraries/network/netctl.h | 4 +- src/core/libraries/ngs2/ngs2.cpp | 9 +- src/core/libraries/ngs2/ngs2.h | 11 +- src/core/libraries/np_manager/np_manager.cpp | 26 +- src/core/libraries/np_manager/np_manager.h | 10 +- src/core/libraries/np_trophy/np_trophy.cpp | 6 +- src/core/libraries/np_trophy/np_trophy.h | 68 +- .../libraries/np_trophy/np_trophy_error.h | 49 ++ src/core/libraries/pad/pad.cpp | 13 +- src/core/libraries/pad/pad.h | 67 +- src/core/libraries/pad/pad_errors.h | 22 + src/core/libraries/playgo/playgo.cpp | 231 ++++--- src/core/libraries/playgo/playgo_types.h | 50 +- src/core/libraries/random/random.h | 6 +- src/core/libraries/rtc/rtc.cpp | 87 ++- src/core/libraries/rtc/rtc.h | 27 +- src/core/libraries/rtc/rtc_error.h | 4 +- src/core/libraries/system/systemservice.cpp | 47 +- src/core/libraries/system/systemservice.h | 187 +++--- .../libraries/system/systemservice_error.h | 10 + src/core/libraries/system/userservice.cpp | 8 +- src/core/libraries/system/userservice.h | 18 +- src/core/libraries/system/userservice_error.h | 17 + src/core/libraries/videodec/videodec.cpp | 9 +- src/core/libraries/videodec/videodec2.cpp | 9 +- src/core/libraries/videodec/videodec2.h | 2 +- .../libraries/videodec/videodec2_impl.cpp | 3 +- src/core/libraries/videodec/videodec_error.h | 68 ++ src/core/libraries/videodec/videodec_impl.cpp | 2 +- src/core/libraries/videoout/driver.cpp | 38 +- src/core/libraries/videoout/video_out.cpp | 15 +- src/core/libraries/videoout/video_out.h | 36 +- src/core/libraries/videoout/videoout_error.h | 35 + src/core/linker.cpp | 5 +- src/core/memory.cpp | 5 +- src/core/virtual_memory.cpp | 180 ----- src/core/virtual_memory.h | 47 -- src/emulator.cpp | 6 +- src/imgui/renderer/imgui_core.cpp | 6 +- src/input/controller.cpp | 31 +- src/input/controller.h | 5 +- src/sdl_window.cpp | 176 +++-- src/sdl_window.h | 23 +- .../renderer_vulkan/vk_instance.cpp | 2 +- .../renderer_vulkan/vk_platform.cpp | 2 +- .../renderer_vulkan/vk_presenter.cpp | 10 +- .../renderer_vulkan/vk_swapchain.cpp | 2 +- 114 files changed, 2158 insertions(+), 2509 deletions(-) delete mode 100644 src/audio_core/sdl_audio.cpp delete mode 100644 src/audio_core/sdl_audio.h create mode 100644 src/core/libraries/app_content/app_content_error.h create mode 100644 src/core/libraries/audio/audioout_error.h create mode 100644 src/core/libraries/audio/sdl_audio.cpp create mode 100644 src/core/libraries/audio/sdl_audio.h create mode 100644 src/core/libraries/avplayer/avplayer_error.h create mode 100644 src/core/libraries/fiber/fiber_error.h create mode 100644 src/core/libraries/ime/ime_error.h create mode 100644 src/core/libraries/kernel/orbis_error.h create mode 100644 src/core/libraries/kernel/posix_error.h create mode 100644 src/core/libraries/libpng/pngdec_error.h create mode 100644 src/core/libraries/np_trophy/np_trophy_error.h create mode 100644 src/core/libraries/pad/pad_errors.h create mode 100644 src/core/libraries/system/systemservice_error.h create mode 100644 src/core/libraries/system/userservice_error.h create mode 100644 src/core/libraries/videodec/videodec_error.h create mode 100644 src/core/libraries/videoout/videoout_error.h delete mode 100644 src/core/virtual_memory.cpp delete mode 100644 src/core/virtual_memory.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c4f639bd..a8c3275f 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -176,10 +176,6 @@ if(ENABLE_QT_GUI) qt_add_resources(TRANSLATIONS ${TRANSLATIONS_QRC}) endif() -set(AUDIO_CORE src/audio_core/sdl_audio.cpp - src/audio_core/sdl_audio.h -) - set(AJM_LIB src/core/libraries/ajm/ajm.cpp src/core/libraries/ajm/ajm.h src/core/libraries/ajm/ajm_at9.cpp @@ -199,6 +195,9 @@ set(AUDIO_LIB src/core/libraries/audio/audioin.cpp src/core/libraries/audio/audioin.h src/core/libraries/audio/audioout.cpp src/core/libraries/audio/audioout.h + src/core/libraries/audio/sdl_audio.cpp + src/core/libraries/audio/sdl_audio.h + src/core/libraries/audio/audioout_error.h src/core/libraries/ngs2/ngs2.cpp src/core/libraries/ngs2/ngs2.h ) @@ -240,6 +239,8 @@ set(KERNEL_LIB src/core/libraries/kernel/threads/condvar.cpp src/core/libraries/kernel/threads.h src/core/libraries/kernel/time.cpp src/core/libraries/kernel/time.h + src/core/libraries/kernel/orbis_error.h + src/core/libraries/kernel/posix_error.h ) set(NETWORK_LIBS src/core/libraries/network/http.cpp @@ -255,6 +256,21 @@ set(NETWORK_LIBS src/core/libraries/network/http.cpp src/core/libraries/network/ssl.h ) +set(AVPLAYER_LIB src/core/libraries/avplayer/avplayer_common.cpp + src/core/libraries/avplayer/avplayer_common.h + src/core/libraries/avplayer/avplayer_file_streamer.cpp + src/core/libraries/avplayer/avplayer_file_streamer.h + src/core/libraries/avplayer/avplayer_impl.cpp + src/core/libraries/avplayer/avplayer_impl.h + src/core/libraries/avplayer/avplayer_source.cpp + src/core/libraries/avplayer/avplayer_source.h + src/core/libraries/avplayer/avplayer_state.cpp + src/core/libraries/avplayer/avplayer_state.h + src/core/libraries/avplayer/avplayer.cpp + src/core/libraries/avplayer/avplayer.h + src/core/libraries/avplayer/avplayer_error.h +) + set(SYSTEM_LIBS src/core/libraries/system/commondialog.cpp src/core/libraries/system/commondialog.h src/core/libraries/system/msgdialog.cpp @@ -279,28 +295,19 @@ set(SYSTEM_LIBS src/core/libraries/system/commondialog.cpp src/core/libraries/system/system_error.h src/core/libraries/system/systemservice.cpp src/core/libraries/system/systemservice.h + src/core/libraries/system/systemservice_error.h src/core/libraries/system/userservice.cpp src/core/libraries/system/userservice.h + src/core/libraries/system/userservice_error.h src/core/libraries/app_content/app_content.cpp src/core/libraries/app_content/app_content.h + src/core/libraries/app_content/app_content_error.h src/core/libraries/rtc/rtc.cpp src/core/libraries/rtc/rtc.h src/core/libraries/rtc/rtc_error.h src/core/libraries/disc_map/disc_map.cpp src/core/libraries/disc_map/disc_map.h src/core/libraries/disc_map/disc_map_codes.h - src/core/libraries/avplayer/avplayer_common.cpp - src/core/libraries/avplayer/avplayer_common.h - src/core/libraries/avplayer/avplayer_file_streamer.cpp - src/core/libraries/avplayer/avplayer_file_streamer.h - src/core/libraries/avplayer/avplayer_impl.cpp - src/core/libraries/avplayer/avplayer_impl.h - src/core/libraries/avplayer/avplayer_source.cpp - src/core/libraries/avplayer/avplayer_source.h - src/core/libraries/avplayer/avplayer_state.cpp - src/core/libraries/avplayer/avplayer_state.h - src/core/libraries/avplayer/avplayer.cpp - src/core/libraries/avplayer/avplayer.h src/core/libraries/ngs2/ngs2.cpp src/core/libraries/ngs2/ngs2.h src/core/libraries/ngs2/ngs2_error.h @@ -327,6 +334,7 @@ set(VIDEOOUT_LIB src/core/libraries/videoout/buffer.h src/core/libraries/videoout/driver.h src/core/libraries/videoout/video_out.cpp src/core/libraries/videoout/video_out.h + src/core/libraries/videoout/videoout_error.h ) set(LIBC_SOURCES src/core/libraries/libc_internal/libc_internal.cpp @@ -344,14 +352,17 @@ set(IME_LIB src/core/libraries/ime/error_dialog.cpp src/core/libraries/ime/ime_ui.h src/core/libraries/ime/ime.cpp src/core/libraries/ime/ime.h + src/core/libraries/ime/ime_error.h ) set(PAD_LIB src/core/libraries/pad/pad.cpp src/core/libraries/pad/pad.h + src/core/libraries/pad/pad_errors.h ) set(PNG_LIB src/core/libraries/libpng/pngdec.cpp src/core/libraries/libpng/pngdec.h + src/core/libraries/libpng/pngdec_error.h ) set(JPEG_LIB src/core/libraries/jpeg/jpeg_error.h @@ -375,6 +386,7 @@ set(USBD_LIB src/core/libraries/usbd/usbd.cpp set(FIBER_LIB src/core/libraries/fiber/fiber.cpp src/core/libraries/fiber/fiber.h + src/core/libraries/fiber/fiber_error.h ) set(VDEC_LIB src/core/libraries/videodec/videodec2_impl.cpp @@ -384,6 +396,7 @@ set(VDEC_LIB src/core/libraries/videodec/videodec2_impl.cpp src/core/libraries/videodec/videodec2_avc.h src/core/libraries/videodec/videodec.cpp src/core/libraries/videodec/videodec.h + src/core/libraries/videodec/videodec_error.h src/core/libraries/videodec/videodec_impl.cpp src/core/libraries/videodec/videodec_impl.h ) @@ -396,6 +409,7 @@ set(NP_LIBS src/core/libraries/np_manager/np_manager.cpp src/core/libraries/np_trophy/np_trophy.h src/core/libraries/np_trophy/trophy_ui.cpp src/core/libraries/np_trophy/trophy_ui.h + src/core/libraries/np_trophy/np_trophy_error.h ) set(MISC_LIBS src/core/libraries/screenshot/screenshot.cpp @@ -527,10 +541,10 @@ set(CORE src/core/aerolib/stubs.cpp src/core/loader/elf.h src/core/loader/symbols_resolver.h src/core/loader/symbols_resolver.cpp - src/core/libraries/error_codes.h src/core/libraries/libs.h src/core/libraries/libs.cpp ${AJM_LIB} + ${AVPLAYER_LIB} ${AUDIO_LIB} ${GNM_LIB} ${KERNEL_LIB} @@ -565,8 +579,6 @@ set(CORE src/core/aerolib/stubs.cpp src/core/thread.h src/core/tls.cpp src/core/tls.h - src/core/virtual_memory.cpp - src/core/virtual_memory.h ) if (ARCHITECTURE STREQUAL "x86_64") diff --git a/src/audio_core/sdl_audio.cpp b/src/audio_core/sdl_audio.cpp deleted file mode 100644 index 7fed42a4..00000000 --- a/src/audio_core/sdl_audio.cpp +++ /dev/null @@ -1,166 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "sdl_audio.h" - -#include "common/assert.h" -#include "core/libraries/error_codes.h" - -#include -#include -#include - -#include // std::unique_lock - -namespace Audio { - -constexpr int AUDIO_STREAM_BUFFER_THRESHOLD = 65536; // Define constant for buffer threshold - -s32 SDLAudio::AudioOutOpen(int type, u32 samples_num, u32 freq, - Libraries::AudioOut::OrbisAudioOutParamFormat format) { - using Libraries::AudioOut::OrbisAudioOutParamFormat; - std::unique_lock lock{m_mutex}; - for (int id = 0; id < portsOut.size(); id++) { - auto& port = portsOut[id]; - if (!port.isOpen) { - port.isOpen = true; - port.type = type; - port.samples_num = samples_num; - port.freq = freq; - port.format = format; - SDL_AudioFormat sampleFormat; - switch (format) { - case OrbisAudioOutParamFormat::ORBIS_AUDIO_OUT_PARAM_FORMAT_S16_MONO: - sampleFormat = SDL_AUDIO_S16; - port.channels_num = 1; - port.sample_size = 2; - break; - case OrbisAudioOutParamFormat::ORBIS_AUDIO_OUT_PARAM_FORMAT_FLOAT_MONO: - sampleFormat = SDL_AUDIO_F32; - port.channels_num = 1; - port.sample_size = 4; - break; - case OrbisAudioOutParamFormat::ORBIS_AUDIO_OUT_PARAM_FORMAT_S16_STEREO: - sampleFormat = SDL_AUDIO_S16; - port.channels_num = 2; - port.sample_size = 2; - break; - case OrbisAudioOutParamFormat::ORBIS_AUDIO_OUT_PARAM_FORMAT_FLOAT_STEREO: - sampleFormat = SDL_AUDIO_F32; - port.channels_num = 2; - port.sample_size = 4; - break; - case OrbisAudioOutParamFormat::ORBIS_AUDIO_OUT_PARAM_FORMAT_S16_8CH: - sampleFormat = SDL_AUDIO_S16; - port.channels_num = 8; - port.sample_size = 2; - break; - case OrbisAudioOutParamFormat::ORBIS_AUDIO_OUT_PARAM_FORMAT_FLOAT_8CH: - sampleFormat = SDL_AUDIO_F32; - port.channels_num = 8; - port.sample_size = 4; - break; - case OrbisAudioOutParamFormat::ORBIS_AUDIO_OUT_PARAM_FORMAT_S16_8CH_STD: - sampleFormat = SDL_AUDIO_S16; - port.channels_num = 8; - port.sample_size = 2; - break; - case OrbisAudioOutParamFormat::ORBIS_AUDIO_OUT_PARAM_FORMAT_FLOAT_8CH_STD: - sampleFormat = SDL_AUDIO_F32; - port.channels_num = 8; - port.sample_size = 4; - break; - default: - UNREACHABLE_MSG("Unknown format"); - } - - for (int i = 0; i < port.channels_num; i++) { - port.volume[i] = Libraries::AudioOut::SCE_AUDIO_OUT_VOLUME_0DB; - } - - SDL_AudioSpec fmt; - SDL_zero(fmt); - fmt.format = sampleFormat; - fmt.channels = port.channels_num; - fmt.freq = freq; // Set frequency from the argument - port.stream = - SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &fmt, NULL, NULL); - SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(port.stream)); - return id + 1; - } - } - - LOG_ERROR(Lib_AudioOut, "Audio ports are full"); - return ORBIS_AUDIO_OUT_ERROR_PORT_FULL; // all ports are used -} - -s32 SDLAudio::AudioOutOutput(s32 handle, const void* ptr) { - std::shared_lock lock{m_mutex}; - auto& port = portsOut[handle - 1]; - if (!port.isOpen) { - return ORBIS_AUDIO_OUT_ERROR_INVALID_PORT; - } - - const size_t data_size = port.samples_num * port.sample_size * port.channels_num; - - bool result = SDL_PutAudioStreamData(port.stream, ptr, data_size); - - lock.unlock(); // Unlock only after necessary operations - - while (SDL_GetAudioStreamAvailable(port.stream) > AUDIO_STREAM_BUFFER_THRESHOLD) { - SDL_Delay(0); - } - - return result ? ORBIS_OK : -1; -} - -s32 SDLAudio::AudioOutSetVolume(s32 handle, s32 bitflag, s32* volume) { - using Libraries::AudioOut::OrbisAudioOutParamFormat; - std::shared_lock lock{m_mutex}; - auto& port = portsOut[handle - 1]; - if (!port.isOpen) { - return ORBIS_AUDIO_OUT_ERROR_INVALID_PORT; - } - - for (int i = 0; i < port.channels_num; i++, bitflag >>= 1u) { - auto bit = bitflag & 0x1u; - - if (bit == 1) { - int src_index = i; - if (port.format == - OrbisAudioOutParamFormat::ORBIS_AUDIO_OUT_PARAM_FORMAT_FLOAT_8CH_STD || - port.format == OrbisAudioOutParamFormat::ORBIS_AUDIO_OUT_PARAM_FORMAT_S16_8CH_STD) { - switch (i) { - case 4: - src_index = 6; - break; - case 5: - src_index = 7; - break; - case 6: - src_index = 4; - break; - case 7: - src_index = 5; - break; - default: - break; - } - } - port.volume[i] = volume[src_index]; - } - } - - return ORBIS_OK; -} - -s32 SDLAudio::AudioOutGetStatus(s32 handle, int* type, int* channels_num) { - std::shared_lock lock{m_mutex}; - auto& port = portsOut[handle - 1]; - *type = port.type; - *channels_num = port.channels_num; - - return ORBIS_OK; -} - -} // namespace Audio diff --git a/src/audio_core/sdl_audio.h b/src/audio_core/sdl_audio.h deleted file mode 100644 index 0d4783f1..00000000 --- a/src/audio_core/sdl_audio.h +++ /dev/null @@ -1,39 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include -#include -#include "core/libraries/audio/audioout.h" - -namespace Audio { - -class SDLAudio { -public: - SDLAudio() = default; - virtual ~SDLAudio() = default; - - s32 AudioOutOpen(int type, u32 samples_num, u32 freq, - Libraries::AudioOut::OrbisAudioOutParamFormat format); - s32 AudioOutOutput(s32 handle, const void* ptr); - s32 AudioOutSetVolume(s32 handle, s32 bitflag, s32* volume); - s32 AudioOutGetStatus(s32 handle, int* type, int* channels_num); - -private: - struct PortOut { - SDL_AudioStream* stream = nullptr; - u32 samples_num = 0; - u32 freq = 0; - u32 format = -1; - int type = 0; - int channels_num = 0; - int volume[8] = {}; - u8 sample_size = 0; - bool isOpen = false; - }; - std::shared_mutex m_mutex; - std::array portsOut; -}; - -} // namespace Audio diff --git a/src/common/memory_patcher.cpp b/src/common/memory_patcher.cpp index d2930cf5..6b79edb9 100644 --- a/src/common/memory_patcher.cpp +++ b/src/common/memory_patcher.cpp @@ -28,7 +28,7 @@ std::string g_game_serial; std::string patchFile; std::vector pending_patches; -std::string toHex(unsigned long long value, size_t byteSize) { +std::string toHex(u64 value, size_t byteSize) { std::stringstream ss; ss << std::hex << std::setfill('0') << std::setw(byteSize * 2) << value; return ss.str(); @@ -38,16 +38,16 @@ std::string convertValueToHex(const std::string type, const std::string valueStr std::string result; if (type == "byte") { - unsigned int value = std::stoul(valueStr, nullptr, 16); + const u32 value = std::stoul(valueStr, nullptr, 16); result = toHex(value, 1); } else if (type == "bytes16") { - unsigned int value = std::stoul(valueStr, nullptr, 16); + const u32 value = std::stoul(valueStr, nullptr, 16); result = toHex(value, 2); } else if (type == "bytes32") { - unsigned long value = std::stoul(valueStr, nullptr, 16); + const u32 value = std::stoul(valueStr, nullptr, 16); result = toHex(value, 4); } else if (type == "bytes64") { - unsigned long long value = std::stoull(valueStr, nullptr, 16); + const u64 value = std::stoull(valueStr, nullptr, 16); result = toHex(value, 8); } else if (type == "float32") { union { diff --git a/src/core/cpu_patches.h b/src/core/cpu_patches.h index f9f7fe64..1ccac073 100644 --- a/src/core/cpu_patches.h +++ b/src/core/cpu_patches.h @@ -3,6 +3,8 @@ #pragma once +#include "common/types.h" + namespace Core { /// Initializes a stack for the current thread for use by patch implementations. diff --git a/src/core/devtools/widget/imgui_memory_editor.h b/src/core/devtools/widget/imgui_memory_editor.h index f90387a7..086cfb1d 100644 --- a/src/core/devtools/widget/imgui_memory_editor.h +++ b/src/core/devtools/widget/imgui_memory_editor.h @@ -458,7 +458,7 @@ struct MemoryEditor { data_write = data_next = true; if (data_editing_addr_next != (size_t)-1) data_write = data_next = false; - unsigned int data_input_value = 0; + u32 data_input_value = 0; if (!ReadOnly && data_write && sscanf(DataInputBuf, "%X", &data_input_value) == 1) { if (WriteFn) diff --git a/src/core/devtools/widget/text_editor.cpp b/src/core/devtools/widget/text_editor.cpp index f447e45a..07f2f658 100644 --- a/src/core/devtools/widget/text_editor.cpp +++ b/src/core/devtools/widget/text_editor.cpp @@ -131,7 +131,7 @@ static int UTF8CharLength(TextEditor::Char c) { } // "Borrowed" from ImGui source -static inline int ImTextCharToUtf8(char* buf, int buf_size, unsigned int c) { +static inline int ImTextCharToUtf8(char* buf, int buf_size, u32 c) { if (c < 0x80) { buf[0] = (char)c; return 1; diff --git a/src/core/file_format/playgo_chunk.h b/src/core/file_format/playgo_chunk.h index b6d38e0e..2a234f5f 100644 --- a/src/core/file_format/playgo_chunk.h +++ b/src/core/file_format/playgo_chunk.h @@ -97,24 +97,23 @@ struct PlaygoChunk { class PlaygoFile { public: - bool initialized; - OrbisPlayGoHandle handle; - OrbisPlayGoChunkId id; - OrbisPlayGoLocus locus; - OrbisPlayGoInstallSpeed speed; - s64 speed_tick; - OrbisPlayGoEta eta; - OrbisPlayGoLanguageMask langMask; + bool initialized = false; + OrbisPlayGoHandle handle = 0; + OrbisPlayGoChunkId id = 0; + OrbisPlayGoLocus locus = OrbisPlayGoLocus::NotDownloaded; + OrbisPlayGoInstallSpeed speed = OrbisPlayGoInstallSpeed::Trickle; + s64 speed_tick = 0; + OrbisPlayGoEta eta = 0; + OrbisPlayGoLanguageMask langMask = 0; std::vector chunks; public: - PlaygoFile() - : initialized(false), handle(0), id(0), locus(0), speed(ORBIS_PLAYGO_INSTALL_SPEED_TRICKLE), - speed_tick(0), eta(0), langMask(0), playgoHeader{0} {} + explicit PlaygoFile() = default; ~PlaygoFile() = default; bool Open(const std::filesystem::path& filepath); bool LoadChunks(const Common::FS::IOFile& file); + PlaygoHeader& GetPlaygoHeader() { return playgoHeader; } diff --git a/src/core/libraries/app_content/app_content.cpp b/src/core/libraries/app_content/app_content.cpp index f912639e..ca3cdad3 100644 --- a/src/core/libraries/app_content/app_content.cpp +++ b/src/core/libraries/app_content/app_content.cpp @@ -6,34 +6,30 @@ #include "app_content.h" #include "common/assert.h" #include "common/config.h" -#include "common/io_file.h" #include "common/logging/log.h" -#include "common/path_util.h" #include "common/singleton.h" -#include "common/string_util.h" #include "core/file_format/psf.h" #include "core/file_sys/fs.h" -#include "core/libraries/error_codes.h" +#include "core/libraries/app_content/app_content_error.h" #include "core/libraries/libs.h" namespace Libraries::AppContent { -int32_t addcont_count = 0; - struct AddContInfo { - char entitlementLabel[ORBIS_NP_UNIFIED_ENTITLEMENT_LABEL_SIZE]; + char entitlement_label[ORBIS_NP_UNIFIED_ENTITLEMENT_LABEL_SIZE]; OrbisAppContentAddcontDownloadStatus status; OrbisAppContentGetEntitlementKey key; }; -std::array addcont_info = {{ +static std::array addcont_info = {{ {"0000000000000000", - ORBIS_APP_CONTENT_ADDCONT_DOWNLOAD_STATUS_INSTALLED, + OrbisAppContentAddcontDownloadStatus::Installed, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, }}; -std::string title_id; +static s32 addcont_count = 0; +static std::string title_id; int PS4_SYSV_ABI _Z5dummyv() { LOG_ERROR(Lib_AppContent, "(STUBBED) called"); @@ -64,12 +60,11 @@ int PS4_SYSV_ABI sceAppContentAddcontMount(u32 service_label, auto* mnt = Common::Singleton::Instance(); for (int i = 0; i < addcont_count; i++) { - if (strncmp(entitlement_label->data, addcont_info[i].entitlementLabel, + if (strncmp(entitlement_label->data, addcont_info[i].entitlement_label, ORBIS_NP_UNIFIED_ENTITLEMENT_LABEL_SIZE - 1) != 0) { continue; } - - if (addcont_info[i].status != ORBIS_APP_CONTENT_ADDCONT_DOWNLOAD_STATUS_INSTALLED) { + if (addcont_info[i].status != OrbisAppContentAddcontDownloadStatus::Installed) { return ORBIS_APP_CONTENT_ERROR_NOT_FOUND; } @@ -170,14 +165,14 @@ int PS4_SYSV_ABI sceAppContentGetAddcontInfo(u32 service_label, } for (auto i = 0; i < addcont_count; i++) { - if (strncmp(entitlementLabel->data, addcont_info[i].entitlementLabel, + if (strncmp(entitlementLabel->data, addcont_info[i].entitlement_label, ORBIS_NP_UNIFIED_ENTITLEMENT_LABEL_SIZE - 1) != 0) { continue; } LOG_INFO(Lib_AppContent, "found DLC {}", entitlementLabel->data); - strncpy(info->entitlement_label.data, addcont_info[i].entitlementLabel, + strncpy(info->entitlement_label.data, addcont_info[i].entitlement_label, ORBIS_NP_UNIFIED_ENTITLEMENT_LABEL_SIZE); info->status = addcont_info[i].status; return ORBIS_OK; @@ -202,7 +197,7 @@ int PS4_SYSV_ABI sceAppContentGetAddcontInfoList(u32 service_label, int dlcs_to_list = addcont_count < list_num ? addcont_count : list_num; for (int i = 0; i < dlcs_to_list; i++) { - strncpy(list[i].entitlement_label.data, addcont_info[i].entitlementLabel, + strncpy(list[i].entitlement_label.data, addcont_info[i].entitlement_label, ORBIS_NP_UNIFIED_ENTITLEMENT_LABEL_SIZE); list[i].status = addcont_info[i].status; } @@ -224,7 +219,7 @@ int PS4_SYSV_ABI sceAppContentGetEntitlementKey( } for (int i = 0; i < addcont_count; i++) { - if (strncmp(entitlement_label->data, addcont_info[i].entitlementLabel, + if (strncmp(entitlement_label->data, addcont_info[i].entitlement_label, ORBIS_NP_UNIFIED_ENTITLEMENT_LABEL_SIZE - 1) != 0) { continue; } @@ -252,21 +247,19 @@ int PS4_SYSV_ABI sceAppContentInitialize(const OrbisAppContentInitParam* initPar } else { UNREACHABLE_MSG("Failed to get TITLE_ID"); } - auto addon_path = addons_dir / title_id; - if (std::filesystem::exists(addon_path)) { - for (const auto& entry : std::filesystem::directory_iterator(addon_path)) { - if (entry.is_directory()) { - auto entitlement_label = entry.path().filename().string(); - - AddContInfo info{}; - info.status = ORBIS_APP_CONTENT_ADDCONT_DOWNLOAD_STATUS_INSTALLED; - strcpy(info.entitlementLabel, entitlement_label.c_str()); - - addcont_info[addcont_count++] = info; - } - } + const auto addon_path = addons_dir / title_id; + if (!std::filesystem::exists(addon_path)) { + return ORBIS_OK; } + for (const auto& entry : std::filesystem::directory_iterator(addon_path)) { + if (entry.is_directory()) { + auto entitlement_label = entry.path().filename().string(); + auto& info = addcont_info[addcont_count++]; + info.status = OrbisAppContentAddcontDownloadStatus::Installed; + entitlement_label.copy(info.entitlement_label, sizeof(info.entitlement_label)); + } + } return ORBIS_OK; } @@ -314,9 +307,11 @@ int PS4_SYSV_ABI sceAppContentTemporaryDataMount() { int PS4_SYSV_ABI sceAppContentTemporaryDataMount2(OrbisAppContentTemporaryDataOption option, OrbisAppContentMountPoint* mountPoint) { - if (mountPoint == nullptr) + if (mountPoint == nullptr) { return ORBIS_APP_CONTENT_ERROR_PARAMETER; - strncpy(mountPoint->data, "/temp0", 16); + } + static constexpr std::string_view TmpMount = "/temp0"; + TmpMount.copy(mountPoint->data, sizeof(mountPoint->data)); LOG_INFO(Lib_AppContent, "sceAppContentTemporaryDataMount2: option = {}, mountPoint = {}", option, mountPoint->data); return ORBIS_OK; diff --git a/src/core/libraries/app_content/app_content.h b/src/core/libraries/app_content/app_content.h index a16da5b4..f41f7dcc 100644 --- a/src/core/libraries/app_content/app_content.h +++ b/src/core/libraries/app_content/app_content.h @@ -30,7 +30,7 @@ struct OrbisAppContentBootParam { char reserved2[32]; }; -typedef u32 OrbisAppContentTemporaryDataOption; +using OrbisAppContentTemporaryDataOption = u32; constexpr int ORBIS_APP_CONTENT_MOUNTPOINT_DATA_MAXSIZE = 16; @@ -44,12 +44,12 @@ constexpr int ORBIS_NP_UNIFIED_ENTITLEMENT_LABEL_SIZE = 17; constexpr int ORBIS_APP_CONTENT_ENTITLEMENT_KEY_SIZE = 16; constexpr int ORBIS_APP_CONTENT_INFO_LIST_MAX_SIZE = 2500; -enum OrbisAppContentAddcontDownloadStatus : u32 { - ORBIS_APP_CONTENT_ADDCONT_DOWNLOAD_STATUS_NO_EXTRA_DATA = 0, - ORBIS_APP_CONTENT_ADDCONT_DOWNLOAD_STATUS_NO_IN_QUEUE = 1, - ORBIS_APP_CONTENT_ADDCONT_DOWNLOAD_STATUS_DOWNLOADING = 2, - ORBIS_APP_CONTENT_ADDCONT_DOWNLOAD_STATUS_DOWNLOAD_SUSPENDED = 3, - ORBIS_APP_CONTENT_ADDCONT_DOWNLOAD_STATUS_INSTALLED = 4 +enum class OrbisAppContentAddcontDownloadStatus : u32 { + NoExtraData = 0, + NoInQueue = 1, + Downloading = 2, + DownloadSuspended = 3, + Installed = 4 }; struct OrbisNpUnifiedEntitlementLabel { @@ -57,11 +57,11 @@ struct OrbisNpUnifiedEntitlementLabel { char padding[3]; }; -typedef u32 OrbisAppContentAppParamId; +using OrbisAppContentAppParamId = u32; struct OrbisAppContentAddcontInfo { OrbisNpUnifiedEntitlementLabel entitlement_label; - u32 status; + OrbisAppContentAddcontDownloadStatus status; }; struct OrbisAppContentGetEntitlementKey { @@ -119,4 +119,4 @@ int PS4_SYSV_ABI sceAppContentGetAddcontInfoListByIroTag(); int PS4_SYSV_ABI sceAppContentGetDownloadedStoreCountry(); void RegisterlibSceAppContent(Core::Loader::SymbolsResolver* sym); -} // namespace Libraries::AppContent \ No newline at end of file +} // namespace Libraries::AppContent diff --git a/src/core/libraries/app_content/app_content_error.h b/src/core/libraries/app_content/app_content_error.h new file mode 100644 index 00000000..3a582b99 --- /dev/null +++ b/src/core/libraries/app_content/app_content_error.h @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/libraries/error_codes.h" + +// AppContent library +constexpr int ORBIS_APP_CONTENT_ERROR_PARAMETER = 0x80D90002; +constexpr int ORBIS_APP_CONTENT_ERROR_DRM_NO_ENTITLEMENT = 0x80D90007; +constexpr int ORBIS_APP_CONTENT_ERROR_NOT_FOUND = 0x80D90005; diff --git a/src/core/libraries/audio/audioout.cpp b/src/core/libraries/audio/audioout.cpp index 778d777c..b92c75a8 100644 --- a/src/core/libraries/audio/audioout.cpp +++ b/src/core/libraries/audio/audioout.cpp @@ -4,30 +4,30 @@ #include #include -#include "audio_core/sdl_audio.h" #include "common/assert.h" #include "common/logging/log.h" #include "core/libraries/audio/audioout.h" -#include "core/libraries/error_codes.h" +#include "core/libraries/audio/audioout_error.h" +#include "core/libraries/audio/sdl_audio.h" #include "core/libraries/libs.h" namespace Libraries::AudioOut { -static std::unique_ptr audio; +static std::unique_ptr audio; -static std::string_view GetAudioOutPort(u32 port) { +static std::string_view GetAudioOutPort(OrbisAudioOutPort port) { switch (port) { - case ORBIS_AUDIO_OUT_PORT_TYPE_MAIN: + case OrbisAudioOutPort::Main: return "MAIN"; - case ORBIS_AUDIO_OUT_PORT_TYPE_BGM: + case OrbisAudioOutPort::Bgm: return "BGM"; - case ORBIS_AUDIO_OUT_PORT_TYPE_VOICE: + case OrbisAudioOutPort::Voice: return "VOICE"; - case ORBIS_AUDIO_OUT_PORT_TYPE_PERSONAL: + case OrbisAudioOutPort::Personal: return "PERSONAL"; - case ORBIS_AUDIO_OUT_PORT_TYPE_PADSPK: + case OrbisAudioOutPort::Padspk: return "PADSPK"; - case ORBIS_AUDIO_OUT_PORT_TYPE_AUX: + case OrbisAudioOutPort::Aux: return "AUX"; default: return "INVALID"; @@ -36,21 +36,21 @@ static std::string_view GetAudioOutPort(u32 port) { static std::string_view GetAudioOutParamFormat(OrbisAudioOutParamFormat param) { switch (param) { - case ORBIS_AUDIO_OUT_PARAM_FORMAT_S16_MONO: + case OrbisAudioOutParamFormat::S16Mono: return "S16_MONO"; - case ORBIS_AUDIO_OUT_PARAM_FORMAT_S16_STEREO: + case OrbisAudioOutParamFormat::S16Stereo: return "S16_STEREO"; - case ORBIS_AUDIO_OUT_PARAM_FORMAT_S16_8CH: + case OrbisAudioOutParamFormat::S16_8CH: return "S16_8CH"; - case ORBIS_AUDIO_OUT_PARAM_FORMAT_FLOAT_MONO: + case OrbisAudioOutParamFormat::FloatMono: return "FLOAT_MONO"; - case ORBIS_AUDIO_OUT_PARAM_FORMAT_FLOAT_STEREO: + case OrbisAudioOutParamFormat::FloatStereo: return "FLOAT_STEREO"; - case ORBIS_AUDIO_OUT_PARAM_FORMAT_FLOAT_8CH: + case OrbisAudioOutParamFormat::Float_8CH: return "FLOAT_8CH"; - case ORBIS_AUDIO_OUT_PARAM_FORMAT_S16_8CH_STD: + case OrbisAudioOutParamFormat::S16_8CH_Std: return "S16_8CH_STD"; - case ORBIS_AUDIO_OUT_PARAM_FORMAT_FLOAT_8CH_STD: + case OrbisAudioOutParamFormat::Float_8CH_Std: return "FLOAT_8CH_STD"; default: return "INVALID"; @@ -59,11 +59,11 @@ static std::string_view GetAudioOutParamFormat(OrbisAudioOutParamFormat param) { static std::string_view GetAudioOutParamAttr(OrbisAudioOutParamAttr attr) { switch (attr) { - case ORBIS_AUDIO_OUT_PARAM_ATTR_NONE: + case OrbisAudioOutParamAttr::None: return "NONE"; - case ORBIS_AUDIO_OUT_PARAM_ATTR_RESTRICTED: + case OrbisAudioOutParamAttr::Restricted: return "RESTRICTED"; - case ORBIS_AUDIO_OUT_PARAM_ATTR_MIX_TO_MAIN: + case OrbisAudioOutParamAttr::MixToMain: return "MIX_TO_MAIN"; default: return "INVALID"; @@ -180,29 +180,23 @@ int PS4_SYSV_ABI sceAudioOutGetPortState(s32 handle, OrbisAudioOutPortState* sta return ORBIS_AUDIO_OUT_ERROR_INVALID_PORT; } - int type = 0; - int channels_num = 0; - - if (const auto err = audio->AudioOutGetStatus(handle, &type, &channels_num); err != ORBIS_OK) { - return err; - } - + const auto [type, channels_num] = audio->GetStatus(handle); state->rerouteCounter = 0; - state->volume = 127; // max volume + state->volume = 127; switch (type) { - case ORBIS_AUDIO_OUT_PORT_TYPE_MAIN: - case ORBIS_AUDIO_OUT_PORT_TYPE_BGM: - case ORBIS_AUDIO_OUT_PORT_TYPE_VOICE: + case OrbisAudioOutPort::Main: + case OrbisAudioOutPort::Bgm: + case OrbisAudioOutPort::Voice: state->output = 1; state->channel = (channels_num > 2 ? 2 : channels_num); break; - case ORBIS_AUDIO_OUT_PORT_TYPE_PERSONAL: - case ORBIS_AUDIO_OUT_PORT_TYPE_PADSPK: + case OrbisAudioOutPort::Personal: + case OrbisAudioOutPort::Padspk: state->output = 4; state->channel = 1; break; - case ORBIS_AUDIO_OUT_PORT_TYPE_AUX: + case OrbisAudioOutPort::Aux: state->output = 0; state->channel = 0; break; @@ -243,7 +237,7 @@ int PS4_SYSV_ABI sceAudioOutInit() { if (audio != nullptr) { return ORBIS_AUDIO_OUT_ERROR_ALREADY_INIT; } - audio = std::make_unique(); + audio = std::make_unique(); return ORBIS_OK; } @@ -287,7 +281,8 @@ s32 PS4_SYSV_ABI sceAudioOutOpen(UserService::OrbisUserServiceUserId user_id, user_id, GetAudioOutPort(port_type), index, length, sample_rate, GetAudioOutParamFormat(param_type.data_format), GetAudioOutParamAttr(param_type.attributes)); - if ((port_type < 0 || port_type > 4) && (port_type != 127)) { + if ((port_type < OrbisAudioOutPort::Main || port_type > OrbisAudioOutPort::Padspk) && + (port_type != OrbisAudioOutPort::Aux)) { LOG_ERROR(Lib_AudioOut, "Invalid port type"); return ORBIS_AUDIO_OUT_ERROR_INVALID_PORT_TYPE; } @@ -303,18 +298,19 @@ s32 PS4_SYSV_ABI sceAudioOutOpen(UserService::OrbisUserServiceUserId user_id, if (index != 0) { LOG_ERROR(Lib_AudioOut, "index is not valid !=0 {}", index); } - OrbisAudioOutParamFormat format = param_type.data_format; - if (format < 0 || format > 7) { + const auto format = param_type.data_format.Value(); + if (format < OrbisAudioOutParamFormat::S16Mono || + format > OrbisAudioOutParamFormat::Float_8CH_Std) { LOG_ERROR(Lib_AudioOut, "Invalid format"); return ORBIS_AUDIO_OUT_ERROR_INVALID_FORMAT; } - OrbisAudioOutParamAttr attr = param_type.attributes; - if (attr < 0 || attr > 2) { + const auto attr = param_type.attributes; + if (attr < OrbisAudioOutParamAttr::None || attr > OrbisAudioOutParamAttr::MixToMain) { // TODO Handle attributes in output audio device LOG_ERROR(Lib_AudioOut, "Invalid format attribute"); return ORBIS_AUDIO_OUT_ERROR_INVALID_FORMAT; } - return audio->AudioOutOpen(port_type, length, sample_rate, format); + return audio->Open(port_type, length, sample_rate, format); } int PS4_SYSV_ABI sceAudioOutOpenEx() { @@ -330,7 +326,7 @@ s32 PS4_SYSV_ABI sceAudioOutOutput(s32 handle, const void* ptr) { // Nothing to output return ORBIS_OK; } - return audio->AudioOutOutput(handle, ptr); + return audio->Output(handle, ptr); } int PS4_SYSV_ABI sceAudioOutOutputs(OrbisAudioOutOutputParam* param, u32 num) { @@ -435,7 +431,7 @@ s32 PS4_SYSV_ABI sceAudioOutSetVolume(s32 handle, s32 flag, s32* vol) { if (handle < 1 || handle > SCE_AUDIO_OUT_NUM_PORTS) { return ORBIS_AUDIO_OUT_ERROR_INVALID_PORT; } - return audio->AudioOutSetVolume(handle, flag, vol); + return audio->SetVolume(handle, flag, vol); } int PS4_SYSV_ABI sceAudioOutSetVolumeDown() { diff --git a/src/core/libraries/audio/audioout.h b/src/core/libraries/audio/audioout.h index 95cfc170..e8e718b8 100644 --- a/src/core/libraries/audio/audioout.h +++ b/src/core/libraries/audio/audioout.h @@ -9,46 +9,36 @@ namespace Libraries::AudioOut { -constexpr int SCE_AUDIO_OUT_VOLUME_0DB = 32768; // max volume value - -// main up to 8 ports, BGM 1 port, voice up to 4 ports, +// Main up to 8 ports, BGM 1 port, voice up to 4 ports, // personal up to 4 ports, padspk up to 5 ports, aux 1 port constexpr int SCE_AUDIO_OUT_NUM_PORTS = 22; +constexpr int SCE_AUDIO_OUT_VOLUME_0DB = 32768; // max volume value -enum OrbisAudioOutPort { - ORBIS_AUDIO_OUT_PORT_TYPE_MAIN = 0, - ORBIS_AUDIO_OUT_PORT_TYPE_BGM = 1, - ORBIS_AUDIO_OUT_PORT_TYPE_VOICE = 2, - ORBIS_AUDIO_OUT_PORT_TYPE_PERSONAL = 3, - ORBIS_AUDIO_OUT_PORT_TYPE_PADSPK = 4, - ORBIS_AUDIO_OUT_PORT_TYPE_AUX = 127 +enum class OrbisAudioOutPort { Main = 0, Bgm = 1, Voice = 2, Personal = 3, Padspk = 4, Aux = 127 }; + +enum class OrbisAudioOutParamFormat { + S16Mono = 0, + S16Stereo = 1, + S16_8CH = 2, + FloatMono = 3, + FloatStereo = 4, + Float_8CH = 5, + S16_8CH_Std = 6, + Float_8CH_Std = 7 }; -enum OrbisAudioOutParamFormat { - ORBIS_AUDIO_OUT_PARAM_FORMAT_S16_MONO = 0, - ORBIS_AUDIO_OUT_PARAM_FORMAT_S16_STEREO = 1, - ORBIS_AUDIO_OUT_PARAM_FORMAT_S16_8CH = 2, - ORBIS_AUDIO_OUT_PARAM_FORMAT_FLOAT_MONO = 3, - ORBIS_AUDIO_OUT_PARAM_FORMAT_FLOAT_STEREO = 4, - ORBIS_AUDIO_OUT_PARAM_FORMAT_FLOAT_8CH = 5, - ORBIS_AUDIO_OUT_PARAM_FORMAT_S16_8CH_STD = 6, - ORBIS_AUDIO_OUT_PARAM_FORMAT_FLOAT_8CH_STD = 7 +enum class OrbisAudioOutParamAttr { + None = 0, + Restricted = 1, + MixToMain = 2, }; -enum OrbisAudioOutParamAttr { - ORBIS_AUDIO_OUT_PARAM_ATTR_NONE = 0, - ORBIS_AUDIO_OUT_PARAM_ATTR_RESTRICTED = 1, - ORBIS_AUDIO_OUT_PARAM_ATTR_MIX_TO_MAIN = 2, -}; - -struct OrbisAudioOutParamExtendedInformation { - union { - BitField<0, 8, OrbisAudioOutParamFormat> data_format; - BitField<8, 8, u32> reserve0; - BitField<16, 4, OrbisAudioOutParamAttr> attributes; - BitField<20, 10, u32> reserve1; - BitField<31, 1, u32> unused; - }; +union OrbisAudioOutParamExtendedInformation { + BitField<0, 8, OrbisAudioOutParamFormat> data_format; + BitField<8, 8, u32> reserve0; + BitField<16, 4, OrbisAudioOutParamAttr> attributes; + BitField<20, 10, u32> reserve1; + BitField<31, 1, u32> unused; }; struct OrbisAudioOutOutputParam { diff --git a/src/core/libraries/audio/audioout_error.h b/src/core/libraries/audio/audioout_error.h new file mode 100644 index 00000000..7642e87e --- /dev/null +++ b/src/core/libraries/audio/audioout_error.h @@ -0,0 +1,34 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/libraries/error_codes.h" + +// AudioOut library +constexpr int ORBIS_AUDIO_OUT_ERROR_NOT_OPENED = 0x80260001; +constexpr int ORBIS_AUDIO_OUT_ERROR_BUSY = 0x80260002; +constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_PORT = 0x80260003; +constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_POINTER = 0x80260004; +constexpr int ORBIS_AUDIO_OUT_ERROR_PORT_FULL = 0x80260005; +constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_SIZE = 0x80260006; +constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_FORMAT = 0x80260007; +constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_SAMPLE_FREQ = 0x80260008; +constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_VOLUME = 0x80260009; +constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_PORT_TYPE = 0x8026000A; +constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_CONF_TYPE = 0x8026000C; +constexpr int ORBIS_AUDIO_OUT_ERROR_OUT_OF_MEMORY = 0x8026000D; +constexpr int ORBIS_AUDIO_OUT_ERROR_ALREADY_INIT = 0x8026000E; +constexpr int ORBIS_AUDIO_OUT_ERROR_NOT_INIT = 0x8026000F; +constexpr int ORBIS_AUDIO_OUT_ERROR_MEMORY = 0x80260010; +constexpr int ORBIS_AUDIO_OUT_ERROR_SYSTEM_RESOURCE = 0x80260011; +constexpr int ORBIS_AUDIO_OUT_ERROR_TRANS_EVENT = 0x80260012; +constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_FLAG = 0x80260013; +constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_MIXLEVEL = 0x80260014; +constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_ARG = 0x80260015; +constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_PARAM = 0x80260016; +constexpr int ORBIS_AUDIO_OUT_ERROR_MASTERING_FATAL = 0x80260200; +constexpr int ORBIS_AUDIO_OUT_ERROR_MASTERING_INVALID_API_PARAM = 0x80260201; +constexpr int ORBIS_AUDIO_OUT_ERROR_MASTERING_INVALID_CONFIG = 0x80260202; +constexpr int ORBIS_AUDIO_OUT_ERROR_MASTERING_NOT_INITIALIZED = 0x80260203; +constexpr int ORBIS_AUDIO_OUT_ERROR_MASTERING_INVALID_STATES_ID = 0x80260204; diff --git a/src/core/libraries/audio/sdl_audio.cpp b/src/core/libraries/audio/sdl_audio.cpp new file mode 100644 index 00000000..8cc823ab --- /dev/null +++ b/src/core/libraries/audio/sdl_audio.cpp @@ -0,0 +1,141 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include +#include +#include +#include + +#include "common/assert.h" +#include "core/libraries/audio/audioout_error.h" +#include "core/libraries/audio/sdl_audio.h" + +namespace Libraries::AudioOut { + +constexpr int AUDIO_STREAM_BUFFER_THRESHOLD = 65536; // Define constant for buffer threshold + +s32 SDLAudioOut::Open(OrbisAudioOutPort type, u32 samples_num, u32 freq, + OrbisAudioOutParamFormat format) { + std::scoped_lock lock{m_mutex}; + const auto port = std::ranges::find(ports_out, false, &PortOut::is_open); + if (port == ports_out.end()) { + LOG_ERROR(Lib_AudioOut, "Audio ports are full"); + return ORBIS_AUDIO_OUT_ERROR_PORT_FULL; + } + + port->is_open = true; + port->type = type; + port->samples_num = samples_num; + port->freq = freq; + port->format = format; + SDL_AudioFormat sampleFormat; + switch (format) { + case OrbisAudioOutParamFormat::S16Mono: + sampleFormat = SDL_AUDIO_S16; + port->channels_num = 1; + port->sample_size = 2; + break; + case OrbisAudioOutParamFormat::FloatMono: + sampleFormat = SDL_AUDIO_F32; + port->channels_num = 1; + port->sample_size = 4; + break; + case OrbisAudioOutParamFormat::S16Stereo: + sampleFormat = SDL_AUDIO_S16; + port->channels_num = 2; + port->sample_size = 2; + break; + case OrbisAudioOutParamFormat::FloatStereo: + sampleFormat = SDL_AUDIO_F32; + port->channels_num = 2; + port->sample_size = 4; + break; + case OrbisAudioOutParamFormat::S16_8CH: + sampleFormat = SDL_AUDIO_S16; + port->channels_num = 8; + port->sample_size = 2; + break; + case OrbisAudioOutParamFormat::Float_8CH: + sampleFormat = SDL_AUDIO_F32; + port->channels_num = 8; + port->sample_size = 4; + break; + case OrbisAudioOutParamFormat::S16_8CH_Std: + sampleFormat = SDL_AUDIO_S16; + port->channels_num = 8; + port->sample_size = 2; + break; + case OrbisAudioOutParamFormat::Float_8CH_Std: + sampleFormat = SDL_AUDIO_F32; + port->channels_num = 8; + port->sample_size = 4; + break; + default: + UNREACHABLE_MSG("Unknown format"); + } + + port->volume.fill(Libraries::AudioOut::SCE_AUDIO_OUT_VOLUME_0DB); + + SDL_AudioSpec fmt; + SDL_zero(fmt); + fmt.format = sampleFormat; + fmt.channels = port->channels_num; + fmt.freq = freq; + port->stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &fmt, NULL, NULL); + SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(port->stream)); + return std::distance(ports_out.begin(), port) + 1; +} + +s32 SDLAudioOut::Output(s32 handle, const void* ptr) { + auto& port = ports_out.at(handle - 1); + if (!port.is_open) { + return ORBIS_AUDIO_OUT_ERROR_INVALID_PORT; + } + + const size_t data_size = port.samples_num * port.sample_size * port.channels_num; + bool result = SDL_PutAudioStreamData(port.stream, ptr, data_size); + while (SDL_GetAudioStreamAvailable(port.stream) > AUDIO_STREAM_BUFFER_THRESHOLD) { + SDL_Delay(0); + } + return result ? ORBIS_OK : -1; +} + +s32 SDLAudioOut::SetVolume(s32 handle, s32 bitflag, s32* volume) { + using Libraries::AudioOut::OrbisAudioOutParamFormat; + auto& port = ports_out.at(handle - 1); + if (!port.is_open) { + return ORBIS_AUDIO_OUT_ERROR_INVALID_PORT; + } + + for (int i = 0; i < port.channels_num; i++, bitflag >>= 1u) { + auto bit = bitflag & 0x1u; + + if (bit == 1) { + int src_index = i; + if (port.format == OrbisAudioOutParamFormat::Float_8CH_Std || + port.format == OrbisAudioOutParamFormat::S16_8CH_Std) { + switch (i) { + case 4: + src_index = 6; + break; + case 5: + src_index = 7; + break; + case 6: + src_index = 4; + break; + case 7: + src_index = 5; + break; + default: + break; + } + } + port.volume[i] = volume[src_index]; + } + } + + return ORBIS_OK; +} + +} // namespace Libraries::AudioOut diff --git a/src/core/libraries/audio/sdl_audio.h b/src/core/libraries/audio/sdl_audio.h new file mode 100644 index 00000000..2c34f8e2 --- /dev/null +++ b/src/core/libraries/audio/sdl_audio.h @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include +#include +#include "core/libraries/audio/audioout.h" + +namespace Libraries::AudioOut { + +class SDLAudioOut { +public: + explicit SDLAudioOut() = default; + ~SDLAudioOut() = default; + + s32 Open(OrbisAudioOutPort type, u32 samples_num, u32 freq, OrbisAudioOutParamFormat format); + s32 Output(s32 handle, const void* ptr); + s32 SetVolume(s32 handle, s32 bitflag, s32* volume); + + constexpr std::pair GetStatus(s32 handle) const { + const auto& port = ports_out.at(handle - 1); + return std::make_pair(port.type, port.channels_num); + } + +private: + struct PortOut { + SDL_AudioStream* stream; + u32 samples_num; + u32 freq; + OrbisAudioOutParamFormat format; + OrbisAudioOutPort type; + int channels_num; + std::array volume; + u8 sample_size; + bool is_open; + }; + std::shared_mutex m_mutex; + std::array ports_out{}; +}; + +} // namespace Libraries::AudioOut diff --git a/src/core/libraries/audio3d/audio3d.cpp b/src/core/libraries/audio3d/audio3d.cpp index 8aeb88da..44670d87 100644 --- a/src/core/libraries/audio3d/audio3d.cpp +++ b/src/core/libraries/audio3d/audio3d.cpp @@ -1,19 +1,15 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "audio3d.h" -#include "audio3d_error.h" -#include "audio3d_impl.h" - #include "common/logging/log.h" #include "core/libraries/audio/audioout.h" +#include "core/libraries/audio3d/audio3d.h" +#include "core/libraries/audio3d/audio3d_error.h" #include "core/libraries/error_codes.h" #include "core/libraries/libs.h" namespace Libraries::Audio3d { -// Audio3d - int PS4_SYSV_ABI sceAudio3dInitialize(s64 iReserved) { LOG_INFO(Lib_Audio3d, "iReserved = {}", iReserved); return ORBIS_OK; @@ -25,18 +21,19 @@ int PS4_SYSV_ABI sceAudio3dTerminate() { return ORBIS_OK; } -void PS4_SYSV_ABI sceAudio3dGetDefaultOpenParameters(OrbisAudio3dOpenParameters* sParameters) { - if (sParameters != NULL) { - sParameters->szSizeThis = sizeof(OrbisAudio3dOpenParameters); - sParameters->uiGranularity = 256; - sParameters->eRate = ORBIS_AUDIO3D_RATE_48000; - sParameters->uiMaxObjects = 512; - sParameters->uiQueueDepth = 2; - sParameters->eBufferMode = ORBIS_AUDIO3D_BUFFER_ADVANCE_AND_PUSH; - sParameters->uiNumBeds = 2; - } else { +void PS4_SYSV_ABI sceAudio3dGetDefaultOpenParameters(OrbisAudio3dOpenParameters* parameters) { + if (parameters == nullptr) { LOG_ERROR(Lib_Audio3d, "Invalid OpenParameters ptr"); + return; } + + parameters->size_this = sizeof(OrbisAudio3dOpenParameters); + parameters->granularity = 256; + parameters->rate = OrbisAudio3dRate::Rate48000; + parameters->max_objects = 512; + parameters->queue_depth = 2; + parameters->buffer_mode = OrbisAudio3dBufferMode::AdvanceAndPush; + parameters->num_beds = 2; } int PS4_SYSV_ABI sceAudio3dPortOpen(OrbisUserServiceUserId iUserId, @@ -76,13 +73,13 @@ int PS4_SYSV_ABI sceAudio3dPortPush(OrbisAudio3dPortId uiPortId, OrbisAudio3dBlo int PS4_SYSV_ABI sceAudio3dPortGetAttributesSupported(OrbisAudio3dPortId uiPortId, OrbisAudio3dAttributeId* pCapabilities, - unsigned int* pNumCapabilities) { + u32* pNumCapabilities) { LOG_INFO(Lib_Audio3d, "uiPortId = {}", uiPortId); return ORBIS_OK; } -int PS4_SYSV_ABI sceAudio3dPortGetQueueLevel(OrbisAudio3dPortId uiPortId, unsigned int* pQueueLevel, - unsigned int* pQueueAvailable) { +int PS4_SYSV_ABI sceAudio3dPortGetQueueLevel(OrbisAudio3dPortId uiPortId, u32* pQueueLevel, + u32* pQueueAvailable) { LOG_INFO(Lib_Audio3d, "uiPortId = {}", uiPortId); return ORBIS_OK; } @@ -107,24 +104,24 @@ int PS4_SYSV_ABI sceAudio3dObjectSetAttributes(OrbisAudio3dPortId uiPortId, return ORBIS_OK; } -int PS4_SYSV_ABI sceAudio3dBedWrite(OrbisAudio3dPortId uiPortId, unsigned int uiNumChannels, +int PS4_SYSV_ABI sceAudio3dBedWrite(OrbisAudio3dPortId uiPortId, u32 uiNumChannels, OrbisAudio3dFormat eFormat, const void* pBuffer, - unsigned int uiNumSamples) { + u32 uiNumSamples) { LOG_TRACE(Lib_Audio3d, "uiPortId = {}, uiNumChannels = {}, uiNumSamples = {}", uiPortId, uiNumChannels, uiNumSamples); return ORBIS_OK; } -int PS4_SYSV_ABI sceAudio3dBedWrite2(OrbisAudio3dPortId uiPortId, unsigned int uiNumChannels, +int PS4_SYSV_ABI sceAudio3dBedWrite2(OrbisAudio3dPortId uiPortId, u32 uiNumChannels, OrbisAudio3dFormat eFormat, const void* pBuffer, - unsigned int uiNumSamples, - OrbisAudio3dOutputRoute eOutputRoute, bool bRestricted) { + u32 uiNumSamples, OrbisAudio3dOutputRoute eOutputRoute, + bool bRestricted) { LOG_INFO(Lib_Audio3d, "uiPortId = {}, uiNumChannels = {}, uiNumSamples = {}, bRestricted = {}", uiPortId, uiNumChannels, uiNumSamples, bRestricted); return ORBIS_OK; } -size_t PS4_SYSV_ABI sceAudio3dGetSpeakerArrayMemorySize(unsigned int uiNumSpeakers, bool bIs3d) { +size_t PS4_SYSV_ABI sceAudio3dGetSpeakerArrayMemorySize(u32 uiNumSpeakers, bool bIs3d) { LOG_INFO(Lib_Audio3d, "uiNumSpeakers = {}, bIs3d = {}", uiNumSpeakers, bIs3d); return ORBIS_OK; } @@ -152,7 +149,7 @@ int PS4_SYSV_ABI sceAudio3dDeleteSpeakerArray(OrbisAudio3dSpeakerArrayHandle han int PS4_SYSV_ABI sceAudio3dGetSpeakerArrayMixCoefficients(OrbisAudio3dSpeakerArrayHandle handle, OrbisAudio3dPosition pos, float fSpread, float* pCoefficients, - unsigned int uiNumCoefficients) { + u32 uiNumCoefficients) { LOG_INFO(Lib_Audio3d, "fSpread = {}, uiNumCoefficients = {}", fSpread, uiNumCoefficients); if (handle == nullptr) { LOG_ERROR(Lib_Audio3d, "invalid SpeakerArrayHandle"); @@ -164,8 +161,7 @@ int PS4_SYSV_ABI sceAudio3dGetSpeakerArrayMixCoefficients(OrbisAudio3dSpeakerArr int PS4_SYSV_ABI sceAudio3dGetSpeakerArrayMixCoefficients2(OrbisAudio3dSpeakerArrayHandle handle, OrbisAudio3dPosition pos, float fSpread, float* pCoefficients, - unsigned int uiNumCoefficients, - bool bHeightAware, + u32 uiNumCoefficients, bool bHeightAware, float fDownmixSpreadRadius) { LOG_INFO(Lib_Audio3d, "fSpread = {}, uiNumCoefficients = {}, bHeightAware = {}, fDownmixSpreadRadius = {}", @@ -209,8 +205,8 @@ s32 PS4_SYSV_ABI sceAudio3dAudioOutOutputs(::Libraries::AudioOut::OrbisAudioOutO return ORBIS_OK; } -int PS4_SYSV_ABI sceAudio3dPortCreate(unsigned int uiGranularity, OrbisAudio3dRate eRate, - s64 iReserved, OrbisAudio3dPortId* pId) { +int PS4_SYSV_ABI sceAudio3dPortCreate(u32 uiGranularity, OrbisAudio3dRate eRate, s64 iReserved, + OrbisAudio3dPortId* pId) { LOG_INFO(Lib_Audio3d, "uiGranularity = {}, iReserved = {}", uiGranularity, iReserved); return ORBIS_OK; } @@ -341,4 +337,4 @@ void RegisterlibSceAudio3d(Core::Loader::SymbolsResolver* sym) { sceAudio3dSetGpuRenderer); }; -} // namespace Libraries::Audio3d \ No newline at end of file +} // namespace Libraries::Audio3d diff --git a/src/core/libraries/audio3d/audio3d.h b/src/core/libraries/audio3d/audio3d.h index 6cbe2d02..6f344226 100644 --- a/src/core/libraries/audio3d/audio3d.h +++ b/src/core/libraries/audio3d/audio3d.h @@ -15,56 +15,57 @@ namespace Libraries::Audio3d { class Audio3d; -typedef int OrbisUserServiceUserId; -typedef unsigned int OrbisAudio3dPortId; -typedef unsigned int OrbisAudio3dObjectId; -typedef unsigned int OrbisAudio3dAttributeId; +using OrbisUserServiceUserId = s32; +using OrbisAudio3dPortId = u32; +using OrbisAudio3dObjectId = u32; +using OrbisAudio3dAttributeId = u32; -enum OrbisAudio3dFormat { - ORBIS_AUDIO3D_FORMAT_S16 = 0, // s16 - ORBIS_AUDIO3D_FORMAT_FLOAT = 1 // f32 +enum class OrbisAudio3dFormat { + S16 = 0, + Float = 1, }; -enum OrbisAudio3dRate { ORBIS_AUDIO3D_RATE_48000 = 0 }; - -enum OrbisAudio3dBufferMode { - ORBIS_AUDIO3D_BUFFER_NO_ADVANCE = 0, - ORBIS_AUDIO3D_BUFFER_ADVANCE_NO_PUSH = 1, - ORBIS_AUDIO3D_BUFFER_ADVANCE_AND_PUSH = 2 +enum class OrbisAudio3dRate { + Rate48000 = 0, }; -enum OrbisAudio3dBlocking { ORBIS_AUDIO3D_BLOCKING_ASYNC = 0, ORBIS_AUDIO3D_BLOCKING_SYNC = 1 }; +enum class OrbisAudio3dBufferMode { NoAdvance = 0, AdvanceNoPush = 1, AdvanceAndPush = 2 }; -enum OrbisAudio3dPassthrough { - ORBIS_AUDIO3D_PASSTHROUGH_NONE = 0, - ORBIS_AUDIO3D_PASSTHROUGH_LEFT = 1, - ORBIS_AUDIO3D_PASSTHROUGH_RIGHT = 2 +enum class OrbisAudio3dBlocking { + Async = 0, + Sync = 1, }; -enum OrbisAudio3dOutputRoute { - ORBIS_AUDIO3D_OUTPUT_BOTH = 0, - ORBIS_AUDIO3D_OUTPUT_HMU_ONLY = 1, - ORBIS_AUDIO3D_OUTPUT_TV_ONLY = 2 +enum class OrbisAudio3dPassthrough { + None = 0, + Left = 1, + Right = 2, }; -enum OrbisAudio3dAmbisonics { - ORBIS_AUDIO3D_AMBISONICS_NONE = ~0, - ORBIS_AUDIO3D_AMBISONICS_W = 0, - ORBIS_AUDIO3D_AMBISONICS_X = 1, - ORBIS_AUDIO3D_AMBISONICS_Y = 2, - ORBIS_AUDIO3D_AMBISONICS_Z = 3, - ORBIS_AUDIO3D_AMBISONICS_R = 4, - ORBIS_AUDIO3D_AMBISONICS_S = 5, - ORBIS_AUDIO3D_AMBISONICS_T = 6, - ORBIS_AUDIO3D_AMBISONICS_U = 7, - ORBIS_AUDIO3D_AMBISONICS_V = 8, - ORBIS_AUDIO3D_AMBISONICS_K = 9, - ORBIS_AUDIO3D_AMBISONICS_L = 10, - ORBIS_AUDIO3D_AMBISONICS_M = 11, - ORBIS_AUDIO3D_AMBISONICS_N = 12, - ORBIS_AUDIO3D_AMBISONICS_O = 13, - ORBIS_AUDIO3D_AMBISONICS_P = 14, - ORBIS_AUDIO3D_AMBISONICS_Q = 15 +enum class OrbisAudio3dOutputRoute { + Both = 0, + HmuOnly = 1, + TvOnly = 2, +}; + +enum class OrbisAudio3dAmbisonics : u32 { + None = ~0U, + W = 0, + X = 1, + Y = 2, + Z = 3, + R = 4, + S = 5, + T = 6, + U = 7, + V = 8, + K = 9, + L = 10, + M = 11, + N = 12, + O = 13, + P = 14, + Q = 15 }; static const OrbisAudio3dAttributeId s_sceAudio3dAttributePcm = 0x00000001; @@ -86,21 +87,21 @@ struct OrbisAudio3dSpeakerArray; using OrbisAudio3dSpeakerArrayHandle = OrbisAudio3dSpeakerArray*; // head struct OrbisAudio3dOpenParameters { - size_t szSizeThis; - unsigned int uiGranularity; - OrbisAudio3dRate eRate; - unsigned int uiMaxObjects; - unsigned int uiQueueDepth; - OrbisAudio3dBufferMode eBufferMode; + size_t size_this; + u32 granularity; + OrbisAudio3dRate rate; + u32 max_objects; + u32 queue_depth; + OrbisAudio3dBufferMode buffer_mode; char padding[32]; - unsigned int uiNumBeds; + u32 num_beds; }; struct OrbisAudio3dAttribute { - OrbisAudio3dAttributeId uiAttributeId; + OrbisAudio3dAttributeId attribute_id; char padding[32]; - const void* pValue; - size_t szValue; + const void* p_value; + size_t value; }; struct OrbisAudio3dPosition { @@ -110,25 +111,25 @@ struct OrbisAudio3dPosition { }; struct OrbisAudio3dPcm { - OrbisAudio3dFormat eFormat; - const void* pSampleBuffer; - unsigned int uiNumSamples; + OrbisAudio3dFormat format; + const void* sample_buffer; + u32 num_samples; }; struct OrbisAudio3dSpeakerArrayParameters { - OrbisAudio3dPosition* pSpeakerPosition; - unsigned int uiNumSpeakers; - bool bIs3d; - void* pBuffer; - size_t szSize; + OrbisAudio3dPosition* speaker_position; + u32 num_speakers; + bool is_3d; + void* buffer; + size_t size; }; struct OrbisAudio3dApplicationSpecific { - size_t szSizeThis; - u8 cApplicationSpecific[32]; + size_t size_this; + u8 application_specific[32]; }; void PS4_SYSV_ABI sceAudio3dGetDefaultOpenParameters(OrbisAudio3dOpenParameters* sParameters); void RegisterlibSceAudio3d(Core::Loader::SymbolsResolver* sym); -} // namespace Libraries::Audio3d \ No newline at end of file +} // namespace Libraries::Audio3d diff --git a/src/core/libraries/audio3d/audio3d_error.h b/src/core/libraries/audio3d/audio3d_error.h index ff9d9749..626ac869 100644 --- a/src/core/libraries/audio3d/audio3d_error.h +++ b/src/core/libraries/audio3d/audio3d_error.h @@ -3,6 +3,8 @@ #pragma once +#include "core/libraries/error_codes.h" + constexpr int ORBIS_AUDIO3D_ERROR_UNKNOWN = 0x80EA0001; constexpr int ORBIS_AUDIO3D_ERROR_INVALID_PORT = 0x80EA0002; constexpr int ORBIS_AUDIO3D_ERROR_INVALID_OBJECT = 0x80EA0003; diff --git a/src/core/libraries/audio3d/audio3d_impl.h b/src/core/libraries/audio3d/audio3d_impl.h index 4e6342b1..1213a030 100644 --- a/src/core/libraries/audio3d/audio3d_impl.h +++ b/src/core/libraries/audio3d/audio3d_impl.h @@ -10,7 +10,7 @@ namespace Libraries::Audio3d { class Audio3d { public: private: - typedef unsigned int OrbisAudio3dPluginId; + using OrbisAudio3dPluginId = u32; }; } // namespace Libraries::Audio3d diff --git a/src/core/libraries/avplayer/avplayer.cpp b/src/core/libraries/avplayer/avplayer.cpp index 1257473e..176fda13 100644 --- a/src/core/libraries/avplayer/avplayer.cpp +++ b/src/core/libraries/avplayer/avplayer.cpp @@ -3,8 +3,8 @@ #include "common/logging/log.h" #include "core/libraries/avplayer/avplayer.h" +#include "core/libraries/avplayer/avplayer_error.h" #include "core/libraries/avplayer/avplayer_impl.h" -#include "core/libraries/error_codes.h" #include "core/libraries/libs.h" namespace Libraries::AvPlayer { diff --git a/src/core/libraries/avplayer/avplayer.h b/src/core/libraries/avplayer/avplayer.h index 9f100bef..2d472f80 100644 --- a/src/core/libraries/avplayer/avplayer.h +++ b/src/core/libraries/avplayer/avplayer.h @@ -18,17 +18,26 @@ class AvPlayer; using SceAvPlayerHandle = AvPlayer*; -enum SceAvPlayerUriType { SCE_AVPLAYER_URI_TYPE_SOURCE = 0 }; +enum class SceAvPlayerUriType : u32 { + Source = 0, +}; struct SceAvPlayerUri { const char* name; u32 length; }; -enum SceAvPlayerSourceType { - SCE_AVPLAYER_SOURCE_TYPE_UNKNOWN = 0, - SCE_AVPLAYER_SOURCE_TYPE_FILE_MP4 = 1, - SCE_AVPLAYER_SOURCE_TYPE_HLS = 8 +enum class SceAvPlayerSourceType { + Unknown = 0, + FileMp4 = 1, + Hls = 8, +}; + +enum class SceAvPlayerStreamType : u32 { + Video, + Audio, + TimedText, + Unknown, }; struct SceAvPlayerSourceDetails { @@ -50,7 +59,7 @@ struct SceAvPlayerVideo { u32 width; u32 height; f32 aspect_ratio; - u8 language_code[4]; + char language_code[4]; }; struct SceAvPlayerTextPosition { @@ -82,7 +91,7 @@ struct SceAvPlayerFrameInfo { }; struct SceAvPlayerStreamInfo { - u32 type; + SceAvPlayerStreamType type; u8 reserved[4]; SceAvPlayerStreamDetails details; u64 duration; @@ -135,10 +144,10 @@ struct SceAvPlayerFrameInfoEx { SceAvPlayerStreamDetailsEx details; }; -typedef void* PS4_SYSV_ABI (*SceAvPlayerAllocate)(void* p, u32 align, u32 size); -typedef void PS4_SYSV_ABI (*SceAvPlayerDeallocate)(void* p, void* mem); -typedef void* PS4_SYSV_ABI (*SceAvPlayerAllocateTexture)(void* p, u32 align, u32 size); -typedef void PS4_SYSV_ABI (*SceAvPlayerDeallocateTexture)(void* p, void* mem); +using SceAvPlayerAllocate = void* PS4_SYSV_ABI (*)(void* p, u32 align, u32 size); +using SceAvPlayerDeallocate = void PS4_SYSV_ABI (*)(void* p, void* mem); +using SceAvPlayerAllocateTexture = void* PS4_SYSV_ABI (*)(void* p, u32 align, u32 size); +using SceAvPlayerDeallocateTexture = void PS4_SYSV_ABI (*)(void* p, void* mem); struct SceAvPlayerMemAllocator { void* object_ptr; @@ -148,10 +157,10 @@ struct SceAvPlayerMemAllocator { SceAvPlayerDeallocateTexture deallocate_texture; }; -typedef s32 PS4_SYSV_ABI (*SceAvPlayerOpenFile)(void* p, const char* name); -typedef s32 PS4_SYSV_ABI (*SceAvPlayerCloseFile)(void* p); -typedef s32 PS4_SYSV_ABI (*SceAvPlayerReadOffsetFile)(void* p, u8* buf, u64 pos, u32 len); -typedef u64 PS4_SYSV_ABI (*SceAvPlayerSizeFile)(void* p); +using SceAvPlayerOpenFile = s32 PS4_SYSV_ABI (*)(void* p, const char* name); +using SceAvPlayerCloseFile = s32 PS4_SYSV_ABI (*)(void* p); +using SceAvPlayerReadOffsetFile = s32 PS4_SYSV_ABI (*)(void* p, u8* buf, u64 pos, u32 len); +using SceAvPlayerSizeFile = u64 PS4_SYSV_ABI (*)(void* p); struct SceAvPlayerFileReplacement { void* object_ptr; @@ -161,31 +170,31 @@ struct SceAvPlayerFileReplacement { SceAvPlayerSizeFile size; }; -enum SceAvPlayerEvents { - SCE_AVPLAYER_STATE_STOP = 0x01, - SCE_AVPLAYER_STATE_READY = 0x02, - SCE_AVPLAYER_STATE_PLAY = 0x03, - SCE_AVPLAYER_STATE_PAUSE = 0x04, - SCE_AVPLAYER_STATE_BUFFERING = 0x05, - SCE_AVPLAYER_TIMED_TEXT_DELIVERY = 0x10, - SCE_AVPLAYER_WARNING_ID = 0x20, - SCE_AVPLAYER_ENCRYPTION = 0x30, - SCE_AVPLAYER_DRM_ERROR = 0x40 +enum class SceAvPlayerEvents { + StateStop = 0x01, + StateReady = 0x02, + StatePlay = 0x03, + StatePause = 0x04, + StateBuffering = 0x05, + TimedTextDelivery = 0x10, + WarningId = 0x20, + Encryption = 0x30, + DrmError = 0x40, }; -typedef void PS4_SYSV_ABI (*SceAvPlayerEventCallback)(void* p, SceAvPlayerEvents event, s32 src_id, - void* data); +using SceAvPlayerEventCallback = void PS4_SYSV_ABI (*)(void* p, SceAvPlayerEvents event, s32 src_id, + void* data); struct SceAvPlayerEventReplacement { void* object_ptr; SceAvPlayerEventCallback event_callback; }; -enum SceAvPlayerDebuglevels { - SCE_AVPLAYER_DBG_NONE, - SCE_AVPLAYER_DBG_INFO, - SCE_AVPLAYER_DBG_WARNINGS, - SCE_AVPLAYER_DBG_ALL +enum class SceAvPlayerDebuglevels { + None, + Info, + Warnings, + All, }; struct SceAvPlayerInitData { @@ -224,24 +233,17 @@ struct SceAvPlayerInitDataEx { u8 reserved[3]; }; -enum SceAvPlayerStreamType { - SCE_AVPLAYER_VIDEO, - SCE_AVPLAYER_AUDIO, - SCE_AVPLAYER_TIMEDTEXT, - SCE_AVPLAYER_UNKNOWN +enum class SceAvPlayerVideoDecoderType { + Default = 0, + Reserved1, + Software, + Software2, }; -enum SceAvPlayerVideoDecoderType { - SCE_AVPLAYER_VIDEO_DECODER_TYPE_DEFAULT = 0, - SCE_AVPLAYER_VIDEO_DECODER_TYPE_RESERVED1, - SCE_AVPLAYER_VIDEO_DECODER_TYPE_SOFTWARE, - SCE_AVPLAYER_VIDEO_DECODER_TYPE_SOFTWARE2 -}; - -enum SceAvPlayerAudioDecoderType { - SCE_AVPLAYER_AUDIO_DECODER_TYPE_DEFAULT = 0, - SCE_AVPLAYER_AUDIO_DECODER_TYPE_RESERVED1, - SCE_AVPLAYER_AUDIO_DECODER_TYPE_RESERVED2 +enum class SceAvPlayerAudioDecoderType { + Default = 0, + Reserved1, + Reserved2, }; struct SceAvPlayerDecoderInit { @@ -281,12 +283,12 @@ struct SceAvPlayerPostInitData { u8 reserved[56]; }; -enum SceAvPlayerAvSyncMode { - SCE_AVPLAYER_AV_SYNC_MODE_DEFAULT = 0, - SCE_AVPLAYER_AV_SYNC_MODE_NONE +enum class SceAvPlayerAvSyncMode { + Default = 0, + None, }; -typedef int PS4_SYSV_ABI (*SceAvPlayerLogCallback)(void* p, const char* format, va_list args); +using SceAvPlayerLogCallback = int PS4_SYSV_ABI (*)(void* p, const char* format, va_list args); void RegisterlibSceAvPlayer(Core::Loader::SymbolsResolver* sym); diff --git a/src/core/libraries/avplayer/avplayer_common.cpp b/src/core/libraries/avplayer/avplayer_common.cpp index 805920a3..28d7803a 100644 --- a/src/core/libraries/avplayer/avplayer_common.cpp +++ b/src/core/libraries/avplayer/avplayer_common.cpp @@ -15,7 +15,7 @@ static bool iequals(std::string_view l, std::string_view r) { SceAvPlayerSourceType GetSourceType(std::string_view path) { if (path.empty()) { - return SCE_AVPLAYER_SOURCE_TYPE_UNKNOWN; + return SceAvPlayerSourceType::Unknown; } std::string_view name = path; @@ -25,14 +25,14 @@ SceAvPlayerSourceType GetSourceType(std::string_view path) { // -> schema://server.domain/path/to/file.ext/and/beyond name = path.substr(0, path.find_first_of("?#")); if (name.empty()) { - return SCE_AVPLAYER_SOURCE_TYPE_UNKNOWN; + return SceAvPlayerSourceType::Unknown; } } // schema://server.domain/path/to/file.ext/and/beyond -> .ext/and/beyond auto ext = name.substr(name.rfind('.')); if (ext.empty()) { - return SCE_AVPLAYER_SOURCE_TYPE_UNKNOWN; + return SceAvPlayerSourceType::Unknown; } // .ext/and/beyond -> .ext @@ -40,14 +40,14 @@ SceAvPlayerSourceType GetSourceType(std::string_view path) { if (iequals(ext, ".mp4") || iequals(ext, ".m4v") || iequals(ext, ".m3d") || iequals(ext, ".m4a") || iequals(ext, ".mov")) { - return SCE_AVPLAYER_SOURCE_TYPE_FILE_MP4; + return SceAvPlayerSourceType::FileMp4; } if (iequals(ext, ".m3u8")) { - return SCE_AVPLAYER_SOURCE_TYPE_HLS; + return SceAvPlayerSourceType::Hls; } - return SCE_AVPLAYER_SOURCE_TYPE_UNKNOWN; + return SceAvPlayerSourceType::Unknown; } } // namespace Libraries::AvPlayer diff --git a/src/core/libraries/avplayer/avplayer_error.h b/src/core/libraries/avplayer/avplayer_error.h new file mode 100644 index 00000000..ebe4d0dd --- /dev/null +++ b/src/core/libraries/avplayer/avplayer_error.h @@ -0,0 +1,19 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/libraries/error_codes.h" + +// AvPlayer library +constexpr int ORBIS_AVPLAYER_ERROR_INVALID_PARAMS = 0x806A0001; +constexpr int ORBIS_AVPLAYER_ERROR_OPERATION_FAILED = 0x806A0002; +constexpr int ORBIS_AVPLAYER_ERROR_NO_MEMORY = 0x806A0003; +constexpr int ORBIS_AVPLAYER_ERROR_NOT_SUPPORTED = 0x806A0004; +constexpr int ORBIS_AVPLAYER_ERROR_WAR_FILE_NONINTERLEAVED = 0x806A00A0; +constexpr int ORBIS_AVPLAYER_ERROR_WAR_LOOPING_BACK = 0x806A00A1; +constexpr int ORBIS_AVPLAYER_ERROR_WAR_JUMP_COMPLETE = 0x806A00A3; +constexpr int ORBIS_AVPLAYER_ERROR_INFO_MARLIN_ENCRY = 0x806A00B0; +constexpr int ORBIS_AVPLAYER_ERROR_INFO_PLAYREADY_ENCRY = 0x806A00B4; +constexpr int ORBIS_AVPLAYER_ERROR_INFO_AES_ENCRY = 0x806A00B5; +constexpr int ORBIS_AVPLAYER_ERROR_INFO_OTHER_ENCRY = 0x806A00BF; diff --git a/src/core/libraries/avplayer/avplayer_impl.cpp b/src/core/libraries/avplayer/avplayer_impl.cpp index 0f39acfd..d9a67134 100644 --- a/src/core/libraries/avplayer/avplayer_impl.cpp +++ b/src/core/libraries/avplayer/avplayer_impl.cpp @@ -2,8 +2,8 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "core/libraries/avplayer/avplayer_common.h" +#include "core/libraries/avplayer/avplayer_error.h" #include "core/libraries/avplayer/avplayer_impl.h" -#include "core/libraries/error_codes.h" #include "core/tls.h" namespace Libraries::AvPlayer { diff --git a/src/core/libraries/avplayer/avplayer_source.cpp b/src/core/libraries/avplayer/avplayer_source.cpp index 8a65377c..8e43e727 100644 --- a/src/core/libraries/avplayer/avplayer_source.cpp +++ b/src/core/libraries/avplayer/avplayer_source.cpp @@ -85,17 +85,17 @@ s32 AvPlayerSource::GetStreamCount() { return m_avformat_context->nb_streams; } -static s32 CodecTypeToStreamType(AVMediaType codec_type) { +static SceAvPlayerStreamType CodecTypeToStreamType(AVMediaType codec_type) { switch (codec_type) { case AVMediaType::AVMEDIA_TYPE_VIDEO: - return SCE_AVPLAYER_VIDEO; + return SceAvPlayerStreamType::Video; case AVMediaType::AVMEDIA_TYPE_AUDIO: - return SCE_AVPLAYER_AUDIO; + return SceAvPlayerStreamType::Audio; case AVMediaType::AVMEDIA_TYPE_SUBTITLE: - return SCE_AVPLAYER_TIMEDTEXT; + return SceAvPlayerStreamType::TimedText; default: LOG_ERROR(Lib_AvPlayer, "Unexpected AVMediaType {}", magic_enum::enum_name(codec_type)); - return -1; + return SceAvPlayerStreamType::Unknown; } } @@ -124,7 +124,7 @@ bool AvPlayerSource::GetStreamInfo(u32 stream_index, SceAvPlayerStreamInfo& info LOG_WARNING(Lib_AvPlayer, "Stream {} language is unknown", stream_index); } switch (info.type) { - case SCE_AVPLAYER_VIDEO: { + case SceAvPlayerStreamType::Video: { LOG_INFO(Lib_AvPlayer, "Stream {} is a video stream.", stream_index); info.details.video.aspect_ratio = f32(p_stream->codecpar->width) / p_stream->codecpar->height; @@ -142,7 +142,7 @@ bool AvPlayerSource::GetStreamInfo(u32 stream_index, SceAvPlayerStreamInfo& info } break; } - case SCE_AVPLAYER_AUDIO: { + case SceAvPlayerStreamType::Audio: { LOG_INFO(Lib_AvPlayer, "Stream {} is an audio stream.", stream_index); info.details.audio.channel_count = p_stream->codecpar->ch_layout.nb_channels; info.details.audio.sample_rate = p_stream->codecpar->sample_rate; @@ -153,7 +153,7 @@ bool AvPlayerSource::GetStreamInfo(u32 stream_index, SceAvPlayerStreamInfo& info } break; } - case SCE_AVPLAYER_TIMEDTEXT: { + case SceAvPlayerStreamType::TimedText: { LOG_WARNING(Lib_AvPlayer, "Stream {} is a timedtext stream.", stream_index); info.details.subs.font_size = 12; info.details.subs.text_size = 12; @@ -164,7 +164,8 @@ bool AvPlayerSource::GetStreamInfo(u32 stream_index, SceAvPlayerStreamInfo& info break; } default: { - LOG_ERROR(Lib_AvPlayer, "Stream {} type is unknown: {}.", stream_index, info.type); + LOG_ERROR(Lib_AvPlayer, "Stream {} type is unknown: {}.", stream_index, + magic_enum::enum_name(info.type)); return false; } } diff --git a/src/core/libraries/avplayer/avplayer_state.cpp b/src/core/libraries/avplayer/avplayer_state.cpp index 3d9840a1..c3694eec 100644 --- a/src/core/libraries/avplayer/avplayer_state.cpp +++ b/src/core/libraries/avplayer/avplayer_state.cpp @@ -3,9 +3,9 @@ #include "common/logging/log.h" #include "common/thread.h" +#include "core/libraries/avplayer/avplayer_error.h" #include "core/libraries/avplayer/avplayer_source.h" #include "core/libraries/avplayer/avplayer_state.h" -#include "core/libraries/error_codes.h" #include "core/tls.h" #include @@ -16,7 +16,7 @@ void PS4_SYSV_ABI AvPlayerState::AutoPlayEventCallback(void* opaque, SceAvPlayer s32 source_id, void* event_data) { auto const self = reinterpret_cast(opaque); - if (event_id == SCE_AVPLAYER_STATE_READY) { + if (event_id == SceAvPlayerEvents::StateReady) { s32 video_stream_index = -1; s32 audio_stream_index = -1; s32 timedtext_stream_index = -1; @@ -36,36 +36,37 @@ void PS4_SYSV_ABI AvPlayerState::AutoPlayEventCallback(void* opaque, SceAvPlayer return; } - const std::string_view default_language( - reinterpret_cast(self->m_default_language)); + const std::string_view default_language{self->m_default_language}; switch (info.type) { - case SCE_AVPLAYER_VIDEO: + case SceAvPlayerStreamType::Video: if (video_stream_index == -1) { video_stream_index = stream_index; } if (!default_language.empty() && - default_language == reinterpret_cast(info.details.video.language_code)) { + default_language == info.details.video.language_code) { video_stream_index = stream_index; } break; - case SCE_AVPLAYER_AUDIO: + case SceAvPlayerStreamType::Audio: if (audio_stream_index == -1) { audio_stream_index = stream_index; } if (!default_language.empty() && - default_language == reinterpret_cast(info.details.video.language_code)) { + default_language == info.details.video.language_code) { audio_stream_index = stream_index; } break; - case SCE_AVPLAYER_TIMEDTEXT: + case SceAvPlayerStreamType::TimedText: if (default_language.empty()) { timedtext_stream_index = stream_index; break; } - if (default_language == reinterpret_cast(info.details.video.language_code)) { + if (default_language == info.details.video.language_code) { timedtext_stream_index = stream_index; } break; + default: + break; } } @@ -141,7 +142,7 @@ bool AvPlayerState::AddSource(std::string_view path, SceAvPlayerSourceType sourc m_up_source = std::make_unique( *this, m_post_init_data.video_decoder_init.decoderType.video_type == - SCE_AVPLAYER_VIDEO_DECODER_TYPE_SOFTWARE2); + SceAvPlayerVideoDecoderType::Software2); if (!m_up_source->Init(m_init_data, path)) { SetState(AvState::Error); m_up_source.reset(); @@ -317,23 +318,23 @@ void AvPlayerState::OnEOF() { void AvPlayerState::OnPlaybackStateChanged(AvState state) { switch (state) { case AvState::Ready: { - EmitEvent(SCE_AVPLAYER_STATE_READY); + EmitEvent(SceAvPlayerEvents::StateReady); break; } case AvState::Play: { - EmitEvent(SCE_AVPLAYER_STATE_PLAY); + EmitEvent(SceAvPlayerEvents::StatePlay); break; } case AvState::Stop: { - EmitEvent(SCE_AVPLAYER_STATE_STOP); + EmitEvent(SceAvPlayerEvents::StateStop); break; } case AvState::Pause: { - EmitEvent(SCE_AVPLAYER_STATE_PAUSE); + EmitEvent(SceAvPlayerEvents::StatePause); break; } case AvState::Buffering: { - EmitEvent(SCE_AVPLAYER_STATE_BUFFERING); + EmitEvent(SceAvPlayerEvents::StateBuffering); break; } default: diff --git a/src/core/libraries/avplayer/avplayer_state.h b/src/core/libraries/avplayer/avplayer_state.h index 8a0d7f4f..48cd17bf 100644 --- a/src/core/libraries/avplayer/avplayer_state.h +++ b/src/core/libraries/avplayer/avplayer_state.h @@ -69,7 +69,7 @@ private: SceAvPlayerPostInitData m_post_init_data{}; SceAvPlayerEventReplacement m_event_replacement{}; bool m_auto_start{}; - u8 m_default_language[4]{}; + char m_default_language[4]{}; std::atomic m_current_state; std::atomic m_previous_state; diff --git a/src/core/libraries/error_codes.h b/src/core/libraries/error_codes.h index 280ddf1c..e1902b61 100644 --- a/src/core/libraries/error_codes.h +++ b/src/core/libraries/error_codes.h @@ -3,626 +3,6 @@ #pragma once -// posix error codes -constexpr int POSIX_EPERM = 1; -constexpr int POSIX_ENOENT = 2; -constexpr int POSIX_ESRCH = 3; -constexpr int POSIX_EINTR = 4; -constexpr int POSIX_EIO = 5; -constexpr int POSIX_ENXIO = 6; -constexpr int POSIX_E2BIG = 7; -constexpr int POSIX_ENOEXEC = 8; -constexpr int POSIX_EBADF = 9; -constexpr int POSIX_ECHILD = 10; -constexpr int POSIX_EDEADLK = 11; -constexpr int POSIX_ENOMEM = 12; -constexpr int POSIX_EACCES = 13; -constexpr int POSIX_EFAULT = 14; -constexpr int POSIX_ENOTBLK = 15; -constexpr int POSIX_EBUSY = 16; -constexpr int POSIX_EEXIST = 17; -constexpr int POSIX_EXDEV = 18; -constexpr int POSIX_ENODEV = 19; -constexpr int POSIX_ENOTDIR = 20; -constexpr int POSIX_EISDIR = 21; -constexpr int POSIX_EINVAL = 22; -constexpr int POSIX_ENFILE = 23; -constexpr int POSIX_EMFILE = 24; -constexpr int POSIX_ENOTTY = 25; -constexpr int POSIX_ETXTBSY = 26; -constexpr int POSIX_EFBIG = 27; -constexpr int POSIX_ENOSPC = 28; -constexpr int POSIX_ESPIPE = 29; -constexpr int POSIX_EROFS = 30; -constexpr int POSIX_EMLINK = 31; -constexpr int POSIX_EPIPE = 32; -constexpr int POSIX_EDOM = 33; -constexpr int POSIX_ERANGE = 34; -constexpr int POSIX_EAGAIN = 35; -constexpr int POSIX_EWOULDBLOCK = 35; -constexpr int POSIX_EINPROGRESS = 36; -constexpr int POSIX_EALREADY = 37; -constexpr int POSIX_ENOTSOCK = 38; -constexpr int POSIX_EDESTADDRREQ = 39; -constexpr int POSIX_EMSGSIZE = 40; -constexpr int POSIX_EPROTOTYPE = 41; -constexpr int POSIX_ENOPROTOOPT = 42; -constexpr int POSIX_EPROTONOSUPPORT = 43; -constexpr int POSIX_ESOCKTNOSUPPORT = 44; -constexpr int POSIX_EOPNOTSUPP = 45; -constexpr int POSIX_ENOTSUP = 45; -constexpr int POSIX_EPFNOSUPPORT = 46; -constexpr int POSIX_EAFNOSUPPORT = 47; -constexpr int POSIX_EADDRINUSE = 48; -constexpr int POSIX_EADDRNOTAVAIL = 49; -constexpr int POSIX_ENETDOWN = 50; -constexpr int POSIX_ENETUNREACH = 51; -constexpr int POSIX_ENETRESET = 52; -constexpr int POSIX_ECONNABORTED = 53; -constexpr int POSIX_ECONNRESET = 54; -constexpr int POSIX_ENOBUFS = 55; -constexpr int POSIX_EISCONN = 56; -constexpr int POSIX_ENOTCONN = 57; -constexpr int POSIX_ESHUTDOWN = 58; -constexpr int POSIX_ETOOMANYREFS = 59; -constexpr int POSIX_ETIMEDOUT = 60; -constexpr int POSIX_ECONNREFUSED = 61; -constexpr int POSIX_ELOOP = 62; -constexpr int POSIX_ENAMETOOLONG = 63; -constexpr int POSIX_EHOSTDOWN = 64; -constexpr int POSIX_EHOSTUNREACH = 65; -constexpr int POSIX_ENOTEMPTY = 66; -constexpr int POSIX_EPROCLIM = 67; -constexpr int POSIX_EUSERS = 68; -constexpr int POSIX_EDQUOT = 69; -constexpr int POSIX_ESTALE = 70; -constexpr int POSIX_EREMOTE = 71; -constexpr int POSIX_EBADRPC = 72; -constexpr int POSIX_ERPCMISMATCH = 73; -constexpr int POSIX_EPROGUNAVAIL = 74; -constexpr int POSIX_EPROGMISMATCH = 75; -constexpr int POSIX_EPROCUNAVAIL = 76; -constexpr int POSIX_ENOLCK = 77; -constexpr int POSIX_ENOSYS = 78; -constexpr int POSIX_EFTYPE = 79; -constexpr int POSIX_EAUTH = 80; -constexpr int POSIX_ENEEDAUTH = 81; -constexpr int POSIX_EIDRM = 82; -constexpr int POSIX_ENOMSG = 83; -constexpr int POSIX_EOVERFLOW = 84; -constexpr int POSIX_ECANCELED = 85; -constexpr int POSIX_EILSEQ = 86; -constexpr int POSIX_ENOATTR = 87; -constexpr int POSIX_EDOOFUS = 88; -constexpr int POSIX_EBADMSG = 89; -constexpr int POSIX_EMULTIHOP = 90; -constexpr int POSIX_ENOLINK = 91; -constexpr int POSIX_EPROTO = 92; -constexpr int POSIX_ENOTCAPABLE = 93; -constexpr int POSIX_ECAPMODE = 94; -constexpr int POSIX_ENOBLK = 95; -constexpr int POSIX_EICV = 96; -constexpr int POSIX_ENOPLAYGOENT = 97; -constexpr int POSIX_EREVOKE = 98; -constexpr int POSIX_ESDKVERSION = 99; -constexpr int POSIX_ESTART = 100; -constexpr int POSIX_ESTOP = 101; -constexpr int POSIX_EINVALID2MB = 102; -constexpr int POSIX_ELAST = 102; -constexpr int POSIX_EADHOC = 160; -constexpr int POSIX_EINACTIVEDISABLED = 163; -constexpr int POSIX_ENETNODATA = 164; -constexpr int POSIX_ENETDESC = 165; -constexpr int POSIX_ENETDESCTIMEDOUT = 166; -constexpr int POSIX_ENETINTR = 167; -constexpr int POSIX_ERETURN = 205; -constexpr int POSIX_EFPOS = 152; -constexpr int POSIX_ENODATA = 1040; -constexpr int POSIX_ENOSR = 1050; -constexpr int POSIX_ENOSTR = 1051; -constexpr int POSIX_ENOTRECOVERABLE = 1056; -constexpr int POSIX_EOTHER = 1062; -constexpr int POSIX_EOWNERDEAD = 1064; -constexpr int POSIX_ETIME = 1074; - -constexpr int SCE_OK = 0; - -// kernel error codes -constexpr int SCE_KERNEL_ERROR_UNKNOWN = 0x80020000; -constexpr int SCE_KERNEL_ERROR_EPERM = 0x80020001; -constexpr int SCE_KERNEL_ERROR_ENOENT = 0x80020002; -constexpr int SCE_KERNEL_ERROR_ESRCH = 0x80020003; -constexpr int SCE_KERNEL_ERROR_EINTR = 0x80020004; -constexpr int SCE_KERNEL_ERROR_EIO = 0x80020005; -constexpr int SCE_KERNEL_ERROR_ENXIO = 0x80020006; -constexpr int SCE_KERNEL_ERROR_E2BIG = 0x80020007; -constexpr int SCE_KERNEL_ERROR_ENOEXEC = 0x80020008; -constexpr int SCE_KERNEL_ERROR_EBADF = 0x80020009; -constexpr int SCE_KERNEL_ERROR_ECHILD = 0x8002000A; -constexpr int SCE_KERNEL_ERROR_EDEADLK = 0x8002000B; -constexpr int SCE_KERNEL_ERROR_ENOMEM = 0x8002000C; -constexpr int SCE_KERNEL_ERROR_EACCES = 0x8002000D; -constexpr int SCE_KERNEL_ERROR_EFAULT = 0x8002000E; -constexpr int SCE_KERNEL_ERROR_ENOTBLK = 0x8002000F; -constexpr int SCE_KERNEL_ERROR_EBUSY = 0x80020010; -constexpr int SCE_KERNEL_ERROR_EEXIST = 0x80020011; -constexpr int SCE_KERNEL_ERROR_EXDEV = 0x80020012; -constexpr int SCE_KERNEL_ERROR_ENODEV = 0x80020013; -constexpr int SCE_KERNEL_ERROR_ENOTDIR = 0x80020014; -constexpr int SCE_KERNEL_ERROR_EISDIR = 0x80020015; -constexpr int SCE_KERNEL_ERROR_EINVAL = 0x80020016; -constexpr int SCE_KERNEL_ERROR_ENFILE = 0x80020017; -constexpr int SCE_KERNEL_ERROR_EMFILE = 0x80020018; -constexpr int SCE_KERNEL_ERROR_ENOTTY = 0x80020019; -constexpr int SCE_KERNEL_ERROR_ETXTBSY = 0x8002001A; -constexpr int SCE_KERNEL_ERROR_EFBIG = 0x8002001B; -constexpr int SCE_KERNEL_ERROR_ENOSPC = 0x8002001C; -constexpr int SCE_KERNEL_ERROR_ESPIPE = 0x8002001D; -constexpr int SCE_KERNEL_ERROR_EROFS = 0x8002001E; -constexpr int SCE_KERNEL_ERROR_EMLINK = 0x8002001F; -constexpr int SCE_KERNEL_ERROR_EPIPE = 0x80020020; -constexpr int SCE_KERNEL_ERROR_EDOM = 0x80020021; -constexpr int SCE_KERNEL_ERROR_ERANGE = 0x80020022; -constexpr int SCE_KERNEL_ERROR_EAGAIN = 0x80020023; -constexpr int SCE_KERNEL_ERROR_EWOULDBLOCK = 0x80020023; -constexpr int SCE_KERNEL_ERROR_EINPROGRESS = 0x80020024; -constexpr int SCE_KERNEL_ERROR_EALREADY = 0x80020025; -constexpr int SCE_KERNEL_ERROR_ENOTSOCK = 0x80020026; -constexpr int SCE_KERNEL_ERROR_EDESTADDRREQ = 0x80020027; -constexpr int SCE_KERNEL_ERROR_EMSGSIZE = 0x80020028; -constexpr int SCE_KERNEL_ERROR_EPROTOTYPE = 0x80020029; -constexpr int SCE_KERNEL_ERROR_ENOPROTOOPT = 0x8002002A; -constexpr int SCE_KERNEL_ERROR_EPROTONOSUPPORT = 0x8002002B; -constexpr int SCE_KERNEL_ERROR_ESOCKTNOSUPPORT = 0x8002002C; -constexpr int SCE_KERNEL_ERROR_EOPNOTSUPP = 0x8002002D; -constexpr int SCE_KERNEL_ERROR_ENOTSUP = 0x8002002D; -constexpr int SCE_KERNEL_ERROR_EPFNOSUPPORT = 0x8002002E; -constexpr int SCE_KERNEL_ERROR_EAFNOSUPPORT = 0x8002002F; -constexpr int SCE_KERNEL_ERROR_EADDRINUSE = 0x80020030; -constexpr int SCE_KERNEL_ERROR_EADDRNOTAVAIL = 0x80020031; -constexpr int SCE_KERNEL_ERROR_ENETDOWN = 0x80020032; -constexpr int SCE_KERNEL_ERROR_ENETUNREACH = 0x80020033; -constexpr int SCE_KERNEL_ERROR_ENETRESET = 0x80020034; -constexpr int SCE_KERNEL_ERROR_ECONNABORTED = 0x80020035; -constexpr int SCE_KERNEL_ERROR_ECONNRESET = 0x80020036; -constexpr int SCE_KERNEL_ERROR_ENOBUFS = 0x80020037; -constexpr int SCE_KERNEL_ERROR_EISCONN = 0x80020038; -constexpr int SCE_KERNEL_ERROR_ENOTCONN = 0x80020039; -constexpr int SCE_KERNEL_ERROR_ESHUTDOWN = 0x8002003A; -constexpr int SCE_KERNEL_ERROR_ETOOMANYREFS = 0x8002003B; -constexpr int SCE_KERNEL_ERROR_ETIMEDOUT = 0x8002003C; -constexpr int SCE_KERNEL_ERROR_ECONNREFUSED = 0x8002003D; -constexpr int SCE_KERNEL_ERROR_ELOOP = 0x8002003E; -constexpr int SCE_KERNEL_ERROR_ENAMETOOLONG = 0x8002003F; -constexpr int SCE_KERNEL_ERROR_EHOSTDOWN = 0x80020040; -constexpr int SCE_KERNEL_ERROR_EHOSTUNREACH = 0x80020041; -constexpr int SCE_KERNEL_ERROR_ENOTEMPTY = 0x80020042; -constexpr int SCE_KERNEL_ERROR_EPROCLIM = 0x80020043; -constexpr int SCE_KERNEL_ERROR_EUSERS = 0x80020044; -constexpr int SCE_KERNEL_ERROR_EDQUOT = 0x80020045; -constexpr int SCE_KERNEL_ERROR_ESTALE = 0x80020046; -constexpr int SCE_KERNEL_ERROR_EREMOTE = 0x80020047; -constexpr int SCE_KERNEL_ERROR_EBADRPC = 0x80020048; -constexpr int SCE_KERNEL_ERROR_ERPCMISMATCH = 0x80020049; -constexpr int SCE_KERNEL_ERROR_EPROGUNAVAIL = 0x8002004A; -constexpr int SCE_KERNEL_ERROR_EPROGMISMATCH = 0x8002004B; -constexpr int SCE_KERNEL_ERROR_EPROCUNAVAIL = 0x8002004C; -constexpr int SCE_KERNEL_ERROR_ENOLCK = 0x8002004D; -constexpr int SCE_KERNEL_ERROR_ENOSYS = 0x8002004E; -constexpr int SCE_KERNEL_ERROR_EFTYPE = 0x8002004F; -constexpr int SCE_KERNEL_ERROR_EAUTH = 0x80020050; -constexpr int SCE_KERNEL_ERROR_ENEEDAUTH = 0x80020051; -constexpr int SCE_KERNEL_ERROR_EIDRM = 0x80020052; -constexpr int SCE_KERNEL_ERROR_ENOMSG = 0x80020053; -constexpr int SCE_KERNEL_ERROR_EOVERFLOW = 0x80020054; -constexpr int SCE_KERNEL_ERROR_ECANCELED = 0x80020055; -constexpr int SCE_KERNEL_ERROR_EILSEQ = 0x80020056; -constexpr int SCE_KERNEL_ERROR_ENOATTR = 0x80020057; -constexpr int SCE_KERNEL_ERROR_EDOOFUS = 0x80020058; -constexpr int SCE_KERNEL_ERROR_EBADMSG = 0x80020059; -constexpr int SCE_KERNEL_ERROR_EMULTIHOP = 0x8002005A; -constexpr int SCE_KERNEL_ERROR_ENOLINK = 0x8002005B; -constexpr int SCE_KERNEL_ERROR_EPROTO = 0x8002005C; -constexpr int SCE_KERNEL_ERROR_ENOTCAPABLE = 0x8002005D; -constexpr int SCE_KERNEL_ERROR_ECAPMODE = 0x8002005E; -constexpr int SCE_KERNEL_ERROR_ENOBLK = 0x8002005F; -constexpr int SCE_KERNEL_ERROR_EICV = 0x80020060; -constexpr int SCE_KERNEL_ERROR_ENOPLAYGOENT = 0x80020061; -constexpr int SCE_KERNEL_ERROR_EREVOKE = 0x80020062; -constexpr int SCE_KERNEL_ERROR_ESDKVERSION = 0x80020063; -constexpr int SCE_KERNEL_ERROR_ESTART = 0x80020064; -constexpr int SCE_KERNEL_ERROR_ESTOP = 0x80020065; - -// videoOut -constexpr int SCE_VIDEO_OUT_ERROR_INVALID_VALUE = 0x80290001; // invalid argument -constexpr int SCE_VIDEO_OUT_ERROR_INVALID_ADDRESS = 0x80290002; // invalid addresses -constexpr int SCE_VIDEO_OUT_ERROR_INVALID_TILING_MODE = 0x80290007; // invalid tiling mode -constexpr int SCE_VIDEO_OUT_ERROR_INVALID_ASPECT_RATIO = 0x80290008; // invalid aspect ration -constexpr int SCE_VIDEO_OUT_ERROR_RESOURCE_BUSY = 0x80290009; // already opened -constexpr int SCE_VIDEO_OUT_ERROR_INVALID_INDEX = 0x8029000A; // invalid buffer index -constexpr int SCE_VIDEO_OUT_ERROR_INVALID_HANDLE = 0x8029000B; // invalid handle -constexpr int SCE_VIDEO_OUT_ERROR_INVALID_EVENT_QUEUE = 0x8029000C; // Invalid event queue -constexpr int SCE_VIDEO_OUT_ERROR_SLOT_OCCUPIED = 0x80290010; // slot already used -constexpr int SCE_VIDEO_OUT_ERROR_FLIP_QUEUE_FULL = 0x80290012; // flip queue is full -constexpr int SCE_VIDEO_OUT_ERROR_INVALID_OPTION = 0x8029001A; // Invalid buffer attribute option - // Generic constexpr int ORBIS_OK = 0x00000000; constexpr int ORBIS_FAIL = 0xFFFFFFFF; - -// Libkernel library -constexpr int ORBIS_KERNEL_ERROR_UNKNOWN = 0x80020000; -constexpr int ORBIS_KERNEL_ERROR_EPERM = 0x80020001; -constexpr int ORBIS_KERNEL_ERROR_ENOENT = 0x80020002; -constexpr int ORBIS_KERNEL_ERROR_ESRCH = 0x80020003; -constexpr int ORBIS_KERNEL_ERROR_EINTR = 0x80020004; -constexpr int ORBIS_KERNEL_ERROR_EIO = 0x80020005; -constexpr int ORBIS_KERNEL_ERROR_ENXIO = 0x80020006; -constexpr int ORBIS_KERNEL_ERROR_E2BIG = 0x80020007; -constexpr int ORBIS_KERNEL_ERROR_ENOEXEC = 0x80020008; -constexpr int ORBIS_KERNEL_ERROR_EBADF = 0x80020009; -constexpr int ORBIS_KERNEL_ERROR_ECHILD = 0x8002000A; -constexpr int ORBIS_KERNEL_ERROR_EDEADLK = 0x8002000B; -constexpr int ORBIS_KERNEL_ERROR_ENOMEM = 0x8002000C; -constexpr int ORBIS_KERNEL_ERROR_EACCES = 0x8002000D; -constexpr int ORBIS_KERNEL_ERROR_EFAULT = 0x8002000E; -constexpr int ORBIS_KERNEL_ERROR_ENOTBLK = 0x8002000F; -constexpr int ORBIS_KERNEL_ERROR_EBUSY = 0x80020010; -constexpr int ORBIS_KERNEL_ERROR_EEXIST = 0x80020011; -constexpr int ORBIS_KERNEL_ERROR_EXDEV = 0x80020012; -constexpr int ORBIS_KERNEL_ERROR_ENODEV = 0x80020013; -constexpr int ORBIS_KERNEL_ERROR_ENOTDIR = 0x80020014; -constexpr int ORBIS_KERNEL_ERROR_EISDIR = 0x80020015; -constexpr int ORBIS_KERNEL_ERROR_EINVAL = 0x80020016; -constexpr int ORBIS_KERNEL_ERROR_ENFILE = 0x80020017; -constexpr int ORBIS_KERNEL_ERROR_EMFILE = 0x80020018; -constexpr int ORBIS_KERNEL_ERROR_ENOTTY = 0x80020019; -constexpr int ORBIS_KERNEL_ERROR_ETXTBSY = 0x8002001A; -constexpr int ORBIS_KERNEL_ERROR_EFBIG = 0x8002001B; -constexpr int ORBIS_KERNEL_ERROR_ENOSPC = 0x8002001C; -constexpr int ORBIS_KERNEL_ERROR_ESPIPE = 0x8002001D; -constexpr int ORBIS_KERNEL_ERROR_EROFS = 0x8002001E; -constexpr int ORBIS_KERNEL_ERROR_EMLINK = 0x8002001F; -constexpr int ORBIS_KERNEL_ERROR_EPIPE = 0x80020020; -constexpr int ORBIS_KERNEL_ERROR_EDOM = 0x80020021; -constexpr int ORBIS_KERNEL_ERROR_ERANGE = 0x80020022; -constexpr int ORBIS_KERNEL_ERROR_EAGAIN = 0x80020023; -constexpr int ORBIS_KERNEL_ERROR_EWOULDBLOCK = 0x80020023; -constexpr int ORBIS_KERNEL_ERROR_EINPROGRESS = 0x80020024; -constexpr int ORBIS_KERNEL_ERROR_EALREADY = 0x80020025; -constexpr int ORBIS_KERNEL_ERROR_ENOTSOCK = 0x80020026; -constexpr int ORBIS_KERNEL_ERROR_EDESTADDRREQ = 0x80020027; -constexpr int ORBIS_KERNEL_ERROR_EMSGSIZE = 0x80020028; -constexpr int ORBIS_KERNEL_ERROR_EPROTOTYPE = 0x80020029; -constexpr int ORBIS_KERNEL_ERROR_ENOPROTOOPT = 0x8002002A; -constexpr int ORBIS_KERNEL_ERROR_EPROTONOSUPPORT = 0x8002002B; -constexpr int ORBIS_KERNEL_ERROR_ESOCKTNOSUPPORT = 0x8002002C; -constexpr int ORBIS_KERNEL_ERROR_ENOTSUP = 0x8002002D; -constexpr int ORBIS_KERNEL_ERROR_EOPNOTSUPP = 0x8002002D; -constexpr int ORBIS_KERNEL_ERROR_EPFNOSUPPORT = 0x8002002E; -constexpr int ORBIS_KERNEL_ERROR_EAFNOSUPPORT = 0x8002002F; -constexpr int ORBIS_KERNEL_ERROR_EADDRINUSE = 0x80020030; -constexpr int ORBIS_KERNEL_ERROR_EADDRNOTAVAIL = 0x80020031; -constexpr int ORBIS_KERNEL_ERROR_ENETDOWN = 0x80020032; -constexpr int ORBIS_KERNEL_ERROR_ENETUNREACH = 0x80020033; -constexpr int ORBIS_KERNEL_ERROR_ENETRESET = 0x80020034; -constexpr int ORBIS_KERNEL_ERROR_ECONNABORTED = 0x80020035; -constexpr int ORBIS_KERNEL_ERROR_ECONNRESET = 0x80020036; -constexpr int ORBIS_KERNEL_ERROR_ENOBUFS = 0x80020037; -constexpr int ORBIS_KERNEL_ERROR_EISCONN = 0x80020038; -constexpr int ORBIS_KERNEL_ERROR_ENOTCONN = 0x80020039; -constexpr int ORBIS_KERNEL_ERROR_ESHUTDOWN = 0x8002003A; -constexpr int ORBIS_KERNEL_ERROR_ETOOMANYREFS = 0x8002003B; -constexpr int ORBIS_KERNEL_ERROR_ETIMEDOUT = 0x8002003C; -constexpr int ORBIS_KERNEL_ERROR_ECONNREFUSED = 0x8002003D; -constexpr int ORBIS_KERNEL_ERROR_ELOOP = 0x8002003E; -constexpr int ORBIS_KERNEL_ERROR_ENAMETOOLONG = 0x8002003F; -constexpr int ORBIS_KERNEL_ERROR_EHOSTDOWN = 0x80020040; -constexpr int ORBIS_KERNEL_ERROR_EHOSTUNREACH = 0x80020041; -constexpr int ORBIS_KERNEL_ERROR_ENOTEMPTY = 0x80020042; -constexpr int ORBIS_KERNEL_ERROR_EPROCLIM = 0x80020043; -constexpr int ORBIS_KERNEL_ERROR_EUSERS = 0x80020044; -constexpr int ORBIS_KERNEL_ERROR_EDQUOT = 0x80020045; -constexpr int ORBIS_KERNEL_ERROR_ESTALE = 0x80020046; -constexpr int ORBIS_KERNEL_ERROR_EREMOTE = 0x80020047; -constexpr int ORBIS_KERNEL_ERROR_EBADRPC = 0x80020048; -constexpr int ORBIS_KERNEL_ERROR_ERPCMISMATCH = 0x80020049; -constexpr int ORBIS_KERNEL_ERROR_EPROGUNAVAIL = 0x8002004A; -constexpr int ORBIS_KERNEL_ERROR_EPROGMISMATCH = 0x8002004B; -constexpr int ORBIS_KERNEL_ERROR_EPROCUNAVAIL = 0x8002004C; -constexpr int ORBIS_KERNEL_ERROR_ENOLCK = 0x8002004D; -constexpr int ORBIS_KERNEL_ERROR_ENOSYS = 0x8002004E; -constexpr int ORBIS_KERNEL_ERROR_EFTYPE = 0x8002004F; -constexpr int ORBIS_KERNEL_ERROR_EAUTH = 0x80020050; -constexpr int ORBIS_KERNEL_ERROR_ENEEDAUTH = 0x80020051; -constexpr int ORBIS_KERNEL_ERROR_EIDRM = 0x80020052; -constexpr int ORBIS_KERNEL_ERROR_ENOMSG = 0x80020053; -constexpr int ORBIS_KERNEL_ERROR_EOVERFLOW = 0x80020054; -constexpr int ORBIS_KERNEL_ERROR_ECANCELED = 0x80020055; -constexpr int ORBIS_KERNEL_ERROR_EILSEQ = 0x80020056; -constexpr int ORBIS_KERNEL_ERROR_ENOATTR = 0x80020057; -constexpr int ORBIS_KERNEL_ERROR_EDOOFUS = 0x80020058; -constexpr int ORBIS_KERNEL_ERROR_EBADMSG = 0x80020059; -constexpr int ORBIS_KERNEL_ERROR_EMULTIHOP = 0x8002005A; -constexpr int ORBIS_KERNEL_ERROR_ENOLINK = 0x8002005B; -constexpr int ORBIS_KERNEL_ERROR_EPROTO = 0x8002005C; -constexpr int ORBIS_KERNEL_ERROR_ENOTCAPABLE = 0x8002005D; -constexpr int ORBIS_KERNEL_ERROR_ECAPMODE = 0x8002005E; -constexpr int ORBIS_KERNEL_ERROR_ENOBLK = 0x8002005F; -constexpr int ORBIS_KERNEL_ERROR_EICV = 0x80020060; -constexpr int ORBIS_KERNEL_ERROR_ENOPLAYGOENT = 0x80020061; - -// AudioOut library -constexpr int ORBIS_AUDIO_OUT_ERROR_NOT_OPENED = 0x80260001; -constexpr int ORBIS_AUDIO_OUT_ERROR_BUSY = 0x80260002; -constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_PORT = 0x80260003; -constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_POINTER = 0x80260004; -constexpr int ORBIS_AUDIO_OUT_ERROR_PORT_FULL = 0x80260005; -constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_SIZE = 0x80260006; -constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_FORMAT = 0x80260007; -constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_SAMPLE_FREQ = 0x80260008; -constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_VOLUME = 0x80260009; -constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_PORT_TYPE = 0x8026000A; -constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_CONF_TYPE = 0x8026000C; -constexpr int ORBIS_AUDIO_OUT_ERROR_OUT_OF_MEMORY = 0x8026000D; -constexpr int ORBIS_AUDIO_OUT_ERROR_ALREADY_INIT = 0x8026000E; -constexpr int ORBIS_AUDIO_OUT_ERROR_NOT_INIT = 0x8026000F; -constexpr int ORBIS_AUDIO_OUT_ERROR_MEMORY = 0x80260010; -constexpr int ORBIS_AUDIO_OUT_ERROR_SYSTEM_RESOURCE = 0x80260011; -constexpr int ORBIS_AUDIO_OUT_ERROR_TRANS_EVENT = 0x80260012; -constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_FLAG = 0x80260013; -constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_MIXLEVEL = 0x80260014; -constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_ARG = 0x80260015; -constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_PARAM = 0x80260016; -constexpr int ORBIS_AUDIO_OUT_ERROR_MASTERING_FATAL = 0x80260200; -constexpr int ORBIS_AUDIO_OUT_ERROR_MASTERING_INVALID_API_PARAM = 0x80260201; -constexpr int ORBIS_AUDIO_OUT_ERROR_MASTERING_INVALID_CONFIG = 0x80260202; -constexpr int ORBIS_AUDIO_OUT_ERROR_MASTERING_NOT_INITIALIZED = 0x80260203; -constexpr int ORBIS_AUDIO_OUT_ERROR_MASTERING_INVALID_STATES_ID = 0x80260204; - -// VideoOut library -constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_VALUE = 0x80290001; -constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_ADDRESS = 0x80290002; -constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_PIXEL_FORMAT = 0x80290003; -constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_PITCH = 0x80290004; -constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_RESOLUTION = 0x80290005; -constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_FLIP_MODE = 0x80290006; -constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_TILING_MODE = 0x80290007; -constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_ASPECT_RATIO = 0x80290008; -constexpr int ORBIS_VIDEO_OUT_ERROR_RESOURCE_BUSY = 0x80290009; -constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_INDEX = 0x8029000A; -constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_HANDLE = 0x8029000B; -constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_EVENT_QUEUE = 0x8029000C; -constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_EVENT = 0x8029000D; -constexpr int ORBIS_VIDEO_OUT_ERROR_NO_EMPTY_SLOT = 0x8029000F; -constexpr int ORBIS_VIDEO_OUT_ERROR_SLOT_OCCUPIED = 0x80290010; -constexpr int ORBIS_VIDEO_OUT_ERROR_FLIP_QUEUE_FULL = 0x80290012; -constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_MEMORY = 0x80290013; -constexpr int ORBIS_VIDEO_OUT_ERROR_MEMORY_NOT_PHYSICALLY_CONTIGUOUS = 0x80290014; -constexpr int ORBIS_VIDEO_OUT_ERROR_MEMORY_INVALID_ALIGNMENT = 0x80290015; -constexpr int ORBIS_VIDEO_OUT_ERROR_UNSUPPORTED_OUTPUT_MODE = 0x80290016; -constexpr int ORBIS_VIDEO_OUT_ERROR_OVERFLOW = 0x80290017; -constexpr int ORBIS_VIDEO_OUT_ERROR_NO_DEVICE = 0x80290018; -constexpr int ORBIS_VIDEO_OUT_ERROR_UNAVAILABLE_OUTPUT_MODE = 0x80290019; -constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_OPTION = 0x8029001A; -constexpr int ORBIS_VIDEO_OUT_ERROR_UNKNOWN = 0x802900FE; -constexpr int ORBIS_VIDEO_OUT_ERROR_FATAL = 0x802900FF; -constexpr int ORBIS_VIDEO_OUT_ERROR_ENOMEM = 0x8029100C; - -// Pad library -constexpr int ORBIS_PAD_ERROR_INVALID_ARG = 0x80920001; -constexpr int ORBIS_PAD_ERROR_INVALID_PORT = 0x80920002; -constexpr int ORBIS_PAD_ERROR_INVALID_HANDLE = 0x80920003; -constexpr int ORBIS_PAD_ERROR_ALREADY_OPENED = 0x80920004; -constexpr int ORBIS_PAD_ERROR_NOT_INITIALIZED = 0x80920005; -constexpr int ORBIS_PAD_ERROR_INVALID_LIGHTBAR_SETTING = 0x80920006; -constexpr int ORBIS_PAD_ERROR_DEVICE_NOT_CONNECTED = 0x80920007; -constexpr int ORBIS_PAD_ERROR_DEVICE_NO_HANDLE = 0x80920008; -constexpr int ORBIS_PAD_ERROR_FATAL = 0x809200FF; -constexpr int ORBIS_PAD_ERROR_NOT_PERMITTED = 0x80920101; -constexpr int ORBIS_PAD_ERROR_INVALID_BUFFER_LENGTH = 0x80920102; -constexpr int ORBIS_PAD_ERROR_INVALID_REPORT_LENGTH = 0x80920103; -constexpr int ORBIS_PAD_ERROR_INVALID_REPORT_ID = 0x80920104; -constexpr int ORBIS_PAD_ERROR_SEND_AGAIN = 0x80920105; - -// UserService library -constexpr int ORBIS_USER_SERVICE_ERROR_INTERNAL = 0x80960001; -constexpr int ORBIS_USER_SERVICE_ERROR_NOT_INITIALIZED = 0x80960002; -constexpr int ORBIS_USER_SERVICE_ERROR_ALREADY_INITIALIZED = 0x80960003; -constexpr int ORBIS_USER_SERVICE_ERROR_NO_MEMORY = 0x80960004; -constexpr int ORBIS_USER_SERVICE_ERROR_INVALID_ARGUMENT = 0x80960005; -constexpr int ORBIS_USER_SERVICE_ERROR_OPERATION_NOT_SUPPORTED = 0x80960006; -constexpr int ORBIS_USER_SERVICE_ERROR_NO_EVENT = 0x80960007; -constexpr int ORBIS_USER_SERVICE_ERROR_NOT_LOGGED_IN = 0x80960009; -constexpr int ORBIS_USER_SERVICE_ERROR_BUFFER_TOO_SHORT = 0x8096000A; - -// SystemService library -constexpr int ORBIS_SYSTEM_SERVICE_ERROR_PARAMETER = 0x80A10003; -constexpr int ORBIS_SYSTEM_SERVICE_ERROR_NO_EVENT = 0x80A10004; - -// NpTrophy library -constexpr int ORBIS_NP_TROPHY_ERROR_UNKNOWN = 0x80551600; -constexpr int ORBIS_NP_TROPHY_ERROR_NOT_INITIALIZED = 0x80551601; -constexpr int ORBIS_NP_TROPHY_ERROR_ALREADY_INITIALIZED = 0x80551602; -constexpr int ORBIS_NP_TROPHY_ERROR_OUT_OF_MEMORY = 0x80551603; -constexpr int ORBIS_NP_TROPHY_ERROR_INVALID_ARGUMENT = 0x80551604; -constexpr int ORBIS_NP_TROPHY_ERROR_INSUFFICIENT_BUFFER = 0x80551605; -constexpr int ORBIS_NP_TROPHY_ERROR_EXCEEDS_MAX = 0x80551606; -constexpr int ORBIS_NP_TROPHY_ERROR_ABORT = 0x80551607; -constexpr int ORBIS_NP_TROPHY_ERROR_INVALID_HANDLE = 0x80551608; -constexpr int ORBIS_NP_TROPHY_ERROR_INVALID_CONTEXT = 0x80551609; -constexpr int ORBIS_NP_TROPHY_ERROR_INVALID_TROPHY_ID = 0x8055160A; -constexpr int ORBIS_NP_TROPHY_ERROR_INVALID_GROUP_ID = 0x8055160B; -constexpr int ORBIS_NP_TROPHY_ERROR_TROPHY_ALREADY_UNLOCKED = 0x8055160C; -constexpr int ORBIS_NP_TROPHY_ERROR_PLATINUM_CANNOT_UNLOCK = 0x8055160D; -constexpr int ORBIS_NP_TROPHY_ERROR_ACCOUNTID_NOT_MATCH = 0x8055160E; -constexpr int ORBIS_NP_TROPHY_ERROR_NOT_REGISTERED = 0x8055160F; -constexpr int ORBIS_NP_TROPHY_ERROR_ALREADY_REGISTERED = 0x80551610; -constexpr int ORBIS_NP_TROPHY_ERROR_BROKEN_DATA = 0x80551611; -constexpr int ORBIS_NP_TROPHY_ERROR_INSUFFICIENT_SPACE = 0x80551612; -constexpr int ORBIS_NP_TROPHY_ERROR_CONTEXT_ALREADY_EXISTS = 0x80551613; -constexpr int ORBIS_NP_TROPHY_ERROR_ICON_FILE_NOT_FOUND = 0x80551614; -constexpr int ORBIS_NP_TROPHY_ERROR_INVALID_TRP_FILE_FORMAT = 0x80551616; -constexpr int ORBIS_NP_TROPHY_ERROR_UNSUPPORTED_TRP_FILE = 0x80551617; -constexpr int ORBIS_NP_TROPHY_ERROR_INVALID_TROPHY_CONF_FORMAT = 0x80551618; -constexpr int ORBIS_NP_TROPHY_ERROR_UNSUPPORTED_TROPHY_CONF = 0x80551619; -constexpr int ORBIS_NP_TROPHY_ERROR_TROPHY_NOT_UNLOCKED = 0x8055161A; -constexpr int ORBIS_NP_TROPHY_ERROR_USER_NOT_FOUND = 0x8055161C; -constexpr int ORBIS_NP_TROPHY_ERROR_USER_NOT_LOGGED_IN = 0x8055161D; -constexpr int ORBIS_NP_TROPHY_ERROR_CONTEXT_USER_LOGOUT = 0x8055161E; -constexpr int ORBIS_NP_TROPHY_ERROR_USE_TRP_FOR_DEVELOPMENT = 0x8055161F; -constexpr int ORBIS_NP_TROPHY_ERROR_INVALID_NP_SERVICE_LABEL = 0x80551621; -constexpr int ORBIS_NP_TROPHY_ERROR_NOT_SUPPORTED = 0x80551622; -constexpr int ORBIS_NP_TROPHY_ERROR_CONTEXT_EXCEEDS_MAX = 0x80551623; -constexpr int ORBIS_NP_TROPHY_ERROR_HANDLE_EXCEEDS_MAX = 0x80551624; -constexpr int ORBIS_NP_TROPHY_ERROR_INVALID_USER_ID = 0x80551625; -constexpr int ORBIS_NP_TROPHY_ERROR_TITLE_CONF_NOT_INSTALLED = 0x80551626; -constexpr int ORBIS_NP_TROPHY_ERROR_BROKEN_TITLE_CONF = 0x80551627; -constexpr int ORBIS_NP_TROPHY_ERROR_INCONSISTENT_TITLE_CONF = 0x80551628; -constexpr int ORBIS_NP_TROPHY_ERROR_TITLE_BACKGROUND = 0x80551629; -constexpr int ORBIS_NP_TROPHY_ERROR_SCREENSHOT_DISABLED = 0x8055162B; -constexpr int ORBIS_NP_TROPHY_ERROR_SCREENSHOT_DISPLAY_BUFFER_NOT_IN_USE = 0x8055162D; - -// AvPlayer library -constexpr int ORBIS_AVPLAYER_ERROR_INVALID_PARAMS = 0x806A0001; -constexpr int ORBIS_AVPLAYER_ERROR_OPERATION_FAILED = 0x806A0002; -constexpr int ORBIS_AVPLAYER_ERROR_NO_MEMORY = 0x806A0003; -constexpr int ORBIS_AVPLAYER_ERROR_NOT_SUPPORTED = 0x806A0004; -constexpr int ORBIS_AVPLAYER_ERROR_WAR_FILE_NONINTERLEAVED = 0x806A00A0; -constexpr int ORBIS_AVPLAYER_ERROR_WAR_LOOPING_BACK = 0x806A00A1; -constexpr int ORBIS_AVPLAYER_ERROR_WAR_JUMP_COMPLETE = 0x806A00A3; -constexpr int ORBIS_AVPLAYER_ERROR_INFO_MARLIN_ENCRY = 0x806A00B0; -constexpr int ORBIS_AVPLAYER_ERROR_INFO_PLAYREADY_ENCRY = 0x806A00B4; -constexpr int ORBIS_AVPLAYER_ERROR_INFO_AES_ENCRY = 0x806A00B5; -constexpr int ORBIS_AVPLAYER_ERROR_INFO_OTHER_ENCRY = 0x806A00BF; - -// AppContent library -constexpr int ORBIS_APP_CONTENT_ERROR_PARAMETER = 0x80D90002; -constexpr int ORBIS_APP_CONTENT_ERROR_DRM_NO_ENTITLEMENT = 0x80D90007; -constexpr int ORBIS_APP_CONTENT_ERROR_NOT_FOUND = 0x80D90005; - -// Fiber library -constexpr int ORBIS_FIBER_ERROR_NULL = 0x80590001; -constexpr int ORBIS_FIBER_ERROR_ALIGNMENT = 0x80590002; -constexpr int ORBIS_FIBER_ERROR_RANGE = 0x80590003; -constexpr int ORBIS_FIBER_ERROR_INVALID = 0x80590004; -constexpr int ORBIS_FIBER_ERROR_PERMISSION = 0x80590005; -constexpr int ORBIS_FIBER_ERROR_STATE = 0x80590006; - -// ImeDialog library -constexpr int ORBIS_ERROR_DIALOG_ERROR_NOT_INITIALIZED = 0x80ED0001; -constexpr int ORBIS_ERROR_DIALOG_ERROR_ALREADY_INITIALIZED = 0x80ED0002; -constexpr int ORBIS_ERROR_DIALOG_ERROR_PARAM_INVALID = 0x80ED0003; -constexpr int ORBIS_ERROR_DIALOG_ERROR_UNEXPECTED_FATAL = 0x80ED0004; -constexpr int ORBIS_ERROR_DIALOG_ERROR_INVALID_STATE = 0x80ED0005; -constexpr int ORBIS_ERROR_DIALOG_ERROR_SERVICE_BUSY = 0x80ED0006; -constexpr int ORBIS_ERROR_DIALOG_ERROR_INVALID_USER_ID = 0x80ED0007; - -// Ime library -constexpr int ORBIS_IME_ERROR_BUSY = 0x80BC0001; -constexpr int ORBIS_IME_ERROR_NOT_OPENED = 0x80BC0002; -constexpr int ORBIS_IME_ERROR_NO_MEMORY = 0x80BC0003; -constexpr int ORBIS_IME_ERROR_CONNECTION_FAILED = 0x80BC0004; -constexpr int ORBIS_IME_ERROR_TOO_MANY_REQUESTS = 0x80BC0005; -constexpr int ORBIS_IME_ERROR_INVALID_TEXT = 0x80BC0006; -constexpr int ORBIS_IME_ERROR_EVENT_OVERFLOW = 0x80BC0007; -constexpr int ORBIS_IME_ERROR_NOT_ACTIVE = 0x80BC0008; -constexpr int ORBIS_IME_ERROR_IME_SUSPENDING = 0x80BC0009; -constexpr int ORBIS_IME_ERROR_DEVICE_IN_USE = 0x80BC000A; -constexpr int ORBIS_IME_ERROR_INVALID_USER_ID = 0x80BC0010; -constexpr int ORBIS_IME_ERROR_INVALID_TYPE = 0x80BC0011; -constexpr int ORBIS_IME_ERROR_INVALID_SUPPORTED_LANGUAGES = 0x80BC0012; -constexpr int ORBIS_IME_ERROR_INVALID_ENTER_LABEL = 0x80BC0013; -constexpr int ORBIS_IME_ERROR_INVALID_INPUT_METHOD = 0x80BC0014; -constexpr int ORBIS_IME_ERROR_INVALID_OPTION = 0x80BC0015; -constexpr int ORBIS_IME_ERROR_INVALID_MAX_TEXT_LENGTH = 0x80BC0016; -constexpr int ORBIS_IME_ERROR_INVALID_INPUT_TEXT_BUFFER = 0x80BC0017; -constexpr int ORBIS_IME_ERROR_INVALID_POSX = 0x80BC0018; -constexpr int ORBIS_IME_ERROR_INVALID_POSY = 0x80BC0019; -constexpr int ORBIS_IME_ERROR_INVALID_HORIZONTAL_ALIGNMENT = 0x80BC001A; -constexpr int ORBIS_IME_ERROR_INVALID_VERTICAL_ALIGNMENT = 0x80BC001B; -constexpr int ORBIS_IME_ERROR_INVALID_EXTENDED = 0x80BC001C; -constexpr int ORBIS_IME_ERROR_INVALID_KEYBOARD_TYPE = 0x80BC001D; -constexpr int ORBIS_IME_ERROR_INVALID_WORK = 0x80BC0020; -constexpr int ORBIS_IME_ERROR_INVALID_ARG = 0x80BC0021; -constexpr int ORBIS_IME_ERROR_INVALID_HANDLER = 0x80BC0022; -constexpr int ORBIS_IME_ERROR_NO_RESOURCE_ID = 0x80BC0023; -constexpr int ORBIS_IME_ERROR_INVALID_MODE = 0x80BC0024; -constexpr int ORBIS_IME_ERROR_INVALID_PARAM = 0x80BC0030; -constexpr int ORBIS_IME_ERROR_INVALID_ADDRESS = 0x80BC0031; -constexpr int ORBIS_IME_ERROR_INVALID_RESERVED = 0x80BC0032; -constexpr int ORBIS_IME_ERROR_INVALID_TIMING = 0x80BC0033; -constexpr int ORBIS_IME_ERROR_INTERNAL = 0x80BC00FF; - -// Videodec2 library -constexpr int ORBIS_VIDEODEC2_ERROR_API_FAIL = 0x811D0100; -constexpr int ORBIS_VIDEODEC2_ERROR_STRUCT_SIZE = 0x811D0101; -constexpr int ORBIS_VIDEODEC2_ERROR_ARGUMENT_POINTER = 0x811D0102; -constexpr int ORBIS_VIDEODEC2_ERROR_DECODER_INSTANCE = 0x811D0103; -constexpr int ORBIS_VIDEODEC2_ERROR_MEMORY_SIZE = 0x811D0104; -constexpr int ORBIS_VIDEODEC2_ERROR_MEMORY_POINTER = 0x811D0105; -constexpr int ORBIS_VIDEODEC2_ERROR_FRAME_BUFFER_SIZE = 0x811D0106; -constexpr int ORBIS_VIDEODEC2_ERROR_FRAME_BUFFER_POINTER = 0x811D0107; -constexpr int ORBIS_VIDEODEC2_ERROR_FRAME_BUFFER_ALIGNMENT = 0x811D0108; -constexpr int ORBIS_VIDEODEC2_ERROR_NOT_ONION_MEMORY = 0x811D0109; -constexpr int ORBIS_VIDEODEC2_ERROR_NOT_GARLIC_MEMORY = 0x811D010A; -constexpr int ORBIS_VIDEODEC2_ERROR_NOT_DIRECT_MEMORY = 0x811D010B; -constexpr int ORBIS_VIDEODEC2_ERROR_MEMORY_INFO = 0x811D010C; -constexpr int ORBIS_VIDEODEC2_ERROR_ACCESS_UNIT_SIZE = 0x811D010D; -constexpr int ORBIS_VIDEODEC2_ERROR_ACCESS_UNIT_POINTER = 0x811D010E; -constexpr int ORBIS_VIDEODEC2_ERROR_OUTPUT_INFO = 0x811D010F; -constexpr int ORBIS_VIDEODEC2_ERROR_COMPUTE_QUEUE = 0x811D0110; -constexpr int ORBIS_VIDEODEC2_ERROR_FATAL_STATE = 0x811D0111; -constexpr int ORBIS_VIDEODEC2_ERROR_PRESET_VALUE = 0x811D0112; -constexpr int ORBIS_VIDEODEC2_ERROR_CONFIG_INFO = 0x811D0200; -constexpr int ORBIS_VIDEODEC2_ERROR_COMPUTE_PIPE_ID = 0x811D0201; -constexpr int ORBIS_VIDEODEC2_ERROR_COMPUTE_QUEUE_ID = 0x811D0202; -constexpr int ORBIS_VIDEODEC2_ERROR_RESOURCE_TYPE = 0x811D0203; -constexpr int ORBIS_VIDEODEC2_ERROR_CODEC_TYPE = 0x811D0204; -constexpr int ORBIS_VIDEODEC2_ERROR_PROFILE_LEVEL = 0x811D0205; -constexpr int ORBIS_VIDEODEC2_ERROR_PIPELINE_DEPTH = 0x811D0206; -constexpr int ORBIS_VIDEODEC2_ERROR_AFFINITY_MASK = 0x811D0207; -constexpr int ORBIS_VIDEODEC2_ERROR_THREAD_PRIORITY = 0x811D0208; -constexpr int ORBIS_VIDEODEC2_ERROR_DPB_FRAME_COUNT = 0x811D0209; -constexpr int ORBIS_VIDEODEC2_ERROR_FRAME_WIDTH_HEIGHT = 0x811D020A; -constexpr int ORBIS_VIDEODEC2_ERROR_EXTRA_CONFIG_INFO = 0x811D020B; -constexpr int ORBIS_VIDEODEC2_ERROR_NEW_SEQUENCE = 0x811D0300; -constexpr int ORBIS_VIDEODEC2_ERROR_ACCESS_UNIT = 0x811D0301; -constexpr int ORBIS_VIDEODEC2_ERROR_OVERSIZE_DECODE = 0x811D0302; -constexpr int ORBIS_VIDEODEC2_ERROR_INVALID_SEQUENCE = 0x811D0303; -constexpr int ORBIS_VIDEODEC2_ERROR_FATAL_STREAM = 0x811D0304; - -// Videodec library -constexpr int ORBIS_VIDEODEC_ERROR_API_FAIL = 0x80C10000; -constexpr int ORBIS_VIDEODEC_ERROR_CODEC_TYPE = 0x80C10001; -constexpr int ORBIS_VIDEODEC_ERROR_STRUCT_SIZE = 0x80C10002; -constexpr int ORBIS_VIDEODEC_ERROR_HANDLE = 0x80C10003; -constexpr int ORBIS_VIDEODEC_ERROR_CPU_MEMORY_SIZE = 0x80C10004; -constexpr int ORBIS_VIDEODEC_ERROR_CPU_MEMORY_POINTER = 0x80C10005; -constexpr int ORBIS_VIDEODEC_ERROR_CPU_GPU_MEMORY_SIZE = 0x80C10006; -constexpr int ORBIS_VIDEODEC_ERROR_CPU_GPU_MEMORY_POINTER = 0x80C10007; -constexpr int ORBIS_VIDEODEC_ERROR_SHADER_CONTEXT_POINTER = 0x80C10008; -constexpr int ORBIS_VIDEODEC_ERROR_AU_SIZE = 0x80C10009; -constexpr int ORBIS_VIDEODEC_ERROR_AU_POINTER = 0x80C1000A; -constexpr int ORBIS_VIDEODEC_ERROR_FRAME_BUFFER_SIZE = 0x80C1000B; -constexpr int ORBIS_VIDEODEC_ERROR_FRAME_BUFFER_POINTER = 0x80C1000C; -constexpr int ORBIS_VIDEODEC_ERROR_FRAME_BUFFER_ALIGNMENT = 0x80C1000D; -constexpr int ORBIS_VIDEODEC_ERROR_CONFIG_INFO = 0x80C1000E; -constexpr int ORBIS_VIDEODEC_ERROR_ARGUMENT_POINTER = 0x80C1000F; -constexpr int ORBIS_VIDEODEC_ERROR_NEW_SEQUENCE = 0x80C10010; -constexpr int ORBIS_VIDEODEC_ERROR_DECODE_AU = 0x80C10011; -constexpr int ORBIS_VIDEODEC_ERROR_MISMATCH_SPEC = 0x80C10012; -constexpr int ORBIS_VIDEODEC_ERROR_INVALID_SEQUENCE = 0x80C10013; -constexpr int ORBIS_VIDEODEC_ERROR_FATAL_STREAM = 0x80C10014; -constexpr int ORBIS_VIDEODEC_ERROR_FATAL_STATE = 0x80C10015; - -// PngDec library -constexpr int ORBIS_PNG_DEC_ERROR_INVALID_ADDR = 0x80690001; -constexpr int ORBIS_PNG_DEC_ERROR_INVALID_SIZE = 0x80690002; -constexpr int ORBIS_PNG_DEC_ERROR_INVALID_PARAM = 0x80690003; -constexpr int ORBIS_PNG_DEC_ERROR_INVALID_HANDLE = 0x80690004; -constexpr int ORBIS_PNG_DEC_ERROR_INVALID_WORK_MEMORY = 0x80690005; -constexpr int ORBIS_PNG_DEC_ERROR_INVALID_DATA = 0x80690010; -constexpr int ORBIS_PNG_DEC_ERROR_UNSUPPORT_DATA = 0x80690011; -constexpr int ORBIS_PNG_DEC_ERROR_DECODE_ERROR = 0x80690012; -constexpr int ORBIS_PNG_DEC_ERROR_FATAL = 0x80690020; \ No newline at end of file diff --git a/src/core/libraries/fiber/fiber.cpp b/src/core/libraries/fiber/fiber.cpp index 92bf894b..c28d8d73 100644 --- a/src/core/libraries/fiber/fiber.cpp +++ b/src/core/libraries/fiber/fiber.cpp @@ -4,7 +4,7 @@ #include "fiber.h" #include "common/logging/log.h" -#include "core/libraries/error_codes.h" +#include "core/libraries/fiber/fiber_error.h" #include "core/libraries/libs.h" #include "core/tls.h" diff --git a/src/core/libraries/fiber/fiber.h b/src/core/libraries/fiber/fiber.h index 930409ca..00099f93 100644 --- a/src/core/libraries/fiber/fiber.h +++ b/src/core/libraries/fiber/fiber.h @@ -26,17 +26,12 @@ struct SceFiber { u64 signature; FiberState state; SceFiberEntry entry; - u64 argOnInitialize; - u64 argRun; u64* pArgRun; - u64 argReturn; u64* pArgReturn; - u64 sizeContext; - char name[ORBIS_FIBER_MAX_NAME_LENGTH]; void* handle; }; @@ -53,7 +48,7 @@ struct SceFiberInfo { }; static_assert(sizeof(SceFiberInfo) <= 128); -typedef void* SceFiberOptParam; +using SceFiberOptParam = void*; s32 PS4_SYSV_ABI sceFiberInitialize(SceFiber* fiber, const char* name, SceFiberEntry entry, u64 argOnInitialize, void* addrContext, u64 sizeContext, diff --git a/src/core/libraries/fiber/fiber_error.h b/src/core/libraries/fiber/fiber_error.h new file mode 100644 index 00000000..c89fe30b --- /dev/null +++ b/src/core/libraries/fiber/fiber_error.h @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/libraries/error_codes.h" + +// Fiber library +constexpr int ORBIS_FIBER_ERROR_NULL = 0x80590001; +constexpr int ORBIS_FIBER_ERROR_ALIGNMENT = 0x80590002; +constexpr int ORBIS_FIBER_ERROR_RANGE = 0x80590003; +constexpr int ORBIS_FIBER_ERROR_INVALID = 0x80590004; +constexpr int ORBIS_FIBER_ERROR_PERMISSION = 0x80590005; +constexpr int ORBIS_FIBER_ERROR_STATE = 0x80590006; diff --git a/src/core/libraries/gnmdriver/gnm_error.h b/src/core/libraries/gnmdriver/gnm_error.h index eab684a2..b8e57f6f 100644 --- a/src/core/libraries/gnmdriver/gnm_error.h +++ b/src/core/libraries/gnmdriver/gnm_error.h @@ -3,6 +3,8 @@ #pragma once +#include "core/libraries/error_codes.h" + constexpr int ORBIS_GNM_ERROR_SUBMISSION_FAILED_INVALID_ARGUMENT = 0x80D11000; constexpr int ORBIS_GNM_ERROR_SUBMISSION_NOT_ENOUGH_RESOURCES = 0x80D11001; constexpr int ORBIS_GNM_ERROR_SUBMISSION_AND_FLIP_FAILED_INVALID_COMMAND_BUFFER = 0x80D11080; diff --git a/src/core/libraries/gnmdriver/gnmdriver.cpp b/src/core/libraries/gnmdriver/gnmdriver.cpp index 70cf09a9..10d121af 100644 --- a/src/core/libraries/gnmdriver/gnmdriver.cpp +++ b/src/core/libraries/gnmdriver/gnmdriver.cpp @@ -11,7 +11,8 @@ #include "common/slot_vector.h" #include "core/address_space.h" #include "core/debug_state.h" -#include "core/libraries/error_codes.h" +#include "core/libraries/gnmdriver/gnm_error.h" +#include "core/libraries/kernel/orbis_error.h" #include "core/libraries/kernel/process.h" #include "core/libraries/libs.h" #include "core/libraries/videoout/video_out.h" diff --git a/src/core/libraries/ime/ime.cpp b/src/core/libraries/ime/ime.cpp index efb988c7..700585ff 100644 --- a/src/core/libraries/ime/ime.cpp +++ b/src/core/libraries/ime/ime.cpp @@ -2,14 +2,12 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include -#include "ime.h" -#include "ime_ui.h" - #include "common/logging/log.h" -#include "common/singleton.h" -#include "core/libraries/error_codes.h" +#include "core/libraries/ime/ime.h" +#include "core/libraries/ime/ime_error.h" +#include "core/libraries/ime/ime_ui.h" #include "core/libraries/libs.h" -#include "core/linker.h" +#include "core/tls.h" namespace Libraries::Ime { @@ -37,7 +35,7 @@ public: // Open an event to let the game know the IME has started OrbisImeEvent openEvent{}; - openEvent.id = (ime_mode ? OrbisImeEventId::OPEN : OrbisImeEventId::KEYBOARD_OPEN); + openEvent.id = (ime_mode ? OrbisImeEventId::Open : OrbisImeEventId::KeyboardOpen); if (ime_mode) { sceImeGetPanelSize(&m_param.ime, &openEvent.param.rect.width, @@ -45,8 +43,8 @@ public: openEvent.param.rect.x = m_param.ime.posx; openEvent.param.rect.y = m_param.ime.posy; } else { - openEvent.param.resourceIdArray.userId = 1; - openEvent.param.resourceIdArray.resourceId[0] = 1; + openEvent.param.resource_id_array.userId = 1; + openEvent.param.resource_id_array.resource_id[0] = 1; } Execute(nullptr, &openEvent, true); @@ -215,15 +213,15 @@ s32 PS4_SYSV_ABI sceImeGetPanelSize(const OrbisImeParam* param, u32* width, u32* } switch (param->type) { - case OrbisImeType::DEFAULT: - case OrbisImeType::BASIC_LATIN: - case OrbisImeType::URL: - case OrbisImeType::MAIL: + case OrbisImeType::Default: + case OrbisImeType::BasicLatin: + case OrbisImeType::Url: + case OrbisImeType::Mail: // We set our custom sizes, commented sizes are the original ones *width = 500; // 793 *height = 100; // 408 break; - case OrbisImeType::NUMBER: + case OrbisImeType::Number: *width = 370; *height = 402; break; @@ -315,7 +313,7 @@ void PS4_SYSV_ABI sceImeParamInit(OrbisImeParam* param) { } memset(param, 0, sizeof(OrbisImeParam)); - param->userId = -1; + param->user_id = -1; } int PS4_SYSV_ABI sceImeSetCandidateIndex() { diff --git a/src/core/libraries/ime/ime.h b/src/core/libraries/ime/ime.h index fc98d426..2915b70d 100644 --- a/src/core/libraries/ime/ime.h +++ b/src/core/libraries/ime/ime.h @@ -3,9 +3,9 @@ #pragma once +#include "common/enum.h" #include "common/types.h" - -#include "ime_common.h" +#include "core/libraries/ime/ime_common.h" namespace Core::Loader { class SymbolsResolver; @@ -16,13 +16,13 @@ namespace Libraries::Ime { constexpr u32 ORBIS_IME_MAX_TEXT_LENGTH = 2048; enum class OrbisImeKeyboardOption : u32 { - DEFAULT = 0, - REPEAT = 1, - REPEAT_EACH_KEY = 2, - ADD_OSK = 4, - EFFECTIVE_WITH_TIME = 8, - DISABLE_RESUME = 16, - DISABLE_CAPSLOCK_WITHOUT_SHIFT = 32, + Default = 0, + Repeat = 1, + RepeatEachKey = 2, + AddOsk = 4, + EffectiveWithTime = 8, + DisableResume = 16, + DisableCapslockWithoutShift = 32, }; DECLARE_ENUM_FLAG_OPERATORS(OrbisImeKeyboardOption) @@ -35,19 +35,19 @@ struct OrbisImeKeyboardParam { }; struct OrbisImeParam { - s32 userId; + s32 user_id; OrbisImeType type; - u64 supportedLanguages; - OrbisImeEnterLabel enterLabel; - OrbisImeInputMethod inputMethod; + u64 supported_languages; + OrbisImeEnterLabel enter_label; + OrbisImeInputMethod input_method; OrbisImeTextFilter filter; u32 option; - u32 maxTextLength; - char16_t* inputTextBuffer; + u32 max_text_length; + char16_t* input_text_buffer; float posx; float posy; - OrbisImeHorizontalAlignment horizontalAlignment; - OrbisImeVerticalAlignment verticalAlignment; + OrbisImeHorizontalAlignment horizontal_alignment; + OrbisImeVerticalAlignment vertical_alignment; void* work; void* arg; OrbisImeEventHandler handler; @@ -117,4 +117,5 @@ int PS4_SYSV_ABI sceImeVshUpdateContext(); int PS4_SYSV_ABI sceImeVshUpdateContext2(); void RegisterlibSceIme(Core::Loader::SymbolsResolver* sym); -} // namespace Libraries::Ime \ No newline at end of file + +} // namespace Libraries::Ime diff --git a/src/core/libraries/ime/ime_common.h b/src/core/libraries/ime/ime_common.h index 078a6469..77f23d91 100644 --- a/src/core/libraries/ime/ime_common.h +++ b/src/core/libraries/ime/ime_common.h @@ -2,65 +2,64 @@ // SPDX-License-Identifier: GPL-2.0-or-later #pragma once -#include -#include "common/enum.h" + #include "common/types.h" #include "core/libraries/rtc/rtc.h" enum class OrbisImeType : u32 { - DEFAULT = 0, - BASIC_LATIN = 1, - URL = 2, - MAIL = 3, - NUMBER = 4, + Default = 0, + BasicLatin = 1, + Url = 2, + Mail = 3, + Number = 4, }; enum class OrbisImeHorizontalAlignment : u32 { - LEFT = 0, - CENTER = 1, - RIGHT = 2, + Left = 0, + Center = 1, + Right = 2, }; enum class OrbisImeVerticalAlignment : u32 { - TOP = 0, - CENTER = 1, - BOTTOM = 2, + Top = 0, + Center = 1, + Bottom = 2, }; enum class OrbisImeEnterLabel : u32 { - DEFAULT = 0, - SEND = 1, - SEARCH = 2, - GO = 3, + Default = 0, + Send = 1, + Search = 2, + Go = 3, }; enum class OrbisImeInputMethod : u32 { - DEFAULT = 0, + Default = 0, }; enum class OrbisImeEventId : u32 { - OPEN = 0, - UPDATE_TEXT = 1, - UPDATE_CARET = 2, - PRESS_CLOSE = 4, - PRESS_ENTER = 5, - ABORT = 6, - CANDIDATE_LIST_START = 7, - CANDIDATE_LIST_END = 8, - CANDIDATE_WORD = 9, - CANDIDATE_INDEX = 10, - CANDIDATE_DONE = 11, - CANDIDATE_CANCEL = 12, - CHANGE_DEVICE = 14, - CHANGE_INPUT_METHOD_STATE = 18, + Open = 0, + UpdateText = 1, + UpdateCaret = 2, + PressClose = 4, + PressEnter = 5, + Abort = 6, + CandidateListStart = 7, + CandidateListEnd = 8, + CandidateWord = 9, + CandidateIndex = 10, + CandidateDone = 11, + CandidateCancel = 12, + ChangeDevice = 14, + ChangeInputMethodState = 18, - KEYBOARD_OPEN = 256, - KEYBOARD_KEYCODE_DOWN = 257, - KEYBOARD_KEYCODE_UP = 258, - KEYBOARD_KEYCODE_REPEAT = 259, - KEYBOARD_CONNECTION = 260, - KEYBOARD_DISCONNECTION = 261, - KEYBOARD_ABORT = 262, + KeyboardOpen = 256, + KeyboardKeycodeDoen = 257, + KeyboardKeycodeUp = 258, + KeyboardKeycodeRepeat = 259, + KeyboardConnection = 260, + KeyboardDisconnection = 261, + KeyboardAbort = 262, }; enum class OrbisImeKeyboardType : u32 { @@ -105,10 +104,10 @@ enum class OrbisImeKeyboardType : u32 { }; enum class OrbisImeDeviceType : u32 { - NONE = 0, - CONTROLLER = 1, - EXT_KEYBOARD = 2, - REMOTE_OSK = 3, + None = 0, + Controller = 1, + ExtKeyboard = 2, + RemoteOsk = 3, }; struct OrbisImeRect { @@ -126,9 +125,9 @@ struct OrbisImeTextAreaProperty { struct OrbisImeEditText { char16_t* str; - u32 caretIndex; - u32 areaNum; - OrbisImeTextAreaProperty textArea[4]; + u32 caret_index; + u32 area_num; + OrbisImeTextAreaProperty text_area[4]; }; struct OrbisImeKeycode { @@ -136,40 +135,40 @@ struct OrbisImeKeycode { char16_t character; u32 status; OrbisImeKeyboardType type; - s32 userId; - u32 resourceId; + s32 user_id; + u32 resource_id; Libraries::Rtc::OrbisRtcTick timestamp; }; struct OrbisImeKeyboardResourceIdArray { s32 userId; - u32 resourceId[6]; + u32 resource_id[6]; }; enum class OrbisImeCaretMovementDirection : u32 { - STILL = 0, - LEFT = 1, - RIGHT = 2, - UP = 3, - DOWN = 4, - HOME = 5, - END = 6, - PAGE_UP = 7, - PAGE_DOWN = 8, - TOP = 9, - BOTTOM = 10, + Still = 0, + Left = 1, + Right = 2, + Up = 3, + Down = 4, + Home = 5, + End = 6, + PageUp = 7, + PageDown = 8, + Top = 9, + Bottom = 10, }; union OrbisImeEventParam { OrbisImeRect rect; OrbisImeEditText text; - OrbisImeCaretMovementDirection caretMove; + OrbisImeCaretMovementDirection caret_move; OrbisImeKeycode keycode; - OrbisImeKeyboardResourceIdArray resourceIdArray; - char16_t* candidateWord; - s32 candidateIndex; - OrbisImeDeviceType deviceType; - u32 inputMethodState; + OrbisImeKeyboardResourceIdArray resource_id_array; + char16_t* candidate_word; + s32 candidate_index; + OrbisImeDeviceType device_type; + u32 input_method_state; s8 reserved[64]; }; @@ -178,7 +177,7 @@ struct OrbisImeEvent { OrbisImeEventParam param; }; -typedef PS4_SYSV_ABI int (*OrbisImeTextFilter)(char16_t* outText, u32* outTextLength, - const char16_t* srcText, u32 srcTextLength); +using OrbisImeTextFilter = PS4_SYSV_ABI int (*)(char16_t* outText, u32* outTextLength, + const char16_t* srcText, u32 srcTextLength); -typedef PS4_SYSV_ABI void (*OrbisImeEventHandler)(void* arg, const OrbisImeEvent* e); +using OrbisImeEventHandler = PS4_SYSV_ABI void (*)(void* arg, const OrbisImeEvent* e); diff --git a/src/core/libraries/ime/ime_dialog.cpp b/src/core/libraries/ime/ime_dialog.cpp index 63b52706..d6d02788 100644 --- a/src/core/libraries/ime/ime_dialog.cpp +++ b/src/core/libraries/ime/ime_dialog.cpp @@ -14,24 +14,24 @@ static constexpr std::array MAX_Y_POSITIONS = {2160.0f, 1080.0f}; namespace Libraries::ImeDialog { -static OrbisImeDialogStatus g_ime_dlg_status = OrbisImeDialogStatus::NONE; +static OrbisImeDialogStatus g_ime_dlg_status = OrbisImeDialogStatus::None; static OrbisImeDialogResult g_ime_dlg_result{}; static ImeDialogState g_ime_dlg_state{}; static ImeDialogUi g_ime_dlg_ui; static bool IsValidOption(OrbisImeDialogOption option, OrbisImeType type) { if (False(~option & - (OrbisImeDialogOption::MULTILINE | OrbisImeDialogOption::NO_AUTO_COMPLETION))) { + (OrbisImeDialogOption::Multiline | OrbisImeDialogOption::NoAutoCompletion))) { return false; } - if (True(option & OrbisImeDialogOption::MULTILINE) && type != OrbisImeType::DEFAULT && - type != OrbisImeType::BASIC_LATIN) { + if (True(option & OrbisImeDialogOption::Multiline) && type != OrbisImeType::Default && + type != OrbisImeType::BasicLatin) { return false; } - if (True(option & OrbisImeDialogOption::NO_AUTO_COMPLETION) && type != OrbisImeType::NUMBER && - type != OrbisImeType::BASIC_LATIN) { + if (True(option & OrbisImeDialogOption::NoAutoCompletion) && type != OrbisImeType::Number && + type != OrbisImeType::BasicLatin) { return false; } @@ -39,29 +39,29 @@ static bool IsValidOption(OrbisImeDialogOption option, OrbisImeType type) { } Error PS4_SYSV_ABI sceImeDialogAbort() { - if (g_ime_dlg_status == OrbisImeDialogStatus::NONE) { + if (g_ime_dlg_status == OrbisImeDialogStatus::None) { LOG_INFO(Lib_ImeDialog, "IME dialog not in use"); return Error::DIALOG_NOT_IN_USE; } - if (g_ime_dlg_status != OrbisImeDialogStatus::RUNNING) { + if (g_ime_dlg_status != OrbisImeDialogStatus::Running) { LOG_INFO(Lib_ImeDialog, "IME dialog not running"); return Error::DIALOG_NOT_RUNNING; } - g_ime_dlg_status = OrbisImeDialogStatus::FINISHED; - g_ime_dlg_result.endstatus = OrbisImeDialogEndStatus::ABORTED; + g_ime_dlg_status = OrbisImeDialogStatus::Finished; + g_ime_dlg_result.endstatus = OrbisImeDialogEndStatus::Aborted; return Error::OK; } Error PS4_SYSV_ABI sceImeDialogForceClose() { - if (g_ime_dlg_status == OrbisImeDialogStatus::NONE) { + if (g_ime_dlg_status == OrbisImeDialogStatus::None) { LOG_INFO(Lib_ImeDialog, "IME dialog not in use"); return Error::DIALOG_NOT_IN_USE; } - g_ime_dlg_status = OrbisImeDialogStatus::NONE; + g_ime_dlg_status = OrbisImeDialogStatus::None; g_ime_dlg_ui = ImeDialogUi(); g_ime_dlg_state = ImeDialogState(); @@ -93,7 +93,7 @@ int PS4_SYSV_ABI sceImeDialogGetPanelSizeExtended() { } Error PS4_SYSV_ABI sceImeDialogGetResult(OrbisImeDialogResult* result) { - if (g_ime_dlg_status == OrbisImeDialogStatus::NONE) { + if (g_ime_dlg_status == OrbisImeDialogStatus::None) { LOG_INFO(Lib_ImeDialog, "IME dialog is not running"); return Error::DIALOG_NOT_IN_USE; } @@ -105,7 +105,7 @@ Error PS4_SYSV_ABI sceImeDialogGetResult(OrbisImeDialogResult* result) { result->endstatus = g_ime_dlg_result.endstatus; - if (g_ime_dlg_status == OrbisImeDialogStatus::RUNNING) { + if (g_ime_dlg_status == OrbisImeDialogStatus::Running) { return Error::DIALOG_NOT_FINISHED; } @@ -114,7 +114,7 @@ Error PS4_SYSV_ABI sceImeDialogGetResult(OrbisImeDialogResult* result) { } OrbisImeDialogStatus PS4_SYSV_ABI sceImeDialogGetStatus() { - if (g_ime_dlg_status == OrbisImeDialogStatus::RUNNING) { + if (g_ime_dlg_status == OrbisImeDialogStatus::Running) { g_ime_dlg_state.CallTextFilter(); } @@ -122,7 +122,7 @@ OrbisImeDialogStatus PS4_SYSV_ABI sceImeDialogGetStatus() { } Error PS4_SYSV_ABI sceImeDialogInit(OrbisImeDialogParam* param, OrbisImeParamExtended* extended) { - if (g_ime_dlg_status != OrbisImeDialogStatus::NONE) { + if (g_ime_dlg_status != OrbisImeDialogStatus::None) { LOG_INFO(Lib_ImeDialog, "IME dialog is already running"); return Error::BUSY; } @@ -142,24 +142,24 @@ Error PS4_SYSV_ABI sceImeDialogInit(OrbisImeDialogParam* param, OrbisImeParamExt if (param->posx < 0.0f || param->posx >= - MAX_X_POSITIONS[False(param->option & OrbisImeDialogOption::LARGE_RESOLUTION)]) { + MAX_X_POSITIONS[False(param->option & OrbisImeDialogOption::LargeResolution)]) { LOG_INFO(Lib_ImeDialog, "Invalid param->posx"); return Error::INVALID_POSX; } if (param->posy < 0.0f || param->posy >= - MAX_Y_POSITIONS[False(param->option & OrbisImeDialogOption::LARGE_RESOLUTION)]) { + MAX_Y_POSITIONS[False(param->option & OrbisImeDialogOption::LargeResolution)]) { LOG_INFO(Lib_ImeDialog, "Invalid param->posy"); return Error::INVALID_POSY; } - if (!magic_enum::enum_contains(param->horizontalAlignment)) { + if (!magic_enum::enum_contains(param->horizontal_alignment)) { LOG_INFO(Lib_ImeDialog, "Invalid param->horizontalAlignment"); return Error::INVALID_HORIZONTALIGNMENT; } - if (!magic_enum::enum_contains(param->verticalAlignment)) { + if (!magic_enum::enum_contains(param->vertical_alignment)) { LOG_INFO(Lib_ImeDialog, "Invalid param->verticalAlignment"); return Error::INVALID_VERTICALALIGNMENT; } @@ -169,7 +169,7 @@ Error PS4_SYSV_ABI sceImeDialogInit(OrbisImeDialogParam* param, OrbisImeParamExt return Error::INVALID_PARAM; } - if (param->inputTextBuffer == nullptr) { + if (param->input_text_buffer == nullptr) { LOG_INFO(Lib_ImeDialog, "Invalid param->inputTextBuffer"); return Error::INVALID_INPUT_TEXT_BUFFER; } @@ -182,25 +182,25 @@ Error PS4_SYSV_ABI sceImeDialogInit(OrbisImeDialogParam* param, OrbisImeParamExt // TODO: do correct extended->option validation - if ((extended->extKeyboardMode & 0xe3fffffc) != 0) { + if ((extended->ext_keyboard_mode & 0xe3fffffc) != 0) { LOG_INFO(Lib_ImeDialog, "Invalid extended->extKeyboardMode"); return Error::INVALID_EXTENDED; } - if (extended->disableDevice > 7) { + if (extended->disable_device > 7) { LOG_INFO(Lib_ImeDialog, "Invalid extended->disableDevice"); return Error::INVALID_EXTENDED; } } - if (param->maxTextLength > ORBIS_IME_DIALOG_MAX_TEXT_LENGTH) { + if (param->max_text_length > ORBIS_IME_DIALOG_MAX_TEXT_LENGTH) { LOG_INFO(Lib_ImeDialog, "Invalid param->maxTextLength"); return Error::INVALID_MAX_TEXT_LENGTH; } g_ime_dlg_result = {}; g_ime_dlg_state = ImeDialogState(param, extended); - g_ime_dlg_status = OrbisImeDialogStatus::RUNNING; + g_ime_dlg_status = OrbisImeDialogStatus::Running; g_ime_dlg_ui = ImeDialogUi(&g_ime_dlg_state, &g_ime_dlg_status, &g_ime_dlg_result); return Error::OK; @@ -227,17 +227,17 @@ int PS4_SYSV_ABI sceImeDialogSetPanelPosition() { } Error PS4_SYSV_ABI sceImeDialogTerm() { - if (g_ime_dlg_status == OrbisImeDialogStatus::NONE) { + if (g_ime_dlg_status == OrbisImeDialogStatus::None) { LOG_INFO(Lib_ImeDialog, "IME dialog not in use"); return Error::DIALOG_NOT_IN_USE; } - if (g_ime_dlg_status == OrbisImeDialogStatus::RUNNING) { + if (g_ime_dlg_status == OrbisImeDialogStatus::Running) { LOG_INFO(Lib_ImeDialog, "IME dialog is still running"); return Error::DIALOG_NOT_FINISHED; } - g_ime_dlg_status = OrbisImeDialogStatus::NONE; + g_ime_dlg_status = OrbisImeDialogStatus::None; g_ime_dlg_ui = ImeDialogUi(); g_ime_dlg_state = ImeDialogState(); @@ -274,4 +274,4 @@ void RegisterlibSceImeDialog(Core::Loader::SymbolsResolver* sym) { LIB_FUNCTION("gyTyVn+bXMw", "libSceImeDialog", 1, "libSceImeDialog", 1, 1, sceImeDialogTerm); }; -} // namespace Libraries::ImeDialog \ No newline at end of file +} // namespace Libraries::ImeDialog diff --git a/src/core/libraries/ime/ime_dialog.h b/src/core/libraries/ime/ime_dialog.h index e99d2961..c8b22849 100644 --- a/src/core/libraries/ime/ime_dialog.h +++ b/src/core/libraries/ime/ime_dialog.h @@ -58,32 +58,32 @@ enum class Error : u32 { }; enum class OrbisImeDialogStatus : u32 { - NONE = 0, - RUNNING = 1, - FINISHED = 2, + None = 0, + Running = 1, + Finished = 2, }; enum class OrbisImeDialogEndStatus : u32 { - OK = 0, - USER_CANCELED = 1, - ABORTED = 2, + Ok = 0, + UserCanceled = 1, + Aborted = 2, }; enum class OrbisImeDialogOption : u32 { - DEFAULT = 0, - MULTILINE = 1, - NO_AUTO_CORRECTION = 2, - NO_AUTO_COMPLETION = 4, + Default = 0, + Multiline = 1, + NoAutoCorrection = 2, + NoAutoCompletion = 4, // TODO: Document missing options - LARGE_RESOLUTION = 1024, + LargeResolution = 1024, }; DECLARE_ENUM_FLAG_OPERATORS(OrbisImeDialogOption) enum class OrbisImePanelPriority : u32 { - DEFAULT = 0, - ALPHABET = 1, - SYMBOL = 2, - ACCENT = 3, + Default = 0, + Alphabet = 1, + Symbol = 2, + Accent = 3, }; struct OrbisImeColor { @@ -103,29 +103,29 @@ struct OrbisImeKeycode { char16_t character; u32 status; OrbisImeKeyboardType type; - s32 userId; - u32 resourceId; + s32 user_id; + u32 resource_id; u64 timestamp; }; -typedef PS4_SYSV_ABI int (*OrbisImeExtKeyboardFilter)(const OrbisImeKeycode* srcKeycode, - u16* outKeycode, u32* outStatus, - void* reserved); +using OrbisImeExtKeyboardFilter = PS4_SYSV_ABI int (*)(const OrbisImeKeycode* srcKeycode, + u16* outKeycode, u32* outStatus, + void* reserved); struct OrbisImeDialogParam { - s32 userId; + s32 user_id; OrbisImeType type; - u64 supportedLanguages; - OrbisImeEnterLabel enterLabel; - OrbisImeInputMethod inputMethod; + u64 supported_languages; + OrbisImeEnterLabel enter_label; + OrbisImeInputMethod input_method; OrbisImeTextFilter filter; OrbisImeDialogOption option; - u32 maxTextLength; - char16_t* inputTextBuffer; + u32 max_text_length; + char16_t* input_text_buffer; float posx; float posy; - OrbisImeHorizontalAlignment horizontalAlignment; - OrbisImeVerticalAlignment verticalAlignment; + OrbisImeHorizontalAlignment horizontal_alignment; + OrbisImeVerticalAlignment vertical_alignment; const char16_t* placeholder; const char16_t* title; s8 reserved[16]; @@ -133,20 +133,20 @@ struct OrbisImeDialogParam { struct OrbisImeParamExtended { u32 option; // OrbisImeDialogOptionExtended - OrbisImeColor colorBase; - OrbisImeColor colorLine; - OrbisImeColor colorTextField; - OrbisImeColor colorPreedit; - OrbisImeColor colorButtonDefault; - OrbisImeColor colorButtonFunction; - OrbisImeColor colorButtonSymbol; - OrbisImeColor colorText; - OrbisImeColor colorSpecial; + OrbisImeColor color_base; + OrbisImeColor color_line; + OrbisImeColor color_text_field; + OrbisImeColor color_preedit; + OrbisImeColor color_button_default; + OrbisImeColor color_button_function; + OrbisImeColor color_button_symbol; + OrbisImeColor color_text; + OrbisImeColor color_special; OrbisImePanelPriority priority; - char* additionalDictionaryPath; - OrbisImeExtKeyboardFilter extKeyboardFilter; - uint32_t disableDevice; - uint32_t extKeyboardMode; + char* additional_dictionary_path; + OrbisImeExtKeyboardFilter ext_keyboard_filter; + uint32_t disable_device; + uint32_t ext_keyboard_mode; int8_t reserved[60]; }; @@ -167,4 +167,4 @@ int PS4_SYSV_ABI sceImeDialogSetPanelPosition(); Error PS4_SYSV_ABI sceImeDialogTerm(); void RegisterlibSceImeDialog(Core::Loader::SymbolsResolver* sym); -} // namespace Libraries::ImeDialog \ No newline at end of file +} // namespace Libraries::ImeDialog diff --git a/src/core/libraries/ime/ime_dialog_ui.cpp b/src/core/libraries/ime/ime_dialog_ui.cpp index de64de5f..5957606e 100644 --- a/src/core/libraries/ime/ime_dialog_ui.cpp +++ b/src/core/libraries/ime/ime_dialog_ui.cpp @@ -8,7 +8,6 @@ #include "common/assert.h" #include "common/logging/log.h" -#include "common/singleton.h" #include "core/libraries/ime/ime_dialog.h" #include "core/libraries/ime/ime_dialog_ui.h" #include "core/tls.h" @@ -26,15 +25,15 @@ ImeDialogState::ImeDialogState(const OrbisImeDialogParam* param, return; } - userId = param->userId; - is_multiLine = True(param->option & OrbisImeDialogOption::MULTILINE); - is_numeric = param->type == OrbisImeType::NUMBER; + user_id = param->user_id; + is_multi_line = True(param->option & OrbisImeDialogOption::Multiline); + is_numeric = param->type == OrbisImeType::Number; type = param->type; - enter_label = param->enterLabel; + enter_label = param->enter_label; text_filter = param->filter; - keyboard_filter = extended ? extended->extKeyboardFilter : nullptr; - max_text_length = param->maxTextLength; - text_buffer = param->inputTextBuffer; + keyboard_filter = extended ? extended->ext_keyboard_filter : nullptr; + max_text_length = param->max_text_length; + text_buffer = param->input_text_buffer; if (param->title) { std::size_t title_len = std::char_traits::length(param->title); @@ -65,12 +64,12 @@ ImeDialogState::ImeDialogState(const OrbisImeDialogParam* param, } ImeDialogState::ImeDialogState(ImeDialogState&& other) noexcept - : input_changed(other.input_changed), userId(other.userId), is_multiLine(other.is_multiLine), - is_numeric(other.is_numeric), type(other.type), enter_label(other.enter_label), - text_filter(other.text_filter), keyboard_filter(other.keyboard_filter), - max_text_length(other.max_text_length), text_buffer(other.text_buffer), - title(std::move(other.title)), placeholder(std::move(other.placeholder)), - current_text(other.current_text) { + : input_changed(other.input_changed), user_id(other.user_id), + is_multi_line(other.is_multi_line), is_numeric(other.is_numeric), type(other.type), + enter_label(other.enter_label), text_filter(other.text_filter), + keyboard_filter(other.keyboard_filter), max_text_length(other.max_text_length), + text_buffer(other.text_buffer), title(std::move(other.title)), + placeholder(std::move(other.placeholder)), current_text(other.current_text) { other.text_buffer = nullptr; } @@ -78,8 +77,8 @@ ImeDialogState::ImeDialogState(ImeDialogState&& other) noexcept ImeDialogState& ImeDialogState::operator=(ImeDialogState&& other) { if (this != &other) { input_changed = other.input_changed; - userId = other.userId; - is_multiLine = other.is_multiLine; + user_id = other.user_id; + is_multi_line = other.is_multi_line; is_numeric = other.is_numeric; type = other.type; enter_label = other.enter_label; @@ -171,7 +170,7 @@ ImeDialogUi::ImeDialogUi(ImeDialogState* state, OrbisImeDialogStatus* status, OrbisImeDialogResult* result) : state(state), status(status), result(result) { - if (state && *status == OrbisImeDialogStatus::RUNNING) { + if (state && *status == OrbisImeDialogStatus::Running) { AddLayer(this); } } @@ -191,7 +190,7 @@ ImeDialogUi::ImeDialogUi(ImeDialogUi&& other) noexcept other.status = nullptr; other.result = nullptr; - if (state && *status == OrbisImeDialogStatus::RUNNING) { + if (state && *status == OrbisImeDialogStatus::Running) { AddLayer(this); } } @@ -208,7 +207,7 @@ ImeDialogUi& ImeDialogUi::operator=(ImeDialogUi&& other) { other.status = nullptr; other.result = nullptr; - if (state && *status == OrbisImeDialogStatus::RUNNING) { + if (state && *status == OrbisImeDialogStatus::Running) { AddLayer(this); } @@ -226,7 +225,7 @@ void ImeDialogUi::Draw() { return; } - if (!status || *status != OrbisImeDialogStatus::RUNNING) { + if (!status || *status != OrbisImeDialogStatus::Running) { return; } @@ -235,7 +234,7 @@ void ImeDialogUi::Draw() { ImVec2 window_size; - if (state->is_multiLine) { + if (state->is_multi_line) { window_size = {500.0f, 300.0f}; } else { window_size = {500.0f, 150.0f}; @@ -259,7 +258,7 @@ void ImeDialogUi::Draw() { SetWindowFontScale(1.0f); } - if (state->is_multiLine) { + if (state->is_multi_line) { DrawMultiLineInputText(); } else { DrawInputText(); @@ -270,16 +269,16 @@ void ImeDialogUi::Draw() { const char* button_text; switch (state->enter_label) { - case OrbisImeEnterLabel::GO: + case OrbisImeEnterLabel::Go: button_text = "Go##ImeDialogOK"; break; - case OrbisImeEnterLabel::SEARCH: + case OrbisImeEnterLabel::Search: button_text = "Search##ImeDialogOK"; break; - case OrbisImeEnterLabel::SEND: + case OrbisImeEnterLabel::Send: button_text = "Send##ImeDialogOK"; break; - case OrbisImeEnterLabel::DEFAULT: + case OrbisImeEnterLabel::Default: default: button_text = "OK##ImeDialogOK"; break; @@ -292,16 +291,16 @@ void ImeDialogUi::Draw() { SetCursorPosX(button_start_pos); if (Button(button_text, BUTTON_SIZE) || - (!state->is_multiLine && IsKeyPressed(ImGuiKey_Enter))) { - *status = OrbisImeDialogStatus::FINISHED; - result->endstatus = OrbisImeDialogEndStatus::OK; + (!state->is_multi_line && IsKeyPressed(ImGuiKey_Enter))) { + *status = OrbisImeDialogStatus::Finished; + result->endstatus = OrbisImeDialogEndStatus::Ok; } SameLine(0.0f, button_spacing); if (Button("Cancel##ImeDialogCancel", BUTTON_SIZE)) { - *status = OrbisImeDialogStatus::FINISHED; - result->endstatus = OrbisImeDialogEndStatus::USER_CANCELED; + *status = OrbisImeDialogStatus::Finished; + result->endstatus = OrbisImeDialogEndStatus::UserCanceled; } } End(); @@ -362,9 +361,10 @@ int ImeDialogUi::InputTextCallback(ImGuiInputTextCallbackData* data) { .status = 1, // ??? 1 = key pressed, 0 = key released .type = OrbisImeKeyboardType::ENGLISH_US, // TODO set this to the correct value (maybe use // the current language?) - .userId = ui->state->userId, - .resourceId = 0, - .timestamp = 0}; + .user_id = ui->state->user_id, + .resource_id = 0, + .timestamp = 0, + }; if (!ui->state->ConvertUTF8ToOrbis(event_char, 4, &src_keycode.character, 1)) { LOG_ERROR(Lib_ImeDialog, "Failed to convert orbis char to utf8"); diff --git a/src/core/libraries/ime/ime_dialog_ui.h b/src/core/libraries/ime/ime_dialog_ui.h index a4cf6e9f..10dff5ee 100644 --- a/src/core/libraries/ime/ime_dialog_ui.h +++ b/src/core/libraries/ime/ime_dialog_ui.h @@ -20,8 +20,8 @@ class ImeDialogState final { bool input_changed = false; - s32 userId{}; - bool is_multiLine{}; + s32 user_id{}; + bool is_multi_line{}; bool is_numeric{}; OrbisImeType type{}; OrbisImeEnterLabel enter_label{}; diff --git a/src/core/libraries/ime/ime_error.h b/src/core/libraries/ime/ime_error.h new file mode 100644 index 00000000..77eeada3 --- /dev/null +++ b/src/core/libraries/ime/ime_error.h @@ -0,0 +1,51 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/libraries/error_codes.h" + +// ImeDialog library +constexpr int ORBIS_ERROR_DIALOG_ERROR_NOT_INITIALIZED = 0x80ED0001; +constexpr int ORBIS_ERROR_DIALOG_ERROR_ALREADY_INITIALIZED = 0x80ED0002; +constexpr int ORBIS_ERROR_DIALOG_ERROR_PARAM_INVALID = 0x80ED0003; +constexpr int ORBIS_ERROR_DIALOG_ERROR_UNEXPECTED_FATAL = 0x80ED0004; +constexpr int ORBIS_ERROR_DIALOG_ERROR_INVALID_STATE = 0x80ED0005; +constexpr int ORBIS_ERROR_DIALOG_ERROR_SERVICE_BUSY = 0x80ED0006; +constexpr int ORBIS_ERROR_DIALOG_ERROR_INVALID_USER_ID = 0x80ED0007; + +// Ime library +constexpr int ORBIS_IME_ERROR_BUSY = 0x80BC0001; +constexpr int ORBIS_IME_ERROR_NOT_OPENED = 0x80BC0002; +constexpr int ORBIS_IME_ERROR_NO_MEMORY = 0x80BC0003; +constexpr int ORBIS_IME_ERROR_CONNECTION_FAILED = 0x80BC0004; +constexpr int ORBIS_IME_ERROR_TOO_MANY_REQUESTS = 0x80BC0005; +constexpr int ORBIS_IME_ERROR_INVALID_TEXT = 0x80BC0006; +constexpr int ORBIS_IME_ERROR_EVENT_OVERFLOW = 0x80BC0007; +constexpr int ORBIS_IME_ERROR_NOT_ACTIVE = 0x80BC0008; +constexpr int ORBIS_IME_ERROR_IME_SUSPENDING = 0x80BC0009; +constexpr int ORBIS_IME_ERROR_DEVICE_IN_USE = 0x80BC000A; +constexpr int ORBIS_IME_ERROR_INVALID_USER_ID = 0x80BC0010; +constexpr int ORBIS_IME_ERROR_INVALID_TYPE = 0x80BC0011; +constexpr int ORBIS_IME_ERROR_INVALID_SUPPORTED_LANGUAGES = 0x80BC0012; +constexpr int ORBIS_IME_ERROR_INVALID_ENTER_LABEL = 0x80BC0013; +constexpr int ORBIS_IME_ERROR_INVALID_INPUT_METHOD = 0x80BC0014; +constexpr int ORBIS_IME_ERROR_INVALID_OPTION = 0x80BC0015; +constexpr int ORBIS_IME_ERROR_INVALID_MAX_TEXT_LENGTH = 0x80BC0016; +constexpr int ORBIS_IME_ERROR_INVALID_INPUT_TEXT_BUFFER = 0x80BC0017; +constexpr int ORBIS_IME_ERROR_INVALID_POSX = 0x80BC0018; +constexpr int ORBIS_IME_ERROR_INVALID_POSY = 0x80BC0019; +constexpr int ORBIS_IME_ERROR_INVALID_HORIZONTAL_ALIGNMENT = 0x80BC001A; +constexpr int ORBIS_IME_ERROR_INVALID_VERTICAL_ALIGNMENT = 0x80BC001B; +constexpr int ORBIS_IME_ERROR_INVALID_EXTENDED = 0x80BC001C; +constexpr int ORBIS_IME_ERROR_INVALID_KEYBOARD_TYPE = 0x80BC001D; +constexpr int ORBIS_IME_ERROR_INVALID_WORK = 0x80BC0020; +constexpr int ORBIS_IME_ERROR_INVALID_ARG = 0x80BC0021; +constexpr int ORBIS_IME_ERROR_INVALID_HANDLER = 0x80BC0022; +constexpr int ORBIS_IME_ERROR_NO_RESOURCE_ID = 0x80BC0023; +constexpr int ORBIS_IME_ERROR_INVALID_MODE = 0x80BC0024; +constexpr int ORBIS_IME_ERROR_INVALID_PARAM = 0x80BC0030; +constexpr int ORBIS_IME_ERROR_INVALID_ADDRESS = 0x80BC0031; +constexpr int ORBIS_IME_ERROR_INVALID_RESERVED = 0x80BC0032; +constexpr int ORBIS_IME_ERROR_INVALID_TIMING = 0x80BC0033; +constexpr int ORBIS_IME_ERROR_INTERNAL = 0x80BC00FF; diff --git a/src/core/libraries/ime/ime_ui.cpp b/src/core/libraries/ime/ime_ui.cpp index 09d36126..c5f41c5e 100644 --- a/src/core/libraries/ime/ime_ui.cpp +++ b/src/core/libraries/ime/ime_ui.cpp @@ -16,7 +16,7 @@ ImeState::ImeState(const OrbisImeParam* param) { } work_buffer = param->work; - text_buffer = param->inputTextBuffer; + text_buffer = param->input_text_buffer; std::size_t text_len = std::char_traits::length(text_buffer); if (!ConvertOrbisToUTF8(text_buffer, text_len, current_text.begin(), @@ -52,13 +52,13 @@ void ImeState::SendEvent(OrbisImeEvent* event) { void ImeState::SendEnterEvent() { OrbisImeEvent enterEvent{}; - enterEvent.id = OrbisImeEventId::PRESS_ENTER; + enterEvent.id = OrbisImeEventId::PressEnter; SendEvent(&enterEvent); } void ImeState::SendCloseEvent() { OrbisImeEvent closeEvent{}; - closeEvent.id = OrbisImeEventId::PRESS_CLOSE; + closeEvent.id = OrbisImeEventId::PressClose; closeEvent.param.text.str = reinterpret_cast(work_buffer); SendEvent(&closeEvent); } @@ -180,7 +180,7 @@ void ImeUi::DrawInputText() { if (first_render) { SetKeyboardFocusHere(); } - if (InputTextEx("##ImeInput", nullptr, state->current_text.begin(), ime_param->maxTextLength, + if (InputTextEx("##ImeInput", nullptr, state->current_text.begin(), ime_param->max_text_length, input_size, ImGuiInputTextFlags_CallbackAlways, InputTextCallback, this)) { state->input_changed = true; } @@ -194,16 +194,16 @@ int ImeUi::InputTextCallback(ImGuiInputTextCallbackData* data) { if (lastCaretPos == -1) { lastCaretPos = data->CursorPos; } else if (data->CursorPos != lastCaretPos) { - OrbisImeCaretMovementDirection caretDirection = OrbisImeCaretMovementDirection::STILL; + OrbisImeCaretMovementDirection caretDirection = OrbisImeCaretMovementDirection::Still; if (data->CursorPos < lastCaretPos) { - caretDirection = OrbisImeCaretMovementDirection::LEFT; + caretDirection = OrbisImeCaretMovementDirection::Left; } else if (data->CursorPos > lastCaretPos) { - caretDirection = OrbisImeCaretMovementDirection::RIGHT; + caretDirection = OrbisImeCaretMovementDirection::Right; } OrbisImeEvent event{}; - event.id = OrbisImeEventId::UPDATE_CARET; - event.param.caretMove = caretDirection; + event.id = OrbisImeEventId::UpdateCaret; + event.param.caret_move = caretDirection; lastCaretPos = data->CursorPos; ui->state->SendEvent(&event); @@ -214,28 +214,28 @@ int ImeUi::InputTextCallback(ImGuiInputTextCallbackData* data) { if (currentText != lastText) { OrbisImeEditText eventParam{}; eventParam.str = reinterpret_cast(ui->ime_param->work); - eventParam.caretIndex = data->CursorPos; - eventParam.areaNum = 1; + eventParam.caret_index = data->CursorPos; + eventParam.area_num = 1; - eventParam.textArea[0].mode = 1; // Edit mode - eventParam.textArea[0].index = data->CursorPos; - eventParam.textArea[0].length = data->BufTextLen; + eventParam.text_area[0].mode = 1; // Edit mode + eventParam.text_area[0].index = data->CursorPos; + eventParam.text_area[0].length = data->BufTextLen; if (!ui->state->ConvertUTF8ToOrbis(data->Buf, data->BufTextLen, eventParam.str, - ui->ime_param->maxTextLength)) { + ui->ime_param->max_text_length)) { LOG_ERROR(Lib_ImeDialog, "Failed to convert Orbis char to UTF-8"); return 0; } if (!ui->state->ConvertUTF8ToOrbis(data->Buf, data->BufTextLen, - ui->ime_param->inputTextBuffer, - ui->ime_param->maxTextLength)) { + ui->ime_param->input_text_buffer, + ui->ime_param->max_text_length)) { LOG_ERROR(Lib_ImeDialog, "Failed to convert Orbis char to UTF-8"); return 0; } OrbisImeEvent event{}; - event.id = OrbisImeEventId::UPDATE_TEXT; + event.id = OrbisImeEventId::UpdateText; event.param.text = eventParam; lastText = currentText; @@ -249,4 +249,4 @@ void ImeUi::Free() { RemoveLayer(this); } -}; // namespace Libraries::Ime \ No newline at end of file +}; // namespace Libraries::Ime diff --git a/src/core/libraries/kernel/equeue.cpp b/src/core/libraries/kernel/equeue.cpp index d4f7eaba..6543cc31 100644 --- a/src/core/libraries/kernel/equeue.cpp +++ b/src/core/libraries/kernel/equeue.cpp @@ -4,8 +4,8 @@ #include "common/assert.h" #include "common/debug.h" #include "common/logging/log.h" -#include "core/libraries/error_codes.h" #include "core/libraries/kernel/equeue.h" +#include "core/libraries/kernel/orbis_error.h" #include "core/libraries/libs.h" namespace Libraries::Kernel { @@ -77,9 +77,8 @@ bool EqueueInternal::TriggerEvent(u64 ident, s16 filter, void* trigger_data) { bool has_found = false; { std::scoped_lock lock{m_mutex}; - for (auto& event : m_events) { - if ((event.event.ident == ident) && (event.event.filter == filter)) { + if (event.event.ident == ident && event.event.filter == filter) { event.Trigger(trigger_data); has_found = true; } @@ -91,7 +90,6 @@ bool EqueueInternal::TriggerEvent(u64 ident, s16 filter, void* trigger_data) { int EqueueInternal::GetTriggeredEvents(SceKernelEvent* ev, int num) { int count = 0; - for (auto& event : m_events) { if (event.IsTriggered()) { if (event.event.flags & SceKernelEvent::Flags::Clear) { diff --git a/src/core/libraries/kernel/file_system.cpp b/src/core/libraries/kernel/file_system.cpp index d0ffa21c..1b95e527 100644 --- a/src/core/libraries/kernel/file_system.cpp +++ b/src/core/libraries/kernel/file_system.cpp @@ -6,8 +6,8 @@ #include "common/scope_exit.h" #include "common/singleton.h" #include "core/file_sys/fs.h" -#include "core/libraries/error_codes.h" #include "core/libraries/kernel/file_system.h" +#include "core/libraries/kernel/orbis_error.h" #include "core/libraries/libs.h" #include "kernel.h" @@ -128,12 +128,12 @@ int PS4_SYSV_ABI sceKernelClose(int d) { return ORBIS_KERNEL_ERROR_EPERM; } if (d == 2003) { // dev/urandom case - return SCE_OK; + return ORBIS_OK; } auto* h = Common::Singleton::Instance(); auto* file = h->GetFile(d); if (file == nullptr) { - return SCE_KERNEL_ERROR_EBADF; + return ORBIS_KERNEL_ERROR_EBADF; } if (!file->is_directory) { file->f.Close(); @@ -141,7 +141,7 @@ int PS4_SYSV_ABI sceKernelClose(int d) { file->is_opened = false; LOG_INFO(Kernel_Fs, "Closing {}", file->m_guest_name); h->DeleteHandle(d); - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI posix_close(int d) { @@ -166,7 +166,7 @@ size_t PS4_SYSV_ABI sceKernelWrite(int d, const void* buf, size_t nbytes) { auto* h = Common::Singleton::Instance(); auto* file = h->GetFile(d); if (file == nullptr) { - return SCE_KERNEL_ERROR_EBADF; + return ORBIS_KERNEL_ERROR_EBADF; } std::scoped_lock lk{file->m_mutex}; @@ -175,7 +175,7 @@ size_t PS4_SYSV_ABI sceKernelWrite(int d, const void* buf, size_t nbytes) { int PS4_SYSV_ABI sceKernelUnlink(const char* path) { if (path == nullptr) { - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } auto* h = Common::Singleton::Instance(); @@ -184,15 +184,15 @@ int PS4_SYSV_ABI sceKernelUnlink(const char* path) { bool ro = false; const auto host_path = mnt->GetHostPath(path, &ro); if (host_path.empty()) { - return SCE_KERNEL_ERROR_EACCES; + return ORBIS_KERNEL_ERROR_EACCES; } if (ro) { - return SCE_KERNEL_ERROR_EROFS; + return ORBIS_KERNEL_ERROR_EROFS; } if (std::filesystem::is_directory(host_path)) { - return SCE_KERNEL_ERROR_EPERM; + return ORBIS_KERNEL_ERROR_EPERM; } auto* file = h->GetFile(host_path); @@ -201,7 +201,7 @@ int PS4_SYSV_ABI sceKernelUnlink(const char* path) { } LOG_INFO(Kernel_Fs, "Unlinked {}", path); - return SCE_OK; + return ORBIS_OK; } size_t PS4_SYSV_ABI _readv(int d, const SceKernelIovec* iov, int iovcnt) { @@ -231,7 +231,7 @@ s64 PS4_SYSV_ABI sceKernelLseek(int d, s64 offset, int whence) { std::scoped_lock lk{file->m_mutex}; if (!file->f.Seek(offset, origin)) { LOG_CRITICAL(Kernel_Fs, "sceKernelLseek: failed to seek"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } return file->f.Tell(); } @@ -257,7 +257,7 @@ s64 PS4_SYSV_ABI sceKernelRead(int d, void* buf, size_t nbytes) { auto* h = Common::Singleton::Instance(); auto* file = h->GetFile(d); if (file == nullptr) { - return SCE_KERNEL_ERROR_EBADF; + return ORBIS_KERNEL_ERROR_EBADF; } std::scoped_lock lk{file->m_mutex}; @@ -277,7 +277,7 @@ int PS4_SYSV_ABI posix_read(int d, void* buf, size_t nbytes) { int PS4_SYSV_ABI sceKernelMkdir(const char* path, u16 mode) { LOG_INFO(Kernel_Fs, "path = {} mode = {}", path, mode); if (path == nullptr) { - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } auto* mnt = Common::Singleton::Instance(); @@ -285,21 +285,21 @@ int PS4_SYSV_ABI sceKernelMkdir(const char* path, u16 mode) { const auto dir_name = mnt->GetHostPath(path, &ro); if (std::filesystem::exists(dir_name)) { - return SCE_KERNEL_ERROR_EEXIST; + return ORBIS_KERNEL_ERROR_EEXIST; } if (ro) { - return SCE_KERNEL_ERROR_EROFS; + return ORBIS_KERNEL_ERROR_EROFS; } // CUSA02456: path = /aotl after sceSaveDataMount(mode = 1) std::error_code ec; if (dir_name.empty() || !std::filesystem::create_directory(dir_name, ec)) { - return SCE_KERNEL_ERROR_EIO; + return ORBIS_KERNEL_ERROR_EIO; } if (!std::filesystem::exists(dir_name)) { - return SCE_KERNEL_ERROR_ENOENT; + return ORBIS_KERNEL_ERROR_ENOENT; } return ORBIS_OK; } @@ -323,13 +323,13 @@ int PS4_SYSV_ABI sceKernelRmdir(const char* path) { if (dir_name.empty()) { LOG_ERROR(Kernel_Fs, "Failed to remove directory: {}, permission denied", fmt::UTF(dir_name.u8string())); - return SCE_KERNEL_ERROR_EACCES; + return ORBIS_KERNEL_ERROR_EACCES; } if (ro) { LOG_ERROR(Kernel_Fs, "Failed to remove directory: {}, directory is read only", fmt::UTF(dir_name.u8string())); - return SCE_KERNEL_ERROR_EROFS; + return ORBIS_KERNEL_ERROR_EROFS; } if (!std::filesystem::is_directory(dir_name)) { @@ -411,7 +411,7 @@ int PS4_SYSV_ABI sceKernelCheckReachability(const char* path) { auto* mnt = Common::Singleton::Instance(); const auto path_name = mnt->GetHostPath(path); if (!std::filesystem::exists(path_name)) { - return SCE_KERNEL_ERROR_ENOENT; + return ORBIS_KERNEL_ERROR_ENOENT; } return ORBIS_OK; } @@ -514,15 +514,15 @@ int PS4_SYSV_ABI sceKernelFtruncate(int fd, s64 length) { auto* file = h->GetFile(fd); if (file == nullptr) { - return SCE_KERNEL_ERROR_EBADF; + return ORBIS_KERNEL_ERROR_EBADF; } if (file->m_host_name.empty()) { - return SCE_KERNEL_ERROR_EACCES; + return ORBIS_KERNEL_ERROR_EACCES; } file->f.SetSize(length); - return SCE_OK; + return ORBIS_OK; } static int GetDents(int fd, char* buf, int nbytes, s64* basep) { @@ -605,11 +605,11 @@ s32 PS4_SYSV_ABI sceKernelRename(const char* from, const char* to) { return ORBIS_KERNEL_ERROR_ENOENT; } if (ro) { - return SCE_KERNEL_ERROR_EROFS; + return ORBIS_KERNEL_ERROR_EROFS; } const auto dst_path = mnt->GetHostPath(to, &ro); if (ro) { - return SCE_KERNEL_ERROR_EROFS; + return ORBIS_KERNEL_ERROR_EROFS; } const bool src_is_dir = std::filesystem::is_directory(src_path); const bool dst_is_dir = std::filesystem::is_directory(dst_path); diff --git a/src/core/libraries/kernel/file_system.h b/src/core/libraries/kernel/file_system.h index 0bc473ec..dcbb3957 100644 --- a/src/core/libraries/kernel/file_system.h +++ b/src/core/libraries/kernel/file_system.h @@ -37,8 +37,8 @@ struct OrbisKernelStat { u32 st_gen; s32 st_lspare; OrbisKernelTimespec st_birthtim; - unsigned int : (8 / 2) * (16 - static_cast(sizeof(OrbisKernelTimespec))); - unsigned int : (8 / 2) * (16 - static_cast(sizeof(OrbisKernelTimespec))); + u32 : (8 / 2) * (16 - static_cast(sizeof(OrbisKernelTimespec))); + u32 : (8 / 2) * (16 - static_cast(sizeof(OrbisKernelTimespec))); }; struct OrbisKernelDirent { diff --git a/src/core/libraries/kernel/kernel.cpp b/src/core/libraries/kernel/kernel.cpp index 512e77bc..b310c7be 100644 --- a/src/core/libraries/kernel/kernel.cpp +++ b/src/core/libraries/kernel/kernel.cpp @@ -2,36 +2,27 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include - #include #include "common/assert.h" #include "common/debug.h" #include "common/logging/log.h" #include "common/polyfill_thread.h" -#include "common/singleton.h" #include "common/thread.h" -#include "core/file_sys/fs.h" -#include "core/libraries/error_codes.h" #include "core/libraries/kernel/equeue.h" #include "core/libraries/kernel/file_system.h" #include "core/libraries/kernel/kernel.h" #include "core/libraries/kernel/memory.h" +#include "core/libraries/kernel/orbis_error.h" +#include "core/libraries/kernel/posix_error.h" #include "core/libraries/kernel/process.h" #include "core/libraries/kernel/threads.h" #include "core/libraries/kernel/threads/exception.h" #include "core/libraries/kernel/time.h" #include "core/libraries/libs.h" -#include "core/linker.h" #ifdef _WIN64 -#include -#include -#include -#else -#ifdef __APPLE__ -#include -#endif +#include #endif namespace Libraries::Kernel { @@ -39,10 +30,10 @@ namespace Libraries::Kernel { static u64 g_stack_chk_guard = 0xDEADBEEF54321ABC; // dummy return boost::asio::io_context io_context; -std::mutex m_asio_req; -std::condition_variable_any cv_asio_req; -std::atomic asio_requests; -std::jthread service_thread; +static std::mutex m_asio_req; +static std::condition_variable_any cv_asio_req; +static std::atomic asio_requests; +static std::jthread service_thread; void KernelSignalRequest() { std::unique_lock lock{m_asio_req}; @@ -93,16 +84,12 @@ int* PS4_SYSV_ABI __Error() { return &g_posix_errno; } -void ErrSceToPosix(int result) { - const int rt = result > SCE_KERNEL_ERROR_UNKNOWN && result <= SCE_KERNEL_ERROR_ESTOP - ? result + -SCE_KERNEL_ERROR_UNKNOWN - : POSIX_EOTHER; - g_posix_errno = rt; +void ErrSceToPosix(int error) { + g_posix_errno = error - ORBIS_KERNEL_ERROR_UNKNOWN; } -int ErrnoToSceKernelError(int e) { - const auto res = SCE_KERNEL_ERROR_UNKNOWN + e; - return res > SCE_KERNEL_ERROR_ESTOP ? SCE_KERNEL_ERROR_UNKNOWN : res; +int ErrnoToSceKernelError(int error) { + return error + ORBIS_KERNEL_ERROR_UNKNOWN; } void SetPosixErrno(int e) { diff --git a/src/core/libraries/kernel/kernel.h b/src/core/libraries/kernel/kernel.h index f6865d22..8e7f475a 100644 --- a/src/core/libraries/kernel/kernel.h +++ b/src/core/libraries/kernel/kernel.h @@ -5,9 +5,8 @@ #include #include -#include "common/logging/log.h" #include "common/types.h" -#include "core/libraries/error_codes.h" +#include "core/libraries/kernel/orbis_error.h" namespace Core::Loader { class SymbolsResolver; @@ -38,7 +37,7 @@ struct WrapperImpl { u32 ret = f(args...); if (ret != 0) { // LOG_ERROR(Lib_Kernel, "Function {} returned {}", std::string_view{name.value}, ret); - ret += SCE_KERNEL_ERROR_UNKNOWN; + ret += ORBIS_KERNEL_ERROR_UNKNOWN; } return ret; } diff --git a/src/core/libraries/kernel/memory.cpp b/src/core/libraries/kernel/memory.cpp index 4d55fc2a..606c5c18 100644 --- a/src/core/libraries/kernel/memory.cpp +++ b/src/core/libraries/kernel/memory.cpp @@ -9,9 +9,9 @@ #include "common/scope_exit.h" #include "common/singleton.h" #include "core/file_sys/fs.h" -#include "core/libraries/error_codes.h" #include "core/libraries/kernel/kernel.h" #include "core/libraries/kernel/memory.h" +#include "core/libraries/kernel/orbis_error.h" #include "core/libraries/libs.h" #include "core/linker.h" #include "core/memory.h" @@ -28,20 +28,20 @@ int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u u64 alignment, int memoryType, s64* physAddrOut) { if (searchStart < 0 || searchEnd <= searchStart) { LOG_ERROR(Kernel_Vmm, "Provided address range is invalid!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } const bool is_in_range = searchEnd - searchStart >= len; if (len <= 0 || !Common::Is16KBAligned(len) || !is_in_range) { LOG_ERROR(Kernel_Vmm, "Provided address range is invalid!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } if (alignment != 0 && !Common::Is16KBAligned(alignment)) { LOG_ERROR(Kernel_Vmm, "Alignment value is invalid!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } if (physAddrOut == nullptr) { LOG_ERROR(Kernel_Vmm, "Result physical address pointer is null!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } auto* memory = Core::Memory::Instance(); @@ -53,7 +53,7 @@ int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u "alignment = {:#x}, memoryType = {:#x}, physAddrOut = {:#x}", searchStart, searchEnd, len, alignment, memoryType, phys_addr); - return SCE_OK; + return ORBIS_OK; } s32 PS4_SYSV_ABI sceKernelAllocateMainDirectMemory(size_t len, size_t alignment, int memoryType, @@ -111,7 +111,7 @@ s32 PS4_SYSV_ABI sceKernelVirtualQuery(const void* addr, int flags, OrbisVirtual size_t infoSize) { LOG_INFO(Kernel_Vmm, "called addr = {}, flags = {:#x}", fmt::ptr(addr), flags); if (!addr) { - return SCE_KERNEL_ERROR_EACCES; + return ORBIS_KERNEL_ERROR_EACCES; } auto* memory = Core::Memory::Instance(); return memory->VirtualQuery(std::bit_cast(addr), flags, info); @@ -123,16 +123,16 @@ s32 PS4_SYSV_ABI sceKernelReserveVirtualRange(void** addr, u64 len, int flags, u if (addr == nullptr) { LOG_ERROR(Kernel_Vmm, "Address is invalid!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } if (len == 0 || !Common::Is16KBAligned(len)) { LOG_ERROR(Kernel_Vmm, "Map size is either zero or not 16KB aligned!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } if (alignment != 0) { if ((!std::has_single_bit(alignment) && !Common::Is16KBAligned(alignment))) { LOG_ERROR(Kernel_Vmm, "Alignment value is invalid!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } } @@ -141,7 +141,7 @@ s32 PS4_SYSV_ABI sceKernelReserveVirtualRange(void** addr, u64 len, int flags, u const auto map_flags = static_cast(flags); memory->Reserve(addr, in_addr, len, map_flags, alignment); - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceKernelMapNamedDirectMemory(void** addr, u64 len, int prot, int flags, @@ -149,16 +149,16 @@ int PS4_SYSV_ABI sceKernelMapNamedDirectMemory(void** addr, u64 len, int prot, i const char* name) { if (len == 0 || !Common::Is16KBAligned(len)) { LOG_ERROR(Kernel_Vmm, "Map size is either zero or not 16KB aligned!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } if (!Common::Is16KBAligned(directMemoryStart)) { LOG_ERROR(Kernel_Vmm, "Start address is not 16KB aligned!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } if (alignment != 0) { if ((!std::has_single_bit(alignment) && !Common::Is16KBAligned(alignment))) { LOG_ERROR(Kernel_Vmm, "Alignment value is invalid!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } } @@ -357,20 +357,20 @@ s32 PS4_SYSV_ABI sceKernelMemoryPoolExpand(u64 searchStart, u64 searchEnd, size_ size_t alignment, u64* physAddrOut) { if (searchStart < 0 || searchEnd <= searchStart) { LOG_ERROR(Kernel_Vmm, "Provided address range is invalid!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } const bool is_in_range = searchEnd - searchStart >= len; if (len <= 0 || !Common::Is64KBAligned(len) || !is_in_range) { LOG_ERROR(Kernel_Vmm, "Provided address range is invalid!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } if (alignment != 0 && !Common::Is64KBAligned(alignment)) { LOG_ERROR(Kernel_Vmm, "Alignment value is invalid!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } if (physAddrOut == nullptr) { LOG_ERROR(Kernel_Vmm, "Result physical address pointer is null!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } auto* memory = Core::Memory::Instance(); @@ -391,16 +391,16 @@ s32 PS4_SYSV_ABI sceKernelMemoryPoolReserve(void* addrIn, size_t len, size_t ali if (addrIn == nullptr) { LOG_ERROR(Kernel_Vmm, "Address is invalid!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } if (len == 0 || !Common::Is2MBAligned(len)) { LOG_ERROR(Kernel_Vmm, "Map size is either zero or not 2MB aligned!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } if (alignment != 0) { if ((!std::has_single_bit(alignment) && !Common::Is2MBAligned(alignment))) { LOG_ERROR(Kernel_Vmm, "Alignment value is invalid!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } } @@ -415,11 +415,11 @@ s32 PS4_SYSV_ABI sceKernelMemoryPoolReserve(void* addrIn, size_t len, size_t ali s32 PS4_SYSV_ABI sceKernelMemoryPoolCommit(void* addr, size_t len, int type, int prot, int flags) { if (addr == nullptr) { LOG_ERROR(Kernel_Vmm, "Address is invalid!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } if (len == 0 || !Common::Is64KBAligned(len)) { LOG_ERROR(Kernel_Vmm, "Map size is either zero or not 64KB aligned!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } LOG_INFO(Kernel_Vmm, "addr = {}, len = {:#x}, type = {:#x}, prot = {:#x}, flags = {:#x}", @@ -434,11 +434,11 @@ s32 PS4_SYSV_ABI sceKernelMemoryPoolCommit(void* addr, size_t len, int type, int s32 PS4_SYSV_ABI sceKernelMemoryPoolDecommit(void* addr, size_t len, int flags) { if (addr == nullptr) { LOG_ERROR(Kernel_Vmm, "Address is invalid!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } if (len == 0 || !Common::Is64KBAligned(len)) { LOG_ERROR(Kernel_Vmm, "Map size is either zero or not 64KB aligned!"); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } LOG_INFO(Kernel_Vmm, "addr = {}, len = {:#x}, flags = {:#x}", fmt::ptr(addr), len, flags); @@ -493,7 +493,7 @@ int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len) { } auto* memory = Core::Memory::Instance(); memory->UnmapMemory(std::bit_cast(addr), len); - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI posix_munmap(void* addr, size_t len) { diff --git a/src/core/libraries/kernel/orbis_error.h b/src/core/libraries/kernel/orbis_error.h new file mode 100644 index 00000000..d19b3f3f --- /dev/null +++ b/src/core/libraries/kernel/orbis_error.h @@ -0,0 +1,108 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/libraries/error_codes.h" + +// Libkernel library +constexpr int ORBIS_KERNEL_ERROR_UNKNOWN = 0x80020000; +constexpr int ORBIS_KERNEL_ERROR_EPERM = 0x80020001; +constexpr int ORBIS_KERNEL_ERROR_ENOENT = 0x80020002; +constexpr int ORBIS_KERNEL_ERROR_ESRCH = 0x80020003; +constexpr int ORBIS_KERNEL_ERROR_EINTR = 0x80020004; +constexpr int ORBIS_KERNEL_ERROR_EIO = 0x80020005; +constexpr int ORBIS_KERNEL_ERROR_ENXIO = 0x80020006; +constexpr int ORBIS_KERNEL_ERROR_E2BIG = 0x80020007; +constexpr int ORBIS_KERNEL_ERROR_ENOEXEC = 0x80020008; +constexpr int ORBIS_KERNEL_ERROR_EBADF = 0x80020009; +constexpr int ORBIS_KERNEL_ERROR_ECHILD = 0x8002000A; +constexpr int ORBIS_KERNEL_ERROR_EDEADLK = 0x8002000B; +constexpr int ORBIS_KERNEL_ERROR_ENOMEM = 0x8002000C; +constexpr int ORBIS_KERNEL_ERROR_EACCES = 0x8002000D; +constexpr int ORBIS_KERNEL_ERROR_EFAULT = 0x8002000E; +constexpr int ORBIS_KERNEL_ERROR_ENOTBLK = 0x8002000F; +constexpr int ORBIS_KERNEL_ERROR_EBUSY = 0x80020010; +constexpr int ORBIS_KERNEL_ERROR_EEXIST = 0x80020011; +constexpr int ORBIS_KERNEL_ERROR_EXDEV = 0x80020012; +constexpr int ORBIS_KERNEL_ERROR_ENODEV = 0x80020013; +constexpr int ORBIS_KERNEL_ERROR_ENOTDIR = 0x80020014; +constexpr int ORBIS_KERNEL_ERROR_EISDIR = 0x80020015; +constexpr int ORBIS_KERNEL_ERROR_EINVAL = 0x80020016; +constexpr int ORBIS_KERNEL_ERROR_ENFILE = 0x80020017; +constexpr int ORBIS_KERNEL_ERROR_EMFILE = 0x80020018; +constexpr int ORBIS_KERNEL_ERROR_ENOTTY = 0x80020019; +constexpr int ORBIS_KERNEL_ERROR_ETXTBSY = 0x8002001A; +constexpr int ORBIS_KERNEL_ERROR_EFBIG = 0x8002001B; +constexpr int ORBIS_KERNEL_ERROR_ENOSPC = 0x8002001C; +constexpr int ORBIS_KERNEL_ERROR_ESPIPE = 0x8002001D; +constexpr int ORBIS_KERNEL_ERROR_EROFS = 0x8002001E; +constexpr int ORBIS_KERNEL_ERROR_EMLINK = 0x8002001F; +constexpr int ORBIS_KERNEL_ERROR_EPIPE = 0x80020020; +constexpr int ORBIS_KERNEL_ERROR_EDOM = 0x80020021; +constexpr int ORBIS_KERNEL_ERROR_ERANGE = 0x80020022; +constexpr int ORBIS_KERNEL_ERROR_EAGAIN = 0x80020023; +constexpr int ORBIS_KERNEL_ERROR_EWOULDBLOCK = 0x80020023; +constexpr int ORBIS_KERNEL_ERROR_EINPROGRESS = 0x80020024; +constexpr int ORBIS_KERNEL_ERROR_EALREADY = 0x80020025; +constexpr int ORBIS_KERNEL_ERROR_ENOTSOCK = 0x80020026; +constexpr int ORBIS_KERNEL_ERROR_EDESTADDRREQ = 0x80020027; +constexpr int ORBIS_KERNEL_ERROR_EMSGSIZE = 0x80020028; +constexpr int ORBIS_KERNEL_ERROR_EPROTOTYPE = 0x80020029; +constexpr int ORBIS_KERNEL_ERROR_ENOPROTOOPT = 0x8002002A; +constexpr int ORBIS_KERNEL_ERROR_EPROTONOSUPPORT = 0x8002002B; +constexpr int ORBIS_KERNEL_ERROR_ESOCKTNOSUPPORT = 0x8002002C; +constexpr int ORBIS_KERNEL_ERROR_ENOTSUP = 0x8002002D; +constexpr int ORBIS_KERNEL_ERROR_EOPNOTSUPP = 0x8002002D; +constexpr int ORBIS_KERNEL_ERROR_EPFNOSUPPORT = 0x8002002E; +constexpr int ORBIS_KERNEL_ERROR_EAFNOSUPPORT = 0x8002002F; +constexpr int ORBIS_KERNEL_ERROR_EADDRINUSE = 0x80020030; +constexpr int ORBIS_KERNEL_ERROR_EADDRNOTAVAIL = 0x80020031; +constexpr int ORBIS_KERNEL_ERROR_ENETDOWN = 0x80020032; +constexpr int ORBIS_KERNEL_ERROR_ENETUNREACH = 0x80020033; +constexpr int ORBIS_KERNEL_ERROR_ENETRESET = 0x80020034; +constexpr int ORBIS_KERNEL_ERROR_ECONNABORTED = 0x80020035; +constexpr int ORBIS_KERNEL_ERROR_ECONNRESET = 0x80020036; +constexpr int ORBIS_KERNEL_ERROR_ENOBUFS = 0x80020037; +constexpr int ORBIS_KERNEL_ERROR_EISCONN = 0x80020038; +constexpr int ORBIS_KERNEL_ERROR_ENOTCONN = 0x80020039; +constexpr int ORBIS_KERNEL_ERROR_ESHUTDOWN = 0x8002003A; +constexpr int ORBIS_KERNEL_ERROR_ETOOMANYREFS = 0x8002003B; +constexpr int ORBIS_KERNEL_ERROR_ETIMEDOUT = 0x8002003C; +constexpr int ORBIS_KERNEL_ERROR_ECONNREFUSED = 0x8002003D; +constexpr int ORBIS_KERNEL_ERROR_ELOOP = 0x8002003E; +constexpr int ORBIS_KERNEL_ERROR_ENAMETOOLONG = 0x8002003F; +constexpr int ORBIS_KERNEL_ERROR_EHOSTDOWN = 0x80020040; +constexpr int ORBIS_KERNEL_ERROR_EHOSTUNREACH = 0x80020041; +constexpr int ORBIS_KERNEL_ERROR_ENOTEMPTY = 0x80020042; +constexpr int ORBIS_KERNEL_ERROR_EPROCLIM = 0x80020043; +constexpr int ORBIS_KERNEL_ERROR_EUSERS = 0x80020044; +constexpr int ORBIS_KERNEL_ERROR_EDQUOT = 0x80020045; +constexpr int ORBIS_KERNEL_ERROR_ESTALE = 0x80020046; +constexpr int ORBIS_KERNEL_ERROR_EREMOTE = 0x80020047; +constexpr int ORBIS_KERNEL_ERROR_EBADRPC = 0x80020048; +constexpr int ORBIS_KERNEL_ERROR_ERPCMISMATCH = 0x80020049; +constexpr int ORBIS_KERNEL_ERROR_EPROGUNAVAIL = 0x8002004A; +constexpr int ORBIS_KERNEL_ERROR_EPROGMISMATCH = 0x8002004B; +constexpr int ORBIS_KERNEL_ERROR_EPROCUNAVAIL = 0x8002004C; +constexpr int ORBIS_KERNEL_ERROR_ENOLCK = 0x8002004D; +constexpr int ORBIS_KERNEL_ERROR_ENOSYS = 0x8002004E; +constexpr int ORBIS_KERNEL_ERROR_EFTYPE = 0x8002004F; +constexpr int ORBIS_KERNEL_ERROR_EAUTH = 0x80020050; +constexpr int ORBIS_KERNEL_ERROR_ENEEDAUTH = 0x80020051; +constexpr int ORBIS_KERNEL_ERROR_EIDRM = 0x80020052; +constexpr int ORBIS_KERNEL_ERROR_ENOMSG = 0x80020053; +constexpr int ORBIS_KERNEL_ERROR_EOVERFLOW = 0x80020054; +constexpr int ORBIS_KERNEL_ERROR_ECANCELED = 0x80020055; +constexpr int ORBIS_KERNEL_ERROR_EILSEQ = 0x80020056; +constexpr int ORBIS_KERNEL_ERROR_ENOATTR = 0x80020057; +constexpr int ORBIS_KERNEL_ERROR_EDOOFUS = 0x80020058; +constexpr int ORBIS_KERNEL_ERROR_EBADMSG = 0x80020059; +constexpr int ORBIS_KERNEL_ERROR_EMULTIHOP = 0x8002005A; +constexpr int ORBIS_KERNEL_ERROR_ENOLINK = 0x8002005B; +constexpr int ORBIS_KERNEL_ERROR_EPROTO = 0x8002005C; +constexpr int ORBIS_KERNEL_ERROR_ENOTCAPABLE = 0x8002005D; +constexpr int ORBIS_KERNEL_ERROR_ECAPMODE = 0x8002005E; +constexpr int ORBIS_KERNEL_ERROR_ENOBLK = 0x8002005F; +constexpr int ORBIS_KERNEL_ERROR_EICV = 0x80020060; +constexpr int ORBIS_KERNEL_ERROR_ENOPLAYGOENT = 0x80020061; diff --git a/src/core/libraries/kernel/posix_error.h b/src/core/libraries/kernel/posix_error.h new file mode 100644 index 00000000..0f7cf3e5 --- /dev/null +++ b/src/core/libraries/kernel/posix_error.h @@ -0,0 +1,128 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/libraries/error_codes.h" + +// Posix error codes +constexpr int POSIX_EPERM = 1; +constexpr int POSIX_ENOENT = 2; +constexpr int POSIX_ESRCH = 3; +constexpr int POSIX_EINTR = 4; +constexpr int POSIX_EIO = 5; +constexpr int POSIX_ENXIO = 6; +constexpr int POSIX_E2BIG = 7; +constexpr int POSIX_ENOEXEC = 8; +constexpr int POSIX_EBADF = 9; +constexpr int POSIX_ECHILD = 10; +constexpr int POSIX_EDEADLK = 11; +constexpr int POSIX_ENOMEM = 12; +constexpr int POSIX_EACCES = 13; +constexpr int POSIX_EFAULT = 14; +constexpr int POSIX_ENOTBLK = 15; +constexpr int POSIX_EBUSY = 16; +constexpr int POSIX_EEXIST = 17; +constexpr int POSIX_EXDEV = 18; +constexpr int POSIX_ENODEV = 19; +constexpr int POSIX_ENOTDIR = 20; +constexpr int POSIX_EISDIR = 21; +constexpr int POSIX_EINVAL = 22; +constexpr int POSIX_ENFILE = 23; +constexpr int POSIX_EMFILE = 24; +constexpr int POSIX_ENOTTY = 25; +constexpr int POSIX_ETXTBSY = 26; +constexpr int POSIX_EFBIG = 27; +constexpr int POSIX_ENOSPC = 28; +constexpr int POSIX_ESPIPE = 29; +constexpr int POSIX_EROFS = 30; +constexpr int POSIX_EMLINK = 31; +constexpr int POSIX_EPIPE = 32; +constexpr int POSIX_EDOM = 33; +constexpr int POSIX_ERANGE = 34; +constexpr int POSIX_EAGAIN = 35; +constexpr int POSIX_EWOULDBLOCK = 35; +constexpr int POSIX_EINPROGRESS = 36; +constexpr int POSIX_EALREADY = 37; +constexpr int POSIX_ENOTSOCK = 38; +constexpr int POSIX_EDESTADDRREQ = 39; +constexpr int POSIX_EMSGSIZE = 40; +constexpr int POSIX_EPROTOTYPE = 41; +constexpr int POSIX_ENOPROTOOPT = 42; +constexpr int POSIX_EPROTONOSUPPORT = 43; +constexpr int POSIX_ESOCKTNOSUPPORT = 44; +constexpr int POSIX_EOPNOTSUPP = 45; +constexpr int POSIX_ENOTSUP = 45; +constexpr int POSIX_EPFNOSUPPORT = 46; +constexpr int POSIX_EAFNOSUPPORT = 47; +constexpr int POSIX_EADDRINUSE = 48; +constexpr int POSIX_EADDRNOTAVAIL = 49; +constexpr int POSIX_ENETDOWN = 50; +constexpr int POSIX_ENETUNREACH = 51; +constexpr int POSIX_ENETRESET = 52; +constexpr int POSIX_ECONNABORTED = 53; +constexpr int POSIX_ECONNRESET = 54; +constexpr int POSIX_ENOBUFS = 55; +constexpr int POSIX_EISCONN = 56; +constexpr int POSIX_ENOTCONN = 57; +constexpr int POSIX_ESHUTDOWN = 58; +constexpr int POSIX_ETOOMANYREFS = 59; +constexpr int POSIX_ETIMEDOUT = 60; +constexpr int POSIX_ECONNREFUSED = 61; +constexpr int POSIX_ELOOP = 62; +constexpr int POSIX_ENAMETOOLONG = 63; +constexpr int POSIX_EHOSTDOWN = 64; +constexpr int POSIX_EHOSTUNREACH = 65; +constexpr int POSIX_ENOTEMPTY = 66; +constexpr int POSIX_EPROCLIM = 67; +constexpr int POSIX_EUSERS = 68; +constexpr int POSIX_EDQUOT = 69; +constexpr int POSIX_ESTALE = 70; +constexpr int POSIX_EREMOTE = 71; +constexpr int POSIX_EBADRPC = 72; +constexpr int POSIX_ERPCMISMATCH = 73; +constexpr int POSIX_EPROGUNAVAIL = 74; +constexpr int POSIX_EPROGMISMATCH = 75; +constexpr int POSIX_EPROCUNAVAIL = 76; +constexpr int POSIX_ENOLCK = 77; +constexpr int POSIX_ENOSYS = 78; +constexpr int POSIX_EFTYPE = 79; +constexpr int POSIX_EAUTH = 80; +constexpr int POSIX_ENEEDAUTH = 81; +constexpr int POSIX_EIDRM = 82; +constexpr int POSIX_ENOMSG = 83; +constexpr int POSIX_EOVERFLOW = 84; +constexpr int POSIX_ECANCELED = 85; +constexpr int POSIX_EILSEQ = 86; +constexpr int POSIX_ENOATTR = 87; +constexpr int POSIX_EDOOFUS = 88; +constexpr int POSIX_EBADMSG = 89; +constexpr int POSIX_EMULTIHOP = 90; +constexpr int POSIX_ENOLINK = 91; +constexpr int POSIX_EPROTO = 92; +constexpr int POSIX_ENOTCAPABLE = 93; +constexpr int POSIX_ECAPMODE = 94; +constexpr int POSIX_ENOBLK = 95; +constexpr int POSIX_EICV = 96; +constexpr int POSIX_ENOPLAYGOENT = 97; +constexpr int POSIX_EREVOKE = 98; +constexpr int POSIX_ESDKVERSION = 99; +constexpr int POSIX_ESTART = 100; +constexpr int POSIX_ESTOP = 101; +constexpr int POSIX_EINVALID2MB = 102; +constexpr int POSIX_ELAST = 102; +constexpr int POSIX_EADHOC = 160; +constexpr int POSIX_EINACTIVEDISABLED = 163; +constexpr int POSIX_ENETNODATA = 164; +constexpr int POSIX_ENETDESC = 165; +constexpr int POSIX_ENETDESCTIMEDOUT = 166; +constexpr int POSIX_ENETINTR = 167; +constexpr int POSIX_ERETURN = 205; +constexpr int POSIX_EFPOS = 152; +constexpr int POSIX_ENODATA = 1040; +constexpr int POSIX_ENOSR = 1050; +constexpr int POSIX_ENOSTR = 1051; +constexpr int POSIX_ENOTRECOVERABLE = 1056; +constexpr int POSIX_EOTHER = 1062; +constexpr int POSIX_EOWNERDEAD = 1064; +constexpr int POSIX_ETIME = 1074; diff --git a/src/core/libraries/kernel/process.cpp b/src/core/libraries/kernel/process.cpp index fc1d6e13..15e4ff82 100644 --- a/src/core/libraries/kernel/process.cpp +++ b/src/core/libraries/kernel/process.cpp @@ -5,7 +5,7 @@ #include "common/elf_info.h" #include "common/logging/log.h" #include "core/file_sys/fs.h" -#include "core/libraries/error_codes.h" +#include "core/libraries/kernel/orbis_error.h" #include "core/libraries/kernel/process.h" #include "core/libraries/libs.h" #include "core/linker.h" @@ -91,7 +91,7 @@ s32 PS4_SYSV_ABI sceKernelGetModuleInfoForUnwind(VAddr addr, int flags, OrbisModuleInfoForUnwind* info) { if (flags >= 3) { std::memset(info, 0, sizeof(OrbisModuleInfoForUnwind)); - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } if (!info) { return ORBIS_KERNEL_ERROR_EFAULT; diff --git a/src/core/libraries/kernel/threads/condvar.cpp b/src/core/libraries/kernel/threads/condvar.cpp index 4437af96..cbe8f6ca 100644 --- a/src/core/libraries/kernel/threads/condvar.cpp +++ b/src/core/libraries/kernel/threads/condvar.cpp @@ -3,8 +3,8 @@ #include #include "common/assert.h" -#include "core/libraries/error_codes.h" #include "core/libraries/kernel/kernel.h" +#include "core/libraries/kernel/posix_error.h" #include "core/libraries/kernel/threads/pthread.h" #include "core/libraries/kernel/threads/sleepq.h" #include "core/libraries/libs.h" diff --git a/src/core/libraries/kernel/threads/event_flag.cpp b/src/core/libraries/kernel/threads/event_flag.cpp index b0f08b91..39925153 100644 --- a/src/core/libraries/kernel/threads/event_flag.cpp +++ b/src/core/libraries/kernel/threads/event_flag.cpp @@ -7,7 +7,7 @@ #include "common/assert.h" #include "common/logging/log.h" -#include "core/libraries/error_codes.h" +#include "core/libraries/kernel/orbis_error.h" #include "core/libraries/libs.h" namespace Libraries::Kernel { diff --git a/src/core/libraries/kernel/threads/mutex.cpp b/src/core/libraries/kernel/threads/mutex.cpp index fc0bf09b..4f11e32d 100644 --- a/src/core/libraries/kernel/threads/mutex.cpp +++ b/src/core/libraries/kernel/threads/mutex.cpp @@ -3,10 +3,9 @@ #include #include "common/assert.h" -#include "common/scope_exit.h" #include "common/types.h" -#include "core/libraries/error_codes.h" #include "core/libraries/kernel/kernel.h" +#include "core/libraries/kernel/posix_error.h" #include "core/libraries/kernel/threads/pthread.h" #include "core/libraries/libs.h" diff --git a/src/core/libraries/kernel/threads/pthread.cpp b/src/core/libraries/kernel/threads/pthread.cpp index 18ddcb9b..4629980c 100644 --- a/src/core/libraries/kernel/threads/pthread.cpp +++ b/src/core/libraries/kernel/threads/pthread.cpp @@ -4,8 +4,8 @@ #include "common/assert.h" #include "common/thread.h" #include "core/debug_state.h" -#include "core/libraries/error_codes.h" #include "core/libraries/kernel/kernel.h" +#include "core/libraries/kernel/posix_error.h" #include "core/libraries/kernel/threads/pthread.h" #include "core/libraries/kernel/threads/thread_state.h" #include "core/libraries/libs.h" @@ -380,7 +380,7 @@ int PS4_SYSV_ABI posix_sched_get_priority_min() { int PS4_SYSV_ABI posix_pthread_rename_np(PthreadT thread, const char* name) { LOG_INFO(Kernel_Pthread, "name = {}", name); thread->name = name; - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI posix_pthread_getschedparam(PthreadT pthread, SchedPolicy* policy, diff --git a/src/core/libraries/kernel/threads/pthread_attr.cpp b/src/core/libraries/kernel/threads/pthread_attr.cpp index ead0ff7d..a8e60ccf 100644 --- a/src/core/libraries/kernel/threads/pthread_attr.cpp +++ b/src/core/libraries/kernel/threads/pthread_attr.cpp @@ -1,8 +1,8 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "core/libraries/error_codes.h" #include "core/libraries/kernel/kernel.h" +#include "core/libraries/kernel/posix_error.h" #include "core/libraries/kernel/threads/pthread.h" #include "core/libraries/kernel/threads/thread_state.h" #include "core/libraries/libs.h" diff --git a/src/core/libraries/kernel/threads/pthread_spec.cpp b/src/core/libraries/kernel/threads/pthread_spec.cpp index f0803b67..9e625da3 100644 --- a/src/core/libraries/kernel/threads/pthread_spec.cpp +++ b/src/core/libraries/kernel/threads/pthread_spec.cpp @@ -1,9 +1,8 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "common/assert.h" -#include "core/libraries/error_codes.h" #include "core/libraries/kernel/kernel.h" +#include "core/libraries/kernel/posix_error.h" #include "core/libraries/kernel/threads/pthread.h" #include "core/libraries/libs.h" diff --git a/src/core/libraries/kernel/threads/rwlock.cpp b/src/core/libraries/kernel/threads/rwlock.cpp index 2d5a4cdb..affaaf99 100644 --- a/src/core/libraries/kernel/threads/rwlock.cpp +++ b/src/core/libraries/kernel/threads/rwlock.cpp @@ -1,8 +1,8 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "core/libraries/error_codes.h" #include "core/libraries/kernel/kernel.h" +#include "core/libraries/kernel/posix_error.h" #include "core/libraries/kernel/threads/pthread.h" #include "core/libraries/libs.h" diff --git a/src/core/libraries/kernel/threads/semaphore.cpp b/src/core/libraries/kernel/threads/semaphore.cpp index db14c298..e3c7e909 100644 --- a/src/core/libraries/kernel/threads/semaphore.cpp +++ b/src/core/libraries/kernel/threads/semaphore.cpp @@ -5,9 +5,11 @@ #include #include #include + #include "common/logging/log.h" -#include "core/libraries/error_codes.h" #include "core/libraries/kernel/kernel.h" +#include "core/libraries/kernel/orbis_error.h" +#include "core/libraries/kernel/posix_error.h" #include "core/libraries/kernel/threads/pthread.h" #include "core/libraries/kernel/time.h" #include "core/libraries/libs.h" @@ -41,7 +43,7 @@ public: } if (timeout && *timeout == 0) { - return SCE_KERNEL_ERROR_ETIMEDOUT; + return ORBIS_KERNEL_ERROR_ETIMEDOUT; } // Create waiting thread object and add it into the list of waiters. @@ -50,7 +52,7 @@ public: // Perform the wait. const s32 result = waiter.Wait(lk, timeout); - if (result == SCE_KERNEL_ERROR_ETIMEDOUT) { + if (result == ORBIS_KERNEL_ERROR_ETIMEDOUT) { wait_list.erase(it); } return result; @@ -120,15 +122,15 @@ public: int GetResult(bool timed_out) { if (timed_out) { - return SCE_KERNEL_ERROR_ETIMEDOUT; + return ORBIS_KERNEL_ERROR_ETIMEDOUT; } if (was_deleted) { - return SCE_KERNEL_ERROR_EACCES; + return ORBIS_KERNEL_ERROR_EACCES; } if (was_cancled) { - return SCE_KERNEL_ERROR_ECANCELED; + return ORBIS_KERNEL_ERROR_ECANCELED; } - return SCE_OK; + return ORBIS_OK; } int Wait(std::unique_lock& lk, u32* timeout) { @@ -223,13 +225,13 @@ int PS4_SYSV_ABI sceKernelCancelSema(OrbisKernelSema sem, s32 setCount, s32* pNu int PS4_SYSV_ABI sceKernelDeleteSema(OrbisKernelSema sem) { if (!sem) { - return SCE_KERNEL_ERROR_ESRCH; + return ORBIS_KERNEL_ERROR_ESRCH; } sem->Delete(); return ORBIS_OK; } -int PS4_SYSV_ABI posix_sem_init(PthreadSem** sem, int pshared, unsigned int value) { +int PS4_SYSV_ABI posix_sem_init(PthreadSem** sem, int pshared, u32 value) { if (value > ORBIS_KERNEL_SEM_VALUE_MAX) { *__Error() = POSIX_EINVAL; return -1; diff --git a/src/core/libraries/kernel/threads/sleepq.h b/src/core/libraries/kernel/threads/sleepq.h index 9274942e..5dc37645 100644 --- a/src/core/libraries/kernel/threads/sleepq.h +++ b/src/core/libraries/kernel/threads/sleepq.h @@ -2,14 +2,13 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include -#include #include #include -#include "common/types.h" namespace Libraries::Kernel { struct Pthread; +struct SleepQueue; using ListBaseHook = boost::intrusive::list_base_hook>; @@ -17,7 +16,7 @@ using ListBaseHook = using SleepqList = boost::intrusive::list>; struct SleepQueue : public ListBaseHook { - std::list sq_blocked; + std::forward_list sq_blocked; SleepqList sq_freeq; void* sq_wchan; int sq_type; @@ -35,4 +34,4 @@ int SleepqRemove(SleepQueue* sq, Pthread* td); void SleepqDrop(SleepQueue* sq, void (*callback)(Pthread*, void*), void* arg); -} // namespace Libraries::Kernel \ No newline at end of file +} // namespace Libraries::Kernel diff --git a/src/core/libraries/kernel/threads/thread_state.cpp b/src/core/libraries/kernel/threads/thread_state.cpp index e968c39a..6c2d4d7e 100644 --- a/src/core/libraries/kernel/threads/thread_state.cpp +++ b/src/core/libraries/kernel/threads/thread_state.cpp @@ -4,7 +4,7 @@ #include #include "common/alignment.h" #include "common/scope_exit.h" -#include "core/libraries/error_codes.h" +#include "core/libraries/kernel/posix_error.h" #include "core/libraries/kernel/threads/pthread.h" #include "core/libraries/kernel/threads/sleepq.h" #include "core/libraries/kernel/threads/thread_state.h" diff --git a/src/core/libraries/kernel/time.cpp b/src/core/libraries/kernel/time.cpp index 76ea5e35..b586431a 100644 --- a/src/core/libraries/kernel/time.cpp +++ b/src/core/libraries/kernel/time.cpp @@ -5,7 +5,7 @@ #include "common/assert.h" #include "common/native_clock.h" -#include "core/libraries/error_codes.h" +#include "core/libraries/kernel/orbis_error.h" #include "core/libraries/kernel/time.h" #include "core/libraries/libs.h" @@ -80,7 +80,7 @@ u32 PS4_SYSV_ABI sceKernelSleep(u32 seconds) { int PS4_SYSV_ABI sceKernelClockGettime(s32 clock_id, OrbisKernelTimespec* tp) { if (tp == nullptr) { - return SCE_KERNEL_ERROR_EFAULT; + return ORBIS_KERNEL_ERROR_EFAULT; } clockid_t pclock_id = CLOCK_REALTIME; switch (clock_id) { @@ -105,9 +105,9 @@ int PS4_SYSV_ABI sceKernelClockGettime(s32 clock_id, OrbisKernelTimespec* tp) { tp->tv_sec = t.tv_sec; tp->tv_nsec = t.tv_nsec; if (result == 0) { - return SCE_OK; + return ORBIS_OK; } - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } int PS4_SYSV_ABI posix_clock_gettime(s32 clock_id, OrbisKernelTimespec* time) { @@ -126,11 +126,11 @@ int PS4_SYSV_ABI posix_nanosleep(const OrbisKernelTimespec* rqtp, OrbisKernelTim int PS4_SYSV_ABI sceKernelNanosleep(const OrbisKernelTimespec* rqtp, OrbisKernelTimespec* rmtp) { if (!rqtp || !rmtp) { - return SCE_KERNEL_ERROR_EFAULT; + return ORBIS_KERNEL_ERROR_EFAULT; } if (rqtp->tv_sec < 0 || rqtp->tv_nsec < 0) { - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } return posix_nanosleep(rqtp, rmtp); @@ -197,7 +197,7 @@ s32 PS4_SYSV_ABI sceKernelGettimezone(OrbisKernelTimezone* tz) { int PS4_SYSV_ABI posix_clock_getres(u32 clock_id, OrbisKernelTimespec* res) { if (res == nullptr) { - return SCE_KERNEL_ERROR_EFAULT; + return ORBIS_KERNEL_ERROR_EFAULT; } clockid_t pclock_id = CLOCK_REALTIME; switch (clock_id) { @@ -221,9 +221,9 @@ int PS4_SYSV_ABI posix_clock_getres(u32 clock_id, OrbisKernelTimespec* res) { res->tv_sec = t.tv_sec; res->tv_nsec = t.tv_nsec; if (result == 0) { - return SCE_OK; + return ORBIS_OK; } - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } int PS4_SYSV_ABI sceKernelConvertLocaltimeToUtc(time_t param_1, int64_t param_2, time_t* seconds, @@ -237,9 +237,9 @@ int PS4_SYSV_ABI sceKernelConvertLocaltimeToUtc(time_t param_1, int64_t param_2, if (dst_seconds) *dst_seconds = timezone->tz_dsttime * 60; } else { - return SCE_KERNEL_ERROR_EINVAL; + return ORBIS_KERNEL_ERROR_EINVAL; } - return SCE_OK; + return ORBIS_OK; } namespace Dev { @@ -254,7 +254,7 @@ Common::NativeClock* GetClock() { } // namespace Dev int PS4_SYSV_ABI sceKernelConvertUtcToLocaltime(time_t time, time_t* local_time, - struct OrbisTimesec* st, unsigned long* dst_sec) { + struct OrbisTimesec* st, u64* dst_sec) { LOG_TRACE(Kernel, "Called"); #ifdef __APPLE__ // std::chrono::current_zone() not available yet. diff --git a/src/core/libraries/kernel/time.h b/src/core/libraries/kernel/time.h index 508ef215..6aa281aa 100644 --- a/src/core/libraries/kernel/time.h +++ b/src/core/libraries/kernel/time.h @@ -81,7 +81,7 @@ int PS4_SYSV_ABI sceKernelConvertLocaltimeToUtc(time_t param_1, int64_t param_2, OrbisKernelTimezone* timezone, int* dst_seconds); int PS4_SYSV_ABI sceKernelConvertUtcToLocaltime(time_t time, time_t* local_time, OrbisTimesec* st, - unsigned long* dst_sec); + u64* dst_sec); void RegisterTime(Core::Loader::SymbolsResolver* sym); diff --git a/src/core/libraries/libpng/pngdec.cpp b/src/core/libraries/libpng/pngdec.cpp index fb9fae4d..d6f291a6 100644 --- a/src/core/libraries/libpng/pngdec.cpp +++ b/src/core/libraries/libpng/pngdec.cpp @@ -4,9 +4,9 @@ #include #include "common/assert.h" #include "common/logging/log.h" -#include "core/libraries/error_codes.h" +#include "core/libraries/libpng/pngdec.h" +#include "core/libraries/libpng/pngdec_error.h" #include "core/libraries/libs.h" -#include "pngdec.h" namespace Libraries::PngDec { @@ -15,24 +15,25 @@ struct PngHandler { png_infop info_ptr; }; +struct PngStruct { + const u8* data; + size_t size; + u64 offset; +}; + static inline OrbisPngDecColorSpace MapPngColor(int color) { switch (color) { case PNG_COLOR_TYPE_GRAY: - return OrbisPngDecColorSpace::ORBIS_PNG_DEC_COLOR_SPACE_GRAYSCALE; - + return OrbisPngDecColorSpace::Grayscale; case PNG_COLOR_TYPE_GRAY_ALPHA: - return OrbisPngDecColorSpace::ORBIS_PNG_DEC_COLOR_SPACE_GRAYSCALE_ALPHA; - + return OrbisPngDecColorSpace::GrayscaleAlpha; case PNG_COLOR_TYPE_PALETTE: - return OrbisPngDecColorSpace::ORBIS_PNG_DEC_COLOR_SPACE_CLUT; - + return OrbisPngDecColorSpace::Clut; case PNG_COLOR_TYPE_RGB: - return OrbisPngDecColorSpace::ORBIS_PNG_DEC_COLOR_SPACE_RGB; - + return OrbisPngDecColorSpace::Rgb; case PNG_COLOR_TYPE_RGB_ALPHA: - return OrbisPngDecColorSpace::ORBIS_PNG_DEC_COLOR_SPACE_RGBA; + return OrbisPngDecColorSpace::Rgba; } - UNREACHABLE_MSG("unknown png color type"); } @@ -54,8 +55,8 @@ s32 PS4_SYSV_ABI scePngDecCreate(const OrbisPngDecCreateParam* param, void* memo LOG_ERROR(Lib_Png, "Invalid memory address!"); return ORBIS_PNG_DEC_ERROR_INVALID_ADDR; } - if (param->maxImageWidth - 1 > 1000000) { - LOG_ERROR(Lib_Png, "Invalid size! width = {}", param->maxImageWidth); + if (param->max_image_width - 1 > 1000000) { + LOG_ERROR(Lib_Png, "Invalid size! width = {}", param->max_image_width); return ORBIS_PNG_DEC_ERROR_INVALID_SIZE; } auto pngh = (PngHandler*)memoryAddress; @@ -86,7 +87,7 @@ s32 PS4_SYSV_ABI scePngDecDecode(OrbisPngDecHandle handle, const OrbisPngDecDeco LOG_ERROR(Lib_Png, "Invalid param!"); return ORBIS_PNG_DEC_ERROR_INVALID_PARAM; } - if (param->pngMemAddr == nullptr || param->pngMemAddr == nullptr) { + if (param->png_mem_addr == nullptr || param->image_mem_addr == nullptr) { LOG_ERROR(Lib_Png, "invalid image address!"); return ORBIS_PNG_DEC_ERROR_INVALID_ADDR; } @@ -98,76 +99,74 @@ s32 PS4_SYSV_ABI scePngDecDecode(OrbisPngDecHandle handle, const OrbisPngDecDeco auto pngh = (PngHandler*)handle; - struct pngstruct { - const u8* data; - size_t size; - u64 offset; - } pngdata = { - .data = (const u8*)param->pngMemAddr, - .size = param->pngMemSize, + const auto pngdata = PngStruct{ + .data = param->png_mem_addr, + .size = param->png_mem_size, .offset = 0, }; - - // Read png from memory png_set_read_fn(pngh->png_ptr, (void*)&pngdata, [](png_structp ps, png_bytep data, png_size_t len) { if (len == 0) return; - auto pngdata = (pngstruct*)png_get_io_ptr(ps); + auto pngdata = (PngStruct*)png_get_io_ptr(ps); ::memcpy(data, pngdata->data + pngdata->offset, len); pngdata->offset += len; }); - u32 width, height; - int color_type, bit_depth; png_read_info(pngh->png_ptr, pngh->info_ptr); - - width = png_get_image_width(pngh->png_ptr, pngh->info_ptr); - height = png_get_image_height(pngh->png_ptr, pngh->info_ptr); - color_type = MapPngColor(png_get_color_type(pngh->png_ptr, pngh->info_ptr)); - bit_depth = png_get_bit_depth(pngh->png_ptr, pngh->info_ptr); + const u32 width = png_get_image_width(pngh->png_ptr, pngh->info_ptr); + const u32 height = png_get_image_height(pngh->png_ptr, pngh->info_ptr); + const auto color_type = MapPngColor(png_get_color_type(pngh->png_ptr, pngh->info_ptr)); + const auto bit_depth = png_get_bit_depth(pngh->png_ptr, pngh->info_ptr); if (imageInfo != nullptr) { - imageInfo->bitDepth = bit_depth; - imageInfo->imageWidth = width; - imageInfo->imageHeight = height; - imageInfo->colorSpace = color_type; - imageInfo->imageFlag = 0; + imageInfo->bit_depth = bit_depth; + imageInfo->image_width = width; + imageInfo->image_height = height; + imageInfo->color_space = color_type; + imageInfo->image_flag = OrbisPngDecImageFlag::None; if (png_get_interlace_type(pngh->png_ptr, pngh->info_ptr) == 1) { - imageInfo->imageFlag |= OrbisPngDecImageFlag::ORBIS_PNG_DEC_IMAGE_FLAG_ADAM7_INTERLACE; + imageInfo->image_flag |= OrbisPngDecImageFlag::Adam7Interlace; } if (png_get_valid(pngh->png_ptr, pngh->info_ptr, PNG_INFO_tRNS)) { - - imageInfo->imageFlag |= ORBIS_PNG_DEC_IMAGE_FLAG_TRNS_CHUNK_EXIST; + imageInfo->image_flag |= OrbisPngDecImageFlag::TrnsChunkExist; } } - if (bit_depth == 16) + if (bit_depth == 16) { png_set_strip_16(pngh->png_ptr); - if (color_type == PNG_COLOR_TYPE_PALETTE) + } + if (color_type == OrbisPngDecColorSpace::Clut) { png_set_palette_to_rgb(pngh->png_ptr); - if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) + } + if (color_type == OrbisPngDecColorSpace::Grayscale && bit_depth < 8) { png_set_expand_gray_1_2_4_to_8(pngh->png_ptr); - if (png_get_valid(pngh->png_ptr, pngh->info_ptr, PNG_INFO_tRNS)) + } + if (png_get_valid(pngh->png_ptr, pngh->info_ptr, PNG_INFO_tRNS)) { png_set_tRNS_to_alpha(pngh->png_ptr); - if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + } + if (color_type == OrbisPngDecColorSpace::Grayscale || + color_type == OrbisPngDecColorSpace::GrayscaleAlpha) { png_set_gray_to_rgb(pngh->png_ptr); - if (param->pixelFormat == OrbisPngDecPixelFormat::ORBIS_PNG_DEC_PIXEL_FORMAT_B8G8R8A8) + } + if (param->pixel_format == OrbisPngDecPixelFormat::B8G8R8A8) { png_set_bgr(pngh->png_ptr); - if (color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_GRAY || - color_type == PNG_COLOR_TYPE_PALETTE) - png_set_add_alpha(pngh->png_ptr, param->alphaValue, PNG_FILLER_AFTER); + } + if (color_type == OrbisPngDecColorSpace::Rgb || + color_type == OrbisPngDecColorSpace::Grayscale || + color_type == OrbisPngDecColorSpace::Clut) { + png_set_add_alpha(pngh->png_ptr, param->alpha_value, PNG_FILLER_AFTER); + } - int pass = png_set_interlace_handling(pngh->png_ptr); + const s32 pass = png_set_interlace_handling(pngh->png_ptr); png_read_update_info(pngh->png_ptr, pngh->info_ptr); - auto const numChannels = png_get_channels(pngh->png_ptr, pngh->info_ptr); - auto horizontal_bytes = numChannels * width; + const s32 num_channels = png_get_channels(pngh->png_ptr, pngh->info_ptr); + const s32 horizontal_bytes = num_channels * width; + const s32 stride = param->image_pitch > 0 ? param->image_pitch : horizontal_bytes; - int stride = param->imagePitch > 0 ? param->imagePitch : horizontal_bytes; - - for (int j = 0; j < pass; j++) { // interlaced - auto ptr = (png_bytep)param->imageMemAddr; + for (int j = 0; j < pass; j++) { + auto ptr = reinterpret_cast(param->image_mem_addr); for (int y = 0; y < height; y++) { png_read_row(pngh->png_ptr, ptr, nullptr); ptr += stride; @@ -196,7 +195,7 @@ s32 PS4_SYSV_ABI scePngDecParseHeader(const OrbisPngDecParseParam* param, } u8 header[8]; - memcpy(header, param->pngMemAddr, 8); + memcpy(header, param->png_mem_addr, 8); // Check if the header indicates a valid PNG file if (png_sig_cmp(header, 0, 8)) { LOG_ERROR(Lib_Png, "Memory doesn't contain a valid png file"); @@ -209,18 +208,14 @@ s32 PS4_SYSV_ABI scePngDecParseHeader(const OrbisPngDecParseParam* param, // Create a libpng info structure auto info_ptr = png_create_info_struct(png_ptr); - struct pngstruct { - const u8* data; - size_t size; - u64 offset; - } pngdata = { - .data = (const u8*)param->pngMemAddr, - .size = param->pngMemSize, + const auto pngdata = PngStruct{ + .data = param->png_mem_addr, + .size = param->png_mem_size, .offset = 0, }; png_set_read_fn(png_ptr, (void*)&pngdata, [](png_structp ps, png_bytep data, png_size_t len) { - auto pngdata = (pngstruct*)png_get_io_ptr(ps); + auto pngdata = (PngStruct*)png_get_io_ptr(ps); ::memcpy(data, pngdata->data + pngdata->offset, len); pngdata->offset += len; }); @@ -229,17 +224,16 @@ s32 PS4_SYSV_ABI scePngDecParseHeader(const OrbisPngDecParseParam* param, // info. png_read_info(png_ptr, info_ptr); - imageInfo->imageWidth = png_get_image_width(png_ptr, info_ptr); - imageInfo->imageHeight = png_get_image_height(png_ptr, info_ptr); - imageInfo->colorSpace = MapPngColor(png_get_color_type(png_ptr, info_ptr)); - imageInfo->bitDepth = png_get_bit_depth(png_ptr, info_ptr); - imageInfo->imageFlag = 0; + imageInfo->image_width = png_get_image_width(png_ptr, info_ptr); + imageInfo->image_height = png_get_image_height(png_ptr, info_ptr); + imageInfo->color_space = MapPngColor(png_get_color_type(png_ptr, info_ptr)); + imageInfo->bit_depth = png_get_bit_depth(png_ptr, info_ptr); + imageInfo->image_flag = OrbisPngDecImageFlag::None; if (png_get_interlace_type(png_ptr, info_ptr) == 1) { - imageInfo->imageFlag |= OrbisPngDecImageFlag::ORBIS_PNG_DEC_IMAGE_FLAG_ADAM7_INTERLACE; + imageInfo->image_flag |= OrbisPngDecImageFlag::Adam7Interlace; } if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { - - imageInfo->imageFlag |= ORBIS_PNG_DEC_IMAGE_FLAG_TRNS_CHUNK_EXIST; + imageInfo->image_flag |= OrbisPngDecImageFlag::TrnsChunkExist; } png_destroy_read_struct(&png_ptr, &info_ptr, nullptr); @@ -260,8 +254,8 @@ s32 PS4_SYSV_ABI scePngDecQueryMemorySize(const OrbisPngDecCreateParam* param) { LOG_ERROR(Lib_Png, "Invalid attribute! attribute = {}", param->attribute); return ORBIS_PNG_DEC_ERROR_INVALID_ADDR; } - if (param->maxImageWidth - 1 > 1000000) { - LOG_ERROR(Lib_Png, "Invalid size! width = {}", param->maxImageWidth); + if (param->max_image_width - 1 > 1000000) { + LOG_ERROR(Lib_Png, "Invalid size! width = {}", param->max_image_width); return ORBIS_PNG_DEC_ERROR_INVALID_SIZE; } return sizeof(PngHandler); @@ -279,4 +273,4 @@ void RegisterlibScePngDec(Core::Loader::SymbolsResolver* sym) { scePngDecDecodeWithInputControl); }; -} // namespace Libraries::PngDec \ No newline at end of file +} // namespace Libraries::PngDec diff --git a/src/core/libraries/libpng/pngdec.h b/src/core/libraries/libpng/pngdec.h index 9d807166..c897d7c9 100644 --- a/src/core/libraries/libpng/pngdec.h +++ b/src/core/libraries/libpng/pngdec.h @@ -3,6 +3,7 @@ #pragma once +#include "common/enum.h" #include "common/types.h" namespace Core::Loader { @@ -11,59 +12,61 @@ class SymbolsResolver; namespace Libraries::PngDec { -enum OrbisPngDecColorSpace { - ORBIS_PNG_DEC_COLOR_SPACE_GRAYSCALE = 2, - ORBIS_PNG_DEC_COLOR_SPACE_RGB, - ORBIS_PNG_DEC_COLOR_SPACE_CLUT, - ORBIS_PNG_DEC_COLOR_SPACE_GRAYSCALE_ALPHA = 18, - ORBIS_PNG_DEC_COLOR_SPACE_RGBA +enum class OrbisPngDecColorSpace : u16 { + Grayscale = 2, + Rgb, + Clut, + GrayscaleAlpha = 18, + Rgba, }; -enum OrbisPngDecImageFlag { - ORBIS_PNG_DEC_IMAGE_FLAG_ADAM7_INTERLACE = 1, - ORBIS_PNG_DEC_IMAGE_FLAG_TRNS_CHUNK_EXIST = 2 +enum class OrbisPngDecImageFlag : u32 { + None = 0, + Adam7Interlace = 1, + TrnsChunkExist = 2, +}; +DECLARE_ENUM_FLAG_OPERATORS(OrbisPngDecImageFlag) + +enum class OrbisPngDecPixelFormat : u16 { + R8G8B8A8 = 0, + B8G8R8A8, }; -enum OrbisPngDecPixelFormat { - ORBIS_PNG_DEC_PIXEL_FORMAT_R8G8B8A8 = 0, - ORBIS_PNG_DEC_PIXEL_FORMAT_B8G8R8A8 -}; - -enum OrbisPngDecAttribute { - ORBIS_PNG_DEC_ATTRIBUTE_NONE = 0, - ORBIS_PNG_DEC_ATTRIBUTE_BIT_DEPTH_16 +enum class OrbisPngDecAttribute { + None = 0, + BitDepth16, }; struct OrbisPngDecParseParam { - const void* pngMemAddr; - u32 pngMemSize; + const u8* png_mem_addr; + u32 png_mem_size; u32 reserved; }; struct OrbisPngDecImageInfo { - u32 imageWidth; - u32 imageHeight; - u16 colorSpace; - u16 bitDepth; - u32 imageFlag; + u32 image_width; + u32 image_height; + OrbisPngDecColorSpace color_space; + u16 bit_depth; + OrbisPngDecImageFlag image_flag; }; struct OrbisPngDecCreateParam { - u32 thisSize; + u32 this_size; u32 attribute; - u32 maxImageWidth; + u32 max_image_width; }; -typedef void* OrbisPngDecHandle; +using OrbisPngDecHandle = void*; struct OrbisPngDecDecodeParam { - const void* pngMemAddr; - void* imageMemAddr; - u32 pngMemSize; - u32 imageMemSize; - u16 pixelFormat; - u16 alphaValue; - u32 imagePitch; + const u8* png_mem_addr; + u8* image_mem_addr; + u32 png_mem_size; + u32 image_mem_size; + OrbisPngDecPixelFormat pixel_format; + u16 alpha_value; + u32 image_pitch; }; s32 PS4_SYSV_ABI scePngDecCreate(const OrbisPngDecCreateParam* param, void* memoryAddress, @@ -77,4 +80,4 @@ s32 PS4_SYSV_ABI scePngDecParseHeader(const OrbisPngDecParseParam* param, s32 PS4_SYSV_ABI scePngDecQueryMemorySize(const OrbisPngDecCreateParam* param); void RegisterlibScePngDec(Core::Loader::SymbolsResolver* sym); -} // namespace Libraries::PngDec \ No newline at end of file +} // namespace Libraries::PngDec diff --git a/src/core/libraries/libpng/pngdec_error.h b/src/core/libraries/libpng/pngdec_error.h new file mode 100644 index 00000000..9745ed5d --- /dev/null +++ b/src/core/libraries/libpng/pngdec_error.h @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/libraries/error_codes.h" + +// PngDec library +constexpr int ORBIS_PNG_DEC_ERROR_INVALID_ADDR = 0x80690001; +constexpr int ORBIS_PNG_DEC_ERROR_INVALID_SIZE = 0x80690002; +constexpr int ORBIS_PNG_DEC_ERROR_INVALID_PARAM = 0x80690003; +constexpr int ORBIS_PNG_DEC_ERROR_INVALID_HANDLE = 0x80690004; +constexpr int ORBIS_PNG_DEC_ERROR_INVALID_WORK_MEMORY = 0x80690005; +constexpr int ORBIS_PNG_DEC_ERROR_INVALID_DATA = 0x80690010; +constexpr int ORBIS_PNG_DEC_ERROR_UNSUPPORT_DATA = 0x80690011; +constexpr int ORBIS_PNG_DEC_ERROR_DECODE_ERROR = 0x80690012; +constexpr int ORBIS_PNG_DEC_ERROR_FATAL = 0x80690020; diff --git a/src/core/libraries/network/netctl.h b/src/core/libraries/network/netctl.h index 4482729a..4992fffa 100644 --- a/src/core/libraries/network/netctl.h +++ b/src/core/libraries/network/netctl.h @@ -23,7 +23,7 @@ constexpr int ORBIS_NET_CTL_HOSTNAME_LEN = 255 + 1; constexpr int ORBIS_NET_CTL_AUTH_NAME_LEN = 127 + 1; constexpr int ORBIS_NET_CTL_IPV4_ADDR_STR_LEN = 16; -typedef union OrbisNetCtlInfo { +union OrbisNetCtlInfo { u32 device; OrbisNetEtherAddr ether_addr; u32 mtu; @@ -45,7 +45,7 @@ typedef union OrbisNetCtlInfo { u32 http_proxy_config; char http_proxy_server[ORBIS_NET_CTL_HOSTNAME_LEN]; u16 http_proxy_port; -} SceNetCtlInfo; +}; // GetInfo codes constexpr int ORBIS_NET_CTL_INFO_DEVICE = 1; diff --git a/src/core/libraries/ngs2/ngs2.cpp b/src/core/libraries/ngs2/ngs2.cpp index b66c9b15..7eb66341 100644 --- a/src/core/libraries/ngs2/ngs2.cpp +++ b/src/core/libraries/ngs2/ngs2.cpp @@ -1,13 +1,12 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "ngs2.h" -#include "ngs2_error.h" -#include "ngs2_impl.h" - #include "common/logging/log.h" #include "core/libraries/error_codes.h" #include "core/libraries/libs.h" +#include "core/libraries/ngs2/ngs2.h" +#include "core/libraries/ngs2/ngs2_error.h" +#include "core/libraries/ngs2/ngs2_impl.h" namespace Libraries::Ngs2 { @@ -416,4 +415,4 @@ void RegisterlibSceNgs2(Core::Loader::SymbolsResolver* sym) { LIB_FUNCTION("AbYvTOZ8Pts", "libSceNgs2", 1, "libSceNgs2", 1, 1, sceNgs2VoiceRunCommands); }; -} // namespace Libraries::Ngs2 \ No newline at end of file +} // namespace Libraries::Ngs2 diff --git a/src/core/libraries/ngs2/ngs2.h b/src/core/libraries/ngs2/ngs2.h index 0df83f56..a5f1f52a 100644 --- a/src/core/libraries/ngs2/ngs2.h +++ b/src/core/libraries/ngs2/ngs2.h @@ -3,10 +3,8 @@ #pragma once -#include "common/types.h" - #include -#include +#include "common/types.h" namespace Core::Loader { class SymbolsResolver; @@ -18,7 +16,9 @@ class Ngs2; using SceNgs2Handle = Ngs2*; -enum SceNgs2HandleType { SCE_NGS2_HANDLE_TYPE_SYSTEM = 0 }; +enum class SceNgs2HandleType : u32 { + System = 0, +}; struct Ngs2Handle { void* selfPointer; @@ -69,4 +69,5 @@ struct StackBuffer { }; void RegisterlibSceNgs2(Core::Loader::SymbolsResolver* sym); -} // namespace Libraries::Ngs2 \ No newline at end of file + +} // namespace Libraries::Ngs2 diff --git a/src/core/libraries/np_manager/np_manager.cpp b/src/core/libraries/np_manager/np_manager.cpp index 00070ef8..ec9cc6bf 100644 --- a/src/core/libraries/np_manager/np_manager.cpp +++ b/src/core/libraries/np_manager/np_manager.cpp @@ -971,12 +971,11 @@ int PS4_SYSV_ABI sceNpGetGamePresenceStatusA() { return ORBIS_OK; } -int PS4_SYSV_ABI sceNpGetNpId(OrbisUserServiceUserId userId, OrbisNpId* npId) { - LOG_INFO(Lib_NpManager, "userId {}", userId); - std::string name = Config::getUserName(); - // Fill the unused stuffs to 0 - memset(npId, 0, sizeof(*npId)); - strcpy(npId->handle.data, name.c_str()); +int PS4_SYSV_ABI sceNpGetNpId(OrbisUserServiceUserId user_id, OrbisNpId* np_id) { + LOG_INFO(Lib_NpManager, "user_id {}", user_id); + const auto name = Config::getUserName(); + std::memset(np_id, 0, sizeof(OrbisNpId)); + name.copy(np_id->handle.data, sizeof(np_id->handle.data)); return ORBIS_OK; } @@ -985,12 +984,11 @@ int PS4_SYSV_ABI sceNpGetNpReachabilityState() { return ORBIS_OK; } -int PS4_SYSV_ABI sceNpGetOnlineId(s32 userId, OrbisNpOnlineId* onlineId) { - LOG_DEBUG(Lib_NpManager, "userId {}", userId); - std::string name = Config::getUserName(); - // Fill the unused stuffs to 0 - memset(onlineId, 0, sizeof(*onlineId)); - strcpy(onlineId->data, name.c_str()); +int PS4_SYSV_ABI sceNpGetOnlineId(s32 user_id, OrbisNpOnlineId* online_id) { + LOG_DEBUG(Lib_NpManager, "user_id {}", user_id); + const auto name = Config::getUserName(); + std::memset(online_id, 0, sizeof(OrbisNpOnlineId)); + name.copy(online_id->data, sizeof(online_id->data)); return ORBIS_OK; } @@ -1005,7 +1003,7 @@ int PS4_SYSV_ABI sceNpGetParentalControlInfoA() { } int PS4_SYSV_ABI sceNpGetState(s32 userId, OrbisNpState* state) { - *state = ORBIS_NP_STATE_SIGNED_OUT; + *state = OrbisNpState::SignedOut; LOG_DEBUG(Lib_NpManager, "Signed out"); return ORBIS_OK; } @@ -2518,7 +2516,7 @@ struct NpStateCallbackForNpToolkit { NpStateCallbackForNpToolkit NpStateCbForNp; int PS4_SYSV_ABI sceNpCheckCallbackForLib() { - Core::ExecuteGuest(NpStateCbForNp.func, 1, ORBIS_NP_STATE_SIGNED_OUT, NpStateCbForNp.userdata); + Core::ExecuteGuest(NpStateCbForNp.func, 1, OrbisNpState::SignedOut, NpStateCbForNp.userdata); return ORBIS_OK; } diff --git a/src/core/libraries/np_manager/np_manager.h b/src/core/libraries/np_manager/np_manager.h index 7e906cdc..6ba588e5 100644 --- a/src/core/libraries/np_manager/np_manager.h +++ b/src/core/libraries/np_manager/np_manager.h @@ -13,18 +13,14 @@ namespace Libraries::NpManager { constexpr int ORBIS_NP_ERROR_SIGNED_OUT = 0x80550006; -enum OrbisNpState { - ORBIS_NP_STATE_UNKNOWN = 0, - ORBIS_NP_STATE_SIGNED_OUT, - ORBIS_NP_STATE_SIGNED_IN -}; +enum class OrbisNpState : u32 { Unknown = 0, SignedOut, SignedIn }; using OrbisNpStateCallbackForNpToolkit = PS4_SYSV_ABI void (*)(s32 userId, OrbisNpState state, void* userdata); constexpr int ORBIS_NP_ONLINEID_MAX_LENGTH = 16; -typedef int OrbisUserServiceUserId; +using OrbisUserServiceUserId = s32; struct OrbisNpOnlineId { char data[ORBIS_NP_ONLINEID_MAX_LENGTH]; @@ -542,4 +538,4 @@ int PS4_SYSV_ABI sceNpRegisterStateCallbackForToolkit(OrbisNpStateCallbackForNpT int PS4_SYSV_ABI sceNpUnregisterStateCallbackForToolkit(); void RegisterlibSceNpManager(Core::Loader::SymbolsResolver* sym); -} // namespace Libraries::NpManager \ No newline at end of file +} // namespace Libraries::NpManager diff --git a/src/core/libraries/np_trophy/np_trophy.cpp b/src/core/libraries/np_trophy/np_trophy.cpp index e8fd57ef..9324ed6b 100644 --- a/src/core/libraries/np_trophy/np_trophy.cpp +++ b/src/core/libraries/np_trophy/np_trophy.cpp @@ -7,10 +7,10 @@ #include "common/logging/log.h" #include "common/path_util.h" #include "common/slot_vector.h" -#include "core/libraries/error_codes.h" #include "core/libraries/libs.h" -#include "np_trophy.h" -#include "trophy_ui.h" +#include "core/libraries/np_trophy/np_trophy.h" +#include "core/libraries/np_trophy/np_trophy_error.h" +#include "core/libraries/np_trophy/trophy_ui.h" namespace Libraries::NpTrophy { diff --git a/src/core/libraries/np_trophy/np_trophy.h b/src/core/libraries/np_trophy/np_trophy.h index ac13a9ab..9abc795b 100644 --- a/src/core/libraries/np_trophy/np_trophy.h +++ b/src/core/libraries/np_trophy/np_trophy.h @@ -29,14 +29,14 @@ constexpr int ORBIS_NP_TROPHY_INVALID_HANDLE = -1; constexpr int ORBIS_NP_TROPHY_INVALID_CONTEXT = -1; constexpr int ORBIS_NP_TROPHY_INVALID_TROPHY_ID = -1; -typedef int32_t OrbisNpTrophyHandle; -typedef int32_t OrbisNpTrophyContext; -typedef int32_t OrbisNpTrophyId; -typedef uint32_t OrbisNpTrophyFlagMask; +using OrbisNpTrophyHandle = s32; +using OrbisNpTrophyContext = s32; +using OrbisNpTrophyId = s32; +using OrbisNpTrophyFlagMask = u32; struct OrbisNpTrophyFlagArray { - OrbisNpTrophyFlagMask - flag_bits[ORBIS_NP_TROPHY_FLAG_SETSIZE >> ORBIS_NP_TROPHY_FLAG_BITS_SHIFT]; + static constexpr int NumMasks = ORBIS_NP_TROPHY_FLAG_SETSIZE >> ORBIS_NP_TROPHY_FLAG_BITS_SHIFT; + std::array flag_bits; }; void ORBIS_NP_TROPHY_FLAG_ZERO(OrbisNpTrophyFlagArray* p); @@ -49,18 +49,18 @@ struct OrbisNpTrophyData { size_t size; OrbisNpTrophyId trophy_id; bool unlocked; - uint8_t reserved[3]; + u8 reserved[3]; Rtc::OrbisRtcTick timestamp; }; -typedef int32_t OrbisNpTrophyGrade; +using OrbisNpTrophyGrade = s32; constexpr int ORBIS_NP_TROPHY_GRADE_UNKNOWN = 0; constexpr int ORBIS_NP_TROPHY_GRADE_PLATINUM = 1; constexpr int ORBIS_NP_TROPHY_GRADE_GOLD = 2; constexpr int ORBIS_NP_TROPHY_GRADE_SILVER = 3; constexpr int ORBIS_NP_TROPHY_GRADE_BRONZE = 4; -typedef int32_t OrbisNpTrophyGroupId; +using OrbisNpTrophyGroupId = s32; constexpr int ORBIS_NP_TROPHY_BASE_GAME_GROUP_ID = -1; constexpr int ORBIS_NP_TROPHY_INVALID_GROUP_ID = -2; @@ -70,29 +70,29 @@ struct OrbisNpTrophyDetails { OrbisNpTrophyGrade trophy_grade; OrbisNpTrophyGroupId group_id; bool hidden; - uint8_t reserved[3]; + u8 reserved[3]; char name[ORBIS_NP_TROPHY_NAME_MAX_SIZE]; char description[ORBIS_NP_TROPHY_DESCR_MAX_SIZE]; }; struct OrbisNpTrophyGameData { size_t size; - uint32_t unlocked_trophies; - uint32_t unlocked_platinum; - uint32_t unlocked_gold; - uint32_t unlocked_silver; - uint32_t unlocked_bronze; - uint32_t progress_percentage; + u32 unlocked_trophies; + u32 unlocked_platinum; + u32 unlocked_gold; + u32 unlocked_silver; + u32 unlocked_bronze; + u32 progress_percentage; }; struct OrbisNpTrophyGameDetails { size_t size; - uint32_t num_groups; - uint32_t num_trophies; - uint32_t num_platinum; - uint32_t num_gold; - uint32_t num_silver; - uint32_t num_bronze; + u32 num_groups; + u32 num_trophies; + u32 num_platinum; + u32 num_gold; + u32 num_silver; + u32 num_bronze; char title[ORBIS_NP_TROPHY_GAME_TITLE_MAX_SIZE]; char description[ORBIS_NP_TROPHY_GAME_DESCR_MAX_SIZE]; }; @@ -100,23 +100,23 @@ struct OrbisNpTrophyGameDetails { struct OrbisNpTrophyGroupData { size_t size; OrbisNpTrophyGroupId group_id; - uint32_t unlocked_trophies; - uint32_t unlocked_platinum; - uint32_t unlocked_gold; - uint32_t unlocked_silver; - uint32_t unlocked_bronze; - uint32_t progress_percentage; + u32 unlocked_trophies; + u32 unlocked_platinum; + u32 unlocked_gold; + u32 unlocked_silver; + u32 unlocked_bronze; + u32 progress_percentage; uint8_t reserved[4]; }; struct OrbisNpTrophyGroupDetails { size_t size; OrbisNpTrophyGroupId group_id; - uint32_t num_trophies; - uint32_t num_platinum; - uint32_t num_gold; - uint32_t num_silver; - uint32_t num_bronze; + u32 num_trophies; + u32 num_platinum; + u32 num_gold; + u32 num_silver; + u32 num_bronze; char title[ORBIS_NP_TROPHY_GROUP_TITLE_MAX_SIZE]; char description[ORBIS_NP_TROPHY_GROUP_DESCR_MAX_SIZE]; }; @@ -133,7 +133,7 @@ int PS4_SYSV_ABI sceNpTrophyConfigGetTrophySetVersion(); int PS4_SYSV_ABI sceNpTrophyConfigGetTrophyTitleDetails(); int PS4_SYSV_ABI sceNpTrophyConfigHasGroupFeature(); s32 PS4_SYSV_ABI sceNpTrophyCreateContext(OrbisNpTrophyContext* context, int32_t user_id, - uint32_t service_label, uint64_t options); + u32 service_label, uint64_t options); s32 PS4_SYSV_ABI sceNpTrophyCreateHandle(OrbisNpTrophyHandle* handle); int PS4_SYSV_ABI sceNpTrophyDestroyContext(OrbisNpTrophyContext context); s32 PS4_SYSV_ABI sceNpTrophyDestroyHandle(OrbisNpTrophyHandle handle); diff --git a/src/core/libraries/np_trophy/np_trophy_error.h b/src/core/libraries/np_trophy/np_trophy_error.h new file mode 100644 index 00000000..9506d9ca --- /dev/null +++ b/src/core/libraries/np_trophy/np_trophy_error.h @@ -0,0 +1,49 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/libraries/error_codes.h" + +// NpTrophy library +constexpr int ORBIS_NP_TROPHY_ERROR_UNKNOWN = 0x80551600; +constexpr int ORBIS_NP_TROPHY_ERROR_NOT_INITIALIZED = 0x80551601; +constexpr int ORBIS_NP_TROPHY_ERROR_ALREADY_INITIALIZED = 0x80551602; +constexpr int ORBIS_NP_TROPHY_ERROR_OUT_OF_MEMORY = 0x80551603; +constexpr int ORBIS_NP_TROPHY_ERROR_INVALID_ARGUMENT = 0x80551604; +constexpr int ORBIS_NP_TROPHY_ERROR_INSUFFICIENT_BUFFER = 0x80551605; +constexpr int ORBIS_NP_TROPHY_ERROR_EXCEEDS_MAX = 0x80551606; +constexpr int ORBIS_NP_TROPHY_ERROR_ABORT = 0x80551607; +constexpr int ORBIS_NP_TROPHY_ERROR_INVALID_HANDLE = 0x80551608; +constexpr int ORBIS_NP_TROPHY_ERROR_INVALID_CONTEXT = 0x80551609; +constexpr int ORBIS_NP_TROPHY_ERROR_INVALID_TROPHY_ID = 0x8055160A; +constexpr int ORBIS_NP_TROPHY_ERROR_INVALID_GROUP_ID = 0x8055160B; +constexpr int ORBIS_NP_TROPHY_ERROR_TROPHY_ALREADY_UNLOCKED = 0x8055160C; +constexpr int ORBIS_NP_TROPHY_ERROR_PLATINUM_CANNOT_UNLOCK = 0x8055160D; +constexpr int ORBIS_NP_TROPHY_ERROR_ACCOUNTID_NOT_MATCH = 0x8055160E; +constexpr int ORBIS_NP_TROPHY_ERROR_NOT_REGISTERED = 0x8055160F; +constexpr int ORBIS_NP_TROPHY_ERROR_ALREADY_REGISTERED = 0x80551610; +constexpr int ORBIS_NP_TROPHY_ERROR_BROKEN_DATA = 0x80551611; +constexpr int ORBIS_NP_TROPHY_ERROR_INSUFFICIENT_SPACE = 0x80551612; +constexpr int ORBIS_NP_TROPHY_ERROR_CONTEXT_ALREADY_EXISTS = 0x80551613; +constexpr int ORBIS_NP_TROPHY_ERROR_ICON_FILE_NOT_FOUND = 0x80551614; +constexpr int ORBIS_NP_TROPHY_ERROR_INVALID_TRP_FILE_FORMAT = 0x80551616; +constexpr int ORBIS_NP_TROPHY_ERROR_UNSUPPORTED_TRP_FILE = 0x80551617; +constexpr int ORBIS_NP_TROPHY_ERROR_INVALID_TROPHY_CONF_FORMAT = 0x80551618; +constexpr int ORBIS_NP_TROPHY_ERROR_UNSUPPORTED_TROPHY_CONF = 0x80551619; +constexpr int ORBIS_NP_TROPHY_ERROR_TROPHY_NOT_UNLOCKED = 0x8055161A; +constexpr int ORBIS_NP_TROPHY_ERROR_USER_NOT_FOUND = 0x8055161C; +constexpr int ORBIS_NP_TROPHY_ERROR_USER_NOT_LOGGED_IN = 0x8055161D; +constexpr int ORBIS_NP_TROPHY_ERROR_CONTEXT_USER_LOGOUT = 0x8055161E; +constexpr int ORBIS_NP_TROPHY_ERROR_USE_TRP_FOR_DEVELOPMENT = 0x8055161F; +constexpr int ORBIS_NP_TROPHY_ERROR_INVALID_NP_SERVICE_LABEL = 0x80551621; +constexpr int ORBIS_NP_TROPHY_ERROR_NOT_SUPPORTED = 0x80551622; +constexpr int ORBIS_NP_TROPHY_ERROR_CONTEXT_EXCEEDS_MAX = 0x80551623; +constexpr int ORBIS_NP_TROPHY_ERROR_HANDLE_EXCEEDS_MAX = 0x80551624; +constexpr int ORBIS_NP_TROPHY_ERROR_INVALID_USER_ID = 0x80551625; +constexpr int ORBIS_NP_TROPHY_ERROR_TITLE_CONF_NOT_INSTALLED = 0x80551626; +constexpr int ORBIS_NP_TROPHY_ERROR_BROKEN_TITLE_CONF = 0x80551627; +constexpr int ORBIS_NP_TROPHY_ERROR_INCONSISTENT_TITLE_CONF = 0x80551628; +constexpr int ORBIS_NP_TROPHY_ERROR_TITLE_BACKGROUND = 0x80551629; +constexpr int ORBIS_NP_TROPHY_ERROR_SCREENSHOT_DISABLED = 0x8055162B; +constexpr int ORBIS_NP_TROPHY_ERROR_SCREENSHOT_DISPLAY_BUFFER_NOT_IN_USE = 0x8055162D; diff --git a/src/core/libraries/pad/pad.cpp b/src/core/libraries/pad/pad.cpp index a1897d04..ec4186f1 100644 --- a/src/core/libraries/pad/pad.cpp +++ b/src/core/libraries/pad/pad.cpp @@ -1,12 +1,11 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "common/assert.h" #include "common/config.h" #include "common/logging/log.h" #include "common/singleton.h" -#include "core/libraries/error_codes.h" #include "core/libraries/libs.h" +#include "core/libraries/pad/pad_errors.h" #include "input/controller.h" #include "pad.h" @@ -99,8 +98,8 @@ int PS4_SYSV_ABI scePadGetControllerInformation(s32 handle, OrbisPadControllerIn pInfo->connectionType = ORBIS_PAD_PORT_TYPE_STANDARD; pInfo->connectedCount = 1; pInfo->connected = false; - pInfo->deviceClass = ORBIS_PAD_DEVICE_CLASS_STANDARD; - return SCE_OK; + pInfo->deviceClass = OrbisPadDeviceClass::Standard; + return ORBIS_OK; } pInfo->touchPadInfo.pixelDensity = 1; pInfo->touchPadInfo.resolution.x = 1920; @@ -110,12 +109,12 @@ int PS4_SYSV_ABI scePadGetControllerInformation(s32 handle, OrbisPadControllerIn pInfo->connectionType = ORBIS_PAD_PORT_TYPE_STANDARD; pInfo->connectedCount = 1; pInfo->connected = true; - pInfo->deviceClass = ORBIS_PAD_DEVICE_CLASS_STANDARD; + pInfo->deviceClass = OrbisPadDeviceClass::Standard; if (Config::getUseSpecialPad()) { pInfo->connectionType = ORBIS_PAD_PORT_TYPE_SPECIAL; pInfo->deviceClass = (OrbisPadDeviceClass)Config::getSpecialPadClass(); } - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI scePadGetDataInternal() { @@ -382,7 +381,7 @@ int PS4_SYSV_ABI scePadReadState(s32 handle, OrbisPadData* pData) { pData->connectedCount = 1; // connectedCount; pData->deviceUniqueDataLen = 0; - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI scePadReadStateExt() { diff --git a/src/core/libraries/pad/pad.h b/src/core/libraries/pad/pad.h index f94a642c..68943b46 100644 --- a/src/core/libraries/pad/pad.h +++ b/src/core/libraries/pad/pad.h @@ -3,6 +3,7 @@ #pragma once +#include "common/enum.h" #include "common/types.h" namespace Core::Loader { @@ -18,18 +19,18 @@ constexpr int ORBIS_PAD_PORT_TYPE_STANDARD = 0; constexpr int ORBIS_PAD_PORT_TYPE_SPECIAL = 2; constexpr int ORBIS_PAD_PORT_TYPE_REMOTE_CONTROL = 16; -enum OrbisPadDeviceClass { - ORBIS_PAD_DEVICE_CLASS_INVALID = -1, - ORBIS_PAD_DEVICE_CLASS_STANDARD = 0, - ORBIS_PAD_DEVICE_CLASS_GUITAR = 1, - ORBIS_PAD_DEVICE_CLASS_DRUM = 2, - ORBIS_PAD_DEVICE_CLASS_DJ_TURNTABLE = 3, - ORBIS_PAD_DEVICE_CLASS_DANCEMAT = 4, - ORBIS_PAD_DEVICE_CLASS_NAVIGATION = 5, - ORBIS_PAD_DEVICE_CLASS_STEERING_WHEEL = 6, - ORBIS_PAD_DEVICE_CLASS_STICK = 7, - ORBIS_PAD_DEVICE_CLASS_FLIGHT_STICK = 8, - ORBIS_PAD_DEVICE_CLASS_GUN = 9, +enum class OrbisPadDeviceClass { + Invalid = -1, + Standard = 0, + Guitar = 1, + Drum = 2, + DjTurntable = 3, + Dancemat = 4, + Navigation = 5, + SteeringWheel = 6, + Stick = 7, + FightStick = 8, + Gun = 9, }; struct OrbisPadDeviceClassExtendedInformation { @@ -123,25 +124,27 @@ struct OrbisPadAnalogStick { u8 y; }; -enum OrbisPadButtonDataOffset { - ORBIS_PAD_BUTTON_L3 = 0x00000002, - ORBIS_PAD_BUTTON_R3 = 0x00000004, - ORBIS_PAD_BUTTON_OPTIONS = 0x00000008, - ORBIS_PAD_BUTTON_UP = 0x00000010, - ORBIS_PAD_BUTTON_RIGHT = 0x00000020, - ORBIS_PAD_BUTTON_DOWN = 0x00000040, - ORBIS_PAD_BUTTON_LEFT = 0x00000080, - ORBIS_PAD_BUTTON_L2 = 0x00000100, - ORBIS_PAD_BUTTON_R2 = 0x00000200, - ORBIS_PAD_BUTTON_L1 = 0x00000400, - ORBIS_PAD_BUTTON_R1 = 0x00000800, - ORBIS_PAD_BUTTON_TRIANGLE = 0x00001000, - ORBIS_PAD_BUTTON_CIRCLE = 0x00002000, - ORBIS_PAD_BUTTON_CROSS = 0x00004000, - ORBIS_PAD_BUTTON_SQUARE = 0x00008000, - ORBIS_PAD_BUTTON_TOUCH_PAD = 0x00100000, - ORBIS_PAD_BUTTON_INTERCEPTED = 0x80000000, +enum class OrbisPadButtonDataOffset : u32 { + None = 0, + L3 = 0x2, + R3 = 0x4, + Options = 0x8, + Up = 0x10, + Right = 0x20, + Down = 0x40, + Left = 0x80, + L2 = 0x100, + R2 = 0x200, + L1 = 0x400, + R1 = 0x800, + Triangle = 0x1000, + Circle = 0x2000, + Cross = 0x4000, + Square = 0x8000, + TouchPad = 0x100000, + Intercepted = 0x80000000, }; +DECLARE_ENUM_FLAG_OPERATORS(OrbisPadButtonDataOffset) struct OrbisFQuaternion { float x, y, z, w; @@ -173,7 +176,7 @@ struct OrbisPadExtensionUnitData { }; struct OrbisPadData { - u32 buttons; + OrbisPadButtonDataOffset buttons; OrbisPadAnalogStick leftStick; OrbisPadAnalogStick rightStick; OrbisPadAnalogButtons analogButtons; @@ -346,4 +349,4 @@ int PS4_SYSV_ABI Func_89C9237E393DA243(); int PS4_SYSV_ABI Func_EF103E845B6F0420(); void RegisterlibScePad(Core::Loader::SymbolsResolver* sym); -} // namespace Libraries::Pad \ No newline at end of file +} // namespace Libraries::Pad diff --git a/src/core/libraries/pad/pad_errors.h b/src/core/libraries/pad/pad_errors.h new file mode 100644 index 00000000..182c8921 --- /dev/null +++ b/src/core/libraries/pad/pad_errors.h @@ -0,0 +1,22 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/libraries/error_codes.h" + +// Pad library +constexpr int ORBIS_PAD_ERROR_INVALID_ARG = 0x80920001; +constexpr int ORBIS_PAD_ERROR_INVALID_PORT = 0x80920002; +constexpr int ORBIS_PAD_ERROR_INVALID_HANDLE = 0x80920003; +constexpr int ORBIS_PAD_ERROR_ALREADY_OPENED = 0x80920004; +constexpr int ORBIS_PAD_ERROR_NOT_INITIALIZED = 0x80920005; +constexpr int ORBIS_PAD_ERROR_INVALID_LIGHTBAR_SETTING = 0x80920006; +constexpr int ORBIS_PAD_ERROR_DEVICE_NOT_CONNECTED = 0x80920007; +constexpr int ORBIS_PAD_ERROR_DEVICE_NO_HANDLE = 0x80920008; +constexpr int ORBIS_PAD_ERROR_FATAL = 0x809200FF; +constexpr int ORBIS_PAD_ERROR_NOT_PERMITTED = 0x80920101; +constexpr int ORBIS_PAD_ERROR_INVALID_BUFFER_LENGTH = 0x80920102; +constexpr int ORBIS_PAD_ERROR_INVALID_REPORT_LENGTH = 0x80920103; +constexpr int ORBIS_PAD_ERROR_INVALID_REPORT_ID = 0x80920104; +constexpr int ORBIS_PAD_ERROR_SEND_AGAIN = 0x80920105; diff --git a/src/core/libraries/playgo/playgo.cpp b/src/core/libraries/playgo/playgo.cpp index d4f5c6b7..6fcf875d 100644 --- a/src/core/libraries/playgo/playgo.cpp +++ b/src/core/libraries/playgo/playgo.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/logging/log.h" -#include "common/singleton.h" #include "core/file_format/playgo_chunk.h" #include "core/libraries/error_codes.h" #include "core/libraries/libs.h" @@ -11,6 +10,9 @@ namespace Libraries::PlayGo { +static constexpr OrbisPlayGoHandle PlaygoHandle = 1; +static std::unique_ptr playgo; + s32 PS4_SYSV_ABI sceDbgPlayGoRequestNextChunk() { LOG_ERROR(Lib_PlayGo, "(STUBBED)called"); return ORBIS_OK; @@ -24,57 +26,63 @@ s32 PS4_SYSV_ABI sceDbgPlayGoSnapshot() { s32 PS4_SYSV_ABI scePlayGoClose(OrbisPlayGoHandle handle) { LOG_INFO(Lib_PlayGo, "called"); - auto* playgo = Common::Singleton::Instance(); - - if (handle != 1) + if (handle != PlaygoHandle) { return ORBIS_PLAYGO_ERROR_BAD_HANDLE; - if (!playgo->initialized) + } + if (!playgo->initialized) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; + } + playgo.reset(); return ORBIS_OK; } s32 PS4_SYSV_ABI scePlayGoGetChunkId(OrbisPlayGoHandle handle, OrbisPlayGoChunkId* outChunkIdList, u32 numberOfEntries, u32* outEntries) { LOG_INFO(Lib_PlayGo, "called"); - auto* playgo = Common::Singleton::Instance(); - if (handle != 1) + if (handle != PlaygoHandle) { return ORBIS_PLAYGO_ERROR_BAD_HANDLE; - if (outEntries == nullptr) + } + if (outEntries == nullptr) { return ORBIS_PLAYGO_ERROR_BAD_POINTER; - if (outChunkIdList != nullptr && numberOfEntries == 0) + } + if (outChunkIdList != nullptr && numberOfEntries == 0) { return ORBIS_PLAYGO_ERROR_BAD_SIZE; + } if (playgo->GetPlaygoHeader().file_size == 0) { *outEntries = 0; - } else { - if (outChunkIdList == nullptr) { - *outEntries = playgo->chunks.size(); - } else { - if (numberOfEntries > playgo->chunks.size()) { - numberOfEntries = playgo->chunks.size(); - } - - if (numberOfEntries != 0) { - for (u32 i = 0; i < numberOfEntries; i++) { - outChunkIdList[i] = i; - } - *outEntries = numberOfEntries; - } - } + return ORBIS_OK; } + + if (outChunkIdList == nullptr) { + *outEntries = playgo->chunks.size(); + return ORBIS_OK; + } + + if (numberOfEntries > playgo->chunks.size()) { + numberOfEntries = playgo->chunks.size(); + } + + for (u32 i = 0; i < numberOfEntries; i++) { + outChunkIdList[i] = i; + } + *outEntries = numberOfEntries; return ORBIS_OK; } s32 PS4_SYSV_ABI scePlayGoGetEta(OrbisPlayGoHandle handle, const OrbisPlayGoChunkId* chunkIds, u32 numberOfEntries, OrbisPlayGoEta* outEta) { LOG_INFO(Lib_PlayGo, "called"); - if (handle != 1) + if (handle != PlaygoHandle) { return ORBIS_PLAYGO_ERROR_BAD_HANDLE; - if (chunkIds == nullptr || outEta == nullptr) + } + if (chunkIds == nullptr || outEta == nullptr) { return ORBIS_PLAYGO_ERROR_BAD_POINTER; - if (numberOfEntries == 0) + } + if (numberOfEntries == 0) { return ORBIS_PLAYGO_ERROR_BAD_SIZE; + } *outEta = 0; // all is loaded return ORBIS_OK; @@ -84,22 +92,23 @@ s32 PS4_SYSV_ABI scePlayGoGetInstallSpeed(OrbisPlayGoHandle handle, OrbisPlayGoInstallSpeed* outSpeed) { LOG_INFO(Lib_PlayGo, "called"); - auto* playgo = Common::Singleton::Instance(); - - if (handle != 1) + if (handle != PlaygoHandle) { return ORBIS_PLAYGO_ERROR_BAD_HANDLE; - if (outSpeed == nullptr) + } + if (outSpeed == nullptr) { return ORBIS_PLAYGO_ERROR_BAD_POINTER; - if (!playgo->initialized) + } + if (!playgo->initialized) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; + } std::scoped_lock lk{playgo->GetSpeedMutex()}; - if (playgo->speed == 0) { + if (playgo->speed == OrbisPlayGoInstallSpeed::Suspended) { using namespace std::chrono; if ((duration_cast(steady_clock::now().time_since_epoch()).count() - playgo->speed_tick) > 30 * 1000) { // 30sec - playgo->speed = ORBIS_PLAYGO_INSTALL_SPEED_TRICKLE; + playgo->speed = OrbisPlayGoInstallSpeed::Trickle; } } *outSpeed = playgo->speed; @@ -111,14 +120,15 @@ s32 PS4_SYSV_ABI scePlayGoGetLanguageMask(OrbisPlayGoHandle handle, OrbisPlayGoLanguageMask* outLanguageMask) { LOG_INFO(Lib_PlayGo, "called"); - auto* playgo = Common::Singleton::Instance(); - - if (handle != 1) + if (handle != PlaygoHandle) { return ORBIS_PLAYGO_ERROR_BAD_HANDLE; - if (outLanguageMask == nullptr) + } + if (outLanguageMask == nullptr) { return ORBIS_PLAYGO_ERROR_BAD_POINTER; - if (!playgo->initialized) + } + if (!playgo->initialized) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; + } *outLanguageMask = playgo->langMask; return ORBIS_OK; @@ -129,24 +139,27 @@ s32 PS4_SYSV_ABI scePlayGoGetLocus(OrbisPlayGoHandle handle, const OrbisPlayGoCh LOG_INFO(Lib_PlayGo, "called handle = {}, chunkIds = {}, numberOfEntries = {}", handle, *chunkIds, numberOfEntries); - auto* playgo = Common::Singleton::Instance(); - - if (handle != 1) + if (handle != PlaygoHandle) { return ORBIS_PLAYGO_ERROR_BAD_HANDLE; - if (chunkIds == nullptr || outLoci == nullptr) + } + if (chunkIds == nullptr || outLoci == nullptr) { return ORBIS_PLAYGO_ERROR_BAD_POINTER; - if (numberOfEntries == 0) + } + if (numberOfEntries == 0) { return ORBIS_PLAYGO_ERROR_BAD_SIZE; - if (!playgo->initialized) + } + if (!playgo->initialized) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; - if (playgo->GetPlaygoHeader().file_size == 0) + } + if (playgo->GetPlaygoHeader().file_size == 0) { return ORBIS_PLAYGO_ERROR_NOT_SUPPORT_PLAYGO; + } - for (uint32_t i = 0; i < numberOfEntries; i++) { + for (int i = 0; i < numberOfEntries; i++) { if (chunkIds[i] <= playgo->chunks.size()) { - outLoci[i] = OrbisPlayGoLocusValue::ORBIS_PLAYGO_LOCUS_LOCAL_FAST; + outLoci[i] = OrbisPlayGoLocus::LocalFast; } else { - outLoci[i] = ORBIS_PLAYGO_LOCUS_NOT_DOWNLOADED; + outLoci[i] = OrbisPlayGoLocus::NotDownloaded; return ORBIS_PLAYGO_ERROR_BAD_CHUNK_ID; } } @@ -158,18 +171,21 @@ s32 PS4_SYSV_ABI scePlayGoGetProgress(OrbisPlayGoHandle handle, const OrbisPlayG LOG_INFO(Lib_PlayGo, "called handle = {}, chunkIds = {}, numberOfEntries = {}", handle, *chunkIds, numberOfEntries); - auto* playgo = Common::Singleton::Instance(); - - if (handle != 1) + if (handle != PlaygoHandle) { return ORBIS_PLAYGO_ERROR_BAD_HANDLE; - if (chunkIds == nullptr || outProgress == nullptr) + } + if (chunkIds == nullptr || outProgress == nullptr) { return ORBIS_PLAYGO_ERROR_BAD_POINTER; - if (numberOfEntries == 0) + } + if (numberOfEntries == 0) { return ORBIS_PLAYGO_ERROR_BAD_SIZE; - if (!playgo->initialized) + } + if (!playgo->initialized) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; - if (playgo->GetPlaygoHeader().file_size == 0) + } + if (playgo->GetPlaygoHeader().file_size == 0) { return ORBIS_PLAYGO_ERROR_BAD_CHUNK_ID; + } outProgress->progressSize = 0; outProgress->totalSize = 0; @@ -194,16 +210,18 @@ s32 PS4_SYSV_ABI scePlayGoGetToDoList(OrbisPlayGoHandle handle, OrbisPlayGoToDo* u32 numberOfEntries, u32* outEntries) { LOG_INFO(Lib_PlayGo, "called handle = {} numberOfEntries = {}", handle, numberOfEntries); - auto* playgo = Common::Singleton::Instance(); - - if (handle != 1) + if (handle != PlaygoHandle) { return ORBIS_PLAYGO_ERROR_BAD_HANDLE; - if (outTodoList == nullptr || outEntries == nullptr) + } + if (outTodoList == nullptr || outEntries == nullptr) { return ORBIS_PLAYGO_ERROR_BAD_POINTER; - if (numberOfEntries == 0) + } + if (numberOfEntries == 0) { return ORBIS_PLAYGO_ERROR_BAD_SIZE; - if (!playgo->initialized) + } + if (!playgo->initialized) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; + } *outEntries = 0; // nothing to do return ORBIS_OK; } @@ -218,19 +236,19 @@ int scePlayGoConvertLanguage(int systemLang) { s32 PS4_SYSV_ABI scePlayGoInitialize(OrbisPlayGoInitParams* param) { LOG_INFO(Lib_PlayGo, "called, bufSize = {}", param->bufSize); - if (param->bufAddr == nullptr) + if (param->bufAddr == nullptr) { return ORBIS_PLAYGO_ERROR_BAD_POINTER; - if (param->bufSize < 0x200000) + } + if (param->bufSize < 0x200000) { return ORBIS_PLAYGO_ERROR_BAD_SIZE; + } - auto* playgo = Common::Singleton::Instance(); - + playgo = std::make_unique(); if (!playgo->initialized) { using namespace SystemService; - // get system lang - int systemLang = 0; - sceSystemServiceParamGetInt(ORBIS_SYSTEM_SERVICE_PARAM_ID_LANG, &systemLang); - playgo->langMask = scePlayGoConvertLanguage(systemLang); + s32 system_lang = 0; + sceSystemServiceParamGetInt(OrbisSystemServiceParamId::Lang, &system_lang); + playgo->langMask = scePlayGoConvertLanguage(system_lang); playgo->initialized = true; } else { return ORBIS_PLAYGO_ERROR_ALREADY_INITIALIZED; @@ -241,18 +259,20 @@ s32 PS4_SYSV_ABI scePlayGoInitialize(OrbisPlayGoInitParams* param) { s32 PS4_SYSV_ABI scePlayGoOpen(OrbisPlayGoHandle* outHandle, const void* param) { LOG_INFO(Lib_PlayGo, "called"); - auto* playgo = Common::Singleton::Instance(); - - if (outHandle == nullptr) + if (outHandle == nullptr) { return ORBIS_PLAYGO_ERROR_BAD_POINTER; - if (param) + } + if (param) { return ORBIS_PLAYGO_ERROR_INVALID_ARGUMENT; - if (!playgo->initialized) + } + if (!playgo->initialized) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; - if (playgo->GetPlaygoHeader().file_size == 0) + } + if (playgo->GetPlaygoHeader().file_size == 0) { return ORBIS_PLAYGO_ERROR_NOT_SUPPORT_PLAYGO; + } - playgo->handle = *outHandle = 1; + playgo->handle = *outHandle = PlaygoHandle; return ORBIS_OK; } @@ -260,21 +280,23 @@ s32 PS4_SYSV_ABI scePlayGoPrefetch(OrbisPlayGoHandle handle, const OrbisPlayGoCh u32 numberOfEntries, OrbisPlayGoLocus minimumLocus) { LOG_INFO(Lib_PlayGo, "called"); - auto* playgo = Common::Singleton::Instance(); - - if (handle != 1) + if (handle != PlaygoHandle) { return ORBIS_PLAYGO_ERROR_BAD_HANDLE; - if (chunkIds == nullptr) + } + if (chunkIds == nullptr) { return ORBIS_PLAYGO_ERROR_BAD_POINTER; - if (numberOfEntries == 0) + } + if (numberOfEntries == 0) { return ORBIS_PLAYGO_ERROR_BAD_SIZE; - if (!playgo->initialized) + } + if (!playgo->initialized) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; + } switch (minimumLocus) { - case ORBIS_PLAYGO_LOCUS_NOT_DOWNLOADED: - case ORBIS_PLAYGO_LOCUS_LOCAL_SLOW: - case ORBIS_PLAYGO_LOCUS_LOCAL_FAST: + case OrbisPlayGoLocus::NotDownloaded: + case OrbisPlayGoLocus::LocalSlow: + case OrbisPlayGoLocus::LocalFast: break; default: return ORBIS_PLAYGO_ERROR_BAD_LOCUS; @@ -285,24 +307,23 @@ s32 PS4_SYSV_ABI scePlayGoPrefetch(OrbisPlayGoHandle handle, const OrbisPlayGoCh s32 PS4_SYSV_ABI scePlayGoSetInstallSpeed(OrbisPlayGoHandle handle, OrbisPlayGoInstallSpeed speed) { LOG_INFO(Lib_PlayGo, "called"); - auto* playgo = Common::Singleton::Instance(); - - if (handle != 1) + if (handle != PlaygoHandle) { return ORBIS_PLAYGO_ERROR_BAD_HANDLE; - if (!playgo->initialized) + } + if (!playgo->initialized) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; + } switch (speed) { - case ORBIS_PLAYGO_INSTALL_SPEED_SUSPENDED: - case ORBIS_PLAYGO_INSTALL_SPEED_TRICKLE: - case ORBIS_PLAYGO_INSTALL_SPEED_FULL: + case OrbisPlayGoInstallSpeed::Suspended: + case OrbisPlayGoInstallSpeed::Trickle: + case OrbisPlayGoInstallSpeed::Full: break; default: return ORBIS_PLAYGO_ERROR_INVALID_ARGUMENT; } std::scoped_lock lk{playgo->GetSpeedMutex()}; - using namespace std::chrono; playgo->speed = speed; playgo->speed_tick = @@ -314,12 +335,13 @@ s32 PS4_SYSV_ABI scePlayGoSetInstallSpeed(OrbisPlayGoHandle handle, OrbisPlayGoI s32 PS4_SYSV_ABI scePlayGoSetLanguageMask(OrbisPlayGoHandle handle, OrbisPlayGoLanguageMask languageMask) { LOG_INFO(Lib_PlayGo, "called"); - auto* playgo = Common::Singleton::Instance(); - if (handle != 1) + if (handle != 1) { return ORBIS_PLAYGO_ERROR_BAD_HANDLE; - if (!playgo->initialized) + } + if (!playgo->initialized) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; + } playgo->langMask = languageMask; return ORBIS_OK; @@ -329,23 +351,24 @@ s32 PS4_SYSV_ABI scePlayGoSetToDoList(OrbisPlayGoHandle handle, const OrbisPlayG uint32_t numberOfEntries) { LOG_INFO(Lib_PlayGo, "called"); - auto* playgo = Common::Singleton::Instance(); - - if (handle != 1) + if (handle != PlaygoHandle) { return ORBIS_PLAYGO_ERROR_BAD_HANDLE; - if (todoList == nullptr) + } + if (todoList == nullptr) { return ORBIS_PLAYGO_ERROR_BAD_POINTER; - if (numberOfEntries == 0) + } + if (numberOfEntries == 0) { return ORBIS_PLAYGO_ERROR_BAD_SIZE; - if (!playgo->initialized) + } + if (!playgo->initialized) { return ORBIS_PLAYGO_ERROR_NOT_INITIALIZED; + } return ORBIS_OK; } s32 PS4_SYSV_ABI scePlayGoTerminate() { LOG_INFO(Lib_PlayGo, "called"); - auto* playgo = Common::Singleton::Instance(); if (playgo->initialized) { playgo->initialized = false; } else { diff --git a/src/core/libraries/playgo/playgo_types.h b/src/core/libraries/playgo/playgo_types.h index 62dea4f4..885eee03 100644 --- a/src/core/libraries/playgo/playgo_types.h +++ b/src/core/libraries/playgo/playgo_types.h @@ -5,41 +5,39 @@ #include "common/types.h" -typedef u32 OrbisPlayGoHandle; -typedef u16 OrbisPlayGoChunkId; -typedef s8 OrbisPlayGoLocus; -typedef s32 OrbisPlayGoInstallSpeed; -typedef s64 OrbisPlayGoEta; -typedef u64 OrbisPlayGoLanguageMask; +using OrbisPlayGoHandle = u32; +using OrbisPlayGoChunkId = u16; +using OrbisPlayGoEta = s64; +using OrbisPlayGoLanguageMask = u64; -typedef struct OrbisPlayGoInitParams { +enum class OrbisPlayGoLocus : s8 { + NotDownloaded = 0, + LocalSlow = 2, + LocalFast = 3, +}; + +enum class OrbisPlayGoInstallSpeed : s32 { + Suspended = 0, + Trickle = 1, + Full = 2, +}; + +struct OrbisPlayGoInitParams { const void* bufAddr; u32 bufSize; u32 reserved; -} OrbisPlayGoInitParams; +}; -typedef struct OrbisPlayGoToDo { +struct OrbisPlayGoToDo { OrbisPlayGoChunkId chunkId; OrbisPlayGoLocus locus; s8 reserved; -} OrbisPlayGoToDo; +}; -typedef struct OrbisPlayGoProgress { - uint64_t progressSize; - uint64_t totalSize; -} OrbisPlayGoProgress; - -typedef enum OrbisPlayGoLocusValue { - ORBIS_PLAYGO_LOCUS_NOT_DOWNLOADED = 0, - ORBIS_PLAYGO_LOCUS_LOCAL_SLOW = 2, - ORBIS_PLAYGO_LOCUS_LOCAL_FAST = 3 -} OrbisPlayGoLocusValue; - -typedef enum OrbisPlayGoInstallSpeedValue { - ORBIS_PLAYGO_INSTALL_SPEED_SUSPENDED = 0, - ORBIS_PLAYGO_INSTALL_SPEED_TRICKLE = 1, - ORBIS_PLAYGO_INSTALL_SPEED_FULL = 2 -} OrbisPlayGoInstallSpeedValue; +struct OrbisPlayGoProgress { + u64 progressSize; + u64 totalSize; +}; constexpr int ORBIS_PLAYGO_ERROR_UNKNOWN = -2135818239; /* 0x80B20001 */ constexpr int ORBIS_PLAYGO_ERROR_FATAL = -2135818238; /* 0x80B20002 */ diff --git a/src/core/libraries/random/random.h b/src/core/libraries/random/random.h index b483cf6e..17249410 100644 --- a/src/core/libraries/random/random.h +++ b/src/core/libraries/random/random.h @@ -10,9 +10,11 @@ class SymbolsResolver; } namespace Libraries::Random { -constexpr int32_t SCE_RANDOM_MAX_SIZE = 64; + +constexpr s32 SCE_RANDOM_MAX_SIZE = 64; s32 PS4_SYSV_ABI sceRandomGetRandomNumber(u8* buf, std::size_t size); void RegisterlibSceRandom(Core::Loader::SymbolsResolver* sym); -} // namespace Libraries::Random \ No newline at end of file + +} // namespace Libraries::Random diff --git a/src/core/libraries/rtc/rtc.cpp b/src/core/libraries/rtc/rtc.cpp index 1b880297..f94c0013 100644 --- a/src/core/libraries/rtc/rtc.cpp +++ b/src/core/libraries/rtc/rtc.cpp @@ -4,7 +4,6 @@ #include #include "common/logging/log.h" -#include "core/libraries/error_codes.h" #include "core/libraries/kernel/process.h" #include "core/libraries/kernel/time.h" #include "core/libraries/libs.h" @@ -49,7 +48,7 @@ int PS4_SYSV_ABI sceRtcCheckValid(OrbisRtcDateTime* pTime) { if (pTime->microsecond >= 1000000) return ORBIS_RTC_ERROR_INVALID_MICROSECOND; - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcCompareTick(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2) { @@ -102,7 +101,7 @@ int PS4_SYSV_ABI sceRtcConvertUtcToLocalTime(OrbisRtcTick* pTickUtc, OrbisRtcTic } int PS4_SYSV_ABI sceRtcEnd() { - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcFormatRFC2822(char* pszDateTime, const OrbisRtcTick* pTickUtc, @@ -253,7 +252,7 @@ int PS4_SYSV_ABI sceRtcFormatRFC2822(char* pszDateTime, const OrbisRtcTick* pTic } } - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcFormatRFC2822LocalTime(char* pszDateTime, const OrbisRtcTick* pTickUtc) { @@ -374,7 +373,7 @@ int PS4_SYSV_ABI sceRtcFormatRFC3339Precise(char* pszDateTime, const OrbisRtcTic pszDateTime[i] = formattedString.c_str()[i]; } - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcFormatRFC3339PreciseLocalTime(char* pszDateTime, @@ -397,13 +396,13 @@ int PS4_SYSV_ABI sceRtcGetCurrentAdNetworkTick(OrbisRtcTick* pTick) { Kernel::OrbisKernelTimespec clocktime; int returnValue = Kernel::sceKernelClockGettime(Kernel::ORBIS_CLOCK_REALTIME, &clocktime); - if (returnValue == SCE_OK) { + if (returnValue == ORBIS_OK) { pTick->tick = clocktime.tv_nsec / 1000 + clocktime.tv_sec * 1000000 + UNIX_EPOCH_TICKS; } else { return ORBIS_RTC_ERROR_NOT_INITIALIZED; } - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcGetCurrentClock(OrbisRtcDateTime* pTime, int timeZone) { @@ -415,7 +414,7 @@ int PS4_SYSV_ABI sceRtcGetCurrentClock(OrbisRtcDateTime* pTime, int timeZone) { Kernel::OrbisKernelTimespec clocktime; int returnValue = Kernel::sceKernelClockGettime(Kernel::ORBIS_CLOCK_REALTIME, &clocktime); - if (returnValue == SCE_OK) { + if (returnValue == ORBIS_OK) { OrbisRtcTick clockTick; clockTick.tick = clocktime.tv_nsec / 1000 + clocktime.tv_sec * 1000000 + UNIX_EPOCH_TICKS; @@ -461,13 +460,13 @@ int PS4_SYSV_ABI sceRtcGetCurrentDebugNetworkTick(OrbisRtcTick* pTick) { Kernel::OrbisKernelTimespec clocktime; int returnValue = Kernel::sceKernelClockGettime(Kernel::ORBIS_CLOCK_REALTIME, &clocktime); - if (returnValue == SCE_OK) { + if (returnValue == ORBIS_OK) { pTick->tick = clocktime.tv_nsec / 1000 + clocktime.tv_sec * 1000000 + UNIX_EPOCH_TICKS; } else { return ORBIS_RTC_ERROR_NOT_INITIALIZED; } - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcGetCurrentNetworkTick(OrbisRtcTick* pTick) { @@ -479,13 +478,13 @@ int PS4_SYSV_ABI sceRtcGetCurrentNetworkTick(OrbisRtcTick* pTick) { Kernel::OrbisKernelTimespec clocktime; int returnValue = Kernel::sceKernelClockGettime(Kernel::ORBIS_CLOCK_REALTIME, &clocktime); - if (returnValue == SCE_OK) { + if (returnValue == ORBIS_OK) { pTick->tick = clocktime.tv_nsec / 1000 + clocktime.tv_sec * 1000000 + UNIX_EPOCH_TICKS; } else { return ORBIS_RTC_ERROR_NOT_INITIALIZED; } - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcGetCurrentRawNetworkTick(OrbisRtcTick* pTick) { @@ -497,13 +496,13 @@ int PS4_SYSV_ABI sceRtcGetCurrentRawNetworkTick(OrbisRtcTick* pTick) { Kernel::OrbisKernelTimespec clocktime; int returnValue = Kernel::sceKernelClockGettime(Kernel::ORBIS_CLOCK_REALTIME, &clocktime); - if (returnValue == SCE_OK) { + if (returnValue == ORBIS_OK) { pTick->tick = clocktime.tv_nsec / 1000 + clocktime.tv_sec * 1000000 + UNIX_EPOCH_TICKS; } else { return ORBIS_RTC_ERROR_NOT_INITIALIZED; } - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcGetCurrentTick(OrbisRtcTick* pTick) { @@ -519,7 +518,7 @@ int PS4_SYSV_ABI sceRtcGetCurrentTick(OrbisRtcTick* pTick) { pTick->tick = clocktime.tv_nsec / 1000 + clocktime.tv_sec * 1000000 + UNIX_EPOCH_TICKS; } - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcGetDayOfWeek(int year, int month, int day) { @@ -576,14 +575,14 @@ int PS4_SYSV_ABI sceRtcGetDaysInMonth(int year, int month) { return lastDay; } -int PS4_SYSV_ABI sceRtcGetDosTime(OrbisRtcDateTime* pTime, unsigned int* dosTime) { +int PS4_SYSV_ABI sceRtcGetDosTime(OrbisRtcDateTime* pTime, u32* dosTime) { LOG_TRACE(Lib_Rtc, "called"); if (pTime == nullptr || dosTime == nullptr) return ORBIS_RTC_ERROR_INVALID_POINTER; int isValid = sceRtcCheckValid(pTime); - if (isValid != SCE_OK) { + if (isValid != ORBIS_OK) { return isValid; } @@ -594,7 +593,7 @@ int PS4_SYSV_ABI sceRtcGetDosTime(OrbisRtcDateTime* pTime, unsigned int* dosTime *dosTime |= (pTime->month & 0x0F) << 21; *dosTime |= ((pTime->year - 1980) & 0x7F) << 25; - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcGetTick(OrbisRtcDateTime* pTime, OrbisRtcTick* pTick) { @@ -629,10 +628,10 @@ int PS4_SYSV_ABI sceRtcGetTick(OrbisRtcDateTime* pTime, OrbisRtcTick* pTick) { pTick->tick = days + msec; - return SCE_OK; + return ORBIS_OK; } -unsigned int PS4_SYSV_ABI sceRtcGetTickResolution() { +u32 PS4_SYSV_ABI sceRtcGetTickResolution() { LOG_TRACE(Lib_Rtc, "called"); return 1000000; @@ -645,7 +644,7 @@ int PS4_SYSV_ABI sceRtcGetTime_t(OrbisRtcDateTime* pTime, time_t* llTime) { return ORBIS_RTC_ERROR_INVALID_POINTER; int isValid = sceRtcCheckValid(pTime); - if (isValid != SCE_OK) { + if (isValid != ORBIS_OK) { return isValid; } @@ -658,7 +657,7 @@ int PS4_SYSV_ABI sceRtcGetTime_t(OrbisRtcDateTime* pTime, time_t* llTime) { *llTime = (timeTick.tick - UNIX_EPOCH_TICKS) / 1000000; } - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcGetWin32FileTime(OrbisRtcDateTime* pTime, uint64_t* ulWin32Time) { @@ -668,7 +667,7 @@ int PS4_SYSV_ABI sceRtcGetWin32FileTime(OrbisRtcDateTime* pTime, uint64_t* ulWin return ORBIS_RTC_ERROR_INVALID_POINTER; int isValid = sceRtcCheckValid(pTime); - if (isValid != SCE_OK) { + if (isValid != ORBIS_OK) { return isValid; } @@ -681,11 +680,11 @@ int PS4_SYSV_ABI sceRtcGetWin32FileTime(OrbisRtcDateTime* pTime, uint64_t* ulWin *ulWin32Time = (timeTick.tick - WIN32_FILETIME_EPOCH_TICKS) * 10; } - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcInit() { - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcIsLeapYear(int yearInt) { @@ -790,7 +789,7 @@ int PS4_SYSV_ABI sceRtcParseDateTime(OrbisRtcTick* pTickUtc, const char* pszDate sceRtcGetTick(&dateTime, pTickUtc); } - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcParseRFC3339(OrbisRtcTick* pTickUtc, const char* pszDateTime) { @@ -825,7 +824,7 @@ int PS4_SYSV_ABI sceRtcParseRFC3339(OrbisRtcTick* pTickUtc, const char* pszDateT } } - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcSetConf() { @@ -869,7 +868,7 @@ int PS4_SYSV_ABI sceRtcSetDosTime(OrbisRtcDateTime* pTime, u32 dosTime) { pTime->day = days & 0x1f; pTime->month = (days >> 5) & 0x0f; pTime->year = (days >> 9) + 1980; - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcSetTick(OrbisRtcDateTime* pTime, OrbisRtcTick* pTick) { @@ -918,7 +917,7 @@ int PS4_SYSV_ABI sceRtcSetTick(OrbisRtcDateTime* pTime, OrbisRtcTick* pTick) { msec %= 1000000; pTime->microsecond = msec; - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcSetTime_t(OrbisRtcDateTime* pTime, time_t llTime) { @@ -946,7 +945,7 @@ int PS4_SYSV_ABI sceRtcSetTime_t(OrbisRtcDateTime* pTime, time_t llTime) { newTick.tick += UNIX_EPOCH_TICKS; sceRtcSetTick(pTime, &newTick); - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcSetWin32FileTime(OrbisRtcDateTime* pTime, int64_t ulWin32Time) { @@ -962,7 +961,7 @@ int PS4_SYSV_ABI sceRtcSetWin32FileTime(OrbisRtcDateTime* pTime, int64_t ulWin32 sceRtcSetTick(pTime, &convertedTick); - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcTickAddDays(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2, int32_t lAdd) { @@ -973,7 +972,7 @@ int PS4_SYSV_ABI sceRtcTickAddDays(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2, i pTick1->tick = (lAdd * 86400000000) + pTick2->tick; - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcTickAddHours(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2, int32_t lAdd) { @@ -984,7 +983,7 @@ int PS4_SYSV_ABI sceRtcTickAddHours(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2, pTick1->tick = (lAdd * 3600000000) + pTick2->tick; - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcTickAddMicroseconds(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2, @@ -996,7 +995,7 @@ int PS4_SYSV_ABI sceRtcTickAddMicroseconds(OrbisRtcTick* pTick1, OrbisRtcTick* p pTick1->tick = lAdd + pTick2->tick; - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcTickAddMinutes(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2, int64_t lAdd) { @@ -1007,7 +1006,7 @@ int PS4_SYSV_ABI sceRtcTickAddMinutes(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2 pTick1->tick = (lAdd * 60000000) + pTick2->tick; - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcTickAddMonths(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2, int32_t lAdd) { @@ -1018,7 +1017,7 @@ int PS4_SYSV_ABI sceRtcTickAddMonths(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2, if (lAdd == 0) { pTick1->tick = pTick2->tick; - return SCE_OK; + return ORBIS_OK; } OrbisRtcDateTime time; @@ -1054,13 +1053,13 @@ int PS4_SYSV_ABI sceRtcTickAddMonths(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2, } int timeIsValid = sceRtcCheckValid(&time); - if (timeIsValid == SCE_OK) { + if (timeIsValid == ORBIS_OK) { sceRtcGetTick(&time, pTick1); } else { return timeIsValid; } - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcTickAddSeconds(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2, int64_t lAdd) { @@ -1071,7 +1070,7 @@ int PS4_SYSV_ABI sceRtcTickAddSeconds(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2 pTick1->tick = (lAdd * 1000000) + pTick2->tick; - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcTickAddTicks(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2, int64_t lAdd) { @@ -1082,7 +1081,7 @@ int PS4_SYSV_ABI sceRtcTickAddTicks(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2, pTick1->tick = lAdd + pTick2->tick; - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcTickAddWeeks(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2, int32_t lAdd) { @@ -1093,7 +1092,7 @@ int PS4_SYSV_ABI sceRtcTickAddWeeks(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2, pTick1->tick = (lAdd * 604800000000) + pTick2->tick; - return SCE_OK; + return ORBIS_OK; } int PS4_SYSV_ABI sceRtcTickAddYears(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2, int32_t lAdd) { @@ -1106,7 +1105,7 @@ int PS4_SYSV_ABI sceRtcTickAddYears(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2, if (lAdd == 0) { pTick1->tick = pTick2->tick; - return SCE_OK; + return ORBIS_OK; } sceRtcSetTick(&time, pTick1); @@ -1114,13 +1113,13 @@ int PS4_SYSV_ABI sceRtcTickAddYears(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2, time.year += lAdd; int timeIsValid = sceRtcCheckValid(&time); - if (timeIsValid == SCE_OK) { + if (timeIsValid == ORBIS_OK) { sceRtcGetTick(&time, pTick1); } else { return timeIsValid; } - return SCE_OK; + return ORBIS_OK; } void RegisterlibSceRtc(Core::Loader::SymbolsResolver* sym) { diff --git a/src/core/libraries/rtc/rtc.h b/src/core/libraries/rtc/rtc.h index c4104086..eb7afa00 100644 --- a/src/core/libraries/rtc/rtc.h +++ b/src/core/libraries/rtc/rtc.h @@ -3,6 +3,7 @@ #pragma once +#include #include "common/types.h" namespace Core::Loader { @@ -19,21 +20,21 @@ constexpr int ORBIS_RTC_DAYOFWEEK_THURSDAY = 4; constexpr int ORBIS_RTC_DAYOFWEEK_FRIDAY = 5; constexpr int ORBIS_RTC_DAYOFWEEK_SATURDAY = 6; -constexpr int64_t UNIX_EPOCH_TICKS = 0xdcbffeff2bc000; -constexpr int64_t WIN32_FILETIME_EPOCH_TICKS = 0xb36168b6a58000; +constexpr s64 UNIX_EPOCH_TICKS = 0xdcbffeff2bc000; +constexpr s64 WIN32_FILETIME_EPOCH_TICKS = 0xb36168b6a58000; struct OrbisRtcTick { - uint64_t tick; + u64 tick; }; struct OrbisRtcDateTime { - uint16_t year; - uint16_t month; - uint16_t day; - uint16_t hour; - uint16_t minute; - uint16_t second; - uint32_t microsecond; + u16 year; + u16 month; + u16 day; + u16 hour; + u16 minute; + u16 second; + u32 microsecond; }; int PS4_SYSV_ABI sceRtcCheckValid(OrbisRtcDateTime* pTime); @@ -58,9 +59,9 @@ int PS4_SYSV_ABI sceRtcGetCurrentRawNetworkTick(OrbisRtcTick* pTick); int PS4_SYSV_ABI sceRtcGetCurrentTick(OrbisRtcTick* pTick); int PS4_SYSV_ABI sceRtcGetDayOfWeek(int year, int month, int day); int PS4_SYSV_ABI sceRtcGetDaysInMonth(int year, int month); -int PS4_SYSV_ABI sceRtcGetDosTime(OrbisRtcDateTime* pTime, unsigned int* dosTime); +int PS4_SYSV_ABI sceRtcGetDosTime(OrbisRtcDateTime* pTime, u32* dosTime); int PS4_SYSV_ABI sceRtcGetTick(OrbisRtcDateTime* pTime, OrbisRtcTick* pTick); -unsigned int PS4_SYSV_ABI sceRtcGetTickResolution(); +u32 PS4_SYSV_ABI sceRtcGetTickResolution(); int PS4_SYSV_ABI sceRtcGetTime_t(OrbisRtcDateTime* pTime, time_t* llTime); int PS4_SYSV_ABI sceRtcGetWin32FileTime(OrbisRtcDateTime* pTime, uint64_t* ulWin32Time); int PS4_SYSV_ABI sceRtcInit(); @@ -88,4 +89,4 @@ int PS4_SYSV_ABI sceRtcTickAddWeeks(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2, int PS4_SYSV_ABI sceRtcTickAddYears(OrbisRtcTick* pTick1, OrbisRtcTick* pTick2, int32_t lAdd); void RegisterlibSceRtc(Core::Loader::SymbolsResolver* sym); -} // namespace Libraries::Rtc \ No newline at end of file +} // namespace Libraries::Rtc diff --git a/src/core/libraries/rtc/rtc_error.h b/src/core/libraries/rtc/rtc_error.h index 3af5a68f..406c6fb5 100644 --- a/src/core/libraries/rtc/rtc_error.h +++ b/src/core/libraries/rtc/rtc_error.h @@ -3,6 +3,8 @@ #pragma once +#include "core/libraries/error_codes.h" + constexpr int ORBIS_RTC_ERROR_DATETIME_UNINITIALIZED = 0x7FFEF9FE; constexpr int ORBIS_RTC_ERROR_INVALID_PARAMETER = 0x80010602; constexpr int ORBIS_RTC_ERROR_INVALID_TICK_PARAMETER = 0x80010603; @@ -29,4 +31,4 @@ constexpr int ORBIS_RTC_ERROR_INVALID_DAY = 0x80B5000A; constexpr int ORBIS_RTC_ERROR_INVALID_HOUR = 0x80B5000B; constexpr int ORBIS_RTC_ERROR_INVALID_MINUTE = 0x80B5000C; constexpr int ORBIS_RTC_ERROR_INVALID_SECOND = 0x80B5000D; -constexpr int ORBIS_RTC_ERROR_INVALID_MICROSECOND = 0x80B5000E; \ No newline at end of file +constexpr int ORBIS_RTC_ERROR_INVALID_MICROSECOND = 0x80B5000E; diff --git a/src/core/libraries/system/systemservice.cpp b/src/core/libraries/system/systemservice.cpp index 4e7f9257..ebb9f439 100644 --- a/src/core/libraries/system/systemservice.cpp +++ b/src/core/libraries/system/systemservice.cpp @@ -3,9 +3,9 @@ #include "common/config.h" #include "common/logging/log.h" -#include "core/libraries/error_codes.h" #include "core/libraries/libs.h" #include "core/libraries/system/systemservice.h" +#include "core/libraries/system/systemservice_error.h" namespace Libraries::SystemService { @@ -1772,14 +1772,12 @@ s32 PS4_SYSV_ABI sceSystemServiceGetStatus(OrbisSystemServiceStatus* status) { LOG_ERROR(Lib_SystemService, "OrbisSystemServiceStatus is null"); return ORBIS_SYSTEM_SERVICE_ERROR_PARAMETER; } - OrbisSystemServiceStatus st = {}; - st.eventNum = 0; - st.isSystemUiOverlaid = false; - st.isInBackgroundExecution = false; - st.isCpuMode7CpuNormal = true; - st.isGameLiveStreamingOnAir = false; - st.isOutOfVrPlayArea = false; - *status = st; + status->event_num = 0; + status->is_system_ui_overlaid = false; + status->is_in_background_execution = false; + status->is_cpu_mode7_cpu_normal = true; + status->is_game_live_streaming_on_air = false; + status->is_out_of_vr_play_area = false; return ORBIS_OK; } @@ -1889,39 +1887,38 @@ int PS4_SYSV_ABI sceSystemServiceNavigateToGoHome() { return ORBIS_OK; } -s32 PS4_SYSV_ABI sceSystemServiceParamGetInt(int param_id, int* value) { +s32 PS4_SYSV_ABI sceSystemServiceParamGetInt(OrbisSystemServiceParamId param_id, int* value) { // TODO this probably should be stored in config for UI configuration - LOG_INFO(Lib_SystemService, "called param_id {}", param_id); + LOG_INFO(Lib_SystemService, "called param_id {}", u32(param_id)); if (value == nullptr) { LOG_ERROR(Lib_SystemService, "value is null"); return ORBIS_SYSTEM_SERVICE_ERROR_PARAMETER; } switch (param_id) { - case ORBIS_SYSTEM_SERVICE_PARAM_ID_LANG: + case OrbisSystemServiceParamId::Lang: *value = Config::GetLanguage(); break; - case ORBIS_SYSTEM_SERVICE_PARAM_ID_DATE_FORMAT: - *value = ORBIS_SYSTEM_PARAM_DATE_FORMAT_DDMMYYYY; + case OrbisSystemServiceParamId::DateFormat: + *value = u32(OrbisSystemParamDateFormat::FmtDDMMYYYY); break; - case ORBIS_SYSTEM_SERVICE_PARAM_ID_TIME_FORMAT: - *value = ORBIS_SYSTEM_PARAM_TIME_FORMAT_24HOUR; + case OrbisSystemServiceParamId::TimeFormat: + *value = u32(OrbisSystemParamTimeFormat::Fmt24Hour); break; - case ORBIS_SYSTEM_SERVICE_PARAM_ID_TIME_ZONE: + case OrbisSystemServiceParamId::TimeZone: *value = +120; break; - case ORBIS_SYSTEM_SERVICE_PARAM_ID_SUMMERTIME: + case OrbisSystemServiceParamId::Summertime: *value = 1; break; - case ORBIS_SYSTEM_SERVICE_PARAM_ID_GAME_PARENTAL_LEVEL: - *value = ORBIS_SYSTEM_PARAM_GAME_PARENTAL_OFF; + case OrbisSystemServiceParamId::GameParentalLevel: + *value = u32(OrbisSystemParamGameParentalLevel::Off); break; - case ORBIS_SYSTEM_SERVICE_PARAM_ID_ENTER_BUTTON_ASSIGN: - *value = ORBIS_SYSTEM_PARAM_ENTER_BUTTON_ASSIGN_CROSS; + case OrbisSystemServiceParamId::EnterButtonAssign: + *value = u32(OrbisSystemParamEnterButtonAssign::Cross); break; default: - LOG_ERROR(Lib_SystemService, "param_id {} unsupported!", - param_id); // shouldn't go there but log it - *value = 0; // return a dummy value + LOG_ERROR(Lib_SystemService, "param_id {} unsupported!", u32(param_id)); + *value = 0; } return ORBIS_OK; diff --git a/src/core/libraries/system/systemservice.h b/src/core/libraries/system/systemservice.h index 56583c97..cdd3c15e 100644 --- a/src/core/libraries/system/systemservice.h +++ b/src/core/libraries/system/systemservice.h @@ -12,114 +12,81 @@ class SymbolsResolver; namespace Libraries::SystemService { -enum OrbisSystemServiceParamId { - ORBIS_SYSTEM_SERVICE_PARAM_ID_LANG = 1, - ORBIS_SYSTEM_SERVICE_PARAM_ID_DATE_FORMAT = 2, - ORBIS_SYSTEM_SERVICE_PARAM_ID_TIME_FORMAT = 3, - ORBIS_SYSTEM_SERVICE_PARAM_ID_TIME_ZONE = 4, - ORBIS_SYSTEM_SERVICE_PARAM_ID_SUMMERTIME = 5, - ORBIS_SYSTEM_SERVICE_PARAM_ID_SYSTEM_NAME = 6, - ORBIS_SYSTEM_SERVICE_PARAM_ID_GAME_PARENTAL_LEVEL = 7, - ORBIS_SYSTEM_SERVICE_PARAM_ID_ENTER_BUTTON_ASSIGN = 1000 +enum class OrbisSystemServiceParamId { + Lang = 1, + DateFormat = 2, + TimeFormat = 3, + TimeZone = 4, + Summertime = 5, + SystemName = 6, + GameParentalLevel = 7, + EnterButtonAssign = 1000, }; -enum OrbisSystemParamDateFormat { - ORBIS_SYSTEM_PARAM_DATE_FORMAT_YYYYMMDD = 0, - ORBIS_SYSTEM_PARAM_DATE_FORMAT_DDMMYYYY = 1, - ORBIS_SYSTEM_PARAM_DATE_FORMAT_MMDDYYYY = 2 +enum class OrbisSystemParamDateFormat { + FmtYYYYMMDD = 0, + FmtDDMMYYYY = 1, + FmtMMDDYYYY = 2, }; -enum OrbisSystemParamTimeFormat { - ORBIS_SYSTEM_PARAM_TIME_FORMAT_12HOUR = 0, - ORBIS_SYSTEM_PARAM_TIME_FORMAT_24HOUR = 1 +enum class OrbisSystemParamTimeFormat { + Fmt12Hour = 0, + Fmt24Hour = 1, }; -enum OrbisSystemParamGameParentalLevel { - ORBIS_SYSTEM_PARAM_GAME_PARENTAL_OFF = 0, - ORBIS_SYSTEM_PARAM_GAME_PARENTAL_LEVEL01 = 1, - ORBIS_SYSTEM_PARAM_GAME_PARENTAL_LEVEL02 = 2, - ORBIS_SYSTEM_PARAM_GAME_PARENTAL_LEVEL03 = 3, - ORBIS_SYSTEM_PARAM_GAME_PARENTAL_LEVEL04 = 4, - ORBIS_SYSTEM_PARAM_GAME_PARENTAL_LEVEL05 = 5, - ORBIS_SYSTEM_PARAM_GAME_PARENTAL_LEVEL06 = 6, - ORBIS_SYSTEM_PARAM_GAME_PARENTAL_LEVEL07 = 7, - ORBIS_SYSTEM_PARAM_GAME_PARENTAL_LEVEL08 = 8, - ORBIS_SYSTEM_PARAM_GAME_PARENTAL_LEVEL09 = 9, - ORBIS_SYSTEM_PARAM_GAME_PARENTAL_LEVEL10 = 10, - ORBIS_SYSTEM_PARAM_GAME_PARENTAL_LEVEL11 = 11 +enum class OrbisSystemParamGameParentalLevel { + Off = 0, + Level01 = 1, + Level02 = 2, + Level03 = 3, + Level04 = 4, + Level05 = 5, + Level06 = 6, + Level07 = 7, + Level08 = 8, + Level09 = 9, + Level10 = 10, + Level11 = 11, }; -enum OrbisSystemParamEnterButtonAssign { - ORBIS_SYSTEM_PARAM_ENTER_BUTTON_ASSIGN_CIRCLE = 0, - ORBIS_SYSTEM_PARAM_ENTER_BUTTON_ASSIGN_CROSS = 1 +enum class OrbisSystemParamEnterButtonAssign { + Circle = 0, + Cross = 1, }; -enum OrbisSystemParamLanguage { - ORBIS_SYSTEM_PARAM_LANG_JAPANESE = 0, - ORBIS_SYSTEM_PARAM_LANG_ENGLISH_US = 1, - ORBIS_SYSTEM_PARAM_LANG_FRENCH = 2, - ORBIS_SYSTEM_PARAM_LANG_SPANISH = 3, - ORBIS_SYSTEM_PARAM_LANG_GERMAN = 4, - ORBIS_SYSTEM_PARAM_LANG_ITALIAN = 5, - ORBIS_SYSTEM_PARAM_LANG_DUTCH = 6, - ORBIS_SYSTEM_PARAM_LANG_PORTUGUESE_PT = 7, - ORBIS_SYSTEM_PARAM_LANG_RUSSIAN = 8, - ORBIS_SYSTEM_PARAM_LANG_KOREAN = 9, - ORBIS_SYSTEM_PARAM_LANG_CHINESE_T = 10, - ORBIS_SYSTEM_PARAM_LANG_CHINESE_S = 11, - ORBIS_SYSTEM_PARAM_LANG_FINNISH = 12, - ORBIS_SYSTEM_PARAM_LANG_SWEDISH = 13, - ORBIS_SYSTEM_PARAM_LANG_DANISH = 14, - ORBIS_SYSTEM_PARAM_LANG_NORWEGIAN = 15, - ORBIS_SYSTEM_PARAM_LANG_POLISH = 16, - ORBIS_SYSTEM_PARAM_LANG_PORTUGUESE_BR = 17, - ORBIS_SYSTEM_PARAM_LANG_ENGLISH_GB = 18, - ORBIS_SYSTEM_PARAM_LANG_TURKISH = 19, - ORBIS_SYSTEM_PARAM_LANG_SPANISH_LA = 20, - ORBIS_SYSTEM_PARAM_LANG_ARABIC = 21, - ORBIS_SYSTEM_PARAM_LANG_FRENCH_CA = 22, - ORBIS_SYSTEM_PARAM_LANG_CZECH = 23, - ORBIS_SYSTEM_PARAM_LANG_HUNGARIAN = 24, - ORBIS_SYSTEM_PARAM_LANG_GREEK = 25, - ORBIS_SYSTEM_PARAM_LANG_ROMANIAN = 26, - ORBIS_SYSTEM_PARAM_LANG_THAI = 27, - ORBIS_SYSTEM_PARAM_LANG_VIETNAMESE = 28, - ORBIS_SYSTEM_PARAM_LANG_INDONESIAN = 29 -}; - -enum OrbisSystemServiceEventType { - ORBIS_SYSTEM_SERVICE_EVENT_INVALID = -1, - ORBIS_SYSTEM_SERVICE_EVENT_ON_RESUME = 0x10000000, - ORBIS_SYSTEM_SERVICE_EVENT_GAME_LIVE_STREAMING_STATUS_UPDATE = 0x10000001, - ORBIS_SYSTEM_SERVICE_EVENT_SESSION_INVITATION = 0x10000002, - ORBIS_SYSTEM_SERVICE_EVENT_ENTITLEMENT_UPDATE = 0x10000003, - ORBIS_SYSTEM_SERVICE_EVENT_GAME_CUSTOM_DATA = 0x10000004, - ORBIS_SYSTEM_SERVICE_EVENT_DISPLAY_SAFE_AREA_UPDATE = 0x10000005, - ORBIS_SYSTEM_SERVICE_EVENT_URL_OPEN = 0x10000006, - ORBIS_SYSTEM_SERVICE_EVENT_LAUNCH_APP = 0x10000007, - ORBIS_SYSTEM_SERVICE_EVENT_APP_LAUNCH_LINK = 0x10000008, - ORBIS_SYSTEM_SERVICE_EVENT_ADDCONTENT_INSTALL = 0x10000009, - ORBIS_SYSTEM_SERVICE_EVENT_RESET_VR_POSITION = 0x1000000a, - ORBIS_SYSTEM_SERVICE_EVENT_JOIN_EVENT = 0x1000000b, - ORBIS_SYSTEM_SERVICE_EVENT_PLAYGO_LOCUS_UPDATE = 0x1000000c, - ORBIS_SYSTEM_SERVICE_EVENT_PLAY_TOGETHER_HOST = 0x1000000d, - ORBIS_SYSTEM_SERVICE_EVENT_SERVICE_ENTITLEMENT_UPDATE = 0x1000000e, - ORBIS_SYSTEM_SERVICE_EVENT_EYE_TO_EYE_DISTANCE_UPDATE = 0x1000000f, - ORBIS_SYSTEM_SERVICE_EVENT_JOIN_MATCH_EVENT = 0x10000010, - ORBIS_SYSTEM_SERVICE_EVENT_PLAY_TOGETHER_HOST_A = 0x10000011, - ORBIS_SYSTEM_SERVICE_EVENT_WEBBROWSER_CLOSED = 0x10000012, - ORBIS_SYSTEM_SERVICE_EVENT_CONTROLLER_SETTINGS_CLOSED = 0x10000013, - ORBIS_SYSTEM_SERVICE_EVENT_JOIN_TEAM_ON_TEAM_MATCH_EVENT = 0x10000014, - ORBIS_SYSTEM_SERVICE_EVENT_OPEN_SHARE_MENU = 0x30000000 +enum class OrbisSystemServiceEventType { + Invalid = -1, + OnResume = 0x10000000, + GameLiveStreamingStatusUpdate = 0x10000001, + SessionInvitation = 0x10000002, + EntitlementUpdate = 0x10000003, + GameCustomData = 0x10000004, + DisplaySafeAreaUpdate = 0x10000005, + UrlOpen = 0x10000006, + LaunchApp = 0x10000007, + AppLaunchLink = 0x10000008, + AddcontentInstall = 0x10000009, + ResetVrPosition = 0x1000000a, + JoinEvent = 0x1000000b, + PlaygoLocusUpdate = 0x1000000c, + PlayTogetherHost = 0x1000000d, + ServiceEntitlementUpdate = 0x1000000e, + EyeToEyeDistanceUpdate = 0x1000000f, + JoinMatchEvent = 0x10000010, + PlayTogetherHostA = 0x10000011, + WebBrowserClosed = 0x10000012, + ControllerSettingsClosed = 0x10000013, + JoinTeamOnTeamMatchEvent = 0x10000014, + OpenShareMenu = 0x30000000 }; struct OrbisSystemServiceStatus { - s32 eventNum; - bool isSystemUiOverlaid; - bool isInBackgroundExecution; - bool isCpuMode7CpuNormal; - bool isGameLiveStreamingOnAir; - bool isOutOfVrPlayArea; + s32 event_num; + bool is_system_ui_overlaid; + bool is_in_background_execution; + bool is_cpu_mode7_cpu_normal; + bool is_game_live_streaming_on_air; + bool is_out_of_vr_play_area; u8 reserved[]; }; @@ -129,36 +96,36 @@ struct OrbisSystemServiceDisplaySafeAreaInfo { }; struct OrbisSystemServiceEvent { - OrbisSystemServiceEventType eventType; + OrbisSystemServiceEventType event_type; union { char param[8192]; struct { char source[1024]; char url[4096]; - } urlOpen; + } url_open; struct { u32 size; u8 arg[8188]; - } launchApp; + } launch_app; struct { u32 size; u8 arg[2020]; - } appLaunchLink; + } app_launch_link; struct { - s32 userId; - char eventId[37]; - char bootArgument[7169]; - } joinEvent; + s32 user_id; + char event_id[37]; + char boot_argument[7169]; + } join_event; struct { - s32 userId; - u32 npServiceLabel; + s32 user_id; + u32 np_service_label; u8 reserved[8184]; - } serviceEntitlementUpdate; + } service_entitlement_update; struct { - s32 userId; - u32 npServiceLabel; + s32 user_id; + u32 np_service_label; u8 reserved[8184]; - } unifiedEntitlementUpdate; + } unified_entitlement_update; u8 reserved[8192]; }; }; @@ -537,7 +504,7 @@ int PS4_SYSV_ABI sceSystemServiceNavigateToAnotherApp(); int PS4_SYSV_ABI sceSystemServiceNavigateToGoBack(); int PS4_SYSV_ABI sceSystemServiceNavigateToGoBackWithValue(); int PS4_SYSV_ABI sceSystemServiceNavigateToGoHome(); -s32 PS4_SYSV_ABI sceSystemServiceParamGetInt(int param_id, int* value); +s32 PS4_SYSV_ABI sceSystemServiceParamGetInt(OrbisSystemServiceParamId param_id, int* value); int PS4_SYSV_ABI sceSystemServiceParamGetString(); int PS4_SYSV_ABI sceSystemServicePowerTick(); int PS4_SYSV_ABI sceSystemServiceRaiseExceptionLocalProcess(); diff --git a/src/core/libraries/system/systemservice_error.h b/src/core/libraries/system/systemservice_error.h new file mode 100644 index 00000000..ca59fab6 --- /dev/null +++ b/src/core/libraries/system/systemservice_error.h @@ -0,0 +1,10 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/libraries/error_codes.h" + +// SystemService library +constexpr int ORBIS_SYSTEM_SERVICE_ERROR_PARAMETER = 0x80A10003; +constexpr int ORBIS_SYSTEM_SERVICE_ERROR_NO_EVENT = 0x80A10004; diff --git a/src/core/libraries/system/userservice.cpp b/src/core/libraries/system/userservice.cpp index 140ca892..e1f9f75e 100644 --- a/src/core/libraries/system/userservice.cpp +++ b/src/core/libraries/system/userservice.cpp @@ -4,9 +4,9 @@ #include "common/config.h" #include "common/logging/log.h" -#include "core/libraries/error_codes.h" #include "core/libraries/libs.h" #include "core/libraries/system/userservice.h" +#include "core/libraries/system/userservice_error.h" namespace Libraries::UserService { @@ -112,7 +112,7 @@ s32 PS4_SYSV_ABI sceUserServiceGetEvent(OrbisUserServiceEvent* event) { if (!logged_in) { logged_in = true; - event->event = SCE_USER_SERVICE_EVENT_TYPE_LOGIN; + event->event = OrbisUserServiceEventType::Login; event->userId = 1; return ORBIS_OK; } @@ -1041,14 +1041,14 @@ int PS4_SYSV_ABI sceUserServiceGetTraditionalChineseInputType() { return ORBIS_OK; } -s32 PS4_SYSV_ABI sceUserServiceGetUserColor(int user_id, int* color) { +s32 PS4_SYSV_ABI sceUserServiceGetUserColor(int user_id, OrbisUserServiceUserColor* color) { // TODO fix me better LOG_INFO(Lib_UserService, "called user_id = {}", user_id); if (color == nullptr) { LOG_ERROR(Lib_UserService, "color is null"); return ORBIS_USER_SERVICE_ERROR_INVALID_ARGUMENT; } - *color = ORBIS_USER_SERVICE_USER_COLOR_BLUE; + *color = OrbisUserServiceUserColor::Blue; return ORBIS_OK; } diff --git a/src/core/libraries/system/userservice.h b/src/core/libraries/system/userservice.h index 5bb1fd04..66ac2b69 100644 --- a/src/core/libraries/system/userservice.h +++ b/src/core/libraries/system/userservice.h @@ -40,16 +40,16 @@ struct OrbisUserServiceRegisteredUserIdList { OrbisUserServiceUserId userId[ORBIS_USER_SERVICE_MAX_REGISTER_USERS]; }; -enum OrbisUserServiceUserColor { - ORBIS_USER_SERVICE_USER_COLOR_BLUE = 0, - ORBIS_USER_SERVICE_USER_COLOR_RED = 1, - ORBIS_USER_SERVICE_USER_COLOR_GREEN = 2, - ORBIS_USER_SERVICE_USER_COLOR_PINK = 3, +enum class OrbisUserServiceUserColor { + Blue = 0, + Red = 1, + Green = 2, + Pink = 3, }; -enum OrbisUserServiceEventType { - SCE_USER_SERVICE_EVENT_TYPE_LOGIN = 0, // Login event - SCE_USER_SERVICE_EVENT_TYPE_LOGOUT = 1, // Logout event +enum class OrbisUserServiceEventType { + Login = 0, // Login event + Logout = 1, // Logout event }; struct OrbisUserServiceEvent { @@ -258,7 +258,7 @@ int PS4_SYSV_ABI sceUserServiceGetTopMenuLimitItem(); int PS4_SYSV_ABI sceUserServiceGetTopMenuNotificationFlag(); int PS4_SYSV_ABI sceUserServiceGetTopMenuTutorialFlag(); int PS4_SYSV_ABI sceUserServiceGetTraditionalChineseInputType(); -s32 PS4_SYSV_ABI sceUserServiceGetUserColor(int user_id, int* color); +s32 PS4_SYSV_ABI sceUserServiceGetUserColor(int user_id, OrbisUserServiceUserColor* color); int PS4_SYSV_ABI sceUserServiceGetUserGroupName(); int PS4_SYSV_ABI sceUserServiceGetUserGroupNameList(); int PS4_SYSV_ABI sceUserServiceGetUserGroupNum(); diff --git a/src/core/libraries/system/userservice_error.h b/src/core/libraries/system/userservice_error.h new file mode 100644 index 00000000..40921df9 --- /dev/null +++ b/src/core/libraries/system/userservice_error.h @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/libraries/error_codes.h" + +// UserService library +constexpr int ORBIS_USER_SERVICE_ERROR_INTERNAL = 0x80960001; +constexpr int ORBIS_USER_SERVICE_ERROR_NOT_INITIALIZED = 0x80960002; +constexpr int ORBIS_USER_SERVICE_ERROR_ALREADY_INITIALIZED = 0x80960003; +constexpr int ORBIS_USER_SERVICE_ERROR_NO_MEMORY = 0x80960004; +constexpr int ORBIS_USER_SERVICE_ERROR_INVALID_ARGUMENT = 0x80960005; +constexpr int ORBIS_USER_SERVICE_ERROR_OPERATION_NOT_SUPPORTED = 0x80960006; +constexpr int ORBIS_USER_SERVICE_ERROR_NO_EVENT = 0x80960007; +constexpr int ORBIS_USER_SERVICE_ERROR_NOT_LOGGED_IN = 0x80960009; +constexpr int ORBIS_USER_SERVICE_ERROR_BUFFER_TOO_SHORT = 0x8096000A; diff --git a/src/core/libraries/videodec/videodec.cpp b/src/core/libraries/videodec/videodec.cpp index 8d6ea498..6c9a9b8c 100644 --- a/src/core/libraries/videodec/videodec.cpp +++ b/src/core/libraries/videodec/videodec.cpp @@ -1,12 +1,11 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "videodec.h" - #include "common/logging/log.h" -#include "core/libraries/error_codes.h" #include "core/libraries/libs.h" -#include "videodec_impl.h" +#include "core/libraries/videodec/videodec.h" +#include "core/libraries/videodec/videodec_error.h" +#include "core/libraries/videodec/videodec_impl.h" namespace Libraries::Videodec { @@ -134,4 +133,4 @@ void RegisterlibSceVideodec(Core::Loader::SymbolsResolver* sym) { LIB_FUNCTION("f8AgDv-1X8A", "libSceVideodec", 1, "libSceVideodec", 1, 1, sceVideodecReset); }; -} // namespace Libraries::Videodec \ No newline at end of file +} // namespace Libraries::Videodec diff --git a/src/core/libraries/videodec/videodec2.cpp b/src/core/libraries/videodec/videodec2.cpp index fe2b82be..0bd68afb 100644 --- a/src/core/libraries/videodec/videodec2.cpp +++ b/src/core/libraries/videodec/videodec2.cpp @@ -1,13 +1,12 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "videodec2.h" -#include "videodec2_impl.h" - #include "common/assert.h" #include "common/logging/log.h" -#include "core/libraries/error_codes.h" #include "core/libraries/libs.h" +#include "core/libraries/videodec/videodec2.h" +#include "core/libraries/videodec/videodec2_impl.h" +#include "core/libraries/videodec/videodec_error.h" namespace Libraries::Vdec2 { @@ -197,4 +196,4 @@ void RegisterlibSceVdec2(Core::Loader::SymbolsResolver* sym) { sceVideodec2GetPictureInfo); } -} // namespace Libraries::Vdec2 \ No newline at end of file +} // namespace Libraries::Vdec2 diff --git a/src/core/libraries/videodec/videodec2.h b/src/core/libraries/videodec/videodec2.h index 9b230cc5..4617e1c2 100644 --- a/src/core/libraries/videodec/videodec2.h +++ b/src/core/libraries/videodec/videodec2.h @@ -15,7 +15,7 @@ namespace Libraries::Vdec2 { class VdecDecoder; using OrbisVideodec2Decoder = VdecDecoder*; -typedef void* OrbisVideodec2ComputeQueue; +using OrbisVideodec2ComputeQueue = void*; struct OrbisVideodec2DecoderConfigInfo { u64 thisSize; diff --git a/src/core/libraries/videodec/videodec2_impl.cpp b/src/core/libraries/videodec/videodec2_impl.cpp index 37270fa8..8daa4882 100644 --- a/src/core/libraries/videodec/videodec2_impl.cpp +++ b/src/core/libraries/videodec/videodec2_impl.cpp @@ -3,10 +3,9 @@ #include "videodec2_impl.h" -#include "common/alignment.h" #include "common/assert.h" #include "common/logging/log.h" -#include "core/libraries/error_codes.h" +#include "core/libraries/videodec/videodec_error.h" // The av_err2str macro in libavutil/error.h does not play nice with C++ #ifdef av_err2str diff --git a/src/core/libraries/videodec/videodec_error.h b/src/core/libraries/videodec/videodec_error.h new file mode 100644 index 00000000..4e0066e5 --- /dev/null +++ b/src/core/libraries/videodec/videodec_error.h @@ -0,0 +1,68 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/libraries/error_codes.h" + +// Videodec library +constexpr int ORBIS_VIDEODEC_ERROR_API_FAIL = 0x80C10000; +constexpr int ORBIS_VIDEODEC_ERROR_CODEC_TYPE = 0x80C10001; +constexpr int ORBIS_VIDEODEC_ERROR_STRUCT_SIZE = 0x80C10002; +constexpr int ORBIS_VIDEODEC_ERROR_HANDLE = 0x80C10003; +constexpr int ORBIS_VIDEODEC_ERROR_CPU_MEMORY_SIZE = 0x80C10004; +constexpr int ORBIS_VIDEODEC_ERROR_CPU_MEMORY_POINTER = 0x80C10005; +constexpr int ORBIS_VIDEODEC_ERROR_CPU_GPU_MEMORY_SIZE = 0x80C10006; +constexpr int ORBIS_VIDEODEC_ERROR_CPU_GPU_MEMORY_POINTER = 0x80C10007; +constexpr int ORBIS_VIDEODEC_ERROR_SHADER_CONTEXT_POINTER = 0x80C10008; +constexpr int ORBIS_VIDEODEC_ERROR_AU_SIZE = 0x80C10009; +constexpr int ORBIS_VIDEODEC_ERROR_AU_POINTER = 0x80C1000A; +constexpr int ORBIS_VIDEODEC_ERROR_FRAME_BUFFER_SIZE = 0x80C1000B; +constexpr int ORBIS_VIDEODEC_ERROR_FRAME_BUFFER_POINTER = 0x80C1000C; +constexpr int ORBIS_VIDEODEC_ERROR_FRAME_BUFFER_ALIGNMENT = 0x80C1000D; +constexpr int ORBIS_VIDEODEC_ERROR_CONFIG_INFO = 0x80C1000E; +constexpr int ORBIS_VIDEODEC_ERROR_ARGUMENT_POINTER = 0x80C1000F; +constexpr int ORBIS_VIDEODEC_ERROR_NEW_SEQUENCE = 0x80C10010; +constexpr int ORBIS_VIDEODEC_ERROR_DECODE_AU = 0x80C10011; +constexpr int ORBIS_VIDEODEC_ERROR_MISMATCH_SPEC = 0x80C10012; +constexpr int ORBIS_VIDEODEC_ERROR_INVALID_SEQUENCE = 0x80C10013; +constexpr int ORBIS_VIDEODEC_ERROR_FATAL_STREAM = 0x80C10014; +constexpr int ORBIS_VIDEODEC_ERROR_FATAL_STATE = 0x80C10015; + +// Videodec2 library +constexpr int ORBIS_VIDEODEC2_ERROR_API_FAIL = 0x811D0100; +constexpr int ORBIS_VIDEODEC2_ERROR_STRUCT_SIZE = 0x811D0101; +constexpr int ORBIS_VIDEODEC2_ERROR_ARGUMENT_POINTER = 0x811D0102; +constexpr int ORBIS_VIDEODEC2_ERROR_DECODER_INSTANCE = 0x811D0103; +constexpr int ORBIS_VIDEODEC2_ERROR_MEMORY_SIZE = 0x811D0104; +constexpr int ORBIS_VIDEODEC2_ERROR_MEMORY_POINTER = 0x811D0105; +constexpr int ORBIS_VIDEODEC2_ERROR_FRAME_BUFFER_SIZE = 0x811D0106; +constexpr int ORBIS_VIDEODEC2_ERROR_FRAME_BUFFER_POINTER = 0x811D0107; +constexpr int ORBIS_VIDEODEC2_ERROR_FRAME_BUFFER_ALIGNMENT = 0x811D0108; +constexpr int ORBIS_VIDEODEC2_ERROR_NOT_ONION_MEMORY = 0x811D0109; +constexpr int ORBIS_VIDEODEC2_ERROR_NOT_GARLIC_MEMORY = 0x811D010A; +constexpr int ORBIS_VIDEODEC2_ERROR_NOT_DIRECT_MEMORY = 0x811D010B; +constexpr int ORBIS_VIDEODEC2_ERROR_MEMORY_INFO = 0x811D010C; +constexpr int ORBIS_VIDEODEC2_ERROR_ACCESS_UNIT_SIZE = 0x811D010D; +constexpr int ORBIS_VIDEODEC2_ERROR_ACCESS_UNIT_POINTER = 0x811D010E; +constexpr int ORBIS_VIDEODEC2_ERROR_OUTPUT_INFO = 0x811D010F; +constexpr int ORBIS_VIDEODEC2_ERROR_COMPUTE_QUEUE = 0x811D0110; +constexpr int ORBIS_VIDEODEC2_ERROR_FATAL_STATE = 0x811D0111; +constexpr int ORBIS_VIDEODEC2_ERROR_PRESET_VALUE = 0x811D0112; +constexpr int ORBIS_VIDEODEC2_ERROR_CONFIG_INFO = 0x811D0200; +constexpr int ORBIS_VIDEODEC2_ERROR_COMPUTE_PIPE_ID = 0x811D0201; +constexpr int ORBIS_VIDEODEC2_ERROR_COMPUTE_QUEUE_ID = 0x811D0202; +constexpr int ORBIS_VIDEODEC2_ERROR_RESOURCE_TYPE = 0x811D0203; +constexpr int ORBIS_VIDEODEC2_ERROR_CODEC_TYPE = 0x811D0204; +constexpr int ORBIS_VIDEODEC2_ERROR_PROFILE_LEVEL = 0x811D0205; +constexpr int ORBIS_VIDEODEC2_ERROR_PIPELINE_DEPTH = 0x811D0206; +constexpr int ORBIS_VIDEODEC2_ERROR_AFFINITY_MASK = 0x811D0207; +constexpr int ORBIS_VIDEODEC2_ERROR_THREAD_PRIORITY = 0x811D0208; +constexpr int ORBIS_VIDEODEC2_ERROR_DPB_FRAME_COUNT = 0x811D0209; +constexpr int ORBIS_VIDEODEC2_ERROR_FRAME_WIDTH_HEIGHT = 0x811D020A; +constexpr int ORBIS_VIDEODEC2_ERROR_EXTRA_CONFIG_INFO = 0x811D020B; +constexpr int ORBIS_VIDEODEC2_ERROR_NEW_SEQUENCE = 0x811D0300; +constexpr int ORBIS_VIDEODEC2_ERROR_ACCESS_UNIT = 0x811D0301; +constexpr int ORBIS_VIDEODEC2_ERROR_OVERSIZE_DECODE = 0x811D0302; +constexpr int ORBIS_VIDEODEC2_ERROR_INVALID_SEQUENCE = 0x811D0303; +constexpr int ORBIS_VIDEODEC2_ERROR_FATAL_STREAM = 0x811D0304; diff --git a/src/core/libraries/videodec/videodec_impl.cpp b/src/core/libraries/videodec/videodec_impl.cpp index a244c4a6..cf484697 100644 --- a/src/core/libraries/videodec/videodec_impl.cpp +++ b/src/core/libraries/videodec/videodec_impl.cpp @@ -6,7 +6,7 @@ #include "common/alignment.h" #include "common/assert.h" #include "common/logging/log.h" -#include "core/libraries/error_codes.h" +#include "core/libraries/videodec/videodec_error.h" // The av_err2str macro in libavutil/error.h does not play nice with C++ #ifdef av_err2str diff --git a/src/core/libraries/videoout/driver.cpp b/src/core/libraries/videoout/driver.cpp index d8013614..f6c25afe 100644 --- a/src/core/libraries/videoout/driver.cpp +++ b/src/core/libraries/videoout/driver.cpp @@ -8,10 +8,9 @@ #include "common/debug.h" #include "common/thread.h" #include "core/debug_state.h" -#include "core/libraries/error_codes.h" #include "core/libraries/kernel/time.h" #include "core/libraries/videoout/driver.h" -#include "core/platform.h" +#include "core/libraries/videoout/videoout_error.h" #include "video_core/renderer_vulkan/vk_presenter.h" extern std::unique_ptr presenter; @@ -42,10 +41,10 @@ constexpr u32 PixelFormatBpp(PixelFormat pixel_format) { } VideoOutDriver::VideoOutDriver(u32 width, u32 height) { - main_port.resolution.fullWidth = width; - main_port.resolution.fullHeight = height; - main_port.resolution.paneWidth = width; - main_port.resolution.paneHeight = height; + main_port.resolution.full_width = width; + main_port.resolution.full_height = height; + main_port.resolution.pane_width = width; + main_port.resolution.pane_height = height; present_thread = std::jthread([&](std::stop_token token) { PresentThread(token); }); } @@ -174,20 +173,21 @@ void VideoOutDriver::Flip(const Request& req) { std::unique_lock lock{port->port_mutex}; auto& flip_status = port->flip_status; flip_status.count++; - flip_status.processTime = Libraries::Kernel::sceKernelGetProcessTime(); + flip_status.process_time = Libraries::Kernel::sceKernelGetProcessTime(); flip_status.tsc = Libraries::Kernel::sceKernelReadTsc(); - flip_status.flipArg = req.flip_arg; - flip_status.currentBuffer = req.index; + flip_status.flip_arg = req.flip_arg; + flip_status.current_buffer = req.index; if (req.eop) { - --flip_status.gcQueueNum; + --flip_status.gc_queue_num; } - --flip_status.flipPendingNum; + --flip_status.flip_pending_num; } // Trigger flip events for the port. for (auto& event : port->flip_events) { if (event != nullptr) { - event->TriggerEvent(SCE_VIDEO_OUT_EVENT_FLIP, Kernel::SceKernelEvent::Filter::VideoOut, + event->TriggerEvent(u64(OrbisVideoOutEventId::Flip), + Kernel::SceKernelEvent::Filter::VideoOut, reinterpret_cast(req.flip_arg)); } } @@ -211,16 +211,16 @@ bool VideoOutDriver::SubmitFlip(VideoOutPort* port, s32 index, s64 flip_arg, bool is_eop /*= false*/) { { std::unique_lock lock{port->port_mutex}; - if (index != -1 && port->flip_status.flipPendingNum >= port->NumRegisteredBuffers()) { + if (index != -1 && port->flip_status.flip_pending_num >= port->NumRegisteredBuffers()) { LOG_ERROR(Lib_VideoOut, "Flip queue is full"); return false; } if (is_eop) { - ++port->flip_status.gcQueueNum; + ++port->flip_status.gc_queue_num; } - ++port->flip_status.flipPendingNum; // integral GPU and CPU pending flips counter - port->flip_status.submitTsc = Libraries::Kernel::sceKernelReadTsc(); + ++port->flip_status.flip_pending_num; // integral GPU and CPU pending flips counter + port->flip_status.submit_tsc = Libraries::Kernel::sceKernelReadTsc(); } if (!is_eop) { @@ -298,9 +298,9 @@ void VideoOutDriver::PresentThread(std::stop_token token) { { // Needs lock here as can be concurrently read by `sceVideoOutGetVblankStatus` - std::unique_lock lock{main_port.vo_mutex}; + std::scoped_lock lock{main_port.vo_mutex}; vblank_status.count++; - vblank_status.processTime = Libraries::Kernel::sceKernelGetProcessTime(); + vblank_status.process_time = Libraries::Kernel::sceKernelGetProcessTime(); vblank_status.tsc = Libraries::Kernel::sceKernelReadTsc(); main_port.vblank_cv.notify_all(); } @@ -308,7 +308,7 @@ void VideoOutDriver::PresentThread(std::stop_token token) { // Trigger flip events for the port. for (auto& event : main_port.vblank_events) { if (event != nullptr) { - event->TriggerEvent(SCE_VIDEO_OUT_EVENT_VBLANK, + event->TriggerEvent(u64(OrbisVideoOutEventId::Vblank), Kernel::SceKernelEvent::Filter::VideoOut, nullptr); } } diff --git a/src/core/libraries/videoout/video_out.cpp b/src/core/libraries/videoout/video_out.cpp index 0258074d..ee4a8934 100644 --- a/src/core/libraries/videoout/video_out.cpp +++ b/src/core/libraries/videoout/video_out.cpp @@ -4,12 +4,11 @@ #include "common/assert.h" #include "common/config.h" #include "common/logging/log.h" -#include "core/libraries/error_codes.h" #include "core/libraries/libs.h" #include "core/libraries/system/userservice.h" #include "core/libraries/videoout/driver.h" #include "core/libraries/videoout/video_out.h" -#include "core/loader/symbols_resolver.h" +#include "core/libraries/videoout/videoout_error.h" #include "core/platform.h" #include "video_core/renderer_vulkan/vk_presenter.h" @@ -51,7 +50,7 @@ s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(Kernel::SceKernelEqueue eq, s32 handle, } Kernel::EqueueEvent event{}; - event.event.ident = SCE_VIDEO_OUT_EVENT_FLIP; + event.event.ident = u64(OrbisVideoOutEventId::Flip); event.event.filter = Kernel::SceKernelEvent::Filter::VideoOut; // The library only sets EV_ADD but kernel driver forces EV_CLEAR event.event.flags = Kernel::SceKernelEvent::Flags::Clear; @@ -78,7 +77,7 @@ s32 PS4_SYSV_ABI sceVideoOutAddVblankEvent(Kernel::SceKernelEqueue eq, s32 handl } Kernel::EqueueEvent event{}; - event.event.ident = SCE_VIDEO_OUT_EVENT_VBLANK; + event.event.ident = u64(OrbisVideoOutEventId::Vblank); event.event.filter = Kernel::SceKernelEvent::Filter::VideoOut; // The library only sets EV_ADD but kernel driver forces EV_CLEAR event.event.flags = Kernel::SceKernelEvent::Flags::Clear; @@ -118,7 +117,7 @@ s32 PS4_SYSV_ABI sceVideoOutIsFlipPending(s32 handle) { LOG_TRACE(Lib_VideoOut, "called"); auto* port = driver->GetPort(handle); std::unique_lock lock{port->port_mutex}; - s32 pending = port->flip_status.flipPendingNum; + s32 pending = port->flip_status.flip_pending_num; return pending; } @@ -156,7 +155,7 @@ s32 PS4_SYSV_ABI sceVideoOutSubmitFlip(s32 handle, s32 bufferIndex, s32 flipMode int PS4_SYSV_ABI sceVideoOutGetEventId(const Kernel::SceKernelEvent* ev) { if (ev == nullptr) { - return SCE_VIDEO_OUT_ERROR_INVALID_ADDRESS; + return ORBIS_VIDEO_OUT_ERROR_INVALID_ADDRESS; } if (ev->filter != Kernel::SceKernelEvent::Filter::VideoOut) { return ORBIS_VIDEO_OUT_ERROR_INVALID_EVENT_QUEUE; @@ -166,7 +165,7 @@ int PS4_SYSV_ABI sceVideoOutGetEventId(const Kernel::SceKernelEvent* ev) { int PS4_SYSV_ABI sceVideoOutGetEventData(const Kernel::SceKernelEvent* ev, int64_t* data) { if (ev == nullptr || data == nullptr) { - return SCE_VIDEO_OUT_ERROR_INVALID_ADDRESS; + return ORBIS_VIDEO_OUT_ERROR_INVALID_ADDRESS; } if (ev->filter != Kernel::SceKernelEvent::Filter::VideoOut) { return ORBIS_VIDEO_OUT_ERROR_INVALID_EVENT_QUEUE; @@ -204,7 +203,7 @@ s32 PS4_SYSV_ABI sceVideoOutGetFlipStatus(s32 handle, FlipStatus* status) { s32 PS4_SYSV_ABI sceVideoOutGetVblankStatus(int handle, SceVideoOutVblankStatus* status) { if (status == nullptr) { - return SCE_VIDEO_OUT_ERROR_INVALID_ADDRESS; + return ORBIS_VIDEO_OUT_ERROR_INVALID_ADDRESS; } auto* port = driver->GetPort(handle); diff --git a/src/core/libraries/videoout/video_out.h b/src/core/libraries/videoout/video_out.h index 0680a849..5af9d550 100644 --- a/src/core/libraries/videoout/video_out.h +++ b/src/core/libraries/videoout/video_out.h @@ -40,36 +40,32 @@ constexpr int SCE_VIDEO_OUT_BUFFER_ATTRIBUTE_OPTION_NONE = 0; constexpr int SCE_VIDEO_OUT_BUFFER_ATTRIBUTE_OPTION_VR = 7; constexpr int SCE_VIDEO_OUT_BUFFER_ATTRIBUTE_OPTION_STRICT_COLORIMETRY = 8; -enum SceVideoOutEventId : s16 { - SCE_VIDEO_OUT_EVENT_FLIP = 0, - SCE_VIDEO_OUT_EVENT_VBLANK = 1, - SCE_VIDEO_OUT_EVENT_PRE_VBLANK_START = 2 -}; +enum class OrbisVideoOutEventId : s16 { Flip = 0, Vblank = 1, PreVblankStart = 2 }; -enum AspectRatioMode : s32 { - SCE_VIDEO_OUT_ASPECT_RATIO_16_9 = 0, +enum class AspectRatioMode : s32 { + Ratio16_9 = 0, }; struct FlipStatus { u64 count = 0; - u64 processTime = 0; + u64 process_time = 0; u64 tsc = 0; - s64 flipArg = -1; - u64 submitTsc = 0; + s64 flip_arg = -1; + u64 submit_tsc = 0; u64 reserved0 = 0; - s32 gcQueueNum = 0; - s32 flipPendingNum = 0; - s32 currentBuffer = -1; + s32 gc_queue_num = 0; + s32 flip_pending_num = 0; + s32 current_buffer = -1; u32 reserved1 = 0; }; struct SceVideoOutResolutionStatus { - s32 fullWidth = 1280; - s32 fullHeight = 720; - s32 paneWidth = 1280; - s32 paneHeight = 720; - u64 refreshRate = SCE_VIDEO_OUT_REFRESH_RATE_59_94HZ; - float screenSizeInInch = 50; + s32 full_width = 1280; + s32 full_height = 720; + s32 pane_width = 1280; + s32 pane_height = 720; + u64 refresh_rate = SCE_VIDEO_OUT_REFRESH_RATE_59_94HZ; + float screen_size_in_inch = 50; u16 flags = 0; u16 reserved0 = 0; u32 reserved1[3] = {0}; @@ -77,7 +73,7 @@ struct SceVideoOutResolutionStatus { struct SceVideoOutVblankStatus { u64 count = 0; - u64 processTime = 0; + u64 process_time = 0; u64 tsc = 0; u64 reserved[1] = {0}; u8 flags = 0; diff --git a/src/core/libraries/videoout/videoout_error.h b/src/core/libraries/videoout/videoout_error.h new file mode 100644 index 00000000..b1ed18c9 --- /dev/null +++ b/src/core/libraries/videoout/videoout_error.h @@ -0,0 +1,35 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/libraries/error_codes.h" + +// VideoOut library +constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_VALUE = 0x80290001; +constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_ADDRESS = 0x80290002; +constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_PIXEL_FORMAT = 0x80290003; +constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_PITCH = 0x80290004; +constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_RESOLUTION = 0x80290005; +constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_FLIP_MODE = 0x80290006; +constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_TILING_MODE = 0x80290007; +constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_ASPECT_RATIO = 0x80290008; +constexpr int ORBIS_VIDEO_OUT_ERROR_RESOURCE_BUSY = 0x80290009; +constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_INDEX = 0x8029000A; +constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_HANDLE = 0x8029000B; +constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_EVENT_QUEUE = 0x8029000C; +constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_EVENT = 0x8029000D; +constexpr int ORBIS_VIDEO_OUT_ERROR_NO_EMPTY_SLOT = 0x8029000F; +constexpr int ORBIS_VIDEO_OUT_ERROR_SLOT_OCCUPIED = 0x80290010; +constexpr int ORBIS_VIDEO_OUT_ERROR_FLIP_QUEUE_FULL = 0x80290012; +constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_MEMORY = 0x80290013; +constexpr int ORBIS_VIDEO_OUT_ERROR_MEMORY_NOT_PHYSICALLY_CONTIGUOUS = 0x80290014; +constexpr int ORBIS_VIDEO_OUT_ERROR_MEMORY_INVALID_ALIGNMENT = 0x80290015; +constexpr int ORBIS_VIDEO_OUT_ERROR_UNSUPPORTED_OUTPUT_MODE = 0x80290016; +constexpr int ORBIS_VIDEO_OUT_ERROR_OVERFLOW = 0x80290017; +constexpr int ORBIS_VIDEO_OUT_ERROR_NO_DEVICE = 0x80290018; +constexpr int ORBIS_VIDEO_OUT_ERROR_UNAVAILABLE_OUTPUT_MODE = 0x80290019; +constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_OPTION = 0x8029001A; +constexpr int ORBIS_VIDEO_OUT_ERROR_UNKNOWN = 0x802900FE; +constexpr int ORBIS_VIDEO_OUT_ERROR_FATAL = 0x802900FF; +constexpr int ORBIS_VIDEO_OUT_ERROR_ENOMEM = 0x8029100C; diff --git a/src/core/linker.cpp b/src/core/linker.cpp index 9592bee0..9cf4198a 100644 --- a/src/core/linker.cpp +++ b/src/core/linker.cpp @@ -16,7 +16,6 @@ #include "core/linker.h" #include "core/memory.h" #include "core/tls.h" -#include "core/virtual_memory.h" namespace Core { @@ -211,7 +210,7 @@ void Linker::Relocate(Module* module) { } if (rel_is_resolved) { - VirtualMemory::memory_patch(rel_virtual_addr, rel_value); + std::memcpy(reinterpret_cast(rel_virtual_addr), &rel_value, sizeof(rel_value)); } else { LOG_INFO(Core_Linker, "Function not patched! {}", rel_name); } @@ -297,8 +296,6 @@ void* Linker::TlsGetAddr(u64 module_index, u64 offset) { u8* addr = dtv_table[module_index + 1].pointer; Module* module = m_modules[module_index - 1].get(); - // LOG_INFO(Core_Linker, "Got DTV addr {} from module index {} with name {}", - // fmt::ptr(addr), module_index, module->file.filename().string()); if (!addr) { // Module was just loaded by above code. Allocate TLS block for it. const u32 init_image_size = module->tls.init_image_size; diff --git a/src/core/memory.cpp b/src/core/memory.cpp index f638e5e1..15fde2a5 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -5,10 +5,9 @@ #include "common/assert.h" #include "common/config.h" #include "common/debug.h" -#include "core/libraries/error_codes.h" #include "core/libraries/kernel/memory.h" +#include "core/libraries/kernel/orbis_error.h" #include "core/memory.h" -#include "video_core/renderer_vulkan/vk_instance.h" #include "video_core/renderer_vulkan/vk_rasterizer.h" namespace Core { @@ -268,7 +267,7 @@ int MemoryManager::MapMemory(void** out_addr, VAddr virtual_addr, size_t size, M // Certain games perform flexible mappings on loop to determine // the available flexible memory size. Questionable but we need to handle this. if (type == VMAType::Flexible && flexible_usage + size > total_flexible_size) { - return SCE_KERNEL_ERROR_ENOMEM; + return ORBIS_KERNEL_ERROR_ENOMEM; } // When virtual addr is zero, force it to virtual_base. The guest cannot pass Fixed diff --git a/src/core/virtual_memory.cpp b/src/core/virtual_memory.cpp deleted file mode 100644 index 8907622a..00000000 --- a/src/core/virtual_memory.cpp +++ /dev/null @@ -1,180 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "common/assert.h" -#include "common/error.h" -#include "common/logging/log.h" -#include "core/virtual_memory.h" - -#ifdef _WIN64 -#include -#else -#include -#endif - -#if !defined(_WIN64) -enum PosixPageProtection { - PAGE_NOACCESS = 0, - PAGE_READONLY = PROT_READ, - PAGE_READWRITE = PROT_READ | PROT_WRITE, - PAGE_EXECUTE = PROT_EXEC, - PAGE_EXECUTE_READ = PROT_EXEC | PROT_READ, - PAGE_EXECUTE_READWRITE = PROT_EXEC | PROT_READ | PROT_WRITE -}; -#endif - -namespace VirtualMemory { -static u32 convertMemoryMode(MemoryMode mode) { - switch (mode) { - case MemoryMode::Read: - return PAGE_READONLY; - case MemoryMode::Write: - case MemoryMode::ReadWrite: - return PAGE_READWRITE; - - case MemoryMode::Execute: - return PAGE_EXECUTE; - case MemoryMode::ExecuteRead: - return PAGE_EXECUTE_READ; - case MemoryMode::ExecuteWrite: - case MemoryMode::ExecuteReadWrite: - return PAGE_EXECUTE_READWRITE; - - case MemoryMode::NoAccess: - return PAGE_NOACCESS; - default: - return PAGE_NOACCESS; - } -} -static MemoryMode convertMemoryMode(u32 mode) { - switch (mode) { - case PAGE_NOACCESS: - return MemoryMode::NoAccess; - case PAGE_READONLY: - return MemoryMode::Read; - case PAGE_READWRITE: - return MemoryMode::ReadWrite; - case PAGE_EXECUTE: - return MemoryMode::Execute; - case PAGE_EXECUTE_READ: - return MemoryMode::ExecuteRead; - case PAGE_EXECUTE_READWRITE: - return MemoryMode::ExecuteReadWrite; - default: - return MemoryMode::NoAccess; - } -} - -u64 memory_alloc(u64 address, u64 size, MemoryMode mode) { -#ifdef _WIN64 - auto ptr = reinterpret_cast(VirtualAlloc( - reinterpret_cast(static_cast(address)), size, - static_cast(MEM_COMMIT) | static_cast(MEM_RESERVE), convertMemoryMode(mode))); - - if (ptr == 0) { - auto err = static_cast(GetLastError()); - LOG_ERROR(Common_Memory, "VirtualAlloc() failed: 0x{:X}", err); - } -#else - auto ptr = reinterpret_cast( - mmap(reinterpret_cast(static_cast(address)), size, - PROT_EXEC | PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0)); - - if (ptr == reinterpret_cast MAP_FAILED) { - LOG_ERROR(Common_Memory, "mmap() failed: {}", std::strerror(errno)); - } -#endif - return ptr; -} -bool memory_protect(u64 address, u64 size, MemoryMode mode, MemoryMode* old_mode) { -#ifdef _WIN64 - DWORD old_protect = 0; - if (VirtualProtect(reinterpret_cast(static_cast(address)), size, - convertMemoryMode(mode), &old_protect) == 0) { - auto err = static_cast(GetLastError()); - LOG_ERROR(Common_Memory, "VirtualProtect() failed: 0x{:X}", err); - return false; - } - if (old_mode != nullptr) { - *old_mode = convertMemoryMode(old_protect); - } - return true; -#else - int ret = mprotect(reinterpret_cast(address), size, convertMemoryMode(mode)); - if (ret != 0) { - const auto error = Common::GetLastErrorMsg(); - ASSERT(false); - } - return true; -#endif -} - -bool memory_flush(u64 address, u64 size) { -#ifdef _WIN64 - if (::FlushInstructionCache(GetCurrentProcess(), - reinterpret_cast(static_cast(address)), - size) == 0) { - auto err = static_cast(GetLastError()); - LOG_ERROR(Common_Memory, "FlushInstructionCache() failed: 0x{:X}", err); - return false; - } - return true; -#else // linux probably doesn't have something similar - return true; -#endif -} -bool memory_patch(u64 vaddr, u64 value) { - MemoryMode old_mode{}; - // memory_protect(vaddr, 8, MemoryMode::ReadWrite, &old_mode); - - auto* ptr = reinterpret_cast(vaddr); - - bool ret = (*ptr != value); - - *ptr = value; - - // memory_protect(vaddr, 8, old_mode, nullptr); - - // if mode is executable flush it so insure that cpu finds it - if (containsExecuteMode(old_mode)) { - memory_flush(vaddr, 8); - } - - return ret; -} -static u64 AlignUp(u64 pos, u64 align) { - return (align != 0 ? (pos + (align - 1)) & ~(align - 1) : pos); -} - -u64 memory_alloc_aligned(u64 address, u64 size, MemoryMode mode, u64 alignment) { -#ifdef _WIN64 - // try allocate aligned address inside user area - MEM_ADDRESS_REQUIREMENTS req{}; - MEM_EXTENDED_PARAMETER param{}; - req.LowestStartingAddress = - (address == 0 ? reinterpret_cast(USER_MIN) - : reinterpret_cast(AlignUp(address, alignment))); - req.HighestEndingAddress = reinterpret_cast(USER_MAX); - req.Alignment = alignment; - param.Type = MemExtendedParameterAddressRequirements; - param.Pointer = &req; - - auto ptr = reinterpret_cast( - VirtualAlloc2(GetCurrentProcess(), nullptr, size, - static_cast(MEM_COMMIT) | static_cast(MEM_RESERVE), - convertMemoryMode(mode), ¶m, 1)); - - if (ptr == 0) { - auto err = static_cast(GetLastError()); - LOG_ERROR(Common_Memory, "VirtualAlloc2() failed: 0x{:X}", err); - } - return ptr; -#else - void* hint_address = address == 0 ? reinterpret_cast(USER_MIN) - : reinterpret_cast(AlignUp(address, alignment)); - void* ptr = mmap(hint_address, size, convertMemoryMode(mode), MAP_ANON | MAP_PRIVATE, -1, 0); - ASSERT(ptr != MAP_FAILED); - return reinterpret_cast(ptr); -#endif -} -} // namespace VirtualMemory diff --git a/src/core/virtual_memory.h b/src/core/virtual_memory.h deleted file mode 100644 index 953f35f7..00000000 --- a/src/core/virtual_memory.h +++ /dev/null @@ -1,47 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include "common/types.h" - -constexpr u64 SYSTEM_RESERVED = 0x800000000u; -constexpr u64 CODE_BASE_OFFSET = 0x100000000u; -constexpr u64 SYSTEM_MANAGED_MIN = 0x0000040000u; -constexpr u64 SYSTEM_MANAGED_MAX = 0x07FFFFBFFFu; -constexpr u64 USER_MIN = 0x1000000000u; -constexpr u64 USER_MAX = 0xFBFFFFFFFFu; - -namespace VirtualMemory { -enum class MemoryMode : u32 { - NoAccess = 0, - Read = 1, - Write = 2, - ReadWrite = 3, - Execute = 4, - ExecuteRead = 5, - ExecuteWrite = 6, - ExecuteReadWrite = 7, -}; -u64 memory_alloc(u64 address, u64 size, MemoryMode mode); -u64 memory_alloc_aligned(u64 address, u64 size, MemoryMode mode, u64 alignment); -bool memory_protect(u64 address, u64 size, MemoryMode mode, MemoryMode* old_mode); -bool memory_flush(u64 address, u64 size); -bool memory_patch(u64 vaddr, u64 value); - -inline bool containsExecuteMode(MemoryMode mode) { - switch (mode) { - case MemoryMode::Execute: - return true; - case MemoryMode::ExecuteRead: - return true; - case MemoryMode::ExecuteWrite: - return true; - case MemoryMode::ExecuteReadWrite: - return true; - default: - return false; - } -} - -} // namespace VirtualMemory diff --git a/src/emulator.cpp b/src/emulator.cpp index a01eb816..4ab535a2 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -257,9 +257,9 @@ void Emulator::Run(const std::filesystem::path& file) { linker->Execute(); - window->initTimers(); - while (window->isOpen()) { - window->waitEvent(); + window->InitTimers(); + while (window->IsOpen()) { + window->WaitEvent(); } #ifdef ENABLE_QT_GUI diff --git a/src/imgui/renderer/imgui_core.cpp b/src/imgui/renderer/imgui_core.cpp index 47f60e8e..46391fae 100644 --- a/src/imgui/renderer/imgui_core.cpp +++ b/src/imgui/renderer/imgui_core.cpp @@ -49,7 +49,7 @@ void Initialize(const ::Vulkan::Instance& instance, const Frontend::WindowSDL& w io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; - io.DisplaySize = ImVec2((float)window.getWidth(), (float)window.getHeight()); + io.DisplaySize = ImVec2((float)window.GetWidth(), (float)window.GetHeight()); PushStyleVar(ImGuiStyleVar_WindowRounding, 6.0f); // Makes the window edges rounded auto path = config_path.u8string(); @@ -83,7 +83,7 @@ void Initialize(const ::Vulkan::Instance& instance, const Frontend::WindowSDL& w StyleColorsDark(); ::Core::Devtools::Layer::SetupSettings(); - Sdl::Init(window.GetSdlWindow()); + Sdl::Init(window.GetSDLWindow()); const Vulkan::InitInfo vk_info{ .instance = instance.GetInstance(), @@ -108,7 +108,7 @@ void Initialize(const ::Vulkan::Instance& instance, const Frontend::WindowSDL& w ImFormatString(label, IM_ARRAYSIZE(label), "WindowOverViewport_%08X", GetMainViewport()->ID); dock_id = ImHashStr(label); - if (const auto dpi = SDL_GetWindowDisplayScale(window.GetSdlWindow()); dpi > 0.0f) { + if (const auto dpi = SDL_GetWindowDisplayScale(window.GetSDLWindow()); dpi > 0.0f) { GetIO().FontGlobalScale = dpi; } } diff --git a/src/input/controller.cpp b/src/input/controller.cpp index cd7d3d8a..3927b096 100644 --- a/src/input/controller.cpp +++ b/src/input/controller.cpp @@ -1,13 +1,10 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "controller.h" - -#include "common/assert.h" +#include #include "core/libraries/kernel/time.h" #include "core/libraries/pad/pad.h" - -#include +#include "input/controller.h" namespace Input { @@ -59,9 +56,7 @@ State GameController::GetLastState() const { if (m_states_num == 0) { return m_last_state; } - - auto last = (m_first_state + m_states_num - 1) % MAX_STATES; - + const u32 last = (m_first_state + m_states_num - 1) % MAX_STATES; return m_states[last]; } @@ -71,19 +66,19 @@ void GameController::AddState(const State& state) { m_first_state = (m_first_state + 1) % MAX_STATES; } - auto index = (m_first_state + m_states_num) % MAX_STATES; - + const u32 index = (m_first_state + m_states_num) % MAX_STATES; m_states[index] = state; m_last_state = state; m_private[index].obtained = false; m_states_num++; } -void GameController::CheckButton(int id, u32 button, bool isPressed) { +void GameController::CheckButton(int id, Libraries::Pad::OrbisPadButtonDataOffset button, + bool is_pressed) { std::scoped_lock lock{m_mutex}; auto state = GetLastState(); state.time = Libraries::Kernel::sceKernelGetProcessTime(); - if (isPressed) { + if (is_pressed) { state.buttonsState |= button; } else { state.buttonsState &= ~button; @@ -93,28 +88,28 @@ void GameController::CheckButton(int id, u32 button, bool isPressed) { } void GameController::Axis(int id, Input::Axis axis, int value) { + using Libraries::Pad::OrbisPadButtonDataOffset; + std::scoped_lock lock{m_mutex}; auto state = GetLastState(); state.time = Libraries::Kernel::sceKernelGetProcessTime(); - int axis_id = static_cast(axis); - state.axes[axis_id] = value; if (axis == Input::Axis::TriggerLeft) { if (value > 0) { - state.buttonsState |= Libraries::Pad::OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_L2; + state.buttonsState |= OrbisPadButtonDataOffset::L2; } else { - state.buttonsState &= ~Libraries::Pad::OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_L2; + state.buttonsState &= ~OrbisPadButtonDataOffset::L2; } } if (axis == Input::Axis::TriggerRight) { if (value > 0) { - state.buttonsState |= Libraries::Pad::OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_R2; + state.buttonsState |= OrbisPadButtonDataOffset::R2; } else { - state.buttonsState &= ~Libraries::Pad::OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_R2; + state.buttonsState &= ~OrbisPadButtonDataOffset::R2; } } diff --git a/src/input/controller.h b/src/input/controller.h index 01ea21c0..d425fb46 100644 --- a/src/input/controller.h +++ b/src/input/controller.h @@ -5,6 +5,7 @@ #include #include "common/types.h" +#include "core/libraries/pad/pad.h" struct SDL_Gamepad; @@ -28,7 +29,7 @@ struct TouchpadEntry { }; struct State { - u32 buttonsState = 0; + Libraries::Pad::OrbisPadButtonDataOffset buttonsState{}; u64 time = 0; int axes[static_cast(Axis::AxisMax)] = {128, 128, 128, 128, 0, 0}; TouchpadEntry touchpad[2] = {{false, 0, 0}, {false, 0, 0}}; @@ -49,7 +50,7 @@ public: 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 CheckButton(int id, Libraries::Pad::OrbisPadButtonDataOffset button, bool isPressed); void AddState(const State& state); void Axis(int id, Input::Axis axis, int value); void SetLightBarRGB(u8 r, u8 g, u8 b); diff --git a/src/sdl_window.cpp b/src/sdl_window.cpp index ad7d1b4a..d95e8d63 100644 --- a/src/sdl_window.cpp +++ b/src/sdl_window.cpp @@ -6,9 +6,9 @@ #include #include #include + #include "common/assert.h" #include "common/config.h" -#include "common/version.h" #include "core/libraries/pad/pad.h" #include "imgui/renderer/imgui_core.h" #include "input/controller.h" @@ -21,6 +21,45 @@ namespace Frontend { +using namespace Libraries::Pad; + +static OrbisPadButtonDataOffset SDLGamepadToOrbisButton(u8 button) { + switch (button) { + case SDL_GAMEPAD_BUTTON_DPAD_DOWN: + return OrbisPadButtonDataOffset::Down; + case SDL_GAMEPAD_BUTTON_DPAD_UP: + return OrbisPadButtonDataOffset::Up; + case SDL_GAMEPAD_BUTTON_DPAD_LEFT: + return OrbisPadButtonDataOffset::Left; + case SDL_GAMEPAD_BUTTON_DPAD_RIGHT: + return OrbisPadButtonDataOffset::Right; + case SDL_GAMEPAD_BUTTON_SOUTH: + return OrbisPadButtonDataOffset::Cross; + case SDL_GAMEPAD_BUTTON_NORTH: + return OrbisPadButtonDataOffset::Triangle; + case SDL_GAMEPAD_BUTTON_WEST: + return OrbisPadButtonDataOffset::Square; + case SDL_GAMEPAD_BUTTON_EAST: + return OrbisPadButtonDataOffset::Circle; + case SDL_GAMEPAD_BUTTON_START: + return OrbisPadButtonDataOffset::Options; + case SDL_GAMEPAD_BUTTON_TOUCHPAD: + return OrbisPadButtonDataOffset::TouchPad; + case SDL_GAMEPAD_BUTTON_BACK: + return OrbisPadButtonDataOffset::TouchPad; + case SDL_GAMEPAD_BUTTON_LEFT_SHOULDER: + return OrbisPadButtonDataOffset::L1; + case SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER: + return OrbisPadButtonDataOffset::R1; + case SDL_GAMEPAD_BUTTON_LEFT_STICK: + return OrbisPadButtonDataOffset::L3; + case SDL_GAMEPAD_BUTTON_RIGHT_STICK: + return OrbisPadButtonDataOffset::R3; + default: + return OrbisPadButtonDataOffset::None; + } +} + static Uint32 SDLCALL PollController(void* userdata, SDL_TimerID timer_id, Uint32 interval) { auto* controller = reinterpret_cast(userdata); return controller->Poll(); @@ -80,7 +119,7 @@ WindowSDL::WindowSDL(s32 width_, s32 height_, Input::GameController* controller_ WindowSDL::~WindowSDL() = default; -void WindowSDL::waitEvent() { +void WindowSDL::WaitEvent() { // Called on main thread SDL_Event event; @@ -96,16 +135,16 @@ void WindowSDL::waitEvent() { case SDL_EVENT_WINDOW_RESIZED: case SDL_EVENT_WINDOW_MAXIMIZED: case SDL_EVENT_WINDOW_RESTORED: - onResize(); + OnResize(); break; case SDL_EVENT_WINDOW_MINIMIZED: case SDL_EVENT_WINDOW_EXPOSED: is_shown = event.type == SDL_EVENT_WINDOW_EXPOSED; - onResize(); + OnResize(); break; case SDL_EVENT_KEY_DOWN: case SDL_EVENT_KEY_UP: - onKeyPress(&event); + OnKeyPress(&event); break; case SDL_EVENT_GAMEPAD_BUTTON_DOWN: case SDL_EVENT_GAMEPAD_BUTTON_UP: @@ -115,7 +154,7 @@ void WindowSDL::waitEvent() { case SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN: case SDL_EVENT_GAMEPAD_TOUCHPAD_UP: case SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION: - onGamepadEvent(&event); + OnGamepadEvent(&event); break; case SDL_EVENT_QUIT: is_open = false; @@ -125,18 +164,16 @@ void WindowSDL::waitEvent() { } } -void WindowSDL::initTimers() { +void WindowSDL::InitTimers() { SDL_AddTimer(100, &PollController, controller); } -void WindowSDL::onResize() { +void WindowSDL::OnResize() { SDL_GetWindowSizeInPixels(window, &width, &height); ImGui::Core::OnResize(); } -void WindowSDL::onKeyPress(const SDL_Event* event) { - using Libraries::Pad::OrbisPadButtonDataOffset; - +void WindowSDL::OnKeyPress(const SDL_Event* event) { #ifdef __APPLE__ // Use keys that are more friendly for keyboards without a keypad. // Once there are key binding options this won't be necessary. @@ -151,38 +188,38 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { constexpr SDL_Keycode TriangleKey = SDLK_KP_8; #endif - u32 button = 0; + auto button = OrbisPadButtonDataOffset::None; Input::Axis axis = Input::Axis::AxisMax; int axisvalue = 0; int ax = 0; std::string backButtonBehavior = Config::getBackButtonBehavior(); switch (event->key.key) { case SDLK_UP: - button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_UP; + button = OrbisPadButtonDataOffset::Up; break; case SDLK_DOWN: - button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_DOWN; + button = OrbisPadButtonDataOffset::Down; break; case SDLK_LEFT: - button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_LEFT; + button = OrbisPadButtonDataOffset::Left; break; case SDLK_RIGHT: - button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_RIGHT; + button = OrbisPadButtonDataOffset::Right; break; case TriangleKey: - button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_TRIANGLE; + button = OrbisPadButtonDataOffset::Triangle; break; case CircleKey: - button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_CIRCLE; + button = OrbisPadButtonDataOffset::Circle; break; case CrossKey: - button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_CROSS; + button = OrbisPadButtonDataOffset::Cross; break; case SquareKey: - button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_SQUARE; + button = OrbisPadButtonDataOffset::Square; break; case SDLK_RETURN: - button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_OPTIONS; + button = OrbisPadButtonDataOffset::Options; break; case SDLK_A: axis = Input::Axis::LeftX; @@ -257,19 +294,19 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { ax = Input::GetAxis(-0x80, 0x80, axisvalue); break; case SDLK_X: - button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_L3; + button = OrbisPadButtonDataOffset::L3; break; case SDLK_M: - button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_R3; + button = OrbisPadButtonDataOffset::R3; break; case SDLK_Q: - button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_L1; + button = OrbisPadButtonDataOffset::L1; break; case SDLK_U: - button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_R1; + button = OrbisPadButtonDataOffset::R1; break; case SDLK_E: - button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_L2; + button = OrbisPadButtonDataOffset::L2; axis = Input::Axis::TriggerLeft; if (event->type == SDL_EVENT_KEY_DOWN) { axisvalue += 255; @@ -279,7 +316,7 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { ax = Input::GetAxis(0, 0x80, axisvalue); break; case SDLK_O: - button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_R2; + button = OrbisPadButtonDataOffset::R2; axis = Input::Axis::TriggerRight; if (event->type == SDL_EVENT_KEY_DOWN) { axisvalue += 255; @@ -294,9 +331,9 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { : (backButtonBehavior == "right" ? 0.75f : 0.5f); // trigger a touchpad event so that the touchpad emulation for back button works controller->SetTouchpadState(0, true, x, 0.5f); - button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_TOUCH_PAD; + button = OrbisPadButtonDataOffset::TouchPad; } else { - button = 0; + button = {}; } break; case SDLK_F11: @@ -317,7 +354,7 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { default: break; } - if (button != 0) { + if (button != OrbisPadButtonDataOffset::None) { controller->CheckButton(0, button, event->type == SDL_EVENT_KEY_DOWN); } if (axis != Input::Axis::AxisMax) { @@ -325,10 +362,8 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { } } -void WindowSDL::onGamepadEvent(const SDL_Event* event) { - using Libraries::Pad::OrbisPadButtonDataOffset; - - u32 button = 0; +void WindowSDL::OnGamepadEvent(const SDL_Event* event) { + auto button = OrbisPadButtonDataOffset::None; Input::Axis axis = Input::Axis::AxisMax; switch (event->type) { case SDL_EVENT_GAMEPAD_ADDED: @@ -343,25 +378,25 @@ void WindowSDL::onGamepadEvent(const SDL_Event* event) { event->gtouchpad.x, event->gtouchpad.y); break; case SDL_EVENT_GAMEPAD_BUTTON_DOWN: - case SDL_EVENT_GAMEPAD_BUTTON_UP: - button = sdlGamepadToOrbisButton(event->gbutton.button); - if (button != 0) { - if (event->gbutton.button == SDL_GAMEPAD_BUTTON_BACK) { - std::string backButtonBehavior = Config::getBackButtonBehavior(); - if (backButtonBehavior != "none") { - float x = backButtonBehavior == "left" - ? 0.25f - : (backButtonBehavior == "right" ? 0.75f : 0.5f); - // trigger a touchpad event so that the touchpad emulation for back button works - controller->SetTouchpadState(0, true, x, 0.5f); - controller->CheckButton(0, button, - event->type == SDL_EVENT_GAMEPAD_BUTTON_DOWN); - } - } else { - controller->CheckButton(0, button, event->type == SDL_EVENT_GAMEPAD_BUTTON_DOWN); - } + case SDL_EVENT_GAMEPAD_BUTTON_UP: { + button = SDLGamepadToOrbisButton(event->gbutton.button); + if (button == OrbisPadButtonDataOffset::None) { + break; + } + if (event->gbutton.button != SDL_GAMEPAD_BUTTON_BACK) { + controller->CheckButton(0, button, event->type == SDL_EVENT_GAMEPAD_BUTTON_DOWN); + break; + } + const auto backButtonBehavior = Config::getBackButtonBehavior(); + if (backButtonBehavior != "none") { + float x = backButtonBehavior == "left" ? 0.25f + : (backButtonBehavior == "right" ? 0.75f : 0.5f); + // trigger a touchpad event so that the touchpad emulation for back button works + controller->SetTouchpadState(0, true, x, 0.5f); + controller->CheckButton(0, button, event->type == SDL_EVENT_GAMEPAD_BUTTON_DOWN); } break; + } case SDL_EVENT_GAMEPAD_AXIS_MOTION: axis = event->gaxis.axis == SDL_GAMEPAD_AXIS_LEFTX ? Input::Axis::LeftX : event->gaxis.axis == SDL_GAMEPAD_AXIS_LEFTY ? Input::Axis::LeftY @@ -383,43 +418,4 @@ void WindowSDL::onGamepadEvent(const SDL_Event* event) { } } -int WindowSDL::sdlGamepadToOrbisButton(u8 button) { - using Libraries::Pad::OrbisPadButtonDataOffset; - - switch (button) { - case SDL_GAMEPAD_BUTTON_DPAD_DOWN: - return OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_DOWN; - case SDL_GAMEPAD_BUTTON_DPAD_UP: - return OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_UP; - case SDL_GAMEPAD_BUTTON_DPAD_LEFT: - return OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_LEFT; - case SDL_GAMEPAD_BUTTON_DPAD_RIGHT: - return OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_RIGHT; - case SDL_GAMEPAD_BUTTON_SOUTH: - return OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_CROSS; - case SDL_GAMEPAD_BUTTON_NORTH: - return OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_TRIANGLE; - case SDL_GAMEPAD_BUTTON_WEST: - return OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_SQUARE; - case SDL_GAMEPAD_BUTTON_EAST: - return OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_CIRCLE; - case SDL_GAMEPAD_BUTTON_START: - return OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_OPTIONS; - case SDL_GAMEPAD_BUTTON_TOUCHPAD: - return OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_TOUCH_PAD; - case SDL_GAMEPAD_BUTTON_BACK: - return OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_TOUCH_PAD; - case SDL_GAMEPAD_BUTTON_LEFT_SHOULDER: - return OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_L1; - case SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER: - return OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_R1; - case SDL_GAMEPAD_BUTTON_LEFT_STICK: - return OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_L3; - case SDL_GAMEPAD_BUTTON_RIGHT_STICK: - return OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_R3; - default: - return 0; - } -} - } // namespace Frontend diff --git a/src/sdl_window.h b/src/sdl_window.h index ec8de354..78d0e582 100644 --- a/src/sdl_window.h +++ b/src/sdl_window.h @@ -46,36 +46,33 @@ public: std::string_view window_title); ~WindowSDL(); - s32 getWidth() const { + s32 GetWidth() const { return width; } - s32 getHeight() const { + s32 GetHeight() const { return height; } - bool isOpen() const { + bool IsOpen() const { return is_open; } - [[nodiscard]] SDL_Window* GetSdlWindow() const { + [[nodiscard]] SDL_Window* GetSDLWindow() const { return window; } - WindowSystemInfo getWindowInfo() const { + WindowSystemInfo GetWindowInfo() const { return window_info; } - void waitEvent(); - - void initTimers(); + void WaitEvent(); + void InitTimers(); private: - void onResize(); - void onKeyPress(const SDL_Event* event); - void onGamepadEvent(const SDL_Event* event); - - int sdlGamepadToOrbisButton(u8 button); + void OnResize(); + void OnKeyPress(const SDL_Event* event); + void OnGamepadEvent(const SDL_Event* event); private: s32 width; diff --git a/src/video_core/renderer_vulkan/vk_instance.cpp b/src/video_core/renderer_vulkan/vk_instance.cpp index a16f35ed..580458e7 100644 --- a/src/video_core/renderer_vulkan/vk_instance.cpp +++ b/src/video_core/renderer_vulkan/vk_instance.cpp @@ -95,7 +95,7 @@ Instance::Instance(bool enable_validation, bool enable_crash_diagnostic) Instance::Instance(Frontend::WindowSDL& window, s32 physical_device_index, bool enable_validation /*= false*/, bool enable_crash_diagnostic /*= false*/) - : instance{CreateInstance(window.getWindowInfo().type, enable_validation, + : instance{CreateInstance(window.GetWindowInfo().type, enable_validation, enable_crash_diagnostic)}, physical_devices{EnumeratePhysicalDevices(instance)} { if (enable_validation) { diff --git a/src/video_core/renderer_vulkan/vk_platform.cpp b/src/video_core/renderer_vulkan/vk_platform.cpp index 0eb7e075..b2a50cd4 100644 --- a/src/video_core/renderer_vulkan/vk_platform.cpp +++ b/src/video_core/renderer_vulkan/vk_platform.cpp @@ -73,7 +73,7 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL DebugUtilsCallback( } vk::SurfaceKHR CreateSurface(vk::Instance instance, const Frontend::WindowSDL& emu_window) { - const auto& window_info = emu_window.getWindowInfo(); + const auto& window_info = emu_window.GetWindowInfo(); vk::SurfaceKHR surface{}; #if defined(VK_USE_PLATFORM_WIN32_KHR) diff --git a/src/video_core/renderer_vulkan/vk_presenter.cpp b/src/video_core/renderer_vulkan/vk_presenter.cpp index 23d2981f..b7d82931 100644 --- a/src/video_core/renderer_vulkan/vk_presenter.cpp +++ b/src/video_core/renderer_vulkan/vk_presenter.cpp @@ -629,9 +629,9 @@ Frame* Presenter::PrepareFrameInternal(VideoCore::ImageId image_id, bool is_eop) void Presenter::Present(Frame* frame) { // Recreate the swapchain if the window was resized. - if (window.getWidth() != swapchain.GetExtent().width || - window.getHeight() != swapchain.GetExtent().height) { - swapchain.Recreate(window.getWidth(), window.getHeight()); + if (window.GetWidth() != swapchain.GetExtent().width || + window.GetHeight() != swapchain.GetExtent().height) { + swapchain.Recreate(window.GetWidth(), window.GetHeight()); } ImGui::Core::NewFrame(); @@ -776,8 +776,8 @@ Frame* Presenter::GetRenderFrame() { device.resetFences(frame->present_done); // If the window dimensions changed, recreate this frame - if (frame->width != window.getWidth() || frame->height != window.getHeight()) { - RecreateFrame(frame, window.getWidth(), window.getHeight()); + if (frame->width != window.GetWidth() || frame->height != window.GetHeight()) { + RecreateFrame(frame, window.GetWidth(), window.GetHeight()); } return frame; diff --git a/src/video_core/renderer_vulkan/vk_swapchain.cpp b/src/video_core/renderer_vulkan/vk_swapchain.cpp index 86d7d506..d0bc7ebd 100644 --- a/src/video_core/renderer_vulkan/vk_swapchain.cpp +++ b/src/video_core/renderer_vulkan/vk_swapchain.cpp @@ -14,7 +14,7 @@ namespace Vulkan { Swapchain::Swapchain(const Instance& instance_, const Frontend::WindowSDL& window) : instance{instance_}, surface{CreateSurface(instance.GetInstance(), window)} { FindPresentFormat(); - Create(window.getWidth(), window.getHeight(), surface); + Create(window.GetWidth(), window.GetHeight(), surface); } Swapchain::~Swapchain() {