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"
2015-11-16 16:04:49 +01:00
# ifdef _MSC_VER
2016-04-14 00:59:00 +02:00
# include "XInputPadHandler.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
2016-03-10 13:57:54 +01:00
# include "Emu/RSX/VK/VKGSRender.h"
2015-12-02 17:12:48 +01:00
# include "Emu/RSX/D3D12/D3D12GSRender.h"
# endif
2014-02-21 17:13:57 +01:00
# ifdef _WIN32
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
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 ( ) ) ;
}
2014-04-13 03:31:59 +02:00
wxDEFINE_EVENT ( wxEVT_DBG_COMMAND , wxCommandEvent ) ;
2012-11-15 00:39:56 +01:00
IMPLEMENT_APP ( Rpcs3App )
Rpcs3App * TheApp ;
2016-04-14 00:59:00 +02:00
cfg : : map_entry < std : : function < std : : shared_ptr < KeyboardHandlerBase > ( ) > > g_cfg_kb_handler ( cfg : : root . io , " Keyboard " ,
{
{ " Null " , PURE_EXPR ( std : : make_shared < NullKeyboardHandler > ( ) ) } ,
{ " Basic " , PURE_EXPR ( std : : make_shared < BasicKeyboardHandler > ( ) ) } ,
} ) ;
cfg : : map_entry < std : : function < std : : shared_ptr < MouseHandlerBase > ( ) > > g_cfg_mouse_handler ( cfg : : root . io , " Mouse " ,
{
{ " Null " , PURE_EXPR ( std : : make_shared < NullMouseHandler > ( ) ) } ,
{ " Basic " , PURE_EXPR ( std : : make_shared < BasicMouseHandler > ( ) ) } ,
} ) ;
cfg : : map_entry < std : : function < std : : shared_ptr < PadHandlerBase > ( ) > > g_cfg_pad_handler ( cfg : : root . io , " Pad " , " Keyboard " ,
{
{ " Null " , PURE_EXPR ( std : : make_shared < NullPadHandler > ( ) ) } ,
{ " Keyboard " , PURE_EXPR ( std : : make_shared < KeyboardPadHandler > ( ) ) } ,
# ifdef _MSC_VER
{ " XInput " , PURE_EXPR ( std : : make_shared < XInputPadHandler > ( ) ) } ,
# endif
} ) ;
cfg : : map_entry < std : : function < std : : shared_ptr < GSRender > ( ) > > g_cfg_gs_render ( cfg : : root . video , " Renderer " , " OpenGL " ,
{
{ " Null " , PURE_EXPR ( std : : make_shared < NullGSRender > ( ) ) } ,
{ " OpenGL " , PURE_EXPR ( std : : make_shared < GLGSRender > ( ) ) } ,
# ifdef _MSC_VER
2016-06-13 18:53:50 +02:00
{ " D3D12 " , PURE_EXPR ( std : : make_shared < D3D12GSRender > ( ) ) } ,
2016-04-14 00:59:00 +02:00
{ " Vulkan " , PURE_EXPR ( std : : make_shared < VKGSRender > ( ) ) } ,
# endif
} ) ;
cfg : : map_entry < std : : function < std : : shared_ptr < AudioThread > ( ) > > g_cfg_audio_render ( cfg : : root . audio , " Renderer " , " OpenAL " ,
{
{ " Null " , PURE_EXPR ( std : : make_shared < NullAudioThread > ( ) ) } ,
{ " OpenAL " , PURE_EXPR ( std : : make_shared < OpenALThread > ( ) ) } ,
2016-04-25 12:49:12 +02:00
# ifdef _WIN32
2016-04-14 00:59:00 +02:00
{ " XAudio2 " , PURE_EXPR ( std : : make_shared < XAudio2Thread > ( ) ) } ,
# endif
} ) ;
extern cfg : : bool_entry g_cfg_autostart ;
extern cfg : : bool_entry g_cfg_autoexit ;
2012-11-15 00:39:56 +01:00
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
2016-04-14 00:59:00 +02:00
callbacks . send_dbg_command = [ ] ( DbgCommand id , cpu_thread * t )
2014-08-24 19:42:19 +02:00
{
2016-04-14 00:59:00 +02:00
wxGetApp ( ) . SendDbgCommand ( id , t ) ;
2015-09-18 00:41:14 +02:00
} ;
2014-12-19 00:18:44 +01:00
2016-04-14 00:59:00 +02:00
callbacks . get_kb_handler = PURE_EXPR ( g_cfg_kb_handler . get ( ) ( ) ) ;
2014-12-19 00:18:44 +01:00
2016-04-14 00:59:00 +02:00
callbacks . get_mouse_handler = PURE_EXPR ( g_cfg_mouse_handler . get ( ) ( ) ) ;
callbacks . get_pad_handler = PURE_EXPR ( g_cfg_pad_handler . get ( ) ( ) ) ;
2014-12-19 00:18:44 +01:00
2016-04-27 00:27:24 +02:00
callbacks . get_gs_frame = [ ] ( frame_type type , int w , int h ) - > std : : unique_ptr < GSFrameBase >
2014-08-25 00:23:26 +02:00
{
2015-10-05 02:42:48 +02:00
switch ( type )
{
2016-04-27 00:27:24 +02:00
case frame_type : : OpenGL : return std : : make_unique < GLGSFrame > ( w , h ) ;
case frame_type : : DX12 : return std : : make_unique < GSFrame > ( " DirectX 12 " , w , h ) ;
case frame_type : : Null : return std : : make_unique < GSFrame > ( " Null " , w , h ) ;
case frame_type : : Vulkan : return std : : make_unique < GSFrame > ( " Vulkan " , w , h ) ;
2015-10-05 02:42:48 +02:00
}
2015-10-21 09:24:02 +02:00
2016-04-14 00:59:00 +02:00
throw EXCEPTION ( " Invalid Frame Type (0x%x) " , type) ;
2015-10-05 02:42:48 +02:00
} ;
2015-05-10 02:21:43 +02:00
2016-04-14 00:59:00 +02:00
callbacks . get_gs_render = PURE_EXPR ( g_cfg_gs_render . get ( ) ( ) ) ;
2015-12-02 17:12:48 +01:00
2016-04-14 00:59:00 +02:00
callbacks . get_audio = PURE_EXPR ( g_cfg_audio_render . get ( ) ( ) ) ;
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 ;
SetAppName ( _PRGNAME_ ) ;
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
g_cfg_autostart = true ;
g_cfg_autoexit = 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 ( ) ;
}
2016-04-14 00:59:00 +02:00
void Rpcs3App : : SendDbgCommand ( DbgCommand id , cpu_thread * thr )
2013-06-30 10:46:29 +02:00
{
wxCommandEvent event ( wxEVT_DBG_COMMAND , id ) ;
event . SetClientData ( thr ) ;
AddPendingEvent ( event ) ;
}
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
}