Refactor code for memwin and pgmwin modify
[emu8051.git] / src / pgmwin.c
index 3a54091..41c74d8 100644 (file)
@@ -29,6 +29,7 @@
 #include "memory.h"
 #include "cpu8051.h"
 #include "pgmwin.h"
+#include "hexfile.h"
 
 static GtkWidget *pgmlist;
 
@@ -107,9 +108,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));
@@ -121,20 +120,16 @@ pgmwin_sel_changed_event(GtkWidget *widget, GdkEvent *event, gpointer data)
                gtk_tree_model_get(model, &iter, COL_ADDR, &str_addr, -1);
 
                /* Convert hex address in ASCII to integer. */
-               sscanf(str_addr, "%x", &val);
+               val = asciihex2int(str_addr);
 
-#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;
@@ -234,7 +229,8 @@ pgmwin_Disasm(void)
                gtk_list_store_set(store, &iter, COL_BREAKPT, str, -1);
 
                /* Display base address. */
-               sprintf(str, "%.4X", Address);
+               int2asciihex(Address, str, 4);
+
                gtk_list_store_set(store, &iter, COL_ADDR, str, -1);
 
                OpCode = memory_read8(PGM_MEM_ID, Address);
@@ -242,8 +238,8 @@ pgmwin_Disasm(void)
 
                /* Display instruction hex bytes. */
                for (k = 0, col_id = COL_B0; k < InstSize; k++, col_id++) {
-                       sprintf(str, "%.2X", memory_read8(PGM_MEM_ID,
-                                                         Address + k));
+                       int2asciihex(memory_read8(PGM_MEM_ID, Address + k),
+                                    str, 2);
                        gtk_list_store_set(store, &iter, col_id, str, -1);
                }