2015-11-14 20:56:40 +00:00
|
|
|
#include "stdafx.h"
|
2016-01-14 06:29:38 +00:00
|
|
|
|
2015-12-08 19:59:50 +00:00
|
|
|
#include <Common/path.h>
|
2015-12-19 23:52:35 +00:00
|
|
|
#include <Common/Trace.h>
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Common/Util.h>
|
2016-01-13 15:14:20 +00:00
|
|
|
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
|
|
|
|
#include <Project64-core/N64System/SystemGlobals.h>
|
|
|
|
#include <Project64-core/Plugins/PluginClass.h>
|
|
|
|
#include <Project64-core/N64System/N64RomClass.h>
|
2016-01-13 07:23:22 +00:00
|
|
|
#include "Settings/SettingType/SettingsType-Application.h"
|
2015-11-14 20:56:40 +00:00
|
|
|
|
2016-01-13 07:23:22 +00:00
|
|
|
static void FixDirectories(void);
|
2015-11-14 20:56:40 +00:00
|
|
|
|
2016-01-13 07:23:22 +00:00
|
|
|
#ifdef _WIN32
|
2015-11-14 20:56:40 +00:00
|
|
|
static void IncreaseThreadPriority(void);
|
2016-01-13 07:23:22 +00:00
|
|
|
#endif
|
|
|
|
|
2015-11-14 20:56:40 +00:00
|
|
|
static CTraceFileLog * g_LogFile = NULL;
|
|
|
|
|
|
|
|
void LogFlushChanged(CTraceFileLog * LogFile)
|
|
|
|
{
|
|
|
|
LogFile->SetFlushFile(g_Settings->LoadDword(Debugger_AppLogFlush) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitializeLog(void)
|
2015-12-14 10:51:33 +00:00
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
|
|
|
TraceSetMaxModule(MaxTraceModuleProject64, TraceInfo);
|
|
|
|
#else
|
|
|
|
TraceSetMaxModule(MaxTraceModuleProject64, TraceError);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddLogModule(void)
|
2015-11-14 20:56:40 +00:00
|
|
|
{
|
|
|
|
CPath LogFilePath(CPath::MODULE_DIRECTORY);
|
|
|
|
LogFilePath.AppendDirectory("Logs");
|
|
|
|
if (!LogFilePath.DirectoryExists())
|
|
|
|
{
|
|
|
|
LogFilePath.DirectoryCreate();
|
|
|
|
}
|
|
|
|
LogFilePath.SetNameExtension("Project64.log");
|
|
|
|
|
|
|
|
g_LogFile = new CTraceFileLog(LogFilePath, g_Settings->LoadDword(Debugger_AppLogFlush) != 0, Log_New, 500);
|
2015-12-14 10:51:33 +00:00
|
|
|
TraceAddModule(g_LogFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetTraceModuleNames(void)
|
|
|
|
{
|
|
|
|
TraceSetModuleName(TraceMD5, "MD5");
|
|
|
|
TraceSetModuleName(TraceSettings, "Settings");
|
|
|
|
TraceSetModuleName(TraceUnknown, "Unknown");
|
|
|
|
TraceSetModuleName(TraceAppInit, "App Init");
|
|
|
|
TraceSetModuleName(TraceAppCleanup, "App Cleanup");
|
|
|
|
TraceSetModuleName(TraceN64System, "N64 System");
|
|
|
|
TraceSetModuleName(TracePlugins, "Plugins");
|
|
|
|
TraceSetModuleName(TraceGFXPlugin, "GFX Plugin");
|
|
|
|
TraceSetModuleName(TraceAudioPlugin, "Audio Plugin");
|
|
|
|
TraceSetModuleName(TraceControllerPlugin, "Controller Plugin");
|
|
|
|
TraceSetModuleName(TraceRSPPlugin, "RSP Plugin");
|
|
|
|
TraceSetModuleName(TraceRSP, "RSP");
|
|
|
|
TraceSetModuleName(TraceAudio, "Audio");
|
|
|
|
TraceSetModuleName(TraceRegisterCache, "Register Cache");
|
|
|
|
TraceSetModuleName(TraceRecompiler, "Recompiler");
|
|
|
|
TraceSetModuleName(TraceTLB, "TLB");
|
|
|
|
TraceSetModuleName(TraceProtectedMem, "Protected Memory");
|
|
|
|
TraceSetModuleName(TraceUserInterface, "User Interface");
|
|
|
|
}
|
2015-11-14 20:56:40 +00:00
|
|
|
|
2015-12-14 10:51:33 +00:00
|
|
|
void UpdateTraceLevel(void * /*NotUsed*/)
|
|
|
|
{
|
|
|
|
g_ModuleLogLevel[TraceMD5] = (uint8_t)g_Settings->LoadDword(Debugger_TraceMD5);
|
|
|
|
g_ModuleLogLevel[TraceSettings] = (uint8_t)g_Settings->LoadDword(Debugger_TraceSettings);
|
|
|
|
g_ModuleLogLevel[TraceUnknown] = (uint8_t)g_Settings->LoadDword(Debugger_TraceUnknown);
|
|
|
|
g_ModuleLogLevel[TraceAppInit] = (uint8_t)g_Settings->LoadDword(Debugger_TraceAppInit);
|
|
|
|
g_ModuleLogLevel[TraceAppCleanup] = (uint8_t)g_Settings->LoadDword(Debugger_TraceAppCleanup);
|
|
|
|
g_ModuleLogLevel[TraceN64System] = (uint8_t)g_Settings->LoadDword(Debugger_TraceN64System);
|
|
|
|
g_ModuleLogLevel[TracePlugins] = (uint8_t)g_Settings->LoadDword(Debugger_TracePlugins);
|
|
|
|
g_ModuleLogLevel[TraceGFXPlugin] = (uint8_t)g_Settings->LoadDword(Debugger_TraceGFXPlugin);
|
|
|
|
g_ModuleLogLevel[TraceAudioPlugin] = (uint8_t)g_Settings->LoadDword(Debugger_TraceAudioPlugin);
|
|
|
|
g_ModuleLogLevel[TraceControllerPlugin] = (uint8_t)g_Settings->LoadDword(Debugger_TraceControllerPlugin);
|
|
|
|
g_ModuleLogLevel[TraceRSPPlugin] = (uint8_t)g_Settings->LoadDword(Debugger_TraceRSPPlugin);
|
|
|
|
g_ModuleLogLevel[TraceRSP] = (uint8_t)g_Settings->LoadDword(Debugger_TraceRSP);
|
|
|
|
g_ModuleLogLevel[TraceAudio] = (uint8_t)g_Settings->LoadDword(Debugger_TraceAudio);
|
|
|
|
g_ModuleLogLevel[TraceRegisterCache] = (uint8_t)g_Settings->LoadDword(Debugger_TraceRegisterCache);
|
|
|
|
g_ModuleLogLevel[TraceRecompiler] = (uint8_t)g_Settings->LoadDword(Debugger_TraceRecompiler);
|
|
|
|
g_ModuleLogLevel[TraceTLB] = (uint8_t)g_Settings->LoadDword(Debugger_TraceTLB);
|
|
|
|
g_ModuleLogLevel[TraceProtectedMem] = (uint8_t)g_Settings->LoadDword(Debugger_TraceProtectedMEM);
|
|
|
|
g_ModuleLogLevel[TraceUserInterface] = (uint8_t)g_Settings->LoadDword(Debugger_TraceUserInterface);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupTrace(void)
|
|
|
|
{
|
|
|
|
SetTraceModuleNames();
|
|
|
|
AddLogModule();
|
|
|
|
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceMD5, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceSettings, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceUnknown, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceAppInit, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceAppCleanup, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceN64System, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TracePlugins, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceGFXPlugin, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceAudioPlugin, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceControllerPlugin, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceRSPPlugin, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceRSP, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceAudio, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceRegisterCache, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceRecompiler, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceTLB, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceProtectedMEM, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->RegisterChangeCB(Debugger_TraceUserInterface, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
2015-11-14 20:56:40 +00:00
|
|
|
g_Settings->RegisterChangeCB(Debugger_AppLogFlush, g_LogFile, (CSettings::SettingChangedFunc)LogFlushChanged);
|
2015-12-14 10:51:33 +00:00
|
|
|
UpdateTraceLevel(NULL);
|
|
|
|
|
|
|
|
WriteTrace(TraceAppInit, TraceInfo, "Application Starting %s", VER_FILE_VERSION_STR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CleanupTrace(void)
|
|
|
|
{
|
|
|
|
WriteTrace(TraceAppCleanup, TraceDebug, "Done");
|
|
|
|
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceMD5, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceSettings, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceUnknown, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceAppInit, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceAppCleanup, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceN64System, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TracePlugins, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceGFXPlugin, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceAudioPlugin, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceControllerPlugin, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceRSPPlugin, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceRSP, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceAudio, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceRegisterCache, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceRecompiler, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceTLB, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceProtectedMEM, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_TraceUserInterface, NULL, (CSettings::SettingChangedFunc)UpdateTraceLevel);
|
|
|
|
g_Settings->UnregisterChangeCB(Debugger_AppLogFlush, g_LogFile, (CSettings::SettingChangedFunc)LogFlushChanged);
|
2015-12-16 06:41:34 +00:00
|
|
|
}
|
2015-12-14 10:51:33 +00:00
|
|
|
|
2015-12-16 06:41:34 +00:00
|
|
|
void TraceDone(void)
|
|
|
|
{
|
2015-12-14 10:51:33 +00:00
|
|
|
CloseTrace();
|
|
|
|
if (g_LogFile) { delete g_LogFile; g_LogFile = NULL; }
|
2015-11-14 20:56:40 +00:00
|
|
|
}
|
|
|
|
|
2016-01-13 07:23:22 +00:00
|
|
|
const char * AppName ( void )
|
|
|
|
{
|
|
|
|
static stdstr_f ApplicationName("Project64 %s", VER_FILE_VERSION_STR);
|
|
|
|
return ApplicationName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ParseCommand(int32_t argc, char **argv)
|
|
|
|
{
|
|
|
|
if (argc == 1)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
for (int32_t i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
int32_t ArgsLeft = argc - i - 1;
|
|
|
|
if (strcmp(argv[i], "--basedir") == 0 && ArgsLeft >= 1)
|
|
|
|
{
|
|
|
|
g_Settings->SaveString(Cmd_BaseDirectory, argv[i + 1]);
|
|
|
|
CSettingTypeApplication::Initialize(AppName());
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "--help") == 0)
|
|
|
|
{
|
|
|
|
g_Settings->SaveBool(Cmd_ShowHelp, true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (ArgsLeft == 0 && argv[i][0] != '-')
|
|
|
|
{
|
|
|
|
g_Settings->SaveString(Cmd_RomFile, &(argv[i][0]));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//WriteTraceF(TraceError, __FUNCTION__ ": unrecognized command-line parameter '%s'", argv[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AppInit(CNotification * Notify, int argc, char **argv)
|
2015-11-14 20:56:40 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
g_Notify = Notify;
|
2015-12-14 10:51:33 +00:00
|
|
|
InitializeLog();
|
2016-01-13 07:23:22 +00:00
|
|
|
if (Notify == NULL)
|
|
|
|
{
|
|
|
|
WriteTrace(TraceAppInit, TraceError, "No Notification class passed");
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-14 20:56:40 +00:00
|
|
|
g_Settings = new CSettings;
|
2016-01-13 07:23:22 +00:00
|
|
|
g_Settings->Initialize(AppName());
|
|
|
|
|
|
|
|
if (!ParseCommand(argc, argv))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-14 20:56:40 +00:00
|
|
|
|
2016-01-13 07:23:22 +00:00
|
|
|
#ifdef _WIN32
|
2015-11-14 20:56:40 +00:00
|
|
|
if (g_Settings->LoadBool(Setting_CheckEmuRunning) &&
|
|
|
|
pjutil::TerminatedExistingExe())
|
|
|
|
{
|
|
|
|
delete g_Settings;
|
|
|
|
g_Settings = new CSettings;
|
2016-01-13 07:23:22 +00:00
|
|
|
g_Settings->Initialize(AppName());
|
2015-11-14 20:56:40 +00:00
|
|
|
}
|
2016-01-13 07:23:22 +00:00
|
|
|
#endif
|
2015-11-14 20:56:40 +00:00
|
|
|
|
2015-12-14 10:51:33 +00:00
|
|
|
SetupTrace();
|
|
|
|
FixDirectories();
|
2016-01-13 07:23:22 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
CMipsMemoryVM::ReserveMemory();
|
|
|
|
IncreaseThreadPriority();
|
|
|
|
#endif
|
2015-11-14 20:56:40 +00:00
|
|
|
|
|
|
|
//Create the plugin container
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(TraceAppInit, TraceInfo, "Create Plugins");
|
2015-11-14 20:56:40 +00:00
|
|
|
g_Plugins = new CPlugins(g_Settings->LoadStringVal(Directory_Plugin));
|
|
|
|
|
|
|
|
g_Lang = new CLanguage();
|
|
|
|
g_Lang->LoadCurrentStrings();
|
|
|
|
g_Notify->AppInitDone();
|
2016-01-13 07:23:22 +00:00
|
|
|
WriteTrace(TraceAppInit, TraceDebug, "Initialized Successfully");
|
|
|
|
return true;
|
2015-11-14 20:56:40 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayError(stdstr_f("Exception caught\nFile: %s\nLine: %d", __FILE__, __LINE__).c_str());
|
2016-01-13 07:23:22 +00:00
|
|
|
WriteTrace(TraceAppInit, TraceError, "Exception caught, Init was not successfull");
|
|
|
|
return false;
|
2015-11-14 20:56:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppCleanup(void)
|
|
|
|
{
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(TraceAppCleanup, TraceDebug, "cleaning up global objects");
|
2015-12-16 06:41:34 +00:00
|
|
|
CleanupTrace();
|
2015-11-14 20:56:40 +00:00
|
|
|
|
|
|
|
if (g_Rom) { delete g_Rom; g_Rom = NULL; }
|
|
|
|
if (g_Plugins) { delete g_Plugins; g_Plugins = NULL; }
|
|
|
|
if (g_Settings) { delete g_Settings; g_Settings = NULL; }
|
|
|
|
if (g_Lang) { delete g_Lang; g_Lang = NULL; }
|
|
|
|
|
|
|
|
CMipsMemoryVM::FreeReservedMemory();
|
2015-12-16 06:41:34 +00:00
|
|
|
TraceDone();
|
2015-11-14 20:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FixDirectories(void)
|
|
|
|
{
|
|
|
|
CPath Directory(CPath::MODULE_DIRECTORY);
|
|
|
|
Directory.AppendDirectory("Config");
|
|
|
|
if (!Directory.DirectoryExists()) Directory.DirectoryCreate();
|
|
|
|
|
|
|
|
Directory.UpDirectory();
|
|
|
|
Directory.AppendDirectory("Save");
|
|
|
|
if (!Directory.DirectoryExists()) Directory.DirectoryCreate();
|
|
|
|
|
|
|
|
Directory.UpDirectory();
|
|
|
|
Directory.AppendDirectory("Screenshots");
|
|
|
|
if (!Directory.DirectoryExists()) Directory.DirectoryCreate();
|
|
|
|
|
|
|
|
Directory.UpDirectory();
|
|
|
|
Directory.AppendDirectory("textures");
|
|
|
|
if (!Directory.DirectoryExists()) Directory.DirectoryCreate();
|
|
|
|
}
|
|
|
|
|
2016-01-13 07:23:22 +00:00
|
|
|
#ifdef _WIN32
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <windows.h>
|
2015-11-14 20:56:40 +00:00
|
|
|
void IncreaseThreadPriority(void)
|
|
|
|
{
|
|
|
|
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
|
2016-01-13 07:23:22 +00:00
|
|
|
}
|
|
|
|
#endif
|