Search
lxdream.org :: lxdream/src/gui/dump_win.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/dump_win.c
changeset 2:42349f6ea216
next31:495e480360d7
author nkeynes
date Sat Aug 21 06:15:49 2004 +0000 (15 years ago)
permissions -rw-r--r--
last change Commit changes into cvs
file annotate diff log raw
nkeynes@2
     1
/**
nkeynes@2
     2
 * Implements the memory dump window.
nkeynes@2
     3
 */
nkeynes@2
     4
#include <gnome.h>
nkeynes@2
     5
#include <ctype.h>
nkeynes@2
     6
#include <assert.h>
nkeynes@2
     7
#include "gui.h"
nkeynes@2
     8
#include "interface.h"
nkeynes@2
     9
#include "mem.h"
nkeynes@2
    10
nkeynes@2
    11
#define MAX_DUMP_SIZE 4096
nkeynes@2
    12
nkeynes@2
    13
#define DUMP_DATA_TAG 0xD4B9DA7A
nkeynes@2
    14
nkeynes@2
    15
typedef struct dump_data {
nkeynes@2
    16
    uint32_t _tag;
nkeynes@2
    17
    uint32_t start;
nkeynes@2
    18
    uint32_t end;
nkeynes@2
    19
    int flags;
nkeynes@2
    20
    char *data;
nkeynes@2
    21
nkeynes@2
    22
    GtkEntry *fromInput, *toInput;
nkeynes@2
    23
    GtkTextView *textArea;
nkeynes@2
    24
    GtkTextTag *changedTag;
nkeynes@2
    25
    GtkTextBuffer *textBuffer;
nkeynes@2
    26
    struct dump_data *next;
nkeynes@2
    27
} *dump_data_t;
nkeynes@2
    28
nkeynes@2
    29
static dump_data_t dump_list_head = NULL;
nkeynes@2
    30
nkeynes@2
    31
gboolean on_dump_win_delete_event( GtkWidget *widget, GdkEvent *event,
nkeynes@2
    32
                                   gpointer user_data );
nkeynes@2
    33
void on_dump_win_button_view_clicked( GtkWidget *widget, gpointer user_data );
nkeynes@2
    34
void dump_win_set_text( dump_data_t data, char *old_data, char *new_data );
nkeynes@2
    35
nkeynes@2
    36
nkeynes@2
    37
void dump_window_new( void ) {
nkeynes@2
    38
    GtkWidget *win = create_dump_win();
nkeynes@2
    39
    GtkWidget *dump_view_button = (GtkWidget *)g_object_get_data(G_OBJECT(win), "dump_view_button");
nkeynes@2
    40
    dump_data_t data = malloc( sizeof(struct dump_data) );
nkeynes@2
    41
    data->_tag = DUMP_DATA_TAG;
nkeynes@2
    42
    data->fromInput = (GtkEntry *)g_object_get_data(G_OBJECT(win), "dump_from");
nkeynes@2
    43
    data->toInput = (GtkEntry *)g_object_get_data(G_OBJECT(win), "dump_to");
nkeynes@2
    44
    data->textArea = (GtkTextView *)g_object_get_data(G_OBJECT(win), "dump_text");
nkeynes@2
    45
    data->next = dump_list_head;
nkeynes@2
    46
    dump_list_head = data;
nkeynes@2
    47
    data->data = NULL;
nkeynes@2
    48
    data->start = 0;
nkeynes@2
    49
    data->end = 0;
nkeynes@2
    50
    gtk_entry_set_text( data->fromInput, "" );
nkeynes@2
    51
    gtk_entry_set_text( data->toInput, "" );
nkeynes@2
    52
    data->textBuffer = gtk_text_buffer_new(NULL);
nkeynes@2
    53
    data->changedTag = gtk_text_buffer_create_tag(data->textBuffer, "changed",
nkeynes@2
    54
                                                 "foreground", "blue",
nkeynes@2
    55
                                                  NULL);
nkeynes@2
    56
    gtk_text_view_set_buffer(data->textArea, data->textBuffer);
nkeynes@2
    57
    gtk_text_view_set_editable(data->textArea, FALSE);
nkeynes@2
    58
    gtk_widget_modify_font(GTK_WIDGET(data->textArea),fixed_list_font);
nkeynes@2
    59
        
nkeynes@2
    60
    g_signal_connect ((gpointer) win, "delete_event",
nkeynes@2
    61
                      G_CALLBACK (on_dump_win_delete_event),
nkeynes@2
    62
                      data);
nkeynes@2
    63
    g_signal_connect ((gpointer) dump_view_button, "clicked",
nkeynes@2
    64
                      G_CALLBACK (on_dump_win_button_view_clicked),
nkeynes@2
    65
                      data);
nkeynes@2
    66
    gtk_widget_show( GTK_WIDGET(win) );
nkeynes@2
    67
}
nkeynes@2
    68
