Search
lxdream.org :: lxdream/src/gui/gui_mmr.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gui_mmr.c
changeset 1:eea311cfd33e
author nkeynes
date Mon Dec 12 10:37:41 2005 +0000 (15 years ago)
permissions -rw-r--r--
last change Use cpu-specific is_valid_page function
view annotate diff log raw
     1 #include <stdint.h>
     2 #include <gnome.h>
     3 #include "interface.h"
     4 #include "gui.h"
     5 #include "mem.h"
     6 #include "mmio.h"
     8 GtkWidget *mmr_win;
     9 GtkNotebook *mmr_book;
    11 static void printbits( char *out, int nbits, uint32_t value )
    12 {
    13     if( nbits < 32 ) {
    14         int i;
    15         for( i=32; i>nbits; i-- ) {
    16             if( !(i % 8) ) *out++ = ' ';
    17             *out++ = ' ';
    18         }
    19     }
    20     while( nbits > 0 ) {
    21         *out++ = (value&(1<<--nbits) ? '1' : '0');
    22         if( !(nbits % 8) ) *out++ = ' ';
    23     }
    24     *out = '\0';
    25 }
    27 static void printhex( char *out, int nbits, uint32_t value )
    28 {
    29     char tmp[10], *p = tmp;
    30     int i;
    32     sprintf( tmp, "%08X", value );
    33     for( i=32; i>0; i-=4, p++ ) {
    34         if( i <= nbits ) *out++ = *p;
    35         else *out++ = ' ';
    36     }
    37     *out = '\0';
    38 }
    41 static GtkCList *create_mmr_page( char *name )
    42 {
    43     GtkCList *list;
    44     GtkWidget *scroll;
    45     GtkWidget *tab;
    47     scroll = gtk_scrolled_window_new(NULL, NULL);
    48     gtk_widget_show( scroll );
    49     gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(scroll),
    50                                     GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS );
    51     list = GTK_CLIST(gtk_clist_new(5));
    52     gtk_clist_set_column_width(list, 0, 60);
    53     gtk_clist_set_column_width(list, 1, 50);
    54     gtk_clist_set_column_width(list, 2, 60);
    55     gtk_clist_set_column_width(list, 3, 220);
    56     gtk_clist_set_column_width(list, 4, 160);
    57     gtk_clist_set_column_justification(list, 0, GTK_JUSTIFY_CENTER );
    58     gtk_clist_set_column_justification(list, 2, GTK_JUSTIFY_CENTER );
    59     gtk_clist_set_column_justification(list, 3, GTK_JUSTIFY_CENTER );
    60     gtk_clist_set_column_title(list, 0, "Address");
    61     gtk_clist_set_column_title(list, 1, "Register");
    62     gtk_clist_set_column_title(list, 2, "Value");
    63     gtk_clist_set_column_title(list, 3, "Bit Pattern");
    64     gtk_clist_set_column_title(list, 4, "Description");
    65     gtk_clist_column_titles_show(list);
    66     gtk_widget_set_style( GTK_WIDGET(list), fixed_list_style );
    67     gtk_widget_show( GTK_WIDGET(list) );
    68     tab = gtk_label_new(_(name));
    69     gtk_widget_show( tab );
    70     gtk_container_add( GTK_CONTAINER(scroll), GTK_WIDGET(list) );
    71     gtk_notebook_append_page( mmr_book, scroll, tab );
    72     gtk_object_set_data( GTK_OBJECT(mmr_win), name, list );
    73     return list;
    74 }
    76 void update_mmr_win( void )
    77 {
    78     int i,j, count = 0;
    79     GtkCList *page, *all_page;
    80     char data[10], bits[40];
    82     all_page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmr_win), "All" ));
    84     for( i=1; i < num_io_rgns; i++ ) {
    85         page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmr_win),
    86                                               io_rgn[i]->id ));
    87         for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
    88             if( *io_rgn[i]->ports[j].val !=
    89                 *(uint32_t *)(io_rgn[i]->save_mem+io_rgn[i]->ports[j].offset)){
    90                 int sz = io_rgn[i]->ports[j].width;
    91                 /* Changed */
    92                 printhex( data, sz, *io_rgn[i]->ports[j].val );
    93                 printbits( bits, sz, *io_rgn[i]->ports[j].val );
    95                 gtk_clist_set_text( page, j, 2, data );
    96                 gtk_clist_set_text( page, j, 3, bits );
    97                 gtk_clist_set_foreground( page, j, &clrChanged );
    99                 gtk_clist_set_text( all_page, count, 2, data );
   100                 gtk_clist_set_text( all_page, count, 3, bits );
   101                 gtk_clist_set_foreground( all_page, count, &clrChanged );
   103             } else {
   104                 gtk_clist_set_foreground( page, j, &clrNormal );
   105                 gtk_clist_set_foreground( all_page, count, &clrNormal );
   106             }
   107             count++;
   108         }
   109         memcpy( io_rgn[i]->save_mem, io_rgn[i]->mem, PAGE_SIZE );
   110     }
   111 }
   113 void init_mmr_win( void )
   114 {
   115     int i, j;
   116     GtkCList *all_list;
   117     mmr_win = create_mmr_win();
   118     mmr_book = GTK_NOTEBOOK( gtk_object_get_data( GTK_OBJECT(mmr_win), "mmr_notebook" ));
   120     /* kill the dummy page glade insists on adding */
   121     gtk_notebook_remove_page( mmr_book, 0 );
   123     all_list = create_mmr_page( "All" );
   124     for( i=1; i < num_io_rgns; i++ ) {
   125         GtkCList *list = create_mmr_page( io_rgn[i]->id );
   127         for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
   128             int sz = io_rgn[i]->ports[j].width;
   129             char addr[10], data[10], bits[40];
   130             char *arr[] = { addr, io_rgn[i]->ports[j].id, data, bits,
   131                             io_rgn[i]->ports[j].desc };
   132             sprintf( addr, "%08X",
   133                      io_rgn[i]->base + io_rgn[i]->ports[j].offset );
   134             printhex( data, sz, *io_rgn[i]->ports[j].val );
   135             printbits( bits, io_rgn[i]->ports[j].width,
   136                        *io_rgn[i]->ports[j].val );
   137             gtk_clist_append( list, arr );
   138             gtk_clist_append( all_list, arr );
   139         }
   140     }
   141 }
   143 void mmr_open_win( void )
   144 {
   145     gtk_widget_show( mmr_win );
   146 }
   148 void mmr_close_win( void )
   149 {
   150     gtk_widget_hide( mmr_win );
   151 }
.