filename | src/gui/gui.c |
changeset | 30:89b30313d757 |
prev | 28:81c206f59dc7 |
next | 43:0cf3e339cc59 |
author | nkeynes |
date | Sun Dec 25 05:57:00 2005 +0000 (15 years ago) |
permissions | -rw-r--r-- |
last change | Change timeslice to nanoseconds (was microseconds) Generize single step (now steps through active CPU) Add lots of header blocks |
view | annotate | diff | log | raw |
1 /**
2 * $Id: gui.c,v 1.8 2005-12-25 05:57:00 nkeynes Exp $
3 *
4 * Top-level GUI (GTK2) module.
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 <stdlib.h>
20 #include <stdarg.h>
21 #include <gnome.h>
22 #include <math.h>
23 #include "dream.h"
24 #include "dreamcast.h"
25 #include "mem.h"
26 #include "sh4/sh4dasm.h"
27 #include "aica/armdasm.h"
28 #include "gui/gui.h"
30 #define REGISTER_FONT "-*-fixed-medium-r-normal--12-*-*-*-*-*-iso8859-1"
32 GdkColor clrNormal, clrChanged, clrError, clrWarn, clrPC, clrDebug, clrTrace;
33 PangoFontDescription *fixed_list_font;
35 debug_info_t main_debug;
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,
48 gtk_gui_run_slice,
49 gtk_gui_stop,
50 NULL, NULL };
52 const cpu_desc_t cpu_descs[4] = { &sh4_cpu_desc, &arm_cpu_desc, &armt_cpu_desc, NULL };
55 void gtk_gui_init() {
56 GdkColormap *map;
57 GtkWidget *debug_win;
59 clrNormal.red = clrNormal.green = clrNormal.blue = 0;
60 clrChanged.red = clrChanged.green = 64*256;
61 clrChanged.blue = 154*256;
62 clrError.red = 65535;
63 clrError.green = clrError.blue = 64*256;
64 clrPC.red = 32*256;
65 clrPC.green = 170*256;
66 clrPC.blue = 52*256;
67 clrWarn = clrChanged;
68 clrTrace.red = 156*256;
69 clrTrace.green = 78*256;
70 clrTrace.blue = 201*256;
71 clrDebug = clrPC;
73 map = gdk_colormap_new(gdk_visual_get_best(), TRUE);
74 gdk_colormap_alloc_color(map, &clrNormal, TRUE, TRUE);
75 gdk_colormap_alloc_color(map, &clrChanged, TRUE, TRUE);
76 gdk_colormap_alloc_color(map, &clrError, TRUE, TRUE);
77 gdk_colormap_alloc_color(map, &clrWarn, TRUE, TRUE);
78 gdk_colormap_alloc_color(map, &clrPC, TRUE, TRUE);
79 gdk_colormap_alloc_color(map, &clrDebug, TRUE, TRUE);
80 gdk_colormap_alloc_color(map, &clrTrace, TRUE, TRUE);
81 fixed_list_font = pango_font_description_from_string("Courier 10");
82 debug_win = create_debug_win ();
83 main_debug = init_debug_win(debug_win, cpu_descs);
84 init_mmr_win();
86 gtk_widget_show (debug_win);
88 }
90 /**
91 * Hook called when DC starts running. Just disables the run/step buttons
92 * and enables the stop button.
93 */
94 void gtk_gui_start( void )
95 {
96 debug_win_set_running( main_debug, TRUE );
97 }
99 /**
100 * Hook called when DC stops running. Enables the run/step buttons
101 * and disables the stop button.
102 */
103 void gtk_gui_stop( void )
104 {
105 debug_win_set_running( main_debug, FALSE );
106 gtk_gui_update();
107 }
109 uint32_t gtk_gui_run_slice( uint32_t nanosecs )
110 {
111 while( gtk_events_pending() )
112 gtk_main_iteration();
113 update_icount(main_debug);
114 return nanosecs;
115 }
117 void gtk_gui_update(void) {
118 update_registers(main_debug);
119 update_icount(main_debug);
120 update_mmr_win();
121 dump_win_update_all();
122 }
124 void open_file_callback(GtkWidget *btn, gint result, gpointer user_data) {
125 GtkFileChooser *file = GTK_FILE_CHOOSER(user_data);
126 if( result == GTK_RESPONSE_ACCEPT ) {
127 gchar *filename =gtk_file_chooser_get_filename(
128 GTK_FILE_CHOOSER(file) );
129 file_callback_t action = (file_callback_t)gtk_object_get_data( GTK_OBJECT(file), "file_action" );
130 gtk_widget_destroy(GTK_WIDGET(file));
131 action( filename );
132 g_free(filename);
133 } else {
134 gtk_widget_destroy(GTK_WIDGET(file));
135 }
136 }
138 static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
139 {
140 if( pattern != NULL ) {
141 GtkFileFilter *filter = gtk_file_filter_new();
142 gtk_file_filter_add_pattern( filter, pattern );
143 gtk_file_filter_set_name( filter, patname );
144 gtk_file_chooser_add_filter( chooser, filter );
145 filter = gtk_file_filter_new();
146 gtk_file_filter_set_name( filter, "All files" );
147 gtk_file_filter_add_pattern( filter, "*" );
148 gtk_file_chooser_add_filter( chooser, filter );
149 }
150 }
152 void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
153 {
154 GtkWidget *file;
156 file = gtk_file_chooser_dialog_new( title, NULL,
157 GTK_FILE_CHOOSER_ACTION_OPEN,
158 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
159 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
160 NULL );
161 add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
162 g_signal_connect( GTK_OBJECT(file), "response",
163 GTK_SIGNAL_FUNC(open_file_callback), file );
164 gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
165 gtk_widget_show( file );
166 }
168 void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
169 {
170 GtkWidget *file;
172 file = gtk_file_chooser_dialog_new( title, NULL,
173 GTK_FILE_CHOOSER_ACTION_SAVE,
174 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
175 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
176 NULL );
177 add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
178 g_signal_connect( GTK_OBJECT(file), "response",
179 GTK_SIGNAL_FUNC(open_file_callback), file );
180 gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
181 gtk_widget_show( file );
182 }
184 uint32_t gtk_entry_get_hex_value( GtkEntry *entry, uint32_t defaultValue )
185 {
186 gchar *text = gtk_entry_get_text(entry);
187 if( text == NULL )
188 return defaultValue;
189 gchar *endptr;
190 uint32_t value = strtoul( text, &endptr, 16 );
191 if( text == endptr ) { /* invalid input */
192 value = defaultValue;
193 gtk_entry_set_hex_value( entry, value );
194 }
195 return value;
196 }
198 void gtk_entry_set_hex_value( GtkEntry *entry, uint32_t value )
199 {
200 char buf[10];
201 sprintf( buf, "%08X", value );
202 gtk_entry_set_text( entry, buf );
203 }
.