Search
lxdream.org :: lxdream/src/gui/dump_win.c :: diff
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 (16 years ago)
permissions -rw-r--r--
last change Commit changes into cvs
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/gui/dump_win.c Sat Aug 21 06:15:49 2004 +0000
1.3 @@ -0,0 +1,194 @@
1.4 +/**
1.5 + * Implements the memory dump window.
1.6 + */
1.7 +#include <gnome.h>
1.8 +#include <ctype.h>
1.9 +#include <assert.h>
1.10 +#include "gui.h"
1.11 +#include "interface.h"
1.12 +#include "mem.h"
1.13 +
1.14 +#define MAX_DUMP_SIZE 4096
1.15 +
1.16 +#define DUMP_DATA_TAG 0xD4B9DA7A
1.17 +
1.18 +typedef struct dump_data {
1.19 + uint32_t _tag;
1.20 + uint32_t start;
1.21 + uint32_t end;
1.22 + int flags;
1.23 + char *data;
1.24 +
1.25 + GtkEntry *fromInput, *toInput;
1.26 + GtkTextView *textArea;
1.27 + GtkTextTag *changedTag;
1.28 + GtkTextBuffer *textBuffer;
1.29 + struct dump_data *next;
1.30 +} *dump_data_t;
1.31 +
1.32 +static dump_data_t dump_list_head = NULL;
1.33 +
1.34 +gboolean on_dump_win_delete_event( GtkWidget *widget, GdkEvent *event,
1.35 + gpointer user_data );
1.36 +void on_dump_win_button_view_clicked( GtkWidget *widget, gpointer user_data );
1.37 +void dump_win_set_text( dump_data_t data, char *old_data, char *new_data );
1.38 +
1.39 +
1.40 +void dump_window_new( void ) {
1.41 + GtkWidget *win = create_dump_win();
1.42 + GtkWidget *dump_view_button = (GtkWidget *)g_object_get_data(G_OBJECT(win), "dump_view_button");
1.43 + dump_data_t data = malloc( sizeof(struct dump_data) );
1.44 + data->_tag = DUMP_DATA_TAG;
1.45 + data->fromInput = (GtkEntry *)g_object_get_data(G_OBJECT(win), "dump_from");
1.46 + data->toInput = (GtkEntry *)g_object_get_data(G_OBJECT(win), "dump_to");
1.47 + data->textArea = (GtkTextView *)g_object_get_data(G_OBJECT(win), "dump_text");
1.48 + data->next = dump_list_head;
1.49 + dump_list_head = data;
1.50 + data->data = NULL;
1.51 + data->start = 0;
1.52 + data->end = 0;
1.53 + gtk_entry_set_text( data->fromInput, "" );
1.54 + gtk_entry_set_text( data->toInput, "" );
1.55 + data->textBuffer = gtk_text_buffer_new(NULL);
1.56 + data->changedTag = gtk_text_buffer_create_tag(data->textBuffer, "changed",
1.57 + "foreground", "blue",
1.58 + NULL);
1.59 + gtk_text_view_set_buffer(data->textArea, data->textBuffer);
1.60 + gtk_text_view_set_editable(data->textArea, FALSE);
1.61 + gtk_widget_modify_font(GTK_WIDGET(data->textArea),fixed_list_font);
1.62 +
1.63 + g_signal_connect ((gpointer) win, "delete_event",
1.64 + G_CALLBACK (on_dump_win_delete_event),
1.65 + data);
1.66 + g_signal_connect ((gpointer) dump_view_button, "clicked",
1.67 + G_CALLBACK (on_dump_win_button_view_clicked),
1.68 + data);
1.69 + gtk_widget_show( GTK_WIDGET(win) );
1.70 +}
1.71 +
1.72 +
1.73 +
1.74 +gboolean on_dump_win_delete_event( GtkWidget *widget, GdkEvent *event,
1.75 + gpointer user_data )
1.76 +{
1.77 + dump_data_t data = (dump_data_t)user_data;
1.78 + if( data->data != NULL )
1.79 + free( data->data );
1.80 + dump_data_t node = dump_list_head;
1.81 + if( node == data )
1.82 + dump_list_head = data->next;
1.83 + else {
1.84 + while( node->next != data ) {
1.85 + node = node->next;
1.86 + assert( node != NULL );
1.87 + }
1.88 + node->next = data->next;
1.89 + }
1.90 + free( data );
1.91 + return FALSE;
1.92 +}
1.93 +
1.94 +void on_dump_win_button_view_clicked( GtkWidget *widget, gpointer user_data )
1.95 +{
1.96 + dump_data_t data = (dump_data_t)user_data;
1.97 + uint32_t startVal, endVal;
1.98 +
1.99 + assert( data != NULL );
1.100 + assert( data->_tag == DUMP_DATA_TAG );
1.101 +
1.102 + startVal = gtk_entry_get_hex_value(data->fromInput, data->start);
1.103 + endVal = gtk_entry_get_hex_value(data->toInput, data->end);
1.104 + if( startVal != data->start || endVal != data->end ) {
1.105 + if( startVal > endVal ) {
1.106 + int tmp = endVal;
1.107 + endVal = startVal;
1.108 + startVal = tmp;
1.109 + }
1.110 + if( endVal > startVal + MAX_DUMP_SIZE )
1.111 + endVal = startVal + MAX_DUMP_SIZE;
1.112 +
1.113 + gtk_entry_set_hex_value(data->fromInput,startVal);
1.114 + gtk_entry_set_hex_value(data->toInput,endVal);
1.115 + data->start = startVal;
1.116 + data->end = endVal;
1.117 +
1.118 + if( data->data != NULL ) {
1.119 + free( data->data );
1.120 + data->data = NULL;
1.121 + }
1.122 + if( startVal != endVal ) {
1.123 + data->data = malloc( endVal - startVal );
1.124 + mem_copy_from_sh4( data->data, startVal, endVal-startVal );
1.125 + dump_win_set_text( data, data->data, data->data );
1.126 + }
1.127 + }
1.128 +}
1.129 +
1.130 +void dump_win_update( dump_data_t data )
1.131 +{
1.132 + if( data->data == NULL )
1.133 + return;
1.134 + char tmp[data->end-data->start];
1.135 + int length = data->end-data->start;
1.136 + memcpy( tmp, data->data, length );
1.137 + mem_copy_from_sh4( data->data, data->start, length );
1.138 + dump_win_set_text( data, tmp, data->data );
1.139 +}
1.140 +
1.141 +void dump_win_update_all( )
1.142 +{
1.143 + dump_data_t node = dump_list_head;
1.144 + while( node != NULL ) {
1.145 + dump_win_update(node);
1.146 + node = node->next;
1.147 + }
1.148 +}
1.149 +
1.150 +void dump_win_set_text( dump_data_t data, char *old_data, char *new_data )
1.151 +{
1.152 + GtkTextBuffer *buf = data->textBuffer;
1.153 + GtkTextTag *changedTag = data->changedTag;
1.154 + GtkTextIter iter, endIter;
1.155 + int i, j, offset;
1.156 + /* Clear out the buffer */
1.157 + gtk_text_buffer_get_start_iter(buf,&iter);
1.158 + gtk_text_buffer_get_end_iter(buf,&endIter);
1.159 + gtk_text_buffer_delete(buf,&iter,&endIter);
1.160 + gtk_text_buffer_get_start_iter(buf,&iter);
1.161 +
1.162 + for( offset = 0, i=data->start; i<data->end; i+=16, offset+=16 ) {
1.163 + char text[80];
1.164 + sprintf(text, "%08X:", i );
1.165 + gtk_text_buffer_insert( buf, &iter, text, 9 );
1.166 + for( j=0; j<16; j++ ) {
1.167 + if( j%4 == 0 )
1.168 + gtk_text_buffer_insert( buf, &iter, " ", 1 );
1.169 + if( i+j < data->end ) {
1.170 + int oldVal = ((int)old_data[offset+j])&0xFF;
1.171 + int newVal = ((int)new_data[offset+j])&0xFF;
1.172 + sprintf(text, "%02X ", newVal);
1.173 + if( oldVal == newVal )
1.174 + gtk_text_buffer_insert( buf, &iter, text, 3 );
1.175 + else
1.176 + gtk_text_buffer_insert_with_tags( buf, &iter, text, 3,
1.177 + changedTag, NULL );
1.178 + } else {
1.179 + gtk_text_buffer_insert( buf, &iter, " ", 3 );
1.180 + }
1.181 + }
1.182 + gtk_text_buffer_insert( buf, &iter, " ", 2 );
1.183 + for( j=0; j<16 && i+j < data->end; j++ ) {
1.184 + int oldVal = ((int)old_data[offset+j])&0xFF;
1.185 + int newVal = ((int)new_data[offset+j])&0xFF;
1.186 + if( isprint(newVal) )
1.187 + sprintf( text, "%c", newVal );
1.188 + else strcpy( text, "." );
1.189 + if( oldVal == newVal )
1.190 + gtk_text_buffer_insert( buf, &iter, text, 1 );
1.191 + else
1.192 + gtk_text_buffer_insert_with_tags( buf, &iter, text, 1,
1.193 + changedTag, NULL );
1.194 + }
1.195 + gtk_text_buffer_insert( buf, &iter, "\n", 1 );
1.196 + }
1.197 +}
.