Search
lxdream.org :: lxdream/src/gui/gui.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gui.c
changeset 30:89b30313d757
prev28:81c206f59dc7
next43:0cf3e339cc59
author nkeynes
date Sun Dec 25 05:57:00 2005 +0000 (15 years ago)
permissions -rw-r--r--
last change Change timeslice to nanoseconds (was microseconds)
Generize single step (now steps through active CPU)
Add lots of header blocks
file annotate diff log raw
nkeynes@30
     1
/**
nkeynes@30
     2
 * $Id: gui.c,v 1.8 2005-12-25 05:57:00 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@1
    33
PangoFontDescription *fixed_list_font;
nkeynes@1
    34
nkeynes@27
    35
debug_info_t main_debug;
nkeynes@27
    36
nkeynes@27
    37
nkeynes@18
    38
void open_file_callback(GtkWidget *btn, gint result, gpointer user_data);
nkeynes@1
    39
nkeynes@27
    40
void gtk_gui_init( void );
nkeynes@27
    41
void gtk_gui_update( void );
nkeynes@28
    42
void gtk_gui_start( void );
nkeynes@28
    43
void gtk_gui_stop( void );
nkeynes@30
    44
uint32_t gtk_gui_run_slice( uint32_t nanosecs );
nkeynes@27
    45
nkeynes@27
    46
struct dreamcast_module gtk_gui_module = { "Debugger", gtk_gui_init,
nkeynes@28
    47
					   gtk_gui_update, gtk_gui_start, 
nkeynes@27
    48
					   gtk_gui_run_slice, 
nkeynes@28
    49
					   gtk_gui_stop, 
nkeynes@27
    50
					   NULL, NULL };
nkeynes@27
    51
					   
nkeynes@27
    52
const cpu_desc_t cpu_descs[4] = { &sh4_cpu_desc, &arm_cpu_desc, &armt_cpu_desc, NULL };
nkeynes@27
    53
nkeynes@27
    54
nkeynes@27
    55
void gtk_gui_init() {
nkeynes@2
    56
    GdkColormap *map;
nkeynes@27
    57
    GtkWidget *debug_win;
nkeynes@27
    58
nkeynes@2
    59
    clrNormal.red = clrNormal.green = clrNormal.blue = 0;
nkeynes@2
    60
    clrChanged.red = clrChanged.green = 64*256;
nkeynes@2
    61
    clrChanged.blue = 154*256;
nkeynes@2
    62
    clrError.red = 65535;
nkeynes@2
    63
    clrError.green = clrError.blue = 64*256;
nkeynes@2
    64
    clrPC.red = 32*256;
nkeynes@2
    65
    clrPC.green = 170*256;
nkeynes@2
    66
    clrPC.blue = 52*256;
nkeynes@2
    67
    clrWarn = clrChanged;
nkeynes@2
    68
    clrTrace.red = 156*256;
nkeynes@2
    69
    clrTrace.green = 78*256;
nkeynes@2
    70
    clrTrace.blue = 201*256;
nkeynes@2
    71
    clrDebug = clrPC;
nkeynes@1
    72
nkeynes@2
    73
    map = gdk_colormap_new(gdk_visual_get_best(), TRUE);
nkeynes@2
    74
    gdk_colormap_alloc_color(map, &clrNormal, TRUE, TRUE);
nkeynes@2
    75
    gdk_colormap_alloc_color(map, &clrChanged, TRUE, TRUE);
nkeynes@2
    76
    gdk_colormap_alloc_color(map, &clrError, TRUE, TRUE);
nkeynes@2
    77
    gdk_colormap_alloc_color(map, &clrWarn, TRUE, TRUE);
nkeynes@2
    78
    gdk_colormap_alloc_color(map, &clrPC, TRUE, TRUE);
nkeynes@2
    79
    gdk_colormap_alloc_color(map, &clrDebug, TRUE, TRUE);
nkeynes@2
    80
    gdk_colormap_alloc_color(map, &clrTrace, TRUE, TRUE);
nkeynes@2
    81
    fixed_list_font = pango_font_description_from_string("Courier 10");
nkeynes@27
    82
    debug_win = create_debug_win ();
nkeynes@27
    83
    main_debug = init_debug_win(debug_win, cpu_descs);
nkeynes@27
    84
    init_mmr_win();
nkeynes@27
    85
    
nkeynes@27
    86
    gtk_widget_show (debug_win);
nkeynes@27
    87
nkeynes@2
    88
}
nkeynes@2
    89
nkeynes@28
    90
/**
nkeynes@28
    91
 * Hook called when DC starts running. Just disables the run/step buttons
nkeynes@28
    92
 * and enables the stop button.
nkeynes@28
    93
 */
nkeynes@28
    94
void gtk_gui_start( void )
nkeynes@28
    95
{
nkeynes@28
    96
    debug_win_set_running( main_debug, TRUE );
nkeynes@28
    97
}
nkeynes@28
    98
nkeynes@28
    99
/**
nkeynes@28
   100
 * Hook called when DC stops running. Enables the run/step buttons
nkeynes@28
   101
 * and disables the stop button.
nkeynes@28
   102
 */
nkeynes@28
   103
