Add better error checking when loading invalid hex files
[emu8051.git] / src / gtk / emugtk.c
index 0377ddc..3374d62 100644 (file)
 #include "filemenu.h"
 #include "viewmenu.h"
 #include "helpmenu.h"
+#include "messagebox.h"
 #include "regwin.h"
 #include "pgmwin.h"
 #include "memwin.h"
 #include "pswwin.h"
+#include "timerwin.h"
 #include "app-config.h"
 
 #define BUTTONS_BORDER 2
 
 static int running;
 static int running_function_tag;
-static int restart_gui = true;
 
 static int emugtk_window_init_complete;
 static GtkWidget *vpaned1;
@@ -70,6 +71,7 @@ emugtk_UpdateDisplay(void)
        regwin_refresh();
        pgmwin_refresh();
        pswwin_refresh();
+       timerwin_update();
 
        if (cfg->view_int_memory && scrollwin_int)
                memwin_refresh(INT_MEM_ID);
@@ -320,22 +322,10 @@ main_paned_notify_event(GtkWindow *window, GdkEvent *event, gpointer data)
        cfg->main_pane_pos = gtk_paned_get_position(GTK_PANED(paned));
 }
 
-void
-emugtk_restart_gui(void)
-{
-       emugtk_stop_running();
-
-       gtk_widget_destroy(mainwin);
-
-       restart_gui = true;
-}
-
 void
 emugtk_quit_gui(void)
 {
        gtk_main_quit();
-
-       restart_gui = false;
 }
 
 static void
@@ -520,6 +510,9 @@ emugtk_window_init(void)
        scrollwin = pswwin_init();
        gtk_box_pack_start(GTK_BOX(buttons_bar), scrollwin, FALSE, FALSE, 100);
 
+       scrollwin = timerwin_init();
+       gtk_box_pack_start(GTK_BOX(buttons_bar), scrollwin, FALSE, FALSE, 100);
+
        /* hpaned will contain registers and disassembly windows. */
        hpaned = gtk_hpaned_new();
        gtk_paned_set_position(GTK_PANED(hpaned), cfg->hpane_pos);
@@ -585,19 +578,26 @@ AddMenuSeparator(GtkWidget *menu)
 void
 emugtk_new_file(char *file)
 {
-       emugtk_stop_running();
+       int rc;
 
-       LoadHexFile(file);
+       emugtk_stop_running();
 
-       if (cfg->clear_ram_on_file_load)
-               emugtk_Reset();
+       rc = LoadHexFile(file);
+       if (rc == false) {
+               message_show_error("Error parsing hex file");
+       } else {
+               if (cfg->clear_ram_on_file_load)
+                       emugtk_Reset();
 
-       emugtk_UpdateDisplay();
+               emugtk_UpdateDisplay();
+       }
 }
 
 int
 main(int argc, char **argv)
 {
+       int rc_load_hexfile = true;
+
        parse_command_line_options(argc, argv);
        app_config_load();
 
@@ -608,17 +608,18 @@ main(int argc, char **argv)
        gtk_init(&argc, &argv);
 
        if (options.filename != NULL)
-               LoadHexFile(options.filename);
+               rc_load_hexfile = LoadHexFile(options.filename);
 
        cpu8051_Reset();
 
-       while (restart_gui == true) {
-               log_info("Init GUI");
+       log_info("Init GUI");
+       emugtk_window_init();
+       emugtk_UpdateDisplay();
 
-               emugtk_window_init();
-               emugtk_UpdateDisplay();
-               gtk_main();
-       }
+       if (rc_load_hexfile == false)
+               message_show_error("Error parsing hex file");
+
+       gtk_main();
 
        log_info("Terminate");