2015-12-02 17:12:48 +01:00
# include "stdafx.h"
2014-08-29 00:49:26 +02:00
# include "stdafx_gui.h"
2016-04-14 00:59:00 +02:00
# include "rpcs3.h"
# include "Utilities/Config.h"
2014-08-29 20:30:21 +02:00
# include "Emu/Memory/Memory.h"
2014-06-02 19:27:24 +02:00
# include "Emu/System.h"
2016-04-14 00:59:00 +02:00
2014-06-02 19:27:24 +02:00
# include "Gui/ConLogFrame.h"
2014-05-02 08:30:32 +02:00
# include "Emu/GameInfo.h"
2014-02-21 17:13:57 +01:00
2014-08-24 19:42:19 +02:00
# include "Emu/Io/Null/NullKeyboardHandler.h"
2016-04-14 00:59:00 +02:00
# include "BasicKeyboardHandler.h"
2014-08-24 19:42:19 +02:00
# include "Emu/Io/Null/NullMouseHandler.h"
2016-04-14 00:59:00 +02:00
# include "BasicMouseHandler.h"
2014-08-24 19:42:19 +02:00
# include "Emu/Io/Null/NullPadHandler.h"
2016-04-14 00:59:00 +02:00
# include "KeyboardPadHandler.h"
2017-04-29 03:02:28 +02:00
# include "DS4PadHandler.h"
2015-11-16 16:04:49 +01:00
# ifdef _MSC_VER
2016-04-14 00:59:00 +02:00
# include "XInputPadHandler.h"
2017-05-20 13:45:02 +02:00
# endif
# ifdef _WIN32
2017-02-10 13:28:00 +01:00
# include "MMJoystickHandler.h"
2014-08-24 19:42:19 +02:00
# endif
2015-10-06 16:02:51 +02:00
# include "Emu/RSX/Null/NullGSRender.h"
# include "Emu/RSX/GL/GLGSRender.h"
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
2014-08-25 00:23:26 +02:00
# include "Gui/GLGSFrame.h"
2015-12-02 17:12:48 +01:00
# include "Emu/RSX/Null/NullGSRender.h"
# include "Emu/RSX/GL/GLGSRender.h"
2015-12-30 02:12:18 +01:00
# include "Emu/Audio/Null/NullAudioThread.h"
# include "Emu/Audio/AL/OpenALThread.h"
2015-12-02 17:12:48 +01:00
# ifdef _MSC_VER
# include "Emu/RSX/D3D12/D3D12GSRender.h"
# endif
2014-02-21 17:13:57 +01:00
# ifdef _WIN32
2016-06-07 22:24:20 +02:00
# include "Emu/RSX/VK/VKGSRender.h"
2016-04-25 12:49:12 +02:00
# include "Emu/Audio/XAudio2/XAudio2Thread.h"
2012-11-15 00:39:56 +01:00
# include <wx/msw/wrapwin.h>
2014-02-21 17:13:57 +01:00
# endif
2017-04-09 14:59:19 +02:00
# ifdef __linux__
# include "Emu/Audio/ALSA/ALSAThread.h"
# endif
2013-06-30 10:46:29 +02:00
2014-09-03 12:06:11 +02:00
# ifdef __unix__
2014-03-28 12:33:51 +01:00
# include <X11/Xlib.h>
# endif
2016-04-14 00:59:00 +02:00
// GUI config
YAML : : Node g_gui_cfg ;
// GUI config file
static fs : : file s_gui_cfg ;
void save_gui_cfg ( )
{
YAML : : Emitter out ;
out . SetSeqFormat ( YAML : : Flow ) ;
out < < g_gui_cfg ;
// Save to file
s_gui_cfg . seek ( 0 ) ;
s_gui_cfg . trunc ( 0 ) ;
s_gui_cfg . write ( out . c_str ( ) , out . size ( ) ) ;
}
2012-11-15 00:39:56 +01:00
IMPLEMENT_APP ( Rpcs3App )
Rpcs3App * TheApp ;
bool Rpcs3App : : OnInit ( )
{
2015-01-27 16:14:15 +01:00
static const wxCmdLineEntryDesc desc [ ]
{
{ wxCMD_LINE_SWITCH , " h " , " help " , " Command line options: \n h (help): Help and commands \n t (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 ) ;
2015-09-18 00:41:14 +02:00
2015-01-27 16:14:15 +01:00
if ( parser . Parse ( ) )
{
// help was given, terminating
this - > Exit ( ) ;
}
2016-04-14 00:59:00 +02:00
s_gui_cfg . open ( fs : : get_config_dir ( ) + " /config_gui.yml " , fs : : read + fs : : write + fs : : create ) ;
g_gui_cfg = YAML : : Load ( s_gui_cfg . to_string ( ) ) ;
2015-09-18 00:41:14 +02:00
EmuCallbacks callbacks ;
callbacks . call_after = [ ] ( std : : function < void ( ) > func )
2014-08-24 19:42:19 +02:00
{
2015-09-18 00:41:14 +02:00
wxGetApp ( ) . CallAfter ( std : : move ( func ) ) ;
} ;
2014-12-19 00:18:44 +01:00
2015-09-18 00:41:14 +02:00
callbacks . process_events = [ this ] ( )
2014-08-24 19:42:19 +02:00
{
2015-09-18 00:41:14 +02:00
m_MainFrame - > Update ( ) ;
wxGetApp ( ) . ProcessPendingEvents ( ) ;
} ;
2014-12-19 00:18:44 +01:00
2016-04-14 00:59:00 +02:00
callbacks . exit = [ this ] ( )
2014-08-24 19:42:19 +02:00
{
2016-04-14 00:59:00 +02:00
wxGetApp ( ) . Exit ( ) ;
2015-09-18 00:41:14 +02:00
} ;
2014-12-19 00:18:44 +01:00
2017-05-20 13:45:02 +02:00
callbacks . get_kb_handler = [ ] ( ) - > std : : shared_ptr < KeyboardHandlerBase >
{
switch ( keyboard_handler type = g_cfg . io . keyboard )
{
case keyboard_handler : : null : return std : : make_shared < NullKeyboardHandler > ( ) ;
case keyboard_handler : : basic : return std : : make_shared < BasicKeyboardHandler > ( ) ;
default : fmt : : throw_exception ( " Invalid keyboard handler: %s " , type ) ;
}
} ;
2016-04-14 00:59:00 +02:00
2017-05-20 13:45:02 +02:00
callbacks . get_mouse_handler = [ ] ( ) - > std : : shared_ptr < MouseHandlerBase >
{
switch ( mouse_handler type = g_cfg . io . mouse )
{
case mouse_handler : : null : return std : : make_shared < NullMouseHandler > ( ) ;
case mouse_handler : : basic : return std : : make_shared < BasicMouseHandler > ( ) ;
default : fmt : : throw_exception ( " Invalid mouse handler: %s " , type ) ;
}
} ;
2014-12-19 00:18:44 +01:00
2017-05-20 13:45:02 +02:00
callbacks . get_pad_handler = [ ] ( ) - > std : : shared_ptr < PadHandlerBase >
2014-08-25 00:23:26 +02:00
{
2017-05-20 13:45:02 +02:00
switch ( pad_handler type = g_cfg . io . pad )
2015-10-05 02:42:48 +02:00
{
2017-05-20 13:45:02 +02:00
case pad_handler : : null : return std : : make_shared < NullPadHandler > ( ) ;
case pad_handler : : keyboard : return std : : make_shared < KeyboardPadHandler > ( ) ;
case pad_handler : : ds4 : return std : : make_shared < DS4PadHandler > ( ) ;
# ifdef _MSC_VER
case pad_handler : : xinput : return std : : make_shared < XInputPadHandler > ( ) ;
# endif
# ifdef _WIN32
case pad_handler : : mm : return std : : make_shared < MMJoystickHandler > ( ) ;
# endif
default : fmt : : throw_exception ( " Invalid pad handler: %s " , type ) ;
2015-10-05 02:42:48 +02:00
}
2017-05-20 13:45:02 +02:00
} ;
callbacks . get_gs_frame = [ ] ( ) - > std : : unique_ptr < GSFrameBase >
{
extern const std : : unordered_map < video_resolution , std : : pair < int , int > , value_hash < video_resolution > > g_video_out_resolution_map ;
2015-10-21 09:24:02 +02:00
2017-05-20 13:45:02 +02:00
const auto size = g_video_out_resolution_map . at ( g_cfg . video . resolution ) ;
switch ( video_renderer type = g_cfg . video . renderer )
{
case video_renderer : : null : return std : : make_unique < GSFrame > ( " Null " , size . first , size . second ) ;
case video_renderer : : opengl : return std : : make_unique < GLGSFrame > ( size . first , size . second ) ;
# ifdef _WIN32
case video_renderer : : vulkan : return std : : make_unique < GSFrame > ( " Vulkan " , size . first , size . second ) ;
# endif
# ifdef _MSC_VER
case video_renderer : : dx12 : return std : : make_unique < GSFrame > ( " DirectX 12 " , size . first , size . second ) ;
# endif
default : fmt : : throw_exception ( " Invalid video renderer: %s " HERE , type ) ;
}
2015-10-05 02:42:48 +02:00
} ;
2015-05-10 02:21:43 +02:00
2017-05-20 13:45:02 +02:00
callbacks . get_gs_render = [ ] ( ) - > std : : shared_ptr < GSRender >
{
switch ( video_renderer type = g_cfg . video . renderer )
{
case video_renderer : : null : return std : : make_shared < NullGSRender > ( ) ;
case video_renderer : : opengl : return std : : make_shared < GLGSRender > ( ) ;
# ifdef _WIN32
case video_renderer : : vulkan : return std : : make_shared < VKGSRender > ( ) ;
# endif
# ifdef _MSC_VER
case video_renderer : : dx12 : return std : : make_shared < D3D12GSRender > ( ) ;
# endif
default : fmt : : throw_exception ( " Invalid video renderer: %s " HERE , type ) ;
}
} ;
2015-12-02 17:12:48 +01:00
2017-05-20 13:45:02 +02:00
callbacks . get_audio = [ ] ( ) - > std : : shared_ptr < AudioThread >
{
switch ( audio_renderer type = g_cfg . audio . renderer )
{
case audio_renderer : : null : return std : : make_shared < NullAudioThread > ( ) ;
# ifdef _WIN32
case audio_renderer : : xaudio : return std : : make_shared < XAudio2Thread > ( ) ;
# elif __linux__
case audio_renderer : : alsa : return std : : make_shared < ALSAThread > ( ) ;
# endif
case audio_renderer : : openal : return std : : make_shared < OpenALThread > ( ) ;
default : fmt : : throw_exception ( " Invalid audio renderer: %s " HERE , type ) ;
}
} ;
2015-12-30 02:12:18 +01:00
2015-12-19 12:40:52 +01:00
callbacks . get_msg_dialog = [ ] ( ) - > std : : shared_ptr < MsgDialogBase >
2015-09-18 00:41:14 +02:00
{
2015-12-19 12:40:52 +01:00
return std : : make_shared < MsgDialogFrame > ( ) ;
2015-09-18 00:41:14 +02:00
} ;
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
2012-11-15 00:39:56 +01:00
TheApp = this ;
2016-07-21 00:00:31 +02:00
SetAppName ( " RPCS3 " ) ;
2012-11-15 00:39:56 +01:00
wxInitAllImageHandlers ( ) ;
Emu . Init ( ) ;
2013-06-30 10:46:29 +02:00
2014-11-29 15:16:48 +01:00
m_MainFrame = new MainFrame ( ) ;
SetTopWindow ( m_MainFrame ) ;
2012-11-15 00:39:56 +01:00
m_MainFrame - > Show ( ) ;
2013-06-30 10:46:29 +02:00
m_MainFrame - > DoSettings ( true ) ;
2014-01-19 17:05:27 +01:00
2015-01-27 16:14:15 +01:00
OnArguments ( parser ) ;
2014-02-27 04:21:08 +01:00
2012-11-15 00:39:56 +01:00
return true ;
}
2015-01-27 16:14:15 +01:00
void Rpcs3App : : OnArguments ( const wxCmdLineParser & parser )
2014-02-27 04:21:08 +01:00
{
// Usage:
// rpcs3-*.exe Initializes RPCS3
// rpcs3-*.exe [(S)ELF] Initializes RPCS3, then loads and runs the specified (S)ELF file.
2015-01-27 16:14:15 +01:00
if ( parser . FoundSwitch ( " t " ) )
{
if ( parser . GetParamCount ( ) ! = 1 )
{
2016-04-14 00:59:00 +02:00
wxLogDebug ( " A (S)ELF file needs to be given in test mode, exiting. " ) ;
2015-01-27 16:14:15 +01:00
this - > Exit ( ) ;
}
2016-04-14 00:59:00 +02:00
// TODO: clean implementation
2017-05-20 13:45:02 +02:00
g_cfg . misc . autostart . from_string ( " true " ) ;
g_cfg . misc . autoexit . from_string ( " true " ) ;
2015-01-27 16:14:15 +01:00
}
if ( parser . GetParamCount ( ) > 0 )
{
Emu . SetPath ( fmt : : ToUTF8 ( parser . GetParam ( 0 ) ) ) ;
2014-02-27 04:21:08 +01:00
Emu . Load ( ) ;
Emu . Run ( ) ;
}
}
2012-11-15 00:39:56 +01:00
void Rpcs3App : : Exit ( )
{
Emu . Stop ( ) ;
wxApp : : Exit ( ) ;
}
2014-03-28 12:33:51 +01:00
Rpcs3App : : Rpcs3App ( )
{
2014-11-10 00:34:28 +01:00
# ifdef _WIN32
timeBeginPeriod ( 1 ) ;
2015-09-18 00:41:14 +02:00
2016-04-18 09:06:22 +02:00
WSADATA wsaData ;
WORD wVersionRequested = MAKEWORD ( 2 , 2 ) ;
WSAStartup ( wVersionRequested , & wsaData ) ;
2015-09-18 00:41:14 +02:00
std : : atexit ( [ ]
{
timeEndPeriod ( 1 ) ;
2016-04-18 09:06:22 +02:00
WSACleanup ( ) ;
2015-09-18 00:41:14 +02:00
} ) ;
2014-11-10 00:34:28 +01:00
# endif
2014-12-17 15:01:59 +01:00
# if defined(__unix__) && !defined(__APPLE__)
2014-03-28 12:33:51 +01:00
XInitThreads ( ) ;
2014-12-17 15:01:59 +01:00
# endif
2014-03-28 12:33:51 +01:00
}