Search
lxdream.org :: lxdream/src/gui/gui.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gui.c
changeset 28:81c206f59dc7
prev27:1ef09a52cd1e
next30:89b30313d757
author nkeynes
date Sun Dec 25 03:35:08 2005 +0000 (16 years ago)
permissions -rw-r--r--
last change Enable/disable run+stop buttons depending on state
file annotate diff log raw
nkeynes@1
     1
#include <stdlib.h>
nkeynes@1
     2
#include <stdarg.h>
nkeynes@1
     3
#include <gnome.h>
nkeynes@1
     4
#include <math.h>
nkeynes@27
     5
#include "dream.h"
nkeynes@18
     6
#include "dreamcast.h"
nkeynes@1
     7
#include "mem.h"
nkeynes@1
     8
#include "sh4dasm.h"
nkeynes@1
     9
#include "sh4core.h"
nkeynes@27
    10
#include "gui/gui.h"
nkeynes@1
    11
nkeynes@1
    12
#define REGISTER_FONT "-*-fixed-medium-r-normal--12-*-*-*-*-*-iso8859-1"
nkeynes@1
    13
nkeynes@1
    14
GdkColor clrNormal, clrChanged, clrError, clrWarn, clrPC, clrDebug, clrTrace;
nkeynes@1
    15
PangoFontDescription *fixed_list_font;
nkeynes@1
    16
nkeynes@27
    17
debug_info_t main_debug;
nkeynes@27
    18
nkeynes@27
    19
nkeynes@18
    20
void open_file_callback(GtkWidget *btn, gint result, gpointer user_data);
nkeynes@1
    21
nkeynes@27
    22
void gtk_gui_init( void );
nkeynes@27
    23
void gtk_gui_update( void );
nkeynes@28
    24
void gtk_gui_start( void );
nkeynes@28
    25
void gtk_gui_stop( void );
nkeynes@27
    26
int gtk_gui_run_slice( int microsecs );
nkeynes@27
    27
nkeynes@27
    28
struct dreamcast_module gtk_gui_module = { "Debugger", gtk_gui_init,
nkeynes@28
    29
					   gtk_gui_update, gtk_gui_start, 
nkeynes@27
    30
					   gtk_gui_run_slice, 
nkeynes@28
    31
					   gtk_gui_stop, 
nkeynes@27
    32
					   NULL, NULL };
nkeynes@27
    33
					   
nkeynes@27
    34
const cpu_desc_t cpu_descs[4] = { &sh4_cpu_desc, &arm_cpu_desc, &armt_cpu_desc, NULL };
nkeynes@27
    35
nkeynes@27
    36
nkeynes@27
    37
void gtk_gui_init() {
nkeynes@2
    38
    GdkColormap *map;
nkeynes@27
    39
    GtkWidget *debug_win;
nkeynes@27
    40
nkeynes@2
    41
    clrNormal.red = clrNormal.green = clrNormal.blue = 0;
nkeynes@2
    42
    clrChanged.red = clrChanged.green = 64*256;
nkeynes@2
    43
    clrChanged.blue = 154*256;
nkeynes@2
    44
    clrError.red = 65535;
nkeynes@2
    45
    clrError.green = clrError.blue = 64*256;
nkeynes@2
    46
    clrPC.red = 32*256;
nkeynes@2
    47
    clrPC.green = 170*256;
nkeynes@2
    48
    clrPC.blue = 52*256;
nkeynes@2
    49
    clrWarn = clrChanged;
nkeynes@2
    50
    clrTrace.red = 156*256;
nkeynes@2
    51
    clrTrace.green = 78*256;
nkeynes@2
    52
    clrTrace.blue = 201*256;
nkeynes@2
    53
    clrDebug = clrPC;
nkeynes@1
    54
nkeynes@2
    55
    map = gdk_colormap_new(gdk_visual_get_best(), TRUE);
nkeynes@2
    56
    gdk_colormap_alloc_color(map, &clrNormal, TRUE, TRUE);
nkeynes@2
    57
    gdk_colormap_alloc_color(map, &clrChanged, TRUE, TRUE);
nkeynes@2
    58
    gdk_colormap_alloc_color(map, &clrError, TRUE, TRUE);
nkeynes@2
    59
    gdk_colormap_alloc_color(map, &clrWarn, TRUE, TRUE);
nkeynes@2
    60
    gdk_colormap_alloc_color(map, &clrPC, TRUE, TRUE);
nkeynes@2
    61
    gdk_colormap_alloc_color(map, &clrDebug, TRUE, TRUE);
nkeynes@2
    62
    gdk_colormap_alloc_color(map, &clrTrace, TRUE, TRUE);
nkeynes@2
    63
    fixed_list_font = pango_font_description_from_string("Courier 10");
nkeynes@27
    64
    debug_win = create_debug_win ();
nkeynes@27
    65
    main_debug = init_debug_win(debug_win, cpu_descs);
nkeynes@27
    66
    init_mmr_win();
nkeynes@27
    67
    
nkeynes@27
    68
    gtk_widget_show (debug_win);
nkeynes@27
    69
nkeynes@2
    70
}
nkeynes@2
    71
nkeynes@28
    72
/**
nkeynes@28
    73
 * Hook called when DC starts running. Just disables the run/step buttons
nkeynes@28
    74
 * and enables the stop button.
nkeynes@28
    75
 */
nkeynes@28
    76
void gtk_gui_start( void )
nkeynes@28
    77
{
nkeynes@28
    78
    debug_win_set_running( main_debug, TRUE );
nkeynes@28
    79
}
nkeynes@28
    80
