shadPS4/src/emulator.cpp

69 lines
2.2 KiB
C++
Raw Normal View History

2023-08-09 09:31:18 +02:00
#include "emulator.h"
2023-09-12 18:39:08 +02:00
2023-09-11 12:14:13 +02:00
#include "Core/PS4/HLE/Graphics/video_out.h"
2023-08-09 09:31:18 +02:00
namespace Emulator {
2023-09-12 18:39:08 +02:00
static WindowCtx* g_window_ctx = nullptr;
void emuInit(u32 width, u32 height) {
g_window_ctx = new WindowCtx;
g_window_ctx->m_graphic_ctx.screen_width = width;
g_window_ctx->m_graphic_ctx.screen_height = height;
}
static void CreateSdlWindow(WindowCtx* ctx) {
int width = static_cast<int>(ctx->m_graphic_ctx.screen_width);
int height = static_cast<int>(ctx->m_graphic_ctx.screen_height);
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("%s\n", SDL_GetError());
std::_Exit(0);
}
ctx->m_window = SDL_CreateWindowWithPosition("shadps4", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height,
(static_cast<uint32_t>(SDL_WINDOW_HIDDEN) | static_cast<uint32_t>(SDL_WINDOW_VULKAN)));
ctx->is_window_hidden = true;//hide window until we need to show something (should draw something in buffers)
if (ctx->m_window == nullptr) {
printf("%s\n", SDL_GetError());
std::_Exit(0);
}
SDL_SetWindowResizable(ctx->m_window, SDL_FALSE);//we don't support resizable atm
SDL_ShowWindow(g_window_ctx->m_window);//TODO should be removed just left it over to make it fancy :D
}
2023-08-09 09:31:18 +02:00
void emuRun() {
2023-09-12 18:39:08 +02:00
g_window_ctx->m_mutex.LockMutex();
{
// init window and wait until init finishes
CreateSdlWindow(g_window_ctx);
g_window_ctx->m_is_graphic_initialized = true;
g_window_ctx->m_graphic_initialized_cond.SignalCondVar();
}
g_window_ctx->m_mutex.UnlockMutex();
2023-09-14 15:49:47 +02:00
auto* pdata = new EmuPrivate;
pdata->m_graphic_ctx = static_cast<HLE::Libs::Graphics::GraphicCtx*>(&g_window_ctx->m_graphic_ctx);
pdata->data1 = pdata;
pdata->data2 = new SDL_Event;
pdata->m_screen_width = pdata->m_graphic_ctx->screen_width;
pdata->m_screen_height = pdata->m_graphic_ctx->screen_height;
2023-09-12 18:39:08 +02:00
2023-08-09 09:31:18 +02:00
for (;;) {
2023-09-14 15:49:47 +02:00
SDL_Event* ev = static_cast<SDL_Event*>(pdata->data2);
if (SDL_PollEvent(ev)!= 0)
{
printf("Event: 0x%04\n", ev->type);
printf("]");
}
2023-09-12 18:39:08 +02:00
HLE::Libs::Graphics::VideoOut::videoOutFlip(100000); // flip every 0.1 sec
2023-08-09 09:31:18 +02:00
}
2023-09-12 18:39:08 +02:00
std::_Exit(0);
2023-08-09 09:31:18 +02:00
}
2023-09-12 18:39:08 +02:00
} // namespace Emulator