Add option no-define to AM_INIT_AUTOMAKE
[emu8051.git] / src / gtk / pswwin.c
index 94f733c..f0badda 100644 (file)
@@ -4,19 +4,7 @@
  * Copyright (C) 1999 Jonathan St-AndrĂ©
  * Copyright (C) 1999 Hugo Villeneuve <hugo@hugovil.com>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ * This file is released under the GPLv2
  */
 
 #if HAVE_CONFIG_H
@@ -24,6 +12,7 @@
 #endif
 
 #include <stdio.h>
+#include <stdint.h>
 
 #include "common.h"
 #include "reg8051.h"
 #include "psw.h"
 #include "instructions_8051.h"
 #include "hexfile.h"
-#include "emugtk.h"
+#include "main.h"
 
 static GtkWidget *pswlist;
 
 #define DATA_ROWS 1
 #define LIST_VIEW_NAME "PSW"
-enum
-{
+
+enum {
        COL_CY = 0,
        COL_AC,
        COL_F0,
@@ -95,23 +84,22 @@ pswwin_cell_edited(GtkCellRendererText *cell, gchar *path_string,
        guint column;
        gpointer columnptr;
        GtkTreeIter iter;
-       u_int8_t old;
+       uint8_t old;
        int new;
        char str[10];
        int bit_index;
 
-       if (!model) {
-               g_error("Unable to get model from cell renderer");
-       }
+       if (!model)
+               log_err("Unable to get model from cell renderer");
 
        /* Column number is passed as renderer object data */
-        columnptr = g_object_get_data(G_OBJECT(cell), "column");
-        column = GPOINTER_TO_UINT(columnptr);
+       columnptr = g_object_get_data(G_OBJECT(cell), "column");
+       column = GPOINTER_TO_UINT(columnptr);
 
        log_info("column = $%02X", column);
 
        /* Get the iterator */
-        gtk_tree_model_get_iter_from_string(model, &iter, path_string);
+       gtk_tree_model_get_iter_from_string(model, &iter, path_string);
 
        bit_index = 7 - column;
 
@@ -122,9 +110,12 @@ pswwin_cell_edited(GtkCellRendererText *cell, gchar *path_string,
        /* Convert new value (asciihex) to integer. */
        new = asciihex2int(new_str);
 
-       if ((new != 0) && (new != 1)) {
-               log_info("  new value: out of range");
-               new = old; /* Put back old value... */
+       if (asciihex2int_get_error()) {
+               log_warn("  new value: invalid");
+               return;
+       } else if ((new != 0) && (new != 1)) {
+               log_warn("  new value: out of range");
+               return;
        } else {
                log_info("  new value: %d", new);
        }
@@ -136,13 +127,13 @@ pswwin_cell_edited(GtkCellRendererText *cell, gchar *path_string,
        int2asciihex(new, str, 1);
 
        /* Store new value in gtk model. */
-        gtk_list_store_set(GTK_LIST_STORE(model), &iter, column, str, -1);
+       gtk_list_store_set(GTK_LIST_STORE(model), &iter, column, str, -1);
 
        /*
         * Make sure to update all registers and memory.
         * For example, BANKed registers depends on internal memory.
         */
-       emugtk_UpdateDisplay();
+       emugtk_update_display();
 };
 
 static void
@@ -163,7 +154,8 @@ pswwin_init_columns(void)
 
                g_signal_connect(renderer, "edited",
                                 G_CALLBACK(pswwin_cell_edited),
-                                gtk_tree_view_get_model(GTK_TREE_VIEW(pswlist)));
+                                gtk_tree_view_get_model(
+                                        GTK_TREE_VIEW(pswlist)));
 
                /* Add column index, used when editing the cell. */
                g_object_set_data(G_OBJECT(renderer), "column",
@@ -176,7 +168,8 @@ pswwin_init_columns(void)
                g_object_set(column, "alignment", 0.5, NULL);
 
                /* Hardcoded width... */
-               gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
+               gtk_tree_view_column_set_sizing(column,
+                                               GTK_TREE_VIEW_COLUMN_FIXED);
                gtk_tree_view_column_set_fixed_width(column, 35);
 
                gtk_tree_view_append_column(GTK_TREE_VIEW(pswlist), column);
@@ -197,7 +190,8 @@ pswwin_init(void)
        /* Creating the view component */
        pswlist = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
 
-       gtk_tree_view_set_grid_lines(GTK_TREE_VIEW(pswlist), GTK_TREE_VIEW_GRID_LINES_BOTH);
+       gtk_tree_view_set_grid_lines(GTK_TREE_VIEW(pswlist),
+                                    GTK_TREE_VIEW_GRID_LINES_BOTH);
 
        gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(pswlist), TRUE);
        gtk_container_add(GTK_CONTAINER(frame), pswlist);
@@ -230,7 +224,7 @@ pswwin_refresh(void)
                GTK_TREE_MODEL(store), &iter);
 
        if (!valid) {
-               printf("Invalid iter...\n");
+               log_err("Tree model: invalid iter");
                return;
        }