nkeynes@28
    81
/**
nkeynes@28
    82
 * Hook called when DC stops running. Enables the run/step buttons
nkeynes@28
    83
 * and disables the stop button.
nkeynes@28
    84
 */
nkeynes@28
    85
void gtk_gui_stop( void )
nkeynes@28
    86
{
nkeynes@28
    87
    debug_win_set_running( main_debug, FALSE );
nkeynes@28
    88
    gtk_gui_update();
nkeynes@28
    89
}
nkeynes@28
    90
nkeynes@27
    91
int gtk_gui_run_slice( int microsecs ) 
nkeynes@23
    92
{
nkeynes@23
    93
    while( gtk_events_pending() )
nkeynes@23
    94
	gtk_main_iteration();
nkeynes@23
    95
    update_icount(main_debug);
nkeynes@27
    96
    return microsecs;
nkeynes@23
    97
}
nkeynes@23
    98
nkeynes@27
    99
void gtk_gui_update(void) {
nkeynes@9
   100
    update_registers(main_debug);
nkeynes@9
   101
    update_icount(main_debug);
nkeynes@1
   102
    update_mmr_win();
nkeynes@2
   103
    dump_win_update_all();
nkeynes@1
   104
}
nkeynes@1
   105
nkeynes@18
   106
void open_file_callback(GtkWidget *btn, gint result, gpointer user_data) {
nkeynes@18
   107
    GtkFileChooser *file = GTK_FILE_CHOOSER(user_data);
nkeynes@18
   108
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@18
   109
	gchar *filename =gtk_file_chooser_get_filename(
nkeynes@18
   110
						       GTK_FILE_CHOOSER(file) );
nkeynes@18
   111
	file_callback_t action = (file_callback_t)gtk_object_get_data( GTK_OBJECT(file), "file_action" );
nkeynes@18
   112
	gtk_widget_destroy(GTK_WIDGET(file));
nkeynes@18
   113
	action( filename );
nkeynes@18
   114
	g_free(filename);
nkeynes@18
   115
    } else {
nkeynes@18
   116
	gtk_widget_destroy(GTK_WIDGET(file));
nkeynes@18
   117
    }
nkeynes@1
   118
}
nkeynes@1
   119
nkeynes@18
   120
static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
nkeynes@18
   121
{
nkeynes@18
   122
    if( pattern != NULL ) {
nkeynes@18
   123
	GtkFileFilter *filter = gtk_file_filter_new();
nkeynes@18
   124
	gtk_file_filter_add_pattern( filter, pattern );
nkeynes@18
   125
	gtk_file_filter_set_name( filter, patname );
nkeynes@18
   126
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@18
   127
	filter = gtk_file_filter_new();
nkeynes@18
   128
	gtk_file_filter_set_name( filter, "All files" );
nkeynes@18
   129
	gtk_file_filter_add_pattern( filter, "*" );
nkeynes@18
   130
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@18
   131
    }
nkeynes@1
   132
}
nkeynes@1
   133
nkeynes@18
   134
void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
nkeynes@1
   135
{
nkeynes@1
   136
    GtkWidget *file;
nkeynes@1
   137
nkeynes@18
   138
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@18
   139
					GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@18
   140
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@18
   141
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@18
   142
					NULL );
nkeynes@18
   143
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@18
   144
    g_signal_connect( GTK_OBJECT(file), "response", 
nkeynes@18
   145
		      GTK_SIGNAL_FUNC(open_file_callback), file );
nkeynes@18
   146
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@18
   147
    gtk_widget_show( file );
nkeynes@18
   148
}
nkeynes@18
   149
nkeynes@18
   150
void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
nkeynes@18
   151
{
nkeynes@18
   152
    GtkWidget *file;
nkeynes@18
   153
nkeynes@18
   154
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@18
   155
					GTK_FILE_CHOOSER_ACTION_SAVE,
nkeynes@18
   156
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@18
   157
					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
nkeynes@18
   158
					NULL );
nkeynes@18
   159
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@18
   160
    g_signal_connect( GTK_OBJECT(file), "response", 
nkeynes@18
   161
		      GTK_SIGNAL_FUNC(open_file_callback), file );
nkeynes@18
   162
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@1
   163
    gtk_widget_show( file );
nkeynes@1
   164
}
nkeynes@1
   165
nkeynes@2
   166
uint32_t gtk_entry_get_hex_value( GtkEntry *entry, uint32_t defaultValue )
nkeynes@1
   167
{
nkeynes@2
   168
    gchar *text = gtk_entry_get_text(entry);
nkeynes@2
   169
    if( text == NULL )
nkeynes@2
   170
        return defaultValue;
nkeynes@2
   171
    gchar *endptr;
nkeynes@2
   172
    uint32_t value = strtoul( text, &endptr, 16 );
nkeynes@2
   173
    if( text == endptr ) { /* invalid input */
nkeynes@2
   174
        value = defaultValue;
nkeynes@2
   175
        gtk_entry_set_hex_value( entry, value );
nkeynes@2
   176
    }
nkeynes@2
   177
    return value;
nkeynes@1
   178
}
nkeynes@1
   179
nkeynes@2
   180
void gtk_entry_set_hex_value( GtkEntry *entry, uint32_t value )
nkeynes@1
   181
{
nkeynes@2
   182
    char buf[10];
nkeynes@2
   183
    sprintf( buf, "%08X", value );
nkeynes@2
   184
    gtk_entry_set_text( entry, buf );
nkeynes@1
   185
}
.