Bug fixes for Qt hex editor ascii section key input. Key inputs now use character table.

This commit is contained in:
mjbudd77 2021-02-21 20:21:11 -05:00
parent e07cd5ec52
commit aacee3ddb9
2 changed files with 100 additions and 61 deletions

View File

@ -747,6 +747,8 @@ void HexEditorCharTable_t::resetAscii(void)
{ {
for (int i=0; i<256; i++) for (int i=0; i<256; i++)
{ {
rmap[i] = i;
if (i > 127) if (i > 127)
{ // Extended Ascii { // Extended Ascii
if ( extAsciiEnable ) if ( extAsciiEnable )
@ -780,7 +782,8 @@ int HexEditorCharTable_t::loadFromFile( const char *filepath )
char line[256]; char line[256];
char tk[64]; char tk[64];
char errMsg[256]; char errMsg[256];
char tmpMap[256]; int tmpMap[256];
int tmpMapR[256];
retVal = 0; retVal = 0;
errMsg[0] = 0; errMsg[0] = 0;
@ -791,7 +794,11 @@ int HexEditorCharTable_t::loadFromFile( const char *filepath )
{ {
return -1; return -1;
} }
memset( tmpMap, '.', sizeof(tmpMap) ); for (i=0; i<256; i++)
{
tmpMap[i] = -1;
tmpMapR[i] = -1;
}
while ( fgets( line, sizeof(line), fp ) != 0 ) while ( fgets( line, sizeof(line), fp ) != 0 )
{ {
@ -898,11 +905,17 @@ int HexEditorCharTable_t::loadFromFile( const char *filepath )
} }
tmpMap[ hexValue ] = mapValue; tmpMap[ hexValue ] = mapValue;
if ( mapValue < 256 )
{
tmpMapR[ mapValue ] = hexValue;
}
} }
if ( retVal == 0 ) if ( retVal == 0 )
{ {
memcpy( map, tmpMap, 256 ); memcpy( map, tmpMap , sizeof( map) );
memcpy( rmap, tmpMapR, sizeof(rmap) );
customMapLoaded = true; customMapLoaded = true;
} }
else else
@ -1354,7 +1367,6 @@ HexEditorDialog_t::HexEditorDialog_t(QWidget *parent)
connect( periodicTimer, &QTimer::timeout, this, &HexEditorDialog_t::updatePeriodic ); connect( periodicTimer, &QTimer::timeout, this, &HexEditorDialog_t::updatePeriodic );
periodicTimer->start( 100 ); // 10hz periodicTimer->start( 100 ); // 10hz
//periodicTimer->start( 16 ); // 10hz
// Lock the mutex before adding a new window to the list, // Lock the mutex before adding a new window to the list,
// we want to be sure that the emulator is not iterating the list // we want to be sure that the emulator is not iterating the list
@ -2396,6 +2408,7 @@ void QHexEdit::keyPressEvent(QKeyEvent *event)
} }
resetCursor(); resetCursor();
update(); update();
event->accept();
} }
else if (event->matches(QKeySequence::MoveToPreviousChar)) else if (event->matches(QKeySequence::MoveToPreviousChar))
{ {
@ -2420,18 +2433,21 @@ void QHexEdit::keyPressEvent(QKeyEvent *event)
} }
resetCursor(); resetCursor();
update(); update();
event->accept();
} }
else if (event->matches(QKeySequence::MoveToEndOfLine)) else if (event->matches(QKeySequence::MoveToEndOfLine))
{ {
cursorPosX = 47; cursorPosX = 47;
resetCursor(); resetCursor();
update(); update();
event->accept();
} }
else if (event->matches(QKeySequence::MoveToStartOfLine)) else if (event->matches(QKeySequence::MoveToStartOfLine))
{ {
cursorPosX = 0; cursorPosX = 0;
resetCursor(); resetCursor();
update(); update();
event->accept();
} }
else if (event->matches(QKeySequence::MoveToPreviousLine)) else if (event->matches(QKeySequence::MoveToPreviousLine))
{ {
@ -2451,6 +2467,7 @@ void QHexEdit::keyPressEvent(QKeyEvent *event)
} }
resetCursor(); resetCursor();
update(); update();
event->accept();
} }
else if (event->matches(QKeySequence::MoveToNextLine)) else if (event->matches(QKeySequence::MoveToNextLine))
{ {
@ -2470,6 +2487,7 @@ void QHexEdit::keyPressEvent(QKeyEvent *event)
} }
resetCursor(); resetCursor();
update(); update();
event->accept();
} }
else if (event->matches(QKeySequence::MoveToNextPage)) else if (event->matches(QKeySequence::MoveToNextPage))
@ -2483,6 +2501,7 @@ void QHexEdit::keyPressEvent(QKeyEvent *event)
vbar->setValue( lineOffset ); vbar->setValue( lineOffset );
resetCursor(); resetCursor();
update(); update();
event->accept();
} }
else if (event->matches(QKeySequence::MoveToPreviousPage)) else if (event->matches(QKeySequence::MoveToPreviousPage))
{ {
@ -2495,6 +2514,7 @@ void QHexEdit::keyPressEvent(QKeyEvent *event)
vbar->setValue( lineOffset ); vbar->setValue( lineOffset );
resetCursor(); resetCursor();
update(); update();
event->accept();
} }
else if (event->matches(QKeySequence::MoveToEndOfDocument)) else if (event->matches(QKeySequence::MoveToEndOfDocument))
{ {
@ -2502,6 +2522,7 @@ void QHexEdit::keyPressEvent(QKeyEvent *event)
vbar->setValue( lineOffset ); vbar->setValue( lineOffset );
resetCursor(); resetCursor();
update(); update();
event->accept();
} }
else if (event->matches(QKeySequence::MoveToStartOfDocument)) else if (event->matches(QKeySequence::MoveToStartOfDocument))
{ {
@ -2509,41 +2530,47 @@ void QHexEdit::keyPressEvent(QKeyEvent *event)
vbar->setValue( lineOffset ); vbar->setValue( lineOffset );
resetCursor(); resetCursor();
update(); update();
event->accept();
} }
else if (Qt::ControlModifier == event->modifiers()) else if (Qt::ControlModifier == event->modifiers())
{ {
if ( event->key() == Qt::Key_A ) if ( event->key() == Qt::Key_A )
{ {
openGotoAddrDialog(); openGotoAddrDialog();
event->accept();
} }
} else if ( event->key() == Qt::Key_L )
else if (Qt::ShiftModifier == event->modifiers())
{
if ( event->key() == Qt::Key_F )
{ {
frzRamAddr = ctxAddr = cursorAddr; frzRamAddr = ctxAddr = cursorAddr;
frzRamToggle(); frzRamToggle();
event->accept();
} }
} }
else if (event->key() == Qt::Key_Tab && (cursorPosX < 32) ) else if (event->key() == Qt::Key_Tab && (cursorPosX < 32) )
{ // switch from hex to ascii edit { // switch from hex to ascii edit
cursorPosX = 32 + (cursorPosX / 2); cursorPosX = 32 + (cursorPosX / 2);
update(); update();
event->accept();
} }
else if (event->key() == Qt::Key_Backtab && (cursorPosX >= 32) ) else if (event->key() == Qt::Key_Backtab && (cursorPosX >= 32) )
{ // switch from ascii to hex edit { // switch from ascii to hex edit
cursorPosX = 2 * (cursorPosX - 32); cursorPosX = 2 * (cursorPosX - 32);
update(); update();
event->accept();
} }
else else
{ {
int key; int key;
if ( cursorPosX >= 32 ) if ( cursorPosX >= 32 )
{ // Edit Area is ASCII { // Edit Area is ASCII
key = (uchar)event->text()[0].toLatin1(); key = (int)event->text()[0].toLatin1();
if ( isascii( key ) ) if ( (key >= 0) && (key < 256) )
{ {
if ( charTable.rmap[key] != -1 )
{
key = charTable.rmap[key];
int offs = (cursorPosX-32); int offs = (cursorPosX-32);
int addr = 16*(lineOffset+cursorPosY) + offs; int addr = 16*(lineOffset+cursorPosY) + offs;
fceuWrapperLock(); fceuWrapperLock();
@ -2558,6 +2585,8 @@ void QHexEdit::keyPressEvent(QKeyEvent *event)
editValue = 0; editValue = 0;
editMask = 0; editMask = 0;
update(); update();
event->accept();
}
} }
} }
else else
@ -2603,6 +2632,7 @@ void QHexEdit::keyPressEvent(QKeyEvent *event)
cursorPosX = 0; cursorPosX = 0;
} }
update(); update();
event->accept();
} }
} }
//printf("Key: %c %i \n", key, key); //printf("Key: %c %i \n", key, key);
@ -2816,7 +2846,7 @@ void QHexEdit::contextMenuEvent(QContextMenuEvent *event)
subMenu = menu.addMenu(tr("&Freeze/Unfreeze Address")); subMenu = menu.addMenu(tr("&Freeze/Unfreeze Address"));
act = new QAction(tr("&Toggle State"), &menu); act = new QAction(tr("&Toggle State"), &menu);
act->setShortcut( QKeySequence(tr("Shift+F"))); act->setShortcut( QKeySequence(tr("Ctrl+L")));
subMenu->addAction(act); subMenu->addAction(act);
connect( act, SIGNAL(triggered(void)), this, SLOT(frzRamToggle(void)) ); connect( act, SIGNAL(triggered(void)), this, SLOT(frzRamToggle(void)) );
@ -3628,7 +3658,15 @@ void QHexEdit::paintEvent(QPaintEvent *event)
c = mb.buf[addr].data; c = mb.buf[addr].data;
asciiTxt.clear(); asciiTxt.clear();
if ( charTable.map[c] >= 0x20 )
{
asciiTxt += QChar(charTable.map[c]); asciiTxt += QChar(charTable.map[c]);
}
else
{
asciiTxt += QChar('.');
}
if ( addr == editAddr ) if ( addr == editAddr )
{ // Set a cell currently being editting to red text { // Set a cell currently being editting to red text

View File

@ -100,7 +100,8 @@ class HexEditorCharTable_t
HexEditorCharTable_t(void); HexEditorCharTable_t(void);
~HexEditorCharTable_t(void); ~HexEditorCharTable_t(void);
char map[256]; int map[256];
int rmap[256];
bool extAsciiEnable; bool extAsciiEnable;
bool customMapLoaded; bool customMapLoaded;