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 Mon Dec 26 11:47:15 2005 +0000 (14 years ago)
permissions -rw-r--r--
last change Add sh4 + arm breakpoints
Hook up break button in GUI
Enable ARM slice in main loop
file annotate diff log raw
nkeynes@30
     1
/**
nkeynes@43
     2
 * $Id: gui.c,v 1.9 2005-12-26 11:47:15 nkeynes Exp $
nkeynes@30
     3
 * 
nkeynes@30
     4
 * Top-level GUI (GTK2) module.
nkeynes@30
     5
 *
nkeynes@30
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@30
     7
 *
nkeynes@30
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@30
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@30
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@30
    11
 * (at your option) any later version.
nkeynes@30
    12
 *
nkeynes@30
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@30
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@30
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@30
    16
 * GNU General Public License for more details.
nkeynes@30
    17
 */
nkeynes@30
    18
nkeynes@1
    19
#include <stdlib.h>
nkeynes@1
    20
#include <stdarg.h>
nkeynes@1
    21
#include <gnome.h>
nkeynes@1
    22
#include <math.h>
nkeynes@27
    23
#include "dream.h"
nkeynes@18
    24
#include "dreamcast.h"
nkeynes@1
    25
#include "mem.h"
nkeynes@30
    26
#include "sh4/sh4dasm.h"
nkeynes@30
    27
#include "aica/armdasm.h"
nkeynes@27
    28
#include "gui/gui.h"
nkeynes@1
    29
nkeynes@1
    30
#define REGISTER_FONT "-*-fixed-medium-r-normal--12-*-*-*-*-*-iso8859-1"
nkeynes@1
    31
nkeynes@1
    32
GdkColor clrNormal, clrChanged, clrError, clrWarn, clrPC, clrDebug, clrTrace;
nkeynes@43
    33
GdkColor clrBreak, clrTempBreak, clrWhite;
nkeynes@1
    34
PangoFontDescription *fixed_list_font;
nkeynes@1
    35
nkeynes@27
    36
debug_info_t main_debug;
nkeynes@27
    37
nkeynes@27
    38
nkeynes@18
    39
void open_file_callback(GtkWidget *btn, gint result, gpointer user_data);
nkeynes@1
    40
nkeynes@27
    41
void gtk_gui_init( void );
nkeynes@27
    42
void gtk_gui_update( void );
nkeynes@28
    43
void gtk_gui_start( void );
nkeynes@28
    44
void gtk_gui_stop( void );
nkeynes@30
    45
uint32_t gtk_gui_run_slice( uint32_t nanosecs );
nkeynes@27
    46
nkeynes@27
    47
struct dreamcast_module gtk_gui_module = { "Debugger", gtk_gui_init,
nkeynes@28
    48
					   gtk_gui_update, gtk_gui_start, 
nkeynes@27
    49
					   gtk_gui_run_slice, 
nkeynes@28
    50
					   gtk_gui_stop, 
nkeynes@27
    51
					   NULL, NULL };
nkeynes@27
    52
					   
nkeynes@27
    53
const cpu_desc_t cpu_descs[4] = { &sh4_cpu_desc, &arm_cpu_desc, &armt_cpu_desc, NULL };
nkeynes@27
    54
nkeynes@27
    55
nkeynes@27
    56
