~ubuntu-branches/ubuntu/breezy/tiemu/breezy

« back to all changes in this revision

Viewing changes to src/gui/debugger/dbg_pclog.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien BLACHE
  • Date: 2005-06-02 16:50:15 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050602165015-59ab24414tl2wzol
Tags: 1.99+svn1460-1
* New snapshot.
* debian/control:
  + Updated build-depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Hey EMACS -*- linux-c -*- */
 
2
/* $Id: dbg_pclog.c 1455 2005-05-31 18:38:03Z roms $ */
 
3
 
 
4
/*  TiEmu - an TI emulator
 
5
 *
 
6
 *  Copyright (c) 2000-2001, Thomas Corvazier, Romain Lievin
 
7
 *  Copyright (c) 2001-2003, Romain Lievin
 
8
 *  Copyright (c) 2003, Julien Blache
 
9
 *  Copyright (c) 2004, Romain Li�vin
 
10
 *  Copyright (c) 2005, Romain Li�vin
 
11
 *
 
12
 *  This program is free software; you can redistribute it and/or modify
 
13
 *  it under the terms of the GNU General Public License as published by
 
14
 *  the Free Software Foundation; either version 2 of the License, or
 
15
 *  (at your option) any later version.
 
16
 *
 
17
 *  This program is distributed in the hope that it will be useful,
 
18
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
 *  GNU General Public License for more details.
 
21
 *
 
22
 *  You should have received a copy of the GNU General Public License
 
23
 *  along with this program; if not, write to the Free Software
 
24
 *  Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
 
25
 */
 
26
 
 
27
#ifdef HAVE_CONFIG_H
 
28
#  include <config.h>
 
29
#endif
 
30
 
 
31
#include <gtk/gtk.h>
 
32
#include <glade/glade.h>
 
33
 
 
34
#include "intl.h"
 
35
#include "paths.h"
 
36
#include "support.h"
 
37
#include "ti68k_int.h"
 
38
#include "struct.h"
 
39
#include "dbg_all.h"
 
40
 
 
41
static GladeXML *xml = NULL;
 
42
static GtkWidget *wnd = NULL;
 
43
static gint already_open = 0;
 
44
 
 
45
enum { 
 
46
            COL_ADDR
 
47
};
 
48
#define CLIST_NVCOLS    (1)             // 1 visible columns
 
49
#define CLIST_NCOLS             (1)             // 1 real columns
 
50
 
 
51
#define FONT_NAME       "courier"
 
52
 
 
53
static GtkListStore* clist_create(GtkWidget *widget)
 
54
{
 
55
        GtkTreeView *view = GTK_TREE_VIEW(widget);
 
56
        GtkListStore *store;
 
57
        GtkTreeModel *model;
 
58
        GtkCellRenderer *renderer;
 
59
        GtkTreeSelection *selection;
 
60
    const gchar *text[CLIST_NVCOLS] = { _("Address") };
 
61
    gint i;
 
62
        
 
63
        store = gtk_list_store_new(CLIST_NCOLS,
 
64
                                G_TYPE_STRING,
 
65
                                -1
 
66
            );
 
67
    model = GTK_TREE_MODEL(store);
 
68
        
 
69
    gtk_tree_view_set_model(view, model); 
 
70
    gtk_tree_view_set_headers_visible(view, TRUE);
 
71
        gtk_tree_view_set_rules_hint(view, FALSE);
 
72
  
 
73
        for(i = COL_ADDR; i <= COL_ADDR; i++)
 
74
        {
 
75
                renderer = gtk_cell_renderer_text_new();
 
76
                gtk_tree_view_insert_column_with_attributes(view, -1, 
 
77
            text[i], renderer, 
 
78
            "text", i,
 
79
                        NULL);
 
80
        }
 
81
    
 
82
    for (i = 0; i < CLIST_NVCOLS; i++) 
 
83
    {
 
84
                GtkTreeViewColumn *col;
 
85
                
 
86
                col = gtk_tree_view_get_column(view, i);
 
87
                gtk_tree_view_column_set_resizable(col, TRUE);
 
88
        }
 
89
        
 
90
        selection = gtk_tree_view_get_selection(view);
 
91
        gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
 
92
 
 
93
        return store;
 
94
}
 
95
 
 
96
static void clist_populate(GtkListStore *store)
 
97
{
 
98
    int i;
 
99
 
 
100
    for(i = 0; i < bkpts.pclog_size; i++)
 
101
    {
 
102
        GtkTreeIter iter;
 
103
        uint32_t addr;
 
104
        gchar *str;
 
105
 
 
106
        addr = bkpts.pclog_buf[(bkpts.pclog_ptr + i) % bkpts.pclog_size];
 
107
        str = g_strdup_printf("0x%06x", addr);
 
108
    
 
109
        gtk_list_store_append(store, &iter);
 
110
                gtk_list_store_set(store, &iter, 
 
111
                COL_ADDR, str, 
 
112
                -1);
 
113
                
 
114
                g_free(str);
 
115
    }
 
116
}
 