nkeynes@2
    69
nkeynes@2
    70
        
nkeynes@2
    71
gboolean on_dump_win_delete_event( GtkWidget *widget, GdkEvent *event,
nkeynes@2
    72
                                   gpointer user_data )
nkeynes@2
    73
{
nkeynes@2
    74
    dump_data_t data = (dump_data_t)user_data;
nkeynes@2
    75
    if( data->data != NULL )
nkeynes@2
    76
        free( data->data );
nkeynes@2
    77
    dump_data_t node = dump_list_head;
nkeynes@2
    78
    if( node == data )
nkeynes@2
    79
        dump_list_head = data->next;
nkeynes@2
    80
    else {
nkeynes@2
    81
        while( node->next != data ) {
nkeynes@2
    82
            node = node->next;
nkeynes@2
    83
            assert( node != NULL );
nkeynes@2
    84
        }
nkeynes@2
    85
        node->next = data->next;
nkeynes@2
    86
    }
nkeynes@2
    87
    free( data );
nkeynes@2
    88
    return FALSE;
nkeynes@2
    89
}
nkeynes@2
    90
nkeynes@2
    91
void on_dump_win_button_view_clicked( GtkWidget *widget, gpointer user_data )
nkeynes@2
    92
{
nkeynes@2
    93
    dump_data_t data = (dump_data_t)user_data;
nkeynes@2
    94
    uint32_t startVal, endVal;
nkeynes@2
    95
nkeynes@2
    96
    assert( data != NULL );
nkeynes@2
    97
    assert( data->_tag == DUMP_DATA_TAG );
nkeynes@2
    98
    
nkeynes@2
    99
    startVal = gtk_entry_get_hex_value(data->fromInput, data->start);
nkeynes@2
   100
    endVal = gtk_entry_get_hex_value(data->toInput, data->end);
nkeynes@2
   101
    if( startVal != data->start || endVal != data->end ) {
nkeynes@2
   102
        if( startVal > endVal ) {
nkeynes@2
   103
            int tmp = endVal;
nkeynes@2
   104
            endVal = startVal;
nkeynes@2
   105
            startVal = tmp;
nkeynes@2
   106
        }
nkeynes@2
   107
        if( endVal > startVal + MAX_DUMP_SIZE )
nkeynes@2
   108
            endVal = startVal + MAX_DUMP_SIZE;
nkeynes@2
   109
nkeynes@2
   110
        gtk_entry_set_hex_value(data->fromInput,startVal);
nkeynes@2
   111
        gtk_entry_set_hex_value(data->toInput,endVal);
nkeynes@2
   112
        data->start = startVal;
nkeynes@2
   113
        data->end = endVal;
nkeynes@2
   114
nkeynes@2
   115
        if( data->data != NULL ) {
nkeynes@2
   116
            free( data->data );
nkeynes@2
   117
            data->data = NULL;
nkeynes@2
   118
        }
nkeynes@2
   119
        if( startVal != endVal ) {
nkeynes@2
   120
            data->data = malloc( endVal - startVal );
nkeynes@2
   121
            mem_copy_from_sh4( data->data, startVal, endVal-startVal );
nkeynes@2
   122
            dump_win_set_text( data, data->data, data->data );
nkeynes@2
   123
        }
nkeynes@2
   124
    }
nkeynes@2
   125
}
nkeynes@2
   126
nkeynes@2
   127
