Search
lxdream.org :: lxdream/src/gui/gui.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gui.c
changeset 109:cc84a653c781
prev106:9048bac046c3
next167:71c0cc416a64
author nkeynes
date Wed Mar 15 13:17:23 2006 +0000 (16 years ago)
permissions -rw-r--r--
last change Limit gui hooks to only every 1/10 second of emulated time
file annotate diff log raw
nkeynes@30
     1
/**
nkeynes@109
     2
 * $Id: gui.c,v 1.11 2006-03-15 13:17:23 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@109
   118
uint32_t gtk_gui_nanos = 0;
nkeynes@109
   119
nkeynes@30
   120
uint32_t gtk_gui_run_slice( uint32_t nanosecs ) 
nkeynes@23
   121
{
nkeynes@109
   122
    gtk_gui_nanos += nanosecs;
nkeynes@109
   123
    if( gtk_gui_nanos > 10000000 ) { /* About 10/sec */
nkeynes@109
   124
	gtk_gui_nanos = 0;
nkeynes@109
   125
	while( gtk_events_pending() )
nkeynes@109
   126
	    gtk_main_iteration();
nkeynes@109
   127
	update_icount(main_debug);
nkeynes@109
   128
	return nanosecs;
nkeynes@109
   129
    }
nkeynes@23
   130
}
nkeynes@23
   131
nkeynes@27
   132
void gtk_gui_update(void) {
nkeynes@106
   133
    if( main_debug == NULL )
nkeynes@106
   134
	return;
nkeynes@9
   135
    update_registers(main_debug);
nkeynes@9
   136
    update_icount(main_debug);
nkeynes@1
   137
    update_mmr_win();
nkeynes@2
   138
    dump_win_update_all();
nkeynes@1
   139
}
nkeynes@1
   140
nkeynes@18
   141
void open_file_callback(GtkWidget *btn, gint result, gpointer user_data) {
nkeynes@18
   142
    GtkFileChooser *file = GTK_FILE_CHOOSER(user_data);
nkeynes@18
   143
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@18
   144
	gchar *filename =gtk_file_chooser_get_filename(
nkeynes@18
   145
						       GTK_FILE_CHOOSER(file) );
nkeynes@18
   146
	file_callback_t action = (file_callback_t)gtk_object_get_data( GTK_OBJECT(file), "file_action" );
nkeynes@18
   147
	gtk_widget_destroy(GTK_WIDGET(file));
nkeynes@18
   148
	action( filename );
nkeynes@18
   149
	g_free(filename);
nkeynes@18
   150
    } else {
nkeynes@18
   151
	gtk_widget_destroy(GTK_WIDGET(file));
nkeynes@18
   152
    }
nkeynes@1
   153
}
nkeynes@1
   154
nkeynes@18
   155
static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
nkeynes@18
   156
{
nkeynes@18
   157
    if( pattern != NULL ) {
nkeynes@18
   158
	GtkFileFilter *filter = gtk_file_filter_new();
nkeynes@18
   159
	gtk_file_filter_add_pattern( filter, pattern );
nkeynes@18
   160
	gtk_file_filter_set_name( filter, patname );
nkeynes@18
   161
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@18
   162
	filter = gtk_file_filter_new();
nkeynes@18
   163
	gtk_file_filter_set_name( filter, "All files" );
nkeynes@18
   164
	gtk_file_filter_add_pattern( filter, "*" );
nkeynes@18
   165
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@18
   166
    }
nkeynes@1
   167
}
nkeynes@1
   168
nkeynes@18
   169
void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
nkeynes@1
   170
{
nkeynes@1
   171
    GtkWidget *file;
nkeynes@1
   172
nkeynes@18
   173
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@18
   174
					GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@18
   175
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@18
   176
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@18
   177
					NULL );
nkeynes@18
   178
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@18
   179
    g_signal_connect( GTK_OBJECT(file), "response", 
nkeynes@18
   180
		      GTK_SIGNAL_FUNC(open_file_callback), file );
nkeynes@18
   181
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@18
   182
    gtk_widget_show( file );
nkeynes@18
   183
}
nkeynes@18
   184
nkeynes@18
   185
void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
nkeynes@18
   186
{
nkeynes@18
   187
    GtkWidget *file;
nkeynes@18
   188
nkeynes@18
   189
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@18
   190
					GTK_FILE_CHOOSER_ACTION_SAVE,
nkeynes@18
   191
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@18
   192
					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
nkeynes@18
   193
					NULL );
nkeynes@18
   194
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@18
   195
    g_signal_connect( GTK_OBJECT(file), "response", 
nkeynes@18
   196
		      GTK_SIGNAL_FUNC(open_file_callback), file );
nkeynes@18
   197
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@1
   198
    gtk_widget_show( file );
nkeynes@1
   199
}
nkeynes@1
   200
nkeynes@2
   201
uint32_t gtk_entry_get_hex_value( GtkEntry *entry, uint32_t defaultValue )
nkeynes@1
   202
{
nkeynes@2
   203
    gchar *text = gtk_entry_get_text(entry);
nkeynes@2
   204
    if( text == NULL )
nkeynes@2
   205
        return defaultValue;
nkeynes@2
   206
    gchar *endptr;
nkeynes@2
   207
    uint32_t value = strtoul( text, &endptr, 16 );
nkeynes@2
   208
    if( text == endptr ) { /* invalid input */
nkeynes@2
   209
        value = defaultValue;
nkeynes@2
   210
        gtk_entry_set_hex_value( entry, value );
nkeynes@2
   211
    }
nkeynes@2
   212
    return value;
nkeynes@1
   213
}
nkeynes@1
   214
nkeynes@2
   215
void gtk_entry_set_hex_value( GtkEntry *entry, uint32_t value )
nkeynes@1
   216
{
nkeynes@2
   217
    char buf[10];
nkeynes@2
   218
    sprintf( buf, "%08X", value );
nkeynes@2
   219
    gtk_entry_set_text( entry, buf );
nkeynes@1
   220
}
.