Replace fixed frames with scrollable windows
[emu8051.git] / src / pgmwin.c
index 80c1f08..cacc8a3 100644 (file)
@@ -1,5 +1,23 @@
-/* pgmwin.c */
-
+/*
+ * pgmwin.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 "cpu8051.h"
 #include "pgmwin.h"
 
+static GtkWidget *pgmclist;
+static unsigned int DisasmAddresses[24];
 
-/* private */
-GtkWidget *pgmwin;
-GtkWidget *pgmclist;
-int NbBreakpoints;
-unsigned int Breakpoints[ MAXBP ];
-unsigned int DisasmAddresses[ 24 ];
-
-
-/*
-int PgmWinNumber = 0;
-int PgmWinNumbers[ 1 ];
-*/
-
-
-/*PgmWin *PgmWinPtrs[ 1 ];*/
-
-
-/* in cpu8051.c */
-extern unsigned int PC;
-
-
-//////////////////////////////////////////////////////////////////////////////
-// PgmWin constructor
-//////////////////////////////////////////////////////////////////////////////
+/* Disasm 24 lines from CPU */
 void
-pgmwin_init( GtkWidget *parentwin )
+pgmwin_Disasm(void)
 {
-  int i;
-  GtkStyle *style;
-  GdkFont *fixedfont;
-  fixedfont = gdk_font_load( "-adobe-courier-medium-r-normal--12-120-75-75-m-70-iso8859-1" );
-
-  pgmclist = gtk_clist_new( 1 );
-  gtk_clist_set_selection_mode( GTK_CLIST( pgmclist ), GTK_SELECTION_SINGLE );
-  gtk_widget_set_usize( GTK_WIDGET( pgmclist ), PGM_WIN_WIDTH, PGM_WIN_HEIGHT );
-  gtk_clist_set_column_justification( GTK_CLIST( pgmclist ), 0, GTK_JUSTIFY_LEFT );
-  gtk_clist_set_column_width( GTK_CLIST( pgmclist ), 0, PGM_WIN_WIDTH-10 );
-
-  style = gtk_widget_get_style( GTK_WIDGET( pgmclist ) );
-
-#ifdef USE_GTK2
-  gtk_style_set_font( style, fixedfont );
-#else
-  style->font = fixedfont;
-#endif
-
-  gtk_widget_set_style( GTK_WIDGET( pgmclist ), style );
-
-  char *pgmdummy[] = { 0 };
-  for ( i = 0; i < 24; i++ ) gtk_clist_append( GTK_CLIST( pgmclist ), pgmdummy );
-
-  gtk_container_add( GTK_CONTAINER( parentwin ), pgmclist );
-
-  gtk_widget_show( pgmclist );
-
-  NbBreakpoints = 0;
-
-  /*
-  PgmWinPtrs[ PgmWinNumber ] = this;
-  PgmWinNumbers[ PgmWinNumber ] = PgmWinNumber;
-  gtk_signal_connect( GTK_OBJECT( pgmclist ), "button-press-event", GTK_SIGNAL_FUNC( PgmWinButtonPress ), &PgmWinNumbers[ PgmWinNumber++ ] );
-  */
-
+       char TextTmp[255];
+       int row;
+       int InstSize;
+       unsigned int Address;
+
+       Address = cpu8051.pc;
+
+       gtk_clist_freeze(GTK_CLIST(pgmclist));
+       for (row = 0; row < 24; row++) {
+               InstSize = cpu8051_Disasm(Address, TextTmp);
+               if (IsBreakpoint(Address))
+                       TextTmp[0] = '*';
+               gtk_clist_set_text(GTK_CLIST(pgmclist), row, 0, TextTmp);
+               DisasmAddresses[row] = Address;
+               Address += InstSize;
+       }
+       gtk_clist_select_row(GTK_CLIST(pgmclist), 0, 0);
+       gtk_clist_thaw(GTK_CLIST(pgmclist));
 }
 
-
-//////////////////////////////////////////////////////////////////////////////
-// void pgmwin_Disasm( )
-// Disasm 24 lines from CPU
-//////////////////////////////////////////////////////////////////////////////
-void
-pgmwin_Disasm( )
+/* Mouse button pressed in the window. */
+static gint
+pgmwin_ButtonPressEvent(GtkWidget *widget, GdkEvent *event, gpointer data)
 {
-char TextTmp[255];
-int row;
-//int TextLength;
-int InstSize;
-unsigned int Address;
-Address = PC;
-
-gtk_clist_freeze( GTK_CLIST( pgmclist ) );
- for ( row = 0; row < 24; row++ ) {
-   InstSize = cpu8051_Disasm( Address, TextTmp );
-   if ( pgmwin_IsBreakpoint( Address ) ) TextTmp[0] = '*';
-   gtk_clist_set_text( GTK_CLIST( pgmclist ), row, 0, TextTmp );
-   DisasmAddresses[ row ] = Address;
-   Address += InstSize;
- }
-gtk_clist_select_row( GTK_CLIST( pgmclist ), 0, 0 );
-gtk_clist_thaw( GTK_CLIST( pgmclist ) );
+       gint row, column;
+       char TextTmp[255];
+
+       gtk_clist_get_selection_info(GTK_CLIST(pgmclist),
+                                    (int) event->button.x,
+                                    (int) event->button.y, &row, &column);
+       if (row >= 24 || row < 0)
+               return TRUE;
+       if (column >= 1 || column < 0)
+               return TRUE;
+       sprintf(TextTmp, "pgmwin_ButtonPressEvent() at %d,%d\n", column, row);
+       g_print(TextTmp);
+       ToggleBreakpoint(DisasmAddresses[row]);
+       pgmwin_Disasm();
+
+       return FALSE;
 }
 
