Search
lxdream.org :: lxdream/src/gui/gui.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gui.c
changeset 429:e581b90c3fb3
prev392:39e596b3b6dd
author nkeynes
date Mon Oct 08 12:09:06 2007 +0000 (14 years ago)
permissions -rw-r--r--
last change Fix compilation warnings
view annotate diff log raw
     1 /**
     2  * $Id: gui.c,v 1.15 2007-10-08 11:48:56 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 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, 
    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;
    58     clrNormal.red = clrNormal.green = clrNormal.blue = 0;
    59     clrChanged.red = clrChanged.green = 64*256;
    60     clrChanged.blue = 154*256;
    61     clrError.red = 65535;
    62     clrError.green = clrError.blue = 64*256;
    63     clrPC.red = 32*256;
    64     clrPC.green = 170*256;
    65     clrPC.blue = 52*256;
    66     clrWarn = clrChanged;
    67     clrTrace.red = 156*256;
    68     clrTrace.green = 78*256;
    69     clrTrace.blue = 201*256;
    70     clrDebug = clrPC;
    71     clrBreak.red = 65535;
    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");
    89 }
    91 void gtk_gui_show_debugger()
    92 {
    93     GtkWidget *debug_win = create_debug_win ();
    94     main_debug = init_debug_win(debug_win, cpu_descs);
    95     init_mmr_win();
    97     gtk_widget_show (debug_win);
    98 }    
   100 /**
   101  * Hook called when DC starts running. Just disables the run/step buttons
   102  * and enables the stop button.
   103  */
   104 void gtk_gui_start( void )
   105 {
   106     debug_win_set_running( main_debug, TRUE );
   107 }
   109 /**
   110  * Hook called when DC stops running. Enables the run/step buttons
   111  * and disables the stop button.
   112  */
   113 void gtk_gui_stop( void )
   114 {
   115     debug_win_set_running( main_debug, FALSE );
   116     gtk_gui_update();
   117 }
   119 uint32_t gtk_gui_nanos = 0;
   121 uint32_t gtk_gui_run_slice( uint32_t nanosecs ) 
   122 {
   123     gtk_gui_nanos += nanosecs;
   124     if( gtk_gui_nanos > 10000000 ) { /* About 10/sec */
   125 	gtk_gui_nanos = 0;
   126 	while( gtk_events_pending() )
   127 	    gtk_main_iteration();
   128 	update_icount(main_debug);
   129     }
   130     return nanosecs;
   131 }
   133 void gtk_gui_update(void) {
   134     if( main_debug != NULL ) {
   135 	update_registers(main_debug);
   136 	update_icount(main_debug);
   137 	update_mmr_win();
   138 	dump_win_update_all();
   139     }
   140 }
   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));
   149 	action( filename );
   150 	g_free(filename);
   151     } else {
   152 	gtk_widget_destroy(GTK_WIDGET(file));
   153     }
   154 }
   156 static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
   157 {
   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 );
   167     }
   168 }
   170 void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
   171 		       gchar const *initial_dir )
   172 {
   173     GtkWidget *file;
   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,
   178 					NULL );
   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 );
   185 }
   187 void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
   188 		       gchar const *initial_dir )
   189 {
   190     GtkWidget *file;
   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,
   195 					NULL );
   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 );
   202 }
   204 uint32_t gtk_entry_get_hex_value( GtkEntry *entry, uint32_t defaultValue )
   205 {
   206     const gchar *text = gtk_entry_get_text(entry);
   207     if( text == NULL )
   208         return defaultValue;
   209     gchar *endptr;
   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 );
   214     }
   215     return value;
   216 }
   218 void gtk_entry_set_hex_value( GtkEntry *entry, uint32_t value )
   219 {
   220     char buf[10];
   221     sprintf( buf, "%08X", value );
   222     gtk_entry_set_text( entry, buf );
   223 }
.