Code simplification and cleanup
authorHugo Villeneuve <hugo@hugovil.com>
Sat, 15 May 2004 06:54:37 +0000 (06:54 +0000)
committerHugo Villeneuve <hugo@hugovil.com>
Sun, 8 Sep 2013 22:54:51 +0000 (18:54 -0400)
28 files changed:
src/Makefile.am
src/common.h
src/cpu8051.c
src/cpu8051.h
src/emugtk.c
src/emugtk.h
src/file.c [deleted file]
src/file.h [deleted file]
src/filemenu.c [new file with mode: 0644]
src/filemenu.h [new file with mode: 0644]
src/helpmenu.c [new file with mode: 0644]
src/helpmenu.h [new file with mode: 0644]
src/hexfile.c [new file with mode: 0644]
src/hexfile.h [new file with mode: 0644]
src/memory.c
src/memwin.c
src/memwin.h
src/messagebox.c [new file with mode: 0644]
src/messagebox.h [new file with mode: 0644]
src/opcode2c.pl
src/options.c
src/options.h
src/pgmwin.c
src/pgmwin.h
src/regwin.c
src/regwin.h
src/viewmenu.c [new file with mode: 0644]
src/viewmenu.h [new file with mode: 0644]

index 30bb820..60133a7 100644 (file)
@@ -5,22 +5,21 @@ INCLUDES = -I$(top_srcdir)/pixmaps
 bin_PROGRAMS = emu8051
 # emu8051_console
 
-emu8051_SOURCES = cpu8051.c emugtk.c memory.c memwin.c pgmwin.c regwin.c options.c file.c \
-                  instructions_8051.c
+emu8051_SOURCES = cpu8051.c emugtk.c memory.c memwin.c pgmwin.c regwin.c options.c hexfile.c \
+                  instructions_8051.c filemenu.c viewmenu.c helpmenu.c messagebox.c
 
 #emu8051_console_SOURCES = EmuConsole.cpp cpu8051.c memory.c options.c file.c
 
 # These headers will be included in the distribution tarball, but will not be
 # installed by 'make install'
-noinst_HEADERS = instructions_8051.h EmuConsole.hpp Keyboard.hpp reg8051.h gtksizes.h \
-                 disasm.hpp
-#                 exceptions.hpp
+noinst_HEADERS = EmuConsole.hpp Keyboard.hpp reg8051.h gtksizes.h hexfile.h filemenu.h \
+                 filemenu.h viewmenu.h helpmenu.h messagebox.h pgmwin.h memwin.h regwin.h
 
 CLEANFILES     = *~
 
 DISTCLEANFILES = .deps/*.P
 
-MAINTAINERCLEANFILES = Makefile.in
+MAINTAINERCLEANFILES = Makefile.in instructions_8051.c instructions_8051.h disasm.h
 
 EXTRA_DIST = opcode2c.pl opcodes.lst instructions_8051.h
 
index 9a3d3e8..4b91b2f 100644 (file)
 #endif
 
 
+#if ( GTK_MAJOR_VERSION == 2 )
+#  define FIXED_FONT "monospace 12"
+#else
+/*#  define FIXED_FONT "-misc-fixed-medium-r-*-*-*-140-*-*-*-*-*-*"*/
+#  define FIXED_FONT "-adobe-courier-medium-r-normal--12-120-75-75-m-70-iso8859-1"
+#endif
+
+
 /* Common constants. */
 #ifndef EXIT_SUCCESS
 #  define EXIT_SUCCESS 0
index 1bdc42e..a4e587b 100644 (file)
@@ -1,6 +1,10 @@
 /* cpu8051.c */
 
 
+/* Define only here, for not having extern scope on local variables. */
+#define CPU8051_M 1
+
+
 #include <stdio.h>
 
 #include "reg8051.h"
 #include "instructions_8051.h"
 
 
-unsigned int PC = 0;
-unsigned long CLOCK = 0;
-int ActivePriority = -1;
-
-
-extern OPCODE_FP opcode_table[256];
+void
+cpu8051_init( void )
+{
+  cpu8051.pc = 0;
+  cpu8051.clock = 0;
+  cpu8051.active_priority = -1;
+}
 
 
 //////////////////////////////////////////////////////////////////////////////
-// Execute at address PC from PGMMem
+// Execute at address cpu8051.pc from PGMMem
 //////////////////////////////////////////////////////////////////////////////
 void
 cpu8051_Exec( void )
@@ -28,26 +33,26 @@ cpu8051_Exec( void )
   unsigned char opcode;
   int insttiming;
 
-  opcode = memory_read8( PGM_MEM_ID, PC );
-  PC++;
+  opcode = memory_read8( PGM_MEM_ID, cpu8051.pc );
+  cpu8051.pc++;
   insttiming = (*opcode_table[opcode])(); /* Function callback. */
   
   for( i = 0; i < insttiming; i++ ) {
     cpu8051_CheckInterrupts();
     cpu8051_DoTimers();
-    CLOCK++;
+    cpu8051.clock++;
   }
 }
 
 
 //////////////////////////////////////////////////////////////////////////////
-// Return PC + size in bytes of current instruction
+// Return cpu8051.pc + size in bytes of current instruction
 //////////////////////////////////////////////////////////////////////////////
 unsigned int
 cpu8051_GetNextAddress( void )
 {
 #ifdef DECPP
-  return ( PC + InstSizesTbl[ memory_read8( PGM_MEM_ID, PC ) ] );
+  return ( cpu8051.pc + InstSizesTbl[ memory_read8( PGM_MEM_ID, cpu8051.pc ) ] );
 #endif
   return 0; /* temp */
 }