void dump_win_update( dump_data_t data )
nkeynes@2
   128
{
nkeynes@2
   129
    if( data->data == NULL )
nkeynes@2
   130
        return;
nkeynes@2
   131
    char tmp[data->end-data->start];
nkeynes@2
   132
    int length = data->end-data->start;
nkeynes@2
   133
    memcpy( tmp, data->data, length );
nkeynes@2
   134
    mem_copy_from_sh4( data->data, data->start, length );
nkeynes@2
   135
    dump_win_set_text( data, tmp, data->data );
nkeynes@2
   136
}
nkeynes@2
   137
nkeynes@2
   138
void dump_win_update_all( )
nkeynes@2
   139
{
nkeynes@2
   140
    dump_data_t node = dump_list_head;
nkeynes@2
   141
    while( node != NULL ) {
nkeynes@2
   142
        dump_win_update(node);
nkeynes@2
   143
        node = node->next;
nkeynes@2
   144
    }
nkeynes@2
   145
}
nkeynes@2
   146
nkeynes@2
   147
void dump_win_set_text( dump_data_t data, char *old_data, char *new_data )
nkeynes@2
   148
{
nkeynes@2
   149
    GtkTextBuffer *buf = data->textBuffer;
nkeynes@2
   150
    GtkTextTag *changedTag = data->changedTag;
nkeynes@2
   151
    GtkTextIter iter, endIter;
nkeynes@2
   152
    int i, j, offset;
nkeynes@2
   153
    /* Clear out the buffer */
nkeynes@2
   154
    gtk_text_buffer_get_start_iter(buf,&iter);
nkeynes@2
   155
    gtk_text_buffer_get_end_iter(buf,&endIter);
nkeynes@2
   156
    gtk_text_buffer_delete(buf,&iter,&endIter);
nkeynes@2
   157
    gtk_text_buffer_get_start_iter(buf,&iter);
nkeynes@2
   158
    
nkeynes@2
   159
    for( offset = 0, i=data->start; i<data->end; i+=16, offset+=16 ) {
nkeynes@2
   160
        char text[80];
nkeynes@2
   161
        sprintf(text, "%08X:", i );
nkeynes@2
   162
        gtk_text_buffer_insert( buf, &iter, text, 9 );
nkeynes@2
   163
        for( j=0; j<16; j++ ) {
nkeynes@2
   164
            if( j%4 == 0 )
nkeynes@2
   165
                gtk_text_buffer_insert( buf, &iter, " ", 1 );
nkeynes@2
   166
            if( i+j < data->end ) {
nkeynes@2
   167
                int oldVal = ((int)old_data[offset+j])&0xFF;
nkeynes@2
   168
                int newVal = ((int)new_data[offset+j])&0xFF;
nkeynes@2
   169
                sprintf(text, "%02X ", newVal);
nkeynes@2
   170
                if( oldVal == newVal )
nkeynes@2
   171
                    gtk_text_buffer_insert( buf, &iter, text, 3 );
nkeynes@2
   172
                else
nkeynes@2
   173
                    gtk_text_buffer_insert_with_tags( buf, &iter, text, 3,
nkeynes@2
   174
                                                      changedTag, NULL );
nkeynes@2
   175
            } else {
nkeynes@2
   176
                gtk_text_buffer_insert( buf, &iter, "   ", 3 );
nkeynes@2
   177
            }
nkeynes@2
   178
        }
nkeynes@2
   179
        gtk_text_buffer_insert( buf, &iter, "  ", 2 );
nkeynes@2
   180
        for( j=0; j<16 && i+j < data->end; j++ ) {
nkeynes@2
   181
            int oldVal = ((int)old_data[offset+j])&0xFF;
nkeynes@2
   182
            int newVal = ((int)new_data[offset+j])&0xFF;
nkeynes@2
   183
            if( isprint(newVal) )
nkeynes@2
   184
                sprintf( text, "%c", newVal );
nkeynes@2
   185
            else strcpy( text, "." );
nkeynes@2
   186
            if( oldVal == newVal )
nkeynes@2
   187
                gtk_text_buffer_insert( buf, &iter, text, 1 );
nkeynes@2
   188
            else
nkeynes@2
   189
                gtk_text_buffer_insert_with_tags( buf, &iter, text, 1,
nkeynes@2
   190
                                                  changedTag, NULL );
nkeynes@2
   191
        }
nkeynes@2
   192
        gtk_text_buffer_insert( buf, &iter, "\n", 1 );
nkeynes@2
   193
    }
nkeynes@2
   194
}
.