From 692e137e6f89e6b317c4cbfb6f19801771fc4334 Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Tue, 6 Jul 2021 22:56:33 -0400 Subject: [PATCH] Opcode tool tips in work for Qt debugger. --- src/drivers/Qt/ConsoleDebugger.cpp | 113 ++++++---- src/drivers/Qt/ConsoleDebugger.h | 5 +- src/drivers/Qt/ConsoleUtilities.cpp | 330 +++++++++++++++++++++++----- src/drivers/Qt/ConsoleUtilities.h | 1 + src/x6502.cpp | 7 +- src/x6502.h | 2 + 6 files changed, 365 insertions(+), 93 deletions(-) diff --git a/src/drivers/Qt/ConsoleDebugger.cpp b/src/drivers/Qt/ConsoleDebugger.cpp index cbaa6bcf..2e00a6b3 100644 --- a/src/drivers/Qt/ConsoleDebugger.cpp +++ b/src/drivers/Qt/ConsoleDebugger.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include "../../types.h" #include "../../fceu.h" @@ -2548,7 +2549,8 @@ void QAsmView::updateAssemblyView(void) } line.append(chr); - size = opsize[GetMem(addr)]; + a->size = size = opsize[GetMem(addr)]; + if (size == 0) { sprintf(chr, "%02X UNDEFINED", GetMem(addr++)); @@ -2585,7 +2587,6 @@ void QAsmView::updateAssemblyView(void) { a->opcode[j] = opcode[j]; } - a->size = size; // special case: an RTS opcode if (GetMem(instruction_addr) == 0x60) @@ -3652,19 +3653,19 @@ void QAsmView::setRegisterNameEnable( bool value ) //---------------------------------------------------------------------------- void QAsmView::calcFontData(void) { - this->setFont(font); - QFontMetrics metrics(font); + this->setFont(font); + QFontMetrics metrics(font); #if QT_VERSION > QT_VERSION_CHECK(5, 11, 0) - pxCharWidth = metrics.horizontalAdvance(QLatin1Char('2')); + pxCharWidth = metrics.horizontalAdvance(QLatin1Char('2')); #else - pxCharWidth = metrics.width(QLatin1Char('2')); + pxCharWidth = metrics.width(QLatin1Char('2')); #endif - pxCharHeight = metrics.height(); - pxLineSpacing = metrics.lineSpacing() * 1.25; - pxLineLead = pxLineSpacing - pxCharHeight; - pxCursorHeight = pxCharHeight; + pxCharHeight = metrics.height(); + pxLineSpacing = metrics.lineSpacing() * 1.25; + pxLineLead = pxLineSpacing - pxCharHeight; + pxCursorHeight = pxCharHeight; - viewLines = (viewHeight / pxLineSpacing) + 1; + viewLines = (viewHeight / pxLineSpacing) + 1; } //---------------------------------------------------------------------------- void QAsmView::setScrollBars( QScrollBar *h, QScrollBar *v ) @@ -3672,6 +3673,38 @@ void QAsmView::setScrollBars( QScrollBar *h, QScrollBar *v ) hbar = h; vbar = v; } //---------------------------------------------------------------------------- +bool QAsmView::event(QEvent *event) +{ + if (event->type() == QEvent::ToolTip) + { + int line; + QHelpEvent *helpEvent = static_cast(event); + bool showOpcodeDesc = false; + + QPoint c = convPixToCursor(helpEvent->pos()); + + line = lineOffset + c.y(); + + showOpcodeDesc = (c.x() >= 22) && (c.x() < 25) && + (line < asmEntry.size()) && (asmEntry[line]->type == dbg_asm_entry_t::ASM_TEXT); + + if ( showOpcodeDesc ) + { + QString qs = fceuGetOpcodeToolTip(asmEntry[line]->opcode, asmEntry[line]->size ); + + //QToolTip::setFont(font); + QToolTip::showText(helpEvent->globalPos(), qs, this ); + } + else + { + QToolTip::hideText(); + event->ignore(); + } + return true; + } + return QWidget::event(event); +} +//---------------------------------------------------------------------------- void QAsmView::resizeEvent(QResizeEvent *event) { viewWidth = event->size().width(); @@ -3720,52 +3753,52 @@ void QAsmView::keyPressEvent(QKeyEvent *event) event->accept(); } else if (event->matches(QKeySequence::MoveToNextPage)) - { - lineOffset += ( (3 * viewLines) / 4); - - if ( lineOffset >= maxLineOffset ) - { - lineOffset = maxLineOffset; - } - vbar->setValue( lineOffset ); + { + lineOffset += ( (3 * viewLines) / 4); + + if ( lineOffset >= maxLineOffset ) + { + lineOffset = maxLineOffset; + } + vbar->setValue( lineOffset ); event->accept(); - } - else if (event->matches(QKeySequence::MoveToPreviousPage)) - { - lineOffset -= ( (3 * viewLines) / 4); - - if ( lineOffset < 0 ) - { - lineOffset = 0; - } - vbar->setValue( lineOffset ); + } + else if (event->matches(QKeySequence::MoveToPreviousPage)) + { + lineOffset -= ( (3 * viewLines) / 4); + + if ( lineOffset < 0 ) + { + lineOffset = 0; + } + vbar->setValue( lineOffset ); event->accept(); - } + } else if ( selAddrValue >= 0 ) { ctxMenuAddr = selAddrValue; if ( event->key() == Qt::Key_B ) - { + { parent->asmViewCtxMenuAddBP(); event->accept(); - } + } else if ( event->key() == Qt::Key_S ) - { + { parent->asmViewCtxMenuAddSym(); event->accept(); - } + } else if ( event->key() == Qt::Key_M ) - { + { parent->asmViewCtxMenuAddBM(); event->accept(); - } + } else if ( event->key() == Qt::Key_H ) - { + { parent->asmViewCtxMenuOpenHexEdit(); event->accept(); - } - } + } + } } //---------------------------------------------------------------------------- void QAsmView::keyReleaseEvent(QKeyEvent *event) @@ -3783,7 +3816,7 @@ QPoint QAsmView::convPixToCursor( QPoint p ) } else { - float x = (float)p.x() / pxCharWidth; + float x = (float)(p.x() + pxLineXScroll) / pxCharWidth; c.setX( (int)x ); } diff --git a/src/drivers/Qt/ConsoleDebugger.h b/src/drivers/Qt/ConsoleDebugger.h index 1d286094..242de77d 100644 --- a/src/drivers/Qt/ConsoleDebugger.h +++ b/src/drivers/Qt/ConsoleDebugger.h @@ -117,6 +117,7 @@ class QAsmView : public QWidget void setPC_placement( int mode, int ofs = 0 ); void setBreakpointAtSelectedLine(void); protected: + bool event(QEvent *event) override; void paintEvent(QPaintEvent *event); void keyPressEvent(QKeyEvent *event); void keyReleaseEvent(QKeyEvent *event); @@ -193,7 +194,7 @@ class DebuggerStackDisplay : public QPlainTextEdit Q_OBJECT public: - DebuggerStackDisplay(QWidget *parent = 0); + DebuggerStackDisplay(QWidget *parent = 0); ~DebuggerStackDisplay(void); void updateText(void); @@ -291,7 +292,7 @@ class ConsoleDebugger : public QDialog void bpListUpdate( bool reset = false ); void bmListUpdate( bool reset = false ); - public slots: + public slots: void closeWindow(void); void asmViewCtxMenuAddBP(void); void asmViewCtxMenuAddBM(void); diff --git a/src/drivers/Qt/ConsoleUtilities.cpp b/src/drivers/Qt/ConsoleUtilities.cpp index f7318831..5e744a68 100644 --- a/src/drivers/Qt/ConsoleUtilities.cpp +++ b/src/drivers/Qt/ConsoleUtilities.cpp @@ -37,6 +37,7 @@ #endif #include "../../fceu.h" +#include "../../x6502.h" #include "Qt/ConsoleUtilities.h" //--------------------------------------------------------------------------- @@ -327,35 +328,35 @@ QValidator::State fceuDecIntValidtor::validate(QString &input, int &pos) const i++; } else if ( s[i] == '+' ) - { - i++; - } - - if ( s[i] == 0 ) - { - return QValidator::Acceptable; - } - - if ( isdigit(s[i]) ) - { - while ( isdigit(s[i]) ) i++; - - if ( s[i] == 0 ) - { + { + i++; + } + + if ( s[i] == 0 ) + { + return QValidator::Acceptable; + } + + if ( isdigit(s[i]) ) + { + while ( isdigit(s[i]) ) i++; + + if ( s[i] == 0 ) + { v = strtol( s.c_str(), NULL, 0 ); - + if ( v < min ) { - return QValidator::Invalid; + return QValidator::Invalid; } else if ( v > max ) { - return QValidator::Invalid; + return QValidator::Invalid; } - return QValidator::Acceptable; - } - } - return QValidator::Invalid; + return QValidator::Acceptable; + } + } + return QValidator::Invalid; } //--------------------------------------------------------------------------- // FCEU Data Entry Custom Validators @@ -395,34 +396,263 @@ QValidator::State fceuHexIntValidtor::validate(QString &input, int &pos) const i++; } else if ( s[i] == '+' ) - { - i++; - } + { + i++; + } - if ( s[i] == 0 ) - { - return QValidator::Acceptable; - } - - if ( isxdigit(s[i]) ) - { - while ( isxdigit(s[i]) ) i++; - - if ( s[i] == 0 ) - { - v = strtol( s.c_str(), NULL, 16 ); - - if ( v < min ) - { - return QValidator::Invalid; - } - else if ( v > max ) - { - return QValidator::Invalid; - } - return QValidator::Acceptable; - } - } - return QValidator::Invalid; + if ( s[i] == 0 ) + { + return QValidator::Acceptable; + } + + if ( isxdigit(s[i]) ) + { + while ( isxdigit(s[i]) ) i++; + + if ( s[i] == 0 ) + { + v = strtol( s.c_str(), NULL, 16 ); + + if ( v < min ) + { + return QValidator::Invalid; + } + else if ( v > max ) + { + return QValidator::Invalid; + } + return QValidator::Acceptable; + } + } + return QValidator::Invalid; +} +//--------------------------------------------------------------------------- +//--- Opcode Tool Tip Description +//--------------------------------------------------------------------------- +QString fceuGetOpcodeToolTip( uint8_t *opcode, int size ) +{ + std::string text; + const char *title = ""; + const char *addrMode = NULL; + char stmp[32]; + + switch (opcode[0]) + { + // ADC - Add with Carry + case 0x69: + case 0x65: + case 0x75: + case 0x6D: + case 0x7D: + case 0x79: + case 0x61: + case 0x71: + title = "ADC - Add with Carry"; + + if ( opcode[0] == 0x69 ) + { + addrMode = "Immediate"; + } + break; + // AND - Logical AND + case 0x29: + case 0x25: + case 0x35: + case 0x2D: + case 0x3D: + case 0x39: + case 0x21: + case 0x31: + title = "AND - Logical AND"; + + if ( opcode[0] == 0x29 ) + { + addrMode = "Immediate"; + } + break; + // ASL - Arithmetic Shift Left + case 0x0A: + case 0x06: + case 0x16: + case 0x0E: + case 0x1E: + title = "ASL - Arithmetic Shift Left"; + + if ( opcode[0] == 0x0A ) + { + addrMode = "Accumulator"; + } + break; + // BCC - Branch if Carry Clear + case 0x90: + title = "BCC - Branch if Carry Clear"; + + if ( opcode[0] == 0x90 ) + { + addrMode = "Relative"; + } + break; + // BCS - Branch if Carry Set + case 0xB0: + title = "BCC - Branch if Carry Set"; + + if ( opcode[0] == 0xB0 ) + { + addrMode = "Relative"; + } + break; + // BEQ - Branch if Equal + case 0xF0: + title = "BCC - Branch if Equal"; + + if ( opcode[0] == 0xF0 ) + { + addrMode = "Relative"; + } + break; + // BIT - Bit Test + case 0x24: + case 0x2C: + title = "BIT - Bit Test"; + break; + // BMI - Branch if Minus + case 0x30: + title = "BMI - Branch if Minus"; + + if ( opcode[0] == 0x30 ) + { + addrMode = "Relative"; + } + break; + // BNE - Branch if Not Equal + case 0xD0: + title = "BNE - Branch if Not Equal"; + + if ( opcode[0] == 0xD0 ) + { + addrMode = "Relative"; + } + break; + // BPL - Branch if Positive + case 0x10: + title = "BPL - Branch if Positive"; + + if ( opcode[0] == 0x10 ) + { + addrMode = "Relative"; + } + break; + // BRK - Force Interrupt + case 0x00: + title = "BRK - Force Interrupt"; + break; + // BVC - Branch if Overflow Clear + case 0x50: + title = "BVC - Branch if Overflow Clear"; + + if ( opcode[0] == 0x50 ) + { + addrMode = "Relative"; + } + break; + // BVS - Branch if Overflow Set + case 0x70: + title = "BVS - Branch if Overflow Set"; + + if ( opcode[0] == 0x70 ) + { + addrMode = "Relative"; + } + break; + // CLC - Clear Carry Flag + case 0x18: + title = "CLC - Clear Carry Flag"; + break; + // CLD - Clear Decimal Mode + case 0xD8: + title = "CLD - Clear Decimal Mode"; + break; + // CLI - Clear Interrupt Disable + case 0x58: + title = "CLI - Clear Interrupt Disable"; + break; + // CLV - Clear Overflow Flag + case 0xB8: + title = "CLV - Clear Overflow Flag"; + break; + // CMP - Compare + case 0xC9: + case 0xC5: + case 0xD5: + case 0xCD: + case 0xDD: + case 0xD9: + case 0xC1: + case 0xD1: + title = "CMP - Compare"; + + if ( opcode[0] == 0xC9 ) + { + addrMode = "Immediate"; + } + break; + default: + title = ""; + break; + } + + if ( addrMode == NULL ) + { + switch ( optype[ opcode[0] ] ) + { + default: + case 0: //Implied\Accumulator\Immediate\Branch\NULL + addrMode = "Implied"; + break; + case 1: // (Indirect,X) + addrMode = "(Indirect,X)"; + break; + case 2: // Zero Page + addrMode = "Zero Page"; + break; + case 3: // Absolute + addrMode = "Absolute"; + break; + case 4: // (Indirect),Y + addrMode = "(Indirect),Y"; + break; + case 5: // Zero Page,X + addrMode = "Zero Page,X"; + break; + case 6: // Absolute,Y + addrMode = "Absolute,Y"; + break; + case 7: // Absolute,X + addrMode = "Absolute,X"; + break; + case 8: // Zero Page,Y + addrMode = "Zero Page,Y"; + break; + } + } + text.assign( title ); + text.append( "\n" ); + text.append( "\nByte Code:\t\t" ); + + for (int i=0; i