Added variadic variants of ConsolePrint(), ConsoleBufferPush() to make code cleaner. Also added ConsoleColorizePrint() and variants.

This commit is contained in:
Kelvin Lee 2016-09-10 22:46:09 +10:00 committed by tomcw
parent 5e59f11625
commit 0992cf16c4
7 changed files with 416 additions and 480 deletions

View File

@ -678,8 +678,7 @@ Update_t CmdBookmarkList (int nArgs)
if (! g_nBookmarks)
{
TCHAR sText[ CONSOLE_WIDTH ];
wsprintf( sText, TEXT(" There are no current bookmarks. (Max: %d)"), MAX_BOOKMARKS );
ConsoleBufferPush( sText );
ConsoleBufferPushFormat( sText, TEXT(" There are no current bookmarks. (Max: %d)"), MAX_BOOKMARKS );
}
else
{
@ -862,8 +861,7 @@ Update_t CmdProfile (int nArgs)
if (ProfileSave())
{
TCHAR sText[ CONSOLE_WIDTH ];
wsprintf( sText, " Saved: %s", g_FileNameProfile );
ConsoleBufferPush( sText );
ConsoleBufferPushFormat ( sText, " Saved: %s", g_FileNameProfile );
}
else
ConsoleBufferPush( TEXT(" ERROR: Couldn't save file. (In use?)" ) );
@ -946,10 +944,9 @@ Update_t CmdBreakInvalid (int nArgs) // Breakpoint IFF Full-speed!
}
if (iType == 0)
wsprintf( sText, TEXT("Enter debugger on BRK opcode: %s"), g_aParameters[ iParam ].m_sName );
ConsoleBufferPushFormat( sText, TEXT("Enter debugger on BRK opcode: %s"), g_aParameters[ iParam ].m_sName );
else
wsprintf( sText, TEXT("Enter debugger on INVALID %1X opcode: %s"), iType, g_aParameters[ iParam ].m_sName );
ConsoleBufferPush( sText );
ConsoleBufferPushFormat( sText, TEXT("Enter debugger on INVALID %1X opcode: %s"), iType, g_aParameters[ iParam ].m_sName );
return ConsoleUpdate();
}
else
@ -967,10 +964,9 @@ Update_t CmdBreakInvalid (int nArgs) // Breakpoint IFF Full-speed!
SetDebugBreakOnInvalid( iType, nActive );
if (iType == 0)
wsprintf( sText, TEXT("Enter debugger on BRK opcode: %s"), g_aParameters[ iParam ].m_sName );
ConsoleBufferPushFormat( sText, TEXT("Enter debugger on BRK opcode: %s"), g_aParameters[ iParam ].m_sName );
else
wsprintf( sText, TEXT("Enter debugger on INVALID %1X opcode: %s"), iType, g_aParameters[ iParam ].m_sName );
ConsoleBufferPush( sText );
ConsoleBufferPushFormat( sText, TEXT("Enter debugger on INVALID %1X opcode: %s"), iType, g_aParameters[ iParam ].m_sName );
return ConsoleUpdate();
}
}
@ -1001,26 +997,24 @@ Update_t CmdBreakOpcode (int nArgs) // Breakpoint IFF Full-speed!
if (iOpcode >= NUM_OPCODES)
{
wsprintf( sText, TEXT("Warning: clamping opcode: %02X"), g_iDebugBreakOnOpcode );
ConsoleBufferPush( sText );
ConsoleBufferPushFormat( sText, TEXT("Warning: clamping opcode: %02X"), g_iDebugBreakOnOpcode );
return ConsoleUpdate();
}
}
if (g_iDebugBreakOnOpcode == 0)
// Show what the current break opcode is
wsprintf( sText, TEXT("%s full speed Break on Opcode: None")
ConsoleBufferPushFormat( sText, TEXT("%s full speed Break on Opcode: None")
, sAction
);
else
// Show what the current break opcode is
wsprintf( sText, TEXT("%s full speed Break on Opcode: %02X %s")
ConsoleBufferPushFormat( sText, TEXT("%s full speed Break on Opcode: %02X %s")
, sAction
, g_iDebugBreakOnOpcode
, g_aOpcodes65C02[ g_iDebugBreakOnOpcode ].sMnemonic
);
ConsoleBufferPush( sText );
return ConsoleUpdate();
}
@ -1595,7 +1589,7 @@ Update_t CmdBreakpointClear (int nArgs)
_BWZ_ClearViaArgs( nArgs, g_aBreakpoints, MAX_BREAKPOINTS, g_nBreakpoints );
}
return UPDATE_DISASM | UPDATE_BREAKPOINTS | UPDATE_CONSOLE_DISPLAY;
return UPDATE_DISASM | UPDATE_BREAKPOINTS | UPDATE_CONSOLE_DISPLAY;
}
//===========================================================================
@ -1648,14 +1642,13 @@ void _BWZ_List( const Breakpoint_t * aBreakWatchZero, const int iBWZ ) //, bool
pSymbol = sName;
}
sprintf( sText, " #%d %c %04X %s",
ConsoleBufferPushFormat( sText, " #%d %c %04X %s",
// (bZeroBased ? iBWZ + 1 : iBWZ),
iBWZ,
sFlags[ (int) aBreakWatchZero[ iBWZ ].bEnabled ],
aBreakWatchZero[ iBWZ ].nAddress,
pSymbol
);
ConsoleBufferPush( sText );
}
void _BWZ_ListAll( const Breakpoint_t * aBreakWatchZero, const int nMax )
@ -1690,8 +1683,7 @@ Update_t CmdBreakpointList (int nArgs)
if (! g_nBreakpoints)
{
TCHAR sText[ CONSOLE_WIDTH ];
wsprintf( sText, TEXT(" There are no current breakpoints. (Max: %d)"), MAX_BREAKPOINTS );
ConsoleBufferPush( sText );
ConsoleBufferPushFormat( sText, TEXT(" There are no current breakpoints. (Max: %d)"), MAX_BREAKPOINTS );
}
else
{
@ -1912,9 +1904,8 @@ Update_t CmdGo (int nArgs)
#if _DEBUG
TCHAR sText[ CONSOLE_WIDTH ];
wsprintf( sText, TEXT("Start: %04X,%04X End: %04X Len: %04X"),
ConsoleBufferPushFormat( sText, TEXT("Start: %04X,%04X End: %04X Len: %04X"),
g_nDebugSkipStart, g_nDebugSkipLen, nEnd, nLen );
ConsoleBufferPush( sText );
ConsoleBufferToDisplay();
#endif
}
@ -2002,7 +1993,7 @@ Update_t CmdTraceFile (int nArgs)
fclose( g_hTraceFile );
g_hTraceFile = NULL;
_snprintf( sText, sizeof(sText), "Trace stopped." );
ConsoleBufferPush( "Trace stopped." );
}
else
{
@ -2023,20 +2014,17 @@ Update_t CmdTraceFile (int nArgs)
if (g_hTraceFile)
{
char* pTextHdr = g_bTraceFileWithVideoScanner ? "Trace (with video info) started: %s"
: "Trace started: %s";
_snprintf( sText, sizeof(sText), pTextHdr, sFilePath );
const char* pTextHdr = g_bTraceFileWithVideoScanner ? "Trace (with video info) started: %s"
: "Trace started: %s";
ConsoleBufferPushFormat( sText, pTextHdr, sFilePath );
g_bTraceHeader = true;
}
else
{
_snprintf( sText, sizeof(sText), "Trace ERROR: %s", sFilePath );
ConsoleBufferPushFormat( sText, "Trace ERROR: %s", sFilePath );
}
}
sText[sizeof(sText)-1] = 0; // _snprintf needs null if string was longer than buffer
ConsoleBufferPush( sText );
ConsoleBufferToDisplay();
return UPDATE_ALL; // TODO: Verify // 0
@ -2169,8 +2157,7 @@ void _ColorPrint( int iColor, COLORREF nColor )
int B = (nColor >> 16) & 0xFF;
TCHAR sText[ CONSOLE_WIDTH ];
wsprintf( sText, " Color %01X: %02X %02X %02X", iColor, R, G, B ); // TODO: print name of colors!
ConsoleBufferPush( sText );
ConsoleBufferPushFormat( sText, " Color %01X: %02X %02X %02X", iColor, R, G, B ); // TODO: print name of colors!
}
void _CmdColorGet( const int iScheme, const int iColor )
@ -2488,8 +2475,7 @@ Update_t CmdConfigDisasm( int nArgs )
}
else // show current setting
{
wsprintf( sText, TEXT( "Branch Type: %d" ), g_iConfigDisasmBranchType );
ConsoleBufferPush( sText );
ConsoleBufferPushFormat( sText, TEXT( "Branch Type: %d" ), g_iConfigDisasmBranchType );
ConsoleBufferToDisplay();
}
break;
@ -2503,8 +2489,7 @@ Update_t CmdConfigDisasm( int nArgs )
else // show current setting
{
int iState = g_bConfigDisasmAddressColon ? PARAM_ON : PARAM_OFF;
wsprintf( sText, TEXT( "Colon: %s" ), g_aParameters[ iState ].m_sName );
ConsoleBufferPush( sText );
ConsoleBufferPushFormat( sText, TEXT( "Colon: %s" ), g_aParameters[ iState ].m_sName );
ConsoleBufferToDisplay();
}
break;
@ -2518,8 +2503,7 @@ Update_t CmdConfigDisasm( int nArgs )
else
{
int iState = g_bConfigDisasmOpcodesView ? PARAM_ON : PARAM_OFF;
wsprintf( sText, TEXT( "Opcodes: %s" ), g_aParameters[ iState ].m_sName );
ConsoleBufferPush( sText );
ConsoleBufferPushFormat( sText, TEXT( "Opcodes: %s" ), g_aParameters[ iState ].m_sName );
ConsoleBufferToDisplay();
}
break;
@ -2533,8 +2517,7 @@ Update_t CmdConfigDisasm( int nArgs )
else
{
int iState = g_bConfigInfoTargetPointer ? PARAM_ON : PARAM_OFF;
wsprintf( sText, TEXT( "Info Target Pointer: %s" ), g_aParameters[ iState ].m_sName );
ConsoleBufferPush( sText );
ConsoleBufferPushFormat( sText, TEXT( "Info Target Pointer: %s" ), g_aParameters[ iState ].m_sName );
ConsoleBufferToDisplay();
}
break;
@ -2548,8 +2531,7 @@ Update_t CmdConfigDisasm( int nArgs )
else
{
int iState = g_bConfigDisasmOpcodeSpaces ? PARAM_ON : PARAM_OFF;
wsprintf( sText, TEXT( "Opcode spaces: %s" ), g_aParameters[ iState ].m_sName );
ConsoleBufferPush( sText );
ConsoleBufferPushFormat( sText, TEXT( "Opcode spaces: %s" ), g_aParameters[ iState ].m_sName );
ConsoleBufferToDisplay();
}
break;
@ -2566,8 +2548,7 @@ Update_t CmdConfigDisasm( int nArgs )
}
else // show current setting
{
wsprintf( sText, TEXT( "Target: %d" ), g_iConfigDisasmTargets );
ConsoleBufferPush( sText );
ConsoleBufferPushFormat( sText, TEXT( "Target: %d" ), g_iConfigDisasmTargets );
ConsoleBufferToDisplay();
}
break;
@ -2634,11 +2615,10 @@ Update_t CmdConfigFont (int nArgs)
(! _tcscmp( g_aArgs[ iArg ].sArg, g_aParameters[ PARAM_MEM_SEARCH_WILD ].m_sName )) )
{
TCHAR sText[ CONSOLE_WIDTH ];
wsprintf( sText, "Lines: %d Font Px: %d Line Px: %d"
ConsoleBufferPushFormat( sText, "Lines: %d Font Px: %d Line Px: %d"
, g_nDisasmDisplayLines
, g_aFontConfig[ FONT_DISASM_DEFAULT ]._nFontHeight
, g_aFontConfig[ FONT_DISASM_DEFAULT ]._nLineHeight );
ConsoleBufferPush( sText );
ConsoleBufferToDisplay();
return UPDATE_CONSOLE_DISPLAY;
}
@ -2886,12 +2866,11 @@ Update_t CmdConfigGetFont (int nArgs)
for (int iFont = 0; iFont < NUM_FONTS; iFont++ )
{
TCHAR sText[ CONSOLE_WIDTH ] = TEXT("");
wsprintf( sText, " Font: %-20s A:%2d M:%2d",
ConsoleBufferPushFormat( sText, " Font: %-20s A:%2d M:%2d",
// g_sFontNameCustom, g_nFontWidthAvg, g_nFontWidthMax );
g_aFontConfig[ iFont ]._sFontName,
g_aFontConfig[ iFont ]._nFontWidthAvg,
g_aFontConfig[ iFont ]._nFontWidthMax );
ConsoleBufferPush( sText );
}
return ConsoleUpdate();
}
@ -3695,7 +3674,7 @@ Update_t CmdDisk ( int nArgs)
int drive = DiskGetCurrentDrive() + 1;
char buffer[200] = "";
sprintf_s(buffer, sizeof(buffer), "D%d at T$%X (%d), phase $%X, offset $%X, %s",
ConsoleBufferPushFormat(buffer, "D%d at T$%X (%d), phase $%X, offset $%X, %s",
drive,
DiskGetCurrentTrack(),
DiskGetCurrentTrack(),
@ -3703,7 +3682,6 @@ Update_t CmdDisk ( int nArgs)
DiskGetCurrentOffset(),
DiskGetCurrentState());
ConsoleBufferPush(buffer);
return ConsoleUpdate();
}
@ -4081,9 +4059,9 @@ static TCHAR g_sMemoryLoadSaveFileName[ MAX_PATH ] = TEXT("");
//===========================================================================
Update_t CmdConfigGetDebugDir (int nArgs)
{
TCHAR sPath[ MAX_PATH + 8 ] = "Path: ";
_tcscat( sPath, g_sCurrentDir ); // TODO: debugger dir has no ` CONSOLE_COLOR_ESCAPE_CHAR ?!?!
ConsoleBufferPush( sPath );
TCHAR sPath[ MAX_PATH + 8 ];
// TODO: debugger dir has no ` CONSOLE_COLOR_ESCAPE_CHAR ?!?!
ConsoleBufferPushFormat( sPath, "Path: %s", g_sCurrentDir );
return ConsoleUpdate();
}
@ -4224,9 +4202,8 @@ Update_t CmdMemoryLoad (int nArgs)
CmdConfigGetDebugDir( 0 );
TCHAR sFile[ MAX_PATH + 8 ] = "File: ";
_tcscat( sFile, g_sMemoryLoadSaveFileName );
ConsoleBufferPush( sFile );
TCHAR sFile[ MAX_PATH + 8 ];
ConsoleBufferPushFormat( sFile, "File: %s", g_sMemoryLoadSaveFileName );
}
delete [] pMemory;
@ -4410,8 +4387,7 @@ Update_t CmdMemoryLoad (int nArgs)
if (nRead == 1)
{
char text[ 128 ];
sprintf( text, "Loaded @ A$%04X,L$%04X", nAddressStart, nAddressLen );
ConsoleBufferPush( text );
ConsoleBufferPushFormat( text, "Loaded @ A$%04X,L$%04X", nAddressStart, nAddressLen );
}
else
{
@ -4437,9 +4413,8 @@ Update_t CmdMemoryLoad (int nArgs)
CmdConfigGetDebugDir( 0 );
TCHAR sFile[ MAX_PATH + 8 ] = "File: ";
_tcscat( sFile, g_sMemoryLoadSaveFileName );
ConsoleBufferPush( sFile );
TCHAR sFile[ MAX_PATH + 8 ];
ConsoleBufferPushFormat( sFile, "File: ", g_sMemoryLoadSaveFileName );
}
return ConsoleUpdate();
@ -4517,14 +4492,13 @@ Update_t CmdMemorySave (int nArgs)
TCHAR sLast[ CONSOLE_WIDTH ] = TEXT("");
if (nAddressLen)
{
wsprintf( sLast, TEXT("Last saved: $%04X:$%04X, %04X"),
ConsoleBufferPushFormat( sLast, TEXT("Last saved: $%04X:$%04X, %04X"),
nAddressStart, nAddressEnd, nAddressLen );
}
else
{
wsprintf( sLast, TEXT( "Last saved: none" ) );
ConsoleBufferPush( sLast, TEXT( "Last saved: none" ) );
}
ConsoleBufferPush( sLast );
}
else
{
@ -4647,17 +4621,16 @@ Update_t CmdMemorySave (int nArgs)
if (nAddressLen)
{
if (!bBankSpecified)
wsprintf( sLast, TEXT("Last saved: $%04X:$%04X, %04X"),
ConsoleBufferPushFormat( sLast, TEXT("Last saved: $%04X:$%04X, %04X"),
nAddressStart, nAddressEnd, nAddressLen );
else
wsprintf( sLast, TEXT("Last saved: Bank=%02X $%04X:$%04X, %04X"),
ConsoleBufferPushFormat( sLast, TEXT("Last saved: Bank=%02X $%04X:$%04X, %04X"),
nBank, nAddressStart, nAddressEnd, nAddressLen );
}
else
{
wsprintf( sLast, TEXT( "Last saved: none" ) );
ConsoleBufferPush( TEXT( "Last saved: none" ) );
}
ConsoleBufferPush( sLast );
}
else
{
@ -5017,7 +4990,7 @@ Update_t CmdNTSC (int nArgs)
if (len >= CONSOLE_WIDTH)
{
ConsoleBufferPush( pPrefixText );
ConsoleBufferPush( pPrefixText ); // TODO: Add a ": " separator
#if _DEBUG
sprintf( text, "Filename.length.1: %d\n", len1 );
@ -5029,10 +5002,12 @@ Update_t CmdNTSC (int nArgs)
// File path is too long
// TODO: Need to split very long path names
strncpy( text, sPaletteFilePath, CONSOLE_WIDTH );
ConsoleBufferPush( text ); // TODO: Switch ConsoleBufferPush() to ConsoleBufferPushFormat()
}
else
sprintf( text, "%s: %s", pPrefixText, sPaletteFilePath );
ConsoleBufferPush( text ); // "Saved."
{
ConsoleBufferPushFormat( text, "%s: %s", pPrefixText, sPaletteFilePath );
}
}
};
@ -5600,8 +5575,7 @@ int CmdTextSave (int nArgs)
if (nWrote == 1)
{
TCHAR text[ CONSOLE_WIDTH ] = TEXT("");
sprintf( text, "Saved: %s", g_sMemoryLoadSaveFileName );
ConsoleBufferPush( text ); // "Saved."
ConsoleBufferPushFormat( text, "Saved: %s", g_sMemoryLoadSaveFileName );
}
else
{
@ -6032,7 +6006,7 @@ Update_t CmdMemorySearchHex (int nArgs)
Update_t CmdRegisterSet (int nArgs)
{
if ((nArgs == 2) &&
(g_aArgs[1].sArg[0] == TEXT('P')) && (g_aArgs[2].sArg[0] == TEXT('L'))) //HACK: TODO/FIXME: undocumented hard-coded command?!?!
(g_aArgs[1].sArg[0] == TEXT('P')) && (g_aArgs[2].sArg[0] == TEXT('L'))) //HACK: TODO/FIXME: undocumented hard-coded command?!?!
{
regs.pc = lastpc;
}
@ -6309,8 +6283,7 @@ Update_t CmdOutputPrintf (int nArgs)
case PS_TYPE:
if (iValue >= nParamValues)
{
wsprintf( sText, TEXT("Error: Missing value arg: %d"), iValue + 1 );
ConsoleBufferPush( sText );
ConsoleBufferPushFormat( sText, TEXT("Error: Missing value arg: %d"), iValue + 1 );
return ConsoleUpdate();
}
switch( c )
@ -6441,12 +6414,11 @@ Update_t CmdOutputRun (int nArgs)
else
{
char sText[ CONSOLE_WIDTH ];
sprintf( sText, "%sCouldn't load filename: %s%s"
ConsolePrintFormat( sText, "%sCouldn't load filename: %s%s"
, CHC_ERROR
, CHC_STRING
, sFileName
);
ConsolePrint( sText );
}
return ConsoleUpdate();
@ -6709,28 +6681,27 @@ Update_t CmdSource (int nArgs)
if (! ParseAssemblyListing( g_bSourceAddMemory, g_bSourceAddSymbols ))
{
wsprintf( sFileName, "Couldn't load filename: %s", sMiniFileName );
ConsoleBufferPush( sFileName );
ConsoleBufferPushFormat( sFileName, "Couldn't load filename: %s", sMiniFileName );
}
else
{
TCHAR sText[ CONSOLE_WIDTH ];
wsprintf( sFileName, " Read: %d lines, %d symbols"
, g_AssemblerSourceBuffer.GetNumLines() // g_nSourceAssemblyLines
, g_nSourceAssemblySymbols );
if (g_nSourceAssembleBytes)
{
wsprintf( sText, ", %d bytes", g_nSourceAssembleBytes );
_tcscat( sFileName, sText );
ConsoleBufferPushFormat( sFileName, " Read: %d lines, %d symbols, %d bytes"
, g_AssemblerSourceBuffer.GetNumLines() // g_nSourceAssemblyLines
, g_nSourceAssemblySymbols, g_nSourceAssembleBytes );
}
else
{
ConsoleBufferPushFormat( sFileName, " Read: %d lines, %d symbols"
, g_AssemblerSourceBuffer.GetNumLines() // g_nSourceAssemblyLines
, g_nSourceAssemblySymbols );
}
ConsoleBufferPush( sFileName );
}
}
else
{
wsprintf( sFileName, "Error reading: %s", sMiniFileName );
ConsoleBufferPush( sFileName );
ConsoleBufferPushFormat( sFileName, "Error reading: %s", sMiniFileName );
}
}
}
@ -7005,8 +6976,7 @@ Update_t CmdWatchList (int nArgs)
if (! g_nWatches)
{
TCHAR sText[ CONSOLE_WIDTH ];
wsprintf( sText, TEXT(" There are no current watches. (Max: %d)"), MAX_WATCHES );
ConsoleBufferPush( sText );
ConsoleBufferPushFormat( sText, TEXT(" There are no current watches. (Max: %d)"), MAX_WATCHES );
}
else
{
@ -7727,12 +7697,11 @@ int FindCommand( LPTSTR pName, CmdFuncPtr_t & pFunction_, int * iCommand_ )
void DisplayAmbigiousCommands( int nFound )
{
char sText[ CONSOLE_WIDTH * 2 ];
sprintf( sText, "Ambiguous %s%d%s Commands:"
ConsolePrintFormat( sText, "Ambiguous %s%d%s Commands:"
, CHC_NUM_DEC
, g_vPotentialCommands.size()
, CHC_DEFAULT
);
ConsolePrint( sText );
int iCommand = 0;
while (iCommand < nFound)
@ -7929,8 +7898,7 @@ Update_t ExecuteCommand (int nArgs)
{
//ArgsGetValue( pArg, & nAddress );
//char sText[ CONSOLE_WIDTH ];
//sprintf( sText, "Dst:%s Src: %s End: %s", pDst, pSrc, pEnd );
//ConsolePrint( sText );
//ConsolePrintFormat( sText, "Dst:%s Src: %s End: %s", pDst, pSrc, pEnd );
g_iCommand = CMD_MEMORY_MOVE;
pFunction = g_aCommands[ g_iCommand ].pFunction;
@ -8950,9 +8918,8 @@ void DebugInitialize ()
int nLen = _tcslen( pHelp ) + 2;
if (nLen > (CONSOLE_WIDTH-1))
{
wsprintf( sText, TEXT("Warning: %s help is %d chars"),
ConsoleBufferPushFormat( sText, TEXT("Warning: %s help is %d chars"),
pHelp, nLen );
ConsoleBufferPush( sText );
}
}
}

View File

@ -826,12 +826,11 @@ int AssemblerHashMnemonic ( const TCHAR * pMnemonic )
int nLen = strlen( pMnemonic );
#if DEBUG_ASSEMBLER
static char sText[ CONSOLE_WIDTH * 3 ];
static int nMaxLen = 0;
if (nMaxLen < nLen) {
nMaxLen = nLen;
sprintf( sText, "New Max Len: %d %s", nMaxLen, pMnemonic );
ConsolePrint( sText );
char sText[CONSOLE_WIDTH * 3];
ConsolePrintFormat( sText, "New Max Len: %d %s", nMaxLen, pMnemonic );
}
#endif
@ -856,8 +855,6 @@ int AssemblerHashMnemonic ( const TCHAR * pMnemonic )
//===========================================================================
void AssemblerHashOpcodes ()
{
static char sText[ 128 ];
Hash_t nMnemonicHash;
int iOpcode;
@ -867,10 +864,10 @@ static char sText[ 128 ];
nMnemonicHash = AssemblerHashMnemonic( pMnemonic );
g_aOpcodesHash[ iOpcode ] = nMnemonicHash;
#if DEBUG_ASSEMBLER
//OutputDebugString( "" );
sprintf( sText, "%s : %08X ", pMnemonic, nMnemonicHash );
ConsolePrint( sText );
// CLC: 002B864
//OutputDebugString( "" );
char sText[ 128 ];
ConsolePrintFormat( sText, "%s : %08X ", pMnemonic, nMnemonicHash );
// CLC: 002B864
#endif
}
ConsoleUpdate();
@ -928,19 +925,17 @@ void _CmdAssembleHashDump ()
int nOpcode = tHash.m_iOpcode;
int nOpmode = g_aOpcodes[ nOpcode ].nAddressMode;
wsprintf( sText, "%08X %02X %s %s"
ConsoleBufferPushFormat( sText, "%08X %02X %s %s"
, iThisHash
, nOpcode
, g_aOpcodes65C02[ nOpcode ].sMnemonic
, g_aOpmodes[ nOpmode ].m_sName
);
ConsoleBufferPush( sText );
nThisHash++;
// if (nPrevHash != iThisHash)
// {
// wsprintf( sText, "Total: %d", nThisHash );
// ConsoleBufferPush( sText );
// ConsoleBufferPushFormat( sText, "Total: %d", nThisHash );
// nThisHash = 0;
// }
}
@ -1435,14 +1430,13 @@ bool Assemble( int iArg, int nArgs, WORD nAddress )
int nMnemonicHash = AssemblerHashMnemonic( pMnemonic );
#if DEBUG_ASSEMBLER
static char sText[ CONSOLE_WIDTH * 2 ];
sprintf( sText, "%s%04X%s: %s%s%s -> %s%08X",
char sText[ CONSOLE_WIDTH * 2 ];
ConsolePrintFormat( sText, "%s%04X%s: %s%s%s -> %s%08X",
CHC_ADDRESS, nAddress,
CHC_DEFAULT,
CHC_STRING, pMnemonic,
CHC_DEFAULT,
CHC_NUM_HEX, nMnemonicHash );
ConsolePrint( sText );
CHC_NUM_HEX, nMnemonicHash );
#endif
m_vAsmOpcodes.clear(); // Candiate opcodes

View File

@ -263,6 +263,18 @@ bool ConsolePrint ( const char * pText )
return true;
}
bool ConsolePrintVa ( char* buf, size_t bufsz, const char * pFormat, va_list va )
{
vsnprintf_s(buf, bufsz, _TRUNCATE, pFormat, va);
return ConsolePrint(buf);
}
bool ConsoleBufferPushVa ( char* buf, size_t bufsz, const char * pFormat, va_list va )
{
vsnprintf_s(buf, bufsz, _TRUNCATE, pFormat, va);
return ConsoleBufferPush(buf);
}
// Add string to buffered output
// Shifts the buffered console output lines "Up"
//===========================================================================

View File

@ -1,6 +1,8 @@
#ifndef DEBUGGER_CONSOLE_H
#define DEBUGGER_CONSOLE_H
#include <cstdarg>
enum
{
// Basic Symbol table has > 600 symbols
@ -253,11 +255,59 @@
// Console
// Buffered
bool ConsolePrint( const char * pText );
void ConsoleBufferToDisplay ();
bool ConsolePrint( const char * pText );
bool ConsolePrintVa( char* buf, size_t bufsz, const char* pFormat, va_list va );
template<size_t _BufSz>
inline bool ConsolePrintVa( char (&buf)[_BufSz], const char* pFormat, va_list va )
{
return ConsolePrintVa(buf, _BufSz, pFormat, va);
}
inline bool ConsolePrintFormat( char* buf, size_t bufsz, const char* pFormat, ... )
{
va_list va;
va_start(va, pFormat);
bool const r = ConsolePrintVa(buf, bufsz, pFormat, va);
va_end(va);
return r;
}
template<size_t _BufSz>
inline bool ConsolePrintFormat( char(&buf)[_BufSz], const char* pFormat, ... )
{
va_list va;
va_start(va, pFormat);
bool const r = ConsolePrintVa(buf, pFormat, va);
va_end(va);
return r;
}
void ConsoleBufferToDisplay ();
const conchar_t* ConsoleBufferPeek ();
void ConsoleBufferPop ();
bool ConsoleBufferPush ( const char * pString );
void ConsoleBufferPop ();
bool ConsoleBufferPush( const char * pString );
bool ConsoleBufferPushVa( char* buf, size_t bufsz, const char* pFormat, va_list va );
template<size_t _BufSz>
inline bool ConsoleBufferPushVa( char (&buf)[_BufSz], const char* pFormat, va_list va )
{
return ConsoleBufferPushVa(buf, _BufSz, pFormat, va);
}
inline bool ConsoleBufferPushFormat( char* buf, size_t bufsz, const char* pFormat, ... )
{
va_list va;
va_start(va, pFormat);
bool const r = ConsoleBufferPushVa(buf, bufsz, pFormat, va);
va_end(va);
return r;
}
template<size_t _BufSz>
inline bool ConsoleBufferPushFormat( char(&buf)[_BufSz], const char* pFormat, ... )
{
va_list va;
va_start(va, pFormat);
bool const r = ConsoleBufferPushVa(buf, pFormat, va);
va_end(va);
return r;
}
void ConsoleConvertFromText( conchar_t * sText, const char * pText );

View File

@ -191,7 +191,6 @@ Update_t CmdDisasmDataList (int nArgs)
// Need to iterate through all blocks
DisasmData_t* pData = NULL;
char sText[ CONSOLE_WIDTH * 2 ];
while( pData = Disassembly_Enumerate( pData ) )
{
@ -199,9 +198,10 @@ Update_t CmdDisasmDataList (int nArgs)
{
int nLen = strlen( pData->sSymbol );
char sText[CONSOLE_WIDTH * 2];
// <smbol> <type> <start>:<end>
// `TEST `300`:`320
sprintf( sText, "%s%s %s%*s %s%04X%s:%s%04X"
ConsolePrintFormat( sText, "%s%s %s%*s %s%04X%s:%s%04X"
, CHC_CATEGORY
, g_aNopcodeTypes[ pData->eElementType ]
, (nLen > 0) ? CHC_SYMBOL : CHC_DEFAULT
@ -213,7 +213,6 @@ Update_t CmdDisasmDataList (int nArgs)
, CHC_ADDRESS
, pData->nEndAddress // Disassembly_IsDataAddress() is *inclusive* // KEEP IN SYNC: _CmdDefineByteRange() CmdDisasmDataList() _6502_GetOpmodeOpbyte() FormatNopcodeBytes()
);
ConsolePrint( sText );
}
}

File diff suppressed because it is too large Load Diff

View File

@ -95,11 +95,10 @@ Update_t _PrintSymbolInvalidTable()
// TODO: display the user specified file name
ConsoleBufferPush( "Invalid symbol table." );
sprintf( sText, "Only %s%d%s symbol tables are supported:"
ConsolePrintFormat( sText, "Only %s%d%s symbol tables are supported:"
, CHC_NUM_DEC, NUM_SYMBOL_TABLES
, CHC_DEFAULT
);
ConsolePrint( sText );
// Similar to _CmdSymbolsInfoHeader()
sText[0] = 0;
@ -359,14 +358,13 @@ void _CmdPrintSymbol( LPCTSTR pSymbol, WORD nAddress, int iTable )
// CHC_STRING and CHC_NUM_DEC are both cyan, using CHC_USAGE instead of CHC_STRING
// 2.6.2.20 Changed: Output of found symbol more table friendly. Symbol table name displayed first.
sprintf( sText, " %s%s%s: $%s%04X %s%s"
ConsolePrintFormat( sText, " %s%s%s: $%s%04X %s%s"
, CHC_USAGE, g_aSymbolTableNames[ iTable ]
, CHC_ARG_SEP
, CHC_ADDRESS, nAddress
, CHC_SYMBOL, pSymbol );
// ConsoleBufferPush( sText );
ConsolePrint( sText );
}
@ -516,11 +514,10 @@ Update_t _CmdSymbolsListTables (int nArgs, int bSymbolTables )
// nope, ok, try as address
if (! _CmdSymbolList_Address2Symbol( nAddress, bSymbolTables))
{
wsprintf( sText
ConsolePrintFormat( sText
, TEXT(" Address not found: %s$%s%04X%s" )
, CHC_ARG_SEP
, CHC_ADDRESS, nAddress, CHC_DEFAULT );
ConsolePrint( sText );
}
}
}
@ -532,20 +529,18 @@ Update_t _CmdSymbolsListTables (int nArgs, int bSymbolTables )
{
if (! _CmdSymbolList_Address2Symbol( nAddress, bSymbolTables ))
{
sprintf( sText
ConsolePrintFormat( sText
, TEXT(" %sSymbol not found: %s%s%s")
, CHC_ERROR, CHC_SYMBOL, pSymbol, CHC_DEFAULT
);
ConsolePrint( sText );
}
}
else
{
sprintf( sText
ConsolePrintFormat( sText
, TEXT(" %sSymbol not found: %s%s%s")
, CHC_ERROR, CHC_SYMBOL, pSymbol, CHC_DEFAULT
);
ConsolePrint( sText );
}
}
}
@ -651,14 +646,13 @@ int ParseSymbolTable( TCHAR *pPathFileName, SymbolTable_Index_e eSymbolTableWrit
bFileDisplayed = true;
// TODO: Must check for buffer overflow !
sprintf( sText, "%s%s"
ConsolePrintFormat( sText, "%s%s"
, CHC_PATH
, pPathFileName
);
ConsolePrint( sText );
}
sprintf( sText, " %sWarning: %s%-16s %saliases %s$%s%04X %s%-12s%s (%s%s%s)"
ConsolePrintFormat( sText, " %sWarning: %s%-16s %saliases %s$%s%04X %s%-12s%s (%s%s%s)"
, CHC_WARNING
, CHC_SYMBOL
, sName
@ -673,11 +667,10 @@ int ParseSymbolTable( TCHAR *pPathFileName, SymbolTable_Index_e eSymbolTableWrit
, g_aSymbolTableNames[ iTable ]
, CHC_DEFAULT
);
ConsolePrint( sText );
ConsoleUpdate(); // Flush buffered output so we don't ask the user to pause
/*
sprintf( sText, " %sWarning: %sAddress already has symbol Name%s (%s%s%s): %s%s"
ConsolePrintFormat( sText, " %sWarning: %sAddress already has symbol Name%s (%s%s%s): %s%s"
, CHC_WARNING
, CHC_INFO
, CHC_ARG_SEP
@ -687,9 +680,8 @@ int ParseSymbolTable( TCHAR *pPathFileName, SymbolTable_Index_e eSymbolTableWrit
, CHC_SYMBOL
, pSymbolPrev
);
ConsolePrint( sText );
sprintf( sText, " %s$%s%04X %s%-31s%s"
ConsolePrintFormat( sText, " %s$%s%04X %s%-31s%s"
, CHC_ARG_SEP
, CHC_ADDRESS
, nAddress
@ -697,7 +689,6 @@ int ParseSymbolTable( TCHAR *pPathFileName, SymbolTable_Index_e eSymbolTableWrit
, sName
, CHC_DEFAULT
);
ConsolePrint( sText );
*/
}
@ -707,7 +698,7 @@ int ParseSymbolTable( TCHAR *pPathFileName, SymbolTable_Index_e eSymbolTableWrit
if( !bDupSymbolHeader )
{
bDupSymbolHeader = true;
sprintf( sText, " %sDup Symbol Name%s (%s%s%s) %s"
ConsolePrintFormat( sText, " %sDup Symbol Name%s (%s%s%s) %s"
, CHC_ERROR
, CHC_DEFAULT
, CHC_STRING
@ -715,10 +706,9 @@ int ParseSymbolTable( TCHAR *pPathFileName, SymbolTable_Index_e eSymbolTableWrit
, CHC_DEFAULT
, pPathFileName
);
ConsolePrint( sText );
}
sprintf( sText, " %s$%s%04X %s%-31s%s"
ConsolePrintFormat( sText, " %s$%s%04X %s%-31s%s"
, CHC_ARG_SEP
, CHC_ADDRESS
, nAddress
@ -726,7 +716,6 @@ int ParseSymbolTable( TCHAR *pPathFileName, SymbolTable_Index_e eSymbolTableWrit
, sName
, CHC_DEFAULT
);
ConsolePrint( sText );
}
// else // It is not a bug to have duplicate addresses by different names
@ -850,14 +839,13 @@ void SymbolUpdate( SymbolTable_Index_e eSymbolTable, char *pSymbolName, WORD nAd
if (bUpdateSymbol)
{
char sText[ CONSOLE_WIDTH * 2 ];
sprintf( sText, " Updating %s%s%s from %s$%s%04X%s to %s$%s%04X%s"
ConsolePrintFormat( sText, " Updating %s%s%s from %s$%s%04X%s to %s$%s%04X%s"
, CHC_SYMBOL, pSymbolName, CHC_DEFAULT
, CHC_ARG_SEP
, CHC_ADDRESS, nAddressPrev, CHC_DEFAULT
, CHC_ARG_SEP
, CHC_ADDRESS, nAddress, CHC_DEFAULT
);
ConsolePrint( sText );
}
}
}
@ -882,12 +870,11 @@ void SymbolUpdate( SymbolTable_Index_e eSymbolTable, char *pSymbolName, WORD nAd
// Tell user symbol was added
char sText[ CONSOLE_WIDTH * 2 ];
sprintf( sText, " Added symbol: %s%s%s %s$%s%04X%s"
ConsolePrintFormat( sText, " Added symbol: %s%s%s %s$%s%04X%s"
, CHC_SYMBOL, pSymbolName, CHC_DEFAULT
, CHC_ARG_SEP
, CHC_ADDRESS, nAddress, CHC_DEFAULT
);
ConsolePrint( sText );
}
}
}
@ -947,10 +934,9 @@ Update_t _CmdSymbolsCommon ( int nArgs, int bSymbolTables )
if (iTable != NUM_SYMBOL_TABLES)
{
Update_t iUpdate = _CmdSymbolsClear( (SymbolTable_Index_e) iTable );
sprintf( sText, TEXT(" Cleared symbol table: %s%s")
ConsolePrintFormat( sText, TEXT(" Cleared symbol table: %s%s")
, CHC_STRING, g_aSymbolTableNames[ iTable ]
);
ConsolePrint( sText );
iUpdate |= ConsoleUpdate();
return iUpdate;
}