debugger:

- more highlighting
- fix address selection
- fix default size to allow one more line
This commit is contained in:
feos-tas 2016-09-25 19:42:18 +00:00
parent 11b17219eb
commit 1ab2293aa9
2 changed files with 115 additions and 59 deletions

View File

@ -85,6 +85,12 @@ char debug_str_decoration_comment[NL_MAX_MULTILINE_COMMENT_LEN + 10] = {0};
char* debug_decoration_comment;
char* debug_decoration_comment_end_pos;
CHARFORMAT2 mnem;
CHARFORMAT2 oper;
CHARFORMAT2 comm;
FINDTEXT newline;
FINDTEXT num;
// this is used to keep track of addresses that lines of Disassembly window correspond to
std::vector<uint16> disassembly_addresses;
// this is used to keep track of addresses in operands of each printed instruction
@ -116,7 +122,7 @@ void RestoreSize(HWND hwndDlg)
{
//If the dialog dimensions are changed those changes need to be reflected here. - adelikat
const int DEFAULT_WIDTH = 820 + (debuggerIDAFont ? 64 : 0); //Original width
const int DEFAULT_HEIGHT = 574; //Original height
const int DEFAULT_HEIGHT = 576 + (debuggerIDAFont ? 2 : 0); //Original height
SetWindowPos(hwndDlg,HWND_TOP,DbgPosX,DbgPosY,DEFAULT_WIDTH,DEFAULT_HEIGHT,SWP_SHOWWINDOW);
}
@ -418,48 +424,61 @@ void HighlightPC()
void HighlightSyntax(int lines)
{
int wordbreak = 0;
int opbreak = 0;
int numpos = 0;
int old_start, old_end;
bool commentline;
SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_GETSEL, (WPARAM)&old_start, (LPARAM)&old_end);
CHARFORMAT2 cf;
memset(&cf, 0, sizeof cf);
cf.cbSize = sizeof cf;
//if (!debuggerIDAFont)
//{
// cf.dwMask = CFM_COLOR | CFM_BOLD;
// cf.dwEffects = CFE_BOLD;
//} else
cf.dwMask = CFM_COLOR;
cf.crTextColor = RGB(0,0,128);
wordbreak = SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_FINDWORDBREAK, (WPARAM)WB_RIGHT, (LPARAM)21);
SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_SETSEL, (WPARAM)20, (LPARAM)wordbreak);
SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf);
FINDTEXT ft;
ft.lpstrText = "\r";
ft.chrg.cpMax = -1;
for (int line = 1; line <= lines; line++)
for (int line = 0; ; line++)
{
ft.chrg.cpMin = SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_FINDTEXT, (WPARAM)FR_DOWN, (LPARAM)&ft) + 1;
wordbreak = SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_FINDWORDBREAK, (WPARAM)WB_RIGHT, (LPARAM)ft.chrg.cpMin+21);
SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_SETSEL, (WPARAM)ft.chrg.cpMin+20, (LPARAM)wordbreak);
SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf);
}
cf.crTextColor = RGB(0,128,0);
ft.lpstrText = "$";
ft.chrg.cpMin = 0;
for (;;)
commentline = false;
wordbreak = SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_FINDWORDBREAK, (WPARAM)WB_RIGHT, (LPARAM)newline.chrg.cpMin + 21);
for (int ch = newline.chrg.cpMin; ; ch++)
{
ft.chrg.cpMin = SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_FINDTEXT, (WPARAM)FR_DOWN, (LPARAM)&ft) + 1;
if (ft.chrg.cpMin == 0)
if (debug_str[ch] == '=' || debug_str[ch] == '@' || debug_str[ch] == '\n' || debug_str[ch] == '-' || debug_str[ch] == ';')
{
opbreak = ch;
break;
if (debug_str[ft.chrg.cpMin+2] == ',' || debug_str[ft.chrg.cpMin+2] == ')')
wordbreak = ft.chrg.cpMin+2;
}
}
if (debug_str[newline.chrg.cpMin] == ';')
commentline = true;
SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_SETSEL, (WPARAM)newline.chrg.cpMin + 20, (LPARAM)opbreak);
int oldline = newline.chrg.cpMin;
newline.chrg.cpMin = SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_FINDTEXT, (WPARAM)FR_DOWN, (LPARAM)&newline) + 1;
// symbolic address
if (debug_str[newline.chrg.cpMin - 2] == ':')
{
SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_SETSEL, (WPARAM)oldline, (LPARAM)newline.chrg.cpMin);
SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&mnem);
continue;
}
if (!commentline)
SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&mnem);
// comment
if (opbreak < newline.chrg.cpMin)
{
SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_SETSEL, (WPARAM)opbreak, (LPARAM)newline.chrg.cpMin);
SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&comm);
}
if (commentline)
continue;
// operand
num.chrg.cpMin = wordbreak;
num.chrg.cpMax = wordbreak + 6;
numpos = SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_FINDTEXT, (WPARAM)FR_DOWN, (LPARAM)&num);
if (numpos != 0)
{
if (debug_str[numpos + 3] == ',' || debug_str[numpos + 3] == ')' || debug_str[numpos + 3] == '\n')
wordbreak = numpos + 2;
else
wordbreak = ft.chrg.cpMin+4;
SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_SETSEL, (WPARAM)ft.chrg.cpMin-1, (LPARAM)wordbreak);
SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf);
wordbreak = numpos + 4;
SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_SETSEL, (WPARAM)numpos, (LPARAM)wordbreak + 1);
SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&oper);
}
if (newline.chrg.cpMin == 0)
break;
}
SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_SETSEL, (WPARAM)old_start, (LPARAM)old_end);
@ -1490,7 +1509,7 @@ int Debugger_CheckClickingOnAnAddressOrSymbolicName(unsigned int lineNumber, boo
// find the ":" or "$" before sel_start
int i = sel_start - 1;
for (; i > sel_start - 6; i--)
if (i >= 0 && debug_str[i] == ':' || debug_str[i] == '$')
if ((i >= 0 && debug_str[i] == ':' || debug_str[i] == '$') && debug_str[i+3] != '\n')
break;
if (i > sel_start - 6)
{
@ -1504,10 +1523,15 @@ int Debugger_CheckClickingOnAnAddressOrSymbolicName(unsigned int lineNumber, boo
if (!firstspace)
{
unsigned int offset;
int numend;
if (sscanf(offsetBuffer, "%4X", &offset) != EOF)
{
if (debug_str[i+3] == ',' || debug_str[i+3] == ')')
numend = 3;
else
numend = 5;
// select the text
SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_SETSEL, (WPARAM)(i + 1), (LPARAM)(i + 5));
SendDlgItemMessage(hDebug, IDC_DEBUGGER_DISASSEMBLY, EM_SETSEL, (WPARAM)(i + 1), (LPARAM)(i + numend));
PrintOffsetToSeekAndBookmarkFields(offset);
return (int)offset;
}
@ -1885,7 +1909,7 @@ BOOL CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
debugSystem->hDisasmFont = debuggerIDAFont ? debugSystem->hIDAFont : debugSystem->hFixedFont;
debugSystem->disasmFontHeight = debuggerIDAFont ? IDAFontSize : debugSystem->fixedFontHeight;
SendDlgItemMessage(hwndDlg, IDC_DEBUGGER_DISASSEMBLY, WM_SETFONT, (WPARAM)debugSystem->hDisasmFont, FALSE);
UpdateDebugger();
UpdateDebugger(false);
break;
case IDC_DEBUGGER_CYCLES_EXCEED:
{
@ -2528,9 +2552,43 @@ void DebugSystem::init()
HexeditorFontWidth = tm.tmAveCharWidth;
SelectObject(hdc,old);
DeleteDC(hdc);
LoadLibrary(TEXT("Riched20.dll"));
hDisasmFont = debuggerIDAFont ? hIDAFont : hFixedFont;
disasmFontHeight = debuggerIDAFont ? IDAFontSize : fixedFontHeight;
memset(&mnem, 0, sizeof mnem);
mnem.cbSize = sizeof mnem;
//if (!debuggerIDAFont)
//{
// mnem.dwMask = CFM_COLOR | CFM_BOLD;
// mnem.dwEffects = CFE_BOLD;
//} else
mnem.dwMask = CFM_COLOR;
mnem.crTextColor = RGB(0,0,128);
memset(&oper, 0, sizeof oper);
oper.cbSize = sizeof oper;
//if (!debuggerIDAFont)
//{
// oper.dwMask = CFM_COLOR | CFM_BOLD;
// oper.dwEffects = CFE_BOLD;
//} else
oper.dwMask = CFM_COLOR;
oper.crTextColor = RGB(0,128,0);
memset(&comm, 0, sizeof comm);
comm.cbSize = sizeof comm;
comm.dwMask = CFM_COLOR;
comm.crTextColor = RGB(128,128,128);
newline.lpstrText = "\r";
newline.chrg.cpMin = 0;
newline.chrg.cpMax = -1;
num.lpstrText = "$";
num.chrg.cpMin = 0;
num.chrg.cpMax = -1;
LoadLibrary(TEXT("Riched20.dll"));
}
DebugSystem::~DebugSystem()

View File

@ -8,7 +8,6 @@
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
@ -711,13 +710,13 @@ BEGIN
PUSHBUTTON "<",MEMW_EXPANDCOLLAPSE,1,259,11,10
END
DEBUGGER DIALOGEX 54, 74, 546, 332
DEBUGGER DIALOGEX 54, 74, 546, 334
STYLE DS_SETFONT | DS_3DLOOK | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "6502 Debugger"
FONT 8, "Tahoma", 0, 0, 0x0
BEGIN
CONTROL "",IDC_DEBUGGER_DISASSEMBLY,"RichEdit20A",ES_MULTILINE | ES_NOHIDESEL | ES_READONLY | WS_BORDER | WS_HSCROLL,18,5,316,315
SCROLLBAR IDC_DEBUGGER_DISASSEMBLY_VSCR,334,5,11,315,SBS_VERT
CONTROL "",IDC_DEBUGGER_DISASSEMBLY,"RichEdit20A",ES_MULTILINE | ES_NOHIDESEL | ES_READONLY | WS_BORDER | WS_HSCROLL,18,5,316,317
SCROLLBAR IDC_DEBUGGER_DISASSEMBLY_VSCR,334,5,11,317,SBS_VERT
GROUPBOX "Status Flags",401,434,140,106,35,WS_TABSTOP
CONTROL "N",IDC_DEBUGGER_FLAG_N,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,440,149,18,12
CONTROL "V",IDC_DEBUGGER_FLAG_V,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,466,149,18,12
@ -762,7 +761,7 @@ BEGIN
EDITTEXT IDC_DEBUGGER_VAL_CYCLES_COUNT2,492,179,54,12,ES_READONLY | ES_WANTRETURN | NOT WS_BORDER | NOT WS_TABSTOP,WS_EX_TRANSPARENT
EDITTEXT IDC_DEBUGGER_VAL_INSTRUCTIONS_COUNT,442,204,47,12,ES_NOHIDESEL | ES_READONLY | ES_WANTRETURN | NOT WS_BORDER | NOT WS_TABSTOP,WS_EX_TRANSPARENT
EDITTEXT IDC_DEBUGGER_VAL_INSTRUCTIONS_COUNT2,491,204,55,12,ES_READONLY | ES_WANTRETURN | NOT WS_BORDER | NOT WS_TABSTOP,WS_EX_TRANSPARENT
CONTROL "",IDC_DEBUGGER_ADDR_LINE,"Static",SS_LEFTNOWORDWRAP | WS_GROUP,4,321,341,11
CONTROL "",IDC_DEBUGGER_ADDR_LINE,"Static",SS_LEFTNOWORDWRAP | WS_GROUP,4,323,341,11
CONTROL "Break on Bad Opcodes",IDC_DEBUGGER_BREAK_ON_BAD_OP,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,440,126,94,10
CONTROL "Symbolic debug",IDC_DEBUGGER_ENABLE_SYMBOLIC,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,473,261,62,10
@ -789,9 +788,9 @@ BEGIN
GROUPBOX "",IDC_STATIC,468,241,72,75
CONTROL "ROM offsets",IDC_DEBUGGER_ROM_OFFSETS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,473,249,62,10
PUSHBUTTON "Name",IDC_DEBUGGER_BOOKMARK_NAME,431,288,30,14
EDITTEXT IDC_DEBUGGER_DISASSEMBLY_LEFT_PANEL,4,5,14,315,ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY | WS_DISABLED
EDITTEXT IDC_DEBUGGER_DISASSEMBLY_LEFT_PANEL,4,5,14,317,ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY | WS_DISABLED
CONTROL "Register names",IDC_DEBUGGER_PREDEFINED_REGS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,473,272,65,10
CONTROL "IDA font",DEBUGIDAFONT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,507,319,38,13
CONTROL "IDA font",DEBUGIDAFONT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,506,319,38,13
END
TRACER DIALOGEX 0, 0, 317, 181
@ -1259,8 +1258,7 @@ BEGIN
LTEXT "Less",-1,330,151,18,10
LTEXT "Display on scanline:",-1,253,166,65,9
EDITTEXT IDC_PPUVIEW_SCANLINE,315,164,27,12
CONTROL "Sprites 8x16 mode",IDC_SPRITE16_MODE,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,6,151,160,10
CONTROL "Sprites 8x16 mode",IDC_SPRITE16_MODE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,6,151,160,10
CONTROL "Mask unused graphics (Code/Data Logger)",IDC_MASK_UNUSED_GRAPHICS,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,6,162,160,10
CONTROL "Invert the mask (Code/Data Logger)",IDC_INVERT_THE_MASK,
@ -1641,6 +1639,7 @@ BEGIN
"DEBUGGER", DIALOG
BEGIN
BOTTOMMARGIN, 332
END
"TRACER", DIALOG
@ -2600,7 +2599,6 @@ IDB_BRANCH_SPRITESHEET BITMAP "res\\branch_spritesheet.bmp"
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED