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