filename | src/gui/gui.c |
changeset | 1:eea311cfd33e |
next | 2:42349f6ea216 |
author | nkeynes |
date | Sat Mar 13 00:03:32 2004 +0000 (20 years ago) |
permissions | -rw-r--r-- |
last change | This commit was generated by cvs2svn to compensate for changes in r2, which included commits to RCS files with non-trunk default branches. |
file | annotate | diff | log | raw |
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +00001.2 +++ b/src/gui/gui.c Sat Mar 13 00:03:32 2004 +00001.3 @@ -0,0 +1,282 @@1.4 +#include <stdlib.h>1.5 +#include <stdarg.h>1.6 +#include <gnome.h>1.7 +#include <math.h>1.8 +#include "gui.h"1.9 +#include "mem.h"1.10 +#include "sh4dasm.h"1.11 +#include "sh4core.h"1.12 +1.13 +#define REGISTER_FONT "-*-fixed-medium-r-normal--12-*-*-*-*-*-iso8859-1"1.14 +1.15 +#define REG_INT 01.16 +#define REG_FLT 11.17 +#define REG_SPECIAL 21.18 +1.19 +struct reg_map_struct {1.20 + char *name;1.21 + int type;1.22 + void *value;1.23 +} reg_map[] = { {"R0", REG_INT, &sh4r.r[0]}, {"R1", REG_INT, &sh4r.r[1]},1.24 + {"R2", REG_INT, &sh4r.r[2]}, {"R3", REG_INT, &sh4r.r[3]},1.25 + {"R4", REG_INT, &sh4r.r[4]}, {"R5", REG_INT, &sh4r.r[5]},1.26 + {"R6", REG_INT, &sh4r.r[6]}, {"R7", REG_INT, &sh4r.r[7]},1.27 + {"R8", REG_INT, &sh4r.r[8]}, {"R9", REG_INT, &sh4r.r[9]},1.28 + {"R10",REG_INT, &sh4r.r[10]}, {"R11",REG_INT, &sh4r.r[11]},1.29 + {"R12",REG_INT, &sh4r.r[12]}, {"R13",REG_INT, &sh4r.r[13]},1.30 + {"R14",REG_INT, &sh4r.r[14]}, {"R15",REG_INT, &sh4r.r[15]},1.31 + {"SR", REG_INT, &sh4r.sr}, {"GBR", REG_INT, &sh4r.gbr},1.32 + {"SSR",REG_INT, &sh4r.ssr}, {"SPC", REG_INT, &sh4r.spc},1.33 + {"SGR",REG_INT, &sh4r.sgr}, {"DBR", REG_INT, &sh4r.dbr},1.34 + {"VBR",REG_INT, &sh4r.vbr},1.35 + {"PC", REG_INT, &sh4r.pc}, {"PR", REG_INT, &sh4r.pr},1.36 + {"MACL",REG_INT, &sh4r.mac},{"MACH",REG_INT, ((uint32_t *)&sh4r.mac)+1},1.37 + {"FPUL", REG_INT, &sh4r.fpul}, {"FPSCR", REG_INT, &sh4r.fpscr},1.38 + {NULL, 0, NULL} };1.39 +1.40 +GtkCList *msgs, *regs, *disasm;1.41 +GdkColor clrNormal, clrChanged, clrError, clrWarn, clrPC, clrDebug, clrTrace;1.42 +GtkEntry *page_field;1.43 +GnomeAppBar *appbar;1.44 +GtkProgressBar *icounter;1.45 +char icounter_text[16];1.46 +GtkStyle *fixed_list_style;1.47 +PangoFontDescription *fixed_list_font;1.48 +GdkColor *msg_colors[] = { &clrError, &clrError, &clrWarn, &clrNormal,1.49 + &clrDebug, &clrTrace };1.50 +1.51 +struct sh4_registers sh4r_s;1.52 +int disasm_from = -1, disasm_to = -1;1.53 +int disasm_pc = -1;1.54 +1.55 +void open_file_callback(GtkWidget *btn, gpointer user_data);1.56 +void open_file_canceled(GtkWidget *btn, gpointer user_data);1.57 +void open_file( char *filename );1.58 +1.59 +/*1.60 + * Check for changed registers and update the display1.61 + */1.62 +void update_registers( void )1.63 +{1.64 + int i;1.65 + for( i=0; reg_map[i].name != NULL; i++ ) {1.66 + if( reg_map[i].type == REG_INT ) {1.67 + /* Yes this _is_ probably fairly evil */1.68 + if( *((uint32_t *)reg_map[i].value) !=1.69 + *((uint32_t *)((char *)&sh4r_s + ((char *)reg_map[i].value - (char *)&sh4r))) ) {1.70 + char buf[20];1.71 + sprintf( buf, "%08X", *((uint32_t *)reg_map[i].value) );1.72 + gtk_clist_set_text( regs, i, 1, buf );1.73 + gtk_clist_set_foreground( regs, i, &clrChanged );1.74 + } else {1.75 + gtk_clist_set_foreground( regs, i, &clrNormal );1.76 + }1.77 + } else {1.78 + if( *((float *)reg_map[i].value) !=1.79 + *((float *)((char *)&sh4r_s + ((char *)reg_map[i].value - (char *)&sh4r))) ) {1.80 + char buf[20];1.81 + sprintf( buf, "%f", *((float *)reg_map[i].value) );1.82 + gtk_clist_set_text( regs, i, 1, buf );1.83 + gtk_clist_set_foreground( regs, i, &clrChanged );1.84 + } else {1.85 + gtk_clist_set_foreground( regs, i, &clrNormal );1.86 + }1.87 + }1.88 + }1.89 + if( sh4r.pc != sh4r_s.pc )1.90 + set_disassembly_pc( sh4r.pc, FALSE );1.91 + memcpy( &sh4r_s, &sh4r, sizeof(sh4r) );1.92 +1.93 + update_icount();1.94 + update_mmr_win();1.95 +}1.96 +1.97 +void update_icount( void )1.98 +{1.99 + sprintf( icounter_text, "%d", sh4r.icount );1.100 + gtk_progress_bar_set_text( icounter, icounter_text );1.101 +}1.102 +1.103 +void set_disassembly_region( unsigned int page )1.104 +{1.105 + uint32_t i, posn;1.106 + uint16_t op;1.107 + char buf[80];1.108 + char addr[10];1.109 + char opcode[6] = "";1.110 + char *arr[4] = { addr, " ", opcode, buf };1.111 + unsigned int from = page & 0xFFFFF000;1.112 + unsigned int to = from + 4096;1.113 +1.114 + gtk_clist_clear(disasm);1.115 +1.116 + sprintf( addr, "%08X", from );1.117 + gtk_entry_set_text( page_field, addr );1.118 +1.119 + if( !mem_has_page( from ) ) {1.120 + arr[3] = "This page is currently unmapped";1.121 + gtk_clist_append( disasm, arr );1.122 + gtk_clist_set_foreground( disasm, 0, &clrError );1.123 + } else {1.124 + for( i=from; i<to; i+=2 ) {1.125 + sh4_disasm_instruction( i, buf, sizeof(buf) );1.126 + sprintf( addr, "%08X", i );1.127 + op = mem_read_phys_word(i);1.128 + sprintf( opcode, "%02X %02X", op&0xFF, op>>8 );1.129 + posn = gtk_clist_append( disasm, arr );1.130 + if( buf[0] == '?' )1.131 + gtk_clist_set_foreground( disasm, posn, &clrWarn );1.132 + }1.133 + if( disasm_pc != -1 && disasm_pc >= from && disasm_pc < to )1.134 + gtk_clist_set_foreground( disasm, (disasm_pc - from)>>1,1.135 + &clrPC );1.136 + }1.137 +1.138 + if( page != from ) { /* not a page boundary */1.139 + gtk_clist_moveto( disasm, (page-from)>>1, 0, 0.5, 0.0 );1.140 + }1.141 + disasm_from = from;1.142 + disasm_to = to;1.143 +}1.144 +1.145 +void jump_to_disassembly( unsigned int addr, gboolean select )1.146 +{1.147 + int row;1.148 +1.149 + if( addr < disasm_from || addr >= disasm_to )1.150 + set_disassembly_region(addr);1.151 +1.152 + row = (addr-disasm_from)>>1;1.153 + if(select) {1.154 + gtk_clist_select_row( disasm, row, 0 );1.155 + }1.156 + if( gtk_clist_row_is_visible( disasm, row ) != GTK_VISIBILITY_FULL ){1.157 + gtk_clist_moveto( disasm, row, 0, 0.5, 0.0 );1.158 + }1.159 +}1.160 +1.161 +void set_disassembly_pc( unsigned int pc, gboolean select )1.162 +{1.163 + int row;1.164 +1.165 + jump_to_disassembly( pc, select );1.166 + if( disasm_pc != -1 && disasm_pc >= disasm_from && disasm_pc < disasm_to )1.167 + gtk_clist_set_foreground( disasm, (disasm_pc - disasm_from)>>1,1.168 + &clrNormal );1.169 + row = (pc - disasm_from)>>1;1.170 + gtk_clist_set_foreground( disasm, row, &clrPC );1.171 + disasm_pc = pc;1.172 +}1.173 +1.174 +void open_file_callback(GtkWidget *btn, gpointer user_data) {1.175 + GtkFileSelection *file = GTK_FILE_SELECTION(user_data);1.176 + gchar *filename = strdup( gtk_file_selection_get_filename(1.177 + GTK_FILE_SELECTION(file) ) );1.178 + gtk_widget_destroy(GTK_WIDGET(file));1.179 + open_file( filename );1.180 + free(filename);1.181 +}1.182 +1.183 +void open_file_canceled(GtkWidget *btn, gpointer user_data) {1.184 + gtk_widget_destroy(GTK_WIDGET(user_data));1.185 +}1.186 +1.187 +void open_file_dialog( void )1.188 +{1.189 + GtkWidget *file;1.190 +1.191 + file = gtk_file_selection_new( "Open..." );1.192 + gtk_signal_connect( GTK_OBJECT(GTK_FILE_SELECTION(file)->ok_button),1.193 + "clicked", GTK_SIGNAL_FUNC(open_file_callback), file );1.194 + gtk_signal_connect( GTK_OBJECT(GTK_FILE_SELECTION(file)->cancel_button),1.195 + "clicked", GTK_SIGNAL_FUNC(open_file_canceled), file );1.196 + gtk_widget_show( file );1.197 +}1.198 +1.199 +void emit( int level, int source, char *msg, ... )1.200 +{1.201 + char buf[20], addr[10] = "", *p;1.202 + char *arr[3] = {buf, addr};1.203 + int posn;1.204 + time_t tm = time(NULL);1.205 + va_list ap;1.206 +1.207 + va_start(ap, msg);1.208 + p = g_strdup_vprintf( msg, ap );1.209 + strftime( buf, sizeof(buf), "%H:%M:%S", localtime(&tm) );1.210 + if( source != -1 )1.211 + sprintf( addr, "%08X", sh4r.pc );1.212 + arr[2] = p;1.213 + posn = gtk_clist_append(msgs, arr);1.214 + free(p);1.215 + va_end(ap);1.216 +1.217 + gtk_clist_set_foreground( msgs, posn, msg_colors[level] );1.218 + gtk_clist_moveto( msgs, posn, 0, 1.0, 0.0 );1.219 +1.220 + /* emit _really_ slows down the emu, to the point where the gui can be1.221 + * completely unresponsive if I don't include this:1.222 + */1.223 + while( gtk_events_pending() )1.224 + gtk_main_iteration();1.225 +}1.226 +1.227 +void init_debug_win(GtkWidget *win)1.228 +{1.229 + GdkColormap *map;1.230 + GdkFont *regfont;1.231 + GtkAdjustment *adj;1.232 + int i;1.233 + char buf[20];1.234 + char *arr[2];1.235 +1.236 + clrNormal.red = clrNormal.green = clrNormal.blue = 0;1.237 + clrChanged.red = clrChanged.green = 64*256;1.238 + clrChanged.blue = 154*256;1.239 + clrError.red = 65535;1.240 + clrError.green = clrError.blue = 64*256;1.241 + clrPC.red = 32*256;1.242 + clrPC.green = 170*256;1.243 + clrPC.blue = 52*256;1.244 + clrWarn = clrChanged;1.245 + clrTrace.red = 156*256;1.246 + clrTrace.green = 78*256;1.247 + clrTrace.blue = 201*256;1.248 + clrDebug = clrPC;1.249 +1.250 + map = gdk_colormap_new(gdk_visual_get_best(), TRUE);1.251 + gdk_colormap_alloc_color(map, &clrNormal, TRUE, TRUE);1.252 + gdk_colormap_alloc_color(map, &clrChanged, TRUE, TRUE);1.253 + gdk_colormap_alloc_color(map, &clrError, TRUE, TRUE);1.254 + gdk_colormap_alloc_color(map, &clrWarn, TRUE, TRUE);1.255 + gdk_colormap_alloc_color(map, &clrPC, TRUE, TRUE);1.256 + gdk_colormap_alloc_color(map, &clrDebug, TRUE, TRUE);1.257 + gdk_colormap_alloc_color(map, &clrTrace, TRUE, TRUE);1.258 +1.259 + fixed_list_font = pango_font_description_from_string("Courier 10");1.260 + regs = gtk_object_get_data(GTK_OBJECT(win), "reg_list");1.261 + arr[1] = buf;1.262 + for( i=0; reg_map[i].name != NULL; i++ ) {1.263 + arr[0] = reg_map[i].name;1.264 + if( reg_map[i].type == REG_INT )1.265 + sprintf( buf, "%08X", *((uint32_t *)reg_map[i].value) );1.266 + else1.267 + sprintf( buf, "%f", *((float *)reg_map[i].value) );1.268 + gtk_clist_append( regs, arr );1.269 + }1.270 +1.271 + fixed_list_style = gtk_style_copy( gtk_rc_get_style( GTK_WIDGET(regs) ) );1.272 + if( fixed_list_style != NULL ) {1.273 + fixed_list_style->font_desc = fixed_list_font;1.274 + gtk_widget_set_style( GTK_WIDGET(regs), fixed_list_style );1.275 + }1.276 +1.277 + msgs = gtk_object_get_data(GTK_OBJECT(win), "output_list");1.278 + disasm = gtk_object_get_data(GTK_OBJECT(win), "disasm_list");1.279 + gtk_clist_set_column_width( disasm, 1, 16 );1.280 + page_field = gtk_object_get_data(GTK_OBJECT(win), "page_field");1.281 +1.282 + appbar = gtk_object_get_data(GTK_OBJECT(win), "debug_appbar");1.283 + icounter = gnome_appbar_get_progress( appbar );1.284 + gtk_progress_bar_set_text(icounter, "1");1.285 +}
.