117
 
 
118
static void clist_refresh(GtkListStore *store)
 
119
{
 
120
        gtk_list_store_clear(store);
 
121
        clist_populate(store);
 
122
}
 
123
 
 
124
static GtkListStore *store = NULL;
 
125
 
 
126
/*
 
127
        Display registers window
 
128
*/
 
129
GtkWidget* dbgpclog_create_window(void)
 
130
{
 
131
        GtkWidget *dbox;
 
132
    GtkWidget *data;
 
133
        
 
134
        xml = glade_xml_new
 
135
                (tilp_paths_build_glade("dbg_pclog-2.glade"), "dbgpclog_window",
 
136
                 PACKAGE);
 
137
        if (!xml)
 
138
                g_error(_("%s: GUI loading failed !\n"), __FILE__);
 
139
        glade_xml_signal_autoconnect(xml);
 
140
        
 
141
        dbox = glade_xml_get_widget(xml, "dbgpclog_window");
 
142
#ifdef WND_TRANSIENT
 
143
        gtk_window_set_transient_for(GTK_WINDOW(dbox), GTK_WINDOW(main_wnd));
 
144
#endif
 
145
 
 
146
        data = glade_xml_get_widget(xml, "treeview1");
 
147
    store = clist_create(data);
 
148
        clist_populate(store);
 
149
 
 
150
        gtk_tree_view_expand_all(GTK_TREE_VIEW(data));
 
151
 
 
152
        already_open = !0;
 
153
 
 
154
        return wnd = dbox;
 
155
}
 
156
 
 
157
GtkWidget* dbgpclog_display_window(void)
 
158
{
 
159
        if(!already_open)
 
160
                wnd = dbgpclog_create_window();
 
161
    
 
162
#ifdef WND_STATE
 
163
        if(!options3.pclog.minimized)
 
164
        {
 
165
                gtk_window_resize(GTK_WINDOW(wnd), options3.pclog.rect.w, options3.pclog.rect.h);
 
166
                gtk_window_move(GTK_WINDOW(wnd), options3.pclog.rect.x, options3.pclog.rect.y);
 
167
        }
 
168
        else
 
169
                gtk_window_iconify(GTK_WINDOW(wnd));
 
170
#endif
 
171
 
 
172
        clist_refresh(store);
 
173
        gtk_widget_show(wnd);
 
174
 
 
175
        return wnd;
 
176
}
 
177
 
 
178
void dbgpclog_refresh_window(void)
 
179
{
 
180
        if(options3.pclog.visible)
 
181
        {
 
182
                clist_refresh(store);
 
183
        }
 
184
}
 
185
 
 
186
GLADE_CB gboolean
 
187
on_pclog_button_press_event        (GtkWidget       *widget,
 
188
                                    GdkEventButton  *event,
 
189
                                    gpointer         user_data)
 
190
{               
 
191
        GtkWidget *list = GTK_WIDGET(widget);
 
192
        GtkTreeView *view = GTK_TREE_VIEW(list);
 
193
        GtkTreeSelection *selection;
 
194
        GtkTreeModel *model;
 
195
        GList *l;
 
196
 
 
197
        // is double click ?
 
198
        if(event->type != GDK_2BUTTON_PRESS)
 
199
                return FALSE;
 
200
        
 
201
        // get selection
 
202
        selection = gtk_tree_view_get_selection(view);
 
203
        l = gtk_tree_selection_get_selected_rows(selection, &model);
 
204
        if(l != NULL)
 
205
        {
 
206
                GtkTreeIter iter;
 
207
                GtkTreePath *path = l->data;
 
208
        gchar** row_text = g_malloc0((CLIST_NVCOLS + 1) * sizeof(gchar *));
 
209
        uint32_t addr;
 
210
                
 
211
                // get address
 
212
                gtk_tree_model_get_iter(model, &iter, path);
 
213
                gtk_tree_model_get(model, &iter, COL_ADDR, &row_text[COL_ADDR], -1);
 
214
 
 
215
                // populate code
 
216
                sscanf(row_text[COL_ADDR], "%x", &addr);
 
217
                dbgcode_disasm_at(addr);
 
218
 
 
219
        g_strfreev(row_text);
 
220
    }
 
221
 
 
222
        // free selection
 
223
        g_list_foreach (l, (GFunc)gtk_tree_path_free, NULL);
 
224
        g_list_free (l);
 
225
 
 
226
    return FALSE;
 
227
}