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
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@27
    24
int gtk_gui_run_slice( int microsecs );
nkeynes@27
    25
nkeynes@27
    26
struct dreamcast_module gtk_gui_module = { "Debugger", gtk_gui_init,
nkeynes@27
    27
					   gtk_gui_update, NULL, 
nkeynes@27
    28
					   gtk_gui_run_slice, 
nkeynes@27
    29
					   gtk_gui_update, 
nkeynes@27
    30
					   NULL, NULL };
nkeynes@27
    31
					   
nkeynes@27
    32
const cpu_desc_t cpu_descs[4] = { &sh4_cpu_desc, &arm_cpu_desc, &armt_cpu_desc, NULL };
nkeynes@27
    33
nkeynes@27
    34
nkeynes@27
    35
void gtk_gui_init() {
nkeynes@2
    36
    GdkColormap *map;
nkeynes@27
    37
    GtkWidget *debug_win;
nkeynes@27
    38
nkeynes@2
    39
    clrNormal.red = clrNormal.green = clrNormal.blue = 0;
nkeynes@2
    40
    clrChanged.red = clrChanged.green = 64*256;
nkeynes@2
    41
    clrChanged.blue = 154*256;
nkeynes@2
    42
    clrError.red = 65535;
nkeynes@2
    43
    clrError.green = clrError.blue = 64*256;
nkeynes@2
    44
    clrPC.red = 32*256;
nkeynes@2
    45
    clrPC.green = 170*256;
nkeynes@2
    46
    clrPC.blue = 52*256;
nkeynes@2
    47
    clrWarn = clrChanged;
nkeynes@2
    48
    clrTrace.red = 156*256;
nkeynes@2
    49
    clrTrace.green = 78*256;
nkeynes@2
    50
    clrTrace.blue = 201*256;
nkeynes@2
    51
    clrDebug = clrPC;
nkeynes@1
    52
nkeynes@2
    53
    map = gdk_colormap_new(gdk_visual_get_best(), TRUE);
nkeynes@2
    54
    gdk_colormap_alloc_color(map, &clrNormal, TRUE, TRUE);
nkeynes@2
    55
    gdk_colormap_alloc_color(map, &clrChanged, TRUE, TRUE);
nkeynes@2
    56
    gdk_colormap_alloc_color(map, &clrError, TRUE, TRUE);
nkeynes@2
    57
    gdk_colormap_alloc_color(map, &clrWarn, TRUE, TRUE);
nkeynes@2
    58
    gdk_colormap_alloc_color(map, &clrPC, TRUE, TRUE);
nkeynes@2
    59
    gdk_colormap_alloc_color(map, &clrDebug, TRUE, TRUE);
nkeynes@2
    60
    gdk_colormap_alloc_color(map, &clrTrace, TRUE, TRUE);
nkeynes@2
    61
    fixed_list_font = pango_font_description_from_string("Courier 10");
nkeynes@27
    62
    debug_win = create_debug_win ();
nkeynes@27
    63
    main_debug = init_debug_win(debug_win, cpu_descs);
nkeynes@27
    64
    init_mmr_win();
nkeynes@27
    65
    
nkeynes@27
    66
    gtk_widget_show (debug_win);
nkeynes@27
    67
nkeynes@2
    68
}
nkeynes@2
    69
nkeynes@27
    70
int gtk_gui_run_slice( int microsecs ) 
nkeynes@23
    71
{
nkeynes@23
    72
    while( gtk_events_pending() )
nkeynes@23
    73
	gtk_main_iteration();
nkeynes@23
    74
    update_icount(main_debug);
nkeynes@27
    75
    return microsecs;
nkeynes@23
    76
}
nkeynes@23
    77
nkeynes@27
    78
void gtk_gui_update(void) {
nkeynes@9
    79
    update_registers(main_debug);
nkeynes@9
    80
    update_icount(main_debug);
nkeynes@1
    81
    update_mmr_win();
nkeynes@2
    82
    dump_win_update_all();
nkeynes@1
    83
}
nkeynes@1
    84
nkeynes@18
    85
