From eece84b5ac1903dcab316bb1351f8eda15fd7f3b Mon Sep 17 00:00:00 2001 From: mpohoreski Date: Sun, 31 Aug 2008 08:49:11 +0000 Subject: [PATCH] Added new command: '@' --- source/Debug.cpp | 98 +++++++++++++++++++++++++++------------- source/Debug.h | 10 ++++ source/Debugger_Help.cpp | 62 ++++++++++++++++++------- source/Debugger_Help.h | 3 ++ source/Debugger_Types.h | 2 + 5 files changed, 127 insertions(+), 48 deletions(-) diff --git a/source/Debug.cpp b/source/Debug.cpp index 832afdbf..c2d421ef 100644 --- a/source/Debug.cpp +++ b/source/Debug.cpp @@ -43,7 +43,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // TODO: COLOR LOAD ["filename"] // See Debugger_Changelong.txt for full details - const int DEBUGGER_VERSION = MAKE_VERSION(2,6,0,2); + const int DEBUGGER_VERSION = MAKE_VERSION(2,6,0,6); // Public _________________________________________________________________________________________ @@ -114,15 +114,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #define __COMMANDS_VERIFY_TXT__ "\xDE\xAD\xC0\xDE" #define __PARAMS_VERIFY_TXT__ "\xDE\xAD\xDA\x1A" - class commands_functor_compare - { - public: - int operator() ( const Command_t & rLHS, const Command_t & rRHS ) const - { - return _tcscmp( rLHS.m_sName, rRHS.m_sName ); - } - }; - int g_iCommand; // last command (enum) // used for consecuitive commands vector g_vPotentialCommands; // global, since TAB-completion also needs @@ -164,7 +155,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA {TEXT("BMA") , CmdBookmarkAdd , CMD_BOOKMARK_ADD , "Add/Update addess to bookmark" }, {TEXT("BMC") , CmdBookmarkClear , CMD_BOOKMARK_CLEAR , "Clear (remove) bookmark" }, {TEXT("BML") , CmdBookmarkList , CMD_BOOKMARK_LIST , "List all bookmarks" }, - {"BMG" , CmdBookmarkGoto , CMD_BOOKMARK_GOTO , "Move cursor to bookmark" }, + {TEXT("BMG") , CmdBookmarkGoto , CMD_BOOKMARK_GOTO , "Move cursor to bookmark" }, // {TEXT("BMLOAD") , CmdBookmarkLoad , CMD_BOOKMARK_LOAD , "Load bookmarks" }, {TEXT("BMSAVE") , CmdBookmarkSave , CMD_BOOKMARK_SAVE , "Save bookmarks" }, // Breakpoints @@ -263,6 +254,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA {TEXT("M") , CmdMemoryMove , CMD_MEMORY_MOVE , "Memory move" }, {TEXT("BSAVE") , CmdMemorySave , CMD_MEMORY_SAVE , "Save a region of memory" }, {TEXT("S") , CmdMemorySearch , CMD_MEMORY_SEARCH , "Search memory for text / hex values" }, + {TEXT("@") ,_SearchMemoryDisplay , CMD_MEMORY_FIND_RESULTS , "Display search memory resuts" }, // {TEXT("SA") , CmdMemorySearchAscii, CMD_MEMORY_SEARCH_ASCII , "Search ASCII text" }, // {TEXT("ST") , CmdMemorySearchApple , CMD_MEMORY_SEARCH_APPLE , "Search Apple text (hi-bit)" }, {TEXT("SH") , CmdMemorySearchHex , CMD_MEMORY_SEARCH_HEX , "Search memory for hex values" }, @@ -922,10 +914,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA , const WORD & nAddress1, const WORD & nAddress2 , WORD & nAddressEnd_, int & nAddressLen_ ); - bool StringCat( TCHAR * pDst, LPCSTR pSrc, const int nDstSize ); - bool TestStringCat ( TCHAR * pDst, LPCSTR pSrc, const int nDstSize ); - bool TryStringCat ( TCHAR * pDst, LPCSTR pSrc, const int nDstSize ); - char FormatCharTxtCtrl ( const BYTE b, bool *pWasCtrl_ ); char FormatCharTxtAsci ( const BYTE b, bool *pWasAsci_ ); char FormatCharTxtHigh ( const BYTE b, bool *pWasHi_ ); @@ -5008,49 +4996,95 @@ int _SearchMemoryFind( //=========================================================================== -Update_t _SearchMemoryDisplay() +Update_t _SearchMemoryDisplay (int nArgs) { + const nBuf = CONSOLE_WIDTH * 2; + int nFound = g_vMemorySearchResults.size() - 1; - TCHAR sMatches[ CONSOLE_WIDTH ] = TEXT(""); - int nThisLineLen = 0; // string length of matches for this line, for word-wrap + 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) { - TCHAR sText[ CONSOLE_WIDTH ]; - int iFound = 1; while (iFound <= nFound) { WORD nAddress = g_vMemorySearchResults.at( iFound ); - wsprintf( sText, "%2d:$%04X ", iFound, nAddress ); - int nLen = _tcslen( sText ); +// sprintf( sText, "%2d:$%04X ", iFound, nAddress ); +// int nLen = _tcslen( sText ); + + sResult[0] = 0; + nLen = 0; + + StringCat( sResult, CHC_COMMAND, nBuf ); + sprintf( sText, "%2d", iFound ); + nLen += StringCat( sResult, sText , nBuf ); + + StringCat( sResult, CHC_DEFAULT, nBuf ); + nLen += StringCat( sResult, ":" , nBuf ); + + StringCat( sResult, CHC_ADDRESS, nBuf ); + sprintf( sText, "$%04X", nAddress ); + nLen += StringCat( sResult, sText, nBuf ); // Fit on same line? - if ((nThisLineLen + nLen) > (g_nConsoleDisplayWidth)) // CONSOLE_WIDTH + if ((nLineLen + nLen) > (g_nConsoleDisplayWidth - 1)) // CONSOLE_WIDTH { - ConsoleDisplayPush( sMatches ); - _tcscpy( sMatches, sText ); - nThisLineLen = nLen; + //ConsoleDisplayPush( sMatches ); + ConsolePrint( sMatches ); + _tcscpy( sMatches, sResult ); + nLineLen = nLen; } else { - _tcscat( sMatches, sText ); - nThisLineLen += nLen; + StringCat( sMatches, sResult, nBuf ); + nLineLen += nLen; } iFound++; } - ConsoleDisplayPush( sMatches ); + ConsolePrint( sMatches ); } - wsprintf( sMatches, "Total: %d (#$%04X)", nFound, nFound ); - ConsoleDisplayPush( sMatches ); +// wsprintf( sMatches, "Total: %d (#$%04X)", nFound, nFound ); +// ConsoleDisplayPush( sMatches ); + sResult[0] = 0; + + StringCat( sResult, CHC_USAGE , nBuf ); + nLen += StringCat( sResult, "Total", nBuf ); + + StringCat( sResult, CHC_DEFAULT, nBuf ); + nLen += StringCat( sResult, ": " , nBuf ); + + StringCat( sResult, CHC_NUM_DEC, nBuf ); + sprintf( sText, "%d ", nFound ); + nLen += StringCat( sResult, sText, nBuf ); + + StringCat( sResult, CHC_ARG_OPT, nBuf ); + nLen += StringCat( sResult, "(" , nBuf ); + + StringCat( sResult, CHC_DEFAULT, nBuf ); + nLen += StringCat( sResult, "#$", nBuf ); + + StringCat( sResult, CHC_NUM_HEX, nBuf ); + sprintf( sText, "%04X", nFound ); + nLen += StringCat( sResult, sText, nBuf ); + + StringCat( sResult, CHC_ARG_OPT, nBuf ); + nLen += StringCat( sResult, ")" , nBuf ); + + ConsolePrint( sResult ); // g_vMemorySearchResults is cleared in DebugEnd() - return UPDATE_CONSOLE_DISPLAY; +// return UPDATE_CONSOLE_DISPLAY; + return ConsoleUpdate(); } diff --git a/source/Debug.h b/source/Debug.h index c797c4b5..e479bcd1 100644 --- a/source/Debug.h +++ b/source/Debug.h @@ -45,6 +45,16 @@ using namespace std; extern Command_t g_aCommands[]; extern Command_t g_aParameters[]; + class commands_functor_compare + { + public: + bool operator() ( const Command_t & rLHS, const Command_t & rRHS ) const + { + // return true if lhs= (CONSOLE_WIDTH - 1)) + { + ConsolePrint( sText ); + sText[ 0 ] = 0; + nLen = StringCat( sText, " ", nBuf ); // indent + } StringCat( sText, CHC_ARG_SEP, nBuf ); - nLen += StringCat( sText, " | " , nBuf ); + nLen += StringCat( sText, sSep, nBuf ); } } StringCat( sText, CHC_ARG_MAND, nBuf ); @@ -347,6 +356,9 @@ bool Colorize( char * pDst, const char * pSrc ) const char sUsage[] = "Usage:"; const int nUsage = sizeof( sUsage ) - 1; + const char sTotal[] = "Total:"; + const int nTotal = sizeof( sTotal ) - 1; + int nLen = 0; while (*pSrc) { @@ -365,6 +377,11 @@ bool Colorize( char * pDst, const char * pSrc ) _ColorizeHeader( pDst, pSrc, sNote, nNote ); } else + if (strncmp( sTotal, pSrc, nNote) == 0) + { + _ColorizeHeader( pDst, pSrc, sTotal, nTotal ); + } + else if (*pSrc == '[') { _ColorizeOperator( pDst, pSrc, CHC_ARG_OPT ); @@ -1359,7 +1376,10 @@ Update_t CmdHelpSpecific (int nArgs) //=========================================================================== Update_t CmdHelpList (int nArgs) { - char sText[ CONSOLE_WIDTH ] = "Commands: "; + const int nBuf = CONSOLE_WIDTH * 2; + + char sText[ nBuf ] = ""; + int nLenLine = strlen( sText ); int y = 0; int nLinesScrolled = 0; @@ -1367,46 +1387,56 @@ Update_t CmdHelpList (int nArgs) int nMaxWidth = g_nConsoleDisplayWidth - 1; int iCommand; -/* + extern vector g_vSortedCommands; + if (! g_vSortedCommands.size()) { for (iCommand = 0; iCommand < NUM_COMMANDS_WITH_ALIASES; iCommand++ ) { -// TCHAR *pName = g_aCommands[ iCommand ].aName ); g_vSortedCommands.push_back( g_aCommands[ iCommand ] ); } - std::sort( g_vSortedCommands.begin(), g_vSortedCommands.end(), commands_functor_compare() ); } int nCommands = g_vSortedCommands.size(); -*/ + + int nLen = 0; +// Colorize( sText, "Commands: " ); + StringCat( sText, CHC_USAGE , nBuf ); + nLen += StringCat( sText, "Commands", nBuf ); + + StringCat( sText, CHC_DEFAULT, nBuf ); + nLen += StringCat( sText, ": " , nBuf ); + for( iCommand = 0; iCommand < NUM_COMMANDS_WITH_ALIASES; iCommand++ ) // aliases are not printed { -// Command_t *pCommand = & g_vSortedCommands.at( iCommand ); - Command_t *pCommand = & g_aCommands[ iCommand ]; + Command_t *pCommand = & g_vSortedCommands.at( iCommand ); +// Command_t *pCommand = & g_aCommands[ iCommand ]; char *pName = pCommand->m_sName; if (! pCommand->pFunction) continue; // not implemented function int nLenCmd = strlen( pName ); - if ((nLenLine + nLenCmd) < (nMaxWidth)) + if ((nLen + nLenCmd) < (nMaxWidth)) { - strcat( sText, pName ); + StringCat( sText, CHC_COMMAND, nBuf ); + nLen += StringCat( sText, pName , nBuf ); } else { - ConsoleBufferPush( sText ); - nLenLine = 1; + ConsolePrint( sText ); + nLen = 1; strcpy( sText, " " ); - strcat( sText, pName ); + StringCat( sText, CHC_COMMAND, nBuf ); + nLen += StringCat( sText, pName, nBuf ); } strcat( sText, " " ); - nLenLine += (nLenCmd + 1); + nLen++; } - ConsoleBufferPush( sText ); + //ConsoleBufferPush( sText ); + ConsolePrint( sText ); ConsoleUpdate(); return UPDATE_CONSOLE_DISPLAY; diff --git a/source/Debugger_Help.h b/source/Debugger_Help.h index 440c6b6f..246dc336 100644 --- a/source/Debugger_Help.h +++ b/source/Debugger_Help.h @@ -26,5 +26,8 @@ inline void UnpackVersion( const unsigned int nVersion, nFixMinor_ = (nVersion >> 0) & 0xFF; } + bool TestStringCat ( TCHAR * pDst, LPCSTR pSrc, const int nDstSize ); + bool TryStringCat ( TCHAR * pDst, LPCSTR pSrc, const int nDstSize ); + int StringCat( TCHAR * pDst, LPCSTR pSrc, const int nDstSize ); #endif diff --git a/source/Debugger_Types.h b/source/Debugger_Types.h index 093346d3..328ab95f 100644 --- a/source/Debugger_Types.h +++ b/source/Debugger_Types.h @@ -555,6 +555,7 @@ , CMD_MEMORY_MOVE , CMD_MEMORY_SAVE , CMD_MEMORY_SEARCH + , CMD_MEMORY_FIND_RESULTS // , CMD_MEMORY_SEARCH_ASCII // Ascii Text // , CMD_MEMORY_SEARCH_APPLE // Flashing Chars, Hi-Bit Set , CMD_MEMORY_SEARCH_HEX @@ -760,6 +761,7 @@ Update_t CmdMemoryMove (int nArgs); Update_t CmdMemorySave (int nArgs); Update_t CmdMemorySearch (int nArgs); + Update_t _SearchMemoryDisplay (int nArgs=0); // Update_t CmdMemorySearchLowBit (int nArgs); // Update_t CmdMemorySearchHiBit (int nArgs); Update_t CmdMemorySearchAscii (int nArgs);