void gtk_gui_init() {
nkeynes@2
    57
    GdkColormap *map;
nkeynes@27
    58
    GtkWidget *debug_win;
nkeynes@27
    59
nkeynes@2
    60
    clrNormal.red = clrNormal.green = clrNormal.blue = 0;
nkeynes@2
    61
    clrChanged.red = clrChanged.green = 64*256;
nkeynes@2
    62
    clrChanged.blue = 154*256;
nkeynes@2
    63
    clrError.red = 65535;
nkeynes@2
    64
    clrError.green = clrError.blue = 64*256;
nkeynes@2
    65
    clrPC.red = 32*256;
nkeynes@2
    66
    clrPC.green = 170*256;
nkeynes@2
    67
    clrPC.blue = 52*256;
nkeynes@2
    68
    clrWarn = clrChanged;
nkeynes@2
    69
    clrTrace.red = 156*256;
nkeynes@2
    70
    clrTrace.green = 78*256;
nkeynes@2
    71
    clrTrace.blue = 201*256;
nkeynes@2
    72
    clrDebug = clrPC;
nkeynes@43
    73
    clrBreak.red = 65535;
nkeynes@43
    74
    clrBreak.green = clrBreak.blue = 192*256;
nkeynes@43
    75
    clrTempBreak.red = clrTempBreak.green = 128*256;
nkeynes@43
    76
    clrTempBreak.blue = 32*256;
nkeynes@43
    77
    clrWhite.red = clrWhite.green = clrWhite.blue = 65535;
nkeynes@1
    78
nkeynes@2
    79
    map = gdk_colormap_new(gdk_visual_get_best(), TRUE);
nkeynes@2
    80
    gdk_colormap_alloc_color(map, &clrNormal, TRUE, TRUE);
nkeynes@2
    81
    gdk_colormap_alloc_color(map, &clrChanged, TRUE, TRUE);
nkeynes@2
    82
    gdk_colormap_alloc_color(map, &clrError, TRUE, TRUE);
nkeynes@2
    83
    gdk_colormap_alloc_color(map, &clrWarn, TRUE, TRUE);
nkeynes@2
    84
    gdk_colormap_alloc_color(map, &clrPC, TRUE, TRUE);
nkeynes@2
    85
    gdk_colormap_alloc_color(map, &clrDebug, TRUE, TRUE);
nkeynes@2
    86
    gdk_colormap_alloc_color(map, &clrTrace, TRUE, TRUE);
nkeynes@43
    87
    gdk_colormap_alloc_color(map, &clrBreak, TRUE, TRUE);
nkeynes@43
    88
    gdk_colormap_alloc_color(map, &clrTempBreak, TRUE, TRUE);
nkeynes@43
    89
    gdk_colormap_alloc_color(map, &clrWhite, TRUE, TRUE);
nkeynes@2
    90
    fixed_list_font = pango_font_description_from_string("Courier 10");
nkeynes@27
    91
    debug_win = create_debug_win ();
nkeynes@27
    92
    main_debug = init_debug_win(debug_win, cpu_descs);
nkeynes@27
    93
    init_mmr_win();
nkeynes@27
    94
    
nkeynes@27
    95
    gtk_widget_show (debug_win);
nkeynes@27
    96
nkeynes@2
    97
}
nkeynes@2
    98
nkeynes@28
    99
/**
nkeynes@28
   100
 * Hook called when DC starts running. Just disables the run/step buttons
nkeynes@28
   101
 * and enables the stop button.
nkeynes@28
   102
 */
nkeynes@28
   103
void gtk_gui_start( void )
nkeynes@28
   104
{
nkeynes@28
   105
    debug_win_set_running( main_debug, TRUE );
nkeynes@28
   106
}
nkeynes@28
   107
nkeynes@28
   108
/**
nkeynes@28
   109
 * Hook called when DC stops running. Enables the run/step buttons
nkeynes@28
   110
 * and disables the stop button.
nkeynes@28
   111
 */
nkeynes@28
   112
void gtk_gui_stop( void )
nkeynes@28
   113
{
nkeynes@28
   114
    debug_win_set_running( main_debug, FALSE );
nkeynes@28
   115
    gtk_gui_update();
nkeynes@28
   116
}
nkeynes@28
   117
nkeynes@30
   118
uint32_t gtk_gui_run_slice( uint32_t nanosecs ) 
nkeynes@23
   119
{
nkeynes@23
   120
    while( gtk_events_pending() )
nkeynes@23
   121
	gtk_main_iteration();
nkeynes@23
   122
    update_icount(main_debug);
nkeynes@30
   123
    return nanosecs;
nkeynes@23
   124
}
nkeynes@23
   125
nkeynes@27
   126
void gtk_gui_update(void) {
nkeynes@9
   127
    update_registers(main_debug);
nkeynes@9
   128
    update_icount(main_debug);
nkeynes@1
   129
    update_mmr_win();
nkeynes@2
   130
    dump_win_update_all();
nkeynes@1
   131
}
nkeynes@1
   132
nkeynes@18
   133
