mirror of
https://github.com/AppleWin/AppleWin.git
synced 2024-06-02 20:41:38 +00:00
Debugger: replace sprintf() part 7 final - Debug (PR #1093)
- Add ProfileLine_t to take care of the profile line buffer - Simplify _SearchMemoryDisplay() without using StringCat() - Simplify CmdOutputPrint() significantly
This commit is contained in:
parent
47ba87a015
commit
4063611e71
|
@ -238,8 +238,30 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
bool ProfileSave ();
|
bool ProfileSave ();
|
||||||
void ProfileFormat( bool bSeperateColumns, ProfileFormat_e eFormatMode );
|
void ProfileFormat( bool bSeperateColumns, ProfileFormat_e eFormatMode );
|
||||||
|
|
||||||
char * ProfileLinePeek ( int iLine );
|
// TODO: Things would be much simpler if g_aProfileLine is just a container of std::string.
|
||||||
char * ProfileLinePush ();
|
struct ProfileLine_t
|
||||||
|
{
|
||||||
|
ProfileLine_t() : buf(NULL), bufsz(0) {}
|
||||||
|
ProfileLine_t(char* _buf, size_t _bufsz) : buf(_buf), bufsz(_bufsz) {}
|
||||||
|
void Assign(std::string const& str)
|
||||||
|
{
|
||||||
|
if (!buf || bufsz <= 0) return;
|
||||||
|
strncpy_s(buf, bufsz, str.c_str(), _TRUNCATE);
|
||||||
|
}
|
||||||
|
ATTRIBUTE_FORMAT_PRINTF(2, 3) /* 1 is "this" */
|
||||||
|
void Format(const char* fmt, ...)
|
||||||
|
{
|
||||||
|
if (!buf || bufsz <= 0) return;
|
||||||
|
va_list va;
|
||||||
|
va_start(va, fmt);
|
||||||
|
Assign(StrFormatV(fmt, va));
|
||||||
|
va_end(va);
|
||||||
|
}
|
||||||
|
char* buf;
|
||||||
|
size_t bufsz;
|
||||||
|
};
|
||||||
|
ProfileLine_t ProfileLinePeek ( int iLine );
|
||||||
|
ProfileLine_t ProfileLinePush ();
|
||||||
void ProfileLineReset ();
|
void ProfileLineReset ();
|
||||||
|
|
||||||
// Soft-switches __________________________________________________________________________________
|
// Soft-switches __________________________________________________________________________________
|
||||||
|
@ -790,11 +812,11 @@ Update_t CmdProfile (int nArgs)
|
||||||
|
|
||||||
for ( int iLine = 0; iLine < nLine; iLine++ )
|
for ( int iLine = 0; iLine < nLine; iLine++ )
|
||||||
{
|
{
|
||||||
const char *pText = ProfileLinePeek( iLine );
|
ProfileLine_t prfline = ProfileLinePeek( iLine );
|
||||||
if (pText)
|
if (prfline.buf)
|
||||||
{
|
{
|
||||||
char sText[ CONSOLE_WIDTH ];
|
char sText[ CONSOLE_WIDTH ];
|
||||||
TextConvertTabsToSpaces( sText, pText, CONSOLE_WIDTH, 4 );
|
TextConvertTabsToSpaces( sText, prfline.buf, CONSOLE_WIDTH, 4 );
|
||||||
// ConsoleBufferPush( sText );
|
// ConsoleBufferPush( sText );
|
||||||
ConsolePrint( sText );
|
ConsolePrint( sText );
|
||||||
}
|
}
|
||||||
|
@ -5391,90 +5413,49 @@ int _SearchMemoryFind(
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
Update_t _SearchMemoryDisplay (int nArgs)
|
Update_t _SearchMemoryDisplay (int nArgs)
|
||||||
{
|
{
|
||||||
const UINT nBuf = CONSOLE_WIDTH * 2;
|
int const nFound = g_vMemorySearchResults.size() - 1;
|
||||||
|
|
||||||
int nFound = g_vMemorySearchResults.size() - 1;
|
|
||||||
|
|
||||||
int nLen = 0; // temp
|
|
||||||
int nLineLen = 0; // string length of matches for this line, for word-wrap
|
|
||||||
|
|
||||||
TCHAR sMatches[ nBuf ] = TEXT("");
|
|
||||||
TCHAR sResult[ nBuf ];
|
|
||||||
TCHAR sText[ nBuf ] = TEXT("");
|
|
||||||
|
|
||||||
if (nFound > 0)
|
if (nFound > 0)
|
||||||
{
|
{
|
||||||
|
std::string sMatches;
|
||||||
|
|
||||||
int iFound = 1;
|
int iFound = 1;
|
||||||
while (iFound <= nFound)
|
while (iFound <= nFound)
|
||||||
{
|
{
|
||||||
WORD nAddress = g_vMemorySearchResults.at( iFound );
|
WORD const nAddress = g_vMemorySearchResults.at( iFound );
|
||||||
|
|
||||||
// sprintf( sText, "%2d:$%04X ", iFound, nAddress );
|
// 2.6.2.17 Search Results: The n'th result now using correct color (was command, now number decimal)
|
||||||
// int nLen = _tcslen( sText );
|
// BUGFIX: 2.6.2.32 n'th Search results were being displayed in dec, yet parser takes hex numbers. i.e. SH D000:FFFF A9 00
|
||||||
|
// Intentional default instead of CHC_ARG_SEP for better readability
|
||||||
|
// 2.6.2.16 Fixed: Search Results: The hex specify for target address results now colorized properly
|
||||||
|
// 2.6.2.15 Fixed: Search Results: Added space between results for better readability
|
||||||
|
|
||||||
sResult[0] = 0;
|
// FIXME: Color is DEC whereas the format is "%X". What's the real intention?
|
||||||
nLen = 0;
|
std::string sResult = StrFormat( CHC_NUM_DEC "%02X" CHC_DEFAULT ":" CHC_ARG_SEP "$" CHC_ADDRESS "%04X ",
|
||||||
|
iFound, nAddress );
|
||||||
StringCat( sResult, CHC_NUM_DEC, nBuf ); // 2.6.2.17 Search Results: The n'th result now using correct color (was command, now number decimal)
|
|
||||||
sprintf( sText, "%02X", iFound ); // BUGFIX: 2.6.2.32 n'th Search results were being displayed in dec, yet parser takes hex numbers. i.e. SH D000:FFFF A9 00
|
|
||||||
nLen += StringCat( sResult, sText , nBuf );
|
|
||||||
|
|
||||||
StringCat( sResult, CHC_DEFAULT, nBuf ); // intentional default instead of CHC_ARG_SEP for better readability
|
|
||||||
nLen += StringCat( sResult, ":" , nBuf );
|
|
||||||
|
|
||||||
StringCat( sResult, CHC_ARG_SEP, nBuf );
|
|
||||||
nLen += StringCat( sResult, "$" , nBuf ); // 2.6.2.16 Fixed: Search Results: The hex specify for target address results now colorized properly
|
|
||||||
|
|
||||||
StringCat( sResult, CHC_ADDRESS, nBuf );
|
|
||||||
sprintf( sText, "%04X ", nAddress ); // 2.6.2.15 Fixed: Search Results: Added space between results for better readability
|
|
||||||
nLen += StringCat( sResult, sText, nBuf );
|
|
||||||
|
|
||||||
// Fit on same line?
|
// Fit on same line?
|
||||||
if ((nLineLen + nLen) > (g_nConsoleDisplayWidth - 1)) // CONSOLE_WIDTH
|
if ((sMatches.length() + sResult.length()) > (size_t(g_nConsoleDisplayWidth) - 1)) // CONSOLE_WIDTH
|
||||||
{
|
{
|
||||||
//ConsoleDisplayPush( sMatches );
|
//ConsoleDisplayPush( sMatches.c_str() );
|
||||||
ConsolePrint( sMatches );
|
ConsolePrint( sMatches.c_str() );
|
||||||
_tcscpy( sMatches, sResult );
|
sMatches = sResult;
|
||||||
nLineLen = nLen;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
StringCat( sMatches, sResult, nBuf );
|
sMatches += sResult;
|
||||||
nLineLen += nLen;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
iFound++;
|
iFound++;
|
||||||
}
|
}
|
||||||
ConsolePrint( sMatches );
|
|
||||||
|
ConsolePrint( sMatches.c_str() );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConsoleDisplayPushFormat( "Total: %d (#$%04X)", nFound, nFound );
|
//ConsoleDisplayPushFormat( "Total: %d (#$%04X)", nFound, nFound );
|
||||||
sResult[0] = 0;
|
|
||||||
|
|
||||||
StringCat( sResult, CHC_USAGE , nBuf );
|
ConsolePrintFormat( CHC_USAGE "Total" CHC_DEFAULT ": " CHC_NUM_DEC "%d " CHC_ARG_SEP "(" CHC_ARG_SEP "#$" CHC_NUM_HEX "%04X" CHC_ARG_SEP ")",
|
||||||
nLen += StringCat( sResult, "Total", nBuf );
|
nFound /*dec*/, nFound /*hex*/ );
|
||||||
|
|
||||||
StringCat( sResult, CHC_DEFAULT, nBuf );
|
|
||||||
nLen += StringCat( sResult, ": " , nBuf );
|
|
||||||
|
|
||||||
StringCat( sResult, CHC_NUM_DEC, nBuf ); // intentional CHC_DEFAULT instead of
|
|
||||||
sprintf( sText, "%d ", nFound );
|
|
||||||
nLen += StringCat( sResult, sText, nBuf );
|
|
||||||
|
|
||||||
StringCat( sResult, CHC_ARG_SEP, nBuf ); // CHC_ARC_OPT -> CHC_ARG_SEP
|
|
||||||
nLen += StringCat( sResult, "(" , nBuf );
|
|
||||||
|
|
||||||
StringCat( sResult, CHC_ARG_SEP, nBuf ); // CHC_DEFAULT
|
|
||||||
nLen += StringCat( sResult, "#$", nBuf );
|
|
||||||
|
|
||||||
StringCat( sResult, CHC_NUM_HEX, nBuf );
|
|
||||||
sprintf( sText, "%04X", nFound );
|
|
||||||
nLen += StringCat( sResult, sText, nBuf );
|
|
||||||
|
|
||||||
StringCat( sResult, CHC_ARG_SEP, nBuf );
|
|
||||||
nLen += StringCat( sResult, ")" , nBuf );
|
|
||||||
|
|
||||||
ConsolePrint( sResult );
|
|
||||||
|
|
||||||
// g_vMemorySearchResults is cleared in DebugEnd()
|
// g_vMemorySearchResults is cleared in DebugEnd()
|
||||||
|
|
||||||
|
@ -5832,52 +5813,26 @@ Update_t CmdOutputPrint (int nArgs)
|
||||||
{
|
{
|
||||||
// PRINT "A:",A," X:",X
|
// PRINT "A:",A," X:",X
|
||||||
// Removed: PRINT "A:%d",A," X: %d",X
|
// Removed: PRINT "A:%d",A," X: %d",X
|
||||||
TCHAR sText[ CONSOLE_WIDTH ] = TEXT("");
|
std::string sText;
|
||||||
int nLen = 0;
|
|
||||||
|
|
||||||
if (! nArgs)
|
if (nArgs <= 0)
|
||||||
goto _Help;
|
goto _Help;
|
||||||
|
|
||||||
for ( int iArg = 1; iArg <= nArgs; iArg++ )
|
for ( int iArg = 1; iArg <= nArgs; iArg++ )
|
||||||
{
|
{
|
||||||
if (g_aArgs[ iArg ].bType & TYPE_QUOTED_2)
|
sText += (!!(g_aArgs[ iArg ].bType & TYPE_QUOTED_2))
|
||||||
{
|
? g_aArgs[ iArg ].sArg
|
||||||
const int nChar = _tcslen( g_aArgs[ iArg ].sArg );
|
: WordToHexStr( g_aArgs[ iArg ].nValue );
|
||||||
for ( int iChar = 0; iChar < nChar; iChar++ )
|
|
||||||
{
|
|
||||||
TCHAR c = g_aArgs[ iArg ].sArg[ iChar ];
|
|
||||||
sText[ nLen++ ] = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
iArg++;
|
iArg++;
|
||||||
// if (iArg > nArgs)
|
//if (iArg > nArgs)
|
||||||
// goto _Help;
|
// goto _Help;
|
||||||
if (iArg <= nArgs)
|
if (iArg <= nArgs && g_aArgs[ iArg ].eToken != TOKEN_COMMA)
|
||||||
if (g_aArgs[ iArg ].eToken != TOKEN_COMMA)
|
goto _Help;
|
||||||
goto _Help;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const int nValue = g_aArgs[ iArg ].nValue;
|
|
||||||
sprintf( &sText[ nLen ], "%04X", nValue );
|
|
||||||
|
|
||||||
while (sText[ nLen ])
|
|
||||||
nLen++;
|
|
||||||
|
|
||||||
iArg++;
|
|
||||||
if (iArg <= nArgs)
|
|
||||||
if (g_aArgs[ iArg ].eToken != TOKEN_COMMA)
|
|
||||||
goto _Help;
|
|
||||||
#if 0
|
|
||||||
sprintf( &sText[ nLen ], "%04X", nValue );
|
|
||||||
sprintf( &sText[ nLen ], "%d", nValue );
|
|
||||||
sprintf( &sText[ nLen ], "%c", nValue );
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nLen)
|
if (!sText.empty())
|
||||||
ConsoleBufferPush( sText );
|
ConsoleBufferPush( sText.c_str() );
|
||||||
|
|
||||||
return ConsoleUpdate();
|
return ConsoleUpdate();
|
||||||
|
|
||||||
|
@ -5912,8 +5867,8 @@ Update_t CmdOutputPrintf (int nArgs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TCHAR sText[ CONSOLE_WIDTH ] = TEXT("");
|
std::string sText;
|
||||||
int nLen = 0;
|
sText.reserve(CONSOLE_WIDTH);
|
||||||
|
|
||||||
PrintState_e eThis = PS_LITERAL;
|
PrintState_e eThis = PS_LITERAL;
|
||||||
int nWidth = 0;
|
int nWidth = 0;
|
||||||
|
@ -5925,10 +5880,9 @@ Update_t CmdOutputPrintf (int nArgs)
|
||||||
{
|
{
|
||||||
if (g_aArgs[ iArg ].bType & TYPE_QUOTED_2)
|
if (g_aArgs[ iArg ].bType & TYPE_QUOTED_2)
|
||||||
{
|
{
|
||||||
const int nChar = _tcslen( g_aArgs[ iArg ].sArg );
|
for ( const char* cp = g_aArgs[iArg].sArg, *ep = cp + strlen(g_aArgs[iArg].sArg); cp < ep; ++cp )
|
||||||
for ( int iChar = 0; iChar < nChar; iChar++ )
|
|
||||||
{
|
{
|
||||||
TCHAR c = g_aArgs[ iArg ].sArg[ iChar ];
|
const char c = *cp;
|
||||||
switch ( eThis )
|
switch ( eThis )
|
||||||
{
|
{
|
||||||
case PS_LITERAL:
|
case PS_LITERAL:
|
||||||
|
@ -5941,7 +5895,7 @@ Update_t CmdOutputPrintf (int nArgs)
|
||||||
eThis = PS_TYPE;
|
eThis = PS_TYPE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sText[ nLen++ ] = c;
|
sText += c;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -5951,7 +5905,7 @@ Update_t CmdOutputPrintf (int nArgs)
|
||||||
case 'n':
|
case 'n':
|
||||||
case 'r':
|
case 'r':
|
||||||
eThis = PS_LITERAL;
|
eThis = PS_LITERAL;
|
||||||
sText[ nLen++ ] = '\n';
|
sText += '\n';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -5965,12 +5919,12 @@ Update_t CmdOutputPrintf (int nArgs)
|
||||||
{
|
{
|
||||||
case 'X':
|
case 'X':
|
||||||
case 'x': // PS_NEXT_ARG_HEX
|
case 'x': // PS_NEXT_ARG_HEX
|
||||||
sprintf( &sText[ nLen ], "%04X", aValues[ iValue ].nValue );
|
sText += WordToHexStr( aValues[ iValue ].nValue );
|
||||||
iValue++;
|
iValue++;
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
case 'd': // PS_NEXT_ARG_DEC
|
case 'd': // PS_NEXT_ARG_DEC
|
||||||
sprintf( &sText[ nLen ], "%d", aValues[ iValue ].nValue );
|
sText += StrFormat( "%d", aValues[ iValue ].nValue );
|
||||||
iValue++;
|
iValue++;
|
||||||
break;
|
break;
|
||||||
break;
|
break;
|
||||||
|
@ -5983,22 +5937,20 @@ Update_t CmdOutputPrintf (int nArgs)
|
||||||
int nBits = nWidth;
|
int nBits = nWidth;
|
||||||
while (nBits-- > 0)
|
while (nBits-- > 0)
|
||||||
{
|
{
|
||||||
sText[ nLen++ ] = ((nValue >> nBits) & 1) ? '1' : '0';
|
sText += ((nValue >> nBits) & 1) ? '1' : '0';
|
||||||
}
|
}
|
||||||
iValue++;
|
iValue++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'c': // PS_NEXT_ARG_CHR;
|
case 'c': // PS_NEXT_ARG_CHR;
|
||||||
sprintf( &sText[ nLen ], "%c", aValues[ iValue ].nValue );
|
sText += char( aValues[ iValue ].nValue );
|
||||||
iValue++;
|
iValue++;
|
||||||
break;
|
break;
|
||||||
case '%':
|
case '%':
|
||||||
default:
|
default:
|
||||||
sText[ nLen++ ] = c;
|
sText += c;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
while (sText[ nLen ])
|
|
||||||
nLen++;
|
|
||||||
eThis = PS_LITERAL;
|
eThis = PS_LITERAL;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -6017,8 +5969,8 @@ Update_t CmdOutputPrintf (int nArgs)
|
||||||
goto _Help;
|
goto _Help;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nLen)
|
if (!sText.empty())
|
||||||
ConsoleBufferPush( sText );
|
ConsoleBufferPush( sText.c_str() );
|
||||||
|
|
||||||
return ConsoleUpdate();
|
return ConsoleUpdate();
|
||||||
|
|
||||||
|
@ -7432,35 +7384,29 @@ int FindCommand( LPCTSTR pName, CmdFuncPtr_t & pFunction_, int * iCommand_ )
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
void DisplayAmbigiousCommands( int nFound )
|
void DisplayAmbigiousCommands( int nFound )
|
||||||
{
|
{
|
||||||
ConsolePrintFormat("Ambiguous %s%" SIZE_T_FMT "%s Commands:"
|
ConsolePrintFormat("Ambiguous " CHC_NUM_DEC "%" SIZE_T_FMT CHC_DEFAULT " Commands:"
|
||||||
, CHC_NUM_DEC
|
|
||||||
, g_vPotentialCommands.size()
|
, g_vPotentialCommands.size()
|
||||||
, CHC_DEFAULT
|
|
||||||
);
|
);
|
||||||
|
|
||||||
int iCommand = 0;
|
int iCommand = 0;
|
||||||
while (iCommand < nFound)
|
while (iCommand < nFound)
|
||||||
{
|
{
|
||||||
char sPotentialCommands[ CONSOLE_WIDTH ];
|
std::string sPotentialCommands = CHC_COMMAND " ";
|
||||||
sprintf( sPotentialCommands, "%s ", CHC_COMMAND );
|
|
||||||
|
|
||||||
int iWidth = strlen( sPotentialCommands );
|
while ((iCommand < nFound) && (sPotentialCommands.length() < size_t(g_nConsoleDisplayWidth)))
|
||||||
while ((iCommand < nFound) && (iWidth < g_nConsoleDisplayWidth))
|
|
||||||
{
|
{
|
||||||
int nCommand = g_vPotentialCommands[ iCommand ];
|
int const nCommand = g_vPotentialCommands[ iCommand ];
|
||||||
char *pName = g_aCommands[ nCommand ].m_sName;
|
const char *const pName = g_aCommands[ nCommand ].m_sName;
|
||||||
int nLen = strlen( pName );
|
size_t const nLen = strlen( pName );
|
||||||
|
|
||||||
if ((iWidth + nLen) >= (CONSOLE_WIDTH - 1))
|
if ((sPotentialCommands.length() + nLen) >= (CONSOLE_WIDTH - 1))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
char sText[ CONSOLE_WIDTH * 2 ];
|
sPotentialCommands.append(pName, nLen).append(1, ' ');
|
||||||
sprintf( sText, "%s ", pName );
|
|
||||||
strcat( sPotentialCommands, sText );
|
|
||||||
iWidth += nLen + 1;
|
|
||||||
iCommand++;
|
iCommand++;
|
||||||
}
|
}
|
||||||
ConsolePrint( sPotentialCommands );
|
ConsolePrint( sPotentialCommands.c_str() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7734,14 +7680,9 @@ void OutputTraceLine ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char sTarget[ 16 ];
|
//std::string const sTarget = (line.bTargetValue)
|
||||||
if (line.bTargetValue)
|
// ? StrFormat( "%s:%s", line.sTargetPointer , line.sTargetValue )
|
||||||
{
|
// : std::string();
|
||||||
sprintf( sTarget, "%s:%s"
|
|
||||||
, line.sTargetPointer
|
|
||||||
, line.sTargetValue
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_bTraceFileWithVideoScanner)
|
if (g_bTraceFileWithVideoScanner)
|
||||||
{
|
{
|
||||||
|
@ -7807,24 +7748,18 @@ void ParseParameter( )
|
||||||
|
|
||||||
// Return address of next line to write to.
|
// Return address of next line to write to.
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
char * ProfileLinePeek ( int iLine )
|
ProfileLine_t ProfileLinePeek ( int iLine )
|
||||||
{
|
{
|
||||||
char *pText = NULL;
|
|
||||||
|
|
||||||
if (iLine < 0)
|
if (iLine < 0)
|
||||||
iLine = 0;
|
iLine = 0;
|
||||||
|
|
||||||
if (! g_nProfileLine)
|
return ( g_nProfileLine == 0 || iLine <= g_nProfileLine )
|
||||||
pText = & g_aProfileLine[ iLine ][ 0 ];
|
? ProfileLine_t( g_aProfileLine[ iLine ], sizeof(g_aProfileLine[iLine]) )
|
||||||
|
: ProfileLine_t();
|
||||||
if (iLine <= g_nProfileLine)
|
|
||||||
pText = & g_aProfileLine[ iLine ][ 0 ];
|
|
||||||
|
|
||||||
return pText;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
char * ProfileLinePush ()
|
ProfileLine_t ProfileLinePush ()
|
||||||
{
|
{
|
||||||
if (g_nProfileLine < NUM_PROFILE_LINES)
|
if (g_nProfileLine < NUM_PROFILE_LINES)
|
||||||
{
|
{
|
||||||
|
@ -7844,24 +7779,28 @@ void ProfileLineReset()
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
void ProfileFormat( bool bExport, ProfileFormat_e eFormatMode )
|
void ProfileFormat( bool bExport, ProfileFormat_e eFormatMode )
|
||||||
{
|
{
|
||||||
char sSeparator7[ 32 ] = "\t";
|
std::string sSeparator7;
|
||||||
char sSeparator2[ 32 ] = "\t";
|
std::string sSeparator2;
|
||||||
char sSeparator1[ 32 ] = "\t";
|
std::string sSeparator1;
|
||||||
char sOpcode [ 8 ]; // 2 chars for opcode in hex, plus quotes on either side
|
|
||||||
char sAddress[MAX_OPMODE_NAME];
|
|
||||||
|
|
||||||
if (eFormatMode == PROFILE_FORMAT_COMMA)
|
if (eFormatMode == PROFILE_FORMAT_COMMA)
|
||||||
{
|
{
|
||||||
sSeparator7[0] = ',';
|
sSeparator7 = ',';
|
||||||
sSeparator2[0] = ',';
|
sSeparator2 = ',';
|
||||||
sSeparator1[0] = ',';
|
sSeparator1 = ',';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (eFormatMode == PROFILE_FORMAT_SPACE)
|
if (eFormatMode == PROFILE_FORMAT_SPACE)
|
||||||
{
|
{
|
||||||
sprintf( sSeparator7, " " ); // 7
|
sSeparator7.assign(7, ' ');
|
||||||
sprintf( sSeparator2, " " ); // 2
|
sSeparator2.assign(2, ' ');
|
||||||
sprintf( sSeparator1, " " ); // 1
|
sSeparator1 = ' ';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sSeparator7 = '\t';
|
||||||
|
sSeparator2 = '\t';
|
||||||
|
sSeparator1 = '\t';
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileLineReset();
|
ProfileLineReset();
|
||||||
|
@ -7911,18 +7850,16 @@ void ProfileFormat( bool bExport, ProfileFormat_e eFormatMode )
|
||||||
pColorTotal = CHC_DEFAULT; // white
|
pColorTotal = CHC_DEFAULT; // white
|
||||||
}
|
}
|
||||||
|
|
||||||
char *pText = ProfileLinePeek( 0 );
|
ProfileLine_t prfline = ProfileLinePeek(0);
|
||||||
|
|
||||||
// Opcode
|
// Opcode
|
||||||
if (bExport) // Export = SeperateColumns
|
if (bExport) // Export = SeperateColumns
|
||||||
sprintf( pText
|
prfline.Format( "\"Percent\"" DELIM "\"Count\"" DELIM "\"Opcode\"" DELIM "\"Mnemonic\"" DELIM "\"Addressing Mode\"\n",
|
||||||
, "\"Percent\"" DELIM "\"Count\"" DELIM "\"Opcode\"" DELIM "\"Mnemonic\"" DELIM "\"Addressing Mode\"\n"
|
sSeparator7.c_str(), sSeparator2.c_str(), sSeparator1.c_str(), sSeparator1.c_str() );
|
||||||
, sSeparator7, sSeparator2, sSeparator1, sSeparator1 );
|
|
||||||
else
|
else
|
||||||
sprintf( pText
|
prfline.Format( "Percent" DELIM "Count" DELIM "Mnemonic" DELIM "Addressing Mode\n",
|
||||||
, "Percent" DELIM "Count" DELIM "Mnemonic" DELIM "Addressing Mode\n"
|
sSeparator7.c_str(), sSeparator2.c_str(), sSeparator1.c_str() );
|
||||||
, sSeparator7, sSeparator2, sSeparator1 );
|
prfline = ProfileLinePush();
|
||||||
pText = ProfileLinePush();
|
|
||||||
|
|
||||||
for ( int iOpcode = 0; iOpcode < NUM_OPCODES; ++iOpcode )
|
for ( int iOpcode = 0; iOpcode < NUM_OPCODES; ++iOpcode )
|
||||||
{
|
{
|
||||||
|
@ -7938,74 +7875,65 @@ void ProfileFormat( bool bExport, ProfileFormat_e eFormatMode )
|
||||||
int nOpmode = g_aOpcodes[ nOpcode ].nAddressMode;
|
int nOpmode = g_aOpcodes[ nOpcode ].nAddressMode;
|
||||||
double nPercent = (100. * nCount) / nOpcodeTotal;
|
double nPercent = (100. * nCount) / nOpcodeTotal;
|
||||||
|
|
||||||
char sOpmode[ MAX_OPMODE_FORMAT ];
|
//std::string sOpmode = StrFormat( g_aOpmodes[ nOpmode ].m_sFormat, 0 );
|
||||||
sprintf( sOpmode, g_aOpmodes[ nOpmode ].m_sFormat, 0 );
|
|
||||||
|
|
||||||
if (bExport)
|
// Excel Bug: Quoted numbers are NOT treated as strings in .csv! WTF?
|
||||||
{
|
// @reference: http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q214233
|
||||||
// Excel Bug: Quoted numbers are NOT treated as strings in .csv! WTF?
|
//
|
||||||
// @reference: http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q214233
|
// Workaround: Prefix with (') apostrophe -- this doesn't break HEX2DEC()
|
||||||
//
|
// This works properly in Openoffice.
|
||||||
// Workaround: Prefix with (') apostrophe -- this doesn't break HEX2DEC()
|
// In Excel, this ONLY works IF you TYPE it in!
|
||||||
// This works properly in Openoffice.
|
//
|
||||||
// In Excel, this ONLY works IF you TYPE it in!
|
// Solution: Quote the numbers, but you must select the "TEXT" Column data format for the "Opcode" column.
|
||||||
//
|
// We don't use .csv, since you aren't given the Import Dialog in Excel!
|
||||||
// Solution: Quote the numbers, but you must select the "TEXT" Column data format for the "Opcode" column.
|
// StrFormat( "'%02X", nOpcode ); // SHOULD work with Excel, but only works with OpenOffice.
|
||||||
// We don't use .csv, since you aren't given the Import Dialog in Excel!
|
const std::string sOpcode = (bExport)
|
||||||
sprintf( sOpcode, "\"%02X\"", nOpcode ); // Works with Excel, IF using Import dialog & choose Text. (also works with OpenOffice)
|
? StrFormat("\"%02X\"", nOpcode) // Works with Excel, IF using Import dialog & choose Text. (also works with OpenOffice)
|
||||||
// sprintf( sOpcode, "'%02X", nOpcode ); // SHOULD work with Excel, but only works with OpenOffice.
|
: ByteToHexStr(nOpcode);
|
||||||
sprintf( sAddress, "\"%s\"", g_aOpmodes[ nOpmode ].m_sName );
|
const std::string sAddress = (bExport)
|
||||||
}
|
? ( '"' + std::string(g_aOpmodes[nOpmode].m_sName) + '"' )
|
||||||
else // not qouted if dumping to console
|
: std::string(g_aOpmodes[ nOpmode ].m_sName);
|
||||||
{
|
|
||||||
sprintf( sOpcode, "%02X", nOpcode );
|
|
||||||
strcpy( sAddress, g_aOpmodes[ nOpmode ].m_sName );
|
|
||||||
}
|
|
||||||
|
|
||||||
// BUG: Yeah 100% is off by 1 char. Profiling only one opcode isn't worth fixing this visual alignment bug.
|
// BUG: Yeah 100% is off by 1 char. Profiling only one opcode isn't worth fixing this visual alignment bug.
|
||||||
sprintf( pText,
|
prfline.Format( "%s%7.4f%s%%" DELIM "%s%9u" DELIM "%s%s" DELIM "%s%s" DELIM "%s%s\n"
|
||||||
"%s%7.4f%s%%" DELIM "%s%9u" DELIM "%s%s" DELIM "%s%s" DELIM "%s%s\n"
|
|
||||||
, pColorNumber
|
, pColorNumber
|
||||||
, nPercent
|
, nPercent
|
||||||
, pColorOperator
|
, pColorOperator
|
||||||
, sSeparator2
|
, sSeparator2.c_str()
|
||||||
, pColorNumber
|
, pColorNumber
|
||||||
, static_cast<unsigned int>(nCount), sSeparator2
|
, static_cast<unsigned int>(nCount), sSeparator2.c_str()
|
||||||
, pColorOpcode
|
, pColorOpcode
|
||||||
, sOpcode, sSeparator2
|
, sOpcode.c_str(), sSeparator2.c_str()
|
||||||
, pColorMnemonic
|
, pColorMnemonic
|
||||||
, g_aOpcodes[ nOpcode ].sMnemonic, sSeparator2
|
, g_aOpcodes[ nOpcode ].sMnemonic, sSeparator2.c_str()
|
||||||
, pColorOpmode
|
, pColorOpmode
|
||||||
, sAddress
|
, sAddress.c_str()
|
||||||
);
|
);
|
||||||
pText = ProfileLinePush();
|
prfline = ProfileLinePush();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! bOpcodeGood)
|
if (! bOpcodeGood)
|
||||||
nOpcodeTotal = 0;
|
nOpcodeTotal = 0;
|
||||||
|
|
||||||
sprintf( pText
|
prfline.Format( "Total: " DELIM "%s%9u\n"
|
||||||
, "Total: " DELIM "%s%9u\n"
|
, sSeparator2.c_str()
|
||||||
, sSeparator2
|
|
||||||
, pColorTotal
|
, pColorTotal
|
||||||
, static_cast<unsigned int>(nOpcodeTotal) );
|
, static_cast<unsigned int>(nOpcodeTotal) );
|
||||||
pText = ProfileLinePush();
|
prfline = ProfileLinePush();
|
||||||
|
|
||||||
sprintf( pText, "\n" );
|
prfline.Assign( "\n" );
|
||||||
pText = ProfileLinePush();
|
prfline = ProfileLinePush();
|
||||||
|
|
||||||
// Opmode
|
// Opmode
|
||||||
// "Percent Count Adressing Mode\n" );
|
// "Percent Count Adressing Mode\n" );
|
||||||
if (bExport)
|
if (bExport)
|
||||||
// Note: 2 extra dummy columns are inserted to keep Addressing Mode in same column
|
// Note: 2 extra dummy columns are inserted to keep Addressing Mode in same column
|
||||||
sprintf( pText
|
prfline.Format( "\"Percent\"" DELIM "\"Count\"" DELIM DELIM DELIM "\"Addressing Mode\"\n",
|
||||||
, "\"Percent\"" DELIM "\"Count\"" DELIM DELIM DELIM "\"Addressing Mode\"\n"
|
sSeparator7.c_str(), sSeparator2.c_str(), sSeparator2.c_str(), sSeparator2.c_str() );
|
||||||
, sSeparator7, sSeparator2, sSeparator2, sSeparator2 );
|
|
||||||
else
|
else
|
||||||
sprintf( pText
|
prfline.Format( "Percent" DELIM "Count" DELIM "Addressing Mode\n",
|
||||||
, "Percent" DELIM "Count" DELIM "Addressing Mode\n"
|
sSeparator7.c_str(), sSeparator2.c_str() );
|
||||||
, sSeparator7, sSeparator2 );
|
prfline = ProfileLinePush();
|
||||||
pText = ProfileLinePush();
|
|
||||||
|
|
||||||
if (nOpmodeTotal < 1)
|
if (nOpmodeTotal < 1)
|
||||||
{
|
{
|
||||||
|
@ -8025,51 +7953,44 @@ void ProfileFormat( bool bExport, ProfileFormat_e eFormatMode )
|
||||||
int nOpmode = tProfileOpmode.m_iOpmode;
|
int nOpmode = tProfileOpmode.m_iOpmode;
|
||||||
double nPercent = (100. * nCount) / nOpmodeTotal;
|
double nPercent = (100. * nCount) / nOpmodeTotal;
|
||||||
|
|
||||||
if (bExport)
|
const std::string sAddress = (bExport)
|
||||||
{
|
|
||||||
// Note: 2 extra dummy columns are inserted to keep Addressing Mode in same column
|
// Note: 2 extra dummy columns are inserted to keep Addressing Mode in same column
|
||||||
sprintf( sAddress, "%s%s\"%s\"", sSeparator1, sSeparator1, g_aOpmodes[ nOpmode ].m_sName );
|
? StrFormat( "%s%s\"%s\"", sSeparator1.c_str(), sSeparator1.c_str(), g_aOpmodes[ nOpmode ].m_sName )
|
||||||
}
|
// not qouted if dumping to console
|
||||||
else // not qouted if dumping to console
|
: std::string( g_aOpmodes[ nOpmode ].m_sName );
|
||||||
{
|
|
||||||
strcpy( sAddress, g_aOpmodes[ nOpmode ].m_sName );
|
|
||||||
}
|
|
||||||
|
|
||||||
// BUG: Yeah 100% is off by 1 char. Profiling only one opcode isn't worth fixing this visual alignment bug.
|
// BUG: Yeah 100% is off by 1 char. Profiling only one opcode isn't worth fixing this visual alignment bug.
|
||||||
sprintf( pText
|
prfline.Format( "%s%7.4f%s%%" DELIM "%s%9u" DELIM "%s%s\n"
|
||||||
, "%s%7.4f%s%%" DELIM "%s%9u" DELIM "%s%s\n"
|
|
||||||
, pColorNumber
|
, pColorNumber
|
||||||
, nPercent
|
, nPercent
|
||||||
, pColorOperator
|
, pColorOperator
|
||||||
, sSeparator2
|
, sSeparator2.c_str()
|
||||||
, pColorNumber
|
, pColorNumber
|
||||||
, static_cast<unsigned int>(nCount), sSeparator2
|
, static_cast<unsigned int>(nCount), sSeparator2.c_str()
|
||||||
, pColorOpmode
|
, pColorOpmode
|
||||||
, sAddress
|
, sAddress.c_str()
|
||||||
);
|
);
|
||||||
pText = ProfileLinePush();
|
prfline = ProfileLinePush();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! bOpmodeGood)
|
if (! bOpmodeGood)
|
||||||
nOpmodeTotal = 0;
|
nOpmodeTotal = 0;
|
||||||
|
|
||||||
sprintf( pText
|
prfline.Format( "Total: " DELIM "%s%9u\n"
|
||||||
, "Total: " DELIM "%s%9u\n"
|
, sSeparator2.c_str()
|
||||||
, sSeparator2
|
|
||||||
, pColorTotal
|
, pColorTotal
|
||||||
, static_cast<unsigned int>(nOpmodeTotal) );
|
, static_cast<unsigned int>(nOpmodeTotal) );
|
||||||
pText = ProfileLinePush();
|
prfline = ProfileLinePush();
|
||||||
|
|
||||||
sprintf( pText, "===================\n" );
|
prfline.Assign( "===================\n" );
|
||||||
pText = ProfileLinePush();
|
prfline = ProfileLinePush();
|
||||||
|
|
||||||
unsigned int cycles = static_cast<unsigned int>(g_nCumulativeCycles - g_nProfileBeginCycles);
|
unsigned int cycles = static_cast<unsigned int>(g_nCumulativeCycles - g_nProfileBeginCycles);
|
||||||
sprintf( pText
|
prfline.Format( "Cycles: " DELIM "%s%9u\n"
|
||||||
, "Cycles: " DELIM "%s%9u\n"
|
, sSeparator2.c_str()
|
||||||
, sSeparator2
|
|
||||||
, pColorNumber
|
, pColorNumber
|
||||||
, cycles );
|
, cycles );
|
||||||
pText = ProfileLinePush();
|
prfline = ProfileLinePush();
|
||||||
}
|
}
|
||||||
#undef DELIM
|
#undef DELIM
|
||||||
|
|
||||||
|
@ -8108,10 +8029,10 @@ bool ProfileSave()
|
||||||
|
|
||||||
for ( int iLine = 0; iLine < nLine; iLine++ )
|
for ( int iLine = 0; iLine < nLine; iLine++ )
|
||||||
{
|
{
|
||||||
const char *pText = ProfileLinePeek( iLine );
|
ProfileLine_t prfline = ProfileLinePeek( iLine );
|
||||||
if ( pText )
|
if ( prfline.buf )
|
||||||
{
|
{
|
||||||
fputs( pText, hFile );
|
fputs( prfline.buf, hFile );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user