/////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// #include "gsCommon.h" #include "gsDebug.h" //#include //#include // THIS FILE ONLY INCLUDED WHEN USING GAMESPY DEBUG FUNCTIONS // (don't put this above the header includes or VC will whine #ifdef GSI_COMMON_DEBUG #if defined(_NITRO) #include "../../common/nitro/screen.h" #define printf Printf #define vprintf VPrintf #endif /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// // Static debug data static struct GSIDebugInstance gGSIDebugInstance; // simple singleton "class" // Line prefixes, e.g. "[ cat][type][ lev] text" char* gGSIDebugCatStrings[GSIDebugCat_Count] = { " APP", " GP ", "PEER", " QR2", " SB", " V2", " AD", " NN", "HTTP", "CDKY", " CMN" }; char* gGSIDebugTypeStrings[GSIDebugType_Count] = { " NET", "FILE", " MEM", "STAT", "MISC" }; char* gGSIDebugLevelStrings[GSIDebugLevel_Count] = { "*ERR", "****", "----", " ", " ", " ", " ->" }; char* gGSIDebugLevelDescriptionStrings[8] = { "None", "", "", "", "", "", "", "" }; /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// // utility to convert bit flag back to base (e.g. 1<<2 returns 2) static gsi_u32 gsiDebugLog2(gsi_u32 theInt) { gsi_u32 total = 0; while (theInt > 1) { theInt = theInt >> 1; total++; } return total; } // default supplied debug function, will receive debug text // this is platform specific static void gsiDebugCallback(GSIDebugCategory category, GSIDebugType type, GSIDebugLevel level, const char * format, va_list params) { #if defined(_PSP) // Output line prefix vprintf(format, params); //gsDebugTTyPrint(string); #elif defined(_PS2) // Output line prefix vprintf(format, params); #elif defined(_PS3) // Output line prefix vprintf(format, params); #elif defined(_WIN32) static char string[256]; vsprintf(string, format, params); OutputDebugStringA(string); #elif defined(_LINUX) || defined(_MACOSX) //static char string[256]; //vsprintf(string, format, params); vprintf(format, params); #elif defined(_NITRO) VPrintf(format, params); #elif defined(_REVOLUTION) static char string[256]; vsprintf(string, format, params); OSReport(string); #else va_list argptr; static char string[256]; va_start(argptr, format); vsprintf(string, format, argptr); va_end(argptr); gsDebugTTyPrint(string); #endif GSI_UNUSED(category); GSI_UNUSED(type); GSI_UNUSED(level); } /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// // process debug output void gsDebugVaList(GSIDebugCategory theCat, GSIDebugType theType, GSIDebugLevel theLevel, const char* theTokenStr, va_list theParamList) { // Retrieve the current debug level GSIDebugLevel aCurLevel; // Verify Parameters assert(theCat <= GSIDebugCat_Count); assert(theType <= GSIDebugType_Count); assert(theLevel <= (1< 0) { gsi_i32 aBytesToRead = min(aBytesLeft, 16); HexEncode16(aReadPos, aHexStr, (unsigned int)aBytesToRead); gsDebugFormat(theCat, theType, theLevel, " %s\r\n", aHexStr); aReadPos += aBytesToRead; aBytesLeft -= aBytesToRead; }; } /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// void gsSetDebugLevel(GSIDebugCategory theCat, GSIDebugType theType, GSIDebugLevel theLevel) { // Verify Parameters assert(theCat <= GSIDebugCat_Count); assert(theType <= GSIDebugType_Count); // Set for all categories? if (theCat == GSIDebugCat_Count) { int i=0; for (; i