Search
lxdream.org :: lxdream/src/gui/debug_win.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/debug_win.c
changeset 2:42349f6ea216
next8:6730608cdaf0
author nkeynes
date Sat Aug 21 06:15:49 2004 +0000 (17 years ago)
permissions -rw-r--r--
last change Commit changes into cvs
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/gui/debug_win.c Sat Aug 21 06:15:49 2004 +0000
1.3 @@ -0,0 +1,217 @@
1.4 +
1.5 +#include <stdlib.h>
1.6 +#include <stdarg.h>
1.7 +#include <gnome.h>
1.8 +#include <math.h>
1.9 +#include "gui.h"
1.10 +#include "mem.h"
1.11 +#include "sh4dasm.h"
1.12 +#include "sh4core.h"
1.13 +
1.14 +GdkColor *msg_colors[] = { &clrError, &clrError, &clrWarn, &clrNormal,
1.15 + &clrDebug, &clrTrace };
1.16 +
1.17 +#define REG_INT 0
1.18 +#define REG_FLT 1
1.19 +#define REG_SPECIAL 2
1.20 +
1.21 +struct reg_map_struct {
1.22 + char *name;
1.23 + int type;
1.24 + void *value;
1.25 +} reg_map[] = { {"R0", REG_INT, &sh4r.r[0]}, {"R1", REG_INT, &sh4r.r[1]},
1.26 + {"R2", REG_INT, &sh4r.r[2]}, {"R3", REG_INT, &sh4r.r[3]},
1.27 + {"R4", REG_INT, &sh4r.r[4]}, {"R5", REG_INT, &sh4r.r[5]},
1.28 + {"R6", REG_INT, &sh4r.r[6]}, {"R7", REG_INT, &sh4r.r[7]},
1.29 + {"R8", REG_INT, &sh4r.r[8]}, {"R9", REG_INT, &sh4r.r[9]},
1.30 + {"R10",REG_INT, &sh4r.r[10]}, {"R11",REG_INT, &sh4r.r[11]},
1.31 + {"R12",REG_INT, &sh4r.r[12]}, {"R13",REG_INT, &sh4r.r[13]},
1.32 + {"R14",REG_INT, &sh4r.r[14]}, {"R15",REG_INT, &sh4r.r[15]},
1.33 + {"SR", REG_INT, &sh4r.sr}, {"GBR", REG_INT, &sh4r.gbr},
1.34 + {"SSR",REG_INT, &sh4r.ssr}, {"SPC", REG_INT, &sh4r.spc},
1.35 + {"SGR",REG_INT, &sh4r.sgr}, {"DBR", REG_INT, &sh4r.dbr},
1.36 + {"VBR",REG_INT, &sh4r.vbr},
1.37 + {"PC", REG_INT, &sh4r.pc}, {"PR", REG_INT, &sh4r.pr},
1.38 + {"MACL",REG_INT, &sh4r.mac},{"MACH",REG_INT, ((uint32_t *)&sh4r.mac)+1},
1.39 + {"FPUL", REG_INT, &sh4r.fpul}, {"FPSCR", REG_INT, &sh4r.fpscr},
1.40 + {NULL, 0, NULL} };
1.41 +
1.42 +GtkCList *msgs, *regs, *disasm;
1.43 +GtkEntry *page_field;
1.44 +GtkProgressBar *icounter;
1.45 +char icounter_text[16];
1.46 +
1.47 +struct sh4_registers sh4r_s;
1.48 +int disasm_from = -1, disasm_to = -1;
1.49 +int disasm_pc = -1;
1.50 +
1.51 +
1.52 +void init_debug_win(GtkWidget *win)
1.53 +{
1.54 + int i;
1.55 + char buf[20];
1.56 + char *arr[2];
1.57 + GnomeAppBar *appbar;
1.58 +
1.59 + regs = gtk_object_get_data(GTK_OBJECT(win), "reg_list");
1.60 + arr[1] = buf;
1.61 + for( i=0; reg_map[i].name != NULL; i++ ) {
1.62 + arr[0] = reg_map[i].name;
1.63 + if( reg_map[i].type == REG_INT )
1.64 + sprintf( buf, "%08X", *((uint32_t *)reg_map[i].value) );
1.65 + else
1.66 + sprintf( buf, "%f", *((float *)reg_map[i].value) );
1.67 + gtk_clist_append( regs, arr );
1.68 + }
1.69 + gtk_widget_modify_font( GTK_WIDGET(regs), fixed_list_font );
1.70 +
1.71 + msgs = gtk_object_get_data(GTK_OBJECT(win), "output_list");
1.72 + disasm = gtk_object_get_data(GTK_OBJECT(win), "disasm_list");
1.73 + gtk_clist_set_column_width( disasm, 1, 16 );
1.74 + page_field = gtk_object_get_data(GTK_OBJECT(win), "page_field");
1.75 +
1.76 + appbar = gtk_object_get_data(GTK_OBJECT(win), "debug_appbar");
1.77 + icounter = gnome_appbar_get_progress( appbar );
1.78 + gtk_progress_bar_set_text(icounter, "1");
1.79 +}
1.80 +
1.81 +/*
1.82 + * Check for changed registers and update the display
1.83 + */
1.84 +void update_registers( void )
1.85 +{
1.86 + int i;
1.87 + for( i=0; reg_map[i].name != NULL; i++ ) {
1.88 + if( reg_map[i].type == REG_INT ) {
1.89 + /* Yes this _is_ probably fairly evil */
1.90 + if( *((uint32_t *)reg_map[i].value) !=
1.91 + *((uint32_t *)((char *)&sh4r_s + ((char *)reg_map[i].value - (char *)&sh4r))) ) {
1.92 + char buf[20];
1.93 + sprintf( buf, "%08X", *((uint32_t *)reg_map[i].value) );
1.94 + gtk_clist_set_text( regs, i, 1, buf );
1.95 + gtk_clist_set_foreground( regs, i, &clrChanged );
1.96 + } else {
1.97 + gtk_clist_set_foreground( regs, i, &clrNormal );
1.98 + }
1.99 + } else {
1.100 + if( *((float *)reg_map[i].value) !=
1.101 + *((float *)((char *)&sh4r_s + ((char *)reg_map[i].value - (char *)&sh4r))) ) {
1.102 + char buf[20];
1.103 + sprintf( buf, "%f", *((float *)reg_map[i].value) );
1.104 + gtk_clist_set_text( regs, i, 1, buf );
1.105 + gtk_clist_set_foreground( regs, i, &clrChanged );
1.106 + } else {
1.107 + gtk_clist_set_foreground( regs, i, &clrNormal );
1.108 + }
1.109 + }
1.110 + }
1.111 + if( sh4r.pc != sh4r_s.pc )
1.112 + set_disassembly_pc( sh4r.pc, FALSE );
1.113 + memcpy( &sh4r_s, &sh4r, sizeof(sh4r) );
1.114 +}
1.115 +
1.116 +void update_icount( void )
1.117 +{
1.118 + sprintf( icounter_text, "%d", sh4r.icount );
1.119 + gtk_progress_bar_set_text( icounter, icounter_text );
1.120 +}
1.121 +
1.122 +void set_disassembly_region( unsigned int page )
1.123 +{
1.124 + uint32_t i, posn;
1.125 + uint16_t op;
1.126 + char buf[80];
1.127 + char addr[10];
1.128 + char opcode[6] = "";
1.129 + char *arr[4] = { addr, " ", opcode, buf };
1.130 + unsigned int from = page & 0xFFFFF000;
1.131 + unsigned int to = from + 4096;
1.132 +
1.133 + gtk_clist_clear(disasm);
1.134 +
1.135 + sprintf( addr, "%08X", from );
1.136 + gtk_entry_set_text( page_field, addr );
1.137 +
1.138 + if( !mem_has_page( from ) ) {
1.139 + arr[3] = "This page is currently unmapped";
1.140 + gtk_clist_append( disasm, arr );
1.141 + gtk_clist_set_foreground( disasm, 0, &clrError );
1.142 + } else {
1.143 + for( i=from; i<to; i+=2 ) {
1.144 + sh4_disasm_instruction( i, buf, sizeof(buf) );
1.145 + sprintf( addr, "%08X", i );
1.146 + op = mem_read_phys_word(i);
1.147 + sprintf( opcode, "%02X %02X", op&0xFF, op>>8 );
1.148 + posn = gtk_clist_append( disasm, arr );
1.149 + if( buf[0] == '?' )
1.150 + gtk_clist_set_foreground( disasm, posn, &clrWarn );
1.151 + }
1.152 + if( disasm_pc != -1 && disasm_pc >= from && disasm_pc < to )
1.153 + gtk_clist_set_foreground( disasm, (disasm_pc - from)>>1,
1.154 + &clrPC );
1.155 + }
1.156 +
1.157 + if( page != from ) { /* not a page boundary */
1.158 + gtk_clist_moveto( disasm, (page-from)>>1, 0, 0.5, 0.0 );
1.159 + }
1.160 + disasm_from = from;
1.161 + disasm_to = to;
1.162 +}
1.163 +
1.164 +void jump_to_disassembly( unsigned int addr, gboolean select )
1.165 +{
1.166 + int row;
1.167 +
1.168 + if( addr < disasm_from || addr >= disasm_to )
1.169 + set_disassembly_region(addr);
1.170 +
1.171 + row = (addr-disasm_from)>>1;
1.172 + if(select) {
1.173 + gtk_clist_select_row( disasm, row, 0 );
1.174 + }
1.175 + if( gtk_clist_row_is_visible( disasm, row ) != GTK_VISIBILITY_FULL ){
1.176 + gtk_clist_moveto( disasm, row, 0, 0.5, 0.0 );
1.177 + }
1.178 +}
1.179 +
1.180 +void set_disassembly_pc( unsigned int pc, gboolean select )
1.181 +{
1.182 + int row;
1.183 +
1.184 + jump_to_disassembly( pc, select );
1.185 + if( disasm_pc != -1 && disasm_pc >= disasm_from && disasm_pc < disasm_to )
1.186 + gtk_clist_set_foreground( disasm, (disasm_pc - disasm_from)>>1,
1.187 + &clrNormal );
1.188 + row = (pc - disasm_from)>>1;
1.189 + gtk_clist_set_foreground( disasm, row, &clrPC );
1.190 + disasm_pc = pc;
1.191 +}
1.192 +
1.193 +
1.194 +void emit( int level, int source, char *msg, ... )
1.195 +{
1.196 + char buf[20], addr[10] = "", *p;
1.197 + char *arr[3] = {buf, addr};
1.198 + int posn;
1.199 + time_t tm = time(NULL);
1.200 + va_list ap;
1.201 +
1.202 + va_start(ap, msg);
1.203 + p = g_strdup_vprintf( msg, ap );
1.204 + strftime( buf, sizeof(buf), "%H:%M:%S", localtime(&tm) );
1.205 + if( source != -1 )
1.206 + sprintf( addr, "%08X", sh4r.pc );
1.207 + arr[2] = p;
1.208 + posn = gtk_clist_append(msgs, arr);
1.209 + free(p);
1.210 + va_end(ap);
1.211 +
1.212 + gtk_clist_set_foreground( msgs, posn, msg_colors[level] );
1.213 + gtk_clist_moveto( msgs, posn, 0, 1.0, 0.0 );
1.214 +
1.215 + /* emit _really_ slows down the emu, to the point where the gui can be
1.216 + * completely unresponsive if I don't include this:
1.217 + */
1.218 + while( gtk_events_pending() )
1.219 + gtk_main_iteration();
1.220 +}
.