core: Implement sceRandomGetRandomNumber (#350)

This commit is contained in:
Dzmitry Dubrova 2024-07-31 14:01:22 +03:00 committed by GitHub
parent a7f2f09a44
commit 0fe766db6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 55 additions and 0 deletions

View File

@ -222,6 +222,10 @@ set(PLAYGO_LIB src/core/libraries/playgo/playgo.cpp
src/core/libraries/playgo/playgo_types.h src/core/libraries/playgo/playgo_types.h
) )
set(RANDOM_LIB src/core/libraries/random/random.cpp
src/core/libraries/random/random.h
)
set(USBD_LIB src/core/libraries/usbd/usbd.cpp set(USBD_LIB src/core/libraries/usbd/usbd.cpp
src/core/libraries/usbd/usbd.h src/core/libraries/usbd/usbd.h
) )
@ -334,6 +338,7 @@ set(CORE src/core/aerolib/stubs.cpp
${NP_LIBS} ${NP_LIBS}
${PNG_LIB} ${PNG_LIB}
${PLAYGO_LIB} ${PLAYGO_LIB}
${RANDOM_LIB}
${USBD_LIB} ${USBD_LIB}
${MISC_LIBS} ${MISC_LIBS}
${DIALOGS_LIB} ${DIALOGS_LIB}

View File

@ -73,6 +73,7 @@ enum class Class : u8 {
Lib_DiscMap, ///< The LibSceDiscMap implementation. Lib_DiscMap, ///< The LibSceDiscMap implementation.
Lib_Png, ///< The LibScePng implementation. Lib_Png, ///< The LibScePng implementation.
Lib_PlayGo, ///< The LibScePlayGo implementation. Lib_PlayGo, ///< The LibScePlayGo implementation.
Lib_Random, ///< The libSceRandom implementation.
Lib_Usbd, ///< The LibSceUsbd implementation. Lib_Usbd, ///< The LibSceUsbd implementation.
Lib_Ajm, ///< The LibSceAjm implementation. Lib_Ajm, ///< The LibSceAjm implementation.
Lib_ErrorDialog, ///< The LibSceErrorDialog implementation. Lib_ErrorDialog, ///< The LibSceErrorDialog implementation.

View File

@ -233,6 +233,9 @@ constexpr int SCE_KERNEL_ERROR_ESDKVERSION = 0x80020063;
constexpr int SCE_KERNEL_ERROR_ESTART = 0x80020064; constexpr int SCE_KERNEL_ERROR_ESTART = 0x80020064;
constexpr int SCE_KERNEL_ERROR_ESTOP = 0x80020065; constexpr int SCE_KERNEL_ERROR_ESTOP = 0x80020065;
// libSceRandom error codes
constexpr int SCE_RANDOM_ERROR_INVALID = 0x817C0016;
// videoOut // videoOut
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_VALUE = 0x80290001; // invalid argument 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_ADDRESS = 0x80290002; // invalid addresses

View File

@ -20,6 +20,7 @@
#include "core/libraries/np_trophy/np_trophy.h" #include "core/libraries/np_trophy/np_trophy.h"
#include "core/libraries/pad/pad.h" #include "core/libraries/pad/pad.h"
#include "core/libraries/playgo/playgo.h" #include "core/libraries/playgo/playgo.h"
#include "core/libraries/random/random.h"
#include "core/libraries/rtc/rtc.h" #include "core/libraries/rtc/rtc.h"
#include "core/libraries/save_data/savedata.h" #include "core/libraries/save_data/savedata.h"
#include "core/libraries/screenshot/screenshot.h" #include "core/libraries/screenshot/screenshot.h"
@ -71,6 +72,7 @@ void InitHLELibs(Core::Loader::SymbolsResolver* sym) {
Libraries::AppContent::RegisterlibSceAppContent(sym); Libraries::AppContent::RegisterlibSceAppContent(sym);
Libraries::PngDec::RegisterlibScePngDec(sym); Libraries::PngDec::RegisterlibScePngDec(sym);
Libraries::PlayGo::RegisterlibScePlayGo(sym); Libraries::PlayGo::RegisterlibScePlayGo(sym);
Libraries::Random::RegisterlibSceRandom(sym);
Libraries::Usbd::RegisterlibSceUsbd(sym); Libraries::Usbd::RegisterlibSceUsbd(sym);
Libraries::Pad::RegisterlibScePad(sym); Libraries::Pad::RegisterlibScePad(sym);
Libraries::Ajm::RegisterlibSceAjm(sym); Libraries::Ajm::RegisterlibSceAjm(sym);

View File

@ -0,0 +1,27 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/logging/log.h"
#include "core/libraries/error_codes.h"
#include "core/libraries/libs.h"
#include "random.h"
namespace Libraries::Random {
s32 PS4_SYSV_ABI sceRandomGetRandomNumber(u8* buf, size_t size) {
LOG_TRACE(Lib_Random, "called");
if (size > SCE_RANDOM_MAX_SIZE) {
return SCE_RANDOM_ERROR_INVALID;
}
for (auto i = 0; i < size; ++i) {
buf[i] = std::rand() & 0xFF;
}
return ORBIS_OK;
}
void RegisterlibSceRandom(Core::Loader::SymbolsResolver* sym) {
LIB_FUNCTION("PI7jIZj4pcE", "libSceRandom", 1, "libSceRandom", 1, 1, sceRandomGetRandomNumber);
};
} // namespace Libraries::Random

View File

@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "common/types.h"
namespace Core::Loader {
class SymbolsResolver;
}
namespace Libraries::Random {
constexpr int32_t SCE_RANDOM_MAX_SIZE = 64;
s32 PS4_SYSV_ABI sceRandomGetRandomNumber(u8* buf, size_t size);
void RegisterlibSceRandom(Core::Loader::SymbolsResolver* sym);
} // namespace Libraries::Random