filename | src/gui/dump_win.c |
changeset | 31:495e480360d7 |
prev | 2:42349f6ea216 |
next | 430:467519b050f4 |
author | nkeynes |
date | Tue Dec 27 08:41:22 2005 +0000 (17 years ago) |
permissions | -rw-r--r-- |
last change | Fix output list click Fix mmr column widths Fix run-to for ARM |
view | annotate | diff | log | raw |
1 /**
2 * $Id: dump_win.c,v 1.2 2005-12-25 08:24:11 nkeynes Exp $
3 *
4 * Implements the memory dump window.
5 *
6 * Copyright (c) 2005 Nathan Keynes.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */
19 #include <gnome.h>
20 #include <ctype.h>
21 #include <assert.h>
22 #include "gui.h"
23 #include "interface.h"
24 #include "mem.h"
26 #define MAX_DUMP_SIZE 4096
28 #define DUMP_DATA_TAG 0xD4B9DA7A
30 typedef struct dump_data {
31 uint32_t _tag;
32 uint32_t start;
33 uint32_t end;
34 int flags;
35 char *data;
37 GtkEntry *fromInput, *toInput;
38 GtkTextView *textArea;
39 GtkTextTag *changedTag;
40 GtkTextBuffer *textBuffer;
41 struct dump_data *next;
42 } *dump_data_t;
44 static dump_data_t dump_list_head = NULL;
46 gboolean on_dump_win_delete_event( GtkWidget *widget, GdkEvent *event,
47 gpointer user_data );
48 void on_dump_win_button_view_clicked( GtkWidget *widget, gpointer user_data );
49 void dump_win_set_text( dump_data_t data, char *old_data, char *new_data );
52 void dump_window_new( void ) {
53 GtkWidget *win = create_dump_win();
54 GtkWidget *dump_view_button = (GtkWidget *)g_object_get_data(G_OBJECT(win), "dump_view_button");
55 dump_data_t data = malloc( sizeof(struct dump_data) );
56 data->_tag = DUMP_DATA_TAG;
57 data->fromInput = (GtkEntry *)g_object_get_data(G_OBJECT(win), "dump_from");
58 data->toInput = (GtkEntry *)g_object_get_data(G_OBJECT(win), "dump_to");
59 data->textArea = (GtkTextView *)g_object_get_data(G_OBJECT(win), "dump_text");
60 data->next = dump_list_head;
61 dump_list_head = data;
62 data->data = NULL;
63 data->start = 0;
64 data->end = 0;
65 gtk_entry_set_text( data->fromInput, "" );
66 gtk_entry_set_text( data->toInput, "" );
67 data->textBuffer = gtk_text_buffer_new(NULL);
68 data->changedTag = gtk_text_buffer_create_tag(data->textBuffer, "changed",
69 "foreground", "blue",
70 NULL);
71 gtk_text_view_set_buffer(data->textArea, data->textBuffer);
72 gtk_text_view_set_editable(data->textArea, FALSE);
73 gtk_widget_modify_font(GTK_WIDGET(data->textArea),fixed_list_font);
75 g_signal_connect ((gpointer) win, "delete_event",
76 G_CALLBACK (on_dump_win_delete_event),
77 data);
78 g_signal_connect ((gpointer) dump_view_button, "clicked",
79 G_CALLBACK (on_dump_win_button_view_clicked),
80 data);
81 gtk_widget_show( GTK_WIDGET(win) );
82 }
86 gboolean on_dump_win_delete_event( GtkWidget *widget, GdkEvent *event,
87 gpointer user_data )
88 {
89 dump_data_t data = (dump_data_t)user_data;
90 if( data->data != NULL )
91 free( data->data );
92 dump_data_t node = dump_list_head;
93 if( node == data )
94 dump_list_head = data->next;
95 else {
96 while( node->next != data ) {
97 node = node->next;
98 assert( node != NULL );
99 }
100 node->next = data->next;
101 }
102 free( data );
103 return FALSE;
104 }
106 void on_dump_win_button_view_clicked( GtkWidget *widget, gpointer user_data )
107 {
108 dump_data_t data = (dump_data_t)user_data;
109 uint32_t startVal, endVal;
111 assert( data != NULL );
112 assert( data->_tag == DUMP_DATA_TAG );
114 startVal = gtk_entry_get_hex_value(data->fromInput, data->start);
115 endVal = gtk_entry_get_hex_value(data->toInput, data->end);
116 if( startVal != data->start || endVal != data->end ) {
117 if( startVal > endVal ) {
118 int tmp = endVal;
119 endVal = startVal;
120 startVal = tmp;
121 }
122 if( endVal > startVal + MAX_DUMP_SIZE )
123 endVal = startVal + MAX_DUMP_SIZE;
125 gtk_entry_set_hex_value(data->fromInput,startVal);
126 gtk_entry_set_hex_value(data->toInput,endVal);
127 data->start = startVal;
128 data->end = endVal;
130 if( data->data != NULL ) {
131 free( data->data );
132 data->data = NULL;
133 }
134 if( startVal != endVal ) {
135 data->data = malloc( endVal - startVal );
136 mem_copy_from_sh4( data->data, startVal, endVal-startVal );
137 dump_win_set_text( data, data->data, data->data );
138 }
139 }
140 }
142 void dump_win_update( dump_data_t data )
143 {
144 if( data->data == NULL )
145 return;
146 char tmp[data->end-data->start];
147 int length = data->end-data->start;
148 memcpy( tmp, data->data, length );
149 mem_copy_from_sh4( data->data, data->start, length );
150 dump_win_set_text( data, tmp, data->data );
151 }
153 void dump_win_update_all( )
154 {
155 dump_data_t node = dump_list_head;
156 while( node != NULL ) {
157 dump_win_update(node);
158 node = node->next;
159 }
160 }
162 void dump_win_set_text( dump_data_t data, char *old_data, char *new_data )
163 {
164 GtkTextBuffer *buf = data->textBuffer;
165 GtkTextTag *changedTag = data->changedTag;
166 GtkTextIter iter, endIter;
167 int i, j, offset;
168 /* Clear out the buffer */
169 gtk_text_buffer_get_start_iter(buf,&iter);
170 gtk_text_buffer_get_end_iter(buf,&endIter);
171 gtk_text_buffer_delete(buf,&iter,&endIter);
172 gtk_text_buffer_get_start_iter(buf,&iter);
174 for( offset = 0, i=data->start; i<data->end; i+=16, offset+=16 ) {
175 char text[80];
176 sprintf(text, "%08X:", i );
177 gtk_text_buffer_insert( buf, &iter, text, 9 );
178 for( j=0; j<16; j++ ) {
179 if( j%4 == 0 )
180 gtk_text_buffer_insert( buf, &iter, " ", 1 );
181 if( i+j < data->end ) {
182 int oldVal = ((int)old_data[offset+j])&0xFF;
183 int newVal = ((int)new_data[offset+j])&0xFF;
184 sprintf(text, "%02X ", newVal);
185 if( oldVal == newVal )
186 gtk_text_buffer_insert( buf, &iter, text, 3 );
187 else
188 gtk_text_buffer_insert_with_tags( buf, &iter, text, 3,
189 changedTag, NULL );
190 } else {
191 gtk_text_buffer_insert( buf, &iter, " ", 3 );
192 }
193 }
194 gtk_text_buffer_insert( buf, &iter, " ", 2 );
195 for( j=0; j<16 && i+j < data->end; j++ ) {
196 int oldVal = ((int)old_data[offset+j])&0xFF;
197 int newVal = ((int)new_data[offset+j])&0xFF;
198 if( isprint(newVal) )
199 sprintf( text, "%c", newVal );
200 else strcpy( text, "." );
201 if( oldVal == newVal )
202 gtk_text_buffer_insert( buf, &iter, text, 1 );
203 else
204 gtk_text_buffer_insert_with_tags( buf, &iter, text, 1,
205 changedTag, NULL );
206 }
207 gtk_text_buffer_insert( buf, &iter, "\n", 1 );
208 }
209 }
.