filename | src/gui/gui.c |
changeset | 1:eea311cfd33e |
next | 2:42349f6ea216 |
author | nkeynes |
date | Sat Mar 13 00:03:32 2004 +0000 (18 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. |
view | annotate | diff | log | raw |
1 #include <stdlib.h>
2 #include <stdarg.h>
3 #include <gnome.h>
4 #include <math.h>
5 #include "gui.h"
6 #include "mem.h"
7 #include "sh4dasm.h"
8 #include "sh4core.h"
10 #define REGISTER_FONT "-*-fixed-medium-r-normal--12-*-*-*-*-*-iso8859-1"
12 #define REG_INT 0
13 #define REG_FLT 1
14 #define REG_SPECIAL 2
16 struct reg_map_struct {
17 char *name;
18 int type;
19 void *value;
20 } reg_map[] = { {"R0", REG_INT, &sh4r.r[0]}, {"R1", REG_INT, &sh4r.r[1]},
21 {"R2", REG_INT, &sh4r.r[2]}, {"R3", REG_INT, &sh4r.r[3]},
22 {"R4", REG_INT, &sh4r.r[4]}, {"R5", REG_INT, &sh4r.r[5]},
23 {"R6", REG_INT, &sh4r.r[6]}, {"R7", REG_INT, &sh4r.r[7]},
24 {"R8", REG_INT, &sh4r.r[8]}, {"R9", REG_INT, &sh4r.r[9]},
25 {"R10",REG_INT, &sh4r.r[10]}, {"R11",REG_INT, &sh4r.r[11]},
26 {"R12",REG_INT, &sh4r.r[12]}, {"R13",REG_INT, &sh4r.r[13]},
27 {"R14",REG_INT, &sh4r.r[14]}, {"R15",REG_INT, &sh4r.r[15]},
28 {"SR", REG_INT, &sh4r.sr}, {"GBR", REG_INT, &sh4r.gbr},
29 {"SSR",REG_INT, &sh4r.ssr}, {"SPC", REG_INT, &sh4r.spc},
30 {"SGR",REG_INT, &sh4r.sgr}, {"DBR", REG_INT, &sh4r.dbr},
31 {"VBR",REG_INT, &sh4r.vbr},
32 {"PC", REG_INT, &sh4r.pc}, {"PR", REG_INT, &sh4r.pr},
33 {"MACL",REG_INT, &sh4r.mac},{"MACH",REG_INT, ((uint32_t *)&sh4r.mac)+1},
34 {"FPUL", REG_INT, &sh4r.fpul}, {"FPSCR", REG_INT, &sh4r.fpscr},
35 {NULL, 0, NULL} };
37 GtkCList *msgs, *regs, *disasm;
38 GdkColor clrNormal, clrChanged, clrError, clrWarn, clrPC, clrDebug, clrTrace;
39 GtkEntry *page_field;
40 GnomeAppBar *appbar;
41 GtkProgressBar *icounter;
42 char icounter_text[16];
43 GtkStyle *fixed_list_style;
44 PangoFontDescription *fixed_list_font;
45 GdkColor *msg_colors[] = { &clrError, &clrError, &clrWarn, &clrNormal,
46 &clrDebug, &clrTrace };
48 struct sh4_registers sh4r_s;
49 int disasm_from = -1, disasm_to = -1;
50 int disasm_pc = -1;
52 void open_file_callback(GtkWidget *btn, gpointer user_data);
53 void open_file_canceled(GtkWidget *btn, gpointer user_data);
54 void open_file( char *filename );
56 /*
57 * Check for changed registers and update the display
58 */
59 void update_registers( void )
60 {
61 int i;
62 for( i=0; reg_map[i].name != NULL; i++ ) {
63 if( reg_map[i].type == REG_INT ) {
64 /* Yes this _is_ probably fairly evil */
65 if( *((uint32_t *)reg_map[i].value) !=
66 *((uint32_t *)((char *)&sh4r_s + ((char *)reg_map[i].value - (char *)&sh4r))) ) {
67 char buf[20];
68 sprintf( buf, "%08X", *((uint32_t *)reg_map[i].value) );
69 gtk_clist_set_text( regs, i, 1, buf );
70 gtk_clist_set_foreground( regs, i, &clrChanged );
71 } else {
72 gtk_clist_set_foreground( regs, i, &clrNormal );
73 }
74 } else {
75 if( *((float *)reg_map[i].value) !=
76 *((float *)((char *)&sh4r_s + ((char *)reg_map[i].value - (char *)&sh4r))) ) {
77 char buf[20];
78 sprintf( buf, "%f", *((float *)reg_map[i].value) );
79 gtk_clist_set_text( regs, i, 1, buf );
80 gtk_clist_set_foreground( regs, i, &clrChanged );
81 } else {
82 gtk_clist_set_foreground( regs, i, &clrNormal );
83 }
84 }
85 }
86 if( sh4r.pc != sh4r_s.pc )
87 set_disassembly_pc( sh4r.pc, FALSE );
88 memcpy( &sh4r_s, &sh4r, sizeof(sh4r) );
90 update_icount();
91 update_mmr_win();
92 }
94 void update_icount( void )
95 {
96 sprintf( icounter_text, "%d", sh4r.icount );
97 gtk_progress_bar_set_text( icounter, icounter_text );
98 }
100 void set_disassembly_region( unsigned int page )
101 {
102 uint32_t i, posn;
103 uint16_t op;
104 char buf[80];
105 char addr[10];
106 char opcode[6] = "";
107 char *arr[4] = { addr, " ", opcode, buf };
108 unsigned int from = page & 0xFFFFF000;
109 unsigned int to = from + 4096;
111 gtk_clist_clear(disasm);
113 sprintf( addr, "%08X", from );
114 gtk_entry_set_text( page_field, addr );
116 if( !mem_has_page( from ) ) {
117 arr[3] = "This page is currently unmapped";
118 gtk_clist_append( disasm, arr );
119 gtk_clist_set_foreground( disasm, 0, &clrError );
120 } else {
121 for( i=from; i<to; i+=2 ) {
122 sh4_disasm_instruction( i, buf, sizeof(buf) );
123 sprintf( addr, "%08X", i );
124 op = mem_read_phys_word(i);
125 sprintf( opcode, "%02X %02X", op&0xFF, op>>8 );
126 posn = gtk_clist_append( disasm, arr );
127 if( buf[0] == '?' )
128 gtk_clist_set_foreground( disasm, posn, &clrWarn );
129 }
130 if( disasm_pc != -1 && disasm_pc >= from && disasm_pc < to )
131 gtk_clist_set_foreground( disasm, (disasm_pc - from)>>1,
132 &clrPC );
133 }
135 if( page != from ) { /* not a page boundary */
136 gtk_clist_moveto( disasm, (page-from)>>1, 0, 0.5, 0.0 );
137 }
138 disasm_from = from;
139 disasm_to = to;
140 }
142 void jump_to_disassembly( unsigned int addr, gboolean select )
143 {
144 int row;
146 if( addr < disasm_from || addr >= disasm_to )
147 set_disassembly_region(addr);
149 row = (addr-disasm_from)>>1;
150 if(select) {
151 gtk_clist_select_row( disasm, row, 0 );
152 }
153 if( gtk_clist_row_is_visible( disasm, row ) != GTK_VISIBILITY_FULL ){
154 gtk_clist_moveto( disasm, row, 0, 0.5, 0.0 );
155 }
156 }
158 void set_disassembly_pc( unsigned int pc, gboolean select )
159 {
160 int row;
162 jump_to_disassembly( pc, select );
163 if( disasm_pc != -1 && disasm_pc >= disasm_from && disasm_pc < disasm_to )
164 gtk_clist_set_foreground( disasm, (disasm_pc - disasm_from)>>1,
165 &clrNormal );
166 row = (pc - disasm_from)>>1;
167 gtk_clist_set_foreground( disasm, row, &clrPC );
168 disasm_pc = pc;
169 }
171 void open_file_callback(GtkWidget *btn, gpointer user_data) {
172 GtkFileSelection *file = GTK_FILE_SELECTION(user_data);
173 gchar *filename = strdup( gtk_file_selection_get_filename(
174 GTK_FILE_SELECTION(file) ) );
175 gtk_widget_destroy(GTK_WIDGET(file));
176 open_file( filename );
177 free(filename);
178 }
180 void open_file_canceled(GtkWidget *btn, gpointer user_data) {
181 gtk_widget_destroy(GTK_WIDGET(user_data));
182 }
184 void open_file_dialog( void )
185 {
186 GtkWidget *file;
188 file = gtk_file_selection_new( "Open..." );
189 gtk_signal_connect( GTK_OBJECT(GTK_FILE_SELECTION(file)->ok_button),
190 "clicked", GTK_SIGNAL_FUNC(open_file_callback), file );
191 gtk_signal_connect( GTK_OBJECT(GTK_FILE_SELECTION(file)->cancel_button),
192 "clicked", GTK_SIGNAL_FUNC(open_file_canceled), file );
193 gtk_widget_show( file );
194 }
196 void emit( int level, int source, char *msg, ... )
197 {
198 char buf[20], addr[10] = "", *p;
199 char *arr[3] = {buf, addr};
200 int posn;
201 time_t tm = time(NULL);
202 va_list ap;
204 va_start(ap, msg);
205 p = g_strdup_vprintf( msg, ap );
206 strftime( buf, sizeof(buf), "%H:%M:%S", localtime(&tm) );
207 if( source != -1 )
208 sprintf( addr, "%08X", sh4r.pc );
209 arr[2] = p;
210 posn = gtk_clist_append(msgs, arr);
211 free(p);
212 va_end(ap);
214 gtk_clist_set_foreground( msgs, posn, msg_colors[level] );
215 gtk_clist_moveto( msgs, posn, 0, 1.0, 0.0 );
217 /* emit _really_ slows down the emu, to the point where the gui can be
218 * completely unresponsive if I don't include this:
219 */
220 while( gtk_events_pending() )
221 gtk_main_iteration();
222 }
224 void init_debug_win(GtkWidget *win)
225 {
226 GdkColormap *map;
227 GdkFont *regfont;
228 GtkAdjustment *adj;
229 int i;
230 char buf[20];
231 char *arr[2];
233 clrNormal.red = clrNormal.green = clrNormal.blue = 0;
234 clrChanged.red = clrChanged.green = 64*256;
235 clrChanged.blue = 154*256;
236 clrError.red = 65535;
237 clrError.green = clrError.blue = 64*256;
238 clrPC.red = 32*256;
239 clrPC.green = 170*256;
240 clrPC.blue = 52*256;
241 clrWarn = clrChanged;
242 clrTrace.red = 156*256;
243 clrTrace.green = 78*256;
244 clrTrace.blue = 201*256;
245 clrDebug = clrPC;
247 map = gdk_colormap_new(gdk_visual_get_best(), TRUE);
248 gdk_colormap_alloc_color(map, &clrNormal, TRUE, TRUE);
249 gdk_colormap_alloc_color(map, &clrChanged, TRUE, TRUE);
250 gdk_colormap_alloc_color(map, &clrError, TRUE, TRUE);
251 gdk_colormap_alloc_color(map, &clrWarn, TRUE, TRUE);
252 gdk_colormap_alloc_color(map, &clrPC, TRUE, TRUE);
253 gdk_colormap_alloc_color(map, &clrDebug, TRUE, TRUE);
254 gdk_colormap_alloc_color(map, &clrTrace, TRUE, TRUE);
256 fixed_list_font = pango_font_description_from_string("Courier 10");
257 regs = gtk_object_get_data(GTK_OBJECT(win), "reg_list");
258 arr[1] = buf;
259 for( i=0; reg_map[i].name != NULL; i++ ) {
260 arr[0] = reg_map[i].name;
261 if( reg_map[i].type == REG_INT )
262 sprintf( buf, "%08X", *((uint32_t *)reg_map[i].value) );
263 else
264 sprintf( buf, "%f", *((float *)reg_map[i].value) );
265 gtk_clist_append( regs, arr );
266 }
268 fixed_list_style = gtk_style_copy( gtk_rc_get_style( GTK_WIDGET(regs) ) );
269 if( fixed_list_style != NULL ) {
270 fixed_list_style->font_desc = fixed_list_font;
271 gtk_widget_set_style( GTK_WIDGET(regs), fixed_list_style );
272 }
274 msgs = gtk_object_get_data(GTK_OBJECT(win), "output_list");
275 disasm = gtk_object_get_data(GTK_OBJECT(win), "disasm_list");
276 gtk_clist_set_column_width( disasm, 1, 16 );
277 page_field = gtk_object_get_data(GTK_OBJECT(win), "page_field");
279 appbar = gtk_object_get_data(GTK_OBJECT(win), "debug_appbar");
280 icounter = gnome_appbar_get_progress( appbar );
281 gtk_progress_bar_set_text(icounter, "1");
282 }
.