void gtk_gui_stop( void )
nkeynes@28
   104
{
nkeynes@28
   105
    debug_win_set_running( main_debug, FALSE );
nkeynes@28
   106
    gtk_gui_update();
nkeynes@28
   107
}
nkeynes@28
   108
nkeynes@30
   109
uint32_t gtk_gui_run_slice( uint32_t nanosecs ) 
nkeynes@23
   110
{
nkeynes@23
   111
    while( gtk_events_pending() )
nkeynes@23
   112
	gtk_main_iteration();
nkeynes@23
   113
    update_icount(main_debug);
nkeynes@30
   114
    return nanosecs;
nkeynes@23
   115
}
nkeynes@23
   116
nkeynes@27
   117
void gtk_gui_update(void) {
nkeynes@9
   118
    update_registers(main_debug);
nkeynes@9
   119
    update_icount(main_debug);
nkeynes@1
   120
    update_mmr_win();
nkeynes@2
   121
    dump_win_update_all();
nkeynes@1
   122
}
nkeynes@1
   123
nkeynes@18
   124
void open_file_callback(GtkWidget *btn, gint result, gpointer user_data) {
nkeynes@18
   125
    GtkFileChooser *file = GTK_FILE_CHOOSER(user_data);
nkeynes@18
   126
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@18
   127
	gchar *filename =gtk_file_chooser_get_filename(
nkeynes@18
   128
						       GTK_FILE_CHOOSER(file) );
nkeynes@18
   129
	file_callback_t action = (file_callback_t)gtk_object_get_data( GTK_OBJECT(file), "file_action" );
nkeynes@18
   130
	gtk_widget_destroy(GTK_WIDGET(file));
nkeynes@18
   131
	action( filename );
nkeynes@18
   132
	g_free(filename);
nkeynes@18
   133
    } else {
nkeynes@18
   134
	gtk_widget_destroy(GTK_WIDGET(file));
nkeynes@18
   135
    }
nkeynes@1
   136
}
nkeynes@1
   137
nkeynes@18
   138
static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
nkeynes@18
   139
{
nkeynes@18
   140
    if( pattern != NULL ) {
nkeynes@18
   141
	GtkFileFilter *filter = gtk_file_filter_new();
nkeynes@18
   142
	gtk_file_filter_add_pattern( filter, pattern );
nkeynes@18
   143
	gtk_file_filter_set_name( filter, patname );
nkeynes@18
   144
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@18
   145
	filter = gtk_file_filter_new();
nkeynes@18
   146
	gtk_file_filter_set_name( filter, "All files" );
nkeynes@18
   147
	gtk_file_filter_add_pattern( filter, "*" );
nkeynes@18
   148
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@18
   149
    }
nkeynes@1
   150
}
nkeynes@1
   151
nkeynes@18
   152
void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
nkeynes@1
   153
{
nkeynes@1
   154
    GtkWidget *file;
nkeynes@1
   155
nkeynes@18
   156
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@18
   157
					GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@18
   158
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@18
   159
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@18
   160
					NULL );
nkeynes@18
   161
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@18
   162
    g_signal_connect( GTK_OBJECT(file), "response", 
nkeynes@18
   163
		      GTK_SIGNAL_FUNC(open_file_callback), file );
nkeynes@18
   164
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@18
   165
    gtk_widget_show( file );
nkeynes@18
   166
}
nkeynes@18
   167
nkeynes@18
   168
void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname )
nkeynes@18
   169
{
nkeynes@18
   170
    GtkWidget *file;
nkeynes@18
   171
nkeynes@18
   172
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@18
   173
					GTK_FILE_CHOOSER_ACTION_SAVE,
nkeynes@18
   174
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@18
   175
					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
nkeynes@18
   176
					NULL );
nkeynes@18
   177
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@18
   178
    g_signal_connect( GTK_OBJECT(file), "response", 
nkeynes@18
   179
		      GTK_SIGNAL_FUNC(open_file_callback), file );
nkeynes@18
   180
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@1
   181
    gtk_widget_show( file );
nkeynes@1
   182
}
nkeynes@1
   183
nkeynes@2
   184
uint32_t gtk_entry_get_hex_value( GtkEntry *entry, uint32_t defaultValue )
nkeynes@1
   185
{
nkeynes@2
   186
    gchar *text = gtk_entry_get_text(entry);
nkeynes@2
   187
    if( text == NULL )
nkeynes@2
   188
        return defaultValue;
nkeynes@2
   189
    gchar *endptr;
nkeynes@2
   190
    uint32_t value = strtoul( text, &endptr, 16 );
nkeynes@2
   191
    if( text == endptr ) { /* invalid input */
nkeynes@2
   192
        value = defaultValue;
nkeynes@2
   193
        gtk_entry_set_hex_value( entry, value );
nkeynes@2
   194
    }
nkeynes@2
   195
    return value;
nkeynes@1
   196
}
nkeynes@1
   197
nkeynes@2
   198
void gtk_entry_set_hex_value( GtkEntry *entry, uint32_t value )
nkeynes@1
   199
{
nkeynes@2
   200
    char buf[10];
nkeynes@2
   201
    sprintf( buf, "%08X", value );
nkeynes@2
   202
    gtk_entry_set_text( entry, buf );
nkeynes@1
   203
}
.