Add option no-define to AM_INIT_AUTOMAKE
[emu8051.git] / src / gtk / regwin.c
index 8b470a9..d3fcb8d 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
 #include "pgmwin.h"
 #include "instructions_8051.h"
 #include "hexfile.h"
-#include "emugtk.h"
+#include "main.h"
 
 static GtkWidget *reglist;
 
 #define LIST_VIEW_NAME "Registers"
 #define DATA_ROWS SFR_REGS
 
-enum
-{
+enum {
        COL_NAME = 0,
        COL_VAL,
        N_COLUMNS,
@@ -80,63 +67,53 @@ regwin_cell_edited(GtkCellRendererText *cell, gchar *path_string,
        int old;
        int new;
        char *str;
+       int rc;
        struct regwin_infos_t *regwin_infos;
 
        (void) cell; /* Remove compiler warning about unused variables. */
 
-       if (!model) {
-               g_error("Unable to get model from cell renderer");
-       }
+       if (!model)
+               log_err("Unable to get model from cell renderer");
 
        /* 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);
 
        /* Get register name. */
        gtk_tree_model_get(model, &iter, COL_NAME, &str, -1);
 
        log_info("Register: %s", str);
        regwin_infos = sfr_get_infos(str);
+       log_info("  width:     %d bits", 4 * regwin_infos->w);
 
        /* Read current (old) value. */
        gtk_tree_model_get(model, &iter, COL_VAL, &str, -1);
 
+       /* No need to check error, has already been validated. */
        old = asciihex2int(str);
-
-       if (regwin_infos->w == 2)
-               log_info("  old value: $%02X", old);
-       else if (regwin_infos->w == 4)
-               log_info("  old value: $%04X", old);
+       log_info("  old value: $%04X", old);
 
        new = asciihex2int(new_str);
-
-       if (regwin_infos->w == 2) {
-               if ((new < 0) || (new > 0xFF)) {
-                       log_info("  new value: out of range");
-                       new = old; /* Put back old value... */
-               } else {
-                       log_info("  new value: $%02X", new);
-               }
-       } else if (regwin_infos->w == 4) {
-               if ((new < 0) || (new > 0xFFFF)) {
-                       log_info("  new value: out of range");
-                       new = old; /* Put back old value... */
-               } else {
-                       log_info("  new value: $%04X", new);
-               }
+       if (asciihex2int_get_error()) {
+               log_warn("  new value: invalid");
+               return;
        }
 
-       /* Store new value in emulator register. */
-       regwin_write(regwin_infos, new);
+       log_info("  new value: $%04X", new);
 
-       /* Store new value in gtk model. */
-       int2asciihex(new, str, regwin_infos->w);
-        gtk_list_store_set(GTK_LIST_STORE(model), &iter, COL_VAL, str, -1);
+       /* Store new value in emulator register (if in range). */
+       rc = regwin_write(regwin_infos, new);
+       if (rc == 0) {
+               /* Store new value in gtk model. */
+               int2asciihex(new, str, regwin_infos->w);
+               gtk_list_store_set(GTK_LIST_STORE(model), &iter, COL_VAL, str,
+                                  -1);
 
-       /*
-        * Make sure to update all windows.
-        * For example, R0-R7 values depends on internal memory values.
-        */
-       emugtk_UpdateDisplay();
+               /*
+                * Make sure to update all windows.
+                * For example, R0-R7 values depends on internal memory values.
+                */
+               emugtk_update_display();
+       }
 };
 
 static void