Search
lxdream.org :: lxdream/src/gui/debug_win.c
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 (18 years ago)
permissions -rw-r--r--
last change Commit changes into cvs
view annotate diff log raw
     2 #include <stdlib.h>
     3 #include <stdarg.h>
     4 #include <gnome.h>
     5 #include <math.h>
     6 #include "gui.h"
     7 #include "mem.h"
     8 #include "sh4dasm.h"
     9 #include "sh4core.h"
    11 GdkColor *msg_colors[] = { &clrError, &clrError, &clrWarn, &clrNormal,
    12                            &clrDebug, &clrTrace };
    14 #define REG_INT 0
    15 #define REG_FLT 1
    16 #define REG_SPECIAL 2
    18 struct reg_map_struct {
    19     char *name;
    20     int type;
    21     void *value;
    22 } reg_map[] = { {"R0", REG_INT, &sh4r.r[0]}, {"R1", REG_INT, &sh4r.r[1]},
    23                 {"R2", REG_INT, &sh4r.r[2]}, {"R3", REG_INT, &sh4r.r[3]},
    24                 {"R4", REG_INT, &sh4r.r[4]}, {"R5", REG_INT, &sh4r.r[5]},
    25                 {"R6", REG_INT, &sh4r.r[6]}, {"R7", REG_INT, &sh4r.r[7]},
    26                 {"R8", REG_INT, &sh4r.r[8]}, {"R9", REG_INT, &sh4r.r[9]},
    27                 {"R10",REG_INT, &sh4r.r[10]}, {"R11",REG_INT, &sh4r.r[11]},
    28                 {"R12",REG_INT, &sh4r.r[12]}, {"R13",REG_INT, &sh4r.r[13]},
    29                 {"R14",REG_INT, &sh4r.r[14]}, {"R15",REG_INT, &sh4r.r[15]},
    30                 {"SR", REG_INT, &sh4r.sr}, {"GBR", REG_INT, &sh4r.gbr},
    31                 {"SSR",REG_INT, &sh4r.ssr}, {"SPC", REG_INT, &sh4r.spc},
    32                 {"SGR",REG_INT, &sh4r.sgr}, {"DBR", REG_INT, &sh4r.dbr},
    33                 {"VBR",REG_INT, &sh4r.vbr},
    34                 {"PC", REG_INT, &sh4r.pc}, {"PR", REG_INT, &sh4r.pr},
    35                 {"MACL",REG_INT, &sh4r.mac},{"MACH",REG_INT, ((uint32_t *)&sh4r.mac)+1},
    36                 {"FPUL", REG_INT, &sh4r.fpul}, {"FPSCR", REG_INT, &sh4r.fpscr},
    37                 {NULL, 0, NULL} };
    39 GtkCList *msgs, *regs, *disasm;
    40 GtkEntry *page_field;
    41 GtkProgressBar *icounter;
    42 char icounter_text[16];
    44 struct sh4_registers sh4r_s;
    45 int disasm_from = -1, disasm_to = -1;
    46 int disasm_pc = -1;
    49 void init_debug_win(GtkWidget *win)
    50 {
    51     int i;
    52     char buf[20];
    53     char *arr[2];
    54     GnomeAppBar *appbar;
    56     regs = gtk_object_get_data(GTK_OBJECT(win), "reg_list");
    57     arr[1] = buf;
    58     for( i=0; reg_map[i].name != NULL; i++ ) {
    59         arr[0] = reg_map[i].name;
    60         if( reg_map[i].type == REG_INT )
    61             sprintf( buf, "%08X", *((uint32_t *)reg_map[i].value) );
    62         else
    63             sprintf( buf, "%f", *((float *)reg_map[i].value) );
    64         gtk_clist_append( regs, arr );
    65     }
    66     gtk_widget_modify_font( GTK_WIDGET(regs), fixed_list_font );
    68     msgs = gtk_object_get_data(GTK_OBJECT(win), "output_list");
    69     disasm = gtk_object_get_data(GTK_OBJECT(win), "disasm_list");
    70     gtk_clist_set_column_width( disasm, 1, 16 );
    71     page_field = gtk_object_get_data(GTK_OBJECT(win), "page_field");
    73     appbar = gtk_object_get_data(GTK_OBJECT(win), "debug_appbar");
    74     icounter = gnome_appbar_get_progress( appbar );
    75     gtk_progress_bar_set_text(icounter, "1");
    76 }
    78 /*
    79  * Check for changed registers and update the display
    80  */
    81 void update_registers( void )
    82 {
    83     int i;
    84     for( i=0; reg_map[i].name != NULL; i++ ) {
    85         if( reg_map[i].type == REG_INT ) {
    86             /* Yes this _is_ probably fairly evil */
    87             if( *((uint32_t *)reg_map[i].value) !=
    88                 *((uint32_t *)((char *)&sh4r_s + ((char *)reg_map[i].value - (char *)&sh4r))) ) {
    89                 char buf[20];
    90                 sprintf( buf, "%08X", *((uint32_t *)reg_map[i].value) );
    91                 gtk_clist_set_text( regs, i, 1, buf );
    92                 gtk_clist_set_foreground( regs, i, &clrChanged );
    93             } else {
    94                 gtk_clist_set_foreground( regs, i, &clrNormal );
    95             }
    96         } else {
    97             if( *((float *)reg_map[i].value) !=
    98                 *((float *)((char *)&sh4r_s + ((char *)reg_map[i].value - (char *)&sh4r))) ) {
    99                 char buf[20];
   100                 sprintf( buf, "%f", *((float *)reg_map[i].value) );
   101                 gtk_clist_set_text( regs, i, 1, buf );
   102                 gtk_clist_set_foreground( regs, i, &clrChanged );
   103             } else {
   104                 gtk_clist_set_foreground( regs, i, &clrNormal );
   105             }
   106         }
   107     }
   108     if( sh4r.pc != sh4r_s.pc )
   109         set_disassembly_pc( sh4r.pc, FALSE );
   110     memcpy( &sh4r_s, &sh4r, sizeof(sh4r) );
   111 }
   113 void update_icount( void )
   114 {
   115     sprintf( icounter_text, "%d", sh4r.icount );
   116     gtk_progress_bar_set_text( icounter, icounter_text );
   117 }
   119 void set_disassembly_region( unsigned int page )
   120 {
   121     uint32_t i, posn;
   122     uint16_t op;
   123     char buf[80];
   124     char addr[10];
   125     char opcode[6] = "";
   126     char *arr[4] = { addr, " ", opcode, buf };
   127     unsigned int from = page & 0xFFFFF000;
   128     unsigned int to = from + 4096;
   130     gtk_clist_clear(disasm);
   132     sprintf( addr, "%08X", from );
   133     gtk_entry_set_text( page_field, addr );
   135     if( !mem_has_page( from ) ) {
   136         arr[3] = "This page is currently unmapped";
   137         gtk_clist_append( disasm, arr );
   138         gtk_clist_set_foreground( disasm, 0, &clrError );
   139     } else {
   140         for( i=from; i<to; i+=2 ) {
   141             sh4_disasm_instruction( i, buf, sizeof(buf) );
   142             sprintf( addr, "%08X", i );
   143             op = mem_read_phys_word(i);
   144             sprintf( opcode, "%02X %02X", op&0xFF, op>>8 );
   145             posn = gtk_clist_append( disasm, arr );
   146             if( buf[0] == '?' )
   147                 gtk_clist_set_foreground( disasm, posn, &clrWarn );
   148         }
   149         if( disasm_pc != -1 && disasm_pc >= from && disasm_pc < to )
   150             gtk_clist_set_foreground( disasm, (disasm_pc - from)>>1,
   151                                       &clrPC );
   152     }
   154     if( page != from ) { /* not a page boundary */
   155         gtk_clist_moveto( disasm, (page-from)>>1, 0, 0.5, 0.0 );
   156     }
   157     disasm_from = from;
   158     disasm_to = to;
   159 }
   161 void jump_to_disassembly( unsigned int addr, gboolean select )
   162 {
   163     int row;
   165     if( addr < disasm_from || addr >= disasm_to )
   166         set_disassembly_region(addr);
   168     row = (addr-disasm_from)>>1;
   169     if(select) {
   170         gtk_clist_select_row( disasm, row, 0 );
   171     }
   172     if( gtk_clist_row_is_visible( disasm, row ) != GTK_VISIBILITY_FULL ){
   173         gtk_clist_moveto( disasm, row, 0, 0.5, 0.0 );
   174     }
   175 }
   177 void set_disassembly_pc( unsigned int pc, gboolean select )
   178 {
   179     int row;
   181     jump_to_disassembly( pc, select );
   182     if( disasm_pc != -1 && disasm_pc >= disasm_from && disasm_pc < disasm_to )
   183         gtk_clist_set_foreground( disasm, (disasm_pc - disasm_from)>>1,
   184                                   &clrNormal );
   185     row = (pc - disasm_from)>>1;
   186     gtk_clist_set_foreground( disasm, row, &clrPC );
   187     disasm_pc = pc;
   188 }
   191 void emit( int level, int source, char *msg, ... )
   192 {
   193     char buf[20], addr[10] = "", *p;
   194     char *arr[3] = {buf, addr};
   195     int posn;
   196     time_t tm = time(NULL);
   197     va_list ap;
   199     va_start(ap, msg);
   200     p = g_strdup_vprintf( msg, ap );
   201     strftime( buf, sizeof(buf), "%H:%M:%S", localtime(&tm) );
   202     if( source != -1 )
   203         sprintf( addr, "%08X", sh4r.pc );
   204     arr[2] = p;
   205     posn = gtk_clist_append(msgs, arr);
   206     free(p);
   207     va_end(ap);
   209     gtk_clist_set_foreground( msgs, posn, msg_colors[level] );
   210     gtk_clist_moveto( msgs, posn, 0, 1.0, 0.0 );
   212     /* emit _really_ slows down the emu, to the point where the gui can be
   213      * completely unresponsive if I don't include this:
   214      */
   215     while( gtk_events_pending() )
   216         gtk_main_iteration();
   217 }
.