1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
/* memory.c: the GTK+ memory browser
Copyright (c) 2004-2005 Philip Kendall
$Id: memory.c 3115 2007-08-19 02:49:14Z fredm $
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Author contact information:
E-mail: philip-fuse@shadowmagic.org.uk
*/
#include <config.h>
#include <stdio.h>
#include <string.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include "compat.h"
#include "gtkinternals.h"
#include "memory.h"
#include "menu.h"
static void
update_display( GtkCList *clist, libspectrum_word base )
{
size_t i, j;
gchar buffer[ 8 + 64 + 20 ];
gchar *text[] = { &buffer[0], &buffer[ 8 ], &buffer[ 8 + 64 ] };
char buffer2[ 8 ];
gtk_clist_freeze( clist );
gtk_clist_clear( clist );
for( i = 0; i < 20; i++ ) {
snprintf( text[0], 8, "%04X", base );
text[1][0] = '\0';
for( j = 0; j < 0x10; j++, base++ ) {
libspectrum_byte b = readbyte_internal( base );
snprintf( buffer2, 4, "%02X ", b );
strncat( text[1], buffer2, 4 );
text[2][j] = ( b >= 32 && b < 127 ) ? b : '.';
}
text[2][ 0x10 ] = '\0';
gtk_clist_append( clist, text );
}
gtk_clist_thaw( clist );
}
static void
scroller( GtkAdjustment *adjustment, gpointer user_data )
{
libspectrum_word base;
GtkCList *clist = user_data;
/* Drop the low bits before displaying anything */
base = adjustment->value; base &= 0xfff0;
update_display( clist, base );
}
void
menu_machine_memorybrowser( GtkWidget *widget GCC_UNUSED,
gpointer data GCC_UNUSED )
{
GtkWidget *dialog, *box, *clist, *scrollbar;
GtkObject *adjustment;
size_t i;
int error;
gtkui_font font;
gchar *titles[] = { "Address", "Hex", "Data" };
error = gtkui_get_monospaced_font( &font ); if( error ) return;
dialog = gtkstock_dialog_new( "Fuse - Memory Browser", NULL );
gtkstock_create_close( dialog, NULL, NULL, FALSE );
box = gtk_hbox_new( FALSE, 0 );
gtk_box_pack_start_defaults( GTK_BOX( GTK_DIALOG( dialog )->vbox ), box );
clist = gtk_clist_new_with_titles( 3, titles );
gtk_clist_column_titles_passive( GTK_CLIST( clist ) );
for( i = 0; i < 3; i++ )
gtk_clist_set_column_auto_resize( GTK_CLIST( clist ), i, TRUE );
gtkui_set_font( clist, font );
update_display( GTK_CLIST( clist ), 0x0000 );
gtk_box_pack_start_defaults( GTK_BOX( box ), clist );
adjustment = gtk_adjustment_new( 0, 0x0000, 0xffff, 0x10, 0xa0, 0x13f );
gtk_signal_connect( adjustment, "value-changed", GTK_SIGNAL_FUNC( scroller ),
clist );
gtkui_scroll_connect( GTK_CLIST( clist ), GTK_ADJUSTMENT( adjustment ) );
scrollbar = gtk_vscrollbar_new( GTK_ADJUSTMENT( adjustment ) );
gtk_box_pack_start( GTK_BOX( box ), scrollbar, FALSE, FALSE, 0 );
gtk_widget_show_all( dialog );
gtk_main();
gtkui_free_font( font );
return;
}
|