Replace macro EMU8051_DEBUG with logging functions
authorHugo Villeneuve <hugo@hugovil.com>
Fri, 11 Oct 2013 03:08:00 +0000 (23:08 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Wed, 6 Nov 2013 02:50:16 +0000 (21:50 -0500)
src/app-config.c
src/common.h
src/emuconsole.c
src/emugtk.c
src/filemenu.c
src/memwin.c
src/pgmwin.c

index 15bed2b..b61b900 100644 (file)
@@ -62,17 +62,11 @@ app_config_key_file_get_int(GKeyFile *kf, const char *grp, const char *key, int
 {
     char *str = g_key_file_get_value(kf, grp, key, NULL);
 
-#ifdef EMU8051_DEBUG
-    printf("key: %s\n", key);
-#endif
+    log_debug("key: %s", key);
 
     if (G_LIKELY(str)) {
            *value = atoi(str);
-
-#ifdef EMU8051_DEBUG
-           printf("  value = %d\n", *value);
-#endif
-
+           log_debug("  value = %d", *value);
            g_free(str);
     }
 
@@ -117,9 +111,7 @@ app_config_get_file_path(void)
 
        file_path = g_build_filename(dir_path, file, NULL);
 
-#ifdef EMU8051_DEBUG
-       printf("app. config file = %s\n", file_path);
-#endif
+       log_info("app. config file = %s", file_path);
 
        g_free(dir_path);
 
index 51a8c1c..0058a01 100644 (file)
@@ -22,9 +22,6 @@
 #ifndef COMMON_H
 #define COMMON_H 1
 
-/* Define this to have debugging output. */
-/* #define EMU8051_DEBUG 1 */
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
index 4c35f5a..3dcdf89 100644 (file)
@@ -462,9 +462,7 @@ main(int argc, char **argv)
 
        console_main();
 
-#ifdef EMU8051_DEBUG
-       printf("End of program.\n");
-#endif
+       log_info("Terminate");
 
        return 0;
 }
index 656a07e..f3e6e37 100644 (file)
@@ -60,9 +60,7 @@ static void
 emugtk_stop_running()
 {
        if (running) {
-#ifdef EMU8051_DEBUG
-               printf("emugtk_StopRunning()\n");
-#endif
+               log_info("StopRunning()");
                g_source_remove(running_function_tag);
                running = 0;
                regwin_Show();
@@ -77,9 +75,7 @@ emugtk_running(gpointer data)
 {
        cpu8051_Exec();
        if (IsBreakpoint(cpu8051.pc)) {
-#ifdef EMU8051_DEBUG
-               g_print("Breakpoint Hit, stopping!\n");
-#endif
+               log_info("Breakpoint Hit");
                emugtk_stop_running();
        }
 
@@ -91,9 +87,7 @@ static void
 emugtk_start_running(void)
 {
        if (!running) {
-#ifdef EMU8051_DEBUG
-               printf("emugtk_StartRunning()\n");
-#endif
+               log_info("StartRunning()");
                running_function_tag = g_idle_add(emugtk_running, 0);
                running = 1;
        }
@@ -131,9 +125,7 @@ emugtk_Reset(void)
 static void
 emugtk_ResetEvent(GtkWidget *widget, GdkEvent *event, gpointer data)
 {
-#ifdef EMU8051_DEBUG
-       g_print("emugtk_ResetEvent(...)\n");
-#endif
+       log_info("ResetEvent()");
        emugtk_stop_running();
        emugtk_Reset();
 }
@@ -152,9 +144,8 @@ emugtk_Step(void)
 static void
 emugtk_RunEvent(GtkWidget *widget, GdkEvent *event, gpointer data)
 {
-#ifdef EMU8051_DEBUG
-       g_print("emugtk_RunEvent(...)\n");
-#endif
+       log_info("RunEvent()");
+
        if (running)
                emugtk_stop_running();
        else
@@ -165,9 +156,7 @@ emugtk_RunEvent(GtkWidget *widget, GdkEvent *event, gpointer data)
 static void
 emugtk_StopEvent(GtkWidget *widget, GdkEvent *event, gpointer data)
 {
-#ifdef EMU8051_DEBUG
-       g_print("emugtk_StopEvent(...)\n");
-#endif
+       log_info("StopEvent()");
        emugtk_stop_running();
 }
 
@@ -175,9 +164,7 @@ emugtk_StopEvent(GtkWidget *widget, GdkEvent *event, gpointer data)
 static void
 emugtk_StepEvent(GtkWidget *widget, GdkEvent *event, gpointer data)
 {
-#ifdef EMU8051_DEBUG
-       g_print("emugtk_StepEvent(...)\n");
-#endif
+       log_info("StepEvent()");
        emugtk_stop_running();
        emugtk_Step();
 }
@@ -399,10 +386,7 @@ emugtk_window_init(void)
 static void
 emugtk_UpdateDisplay(void)
 {
-#ifdef EMU8051_DEBUG
-       g_print("emugtk_UpdateDisplay()\n");
-#endif
-
+       log_debug("UpdateDisplay()");
        regwin_Show();
        pgmwin_Disasm();
        memwin_DumpD("00");
@@ -449,9 +433,7 @@ main(int argc, char **argv)
 
        gtk_main();
 
-#ifdef EMU8051_DEBUG
-       printf("End of program.\n");
-#endif
+       log_info("Terminate");
 
        app_config_save();
 
index 7e9e3dd..47e18aa 100644 (file)
@@ -46,12 +46,9 @@ remember_current_folder(GtkFileChooser *chooser)
        if (folder != NULL) {
                if (strlen(folder) >= MAX_FILENAME_LENGTH) {
                        /* Non-critical error */
-                       g_print("current folder name too long for buffer\n");
+                       log_warn("current folder name too long for buffer");
                } else {
-#if defined(DEBUG)
-                       g_print("current folder = %s\n", folder);
-#endif
-
+                       log_info("current folder = %s", folder);
                        strncpy(previous_folder, folder, MAX_FILENAME_LENGTH);
                }
 
@@ -66,9 +63,7 @@ FileOpenEvent(GtkObject *object, gpointer data)
        char *dir;
        char *cwd = NULL;
 
-#if defined(DEBUG)
-       g_print("FileOpenEvent()\n");
-#endif
+       log_info("FileOpenEvent()");
 
        /* Create a new file selection widget. */
        file_dialog = gtk_file_chooser_dialog_new(
@@ -97,9 +92,7 @@ FileOpenEvent(GtkObject *object, gpointer data)
                        GTK_FILE_CHOOSER(file_dialog));
 
                if (selected_file != NULL) {
-#if defined(DEBUG)
-                       g_print("emugtk_File = %s\n", selected_file);
-#endif
+                       log_info("emugtk_File = %s", selected_file);
 
                        remember_current_folder(GTK_FILE_CHOOSER(file_dialog));
 
@@ -114,10 +107,6 @@ FileOpenEvent(GtkObject *object, gpointer data)
 static void
 FileQuitEvent(gchar *string)
 {
-#if defined(DEBUG)
-       g_print("%s\n", string);
-#endif
-
        gtk_main_quit();
 }
 
index a7ecdc7..5f9170c 100644 (file)
@@ -148,9 +148,7 @@ memwin_DumpD(char *MemAddress)
        unsigned int Address;
        GtkListStore *store;
 
-#ifdef EMU8051_DEBUG
-       printf("memwin_DumpD, address = %s\n", MemAddress);
-#endif
+       log_info("memwin_DumpD, address = %s", MemAddress);
 
        if (strlen(MemAddress) != 0) {
                if (STREQ(MemAddress, "PC"))
index 3a54091..e4f9b46 100644 (file)
@@ -107,9 +107,7 @@ pgmwin_sel_changed_event(GtkWidget *widget, GdkEvent *event, gpointer data)
        GtkTreeModel     *model;
        GtkTreeIter       iter;
 
-#ifdef EMU8051_DEBUG
-       printf("pgmwin_sel_changed_event()\n");
-#endif
+       log_debug("pgmwin_sel_changed_event()");
 
        /* This will only work in single or browse selection mode! */
        selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pgmlist));
@@ -123,18 +121,14 @@ pgmwin_sel_changed_event(GtkWidget *widget, GdkEvent *event, gpointer data)
                /* Convert hex address in ASCII to integer. */
                sscanf(str_addr, "%x", &val);
 
-#ifdef EMU8051_DEBUG
-               printf("  row address is: $%04X\n", val);
-#endif
+               log_debug("  row address is: $%04X", val);
 
                ToggleBreakpoint(val);
                pgmwin_Disasm();
 
                g_free(str_addr);
        } else {
-#ifdef EMU8051_DEBUG
-               printf("  no row selected.\n");
-#endif
+               log_debug("  no row selected");
        }
 
        return FALSE;