void open_file_callback(GtkWidget *btn, gint result, gpointer user_data) {
nkeynes@18
    86
    GtkFileChooser *file = GTK_FILE_CHOOSER(user_data);
nkeynes@18
    87
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@18
    88
	gchar *filename =gtk_file_chooser_get_filename(
nkeynes@18
    89
						       GTK_FILE_CHOOSER(file) );
nkeynes@18
    90
	file_callback_t action = (file_callback_t)gtk_object_get_data( GTK_OBJECT(file), "file_action" );
nkeynes@18
    91
	gtk_widget_destroy(GTK_WIDGET(file));
nkeynes@18
    92
	action( filename );
nkeynes@18
    93
	g_free(filename);
nkeynes@18
    94
    } else {
nkeynes@18
    95
	gtk_widget_destroy(GTK_WIDGET(file));
nkeynes@18
    96
    }
nkeynes@1
    97
}
nkeynes@1
    98
nkeynes@18
    99
static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
nkeynes@18
   100
{
nkeynes@18
   101
    if( pattern != NULL ) {
nkeynes@18
   102
	GtkFileFilter *filter = gtk_file_filter_new();
nkeynes@18
   103
	gtk_file_filter_add_pattern( filter, pattern );
nkeynes@18
   104
	gtk_file_filter_set_name( filter, patname );
nkeynes@18
   105
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@18
   106
	filter = gtk_file_filter_new();
nkeynes@18
   107
	gtk_file_filter_set_name( filter, "All files" );
nkeynes@18
   108
	gtk_file_filter_add_pattern( filter, "*" );
nkeynes@18
   109
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@18
   110
    }
nkeynes@1
   111
}
nkeynes@1
   112
nkeynes@18
   113
void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
nkeynes@1
   114
{
nkeynes@1
   115
    GtkWidget *file;
nkeynes@1
   116
nkeynes@18
   117
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@18
   118
					GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@18
   119
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@18
   120
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@18
   121
					NULL );
nkeynes@18
   122
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@18
   123
    g_signal_connect( GTK_OBJECT(file), "response", 
nkeynes@18
   124
		      GTK_SIGNAL_FUNC(open_file_callback), file );
nkeynes@18
   125
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@18
   126
    gtk_widget_show( file );
nkeynes@18
   127
}
nkeynes@18
   128
nkeynes@18
   129
void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
nkeynes@18
   130
{
nkeynes@18
   131
    GtkWidget *file;
nkeynes@18
   132
nkeynes@18
   133
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@18
   134
					GTK_FILE_CHOOSER_ACTION_SAVE,
nkeynes@18
   135
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@18
   136
					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
nkeynes@18
   137
					NULL );
nkeynes@18
   138
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@18
   139
    g_signal_connect( GTK_OBJECT(file), "response", 
nkeynes@18
   140
		      GTK_SIGNAL_FUNC(open_file_callback), file );
nkeynes@18
   141
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@1
   142
    gtk_widget_show( file );
nkeynes@1
   143
}
nkeynes@1
   144
nkeynes@2
   145
uint32_t gtk_entry_get_hex_value( GtkEntry *entry, uint32_t defaultValue )
nkeynes@1
   146
{
nkeynes@2
   147
    gchar *text = gtk_entry_get_text(entry);
nkeynes@2
   148
    if( text == NULL )
nkeynes@2
   149
        return defaultValue;
nkeynes@2
   150
    gchar *endptr;
nkeynes@2
   151
    uint32_t value = strtoul( text, &endptr, 16 );
nkeynes@2
   152
    if( text == endptr ) { /* invalid input */
nkeynes@2
   153
        value = defaultValue;
nkeynes@2
   154
        gtk_entry_set_hex_value( entry, value );
nkeynes@2
   155
    }
nkeynes@2
   156
    return value;
nkeynes@1
   157
}
nkeynes@1
   158
nkeynes@2
   159
void gtk_entry_set_hex_value( GtkEntry *entry, uint32_t value )
nkeynes@1
   160
{
nkeynes@2
   161
    char buf[10];
nkeynes@2
   162
    sprintf( buf, "%08X", value );
nkeynes@2
   163
    gtk_entry_set_text( entry, buf );
nkeynes@1
   164
}
.