rpcsx/rpcs3/rpcs3.cpp

244 lines
5.4 KiB
C++
Raw Normal View History

#include "stdafx_gui.h"
2014-08-29 20:30:21 +02:00
#include "Emu/Memory/Memory.h"
#include "Emu/System.h"
#include "rpcs3.h"
#include "Ini.h"
2014-12-26 15:06:36 +01:00
#include "Utilities/Log.h"
#include "Gui/ConLogFrame.h"
#include "Emu/GameInfo.h"
2014-02-21 17:13:57 +01:00
2014-08-26 01:55:37 +02:00
#include "Emu/Io/Keyboard.h"
2014-08-24 19:42:19 +02:00
#include "Emu/Io/Null/NullKeyboardHandler.h"
#include "Emu/Io/Windows/WindowsKeyboardHandler.h"
2014-08-26 01:55:37 +02:00
#include "Emu/Io/Mouse.h"
2014-08-24 19:42:19 +02:00
#include "Emu/Io/Null/NullMouseHandler.h"
#include "Emu/Io/Windows/WindowsMouseHandler.h"
2014-08-26 01:55:37 +02:00
#include "Emu/Io/Pad.h"
2014-08-24 19:42:19 +02:00
#include "Emu/Io/Null/NullPadHandler.h"
#include "Emu/Io/Windows/WindowsPadHandler.h"
#if defined(_WIN32)
#include "Emu/Io/XInput/XInputPadHandler.h"
#endif
#include "Emu/RSX/Null/NullGSRender.h"
#include "Emu/RSX/GL/GLGSRender.h"
#if defined(DX12_SUPPORT)
#include "Emu/RSX/D3D12/D3D12GSRender.h"
#endif
2014-08-29 20:30:21 +02:00
#include "Gui/MsgDialog.h"
2015-04-16 17:33:55 +02:00
#include "Gui/SaveDataDialog.h"
2014-08-29 20:30:21 +02:00
#include "Gui/GLGSFrame.h"
#include <wx/stdpaths.h>
2014-02-21 17:13:57 +01:00
#ifdef _WIN32
#include <wx/msw/wrapwin.h>
2014-02-21 17:13:57 +01:00
#endif
2014-09-03 12:06:11 +02:00
#ifdef __unix__
2014-03-28 12:33:51 +01:00
#include <X11/Xlib.h>
#endif
wxDEFINE_EVENT(wxEVT_DBG_COMMAND, wxCommandEvent);
IMPLEMENT_APP(Rpcs3App)
Rpcs3App* TheApp;
bool Rpcs3App::OnInit()
{
static const wxCmdLineEntryDesc desc[]
{
{ wxCMD_LINE_SWITCH, "h", "help", "Command line options:\nh (help): Help and commands\nt (test): For directly executing a (S)ELF", wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
{ wxCMD_LINE_SWITCH, "t", "test", "Run in test mode on (S)ELF", wxCMD_LINE_VAL_NONE },
{ wxCMD_LINE_PARAM, NULL, NULL, "(S)ELF", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
{ wxCMD_LINE_NONE }
};
parser.SetDesc(desc);
parser.SetCmdLine(argc, argv);
if (parser.Parse())
{
// help was given, terminating
this->Exit();
}
EmuCallbacks callbacks;
callbacks.call_after = [](std::function<void()> func)
2014-08-24 19:42:19 +02:00
{
wxGetApp().CallAfter(std::move(func));
};
callbacks.process_events = [this]()
2014-08-24 19:42:19 +02:00
{
m_MainFrame->Update();
wxGetApp().ProcessPendingEvents();
};
callbacks.send_dbg_command = [](DbgCommand id, CPUThread* t)
2014-08-24 19:42:19 +02:00
{
wxGetApp().SendDbgCommand(id, t);
};
callbacks.get_kb_handler = []() -> std::unique_ptr<KeyboardHandlerBase>
2014-08-24 19:42:19 +02:00
{
switch (auto mode = Ini.KeyboardHandlerMode.GetValue())
2014-08-24 19:42:19 +02:00
{
case 0: return std::make_unique<NullKeyboardHandler>();
case 1: return std::make_unique<WindowsKeyboardHandler>();
default: throw EXCEPTION("Invalid Keyboard Handler Mode %d", +mode);
2014-08-24 19:42:19 +02:00
}
};
callbacks.get_mouse_handler = []() -> std::unique_ptr<MouseHandlerBase>
2014-08-24 19:42:19 +02:00
{
switch (auto mode = Ini.MouseHandlerMode.GetValue())
2014-08-24 19:42:19 +02:00
{
case 0: return std::make_unique<NullMouseHandler>();
case 1: return std::make_unique<WindowsMouseHandler>();
default: throw EXCEPTION("Invalid Mouse Handler Mode %d", +mode);
2014-08-24 19:42:19 +02:00
}
};
callbacks.get_pad_handler = []() -> std::unique_ptr<PadHandlerBase>
2014-08-24 19:42:19 +02:00
{
switch (auto mode = Ini.PadHandlerMode.GetValue())
2014-08-24 19:42:19 +02:00
{
case 0: return std::make_unique<NullPadHandler>();
case 1: return std::make_unique<WindowsPadHandler>();
2014-08-24 19:42:19 +02:00
#if defined(_WIN32)
case 2: return std::make_unique<XInputPadHandler>();
2014-08-24 19:42:19 +02:00
#endif
default: throw EXCEPTION("Invalid Pad Handler Mode %d", +mode);
2014-08-24 19:42:19 +02:00
}
};
callbacks.get_gs_frame = [](frame_type type) -> std::unique_ptr<GSFrameBase>
{
switch (type)
{
case frame_type::OpenGL:
return std::make_unique<GLGSFrame>();
case frame_type::DX12:
return std::make_unique<GSFrame>("DirectX 12");
case frame_type::Null:
return std::make_unique<GSFrame>("Null");
}
};
2015-05-10 02:21:43 +02:00
callbacks.get_msg_dialog = []() -> std::unique_ptr<MsgDialogBase>
{
return std::make_unique<MsgDialogFrame>();
};
callbacks.get_save_dialog = []() -> std::unique_ptr<SaveDialogBase>
{
return std::make_unique<SaveDialogFrame>();
};
Emu.SetCallbacks(std::move(callbacks));
2014-08-24 19:42:19 +02:00
TheApp = this;
SetAppName(_PRGNAME_);
wxInitAllImageHandlers();
// RPCS3 assumes the current working directory is the folder where it is contained, so we make sure this is true
2014-11-29 14:16:53 +01:00
const wxString executablePath = wxPathOnly(wxStandardPaths::Get().GetExecutablePath());
wxSetWorkingDirectory(executablePath);
Ini.Load();
Emu.Init();
2014-11-29 14:16:53 +01:00
Emu.SetEmulatorPath(executablePath.ToStdString());
m_MainFrame = new MainFrame();
SetTopWindow(m_MainFrame);
m_MainFrame->Show();
m_MainFrame->DoSettings(true);
2014-01-19 17:05:27 +01:00
OnArguments(parser);
return true;
}
void Rpcs3App::OnArguments(const wxCmdLineParser& parser)
{
// Usage:
// rpcs3-*.exe Initializes RPCS3
// rpcs3-*.exe [(S)ELF] Initializes RPCS3, then loads and runs the specified (S)ELF file.
if (parser.FoundSwitch("t"))
{
HLEExitOnStop = Ini.HLEExitOnStop.GetValue();
Ini.HLEExitOnStop.SetValue(true);
if (parser.GetParamCount() != 1)
{
wxLogDebug(wxT("A (S)ELF file needs to be given in test mode, exiting."));
this->Exit();
}
}
if (parser.GetParamCount() > 0)
{
Emu.SetPath(fmt::ToUTF8(parser.GetParam(0)));
Emu.Load();
Emu.Run();
}
}
void Rpcs3App::Exit()
{
if (parser.FoundSwitch("t"))
{
Ini.HLEExitOnStop.SetValue(HLEExitOnStop);
}
Emu.Stop();
Ini.Save();
wxApp::Exit();
}
void Rpcs3App::SendDbgCommand(DbgCommand id, CPUThread* thr)
{
wxCommandEvent event(wxEVT_DBG_COMMAND, id);
event.SetClientData(thr);
AddPendingEvent(event);
}
2014-03-28 12:33:51 +01:00
Rpcs3App::Rpcs3App()
{
#ifdef _WIN32
timeBeginPeriod(1);
std::atexit([]
{
timeEndPeriod(1);
});
#endif
#if defined(__unix__) && !defined(__APPLE__)
2014-03-28 12:33:51 +01:00
XInitThreads();
#endif
2014-03-28 12:33:51 +01:00
}
GameInfo CurGameInfo;
GSRender * createGSRender(u8 id)
{
switch (id)
{
default:
case 0: return new NullGSRender(); break;
case 1: return new GLGSRender(); break;
#if defined(DX12_SUPPORT)
case 2: return new D3D12GSRender(); break;
#endif
}
}