-//////////////////////////////////////////////////////////////////////////////
-// gint pgmwin_ButtonPressEvent( GtkWidget *widget, GdkEvent *event, gpointer data )
-// Mouse button pressed in the window
-//////////////////////////////////////////////////////////////////////////////
-gint pgmwin_ButtonPressEvent( GtkWidget *widget, GdkEvent *event, gpointer data )
-{
-  gint row, column;
-  char TextTmp[ 255 ];
-  //g_print( "pgmwin_ButtonPressEvent(...)\n" );
-  gtk_clist_get_selection_info( GTK_CLIST( pgmclist ), ( int )event->button.x ,( int )event->button.y, &row, &column );
-  if (row >= 24 || row < 0)
-    return TRUE;
-  if (column >= 1 || column < 0)
-    return TRUE;
-  sprintf( TextTmp, "pgmwin_ButtonPressEvent( ) at %d,%d\n", column, row );
-  g_print( TextTmp );
-  pgmwin_ToggleBreakpoint( DisasmAddresses[ row ] );
-  pgmwin_Disasm( );
-  return FALSE;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// gint PgmWinButtonPress( GtkWidget *widget, GdkEvent *event, gpointer data )
-// Signal Stub with 3 parameters
-//////////////////////////////////////////////////////////////////////////////
-void
-PgmWinButtonPress( GtkWidget *widget, GdkEvent *event, gpointer data )
-{
-  /*int PWNumber = *( (int *) data );*/
-  
-  pgmwin_ButtonPressEvent( widget, event, 0 );
-}
-
-
-//////////////////////////////////////////////////////////////////////////////
-// void pgmwin_ShowBreakpoints( )
-// Show Breakpoints list
-//////////////////////////////////////////////////////////////////////////////
-void pgmwin_ShowBreakpoints( )
-{
-  int Index;
-
-  for ( Index = 0; Index < NbBreakpoints ; Index++ )
-    printf( "Breakpoint at Address = %.4X\n", Breakpoints[ Index ] );
-}
 
-//////////////////////////////////////////////////////////////////////////////
-// void pgmwin_ClearBreakpoint( unsigned int Address )
-// Clear Breakpoint at Address from list
-//////////////////////////////////////////////////////////////////////////////
-void pgmwin_ClearBreakpoint( unsigned int Address )
+GtkWidget *
+pgmwin_init(int width, int height)
 {
-  int Index = 0;
-  while ( Index < NbBreakpoints && Breakpoints[ Index ] != Address ) Index++;
-  if ( Breakpoints[ Index ] != Address ) return;
-  Breakpoints[ Index ] = Breakpoints[ NbBreakpoints - 1 ];
-  NbBreakpoints--;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// void pgmwin_SetBreakpoint( unsigned int Address )
-// Set Breakpoint at Address from list
-//////////////////////////////////////////////////////////////////////////////
-void pgmwin_SetBreakpoint( unsigned int Address )
-{
-  if ( pgmwin_IsBreakpoint( Address ) ) return;
-  if ( NbBreakpoints < MAXBP ) Breakpoints[ NbBreakpoints++ ] = Address;
-}
+       int i;
+       GtkWidget *scrollwin;
 
-//////////////////////////////////////////////////////////////////////////////
-// int pgmwin_IsBreakpoint( unsigned int Address )
-// Is the a breakpoint at Address
-//////////////////////////////////////////////////////////////////////////////
-int pgmwin_IsBreakpoint( unsigned int Address )
-{
-  int Index = 0;
-  while ( Index < NbBreakpoints && Breakpoints[ Index ] != Address ) Index++;
-  return ( Breakpoints[ Index ] == Address && Index < NbBreakpoints );
-}
+       scrollwin = gtk_scrolled_window_new(NULL, NULL);
+       gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrollwin),
+                                           GTK_SHADOW_ETCHED_OUT);
 
-//////////////////////////////////////////////////////////////////////////////
-// void pgmwin_ToggleBreakpoint( unsigned int Address )
-// Toggle the breakpoint at Address
-//////////////////////////////////////////////////////////////////////////////
-void pgmwin_ToggleBreakpoint( unsigned int Address )
-{
-  if ( pgmwin_IsBreakpoint( Address ) ) pgmwin_ClearBreakpoint( Address );
-  else pgmwin_SetBreakpoint( Address );
-}
+       /* Automatically add scrollbars when necessary. */
+       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
+                                      GTK_POLICY_AUTOMATIC,
+                                      GTK_POLICY_AUTOMATIC);
 
+       gtk_widget_set_size_request(GTK_WIDGET(scrollwin), width, height);
 
+       pgmclist = gtk_clist_new(1);
+       gtk_clist_set_selection_mode(GTK_CLIST(pgmclist), GTK_SELECTION_SINGLE);
+       gtk_widget_set_size_request(GTK_WIDGET(pgmclist), width, height);
+       gtk_clist_set_column_justification(GTK_CLIST(pgmclist), 0,
+                                          GTK_JUSTIFY_LEFT);
+       gtk_clist_set_column_width(GTK_CLIST(pgmclist), 0, width-10);
 
+       PangoFontDescription *pango_font;
+       pango_font = pango_font_description_from_string(FIXED_FONT);
+       gtk_widget_modify_font(pgmclist, pango_font);
 
+       char *pgmdummy[] = { 0 };
+       for (i = 0; i < 24; i++)
+               gtk_clist_append(GTK_CLIST(pgmclist), pgmdummy);
 
+       gtk_container_add(GTK_CONTAINER(scrollwin), pgmclist);
 
+       gtk_signal_connect(GTK_OBJECT(pgmclist), "button-press-event",
+                          GTK_SIGNAL_FUNC(pgmwin_ButtonPressEvent), NULL);
 
+       return scrollwin;
+}