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
file annotate diff log raw
nkeynes@31
     1
/**
nkeynes@31
     2
 * $Id: mmio_win.c,v 1.2 2005-12-25 08:24:11 nkeynes Exp $
nkeynes@31
     3
 *
nkeynes@31
     4
 * Implements the MMIO register viewing window
nkeynes@31
     5
 *
nkeynes@31
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@31
     7
 *
nkeynes@31
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@31
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@31
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@31
    11
 * (at your option) any later version.
nkeynes@31
    12
 *
nkeynes@31
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@31
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@31
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@31
    16
 * GNU General Public License for more details.
nkeynes@31
    17
 */
nkeynes@31
    18
nkeynes@2
    19
#include <stdint.h>
nkeynes@2
    20
#include <gnome.h>
nkeynes@2
    21
#include "interface.h"
nkeynes@2
    22
#include "gui.h"
nkeynes@2
    23
#include "mem.h"
nkeynes@2
    24
#include "mmio.h"
nkeynes@2
    25
nkeynes@2
    26
GtkWidget *mmr_win;
nkeynes@2
    27
GtkNotebook *mmr_book;
nkeynes@2
    28
nkeynes@2
    29
static void printbits( char *out, int nbits, uint32_t value )
nkeynes@2
    30
{
nkeynes@2
    31
    if( nbits < 32 ) {
nkeynes@2
    32
        int i;
nkeynes@2
    33
        for( i=32; i>nbits; i-- ) {
nkeynes@2
    34
            if( !(i % 8) ) *out++ = ' ';
nkeynes@2
    35
            *out++ = ' ';
nkeynes@2
    36
        }
nkeynes@2
    37
    }
nkeynes@2
    38
    while( nbits > 0 ) {
nkeynes@2
    39
        *out++ = (value&(1<<--nbits) ? '1' : '0');
nkeynes@2
    40
        if( !(nbits % 8) ) *out++ = ' ';
nkeynes@2
    41
    }
nkeynes@2
    42
    *out = '\0';
nkeynes@2
    43
}
nkeynes@2
    44
nkeynes@2
    45
static void printhex( char *out, int nbits, uint32_t value )
nkeynes@2
    46
{
nkeynes@2
    47
    char tmp[10], *p = tmp;
nkeynes@2
    48
    int i;
nkeynes@2
    49
nkeynes@2
    50
    sprintf( tmp, "%08X", value );
nkeynes@2
    51
    for( i=32; i>0; i-=4, p++ ) {
nkeynes@2
    52
        if( i <= nbits ) *out++ = *p;
nkeynes@2
    53
        else *out++ = ' ';
nkeynes@2
    54
    }
nkeynes@2
    55
    *out = '\0';
nkeynes@2
    56
}
nkeynes@2
    57
    
nkeynes@2
    58
        
nkeynes@2
    59
static GtkCList *create_mmr_page( char *name )
nkeynes@2
    60
{
nkeynes@2
    61
    GtkCList *list;
nkeynes@2
    62
    GtkWidget *scroll;
nkeynes@2
    63
    GtkWidget *tab;
nkeynes@2
    64
nkeynes@2
    65
    scroll = gtk_scrolled_window_new(NULL, NULL);
nkeynes@2
    66
    gtk_widget_show( scroll );
nkeynes@2
    67
    gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(scroll),
nkeynes@2
    68
                                    GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS );
nkeynes@2
    69
    list = GTK_CLIST(gtk_clist_new(5));
nkeynes@2
    70
    gtk_clist_set_column_width(list, 0, 60);
nkeynes@2
    71
    gtk_clist_set_column_width(list, 1, 50);
nkeynes@2
    72
    gtk_clist_set_column_width(list, 2, 60);
nkeynes@2
    73
    gtk_clist_set_column_width(list, 3, 220);
nkeynes@2
    74
    gtk_clist_set_column_width(list, 4, 160);
nkeynes@2
    75
    gtk_clist_set_column_justification(list, 0, GTK_JUSTIFY_CENTER );
nkeynes@2
    76
    gtk_clist_set_column_justification(list, 2, GTK_JUSTIFY_CENTER );
nkeynes@2
    77
    gtk_clist_set_column_justification(list, 3, GTK_JUSTIFY_CENTER );
nkeynes@2
    78
    gtk_clist_set_column_title(list, 0, "Address");
nkeynes@2
    79
    gtk_clist_set_column_title(list, 1, "Register");
nkeynes@2
    80
    gtk_clist_set_column_title(list, 2, "Value");
nkeynes@2
    81
    gtk_clist_set_column_title(list, 3, "Bit Pattern");
nkeynes@2
    82
    gtk_clist_set_column_title(list, 4, "Description");
nkeynes@2
    83
    gtk_clist_column_titles_show(list);
nkeynes@2
    84
    gtk_widget_modify_font( GTK_WIDGET(list), fixed_list_font );
nkeynes@2
    85
    gtk_widget_show( GTK_WIDGET(list) );
nkeynes@2
    86
    tab = gtk_label_new(_(name));
nkeynes@2
    87
    gtk_widget_show( tab );
nkeynes@2
    88
    gtk_container_add( GTK_CONTAINER(scroll), GTK_WIDGET(list) );
