Fix bug with children not resizing with main window
[emu8051.git] / src / memwin.c
index 3e8b41d..6583ed7 100644 (file)
@@ -1,5 +1,23 @@
-/* memwin.c */
-
+/*
+ * memwin.c
+ *
+ * Copyright (C) 1999 Jonathan St-AndrĂ©
+ * Copyright (C) 1999 Hugo Villeneuve <hugo@hugovil.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
 
 #if HAVE_CONFIG_H
 #  include "config.h"
 
 #include <stdio.h>
 
+#include "common.h"
+#include "memory.h"
+#include "hexfile.h"
 #include "cpu8051.h"
 #include "memwin.h"
 
-
-/*static GtkWidget *memwin;*/
 static GtkWidget *memclist;
 
-
-//////////////////////////////////////////////////////////////////////////////
-// MemWin constructor
-//////////////////////////////////////////////////////////////////////////////
-void
-memwin_init( GtkWidget *parentwin )
+GtkWidget *
+memwin_init(void)
 {
-  int i;
-  GtkStyle *style;
-  GdkFont *fixedfont;
-  fixedfont = gdk_font_load( "-adobe-courier-medium-r-normal--12-120-75-75-m-70-iso8859-1" );
-
-  memclist = gtk_clist_new( 18 );
-  gtk_clist_set_selection_mode( GTK_CLIST( memclist ), GTK_SELECTION_SINGLE );
-  gtk_widget_set_usize( GTK_WIDGET( memclist ), 620, 250 );
-
-  for ( i = 0; i < 18; i++ ) gtk_clist_set_column_justification( GTK_CLIST( memclist ), i, GTK_JUSTIFY_LEFT );
-  gtk_clist_set_column_width( GTK_CLIST( memclist ), 0, 5*8 );
-  for ( i = 1; i < 17; i++ ) gtk_clist_set_column_width( GTK_CLIST( memclist ), i, 2*8 );
-  gtk_clist_set_column_width( GTK_CLIST( memclist ), 17, 16*8 );
-
-  style = gtk_widget_get_style( GTK_WIDGET( memclist ) );
-
-#ifdef USE_GTK2
-  gtk_style_set_font( style, fixedfont );
-#else
-  style->font = fixedfont;
-#endif
+       int i;
+       GtkWidget *scrollwin;
+       PangoFontDescription *pango_font;
+       char *memdummy[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                            0, 0, 0, 0, 0, 0, 0, 0, 0 };
 
-  gtk_widget_set_style( GTK_WIDGET( memclist ), style );
+       scrollwin = gtk_scrolled_window_new(NULL, NULL);
+       gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrollwin),
+                                           GTK_SHADOW_ETCHED_OUT);
 
-  char *memdummy[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
-  for ( i = 0; i < 16; i++ ) gtk_clist_append( GTK_CLIST( memclist ), memdummy );
+       /* Automatically add scrollbars when necessary. */
+       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
+                                      GTK_POLICY_AUTOMATIC,
+                                      GTK_POLICY_AUTOMATIC);
 
-  gtk_container_add( GTK_CONTAINER( parentwin ), memclist );
+       memclist = gtk_clist_new(18);
+       gtk_clist_set_selection_mode(GTK_CLIST(memclist), GTK_SELECTION_SINGLE);
 
-  gtk_widget_show( memclist );
-}
+       for (i = 0; i < 18; i++) {
+               gtk_clist_set_column_justification(
+                       GTK_CLIST(memclist), i, GTK_JUSTIFY_LEFT);
+       }
 
+       pango_font = pango_font_description_from_string(FIXED_FONT);
+       gtk_widget_modify_font(memclist, pango_font);
 
