Replace deprecated gtk_clist (regwin)
[emu8051.git] / src / memwin.c
index 7836781..a7ecdc7 100644 (file)
@@ -24,6 +24,7 @@
 #endif
 
 #include <stdio.h>
+#include <ctype.h> /* For isprint */
 
 #include "common.h"
 #include "memory.h"
@@ -102,9 +103,12 @@ memwin_init_columns(void)
 GtkWidget *
 memwin_init(void)
 {
+       GtkWidget *frame;
        GtkWidget *scrollwin;
        GtkListStore *store;
 
+       frame = gtk_frame_new("Internal memory");
+
        scrollwin = gtk_scrolled_window_new(NULL, NULL);
        gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrollwin),
                                            GTK_SHADOW_ETCHED_OUT);
@@ -114,11 +118,11 @@ memwin_init(void)
                                       GTK_POLICY_AUTOMATIC,
                                       GTK_POLICY_AUTOMATIC);
 
+       gtk_container_add(GTK_CONTAINER(frame), scrollwin);
+
        /* Creating a model */
        store = memwin_init_store();
 
-
-
        /* Creating the view component */
        memlist = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
        gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(memlist), TRUE);
@@ -133,7 +137,7 @@ memwin_init(void)
         */
        g_object_unref(store);
 
-       return scrollwin;
+       return frame;
 }
 
 /* Dump up to 256 bytes from Address in Memory (direct addressing) */
@@ -162,8 +166,9 @@ memwin_DumpD(char *MemAddress)
        for (row = 0; row < DATA_ROWS; row++) {
                int valid;
                GtkTreeIter iter;
-               char TextTmp[1024];
-               int column, TextLength;
+               char str[4 + 2]; /* Maximum str len is for address column (4 digits) */
+               char ascii_str[DATA_COLS];
+               int col;
 
                if (row == 0) {
                        /* Get first row in list store */
@@ -171,7 +176,8 @@ memwin_DumpD(char *MemAddress)
                                GTK_TREE_MODEL(store), &iter);
                } else {
                        /* Get next row in list store */
-                       valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
+                       valid = gtk_tree_model_iter_next(
+                               GTK_TREE_MODEL(store), &iter);
                }
 
                if (!valid) {
@@ -179,30 +185,27 @@ memwin_DumpD(char *MemAddress)
                        return;
                }
 
-               sprintf(TextTmp, "%.4X", Address);
-               gtk_list_store_set(store, &iter, COL_ADDRESS, TextTmp, -1);
+               /* Display base address. */
+               sprintf(str, "%.4X", Address);
+               gtk_list_store_set(store, &iter, COL_ADDRESS, str, -1);
 
-               for (column = 0; column < DATA_COLS; column++) {
-                       sprintf(TextTmp, "%.2X",
-                               (int) cpu8051_ReadD(Address + column));
+               for (col = 0; col < DATA_COLS; col++) {
+                       u_int8_t data;
 
-                       gtk_list_store_set(store, &iter, column + 1, TextTmp,
-                                          -1);
-               }
+                       data = cpu8051_ReadD(Address + col);
+
+                       /* Display hex data */
+                       sprintf(str, "%.2X", (u_int8_t) data);
+                       gtk_list_store_set(store, &iter, col + 1, str, -1);
 
-               TextLength = 0;
-               for (column = 0; column < DATA_COLS; 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], ".");
+                       /* Append to ASCII string (if applicable). */
+                       if (!isprint(data))
+                               data = '.';
+                       sprintf(&ascii_str[col], "%c", data);
                }
 
-               gtk_list_store_set(store, &iter, COL_ASCII, TextTmp, -1);
+               /* Display ASCII characters. */
+               gtk_list_store_set(store, &iter, COL_ASCII, ascii_str, -1);
 
                Address += DATA_COLS;
        }