Qt Hex Editor in work.

This commit is contained in:
Matthew Budd 2020-08-16 21:24:27 -04:00
parent 490289a6f7
commit 4e7e82dbcd
2 changed files with 93 additions and 25 deletions

View File

@ -7,6 +7,7 @@
#include <SDL.h> #include <SDL.h>
#include <QHeaderView> #include <QHeaderView>
#include <QScrollBar>
#include "../../types.h" #include "../../types.h"
#include "../../fceu.h" #include "../../fceu.h"
@ -103,9 +104,15 @@ HexEditorDialog_t::HexEditorDialog_t(QWidget *parent)
txtBuf->setFont( font ); txtBuf->setFont( font );
txtBuf->moveCursor(QTextCursor::Start); txtBuf->moveCursor(QTextCursor::Start);
txtBuf->setReadOnly(true); //txtBuf->setReadOnly(true);
txtBuf->setOverwriteMode(true);
txtBuf->setCenterOnScroll(false);
txtBuf->setLineWrapMode( QPlainTextEdit::NoWrap ); txtBuf->setLineWrapMode( QPlainTextEdit::NoWrap );
connect( txtBuf->verticalScrollBar(), SIGNAL(sliderMoved(int)), this, SLOT(vbarMoved(int)) );
connect( txtBuf->verticalScrollBar(), SIGNAL(sliderPressed(void)), this, SLOT(vbarPressed(void)) );
//connect( txtBuf->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(vbarMoved(int)) );
mainLayout->addWidget( txtBuf ); mainLayout->addWidget( txtBuf );
setLayout( mainLayout ); setLayout( mainLayout );
@ -173,7 +180,7 @@ int HexEditorDialog_t::calcVisibleRange( int *start_out, int *end_out, int *cent
start_pos = 0; start_pos = 0;
} }
printf("Start: %i End: %i\n", start_pos, end_pos ); //printf("Start: %i End: %i\n", start_pos, end_pos );
if ( start_out ) if ( start_out )
{ {
@ -211,12 +218,37 @@ void HexEditorDialog_t::initMem(void)
} }
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void HexEditorDialog_t::vbarMoved( int pos )
{
printf("VBAR: %i \n", pos );
}
//----------------------------------------------------------------------------
void HexEditorDialog_t::vbarPressed( void )
{
printf("VBAR: %i \n", txtBuf->verticalScrollBar()->value() );
}
//----------------------------------------------------------------------------
void HexEditorDialog_t::setCursor( int pos )
{
QTextCursor cursor = txtBuf->textCursor();
cursor.setPosition( pos );
txtBuf->setTextCursor( cursor );
}
//----------------------------------------------------------------------------
void HexEditorDialog_t::advCursor( int num )
{
QTextCursor cursor = txtBuf->textCursor();
cursor.setPosition( cursor.position() + num );
txtBuf->setTextCursor( cursor );
}
//----------------------------------------------------------------------------
void HexEditorDialog_t::showMemViewResults (bool reset) void HexEditorDialog_t::showMemViewResults (bool reset)
{ {
int i, row, row_start, row_end; int i, row, row_start, row_end;
int addr = 0, lineAddr = 0, c, un, ln; int addr = 0, lineAddr = 0, c, un, ln;
char addrStr[128], valStr[16][8], ascii[18]; char addrStr[128], valStr[16][8], ascii[18];
char valChg[16], activityColoringOn, colorEnable; char valChg[16], asciiChg, activityColoringOn, colorEnable;
QTextCursor cursorSave;
switch ( mode ) switch ( mode )
{ {
@ -290,40 +322,44 @@ void HexEditorDialog_t::showMemViewResults (bool reset)
else else
{ {
calcVisibleRange( &row_start, &row_end, NULL ); calcVisibleRange( &row_start, &row_end, NULL );
if ( row_start < 0 )
{
row_start = 0;
}
if ( row_end > numLines )
{
row_end = numLines;
}
} }
if ( row_start < 0 )
{
row_start = 0;
}
if ( row_end > numLines )
{
row_end = numLines;
}
cursorSave = txtBuf->textCursor();
//printf("Cursor Start Position: %i\n", txtBuf->textCursor().position() );
for (row=row_start; row<row_end; row++) for (row=row_start; row<row_end; row++)
{ {
lineAddr = (row*16); lineAddr = (row*16);
//printf("Pre Cursor Line %i Position: %i\n", row, txtBuf->textCursor().position() );
if ( !reset ) if ( !reset )
{ {
txtBuf->textCursor().setPosition( row * numCharsPerLine ); setCursor( row * numCharsPerLine );
} }
//printf("Post Cursor Line %i Position: %i\n", row, txtBuf->textCursor().position() );
if ( reset ) if ( reset )
{ {
//next_iter = iter;
//gtk_text_iter_forward_chars( &next_iter, 9 );
sprintf( addrStr, "%08X ", lineAddr ); sprintf( addrStr, "%08X ", lineAddr );
txtBuf->insertPlainText( addrStr ); txtBuf->insertPlainText( addrStr );
} }
else else
{ {
txtBuf->textCursor().movePosition( QTextCursor::NextCharacter, QTextCursor::MoveAnchor, 9 ); advCursor(9);
} }
asciiChg = reset;
for (i=0; i<16; i++) for (i=0; i<16; i++)
{ {
valChg[i] = reset; valChg[i] = reset;
@ -336,6 +372,7 @@ void HexEditorDialog_t::showMemViewResults (bool reset)
{ {
mbuf[addr].draw = 0; mbuf[addr].draw = 0;
valChg[i] = 1; valChg[i] = 1;
asciiChg = 1;
} }
un = ( c & 0x00f0 ) >> 4; un = ( c & 0x00f0 ) >> 4;
@ -356,20 +393,24 @@ void HexEditorDialog_t::showMemViewResults (bool reset)
ascii[i] = '.'; ascii[i] = '.';
} }
if ( valChg[i] ) if ( reset )
{ {
if ( !reset ) txtBuf->insertPlainText( valStr[i] );
}
else
{
if ( valChg[i] )
{ {
for (int j=0; j<4; j++) for (int j=0; j<4; j++)
{ {
txtBuf->textCursor().deleteChar(); txtBuf->textCursor().deleteChar();
} }
txtBuf->insertPlainText( valStr[i] );
}
else
{
advCursor(4);
} }
txtBuf->insertPlainText( valStr[i] );
}
else
{
txtBuf->textCursor().movePosition( QTextCursor::NextCharacter, QTextCursor::MoveAnchor, 4 );
} }
} }
ascii[16] = 0; ascii[16] = 0;
@ -378,18 +419,41 @@ void HexEditorDialog_t::showMemViewResults (bool reset)
{ {
txtBuf->insertPlainText( ascii ); txtBuf->insertPlainText( ascii );
} }
else
{
if ( asciiChg )
{
for (int j=0; j<16; j++)
{
txtBuf->textCursor().deleteChar();
}
txtBuf->insertPlainText( ascii );
}
else
{
advCursor(16);
}
}
if ( reset ) if ( reset )
{ {
txtBuf->insertPlainText("\n"); txtBuf->insertPlainText("\n");
} }
else
{
advCursor(1);
}
} }
// Restore Cursor to Saved Location
txtBuf->setTextCursor( cursorSave );
txtBuf->ensureCursorVisible();
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void HexEditorDialog_t::updatePeriodic(void) void HexEditorDialog_t::updatePeriodic(void)
{ {
printf("Update Periodic\n"); //printf("Update Periodic\n");
checkMemActivity(); checkMemActivity();

View File

@ -47,6 +47,8 @@ class HexEditorDialog_t : public QDialog
void showMemViewResults (bool reset); void showMemViewResults (bool reset);
int checkMemActivity(void); int checkMemActivity(void);
int calcVisibleRange( int *start_out, int *end_out, int *center_out ); int calcVisibleRange( int *start_out, int *end_out, int *center_out );
void setCursor( int pos );
void advCursor( int num );
QFont font; QFont font;
QPlainTextEdit *txtBuf; QPlainTextEdit *txtBuf;
@ -70,5 +72,7 @@ class HexEditorDialog_t : public QDialog
void closeWindow(void); void closeWindow(void);
private slots: private slots:
void updatePeriodic(void); void updatePeriodic(void);
void vbarMoved( int pos );
void vbarPressed( void );
}; };