Assorted code cleanups to WinMain's message handling, and streamlined the language selection 'gui restart' procedure.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@577 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
Jake.Stine 2009-02-23 12:03:22 +00:00
parent 5870bb43e9
commit cf2919cc5a
9 changed files with 280 additions and 212 deletions

View File

@ -109,7 +109,7 @@ public:
}; };
LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM); LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM);
void CreateMainWindow(int nCmdShow); void CreateMainWindow();
void RunGui(); void RunGui();
BOOL Pcsx2Configure(HWND hWnd); BOOL Pcsx2Configure(HWND hWnd);

View File

@ -40,7 +40,8 @@
#include "implement.h" // pthreads-win32 defines for startup/shutdown #include "implement.h" // pthreads-win32 defines for startup/shutdown
unsigned int langsMax; unsigned int langsMax;
bool shouldQuitOnDestroy = true; static bool m_RestartGui = false; // used to signal a GUI restart after DestroyWindow()
static HBITMAP hbitmap_background = NULL;
struct _langs { struct _langs {
@ -202,7 +203,7 @@ static bool TestRunMode()
return false; return false;
} }
void WinRun( int nCmdShow ) void WinRun()
{ {
// Load the command line overrides for plugins. // Load the command line overrides for plugins.
// Back up the user's preferences in winConfig. // Back up the user's preferences in winConfig.
@ -248,8 +249,6 @@ void WinRun( int nCmdShow )
} }
#endif #endif
CreateMainWindow( nCmdShow );
if( Config.PsxOut ) if( Config.PsxOut )
{ {
// output the help commands // output the help commands
@ -362,7 +361,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
else else
Console::Close(); Console::Close();
WinRun( nCmdShow ); WinRun();
} }
catch( Exception::BaseException& ex ) catch( Exception::BaseException& ex )
{ {
@ -396,13 +395,22 @@ void RunGui()
PCSX2_MEM_PROTECT_BEGIN(); PCSX2_MEM_PROTECT_BEGIN();
LoadPatch(str_Default); LoadPatch( str_Default );
do
{
CreateMainWindow();
m_RestartGui = false;
while( true ) while( true )
{ {
if( PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) != 0 ) if( PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) != 0 )
{ {
if( msg.message == WM_QUIT ) return; if( msg.message == WM_QUIT )
{
gApp.hWnd = NULL;
break;
}
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessage(&msg); DispatchMessage(&msg);
@ -410,6 +418,7 @@ void RunGui()
Sleep(10); Sleep(10);
} }
} while( m_RestartGui );
PCSX2_MEM_PROTECT_END(); PCSX2_MEM_PROTECT_END();
} }
@ -560,8 +569,6 @@ BOOL APIENTRY GameFixes(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
return FALSE; return FALSE;
} }
HBITMAP hbitmap_background;//the background image
LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
switch (msg) switch (msg)
@ -597,28 +604,28 @@ LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
case ID_GAMEFIXES: case ID_GAMEFIXES:
DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_GAMEFIXES), hWnd, (DLGPROC)GameFixes); DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_GAMEFIXES), hWnd, (DLGPROC)GameFixes);
return FALSE; break;
case ID_HACKS: case ID_HACKS:
DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_HACKS), hWnd, (DLGPROC)HacksProc); DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_HACKS), hWnd, (DLGPROC)HacksProc);
return FALSE; break;
case ID_ADVANCED_OPTIONS: case ID_ADVANCED_OPTIONS:
DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_ADVANCED_OPTIONS), hWnd, (DLGPROC)AdvancedOptionsProc); DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_ADVANCED_OPTIONS), hWnd, (DLGPROC)AdvancedOptionsProc);
return FALSE; break;
case ID_CHEAT_FINDER_SHOW: case ID_CHEAT_FINDER_SHOW:
ShowFinder(pInstance,hWnd); ShowFinder(pInstance,hWnd);
return FALSE; break;
case ID_CHEAT_BROWSER_SHOW: case ID_CHEAT_BROWSER_SHOW:
ShowCheats(pInstance,hWnd); ShowCheats(pInstance,hWnd);
return FALSE; break;
case ID_FILE_EXIT: case ID_FILE_EXIT:
DestroyWindow( hWnd ); DestroyWindow( hWnd );
// WM_DESTROY will do the shutdown work for us. // WM_DESTROY will do the shutdown work for us.
return FALSE; break;
case ID_FILEOPEN: case ID_FILEOPEN:
{ {
@ -626,32 +633,32 @@ LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
if( Open_File_Proc( outstr ) ) if( Open_File_Proc( outstr ) )
RunExecute( outstr.c_str() ); RunExecute( outstr.c_str() );
} }
return FALSE; break;
case ID_RUN_EXECUTE: case ID_RUN_EXECUTE:
if( g_EmulationInProgress ) if( g_EmulationInProgress )
ExecuteCpu(); ExecuteCpu();
else else
RunExecute( NULL, true ); // boots bios if no savestate is to be recovered RunExecute( NULL, true ); // boots bios if no savestate is to be recovered
return FALSE; break;
case ID_FILE_RUNCD: case ID_FILE_RUNCD:
SysReset(); SysReset();
RunExecute( NULL ); RunExecute( NULL );
return FALSE; break;
case ID_RUN_RESET: case ID_RUN_RESET:
SysReset(); SysReset();
return FALSE; break;
//2002-09-20 (Florin) //2002-09-20 (Florin)
case ID_RUN_CMDLINE: case ID_RUN_CMDLINE:
DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_CMDLINE), hWnd, (DLGPROC)CmdlineProc); DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_CMDLINE), hWnd, (DLGPROC)CmdlineProc);
return FALSE; break;
//------------------- //-------------------
case ID_PATCHBROWSER: case ID_PATCHBROWSER:
DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_PATCHBROWSER), hWnd, (DLGPROC)PatchBDlgProc); DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_PATCHBROWSER), hWnd, (DLGPROC)PatchBDlgProc);
return FALSE; break;
case ID_CONFIG_CONFIGURE: case ID_CONFIG_CONFIGURE:
Pcsx2Configure(hWnd); Pcsx2Configure(hWnd);
@ -659,38 +666,38 @@ LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
// Configure may unload plugins if the user changes settings, so reload // Configure may unload plugins if the user changes settings, so reload
// them here. If they weren't unloaded these functions do nothing. // them here. If they weren't unloaded these functions do nothing.
LoadPlugins(); LoadPlugins();
return FALSE; break;
case ID_CONFIG_GRAPHICS: case ID_CONFIG_GRAPHICS:
if (GSconfigure) GSconfigure(); if (GSconfigure) GSconfigure();
return FALSE; break;
case ID_CONFIG_CONTROLLERS: case ID_CONFIG_CONTROLLERS:
if (PAD1configure) PAD1configure(); if (PAD1configure) PAD1configure();
if (PAD2configure) { if (PAD2configure) {
if (strcmp(Config.PAD1, Config.PAD2))PAD2configure(); if (strcmp(Config.PAD1, Config.PAD2))PAD2configure();
} }
return FALSE; break;
case ID_CONFIG_SOUND: case ID_CONFIG_SOUND:
if (SPU2configure) SPU2configure(); if (SPU2configure) SPU2configure();
return FALSE; break;
case ID_CONFIG_CDVDROM: case ID_CONFIG_CDVDROM:
if (CDVDconfigure) CDVDconfigure(); if (CDVDconfigure) CDVDconfigure();
return FALSE; break;
case ID_CONFIG_DEV9: case ID_CONFIG_DEV9:
if (DEV9configure) DEV9configure(); if (DEV9configure) DEV9configure();
return FALSE; break;
case ID_CONFIG_USB: case ID_CONFIG_USB:
if (USBconfigure) USBconfigure(); if (USBconfigure) USBconfigure();
return FALSE; break;
case ID_CONFIG_FW: case ID_CONFIG_FW:
if (FWconfigure) FWconfigure(); if (FWconfigure) FWconfigure();
return FALSE; break;
case ID_FILE_STATES_LOAD_SLOT1: case ID_FILE_STATES_LOAD_SLOT1:
case ID_FILE_STATES_LOAD_SLOT2: case ID_FILE_STATES_LOAD_SLOT2:
@ -698,11 +705,11 @@ LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
case ID_FILE_STATES_LOAD_SLOT4: case ID_FILE_STATES_LOAD_SLOT4:
case ID_FILE_STATES_LOAD_SLOT5: case ID_FILE_STATES_LOAD_SLOT5:
States_Load(LOWORD(wParam) - ID_FILE_STATES_LOAD_SLOT1); States_Load(LOWORD(wParam) - ID_FILE_STATES_LOAD_SLOT1);
return FALSE; break;
case ID_FILE_STATES_LOAD_OTHER: case ID_FILE_STATES_LOAD_OTHER:
OnStates_LoadOther(); OnStates_LoadOther();
return FALSE; break;
case ID_FILE_STATES_SAVE_SLOT1: case ID_FILE_STATES_SAVE_SLOT1:
case ID_FILE_STATES_SAVE_SLOT2: case ID_FILE_STATES_SAVE_SLOT2:
@ -710,20 +717,20 @@ LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
case ID_FILE_STATES_SAVE_SLOT4: case ID_FILE_STATES_SAVE_SLOT4:
case ID_FILE_STATES_SAVE_SLOT5: case ID_FILE_STATES_SAVE_SLOT5:
States_Save(LOWORD(wParam) - ID_FILE_STATES_SAVE_SLOT1); States_Save(LOWORD(wParam) - ID_FILE_STATES_SAVE_SLOT1);
return FALSE; break;
case ID_FILE_STATES_SAVE_OTHER: case ID_FILE_STATES_SAVE_OTHER:
OnStates_SaveOther(); OnStates_SaveOther();
return FALSE; break;
case ID_CONFIG_CPU: case ID_CONFIG_CPU:
DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_CPUDLG), hWnd, (DLGPROC)CpuDlgProc); DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_CPUDLG), hWnd, (DLGPROC)CpuDlgProc);
return FALSE; break;
#ifdef PCSX2_DEVBUILD #ifdef PCSX2_DEVBUILD
case ID_DEBUG_ENTERDEBUGGER: case ID_DEBUG_ENTERDEBUGGER:
DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_DEBUG), NULL, (DLGPROC)DebuggerProc); DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_DEBUG), NULL, (DLGPROC)DebuggerProc);
return FALSE; break;
case ID_DEBUG_REMOTEDEBUGGING: case ID_DEBUG_REMOTEDEBUGGING:
//read debugging params //read debugging params
@ -744,29 +751,29 @@ LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
//RunGui(); //RunGui();
} }
} }
return FALSE; break;
case ID_DEBUG_MEMORY_DUMP: case ID_DEBUG_MEMORY_DUMP:
DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_MEMORY), hWnd, (DLGPROC)MemoryProc); DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_MEMORY), hWnd, (DLGPROC)MemoryProc);
return FALSE; break;
case ID_DEBUG_LOGGING: case ID_DEBUG_LOGGING:
DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_LOGGING), hWnd, (DLGPROC)LogProc); DialogBox(gApp.hInstance, MAKEINTRESOURCE(IDD_LOGGING), hWnd, (DLGPROC)LogProc);
return FALSE; break;
#endif #endif
case ID_HELP_ABOUT: case ID_HELP_ABOUT:
DialogBox(gApp.hInstance, MAKEINTRESOURCE(ABOUT_DIALOG), hWnd, (DLGPROC)AboutDlgProc); DialogBox(gApp.hInstance, MAKEINTRESOURCE(ABOUT_DIALOG), hWnd, (DLGPROC)AboutDlgProc);
return FALSE; break;
case ID_HELP_HELP: case ID_HELP_HELP:
//system("help\\index.html"); //system("help\\index.html");
system("compat_list\\compat_list.html"); system("compat_list\\compat_list.html");
return FALSE; break;
case ID_CONFIG_MEMCARDS: case ID_CONFIG_MEMCARDS:
MemcardConfig::OpenDialog(); MemcardConfig::OpenDialog();
return FALSE; break;
case ID_PROCESSLOW: case ID_PROCESSLOW:
Config.ThPriority = THREAD_PRIORITY_LOWEST; Config.ThPriority = THREAD_PRIORITY_LOWEST;
@ -774,7 +781,7 @@ LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
CheckMenuItem(gApp.hMenu,ID_PROCESSLOW,MF_CHECKED); CheckMenuItem(gApp.hMenu,ID_PROCESSLOW,MF_CHECKED);
CheckMenuItem(gApp.hMenu,ID_PROCESSNORMAL,MF_UNCHECKED); CheckMenuItem(gApp.hMenu,ID_PROCESSNORMAL,MF_UNCHECKED);
CheckMenuItem(gApp.hMenu,ID_PROCESSHIGH,MF_UNCHECKED); CheckMenuItem(gApp.hMenu,ID_PROCESSHIGH,MF_UNCHECKED);
return FALSE; break;
case ID_PROCESSNORMAL: case ID_PROCESSNORMAL:
Config.ThPriority = THREAD_PRIORITY_NORMAL; Config.ThPriority = THREAD_PRIORITY_NORMAL;
@ -782,7 +789,7 @@ LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
CheckMenuItem(gApp.hMenu,ID_PROCESSNORMAL,MF_CHECKED); CheckMenuItem(gApp.hMenu,ID_PROCESSNORMAL,MF_CHECKED);
CheckMenuItem(gApp.hMenu,ID_PROCESSLOW,MF_UNCHECKED); CheckMenuItem(gApp.hMenu,ID_PROCESSLOW,MF_UNCHECKED);
CheckMenuItem(gApp.hMenu,ID_PROCESSHIGH,MF_UNCHECKED); CheckMenuItem(gApp.hMenu,ID_PROCESSHIGH,MF_UNCHECKED);
return FALSE; break;
case ID_PROCESSHIGH: case ID_PROCESSHIGH:
Config.ThPriority = THREAD_PRIORITY_HIGHEST; Config.ThPriority = THREAD_PRIORITY_HIGHEST;
@ -790,7 +797,7 @@ LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
CheckMenuItem(gApp.hMenu,ID_PROCESSHIGH,MF_CHECKED); CheckMenuItem(gApp.hMenu,ID_PROCESSHIGH,MF_CHECKED);
CheckMenuItem(gApp.hMenu,ID_PROCESSNORMAL,MF_UNCHECKED); CheckMenuItem(gApp.hMenu,ID_PROCESSNORMAL,MF_UNCHECKED);
CheckMenuItem(gApp.hMenu,ID_PROCESSLOW,MF_UNCHECKED); CheckMenuItem(gApp.hMenu,ID_PROCESSLOW,MF_UNCHECKED);
return FALSE; break;
case ID_CONSOLE: case ID_CONSOLE:
Config.PsxOut = !Config.PsxOut; Config.PsxOut = !Config.PsxOut;
@ -805,25 +812,25 @@ LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Console::Close(); Console::Close();
} }
SaveConfig(); SaveConfig();
return FALSE; break;
case ID_PATCHES: case ID_PATCHES:
Config.Patch = !Config.Patch; Config.Patch = !Config.Patch;
CheckMenuItem(gApp.hMenu, ID_PATCHES, Config.Patch ? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(gApp.hMenu, ID_PATCHES, Config.Patch ? MF_CHECKED : MF_UNCHECKED);
SaveConfig(); SaveConfig();
return FALSE; break;
case ID_CDVDPRINT: case ID_CDVDPRINT:
Config.cdvdPrint = !Config.cdvdPrint; Config.cdvdPrint = !Config.cdvdPrint;
CheckMenuItem(gApp.hMenu, ID_CDVDPRINT, Config.cdvdPrint ? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(gApp.hMenu, ID_CDVDPRINT, Config.cdvdPrint ? MF_CHECKED : MF_UNCHECKED);
SaveConfig(); SaveConfig();
return FALSE; break;
case ID_CLOSEGS: case ID_CLOSEGS:
Config.closeGSonEsc = !Config.closeGSonEsc; Config.closeGSonEsc = !Config.closeGSonEsc;
CheckMenuItem(gApp.hMenu, ID_CLOSEGS, Config.closeGSonEsc ? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(gApp.hMenu, ID_CLOSEGS, Config.closeGSonEsc ? MF_CHECKED : MF_UNCHECKED);
SaveConfig(); SaveConfig();
return FALSE; break;
#ifndef _DEBUG #ifndef _DEBUG
case ID_PROFILER: case ID_PROFILER:
@ -839,28 +846,34 @@ LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
ProfilerTerm(); ProfilerTerm();
} }
SaveConfig(); SaveConfig();
return FALSE; break;
#endif #endif
default: default:
if (LOWORD(wParam) >= ID_LANGS && LOWORD(wParam) <= (ID_LANGS + langsMax)) { if (LOWORD(wParam) >= ID_LANGS && LOWORD(wParam) <= (ID_LANGS + langsMax))
shouldQuitOnDestroy = false; {
m_RestartGui = true;
DestroyWindow(gApp.hWnd); DestroyWindow(gApp.hWnd);
ChangeLanguage(langs[LOWORD(wParam) - ID_LANGS].lang); ChangeLanguage(langs[LOWORD(wParam) - ID_LANGS].lang);
CreateMainWindow(SW_SHOWNORMAL); break;
return TRUE;
}
} }
return TRUE; return TRUE;
}
return FALSE;
case WM_DESTROY: case WM_DESTROY:
if( shouldQuitOnDestroy ) { if( hbitmap_background != NULL )
DeleteObject(hbitmap_background); {
PostQuitMessage(0); DeleteObject( hbitmap_background );
gApp.hWnd = NULL; hbitmap_background = NULL;
} }
else shouldQuitOnDestroy = true; gApp.hWnd = NULL;
return FALSE; break;
case WM_NCDESTROY:
PostQuitMessage(0);
break;
// Explicit handling of WM_CLOSE. // Explicit handling of WM_CLOSE.
// This is Windows default behavior, but we handle it here sot hat we might add a // This is Windows default behavior, but we handle it here sot hat we might add a
@ -1041,7 +1054,8 @@ void CreateMainMenu() {
EnableMenuItem(GetSubMenu(gApp.hMenu, 4), ID_DEBUG_LOGGING, MF_GRAYED); EnableMenuItem(GetSubMenu(gApp.hMenu, 4), ID_DEBUG_LOGGING, MF_GRAYED);
} }
void CreateMainWindow(int nCmdShow) { void CreateMainWindow()
{
WNDCLASS wc; WNDCLASS wc;
HWND hWnd; HWND hWnd;
char buf[256]; char buf[256];
@ -1058,6 +1072,7 @@ void CreateMainWindow(int nCmdShow) {
sprintf(COMPILER, "(BC)"); sprintf(COMPILER, "(BC)");
#endif #endif
/* Load Background Bitmap from the ressource */ /* Load Background Bitmap from the ressource */
if( hbitmap_background == NULL )
hbitmap_background = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(SPLASH_LOGO)); hbitmap_background = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(SPLASH_LOGO));
wc.lpszClassName = "PCSX2 Main"; wc.lpszClassName = "PCSX2 Main";
@ -1114,7 +1129,7 @@ void CreateMainWindow(int nCmdShow) {
StatusBar_SetMsg("F1 - save, F2 - next state, Shift+F2 - prev state, F3 - load, F8 - snapshot"); StatusBar_SetMsg("F1 - save, F2 - next state, Shift+F2 - prev state, F3 - load, F8 - snapshot");
ShowWindow(hWnd, nCmdShow); ShowWindow(hWnd, true);
SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
} }

