Improved logic for hex editor button inputs.
This commit is contained in:
parent
0d9b9254ff
commit
5e0cbc1cbc
|
@ -2360,7 +2360,7 @@ unsigned short GDKToSDLKeyval (int gdk_key)
|
||||||
|
|
||||||
|
|
||||||
// Function adapted from Gens/GS (source/gens/input/input_sdl.c)
|
// Function adapted from Gens/GS (source/gens/input/input_sdl.c)
|
||||||
static gint convertKeypress (GtkWidget * grab, GdkEventKey * event,
|
static gboolean convertKeypress (GtkWidget * grab, GdkEventKey * event,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
SDL_Event sdlev;
|
SDL_Event sdlev;
|
||||||
|
|
|
@ -333,9 +333,8 @@ void memViewWin_t::showMemViewResults (int reset)
|
||||||
int i, row, row_start, row_end, totalChars;
|
int i, row, row_start, row_end, totalChars;
|
||||||
gint cpos;
|
gint cpos;
|
||||||
char addrStr[128], valStr[16][8], ascii[18];
|
char addrStr[128], valStr[16][8], ascii[18];
|
||||||
char row_changed;
|
char addrChg, valChg[16];
|
||||||
std::string line;
|
GtkTextIter iter, next_iter, start_iter, end_iter;
|
||||||
GtkTextIter iter, start_iter, end_iter;
|
|
||||||
|
|
||||||
if ( redraw )
|
if ( redraw )
|
||||||
{
|
{
|
||||||
|
@ -404,40 +403,68 @@ void memViewWin_t::showMemViewResults (int reset)
|
||||||
|
|
||||||
row_start = 0;
|
row_start = 0;
|
||||||
row_end = numLines;
|
row_end = numLines;
|
||||||
|
|
||||||
|
gtk_text_buffer_get_iter_at_offset( textbuf, &iter, 0 );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
calcVisibleRange( &row_start, &row_end, NULL );
|
calcVisibleRange( &row_start, &row_end, NULL );
|
||||||
|
|
||||||
|
gtk_text_buffer_get_iter_at_line( textbuf, &iter, row_start );
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_text_buffer_get_iter_at_offset( textbuf, &iter, 0 );
|
//gtk_text_buffer_get_iter_at_offset( textbuf, &iter, 0 );
|
||||||
|
|
||||||
totalChars = row_start * numCharsPerLine;
|
totalChars = row_start * numCharsPerLine;
|
||||||
|
|
||||||
for (row=row_start; row<row_end; row++)
|
for (row=row_start; row<row_end; row++)
|
||||||
{
|
{
|
||||||
gtk_text_buffer_get_iter_at_offset( textbuf, &iter, totalChars );
|
//gtk_text_buffer_get_iter_at_offset( textbuf, &iter, totalChars );
|
||||||
|
|
||||||
row_changed = 1;
|
addrChg = reset;
|
||||||
|
|
||||||
line.clear();
|
|
||||||
|
|
||||||
lineAddr = (row*16);
|
lineAddr = (row*16);
|
||||||
|
|
||||||
|
if ( addrChg )
|
||||||
|
{
|
||||||
|
next_iter = iter;
|
||||||
|
gtk_text_iter_forward_chars( &next_iter, 9 );
|
||||||
|
|
||||||
sprintf( addrStr, "%08X ", lineAddr );
|
sprintf( addrStr, "%08X ", lineAddr );
|
||||||
|
|
||||||
|
if ( !reset )
|
||||||
|
{
|
||||||
|
gtk_text_buffer_delete( textbuf, &iter, &next_iter );
|
||||||
|
}
|
||||||
|
gtk_text_buffer_insert( textbuf, &iter, addrStr, -1 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gtk_text_iter_forward_chars( &iter, 9 );
|
||||||
|
}
|
||||||
|
|
||||||
for (i=0; i<16; i++)
|
for (i=0; i<16; i++)
|
||||||
{
|
{
|
||||||
|
valChg[i] = reset;
|
||||||
|
|
||||||
addr = lineAddr+i;
|
addr = lineAddr+i;
|
||||||
|
|
||||||
c = memAccessFunc(addr);
|
c = memAccessFunc(addr);
|
||||||
|
|
||||||
|
if ( c != mbuf[addr] )
|
||||||
|
{
|
||||||
|
valChg[i] = 1;
|
||||||
|
mbuf[addr] = c;
|
||||||
|
}
|
||||||
|
|
||||||
un = ( c & 0x00f0 ) >> 4;
|
un = ( c & 0x00f0 ) >> 4;
|
||||||
ln = ( c & 0x000f );
|
ln = ( c & 0x000f );
|
||||||
|
|
||||||
valStr[i][0] = conv2xchar(un);
|
valStr[i][0] = ' ';
|
||||||
valStr[i][1] = conv2xchar(ln);
|
valStr[i][1] = conv2xchar(un);
|
||||||
valStr[i][2] = 0;
|
valStr[i][2] = conv2xchar(ln);
|
||||||
|
valStr[i][3] = ' ';
|
||||||
|
valStr[i][4] = 0;
|
||||||
|
|
||||||
if ( isprint(c) )
|
if ( isprint(c) )
|
||||||
{
|
{
|
||||||
|
@ -447,46 +474,73 @@ void memViewWin_t::showMemViewResults (int reset)
|
||||||
{
|
{
|
||||||
ascii[i] = '.';
|
ascii[i] = '.';
|
||||||
}
|
}
|
||||||
if ( c != mbuf[addr] )
|
|
||||||
|
if ( valChg[i] )
|
||||||
{
|
{
|
||||||
row_changed = 1;
|
next_iter = iter;
|
||||||
mbuf[addr] = c;
|
gtk_text_iter_forward_chars( &next_iter, 4 );
|
||||||
|
|
||||||
|
if ( !reset )
|
||||||
|
{
|
||||||
|
gtk_text_buffer_delete( textbuf, &iter, &next_iter );
|
||||||
|
}
|
||||||
|
gtk_text_buffer_insert( textbuf, &iter, valStr[i], -1 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gtk_text_iter_forward_chars( &iter, 4 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ascii[16] = 0;
|
ascii[16] = 0;
|
||||||
|
|
||||||
line.assign( addrStr );
|
|
||||||
|
|
||||||
for (i=0; i<16; i++)
|
for (i=0; i<16; i++)
|
||||||
{
|
{
|
||||||
line.append( " ");
|
if ( valChg[i] )
|
||||||
line.append( valStr[i] );
|
{
|
||||||
line.append( " ");
|
next_iter = iter;
|
||||||
|
gtk_text_iter_forward_chars( &next_iter, 1 );
|
||||||
|
|
||||||
|
if ( !reset )
|
||||||
|
{
|
||||||
|
gtk_text_buffer_delete( textbuf, &iter, &next_iter );
|
||||||
}
|
}
|
||||||
line.append( ascii );
|
gtk_text_buffer_insert( textbuf, &iter, &ascii[i], 1 );
|
||||||
line.append( "\n");
|
|
||||||
|
|
||||||
numCharsPerLine = line.size();
|
|
||||||
|
|
||||||
if ( row_changed )
|
|
||||||
{
|
|
||||||
if ( reset )
|
|
||||||
{
|
|
||||||
gtk_text_buffer_get_iter_at_offset( textbuf, &iter, totalChars );
|
|
||||||
gtk_text_buffer_insert ( textbuf, &iter, line.c_str(), -1 );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GtkTextIter next_iter;
|
gtk_text_iter_forward_chars( &iter, 1 );
|
||||||
|
|
||||||
gtk_text_buffer_get_iter_at_offset( textbuf, &next_iter, totalChars + numCharsPerLine - 1 );
|
|
||||||
gtk_text_buffer_delete ( textbuf, &iter, &next_iter );
|
|
||||||
|
|
||||||
gtk_text_buffer_get_iter_at_offset( textbuf, &iter, totalChars );
|
|
||||||
gtk_text_buffer_insert ( textbuf, &iter, line.c_str(), line.size()-1 );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
numCharsPerLine = 9 + (4*16) + 16 + 1;
|
||||||
|
|
||||||
|
if ( reset )
|
||||||
|
{
|
||||||
|
gtk_text_buffer_insert ( textbuf, &iter, "\n", -1 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gtk_text_iter_forward_chars( &iter, 1 );
|
||||||
|
}
|
||||||
|
//if ( row_changed )
|
||||||
|
//{
|
||||||
|
// if ( reset )
|
||||||
|
// {
|
||||||
|
// gtk_text_buffer_get_iter_at_offset( textbuf, &iter, totalChars );
|
||||||
|
// gtk_text_buffer_insert ( textbuf, &iter, line.c_str(), -1 );
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// GtkTextIter next_iter;
|
||||||
|
|
||||||
|
// gtk_text_buffer_get_iter_at_offset( textbuf, &next_iter, totalChars + numCharsPerLine - 1 );
|
||||||
|
// gtk_text_buffer_delete ( textbuf, &iter, &next_iter );
|
||||||
|
|
||||||
|
// gtk_text_buffer_get_iter_at_offset( textbuf, &iter, totalChars );
|
||||||
|
// gtk_text_buffer_insert ( textbuf, &iter, line.c_str(), line.size()-1 );
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
totalChars += numCharsPerLine;
|
totalChars += numCharsPerLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -711,19 +765,22 @@ textview_string_insert (GtkTextView *text_view,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
//static void
|
||||||
textbuffer_string_insert (GtkTextBuffer *textbuffer,
|
//textbuffer_string_insert (GtkTextBuffer *textbuffer,
|
||||||
GtkTextIter *location,
|
// GtkTextIter *location,
|
||||||
gchar *text,
|
// gchar *text,
|
||||||
gint len,
|
// gint len,
|
||||||
memViewWin_t * mv )
|
// memViewWin_t * mv )
|
||||||
|
static gboolean textbuffer_string_insert (GtkWidget * grab, GdkEventKey * event, memViewWin_t * mv)
|
||||||
{
|
{
|
||||||
if ( len == 1 )
|
|
||||||
{
|
|
||||||
int addr, line, offs, byte0, byte, bcol, c, d;
|
int addr, line, offs, byte0, byte, bcol, c, d;
|
||||||
|
gint cpos;
|
||||||
|
gboolean stopKeyPropagate = TRUE;
|
||||||
|
|
||||||
line = gtk_text_iter_get_line( location ),
|
g_object_get( mv->textbuf, "cursor-position", &cpos, NULL );
|
||||||
offs = gtk_text_iter_get_line_offset( location );
|
|
||||||
|
line = cpos / mv->numCharsPerLine;
|
||||||
|
offs = cpos % mv->numCharsPerLine;
|
||||||
|
|
||||||
byte0 = (offs - 10);
|
byte0 = (offs - 10);
|
||||||
|
|
||||||
|
@ -733,13 +790,47 @@ textbuffer_string_insert (GtkTextBuffer *textbuffer,
|
||||||
addr = (line*16) + byte;
|
addr = (line*16) + byte;
|
||||||
|
|
||||||
//printf("Line: %i Offset: %i Byte:%i Bcol:%i\n", line, offs, byte, bcol );
|
//printf("Line: %i Offset: %i Byte:%i Bcol:%i\n", line, offs, byte, bcol );
|
||||||
//printf("Text: '%s' \n", text );
|
|
||||||
|
|
||||||
if ( !isxdigit( text[0] ) )
|
d = event->keyval;
|
||||||
|
|
||||||
|
//printf("Key: %i '%c' \n", d, d );
|
||||||
|
|
||||||
|
stopKeyPropagate = (d != GDK_KEY_Up ) &&
|
||||||
|
(d != GDK_KEY_Down ) &&
|
||||||
|
(d != GDK_KEY_Left ) &&
|
||||||
|
(d != GDK_KEY_Right ) &&
|
||||||
|
(d != GDK_KEY_Page_Up ) &&
|
||||||
|
(d != GDK_KEY_Page_Down);
|
||||||
|
|
||||||
|
if ( !isascii( d ) )
|
||||||
{
|
{
|
||||||
return;
|
return stopKeyPropagate;
|
||||||
}
|
}
|
||||||
d = text[0];
|
|
||||||
|
if ( offs > (9 + (16*4)) )
|
||||||
|
{ // ASCII Text Area
|
||||||
|
byte = (offs - 73);
|
||||||
|
|
||||||
|
if ( (byte < 0) || (byte >= 16) )
|
||||||
|
{
|
||||||
|
return stopKeyPropagate;
|
||||||
|
}
|
||||||
|
addr = (line*16) + byte;
|
||||||
|
|
||||||
|
c = d;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // Hex Text Area
|
||||||
|
if ( !isxdigit( d ) )
|
||||||
|
{
|
||||||
|
return stopKeyPropagate;
|
||||||
|
}
|
||||||
|
byte0 = (offs - 10);
|
||||||
|
|
||||||
|
byte = byte0 / 4;
|
||||||
|
bcol = byte0 % 4;
|
||||||
|
|
||||||
|
addr = (line*16) + byte;
|
||||||
|
|
||||||
if ( (d >= '0') && (d <= '9') )
|
if ( (d >= '0') && (d <= '9') )
|
||||||
{
|
{
|
||||||
|
@ -768,10 +859,13 @@ textbuffer_string_insert (GtkTextBuffer *textbuffer,
|
||||||
c = c & 0xf0;
|
c = c & 0xf0;
|
||||||
c = c | d;
|
c = c | d;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//printf(" to:0x%02x \n", c );
|
//printf(" to:0x%02x \n", c );
|
||||||
|
|
||||||
mv->writeMem( addr, c );
|
mv->writeMem( addr, c );
|
||||||
}
|
|
||||||
|
// Return wether to allow GTK+ to process this key.
|
||||||
|
return stopKeyPropagate;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1116,7 +1210,9 @@ void openMemoryViewWindow (void)
|
||||||
|
|
||||||
mv->textbuf = gtk_text_view_get_buffer( mv->textview );
|
mv->textbuf = gtk_text_view_get_buffer( mv->textview );
|
||||||
|
|
||||||
g_signal_connect (mv->textbuf, "insert-text",
|
//g_signal_connect (mv->textbuf, "insert-text",
|
||||||
|
// G_CALLBACK (textbuffer_string_insert), mv);
|
||||||
|
g_signal_connect (G_OBJECT (mv->textview), "key-press-event",
|
||||||
G_CALLBACK (textbuffer_string_insert), mv);
|
G_CALLBACK (textbuffer_string_insert), mv);
|
||||||
|
|
||||||
scroll = gtk_scrolled_window_new (NULL, NULL);
|
scroll = gtk_scrolled_window_new (NULL, NULL);
|
||||||
|
|
Loading…
Reference in New Issue