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