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 Sat Mar 13 00:03:32 2004 +0000 (15 years ago)
permissions -rw-r--r--
last change This commit was generated by cvs2svn to compensate for changes in r2,
which included commits to RCS files with non-trunk default branches.
file annotate diff log raw
nkeynes@1
     1
#include <stdint.h>
nkeynes@1
     2
#include <gnome.h>
nkeynes@1
     3
#include "interface.h"
nkeynes@1
     4
#include "gui.h"
nkeynes@1
     5
#include "mem.h"
nkeynes@1
     6
#include "mmio.h"
nkeynes@1
     7
nkeynes@1
     8
GtkWidget *mmr_win;
nkeynes@1
     9
GtkNotebook *mmr_book;
nkeynes@1
    10
nkeynes@1
    11
static void printbits( char *out, int nbits, uint32_t value )
nkeynes@1
    12
{
nkeynes@1
    13
    if( nbits < 32 ) {
nkeynes@1
    14
        int i;
nkeynes@1
    15
        for( i=32; i>nbits; i-- ) {
nkeynes@1
    16
            if( !(i % 8) ) *out++ = ' ';
nkeynes@1
    17
            *out++ = ' ';
nkeynes@1
    18
        }
nkeynes@1
    19
    }
nkeynes@1
    20
    while( nbits > 0 ) {
nkeynes@1
    21
        *out++ = (value&(1<<--nbits) ? '1' : '0');
nkeynes@1
    22
        if( !(nbits % 8) ) *out++ = ' ';
nkeynes@1
    23
    }
nkeynes@1
    24
    *out = '\0';
nkeynes@1
    25
}
nkeynes@1
    26
nkeynes@1
    27
static void printhex( char *out, int nbits, uint32_t value )
nkeynes@1
    28
{
nkeynes@1
    29
    char tmp[10], *p = tmp;
nkeynes@1
    30
    int i;
nkeynes@1
    31
nkeynes@1
    32
    sprintf( tmp, "%08X", value );
nkeynes@1
    33
    for( i=32; i>0; i-=4, p++ ) {
nkeynes@1
    34
        if( i <= nbits ) *out++ = *p;
nkeynes@1
    35
        else *out++ = ' ';
nkeynes@1
    36
    }
nkeynes@1
    37
    *out = '\0';
nkeynes@1
    38
}
nkeynes@1
    39
    
nkeynes@1
    40
        
nkeynes@1
    41
static GtkCList *create_mmr_page( char *name )
nkeynes@1
    42
{
nkeynes@1
    43
    GtkCList *list;
nkeynes@1
    44
    GtkWidget *scroll;
nkeynes@1
    45
    GtkWidget *tab;
nkeynes@1
    46
nkeynes@1
    47
    scroll = gtk_scrolled_window_new(NULL, NULL);
nkeynes@1
    48
    gtk_widget_show( scroll );
nkeynes@1
    49
    gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(scroll),
nkeynes@1
    50
                                    GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS );
nkeynes@1
    51
    list = GTK_CLIST(gtk_clist_new(5));
nkeynes@1
    52
    gtk_clist_set_column_width(list, 0, 60);
nkeynes@1
    53
    gtk_clist_set_column_width(list, 1, 50);
nkeynes@1
    54
    gtk_clist_set_column_width(list, 2, 60);
nkeynes@1
    55
    gtk_clist_set_column_width(list, 3, 220);
nkeynes@1
    56
    gtk_clist_set_column_width(list, 4, 160);
nkeynes@1
    57
    gtk_clist_set_column_justification(list, 0, GTK_JUSTIFY_CENTER );
nkeynes@1
    58
    gtk_clist_set_column_justification(list, 2, GTK_JUSTIFY_CENTER );
nkeynes@1
    59
    gtk_clist_set_column_justification(list, 3, GTK_JUSTIFY_CENTER );
nkeynes@1
    60
    gtk_clist_set_column_title(list, 0, "Address");
nkeynes@1
    61
    gtk_clist_set_column_title(list, 1, "Register");
nkeynes@1
    62
    gtk_clist_set_column_title(list, 2, "Value");
nkeynes@1
    63
    gtk_clist_set_column_title(list, 3, "Bit Pattern");
nkeynes@1
    64
    gtk_clist_set_column_title(list, 4, "Description");
nkeynes@1
    65
    gtk_clist_column_titles_show(list);
nkeynes@1
    66
    gtk_widget_set_style( GTK_WIDGET(list), fixed_list_style );
nkeynes@1
    67
    gtk_widget_show( GTK_WIDGET(list) );
nkeynes@1
    68
    tab = gtk_label_new(_(name));
nkeynes@1
    69
    gtk_widget_show( tab );
nkeynes@1
    70
    gtk_container_add( GTK_CONTAINER(scroll), GTK_WIDGET(list) );
nkeynes@1
    71
    gtk_notebook_append_page( mmr_book, scroll, tab );
nkeynes@1
    72
    gtk_object_set_data( GTK_OBJECT(mmr_win), name, list );
