Search
lxdream.org :: lxdream/src/gui/mmio_win.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/mmio_win.c
changeset 31:495e480360d7
prev2:42349f6ea216
next45:f99236f0632e
author nkeynes
date Sun Dec 25 08:24:11 2005 +0000 (14 years ago)
permissions -rw-r--r--
last change Finish adding header blocks to all files
view annotate diff log raw
     1 /**
     2  * $Id: mmio_win.c,v 1.2 2005-12-25 08:24:11 nkeynes Exp $
     3  *
     4  * Implements the MMIO register viewing 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 <stdint.h>
    20 #include <gnome.h>
    21 #include "interface.h"
    22 #include "gui.h"
    23 #include "mem.h"
    24 #include "mmio.h"
    26 GtkWidget *mmr_win;
    27 GtkNotebook *mmr_book;
    29 static void printbits( char *out, int nbits, uint32_t value )
    30 {
    31     if( nbits < 32 ) {
    32         int i;
    33         for( i=32; i>nbits; i-- ) {
    34             if( !(i % 8) ) *out++ = ' ';
    35             *out++ = ' ';
    36         }
    37     }
    38     while( nbits > 0 ) {
    39         *out++ = (value&(1<<--nbits) ? '1' : '0');
    40         if( !(nbits % 8) ) *out++ = ' ';
    41     }
    42     *out = '\0';
    43 }
    45 static void printhex( char *out, int nbits, uint32_t value )
    46 {
    47     char tmp[10], *p = tmp;
    48     int i;
    50     sprintf( tmp, "%08X", value );
    51     for( i=32; i>0; i-=4, p++ ) {
    52         if( i <= nbits ) *out++ = *p;
    53         else *out++ = ' ';
    54     }
    55     *out = '\0';
    56 }
    59 static GtkCList *create_mmr_page( char *name )
    60 {
    61     GtkCList *list;
    62     GtkWidget *scroll;
    63     GtkWidget *tab;
    65     scroll = gtk_scrolled_window_new(NULL, NULL);
    66     gtk_widget_show( scroll );
    67     gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(scroll),
    68                                     GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS );
    69     list = GTK_CLIST(gtk_clist_new(5));
    70     gtk_clist_set_column_width(list, 0, 60);
    71     gtk_clist_set_column_width(list, 1, 50);
    72     gtk_clist_set_column_width(list, 2, 60);
    73     gtk_clist_set_column_width(list, 3, 220);
    74     gtk_clist_set_column_width(list, 4, 160);
    75     gtk_clist_set_column_justification(list, 0, GTK_JUSTIFY_CENTER );
    76     gtk_clist_set_column_justification(list, 2, GTK_JUSTIFY_CENTER );
    77     gtk_clist_set_column_justification(list, 3, GTK_JUSTIFY_CENTER );
    78     gtk_clist_set_column_title(list, 0, "Address");
    79     gtk_clist_set_column_title(list, 1, "Register");
    80     gtk_clist_set_column_title(list, 2, "Value");
    81     gtk_clist_set_column_title(list, 3, "Bit Pattern");
    82     gtk_clist_set_column_title(list, 4, "Description");
    83     gtk_clist_column_titles_show(list);
    84     gtk_widget_modify_font( GTK_WIDGET(list), fixed_list_font );
    85     gtk_widget_show( GTK_WIDGET(list) );
    86     tab = gtk_label_new(_(name));
    87     gtk_widget_show( tab );
    88     gtk_container_add( GTK_CONTAINER(scroll), GTK_WIDGET(list) );
    89     gtk_notebook_append_page( mmr_book, scroll, tab );
    90     gtk_object_set_data( GTK_OBJECT(mmr_win), name, list );
    91     return list;
    92 }
    94 void update_mmr_win( void )
    95 {
    96     int i,j, count = 0;
    97     GtkCList *page, *all_page;
    98     char data[10], bits[40];
   100     all_page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmr_win), "All" ));
   102     for( i=1; i < num_io_rgns; i++ ) {
   103         page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmr_win),
   104                                               io_rgn[i]->id ));
   105         for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
   106             if( *io_rgn[i]->ports[j].val !=
   107                 *(uint32_t *)(io_rgn[i]->save_mem+io_rgn[i]->ports[j].offset)){
   108                 int sz = io_rgn[i]->ports[j].width;
   109                 /* Changed */
   110                 printhex( data, sz, *io_rgn[i]->ports[j].val );
   111                 printbits( bits, sz, *io_rgn[i]->ports[j].val );
   113                 gtk_clist_set_text( page, j, 2, data );
   114                 gtk_clist_set_text( page, j, 3, bits );
   115                 gtk_clist_set_foreground( page, j, &clrChanged );
   117                 gtk_clist_set_text( all_page, count, 2, data );
   118                 gtk_clist_set_text( all_page, count, 3, bits );
   119                 gtk_clist_set_foreground( all_page, count, &clrChanged );
   121             } else {
   122                 gtk_clist_set_foreground( page, j, &clrNormal );
   123                 gtk_clist_set_foreground( all_page, count, &clrNormal );
   124             }
   125             count++;
   126         }
   127         memcpy( io_rgn[i]->save_mem, io_rgn[i]->mem, PAGE_SIZE );
   128     }
   129 }
   131 void init_mmr_win( void )
   132 {
   133     int i, j;
   134     GtkCList *all_list;
   135     mmr_win = create_mmr_win();
   136     mmr_book = GTK_NOTEBOOK( gtk_object_get_data( GTK_OBJECT(mmr_win), "mmr_notebook" ));
   138     /* kill the dummy page glade insists on adding */
   139     gtk_notebook_remove_page( mmr_book, 0 );
   141     all_list = create_mmr_page( "All" );
   142     for( i=1; i < num_io_rgns; i++ ) {
   143         GtkCList *list = create_mmr_page( io_rgn[i]->id );
   145         for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
   146             int sz = io_rgn[i]->ports[j].width;
   147             char addr[10], data[10], bits[40];
   148             char *arr[] = { addr, io_rgn[i]->ports[j].id, data, bits,
   149                             io_rgn[i]->ports[j].desc };
   150             sprintf( addr, "%08X",
   151                      io_rgn[i]->base + io_rgn[i]->ports[j].offset );
   152             printhex( data, sz, *io_rgn[i]->ports[j].val );
   153             printbits( bits, io_rgn[i]->ports[j].width,
   154                        *io_rgn[i]->ports[j].val );
   155             gtk_clist_append( list, arr );
   156             gtk_clist_append( all_list, arr );
   157         }
   158     }
   159 }
   161 void mmr_open_win( void )
   162 {
   163     gtk_widget_show( mmr_win );
   164 }
   166 void mmr_close_win( void )
   167 {
   168     gtk_widget_hide( mmr_win );
   169 }
.