nkeynes@2
    89
    gtk_notebook_append_page( mmr_book, scroll, tab );
nkeynes@2
    90
    gtk_object_set_data( GTK_OBJECT(mmr_win), name, list );
nkeynes@2
    91
    return list;
nkeynes@2
    92
}
nkeynes@2
    93
nkeynes@2
    94
void update_mmr_win( void )
nkeynes@2
    95
{
nkeynes@2
    96
    int i,j, count = 0;
nkeynes@2
    97
    GtkCList *page, *all_page;
nkeynes@2
    98
    char data[10], bits[40];
nkeynes@2
    99
nkeynes@2
   100
    all_page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmr_win), "All" ));
nkeynes@2
   101
    
nkeynes@2
   102
    for( i=1; i < num_io_rgns; i++ ) {
nkeynes@2
   103
        page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmr_win),
nkeynes@2
   104
                                              io_rgn[i]->id ));
nkeynes@2
   105
        for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
nkeynes@2
   106
            if( *io_rgn[i]->ports[j].val !=
nkeynes@2
   107
                *(uint32_t *)(io_rgn[i]->save_mem+io_rgn[i]->ports[j].offset)){
nkeynes@2
   108
                int sz = io_rgn[i]->ports[j].width;
nkeynes@2
   109
                /* Changed */
nkeynes@2
   110
                printhex( data, sz, *io_rgn[i]->ports[j].val );
nkeynes@2
   111
                printbits( bits, sz, *io_rgn[i]->ports[j].val );
nkeynes@2
   112
                
nkeynes@2
   113
                gtk_clist_set_text( page, j, 2, data );
nkeynes@2
   114
                gtk_clist_set_text( page, j, 3, bits );
nkeynes@2
   115
                gtk_clist_set_foreground( page, j, &clrChanged );
nkeynes@2
   116
                
nkeynes@2
   117
                gtk_clist_set_text( all_page, count, 2, data );
nkeynes@2
   118
                gtk_clist_set_text( all_page, count, 3, bits );
nkeynes@2
   119
                gtk_clist_set_foreground( all_page, count, &clrChanged );
nkeynes@2
   120
                
nkeynes@2
   121
            } else {
nkeynes@2
   122
                gtk_clist_set_foreground( page, j, &clrNormal );
nkeynes@2
   123
                gtk_clist_set_foreground( all_page, count, &clrNormal );
nkeynes@2
   124
            }
nkeynes@2
   125
            count++;
nkeynes@2
   126
        }
nkeynes@2
   127
        memcpy( io_rgn[i]->save_mem, io_rgn[i]->mem, PAGE_SIZE );
nkeynes@2
   128
    }
nkeynes@2
   129
}
nkeynes@2
   130
nkeynes@2
   131
void init_mmr_win( void )
nkeynes@2
   132
{
nkeynes@2
   133
    int i, j;
nkeynes@2
   134
    GtkCList *all_list;
nkeynes@2
   135
    mmr_win = create_mmr_win();
nkeynes@2
   136
    mmr_book = GTK_NOTEBOOK( gtk_object_get_data( GTK_OBJECT(mmr_win), "mmr_notebook" ));
nkeynes@2
   137
    
nkeynes@2
   138
    /* kill the dummy page glade insists on adding */
nkeynes@2
   139
    gtk_notebook_remove_page( mmr_book, 0 );
nkeynes@2
   140
    
nkeynes@2
   141
    all_list = create_mmr_page( "All" );
nkeynes@2
   142
    for( i=1; i < num_io_rgns; i++ ) {
nkeynes@2
   143
        GtkCList *list = create_mmr_page( io_rgn[i]->id );
nkeynes@2
   144
        
nkeynes@2
   145
        for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
nkeynes@2
   146
            int sz = io_rgn[i]->ports[j].width;
nkeynes@2
   147
            char addr[10], data[10], bits[40];
nkeynes@2
   148
            char *arr[] = { addr, io_rgn[i]->ports[j].id, data, bits,
nkeynes@2
   149
                            io_rgn[i]->ports[j].desc };
nkeynes@2
   150
            sprintf( addr, "%08X",
nkeynes@2
   151
                     io_rgn[i]->base + io_rgn[i]->ports[j].offset );
nkeynes@2
   152
            printhex( data, sz, *io_rgn[i]->ports[j].val );
nkeynes@2
   153
            printbits( bits, io_rgn[i]->ports[j].width,
nkeynes@2
   154
                       *io_rgn[i]->ports[j].val );
nkeynes@2
   155
            gtk_clist_append( list, arr );
nkeynes@2
   156
            gtk_clist_append( all_list, arr );
nkeynes@2
   157
        }
nkeynes@2
   158
    }
nkeynes@2
   159
}
nkeynes@2
   160
nkeynes@2
   161
void mmr_open_win( void )
nkeynes@2
   162
{
nkeynes@2
   163
    gtk_widget_show( mmr_win );
nkeynes@2
   164
}
nkeynes@2
   165
nkeynes@2
   166
void mmr_close_win( void )
nkeynes@2
   167
{
nkeynes@2
   168
    gtk_widget_hide( mmr_win );
nkeynes@2
   169
}
.