Debugger: Improve some for-loops definitions (PR #1084)

This commit is contained in:
Kelvin Lee 2022-04-17 20:32:03 +10:00 committed by GitHub
parent f948a9491a
commit a5e8ee31a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 95 deletions

View File

@ -786,17 +786,14 @@ Update_t CmdProfile (int nArgs)
// Dump to console // Dump to console
if (iParam == PARAM_LIST) if (iParam == PARAM_LIST)
{ {
char *pText; const int nLine = g_nProfileLine;
char sText[ CONSOLE_WIDTH ];
int nLine = g_nProfileLine; for ( int iLine = 0; iLine < nLine; iLine++ )
int iLine;
for ( iLine = 0; iLine < nLine; iLine++ )
{ {
pText = ProfileLinePeek( iLine ); const char *pText = ProfileLinePeek( iLine );
if (pText) if (pText)
{ {
char sText[ CONSOLE_WIDTH ];
TextConvertTabsToSpaces( sText, pText, CONSOLE_WIDTH, 4 ); TextConvertTabsToSpaces( sText, pText, CONSOLE_WIDTH, 4 );
// ConsoleBufferPush( sText ); // ConsoleBufferPush( sText );
ConsolePrint( sText ); ConsolePrint( sText );
@ -2400,13 +2397,11 @@ bool ConfigSave_BufferToDisk ( const char *pFileName, ConfigSave_t eConfigSave )
if (hFile) if (hFile)
{ {
char *pText; const int nLine = g_ConfigState.GetNumLines();
int nLine = g_ConfigState.GetNumLines();
int iLine;
for ( iLine = 0; iLine < nLine; iLine++ ) for ( int iLine = 0; iLine < nLine; iLine++ )
{ {
pText = g_ConfigState.GetLine( iLine ); const char *pText = g_ConfigState.GetLine( iLine );
if ( pText ) if ( pText )
{ {
fputs( pText, hFile ); fputs( pText, hFile );
@ -2416,9 +2411,6 @@ bool ConfigSave_BufferToDisk ( const char *pFileName, ConfigSave_t eConfigSave )
fclose( hFile ); fclose( hFile );
bStatus = true; bStatus = true;
} }
else
{
}
return bStatus; return bStatus;
} }
@ -3922,8 +3914,7 @@ Update_t CmdMemoryLoad (int nArgs)
size_t nRead = fread( pMemory, nAddressLen, 1, hFile ); size_t nRead = fread( pMemory, nAddressLen, 1, hFile );
if (nRead == 1) // (size_t)nLen) if (nRead == 1) // (size_t)nLen)
{ {
int iByte; for ( int iByte = 0; iByte < nAddressLen; iByte++ )
for ( iByte = 0; iByte < nAddressLen; iByte++ )
{ {
*pDst++ = *pSrc++; *pDst++ = *pSrc++;
} }
@ -4287,8 +4278,7 @@ Update_t CmdMemorySave (int nArgs)
BYTE *pSrc = mem + nAddressStart; BYTE *pSrc = mem + nAddressStart;
// memcpy -- copy out of active memory bank // memcpy -- copy out of active memory bank
int iByte; for ( int iByte = 0; iByte < nAddressLen; iByte++ )
for ( iByte = 0; iByte < nAddressLen; iByte++ )
{ {
*pDst++ = *pSrc++; *pDst++ = *pSrc++;
} }
@ -5848,19 +5838,15 @@ Update_t CmdOutputPrint (int nArgs)
TCHAR sText[ CONSOLE_WIDTH ] = TEXT(""); TCHAR sText[ CONSOLE_WIDTH ] = TEXT("");
int nLen = 0; int nLen = 0;
int nValue;
if (! nArgs) if (! nArgs)
goto _Help; goto _Help;
int iArg; for ( int iArg = 1; iArg <= nArgs; iArg++ )
for (iArg = 1; iArg <= nArgs; iArg++ )
{ {
if (g_aArgs[ iArg ].bType & TYPE_QUOTED_2) if (g_aArgs[ iArg ].bType & TYPE_QUOTED_2)
{ {
int iChar; const int nChar = _tcslen( g_aArgs[ iArg ].sArg );
int nChar = _tcslen( g_aArgs[ iArg ].sArg ); for ( int iChar = 0; iChar < nChar; iChar++ )
for ( iChar = 0; iChar < nChar; iChar++ )
{ {
TCHAR c = g_aArgs[ iArg ].sArg[ iChar ]; TCHAR c = g_aArgs[ iArg ].sArg[ iChar ];
sText[ nLen++ ] = c; sText[ nLen++ ] = c;
@ -5875,7 +5861,7 @@ Update_t CmdOutputPrint (int nArgs)
} }
else else
{ {
nValue = g_aArgs[ iArg ].nValue; const int nValue = g_aArgs[ iArg ].nValue;
sprintf( &sText[ nLen ], "%04X", nValue ); sprintf( &sText[ nLen ], "%04X", nValue );
while (sText[ nLen ]) while (sText[ nLen ])
@ -5885,12 +5871,12 @@ Update_t CmdOutputPrint (int nArgs)
if (iArg <= nArgs) if (iArg <= nArgs)
if (g_aArgs[ iArg ].eToken != TOKEN_COMMA) if (g_aArgs[ iArg ].eToken != TOKEN_COMMA)
goto _Help; goto _Help;
}
#if 0 #if 0
sprintf( &sText[ nLen ], "%04X", nValue ); sprintf( &sText[ nLen ], "%04X", nValue );
sprintf( &sText[ nLen ], "%d", nValue ); sprintf( &sText[ nLen ], "%d", nValue );
sprintf( &sText[ nLen ], "%c", nValue ); sprintf( &sText[ nLen ], "%c", nValue );
#endif #endif
}
} }
if (nLen) if (nLen)
@ -5909,24 +5895,12 @@ Update_t CmdOutputPrintf (int nArgs)
// PRINTF "A:%d X:%d",A,X // PRINTF "A:%d X:%d",A,X
// PRINTF "Hex:%x Dec:%d Bin:%z",A,A,A // PRINTF "Hex:%x Dec:%d Bin:%z",A,A,A
TCHAR sText[ CONSOLE_WIDTH ] = TEXT("");
std::vector<Arg_t> aValues;
Arg_t entry;
int iValue = 0;
int nValue = 0;
if (! nArgs) if (! nArgs)
return Help_Arg_1( CMD_OUTPUT_PRINTF ); return Help_Arg_1( CMD_OUTPUT_PRINTF );
int nLen = 0; std::vector<Arg_t> aValues;
PrintState_e eThis = PS_LITERAL; for ( int iArg = 1; iArg <= nArgs; iArg++ )
int nWidth = 0;
int iArg;
for (iArg = 1; iArg <= nArgs; iArg++ )
{ {
if (g_aArgs[ iArg ].bType & TYPE_QUOTED_2) if (g_aArgs[ iArg ].bType & TYPE_QUOTED_2)
continue; continue;
@ -5935,19 +5909,27 @@ Update_t CmdOutputPrintf (int nArgs)
continue; continue;
else else
{ {
Arg_t entry;
entry.nValue = g_aArgs[ iArg ].nValue; entry.nValue = g_aArgs[ iArg ].nValue;
aValues.push_back( entry ); aValues.push_back( entry );
} }
} }
const int nParamValues = (int) aValues.size();
for (iArg = 1; iArg <= nArgs; iArg++ ) TCHAR sText[ CONSOLE_WIDTH ] = TEXT("");
int nLen = 0;
PrintState_e eThis = PS_LITERAL;
int nWidth = 0;
const size_t nParamValues = aValues.size();
size_t iValue = 0;
for ( int iArg = 1; iArg <= nArgs; iArg++ )
{ {
if (g_aArgs[ iArg ].bType & TYPE_QUOTED_2) if (g_aArgs[ iArg ].bType & TYPE_QUOTED_2)
{ {
int iChar; const int nChar = _tcslen( g_aArgs[ iArg ].sArg );
int nChar = _tcslen( g_aArgs[ iArg ].sArg ); for ( int iChar = 0; iChar < nChar; iChar++ )
for ( iChar = 0; iChar < nChar; iChar++ )
{ {
TCHAR c = g_aArgs[ iArg ].sArg[ iChar ]; TCHAR c = g_aArgs[ iArg ].sArg[ iChar ];
switch ( eThis ) switch ( eThis )
@ -5979,44 +5961,38 @@ Update_t CmdOutputPrintf (int nArgs)
case PS_TYPE: case PS_TYPE:
if (iValue >= nParamValues) if (iValue >= nParamValues)
{ {
ConsoleBufferPushFormat( "Error: Missing value arg: %d", iValue + 1 ); ConsoleBufferPushFormat( "Error: Missing value arg: %" SIZE_T_FMT, iValue + 1 );
return ConsoleUpdate(); return ConsoleUpdate();
} }
switch ( c ) switch ( c )
{ {
case 'X': case 'X':
case 'x': // PS_NEXT_ARG_HEX case 'x': // PS_NEXT_ARG_HEX
nValue = aValues[ iValue ].nValue; sprintf( &sText[ nLen ], "%04X", aValues[ iValue ].nValue );
sprintf( &sText[ nLen ], "%04X", nValue );
iValue++; iValue++;
break; break;
case 'D': case 'D':
case 'd': // PS_NEXT_ARG_DEC case 'd': // PS_NEXT_ARG_DEC
nValue = aValues[ iValue ].nValue; sprintf( &sText[ nLen ], "%d", aValues[ iValue ].nValue );
sprintf( &sText[ nLen ], "%d", nValue );
iValue++; iValue++;
break; break;
break; break;
case 'Z': case 'Z':
case 'z': case 'z':
{ {
nValue = aValues[ iValue ].nValue; const int nValue = aValues[ iValue ].nValue;
if (!nWidth) if (!nWidth)
nWidth = 8; nWidth = 8;
int nBits = nWidth; int nBits = nWidth;
while (nBits-- > 0) while (nBits-- > 0)
{ {
if ((nValue >> nBits) & 1) sText[ nLen++ ] = ((nValue >> nBits) & 1) ? '1' : '0';
sText[ nLen++ ] = '1';
else
sText[ nLen++ ] = '0';
} }
iValue++; iValue++;
break; break;
} }
case 'c': // PS_NEXT_ARG_CHR; case 'c': // PS_NEXT_ARG_CHR;
nValue = aValues[ iValue ].nValue; sprintf( &sText[ nLen ], "%c", aValues[ iValue ].nValue );
sprintf( &sText[ nLen ], "%c", nValue );
iValue++; iValue++;
break; break;
case '%': case '%':
@ -7892,10 +7868,6 @@ void ProfileFormat( bool bExport, ProfileFormat_e eFormatMode )
} }
ProfileLineReset(); ProfileLineReset();
char *pText = ProfileLinePeek( 0 );
int iOpcode;
int iOpmode;
bool bOpcodeGood = true; bool bOpcodeGood = true;
bool bOpmodeGood = true; bool bOpmodeGood = true;
@ -7910,12 +7882,12 @@ void ProfileFormat( bool bExport, ProfileFormat_e eFormatMode )
Profile_t nOpcodeTotal = 0; Profile_t nOpcodeTotal = 0;
Profile_t nOpmodeTotal = 0; Profile_t nOpmodeTotal = 0;
for (iOpcode = 0; iOpcode < NUM_OPCODES; ++iOpcode ) for ( int iOpcode = 0; iOpcode < NUM_OPCODES; ++iOpcode )
{ {
nOpcodeTotal += vProfileOpcode[ iOpcode ].m_nCount; nOpcodeTotal += vProfileOpcode[ iOpcode ].m_nCount;
} }
for (iOpmode = 0; iOpmode < NUM_OPMODES; ++iOpmode ) for ( int iOpmode = 0; iOpmode < NUM_OPMODES; ++iOpmode )
{ {
nOpmodeTotal += vProfileOpmode[ iOpmode ].m_nCount; nOpmodeTotal += vProfileOpmode[ iOpmode ].m_nCount;
} }
@ -7942,6 +7914,8 @@ void ProfileFormat( bool bExport, ProfileFormat_e eFormatMode )
pColorTotal = CHC_DEFAULT; // white pColorTotal = CHC_DEFAULT; // white
} }
char *pText = ProfileLinePeek( 0 );
// Opcode // Opcode
if (bExport) // Export = SeperateColumns if (bExport) // Export = SeperateColumns
sprintf( pText sprintf( pText
@ -7951,10 +7925,9 @@ void ProfileFormat( bool bExport, ProfileFormat_e eFormatMode )
sprintf( pText sprintf( pText
, "Percent" DELIM "Count" DELIM "Mnemonic" DELIM "Addressing Mode\n" , "Percent" DELIM "Count" DELIM "Mnemonic" DELIM "Addressing Mode\n"
, sSeparator7, sSeparator2, sSeparator1 ); , sSeparator7, sSeparator2, sSeparator1 );
pText = ProfileLinePush(); pText = ProfileLinePush();
for (iOpcode = 0; iOpcode < NUM_OPCODES; ++iOpcode ) for ( int iOpcode = 0; iOpcode < NUM_OPCODES; ++iOpcode )
{ {
ProfileOpcode_t tProfileOpcode = vProfileOpcode.at( iOpcode ); ProfileOpcode_t tProfileOpcode = vProfileOpcode.at( iOpcode );
@ -8032,11 +8005,9 @@ void ProfileFormat( bool bExport, ProfileFormat_e eFormatMode )
, "\"Percent\"" DELIM "\"Count\"" DELIM DELIM DELIM "\"Addressing Mode\"\n" , "\"Percent\"" DELIM "\"Count\"" DELIM DELIM DELIM "\"Addressing Mode\"\n"
, sSeparator7, sSeparator2, sSeparator2, sSeparator2 ); , sSeparator7, sSeparator2, sSeparator2, sSeparator2 );
else else
{
sprintf( pText sprintf( pText
, "Percent" DELIM "Count" DELIM "Addressing Mode\n" , "Percent" DELIM "Count" DELIM "Addressing Mode\n"
, sSeparator7, sSeparator2 ); , sSeparator7, sSeparator2 );
}
pText = ProfileLinePush(); pText = ProfileLinePush();
if (nOpmodeTotal < 1) if (nOpmodeTotal < 1)
@ -8045,7 +8016,7 @@ void ProfileFormat( bool bExport, ProfileFormat_e eFormatMode )
bOpmodeGood = false; bOpmodeGood = false;
} }
for (iOpmode = 0; iOpmode < NUM_OPMODES; ++iOpmode ) for ( int iOpmode = 0; iOpmode < NUM_OPMODES; ++iOpmode )
{ {
ProfileOpmode_t tProfileOpmode = vProfileOpmode.at( iOpmode ); ProfileOpmode_t tProfileOpmode = vProfileOpmode.at( iOpmode );
Profile_t nCount = tProfileOpmode.m_nCount; Profile_t nCount = tProfileOpmode.m_nCount;
@ -8109,16 +8080,13 @@ void ProfileFormat( bool bExport, ProfileFormat_e eFormatMode )
//=========================================================================== //===========================================================================
void ProfileReset() void ProfileReset()
{ {
int iOpcode; for ( int iOpcode = 0; iOpcode < NUM_OPCODES; iOpcode++ )
int iOpmode;
for (iOpcode = 0; iOpcode < NUM_OPCODES; iOpcode++ )
{ {
g_aProfileOpcodes[ iOpcode ].m_iOpcode = iOpcode; g_aProfileOpcodes[ iOpcode ].m_iOpcode = iOpcode;
g_aProfileOpcodes[ iOpcode ].m_nCount = 0; g_aProfileOpcodes[ iOpcode ].m_nCount = 0;
} }
for (iOpmode = 0; iOpmode < NUM_OPMODES; iOpmode++ ) for ( int iOpmode = 0; iOpmode < NUM_OPMODES; iOpmode++ )
{ {
g_aProfileOpmodes[ iOpmode ].m_iOpmode = iOpmode; g_aProfileOpmodes[ iOpmode ].m_iOpmode = iOpmode;
g_aProfileOpmodes[ iOpmode ].m_nCount = 0; g_aProfileOpmodes[ iOpmode ].m_nCount = 0;
@ -8139,13 +8107,11 @@ bool ProfileSave()
if (hFile) if (hFile)
{ {
char *pText; const int nLine = g_nProfileLine;
int nLine = g_nProfileLine;
int iLine; for ( int iLine = 0; iLine < nLine; iLine++ )
for ( iLine = 0; iLine < nLine; iLine++ )
{ {
pText = ProfileLinePeek( iLine ); const char *pText = ProfileLinePeek( iLine );
if ( pText ) if ( pText )
{ {
fputs( pText, hFile ); fputs( pText, hFile );

View File

@ -3086,13 +3086,11 @@ void DrawSubWindow_Data (Update_t bUpdate)
RECT rect; RECT rect;
rect.top = 0 + 0; rect.top = 0 + 0;
int iByte;
WORD iAddress = nAddress; WORD iAddress = nAddress;
int iLine; const int nLines = g_nDisasmWinHeight;
int nLines = g_nDisasmWinHeight;
for (iLine = 0; iLine < nLines; iLine++ ) for ( int iLine = 0; iLine < nLines; iLine++ )
{ {
iAddress = nAddress; iAddress = nAddress;
@ -3100,7 +3098,7 @@ void DrawSubWindow_Data (Update_t bUpdate)
sprintf( sAddress, "%04X", iAddress ); sprintf( sAddress, "%04X", iAddress );
sOpcodes[0] = 0; sOpcodes[0] = 0;
for ( iByte = 0; iByte < nMaxOpcodes; iByte++ ) for ( int iByte = 0; iByte < nMaxOpcodes; iByte++ )
{ {
BYTE nData = (unsigned)*(LPBYTE)(mem + iAddress + iByte); BYTE nData = (unsigned)*(LPBYTE)(mem + iAddress + iByte);
sprintf( &sOpcodes[ iByte * 3 ], "%02X ", nData ); sprintf( &sOpcodes[ iByte * 3 ], "%02X ", nData );
@ -3151,7 +3149,7 @@ void DrawSubWindow_Data (Update_t bUpdate)
eView = MEM_VIEW_ASCII; eView = MEM_VIEW_ASCII;
iAddress = nAddress; iAddress = nAddress;
for (iByte = 0; iByte < nMaxOpcodes; iByte++ ) for ( int iByte = 0; iByte < nMaxOpcodes; iByte++ )
{ {
BYTE nImmediate = (unsigned)*(LPBYTE)(mem + iAddress); BYTE nImmediate = (unsigned)*(LPBYTE)(mem + iAddress);
/*int iTextBackground = iBackground; /*int iTextBackground = iBackground;
@ -3168,7 +3166,7 @@ void DrawSubWindow_Data (Update_t bUpdate)
/* /*
// Colorized Text // Colorized Text
iAddress = nAddress; iAddress = nAddress;
for (iByte = 0; iByte < nMaxOpcodes; iByte++ ) for ( int iByte = 0; iByte < nMaxOpcodes; iByte++ )
{ {
BYTE nImmediate = (unsigned)*(LPBYTE)(membank + iAddress); BYTE nImmediate = (unsigned)*(LPBYTE)(membank + iAddress);
int iTextBackground = iBackground; // BG_INFO_CHAR; int iTextBackground = iBackground; // BG_INFO_CHAR;
@ -3416,7 +3414,7 @@ void DrawSubWindow_Source2 (Update_t bUpdate)
DebuggerSetColorFG( DebuggerGetColor( FG_SOURCE )); DebuggerSetColorFG( DebuggerGetColor( FG_SOURCE ));
int nLines = g_nDisasmWinHeight; const int nLines = g_nDisasmWinHeight;
int y = g_nDisasmWinHeight; int y = g_nDisasmWinHeight;
int nHeight = g_nDisasmWinHeight; int nHeight = g_nDisasmWinHeight;

View File

@ -333,9 +333,7 @@ Update_t CmdSymbolsInfo (int nArgs)
//sprintf( sText, " Symbols Main: %s%d%s User: %s%d%s Source: %s%d%s" //sprintf( sText, " Symbols Main: %s%d%s User: %s%d%s Source: %s%d%s"
// "Main:# Basic:# Asm:# User1:# User2:# Src1:# Src2:# Dos:# Prodos:# // "Main:# Basic:# Asm:# User1:# User2:# Src1:# Src2:# Dos:# Prodos:#
int bTable = 1; for ( int iTable = 0, bTable = 1; bTable <= bDisplaySymbolTables; iTable++, bTable <<= 1 )
int iTable = 0;
for ( ; bTable <= bDisplaySymbolTables; iTable++, bTable <<= 1 )
{ {
if ( bDisplaySymbolTables & bTable ) if ( bDisplaySymbolTables & bTable )
{ {