Opcode tool tips in work for Qt debugger.

This commit is contained in:
mjbudd77 2021-07-06 22:56:33 -04:00
parent 47da5cbc17
commit 692e137e6f
6 changed files with 365 additions and 93 deletions

View File

@ -42,6 +42,7 @@
#include <QActionGroup>
#include <QGuiApplication>
#include <QSettings>
#include <QToolTip>
#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)
@ -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<QHelpEvent *>(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();
@ -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 );
}

View File

@ -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);

View File

@ -37,6 +37,7 @@
#endif
#include "../../fceu.h"
#include "../../x6502.h"
#include "Qt/ConsoleUtilities.h"
//---------------------------------------------------------------------------
@ -426,3 +427,232 @@ QValidator::State fceuHexIntValidtor::validate(QString &input, int &pos) const
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<size; i++)
{
sprintf(stmp, "$%02X ", opcode[i] );
text.append( stmp );
}
text.append( "\nAddressing Mode:\t" );
text.append( addrMode );
text.append( "\nCycle Count:\t\t" );
sprintf( stmp, "%i", X6502_GetOpcodeCycles( opcode[0] ) );
text.append( stmp );
text.append( "\n" );
return QString::fromStdString( text );
}
//---------------------------------------------------------------------------

View File

@ -41,3 +41,4 @@ class fceuHexIntValidtor : public QValidator
int max;
};
QString fceuGetOpcodeToolTip( uint8_t *opcode, int size );

View File

@ -355,6 +355,11 @@ static uint8 CycTable[256] =
/*0xF0*/ 2,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,
};
int X6502_GetOpcodeCycles( int op )
{
return CycTable[op];
}
void X6502_IRQBegin(int w)
{
_IRQlow|=w;

View File

@ -90,5 +90,7 @@ void X6502_DMW(uint32 A, uint8 V);
void X6502_IRQBegin(int w);
void X6502_IRQEnd(int w);
int X6502_GetOpcodeCycles( int op );
#define _X6502H
#endif