Search
lxdream.org :: lxdream/src/gui/gui.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gui.c
changeset 27:1ef09a52cd1e
prev23:1ec3acd0594d
next28:81c206f59dc7
author nkeynes
date Sun Dec 25 01:28:39 2005 +0000 (16 years ago)
permissions -rw-r--r--
last change Refactor all the GUI bits out of the main directory (except for a couple
lingering temporarily in loader.c
Fix a few timeslice issues
view annotate diff log raw
     1 #include <stdlib.h>
     2 #include <stdarg.h>
     3 #include <gnome.h>
     4 #include <math.h>
     5 #include "dream.h"
     6 #include "dreamcast.h"
     7 #include "mem.h"
     8 #include "sh4dasm.h"
     9 #include "sh4core.h"
    10 #include "gui/gui.h"
    12 #define REGISTER_FONT "-*-fixed-medium-r-normal--12-*-*-*-*-*-iso8859-1"
    14 GdkColor clrNormal, clrChanged, clrError, clrWarn, clrPC, clrDebug, clrTrace;
    15 PangoFontDescription *fixed_list_font;
    17 debug_info_t main_debug;
    20 void open_file_callback(GtkWidget *btn, gint result, gpointer user_data);
    22 void gtk_gui_init( void );
    23 void gtk_gui_update( void );
    24 int gtk_gui_run_slice( int microsecs );
    26 struct dreamcast_module gtk_gui_module = { "Debugger", gtk_gui_init,
    27 					   gtk_gui_update, NULL, 
    28 					   gtk_gui_run_slice, 
    29 					   gtk_gui_update, 
    30 					   NULL, NULL };
    32 const cpu_desc_t cpu_descs[4] = { &sh4_cpu_desc, &arm_cpu_desc, &armt_cpu_desc, NULL };
    35 void gtk_gui_init() {
    36     GdkColormap *map;
    37     GtkWidget *debug_win;
    39     clrNormal.red = clrNormal.green = clrNormal.blue = 0;
    40     clrChanged.red = clrChanged.green = 64*256;
    41     clrChanged.blue = 154*256;
    42     clrError.red = 65535;
    43     clrError.green = clrError.blue = 64*256;
    44     clrPC.red = 32*256;
    45     clrPC.green = 170*256;
    46     clrPC.blue = 52*256;
    47     clrWarn = clrChanged;
    48     clrTrace.red = 156*256;
    49     clrTrace.green = 78*256;
    50     clrTrace.blue = 201*256;
    51     clrDebug = clrPC;
    53     map = gdk_colormap_new(gdk_visual_get_best(), TRUE);
    54     gdk_colormap_alloc_color(map, &clrNormal, TRUE, TRUE);
    55     gdk_colormap_alloc_color(map, &clrChanged, TRUE, TRUE);
    56     gdk_colormap_alloc_color(map, &clrError, TRUE, TRUE);
    57     gdk_colormap_alloc_color(map, &clrWarn, TRUE, TRUE);
    58     gdk_colormap_alloc_color(map, &clrPC, TRUE, TRUE);
    59     gdk_colormap_alloc_color(map, &clrDebug, TRUE, TRUE);
    60     gdk_colormap_alloc_color(map, &clrTrace, TRUE, TRUE);
    61     fixed_list_font = pango_font_description_from_string("Courier 10");
    62     debug_win = create_debug_win ();
    63     main_debug = init_debug_win(debug_win, cpu_descs);
    64     init_mmr_win();
    66     gtk_widget_show (debug_win);
    68 }
    70 int gtk_gui_run_slice( int microsecs ) 
    71 {
    72     while( gtk_events_pending() )
    73 	gtk_main_iteration();
    74     update_icount(main_debug);
    75     return microsecs;
    76 }
    78 void gtk_gui_update(void) {
    79     update_registers(main_debug);
    80     update_icount(main_debug);
    81     update_mmr_win();
    82     dump_win_update_all();
    83 }
    85 void open_file_callback(GtkWidget *btn, gint result, gpointer user_data) {
    86     GtkFileChooser *file = GTK_FILE_CHOOSER(user_data);
    87     if( result == GTK_RESPONSE_ACCEPT ) {
    88 	gchar *filename =gtk_file_chooser_get_filename(
    89 						       GTK_FILE_CHOOSER(file) );
    90 	file_callback_t action = (file_callback_t)gtk_object_get_data( GTK_OBJECT(file), "file_action" );
    91 	gtk_widget_destroy(GTK_WIDGET(file));
    92 	action( filename );
    93 	g_free(filename);
    94     } else {
    95 	gtk_widget_destroy(GTK_WIDGET(file));
    96     }
    97 }
    99 static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
   100 {
   101     if( pattern != NULL ) {
   102 	GtkFileFilter *filter = gtk_file_filter_new();
   103 	gtk_file_filter_add_pattern( filter, pattern );
   104 	gtk_file_filter_set_name( filter, patname );
   105 	gtk_file_chooser_add_filter( chooser, filter );
   106 	filter = gtk_file_filter_new();
   107 	gtk_file_filter_set_name( filter, "All files" );
   108 	gtk_file_filter_add_pattern( filter, "*" );
   109 	gtk_file_chooser_add_filter( chooser, filter );
   110     }
   111 }
   113 void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
   114 {
   115     GtkWidget *file;
   117     file = gtk_file_chooser_dialog_new( title, NULL,
   118 					GTK_FILE_CHOOSER_ACTION_OPEN,
   119 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
   120 					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
   121 					NULL );
   122     add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
   123     g_signal_connect( GTK_OBJECT(file), "response", 
   124 		      GTK_SIGNAL_FUNC(open_file_callback), file );
   125     gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
   126     gtk_widget_show( file );
   127 }
   129 void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
   130 {
   131     GtkWidget *file;
   133     file = gtk_file_chooser_dialog_new( title, NULL,
   134 					GTK_FILE_CHOOSER_ACTION_SAVE,
   135 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
   136 					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
   137 					NULL );
   138     add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
   139     g_signal_connect( GTK_OBJECT(file), "response", 
   140 		      GTK_SIGNAL_FUNC(open_file_callback), file );
   141     gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
   142     gtk_widget_show( file );
   143 }
   145 uint32_t gtk_entry_get_hex_value( GtkEntry *entry, uint32_t defaultValue )
   146 {
   147     gchar *text = gtk_entry_get_text(entry);
   148     if( text == NULL )
   149         return defaultValue;
   150     gchar *endptr;
   151     uint32_t value = strtoul( text, &endptr, 16 );
   152     if( text == endptr ) { /* invalid input */
   153         value = defaultValue;
   154         gtk_entry_set_hex_value( entry, value );
   155     }
   156     return value;
   157 }
   159 void gtk_entry_set_hex_value( GtkEntry *entry, uint32_t value )
   160 {
   161     char buf[10];
   162     sprintf( buf, "%08X", value );
   163     gtk_entry_set_text( entry, buf );
   164 }
.