Search
lxdream.org :: lxdream/src/gui/gui.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gui.c
changeset 167:71c0cc416a64
prev109:cc84a653c781
next275:005945dbb813
author nkeynes
date Mon Jun 19 11:00:42 2006 +0000 (15 years ago)
permissions -rw-r--r--
last change Add config value retrieval for pathnames
Implement default path for disc + save state loaders
Dump disc ID when mounting a CD
view annotate diff log raw
     1 /**
     2  * $Id: gui.c,v 1.12 2006-06-19 11:00:42 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;
    39 void open_file_callback(GtkWidget *btn, gint result, gpointer user_data);
    41 void gtk_gui_init( void );
    42 void gtk_gui_update( void );
    43 void gtk_gui_start( void );
    44 void gtk_gui_stop( void );
    45 uint32_t gtk_gui_run_slice( uint32_t nanosecs );
    47 struct dreamcast_module gtk_gui_module = { "Debugger", gtk_gui_init,
    48 					   gtk_gui_update, gtk_gui_start, 
    49 					   gtk_gui_run_slice, 
    50 					   gtk_gui_stop, 
    51 					   NULL, NULL };
    53 const cpu_desc_t cpu_descs[4] = { &sh4_cpu_desc, &arm_cpu_desc, &armt_cpu_desc, NULL };
    56 void gtk_gui_init() {
    57     GdkColormap *map;
    58     GtkWidget *debug_win;
    60     clrNormal.red = clrNormal.green = clrNormal.blue = 0;
    61     clrChanged.red = clrChanged.green = 64*256;
    62     clrChanged.blue = 154*256;
    63     clrError.red = 65535;
    64     clrError.green = clrError.blue = 64*256;
    65     clrPC.red = 32*256;
    66     clrPC.green = 170*256;
    67     clrPC.blue = 52*256;
    68     clrWarn = clrChanged;
    69     clrTrace.red = 156*256;
    70     clrTrace.green = 78*256;
    71     clrTrace.blue = 201*256;
    72     clrDebug = clrPC;
    73     clrBreak.red = 65535;
    74     clrBreak.green = clrBreak.blue = 192*256;
    75     clrTempBreak.red = clrTempBreak.green = 128*256;
    76     clrTempBreak.blue = 32*256;
    77     clrWhite.red = clrWhite.green = clrWhite.blue = 65535;
    79     map = gdk_colormap_new(gdk_visual_get_best(), TRUE);
    80     gdk_colormap_alloc_color(map, &clrNormal, TRUE, TRUE);
    81     gdk_colormap_alloc_color(map, &clrChanged, TRUE, TRUE);
    82     gdk_colormap_alloc_color(map, &clrError, TRUE, TRUE);
    83     gdk_colormap_alloc_color(map, &clrWarn, TRUE, TRUE);
    84     gdk_colormap_alloc_color(map, &clrPC, TRUE, TRUE);
    85     gdk_colormap_alloc_color(map, &clrDebug, TRUE, TRUE);
    86     gdk_colormap_alloc_color(map, &clrTrace, TRUE, TRUE);
    87     gdk_colormap_alloc_color(map, &clrBreak, TRUE, TRUE);
    88     gdk_colormap_alloc_color(map, &clrTempBreak, TRUE, TRUE);
    89     gdk_colormap_alloc_color(map, &clrWhite, TRUE, TRUE);
    90     fixed_list_font = pango_font_description_from_string("Courier 10");
    91     debug_win = create_debug_win ();
    92     main_debug = init_debug_win(debug_win, cpu_descs);
    93     init_mmr_win();
    95     gtk_widget_show (debug_win);
    97 }
    99 /**
   100  * Hook called when DC starts running. Just disables the run/step buttons
   101  * and enables the stop button.
   102  */
   103 void gtk_gui_start( void )
   104 {
   105     debug_win_set_running( main_debug, TRUE );
   106 }
   108 /**
   109  * Hook called when DC stops running. Enables the run/step buttons
   110  * and disables the stop button.
   111  */
   112 void gtk_gui_stop( void )
   113 {
   114     debug_win_set_running( main_debug, FALSE );
   115     gtk_gui_update();
   116 }
   118 uint32_t gtk_gui_nanos = 0;
   120 uint32_t gtk_gui_run_slice( uint32_t nanosecs ) 
   121 {
   122     gtk_gui_nanos += nanosecs;
   123     if( gtk_gui_nanos > 10000000 ) { /* About 10/sec */
   124 	gtk_gui_nanos = 0;
   125 	while( gtk_events_pending() )
   126 	    gtk_main_iteration();
   127 	update_icount(main_debug);
   128 	return nanosecs;
   129     }
   130 }
   132 void gtk_gui_update(void) {
   133     if( main_debug == NULL )
   134 	return;
   135     update_registers(main_debug);
   136     update_icount(main_debug);
   137     update_mmr_win();
   138     dump_win_update_all();
   139 }
   141 void open_file_callback(GtkWidget *btn, gint result, gpointer user_data) {
   142     GtkFileChooser *file = GTK_FILE_CHOOSER(user_data);
   143     if( result == GTK_RESPONSE_ACCEPT ) {
   144 	gchar *filename =gtk_file_chooser_get_filename(
   145 						       GTK_FILE_CHOOSER(file) );
   146 	file_callback_t action = (file_callback_t)gtk_object_get_data( GTK_OBJECT(file), "file_action" );
   147 	gtk_widget_destroy(GTK_WIDGET(file));
   148 	action( filename );
   149 	g_free(filename);
   150     } else {
   151 	gtk_widget_destroy(GTK_WIDGET(file));
   152     }
   153 }
   155 static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
   156 {
   157     if( pattern != NULL ) {
   158 	GtkFileFilter *filter = gtk_file_filter_new();
   159 	gtk_file_filter_add_pattern( filter, pattern );
   160 	gtk_file_filter_set_name( filter, patname );
   161 	gtk_file_chooser_add_filter( chooser, filter );
   162 	filter = gtk_file_filter_new();
   163 	gtk_file_filter_set_name( filter, "All files" );
   164 	gtk_file_filter_add_pattern( filter, "*" );
   165 	gtk_file_chooser_add_filter( chooser, filter );
   166     }
   167 }
   169 void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
   170 		       gchar const *initial_dir )
   171 {
   172     GtkWidget *file;
   173     file = gtk_file_chooser_dialog_new( title, NULL,
   174 					GTK_FILE_CHOOSER_ACTION_OPEN,
   175 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
   176 					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
   177 					NULL );
   178     add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
   179     g_signal_connect( GTK_OBJECT(file), "response", 
   180 		      GTK_SIGNAL_FUNC(open_file_callback), file );
   181     gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
   182     gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
   183     gtk_widget_show( file );
   184 }
   186 void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
   187 		       gchar const *initial_dir )
   188 {
   189     GtkWidget *file;
   190     file = gtk_file_chooser_dialog_new( title, NULL,
   191 					GTK_FILE_CHOOSER_ACTION_SAVE,
   192 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
   193 					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
   194 					NULL );
   195     add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
   196     g_signal_connect( GTK_OBJECT(file), "response", 
   197 		      GTK_SIGNAL_FUNC(open_file_callback), file );
   198     gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
   199     gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
   200     gtk_widget_show( file );
   201 }
   203 uint32_t gtk_entry_get_hex_value( GtkEntry *entry, uint32_t defaultValue )
   204 {
   205     gchar *text = gtk_entry_get_text(entry);
   206     if( text == NULL )
   207         return defaultValue;
   208     gchar *endptr;
   209     uint32_t value = strtoul( text, &endptr, 16 );
   210     if( text == endptr ) { /* invalid input */
   211         value = defaultValue;
   212         gtk_entry_set_hex_value( entry, value );
   213     }
   214     return value;
   215 }
   217 void gtk_entry_set_hex_value( GtkEntry *entry, uint32_t value )
   218 {
   219     char buf[10];
   220     sprintf( buf, "%08X", value );
   221     gtk_entry_set_text( entry, buf );
   222 }
.