@@ -59,9 +64,9 @@ cpu8051_GetNextAddress( void )
 void
 cpu8051_Reset( void )
 {
-  PC = 0;
-  CLOCK = 0;
-  ActivePriority = -1;
+  cpu8051.pc = 0;
+  cpu8051.clock= 0;
+  cpu8051.active_priority = -1;
 
   // Reinitialisation des registres
   int i;
@@ -238,18 +243,18 @@ cpu8051_CheckInterrupts()
 
   if ( cpu8051_ReadD( _IE_ ) & 0x80 ) {
     for ( i = 1; i >= 0; i-- )
-      if ( ActivePriority < i ) {
+      if ( cpu8051.active_priority < i ) {
        //-------------------------  External interrupt 0 ----------------------------     
        //        if ( ( cpu8051_ReadD( _IE_ ) & 0x01 ) && ( ( cpu8051_ReadD( _IP_ ) & 0x01 ) ? i : !i ) && pin0 )
        //-------------------------- Interrupt timer 0 -------------------------------
        if ( ( cpu8051_ReadD( _IE_ ) & 0x02 ) && ( ( cpu8051_ReadD( _IP_ & 0x02 ) ? i : !i ) && ( cpu8051_ReadD( _TCON_ ) & 0x20 ) ) ){
          cpu8051_WriteD( _TCON_, cpu8051_ReadD( _TCON_ ) & 0xDF );
          SP = cpu8051_ReadD( _SP_ );
-         cpu8051_WriteI( ++SP, ( PC & 0xFF ) );
-         cpu8051_WriteI( ++SP, ( PC >> 8 ) );
+         cpu8051_WriteI( ++SP, ( cpu8051.pc & 0xFF ) );
+         cpu8051_WriteI( ++SP, ( cpu8051.pc >> 8 ) );
          cpu8051_WriteD( _SP_, SP );
-         PC = 0x0B;  
-         ActivePriority = i;
+         cpu8051.pc = 0x0B;  
+         cpu8051.active_priority = i;
          return;          
        }
        //-------------------------- External interrupt 1 ----------------------------     
@@ -258,31 +263,31 @@ cpu8051_CheckInterrupts()
        if ( ( cpu8051_ReadD( _IE_ ) & 0x08 ) && ( ( cpu8051_ReadD( _IP_ ) & 0x08 ) ? i : !i ) && ( cpu8051_ReadD( _TCON_ ) & 0x80 ) ) {
          cpu8051_WriteD( _TCON_, cpu8051_ReadD( _TCON_ ) & 0x7F );
          SP = cpu8051_ReadD( _SP_ );
-         cpu8051_WriteI( ++SP, ( PC & 0xFF ) );
-         cpu8051_WriteI( ++SP, ( PC >> 8 ) );
+         cpu8051_WriteI( ++SP, ( cpu8051.pc & 0xFF ) );
+         cpu8051_WriteI( ++SP, ( cpu8051.pc >> 8 ) );
          cpu8051_WriteD( _SP_, SP );
-         PC = 0x1B;
-         ActivePriority = i;
+         cpu8051.pc = 0x1B;
+         cpu8051.active_priority = i;
          return;
        }
        //-------------------------- Serial Interrupts -------------------------------
        if ( ( cpu8051_ReadD( _IE_ ) & 0x10 ) && ( ( cpu8051_ReadD( _IP_ ) & 0x10 ) ? i : !i ) && ( cpu8051_ReadD( _SCON_ ) & 0x03 ) ) {
          SP = cpu8051_ReadD( _SP_ );
-         cpu8051_WriteI( ++SP, ( PC & 0xFF ) );
-         cpu8051_WriteI( ++SP, ( PC >> 8 ) );
+         cpu8051_WriteI( ++SP, ( cpu8051.pc & 0xFF ) );
+         cpu8051_WriteI( ++SP, ( cpu8051.pc >> 8 ) );
          cpu8051_WriteD( _SP_, SP );
-         PC = 0x23;
-         ActivePriority = i;
+         cpu8051.pc = 0x23;
+         cpu8051.active_priority = i;
          return;
        }
        //-------------------------- Interrupt timer 2 -------------------------------
        if ( ( cpu8051_ReadD( _IE_ ) & 0x20 ) && ( ( cpu8051_ReadD( _IP_ ) & 0x20 ) ? i : !i ) && ( cpu8051_ReadD( _T2CON_ ) & 0x80 ) ) {          
          SP = cpu8051_ReadD( _SP_ );
-         cpu8051_WriteI( ++SP, ( PC & 0xFF ) );
-         cpu8051_WriteI( ++SP, ( PC >> 8 ) );
+         cpu8051_WriteI( ++SP, ( cpu8051.pc & 0xFF ) );
+         cpu8051_WriteI( ++SP, ( cpu8051.pc >> 8 ) );
          cpu8051_WriteD( _SP_, SP );
-         PC = 0x2B;
-         ActivePriority = i;
+         cpu8051.pc = 0x2B;
+         cpu8051.active_priority = i;
          return;
        }
       }
index da58ac5..942d64a 100644 (file)
@@ -5,6 +5,28 @@
 #define CPU8051_H 1
 
 
+typedef struct cpu8051_t
+{
+  unsigned int pc;
+  unsigned long clock;
+  int active_priority;
+} cpu8051_t;
+
+
+/* Exported variables */
+#undef _SCOPE_
+#ifdef CPU8051_M
+#  define _SCOPE_ /**/
+#else
+#  define _SCOPE_ extern
+#endif
+
+_SCOPE_ cpu8051_t cpu8051;
+
+
+void
+cpu8051_init( void );
+
 void
 cpu8051_Exec( void );
 
@@ -26,11 +48,9 @@ cpu8051_ReadD( unsigned int Address );
 unsigned char
 cpu8051_ReadInt( unsigned int Address );
 
-
 unsigned char
 cpu8051_ReadI( unsigned int Address );
 
-
 unsigned int
 cpu8051_GetNextAddress( void );
 
index 3e8d6fb..3d5cccd 100644 (file)
 #include "stop.xpm"
 #include "step.xpm"
 
+#include "common.h"
 #include "cpu8051.h"
 #include "options.h"
-#include "file.h"
+#include "hexfile.h"
+#include "filemenu.h"
+#include "viewmenu.h"
+#include "helpmenu.h"
 #include "regwin.h"
 #include "pgmwin.h"
 #include "memwin.h"
 
 
-int NbSignals = 0;
-int SignalsData[ 32 ];
+static int RunningState;
+static int RunFuncTag;
 
-enum {
-  DestroySignal=0,
-  DeleteSignal,
-  OpenISignal,
-  QuitISignal,
-  AboutISignal,
-  ResetBSignal,
-  RunBSignal,
-  StopBSignal,
-  StepBSignal
-};
 
+static GtkWidget *mainwin;
 
-/* private */
-int     EmuGtkID;
-int     RunningState;
-int     RunFuncTag;
 
-GtkWidget *emuwin, *emufixed, *emumainfixed;
-GtkWidget *regfrm, *pgmfrm, *memfrm;
-GtkWidget *ButtonTable;
+/* In options.c */
+extern char *hex_file;
 
-GtkWidget *FileMenu, *OpenItem, *QuitItem, *FileItem;
-GtkWidget *ViewMenu, *ExtMemItem, *IntMemItem, *ViewItem;
 
-GtkWidget *HelpMenu, *AboutItem, *LicenseItem, *HelpItem;
-GtkWidget *MenuBar;
+/* Signal DeleteEvent */
+/* If you return FALSE in the "delete_event" signal handler,
+ * GTK will emit the "destroy" signal. Returning TRUE means
+ * you don't want the window to be destroyed.
+ * This is useful for popping up 'are you sure you want to quit?'
+ * type dialogs.
+ */
+static gboolean
+WindowDeleteEvent( GtkWidget *widget, GdkEvent *event, gpointer data )
+{
+  g_print( "emugtk_DeleteEvent(...)\n" );
 
-// RESET button
-GdkBitmap *RESET_mask;
-GdkPixmap *RESET_pixmap;
-GtkWidget *RESET_widget;
-GtkWidget *ButtonReset;
+  emugtk_StopRunning( );
 
-// RUN button
-GdkBitmap *RUN_mask;
-GdkPixmap *RUN_pixmap;
-GtkWidget *RUN_widget;
-GtkWidget *ButtonRun;
+  return FALSE;
+}
 
-// STOP button
-GdkBitmap *STOP_mask;
-GdkPixmap *STOP_pixmap;
-GtkWidget *STOP_widget;
-GtkWidget *ButtonStop;
 
-// STEP button
-GdkBitmap *STEP_mask;
-GdkPixmap *STEP_pixmap;
-GtkWidget *STEP_widget;
-GtkWidget *ButtonStep;
+/* Signal DestroyEvent */
+static void
+WindowDestroyEvent( GtkWidget *widget, gpointer data )
+{
+  g_print( "emugtk_DestroyEvent(...)\n" );
 
+  gtk_main_quit();
+}
 
 
-#define EXIT_SUCCESS 0
+/* Taken from the Gxine source code. */
+static GtkWidget *
+AddPixButton( GtkWidget *box, gchar **pixmap_array )
+{
+  GtkWidget *button, *icon;
+  GdkPixmap *image;
+  GdkBitmap *transparent;
 
+  button = gtk_button_new();
+  gtk_button_set_relief (GTK_BUTTON(button), GTK_RELIEF_NORMAL );
+  image = gdk_pixmap_colormap_create_from_xpm_d(NULL, gdk_colormap_get_system(),
+                                               &transparent, NULL, pixmap_array);
+  icon = gtk_pixmap_new( image, transparent );
+  gtk_container_add( GTK_CONTAINER(button), icon );
 
-/* in cpu8051.c */
-extern unsigned int PC;
+  gtk_box_pack_start( GTK_BOX(box), button, FALSE, FALSE, 2 );
 
+  return button;
+}
 
-//////////////////////////////////////////////////////////////////////////////
-// EmuGtk constructor
-//////////////////////////////////////////////////////////////////////////////
-void
-emugtk_init( int argc, char **argv )
+
+/* Creates the Reset, Run, Stop and Step buttons. */
+static GtkWidget *
+AddButtons( void )
 {
-  RunningState = 0;
+  GtkWidget *button_hbox;
+  GtkWidget *button;
+
+  /* The buttons of the hbox are NOT given equal space in the box. */
+  button_hbox = gtk_hbox_new( FALSE, 5 );
+
+  /* Creating the RESET button. */
+  button = AddPixButton( button_hbox, reset_xpm );
+  gtk_signal_connect( GTK_OBJECT(button), "clicked",
+                     GTK_SIGNAL_FUNC(emugtk_ResetEvent),
+                     NULL );
+
+  /* Creating the RUN button. */
+  button = AddPixButton( button_hbox, run_xpm );
+  gtk_signal_connect( GTK_OBJECT(button), "clicked",
+                     GTK_SIGNAL_FUNC(emugtk_RunEvent),
+                     NULL );
+
+  /* Creating STOP button. */
+  button = AddPixButton( button_hbox, stop_xpm );
+  gtk_signal_connect( GTK_OBJECT(button), "clicked",
+                     GTK_SIGNAL_FUNC(emugtk_StopEvent),
+                     NULL );
+
+  /* Creating STEP button. */
+  button = AddPixButton( button_hbox, step_xpm );
+  gtk_signal_connect( GTK_OBJECT(button), "clicked",
+                     GTK_SIGNAL_FUNC(emugtk_StepEvent),
+                     NULL );
+
+  return button_hbox;
+}
 
-  g_print( "\n" );
 
-  gtk_init( &argc, &argv );
+GtkWidget *
+AddMenu( void )
+{
+  GtkWidget *menu_bar;
 
-  emuwin = gtk_window_new( GTK_WINDOW_TOPLEVEL );
-  gtk_window_set_title( GTK_WINDOW( emuwin ), "emu8051" );
-  gtk_container_set_border_width( GTK_CONTAINER( emuwin ), 0 );
-  gtk_widget_show( emuwin );
+  /* Creating menu item. */
+  menu_bar = gtk_menu_bar_new();
 
-  emufixed = gtk_fixed_new();
-  gtk_widget_set_usize( GTK_WIDGET( emufixed ), MAIN_WIN_WIDTH, MAIN_WIN_HEIGHT );
-  gtk_container_add( GTK_CONTAINER( emuwin ), emufixed );
-  gtk_widget_show( emufixed );
+  /* Adding the 'File' submenu */
+  FileAddMenu( menu_bar );
 
-  //  EmuMenuBar( );
+  /* Adding the 'View' submenu */
+  ViewAddMenu( menu_bar );
+  
+  /* Adding the 'Help' submenu */
+  HelpAddMenu( menu_bar );
 
-  // Main window
-  emumainfixed = gtk_fixed_new();
-  gtk_widget_set_usize( GTK_WIDGET( emumainfixed ), MAIN_WIN_WIDTH, REG_WIN_HEIGHT + MEM_WIN_HEIGHT + BUTTONS_BAR_HEIGHT + 10 );
-  gtk_fixed_put( GTK_FIXED( emufixed ), emumainfixed, 0, 25 );
-  gtk_widget_show( emumainfixed );
+  gtk_widget_show_all( GTK_WIDGET( menu_bar ) );
+  
+  return menu_bar;
+}
 
-  emugtk_ShowMenu();
 
-  emugtk_AddButtons();
+static void
+emugtk_window_init( void )
+{
+  GtkWidget *main_vbox;
+  GtkWidget *menu_bar;
+  GtkWidget *buttons_bar;
+  GtkWidget *emufixed;
+  GtkWidget *fixed_frame;
+
+  mainwin = gtk_window_new( GTK_WINDOW_TOPLEVEL );
+  gtk_window_set_title( GTK_WINDOW(mainwin), PACKAGE );
+  gtk_widget_set_usize( GTK_WIDGET(mainwin), MAIN_WIN_WIDTH, MAIN_WIN_HEIGHT );
+  gtk_container_set_border_width( GTK_CONTAINER(mainwin), 0 );
+
+  /* Window DESTROY event. */
+  gtk_signal_connect( GTK_OBJECT(mainwin), "destroy", GTK_SIGNAL_FUNC(WindowDestroyEvent),
+                     NULL );
+
+  /* Window DELETE event. */
+  gtk_signal_connect( GTK_OBJECT(mainwin), "delete_event", GTK_SIGNAL_FUNC(WindowDeleteEvent),
+                     NULL );
+
+  /* Setting main window geometry based on command line options (if specified). */
+  /*MainWindowSetGeometry();*/
   
-  // Registers frame
-  regfrm = gtk_frame_new( 0 );
-  gtk_frame_set_shadow_type( GTK_FRAME( regfrm ), GTK_SHADOW_ETCHED_OUT );
-  gtk_widget_set_usize( GTK_WIDGET( regfrm ), REG_WIN_WIDTH, REG_WIN_HEIGHT );
-  gtk_fixed_put( GTK_FIXED( emumainfixed ), regfrm, 0, BUTTONS_BAR_HEIGHT );
-  regwin_init( regfrm );
-  gtk_widget_show( regfrm );
-
-  // Program disassembly frame
-  pgmfrm = gtk_frame_new( 0 );
-  gtk_frame_set_shadow_type( GTK_FRAME( pgmfrm ), GTK_SHADOW_ETCHED_OUT );
-  gtk_widget_set_usize( GTK_WIDGET( pgmfrm ), PGM_WIN_WIDTH, PGM_WIN_HEIGHT );
-  gtk_fixed_put( GTK_FIXED( emumainfixed ), pgmfrm, REG_WIN_WIDTH + 10, BUTTONS_BAR_HEIGHT );
-
-  pgmwin_init( pgmfrm );
-
-  gtk_widget_show( pgmfrm );
-
-  // Memory dump frame
-  memfrm = gtk_frame_new( 0 );
-  gtk_frame_set_shadow_type( GTK_FRAME( memfrm ), GTK_SHADOW_ETCHED_OUT );
-  gtk_widget_set_usize( GTK_WIDGET( memfrm ), MEM_WIN_WIDTH, MEM_WIN_HEIGHT );
-  gtk_fixed_put( GTK_FIXED( emumainfixed ), memfrm, 0, REG_WIN_HEIGHT + BUTTONS_BAR_HEIGHT );
-  memwin_init( memfrm );
-  gtk_widget_show( memfrm );
-
+  /* main_vbox contains the menu bar and body_vbox (for all remaining items). */
+  main_vbox = gtk_vbox_new( FALSE, 1 );
   
-  NbSignals = 0;
-
-  // Window DESTROY signal
-  SignalsData[ NbSignals ] = DestroySignal;
-  gtk_signal_connect( GTK_OBJECT( emuwin ), "destroy", GTK_SIGNAL_FUNC( EmuGtkSignalStub2 ), &SignalsData[ NbSignals ] );
-  NbSignals++;
-      
-  // Window DELETE event
-  SignalsData[ NbSignals ] = DeleteSignal;
-  gtk_signal_connect( GTK_OBJECT( emuwin ), "delete_event", GTK_SIGNAL_FUNC( EmuGtkSignalStub3 ), &SignalsData[ NbSignals ] );
-  NbSignals++;
-
-  // File->Open
-  SignalsData[ NbSignals ] = OpenISignal;
-  gtk_signal_connect( GTK_OBJECT( OpenItem ), "activate", GTK_SIGNAL_FUNC( EmuGtkSignalStub2 ), &SignalsData[ NbSignals ] );
-  NbSignals++;
-
-  // File->Quit
-  SignalsData[ NbSignals ] = QuitISignal;
-  gtk_signal_connect( GTK_OBJECT( QuitItem ), "activate", GTK_SIGNAL_FUNC( EmuGtkSignalStub2 ), &SignalsData[ NbSignals ] );
-  NbSignals++;
-
-  // Help->About
-  SignalsData[ NbSignals ] = AboutISignal;
-  gtk_signal_connect( GTK_OBJECT( AboutItem ), "activate", GTK_SIGNAL_FUNC( EmuGtkSignalStub2 ), &SignalsData[ NbSignals ] );
-  NbSignals++;
-
-  // RESET button
-  SignalsData[ NbSignals ] = ResetBSignal;
-  gtk_signal_connect( GTK_OBJECT( ButtonReset ), "button-press-event", GTK_SIGNAL_FUNC( EmuGtkSignalStub3 ), &SignalsData[ NbSignals ] );
-  NbSignals++;
-      
-  // RUN button
-  SignalsData[ NbSignals ] = RunBSignal;
-  gtk_signal_connect( GTK_OBJECT( ButtonRun ), "button-press-event", GTK_SIGNAL_FUNC( EmuGtkSignalStub3 ), &SignalsData[ NbSignals ] );
-  NbSignals++;
-
-  // STOP button
-  SignalsData[ NbSignals ] = StopBSignal;
-  gtk_signal_connect( GTK_OBJECT( ButtonStop ), "button-press-event", GTK_SIGNAL_FUNC( EmuGtkSignalStub3 ), &SignalsData[ NbSignals ] );
-  NbSignals++;      
-
-  // STEP button
-  SignalsData[ NbSignals ] = StepBSignal;
-  gtk_signal_connect( GTK_OBJECT( ButtonStep ), "button-press-event", GTK_SIGNAL_FUNC( EmuGtkSignalStub3 ), &SignalsData[ NbSignals ] );
-  NbSignals++;
-      
-
-  if( GetHexFileName() != NULL ) {
-    LoadHexFile( GetHexFileName() );
-  }
+  /* Creating the menu bar. */
+  menu_bar = AddMenu();
+  /* Adding menu bar to main_vbox */
+  gtk_box_pack_start( GTK_BOX(main_vbox), menu_bar, FALSE, FALSE, 1 );
+
+  /* Creating the buttons bar. */
+  buttons_bar = AddButtons();
+  /* Adding buttons bar to main_vbox */
+  gtk_box_pack_start( GTK_BOX(main_vbox), buttons_bar, FALSE, FALSE, 1 );
+
+  /* Emulator fixed window. */
+  emufixed = gtk_fixed_new();
+  gtk_widget_set_usize( GTK_WIDGET( emufixed ), MAIN_WIN_WIDTH,
+                       REG_WIN_HEIGHT + MEM_WIN_HEIGHT + 10 );
+
+  /* 8051 registers frame. */
+  fixed_frame = regwin_init( REG_WIN_WIDTH, REG_WIN_HEIGHT );
+  gtk_fixed_put( GTK_FIXED( emufixed ), fixed_frame, 0, 0 );
+
+  /* Program disassembly frame. */
+  fixed_frame = pgmwin_init( PGM_WIN_WIDTH, PGM_WIN_HEIGHT );
+  gtk_fixed_put( GTK_FIXED( emufixed ), fixed_frame, REG_WIN_WIDTH + 10, 0 );
+
+  /* Memory dump frame. */
+  fixed_frame = memwin_init( MEM_WIN_WIDTH, MEM_WIN_HEIGHT );
+  gtk_fixed_put( GTK_FIXED( emufixed ), fixed_frame, 0, REG_WIN_HEIGHT );
+
+  /* Adding fixed window to main_vbox */
+  gtk_box_pack_start( GTK_BOX(main_vbox), emufixed, FALSE, FALSE, 1 );
+
+  /* Adding the main_vbox to the main window. */
+  gtk_container_add( GTK_CONTAINER(mainwin), main_vbox );
+
+  gtk_widget_show_all( mainwin );
 }
 
 
@@ -203,292 +214,97 @@ main( int argc, char **argv )
 {
   ParseCommandLineOptions( argc, argv );
 
-  emugtk_init( argc, argv );
-
-  emugtk_Reset( );
-  gtk_main();
+  cpu8051_init();
 
-  printf( "End of program.\n" );
+  RunningState = 0;
   
-  return EXIT_SUCCESS;
-}
+  gtk_init( &argc, &argv );
 
+  emugtk_window_init();
 
-//////////////////////////////////////////////////////////////////////////////
-// Create and show the Reset, Run, Stop, Trace and Step buttons
-//////////////////////////////////////////////////////////////////////////////
-void
-emugtk_AddButtons( void )
-{
-  RESET_pixmap = gdk_pixmap_colormap_create_from_xpm_d( NULL,
-                                                       gtk_widget_get_default_colormap(),
-                                                       &RESET_mask,
-                                                       NULL,
-                                                       ( gchar ** ) reset_xpm );
-  RESET_widget = gtk_pixmap_new( RESET_pixmap, RESET_mask );
-  
-  RUN_pixmap = gdk_pixmap_colormap_create_from_xpm_d( NULL,
-                                                     gtk_widget_get_default_colormap(),
-                                                     &RUN_mask,
-                                                     NULL,
-                                                     ( gchar ** ) run_xpm );
-  RUN_widget = gtk_pixmap_new( RUN_pixmap, RUN_mask );
-  
-  STOP_pixmap = gdk_pixmap_colormap_create_from_xpm_d( NULL,
-                                                      gtk_widget_get_default_colormap(),
-                                                      &STOP_mask,
-                                                      NULL,
-                                                      ( gchar ** ) stop_xpm );
-  STOP_widget = gtk_pixmap_new( STOP_pixmap, STOP_mask );
-  
-  STEP_pixmap = gdk_pixmap_colormap_create_from_xpm_d( NULL,
-                                                      gtk_widget_get_default_colormap(),
-                                                      &STEP_mask,
-                                                      NULL,
-                                                      ( gchar ** ) step_xpm );
-  STEP_widget = gtk_pixmap_new( STEP_pixmap, STEP_mask );
-  
-  ButtonTable = gtk_table_new( 1, 4, TRUE );
-  gtk_widget_set_usize( GTK_WIDGET( ButtonTable ), BUTTONS_BAR_WIDTH, BUTTONS_BAR_HEIGHT );
-  gtk_fixed_put( GTK_FIXED( emumainfixed ), ButtonTable, 0, 0 );
-  
-  ButtonReset = gtk_button_new();
-  ButtonRun   = gtk_button_new();
-  ButtonStop  = gtk_button_new();
-  ButtonStep  = gtk_button_new();
-
-  gtk_container_add( GTK_CONTAINER( ButtonReset ), RESET_widget );
-  gtk_container_add( GTK_CONTAINER( ButtonRun ), RUN_widget );
-  gtk_container_add( GTK_CONTAINER( ButtonStop ), STOP_widget );
-  gtk_container_add( GTK_CONTAINER( ButtonStep ), STEP_widget );
-
-  gtk_widget_set_usize( GTK_WIDGET( ButtonReset ), BUTTON_WIDTH, BUTTON_HEIGHT );
-  gtk_widget_set_usize( GTK_WIDGET( ButtonRun ),   BUTTON_WIDTH, BUTTON_HEIGHT );
-  gtk_widget_set_usize( GTK_WIDGET( ButtonStop ),  BUTTON_WIDTH, BUTTON_HEIGHT );
-  gtk_widget_set_usize( GTK_WIDGET( ButtonStep ),  BUTTON_WIDTH, BUTTON_HEIGHT );
-
-  gtk_table_attach_defaults( GTK_TABLE( ButtonTable ), ButtonReset, 0, 1, 0, 1);
-  gtk_table_attach_defaults( GTK_TABLE( ButtonTable ), ButtonRun,   1, 2, 0, 1);
-  gtk_table_attach_defaults( GTK_TABLE( ButtonTable ), ButtonStop,  2, 3, 0, 1);
-  gtk_table_attach_defaults( GTK_TABLE( ButtonTable ), ButtonStep,  3, 4, 0, 1);
-
-  gtk_widget_show( GTK_WIDGET( ButtonReset ) );
-  gtk_widget_show( GTK_WIDGET( ButtonRun ) );
-  gtk_widget_show( GTK_WIDGET( ButtonStop ) );  
-  gtk_widget_show( GTK_WIDGET( ButtonStep ) );  
-
-  gtk_widget_show_all( GTK_WIDGET( ButtonTable ) );
-}
+  if( hex_file != NULL ) {
+    emugtk_new_file( hex_file );
+  }
 
+  /*emugtk_Reset();*/
 
-//////////////////////////////////////////////////////////////////////////////
-// CPU reset and Gtk UI update
-//////////////////////////////////////////////////////////////////////////////
-void
-emugtk_Reset( void )
-{
-  cpu8051_Reset( );
-  regwin_Show();
-  pgmwin_Disasm();
-  memwin_DumpD( 0 );
-}
-
+  gtk_main();
 
-//////////////////////////////////////////////////////////////////////////////
-// CPU Step and Gtk UI update
-//////////////////////////////////////////////////////////////////////////////
-void
-emugtk_Step( void )
-{
-  cpu8051_Exec();
-  regwin_Show();
-  pgmwin_Disasm();
-  memwin_DumpD( 0 );
+  printf( "End of program.\n" );
+  
+  return EXIT_SUCCESS;
 }
 
 
-
-//////////////////////////////////////////////////////////////////////////////
-// Show the menu
-//////////////////////////////////////////////////////////////////////////////
 void
-emugtk_ShowMenu( void )
+emugtk_new_file( char *file )
 {
-  FileMenu = gtk_menu_new( );
-  OpenItem = gtk_menu_item_new_with_label( "Open" );
-  QuitItem = gtk_menu_item_new_with_label( "Quit" );
-  gtk_menu_append( GTK_MENU( FileMenu ), GTK_WIDGET( OpenItem ) );
-  gtk_menu_append( GTK_MENU( FileMenu ), GTK_WIDGET( QuitItem ) );
-  gtk_widget_show( GTK_WIDGET( OpenItem ) );
-  gtk_widget_show( GTK_WIDGET( QuitItem ) );
-  
-  ViewMenu = gtk_menu_new( );
-  ExtMemItem = gtk_menu_item_new_with_label( "External Memory Dump" );
-  IntMemItem = gtk_menu_item_new_with_label( "Internal Memory Dump" );
-  //PgmMemItem = gtk_menu_item_new_with_label( "Program Memory Dump" );
-  gtk_menu_append( GTK_MENU( ViewMenu ), GTK_WIDGET( ExtMemItem ) );
-  gtk_menu_append( GTK_MENU( ViewMenu ), GTK_WIDGET( IntMemItem ) );
-  //gtk_menu_append( GTK_MENU( ViewMenu ), GTK_WIDGET( PgmMemItem ) );
-  gtk_widget_show( GTK_WIDGET( ExtMemItem ) );
-  gtk_widget_show( GTK_WIDGET( IntMemItem ) );
-  //gtk_widget_show( GTK_WIDGET( PgmMemItem ) );
-  
-  HelpMenu = gtk_menu_new( );
-  AboutItem = gtk_menu_item_new_with_label( "About" );
-  gtk_menu_append( GTK_MENU( HelpMenu ), GTK_WIDGET( AboutItem ) );
-  gtk_widget_show( GTK_WIDGET( AboutItem ) );
+  emugtk_StopRunning();
   
-  MenuBar = gtk_menu_bar_new( );
-  gtk_fixed_put( GTK_FIXED( emufixed ), MenuBar, 0, 0 );
-  gtk_widget_show( GTK_WIDGET( MenuBar ) );
+  LoadHexFile( file );
   
-  FileItem = gtk_menu_item_new_with_label( "File" );
-  ViewItem = gtk_menu_item_new_with_label( "View" );
-  HelpItem = gtk_menu_item_new_with_label( "Help" );
-  gtk_widget_show( GTK_WIDGET( FileItem ) );
-  gtk_widget_show( GTK_WIDGET( ViewItem ) );
-  gtk_widget_show( GTK_WIDGET( HelpItem ) );
-  gtk_menu_item_set_submenu( GTK_MENU_ITEM( FileItem ), FileMenu );
-  gtk_menu_item_set_submenu( GTK_MENU_ITEM( ViewItem ), ViewMenu );
-  gtk_menu_item_set_submenu( GTK_MENU_ITEM( HelpItem ), HelpMenu );
-  gtk_menu_bar_append( GTK_MENU_BAR( MenuBar ), FileItem );
-  gtk_menu_bar_append( GTK_MENU_BAR( MenuBar ), ViewItem );
-  gtk_menu_bar_append( GTK_MENU_BAR( MenuBar ), HelpItem );
+  emugtk_Reset();
+  emugtk_UpdateDisplay();
 }
 
 
-//////////////////////////////////////////////////////////////////////////////
-// Signal DeleteEvent
-//////////////////////////////////////////////////////////////////////////////
-gboolean
-emugtk_DeleteEvent( GtkWidget *widget, GdkEvent *event, gpointer data )
-{
-  g_print( "emugtk_DeleteEvent(...)\n" );
-  emugtk_StopRunning( );
-  return FALSE;
-}
 
 
-//////////////////////////////////////////////////////////////////////////////
-// Signal DestroyEvent
-//////////////////////////////////////////////////////////////////////////////
 void
-emugtk_DestroyEvent( GtkWidget *widget, gpointer data )
+AddMenuSeparator( GtkWidget *menu )
 {
-  g_print( "emugtk_DestroyEvent(...)\n" );
-  gtk_main_quit();
-}
-
-
-//////////////////////////////////////////////////////////////////////////////
-// gint emugtk_AboutEvent( GtkWidget *widget, gpointer data )
-// Signal AboutEvent ( Help->About in menu )
-//////////////////////////////////////////////////////////////////////////////
-void
-emugtk_AboutEvent( GtkWidget *widget, gpointer data )
-{
-  char about_string[256];
-  GtkWidget *about_window;
-  GtkWidget *text_window;
-
-  sprintf( about_string,
-          "%s\n\nversion %s\n\n\nAuthors:\nHugo Villeneuve\nJonathan St-André\n",
-          PACKAGE, VERSION );
+  GtkWidget *item;
   
-  about_window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
-  gtk_window_set_title( GTK_WINDOW( about_window ), "About" );
-  gtk_container_set_border_width( GTK_CONTAINER( about_window ), 20 );
-  
-  text_window = gtk_label_new( about_string );
-  gtk_container_add( GTK_CONTAINER( about_window ), text_window );
-  
-  gtk_widget_show_all( GTK_WIDGET( about_window ) );
+  item = gtk_menu_item_new();
+  gtk_menu_append( GTK_MENU(menu), item );
 }
 
 
-//////////////////////////////////////////////////////////////////////////////
-// Signal OpenEvent ( File->Open in menu )
-//////////////////////////////////////////////////////////////////////////////
 void
-emugtk_OpenEvent( GtkWidget *widget, gpointer data )
+emugtk_UpdateDisplay( void )
 {
-  GtkWidget *FileOpendialog;
+  g_print( "emugtk_UpdateDisplay()\n" );
 
-  // g_print( "emugtk_OpenEvent(...)\n" );
+  regwin_Show();
+  pgmwin_Disasm();
+  memwin_DumpD( 0 );
+}
 
-  FileOpendialog = gtk_file_selection_new( "Open Intel Hex file" );
 
-  // Connect the file dialog's OK button up to a handler.
-  gtk_signal_connect( GTK_OBJECT( GTK_FILE_SELECTION ( FileOpendialog ) -> ok_button ),
-                     "clicked",
-                     GTK_SIGNAL_FUNC( FileOpenDialog_OK ),
-                     FileOpendialog );
 
-  // Connect the file dialog's CANCEL button up to a handler.
-  gtk_signal_connect( GTK_OBJECT( GTK_FILE_SELECTION ( FileOpendialog ) -> cancel_button ),
-                     "clicked",
-                     GTK_SIGNAL_FUNC( FileOpenDialog_CANCEL ),
-                     FileOpendialog );
 
-  // Set the 'File Open dialog' to show only Intel HEX files (.hex).
-  // gtk_file_selection_complete( GTK_FILE_SELECTION( FileOpendialog ), "*.hex" );
-  
-  // Show the dialog
-  gtk_widget_show( GTK_WIDGET( FileOpendialog ) );
-}
 
 
-void
-FileOpenDialog_OK( GtkButton *button, gpointer data )
-{
-  g_print( "emugtk_FileOpenDialog_OK Event(...)\n" );
 
-  const gchar *SelectedFile;
 
-  SelectedFile = (const gchar *) gtk_file_selection_get_filename( GTK_FILE_SELECTION( data ) );
-  
-  g_print( "emugtk_File = %s\n", SelectedFile );
-  
-  emugtk_StopRunning();
 
-  LoadHexFile( SelectedFile );
 
-  gtk_widget_destroy( GTK_WIDGET( data ) );
 
-  emugtk_Reset();
-  emugtk_UpdateDisplay();
-}
 
 
+//////////////////////////////////////////////////////////////////////////////
+// CPU reset and Gtk UI update
+//////////////////////////////////////////////////////////////////////////////
 void
-emugtk_UpdateDisplay( void )
+emugtk_Reset( void )
 {
-  g_print( "emugtk_UpdateDisplay()\n" );
-
+  cpu8051_Reset( );
   regwin_Show();
   pgmwin_Disasm();
   memwin_DumpD( 0 );
 }
 
 
-void
-FileOpenDialog_CANCEL( GtkButton *button, gpointer data )
-{
-  g_print( "emugtk_FileOpenDialog_CANCEL Event(...)\n" );
-  
-  gtk_widget_destroy( GTK_WIDGET( data ) );
-}
-
-
 //////////////////////////////////////////////////////////////////////////////
-// Signal QuitEvent ( File->Quit in menu )
+// CPU Step and Gtk UI update
 //////////////////////////////////////////////////////////////////////////////
 void
-emugtk_QuitEvent( GtkWidget *widget, gpointer data )
+emugtk_Step( void )
 {
-  g_print( "emugtk_QuitEvent(...)\n" );
-  emugtk_StopRunning( );
-  gtk_main_quit( );
+  cpu8051_Exec();
+  regwin_Show();
+  pgmwin_Disasm();
+  memwin_DumpD( 0 );
 }
 
 
@@ -545,68 +361,6 @@ emugtk_StepEvent( GtkWidget *widget, GdkEvent *event, gpointer data )
 }
 
 
-//////////////////////////////////////////////////////////////////////////////
-// Signal Stub with 2 parameters
-//////////////////////////////////////////////////////////////////////////////
-void
-EmuGtkSignalStub2( GtkWidget *widget, gpointer data )
-{
-  g_print( "EmuGtkSignalStub2(...)\n");
-
-  int SigNumber = *( (int *) data );
-
-  switch( SigNumber ) {
-  case DestroySignal:
-    emugtk_DestroyEvent( widget, 0 );
-    break;
-  case AboutISignal:
-    emugtk_AboutEvent( widget, 0 );
-    break;
-  case OpenISignal:
-    emugtk_OpenEvent( widget, 0 );
-    break;
-  case QuitISignal:
-    emugtk_QuitEvent( widget, 0 );
-    break;
-  default:
-    g_print( "*** error: EmuGtkSignalStub2: default case reached\n" );
-    break;
-  };
-}
-
-
-//////////////////////////////////////////////////////////////////////////////
-// Signal Stub with 3 parameters
-//////////////////////////////////////////////////////////////////////////////
-void EmuGtkSignalStub3( GtkWidget *widget, GdkEvent *event, gpointer data )
-{
-  g_print( "EmuGtkSignalStub3(...)\n");
-
-  int SigNumber = *( (int *) data );
-  
-  switch( SigNumber ) {
-  case DeleteSignal:
-    emugtk_DeleteEvent( widget, event, 0 );
-    break;
-  case ResetBSignal:
-    emugtk_ResetEvent( widget, event, 0 );
-    break;
-  case RunBSignal:
-    emugtk_RunEvent( widget, event, 0 );
-    break;
-  case StopBSignal:
-    emugtk_StopEvent( widget, event, 0 );
-    break;
-  case StepBSignal:
-    emugtk_StepEvent( widget, event, 0 );
-    break;
-  default:
-    g_print( "*** error: EmuGtkSignalStub3: default case reached\n" );
-    break;
-  };
-}
-
-
 //////////////////////////////////////////////////////////////////////////////
 // Running called by RunningFunction( )
 //////////////////////////////////////////////////////////////////////////////
@@ -614,7 +368,7 @@ void
 emugtk_Running( )
 {
   cpu8051_Exec( );
-  if( pgmwin_IsBreakpoint( PC ) ) {
+  if( pgmwin_IsBreakpoint( cpu8051.pc ) ) {
     g_print( "Breakpoint Hit, stopping!\n" );
     emugtk_StopRunning( );
   }
index fc5bda2..7a4ddbd 100644 (file)
@@ -7,23 +7,34 @@
 
 #include <gtk/gtk.h>
 #include "gtksizes.h"
-/*#include "exceptions.hpp"*/
 
 
-void emugtk_Reset( );
+
+
+void
+AddMenuSeparator( GtkWidget *menu );
+
+void
+emugtk_new_file( char *file );
+
+
+
+void
+emugtk_StopRunning( void );
+
+void
+emugtk_Reset( void );
+
+void
+emugtk_UpdateDisplay( void );
+
+
+
+
 void emugtk_Step( );
-//  void Step( );
-//  void Exec( );
 
-void emugtk_AddButtons( );
-void emugtk_ShowMenu( );
 
-gboolean emugtk_DeleteEvent( GtkWidget *widget, GdkEvent *event, gpointer data );
-void emugtk_DestroyEvent( GtkWidget *widget, gpointer data );
 
-void emugtk_OpenEvent( GtkWidget *widget, gpointer data );
-void emugtk_QuitEvent( GtkWidget *widget, gpointer data );
-void emugtk_AboutEvent( GtkWidget *widget, gpointer data );
 
 void emugtk_ResetEvent( GtkWidget *widget, GdkEvent *event, gpointer data );
 void emugtk_RunEvent( GtkWidget *widget, GdkEvent *event, gpointer data );
@@ -31,22 +42,11 @@ void emugtk_StopEvent( GtkWidget *widget, GdkEvent *event, gpointer data );
 void emugtk_StepEvent( GtkWidget *widget, GdkEvent *event, gpointer data );
 
 void emugtk_StartRunning( );
-void emugtk_StopRunning( );
-void emugtk_Running( );
-
-void emugtk_UpdateDisplay();
-
-
-
-
 
+void emugtk_Running( );
 
 
 
-void EmuGtkSignalStub3( GtkWidget *widget, GdkEvent *event, gpointer data );
-void EmuGtkSignalStub2( GtkWidget *widget, gpointer data );
-void FileOpenDialog_OK( GtkButton *button, gpointer data );
-void FileOpenDialog_CANCEL( GtkButton *button, gpointer data );
 
 
 #endif /* EMUGTK_H */
diff --git a/src/file.c b/src/file.c
deleted file mode 100644 (file)
index 51ad33e..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/* file.c -- functions for loading an Intel HEX file
-   Copyright (C) 2004 Hugo Villeneuve */
-
-
-#if HAVE_CONFIG_H
-#  include "config.h"
-#endif
-
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#if STDC_HEADERS
-#  include <string.h>
-#elif HAVE_STRINGS_H
-#  include <strings.h>
-#endif
-
-#include "common.h"
-#include "memory.h"
-
-
-/* Convert an ascii string to an hexadecimal number. */
-static unsigned int
-Ascii2Hex( char *istring, int length )
-{
-  unsigned int result = 0;
-  int i, ascii_code;
-
-  if ( !length || ( length > (int) strlen(istring) ) ) {
-    length = strlen(istring);
-  }
-  
-  for ( i = 0; i < length; i++ ) {
-    ascii_code = istring[ i ];
-    if ( ascii_code > 0x39 ) {
-      ascii_code &= 0xDF;
-    }
-    if ( ( ascii_code >= 0x30 && ascii_code <= 0x39 ) ||
-        ( ascii_code >= 0x41 && ascii_code <= 0x46 ) ) {
-      ascii_code -= 0x30;
-      if ( ascii_code > 9 ) {
-       ascii_code -= 7;
-      }
-      result <<= 4;
-      result += ascii_code;
-    }
-    else {
-      printf( "%s: In Ascii2Hex(), syntax error.\n", PACKAGE );
-    }
-  }
-  return result;
-}
-
-
-void
-LoadHexFile( const char *filename )
-{
-  int i, j, RecLength, LoadOffset, RecType, Data, Checksum;
-  
-#define LINE_BUFFER_LEN 256
-  FILE *fp;
-  int status;
-  char line[LINE_BUFFER_LEN];
-
-  if( filename != NULL ) {
-    /* Trying to open the file. */
-    fp = fopen( filename, "r" );
-    if( fp == NULL ) {
-      perror( PACKAGE );
-      /*ErrorLocation( __FILE__, __LINE__ );*/
-      exit( EXIT_FAILURE );
-    }
-  }
-  
-  /* Reading one line of data from the configuration file. */
-  /* char *fgets(char *s, int size, FILE *stream);
-     Reading stops after an EOF or a newline.  If a newline is read, it is
-     stored into the buffer.  A '\0'  is  stored after the last character in
-     the buffer. */
-  while( fgets( line, LINE_BUFFER_LEN, fp ) != NULL ) {
-    i = 0;
-    Checksum = 0;
-
-    if ( line[ i++ ] != ':' ) {
-      printf( "%s: line not beginning with \":\"\n", PACKAGE );
-      goto close_file;
-    }
-      
-    RecLength = Ascii2Hex( &line[ i ], 2 );
-    i += 2;
-    Checksum += RecLength;
-      
-    LoadOffset = Ascii2Hex( &line[i], 4 );
-    Checksum += LoadOffset / 256;
-    Checksum += LoadOffset % 256;
-    i += 4;
-    
-    RecType = Ascii2Hex( &line[i],2);
-    i += 2;
-    Checksum += RecType;
-    
-    if ( RecType == 1 ) {
-      Checksum += Ascii2Hex( &line[ i ], 2 );
-      if ( Checksum &= 0x000000FF ) {
-       /* Error. */
-       printf( "%s: Invalid format\n", PACKAGE );
-       goto close_file;
-      }
-      else {
-       /* OK */
-       goto close_file;
-      }
-    }   
-    
-    for ( j = 0; j < RecLength; j++ ) {
-      Data = Ascii2Hex( &line[ i ], 2 );
-      memory_write8( PGM_MEM_ID, (unsigned int)(LoadOffset + j), (unsigned char)Data );
-      i += 2;
-      Checksum += Data;
-    }
-    
-    RecType = Ascii2Hex( &line[ i ], 2 );
-    Checksum += RecType;      
-    
-    if ( Checksum &= 0x000000FF ) {
-      printf( "%s: Invalid format\n", PACKAGE );
-      goto close_file;
-    }
-  }
-  
- close_file:
-  status = fclose( fp );
-  if( status != EXIT_SUCCESS ) {
-    fprintf( stderr, "%s: Error closing configuration file.\n", PACKAGE );
-    /*ErrorLocation( __FILE__, __LINE__ );*/
-    exit( EXIT_FAILURE );
-  }
-}
diff --git a/src/file.h b/src/file.h
deleted file mode 100644 (file)
index 10d7d92..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-/* file.h */
-
-
-#ifndef FILE_H
-#define FILE_H 1
-
-
-void
-LoadHexFile( const char *filename );
-
-
-#endif /* FILE_H */
diff --git a/src/filemenu.c b/src/filemenu.c
new file mode 100644 (file)
index 0000000..c96d35c
--- /dev/null
@@ -0,0 +1,114 @@
+/* file.c */
+
+
+#if HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <unistd.h>  /* UNIX standard function definitions */
+#include <pwd.h>
+#include <gtk/gtk.h>
+
+#include "common.h"
+#include "emugtk.h"
+#include "messagebox.h"
+#include "filemenu.h"
+
+
+#define FILENAME_DESCRIPTION "Open Intel Hex file"
+
+
+static void
+FileOpenDialog_OK( GtkWidget *widget, gpointer file_dialog )
+{
+  char *selected_file;
+
+#if defined(DEBUG)
+  g_print( "FileOpenDialog_OK()\n" );
+#endif
+  
+  /* The cast to (char *) is to remove a warning in GTK2, because the return value of the
+     gtk_file_selection_get_filename() function is 'G_CONST_RETURN gchar *'. */
+  selected_file =
+    (char *) gtk_file_selection_get_filename( GTK_FILE_SELECTION(file_dialog) );
+
+  g_print( "emugtk_File = %s\n", selected_file );
+
+  emugtk_new_file( selected_file );
+
+  gtk_widget_destroy( GTK_WIDGET(file_dialog) );
+}
+
+
+void
+FileOpenEvent( GtkObject *object, gpointer data )
+{
+  GtkWidget *file_dialog;
+
+#if defined(DEBUG)
+  g_print( "FileOpenEvent()\n" );
+#endif
+
+  /* Create a new file selection widget. */
+  file_dialog = gtk_file_selection_new( FILENAME_DESCRIPTION );
+  
+  /* Connect the file dialog's OK button up to a handler. */
+  gtk_signal_connect( GTK_OBJECT( GTK_FILE_SELECTION(file_dialog)->ok_button ), "clicked",
+                     GTK_SIGNAL_FUNC(FileOpenDialog_OK), file_dialog );
+
+  /* Ensure that the file selection dialog box is destroyed when the user clicks CANCEL. */
+  gtk_signal_connect_object( GTK_OBJECT( GTK_FILE_SELECTION(file_dialog)->cancel_button),
+                            "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy),
+                            (gpointer) file_dialog );
+
+  /* Set the 'File Open dialog' to show only Intel HEX files (.hex). */
+  /* gtk_file_selection_complete( GTK_FILE_SELECTION( FileOpendialog ), "*.hex" ); */
+
+  /* Show the dialog. */
+  gtk_widget_show( GTK_WIDGET(file_dialog) );
+  
+  /* To have the main window of our application being unusable while using the dialog. */
+  gtk_window_set_modal( GTK_WINDOW(file_dialog), TRUE );
+}
+
+
+static void
+FileQuitEvent( gchar *string )
+{
+#if defined(DEBUG)
+  g_print( "%s\n", string );
+#endif
+
+  emugtk_StopRunning();
+  gtk_main_quit();
+}
+
+
+void
+FileAddMenu( GtkWidget *menu_bar )
+{
+  GtkWidget *item;
+  GtkWidget *menu;
+  
+  menu = gtk_menu_new();
+  
+  /* Create the 'open' item. */
+  item = gtk_menu_item_new_with_label( FILENAME_DESCRIPTION );
+  gtk_menu_append( GTK_MENU(menu), item );
+  /* Attach the callback functions to the activate signal. */
+  gtk_signal_connect_object( GTK_OBJECT(item), "activate", GTK_SIGNAL_FUNC(FileOpenEvent),
+                            NULL );
+
+  AddMenuSeparator(menu);
+
+  item = gtk_menu_item_new_with_label("Exit");
+  gtk_menu_append( GTK_MENU(menu), item );
+  /* We can attach the Quit menu item to our exit function */
+  gtk_signal_connect_object( GTK_OBJECT(item), "activate", GTK_SIGNAL_FUNC(FileQuitEvent),
+                            (gpointer) "file.quit" );
+  
+  /* Adding submenu title. */
+  item = gtk_menu_item_new_with_label( "File" );
+  gtk_menu_item_set_submenu( GTK_MENU_ITEM(item), menu );
+  gtk_menu_bar_append( GTK_MENU_BAR( menu_bar ), item );
+}
diff --git a/src/filemenu.h b/src/filemenu.h
new file mode 100644 (file)
index 0000000..64afad3
--- /dev/null
@@ -0,0 +1,21 @@
+/* filemenu.h */
+
+
+#ifndef FILEMENU_H
+#define FILEMENU_H 1
+
+
+#include <gtk/gtk.h>
+
+
+void
+FileOpenEvent( GtkObject *object, gpointer data );
+
+void
+FileResetEvent( GtkObject *object, gpointer data );
+
+void
+FileAddMenu( GtkWidget *menu_bar );
+
+
+#endif /* FILEMENU_H */
diff --git a/src/helpmenu.c b/src/helpmenu.c
new file mode 100644 (file)
index 0000000..e377b09
--- /dev/null
@@ -0,0 +1,68 @@
+/* help.c */
+
+
+#if HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#if STDC_HEADERS
+#  include <string.h>
+#elif HAVE_STRINGS_H
+#  include <strings.h>
+#endif
+
+#include <gtk/gtk.h>
+
+#include "common.h"
+#include "options.h"
+#include "emugtk.h"
+#include "messagebox.h"
+#include "helpmenu.h"
+
+
+static void
+HelpCommandsEvent( gchar *string )
+{
+  ShowMessage( "Command Line Options", COMMAND_LINE_OPTIONS, GTK_JUSTIFY_LEFT,
+              MESSAGE_DIALOG_FIXED_FONT );
+}
+
+
+static void
+HelpAboutEvent( gchar *string )
+{
+  ShowMessage( "About", VERSION_STRING, GTK_JUSTIFY_CENTER, MESSAGE_DIALOG_NORMAL_FONT );
+}
+
+
+void
+HelpAddMenu( GtkWidget *menu_bar )
+{
+  GtkWidget *item;
+  GtkWidget *menu;
+  
+  menu = gtk_menu_new();
+
+  /* Create the 'Help Command Line Options' item. */
+  item = gtk_menu_item_new_with_label("Command Line Options");
+  gtk_menu_append( GTK_MENU(menu), item );
+  /* Attach the callback functions to the activate signal. */
+  gtk_signal_connect_object( GTK_OBJECT(item), "activate",
+                            GTK_SIGNAL_FUNC(HelpCommandsEvent),
+                            NULL );
+
+  AddMenuSeparator(menu);
+
+  /* Create the 'Help About' item. */
+  item = gtk_menu_item_new_with_label( "About " PACKAGE );
+  gtk_menu_append( GTK_MENU(menu), item );
+  /* Attach the callback functions to the activate signal. */
+  gtk_signal_connect_object( GTK_OBJECT(item), "activate",
+                            GTK_SIGNAL_FUNC(HelpAboutEvent),
+                            NULL );
+  
+  /* Adding submenu title. */
+  item = gtk_menu_item_new_with_label( "Help" );
+  gtk_menu_item_set_submenu( GTK_MENU_ITEM(item), menu );
+  gtk_menu_bar_append( GTK_MENU_BAR( menu_bar ), item );
+}
diff --git a/src/helpmenu.h b/src/helpmenu.h
new file mode 100644 (file)
index 0000000..8387bdc
--- /dev/null
@@ -0,0 +1,14 @@
+/* helpmenu.h */
+
+
+#ifndef HELPMENU_H
+#define HELPMENU_H 1
+
+#include <gtk/gtk.h>
+
+
+void
+HelpAddMenu( GtkWidget *menu_bar );
+
+
+#endif /* HELPMENU_H */
diff --git a/src/hexfile.c b/src/hexfile.c
new file mode 100644 (file)
index 0000000..51ad33e
--- /dev/null
@@ -0,0 +1,139 @@
+/* file.c -- functions for loading an Intel HEX file
+   Copyright (C) 2004 Hugo Villeneuve */
+
+
+#if HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#if STDC_HEADERS
+#  include <string.h>
+#elif HAVE_STRINGS_H
+#  include <strings.h>
+#endif
+
+#include "common.h"
+#include "memory.h"
+
+
+/* Convert an ascii string to an hexadecimal number. */
+static unsigned int
+Ascii2Hex( char *istring, int length )
+{
+  unsigned int result = 0;
+  int i, ascii_code;
+
+  if ( !length || ( length > (int) strlen(istring) ) ) {
+    length = strlen(istring);
+  }
+  
+  for ( i = 0; i < length; i++ ) {
+    ascii_code = istring[ i ];
+    if ( ascii_code > 0x39 ) {
+      ascii_code &= 0xDF;
+    }
+    if ( ( ascii_code >= 0x30 && ascii_code <= 0x39 ) ||
+        ( ascii_code >= 0x41 && ascii_code <= 0x46 ) ) {
+      ascii_code -= 0x30;
+      if ( ascii_code > 9 ) {
+       ascii_code -= 7;
+      }
+      result <<= 4;
+      result += ascii_code;
+    }
+    else {
+      printf( "%s: In Ascii2Hex(), syntax error.\n", PACKAGE );
+    }
+  }
+  return result;
+}
+
+
+void
+LoadHexFile( const char *filename )
+{
+  int i, j, RecLength, LoadOffset, RecType, Data, Checksum;
+  
+#define LINE_BUFFER_LEN 256
+  FILE *fp;
+  int status;
+  char line[LINE_BUFFER_LEN];
+
+  if( filename != NULL ) {
+    /* Trying to open the file. */
+    fp = fopen( filename, "r" );
+    if( fp == NULL ) {
+      perror( PACKAGE );
+      /*ErrorLocation( __FILE__, __LINE__ );*/
+      exit( EXIT_FAILURE );
+    }
+  }
+  
+  /* Reading one line of data from the configuration file. */
+  /* char *fgets(char *s, int size, FILE *stream);
+     Reading stops after an EOF or a newline.  If a newline is read, it is
+     stored into the buffer.  A '\0'  is  stored after the last character in
+     the buffer. */
+  while( fgets( line, LINE_BUFFER_LEN, fp ) != NULL ) {
+    i = 0;
+    Checksum = 0;
+
+    if ( line[ i++ ] != ':' ) {
+      printf( "%s: line not beginning with \":\"\n", PACKAGE );
+      goto close_file;
+    }
+      
+    RecLength = Ascii2Hex( &line[ i ], 2 );
+    i += 2;
+    Checksum += RecLength;
+      
+    LoadOffset = Ascii2Hex( &line[i], 4 );
+    Checksum += LoadOffset / 256;
+    Checksum += LoadOffset % 256;
+    i += 4;
+    
+    RecType = Ascii2Hex( &line[i],2);
+    i += 2;
+    Checksum += RecType;
+    
+    if ( RecType == 1 ) {
+      Checksum += Ascii2Hex( &line[ i ], 2 );
+      if ( Checksum &= 0x000000FF ) {
+       /* Error. */
+       printf( "%s: Invalid format\n", PACKAGE );
+       goto close_file;
+      }
+      else {
+       /* OK */
+       goto close_file;
+      }
+    }   
+    
+    for ( j = 0; j < RecLength; j++ ) {
+      Data = Ascii2Hex( &line[ i ], 2 );
+      memory_write8( PGM_MEM_ID, (unsigned int)(LoadOffset + j), (unsigned char)Data );
+      i += 2;
+      Checksum += Data;
+    }
+    
+    RecType = Ascii2Hex( &line[ i ], 2 );
+    Checksum += RecType;      
+    
+    if ( Checksum &= 0x000000FF ) {
+      printf( "%s: Invalid format\n", PACKAGE );
+      goto close_file;
+    }
+  }
+  
+ close_file:
+  status = fclose( fp );
+  if( status != EXIT_SUCCESS ) {
+    fprintf( stderr, "%s: Error closing configuration file.\n", PACKAGE );
+    /*ErrorLocation( __FILE__, __LINE__ );*/
+    exit( EXIT_FAILURE );
+  }
+}
diff --git a/src/hexfile.h b/src/hexfile.h
new file mode 100644 (file)
index 0000000..10d7d92
--- /dev/null
@@ -0,0 +1,12 @@
+/* file.h */
+
+
+#ifndef FILE_H
+#define FILE_H 1
+
+
+void
+LoadHexFile( const char *filename );
+
+
+#endif /* FILE_H */
index 6c854c2..96ca1c2 100644 (file)
 #define EXT_MEM_SIZE 65536
 
 
-u_int8_t sfr_mem[SFR_MEM_SIZE];
-u_int8_t pgm_mem[PGM_MEM_SIZE];
-u_int8_t int_mem[INT_MEM_SIZE];
-u_int8_t ext_mem[EXT_MEM_SIZE];
+static u_int8_t sfr_mem[SFR_MEM_SIZE];
+static u_int8_t pgm_mem[PGM_MEM_SIZE];
+static u_int8_t int_mem[INT_MEM_SIZE];
+static u_int8_t ext_mem[EXT_MEM_SIZE];
 
 
 void
index 3e8b41d..9ce6845 100644 (file)
 
 #include <stdio.h>
 
+#include "common.h"
 #include "cpu8051.h"
 #include "memwin.h"
 
 
-/*static GtkWidget *memwin;*/
 static GtkWidget *memclist;
 
 
-//////////////////////////////////////////////////////////////////////////////
-// MemWin constructor
-//////////////////////////////////////////////////////////////////////////////
-void
-memwin_init( GtkWidget *parentwin )
+GtkWidget *
+memwin_init( int width, int height )
 {
   int i;
-  GtkStyle *style;
-  GdkFont *fixedfont;
-  fixedfont = gdk_font_load( "-adobe-courier-medium-r-normal--12-120-75-75-m-70-iso8859-1" );
+  GtkWidget *fixed_frame;
+
+  fixed_frame = gtk_frame_new(0);
+  gtk_frame_set_shadow_type( GTK_FRAME( fixed_frame ), GTK_SHADOW_ETCHED_OUT );
+  gtk_widget_set_usize( GTK_WIDGET( fixed_frame ), width, height );
 
   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 );
+  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 ) );
+  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 );
 
