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