From 1292bafeb6aac59905acc6f7bf61dd37bac1e67a Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Wed, 30 May 2001 22:15:15 +0000 Subject: binary devices output formats added --- NEWS | 8 ++ mixgtk/mixgtk.glade | 347 +++++++++++++++++++++++++++++++++++++++++------- mixgtk/mixgtk_device.c | 206 ++++++++++++++++++++++++++-- mixgtk/mixgtk_device.h | 6 +- mixgtk/mixgtk_widgets.c | 1 + mixgtk/mixgtk_widgets.h | 1 + mixlib/mix_vm.c | 9 ++ mixlib/mix_vm.h | 5 + 8 files changed, 523 insertions(+), 60 deletions(-) diff --git a/NEWS b/NEWS index 1600b1b..aed5b34 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,14 @@ See the end for copying conditions. Please send mdk bug reports to bug-mdk@gnu.org. +--------------------------------------------------------------------------- +* Version 0.3.3 + +** The output of the contents of binary devices in gmixvm can be + configured to be in decimal or word format (for each block device). + +** The main gmixvm window is not shown until it is completely drawn. + --------------------------------------------------------------------------- * Version 0.3.2 (10/04/01) diff --git a/mixgtk/mixgtk.glade b/mixgtk/mixgtk.glade index 5dde85d..eaf7680 100644 --- a/mixgtk/mixgtk.glade +++ b/mixgtk/mixgtk.glade @@ -260,6 +260,19 @@ + + GtkMenuItem + device_output1 + Change format of binary devices output + + activate + on_devform_activate + Wed, 30 May 2001 20:44:48 GMT + + + False + + GtkMenuItem separator1 @@ -908,46 +921,6 @@ True - - GtkRadioButton - lesser_radio - 264 - 128 - 35 - 24 - Comparison flag: lesser - True - - toggled - on_cmp_l_toggled - Tue, 06 Mar 2001 21:21:51 GMT - - - False - True - cmp_group - - - - GtkRadioButton - equal_radio - 304 - 128 - 31 - 24 - Comparison flag: equal - True - - toggled - on_cmp_e_toggled - Tue, 06 Mar 2001 21:22:04 GMT - - - False - True - cmp_group - - GtkRadioButton greater_radio @@ -1040,6 +1013,46 @@ 627 16 + + + GtkRadioButton + lesser_radio + 264 + 128 + 35 + 24 + Comparison flag: lesser + True + + toggled + on_cmp_l_toggled + Tue, 06 Mar 2001 21:21:51 GMT + + + False + True + cmp_group + + + + GtkRadioButton + equal_radio + 304 + 128 + 31 + 24 + Comparison flag: equal + True + + toggled + on_cmp_e_toggled + Tue, 06 Mar 2001 21:22:04 GMT + + + False + True + cmp_group + @@ -1327,7 +1340,7 @@ on_word_reset_clicked Mon, 12 Mar 2001 22:40:33 GMT - + GTK_RELIEF_NORMAL @@ -1341,7 +1354,7 @@ on_word_ok_clicked Mon, 12 Mar 2001 22:40:45 GMT - + GTK_RELIEF_NORMAL @@ -1355,7 +1368,7 @@ on_word_cancel_clicked Mon, 12 Mar 2001 23:18:49 GMT - + GTK_RELIEF_NORMAL @@ -1764,7 +1777,7 @@ on_goto_cancel_clicked Wed, 14 Mar 2001 14:24:59 GMT - + GTK_RELIEF_NORMAL @@ -1778,7 +1791,7 @@ on_goto_ok_clicked Wed, 14 Mar 2001 14:25:23 GMT - + GTK_RELIEF_NORMAL @@ -1913,7 +1926,7 @@ on_colors_ok_clicked Thu, 12 Apr 2001 21:05:07 GMT - + GTK_RELIEF_NORMAL @@ -1927,7 +1940,7 @@ on_colors_apply_clicked Thu, 12 Apr 2001 21:04:56 GMT - + GTK_RELIEF_NORMAL @@ -1941,7 +1954,7 @@ on_colors_cancel_clicked Thu, 12 Apr 2001 21:04:45 GMT - + GTK_RELIEF_NORMAL @@ -2253,4 +2266,242 @@ + + GtkDialog + devform_dialog + 308 + 172 + False + + delete_event + gtk_widget_hide + Wed, 30 May 2001 20:14:53 GMT + + + destroy_event + gtk_widget_hide + Wed, 30 May 2001 20:15:13 GMT + + + destroy + gtk_widget_hide + Wed, 30 May 2001 20:15:29 GMT + + Device output format + GTK_WINDOW_DIALOG + GTK_WIN_POS_NONE + True + False + False + False + + + GtkVBox + Dialog:vbox + dialog-vbox8 + False + 0 + + + GtkHBox + Dialog:action_area + dialog-action_area8 + 10 + True + 5 + + 0 + False + True + GTK_PACK_END + + + + GtkHButtonBox + hbuttonbox8 + GTK_BUTTONBOX_DEFAULT_STYLE + 30 + 85 + 27 + 7 + 0 + + 0 + True + True + + + + GtkButton + devok_button + True + True + + clicked + on_devok_button_clicked + Wed, 30 May 2001 20:13:56 GMT + + + GTK_RELIEF_NORMAL + + + + GtkButton + devapp_button + True + True + + clicked + on_devapp_button_clicked + Wed, 30 May 2001 20:14:05 GMT + + + GTK_RELIEF_NORMAL + + + + GtkButton + devcancel_button + True + True + + clicked + on_devcancel_button_clicked + Wed, 30 May 2001 20:14:17 GMT + + + GTK_RELIEF_NORMAL + + + + + + GtkFixed + fixed2 + + 0 + True + True + + + + GtkButton + devset_button + 208 + 80 + 79 + 24 + Set all devices to current format + True + + clicked + on_devset_button_clicked + Wed, 30 May 2001 20:13:37 GMT + + + GTK_RELIEF_NORMAL + + + + GtkLabel + label232 + 16 + 22 + 48 + 16 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + GtkLabel + label233 + 216 + 22 + 48 + 16 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + GtkCombo + dev_combo + 16 + 48 + 150 + 22 + True + True + False + True + False + + + + GtkEntry + GtkCombo:entry + combo-entry1 + Choose a device + True + + changed + on_deventry_changed + Wed, 30 May 2001 19:50:03 GMT + + True + True + 0 + + + + + + GtkRadioButton + decradio + 184 + 48 + 48 + 24 + Show output as decimal numbers + True + + toggled + on_decradio_toggled + Wed, 30 May 2001 20:13:03 GMT + + + False + True + format_group + + + + GtkRadioButton + wordradio + 240 + 48 + 56 + 24 + Show output as MIX words + True + + False + True + format_group + + + + + diff --git a/mixgtk/mixgtk_device.c b/mixgtk/mixgtk_device.c index 26e48f5..b152469 100644 --- a/mixgtk/mixgtk_device.c +++ b/mixgtk/mixgtk_device.c @@ -23,17 +23,30 @@ #include +#include #include #include "mixgtk.h" +#include "mixgtk_widgets.h" +#include "mixgtk_config.h" #include "mixgtk_device.h" #define BIN_DEV_COL_ 5 +static const gchar *DEV_FORMAT_KEY_ = "Device.format"; + /* device container */ static GtkNotebook *container_ = NULL; static gint last_pos_ = 0; /* virtual machine */ static mix_vm_t *vm_ = NULL; +/* dec settings */ +static gint32 decs_ = 0; +static gint32 new_decs_ = 0; + +/* macros manipulating dec settings */ +#define IS_DEC(flags,type) (((flags) >> (type)) & 1) +#define SET_DEC(flags,type) ((flags) |= (1<<(type))) +#define CLEAR_DEC(flags,type) ((flags) &= ~(1<<(type))) /* a mixgtk device */ struct mixgtk_device_t @@ -48,6 +61,7 @@ struct mixgtk_bin_device_t struct mixgtk_device_t gtk_device; guint last_insert; GtkWidget *scroll; + gboolean dec; }; /* callbacks for output devices */ @@ -72,31 +86,81 @@ write_char_ (struct mixgtk_device_t *dev, const mix_word_t *block) } -static void -write_bin_ (struct mixgtk_bin_device_t *dev, const mix_word_t *block) +static const gchar * +get_word_string_ (mix_word_t w, gboolean dec) { enum {BUFF_SIZE = 17}; static gchar BUFFER[BUFF_SIZE] = { 0 }; + if (dec) + snprintf (BUFFER, BUFF_SIZE, "%s%011ld", + mix_word_is_negative (w)? "-" : "+", + mix_word_magnitude (w)); + else + mix_word_print_to_buffer (w, BUFFER); + return BUFFER; +} + +static void +write_bin_ (struct mixgtk_bin_device_t *dev, const mix_word_t *block) +{ static gchar *DEFTEXT[BIN_DEV_COL_] = { "0", "0", "0", "0", "0" }; guint k, col, row; + gboolean dec = FALSE; + GtkCList *list = GTK_CLIST (dev->gtk_device.widget); + dec = IS_DEC(decs_, dev->gtk_device.device.type); + gtk_clist_freeze (list); for (k = 0; k < SIZES_[dev->gtk_device.device.type]; k++) { - mix_word_print_to_buffer (block[k], BUFFER); row = dev->last_insert / BIN_DEV_COL_; col = dev->last_insert % BIN_DEV_COL_; - if (col == 0) gtk_clist_append (list, DEFTEXT); - gtk_clist_set_text (list, row, col, BUFFER); + if (col == 0) + { + int j; + mix_word_t *words = g_new (mix_word_t, 5); + gtk_clist_append (list, DEFTEXT); + for (j = 0; j < 5; ++j) words[j] = block[k + j]; + gtk_clist_set_row_data_full (list, row, (gpointer)words, g_free); + } + gtk_clist_set_text (list, row, col, get_word_string_ (block[k], dec)); dev->last_insert++; } gtk_clist_thaw (list); } +static void +redraw_bin_device_ (struct mixgtk_bin_device_t *dev) +{ + gint k, col, row; + gboolean dec = FALSE; + mix_word_t *words = NULL; + GtkCList *list; + + if (!dev) return; + + list = GTK_CLIST (dev->gtk_device.widget); + dec = IS_DEC(decs_, dev->gtk_device.device.type); + + gtk_clist_freeze (list); + + for (k = 0; k < dev->last_insert; ++k) + { + row = k / BIN_DEV_COL_; + col = k % BIN_DEV_COL_; + if (col == 0) + words = gtk_clist_get_row_data (list, row); + gtk_clist_set_text (list, row, col, get_word_string_ (words[col], dec)); + } + + gtk_clist_thaw (list); +} + + static gboolean write_ (mix_device_t *dev, const mix_word_t *block) { @@ -254,7 +318,7 @@ mixgtk_device_init (GtkNotebook *container, mix_vm_t *vm) }; gint k = 0; - + g_return_val_if_fail (container != NULL, FALSE); g_return_val_if_fail (vm != NULL, FALSE); container_ = container; @@ -265,6 +329,9 @@ mixgtk_device_init (GtkNotebook *container, mix_vm_t *vm) mix_vm_set_device_factory (vm, mixgtk_device_new_); + /* read format configuration */ + decs_ = atoi (mixgtk_config_get (DEV_FORMAT_KEY_)); + /* connect default devices */ while (def_types[k] != mix_dev_INVALID) { @@ -279,6 +346,127 @@ mixgtk_device_init (GtkNotebook *container, mix_vm_t *vm) return TRUE; } -/* connect a new (file-based) device */ -gboolean -mixgtk_device_connect (mix_device_type_t type, const gchar *name); +void +mixgtk_device_set_format (mix_device_type_t dev, gboolean dec) +{ + gboolean changed; + + g_return_if_fail (dev < mix_dev_INVALID); + + changed = (dec && !IS_DEC (decs_, dev)) || (!dec && IS_DEC (decs_, dev)); + + if (changed && (MODES_[dev] == mix_dev_BIN)) + { + if (dec) SET_DEC (decs_, dev); + else CLEAR_DEC (decs_, dev); + redraw_bin_device_ ((struct mixgtk_bin_device_t *) + mix_vm_get_device (vm_, dev)); + } + +} + + +/** configuration stuff */ +#define LAST_BIN_DEV_ mix_dev_DISK_7 +static GtkWidget *devdlg_ = NULL; +static GtkWidget *dtoggle_ = NULL; +static GtkWidget *wtoggle_ = NULL; +static GtkWidget *combo_ = NULL; + +static mix_device_type_t +get_device_idx_ (void) +{ + const gchar *name = gtk_entry_get_text + (GTK_ENTRY (GTK_COMBO (combo_)->entry)); + /* inefficient, but the list is short */ + int k; + for (k = 0; k <= LAST_BIN_DEV_; ++k) + if (!strcmp (name, DEF_NAMES_[k])) return k; + g_assert_not_reached (); + return 0; +} + +static void +init_devform_ (void) +{ + GList *names = NULL; + int k; + + devdlg_ = mixgtk_widget_factory_get_dialog (MIXGTK_DEVFORM_DIALOG); + g_assert (devdlg_); + dtoggle_ = mixgtk_widget_factory_get_child_by_name + (MIXGTK_DEVFORM_DIALOG, "decradio"); + g_assert (dtoggle_); + wtoggle_ = mixgtk_widget_factory_get_child_by_name + (MIXGTK_DEVFORM_DIALOG, "wordradio"); + g_assert (wtoggle_); + combo_ = mixgtk_widget_factory_get_child_by_name + (MIXGTK_DEVFORM_DIALOG, "dev_combo"); + g_assert (combo_); + + for (k = 0; k <= LAST_BIN_DEV_; ++k) + names = g_list_append (names, (gchar *)DEF_NAMES_[k]); + gtk_combo_set_popdown_strings (GTK_COMBO (combo_), names); +} + +void +on_deventry_changed () +{ + mix_device_type_t dev = get_device_idx_ (); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dtoggle_), + IS_DEC (new_decs_, dev)); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (wtoggle_), + !IS_DEC (new_decs_, dev)); +} + +void +on_devform_activate () +{ + if (!devdlg_) init_devform_ (); + new_decs_ = decs_; + gtk_widget_show (devdlg_); + on_deventry_changed (); +} + + +void +on_decradio_toggled (GtkToggleButton *button) +{ + if (gtk_toggle_button_get_active (button)) + SET_DEC (new_decs_, get_device_idx_ ()); + else + CLEAR_DEC (new_decs_, get_device_idx_ ()); +} + +void +on_devapp_button_clicked () +{ + int k; + gchar value[20]; + for (k = 0; k <= LAST_BIN_DEV_; ++k) + mixgtk_device_set_format (k, IS_DEC (new_decs_, k)); + snprintf (value, 20, "%d", decs_); + mixgtk_config_update (DEV_FORMAT_KEY_, value); +} + +void +on_devok_button_clicked () +{ + on_devapp_button_clicked (); + gtk_widget_hide (devdlg_); +} + +void +on_devcancel_button_clicked () +{ + gtk_widget_hide (devdlg_); +} + +void +on_devset_button_clicked () +{ + static gint32 ON = 0xffff, OFF = 0; + new_decs_ = (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dtoggle_)))? + ON : OFF; +} + diff --git a/mixgtk/mixgtk_device.h b/mixgtk/mixgtk_device.h index 7c21238..cdfec66 100644 --- a/mixgtk/mixgtk_device.h +++ b/mixgtk/mixgtk_device.h @@ -33,10 +33,10 @@ extern gboolean mixgtk_device_init (GtkNotebook *container, mix_vm_t *vm); +/* change the output format of a device */ +extern void +mixgtk_device_set_format (mix_device_type_t dev, gboolean dec); -/* connect a new (file-based) device */ -extern gboolean -mixgtk_device_connect (mix_device_type_t type, const gchar *name); #endif /* MIXGTK_DEVICE_H */ diff --git a/mixgtk/mixgtk_widgets.c b/mixgtk/mixgtk_widgets.c index 18d60e1..b032898 100644 --- a/mixgtk/mixgtk_widgets.c +++ b/mixgtk/mixgtk_widgets.c @@ -37,6 +37,7 @@ static const gchar * dnames_[] = { "color_dialog", "colorsel_dialog", "fontsel_dialog", + "devform_dialog" }; #define DLG_NO_ (sizeof (dnames_) / sizeof(dnames_[0])) diff --git a/mixgtk/mixgtk_widgets.h b/mixgtk/mixgtk_widgets.h index 8054ed4..261ad12 100644 --- a/mixgtk/mixgtk_widgets.h +++ b/mixgtk/mixgtk_widgets.h @@ -37,6 +37,7 @@ typedef enum { MIXGTK_COLOR_DIALOG, /* color customization dialog */ MIXGTK_COLORSEL_DIALOG, /* color selection dialog */ MIXGTK_FONTSEL_DIALOG, /* font selection dialog */ + MIXGTK_DEVFORM_DIALOG /* device format config dialog */ } mixgtk_dialog_id_t; /* enumeration of mixvm widget ids */ diff --git a/mixlib/mix_vm.c b/mixlib/mix_vm.c index 4446bcf..9816cb5 100644 --- a/mixlib/mix_vm.c +++ b/mixlib/mix_vm.c @@ -124,6 +124,15 @@ mix_vm_connect_device (mix_vm_t *vm, mix_device_t *device) return old; } +/* get device */ +mix_device_t * +mix_vm_get_device (const mix_vm_t *vm, mix_device_type_t dev) +{ + g_return_val_if_fail (vm != NULL, NULL); + g_return_val_if_fail (dev < mix_dev_INVALID, NULL); + return vm->devices[dev]; +} + /* install a device factory for automatic connection */ void mix_vm_set_device_factory (mix_vm_t *vm, mix_device_factory_t factory) diff --git a/mixlib/mix_vm.h b/mixlib/mix_vm.h index c4663bc..a8b826e 100644 --- a/mixlib/mix_vm.h +++ b/mixlib/mix_vm.h @@ -51,6 +51,11 @@ mix_vm_delete(mix_vm_t * vm); extern mix_device_t * /* previously connected device */ mix_vm_connect_device (mix_vm_t *vm, mix_device_t *device); +/* get device */ +extern mix_device_t * +mix_vm_get_device (const mix_vm_t *vm, mix_device_type_t dev); + + /* install a device factory for automatic connection */ typedef mix_device_t * (* mix_device_factory_t) (mix_device_type_t device); extern void -- cgit v1.2.3