small speedup of logmanager, minor logging improvements, misc code standard improvements, replace a crash with an error message in ppcanalyst

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1521 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2008-12-13 16:58:06 +00:00
parent 4355c37397
commit 522752c77d
16 changed files with 188 additions and 197 deletions

View file

@ -58,7 +58,7 @@ void CriticalSection::Enter()
bool CriticalSection::TryEnter()
{
return(TryEnterCriticalSection(&section) ? true : false);
return TryEnterCriticalSection(&section) ? true : false;
}

View file

@ -15,15 +15,14 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
// Simple partial Action Replay code system implementation.
// Partial Action Replay code system implementation.
// Will never be able to support some AR codes - specifically those that patch the running
// Action Replay engine itself - yes they do exist!!!
// Action Replay actually is a small virtual machine with a limited number of commands.
// It probably is Turing complete - but what does that matter when AR codes can write
// actual PowerPC code.
// actual PowerPC code...
#include <string>
#include <vector>
@ -166,14 +165,14 @@ void LogInfo(const char *format, ...)
{
if (!b_RanOnce)
{
if (IsLoggingActivated() || logSelf)
if (LogManager::Enabled() || logSelf)
{
char* temp = (char*)alloca(strlen(format)+512);
va_list args;
va_start(args, format);
CharArrayFromFormatV(temp, 512, format, args);
va_end(args);
if (IsLoggingActivated())
if (LogManager::Enabled())
LogManager::Log(LogTypes::ACTIONREPLAY, temp);
if (logSelf)
{
@ -189,20 +188,21 @@ void ActionReplayRunAllActive()
{
if (Core::GetStartupParameter().bEnableCheats) {
for (std::vector<ARCode>::iterator iter = activeCodes.begin(); iter != activeCodes.end(); ++iter)
if (iter->active) {
{
if (iter->active)
{
if (!RunActionReplayCode(*iter))
iter->active = false;
LogInfo("\n");
}
}
if (!b_RanOnce)
b_RanOnce = true;
}
}
bool RunActionReplayCode(const ARCode &arcode) {
// The mechanism is slightly different than what the real AR uses, so there may be compatibility problems.
// The mechanism is different than what the real AR uses, so there may be compatibility problems.
u8 cmd;
u32 addr;
u32 data;
@ -276,7 +276,8 @@ bool RunActionReplayCode(const ARCode &arcode) {
}
// skip these weird init lines
if (iter == code.ops.begin() && cmd == 1) continue;
if (iter == code.ops.begin() && cmd == 1)
continue;
// Zero codes
if (addr == 0x0) // Check if the code is a zero code
@ -380,8 +381,6 @@ bool RunActionReplayCode(const ARCode &arcode) {
return true;
}
// Subtypes
bool Subtype_RamWriteAndFill(u32 addr, u32 data)
{
@ -543,7 +542,6 @@ bool Subtype_MasterCodeAndWriteToCCXXXXXX()
return false;
}
// Zero Codes
bool ZeroCode_FillAndSlide(u32 val_last, u32 addr, u32 data) // This needs more testing
{
@ -784,6 +782,7 @@ bool NormalCode_Type_1(u8 subtype, u32 addr, u32 data, int *count, bool *skip)
}
return true;
}
bool NormalCode_Type_2(u8 subtype, u32 addr, u32 data, int *count, bool *skip)
{
u8 size = (addr >> 25) & 0x03;
@ -819,6 +818,7 @@ bool NormalCode_Type_2(u8 subtype, u32 addr, u32 data, int *count, bool *skip)
}
return true;
}
bool NormalCode_Type_3(u8 subtype, u32 addr, u32 data, int *count, bool *skip)
{
u8 size = (addr >> 25) & 0x03;
@ -854,6 +854,7 @@ bool NormalCode_Type_3(u8 subtype, u32 addr, u32 data, int *count, bool *skip)
}
return true;
}
bool NormalCode_Type_4(u8 subtype, u32 addr, u32 data, int *count, bool *skip)
{
u8 size = (addr >> 25) & 0x03;
@ -889,6 +890,7 @@ bool NormalCode_Type_4(u8 subtype, u32 addr, u32 data, int *count, bool *skip)
}
return true;
}
bool NormalCode_Type_5(u8 subtype, u32 addr, u32 data, int *count, bool *skip)
{
u8 size = (addr >> 25) & 0x03;
@ -924,6 +926,7 @@ bool NormalCode_Type_5(u8 subtype, u32 addr, u32 data, int *count, bool *skip)
}
return true;
}
bool NormalCode_Type_6(u8 subtype, u32 addr, u32 data, int *count, bool *skip)
{
u8 size = (addr >> 25) & 0x03;
@ -959,6 +962,7 @@ bool NormalCode_Type_6(u8 subtype, u32 addr, u32 data, int *count, bool *skip)
}
return true;
}
bool NormalCode_Type_7(u8 subtype, u32 addr, u32 data, int *count, bool *skip)
{
u8 size = (addr >> 25) & 0x03;
@ -999,6 +1003,7 @@ size_t ActionReplay_GetCodeListSize()
{
return arCodes.size();
}
ARCode ActionReplay_GetARCode(size_t index)
{
if (index > arCodes.size())
@ -1008,6 +1013,7 @@ ARCode ActionReplay_GetARCode(size_t index)
}
return arCodes[index];
}
void ActionReplay_SetARCode_IsActive(bool active, size_t index)
{
if (index > arCodes.size())
@ -1018,6 +1024,7 @@ void ActionReplay_SetARCode_IsActive(bool active, size_t index)
arCodes[index].active = active;
ActionReplay_UpdateActiveList();
}
void ActionReplay_UpdateActiveList()
{
b_RanOnce = false;
@ -1033,10 +1040,12 @@ void ActionReplay_EnableSelfLogging(bool enable)
{
logSelf = enable;
}
std::vector<std::string> ActionReplay_GetSelfLog()
const std::vector<std::string> &ActionReplay_GetSelfLog()
{
return arLog;
}
bool ActionReplay_IsSelfLogging()
{
return logSelf;

View file

@ -39,7 +39,7 @@ ARCode ActionReplay_GetARCode(size_t index);
void ActionReplay_SetARCode_IsActive(bool active, size_t index);
void ActionReplay_UpdateActiveList();
void ActionReplay_EnableSelfLogging(bool enable);
std::vector<std::string> ActionReplay_GetSelfLog();
const std::vector<std::string> &ActionReplay_GetSelfLog();
bool ActionReplay_IsSelfLogging();
#endif //_ACTIONREPLAY_H_

View file

@ -73,7 +73,7 @@ namespace Core
void Callback_VideoLog(const TCHAR* _szMessage, int _bDoBreak);
void Callback_VideoCopiedToXFB();
void Callback_DSPLog(const TCHAR* _szMessage, int _v);
char *Callback_ISOName(void);
const char *Callback_ISOName(void);
void Callback_DSPInterrupt();
void Callback_PADLog(const TCHAR* _szMessage);
void Callback_WiimoteLog(const TCHAR* _szMessage, int _v);
@ -375,12 +375,12 @@ THREAD_RETURN EmuThread(void *pArg)
cpuThread->WaitForDeath();
if (g_pUpdateFPSDisplay != NULL)
g_pUpdateFPSDisplay("Stopping...");
if (cpuThread) {
delete cpuThread;
delete cpuThread; // This joins the cpu thread.
// Returns after game exited
cpuThread = NULL;
}
// Returns after game exited
g_bHwInit = false;
PluginPAD::PAD_Shutdown();
@ -396,7 +396,7 @@ THREAD_RETURN EmuThread(void *pArg)
LOG(MASTER_LOG, "EmuThread exited");
// The CPU should return when a game is stopped and cleanup should be done here,
//so we can restart the plugins (or load new ones) for the next game
// so we can restart the plugins (or load new ones) for the next game.
if (_CoreParameter.hMainWindow == g_pWindowHandle)
Host_UpdateMainFrame();
return 0;
@ -555,12 +555,12 @@ void Callback_PADLog(const TCHAR* _szMessage)
// Callback_ISOName: Let the DSP plugin get the game name
//
//std::string Callback_ISOName(void)
char * Callback_ISOName(void)
const char *Callback_ISOName(void)
{
if (g_CoreStartupParameter.m_strName.length() > 0)
return (char *)g_CoreStartupParameter.m_strName.c_str();
return (const char *)g_CoreStartupParameter.m_strName.c_str();
else
return (char *)"";
return (const char *)"";
}
// __________________________________________________________________________________________________

View file

@ -72,7 +72,6 @@ void CheckGatherPipe()
memcpy(Memory::GetPointer(CPeripheralInterface::Fifo_CPUWritePointer), m_gatherPipe, GATHER_PIPE_SIZE);
// [F|RES]: i thought GP is forced to mem1 ... strange
// memcpy(&Memory::GetMainRAMPtr()[CPeripheralInterface::Fifo_CPUWritePointer], m_gatherPipe, GATHER_PIPE_SIZE);
// move back the spill bytes
m_gatherPipeCount -= GATHER_PIPE_SIZE;
@ -85,7 +84,7 @@ void CheckGatherPipe()
// increase the CPUWritePointer
CPeripheralInterface::Fifo_CPUWritePointer += GATHER_PIPE_SIZE;
if (CPeripheralInterface::Fifo_CPUWritePointer > CPeripheralInterface::Fifo_CPUEnd)
_assert_msg_(DYNA_REC, 0, "Fifo_CPUWritePointer out of bounds");
_assert_msg_(DYNA_REC, 0, "Fifo_CPUWritePointer out of bounds: %08x (end = %08x)", CPeripheralInterface::Fifo_CPUWritePointer, CPeripheralInterface::Fifo_CPUEnd);
if (CPeripheralInterface::Fifo_CPUWritePointer >= CPeripheralInterface::Fifo_CPUEnd)
CPeripheralInterface::Fifo_CPUWritePointer = CPeripheralInterface::Fifo_CPUBase;

View file

@ -623,7 +623,6 @@ bool Init()
position += FAKEVMEM_SIZE;
}
//WriteProtectMemory(base + 24*1024*1024, 8*1024*1024);
if (wii)
{
m_pPhysicalEXRAM = (u8*)g_arena.CreateViewAt(position, EXRAM_SIZE, base + 0x10000000);
@ -673,6 +672,7 @@ bool Init()
else
InitHWMemFuncs();
LOG(MEMMAP, "Memory system initialized. RAM at %p (0x80000000 @ %p)", base, base + 0x80000000);
m_IsInitialized = true;
return true;
}
@ -690,7 +690,6 @@ void DoState(PointerWrap &p)
bool Shutdown()
{
m_IsInitialized = false;
bool wii = Core::GetStartupParameter().bWii;
g_arena.ReleaseView(m_pRAM, RAM_SIZE);
@ -728,6 +727,7 @@ bool Shutdown()
g_arena.ReleaseView(m_pPhysicalFakeVMEM, FAKEVMEM_SIZE);
#endif
g_arena.ReleaseSpace();
LOG(MEMMAP, "Memory system shut down.");
return true;
}

View file

@ -511,7 +511,6 @@ void Update()
if (VerticalBeamPos == NextXFBRender)
{
u8* xfbPtr = 0;
int yOffset = 0;

View file

@ -197,24 +197,18 @@ void LogManager::Shutdown()
// ==========================================================================================
// The function that finally writes the log.
// ---------------
u32 lastPC;
std::string lastSymbol;
void LogManager::Log(LogTypes::LOG_TYPE _type, const char *_fmt, ...)
{
static u32 lastPC;
static std::string lastSymbol;
if (m_LogSettings == NULL)
return;
// declarations
int v; // verbosity level
int type; // the log type, CONSOLE etc.
char cvv[20];
std::string svv;
// get the current verbosity level and type
sprintf(cvv, "%03i", (int)_type);
svv = cvv;
v = atoi(svv.substr(0, 1).c_str());
type = atoi(svv.substr(1, 2).c_str());
// TODO: Base 100 is bad for speed.
int v = _type / 100;
int type = _type % 100;
// security checks
if (m_Log[_type] == NULL || !m_Log[_type]->m_bEnable
@ -310,7 +304,7 @@ void LogManager::Log(LogTypes::LOG_TYPE _type, const char *_fmt, ...)
fprintf(m_Log[ver*100 + LogTypes::MASTER_LOG]->m_pFile, "%s", Msg2);
/* In case it crashes write now to make sure you get the last messages.
Is this slower than caching it? */
Is this slower than caching it? Most likely yes, fflush can be really slow.*/
//fflush(m_Log[id]->m_pFile);
//fflush(m_Log[ver*100 + LogTypes::MASTER_LOG]->m_pFile);
@ -320,15 +314,13 @@ void LogManager::Log(LogTypes::LOG_TYPE _type, const char *_fmt, ...)
m_nextMessages[ver]++;
if (m_nextMessages[ver] >= MAX_MESSAGES)
m_nextMessages[ver] = 0;
// ---------------
}
else // write to separate files and structs
{
int id;
for (int i = VERBOSITY_LEVELS; i >= v ; i--)
{
// prepare the right id
id = i*100 + type;
int id = i*100 + type;
// write to memory
m_Messages[i][m_nextMessages[i]].Set((LogTypes::LOG_TYPE)id, v, Msg2);
@ -357,12 +349,3 @@ void LogManager::Log(LogTypes::LOG_TYPE _type, const char *_fmt, ...)
}
m_bDirty = true; // tell LogWindow that the log has been updated
}
bool IsLoggingActivated()
{
#ifdef LOGGING
return true;
#else
return false;
#endif
}

View file

@ -30,8 +30,9 @@ struct CDebugger_Log
{
char m_szName[128];
char m_szShortName[32];
char m_szShortName_[32]; // save the unadjusted originals here
char m_szShortName_[32]; // save the unadjusted originals here ( ???? )
char m_szFilename[256];
bool m_bLogToFile;
bool m_bShowInLog;
bool m_bEnable;
@ -40,10 +41,7 @@ struct CDebugger_Log
void Init();
void Shutdown();
// constructor
CDebugger_Log(const char* _szShortName, const char* _szName, int a);
// destructor
~CDebugger_Log();
};
@ -55,10 +53,7 @@ struct CDebugger_LogSettings
bool bWriteMaster;
bool bUnify;
// constructor
CDebugger_LogSettings();
// destructor
~CDebugger_LogSettings();
};
@ -67,7 +62,6 @@ class LogManager
#define MAX_MESSAGES 8000 // the old value was to large
#define MAX_MSGLEN 256
public:
// Message
struct SMessage
{
@ -103,6 +97,7 @@ public:
//
static void Log(LogTypes::LOG_TYPE _type, const char *_fmt, ...);
};
private:
enum LOG_SETTINGS
{
@ -118,13 +113,17 @@ private:
static bool m_bInitialized;
static CDebugger_LogSettings* m_LogSettings;
static CDebugger_Log* m_Log[LogTypes::NUMBER_OF_LOGS + (VERBOSITY_LEVELS * 100)]; // make 326 of them
public:
static void Init();
static void Clear(void);
static void Shutdown();
#ifdef LOGGING
static bool Enabled() { return true; }
#else
static bool Enabled() { return false; }
#endif
static void Log(LogTypes::LOG_TYPE _type, const char *_fmt, ...);
};
extern bool IsLoggingActivated();
#endif

View file

@ -359,6 +359,7 @@ CodeOp *Flatten(u32 address, u32 &realsize, BlockStats &st, BlockRegStats &gpa,
code[i].branchToIndex = -1;
code[i].x86ptr = 0;
GekkoOPInfo *opinfo = GetOpInfo(inst);
if (opinfo)
numCycles += opinfo->numCyclesMinusOne + 1;
_assert_msg_(GEKKO, opinfo != 0, "Invalid Op - Error flattening %08x op %08x",address+i*4,inst);
int flags = opinfo->flags;

View file

@ -284,11 +284,13 @@ void CCodeWindow::CreateGUIControls(const SCoreStartupParameter& _LocalCoreStart
// additional dialogs
if (IsLoggingActivated() && bLogWindow)
#ifdef LOGGING
if (bLogWindow)
{
m_LogWindow = new CLogWindow(this);
m_LogWindow->Show(true);
}
#endif
if (bRegisterWindow)
{
@ -380,7 +382,7 @@ void CCodeWindow::CreateMenu(const SCoreStartupParameter& _LocalCoreStartupParam
{
wxMenu* pDebugDialogs = new wxMenu;
if (IsLoggingActivated())
if (LogManager::Enabled())
{
wxMenuItem* pLogWindow = pDebugDialogs->Append(IDM_LOGWINDOW, _T("&LogManager"), wxEmptyString, wxITEM_CHECK);
pLogWindow->Check(bLogWindow);
@ -905,12 +907,11 @@ void CCodeWindow::OnSymbolListContextMenu(wxContextMenuEvent& event)
/////////////////////////////////////////////////////////////////////////////////////////////////
// Show and hide windows
// -----------------------
/////////////////////////////////////////////////////////////////////////////////////////////////
void CCodeWindow::OnToggleLogWindow(wxCommandEvent& event)
{
if (IsLoggingActivated())
if (LogManager::Enabled())
{
bool show = GetMenuBar()->IsChecked(event.GetId());

View file

@ -198,7 +198,7 @@ void wxCheatsWindow::OnEvent_ButtonUpdateCodes_Press(wxCommandEvent& WXUNUSED (e
void wxCheatsWindow::OnEvent_ButtonUpdateLog_Press(wxCommandEvent& WXUNUSED (event))
{
m_TextCtrl_Log->Clear();
std::vector<std::string> arLog = ActionReplay_GetSelfLog();
const std::vector<std::string> &arLog = ActionReplay_GetSelfLog();
for (int i = 0; i < arLog.size(); i++)
{
m_TextCtrl_Log->AppendText(wxString::FromAscii(arLog[i].c_str()));

View file

@ -371,7 +371,7 @@
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../../Core/Common/Src;../../PluginSpecs"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_SECURE_SCL=0WIN32;_LIB;__WXMSW__;wxUSE_BASE=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_SECURE_SCL=0;__WXMSW__;wxUSE_BASE=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="0"
BufferSecurityCheck="false"
UsePrecompiledHeader="0"

View file

@ -12,7 +12,7 @@ typedef unsigned char (*TARAM_Read_U8)(const unsigned int _uAddress);
typedef unsigned char* (*TGetMemoryPointer)(const unsigned int _uAddress);
typedef unsigned char* (*TGetARAMPointer)(void);
typedef void (*TLogv)(const char* _szMessage, int _v);
typedef char* (*TName)(void);
typedef const char* (*TName)(void);
typedef void (*TDebuggerBreak)(void);
typedef void (*TGenerateDSPInt)(void);
typedef unsigned int (*TAudioGetStreaming)(short* _pDestBuffer, unsigned int _numSamples);