-#ifdef USE_GTK2
-  gtk_style_set_font( style, fixedfont );
+#if ( GTK_MAJOR_VERSION == 2)
+  PangoFontDescription *pango_font;
+  pango_font = pango_font_description_from_string( FIXED_FONT );
+  gtk_widget_modify_font( memclist, pango_font );
 #else
-  style->font = fixedfont;
+  {
+    GtkStyle *style;
+    /* Setting font for the widget. */
+    style = gtk_style_new();
+    gdk_font_unref( style->font );
+    
+    /* Load a fixed font */
+    style->font = gdk_font_load( FIXED_FONT );
+    gtk_widget_set_style( GTK_WIDGET( memclist ), style );
+  }
 #endif
 
-  gtk_widget_set_style( GTK_WIDGET( memclist ), style );
-
-  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 );
+    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 );
+  }
 
-  gtk_container_add( GTK_CONTAINER( parentwin ), memclist );
+  gtk_container_add( GTK_CONTAINER( fixed_frame ), memclist );
 
-  gtk_widget_show( memclist );
+  return fixed_frame;
 }
 
 
-//////////////////////////////////////////////////////////////////////////////
-// Dump 16 rows of 16 bytes from Address in Memory (direct addressing)
-//////////////////////////////////////////////////////////////////////////////
+/* 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 ) );
+  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 ) );
 }
 
 
-//////////////////////////////////////////////////////////////////////////////
-// Dump 16 rows of 16 bytes from Address in Memory (indirect addressing)
-//////////////////////////////////////////////////////////////////////////////
+/* Dump 16 rows of 16 bytes from Address in Memory (indirect addressing) */
 void
 memwin_DumpI( unsigned int Address )
 {
index ce3f1f1..0336076 100644 (file)
@@ -8,8 +8,8 @@
 #include <gtk/gtk.h>
 
 
-void
-memwin_init( GtkWidget *parentwin );
+GtkWidget *
+memwin_init( int width, int height );
 
 void
 memwin_DumpD( unsigned int Address );
diff --git a/src/messagebox.c b/src/messagebox.c
new file mode 100644 (file)
index 0000000..ffe1e03
--- /dev/null
@@ -0,0 +1,133 @@
+/* messagebox.c */
+
+
+#if HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <gtk/gtk.h>
+
+#include "common.h"
+#include "messagebox.h"
+
+
+#define MESSAGE_DIALOG_BORDER 25
+
+#define BUTTON_TEXT_BORDER 3
+
+
+/* This function is used to adjust the border around the text in a button. */
+static GtkWidget *
+AddTextButton( gchar *button_text )
+{
+  GtkWidget *button;
+  GtkWidget *label;
+  GtkWidget *label_window;
+
+  /* The GtkLabel widget is one of a few GTK+ widgets that don't create their own window to
+     render themselves into. Instead, they draw themselves directly onto their parents
+     window. This means that in order to set a property for a GtkLabel widget, you need to
+     change the property of its parent, i.e. the object that you pack it into.
+     Another solution (short term workaround) is to put the label widget inside another
+     widget that does get its own window, like the 'ViewPort' or 'EventBox' widget. */
+
+  /* Using workaround described above to set the border width of 'label' widget. */
+  label_window = gtk_event_box_new();
+
+  /* Creating our label. */
+  label = gtk_label_new(button_text);
+
+  /* Adding label widget to label_window widget. */
+  gtk_container_add( GTK_CONTAINER(label_window), label );
+
+  /* Changing border width of the label widget by way of label_window widget. */
+  gtk_container_set_border_width( GTK_CONTAINER(label_window), BUTTON_TEXT_BORDER );
+  
+  /* Create the button. */
+  button = gtk_button_new();
+
+  /* Adding label to button. */
+  gtk_container_add( GTK_CONTAINER(button), label_window );
+  
+  return button;
+}
+
+
+void
+ShowMessage( gchar *title, gchar *message, int justification, int font_style )
+{
+  GtkWidget *dialog;
+  GtkWidget *label;
+  GtkWidget *okay_button;
+  GtkWidget *label_window;
+  GtkWidget *center;
+  
+  /* Set-up a dialog window, centered on the screen. */
+  dialog = gtk_dialog_new();
+  gtk_window_set_title( GTK_WINDOW(dialog), title );
+  gtk_window_set_position( GTK_WINDOW(dialog), GTK_WIN_POS_CENTER );
+  
+  /* To have the main window of our application being unusable while using the dialog. */
+  gtk_window_set_modal( GTK_WINDOW(dialog), TRUE );
+  
+  /* The GtkLabel widget is one of a few GTK+ widgets that don't create their own window to
+     render themselves into. Instead, they draw themselves directly onto their parents
+     window. This means that in order to set a property for a GtkLabel widget, you need to
+     change the property of its parent, i.e. the object that you pack it into.
+     Another solution (short term workaround) is to put the label widget inside another
+     widget that does get its own window, like the 'ViewPort' or 'EventBox' widget. */
+
+  /* Using workaround described above to set the border width of 'label' widget. */
+  label_window = gtk_event_box_new();
+
+  /* Creating our label. */
+  label = gtk_label_new(message);
+  gtk_label_set_justify( GTK_LABEL(label), justification );
+
+  if( font_style == MESSAGE_DIALOG_FIXED_FONT ) {
+#if ( GTK_MAJOR_VERSION == 2)
+    PangoFontDescription *pango_font;
+
+    pango_font = pango_font_description_from_string( FIXED_FONT );
+
+    gtk_widget_modify_font( label, pango_font );
+#else
+    GtkStyle *style;
+    
+    /* Setting font for the label. */
+    style = gtk_style_new();
+    gdk_font_unref( style->font );
+    
+    /* Load a fixed font */
+    style->font = gdk_font_load( FIXED_FONT );
+    gtk_widget_set_style( label, style );
+#endif
+  }
+    
+  /* Adding label widget to label_window widget. */
+  gtk_container_add( GTK_CONTAINER(label_window), label );
+
+  /* Changing border width of the label widget by way of label_window widget. */
+  gtk_container_set_border_width( GTK_CONTAINER(label_window), MESSAGE_DIALOG_BORDER );
+
+  /* xalign, yalign, xscale, yscale */
+  center = gtk_alignment_new( 0.5, 0.5, 0.0, 0.0 );
+
+  /* Create the OK button. */
+  okay_button = AddTextButton( "OK" );
+  
+  /* Ensure that the dialog box is destroyed when the user clicks ok. */
+  gtk_signal_connect_object( GTK_OBJECT(okay_button), "clicked",
+                            GTK_SIGNAL_FUNC(gtk_widget_destroy), (gpointer) dialog );
+  
+  /* Add the OK button to the alignment widget. */
+  gtk_container_add( GTK_CONTAINER(center), okay_button );
+  /* Add the alignment widget to the dialog window. */
+  gtk_container_add( GTK_CONTAINER( GTK_DIALOG(dialog)->action_area ), center );
+
+  /* Add the label_window to the dialog window. */
+  gtk_container_add( GTK_CONTAINER( GTK_DIALOG(dialog)->vbox ), label_window );
+  
+  /* Show everything we've added to the dialog. */
+  gtk_widget_show_all(dialog);
+}
diff --git a/src/messagebox.h b/src/messagebox.h
new file mode 100644 (file)
index 0000000..ad5c382
--- /dev/null
@@ -0,0 +1,18 @@
+/* messagebox.h */
+
+
+#ifndef MESSAGEBOX_H
+#define MESSAGEBOX_H 1
+
+#include <gtk/gtk.h>
+
+
+#define MESSAGE_DIALOG_NORMAL_FONT 0
+#define MESSAGE_DIALOG_FIXED_FONT  1
+
+
+void
+ShowMessage( gchar *title, gchar *message, int justification, int font_style );
+
+
+#endif /* MESSAGEBOX_H */
index 98483a7..8aaae22 100755 (executable)
@@ -15,8 +15,6 @@ print INST_IMP "#include \"reg8051.h\"\n";
 print INST_IMP "#include \"cpu8051.h\"\n";
 print INST_IMP "#include \"memory.h\"\n";
 print INST_IMP "#include \"instructions_8051.h\"\n\n\n";
-print INST_IMP "extern int ActivePriority;\n";
-print INST_IMP "extern unsigned int PC;\n\n\n";
 
 print DISASM_H "/* disasm.h */\n\n\n";
 print DISASM_H "/* Do not modify this file directly, as it was created by opcode2c.pl\n";
@@ -159,9 +157,9 @@ for ($i=0 ; $i< 256; $i++) {
 
     if( $i == 0x85 ) {
        # Cas particulier pour MOV direct,direct -> src et dest sont inverses dans la memoire
-        print INST_IMP "  unsigned char srcaddr = memory_read8( PGM_MEM_ID, PC++ );\n";
+        print INST_IMP "  unsigned char srcaddr = memory_read8( PGM_MEM_ID, cpu8051.pc++ );\n";
        print INST_IMP "  unsigned char source = cpu8051_ReadD( srcaddr );\n";
-       print INST_IMP "  unsigned char destaddr = memory_read8( PGM_MEM_ID, PC++ );\n";
+       print INST_IMP "  unsigned char destaddr = memory_read8( PGM_MEM_ID, cpu8051.pc++ );\n";
        print INST_IMP "  unsigned char destination = cpu8051_ReadD( destaddr );\n";
        print INST_IMP "  destination = source;\n";
        print INST_IMP "  cpu8051_WriteD( destaddr, destination );\n";
@@ -170,17 +168,17 @@ for ($i=0 ; $i< 256; $i++) {
        if ($instargs[$i*4] > 0) {
            $op_destination=$instargs[$i*4+1];
            if ($op_destination == 0) { # addr11
-               print INST_IMP "  unsigned int addr11 = ( ( memory_read8( PGM_MEM_ID, PC - 1 ) << 3 ) & 0xF00 ) + memory_read8( PGM_MEM_ID, PC++ );\n";
+               print INST_IMP "  unsigned int addr11 = ( ( memory_read8( PGM_MEM_ID, cpu8051.pc - 1 ) << 3 ) & 0xF00 ) + memory_read8( PGM_MEM_ID, cpu8051.pc++ );\n";
            }
            if ($op_destination == 1) { # addr16
-               print INST_IMP "unsigned int addr16 = ( memory_read8( PGM_MEM_ID, PC++ ) << 8 );\n";
-               print INST_IMP "addr16 += memory_read8( PGM_MEM_ID, PC++ );\n";
+               print INST_IMP "unsigned int addr16 = ( memory_read8( PGM_MEM_ID, cpu8051.pc++ ) << 8 );\n";
+               print INST_IMP "addr16 += memory_read8( PGM_MEM_ID, cpu8051.pc++ );\n";
            }
            if ($op_destination == 2) { # A
                print INST_IMP "unsigned char destination = cpu8051_ReadD( _ACC_ );\n";
            }
            if ($op_destination == 3) { # direct
-               print INST_IMP "unsigned char destaddr = memory_read8( PGM_MEM_ID, PC++ );\n";
+               print INST_IMP "unsigned char destaddr = memory_read8( PGM_MEM_ID, cpu8051.pc++ );\n";
                print INST_IMP "unsigned char destination = cpu8051_ReadD( destaddr );\n";
            }
            if ($op_destination == 4) { # @R0
@@ -215,15 +213,15 @@ for ($i=0 ; $i< 256; $i++) {
                print INST_IMP "unsigned char destination = cpu8051_ReadD( BANKPSW + _R7_ );\n";
            }
            if ($op_destination == 14) { # bitaddr
-               print INST_IMP "unsigned char destination, dstbitaddr = memory_read8( PGM_MEM_ID, PC++ );\n";
+               print INST_IMP "unsigned char destination, dstbitaddr = memory_read8( PGM_MEM_ID, cpu8051.pc++ );\n";
                print INST_IMP "destination = cpu8051_ReadB( dstbitaddr );\n";
            }
            if ($op_destination == 15) { # reladdr
-               print INST_IMP "PC++;\n";
-               print INST_IMP "unsigned int destination = ( ( memory_read8( PGM_MEM_ID, PC - 1 ) + PC ) & 0xFF ) + ( PC & 0xFF00 );\n";
+               print INST_IMP "cpu8051.pc++;\n";
+               print INST_IMP "unsigned int destination = ( ( memory_read8( PGM_MEM_ID, cpu8051.pc - 1 ) + cpu8051.pc ) & 0xFF ) + ( cpu8051.pc & 0xFF00 );\n";
            }
            if ($op_destination == 16) { # #data
-               print INST_IMP "unsigned char destination = memory_read8( PGM_MEM_ID, PC++ );\n";
+               print INST_IMP "unsigned char destination = memory_read8( PGM_MEM_ID, cpu8051.pc++ );\n";
            }
            if ($op_destination == 17) { # C
                print INST_IMP "unsigned char destination = ( cpu8051_ReadD( _PSW_ ) >> 7 );\n";
@@ -240,11 +238,11 @@ for ($i=0 ; $i< 256; $i++) {
                print INST_IMP "unsigned int destination = ( cpu8051_ReadD( _DPTRHIGH_ ) << 8 ) + cpu8051_ReadD( _DPTRLOW_ );\n";
            }
            if ($op_destination == 22) { # #data16
-               print INST_IMP "unsigned char destination = ( memory_read8( PGM_MEM_ID, PC++ ) << 8 );\n";
-               print INST_IMP "destination += memory_read8( PGM_MEM_ID, PC++ );\n";
+               print INST_IMP "unsigned char destination = ( memory_read8( PGM_MEM_ID, (cpu8051.pc)++ ) << 8 );\n";
+               print INST_IMP "destination += memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );\n";
            }
            if ($op_destination == 23) { # /bitaddr
-               print INST_IMP "unsigned char destination, dstbitaddr = memory_read8( PGM_MEM_ID, PC++ );\n";
+               print INST_IMP "unsigned char destination, dstbitaddr = memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );\n";
                print INST_IMP "destination = ( cpu8051_ReadB( dstbitaddr ) ^ 1 );\n";
            }
            if ($op_destination == 24) { # @DPTR
@@ -255,17 +253,17 @@ for ($i=0 ; $i< 256; $i++) {
        if ($instargs[$i*4] > 1) {
            $op_source=$instargs[$i*4+2];
            if ($op_source == 0) { # addr11
-               print INST_IMP "unsigned int addr11 = ( ( memory_read8( PGM_MEM_ID, PC - 1 ) << 3 ) & 0xF00 ) + memory_read8( PGM_MEM_ID, PC++ );\n";
+               print INST_IMP "unsigned int addr11 = ( ( memory_read8( PGM_MEM_ID, cpu8051.pc - 1 ) << 3 ) & 0xF00 ) + memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );\n";
            }
            if ($op_source == 1) { # addr16
-               print INST_IMP "unsigned int addr16 = ( memory_read8( PGM_MEM_ID, PC++ ) << 8 );\n";
-               print INST_IMP "addr16 += memory_read8( PGM_MEM_ID, PC++ );\n";
+               print INST_IMP "unsigned int addr16 = ( memory_read8( PGM_MEM_ID, (cpu8051.pc)++ ) << 8 );\n";
+               print INST_IMP "addr16 += memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );\n";
            }
            if ($op_source == 2) { # A
                print INST_IMP "unsigned char source = cpu8051_ReadD( _ACC_ );\n";
            }
            if ($op_source == 3) { # direct
-               print INST_IMP "unsigned char srcaddr = memory_read8( PGM_MEM_ID, PC++ );\n";
+               print INST_IMP "unsigned char srcaddr = memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );\n";
                print INST_IMP "unsigned char source = cpu8051_ReadD( srcaddr );\n";
            }
            if ($op_source == 4) { # @R0
@@ -300,15 +298,15 @@ for ($i=0 ; $i< 256; $i++) {
            }
 
            if ($op_source == 14) { # bitaddr
-               print INST_IMP "unsigned char source, srcbitaddr = memory_read8( PGM_MEM_ID, PC++ );\n";
+               print INST_IMP "unsigned char source, srcbitaddr = memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );\n";
                print INST_IMP "source = cpu8051_ReadB( srcbitaddr );\n";
            }
            if ($op_source == 15) { # reladdr
-               print INST_IMP "PC++;\n";
-               print INST_IMP "unsigned int source = ( ( memory_read8( PGM_MEM_ID, PC - 1 ) + PC ) & 0xFF ) + ( PC & 0xFF00 );\n";
+               print INST_IMP "(cpu8051.pc)++;\n";
+               print INST_IMP "unsigned int source = ( ( memory_read8( PGM_MEM_ID, cpu8051.pc - 1 ) + cpu8051.pc ) & 0xFF ) + ( cpu8051.pc & 0xFF00 );\n";
            }
            if ($op_source == 16) { # #data
-               print INST_IMP "unsigned char source = memory_read8( PGM_MEM_ID, PC++ );\n";
+               print INST_IMP "unsigned char source = memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );\n";
            }
            if ($op_source == 17) { # C
                print INST_IMP "unsigned char source = ( cpu8051_ReadD( _PSW_ ) >> 7 );\n";
@@ -317,17 +315,17 @@ for ($i=0 ; $i< 256; $i++) {
                print INST_IMP "unsigned char source = memory_read8( PGM_MEM_ID, cpu8051_ReadD( _ACC_ ) + cpu8051_ReadD( _DPTRLOW_ ) + ( cpu8051_ReadD( _DPTRHIGH_ ) << 8 ) );\n";
            }
            if ($op_source == 19) { # @A+PC
-               print INST_IMP "unsigned char source = memory_read8( PGM_MEM_ID, cpu8051_ReadD( _ACC_ ) + ( ++PC ) );\n";
+               print INST_IMP "unsigned char source = memory_read8( PGM_MEM_ID, cpu8051_ReadD( _ACC_ ) + ( ++cpu8051.pc ) );\n";
            }
            if ($op_source == 21) { # DPTR
                print INST_IMP "unsigned int source = ( cpu8051_ReadD( _DPTRHIGH_ ) << 8 ) + cpu8051_ReadD( _DPTRLOW_ );\n";
            }
            if ($op_source == 22) { # #data16
-               print INST_IMP "unsigned char source = ( memory_read8( PGM_MEM_ID, PC++ ) << 8 );\n";
-               print INST_IMP "source += memory_read8( PGM_MEM_ID, PC++ );\n";
+               print INST_IMP "unsigned char source = ( memory_read8( PGM_MEM_ID, (cpu8051.pc)++ ) << 8 );\n";
+               print INST_IMP "source += memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );\n";
            }
            if ($op_source == 23) { # /bitaddr
-               print INST_IMP "unsigned char source, srcbitaddr = memory_read8( PGM_MEM_ID, PC++ );\n";
+               print INST_IMP "unsigned char source, srcbitaddr = memory_read8( PGM_MEM_ID, (cpu8051.pc)++ );\n";
                print INST_IMP "source = ( cpu8051_ReadB( srcbitaddr ) ^ 1 );\n";
            }
            if ($op_source == 24) { # @DPTR
@@ -351,22 +349,22 @@ for ($i=0 ; $i< 256; $i++) {
 
        # JBC
        if ($insttype[$i] == 5) {
-           print INST_IMP "if ( destination == 1 ) { PC = source; destination = 0; }\n";
+           print INST_IMP "if ( destination == 1 ) { cpu8051.pc = source; destination = 0; }\n";
        }
 
        # ACALL
        if ($insttype[$i] == 6) {
            print INST_IMP "unsigned char SP = cpu8051_ReadD( _SP_ );\n";
-           print INST_IMP "cpu8051_WriteI( ++SP, ( PC & 0x00FF ) );\n";
-           print INST_IMP "cpu8051_WriteI( ++SP, ( PC >> 8 ) );\n";
+           print INST_IMP "cpu8051_WriteI( ++SP, ( cpu8051.pc & 0x00FF ) );\n";
+           print INST_IMP "cpu8051_WriteI( ++SP, ( cpu8051.pc >> 8 ) );\n";
            print INST_IMP "cpu8051_WriteD( _SP_, SP );\n";
        }
 
        # LCALL
        if ($insttype[$i] == 7) {
            print INST_IMP "unsigned char SP = cpu8051_ReadD( _SP_ );\n";
-           print INST_IMP "cpu8051_WriteI( ++SP, ( PC & 0x00FF ) );\n";
-           print INST_IMP "cpu8051_WriteI( ++SP, ( PC >> 8 ) );\n";
+           print INST_IMP "cpu8051_WriteI( ++SP, ( cpu8051.pc & 0x00FF ) );\n";
+           print INST_IMP "cpu8051_WriteI( ++SP, ( cpu8051.pc >> 8 ) );\n";
            print INST_IMP "cpu8051_WriteD( _SP_, SP );\n";
        }
 
@@ -384,14 +382,14 @@ for ($i=0 ; $i< 256; $i++) {
 
        # JB
        if ($insttype[$i] == 10) {
-           print INST_IMP "if ( destination == 1 ) { PC = source; }\n";
+           print INST_IMP "if ( destination == 1 ) { cpu8051.pc = source; }\n";
        }
 
        # RET
        if ($insttype[$i] == 11) {
            print INST_IMP "unsigned char SP = cpu8051_ReadD( _SP_ );\n";
-           print INST_IMP "PC = ( cpu8051_ReadI( SP-- ) << 8 );\n";
-           print INST_IMP "PC += cpu8051_ReadI ( SP-- );\n";
+           print INST_IMP "cpu8051.pc = ( cpu8051_ReadI( SP-- ) << 8 );\n";
+           print INST_IMP "cpu8051.pc += cpu8051_ReadI ( SP-- );\n";
            print INST_IMP "cpu8051_WriteD( _SP_, SP );\n";
        }
 
@@ -413,15 +411,15 @@ for ($i=0 ; $i< 256; $i++) {
 
        # JNB
        if ($insttype[$i] == 14) {
-           print INST_IMP "if ( destination == 0 ) { PC = source; }\n";
+           print INST_IMP "if ( destination == 0 ) { cpu8051.pc = source; }\n";
        }
 
        # RETI
        if ($insttype[$i] == 15) {
-           print INST_IMP "ActivePriority = -1;\n";
+           print INST_IMP "cpu8051.active_priority = -1;\n";
            print INST_IMP "unsigned char SP = cpu8051_ReadD( _SP_ );\n";
-           print INST_IMP "PC = ( cpu8051_ReadI( SP-- ) << 8 );\n";
-           print INST_IMP "PC += cpu8051_ReadI( SP-- );\n";
+           print INST_IMP "cpu8051.pc = ( cpu8051_ReadI( SP-- ) << 8 );\n";
+           print INST_IMP "cpu8051.pc += cpu8051_ReadI( SP-- );\n";
        }
 
        # RLC
@@ -445,7 +443,7 @@ for ($i=0 ; $i< 256; $i++) {
 
        # JC
        if ($insttype[$i] == 18) {
-           print INST_IMP "if ( cpu8051_ReadD( _PSW_ ) > 0x7F) { PC = destination; }\n";
+           print INST_IMP "if ( cpu8051_ReadD( _PSW_ ) > 0x7F) { cpu8051.pc = destination; }\n";
        }
 
        # ORL
@@ -461,7 +459,7 @@ for ($i=0 ; $i< 256; $i++) {
 
        # JNC
        if ($insttype[$i] == 20) {
-           print INST_IMP "if ( cpu8051_ReadD( _PSW_ ) < 0x80 ) { PC = destination; }\n";
+           print INST_IMP "if ( cpu8051_ReadD( _PSW_ ) < 0x80 ) { cpu8051.pc = destination; }\n";
        }
 
        # ANL
@@ -477,7 +475,7 @@ for ($i=0 ; $i< 256; $i++) {
 
        # JZ
        if ($insttype[$i] == 22) {
-           print INST_IMP "if ( cpu8051_ReadD( _ACC_ ) == 0 ) { PC = destination; }\n";
+           print INST_IMP "if ( cpu8051_ReadD( _ACC_ ) == 0 ) { cpu8051.pc = destination; }\n";
        }
 
        # XRL
@@ -487,12 +485,12 @@ for ($i=0 ; $i< 256; $i++) {
 
        # JNZ
        if ($insttype[$i] == 24) {
-           print INST_IMP "if ( cpu8051_ReadD( _ACC_ ) != 0 ) { PC = destination; }\n";
+           print INST_IMP "if ( cpu8051_ReadD( _ACC_ ) != 0 ) { cpu8051.pc = destination; }\n";
        }
 
        # JMP
        if ($insttype[$i] == 25) {
-           print INST_IMP "PC = destination;\n";
+           print INST_IMP "cpu8051.pc = destination;\n";
        }
 
        # MOV
@@ -502,7 +500,7 @@ for ($i=0 ; $i< 256; $i++) {
 
        # SJMP
        if ($insttype[$i] == 27) {
-           print INST_IMP "PC = destination;\n";
+           print INST_IMP "cpu8051.pc = destination;\n";
        }
 
        # MOVC
@@ -547,10 +545,10 @@ for ($i=0 ; $i< 256; $i++) {
 
        # CJNE
        if ($insttype[$i] == 34) {
-           print INST_IMP "unsigned int reladdr = ( ( memory_read8( PGM_MEM_ID, PC ) + ( ( PC + 1 ) & 0x00FF ) ) & 0x00FF ) + ( ( PC + 1 ) & 0xFF00 );\n";
+           print INST_IMP "unsigned int reladdr = ( ( memory_read8( PGM_MEM_ID, cpu8051.pc ) + ( ( cpu8051.pc + 1 ) & 0x00FF ) ) & 0x00FF ) + ( ( cpu8051.pc + 1 ) & 0xFF00 );\n";
            print INST_IMP "cpu8051_WriteD( _PSW_, ( cpu8051_ReadD( _PSW_ ) & 0x7F ) );\n";
            print INST_IMP "if ( destination < source ) cpu8051_WriteD( _PSW_, ( cpu8051_ReadD( _PSW_ ) | 0x80 ) );\n";
-           print INST_IMP "if ( destination != source ) PC = reladdr;\n";
+           print INST_IMP "if ( destination != source ) cpu8051.pc = reladdr;\n";
        }
 
        # PUSH
@@ -604,7 +602,7 @@ for ($i=0 ; $i< 256; $i++) {
        # DJNZ
        if ($insttype[$i] == 42) {
            print INST_IMP "destination--;\n";
-           print INST_IMP "if ( destination != 0 ) PC = source;\n";
+           print INST_IMP "if ( destination != 0 ) cpu8051.pc = source;\n";
        }
 
        # XCHD
@@ -628,10 +626,10 @@ for ($i=0 ; $i< 256; $i++) {
        if ($instargs[$i*4] > 0) {
            $op_destination=$instargs[$i*4+1];
            if ($op_destination == 0) { # addr11
-               print INST_IMP "PC = ( PC & 0xF800 ) | addr11;\n";
+               print INST_IMP "cpu8051.pc = ( cpu8051.pc & 0xF800 ) | addr11;\n";
            }
            if ($op_destination == 1) { # addr16
-               print INST_IMP "PC = addr16;\n";
+               print INST_IMP "cpu8051.pc = addr16;\n";
            }
            if ($op_destination == 2) { # A
                print INST_IMP "cpu8051_WriteD( _ACC_, destination );\n";
@@ -692,10 +690,10 @@ for ($i=0 ; $i< 256; $i++) {
            if ($instargs[$i*4] > 1) {
                $op_source=$instargs[$i*4+2];
                if ($op_source == 0) { # addr11
-                   print INST_IMP "PC = ( PC & 0xF800 ) | addr11;\n";
+                   print INST_IMP "cpu8051.pc = ( cpu8051.pc & 0xF800 ) | addr11;\n";
                }
                if ($op_source == 1) { # addr16
-                   print INST_IMP "PC = addr16;\n";
+                   print INST_IMP "cpu8051.pc = addr16;\n";
                }
                if ($op_source == 2) { # A
                    print INST_IMP "cpu8051_WriteD( _ACC_, source );\n";
index e32f811..aab7d13 100644 (file)
 char *hex_file;
 
 
-char *
-GetHexFileName( void )
-{
-  return hex_file;
-}
-
-
 /*******************************************************************************
  * Display the help message and exit
  ******************************************************************************/
 static void
 DisplayUsage( void )
 {
-  printf( "Usage: %s [OPTION]... [FILENAME]\n", PACKAGE );
-  printf( "Simulator/emulator for 8051 family microcontrollers.\n\n" );
-  printf( "  -h                        display this help and exit\n" );
-  printf( "  -version                  display version information and exit\n");
-  printf( "\n" );
+  printf( COMMAND_LINE_OPTIONS );
 }
 
 
@@ -52,7 +41,7 @@ DisplayVersion( void )
 {
   printf( "\n" );
   printf( "  %s, version %s\n", PACKAGE, VERSION );
-  printf( "  Written by Hugo Villeneuve, Jonathan St-André and Pascal Fecteau.\n\n" );
+  printf( "  Written by Jonathan St-André, Pascal Fecteau and Hugo Villeneuve\n\n" );
 }
 
 
index 657e263..e7fd9f6 100644 (file)
@@ -4,8 +4,21 @@
 #define OPTIONS_H 1
 
 
-char *
-GetHexFileName( void );
+#define COMMAND_LINE_OPTIONS \
+  "Usage: " PACKAGE " [OPTION]... [FILENAME]\n" \
+  "Simulator/emulator for 8051 family microcontrollers.\n\n" \
+  "  -h                    display this help and exit\n" \
+  "  -version              display version information and exit\n"
+
+#define VERSION_STRING \
+  PACKAGE "\n" \
+  "Version " VERSION "\n" \
+  "\n" \
+  "Written by\n" \
+  "Hugo Villeneuve\n" \
+  "Jonathan St-André\n" \
+  "Pascal Fecteau"
+
 
 void
 ParseCommandLineOptions( int argc, char *argv[] );
index 80c1f08..67824f6 100644 (file)
 
 #include <stdio.h>
 
+#include "common.h"
 #include "cpu8051.h"
 #include "pgmwin.h"
 
 
-/* private */
-GtkWidget *pgmwin;
-GtkWidget *pgmclist;
-int NbBreakpoints;
-unsigned int Breakpoints[ MAXBP ];
-unsigned int DisasmAddresses[ 24 ];
+static GtkWidget *pgmclist;
+static int NbBreakpoints;
+static unsigned int Breakpoints[ MAXBP ];
+static 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( )
 {
-  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 );
+  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 ( 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 ) );
+}
 
-  style = gtk_widget_get_style( GTK_WIDGET( pgmclist ) );
 
-#ifdef USE_GTK2
-  gtk_style_set_font( style, fixedfont );
-#else
-  style->font = fixedfont;
-#endif
+/* Clear Breakpoint at Address from list */
+static void
+pgmwin_ClearBreakpoint( unsigned int Address )
+{
+  int Index = 0;
 
-  gtk_widget_set_style( GTK_WIDGET( pgmclist ), style );
+  while( Index < NbBreakpoints && Breakpoints[ Index ] != Address ) {
+    Index++;
+  }
+  if( Breakpoints[ Index ] != Address ) {
+    return;
+  }
+  Breakpoints[ Index ] = Breakpoints[ NbBreakpoints - 1 ];
+  NbBreakpoints--;
+}
 
-  char *pgmdummy[] = { 0 };
-  for ( i = 0; i < 24; i++ ) gtk_clist_append( GTK_CLIST( pgmclist ), pgmdummy );
 
-  gtk_container_add( GTK_CONTAINER( parentwin ), pgmclist );
+/* Set Breakpoint at Address from list. */
+static void
+pgmwin_SetBreakpoint( unsigned int Address )
+{
+  if( pgmwin_IsBreakpoint( Address ) ) {
+    return;
+  }
+  if( NbBreakpoints < MAXBP ) {
+    Breakpoints[ NbBreakpoints++ ] = Address;
+  }
+}
 
-  gtk_widget_show( pgmclist );
+/* Toggle the breakpoint at Address. */
+static void
+pgmwin_ToggleBreakpoint( unsigned int Address )
+{
+  if( pgmwin_IsBreakpoint( Address ) ) {
+    pgmwin_ClearBreakpoint( Address );
+  }
+  else {
+    pgmwin_SetBreakpoint( Address );
+  }
+}
 
-  NbBreakpoints = 0;
 
-  /*
-  PgmWinPtrs[ PgmWinNumber ] = this;
-  PgmWinNumbers[ PgmWinNumber ] = PgmWinNumber;
-  gtk_signal_connect( GTK_OBJECT( pgmclist ), "button-press-event", GTK_SIGNAL_FUNC( PgmWinButtonPress ), &PgmWinNumbers[ PgmWinNumber++ ] );
-  */
+#ifdef dsfdsfs
+/* Show Breakpoints list. */
+static void
+pgmwin_ShowBreakpoints( )
+{
+  int Index;
 
+  for ( Index = 0; Index < NbBreakpoints ; Index++ ) {
+    printf( "Breakpoint at Address = %.4X\n", Breakpoints[ Index ] );
+  }
 }
+#endif
 
 
-//////////////////////////////////////////////////////////////////////////////
-// void pgmwin_Disasm( )
-// Disasm 24 lines from CPU
-//////////////////////////////////////////////////////////////////////////////
-void
-pgmwin_Disasm( )
+/* Is the a breakpoint at Address. */
+int
+pgmwin_IsBreakpoint( unsigned int Address )
 {
-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 ) );
+  int Index = 0;
+  while( Index < NbBreakpoints && Breakpoints[ Index ] != Address ) {
+    Index++;
+  }
+
+  return ( Breakpoints[ Index ] == Address && Index < NbBreakpoints );
 }
 
-//////////////////////////////////////////////////////////////////////////////
-// gint pgmwin_ButtonPressEvent( GtkWidget *widget, GdkEvent *event, gpointer data )
-// Mouse button pressed in the window
-//////////////////////////////////////////////////////////////////////////////
-gint pgmwin_ButtonPressEvent( GtkWidget *widget, GdkEvent *event, gpointer data )
+
+/* Mouse button pressed in the window. */
+static 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;
@@ -120,82 +128,56 @@ gint pgmwin_ButtonPressEvent( GtkWidget *widget, GdkEvent *event, gpointer data
   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_Disasm();
   
-  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 )
-{
-  int Index = 0;
-  while ( Index < NbBreakpoints && Breakpoints[ Index ] != Address ) Index++;
-  if ( Breakpoints[ Index ] != Address ) return;
-  Breakpoints[ Index ] = Breakpoints[ NbBreakpoints - 1 ];
-  NbBreakpoints--;
+  return FALSE;
 }
 
-//////////////////////////////////////////////////////////////////////////////
-// 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 pgmwin_IsBreakpoint( unsigned int Address )
-// Is the a breakpoint at Address
-//////////////////////////////////////////////////////////////////////////////
-int pgmwin_IsBreakpoint( unsigned int Address )
+GtkWidget *
+pgmwin_init( int width, int height )
 {
-  int Index = 0;
-  while ( Index < NbBreakpoints && Breakpoints[ Index ] != Address ) Index++;
-  return ( Breakpoints[ Index ] == Address && Index < NbBreakpoints );
-}
+  int i;
+  GtkWidget *fixed_frame;
 
-//////////////////////////////////////////////////////////////////////////////
-// 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 );
-}
+  fixed_frame = gtk_frame_new(0);
+  gtk_frame_set_shadow_type( GTK_FRAME( fixed_frame ), GTK_SHADOW_ETCHED_OUT );
+  gtk_widget_set_usize( GTK_WIDGET( fixed_frame ), width, height );
 
+  pgmclist = gtk_clist_new( 1 );
+  gtk_clist_set_selection_mode( GTK_CLIST( pgmclist ), GTK_SELECTION_SINGLE );
+  gtk_widget_set_usize( 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 );
 
+#if ( GTK_MAJOR_VERSION == 2)
+  PangoFontDescription *pango_font;
+  pango_font = pango_font_description_from_string( FIXED_FONT );
+  gtk_widget_modify_font( pgmclist, pango_font );
+#else
+  {
+    GtkStyle *style;
+    /* Setting font for the widget. */
+    style = gtk_style_new();
+    gdk_font_unref( style->font );
+    
+    /* Load a fixed font */
+    style->font = gdk_font_load( FIXED_FONT );
+    gtk_widget_set_style( GTK_WIDGET( pgmclist ), style );
+  }
+#endif
 
+  char *pgmdummy[] = { 0 };
+  for( i = 0; i < 24; i++ ) {
+    gtk_clist_append( GTK_CLIST( pgmclist ), pgmdummy );
+  }
 
+  gtk_container_add( GTK_CONTAINER( fixed_frame ), pgmclist );
 
+  NbBreakpoints = 0;
 
+  gtk_signal_connect( GTK_OBJECT( pgmclist ), "button-press-event",
+                     GTK_SIGNAL_FUNC( pgmwin_ButtonPressEvent ), NULL );
 
+  return fixed_frame;
+}
index dc3cbae..998b66f 100644 (file)
 #define MAXBP 32
 
 
-void
-pgmwin_init( GtkWidget *parentwin );
+GtkWidget *
+pgmwin_init( int width, int height );
 
 void
 pgmwin_Disasm( void );
 
-gint
-pgmwin_ButtonPressEvent( GtkWidget *widget, GdkEvent *event, gpointer data );
-
-void
-pgmwin_ShowBreakpoints( void );
-
-void
-pgmwin_SetBreakpoint( unsigned int Address );
-
-void
-pgmwin_ClearBreakpoint( unsigned int Address );
-
 int
 pgmwin_IsBreakpoint( unsigned int Address );
 
-void
-pgmwin_ToggleBreakpoint( unsigned int Address );
-
-void
-pgmwin_PgmWinButtonPress( GtkWidget *widget, GdkEvent *event, gpointer data );
-
 
 #endif /* PGMWIN_H */
index 91f156a..bf17f02 100644 (file)
@@ -7,61 +7,60 @@
 
 #include <stdio.h>
 
+#include "common.h"
 #include "reg8051.h"
 #include "cpu8051.h"
 #include "regwin.h"
 
 
-/* private */
-/*GtkWidget *regwin;*/
-GtkWidget *regclist;
+static GtkWidget *regclist;
 
 
-/* in cpu8051.c */
-extern unsigned int PC;
-
-
-//////////////////////////////////////////////////////////////////////////////
-// RegWin constructor
-//////////////////////////////////////////////////////////////////////////////
-void
-regwin_init( GtkWidget *parentwin )
+GtkWidget *
+regwin_init( int width, int height )
 {
   int i;
-  GtkStyle *style;
-  GdkFont *fixedfont;
-  fixedfont = gdk_font_load( "-adobe-courier-medium-r-normal--12-120-75-75-m-70-iso8859-1" );
-  
+  GtkWidget *fixed_frame;
+
+  fixed_frame = gtk_frame_new(0);
+  gtk_frame_set_shadow_type( GTK_FRAME( fixed_frame ), GTK_SHADOW_ETCHED_OUT );
+  gtk_widget_set_usize( GTK_WIDGET( fixed_frame ), width, height );
+
   regclist = gtk_clist_new( 1 );
   gtk_clist_set_selection_mode( GTK_CLIST( regclist ), GTK_SELECTION_SINGLE );
-  gtk_widget_set_usize( GTK_WIDGET( regclist ), REG_WIN_WIDTH, REG_WIN_HEIGHT );
+  gtk_widget_set_usize( GTK_WIDGET( regclist ), width, height );
   gtk_clist_set_column_justification( GTK_CLIST( regclist ), 0, GTK_JUSTIFY_LEFT );
-  gtk_clist_set_column_width( GTK_CLIST( regclist ), 0, REG_WIN_WIDTH );
+  gtk_clist_set_column_width( GTK_CLIST( regclist ), 0, width );
 
-  style = gtk_widget_get_style( GTK_WIDGET( regclist ) );
-
-#ifdef USE_GTK2
-  gtk_style_set_font( style, fixedfont );
+#if ( GTK_MAJOR_VERSION == 2)
+  PangoFontDescription *pango_font;
+  pango_font = pango_font_description_from_string( FIXED_FONT );
+  gtk_widget_modify_font( regclist, pango_font );
 #else
-  style->font = fixedfont;
+  {
+    GtkStyle *style;
+    /* Setting font for the widget. */
+    style = gtk_style_new();
+    gdk_font_unref( style->font );
+    
+    /* Load a fixed font */
+    style->font = gdk_font_load( FIXED_FONT );
+    gtk_widget_set_style( GTK_WIDGET( regclist ), style );
+  }
 #endif
 
-  gtk_widget_set_style( GTK_WIDGET( regclist ), style );
-
   char *regdummy[] = { 0 };
-  for ( i = 0; i < 24; i++ )
+  for ( i = 0; i < 24; i++ ) {
     gtk_clist_append( GTK_CLIST( regclist ), regdummy );
+  }
   
-  gtk_container_add( GTK_CONTAINER( parentwin ), regclist );
+  gtk_container_add( GTK_CONTAINER( fixed_frame ), regclist );
 
-  gtk_widget_show( regclist );
+  return fixed_frame;
 }
 
 
-//////////////////////////////////////////////////////////////////////////////
-// void regwin_Show( CPU8051 *CPU )
-// Show registers
-//////////////////////////////////////////////////////////////////////////////
+/* Show registers. */
 void
 regwin_Show( void )
 {
@@ -73,7 +72,7 @@ regwin_Show( void )
   gtk_clist_freeze( GTK_CLIST( regclist ) );
   
   // Main registers
-  sprintf( TextTmp , "PC   = %.4X", PC );
+  sprintf( TextTmp , "PC   = %.4X", cpu8051.pc );
   gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp );
   sprintf( TextTmp , "SP   =   %.2X", cpu8051_ReadD( _SP_ ) );
   gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp );
@@ -89,13 +88,13 @@ regwin_Show( void )
   gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp );
 
   // Ports registers
-  sprintf( TextTmp , "P0 =     %.2X", cpu8051_ReadD( _P0_ ) );
+  sprintf( TextTmp , "P0   =   %.2X", cpu8051_ReadD( _P0_ ) );
   gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp );
-  sprintf( TextTmp , "P1 =     %.2X", cpu8051_ReadD( _P1_ ) );
+  sprintf( TextTmp , "P1   =   %.2X", cpu8051_ReadD( _P1_ ) );
   gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp );
-  sprintf( TextTmp , "P2 =     %.2X", cpu8051_ReadD( _P2_ ) );
+  sprintf( TextTmp , "P2   =   %.2X", cpu8051_ReadD( _P2_ ) );
   gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp );
-  sprintf( TextTmp , "P3 =     %.2X", cpu8051_ReadD( _P3_ ) );
+  sprintf( TextTmp , "P3   =   %.2X", cpu8051_ReadD( _P3_ ) );
   gtk_clist_set_text( GTK_CLIST( regclist ), row++, 0, TextTmp );
 
   // Misc Registers
index 2b571b5..ec31334 100644 (file)
@@ -9,8 +9,8 @@
 #include "gtksizes.h"
 
 
-void
-regwin_init( GtkWidget *parentwin );
+GtkWidget *
+regwin_init( int width, int height );
 
 void
 regwin_Show( void );
diff --git a/src/viewmenu.c b/src/viewmenu.c
new file mode 100644 (file)
index 0000000..31a164e
--- /dev/null
@@ -0,0 +1,62 @@
+/* viewmenu.c */
+
+
+#if HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <gtk/gtk.h>
+
+#include "common.h"
+#include "emugtk.h" /* For AddMenuSeparator() function. */
+#include "messagebox.h"
+#include "viewmenu.h"
+
+
+static void
+ViewMenuExternalDump( gchar *string )
+{
+  ShowMessage( "External Memory Dump", "Not implemented yet!", GTK_JUSTIFY_CENTER,
+              MESSAGE_DIALOG_NORMAL_FONT );
+}
+
+
+static void
+ViewMenuInternalDump( gchar *string )
+{
+  ShowMessage( "Internal Memory Dump", "Not implemented yet!", GTK_JUSTIFY_CENTER,
+              MESSAGE_DIALOG_NORMAL_FONT );
+}
+
+
+void
+ViewAddMenu( GtkWidget *menu_bar )
+{
+  GtkWidget *item;
+  GtkWidget *menu;
+  
+  menu = gtk_menu_new();
+
+  /* Create the 'Viewmenu External Memory Dump' item. */
+  item = gtk_menu_item_new_with_label("External Memory Dump");
+  gtk_menu_append( GTK_MENU(menu), item );
+  /* Attach the callback functions to the activate signal. */
+  gtk_signal_connect_object( GTK_OBJECT(item), "activate",
+                            GTK_SIGNAL_FUNC(ViewMenuExternalDump),
+                            NULL );
+
+  AddMenuSeparator(menu);
+
+  /* Create the 'Viewmenu Internal Memory Dump' item. */
+  item = gtk_menu_item_new_with_label( "Internal Memory Dump" );
+  gtk_menu_append( GTK_MENU(menu), item );
+  /* Attach the callback functions to the activate signal. */
+  gtk_signal_connect_object( GTK_OBJECT(item), "activate",
+                            GTK_SIGNAL_FUNC(ViewMenuInternalDump),
+                            NULL );
+  
+  /* Adding submenu title. */
+  item = gtk_menu_item_new_with_label( "View" );
+  gtk_menu_item_set_submenu( GTK_MENU_ITEM(item), menu );
+  gtk_menu_bar_append( GTK_MENU_BAR( menu_bar ), item );
+}
diff --git a/src/viewmenu.h b/src/viewmenu.h
new file mode 100644 (file)
index 0000000..db30bd0
--- /dev/null
@@ -0,0 +1,14 @@
+/* viewmenu.h */
+
+
+#ifndef VIEWMENU_H
+#define VIEWMENU_H 1
+
+#include <gtk/gtk.h>
+
+
+void
+ViewAddMenu( GtkWidget *menu_bar );
+
+
+#endif /* VIEWMENU_H */