void open_file_callback(GtkWidget *btn, gint result, gpointer user_data) {
nkeynes@18
   134
    GtkFileChooser *file = GTK_FILE_CHOOSER(user_data);
nkeynes@18
   135
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@18
   136
	gchar *filename =gtk_file_chooser_get_filename(
nkeynes@18
   137
						       GTK_FILE_CHOOSER(file) );
nkeynes@18
   138
	file_callback_t action = (file_callback_t)gtk_object_get_data( GTK_OBJECT(file), "file_action" );
nkeynes@18
   139
	gtk_widget_destroy(GTK_WIDGET(file));
nkeynes@18
   140
	action( filename );
nkeynes@18
   141
	g_free(filename);
nkeynes@18
   142
    } else {
nkeynes@18
   143
	gtk_widget_destroy(GTK_WIDGET(file));
nkeynes@18
   144
    }
nkeynes@1
   145
}
nkeynes@1
   146
nkeynes@18
   147
static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
nkeynes@18
   148
{
nkeynes@18
   149
    if( pattern != NULL ) {
nkeynes@18
   150
	GtkFileFilter *filter = gtk_file_filter_new();
nkeynes@18
   151
	gtk_file_filter_add_pattern( filter, pattern );
nkeynes@18
   152
	gtk_file_filter_set_name( filter, patname );
nkeynes@18
   153
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@18
   154
	filter = gtk_file_filter_new();
nkeynes@18
   155
	gtk_file_filter_set_name( filter, "All files" );
nkeynes@18
   156
	gtk_file_filter_add_pattern( filter, "*" );
nkeynes@18
   157
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@18
   158
    }
nkeynes@1
   159
}
nkeynes@1
   160
nkeynes@18
   161
void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
nkeynes@1
   162
{
nkeynes@1
   163
    GtkWidget *file;
nkeynes@1
   164
nkeynes@18
   165
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@18
   166
					GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@18
   167
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@18
   168
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@18
   169
					NULL );
nkeynes@18
   170
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@18
   171
    g_signal_connect( GTK_OBJECT(file), "response", 
nkeynes@18
   172
		      GTK_SIGNAL_FUNC(open_file_callback), file );
nkeynes@18
   173
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@18
   174
    gtk_widget_show( file );
nkeynes@18
   175
}
nkeynes@18
   176
nkeynes@18
   177
void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
nkeynes@18
   178
{
nkeynes@18
   179
    GtkWidget *file;
nkeynes@18
   180
nkeynes@18
   181
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@18
   182
					GTK_FILE_CHOOSER_ACTION_SAVE,
nkeynes@18
   183
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@18
   184
					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
nkeynes@18
   185
					NULL );
nkeynes@18
   186
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@18
   187
    g_signal_connect( GTK_OBJECT(file), "response", 
nkeynes@18
   188
		      GTK_SIGNAL_FUNC(open_file_callback), file );
nkeynes@18
   189
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@1
   190
    gtk_widget_show( file );
nkeynes@1
   191
}
nkeynes@1
   192
nkeynes@2
   193
uint32_t gtk_entry_get_hex_value( GtkEntry *entry, uint32_t defaultValue )
nkeynes@1
   194
{
nkeynes@2
   195
    gchar *text = gtk_entry_get_text(entry);
nkeynes@2
   196
    if( text == NULL )
nkeynes@2
   197
        return defaultValue;
nkeynes@2
   198
    gchar *endptr;
nkeynes@2
   199
    uint32_t value = strtoul( text, &endptr, 16 );
nkeynes@2
   200
    if( text == endptr ) { /* invalid input */
nkeynes@2
   201
        value = defaultValue;
nkeynes@2
   202
        gtk_entry_set_hex_value( entry, value );
nkeynes@2
   203
    }
nkeynes@2
   204
    return value;
nkeynes@1
   205
}
nkeynes@1
   206
nkeynes@2
   207
void gtk_entry_set_hex_value( GtkEntry *entry, uint32_t value )
nkeynes@1
   208
{
nkeynes@2
   209
    char buf[10];
nkeynes@2
   210
    sprintf( buf, "%08X", value );
nkeynes@2
   211
    gtk_entry_set_text( entry, buf );
nkeynes@1
   212
}
.