For Qt debugger. Added logic to make byte code display configurable. Saved color configs to file.

This commit is contained in:
mjbudd77 2021-07-10 16:49:18 -04:00
parent 8314f7bad1
commit fcf250e350
7 changed files with 166 additions and 35 deletions

View File

@ -31,13 +31,15 @@
#include <QStyle>
#include "Qt/ColorMenu.h"
#include "Qt/fceuWrapper.h"
//----------------------------------------------------------------------------
ColorMenuItem::ColorMenuItem( QString txt, QWidget *parent)
ColorMenuItem::ColorMenuItem( QString txt, const char *confNameConst, QWidget *parent)
: QAction( txt, parent)
{
title = txt;
picker = NULL;
colorPtr = &lastColor;
confName = confNameConst;
setImageColor( Qt::red );
@ -108,6 +110,22 @@ void ColorMenuItem::pickerClosed(int ret)
picker = NULL;
setImageColor( *colorPtr );
if ( ret )
{
if ( confName != NULL )
{
QString colorText;
colorText = colorPtr->name();
//printf("Saving '%s' = Color string '%s'\n", confName.c_str(), colorText.toStdString().c_str() );
g_config->setOption( confName, colorText.toStdString().c_str() );
g_config->save();
}
}
//printf("Picker Closed: %i\n", ret );
}
//----------------------------------------------------------------------------
@ -116,7 +134,7 @@ void ColorMenuItem::openColorPicker(void)
//printf("Open Color Picker\n");
if ( picker == NULL )
{
picker = new ColorMenuPickerDialog_t( colorPtr, parentWidget() );
picker = new ColorMenuPickerDialog_t( colorPtr, title.toStdString().c_str(), parentWidget() );
picker->show();
@ -130,7 +148,7 @@ void ColorMenuItem::openColorPicker(void)
//----------------------------------------------------------------------------
//------ Color Menu Picker
//----------------------------------------------------------------------------
ColorMenuPickerDialog_t::ColorMenuPickerDialog_t( QColor *c, QWidget *parent )
ColorMenuPickerDialog_t::ColorMenuPickerDialog_t( QColor *c, const char *txt, QWidget *parent )
: QDialog( parent )
{
QVBoxLayout *mainLayout;
@ -143,7 +161,7 @@ ColorMenuPickerDialog_t::ColorMenuPickerDialog_t( QColor *c, QWidget *parent )
style = this->style();
sprintf( stmp, "Pick Color");
sprintf( stmp, "Pick Color for %s", txt);
setWindowTitle( stmp );
@ -220,7 +238,7 @@ void ColorMenuPickerDialog_t::colorChanged( const QColor &color )
void ColorMenuPickerDialog_t::colorAccepted(void)
{
//printf("nesColorPicker Accepted: %zi\n", colorChangeHistory.size() );
done(0);
done(1);
deleteLater();
}
//----------------------------------------------------------------------------

View File

@ -16,7 +16,7 @@ class ColorMenuPickerDialog_t : public QDialog
Q_OBJECT
public:
ColorMenuPickerDialog_t( QColor *c, QWidget *parent = 0);
ColorMenuPickerDialog_t( QColor *c, const char *txt, QWidget *parent = 0);
~ColorMenuPickerDialog_t(void);
protected:
@ -41,7 +41,7 @@ class ColorMenuItem : public QAction
Q_OBJECT
public:
ColorMenuItem( QString txt, QWidget *parent = 0);
ColorMenuItem( QString txt, const char *confName, QWidget *parent = 0);
~ColorMenuItem(void);
void connectColor( QColor *c );
@ -50,6 +50,7 @@ class ColorMenuItem : public QAction
QColor *colorPtr;
QColor lastColor;
ColorMenuPickerDialog_t *picker;
const char *confName;
void setImageColor( QColor c );
public slots:

View File

@ -419,20 +419,37 @@ ConsoleDebugger::ConsoleDebugger(QWidget *parent)
subMenu = optMenu->addMenu(tr("&Color Selection"));
// Options -> Color Selection -> Opcodes
opcodeColorAct = new ColorMenuItem( tr("&Opcodes"), this);
opcodeColorAct = new ColorMenuItem( tr("&Opcodes"), "SDL.DebuggerSyntaxColorOpcode", this);
subMenu->addAction(opcodeColorAct);
// Options -> Color Selection -> Address Values
addressColorAct = new ColorMenuItem( tr("&Address Values"), "SDL.DebuggerSyntaxColorAddress", this);
subMenu->addAction(addressColorAct);
// Options -> Color Selection -> Immediate Values
immediateColorAct = new ColorMenuItem( tr("&Immediate Values"), "SDL.DebuggerSyntaxColorImmediate", this);
subMenu->addAction(immediateColorAct);
// Options -> Color Selection -> Labels
labelColorAct = new ColorMenuItem( tr("&Labels"), this);
labelColorAct = new ColorMenuItem( tr("&Labels"), "SDL.DebuggerSyntaxColorLabel", this);
subMenu->addAction(labelColorAct);
// Options -> Color Selection -> Comments
commentColorAct = new ColorMenuItem( tr("&Comments"), this);
commentColorAct = new ColorMenuItem( tr("&Comments"), "SDL.DebuggerSyntaxColorComment", this);
subMenu->addAction(commentColorAct);
subMenu->addSeparator();
// Options -> Color Selection -> (PC) Active Statement
pcColorAct = new ColorMenuItem( tr("(&PC) Active Statement BG"), "SDL.DebuggerSyntaxColorPC", this);
subMenu->addAction(pcColorAct);
optMenu->addSeparator();
// Symbols
@ -450,6 +467,16 @@ ConsoleDebugger::ConsoleDebugger(QWidget *parent)
symMenu->addSeparator();
// Symbols -> Show Byte Codes
act = new QAction(tr("Show &Byte Codes"), this);
//act->setShortcut(QKeySequence( tr("F7") ) );
act->setStatusTip(tr("Show &Byte Codes"));
act->setCheckable(true);
act->setChecked(false);
connect( act, SIGNAL(triggered(bool)), this, SLOT(displayByteCodesCB(bool)) );
symMenu->addAction(act);
// Symbols -> Display ROM Offsets
act = new QAction(tr("Show ROM &Offsets"), this);
//act->setShortcut(QKeySequence( tr("F7") ) );
@ -995,9 +1022,12 @@ ConsoleDebugger::ConsoleDebugger(QWidget *parent)
setCpuStatusFont( cpuFont );
opcodeColorAct->connectColor( &asmView->opcodeColor );
labelColorAct->connectColor( &asmView->labelColor );
commentColorAct->connectColor( &asmView->commentColor);
opcodeColorAct->connectColor( &asmView->opcodeColor );
addressColorAct->connectColor( &asmView->addressColor );
immediateColorAct->connectColor( &asmView->immediateColor );
labelColorAct->connectColor( &asmView->labelColor );
commentColorAct->connectColor( &asmView->commentColor);
pcColorAct->connectColor( &asmView->pcBgColor);
}
//----------------------------------------------------------------------------
ConsoleDebugger::~ConsoleDebugger(void)
@ -1866,6 +1896,11 @@ void ConsoleDebugger::instructionsThresChanged(const QString &txt)
}
}
//----------------------------------------------------------------------------
void ConsoleDebugger::displayByteCodesCB( bool value )
{
asmView->setDisplayByteCodes(value);
}
//----------------------------------------------------------------------------
void ConsoleDebugger::displayROMoffsetCB( bool value )
{
asmView->setDisplayROMoffsets(value);
@ -2796,11 +2831,11 @@ void QAsmView::updateAssemblyView(void)
for (int j = 0; j < size; j++)
{
sprintf(chr, "%02X ", opcode[j] = GetMem(addr++));
line.append(chr);
if ( showByteCodes ) line.append(chr);
}
while (size < 3)
{
line.append(" "); //pad output to align ASM
if ( showByteCodes ) line.append(" "); //pad output to align ASM
size++;
}
@ -2816,7 +2851,7 @@ void QAsmView::updateAssemblyView(void)
// special case: an RTS opcode
if (GetMem(instruction_addr) == 0x60)
{
line.append("-------------------------");
line.append(" -------------------------");
}
if ( symbolicDebugEnable )
@ -2875,6 +2910,8 @@ void QAsmView::updateAssemblyView(void)
{
stmp[j] = ' '; j++;
}
stmp[j] = ';'; j++;
stmp[j] = ' '; j++;
}
stmp[j] = c[i]; j++; i++;
}
@ -3686,12 +3723,20 @@ QAsmView::QAsmView(QWidget *parent)
useDarkTheme = false;
pcBgColor.setRgb( 255, 255, 0 );
opcodeColor.setRgb( 46, 139, 87 );
labelColor.setRgb( 165, 42, 42 );
commentColor.setRgb( 0, 0, 255 );
addressColor.setRgb( 106, 90, 205 );
immediateColor.setRgb( 255, 1, 255 );
fceuLoadConfigColor( "SDL.DebuggerSyntaxColorOpcode" , &opcodeColor );
fceuLoadConfigColor( "SDL.DebuggerSyntaxColorAddress" , &addressColor );
fceuLoadConfigColor( "SDL.DebuggerSyntaxColorImmediate", &immediateColor );
fceuLoadConfigColor( "SDL.DebuggerSyntaxColorLabel" , &labelColor );
fceuLoadConfigColor( "SDL.DebuggerSyntaxColorComment" , &commentColor );
fceuLoadConfigColor( "SDL.DebuggerSyntaxColorPC" , &pcBgColor );
g_config->getOption("SDL.DebuggerAsmFont", &fontString);
if ( fontString.size() > 0 )
@ -3743,14 +3788,13 @@ QAsmView::QAsmView(QWidget *parent)
calcFontData();
setMinimumWidth( 50 * pxCharWidth );
vbar = NULL;
hbar = NULL;
asmPC = NULL;
displayROMoffsets = false;
symbolicDebugEnable = true;
registerNameEnable = true;
showByteCodes = false;
maxLineLen = 0;
pxLineWidth = 0;
lineOffset = 0;
@ -3790,10 +3834,7 @@ QAsmView::QAsmView(QWidget *parent)
//printf("clipboard->supportsSelection() : '%i' \n", clipboard->supportsSelection() );
//printf("clipboard->supportsFindBuffer(): '%i' \n", clipboard->supportsFindBuffer() );
pcLocLinePos = 4;
byteCodeLinePos = 12;
opcodeLinePos = 22;
operandLinePos = 25;
calcLineOffsets();
}
//----------------------------------------------------------------------------
QAsmView::~QAsmView(void)
@ -3810,6 +3851,14 @@ void QAsmView::asmClear(void)
asmEntry.clear();
}
//----------------------------------------------------------------------------
void QAsmView::calcLineOffsets(void)
{
pcLocLinePos = 4;
byteCodeLinePos = pcLocLinePos + 8; // 12;
opcodeLinePos = byteCodeLinePos + (showByteCodes ? 10 : 1); //22;
operandLinePos = opcodeLinePos + 3; // 25;
}
//----------------------------------------------------------------------------
void QAsmView::setLine(int lineNum)
{
lineOffset = lineNum;
@ -3881,6 +3930,21 @@ void QAsmView::scrollToPC(void)
}
}
//----------------------------------------------------------------------------
void QAsmView::setDisplayByteCodes( bool value )
{
if ( value != showByteCodes )
{
showByteCodes = value;
calcLineOffsets();
calcMinimumWidth();
fceuWrapperLock();
updateAssemblyView();
fceuWrapperUnLock();
}
}
//----------------------------------------------------------------------------
void QAsmView::setDisplayROMoffsets( bool value )
{
if ( value != displayROMoffsets )
@ -3941,6 +4005,20 @@ void QAsmView::calcFontData(void)
pxCursorHeight = pxCharHeight;
viewLines = (viewHeight / pxLineSpacing) + 1;
calcMinimumWidth();
}
//----------------------------------------------------------------------------
void QAsmView::calcMinimumWidth(void)
{
if ( showByteCodes )
{
setMinimumWidth( 50 * pxCharWidth );
}
else
{
setMinimumWidth( 41 * pxCharWidth );
}
}
//----------------------------------------------------------------------------
void QAsmView::setScrollBars( QScrollBar *h, QScrollBar *v )
@ -3963,13 +4041,13 @@ bool QAsmView::event(QEvent *event)
opcodeValid = (line < asmEntry.size()) && (asmEntry[line]->size > 0) &&
(asmEntry[line]->type == dbg_asm_entry_t::ASM_TEXT);
showOpcodeDesc = (c.x() >= 22) && (c.x() < 25) && opcodeValid;
showOpcodeDesc = (c.x() >= opcodeLinePos) && (c.x() < operandLinePos) && opcodeValid;
if ( (c.x() > 25) && opcodeValid && (asmEntry[line]->sym.name.size() > 0) )
if ( (c.x() > operandLinePos) && opcodeValid && (asmEntry[line]->sym.name.size() > 0) )
{
size_t subStrLoc = asmEntry[line]->text.find( asmEntry[line]->sym.name, 25 );
size_t subStrLoc = asmEntry[line]->text.find( asmEntry[line]->sym.name, operandLinePos );
if ( (subStrLoc != std::string::npos) && (subStrLoc > 25) )
if ( (subStrLoc != std::string::npos) && (subStrLoc > operandLinePos) )
{
//printf("Line:%i asmEntry DB Sym: %zi '%s'\n", line, subStrLoc, asmEntry[line]->sym.name.c_str() );
int symTextStart = subStrLoc;
@ -4404,9 +4482,9 @@ void QAsmView::mousePressEvent(QMouseEvent * event)
if ( asmEntry[line]->sym.name.size() > 0 )
{
size_t subStrLoc = asmEntry[line]->text.find( asmEntry[line]->sym.name, 25 );
size_t subStrLoc = asmEntry[line]->text.find( asmEntry[line]->sym.name, operandLinePos );
if ( (subStrLoc != std::string::npos) && (subStrLoc > 25) )
if ( (subStrLoc != std::string::npos) && (subStrLoc > operandLinePos) )
{
//printf("Line:%i asmEntry DB Sym: %zi '%s'\n", line, subStrLoc, asmEntry[line]->sym.name.c_str() );
symTextStart = subStrLoc;
@ -4839,7 +4917,11 @@ void QAsmView::paintEvent(QPaintEvent *event)
painter.fillRect( 0, 0, viewWidth, viewHeight, this->palette().color(QPalette::Window) );
painter.fillRect( 0, 0, cd_boundary, viewHeight, this->palette().color(QPalette::Mid) );
painter.fillRect( asm_start_boundary, 0, (9*pxCharWidth), viewHeight, this->palette().color(QPalette::AlternateBase) );
if ( showByteCodes )
{
painter.fillRect( asm_start_boundary, 0, (9*pxCharWidth), viewHeight, this->palette().color(QPalette::AlternateBase) );
}
y = pxLineSpacing;
@ -4856,7 +4938,7 @@ void QAsmView::paintEvent(QPaintEvent *event)
{
if ( l == asmPC->line )
{
painter.fillRect( cd_boundary, y - pxLineSpacing + pxLineLead, viewWidth, pxLineSpacing, QColor("pink") );
painter.fillRect( cd_boundary, y - pxLineSpacing + pxLineLead, viewWidth, pxLineSpacing, pcBgColor );
forceDarkColor = true;
}
}
@ -5131,6 +5213,11 @@ DebuggerStackDisplay::DebuggerStackDisplay(QWidget *parent)
QFont font;
std::string fontString;
stackBytesPerLine = 4;
showAddrs = true;
recalcCharsPerLine();
g_config->getOption("SDL.DebuggerStackFont", &fontString);
if ( fontString.size() > 0 )
@ -5147,9 +5234,6 @@ DebuggerStackDisplay::DebuggerStackDisplay(QWidget *parent)
QFontMetrics fm(font);
stackBytesPerLine = 4;
showAddrs = true;
#if QT_VERSION > QT_VERSION_CHECK(5, 11, 0)
pxCharWidth = fm.horizontalAdvance(QLatin1Char('2'));
#else
@ -5157,8 +5241,6 @@ DebuggerStackDisplay::DebuggerStackDisplay(QWidget *parent)
#endif
pxLineSpacing = fm.lineSpacing();
recalcCharsPerLine();
setMinimumWidth( pxCharWidth * charsPerLine );
setMinimumHeight( pxLineSpacing * 5 );
setMaximumHeight( pxLineSpacing * 20 );

View File

@ -115,6 +115,7 @@ class QAsmView : public QWidget
void setDisplayROMoffsets( bool value );
void setSymbolDebugEnable( bool value );
void setRegisterNameEnable( bool value );
void setDisplayByteCodes( bool value );
int getCtxMenuAddr(void){ return ctxMenuAddr; };
int getCursorAddr(void){ return cursorLineAddr; };
void setPC_placement( int mode, int ofs = 0 );
@ -129,6 +130,7 @@ class QAsmView : public QWidget
QColor immediateColor;
QColor commentColor;
QColor labelColor;
QColor pcBgColor;
protected:
bool event(QEvent *event) override;
@ -145,6 +147,8 @@ class QAsmView : public QWidget
void toggleBreakpoint(int line);
void calcFontData(void);
void calcMinimumWidth(void);
void calcLineOffsets(void);
QPoint convPixToCursor( QPoint p );
bool textIsHighlighted(void);
void setHighlightEndCoord( int x, int y );
@ -208,6 +212,7 @@ class QAsmView : public QWidget
bool symbolicDebugEnable;
bool registerNameEnable;
bool mouseLeftBtnDown;
bool showByteCodes;
};
@ -314,8 +319,11 @@ class ConsoleDebugger : public QDialog
QFont font;
ColorMenuItem *opcodeColorAct;
ColorMenuItem *addressColorAct;
ColorMenuItem *immediateColorAct;
ColorMenuItem *commentColorAct;
ColorMenuItem *labelColorAct;
ColorMenuItem *pcColorAct;
int selBmAddrVal;
bool windowUpdateReq;
@ -355,6 +363,7 @@ class ConsoleDebugger : public QDialog
void delete_BM_CB(void);
void resetCountersCB (void);
void reloadSymbolsCB(void);
void displayByteCodesCB(bool value);
void displayROMoffsetCB(bool value);
void symbolDebugEnableCB(bool value);
void registerNameEnableCB(bool value);

View File

@ -38,6 +38,7 @@
#include "../../fceu.h"
#include "../../x6502.h"
#include "Qt/fceuWrapper.h"
#include "Qt/ConsoleUtilities.h"
//---------------------------------------------------------------------------
@ -290,7 +291,19 @@ int fceuExecutablePath( char *outputPath, int outputSize )
#endif
return -1;
}
//---------------------------------------------------------------------------
int fceuLoadConfigColor( const char *confName, QColor *color )
{
std::string colorString;
g_config->getOption(confName, &colorString);
if ( (color != NULL) && (colorString.size() > 0) )
{
color->setNamedColor( colorString.c_str() );
}
return 0;
}
//---------------------------------------------------------------------------
// FCEU Data Entry Custom Validators
//---------------------------------------------------------------------------

View File

@ -2,6 +2,7 @@
#pragma once
#include <QColor>
#include <QValidator>
int getDirFromFile( const char *path, char *dir );
@ -14,6 +15,7 @@ int parseFilepath( const char *filepath, char *dir, char *base, char *suffix = N
int fceuExecutablePath( char *outputPath, int outputSize );
int fceuLoadConfigColor( const char *confName, QColor *color );
class fceuDecIntValidtor : public QValidator
{

View File

@ -577,6 +577,12 @@ InitConfig()
config->addOption("SDL.DebuggerAsmFont" , "");
config->addOption("SDL.DebuggerStackFont" , "");
config->addOption("SDL.DebuggerCpuStatusFont" , "");
config->addOption("SDL.DebuggerSyntaxColorOpcode", "");
config->addOption("SDL.DebuggerSyntaxColorAddress", "");
config->addOption("SDL.DebuggerSyntaxColorImmediate", "");
config->addOption("SDL.DebuggerSyntaxColorLabel", "");
config->addOption("SDL.DebuggerSyntaxColorComment", "");
config->addOption("SDL.DebuggerSyntaxColorPC", "");
// Code Data Logger Options
config->addOption("autoSaveCDL" , "SDL.AutoSaveCDL", 1);