View File

@ -37,7 +37,7 @@ namespace Exception
const ResultType PartialResult; const ResultType PartialResult;
virtual ~UTFConversion() throw() {} virtual ~UTFConversion() throw() {}
UTFConversion( const ResultType& result, std::string msg ) : UTFConversion( const ResultType& result, const std::string& msg ) :
runtime_error( msg ), runtime_error( msg ),
PartialResult( result ) {} PartialResult( result ) {}
}; };

View File

@ -1,20 +1,23 @@
//GiGaHeRz's SPU2 Driver /* SPU2-X, A plugin for Emulating the Sound Processing Unit of the Playstation 2
//Copyright (c) 2003-2008, David Quintana <gigaherz@gmail.com> * Developed and maintained by the Pcsx2 Development Team.
// *
//This library is free software; you can redistribute it and/or * Original portions from SPU2ghz are (c) 2008 by David Quintana [gigaherz]
//modify it under the terms of the GNU Lesser General Public *
//License as published by the Free Software Foundation; either * This library is free software; you can redistribute it and/or modify it under
//version 2.1 of the License, or (at your option) any later version. * the terms of the GNU Lesser General Public License as published by the Free
// * Software Foundation; either version 2.1 of the the License, or (at your
//This library is distributed in the hope that it will be useful, * option) any later version.
//but WITHOUT ANY WARRANTY; without even the implied warranty of *
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * This library is distributed in the hope that it will be useful, but WITHOUT
//Lesser General Public License for more details. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
//You should have received a copy of the GNU Lesser General Public * for more details.
//License along with this library; if not, write to the Free Software *
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * You should have received a copy of the GNU Lesser General Public License along
// * with this library; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "Spu2.h" #include "Spu2.h"
@ -26,14 +29,13 @@ FILE *spu2Log;
void FileLog(const char *fmt, ...) { void FileLog(const char *fmt, ...) {
#ifdef SPU2_LOG #ifdef SPU2_LOG
int n;
va_list list; va_list list;
if(!AccessLog()) return; if(!AccessLog()) return;
if(!spu2Log) return; if(!spu2Log) return;
va_start(list, fmt); va_start(list, fmt);
n=vsprintf(s,fmt, list); vsprintf(s,fmt, list);
va_end(list); va_end(list);
fputs(s,spu2Log); fputs(s,spu2Log);
@ -51,13 +53,12 @@ void FileLog(const char *fmt, ...) {
void ConLog(const char *fmt, ...) { void ConLog(const char *fmt, ...) {
#ifdef SPU2_LOG #ifdef SPU2_LOG
int n;
va_list list; va_list list;
if(!MsgToConsole()) return; if(!MsgToConsole()) return;
va_start(list, fmt); va_start(list, fmt);
n=vsprintf(s,fmt, list); vsprintf(s,fmt, list);
va_end(list); va_end(list);
fputs(s,stderr); fputs(s,stderr);

View File

@ -1,20 +1,23 @@
//GiGaHeRz's SPU2 Driver /* SPU2-X, A plugin for Emulating the Sound Processing Unit of the Playstation 2
//Copyright (c) 2003-2008, David Quintana <gigaherz@gmail.com> * Developed and maintained by the Pcsx2 Development Team.
// *
//This library is free software; you can redistribute it and/or * Original portions from SPU2ghz are (c) 2008 by David Quintana [gigaherz]
//modify it under the terms of the GNU Lesser General Public *
//License as published by the Free Software Foundation; either * This library is free software; you can redistribute it and/or modify it under
//version 2.1 of the License, or (at your option) any later version. * the terms of the GNU Lesser General Public License as published by the Free
// * Software Foundation; either version 2.1 of the the License, or (at your
//This library is distributed in the hope that it will be useful, * option) any later version.
//but WITHOUT ANY WARRANTY; without even the implied warranty of *
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * This library is distributed in the hope that it will be useful, but WITHOUT
//Lesser General Public License for more details. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
//You should have received a copy of the GNU Lesser General Public * for more details.
//License along with this library; if not, write to the Free Software *
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * You should have received a copy of the GNU Lesser General Public License along
// * with this library; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "Spu2.h" #include "Spu2.h"
#include "RegTable.h" #include "RegTable.h"

View File

@ -1,20 +1,23 @@
//GiGaHeRz's SPU2 Driver /* SPU2-X, A plugin for Emulating the Sound Processing Unit of the Playstation 2
//Copyright (c) 2003-2008, David Quintana <gigaherz@gmail.com> * Developed and maintained by the Pcsx2 Development Team.
// *
//This library is free software; you can redistribute it and/or * Original portions from SPU2ghz are (c) 2008 by David Quintana [gigaherz]
//modify it under the terms of the GNU Lesser General Public *
//License as published by the Free Software Foundation; either * This library is free software; you can redistribute it and/or modify it under
//version 2.1 of the License, or (at your option) any later version. * the terms of the GNU Lesser General Public License as published by the Free
// * Software Foundation; either version 2.1 of the the License, or (at your
//This library is distributed in the hope that it will be useful, * option) any later version.
//but WITHOUT ANY WARRANTY; without even the implied warranty of *
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * This library is distributed in the hope that it will be useful, but WITHOUT
//Lesser General Public License for more details. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
//You should have received a copy of the GNU Lesser General Public * for more details.
//License along with this library; if not, write to the Free Software *
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * You should have received a copy of the GNU Lesser General Public License along
// * with this library; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <stdexcept> #include <stdexcept>
#include <new> #include <new>

View File

@ -1,23 +1,23 @@
/* SPU2-X, A plugin for Emulating the Sound Processing Unit of the Playstation 2 /* SPU2-X, A plugin for Emulating the Sound Processing Unit of the Playstation 2
* Developed and maintained by the Pcsx2 Development Team. * Developed and maintained by the Pcsx2 Development Team.
* *
* Original portions from SPU2ghz are (c) 2008 by David Quintana [gigaherz] * Original portions from SPU2ghz are (c) 2008 by David Quintana [gigaherz]
* *
* This library is free software; you can redistribute it and/or modify it under * This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free * the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the the License, or (at your * Software Foundation; either version 2.1 of the the License, or (at your
* option) any later version. * option) any later version.
* *
* This library is distributed in the hope that it will be useful, but WITHOUT * This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License along * You should have received a copy of the GNU Lesser General Public License along
* with this library; if not, write to the Free Software Foundation, Inc., 59 * with this library; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA * Temple Place, Suite 330, Boston, MA 02111-1307 USA
* *
*/ */
#include "SPU2.h" #include "SPU2.h"

View File

@ -27,6 +27,46 @@
#include <xaudio2.h> #include <xaudio2.h>
namespace Exception
{
class XAudio2Error : public std::runtime_error
{
protected:
static const char* SomeKindaErrorString( HRESULT hr )
{
switch( hr )
{
case XAUDIO2_E_INVALID_CALL:
return "Invalid call for the XA2 object state.";
case XAUDIO2_E_DEVICE_INVALIDATED:
return "Device is unavailable, unplugged, unsupported, or has been consumed by The Nothing.";
}
return "Unknown error code!";
}
public:
const HRESULT ErrorCode;
string m_Message;
const char* CMessage() const
{
return m_Message.c_str();
}
virtual ~XAudio2Error() throw() {}
XAudio2Error( const HRESULT result, const std::string& msg ) :
runtime_error( msg ),
ErrorCode( result ),
m_Message()
{
char omg[1024];
sprintf_s( omg, "%s (code 0x%x)\n\n%s", what(), ErrorCode, SomeKindaErrorString( ErrorCode ) );
m_Message = omg;
}
};
}
static const double SndOutNormalizer = (double)(1UL<<(SndOutVolumeShift+16)); static const double SndOutNormalizer = (double)(1UL<<(SndOutVolumeShift+16));
class XAudio2Mod: public SndOutModule class XAudio2Mod: public SndOutModule
@ -95,9 +135,7 @@ private:
if( FAILED(hr = pXAudio2->CreateSourceVoice( &pSourceVoice, &wfx, if( FAILED(hr = pXAudio2->CreateSourceVoice( &pSourceVoice, &wfx,
XAUDIO2_VOICE_NOSRC, 1.0f, this ) ) ) XAUDIO2_VOICE_NOSRC, 1.0f, this ) ) )
{ {
SysMessage( "Error %#X creating source voice\n", hr ); throw Exception::XAudio2Error( hr, "XAudio2 CreateSourceVoice failure." );
SAFE_RELEASE( pXAudio2 );
return;
} }
InitializeCriticalSection( &cs ); InitializeCriticalSection( &cs );
@ -192,6 +230,8 @@ public:
{ {
HRESULT hr; HRESULT hr;
jASSUME( pXAudio2 == NULL );
// //
// Initialize XAudio2 // Initialize XAudio2
// //
@ -201,12 +241,14 @@ public:
if( IsDebugBuild ) if( IsDebugBuild )
flags |= XAUDIO2_DEBUG_ENGINE; flags |= XAUDIO2_DEBUG_ENGINE;
if ( FAILED(hr = XAudio2Create( &pXAudio2, flags ) ) ) try
{ {
SysMessage( "Failed to init XAudio2 engine: %#X\n", hr ); if ( FAILED(hr = XAudio2Create( &pXAudio2, flags ) ) )
CoUninitialize(); throw Exception::XAudio2Error( hr,
return -1; "Failed to init XAudio2 engine. XA2 may not be available on your system.\n"
} "Ensure that you have the latest DirectX runtimes installed, or use \n"
"DirectX / WaveOut drivers instead. Error Details:"
);
XAUDIO2_DEVICE_DETAILS deviceDetails; XAUDIO2_DEVICE_DETAILS deviceDetails;
pXAudio2->GetDeviceDetails( 0, &deviceDetails ); pXAudio2->GetDeviceDetails( 0, &deviceDetails );
@ -217,7 +259,6 @@ public:
if ( FAILED(hr = pXAudio2->CreateMasteringVoice( &pMasteringVoice, 0, SampleRate ) ) ) if ( FAILED(hr = pXAudio2->CreateMasteringVoice( &pMasteringVoice, 0, SampleRate ) ) )
{ {
SysMessage( "Failed creating mastering voice: %#X\n", hr ); SysMessage( "Failed creating mastering voice: %#X\n", hr );
SAFE_RELEASE( pXAudio2 );
CoUninitialize(); CoUninitialize();
return -1; return -1;
} }
@ -263,6 +304,15 @@ public:
} }
voiceContext->Init( pXAudio2 ); voiceContext->Init( pXAudio2 );
}
catch( Exception::XAudio2Error& ex )
{
SysMessage( ex.CMessage() );
SAFE_RELEASE( pXAudio2 );
CoUninitialize();
return -1;
}
return 0; return 0;
} }

View File

@ -495,10 +495,6 @@
/> />
</FileConfiguration> </FileConfiguration>
</File> </File>
<File
RelativePath="debug.h"
>
</File>
<File <File
RelativePath=".\RealtimeDebugger.cpp" RelativePath=".\RealtimeDebugger.cpp"
> >