nkeynes@1
    73
    return list;
nkeynes@1
    74
}
nkeynes@1
    75
nkeynes@1
    76
void update_mmr_win( void )
nkeynes@1
    77
{
nkeynes@1
    78
    int i,j, count = 0;
nkeynes@1
    79
    GtkCList *page, *all_page;
nkeynes@1
    80
    char data[10], bits[40];
nkeynes@1
    81
nkeynes@1
    82
    all_page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmr_win), "All" ));
nkeynes@1
    83
    
nkeynes@1
    84
    for( i=1; i < num_io_rgns; i++ ) {
nkeynes@1
    85
        page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmr_win),
nkeynes@1
    86
                                              io_rgn[i]->id ));
nkeynes@1
    87
        for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
nkeynes@1
    88
            if( *io_rgn[i]->ports[j].val !=
nkeynes@1
    89
                *(uint32_t *)(io_rgn[i]->save_mem+io_rgn[i]->ports[j].offset)){
nkeynes@1
    90
                int sz = io_rgn[i]->ports[j].width;
nkeynes@1
    91
                /* Changed */
nkeynes@1
    92
                printhex( data, sz, *io_rgn[i]->ports[j].val );
nkeynes@1
    93
                printbits( bits, sz, *io_rgn[i]->ports[j].val );
nkeynes@1
    94
                
nkeynes@1
    95
                gtk_clist_set_text( page, j, 2, data );
nkeynes@1
    96
                gtk_clist_set_text( page, j, 3, bits );
nkeynes@1
    97
                gtk_clist_set_foreground( page, j, &clrChanged );
nkeynes@1
    98
                
nkeynes@1
    99
                gtk_clist_set_text( all_page, count, 2, data );
nkeynes@1
   100
                gtk_clist_set_text( all_page, count, 3, bits );
nkeynes@1
   101
                gtk_clist_set_foreground( all_page, count, &clrChanged );
nkeynes@1
   102
                
nkeynes@1
   103
            } else {
nkeynes@1
   104
                gtk_clist_set_foreground( page, j, &clrNormal );
nkeynes@1
   105
                gtk_clist_set_foreground( all_page, count, &clrNormal );
nkeynes@1
   106
            }
nkeynes@1
   107
            count++;
nkeynes@1
   108
        }
nkeynes@1
   109
        memcpy( io_rgn[i]->save_mem, io_rgn[i]->mem, PAGE_SIZE );
nkeynes@1
   110
    }
nkeynes@1
   111
}
nkeynes@1
   112
nkeynes@1
   113
void init_mmr_win( void )
nkeynes@1
   114
{
nkeynes@1
   115
    int i, j;
nkeynes@1
   116
    GtkCList *all_list;
nkeynes@1
   117
    mmr_win = create_mmr_win();
nkeynes@1
   118
    mmr_book = GTK_NOTEBOOK( gtk_object_get_data( GTK_OBJECT(mmr_win), "mmr_notebook" ));
nkeynes@1
   119
    
nkeynes@1
   120
    /* kill the dummy page glade insists on adding */
nkeynes@1
   121
    gtk_notebook_remove_page( mmr_book, 0 );
nkeynes@1
   122
    
nkeynes@1
   123
    all_list = create_mmr_page( "All" );
nkeynes@1
   124
    for( i=1; i < num_io_rgns; i++ ) {
nkeynes@1
   125
        GtkCList *list = create_mmr_page( io_rgn[i]->id );
nkeynes@1
   126
        
nkeynes@1
   127
        for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
nkeynes@1
   128
            int sz = io_rgn[i]->ports[j].width;
nkeynes@1
   129
            char addr[10], data[10], bits[40];
nkeynes@1
   130
            char *arr[] = { addr, io_rgn[i]->ports[j].id, data, bits,
nkeynes@1
   131
                            io_rgn[i]->ports[j].desc };
nkeynes@1
   132
            sprintf( addr, "%08X",
nkeynes@1
   133
                     io_rgn[i]->base + io_rgn[i]->ports[j].offset );
nkeynes@1
   134
            printhex( data, sz, *io_rgn[i]->ports[j].val );
nkeynes@1
   135
            printbits( bits, io_rgn[i]->ports[j].width,
nkeynes@1
   136
                       *io_rgn[i]->ports[j].val );
nkeynes@1
   137
            gtk_clist_append( list, arr );
nkeynes@1
   138
            gtk_clist_append( all_list, arr );
nkeynes@1
   139
        }
nkeynes@1
   140
    }
nkeynes@1
   141
}
nkeynes@1
   142
nkeynes@1
   143
void mmr_open_win( void )
nkeynes@1
   144
{
nkeynes@1
   145
    gtk_widget_show( mmr_win );
nkeynes@1
   146
}
nkeynes@1
   147
nkeynes@1
   148
void mmr_close_win( void )
nkeynes@1
   149
{
nkeynes@1
   150
    gtk_widget_hide( mmr_win );
nkeynes@1
   151
}
.