-//////////////////////////////////////////////////////////////////////////////
-// Dump 16 rows of 16 bytes from Address in Memory (direct addressing)
-//////////////////////////////////////////////////////////////////////////////
-void
-memwin_DumpD( unsigned int Address )
-{
-char TextTmp[255];
-int row, column, TextLength;
-
-gtk_clist_freeze( GTK_CLIST( memclist ) );
- for ( row = 0; row < 16; row++ ) {
-   sprintf( TextTmp, "%.4X", Address );
-   gtk_clist_set_text( GTK_CLIST( memclist ), row, 0, TextTmp );
-
-   for ( column = 0; column < 16; column++ ) {
-     sprintf( TextTmp, "%.2X", ( int ) cpu8051_ReadD( Address + column ) );
-     gtk_clist_set_text( GTK_CLIST( memclist ), row, column + 1, TextTmp );
-   }
-
-   TextLength = 0;
-   for ( column = 0; column < 16; column++ ) {
-     if ( ( ( int ) cpu8051_ReadD( Address + column ) >= 32 ) && ( ( int ) cpu8051_ReadD( Address + column ) <= 126 ) )
-       TextLength += sprintf( &TextTmp[ TextLength ], "%c", cpu8051_ReadD( Address + column ) );
-     else TextLength += sprintf( &TextTmp[ TextLength ], "." );
-   }
-   gtk_clist_set_text( GTK_CLIST( memclist ), row, 17, TextTmp );
-
-   Address += 16;
- }
-
-gtk_clist_select_row( GTK_CLIST( memclist ), 0, 0 );
-gtk_clist_thaw( GTK_CLIST( memclist ) );
-}
+       for (i = 0; i < 16; i++)
+               gtk_clist_append(GTK_CLIST(memclist), memdummy);
 
+       gtk_container_add(GTK_CONTAINER(scrollwin), memclist);
+
+       return scrollwin;
+}
 
-//////////////////////////////////////////////////////////////////////////////
-// Dump 16 rows of 16 bytes from Address in Memory (indirect addressing)
-//////////////////////////////////////////////////////////////////////////////
+/* Dump 16 rows of 16 bytes from Address in Memory (direct addressing) */
 void
-memwin_DumpI( unsigned int Address )
+memwin_DumpD(char *MemAddress)
 {
-  char TextTmp[255];
-  int row, column, TextLength;
-  
-  gtk_clist_freeze( GTK_CLIST( memclist ) );
-  for ( row = 0; row < 16; row++ ) {
-    sprintf( TextTmp, "%.4X", Address );
-    gtk_clist_set_text( GTK_CLIST( memclist ), row, 0, TextTmp );
-    
-    for ( column = 0; column < 16; column++ ) {
-      sprintf( TextTmp, "%.2X", ( int ) cpu8051_ReadI( Address + column ) );
-      gtk_clist_set_text( GTK_CLIST( memclist ), row, column + 1, TextTmp );
-    }
-    
-    TextLength = 0;
-    for ( column = 0; column < 16; column++ ) {
-      if ( ( ( int ) cpu8051_ReadI( Address + column ) >= 32 ) && ( ( int ) cpu8051_ReadI( Address + column ) <= 126 ) )
-       TextLength += sprintf( &TextTmp[ TextLength ], "%c", cpu8051_ReadI( Address + column ) );
-      else TextLength += sprintf( &TextTmp[ TextLength ], "." );
-    }
-    gtk_clist_set_text( GTK_CLIST( memclist ), row, 17, TextTmp );
-    
-    Address += 16;
-  }
-  gtk_clist_thaw( GTK_CLIST( memclist ) );
+       char TextTmp[1024];
+       int row, column, TextLength;
+       unsigned int Address;
+
+       if (strlen(MemAddress) != 0) {
+               if (STREQ(MemAddress, "PC"))
+                       Address = cpu8051.pc;
+               else
+                       Address = Ascii2Hex(MemAddress, strlen(MemAddress));
+       } else {
+               Address = 0;
+       }
+
+       gtk_clist_freeze(GTK_CLIST(memclist));
+
+       for (row = 0; row < 16; row++) {
+               sprintf(TextTmp, "%.4X", Address);
+               gtk_clist_set_text(GTK_CLIST(memclist), row, 0, TextTmp);
+
+               for (column = 0; column < 16; column++) {
+                       sprintf(TextTmp, "%.2X",
+                               (int) cpu8051_ReadD(Address + column));
+                       gtk_clist_set_text(GTK_CLIST(memclist), row,
+                                          column + 1, TextTmp);
+               }
+
+               TextLength = 0;
+               for (column = 0; column < 16; column++) {
+                       if (((int) cpu8051_ReadD(Address + column) >= 32) &&
+                           ((int) cpu8051_ReadD(Address + column) <= 126))
+                               TextLength += sprintf(
+                                       &TextTmp[TextLength],
+                                       "%c", cpu8051_ReadD(Address + column));
+                       else
+                               TextLength +=
+                                       sprintf(&TextTmp[TextLength], ".");
+               }
+               gtk_clist_set_text(GTK_CLIST(memclist), row, 17, TextTmp);
+
+               Address += 16;
+       }
+
+       gtk_clist_select_row(GTK_CLIST(memclist), 0, 0);
+       gtk_clist_thaw(GTK_CLIST(memclist));
 }