mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2024-12-29 11:06:07 +00:00
code: Replace printf/scanf with type safe fmt
This commit is contained in:
parent
33729d634e
commit
28819dede1
|
@ -1,5 +1,5 @@
|
|||
#include "graphics_render.h"
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include "Emulator/Util/singleton.h"
|
||||
#include "emulator.h"
|
||||
|
||||
|
@ -60,7 +60,7 @@ void GPU::CommandBuffer::begin() const {
|
|||
auto result = vkBeginCommandBuffer(buffer, &begin_info);
|
||||
|
||||
if (result != VK_SUCCESS) {
|
||||
printf("vkBeginCommandBuffer failed\n");
|
||||
fmt::print("vkBeginCommandBuffer failed\n");
|
||||
std::exit(0);
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ void GPU::CommandBuffer::end() const {
|
|||
auto result = vkEndCommandBuffer(buffer);
|
||||
|
||||
if (result != VK_SUCCESS) {
|
||||
printf("vkEndCommandBuffer failed\n");
|
||||
fmt::print("vkEndCommandBuffer failed\n");
|
||||
std::exit(0);
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ void GPU::CommandBuffer::executeWithSemaphore() {
|
|||
m_execute = true;
|
||||
|
||||
if (result != VK_SUCCESS) {
|
||||
printf("vkQueueSubmit failed\n");
|
||||
fmt::print("vkQueueSubmit failed\n");
|
||||
std::exit(0);
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ void GPU::CommandBuffer::execute() {
|
|||
m_execute = true;
|
||||
|
||||
if (result != VK_SUCCESS) {
|
||||
printf("vkQueueSubmit failed\n");
|
||||
fmt::print("vkQueueSubmit failed\n");
|
||||
std::exit(0);
|
||||
}
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ void GPU::CommandPool::createPool(int id) {
|
|||
vkCreateCommandPool(ctx->m_device, &pool_info, nullptr, &m_pool[id]->pool);
|
||||
|
||||
if (m_pool[id]->pool == nullptr) {
|
||||
printf("pool is nullptr");
|
||||
fmt::print("pool is nullptr");
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ void GPU::CommandPool::createPool(int id) {
|
|||
alloc_info.commandBufferCount = m_pool[id]->buffers_count;
|
||||
|
||||
if (vkAllocateCommandBuffers(ctx->m_device, &alloc_info, m_pool[id]->buffers) != VK_SUCCESS) {
|
||||
printf("Can't allocate command buffers\n");
|
||||
fmt::print("Can't allocate command buffers\n");
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,7 @@ void GPU::CommandPool::createPool(int id) {
|
|||
fence_info.flags = 0;
|
||||
|
||||
if (vkCreateFence(ctx->m_device, &fence_info, nullptr, &m_pool[id]->fences[i]) != VK_SUCCESS) {
|
||||
printf("Can't create fence\n");
|
||||
fmt::print("Can't create fence\n");
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
|
@ -181,7 +181,7 @@ void GPU::CommandPool::createPool(int id) {
|
|||
semaphore_info.flags = 0;
|
||||
|
||||
if (vkCreateSemaphore(ctx->m_device, &semaphore_info, nullptr, &m_pool[id]->semaphores[i]) != VK_SUCCESS) {
|
||||
printf("Can't create semas\n");
|
||||
fmt::print("Can't create semas\n");
|
||||
std::exit(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "Linker.h"
|
||||
#include "../virtual_memory.h"
|
||||
#include <Util/log.h>
|
||||
#include <fmt/core.h>
|
||||
#include "Zydis.h"
|
||||
#include <Util/string_util.h>
|
||||
#include "Util/aerolib.h"
|
||||
|
@ -175,7 +176,7 @@ void Linker::LoadModuleToMemory(Module* m)
|
|||
/* length: */ sizeof(rt1) - offset,
|
||||
/* instruction: */ &instruction
|
||||
))) {
|
||||
printf("%016" PRIX64 " %s\n", runtime_address, instruction.text);
|
||||
fmt::print("{:#x}" PRIX64 " {}\n", runtime_address, instruction.text);
|
||||
offset += instruction.info.length;
|
||||
runtime_address += instruction.info.length;
|
||||
}
|
||||
|
@ -625,8 +626,7 @@ using exit_func_t = PS4_SYSV_ABI void (*)();
|
|||
using entry_func_t = PS4_SYSV_ABI void (*)(EntryParams* params, exit_func_t atexit_func);
|
||||
|
||||
static PS4_SYSV_ABI void ProgramExitFunc() {
|
||||
|
||||
printf("exit function called\n");
|
||||
fmt::print("exit function called\n");
|
||||
}
|
||||
|
||||
static void run_main_entry(u64 addr, EntryParams* params, exit_func_t exit_func) {
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include "SymbolsResolver.h"
|
||||
#include <Util/log.h>
|
||||
|
||||
|
||||
void SymbolsResolver::AddSymbol(const SymbolRes& s, u64 virtual_addr)
|
||||
{
|
||||
SymbolRecord r{};
|
||||
|
@ -12,21 +11,19 @@ void SymbolsResolver::AddSymbol(const SymbolRes& s, u64 virtual_addr)
|
|||
}
|
||||
|
||||
std::string SymbolsResolver::GenerateName(const SymbolRes& s) {
|
||||
char str[256];
|
||||
sprintf(str, "%s lib[%s_v%d]mod[%s_v%d.%d]", s.name.c_str(),s.library.c_str(), s.library_version, s.module.c_str(),
|
||||
s.module_version_major, s.module_version_minor);
|
||||
return std::string(str);
|
||||
return fmt::format("{} lib[{}_v{}]mod[{}_v{}.{}]",
|
||||
s.name, s.library, s.library_version,
|
||||
s.module, s.module_version_major, s.module_version_minor);
|
||||
}
|
||||
|
||||
const SymbolRecord* SymbolsResolver::FindSymbol(const SymbolRes& s) const {
|
||||
std::string name = GenerateName(s);
|
||||
int index = 0;
|
||||
for (auto symbol : m_symbols) {
|
||||
if (symbol.name.compare(name) == 0) {
|
||||
return &m_symbols.at(index);
|
||||
const std::string name = GenerateName(s);
|
||||
for (u32 i = 0; i < m_symbols.size(); i++) {
|
||||
if (m_symbols[i].name.compare(name) == 0) {
|
||||
return &m_symbols[i];
|
||||
}
|
||||
index++;
|
||||
}
|
||||
LOG_INFO_IF(true, "unresolved! {}\n", name);
|
||||
|
||||
LOG_INFO("Unresolved! {}\n", name);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ public:
|
|||
if (!m_instance) {
|
||||
m_instance = std::make_unique<T>();
|
||||
}
|
||||
return m_instance;
|
||||
return m_instance.get();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "Disassembler.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
Disassembler::Disassembler()
|
||||
{
|
||||
|
@ -15,11 +14,11 @@ Disassembler::~Disassembler()
|
|||
void Disassembler::printInstruction(void* code,u64 address)//print a single instruction
|
||||
{
|
||||
ZydisDecodedInstruction instruction;
|
||||
ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT_VISIBLE];
|
||||
ZyanStatus status = ZydisDecoderDecodeFull(&m_decoder, code, sizeof(code), &instruction, operands);
|
||||
ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT_VISIBLE];
|
||||
ZyanStatus status = ZydisDecoderDecodeFull(&m_decoder, code, sizeof(code), &instruction, operands);
|
||||
if (!ZYAN_SUCCESS(status))
|
||||
{
|
||||
printf("decode instruction failed at %p\n", code);
|
||||
fmt::print("decode instruction failed at {}\n", fmt::ptr(code));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -30,7 +29,7 @@ void Disassembler::printInstruction(void* code,u64 address)//print a single inst
|
|||
void Disassembler::printInst(ZydisDecodedInstruction& inst, ZydisDecodedOperand* operands,u64 address)
|
||||
{
|
||||
const int bufLen = 256;
|
||||
char szBuffer[bufLen];
|
||||
char szBuffer[bufLen];
|
||||
ZydisFormatterFormatInstruction(&m_formatter, &inst, operands,inst.operand_count_visible, szBuffer, sizeof(szBuffer), address, ZYAN_NULL);
|
||||
printf("instruction: %s\n", szBuffer);
|
||||
}
|
||||
fmt::print("instruction: {}\n", szBuffer);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <fmt/core.h>
|
||||
#include <toml11/toml.hpp>
|
||||
|
||||
namespace Config {
|
||||
|
@ -29,7 +30,7 @@ void load(const std::filesystem::path& path) {
|
|||
try {
|
||||
data = toml::parse(path);
|
||||
} catch (std::exception& ex) {
|
||||
printf("Got exception trying to load config file. Exception: %s\n", ex.what());
|
||||
fmt::print("Got exception trying to load config file. Exception: {}\n", ex.what());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -61,14 +62,14 @@ void save(const std::filesystem::path& path) {
|
|||
try {
|
||||
data = toml::parse<toml::preserve_comments>(path);
|
||||
} catch (const std::exception& ex) {
|
||||
printf("Exception trying to parse config file. Exception: %s\n", ex.what());
|
||||
fmt::print("Exception trying to parse config file. Exception: {}\n", ex.what());
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (error) {
|
||||
printf("Filesystem error accessing %s (error: %s)\n", path.string().c_str(), error.message().c_str());
|
||||
fmt::print("Filesystem error accessing {} (error: {})\n", path.string(), error.message().c_str());
|
||||
}
|
||||
printf("Saving new configuration file %s\n", path.string().c_str());
|
||||
fmt::print("Saving new configuration file {}\n", path.string());
|
||||
}
|
||||
|
||||
data["General"]["isPS4Pro"] = isNeo;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "emulator.h"
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include <Core/PS4/HLE/Graphics/graphics_render.h>
|
||||
#include <Emulator/Host/controller.h>
|
||||
#include "Emulator/Util/singleton.h"
|
||||
|
@ -33,7 +33,7 @@ static void CreateSdlWindow(WindowCtx* ctx) {
|
|||
int height = static_cast<int>(ctx->m_graphic_ctx.screen_height);
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
printf("%s\n", SDL_GetError());
|
||||
fmt::print("{}\n", SDL_GetError());
|
||||
std::exit(0);
|
||||
}
|
||||
std::string title = "shadps4 v" + std::string(Emulator::VERSION);
|
||||
|
@ -43,7 +43,7 @@ static void CreateSdlWindow(WindowCtx* ctx) {
|
|||
ctx->is_window_hidden = true; // hide window until we need to show something (should draw something in buffers)
|
||||
|
||||
if (ctx->m_window == nullptr) {
|
||||
printf("%s\n", SDL_GetError());
|
||||
fmt::print("{}\n", SDL_GetError());
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
|
@ -115,11 +115,11 @@ void DrawBuffer(HLE::Libs::Graphics::VideoOutVulkanImage* image) {
|
|||
window_ctx->swapchain->present_complete_fence, &window_ctx->swapchain->current_index);
|
||||
|
||||
if (result != VK_SUCCESS) {
|
||||
printf("Can't aquireNextImage\n");
|
||||
fmt::print("Can't aquireNextImage\n");
|
||||
std::exit(0);
|
||||
}
|
||||
if (window_ctx->swapchain->current_index == static_cast<u32>(-1)) {
|
||||
printf("Unsupported:swapchain current index is -1\n");
|
||||
fmt::print("Unsupported:swapchain current index is -1\n");
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,7 @@ void DrawBuffer(HLE::Libs::Graphics::VideoOutVulkanImage* image) {
|
|||
result = vkWaitForFences(window_ctx->m_graphic_ctx.m_device, 1, &window_ctx->swapchain->present_complete_fence, VK_TRUE, 100000000);
|
||||
} while (result == VK_TIMEOUT);
|
||||
if (result != VK_SUCCESS) {
|
||||
printf("vkWaitForFences is not success\n");
|
||||
fmt::print("vkWaitForFences is not success\n");
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
|
@ -137,11 +137,11 @@ void DrawBuffer(HLE::Libs::Graphics::VideoOutVulkanImage* image) {
|
|||
auto* blt_dst_image = window_ctx->swapchain;
|
||||
|
||||
if (blt_src_image == nullptr) {
|
||||
printf("blt_src_image is null\n");
|
||||
fmt::print("blt_src_image is null\n");
|
||||
std::exit(0);
|
||||
}
|
||||
if (blt_dst_image == nullptr) {
|
||||
printf("blt_dst_image is null\n");
|
||||
fmt::print("blt_dst_image is null\n");
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
|
@ -187,13 +187,13 @@ void DrawBuffer(HLE::Libs::Graphics::VideoOutVulkanImage* image) {
|
|||
const auto& queue = window_ctx->m_graphic_ctx.queues[10];
|
||||
|
||||
if (queue.mutex != nullptr) {
|
||||
printf("queue.mutexe is null\n");
|
||||
fmt::print("queue.mutexe is null\n");
|
||||
std::exit(0);
|
||||
}
|
||||
|
||||
result = vkQueuePresentKHR(queue.vk_queue, &present);
|
||||
if (result != VK_SUCCESS) {
|
||||
printf("vkQueuePresentKHR failed\n");
|
||||
fmt::print("vkQueuePresentKHR failed\n");
|
||||
std::exit(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#include <SDL3/SDL.h>
|
||||
#include <cstdio>
|
||||
#include <Util/log.h>
|
||||
#include <fmt/core.h>
|
||||
#include "types.h"
|
||||
#include "Util/log.h"
|
||||
#include <Core/PS4/HLE/Graphics/video_out.h>
|
||||
#include <Util/config.h>
|
||||
#include <Zydis/Zydis.h>
|
||||
|
@ -16,7 +17,7 @@
|
|||
// Main code
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc == 1) {
|
||||
printf("Usage: %s <elf or eboot.bin path>\n", argv[0]);
|
||||
fmt::print("Usage: {} <elf or eboot.bin path>\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
Config::load("config.toml");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "vulkan_util.h"
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include <Core/PS4/GPU/gpu_memory.h>
|
||||
#include <SDL_vulkan.h>
|
||||
#include <Emulator/Util/singleton.h>
|
||||
|
@ -588,7 +588,7 @@ void Graphics::Vulkan::vulkanCreateBuffer(HLE::Libs::Graphics::GraphicCtx* ctx,
|
|||
|
||||
bool allocated = GPU::vulkanAllocateMemory(ctx, &buffer->memory);
|
||||
if (!allocated) {
|
||||
printf("Can't allocate vulkan\n");
|
||||
fmt::print("Can't allocate vulkan\n");
|
||||
std::exit(0);
|
||||
}
|
||||
vkBindBufferMemory(ctx->m_device, buffer->buffer, buffer->memory.memory, buffer->memory.offset);
|
||||
|
|
Loading…
Reference in a new issue