PCSX2 Documentation/The PCSX2 Program Flow: Difference between revisions

From PCSX2 Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 20: Line 20:




<code>in [https://github.com/PCSX2/pcsx2/blob/master/pcsx2/gui/AppInit.cpp AppInit.cpp]</code>
'''in [https://github.com/PCSX2/pcsx2/blob/master/pcsx2/gui/AppInit.cpp AppInit.cpp]'''
<source lang="cpp">
<source lang="cpp">
bool Pcsx2App::OnInit()
bool Pcsx2App::OnInit()
Line 61: Line 61:
In addition to Application classes, there are also Frame classes. So when we call the OpenMainFrame function, what happens? Take a look at this code:
In addition to Application classes, there are also Frame classes. So when we call the OpenMainFrame function, what happens? Take a look at this code:


<code>in [https://github.com/PCSX2/pcsx2/blob/master/pcsx2/gui/AppInit.cpp pcsx2/gui/AppInit.cpp]</code>
'''in [https://github.com/PCSX2/pcsx2/blob/master/pcsx2/gui/AppInit.cpp pcsx2/gui/AppInit.cpp]'''
<source lang="cpp">
<source lang="cpp">
void Pcsx2App::OpenMainFrame()
void Pcsx2App::OpenMainFrame()
Line 77: Line 77:
Here we're creating an instance of the MainEmuFrame class. That class contains members for all the cool GUI elements, buttons, menus, stuff like that. So let's take a step further. Suppose we want to boot up a game. When we select Boot DVD in the pcsx2 menus, we are calling upon this function here:
Here we're creating an instance of the MainEmuFrame class. That class contains members for all the cool GUI elements, buttons, menus, stuff like that. So let's take a step further. Suppose we want to boot up a game. When we select Boot DVD in the pcsx2 menus, we are calling upon this function here:


<code>in [https://github.com/PCSX2/pcsx2/blob/f3bb434b27737849546290bbfc8d09c61103081c/pcsx2/gui/MainMenuClicks.cpp MainMenuClicks.cpp]</code>
'''in [https://github.com/PCSX2/pcsx2/blob/f3bb434b27737849546290bbfc8d09c61103081c/pcsx2/gui/MainMenuClicks.cpp MainMenuClicks.cpp]'''
<source lang="cpp">
<source lang="cpp">
void MainEmuFrame::_DoBootCdvd()
void MainEmuFrame::_DoBootCdvd()

Latest revision as of 20:22, 19 July 2015

The following article is a very general overview of the flow of the PCSX2 application. It's a bit sloppy right now, I will clean it up more as I go along.

AppMain.cpp - It all starts here

There is a lot that happens under the hood with wxWidgets. We don't need to worry about that. All we need to worry about is this this line of code:

in AppMain.cpp <source lang="cpp">IMPLEMENT_APP(Pcsx2App)</source>

This macro tells the wxWidgets framework that we want to fire up Pcsx2App. Easy, right?

Pcsx2App - the part we care about

Next, Let's take a look at this code here.


in App.h <source lang=cpp> class Pcsx2App : public wxAppWithHelpers{} </source> You can see here that the Pcsx2App class is an extension of the wxAppWithHelpers class. WxWidgets applications are defined as classes, which are instantiated into an object when we start the program. Pcsx2App contains methods that wxWidgets is going to call upon at various times. So what gets called when we fire up Pcsx2App? That would be OnInit(). Let's take a look, I have written some notes on what happens here:


in AppInit.cpp <source lang="cpp"> bool Pcsx2App::OnInit() { EnableAllLogging(); Console.WriteLn("Interface is initializing. Entering Pcsx2App::OnInit!"); </source> Here we enable logging to the pcsx2 frame, and write some messages in it.


<source lang="cpp"> InitCPUTicks(); </source> Misc. windows performance benchmarking, defined here.


<source lang="cpp"> pxDoAssert = AppDoAssert; pxDoOutOfMemory = SysOutOfMemory_EmergencyResponse; </source> These are function pointers for the pxThread, which is the main threading class for the PCSX2 virtual machine. Basically here we are telling pxThread how to handle certain function calls. For example, if pxDoAssert is called, then we will actually call AppDoAssert, which defined here. Similarly, pxDoOutOfMemory will actually call SysOutOfMemory_EmergencyResponse, defined here.


<source lang="cpp"> wxInitAllImageHandlers();

Console.WriteLn("Applying operating system default language..."); i18n_SetLanguage( wxLANGUAGE_DEFAULT );

Console.WriteLn("Command line parsing..."); if( !_parent::OnInit() ) return false; Console.WriteLn("Command line parsed!");

i18n_SetLanguagePath(); </source> This is really straightforward. We're just doing some more initialization for the gui. We're creating an instance of AppConfig, which contains all kinds of options for wxWidgets. The declarations are here. We're also setting the PCSX2 language to whatever the operating system language is.

WxWidgets Frames

In addition to Application classes, there are also Frame classes. So when we call the OpenMainFrame function, what happens? Take a look at this code:

in pcsx2/gui/AppInit.cpp <source lang="cpp"> void Pcsx2App::OpenMainFrame() { if( AppRpc_TryInvokeAsync( &Pcsx2App::OpenMainFrame ) ) return;

if( GetMainFramePtr() != NULL ) return;

MainEmuFrame* mainFrame = new MainEmuFrame( NULL, pxGetAppName() );

... } </source>

Here we're creating an instance of the MainEmuFrame class. That class contains members for all the cool GUI elements, buttons, menus, stuff like that. So let's take a step further. Suppose we want to boot up a game. When we select Boot DVD in the pcsx2 menus, we are calling upon this function here:

in MainMenuClicks.cpp <source lang="cpp"> void MainEmuFrame::_DoBootCdvd() </source>

Into The Core

OK, this is where things start to get a little complicated. PCSX2 is basically divided up into a few different parts:

SysExecutorThread

Handles the PCSX2 "Core" (Virtual Machine, GUI, etc). Instance of ExecutorThread, which is a "proxy". It basically queues up jobs and then distributes them to a worker thread.

SysMtgsThread

Handles the Graphics Synthesizer (GSdx or other plugins).