Search
lxdream.org :: lxdream/src/gui/gui.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gui.c
changeset 43:0cf3e339cc59
prev30:89b30313d757
next106:9048bac046c3
author nkeynes
date Sun Jan 01 08:09:17 2006 +0000 (18 years ago)
permissions -rw-r--r--
last change Remove sh4core.h reference
view annotate diff log raw
     1 /**
     2  * $Id: gui.c,v 1.9 2005-12-26 11:47:15 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_run_slice( uint32_t nanosecs ) 
   119 {
   120     while( gtk_events_pending() )
   121 	gtk_main_iteration();
   122     update_icount(main_debug);
   123     return nanosecs;
   124 }
   126 void gtk_gui_update(void) {
   127     update_registers(main_debug);
   128     update_icount(main_debug);
   129     update_mmr_win();
   130     dump_win_update_all();
   131 }
   133 void open_file_callback(GtkWidget *btn, gint result, gpointer user_data) {
   134     GtkFileChooser *file = GTK_FILE_CHOOSER(user_data);
   135     if( result == GTK_RESPONSE_ACCEPT ) {
   136 	gchar *filename =gtk_file_chooser_get_filename(
   137 						       GTK_FILE_CHOOSER(file) );
   138 	file_callback_t action = (file_callback_t)gtk_object_get_data( GTK_OBJECT(file), "file_action" );
   139 	gtk_widget_destroy(GTK_WIDGET(file));
   140 	action( filename );
   141 	g_free(filename);
   142     } else {
   143 	gtk_widget_destroy(GTK_WIDGET(file));
   144     }
   145 }
   147 static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
   148 {
   149     if( pattern != NULL ) {
   150 	GtkFileFilter *filter = gtk_file_filter_new();
   151 	gtk_file_filter_add_pattern( filter, pattern );
   152 	gtk_file_filter_set_name( filter, patname );
   153 	gtk_file_chooser_add_filter( chooser, filter );
   154 	filter = gtk_file_filter_new();
   155 	gtk_file_filter_set_name( filter, "All files" );
   156 	gtk_file_filter_add_pattern( filter, "*" );
   157 	gtk_file_chooser_add_filter( chooser, filter );
   158     }
   159 }
   161 void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
   162 {
   163     GtkWidget *file;
   165     file = gtk_file_chooser_dialog_new( title, NULL,
   166 					GTK_FILE_CHOOSER_ACTION_OPEN,
   167 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
   168 					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
   169 					NULL );
   170     add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
   171     g_signal_connect( GTK_OBJECT(file), "response", 
   172 		      GTK_SIGNAL_FUNC(open_file_callback), file );
   173     gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
   174     gtk_widget_show( file );
   175 }
   177 void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
   178 {
   179     GtkWidget *file;
   181     file = gtk_file_chooser_dialog_new( title, NULL,
   182 					GTK_FILE_CHOOSER_ACTION_SAVE,
   183 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
   184 					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
   185 					NULL );
   186     add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
   187     g_signal_connect( GTK_OBJECT(file), "response", 
   188 		      GTK_SIGNAL_FUNC(open_file_callback), file );
   189     gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
   190     gtk_widget_show( file );
   191 }
   193 uint32_t gtk_entry_get_hex_value( GtkEntry *entry, uint32_t defaultValue )
   194 {
   195     gchar *text = gtk_entry_get_text(entry);
   196     if( text == NULL )
   197         return defaultValue;
   198     gchar *endptr;
   199     uint32_t value = strtoul( text, &endptr, 16 );
   200     if( text == endptr ) { /* invalid input */
   201         value = defaultValue;
   202         gtk_entry_set_hex_value( entry, value );
   203     }
   204     return value;
   205 }
   207 void gtk_entry_set_hex_value( GtkEntry *entry, uint32_t value )
   208 {
   209     char buf[10];
   210     sprintf( buf, "%08X", value );
   211     gtk_entry_set_text( entry, buf );
   212 }
.