From 849888054026aa6086cb39764f93a56771f65a95 Mon Sep 17 00:00:00 2001 From: damdoum Date: Sun, 14 Jan 2007 01:50:32 +0000 Subject: [PATCH] added changes tracking to memory viewer (oh yeah ;) this mean autoupdate has been done too) --- .../src/gtk-glade/dTools/callbacks_1_ioregs.c | 18 +++ .../gtk-glade/dTools/callbacks_2_memview.c | 108 ++++++++++++++++-- .../src/gtk-glade/dTools/callbacks_dtools.h | 9 +- desmume/src/gtk-glade/desmume.c | 1 + .../src/gtk-glade/glade/DeSmuMe_Dtools.glade | 5 +- desmume/src/gtk-glade/globals.h | 5 + desmume/src/gtk-glade/main.c | 23 ++++ 7 files changed, 156 insertions(+), 13 deletions(-) diff --git a/desmume/src/gtk-glade/dTools/callbacks_1_ioregs.c b/desmume/src/gtk-glade/dTools/callbacks_1_ioregs.c index 43d6152c6..7f315a74c 100755 --- a/desmume/src/gtk-glade/dTools/callbacks_1_ioregs.c +++ b/desmume/src/gtk-glade/dTools/callbacks_1_ioregs.c @@ -28,6 +28,16 @@ static BOOL hword; static GtkLabel * reg_address; static GtkEntry * reg_value; +void display_current_reg(); + +/* update */ + +void wtools_1_update () { + display_current_reg(); +} + + +/* registers */ void display_current_reg() { char text_address[16]; @@ -58,12 +68,20 @@ void on_wtools_1_combo_cpu_changed (GtkComboBox *widget, gpointer user_data) void on_wtools_1_IOregs_show (GtkWidget *widget, gpointer user_data) { GtkWidget * b = glade_xml_get_widget(xml_tools, "wtools_1_r_ime"); GtkWidget * combo = glade_xml_get_widget(xml_tools, "wtools_1_combo_cpu"); + reg_address = (GtkLabel*)glade_xml_get_widget(xml_tools, "wtools_1_REGADRESS"); reg_value = (GtkEntry*)glade_xml_get_widget(xml_tools, "wtools_1_REGVALUE"); + // do as if we had selected this button and ARM7 cpu gtk_toggle_button_set_active((GtkToggleButton*)b, TRUE); gtk_combo_box_set_active((GtkComboBox*)combo, 0); + + register_Tool(wtools_1_update); } +gboolean on_wtools_1_IOregs_delete_event (GtkWidget *widget, GdkEvent *event, gpointer user_data) { + unregister_Tool(wtools_1_update); +} + void on_wtools_1_r_ipcfifocnt_toggled (GtkToggleButton *togglebutton, gpointer user_data) { display_reg(REG_IPCFIFOCNT,TRUE); } void on_wtools_1_r_spicnt_toggled (GtkToggleButton *togglebutton, gpointer user_data) { display_reg(REG_SPICNT,TRUE); } diff --git a/desmume/src/gtk-glade/dTools/callbacks_2_memview.c b/desmume/src/gtk-glade/dTools/callbacks_2_memview.c index 6ff7ef653..2ef72aeae 100755 --- a/desmume/src/gtk-glade/dTools/callbacks_2_memview.c +++ b/desmume/src/gtk-glade/dTools/callbacks_2_memview.c @@ -33,8 +33,10 @@ enum SHOW { static BOOL init=FALSE; static enum SHOW packmode=Bit8; static u32 address=0, tmpaddr=0, bpl=0; int cpu=0; -static PangoAttrList *attr_Text8,*attr_Text16,*attr_Text32; +static PangoAttrList *attr_Text8,*attr_Text16,*attr_Text32,*attr_red; static char patt[512]; +static u8 mem[0x100]; +static int w,h; static GtkEntry *wAddress; static GtkDrawingArea *wPaint; @@ -44,6 +46,78 @@ void refresh(); void initialise(); +/* update */ + +void wtools_2_update() { + int i,j, x,y=5; + int px = w/78, qx; + u8 m8, *mem8 =mem; u16 m16, *mem16=(u16*)mem; u32 m32, *mem32=(u32*)mem; + u32 addr; + char txt[16]; + + GtkWidget * area = (GtkWidget*)wPaint; + PangoLayout* playout = gtk_widget_create_pango_layout(area, NULL); + GdkGC * GC = area->style->fg_gc[area->state]; + + pango_layout_set_attributes(playout, attr_red); + +#define PAINT_TEXT(w) \ + gdk_draw_rectangle(area->window, area->style->white_gc, TRUE, x, y, w, h); \ + pango_layout_set_text(playout, txt, -1); \ + gdk_draw_layout(area->window, GC, x, y, playout); + + addr = address; + switch (packmode) { + case Bit8: + for (i=0; i<0x10; i++, y+=h) { + x = 12 * px + 10; qx = 62 * px + 10; + for (j=0; j<16; j++, addr++,mem8++,x+=3*px,qx+=px) { + m8 = *mem8; *mem8 = MMU_readByte(cpu, addr); + if (m8 != *mem8) { + sprintf(txt, "%02X", *mem8); + PAINT_TEXT(3*px) + } + } + } + break; + case Bit16: + for (i=0; i<0x10; i++, y+=h) { + x = 12 * px + 10; qx = 62 * px + 10; + for (j=0; j<8; j++, addr+=2,mem16++,x+=6*px,qx+=2*px) { + m16 = *mem16; *mem16 = MMU_readHWord(cpu, addr); + if (m16 != *mem16) { + sprintf(txt, " %04X", *mem16); + PAINT_TEXT(6*px) + } + } + } + break; + case Bit32: + for (i=0; i<0x10; i++, y+=h) { + x = 12 * px + 10; qx = 62 * px + 10; + for (j=0; j<4; j++, addr+=4,mem32++,x+=12*px,qx+=4*px) { + m32 = *mem32; *mem32 = MMU_readWord(cpu, addr); + if (m32 != *mem32) { + sprintf(txt, " %08X", *mem32); + PAINT_TEXT(12*px) + } + } + } + break; + } + g_object_unref(playout); + +#undef PAINT_TEXT +} + +gboolean on_wtools_2_draw_button_release_event(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { + // clear the red marks :) + if (event->button==1) + refresh(); +} + + + /* which cpu we look into */ @@ -94,8 +168,11 @@ void on_wtools_2_GotoButton_clicked (GtkButton *button, gpointer user_data) { void on_wtools_2_MemView_show (GtkWidget *widget, gpointer user_data) { initialize(); change_address(RANGE_MIN); + register_Tool(wtools_2_update); +} +gboolean on_wtools_2_MemView_delete_event (GtkWidget *widget, GdkEvent *event, gpointer user_data) { + unregister_Tool(wtools_2_update); } - /* scroll functions :D */ @@ -141,6 +218,9 @@ void initialize() { gtk_combo_box_set_active((GtkComboBox*)combo, 0); gtk_range_set_adjustment(wRange, adj); + strcpy(patt, "__00000000__"); + pango_parse_markup(patt,-1,0,&attr_red,NULL,NULL,NULL); + #define PATT(x) x"" x "" #define DUP(x) x x strcpy(patt, "0000:0000 | "); @@ -167,7 +247,11 @@ void refresh() { GtkWidget * area = (GtkWidget*)wPaint; PangoLayout* playout = gtk_widget_create_pango_layout(area, NULL); GdkGC * GC = area->style->fg_gc[area->state]; - int i,j,addr, w,h,x,y; u8 c; + int i,j,addr, x,y; u8 c; + u8 *mem8=mem; + u16 *mem16=(u16*)mem; + u32 *mem32=(u32*)mem; + char *ptxt, txt[]="0000:0000 | 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF | 0123456789ABCDEF\0"; PangoAttrList *attr; @@ -178,6 +262,10 @@ void refresh() { case Bit32: attr=attr_Text32; break; } + for (i=0; i<0x100; i++) + mem[i] = MMU_readByte(cpu, address+i); + + gdk_draw_rectangle(area->window, area->style->white_gc, TRUE, 0, 0, area->allocation.width, area->allocation.height); @@ -194,21 +282,23 @@ void refresh() { switch(packmode) { case Bit8: for (j=0; j<16; j++,ptxt+=3) - sprintf(ptxt, "%02X ", MMU_readByte(cpu, addr+j)); + sprintf(ptxt, "%02X ", mem8[j]); break; case Bit16: - for (j=0; j<16; j+=2,ptxt+=6) - sprintf(ptxt, " %04X ", MMU_readHWord(cpu, addr+j)); + for (j=0; j<16; j+=2,ptxt+=6, mem16++) + sprintf(ptxt, " %04X ", *mem16); break; case Bit32: - for (j=0; j<16; j+=4,ptxt+=12) - sprintf(ptxt, " %08X ", (int)MMU_readWord(cpu, addr+j)); + for (j=0; j<16; j+=4,ptxt+=12, mem32++) + sprintf(ptxt, " %08X ", *mem32); break; } sprintf(ptxt, "| "); ptxt +=2; for (j=0; j<16; j++,ptxt++) - sprintf(ptxt, "%c", ((c=MMU_readByte(cpu, addr+j))<0x20)?'.':((c>=0x7F)?'.':c)); // only ASCII printable + // only ASCII printable + sprintf(ptxt, "%c", ((c=mem8[j])<0x20)?'.':((c>=0x7F)?'.':c)); addr += 16; + mem8 +=16; *(ptxt)=0; pango_layout_set_text(playout, txt, -1); diff --git a/desmume/src/gtk-glade/dTools/callbacks_dtools.h b/desmume/src/gtk-glade/dTools/callbacks_dtools.h index 8dcbf02fa..0f3546f31 100755 --- a/desmume/src/gtk-glade/dTools/callbacks_dtools.h +++ b/desmume/src/gtk-glade/dTools/callbacks_dtools.h @@ -20,11 +20,15 @@ */ #include "../globals.h" +/* update functions */ +void wtools_1_update(); +void wtools_2_update(); + /* ***** ***** IO REGISTERS ***** ***** */ - void on_wtools_1_combo_cpu_changed (GtkComboBox *widget, gpointer user_data); void on_wtools_1_IOregs_show (GtkWidget *widget, gpointer user_data); +gboolean on_wtools_1_IOregs_delete_event (GtkWidget *widget, GdkEvent *event, gpointer user_data); void on_wtools_1_r_ipcfifocnt_toggled (GtkToggleButton *togglebutton, gpointer user_data); void on_wtools_1_r_spicnt_toggled (GtkToggleButton *togglebutton, gpointer user_data); void on_wtools_1_r_ime_toggled (GtkToggleButton *togglebutton, gpointer user_data); @@ -45,7 +49,8 @@ void on_wtools_1_r_dispb_winin_toggled(GtkToggleButton *togglebutton, gpointer u void on_wtools_1_r_dispb_winout_toggled(GtkToggleButton *togglebutton, gpointer user_data); /* ***** ***** MEMORY VIEWER ***** ***** */ - +gboolean on_wtools_2_MemView_delete_event (GtkWidget *widget, GdkEvent *event, gpointer user_data); +gboolean on_wtools_2_draw_button_release_event(GtkWidget *widget, GdkEventButton *event, gpointer user_data); void on_wtools_2_cpu_changed (GtkComboBox *widget, gpointer user_data); void on_wtools_2_MemView_show (GtkWidget *widget, gpointer user_data); void on_wtools_2_r8_toggled (GtkToggleButton *togglebutton, gpointer user_data); diff --git a/desmume/src/gtk-glade/desmume.c b/desmume/src/gtk-glade/desmume.c index 3411fc66e..e7d81fc6e 100755 --- a/desmume/src/gtk-glade/desmume.c +++ b/desmume/src/gtk-glade/desmume.c @@ -178,6 +178,7 @@ gboolean EmuLoop(gpointer data) Draw(); // _updateDTools(); + notify_Tools(); gtk_widget_queue_draw(pDrawingArea); gtk_widget_queue_draw(pDrawingArea2); diff --git a/desmume/src/gtk-glade/glade/DeSmuMe_Dtools.glade b/desmume/src/gtk-glade/glade/DeSmuMe_Dtools.glade index f015d5bbc..bc968f48c 100755 --- a/desmume/src/gtk-glade/glade/DeSmuMe_Dtools.glade +++ b/desmume/src/gtk-glade/glade/DeSmuMe_Dtools.glade @@ -18,9 +18,9 @@ True False True - + @@ -600,9 +600,9 @@ cpu : ARM9 True False True - + @@ -825,6 +825,7 @@ ARM7 cpu GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 diff --git a/desmume/src/gtk-glade/globals.h b/desmume/src/gtk-glade/globals.h index f268ff862..302c056d3 100755 --- a/desmume/src/gtk-glade/globals.h +++ b/desmume/src/gtk-glade/globals.h @@ -57,6 +57,11 @@ GtkWidget * pDrawingArea; GtkWidget * pDrawingArea2; GladeXML * xml, * xml_tools; +typedef void (*VoidFunPtr)(); +void notify_Tools(); +void register_Tool(VoidFunPtr fun); +void unregister_Tool(VoidFunPtr fun); + /* callbacks.c */ void enable_rom_features(); diff --git a/desmume/src/gtk-glade/main.c b/desmume/src/gtk-glade/main.c index d48847be7..d58c5175e 100755 --- a/desmume/src/gtk-glade/main.c +++ b/desmume/src/gtk-glade/main.c @@ -36,6 +36,29 @@ SoundInterface_struct *SNDCoreList[] = { NULL }; +/* ***** ***** TOOLS ***** ***** */ + +GList * tools_to_update = NULL; + +// register tool +void register_Tool(VoidFunPtr fun) { + tools_to_update = g_list_append(tools_to_update, fun); +} +void unregister_Tool(VoidFunPtr fun) { + if (tools_to_update == NULL) return; + tools_to_update = g_list_remove(tools_to_update, fun); +} + +void notify_Tool (VoidFunPtr fun, gpointer func_data) { + fun(); +} + +void notify_Tools() { + g_list_foreach(tools_to_update, ¬ify_Tool, NULL); +} + + + /* ***** ***** CONFIG FILE ***** ***** */ gint Keypad_Config[DESMUME_NB_KEYS];