2 * $Id: gui.c,v 1.14 2007-09-18 10:48:57 nkeynes Exp $
4 * Top-level GUI (GTK2) module.
6 * Copyright (c) 2005 Nathan Keynes.
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.
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.
24 #include "dreamcast.h"
26 #include "sh4/sh4dasm.h"
27 #include "aica/armdasm.h"
30 #define REGISTER_FONT "-*-fixed-medium-r-normal--12-*-*-*-*-*-iso8859-1"
32 GdkColor clrNormal, clrChanged, clrError, clrWarn, clrPC, clrDebug, clrTrace;
33 GdkColor clrBreak, clrTempBreak, clrWhite;
34 PangoFontDescription *fixed_list_font;
36 debug_info_t main_debug = NULL;
38 void open_file_callback(GtkWidget *btn, gint result, gpointer user_data);
40 void gtk_gui_init( void );
41 void gtk_gui_update( void );
42 void gtk_gui_start( void );
43 void gtk_gui_stop( void );
44 uint32_t gtk_gui_run_slice( uint32_t nanosecs );
46 struct dreamcast_module gtk_gui_module = { "Debugger", gtk_gui_init,
47 gtk_gui_update, gtk_gui_start,
52 const cpu_desc_t cpu_descs[4] = { &sh4_cpu_desc, &arm_cpu_desc, &armt_cpu_desc, NULL };
58 clrNormal.red = clrNormal.green = clrNormal.blue = 0;
59 clrChanged.red = clrChanged.green = 64*256;
60 clrChanged.blue = 154*256;
62 clrError.green = clrError.blue = 64*256;
64 clrPC.green = 170*256;
67 clrTrace.red = 156*256;
68 clrTrace.green = 78*256;
69 clrTrace.blue = 201*256;
72 clrBreak.green = clrBreak.blue = 192*256;
73 clrTempBreak.red = clrTempBreak.green = 128*256;
74 clrTempBreak.blue = 32*256;
75 clrWhite.red = clrWhite.green = clrWhite.blue = 65535;
77 map = gdk_colormap_new(gdk_visual_get_best(), TRUE);
78 gdk_colormap_alloc_color(map, &clrNormal, TRUE, TRUE);
79 gdk_colormap_alloc_color(map, &clrChanged, TRUE, TRUE);
80 gdk_colormap_alloc_color(map, &clrError, TRUE, TRUE);
81 gdk_colormap_alloc_color(map, &clrWarn, TRUE, TRUE);
82 gdk_colormap_alloc_color(map, &clrPC, TRUE, TRUE);
83 gdk_colormap_alloc_color(map, &clrDebug, TRUE, TRUE);
84 gdk_colormap_alloc_color(map, &clrTrace, TRUE, TRUE);
85 gdk_colormap_alloc_color(map, &clrBreak, TRUE, TRUE);
86 gdk_colormap_alloc_color(map, &clrTempBreak, TRUE, TRUE);
87 gdk_colormap_alloc_color(map, &clrWhite, TRUE, TRUE);
88 fixed_list_font = pango_font_description_from_string("Courier 10");
91 void gtk_gui_show_debugger()
93 GtkWidget *debug_win = create_debug_win ();
94 main_debug = init_debug_win(debug_win, cpu_descs);
97 gtk_widget_show (debug_win);
101 * Hook called when DC starts running. Just disables the run/step buttons
102 * and enables the stop button.
104 void gtk_gui_start( void )
106 debug_win_set_running( main_debug, TRUE );
110 * Hook called when DC stops running. Enables the run/step buttons
111 * and disables the stop button.
113 void gtk_gui_stop( void )
115 debug_win_set_running( main_debug, FALSE );
119 uint32_t gtk_gui_nanos = 0;
121 uint32_t gtk_gui_run_slice( uint32_t nanosecs )
123 gtk_gui_nanos += nanosecs;
124 if( gtk_gui_nanos > 10000000 ) { /* About 10/sec */
126 while( gtk_events_pending() )
127 gtk_main_iteration();
128 update_icount(main_debug);
133 void gtk_gui_update(void) {
134 if( main_debug != NULL ) {
135 update_registers(main_debug);
136 update_icount(main_debug);
138 dump_win_update_all();
142 void open_file_callback(GtkWidget *btn, gint result, gpointer user_data) {
143 GtkFileChooser *file = GTK_FILE_CHOOSER(user_data);
144 if( result == GTK_RESPONSE_ACCEPT ) {
145 gchar *filename =gtk_file_chooser_get_filename(
146 GTK_FILE_CHOOSER(file) );
147 file_callback_t action = (file_callback_t)gtk_object_get_data( GTK_OBJECT(file), "file_action" );
148 gtk_widget_destroy(GTK_WIDGET(file));
152 gtk_widget_destroy(GTK_WIDGET(file));
156 static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
158 if( pattern != NULL ) {
159 GtkFileFilter *filter = gtk_file_filter_new();
160 gtk_file_filter_add_pattern( filter, pattern );
161 gtk_file_filter_set_name( filter, patname );
162 gtk_file_chooser_add_filter( chooser, filter );
163 filter = gtk_file_filter_new();
164 gtk_file_filter_set_name( filter, "All files" );
165 gtk_file_filter_add_pattern( filter, "*" );
166 gtk_file_chooser_add_filter( chooser, filter );
170 void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
171 gchar const *initial_dir )
174 file = gtk_file_chooser_dialog_new( title, NULL,
175 GTK_FILE_CHOOSER_ACTION_OPEN,
176 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
177 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
179 add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
180 g_signal_connect( GTK_OBJECT(file), "response",
181 GTK_SIGNAL_FUNC(open_file_callback), file );
182 gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
183 gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
184 gtk_widget_show( file );
187 void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
188 gchar const *initial_dir )
191 file = gtk_file_chooser_dialog_new( title, NULL,
192 GTK_FILE_CHOOSER_ACTION_SAVE,
193 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
194 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
196 add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
197 g_signal_connect( GTK_OBJECT(file), "response",
198 GTK_SIGNAL_FUNC(open_file_callback), file );
199 gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
200 gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
201 gtk_widget_show( file );
204 uint32_t gtk_entry_get_hex_value( GtkEntry *entry, uint32_t defaultValue )
206 gchar *text = gtk_entry_get_text(entry);
210 uint32_t value = strtoul( text, &endptr, 16 );
211 if( text == endptr ) { /* invalid input */
212 value = defaultValue;
213 gtk_entry_set_hex_value( entry, value );
218 void gtk_entry_set_hex_value( GtkEntry *entry, uint32_t value )
221 sprintf( buf, "%08X", value );
222 gtk_entry_set_text( entry, buf );
.